ZX Review #5-6
04 ноября 1997
  TR-DOS  

TR-DOS for beginners - Continued.

<b>TR-DOS for beginners</b> - Continued.
    TR DOS FOR BEGINNERS



(C) VA Sirotkin


   Continued. Start see the ZX
REVIEW 1996 NN 1-2, 4-5, 6, 7-8;
ZX REVIEW 1997 NN 1-2, 3-4.


  PROGRAMMING THE CONTROLLER


   Now we explain a few
specific examples.


   ! Needed a reminder:
Do not forget that for the different versions TRDOS must exhibit
their addresses routines!


   Before the loader starts, the program must
identify and correct version TRDOS address challenges.
To determine the version and configure
bootstrap function is most conveniently
TRDOS C = # 13. We will miss this
part of the program, as in Chapter
'FUNCTION TRDOS' for details on how to do it.


   Example 1. Boot files
140.
; Base addresses are given for ROM version 5.01 *
; In angle brackets will be given an address for 3.5 *

, Head of the boot


       ORG ADRESS; starting address of the bootloader

       DI; disable the interrupt

       LD HL, # 5800; paint the screen black Atri
                     ; Butami

                     ; On the screen we will have a buffer

       LD DE, # 5801; to read the latest

                     ; Sector file to the RAM

                     ; Move the right amount

                     ; Bytes

                     , As well as a buffer for the read
                     ; Tion disk directory

       LD BC, # 01FF

       LD (HL), L

       LDIR
;-----------------

       CALL LOAD_CAT; find the file on disk
, And its attributes (routine returns as a result; Giustra 
'D'-track number in the' E '- number sects; RA' HL 'load 
address in RAM; in' BC'-length) ;-----------------

       PUSH BC; hide the file length

       DEC B; reduce the length of 1 sector
;------------------

       CALL LOAD_SEK; file without the last

                      2-x sectors (if the 'C' = 0,

                      , Then without 1 last)

                      ; Downloaded from the address of 'HL'
;------------------
       PUSH HL; hide subsequent address

                      ; RAM for the remaining 2,

                      , (1) sector

       LD HL, # 4800; buffer address for sector


       LD B, 2; two sectors

       CALL LOAD_SEK; get to the two # 4800

                      ; Last sector

       POP DE; get the address of the RAM for the remaining
                      ; Shihsya sectors / sector

       POP BC; get the length of the entire file

       LD B, 1, one sector is likely, and

                      The residue length of the 'C'

       LD HL, # 4800; move out of the screen

       LDIR; addressed to 'DE'

       EI;

       RET; return to the program

;--------------------------; Subroutine reads the directory and 
the definition ; File attributes


LOAD_CAT LD DE, 0000 Zero Track and Sector
LOAD PUSH DE; hide

         LD HL, # 4800; address of a buffer in RAM

                        ; Sector

         PUSH HL; hide

         LD B, 1; One Sector

         CALL LOAD_SEK; assume sector number

                        ; Of 'E'

                        ; With ZERO track, ie

                        ; From the directory of the disk

         POP HL; beginning buffer address

         LD B, # 10; meter titles (at

                        ; Sector of 16)
CIKL PUSH HL; hide the address of the beginning

         LD DE, FILENAME; address in RAM, where NAME

                        ; File

                        ; You want to download

         LD C, 08; counter letter file name
NAME_F INC HL; miss the first letter in the

                        ; Name

                        ; File in a matter of khat
                        , Log

         LD A, (DE); letter of the name

         CP (HL); comparable with the letter of the NAME

                        ; File read from disk

         JR NZ, ZAGOLOW; no coincidence - the transition

         INC DE; coincided - the next letter

                        ; Name

         DEC C; reduce the count of letters

                        ; Name

         JR NZ, NAME_F; all the letters? - None - Returns

                        ; The cycle test

         POP DE; Yes, the name and file type

                        ; Match!

         POP DE; stack pointer will return to

                        , The initial state

         INC HL; go to the attributes

                        ; File

         LD E, (HL); ml.bit Load address

                        ; File

         INC HL

         LD D, (HL); st.bit Load address

         INC HL

         LD C, (HL); ml.bit LENGTH

         INC HL

         LD B, (HL); st.bit LENGTH

         INC HL; skip byte volume

                        ; Sectors

         INC HL;

         LD A, (HL); Number of the first Sector

                        ; File

         INC HL

         LD H, (HL); Track Number

         LD L, A

         EX DE, HL; in HL-load address in RAM

                        ; In DE - track / sector

                        ; In BC - the length of zgruzhaemogo

                        ; Block

         RET; back

