Derivation of three-character file extensions
in the operating system TR-DOS
(C) Ivan Roshchin, Moscow
Fido: 2:5020 / 689.53
E-mail: asder_ffc@softhome.net
WWW: http://www.zx.ru/echo/roschin
In the TR-DOS each file is put in
compliance with the 16-byte descriptor that is in your drive.
As seen from tables in this descriptor for expansion
file by only one symbol:
Shift
The length from the beginning Comment
0 8 Filename
August 1 File Extension
September 2 starting address file
(For BASIC-length of
programs and variables)
February 11 Length of file in bytes
(For BASIC-length of
programs without regard to length
Ny variables)
January 13 length of the file in the sector
tures
January 14 start sector number
File
January 15 Track number beginning
File
But in recent years increasingly used a more informative
three-letter file extension (as in MS-DOS):
Shift
The length from the beginning Comment
0 8 Filename
August 3 File Extension
February 11 Length of file in bytes
(For BASIC - the length of
program without
length variables)
January 13 length of the file in the sector
tures
January 14 start sector number
File
January 15 Track number beginning
File
It is seen that the length of the extension due to the use
of two bytes, which had been stored starting address
file (for BASIC-files - the length of the program
and variables).
If you write a program
for working with files, it would be nice to include in its
three-character output extensions. But here comes the problem:
not known in advance which files will have to deal, and the
extension of files may be a three-character and
single-character. Thus, for each specific file your program
should correctly determine the length of the extension. If we
assume a three-character extension is, the directory of the
drive will look like messy:
boot B>
ZX_WIN ZIP
******** ZIP
S_PLAY2d BB
BACKUM GTR
BUZZ16_1 MPS
FL_SH_EI MPS
KL_F_CUT m!
SPY MPS
VIVID ME
NOSTALGY Y
s_play2d txt
Let's try to do: determine what
sequence of three bytes are
valid three-character extensions
and if the file descriptor will be invalid sequence, we assume
that this single-character file extension.
First, we list a list of demands
which must satisfy the three-letter extension:
1. All three characters - codes in the range
# 20 .. # 7F
2. In the extension can not be simultaneously
large and small Latin letters.
3. Notwithstanding paragraph 2, the expansion of XAS,
xAS, XaS, xaS are admissible
(Files with extensions creates
assembler XAS).
4. If the first character - "B", then the extension
can not be a three-character, because
that BASIC-files the next two bytes
contain the length of the program and variables
can not be a symbol of expansion.
Now consider the procedure that defines the length of the
file extension in accordance with these requirements.
The procedure is designed to compile in assembly ZX ASM 3.10,
and when compiling in another assembler you may need
replace command 'PUSH HL, DE, BC' to three
Team: 'PUSH HL', 'PUSH DE' and 'PUSH BC'.
Accordingly, the command 'POP BC, DE, HL'
need to be replaced by the three teams' POP
BC ',' POP DE 'and' POP HL '.
Input parameters: HL points to first character of the
expansion. Register of H should not be zero.
Output parameters: the registers are
unchanged (except for battery), and the flag
Z carries information about the length of the extension: if the
flag is set - the three-letter extension, if not set - single
character.
The length of the procedure, only seventy two bytes, it is
the most optimized, and, apparently, to make it shorter,
without prejudice to functionality will not work.
Text of procedure:
ANALYS_EXT PUSH HL, DE, BC
; Check BASIC:
LD A, (HL)
CP "B"
JR Z, ANALYS_NO
; Check XAS, xAS, XaS, xaS:
RES 5, A
CP "X"
JR NZ, ANALYS_EX1
INC HL
LD A, (HL)
RES 5, A
CP "A"
JR NZ, ANALYS_EX2
INC HL
LD A, (HL)
CP "S"
JR Z, ANALYS_YES
DEC HL
ANALYS_EX2 DEC HL
; Initially, D = # FF, E = 0. Once
; Find symbol A.. Z or a.. Z,
; Add it to D for AND and E on OR.
; In the fifth bit to 0 if the letter is large,
, And 1 if the letter is small. Valid
; Only options 0,0,0 and 1,1,1. If
; Option 0,0,0 (all letters long), then
, 5 th bit D = 0 and 5 th bit E = 0. If
; Option 1,1,1 (all small letters), then
, 5 th bit D = 1 and the 5 th bit E = 1. For
; Other options (when there are 0, 1)
, 5 th bit D = 0 and 5 th bit E = 1. See
; For options 0,0,0 and 1,1,1 5-th bit
, From D XOR E is 0, while for others
; Options will be equal to 1, so
;, We can distinguish between permissible
; Options from unacceptable.
ANALYS_EX1 LD DE, # FF00
LD BC, 3 * 256 +% 00100000
ANALYS_EX3 LD A, (HL)
CP C; = CP # 20
JR C, ANALYS_NO
CP # 80
JR NC, ANALYS_NO; not # 20 .. # 7F
OR C
CP "a"
JR C, ANALYS_EX4
CP "z" +1
JR NC, ANALYS_EX4
LD A, (HL)
AND D
LD D, A
LD A, (HL)
OR E
LD E, A
ANALYS_EX4 INC HL
DJNZ ANALYS_EX3
LD A, D
XOR E
AND C
JR Z, ANALYS_YES
ANALYS_NO OR H; reset Z flag
; (Since H <> 0 then
; Result of the operation
; OR is <> 0)
; When transferring control to ANALYS_YES
; By JR - Z flag will always be installed!
ANALYS_YES POP BC, DE, HL
RET
Here, for example, looks like the disk directory where each
file length extensions determined using this procedure:
boot B
ZX_WIN ZIP
******** ZIP
S_PLAY2d B
BACKUM GTR
BUZZ16_1 MPS
FL_SH_EI MPS
FL_F_CUT m
SPY MPS
VIVID M
NOSTALGY Y
s_play2d txt
Now I would like to say a few
words on the drive. In the TR-DOS disk under the name given to
eight characters, and the name located at offset # F5 in the
service (Ninth) sector mulevoy track.
As we see in this sector remain free even three bytes, which
means that the drive name may be increased to eleven
characters. Indeed, the 11-character name is often used. But
there is one nuance ...
If you want to assign a drive 11simvolnoe name, MSB last
bytes must be set.
The fact that routine printing a string
in TR-DOS (which is used for output
name of the disk when you run CAT)
finishes typing a string or a null byte at a meeting, or when
the highest bit recently typed characters was
set (printing character MSB
reset). If you typed the common name
eight characters, all goes well, as it is followed by three zero
bytes, but when printing 11-character
name, if the highest bit of the last byte
is not set, then the procedure will not stop printing the name,
and will print on and further, filling the screen garbage.
Accordingly, if you write a program
to the disk and want to support
11-character name of the drive, then press
last character name your procedure
print should drop its MSB.
Sincerely, Ivan Roshchin.