tmp: implement mechanisms for a emu reset fn (currently crashes)
This commit is contained in:
parent
3fff4fd742
commit
6ebd66eb3b
|
@ -314,6 +314,14 @@ pub const Arm7tdmi = struct {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME: Resetting disables logging (if enabled)
|
||||||
|
pub fn reset(self: *Self) void {
|
||||||
|
const bus_ptr = self.bus;
|
||||||
|
const scheduler_ptr = self.sched;
|
||||||
|
|
||||||
|
self.* = Self.init(scheduler_ptr, bus_ptr, null);
|
||||||
|
}
|
||||||
|
|
||||||
pub inline fn hasSPSR(self: *const Self) bool {
|
pub inline fn hasSPSR(self: *const Self) bool {
|
||||||
const mode = getModeChecked(self, self.cpsr.mode.read());
|
const mode = getModeChecked(self, self.cpsr.mode.read());
|
||||||
return switch (mode) {
|
return switch (mode) {
|
||||||
|
|
|
@ -222,3 +222,10 @@ pub const EmuThing = struct {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
pub fn reset(cpu: *Arm7tdmi) void {
|
||||||
|
@breakpoint();
|
||||||
|
cpu.sched.reset(); // Yes this is order sensitive, see the PPU reset for why
|
||||||
|
// cpu.bus.reset();
|
||||||
|
cpu.reset();
|
||||||
|
}
|
||||||
|
|
|
@ -11,11 +11,11 @@ const log = std.log.scoped(.Scheduler);
|
||||||
pub const Scheduler = struct {
|
pub const Scheduler = struct {
|
||||||
const Self = @This();
|
const Self = @This();
|
||||||
|
|
||||||
tick: u64,
|
tick: u64 = 0,
|
||||||
queue: PriorityQueue(Event, void, lessThan),
|
queue: PriorityQueue(Event, void, lessThan),
|
||||||
|
|
||||||
pub fn init(allocator: Allocator) Self {
|
pub fn init(allocator: Allocator) Self {
|
||||||
var sched = Self{ .tick = 0, .queue = PriorityQueue(Event, void, lessThan).init(allocator, {}) };
|
var sched = Self{ .queue = PriorityQueue(Event, void, lessThan).init(allocator, {}) };
|
||||||
sched.queue.add(.{ .kind = .HeatDeath, .tick = std.math.maxInt(u64) }) catch unreachable;
|
sched.queue.add(.{ .kind = .HeatDeath, .tick = std.math.maxInt(u64) }) catch unreachable;
|
||||||
|
|
||||||
return sched;
|
return sched;
|
||||||
|
@ -26,6 +26,17 @@ pub const Scheduler = struct {
|
||||||
self.* = undefined;
|
self.* = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn reset(self: *Self) void {
|
||||||
|
// `std.PriorityQueue` provides no reset function, so we will just create a new one
|
||||||
|
const allocator = self.queue.allocator;
|
||||||
|
self.queue.deinit();
|
||||||
|
|
||||||
|
var new_queue = PriorityQueue(Event, void, lessThan).init(allocator, {});
|
||||||
|
new_queue.add(.{ .kind = .HeatDeath, .tick = std.math.maxInt(u64) }) catch unreachable;
|
||||||
|
|
||||||
|
self.* = .{ .queue = new_queue };
|
||||||
|
}
|
||||||
|
|
||||||
pub inline fn now(self: *const Self) u64 {
|
pub inline fn now(self: *const Self) u64 {
|
||||||
return self.tick;
|
return self.tick;
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +48,7 @@ pub const State = struct {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn draw(state: *State, tex_id: GLuint, cpu: *const Arm7tdmi) void {
|
pub fn draw(state: *State, tex_id: GLuint, cpu: *Arm7tdmi) void {
|
||||||
const win_scale = config.config().host.win_scale;
|
const win_scale = config.config().host.win_scale;
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -77,7 +77,10 @@ pub fn draw(state: *State, tex_id: GLuint, cpu: *const Arm7tdmi) void {
|
||||||
if (zgui.beginMenu("Emulation", true)) {
|
if (zgui.beginMenu("Emulation", true)) {
|
||||||
defer zgui.endMenu();
|
defer zgui.endMenu();
|
||||||
|
|
||||||
if (zgui.menuItem("Restart", .{})) log.warn("TODO: Restart Emulator", .{});
|
if (zgui.menuItem("Restart", .{})) {
|
||||||
|
@breakpoint();
|
||||||
|
emu.reset(cpu);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue