Sinclair Club #04
25 мая 2001 |
|
Programming - Displays a three-character file extensions in the operating system TR-DOS.
Derivation of three-character file extensions in the operating system TR-DOS (C) Ivan Roshchin, Moscow In the TR-DOS each file is put in line 16 - byte descriptor located in the directory of the disk. As can be seen from a table in the descriptor for file extension by only one Symbol: Offset Length Commentary from the beginning 0 8 Filename August 1 File Extension September 2 starting address file (for BASIC - program and variables) February 11 Length of the file bytes (for the length of the BASIC program without taking into account the length of variables) January 13 in the length of the file sectors January 14 sector number beginning of the file January 15 Track Number beginning of the file But in recent years increasingly used a more informative three-letter file extension (as in MS-DOS): Offset Length Commentary from the beginning 0 8 Filename August 3 File Extension February 11 Length of the file bytes (for BASIC - length of the program without taking into account the length of variables) January 13 in the length of the file sectors January 14 sector number beginning of the file January 15 Track Number beginning of the file It is seen that the length of the expansion has increased by using two bytes, which previously stored starting address of the file (for BASIC - the files - the length of the program and variables). If you write a program for work with files, it would be nice to include in her three-character output extensions. But here comes the problem: not known in advance which files 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 the extension is always considered three-character, then the directory of the drive will look 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, then we assume that this single-character file extension. First, we list a list of demands that must be satisfied 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 and can not be symbols expansion. Now consider the procedure determining the length of the file extension According to these requirements. The procedure is designed to compile a Assembler 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 the first character of the expansion. Register H can not must be zero. Output parameters: the registers are unchanged (except for battery). Z flag carries information about the length of the extension: if flag is set - three-letter extension, if not set - single character. The length of the procedure, all seventy-two byte, it is the most optimized, and seem to make it shorter, without prejudice for the 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 directory disk, where each file length expansion is determined by this Procedure: boot B ZX_WIN ZIP ******** ZIP S_PLAY2d B BACKUM GTR BUZZ16_1 MPS FL_SH_EI MPS KL_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 under the name drive for eight characters, and itself name is located at offset # F5 in the service (ninth) sector mulevoy track. As we see in this sector are free three bytes, and hence the name disc can be increased to eleven characters. Indeed, the 11-character name quite often used. But there is a caveat ... If you want to assign a disk 11 - character name, then MSB the last byte must be installed. The fact that the subroutine print lines in TR - DOS (which used to display the name of the disc with command CAT) finishes print a line or at a meeting of the zero bytes, or when the MSB of the last printed character has been established (at print character MSB cleared). If you typed the common name of the eight characters, all goes well, as followed by three zero bytes, but printing 11 - character name, if MSB of the last byte is not installed, the procedure will not stop typing a name, and will print on and continue to fill the screen garbage. Accordingly, if you write program to the disk and want to support the 11-character name of the drive, then print the last character of your name how to print should drop its MSB. (Radiolyubitel. your PC 7 / 2000)
Other articles:
Similar articles:
В этот день... 21 November