summaryrefslogtreecommitdiff
path: root/agbx/source/gfx/setpx.c
diff options
context:
space:
mode:
Diffstat (limited to 'agbx/source/gfx/setpx.c')
-rw-r--r--agbx/source/gfx/setpx.c21
1 files changed, 15 insertions, 6 deletions
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);
}