Moved get_pixel to ppu.c
This commit is contained in:
parent
08f7ef10e5
commit
8d72c36123
|
@ -35,8 +35,15 @@ ppu_clear(Ppu *p)
|
||||||
p->dat[i] = 0;
|
p->dat[i] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Uint8
|
||||||
|
ppu_read(Ppu *p, Uint16 x, Uint16 y)
|
||||||
|
{
|
||||||
|
unsigned int i = x / PPW + y * p->stride, shift = x % PPW * 4;
|
||||||
|
return (p->dat[i] >> shift) & 0xf;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ppu_pixel(Ppu *p, int fg, Uint16 x, Uint16 y, Uint8 color)
|
ppu_write(Ppu *p, int fg, Uint16 x, Uint16 y, Uint8 color)
|
||||||
{
|
{
|
||||||
unsigned int v, i = x / PPW + y * p->stride, shift = x % PPW * 4;
|
unsigned int v, i = x / PPW + y * p->stride, shift = x % PPW * 4;
|
||||||
if(x >= p->width || y >= p->height)
|
if(x >= p->width || y >= p->height)
|
||||||
|
@ -60,7 +67,7 @@ ppu_1bpp(Ppu *p, int fg, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Uint8 f
|
||||||
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])
|
||||||
ppu_pixel(p,
|
ppu_write(p,
|
||||||
fg,
|
fg,
|
||||||
x + (flipx ? 7 - h : h),
|
x + (flipx ? 7 - h : h),
|
||||||
y + (flipy ? 7 - v : v),
|
y + (flipy ? 7 - v : v),
|
||||||
|
@ -78,7 +85,7 @@ ppu_2bpp(Ppu *p, int fg, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Uint8 f
|
||||||
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])
|
||||||
ppu_pixel(p,
|
ppu_write(p,
|
||||||
fg,
|
fg,
|
||||||
x + (flipx ? 7 - h : h),
|
x + (flipx ? 7 - h : h),
|
||||||
y + (flipy ? 7 - v : v),
|
y + (flipy ? 7 - v : v),
|
||||||
|
|
|
@ -26,8 +26,9 @@ typedef struct Ppu {
|
||||||
unsigned int i0, i1, redraw, *dat, stride;
|
unsigned int i0, i1, redraw, *dat, stride;
|
||||||
} Ppu;
|
} Ppu;
|
||||||
|
|
||||||
|
Uint8 ppu_read(Ppu *p, Uint16 x, Uint16 y);
|
||||||
|
void ppu_write(Ppu *p, int fg, Uint16 x, Uint16 y, Uint8 color);
|
||||||
void ppu_frame(Ppu *p);
|
void ppu_frame(Ppu *p);
|
||||||
int ppu_set_size(Ppu *p, Uint16 width, Uint16 height);
|
|
||||||
void ppu_pixel(Ppu *p, int fg, Uint16 x, Uint16 y, Uint8 color);
|
|
||||||
void ppu_1bpp(Ppu *p, int fg, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Uint8 flipx, Uint8 flipy);
|
void ppu_1bpp(Ppu *p, int fg, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Uint8 flipx, Uint8 flipy);
|
||||||
void ppu_2bpp(Ppu *p, int fg, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Uint8 flipx, Uint8 flipy);
|
void ppu_2bpp(Ppu *p, int fg, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Uint8 flipx, Uint8 flipy);
|
||||||
|
int ppu_set_size(Ppu *p, Uint16 width, Uint16 height);
|
||||||
|
|
23
src/uxnemu.c
23
src/uxnemu.c
|
@ -206,22 +206,15 @@ draw_inspect(Ppu *p, Uint8 *stack, Uint8 wptr, Uint8 rptr, Uint8 *memory)
|
||||||
ppu_1bpp(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 */
|
||||||
ppu_pixel(p, 1, x, p->height / 2, 2);
|
ppu_write(p, 1, x, p->height / 2, 2);
|
||||||
ppu_pixel(p, 1, p->width - x, p->height / 2, 2);
|
ppu_write(p, 1, p->width - x, p->height / 2, 2);
|
||||||
ppu_pixel(p, 1, p->width / 2, p->height - x, 2);
|
ppu_write(p, 1, p->width / 2, p->height - x, 2);
|
||||||
ppu_pixel(p, 1, p->width / 2, x, 2);
|
ppu_write(p, 1, p->width / 2, x, 2);
|
||||||
ppu_pixel(p, 1, p->width / 2 - 0x10 / 2 + x, p->height / 2, 2);
|
ppu_write(p, 1, p->width / 2 - 0x10 / 2 + x, p->height / 2, 2);
|
||||||
ppu_pixel(p, 1, p->width / 2, p->height / 2 - 0x10 / 2 + x, 2);
|
ppu_write(p, 1, p->width / 2, p->height / 2 - 0x10 / 2 + x, 2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static Uint8
|
|
||||||
get_pixel(int x, int y)
|
|
||||||
{
|
|
||||||
unsigned int i = x / PPW + y * ppu.stride, shift = x % PPW * 4;
|
|
||||||
return (ppu.dat[i] >> shift) & 0xf;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
redraw(Uxn *u)
|
redraw(Uxn *u)
|
||||||
{
|
{
|
||||||
|
@ -237,7 +230,7 @@ redraw(Uxn *u)
|
||||||
}
|
}
|
||||||
for(y = y0; y < y1; ++y)
|
for(y = y0; y < y1; ++y)
|
||||||
for(x = 0; x < ppu.width; ++x)
|
for(x = 0; x < ppu.width; ++x)
|
||||||
ppu_screen[x + y * ppu.width] = palette[get_pixel(x, y)];
|
ppu_screen[x + y * ppu.width] = palette[ppu_read(&ppu, x, y)];
|
||||||
SDL_UpdateTexture(gTexture, &up, ppu_screen + y0 * ppu.width, ppu.width * sizeof(Uint32));
|
SDL_UpdateTexture(gTexture, &up, ppu_screen + y0 * ppu.width, ppu.width * sizeof(Uint32));
|
||||||
SDL_RenderClear(gRenderer);
|
SDL_RenderClear(gRenderer);
|
||||||
SDL_RenderCopy(gRenderer, gTexture, NULL, NULL);
|
SDL_RenderCopy(gRenderer, gTexture, NULL, NULL);
|
||||||
|
@ -404,7 +397,7 @@ screen_talk(Device *d, Uint8 b0, Uint8 w)
|
||||||
Uint16 x = peek16(d->dat, 0x8);
|
Uint16 x = peek16(d->dat, 0x8);
|
||||||
Uint16 y = peek16(d->dat, 0xa);
|
Uint16 y = peek16(d->dat, 0xa);
|
||||||
Uint8 layer = d->dat[0xe] & 0x40;
|
Uint8 layer = d->dat[0xe] & 0x40;
|
||||||
ppu_pixel(&ppu, layer, x, y, d->dat[0xe] & 0x3);
|
ppu_write(&ppu, layer, x, y, d->dat[0xe] & 0x3);
|
||||||
if(d->dat[0x6] & 0x01) poke16(d->dat, 0x8, x + 1); /* auto x+1 */
|
if(d->dat[0x6] & 0x01) poke16(d->dat, 0x8, x + 1); /* auto x+1 */
|
||||||
if(d->dat[0x6] & 0x02) poke16(d->dat, 0xa, y + 1); /* auto y+1 */
|
if(d->dat[0x6] & 0x02) poke16(d->dat, 0xa, y + 1); /* auto y+1 */
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in New Issue