726 lines
34 KiB
Zig
726 lines
34 KiB
Zig
const std = @import("std");
|
|
|
|
const GBA = @import("gba").GBA;
|
|
const Mode3 = @import("gba").Mode3;
|
|
const LCD = @import("gba").LCD;
|
|
const OAM = @import("gba").OAM;
|
|
const Input = @import("gba").Input;
|
|
|
|
const SquareSpriteTuple = std.meta.Tuple(&[_]type{ Sprite8x8, Sprite16x16, Sprite32x32, Sprite64x64 });
|
|
const HorizSpriteTuple = std.meta.Tuple(&[_]type{ Sprite16x8, Sprite32x8, Sprite32x16, Sprite64x32 });
|
|
const VertSpriteTuple = std.meta.Tuple(&[_]type{ Sprite8x16, Sprite8x32, Sprite16x32, Sprite32x64 });
|
|
|
|
// 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
|
|
|
|
const square_sprites = initSquareSpriteTuple();
|
|
const horiz_sprites = initHorizSpriteTuple();
|
|
const vert_sprites = initVertSpriteTuple();
|
|
|
|
fn initSquareSpriteTuple() SquareSpriteTuple {
|
|
return .{ Sprite8x8{}, Sprite16x16{}, Sprite32x32{}, Sprite64x64{} };
|
|
}
|
|
|
|
fn initHorizSpriteTuple() HorizSpriteTuple {
|
|
return .{ Sprite16x8{}, Sprite32x8{}, Sprite32x16{}, Sprite64x32{} };
|
|
}
|
|
|
|
fn initVertSpriteTuple() VertSpriteTuple {
|
|
return .{ Sprite8x16{}, Sprite8x32{}, Sprite16x32{}, Sprite32x64{} };
|
|
}
|
|
|
|
pub fn main() noreturn {
|
|
LCD.setupDisplayControl(.{
|
|
.mode = .Mode0, // No Affine BGs
|
|
.objectLayer = .Show, // Enable Sprites
|
|
.objVramCharacterMapping = .TwoDimension, // 2D Sprite Mapping
|
|
});
|
|
|
|
OAM.init();
|
|
|
|
const sprites = square_sprites;
|
|
|
|
sprites[0].load(); // Copy Mapping to VRAM and Palette to PALRAM
|
|
|
|
var sprite: *OAM.Attribute = OAM.allocate();
|
|
sprite.paletteMode = sprites[0].paletteMode();
|
|
sprite.palette = 0;
|
|
sprite.tileIndex = 0;
|
|
sprite.setSize(sprites[0].size());
|
|
|
|
var x: i32 = 96;
|
|
var y: i32 = 32;
|
|
|
|
var i: i32 = 0;
|
|
|
|
while (true) {
|
|
LCD.naiveVSync();
|
|
Input.readInput();
|
|
|
|
const shoulder = Input.getShoulderJustPressed();
|
|
if (shoulder != 0) {
|
|
i = (i + shoulder) & 0b11;
|
|
|
|
// Index must be comptime known unfortunately
|
|
// so we need this ugly switch statement
|
|
switch (i) {
|
|
0 => {
|
|
sprites[0].load();
|
|
sprite.setSize(sprites[0].size());
|
|
},
|
|
1 => {
|
|
sprites[1].load();
|
|
sprite.setSize(sprites[1].size());
|
|
},
|
|
2 => {
|
|
sprites[2].load();
|
|
sprite.setSize(sprites[2].size());
|
|
},
|
|
3 => {
|
|
sprites[3].load();
|
|
sprite.setSize(sprites[3].size());
|
|
},
|
|
else => unreachable,
|
|
}
|
|
}
|
|
|
|
x += Input.getHorizontal() * 2;
|
|
y += Input.getVertical() * 2;
|
|
|
|
sprite.setPosition(x, y);
|
|
|
|
OAM.update(1);
|
|
}
|
|
}
|
|
|
|
const Sprite8x8 = struct {
|
|
const Self = @This();
|
|
|
|
const pal = [8]u32{
|
|
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
|
|
|
|
const sprite_width = 8; // 8x8
|
|
const len = sprite_width * @sizeOf(u32);
|
|
|
|
// Copy Tile Mapping
|
|
GBA.memcpy32(GBA.SPRITE_VRAM, &Self.tiles[0], len);
|
|
|
|
// 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{
|
|
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 {
|
|
return .Color16;
|
|
}
|
|
|
|
fn size(_: Self) OAM.ObjectSize {
|
|
return .Size16x16;
|
|
}
|
|
|
|
fn load(_: Self) void {
|
|
// In Memory, Tile Map is laid out like: 1 2
|
|
// 3 4
|
|
|
|
const half = Self.tiles.len / 2;
|
|
|
|
GBA.memcpy32(GBA.SPRITE_VRAM, &Self.tiles[0], half * @sizeOf(u32)); // Top
|
|
GBA.memcpy32(GBA.SPRITE_VRAM + (half * 0x20), &Self.tiles[half], half * @sizeOf(u32)); // Bottom
|
|
|
|
// Palette
|
|
GBA.memcpy32(GBA.OBJ_PALETTE_RAM, &Self.pal, Self.pal.len * @sizeOf(u32));
|
|
}
|
|
};
|
|
|
|
const Sprite32x32 = struct {
|
|
const Self = @This();
|
|
|
|
const pal = [8]u32{
|
|
0x3DEF0000, 0x00005EF7, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
|
};
|
|
|
|
const tiles = [128]u32{
|
|
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,
|
|
|
|
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 {
|
|
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
|
|
// 9 10 11 12
|
|
// 13 14 15 16
|
|
|
|
const px_width = 8 * 4;
|
|
const offset = 0x40 / 4;
|
|
const len = px_width * @sizeOf(u32);
|
|
|
|
GBA.memcpy32(GBA.SPRITE_VRAM, &Self.tiles[0], len);
|
|
GBA.memcpy32(GBA.SPRITE_VRAM + (px_width * offset), &Self.tiles[px_width], len);
|
|
GBA.memcpy32(GBA.SPRITE_VRAM + (px_width * (offset * 2)), &Self.tiles[px_width * 2], len);
|
|
GBA.memcpy32(GBA.SPRITE_VRAM + (px_width * (offset * 3)), &Self.tiles[px_width * 3], len);
|
|
|
|
// Palette
|
|
GBA.memcpy32(GBA.OBJ_PALETTE_RAM, &Self.pal, Self.pal.len * @sizeOf(u32));
|
|
}
|
|
};
|
|
|
|
const Sprite64x64 = struct {
|
|
const Self = @This();
|
|
|
|
const pal = [8]u32{
|
|
0x3DEF0000, 0x00005EF7, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
|
};
|
|
|
|
const tiles = [512]u32{
|
|
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,
|
|
|
|
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,
|
|
|
|
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,
|
|
|
|
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,
|
|
|
|
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,
|
|
|
|
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,
|
|
|
|
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,
|
|
|
|
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 {
|
|
return .Color16;
|
|
}
|
|
|
|
fn size(_: Self) OAM.ObjectSize {
|
|
return .Size64x64;
|
|
}
|
|
|
|
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
|
|
// 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 px_width = 8 * 8;
|
|
const offset = 0x40 / 8;
|
|
const len = px_width * @sizeOf(u32);
|
|
|
|
GBA.memcpy32(GBA.SPRITE_VRAM, &Self.tiles[0], len);
|
|
GBA.memcpy32(GBA.SPRITE_VRAM + (px_width * offset), &Self.tiles[px_width], len);
|
|
GBA.memcpy32(GBA.SPRITE_VRAM + (px_width * (offset * 2)), &Self.tiles[px_width * 2], len);
|
|
GBA.memcpy32(GBA.SPRITE_VRAM + (px_width * (offset * 3)), &Self.tiles[px_width * 3], len);
|
|
GBA.memcpy32(GBA.SPRITE_VRAM + (px_width * (offset * 4)), &Self.tiles[px_width * 4], len);
|
|
GBA.memcpy32(GBA.SPRITE_VRAM + (px_width * (offset * 5)), &Self.tiles[px_width * 5], len);
|
|
GBA.memcpy32(GBA.SPRITE_VRAM + (px_width * (offset * 6)), &Self.tiles[px_width * 6], len);
|
|
GBA.memcpy32(GBA.SPRITE_VRAM + (px_width * (offset * 7)), &Self.tiles[px_width * 7], len);
|
|
|
|
// Palette
|
|
GBA.memcpy32(GBA.OBJ_PALETTE_RAM, &Self.pal, Self.pal.len * @sizeOf(u32));
|
|
}
|
|
};
|
|
|
|
const Sprite16x8 = struct {
|
|
const Self = @This();
|
|
|
|
const pal = [8]u32{
|
|
0x3DEF0000, 0x00006318, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
|
};
|
|
|
|
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 {
|
|
return .Color16;
|
|
}
|
|
|
|
fn size(_: Self) OAM.ObjectSize {
|
|
return .Size16x8;
|
|
}
|
|
|
|
fn load(_: Self) void {
|
|
// In Memory, Tile Map is laid out like: 1 2
|
|
|
|
const px_width = 8 * 2;
|
|
const len = px_width * @sizeOf(u32);
|
|
|
|
GBA.memcpy32(GBA.SPRITE_VRAM, &Self.tiles[0], len);
|
|
|
|
// 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
|
|
|
|
const px_width = 8 * 4;
|
|
const len = px_width * @sizeOf(u32);
|
|
|
|
GBA.memcpy32(GBA.SPRITE_VRAM, &Self.tiles[0], len);
|
|
|
|
// 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 px_width = 8 * 4;
|
|
const offset = 0x40 / 4;
|
|
const len = px_width * @sizeOf(u32);
|
|
|
|
GBA.memcpy32(GBA.SPRITE_VRAM, &Self.tiles[0], len);
|
|
GBA.memcpy32(GBA.SPRITE_VRAM + (px_width * offset), &Self.tiles[px_width], len);
|
|
|
|
// 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 px_width = 8 * 8;
|
|
const offset = 0x40 / 8;
|
|
const len = px_width * @sizeOf(u32);
|
|
|
|
GBA.memcpy32(GBA.SPRITE_VRAM, &Self.tiles[0], len);
|
|
GBA.memcpy32(GBA.SPRITE_VRAM + (px_width * offset), &Self.tiles[px_width], len);
|
|
GBA.memcpy32(GBA.SPRITE_VRAM + (px_width * (offset * 2)), &Self.tiles[px_width * 2], len);
|
|
GBA.memcpy32(GBA.SPRITE_VRAM + (px_width * (offset * 3)), &Self.tiles[px_width * 3], len);
|
|
|
|
// Palette
|
|
GBA.memcpy32(GBA.OBJ_PALETTE_RAM, &Self.pal, Self.pal.len * @sizeOf(u32));
|
|
}
|
|
};
|
|
|
|
const Sprite8x16 = struct {
|
|
const Self = @This();
|
|
|
|
const pal = [8]u32{
|
|
0x3DEF0000, 0x00006318, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
|
};
|
|
|
|
const tiles = [16]u32{
|
|
0x21111112, 0x21111112, 0x12111121, 0x12111121, 0x11211211, 0x11211211, 0x11112111, 0x11112111,
|
|
0x11121111, 0x11121111, 0x11211211, 0x11211211, 0x12111121, 0x12111121, 0x21111112, 0x21111112,
|
|
};
|
|
|
|
fn paletteMode(_: Self) GBA.PaletteMode {
|
|
return .Color16;
|
|
}
|
|
|
|
fn size(_: Self) OAM.ObjectSize {
|
|
return .Size8x16;
|
|
}
|
|
|
|
fn load(_: Self) void {
|
|
// In Memory, Tile Map is laid out like: 1
|
|
// 2
|
|
|
|
const sprite_len = 8;
|
|
|
|
GBA.memcpy32(GBA.SPRITE_VRAM, &Self.tiles[0], sprite_len * @sizeOf(u32));
|
|
GBA.memcpy32(GBA.SPRITE_VRAM + (sprite_len * 0x40), &Self.tiles[sprite_len], sprite_len * @sizeOf(u32));
|
|
|
|
// Palette
|
|
GBA.memcpy32(GBA.OBJ_PALETTE_RAM, &Self.pal, Self.pal.len * @sizeOf(u32));
|
|
}
|
|
};
|
|
|
|
const Sprite8x32 = struct {
|
|
const Self = @This();
|
|
|
|
const pal = [8]u32{
|
|
0x3DEF0000, 0x00006318, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
|
};
|
|
|
|
const tiles = [32]u32{
|
|
0x21111112, 0x21111112, 0x21111112, 0x21111112, 0x12111121, 0x12111121, 0x12111121, 0x12111121,
|
|
0x11211211, 0x11211211, 0x11211211, 0x11211211, 0x11112111, 0x11112111, 0x11112111, 0x11112111,
|
|
0x11121111, 0x11121111, 0x11121111, 0x11121111, 0x11211211, 0x11211211, 0x11211211, 0x11211211,
|
|
0x12111121, 0x12111121, 0x12111121, 0x12111121, 0x21111112, 0x21111112, 0x21111112, 0x21111112,
|
|
};
|
|
|
|
fn paletteMode(_: Self) GBA.PaletteMode {
|
|
return .Color16;
|
|
}
|
|
|
|
fn size(_: Self) OAM.ObjectSize {
|
|
return .Size8x32;
|
|
}
|
|
|
|
fn load(_: Self) void {
|
|
// In Memory, Tile Map is laid out like: 1
|
|
// 2
|
|
// 3
|
|
// 4
|
|
|
|
const px_width = 8;
|
|
const offset = 0x40;
|
|
const len = px_width * @sizeOf(u32);
|
|
|
|
GBA.memcpy32(GBA.SPRITE_VRAM, &Self.tiles[0], len);
|
|
GBA.memcpy32(GBA.SPRITE_VRAM + (px_width * offset), &Self.tiles[px_width], len);
|
|
GBA.memcpy32(GBA.SPRITE_VRAM + (px_width * (offset * 2)), &Self.tiles[px_width * 2], len);
|
|
GBA.memcpy32(GBA.SPRITE_VRAM + (px_width * (offset * 3)), &Self.tiles[px_width * 3], len);
|
|
|
|
// Palette
|
|
GBA.memcpy32(GBA.OBJ_PALETTE_RAM, &Self.pal, Self.pal.len * @sizeOf(u32));
|
|
}
|
|
};
|
|
|
|
const Sprite16x32 = struct {
|
|
const Self = @This();
|
|
|
|
const pal = [8]u32{
|
|
0x3DEF0000, 0x00006318, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
|
};
|
|
|
|
const tiles = [64]u32{
|
|
0x11111112, 0x11111112, 0x11111121, 0x11111121, 0x11111211, 0x11111211, 0x11112111, 0x11112111,
|
|
0x21111111, 0x21111111, 0x12111111, 0x12111111, 0x11211111, 0x11211111, 0x11121111, 0x11121111,
|
|
0x11121111, 0x11121111, 0x11211111, 0x11211111, 0x12111111, 0x12111111, 0x21111111, 0x21111111,
|
|
0x11112111, 0x11112111, 0x11111211, 0x11111211, 0x11111121, 0x11111121, 0x11111111, 0x11111111,
|
|
0x11111111, 0x11111111, 0x12111111, 0x12111111, 0x11211111, 0x11211111, 0x11121111, 0x11121111,
|
|
0x11111112, 0x11111112, 0x11111121, 0x11111121, 0x11111211, 0x11111211, 0x11112111, 0x11112111,
|
|
0x11112111, 0x11112111, 0x11111211, 0x11111211, 0x11111121, 0x11111121, 0x11111112, 0x11111112,
|
|
0x11121111, 0x11121111, 0x11211111, 0x11211111, 0x12111111, 0x12111111, 0x21111111, 0x21111111,
|
|
};
|
|
|
|
fn paletteMode(_: Self) GBA.PaletteMode {
|
|
return .Color16;
|
|
}
|
|
|
|
fn size(_: Self) OAM.ObjectSize {
|
|
return .Size16x32;
|
|
}
|
|
|
|
fn load(_: Self) void {
|
|
// In Memory, Tile Map is laid out like: 1 2
|
|
// 3 4
|
|
// 5 6
|
|
// 7 8
|
|
|
|
const px_width = 8 * 2;
|
|
const offset = 0x40 / 2;
|
|
const len = px_width * @sizeOf(u32);
|
|
|
|
GBA.memcpy32(GBA.SPRITE_VRAM, &Self.tiles[0], len);
|
|
GBA.memcpy32(GBA.SPRITE_VRAM + (px_width * offset), &Self.tiles[px_width], len);
|
|
GBA.memcpy32(GBA.SPRITE_VRAM + (px_width * (offset * 2)), &Self.tiles[px_width * 2], len);
|
|
GBA.memcpy32(GBA.SPRITE_VRAM + (px_width * (offset * 3)), &Self.tiles[px_width * 3], len);
|
|
|
|
// Palette
|
|
GBA.memcpy32(GBA.OBJ_PALETTE_RAM, &Self.pal, Self.pal.len * @sizeOf(u32));
|
|
}
|
|
};
|
|
|
|
const Sprite32x64 = struct {
|
|
const Self = @This();
|
|
|
|
const pal = [8]u32{
|
|
0x3DEF0000, 0x00006318, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
|
};
|
|
|
|
const tiles = [256]u32{
|
|
0x11111112, 0x11111112, 0x11111121, 0x11111121, 0x11111211, 0x11111211, 0x11112111, 0x11112111,
|
|
0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111,
|
|
0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111,
|
|
0x21111111, 0x21111111, 0x12111111, 0x12111111, 0x11211111, 0x11211111, 0x11121111, 0x11121111,
|
|
0x11121111, 0x11121111, 0x11211111, 0x11211111, 0x12111111, 0x12111111, 0x21111111, 0x21111111,
|
|
0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111,
|
|
0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111,
|
|
0x11112111, 0x11112111, 0x11111211, 0x11111211, 0x11111121, 0x11111121, 0x11111112, 0x11111112,
|
|
|
|
0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111,
|
|
0x11111112, 0x11111112, 0x11111121, 0x11111121, 0x11111211, 0x11111211, 0x11112111, 0x11112111,
|
|
0x21111111, 0x21111111, 0x12111111, 0x12111111, 0x11211111, 0x11211111, 0x11121111, 0x11121111,
|
|
0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111,
|
|
0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111,
|
|
0x11121111, 0x11121111, 0x11211111, 0x11211111, 0x12111111, 0x12111111, 0x21111111, 0x21111111,
|
|
0x11112111, 0x11112111, 0x11111211, 0x11111211, 0x11111121, 0x11111121, 0x11111111, 0x11111111,
|
|
0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111,
|
|
|
|
0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111,
|
|
0x11111111, 0x11111111, 0x12111111, 0x12111111, 0x11211111, 0x11211111, 0x11121111, 0x11121111,
|
|
0x11111112, 0x11111112, 0x11111121, 0x11111121, 0x11111211, 0x11111211, 0x11112111, 0x11112111,
|
|
0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111,
|
|
0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111,
|
|
0x11112111, 0x11112111, 0x11111211, 0x11111211, 0x11111121, 0x11111121, 0x11111112, 0x11111112,
|
|
0x11121111, 0x11121111, 0x11211111, 0x11211111, 0x12111111, 0x12111111, 0x21111111, 0x21111111,
|
|
0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111,
|
|
|
|
0x21111111, 0x21111111, 0x12111111, 0x12111111, 0x11211111, 0x11211111, 0x11121111, 0x11121111,
|
|
0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111,
|
|
0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111,
|
|
0x11111112, 0x11111112, 0x11111121, 0x11111121, 0x11111211, 0x11111211, 0x11112111, 0x11112111,
|
|
0x11112111, 0x11112111, 0x11111211, 0x11111211, 0x11111121, 0x11111121, 0x11111112, 0x11111112,
|
|
0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111,
|
|
0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111,
|
|
0x11121111, 0x11121111, 0x11211111, 0x11211111, 0x12111111, 0x12111111, 0x21111111, 0x21111111,
|
|
};
|
|
|
|
fn paletteMode(_: Self) GBA.PaletteMode {
|
|
return .Color16;
|
|
}
|
|
|
|
fn size(_: Self) OAM.ObjectSize {
|
|
return .Size32x64;
|
|
}
|
|
|
|
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 px_width = 8 * 4;
|
|
const offset = 0x40 / 4;
|
|
const len = px_width * @sizeOf(u32);
|
|
|
|
GBA.memcpy32(GBA.SPRITE_VRAM, &Self.tiles[0], len);
|
|
GBA.memcpy32(GBA.SPRITE_VRAM + (px_width * offset), &Self.tiles[px_width], len);
|
|
GBA.memcpy32(GBA.SPRITE_VRAM + (px_width * (offset * 2)), &Self.tiles[px_width * 2], len);
|
|
GBA.memcpy32(GBA.SPRITE_VRAM + (px_width * (offset * 3)), &Self.tiles[px_width * 3], len);
|
|
GBA.memcpy32(GBA.SPRITE_VRAM + (px_width * (offset * 4)), &Self.tiles[px_width * 4], len);
|
|
GBA.memcpy32(GBA.SPRITE_VRAM + (px_width * (offset * 5)), &Self.tiles[px_width * 5], len);
|
|
GBA.memcpy32(GBA.SPRITE_VRAM + (px_width * (offset * 6)), &Self.tiles[px_width * 6], len);
|
|
GBA.memcpy32(GBA.SPRITE_VRAM + (px_width * (offset * 7)), &Self.tiles[px_width * 7], len);
|
|
|
|
// Palette
|
|
GBA.memcpy32(GBA.OBJ_PALETTE_RAM, &Self.pal, Self.pal.len * @sizeOf(u32));
|
|
}
|
|
};
|