;--------------------------; Meter titles and directory sectors

ZAGOLOW POP HL; return address of the current

                        ; Title

        LD DE, # 0010; header length

        ADD HL, DE; proceed to the next

                        ; Title

        DJNZ CIKL; if not the entire sector -

                        ; Repeat

        POP DE; return and increase the number

        INC DE; sector

        BIT 3, E; all 7 sectors of the directory

        JR Z, LOAD; not - repeat

        JP ERROR; yes, the entire catalog,

                        , But no files were found:

                        ; Go to the processing

                        ; Error situation

;--------------------------; File name to search the directory

FILENAME DEFM 'FNAME_0'; filename without the 1-st

                         ; Letters

          DEFM 'C'; file type CODE
;---------------------------
; Routine boot disk

LOAD_SEK LD IX, # 2F1B <# 2F65>; address Subprogramme
                                And we in the ROM
; 'RECOVERY, ie a track 0
S address is input in the middle of the procedure
; # 2EF0 <# 2F3A> (see annex)


          CALL TRDOS; perform routine

                         ; In ROM

TREK PUSH BC; hide block length

          PUSH; and track number with

                         ; Sector

          LD A, D; track number

          OR A; transform a room

                         ; CYLINDER

          RRA; and the disc

          LD C, A; copy number of the cylinder

                         And in 'C' for the ROM

          JR NC, UP_TREK; was a 'transfer'? Number was

                         , Even?

          LD A, # 2C; if odd -

                         ; Readiness 'NIH'

          JR FIND_TRK; go on 'Finding

                         ; Track '

UP_TREK LD A, # 3C; number is even -

                         ; Readiness 'TOP'

FIND_TRK LD IX, # 2F03 <# 2F4D>; address in the ROM;

                               , "Search"

, This address is the entrance to the middle of the procedure
; # 2EF0 <# 2F3A> (see annex to chapter)


         CALL TRDOS; find the cylinder and

                        , Pressed to the desired direction

                        ; Drive

          POP DE; extract track number,

                        ; Sector

          POP BC; and block length

N_SECTOR PUSH BC; hide

                        , (Here are already in the process

          PUSH DE; downloads will be ongoing

                        ; Rates

                        ; Tracks and sectors)


          LD IX, # 2ED1 <# 2F1B>; load sector

                                ; Number

                         ; Of 'E', the address of 'HL'


          CALL TRDOS; execute


          POP DE; extract track number

                         , And SECTOR

                         ; Already loaded

          INC H; increase the buffer address

                         ; RAM 1 sector,

                         , Ie rose to 256

          INC E; increase the number of sectors

          BIT 4, E; all sectors on the track?


          JR Z, ALL_SEC; NO, continue to boot


          LD E, 00; YES - zero the number

                         ; Sector

          INC D; increase the track number

          POP BC; see the rest

                         ; Length

          DJNZ TREK; reduce it to 256

                         ; (1 sector)

                         Or rather, if not all

                         ; Loaded


          RET; downloaded all that is needed

                         , Output
;-------------------- ALL_SEK POP BC; see the rest

                         ; Length

          DJNZ N_SECTOR; reduce it to 256

                         ; (1 sector)

                         ; Zgruzhaem Track

                         ; Further, if not all


          RET; downloaded all you need -

                         ; Go

;-------------------- TRDOS PUSH IX; address for execution

                        ; Procedures ROM TRDOS

          JP # 3D2F; call the procedure indirectly

                        To the address on the stack
;------------------------------------------------- - 2

   This program does not need any system variables and can work 
even in the display area. It can be downloaded as the head of a 
program and load the next levels. The only drawback

