EXX
EXchanges the 16-bit contents of BC, DE, and HL with BC’, DE’, and HL’. Among other things, this puts DE back to point to a TRACK and SECTOR, and HL back to pointing to the Floppy Disk Controller DATA BYTE.Note: AF is not handled via EXX.
4256H
LD B,0AH
Let Register B equal 0AH (Decimal: 10) for a retry count of 10 times.
LD HL,37E1H
Let Register Pair HL equal 37E1H, which is the DISK DRIVE SELECT LATCH ADDRESS.
425BH
LD (HL),01H
Store the value 01H into the drive select latch, which sets to DRIVE :0.
425DH
PUSH DE
Save the contents of Register Pair DE (i.e., the track and sector) to the top of the stack.
425EH
PUSH BC
Save the contents of Register Pair BC (i.e., the retry count) to the top of the stack.
425FH
LD A,E
Copy the contents of Register E (i.e., the sector) into Register A.
4260H
SUB 0AH
SUBtract the value 0AH (Decimal: 10) from Register A. If Register A was greater than 10, the CARRY FLAG will trip.
4262H
If the Carry Flag is set, then the sector number is too high! JUMP to 4267H.
4264H
LD E,A
Copy the SUBTRACTED FROM 10 contents of Register A into Register E.
4265H
LD (HL),09H
Store the value 09H (Binary:0000 1001) into the drive select latch, which turns on all drive lights.
LD HL,37ECH
Let Register Pair HL equal 37ECH, which is the RAM location for the Floppy Disk Controller.
426AH
GOSUB to 42CEH to wait until the Floppy Disk Controller signals READY.
426DH
LD (37EEH),DE
Store the value held in Register Pair DE into the FLOPPY DRIVE CONTROLLER SECTOR SELECT Register (i.e., 37EEH).
4271H
LD (HL),1BH
Store the value 1BH (Binary:0001 1011) into the Floppy Drive Controller. This is the command to SEEK (0001), Load Head at Beginning (1), No Verify (0), 30ms Stepping Rate (11)
4273H
GOSUB to 42CEH to wait until the Floppy Disk Controller signals READY.
4276H
LD (HL),88H
Store the value 88H (Binary: 1000 1000) into the Floppy Drive Controller. This is the command to READ (100), Single Record (0), Compare for Side 1 (1), No 15ms Delay (0), Disable Side Compare (00).
4278H
LD DE,37EFH
Let Register Pair DE equal 37EFH (aka Port F3H) to point to the Floppy Disk Controller DATA Register.
427BH
LD BC,5100H
Let Register Pair BC equal 5100H to be a RAM BUFFER to hold the sector data.
427EH
GOSUB to 42D7H for a very short delay.
LD A,(HL)
Fetch the value from the Floppy Disk Controller Status Register and put the result into Register A.
4282H
AND 83H
MASK the value of Register A against 83H (1000 0011). This has the effect of leaving only bits 7 (1=NOT READY), 1 (1=Index Found), and 0 (1=Busy/Command in Progress) active.
4284H
If the PARITY/OVERFLOW FLAG has been RESET, LOOP back to 4281H and keep polling.
LD A,(DE)
Fetch a byte from the Floppy Disk Controller Data Register and store it into Register A.
4288H
LD (BC),A
Store the byte (now held in Register A) into the RAM BUFFER (pointed to by Register Pair BC).
4289H
INC BC
INCrement the RAM BUFFER pointer (stored in Register Pair BC) by 1.
BIT 1,(HL)
Test Bit Number 1 of the Floppy Disk Controller Status Register. Z FLAG will be set if that bit is 0 (meaning NO index mark), and NZ FLAG will be set if that bit is 1 (meaning, index mark found).
428CH
If the index mark was found, JUMP to 4287H.
428FH
BIT 1,(HL)
Check for the index mark a second time … Z=Not Found, NZ=Found.
4291H
If the index mark was found, JUMP to 4287H.
4294H
BIT 1,(HL)
Check for the index mark a THIRD time … Z=Not Found, NZ=Found.
4296H
If the index mark was found, JUMP to 4287H.
4298H
BIT 0,(HL)
So far, we have failed to find an index mark 3 times. Next, test Bit 0 of the Floppy Disk Controller Status Register. Z FLAG will be set if that bit is 0 (meaning NOT busy), and NZ FLAG will be set if that bit is 1 (meaning, BUSY).
429AH
If the drive is BUSY, JUMP to 42A4H.
429CH
BIT 1,(HL)
Check for the index mark again … Z=Not Found, NZ=Found.
429EH
If the index mark was found, JUMP to 4287H.
42A0H
BIT 7,(HL)
Test Bit Number 7 of the Floppy Disk Controller Status Register. Z FLAG will be set if that bit is 0 (READY), and NZ FLAG will be set if that bit is 1 (NOT READY).
42A2H
If drive is READY, JUMP to 428AH.
LD A,(HL)
Fetch the status from the Floppy Drive Controller Status Register and store it into Register A.
42A5H
LD (HL),0D0H
Store the value 0D0H (Binary: 1101 0000) into the Floppy Drive Controller Command Register, which resets the Floppy Disk Controller and puts it into INTRQ mode for NOT READY to READY transition.
42A7H
POP BC
Put the value held at the top of the STACK (i.e., the retry count) into Register Pair BC, and then remove the entry from the stack.
42A8H
POP DE
Put the value held at the top of the STACK (i.e., the track and sector) into Register Pair DE, and then remove the entry from the stack.
42A9H
AND 0FCH
MASK the value of Register A (i.e., the status from the Floppy Disk Controller; read at 42A4H) against 0FCH (1111 1100). This has the effect of turning off bits 1 and 0. With that NZ will only be set if the following is true: The head is positioned to Track 0, there is a CRC error, there is a Seek error, the head is loaded, write protect is actived, or the drive is not ready.
42ABH
If any of that stuff is true then that’s a bad thing … JUMP to 42B9H to wait for the Floppy Drive Controller to be ready, send a RESET to the FDC, and continue a countdown of retries; failing to DISK ERROR if the retry count expires.
42ADH
INC E
INCrement the sector number (stored in Register E) by 1.
42AEH
LD A,E
Copy the new sector number (held in Register E) into Register A.
42AFH
SUB 0AH
SUBtract the value 0AH (Decimal: 10) from Register A. If Register A was less than 10, the NZ FLAG will be set.
42B1H
If the NZ FLAG (Not Zero) has been set, JUMP to 42B6H to skip over incrementing the track.
42B3H
INC D
INCrement the track (stored in Register D) by 1.
42B4H
LD E,00H
Let Register E equal 00H to reset to Sector 0 on that new track.
EXX
EXchanges the 16-bit contents of BC, DE, and HL with BC’, DE’, and HL’. Note: AF is not handled via EXX.
42B7H
LD A,(HL)
Fetch the value held in the RAM BUFFER pointed to by Register Pair HL and store it into Register A.
42B8H
RET
RETurn to the caller.