chore(config): switch toml library

TODO: find a lib that can serialize Zig structs to TOML
This commit is contained in:
Rekai Nyangadzayi Musuka 2023-06-21 17:59:59 -05:00
parent e8bc798120
commit 10215d4e99
8 changed files with 29 additions and 47 deletions

3
.gitmodules vendored
View File

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

View File

@ -84,14 +84,16 @@ Most recently built on Zig [v0.11.0-dev.3299+34865d693](https://github.com/zigla
Dependency | Source Dependency | Source
--- | --- --- | ---
SDL.zig | <https://github.com/MasterQ32/SDL.zig>
known-folders | <https://github.com/ziglibs/known-folders> known-folders | <https://github.com/ziglibs/known-folders>
nfd-zig | <https://github.com/fabioarnold/nfd-zig> nfd-zig | <https://github.com/fabioarnold/nfd-zig>
SDL.zig | <https://github.com/MasterQ32/SDL.zig>
tomlz | <https://github.com/mattyhall/tomlz>
zba-gdbstub | <https://github.com/paoda/zba-gdbstub>
zba-util | <https://git.musuka.dev/paoda/zba-util>
zgui | <https://github.com/michal-z/zig-gamedev/tree/main/libs/zgui> zgui | <https://github.com/michal-z/zig-gamedev/tree/main/libs/zgui>
zig-clap | <https://github.com/Hejsil/zig-clap> zig-clap | <https://github.com/Hejsil/zig-clap>
zig-datetime | <https://github.com/frmdstryr/zig-datetime> zig-datetime | <https://github.com/frmdstryr/zig-datetime>
zig-toml | <https://github.com/aeronavery/zig-toml> `bitfield.zig` | [https://github.com/FlorenceOS/Florence](https://github.com/FlorenceOS/Florence/blob/aaa5a9e568/lib/util/bitfields.zig)
`bitfields.zig` | [https://github.com/FlorenceOS/Florence](https://github.com/FlorenceOS/Florence/blob/aaa5a9e568/lib/util/bitfields.zig)
`gl.zig` | <https://github.com/MasterQ32/zig-opengl> `gl.zig` | <https://github.com/MasterQ32/zig-opengl>
Use `git submodule update --init` from the project root to pull the git relevant git submodules Use `git submodule update --init` from the project root to pull the git relevant git submodules

View File

@ -29,6 +29,7 @@ pub fn build(b: *std.Build) void {
exe.addModule("clap", b.dependency("zig-clap", .{}).module("clap")); // https://github.com/Hejsil/zig-clap exe.addModule("clap", b.dependency("zig-clap", .{}).module("clap")); // https://github.com/Hejsil/zig-clap
exe.addModule("gdbstub", b.dependency("zba-gdbstub", .{}).module("gdbstub")); // https://git.musuka.dev/paoda/zba-gdbstub exe.addModule("gdbstub", b.dependency("zba-gdbstub", .{}).module("gdbstub")); // https://git.musuka.dev/paoda/zba-gdbstub
exe.addModule("zba-util", b.dependency("zba-util", .{}).module("zba-util")); // https://git.musuka.dev/paoda/zba-util exe.addModule("zba-util", b.dependency("zba-util", .{}).module("zba-util")); // https://git.musuka.dev/paoda/zba-util
exe.addModule("tomlz", b.dependency("tomlz", .{}).module("tomlz")); // https://github.com/mattyhall/tomlz
// https://github.com/fabioarnold/nfd-zig // https://github.com/fabioarnold/nfd-zig
const nfd_dep = b.dependency("nfd", .{ .target = target, .optimize = optimize }); const nfd_dep = b.dependency("nfd", .{ .target = target, .optimize = optimize });
@ -46,7 +47,6 @@ pub fn build(b: *std.Build) void {
zgui_pkg.link(exe); zgui_pkg.link(exe);
exe.addAnonymousModule("bitfield", .{ .source_file = .{ .path = "lib/bitfield.zig" } }); // https://github.com/FlorenceOS/ exe.addAnonymousModule("bitfield", .{ .source_file = .{ .path = "lib/bitfield.zig" } }); // https://github.com/FlorenceOS/
exe.addAnonymousModule("toml", .{ .source_file = .{ .path = "lib/zig-toml/src/toml.zig" } }); // https://github.com/aeronavery/zig-toml
exe.addAnonymousModule("gl", .{ .source_file = .{ .path = "lib/gl.zig" } }); // https://github.com/MasterQ32/zig-opengl exe.addAnonymousModule("gl", .{ .source_file = .{ .path = "lib/gl.zig" } }); // https://github.com/MasterQ32/zig-opengl
b.installArtifact(exe); b.installArtifact(exe);

View File

@ -26,5 +26,9 @@
.url = "https://git.musuka.dev/paoda/zba-util/archive/e616cf09e53f5c402c8f040d14baa211683e70e3.tar.gz", .url = "https://git.musuka.dev/paoda/zba-util/archive/e616cf09e53f5c402c8f040d14baa211683e70e3.tar.gz",
.hash = "1220b80b2c0989dcc47275ab9d7d70da4858ef3c1fe1f934e8d838e65028127f6ef3", .hash = "1220b80b2c0989dcc47275ab9d7d70da4858ef3c1fe1f934e8d838e65028127f6ef3",
}, },
.tomlz = .{
.url = "https://github.com/mattyhall/tomlz/archive/4928d38e9bb682a9966ffe7f41230435d0111b1e.tar.gz",
.hash = "12202b57d7b46fff8d16a17371c4f9b711a56b866f0cd11844e4243c09343a2c4c6d",
},
}, },
} }

