summaryrefslogtreecommitdiff
path: root/agbx
diff options
context:
space:
mode:
Diffstat (limited to 'agbx')
-rw-r--r--agbx/GNUmakefile2
-rw-r--r--agbx/include/agbx/bs.h1
-rw-r--r--agbx/include/agbx/gfx.h19
-rw-r--r--agbx/source/bs/get.s15
-rw-r--r--agbx/source/bs/set.s15
-rw-r--r--agbx/source/gfx/flip.s13
-rw-r--r--agbx/source/gfx/getpx.s2
-rw-r--r--agbx/source/gfx/getvbnk.s11
-rw-r--r--agbx/source/gfx/setpx.c21
-rw-r--r--agbx/source/gfx/vsync.s21
-rw-r--r--agbx/source/key/getkeymap.s7
-rw-r--r--agbx/source/priv/init.s1
12 files changed, 70 insertions, 58 deletions
diff --git a/agbx/GNUmakefile b/agbx/GNUmakefile
index afd8f50..ede1e96 100644
--- a/agbx/GNUmakefile
+++ b/agbx/GNUmakefile
@@ -25,7 +25,7 @@ CFLAGS := \
-mthumb \
-mtune=arm7tdmi \
-nostdlib \
- --std=c2x
+ -std=c2x
# HEADERS
diff --git a/agbx/include/agbx/bs.h b/agbx/include/agbx/bs.h
index a9869fa..7d38d73 100644
--- a/agbx/include/agbx/bs.h
+++ b/agbx/include/agbx/bs.h
@@ -9,7 +9,6 @@
/* C23 compatibility: */
#define constexpr static const
-#define nullptr ((void *)0x0u)
#define typeof __typeof__
typedef unsigned short agbx_i10;
diff --git a/agbx/include/agbx/gfx.h b/agbx/include/agbx/gfx.h
index beec93b..07e74e6 100644
--- a/agbx/include/agbx/gfx.h
+++ b/agbx/include/agbx/gfx.h
@@ -31,4 +31,23 @@ agbx_i10 agbx_rd3(agbx_i8 x, agbx_i8 y);
agbx_i8 agbx_rd4(agbx_i20 vaddr,agbx_i8 x,agbx_i8 y);
agbx_i10 agbx_rd5(agbx_i20 vaddr,agbx_i8 x,agbx_i8 y);
+void agbx_cir3(agbx_i8 x, agbx_i8 y,agbx_i8 r);
+void agbx_cir4(agbx_i20 vaddr,agbx_i8 x,agbx_i8 y,agbx_i8 r);
+void agbx_cir5(agbx_i20 vaddr,agbx_i8 x,agbx_i8 y,agbx_i8 r);
+
+#if false
+void agbx_setpx1(agbx_i20 const _vaddr,agbx_i10 const _px,agbx_i8 const _col) {
+ /* We can only write halfwords to VRAM, so we need to load the adjacent pixel value and combine it into a halfword. */
+ agbx_i20 const addr = _vaddr + _px - (_px & 0x1u) * 0x1u;
+ agbx_i10 col;
+ if (_px & 0x1u) {col = (agbx_i10)agbx_get8(addr) | (agbx_i10)_col << 0x8u;}
+ else {col = (agbx_i10)agbx_get8(addr + 0x1u) << 0x8u | (agbx_i10)_col;}
+ __agbx_set10(addr,col);
+}
+
+void agbx_setpx2(agbx_i20 const _vaddr,agbx_i10 const _px,agbx_i10 const _col) {
+ __agbx_setpx2(_vaddr,_px,_col)
+}
+#endif
+
#endif
diff --git a/agbx/source/bs/get.s b/agbx/source/bs/get.s
index dfd6453..b827dec 100644
--- a/agbx/source/bs/get.s
+++ b/agbx/source/bs/get.s
@@ -12,31 +12,28 @@
.globl agbx_get8
.func
-
.thumb_func
agbx_get10:
- ldrh r0,[r0]
- bx lr
+ ldrh r0,[r0] @ agbx_i10 val = *(agbx_i10 *)addr;
+ bx lr @ return val;
.endfunc
.func
-
.thumb_func
agbx_get20:
- ldr r0,[r0]
- bx lr
+ ldr r0,[r0] @ agbx_i20 val = *(agbx_i20 *)addr;
+ bx lr @ return val;
.endfunc
.func
-
.thumb_func
agbx_get8:
- ldrb r0,[r0]
- bx lr
+ ldrb r0,[r0] @ agbx_i8 val = *(agbx_i8 *)addr;
+ bx lr @ return val;
.endfunc
diff --git a/agbx/source/bs/set.s b/agbx/source/bs/set.s
index 93ea3b5..85e6372 100644
--- a/agbx/source/bs/set.s
+++ b/agbx/source/bs/set.s
@@ -12,31 +12,28 @@
.globl agbx_set8
.func
-
.thumb_func
agbx_set10:
- strh r1,[r0]
- bx lr
+ strh r1,[r0] @ *(agbx_i10 *)addr = val;
+ bx lr @ return;
.endfunc
.func
-
.thumb_func
agbx_set20:
- str r1,[r0]
- bx lr
+ str r1,[r0] @ *(agbx_i20 *)addr = val;
+ bx lr @ return;
.endfunc
.func
-
.thumb_func
agbx_set8:
- strb r1,[r0]
- bx lr
+ strb r1,[r0] @ *(agbx_i8 *)addr = val;
+ bx lr @ return;
.endfunc
diff --git a/agbx/source/gfx/flip.s b/agbx/source/gfx/flip.s
index 019289d..32171d1 100644
--- a/agbx/source/gfx/flip.s
+++ b/agbx/source/gfx/flip.s
@@ -12,25 +12,24 @@
.globl agbx_flip
.func
-
.thumb_func
agbx_flip:
@ Get the current value of dispcnt:
- ldr r0,.dispcntaddr
- ldrh r1,[r0]
+ ldr r0,.dispcntaddr @ agbx_i20 dispcntaddr = 0x4000000u;
+ ldrh r1,[r0] @ agbx_i10 dispcnt = *(agbx_i10 *)dispcntaddr;
@ XOR bit five:
movs r2,0b10000
- eors r1,r2
+ eors r1,r2 @ dispcnt ^= 0b10000u;
@ Save dispcnt:
- strh r1,[r0]
+ strh r1,[r0] @ *(agbx_i10 *)dispcntaddr = dispcnt;
@ Get the address of the video bank:
- b __agbx_getvbnk
+ b __agbx_getvbnk @ agbx_i20 vaddr = __agbx_getvbnk();
- bx lr
+ bx lr @ return vaddr;
.endfunc
diff --git a/agbx/source/gfx/getpx.s b/agbx/source/gfx/getpx.s
index f583b56..f5a976f 100644
--- a/agbx/source/gfx/getpx.s
+++ b/agbx/source/gfx/getpx.s
@@ -11,7 +11,6 @@
.globl agbx_getpx2
.func
-
.thumb_func
agbx_getpx1:
@@ -22,7 +21,6 @@ agbx_getpx1:
.endfunc
.func
-
.thumb_func
agbx_getpx2:
diff --git a/agbx/source/gfx/getvbnk.s b/agbx/source/gfx/getvbnk.s
index 6898266..f2e22ae 100644
--- a/agbx/source/gfx/getvbnk.s
+++ b/agbx/source/gfx/getvbnk.s
@@ -11,30 +11,27 @@
.globl agbx_getvbnk
.func
-
.thumb_func
agbx_getvbnk:
@ Get the current value of dispcnt:
- ldr r0,.dispcntaddr
- ldrh r1,[r0]
+ ldr r0,.dispcntaddr @ agbx_i20 dispcntaddr = 0x4000000u;
+ ldrh r1,[r0] @ agbx_i10 dispcnt = *(agbx_i10 *)dispcntaddr;
@ Get the address:
- b __agbx_getvbnk
+ b __agbx_getvbnk @ agbx_i20 vaddr = __agbx_getvbnk();
- bx lr
+ bx lr @ return vaddr;
.endfunc
.func
-
.thumb_func
__agbx_getvbnk: @ Takes the value of dispcnt in r1.
@ Check if the fifth bit is set:
movs r0,0b10000
tst r1,r0
-
beq .vbnk1
.vbnk0:
diff --git a/agbx/source/gfx/setpx.c b/agbx/source/gfx/setpx.c
index e478603..322784e 100644
--- a/agbx/source/gfx/setpx.c
+++ b/agbx/source/gfx/setpx.c
@@ -10,13 +10,22 @@
void agbx_setpx1(agbx_i20 const _vaddr,agbx_i10 const _px,agbx_i8 const _col) {
/* We can only write halfwords to VRAM, so we need to load the adjacent pixel value and combine it into a halfword. */
- agbx_i20 const addr = _vaddr + _px - (_px & 0x1u) * 0x1u;
- agbx_i10 col;
- if (_px & 0x1u) {col = (agbx_i10)agbx_get8(addr) | (agbx_i10)_col << 0x8u;}
- else {col = (agbx_i10)agbx_get8(addr + 0x1u) << 0x8u | (agbx_i10)_col;}
- __agbx_set10(addr,col);
+ bool const odd = _px & 0x1u;
+ agbx_i20 addr = _vaddr + _px - odd;
+ agbx_i10 precol = __agbx_get10(addr);
+ agbx_i10 col = _col;
+ if (odd) {
+ precol &= 0b11111111u;
+ col <<= 0x8u;
+ }
+ else {
+ precol &= 0b1111111100000000u;
+ }
+ agbx_i10 const newcol = precol | col;
+ __agbx_set10(addr,newcol);
}
void agbx_setpx2(agbx_i20 const _vaddr,agbx_i10 const _px,agbx_i10 const _col) {
- __agbx_setpx2(_vaddr,_px,_col)
+ agbx_i20 const addr = _vaddr + _px;
+ __agbx_set10(addr,_col);
}
diff --git a/agbx/source/gfx/vsync.s b/agbx/source/gfx/vsync.s
index 5bfbe06..2e6ac3f 100644
--- a/agbx/source/gfx/vsync.s
+++ b/agbx/source/gfx/vsync.s
@@ -10,29 +10,28 @@
.globl agbx_vsync
.func
-
.thumb_func
agbx_vsync:
@ Set the constants:
- ldr r0,.scancnt @ Address of the scanline counter register.
- movs r1,0xA0 @ Number of horizontal lines;
+ ldr r0,.vcountaddr @ agbx_i20 vcountaddr = 0x4000006u;
+ movs r1,0xA0 @ agbx_i20 numhline = 0xA0;
.loop:
@ Check the scanline counter:
- ldr r2,[r0] @ Load the counter.
- cmp r2,r1 @ Check if it has reached the bottom.
- beq .ret @ Return if so.
+ ldrh r2,[r0] @ agbx_i20 vcount = *(agbx_i10 *)vcountaddr;
+ cmp r2,r1
+ beq .ret @ if (vcount == numhline) {goto ret;}
+
+ b .loop @ goto loop;
.ret:
@ Return:
- bx lr
+ bx lr @ return;
.endfunc
.align
-.scancnt:
- .long 0x4000000
-
-.align
+.vcountaddr:
+ .long 0x4000006
diff --git a/agbx/source/key/getkeymap.s b/agbx/source/key/getkeymap.s
index e433f04..38c6dbe 100644
--- a/agbx/source/key/getkeymap.s
+++ b/agbx/source/key/getkeymap.s
@@ -10,15 +10,14 @@
.globl agbx_getkeymap
.func
-
.thumb_func
agbx_getkeymap:
@ Load the keys:
- ldr r0,.addr
- ldrh r0,[r0]
+ ldr r0,.addr @ agbx_i20 addr = 0x4000130u;
+ ldrh r0,[r0] @ agbx_keymap keymap = *(agbx_i10 *)addr;
- bx lr
+ bx lr @ return keymap;
.endfunc
diff --git a/agbx/source/priv/init.s b/agbx/source/priv/init.s
index 302cb29..b9f1f45 100644
--- a/agbx/source/priv/init.s
+++ b/agbx/source/priv/init.s
@@ -13,7 +13,6 @@
.globl __agbx_init
.func
-
.thumb_func
__agbx_init: