diff options
-rw-r--r-- | CHANGELOG.txt | 9 | ||||
-rw-r--r-- | agbx/include/ax/key.h | 33 | ||||
-rw-r--r-- | agbx/source/gfx/vsync.s | 37 | ||||
-rw-r--r-- | ax/GNUmakefile (renamed from agbx/GNUmakefile) | 9 | ||||
-rw-r--r-- | ax/include-private/ax/priv.h (renamed from agbx/include-private/ax/priv.h) | 10 | ||||
-rw-r--r-- | ax/include/ax/algo.h | 23 | ||||
-rw-r--r-- | ax/include/ax/bs.h (renamed from agbx/include/ax/bs.h) | 14 | ||||
-rw-r--r-- | ax/include/ax/gfx.h (renamed from agbx/include/ax/gfx.h) | 22 | ||||
-rw-r--r-- | ax/include/ax/key.h | 33 | ||||
-rw-r--r-- | ax/source/algo/cp.c | 16 | ||||
-rw-r--r-- | ax/source/algo/fill.c | 15 | ||||
-rw-r--r-- | ax/source/bs/done.c (renamed from agbx/source/bs/done.c) | 0 | ||||
-rw-r--r-- | ax/source/bs/get.s (renamed from agbx/source/bs/get.s) | 8 | ||||
-rw-r--r-- | ax/source/bs/set.s (renamed from agbx/source/bs/set.s) | 8 | ||||
-rw-r--r-- | ax/source/gfx/blnk.s | 35 | ||||
-rw-r--r-- | ax/source/gfx/clrscrn.cc (renamed from agbx/source/gfx/clrscrn.cc) | 4 | ||||
-rw-r--r-- | ax/source/gfx/flip.s (renamed from agbx/source/gfx/flip.s) | 3 | ||||
-rw-r--r-- | ax/source/gfx/getvbnk.s (renamed from agbx/source/gfx/getvbnk.s) | 0 | ||||
-rw-r--r-- | ax/source/gfx/plot.c (renamed from agbx/source/gfx/plot.c) | 8 | ||||
-rw-r--r-- | ax/source/gfx/plottex.cc (renamed from agbx/source/gfx/plottex.cc) | 2 | ||||
-rw-r--r-- | ax/source/gfx/rd.s (renamed from agbx/source/gfx/rd.s) | 0 | ||||
-rw-r--r-- | ax/source/gfx/setcol.s | 32 | ||||
-rw-r--r-- | ax/source/gfx/vsync.s | 42 | ||||
-rw-r--r-- | ax/source/key/getkeymap.s (renamed from agbx/source/key/getkeymap.s) | 0 | ||||
-rw-r--r-- | ax/source/priv/init.s (renamed from agbx/source/priv/init.s) | 0 | ||||
-rw-r--r-- | demo/GNUmakefile | 6 | ||||
-rw-r--r-- | demo/hdr.s | 4 | ||||
-rw-r--r-- | demo/include/ax-demo.h (renamed from demo/include/agbx-demo.h) | 0 | ||||
-rw-r--r-- | demo/source/chgcol.c | 2 | ||||
-rw-r--r-- | demo/source/chkkeys.c | 2 | ||||
-rw-r--r-- | demo/source/initdat.c | 2 | ||||
-rw-r--r-- | demo/source/initgfx.c | 40 | ||||
-rw-r--r-- | demo/source/loop.c | 2 | ||||
-rw-r--r-- | demo/source/setcolbdr.c | 2 | ||||
-rw-r--r-- | demo/source/start.c | 65 |
35 files changed, 346 insertions, 142 deletions
diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 2e8eed4..9f896fd 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,3 +1,12 @@ +# A.0 + +* Add more functions for drawing geometric shapes; +* Add function for configuring the palette; +* Re-add algorithms; +* Fix get and set using old naming convention; +* Rename project to ax; +* Update vsync; + # 9.1 * Remove algo references; diff --git a/agbx/include/ax/key.h b/agbx/include/ax/key.h deleted file mode 100644 index 88d6250..0000000 --- a/agbx/include/ax/key.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - 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>. -*/ - -#if !defined(__ax_hdr_key) -#define __ax_hdr_key - -#include <ax/bs.h> - -typedef enum { - ax_key_a = 0x0u, - ax_key_b = 0x1u, - ax_key_l = 0x9u, - ax_key_pade = 0x4u, - ax_key_padn = 0x6u, - ax_key_pads = 0x7u, - ax_key_padw = 0x5u, - ax_key_r = 0x8u, - ax_key_sel = 0x2u, - ax_key_start = 0x3u, -} ax_key; - -typedef struct { - ax_i01 _keys; -} ax_keymap; - -#define ax_chkkey(_map,_key) (!(bool)((_map)._keys >> (ax_i01)(_key) & 0x1u)) - -ax_keymap ax_getkeymap(void); - -#endif diff --git a/agbx/source/gfx/vsync.s b/agbx/source/gfx/vsync.s deleted file mode 100644 index e16724f..0000000 --- a/agbx/source/gfx/vsync.s +++ /dev/null @@ -1,37 +0,0 @@ -@ 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>. - -.syntax unified - -.cpu arm7tdmi -.thumb - -.globl ax_vsync - -.func -.thumb_func - -ax_vsync: - @ Set the constants: - ldr r0,.vcountaddr @ ax_i02 vcountaddr = 0x4000006u; - movs r1,0xA0 @ ax_i02 numhline = 0xA0; - -.loop: - @ Check the scanline counter: - ldrh r2,[r0] @ ax_i02 vcount = *(ax_i01 *)vcountaddr; - cmp r2,r1 - beq .ret @ if (vcount == numhline) {goto ret;} - - b .loop @ goto loop; - -.ret: - @ Return: - bx lr @ return; - -.endfunc - -.align - -.vcountaddr: - .long 0x4000006 diff --git a/agbx/GNUmakefile b/ax/GNUmakefile index e3ea1b0..054fcaa 100644 --- a/agbx/GNUmakefile +++ b/ax/GNUmakefile @@ -53,28 +53,33 @@ CXXFLAGS := \ # HEADERS HDRS := \ + include/ax/algo.h \ include/ax/bs.h \ include/ax/gfx.h \ include/ax/key.h \ include-private/ax/priv.h -# BINARIES +# ARTEFACTS OBJS := \ + source/algo/cp.o \ + source/algo/fill.o \ source/bs/done.o \ source/bs/get.o \ source/bs/set.o \ + source/gfx/blnk.o \ source/gfx/clrscrn.o \ source/gfx/flip.o \ source/gfx/getvbnk.o \ source/gfx/plot.o \ source/gfx/plottex.o \ source/gfx/rd.o \ + source/gfx/setcol.o \ source/gfx/vsync.o \ source/key/getkeymap.o \ source/priv/init.o -LIB := libagbx.a +LIB := libax.a # TARGETS diff --git a/agbx/include-private/ax/priv.h b/ax/include-private/ax/priv.h index 677d77f..e38ed64 100644 --- a/agbx/include-private/ax/priv.h +++ b/ax/include-private/ax/priv.h @@ -13,21 +13,21 @@ extern "C" { #endif -#define __ax_get10(_addr) (*(ax_i01 volatile *)_addr) +#define __ax_get01(_addr) (*(ax_i01 volatile *)_addr) -#define __ax_get20(_addr) (*(ax_i02 volatile *)_addr) +#define __ax_get02(_addr) (*(ax_i02 volatile *)_addr) #define __ax_get8(_addr) (*(ax_i8 volatile *)_addr) -#define __ax_set10(_addr,_val) ((void)(*(ax_i01 volatile *)_addr = _val)) +#define __ax_set01(_addr,_val) ((void)(*(ax_i01 volatile *)_addr = _val)) -#define __ax_set20(_addr,_val) ((void)(*(ax_i02 volatile *)_addr = _val)) +#define __ax_set02(_addr,_val) ((void)(*(ax_i02 volatile *)_addr = _val)) #define __ax_set8(_addr,_val) ((void)(*(ax_i8 volatile *)_addr = _val)) #define __ax_plot2(_vaddr,_px,_col) { \ ax_i02 const addr = _vaddr + _px * 0x2u; /* We multiply it by two as each pixel takes up two bytes. */ \ - __ax_set10(addr,_col); \ + __ax_set01(addr,_col); \ } #if defined(__cplusplus) diff --git a/ax/include/ax/algo.h b/ax/include/ax/algo.h new file mode 100644 index 0000000..6347ac4 --- /dev/null +++ b/ax/include/ax/algo.h @@ -0,0 +1,23 @@ +/* + 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>. +*/ + +#if !defined(__ax_hdr_algo) +#define __ax_hdr_algo + +#include <ax/bs.h> + +#if defined(__cplusplus) +extern "C" { +#endif + +void ax_cp( void const * in, ax_i02 num,void * out); +void ax_fill(void * ptr,ax_i02 num,ax_i8 byte); + +#if defined(__cplusplus) +} +#endif + +#endif diff --git a/agbx/include/ax/bs.h b/ax/include/ax/bs.h index 0bcfbd7..5a6b45a 100644 --- a/agbx/include/ax/bs.h +++ b/ax/include/ax/bs.h @@ -32,18 +32,20 @@ typedef enum { ax_err_max = 0xFFu, } ax_err; -constexpr ax_i04 ax_ver = 0x9u; +constexpr ax_i04 ax_ver = 0xAu; -[[noreturn]] void ax_done(ax_err err); +constexpr ax_i01 ax_sec = 0x1; -[[nodiscard]] ax_i01 ax_get10(ax_i02 addr); -[[nodiscard]] ax_i02 ax_get20(ax_i02 addr); +[[nodiscard]] ax_i01 ax_get01(ax_i02 addr); +[[nodiscard]] ax_i02 ax_get02(ax_i02 addr); [[nodiscard]] ax_i8 ax_get8( ax_i02 addr); -void ax_set10(ax_i02 addr,ax_i01 val); -void ax_set20(ax_i02 addr,ax_i02 val); +void ax_set01(ax_i02 addr,ax_i01 val); +void ax_set02(ax_i02 addr,ax_i02 val); void ax_set8( ax_i02 addr,ax_i8 val); +[[noreturn]] void ax_done(ax_err err); + #if defined(__cplusplus) } #endif diff --git a/agbx/include/ax/gfx.h b/ax/include/ax/gfx.h index 56405f1..c378bf8 100644 --- a/agbx/include/ax/gfx.h +++ b/ax/include/ax/gfx.h @@ -22,6 +22,7 @@ constexpr ax_i8 ax_scrnh5 = 0x80u; #define ax_col(_r,_g,_b) ((ax_i01)(((ax_i01)(_r) | (ax_i01)(_g) << 0x5u | (ax_i01)(_b) << 0xAu) & 0b000000111111111111111)) +void ax_blnk( void); ax_i02 ax_flip( void); ax_i02 ax_getvbnk(void); void ax_vsync( void); @@ -38,8 +39,25 @@ void ax_plottex2(ax_i02 vaddr,ax_i8 scrnw,ax_i01 const * tex,ax_i01 px,ax_i8 w,a ax_i8 ax_rd1(ax_i02 vaddr,ax_i01 px); ax_i01 ax_rd2(ax_i02 vaddr,ax_i01 px); -void ax_cir1(ax_i02 vaddr,ax_i8 scrnw,ax_i01 px,ax_i8 r,ax_i8 col); -void ax_cir2(ax_i02 vaddr,ax_i8 scrnw,ax_i01 px,ax_i8 r,ax_i01 col); +void ax_setcol(ax_i8 n,ax_i01 col); + +void ax_cir1( ax_i02 vaddr,ax_i8 scrnw,ax_i01 px,ax_i8 r,ax_i8 col); +void ax_cir2( ax_i02 vaddr,ax_i8 scrnw,ax_i01 px,ax_i8 r,ax_i01 col); +void ax_hcir1(ax_i02 vaddr,ax_i8 scrnw,ax_i01 px,ax_i8 r,ax_i8 col); +void ax_hcir2(ax_i02 vaddr,ax_i8 scrnw,ax_i01 px,ax_i8 r,ax_i01 col); + +void ax_ell1( ax_i02 vaddr,ax_i8 scrnw,ax_i01 px,ax_i8 rx,ax_i8 ry,ax_i8 col); +void ax_ell2( ax_i02 vaddr,ax_i8 scrnw,ax_i01 px,ax_i8 rx,ax_i8 ry,ax_i01 col); +void ax_hell1(ax_i02 vaddr,ax_i8 scrnw,ax_i01 px,ax_i8 rx,ax_i8 ry,ax_i8 col); +void ax_hell2(ax_i02 vaddr,ax_i8 scrnw,ax_i01 px,ax_i8 rx,ax_i8 ry,ax_i01 col); + +void ax_ln1(ax_i02 vaddr,ax_i8 scrnw,ax_i01 px0,ax_i01 px1,ax_i8 col); +void ax_ln2(ax_i02 vaddr,ax_i8 scrnw,ax_i01 px0,ax_i01 px1,ax_i01 col); + +void ax_rec1( ax_i02 vaddr,ax_i8 scrnw,ax_i01 px,ax_i8 w,ax_i8 h,ax_i8 col); +void ax_rec2( ax_i02 vaddr,ax_i8 scrnw,ax_i01 px,ax_i8 w,ax_i8 h,ax_i01 col); +void ax_hrec1(ax_i02 vaddr,ax_i8 scrnw,ax_i01 px,ax_i8 w,ax_i8 h,ax_i8 col); +void ax_hrec2(ax_i02 vaddr,ax_i8 scrnw,ax_i01 px,ax_i8 w,ax_i8 h,ax_i01 col); #if defined(__cplusplus) } diff --git a/ax/include/ax/key.h b/ax/include/ax/key.h new file mode 100644 index 0000000..ad70743 --- /dev/null +++ b/ax/include/ax/key.h @@ -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>. +*/ + +#if !defined(__ax_hdr_key) +#define __ax_hdr_key + +#include <ax/bs.h> + +typedef enum { + ax_key_a = 0b00000000'00000001u, + ax_key_b = 0b00000000'00000010u, + ax_key_l = 0b00000010'00000000u, + ax_key_pade = 0b00000000'00010000u, + ax_key_padn = 0b00000000'01000000u, + ax_key_pads = 0b00000000'10000000u, + ax_key_padw = 0b00000000'00100000u, + ax_key_r = 0b00000001'00000000u, + ax_key_sel = 0b00000000'00000100u, + ax_key_start = 0b00000000'00001000u, +} ax_key; + +typedef struct { + ax_i01 _keys; +} ax_keymap; + +#define ax_chkkey(_map,_key) ((bool)((_map)._keys & (ax_i01)(_key) ^ (ax_i01)(_key))) + +ax_keymap ax_getkeymap(void); + +#endif diff --git a/ax/source/algo/cp.c b/ax/source/algo/cp.c new file mode 100644 index 0000000..4f9ae7a --- /dev/null +++ b/ax/source/algo/cp.c @@ -0,0 +1,16 @@ +/* + 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 <ax/priv.h> + +#include <ax/algo.h> + +void ax_cp(void const * const _in,ax_i02 const _num,void * const _out) { + unsigned char const * in = _in; + unsigned char * out = _out; + unsigned char const * const afterbuf = in + _num; + for (;in != afterbuf;++in,++out) {*out = *in;} +} diff --git a/ax/source/algo/fill.c b/ax/source/algo/fill.c new file mode 100644 index 0000000..36961fd --- /dev/null +++ b/ax/source/algo/fill.c @@ -0,0 +1,15 @@ +/* + 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 <ax/priv.h> + +#include <ax/algo.h> + +void ax_fill(void * const _ptr,ax_i02 const _num,unsigned char const _byte) { + unsigned char * pos = _ptr; + unsigned char * const afterbuf = pos + _num; + for (;pos != afterbuf;++pos) {*pos = _byte;} +} diff --git a/agbx/source/bs/done.c b/ax/source/bs/done.c index 17b55c6..17b55c6 100644 --- a/agbx/source/bs/done.c +++ b/ax/source/bs/done.c diff --git a/agbx/source/bs/get.s b/ax/source/bs/get.s index a936f73..a4a1e8d 100644 --- a/agbx/source/bs/get.s +++ b/ax/source/bs/get.s @@ -7,14 +7,14 @@ .cpu arm7tdmi .thumb -.globl ax_get10 -.globl ax_get20 +.globl ax_get01 +.globl ax_get02 .globl ax_get8 .func .thumb_func -ax_get10: +ax_get01: ldrh r0,[r0] @ ax_i01 val = *(ax_i01 *)addr; bx lr @ return val; @@ -23,7 +23,7 @@ ax_get10: .func .thumb_func -ax_get20: +ax_get02: ldr r0,[r0] @ ax_i02 val = *(ax_i02 *)addr; bx lr @ return val; diff --git a/agbx/source/bs/set.s b/ax/source/bs/set.s index 1719be6..92f034d 100644 --- a/agbx/source/bs/set.s +++ b/ax/source/bs/set.s @@ -7,14 +7,14 @@ .cpu arm7tdmi .thumb -.globl ax_set10 -.globl ax_set20 +.globl ax_set01 +.globl ax_set02 .globl ax_set8 .func .thumb_func -ax_set10: +ax_set01: strh r1,[r0] @ *(ax_i01 *)addr = val; bx lr @ return; @@ -23,7 +23,7 @@ ax_set10: .func .thumb_func -ax_set20: +ax_set02: str r1,[r0] @ *(ax_i02 *)addr = val; bx lr @ return; diff --git a/ax/source/gfx/blnk.s b/ax/source/gfx/blnk.s new file mode 100644 index 0000000..c66c533 --- /dev/null +++ b/ax/source/gfx/blnk.s @@ -0,0 +1,35 @@ +@ 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>. + +.syntax unified + +.cpu arm7tdmi +.thumb + +.globl ax_blnk + +.func +.thumb_func + +ax_blnk: + @ Get the current value of dispcnt: + ldr r0,.dispcntaddr @ ax_i02 dispcntaddr = 0x4000000u; + ldrh r1,[r0] @ ax_i01 dispcnt = *(ax_i01 *)dispcntaddr; + + @ XOR bit seven: + movs r2,0b10000000 + eors r1,r2 @ dispcnt ^= 0b10000000u; + + @ Save dispcnt: + strh r1,[r0] @ *(ax_i01 *)dispcntaddr = dispcnt; + + @ Return: + bx lr @ return vaddr; + +.endfunc + +.align + +.dispcntaddr: + .long 0x4000000 diff --git a/agbx/source/gfx/clrscrn.cc b/ax/source/gfx/clrscrn.cc index 8f27268..b1bd3b7 100644 --- a/agbx/source/gfx/clrscrn.cc +++ b/ax/source/gfx/clrscrn.cc @@ -16,8 +16,8 @@ template<typename _pxtyp> [[gnu::always_inline]] inline static auto __ax_clrscrn } return (ax_i02)_col | (ax_i02)_col << 0x8u | (ax_i02)_col << 0x10u | (ax_i02)_col << 0x18u; }(); - for (::ax_i02 addr = _vaddr;addr != _vaddr + 0x9600u;addr += 0x4u) {__ax_set20(addr,val);} + for (::ax_i02 addr = _vaddr;addr != _vaddr + 0x9600u;addr += 0x4u) {__ax_set02(addr,val);} } -extern "C" auto ax_clrscrn1(::ax_i02 const _vaddr,::ax_i8 const _col) -> void {::__ax_clrscrn(_vaddr,_col);} +extern "C" auto ax_clrscrn1(::ax_i02 const _vaddr,::ax_i8 const _col) -> void {::__ax_clrscrn(_vaddr,_col);} extern "C" auto ax_clrscrn2(::ax_i02 const _vaddr,::ax_i01 const _col) -> void {::__ax_clrscrn(_vaddr,_col);} diff --git a/agbx/source/gfx/flip.s b/ax/source/gfx/flip.s index 887377d..2b09b04 100644 --- a/agbx/source/gfx/flip.s +++ b/ax/source/gfx/flip.s @@ -19,7 +19,7 @@ ax_flip: ldr r0,.dispcntaddr @ ax_i02 dispcntaddr = 0x4000000u; ldrh r1,[r0] @ ax_i01 dispcnt = *(ax_i01 *)dispcntaddr; - @ XOR bit five: + @ XOR bit four: movs r2,0b10000 eors r1,r2 @ dispcnt ^= 0b10000u; @@ -29,6 +29,7 @@ ax_flip: @ Get the address of the video bank: b __ax_getvbnk @ ax_i02 vaddr = __ax_getvbnk(); + @ Return: bx lr @ return vaddr; .endfunc diff --git a/agbx/source/gfx/getvbnk.s b/ax/source/gfx/getvbnk.s index d3dcbcf..d3dcbcf 100644 --- a/agbx/source/gfx/getvbnk.s +++ b/ax/source/gfx/getvbnk.s diff --git a/agbx/source/gfx/plot.c b/ax/source/gfx/plot.c index 066b97e..d9f7a32 100644 --- a/agbx/source/gfx/plot.c +++ b/ax/source/gfx/plot.c @@ -12,20 +12,20 @@ void ax_plot1(ax_i02 const _vaddr,ax_i01 const _px,ax_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. */ bool const odd = _px & 0x1u; ax_i02 addr = _vaddr + _px - odd; - ax_i01 precol = __ax_get10(addr); + ax_i01 precol = __ax_get01(addr); ax_i01 col = _col; if (odd) { precol &= 0b11111111u; col <<= 0x8u; } else { - precol &= 0b1111111100000000u; + precol &= 0b11111111'00000000u; } ax_i01 const newcol = precol | col; - __ax_set10(addr,newcol); + __ax_set01(addr,newcol); } void ax_plot2(ax_i02 const _vaddr,ax_i01 const _px,ax_i01 const _col) { ax_i02 const addr = _vaddr + _px; - __ax_set10(addr,_col); + __ax_set01(addr,_col); } diff --git a/agbx/source/gfx/plottex.cc b/ax/source/gfx/plottex.cc index 836a6ff..c039291 100644 --- a/agbx/source/gfx/plottex.cc +++ b/ax/source/gfx/plottex.cc @@ -25,5 +25,5 @@ template<typename _pxtyp> [[gnu::always_inline]] inline static auto __ax_plottex } } -extern "C" auto ax_plottex1(::ax_i02 const _vaddr,::ax_i8 const _scrnw,::ax_i8 const * const _tex,::ax_i01 const _px,::ax_i8 const _w,::ax_i8 const _h) -> void {::__ax_plottex(_vaddr,_scrnw,_tex,_px,_w,_h);} +extern "C" auto ax_plottex1(::ax_i02 const _vaddr,::ax_i8 const _scrnw,::ax_i8 const * const _tex,::ax_i01 const _px,::ax_i8 const _w,::ax_i8 const _h) -> void {::__ax_plottex(_vaddr,_scrnw,_tex,_px,_w,_h);} extern "C" auto ax_plottex2(::ax_i02 const _vaddr,::ax_i8 const _scrnw,::ax_i01 const * const _tex,::ax_i01 const _px,::ax_i8 const _w,::ax_i8 const _h) -> void {::__ax_plottex(_vaddr,_scrnw,_tex,_px,_w,_h);} diff --git a/agbx/source/gfx/rd.s b/ax/source/gfx/rd.s index 6662848..6662848 100644 --- a/agbx/source/gfx/rd.s +++ b/ax/source/gfx/rd.s diff --git a/ax/source/gfx/setcol.s b/ax/source/gfx/setcol.s new file mode 100644 index 0000000..bdf99f0 --- /dev/null +++ b/ax/source/gfx/setcol.s @@ -0,0 +1,32 @@ +@ 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>. + +.syntax unified + +.cpu arm7tdmi +.thumb + +.globl ax_setcol + +.func +.thumb_func + +ax_setcol: + @ Get the address of the colour: + ldr r2,.paladdr @ ax_i02 paladdr = 0x5000000u; + adds r2,r0 @ paladdr += _n; + adds r2,r0 @ paladdr += _n; /* Add the colour number twice as each colour value takes up two bytes. */ + + @ Set the colour value: + strh r1,[r2] @ *(ax_i01 *)paladdr = _col; + + @ Return: + bx lr @ return; + +.endfunc + +.align + +.paladdr: + .long 0x5000000 diff --git a/ax/source/gfx/vsync.s b/ax/source/gfx/vsync.s new file mode 100644 index 0000000..6b2908c --- /dev/null +++ b/ax/source/gfx/vsync.s @@ -0,0 +1,42 @@ +@ 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>. + +.syntax unified + +.cpu arm7tdmi +.thumb + +.globl ax_vsync + +.func +.thumb_func + +ax_vsync: + @ Set the constants: + ldr r0,.vcntaddr @ ax_i02 vcntaddr = 0x4000006u; + +.waitvdrw: @ waitvdrw:; + @ Wait for the next VDraw: + ldrh r2,[r0] @ ax_i02 vcnt = *(ax_i01 *)vcntaddr; + cmp r2,0x0 + beq .waitvblnk @ if (vcnt == 0x0u) goto waitvblnk; + b .waitvdrw @ goto waitvdrw; + +.waitvblnk: @ waitvblnk:; + @ Wait for the VBlank: + ldrh r2,[r0] @ ax_i02 vcnt = *(ax_i01 *)vcntaddr; + cmp r2,0xA0 + beq .ret @ if (vcnt == 0xA0u) goto ret; + b .waitvblnk @ goto waitvblnk; + +.ret: + @ Return: + bx lr @ return; + +.endfunc + +.align + +.vcntaddr: + .long 0x4000006 diff --git a/agbx/source/key/getkeymap.s b/ax/source/key/getkeymap.s index 2751c9f..2751c9f 100644 --- a/agbx/source/key/getkeymap.s +++ b/ax/source/key/getkeymap.s diff --git a/agbx/source/priv/init.s b/ax/source/priv/init.s index 718638d..718638d 100644 --- a/agbx/source/priv/init.s +++ b/ax/source/priv/init.s diff --git a/demo/GNUmakefile b/demo/GNUmakefile index ee59a0d..d5c5a81 100644 --- a/demo/GNUmakefile +++ b/demo/GNUmakefile @@ -13,7 +13,7 @@ OBJCOPY := arm-none-eabi-objcopy # TOOL FLAGS CFLAGS := \ - -I../agbx/include \ + -I../ax/include \ -Iinclude \ -O3 \ -Wall \ @@ -27,7 +27,7 @@ CFLAGS := \ -std=c2x LDFLAGS := \ - -L../agbx \ + -L../ax \ -Tscript.ld \ -znoexecstack @@ -45,7 +45,7 @@ OBJS := \ ROMHDR := hdr.o LDLIBS := \ - -lagbx + -lax IMG := demo.gba @@ -5,7 +5,7 @@ @ Please read this thoroughly, as to make sure to cater it to your own program. @ Image entry point (4) -@ 32-bit ARM instruction that serves as the entry point of the image, which usually is a branch instruction. Must be "b __ax_init" if agbx is used. +@ 32-bit ARM instruction that serves as the entry point of the image, which usually is a branch instruction. Must be "b __ax_init" if ax is used. .ARM .global _start _start: @ We define this label to stop the linker from complaining @@ -17,7 +17,7 @@ _start: @ We define this label to stop the linker from complaining @ Game title (12) @ Twelve character ASCII-string (with uppercase letters) signalling the title of the program. If the string does not take up twelve characters, it is padded to that size with zero. -.ascii "AGBXDEMO\x0\x0\x0\x0" +.ascii "AXDEMO\x0\x0\x0\x0\x0\x0" @ Game code (4) @ Four character ASCII-string. This is the code that is printed on the cartridge sticker (following the "AGB-"-part). diff --git a/demo/include/agbx-demo.h b/demo/include/ax-demo.h index 6b354c6..6b354c6 100644 --- a/demo/include/agbx-demo.h +++ b/demo/include/ax-demo.h diff --git a/demo/source/chgcol.c b/demo/source/chgcol.c index 4519319..6b99abb 100644 --- a/demo/source/chgcol.c +++ b/demo/source/chgcol.c @@ -1,4 +1,4 @@ -#include <agbx-demo.h> +#include <ax-demo.h> #include <ax/gfx.h> diff --git a/demo/source/chkkeys.c b/demo/source/chkkeys.c index 8e2a76c..262d542 100644 --- a/demo/source/chkkeys.c +++ b/demo/source/chkkeys.c @@ -1,4 +1,4 @@ -#include <agbx-demo.h> +#include <ax-demo.h> #include <ax/key.h> #include <ax/gfx.h> diff --git a/demo/source/initdat.c b/demo/source/initdat.c index 4650593..4d0b420 100644 --- a/demo/source/initdat.c +++ b/demo/source/initdat.c @@ -1,4 +1,4 @@ -#include <agbx-demo.h> +#include <ax-demo.h> #include <ax/gfx.h> diff --git a/demo/source/initgfx.c b/demo/source/initgfx.c index 14ea24f..de95d29 100644 --- a/demo/source/initgfx.c +++ b/demo/source/initgfx.c @@ -1,4 +1,4 @@ -#include <agbx-demo.h> +#include <ax-demo.h> #include <ax/gfx.h> @@ -7,23 +7,23 @@ static_assert(ax_col(0x0u,0x1Fu,0x0u) == 0b000001111100000u); static_assert(ax_col(0x0u,0x0u,0x1Fu) == 0b111110000000000u); void axd_initgfx(void) { - 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'0000u,0x0u); + ax_set01(0x400'0000u,0b00000100'10000100u); + ax_setcol(0x00u,ax_col(0x00u,0x00u,0x00u)); /* Black */ + ax_setcol(0x01u,ax_col(0x07u,0x07u,0x07u)); /* Darkgrey */ + ax_setcol(0x02u,ax_col(0x0Fu,0x0Fu,0x0Fu)); /* Grey */ + ax_setcol(0x03u,ax_col(0x17u,0x17u,0x17u)); /* Lightgrey */ + ax_setcol(0x04u,ax_col(0x1Fu,0x1Fu,0x1Fu)); /* White */ + ax_setcol(0x05u,ax_col(0x11u,0x01u,0x07u)); /* Red */ + ax_setcol(0x06u,ax_col(0x17u,0x0Au,0x04u)); /* Vermillion */ + ax_setcol(0x07u,ax_col(0x1Bu,0x0Eu,0x04u)); /* Orange */ + ax_setcol(0x08u,ax_col(0x1Bu,0x11u,0x01u)); /* Amber */ + ax_setcol(0x09u,ax_col(0x1Du,0x16u,0x02u)); /* Yellow */ + ax_setcol(0x0Au,ax_col(0x12u,0x19u,0x05u)); /* Chartreuse */ + ax_setcol(0x0Bu,ax_col(0x04u,0x0Fu,0x03u)); /* Green */ + ax_setcol(0x0Cu,ax_col(0x04u,0x11u,0x0Du)); /* Teal */ + ax_setcol(0x0Du,ax_col(0x04u,0x08u,0x16u)); /* Blue */ + ax_setcol(0x0Eu,ax_col(0x08u,0x05u,0x10u)); /* Violet */ + ax_setcol(0x0Fu,ax_col(0x0Au,0x05u,0x11u)); /* Purple */ + ax_setcol(0x10u,ax_col(0x11u,0x03u,0x15u)); /* Magenta */ + ax_clrscrn1(0x600'0000u,0x4u); } diff --git a/demo/source/loop.c b/demo/source/loop.c index 65779fa..469f62e 100644 --- a/demo/source/loop.c +++ b/demo/source/loop.c @@ -1,4 +1,4 @@ -#include <agbx-demo.h> +#include <ax-demo.h> #include <ax/key.h> #include <ax/gfx.h> diff --git a/demo/source/setcolbdr.c b/demo/source/setcolbdr.c index 1173d55..64a0029 100644 --- a/demo/source/setcolbdr.c +++ b/demo/source/setcolbdr.c @@ -1,4 +1,4 @@ -#include <agbx-demo.h> +#include <ax-demo.h> #include <ax/gfx.h> diff --git a/demo/source/start.c b/demo/source/start.c index 15da8f6..15ecec6 100644 --- a/demo/source/start.c +++ b/demo/source/start.c @@ -1,4 +1,4 @@ -#include <agbx-demo.h> +#include <ax-demo.h> #include <ax/key.h> #include <ax/gfx.h> @@ -7,13 +7,13 @@ 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,0x08u, 0x04u,0x00u, - 0x00u,0x04u, 0x05u,0x06u,0x04u,0x04u,0x04u,0x0Au,0x0Bu, 0x04u, 0x0Cu,0x0Du,0x04u,0x04u,0x04u,0x04u,0x04u, 0x04u, 0x07u,0x08u,0x04u,0x04u,0x04u,0x0Cu,0x0Du, 0x04u, 0x04u,0x0Fu,0x10u,0x05u,0x06u,0x07u,0x04u, 0x04u,0x00u, - 0x00u,0x04u, 0x05u,0x06u,0x04u,0x04u,0x04u,0x0Au,0x0Bu, 0x04u, 0x0Cu,0x0Du,0x04u,0x0Fu,0x10u,0x05u,0x06u, 0x04u, 0x07u,0x08u,0x09u,0x0Au,0x0Bu,0x0Cu,0x04u, 0x04u, 0x04u,0x04u,0x10u,0x05u,0x06u,0x04u,0x04u, 0x04u,0x00u, - 0x00u,0x04u, 0x05u,0x06u,0x07u,0x08u,0x09u,0x0Au,0x0Bu, 0x04u, 0x0Cu,0x0Du,0x04u,0x04u,0x04u,0x05u,0x06u, 0x04u, 0x07u,0x08u,0x04u,0x04u,0x04u,0x0Cu,0x0Du, 0x04u, 0x04u,0x0Fu,0x10u,0x05u,0x06u,0x07u,0x04u, 0x04u,0x00u, - 0x00u,0x04u, 0x05u,0x06u,0x04u,0x04u,0x04u,0x0Au,0x0Bu, 0x04u, 0x0Cu,0x0Du,0x0Eu,0x0Fu,0x10u,0x05u,0x06u, 0x04u, 0x07u,0x08u,0x09u,0x0Au,0x0Bu,0x0Cu,0x0Du, 0x04u, 0x0Eu,0x0Fu,0x10u,0x04u,0x06u,0x07u,0x08u, 0x04u,0x00u, - 0x00u,0x04u, 0x05u,0x06u,0x04u,0x04u,0x04u,0x0Au,0x0Bu, 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,0x04u,0x04u,0x04u,0x04u,0x04u,0x04u, 0x04u, 0x04u,0x04u,0x07u,0x08u,0x09u,0x04u,0x04u, 0x04u, 0x0Cu,0x0Du,0x04u,0x04u,0x04u,0x05u,0x06u, 0x04u, 0x04u,0x04u,0x04u,0x04u,0x04u,0x04u,0x04u, 0x04u,0x00u, + 0x00u,0x04u, 0x04u,0x04u,0x04u,0x04u,0x04u,0x04u,0x04u, 0x04u, 0x04u,0x06u,0x07u,0x08u,0x09u,0x0Au,0x04u, 0x04u, 0x0Cu,0x0Du,0x0Eu,0x04u,0x10u,0x05u,0x06u, 0x04u, 0x04u,0x04u,0x04u,0x04u,0x04u,0x04u,0x04u, 0x04u,0x00u, + 0x00u,0x04u, 0x04u,0x04u,0x04u,0x04u,0x04u,0x04u,0x04u, 0x04u, 0x05u,0x06u,0x04u,0x04u,0x04u,0x0Au,0x0Bu, 0x04u, 0x04u,0x0Du,0x0Eu,0x0Fu,0x10u,0x05u,0x04u, 0x04u, 0x04u,0x04u,0x04u,0x04u,0x04u,0x04u,0x04u, 0x04u,0x00u, + 0x00u,0x04u, 0x04u,0x04u,0x04u,0x04u,0x04u,0x04u,0x04u, 0x04u, 0x05u,0x06u,0x04u,0x04u,0x04u,0x0Au,0x0Bu, 0x04u, 0x04u,0x04u,0x0Eu,0x0Fu,0x10u,0x04u,0x04u, 0x04u, 0x04u,0x04u,0x04u,0x04u,0x04u,0x04u,0x04u, 0x04u,0x00u, + 0x00u,0x04u, 0x04u,0x04u,0x04u,0x04u,0x04u,0x04u,0x04u, 0x04u, 0x05u,0x06u,0x07u,0x08u,0x09u,0x0Au,0x0Bu, 0x04u, 0x04u,0x0Du,0x0Eu,0x0Fu,0x10u,0x05u,0x04u, 0x04u, 0x04u,0x04u,0x04u,0x04u,0x04u,0x04u,0x04u, 0x04u,0x00u, + 0x00u,0x04u, 0x04u,0x04u,0x04u,0x04u,0x04u,0x04u,0x04u, 0x04u, 0x05u,0x06u,0x04u,0x04u,0x04u,0x0Au,0x0Bu, 0x04u, 0x0Cu,0x0Du,0x0Eu,0x04u,0x10u,0x05u,0x06u, 0x04u, 0x04u,0x04u,0x04u,0x04u,0x04u,0x04u,0x04u, 0x04u,0x00u, + 0x00u,0x04u, 0x04u,0x04u,0x04u,0x04u,0x04u,0x04u,0x04u, 0x04u, 0x05u,0x06u,0x04u,0x04u,0x04u,0x0Au,0x0Bu, 0x04u, 0x0Cu,0x0Du,0x04u,0x04u,0x04u,0x05u,0x06u, 0x04u, 0x04u,0x04u,0x04u,0x04u,0x04u,0x04u,0x04u, 0x04u,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, 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, @@ -39,16 +39,59 @@ ax_err ax_start(void) { axd_dat dat; axd_initdat(&dat); axd_initgfx(); + ax_vsync(); + ax_blnk(); + ax_clrscrn1(dat.vaddr,0x0u); 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); + ax_key startkey; for (;;) { ax_keymap const keymap = ax_getkeymap(); - if (ax_chkkey(keymap,ax_key_a)) { + startkey = ax_key_a; + if (ax_chkkey(keymap,startkey)) { + break; + } + startkey = ax_key_b; + if (ax_chkkey(keymap,startkey)) { + break; + } + startkey = ax_key_l; + if (ax_chkkey(keymap,startkey)) { + break; + } + startkey = ax_key_pade; + if (ax_chkkey(keymap,startkey)) { + break; + } + startkey = ax_key_padn; + if (ax_chkkey(keymap,startkey)) { + break; + } + startkey = ax_key_pads; + if (ax_chkkey(keymap,startkey)) { + break; + } + startkey = ax_key_padw; + if (ax_chkkey(keymap,startkey)) { + break; + } + startkey = ax_key_r; + if (ax_chkkey(keymap,startkey)) { + break; + } + startkey = ax_key_sel; + if (ax_chkkey(keymap,startkey)) { + break; + } + startkey = ax_key_start; + if (ax_chkkey(keymap,startkey)) { break; } } - for (;;) { /* Wait for the key to become released. */ + ax_vsync(); + ax_clrscrn1(dat.vaddr,0x0u); + for (;;) { /* Wait for the key to be released. */ ax_keymap const keymap = ax_getkeymap(); - if (!ax_chkkey(keymap,ax_key_a)) { + if (!ax_chkkey(keymap,startkey)) { break; } } |