From eed98067d0e42b2d7a812e25c48fa482cc969b37 Mon Sep 17 00:00:00 2001 From: Andre Weissflog Date: Fri, 9 Aug 2024 18:21:45 +0200 Subject: [PATCH] kc85 implement patch callback --- emus/kc85/kc85.zig | 26 ++++++++++++++++++++++++-- src/systems/kc85.zig | 1 - 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/emus/kc85/kc85.zig b/emus/kc85/kc85.zig index ad894dc..2e2a747 100644 --- a/emus/kc85/kc85.zig +++ b/emus/kc85/kc85.zig @@ -87,8 +87,7 @@ export fn frame() void { }); if (file_loaded.once()) { if (args.file_data) |file_data| { - // FIXME: patch-func - sys.load(.{ .data = file_data, .start = true, .patch = null }) catch |err| { + sys.load(.{ .data = file_data, .start = true, .patch = .{ .func = patch } }) catch |err| { print("Failed to load file into emulator with {}", .{err}); }; } @@ -196,6 +195,29 @@ pub fn main() void { }); } +// game patcher callback +fn patch(image_name: []const u8, userdata: usize) void { + _ = userdata; + if (std.mem.startsWith(u8, image_name, "JUNGLE ")) { + // patch start level 1 into memory + sys.mem.wr(0x36B7, 1); + sys.mem.wr(0x3697, 1); + for (0..5) |idx| { + const idx16: u16 = @truncate(idx); + const b = sys.mem.rd(0x36B6 +% idx16); + sys.mem.wr(0x1770 +% idx16, b); + } + } else if (std.mem.startsWith(u8, image_name, "DIGGER COM\x01")) { + // time for delay loop 0x0160 instead of 0x0260 + sys.mem.wr16(0x09AA, 0x0160); + // OR L instead of OR (HL) + sys.mem.wr(0x3D3A, 0xB5); + } else if (std.mem.startsWith(u8, image_name, "DIGGERJ")) { + sys.mem.wr16(0x09AA, 0x0260); // not a bug + sys.mem.wr(0x3D3A, 0xB5); + } +} + // command line args const Args = struct { const Module = struct { diff --git a/src/systems/kc85.zig b/src/systems/kc85.zig index cb3764b..4d63351 100644 --- a/src/systems/kc85.zig +++ b/src/systems/kc85.zig @@ -105,7 +105,6 @@ pub fn Type(comptime model: Model) type { // runtime options pub const Options = struct { audio: Audio.Options, - // FIXME: patch callback roms: switch (model) { .KC852 => struct { caos22: []const u8,