Compare commits

...

9 Commits

Author SHA1 Message Date
9a0d86b89d fix(ci): disable macOS builds 2024-09-09 04:13:16 -05:00
98d6de640f fix(windows): "SDL.h" as opposed to "SDL2/SDL.h" 2024-09-09 03:34:00 -05:00
26870542cb feat: Update to Zig v0.13.0 2024-09-09 02:43:04 -05:00
34210d1068 chore: update SDL.zig
Windows CI should work again
2024-03-22 12:39:53 -05:00
b0e23c1e28 chore: update zgui 2024-03-22 11:14:45 -05:00
9c998f7d66 fix: properly handle 16-bit misaligned reads 2024-03-11 11:07:01 -05:00
0ac107dd28 chore: replace SDL.zig 2024-03-06 18:44:06 -06:00
d71a07733d feat(ci): update ci 2024-03-06 18:36:34 -06:00
114eb69e35 fix: correctly point to SDL2 on windows builds 2024-03-06 15:32:37 -06:00
10 changed files with 59 additions and 60 deletions

View File

@@ -4,7 +4,8 @@ on:
push:
paths:
- "**.zig"
- "**.zig.zon"
- "dl_sdl2.ps1"
- "build.zig.zon"
branches:
- main
schedule:
@@ -15,12 +16,17 @@ jobs:
build:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
os: [ubuntu-latest, windows-latest] # TODO: Figure out Apple Silicon macOS
runs-on: ${{matrix.os}}
steps:
- uses: goto-bus-stop/setup-zig@v2
with:
version: 0.11.0
version: 0.13.0
- run: |
git config --global core.autocrlf false
- uses: actions/checkout@v3
with:
submodules: recursive
- name: prepare-linux
if: runner.os == 'Linux'
run: |
@@ -29,26 +35,19 @@ jobs:
- name: prepare-windows
if: runner.os == 'Windows'
run: |
vcpkg integrate install
vcpkg install sdl2:x64-windows
git config --global core.autocrlf false
.\dl_sdl2.ps1
- name: prepare-macos
if: runner.os == 'macOS'
run: |
brew install sdl2
- uses: actions/checkout@v3
with:
submodules: recursive
- name: build
run: zig build -Doptimize=ReleaseSafe -Dcpu=baseline
- name: prepare-executable
run: |
mv zig-out/lib/* zig-out/bin
- name: upload
uses: actions/upload-artifact@v3
with:
name: zba-${{matrix.os}}
path: zig-out/bin
path: zig-out
lint:
runs-on: ubuntu-latest
steps:
@@ -57,6 +56,5 @@ jobs:
submodules: recursive
- uses: goto-bus-stop/setup-zig@v2
with:
version: 0.11.0-dev.3395+1e7dcaa3a
- run: zig fmt src/**/*.zig
version: 0.13.0
- run: zig fmt --check {src,lib}/**/*.zig build.zig build.zig.zon

2
.gitignore vendored
View File

@@ -1,4 +1,4 @@
zig-cache/
.zig-cache/
zig-out/
bin/
doc/

5
.gitmodules vendored
View File

@@ -1,6 +1,3 @@
[submodule "lib/SDL.zig"]
path = lib/SDL.zig
url = https://github.com/MasterQ32/SDL.zig
[submodule "lib/zgui"]
path = lib/zgui
url = https://git.musuka.dev/paoda/zgui
url = https://github.com/paoda/SDL.zig

View File

