556BH
LD A,0DH
Let Register A equal 0DH (ASCII: CARRIAGE RETURN).
556DH
GOSUB to 0033H to display the character held in Register A at the current cursor position.
The next routine verifies the tracks.
5570H
LD D,00H
Let Register D equal 00H.
5572H
LD L,D
Copy the contents of Register D into Register L.
5573H
LD H,5CH
Let Register H equal 5CH, which MSB of the in-RAM representation of the GAT table of the disk being formatted. At this point, HL now points to the in-RAM GAT
5575H
LD A,(HL)
Fetch the byte from the in-RAM GAT (pointed to by Register Pair HL) and store it into Register A.
5576H
INC A
INCrement the value stored in Register A by 1 to make it easier to test to see if it was FFH or not.
5577H
If it was FFH, then the Z FLAG (Zero) will have been set, so JUMP to 55BDH.
557AH
LD A,D
If it wasn't FFH then copy the contents of Register D into Register A.
557BH
GOSUB to 5726H to to set Registers C and B to the ASCII bumber corresponding to Register A (Tens Digit in ASCII to C and Ones Digit in ASCII to B).
557EH
LD (5AB0H),BC
Store the value held in Register Pair BC into memory location 5AB0H which is the xx of the "VERIFYING TRACK xx, SECTOR yy" message.
5582H
LD E,00H
Let Register E equal 00H.
5584H
PUSH DE
Temporarily save the contents of Register Pair DE to the top of the stack.
5585H
LD A,D
Copy the contents of Register D into Register A.
5586H
GOSUB to 5767H to send a nnH to the disk drive select latch address and RETurn.
5589H
LD A,E
Copy the contents of Register E into Register A.
558AH
GOSUB to 5726H to to set Registers C and B to the ASCII bumber corresponding to Register A (Tens Digit in ASCII to C and Ones Digit in ASCII to B).
558DH
LD (5ABBH),BC
Store the value held in Register Pair BC into memory location 5ABBH which is the yy of the "VERIFYING TRACK xx, SECTOR yy" message.
5591H
LD HL,5A9FH
Let Register Pair HL equal 5A9FH to point to the message 1DH + "VERIFYING TRACK xx, SECTOR yy" + 03H
5594H
GOSUB to 429AH (part of SYS0/SYS) to send the message pointed to by Register Pair HL to the video display.
5597H
POP DE
Restore DE from the stack.
5598H
LD BC,5D00H
Let Register Pair BC equal 5D00H, which will be a buffer for the READ SECTOR subroutine about to be called.
559BH
GOSUB to 42AAH to read a sector from the disk. D must hold the track, E must hold the sector, and BC must point to the start of the memory buffer to hold the sector data. On exit, Register A holds the FDC Status.
559EH
LD HL,5ABEH
Let Register Pair HL equal 5ABEH to point to the message ": NOT FOUND! TRACK LOCKED OUT!" + 0DH.
55A1H
BIT 4,A
Test Bit Number 4 of Register A which would be the FDC status of "RECORD NOT FOUND" if high. Z FLAG will be set if that bit is 0, and NZ FLAG will be set if that bit is 1.
55A3H
If the NZ FLAG (Not Zero) has been set, JUMP to 5719H to display the message pointed to by Register Pair HL, put a FFH into the in-RAM GAT at 5Cnn (nn = the contents of Register D), and then JUMP to 55BDH.
55A6H
LD HL,5ADDH
Let Register Pair HL equal 5ADDH to point to the message ": CRC ERROR! TRACK LOCKED OUT!" + 0DH
55A9H
BIT 3,A
Test Bit Number 3 of Register A which would be the FDC status of "CRC ERROR" if high. Z FLAG will be set if that bit is 0, and NZ FLAG will be set if that bit is 1.
55ABH
If the NZ FLAG (Not Zero) has been set, JUMP to 5719H to display the message pointed to by Register Pair HL, put a FFH into the in-RAM GAT at 5Cnn (nn = the contents of Register D), and then JUMP to 55BDH.
55AEH
LD HL,5AFCH
Let Register Pair HL equal 5AFCH to point to the message 0AH + "CAN'T VERIFY, DISK TRANSFER RATE TOO FAST!" + 0DH.
55B1H
BIT 2,A
Test Bit Number 2 of Register A which would be the FDC status of "LOST DATA" if high. Z FLAG will be set if that bit is 0, and NZ FLAG will be set if that bit is 1.
55B3H
If the NZ FLAG (Not Zero) has been set, JUMP to 56ADH to display HIT ENTER TO CONTINUE, loop until an ENTER is hit, and then HALT the system.
55B6H
INC E
INCrement the value stored in Register E by 1 to point to the next sector to be read.
55B7H
LD A,E
Copy the contents of Register E into Register A for testing.
55B8H
CP 0AH
Compare the value held in Register A against 0AH (Decimal: 10). If Register A equals 10, the Z FLAG is set; otherwise the NZ FLAG is set.
55BAH
If the NZ FLAG (Not Zero) has been set then we have not yet hit 10 sectors on the track, so JUMP BACK to 5584H.
While this can be a pass through, it is also the jump point if the byte in the in-RAM GAT was FFH
55BDH
INC D
INCrement the value stored in Register D by 1 to move to the next track.
55BEH
LD A,D
Copy the contents of Register D into Register A.
55BFH
CP 23H
Compare the value held in Register A against 23H (Decimal: 35). If Register A equals 35, the Z FLAG is set; otherwise the NZ FLAG is set.
55C1H
If the NZ FLAG (Not Zero) has been set, then we have not yet hit 35 tracks, so JUMP BACK to 5572H to keep reading.
At this point, we have verified all tracks, now lets make a duplicate copy of the GAT into 5C60H.
55C4H
LD HL,5C00H
Let Register Pair HL equal 5C00H, which is the source RAM area.
55C7H
LD DE,5C60H
Let Register Pair DE equal 5C60H, which is the DEstination RAM area.
55CAH
LD BC,0023H
Let Register Pair BC equal 0023H (Decimal: 35) to transfer 35 bytes of data; one byte for each track.
55CDH
LDIR
Transfers a byte of data from the memory location pointed to by HL to the memory location pointed to by DE. Then HL and DE are incremented and BC is decremented. If BC is not zero, this operation is repeated. Interrupts can trigger while this instruction is processing.
55CFH
LD HL,5B28H
Let Register Pair HL equal 5B28H to point to the message 0AH + "INITIALIZING SYSTEM INFORMATION" + 0DH.
55D2H
GOSUB to 429AH (part of SYS0/SYS) to send the message pointed to by Register Pair HL to the video display.
Next, set the BOOT GAT entry to "Sectors 0-4 Used" by turning on Bit 0 of the first entry in the GAT; thus changing the FCH (completely empty) to FDH (sectors 0-4 in use).
55D5H
LD HL,5C00H
Let Register Pair HL equal 5C00H to point to the first byte of the GAT.
55D8H
LD A,(HL)
Fetch the first byte of the GAT (held in the memory location pointed to by Register Pair HL) and store it into Register A.
55D9H
OR 01H
OR Register A against 01H, to turn on bit 0. This will change the FCH into FDH.
55DBH
LD (HL),A
Store the revised byte held in Register A into the memory location pointed to by Register Pair HL.
Next, set the DIRECTORY GAT entry to "all granules on track used" (FFH).
55DCH
LD A,(4202H)
Fetch the DIRECTORY TRACK NUMBER (which is stored at 4202H in TRSDOS v2.3) and put it into Register A.
55DFH
LD (57B6H),A
Store the value held in Register A into memory location 57B6H. 57B6H is in the pre-set code for the FPDE/FXDE entry for the DIR/SYS held at 57A0H-57BFH.
55E2H
LD L,A
Copy the contents of Register A into Register L to form an offset into the GAT in RAM for the chosen directory track.
55E3H
LD H,5CH
Let Register H equal 5CH, which MSB of the in-RAM representation of the GAT table of the disk being formatted.
55E5H
LD A,(HL)
Fetch the value held in the memory location pointed to by Register Pair HL and store it into Register A. This is the byte held in the GAT for DIR/SYS
55E6H
INC A
INCrement the value stored in Register A by 1 to help test to see if it was already FFH (meaning that the track had no available sectors to use).
55E7H
If the INC A triggered the Z FLAG (Zero), then it was already FFH (meaning that the track had no available sectors to use), which means that the chosen directory track had no room. With this, JUMP to 56D1H to display "CAN'T FORMAT, DIRECTORY TRACK FLAWED!", prompt for an ENTER, and then HALT the system.
55EAH
LD (HL),FFH
Store the value held in FFH into the memory location pointed to by Register Pair HL. This puts a "all granules on track used" notation of FFH into the GAT for the track upon which the directory is to be placed.
55ECH
LD DE,0000H
Let Register Pair DE equal 0000H.
55EFH
LD BC,4200H
Let Register Pair BC equal 4200H / (Decimal: 16896).
NOTE: 4200H is the storage location for the [TAKEN FROM PAGE] System Sector Buffer Area
55F2H
LD A,A8H
Let Register A equal A8H for the next instruction so as to write a 0FBH DAM.
55F4H
GOSUB to 56BDH to put A8 or A9 into the OPCODE LD (HL),nnH at 56F7H, Save BC, send DE to the FDC Sector Register, Send a SEEK and a WRITE FBH or F8H, and JUMP to 5706H to write out some data.
55F7H
LD A,(37ECH)
Fetch the FDC's status (which is mirrored to 37ECH) and store it into Register A.
| 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
Not Ready | Protected | Head Loaded | Seek Error | CRC Error | Track 00 | Index | Busy |
55FAH
AND 60H
MASK the value of Register A against 60H (0110 0000). This has the effect of turning off bits 7, 4, 3, 2, 1, 0, leaving only bits 6, 5 active. Since this follows a write command, BIT 5 HIGH means WRITE FAULT and BIT 6 HIGH means WRITE PROTECTED.
55FCH
If the NZ FLAG (Not Zero) has been set, the one of those 2 errors occurred, and so JUMP to 56CBH to display "CAN'T INITIALIZE SYSTEM INFORMATION", prompt for an ENTER, and then HALT the system.
55FFH
LD BC,5C00H
Let Register Pair BC equal 5C00H, which is the in-RAM representation of the GAT table of the disk being formatted.
5602H
LD A,(4202H)
Fetch the DIRECTORY TRACK NUMBER (which is stored at 4202H in TRSDOS v2.3) and put it into Register A.
5605H
LD D,A
Copy the contents of Register A into Register D.
5606H
LD E,00H
Let Register E equal 00H.
5608H
LD A,A9H
Let Register A equal A9H for the next instruction so as to write a 0F8H DAM.
560AH
GOSUB to 56BDH to put A8 or A9 into the OPCODE LD (HL),nnH at 56F7H, Save BC, send DE to the FDC Sector Register, Send a SEEK and a WRITE FBH or F8H, and JUMP to 5706H to write out some data.
560DH
LD A,(37ECH)
Fetch the FDC's status (which is mirrored to 37ECH) and store it into Register A.
| 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
Not Ready | Protected | Head Loaded | Seek Error | CRC Error | Track 00 | Index | Busy |
5610H
AND 60H
MASK the value of Register A against 60H (0110 0000). This has the effect of turning off bits 7, 4, 3, 2, 1, 0, leaving only bits 6, 5 active. Since this follows a write command, BIT 5 HIGH means WRITE FAULT and BIT 6 HIGH means WRITE PROTECTED.
5612H
CP 20H
Compare the value held in Register A against 0010 0000, which is BIT 5 of the status. If Bit 5 is 0, then the Z FLAG will be set, if Bit 5 is 1 (WRITE FAULT) then the NZ FLAG is set.
5614H
If the NZ FLAG (Not Zero) has been set then we have a WRITE FAULT so JUMP to 56CBH since to display "CAN'T INITIALIZE SYSTEM INFORMATION", prompt for an ENTER, and then HALT the system.
The next instructions move the BOOT/SYS FPDE entry to 5D00H and then send it to disk.
5617H
LD HL,5D00H
Let Register Pair HL equal 5D00H, which will be the buffer.
Top of a loop to ZERO out 5D00H-5DFFH
561AH
LD (HL),00H
Store the value 00H into the memory location pointed to by Register Pair HL.
561CH
INC L
INCrement the value stored in Register L by 1.
561DH
If the NZ FLAG (Not Zero) has been set, meaning we didn't yet get to FFH, LOOP BACK to 561AH to keep ZEROing and BUMPing.
Now that 5D00H-5DFFH has been ZEROed out, and HL is back to 5D00H, let's start filling that buffer.
561FH
LD (HL),A2H
Store an A2H into (5D00H).
5621H
INC HL
INCrement the value stored in Register Pair HL by 1.
5622H
LD (HL),2CH
Store a 2CH into (5D01H).
5624H
DEC HL
DECrement the value stored in Register Pair HL by 1.
5625H
LD E,01H
Let Register E equal 01H.
5627H
LD BC,5D00H
Let Register Pair BC equal 5D00H, which will be the buffer.
562AH
LD A,A9H
Let Register A equal A9H for the next instruction so as to write a 0F8H DAM.
562CH
GOSUB to 56BDH to put A8 or A9 into the OPCODE LD (HL),nnH at 56F7H, Save BC, send DE to the FDC Sector Register, Send a SEEK and a WRITE FBH or F8H, and JUMP to 5706H to write out some data.
562FH
LD A,(37ECH)
Fetch the FDC's status (which is mirrored to 37ECH) and store it into Register A.
| 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
Not Ready | Protected | Head Loaded | Seek Error | CRC Error | Track 00 | Index | Busy |
5632H
AND 60H
MASK the value of Register A against 60H (0110 0000). This has the effect of turning off bits 7, 4, 3, 2, 1, 0, leaving only bits 6, 5 active. Since this follows a write command, BIT 5 HIGH means WRITE FAULT and BIT 6 HIGH means WRITE PROTECTED.
5634H
CP 20H
Compare the value held in Register A against 0010 0000, which is BIT 5 of the status. If Bit 5 is 0, then the Z FLAG will be set, if Bit 5 is 1 (WRITE FAULT) then the NZ FLAG is set.
5636H
If the NZ FLAG (Not Zero) has been set then we have a WRITE FAULT so JUMP to 56CBH since to display "CAN'T INITIALIZE SYSTEM INFORMATION", prompt for an ENTER, and then HALT the system.
The next instructions move the BOOT/SYS FPDE entry to 5D00H and then send it to disk.
5639H
LD DE,5D00H
Let Register Pair DE equal 5D00H, which will be a buffer.
563CH
LD HL,5780H
Let Register Pair HL equal 5780H which is the area in RAM holding the literal code for the BOOT/SYS entry in the FPDE/FXDE area ... Sector 1 Bytes 00-1F.
563FH
LD BC,0020H
Let Register Pair BC equal 0020H (Decimal: 32) to tranfer the 32 byte BOOT/SYS FPDE/FXDE entry to 5D00H.
5642H
LDIR
Transfers a byte of data from the memory location pointed to by HL to the memory location pointed to by DE. Then HL and DE are incremented and BC is decremented. If BC is not zero, this operation is repeated. Interrupts can trigger while this instruction is processing.
5644H
LD A,(4202H)
Fetch the DIRECTORY TRACK NUMBER (which is stored at 4202H in TRSDOS v2.3) and put it into Register A.
5647H
LD D,A
Copy the contents of Register A into Register D.
5648H
LD E,02H
Let Register E equal 02H. Now DE points to 1102H (if we are using the standard directory track location).
564AH
LD BC,5D00H
Let Register Pair BC equal 5D00H, which will be a buffer.
564DH
LD A,A9H
Let Register A equal A9H for the next instruction so as to write a 0F8H DAM.
564FH
GOSUB to 56BDH to put A8 or A9 into the OPCODE LD (HL),nnH at 56F7H, Save BC, send DE to the FDC Sector Register, Send a SEEK and a WRITE FBH or F8H, and JUMP to 5706H to write out some data.
5652H
LD A,(37ECH)
Fetch the FDC's status (which is mirrored to 37ECH) and store it into Register A.
| 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
Not Ready | Protected | Head Loaded | Seek Error | CRC Error | Track 00 | Index | Busy |
5655H
AND 60H
MASK the value of Register A against 60H (0110 0000). This has the effect of turning off bits 7, 4, 3, 2, 1, 0, leaving only bits 6, 5 active. Since this follows a write command, BIT 5 HIGH means WRITE FAULT and BIT 6 HIGH means WRITE PROTECTED.
5657H
CP 20H
Compare the value held in Register A against 0010 0000, which is BIT 5 of the status. If Bit 5 is 0, then the Z FLAG will be set, if Bit 5 is 1 (WRITE FAULT) then the NZ FLAG is set.
5659H
If the NZ FLAG (Not Zero) has been set then we have a WRITE FAULT so JUMP to 56CBH since to display "CAN'T INITIALIZE SYSTEM INFORMATION", prompt for an ENTER, and then HALT the system.
The next instructions move the DIR/SYS FPDE entry to 5D00H and then send it to disk.
565CH
LD HL,57A0H
Let Register Pair HL equal 57A0H which contains the literal code for the DIR/SYS entry in the FPDE/FXDE area ... Sector 2 Bytes 00-1F.
565FH
LD DE,5D00H
Let Register Pair DE equal 5D00H, which will be the buffer.
5662H
LD BC,0020H
Let Register Pair BC equal 0020H (Decimal: 32) to tranfer the 32 byte DIR/SYS FPDE/FXDE entry to 5D00H.
5665H
LDIR
Transfers a byte of data from the memory location pointed to by HL to the memory location pointed to by DE. Then HL and DE are incremented and BC is decremented. If BC is not zero, this operation is repeated. Interrupts can trigger while this instruction is processing.
5667H
LD A,(4202H)
Fetch the DIRECTORY TRACK NUMBER (which is stored at 4202H in TRSDOS v2.3) and put it into Register A.
566AH
LD D,A
Copy the contents of Register A into Register D.
566BH
LD E,03H
Let Register E equal 03H / (Binary:0000 0011) / (Decimal: 3).
566DH
LD BC,5D00H
Let Register Pair BC equal 5D00H, which will be the buffer used by the ROM to accept keyboard input and store the keys entered.
5670H
LD A,A9H
Let Register A equal A9H for the next instruction so as to write a 0F8H DAM.
5672H
GOSUB to 56BDH to put A8 or A9 into the OPCODE LD (HL),nnH at 56F7H, Save BC, send DE to the FDC Sector Register, Send a SEEK and a WRITE FBH or F8H, and JUMP to 5706H to write out some data.
5675H
LD A,(37ECH)
Fetch the FDC's status (which is mirrored to 37ECH) and store it into Register A.
| 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
Not Ready | Protected | Head Loaded | Seek Error | CRC Error | Track 00 | Index | Busy |
5678H
AND 60H
MASK the value of Register A against 60H (0110 0000). This has the effect of turning off bits 7, 4, 3, 2, 1, 0, leaving only bits 6, 5 active. Since this follows a write command, BIT 5 HIGH means WRITE FAULT and BIT 6 HIGH means WRITE PROTECTED.
567AH
CP 20H
Compare the value held in Register A against 0010 0000, which is BIT 5 of the status. If Bit 5 is 0, then the Z FLAG will be set, if Bit 5 is 1 (WRITE FAULT) then the NZ FLAG is set.
567CH
If the NZ FLAG (Not Zero) has been set then we have a WRITE FAULT so JUMP to 56CBH since to display "CAN'T INITIALIZE SYSTEM INFORMATION", prompt for an ENTER, and then HALT the system.
The next instructions clear the 32 bytes from 5D00H, and writes out 4 (tracked in E) blank FPDE/FXDE entries..
567FH
LD HL,5D00H
Let Register Pair HL equal 5D00H, which will be the buffer used by the ROM to accept keyboard input and store the keys entered.
5682H
LD B,20H
Let Register BC equal 0020H (Decimal: 32) to allow for a 32 pass DJNZ Loop (32 bytes being the size of a FPDE/FXDE entry).
5684H
LD (HL),00H
Store the value 00H into the memory location pointed to by Register Pair HL.
5686H
INC HL
INCrement the value stored in Register Pair HL by 1.
5687H
LOOP back to 5684H, reducing Register B each time, and continue to LOOP until Register B has been reduced to ZERO, in which case, continue with the next instruction.
5689H
LD A,(4202H)
Fetch the DIRECTORY TRACK NUMBER (which is stored at 4202H in TRSDOS v2.3) and put it into Register A.
568CH
LD D,A
Copy the contents of Register A into Register D.
568DH
LD E,04H
Let Register E equal 04H for 4 loop passes.
568FH
LD BC,5D00H
Let Register Pair BC equal 5D00H, which will be the buffer used by the ROM to accept keyboard input and store the keys entered.
5692H
LD A,A9H
Let Register A equal A9H for the next instruction so as to write a 0F8H DAM.
5694H
GOSUB to 56BDH to put A8 or A9 into the OPCODE LD (HL),nnH at 56F7H, Save BC, send DE to the FDC Sector Register, Send a SEEK and a WRITE FBH or F8H, and JUMP to 5706H to write out some data.
5697H
LD A,(37ECH)
Fetch the FDC's status (which is mirrored to 37ECH) and store it into Register A.
| 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
Not Ready | Protected | Head Loaded | Seek Error | CRC Error | Track 00 | Index | Busy |
569AH
AND 60H
MASK the value of Register A against 60H (0110 0000). This has the effect of turning off bits 7, 4, 3, 2, 1, 0, leaving only bits 6, 5 active. Since this follows a write command, BIT 5 HIGH means WRITE FAULT and BIT 6 HIGH means WRITE PROTECTED.
569CH
CP 20H
Compare the value held in Register A against 0010 0000, which is BIT 5 of the status. If Bit 5 is 0, then the Z FLAG will be set, if Bit 5 is 1 (WRITE FAULT) then the NZ FLAG is set.
569EH
If the NZ FLAG (Not Zero) has been set then we have a WRITE FAULT so JUMP to 56CBH since to display "CAN'T INITIALIZE SYSTEM INFORMATION", prompt for an ENTER, and then HALT the system.
56A1H
INC E
INCrement the value stored in Register E by 1 to note that the FPDE/FXDE was written.
56A2H
LD A,E
Copy the contents of Register E into Register A.
56A3H
CP 0AH
Compare the value held in Register A against 0AH (Decimal: 10) for a total of 10 sectors in the directory track.
56A5H
If the NZ FLAG (Not Zero) has been set, JUMP to 568FH to write the next sector.
56A7H
GOSUB to 5754H to send a RESTORE/LOAD HEAD to the Floppy Drive and then keep checking the floppy drive controller status until the drive is not BUSY, at which point the routine RETurns.
56AAH
LD HL,5B6DH
Let Register Pair HL equal 5B6DH to point to the message 0AH + "FORMATTING COMPLETE" + 0DH