TRS-80 DOS - LDOS 5.3.1 for the Model I - FDUBL/CMD Disassembled

Page Customization

Introduction/Summary

LDOS 5.3.1 FDUBL/CMD Disassembly - The Double Density Driver (Model I)

FDUBL installs $FDD, a floppy disk driver for a Model I with a double density adapter, in place of SYS0/SYS's single density driver: FDUBL (TANDY) for the Radio Shack adapter (the default) or FDUBL (PERCOM) for a Percom type doubler. The module is copied so that its last byte lies at HIGH$, HIGH$ goes below it, and every drive code table whose +04H has bit 4 clear gets its JP pointed at the module and bit 6 of +04H set (the controller can do double density, the bit FORMAT tests before it asks for the density).

The file is a load module of 983 bytes: a copyright record, four load blocks for 5200H-5573H, a record of type 07H with the name of the patch FDUBL1, the patch's two load blocks (5265H-5267H over the first block, and 5574H-557CH), and the transfer address 521EH: 893 bytes in 5200H-557CH. The rows show the bytes as loaded, with the patch.

What FDUBL Does

521EH: the banner, @PARAM (PERCOM or P, TANDY or T; anything else gives Parameter error), the old HIGH$ into the header's link word. With PERCOM (and not TANDY as well: Can't specify both Percom and Tandy!) the module is rebuilt in place (5243H). Then each drive's driver is checked for the name $FDD (Driver is already resident!, 5286H), the module's own operands are moved by the distance to HIGH$ (52B2H, with the table at 5200H), the module is copied below HIGH$ and the drives are taken over (52DCH). An error ends with Register Pair HL = FFFFH, and at @ABORT during a JCL job.

BuildModuleDifferences
Tandy (default)540CH-5563H, 0158H (344) bytes, 15 operands movedThe density is set by writing 80H (double) or A0H (single) to the sector register 37EEH (5558H); a seek first sets the adapter's precompensation (C0H off, E0H on, 5415H).
PERCOM5421H-5567H, 0147H (327) bytes, 14 operands movedThe density is set by writing FEH (single) or FFH (double) to the command register 37ECH, then D0H (5564H, copied to 5558H). No precompensation: the header goes over that code to 5421H, and the seeks go to SYS0/SYS's 462AH. The patch FDUBL1 (5574H) gives the moved header the displacement 2CH, so its JR still reaches 544FH.

The Driver

The module (540CH) starts with a header: the JR to the driver, the link word, the length of the name and $FDD. The driver (544FH) takes the functions of SYS0/SYS's driver with the same registers; 00H returns at once, and 01H, 02H-05H and 07H go to SYS0/SYS's own routines. The sector and track functions (5477H) set the adapter for the drive's density first, and use their own transfer loop, which tests for the next data request five times between each test of BUSY (550AH). Reads get 10 tries, verifies 4, writes 6; a write with the deleted data mark uses A9H in double density and ABH in single density. When a sector is not found, the drive's density is changed (bit 6 of +03H, with the geometry 2409H or 4511H in +07H and +08H, 542DH) and the operation tried again, so a diskette of either density is read. Errors become LDOS error numbers through SYS0/SYS's decoder (46F4H), whose first number FDUBL stores at 46F6H.

About This Page

Every byte is shown at its address in the file; the module works above HIGH$, and the rows at 5421H-5429H, 5558H-5567H, 545DH, 542BH-542CH and 54C3H-54C4H are what the Tandy build keeps there. The precompensation test reads +05H, the cylinder the head is on before the seek, not the cylinder sought. FDUBL takes over every drive whose +04H has bit 4 clear, whatever its size, and drives that are not present (their tables keep the RET at +00H). Two pairs of entries share bytes: 5320H/5321H (two messages) and 5549H/554AH (LD B,F1H, whose F1H is POP AF for 553BH).

Memory Map

Load Blocks in File Order

The file starts with a copyright record (type 1FH, 49 bytes), then the load blocks in the order LDOS loads them. A record of type 07H with the name FDUBL1 comes before the last two blocks, the patch: 5265H-5267H loads over the first block. 893 bytes in 5200H-557CH; the transfer address is 521EH.

AddressContents
5200H-52FFH256 bytes
5300H-53FFH256 bytes
5400H-54FFH256 bytes
5500H-5573H116 bytes
5265H-5267H3 bytes
5574H-557CH9 bytes

The Parts of the File

AddressContents
5200H-521DHThe table of the 15 operands to move.
521EH-5332HThe installer: the parameters, the PERCOM build, the check for $FDD, the move of the operands, the copy and the drive tables, the end and the errors.
5333H-540BHThe parameters, the cells of the module, the texts.
540CH-5563HThe module $FDD for the Tandy adapter (5421H-5567H for PERCOM).
5564H-557CHThe density routine of the Percom doubler (copied to 5558H for PERCOM) and the routine of the patch FDUBL1.

Sections of the Disassembly

AddressContents
5200HThe Table of the Operands to Move
521EHEntry: the Banner and the Parameters
5243HThe Module for the Percom Doubler
5286HIs $FDD Already in Place?
52B2HMove the Operands
52DCHCopy the Module, Lower HIGH$, Take Over the Drives
530BHThe End
531DHThe Errors
5333HThe Parameters, the Cells of the Module, the Texts
540CHThe Module $FDD: Header
5415HSeek With the Precompensation (Tandy Adapter)
542DHChange the Density
544FHThe Driver: the Functions
5477HThe Sector and Track Functions
54B1HTake the Three Parameters
54BFHIssue the Command, Move the Bytes, Try Again
5558HSet the Density (Tandy Adapter)
5564HSet the Density (Percom Doubler)
5574HThe Patch FDUBL1

Memory FDUBL Uses