@@ -1,7 +1,5 @@
const std = @import("std");
const Sdk = @import("lib/SDL.zig/build.zig");
const zgui = @import("lib/zgui/build.zig");
const sdl = @import("lib/SDL.zig/build.zig");
// Although this function looks imperative, note that its job is to
// declaratively construct a build graph that will be executed by an external
@@ -22,28 +20,27 @@ pub fn build(b: *std.Build) void {
.name = "turbo",
// In this case the main source file is merely a path, however, in more
// complicated build scripts, this could be a generated file.
.root_source_file = .{ .path = "src/main.zig" },
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
exe.root_module.addImport("arm32", b.dependency("arm32", .{}).module("arm32"));
exe.root_module.addImport("gdbstub", b.dependency("zba-gdbstub", .{}).module("gdbstub"));
exe.root_module.addImport("zig-clap", b.dependency("zig-clap", .{}).module("clap"));
const sdk = sdl.init(b, null, null);
const zgui = b.dependency("zgui", .{ .shared = false, .with_implot = true, .backend = .sdl2_opengl3 });
const imgui = zgui.artifact("imgui");
exe.root_module.addAnonymousImport("bitfield", .{ .root_source_file = .{ .path = "lib/bitfield.zig" } }); // https://github.com/FlorenceOS/
exe.root_module.addAnonymousImport("gl", .{ .root_source_file = .{ .path = "lib/gl.zig" } }); // https://github.com/MasterQ32/zig-opengl
exe.root_module.addImport("arm32", b.dependency("arm32", .{}).module("arm32")); // https://git.musuka.dev/paoda/arm32
exe.root_module.addImport("gdbstub", b.dependency("zba-gdbstub", .{}).module("zba-gdbstub")); // https://git.musuka.dev/paoda/zba-gdbstub
exe.root_module.addImport("zig-clap", b.dependency("zig-clap", .{}).module("clap")); // https://github.com/Hejsil/zig-clap
exe.root_module.addImport("zgui", zgui.module("root")); // https://git.musuka.dev/paoda/zgui
exe.root_module.addImport("sdl2", sdk.getNativeModule()); // https://github.com/MasterQ32/SDL.zig
// https://github.com/MasterQ32/SDL.zig
const sdk = Sdk.init(b, null);
sdk.link(exe, .static);
exe.root_module.addImport("sdl2", sdk.getNativeModule());
exe.root_module.addAnonymousImport("bitfield", .{ .root_source_file = b.path("lib/bitfield.zig") }); // https://github.com/FlorenceOS/
exe.root_module.addAnonymousImport("gl", .{ .root_source_file = b.path("lib/gl.zig") }); // https://github.com/MasterQ32/zig-opengl
// https://git.musuka.dev/paoda/zgui
const zgui_pkg = zgui.package(b, target, optimize, .{ .options = .{ .backend = .sdl2_opengl3 } });
zgui_pkg.link(exe);
sdk.link(zgui_pkg.zgui_c_cpp, .static);
sdk.link(exe, .dynamic, .SDL2);
sdk.link(imgui, .dynamic, .SDL2);
exe.linkLibrary(imgui);
// This declares intent for the executable to be installed into the
// standard location when the user invokes the "install" step (the default
@@ -76,7 +73,7 @@ pub fn build(b: *std.Build) void {
// Creates a step for unit testing. This only builds the test executable
// but does not run it.
const unit_tests = b.addTest(.{
.root_source_file = .{ .path = "src/main.zig" },
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});

View File

@@ -10,16 +10,20 @@
},
.dependencies = .{
.@"zig-clap" = .{
.url = "https://github.com/Hejsil/zig-clap/archive/4267b0b60ef6f87cccf3ee6ed481e6d0759180c6.tar.gz",
.hash = "12202fa30d679d821292bcd953458b9e76097a5d16999489125a206db63a53392833",
.url = "git+https://github.com/Hejsil/zig-clap#c0193e9247335a6c1688b946325060289405de2a",
.hash = "12207ee987ce045596cb992cfb15b0d6d9456e50d4721c3061c69dabc2962053644d",
},
.@"zba-gdbstub" = .{
.url = "https://git.musuka.dev/paoda/zba-gdbstub/archive/7ae72ed5a892d2fc6cc3f5511e2b96134d928b59.tar.gz",
.hash = "1220823e961f369e22b62edc1b4da3742af0a7cb420ae9a52ec33216ff5a8ef270c8",
.url = "git+https://git.musuka.dev/paoda/zba-gdbstub#9a50607d5f48293f950a4e823344f2bc24582a5a",
.hash = "1220ac267744ed2a735f03c4620d7c6210fbd36d7bfb2b376ddc3436faebadee0f61",
},
.arm32 = .{
.url = "https://git.musuka.dev/paoda/arm32/archive/6f0e27136072610e6dba97ff8aaf5e2ec86e2c09.tar.gz",
.hash = "122047d0affe12b9e9e9c655a7ba6d51b311f02d688e9f1c9a91394a03103f1c0cd5",
.url = "git+https://git.musuka.dev/paoda/arm32#814d081ea0983bc48841a6baad7158c157b17ad6",
.hash = "12203c3dacf3a7aa7aee5fc5763dd7b40399bd1c34d1483330b6bd5a76bffef22d82",
},
.zgui = .{
.url = "git+https://git.musuka.dev/paoda/zgui#7f8d05101e96c64314d7926c80ee157dcb89da4e",
.hash = "1220bd81a1c7734892b1d4233ed047710487787873c85dd5fc76d1764a331ed2ff43",
},
},
}

