From 29eb97170cf9f87f6695bfeff8d964f1fa7ed6d4 Mon Sep 17 00:00:00 2001 From: Andre Weissflog Date: Fri, 12 Jul 2024 13:39:38 +0200 Subject: [PATCH] add a Z80.init function --- src/chips/z80.zig | 4 ++++ src/systems/bombjack.zig | 4 ++-- src/systems/namco.zig | 2 +- tests/z80int.zig | 2 +- tests/z80test.zig | 2 +- tests/z80timing.zig | 2 +- tests/z80zex.zig | 2 +- 7 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/chips/z80.zig b/src/chips/z80.zig index f25f152..c7cf9ed 100644 --- a/src/chips/z80.zig +++ b/src/chips/z80.zig @@ -174,6 +174,10 @@ pub fn Z80(comptime P: Pins, comptime Bus: anytype) type { de2: u16 = 0xFFFF, hl2: u16 = 0xFFFF, + pub fn init() Self { + return .{}; + } + pub fn prefetch(self: *Self, addr: u16) void { self.pc = addr; self.step = 0; diff --git a/src/systems/bombjack.zig b/src/systems/bombjack.zig index ae46141..0af1409 100644 --- a/src/systems/bombjack.zig +++ b/src/systems/bombjack.zig @@ -269,7 +269,7 @@ pub const Bombjack = struct { pub fn initInPlace(self: *Self, opts: Options) void { self.* = .{ .main_board = .{ - .cpu = .{}, + .cpu = Z80.init(), .vsync_count = VSYNC_PERIOD_4MHZ, .mem = Memory.init(.{ .junk_page = &self.junk_page, @@ -278,7 +278,7 @@ pub const Bombjack = struct { .palette = std.mem.zeroes(@TypeOf(self.main_board.palette)), }, .sound_board = .{ - .cpu = .{}, + .cpu = Z80.init(), .psg0 = Psg0.init(.{ .tick_hz = PSG_FREQUENCY, .sound_hz = @intCast(opts.audio.sample_rate), diff --git a/src/systems/namco.zig b/src/systems/namco.zig index b5aa478..9a14f90 100644 --- a/src/systems/namco.zig +++ b/src/systems/namco.zig @@ -430,7 +430,7 @@ pub fn Namco(comptime sys: System) type { pub fn initInPlace(self: *Self, opts: Options) void { self.* = .{ - .cpu = .{}, + .cpu = Z80.init(), .mem = Memory.init(.{ .junk_page = &self.junk_page, .unmapped_page = &self.unmapped_page, diff --git a/tests/z80int.zig b/tests/z80int.zig index 5fda0d5..cf2f6b2 100644 --- a/tests/z80int.zig +++ b/tests/z80int.zig @@ -75,7 +75,7 @@ fn copy(start_addr: u16, bytes: []const u8) void { fn init(start_addr: u16, bytes: []const u8) void { mem = std.mem.zeroes(@TypeOf(mem)); bus = 0; - cpu = Z80{}; + cpu = Z80.init(); copy(start_addr, bytes); cpu.prefetch(start_addr); } diff --git a/tests/z80test.zig b/tests/z80test.zig index df632dd..0523142 100644 --- a/tests/z80test.zig +++ b/tests/z80test.zig @@ -56,7 +56,7 @@ fn ok() void { fn init(start_addr: u16, bytes: []const u8) void { mem = std.mem.zeroes(@TypeOf(mem)); bus = 0; - cpu = Z80{}; + cpu = Z80.init(); cpu.r[Z80.F] = 0; cpu.af2 = 0xFF00; cpu.bc2 = 0xFFFF; diff --git a/tests/z80timing.zig b/tests/z80timing.zig index 96d7924..9644623 100644 --- a/tests/z80timing.zig +++ b/tests/z80timing.zig @@ -151,7 +151,7 @@ fn copy(start_addr: u16, bytes: []const u8) void { fn init(bytes: []const u8) void { mem = std.mem.zeroes(@TypeOf(mem)); bus = 0; - cpu = Z80{}; + cpu = Z80.init(); copy(0, bytes); cpu.prefetch(0); } diff --git a/tests/z80zex.zig b/tests/z80zex.zig index 4203213..51962ac 100644 --- a/tests/z80zex.zig +++ b/tests/z80zex.zig @@ -71,7 +71,7 @@ fn cpmBDOS() void { // run the currently configured test fn runTest() u64 { - cpu = Z80{}; + cpu = Z80.init(); cpu.setSP(0xF000); cpu.prefetch(0x0100); const bdos_call: Bus = Z80.setAddr(M1 | MREQ | RD, 0x0005);