Loading routine "cores": Difference between revisions

From Sinclair Wiki
Jump to navigation Jump to search
(Document ROM and Speedlock core loops.)
 
No edit summary
(9 intermediate revisions by the same user not shown)
Line 35: Line 35:


This is essentially identical to the ROM loader, but just without the <code>RET NC</code> which aborts if space is pressed during the ROM loading routine.
This is essentially identical to the ROM loader, but just without the <code>RET NC</code> which aborts if space is pressed during the ROM loading routine.
=== Alkatraz ===
The Alkatraz loader, used in games like [https://spectrumcomputing.co.uk/index.php?cat=96&id=41 720&deg;] and [https://spectrumcomputing.co.uk/index.php?cat=96&id=996 Cobra].
LD-SAMPLE  INC B
            JR NZ,LD-SAMPLE2
            JP <somewhere else>
LD-SAMPLE2 IN A,(FE)
            RRA
            RET Z
            XOR C
            AND 20
            JR Z,LD-SAMPLE
This again isn't that different from the ROM loader; the minor changes are:
* Inverting the "no edge found" condition
* Using a <code>JP</code> if an edge is not found rather than a <code>RET</code>
* Not setting the high byte of the <code>IN</code> - this isn't critical as it affects only which keyboard half-rows are scanned
* Replacing the RET NC with a RET Z. I ''think'' this makes it essentially a no-op unless lots of keys are pressed at once.
==== "Variant" Alkatraz ====
A very close variant of the Alkatraz loader, seen only in three late era Spectrum games: [https://spectrumcomputing.co.uk/index.php?cat=96&id=1993 Gauntlet III], [https://spectrumcomputing.co.uk/index.php?cat=96&id=3567 Out Run Europa] and [https://spectrumcomputing.co.uk/index.php?cat=96&id=4421 Shadow Dancer].
LD-SAMPLE  INC B
            JR NZ,LD-SAMPLE2
            RET
LD-SAMPLE2 IN A,(FE)
            RRA
            RET Z
            XOR C
            AND 20
            JR Z,LD-SAMPLE
This actually makes the Alkatraz routine closer to the original ROM code as it now uses a <code>RET</code> to exit in the "no edge found" case.
=== Bleepload ===
The [http://birdsanctuary.co.uk/bleepload/ Bleepload] routine, used in lots of Firebird games, for example [https://spectrumcomputing.co.uk/index.php?cat=96&id=722 Bubble Bobble] and [https://spectrumcomputing.co.uk/index.php?cat=96&id=4867 Starglider 2].
LD-SAMPLE  INC B
            RET Z
            LD A,7F
            IN A,(FE)
            RRA
            NOP
            XOR C
            AND 20
            JR Z,LD-SAMPLE
This is just the ROM routine, but with the "space pressed" check explicitly replaced with a <code>NOP</code>.
=== Microsphere ===
Used in a few Microsphere games, for instance [https://spectrumcomputing.co.uk/index.php?cat=96&id=1055 Contact Sam Cruise] and [https://spectrumcomputing.co.uk/index.php?cat=96&id=4549 Skool Daze].
LD-SAMPLE  INC B
            RET Z
            LD A,7F
            IN A,(FE)
            RRA
            AND A
            XOR C
            AND 20
            JR Z,LD-SAMPLE
Another very close variant on the ROM loader, this time replacing the <code>RET NC</code> with the <code>NOP</code>-equivalent <code>AND A</code>.
=== Paul Owens ===
Used in some Ocean games, for example [https://spectrumcomputing.co.uk/index.php?cat=96&id=903 Chase H.Q.].
LD-SAMPLE  INC B
            RET Z
            LD A,7F
            IN A,(FE)
            RRA
            RET Z
            XOR C
            AND 20
            JR Z,LD-SAMPLE
Again just a one-byte change from the ROM loader, replacing the <code>RET NC</code> with Alkatraz's <code>RET Z</code>.
=== Dinaload ===
Used by Dinamic, for example in [https://spectrumcomputing.co.uk/index.php?cat=96&id=295 Astro Marine Corps] and [https://spectrumcomputing.co.uk/index.php?cat=96&id=1863 Freddy Hardest en Manhattan Sur].
LD-SAMPLE  INC B
            RET Z
            LD A,FF
            IN A,(FE)
            RRA
            RET NC
            XOR C
            AND 20
            JR Z,LD-SAMPLE
Yet another one-byte change from the ROM loader, this time ensuring that no keyboard half-rows are read, meaning the <code>RET NC</code> will never trigger.
=== Search Loader ===
Used in [https://spectrumcomputing.co.uk/index.php?cat=96&id=584 Blood Brothers] and [https://spectrumcomputing.co.uk/index.php?cat=96&id=978 City Slicker].
LD-SAMPLE  INC B
            RET Z
            LD A,00
            IN A,(FE)
            XOR C
            AND 40
            RET C
            NOP
            JR Z,LD-SAMPLE
The first loader which is actually non-trivially different from the ROM loader. The changes here:
* Setting the high byte of the <code>IN</code> to be zero - this causes every keyboard half-row to be read. This is unimportant as all five low bits are masked out later.
* Dropping the <code>RRA</code> of the ROM loader - as we're not checking for any keys being pressed, no need to shift the byte around. This means the EAR bit stays in bit 6 rather than being shifted to bit 5 so the <code>AND</code> changes as well.
* The <code>RET C</code> is a no-op as <code>AND</code> explicitly clears the carry flag.
This code has fairly obviously been constructed to have exactly the same runtime as the ROM code, which explains the always failing <code>RET C</code> and <code>NOP</code> (which replaces the <code>RRA</code> of the ROM routine). All the variants which replace the <code>RET NC</code> with a <code>NOP</code> or similar actually have a different runtime as a failing conditional <code>RET</code> is the ''only'' Z80 instruction which takes 5 t-states.
==== "Variant" Search Loader ====
Used by some late era Gremlin games; so far seen only in [https://spectrumcomputing.co.uk/index.php?cat=96&id=2937 Lotus Esprit Turbo Challenge] and [https://spectrumcomputing.co.uk/index.php?cat=96&id=4660 Space Crusade].
LD-SAMPLE  INC B
            RET Z
            LD A,7F
            IN A,(FE)
            XOR C
            AND 40
            JR Z,LD-SAMPLE
While this maintains the distinctive <code>AND 40</code> of the Search Loader, I suspect it's actually an independent derivation.
=== Digital Integration ===
Unsurprisingly enough, used by Digital Integration in some of their games, for example [https://spectrumcomputing.co.uk/index.php?cat=96&id=305 ATF] and [https://spectrumcomputing.co.uk/index.php?cat=96&id=5317 Tomahawk].
LD-SAMPLE  DEC B
            RET Z
            IN A,(FE)
            XOR C
            AND 40
            JP Z,LD-SAMPLE
This loader has two points of note: it inverts the counter (which just requires the flip of a condition outside this loop when working out whether it's a long or short pulse), and it's probably the minimal loop which is possible while still being anything even vaguely similar to the ROM loader.
== Emulation ==
[http://fuse-emulator.sourceforge.net/ Fuse] pattern matches for the above cores to implement its "accelerate loaders" feature.

Revision as of 21:38, 28 July 2018

This page documents the "core" of the loading routine used in the various turboloaders: the part of the loader which actually finds an edge from the tape.

ROM loader

The basis for every loading routine out there, this is the one found in the Spectrum ROM (at 05ED). The LD-SAMPLE name is taken from Logan and O'Hara's The Complete Spectrum ROM Disassembly.

LD-SAMPLE  INC B
           RET Z
           LD A,7F
           IN A,(FE)
           RRA
           RET NC
           XOR C
           AND 20
           JR Z,LD-SAMPLE

This routine is used unchanged (just copied elsewhere in memory) by a large number of turboloaders, for example Cybernoid and Dan Dare.

Turboloaders

The names given to each of these loading routines are not meant to imply that loaders was the first to use the specific loading loop; it is the most common usage of the loading loop, or just the first place that it was seen by the authors of this page.

Speedlock

The Speedlock loader, used in huge numbers of games, for example Daley Thompson's Decathlon and Head over Heels.

LD-SAMPLE  INC B
           RET Z
           LD A,7F
           IN A,(FE)
           RRA
           XOR C
           AND 20
           JR Z,LD-SAMPLE

This is essentially identical to the ROM loader, but just without the RET NC which aborts if space is pressed during the ROM loading routine.

Alkatraz

The Alkatraz loader, used in games like 720° and Cobra.

LD-SAMPLE  INC B
           JR NZ,LD-SAMPLE2
           JP <somewhere else>
LD-SAMPLE2 IN A,(FE)
           RRA
           RET Z
           XOR C
           AND 20
           JR Z,LD-SAMPLE

This again isn't that different from the ROM loader; the minor changes are:

  • Inverting the "no edge found" condition
  • Using a JP if an edge is not found rather than a RET
  • Not setting the high byte of the IN - this isn't critical as it affects only which keyboard half-rows are scanned
  • Replacing the RET NC with a RET Z. I think this makes it essentially a no-op unless lots of keys are pressed at once.

"Variant" Alkatraz

A very close variant of the Alkatraz loader, seen only in three late era Spectrum games: Gauntlet III, Out Run Europa and Shadow Dancer.

LD-SAMPLE  INC B
           JR NZ,LD-SAMPLE2
           RET
LD-SAMPLE2 IN A,(FE)
           RRA
           RET Z
           XOR C
           AND 20
           JR Z,LD-SAMPLE

This actually makes the Alkatraz routine closer to the original ROM code as it now uses a RET to exit in the "no edge found" case.

Bleepload

The Bleepload routine, used in lots of Firebird games, for example Bubble Bobble and Starglider 2.

LD-SAMPLE  INC B
           RET Z
           LD A,7F
           IN A,(FE)
           RRA
           NOP
           XOR C
           AND 20
           JR Z,LD-SAMPLE

This is just the ROM routine, but with the "space pressed" check explicitly replaced with a NOP.

Microsphere

Used in a few Microsphere games, for instance Contact Sam Cruise and Skool Daze.

LD-SAMPLE  INC B
           RET Z
           LD A,7F
           IN A,(FE)
           RRA
           AND A
           XOR C
           AND 20
           JR Z,LD-SAMPLE

Another very close variant on the ROM loader, this time replacing the RET NC with the NOP-equivalent AND A.

Paul Owens

Used in some Ocean games, for example Chase H.Q..

LD-SAMPLE  INC B
           RET Z
           LD A,7F
           IN A,(FE)
           RRA
           RET Z
           XOR C
           AND 20
           JR Z,LD-SAMPLE

Again just a one-byte change from the ROM loader, replacing the RET NC with Alkatraz's RET Z.

Dinaload

Used by Dinamic, for example in Astro Marine Corps and Freddy Hardest en Manhattan Sur.

LD-SAMPLE  INC B
           RET Z
           LD A,FF
           IN A,(FE)
           RRA
           RET NC
           XOR C
           AND 20
           JR Z,LD-SAMPLE

Yet another one-byte change from the ROM loader, this time ensuring that no keyboard half-rows are read, meaning the RET NC will never trigger.

Search Loader

Used in Blood Brothers and City Slicker.

LD-SAMPLE  INC B
           RET Z
           LD A,00
           IN A,(FE)
           XOR C
           AND 40
           RET C
           NOP
           JR Z,LD-SAMPLE

The first loader which is actually non-trivially different from the ROM loader. The changes here:

  • Setting the high byte of the IN to be zero - this causes every keyboard half-row to be read. This is unimportant as all five low bits are masked out later.
  • Dropping the RRA of the ROM loader - as we're not checking for any keys being pressed, no need to shift the byte around. This means the EAR bit stays in bit 6 rather than being shifted to bit 5 so the AND changes as well.
  • The RET C is a no-op as AND explicitly clears the carry flag.

This code has fairly obviously been constructed to have exactly the same runtime as the ROM code, which explains the always failing RET C and NOP (which replaces the RRA of the ROM routine). All the variants which replace the RET NC with a NOP or similar actually have a different runtime as a failing conditional RET is the only Z80 instruction which takes 5 t-states.

"Variant" Search Loader

Used by some late era Gremlin games; so far seen only in Lotus Esprit Turbo Challenge and Space Crusade.

LD-SAMPLE  INC B
           RET Z
           LD A,7F
           IN A,(FE)
           XOR C
           AND 40
           JR Z,LD-SAMPLE

While this maintains the distinctive AND 40 of the Search Loader, I suspect it's actually an independent derivation.

Digital Integration

Unsurprisingly enough, used by Digital Integration in some of their games, for example ATF and Tomahawk.

LD-SAMPLE  DEC B
           RET Z
           IN A,(FE)
           XOR C
           AND 40
           JP Z,LD-SAMPLE

This loader has two points of note: it inverts the counter (which just requires the flip of a condition outside this loop when working out whether it's a long or short pulse), and it's probably the minimal loop which is possible while still being anything even vaguely similar to the ROM loader.

Emulation

Fuse pattern matches for the above cores to implement its "accelerate loaders" feature.