diff options
Diffstat (limited to 'agbx/source')
-rw-r--r-- | agbx/source/bs/done.c | 34 | ||||
-rw-r--r-- | agbx/source/bs/get.c | 40 | ||||
-rw-r--r-- | agbx/source/bs/set.c | 13 | ||||
-rw-r--r-- | agbx/source/gfx/plot.c | 34 | ||||
-rw-r--r-- | agbx/source/gfx/setpx.c | 33 | ||||
-rw-r--r-- | agbx/source/priv/init.c | 14 |
6 files changed, 168 insertions, 0 deletions
diff --git a/agbx/source/bs/done.c b/agbx/source/bs/done.c new file mode 100644 index 0000000..afac799 --- /dev/null +++ b/agbx/source/bs/done.c @@ -0,0 +1,34 @@ +/* + Copyright 2022 Gabriel Jensen. + This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. + If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/. +*/ + +#include <agbx/priv.h> + +void agbx_done(agbx_err const _err) { + if (_err == agbx_err_ok) { + __asm__ ( + "swi 0x3\n" + ); + __builtin_unreachable(); + } + /* Display the barcode-like error message: */ + agbx_set10(0x4000000u,0x403u); + agbx_i10 err[0x8u]; + for (agbx_i8 pos = 0x0u;pos != 0x8u;++pos) {err[pos] = (agbx_i8)_err >> pos & 0x1u ? 0xFFFFu : 0x0u;} + for (agbx_i10 pos = 0x0u;pos != 0x9600u;pos += 0xF0u) { + agbx_setpx2(pos, err[0x0u]); + agbx_setpx2(pos + 0x1u,err[0x1u]); + agbx_setpx2(pos + 0x2u,err[0x2u]); + agbx_setpx2(pos + 0x3u,err[0x3u]); + agbx_setpx2(pos + 0x4u,err[0x4u]); + agbx_setpx2(pos + 0x5u,err[0x5u]); + agbx_setpx2(pos + 0x6u,err[0x6u]); + agbx_setpx2(pos + 0x7u,err[0x7u]); + } + __asm__ ( + "swi 0x2\n" + ); + for (;;) {} +} diff --git a/agbx/source/bs/get.c b/agbx/source/bs/get.c new file mode 100644 index 0000000..38da5af --- /dev/null +++ b/agbx/source/bs/get.c @@ -0,0 +1,40 @@ +/* + Copyright 2022 Gabriel Jensen. + This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. + If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/. +*/ + +#include <agbx/priv.h> + +agbx_i10 agbx_get10(agbx_i20 const _addr) { + agbx_i10 val; + __asm__ ( \ + "ldrh %0,[%1]" + : "=r" (val) + : "r" (_addr) + : "memory" + ); + return val; +} + +agbx_i20 agbx_get20(agbx_i20 const _addr) { + agbx_i20 val; + __asm__ ( \ + "ldr %0,[%1]" + : "=r" (val) + : "r" (_addr) + : "memory" + ); + return val; +} + +agbx_i8 agbx_get8(agbx_i20 const _addr) { + agbx_i8 val; + __asm__ ( \ + "ldrb %0,[%1]" + : "=r" (val) + : "r" (_addr) + : "memory" + ); + return val; +} diff --git a/agbx/source/bs/set.c b/agbx/source/bs/set.c new file mode 100644 index 0000000..8aa9976 --- /dev/null +++ b/agbx/source/bs/set.c @@ -0,0 +1,13 @@ +/* + Copyright 2022 Gabriel Jensen. + This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. + If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/. +*/ + +#include <agbx/priv.h> + +void agbx_set10(agbx_i20 const _addr,agbx_i10 const _val) {__agbx_set10(_addr,_val)} + +void agbx_set20(agbx_i20 const _addr,agbx_i20 const _val) {__agbx_set20(_addr,_val)} + +void agbx_set8(agbx_i20 const _addr,agbx_i8 const _val) {__agbx_set8(_addr,_val)} diff --git a/agbx/source/gfx/plot.c b/agbx/source/gfx/plot.c new file mode 100644 index 0000000..5a65972 --- /dev/null +++ b/agbx/source/gfx/plot.c @@ -0,0 +1,34 @@ +/* + Copyright 2022 Gabriel Jensen. + This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. + If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/. +*/ + +#include <agbx/priv.h> + +agbx_i10 agbx_plot3(agbx_i8 const _x,agbx_i8 const _y,agbx_i10 const _col) { +#if defined(__agbx_dbg) + if (_x >= 0xF0u || _y >= 0xA0u) {agbx_done(agbx_err_pos2big);} +#endif + agbx_i10 const px = _y * 0xF0u + _x; + __agbx_setpx2(px,_col) + return px; +} + +agbx_i10 agbx_plot4(agbx_i8 const _x,agbx_i8 const _y,agbx_i8 const _col) { +#if defined(__agbx_dbg) + if (_x >= 0xF0u || _y >= 0xA0u) {agbx_done(agbx_err_pos2big);} +#endif + agbx_i10 const px = _y * 0xF0u + _x; + __agbx_setpx1(px,_col) + return px; +} + +agbx_i10 agbx_plot5(agbx_i8 const _x,agbx_i8 const _y,agbx_i10 const _col) { +#if defined(__agbx_dbg) + if (_x >= 0xA0u || _y >= 0x80u) {agbx_done(agbx_err_pos2big);} +#endif + agbx_i10 const px = _y * 0xA0u + _x; + __agbx_setpx2(px,_col) + return px; +} diff --git a/agbx/source/gfx/setpx.c b/agbx/source/gfx/setpx.c new file mode 100644 index 0000000..ace2463 --- /dev/null +++ b/agbx/source/gfx/setpx.c @@ -0,0 +1,33 @@ +/* + Copyright 2022 Gabriel Jensen. + This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. + If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/. +*/ + +#include <agbx/priv.h> + +void agbx_setpx1(agbx_i10 const _px,agbx_i8 const _col) { +#if defined(__agbx_dbg) + agbx_i10 const dispcnt = agbx_get10(0x4000000u); + agbx_i8 const md = dispcnt & 0x7u; + if (md == 0x3u || md == 0x5u) {agbx_done(agbx_err_badmd);} + if (_px >= 0x9600u) {agbx_done(agbx_err_px2big);} +#endif + __agbx_setpx1(_px,_col) +} + +void agbx_setpx2(agbx_i10 const _px,agbx_i10 const _col) { +#if defined(__agbx_dbg) + agbx_i10 const dispcnt = agbx_get10(0x4000000u); + agbx_i8 const md = dispcnt & 0x7u; + if (md == 0x4u) {agbx_done(agbx_err_badmd);} + if (md == 0x5u) { + if (_px >= 0x5000u) {agbx_done(agbx_err_px2big);} + } + else { + if (md != 0x3u) {agbx_done(agbx_err_badmd);} + if (_px >= 0x9600u) {agbx_done(agbx_err_px2big);} + } +#endif + __agbx_setpx2(_px,_col) +} diff --git a/agbx/source/priv/init.c b/agbx/source/priv/init.c new file mode 100644 index 0000000..3ba1f17 --- /dev/null +++ b/agbx/source/priv/init.c @@ -0,0 +1,14 @@ +/* + Copyright 2022 Gabriel Jensen. + This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. + If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/. +*/ + +#include <agbx/priv.h> + +agbx_err agbx_main(void); + +[[noreturn]] void __agbx_init(void) { + agbx_err const err = agbx_main(); + agbx_done(err); +} |