01/08/22: Part 2
Current Goal: I will write the bare minimum amount of code to display a red pixel onto the GBA screen using Zig
04000000-040003FE
This is a good starting point, now i just need to find out what values to write into what spots to get the desired setup. Should be simple right?
4000000h 2 R/W DISPCNT LCD Control
Which from my inferred and possibly incorrect understanding means at 4000000 (no idea what the h is for, high bit maybe? something endian perhaps?), there are 2 bits, they can be Read or Written to, they're called DISPCNT and they control the LCD.
4000000h - DISPCNT - LCD Control (Read/Write)
Bit Expl.
0-2 BG Mode (0-5=Video Mode 0-5, 6-7=Prohibited)
3 Reserved / CGB Mode (0=GBA, 1=CGB; can be set only by BIOS opcodes)
4 Display Frame Select (0-1=Frame 0-1) (for BG Modes 4,5 only)
5 H-Blank Interval Free (1=Allow access to OAM during H-Blank)
6 OBJ Character VRAM Mapping (0=Two dimensional, 1=One dimensional)
7 Forced Blank (1=Allow FAST access to VRAM,Palette,OAM)
8 Screen Display BG0 (0=Off, 1=On)
9 Screen Display BG1 (0=Off, 1=On)
10 Screen Display BG2 (0=Off, 1=On)
11 Screen Display BG3 (0=Off, 1=On)
12 Screen Display OBJ (0=Off, 1=On)
13 Window 0 Display Flag (0=Off, 1=On)
14 Window 1 Display Flag (0=Off, 1=On)
15 OBJ Window Display Flag (0=Off, 1=On)
According to the book BG Modes 0-2 are Tile/Map-based. BG Modes 3-5 are Bitmap-based. It seems like what we want is one of the modes 3-5, so we have a nice chunky bitmap we can write to. Further on we find a description of Mode 3 which seems to fit it nicely.
BG Mode 3 (Bitmap based Mode for still images)
06000000-06013FFF 80 KBytes Frame 0 buffer (only 75K actually used)
06014000-06017FFF 16 KBytes OBJ Tiles
So now to write some Zig, i need to get a gba rom compiling that sets up Mode 3 video mode and doesn't crash on the emulator, that'll do for the moment.
Zig is super cool!
Me$ zig init-exe
info: Created build.zig
info: Created src/main.zig
info: Next, try `zig build --help` or `zig build run`
Me$ zig build run
info: All your codebase are belong to us.
const gba_thumb_target = blk: {
var target = CrossTarget{
.cpu_arch = std.Target.Cpu.Arch.thumb,
.cpu_model = .{ .explicit = &std.Target.arm.cpu.arm7tdmi },
.os_tag = .freestanding,
};
target.cpu_features_add.addFeature(@enumToInt(std.Target.arm.Feature.thumb_mode));
break :blk target;
};
.text :
{
KEEP(*(.gbaheader))
KEEP(*(.gbamain))
*(EXCLUDE_FILE (*.iwram*) .text*)
. ALIGN(4);
} >rom = 0xff
It appears we can export these things out from Zig, I found the following line that looks interesting.
export var gameHeader linksection(".gbaheader")
Lets have a look and see what the Zig documentation has to say about linksection.
The linksection keyword.
TODO add documentation for linksection
Ah.. Did i mention Zig is still in active development! Ok, for now, we will guess that it makes that keyword available for linking stuff in outside of our source code or something!