View File

@ -1,4 +1,4 @@
[Host] [host]
# Using nearest-neighbour scaling, how many times the native resolution # Using nearest-neighbour scaling, how many times the native resolution
# of the game bow should the screen be? # of the game bow should the screen be?
win_scale = 3 win_scale = 3
@ -7,7 +7,7 @@ vsync = true
# Mute ZBA # Mute ZBA
mute = false mute = false
[Guest] [guest]
# Sync Emulation to Audio # Sync Emulation to Audio
audio_sync = true audio_sync = true
# Sync Emulation to Video # Sync Emulation to Video
@ -17,7 +17,7 @@ force_rtc = false
# Skip BIOS # Skip BIOS
skip_bios = false skip_bios = false
[Debug] [debug]
# Enable detailed CPU logs # Enable detailed CPU logs
cpu_trace = false cpu_trace = false
# When false and builtin.mode == .Debug, ZBA will panic # When false and builtin.mode == .Debug, ZBA will panic

@ -1 +0,0 @@
Subproject commit 016b8bcf98e50ae9408f6a9606bbec5a9bc6f677

View File

@ -1,5 +1,5 @@
const std = @import("std"); const std = @import("std");
const toml = @import("toml"); const tomlz = @import("tomlz");
const Allocator = std.mem.Allocator; const Allocator = std.mem.Allocator;
@ -7,6 +7,7 @@ const log = std.log.scoped(.Config);
var state: Config = .{}; var state: Config = .{};
const Config = struct { const Config = struct {
// FIXME: tomlz expects these to be case sensitive
host: Host = .{}, host: Host = .{},
guest: Guest = .{}, guest: Guest = .{},
debug: Debug = .{}, debug: Debug = .{},
@ -58,29 +59,5 @@ pub fn load(allocator: Allocator, file_path: []const u8) !void {
const contents = try config_file.readToEndAlloc(allocator, try config_file.getEndPos()); const contents = try config_file.readToEndAlloc(allocator, try config_file.getEndPos());
defer allocator.free(contents); defer allocator.free(contents);
var parser = try toml.parseFile(allocator, file_path); state = try tomlz.parser.decode(Config, allocator, contents);
defer parser.deinit();
const table = try parser.parse();
defer table.deinit();
// TODO: Report unknown config options
if (table.keys.get("Host")) |host| {
if (host.Table.keys.get("win_scale")) |scale| state.host.win_scale = scale.Integer;
if (host.Table.keys.get("vsync")) |vsync| state.host.vsync = vsync.Boolean;
if (host.Table.keys.get("mute")) |mute| state.host.mute = mute.Boolean;
}
if (table.keys.get("Guest")) |guest| {
if (guest.Table.keys.get("audio_sync")) |sync| state.guest.audio_sync = sync.Boolean;
if (guest.Table.keys.get("video_sync")) |sync| state.guest.video_sync = sync.Boolean;
if (guest.Table.keys.get("force_rtc")) |forced| state.guest.force_rtc = forced.Boolean;
if (guest.Table.keys.get("skip_bios")) |skip| state.guest.skip_bios = skip.Boolean;
}
if (table.keys.get("Debug")) |debug| {
if (debug.Table.keys.get("cpu_trace")) |trace| state.debug.cpu_trace = trace.Boolean;
if (debug.Table.keys.get("unhandled_io")) |unhandled| state.debug.unhandled_io = unhandled.Boolean;
}
} }

View File

@ -179,14 +179,6 @@ pub fn draw(state: *State, win_dim: Dimensions, tex_id: GLuint, cpu: *Arm7tdmi)
_ = zgui.begin("Dependencies", .{ .popen = &state.win_stat.show_deps }); _ = zgui.begin("Dependencies", .{ .popen = &state.win_stat.show_deps });
defer zgui.end(); defer zgui.end();
zgui.bulletText("SDL.zig by Felix Queißner", .{});
{
zgui.indent(.{});
defer zgui.unindent(.{});
zgui.bulletText("SDL by Sam Lantinga", .{});
}
zgui.bulletText("known-folders by ziglibs", .{}); zgui.bulletText("known-folders by ziglibs", .{});
zgui.bulletText("nfd-zig by Fabio Arnold", .{}); zgui.bulletText("nfd-zig by Fabio Arnold", .{});
{ {
@ -195,6 +187,16 @@ pub fn draw(state: *State, win_dim: Dimensions, tex_id: GLuint, cpu: *Arm7tdmi)
zgui.bulletText("nativefiledialog by Michael Labbe", .{}); zgui.bulletText("nativefiledialog by Michael Labbe", .{});
} }
zgui.bulletText("SDL.zig by Felix Queißner", .{});
{
zgui.indent(.{});
defer zgui.unindent(.{});
zgui.bulletText("SDL by Sam Lantinga", .{});
}
zgui.bulletText("tomlz by Matthew Hall", .{});
zgui.bulletText("zba-gdbstub by Rekai Musuka", .{}); zgui.bulletText("zba-gdbstub by Rekai Musuka", .{});
zgui.bulletText("zba-util by Rekai Musuka", .{}); zgui.bulletText("zba-util by Rekai Musuka", .{});
zgui.bulletText("zgui by Michal Ziulek", .{}); zgui.bulletText("zgui by Michal Ziulek", .{});
@ -206,6 +208,9 @@ pub fn draw(state: *State, win_dim: Dimensions, tex_id: GLuint, cpu: *Arm7tdmi)
} }
zgui.bulletText("zig-clap by Jimmi Holst Christensen", .{}); zgui.bulletText("zig-clap by Jimmi Holst Christensen", .{});
zgui.bulletText("zig-datetime by Jairus Martin", .{}); zgui.bulletText("zig-datetime by Jairus Martin", .{});
zgui.newLine();
zgui.bulletText("bitfield.zig by Hannes Bredberg and FlorenceOS contributors", .{});
zgui.bulletText("zig-opengl by Felix Queißner", .{}); zgui.bulletText("zig-opengl by Felix Queißner", .{});
{ {
zgui.indent(.{}); zgui.indent(.{});
@ -213,8 +218,6 @@ pub fn draw(state: *State, win_dim: Dimensions, tex_id: GLuint, cpu: *Arm7tdmi)
zgui.bulletText("OpenGL-Registry by The Khronos Group", .{}); zgui.bulletText("OpenGL-Registry by The Khronos Group", .{});
} }
zgui.bulletText("zig-toml by Aeron Avery", .{});
zgui.bulletText("bitfield.zig by Hannes Bredberg and FlorenceOS contributors", .{});
} }
if (state.win_stat.show_regs) { if (state.win_stat.show_regs) {