diff options
Diffstat (limited to 'agbx/source/gfx')
-rw-r--r-- | agbx/source/gfx/flip.c | 17 | ||||
-rw-r--r-- | agbx/source/gfx/plot.c | 10 | ||||
-rw-r--r-- | agbx/source/gfx/setpx.c | 21 |
3 files changed, 36 insertions, 12 deletions
diff --git a/agbx/source/gfx/flip.c b/agbx/source/gfx/flip.c new file mode 100644 index 0000000..92b8939 --- /dev/null +++ b/agbx/source/gfx/flip.c @@ -0,0 +1,17 @@ +/* + 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/plot.c b/agbx/source/gfx/plot.c index 2146c54..cc41d38 100644 --- a/agbx/source/gfx/plot.c +++ b/agbx/source/gfx/plot.c @@ -13,7 +13,7 @@ agbx_i10 agbx_plot3(agbx_i8 const _x,agbx_i8 const _y,agbx_i10 const _col) { if (_x >= 0xF0u || _y >= 0xA0u) {agbx_done(agbx_err_pos2big);} #endif agbx_i10 const px = _y * 0xF0u + _x; - __agbx_setpx2(px,_col) + __agbx_setpx2(0x600'0000u,px,_col) return px; } @@ -21,8 +21,9 @@ 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 const px = _y * 0xF0u + _x; - __agbx_setpx1(px,_col) + agbx_setpx1(vaddr,px,_col); return px; } @@ -30,7 +31,8 @@ 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_i10 const px = _y * 0xA0u + _x; - __agbx_setpx2(px,_col) + agbx_i20 const vaddr = 0x600'0000u + (agbx_get10(0x400'0000u) >> 0x4u & 0x1u) * 0xA000u; + agbx_i10 const px = _y * 0xF0u + _x; + __agbx_setpx2(vaddr,px,_col) return px; } diff --git a/agbx/source/gfx/setpx.c b/agbx/source/gfx/setpx.c index 563fd3b..b2c5c2d 100644 --- a/agbx/source/gfx/setpx.c +++ b/agbx/source/gfx/setpx.c @@ -8,19 +8,24 @@ #include <agbx/gfx.h> -void agbx_setpx1(agbx_i10 const _px,agbx_i8 const _col) { +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(0x4000000u); + agbx_i10 const dispcnt = agbx_get10(0x400'0000u); agbx_i8 const md = dispcnt & 0x7u; - if (md == 0x3u || md == 0x5u) {agbx_done(agbx_err_badmd);} - if (_px >= 0x9600u) {agbx_done(agbx_err_px2big);} + if (md != 0x4u) {agbx_done(agbx_err_badmd);} + if (_px >= 0x9600u) {agbx_done(agbx_err_px2big);} #endif - __agbx_setpx1(_px,_col) + /* 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; + 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_i10 const _px,agbx_i10 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(0x4000000u); + 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) { @@ -31,5 +36,5 @@ void agbx_setpx2(agbx_i10 const _px,agbx_i10 const _col) { if (_px >= 0x9600u) {agbx_done(agbx_err_px2big);} } #endif - __agbx_setpx2(_px,_col) + __agbx_setpx2(_vaddr,_px,_col) } |