Simulation stimulation
SkoolKit 8.7 has been released. To get a copy, please head over to the download page, the Python Package Index, the Ubuntu PPA, or the Fedora copr repo.
The tradition in these release announcements is to start by listing the main new macros, commands, or parameters thereof that you can get your teeth sunk into. In this case, however, you may consider that tradition (slightly) bucked. The main bit of newness in version 8.7 is not a macro, or a command - or, indeed, a parameter thereof - but a Z80 instruction set simulator.
The question, then, is how this simulator has been applied to provide the new
and exciting features you’ve come to expect from a SkoolKit release. Well,
taking centre stage is the --sim-load
option of tap2sna.py
. It simulates
a freshly booted 48K ZX Spectrum running LOAD "" (or
LOAD ""CODE, if the first block on the tape is a ‘Bytes’ header). Which
means it’s now much easier to convert a TAP/TZX file into a pristine snapshot.
No more messing around with --ram load
, --ram poke
or any of the other
--ram
commands, and no more worrying about headerless blocks and turbo
loaders. Give --sim-load
a try and see how much cruft you can remove from
your t2s file.
Next, taking stage right, is the #AUDIO
macro. It converts a sequence of
delays between changes in the Spectrum’s speaker state into a WAV file, and
then presents it for playing via an HTML5 <audio>
element. But how does the
simulator fit into this picture? Good question. While you can provide the
sequence of delays manually, a much easier option is to use the simulator to
calculate them for you by running the code that produces the sound effect. For
example, here’s how you might create an <audio>
element that plays the theme
tune for Manic Miner:
#AUDIO4(blue-danube.wav)(34351,34358)
Now, taking stage left, is the #TSTATES
macro. As its name suggests, it
computes the number of T-states it takes to execute a single instruction or a
sequence of instructions. Where the simulator really helps here is if the code
you want to time is a loop, or contains conditional instructions with variable
timing. For example:
; This code creates a delay of #TSTATES(32768,32776,4) T-states.
32768 LD DE,0
*32771 DEC DE
32772 LD A,D
32773 OR E
32774 JR NZ,32771
And finally in the simulator department, what if none of the applications
described so far scratches your itch? In that case, perhaps the #SIM
macro
will help. Instead of executing Z80 machine code for the specific purpose of
loading a tape, calculating speaker flip delays, or timing instructions, it
just executes Z80 machine code and lets you do whatever you like with the
result - that result being changes to register values (available as replacement
fields in the sim
dictionary) or changes to the contents of the internal
memory snapshot constructed from the contents of the skool file. For example,
you could create an image of the Manic Miner title screen like this:
#SIM(start=34278,stop=34332)
#SCR
As for non-simulator-related new features, well, there are some, but they’re just not as interesting. If you really want to know what they are, you can consult the changelog. After that, why not take 8.7 for a spin and see what the simulator can do for you?