ZX-News #54
30 декабря 2000

ZX Spectrum and the hard drive - Article Vlad Sotnikova / Vega about work and programming of the hard drive (HDD) on the Spectrum.

<b>ZX Spectrum and the hard drive</b> - Article Vlad Sotnikova / Vega about work and programming of the hard drive (HDD) on the Spectrum.
              Olden Z80



   I am pleased to present the story of Vlad's capital 
Sotnikova / Vega (St. Petersburg) of the phenomenon as a hard 
drive on Spectrum. This subject is covered from all sides, 
since the author - the best specialist in St. Petersburg 
(except MOA:)) to have regards SMUC'a, I mean the device

allows to work with "gadgets" in the
benefit Speccy!


   Now Vlad is working on the issue of connection to the 
Spectrum CD-ROM, although what that's us! He is already 
attached! But to CD-ROM fully earned, is required ff.

Information: ATAPI command list and description of the driver 
CD-ROM (in any human or machine language) and also a good idea 
to get the documentation to _not_ ATAPI CD-ROM'am - how they 
work, team. 


   Waiting for information at the following addresses:


   ZXNet: Vlad Sotnikov (500:812 / 08.9)

    Fido: Vlad Sotnikov (2:5030 / 885.50)


   If you do not have access to these networks, then
write to the editorial office, we will give
All Vlad.
__________________________________________

(C) Vlad Sotnikov / Vega, 2000


        -= Spectrum and HDD =

   1. Working with the hard drive on Spectrum'e.

   1.1. Introduction.

   1.2. Appeal to the hard drive.

   1.3. Device hard drive.

   1.4. Terminology.

   1.5. Accessing the registry Scorpion'e.

   1.6. Description of the registers.

   1.7. Reading data from the hard drive.

   1.8. Positioning the head.

   1.9. Writing data to the hard drive.

   1.10. Command Winchester.

   1.11. Determination of the configuration Winchester.


   2. The structure of the hard drive on the Scorpion.

   2.1. File structure of the hard drive.

   2.2. Structure description subsections.

   2.3. The internal structure of the subsections.

   2.4. How to run Is-Dos.

   2.5. Structure of the sub-TR-DOS.

   2.6. Sector Structure emulations.

   2.7. The calculation of the checksum.



  1. Working with the hard drive on Spectrum'e


   Everything that is written here is based on
my personal experience, and therefore almost all of the 
information is exclusive. As a consequence, the description can 
meet inaccuracies or defects, for which apologize in advance.




              1.1. Introduction


   This article focuses on programming the hard disk, also 
called "Winchester" on the computer Scorpion. On

Actually, if you have a hard drive connected
by another controller, then you just need to
know the port addresses of your controller, and
you with this article can learn
its programming.


   Winchester - is an integral component of any computer, 
especially now, when the amount of information in the hundreds 
and even thousands of times larger than memory computers. Such 
media as floppy disks, are losing their relevance. But despite 
this, Spectrum has long been without the hard drive, and he 
appeared only recently. K Unfortunately, the adaptation of the 
hard drive to the system TR-DOS does not allow much

part of its capacity and therefore, working with them directly, 
through the ports, you can not only a few times to increase 
speed hard disk drive, but also to transform

it into an analog computer memory, as, indeed, made at a
computer as a PC.



       1.2. Appeal to Winchester


   So, to Winchester, please contact
in two ways. The first option - a request by
driver. On a PC, it is a program that allows you to see the 
hard drive as storage for placing files in MS-DOS. On

Spectrum so the driver can be called
ProfPZU 4.01, which represents the hard disk as a collection of 
images of TR-DOS floppies. Image connects to drive A, B, C or D 
in terms of shadow monitor, and then the program works with one 
of these carriers, not suspecting that instead of a floppy 
disk, it communicates with the hard disk. This approach has 
some drawbacks. In particular, it supports only appeal to the 
TR-DOS through podgrogrammu # 3D13 (estestvenno!), and all 
sorts of treatment such as # 3D2F lead to that the program is 
on the TR-DOS hard drive image can not work. But it's not about 
that. 


   In addition to contact through # 3D13 shadow monitor offers 
an appeal to the hard drive via the command RST 8. I'm not one 
here describe how it works can be found

in the book "SMUC, instructions on connecting
and work, v1.2 ". But the second version of
only increases the speed of reading and writing
data and, therefore, be called a full-fledged
can not.



        1.3. Device hard drive


   Winchester - a device that has
internal controller to read, write and process information. 
Thus, the computer is not necessary to unscrew the drive and 
perform these procedures - they take on a controller. Actually 
programming the hard disk - is the transfer of his command, and 
the transmission / reception of information from him. 


   Winchester is the next logical
