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