diff options
Diffstat (limited to 'demo')
-rw-r--r-- | demo/GNUmakefile | 8 | ||||
-rw-r--r-- | demo/demo.c | 81 | ||||
-rw-r--r-- | demo/include/agbx-demo.h | 33 | ||||
-rw-r--r-- | demo/source/chgcol.c | 17 | ||||
-rw-r--r-- | demo/source/chkkeys.c | 64 | ||||
-rw-r--r-- | demo/source/initdat.c | 10 | ||||
-rw-r--r-- | demo/source/initgfx.c | 17 | ||||
-rw-r--r-- | demo/source/loop.c | 29 | ||||
-rw-r--r-- | demo/source/main.c | 18 |
9 files changed, 195 insertions, 82 deletions
diff --git a/demo/GNUmakefile b/demo/GNUmakefile index 076b19f..aed29df 100644 --- a/demo/GNUmakefile +++ b/demo/GNUmakefile @@ -14,6 +14,7 @@ OBJCOPY := arm-none-eabi-objcopy CFLAGS := \ -I../agbx/include \ + -Iinclude \ -O3 \ -Wall \ -Wextra \ @@ -25,7 +26,12 @@ CFLAGS := \ # BINARIES OBJS := \ - demo.o + source/chkkeys.o \ + source/chgcol.o \ + source/initdat.o \ + source/initgfx.o \ + source/loop.o \ + source/main.o ROMHDR := hdr.o diff --git a/demo/demo.c b/demo/demo.c deleted file mode 100644 index 012e705..0000000 --- a/demo/demo.c +++ /dev/null @@ -1,81 +0,0 @@ -#include <agbx/key.h> -#include <agbx/gfx.h> - -agbx_err agbx_main(void) { - agbx_set10(0x500'0000u,0x0u); - agbx_set10(0x500'0002u,0x19u); - agbx_set10(0x500'0004u,0xFFFFu); - agbx_set10(0x400'0000u,0x404u); - agbx_clrscrn4(0x600'0000u,0x0u); - agbx_clrscrn4(0x600'A000u,0x0u); - agbx_i10 const cols[] = { - 0b11111u, - 0b1111100000u, - 0b111110000000000u, - }; - agbx_i8 col = 0x0u; - struct { - agbx_i8 x; - agbx_i8 y; - } pos = {.x = 0x0u,.y = 0x0u,}; - agbx_setpx1(0x600'0000u,0x0u,0x2u); - agbx_i20 vaddr = 0x600'0000u; - for (;;) { - agbx_vsync(); - agbx_keymap const keymap = agbx_getkeymap(); - if (agbx_chkkey(keymap,agbx_key_b)) { - return (agbx_err)(((agbx_i10)pos.x + (agbx_i10)pos.y)/0x2u); - } - if (agbx_chkkey(keymap,agbx_key_a)) { - return agbx_err_ok; - } - if (agbx_chkkey(keymap,agbx_key_l)) { - agbx_plot4(vaddr,pos.x,pos.y,0x1u); - vaddr = agbx_flip(); - agbx_plot4(vaddr,pos.x,pos.y,0x2u); - while (agbx_chkkey(agbx_getkeymap(),agbx_key_l)) {} - continue; - } - if (agbx_chkkey(keymap,agbx_key_r)) { - if (col == 0x2u) {col = 0x0u;} - else {++col;} - agbx_set10(0x500'0002u,cols[col]); - while (agbx_chkkey(agbx_getkeymap(),agbx_key_r)) {} - continue; - } - typeof (pos) const prevpos = pos; - agbx_key key = agbx_key_pade; - if (agbx_chkkey(keymap,key)) { - if (pos.x != 0xEFu) { - ++pos.x; - goto drw; - } - } - key = agbx_key_padn; - if (agbx_chkkey(keymap,key)) { - if (pos.y != 0x0u) { - --pos.y; - goto drw; - } - } - key = agbx_key_pads; - if (agbx_chkkey(keymap,key)) { - if (pos.y != 0x9Fu) { - ++pos.y; - goto drw; - } - } - key = agbx_key_padw; - if (agbx_chkkey(keymap,key)) { - if (pos.x != 0x0u) { - --pos.x; - goto drw; - } - } - continue; - drw:; - agbx_plot4(vaddr,prevpos.x,prevpos.y,0x1u); - agbx_plot4(vaddr,pos.x,pos.y,0x2u); - while (agbx_chkkey(agbx_getkeymap(),key)) {} - } -} diff --git a/demo/include/agbx-demo.h b/demo/include/agbx-demo.h new file mode 100644 index 0000000..2dc2313 --- /dev/null +++ b/demo/include/agbx-demo.h @@ -0,0 +1,33 @@ +#if !defined(agbxd_hdr) +#define agbxd_hdr + +#include <agbx/bs.h> + +typedef struct { + agbx_i8 x; + agbx_i8 y; +} agbxd_pos; + +typedef struct { + agbx_i8 col; + agbxd_pos pos; + agbx_i8 prevcol; + agbxd_pos prevpos; + agbx_i20 vaddr; +} agbxd_dat; + +typedef struct { + bool done; + bool err; + bool drw; + bool mv; +} agbxd_upd; + +agbxd_upd agbxd_chkkeys(agbxd_dat * dat); +void agbxd_chgcol( agbxd_dat * dat,agbx_i8 dir); +void agbxd_drw( agbxd_dat * dat); +void agbxd_initdat(agbxd_dat * dat); +void agbxd_initgfx(void); +bool agbxd_loop( agbxd_dat * dat); + +#endif diff --git a/demo/source/chgcol.c b/demo/source/chgcol.c new file mode 100644 index 0000000..cbd653e --- /dev/null +++ b/demo/source/chgcol.c @@ -0,0 +1,17 @@ +#include <agbx-demo.h> + +#include <agbx/gfx.h> + +void agbxd_chgcol(agbxd_dat * _dat,agbx_i8 const _dir) { + constexpr agbx_i8 maxcol = 0x7u; + agbx_i8 col = _dat->col; + if (!_dir) { + if (!col) {col = maxcol;} + else {--col;} + } + else { + if (col == maxcol) {col = 0x0u;} + else {++col;} + } + _dat->col = col; +} diff --git a/demo/source/chkkeys.c b/demo/source/chkkeys.c new file mode 100644 index 0000000..f117d09 --- /dev/null +++ b/demo/source/chkkeys.c @@ -0,0 +1,64 @@ +#include <agbx-demo.h> + +#include <agbx/key.h> +#include <agbx/gfx.h> + +#define agbxd_chk(_key) \ + curkey = _key; \ + if (agbx_chkkey(keymap,_key)) + +#define agbxd_wait() \ + while (agbx_chkkey(agbx_getkeymap(),curkey)) {} + +agbxd_upd agbxd_chkkeys(agbxd_dat * _dat) { + agbxd_upd upd = {}; + agbx_keymap const keymap = agbx_getkeymap(); + agbx_key curkey; + agbxd_chk(agbx_key_sel) { + upd.done = true; + upd.err = true; + return upd; + } + agbxd_chk(agbx_key_start) { + upd.done = true; + return upd; + } + agbxd_chk(agbx_key_l) { + agbxd_chgcol(_dat,0x0u); + agbxd_wait(); + } + agbxd_chk(agbx_key_r) { + agbxd_chgcol(_dat,0x1u); + agbxd_wait(); + } + agbxd_chk(agbx_key_pade) { + if (_dat->pos.x != 0xEFu) { + upd.mv = true; + ++_dat->pos.x; + agbxd_wait(); + } + } + agbxd_chk(agbx_key_padn) { + if (_dat->pos.y != 0x0u) { + upd.mv = true; + --_dat->pos.y; + agbxd_wait(); + } + } + agbxd_chk(agbx_key_pads) { + if (_dat->pos.y != 0x9Fu) { + upd.mv = true; + ++_dat->pos.y; + agbxd_wait(); + } + } + agbxd_chk(agbx_key_padw) { + if (_dat->pos.x != 0x0u) { + upd.mv = true; + --_dat->pos.x; + agbxd_wait(); + } + } + agbxd_chk(agbx_key_a) {upd.drw = true;} + return upd; +} diff --git a/demo/source/initdat.c b/demo/source/initdat.c new file mode 100644 index 0000000..c9bb7af --- /dev/null +++ b/demo/source/initdat.c @@ -0,0 +1,10 @@ +#include <agbx-demo.h> + +#include <agbx/gfx.h> + +void agbxd_initdat(agbxd_dat * const _dat) { + _dat->col = 0x2u; + _dat->pos.x = 0x0u; + _dat->pos.y = 0x0u; + _dat->vaddr = 0x600'0000u; +} diff --git a/demo/source/initgfx.c b/demo/source/initgfx.c new file mode 100644 index 0000000..474d5cd --- /dev/null +++ b/demo/source/initgfx.c @@ -0,0 +1,17 @@ +#include <agbx-demo.h> + +#include <agbx/gfx.h> + +void agbxd_initgfx(void) { + agbx_set10(0x500'0000u,0b0u); + agbx_set10(0x500'0002u,0b111111111111111u); + agbx_set10(0x500'0004u,0b11111u); + agbx_set10(0x500'0006u,0b1111111111u); + agbx_set10(0x500'0008u,0b1111100000u); + agbx_set10(0x500'000Au,0b111111111100000u); + agbx_set10(0x500'000Cu,0b111110000000000u); + agbx_set10(0x500'000Eu,0b111110000011111u); + agbx_set10(0x400'0000u,0x404u); + agbx_clrscrn4(0x600'0000u,0x0u); + agbx_clrscrn4(0x600'A000u,0x0u); +} diff --git a/demo/source/loop.c b/demo/source/loop.c new file mode 100644 index 0000000..003ac61 --- /dev/null +++ b/demo/source/loop.c @@ -0,0 +1,29 @@ +#include <agbx-demo.h> + +#include <agbx/key.h> +#include <agbx/gfx.h> + +bool agbxd_loop(agbxd_dat * const _dat) { + bool err = false; + _dat->prevcol = 0x0u; + agbx_plot4(_dat->vaddr,_dat->pos.x,_dat->pos.y,0x1u); + for (;;) { + _dat->prevpos = _dat->pos; + agbxd_upd const upd = agbxd_chkkeys(_dat); + if (upd.done) { + err = upd.err; + break; + } + agbx_vsync(); + if (upd.drw) { + _dat->prevcol = _dat->col; + if (upd.mv) {agbx_plot4(_dat->vaddr,_dat->pos.x,_dat->pos.y,_dat->col);} + } + if (upd.mv) { + agbx_plot4(_dat->vaddr,_dat->prevpos.x,_dat->prevpos.y,_dat->prevcol); + _dat->prevcol = agbx_rd4(_dat->vaddr,_dat->pos.x,_dat->pos.y); + agbx_plot4(_dat->vaddr,_dat->pos.x,_dat->pos.y,0x1u); + } + } + return err; +} diff --git a/demo/source/main.c b/demo/source/main.c new file mode 100644 index 0000000..fe75179 --- /dev/null +++ b/demo/source/main.c @@ -0,0 +1,18 @@ +#include <agbx-demo.h> + +#include <agbx/key.h> +#include <agbx/gfx.h> + +agbx_err agbx_main(void) { + agbxd_dat dat; + agbxd_initdat(&dat); + agbxd_initgfx(); + bool const err = agbxd_loop(&dat); + if (err) { + for (agbx_i10 px = 0x0u;px != 0x9600u;++px) { + agbx_setpx1(dat.vaddr,px,dat.col); + agbxd_chgcol(&dat,0x1u); + } + } + return err ? agbx_err_max : agbx_err_ok; +} |