internal structure: it exists
a number of cylinders. In each
cylinder has a certain amount of
heads. And each head has a certain number of sectors. If you 
multiply all these values, we obtain the total number of

sectors (512 bytes) to your hard drive.
Dividing this number by 2, we know it
volume.


   It goes without saying that the logical
structure of the hard drive has nothing to do with his actual 
physical parameters. That is 16 heads does not mean that they 
are in the hard drive is really 16. Usually physical heads 3-4, 
while the number of sectors on each track varies,

as well as on CD-ROM. Nevertheless, to communicate with the 
hard drive must be through its logical parameters, except

case when addressing mode is specified in
LBA (Logical Block Addressing), ie
Winchester instead of cylinder / head / sector
immediately indicates the relative address. But
LBA mode I have described here will not, because I do not know 
exactly registers, where This 28-bit address is written.



   These registers you can pick yourself.
As I recall, here they are: the registers of the cylinder 
(both), the register of sectors, register drive / head 
register, and opportunities (Same as the error register, only

record). Registers themselves are detailed below.



            1.4. Terminology


   Before starting the description let us agree on terms that 
will be used by me in this article. 


   ■ Logical address: consists of 3 values: the cylinder 
number, head number and facilities sector.



   ■ Relative Address: 4-byte address
relatively early by the hard drive. Used in LBA mode. In the 
logical address is converted to a logical address subroutine 
SET_. At the Spectrum in the range 1.9 GB are used only 3 bytes.



   ■ Sector: hard drive it is 512
bytes. Therefore, under any sector referred to by me in this 
article, you must understand the 512 bytes. 


 1.5. Accessing the registry Scorpion'e


   Management controller is through registers. Each register in
controller SMUC corresponding port. He
will be indicated next to the register. Unfortunately, access 
to these ports Scorpion in the computer should take place with

ROM included TR-DOS. Therefore, the record values ​​in the port 
will be as follows: 

; OUT register A.
; In: [BC] - port number
; [A] - value to write to the port.
OUT_A LD IX, # 3FF0

        PUSH IX

        JP # 3D2F


   The fact is that when accessing this
the memory automatically ROM TR-DOS and run the command
OUT (C), A.


   Accordingly, reading:

; IN register A.
; In: [BC] - port number.
; Out: [A] - value read from the port.
IN_A LD IX, # 3FF3

        PUSH IX

        JP # 3D2F


   Here is the same, only holds
Team IN A, (C).


   In the following examples we will refer to these 
subprograms. Knowing them, you can read and write ports 
(Registers) hard drive. Below is a complete description of the 
registers. Please note that the younger the register value is 
always well # BE. It can be used to optimize code for speed

