Adaptation programs for the ZX Spectrum to TR-DOS with modern tools. Part 2

Adaptation programs for the ZX Spectrum to TR-DOS with modern tools. Part 2


In the first part of the article, we disassembled the original version downloader and found out where the game code is loaded and how it starts. Now you need to transfer files to disk.


Floppy 5.25 "


This is usually done by simply copying files, but there is one problem. The fact is that the original file contains a picture and a game code in a whole piece and, therefore, overwrites the area of ​​basic and system variables that are immediately behind the screen area. Such a file can be loaded from a tape, but cannot be loaded from a floppy. TR-DOS reserves a certain area of ​​memory for your needs, and if you load data there, during the boot process, everything will break.


Fortunately, we have enough memory, not busy playing. Therefore, the game can be downloaded to another location, and after the download is complete, move it to where it should be and run it. In this case, I would like to show the picture before the end of the download - for that it is bootable. To do this, we cut a monolithic file into two - data from the screen area and game data:


  $ head -c 6912 headless.bin & gt;  screen.bin
 $ tail -c +6913 headless.bin & gt;  data.bin  

The file with the game data will immediately translate the hobeta format. Later we need it to write to the final image. We’ll use zxspectrum-utils and trd2hob :


  $ binto0 data.bin 3
 $ 0tohob data.000 # will create a data file. $ C  

Loading screen


As for the boot screen, spend 6.75 kb on such a simple picture - waste. You can compress it with a screen compressor, for example, Laser Compact 5.2 . To do this, you first need to write the picture file to a temporary floppy image:


  $ binto0 screen.bin 3
 $ 0tohob screen.000
 $ createtrd tmp.trd
 $ hobeta2trd screen. \ $ C tmp.trd  

After that, run the Laser Compact in the emulator and save the compressed image on the same diskette (Pack screen → Save with depacker). When saving, specify the file name screenz.C . Next, you need to copy the compressed image from the floppy image back to the disk. Unfortunately, the source code trd2hob I could not find anywhere, so I have to run the DOS binary from under DosBox:


  $ dosbox -c "mount C $ PWD" -c "C:" -c "trd2hob.exe screen.trd" -c exit  

As a result, we get a screenz. $ C hobeta file with a compressed image.


In addition to native Spectrum utilities for compressing screens, there are utilities for PCs, for example, zx7b and < code> zxsc . Although it is more convenient to automate work with them, both of them have laser drawbacks:


  1. Both lose on compression quality.
  2. When unpacking a picture, certain artifacts are visible when, as a Laser Compact, it fills the screen attribute area almost instantly.
  3. zx7b does not support creating self-extracting archives - you have to additionally compile the decompressor.

Finally, find out the size of the compressed file. We will need it later to write the bootloader.


  $ lstrd tmp.trd
 80 Tracks, Double Side, capacity 640kB
 Number of files/deleted: 2/0
 Free sectors/bytes: 2509/642304
 First free sector/track: 3/3

 FILENAME TYPE SECTORS ADDRESS LENGTH TRACK SECTOR
 --------------------------------------------------  ------------
 screen & lt; C & gt;  CODE (BYTES) 27 16384 6912 1 0
 screenz & lt; C & gt;  CODE (BYTES) 8 40000 1812 2 11  

As you can see, the file has shrunk more than tripled and takes 8 sectors on the disk.


In the next section, let's go directly to the bootloader.

Source text: Adaptation programs for the ZX Spectrum to TR-DOS with modern tools. Part 2