chore: cleanup 2d mapping code for 4bpp square sprites
This commit is contained in:
parent
a05efaae0f
commit
77e2ef6103
|
@ -41,11 +41,11 @@ pub const square = struct {
|
||||||
pub fn load() void {
|
pub fn load() void {
|
||||||
// 8x8 Sprites don't differ in any meaningful way between 1D and 2D mapping
|
// 8x8 Sprites don't differ in any meaningful way between 1D and 2D mapping
|
||||||
|
|
||||||
const sprite_width = 8; // 8x8
|
const tile_width = 8 * 4;
|
||||||
const len = sprite_width * @sizeOf(u32);
|
const tiles_per_row = 1;
|
||||||
|
|
||||||
// Copy Tile Mapping
|
const sprite_width = tile_width * tiles_per_row;
|
||||||
GBA.memcpy32(GBA.SPRITE_VRAM, &Self.tile[0], len);
|
GBA.memcpy32(GBA.SPRITE_VRAM, &Self.tile[0], sprite_width);
|
||||||
|
|
||||||
loadPalette();
|
loadPalette();
|
||||||
}
|
}
|
||||||
|
@ -76,10 +76,16 @@ pub const square = struct {
|
||||||
// In Memory, Tile Map is laid out like: 1 2
|
// In Memory, Tile Map is laid out like: 1 2
|
||||||
// 3 4
|
// 3 4
|
||||||
|
|
||||||
const half = Self.tile.len / 2;
|
const tile_width = 8 * 4;
|
||||||
|
const tiles_per_row = 2;
|
||||||
|
|
||||||
GBA.memcpy32(GBA.SPRITE_VRAM, &Self.tile[0], half * @sizeOf(u32)); // Top
|
const sprite_width = tile_width * tiles_per_row;
|
||||||
GBA.memcpy32(GBA.SPRITE_VRAM + (half * 0x20), &Self.tile[half], half * @sizeOf(u32)); // Bottom
|
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();
|
loadPalette();
|
||||||
}
|
}
|
||||||
|
@ -125,14 +131,18 @@ pub const square = struct {
|
||||||
// 9 10 11 12
|
// 9 10 11 12
|
||||||
// 13 14 15 16
|
// 13 14 15 16
|
||||||
|
|
||||||
const px_width = 8 * 4;
|
const tile_width = 8 * 4;
|
||||||
const offset = 0x40 / 4;
|
const tiles_per_row = 4;
|
||||||
const len = px_width * @sizeOf(u32);
|
|
||||||
|
|
||||||
GBA.memcpy32(GBA.SPRITE_VRAM, &Self.tile[0], len);
|
const sprite_width = tile_width * tiles_per_row;
|
||||||
GBA.memcpy32(GBA.SPRITE_VRAM + (px_width * offset), &Self.tile[px_width], len);
|
const offset = 0x10 / tiles_per_row;
|
||||||
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 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);
|
||||||
|
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();
|
loadPalette();
|
||||||
}
|
}
|
||||||
|
@ -236,18 +246,22 @@ pub const square = struct {
|
||||||
// 49 50 51 52 53 54 55 56
|
// 49 50 51 52 53 54 55 56
|
||||||
// 57 58 59 60 61 62 63 64
|
// 57 58 59 60 61 62 63 64
|
||||||
|
|
||||||
const px_width = 8 * 8;
|
const tile_width = 8 * 4;
|
||||||
const offset = 0x40 / 8;
|
const tiles_per_row = 8;
|
||||||
const len = px_width * @sizeOf(u32);
|
|
||||||
|
|
||||||
GBA.memcpy32(GBA.SPRITE_VRAM, &Self.tile[0], len);
|
const sprite_width = tile_width * tiles_per_row;
|
||||||
GBA.memcpy32(GBA.SPRITE_VRAM + (px_width * offset), &Self.tile[px_width], len);
|
const offset = 0x10 / tiles_per_row;
|
||||||
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 tile_idx = sprite_width / @sizeOf(u32);
|
||||||
GBA.memcpy32(GBA.SPRITE_VRAM + (px_width * (offset * 4)), &Self.tile[px_width * 4], len);
|
|
||||||
GBA.memcpy32(GBA.SPRITE_VRAM + (px_width * (offset * 5)), &Self.tile[px_width * 5], len);
|
GBA.memcpy32(GBA.SPRITE_VRAM, &Self.tile[0], sprite_width);
|
||||||
GBA.memcpy32(GBA.SPRITE_VRAM + (px_width * (offset * 6)), &Self.tile[px_width * 6], len);
|
GBA.memcpy32(GBA.SPRITE_VRAM + sprite_width * (offset * 1), &Self.tile[tile_idx * 1], sprite_width);
|
||||||
GBA.memcpy32(GBA.SPRITE_VRAM + (px_width * (offset * 7)), &Self.tile[px_width * 7], len);
|
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);
|
||||||
|
GBA.memcpy32(GBA.SPRITE_VRAM + sprite_width * (offset * 4), &Self.tile[tile_idx * 4], sprite_width);
|
||||||
|
GBA.memcpy32(GBA.SPRITE_VRAM + sprite_width * (offset * 5), &Self.tile[tile_idx * 5], sprite_width);
|
||||||
|
GBA.memcpy32(GBA.SPRITE_VRAM + sprite_width * (offset * 6), &Self.tile[tile_idx * 6], sprite_width);
|
||||||
|
GBA.memcpy32(GBA.SPRITE_VRAM + sprite_width * (offset * 7), &Self.tile[tile_idx * 7], sprite_width);
|
||||||
|
|
||||||
loadPalette();
|
loadPalette();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue