diff options
Diffstat (limited to 'agbx/source/gfx')
-rw-r--r-- | agbx/source/gfx/clrscrn.c | 24 | ||||
-rw-r--r-- | agbx/source/gfx/flip.s | 37 | ||||
-rw-r--r-- | agbx/source/gfx/getvbnk.s | 65 | ||||
-rw-r--r-- | agbx/source/gfx/plot.c | 19 | ||||
-rw-r--r-- | agbx/source/gfx/setpx.c | 18 | ||||
-rw-r--r-- | agbx/source/gfx/vsync.s | 38 |
6 files changed, 146 insertions, 55 deletions
diff --git a/agbx/source/gfx/clrscrn.c b/agbx/source/gfx/clrscrn.c new file mode 100644 index 0000000..157498c --- /dev/null +++ b/agbx/source/gfx/clrscrn.c @@ -0,0 +1,24 @@ +/* + 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> + +void agbx_clrscrn3(agbx_i10 const _col) { + agbx_i20 const val = _col | _col << 0x8u | _col << 0x10u | _col << 0x18u; + for (agbx_i20 addr = 0x400'0000u;addr != 0x401'2C00u;addr += 0x4u) {agbx_set20(addr,val);} +} + +void agbx_clrscrn4(agbx_i20 const _vaddr,agbx_i8 const _col) { + agbx_i20 const val = _col | _col << 0x8u | _col << 0x10u | _col << 0x18u; + for (agbx_i20 addr = _vaddr;addr != _vaddr + 0x9600u;addr += 0x4u) {agbx_set20(addr,val);} +} + +void agbx_clrscrn5(agbx_i20 const _vaddr,agbx_i10 const _col) { + agbx_i20 const val = _col | _col << 0x10u; + for (agbx_i20 addr = _vaddr;addr != _vaddr + 0xA000u;addr += 0x4u) {agbx_set20(addr,val);} +} diff --git a/agbx/source/gfx/flip.s b/agbx/source/gfx/flip.s index c2f4336..019289d 100644 --- a/agbx/source/gfx/flip.s +++ b/agbx/source/gfx/flip.s @@ -7,6 +7,8 @@ .cpu arm7tdmi .thumb +.extern __agbx_getvbnk + .globl agbx_flip .func @@ -14,19 +16,20 @@ .thumb_func agbx_flip: + @ Get the current value of dispcnt: 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 + ldrh r1,[r0] + + @ XOR bit five: + movs r2,0b10000 + eors r1,r2 + + @ Save dispcnt: + strh r1,[r0] + + @ Get the address of the video bank: + b __agbx_getvbnk + bx lr .endfunc @@ -35,13 +38,3 @@ agbx_flip: .dispcntaddr: .long 0x4000000 - -.align - -.vbnk0addr: - .long 0x6000000 - -.align - -.vbnk1addr: - .long 0x600A000 diff --git a/agbx/source/gfx/getvbnk.s b/agbx/source/gfx/getvbnk.s new file mode 100644 index 0000000..e04a127 --- /dev/null +++ b/agbx/source/gfx/getvbnk.s @@ -0,0 +1,65 @@ +@ 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_getvbnk +.globl agbx_getvbnk + +.func + +.thumb_func + +agbx_getvbnk: + @ Get the current value of dispcnt: + ldr r0,.dispcntaddr + ldrh r1,[r0] + + @ Get the address: + b __agbx_getvbnk + + bx lr + +.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 + + bne .vbnk1 + +.vbnk0: + @ Return the address of the first video bank: + ldr r0,.vbnk0addr + bx lr + +.vbnk1: + @ Return the address of the second video bank: + ldr r0,.vbnk1addr + bx lr + +.endfunc + +.align + +.dispcntaddr: + .long 0x4000000 + +.align + +.vbnk0addr: + .long 0x6000000 + +.align + +.vbnk1addr: + .long 0x600A000 diff --git a/agbx/source/gfx/plot.c b/agbx/source/gfx/plot.c index cc41d38..e23834c 100644 --- a/agbx/source/gfx/plot.c +++ b/agbx/source/gfx/plot.c @@ -9,30 +9,19 @@ #include <agbx/gfx.h> agbx_i10 agbx_plot3(agbx_i8 const _x,agbx_i8 const _y,agbx_i10 const _col) { -#if defined(__agbx_dbg) - if (_x >= 0xF0u || _y >= 0xA0u) {agbx_done(agbx_err_pos2big);} -#endif agbx_i10 const px = _y * 0xF0u + _x; __agbx_setpx2(0x600'0000u,px,_col) return px; } -agbx_i10 agbx_plot4(agbx_i8 const _x,agbx_i8 const _y,agbx_i8 const _col) { -#if defined(__agbx_dbg) - if (_x >= 0xF0u || _y >= 0xA0u) {agbx_done(agbx_err_pos2big);} -#endif - agbx_i20 const vaddr = 0x600'0000u + (agbx_get10(0x400'0000u) >> 0x4u & 0x1u) * 0xA000u; +agbx_i10 agbx_plot4(agbx_i20 const _vaddr,agbx_i8 const _x,agbx_i8 const _y,agbx_i8 const _col) { agbx_i10 const px = _y * 0xF0u + _x; - agbx_setpx1(vaddr,px,_col); + agbx_setpx1(_vaddr,px,_col); return px; } -agbx_i10 agbx_plot5(agbx_i8 const _x,agbx_i8 const _y,agbx_i10 const _col) { -#if defined(__agbx_dbg) - if (_x >= 0xA0u || _y >= 0x80u) {agbx_done(agbx_err_pos2big);} -#endif - agbx_i20 const vaddr = 0x600'0000u + (agbx_get10(0x400'0000u) >> 0x4u & 0x1u) * 0xA000u; +agbx_i10 agbx_plot5(agbx_i20 const _vaddr,agbx_i8 const _x,agbx_i8 const _y,agbx_i10 const _col) { agbx_i10 const px = _y * 0xF0u + _x; - __agbx_setpx2(vaddr,px,_col) + __agbx_setpx2(_vaddr,px,_col) return px; } diff --git a/agbx/source/gfx/setpx.c b/agbx/source/gfx/setpx.c index d7d3110..df3f0de 100644 --- a/agbx/source/gfx/setpx.c +++ b/agbx/source/gfx/setpx.c @@ -9,12 +9,6 @@ #include <agbx/gfx.h> void agbx_setpx1(agbx_i20 const _vaddr,agbx_i10 const _px,agbx_i8 const _col) { -#if defined(__agbx_dbg) - agbx_i10 const dispcnt = agbx_get10(0x400'0000u); - agbx_i8 const md = dispcnt & 0x7u; - if (md != 0x4u) {agbx_done(agbx_err_badmd);} - if (_px >= 0x9600u) {agbx_done(agbx_err_px2big);} -#endif /* We can only write halfwords to VRAM, so we load the adjacent pixel value and combine it into a halfword. */ agbx_i20 const addr = _vaddr + _px - (_px & 0x1u) * 0x1u; agbx_i10 col; @@ -24,17 +18,5 @@ void agbx_setpx1(agbx_i20 const _vaddr,agbx_i10 const _px,agbx_i8 const _col) { } void agbx_setpx2(agbx_i20 const _vaddr,agbx_i10 const _px,agbx_i10 const _col) { -#if defined(__agbx_dbg) - agbx_i10 const dispcnt = agbx_get10(0x400'0000u); - agbx_i8 const md = dispcnt & 0x7u; - if (md == 0x4u) {agbx_done(agbx_err_badmd);} - if (md == 0x5u) { - if (_px >= 0x5000u) {agbx_done(agbx_err_px2big);} - } - else { - if (md != 0x3u) {agbx_done(agbx_err_badmd);} - if (_px >= 0x9600u) {agbx_done(agbx_err_px2big);} - } -#endif __agbx_setpx2(_vaddr,_px,_col) } diff --git a/agbx/source/gfx/vsync.s b/agbx/source/gfx/vsync.s new file mode 100644 index 0000000..5bfbe06 --- /dev/null +++ b/agbx/source/gfx/vsync.s @@ -0,0 +1,38 @@ +@ 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_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; + +.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. + +.ret: + @ Return: + bx lr + +.endfunc + +.align + +.scancnt: + .long 0x4000000 + +.align |