Palette is now part of the PPU
This commit is contained in:
parent
668eab05bf
commit
0794070adf
|
@ -39,6 +39,22 @@ static Uint8 font[][8] = {
|
||||||
{0x00, 0x7c, 0x82, 0x80, 0xf0, 0x80, 0x82, 0x7c},
|
{0x00, 0x7c, 0x82, 0x80, 0xf0, 0x80, 0x82, 0x7c},
|
||||||
{0x00, 0x7c, 0x82, 0x80, 0xf0, 0x80, 0x80, 0x80}};
|
{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
|
void
|
||||||
ppu_resize(Ppu *p, Uint16 width, Uint16 height)
|
ppu_resize(Ppu *p, Uint16 width, Uint16 height)
|
||||||
{
|
{
|
||||||
|
|
|
@ -23,8 +23,10 @@ typedef unsigned int Uint32;
|
||||||
typedef struct Ppu {
|
typedef struct Ppu {
|
||||||
Uint8 *pixels, reqdraw;
|
Uint8 *pixels, reqdraw;
|
||||||
Uint16 width, height;
|
Uint16 width, height;
|
||||||
|
Uint32 palette[16];
|
||||||
} Ppu;
|
} Ppu;
|
||||||
|
|
||||||
|
void ppu_palette(Ppu *p, Uint8 *addr);
|
||||||
void ppu_resize(Ppu *p, Uint16 width, Uint16 height);
|
void ppu_resize(Ppu *p, Uint16 width, Uint16 height);
|
||||||
void ppu_clear(Ppu *p, Uint8 layer);
|
void ppu_clear(Ppu *p, Uint8 layer);
|
||||||
Uint8 ppu_read(Ppu *p, Uint16 x, Uint16 y);
|
Uint8 ppu_read(Ppu *p, Uint16 x, Uint16 y);
|
||||||
|
|
22
src/uxnemu.c
22
src/uxnemu.c
|
@ -39,7 +39,7 @@ static Ppu ppu;
|
||||||
static Apu apu[POLYPHONY];
|
static Apu apu[POLYPHONY];
|
||||||
static Device *devsystem, *devscreen, *devmouse, *devctrl, *devaudio0, *devconsole;
|
static Device *devsystem, *devscreen, *devmouse, *devctrl, *devaudio0, *devconsole;
|
||||||
static Uint8 zoom = 1;
|
static Uint8 zoom = 1;
|
||||||
static Uint32 *ppu_screen, stdin_event, audio0_event, palette[16];
|
static Uint32 *ppu_screen, stdin_event, audio0_event;
|
||||||
|
|
||||||
static int
|
static int
|
||||||
clamp(int val, int min, int max)
|
clamp(int val, int min, int max)
|
||||||
|
@ -88,22 +88,6 @@ stdin_handler(void *p)
|
||||||
(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
|
static void
|
||||||
set_window_size(SDL_Window *window, int w, int h)
|
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);
|
ppu_debug(&ppu, u->wst.dat, u->wst.ptr, u->rst.ptr, u->ram.dat);
|
||||||
for(y = 0; y < ppu.height; ++y)
|
for(y = 0; y < ppu.height; ++y)
|
||||||
for(x = 0; x < ppu.width; ++x)
|
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)
|
if(SDL_UpdateTexture(gTexture, &gRect, ppu_screen, ppu.width * sizeof(Uint32)) != 0)
|
||||||
error("SDL_UpdateTexture", SDL_GetError());
|
error("SDL_UpdateTexture", SDL_GetError());
|
||||||
SDL_RenderClear(gRenderer);
|
SDL_RenderClear(gRenderer);
|
||||||
|
@ -277,7 +261,7 @@ system_deo(Device *d, Uint8 port)
|
||||||
case 0x3: d->u->rst.ptr = d->dat[port]; break;
|
case 0x3: d->u->rst.ptr = d->dat[port]; break;
|
||||||
}
|
}
|
||||||
if(port > 0x7 && port < 0xe)
|
if(port > 0x7 && port < 0xe)
|
||||||
set_palette(&d->dat[0x8]);
|
ppu_palette(&ppu, &d->dat[0x8]);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
Loading…
Reference in New Issue