diff options
Diffstat (limited to 'demo/source')
-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 |
6 files changed, 155 insertions, 0 deletions
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; +} |