╔═══════════════════ ═══════════════════╗
║Section: CPU for you; ║
║Article: Working with TR-DOS; ║
║Music: Dreamer; ║
║Text: Vorozhkin Alexander. ║
╚═══════════════════ ═══════════════════╝
Working with TR-DOS at the machine code level
valid. Login to TR-DOS is provided when
computer reading commands to addresses
#3D00-#3DFF.In this case, the main ROM of the computer
The yuter is switched off, and in its place is "pods-
TR-DOS ROM is installed. In it at the addresses
#3D00-#3D2E (15610-15663) are placed at
ki entry into TR-DOS routines. Most
The important ones are listed below.
HEX DEC Action to be performed
#3D00 15616 Exit to TR-DOS
#3D03 15619 Exit to TR-DOS, complete
introduction of the TR-DOS command and
return to SOS
#3D13 15635 Execution of internal
TR-DOS commands, depending
benefits from content
register C microprocessor
litter
#3D2F 15664 Execution of subroutines
TR-DOS addressed via
stack
The first two entry points are well known and
their use does not cause any special problems
mineralization, the last two deserve
efficient consideration.After contacting
address #3D13transition to sub-
program #283C (10300), which depending
depending on the code contained in the register
re C, transitions to the required
TR-DOS subroutine.
1.C = #01.Select a drive.Its number
indicated in register A. At the first
access to this drive occurs
its initialization is carried out (determined
number of tracks, position constant
roving) and the corresponding
system variables.
2.C = #02.Head is installed on
the track indicated by register A. In case
double-sided drive tracks 0
(lower) and 1 (upper) corresponds
the first physical track, tracks 2 and 3 -
second, etc. It should be noted that on
the disk may not have 80 physical
tracks (from 0 to 79), and 82 - 85 depending
depending on a specific drive, which
used by some programs.
An example of using this command is
details are given below (example 16).
3.C = #05.Reading a group of sectors. In re-
hyster B-number of read sec-
tori, D-number of the initial track, E-on-
starting sector, HL buffer address, in
which is being read.
example 6.
LD C,#05 ;command code
LD B,#10 ;16 sectors
LD D,#00 ;track
LD E,#00 ;sector
LD HL,#8000 ;buffer address
CALL #3D13
RET
This programwill read the contents well-
left track to the buffer at address 32678.At
first glance, the last two lines about
grams can be replaced with one command
JP #3D13 - after all, the called subroutine
ends with RET. However, such a replacement does not
is always possible due to the characteristics of the air
rata after executing TR-DOS routines
TR-DOS ROM is disabled when
when the processor reads the command code at the address
su, more #3FFF. If you launch-
provide suggested examples from BASIC co-
manda RANDOMIZE USR adr , then return
occurs through point #2D2B(STACK-BC) in
mostly ROM.If you make a suggestion-
any replacement, then the program will be normal
but work when calling it from another program
grams located in RAM. If you call -
create this program using USR from BASIC,
then when returning there will be no switching
flashing the ROM and the result will be the same as not
I would like to.
4.C = #06.Record sector group.Para-
meters are similar to operation
reading a group of sectors.
Example 7.
LD C,#06 ;command code
LD B,#10 ;16 sectors
LD D,#9F ;track
LD E,#00 ;sector
LD HL,#8000 ;buffer address
CALL #3D13
RET
This program will write the contents of the buffer
at 32768 on the last, 159th track.
So you can, for example, save previously read-
special catalog for the occasionhis damage. Pro-
reading it then from the 159th track and recording
Saving at 0, you can save valuable programs
One more feature should be noted
commands #05 and #06 - they may not work
only with sectors 256 bytes long, but also
with sectors of different lengths (128,512,1024
bytes).Using the feature, it is easy to
organize the exchange of information between ZX-
SPECTRUM and other computers. so can-
but read and write to the disks used
in computers "SPECIALIST", "ORION-128",
DVK (with MY controller), as well as IBM.od-
However, in these cases it is impossible to immediately
write or write down a group of sectors, like this
how sectors longer than 256 bytes will be
get along in the computer memory one on
another, failure will also befall you when
trying to read a sector from an IBM disk with no.
nerom 9 - there are no such things there (with standard
format). The way out of this situation is simple -
it is necessary to study the structure of the “alien”
disk and read (or write) information
one sector at a time, calculating each time
the number of the next track and sector, as well as
buffer address.
5.C = #07. Output of the disk directory. In the registry
page A - channel number for cat output
log. You must first perform
nena team #18.
example 8.
LD C,#18 ;command code
CALL #3D13 ;
LD A,#02 ;channel number
LD C,#07 ;command code
CALL #3D13RET
This program is equivalent to the CAT directive
TR-DOS.If in register A before calling
commands to enter #03 , then the directory will be
output to the printer.
6.C = #08.Reading file information.B
register A is pre-placed in
serial number of the file (0-127).From the catalog
disk 16 bytes are transferred to the system area
dark variables TR-DOS. Doesn’t matter
whether this file is erased or not and whether it exists
does it exist at all? Addresses of the corresponding
system variables are given below.
HEX DEC Length, purpose
byte
#5CDD 23733 8 File name in ASCII
... ...
#5CE4 23780
#5CE5 23781 1 File type (A,B,C,
D or #) , but , in
in principle, maybe
be any sim
the ox that opens
additional
opportunities
#5CE6 23782 2 Start address
code file
or BASIC length
programs
#5CE8 23784 2 File length
#5CEA 23786 1 File size in
sectors
#5CEB 23787 1 Number one
file sectors
#5CEC 23788 1 Number one
file track.
7.C = #09.Recordfile information in
directory.From the system variables area
16 bytes are written to the directory per month
then information about the file whose number is
given in A.
Example 9.
LD A,#20
LD C,#80
CALL #3D13
LD HL,#5CDD
LD (HL),#41
LD C,#09
CALL #3D13
RET
This program will change the first character in
name of the 32nd file "A".If this file was
erased, then it will be “restored”, but for
this needs to be added
changes also in the 8th sector of zero
track. How to do this will be explained
below.
8.C = #0A.Search for a file by name, specified
nomu in the field of system variables.
The number of the found file is returned to
register C. You can search for files by name
and type (9 bytes) or by any number
wu of the first bytes of the name (from 1 to 16), next
you just need to specify the number of characters in
system variable at address #5D06
(23814).
9.C = #0B.Write file to disk.Name and
file type - in the system changes area -
nyh, length - in DE, starting address - in HL.
Example 10.
LD HL,NAME ;file name address
LD C,#13 ;command code
CALL #3D13
LD DE,#1B00
LD HL,#4000
LD C,#0B ;command code
CALL #3D13
RET
NAME DEFM "SCR C" ;file name and type
la - 9 bytes.
Thisthe program will transfer the file name and type
"SCR" CODE (actually carried 16 , but
not 9 bytes, but the last 7 bytes in a given
case do not matter) in the field of systems
dark variables (addresses 23773-23781),
then writes the file to disk.
10.C = #0C.BASIC program entry.Name and
file type (for a type other than "B", file
is written under the name "boot") - in the ob-
area of system variables.
11.C = #0E.Read/check file.Name
and file type - in the area of system re-
variables. The file download address is taken from
directory with A = #00 or from the register
howl pair DE at A = #03. When A = #FF co-
dy are loaded from the HL address, and the length
the downloaded file is taken from DE.Byte by
address 23801 determines the type of operation:
#00 - LOAD,#FF - VERIFY.
Example 11.
Let's assume that the disk has a screen
file with starting address 16384 and length
6912 bytes.
LD HL,M1
LD C,#13
CALL #3D13
LD C,#0A
CALL #3D13
LD A,C
LD C,#08
CALL #3D13
LD A,#00
LD (#5CF9),A
LD C,#0E
CALL #3D13
RET
M1 DEFM "SCR C"
This program will transfer the file name and type
la "SCR" CODE (9 characters) in the system area
dark variables (addresses 23773-23781),
will then find this file in the directory
reads information about him from the dis- catalog
ka, and thenreads the file itself according to the data,
taken from the catalogue.
Example 12.
Add to the program from example 11 the following:
blowing lines:
LD A,#03
LD HL,#4800
LD DE,#0800
These lines should be inserted between
LD (#5CF9),A and LD C,#0E.
Now running the program, you will see
in the center of the screen is what was previously at the top
her parts.
Example 13.
If we modify example 11 as follows
way:
LD A,#FF
LD HL,#8000
Then the program will download the entire "SCR" file
CODE at 32768.
Note: example 13 should be inserted
in example 11 between the lines:
LD (#5CF9),A and LD C,#0E.
12. C = #12.Deleting files. Name and type
file - in the system area
variables. all are deleted
files with such data.
Example 14.
LD HL,M1
LD C,#12
CALL #3D13
LD C,#0A
CALL #3D13
LD A,C
LD C,#18
CALL #3D13
RET
M1 DEFM "SCR C"
This program will find a file on disk
"SCR" CODE and will erase it.
13. C = #13.At address 23773 rewrite-
There are 16 bytes of information from
memory addressed by the register
howl pair HL.
14. C = #14.16 bytes are overwritten
formations from the field of systems-
variables at address
23773to memory at the address
specified in the register
pair HL.
15. C = #15.Track check. Register D
must contain the pro- number
verifiable physical track
16. C = #16.Loading system registry
tra.Code - in register A.Pre-
added to it
#3C.
17. C = #17.Select the bottom side.
18. C = #18.Setting to disk. Checking-
The disk type is specified (the 8th sector of the directory).
Point #3D2E provides access to any
subroutine TR-DOS, however, it is used
a little more complicated than #3D13. For reference
let's remember how the Z80 microprocessor
Executes the CALL_adr and RET commands. When you-
executing the CALL_adr command on the write stack -
There are two bytes - the address of the command, followed by
for CALL_adr, then the re-
move to address adr, When executing a command
RET two bytes are read from the stack - ad-
res according to which the return from
subroutines. Moreover, it is not at all obligatory -
but for these two bytes to be written to
stack when executing the CALL_adr command - they
can be placed there, for example, when
execution of the PUSH_dd command, where dd is any
bay pair of microprocessor registers. When
contacting the address corresponding
DOS entry point (in this case
#3D2E), as already mentioned, happens
replacing the main ROM with TR-DOS ROM.Bin the latter case, it is written to address #3D2E
RET command code (#C9).If pre-
but put some address on the stack
TR-DOS routines, it will be executed
transition to it. The stack is also necessary
before this place the return address from
subroutines.
Example 15.
LD HL,RET1 ;return address
PUSH HL ;push on stack
LD HL,ADRESS ;subprogram address
we are TR-DOS
PUSH HL ;push on stack
JP #3D2E ;transition
RET1 RET ;return point
To use the #3D2E entry point, do not
you need to know the addresses of TR-DOS routines
Unfortunately, TR-DOS is written very poorly.
tanno and disassemble it quite
difficult. The three passages below can-
but to use when developing applications
other programs that work with the disk. They are
correspond to version 5.03, in other versions
yah they exist too, but others may have them
addresses.
#2A53 (10835):
OUT(C),A
RET
#3FCA (16330):
M1 IN A,(#FF) ;read system
register
AND #C0 ;check readiness-
data density
JR Z,M1 ;once again, if not
ready
RET M ;return if all
recorded
OUTI ;output nextbyte to register
JR M1 ;data
#3FE5 (16357):
M2 IN A,(#FF)
AND #C0
JR Z,M2
RET M ;return if all
read
INI ;read next-
the last byte from the re-
JR M2 ;data gistra
The first of the given subroutines poses
allows you to display the necessary data in any way
fight from the ports of the TR-DOS controller (this
can only be done by contacting
ROM TR-DOS). There are five such ports. The first ones are
Four of them belong to the microcircuit
KR1818VG93 (Table 1).
Table 1.
Address Purpose
#1F Command/status register
#3F Track Register
#5F sector register
#7F data register
Register assignments and instruction structure
KR1818VG93 are considered in [4].
There is another port that has the address
#FF and is usually implemented on K555TM9. This
TR-DOS system register. If necessary
you can find out the contents of this register
You can use cell 23830 to
which stores a copy of this register.
Assignment of control word bits
the following:
D0 and D1 - NGMD number (0-A,1-B,2-C,3-D);
D2 - controller reset command;
D3 - head readiness (1 - ready);
D4 - disk side (0 - bottom, 1 - top);
D6 - recording density (0 -double,1 -
single);
When reading from port #FF, the si-
DRQ signals (data readiness for transmission)
chi, 38 pin VG93, 6th bit of port) and
INTRQ (command execution, 38 output VG93,
7th bit of the port).
The last two subroutines are intended
Codes for reading a data array into a register
data. They can be used like this:
Example 16.
LD A,#10 ;track number
LD C,#02 ;command code
CALL #3D13 ;install head
LD A,#50 ;data for systems-
registry
LD C,#FF ;port address
LD HL,RET0 ;return address
PUSH HL ;to stack
LD HL,#2A53 ;subroutine address
PUSH HL ;to stack
JP #3D2E
RET0 LD C,#1F ;registration port address
tra commands
LD A,#E4 ;read command code
track
LD HL,RET1 ;return address
PUSH HL ;to stack
LD HL,#2A53 ;subroutine address
PUSH HL ;to stack
JP #3D2E
RET1 LD C,#7F ;registration port address
data transfer
LD HL,RET2 ;return address
PUSH HL ;to stack
LD HL,#3FE5 ;subroutine address
PUSH HL ;to stack
LD HL,#A000 ;buffer address
JP #3D2E
RET2 RET
This program will readcontents ver-
the next track of the 16th cylinder of the disc with all
with marks into the buffer at address #A000.
If you change two lines
LD A,#F4 ;write command code
track
LD HL,#3FCA ;subroutine address
(This program must be placed behind
place of the lines LD A,#E4 and LD HL,#3FE5 ), then
we will get a track recording program with all
marks (track formatting).Preliminary
Actually in the buffer you need to prepare
array to write to. Moreover, you can record-
create tracks with sectors of any length
(128,256,512,1024 bytes) and with arbitrary
numbering - just need to be correct
prepare data [4]. Can you suggest
another use for this entry point.B
TR-DOS ROM is quite free
space (about 4KB). There you can place-
write your programs and run them like
suggested in example 15. Thus,
capabilities can be significantly expanded
TR-DOS, and such a change does not reflect
depends on compatibility. For example, you can
add a "recovery" program or
disk check, a small "boot" program
mu or even a printer driver, although in pos-
In the last case, small (not
more than 20 bytes) changes to the main ROM.
Of course, it would be nice to make changes
into some TR-DOS ROM routines, although
in order to correct existing errors,
but this is not always acceptable. Any changeThis may lead to the fact that some
be the program stops working on
such a computer. This is especially true
the computer's main ROM. There's not even-
big change (including filling
lack of free space, change
font or even an inscription that displays -
when turning on the computer) may worsen
sew compatibility with his “branded bra-
Tom". So, decide what kind of computer you are
want to have: Sinclair - compatible or
Sinclair - similar.
Share your thoughts about the article