summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBad Diode <bd@badd10de.dev>2021-06-08 13:34:41 +0200
committerBad Diode <bd@badd10de.dev>2021-06-08 13:34:41 +0200
commit5b160c23330663e38d1c7fa387d64e83a372638d (patch)
tree9be178de53000ee57f5a96a9c4c482ba1ce6de63
parent1040149ad5dc47613b9a90f1e17d242b9cdf1931 (diff)
downloadgba-sequencer-5b160c23330663e38d1c7fa387d64e83a372638d.tar.gz
gba-sequencer-5b160c23330663e38d1c7fa387d64e83a372638d.zip
Fix bug on tile rendering
-rw-r--r--src/renderer.c21
1 files changed, 11 insertions, 10 deletions
diff --git a/src/renderer.c b/src/renderer.c
index 4318610..afc9904 100644
--- a/src/renderer.c
+++ b/src/renderer.c
@@ -294,7 +294,8 @@ draw_tile(size_t x, size_t y, Tile *tile, bool merge) {
294 // higher than 1. 294 // higher than 1.
295 size_t shift_left = start_col * 4; 295 size_t shift_left = start_col * 4;
296 size_t shift_right = (8 - start_col) * 4; 296 size_t shift_right = (8 - start_col) * 4;
297 u32 row_mask = merge ? 0 : 0xFFFFFFFF << shift_left; 297 u32 row_mask_left = merge ? 0 : 0xFFFFFFFF << shift_left;
298 u32 row_mask_right = merge ? 0 : 0xFFFFFFFF >> shift_right;
298 299
299 // Draw the tiles. There are 4 possible cases: 300 // Draw the tiles. There are 4 possible cases:
300 // 1. The tile is exactly at the tile boundary. 301 // 1. The tile is exactly at the tile boundary.
@@ -304,40 +305,40 @@ draw_tile(size_t x, size_t y, Tile *tile, bool merge) {
304 if (start_col == 0 && start_row == 0) { 305 if (start_col == 0 && start_row == 0) {
305 for (size_t i = 0; i < (8 - start_row); i++, backbuffer++) { 306 for (size_t i = 0; i < (8 - start_row); i++, backbuffer++) {
306 BOUNDCHECK_SCREEN(x, y + i); 307 BOUNDCHECK_SCREEN(x, y + i);
307 backbuffer[0] = (backbuffer[0] & ~row_mask) | row[i]; 308 backbuffer[0] = (backbuffer[0] & ~row_mask_left) | row[i];
308 } 309 }
309 dirty_tiles[tile_y] |= 1 << tile_x; 310 dirty_tiles[tile_y] |= 1 << tile_x;
310 } else if (start_row == 0) { 311 } else if (start_row == 0) {
311 for (size_t i = 0; i < 8; i++, backbuffer++) { 312 for (size_t i = 0; i < 8; i++, backbuffer++) {
312 BOUNDCHECK_SCREEN(x, y + i); 313 BOUNDCHECK_SCREEN(x, y + i);
313 backbuffer[0] = (backbuffer[0] & ~row_mask) | (row[i] << shift_left); 314 backbuffer[0] = (backbuffer[0] & ~row_mask_left) | (row[i] << shift_left);
314 backbuffer[8] = (backbuffer[8] & row_mask) | (row[i] >> shift_right); 315 backbuffer[8] = (backbuffer[8] & ~row_mask_right) | (row[i] >> shift_right);
315 } 316 }
316 dirty_tiles[tile_y] |= 1 << tile_x; 317 dirty_tiles[tile_y] |= 1 << tile_x;
317 dirty_tiles[tile_y] |= 1 << (tile_x + 1); 318 dirty_tiles[tile_y] |= 1 << (tile_x + 1);
318 } else if (start_col == 0) { 319 } else if (start_col == 0) {
319 for (size_t i = 0; i < (8 - start_row); i++, backbuffer++) { 320 for (size_t i = 0; i < (8 - start_row); i++, backbuffer++) {
320 BOUNDCHECK_SCREEN(x, y + i); 321 BOUNDCHECK_SCREEN(x, y + i);
321 backbuffer[0] = (backbuffer[0] & ~row_mask) | row[i]; 322 backbuffer[0] = (backbuffer[0] & ~row_mask_left) | row[i];
322 } 323 }
323 backbuffer += 8 * 31; 324 backbuffer += 8 * 31;
324 for (size_t i = (8 - start_row); i < 8; i++, backbuffer++) { 325 for (size_t i = (8 - start_row); i < 8; i++, backbuffer++) {
325 BOUNDCHECK_SCREEN(x, y + i); 326 BOUNDCHECK_SCREEN(x, y + i);
326 backbuffer[0] = (backbuffer[0] & ~row_mask) | row[i]; 327 backbuffer[0] = (backbuffer[0] & ~row_mask_left) | row[i];
327 } 328 }
328 dirty_tiles[tile_y] |= 1 << tile_x; 329 dirty_tiles[tile_y] |= 1 << tile_x;
329 dirty_tiles[tile_y + 1] |= 1 << tile_x; 330 dirty_tiles[tile_y + 1] |= 1 << tile_x;
330 } else { 331 } else {
331 for (size_t i = 0; i < (8 - start_row); i++, backbuffer++) { 332 for (size_t i = 0; i < (8 - start_row); i++, backbuffer++) {
332 BOUNDCHECK_SCREEN(x, y + i); 333 BOUNDCHECK_SCREEN(x, y + i);
333 backbuffer[0] = (backbuffer[0] & ~row_mask) | (row[i] << shift_left); 334 backbuffer[0] = (backbuffer[0] & ~row_mask_left) | (row[i] << shift_left);
334 backbuffer[8] = (backbuffer[8] & row_mask) | (row[i] >> shift_right); 335 backbuffer[8] = (backbuffer[8] & ~row_mask_right) | (row[i] >> shift_right);
335 } 336 }
336 backbuffer += 8 * 31; 337 backbuffer += 8 * 31;
337 for (size_t i = (8 - start_row); i < 8; i++, backbuffer++) { 338 for (size_t i = (8 - start_row); i < 8; i++, backbuffer++) {
338 BOUNDCHECK_SCREEN(x, y + i); 339 BOUNDCHECK_SCREEN(x, y + i);
339 backbuffer[0] = (backbuffer[0] & ~row_mask) | (row[i] << shift_left); 340 backbuffer[0] = (backbuffer[0] & ~row_mask_left) | (row[i] << shift_left);
340 backbuffer[8] = (backbuffer[8] & row_mask) | (row[i] >> shift_right); 341 backbuffer[8] = (backbuffer[8] & ~row_mask_right) | (row[i] >> shift_right);
341 } 342 }
342 dirty_tiles[tile_y] |= 1 << tile_x; 343 dirty_tiles[tile_y] |= 1 << tile_x;
343 dirty_tiles[tile_y] |= 1 << (tile_x + 1); 344 dirty_tiles[tile_y] |= 1 << (tile_x + 1);