diff options
-rw-r--r-- | CHANGELOG.txt | 8 | ||||
-rw-r--r-- | agbx/include-private/agbx/priv.h | 33 | ||||
-rw-r--r-- | agbx/source/bs/get.c | 40 | ||||
-rw-r--r-- | agbx/source/bs/get.s | 42 | ||||
-rw-r--r-- | agbx/source/bs/set.c | 13 | ||||
-rw-r--r-- | agbx/source/bs/set.s | 42 | ||||
-rw-r--r-- | agbx/source/gfx/flip.c | 17 | ||||
-rw-r--r-- | agbx/source/gfx/flip.s | 47 | ||||
-rw-r--r-- | agbx/source/gfx/setpx.c | 2 | ||||
-rw-r--r-- | agbx/source/key/getkeymap.c | 15 | ||||
-rw-r--r-- | agbx/source/key/getkeymap.s | 26 | ||||
-rw-r--r-- | agbx/source/priv/init.c | 14 | ||||
-rw-r--r-- | agbx/source/priv/init.s | 23 | ||||
-rw-r--r-- | demo/GNUmakefile | 3 |
14 files changed, 201 insertions, 124 deletions
diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 3a2c6c6..a2da5ed 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,3 +1,11 @@ +# 2.2 + +* Enable warnings in demo makefile; +* Implement flip in assembly; +* Implement init in assembly; +* Implement getkeymap in assembly; +* Update get and set internally; + # 2.1 * Add colour switching to the demo (press R); diff --git a/agbx/include-private/agbx/priv.h b/agbx/include-private/agbx/priv.h index 3f55813..1534ff3 100644 --- a/agbx/include-private/agbx/priv.h +++ b/agbx/include-private/agbx/priv.h @@ -9,32 +9,17 @@ #include <agbx/bs.h> -#define __agbx_set10(_addr,_val) { \ - __asm__ ( \ - "strh %1,[%0]" \ - : \ - : "r" (_addr),"r" (_val) \ - : "memory" \ - ); \ -} +#define __agbx_get10(_addr) (*(agbx_i10 volatile *)_addr) -#define __agbx_set20(_addr,_val) { \ - __asm__ ( \ - "str %1,[%0]" \ - : \ - : "r" (_addr),"r" (_val) \ - : "memory" \ - ); \ -} +#define __agbx_get20(_addr) (*(agbx_i20 volatile *)_addr) -#define __agbx_set8(_addr,_val) { \ - __asm__ ( \ - "strb %1,[%0]" \ - : \ - : "r" (_addr),"r" (_val) \ - : "memory" \ - ); \ -} +#define __agbx_get8(_addr) (*(agbx_i8 volatile *)_addr) + +#define __agbx_set10(_addr,_val) ((void)(*(agbx_i10 volatile *)_addr = _val)) + +#define __agbx_set20(_addr,_val) ((void)(*(agbx_i20 volatile *)_addr = _val)) + +#define __agbx_set8(_addr,_val) ((void)(*(agbx_i8 volatile *)_addr = _val)) #define __agbx_setpx2(_vaddr,_px,_col) { \ agbx_i20 const addr = _vaddr + _px * 0x2u; /* We multiply it by two as each pixel takes up two bytes. */ \ diff --git a/agbx/source/bs/get.c b/agbx/source/bs/get.c deleted file mode 100644 index 38da5af..0000000 --- a/agbx/source/bs/get.c +++ /dev/null @@ -1,40 +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/. -*/ - -#include <agbx/priv.h> - -agbx_i10 agbx_get10(agbx_i20 const _addr) { - agbx_i10 val; - __asm__ ( \ - "ldrh %0,[%1]" - : "=r" (val) - : "r" (_addr) - : "memory" - ); - return val; -} - -agbx_i20 agbx_get20(agbx_i20 const _addr) { - agbx_i20 val; - __asm__ ( \ - "ldr %0,[%1]" - : "=r" (val) - : "r" (_addr) - : "memory" - ); - return val; -} - -agbx_i8 agbx_get8(agbx_i20 const _addr) { - agbx_i8 val; - __asm__ ( \ - "ldrb %0,[%1]" - : "=r" (val) - : "r" (_addr) - : "memory" - ); - return val; -} diff --git a/agbx/source/bs/get.s b/agbx/source/bs/get.s new file mode 100644 index 0000000..dfd6453 --- /dev/null +++ b/agbx/source/bs/get.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 agbx_get10 +.globl agbx_get20 +.globl agbx_get8 + +.func + +.thumb_func + +agbx_get10: + ldrh r0,[r0] + bx lr + +.endfunc + +.func + +.thumb_func + +agbx_get20: + ldr r0,[r0] + bx lr + +.endfunc + +.func + +.thumb_func + +agbx_get8: + ldrb r0,[r0] + bx lr + +.endfunc diff --git a/agbx/source/bs/set.c b/agbx/source/bs/set.c deleted file mode 100644 index 8aa9976..0000000 --- a/agbx/source/bs/set.c +++ /dev/null @@ -1,13 +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/. -*/ - -#include <agbx/priv.h> - -void agbx_set10(agbx_i20 const _addr,agbx_i10 const _val) {__agbx_set10(_addr,_val)} - -void agbx_set20(agbx_i20 const _addr,agbx_i20 const _val) {__agbx_set20(_addr,_val)} - -void agbx_set8(agbx_i20 const _addr,agbx_i8 const _val) {__agbx_set8(_addr,_val)} diff --git a/agbx/source/bs/set.s b/agbx/source/bs/set.s new file mode 100644 index 0000000..93ea3b5 --- /dev/null +++ b/agbx/source/bs/set.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 agbx_set10 +.globl agbx_set20 +.globl agbx_set8 + +.func + +.thumb_func + +agbx_set10: + strh r1,[r0] + bx lr + +.endfunc + +.func + +.thumb_func + +agbx_set20: + str r1,[r0] + bx lr + +.endfunc + +.func + +.thumb_func + +agbx_set8: + strb r1,[r0] + bx lr + +.endfunc diff --git a/agbx/source/gfx/flip.c b/agbx/source/gfx/flip.c deleted file mode 100644 index 92b8939..0000000 --- a/agbx/source/gfx/flip.c +++ /dev/null @@ -1,17 +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/. -*/ - -#include <agbx/priv.h> - -#include <agbx/gfx.h> - -agbx_i20 agbx_flip(void) { - agbx_i10 dispcnt = agbx_get10(0x400'0000u); - dispcnt ^= 0b10000u; - agbx_set10(0x400'0000u,dispcnt); - if (dispcnt & 0x10000u) {return 0x600'A000u;} - return 0x600'0000u; -} diff --git a/agbx/source/gfx/flip.s b/agbx/source/gfx/flip.s new file mode 100644 index 0000000..c2f4336 --- /dev/null +++ b/agbx/source/gfx/flip.s @@ -0,0 +1,47 @@ +@ 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 agbx_flip + +.func + +.thumb_func + +agbx_flip: + ldr r0,.dispcntaddr + ldrh r1,[r0] @ Get the current value of dispcnt. + movs r2,#0b10000 + eors r1,r2 @ XOR bit five. + strh r1,[r0] @ Save dispcnt. + movs r0,#0x10 + tst r1,r0 @ Check what video bank we should return the address of. + beq .vbnk0 +.vbnk1: + ldr r0,.vbnk1addr + bx lr +.vbnk0: + ldr r0,.vbnk0addr + bx lr + +.endfunc + +.align + +.dispcntaddr: + .long 0x4000000 + +.align + +.vbnk0addr: + .long 0x6000000 + +.align + +.vbnk1addr: + .long 0x600A000 diff --git a/agbx/source/gfx/setpx.c b/agbx/source/gfx/setpx.c index b2c5c2d..d7d3110 100644 --- a/agbx/source/gfx/setpx.c +++ b/agbx/source/gfx/setpx.c @@ -20,7 +20,7 @@ void agbx_setpx1(agbx_i20 const _vaddr,agbx_i10 const _px,agbx_i8 const _col) { 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) + __agbx_set10(addr,col); } void agbx_setpx2(agbx_i20 const _vaddr,agbx_i10 const _px,agbx_i10 const _col) { diff --git a/agbx/source/key/getkeymap.c b/agbx/source/key/getkeymap.c deleted file mode 100644 index fe24c6c..0000000 --- a/agbx/source/key/getkeymap.c +++ /dev/null @@ -1,15 +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/. -*/ - -#include <agbx/priv.h> - -#include <agbx/key.h> - -agbx_keymap agbx_getkeymap(void) { - agbx_keymap map; - map._keys = agbx_get10(0x400'0130u); - return map; -} diff --git a/agbx/source/key/getkeymap.s b/agbx/source/key/getkeymap.s new file mode 100644 index 0000000..bb3638e --- /dev/null +++ b/agbx/source/key/getkeymap.s @@ -0,0 +1,26 @@ +@ 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 agbx_getkeymap + +.func + +.thumb_func + +agbx_getkeymap: + ldr r0,.addr + ldrh r0,[r0] + bx lr + +.endfunc + +.align + +.addr: + .long 0x4000130 diff --git a/agbx/source/priv/init.c b/agbx/source/priv/init.c deleted file mode 100644 index 3ba1f17..0000000 --- a/agbx/source/priv/init.c +++ /dev/null @@ -1,14 +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/. -*/ - -#include <agbx/priv.h> - -agbx_err agbx_main(void); - -[[noreturn]] void __agbx_init(void) { - agbx_err const err = agbx_main(); - agbx_done(err); -} diff --git a/agbx/source/priv/init.s b/agbx/source/priv/init.s new file mode 100644 index 0000000..ec0b6df --- /dev/null +++ b/agbx/source/priv/init.s @@ -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/. + +.syntax unified + +.cpu arm7tdmi +.thumb + +.extern agbx_done +.extern agbx_main + +.globl __agbx_init + +.func + +.thumb_func + +__agbx_init: + bl agbx_main + bl agbx_done @ The return value is already in r0, so there's no need to move it. + +.endfunc diff --git a/demo/GNUmakefile b/demo/GNUmakefile index 474f957..18d3083 100644 --- a/demo/GNUmakefile +++ b/demo/GNUmakefile @@ -15,6 +15,9 @@ OBJCOPY := arm-none-eabi-objcopy CFLAGS := \ -I../agbx/include \ -O3 \ + -Wall \ + -Wextra \ + -Wpedantic \ -mcpu=arm7tdmi \ -nostdlib \ -std=c2x |