The --sim-load challenge

The place for codemasters or beginners to talk about programming any language for the Spectrum.
Post Reply
User avatar
SkoolKid
Manic Miner
Posts: 407
Joined: Wed Nov 15, 2017 3:07 pm

The --sim-load challenge

Post by SkoolKid »

As some of you may recall from such forum topics as this one, in recent months I've been working on the --sim-load option of SkoolKit's tap2sna.py command, the idea being that producing a working pristine snapshot of a game should be as simple as:

Code: Select all

tap2sna.py --sim-load anygameyoulike.tzx game.z80
Things are going pretty well so far, and I can say without fear of contradiction that tap2sna.py in the upcoming SkoolKit 8.9 will be by far the best yet in terms of its --sim-load abilities. In a recent test I conducted of about 600 TZX files, tap2sna.py --sim-load managed to produce a working snapshot for over 95% of them.

But...having to test and check all the TZX and TAP files out there all by myself is a bit of a tall order, so this is where I'm putting a call out for some volunteers. If you have some time, could you pick a handful of games whose loaders might be a bit tricky, and run their TZX/TAP files through tap2sna.py --sim-load to see what happens? Then if you find a game that makes --sim-load choke, let me know in this thread, and I'll investigate.

Some tips before you get started:
  • Make sure you use tap2sna.py from the absolute latest development version of SkoolKit, available on GitHub. (Click the green "Code" button to download a zip archive if you don't have "git" installed.)
  • If a plain --sim-load doesn't work, try --sim-load --no-fast-load as well. If --no-fast-load works, that's useful information.
  • If you're ever curious about where --sim-load is going wrong (or right), try the --trace option, which logs all instructions that are executed during the simulated LOAD to a file (which may get very large - potentially hundreds of megabytes).
  • If you can, use Python 3.11 - it's the fastest version of Python 3 currently available, and will cut your --sim-load times significantly.
Good luck to any and all who accept the challenge!
SkoolKit - disassemble a game today
Pyskool - a remake of Skool Daze and Back to Skool
Stu
Manic Miner
Posts: 243
Joined: Wed May 20, 2020 2:59 pm

Re: The --sim-load challenge

Post by Stu »

Not really a fail as such, but to get Star Wars to work I had to make a new TZX without the first few blocks (which just displays some info and can be skipped over), so I don't know if there's any scope for a "start loading from block x" option? But once I did that it did at least work!

MASK on the other hand doesn't work at all -- as far as I can tell it resets fairly early on in the loading process.

Basil the Great Mouse Detective also fails.
User avatar
SkoolKid
Manic Miner
Posts: 407
Joined: Wed Nov 15, 2017 3:07 pm

Re: The --sim-load challenge

Post by SkoolKid »

Stu wrote: Wed Feb 01, 2023 12:05 am Not really a fail as such, but to get Star Wars to work I had to make a new TZX without the first few blocks (which just displays some info and can be skipped over), so I don't know if there's any scope for a "start loading from block x" option?
Yep, good idea - I will add that to the TODO list for SkoolKit 8.9.
Funnily enough, I just added support for that game today. It requires the polarity of the tape to be switched:

Code: Select all

tap2sna.py --sim-load -c polarity=1 'Basil The Great Mouse Detective.tzx' basil.z80
I think Mask might require the same polarity switch, but I haven't tested that yet.

Thanks for finding these!

By the way, one thing I forgot to mention in the first post is that I'm only looking at supporting 48K games at the moment. Support for 128K games may come later.
SkoolKit - disassemble a game today
Pyskool - a remake of Skool Daze and Back to Skool
Stu
Manic Miner
Posts: 243
Joined: Wed May 20, 2020 2:59 pm

Re: The --sim-load challenge

Post by Stu »

SkoolKid wrote: Wed Feb 01, 2023 1:34 am Funnily enough, I just added support for that game today. It requires the polarity of the tape to be switched:

Code: Select all

tap2sna.py --sim-load -c polarity=1 'Basil The Great Mouse Detective.tzx' basil.z80
I think Mask might require the same polarity switch, but I haven't tested that yet.
Nice one, just checked and yeah that does the trick for Mask as well :D
User avatar
TomD
Manic Miner
Posts: 379
Joined: Tue Nov 13, 2018 9:47 am
Location: Leeds UK
Contact:

Re: The --sim-load challenge

Post by TomD »

This is brilliant and great for getting good snapshots with loading screens in place for putting onto Microdrive or Disk. Just tried Bobby Bearing which has a scrolling message loader and it worked fine.

TomD
Retro enthusiast and author of Flynn's Adventure in Bombland, The Order of Mazes & Maze Death Rally-X. Check them out at http://tomdalby.com
User avatar
TomD
Manic Miner
Posts: 379
Joined: Tue Nov 13, 2018 9:47 am
Location: Leeds UK
Contact:

Re: The --sim-load challenge

Post by TomD »

Just tried Three Weeks in Paradise 128k version and it stalled. Does this support 128k?

TomD
Retro enthusiast and author of Flynn's Adventure in Bombland, The Order of Mazes & Maze Death Rally-X. Check them out at http://tomdalby.com
User avatar
SkoolKid
Manic Miner
Posts: 407
Joined: Wed Nov 15, 2017 3:07 pm

Re: The --sim-load challenge

Post by SkoolKid »

TomD wrote: Wed Feb 01, 2023 4:53 pm Just tried Three Weeks in Paradise 128k version and it stalled. Does this support 128k?
No, it's 48K only at the moment. I might add support for 128K later, depending on how complex simulating that hardware is. (I only ever had a 48K Spectrum, and know very little about the 128K models.)
SkoolKit - disassemble a game today
Pyskool - a remake of Skool Daze and Back to Skool
User avatar
TomD
Manic Miner
Posts: 379
Joined: Tue Nov 13, 2018 9:47 am
Location: Leeds UK
Contact:

Re: The --sim-load challenge

Post by TomD »

SkoolKid wrote: Wed Feb 01, 2023 5:26 pm No, it's 48K only at the moment. I might add support for 128K later, depending on how complex simulating that hardware is. (I only ever had a 48K Spectrum, and know very little about the 128K models.)
Thanks, I think it will mostly be capturing the bank switch outs so the correct memory page is loaded but that’s probably a slight simplification :-)