this boot - is that
all files on the disk in the directory
should have its real length
and the load address. If you do
for some reason is not appropriate (for example,
you want to protect their programs), then adding the program has
several commands and applying the method of encryption length 
and address file during its creation, it is possible to solve 
this problem. But this call for a separate chapter.


   As we see, most of
places in the program is searching
file on the disk and determine its
attributes (length, start, number
track and sector number).

   Program can significantly
reduced if all this is to define the beginning, when there is 
an initial load of BASIC. While memory is free and the area

system variables TRDOS not
blocked codes. It is more convenient
make the function DOS, and the data
the file transfer then to the main program, saving them up to
for the time being in the space of memory.


           Example 2


   Consider just the case when the data file (which should be 
loaded as the next level of play or state of the game) were 
transferred into program while it downloads.

140.
* Boot * use the routine
; TRDOS # 3F00 <# 3F0A>
; Programa starts with the label START
And the data file are in the addresses of RAM
; Sector number and track number - the address
; 'ATRIBUT'
The length of the file at 'DLINN'
, The load address at 'ADR_LO'
;----------------
ATRIBUT NOP; here to convey sector number

               NOP; here refer Track Number
DLIN NOP; here to convey the length of load

               NOP
ADR_LO NOP; here to pass the load address

               NOP

;------- Routine procedure call DOS --------- TRDOS PUSH IX; 
call subroutine 

                            ; TRDOS

               JP # 3D2F; address of the 'IX'
;-------------------------------------------------
;............... START ..............................

