chore: improve init/deinit methods

This commit is contained in:
2022-08-29 00:32:41 -05:00
parent aa52bb5917
commit 5f8c6833f4
11 changed files with 100 additions and 79 deletions

View File

@@ -40,22 +40,20 @@ pub fn main() anyerror!void {
const paths = try handleArguments(allocator, &result);
defer if (paths.save) |path| allocator.free(path);
const log_file: ?std.fs.File = if (arm7tdmi_logging) try std.fs.cwd().createFile("zba.log", .{}) else null;
defer if (log_file) |file| file.close();
// TODO: Take Emulator Init Code out of main.zig
var scheduler = Scheduler.init(allocator);
defer scheduler.deinit();
var bus = try Bus.init(allocator, &scheduler, paths);
defer bus.deinit();
var arm7tdmi = Arm7tdmi.init(&scheduler, &bus);
const log_file: ?std.fs.File = if (arm7tdmi_logging) try std.fs.cwd().createFile("zba.log", .{}) else null;
defer if (log_file) |file| file.close();
if (log_file) |file| arm7tdmi.attach(file);
bus.attach(&arm7tdmi); // TODO: Shrink Surface (only CPSR and r15?)
var bus: Bus = undefined;
var arm7tdmi = Arm7tdmi.init(&scheduler, &bus, log_file);
if (paths.bios == null) arm7tdmi.fastBoot();
try bus.init(allocator, &scheduler, &arm7tdmi, paths);
defer bus.deinit();
var gui = Gui.init(bus.pak.title, width, height);
gui.initAudio(&bus.apu);
defer gui.deinit();