AddressContents
37ECH-37EFHThe floppy disk controller: command and status, track, sector (the Tandy adapter's code in its three high bits), data.
4049H-404AHHIGH$: the module goes just below it, and it is lowered by the module's length.
4467H, 447BH, 4476H, 4409H@DSPLY (the banner), @LOGOT (the errors), @PARAM and @ERROR.
4030H@ABORT: an error during a JCL job.
430FHSFLAG$: bit 5 a JCL job runs.
45E0H, 461CH, 462AH, 462DH, 4659H, 4662HSYS0/SYS's floppy driver: select, wait until not busy, seek (462AH waits first), issue a Type I command with the step rate, issue a command.
46F4H, 46F6HSYS0/SYS's error decoder and its first error number, which the driver stores (54B4H).
46FDHA NOP and a RET in SYS0/SYS, DI after SYSTEM (SMOOTH): called before each transfer.
4700H-474FHDCT$: +01H-+02H of each taken over drive get the module's address, +04H bit 6 is set; the driver changes +03H bit 6, +05H, +07H and +08H.

Variables

The entry points of FDUBL, then the data of the file, the operands it changes, and the memory outside the file that it changes, by address. Addresses in the module are its addresses in the file.

Entry Points

AddressContents
521EHThe start of FDUBL, the transfer address of the file.
5243HBuild the module for the Percom doubler.
5286HIs $FDD already in place?
52B2HMove the module's operands.
52DCHCopy the module, lower HIGH$, take over the drives.
530BHThe end; 530EH with the return code in Register Pair HL.
531DHThe errors: 531DH, 5321H and 532CH.
540CHThe module's first byte: the JR to the driver.
5415HPrecompensation and seek (Tandy adapter).
542DHChange the density of a drive.
544FHThe driver: the functions.
5477HThe sector and track functions.
54B1HTake the three parameters after a CALL.
54BFHIssue the command, move the bytes, try again.
5558HSet the density (Tandy adapter; Percom after 5255H).
5574HThe patch FDUBL1.

Data in the File

Address
Size
Contents
5200H-5201H
2 bytes
DEFW 547AH
5200H-5201H: 547AH, the CALL 5558H at 547AH (operand 547BH-547CH): the density routine.
5202H-5203H
2 bytes
DEFW 548EH
5202H-5203H: 548EH, the CALL 54B1H at 548EH (operand 548FH-5490H): the parameter reader, for a read.
5204H-5205H
2 bytes
DEFW 54ABH
5204H-5205H: 54ABH, the CALL 54B1H at 54ABH (operand 54ACH-54ADH): the parameter reader, for a write.
5206H-5207H
2 bytes
DEFW 54BBH
5206H-5207H: 54BBH, the LD (550AH),HL at 54BBH (operand 54BCH-54BDH): the body of the transfer loop.
5208H-5209H
2 bytes
DEFW 5551H
5208H-5209H: 5551H, the JP PO,554EH at 5551H (operand 5552H-5553H): the wait for the first byte of a read.
520AH-520BH
2 bytes
DEFW 54F8H
520AH-520BH: 54F8H, the JP Z,54F3H at 54F8H (operand 54F9H-54FAH): the wait for the first byte of a write.
520CH-520DH
2 bytes
DEFW 550FH
520CH-520DH: 550FH, the JP NZ,550AH at 550FH (operand 5510H-5511H): the transfer loop.
520EH-520FH
2 bytes
DEFW 5514H
520EH-520FH: 5514H, the JP NZ,550AH at 5514H (operand 5515H-5516H): the transfer loop.
5210H-5211H
2 bytes
DEFW 54CCH
5210H-5211H: 54CCH, the second byte of LD IX,550BH at 54CBH: its operand 54CDH-54CEH is the word after 54CCH.
5212H-5213H
2 bytes
DEFW 5457H
5212H-5213H: 5457H, the JP NC,5477H at 5457H (operand 5458H-5459H): the sector functions.
5214H-5215H
2 bytes
DEFW 5540H
5214H-5215H: 5540H, the CALL NZ,542DH at 5540H (operand 5541H-5542H): the change of density.
5216H-5217H
2 bytes
DEFW 5447H
5216H-5217H: 5447H, the CALL 5558H at 5447H (operand 5448H-5449H): the density routine.
5218H-5219H
2 bytes
DEFW 5494H
5218H-5219H: 5494H, the CALL 54B1H at 5494H (operand 5495H-5496H): the parameter reader, for a verify.
521AH-521BH
2 bytes
DEFW 5546H
521AH-521BH: 5546H, the JP NZ,54BFH at 5546H (operand 5547H-5548H): the next try.
521CH-521DH
2 bytes
DEFW 54C2H
521CH-521DH: 54C2H, the CALL Z,5415H at 54C2H (operand 54C3H-54C4H): the precompensation and seek. Not used by the PERCOM build, whose operand there is 462AH in SYS0/SYS.
5333H-533AH
8 bytes
DEFM "PERCOM" / DEFW 523CH
5333H-533AH: PERCOM, the Percom doubler: the operand of LD HL,0000H at 523BH.
533BH-5342H
8 bytes
DEFM "P " / DEFW 523CH
533BH-5342H: P, the short form of PERCOM: 523CH.
5343H-534AH
8 bytes
DEFM "TANDY " / DEFW 5354H
5343H-534AH: TANDY, the Tandy adapter, the module as the file has it: the word at 5354H, tested only at 5243H.
534BH-5352H
8 bytes
DEFM "T " / DEFW 5354H
534BH-5352H: T, the short form of TANDY: 5354H.
5353H
1 byte
DEFB 00H
5353H: 00H, the end of the table of the parameters.
5354H-5355H
2 bytes
DEFW 0000H
5354H-5355H: the TANDY parameter, 0000H in the file, FFFFH for TANDY or T (5243H-5249H).
5356H-5357H
2 bytes
DEFW 0158H
5356H-5357H: the length of the module, 0158H (344 bytes, 540CH-5563H); 0147H for PERCOM (5273H). Read by 52E3H.
5358H-5359H
2 bytes
DEFW 540CH
5358H-5359H: the first byte of the module, 540CH; 5421H for PERCOM (527AH). No code reads it.
535AH-535BH
2 bytes
DEFW 5563H
535AH-535BH: the last byte of the module, 5563H; 5567H for PERCOM (527FH). Read by 52B9H and 52E0H.
535CH
1 byte
DEFB 0FH
535CH: the count of the operands to move, 0FH (15); 0EH for PERCOM (5285H). Read by 52C2H.
535DH-5380H
36 bytes
DEFM "Can't specify both Percom and Tandy!"
535DH-5380H: the text of 531DH, for PERCOM and TANDY both given.
5381H
1 byte
DEFB 0DH
5381H: 0DH, the end of the line and of the text.
5382H-539CH
27 bytes
DEFM "Driver is already resident!"
5382H-539CH: the text of 5321H, for a drive served by a module named $FDD.
539DH
1 byte
DEFB 0DH
539DH: 0DH, the end of the line and of the text.
539EH-53D7H
58 bytes
DEFM "FDUBL 5.3.1 - Driver for the Percom and Tandy type doubler"
539EH-53D7H: the first line of the banner (5223H).
53D8H
1 byte
DEFB 0AH
53D8H: 0AH, a new line within the banner, before the copyright.
53D9H-540AH
50 bytes
DEFM "Copyright 1991, MISOSYS, Inc., All rights reserved"
53D9H-540AH: the second line of the banner, the copyright.
540BH
1 byte
DEFB 0DH
540BH: 0DH, the end of the banner and of its second line.
540EH-540FH
2 bytes
DEFW 0000H
540EH-540FH: the link word of the header, 0000H in the file: the HIGH$ before the module is copied (5238H).
5410H
1 byte
DEFB 04H
5410H: 04H, the length of the name; 5292H compares it.
5411H-5414H
4 bytes
DEFM "$FDD"
5411H-5414H: the name of the module, $FDD; 529CH compares it.
5491H-5493H
3 bytes
DEFB 01H, 1AH, 02H
5491H-5493H: the parameters of a read: 01H, the first error number (to 46F6H), and 1AH 02H, the loop body LD A,(DE) / LD (BC),A: a byte from the data register into the buffer.
5497H-5499H
3 bytes
DEFB 01H, 1AH, 7EH
5497H-5499H: the parameters of a verify: 01H, the first error number, and 1AH 7EH, the loop body LD A,(DE) / LD A,(HL): the byte is read and not stored.
54AEH-54B0H
3 bytes
DEFB 09H, 12H, 0AH
54AEH-54B0H: the parameters of a write: 09H, the first error number of a write, and 12H 0AH, the loop body LD (DE),A / LD A,(BC): the byte in Register A to the data register, then the next byte of the buffer.

Operands Changed While It Runs

Address
Size
Contents
523CH-523DH
2 bytes
The operand of LD HL,0000H at 523BH: PERCOM, FFFFH when given (@PARAM).
530FH-5310H
2 bytes
The operand of LD SP,0000H at 530EH: the Stack Pointer LDOS gave (521EH).
540DH
1 byte
The displacement of the header's JR: 41H, 2CH for PERCOM (5576H).
542BH-542CH
2 bytes
The operand of JP 462DH at 542AH: 462AH for PERCOM (525FH).
545DH
1 byte
The displacement of JR Z,5415H at 545CH: CCH (JR Z,542AH) for PERCOM (5259H).
54C3H-54C4H
2 bytes
The operand of CALL Z,5415H at 54C2H: 462AH for PERCOM (5262H).
550AH-550BH
2 bytes
The body of the transfer loop (54BBH): 1AH 02H read, 1AH 7EH verify, 12H 0AH write.
5558H-5567H
16 bytes
The density routine: the Percom one from 5564H for PERCOM (5255H).
5421H-5429H
9 bytes
The header for PERCOM (526EH).
5356H-535CH
7 bytes
The length, first byte, last byte and operand count of the module (5273H-5285H).
the 15 operands
2 bytes each
The operands the table at 5200H names, moved by the distance to HIGH$ (52B2H).

Memory Outside the File That FDUBL Changes

Address
Size
Contents
4049H-404AH
2 bytes
HIGH$, lowered by the module's length (52EAH).
4700H + drive x 10, +01H-+02H
2 bytes
The driver address of each drive taken over: the module's first byte (52FDH).
+04H, bit 6
1 bit
Set for each drive taken over: its controller can do double density (5303H).
+03H bit 6, +07H, +08H
3 bytes
Changed by the driver when a sector is not found (542DH): the density and its geometry.
46F6H
1 byte
The first error number of SYS0/SYS's error decoder: 01H for a read or verify, 09H for a write (54B4H).

Disassembly

5200H - The Table of the Operands to Move

FDUBL/CMD builds the driver module $FDD in its own image (540CH-5563H, or 5421H-5567H for PERCOM) and copies it so that its last byte lies at HIGH$. Fifteen words: each is the address of an instruction of the module whose operand (the word after the instruction's first byte; for 54CCH the word after it) is an address inside the module. 52B2H adds the distance of the move to each operand. The PERCOM build uses only the first 14 (535CH).

5200-5201
DEFW 547AH 7A 54
5200H-5201H: 547AH, the CALL 5558H at 547AH (operand 547BH-547CH): the density routine.
5202-5203
DEFW 548EH 8E 54
5202H-5203H: 548EH, the CALL 54B1H at 548EH (operand 548FH-5490H): the parameter reader, for a read.
5204-5205
DEFW 54ABH AB 54
5204H-5205H: 54ABH, the CALL 54B1H at 54ABH (operand 54ACH-54ADH): the parameter reader, for a write.
5206-5207
DEFW 54BBH BB 54
5206H-5207H: 54BBH, the LD (550AH),HL at 54BBH (operand 54BCH-54BDH): the body of the transfer loop.
5208-5209
DEFW 5551H 51 55
5208H-5209H: 5551H, the JP PO,554EH at 5551H (operand 5552H-5553H): the wait for the first byte of a read.
520A-520B
DEFW 54F8H F8 54
520AH-520BH: 54F8H, the JP Z,54F3H at 54F8H (operand 54F9H-54FAH): the wait for the first byte of a write.
520C-520D
DEFW 550FH 0F 55
520CH-520DH: 550FH, the JP NZ,550AH at 550FH (operand 5510H-5511H): the transfer loop.
520E-520F
DEFW 5514H 14 55
520EH-520FH: 5514H, the JP NZ,550AH at 5514H (operand 5515H-5516H): the transfer loop.
5210-5211
DEFW 54CCH CC 54
5210H-5211H: 54CCH, the second byte of LD IX,550BH at 54CBH: its operand 54CDH-54CEH is the word after 54CCH.
5212-5213
DEFW 5457H 57 54
5212H-5213H: 5457H, the JP NC,5477H at 5457H (operand 5458H-5459H): the sector functions.
5214-5215
DEFW 5540H 40 55
5214H-5215H: 5540H, the CALL NZ,542DH at 5540H (operand 5541H-5542H): the change of density.
5216-5217
DEFW 5447H 47 54
5216H-5217H: 5447H, the CALL 5558H at 5447H (operand 5448H-5449H): the density routine.
5218-5219
DEFW 5494H 94 54
5218H-5219H: 5494H, the CALL 54B1H at 5494H (operand 5495H-5496H): the parameter reader, for a verify.
521A-521B
DEFW 5546H 46 55
521AH-521BH: 5546H, the JP NZ,54BFH at 5546H (operand 5547H-5548H): the next try.
521C-521D
DEFW 54C2H C2 54
521CH-521DH: 54C2H, the CALL Z,5415H at 54C2H (operand 54C3H-54C4H): the precompensation and seek. Not used by the PERCOM build, whose operand there is 462AH in SYS0/SYS.

521EH - Entry: the Banner and the Parameters

The transfer address. LDOS runs FDUBL with Register Pair HL pointing to the command line. The Stack Pointer is kept for the end (530EH), the banner is displayed and @PARAM reads PERCOM (P) and TANDY (T) with the table at 5333H. HIGH$ goes into the link word of the module's header. Without PERCOM the module is built for the Tandy adapter, as it is in the file.

521E
LD (530FH),SP ED 73 0F 53
Store the Stack Pointer at 530FH-5310H, the operand of LD SP,0000H at 530EH, so that the end goes back to LDOS on this stack.
5222
PUSH HL E5
Save Register Pair HL (the pointer to the command line) to the stack.
5223
LD HL,539EH 21 9E 53
Point Register Pair HL to 539EH, the banner: FDUBL 5.3.1 - Driver for the Percom and Tandy type doubler, a new line, the copyright and 0DH.
5226
GOSUB to 4467H, @DSPLY, to display the text at Register Pair HL (539EH).
5229
POP HL E1
Restore Register Pair HL from the stack: the pointer to the command line.
522A
LD DE,5333H 11 33 53
Point Register Pair DE to 5333H, the table of the parameters PERCOM, P, TANDY and T.
522D
GOSUB to 4476H, @PARAM, to read the parameters at Register Pair HL against the table at Register Pair DE (5333H): a parameter given stores FFFFH (or 0000H for =N). The Z FLAG on success.
5230
LD A,2CH 3E 2C
Load Register A with 2CH, error 2CH, Parameter error. LD does not change the flags.
5232
If the NZ FLAG is set (a parameter @PARAM does not know, a bad value or a bad character after a parameter), JUMP to 532CH to give the error in Register A (2CH) through @ERROR.
5235
LD HL,(4049H) 2A 49 40
Fetch HIGH$ from 4049H into Register Pair HL: the highest address free for programs, before the module goes below it.
5238
LD (540EH),HL 22 0E 54
Store Register Pair HL (HIGH$) at 540EH-540FH, the link word of the module's header (+02H-+03H).
523B
LD HL,0000H 21 00 00
Load Register Pair HL with the PERCOM parameter: the operand 523CH-523DH, 0000H in the file, FFFFH for PERCOM or P.
523E
LD A,H 7C
Copy Register H (the high byte of PERCOM) into Register A.
523F
AND L A5
AND Register L (the low byte) into Register A: FFH only when both bytes are FFH.
5240
INC A 3C
INCrement Register A: the Z FLAG for PERCOM (FFFFH), and Register A = 00H.
5241
If the NZ FLAG is set (no PERCOM), JUMP to 5286H with the module for the Tandy adapter as the file has it.

5243H - The Module for the Percom Doubler

With PERCOM, and not TANDY too, the module is changed in the image: the Percom density routine (5564H) goes over the Tandy one at 5558H; the seek of function 06H and of the sector functions goes to SYS0/SYS's 462AH, without the precompensation routine 5415H; the patch FDUBL1 (5574H) gives the header the displacement 2CH; the header's 9 bytes move from 540CH-5414H to 5421H-5429H, over the precompensation code; the module becomes 5421H-5567H, 0147H bytes, with 14 operands to move.

5243
LD HL,5354H 21 54 53
Point Register Pair HL to 5354H, the TANDY parameter (0000H in the file, FFFFH for TANDY or T).
5246
OR (HL) B6
OR the low byte of TANDY at Register Pair HL (5354H) into Register A (00H from 5240H).
5247
INC HL 23
INCrement Register Pair HL to 5355H, the high byte of TANDY.
5248
OR (HL) B6
OR the high byte of TANDY at Register Pair HL (5355H) into Register A: not 0 when TANDY was given.
5249
If the NZ FLAG is set (PERCOM and TANDY both given), JUMP to 531DH to display Can't specify both Percom and Tandy! and end.
524C
LD HL,5564H 21 64 55
Point Register Pair HL to 5564H, the density routine of the Percom doubler (16 bytes, 5564H-5573H).
524F
LD DE,5558H 11 58 55
Point Register Pair DE to 5558H, the density routine of the module, for the Tandy adapter in the file.
5252
LD BC,0010H 01 10 00
Load Register Pair BC with 0010H, the 16 bytes of the Percom routine.
5255
LDIR ED B0
Copy the 16 bytes from Register Pair HL (5564H) to Register Pair DE (5558H-5567H), Register Pair BC the count (LDIR).
5257
LD A,CCH 3E CC
Load Register A with CCH, the displacement of a JR from 545CH to 542AH.
5259
LD (545DH),A 32 5D 54
Store Register A (CCH) at 545DH: JR Z,5415H at 545CH becomes JR Z,542AH, so function 06H (seek) goes to the JP at 542AH, past the precompensation.
525C
LD HL,462AH 21 2A 46
Load Register Pair HL with 462AH, SYS0/SYS's seek that waits for the controller first.
525F
LD (542BH),HL 22 2B 54
Store Register Pair HL (462AH) at 542BH-542CH: JP 462DH at 542AH becomes JP 462AH.
5262
LD (54C3H),HL 22 C3 54
Store Register Pair HL (462AH) at 54C3H-54C4H: CALL Z,5415H at 54C2H becomes CALL Z,462AH, the seek of the sector functions.
5265
GOSUB to 5574H, the routine of the patch FDUBL1: the displacement 2CH into the header's JR (540DH) and Register Pair HL = 5414H. The file's first load block has 21H 14H 54H here (LD HL,5414H); the patch's load record puts CDH 74H 55H over them.
5268
LD DE,5429H 11 29 54
Point Register Pair DE to 5429H, where the last byte of the header goes.
526B
LD BC,0009H 01 09 00
Load Register Pair BC with 0009H, the 9 bytes of the header (540CH-5414H).
526E
LDDR ED B8
Copy the header from Register Pair HL (5414H) down to Register Pair DE (5429H), Register Pair BC the count (LDDR): the header lies at 5421H-5429H, just before the JP at 542AH.
5270
LD HL,0147H 21 47 01
Load Register Pair HL with 0147H (327), the length of the Percom module.
5273
LD (5356H),HL 22 56 53
Store Register Pair HL (0147H) at 5356H-5357H, the length of the module (0158H in the file).
5276
EX DE,HL EB
Exchange Register Pairs DE and HL: Register Pair DE = 0147H.
5277
LD HL,5421H 21 21 54
Load Register Pair HL with 5421H, the first byte of the Percom module (its header).
527A
LD (5358H),HL 22 58 53
Store Register Pair HL (5421H) at 5358H-5359H, the first byte of the module (540CH in the file).
527D
ADD HL,DE 19
ADD Register Pair DE (0147H) to Register Pair HL (5421H): 5568H.
527E
DEC HL 2B
DECrement Register Pair HL: 5567H, the last byte of the Percom module (the RET of its density routine).
527F
LD (535AH),HL 22 5A 53
Store Register Pair HL (5567H) at 535AH-535BH, the last byte of the module (5563H in the file).
5282
LD HL,535CH 21 5C 53
Point Register Pair HL to 535CH, the count of the operands to move (0FH in the file).
5285
DEC (HL) 35
DECrement the count at Register Pair HL (535CH) to 0EH: the 15th entry (521CH, the operand at 54C3H) now holds 462AH and is not moved.

5286H - Is $FDD Already in Place?

For each of the eight drive code tables (4700H-474FH) the address in its JP (+01H-+02H) is taken as a module, and the name length and name at that address +04H are compared with 04H $FDD (5410H). A match ends FDUBL with Driver is already resident!. A drive that is not present (RET at +00H) is checked the same way, at whatever address its +01H-+02H hold.

5286
LD HL,4701H 21 01 47
Point Register Pair HL to 4701H, +01H of drive 0's drive code table: the address of the driver in its JP.
5289
PUSH HL E5
Save Register Pair HL (the address of +01H of the table) to the stack. 52B0H loops back here.
528A
LD A,(HL) 7E
Fetch the low byte of the driver address at Register Pair HL into Register A.
528B
INC HL 23
INCrement Register Pair HL to +02H of the table.
528C
LD H,(HL) 66
Fetch the high byte of the driver address at Register Pair HL into Register H.
528D
LD L,A 6F
Copy Register A (the low byte) into Register L: Register Pair HL = the address of the drive's driver.
528E
INC HL 23
INCrement Register Pair HL: the driver address +01H.
528F
INC HL 23
INCrement Register Pair HL: the driver address +02H.
5290
INC HL 23
INCrement Register Pair HL: the driver address +03H.
5291
INC HL 23
INCrement Register Pair HL: the driver address +04H, where a module header has the length of its name.
5292
LD DE,5410H 11 10 54
Point Register Pair DE to 5410H, the header's name length (04H), followed by the name $FDD.
5295
LD A,(DE) 1A
Fetch the name length at Register Pair DE (5410H) into Register A: 04H.
5296
CP (HL) BE
Compare Register A (04H) against the byte at Register Pair HL (the driver +04H).
5297
If the NZ FLAG is set (not 04H), JUMP to 52A8H for the next table.
5299
INC HL 23
INCrement Register Pair HL to the first character of the name in the driver.
529A
INC DE 13
INCrement Register Pair DE to 5411H, the first character of $FDD.
529B
LD B,A 47
Copy Register A (04H, the length) into Register B, the count of the characters.
529C
LD A,(DE) 1A
Fetch a character of $FDD at Register Pair DE into Register A.
529D
CP (HL) BE
Compare Register A (the character) against the byte at Register Pair HL (the driver's name).
529E
If the NZ FLAG is set (another name), JUMP to 52A8H for the next table.
52A0
INC DE 13
INCrement Register Pair DE to the next character of $FDD.
52A1
INC HL 23
INCrement Register Pair HL to the next character of the driver's name.
52A2
DECrement Register B (the characters left) and LOOP BACK to 529CH until the four are compared.
52A4
POP HL E1
Restore Register Pair HL from the stack: this drops the saved address, to leave the stack as it was.
52A5
JUMP to 5321H to display Driver is already resident! and end: a driver named $FDD already serves this drive.
52A8
POP HL E1
Restore Register Pair HL from the stack: the address of +01H of the table.
52A9
LD DE,000AH 11 0A 00
Load Register Pair DE with 000AH, the ten bytes of a drive code table.
52AC
ADD HL,DE 19
ADD Register Pair DE (000AH) to Register Pair HL: +01H of the next drive's table.
52AD
LD A,51H 3E 51
Load Register A with 51H, the low byte of 4751H, +01H of a ninth table that does not exist.
52AF
CP L BD
Compare Register A (51H) against Register L (the low byte of the pointer).
52B0
If the NZ FLAG is set (tables are left), LOOP BACK to 5289H.

52B2H - Move the Operands

The module goes so that its last byte lies at HIGH$: the distance is HIGH$ less the last byte in the image (535AH). The distance is added to the operand of each instruction the table at 5200H names (535CH entries).

52B2
LD IX,5200H DD 21 00 52
Point Index Register IX to 5200H, the table of the instructions whose operands move.
52B6
LD HL,(4049H) 2A 49 40
Fetch HIGH$ from 4049H into Register Pair HL: where the module's last byte goes.
52B9
LD DE,(535AH) ED 5B 5A 53
Fetch the last byte of the module from 535AH-535BH into Register Pair DE: 5563H, or 5567H for PERCOM.
52BD
OR A B7
Set the flags from Register A (OR A): the CARRY FLAG is clear for the SBC.
52BE
SBC HL,DE ED 52
SUBtract Register Pair DE (the module's last byte) from Register Pair HL (HIGH$): the distance of the move.
52C0
LD B,H 44
Copy Register H (the high byte of the distance) into Register B.
52C1
LD C,L 4D
Copy Register L (the low byte of the distance) into Register C: Register Pair BC = the distance.
52C2
LD A,(535CH) 3A 5C 53
Fetch the count of the operands from 535CH into Register A: 0FH, or 0EH for PERCOM.
52C5
LD L,(IX+00H) DD 6E 00
Fetch the low byte of the table entry at Index Register IX (IX+00H) into Register L. 52DAH loops back here.
52C8
LD H,(IX+01H) DD 66 01
Fetch the high byte of the table entry at Index Register IX (IX+01H) into Register H: Register Pair HL = the address of an instruction.
52CB
INC HL 23
INCrement Register Pair HL to the low byte of the instruction's operand.
52CC
LD E,(HL) 5E
Fetch the low byte of the operand at Register Pair HL into Register E.
52CD
INC HL 23
INCrement Register Pair HL to the high byte of the operand.
52CE
LD D,(HL) 56
Fetch the high byte of the operand at Register Pair HL into Register D: Register Pair DE = the operand, an address in the module.
52CF
EX DE,HL EB
Exchange Register Pairs DE and HL: Register Pair HL = the operand, Register Pair DE = the address of its high byte.
52D0
ADD HL,BC 09
ADD Register Pair BC (the distance) to Register Pair HL (the operand): its address after the move.
52D1
EX DE,HL EB
Exchange Register Pairs DE and HL: Register Pair DE = the new operand, Register Pair HL = the address of its high byte.
52D2
LD (HL),D 72
Store Register D (the high byte of the new operand) at Register Pair HL.
52D3
DEC HL 2B
DECrement Register Pair HL to the low byte of the operand.
52D4
LD (HL),E 73
Store Register E (the low byte of the new operand) at Register Pair HL.
52D5
INC IX DD 23
INCrement Index Register IX to the high byte of the table entry.
52D7
INC IX DD 23
INCrement Index Register IX to the next entry of the table.
52D9
DEC A 3D
DECrement Register A, the table entries still to do.
52DA
If the NZ FLAG is set (entries left), LOOP BACK to 52C5H.

52DCH - Copy the Module, Lower HIGH$, Take Over the Drives

The module is copied to end at HIGH$, and HIGH$ goes below it. Every drive code table whose +04H has bit 4 clear gets the module's first byte (the header's JR to the driver) in its JP (+01H-+02H) and bit 6 of +04H set: the drive's controller can do double density. A table that starts with RET (C9H) gets them too, without effect.

52DC
LD DE,(4049H) ED 5B 49 40
Fetch HIGH$ from 4049H into Register Pair DE: where the module's last byte goes.
52E0
LD HL,(535AH) 2A 5A 53
Fetch the last byte of the module from 535AH-535BH into Register Pair HL: 5563H, or 5567H for PERCOM.
52E3
LD BC,(5356H) ED 4B 56 53
Fetch the length of the module from 5356H-5357H into Register Pair BC: 0158H, or 0147H for PERCOM.
52E7
LDDR ED B8
Copy the module from Register Pair HL down to Register Pair DE, Register Pair BC the count (LDDR): its last byte lies at HIGH$. Register Pair DE comes out one below its first byte.
52E9
EX DE,HL EB
Exchange Register Pairs DE and HL: Register Pair HL = the byte below the module.
52EA
LD (4049H),HL 22 49 40
Store Register Pair HL at 4049H, HIGH$: the module is above the highest address free for programs.
52ED
INC HL 23
INCrement Register Pair HL: the module's first byte, the 18H (JR) of its header.
52EE
LD IY,4700H FD 21 00 47
Point Index Register IY to 4700H, the drive code table of drive 0.
52F2
LD B,08H 06 08
Load Register B with 08H, the eight drives 0-7 to visit.
52F4
LD DE,000AH 11 0A 00
Load Register Pair DE with 000AH, the ten bytes of a drive code table.
52F7
BIT 4,(IY+04H) FD CB 04 66
Test bit 4 of +04H of the drive code table at Index Register IY: when set the drive is not taken over (SYS2/SYS's @CKDRV skips its index test for such a drive, FORMAT/CMD writes no tracks on it). 5309H loops back here.
52FB
If the NZ FLAG is set (bit 4 set), JUMP to 5307H: the drive is not taken over.
52FD
LD (IY+01H),L FD 75 01
Store Register L (the low byte of the module's first byte) into +01H of the drive code table at Index Register IY.
5300
LD (IY+02H),H FD 74 02
Store Register H (the high byte) into +02H of the drive code table at Index Register IY: the drive's JP goes to the module.
5303
SET 6,(IY+04H) FD CB 04 F6
Set bit 6 of +04H of the drive code table at Index Register IY: the drive's controller can do double density.
5307
ADD IY,DE FD 19
ADD Register Pair DE (000AH) to Index Register IY: the next drive's table.
5309
DECrement Register B (the drives left) and LOOP BACK to 52F7H.

530BH - The End

The return code 0000H (success) or FFFFH (an error) goes to Register Pair HL, the Stack Pointer of the entry comes back, and the program returns to LDOS; an error during a JCL job ends at @ABORT.

530B
LD HL,0000H 21 00 00
Load Register Pair HL with 0000H, the return code of a program that ended without an error.
530E
LD SP,0000H 31 00 00
Load the Stack Pointer with the value LDOS gave: the operand 530FH-5310H, 0000H in the file, stored by 521EH. 532AH comes here with FFFFH.
5311
LD A,H 7C
Copy Register H (the high byte of the return code) into Register A.
5312
OR L B5
OR Register L (the low byte) into Register A: the Z FLAG for 0000H.
5313
RET Z C8
If the Z FLAG is set (no error), RETurn to LDOS with Register Pair HL = 0000H.
5314
LD A,(430FH) 3A 0F 43
Fetch SFLAG$ from 430FH into Register A: bit 5 is set while a JCL job runs.
5317
BIT 5,A CB 6F
Test bit 5 of Register A (SFLAG$): a JCL job.
5319
RET Z C8
If the Z FLAG is set (no job), RETurn to LDOS with Register Pair HL = FFFFH.
531A
JUMP to 4030H, @ABORT: the error ends the job.

531DH - The Errors

Two messages through one @LOGOT: 531DH loads the first; the next instruction, LD IX at 5320H, passes over the LD HL that starts at 5321H, the entry for the second. 532CH gives an error number through @ERROR.

531D
LD HL,535DH 21 5D 53
Point Register Pair HL to 535DH, the text Can't specify both Percom and Tandy! ended by 0DH (5249H).
5320
LD IX,5382H DD 21 82 53
Load Index Register IX with 5382H: entered from 531DH this only passes over the LD HL that starts at 5321H, and Register Pair HL keeps 535DH. Entered at 5321H from 52A5H, the bytes 21H 82H 53H are LD HL,5382H: Register Pair HL points to Driver is already resident!.
5324
GOSUB to 447BH, @LOGOT, to display the text at Register Pair HL (535DH or 5382H) and write it to the job log.
5327
LD HL,FFFFH 21 FF FF
Load Register Pair HL with FFFFH, the return code of an error.
532A
JUMP to 530EH to end with Register Pair HL = FFFFH.
532C
OR C0H F6 C0
Set bits 7 and 6 in Register A (OR C0H): error 2CH as ECH, bit 7 so that @ERROR returns, bit 6 for the short message.
532E
GOSUB to 4409H, @ERROR, to display the message of the error in Register A (Parameter error).
5331
JUMP to 5327H to end with Register Pair HL = FFFFH.

5333H - The Parameters, the Cells of the Module, the Texts

The table @PARAM reads (522DH): the name, 6 characters padded with spaces, and the address of the operand that takes its value; 00H ends it. Then the TANDY parameter, the length, first and last byte of the module and the count of operands to move (the PERCOM build changes the last four), and the texts.

5333-533A
DEFM "PERCOM" / DEFW 523CH 50 45 52 43 4F 4D 3C 52
5333H-533AH: PERCOM, the Percom doubler: the operand of LD HL,0000H at 523BH.
533B-5342
DEFM "P " / DEFW 523CH 50 20 20 20 20 20 3C 52
533BH-5342H: P, the short form of PERCOM: 523CH.
5343-534A
DEFM "TANDY " / DEFW 5354H 54 41 4E 44 59 20 54 53
5343H-534AH: TANDY, the Tandy adapter, the module as the file has it: the word at 5354H, tested only at 5243H.
534B-5352
DEFM "T " / DEFW 5354H 54 20 20 20 20 20 54 53
534BH-5352H: T, the short form of TANDY: 5354H.
5353
DEFB 00H 00
5353H: 00H, the end of the table of the parameters.
5354-5355
DEFW 0000H 00 00
5354H-5355H: the TANDY parameter, 0000H in the file, FFFFH for TANDY or T (5243H-5249H).
5356-5357
DEFW 0158H 58 01
5356H-5357H: the length of the module, 0158H (344 bytes, 540CH-5563H); 0147H for PERCOM (5273H). Read by 52E3H.
5358-5359
DEFW 540CH 0C 54
5358H-5359H: the first byte of the module, 540CH; 5421H for PERCOM (527AH). No code reads it.
535A-535B
DEFW 5563H 63 55
535AH-535BH: the last byte of the module, 5563H; 5567H for PERCOM (527FH). Read by 52B9H and 52E0H.
535C
DEFB 0FH 0F
535CH: the count of the operands to move, 0FH (15); 0EH for PERCOM (5285H). Read by 52C2H.
535D-5380
DEFM "Can't specify both Percom and Tandy!" 43 61 6E 27 74 20 73 70 65 63 69 66 79 20 62 6F 74 68 20 50 65 72 63 6F 6D 20 61 6E 64 20 54 61 6E 64 79 21
535DH-5380H: the text of 531DH, for PERCOM and TANDY both given.
5381
DEFB 0DH 0D
5381H: 0DH, the end of the line and of the text.
5382-539C
DEFM "Driver is already resident!" 44 72 69 76 65 72 20 69 73 20 61 6C 72 65 61 64 79 20 72 65 73 69 64 65 6E 74 21
5382H-539CH: the text of 5321H, for a drive served by a module named $FDD.
539D
DEFB 0DH 0D
539DH: 0DH, the end of the line and of the text.
539E-53D7
DEFM "FDUBL 5.3.1 - Driver for the Percom and Tandy type doubler" 46 44 55 42 4C 20 35 2E 33 2E 31 20 2D 20 44 72 69 76 65 72 20 66 6F 72 20 74 68 65 20 50 65 72 63 6F 6D 20 61 6E 64 20 54 61 6E 64 79 20 74 79 70 65 20 64 6F 75 62 6C 65 72
539EH-53D7H: the first line of the banner (5223H).
53D8
DEFB 0AH 0A
53D8H: 0AH, a new line within the banner, before the copyright.
53D9-540A
DEFM "Copyright 1991, MISOSYS, Inc., All rights reserved" 43 6F 70 79 72 69 67 68 74 20 31 39 39 31 2C 20 4D 49 53 4F 53 59 53 2C 20 49 6E 63 2E 2C 20 41 6C 6C 20 72 69 67 68 74 73 20 72 65 73 65 72 76 65 64
53D9H-540AH: the second line of the banner, the copyright.
540B
DEFB 0DH 0D
540BH: 0DH, the end of the banner and of its second line.

540CH - The Module $FDD: Header

The module is the floppy disk driver for double density, 540CH-5563H for the Tandy adapter. Copied above HIGH$ (52E7H), its first byte is where every drive's JP goes. The header: 18H and a displacement (a JR to the driver at 544FH), the link word (the HIGH$ before the module, 5238H), the length of the name (04H) and the name $FDD. Its addresses are the file's; 52B2H moves the operands that point inside it.

540C
JUMP to 544FH, the driver's entry (the displacement 41H at 540DH). The drive's JP comes here with Register B = the function. The PERCOM build moves the header to 5421H with the displacement 2CH (5574H), so its JR also reaches 544FH.
540E-540F
DEFW 0000H 00 00
540EH-540FH: the link word of the header, 0000H in the file: the HIGH$ before the module is copied (5238H).
5410
DEFB 04H 04
5410H: 04H, the length of the name; 5292H compares it.
5411-5414
DEFM "$FDD" 24 46 44 44
5411H-5414H: the name of the module, $FDD; 529CH compares it.

5415H - Seek With the Precompensation (Tandy Adapter)

Function 06H and the sector functions come here: after the controller is free, the adapter's precompensation is turned on (E0H to 37EEH) when the cylinder the head is on (+05H) is above half of (the highest cylinder plus 7), else off (C0H); then SYS0/SYS's seek at 462DH. The PERCOM build has no such routine: its header lies at 5421H-5429H, and 542AH goes to 462AH.

5415
GOSUB to 461CH (SYS0/SYS) to wait until the controller is not busy, keeping the drive selected.
5418
LD A,(IY+06H) FD 7E 06
Fetch +06H of the drive code table at Index Register IY into Register A: the highest cylinder.
541B
ADD A,07H C6 07
ADD 07H to Register A (the highest cylinder).
541D
RRA 1F
Rotate Register A right through the CARRY FLAG (RRA, the CARRY FLAG clear after the ADD): half of (the highest cylinder plus 7), the last cylinder without precompensation.
541E
CP (IY+05H) FD BE 05
Compare Register A (that cylinder) against +05H of the drive code table at Index Register IY: the cylinder the head is on. The CARRY FLAG when the head is above it.
5421
LD A,C0H 3E C0
Load Register A with C0H, the adapter's code for the precompensation off. LD does not change the flags.
5423
If the NO CARRY FLAG is set (the head is not above that cylinder), JUMP to 5427H with C0H.
5425
OR 20H F6 20
OR 20H into Register A: E0H, the precompensation on.
5427
LD (37EEH),A 32 EE 37
Store Register A (C0H or E0H) to 37EEH, the controller's sector register: the Tandy adapter takes the three high bits of the byte as its code.
542A
JUMP to 462DH (SYS0/SYS): seek cylinder Register D for sector Register E (the side from the sector number); its RET goes to the caller. The PERCOM build stores 462AH here (525FH).

542DH - Change the Density

Called from 5540H when a sector was not found: bit 6 of +03H (double density) is changed, +07H and +08H get the geometry of the other density (single 09H 24H, double 11H 45H), and the adapter is set for it. On an odd count of tries left (bit 0 of Register B) the head is also restored to cylinder 0.

542D
PUSH HL E5
Save Register Pair HL (the caller's buffer address) to the stack.
542E
LD A,(IY+03H) FD 7E 03
Fetch +03H of the drive code table at Index Register IY into Register A: the drive's flags, bit 6 double density.
5431
XOR 40H EE 40
Exclusive OR 40H into Register A: bit 6 changed, the other density.
5433
LD (IY+03H),A FD 77 03
Store Register A (the flags) into +03H of the drive code table at Index Register IY.
5436
LD HL,2409H 21 09 24
Load Register Pair HL with 2409H, the geometry of single density: Register L = 09H for +07H (10 sectors), Register H = 24H for +08H.
5439
BIT 6,A CB 77
Test bit 6 of Register A (the new flags): set for double density.
543B
If the Z FLAG is set (single density now), JUMP to 5440H with 2409H.
543D
LD HL,4511H 21 11 45
Load Register Pair HL with 4511H, the geometry of double density: Register L = 11H for +07H (18 sectors), Register H = 45H for +08H.
5440
LD (IY+07H),L FD 75 07
Store Register L into +07H of the drive code table at Index Register IY: the highest sector on a track.
5443
LD (IY+08H),H FD 74 08
Store Register H into +08H of the drive code table at Index Register IY: the granules on a track and the sectors in a granule.
5446
POP HL E1
Restore Register Pair HL from the stack: the caller's buffer address.
5447
GOSUB to 5558H to set the adapter for the density in bit 6 of +03H.
544A
BIT 0,B CB 40
Test bit 0 of Register B, the tries left: set for an odd count.
544C
RET Z C8
If the Z FLAG is set (an even count), RETurn to 5543H.
544D
JUMP to 546BH to restore the head to cylinder 0 (+05H = 0); its RET goes to 5543H.

544FH - The Driver: the Functions

Register B = the function, Register C = the drive, Register D = the cylinder, Register E = the sector, Register Pair HL = the buffer, Index Register IY = the drive code table. As in SYS0/SYS's driver (45FBH): 00H returns, 07H waits (461CH), 01H selects (45E0H), 02H-04H restore and 05H steps in (4659H); 06H seeks through 5415H; 08H and up (the sector and track functions) go to 5477H.

544F
LD A,B 78
Copy Register B (the function) into Register A.
5450
OR A B7
Set the flags from Register A (OR A): the Z FLAG for function 00H.
5451
RET Z C8
If the Z FLAG is set (function 00H), RETurn with Register A = 00H and the Z FLAG: nothing done.
5452
CP 07H FE 07
Compare Register A (the function) against 07H.
5454
If the Z FLAG is set (function 07H), JUMP to 461CH (SYS0/SYS) to wait until the controller is not busy; it returns the status in Register A.
5457
If the NO CARRY FLAG is set (08H and up), JUMP to 5477H for the sector and track functions.
545A
CP 06H FE 06
Compare Register A (the function) against 06H.
545C
If the Z FLAG is set (function 06H, seek), JUMP to 5415H for the precompensation and the seek. The PERCOM build changes the displacement at 545DH to CCH, a JR Z,542AH.
545E
DEC A 3D
DECrement Register A (the function): the Z FLAG for function 01H.
545F
If the Z FLAG is set (function 01H), JUMP to 5474H to select the drive.
5461
INC (IY+05H) FD 34 05
INCrement +05H of the drive code table at Index Register IY, the cylinder the head is on: a Step In moves one cylinder in; a restore sets it to 0 at 546BH.
5464
CP 04H FE 04
Compare Register A (the function less 1) against 04H: the Z FLAG for function 05H.
5466
LD B,58H 06 58
Load Register B with 58H, the command Step In with the track register updated. LD does not change the flags.
1771 FDC Command: 58H (01011000)Function Description
Bit 7Bit 6Bit 5Bit 4Bit 3Bit 2Bit 1Bit 0Summary of Bits
01011000Command=Step In (bits 7-5 = 010)
u = 1: update the track register
h = 1: head load and settle delay
V = 0: no verify
r1 r0 = 00: 6 ms (12 ms on the Radio Shack interface) stepping rate
5468
If the Z FLAG is set (function 05H), JUMP to 4659H (SYS0/SYS) to issue the command in Register B with the drive's step rate.
546B
LD (IY+05H),00H FD 36 05 00
Store 00H into +05H of the drive code table at Index Register IY: after a restore the head is on cylinder 0. 544DH comes here.
546F
LD B,08H 06 08
Load Register B with 08H, the command Restore.
1771 FDC Command: 08H (00001000)Function Description
Bit 7Bit 6Bit 5Bit 4Bit 3Bit 2Bit 1Bit 0Summary of Bits
00001000Command=Restore (bits 7-4 = 0000)
h = 1: head load and settle delay
V = 0: no verify
r1 r0 = 00: 6 ms (12 ms on the Radio Shack interface) stepping rate
5471
JUMP to 4659H (SYS0/SYS) to issue the command in Register B (08H) with the drive's step rate; it returns Register A = 00H and the Z FLAG.
5474
JUMP to 45E0H (SYS0/SYS) to select the drive and its side, waiting for the motor when it was off.

5477H - The Sector and Track Functions

The adapter is set for the drive's density. Function 09H reads (10 tries), 0AH verifies (4 tries), 0BH reads too, 0CH and 0DH write a sector (A8H, 6 tries), 0EH writes a sector with the deleted data mark (A9H, 6 tries), 0FH writes a track (F4H, 6 tries). A write is refused with error 0FH when bit 7 of +03H is set. Each CALL 54B1H is followed by three bytes: the first error number of the operation and the two bytes of the transfer loop.

5477
GOSUB to 461CH (SYS0/SYS) to wait until the controller is not busy.
547A
GOSUB to 5558H to set the adapter for the density in bit 6 of +03H of the drive code table.
547D
LD A,B 78
Copy Register B (the function) into Register A.
547E
BIT 2,B CB 50
Test bit 2 of Register B (the function): set for 0CH-0FH, the writes.
5480
LD BC,06A8H 01 A8 06
Load Register Pair BC with 06A8H: Register B = 6 tries, Register C = A8H, the command Write Sector. LD does not change the flags.
1771 FDC Command: A8H (10101000)Function Description
Bit 7Bit 6Bit 5Bit 4Bit 3Bit 2Bit 1Bit 0Summary of Bits
10101000Command=Write Sector (bits 7-5 = 101)
m = 0: one sector
b = 1: IBM sector length
E = 0: no head load delay
a1 a0 = 00: data mark FBH (normal)
5483
If the NZ FLAG is set (a write), JUMP to 549AH.
5485
LD BC,0488H 01 88 04
Load Register Pair BC with 0488H: Register B = 4 tries, Register C = 88H, the command Read Sector.
1771 FDC Command: 88H (10001000)Function Description
Bit 7Bit 6Bit 5Bit 4Bit 3Bit 2Bit 1Bit 0Summary of Bits
10001000Command=Read Sector (bits 7-5 = 100)
m = 0: one sector
b = 1: IBM sector length
E = 0: no head load delay
5488
CP 0AH FE 0A
Compare Register A (the function) against 0AH, verify.
548A
If the Z FLAG is set (function 0AH), JUMP to 5494H with 4 tries.
548C
LD B,0AH 06 0A
Load Register B with 0AH, 10 tries for a read (functions 08H, 09H, 0BH).
548E
GOSUB to 54B1H with the three bytes that follow (01H, 1AH, 02H); it does not return here but goes on at 54BFH.
5491-5493
DEFB 01H, 1AH, 02H 01 1A 02
5491H-5493H: the parameters of a read: 01H, the first error number (to 46F6H), and 1AH 02H, the loop body LD A,(DE) / LD (BC),A: a byte from the data register into the buffer.
5494
GOSUB to 54B1H with the three bytes that follow (01H, 1AH, 7EH); it goes on at 54BFH.
5497-5499
DEFB 01H, 1AH, 7EH 01 1A 7E
5497H-5499H: the parameters of a verify: 01H, the first error number, and 1AH 7EH, the loop body LD A,(DE) / LD A,(HL): the byte is read and not stored.
549A
CP 0EH FE 0E
Compare Register A (the function) against 0EH.
549C
If the CARRY FLAG is set (0CH or 0DH), JUMP to 54A4H with the command A8H.
549E
LD C,F4H 0E F4
Load Register C with F4H, the command Write Track, for function 0FH. LD does not change the flags.
1771 FDC Command: F4H (11110100)Function Description
Bit 7Bit 6Bit 5Bit 4Bit 3Bit 2Bit 1Bit 0Summary of Bits
11110100Command=Write Track (bits 7-4 = 1111)
E = 1: head load delay
In the data, F7H writes the two CRC bytes and F8H-FEH are written as address marks
54A0
If the NZ FLAG is set (function 0FH), JUMP to 54A4H with Write Track.
54A2
LD C,A9H 0E A9
Load Register C with A9H, Write Sector with bit 0 set, the deleted data mark, for function 0EH; 54DEH-54E8H makes it ABH in single density.
54A4
BIT 7,(IY+03H) FD CB 03 7E
Test bit 7 of +03H of the drive code table at Index Register IY: the drive's software write protect.
54A8
LD A,0FH 3E 0F
Load Register A with 0FH, the error number of a write protected disk. LD does not change the flags.
54AA
RET NZ C0
If the NZ FLAG is set (write protected), RETurn with Register A = 0FH and the NZ FLAG.
54AB
GOSUB to 54B1H with the three bytes that follow (09H, 12H, 0AH); it goes on at 54BFH.
54AE-54B0
DEFB 09H, 12H, 0AH 09 12 0A
54AEH-54B0H: the parameters of a write: 09H, the first error number of a write, and 12H 0AH, the loop body LD (DE),A / LD A,(BC): the byte in Register A to the data register, then the next byte of the buffer.

54B1H - Take the Three Parameters

The return address of the CALL points to the three bytes. The first goes to 46F6H, the first error number of SYS0/SYS's error decoder (46F4H); the other two become the body of the transfer loop at 550AH-550BH. The return address is dropped: the code goes on at 54BFH.

54B1
EX (SP),HL E3
Exchange Register Pair HL with the top of the stack (the Stack Pointer is not changed): Register Pair HL = the address of the three bytes, the caller's Register Pair HL (the buffer) on the stack.
54B2
LD A,(HL) 7E
Fetch the first byte at Register Pair HL into Register A: the first error number (01H or 09H).
54B3
INC HL 23
INCrement Register Pair HL to the second byte.
54B4
LD (46F6H),A 32 F6 46
Store Register A (the first error number) at 46F6H, the operand of LD A at 46F5H in SYS0/SYS's error decoder.
54B7
LD A,(HL) 7E
Fetch the second byte at Register Pair HL into Register A: the first byte of the loop body.
54B8
INC HL 23
INCrement Register Pair HL to the third byte.
54B9
LD H,(HL) 66
Fetch the third byte at Register Pair HL into Register H: the second byte of the loop body.
54BA
LD L,A 6F
Copy Register A (the first byte of the loop body) into Register L: Register Pair HL = the loop body.
54BB
LD (550AH),HL 22 0A 55
Store Register Pair HL (the two bytes of the loop body) at 550AH-550BH.
54BE
POP HL E1
Restore Register Pair HL from the stack: the caller's buffer address. The return address is gone.

54BFH - Issue the Command, Move the Bytes, Try Again

Register B = the tries left, Register C = the command, Register Pair HL = the buffer. A sector command first seeks (5415H, or 462AH for PERCOM); a Write Track works on the cylinder the head is on. The cylinder goes to the track register and the command to the controller. A write waits for the first request, gives the first byte, takes the next one ahead and enters the loop; a read waits for the first byte and enters the loop at its second instruction. The loop at 550AH-5525H tests for the next request five times between each test of BUSY, so that a byte of double density is never missed. Lost data (bit 2) tries again without counting; not found (bit 4) changes the density (542DH) and, like a CRC error (bit 3), counts a try; any other error, or the last try, goes to SYS0/SYS's error decoder (46F4H). The caller's alternate Register Pair AF' is kept.

54BF
PUSH BC C5
Save Register Pair BC (Register B = the tries left, Register C = the command) to the stack. 5536H and 5546H come back here for another try.
54C0
BIT 4,C CB 61
Test bit 4 of Register C (the command): set only for Write Track (F4H).
54C2
If the Z FLAG is set (a sector command), GOSUB to 5415H to set the precompensation and seek cylinder Register D for sector Register E. The PERCOM build calls 462AH (SYS0/SYS's seek) here (5262H).
54C5
PUSH IX DD E5
Save Index Register IX to the stack: it points to the loop below until the end.
54C7
PUSH DE D5
Save Register Pair DE (the cylinder and sector) to the stack.
54C8
EX AF,AF' 08
Exchange Register Pair AF with the alternate AF': the alternate is used for a byte of the write below.
54C9
PUSH AF F5
Save Register Pair AF (the caller's AF', now in the main set) to the stack.
54CA
PUSH HL E5
Save Register Pair HL (the buffer) to the stack.
54CB
LD IX,550BH DD 21 0B 55
Point Index Register IX to 550BH, the second instruction of the transfer loop, where a read enters it (5556H).
54CF
LD HL,37EDH 21 ED 37
Point Register Pair HL to 37EDH, the controller's track register.
54D2
GOSUB to 461CH (SYS0/SYS) to wait until the controller is not busy: the seek is finished.
54D5
GOSUB to 46FDH (SYS0/SYS): a NOP and a RET, or DI when SYSTEM (SMOOTH) stored F3H there, so that interrupts stay off for the transfer.
54D8
LD (HL),D 72
Store Register D (the cylinder) to the track register at Register Pair HL (37EDH): the controller compares it with the sector's ID field.
54D9
DEC HL 2B
DECrement Register Pair HL to 37ECH, the command and status register.
54DA
LD DE,37EFH 11 EF 37
Point Register Pair DE to 37EFH, the controller's data register.
54DD
LD A,C 79
Copy Register C (the command) into Register A.
54DE
CP A9H FE A9
Compare Register A (the command) against A9H, Write Sector with the deleted data mark.
54E0
If the NZ FLAG is set (another command), JUMP to 54EAH to issue it as it is.
54E2
BIT 6,(IY+03H) FD CB 03 76
Test bit 6 of +03H of the drive code table at Index Register IY: set for double density.
54E6
If the NZ FLAG is set (double density), JUMP to 54EAH: A9H stays.
54E8
LD A,ABH 3E AB
Load Register A with ABH, Write Sector with bits 1-0 set, the deleted data mark F8H in single density.
1771 FDC Command: ABH (10101011)Function Description
Bit 7Bit 6Bit 5Bit 4Bit 3Bit 2Bit 1Bit 0Summary of Bits
10101011Command=Write Sector (bits 7-5 = 101)
m = 0: one sector
b = 1: IBM sector length
E = 0: no head load delay
a1 a0 = 11: data mark F8H
54EA
GOSUB to 4662H (SYS0/SYS) to write Register A (the command) to 37ECH and wait a moment; Register A and Register B come back as 00H.
54ED
BIT 5,C CB 69
Test bit 5 of Register C (the command): set for the writes (A8H, A9H, F4H), clear for Read Sector (88H).
54EF
POP BC C1
Restore Register Pair BC from the stack: the buffer address saved at 54CAH.
54F0
PUSH BC C5
Save Register Pair BC (the buffer address) to the stack again, for the end at 5529H.
54F1
If the Z FLAG is set (a read or a verify), JUMP to 554EH.
54F3
EI FB
Enable interrupts while the write waits for its first request. 54F8H loops back here.
54F4
LD A,76H 3E 76
Load Register A with 76H, the status bits that end the wait: 6, 5, 4, 2 and 1 (DATA REQUEST).
54F6
DI F3
Disable interrupts for the test of the controller's status.
54F7
AND (HL) A6
AND the controller's status at Register Pair HL (37ECH) into Register A: not 0 when a byte is wanted or an error is shown.
54F8
If the Z FLAG is set (none of those bits), JUMP to 54F3H to wait.
54FB
LD A,(BC) 0A
Fetch the first byte of the buffer at Register Pair BC into Register A.
54FC
LD (DE),A 12
Store Register A (the first byte) to the data register at Register Pair DE (37EFH).
54FD
INC BC 03
INCrement Register Pair BC to the second byte of the buffer.
54FE
LD A,(BC) 0A
Fetch the second byte of the buffer at Register Pair BC into Register A, ready before the next request.
54FF
INC BC 03
INCrement Register Pair BC to the third byte of the buffer.
5500
EX AF,AF' 08
Exchange Register Pair AF with the alternate AF': the second byte waits in the alternate Register A.
5501
LD A,(HL) 7E
Fetch the controller's status at Register Pair HL (37ECH) into Register A.
5502
AND FCH E6 FC
Mask Register A to bits 7-2 (AND FCH): DATA REQUEST and BUSY cleared.
5504
OR 01H F6 01
Set bit 0 in Register A (OR 01H): the status as it reads while the controller is busy without a request.
5506
CP (HL) BE
Compare Register A (that status) against the status at Register Pair HL (37ECH). 5507H loops back here.
5507
If the Z FLAG is set (no change: busy, no request), LOOP BACK to 5506H.
5509
EX AF,AF' 08
Exchange Register Pair AF with the alternate AF': Register A = the second byte of the buffer.
550A
NOP 00
The first byte of the loop body, 00H (NOP) in the file; 54BBH stores 1AH (LD A,(DE): read the data register) or 12H (LD (DE),A: write it). 550FH-5521H loop back here for every byte.
550B
NOP 00
The second byte of the loop body, 00H (NOP) in the file; 54BBH stores 02H (LD (BC),A: into the buffer), 7EH (LD A,(HL): the verify keeps nothing) or 0AH (LD A,(BC): the next byte to write). A read enters here (5556H).
550C
INC BC 03
INCrement Register Pair BC to the next byte of the buffer.
550D
BIT 1,(HL) CB 4E
Test bit 1 of the status at Register Pair HL (37ECH): DATA REQUEST. 5525H loops back here.
550F
If the NZ FLAG is set (a request), JUMP to 550AH for the next byte.
5512
BIT 1,(HL) CB 4E
Test bit 1 of the status at Register Pair HL (37ECH): DATA REQUEST, the second test.
5514
If the NZ FLAG is set (a request), JUMP to 550AH for the next byte.
5517
BIT 1,(HL) CB 4E
Test bit 1 of the status at Register Pair HL (37ECH): DATA REQUEST, the third test.
5519
If the NZ FLAG is set (a request), JUMP to 550AH for the next byte.
551B
BIT 1,(HL) CB 4E
Test bit 1 of the status at Register Pair HL (37ECH): DATA REQUEST, the fourth test.
551D
If the NZ FLAG is set (a request), JUMP to 550AH for the next byte.
551F
BIT 1,(HL) CB 4E
Test bit 1 of the status at Register Pair HL (37ECH): DATA REQUEST, the fifth test.
5521
If the NZ FLAG is set (a request), JUMP to 550AH for the next byte.
5523
BIT 0,(HL) CB 46
Test bit 0 of the status at Register Pair HL (37ECH): BUSY.
5525
If the NZ FLAG is set (still busy), LOOP BACK to 550DH to test for a request again.
5527
EI FB
Enable interrupts: the command has finished, no byte is to come.
5528
LD A,(HL) 7E
Fetch the controller's final status at Register Pair HL (37ECH) into Register A.
5529
POP HL E1
Restore Register Pair HL from the stack: the buffer address.
552A
EX AF,AF' 08
Exchange Register Pair AF with the alternate AF': the status goes to the alternate set.
552B
POP AF F1
Restore Register Pair AF from the stack: the caller's AF' (saved at 54C9H).
552C
EX AF,AF' 08
Exchange Register Pair AF with the alternate AF': the caller's AF' is back, Register A = the status.
552D
AND 7CH E6 7C
Mask Register A to bits 6-2 of the status (AND 7CH): 6 write protect, 5 write fault or the record type, 4 not found, 3 CRC error, 2 lost data. The Z FLAG when none is on.
552F
POP DE D1
Restore Register Pair DE from the stack: the cylinder and sector.
5530
POP IX DD E1
Restore Index Register IX from the stack, as the caller had it.
5532
POP BC C1
Restore Register Pair BC from the stack: Register B = the tries left, Register C = the command.
5533
RET Z C8
If the Z FLAG is set (no error bit), RETurn with Register A = 00H and the Z FLAG: the operation succeeded.
5534
BIT 2,A CB 57
Test bit 2 of Register A (the error bits): LOST DATA.
5536
If the NZ FLAG is set (lost data), JUMP to 54BFH to try again without counting the try.
5538
PUSH AF F5
Save Register Pair AF (Register A = the error bits) to the stack.
5539
AND 18H E6 18
Mask Register A to bits 4 and 3 (AND 18H): NOT FOUND and CRC ERROR, the errors worth another try.
553B
If the Z FLAG is set (another error: bit 6 or 5), JUMP to 554AH, inside the LD B at 5549H, where the byte F1H is POP AF: no more tries.
553D
BIT 4,A CB 67
Test bit 4 of Register A: NOT FOUND, the sector's ID field was not found.
553F
PUSH BC C5
Save Register Pair BC (the tries and the command) to the stack.
5540
If the NZ FLAG is set (not found), GOSUB to 542DH to change the drive's density (and restore the head on an odd count of tries).
5543
POP BC C1
Restore Register Pair BC from the stack: Register B = the tries left, Register C = the command.
5544
POP AF F1
Restore Register Pair AF from the stack: Register A = the error bits.
5545
DEC B 05
DECrement Register B, the tries left for this operation.
5546
If the NZ FLAG is set (tries left), JUMP to 54BFH to try again.
5549
LD B,F1H 06 F1
Load Register B with F1H. Its only use is to pass over the byte F1H: entered at 554AH from 553BH, F1H is POP AF, which takes back the error bits saved at 5538H. Either way Register A holds the error bits.
554B
JUMP to 46F4H (SYS0/SYS) to turn the error bits in Register A into the error number (the first number at 46F6H plus 2 for bit 2, plus 3 for bit 3 and so on); it returns the NZ FLAG to the caller of the driver.
554E
LD A,(HL) 7E
Fetch the controller's status at Register Pair HL (37ECH) into Register A. 5551H loops back here.
554F
AND 03H E6 03
Mask Register A to bits 1-0 (AND 03H): DATA REQUEST and BUSY.
5551
If the PO FLAG is set (one of the two bits: busy without a byte, or a byte without BUSY), JUMP to 554EH to wait; 00H (finished) and 03H (busy with a byte) go on.
5554
LD A,(DE) 1A
Fetch the first byte from the data register at Register Pair DE (37EFH) into Register A. When neither bit was set the command has ended; a read still stores this byte at 550BH before the loop ends.
5555
DI F3
Disable interrupts for the transfer of the 256 bytes.
5556
JP (IX) DD E9
JUMP to Index Register IX (550BH), the second instruction of the loop body, with the first byte in Register A.

5558H - Set the Density (Tandy Adapter)

The last routine of the module for the Tandy adapter: 80H (double density) or A0H (single density) is written to the controller's sector register, whose three high bits the adapter takes as its code. For PERCOM, 5255H copies the routine at 5564H over it.

5558
LD A,(IY+03H) FD 7E 03
Fetch +03H of the drive code table at Index Register IY into Register A: the drive's flags, bit 6 double density.
555B
AND 40H E6 40
Mask Register A to bit 6 (AND 40H): 40H for double density, 00H for single.
555D
RRCA 0F
Rotate Register A right one place (RRCA): 20H or 00H.
555E
XOR A0H EE A0
Exclusive OR A0H into Register A: 80H for double density, A0H for single density.
5560
LD (37EEH),A 32 EE 37
Store Register A (80H or A0H) to 37EEH, the controller's sector register: the adapter sets the density.
5563
RET C9
RETurn to the caller. The last byte of the module for the Tandy adapter (535AH).

5564H - Set the Density (Percom Doubler)

Not part of the module in the file: 5255H copies these 16 bytes to 5558H-5567H for PERCOM. FEH (single density) or FFH (double density) is written to the controller's command register, where the Percom doubler takes it, then D0H, Force Interrupt, ends it for the controller.

5564
LD A,(IY+03H) FD 7E 03
Fetch +03H of the drive code table at Index Register IY into Register A: the drive's flags, bit 6 double density.
5567
RLCA 07
Rotate Register A left one place (RLCA): bit 6 to bit 7.
5568
RLCA 07
Rotate Register A left one place (RLCA): bit 7 to bit 0, set for double density.
5569
OR FEH F6 FE
Set bits 7-1 in Register A (OR FEH): FFH for double density, FEH for single density.
556B
LD (37ECH),A 32 EC 37
Store Register A (FEH or FFH) to 37ECH, the controller's command register: the doubler sets the density.
556E
LD A,D0H 3E D0
Load Register A with D0H, the command Force Interrupt.
1771 FDC Command: D0H (11010000)Function Description
Bit 7Bit 6Bit 5Bit 4Bit 3Bit 2Bit 1Bit 0Summary of Bits
11010000Command=Force Interrupt (bits 7-4 = 1101)
I3-I0 = 0000: end the command, no interrupt
5570
LD (37ECH),A 32 EC 37
Store Register A (D0H) to 37ECH: the controller ends whatever the byte above started.
5573
RET C9
RETurn to the caller. At 5567H after the copy, the last byte of the Percom module.

5574H - The Patch FDUBL1

Loaded by the patch's records after the type 07H record FDUBL1, with CALL 5574H over 5265H. Called once in the PERCOM build: the header's JR gets the displacement 2CH, which reaches 544FH from 5421H (41H would reach 5464H), and Register Pair HL = 5414H as the instruction it replaced gave.

5574
LD A,2CH 3E 2C
Load Register A with 2CH, the displacement of a JR from 5421H to 544FH.
5576
LD (540DH),A 32 0D 54
Store Register A (2CH) at 540DH, the displacement of the header's JR, before the header moves to 5421H.
5579
LD HL,5414H 21 14 54
Load Register Pair HL with 5414H, the last byte of the header: the LD HL,5414H that 5265H held before the patch.
557C
RET C9
RETurn to 5268H with Register Pair HL = 5414H.