Prefixed function names with ppu

This commit is contained in:
neauoire 2021-08-01 11:33:43 -07:00
parent c3be359163
commit be85023831
3 changed files with 28 additions and 36 deletions

View File

@ -20,15 +20,7 @@ static Uint8 blending[5][16] = {
{1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0}}; {1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0}};
void void
clear(Ppu *p) ppu_pixel(Ppu *p, Uint8 layer, Uint16 x, Uint16 y, Uint8 color)
{
int i, sz = p->height * p->width;
for(i = 0; i < sz; ++i)
p->pixels[i] = 0x00;
}
void
putpixel(Ppu *p, Uint8 layer, Uint16 x, Uint16 y, Uint8 color)
{ {
Uint8 *pixel = &p->pixels[y * p->width + x], shift = layer * 2; Uint8 *pixel = &p->pixels[y * p->width + x], shift = layer * 2;
if(x < p->width && y < p->height) if(x < p->width && y < p->height)
@ -36,14 +28,14 @@ putpixel(Ppu *p, Uint8 layer, Uint16 x, Uint16 y, Uint8 color)
} }
void void
puticn(Ppu *p, Uint8 layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Uint8 flipx, Uint8 flipy) ppu_1bpp(Ppu *p, Uint8 layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Uint8 flipx, Uint8 flipy)
{ {
Uint16 v, h; Uint16 v, h;
for(v = 0; v < 8; v++) for(v = 0; v < 8; v++)
for(h = 0; h < 8; h++) { for(h = 0; h < 8; h++) {
Uint8 ch1 = (sprite[v] >> (7 - h)) & 0x1; Uint8 ch1 = (sprite[v] >> (7 - h)) & 0x1;
if(ch1 || blending[4][color]) if(ch1 || blending[4][color])
putpixel(p, ppu_pixel(p,
layer, layer,
x + (flipx ? 7 - h : h), x + (flipx ? 7 - h : h),
y + (flipy ? 7 - v : v), y + (flipy ? 7 - v : v),
@ -52,7 +44,7 @@ puticn(Ppu *p, Uint8 layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Uint
} }
void void
putchr(Ppu *p, Uint8 layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Uint8 flipx, Uint8 flipy) ppu_2bpp(Ppu *p, Uint8 layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Uint8 flipx, Uint8 flipy)
{ {
Uint16 v, h; Uint16 v, h;
for(v = 0; v < 8; v++) for(v = 0; v < 8; v++)
@ -61,7 +53,7 @@ putchr(Ppu *p, Uint8 layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Uint
Uint8 ch2 = ((sprite[v + 8] >> (7 - h)) & 0x1); Uint8 ch2 = ((sprite[v + 8] >> (7 - h)) & 0x1);
Uint8 ch = ch1 + ch2 * 2; Uint8 ch = ch1 + ch2 * 2;
if(ch || blending[4][color]) if(ch || blending[4][color])
putpixel(p, ppu_pixel(p,
layer, layer,
x + (flipx ? 7 - h : h), x + (flipx ? 7 - h : h),
y + (flipy ? 7 - v : v), y + (flipy ? 7 - v : v),
@ -72,7 +64,7 @@ putchr(Ppu *p, Uint8 layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Uint
/* output */ /* output */
int int
initppu(Ppu *p, Uint8 hor, Uint8 ver) ppu_init(Ppu *p, Uint8 hor, Uint8 ver)
{ {
p->hor = hor; p->hor = hor;
p->ver = ver; p->ver = ver;

View File

@ -22,7 +22,7 @@ typedef struct Ppu {
Uint8 *pixels; Uint8 *pixels;
} Ppu; } Ppu;
int initppu(Ppu *p, Uint8 hor, Uint8 ver); int ppu_init(Ppu *p, Uint8 hor, Uint8 ver);
void putpixel(Ppu *p, Uint8 layer, Uint16 x, Uint16 y, Uint8 color); void ppu_pixel(Ppu *p, Uint8 layer, Uint16 x, Uint16 y, Uint8 color);
void puticn(Ppu *p, Uint8 layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Uint8 flipx, Uint8 flipy); void ppu_1bpp(Ppu *p, Uint8 layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Uint8 flipx, Uint8 flipy);
void putchr(Ppu *p, Uint8 layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Uint8 flipx, Uint8 flipy); void ppu_2bpp(Ppu *p, Uint8 layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Uint8 flipx, Uint8 flipy);

View File

@ -84,24 +84,24 @@ inspect(Ppu *p, Uint8 *stack, Uint8 wptr, Uint8 rptr, Uint8 *memory)
Uint8 i, x, y, b; Uint8 i, x, y, b;
for(i = 0; i < 0x20; ++i) { /* stack */ for(i = 0; i < 0x20; ++i) { /* stack */
x = ((i % 8) * 3 + 1) * 8, y = (i / 8 + 1) * 8, b = stack[i]; x = ((i % 8) * 3 + 1) * 8, y = (i / 8 + 1) * 8, b = stack[i];
puticn(p, 1, x, y, font[(b >> 4) & 0xf], 1 + (wptr == i) * 0x7, 0, 0); ppu_1bpp(p, 1, x, y, font[(b >> 4) & 0xf], 1 + (wptr == i) * 0x7, 0, 0);
puticn(p, 1, x + 8, y, font[b & 0xf], 1 + (wptr == i) * 0x7, 0, 0); ppu_1bpp(p, 1, x + 8, y, font[b & 0xf], 1 + (wptr == i) * 0x7, 0, 0);
} }
/* return pointer */ /* return pointer */
puticn(p, 1, 0x8, y + 0x10, font[(rptr >> 4) & 0xf], 0x2, 0, 0); ppu_1bpp(p, 1, 0x8, y + 0x10, font[(rptr >> 4) & 0xf], 0x2, 0, 0);
puticn(p, 1, 0x10, y + 0x10, font[rptr & 0xf], 0x2, 0, 0); ppu_1bpp(p, 1, 0x10, y + 0x10, font[rptr & 0xf], 0x2, 0, 0);
for(i = 0; i < 0x20; ++i) { /* memory */ for(i = 0; i < 0x20; ++i) { /* memory */
x = ((i % 8) * 3 + 1) * 8, y = 0x38 + (i / 8 + 1) * 8, b = memory[i]; x = ((i % 8) * 3 + 1) * 8, y = 0x38 + (i / 8 + 1) * 8, b = memory[i];
puticn(p, 1, x, y, font[(b >> 4) & 0xf], 3, 0, 0); ppu_1bpp(p, 1, x, y, font[(b >> 4) & 0xf], 3, 0, 0);
puticn(p, 1, x + 8, y, font[b & 0xf], 3, 0, 0); ppu_1bpp(p, 1, x + 8, y, font[b & 0xf], 3, 0, 0);
} }
for(x = 0; x < 0x10; ++x) { /* guides */ for(x = 0; x < 0x10; ++x) { /* guides */
putpixel(p, 1, x, p->height / 2, 2); ppu_pixel(p, 1, x, p->height / 2, 2);
putpixel(p, 1, p->width - x, p->height / 2, 2); ppu_pixel(p, 1, p->width - x, p->height / 2, 2);
putpixel(p, 1, p->width / 2, p->height - x, 2); ppu_pixel(p, 1, p->width / 2, p->height - x, 2);
putpixel(p, 1, p->width / 2, x, 2); ppu_pixel(p, 1, p->width / 2, x, 2);
putpixel(p, 1, p->width / 2 - 0x10 / 2 + x, p->height / 2, 2); ppu_pixel(p, 1, p->width / 2 - 0x10 / 2 + x, p->height / 2, 2);
putpixel(p, 1, p->width / 2, p->height / 2 - 0x10 / 2 + x, 2); ppu_pixel(p, 1, p->width / 2, p->height / 2 - 0x10 / 2 + x, 2);
} }
} }
@ -168,7 +168,7 @@ static int
init(void) init(void)
{ {
SDL_AudioSpec as; SDL_AudioSpec as;
if(!initppu(&ppu, 64, 40)) if(!ppu_init(&ppu, 64, 40))
return error("ppu", "Init failure"); return error("ppu", "Init failure");
if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0) if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0)
return error("sdl", SDL_GetError()); return error("sdl", SDL_GetError());
@ -306,13 +306,13 @@ screen_talk(Device *d, Uint8 b0, Uint8 w)
Uint8 layer = d->dat[0xe] >> 4 & 0x1; Uint8 layer = d->dat[0xe] >> 4 & 0x1;
Uint8 mode = d->dat[0xe] >> 5; Uint8 mode = d->dat[0xe] >> 5;
if(!mode) if(!mode)
putpixel(&ppu, layer, x, y, d->dat[0xe] & 0x3); ppu_pixel(&ppu, layer, x, y, d->dat[0xe] & 0x3);
else { else {
Uint8 *addr = &d->mem[mempeek16(d->dat, 0xc)]; Uint8 *addr = &d->mem[mempeek16(d->dat, 0xc)];
if(mode-- & 0x1) if(mode-- & 0x1)
puticn(&ppu, layer, x, y, addr, d->dat[0xe] & 0xf, mode & 0x2, mode & 0x4); ppu_1bpp(&ppu, layer, x, y, addr, d->dat[0xe] & 0xf, mode & 0x2, mode & 0x4);
else else
putchr(&ppu, layer, x, y, addr, d->dat[0xe] & 0xf, mode & 0x2, mode & 0x4); ppu_2bpp(&ppu, layer, x, y, addr, d->dat[0xe] & 0xf, mode & 0x2, mode & 0x4);
} }
reqdraw = 1; reqdraw = 1;
} else if(w && b0 == 0xf) { } else if(w && b0 == 0xf) {
@ -321,9 +321,9 @@ screen_talk(Device *d, Uint8 b0, Uint8 w)
Uint8 layer = d->dat[0xf] >> 0x6 & 0x1; Uint8 layer = d->dat[0xf] >> 0x6 & 0x1;
Uint8 *addr = &d->mem[mempeek16(d->dat, 0xc)]; Uint8 *addr = &d->mem[mempeek16(d->dat, 0xc)];
if(d->dat[0xf] >> 0x7 & 0x1) if(d->dat[0xf] >> 0x7 & 0x1)
putchr(&ppu, layer, x, y, addr, d->dat[0xf] & 0xf, d->dat[0xf] >> 0x4 & 0x1, d->dat[0xf] >> 0x5 & 0x1); ppu_2bpp(&ppu, layer, x, y, addr, d->dat[0xf] & 0xf, d->dat[0xf] >> 0x4 & 0x1, d->dat[0xf] >> 0x5 & 0x1);
else else
puticn(&ppu, layer, x, y, addr, d->dat[0xf] & 0xf, d->dat[0xf] >> 0x4 & 0x1, d->dat[0xf] >> 0x5 & 0x1); ppu_1bpp(&ppu, layer, x, y, addr, d->dat[0xf] & 0xf, d->dat[0xf] >> 0x4 & 0x1, d->dat[0xf] >> 0x5 & 0x1);
reqdraw = 1; reqdraw = 1;
} }
} }