View File

@@ -3,9 +3,9 @@ $ArchiveFile = ".\SDL2-devel-mingw.zip"
$Json = @"
{
"x86_64-windows-gnu": {
"include": "SDL2\\include",
"libs": "SDL2\\lib",
"bin": "SDL2\\bin"
"include": ".build_config\\SDL2\\include",
"libs": ".build_config\\SDL2\\lib",
"bin": ".build_config\\SDL2\\bin"
}
}
"@
@@ -19,13 +19,17 @@ if (!(Test-Path -PathType Leaf $ArchiveFile)) {
Expand-Archive $ArchiveFile
if (Test-Path -PathType Leaf .\SDL2) {
if (Test-Path -PathType Container .\SDL2) {
Remove-Item -Recurse .\SDL2
}
New-Item -Force -ItemType Directory -Path .\SDL2
Get-ChildItem -Path ".\SDL2-devel-mingw\SDL2-$SDL2Version\x86_64-w64-mingw32" | Move-Item -Destination .\SDL2
# #include <SDL.h>
Move-Item -Force -Path .\SDL2\include\SDL2\* -Destination .\SDL2\include
Remove-Item -Force .\SDL2\include\SDL2
New-Item -Force .\sdl.json -Value $Json
Remove-Item -Recurse .\SDL2-devel-mingw

Submodule lib/zgui deleted from 1fff275f8d

View File

@@ -429,7 +429,7 @@ const Input = struct {
inner: u32 = 0x007F_03FF,
pub inline fn keyinput(self: *const Input) KeyInput {
const value = @atomicLoad(u32, &self.inner, .Monotonic);
const value = @atomicLoad(u32, &self.inner, .monotonic);
return .{ .raw = @truncate(value) };
}
@@ -440,11 +440,11 @@ const Input = struct {
else => @compileError("not supported"),
};
_ = @atomicRmw(u32, &self.inner, op, msked, .Monotonic);
_ = @atomicRmw(u32, &self.inner, op, msked, .monotonic);
}
pub inline fn extkeyin(self: *const Input) ExtKeyIn {
const value = @atomicLoad(u32, &self.inner, .Monotonic);
const value = @atomicLoad(u32, &self.inner, .monotonic);
const shifted: u16 = @truncate(value >> 16);
return .{ .raw = shifted | 0b00110100 }; // bits 2, 4, 5 are always set
@@ -457,10 +457,10 @@ const Input = struct {
else => @compileError("not supported"),
};
_ = @atomicRmw(u32, &self.inner, op, msked, .Monotonic);
_ = @atomicRmw(u32, &self.inner, op, msked, .monotonic);
}
pub inline fn set(self: *Input, comptime op: AtomicRmwOp, value: u32) void {
_ = @atomicRmw(u32, &self.inner, op, value, .Monotonic);
_ = @atomicRmw(u32, &self.inner, op, value, .monotonic);
}
};

View File

@@ -98,7 +98,7 @@ pub const Ui = struct {
var event: SDL.SDL_Event = undefined;
while (!sync.should_quit.load(.Monotonic)) {
while (!sync.should_quit.load(.monotonic)) {
emu.runFrame(scheduler, system); // TODO: run emu in separate thread
while (SDL.SDL_PollEvent(&event) != 0) {
@@ -141,7 +141,7 @@ pub const Ui = struct {
var event: SDL.SDL_Event = undefined;
while (!sync.should_quit.load(.Monotonic)) {
while (!sync.should_quit.load(.monotonic)) {
while (SDL.SDL_PollEvent(&event) != 0) {
_ = zgui.backend.processEvent(&event);
handleInput(&event, system, &self.state, sync);
@@ -178,7 +178,7 @@ pub const Ui = struct {
fn handleInput(event: *SDL.SDL_Event, system: System, state: *imgui.State, sync: *Sync) void {
switch (event.type) {
SDL.SDL_QUIT => sync.should_quit.store(true, .Monotonic),
SDL.SDL_QUIT => sync.should_quit.store(true, .monotonic),
SDL.SDL_WINDOWEVENT => {
if (event.window.event == SDL.SDL_WINDOWEVENT_RESIZED) {
std.log.debug("window resized to: {}x{}", .{ event.window.data1, event.window.data2 });