| ... | ... |
@@ -38,7 +38,7 @@ static Uint8 font[][8] = {
|
| 38 | 38 |
{0x00, 0x7c, 0x82, 0x80, 0xf0, 0x80, 0x80, 0x80}};
|
| 39 | 39 |
|
| 40 | 40 |
void |
| 41 |
-ppu_set_size(Ppu *p, Uint16 width, Uint16 height) |
|
| 41 |
+ppu_resize(Ppu *p, Uint16 width, Uint16 height) |
|
| 42 | 42 |
{
|
| 43 | 43 |
Uint8 *pixels; |
| 44 | 44 |
if(!(pixels = realloc(p->pixels, width * height / 2))) |
| ... | ... |
@@ -49,11 +49,19 @@ ppu_set_size(Ppu *p, Uint16 width, Uint16 height) |
| 49 | 49 |
p->height = height; |
| 50 | 50 |
} |
| 51 | 51 |
|
| 52 |
+void |
|
| 53 |
+ppu_clear(Ppu *p, Uint8 mask) |
|
| 54 |
+{
|
|
| 55 |
+ Uint32 i, size = p->width * p->height / 2; |
|
| 56 |
+ for(i = 0; i < size; ++i) |
|
| 57 |
+ p->pixels[i] &= mask; |
|
| 58 |
+} |
|
| 59 |
+ |
|
| 52 | 60 |
Uint8 |
| 53 | 61 |
ppu_read(Ppu *p, Uint16 x, Uint16 y) |
| 54 | 62 |
{
|
| 55 | 63 |
if(x < p->width && y < p->height) {
|
| 56 |
- Uint32 row = (x + y * p->width) / 0x2; |
|
| 64 |
+ Uint32 row = (x + y * p->width) / 2; |
|
| 57 | 65 |
Uint8 shift = !(x & 0x1) << 2; |
| 58 | 66 |
Uint8 pix = p->pixels[row] >> shift; |
| 59 | 67 |
if(pix & 0x0c) |
| ... | ... |
@@ -67,7 +75,7 @@ void |
| 67 | 75 |
ppu_write(Ppu *p, Uint8 layer, Uint16 x, Uint16 y, Uint8 color) |
| 68 | 76 |
{
|
| 69 | 77 |
if(x < p->width && y < p->height) {
|
| 70 |
- Uint32 row = (x + y * p->width) / 0x2; |
|
| 78 |
+ Uint32 row = (x + y * p->width) / 2; |
|
| 71 | 79 |
Uint8 shift = (!(x & 0x1) << 2) + (layer << 1); |
| 72 | 80 |
Uint8 pix = p->pixels[row]; |
| 73 | 81 |
Uint8 mask = ~(0x3 << shift); |
| ... | ... |
@@ -14,6 +14,10 @@ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 14 | 14 |
WITH REGARD TO THIS SOFTWARE. |
| 15 | 15 |
*/ |
| 16 | 16 |
|
| 17 |
+#define CLEAR_BG 0xcc |
|
| 18 |
+#define CLEAR_FG 0x33 |
|
| 19 |
+#define CLEAR_BOTH 0x00 |
|
| 20 |
+ |
|
| 17 | 21 |
typedef unsigned char Uint8; |
| 18 | 22 |
typedef unsigned short Uint16; |
| 19 | 23 |
typedef unsigned int Uint32; |
| ... | ... |
@@ -23,10 +27,10 @@ typedef struct Ppu {
|
| 23 | 27 |
Uint16 width, height; |
| 24 | 28 |
} Ppu; |
| 25 | 29 |
|
| 26 |
-void ppu_set_size(Ppu *p, Uint16 width, Uint16 height); |
|
| 30 |
+void ppu_resize(Ppu *p, Uint16 width, Uint16 height); |
|
| 31 |
+void ppu_clear(Ppu *p, Uint8 layer); |
|
| 27 | 32 |
Uint8 ppu_read(Ppu *p, Uint16 x, Uint16 y); |
| 28 | 33 |
void ppu_write(Ppu *p, Uint8 layer, Uint16 x, Uint16 y, Uint8 color); |
| 29 |
-void ppu_frame(Ppu *p); |
|
| 30 | 34 |
void ppu_1bpp(Ppu *p, Uint8 layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Uint8 flipx, Uint8 flipy); |
| 31 | 35 |
void ppu_2bpp(Ppu *p, Uint8 layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Uint8 flipx, Uint8 flipy); |
| 32 | 36 |
void ppu_debug(Ppu *p, Uint8 *stack, Uint8 wptr, Uint8 rptr, Uint8 *memory); |
| ... | ... |
@@ -127,7 +127,7 @@ set_zoom(Uint8 scale) |
| 127 | 127 |
static int |
| 128 | 128 |
set_size(Uint16 width, Uint16 height, int is_resize) |
| 129 | 129 |
{
|
| 130 |
- ppu_set_size(&ppu, width, height); |
|
| 130 |
+ ppu_resize(&ppu, width, height); |
|
| 131 | 131 |
gRect.x = PAD; |
| 132 | 132 |
gRect.y = PAD; |
| 133 | 133 |
gRect.w = ppu.width; |
| ... | ... |
@@ -487,7 +487,7 @@ doctrl(Uxn *u, SDL_Event *event, int z) |
| 487 | 487 |
case SDLK_LEFT: flag = 0x40; break; |
| 488 | 488 |
case SDLK_RIGHT: flag = 0x80; break; |
| 489 | 489 |
case SDLK_F1: if(z) set_zoom(zoom > 2 ? 1 : zoom + 1); break; |
| 490 |
- case SDLK_F2: if(z) devsystem->dat[0xe] = !devsystem->dat[0xe]; break; |
|
| 490 |
+ case SDLK_F2: if(z) devsystem->dat[0xe] = !devsystem->dat[0xe]; ppu_clear(&ppu, CLEAR_FG); break; |
|
| 491 | 491 |
case SDLK_F3: if(z) capture_screen(); break; |
| 492 | 492 |
case SDLK_AC_BACK: |
| 493 | 493 |
case SDLK_F4: if(z) restart(u); break; |