fix: reimplement grabbing ROM title if provided via cmd arg

This commit is contained in:
Rekai Nyangadzayi Musuka 2023-03-27 16:22:07 -05:00
parent b879c76510
commit 1d8b21d6b4
4 changed files with 10 additions and 8 deletions

View File

@ -6,7 +6,7 @@ const gdbstub = @import("lib/zba-gdbstub/build.zig");
const zgui = @import("lib/zgui/build.zig"); const zgui = @import("lib/zgui/build.zig");
const nfd = @import("lib/nfd-zig/build.zig"); const nfd = @import("lib/nfd-zig/build.zig");
pub fn build(b: *std.build.Builder) void { pub fn build(b: *std.Build) void {
// Minimum Zig Version // Minimum Zig Version
const min_ver = std.SemanticVersion.parse("0.11.0-dev.2168+322ace70f") catch return; // https://github.com/ziglang/zig/commit/322ace70f const min_ver = std.SemanticVersion.parse("0.11.0-dev.2168+322ace70f") catch return; // https://github.com/ziglang/zig/commit/322ace70f
if (builtin.zig_version.order(min_ver).compare(.lt)) { if (builtin.zig_version.order(min_ver).compare(.lt)) {

View File

@ -31,12 +31,12 @@ pub const State = struct {
fps_hist: RingBuffer(u32), fps_hist: RingBuffer(u32),
should_quit: bool = false, should_quit: bool = false,
pub fn init(allocator: Allocator) !@This() { /// if zba is initialized with a ROM already provided, this initializer should be called
/// with `title_opt` being non-null
pub fn init(allocator: Allocator, title_opt: ?*const [12]u8) !@This() {
const history = try allocator.alloc(u32, histogram_len); const history = try allocator.alloc(u32, histogram_len);
var title: [12:0]u8 = [_:0]u8{0} ** 12; const title: [12:0]u8 = if (title_opt) |t| t.* ++ [_:0]u8{} else "[No Title]\x00\x00".*;
std.mem.copy(u8, &title, "[No Title]");
return .{ .title = title, .fps_hist = RingBuffer(u32).init(history) }; return .{ .title = title, .fps_hist = RingBuffer(u32).init(history) };
} }

View File

@ -90,8 +90,10 @@ pub fn main() void {
cpu.fastBoot(); cpu.fastBoot();
} }
const title_ptr = if (paths.rom != null) &bus.pak.title else null;
// TODO: Just copy the title instead of grabbing a pointer to it // TODO: Just copy the title instead of grabbing a pointer to it
var gui = Gui.init(allocator, &bus.apu) catch |e| exitln("failed to init gui: {}", .{e}); var gui = Gui.init(allocator, &bus.apu, title_ptr) catch |e| exitln("failed to init gui: {}", .{e});
defer gui.deinit(); defer gui.deinit();
var quit = std.atomic.Atomic(bool).init(false); var quit = std.atomic.Atomic(bool).init(false);

View File

@ -57,7 +57,7 @@ pub const Gui = struct {
allocator: Allocator, allocator: Allocator,
program_id: gl.GLuint, program_id: gl.GLuint,
pub fn init(allocator: Allocator, apu: *Apu) !Self { pub fn init(allocator: Allocator, apu: *Apu, title_opt: ?*const [12]u8) !Self {
if (SDL.SDL_Init(SDL.SDL_INIT_VIDEO | SDL.SDL_INIT_EVENTS | SDL.SDL_INIT_AUDIO) < 0) panic(); if (SDL.SDL_Init(SDL.SDL_INIT_VIDEO | SDL.SDL_INIT_EVENTS | SDL.SDL_INIT_AUDIO) < 0) panic();
if (SDL.SDL_GL_SetAttribute(SDL.SDL_GL_CONTEXT_PROFILE_MASK, SDL.SDL_GL_CONTEXT_PROFILE_CORE) < 0) panic(); if (SDL.SDL_GL_SetAttribute(SDL.SDL_GL_CONTEXT_PROFILE_MASK, SDL.SDL_GL_CONTEXT_PROFILE_CORE) < 0) panic();
if (SDL.SDL_GL_SetAttribute(SDL.SDL_GL_CONTEXT_MAJOR_VERSION, 3) < 0) panic(); if (SDL.SDL_GL_SetAttribute(SDL.SDL_GL_CONTEXT_MAJOR_VERSION, 3) < 0) panic();
@ -91,7 +91,7 @@ pub const Gui = struct {
.audio = Audio.init(apu), .audio = Audio.init(apu),
.allocator = allocator, .allocator = allocator,
.state = try imgui.State.init(allocator), .state = try imgui.State.init(allocator, title_opt),
}; };
} }