diff options
author | Bad Diode <bd@badd10de.dev> | 2021-05-20 23:41:48 +0200 |
---|---|---|
committer | Bad Diode <bd@badd10de.dev> | 2021-05-20 23:41:48 +0200 |
commit | b3f4342b584612f95938f1f00ca2d026a3f3c304 (patch) | |
tree | 0189502c98b2d391bfdf5a99c3dcc2d1ba7bf944 | |
parent | 431b35d85fa590d199acadbeaf638711eb10c6af (diff) | |
download | uxngba-b3f4342b584612f95938f1f00ca2d026a3f3c304.tar.gz uxngba-b3f4342b584612f95938f1f00ca2d026a3f3c304.zip |
Apply asie's patch 5 for PPU fixes and cleanup
-rw-r--r-- | src/main.c | 8 | ||||
-rw-r--r-- | src/uxn/devices/ppu.c | 18 | ||||
-rw-r--r-- | src/uxn/uxn.c | 13 |
3 files changed, 8 insertions, 31 deletions
@@ -25,7 +25,6 @@ WITH REGARD TO THIS SOFTWARE. | |||
25 | */ | 25 | */ |
26 | 26 | ||
27 | static Ppu ppu; | 27 | static Ppu ppu; |
28 | u8 reqdraw = 0; | ||
29 | static Device *devscreen; | 28 | static Device *devscreen; |
30 | static Device *devctrl; | 29 | static Device *devctrl; |
31 | time_t time_seconds; | 30 | time_t time_seconds; |
@@ -78,7 +77,6 @@ screen_talk(Device *d, Uint8 b0, Uint8 w) { | |||
78 | } else { | 77 | } else { |
79 | putchr(&ppu, layer, x, y, addr, d->dat[0xe] & 0xf, mode & 0x2, mode & 0x4); | 78 | putchr(&ppu, layer, x, y, addr, d->dat[0xe] & 0xf, mode & 0x2, mode & 0x4); |
80 | } | 79 | } |
81 | reqdraw = 1; | ||
82 | } | 80 | } |
83 | } | 81 | } |
84 | 82 | ||
@@ -192,7 +190,6 @@ int main(void) { | |||
192 | irq_init(); | 190 | irq_init(); |
193 | irs_set(IRQ_VBLANK, irs_stub); | 191 | irs_set(IRQ_VBLANK, irs_stub); |
194 | 192 | ||
195 | |||
196 | // Initialize VM. | 193 | // Initialize VM. |
197 | memset(&u, 0, sizeof(u)); | 194 | memset(&u, 0, sizeof(u)); |
198 | u.ram.dat = umem; | 195 | u.ram.dat = umem; |
@@ -215,13 +212,8 @@ int main(void) { | |||
215 | while(true) { | 212 | while(true) { |
216 | bios_vblank_wait(); | 213 | bios_vblank_wait(); |
217 | handle_input(&u); | 214 | handle_input(&u); |
218 | profile_start(); | ||
219 | evaluxn(&u, mempeek16(devscreen->dat, 0)); | 215 | evaluxn(&u, mempeek16(devscreen->dat, 0)); |
220 | int eval_cycles = profile_stop(); | ||
221 | flipbuf(&ppu); | 216 | flipbuf(&ppu); |
222 | txt_position(0,0); | ||
223 | txt_printf("FRAME: %d\n", frame_counter); | ||
224 | txt_printf("EVAL: %d\n", eval_cycles); | ||
225 | time_seconds++; | 217 | time_seconds++; |
226 | frame_counter++; | 218 | frame_counter++; |
227 | } | 219 | } |
diff --git a/src/uxn/devices/ppu.c b/src/uxn/devices/ppu.c index 61e4d26..726b510 100644 --- a/src/uxn/devices/ppu.c +++ b/src/uxn/devices/ppu.c | |||
@@ -142,7 +142,7 @@ static Uint32 unpack_icon_lut_flipx[256] = { | |||
142 | 0x11111111 | 142 | 0x11111111 |
143 | }; | 143 | }; |
144 | 144 | ||
145 | static u32 dirty_tiles[20] = {0}; | 145 | static u32 dirty_tiles[21] = {0}; |
146 | 146 | ||
147 | void | 147 | void |
148 | putcolors(Ppu *p, Uint8 *addr) { | 148 | putcolors(Ppu *p, Uint8 *addr) { |
@@ -162,9 +162,7 @@ putcolors(Ppu *p, Uint8 *addr) { | |||
162 | IWRAM_CODE | 162 | IWRAM_CODE |
163 | void | 163 | void |
164 | putpixel(Ppu *p, Uint32 *layer, Uint16 x, Uint16 y, Uint8 color) { | 164 | putpixel(Ppu *p, Uint32 *layer, Uint16 x, Uint16 y, Uint8 color) { |
165 | if(x >= 30 * 8 || y >= 20 * 8) { | 165 | if (x >= SCREEN_WIDTH || y >= SCREEN_HEIGHT) return; |
166 | return; | ||
167 | } | ||
168 | size_t tile_x = x / 8; | 166 | size_t tile_x = x / 8; |
169 | size_t tile_y = y / 8; | 167 | size_t tile_y = y / 8; |
170 | size_t start_col = x % 8; | 168 | size_t start_col = x % 8; |
@@ -179,7 +177,6 @@ IWRAM_CODE | |||
179 | void | 177 | void |
180 | puticn(Ppu *p, Uint32 *layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Uint8 flipx, Uint8 flipy) { | 178 | puticn(Ppu *p, Uint32 *layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Uint8 flipx, Uint8 flipy) { |
181 | Uint8 sprline; | 179 | Uint8 sprline; |
182 | Uint8 xrightedge = x < ((32 - 1) * 8); | ||
183 | Uint16 v; | 180 | Uint16 v; |
184 | Uint32 dirtyflag = (1 << (x >> 3)) | (1 << ((x + 7) >> 3)); | 181 | Uint32 dirtyflag = (1 << (x >> 3)) | (1 << ((x + 7) >> 3)); |
185 | 182 | ||
@@ -203,7 +200,7 @@ puticn(Ppu *p, Uint32 *layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Ui | |||
203 | data |= (u64)(lut_expand[sprline ^ 0xFF] * (color >> 2)) << shift; | 200 | data |= (u64)(lut_expand[sprline ^ 0xFF] * (color >> 2)) << shift; |
204 | 201 | ||
205 | layerptr[0] = (layerptr[0] & mask) | data; | 202 | layerptr[0] = (layerptr[0] & mask) | data; |
206 | if (xrightedge) layerptr[8] = (layerptr[8] & (mask >> 32)) | (data >> 32); | 203 | layerptr[8] = (layerptr[8] & (mask >> 32)) | (data >> 32); |
207 | 204 | ||
208 | if (((y + v) & 7) == 7) layerptr += (32 - 1) * 8; | 205 | if (((y + v) & 7) == 7) layerptr += (32 - 1) * 8; |
209 | } | 206 | } |
@@ -216,7 +213,7 @@ puticn(Ppu *p, Uint32 *layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Ui | |||
216 | u64 data = (u64)(lut_expand[sprline] * (color & 3)) << shift; | 213 | u64 data = (u64)(lut_expand[sprline] * (color & 3)) << shift; |
217 | 214 | ||
218 | layerptr[0] = (layerptr[0] & mask) | data; | 215 | layerptr[0] = (layerptr[0] & mask) | data; |
219 | if (xrightedge) layerptr[8] = (layerptr[8] & (mask >> 32)) | (data >> 32); | 216 | layerptr[8] = (layerptr[8] & (mask >> 32)) | (data >> 32); |
220 | 217 | ||
221 | if (((y + v) & 7) == 7) layerptr += (32 - 1) * 8; | 218 | if (((y + v) & 7) == 7) layerptr += (32 - 1) * 8; |
222 | } | 219 | } |
@@ -231,7 +228,6 @@ void | |||
231 | putchr(Ppu *p, Uint32 *layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, | 228 | putchr(Ppu *p, Uint32 *layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, |
232 | Uint8 flipx, Uint8 flipy) { | 229 | Uint8 flipx, Uint8 flipy) { |
233 | Uint8 sprline1, sprline2; | 230 | Uint8 sprline1, sprline2; |
234 | Uint8 xrightedge = x < ((32 - 1) * 8); | ||
235 | Uint16 v; | 231 | Uint16 v; |
236 | Uint32 dirtyflag = (1 << (x >> 3)) | (1 << ((x + 7) >> 3)); | 232 | Uint32 dirtyflag = (1 << (x >> 3)) | (1 << ((x + 7) >> 3)); |
237 | 233 | ||
@@ -260,7 +256,7 @@ putchr(Ppu *p, Uint32 *layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, | |||
260 | u64 data = ((u64) (data32 & 0x33333333)) << shift; | 256 | u64 data = ((u64) (data32 & 0x33333333)) << shift; |
261 | 257 | ||
262 | layerptr[0] = (layerptr[0] & mask) | data; | 258 | layerptr[0] = (layerptr[0] & mask) | data; |
263 | if (xrightedge) layerptr[8] = (layerptr[8] & (mask >> 32)) | (data >> 32); | 259 | layerptr[8] = (layerptr[8] & (mask >> 32)) | (data >> 32); |
264 | 260 | ||
265 | if (((y + v) & 7) == 7) layerptr += (32 - 1) * 8; | 261 | if (((y + v) & 7) == 7) layerptr += (32 - 1) * 8; |
266 | } | 262 | } |
@@ -325,8 +321,8 @@ initppu(Ppu *p, Uint8 hor, Uint8 ver, Uint8 pad) { | |||
325 | DMA_DST(3) = p->bg; | 321 | DMA_DST(3) = p->bg; |
326 | DMA_CTRL(3) = tile_clear_ctrl; | 322 | DMA_CTRL(3) = tile_clear_ctrl; |
327 | 323 | ||
328 | p->fg = (u32*) (MEM_VRAM + (56 * 1024)); | 324 | p->fg = (u32*) (MEM_VRAM + (56 * 1024)); // 0-20K front, 32K-52K back |
329 | p->bg = (u32*) (MEM_VRAM + (76 * 1024)); | 325 | p->bg = (u32*) (MEM_VRAM + (76 * 1024)); // 56K-76K front, 76K-96K back |
330 | DMA_DST(3) = p->fg; | 326 | DMA_DST(3) = p->fg; |
331 | DMA_CTRL(3) = tile_clear_ctrl; | 327 | DMA_CTRL(3) = tile_clear_ctrl; |
332 | DMA_DST(3) = p->bg; | 328 | DMA_DST(3) = p->bg; |
diff --git a/src/uxn/uxn.c b/src/uxn/uxn.c index 8e76660..53f7983 100644 --- a/src/uxn/uxn.c +++ b/src/uxn/uxn.c | |||
@@ -16,21 +16,12 @@ WITH REGARD TO THIS SOFTWARE. | |||
16 | /* clang-format off */ | 16 | /* clang-format off */ |
17 | 17 | ||
18 | static inline void push8(Stack *s, Uint8 a) { | 18 | static inline void push8(Stack *s, Uint8 a) { |
19 | #ifdef CPU_ERROR_CHECKING | ||
20 | if (s->ptr == 0xff) { s->error = 2; return; } | ||
21 | #endif | ||
22 | s->dat[s->ptr++] = a; | 19 | s->dat[s->ptr++] = a; |
23 | } | 20 | } |
24 | static inline Uint8 pop8_keep(Stack *s) { | 21 | static inline Uint8 pop8_keep(Stack *s) { |
25 | #ifdef CPU_ERROR_CHECKING | ||
26 | if (s->kptr == 0) { s->error = 1; return 0; } | ||
27 | #endif | ||
28 | return s->dat[--s->kptr]; | 22 | return s->dat[--s->kptr]; |
29 | } | 23 | } |
30 | static inline Uint8 pop8_nokeep(Stack *s) { | 24 | static inline Uint8 pop8_nokeep(Stack *s) { |
31 | #ifdef CPU_ERROR_CHECKING | ||
32 | if (s->ptr == 0) { s->error = 1; return 0; } | ||
33 | #endif | ||
34 | return s->dat[--s->ptr]; | 25 | return s->dat[--s->ptr]; |
35 | } | 26 | } |
36 | static inline void devpoke8(Device *d, Uint8 a, Uint8 b) { d->dat[a & 0xf] = b; d->talk(d, a & 0x0f, 1); } | 27 | static inline void devpoke8(Device *d, Uint8 a, Uint8 b) { d->dat[a & 0xf] = b; d->talk(d, a & 0x0f, 1); } |
@@ -55,7 +46,7 @@ IWRAM_CODE | |||
55 | static inline void | 46 | static inline void |
56 | opcuxn(Uxn *u, Uint8 instr) | 47 | opcuxn(Uxn *u, Uint8 instr) |
57 | { | 48 | { |
58 | #ifdef CPU_ERROR_CHECKING | 49 | #if 1 |
59 | // With CPU error checking enabled, the codebase becomes too large to fit in ITCM. | 50 | // With CPU error checking enabled, the codebase becomes too large to fit in ITCM. |
60 | // Therefore, we take some concessions. | 51 | // Therefore, we take some concessions. |
61 | if (instr & 0x40) { | 52 | if (instr & 0x40) { |
@@ -155,8 +146,6 @@ int | |||
155 | evaluxn(Uxn *u, Uint16 vec) | 146 | evaluxn(Uxn *u, Uint16 vec) |
156 | { | 147 | { |
157 | u->ram.ptr = vec; | 148 | u->ram.ptr = vec; |
158 | u->wst.error = 0; | ||
159 | u->rst.error = 0; | ||
160 | while(u->ram.ptr) { | 149 | while(u->ram.ptr) { |
161 | opcuxn(u, u->ram.dat[u->ram.ptr++]); | 150 | opcuxn(u, u->ram.dat[u->ram.ptr++]); |
162 | } | 151 | } |