aboutsummaryrefslogtreecommitdiffstats
path: root/src/uxn/devices/ppu.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/uxn/devices/ppu.c')
-rw-r--r--src/uxn/devices/ppu.c50
1 files changed, 23 insertions, 27 deletions
diff --git a/src/uxn/devices/ppu.c b/src/uxn/devices/ppu.c
index 4db8c77..02267f0 100644
--- a/src/uxn/devices/ppu.c
+++ b/src/uxn/devices/ppu.c
@@ -20,7 +20,7 @@ WITH REGARD TO THIS SOFTWARE.
20#define BG_BACK ((u32*)(MEM_VRAM + KB(64))) 20#define BG_BACK ((u32*)(MEM_VRAM + KB(64)))
21#define TILE_MAP ((u32*)(MEM_VRAM + KB(40))) 21#define TILE_MAP ((u32*)(MEM_VRAM + KB(40)))
22 22
23static Uint32 unpack_icon_lut[256] = { 23static u32 unpack_icon_lut[256] = {
24 0x00000000, 0x00000001, 0x00000010, 0x00000011, 0x00000100, 24 0x00000000, 0x00000001, 0x00000010, 0x00000011, 0x00000100,
25 0x00000101, 0x00000110, 0x00000111, 0x00001000, 0x00001001, 25 0x00000101, 0x00000110, 0x00000111, 0x00001000, 0x00001001,
26 0x00001010, 0x00001011, 0x00001100, 0x00001101, 0x00001110, 26 0x00001010, 0x00001011, 0x00001100, 0x00001101, 0x00001110,
@@ -75,7 +75,7 @@ static Uint32 unpack_icon_lut[256] = {
75 0x11111111 75 0x11111111
76}; 76};
77 77
78static Uint32 unpack_icon_lut_flipx[256] = { 78static u32 unpack_icon_lut_flipx[256] = {
79 0x00000000, 0x10000000, 0x01000000, 0x11000000, 0x00100000, 79 0x00000000, 0x10000000, 0x01000000, 0x11000000, 0x00100000,
80 0x10100000, 0x01100000, 0x11100000, 0x00010000, 0x10010000, 80 0x10100000, 0x01100000, 0x11100000, 0x00010000, 0x10010000,
81 0x01010000, 0x11010000, 0x00110000, 0x10110000, 0x01110000, 81 0x01010000, 0x11010000, 0x00110000, 0x10110000, 0x01110000,
@@ -133,10 +133,10 @@ static Uint32 unpack_icon_lut_flipx[256] = {
133static u32 dirty_tiles[21] = {0}; 133static u32 dirty_tiles[21] = {0};
134 134
135void 135void
136putcolors(Ppu *p, Uint8 *addr) { 136putcolors(u8 *addr) {
137 int i; 137 int i;
138 for(i = 0; i < 4; ++i) { 138 for(i = 0; i < 4; ++i) {
139 Uint8 139 u8
140 r = (*(addr + i / 2) >> (!(i % 2) << 2)) & 0x0f, 140 r = (*(addr + i / 2) >> (!(i % 2) << 2)) & 0x0f,
141 g = (*(addr + 2 + i / 2) >> (!(i % 2) << 2)) & 0x0f, 141 g = (*(addr + 2 + i / 2) >> (!(i % 2) << 2)) & 0x0f,
142 b = (*(addr + 4 + i / 2) >> (!(i % 2) << 2)) & 0x0f; 142 b = (*(addr + 4 + i / 2) >> (!(i % 2) << 2)) & 0x0f;
@@ -145,12 +145,11 @@ putcolors(Ppu *p, Uint8 *addr) {
145 (g << 1) | (g >> 3), 145 (g << 1) | (g >> 3),
146 (b << 1) | (b >> 3)); 146 (b << 1) | (b >> 3));
147 } 147 }
148 (void)p;
149} 148}
150 149
151IWRAM_CODE 150IWRAM_CODE
152void 151void
153putpixel(Ppu *p, Uint32 *layer, Uint16 x, Uint16 y, Uint8 color) { 152putpixel(u32 *layer, u16 x, u16 y, u8 color) {
154 if (x >= SCREEN_WIDTH || y >= SCREEN_HEIGHT) return; 153 if (x >= SCREEN_WIDTH || y >= SCREEN_HEIGHT) return;
155 size_t tile_x = x / 8; 154 size_t tile_x = x / 8;
156 size_t tile_y = y / 8; 155 size_t tile_y = y / 8;
@@ -160,20 +159,19 @@ putpixel(Ppu *p, Uint32 *layer, Uint16 x, Uint16 y, Uint8 color) {
160 size_t shift = start_col * 4; 159 size_t shift = start_col * 4;
161 layer[pos] = (layer[pos] & (~(0xF << shift))) | (color << shift); 160 layer[pos] = (layer[pos] & (~(0xF << shift))) | (color << shift);
162 dirty_tiles[tile_y] |= 1 << tile_x; 161 dirty_tiles[tile_y] |= 1 << tile_x;
163 (void)p;
164} 162}
165 163
166IWRAM_CODE 164IWRAM_CODE
167void 165void
168puticn(Ppu *p, Uint32 *layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Uint8 flipx, Uint8 flipy) { 166puticn(u32 *layer, u16 x, u16 y, u8 *sprite, u8 color, u8 flipx, u8 flipy) {
169 Uint8 sprline; 167 u8 sprline;
170 Uint16 v; 168 u16 v;
171 Uint32 dirtyflag = (1 << (x >> 3)) | (1 << ((x + 7) >> 3)); 169 u32 dirtyflag = (1 << (x >> 3)) | (1 << ((x + 7) >> 3));
172 170
173 Uint32 layerpos = ((y & 7) + (((x >> 3) + (y >> 3) * 32) * 8)); 171 u32 layerpos = ((y & 7) + (((x >> 3) + (y >> 3) * 32) * 8));
174 Uint32 *layerptr = &layer[layerpos]; 172 u32 *layerptr = &layer[layerpos];
175 Uint32 shift = (x & 7) << 2; 173 u32 shift = (x & 7) << 2;
176 Uint32 *lut_expand = flipx ? unpack_icon_lut : unpack_icon_lut_flipx; 174 u32 *lut_expand = flipx ? unpack_icon_lut : unpack_icon_lut_flipx;
177 175
178 if (flipy) flipy = 7; 176 if (flipy) flipy = 7;
179 177
@@ -211,21 +209,20 @@ puticn(Ppu *p, Uint32 *layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Ui
211 209
212 dirty_tiles[y >> 3] |= dirtyflag; 210 dirty_tiles[y >> 3] |= dirtyflag;
213 dirty_tiles[(y + 7) >> 3] |= dirtyflag; 211 dirty_tiles[(y + 7) >> 3] |= dirtyflag;
214 (void)p;
215} 212}
216 213
217IWRAM_CODE 214IWRAM_CODE
218void 215void
219putchr(Ppu *p, Uint32 *layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, 216putchr(u32 *layer, u16 x, u16 y, u8 *sprite, u8 color,
220 Uint8 flipx, Uint8 flipy) { 217 u8 flipx, u8 flipy) {
221 Uint8 sprline1, sprline2; 218 u8 sprline1, sprline2;
222 Uint16 v; 219 u16 v;
223 Uint32 dirtyflag = (1 << (x >> 3)) | (1 << ((x + 7) >> 3)); 220 u32 dirtyflag = (1 << (x >> 3)) | (1 << ((x + 7) >> 3));
224 221
225 Uint32 layerpos = ((y & 7) + (((x >> 3) + (y >> 3) * 32) * 8)); 222 u32 layerpos = ((y & 7) + (((x >> 3) + (y >> 3) * 32) * 8));
226 Uint32 *layerptr = &layer[layerpos]; 223 u32 *layerptr = &layer[layerpos];
227 Uint32 shift = (x & 7) << 2; 224 u32 shift = (x & 7) << 2;
228 Uint32 *lut_expand = flipx ? unpack_icon_lut : unpack_icon_lut_flipx; 225 u32 *lut_expand = flipx ? unpack_icon_lut : unpack_icon_lut_flipx;
229 226
230 if (flipy) flipy = 7; 227 if (flipy) flipy = 7;
231 228
@@ -254,7 +251,6 @@ putchr(Ppu *p, Uint32 *layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color,
254 251
255 dirty_tiles[y >> 3] |= dirtyflag; 252 dirty_tiles[y >> 3] |= dirtyflag;
256 dirty_tiles[(y + 7) >> 3] |= dirtyflag; 253 dirty_tiles[(y + 7) >> 3] |= dirtyflag;
257 (void)p;
258} 254}
259 255
260IWRAM_CODE 256IWRAM_CODE
@@ -281,7 +277,7 @@ flipbuf(Ppu *p) {
281} 277}
282 278
283int 279int
284initppu(Ppu *p, Uint8 hor, Uint8 ver, Uint8 pad) { 280initppu(Ppu *p, u8 hor, u8 ver, u8 pad) {
285 p->hor = hor; 281 p->hor = hor;
286 p->ver = ver; 282 p->ver = ver;
287 p->pad = pad; 283 p->pad = pad;