From f7e0a0ed0f9bb1396efaa41bf8fd7d8358d070c6 Mon Sep 17 00:00:00 2001 From: Rekai Musuka Date: Fri, 13 May 2022 10:13:44 -0300 Subject: [PATCH] feat: horizontal sprites + depersonalization --- src/2d_sprites.zig | 419 +++++++++++++++++++++++++++++++-------------- 1 file changed, 295 insertions(+), 124 deletions(-) diff --git a/src/2d_sprites.zig b/src/2d_sprites.zig index a9cbf3e..04bba7f 100644 --- a/src/2d_sprites.zig +++ b/src/2d_sprites.zig @@ -6,21 +6,25 @@ const LCD = @import("gba").LCD; const OAM = @import("gba").OAM; const Input = @import("gba").Input; -const SquareSpriteTuple = std.meta.Tuple(&[_]type{ Rainbow, Bebe16, Bebe32, Bebe64 }); +const SquareSpriteTuple = std.meta.Tuple(&[_]type{ Sprite8x8, Sprite16x16, Sprite32x32, Sprite64x64 }); +const HorizSpriteTuple = std.meta.Tuple(&[_]type{ Sprite16x8, Sprite32x8, Sprite32x16, Sprite64x32 }); -// TODO: ZigGBA should support spaces in the ROM Title IIRC +// TODO: ZigGBA should support spaces, slashes, underscores, etc. in ROM Title export var gameHeader linksection(".gbaheader") = GBA.Header.setup("2DSPRITE", "PAOD", "00", 0); // To-do List: // TODO: 8BPP variants? // TODO: Tall Sprites -// TODO: Wide Sprites -// TODO: 8x8 Bebe-chan const square_sprites = initSquareSpriteTuple(); +const horiz_sprites = initHorizSpriteTuple(); fn initSquareSpriteTuple() SquareSpriteTuple { - return .{ Rainbow{}, Bebe16{}, Bebe32{}, Bebe64{} }; + return .{ Sprite8x8{}, Sprite16x16{}, Sprite32x32{}, Sprite64x64{} }; +} + +fn initHorizSpriteTuple() HorizSpriteTuple { + return .{ Sprite16x8{}, Sprite32x8{}, Sprite32x16{}, Sprite64x32{} }; } pub fn main() noreturn { @@ -32,13 +36,15 @@ pub fn main() noreturn { OAM.init(); - square_sprites[0].load(); // Copy Mapping to VRAM and Palette to PALRAM + const sprites = horiz_sprites; + + sprites[0].load(); // Copy Mapping to VRAM and Palette to PALRAM var sprite: *OAM.Attribute = OAM.allocate(); - sprite.paletteMode = square_sprites[0].paletteMode(); + sprite.paletteMode = sprites[0].paletteMode(); sprite.palette = 0; sprite.tileIndex = 0; - sprite.setSize(square_sprites[0].size()); + sprite.setSize(sprites[0].size()); var x: i32 = 96; var y: i32 = 32; @@ -57,20 +63,20 @@ pub fn main() noreturn { // so we need this ugly switch statement switch (i) { 0 => { - square_sprites[0].load(); - sprite.setSize(square_sprites[0].size()); + sprites[0].load(); + sprite.setSize(sprites[0].size()); }, 1 => { - square_sprites[1].load(); - sprite.setSize(square_sprites[1].size()); + sprites[1].load(); + sprite.setSize(sprites[1].size()); }, 2 => { - square_sprites[2].load(); - sprite.setSize(square_sprites[2].size()); + sprites[2].load(); + sprite.setSize(sprites[2].size()); }, 3 => { - square_sprites[3].load(); - sprite.setSize(square_sprites[3].size()); + sprites[3].load(); + sprite.setSize(sprites[3].size()); }, else => unreachable, } @@ -85,21 +91,48 @@ pub fn main() noreturn { } } -/// 16x16 4bpp Sprite -/// Denpa vocalist Nanahira's pet rabbit: Bebe-chan -// Ad: If you're weeb enough, check out Denpasongs -const Bebe16 = struct { +const Sprite8x8 = struct { const Self = @This(); const pal = [8]u32{ - 0x00000000, 0x11B32BAF, 0x7FFF3680, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x3DEF0000, 0x00005EF7, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + }; + + const tiles = [8]u32{ + 0x21111112, 0x12111121, 0x11211211, 0x11112111, 0x11121111, 0x11211211, 0x12111121, 0x21111112, + }; + + fn paletteMode(_: Self) GBA.PaletteMode { + return .Color16; + } + + fn size(_: Self) OAM.ObjectSize { + return .Size8x8; + } + + fn load(_: Self) void { + // 8x8 Sprites don't differ in any meaningful way between 1D and 2D mapping + + // Copy Tile Mapping + GBA.memcpy32(GBA.SPRITE_VRAM, &Self.tiles, Self.tiles.len * @sizeOf(u32)); + + // Copy Palette + GBA.memcpy32(GBA.OBJ_PALETTE_RAM, &Self.pal, Self.pal.len * @sizeOf(u32)); + } +}; + +const Sprite16x16 = struct { + const Self = @This(); + + const pal = [8]u32{ + 0x3DEF0000, 0x00005EF7, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, }; const tiles = [32]u32{ - 0x00000000, 0x00000000, 0x02220000, 0x02222000, 0x22223100, 0x24223310, 0x42233310, 0x32333310, - 0x00000000, 0x00000000, 0x00022200, 0x00232220, 0x01333240, 0x01333324, 0x01333334, 0x00133333, - 0x33333100, 0x13313100, 0x33333510, 0x55555100, 0x55511000, 0x11100000, 0x00000000, 0x00000000, - 0x01553333, 0x05555133, 0x05555513, 0x00555155, 0x00155555, 0x00011111, 0x00000000, 0x00000000, + 0x11111112, 0x11111121, 0x11111211, 0x11112111, 0x11121111, 0x11211111, 0x12111111, 0x21111111, + 0x21111111, 0x12111111, 0x11211111, 0x11121111, 0x11112111, 0x11111211, 0x11111121, 0x11111111, + 0x11111111, 0x12111111, 0x11211111, 0x11121111, 0x11112111, 0x11111211, 0x11111121, 0x11111112, + 0x11111112, 0x11111121, 0x11111211, 0x11112111, 0x11121111, 0x11211111, 0x12111111, 0x21111111, }; fn paletteMode(_: Self) GBA.PaletteMode { @@ -124,33 +157,31 @@ const Bebe16 = struct { } }; -/// 32x32 Bebe-chan -/// Same art as Bebe16, but scaled up -const Bebe32 = struct { +const Sprite32x32 = struct { const Self = @This(); const pal = [8]u32{ - 0x00000000, 0x11B32BAF, 0x7FFF3680, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x3DEF0000, 0x00005EF7, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, }; const tiles = [128]u32{ - 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x22000000, 0x22000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00222222, 0x00222222, 0x00222222, 0x00222222, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x22220000, 0x22220000, 0x22222200, 0x22222200, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000022, 0x00000022, 0x00002233, 0x00002233, - 0x33110000, 0x33110000, 0x33331100, 0x33331100, 0x33331100, 0x33331100, 0x33331100, 0x33331100, - 0x22222222, 0x22222222, 0x22442222, 0x22442222, 0x44222233, 0x44222233, 0x33223333, 0x33223333, - 0x33224400, 0x33224400, 0x33332244, 0x33332244, 0x33333344, 0x33333344, 0x33333333, 0x33333333, - 0x00113333, 0x00113333, 0x00113333, 0x00113333, 0x00113333, 0x00113333, 0x00001133, 0x00001133, + 0x11111112, 0x11111121, 0x11111211, 0x11112111, 0x11121111, 0x11211111, 0x12111111, 0x21111111, + 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, + 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, + 0x21111111, 0x12111111, 0x11211111, 0x11121111, 0x11112111, 0x11111211, 0x11111121, 0x11111112, + 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, + 0x11111112, 0x11111121, 0x11111211, 0x11112111, 0x11121111, 0x11211111, 0x12111111, 0x21111111, + 0x21111111, 0x12111111, 0x11211111, 0x11121111, 0x11112111, 0x11111211, 0x11111121, 0x11111111, + 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, - 0x33110000, 0x33110000, 0x33110000, 0x33110000, 0x33551100, 0x33551100, 0x55110000, 0x55110000, - 0x33333333, 0x33333333, 0x11333311, 0x11333311, 0x33333333, 0x33333333, 0x55555555, 0x55555555, - 0x33333333, 0x33333333, 0x55113333, 0x55113333, 0x55551133, 0x55551133, 0x55115555, 0x55115555, - 0x00115555, 0x00115555, 0x00555555, 0x00555555, 0x00555555, 0x00555555, 0x00005555, 0x00005555, - 0x11000000, 0x11000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x55555511, 0x55555511, 0x11111100, 0x11111100, 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x55555555, 0x55555555, 0x11111111, 0x11111111, 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00001155, 0x00001155, 0x00000011, 0x00000011, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, + 0x11111111, 0x12111111, 0x11211111, 0x11121111, 0x11112111, 0x11111211, 0x11111121, 0x11111112, + 0x11111112, 0x11111121, 0x11111211, 0x11112111, 0x11121111, 0x11211111, 0x12111111, 0x21111111, + 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, + 0x21111111, 0x12111111, 0x11211111, 0x11121111, 0x11112111, 0x11111211, 0x11111121, 0x11111112, + 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, + 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, + 0x11111112, 0x11111121, 0x11111211, 0x11112111, 0x11121111, 0x11211111, 0x12111111, 0x21111111, }; fn paletteMode(_: Self) GBA.PaletteMode { @@ -179,87 +210,85 @@ const Bebe32 = struct { } }; -/// 64x64 Bebe-chan -/// Same art as Bebe16, just scaled up -const Bebe64 = struct { +const Sprite64x64 = struct { const Self = @This(); const pal = [8]u32{ - 0x00000000, 0x11B32BAF, 0x7FFF3680, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x3DEF0000, 0x00005EF7, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, }; const tiles = [512]u32{ - 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x11111112, 0x11111121, 0x11111211, 0x11112111, 0x11121111, 0x11211111, 0x12111111, 0x21111111, + 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, + 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, + 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, + 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, + 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, + 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, + 0x21111111, 0x12111111, 0x11211111, 0x11121111, 0x11112111, 0x11111211, 0x11111121, 0x11111112, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x22220000, 0x22220000, 0x22220000, 0x22220000, - 0x22222222, 0x22222222, 0x22222222, 0x22222222, 0x22222222, 0x22222222, 0x22222222, 0x22222222, - 0x00002222, 0x00002222, 0x00002222, 0x00002222, 0x00002222, 0x00002222, 0x00002222, 0x00002222, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x22220000, 0x22220000, 0x22220000, 0x22220000, - 0x22222222, 0x22222222, 0x22222222, 0x22222222, 0x22222222, 0x22222222, 0x22222222, 0x22222222, - 0x00002222, 0x00002222, 0x00002222, 0x00002222, 0x22223333, 0x22223333, 0x22223333, 0x22223333, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, + 0x11111112, 0x11111121, 0x11111211, 0x11112111, 0x11121111, 0x11211111, 0x12111111, 0x21111111, + 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, + 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, + 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, + 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, + 0x21111111, 0x12111111, 0x11211111, 0x11121111, 0x11112111, 0x11111211, 0x11111121, 0x11111112, + 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x11110000, 0x11110000, 0x11110000, 0x11110000, - 0x33331111, 0x33331111, 0x33331111, 0x33331111, 0x33333333, 0x33333333, 0x33333333, 0x33333333, - 0x22222222, 0x22222222, 0x22222222, 0x22222222, 0x22222222, 0x22222222, 0x22222222, 0x22222222, - 0x22222222, 0x22222222, 0x22222222, 0x22222222, 0x22224444, 0x22224444, 0x22224444, 0x22224444, - 0x44440000, 0x44440000, 0x44440000, 0x44440000, 0x22224444, 0x22224444, 0x22224444, 0x22224444, - 0x33332222, 0x33332222, 0x33332222, 0x33332222, 0x33333333, 0x33333333, 0x33333333, 0x33333333, - 0x33333333, 0x33333333, 0x33333333, 0x33333333, 0x33333333, 0x33333333, 0x33333333, 0x33333333, - 0x00001111, 0x00001111, 0x00001111, 0x00001111, 0x00001111, 0x00001111, 0x00001111, 0x00001111, + 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, + 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, + 0x11111112, 0x11111121, 0x11111211, 0x11112111, 0x11121111, 0x11211111, 0x12111111, 0x21111111, + 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, + 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, + 0x21111111, 0x12111111, 0x11211111, 0x11121111, 0x11112111, 0x11111211, 0x11111121, 0x11111112, + 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, + 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, - 0x11110000, 0x11110000, 0x11110000, 0x11110000, 0x11110000, 0x11110000, 0x11110000, 0x11110000, - 0x33333333, 0x33333333, 0x33333333, 0x33333333, 0x33333333, 0x33333333, 0x33333333, 0x33333333, - 0x22223333, 0x22223333, 0x22223333, 0x22223333, 0x33333333, 0x33333333, 0x33333333, 0x33333333, - 0x44442222, 0x44442222, 0x44442222, 0x44442222, 0x33332222, 0x33332222, 0x33332222, 0x33332222, - 0x33334444, 0x33334444, 0x33334444, 0x33334444, 0x33333333, 0x33333333, 0x33333333, 0x33333333, - 0x33333333, 0x33333333, 0x33333333, 0x33333333, 0x33333333, 0x33333333, 0x33333333, 0x33333333, - 0x33333333, 0x33333333, 0x33333333, 0x33333333, 0x11113333, 0x11113333, 0x11113333, 0x11113333, - 0x00001111, 0x00001111, 0x00001111, 0x00001111, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, + 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, + 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, + 0x11111112, 0x11111121, 0x11111211, 0x11112111, 0x11121111, 0x11211111, 0x12111111, 0x21111111, + 0x21111111, 0x12111111, 0x11211111, 0x11121111, 0x11112111, 0x11111211, 0x11111121, 0x11111111, + 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, + 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, + 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x33331111, 0x33331111, 0x33331111, 0x33331111, 0x33331111, 0x33331111, 0x33331111, 0x33331111, - 0x33333333, 0x33333333, 0x33333333, 0x33333333, 0x33331111, 0x33331111, 0x33331111, 0x33331111, - 0x33333333, 0x33333333, 0x33333333, 0x33333333, 0x11113333, 0x11113333, 0x11113333, 0x11113333, - 0x33333333, 0x33333333, 0x33333333, 0x33333333, 0x33333333, 0x33333333, 0x33333333, 0x33333333, - 0x33333333, 0x33333333, 0x33333333, 0x33333333, 0x55551111, 0x55551111, 0x55551111, 0x55551111, - 0x55555555, 0x55555555, 0x55555555, 0x55555555, 0x55555555, 0x55555555, 0x55555555, 0x55555555, - 0x00001111, 0x00001111, 0x00001111, 0x00001111, 0x00005555, 0x00005555, 0x00005555, 0x00005555, + 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, + 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, + 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, + 0x11111111, 0x12111111, 0x11211111, 0x11121111, 0x11112111, 0x11111211, 0x11111121, 0x11111112, + 0x11111112, 0x11111121, 0x11111211, 0x11112111, 0x11121111, 0x11211111, 0x12111111, 0x21111111, + 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, + 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, + 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, - 0x11110000, 0x11110000, 0x11110000, 0x11110000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x33335555, 0x33335555, 0x33335555, 0x33335555, 0x55551111, 0x55551111, 0x55551111, 0x55551111, - 0x33333333, 0x33333333, 0x33333333, 0x33333333, 0x55555555, 0x55555555, 0x55555555, 0x55555555, - 0x33333333, 0x33333333, 0x33333333, 0x33333333, 0x55555555, 0x55555555, 0x55555555, 0x55555555, - 0x11113333, 0x11113333, 0x11113333, 0x11113333, 0x55555555, 0x55555555, 0x55555555, 0x55555555, - 0x55555555, 0x55555555, 0x55555555, 0x55555555, 0x55551111, 0x55551111, 0x55551111, 0x55551111, - 0x55555555, 0x55555555, 0x55555555, 0x55555555, 0x55555555, 0x55555555, 0x55555555, 0x55555555, - 0x00005555, 0x00005555, 0x00005555, 0x00005555, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, + 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, + 0x21111111, 0x12111111, 0x11211111, 0x11121111, 0x11112111, 0x11111211, 0x11111121, 0x11111112, + 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, + 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, + 0x11111112, 0x11111121, 0x11111211, 0x11112111, 0x11121111, 0x11211111, 0x12111111, 0x21111111, + 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, + 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x11110000, 0x11110000, 0x11110000, 0x11110000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x55551111, 0x55551111, 0x55551111, 0x55551111, 0x11110000, 0x11110000, 0x11110000, 0x11110000, - 0x55555555, 0x55555555, 0x55555555, 0x55555555, 0x11111111, 0x11111111, 0x11111111, 0x11111111, - 0x55555555, 0x55555555, 0x55555555, 0x55555555, 0x11111111, 0x11111111, 0x11111111, 0x11111111, - 0x55555555, 0x55555555, 0x55555555, 0x55555555, 0x11111111, 0x11111111, 0x11111111, 0x11111111, - 0x11115555, 0x11115555, 0x11115555, 0x11115555, 0x00001111, 0x00001111, 0x00001111, 0x00001111, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, + 0x21111111, 0x12111111, 0x11211111, 0x11121111, 0x11112111, 0x11111211, 0x11111121, 0x11111112, + 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, + 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, + 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, + 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, + 0x11111112, 0x11111121, 0x11111211, 0x11112111, 0x11121111, 0x11211111, 0x12111111, 0x21111111, + 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x21111111, 0x12111111, 0x11211111, 0x11121111, 0x11112111, 0x11111211, 0x11111121, 0x11111112, + 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, + 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, + 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, + 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, + 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, + 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, + 0x11111112, 0x11111121, 0x11111211, 0x11112111, 0x11121111, 0x11211111, 0x12111111, 0x21111111, }; fn paletteMode(_: Self) GBA.PaletteMode { @@ -275,6 +304,10 @@ const Bebe64 = struct { // 9 10 11 12 13 14 15 16 // 17 18 19 20 21 22 23 24 // 25 26 27 28 29 30 31 32 + // 33 34 35 36 37 38 39 40 + // 41 42 43 44 45 46 47 48 + // 49 50 51 52 53 54 55 56 + // 57 58 59 60 61 62 63 64 const eighth = Self.tiles.len / 8; @@ -292,16 +325,16 @@ const Bebe64 = struct { } }; -/// 8x8 4bpp Sprite depicting a Rainbow-like gradient 'cause I can't draw -const Rainbow = struct { +const Sprite16x8 = struct { const Self = @This(); const pal = [8]u32{ - 0x001F0000, 0x03FF01FF, 0x03E003EF, 0x7FE03FE0, 0x00007DE0, 0x00000000, 0x00000000, 0x00000000, + 0x3DEF0000, 0x00006318, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, }; - const tiles = [8]u32{ - 0x11111111, 0x22222222, 0x33333333, 0x44444444, 0x55555555, 0x66666666, 0x77777777, 0x88888888, + const tiles = [16]u32{ + 0x11111122, 0x11112211, 0x11221111, 0x22111111, 0x11111111, 0x11221111, 0x11112211, 0x11111122, + 0x22111111, 0x11221111, 0x11112211, 0x11111111, 0x11111122, 0x11112211, 0x11221111, 0x22111111, }; fn paletteMode(_: Self) GBA.PaletteMode { @@ -309,16 +342,154 @@ const Rainbow = struct { } fn size(_: Self) OAM.ObjectSize { - return .Size8x8; + return .Size16x8; } fn load(_: Self) void { - // 8x8 Sprites don't differ in any meaningful way between 1D and 2D mapping + // In Memory, Tile Map is laid out like: 1 2 + GBA.memcpy32(GBA.SPRITE_VRAM, &Self.tiles[0], Self.tiles.len * @sizeOf(u32)); - // Copy Tile Mapping - GBA.memcpy32(GBA.SPRITE_VRAM, &Self.tiles, Self.tiles.len * @sizeOf(u32)); - - // Copy Palette + // Palette + GBA.memcpy32(GBA.OBJ_PALETTE_RAM, &Self.pal, Self.pal.len * @sizeOf(u32)); + } +}; + +const Sprite32x8 = struct { + const Self = @This(); + + const pal = [8]u32{ + 0x3DEF0000, 0x00006318, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + }; + + const tiles = [32]u32{ + 0x11112222, 0x22221111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x22221111, 0x11112222, + 0x11111111, 0x11111111, 0x11112222, 0x22221111, 0x11111111, 0x11112222, 0x11111111, 0x11111111, + 0x11111111, 0x11111111, 0x22221111, 0x11111111, 0x11112222, 0x22221111, 0x11111111, 0x11111111, + 0x22221111, 0x11112222, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11112222, 0x22221111, + }; + + fn paletteMode(_: Self) GBA.PaletteMode { + return .Color16; + } + + fn size(_: Self) OAM.ObjectSize { + return .Size32x8; + } + + fn load(_: Self) void { + // In Memory, Tile Map is laid out like: 1 2 3 4 + GBA.memcpy32(GBA.SPRITE_VRAM, &Self.tiles[0], Self.tiles.len * @sizeOf(u32)); + + // Palette + GBA.memcpy32(GBA.OBJ_PALETTE_RAM, &Self.pal, Self.pal.len * @sizeOf(u32)); + } +}; + +const Sprite32x16 = struct { + const Self = @This(); + + const pal = [8]u32{ + 0x3DEF0000, 0x00006318, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + }; + + const tiles = [64]u32{ + 0x11111122, 0x11112211, 0x11221111, 0x22111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, + 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111122, 0x11112211, 0x11221111, 0x22111111, + 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x22111111, 0x11221111, 0x11112211, 0x11111111, + 0x22111111, 0x11221111, 0x11112211, 0x11111122, 0x11111111, 0x11111111, 0x11111111, 0x11111111, + 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x22111111, 0x11221111, 0x11112211, 0x11111122, + 0x11111111, 0x11221111, 0x11112211, 0x11111122, 0x11111111, 0x11111111, 0x11111111, 0x11111111, + 0x11111122, 0x11112211, 0x11221111, 0x22111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, + 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111122, 0x11112211, 0x11221111, 0x22111111, + }; + + fn paletteMode(_: Self) GBA.PaletteMode { + return .Color16; + } + + fn size(_: Self) OAM.ObjectSize { + return .Size32x32; + } + + fn load(_: Self) void { + // In Memory, Tile Map is laid out like: 1 2 3 4 + // 5 6 7 8 + + const half = Self.tiles.len / 2; + GBA.memcpy32(GBA.SPRITE_VRAM, &Self.tiles[0], half * @sizeOf(u32)); + GBA.memcpy32(GBA.SPRITE_VRAM + (half * 0x10), &Self.tiles[half], half * @sizeOf(u32)); + + // Palette + GBA.memcpy32(GBA.OBJ_PALETTE_RAM, &Self.pal, Self.pal.len * @sizeOf(u32)); + } +}; + +const Sprite64x32 = struct { + const Self = @This(); + + const pal = [8]u32{ + 0x3DEF0000, 0x00006318, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + }; + + const tiles = [256]u32{ + 0x11111122, 0x11112211, 0x11221111, 0x22111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, + 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111122, 0x11112211, 0x11221111, 0x22111111, + 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, + 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, + 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, + 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, + 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x22111111, 0x11221111, 0x11112211, 0x11111122, + 0x22111111, 0x11221111, 0x11112211, 0x11111122, 0x11111111, 0x11111111, 0x11111111, 0x11111111, + + 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, + 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, + 0x11111122, 0x11112211, 0x11221111, 0x22111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, + 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111122, 0x11112211, 0x11221111, 0x22111111, + 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x22111111, 0x11221111, 0x11112211, 0x11111111, + 0x22111111, 0x11221111, 0x11112211, 0x11111122, 0x11111111, 0x11111111, 0x11111111, 0x11111111, + 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, + 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, + + 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, + 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, + 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x22111111, 0x11221111, 0x11112211, 0x11111122, + 0x11111111, 0x11221111, 0x11112211, 0x11111122, 0x11111111, 0x11111111, 0x11111111, 0x11111111, + 0x11111122, 0x11112211, 0x11221111, 0x22111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, + 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111122, 0x11112211, 0x11221111, 0x22111111, + 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, + 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, + + 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x22111111, 0x11221111, 0x11112211, 0x11111122, + 0x22111111, 0x11221111, 0x11112211, 0x11111122, 0x11111111, 0x11111111, 0x11111111, 0x11111111, + 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, + 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, + 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, + 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, + 0x11111122, 0x11112211, 0x11221111, 0x22111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, + 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111122, 0x11112211, 0x11221111, 0x22111111, + }; + + fn paletteMode(_: Self) GBA.PaletteMode { + return .Color16; + } + + fn size(_: Self) OAM.ObjectSize { + return .Size64x32; + } + + fn load(_: Self) void { + // In Memory, Tile Map is laid out like: 1 2 3 4 5 6 7 8 + // 9 10 11 12 13 14 15 16 + // 17 18 19 20 21 22 23 24 + // 25 26 27 28 29 30 31 32 + const quarter = Self.tiles.len / 4; + + GBA.memcpy32(GBA.SPRITE_VRAM, &Self.tiles[0], quarter * @sizeOf(u32)); + GBA.memcpy32(GBA.SPRITE_VRAM + (quarter * 0x8), &Self.tiles[quarter], quarter * @sizeOf(u32)); + GBA.memcpy32(GBA.SPRITE_VRAM + (quarter * 0x10), &Self.tiles[quarter * 2], quarter * @sizeOf(u32)); + GBA.memcpy32(GBA.SPRITE_VRAM + (quarter * 0x18), &Self.tiles[quarter * 3], quarter * @sizeOf(u32)); + + // Palette GBA.memcpy32(GBA.OBJ_PALETTE_RAM, &Self.pal, Self.pal.len * @sizeOf(u32)); } };