commit 0794070adfffbf78ba117f140f259fd52fd33d9d
parent 668eab05bfa7a828312341b32ba0dccd36c39548
Author: neauoire <aliceffekt@gmail.com>
Date: Fri, 24 Dec 2021 09:39:51 -0800
Palette is now part of the PPU
Diffstat:
3 files changed, 21 insertions(+), 19 deletions(-)
diff --git a/src/devices/ppu.c b/src/devices/ppu.c
@@ -40,6 +40,22 @@ static Uint8 font[][8] = {
{0x00, 0x7c, 0x82, 0x80, 0xf0, 0x80, 0x80, 0x80}};
void
+ppu_palette(Ppu *p, Uint8 *addr)
+{
+ int i;
+ for(i = 0; i < 4; ++i) {
+ Uint8
+ r = (*(addr + i / 2) >> (!(i % 2) << 2)) & 0x0f,
+ g = (*(addr + 2 + i / 2) >> (!(i % 2) << 2)) & 0x0f,
+ b = (*(addr + 4 + i / 2) >> (!(i % 2) << 2)) & 0x0f;
+ p->palette[i] = 0xff000000 | (r << 20) | (r << 16) | (g << 12) | (g << 8) | (b << 4) | b;
+ }
+ for(i = 4; i < 16; ++i)
+ p->palette[i] = p->palette[i / 4];
+ p->reqdraw = 1;
+}
+
+void
ppu_resize(Ppu *p, Uint16 width, Uint16 height)
{
Uint8 *pixels;
diff --git a/src/devices/ppu.h b/src/devices/ppu.h
@@ -23,8 +23,10 @@ typedef unsigned int Uint32;
typedef struct Ppu {
Uint8 *pixels, reqdraw;
Uint16 width, height;
+ Uint32 palette[16];
} Ppu;
+void ppu_palette(Ppu *p, Uint8 *addr);
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);
diff --git a/src/uxnemu.c b/src/uxnemu.c
@@ -39,7 +39,7 @@ static Ppu ppu;
static Apu apu[POLYPHONY];
static Device *devsystem, *devscreen, *devmouse, *devctrl, *devaudio0, *devconsole;
static Uint8 zoom = 1;
-static Uint32 *ppu_screen, stdin_event, audio0_event, palette[16];
+static Uint32 *ppu_screen, stdin_event, audio0_event;
static int
clamp(int val, int min, int max)
@@ -88,22 +88,6 @@ stdin_handler(void *p)
(void)p;
}
-void
-set_palette(Uint8 *addr)
-{
- int i;
- for(i = 0; i < 4; ++i) {
- Uint8
- r = (*(addr + i / 2) >> (!(i % 2) << 2)) & 0x0f,
- g = (*(addr + 2 + i / 2) >> (!(i % 2) << 2)) & 0x0f,
- b = (*(addr + 4 + i / 2) >> (!(i % 2) << 2)) & 0x0f;
- palette[i] = 0xff000000 | (r << 20) | (r << 16) | (g << 12) | (g << 8) | (b << 4) | b;
- }
- for(i = 4; i < 16; ++i)
- palette[i] = palette[i / 4];
- ppu.reqdraw = 1;
-}
-
static void
set_window_size(SDL_Window *window, int w, int h)
{
@@ -173,7 +157,7 @@ redraw(Uxn *u)
ppu_debug(&ppu, u->wst.dat, u->wst.ptr, u->rst.ptr, u->ram.dat);
for(y = 0; y < ppu.height; ++y)
for(x = 0; x < ppu.width; ++x)
- ppu_screen[x + y * ppu.width] = palette[ppu_read(&ppu, x, y)];
+ ppu_screen[x + y * ppu.width] = ppu.palette[ppu_read(&ppu, x, y)];
if(SDL_UpdateTexture(gTexture, &gRect, ppu_screen, ppu.width * sizeof(Uint32)) != 0)
error("SDL_UpdateTexture", SDL_GetError());
SDL_RenderClear(gRenderer);
@@ -277,7 +261,7 @@ system_deo(Device *d, Uint8 port)
case 0x3: d->u->rst.ptr = d->dat[port]; break;
}
if(port > 0x7 && port < 0xe)
- set_palette(&d->dat[0x8]);
+ ppu_palette(&ppu, &d->dat[0x8]);
}
static void