Loading TR-DOS files through $3D13 and Brazilian interfaces

The place for codemasters or beginners to talk about programming any language for the Spectrum.
Post Reply
User avatar
Alessandro
Dynamite Dan
Posts: 1908
Joined: Wed Nov 15, 2017 11:10 am
Location: Messina, Italy
Contact:

Loading TR-DOS files through $3D13 and Brazilian interfaces

Post by Alessandro »

In this thread, I explained how I followed the Beta Disk user manual to load files from a TR-DOS image file disk in machine code. However, I always felt the process to be rather cumbersome and code intensive, and wished to employ direct calls to the $3D13 routine instead. After reading some documentation available on the Web, I managed to do it and used this new method for the .TRD multi-language disk image of Sophia II, which allowed for smaller and (hopefully!) more efficient code. Here's how I did it.

To directly load a file, you must know its location on the disk first, i.e. at which track and sector it starts, and its length in sectors. With ZX-Blockeditor, you can know that easily. Open the .TRD disk image file with it, then select Disk > Show disk image... A window like this one will appear:

Image

This is the map of the disk image with the list of all files on disk on the left, and the track/sector (or "blocks" as the program calls them) disposition on the right. The numbers in the row indicate the local sectors, i.e. the sectors of the current track, those in the column the total sectors; to know the number of the corresponding track, you must divide that number for 16.

When you click with the left or right mouse button on one of the files on the left, its position on the disk will appear, with the indication of its length at the bottom. In this example, file "1" begins at track 224/16 = 14 and at sector 9, and is 124 sectors long.

With this information, you must then convert the track, sector and length to hexadecimal, and then follow this syntax:

Code: Select all

  LD HL, ADDRESS     ; address in memory where to load the file
  LD DE, $XXYY       ; track $XX, sector $YY
  LD BC, $ZZ05       ; $ZZ sectors length, plus $05, the function number for loading data from disk (saving is $06)
  CALL $3D13         ; TR-DOS internal routine
The example above would then be as follows:

Code: Select all

  LD HL, 30702       ; address in memory where to load the file
  LD DE, $0E09       ; track 14, sector 09
  LD BC, $7C05       ; 124 sectors length
  CALL $3D13         ; TR-DOS internal routine
The disadvantage of this method is that you must update the loading code if you have to replace the file in the disk with another one of a different length, which will make all of the other files after it change their position on the disk. And when you have dozens of files on one disk, it becomes quite a pain in the neck to re-check the position of every file just because you had to replace one of the first files in the disk...

Notwithstanding this, the method worked as expected and then I had to adapt it to make it work with the Brazilian clones of the Beta Disk interfaces, which employ different routine calls and a "shadow" page. By reading the CBI-95 disk interface manual - as transcribed by Clóvis Friolani and Otto Frederico - and after several attempts, I understood how to do it. I'll follow the same example as above:

Code: Select all

  CALL   15467       ; initialization
  LD HL, 30702       ; address in memory where to load the file
  LD DE, $0E09       ; track 14, sector 09
  LD BC, $7C05       ; 124 sectors length
  CALL   11990       ; modified TR-DOS internal routine
  CALL   15484       ; de-pagination of "shadow" ROM
As a consequence, I wrote a modified version of the Portuguese language game management program for the TR-DOS version, with the integration of these codes. Otherwise I would have had to duplicate and modify all of the TR-DOS game management programs if I wanted all language versions to be available to them, and that would have been really too much... This way, when used with one of such interfaces, the "boot" program will load straight the Portuguese language version, after "recognizing" the interface thanks to the trick Einar suggested me. The only difference is that a dedicated screen will briefly appear before the game loading screen:

Image

In fact, I assumed that Brazilian users would have been interested into playing the game straight into their own language, rather than having to go through the language selection screen, so in a certain sense they have been favored ;-)
Post Reply