program.



         1.6. Description of Registers


          Command register (# FFBE)


   Register just for the record. This register
contains the command code sent by the hard drive. Command 
execution begins immediately after writing the register. It is 
known that the command # E6 down the hard disc. Write:



        LD A, # E6

        LD BC, # FFBE

        CALL OUT_A

        RET


   Your hard drive must stop.


        Status register (# FFBE)


   This register contains the drive status. The contents of 
this register is updated after each command. Accordingly, the 
bits of this register: 


      7 6 5 4 3 2 1 0


     BSY DRDY DWF DSC DRQ CORR IDX ERR



   - BSY (Busy). This bit is set immediately after the transfer 
of command Winchester and is reset only after it

this team will perform. That is, bit set indicates that the hard
drive executes the command and you do not "hear".


   - DRDY (drive ready). This
bit is set if the HDD is ready to take command.


   - DWF (Prohibition of writing to disk). Bit indicates the 
current state prohibition records (?). 


   - DSC (disk drive installation is completed).
Bit indicates that the drive heads are mounted on the track.


   - DRQ (Data Request). Bit indicates
that the drive is ready to transfer a word or
byte of data between computers and storage.


   - CORR (Corrected Data). Bit indicates that when reading 
data occurred correction and data have been corrected.



   - IDX (Index). Bit is set when
each revolution of the disc.


   - ERR (Error). Bit indicates that the
During the previous command failed. More
to the cause of the error contained in
Register errors.


   Most significant for us are
bits BSY, DRQ, and ERR. When a team to
hard drive requires the following steps:


   1. Command is given (via the Command register).

   2. We are waiting for removal of the signal BSY.

   3. Enjoying a bit of ERR. If it is set - read the error 
register and process error.



   Let's write a subroutine that will be waiting for reset 
signal BSY: 

NO_BSY LD BC, # FFBE

        CALL IN_A

        RLCA

        RET NC

        JR NO_BSY


   We run around in a loop as long as
BSY signal will not be withdrawn. Each team
must be terminated by an appeal to this routine.


   Sub-validation errors:

ERR_ LD BC, # FFBE

        CALL IN_A

        RRCA

        RET


   If the output of the carry flag is set, the command was 
executed with an error. 


   And our previous example, stopping the hard drive will look 
like as follows:



      LD A, # E6

      LD BC, # FFBE

      CALL OUT_A

      CALL NO_BSY

      CALL ERR_

      JP C, ERROR ...

      RET


   So, now known as the fully
send a command to the hard drive. Below I give a subroutine 
that does this. 

; HDd Send Command.
; IN: [A] - command code.
; OUT: CY - Operation completed with error.
HDSC LD BC, # FFBE

      CALL OUT_A; send command.

      CALL NO_BSY; waiting for execution.

      JP ERR_; look, there are no errors.



   The following registers indicate the number of cylinders, 
heads and sectors with which the operation occurs. So, when 
reading these registers, we learn the place where the head. 
When recording in the registers of other values ​​of the head 
does not change its position, but when doing a read / write, it 
is positioned in accordance with values ​​set in these 
registers. 

 Register of the cylinder (the highest part) (# FDBE)


   This register contains the high part of the initial cylinder 
number for any disk operation. After the command this register 
is modified, and always reflect the current cylinder number. 
Elder cylinder number bits to be loaded into the register.


 Register of the cylinder (the youngest part) (# FCBE)


   This register contains the lower 8 bits of the initial 
cylinder number for any disk operation. After issuing the 
command This register is modified, and always reflects the 
current cylinder number. 


      Register sector number (# FBBE)


   This register contains the starting number
sector for every data operation. Sector number can be from 1 to 
maximum number of sectors per track. 


    Register memory / Heads (# FEBE)


   This register contains the number of heads and
drive. The contents of this register sets the number of the 
drive and head number for command Initialize Drive Parameters.



       7 6 5 4 3 2 1 0


       1 LBA 1 DRV HS3 HS2 HS1 HS0



   - DRV - drive selection bit. If
DRV = 0, then select drive 0, if the DRV = 1,
then select drive 1.


   - LBA - bits indicate enabled or disabled LBA.


   - HS3 ... HS0 contain binary numbers head (starting from 
zero), which will selected. For example, if HS3 ... HS0 =% 0011,

will be selected head 3. HS3 - Senior
bits. After completion of the command this register
modified and always contains the current
number of the selected heads.


   Fourth bit is very interesting. He sets the device slave \ 
master, with whom should operate the computer. So, if we

want to switch from the primary hard drive to a second, 
parallel connection, then we need only set this bit and

record number in the register. All subsequent commands will 
work with the selected device. 


    Sector count register (# FABE)


   This register contains the number of transmitted data 
sectors for read / record. A value of zero corresponds to 256

sectors.


   When the command is read or
write sectors in this register records the number of sectors 
that need to be send or receive. Next, it looks

as follows: we pass the byte
sector, and read the register counter sectors. The number in 
this register will show the number of rough sectors. The number 
0 indicates that the read / write completed. 


          Registry Errors (# F9BE)


   This register contains the drive status, after the last 
command or a diagnostic code.



   After the completion of any command except Execute Drive 
Diagnostic, this register contains the error code if bit ERR

in the status register is set (ERR = 1).


    7 6 5 4 3 2 1 0


   BBK UNC 0 0 IDNF ABRT TK0NF AMNF



   - BBK (Bad Block Meeting). Bit indicates that when the 
operation was received by the sector with the wrong label in 
the header block of the sector. 


   - UNC (Uncorrectable Data Error).
Bit indicates that during the operation was
met with a fatal error in zone data.


   - IDNF (Sector not found). Bit indicates that the title of 
this sector is not found.



   - ABRT (command aborted). Bit indicates that execution of a 
given command was aborted due to an error state hard drive (not 
ready yet, ban entry, etc.) or when an invalid command code.



   - TK0NF (Track 0 not found). Bit
indicates that, under the command Recalibrate track 0 not found.


   - AMNF (not found address marker). Bit
indicates that the address marker is not found
After finding the correct header sector.


   - Unused bits are cleared.


   Data register (the highest part) (# D8BE),
Data register (low part) (# F8BE).



     1.7. Reading data from hard drive


   Through the Data Register data exchange between computer and 
hard drive. So, if we want to consider a sector with hard 
drive, then we give the command "read". Further, the hard drive 
reads one 512baytny sector in its buffer and waits. Then We 
read the younger part of the sector, put in memory. Then older. 
And so 256 times. It turns out 512 bytes. It is interesting 
that among reading the bytes can be arbitrarily long pause - 
the hard drive knows how many bytes we have taken. Then we read 
the value of the register counter sectors. If the number is not 
0, then repeat the cycle over again. Thus reads the sectors 
from the hard drive. Below contains this subroutine. In HL 
should be given a place in memory where the read

in A - the number of 512-byte sectors.

; Read the sector, given <HDSC>.
; IN: HL-buffer for reading, A-SECTORS
READ LD B, A

        PUSH BC

        LD BC, # FABE

        CALL OUT_A

        LD (BUF), HL

        LD A, # 20

        CALL HDSC; command to read ...

        POP BC
READ1 PUSH BC

        CALL READ_S; read Sector

        POP BC

        DJNZ READ1

        RET

; READ Sector.
; Read sector ...
READ_S LD HL, (BUF)

        LD BC, # 00BE

        LD DE, # D8F8
READ_1 PUSH BC

        LD B, E

        CALL IN_A

        LD (HL), A

        INC HL

        LD B, D

        CALL IN_A

        LD (HL), A

        INC HL

        POP BC

        DJNZ READ_1

        LD (BUF), HL

        RET

BUF DS 2; Temporary variable for

             store the address in memory

             read / write.



      1.8. Positioning the head


   I think you have not forgotten that before calling the READ 
command must specify the Winchester location from which to 
read. This can be do the following routine:


; Write Cylinder, Head, Sector.
; Write to the cylinder number registers /
; Head / sector.
; IN: DE-cylinder, H-head, L-sector.
W_CHS LD BC, # FEBE

        LD A, # A0; # B0 - slave.

        XOR H

        CALL OUT_A

        DEC B

        LD A, D

        CALL OUT_A

        DEC B

        LD A, E

        CALL OUT_A

        DEC B

        LD A, L

        JP OUT_A


   Subroutine that performs the opposite action, ie, 
determining the position of head of the hard drive, will look 
as follows: 

; Read Cylinder, Head, Sector.
; Read the current cylinder / head / sector.
; OUT: DE-cylinder, H-head, L-sector.
R_CHS LD BC, # FEBE

        CALL IN_A

        AND # 0F

        LD H, A

        DEC B

        CALL IN_A

        LD D, A

        DEC B

        CALL IN_A

        LD E, A

        DEC B

        CALL IN_A

        LD L, A

        RET


   If you need to specify the relative address, you can use 
subroutine SET_. For her work requires that

SECTOR cell was the number of sectors on the hard drive, and in 
cell SH_SUM - product heads, and sectors.


; Install crown D, H, L.
; ADDRESS OFFSET - CIL / HED / SEC
; IN: D, H, L - 24-bit address.
; OUT: given the installation head.
SET_ LD (SET_3 +1), HL

        LD HL, 0, E, H

        LD A, D

        OR A

        JR Z, SET_1

        LD D, L
SET_2 PUSH HL

        PUSH DE

        LD HL, # FFFF

        LD DE, (SH_SUM)

        PUSH AF

        CALL DIV

        POP AF, DE

        INC HL

        ADD HL, DE

        EX DE, HL

        POP HL

        ADD HL, BC

        DEC A

        JR NZ, SET_2
SET_1 PUSH HL, DE
SET_3 LD HL, # 2121

        LD DE, (SH_SUM)

        CALL DIV

        POP DE

        ADD HL, DE

        EX DE, HL

        POP HL

        ADD HL, BC

        PUSH HL

        EX DE, HL

        LD DE, (SH_SUM)

        CALL DIV

        EX DE, HL

        POP HL

        ADD HL, BC

        PUSH HL

        EX DE, HL

        LD A, (SECTOR)

        LD D, 0, E, A

        CALL DIV

        LD H, C

        INC L

        POP DE

        CALL W_CHS

        RET

; Division. <>
DIV LD A, E

        OR D

        RET Z

        XOR A

        LD C, A, B, A

        EX DE, HL
DIVW1 INC B

        BIT 7, H

        JR NZ, DIVW2

        ADD HL, HL

        JR DIVW1
DIVW2 EX DE, HL
DIVW3 OR A

        SBC HL, DE

        JR NC, DIVW4

        ADD HL, DE
DIVW4 CCF

        RL C, A

        RR D, E

        DJNZ DIVW3

        LD B, A

        RET

SH_SUM DB heads * sectors.
SECTOR DB number of sectors.



     1.9. Writing data to a hard drive


   To record information on a hard drive,
you must install the head using
sub W_CHS or SET_ and perform
following routine:

; Writing sector, given <HDSC>.
; IN: HL-buffer for writing, A-SECTORS
WRITE LD B, A

        PUSH BC

        LD BC, # FABE

        CALL OUT_A

        LD (BUF), HL

        LD A, # 30

        CALL HDSC; team to write ...

        POP BC
WRITE1 PUSH BC

        CALL WRITE_S

        POP BC

        DJNZ WRITE1

        RET

; WRITE Sector.
; Write sector ...
WRITE_S LD HL, (BUF)

        LD BC, # 00BE

        LD DE, # D8F8
WRITE_1 PUSH BC

        LD B, D

        INC HL

        LD A, (HL)

        CALL OUT_A

        LD B, E

        DEC HL

        LD A, (HL)

        CALL OUT_A

        INC HL

        INC HL

        POP BC

        DJNZ WRITE_1

        LD (BUF), HL

        RET



     1.10. Command Winchester


   Below I will provide a list of commands relevant when 
working with the hard drive on the Spectrum. 


            Identify Drive (# EC)

       (Identify Drive)


   After the team must wait for the installation DRQ signal and 
perform routine READ_S, pre-recorded in cell (BUF) address in 
memory where the read data on your hard drive. Here are the 
most important:



   2 - number of cylinders (2 bytes);

   6 - number of heads (2 bytes);

   12 - number of sectors (2 bytes);

   20 - serial number (20 characters);

   +40 - Buffer type hard drive (2 bytes);

   42 - Buffer size in sectors (2 bye
         ma);

   +46 - Firmware (8 characters);

   54 - model name (40 characters).


   This number of heads, sectors and cylinders, in most cases
turn out to be false. In addition, all textual information is a 
custom format. First is the high byte, and then junior. To make 
it readable kind of need to change the first byte of the second,

the third with the fourth, etc.


   The whole text is left-aligned and
padded with spaces. In case the first
bytes of text - 0, then the name is not defined.


   The buffer type is the hard drive:


    0 - not defined.


    1 - Single Buffering, Winchester
can not perform simultaneous read and write operations.


    2 - double buffering. Winchester can simultaneously read 
and write information.



    3 - double buffering, in addition
reading is carried out with caching.


   The cell size of the buffer indicates which
volume has an internal buffer hard drive.
The larger the buffer size, the higher the rate of
exchange of data between hard disk and the computer.


        Idle (# 97, # E3, # 95, # E1)

       (Go to the passive mode)


   Occurs stop the hard drive to the next command.


            Recalibrate (# 1x)

             (Recalibration)


   This command moves the head read /
records from any location in the disk at cylinder 0.
If the drive can not install head
zero-cylinder, generating an error
"Track Not Found" (Track Not Found).


           Read Sector (s) (# 20)

           (Read sector (s))


          Write Sector (s) (# 30)

           (Write Sector (s))


   Work teams described above.


             Sleep (# 99, # E6)

               (Stop)


   Winchester is completely stopped.
The only way to get your hard drive
Stop mode without powering down
Hardware and software reset is
reset.


        Standby (# 96, # E2, # 94, # E0)

             (Standby)


   This command takes the hard disk into standby mode. If the 
disc is already stopped, then sequence of stopping drive fails.



 1.11. Determination of the hard drive configuration


   I also want to talk about how I
managed to write a subroutine that determines the true the 
logical geometry of the hard drive. 


   It is well known, and I'm here to write about it
that logical hard disk geometry
You can read from the sector caused by
team Identify Drive, and it does so the Shadow Monitor option 
Auto Detect Hard Disk. But 25% of cases, this information

turns out to be wrong.


   How do you know the real meaning of cylinders / heads / 
sectors of your hard drive? After all, rely on the words the 
seller from whom you buy this hard drive is very unreliable. 


   My own idea is very simple: let's say you
give the hard drive, click to read 256
sectors. Reads one sector (sub READ_S). Now, in the registers 
of the cylinder / head / sectors recorded values ​​following 
the order in Gaza. That is the number of the sector increased 
by 1. Read the next sector. And as soon as

sector to take the value 1 and increased number of heads, then 
the previous value sector and there are a number of sectors on 
the disk. Same with the heads (wait until the head is not to 
take the value 0 and increased number of sectors). Since the 
cylinders more complicated, but, on the other hand, if we work 
within existing subdivisions, to know the maximum number of 
cylinders does not necessarily - beyond the hard drive you do 
not quit. Nevertheless, to determine the number of cylinders it 
is possible - for example, reading 0 and head 1 sector each 
cylinder until it fails, then there is still the sector will 
not be found. 


   Presented here the software automatically determines the 
number of heads and sectors on the disk. The label should TABL 
indicate a 512-byte buffer. 

, Automatic configuration of screw.
; OUT: [H] - HEADS.
; [L] - SECTORS.
A_CONF LD DE, 0

        LD H, D

        LD L, E

        CALL W_CHS

        LD A, # EC

        CALL HDSC

        LD BC, # FFBE

        CALL IN_A

        OR A

        RET Z; device does not

        CALL R_CHS

        OR A

        LD HL, # EB14

        SBC HL, DE

        RET Z; a CD-ROM

        CALL NO_BSY

        LD DE, 0

        LD HL, # 0002

        CALL W_CHS

        LD A, 65

        LD BC, # FABE

        CALL OUT_A

        LD A, # 20

        CALL HDSC

        CALL NO_BSY

        LD BC, # FBBE
A_CONF2 PUSH BC

        CALL IN_A

        LD D, A

        PUSH DE

        LD BC, # FFBE
A_CONF3 CALL IN_A

        BIT 3, A

        JR Z, A_CONF3

        LD HL, TABL

        LD (BUF), HL

        CALL READ_S

        CALL NO_BSY

        POP DE

        POP BC

        CALL IN_A

        SUB D

        JR NC, A_CONF2

        LD A, D

        PUSH AF

        LD (A_CONFS-1), A

        LD A, 1

        LD (A_CONFS), A
A_CONFS EQU $ +2

        LD HL, # 0100

        LD DE, 0

        CALL W_CHS

        LD A, 2

        LD BC, # FABE

        CALL OUT_A

        LD A, # 40

        CALL HDSC

        CALL NO_BSY

        LD BC, # FEBE

        CALL IN_A

        LD HL, A_CONFS

        AND 15

        OR A

        JR Z, A_CONFH

        INC (HL)

        JR A_CONFS-2
A_CONFH LD A, (HL)

        INC A

        LD H, A

        POP AF

        LD L, A

        RET



     2. The structure of hard disk partitioning

          Scorpion on a computer


   The system MS-DOS programs for the Spectrum, of course, to 
work without some and very time-consuming adaptation can not.

Required to create a hard disk system TR-DOS. The authors of 
the Shadow Monitor approached this problem fairly original: on 
the hard drive creates a sequence of TR-DOS disk images, and 
each of these images can be "connected" to the carrier A, B, C 
or D and the operating system TR-DOS will work with this way, 
not knowing that it's not a real disk. Hence it is the 
terminology: drive physical (floppy diskette drive), and 
emulated drive (HDD-image). 



    2.1. File structure Winchester


   Structural organization of accommodation on
hard drive information is as follows
manner.


   1. Will create a global sub-wearing always the name of MFS 
(MOA File System?). Shadow Monitor will work only with him. In 
addition to this subsection to hard drive can be sub-

other operating systems. Thus,
one hard drive can be used on
Spectrum and other computers.


   2. Within the global sub-creates the so-called local 
sections. They may be the following:



   - TR-DOS. This section contains a sequence of TR-DOS disk 
images (1 to 51). 


   - MicroDos. As the author wrote of the Shadow
Monitor this subsection is reserved
for compatibility with PCs that use this
OS and application support for this sub-section planned to 
write in the future. But so far nothing written and was not.



   - IS-DOS. Subdivision for the OS with the same name.


   - BAD. With the help of this subsection to
Winchester covers an area that has
bad sectors.


   Ways to work with this structure, the hard drive via the 
menu of the Monitor and the Shadow subroutine RST 8 are quite 
diverse. Here I will describe how this

structure looks like from the inside. "



    2.2. Subsections describe the structure


   List of global sub is 0 for the sector (0 cylinder
0 head 1 sector) at # 01BE, and
occupies 16 bytes, where:


   0 - At MOA 0.


   1 - head |

   2 - Sector | beginning

   3 - cylinder (?) | Subdivision.


   4 - at MOA # 53 - MFS.


   5 -?

   6 -?

   7 -?


   +8 |

   +9 | Relative address

   +10 | Subdivision.

   +11 |


   +12 |

   +13 | Length sub

   +14 | (In sectors).

   +15 |


   Total number of such descriptors can be 4.
Fourth byte # 53 - a sign of sub-
MFS. Meaning 5, 6 and 7 of the byte I guess so and failed. 
Also, I'm not quite sure of the meaning third byte. 
Nevertheless, 2 nd and third bytes indicate the location

list of local subdivisions.


   It takes 2 sector (1024 bytes).
Description of each subsection is 16
bytes as follows.


   0 - type of sub-section:

        1 - TR-DOS.

        2 - MicroDos.

        3 - Is-DOS.

        4 - BAD.


   +1 |

   +2 | Relative address

   +3 | Subdivision.

   +4 |


   +6 |

   +7 | Length sub

   +8 | (In sectors).

   +9 |


   10 - Name of sub-section (6 characters).


   With the 4-byte relative address, we can turn to the top of 
any local subdivision.




  2.3. The internal structure of sub-


   Subsections MicroDos and BAD internal
structures do not have. Subdivision IS-DOS such
structure has, but she is determined entirely just this 
operating system. Here I will only tell you how to run the 
IS-DOS, located on the hard drive. 



        2.4. How to run IS-DOS


   The launch will take place with the help of sub RST 8. To do 
this, run the following routine: 


      LD DE, name of the subkey *

      LD A, 15; connect to the drive "D"

      LD H, A; glitch MOA: SET 4, (HL)

      LD C, 35

      RST 8

      DB # 81

      LD HL, buffer for 1 sector.

      PUSH HL

      LD BC, # 0124, read 1 sector.

      LD DE, 1

      RST 8

      DB # 81

      POP HL

      LD A, (HL)

      CP # 18; jr $+... ?

      RET NZ; nezapuskaemy IS-DOS

      JP (HL); launched


   I note that in some cases, IS-DOS starts incomplete. What
this case: whether the stack, whether in kakoylibo installed 
wrong page - to determine yourself. 



     2.5. Structure of the sub-TR-DOS


   Now consider the sub-TR-DOS. He
is one of the central sub-
on the hard drive, because most programs work with this 
operating system. Therefore, we consider it in detail. 
Structure of the sub is as follows: in the first two sectors is 
a description of TR-DOS disk images. Description absolutely 
similar in structure to the description of the local drives. 
Each disk is described 16 bytes, where 0 - is always 1 (TR-DOS),

1 - e disk image, plus 1, 6 - length of the disc (always 1, 5, 
0, 0 - as length of the TR-DOS image is strictly fixed:

1280 a 512-byte sectors), 10 - name
disc. Standard name - Disk??, Where? -
serial number of the disk, but it can be painless for the 
Shadow Monitor change. 


   Please note that the address drive
on the hard drive to add 1 sector. The fact is that before each 
disc unclear why there is a 512-byte region filled with zeros.



   I also want to draw attention to the maximum number of disk 
images in TR-DOS section. I've an opinion that there may be 
more than 51. Explain what is misleading: the fact that the 
Shadow Monitor for Treatment to the disks inside the sub uses a 
16-bit register. With respect to the sub-address 51-second 
drive to be # FF33, and the address of 52-second drive would 
have been # 010434. That is why the maximum number of drives in 
the subsection - 51. 



     2.6. Sector Structure emulations


   Each subsection or a disk image can be
connected to a driver A, B, C or D. Information about the 
emulation is in 2 relative to the sector if the Shadow Monitor 
does not work in LBA mode, and 3 relative to the sector, if the 
flag is LBA enabled. Her length - 1 sector. Each disc is 
described by 22 Bytes:



   0 - type of sub-section (0 - no emulation).


   +1 |

   +2 | Disk address / subdivision.

   +3 |

   +4 |


   5 - the type of subdivision.


   +6 |

   +7 | Length CD / subsection.

   +8 |

   +9 |


   10 - Name of sub-section (6 bytes).


   16 - drive name / subsection (6 bytes).


   If we connect the disk image, then 10 will be the name of 
the subsection, and 16 - the name of a disk image (Disk01 and 
the like). If not connected to TR-DOS sub-section, then

16 will be addressed in sub-section (ie the same
as in 10).


   To fully connect the drive or
subkey, follow these
steps:


   1. Connect the emulation via RST 8. Emulation prescribe an 8 
page. 


   2. Consider the sector from the hard drive emulation.


   3. Change the emulation drive.


   4. Record CRC in the sector emulation.


   5. Save this sector on the hard drive.


   It is very important when the simulation to calculate the 
checksum. If while reading this the shadow Monitor checksum 
does not match, then he would withdraw emulation of all four 
discs. 


   To calculate the correct checksum, must do the following:


        LD DE, sector in the memory.

        LD BC, 508

        CALL CRC

        LD HL, sector + 508.

        LD (HL), E

        INC HL

        LD (HL), D

        RET



       2.7. Checksum calculation


   The code below courtesy of the CRC to me MOA and is a
himself, as he explained to me, "hybrid" CRC-16
and CRC-32.

; Cyclic Redundancy Check.
; Calculation of the checksum.
; IN: [DE] - START, [BC] - LENGHT
; OUT: [DE] - CRC-SUMM.
CRC LD HL, # FFFF

        PUSH IX

        PUSH DE

        POP IX

        EX DE, HL
CRC_1 LD HL, CRC_TAB

        LD A, (IX)

        INC IX

        XOR E

        ADD A, L

        LD L, A

        JR NC, CRC_2

        INC H
CRC_2 LD A, D

        XOR (HL)

        LD E, A

        INC HL

        XOR A

        XOR (HL)

        LD D, A

        DEC BC

        LD A, C

        OR B

        JR NZ, CRC_1

        POP IX

        RET

CRC_TAB DW # 0000, # 1021, # 2042, # 3063

        DW # 4084, # 50A5, # 60C6, # 70E7

        DW # 8108, # 9129, # A14A, # B16B

        DW # C18C, # D1AD, # E1CE, # F1EF

        DW # 1231, # 0210, # 3273, # 2252

        DW # 52B5, # 4294, # 72F7, # 62D6

        DW # 9339, # 8318, # B37B, # A35A

        DW # D3BD, # C39C, # F3FF, # E3DE

        DW # 2462, # 3443, # 0420, # 1401

        DW # 64E6, # 74C7, # 44A4, # 5485

        DW # A56A, # B54B, # 8528, # 9509

        DW # E5EE, # F5CF, # C5AC, # D58D

        DW # 3653, # 2672, # 1611, # 0630

        DW # 76D7, # 66F6, # 5695, # 46B4

        DW # B75B, # A77A, # 9719, # 8738

        DW # F7DF, # E7FE, # D79D, # C7BC

        DW # 48C4, # 58E5, # 6886, # 78A7

        DW # 0840, # 1861, # 2802, # 3823

        DW # C9CC, # D9ED, # E98E, # F9AF

        DW # 8948, # 9969, # A90A, # B92B

        DW # 5AF5, # 4AD4, # 7AB7, # 6A96

        DW # 1A71, # 0A50, # 3A33, # 2A12

        DW # DBFD, # CBDC, # FBBF, # EB9E

        DW # 9B79, # 8B58, # BB3B, # AB1A

        DW # 6CA6, # 7C87, # 4CE4, # 5CC5

        DW # 2C22, # 3C03, # 0C60, # 1C41

        DW # EDAE, # FD8F, # CDEC, # DDCD

        DW # AD2A, # BD0B, # 8D68, # 9D49

        DW # 7E97, # 6EB6, # 5ED5, # 4EF4

        DW # 3E13, # 2E32, # 1E51, # 0E70

        DW # FF9F, # EFBE, # DFDD, # CFFC

        DW # BF1B, # AF3A, # 9F59, # 8F78

        DW # 9188, # 81A9, # B1CA, # A1EB

        DW # D10C, # C12D, # F14E, # E16F

        DW # 1080, # 00A1, # 30C2, # 20E3

        DW # 5004, # 4025, # 7046, # 6067

        DW # 83B9, # 9398, # A3FB, # B3DA

        DW # C33D, # D31C, # E37F, # F35E

        DW # 02B1, # 1290, # 22F3, # 32D2

        DW # 4235, # 5214, # 6277, # 7256

        DW # B5EA, # A5CB, # 95A8, # 8589

        DW # F56E, # E54F, # D52C, # C50D

        DW # 34E2, # 24C3, # 14A0, # 0481

        DW # 7466, # 6447, # 5424, # 4405

        DW # A7DB, # B7FA, # 8799, # 97B8

        DW # E75F, # F77E, # C71D, # D73C

        DW # 26D3, # 36F2, # 0691, # 16B0

        DW # 6657, # 7676, # 4615, # 5634

        DW # D94C, # C96D, # F90E, # E92F

        DW # 99C8, # 89E9, # B98A, # A9AB

        DW # 5844, # 4865, # 7806, # 6827

        DW # 18C0, # 08E1, # 3882, # 28A3

        DW # CB7D, # DB5C, # EB3F, # FB1E

        DW # 8BF9, # 9BD8, # ABBB, # BB9A

        DW # 4A75, # 5A54, # 6A37, # 7A16

        DW # 0AF1, # 1AD0, # 2AB3, # 3A92

        DW # FD2E, # ED0F, # DD6C, # CD4D

        DW # BDAA, # AD8B, # 9DE8, # 8DC9

        DW # 7C26, # 6C07, # 5C64, # 4C45

        DW # 3CA2, # 2C83, # 1CE0, # 0CC1

        DW # EF1F, # FF3E, # CF5D, # DF7C

        DW # AF9B, # BFBA, # 8FD9, # 9FF8

        DW # 6E17, # 7E36, # 4E55, # 5E74

        DW # 2E93, # 3EB2, # 0ED1, # 1EF0


    __________________________________







Other articles:

ZX Spectrum and the hard drive - Article Vlad Sotnikova / Vega about work and programming of the hard drive (HDD) on the Spectrum.

ZX-Party - the result of hot and controversial debate in a long year.

Hotline - Site "ZX-News"! Plus something to SOSG.

From the Editor - Happy new year, century and millennium!

Presentation - Interactive Fiction: a new word! New game and editor adventyur.


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

Similar articles:
No need la la! - very funny poems.
News - The Belarusian team Ellipse completely ceased creativity on the platform zx
Advertising - Advertisements and announcements ...

В этот день...   21 November