Would it be possible, and if so what would the approach be, to allow the Spectrum to talk to the emulator?
I have a particular usecase in mind: when the program I'm developing hits an assert() I want it to cause the emulator to dump the contents of the Spectrum's memory out to a file so I can inspect it using tools on Linux. Fuse has the memory dump feature (File->Save binary data) but it needs to be run manually which isn't too efficient in my usecase.
So I was thinking, could the assert() code running on the Spectrum's Z80 somehow signal to the emulator that something should happen? Ideally the "something" should be programmable or configurable, since I can see not everyone would want a memory dump.
From the lay perspective, it feels it should be possible to have the emulator "plug in to the Spectrum's edge connector" and act like a piece of hardware which can be written to or utilised. I don't know if this is practical, or whether there's another way which is easier?
We're actually quite close to this at the moment. If you start fuse with the
--debugger-command
option, you can pass something likeUnfortunately, "do stuff" doesn't yet support "save binary data" so this doesn't quite do what you want it to. It would be relatively easy to add that, but rather than making Fuse's debugger a fully featured scripting language, I'm looking at ways to call Python code on a breakpoint... watch this space.
OK, here we go :-)
PYTHONPATH=. ./fuse breakpoint.tap --debugger-command $'break 49153\nhook 1 1\nbreak 49154\nhook 2 1'
RUN
the not very complicated BASIC.To customize what happens, edit
debugger.py
- thebreakpoint
function will be called every time a Fuse breakpoint is hit with the ID of the breakpoint hit.This is obviously very much WIP at the moment, but I think it demonstrates what can be done relatively easily - extending this further isn't going to be hard.
Let me know if this is the sort of thing you're after.
[ Update 2018-06-28: no special arguments needing when configuring any more, now detected via autotools ]
[ Update 2018-06-30: need to explicitly enable Python hooks ]
[ Update 2018-07-02: file writing now needs to happen in Python, see
debugger.py
for example ]Last edit: Philip Kendall 2018-07-02
Goodness. I like your service... :)
That works a treat. In my game loop code I added this where I appear to have a problem:
then pick the address of the assert function from the compiler's map file with this:
I tweaked your little python script to dump the whole memory space (I use the ROM area for a trace table, which is the data I actually need) and, well, it just worked. For what I'm doing, that's going to be incredibly useful.
I looked at the code you've added and see that you appear to have used my request as a single getting-started sort of example. I guess the work now is to devise a generic interface for Python which will allow it to interact with the emulator in the way other people might find useful.