diff options
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 76 |
1 files changed, 31 insertions, 45 deletions
@@ -28,9 +28,9 @@ | |||
28 | // | 28 | // |
29 | 29 | ||
30 | #if !defined(TEXT_MODE) || TEXT_MODE == 0 | 30 | #if !defined(TEXT_MODE) || TEXT_MODE == 0 |
31 | #define TEXT_LAYER ppu.fg | 31 | #define TEXT_LAYER FG_BACK |
32 | #else | 32 | #else |
33 | #define TEXT_LAYER ppu.bg | 33 | #define TEXT_LAYER BG_BACK |
34 | #endif | 34 | #endif |
35 | 35 | ||
36 | #ifndef CONTROL_METHODS | 36 | #ifndef CONTROL_METHODS |
@@ -46,6 +46,12 @@ | |||
46 | #elif PROF_ENABLE == 1 | 46 | #elif PROF_ENABLE == 1 |
47 | #define TEXT_ENABLE 1 | 47 | #define TEXT_ENABLE 1 |
48 | #define PROF(F,VAR) (profile_start(),(F),(VAR) = MAX(profile_stop(), (VAR))) | 48 | #define PROF(F,VAR) (profile_start(),(F),(VAR) = MAX(profile_stop(), (VAR))) |
49 | #elif PROF_ENABLE == 2 | ||
50 | #define TEXT_ENABLE 1 | ||
51 | // TODO: allow measuring inside a PROF function using profile_measure to store | ||
52 | // temporary values and calcualting the difference. | ||
53 | // TODO: allow per frame or per 60 second averaging of cycle measurement. | ||
54 | // TODO: calculate fps based on frame timing. | ||
49 | #endif | 55 | #endif |
50 | #ifndef PROF_SHOW_X | 56 | #ifndef PROF_SHOW_X |
51 | #define PROF_SHOW_X 0 | 57 | #define PROF_SHOW_X 0 |
@@ -53,45 +59,26 @@ | |||
53 | #ifndef PROF_SHOW_Y | 59 | #ifndef PROF_SHOW_Y |
54 | #define PROF_SHOW_Y 0 | 60 | #define PROF_SHOW_Y 0 |
55 | #endif | 61 | #endif |
56 | /* | ||
57 | // #define PROF_SHOW() \ | ||
58 | // do { \ | ||
59 | // txt_position((PROF_SHOW_X), (PROF_SHOW_Y));\ | ||
60 | // txt_printf("INPUT: %lu ", input_cycles);\ | ||
61 | // txt_position((PROF_SHOW_X), (PROF_SHOW_Y)+1);\ | ||
62 | // txt_printf("EVAL: %lu ", eval_cycles);\ | ||
63 | // txt_position((PROF_SHOW_X), (PROF_SHOW_Y)+2);\ | ||
64 | // txt_printf("FLIP: %lu ", flip_cycles);\ | ||
65 | // txt_position((PROF_SHOW_X), (PROF_SHOW_Y)+3);\ | ||
66 | // txt_printf("MIX: %lu ", mix_cycles);\ | ||
67 | // } while (0) | ||
68 | // #define PROF_SHOW() \ | ||
69 | // do { \ | ||
70 | // txt_position((PROF_SHOW_X), (PROF_SHOW_Y));\ | ||
71 | // txt_printf("PIX: %lu ", ppu_pixel_cycles);\ | ||
72 | // txt_position((PROF_SHOW_X), (PROF_SHOW_Y)+1);\ | ||
73 | // txt_printf("1BPP: %lu ", ppu_icn_cycles);\ | ||
74 | // txt_position((PROF_SHOW_X), (PROF_SHOW_Y)+2);\ | ||
75 | // txt_printf("2BPP: %lu ", ppu_chr_cycles);\ | ||
76 | // txt_position((PROF_SHOW_X), (PROF_SHOW_Y)+3);\ | ||
77 | // txt_printf("FLIP: %lu ", flip_cycles);\ | ||
78 | // } while (0) | ||
79 | // */ | ||
80 | #define PROF_SHOW() \ | 62 | #define PROF_SHOW() \ |
81 | do { \ | 63 | do { \ |
82 | txt_position((PROF_SHOW_X), (PROF_SHOW_Y));\ | 64 | txt_position((PROF_SHOW_X), (PROF_SHOW_Y));\ |
83 | txt_printf("1BPP: %.8lu\n2BPP: %.8lu\nFILL: %.8lu", ppu_icn_cycles, ppu_chr_cycles, ppu_fill_cycles);\ | 65 | txt_printf("FLIP: %.8lu\n", flip_cycles);\ |
66 | txt_printf("EVAL: %.8lu\n", eval_cycles);\ | ||
67 | screen_fill(BG_BACK, 0, 0, 15 * 8, 2 * 8, 0);\ | ||
68 | flipbuf();\ | ||
84 | } while (0) | 69 | } while (0) |
85 | 70 | ||
86 | static u32 ppu_pixel_cycles = 0; | 71 | |
87 | static u32 ppu_fill_cycles = 0; | 72 | // static u32 ppu_pixel_cycles = 0; |
88 | static u32 ppu_chr_cycles = 0; | 73 | // static u32 ppu_fill_cycles = 0; |
89 | static u32 ppu_icn_cycles = 0; | 74 | // static u32 ppu_chr_cycles = 0; |
75 | // static u32 ppu_icn_cycles = 0; | ||
90 | static u32 flip_cycles = 0; | 76 | static u32 flip_cycles = 0; |
91 | static u32 eval_cycles = 0; | 77 | static u32 eval_cycles = 0; |
92 | static u32 input_cycles = 0; | 78 | static u32 input_cycles = 0; |
93 | static u32 mix_cycles = 0; | 79 | static u32 mix_cycles = 0; |
94 | 80 | #define FRAME_START() ; // TODO | |
81 | #define FRAME_END() ; // TODO | ||
95 | #else | 82 | #else |
96 | #define PROF(F,VAR) (F) | 83 | #define PROF(F,VAR) (F) |
97 | #define PROF_SHOW() | 84 | #define PROF_SHOW() |
@@ -120,7 +107,6 @@ EWRAM_BSS | |||
120 | static u8 umem[0x10300]; | 107 | static u8 umem[0x10300]; |
121 | 108 | ||
122 | static Uxn u; | 109 | static Uxn u; |
123 | static Ppu ppu; | ||
124 | 110 | ||
125 | static Mouse mouse = {SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2}; | 111 | static Mouse mouse = {SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2}; |
126 | 112 | ||
@@ -155,17 +141,15 @@ screen_deo(u8 *ram, u8 *d, u8 port) { | |||
155 | u8 color = ctrl & 0x3; | 141 | u8 color = ctrl & 0x3; |
156 | u16 x0 = PEEK2(d + 0x8); | 142 | u16 x0 = PEEK2(d + 0x8); |
157 | u16 y0 = PEEK2(d + 0xa); | 143 | u16 y0 = PEEK2(d + 0xa); |
158 | u8 *layer = (ctrl & 0x40) ? ppu.fg : ppu.bg; | 144 | u8 *layer = (ctrl & 0x40) ? FG_BACK : BG_BACK; |
159 | if(ctrl & 0x80) { | 145 | if(ctrl & 0x80) { |
160 | u16 x1 = SCREEN_WIDTH - 1; | 146 | u16 x1 = SCREEN_WIDTH - 1; |
161 | u16 y1 = SCREEN_HEIGHT - 1; | 147 | u16 y1 = SCREEN_HEIGHT - 1; |
162 | if(ctrl & 0x10) x1 = x0, x0 = 0; | 148 | if(ctrl & 0x10) x1 = x0, x0 = 0; |
163 | if(ctrl & 0x20) y1 = y0, y0 = 0; | 149 | if(ctrl & 0x20) y1 = y0, y0 = 0; |
164 | PROF(screen_fill(layer, x0, y0, x1, y1, color), ppu_fill_cycles); | 150 | screen_fill(layer, x0, y0, x1, y1, color); |
165 | } else { | 151 | } else { |
166 | u16 width = SCREEN_WIDTH; | 152 | ppu_pixel(layer, x0, y0, color); |
167 | u16 height = SCREEN_HEIGHT; | ||
168 | PROF(ppu_pixel(layer, x0, y0, color), ppu_pixel_cycles); | ||
169 | if(d[0x6] & 0x1) POKE2(d + 0x8, x0 + 1); /* auto x+1 */ | 153 | 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 */ | 154 | if(d[0x6] & 0x2) POKE2(d + 0xa, y0 + 1); /* auto y+1 */ |
171 | } | 155 | } |
@@ -183,16 +167,16 @@ screen_deo(u8 *ram, u8 *d, u8 port) { | |||
183 | if(addr > 0x10000 - ((n + 1) << (3 + twobpp))) { | 167 | if(addr > 0x10000 - ((n + 1) << (3 + twobpp))) { |
184 | return; | 168 | return; |
185 | } | 169 | } |
186 | u8 *layer = (d[0xf] & 0x40) ? ppu.fg : ppu.bg; | 170 | u8 *layer = (d[0xf] & 0x40) ? FG_BACK : BG_BACK; |
187 | u8 color = d[0xf] & 0xf; | 171 | u8 color = d[0xf] & 0xf; |
188 | u8 flipx = d[0xf] & 0x10; | 172 | u8 flipx = d[0xf] & 0x10; |
189 | u8 flipy = d[0xf] & 0x20; | 173 | u8 flipy = d[0xf] & 0x20; |
190 | for(size_t i = 0; i <= n; i++) { | 174 | for(size_t i = 0; i <= n; i++) { |
191 | u8 *sprite = &ram[addr]; | 175 | u8 *sprite = &ram[addr]; |
192 | if (twobpp) { | 176 | if (twobpp) { |
193 | PROF(ppu_2bpp(layer, x + dy * i, y + dx * i, sprite, color, flipx, flipy), ppu_chr_cycles); | 177 | ppu_2bpp(layer, x + dy * i, y + dx * i, sprite, color, flipx, flipy); |
194 | } else { | 178 | } else { |
195 | PROF(ppu_1bpp(layer, x + dy * i, y + dx * i, sprite, color, flipx, flipy), ppu_icn_cycles); | 179 | ppu_1bpp(layer, x + dy * i, y + dx * i, sprite, color, flipx, flipy); |
196 | } | 180 | } |
197 | addr += (d[0x6] & 0x04) << (1 + twobpp); | 181 | addr += (d[0x6] & 0x04) << (1 + twobpp); |
198 | } | 182 | } |
@@ -614,7 +598,7 @@ main(void) { | |||
614 | irs_set(IRQ_VBLANK, sound_vsync); | 598 | irs_set(IRQ_VBLANK, sound_vsync); |
615 | 599 | ||
616 | // Initialize PPU. | 600 | // Initialize PPU. |
617 | initppu(&ppu, 30, 20); | 601 | video_init(); |
618 | 602 | ||
619 | // Initialize text engine. | 603 | // Initialize text engine. |
620 | #ifdef TEXT_ENABLE | 604 | #ifdef TEXT_ENABLE |
@@ -632,17 +616,19 @@ main(void) { | |||
632 | uxn_eval(&u, PAGE_PROGRAM); | 616 | uxn_eval(&u, PAGE_PROGRAM); |
633 | u8 frame_counter = 0; | 617 | u8 frame_counter = 0; |
634 | while(true) { | 618 | while(true) { |
635 | bios_vblank_wait(); | 619 | FRAME_START(); |
636 | PROF(handle_input(&u), input_cycles); | 620 | PROF(handle_input(&u), input_cycles); |
637 | PROF(uxn_eval(&u, PEEK2(&u.dev[0x20])), eval_cycles); | 621 | PROF(uxn_eval(&u, PEEK2(&u.dev[0x20])), eval_cycles); |
638 | PROF(sound_mix(), mix_cycles); | 622 | PROF(sound_mix(), mix_cycles); |
639 | PROF_SHOW(); | 623 | bios_vblank_wait(); |
640 | PROF(flipbuf(&ppu), flip_cycles); | 624 | PROF(flipbuf(), flip_cycles); |
641 | frame_counter++; | 625 | frame_counter++; |
642 | if (frame_counter == 60) { | 626 | if (frame_counter == 60) { |
643 | seconds++; | 627 | seconds++; |
644 | frame_counter = 0; | 628 | frame_counter = 0; |
645 | } | 629 | } |
630 | PROF_SHOW(); | ||
631 | FRAME_END(); | ||
646 | } | 632 | } |
647 | 633 | ||
648 | return 0; | 634 | return 0; |