Add a GUI to ZBA #7

Merged
paoda merged 24 commits from imgui into main 2023-03-11 03:18:15 +00:00
7 changed files with 51 additions and 9 deletions
Showing only changes of commit f8477714ae - Show all commits

View File

@ -104,7 +104,7 @@ pub fn deinit(self: *Self) void {
pub fn reset(self: *Self) void { pub fn reset(self: *Self) void {
self.bios.reset(); self.bios.reset();
// TODO: deinit ppu self.ppu.reset();
self.apu.reset(); self.apu.reset();
self.iwram.reset(); self.iwram.reset();
self.ewram.reset(); self.ewram.reset();

View File

@ -278,16 +278,20 @@ pub const Apu = struct {
.is_buffer_full = false, .is_buffer_full = false,
}; };
sched.push(.SampleAudio, apu.interval()); Self.initEvents(apu.sched, apu.interval());
sched.push(.{ .ApuChannel = 0 }, @import("apu/signal/Square.zig").interval);
sched.push(.{ .ApuChannel = 1 }, @import("apu/signal/Square.zig").interval);
sched.push(.{ .ApuChannel = 2 }, @import("apu/signal/Wave.zig").interval);
sched.push(.{ .ApuChannel = 3 }, @import("apu/signal/Lfsr.zig").interval);
sched.push(.FrameSequencer, FrameSequencer.interval);
return apu; return apu;
} }
fn initEvents(scheduler: *Scheduler, apu_interval: u64) void {
scheduler.push(.SampleAudio, apu_interval);
scheduler.push(.{ .ApuChannel = 0 }, @import("apu/signal/Square.zig").interval);
scheduler.push(.{ .ApuChannel = 1 }, @import("apu/signal/Square.zig").interval);
scheduler.push(.{ .ApuChannel = 2 }, @import("apu/signal/Wave.zig").interval);
scheduler.push(.{ .ApuChannel = 3 }, @import("apu/signal/Lfsr.zig").interval);
scheduler.push(.FrameSequencer, FrameSequencer.interval);
}
/// Used when resetting the emulator /// Used when resetting the emulator
pub fn reset(self: *Self) void { pub fn reset(self: *Self) void {
// FIXME: These reset functions are meant to emulate obscure APU behaviour. Write proper emu reset fns // FIXME: These reset functions are meant to emulate obscure APU behaviour. Write proper emu reset fns
@ -306,6 +310,8 @@ pub const Apu = struct {
self.sampling_cycle = 0; self.sampling_cycle = 0;
self.fs.reset(); self.fs.reset();
Self.initEvents(self.sched, self.interval());
} }
/// Emulates the reset behaviour of the APU /// Emulates the reset behaviour of the APU

View File

@ -290,6 +290,26 @@ pub const Ppu = struct {
}; };
} }
pub fn reset(self: *Self) void {
self.sched.push(.Draw, 240 * 4);
self.vram.reset();
self.palette.reset();
self.oam.reset();
self.framebuf.reset();
self.win = Window.init();
self.bg = [_]Background{Background.init()} ** 4;
self.aff_bg = [_]AffineBackground{AffineBackground.init()} ** 2;
self.bld = Blend.create();
self.dispcnt = .{ .raw = 0x0000 };
self.dispstat = .{ .raw = 0x0000 };
self.vcount = .{ .raw = 0x0000 };
self.scanline.reset();
std.mem.set(?Sprite, self.scanline_sprites, null);
}
pub fn deinit(self: *Self) void { pub fn deinit(self: *Self) void {
self.allocator.destroy(self.scanline_sprites); self.allocator.destroy(self.scanline_sprites);
self.framebuf.deinit(); self.framebuf.deinit();

View File

@ -34,6 +34,10 @@ pub fn init(allocator: Allocator) !Self {
return Self{ .buf = buf, .allocator = allocator }; return Self{ .buf = buf, .allocator = allocator };
} }
pub fn reset(self: *Self) void {
std.mem.set(u8, self.buf, 0);
}
pub fn deinit(self: *Self) void { pub fn deinit(self: *Self) void {
self.allocator.free(self.buf); self.allocator.free(self.buf);
self.* = undefined; self.* = undefined;

View File

@ -37,6 +37,10 @@ pub fn init(allocator: Allocator) !Self {
return Self{ .buf = buf, .allocator = allocator }; return Self{ .buf = buf, .allocator = allocator };
} }
pub fn reset(self: *Self) void {
std.mem.set(u8, self.buf, 0);
}
pub fn deinit(self: *Self) void { pub fn deinit(self: *Self) void {
self.allocator.free(self.buf); self.allocator.free(self.buf);
self.* = undefined; self.* = undefined;

View File

@ -45,6 +45,10 @@ pub fn init(allocator: Allocator) !Self {
return Self{ .buf = buf, .allocator = allocator }; return Self{ .buf = buf, .allocator = allocator };
} }
pub fn reset(self: *Self) void {
std.mem.set(u8, self.buf, 0);
}
pub fn deinit(self: *Self) void { pub fn deinit(self: *Self) void {
self.allocator.free(self.buf); self.allocator.free(self.buf);
self.* = undefined; self.* = undefined;

View File

@ -251,7 +251,7 @@ pub const FrameBuffer = struct {
layers: [2][]u8, layers: [2][]u8,
buf: []u8, buf: []u8,
current: u1, current: u1 = 0,
allocator: Allocator, allocator: Allocator,
@ -266,12 +266,16 @@ pub const FrameBuffer = struct {
// Front and Back Framebuffers // Front and Back Framebuffers
.layers = [_][]u8{ buf[0..][0..len], buf[len..][0..len] }, .layers = [_][]u8{ buf[0..][0..len], buf[len..][0..len] },
.buf = buf, .buf = buf,
.current = 0,
.allocator = allocator, .allocator = allocator,
}; };
} }
pub fn reset(self: *Self) void {
std.mem.set(u8, self.buf, 0);
self.current = 0;
}
pub fn deinit(self: *Self) void { pub fn deinit(self: *Self) void {
self.allocator.free(self.buf); self.allocator.free(self.buf);
self.* = undefined; self.* = undefined;