-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rename repo to Zig GBA to build more of a SDK
* Add GBA static library * Create examples folder and move "Hello World" to examples/first * Add GBA/builder.zig helper for simplifying setup of building GBA ROM
- Loading branch information
1 parent
331e320
commit eeb42c7
Showing
9 changed files
with
93 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ | |
"label": "Format current file", | ||
"type": "shell", | ||
"command": "zig fmt ${file}", | ||
"problemMatcher": [] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
const Builder = @import("std").build.Builder; | ||
const LibExeObjStep = @import("std").build.LibExeObjStep; | ||
const builtin = @import("std").builtin; | ||
const fmt = @import("std").fmt; | ||
const FixedBufferAllocator = @import("std").heap.FixedBufferAllocator; | ||
const std = @import("std"); | ||
const fs = @import("std").fs; | ||
|
||
const GBALinkerScript = "GBA/gba.ld"; | ||
|
||
fn gbaThumbTarget() std.Target { | ||
return std.Target{ | ||
.Cross = std.Target.Cross{ | ||
.arch = std.Target.Arch{ .thumb = std.Target.Arch.Arm32.v4t }, | ||
.os = .freestanding, | ||
.abi = .none, | ||
}, | ||
}; | ||
} | ||
|
||
pub fn addGBAStaticLibrary(b: *Builder, libraryName: []const u8, sourceFile: []const u8) *LibExeObjStep { | ||
const lib = b.addStaticLibrary(libraryName, sourceFile); | ||
|
||
lib.setTheTarget(gbaThumbTarget()); | ||
|
||
lib.setLinkerScriptPath(GBALinkerScript); | ||
lib.setBuildMode(builtin.Mode.ReleaseFast); | ||
|
||
return lib; | ||
} | ||
|
||
pub fn createGBALib(b: *Builder) *LibExeObjStep { | ||
return addGBAStaticLibrary(b, "ZigGBA", "GBA/gba.zig"); | ||
} | ||
|
||
pub fn addGBAExecutable(b: *Builder, romName: []const u8, sourceFile: []const u8) *LibExeObjStep { | ||
const exe = b.addExecutable(romName, sourceFile); | ||
|
||
exe.setTheTarget(gbaThumbTarget()); | ||
|
||
exe.setOutputDir("zig-cache/raw"); | ||
exe.setLinkerScriptPath(GBALinkerScript); | ||
exe.setBuildMode(builtin.Mode.ReleaseFast); | ||
|
||
const gbaLib = createGBALib(b); | ||
exe.addPackagePath("gba", "GBA/gba.zig"); | ||
exe.linkLibrary(gbaLib); | ||
|
||
var allocBuffer: [4 * 1024]u8 = undefined; | ||
var fixed = FixedBufferAllocator.init(allocBuffer[0..]); | ||
const fixedAllocator = &fixed.allocator; | ||
|
||
const outputPath = fmt.allocPrint(fixedAllocator, "zig-cache/bin/{}.gba", .{romName}) catch unreachable; | ||
|
||
if (fs.path.dirname(outputPath)) |dirPath| { | ||
_ = fs.makePath(fixedAllocator, dirPath) catch unreachable; | ||
} | ||
|
||
// TODO: Use builtin raw output when available in Zig compiler | ||
const objCopyCommand = if (builtin.os == builtin.Os.windows) "C:\\Programmation\\Zig\\llvm+clang-9.0.0-win64-msvc-mt\\bin\\llvm-objcopy.exe" else "llvm-objcopy"; | ||
const buildGBARomCommand = b.addSystemCommand(&[_][]const u8{ | ||
objCopyCommand, exe.getOutputPath(), | ||
"-O", "binary", | ||
outputPath, | ||
}); | ||
|
||
buildGBARomCommand.step.dependOn(&exe.step); | ||
|
||
b.default_step.dependOn(&buildGBARomCommand.step); | ||
|
||
return exe; | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,19 @@ | ||
# Zig GBA "Hello World" | ||
# Zig GBA | ||
|
||
This is a simple GBA program that display 3 color pixel as a hello world to the system. Also a testament to the Zig excellent cross-compile functionality ! | ||
This is a work in progress SDK for creating Game Boy Advance games using [Zig](https://ziglang.org/) programming language. Once Zig has a proper package manager, I hope that it would as easy as import the ZigGBA package. Inspired by [TONC GBA tutorial](https://www.coranac.com/tonc/text/) | ||
|
||
## Build | ||
This project assume current Zig master (0.5.0+d28aa38db). For now, you need llvm-objcopy in your PATH or change the hardcoded path in build.zig. | ||
This project assume current Zig master (0.5.0+a3f6a58c7). For now, you need llvm-objcopy in your PATH or change the hardcoded path in GBA/builder.zig. | ||
|
||
To build, simply use Zig's integrated build system | ||
```Shell | ||
zig build | ||
``` | ||
|
||
## Running in a emulator | ||
## First example running in a emulator | ||
|
||
![Emulator image](docs/Emulator.png) | ||
![First example emulator image](docs/images/FirstExampleEmulator.png) | ||
|
||
## Running on real hardware | ||
## First example running on real hardware | ||
|
||
![Real hardware image](docs/RealHardware.png) | ||
![First example real hardware image](docs/images/FirstExampleRealHardware.png) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,6 @@ | ||
const Builder = @import("std").build.Builder; | ||
const builtin = @import("std").builtin; | ||
const std = @import("std"); | ||
usingnamespace @import("GBA/builder.zig"); | ||
|
||
pub fn build(b: *Builder) void { | ||
const exe = b.addExecutable("GBAHelloWorld", "src/main.zig"); | ||
|
||
exe.setTheTarget(std.Target { | ||
.Cross = std.Target.Cross { | ||
.arch = std.Target.Arch { | ||
.thumb = std.Target.Arch.Arm32.v4t | ||
}, | ||
.os = .freestanding, | ||
.abi = .none | ||
} | ||
}); | ||
|
||
exe.setOutputDir("zig-cache/raw"); | ||
exe.setLinkerScriptPath("gba.ld"); | ||
exe.setBuildMode(builtin.Mode.ReleaseFast); | ||
|
||
const objCopyCommand = if (builtin.os == builtin.Os.windows) "C:\\Programmation\\Zig\\llvm+clang-9.0.0-win64-msvc-mt\\bin\\llvm-objcopy.exe" else "llvm-objcopy"; | ||
|
||
const buildGBARomCommand = b.addSystemCommand(&[_][]const u8 { | ||
objCopyCommand, exe.getOutputPath(), | ||
"-O", "binary", | ||
"zig-cache/bin/GBAHelloWorld.gba", | ||
}); | ||
|
||
buildGBARomCommand.step.dependOn(&exe.step); | ||
|
||
b.default_step.dependOn(&buildGBARomCommand.step); | ||
const first = addGBAExecutable(b, "first", "examples/first/first.zig"); | ||
} |
File renamed without changes
File renamed without changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters