diff options
Diffstat (limited to 'src/uxn/devices/ppu.c')
-rw-r--r-- | src/uxn/devices/ppu.c | 76 |
1 files changed, 32 insertions, 44 deletions
diff --git a/src/uxn/devices/ppu.c b/src/uxn/devices/ppu.c index 726b510..4db8c77 100644 --- a/src/uxn/devices/ppu.c +++ b/src/uxn/devices/ppu.c | |||
@@ -14,23 +14,11 @@ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | |||
14 | WITH REGARD TO THIS SOFTWARE. | 14 | WITH REGARD TO THIS SOFTWARE. |
15 | */ | 15 | */ |
16 | 16 | ||
17 | static Uint8 font[][8] = { | 17 | #define FG_FRONT ((u32*)(MEM_VRAM)) |
18 | {0x00, 0x7c, 0x82, 0x82, 0x82, 0x82, 0x82, 0x7c}, | 18 | #define BG_FRONT ((u32*)(MEM_VRAM + KB(20))) |
19 | {0x00, 0x30, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10}, | 19 | #define FG_BACK ((u32*)(MEM_VRAM + KB(44))) |
20 | {0x00, 0x7c, 0x82, 0x02, 0x7c, 0x80, 0x80, 0xfe}, | 20 | #define BG_BACK ((u32*)(MEM_VRAM + KB(64))) |
21 | {0x00, 0x7c, 0x82, 0x02, 0x1c, 0x02, 0x82, 0x7c}, | 21 | #define TILE_MAP ((u32*)(MEM_VRAM + KB(40))) |
22 | {0x00, 0x0c, 0x14, 0x24, 0x44, 0x84, 0xfe, 0x04}, | ||
23 | {0x00, 0xfe, 0x80, 0x80, 0x7c, 0x02, 0x82, 0x7c}, | ||
24 | {0x00, 0x7c, 0x82, 0x80, 0xfc, 0x82, 0x82, 0x7c}, | ||
25 | {0x00, 0x7c, 0x82, 0x02, 0x1e, 0x02, 0x02, 0x02}, | ||
26 | {0x00, 0x7c, 0x82, 0x82, 0x7c, 0x82, 0x82, 0x7c}, | ||
27 | {0x00, 0x7c, 0x82, 0x82, 0x7e, 0x02, 0x82, 0x7c}, | ||
28 | {0x00, 0x7c, 0x82, 0x02, 0x7e, 0x82, 0x82, 0x7e}, | ||
29 | {0x00, 0xfc, 0x82, 0x82, 0xfc, 0x82, 0x82, 0xfc}, | ||
30 | {0x00, 0x7c, 0x82, 0x80, 0x80, 0x80, 0x82, 0x7c}, | ||
31 | {0x00, 0xfc, 0x82, 0x82, 0x82, 0x82, 0x82, 0xfc}, | ||
32 | {0x00, 0x7c, 0x82, 0x80, 0xf0, 0x80, 0x82, 0x7c}, | ||
33 | {0x00, 0x7c, 0x82, 0x80, 0xf0, 0x80, 0x80, 0x80}}; | ||
34 | 22 | ||
35 | static Uint32 unpack_icon_lut[256] = { | 23 | static Uint32 unpack_icon_lut[256] = { |
36 | 0x00000000, 0x00000001, 0x00000010, 0x00000011, 0x00000100, | 24 | 0x00000000, 0x00000001, 0x00000010, 0x00000011, 0x00000100, |
@@ -157,6 +145,7 @@ putcolors(Ppu *p, Uint8 *addr) { | |||
157 | (g << 1) | (g >> 3), | 145 | (g << 1) | (g >> 3), |
158 | (b << 1) | (b >> 3)); | 146 | (b << 1) | (b >> 3)); |
159 | } | 147 | } |
148 | (void)p; | ||
160 | } | 149 | } |
161 | 150 | ||
162 | IWRAM_CODE | 151 | IWRAM_CODE |
@@ -171,6 +160,7 @@ putpixel(Ppu *p, Uint32 *layer, Uint16 x, Uint16 y, Uint8 color) { | |||
171 | size_t shift = start_col * 4; | 160 | size_t shift = start_col * 4; |
172 | layer[pos] = (layer[pos] & (~(0xF << shift))) | (color << shift); | 161 | layer[pos] = (layer[pos] & (~(0xF << shift))) | (color << shift); |
173 | dirty_tiles[tile_y] |= 1 << tile_x; | 162 | dirty_tiles[tile_y] |= 1 << tile_x; |
163 | (void)p; | ||
174 | } | 164 | } |
175 | 165 | ||
176 | IWRAM_CODE | 166 | IWRAM_CODE |
@@ -221,6 +211,7 @@ puticn(Ppu *p, Uint32 *layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Ui | |||
221 | 211 | ||
222 | dirty_tiles[y >> 3] |= dirtyflag; | 212 | dirty_tiles[y >> 3] |= dirtyflag; |
223 | dirty_tiles[(y + 7) >> 3] |= dirtyflag; | 213 | dirty_tiles[(y + 7) >> 3] |= dirtyflag; |
214 | (void)p; | ||
224 | } | 215 | } |
225 | 216 | ||
226 | IWRAM_CODE | 217 | IWRAM_CODE |
@@ -263,13 +254,14 @@ putchr(Ppu *p, Uint32 *layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, | |||
263 | 254 | ||
264 | dirty_tiles[y >> 3] |= dirtyflag; | 255 | dirty_tiles[y >> 3] |= dirtyflag; |
265 | dirty_tiles[(y + 7) >> 3] |= dirtyflag; | 256 | dirty_tiles[(y + 7) >> 3] |= dirtyflag; |
257 | (void)p; | ||
266 | } | 258 | } |
267 | 259 | ||
268 | IWRAM_CODE | 260 | IWRAM_CODE |
269 | void | 261 | void |
270 | flipbuf(Ppu *p) { | 262 | flipbuf(Ppu *p) { |
271 | Tile *mem_fg = &TILE_MEM[0]; | 263 | Tile *mem_fg = FG_FRONT; |
272 | Tile *mem_bg = &TILE_MEM[2]; | 264 | Tile *mem_bg = BG_FRONT; |
273 | for (size_t j = 0; j < 20; ++j) { | 265 | for (size_t j = 0; j < 20; ++j) { |
274 | if (dirty_tiles[j] == 0) { | 266 | if (dirty_tiles[j] == 0) { |
275 | continue; | 267 | continue; |
@@ -301,32 +293,26 @@ initppu(Ppu *p, Uint8 hor, Uint8 ver, Uint8 pad) { | |||
301 | 293 | ||
302 | // Initialize backgrounds. | 294 | // Initialize backgrounds. |
303 | u8 cb_fg = 0; | 295 | u8 cb_fg = 0; |
304 | u8 cb_bg = 2; | 296 | u8 cb_bg = 1; |
305 | u8 sb_idx = 10; | 297 | u8 sb_fg = 20; |
306 | BG_CTRL(0) = BG_CHARBLOCK(cb_fg) | BG_SCREENBLOCK(sb_idx) | BG_PRIORITY(1); | 298 | u8 sb_bg = 21; |
307 | BG_CTRL(1) = BG_CHARBLOCK(cb_bg) | BG_SCREENBLOCK(sb_idx) | BG_PRIORITY(2); | 299 | BG_CTRL(0) = BG_CHARBLOCK(cb_fg) | BG_SCREENBLOCK(sb_fg) | BG_PRIORITY(1); |
308 | 300 | BG_CTRL(1) = BG_CHARBLOCK(cb_bg) | BG_SCREENBLOCK(sb_bg) | BG_PRIORITY(2); | |
309 | // Clear tile memory. | 301 | |
310 | for (size_t i = 0; i < 32 * 20 * 8; ++i) { | 302 | // Clear front buffer. |
311 | p->fg[i] = 0; | 303 | p->fg = FG_FRONT; |
312 | p->bg[i] = 0; | 304 | p->bg = BG_FRONT; |
313 | } | ||
314 | 305 | ||
315 | // Use DMA to clear VRAM. | 306 | // Use DMA to clear VRAM. |
316 | u32 fill = 0; | 307 | u32 fill = 0; |
317 | u32 tile_clear_ctrl = (32 * 20 * 8) | DMA_DST_INC | DMA_SRC_FIXED | DMA_NOW | DMA_CHUNK_32 | DMA_ENABLE; | 308 | dma_fill(p->fg, fill, KB(20), 3); |
318 | DMA_SRC(3) = &fill; | 309 | dma_fill(p->bg, fill, KB(20), 3); |
319 | DMA_DST(3) = p->fg; | 310 | |
320 | DMA_CTRL(3) = tile_clear_ctrl; | 311 | // Clear back buffer. |
321 | DMA_DST(3) = p->bg; | 312 | p->fg = FG_BACK; |
322 | DMA_CTRL(3) = tile_clear_ctrl; | 313 | p->bg = BG_BACK; |
323 | 314 | dma_fill(p->fg, fill, KB(20), 3); | |
324 | p->fg = (u32*) (MEM_VRAM + (56 * 1024)); // 0-20K front, 32K-52K back | 315 | dma_fill(p->bg, fill, KB(20), 3); |
325 | p->bg = (u32*) (MEM_VRAM + (76 * 1024)); // 56K-76K front, 76K-96K back | ||
326 | DMA_DST(3) = p->fg; | ||
327 | DMA_CTRL(3) = tile_clear_ctrl; | ||
328 | DMA_DST(3) = p->bg; | ||
329 | DMA_CTRL(3) = tile_clear_ctrl; | ||
330 | 316 | ||
331 | // Initialize default palette. | 317 | // Initialize default palette. |
332 | PAL_BUFFER_BG[0] = COLOR_BLACK; | 318 | PAL_BUFFER_BG[0] = COLOR_BLACK; |
@@ -335,10 +321,12 @@ initppu(Ppu *p, Uint8 hor, Uint8 ver, Uint8 pad) { | |||
335 | PAL_BUFFER_BG[3] = COLOR_BLUE; | 321 | PAL_BUFFER_BG[3] = COLOR_BLUE; |
336 | 322 | ||
337 | // Initialize memory map. | 323 | // Initialize memory map. |
338 | u16 *mem_map = SCREENBLOCK_MEM[sb_idx]; | 324 | u16 *mem_map_fg = SCREENBLOCK_MEM[sb_fg]; |
325 | u16 *mem_map_bg = SCREENBLOCK_MEM[sb_bg]; | ||
339 | size_t k = 0; | 326 | size_t k = 0; |
340 | for (size_t i = 0; i < 32 * 20; ++i, ++k) { | 327 | for (size_t i = 0; i < 32 * 20; ++i, ++k) { |
341 | mem_map[i] = k; | 328 | mem_map_fg[i] = k; |
329 | mem_map_bg[i] = k + 32 * 4; | ||
342 | } | 330 | } |
343 | 331 | ||
344 | return 1; | 332 | return 1; |