chore: cleanup 2d-mapping code for 4bpp horizontal sprites

This commit is contained in:
Rekai Nyangadzayi Musuka 2022-06-22 18:54:06 -03:00
parent f689f63eda
commit 1bf10f6d76
1 changed files with 28 additions and 18 deletions

View File

@ -908,10 +908,11 @@ pub const horizontal = struct {
pub fn load() void {
// In Memory, Tile Map is laid out like: 1 2
const px_width = 8 * 2;
const len = px_width * @sizeOf(u32);
const tile_width = 8 * 4;
const tiles_per_row = 2;
GBA.memcpy32(GBA.SPRITE_VRAM, &Self.tile[0], len);
const sprite_width = tile_width * tiles_per_row;
GBA.memcpy32(GBA.SPRITE_VRAM, &Self.tile[0], sprite_width);
loadPalette();
}
@ -941,10 +942,11 @@ pub const horizontal = struct {
pub fn load() void {
// In Memory, Tile Map is laid out like: 1 2 3 4
const px_width = 8 * 4;
const len = px_width * @sizeOf(u32);
const tile_width = 8 * 4;
const tiles_per_row = 4;
GBA.memcpy32(GBA.SPRITE_VRAM, &Self.tile[0], len);
const sprite_width = tile_width * tiles_per_row;
GBA.memcpy32(GBA.SPRITE_VRAM, &Self.tile[0], sprite_width);
loadPalette();
}
@ -979,12 +981,16 @@ pub const horizontal = struct {
// In Memory, Tile Map is laid out like: 1 2 3 4
// 5 6 7 8
const px_width = 8 * 4;
const offset = 0x40 / 4;
const len = px_width * @sizeOf(u32);
const tile_width = 8 * 4;
const tiles_per_row = 4;
GBA.memcpy32(GBA.SPRITE_VRAM, &Self.tile[0], len);
GBA.memcpy32(GBA.SPRITE_VRAM + (px_width * offset), &Self.tile[px_width], len);
const sprite_width = tile_width * tiles_per_row;
const offset = 0x10 / tiles_per_row;
const tile_idx = sprite_width / @sizeOf(u32);
GBA.memcpy32(GBA.SPRITE_VRAM, &Self.tile[0], sprite_width);
GBA.memcpy32(GBA.SPRITE_VRAM + sprite_width * (offset * 1), &Self.tile[tile_idx], sprite_width);
loadPalette();
}
@ -1048,14 +1054,18 @@ pub const horizontal = struct {
// 17 18 19 20 21 22 23 24
// 25 26 27 28 29 30 31 32
const px_width = 8 * 8;
const offset = 0x40 / 8;
const len = px_width * @sizeOf(u32);
const tile_width = 8 * 4;
const tiles_per_row = 8;
GBA.memcpy32(GBA.SPRITE_VRAM, &Self.tile[0], len);
GBA.memcpy32(GBA.SPRITE_VRAM + (px_width * offset), &Self.tile[px_width], len);
GBA.memcpy32(GBA.SPRITE_VRAM + (px_width * (offset * 2)), &Self.tile[px_width * 2], len);
GBA.memcpy32(GBA.SPRITE_VRAM + (px_width * (offset * 3)), &Self.tile[px_width * 3], len);
const sprite_width = tile_width * tiles_per_row;
const offset = 0x10 / tiles_per_row;
const tile_idx = sprite_width / @sizeOf(u32);
GBA.memcpy32(GBA.SPRITE_VRAM, &Self.tile[0], sprite_width);
GBA.memcpy32(GBA.SPRITE_VRAM + sprite_width * (offset * 1), &Self.tile[tile_idx * 1], sprite_width);
GBA.memcpy32(GBA.SPRITE_VRAM + sprite_width * (offset * 2), &Self.tile[tile_idx * 2], sprite_width);
GBA.memcpy32(GBA.SPRITE_VRAM + sprite_width * (offset * 3), &Self.tile[tile_idx * 3], sprite_width);
loadPalette();
}