Skip to content

Commit

Permalink
fix screen.bounds example on NDS
Browse files Browse the repository at this point in the history
  • Loading branch information
asiekierka committed Apr 30, 2024
1 parent e1d2eb3 commit cddce33
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
24 changes: 13 additions & 11 deletions arm9/source/nds_ppu.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,10 @@ nds_ppu_fill(NdsPpu *p, Uint32 *layer, Uint16 x1, Uint16 y1, Uint16 x2, Uint16 y

ITCM_ARM_CODE
void
nds_ppu_1bpp(NdsPpu *p, Uint32 *layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Uint8 flipx, Uint8 flipy)
nds_ppu_1bpp(NdsPpu *p, Uint32 *layer, int16_t x, int16_t y, Uint8 *sprite, Uint8 color, Uint8 flipx, Uint8 flipy)
{
Uint8 sprline;
Uint8 xleftedge = x >= 0;
Uint8 xrightedge = x < ((PPU_TILES_WIDTH - 1) * 8);
Uint16 v;
Uint32 dirtyflag = (1 << (x >> 3)) | (1 << ((x + 7) >> 3));
Expand All @@ -215,7 +216,7 @@ nds_ppu_1bpp(NdsPpu *p, Uint32 *layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8

if (flipy) flipy = 7;

if(x >= PPU_TILES_WIDTH * 8 || y >= PPU_TILES_HEIGHT * 8)
if(x <= -8 || y <= -8 || x >= PPU_TILES_WIDTH * 8 || y >= PPU_TILES_HEIGHT * 8)
return;

if (blending[4][color]) {
Expand All @@ -227,7 +228,7 @@ nds_ppu_1bpp(NdsPpu *p, Uint32 *layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8
u64 data = (u64)(lut_expand[sprline] & color_fg) << shift;
data |= (u64)(lut_expand[sprline ^ 0xFF] & color_bg) << shift;

layerptr[0] = (layerptr[0] & mask) | data;
if (xleftedge) layerptr[0] = (layerptr[0] & mask) | data;
if (xrightedge) layerptr[8] = (layerptr[8] & (mask >> 32)) | (data >> 32);
} else if (!flipy) break;

Expand All @@ -240,25 +241,26 @@ nds_ppu_1bpp(NdsPpu *p, Uint32 *layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8
u64 mask = ~((u64)(lut_expand[sprline]) << shift);
u64 data = (u64)(lut_expand[sprline] & color_fg) << shift;

layerptr[0] = (layerptr[0] & mask) | data;
if (xleftedge) layerptr[0] = (layerptr[0] & mask) | data;
if (xrightedge) layerptr[8] = (layerptr[8] & (mask >> 32)) | (data >> 32);
} else if (!flipy) break;

if (((y + v) & 7) == 7) layerptr += (PPU_TILES_WIDTH - 1) * 8;
}
}

tile_dirty[y >> 3] |= dirtyflag;
if (y >= 0) tile_dirty[y >> 3] |= dirtyflag;
tile_dirty[(y + 7) >> 3] |= dirtyflag;
}

#ifndef DEBUG
ITCM_ARM_CODE
#endif
void
nds_ppu_2bpp(NdsPpu *p, Uint32 *layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Uint8 flipx, Uint8 flipy)
nds_ppu_2bpp(NdsPpu *p, Uint32 *layer, int16_t x, int16_t y, Uint8 *sprite, Uint8 color, Uint8 flipx, Uint8 flipy)
{
Uint8 sprline1, sprline2;
Uint8 xleftedge = x >= 0;
Uint8 xrightedge = x < ((PPU_TILES_WIDTH - 1) * 8);
Uint16 v, h;
Uint32 dirtyflag = (1 << (x >> 3)) | (1 << ((x + 7) >> 3));
Expand All @@ -269,7 +271,7 @@ nds_ppu_2bpp(NdsPpu *p, Uint32 *layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8

if (flipy) flipy = 7;

if(x >= PPU_TILES_WIDTH * 8 || y >= PPU_TILES_HEIGHT * 8)
if(x <= -8 || y <= -8 || x >= PPU_TILES_WIDTH * 8 || y >= PPU_TILES_HEIGHT * 8)
return;

if (color == 1) {
Expand All @@ -284,7 +286,7 @@ nds_ppu_2bpp(NdsPpu *p, Uint32 *layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8
u32 data32 = (lut_expand[sprline1]) | ((lut_expand[sprline2]) << 1);
u64 data = ((u64) (data32)) << shift;

layerptr[0] = (layerptr[0] & mask) | data;
if (xleftedge) layerptr[0] = (layerptr[0] & mask) | data;
if (xrightedge) layerptr[8] = (layerptr[8] & (mask >> 32)) | (data >> 32);
} else if (!flipy) break;

Expand Down Expand Up @@ -321,7 +323,7 @@ nds_ppu_2bpp(NdsPpu *p, Uint32 *layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8

u64 data = ((u64) (data32)) << shift;

layerptr[0] = (layerptr[0] & mask) | data;
if (xleftedge) layerptr[0] = (layerptr[0] & mask) | data;
if (xrightedge) layerptr[8] = (layerptr[8] & (mask >> 32)) | (data >> 32);
} else if (!flipy) break;

Expand Down Expand Up @@ -364,15 +366,15 @@ nds_ppu_2bpp(NdsPpu *p, Uint32 *layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8
u64 data = ((u64) (data32)) << shift;
u64 mask = ~(((u64) (mask32)) << shift);

layerptr[0] = (layerptr[0] & mask) | data;
if (xleftedge) layerptr[0] = (layerptr[0] & mask) | data;
if (xrightedge) layerptr[8] = (layerptr[8] & (mask >> 32)) | (data >> 32);
} else if (!flipy) break;

if (((y + v) & 7) == 7) layerptr += (PPU_TILES_WIDTH - 1) * 8;
}
}

tile_dirty[y >> 3] |= dirtyflag;
if (y >= 0) tile_dirty[y >> 3] |= dirtyflag;
tile_dirty[(y + 7) >> 3] |= dirtyflag;
}

Expand Down
5 changes: 3 additions & 2 deletions arm9/source/nds_ppu.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>

Expand Down Expand Up @@ -31,6 +32,6 @@ int nds_initppu(NdsPpu *p);
void nds_putcolors(NdsPpu *p, Uint8 *addr);
void nds_ppu_pixel(NdsPpu *p, Uint32 *layer, Uint16 x, Uint16 y, Uint8 color);
void nds_ppu_fill(NdsPpu *p, Uint32 *layer, Uint16 x1, Uint16 y1, Uint16 x2, Uint16 y2, Uint8 color);
void nds_ppu_2bpp(NdsPpu *p, Uint32 *layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Uint8 flipx, Uint8 flipy);
void nds_ppu_1bpp(NdsPpu *p, Uint32 *layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Uint8 flipx, Uint8 flipy);
void nds_ppu_2bpp(NdsPpu *p, Uint32 *layer, int16_t x, int16_t y, Uint8 *sprite, Uint8 color, Uint8 flipx, Uint8 flipy);
void nds_ppu_1bpp(NdsPpu *p, Uint32 *layer, int16_t x, int16_t y, Uint8 *sprite, Uint8 color, Uint8 flipx, Uint8 flipy);
void nds_copyppu(NdsPpu *p);

0 comments on commit cddce33

Please sign in to comment.