... | ... |
@@ -39,6 +39,22 @@ static Uint8 font[][8] = { |
39 | 39 |
{0x00, 0x7c, 0x82, 0x80, 0xf0, 0x80, 0x82, 0x7c}, |
40 | 40 |
{0x00, 0x7c, 0x82, 0x80, 0xf0, 0x80, 0x80, 0x80}}; |
41 | 41 |
|
42 |
+void |
|
43 |
+ppu_palette(Ppu *p, Uint8 *addr) |
|
44 |
+{ |
|
45 |
+ int i; |
|
46 |
+ for(i = 0; i < 4; ++i) { |
|
47 |
+ Uint8 |
|
48 |
+ r = (*(addr + i / 2) >> (!(i % 2) << 2)) & 0x0f, |
|
49 |
+ g = (*(addr + 2 + i / 2) >> (!(i % 2) << 2)) & 0x0f, |
|
50 |
+ b = (*(addr + 4 + i / 2) >> (!(i % 2) << 2)) & 0x0f; |
|
51 |
+ p->palette[i] = 0xff000000 | (r << 20) | (r << 16) | (g << 12) | (g << 8) | (b << 4) | b; |
|
52 |
+ } |
|
53 |
+ for(i = 4; i < 16; ++i) |
|
54 |
+ p->palette[i] = p->palette[i / 4]; |
|
55 |
+ p->reqdraw = 1; |
|
56 |
+} |
|
57 |
+ |
|
42 | 58 |
void |
43 | 59 |
ppu_resize(Ppu *p, Uint16 width, Uint16 height) |
44 | 60 |
{ |
... | ... |
@@ -23,8 +23,10 @@ typedef unsigned int Uint32; |
23 | 23 |
typedef struct Ppu { |
24 | 24 |
Uint8 *pixels, reqdraw; |
25 | 25 |
Uint16 width, height; |
26 |
+ Uint32 palette[16]; |
|
26 | 27 |
} Ppu; |
27 | 28 |
|
29 |
+void ppu_palette(Ppu *p, Uint8 *addr); |
|
28 | 30 |
void ppu_resize(Ppu *p, Uint16 width, Uint16 height); |
29 | 31 |
void ppu_clear(Ppu *p, Uint8 layer); |
30 | 32 |
Uint8 ppu_read(Ppu *p, Uint16 x, Uint16 y); |
... | ... |
@@ -39,7 +39,7 @@ static Ppu ppu; |
39 | 39 |
static Apu apu[POLYPHONY]; |
40 | 40 |
static Device *devsystem, *devscreen, *devmouse, *devctrl, *devaudio0, *devconsole; |
41 | 41 |
static Uint8 zoom = 1; |
42 |
-static Uint32 *ppu_screen, stdin_event, audio0_event, palette[16]; |
|
42 |
+static Uint32 *ppu_screen, stdin_event, audio0_event; |
|
43 | 43 |
|
44 | 44 |
static int |
45 | 45 |
clamp(int val, int min, int max) |
... | ... |
@@ -88,22 +88,6 @@ stdin_handler(void *p) |
88 | 88 |
(void)p; |
89 | 89 |
} |
90 | 90 |
|
91 |
-void |
|
92 |
-set_palette(Uint8 *addr) |
|
93 |
-{ |
|
94 |
- int i; |
|
95 |
- for(i = 0; i < 4; ++i) { |
|
96 |
- Uint8 |
|
97 |
- r = (*(addr + i / 2) >> (!(i % 2) << 2)) & 0x0f, |
|
98 |
- g = (*(addr + 2 + i / 2) >> (!(i % 2) << 2)) & 0x0f, |
|
99 |
- b = (*(addr + 4 + i / 2) >> (!(i % 2) << 2)) & 0x0f; |
|
100 |
- palette[i] = 0xff000000 | (r << 20) | (r << 16) | (g << 12) | (g << 8) | (b << 4) | b; |
|
101 |
- } |
|
102 |
- for(i = 4; i < 16; ++i) |
|
103 |
- palette[i] = palette[i / 4]; |
|
104 |
- ppu.reqdraw = 1; |
|
105 |
-} |
|
106 |
- |
|
107 | 91 |
static void |
108 | 92 |
set_window_size(SDL_Window *window, int w, int h) |
109 | 93 |
{ |
... | ... |
@@ -173,7 +157,7 @@ redraw(Uxn *u) |
173 | 157 |
ppu_debug(&ppu, u->wst.dat, u->wst.ptr, u->rst.ptr, u->ram.dat); |
174 | 158 |
for(y = 0; y < ppu.height; ++y) |
175 | 159 |
for(x = 0; x < ppu.width; ++x) |
176 |
- ppu_screen[x + y * ppu.width] = palette[ppu_read(&ppu, x, y)]; |
|
160 |
+ ppu_screen[x + y * ppu.width] = ppu.palette[ppu_read(&ppu, x, y)]; |
|
177 | 161 |
if(SDL_UpdateTexture(gTexture, &gRect, ppu_screen, ppu.width * sizeof(Uint32)) != 0) |
178 | 162 |
error("SDL_UpdateTexture", SDL_GetError()); |
179 | 163 |
SDL_RenderClear(gRenderer); |
... | ... |
@@ -277,7 +261,7 @@ system_deo(Device *d, Uint8 port) |
277 | 261 |
case 0x3: d->u->rst.ptr = d->dat[port]; break; |
278 | 262 |
} |
279 | 263 |
if(port > 0x7 && port < 0xe) |
280 |
- set_palette(&d->dat[0x8]); |
|
264 |
+ ppu_palette(&ppu, &d->dat[0x8]); |
|
281 | 265 |
} |
282 | 266 |
|
283 | 267 |
static void |