chore: rename consturctors to fit convention

This commit is contained in:
Rekai Nyangadzayi Musuka 2022-01-02 13:58:57 -06:00
parent f09f814dc3
commit 01d6399dfb
6 changed files with 10 additions and 10 deletions

View File

@ -8,11 +8,11 @@ pub const Bus = struct {
pak: GamePak,
bios: Bios,
pub fn withPak(alloc: Allocator, path: []const u8) !@This() {
pub fn init(alloc: Allocator, path: []const u8) !@This() {
return @This(){
.pak = try GamePak.fromPath(alloc, path),
.pak = try GamePak.init(alloc, path),
// TODO: don't hardcode this + bundle open-sorce Boot ROM
.bios = try Bios.fromPath(alloc, "./bin/gba_bios.bin"),
.bios = try Bios.init(alloc, "./bin/gba_bios.bin"),
};
}

View File

@ -5,7 +5,7 @@ const Allocator = std.mem.Allocator;
pub const Bios = struct {
buf: []u8,
pub fn fromPath(alloc: Allocator, path: []const u8) !@This() {
pub fn init(alloc: Allocator, path: []const u8) !@This() {
const file = try std.fs.cwd().openFile(path, .{ .read = true });
defer file.close();

View File

@ -5,7 +5,7 @@ const Allocator = std.mem.Allocator;
pub const GamePak = struct {
buf: []u8,
pub fn fromPath(alloc: Allocator, path: []const u8) !@This() {
pub fn init(alloc: Allocator, path: []const u8) !@This() {
const file = try std.fs.cwd().openFile(path, .{ .read = true });
defer file.close();

View File

@ -20,7 +20,7 @@ pub const Arm7tdmi = struct {
bus: *Bus,
cpsr: CPSR,
pub fn new(scheduler: *Scheduler, bus: *Bus) @This() {
pub fn init(scheduler: *Scheduler, bus: *Bus) @This() {
return .{
.r = [_]u32{0x00} ** 16,
.sch = scheduler,

View File

@ -23,9 +23,9 @@ pub fn main() anyerror!void {
return;
}
var bus = try Bus.withPak(alloc, zba_args[0]);
var scheduler = Scheduler.new(alloc);
var cpu = Arm7tdmi.new(&scheduler, &bus);
var bus = try Bus.init(alloc, zba_args[0]);
var scheduler = Scheduler.init(alloc);
var cpu = Arm7tdmi.init(&scheduler, &bus);
while (true) {
emu.runFrame(&scheduler, &cpu, &bus);

View File

@ -10,7 +10,7 @@ pub const Scheduler = struct {
tick: u64,
queue: PriorityQueue(Event, void, lessThan),
pub fn new(alloc: Allocator) @This() {
pub fn init(alloc: Allocator) @This() {
var scheduler = Scheduler{ .tick = 0, .queue = PriorityQueue(Event, void, lessThan).init(alloc, {}) };
scheduler.queue.add(.{