Add a GUI to ZBA #7
|
@ -188,7 +188,7 @@ pub fn init(allocator: Allocator, cpu: *Arm7tdmi, rom_path: []const u8, save_pat
|
|||
const kind = Backup.guess(file_buf);
|
||||
const device = if (config.config().guest.force_rtc) .Rtc else guessDevice(file_buf);
|
||||
|
||||
logHeader(file_buf, &title);
|
||||
logHeader(file_buf, title);
|
||||
|
||||
return .{
|
||||
.buf = file_buf,
|
||||
|
@ -220,19 +220,17 @@ fn guessDevice(buf: []const u8) Gpio.Device.Kind {
|
|||
}
|
||||
|
||||
// TODO: Detect other GPIO devices
|
||||
|
||||
return .None;
|
||||
}
|
||||
|
||||
fn logHeader(buf: []const u8, title: *const [12]u8) void {
|
||||
const code = buf[0xAC..0xB0];
|
||||
const maker = buf[0xB0..0xB2];
|
||||
const version = buf[0xBC];
|
||||
fn logHeader(buf: []const u8, title: [12]u8) void {
|
||||
const ver = buf[0xBC];
|
||||
|
||||
log.info("Title: {s}", .{title});
|
||||
if (version != 0) log.info("Version: {}", .{version});
|
||||
log.info("Game Code: {s}", .{code});
|
||||
log.info("Maker Code: {s}", .{maker});
|
||||
if (ver != 0) log.info("Version: {}", .{ver});
|
||||
|
||||
log.info("Game Code: {s}", .{buf[0xAC..0xB0]});
|
||||
log.info("Maker Code: {s}", .{buf[0xB0..0xB2]});
|
||||
}
|
||||
|
||||
test "OOB Access" {
|
||||
|
|
|
@ -90,7 +90,7 @@ pub fn main() void {
|
|||
}
|
||||
|
||||
// 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();
|
||||
|
||||
var quit = Atomic(bool).init(false);
|
||||
|
|
|
@ -34,19 +34,14 @@ pub const Gui = struct {
|
|||
|
||||
const State = struct {
|
||||
fps_hist: RingBuffer(u32),
|
||||
allocator: Allocator,
|
||||
|
||||
pub fn init(allocator: Allocator) !@This() {
|
||||
const history = try allocator.alloc(u32, 0x400);
|
||||
|
||||
return .{
|
||||
.fps_hist = RingBuffer(u32).init(history),
|
||||
.allocator = allocator,
|
||||
};
|
||||
return .{ .fps_hist = RingBuffer(u32).init(history) };
|
||||
}
|
||||
|
||||
fn deinit(self: *@This()) void {
|
||||
self.fps_hist.deinit(self.allocator);
|
||||
fn deinit(self: *@This(), allocator: Allocator) void {
|
||||
self.fps_hist.deinit(allocator);
|
||||
self.* = undefined;
|
||||
}
|
||||
};
|
||||
|
@ -68,14 +63,15 @@ pub const Gui = struct {
|
|||
|
||||
window: *SDL.SDL_Window,
|
||||
ctx: SDL_GLContext,
|
||||
title: []const u8,
|
||||
title: [:0]const u8,
|
||||
audio: Audio,
|
||||
|
||||
state: State,
|
||||
|
||||
allocator: Allocator,
|
||||
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_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();
|
||||
|
@ -104,18 +100,19 @@ pub const Gui = struct {
|
|||
|
||||
return Self{
|
||||
.window = window,
|
||||
.title = std.mem.sliceTo(title, 0),
|
||||
.title = try allocator.dupeZ(u8, &title),
|
||||
.ctx = ctx,
|
||||
.program_id = try compileShaders(),
|
||||
.audio = Audio.init(apu),
|
||||
|
||||
.allocator = allocator,
|
||||
.state = try State.init(allocator),
|
||||
};
|
||||
}
|
||||
|
||||
pub fn deinit(self: *Self) void {
|
||||
self.audio.deinit();
|
||||
self.state.deinit();
|
||||
self.state.deinit(self.allocator);
|
||||
|
||||
zgui.backend.deinit();
|
||||
zgui.plot.deinit();
|
||||
|
@ -125,6 +122,8 @@ pub const Gui = struct {
|
|||
SDL.SDL_GL_DeleteContext(self.ctx);
|
||||
SDL.SDL_DestroyWindow(self.window);
|
||||
SDL.SDL_Quit();
|
||||
|
||||
self.allocator.free(self.title);
|
||||
self.* = undefined;
|
||||
}
|
||||
|
||||
|
@ -266,7 +265,7 @@ pub const Gui = struct {
|
|||
const w = @intToFloat(f32, gba_width * 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();
|
||||
|
||||
zgui.image(@intToPtr(*anyopaque, tex_id), .{ .w = w, .h = h, .uv0 = .{ 0, 1 }, .uv1 = .{ 1, 0 } });
|
||||
|
|
Loading…
Reference in New Issue