diff options
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 104 |
1 files changed, 57 insertions, 47 deletions
@@ -80,19 +80,21 @@ | |||
80 | #define PROF_SHOW() \ | 80 | #define PROF_SHOW() \ |
81 | do { \ | 81 | do { \ |
82 | txt_position((PROF_SHOW_X), (PROF_SHOW_Y));\ | 82 | txt_position((PROF_SHOW_X), (PROF_SHOW_Y));\ |
83 | txt_printf("1BPP: %lu 2BPP: %lu", ppu_icn_cycles, ppu_chr_cycles);\ | 83 | txt_printf("1BPP: %.8lu\n2BPP: %.8lu\nFILL: %.8lu", ppu_icn_cycles, ppu_chr_cycles, ppu_fill_cycles);\ |
84 | } while (0) | 84 | } while (0) |
85 | |||
85 | static u32 ppu_pixel_cycles = 0; | 86 | static u32 ppu_pixel_cycles = 0; |
87 | static u32 ppu_fill_cycles = 0; | ||
86 | static u32 ppu_chr_cycles = 0; | 88 | static u32 ppu_chr_cycles = 0; |
87 | static u32 ppu_icn_cycles = 0; | 89 | static u32 ppu_icn_cycles = 0; |
88 | static u32 flip_cycles = 0; | 90 | static u32 flip_cycles = 0; |
89 | static u32 eval_cycles = 0; | 91 | static u32 eval_cycles = 0; |
90 | static u32 input_cycles = 0; | 92 | static u32 input_cycles = 0; |
91 | static u32 mix_cycles = 0; | 93 | static u32 mix_cycles = 0; |
94 | |||
92 | #else | 95 | #else |
93 | #define PROF(F,VAR) (F) | 96 | #define PROF(F,VAR) (F) |
94 | #define PROF_SHOW() | 97 | #define PROF_SHOW() |
95 | #define PROF_INIT() | ||
96 | #endif | 98 | #endif |
97 | 99 | ||
98 | static time_t seconds = 0; | 100 | static time_t seconds = 0; |
@@ -149,21 +151,23 @@ void | |||
149 | screen_deo(u8 *ram, u8 *d, u8 port) { | 151 | screen_deo(u8 *ram, u8 *d, u8 port) { |
150 | switch(port) { | 152 | switch(port) { |
151 | case 0xe: { | 153 | case 0xe: { |
152 | u16 x, y; | 154 | u8 ctrl = d[0xe]; |
153 | u8 *layer = (d[0xe] & 0x40) ? ppu.fg : ppu.bg; | 155 | u8 color = ctrl & 0x3; |
154 | x = PEEK2(d + 0x8); | 156 | u16 x0 = PEEK2(d + 0x8); |
155 | y = PEEK2(d + 0xa); | 157 | u16 y0 = PEEK2(d + 0xa); |
156 | if(d[0xe] & 0x80) { | 158 | u8 *layer = (ctrl & 0x40) ? ppu.fg : ppu.bg; |
157 | screen_fill(layer, | 159 | if(ctrl & 0x80) { |
158 | (d[0xe] & 0x10) ? 0 : x, | 160 | u16 x1 = SCREEN_WIDTH - 1; |
159 | (d[0xe] & 0x20) ? 0 : y, | 161 | u16 y1 = SCREEN_HEIGHT - 1; |
160 | (d[0xe] & 0x10) ? x : SCREEN_WIDTH, | 162 | if(ctrl & 0x10) x1 = x0, x0 = 0; |
161 | (d[0xe] & 0x20) ? y : SCREEN_HEIGHT, | 163 | if(ctrl & 0x20) y1 = y0, y0 = 0; |
162 | (d[0xe] & 0x03)); | 164 | PROF(screen_fill(layer, x0, y0, x1, y1, color), ppu_fill_cycles); |
163 | } else { | 165 | } else { |
164 | PROF(ppu_pixel(layer, x, y, d[0xe] & 0x3), ppu_pixel_cycles); | 166 | u16 width = SCREEN_WIDTH; |
165 | if(d[0x6] & 0x01) POKE2(d + 0x8, x + 1); /* auto x+1 */ | 167 | u16 height = SCREEN_HEIGHT; |
166 | if(d[0x6] & 0x02) POKE2(d + 0xa, y + 1); /* auto y+1 */ | 168 | PROF(ppu_pixel(layer, x0, y0, color), ppu_pixel_cycles); |
169 | if(d[0x6] & 0x1) POKE2(d + 0x8, x0 + 1); /* auto x+1 */ | ||
170 | if(d[0x6] & 0x2) POKE2(d + 0xa, y0 + 1); /* auto y+1 */ | ||
167 | } | 171 | } |
168 | break; | 172 | break; |
169 | } | 173 | } |
@@ -328,25 +332,30 @@ console_deo(u8 *d, u8 port) { | |||
328 | 332 | ||
329 | static void | 333 | static void |
330 | system_cmd(u8 *ram, u16 addr) { | 334 | system_cmd(u8 *ram, u16 addr) { |
331 | // if(ram[addr] == 0x01) { | 335 | if(ram[addr] == 0x01) { |
332 | // u16 i, length = PEEK2(ram + addr + 1); | 336 | // NOTE: Handle rom paging on a case by case basis if a rom has to be |
333 | // u16 a_page = PEEK2(ram + addr + 1 + 2); | 337 | // split in multiple chunks. The GBA compiler doesn't like allocating |
334 | // u16 a_addr = PEEK2(ram + addr + 1 + 4); | 338 | // big arrays, but it's fine if we split it into chunks of 64KB, for |
335 | // u16 b_addr = PEEK2(ram + addr + 1 + 8); | 339 | // example. |
336 | // u8 *rom = uxn_rom; | 340 | // |
337 | // for(i = 0; i < length; i++) { | 341 | // u16 i, length = PEEK2(ram + addr + 1); |
338 | // switch (a_page % RAM_PAGES) { | 342 | // u16 a_page = PEEK2(ram + addr + 1 + 2); |
339 | // case 0: { rom = uxn_rom; } break; | 343 | // u16 a_addr = PEEK2(ram + addr + 1 + 4); |
340 | // case 1: { rom = uxn_rom_2; } break; | 344 | // u16 b_addr = PEEK2(ram + addr + 1 + 8); |
341 | // case 2: { rom = uxn_rom_3; } break; | 345 | // u8 *rom = uxn_rom; |
342 | // case 3: { rom = uxn_rom_4; } break; | 346 | // for(i = 0; i < length; i++) { |
343 | // case 4: { rom = uxn_rom_5; } break; | 347 | // switch (a_page % RAM_PAGES) { |
344 | // case 5: { rom = uxn_rom_6; } break; | 348 | // case 0: { rom = uxn_rom; } break; |
345 | // case 6: { rom = uxn_rom_7; } break; | 349 | // case 1: { rom = uxn_rom_2; } break; |
346 | // } | 350 | // case 2: { rom = uxn_rom_3; } break; |
347 | // ram[(u16)(b_addr + i)] = rom[(u16)(a_addr + i)]; | 351 | // case 3: { rom = uxn_rom_4; } break; |
352 | // case 4: { rom = uxn_rom_5; } break; | ||
353 | // case 5: { rom = uxn_rom_6; } break; | ||
354 | // case 6: { rom = uxn_rom_7; } break; | ||
355 | // } | ||
356 | // ram[(u16)(b_addr + i)] = rom[(u16)(a_addr + i)]; | ||
348 | // } | 357 | // } |
349 | // } | 358 | } |
350 | } | 359 | } |
351 | 360 | ||
352 | void | 361 | void |
@@ -378,19 +387,20 @@ void | |||
378 | uxn_deo(Uxn *u, u8 addr) { | 387 | uxn_deo(Uxn *u, u8 addr) { |
379 | u8 p = addr & 0x0f, d = addr & 0xf0; | 388 | u8 p = addr & 0x0f, d = addr & 0xf0; |
380 | switch(d) { | 389 | switch(d) { |
381 | case 0x00: | 390 | case 0x00: |
382 | system_deo(u, &u->dev[d], p); | 391 | system_deo(u, &u->dev[d], p); |
383 | if(p > 0x7 && p < 0xe) | 392 | if(p > 0x7 && p < 0xe) { |
384 | putcolors(&u->dev[0x8]); | 393 | putcolors(&u->dev[0x8]); |
385 | break; | 394 | } |
386 | case 0x10: console_deo(&u->dev[d], p); break; | 395 | break; |
387 | case 0x20: screen_deo(u->ram, &u->dev[d], p); break; | 396 | case 0x10: console_deo(&u->dev[d], p); break; |
388 | case 0x30: audio_deo(0, &u->dev[d], p, u); break; | 397 | case 0x20: screen_deo(u->ram, &u->dev[d], p); break; |
389 | case 0x40: audio_deo(1, &u->dev[d], p, u); break; | 398 | case 0x30: audio_deo(0, &u->dev[d], p, u); break; |
390 | case 0x50: audio_deo(2, &u->dev[d], p, u); break; | 399 | case 0x40: audio_deo(1, &u->dev[d], p, u); break; |
391 | case 0x60: audio_deo(3, &u->dev[d], p, u); break; | 400 | case 0x50: audio_deo(2, &u->dev[d], p, u); break; |
392 | case 0xa0: file_deo(0, u->ram, &u->dev[d], p); break; | 401 | case 0x60: audio_deo(3, &u->dev[d], p, u); break; |
393 | case 0xb0: file_deo(1, u->ram, &u->dev[d], p); break; | 402 | case 0xa0: file_deo(0, u->ram, &u->dev[d], p); break; |
403 | case 0xb0: file_deo(1, u->ram, &u->dev[d], p); break; | ||
394 | } | 404 | } |
395 | } | 405 | } |
396 | 406 | ||