START LD BC, (ATRIBUT); take the track number and

                        ; Sector

       LD HL, (# 5CFE); keep changing cells

       PUSH HL; RAM in the system

       LD HL, (# 5D00)

       PUSH HL

       LD HL, (# 5C00)

       PUSH HL

       LD A, 0; (# 5C00) should be 0

       LD (# 5C00), 0

       LD A, C; Number sector

       LD C, B

       LD (# 5CFF), A; Record N. Sector

       PUSH BC; retain N. Track


       LD IX, # 2EF0 <# 2F3A>; find the track on

       CALL TRDOS; drive


       LD BC, 00; linger
WAIT DJNZ WAIT; and

       DEC C; wait

       JR NZ, WAIT


       POP BC; extract N. Track


       LD IX, # 2EF0 <# 2F3A>; as we head

                     , Entered the appropriate place

       CALL TRDOS; then giving 'Search' to the same track

                     And we just push the head to

                     ; Disk drive and promote the

       LD IX, # 3F00 <# 3F0A>; disk spins, the head

                      ; Pressed, now -

                      ; Team read Sector

       LD HL, (ADR_LO); take the load address and

       LD (# 5D00), HL; place to work


       CALL TRDOS; assume one sector to drive

                      , The address of RAM

               ............

               etc., followed by code conversion

                       , How much is left to upload,

                       ; Which sectors and tracks.
;------------------------------------------------ 2

   I think the continuation of this
program, you can append
themselves (the algorithm can be taken from
previous example). Do not forget to return when leaving the
program from the stack all the saved values ​​in the area of 
​​system variables.



   A few words about
Written to disk. If in the above examples call 'READING
SECTOR 'replace' ENTRY IN
SECTOR 'and slightly alter
program, then you will have the
Finished in routine RECORD
fixed file. (See Chapter TRDOS functions, an example of the 
conservation state of the game 'Elite'). 

   You create a file from the BASIC
desired value for subsequent
write to data from a working program. Convey
attributes of this file during
Download the program into the body where
you have located your routine 'ZAPISI'-all.

   It's the easiest way to solve the problem. If you want to
write a complete program
'Save', then the rules for writing
the file to disk remain the
same as in the chapter 'Options TRDOS'.
And the information that you have already learned - will be 
enough to do it quite professionally.



   Now, when we learned how to
write - read from disk and
how to write a subroutine that does it, talk about
where to put this subroutine in
Reinvent program.

   Little about it has been said
in the chapter 'Options TRDOS', but
As we have already reached the level of
programming the controller, then
we have and opportunities appeared
more.

   How to build a decent
FULL 'loader / sohranitel' in a program that uses all the 
memory your computer if, moreover, does not want out

This program is nothing to throw, and do not want to ruin the 
screen?? There is a way! 

   Stuff This can have many different options, but
are the same: a remake
The program integrates a small sub-loader
(Only a few bytes), which is designed to keep
of RAM with address # 5C00 to address, for example, # 5FFF (4 
sectors, we hopefully will be enough) in the fixed the file, 
and for this a place to download a file from another fixed up - 
image of system variables and

BASIC loader, which
will carry out major work
read / write.

   After the end of the main loader must pass
Management at the little routine to restore
Reserved area of ​​RAM from the first file in its place.

   This is called the overlay
DOWNLOADING or 'pulling himself by his hair. " You are looking 
at disk space as an area of ​​more memory with the hard-coded 
addresses and pumped into it, or out of it what you need at the 
moment. Step by step it may look like this:



   Create two teams BASIC
File type CODE.

> RANDOMIZE USR 15619: REM: SAVE

  "BUFFER" CODE any address, 1024


   This is a file to save the RAM area of ​​the body Reinvent 
program during its operation. 

> RANDOMIZE USR 15619: REM:

  SAVE "SYSBOOT" CODE 23552,1024


   This image file system
variables and the main routine of the disk.


   Choose to Reinvent
program area for the placement of the auxiliary loader
and enter its code at this place.


   The file 'SYSBOOT' after copies
the entire range of system variables and buffer area is entered
our main routine of the disk.


   Now in the process of starting Reinvent program we must pass 
in the area of ​​satellite boot all 4 parameters: 

 - Number of first sector of file

   "BUFFER",
 - Number of the first track of this

   file
 - Number of first sector of file

   "SYSBOOT",
 - Number of the first track of this

   file.


   The length of the transfer is not necessary, so
as it is known initially.


   While working Reinvent the program, if it goes
the process of loading or saving, start the auxiliary
loader that first save area RAM address # 5C00
by # 5FFF in the file "BUFFER", and then it is place in the 
memory load from the file "SYSBOOT" copy of system variables and

MAIN routine work with
drive and pass control to it.


   Since all system variables and SOS TRDOS and restore, the 
main routine can work with the disk through any

FEATURES TRDOS. This means that
you have fallen away all the problems with
find a file on disk and
the recalculation of track numbers and
sectors - while reading from disk, while recording - the 
problem of recording the information on file in the directory 
and in the 8-th sector of the system! 


   Do not forget to register for IY
You must have a value of # 5C3A,
and set interrupt 1. A
also - re-install the stack, if it was set to the area, which 
remains at disk.


   After its completion the main routine should
pass control back to
auxiliary loader which restore from file "BUFFER"
the entire area of ​​the program stored on the disk, the old 
place in the RAM.


   The only downside to this method - it is a necessity
have all other files
program is also our 2 file.

   You can abandon the files
if you put a buffer conservation
and the main routine of working with
disk in specific sectors,
specific track disc. For example, you can use an empty sector 
to the zero track. Recall that a directory on our

the first seven sectors, the system
sector - the eighth, and the remaining
sector are free and the system does not
used (their uses routine ROM TRDOS during
save magico-file).

   If you do so,
then you get a program that will run only on
this disk. On the one hand, this
create problems when copying this software on another drive. It 
will be necessary to copy the program files are not 
interpreted, but the sector ZERO track

where you will have written the basic routine of the disk.

   On the other hand, the module
work with discs recorded on
these sectors, can use several applications at once, and
the programs themselves will be protected from
unauthorized copying from your hard drive as a boot module on 
the zero track while trying to 'blow out' you program will 
uncopied. 

   Such a disk can be copied only in its entirety TRACK
Copiers.

   And if you go ahead and place the sector with our routine on 
track specifically labeled with the number of such 161, on 
which the system will be just do not know what to fully copy 
the disc can not no copyist. But the protection of CDs, we will 
talk a little later. 


   Now consider those aspects of programming the controller,
hitherto mentioned
only in passing.


         FORMATTING


   The formatting process - it
account some special
sequence codes for the selected CYLINDER and side of the disc.
The largest number of cylinders on
drive depends primarily on
drive, as some have drive-stop, heads, stands at 80, while in 
others it can stand on 86 (limiter

purely mechanical).

   TRDOS formats the drive for 80
cylinders, writing in the 8 th sector 0 track 
information-signanalizator - what is the drive and how much 
free sectors on the disk.


   The procedure for formatting
one track is in ROM on
at # 1FC1 <# 1FFD>. Before this
heads must be brought to
desired cylinder and pinned to the top (even) or bottom (odd) 
side of the disc. Next comes the command 'TRACK RECORD' # F4. 


   Formatting is
the following sequence
bytes (these bytes are fed into
Port # 7F in routine at # 2075 <# 20B1>).

   For illustrative purposes, the table - that served to record
to disk, and that is recorded on
disk, as some bytes in the
team 'TRACK RECORD' interpretation
preted chip VG93,
as nested subcommands.


               TABLE ARRAY FOR ONE SECTOR



       THAT SERVED IN PORT FOR RECORDING THAT RECORD


                 10 bytes # 4E (beginning of the space)


                        12 bytes of zeros


       3 times the code # F5 (initialization code # A1, label

          counter kontr.summy) top IAM


              code # FE (Address index mark)


                      Track number of bytes

       (NOTE! Track number is written on the disk TRDOS
       Vaeth and on the top and bottom of the disc with the OAG
       Nakov - Room CYLINDER. Definition,

       what a track of 160 where there is, there is

       purely programmatically).


                      Byte of the disk

        (NOTE! TRDOS and upper and lower side

       disc marks byte 0, the definition of which side

       drive to be a member of the 160 tracks are

       purely programmatically).


             Byte sector number (counting from 1 to 16)


       Byte sector size (in TRDOS = 1, ie 256 bytes)


       Byte # F7 (subcommand - Two bytes

       written as computed k.summu) konrolnoy amount


              22 bytes # 4E (space before the data)


                           12 bytes of zeros


       3 times the code # F5 (initialization code # A1, top

          counter kontr.summy) data labels


               Code # FB (address label data)


                             256 zeros

                         (This data field)


            Byte # F7 (subcommand - Two bytes

        written as computed checksum k.summu


              50 bytes # 4E (remaining space)



   Once all 16 sectors per track are marked, the remaining 
space is filled with tracks Code # 4E.


   This array format
designed to drive
Dual density. For single-density disk drives will be different.

   For the double-density disk drives (Mode Modified
Frequency modulation) in the process of executing the "RECORD
WALK "chip receives and considers a subcommand following bytes:

B # F5 - entry code # A1, and for
           Start counter con
           trolnoy amount;
B # F6 - write code C2;
B # F7 - record counted

           checksum

           disc.


   In the process of programming a
You might want to format the individual tracks
on the drive differently. For example, in
the process of establishing secure
disks or hidden boot. No problem!

   You can format,
For example, the 163rd track on its
drive with only one sector
length of 1024 bytes and the system number 223, and this will 
only know your program, working with this track, and you

themselves.

   When you try someone else read your secret track and sector 
are likely to it will fail, because

that someone would not know the system facilities in this 
sector. IC VG93 it just does not

finds on the track, not to mention
about trying to read the content.

   (When you read this book
to the end and spend some efforts you can easily copy any such
CDs Any Boolean
Protection).


   Formatting the tracks can be
run through the other sub TRDOS, namely # 3FC0
<# 3FCA> (see above). Formed in
of RAM, the entire array of tracks,
how it should be on a disk,
can one go to record information from RAM to disk on the track, 
and thus reformatting it. 

   Calculate the table as
bytes of RAM it will take us all
array:

   376 bytes - it is one
sector and 376 * 16 = 6016 bytes per
the whole track (plus appendage,
about 200 bytes).

   When you format a track
their format, you must take this into account, and the length 
of the entire array of your size should not exceed this figure. 
Extra information is simply not recorded on the track. 


   DEFINITION Partitioning


   In some cases you may need to determine
marked as one or the other drive
(Eg, for 'opening' protected discs or discs labeled 
nonstandard). The system VG93 teams have a team: 'Reading the 
address', but it is designed to properly labeled disks, ie 
without any frills. 

   With it you can read the tag and index address TRDOSovskih 
and MSDOS-disk-native, and CP / M disks, but if you try to read 
an indexed address the label on the disk, where on one track, 
there are sectors with different lengths and numbers taken from 
the ceiling - that you will read the label of one sector, but 
to learn which sectors, how many and what are their numbers, 
you are unlikely to able. For this purpose there

'Clever' way.

   Recall. We have in reserve
left the team VG93 'READING
WALK IN WHOLE '. When this command reads the chip to track 
everything: the tags, and sync bytes, and data - in short, 
everything, everything, everything. Only drawback of this team 
- this is that when reading data from

Disk read bytes are not sampled. But we do not interfere.
So what? Imagine you got to
CD with suspicious markings.
Displays drive heads to
any path (usually
zero), pulls the head to
surface, give the command 'Read Track' and exit the subroutine 
TRDOS # 3FDB <# 3FE5> - Reading an array from the data port in

e M (HL) (of course, before
that you should reserve
buffer to read data
size of approximately 6,300
bytes, you can even on the screen).

   Repeat this process 2-3 times in a row reading for more
reliable reading, as bytes are not accompanied by a clock. And 
here you have the buffer will be an array of data of an entire 
track with all the official tags. And then quite simply.


   Recall, from which bytes begins IAM - Indexed address label. 
That's right - with bytes # A1 and # FE (who does not remember 
- See previous table, the array format). (For CDs

with single-density bytes before the code # FE will be another 
(maybe 00, and # C9, and # FF - in Depending on the initial 
array format). 

   We find these bytes in the buffer, and
after them, please, all data of one sector: track number, side, 
number and length of the sector. Remember these data in some 
kind of memory cells. Looking for The following two bytes # A1 
and # FE; and so until the entire buffer is not over. After 
that we will hold all the trumps, no matter what

was a dodgy format on the track. Scan the entire disk, we
obtain a map format for all tracks and sectors. But it is 
usually sufficient to scan 02/04 tracks.



       To be continued







Other articles:

Adventure Project - Design and razrabotaka Adventyurnyh and RPG games.

Adventure Project - Russification adventyur.

TR-DOS for beginners - Continued.

Authoring - Scorpion 2000 (S. Zonov).

Authoring - Trampoline (S. Veremeenko).

Business Card - a new electronic humor magazine "SpectrofUn".

Crossing Dragon - Promotion of the game Finders Keepers.

Crossing Dragon - Promotion of the game Knight Tyme.

Crossing Dragon - Game Promotions Spellbound.

Crossing Dragon - Game Promotions Stormbringer.

Retro - 40 best procedures: Merge images, rotation of the symbol clockwise Inverting character, changing the attribute, fill circuit construction templates (Dzh.Hardman, E. Hyuzon.).

Expert Tips - Total Eclipse 2.

Expert Tips Super League.

Forum Games - Description of the game land of myths.

Forum Games - Passage Renegade.

Forum Games - Subtleties trading game Elite

Forum - Studying and debugging @ files using STS 5.1. Features of debugging using a monitor STS. Bugfix STS 5.1.

Forum - compression programs.

forum - Reduction in the time format. On the recording sectors while formatting. Rebuilding the screen for one interrupt.

Forum - Features assembly ZX ASM 3.0.

Forum - As for the BASIC compiler "Blast".

Forum - With regard to relotsiruemyh programs.

Forum - Program "Flame" and "Dragon."

reader-reader - TR-DOS: how to avoid mistakes?

reader-reader - The effective work with the drive.

ethidium - The calculation of addresses in the file attributes. Program scrolling specified window 1 pixel to the right. Cleanup of the specified window. Procedure display images from the buffer.

Studies - LED channel music processor. The procedure for cleaning the screen. Proposal for standardization.

Studies - A set of eight programs of "extension" screen. Two procedures are manifestations of the screen.

Studies - New themes for development.

Studies - Playback software tool from the editors of digitized music.

Studies - processing program @ BASIC files.

Studies - The procedure for turning the symbol 90 degrees clockwise.

Studies - The procedure for searching text files.

Studies - Screen procedure "UP HL".


Темы: Игры, Программное обеспечение, Пресса, Аппаратное обеспечение, Сеть, Демосцена, Люди, Программирование

Similar articles:
News - sq: news around us.
WANTED - Searching software ...

В этот день...   5 May