aboutsummaryrefslogtreecommitdiffstats
path: root/src/uxn
diff options
context:
space:
mode:
authorBad Diode <bd@badd10de.dev>2021-05-20 23:41:48 +0200
committerBad Diode <bd@badd10de.dev>2021-05-20 23:41:48 +0200
commitb3f4342b584612f95938f1f00ca2d026a3f3c304 (patch)
tree0189502c98b2d391bfdf5a99c3dcc2d1ba7bf944 /src/uxn
parent431b35d85fa590d199acadbeaf638711eb10c6af (diff)
downloaduxngba-b3f4342b584612f95938f1f00ca2d026a3f3c304.tar.gz
uxngba-b3f4342b584612f95938f1f00ca2d026a3f3c304.zip
Apply asie's patch 5 for PPU fixes and cleanup
Diffstat (limited to 'src/uxn')
-rw-r--r--src/uxn/devices/ppu.c18
-rw-r--r--src/uxn/uxn.c13
2 files changed, 8 insertions, 23 deletions
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
145static u32 dirty_tiles[20] = {0}; 145static u32 dirty_tiles[21] = {0};
146 146
147void 147void
148putcolors(Ppu *p, Uint8 *addr) { 148putcolors(Ppu *p, Uint8 *addr) {
@@ -162,9 +162,7 @@ putcolors(Ppu *p, Uint8 *addr) {
162IWRAM_CODE 162IWRAM_CODE
163void 163void
164putpixel(Ppu *p, Uint32 *layer, Uint16 x, Uint16 y, Uint8 color) { 164putpixel(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
179void 177void
180puticn(Ppu *p, Uint32 *layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Uint8 flipx, Uint8 flipy) { 178puticn(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
231putchr(Ppu *p, Uint32 *layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, 228putchr(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
18static inline void push8(Stack *s, Uint8 a) { 18static 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}
24static inline Uint8 pop8_keep(Stack *s) { 21static 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}
30static inline Uint8 pop8_nokeep(Stack *s) { 24static 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}
36static inline void devpoke8(Device *d, Uint8 a, Uint8 b) { d->dat[a & 0xf] = b; d->talk(d, a & 0x0f, 1); } 27static 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
55static inline void 46static inline void
56opcuxn(Uxn *u, Uint8 instr) 47opcuxn(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
155evaluxn(Uxn *u, Uint16 vec) 146evaluxn(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 }