Tape Loader vs Key Scanner detection

Struggling with Fuse or trying to find an emulator with a specific feature. Ask your questions here.
Post Reply
User avatar
Lethargeek
Manic Miner
Posts: 743
Joined: Wed Dec 11, 2019 6:47 am

Tape Loader vs Key Scanner detection

Post by Lethargeek »

As we know, Spectrum has reads tape and keyboard from the same port (any even number, traditionally #FE). This can be a problem if you're an emulator author and you want to implement a fast loader or just tape autostart/autostop in your emulator. So you need to know what these few last INs were reading, keyboard or the tape input. To keep things simple, let's talk first about the tap format with well known signal durations. Sure, there are clear cases when the time between some INs was too long - this is definitely a sign of a keyboard/joystick scanning routine and not a loader. But what about multiload games asking user to stop the tape and then immediately polling port #FE in a tight loop waiting for any key? My first thought was to look if the interrupts were enabled, but it turned out that even the loaders with interrupts enabled do exist, and OTOH key scanner routines do not necessarily enable the interrupts until a keypress is detected. And yet some emulators are able to stop the tape at the right moment nevertheless. So is there a simple rule? I'm especially interested in the answer of [mention]ZXDunny[/mention] , how it is done in ZXSpin?
User avatar
Lethargeek
Manic Miner
Posts: 743
Joined: Wed Dec 11, 2019 6:47 am

Re: Tape Loader vs Key Scanner detection

Post by Lethargeek »

Well, since nobody (anyw)here can't seem to help me, and any detection method on a shared port is inherently unreliable anyway, for now i've decided maybe it's better to autopause the emulator instead of autostopping the tape, letting the user to judge if the tape has to be stopped at this point or the tricky loader may continue.
User avatar
ZXDunny
Manic Miner
Posts: 498
Joined: Tue Nov 14, 2017 3:45 pm

Re: Tape Loader vs Key Scanner detection

Post by ZXDunny »

There are certain patterns you can look for - commonly, a tight INC B is used. If that's near an IN on a ULA port, you can be reasonably certain that it's a tape loader. There are other code patterns you can look for though.

Edit 2: Some TZX files also contain "tape stop here" blocks which can kinda give the game away.

Edit: Using @<nickname> doesn't do anything btw.
User avatar
Lethargeek
Manic Miner
Posts: 743
Joined: Wed Dec 11, 2019 6:47 am

Re: Tape Loader vs Key Scanner detection

Post by Lethargeek »

ZXDunny wrote: Thu Jan 30, 2020 12:20 pm There are certain patterns you can look for - commonly, a tight INC B is used. If that's near an IN on a ULA port, you can be reasonably certain that it's a tape loader. There are other code patterns you can look for though.
ouch, i hoped for something simpler and independent from the actual code :(
so far i'm using "tight INs" counter, iff1 and "long time from the last IN" in the DATA state
only the latter one is a clear case

well, thanks for the answer anyway! :)
ZXDunny wrote: Thu Jan 30, 2020 12:20 pm Edit 2: Some TZX files also contain "tape stop here" blocks which can kinda give the game away.
sadly, i'm still far from the tzx support
ZXDunny wrote: Thu Jan 30, 2020 12:20 pm Edit: Using @<nickname> doesn't do anything btw.
but... but it places the mention tag around and paints the nickname a pretty color :D
Post Reply