Disking ZX Spectrum Games for TR-DOS: Adapting SAVE/LOAD and Levels

Electra #02

Program Adaptation

Coding

This article is a continuation of the topic started in the previous issue. This time we will talk about disking games. The first and most important piece of advice is to perform all the manipulations described below using the built-in monitor of ZS 256 SCORPION. But if you don't have 70 - 80 Ls, I advise you to acquire a monitor that takes up little memory, has great program tracing capabilities, and is convenient enough.

Now let's get down to business – the disking of all games can be divided into two main types:

  1. Games where position SAVE and LOAD procedures need to be disked;
  2. Games that have additional levels.

In the first case, the algorithm is as follows:

  1. A file must be created on disk using a disk monitor, or some position must be transferred from tape.
  2. In the program, disk LOAD and SAVE procedures must be inserted instead of tape LOAD and SAVE procedures.

The listings of these procedures are as follows:

LOAD    PUSH IX       ;target
        POP HL        ;address

DATA1   LD DE,0
DATA2   LD BC,#0005
        CALL #3D13

SAVE    PUSH IX
        POP HL
DATA3   LD DE,0
DATA4   LD BC,#0006
        CALL #3D13

These procedures are designed with the assumption that the address is always stored in IX.

  1. After the whole program is written, the following manipulations must be performed:
    1) Read from the disk the location of the position on disk and the position's length in sectors;
    2) Insert the read values into the LOAD and SAVE procedures:
LD HL,FADR      ; location
LD (DATA1+1),HL
LD (DATA3+1),HL
LD A,LEN        ; len., sect.
LD (DATA2+2),A
LD (DATA4+2),A

That should be about all.

It can also be mentioned that if a position is short, it can also be saved at a specific location on the disk – on the last tracks or on track zero after the disk title.

Now let us consider the case when the game has additional levels loaded from tape. While in the first case one could still manage without the ZS 256 monitor, in this case it is practically impossible.

All disking can be divided into the following stages:

  1. Create a monoloader (see ELECTRA N1);
  2. Ensure return to the first level if the player loses all lives or completes the game.

When creating a monoloader, the following basic principles must be taken into account:
1) all levels must be located consecutively and immediately after the last block being loaded;
2) the monoloader must be created according to the specific circumstances – using the variable at address #5CF4.

Returning to the first level can be achieved by writing into address #5CF4 the value that was stored there at the very beginning.

The main problem that arises is that TR DOS corrupts 112 bytes at address #5CB6. This problem can be solved by saving these 112 bytes in memory and restoring them afterwards.

Share your thoughts about the article