uxn

Varvara Ordinator, written in ANSI C(SDL2)
git clone https://git.eamoncaddigan.net/uxn.git
Log | Files | Refs | README | LICENSE

commit 79949be735a13e6b1cfb80a1c8d517e84be48d4a
parent f2509f13f4568d61d4f83f4d45e281bb42b6e6c8
Author: neauoire <aliceffekt@gmail.com>
Date:   Fri,  9 Apr 2021 08:02:55 -0700

Minor cleanup

Diffstat:
Msrc/emulator.c | 17+++++------------
Msrc/ppu.c | 15++++++++++++++-
Msrc/ppu.h | 9++++-----
3 files changed, 23 insertions(+), 18 deletions(-)

diff --git a/src/emulator.c b/src/emulator.c @@ -215,7 +215,8 @@ screen_poke(Uxn *u, Uint16 ptr, Uint8 b0, Uint8 b1) if(b0 == 0x0c) { Uint16 x = (m[ptr] << 8) + m[ptr + 1]; Uint16 y = (m[ptr + 2] << 8) + m[ptr + 3]; - putpixel(&ppu, b1 >> 4 & 0xf ? ppu.fg : ppu.bg, x, y, b1 & 0xf); + Uint8 *layer = b1 >> 4 & 0xf ? ppu.fg : ppu.bg; + putpixel(&ppu, layer, x, y, b1 & 0xf); reqdraw = 1; } return b1; @@ -227,19 +228,11 @@ sprite_poke(Uxn *u, Uint16 ptr, Uint8 b0, Uint8 b1) Uint8 *m = u->ram.dat; ptr += 8; if(b0 == 0x0e) { - Uint16 v, h; Uint16 x = (m[ptr] << 8) + m[ptr + 1]; Uint16 y = (m[ptr + 2] << 8) + m[ptr + 3]; - Uint8 blend = b1 & 0xf; - Uint8 *layer = ((b1 >> 4) & 0xf) % 2 ? ppu.fg : ppu.bg; + Uint8 *layer = (b1 >> 4) & 0xf ? ppu.fg : ppu.bg; Uint8 *sprite = &m[(m[ptr + 4] << 8) + m[ptr + 5]]; - for(v = 0; v < 8; v++) - for(h = 0; h < 8; h++) { - Uint8 ch1 = ((sprite[v] >> (7 - h)) & 0x1); - if(ch1 == 0 && (blend == 0x05 || blend == 0x0a || blend == 0x0f)) - continue; - putpixel(&ppu, layer, x + h, y + v, ch1 ? blend % 4 : blend / 4); - } + putsprite(&ppu, layer, x, y, sprite, b1 & 0xf); reqdraw = 1; } return b1; @@ -325,7 +318,7 @@ system_poke(Uxn *u, Uint16 ptr, Uint8 b0, Uint8 b1) { Uint8 *m = u->ram.dat; m[PAGE_DEVICE + b0] = b1; - loadtheme(&ppu, &m[PAGE_DEVICE + 0x0008]); + getcolors(&ppu, &m[PAGE_DEVICE + 0x0008]); reqdraw = 1; (void)ptr; return b1; diff --git a/src/ppu.c b/src/ppu.c @@ -110,7 +110,20 @@ putpixel(Ppu *p, Uint8 *layer, Uint16 x, Uint16 y, Uint8 color) } void -loadtheme(Ppu *p, Uint8 *addr) +putsprite(Ppu *p, Uint8 *layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color) +{ + Uint16 v, h; + for(v = 0; v < 8; v++) + for(h = 0; h < 8; h++) { + Uint8 ch1 = ((sprite[v] >> (7 - h)) & 0x1); + if(ch1 == 0 && (color == 0x05 || color == 0x0a || color == 0x0f)) + continue; + putpixel(p, layer, x + h, y + v, ch1 ? color % 4 : color / 4); + } +} + +void +getcolors(Ppu *p, Uint8 *addr) { int i; for(i = 0; i < 4; ++i) { diff --git a/src/ppu.h b/src/ppu.h @@ -13,9 +13,7 @@ WITH REGARD TO THIS SOFTWARE. */ typedef unsigned char Uint8; -typedef signed char Sint8; typedef unsigned short Uint16; -typedef signed short Sint16; typedef unsigned int Uint32; typedef struct Ppu { @@ -27,5 +25,6 @@ typedef struct Ppu { int initppu(Ppu *p, Uint8 hor, Uint8 ver, Uint8 pad); void drawppu(Ppu *p); void drawdebugger(Ppu *p, Uint8 *stack, Uint8 ptr); -void loadtheme(Ppu *p, Uint8 *addr); -void putpixel(Ppu *p, Uint8 *layer, Uint16 x, Uint16 y, Uint8 color); -\ No newline at end of file +void getcolors(Ppu *p, Uint8 *addr); +void putpixel(Ppu *p, Uint8 *layer, Uint16 x, Uint16 y, Uint8 color); +void putsprite(Ppu *p, Uint8 *layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color); +\ No newline at end of file