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
This commit is contained in:
Jeremy Penner 2024-01-01 21:27:33 -05:00
parent bd5553f7d9
commit c84c1c636d
3 changed files with 8 additions and 8 deletions

View file

@ -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. Run `make`. Assumes a POSIX-like environment. Works On My Machine, totally untested on anything besides Linux.
## Booting reno ## 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 ## 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 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

View file

@ -59,7 +59,7 @@ void sendAbsoluteSegments() {
readbytes(count); readbytes(count);
printf("Segment: %4x-%4x\n", start, end); printf("Segment: %4x-%4x\n", start, end);
down(buf, count, start); down(buf, count, start);
if (start == end) { if (start == end && entryPoint == 0) {
entryPoint = start; entryPoint = start;
} }
} }

View file

@ -39,7 +39,8 @@ local function fastlink(bytein, byteout)
end end
elseif command == 4 then -- jump elseif command == 4 then -- jump
local address = readword(bytein) local address = readword(bytein)
cpu.state["PC"].value = address -- cpu.state["PC"].value = address
emu.keypost("SYS" .. tostring(address) .. "\n")
else else
print("Unknown command: " .. tostring(command)) print("Unknown command: " .. tostring(command))
end end
@ -47,9 +48,8 @@ local function fastlink(bytein, byteout)
end end
local function is_booted() local function is_booted()
local cpu = manager.machine.devices[":u7"] -- wait for machine to be started, and allow 3 seconds for booting before accepting commands
local mem = cpu.spaces.program return manager.machine.time:as_double() > 3
return mem
end end
function exports.startplugin() function exports.startplugin()
@ -77,14 +77,14 @@ function exports.startplugin()
io.outfile:write(string.char(byte)) io.outfile:write(string.char(byte))
end end
print(coroutine.resume(link, bytein, byteout)) assert(coroutine.resume(link, bytein, byteout))
emu.register_periodic(function() emu.register_periodic(function()
if not is_booted() then return end if not is_booted() then return end
linkio.infile = io.open(infilename, "rb") linkio.infile = io.open(infilename, "rb")
if linkio.infile then if linkio.infile then
linkio.outfile = io.open(pendingfilename, "wb") linkio.outfile = io.open(pendingfilename, "wb")
print(coroutine.resume(link)) assert(coroutine.resume(link))
linkio.infile:close() linkio.infile:close()
linkio.infile = nil linkio.infile = nil
linkio.outfile:close() linkio.outfile:close()