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 /src/uxn/devices/ppu.c | |
parent | 431b35d85fa590d199acadbeaf638711eb10c6af (diff) | |
download | uxngba-b3f4342b584612f95938f1f00ca2d026a3f3c304.tar.gz uxngba-b3f4342b584612f95938f1f00ca2d026a3f3c304.zip |
Apply asie's patch 5 for PPU fixes and cleanup
Diffstat (limited to 'src/uxn/devices/ppu.c')
-rw-r--r-- | src/uxn/devices/ppu.c | 18 |
1 files changed, 7 insertions, 11 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 | ||
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; |