summaryrefslogtreecommitdiff
path: root/demo
diff options
context:
space:
mode:
Diffstat (limited to 'demo')
-rw-r--r--demo/GNUmakefile24
-rw-r--r--demo/include/agbx-demo.h13
-rw-r--r--demo/source/chgcol.c3
-rw-r--r--demo/source/chkkeys.c8
-rw-r--r--demo/source/initdat.c6
-rw-r--r--demo/source/initgfx.c31
-rw-r--r--demo/source/loop.c11
-rw-r--r--demo/source/main.c19
-rw-r--r--demo/source/setcolbdr.c18
-rw-r--r--demo/source/start.c65
10 files changed, 140 insertions, 58 deletions
diff --git a/demo/GNUmakefile b/demo/GNUmakefile
index 27be37f..9e19631 100644
--- a/demo/GNUmakefile
+++ b/demo/GNUmakefile
@@ -26,19 +26,21 @@ CFLAGS := \
-nostdlib \
-std=c2x
-LDFLAGS := \
- -L../agbx \
- -Tscript.ld
+LDFLAGS := \
+ -L../agbx \
+ -Tscript.ld \
+ -znoexecstack
# BINARIES
-OBJS := \
- source/chkkeys.o \
- source/chgcol.o \
- source/initdat.o \
- source/initgfx.o \
- source/loop.o \
- source/main.o
+OBJS := \
+ source/chkkeys.o \
+ source/chgcol.o \
+ source/initdat.o \
+ source/initgfx.o \
+ source/loop.o \
+ source/setcolbdr.o \
+ source/start.o
ROMHDR := hdr.o
@@ -52,7 +54,7 @@ IMG := demo.gba
.PHONY: clean purge
$(IMG): $(ROMHDR) $(OBJS)
- $(LD) $(LDFLAGS) -odemo.elf -znoexecstack $(^) $(LDLIBS)
+ $(LD) $(LDFLAGS) -odemo.elf $(^) $(LDLIBS)
$(OBJCOPY) -Obinary demo.elf $(@)
agbsum -psi$(@)
diff --git a/demo/include/agbx-demo.h b/demo/include/agbx-demo.h
index 0bb0b22..6b354c6 100644
--- a/demo/include/agbx-demo.h
+++ b/demo/include/agbx-demo.h
@@ -23,11 +23,12 @@ typedef struct {
bool mv;
} axd_upd;
-axd_upd axd_chkkeys(axd_dat * dat);
-void axd_chgcol( axd_dat * dat,ax_i8 dir);
-void axd_drw( axd_dat * dat);
-void axd_initdat(axd_dat * dat);
-void axd_initgfx(void);
-bool axd_loop( axd_dat * dat);
+axd_upd axd_chkkeys( axd_dat * dat);
+void axd_chgcol( axd_dat * dat, ax_i8 dir);
+void axd_drw( axd_dat * dat);
+void axd_initdat( axd_dat * dat);
+void axd_initgfx( void);
+bool axd_loop( axd_dat * dat);
+void axd_setcolbdr(ax_i02 vaddr,ax_i01 col);
#endif
diff --git a/demo/source/chgcol.c b/demo/source/chgcol.c
index 554c2d3..4519319 100644
--- a/demo/source/chgcol.c
+++ b/demo/source/chgcol.c
@@ -3,7 +3,7 @@
#include <ax/gfx.h>
void axd_chgcol(axd_dat * _dat,ax_i8 const _dir) {
- constexpr ax_i8 maxcol = 0x7u;
+ constexpr ax_i8 maxcol = 0xEu;
ax_i8 col = _dat->col;
if (!_dir) {
if (!col) {col = maxcol;}
@@ -14,4 +14,5 @@ void axd_chgcol(axd_dat * _dat,ax_i8 const _dir) {
else {++col;}
}
_dat->col = col;
+ axd_setcolbdr(_dat->vaddr,col);
}
diff --git a/demo/source/chkkeys.c b/demo/source/chkkeys.c
index 394495c..8e2a76c 100644
--- a/demo/source/chkkeys.c
+++ b/demo/source/chkkeys.c
@@ -32,28 +32,28 @@ axd_upd axd_chkkeys(axd_dat * _dat) {
axd_wait()
}
axd_chk(ax_key_pade) {
- if (_dat->pos.x != 0xEFu) {
+ if (_dat->pos.x != 0xEEu) {
upd.mv = true;
++_dat->pos.x;
axd_wait()
}
}
axd_chk(ax_key_padn) {
- if (_dat->pos.y != 0x0u) {
+ if (_dat->pos.y != 0x1u) {
upd.mv = true;
--_dat->pos.y;
axd_wait()
}
}
axd_chk(ax_key_pads) {
- if (_dat->pos.y != 0x9Fu) {
+ if (_dat->pos.y != 0x9Eu) {
upd.mv = true;
++_dat->pos.y;
axd_wait()
}
}
axd_chk(ax_key_padw) {
- if (_dat->pos.x != 0x0u) {
+ if (_dat->pos.x != 0x1u) {
upd.mv = true;
--_dat->pos.x;
axd_wait()
diff --git a/demo/source/initdat.c b/demo/source/initdat.c
index 86f0e6b..4650593 100644
--- a/demo/source/initdat.c
+++ b/demo/source/initdat.c
@@ -3,8 +3,8 @@
#include <ax/gfx.h>
void axd_initdat(axd_dat * const _dat) {
- _dat->col = 0x2u;
- _dat->pos.x = 0x0u;
- _dat->pos.y = 0x0u;
+ _dat->col = 0x4u;
+ _dat->pos.x = 0x1u;
+ _dat->pos.y = 0x1u;
_dat->vaddr = 0x600'0000u;
}
diff --git a/demo/source/initgfx.c b/demo/source/initgfx.c
index 342bf20..14ea24f 100644
--- a/demo/source/initgfx.c
+++ b/demo/source/initgfx.c
@@ -2,15 +2,28 @@
#include <ax/gfx.h>
+static_assert(ax_col(0x1Fu,0x0u,0x0u) == 0b000000000011111u);
+static_assert(ax_col(0x0u,0x1Fu,0x0u) == 0b000001111100000u);
+static_assert(ax_col(0x0u,0x0u,0x1Fu) == 0b111110000000000u);
+
void axd_initgfx(void) {
- ax_set10(0x500'0000u,0b000000000000000u);
- ax_set10(0x500'0002u,0b111111111111111u);
- ax_set10(0x500'0004u,0b000000000011111u);
- ax_set10(0x500'0006u,0b00001111111111u);
- ax_set10(0x500'0008u,0b00001111100000u);
- ax_set10(0x500'000Au,0b111111111100000u);
- ax_set10(0x500'000Cu,0b111110000000000u);
- ax_set10(0x500'000Eu,0b111110000011111u);
+ ax_set10(0x500'0000u,ax_col(0x00u,0x00u,0x00u)); /* Black */
+ ax_set10(0x500'0002u,ax_col(0x07u,0x07u,0x07u)); /* Darkgrey */
+ ax_set10(0x500'0004u,ax_col(0x0Fu,0x0Fu,0x0Fu)); /* Grey */
+ ax_set10(0x500'0006u,ax_col(0x17u,0x17u,0x17u)); /* Lightgrey */
+ ax_set10(0x500'0008u,ax_col(0x1Fu,0x1Fu,0x1Fu)); /* White */
+ ax_set10(0x500'000Au,ax_col(0x11u,0x01u,0x07u)); /* Red */
+ ax_set10(0x500'000Cu,ax_col(0x15u,0x06u,0x02u)); /* Vermillion */
+ ax_set10(0x500'000Eu,ax_col(0x1Bu,0x0Eu,0x04u)); /* Orange */
+ ax_set10(0x500'0010u,ax_col(0x1Du,0x12u,0x01u)); /* Amber */
+ ax_set10(0x500'0012u,ax_col(0x1Du,0x17u,0x01u)); /* Yellow */
+ ax_set10(0x500'0014u,ax_col(0x12u,0x19u,0x05u)); /* Chartreuse */
+ ax_set10(0x500'0016u,ax_col(0x04u,0x0Fu,0x03u)); /* Green */
+ ax_set10(0x500'0018u,ax_col(0x04u,0x11u,0x0Du)); /* Teal */
+ ax_set10(0x500'001Au,ax_col(0x04u,0x08u,0x16u)); /* Blue */
+ ax_set10(0x500'001Cu,ax_col(0x08u,0x05u,0x10u)); /* Violet */
+ ax_set10(0x500'001Eu,ax_col(0x0Au,0x05u,0x11u)); /* Purple */
+ ax_set10(0x500'0020u,ax_col(0x11u,0x03u,0x15u)); /* Magenta */
ax_set10(0x400'0000u,0x404u);
- ax_clrscrn1(0x600'A000u,0x0u);
+ ax_clrscrn1(0x600'0000u,0x0u);
}
diff --git a/demo/source/loop.c b/demo/source/loop.c
index c5f88c6..65779fa 100644
--- a/demo/source/loop.c
+++ b/demo/source/loop.c
@@ -6,7 +6,8 @@
bool axd_loop(axd_dat * const _dat) {
bool err = false;
_dat->prevcol = 0x0u;
- ax_plot1(_dat->vaddr,ax_coord3(_dat->pos.x,_dat->pos.y),0x1u);
+ axd_setcolbdr(_dat->vaddr,_dat->col);
+ ax_plot1(_dat->vaddr,ax_coord(ax_scrnw3,_dat->pos.x,_dat->pos.y),0x4u);
for (;;) {
_dat->prevpos = _dat->pos;
axd_upd const upd = axd_chkkeys(_dat);
@@ -17,12 +18,12 @@ bool axd_loop(axd_dat * const _dat) {
ax_vsync();
if (upd.drw) {
_dat->prevcol = _dat->col;
- if (upd.mv) {ax_plot1(_dat->vaddr,ax_coord3(_dat->pos.x,_dat->pos.y),_dat->col);}
+ if (upd.mv) {ax_plot1(_dat->vaddr,ax_coord(ax_scrnw3,_dat->pos.x,_dat->pos.y),_dat->col);}
}
if (upd.mv) {
- ax_plot1(_dat->vaddr,ax_coord3(_dat->prevpos.x,_dat->prevpos.y),_dat->prevcol);
- _dat->prevcol = ax_rd1(_dat->vaddr,ax_coord3(_dat->pos.x,_dat->pos.y));
- ax_plot1(_dat->vaddr,ax_coord3(_dat->pos.x,_dat->pos.y),0x1u);
+ ax_plot1(_dat->vaddr,ax_coord(ax_scrnw3,_dat->prevpos.x,_dat->prevpos.y),_dat->prevcol);
+ _dat->prevcol = ax_rd1(_dat->vaddr,ax_coord(ax_scrnw3,_dat->pos.x,_dat->pos.y));
+ ax_plot1(_dat->vaddr,ax_coord(ax_scrnw3,_dat->pos.x,_dat->pos.y),0x4u);
}
}
return err;
diff --git a/demo/source/main.c b/demo/source/main.c
deleted file mode 100644
index ca31e5c..0000000
--- a/demo/source/main.c
+++ /dev/null
@@ -1,19 +0,0 @@
-#include <agbx-demo.h>
-
-#include <ax/key.h>
-#include <ax/gfx.h>
-
-ax_err ax_main(void) {
- axd_dat dat;
- axd_initdat(&dat);
- axd_initgfx();
- bool const err = axd_loop(&dat);
- if (err) {
- for (ax_i01 px = 0x0u;px != 0x9600u;++px) {
- ax_plot1(dat.vaddr,px,dat.col);
- axd_chgcol(&dat,0x1u);
- }
- return ax_err_max;
- }
- return ax_err_ok;
-}
diff --git a/demo/source/setcolbdr.c b/demo/source/setcolbdr.c
new file mode 100644
index 0000000..1173d55
--- /dev/null
+++ b/demo/source/setcolbdr.c
@@ -0,0 +1,18 @@
+#include <agbx-demo.h>
+
+#include <ax/gfx.h>
+
+void axd_setcolbdr(ax_i02 const _vaddr,ax_i01 const _col) {
+ for (ax_i01 px = 0x0u;px != 0xF0u;++px) {
+ ax_plot1(_vaddr,px,_col);
+ }
+ for (ax_i01 px = 0xEFu;px != ax_scrnh3 * ax_scrnw3 + 0xEFu;px += ax_scrnw3) {
+ ax_plot1(_vaddr,px,_col);
+ }
+ for (ax_i01 px = 0x9Fu * ax_scrnw3;px != 0x9Fu * ax_scrnw3 + 0xF0u;++px) {
+ ax_plot1(_vaddr,px,_col);
+ }
+ for (ax_i01 px = 0x0u;px != ax_scrnh3 * ax_scrnw3;px += ax_scrnw3) {
+ ax_plot1(_vaddr,px,_col);
+ }
+}
diff --git a/demo/source/start.c b/demo/source/start.c
new file mode 100644
index 0000000..15da8f6
--- /dev/null
+++ b/demo/source/start.c
@@ -0,0 +1,65 @@
+#include <agbx-demo.h>
+
+#include <ax/key.h>
+#include <ax/gfx.h>
+
+static ax_i8 const axd_logo[] = {
+ 0x00u,0x00u, 0x00u,0x00u,0x00u,0x00u,0x00u,0x00u,0x00u, 0x00u, 0x00u,0x00u,0x00u,0x00u,0x00u,0x00u,0x00u, 0x00u, 0x00u,0x00u,0x00u,0x00u,0x00u,0x00u,0x00u, 0x00u, 0x00u,0x00u,0x00u,0x00u,0x00u,0x00u,0x00u, 0x00u,0x00u,
+ 0x00u,0x04u, 0x04u,0x04u,0x04u,0x04u,0x04u,0x04u,0x04u, 0x04u, 0x04u,0x04u,0x04u,0x04u,0x04u,0x04u,0x04u, 0x04u, 0x04u,0x04u,0x04u,0x04u,0x04u,0x04u,0x04u, 0x04u, 0x04u,0x04u,0x04u,0x04u,0x04u,0x04u,0x04u, 0x04u,0x00u,
+
+ 0x00u,0x04u, 0x04u,0x04u,0x07u,0x08u,0x09u,0x04u,0x04u, 0x04u, 0x04u,0x0Du,0x0Eu,0x0Fu,0x10u,0x05u,0x04u, 0x04u, 0x07u,0x08u,0x09u,0x0Au,0x0Bu,0x0Cu,0x04u, 0x04u, 0x0Eu,0x0Fu,0x04u,0x04u,0x04u,0x07u,0x08u, 0x04u,0x00u,
+ 0x00u,0x04u, 0x04u,0x06u,0x07u,0x08u,0x09u,0x0Au,0x04u, 0x04u, 0x0Cu,0x0Du,0x0Eu,0x0Fu,0x10u,0x05u,0x06u, 0x04u, 0x07u,0x08u,0x09u,0x0Au,0x0Bu,0x0Cu,0x0Du, 0x04u, 0x0Eu,0x0Fu,0x10u,0x04u,0x06u,0x07u,0x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+ 0x00u,0x04u, 0x04u,0x04u,0x04u,0x04u,0x04u,0x04u,0x04u, 0x04u, 0x04u,0x04u,0x04u,0x04u,0x04u,0x04u,0x04u, 0x04u, 0x04u,0x04u,0x04u,0x04u,0x04u,0x04u,0x04u, 0x04u, 0x04u,0x04u,0x04u,0x04u,0x04u,0x04u,0x04u, 0x04u,0x00u,
+ 0x04u,0x00u, 0x00u,0x00u,0x00u,0x00u,0x00u,0x00u,0x00u, 0x00u, 0x00u,0x00u,0x00u,0x00u,0x00u,0x00u,0x00u, 0x00u, 0x00u,0x00u,0x00u,0x00u,0x00u,0x00u,0x00u, 0x00u, 0x00u,0x00u,0x00u,0x00u,0x00u,0x00u,0x00u, 0x00u,0x04u,
+
+ 0x04u,0x00u, 0x04u,0x04u,0x04u,0x04u,0x04u,0x04u,0x00u, 0x00u, 0x04u,0x04u,0x04u,0x04u,0x04u,0x04u,0x04u, 0x00u, 0x04u,0x04u,0x00u,0x00u,0x00u,0x04u,0x04u, 0x00u, 0x00u,0x04u,0x04u,0x04u,0x04u,0x04u,0x00u, 0x00u,0x04u,
+ 0x04u,0x00u, 0x04u,0x03u,0x03u,0x03u,0x03u,0x02u,0x02u, 0x00u, 0x04u,0x02u,0x02u,0x02u,0x02u,0x02u,0x02u, 0x00u, 0x04u,0x03u,0x04u,0x00u,0x04u,0x03u,0x02u, 0x00u, 0x04u,0x04u,0x03u,0x03u,0x03u,0x02u,0x02u, 0x00u,0x04u,
+ 0x04u,0x00u, 0x04u,0x03u,0x00u,0x00u,0x00u,0x03u,0x02u, 0x00u, 0x04u,0x02u,0x00u,0x00u,0x00u,0x00u,0x00u, 0x00u, 0x04u,0x02u,0x02u,0x04u,0x02u,0x03u,0x02u, 0x00u, 0x04u,0x03u,0x00u,0x00u,0x00u,0x03u,0x02u, 0x00u,0x04u,
+ 0x04u,0x00u, 0x04u,0x03u,0x00u,0x00u,0x00u,0x03u,0x02u, 0x00u, 0x04u,0x02u,0x02u,0x02u,0x00u,0x00u,0x00u, 0x00u, 0x04u,0x02u,0x00u,0x02u,0x00u,0x03u,0x02u, 0x00u, 0x04u,0x03u,0x00u,0x00u,0x00u,0x03u,0x02u, 0x00u,0x04u,
+ 0x04u,0x00u, 0x04u,0x03u,0x00u,0x00u,0x00u,0x03u,0x02u, 0x00u, 0x04u,0x02u,0x00u,0x00u,0x00u,0x00u,0x00u, 0x00u, 0x04u,0x02u,0x00u,0x00u,0x00u,0x03u,0x02u, 0x00u, 0x04u,0x03u,0x00u,0x00u,0x00u,0x03u,0x02u, 0x00u,0x04u,
+ 0x04u,0x00u, 0x04u,0x03u,0x03u,0x03u,0x03u,0x02u,0x02u, 0x00u, 0x04u,0x03u,0x03u,0x03u,0x03u,0x03u,0x02u, 0x00u, 0x04u,0x02u,0x00u,0x00u,0x00u,0x03u,0x02u, 0x00u, 0x04u,0x02u,0x03u,0x03u,0x03u,0x02u,0x02u, 0x00u,0x04u,
+ 0x04u,0x00u, 0x04u,0x02u,0x02u,0x02u,0x02u,0x02u,0x00u, 0x00u, 0x04u,0x02u,0x02u,0x02u,0x02u,0x02u,0x02u, 0x00u, 0x04u,0x02u,0x00u,0x00u,0x00u,0x02u,0x02u, 0x00u, 0x00u,0x02u,0x02u,0x02u,0x02u,0x02u,0x00u, 0x00u,0x04u,
+
+ 0x04u,0x00u, 0x00u,0x00u,0x00u,0x00u,0x00u,0x00u,0x00u, 0x00u, 0x00u,0x00u,0x00u,0x00u,0x00u,0x00u,0x00u, 0x00u, 0x00u,0x00u,0x00u,0x00u,0x00u,0x00u,0x00u, 0x00u, 0x00u,0x00u,0x00u,0x00u,0x00u,0x00u,0x00u, 0x00u,0x04u,
+ 0x04u,0x04u, 0x04u,0x04u,0x04u,0x04u,0x04u,0x04u,0x04u, 0x04u, 0x04u,0x04u,0x04u,0x04u,0x04u,0x04u,0x04u, 0x04u, 0x04u,0x04u,0x04u,0x04u,0x04u,0x04u,0x04u, 0x04u, 0x04u,0x04u,0x04u,0x04u,0x04u,0x04u,0x04u, 0x04u,0x04u,
+};
+
+constexpr ax_i8 axd_logow = (0x7u * 0x4u) + (0x2u * 0x2u) + (0x1u * 0x3u);
+constexpr ax_i8 axd_logoh = (0x7u * 0x2u) + (0x2u * 0x2u) + (0x2u);
+
+static_assert(sizeof (axd_logo) == axd_logow * axd_logoh);
+
+ax_err ax_start(void) {
+ axd_dat dat;
+ axd_initdat(&dat);
+ axd_initgfx();
+ ax_plottex1(dat.vaddr,ax_scrnw3,axd_logo,ax_coord(ax_scrnw3,ax_scrnw3 / 0x2u - axd_logow / 0x2u,ax_scrnh3 / 0x2u - axd_logoh / 0x2u),axd_logow,axd_logoh);
+ for (;;) {
+ ax_keymap const keymap = ax_getkeymap();
+ if (ax_chkkey(keymap,ax_key_a)) {
+ break;
+ }
+ }
+ for (;;) { /* Wait for the key to become released. */
+ ax_keymap const keymap = ax_getkeymap();
+ if (!ax_chkkey(keymap,ax_key_a)) {
+ break;
+ }
+ }
+ ax_clrscrn1(dat.vaddr,0x0u);
+ bool const err = axd_loop(&dat);
+ if (err) {
+ for (ax_i01 px = 0x0u;px != 0x9600u;++px) {
+ ax_plot1(dat.vaddr,px,dat.col);
+ axd_chgcol(&dat,0x1u);
+ }
+ return ax_err_max;
+ }
+ return ax_err_ok;
+}