128k snapshots are great for supported multi load games like combat school as all in one load.
Retro enthusiast and author of Flynn's Adventure in Bombland, The Order of Mazes & Maze Death Rally-X. Check them out at http://tomdalby.com
User avatar
SkoolKid
Manic Miner
Posts: 407
Joined: Wed Nov 15, 2017 3:07 pm

Re: The --sim-load challenge

Post by SkoolKid »

As promised, I've implemented the --tape-start option, to effectively skip blocks at the start of a tape. For example:

Code: Select all

$ tap2sna.py --sim-load --tape-start 6 https://spectrumcomputing.co.uk/pub/sinclair/games/s/StarWarsV1.tzx.zip starwars.z80
Downloading https://spectrumcomputing.co.uk/pub/sinclair/games/s/StarWarsV1.tzx.zip
Extracting Star Wars - Release 1 - Side 1.tzx
Program: STAR WARS 
Fast loading data block: 23755,725
Data (66727 bytes)
Tape finished
Simulation stopped (end of tape): PC=56027
Writing starwars.z80
I've also removed the --accelerator, --no-fast-load, --no-pause and --trace options and made their functionality available via configuration parameters that can be set by the --sim-load-config (or -c) option, as documented here.

By the way, if anyone can find a tape that would benefit from (i.e. not work without) a --tape-end option (to effectively remove blocks from the tail end of the tape), let me know and I'll implement it.
SkoolKit - disassemble a game today
Pyskool - a remake of Skool Daze and Back to Skool
User avatar
SkoolKid
Manic Miner
Posts: 407
Joined: Wed Nov 15, 2017 3:07 pm

Re: The --sim-load challenge

Post by SkoolKid »

Apologies in advance to anyone who might have wanted to use --sim-load to produce a pristine snapshot of Gold Mine: It definitely won't work for the foreseeable future.

Why? Well, after the first CODE block has loaded, this line of BASIC is run:

Code: Select all

3 LET I=USR 23328: IF I<1200 OR I>3000 THEN RANDOMIZE USR O
And the code at 23328 listens for the pilot tone of the next block on the tape:

Code: Select all

23328 LD H,50       ; Detect 50 edges of the pilot tone.
23330 LD BC,0       ; BC will count the port readings.
23333 IN A,(254)    ; Take an initial port reading.
23335 LD L,A        ; Save the current port reading in L.
23336 IN A,(254)    ; Take another port reading.
23338 INC BC        ; Increment the counter.
23339 CP L          ; Detected an edge yet?
23340 JR Z,23336    ; If not, jump back to take another port reading.
23342 DEC H         ; Detected 50 edges yet?
23343 JR NZ,23335   ; Jump back if not.
23345 RET           ; Return to BASIC.
Now, the problem with this code is that it's resident in contended memory, the slowdown effects of which --sim-load does not simulate. So it returns to BASIC with BC=3208, which is too high a value, and triggers the RANDOMIZE USR O (where the variable O equals 0). Sad.

Not sure what anyone else thinks, but I think this is rather bad form on the part of Simon Goodwin to write code like this. If he had a shred of decency he'd release an updated version of Gold Mine without that weird pilot tone check so that everyone could --sim-load it to their heart's content. :D
SkoolKit - disassemble a game today
Pyskool - a remake of Skool Daze and Back to Skool
User avatar
SkoolKid
Manic Miner
Posts: 407
Joined: Wed Nov 15, 2017 3:07 pm

Re: The --sim-load challenge

Post by SkoolKid »

SkoolKid wrote: Sat Feb 04, 2023 4:34 pm Apologies in advance to anyone who might have wanted to use --sim-load to produce a pristine snapshot of Gold Mine: It definitely won't work for the foreseeable future.
Good news for anyone who might have wanted to use tap2sna.py to produce a pristine snapshot of Gold Mine from the original TZX: in SkoolKit 9.1 (currently under development), tap2sna.py can enable simulation of contended memory and I/O!

So now this t2s file will create the snapshot you've been waiting for:

Code: Select all

https://worldofspectrum.net/pub/sinclair/games/g/GoldMine.tzx.zip
--start 1343
--sim-load-config cmio=1
--sim-load-config first-edge=30000
--sim-load-config in-flags=1
--sim-load-config finish-tape=1
But it turns out that simulating contended memory and I/O isn't good just for Gold Mine: it also enables tap2sna.py to load the TZXs for 1999, Ceasefire, and Quadrados. :dance
SkoolKit - disassemble a game today
Pyskool - a remake of Skool Daze and Back to Skool
Post Reply