From c84c1c636d81320ad19c479374044e9727c4c273 Mon Sep 17 00:00:00 2001 From: Jeremy Penner Date: Mon, 1 Jan 2024 21:27:33 -0500 Subject: [PATCH] Make mamelink wait until the C64 has booted to begin accepting commands Fix detection of entry point Type "SYS" command to "jump" instead of modifying the program counter directly - arbitrary PC modification can sometimes lead to freezes Reduce console output spam --- mamelink/README.md | 2 +- mamelink/down.c | 2 +- mamelink/mameplugins/mamelink/init.lua | 12 ++++++------ 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/mamelink/README.md b/mamelink/README.md index 6c4e2b1..a004d42 100644 --- a/mamelink/README.md +++ b/mamelink/README.md @@ -5,7 +5,7 @@ A compatibility shim for Lucasfilm Games' "fastlink", using a MAME plugin to imp Run `make`. Assumes a POSIX-like environment. Works On My Machine, totally untested on anything besides Linux. ## Booting reno -Run `./start`. Assumes that `mame` is in the current path, with C64 ROMs installed. +Run `./start`. Assumes that `mame` is in the current path, with C64 ROMs installed. MAME will start, and you will probably need to press a key to start the emulated C64 booting. Once the C64 has completed startup, `reno` will automatically begin uploading, and when it is complete, you will see the command `SYS2122` automatically be entered into the emulator. After a few more seconds, Reno will start. ## How It Works It's a terrible, awful, very bad, no good hack, but it does the trick and should hopefully be portable, even to an enscripten-type browser environment. To send a command to the `mamelink` plugin, the `mamelink.c` library creates a file called `mameplugins/mamelink/linkin` with diff --git a/mamelink/down.c b/mamelink/down.c index 416bc41..de481cd 100644 --- a/mamelink/down.c +++ b/mamelink/down.c @@ -59,7 +59,7 @@ void sendAbsoluteSegments() { readbytes(count); printf("Segment: %4x-%4x\n", start, end); down(buf, count, start); - if (start == end) { + if (start == end && entryPoint == 0) { entryPoint = start; } } diff --git a/mamelink/mameplugins/mamelink/init.lua b/mamelink/mameplugins/mamelink/init.lua index 7ab5b01..01ead96 100644 --- a/mamelink/mameplugins/mamelink/init.lua +++ b/mamelink/mameplugins/mamelink/init.lua @@ -39,7 +39,8 @@ local function fastlink(bytein, byteout) end elseif command == 4 then -- jump local address = readword(bytein) - cpu.state["PC"].value = address + -- cpu.state["PC"].value = address + emu.keypost("SYS" .. tostring(address) .. "\n") else print("Unknown command: " .. tostring(command)) end @@ -47,9 +48,8 @@ local function fastlink(bytein, byteout) end local function is_booted() - local cpu = manager.machine.devices[":u7"] - local mem = cpu.spaces.program - return mem + -- wait for machine to be started, and allow 3 seconds for booting before accepting commands + return manager.machine.time:as_double() > 3 end function exports.startplugin() @@ -77,14 +77,14 @@ function exports.startplugin() io.outfile:write(string.char(byte)) end - print(coroutine.resume(link, bytein, byteout)) + assert(coroutine.resume(link, bytein, byteout)) emu.register_periodic(function() if not is_booted() then return end linkio.infile = io.open(infilename, "rb") if linkio.infile then linkio.outfile = io.open(pendingfilename, "wb") - print(coroutine.resume(link)) + assert(coroutine.resume(link)) linkio.infile:close() linkio.infile = nil linkio.outfile:close()