Minor cleanup

This commit is contained in:
neauoire 2021-04-09 08:02:55 -07:00
parent f2509f13f4
commit 79949be735
3 changed files with 22 additions and 17 deletions

View File

@ -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;

View File

@ -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) {

View File

@ -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 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);