diff --git a/src/devices/ppu.c b/src/devices/ppu.c index 59a1b77..6a1b8be 100644 --- a/src/devices/ppu.c +++ b/src/devices/ppu.c @@ -38,7 +38,7 @@ static Uint8 font[][8] = { {0x00, 0x7c, 0x82, 0x80, 0xf0, 0x80, 0x80, 0x80}}; void -ppu_set_size(Ppu *p, Uint16 width, Uint16 height) +ppu_resize(Ppu *p, Uint16 width, Uint16 height) { Uint8 *pixels; if(!(pixels = realloc(p->pixels, width * height / 2))) @@ -49,11 +49,19 @@ ppu_set_size(Ppu *p, Uint16 width, Uint16 height) p->height = height; } +void +ppu_clear(Ppu *p, Uint8 mask) +{ + Uint32 i, size = p->width * p->height / 2; + for(i = 0; i < size; ++i) + p->pixels[i] &= mask; +} + Uint8 ppu_read(Ppu *p, Uint16 x, Uint16 y) { if(x < p->width && y < p->height) { - Uint32 row = (x + y * p->width) / 0x2; + Uint32 row = (x + y * p->width) / 2; Uint8 shift = !(x & 0x1) << 2; Uint8 pix = p->pixels[row] >> shift; if(pix & 0x0c) @@ -67,7 +75,7 @@ void ppu_write(Ppu *p, Uint8 layer, Uint16 x, Uint16 y, Uint8 color) { if(x < p->width && y < p->height) { - Uint32 row = (x + y * p->width) / 0x2; + Uint32 row = (x + y * p->width) / 2; Uint8 shift = (!(x & 0x1) << 2) + (layer << 1); Uint8 pix = p->pixels[row]; Uint8 mask = ~(0x3 << shift); diff --git a/src/devices/ppu.h b/src/devices/ppu.h index 93a8110..7911317 100644 --- a/src/devices/ppu.h +++ b/src/devices/ppu.h @@ -14,6 +14,10 @@ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE. */ +#define CLEAR_BG 0xcc +#define CLEAR_FG 0x33 +#define CLEAR_BOTH 0x00 + typedef unsigned char Uint8; typedef unsigned short Uint16; typedef unsigned int Uint32; @@ -23,10 +27,10 @@ typedef struct Ppu { Uint16 width, height; } Ppu; -void ppu_set_size(Ppu *p, Uint16 width, Uint16 height); +void ppu_resize(Ppu *p, Uint16 width, Uint16 height); +void ppu_clear(Ppu *p, Uint8 layer); Uint8 ppu_read(Ppu *p, Uint16 x, Uint16 y); void ppu_write(Ppu *p, Uint8 layer, Uint16 x, Uint16 y, Uint8 color); -void ppu_frame(Ppu *p); void ppu_1bpp(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); void ppu_debug(Ppu *p, Uint8 *stack, Uint8 wptr, Uint8 rptr, Uint8 *memory); diff --git a/src/uxnemu.c b/src/uxnemu.c index 8e02448..f237052 100644 --- a/src/uxnemu.c +++ b/src/uxnemu.c @@ -127,7 +127,7 @@ set_zoom(Uint8 scale) static int set_size(Uint16 width, Uint16 height, int is_resize) { - ppu_set_size(&ppu, width, height); + ppu_resize(&ppu, width, height); gRect.x = PAD; gRect.y = PAD; gRect.w = ppu.width; @@ -487,7 +487,7 @@ doctrl(Uxn *u, SDL_Event *event, int z) case SDLK_LEFT: flag = 0x40; break; case SDLK_RIGHT: flag = 0x80; break; case SDLK_F1: if(z) set_zoom(zoom > 2 ? 1 : zoom + 1); break; - case SDLK_F2: if(z) devsystem->dat[0xe] = !devsystem->dat[0xe]; break; + case SDLK_F2: if(z) devsystem->dat[0xe] = !devsystem->dat[0xe]; ppu_clear(&ppu, CLEAR_FG); break; case SDLK_F3: if(z) capture_screen(); break; case SDLK_AC_BACK: case SDLK_F4: if(z) restart(u); break;