Skip to content

Commit

Permalink
add a Z80.init function
Browse files Browse the repository at this point in the history
  • Loading branch information
floooh committed Jul 12, 2024
1 parent df5e8e7 commit 29eb971
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 7 deletions.
4 changes: 4 additions & 0 deletions src/chips/z80.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/systems/bombjack.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion src/systems/namco.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion tests/z80int.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/z80test.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion tests/z80timing.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/z80zex.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 29eb971

Please sign in to comment.