feat: show game title as imgui screen title
This commit is contained in:
parent
ba200692c1
commit
b56b1b62d8
|
@ -188,7 +188,7 @@ pub fn init(allocator: Allocator, cpu: *Arm7tdmi, rom_path: []const u8, save_pat
|
||||||
const kind = Backup.guess(file_buf);
|
const kind = Backup.guess(file_buf);
|
||||||
const device = if (config.config().guest.force_rtc) .Rtc else guessDevice(file_buf);
|
const device = if (config.config().guest.force_rtc) .Rtc else guessDevice(file_buf);
|
||||||
|
|
||||||
logHeader(file_buf, &title);
|
logHeader(file_buf, title);
|
||||||
|
|
||||||
return .{
|
return .{
|
||||||
.buf = file_buf,
|
.buf = file_buf,
|
||||||
|
@ -219,19 +219,17 @@ fn guessDevice(buf: []const u8) Gpio.Device.Kind {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Detect other GPIO devices
|
// TODO: Detect other GPIO devices
|
||||||
|
|
||||||
return .None;
|
return .None;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn logHeader(buf: []const u8, title: *const [12]u8) void {
|
fn logHeader(buf: []const u8, title: [12]u8) void {
|
||||||
const code = buf[0xAC..0xB0];
|
const ver = buf[0xBC];
|
||||||
const maker = buf[0xB0..0xB2];
|
|
||||||
const version = buf[0xBC];
|
|
||||||
|
|
||||||
log.info("Title: {s}", .{title});
|
log.info("Title: {s}", .{title});
|
||||||
if (version != 0) log.info("Version: {}", .{version});
|
if (ver != 0) log.info("Version: {}", .{ver});
|
||||||
log.info("Game Code: {s}", .{code});
|
|
||||||
log.info("Maker Code: {s}", .{maker});
|
log.info("Game Code: {s}", .{buf[0xAC..0xB0]});
|
||||||
|
log.info("Maker Code: {s}", .{buf[0xB0..0xB2]});
|
||||||
}
|
}
|
||||||
|
|
||||||
test "OOB Access" {
|
test "OOB Access" {
|
||||||
|
|
|
@ -86,7 +86,7 @@ pub fn main() void {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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.pak.title, &bus.apu) catch |e| exitln("failed to init gui: {}", .{e});
|
var gui = Gui.init(allocator, bus.pak.title, &bus.apu) catch |e| exitln("failed to init gui: {}", .{e});
|
||||||
defer gui.deinit();
|
defer gui.deinit();
|
||||||
|
|
||||||
gui.run(&cpu, &scheduler) catch |e| exitln("failed to run gui thread: {}", .{e});
|
gui.run(&cpu, &scheduler) catch |e| exitln("failed to run gui thread: {}", .{e});
|
||||||
|
|
|
@ -34,19 +34,14 @@ pub const Gui = struct {
|
||||||
|
|
||||||
const State = struct {
|
const State = struct {
|
||||||
fps_hist: RingBuffer(u32),
|
fps_hist: RingBuffer(u32),
|
||||||
allocator: Allocator,
|
|
||||||
|
|
||||||
pub fn init(allocator: Allocator) !@This() {
|
pub fn init(allocator: Allocator) !@This() {
|
||||||
const history = try allocator.alloc(u32, 0x400);
|
const history = try allocator.alloc(u32, 0x400);
|
||||||
|
return .{ .fps_hist = RingBuffer(u32).init(history) };
|
||||||
return .{
|
|
||||||
.fps_hist = RingBuffer(u32).init(history),
|
|
||||||
.allocator = allocator,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn deinit(self: *@This()) void {
|
fn deinit(self: *@This(), allocator: Allocator) void {
|
||||||
self.fps_hist.deinit(self.allocator);
|
self.fps_hist.deinit(allocator);
|
||||||
self.* = undefined;
|
self.* = undefined;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -68,14 +63,15 @@ pub const Gui = struct {
|
||||||
|
|
||||||
window: *SDL.SDL_Window,
|
window: *SDL.SDL_Window,
|
||||||
ctx: SDL_GLContext,
|
ctx: SDL_GLContext,
|
||||||
title: []const u8,
|
title: [:0]const u8,
|
||||||
audio: Audio,
|
audio: Audio,
|
||||||
|
|
||||||
state: State,
|
state: State,
|
||||||
|
|
||||||
|
allocator: Allocator,
|
||||||
program_id: gl.GLuint,
|
program_id: gl.GLuint,
|
||||||
|
|
||||||
pub fn init(allocator: Allocator, title: *const [12]u8, apu: *Apu) !Self {
|
pub fn init(allocator: Allocator, title: [12]u8, apu: *Apu) !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();
|
||||||
|
@ -104,18 +100,19 @@ pub const Gui = struct {
|
||||||
|
|
||||||
return Self{
|
return Self{
|
||||||
.window = window,
|
.window = window,
|
||||||
.title = std.mem.sliceTo(title, 0),
|
.title = try allocator.dupeZ(u8, &title),
|
||||||
.ctx = ctx,
|
.ctx = ctx,
|
||||||
.program_id = try compileShaders(),
|
.program_id = try compileShaders(),
|
||||||
.audio = Audio.init(apu),
|
.audio = Audio.init(apu),
|
||||||
|
|
||||||
|
.allocator = allocator,
|
||||||
.state = try State.init(allocator),
|
.state = try State.init(allocator),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn deinit(self: *Self) void {
|
pub fn deinit(self: *Self) void {
|
||||||
self.audio.deinit();
|
self.audio.deinit();
|
||||||
self.state.deinit();
|
self.state.deinit(self.allocator);
|
||||||
|
|
||||||
zgui.backend.deinit();
|
zgui.backend.deinit();
|
||||||
zgui.plot.deinit();
|
zgui.plot.deinit();
|
||||||
|
@ -125,6 +122,8 @@ pub const Gui = struct {
|
||||||
SDL.SDL_GL_DeleteContext(self.ctx);
|
SDL.SDL_GL_DeleteContext(self.ctx);
|
||||||
SDL.SDL_DestroyWindow(self.window);
|
SDL.SDL_DestroyWindow(self.window);
|
||||||
SDL.SDL_Quit();
|
SDL.SDL_Quit();
|
||||||
|
|
||||||
|
self.allocator.free(self.title);
|
||||||
self.* = undefined;
|
self.* = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -266,7 +265,7 @@ pub const Gui = struct {
|
||||||
const w = @intToFloat(f32, gba_width * win_scale);
|
const w = @intToFloat(f32, gba_width * win_scale);
|
||||||
const h = @intToFloat(f32, gba_height * win_scale);
|
const h = @intToFloat(f32, gba_height * win_scale);
|
||||||
|
|
||||||
_ = zgui.begin("Game Boy Advance Screen", .{ .flags = .{ .no_resize = true, .always_auto_resize = true } });
|
_ = zgui.begin(self.title, .{ .flags = .{ .no_resize = true, .always_auto_resize = true } });
|
||||||
defer zgui.end();
|
defer zgui.end();
|
||||||
|
|
||||||
zgui.image(@intToPtr(*anyopaque, tex_id), .{ .w = w, .h = h, .uv0 = .{ 0, 1 }, .uv1 = .{ 1, 0 } });
|
zgui.image(@intToPtr(*anyopaque, tex_id), .{ .w = w, .h = h, .uv0 = .{ 0, 1 }, .uv1 = .{ 1, 0 } });
|
||||||
|
|
Loading…
Reference in New Issue