TRS-80 DOS - TRSDOS v1.3 - SYS07/SYS Disassembled

General:

Program Overview

SYS7 is the TRSDOS v1.3 overlay that runs the FORMAT and BACKUP commands on the TRS-80 Model III (the source's TITLE: SYSTEM 7 - FORMAT & BACKUP). The file loads 4E00H–5D71H (3944 bytes, transfer address 57A1H). Above it SYS7 uses 5E00H–61FFH for its buffers and the main buffer from 6200H up to the end of memory; none of these is in the file. SYS7 is assembled as the customer version of the source (CUST true), so the factory serial number code of the source is not in it.

SYS1 reaches SYS7 through two DOS vectors: FORMAT through 429FH (LD A,A7H / RST 28H, entry 2) and BACKUP through 42A2H (LD A,97H / RST 28H, entry 1). SYSLD loads the overlay and jumps to BEGIN (57A1H) with the request code in Register A and HL at the command line after the command name. BEGIN marks SYS6 as no longer resident (bit 4 of OVLFLG, 442BH), sets CFLAG (42B4H) to 55H so SYS1 clears the user memory at the next TRSDOS Ready, lowers the read and write retry counts of SYS0 (TRY1 467DH, TRY2 460AH) from 9 to 2, and goes to FRMAT (5762H) or BACKP (5739H). Both end through EXIT (4E50H), which returns to TRSDOS Ready through 402DH; a disk error goes to FATAL (4E00H), which shows the error through SYS4 (4409H).

FORMAT (FORMAT :d): FRMAT clears the screen and shows the title, takes the date from the ROM, the drive from the command line (:d) or a prompt, the diskette name and the master password (as its trap door code, TRAP at 57C3H), and looks at the diskette with CHKFOR (a diskette with files asks 'Diskette contains DATA. Use Disk or not?'; N returns to TRSDOS Ready). It puts the name, the date and the password code into the new GAT at 6100H and calls FOMAT (5803H). FOMAT restores the head to track 0 and calls FORM (5CBDH), which formats the 40 tracks one by one: TRKIMG (5C1FH) builds the 7010 byte image of the track at 6200H from the track building table (5BB5H–5C1EH: 18 sectors of 256 bytes in the order 1, 4, 7, ... 18, each filled with 240 E5H bytes and the text '(c) 1980 Tandy '), TRKWRT (5AB0H) writes it with the FDC's Write Track command, and VERFIT (5AEEH) reads the 18 sectors back. A track that fails 4 tries is marked FFH in the flaw table of the new GAT (offset 60H). From track 22 on, the drive select byte has the write precompensation bit set. Then BOTWRI (5A53H) writes the boot sector (5853H–5952H) to track 0, sector 1, the 'Not a SYSTEM Disk' load module (5953H–5A52H) to sector 2, the GAT to track 17, sector 1, and an empty HIT and empty directory sectors to sectors 2–18.

BACKUP (BACKUP :s :d): BACKP shows the title, takes the date, the source and destination drives (the command line or prompts) and the master password of the source, and calls BPREP (5560H). BPREP reads the HIT of the source (a source without SYS0 involving drive 0 makes SYS7 ask for a system diskette at the end), reads the GAT of the source and compares its master password code (offset CEH) with the code typed. DOLLAR (5518H) then looks at the destination with CHKFOR (it is formatted with FOMAT when it cannot be read, or when the operator answers Y to 'Do you wish to RE-FORMAT the diskette?'), reads both GATs with DGAT (54B9H, which aborts when a track holding data on the source is flawed on the destination), and copies the grans in use: MREAD (5438H) fills the main buffer with gran records (2 bytes sector and track, then the 768 bytes of the gran) as long as they fit below MEMTOP, MWRIT (53D3H) writes and verifies them, and this goes on until the source has no gran left. Last, the directory track of the source is read into the buffer (RDIR, 52B4H), given the flaw table of the destination, the allocation bytes and today's date, and written to the destination (WDIR, 52F2H). With the source and destination on one drive, the operator is asked to change the diskettes (CKSRC 5492H, CKDES 54A5H).

The backup counter. Byte 22H of every boot sector SYS7 writes (CNT1, 5875H) is a backup counter, FFH for no limit. When BACKUP reads the boot sector of the source (RBOOT, 5257H) with a counter of 1–FEH, it lowers the counter on the source; the copy gets 00H. When the counter is 00H, CXFLAG (4E85H) is set and RDIR takes every file whose attribute byte has bit 5 set out of the copy (EXMGRN 5312H, DEALOC 5351H, RELEAS 537CH): its grans are released in the GAT, its directory record and its HIT byte are cleared, and EXIT shows the two messages coded at 50DFH ('Maximum Backup Count Exceeded', 'Protected Files NOT Backed Up').

Release file and source. The bytes on this page are those of the release SYS7 in S:\1, with one exception: the release file carries a zap (on the zaps page, part of the upgrade to the Wed. July 1, 1981 version) at 5135H–5140H and 579CH–579DH. It shortens the text REFORM to 'Do you wish to RE-FORMAT? ' and puts LD A,(4E7DH) / CP 81H / JP Z,550DH / RET at 5138H, and FRMAT calls 5138H instead of CKSYS (579BH), so that formatting drive 0 asks for a system diskette. This page shows the source code there, as the source has it; the rows name the release bytes. The shipped code also has 7 instructions at 5814H–5823H (a wait for the index pulse after the Restore) that the source text in S:\2 does not have; they are documented from the bytes.

Code assembled for other addresses. The boot sector at 5853H–5952H is assembled to run at 4300H (SETLOC BUFF1), where the ROM loads it, and the NOSYS load module at 5957H–5975H to run at 4D00H (SETLOC BUFF2). The absolute addresses in their instructions (CALL 433EH, LD (43EAH),HL and so on) are run addresses; the rows show the addresses in this file, the links of their CALLs and JPs go to the rows in this file, and each comment gives both addresses. Their relative jumps are shown with the address in this file.

Memory Map

RangeLabelContents
4E00H–4E7BHFATAL, N12, RESTRY, ABRT, EXIT, CLRBUFThe error exit, the exits and their helpers.
4E7CH–4EAAHSDFLAG ... NAMBUFVariables (NAMBUF, 4EA1H–4EAAH, is not in the file).
4EABH–516DHREADM ... FDDScreen messages, the two coded GEORGE messages (50DFH) and the source and destination drive message (5145H).
516EH–5257HSPRINT, RNEXT, RGRAN, WGRAN, VGRAN, FUNCTA–FUNCTC, GREAD, OUTHEX, BUMP, GBUMPDecoding of the coded messages, gran and sector I/O with the 'Reading / Writing / Verifying Track nn, Sector nn' line.
5257H–53B9HRBOOT, RDIR, WDIR, EXMGRN, DEALOC, RELEAS, CLRBITThe boot sector and the backup counter, the directory track, taking protected files out of a copy.
53BAH–5464HMEMCHK, MWRIT, FALOC, MREADThe main buffer of BACKUP: finding the grans in use, reading and writing them.
5465H–5517HFWAIT, LINOFF, CKSRC, CKDES, DGAT, CKSYSThe flashing prompts, the diskette changes, the two GATs.
5518H–5713HDOLLAR, BPREP, GETSRC, GETDES, GETFOR, INPUT, GETPSF, GETPSB, GETNAM, GETDAT, CLRGAT, SETDAT, CHKFORThe backup loop, the questions to the operator and the look at the destination diskette.
5714H–57C2HDOTITL, COMON, BACKP, FRMAT, BEGINThe two commands and the entry point.
57C3H–5802HTRAPThe trap door code of a password.
5803H–5852HFOMATThe formatter's entry.
5853H–5952HBOOT / ENTThe boot sector written to track 0, sector 1 (runs at 4300H–43FFH).
5953H–5A52HSYST / NOSYSThe sector written to track 0, sector 2: the 'Not a SYSTEM Disk' load module (runs at 4D00H).
5A53H–5B6CHBOTWRI, TRKWRT, VERFIT, STEPR, ASCII, PDATAWriting the system sectors, writing and verifying a track, stepping the head.
5B6DH–5BB4HWRTDIR, VERMSG, FORMSGThe messages of the formatter.
5BB5H–5C1EHTRKNN, DDST, DDTAB ... DDTRL, SECTAB, CSECTBThe track building table and the sector order.
5C1FH–5D71HTRKIMG, TBLBMP, EXPAND, FORM, FLAWXBuilding the track image and formatting the diskette.
5E00H–5EFFHSPAR_Copy of the boot sector of the source (RBOOT). Not in the file.
5F00H–5FFFHDUM1The empty HIT and directory sector FORM builds for BOTWRI. Not in the file.
6000H–60FFHSGATCopy of the allocation bytes of the source GAT that FALOC clears gran by gran. Not in the file.
6100H–61FFHFGAT, FLAWDThe GAT being built: the new GAT of FORMAT, or the source GAT with the destination's flaw table for BACKUP (FLAWD = 6160H, offset 60H). Not in the file.
6200H upBUFFThe main buffer: the track image of FORM (6200H–7D61H), the gran records of BACKUP (770 bytes each, up to MEMTOP), the directory track (6 gran records, 6200H–7413H). Not in the file.

Variables and Self Modified Operands

AddressLabelWhat it holds
4E7CH
1 byte
SDFLAGWhich diskette is in for a backup on one drive: 00H the source, FFH the destination.
4E7DH
1 byte
FDRIVEDrive select byte for the formatter: the drive's bit, 80H (double density), and bit 5 (precompensation) while FORM is on tracks 22 and up.
4E7EH
1 byte
FDRIVSSource drive number of BACKUP.
4E7FH
1 byte
FDRIVDDestination drive number of BACKUP, and the drive FORMAT formats (01H in the file).
4E80H
1 byte
FLAWCNumber of flawed tracks FORM found.
4E81H
1 byte
BSIDESSide of the source (00H; not changed by SYS7).
4E82H
1 byte
BSIDEDSide of the destination (00H; not changed by SYS7).
4E83H
1 byte
FLAGState of the flashing prompt (bit 0).
4E84H
1 byte
CLFNNumber of the directory record EXMGRN is looking at (0-79).
4E85H
1 byte
CXFLAGFFH when the backup counter of the source was at 0.
4E86H
1 byte
CCFLAGNot zero when a protected file was taken out of the copy.
4E87H
1 byte
SINGLEDestination drive minus source drive: 00H = backup on one drive.
4E88H
2 bytes
PTRAPTrap door code of the master password typed (8FD3H in the file).
4E8AH
2 bytes
CSAVECommand line pointer.
4E8CH
2 bytes
BUFPNTAddress of the gran record MREAD or MWRIT is on (6200H in the file).
4E8EH
2 bytes
MEMTOPMEMEND minus 768: the highest address a gran record may start at.
4E90H
8 bytes
DATBUFToday's date, MM/DD/YY.
4E98H
9 bytes
NAMEBFDiskette name ('TRSDOS' and spaces in the file); 8 bytes are used.
4EA1H
10 bytes
NAMBUFInput buffer of INPUT (not in the file).
4ED3H
2 bytes
FTRACKTrack digits of the 'Track nn, Sector nn' line.
4EDEH
2 bytes
SECSector digits of the same line.
5152H
1 byte
FDSSource drive digit of FDSMSG.
516BH
1 byte
FDDDestination drive digit of FDSMSG.
51C5H
2 bytes
VEROperand of LD DE at 51C4H: the track and first sector of the gran WGRAN wrote, for VGRAN.
53B8H
1 byte
CLRBT2Second byte of the RES n,B at 53B7H, built by CLRBIT.
550AH
1 byte
DATDSKOperand of LD A at 5509H: FFH = ask for a system diskette at the end (SETDAT).
5836H
1 byte
BCKFLGOperand of LD A at 5835H: 0FH when BACKUP formats the destination (DOLLAR), 00H for FORMAT.
5875H
1 byte
CNT1Backup counter of the boot sector written (FFH, no limit; 4322H when it runs).
593DH
2 bytes
TRKSAVBoot sector: the track and sector it reads next (43EAH when it runs).
593FH
1 byte
EOFBYTBoot sector: the offset of the next byte in the sector buffer 4D00H (43ECH when it runs).
5B1BH
1 byte
FSVSECOperand of LD E at 5B1AH: the sector VERFIT reads.
5B9AH
2 bytes
VERASCSector digits of 'Verifying sector nn'.
5BAFH
2 bytes
FORASCTrack digits of 'Formatting track nn'.
5BD3H
1 byte
DDTRKTrack number of the ID fields of the track image.
5BD6H
1 byte
DDSIDSide number of the ID fields (00H; not changed by SYS7).
5BD9H
1 byte
DDSECSector number of the ID field being built.
5C1DH
2 bytes
CSECTBPointer to the next entry of SECTAB.
5C4DH
1 byte
SAVEAOperand of LD A at 5C4CH: the track number TRKIMG is building.
5CBCH
1 byte
WORKRegister A saved by EXPAND.
5D61H
2 bytes
FLAWXDigits of 'nn Flawed Tracks'.

Major Routine List

AddressLabelDescription / Purpose
4E00HFATALError exit, A = the error code: when CXFLAG is set, write 4100H-41FFH to the boot sector of the source (see the note on that row); clear SPAR_, reset the retry counts, then JP 4409H (ERROR) with bit 6 of the code set.
4E35HN12'Cannot Backup Version 1.1. Diskette', then ABORT (4030H).
4E41HRESTRYTRY1 and TRY2 back to 9.
4E4AHABRT'Operation ABORTED due to flaws on diskette', then EXIT.
4E50HEXITThe GEORGE messages when protected files were taken out, then CLRBUF and JP 402DH.
4E6EHCLRBUFClear 5E00H-5EFFH.
516EHSPRINTShow a message coded with XOR 55H (count byte first).
517AH / 517DHRNEXT / RGRANRead a gran of the source into a gran record (D = track, E = sector; HL = the record, or BUFPNT for RNEXT).
519AHWGRANWrite the gran record at HL to the destination.
51BBHVGRANRead back the gran WGRAN wrote.
51D8H / 51E2H / 51ECHFUNCTA / FUNCTB / FUNCTCXREAD, XWRITE or XREAD with the Reading, Writing or Verifying line, through GREAD (51F4H).
522CHOUTHEXA (0-99) as two decimal digits at HL.
5238H / 5240HBUMP / GBUMPNext sector (E+1, HL+256) / next gran (E+3, next record).
5257HRBOOTRead the boot gran of the source and handle the backup counter.
52B4H / 52F2HRDIR / WDIRRead the directory track of the source / write it to the destination.
5312H / 5351H / 537CH / 53ADHEXMGRN / DEALOC / RELEAS / CLRBITTake the files with bit 5 of the attribute byte set out of the copy.
53BAHMEMCHKNext gran record; CARRY when the buffer is full.
53D3H / 5438HMWRIT / MREADWrite the buffer / fill the buffer.
53FAHFALOCNext gran in use on the source (D = track, E = sector), CARRY at the end.
5465H / 5488HFWAIT / LINOFFFlash a prompt until ENTER / erase the line.
5492H / 54A5H / 5509HCKSRC / CKDES / CKSYSAsk for the source, destination or system diskette when needed.
54B9HDGATRead and check both GATs.
5518HDOLLARThe backup itself.
5560HBPREPCheck the source and its master password, then DOLLAR.
55CCH / 55F4H / 5626HGETSRC / GETDES / GETFORThe drives.
5645HINPUTShow a prompt and read an answer into NAMBUF.
5652H / 5657HGETPSF / GETPSBThe master password (FORMAT / BACKUP).
5666H / 568CHGETNAM / GETDATThe diskette name / the date.
5693H / 56ABHCLRGAT / SETDATClear the GAT copies / ask for a system diskette at the end.
56B1HCHKFORLook at the destination: NZ = format it.
5714H / 5728HDOTITL / COMONThe title / the common start of both commands.
5739H / 5762HBACKP / FRMATBACKUP / FORMAT.
57A1HBEGINEntry point: A7H FORMAT, 97H BACKUP.
57C3HTRAPTrap door code of a password (HL, B characters) into HL.
5803HFOMATRestore, FORM, Restore, BOTWRI.
5853HBOOT / ENTThe boot sector (runs at 4300H).
5957HNOSYS'Not a SYSTEM Disk' (runs at 4D00H).
5A53HBOTWRIWrite the system sectors of a new diskette.
5AB0H / 5AEEHTRKWRT / VERFITWrite the track image / read back its 18 sectors.
5B35HSTEPRStep in one track and update SEKTRK.
5B55H / 5B67HASCII / PDATAA as two decimal digits at HL / show text, keeping DE (not called).
5C1FH / 5C7BH / 5C8CHTRKIMG / TBLBMP / EXPANDBuild the track image from the track building table.
5CBDHFORMFormat and verify the 40 tracks.

Notes

  • FATAL and 4100H. When an error ends a backup whose source counter was at 0, FATAL asks for the source diskette and writes the 256 bytes at 4100H-41FFH to its boot sector (the source comment: write out old counter). RBOOT keeps its copy of the source boot sector at 5E00H, and no code in SYS7 writes to 4100H-41FFH.
  • The formatter's step. FORM tests the NZ FLAG after CALL NZ,STEPR (5CE8H, JP NZ,ABRT); STEPR always returns with the Z FLAG set, so that jump is never taken.
  • Tracks 40 and above. GREAD (5202H) and TRKIMG (5C4EH) add 80H to the sector number on tracks 40 and above (the source calls such a track the secret track); a diskette formatted by SYS7 has tracks 0-39 only.

Disassembly

4E00H - FATAL - Error exit (A = the error code): when the backup counter of the source was at 0, write 4100H-41FFH to the boot sector of the source; clear the saved boot sector, reset the retry counts and show the error through SYS4. The entry point of SYS7 is BEGIN at 57A1H.

 
ORG 4E00H
4E00FATAL
PUSH AF F5
FATAL: Save Register Pair AF on the STACK. Register A holds the error code of the failed disk operation (FATAL is reached by JP NZ,4E00H right after a SYS0 disk routine returned NZ with the error code in A).
Original Source Code Comment: SAVE THE ERROR CODE
4E01
XOR A AF
Set Register A to 00H and clear all Flags, ready to select side 0.
Original Source Code Comment: RESET FOR SIDE 0
4E02
LD (4463H),ALD (CSIDE),A 32 63 44
Store 00H (Register A) into 4463H (CSIDE, the current side number SYS0 uses for disk I/O), so the I/O that follows uses side 0.
4E05
LD A,(4E85H)LD A,(CXFLAG) 3A 85 4E
Fetch the byte at 4E85H (CXFLAG) into Register A. CXFLAG is FFH when RBOOT found the backup counter of the source boot sector at 0 (52A9H) and 00H otherwise.
Original Source Code Comment: GET THE 'COUNT' FLAG
4E08
OR A B7
OR Register A with itself to set the flags from CXFLAG (a LD does not set the flags).
Original Source Code Comment: COUNTER SET?
4E09
If the Z FLAG is set (CXFLAG is 00H, no counter was found at 0), JUMP to 4E1DH (FATAL1) and skip the rewrite of the source boot sector.
Original Source Code Comment: NO, CONTINUE
4E0B
GOSUB to 5492H (CKSRC). For a backup on one drive (SINGLE at 4E87H is 00H) it asks for the SOURCE diskette if the destination is in the drive; with two drives it does nothing.
Original Source Code Comment: INSERT SOURCE DISK
4E0E
LD A,(4E7EH)LD A,(FDRIVS) 3A 7E 4E
Fetch the source drive number from 4E7EH (FDRIVS) into Register A.
Original Source Code Comment: GET THE SOURCE DRIVE
4E11
AND 0FHAND 0FH E6 0F
MASK Register A with 0FH (0000 1111) to keep the drive number in bits 3-0.
4E13
LD C,A 4F
LET Register C = Register A, the source drive number, for XWRITE.
Original Source Code Comment: INTO C
4E14
LD DE,0001HLD DE,1 11 01 00
LET Register Pair DE = 0001H: Register D = track 00H and Register E = sector 01H, the boot sector.
Original Source Code Comment: SET FOR BOOT TRACK/SECTOR
4E17
LD HL,4100H 21 00 41
LET Register Pair HL = 4100H, the buffer XWRITE writes from. The source comment calls it the saved boot with the counter; RBOOT keeps its copy of the source boot sector at 5E00H (SPAR_), and no code in SYS7 writes to 4100H-41FFH.
Original Source Code Comment: SAVED BOOT WITH COUNTER
4E1A
GOSUB to 45F7H (XWRITE in SYS0) to write the 256 bytes at HL (4100H) to drive C, track D (00H), sector E (01H) on the side in CSIDE. XWRITE returns Z when the write worked or NZ with the error code in A; the result is not tested here.
Original Source Code Comment: WRITE OUT OLD COUNTER
4E1DFATAL1
FATAL1: GOSUB to 4E6EH (CLRBUF) to clear the copy of the boot sector at 5E00H-5EFFH (SPAR_).
Original Source Code Comment: CLEAR OUT THE BOOT FROM RAM
4E20
GOSUB to 4E41H (RESTRY) to put the read and write retry counts of SYS0 (467DH TRY1 and 460AH TRY2) back to 9.
Original Source Code Comment: RESET THE RETRY COUNTER
4E23
XOR A AF
Set Register A to 00H and clear all Flags.
4E24
LD (4E85H),ALD (CXFLAG),A 32 85 4E
Store 00H (Register A) into 4E85H (CXFLAG), the flag that the backup counter was found at 0.
4E27
LD (4E86H),ALD (CCFLAG),A 32 86 4E
Store 00H (Register A) into 4E86H (CCFLAG), the flag that a protected file was taken out of the backup.
4E2A
LD A,0DHLD A,0DH 3E 0D
LET Register A = 0DH (carriage return).
Original Source Code Comment: NEW LINE
4E2C
GOSUB to 0033H (the ROM's display routine) to show the character in Register A (0DH): the cursor moves to the start of the next line.
4E2F
POP AF F1
Restore Register Pair AF from the STACK: Register A again holds the error code pushed at 4E00H.
Original Source Code Comment: GET THE ERROR CODE BACK
4E30
OR 40H F6 40
OR Register A with 40H (0100 0000) to set bit 6 of the error code, which makes SYS4 show the full text of the error. Bit 7 stays clear, so SYS4 ends with Operation Aborted and TRSDOS Ready.
Original Source Code Comment: ADD IN THE DETAIL BITS
4E32
JUMP to 4409H (ERROR in SYS0), which pushes AF and loads SYS4 (request 84H) to show error code A.
Original Source Code Comment: CALL THE ERROR HANDLER

4E35H - N12 - Show 'Cannot Backup Version 1.1. Diskette' and 'Use "XFERSYS" First', then abort to TRSDOS Ready

4E35N12
LD HL,507AHLD HL,N12M 21 7A 50
N12: LET Register Pair HL = 507AH (N12M), the text 'Cannot Backup Version 1.1. Diskette' / 'Use "XFERSYS" First'. RBOOT jumps here when the source boot sector carries a version byte below 12H.
Original Source Code Comment: HL => 'NOT VERS 1.3' MSG
4E38
GOSUB to 021BH (the ROM's PRINT routine) to show the text at HL up to and including the 0DH that ends it.
4E3B
GOSUB to 4E41H (RESTRY) to put the read and write retry counts of SYS0 back to 9.
Original Source Code Comment: RESET THE RETRY COUNTER
4E3E
JUMP to 4030H (ABORT, LD A,A1H / RST 28H): SYS1 shows Operation Aborted and returns to TRSDOS Ready.

4E41H - RESTRY - Put the read and write retry counts of SYS0 (TRY1 467DH, TRY2 460AH) back to 9

4E41RESTRY
LD A,09HLD A,RETRY 3E 09
RESTRY: LET Register A = 09H, the normal retry count of SYS0 (the source's RETRY). BEGIN lowered it to 2 (57AEH).
Original Source Code Comment: RESET THE RETRY COUNTER IN DOS
4E43
LD (467DH),ALD (TRY1),A 32 7D 46
Store 09H (Register A) into 467DH (TRY1), the operand of the LD B that sets the read retry count in SYS0's XREAD.
4E46
LD (460AH),ALD (TRY2),A 32 0A 46
Store 09H (Register A) into 460AH (TRY2), the operand of the LD B that sets the write retry count in SYS0's XWRITE.
4E49
RET C9
RETurn to the caller.

4E4AH - ABRT - Show 'Operation ABORTED due to flaws on diskette', then EXIT: show the GEORGE messages when protected files were taken out of a backup, clear the saved boot sector and return to TRSDOS Ready

4E4AABRT
LD HL,50B3HLD HL,ABMSG 21 B3 50
ABRT: LET Register Pair HL = 50B3H (ABMSG), the text 0AH 'Operation ABORTED due to flaws on diskette' 0DH. DGAT jumps here when a track that holds data on the source is flawed on the destination.
Original Source Code Comment: HL => 'ABORT' MSG
4E4D
GOSUB to 021BH (the ROM's PRINT routine) to show the text at HL; then fall into EXIT.
Original Source Code Comment: DISPLAY IT
4E50
LD A,(4E85H)LD A,(CXFLAG) 3A 85 4E
EXIT: Fetch 4E85H (CXFLAG) into Register A: FFH when RBOOT found the backup counter of the source at 0, else 00H.
Original Source Code Comment: GET THE 'COUNT' FLAG
4E53
OR A B7
OR Register A with itself to set the flags from CXFLAG.
Original Source Code Comment: WAS IT SET?
4E54
If the Z FLAG is set (CXFLAG is 00H), JUMP to 4E68H (EXIT1). The jump skips RESTRY at 4E65H.
Original Source Code Comment: NO, CONTINUE
4E56
LD A,(4E86H)LD A,(CCFLAG) 3A 86 4E
Fetch 4E86H (CCFLAG) into Register A: not zero when EXMGRN took at least one protected file out of the backup.
Original Source Code Comment: DID WE SKIP OVER ANYTHING?
4E59
OR A B7
OR Register A with itself to set the flags from CCFLAG.
4E5A
If the Z FLAG is set (no protected file was taken out), JUMP to 4E68H (EXIT1).
Original Source Code Comment: NO, CONTINUE
4E5C
LD HL,50DFHLD HL,GEORGE 21 DF 50
LET Register Pair HL = 50DFH (GEORGE), the first of the two coded messages for SPRINT.
Original Source Code Comment: HL => 'PROTECTED' MSG
4E5F
GOSUB to 516EH (SPRINT) to decode and show 'Maximum Backup Count Exceeded' and a new line. SPRINT returns with HL at the next coded message (50FEH).
4E62
GOSUB to 516EH (SPRINT) again with HL = 50FEH to decode and show 'Protected Files NOT Backed Up' and a new line.
Original Source Code Comment: PRINT 2ND PART OF MSG
4E65
GOSUB to 4E41H (RESTRY) to put the read and write retry counts of SYS0 back to 9.
Original Source Code Comment: RESET THE RETRY COUNTER
4E68EXIT1
EXIT1: GOSUB to 4E6EH (CLRBUF) to clear the copy of the source boot sector at 5E00H-5EFFH.
Original Source Code Comment: CLEAR OUT THE BOOT FROM RAM
4E6B
JUMP to 402DH (SYS1IN, JP 4296H): return to TRSDOS Ready through SYS1.

4E6EH - CLRBUF - Clear the copy of the source boot sector at 5E00H-5EFFH (SPAR_)

4E6ECLRBUF
LD HL,5E00HLD HL,SPAR_ 21 00 5E
CLRBUF: LET Register Pair HL = 5E00H (SPAR_), the 256 byte area where RBOOT keeps a copy of the source boot sector.
Original Source Code Comment: HL => WHERE BOOT WAS STORED
4E71
LD DE,5E01HLD DE,SPAR_+1 11 01 5E
LET Register Pair DE = 5E01H (SPAR_+1), one byte above HL, so the LDIR copies the cleared byte forward.
Original Source Code Comment: CLEAR IT OUT OF RAM
4E74
LD BC,00FFHLD BC,SECTOR-1 01 FF 00
LET Register Pair BC = 00FFH (255), the number of bytes the LDIR copies after the first one.
4E77
LD (HL),00HLD (HL),0 36 00
Store 00H into the memory location at HL (5E00H).
Original Source Code Comment: CLEAR BYTE
4E79
LDIR ED B0
Copy the byte at HL to DE, add 1 to HL and DE and subtract 1 from BC until BC is 0000H: 5E01H-5EFFH become 00H like 5E00H.
4E7B
RET C9
RETurn to the caller.

4E7CH - SDFLAG - The variables of FORMAT and BACKUP (the source's SAVES AND SCREEN MESSAGES)

4E7CSDFLAG
DEFB 00H 00
SDFLAG: which diskette the operator was last asked to put in for a backup on one drive: 00H = the source (also at load), FFH = the destination. CKSRC (5492H) and CKDES (54A5H) set it.
Original Source Code Comment: FLAG TO SHOW SOURCE OR DEST DISK
4E7DFDRIVE
DEFB 00H 00
FDRIVE: the drive select byte for the formatter: the drive's bit (from SITIT, 45E9H) with 80H (double density) added by GETDE3 (5617H); FORM sets bit 5 (write precompensation) from track 22 on and clears it at the end.
Original Source Code Comment: DESTINATION DRIVE FOR FORMAT
4E7EFDRIVS
DEFB 00H 00
FDRIVS: the source drive number of BACKUP (00H at load), set by GETSRC (55EEH).
Original Source Code Comment: SOURCE DRIVE FOR BACKUP
4E7FFDRIVD
DEFB 01H 01
FDRIVD: the destination drive number of BACKUP, and the drive FORMAT formats (01H at load), set by GETDE3 (560FH).
Original Source Code Comment: DESTINATION DRIVE FOR BACKUP
4E80FLAWC
DEFB 00H 00
FLAWC: the number of tracks FORM marked as flawed; FORM shows it as 'nn Flawed Tracks'.
Original Source Code Comment: FLAWED TRACK COUNT
4E81BSIDES
DEFB 00H 00
BSIDES: the side of the source diskette that BACKUP reads (00H; no code in SYS7 changes it). RBOOT, RDIR and MREAD copy it into CSIDE (4463H).
Original Source Code Comment: SOURCE SIDE NUMBER TO BACKUP
4E82BSIDED
DEFB 00H 00
BSIDED: the side of the destination diskette that BACKUP writes (00H; no code in SYS7 changes it). WDIR and MWRIT copy it into CSIDE (4463H).
Original Source Code Comment: DESTIN SIDE NUMBER TO BACKUP
4E83FLAG
DEFB 00H 00
FLAG: the state of the flashing prompt of FWAIT (5465H): bit 0 is flipped each time the timer runs out; 00H means the message is shown again.
Original Source Code Comment: FLAG FOR 'FLASH' ROUTINE
4E84CLFN
DEFB 00H 00
CLFN: the number (0-79) of the directory record EXMGRN is looking at; DEALOC uses it as the offset of the record's byte in the HIT.
Original Source Code Comment: LFN OF FILE UNDER EXAMINATION
4E85CXFLAG
DEFB 00H 00
CXFLAG: FFH when RBOOT (52A9H) found the backup counter of the source boot sector at 0, so RDIR takes the protected files out of the copy; 00H otherwise.
Original Source Code Comment: FLAG FOR 'COUNTER' ACTIVE
4E86CCFLAG
DEFB 00H 00
CCFLAG: not zero (the attribute byte of the file) when EXMGRN (5331H) took a protected file out of the backup; EXIT then shows the two GEORGE messages.
Original Source Code Comment: FLAG TO SHOW A PROTECTED FILE WAS SKIPPED
4E87SINGLE
DEFB 00H 00
SINGLE: the destination drive number minus the source drive number (5622H): 00H = BACKUP on one drive (CKSRC and CKDES ask for the diskettes), not zero = two drives.
Original Source Code Comment: 'NZ' IF IT'S A MULTI DRIVE BACKUP
4E88-4E89PTRAP
DEFW 8FD3H D3 8F
PTRAP: the trap door code of the master password typed (GETPAS, 5662H). D3H 8FH (8FD3H) in the file. FRMAT puts it into the new GAT at offset CEH; BPREP compares it with the GAT of the source.
Original Source Code Comment: INPUT PASSWORD STORED HERE
4E8A-4E8BCSAVE
DEFW 0000H 00 00
CSAVE: the command line pointer (HL when BEGIN was entered), stored by COMON (5728H) and read by GETSRC and GETFOR.
Original Source Code Comment: COMMAND LINE POINTER HERE
4E8C-4E8DBUFPNT
DEFW 6200H 00 62
BUFPNT: the address in the main buffer of the gran record MREAD or MWRIT is working on (6200H, BUFF, in the file); each record is 770 bytes (2 bytes sector and track, then 768 bytes of data).
Original Source Code Comment: PRESENT BUFFER POINTER
4E8E-4E8FMEMTOP
DEFW 0000H 00 00
MEMTOP: the end of memory minus 768 (COMON, 5732H): MEMCHK reports the buffer full once the next gran record would start above it.
Original Source Code Comment: TOP OF MEMORY
4E90-4E97DATBUF
DEFM "00/00/00" 30 30 2F 30 30 2F 30 30
DATBUF: the date as MM/DD/YY, filled in by GETDAT (568CH) through the ROM's DATE routine (3033H). FRMAT copies it into the new GAT (offset D8H); DOLLAR into the GAT of the destination.
4E98-4EA0NAMEBF
DEFM "TRSDOS " 54 52 53 44 4F 53 20 20 20
NAMEBF: the diskette name, 9 bytes in the source ('TRSDOS' and three spaces), of which 8 are used: GETNAM (5683H) stores the name typed for FORMAT there, and FRMAT copies it into the new GAT at offset D0H.
Original Source Code Comment: WHERE DISK ID GOES
4EA1-4EAANAMBUF
DEFS 10
NAMBUF: 10 bytes where INPUT (5648H) has the ROM's KEYN (0040H) put the line typed (drive numbers, names, passwords, answers). Not in the file.

4EABH - READM - The screen messages. 03H ends a text for the ROM's PRINT routine without a new line, 0DH with one; 1DH moves the cursor to the start of the line, 1EH erases to the end of the line.

4EABREADM
DEFB 1DH 1D
READM: 1DH, which moves the cursor to the start of the line, first byte of the message GREAD shows before a read.
4EAC-4EB4
DEFM "Reading " 52 65 61 64 69 6E 67 20 20
'Reading ': the word GREAD shows before ' Track nn, Sector nn' (REST, 4ECCH).
4EB5
DEFB 03H 03
03H: ends the text for PRINT without a new line.
4EB6WRITM
DEFB 1DH 1D
WRITM: 1DH (cursor to the start of the line), first byte of the message GREAD shows before a write.
4EB7-4EBF
DEFM "Writing " 57 72 69 74 69 6E 67 20 20
'Writing ': the word GREAD shows before ' Track nn, Sector nn'.
4EC0
DEFB 03H 03
03H: ends the text for PRINT without a new line.
4EC1VERFM
DEFB 1DH 1D
VERFM: 1DH (cursor to the start of the line), first byte of the message GREAD shows before a verify.
4EC2-4ECA
DEFM "Verifying" 56 65 72 69 66 79 69 6E 67
'Verifying': the word GREAD shows before ' Track nn, Sector nn'.
4ECB
DEFB 03H 03
03H: ends the text for PRINT without a new line.
4ECC-4ED2REST
DEFM " Track " 20 54 72 61 63 6B 20
REST: ' Track ', the second part of the message GREAD shows (5222H).
4ED3-4EDDFTRACK
DEFM "00, Sector " 30 30 2C 20 53 65 63 74 6F 72 20
FTRACK: '00', the two digits of the track number, written by OUTHEX (from 520EH), then ', Sector '.
4EDE-4EDFSEC
DEFM "00" 30 30
SEC: '00', the two digits of the sector number, written by OUTHEX (from 5215H).
4EE0
DEFB 1EH 1E
1EH: erases from the cursor to the end of the line.
4EE1
DEFB 03H 03
03H: ends the text for PRINT without a new line.
4EE2ANALYZ
DEFB 1DH 1D
ANALYZ: 1DH (cursor to the start of the line), first byte of the message CHKFOR shows (56B1H).
4EE3-4EF4
DEFM "Analyzing Diskette" 41 6E 61 6C 79 7A 69 6E 67 20 44 69 73 6B 65 74 74 65
'Analyzing Diskette'.
4EF5
DEFB 1DH 1D
1DH: moves the cursor back to the start of the line, so the next text writes over this one.
4EF6
DEFB 03H 03
03H: ends the text for PRINT.
4EF7SRCMSG
DEFB 1DH 1D
SRCMSG: 1DH (cursor to the start of the line), first byte of the prompt INSRC flashes (54A0H).
4EF8-4F15
DEFM "Insert SOURCE Diskette <ENTER>" 49 6E 73 65 72 74 20 53 4F 55 52 43 45 20 44 69 73 6B 65 74 74 65 20 3C 45 4E 54 45 52 3E
'Insert SOURCE Diskette <ENTER>'.
4F16
DEFB 03H 03
03H: ends the text for PRINT without a new line.
4F17DESMSG
DEFB 1DH 1D
DESMSG: 1DH (cursor to the start of the line), first byte of the prompt INDES flashes (54B4H).
4F18-4F3A
DEFM "Insert DESTINATION Diskette &lt;ENTER&gt;" 49 6E 73 65 72 74 20 44 45 53 54 49 4E 41 54 49 4F 4E 20 44 69 73 6B 65 74 74 65 20 3C 45 4E 54 45 52 3E
'Insert DESTINATION Diskette <ENTER>'.
4F3B
DEFB 03H 03
03H: ends the text for PRINT without a new line.
4F3CSYSMSG
DEFB 1DH 1D
SYSMSG: 1DH (cursor to the start of the line), first byte of the prompt INSYS flashes (5512H).
4F3D-4F5A
DEFM "Insert SYSTEM Diskette &lt;ENTER&gt;" 49 6E 73 65 72 74 20 53 59 53 54 45 4D 20 44 69 73 6B 65 74 74 65 20 3C 45 4E 54 45 52 3E
'Insert SYSTEM Diskette <ENTER>'.
4F5B
DEFB 03H 03
03H: ends the text for PRINT without a new line.
4F5C-4F74BCOMP
DEFM " ** Backup Complete **" 20 20 20 20 2A 2A 20 42 61 63 6B 75 70 20 43 6F 6D 70 6C 65 74 65 20 2A 2A
BCOMP: ' ** Backup Complete **', shown by BACKP (5756H).
4F75
DEFB 0DH 0D
0DH: ends BCOMP with a new line (the source's ~).
4F76-4F86TITLE1
DEFM "TRSDOS Model III " 54 52 53 44 4F 53 20 4D 6F 64 65 6C 20 49 49 49 20
TITLE1: 'TRSDOS Model III ', the first part of the title DOTITL shows.
4F87
DEFB 03H 03
03H: ends the text for PRINT without a new line.
4F88-4F90TITLE2
DEFM " Ver 1.3" 20 20 56 65 72 20 31 2E 33
TITLE2: ' Ver 1.3', the last part of the title DOTITL shows.
4F91
DEFB 0AH 0A
0AH: line feed.
4F92
DEFB 0DH 0D
0DH: carriage return; ends TITLE2 for PRINT.
4F93-4FA0
DEFM "Backup Utility" 42 61 63 6B 75 70 20 55 74 69 6C 69 74 79
BMSG: 'Backup Utility', the middle part of the title for BACKUP (573CH).
4FA1
DEFB 03H 03
03H: ends the text for PRINT without a new line.
4FA2-4FAFFMSG
DEFM "Disk Formatter" 44 69 73 6B 20 46 6F 72 6D 61 74 74 65 72
FMSG: 'Disk Formatter', the middle part of the title for FORMAT (5765H).
4FB0
DEFB 03H 03
03H: ends the text for PRINT without a new line.
4FB1-4FC4FDRV
DEFM "Format Which Drive? " 46 6F 72 6D 61 74 20 57 68 69 63 68 20 44 72 69 76 65 3F 20
FDRV: 'Format Which Drive? ', the prompt of GETFOR (562FH).
4FC5
DEFB 03H 03
03H: ends the text for PRINT without a new line.
4FC6-4FEFDDATA
DEFM "Diskette contains DATA. Use Disk or not? " 44 69 73 6B 65 74 74 65 20 63 6F 6E 74 61 69 6E 73 20 44 41 54 41 2E 20 20 55 73 65 20 44 69 73 6B 20 6F 72 20 6E 6F 74 3F 20
DDATA: 'Diskette contains DATA. Use Disk or not? ', the prompt of CHKFO2 (56E9H).
4FF0
DEFB 03H 03
03H: ends the text for PRINT without a new line.
4FF1-4FFFNAMMES
DEFM "Diskette Name? " 44 69 73 6B 65 74 74 65 20 4E 61 6D 65 3F 20
NAMMES: 'Diskette Name? ', the prompt of GETNAM (5666H).
5000
DEFB 03H 03
03H: ends the text for PRINT without a new line.
5001-5011PASMES
DEFM "Master Password? " 4D 61 73 74 65 72 20 50 61 73 73 77 6F 72 64 3F 20
PASMES: 'Master Password? ', the prompt of GETPSF (5652H) for FORMAT.
5012
DEFB 03H 03
03H: ends the text for PRINT without a new line.
5013-502FSPASS
DEFM "SOURCE Disk Master Password? " 53 4F 55 52 43 45 20 44 69 73 6B 20 4D 61 73 74 65 72 20 50 61 73 73 77 6F 72 64 3F 20
SPASS: 'SOURCE Disk Master Password? ', the prompt of GETPSB (5657H) for BACKUP.
5030
DEFB 03H 03
03H: ends the text for PRINT without a new line.
5031-5047INVPAS
DEFM "Invalid Master Password" 49 6E 76 61 6C 69 64 20 4D 61 73 74 65 72 20 50 61 73 73 77 6F 72 64
INVPAS: 'Invalid Master Password', shown by BPREP (55AAH) when the code of the password typed is not the one in the GAT of the source.
5048
DEFB 0DH 0D
0DH: ends INVPAS with a new line (the source's ~).
5049-505DSDRV
DEFM "SOURCE Drive Number? " 53 4F 55 52 43 45 20 44 72 69 76 65 20 4E 75 6D 62 65 72 3F 20
SDRV: 'SOURCE Drive Number? ', the prompt of GETSRC (55D8H).
505E
DEFB 03H 03
03H: ends the text for PRINT without a new line.
505F-5078DDRV
DEFM "DESTINATION Drive Number? " 44 45 53 54 49 4E 41 54 49 4F 4E 20 44 72 69 76 65 20 4E 75 6D 62 65 72 3F 20
DDRV: 'DESTINATION Drive Number? ', the prompt of GETDES (55FAH).
5079
DEFB 03H 03
03H: ends the text for PRINT without a new line.
507AN12M
DEFB 0AH 0A
N12M: 0AH (line feed), first byte of the message N12 (4E35H) shows.
507B-509D
DEFM "Cannot Backup Version 1.1. Diskette" 43 61 6E 6E 6F 74 20 42 61 63 6B 75 70 20 56 65 72 73 69 6F 6E 20 31 2E 31 2E 20 44 69 73 6B 65 74 74 65
'Cannot Backup Version 1.1. Diskette'.
509E
DEFB 0AH 0A
0AH: line feed.
509F-50B1
DEFM 'Use "XFERSYS" First' 55 73 65 20 22 58 46 45 52 53 59 53 22 20 46 69 72 73 74
'Use "XFERSYS" First'.
50B2
DEFB 0DH 0D
0DH: ends N12M with a new line (the source's ~).
50B3ABMSG
DEFB 0AH 0A
ABMSG: 0AH (line feed), first byte of the message ABRT (4E4AH) shows.
50B4-50DD
DEFM "Operation ABORTED due to flaws on diskette" 4F 70 65 72 61 74 69 6F 6E 20 41 42 4F 52 54 45 44 20 64 75 65 20 74 6F 20 66 6C 61 77 73 20 6F 6E 20 64 69 73 6B 65 74 74 65
'Operation ABORTED due to flaws on diskette'.
50DE
DEFB 0DH 0D
0DH: ends ABMSG with a new line (the source's ~).

50DFH - GEORGE - The two messages EXIT shows when protected files were taken out of a backup, coded with XOR 55H (the source's DEFE) and shown by SPRINT

50DFGEORGE
DEFB 1EH 1E
GEORGE: 1EH (30), the number of coded characters SPRINT shows from the bytes that follow.
50E0-50FD
DEFB 18H,34H,2DH,3CH,38H,20H,38H,75H,17H,34H,36H,3EH,20H,25H,75H,16H,3AH,20H,3BH,21H,75H,10H,2DH,36H,30H,30H,31H,30H,31H,58H 18 34 2D 3C 38 20 38 75 17 34 36 3E 20 25 75 16 3A 20 3B 21 75 10 2D 36 30 30 31 30 31 58
The source's DEFE: 'Maximum Backup Count Exceeded' and 0DH, each byte XORed with 55H (the 0DH is 58H here). SPRINT XORs them back.
50FE
DEFB 1EH 1E
1EH (30), the number of coded characters of the second message.
50FF-511C
DEFB 05H,27H,3AH,21H,30H,36H,21H,30H,31H,75H,13H,3CH,39H,30H,26H,75H,1BH,1AH,01H,75H,17H,34H,36H,3EH,30H,31H,75H,00H,25H,58H 05 27 3A 21 30 36 21 30 31 75 13 3C 39 30 26 75 1B 1A 01 75 17 34 36 3E 30 31 75 00 25 58
The source's DEFE: 'Protected Files NOT Backed Up' and 0DH, each byte XORed with 55H.

511DH - REFORM - The prompt of BACKUP for a formatted destination (the release file's zap at 5135H-5140H is described on the row)

511D-5143REFORM
DEFM "Do you wish to RE-FORMAT the diskette? " 44 6F 20 79 6F 75 20 77 69 73 68 20 74 6F 20 52 45 2D 46 4F 52 4D 41 54 20 74 68 65 20 64 69 73 6B 65 74 74 65 3F 20
REFORM: 'Do you wish to RE-FORMAT the diskette? ', the prompt of CHKFO3 (5704H) when BACKUP finds a formatted destination. The release file has the zap of the zaps page here: from 5135H it holds '? ', 03H and the code LD A,(4E7DH) / CP 81H / JP Z,550DH / RET at 5138H-5140H (FRMAT then calls 5138H instead of CKSYS, 579BH); the text left at 5141H-5143H is 'e? '. The page shows the source.
5144
DEFB 03H 03
03H: ends the text for PRINT without a new line.

5145H - FDSMSG - The source and destination drive message of BACKUP

5145-5151FDSMSG
DEFM "Source Drive " 53 6F 75 72 63 65 20 44 72 69 76 65 20
FDSMSG: 'Source Drive ', shown by BPREP1 (55C3H).
5152-516AFDS
DEFM "0 Destination Drive " 30 20 20 20 20 20 20 44 65 73 74 69 6E 61 74 69 6F 6E 20 44 72 69 76 65 20
FDS: '0', the source drive digit (BPREP1 stores FDRIVS plus 30H here at 55B8H), then ' Destination Drive '.
516BFDD
DEFB 30H 30
FDD: '0', the destination drive digit (BPREP1 stores FDRIVD plus 30H here at 55C0H).
516C
DEFB 0AH 0A
0AH: line feed.
516D
DEFB 0DH 0D
0DH: carriage return; ends FDSMSG for PRINT.

516EH - SPRINT - Decode and show a message coded with XOR 55H. On entry HL points at the count byte; on exit HL points at the byte after the message.

516ESPRINT
LD B,(HL) 46
SPRINT: Fetch the byte at HL into Register B: the count of coded characters that follow (1EH for both GEORGE messages).
Original Source Code Comment: GET THE CHAR COUNT
516F
INC HL 23
INCrement Register Pair HL by 1 to point at the first coded character.
Original Source Code Comment: BUMP TO NEXT
5170SPRIN1
LD A,(HL) 7E
SPRIN1: Fetch the coded character at HL into Register A.
Original Source Code Comment: GET A CHARACTER
5171
XOR 55H EE 55
XOR Register A with 55H (0101 0101) to undo the coding of the source's DEFE and get the real character.
Original Source Code Comment: UNSCRAMBLE IT
5173
GOSUB to 0033H (the ROM's display routine) to show the character in Register A; the last one, 0DH, gives a new line.
Original Source Code Comment: DISPLAY IT
5176
INC HL 23
INCrement Register Pair HL by 1 to point at the next coded character.
Original Source Code Comment: BUMP TO NEXT CHAR
5177
DECrement Register B (the characters left) and, if it is not 0, LOOP BACK to 5170H (SPRIN1) for the next one.
Original Source Code Comment: LOOP FOR COUNT
5179
RET C9
RETurn to the caller with Register Pair HL pointing at the byte after the message (the count byte of the next message).

517AH - RNEXT / RGRAN - Read a gran (3 sectors) of the source into a gran record. D = track, E = first sector; RNEXT takes the record address from BUFPNT (4E8CH), RGRAN in HL. The record gets the sector and the track in its first two bytes and the 768 bytes of data after them. Exit: Z, or NZ with the error code in A.

517ARNEXT
LD HL,(4E8CH)LD HL,(BUFPNT) 2A 8C 4E
RNEXT: Fetch the address of the next gran record of the main buffer from 4E8CH-4E8DH (BUFPNT) into Register Pair HL, then fall into RGRAN. Register D holds the track and Register E the first sector of the gran (from FALOC).
Original Source Code Comment: PICK UP THE BUFFER POINTER
517DRGRAN
PUSH BCSAV3 C5
RGRAN: Save Register Pair BC on the STACK (Register B is the caller's loop count). RGRAN reads 3 sectors starting at track D, sector E, from the source drive into a gran record at HL.
517E
PUSH DE D5
Save Register Pair DE (the track in D, the first sector in E) on the STACK.
517F
PUSH HL E5
Save Register Pair HL (the address of the gran record) on the STACK.
5180
LD B,03HLD B,DGRAN 06 03
LET Register B = 03H, the number of sectors in a gran (the source's DGRAN), as the count for the DJNZ at 5192H.
Original Source Code Comment: NUMBER OF SECTORS IN A GRAN
5182
LD A,(4E7EH)LD A,(FDRIVS) 3A 7E 4E
Fetch the source drive number from 4E7EH (FDRIVS) into Register A.
Original Source Code Comment: GET THE SOURCE DRIVE NUMBER
5185
LD C,A 4F
LET Register C = Register A, the source drive number, for XREAD.
Original Source Code Comment: INTO C
5186
LD (HL),ELD (HL),DE 73
Store Register E (the sector number) into the first byte of the gran record at HL.
Original Source Code Comment: SAVE THE TRACK AND SECTOR IN RAM
5187
INC HL 23
INCrement Register Pair HL by 1.
5188
LD (HL),D 72
Store Register D (the track number) into the second byte of the gran record. MWRIT and WGRAN later take the track and sector from these two bytes.
5189
INC HL 23
INCrement Register Pair HL by 1 to point at the data part of the record, where the first sector goes.
518ARGRAN1
RGRAN1: GOSUB to 51D8H (FUNCTA) to read track D, sector E, of drive C into HL with the message 'Reading Track nn, Sector nn'. FUNCTA returns Z when the read worked or NZ with the error code in A.
Original Source Code Comment: DO THE READ
518D
If the NZ FLAG is set (the read failed, A = the error code), JUMP to 5195H (RGRAN2).
Original Source Code Comment: EXIT IF ERROR
518F
GOSUB to 5238H (BUMP): Register E becomes the next sector and Register Pair HL moves 256 bytes on to the next sector's place in the record.
Original Source Code Comment: BUMP TO NEXT SECTOR AND BUFFER
5192
DECrement Register B (the sectors left) and, if it is not 0, LOOP BACK to 518AH (RGRAN1) for the next sector.
Original Source Code Comment: LOOP FOR COUNT
5194
XOR A AF
All 3 sectors were read: set Register A to 00H, so the OR A that follows sets the Z FLAG.
Original Source Code Comment: INSURE 'Z'
5195RGRAN2
OR A B7
RGRAN2: OR Register A with itself: Z when Register A is 00H (all read), NZ when it holds the error code of a failed read.
Original Source Code Comment: SET 'Z' OR 'NZ'
5196
POP HLEXI3 E1
Restore Register Pair HL (the address of the gran record) from the STACK.
5197
POP DE D1
Restore Register Pair DE (the track and first sector) from the STACK.
5198
POP BC C1
Restore Register Pair BC from the STACK.
5199
RET C9
RETurn to the caller with Z (gran read) or NZ and the error code in Register A.

519AH - WGRAN - Write the gran record at HL to the destination at the sector and track stored in its first two bytes, and keep them in VER (51C5H) for VGRAN. Exit: Z, or NZ with the error code in A.

519AWGRAN
PUSH BCSAV3 C5
WGRAN: Save Register Pair BC on the STACK. WGRAN writes the gran record at HL to the destination drive at the track and sector stored in the record's first two bytes.
519B
PUSH DE D5
Save Register Pair DE on the STACK.
519C
PUSH HL E5
Save Register Pair HL (the address of the gran record) on the STACK.
519D
LD B,03HLD B,DGRAN 06 03
LET Register B = 03H, the number of sectors in a gran (DGRAN), as the count for the DJNZ at 51B3H.
Original Source Code Comment: NUMBER OF SECTORS IN A GRAN
519F
LD A,(4E7FH)LD A,(FDRIVD) 3A 7F 4E
Fetch the destination drive number from 4E7FH (FDRIVD) into Register A.
Original Source Code Comment: GET THE DESTINATION DRIVE NUMBER
51A2
LD C,A 4F
LET Register C = Register A, the destination drive number, for XWRITE.
Original Source Code Comment: INTO C
51A3
LD E,(HL)LD DE,(HL) 5E
Fetch the first byte of the gran record (the sector number) into Register E.
Original Source Code Comment: GET THE TRACK AND SECTOR NUMBER
51A4
INC HL 23
INCrement Register Pair HL by 1.
51A5
LD D,(HL) 56
Fetch the second byte of the gran record (the track number) into Register D.
51A6
INC HL 23
INCrement Register Pair HL by 1 to point at the data of the first sector.
51A7
LD (51C5H),DELD (VER),DE ED 53 C5 51
Store Register Pair DE (D = track, E = first sector) into 51C5H-51C6H (VER), the operand of the LD DE at 51C4H in VGRAN, so the verify reads the same three sectors.
Original Source Code Comment: SAVE FOR 'VERIFY' ROUTINE
51ABWGRAN1
WGRAN1: GOSUB to 51E2H (FUNCTB) to write the 256 bytes at HL to drive C, track D, sector E with the message 'Writing Track nn, Sector nn'. FUNCTB returns Z when the write worked or NZ with the error code in A.
Original Source Code Comment: DO THE WRITE
51AE
If the NZ FLAG is set (the write failed, A = the error code), JUMP to 51B6H (WGRAN2).
Original Source Code Comment: EXIT IF ERROR
51B0
GOSUB to 5238H (BUMP): Register E becomes the next sector and Register Pair HL moves 256 bytes on.
Original Source Code Comment: BUMP TO NEXT SECTOR AND BUFFER
51B3
DECrement Register B (the sectors left) and, if it is not 0, LOOP BACK to 51ABH (WGRAN1).
Original Source Code Comment: LOOP FOR COUNT
51B5
XOR A AF
All 3 sectors were written: set Register A to 00H, so the OR A that follows sets the Z FLAG.
Original Source Code Comment: INSURE 'Z'
51B6WGRAN2
OR A B7
WGRAN2: OR Register A with itself: Z when Register A is 00H, NZ when it holds the error code of a failed write.
Original Source Code Comment: SET 'Z' OR 'NZ'
51B7
POP HLEXI3 E1
Restore Register Pair HL (the address of the gran record) from the STACK.
51B8
POP DE D1
Restore Register Pair DE from the STACK.
51B9
POP BC C1
Restore Register Pair BC from the STACK.
51BA
RET C9
RETurn to the caller with Z (gran written) or NZ and the error code in Register A.

51BBH - VGRAN - Read back the 3 sectors WGRAN wrote (track and sector in VER) from the destination, into the ROM, to check them. Exit: Z, or NZ with the error code in A.

51BBVGRAN
PUSH BCSAV3 C5
VGRAN: Save Register Pair BC on the STACK. VGRAN reads back the 3 sectors WGRAN last wrote (track and sector in VER, 51C5H) from the destination drive, to check them.
51BC
PUSH DE D5
Save Register Pair DE on the STACK.
51BD
PUSH HL E5
Save Register Pair HL on the STACK.
51BE
LD B,03HLD B,DGRAN 06 03
LET Register B = 03H, the number of sectors in a gran (DGRAN), as the count for the DJNZ at 51D0H.
Original Source Code Comment: NUMBER OF SECTORS IN A GRAN
51C0
LD A,(4E7FH)LD A,(FDRIVD) 3A 7F 4E
Fetch the destination drive number from 4E7FH (FDRIVD) into Register A.
Original Source Code Comment: GET THE DESTINATION DRIVE NUMBER
51C3
LD C,A 4F
LET Register C = Register A, the destination drive number, for XREAD.
Original Source Code Comment: INTO C
51C4
LD DE,0000HLD DE,0 11 00 00
LET Register Pair DE = the track (D) and first sector (E) of the gran WGRAN wrote: the operand at 51C5H-51C6H (VER) is 0000H in the file and is stored by WGRAN at 51A7H.
Original Source Code Comment: TRACK SECTOR SAVED HERE
51C7
LD HL,0000HLD HL,0 21 00 00
LET Register Pair HL = 0000H as the buffer for XREAD: the data read is written into the ROM, which keeps nothing, so only the read itself (with its CRC check) counts.
Original Source Code Comment: READ INTO ROM
51CAVGRAN1
VGRAN1: GOSUB to 51ECH (FUNCTC) to read track D, sector E, of drive C with the message 'Verifying Track nn, Sector nn'. FUNCTC returns Z when the read worked or NZ with the error code in A.
Original Source Code Comment: DO THE VERIFY
51CD
If the NZ FLAG is set (the read failed, A = the error code), JUMP to 51D3H (VGRAN2).
Original Source Code Comment: EXIT IF ERROR
51CF
INC E 1C
INCrement Register E (the sector number) by 1 for the next sector. HL stays 0000H.
Original Source Code Comment: BUMP TO NEXT SECTOR
51D0
DECrement Register B (the sectors left) and, if it is not 0, LOOP BACK to 51CAH (VGRAN1).
Original Source Code Comment: LOOP FOR COUNT
51D2
XOR A AF
All 3 sectors read back: set Register A to 00H, so the OR A that follows sets the Z FLAG.
Original Source Code Comment: SET 'Z'
51D3VGRAN2
OR A B7
VGRAN2: OR Register A with itself: Z when Register A is 00H, NZ when it holds the error code of a failed read.
Original Source Code Comment: SET 'Z' OR 'NZ'
51D4
POP HLEXI3 E1
Restore Register Pair HL from the STACK.
51D5
POP DE D1
Restore Register Pair DE from the STACK.
51D6
POP BC C1
Restore Register Pair BC from the STACK.
51D7
RET C9
RETurn to the caller with Z (gran verified) or NZ and the error code in Register A.

51D8H - FUNCTA - Read a sector (XREAD) with the line 'Reading Track nn, Sector nn'

51D8FUNCTA
LD IX,4675HLD IX,XREAD DD 21 75 46
FUNCTA: LET Register Pair IX = 4675H, the address of XREAD in SYS0 (read sector: C = drive, D = track, E = sector, HL = buffer), the routine GREAD is to run.
Original Source Code Comment: 'SECTOR' READ ROUTINE
51DC
LD IY,4EABHLD IY,READM FD 21 AB 4E
LET Register Pair IY = 4EABH (READM), the message 1DH 'Reading ' GREAD shows first.
Original Source Code Comment: IY => 'READING' MSG
51E0
JUMP to 51F4H (GREAD) to show the message and run the routine in IX.
Original Source Code Comment: DO IT

51E2H - FUNCTB - Write a sector (XWRITE) with the line 'Writing Track nn, Sector nn'

51E2FUNCTB
LD IX,45F7HLD IX,XWRITE DD 21 F7 45
FUNCTB: LET Register Pair IX = 45F7H, the address of XWRITE in SYS0 (write sector: C = drive, D = track, E = sector, HL = buffer), the routine GREAD is to run.
Original Source Code Comment: 'SECTOR' WRITE ROUTINE
51E6
LD IY,4EB6HLD IY,WRITM FD 21 B6 4E
LET Register Pair IY = 4EB6H (WRITM), the message 1DH 'Writing ' GREAD shows first.
Original Source Code Comment: IY => 'WRITING' MSG
51EA
JUMP to 51F4H (GREAD) to show the message and run the routine in IX.
Original Source Code Comment: DO IT

51ECH - FUNCTC - Read a sector (XREAD) with the line 'Verifying Track nn, Sector nn'

51ECFUNCTC
LD IX,4675HLD IX,XREAD DD 21 75 46
FUNCTC: LET Register Pair IX = 4675H, the address of XREAD in SYS0, the routine GREAD is to run.
Original Source Code Comment: 'SECTOR' READ ROUTINE
51F0
LD IY,4EC1HLD IY,VERFM FD 21 C1 4E
LET Register Pair IY = 4EC1H (VERFM), the message 1DH 'Verifying' GREAD shows first; fall into GREAD.
Original Source Code Comment: IY => 'VERIFYING' MSG

51F4H - GREAD - Run the disk routine in IX (C = drive, D = track, E = sector, HL = buffer) after showing the message at IY with the track and sector. Exit: the Z or NZ and the error code in A that the disk routine returned.

51F4GREAD
PUSH BCSAV3 C5
GREAD: Save Register Pair BC (C = the drive) on the STACK. GEXIT (5228H) restores it after the disk routine.
51F5
PUSH DE D5
Save Register Pair DE (D = track, E = sector) on the STACK.
51F6
PUSH HL E5
Save Register Pair HL (the buffer) on the STACK.
51F7
PUSH IX DD E5
Save Register Pair IX, the address of the disk routine (XREAD or XWRITE), on the STACK.
Original Source Code Comment: PUT THE FUNCTION ON THE STACK
51F9
LD IX,5228HLD IX,GEXIT DD 21 28 52
LET Register Pair IX = 5228H (GEXIT), where the disk routine is to return to.
Original Source Code Comment: PLACE TO RETURN TO
51FD
EX (SP),IX DD E3
EXchange Register Pair IX with the top of the STACK: the STACK now holds 5228H (GEXIT) and IX the address of the disk routine again.
Original Source Code Comment: PUT IT ON THE STACK
51FF
PUSH IX DD E5
Save Register Pair IX (the disk routine) on the STACK above GEXIT: a RET now goes to the disk routine, and its own RET goes to GEXIT.
Original Source Code Comment: RE-SAVE THE FUNCTION
5201
LD A,D 7A
LET Register A = Register D, the track number.
Original Source Code Comment: GET THE TRACK NUMBER
5202
CP 28HCP STRK FE 28
Compare Register A (the track) with 28H (40, the source's STRK): the CARRY FLAG is set for tracks 0-39.
Original Source Code Comment: IS THIS THE 'SECRET' TRACK
5204
If the CARRY FLAG is set (track 0-39), JUMP to 520BH (GREAD1) to show the message first.
Original Source Code Comment: NO, CONTINUE

Tracks 40 and above (the source's secret track): no message, and 80H added to the sector number for the disk routine.

5206
LD A,E 7B
Track 40 or above (the source calls it the secret track): LET Register A = Register E, the sector number.
Original Source Code Comment: GET THE SECTOR NUMBER
5207
OR 80HOR SSEC F6 80
OR Register A with 80H (the source's SSEC), the offset added to the sector numbers of that track.
Original Source Code Comment: ADD IN THE 'SECTOR' OFFSET
5209
LD E,A 5F
LET Register E = Register A, the sector number with bit 7 set, for the disk routine.
Original Source Code Comment: BACK INTO (E)
520A
RET C9
RETurn, which goes to the disk routine on the STACK (XREAD or XWRITE) with no message; it returns to GEXIT (5228H), which restores BC, DE (the sector number without bit 7) and HL.
Original Source Code Comment: AND DO THE FUNCTION WITHOUT MSG'S

520BH - GREAD1 - Show the message at IY and ' Track nn, Sector nn', then go on to the disk routine through GEXIT

520BGREAD1
PUSH BCSAV3 C5
GREAD1: Save Register Pair BC on the STACK for the GEXIT at 5228H, which restores it before going to the disk routine.
520C
PUSH DE D5
Save Register Pair DE (D = track, E = sector) on the STACK.
520D
PUSH HL E5
Save Register Pair HL (the buffer) on the STACK.
520E
LD HL,4ED3HLD HL,FTRACK 21 D3 4E
LET Register Pair HL = 4ED3H (FTRACK), the two digits of the track number in the message.
Original Source Code Comment: WERE THE ASCII VALUE GOES
5211
LD A,D 7A
LET Register A = Register D, the track number.
Original Source Code Comment: GET THE TRACK NUMBER
5212
GOSUB to 522CH (OUTHEX) to write the track number in Register A as two decimal digits at 4ED3H-4ED4H.
Original Source Code Comment: CONVERT TO ASCII AND STORE
5215
LD HL,4EDEHLD HL,SEC 21 DE 4E
LET Register Pair HL = 4EDEH (SEC), the two digits of the sector number in the message.
Original Source Code Comment: WHERE THE ASCII VALUE GOES
5218
LD A,E 7B
LET Register A = Register E, the sector number.
Original Source Code Comment: GET THE SECTOR NUMBER
5219
GOSUB to 522CH (OUTHEX) to write the sector number in Register A as two decimal digits at 4EDEH-4EDFH.
Original Source Code Comment: CONVERT TO ASCII AND STORE
521C
PUSH IY FD E5
Save Register Pair IY (the first part of the message: READM, WRITM or VERFM) on the STACK.
Original Source Code Comment: MOVE THE 1ST MSG TO HL
521E
POP HL E1
Restore it into Register Pair HL, so HL points at that message.
521F
GOSUB to 021BH (the ROM's PRINT routine) to show the text at HL: 1DH (start of the line) and 'Reading ', 'Writing ' or 'Verifying', up to the 03H.
Original Source Code Comment: DISPLAY IT
5222
LD HL,4ECCHLD HL,REST 21 CC 4E
LET Register Pair HL = 4ECCH (REST), the text ' Track nn, Sector nn' with 1EH (erase to the end of the line) and 03H.
Original Source Code Comment: HL => REST OF MESSAGE
5225
GOSUB to 021BH (the ROM's PRINT routine) to show it; then fall into GEXIT.
Original Source Code Comment: DISPLAY IT
5228GEXIT
POP HLEXI3 E1
GEXIT: Restore Register Pair HL from the STACK. After GREAD1 this is the HL saved at 520DH and the RET at 522BH goes to the disk routine; after the disk routine it is the HL saved at 51F6H and the RET goes back to the caller of GREAD. The POPs keep the flags and Register A the disk routine returned.
Original Source Code Comment: RETURN TO FUNCTION
5229
POP DE D1
Restore Register Pair DE (the track and sector) from the STACK.
522A
POP BC C1
Restore Register Pair BC (C = the drive) from the STACK.
522B
RET C9
RETurn: to the disk routine after the message (C, D, E and HL ready for it), or, after the disk routine, to the caller of FUNCTA, FUNCTB or FUNCTC with its Z or NZ and the error code in A.

522CH - OUTHEX - Write Register A (0-99) as two decimal digits at HL and HL+1

522COUTHEX
LD (HL),2FHLD (HL),'0'-1 36 2F
OUTHEX: Store 2FH (the character before '0') at HL, the tens digit of the two digit number. Register A holds the number (0-99) to convert.
Original Source Code Comment: START WITH 0
522EASCII1
INC (HL) 34
ASCII1: INCrement the digit at HL by 1 (the first pass makes it '0').
Original Source Code Comment: BUMP TO NEXT DIGIT
522F
SUB 0AHSUB 10 D6 0A
SUBtract 0AH (10) from Register A.
Original Source Code Comment: CONVERT TO DECIMAL
5231
If the NO CARRY FLAG is set (Register A did not go below 0), LOOP BACK to 522EH to count one more ten.
Original Source Code Comment: LOOP TILL NEGATIVE
5233
ADD A,3AHADD A,'0'+10 C6 3A
ADD 3AH ('0' + 10) to Register A: the subtraction went one ten too far, so this gives the units digit as a character.
Original Source Code Comment: MAKE ASCII AND BRING BACK POSITIVE
5235
INC HL 23
INCrement Register Pair HL by 1 to point at the units digit.
Original Source Code Comment: BUMP TO NEXT SLOT
5236
LD (HL),A 77
Store the units digit (Register A) at HL.
Original Source Code Comment: STORE IT
5237
RET C9
RETurn to the caller.
Original Source Code Comment: EXIT, DONE

5238H - BUMP - Move on to the next sector of a gran: E = E + 1, HL = HL + 256

5238BUMP
INC E 1C
BUMP: INCrement Register E (the sector number) by 1.
Original Source Code Comment: BUMP TO NEXT SECTOR NUMBER
5239
PUSH DE D5
Save Register Pair DE (D = track, E = the next sector) on the STACK.
Original Source Code Comment: SAVE TRACK/SECTOR
523A
LD DE,0100HLD DE,SECTOR 11 00 01
LET Register Pair DE = 0100H (256, the bytes in a sector).
Original Source Code Comment: SIZE OF ONE SECTOR
523D
ADD HL,DE 19
ADD Register Pair DE (256) to Register Pair HL, so HL points at the place for the next sector in the buffer.
Original Source Code Comment: HL => NEXT DATA BUFFER
523E
POP DE D1
Restore Register Pair DE (the track and the next sector) from the STACK.
Original Source Code Comment: RESTORE DE
523F
RET C9
RETurn to the caller.

5240H - GBUMP - Move on to the next gran: E = E + 3, HL = the next gran record (770 bytes on)

5240GBUMP
LD IY,0003HLD IY,DGRAN FD 21 03 00
GBUMP: LET Register Pair IY = 0003H, the number of sectors in a gran (DGRAN). On entry Register Pair DE holds the track (D) and first sector (E) of a gran and HL the address of its gran record.
Original Source Code Comment: NUMBER OF SECTORS IN A GRAN
5244
ADD IY,DE FD 19
ADD Register Pair DE to IY: IY = DE + 3, the first sector of the next gran on the same track (Register E plus 3).
Original Source Code Comment: BUMP THE SECTOR POINTER
5246
PUSH IY FD E5
Save Register Pair IY (the new track and sector) on the STACK.
Original Source Code Comment: MOVE IT BACK TO DE
5248
POP DE D1
Restore it into Register Pair DE: D = track, E = first sector of the next gran.
5249
INC HL 23
INCrement Register Pair HL by 1 (past the sector byte of the gran record).
Original Source Code Comment: BUMP PAST TRACK SECTOR
524A
INC HL 23
INCrement Register Pair HL by 1 (past the track byte).
524B
EX DE,HL EB
EXchange Register Pairs DE and HL: DE = the address of the record's data, HL = the next track and sector.
Original Source Code Comment: MOVE TO DE
524C
LD IY,0300HLD IY,.RES.(SECTOR*DGRAN) FD 21 00 03
LET Register Pair IY = 0300H (768, the bytes of the 3 sectors of a gran).
Original Source Code Comment: NUMBER OF BYTES
5250
ADD IY,DE FD 19
ADD Register Pair DE (the record's data address) to IY: IY = the address of the next gran record (770 bytes after the start of this one).
Original Source Code Comment: ADD TO BUFFER POINTER
5252
EX DE,HL EB
EXchange Register Pairs DE and HL back: DE = the next track and sector again.
Original Source Code Comment: PUT THE POINTERS BACK
5253
PUSH IYLD HL,IY FD E5
Save Register Pair IY (the address of the next gran record) on the STACK.
Original Source Code Comment: MOVE THE NEW BUFFER POINTER TO HL
5255
POP HL E1
Restore it into Register Pair HL.
5256
RET C9
RETurn with Register Pair DE = the track and first sector of the next gran and HL = the address of the next gran record.

5257H - RBOOT - Read the boot gran of the source into the first gran record, keep a copy of the boot sector at 5E00H, refuse a version below 12H and handle the backup counter: lower it on the source, or set CXFLAG when it is at 0; the copy gets 00H

5257RBOOT
LD A,(6000H)LD A,(SGAT) 3A 00 60
RBOOT: Fetch 6000H (SGAT, the copy of the source GAT that FALOC works through) into Register A: the allocation byte of track 0, in which bit 0 is the boot gran.
Original Source Code Comment: GET THE BOOT ALLOCATION
525A
RES 0,A CB 87
RESet bit 0 of Register A: the gran of the boot sector (track 0, sectors 1-3) is being read now.
Original Source Code Comment: SHOW BOOT ALREADY READ
525C
LD (6000H),ALD (SGAT),A 32 00 60
Store Register A back into 6000H (SGAT), so FALOC does not offer that gran again.
525F
LD A,(4E81H)LD A,(BSIDES) 3A 81 4E
Fetch the source side number from 4E81H (BSIDES) into Register A.
Original Source Code Comment: GET THE SOURCE SIDE
5262
LD (4463H),ALD (CSIDE),A 32 63 44
Store it into 4463H (CSIDE, the current side for SYS0's disk I/O).
Original Source Code Comment: SET IT IN DOS
5265
LD DE,0001HLD DE,1 11 01 00
LET Register Pair DE = 0001H: Register D = track 00H, Register E = sector 01H (the boot sector).
Original Source Code Comment: DE = BOOT TRACK/SECTOR
5268
LD HL,6200HLD HL,BUFF 21 00 62
LET Register Pair HL = 6200H (BUFF), the first gran record of the main buffer. The boot gran is the first gran MREAD finds, so it goes into the first record (the source comment: this is a one time only read).
Original Source Code Comment: SINCE THIS IS A 1 TIME ONLY READ
526B
GOSUB to 517DH (RGRAN) to read track 0, sectors 1-3, of the source drive into the gran record at 6200H (sector and track at 6200H-6201H, data from 6202H). Returns Z, or NZ with the error code in A.
Original Source Code Comment: READ IN THE GRAN
526E
If the NZ FLAG is set (the read failed, A = the error code), JUMP to 4E00H (FATAL).
Original Source Code Comment: EXIT IF ERROR
5271
LD HL,6202HLD HL,BUFF+2 21 02 62
LET Register Pair HL = 6202H (BUFF+2), the boot sector in the gran record (past the sector and track bytes).
Original Source Code Comment: HL => BOOT SECTOR
5274
LD DE,5E00HLD DE,SPAR_ 11 00 5E
LET Register Pair DE = 5E00H (SPAR_), where the copy of the boot sector goes.
Original Source Code Comment: TEMP SCRATCH PAD AREA
5277
LD BC,0100HLD BC,SECTOR 01 00 01
LET Register Pair BC = 0100H (256 bytes) for the LDIR.
Original Source Code Comment: NUMBER OF BYTES
527A
LDIR ED B0
Copy the 256 bytes of the boot sector from 6202H to 5E00H-5EFFH (LDIR: HL to DE, HL and DE up by 1, BC down by 1 until 0000H).
Original Source Code Comment: SAVE A COPY OF THE BOOT
527C
LD A,(6300H)LD A,(BUFF+S1TYPE+2) 3A 00 63
Fetch the byte at 6300H into Register A: 6202H plus FEH (S1TYPE), the version byte of the source boot sector (13H for TRSDOS 1.3).
Original Source Code Comment: SEE IF THIS IS VERSION 1.1 OR 1.3
527F
CP 12H FE 12
Compare Register A with 12H: the CARRY FLAG is set when the version byte is below 12H.
Original Source Code Comment: IS IT 1.3?
5281
If the CARRY FLAG is set (an older version diskette), JUMP to 4E35H (N12): Cannot Backup Version 1.1. Diskette.
Original Source Code Comment: NO. CAN'T HANDLE 1.1
5284
LD IXH,62HLD XH,.MSB.BUFF DD 26 62
LET Register IXH (the high byte of IX) = 62H, the high byte of the main buffer (BUFF, 6200H).
Original Source Code Comment: MSB => MSB OF BUFFER LOCATION
5287
LD IXL,24HLD XL,C1LOC+2 DD 2E 24
LET Register IXL (the low byte of IX) = 24H, the offset of the backup counter in the boot sector (C1LOC = 22H) plus the 2 bytes of sector and track: IX = 6224H, the counter (CNT1) of the boot sector read.
Original Source Code Comment: LSB = OFFSET TO PROTECTION COUNTER
528A
LD A,(IX+0) DD 7E 00
Fetch the backup counter at IX (6224H) into Register A: FFH = no limit, 00H-FEH = the backups left.
Original Source Code Comment: GET THE COUNTER
528D
INC A 3C
INCrement Register A by 1: it becomes 00H (Z FLAG set) only when the counter was FFH.
Original Source Code Comment: IS IT SET?
528E
RET Z C8
If the Z FLAG is set (counter FFH, no limit), RETurn to MREAD with Z.
Original Source Code Comment: NO, EXIT
528F
DEC A 3D
DECrement Register A by 1, back to the counter value; the Z FLAG is set when it is 00H.
Original Source Code Comment: SEE IF THE COUNTER IS 0
5290
If the Z FLAG is set (no backups left), JUMP to 52A9H (RBOOT1) to set CXFLAG.
Original Source Code Comment: YES, SET THE 'COUNT' FLAG
5292
DEC (IX+0) DD 35 00
DECrement the counter at IX (6224H) by 1, one backup used, in the copy of the boot sector in the buffer.
Original Source Code Comment: DEC THE COUNTER FOR THIS BACKUP
5295
PUSH HL E5
Save Register Pair HL on the STACK.
Original Source Code Comment: SAVE THE POINTER
5296
LD DE,0001HLD DE,1 11 01 00
LET Register Pair DE = 0001H: track 00H, sector 01H, the boot sector.
Original Source Code Comment: WRITE OUT THE NEW COUNT TO THE SOURCE
5299
LD HL,6202HLD HL,BUFF+2 21 02 62
LET Register Pair HL = 6202H (BUFF+2), the boot sector with the counter just lowered.
Original Source Code Comment: HL POINTS 'PAST' THE TRK/SEC STORED IN RAM
529C
LD A,(4E7EH)LD A,(FDRIVS) 3A 7E 4E
Fetch the source drive number from 4E7EH (FDRIVS) into Register A.
Original Source Code Comment: GET THE SOURCE DRIVE
529F
LD C,A 4F
LET Register C = Register A, the source drive number, for XWRITE.
Original Source Code Comment: INTO C
52A0
GOSUB to 45F7H (XWRITE in SYS0) to write the boot sector at 6202H back to track 0, sector 1, of the source diskette, so the source keeps the lowered count. Returns Z, or NZ with the error code in A.
Original Source Code Comment: DO THE WRITE
52A3
POP HL E1
Restore Register Pair HL from the STACK.
Original Source Code Comment: GET THE POINTER BACK
52A4
If the NZ FLAG is set (the write failed, A = the error code), JUMP to 4E00H (FATAL).
Original Source Code Comment: EXIT IF ERROR
52A7
JUMP to 52AEH (RBOOT2) to set the counter of the copy to 00H.
Original Source Code Comment: CLEAR THE COUNT FOR THIS BACKUP

52A9H - RBOOT1 - The backup counter of the source is at 0: set CXFLAG, then RBOOT2 clears the counter of the copy

52A9RBOOT1
LD A,0FFHLD A,-1 3E FF
RBOOT1: LET Register A = FFH, a value that is not zero.
Original Source Code Comment: GET AN 'NZ' CHAR
52AB
LD (4E85H),ALD (CXFLAG),A 32 85 4E
Store FFH (Register A) into 4E85H (CXFLAG): the counter of the source was at 0, so RDIR takes the protected files out of the copy and EXIT shows the GEORGE messages when it did.
Original Source Code Comment: SET THE 'COUNTER' FLAG
52AERBOOT2
LD (IX+0),00HLD (IX),0 DD 36 00 00
RBOOT2: Store 00H into the counter at IX (6224H) in the buffer: the boot sector written to the destination carries a count of 0, so the copy cannot be backed up again with protected files.
Original Source Code Comment: CLEAR THE COUNT FOR THIS BACKUP
52B2
XOR A AF
Set Register A to 00H and the Z FLAG (boot gran read without error).
Original Source Code Comment: SET 'Z'
52B3
RET C9
RETurn to MREAD with the Z FLAG set.

52B4H - RDIR - Read the directory track of the source into the main buffer, put the destination's flaw table into its GAT and, when CXFLAG is set, take the protected files out with EXMGRN

52B4RDIR
LD DE,1101H 11 01 11
RDIR: LET Register Pair DE = 1101H: Register D = track 11H (17, the directory track), Register E = sector 01H.
Original Source Code Comment: STARTING TRACK/SECTOR FOR DIRECTORY
52B7
LD HL,6200HLD HL,BUFF 21 00 62
LET Register Pair HL = 6200H (BUFF), the start of the main buffer, where the directory track goes as 6 gran records.
Original Source Code Comment: WHERE TO STORE IT
52BA
LD B,06HLD B,NGRAN 06 06
LET Register B = 06H, the number of grans on a track (NGRAN), as the count for the DJNZ at 52CBH.
Original Source Code Comment: NUMBER OF GRANS IN DIRECTORY
52BC
LD A,(4E81H)LD A,(BSIDES) 3A 81 4E
Fetch the source side number from 4E81H (BSIDES) into Register A.
Original Source Code Comment: GET THE SOURCE SIDE
52BF
LD (4463H),ALD (CSIDE),A 32 63 44
Store it into 4463H (CSIDE, the current side for SYS0's disk I/O).
Original Source Code Comment: SET IT IN DOS
52C2RDIR1
RDIR1: GOSUB to 517DH (RGRAN) to read the 3 sectors of track D starting at sector E from the source drive into the gran record at HL. Returns Z, or NZ with the error code in A.
Original Source Code Comment: READ IN A GRAN
52C5
If the NZ FLAG is set (the read failed, A = the error code), JUMP to 4E00H (FATAL).
Original Source Code Comment: EXIT IF ERROR
52C8
GOSUB to 5240H (GBUMP): Register E moves on 3 sectors and Register Pair HL to the next gran record (770 bytes on).
Original Source Code Comment: BUMP THE POINTERS
52CB
DECrement Register B (the grans left) and, if it is not 0, LOOP BACK to 52C2H (RDIR1): the 18 sectors of the track end up in 6 gran records at 6200H-7413H.
Original Source Code Comment: LOOP FOR COUNT
52CD
LD HL,6160HLD HL,FGAT+FLAW 21 60 61
LET Register Pair HL = 6160H (FGAT+FLAW), the flaw table of the destination that DGAT (5500H) copied into the GAT copy at 6100H.
Original Source Code Comment: GET THE SAVED FLAW TABLE FROM DESTINATION
52D0
LD DE,6262HLD DE,BUFF+2+FLAW 11 62 62
LET Register Pair DE = 6262H (BUFF+2+FLAW), the flaw table at offset 60H of the GAT just read (the GAT is the first sector of the first gran record, from 6202H).
Original Source Code Comment: DE => WHERE IT IS TO GO
52D3
LD BC,0028HLD BC,MAXTRK 01 28 00
LET Register Pair BC = 0028H (40, MAXTRK), one flaw byte per track.
Original Source Code Comment: BC = NUMBER OF BYTES TO MOVE
52D6
LDIR ED B0
Copy the 40 flaw bytes of the destination over those of the source GAT in the buffer (LDIR), so the GAT written to the destination keeps its own flaw table.
Original Source Code Comment: MOVE THE FAD
52D8
LD A,(4E85H)LD A,(CXFLAG) 3A 85 4E
Fetch 4E85H (CXFLAG) into Register A: FFH when the backup counter of the source was at 0.
Original Source Code Comment: SEE IF MODIFICATION HAS TO OCCUR
52DB
OR A B7
OR Register A with itself to set the flags from CXFLAG.
52DC
RET Z C8
If the Z FLAG is set (CXFLAG 00H), RETurn: no file is taken out of the copy.
Original Source Code Comment: NO, EXIT
52DD
XOR A AF
Set Register A to 00H.
Original Source Code Comment: CLEAR A LFN COUNTER
52DE
LD (4E84H),ALD (CLFN),A 32 84 4E
Store 00H (Register A) into 4E84H (CLFN), the number of the directory record EXMGRN looks at first.
52E1
LD DE,1101H 11 01 11
LET Register Pair DE = 1101H: track 17, sector 1, the first gran of the directory track.
Original Source Code Comment: SET FOR START OF DIR TRACK
52E4
LD HL,6200HLD HL,BUFF 21 00 62
LET Register Pair HL = 6200H (BUFF), the first gran record of the directory track in the buffer.
Original Source Code Comment: HL => DIR TRACK IN RAM
52E7
LD B,06HLD B,NGRAN 06 06
LET Register B = 06H, the grans on a track (NGRAN), as the count for the DJNZ at 52EFH.
Original Source Code Comment: NUMBER OF GRANS IN A TRACK
52E9RDIR2
RDIR2: GOSUB to 5312H (EXMGRN) to look at the directory records in the gran record at HL (sector E first) and take out the protected files.
Original Source Code Comment: EXAMINE THE GRAN FOR 'COUNTER' PGMS
52EC
GOSUB to 5240H (GBUMP): Register E moves on 3 sectors and Register Pair HL to the next gran record.
Original Source Code Comment: BUMP TO NEXT GRAN
52EF
DECrement Register B (the grans left) and, if it is not 0, LOOP BACK to 52E9H (RDIR2).
Original Source Code Comment: LOOP FOR COUNT
52F1
RET C9
RETurn to DOLLAR.
Original Source Code Comment: DONE. EXIT

52F2H - WDIR - Write and verify the directory track in the main buffer on the destination

52F2WDIR
LD DE,1101H 11 01 11
WDIR: LET Register Pair DE = 1101H: track 17 (11H), sector 1, where the directory goes on the destination.
Original Source Code Comment: WHERE THE DIRECTORY GOES
52F5
LD HL,6200HLD HL,BUFF 21 00 62
LET Register Pair HL = 6200H (BUFF), the first gran record of the directory track in the buffer. WGRAN takes the track and sector from each record.
Original Source Code Comment: WHERE THE DATA IS
52F8
LD B,06HLD B,NGRAN 06 06
LET Register B = 06H, the grans on a track (NGRAN), as the count for the DJNZ at 530FH.
Original Source Code Comment: NUMBER OF GRANS IN A TRACK
52FA
LD A,(4E82H)LD A,(BSIDED) 3A 82 4E
Fetch the destination side number from 4E82H (BSIDED) into Register A.
Original Source Code Comment: GET THE DESTINATION SIDE
52FD
LD (4463H),ALD (CSIDE),A 32 63 44
Store it into 4463H (CSIDE, the current side for SYS0's disk I/O).
Original Source Code Comment: SET IT IN DOS
5300WDIR1
WDIR1: GOSUB to 519AH (WGRAN) to write the gran record at HL to the destination drive. Returns Z, or NZ with the error code in A.
Original Source Code Comment: WRITE OUT A GRAN
5303
If the NZ FLAG is set (the write failed, A = the error code), JUMP to 4E00H (FATAL).
Original Source Code Comment: EXIT IF ERROR
5306
GOSUB to 51BBH (VGRAN) to read the 3 sectors back from the destination. Returns Z, or NZ with the error code in A.
Original Source Code Comment: VERIFY THE GRAN
5309
If the NZ FLAG is set (the read back failed, A = the error code), JUMP to 4E00H (FATAL).
Original Source Code Comment: EXIT IF ERROR
530C
GOSUB to 5240H (GBUMP): Register Pair HL moves to the next gran record (and Register E on by 3).
Original Source Code Comment: BUMP TO NEXT GRAN
530F
DECrement Register B (the grans left) and, if it is not 0, LOOP BACK to 5300H (WDIR1).
Original Source Code Comment: LOOP FOR COUNT
5311
RET C9
RETurn to DOLLAR.
Original Source Code Comment: DONE

5312H - EXMGRN - Look at the directory records in one gran record (HL, first sector E) and take every file whose attribute byte has bit 5 set out of the copy

5312EXMGRN
PUSH BCSAV3 C5
EXMGRN: Save Register Pair BC on the STACK (Register B is RDIR's gran count). On entry Register E holds the first sector of the gran and HL the address of its gran record.
5313
PUSH DE D5
Save Register Pair DE on the STACK.
5314
PUSH HL E5
Save Register Pair HL on the STACK.
5315EXMGR1
LD B,03HLD B,DGRAN 06 03
EXMGR1: LET Register B = 03H, the sectors in a gran (DGRAN), the count for the DJNZ at 534BH.
Original Source Code Comment: NUMBER OF SECTORS PER GRAN
5317
INC HL 23
INCrement Register Pair HL by 1 (past the sector byte of the gran record).
Original Source Code Comment: BUMP PAST TRACK/SECTOR NUMBER
5318
INC HL 23
INCrement Register Pair HL by 1 (past the track byte): HL points at the first sector of the gran.
5319
LD A,E 7B
LET Register A = Register E, the first sector of the gran.
Original Source Code Comment: GET THE SECTOR NUMBER
531A
CP 01HCP GAT FE 01
Compare Register A with 01H (the source's GAT, the sector of the GAT): the Z FLAG is set for the first gran of the track (sectors 1-3: GAT, HIT and the first directory sector).
Original Source Code Comment: IS THE IS THE GAT SECTOR?
531C
If the NZ FLAG is set (sectors 4 and up, all directory sectors), JUMP to 5323H (EXMGR2) with B = 3.
Original Source Code Comment: NO, CONTINUE
531E
LD B,01HLD B,1 06 01
LET Register B = 01H: in the first gran only one sector holds directory records.
Original Source Code Comment: YES, ONLY ONE SECTOR TO CHECK
5320
LD HL,6402HLD HL,BUFF+(SECTOR*2)+2 21 02 64
LET Register Pair HL = 6402H (BUFF + 512 + 2), sector 3 of the directory track, the third sector of the first gran record.
Original Source Code Comment: GET POINTER TO RIGHT PLACE
5323EXMGR2
PUSH BC C5
EXMGR2: Save Register Pair BC (Register B = the sectors left in this gran) on the STACK.
Original Source Code Comment: SAVE IT
5324
PUSH HL E5
Save Register Pair HL (the start of the sector) on the STACK.
Original Source Code Comment: SAVE BUFFER POINTER
5325
LD B,05HLD B,RECSEC 06 05
LET Register B = 05H, the directory records in a sector (RECSEC), the count for the DJNZ at 5344H.
Original Source Code Comment: NUMBER OF RECORDS PER SECTOR
5327EXMGR3
PUSH BC C5
EXMGR3: Save Register Pair BC (Register B = the records left in this sector) on the STACK.
Original Source Code Comment: SAVE THE NUMBER OF RECORDS
5328
LD A,(HL) 7E
Fetch the first byte of the directory record at HL (the attribute byte) into Register A.
Original Source Code Comment: GET AN ATTRIB BYTE
5329
PUSH HL E5
Save Register Pair HL (the address of the record) on the STACK.
Original Source Code Comment: SAVE POINTER
532A
OR A B7
OR Register A with itself: the Z FLAG is set when the attribute byte is 00H (no file in this record).
Original Source Code Comment: ANY FILE HERE?
532B
If the Z FLAG is set (empty record), JUMP to 5337H (NXTREC).
Original Source Code Comment: NO, CONTINUE TO NEXT RECORD
532D
BIT 5,(HL)BIT PROTC,(HL) CB 6E
Test bit 5 of the attribute byte at HL (the source's PROTC): set for a file that may not be copied once the backup count is used up.
Original Source Code Comment: THIS FILE PROTECTED?
532F
If the Z FLAG is set (bit 5 clear, an ordinary file), JUMP to 5337H (NXTREC).
Original Source Code Comment: NO CONTINUE

The record holds a file with bit 5 of its attribute byte set: take it out of the copy.

5331
LD (4E86H),ALD (CCFLAG),A 32 86 4E
Store Register A (the attribute byte, not zero) into 4E86H (CCFLAG): a protected file is being taken out of the backup.
Original Source Code Comment: SET THE 'KILLED A FILE' FLAG
5334
GOSUB to 5351H (DEALOC) to release the file's grans in the GAT copy at 6100H, clear its directory record at HL and its byte in the HIT.
Original Source Code Comment: DE-ALLOCATE IT AND THE SPACE
5337NXTREC
POP HL E1
NXTREC: Restore Register Pair HL (the address of the directory record) from the STACK.
Original Source Code Comment: GET DIRECTORY POINTER BACK
5338
LD DE,0030HLD DE,SIZDIR 11 30 00
LET Register Pair DE = 0030H (48, SIZDIR), the size of a directory record.
Original Source Code Comment: DE = NUMBER OF BYTES IN A DIR RECORD
533B
ADD HL,DE 19
ADD Register Pair DE to HL, so HL points at the next directory record.
Original Source Code Comment: HL => NEXT FILE
533C
LD A,(4E84H)LD A,(CLFN) 3A 84 4E
Fetch the record number from 4E84H (CLFN) into Register A.
Original Source Code Comment: GET THE LFN COUNT
533F
INC A 3C
INCrement Register A by 1 for the next record.
Original Source Code Comment: BUMP IT TO NEXT LFN
5340
LD (4E84H),ALD (CLFN),A 32 84 4E
Store it back into 4E84H (CLFN).
5343
POP BC C1
Restore Register Pair BC (Register B = the records left in this sector) from the STACK.
Original Source Code Comment: GET THE RECORDS PER SECTOR COUNT
5344
DECrement Register B and, if it is not 0, LOOP BACK to 5327H (EXMGR3) for the next record.
Original Source Code Comment: DO NEXT RECORD
5346
POP HL E1
Restore Register Pair HL (the start of the sector) from the STACK.
Original Source Code Comment: GET BUFFER POINTER BACK
5347
POP BC C1
Restore Register Pair BC (Register B = the sectors left in the gran) from the STACK.
Original Source Code Comment: GET GRAN COUNT BACK
5348
GOSUB to 5238H (BUMP): Register E becomes the next sector and HL moves 256 bytes on to the next sector of the gran.
Original Source Code Comment: BUMP TO NEXT SECTOR
534B
DECrement Register B (the sectors left) and, if it is not 0, LOOP BACK to 5323H (EXMGR2).
Original Source Code Comment: DO ANOTHER DIR RECORD
534D
POP HLEXI3 E1
Restore Register Pair HL (the address of the gran record) from the STACK.
534E
POP DE D1
Restore Register Pair DE (the first sector of the gran) from the STACK.
534F
POP BC C1
Restore Register Pair BC (RDIR's gran count) from the STACK.
5350
RET C9
RETurn to RDIR.

5351H - DEALOC - Take a protected file out of the copy: release the grans of each of its extents in the GAT copy at 6100H (RELEAS), then clear its directory record at HL and its byte in the HIT

5351DEALOC
PUSH HL E5
DEALOC: Save Register Pair HL, the address of the directory record of the file to take out, on the STACK.
Original Source Code Comment: SAVE POINTER TO THE FILE
5352
LD A,16HLD A,DSEG 3E 16
LET Register A = 16H (22, DSEG), the offset of the first extent in a directory record.
Original Source Code Comment: OFFSET TO THE SEGMENT DESCRIPTORS
5354
ADD A,L 85
ADD Register L to Register A. Every directory record in the buffer starts at most CCH bytes into a 256 byte page, so adding 16H does not carry into H.
5355
LD L,A 6F
LET Register L = Register A: HL points at the first extent (2 bytes: track, then the allocation byte).
Original Source Code Comment: HL => SD'S
5356DEALC1
LD E,(HL)LD DE,(HL) 5E
DEALC1: Fetch the first byte of the extent at HL (the track) into Register E.
Original Source Code Comment: GET THE NEXT SD
5357
INC HL 23
INCrement Register Pair HL by 1.
5358
LD D,(HL) 56
Fetch the second byte of the extent (bits 7-5 the first gran, bits 4-0 the number of grans) into Register D.

Register Pair DE now holds the extent: E = its track (FEH or FFH ends the list), D = its allocation byte (bits 7-5 the first gran, bits 4-0 the number of grans).

5359
LD A,E 7B
LET Register A = Register E, the track of the extent.
Original Source Code Comment: GET THE TRACK NUMBER
535A
CP 0FEHCP 0FEH FE FE
Compare Register A with FEH: the NO CARRY FLAG is set for FEH or FFH, the end of the extents.
Original Source Code Comment: WE DONE WITH THIS FILE?
535C
If the NO CARRY FLAG is set (no more extents), JUMP to 5364H (DEALC2).
Original Source Code Comment: YES, EXIT
535E
INC HL 23
INCrement Register Pair HL by 1 to point at the next extent.
Original Source Code Comment: BUMP TO NEXT SD
535F
GOSUB to 537CH (RELEAS) to clear the bits of the extent's grans (track E, allocation byte D) in the GAT copy at 6100H.
Original Source Code Comment: RELEASE THIS SD
5362
LOOP BACK to 5356H (DEALC1) for the next extent.
Original Source Code Comment: LOOP FOR ANOTHER SD

5364H - DEALC2 - Clear the directory record and the file's byte in the HIT

5364DEALC2
POP HL E1
DEALC2: Restore Register Pair HL, the address of the directory record, from the STACK.
Original Source Code Comment: GET THE SD POINTER BACK
5365
LD D,HLD DE,HL 54
LET Register D = Register H.
Original Source Code Comment: MIRROR TO DE
5366
LD E,L 5D
LET Register E = Register L: DE = HL, the address of the directory record.
5367
INC DE 13
INCrement Register Pair DE by 1, so the LDIR copies the cleared byte forward.
Original Source Code Comment: BUMP TO NEXT SLOT
5368
LD BC,002FHLD BC,SIZDIR-1 01 2F 00
LET Register Pair BC = 002FH (47, SIZDIR minus 1), the bytes the LDIR copies after the first.
Original Source Code Comment: NUMBER OF BYTES IN A DIR RECORD
536B
LD (HL),00HLD (HL),0 36 00
Store 00H into the first byte of the directory record (its attribute byte).
Original Source Code Comment: CLEAR IT OUT
536D
LDIR ED B0
Copy the 00H forward (LDIR): all 48 bytes of the directory record become 00H.
536F
LD HL,6302HLD HL,.RES.BUFF+SECTOR+2 21 02 63
LET Register Pair HL = 6302H (BUFF + 256 + 2), the HIT: the second sector of the first gran record of the directory track.
Original Source Code Comment: HL => BEGIN OF HIT TABLE
5372
LD A,(4E84H)LD A,(CLFN) 3A 84 4E
Fetch the record number from 4E84H (CLFN) into Register A.
Original Source Code Comment: THIS THIS FILE'S LFN
5375
LD E,ALD DE,A 5F
LET Register E = Register A, the record number.
Original Source Code Comment: INTO DE
5376
LD D,00H 16 00
LET Register D = 00H: DE = the record number.
5378
ADD HL,DE 19
ADD Register Pair DE to HL, so HL points at the record's byte in the HIT.
Original Source Code Comment: HL => HASH CODE FOR THIS FILE
5379
LD (HL),00HLD (HL),0 36 00
Store 00H into the HIT byte: the file is no longer in the directory.
Original Source Code Comment: CLEAR IT OUT
537B
RET C9
RETurn to EXMGRN.

537CH - RELEAS - Clear the bits of the grans of one extent in the GAT copy at 6100H. On entry E = the track of the extent, D = its allocation byte.

537CRELEAS
PUSH BCSAV3 C5
RELEAS: Save Register Pair BC on the STACK. On entry Register E holds the track of an extent and Register D its allocation byte (bits 7-5 the first gran, bits 4-0 the number of grans).
537D
PUSH DE D5
Save Register Pair DE on the STACK.
537E
PUSH HL E5
Save Register Pair HL on the STACK.
537F
LD L,E 6B
LET Register L = Register E, the track of the extent.
Original Source Code Comment: THE TRACK NUMBER INTO L
5380
LD H,61HLD H,FGAT.HIGH. 26 61
LET Register H = 61H: HL = 6100H plus the track, the allocation byte of that track in the GAT copy (FGAT).
Original Source Code Comment: HL => THIS TRACKS ALLOCATION
5382
LD A,D 7A
LET Register A = Register D, the allocation byte of the extent.
Original Source Code Comment: GET THE GRAN INFO
5383
AND 1FHAND 1FH E6 1F
MASK Register A with 1FH (0001 1111) to keep bits 4-0, the number of grans of the extent.
Original Source Code Comment: MASK OFF STARTING GRAN
5385
LD C,A 4F
LET Register C = Register A, the number of grans to release (the count for the loop at 53A6H).
Original Source Code Comment: INTO C
5386
XOR D AA
XOR Register A with Register D: A now holds only bits 7-5 of D, the first gran.
Original Source Code Comment: A = STARTING GRAN
5387
RLCA 07
Rotate Register A left (RLCA); three of these move bits 7-5 into bits 2-0.
Original Source Code Comment: SHIFT IT TO LSB
5388
RLCA 07
Rotate Register A left again.
5389
RLCA 07
Rotate Register A left a third time: Register A = the first gran (0-5) of the extent.
538A
LD E,00HLD E,0 1E 00
LET Register E = 00H, the number of grans of the extent already released.
Original Source Code Comment: SET AN OFFSET COUNTER
538CREL1
PUSH AF F5
REL1: Save Register Pair AF (Register A = the first gran) on the STACK.
Original Source Code Comment: SAVE STARTING GRAN
538D
PUSH HL E5
Save Register Pair HL (the GAT byte of the extent's track) on the STACK.
Original Source Code Comment: SAVE BUFFER POINTER
538E
ADD A,E 83
ADD Register E to Register A: the gran to release, counted from the extent's track (it can be 6 or more when the extent goes on into the next tracks).
Original Source Code Comment: ADD IN THE OFFSET
538F
LD L,ALD HL,A 6F
LET Register L = Register A.
Original Source Code Comment: INTO HL
5390
LD H,00H 26 00
LET Register H = 00H: HL = the gran number.
5392
LD A,06HLD A,NGRAN 3E 06
LET Register A = 06H, the grans on a track (NGRAN), as the divisor.
Original Source Code Comment: NUMBER OF GRANS PER TRACK
5394
GOSUB to 4451H (DIV in SYS0, JP 4B6FH): HL = HL / 6 and Register A = the remainder. L = the number of tracks past the extent's track and A = the gran on that track, which is the bit number in its GAT byte.
Original Source Code Comment: A = BIT NUMBER, L = TRACK OFFSET
5397
LD D,A 57
LET Register D = Register A, the bit number.
Original Source Code Comment: SAVE THE BIT NUMBER
5398
LD A,L 7D
LET Register A = Register L, the number of tracks past the extent's track.
Original Source Code Comment: GET THE TRACK OFFSET
5399
POP HL E1
Restore Register Pair HL (the GAT byte of the extent's track) from the STACK.
Original Source Code Comment: GET THE GAT POINTER BACK
539A
PUSH HL E5
Save it on the STACK again for the next pass.
539B
ADD A,L 85
ADD Register L to Register A.
Original Source Code Comment: ADD IN THE TRACK OFFSET
539C
LD L,A 6F
LET Register L = Register A: HL points at the GAT byte of the track that holds this gran.
Original Source Code Comment: HL => NEXT TRACK
539D
LD A,D 7A
LET Register A = Register D, the bit number of the gran.
Original Source Code Comment: GET THE BIT NUMBER BACK
539E
LD B,(HL) 46
Fetch the GAT byte at HL into Register B.
Original Source Code Comment: GET THE ALLOCATION BYTE
539F
GOSUB to 53ADH (CLRBIT) to clear bit A of Register B.
Original Source Code Comment: RELEASE ONE BIT
53A2
LD (HL),B 70
Store Register B (the GAT byte with the gran's bit cleared) back at HL.
Original Source Code Comment: PUT THE RELEASED BACK
53A3
POP HL E1
Restore Register Pair HL (the GAT byte of the extent's track) from the STACK.
Original Source Code Comment: GET GAT POINTER BACK
53A4
POP AF F1
Restore Register Pair AF (Register A = the first gran) from the STACK.
Original Source Code Comment: GET STARTING GRAN BACK
53A5
INC E 1C
INCrement Register E by 1: one more gran of the extent released.
Original Source Code Comment: BUMP TO NEXT OFFSET
53A6
DEC C 0D
DECrement Register C (the grans still to release).
Original Source Code Comment: DEC THE NUMBER OF GRANS TO RELEASE
53A7
If the NZ FLAG is set (more grans), LOOP BACK to 538CH (REL1).
Original Source Code Comment: LOOP IF MORE SD'S TO DO
53A9
POP HLEXI3 E1
Restore Register Pair HL from the STACK.
53AA
POP DE D1
Restore Register Pair DE from the STACK.
53AB
POP BC C1
Restore Register Pair BC from the STACK.
53AC
RET C9
RETurn to DEALOC.

53ADH - CLRBIT - Clear bit A (0-7) of Register B by building a RES n,B at 53B7H

53ADCLRBIT
AND 07HAND 7 E6 07
CLRBIT: MASK Register A (the bit number) with 07H (0000 0111) to keep 0-7.
Original Source Code Comment: THERE'S ONLY 8 BITS
53AF
RLCA 07
Rotate Register A left (RLCA); three of these move the bit number into bits 5-3, where the second byte of a RES instruction holds it.
53B0
RLCA 07
Rotate Register A left again.
53B1
RLCA 07
Rotate Register A left a third time.
53B2
OR 80H F6 80
OR Register A with 80H: 80H plus 8 times the bit number is the second byte of RES n,B.
Original Source Code Comment: INSURE BIT 7 ON
53B4
LD (53B8H),ALD (CLRBT2),A 32 B8 53
Store Register A into 53B8H (CLRBT2), the second byte of the RES at 53B7H, so that instruction becomes RES n,B for the bit wanted.
Original Source Code Comment: STORE IT
53B7
RES 0,B CB 80
RES 0,B in the file; at run time RES n,B with the bit n stored at 53B4H: clear the gran's bit in Register B (the GAT byte).
Original Source Code Comment: TURN THE BIT OFF
53B9
RET C9
RETurn to RELEAS with Register B changed.

53BAH - MEMCHK - Move BUFPNT to the next gran record; CARRY when it would start above MEMTOP (the main buffer is full)

53BAMEMCHK
PUSH BCSAV3 C5
MEMCHK: Save Register Pair BC on the STACK.
53BB
PUSH DE D5
Save Register Pair DE (the track and sector) on the STACK.
53BC
PUSH HL E5
Save Register Pair HL on the STACK.
53BD
LD HL,(4E8CH)LD HL,(BUFPNT) 2A 8C 4E
Fetch the address of the current gran record from 4E8CH-4E8DH (BUFPNT) into Register Pair HL.
Original Source Code Comment: GET THE BUFFER POINTER
53C0
GOSUB to 5240H (GBUMP): HL becomes the address of the next gran record (770 bytes on). DE changes too, but it is restored at 53D0H.
Original Source Code Comment: BUMP IT
53C3
LD (4E8CH),HLLD (BUFPNT),HL 22 8C 4E
Store the new record address into 4E8CH-4E8DH (BUFPNT).
Original Source Code Comment: SAVE NEW VALUE
53C6
EX DE,HL EB
EXchange Register Pairs DE and HL: DE = the new record address.
Original Source Code Comment: INTO DE
53C7
LD HL,(4E8EH)LD HL,(MEMTOP) 2A 8E 4E
Fetch the top of the buffer from 4E8EH-4E8FH (MEMTOP, the end of memory minus 768) into Register Pair HL.
Original Source Code Comment: GET THE END OF MEMORY
53CA
PUSH HLCD DE E5
Save Register Pair HL (MEMTOP) on the STACK; with the next three instructions this is the source's CD DE (compare DE).
Original Source Code Comment: SEE IF OUT OF MEMORY
53CB
OR A B7
OR Register A with itself to clear the CARRY FLAG for the SBC.
53CC
SBC HL,DE ED 52
SUBtract Register Pair DE (the new record address) from HL (MEMTOP): the CARRY FLAG is set when the new record would start above MEMTOP, the buffer is full.
53CE
POP HL E1
Restore Register Pair HL (MEMTOP) from the STACK; the flags of the SBC stay.
53CF
POP HLEXI3 E1
Restore Register Pair HL (the caller's HL) from the STACK.
53D0
POP DE D1
Restore Register Pair DE (the track and sector) from the STACK.
53D1
POP BC C1
Restore Register Pair BC from the STACK.
53D2
RET C9
RETurn with the CARRY FLAG set (buffer full) or clear (room for another gran record).

53D3H - MWRIT - Write and verify the gran records of the main buffer on the destination. Exit: CARRY when the FFH end mark was reached (the source is finished), NC when the buffer was written and more of the source is left.

53D3MWRIT
LD HL,6200HLD HL,BUFF 21 00 62
MWRIT: LET Register Pair HL = 6200H (BUFF), the first gran record of the main buffer.
Original Source Code Comment: RESET THE BUFFER POINTER
53D6
LD (4E8CH),HLLD (BUFPNT),HL 22 8C 4E
Store it into 4E8CH-4E8DH (BUFPNT) as the record to write first.
53D9
LD A,(4E82H)LD A,(BSIDED) 3A 82 4E
Fetch the destination side number from 4E82H (BSIDED) into Register A.
Original Source Code Comment: GET THE DESTINATION SIDE NUMBER
53DC
LD (4463H),ALD (CSIDE),A 32 63 44
Store it into 4463H (CSIDE, the current side for SYS0's disk I/O).
Original Source Code Comment: SET IT IN DOS
53DFMWRIT1
LD HL,(4E8CH)LD HL,(BUFPNT) 2A 8C 4E
MWRIT1: Fetch the address of the current gran record from 4E8CH-4E8DH (BUFPNT) into Register Pair HL.
Original Source Code Comment: GET THE BUFFER POINTER
53E2
LD A,(HL) 7E
Fetch the first byte of the record (its sector number, or FFH that MREAD3 stored after the last gran of the diskette) into Register A.
Original Source Code Comment: GET THE SECTOR NUMBER
53E3
CP 0FFHCP -1 FE FF
Compare Register A with FFH: the Z FLAG is set at the end of the diskette.
Original Source Code Comment: END OF DISK?
53E5
SCF 37
Set the CARRY FLAG (the end of the diskette, in case the RET Z is taken).
Original Source Code Comment: SET CARRY IN CASE
53E6
RET Z C8
If the Z FLAG is set (end of the diskette), RETurn to DOLOOP with the CARRY FLAG set: the copy of the data is done.
Original Source Code Comment: YES, EXIT
53E7
GOSUB to 519AH (WGRAN) to write the gran record at HL to the destination drive at its track and sector. Returns Z, or NZ with the error code in A.
Original Source Code Comment: WRITE OUT A GRAN
53EA
If the NZ FLAG is set (the write failed, A = the error code), JUMP to 4E00H (FATAL).
Original Source Code Comment: EXIT IF ERROR
53ED
GOSUB to 51BBH (VGRAN) to read the 3 sectors back from the destination. Returns Z, or NZ with the error code in A.
Original Source Code Comment: VERIFY A GRAN
53F0
If the NZ FLAG is set (the read back failed, A = the error code), JUMP to 4E00H (FATAL).
53F3
GOSUB to 53BAH (MEMCHK) to move BUFPNT to the next gran record: the CARRY FLAG is set when that would pass MEMTOP (all records MREAD filled are written).
Original Source Code Comment: BUMP POINTER AND CHECK END OF MEMORY
53F6
If the NO CARRY FLAG is set, LOOP BACK to 53DFH (MWRIT1) for the next record.
Original Source Code Comment: LOOP TILL DONE
53F8
OR A B7
OR Register A with itself to clear the CARRY FLAG: the buffer was written but the diskette is not finished.
Original Source Code Comment: CLEAR CARRY
53F9
RET C9
RETurn to DOLOOP with the CARRY FLAG clear, so DOLOOP reads the next part of the source.

53FAH - FALOC - Find the next gran in use on the source in SGAT (6000H) and take it off. Exit: NC with D = track and E = first sector, or CARRY when no gran is left.

53FAFALOC
LD HL,6000HLD HL,SGAT 21 00 60
FALOC: LET Register Pair HL = 6000H (SGAT), the copy of the allocation bytes of the source GAT (one byte per track) that FALOC clears gran by gran as they are copied.
Original Source Code Comment: HL => CHANGABLE GAT BUFFER
53FDFALOC1
LD A,L 7D
FALOC1: LET Register A = Register L, the low byte of HL, which is the track number (SGAT starts at 6000H).
Original Source Code Comment: GET THE LSB OF THE POINTER
53FE
CP 28HCP MAXTRK FE 28
Compare Register A with 28H (40, MAXTRK): the CARRY FLAG is set for tracks 0-39.
Original Source Code Comment: WE AT THE END OF THE DISK?
5400
CCF 3F
Complement the CARRY FLAG: it is now set when the track is 40 or more, the end of the diskette.
Original Source Code Comment: COMPLIMENT THE CARRY
5401
RET C D8
If the CARRY FLAG is set (no more tracks), RETurn to MREAD with CARRY.
Original Source Code Comment: YES, EXIT
5402
LD A,(HL) 7E
Fetch the allocation byte of the track at HL into Register A (bit n set = gran n holds data).
Original Source Code Comment: GET AN ALLOCATION BYTE
5403
OR A B7
OR Register A with itself: the Z FLAG is set when no gran of this track is in use.
Original Source Code Comment: ANYTHING IN THIS TRACK?
5404
If the NZ FLAG is set (a gran of this track is in use), JUMP to 5409H (FALOC2).
Original Source Code Comment: YES, PROCESS IT
5406
INC HL 23
INCrement Register Pair HL by 1 to the next track's allocation byte.
Original Source Code Comment: NO, BUMP TO NEXT TRACK
5407
LOOP BACK to 53FDH (FALOC1).
Original Source Code Comment: LOOP TILL FOUND or END OF DISK

5409H - FALOC2 - Take the lowest gran in use off the track's allocation byte at HL and return its first sector in E

5409FALOC2
RES 0,(HL) CB 86
FALOC2: RESet bit 0 of the allocation byte at HL, taking gran 0 off (Register A keeps the old byte for the tests).
Original Source Code Comment: TRY FOR 1ST GRAN
540B
LD E,01HLD E,1 1E 01
LET Register E = 01H, the first sector of gran 0.
Original Source Code Comment: SET FOR SECTOR 1
540D
BIT 0,A CB 47
Test bit 0 of Register A: is gran 0 in use?
Original Source Code Comment: 1ST GRAN?
540F
If the NZ FLAG is set (gran 0 is in use), JUMP to 5435H (FALEXT) with E = 1.
Original Source Code Comment: YES, EXIT
5411
RES 1,(HL) CB 8E
RESet bit 1 of the allocation byte at HL (gran 1).
Original Source Code Comment: TRY FOR 2ND GRAN
5413
LD E,04HLD E,4 1E 04
LET Register E = 04H, the first sector of gran 1.
Original Source Code Comment: SET FOR SECTOR 4
5415
BIT 1,A CB 4F
Test bit 1 of Register A: is gran 1 in use?
Original Source Code Comment: 2ND GRAN?
5417
If the NZ FLAG is set, JUMP to 5435H (FALEXT) with E = 4.
Original Source Code Comment: YES, EXIT
5419
RES 2,(HL) CB 96
RESet bit 2 of the allocation byte at HL (gran 2).
Original Source Code Comment: TRY FOR 3RD GRAN
541B
LD E,07HLD E,7 1E 07
LET Register E = 07H, the first sector of gran 2.
Original Source Code Comment: SET FOR SECTOR 7
541D
BIT 2,A CB 57
Test bit 2 of Register A: is gran 2 in use?
Original Source Code Comment: 3RD GRAN?
541F
If the NZ FLAG is set, JUMP to 5435H (FALEXT) with E = 7.
Original Source Code Comment: YES, EXIT
5421
RES 3,(HL) CB 9E
RESet bit 3 of the allocation byte at HL (gran 3).
Original Source Code Comment: TRY FOR 4TH GRAN
5423
LD E,0AHLD E,10 1E 0A
LET Register E = 0AH (10), the first sector of gran 3.
Original Source Code Comment: SET FOR SECTOR 10
5425
BIT 3,A CB 5F
Test bit 3 of Register A: is gran 3 in use?
Original Source Code Comment: 4TH GRAN?
5427
If the NZ FLAG is set, JUMP to 5435H (FALEXT) with E = 10.
Original Source Code Comment: YES, EXIT
5429
RES 4,(HL) CB A6
RESet bit 4 of the allocation byte at HL (gran 4).
Original Source Code Comment: TRY FOR 5TH GRAN
542B
LD E,0DHLD E,13 1E 0D
LET Register E = 0DH (13), the first sector of gran 4.
Original Source Code Comment: SET FOR SECTOR 13
542D
BIT 4,A CB 67
Test bit 4 of Register A: is gran 4 in use?
Original Source Code Comment: 5TH GRAN?
542F
If the NZ FLAG is set, JUMP to 5435H (FALEXT) with E = 13.
Original Source Code Comment: YES, EXIT
5431
RES 5,(HL) CB AE
RESet bit 5 of the allocation byte at HL (gran 5, the last one; the source: then it must be gran six).
Original Source Code Comment: THEN IT MUST BE GRAN SIX
5433
LD E,10HLD E,16 1E 10
LET Register E = 10H (16), the first sector of gran 5.
Original Source Code Comment: SET FOR SECTOR 16
5435FALEXT
LD D,L 55
FALEXT: LET Register D = Register L, the track number.
Original Source Code Comment: PUT THE TRACK NUMBER INTO D
5436
OR A B7
OR Register A with itself to clear the CARRY FLAG.
Original Source Code Comment: INSURE CARRY OFF
5437
RET C9
RETurn to MREAD with NC, Register D = the track and Register E = the first sector of the gran found.
Original Source Code Comment: DONE

5438H - MREAD - Fill the main buffer with the grans in use of the source. Exit: NC when the buffer is full, CARRY when the source has no more grans (FFH stored as the end mark).

5438MREAD
LD HL,6200HLD HL,BUFF 21 00 62
MREAD: LET Register Pair HL = 6200H (BUFF), the start of the main buffer.
Original Source Code Comment: HL => MAIN BUFFER
543B
LD (4E8CH),HLLD (BUFPNT),HL 22 8C 4E
Store it into 4E8CH-4E8DH (BUFPNT), the first gran record to fill.
Original Source Code Comment: INIT THE POINTER
543E
LD A,(4E81H)LD A,(BSIDES) 3A 81 4E
Fetch the source side number from 4E81H (BSIDES) into Register A.
Original Source Code Comment: GET THE SOURCE SIDE NUMBER
5441
LD (4463H),ALD (CSIDE),A 32 63 44
Store it into 4463H (CSIDE, the current side for SYS0's disk I/O).
Original Source Code Comment: SET IT IN DOS
5444MREAD1
MREAD1: GOSUB to 53FAH (FALOC) to find the next gran in use on the source: D = track, E = first sector, NC; or CARRY when there is none left.
Original Source Code Comment: GET A GRAN WITH SOMETHING ON IT
5447
If the CARRY FLAG is set (no gran left), JUMP to 545EH (MREAD3) to mark the end of the diskette.
Original Source Code Comment: IS END, SET END OF DISK MARKER
5449
LD A,D 7A
LET Register A = Register D, the track.
Original Source Code Comment: SEE IF BOOT TRACK
544A
ADD A,E 83
ADD Register E (the first sector) to Register A: the sum is 1 only for track 0, sector 1.
Original Source Code Comment: RESULT 'SHOULD' BE "1"
544B
CP 01HCP 1 FE 01
Compare Register A with 01H.
Original Source Code Comment: IS IT BOOT TRACK/SRCTOR?
544D
If the NZ FLAG is set (not the boot gran), JUMP to 5454H (MREAD2).
Original Source Code Comment: NO, CONTINUE
544F
GOSUB to 5257H (RBOOT) to read the boot gran into the first record and handle the backup counter.
Original Source Code Comment: READ IN THE BOOT AND CHECK COUNTER
5452
JUMP to 5457H (NXREAD).
Original Source Code Comment: AND DO THE NEXT GRAN

5454H - MREAD2 - Read the gran into the next record, then move on (NXREAD)

5454MREAD2
MREAD2: GOSUB to 517AH (RNEXT) to read the gran at track D, sector E, into the record at BUFPNT. RNEXT returns Z, or NZ with the error code in A; the result is not tested here.
Original Source Code Comment: READ IN THE NEXT GRAN
5457NXREAD
NXREAD: GOSUB to 53BAH (MEMCHK) to move BUFPNT to the next gran record: the CARRY FLAG is set when the buffer is full.
Original Source Code Comment: CHECK THE MEMORY FULL CONDITION
545A
If the NO CARRY FLAG is set (room for another gran), LOOP BACK to 5444H (MREAD1).
Original Source Code Comment: NO PROBLEM, DO NEXT GRAN
545C
OR A B7
OR Register A with itself to clear the CARRY FLAG: the buffer is full, the diskette is not finished.
Original Source Code Comment: INSURE CARRY OFF
545D
RET C9
RETurn to DOLOOP with NC.
Original Source Code Comment: EXIT

545EH - MREAD3 - Mark the end of the source in the next gran record (FFH) and return with CARRY

545EMREAD3
LD HL,(4E8CH)LD HL,(BUFPNT) 2A 8C 4E
MREAD3: Fetch the address of the next gran record from 4E8CH-4E8DH (BUFPNT) into Register Pair HL.
Original Source Code Comment: GET THE BUFFER POINTER
5461
LD (HL),0FFHLD (HL),-1 36 FF
Store FFH into its first byte (where the sector number would be): MWRIT stops there.
Original Source Code Comment: SET THE END OF DISK FLAG
5463
SCF 37
Set the CARRY FLAG (the end of the diskette).
Original Source Code Comment: INSURE CARRY SET
5464
RET C9
RETurn to DOLOOP with CARRY.

5465H - FWAIT - Flash the prompt at HL on its line until ENTER is pressed, then erase it

5465FWAIT
PUSH HL E5
FWAIT: Save Register Pair HL, the address of the prompt to flash, on the STACK.
Original Source Code Comment: SAVE TEXT POINTER
5466
GOSUB to 021BH (the ROM's PRINT routine) to show the prompt at HL (it starts with 1DH, start of the line).
Original Source Code Comment: DISPLAY THE TEXT
5469
POP HL E1
Restore Register Pair HL (the prompt) from the STACK.
Original Source Code Comment: GET POINTER BACK
546ALOOPY
LD BC,0256H 01 56 02
LOOPY: LET Register Pair BC = 0256H (598), the count of keyboard scans before the prompt is shown or hidden again.
Original Source Code Comment: TIME DELAY VALUE
546DLOOPX
LOOPX: GOSUB to 002BH (the ROM's KBD routine) to scan the keyboard: Register A = the key pressed, or 00H.
Original Source Code Comment: SCAN THE KEYBOARD
5470
CP 0DHCP 13 FE 0D
Compare Register A with 0DH (ENTER).
Original Source Code Comment: 'ENTER' KEY?
5472
If the Z FLAG is set (ENTER was pressed), JUMP to 5488H (LINOFF) to erase the prompt and return to the caller.
Original Source Code Comment: YES, EXIT AND TAKE MSG OFF SCREEN
5474
DEC BC 0B
DECrement Register Pair BC, the scans left.
Original Source Code Comment: DEC THE TIMER
5475
LD A,BCR BC 78
LET Register A = Register B.
5476
OR C B1
OR Register C into Register A: the Z FLAG is set when BC has reached 0000H.
5477
If the NZ FLAG is set (scans left), LOOP BACK to 546DH (LOOPX).
Original Source Code Comment: LOOP TILL TIMER RUNS OUT
5479
LD A,(4E83H)LD A,(FLAG) 3A 83 4E
The time is up: fetch 4E83H (FLAG, the state of the flashing) into Register A.
Original Source Code Comment: GET THE 'FLASH' FLAG
547C
XOR 01HXOR 1 EE 01
XOR Register A with 01H to flip bit 0.
Original Source Code Comment: FLIP TO OTHER STATE
547E
LD (4E83H),ALD (FLAG),A 32 83 4E
Store the new state into 4E83H (FLAG).
Original Source Code Comment: SAVE FOR NEXT TIME
5481
If the Z FLAG is set (FLAG became 00H), JUMP to 5465H (FWAIT) to show the prompt again.
Original Source Code Comment: IF Z, PRINT MSG AGAIN
5483
GOSUB to 5488H (LINOFF) to erase the prompt from the line.
Original Source Code Comment: BLANK OUT THE LINE ON THE SCREEN
5486
JUMP to 546AH (LOOPY) to start the count again with the line empty.
Original Source Code Comment: AND TIME AGAIN

5488H - LINOFF - Erase the line the cursor is on: 1DH (to the start of the line), then 1EH (erase to the end of the line)

5488LINOFF
LD A,1DHLD A,29 3E 1D
LINOFF: LET Register A = 1DH, the display code that moves the cursor to the start of the line.
Original Source Code Comment: MOVE TO BEG OF LINE CHAR
548A
GOSUB to 0033H (the ROM's display routine) to send it.
Original Source Code Comment: DISPLAY IT
548D
LD A,1EHLD A,30 3E 1E
LET Register A = 1EH, the display code that erases from the cursor to the end of the line.
Original Source Code Comment: ERASE TO END OF LINE CHAR
548F
JUMP to 0033H (the ROM's display routine) to send it; its RET returns to the caller of LINOFF.
Original Source Code Comment: DISPLAY IT AND RETURN

5492H - CKSRC / INSRC - On a backup with one drive, ask for the source diskette when the destination is in

5492CKSRC
LD A,(4E87H)LD A,(SINGLE) 3A 87 4E
CKSRC: Fetch 4E87H (SINGLE, the destination drive minus the source drive) into Register A.
Original Source Code Comment: SINGLE DRIVE BACKUP?
5495
OR A B7
OR Register A with itself to set the flags from SINGLE.
5496
RET NZ C0
If the NZ FLAG is set (the source and destination are different drives), RETurn: no diskette has to be changed.
Original Source Code Comment: NO, IS MULIT
5497
LD A,(4E7CH)LD A,(SDFLAG) 3A 7C 4E
Fetch 4E7CH (SDFLAG, 00H = the source diskette is in, FFH = the destination) into Register A.
Original Source Code Comment: GET THE SOURCE/DESTINATION FLAG
549A
OR A B7
OR Register A with itself to set the flags from SDFLAG.
Original Source Code Comment: SOURCE ALREADY IN?
549B
RET Z C8
If the Z FLAG is set (the source diskette is in already), RETurn.
Original Source Code Comment: YES, EXIT
549C
XOR A AF
Set Register A to 00H.
Original Source Code Comment: NO, SET FLAG TO SOURCE
549D
LD (4E7CH),ALD (SDFLAG),A 32 7C 4E
Store 00H into 4E7CH (SDFLAG): the source diskette goes in now.
54A0INSRC
LD HL,4EF7HLD HL,SRCMSG 21 F7 4E
INSRC: LET Register Pair HL = 4EF7H (SRCMSG), the prompt 'Insert SOURCE Diskette <ENTER>'.
Original Source Code Comment: HL => 'INSERT SOURCE' MSG
54A3
JUMP to 5465H (FWAIT) to flash it until ENTER is pressed; FWAIT returns to the caller of CKSRC.
Original Source Code Comment: FLASH IT AND WAIT

54A5H - CKDES / INDES - On a backup with one drive, ask for the destination diskette when the source is in

54A5CKDES
LD A,(4E87H)LD A,(SINGLE) 3A 87 4E
CKDES: Fetch 4E87H (SINGLE) into Register A.
Original Source Code Comment: SINGLE DRIVE BACKUP?
54A8
OR A B7
OR Register A with itself to set the flags from SINGLE.
54A9
RET NZ C0
If the NZ FLAG is set (two drives), RETurn: no diskette has to be changed.
Original Source Code Comment: NO, EXIT
54AA
LD A,(4E7CH)LD A,(SDFLAG) 3A 7C 4E
Fetch 4E7CH (SDFLAG) into Register A.
Original Source Code Comment: GET THE SOURCE DESTINATION FLAG
54AD
OR A B7
OR Register A with itself to set the flags from SDFLAG.
Original Source Code Comment: DESTINATION ALREADY IN?
54AE
RET NZ C0
If the NZ FLAG is set (the destination diskette is in already), RETurn.
Original Source Code Comment: YES, EXIT
54AF
LD A,0FFHLD A,-1 3E FF
LET Register A = FFH.
Original Source Code Comment: NO, SET FLAG FOR DEST
54B1
LD (4E7CH),ALD (SDFLAG),A 32 7C 4E
Store FFH into 4E7CH (SDFLAG): the destination diskette goes in now.
54B4INDES
LD HL,4F17HLD HL,DESMSG 21 17 4F
INDES: LET Register Pair HL = 4F17H (DESMSG), the prompt 'Insert DESTINATION Diskette <ENTER>'.
Original Source Code Comment: HL => 'INSERT DESTIN' MSG
54B7
JUMP to 5465H (FWAIT) to flash it until ENTER is pressed; FWAIT returns to the caller of CKDES.
Original Source Code Comment: FLASH IT AND WAIT

54B9H - DGAT - Read the GAT of the source into 6100H (and its allocation bytes into 6000H, SGAT), read the GAT of the destination, abort when a track holding data on the source is flawed on the destination, and put the destination's flaw table into the GAT copy

54B9DGAT
DGAT: GOSUB to 5492H (CKSRC) to have the source diskette put in when the backup uses one drive.
Original Source Code Comment: INSURE SOURCE DISK
54BC
LD A,(4E7EH)LD A,(FDRIVS) 3A 7E 4E
Fetch the source drive number from 4E7EH (FDRIVS) into Register A.
Original Source Code Comment: GET THE SOURCE DRIVE
54BF
LD C,A 4F
LET Register C = Register A, the drive for RDGAT.
Original Source Code Comment: INTO C
54C0
GOSUB to 4A93H (RDGAT in SYS0) to read the GAT (track 17, sector 1) of drive C into 4D00H (BUFF2). Returns Z, or NZ with the error code in A.
Original Source Code Comment: READ IN THE GAT
54C3
If the NZ FLAG is set (the read failed, A = the error code), JUMP to 4E00H (FATAL).
Original Source Code Comment: EXIT IF ERROR
54C6
LD HL,4D00HLD HL,BUFF2 21 00 4D
LET Register Pair HL = 4D00H (BUFF2), where RDGAT put the GAT of the source.
Original Source Code Comment: HL => WHERE GAT IS
54C9
PUSH HL E5
Save Register Pair HL (4D00H) on the STACK.
Original Source Code Comment: SAVE THE POINTER
54CA
LD DE,6100HLD DE,FGAT 11 00 61
LET Register Pair DE = 6100H (FGAT), the 256 byte copy of the source GAT that becomes the GAT of the destination.
Original Source Code Comment: DE => SOURCE GAT
54CD
LD BC,0100HLD BC,SECTOR 01 00 01
LET Register Pair BC = 0100H (256 bytes) for the LDIR.
Original Source Code Comment: NUMBER OF BYTES
54D0
LDIR ED B0
Copy the whole GAT from 4D00H to 6100H-61FFH (LDIR).
Original Source Code Comment: MOVE IT
54D2
POP HL E1
Restore Register Pair HL (4D00H) from the STACK.
Original Source Code Comment: GET GAT POINTER BACK
54D3
LD DE,6000HLD DE,SGAT 11 00 60
LET Register Pair DE = 6000H (SGAT), the copy of the allocation bytes that FALOC works through.
Original Source Code Comment: NEEED A COPY OF IT
54D6
LD BC,0029HLD BC,MAXTRK+1 01 29 00
LET Register Pair BC = 0029H (41, MAXTRK + 1) for the LDIR.
Original Source Code Comment: NUMBER OF BYTES
54D9
LDIR ED B0
Copy the first 41 bytes of the GAT (the allocation bytes of tracks 0-40) to 6000H-6028H (LDIR).
Original Source Code Comment: MOVE IT
54DB
GOSUB to 54A5H (CKDES) to have the destination diskette put in when the backup uses one drive.
Original Source Code Comment: INSURE DESTINATION DISK
54DE
LD A,(4E7FH)LD A,(FDRIVD) 3A 7F 4E
Fetch the destination drive number from 4E7FH (FDRIVD) into Register A.
Original Source Code Comment: GET THE DESTINATION DRIVE
54E1
LD C,A 4F
LET Register C = Register A, the drive for RDGAT.
Original Source Code Comment: INTO C
54E2
GOSUB to 4A93H (RDGAT in SYS0) to read the GAT of the destination into 4D00H. Returns Z, or NZ with the error code in A.
Original Source Code Comment: READ IN THE DESTINATION GAT
54E5
If the NZ FLAG is set (the read failed, A = the error code), JUMP to 4E00H (FATAL).
Original Source Code Comment: EXIT IF ERROR
54E8
LD HL,4D60HLD HL,BUFF2+FLAW 21 60 4D
LET Register Pair HL = 4D60H (BUFF2 + FLAW), the flaw table (offset 60H) of the destination GAT: FFH for each flawed track.
Original Source Code Comment: HL => DESTINATION GAT FLAW TABLE
54EB
LD DE,6100HLD DE,FGAT 11 00 61
LET Register Pair DE = 6100H (FGAT), the allocation bytes of the source GAT.
Original Source Code Comment: DE => SOURCE ALLOCATION
54EE
LD B,27HLD B,MAXTRK-1 06 27
LET Register B = 27H (39, MAXTRK minus 1), the tracks 0-38 to check, as the count for the DJNZ at 54FBH.
Original Source Code Comment: NUMBER OF TRACKS TO CHECK
54F0DGAT1
LD A,(DE) 1A
DGAT1: Fetch the allocation byte of the source track at DE into Register A.
Original Source Code Comment: IS THERE A FILE HERE?
54F1
OR A B7
OR Register A with itself: the Z FLAG is set when no gran of this track holds data on the source.
54F2
If the Z FLAG is set (track empty on the source), JUMP to 54F9H (DGAT2).
Original Source Code Comment: NO, CONTINUE
54F4
LD A,(HL) 7E
Fetch the flaw byte of the same track of the destination (at HL) into Register A.
Original Source Code Comment: IS THE DESTINATION FLAWED?
54F5
INC A 3C
INCrement Register A by 1: the Z FLAG is set only when the flaw byte was FFH (a flawed track).
54F6
If the Z FLAG is set (the destination track is flawed where the source holds data), JUMP to 4E4AH (ABRT): Operation ABORTED due to flaws on diskette.
Original Source Code Comment: YES, EXIT
54F9DGAT2
INC HL 23
DGAT2: INCrement Register Pair HL to the next flaw byte.
Original Source Code Comment: BUMP THE POINTERS
54FA
INC DE 13
INCrement Register Pair DE to the next allocation byte.
54FB
DECrement Register B (the tracks left) and, if it is not 0, LOOP BACK to 54F0H (DGAT1).
Original Source Code Comment: LOOP FOR COUNT
54FD
LD HL,4D60HLD HL,BUFF2+FLAW 21 60 4D
LET Register Pair HL = 4D60H (BUFF2 + FLAW), the flaw table of the destination.
Original Source Code Comment: HL => FLAW TABLE FOR DESTINATION DRIVE
5500
LD DE,6160HLD DE,FGAT+FLAW 11 60 61
LET Register Pair DE = 6160H (FGAT + FLAW), the flaw table of the GAT copy.
Original Source Code Comment: DE => FLAW TABLE TO BECOME DESTIN DRIVE
5503
LD BC,0028HLD BC,MAXTRK 01 28 00
LET Register Pair BC = 0028H (40, MAXTRK), one flaw byte per track.
Original Source Code Comment: MAX NUMBER OF TRACKS ON DISKETTE
5506
LDIR ED B0
Copy the 40 flaw bytes of the destination into the GAT copy (LDIR), so the GAT written to the destination keeps its own flaw table.
Original Source Code Comment: MOVE THE FLAW TABLE
5508
RET C9
RETurn to DOLLAR.
Original Source Code Comment: DONE

5509H - CKSYS / INSYS - Ask for a system diskette when DATDSK (550AH) was set by SETDAT

5509CKSYS
LD A,00HLD A,0 3E 00
CKSYS: LET Register A = 00H in the file. The operand at 550AH (DATDSK) becomes FFH when SETDAT (56ABH) finds that a backup involves drive 0 and a source diskette without SYS0.
Original Source Code Comment: FLAG HERE TO SHOW IF DATA DISK
550B
OR A B7
OR Register A with itself to set the flags from DATDSK.
550C
RET Z C8
If the Z FLAG is set (DATDSK 00H), RETurn: no prompt.
Original Source Code Comment: NO, EXIT
550DINSYS
LD A,0DHLD A,0DH 3E 0D
INSYS: LET Register A = 0DH (carriage return).
Original Source Code Comment: NEW LINE
550F
GOSUB to 0033H (the ROM's display routine) to start a new line.
5512
LD HL,4F3CHLD HL,SYSMSG 21 3C 4F
LET Register Pair HL = 4F3CH (SYSMSG), the prompt 'Insert SYSTEM Diskette <ENTER>'.
Original Source Code Comment: HL => 'INSERT SYSTEM' MSG
5515
JUMP to 5465H (FWAIT) to flash it until ENTER is pressed; FWAIT returns to the caller of CKSYS.

5518H - DOLLAR / DOLOOP - The backup: format the destination when needed, check the flaws, copy the grans in use buffer by buffer, then write the directory track with the new GAT

5518DOLLAR
LD A,0FHLD A,15 3E 0F
DOLLAR: LET Register A = 0FH, the display code that turns the cursor off.
Original Source Code Comment: TURN THE CURSOR OFF
551A
LD (5836H),ALD (BCKFLG),A 32 36 58
Store 0FH (not zero) into 5836H (BCKFLG), the operand of the LD A at 5835H in FOMAT: BACKUP is the caller, so FOMAT does not show 'Writing System Information' and CHKFOR asks whether to format again.
Original Source Code Comment: SET THE FLAG FOR BACKUP
551D
GOSUB to 0033H (the ROM's display routine) to send 0FH: the cursor goes off.
Original Source Code Comment: OUTPUT THE CURSOR CHAR
5520
GOSUB to 54A5H (CKDES) to have the destination diskette put in when the backup uses one drive.
Original Source Code Comment: INSERT DESTIN IF NECESSARY
5523
GOSUB to 56B1H (CHKFOR) to look at the destination: NZ when it has to be formatted first.
Original Source Code Comment: SEE IF DESTINATION NEEDS FORMATTING
5526
If the NZ FLAG is set, GOSUB to 5803H (FOMAT) to format the destination diskette.
Original Source Code Comment: IF SO, FORMAT IT
5529
GOSUB to 4E41H (RESTRY) to put the read and write retry counts of SYS0 back to 9.
Original Source Code Comment: RESET THE RETRY COUNTER
552C
GOSUB to 54B9H (DGAT) to read both GATs, check the destination flaws and build the GAT copies at 6000H and 6100H.
Original Source Code Comment: GET THE DESTINATION GAT
552FDOLOOP
DOLOOP: GOSUB to 5492H (CKSRC) to have the source diskette put in when the backup uses one drive.
Original Source Code Comment: PROMPT FOR SOURCE DISK IF SINGLE
5532
GOSUB to 5438H (MREAD) to read as many grans in use from the source as the buffer holds.
Original Source Code Comment: DO A BUFFER READ
5535
GOSUB to 54A5H (CKDES) to have the destination diskette put in when the backup uses one drive.
Original Source Code Comment: PROMPT FOR DESTIN DISK IF SINGLE
5538
GOSUB to 53D3H (MWRIT) to write and verify the grans in the buffer on the destination: CARRY when the end of the source was reached.
Original Source Code Comment: WRITE OUT THE BUFFER
553B
If the NO CARRY FLAG is set (the source has more grans), LOOP BACK to 552FH (DOLOOP).
Original Source Code Comment: CONTINUE IF NOT END OF DISK
553D
GOSUB to 5492H (CKSRC) to have the source diskette put in when the backup uses one drive.
Original Source Code Comment: PROMPT FOR SOURCE
5540
GOSUB to 52B4H (RDIR) to read the directory track of the source into the buffer, put in the destination's flaw table and take out the protected files when the counter was at 0.
Original Source Code Comment: READ IN THE DIRECTORY
5543
LD HL,6100HLD HL,FGAT 21 00 61
LET Register Pair HL = 6100H (FGAT), the allocation bytes of the GAT copy (with the grans of any file taken out released by RELEAS).
Original Source Code Comment: HL => SOURCE GAT
5546
LD DE,6202HLD DE,BUFF+2 11 02 62
LET Register Pair DE = 6202H (BUFF+2), the GAT in the buffer (the first sector of the directory track).
Original Source Code Comment: DE => DESTINATION GAT
5549
LD BC,0028HLD BC,MAXTRK 01 28 00
LET Register Pair BC = 0028H (40, MAXTRK), one allocation byte per track.
Original Source Code Comment: BC = NUMBER OF BYTES
554C
LDIR ED B0
Copy the 40 allocation bytes into the GAT in the buffer (LDIR).
Original Source Code Comment: MOVE THE MODIFIED GAT TO THE REAL GAT
554E
LD HL,4E90HLD HL,DATBUF 21 90 4E
LET Register Pair HL = 4E90H (DATBUF), today's date as MM/DD/YY.
Original Source Code Comment: HL => TODAY'S DATE
5551
LD DE,62DAHLD DE,BUFF+0DAH 11 DA 62
LET Register Pair DE = 62DAH (BUFF + 0DAH), offset D8H of the GAT in the buffer, where the date goes.
Original Source Code Comment: OFFSET TO THE DATE SLOT
5554
LD BC,0008HLD BC,8 01 08 00
LET Register Pair BC = 0008H (8 characters) for the LDIR.
Original Source Code Comment: NUMBER OF BYTES
5557
LDIR ED B0
Copy the date into the GAT in the buffer (LDIR).
Original Source Code Comment: MOVE IN THE DATE
5559
GOSUB to 54A5H (CKDES) to have the destination diskette put in when the backup uses one drive.
Original Source Code Comment: PROMPT FOR DESTINATION
555C
GOSUB to 52F2H (WDIR) to write and verify the whole directory track on the destination.
Original Source Code Comment: WRITE OUT THE DIRECTORY
555F
RET C9
RETurn to BPREP's caller, BACKP (5751H).
Original Source Code Comment: DONE

5560H - BPREP - Read the HIT of the source (a data diskette involving drive 0 sets DATDSK), clear the GAT copies, read the GAT of the source and check the master password

5560BPREP
BPREP: GOSUB to 5492H (CKSRC) to have the source diskette put in when the backup uses one drive.
Original Source Code Comment: INSERT SOURCE IF NECESSARY
5563
LD A,(4E7EH)LD A,(FDRIVS) 3A 7E 4E
Fetch the source drive number from 4E7EH (FDRIVS) into Register A.
Original Source Code Comment: GET THE SOURCE DRIVE
5566
LD C,A 4F
LET Register C = Register A, the drive for RDHIT.
Original Source Code Comment: INTO C
5567
GOSUB to 4ABAH (RDHIT in SYS0) to read the HIT (track 17, sector 2) of drive C into 4300H (BUFF1). Returns Z, or NZ with the error code in A.
Original Source Code Comment: READ IN THE HIT TABLE
556A
If the NZ FLAG is set (the read failed, A = the error code), JUMP to 4E00H (FATAL).
Original Source Code Comment: EXIT IF ERROR
556D
LD HL,(43E0H)LD HL,(BUFF1+0E0H) 2A E0 43
Fetch the two bytes at 43E0H-43E1H into Register Pair HL: offset E0H of the HIT, the system file pointer of SYS0 (track, gran byte); FFFFH when the diskette has no system.
Original Source Code Comment: GET SYS 0 EXTENT POINTER
5570
INC HL 23
INCrement Register Pair HL by 1: FFFFH becomes 0000H.
Original Source Code Comment: SEE IF DATA DISK
5571
LD A,H 7C
LET Register A = Register H.
5572
OR L B5
OR Register L into Register A: the Z FLAG is set when HL is 0000H (a data diskette).
5573
If the NZ FLAG is set (the source holds the system), JUMP to 5585H (BPREPX).
Original Source Code Comment: NO, IS SYSTEM DISK

The source has no SYS0 (a data diskette).

5575
LD A,(4E7EH)LD A,(FDRIVS) 3A 7E 4E
The source is a data diskette: fetch the source drive number from 4E7EH (FDRIVS) into Register A.
Original Source Code Comment: GET THE SOURCE DRIVE
5578
AND 03HAND 3 E6 03
MASK Register A with 03H (0000 0011): the Z FLAG is set for drive 0.
Original Source Code Comment: DRIVE 0?
557A
If the Z FLAG is set (the source is drive 0), GOSUB to 56ABH (SETDAT): at the end the operator is asked to put a system diskette back in drive 0.
Original Source Code Comment: YES, SET AS DATA DISK
557D
LD A,(4E7FH)LD A,(FDRIVD) 3A 7F 4E
Fetch the destination drive number from 4E7FH (FDRIVD) into Register A.
Original Source Code Comment: GET THE DESTINATION DRIVE
5580
AND 03HAND 3 E6 03
MASK Register A with 03H: the Z FLAG is set for drive 0.
Original Source Code Comment: DRIVE 0?
5582
If the Z FLAG is set (the destination is drive 0), GOSUB to 56ABH (SETDAT).
Original Source Code Comment: YES, SET AS DATA DISK
5585BPREPX
LD HL,6000HLD HL,SGAT 21 00 60
BPREPX: LET Register Pair HL = 6000H (SGAT).
Original Source Code Comment: POINT TO SOURCE GAT
5588
LD DE,6001HLD DE,SGAT+1 11 01 60
LET Register Pair DE = 6001H (SGAT+1), so the LDIR copies the cleared byte forward.
Original Source Code Comment: CLEAR IT AND DESTINATION GAT OUT
558B
LD BC,01FFHLD BC,(SECTOR*2)-1 01 FF 01
LET Register Pair BC = 01FFH (511) for the LDIR.
Original Source Code Comment: NUMBER OF BYTES
558E
LD (HL),00HLD (HL),0 36 00
Store 00H at 6000H.
Original Source Code Comment: CLEAR BYTE
5590
LDIR ED B0
Copy the 00H forward (LDIR): 6000H-61FFH (SGAT and FGAT) become 00H.
Original Source Code Comment: CLEAR IT OUT
5592
LD A,(4E7EH)LD A,(FDRIVS) 3A 7E 4E
Fetch the source drive number from 4E7EH (FDRIVS) into Register A.
Original Source Code Comment: GET THE SOURCE DRIVE AGAIN
5595
LD C,A 4F
LET Register C = Register A, the drive for RDGAT.
Original Source Code Comment: INTO C
5596
GOSUB to 4A93H (RDGAT in SYS0) to read the GAT of the source into 4D00H (BUFF2). Returns Z, or NZ with the error code in A.
Original Source Code Comment: READ IN THE GAT
5599
If the NZ FLAG is set (the read failed, A = the error code), JUMP to 4E00H (FATAL).
Original Source Code Comment: EXIT IF ERROR
559C
LD HL,(4DCEH)LD HL,(BUFF2+DPASS) 2A CE 4D
Fetch the two bytes at 4DCEH-4DCFH into Register Pair HL: offset CEH of the GAT (DPASS), the trap door code of the master password of the source.
Original Source Code Comment: GET THE PASSWORD FROM DISK
559F
LD DE,(4E88H)LD DE,(PTRAP) ED 5B 88 4E
Fetch the trap door code of the password typed from 4E88H-4E89H (PTRAP) into Register Pair DE.
Original Source Code Comment: GET THE ONE THE USER SUPPLIED
55A3
PUSH HLCD DE E5
Save Register Pair HL on the STACK; with the next three instructions this is the source's CD DE.
Original Source Code Comment: SEE IF SAME
55A4
OR A B7
OR Register A with itself to clear the CARRY FLAG for the SBC.
55A5
SBC HL,DE ED 52
SUBtract Register Pair DE (the code typed) from HL (the code of the diskette): the Z FLAG is set when they are the same.
55A7
POP HL E1
Restore Register Pair HL from the STACK; the flags of the SBC stay.
55A8
If the Z FLAG is set (the master password is right), JUMP to 55B3H (BPREP1).
Original Source Code Comment: YES, EXECUTE THE BACKUP
55AA
LD HL,5031HLD HL,INVPAS 21 31 50
LET Register Pair HL = 5031H (INVPAS), the text 'Invalid Master Password' and 0DH.
Original Source Code Comment: HL => 'INVALID PASSWORD'
55AD
GOSUB to 021BH (the ROM's PRINT routine) to show it.
Original Source Code Comment: DISPLAY IT
55B0
JUMP to 4E50H (EXIT) to end the backup and return to TRSDOS Ready.
Original Source Code Comment: DONE

55B3H - BPREP1 - The master password is right: show 'Source Drive n Destination Drive n' and run DOLLAR

55B3
LD A,(4E7EH)LD A,(FDRIVS) 3A 7E 4E
BPREP1: Fetch the source drive number from 4E7EH (FDRIVS) into Register A.
Original Source Code Comment: GET THE SOURCE DRIVE NUMBER
55B6
ADD A,30HADD A,'0' C6 30
ADD 30H ('0') to Register A to make the drive number a digit.
Original Source Code Comment: MAKE IT ASCII
55B8
LD (5152H),ALD (FDS),A 32 52 51
Store the digit into 5152H (FDS) in the message 'Source Drive n'.
Original Source Code Comment: SAVE IT IN MESSAGE
55BB
LD A,(4E7FH)LD A,(FDRIVD) 3A 7F 4E
Fetch the destination drive number from 4E7FH (FDRIVD) into Register A.
Original Source Code Comment: GET THE DESTINATION DRIVE NUMBER
55BE
ADD A,30HADD A,'0' C6 30
ADD 30H ('0') to Register A to make the drive number a digit.
Original Source Code Comment: MAKE IT ASCII
55C0
LD (516BH),ALD (FDD),A 32 6B 51
Store the digit into 516BH (FDD) in the message.
Original Source Code Comment: SAVE IT IN MESSAGE
55C3
LD HL,5145HLD HL,FDSMSG 21 45 51
LET Register Pair HL = 5145H (FDSMSG), the text 'Source Drive n Destination Drive n', 0AH, 0DH.
Original Source Code Comment: HL => 'SOURCE X, DESTIN X' MSG
55C6
GOSUB to 021BH (the ROM's PRINT routine) to show it.
Original Source Code Comment: DISPLAY IT
55C9
JUMP to 5518H (DOLLAR) to run the backup; DOLLAR's RET goes back to BACKP.
Original Source Code Comment: DO THE BACKUP

55CCH - GETSRC - Take the source drive from the command line (:d) or ask for it, check it against MAXDRV and store it in FDRIVS

55CCGETSRC
LD HL,(4E8AH)LD HL,(CSAVE) 2A 8A 4E
GETSRC: Fetch the command line pointer from 4E8AH-4E8BH (CSAVE) into Register Pair HL.
Original Source Code Comment: GET THE COMMAND LINE POINTER
55CF
LD A,(HL) 7E
Fetch the character at HL into Register A.
Original Source Code Comment: GET A BYTE FROM THE COMMAND LINE
55D0
CP 3AHCP ':' FE 3A
Compare Register A with 3AH (':'), the start of a drive given on the command line.
Original Source Code Comment: DRIVE SPECIFIER?
55D2
INC HL 23
INCrement Register Pair HL by 1 (the flags of the CP stay).
Original Source Code Comment: BUMP TO NEXT SLOT
55D3
PUSH HL E5
Save Register Pair HL (the pointer after the character) on the STACK.
Original Source Code Comment: SAVE THE POINTER
55D4
If the Z FLAG is set (the command line holds ':d'), JUMP to 55E0H (GETSR2) with HL at the drive digit.
Original Source Code Comment: YES, PICK UP DRIVE NUMBER
55D6
POP HL E1
Restore Register Pair HL from the STACK.
55D7GETSR1
PUSH HL E5
GETSR1: Save Register Pair HL (the command line pointer) on the STACK.
Original Source Code Comment: SAVE THE POINTER
55D8
LD HL,5049HLD HL,SDRV 21 49 50
LET Register Pair HL = 5049H (SDRV), the prompt 'SOURCE Drive Number? '.
Original Source Code Comment: HL => 'SOURCE DRIVE NO?' MSG
55DB
LD B,01HLD B,1 06 01
LET Register B = 01H, the longest answer (one character).
Original Source Code Comment: SET FOR 1 CHAR
55DD
GOSUB to 5645H (INPUT) to show the prompt and read the answer into 4EA1H (NAMBUF); HL returns at the answer.
Original Source Code Comment: DISPLAY AND GET THE ANSWER
55E0GETSR2
LD A,(HL) 7E
GETSR2: Fetch the character at HL (the drive digit from the command line or the answer) into Register A.
Original Source Code Comment: GET THE DRIVE NUMBER
55E1
POP HL E1
Restore Register Pair HL (the command line pointer) from the STACK.
Original Source Code Comment: GET POINTER BACK
55E2
SUB 30HSUB '0' D6 30
SUBtract 30H ('0') from Register A: a digit becomes 0-9.
Original Source Code Comment: MASK OFF THE ASCII
55E4
If the CARRY FLAG is set (the character is below '0'), JUMP to 55D7H (GETSR1) to ask again.
Original Source Code Comment: NOT A DIGIT, TRY AGAIN
55E6
LD C,A 4F
LET Register C = Register A, the drive number.
Original Source Code Comment: SAVE THE DRIVE NUMBER
55E7
LD A,(4413H)LD A,(MAXDRV) 3A 13 44
Fetch 4413H (MAXDRV, the highest drive number of the system) into Register A.
Original Source Code Comment: GET THE TOP DRIVE IN SYSTEM
55EA
CP C B9
Compare Register A with Register C: the CARRY FLAG is set when the drive number is above MAXDRV.
Original Source Code Comment: DOING A NON-EXISTANT DRIVE?
55EB
If the CARRY FLAG is set (no such drive), JUMP to 55D7H (GETSR1) to ask again.
Original Source Code Comment: YES, DO IT AGAIN
55ED
LD A,C 79
LET Register A = Register C, the drive number.
Original Source Code Comment: GET THE DRIVE NUMBER BACK
55EE
LD (4E7EH),ALD (FDRIVS),A 32 7E 4E
Store it into 4E7EH (FDRIVS), the source drive.
Original Source Code Comment: SET THE SOURCE DRIVE
55F1
INC HL 23
INCrement Register Pair HL by 1 (the source comment: to the space).
Original Source Code Comment: BUMP TO SPACE
55F2
INC HL 23
INCrement Register Pair HL by 1 (the next character), where GETDES looks for the destination drive.
Original Source Code Comment: BUMP TO NEXT CHAR
55F3
RET C9
RETurn to BACKP with Register Pair HL in the command line.
Original Source Code Comment: EXIT

55F4H - GETDES / GETDE3 - Take the destination drive from the command line (:d) or ask for it; GETDE3 stores it in FDRIVD, its select byte in FDRIVE and its difference to the source drive in SINGLE

55F4GETDES
LD A,(HL) 7E
GETDES: Fetch the character at HL (the command line, after the source drive) into Register A.
Original Source Code Comment: GET THE NEXT CHAR
55F5
CP 3AHCP ':' FE 3A
Compare Register A with 3AH (':').
Original Source Code Comment: DRIVE SPECIFIER?
55F7
INC HL 23
INCrement Register Pair HL by 1 (the flags of the CP stay).
Original Source Code Comment: BUMP TO NEXT SLOT
55F8
If the Z FLAG is set (':d' given), JUMP to 5602H (GETDE2) with HL at the drive digit.
Original Source Code Comment: YES, PICK UP THE DRIVE NUMBER
55FAGETDE1
LD HL,505FHLD HL,DDRV 21 5F 50
GETDE1: LET Register Pair HL = 505FH (DDRV), the prompt 'DESTINATION Drive Number? '.
Original Source Code Comment: HL => 'DESTIN DRIVE NO?' MSG
55FD
LD B,01HLD B,1 06 01
LET Register B = 01H, the longest answer (one character).
Original Source Code Comment: SET FOR 1 CHAR
55FF
GOSUB to 5645H (INPUT) to show the prompt and read the answer into 4EA1H (NAMBUF); HL returns at the answer.
Original Source Code Comment: DISPLAY AND GET ANSWER
5602GETDE2
LD A,(HL) 7E
GETDE2: Fetch the character at HL (the drive digit) into Register A.
Original Source Code Comment: GET THE DRIVE NUMBER
5603
SUB 30HSUB '0' D6 30
SUBtract 30H ('0') from Register A.
Original Source Code Comment: MASK OFF ASCII
5605
If the CARRY FLAG is set (not a digit), JUMP to 55FAH (GETDE1) to ask again.
Original Source Code Comment: NOT A DIGIT. TRY AGAIN
5607
LD C,A 4F
LET Register C = Register A, the drive number.
Original Source Code Comment: SAVE THE DRIVE NUMBER
5608
LD A,(4413H)LD A,(MAXDRV) 3A 13 44
Fetch 4413H (MAXDRV, the highest drive number) into Register A.
Original Source Code Comment: GET THE TOP DRIVE IN SYSTEM
560B
CP C B9
Compare Register A with Register C: the CARRY FLAG is set when the drive number is above MAXDRV.
Original Source Code Comment: DOING A NON-EXISTANT DRIVE?
560C
If the CARRY FLAG is set (no such drive), JUMP to 55FAH (GETDE1) to ask again.
Original Source Code Comment: YES, PLAY IT AGAIN SAM.
560EGETDE3
LD A,C 79
GETDE3: LET Register A = Register C, the destination drive number (also from GETFOR).
Original Source Code Comment: GET THE DRIVE NUMBE
560F
LD (4E7FH),ALD (FDRIVD),A 32 7F 4E
Store it into 4E7FH (FDRIVD), the destination drive.
Original Source Code Comment: SAVE AS DESTINATION DRIVE
5612
GOSUB to 45E9H (SITIT in SYS0) to turn the drive number in A into its select bit: Register A = 01H, 02H, 04H or 08H for drive 0-3.
Original Source Code Comment: MAKE IT A BIT PATTERN
5615
OR 80HOR DOUBLE F6 80
OR Register A with 80H (the source's DOUBLE), the double density bit of port F4H.
Original Source Code Comment: ADD IN THE DOUBLE DENSITY BIT
5617
LD (4E7DH),ALD (FDRIVE),A 32 7D 4E
Store the drive select byte into 4E7DH (FDRIVE) for the formatter.
Original Source Code Comment: SAVE FOR FORMATTER
561A
LD A,(4E7EH)LD A,(FDRIVS) 3A 7E 4E
Fetch the source drive number from 4E7EH (FDRIVS) into Register A.
Original Source Code Comment: GET THE SOURCE DRIVE
561D
LD B,A 47
LET Register B = Register A, the source drive.
Original Source Code Comment: INTO B
561E
LD A,(4E7FH)LD A,(FDRIVD) 3A 7F 4E
Fetch the destination drive number from 4E7FH (FDRIVD) into Register A.
Original Source Code Comment: GET THE DESTINATION DRIVE
5621
SUB B 90
SUBtract Register B (the source drive) from Register A: 00H when both are the same drive.
Original Source Code Comment: MAKE 'Z' OR 'NZ'
5622
LD (4E87H),ALD (SINGLE),A 32 87 4E
Store the difference into 4E87H (SINGLE): 00H = a backup on one drive.
Original Source Code Comment: SET THE SINGLE DRIVE FLAG
5625
RET C9
RETurn to the caller.

5626H - GETFOR - Take the drive to format from the command line (:d) or ask for it, then GETDE3

5626GETFOR
LD HL,(4E8AH)LD HL,(CSAVE) 2A 8A 4E
GETFOR: Fetch the command line pointer from 4E8AH-4E8BH (CSAVE) into Register Pair HL.
Original Source Code Comment: GET THE COMMAND LINE POINTER
5629
LD A,(HL) 7E
Fetch the character at HL into Register A.
Original Source Code Comment: GET THE NEXT CHAR
562A
INC HL 23
INCrement Register Pair HL by 1.
Original Source Code Comment: BUMP TO NEXT CHAR
562B
CP 3AHCP ':' FE 3A
Compare Register A with 3AH (':').
Original Source Code Comment: DRIVE SPECIFIER?
562D
If the Z FLAG is set (':d' given), JUMP to 5637H (GETFO2) with HL at the drive digit.
Original Source Code Comment: YES, PICK UP THE DRIVE NUMBER
562FGETFO1
LD HL,4FB1HLD HL,FDRV 21 B1 4F
GETFO1: LET Register Pair HL = 4FB1H (FDRV), the prompt 'Format Which Drive? '.
Original Source Code Comment: HL => 'FORMAT WHICH DRIVE' MSG
5632
LD B,01HLD B,1 06 01
LET Register B = 01H, the longest answer (one character).
Original Source Code Comment: SET FOR 1 CHAR
5634
GOSUB to 5645H (INPUT) to show the prompt and read the answer into 4EA1H (NAMBUF); HL returns at the answer.
Original Source Code Comment: DISPLAY AND GET ANSWER
5637GETFO2
LD A,(HL) 7E
GETFO2: Fetch the character at HL (the drive digit) into Register A.
Original Source Code Comment: GET THE DIGIT
5638
SUB 30HSUB '0' D6 30
SUBtract 30H ('0') from Register A.
Original Source Code Comment: MASK OFF ASCII
563A
If the CARRY FLAG is set (not a digit), JUMP to 562FH (GETFO1) to ask again.
Original Source Code Comment: WASN'T DIGIT. TRY AGAIN
563C
LD C,A 4F
LET Register C = Register A, the drive number.
Original Source Code Comment: SAVE THE DRIVE NUMBER
563D
LD A,(4413H)LD A,(MAXDRV) 3A 13 44
Fetch 4413H (MAXDRV, the highest drive number) into Register A.
Original Source Code Comment: GET TOP DRIVE IN SYSTEM
5640
CP C B9
Compare Register A with Register C: the CARRY FLAG is set when the drive number is above MAXDRV.
Original Source Code Comment: DOING A NON-EXISTANT DRIVE?
5641
If the CARRY FLAG is set (no such drive), JUMP to 562FH (GETFO1) to ask again.
Original Source Code Comment: YES, DO IT AGAIN
5643
JUMP to 560EH (GETDE3) to store the drive into FDRIVD, its select byte into FDRIVE and SINGLE.
Original Source Code Comment: FINISH UP THROUGH 'DESTIN'

5645H - INPUT - Show the prompt at HL and read up to B characters into NAMBUF (4EA1H). Exit: HL = NAMBUF, B = the number of characters typed; BREAK aborts.

5645INPUT
INPUT: GOSUB to 021BH (the ROM's PRINT routine) to show the prompt at HL.
Original Source Code Comment: DISPLAY THE MESSAGE
5648
LD HL,4EA1HLD HL,NAMBUF 21 A1 4E
LET Register Pair HL = 4EA1H (NAMBUF), the buffer for the answer.
Original Source Code Comment: SCRATCH PAD AREA
564B
GOSUB to 0040H (the ROM's KEYN routine) to read a line of up to B characters into HL. It returns HL at the buffer, B = the number of characters typed, and the CARRY FLAG set when BREAK was pressed.
Original Source Code Comment: GET THE ANSWER
564E
If the CARRY FLAG is set (BREAK), JUMP to 4030H (ABORT): Operation Aborted, TRSDOS Ready.
Original Source Code Comment: EXIT IF BREAK KEY
5651
RET C9
RETurn to the caller with HL at the answer and B its length.

5652H - GETPSF / GETPAS - Ask for the master password of the new diskette (FORMAT); GETPAS reads it and stores its trap door code in PTRAP

5652GETPSF
LD HL,5001HLD HL,PASMES 21 01 50
GETPSF: LET Register Pair HL = 5001H (PASMES), the prompt 'Master Password? ' of FORMAT.
Original Source Code Comment: HL => 'MASTER PW' MSG
5655
JUMP to 565AH (GETPAS).
Original Source Code Comment: GET THE PASSWORD

5657H - GETPSB - Ask for the master password of the source diskette (BACKUP)

5657GETPSB
LD HL,5013HLD HL,SPASS 21 13 50
GETPSB: LET Register Pair HL = 5013H (SPASS), the prompt 'SOURCE Disk Master Password? ' of BACKUP.
Original Source Code Comment: HL => 'SOURCE PW' MSG
565AGETPAS
LD B,08HLD B,8 06 08
GETPAS: LET Register B = 08H, the longest password.
Original Source Code Comment: SET FOR 8 CHARS
565C
GOSUB to 5645H (INPUT) to show the prompt and read the password into 4EA1H (NAMBUF): HL at it, B = its length.
Original Source Code Comment: PRINT AND GET ANSWER
565F
GOSUB to 57C3H (TRAP) to pad the password with spaces to 8 characters and compute its trap door code into Register Pair HL.
Original Source Code Comment: DO A TRAP DOOR CODE ON IT
5662
LD (4E88H),HLLD (PTRAP),HL 22 88 4E
Store the code (Register Pair HL) into 4E88H-4E89H (PTRAP).
Original Source Code Comment: SAVE THE CRUNCHED VALUE
5665
RET C9
RETurn to the caller.
Original Source Code Comment: DONE

5666H - GETNAM - Ask for the diskette name, pad it with spaces to 8 characters and put it into NAMEBF (4E98H)

5666GETNAM
LD HL,4FF1HLD HL,NAMMES 21 F1 4F
GETNAM: LET Register Pair HL = 4FF1H (NAMMES), the prompt 'Diskette Name? '.
Original Source Code Comment: HL => 'DISK NAME' MSG
5669
LD B,08HLD B,8 06 08
LET Register B = 08H, the longest name.
Original Source Code Comment: SET FOR 8 CHARS
566B
GOSUB to 5645H (INPUT) to show the prompt and read the name into 4EA1H (NAMBUF): HL at it, B = its length.
Original Source Code Comment: GET THE DISK ID
566E
LD A,08HLD A,8 3E 08
LET Register A = 08H, the length of the name field.
Original Source Code Comment: MAX NUMBER OF CHARS
5670
SUB B 90
SUBtract Register B (the characters typed) from Register A: A = the characters missing.
Original Source Code Comment: SEE HOW MANY ENTERED
5671
If the Z FLAG is set (8 characters typed), JUMP to 5683H (GETNA2).
Original Source Code Comment: ALL EIGHT. EXIT
5673
CP 08HCP 8 FE 08
Compare Register A with 08H: the Z FLAG is set when nothing was typed.
Original Source Code Comment: ANY ANSWER?
5675
If the Z FLAG is set (no name typed), JUMP to 5666H (GETNAM) to ask again.
Original Source Code Comment: NO, DO IT AGAIN
5677
PUSH HL E5
Save Register Pair HL (the start of the name) on the STACK.
Original Source Code Comment: SAVE THE POINTER
5678
LD E,A 5F
LET Register E = Register A, the number of spaces to add.
Original Source Code Comment: SAVE THE DIFFERENCE
5679
LD A,B 78
LET Register A = Register B, the characters typed.
Original Source Code Comment: GET THE COUNT
567A
ADD A,L 85
ADD Register L to Register A.
Original Source Code Comment: ADD TO THE LSB OF POINTER
567B
LD L,A 6F
LET Register L = Register A: HL points just past the last character typed (NAMBUF lies in one 256 byte page, so H needs no change).
Original Source Code Comment: HL => LAST CHAR +1 OF NAME
567C
LD B,E 43
LET Register B = Register E, the number of spaces to add, as the count for the DJNZ at 5680H.
Original Source Code Comment: GET THE DIFF BACK
567DGETNA1
LD (HL),20HLD (HL),' ' 36 20
GETNA1: Store 20H (a space) at HL.
Original Source Code Comment: PAD WITH SPACES
567F
INC HL 23
INCrement Register Pair HL by 1.
Original Source Code Comment: BUMP TO NEXT SLOT
5680
DECrement Register B and, if it is not 0, LOOP BACK to 567DH (GETNA1).
Original Source Code Comment: LOOP FOR COUNT
5682
POP HL E1
Restore Register Pair HL (the start of the name) from the STACK.
Original Source Code Comment: GET FRONT POINTER BACK
5683GETNA2
LD DE,4E98HLD DE,NAMEBF 11 98 4E
GETNA2: LET Register Pair DE = 4E98H (NAMEBF), where the diskette name is kept.
Original Source Code Comment: WHERE WE WANT IT
5686
LD BC,0008HLD BC,8 01 08 00
LET Register Pair BC = 0008H (8 characters) for the LDIR.
Original Source Code Comment: NUMBER OF CHARS
5689
LDIR ED B0
Copy the 8 characters of the name from NAMBUF to 4E98H-4E9FH (LDIR).
Original Source Code Comment: MOVE THE NAME
568B
RET C9
RETurn to FRMAT.

568CH - GETDAT - Put today's date (MM/DD/YY) into DATBUF (4E90H) through the ROM's DATE routine

568CGETDAT
LD HL,4E90HLD HL,DATBUF 21 90 4E
GETDAT: LET Register Pair HL = 4E90H (DATBUF), the 8 bytes for the date.
Original Source Code Comment: HL => PLACE TO STORE DATE
568F
GOSUB to 3033H (the ROM's DATE routine) to store today's date as MM/DD/YY at HL (taken from the clock bytes 421AH-421CH).
Original Source Code Comment: GET THE DATE FROM ROM
5692
RET C9
RETurn to the caller.
Original Source Code Comment: DONE

5693H - CLRGAT - Clear SGAT and FGAT (6000H-61FFH) and mark the boot gran (track 0) and the directory track (track 17) in the new GAT at 6100H

5693CLRGAT
LD HL,6000HLD HL,SGAT 21 00 60
CLRGAT: LET Register Pair HL = 6000H (SGAT).
Original Source Code Comment: HL => GAT
5696
LD DE,6001HLD DE,SGAT+1 11 01 60
LET Register Pair DE = 6001H (SGAT+1), so the LDIR copies the cleared byte forward.
5699
LD BC,01FFHLD BC,(SECTOR*2)-1 01 FF 01
LET Register Pair BC = 01FFH (511) for the LDIR.
Original Source Code Comment: NUMBER OF BYTES TO FILL
569C
LD (HL),00HLD (HL),0 36 00
Store 00H at 6000H.
Original Source Code Comment: FILL BYTE
569E
LDIR ED B0
Copy the 00H forward (LDIR): 6000H-61FFH (SGAT and FGAT) become 00H.
Original Source Code Comment: CLEAR IT OUT
56A0
LD A,01HLD A,1 3E 01
LET Register A = 01H: bit 0 = gran 0 of track 0, the gran of the boot sector.
Original Source Code Comment: SET THE BOOT ALLOCATION
56A2
LD (6100H),ALD (FGAT),A 32 00 61
Store 01H into 6100H (FGAT), the allocation byte of track 0 in the GAT FORMAT writes.
56A5
LD A,3FHLD A,USDTRK 3E 3F
LET Register A = 3FH (the source's USDTRK): bits 0-5 set, all 6 grans of a track in use.
Original Source Code Comment: SET THE DIRECTORY ALLOCATION
56A7
LD (6111H),ALD (FGAT+17),A 32 11 61
Store 3FH into 6111H (FGAT+17), the allocation byte of track 17, the directory track.
56AA
RET C9
RETurn to COMON.
Original Source Code Comment: DONE

56ABH - SETDAT - Set DATDSK (550AH) to FFH so CKSYS asks for a system diskette at the end

56ABSETDAT
LD A,0FFHLD A,-1 3E FF
SETDAT: LET Register A = FFH.
Original Source Code Comment: LOAD AN 'NZ' CHAR
56AD
LD (550AH),ALD (DATDSK),A 32 0A 55
Store FFH into 550AH (DATDSK), the operand of the LD A at 5509H in CKSYS, so CKSYS asks for a system diskette at the end.
Original Source Code Comment: SET THE FLAG
56B0
RET C9
RETurn to BPREP.

56B1H - CHKFOR - Look at the destination. Exit: NZ = format it (it cannot be read, or BACKUP was told Y), Z = use it as it is.

56B1CHKFOR
LD HL,4EE2HLD HL,ANALYZ 21 E2 4E
CHKFOR: LET Register Pair HL = 4EE2H (ANALYZ), the text 1DH 'Analyzing Diskette' 1DH.
Original Source Code Comment: HL => 'ANALYZING DISK' MSG
56B4
GOSUB to 021BH (the ROM's PRINT routine) to show it.
Original Source Code Comment: DISPLAY IT
56B7
LD A,(4E7FH)LD A,(FDRIVD) 3A 7F 4E
Fetch the destination drive number from 4E7FH (FDRIVD) into Register A.
Original Source Code Comment: GET THE DRIVE NUMBER
56BA
LD C,A 4F
LET Register C = Register A, the drive.
Original Source Code Comment: INTO C
56BB
PUSH BC C5
Save Register Pair BC (C = the drive) on the STACK.
Original Source Code Comment: SAVE THE DRIVE NUMBER
56BC
GOSUB to 4C6BH (CHKDRV in SYS0) to check that drive C exists and is ready. Returns Z, or NZ with the error code in A.
Original Source Code Comment: SEE IF THE DRIVE IS READY
56BF
POP BC C1
Restore Register Pair BC (C = the drive) from the STACK.
Original Source Code Comment: RESTORE THE DRIVE NUMBER
56C0
If the NZ FLAG is set (the drive is missing or not ready, A = the error code), JUMP to 4E00H (FATAL).
Original Source Code Comment: EXIT IF ERROR
56C3
PUSH BC C5
Save Register Pair BC (C = the drive) on the STACK.
Original Source Code Comment: SAVE THE DRIVE NUMBER
56C4
LD DE,0001HLD DE,1 11 01 00
LET Register Pair DE = 0001H: track 00H, sector 01H, the boot sector.
Original Source Code Comment: SET FOR TRACK 0, SECTOR 1
56C7
LD HL,0000HLD HL,0 21 00 00
LET Register Pair HL = 0000H as the buffer: the data read goes into the ROM and is not kept; only whether the read works counts.
Original Source Code Comment: READ INTO ROM
56CA
GOSUB to 4675H (XREAD in SYS0) to read the boot sector of drive C. Returns Z, or NZ with the error code in A.
Original Source Code Comment: TRY TO READ BOOT
56CD
POP BC C1
Restore Register Pair BC (C = the drive) from the STACK.
Original Source Code Comment: GET THE DRIVE NUMBER BACK
56CE
RET NZ C0
If the NZ FLAG is set (the diskette cannot be read, it is not formatted), RETurn to the caller with NZ: format it.
Original Source Code Comment: EXIT IF ERROR
56CF
PUSH BC C5
Save Register Pair BC (C = the drive) on the STACK.
Original Source Code Comment: SAVE DRIVE NUMBER
56D0
GOSUB to 4ABAH (RDHIT in SYS0) to read the HIT of drive C into 4300H (BUFF1). Returns Z, or NZ with the error code in A.
Original Source Code Comment: READ THE HASH TABLE
56D3
POP BC C1
Restore Register Pair BC (C = the drive) from the STACK.
56D4
RET NZ C0
If the NZ FLAG is set (the HIT cannot be read), RETurn with NZ: format it.
Original Source Code Comment: EXIT IF ERROR
56D5
GOSUB to 4AC2H (WRHIT in SYS0) to write the HIT at 4300H back to drive C: this fails on a write protected diskette. Returns Z, or NZ with the error code in A.
Original Source Code Comment: SEE IF DISKETTE IS WRITE PROTECTED
56D8
If the NZ FLAG is set (the write failed, A = the error code), JUMP to 4E00H (FATAL).
Original Source Code Comment: YES, EXIT
56DBCHKFO0
LD HL,4300HLD HL,BUFF1 21 00 43
CHKFO0: LET Register Pair HL = 4300H (BUFF1), the HIT just read.
Original Source Code Comment: HL => HIT TABLE
56DE
LD B,50HLD B,MAXFIL 06 50
LET Register B = 50H (80, MAXFIL), one HIT byte per directory record, as the count for the DJNZ at 56E5H.
Original Source Code Comment: NUMBER OF FILES ON DISK MAX
56E0
XOR A AF
Set Register A to 00H for the comparisons.
Original Source Code Comment: CLEAR FOR COMPARISON
56E1CHKFO1
CP (HL) BE
CHKFO1: Compare Register A (00H) with the HIT byte at HL: the NZ FLAG is set when a file is there.
Original Source Code Comment: THERE A HASH CODE HERE?
56E2
If the NZ FLAG is set (the diskette holds a file), JUMP to 56E9H (CHKFO2).
Original Source Code Comment: YES, HAS DATA
56E4
INC HL 23
INCrement Register Pair HL to the next HIT byte.
Original Source Code Comment: NO, BUMP TO NEXT GUY
56E5
DECrement Register B and, if it is not 0, LOOP BACK to 56E1H (CHKFO1).
Original Source Code Comment: LOOP FOR COUNT
56E7
No file on the diskette: JUMP to 56FFH (CHKFO3).
Original Source Code Comment: ASK IF REFORMAT. NO DATA

56E9H - CHKFO2 / CHKFO3 - The diskette holds files: N returns to TRSDOS Ready, Y or U go on; for BACKUP ask whether to format it again

56E9CHKFO2
LD HL,4FC6HLD HL,DDATA 21 C6 4F
CHKFO2: LET Register Pair HL = 4FC6H (DDATA), the prompt 'Diskette contains DATA. Use Disk or not? '.
Original Source Code Comment: HL => 'DISK HAS DATA' MSG
56EC
LD B,03HLD B,3 06 03
LET Register B = 03H, the longest answer.
Original Source Code Comment: SET FOR 3 CHARS
56EE
GOSUB to 5645H (INPUT) to show the prompt and read the answer into 4EA1H (NAMBUF): HL at it.
Original Source Code Comment: DISPLAY AND GET ANSWER
56F1
LD A,(HL) 7E
Fetch the first character of the answer into Register A.
Original Source Code Comment: GET THE ANSWER
56F2
CP 4EHCP 'N' FE 4E
Compare Register A with 4EH ('N').
Original Source Code Comment: NO?
56F4
If the Z FLAG is set (N: do not use the diskette), JUMP to 4E50H (EXIT) and return to TRSDOS Ready.
Original Source Code Comment: YES, ABORT THE OPERATION
56F7
CP 59HCP 'Y' FE 59
Compare Register A with 59H ('Y').
Original Source Code Comment: YES?
56F9
If the Z FLAG is set (Y), JUMP to 56FFH (CHKFO3).
Original Source Code Comment: YES, EXIT
56FB
CP 55HCP 'U' FE 55
Compare Register A with 55H ('U').
Original Source Code Comment: USE?
56FD
If the NZ FLAG is set (not N, Y or U), JUMP to 56E9H (CHKFO2) to ask again. U falls into CHKFO3 like Y.
Original Source Code Comment: NO, DO IT AGAIN
56FFCHKFO3
LD A,(5836H)LD A,(BCKFLG) 3A 36 58
CHKFO3: Fetch 5836H (BCKFLG, the operand of the LD A at 5835H) into Register A: 0FH when BACKUP called (DOLLAR stores it), 00H for FORMAT.
Original Source Code Comment: IS THIS BACKUP CALLING
5702
OR A B7
OR Register A with itself to set the flags from BCKFLG.
5703
RET Z C8
If the Z FLAG is set (FORMAT is the caller), RETurn with Z. FRMAT formats the diskette whatever CHKFOR returns.
Original Source Code Comment: NO, EXIT
5704
LD HL,511DHLD HL,REFORM 21 1D 51
LET Register Pair HL = 511DH (REFORM), the prompt 'Do you wish to RE-FORMAT the diskette? '.
Original Source Code Comment: HL => 'WANT TO RE-FORMAT' MSG
5707
LD B,03HLD B,3 06 03
LET Register B = 03H, the longest answer.
Original Source Code Comment: SET FOR 3 CHARS
5709
GOSUB to 5645H (INPUT) to show the prompt and read the answer into 4EA1H (NAMBUF): HL at it.
Original Source Code Comment: DISPLAY AND GET ANSWER
570C
LD A,(HL) 7E
Fetch the first character of the answer into Register A.
Original Source Code Comment: GET THE ANSWER
570D
CP 59HCP 'Y' FE 59
Compare Register A with 59H ('Y').
Original Source Code Comment: YES?
570F
If the Z FLAG is set (Y), JUMP to 5712H (CHKFO4) with A = 59H, so the OR A gives NZ: format the destination.
Original Source Code Comment: YES, EXIT
5711
XOR A AF
Any other answer: set Register A to 00H, so the OR A gives Z: do not format.
Original Source Code Comment: NO, SET 'Z'
5712CHKFO4
OR A B7
CHKFO4: OR Register A with itself: NZ = format the diskette, Z = use it as it is.
Original Source Code Comment: SET 'Z' OR 'NZ'
5713
RET C9
RETurn to DOLLAR.

5714H - DOTITL - Clear the screen and show 'TRSDOS Model III ', the text at HL and ' Ver 1.3'

5714DOTITL
PUSH HL E5
DOTITL: Save Register Pair HL, the middle part of the title ('Backup Utility' or 'Disk Formatter'), on the STACK.
Original Source Code Comment: SAVE THE MIDDLE PART
5715
GOSUB to 01C9H (the ROM's CLS routine) to clear the screen.
Original Source Code Comment: CLEAR THE SCREEN
5718
LD HL,4F76HLD HL,TITLE1 21 76 4F
LET Register Pair HL = 4F76H (TITLE1), the text 'TRSDOS Model III '.
Original Source Code Comment: HL => FRONT PART
571B
GOSUB to 021BH (the ROM's PRINT routine) to show it.
Original Source Code Comment: DISPLAY IT
571E
POP HL E1
Restore Register Pair HL (the middle part) from the STACK.
Original Source Code Comment: GET THE MIDDLE PART
571F
GOSUB to 021BH (the ROM's PRINT routine) to show it.
Original Source Code Comment: DISPLAY IT
5722
LD HL,4F88HLD HL,TITLE2 21 88 4F
LET Register Pair HL = 4F88H (TITLE2), the text ' Ver 1.3', 0AH, 0DH.
Original Source Code Comment: GET THE TAIL END
5725
JUMP to 021BH (the ROM's PRINT routine) to show it; its RET returns to the caller of DOTITL.
Original Source Code Comment: DISPLAY AND RETURN

5728H - COMON - Save the command line pointer, set MEMTOP to MEMEND minus 768 and clear the GAT copies (both FORMAT and BACKUP)

5728COMON
LD (4E8AH),HLLD (CSAVE),HL 22 8A 4E
COMON: Store Register Pair HL, the command line pointer BEGIN was entered with, into 4E8AH-4E8BH (CSAVE).
Original Source Code Comment: SAVE THE COMMAND LINE POINTER
572B
LD HL,(4411H)LD HL,(MEMEND) 2A 11 44
Fetch the end of memory from 4411H-4412H (MEMEND in SYS0) into Register Pair HL.
Original Source Code Comment: GET THE END OF MEMORY
572E
LD DE,0FD00HLD DE,-(SECTOR*DGRAN) 11 00 FD
LET Register Pair DE = FD00H (minus 768, the bytes of a gran).
Original Source Code Comment: BREATHING ROOM
5731
ADD HL,DE 19
ADD Register Pair DE to HL: HL = MEMEND minus 768.
5732
LD (4E8EH),HLLD (MEMTOP),HL 22 8E 4E
Store it into 4E8EH-4E8FH (MEMTOP), the highest address where a gran record may start in the main buffer.
Original Source Code Comment: SET THE INTERNAL TOP OF MEMORY
5735
GOSUB to 5693H (CLRGAT) to clear 6000H-61FFH and mark the boot gran and the directory track in the new GAT at 6100H.
Original Source Code Comment: CLEAR OUT THE DUMMY GAT
5738
RET C9
RETurn to the caller.
Original Source Code Comment: EXIT

5739H - BACKP - The BACKUP command

5739BACKP
BACKP: GOSUB to 5728H (COMON) to save the command line pointer, set MEMTOP and clear the GAT copies.
Original Source Code Comment: DO THE COMMON STUFF
573C
LD HL,4F93HLD HL,BMSG 21 93 4F
LET Register Pair HL = 4F93H (BMSG), the text 'Backup Utility'.
Original Source Code Comment: HL => 'BACKUP UTILITY' MSG
573F
GOSUB to 5714H (DOTITL) to clear the screen and show 'TRSDOS Model III Backup Utility Ver 1.3'.
Original Source Code Comment: DISPLAY IT
5742
GOSUB to 568CH (GETDAT) to put today's date into 4E90H (DATBUF).
Original Source Code Comment: GET THE DATE
5745
GOSUB to 55CCH (GETSRC) to take the source drive from the command line or ask for it.
Original Source Code Comment: GET THE SOURCE DRIVE
5748
GOSUB to 55F4H (GETDES) to take the destination drive from the command line or ask for it.
Original Source Code Comment: GET THE DESTINATION
574B
GOSUB to 5657H (GETPSB) to ask for the master password of the source diskette and store its code into PTRAP.
Original Source Code Comment: GET THE SOURCE MASTER PW
574E
GOSUB to 5560H (BPREP) to check the source diskette and its password and run the backup.
Original Source Code Comment: DO THE BACKUP
5751
LD A,0DHLD A,0DH 3E 0D
LET Register A = 0DH (carriage return).
Original Source Code Comment: NEW LINE
5753
GOSUB to 0033H (the ROM's display routine) to start a new line.
5756
LD HL,4F5CHLD HL,BCOMP 21 5C 4F
LET Register Pair HL = 4F5CH (BCOMP), the text ' ** Backup Complete **' and 0DH.
Original Source Code Comment: HL => 'BACKUP COMPLETE'
5759
GOSUB to 021BH (the ROM's PRINT routine) to show it.
Original Source Code Comment: DISPLAY IT
575C
GOSUB to 5509H (CKSYS) to ask for a system diskette in drive 0 when SETDAT asked for it.
Original Source Code Comment: INSERT SYSTEM DISK
575F
JUMP to 4E50H (EXIT) to show the GEORGE messages when files were taken out and return to TRSDOS Ready.
Original Source Code Comment: DONE

5762H - FRMAT - The FORMAT command

5762FRMAT
FRMAT: GOSUB to 5728H (COMON) to save the command line pointer, set MEMTOP and clear the GAT copies.
Original Source Code Comment: DO THE COMMON PREP WORK
5765
LD HL,4FA2HLD HL,FMSG 21 A2 4F
LET Register Pair HL = 4FA2H (FMSG), the text 'Disk Formatter'.
Original Source Code Comment: HL => 'DISK FORMATTER' MSG
5768
GOSUB to 5714H (DOTITL) to clear the screen and show 'TRSDOS Model III Disk Formatter Ver 1.3'.
Original Source Code Comment: DISPLAY IT
576B
GOSUB to 568CH (GETDAT) to put today's date into 4E90H (DATBUF).
Original Source Code Comment: GET THE DATE
576E
GOSUB to 5626H (GETFOR) to take the drive from the command line or ask for it.
Original Source Code Comment: GET THE DISK TO FORMAT
5771
GOSUB to 5666H (GETNAM) to ask for the diskette name and put it into 4E98H (NAMEBF).
Original Source Code Comment: GET THE DISKETTE NAME
5774
GOSUB to 5652H (GETPSF) to ask for the master password and store its code into PTRAP.
Original Source Code Comment: GET THE DISKETTE PASSWORD
5777
GOSUB to 56B1H (CHKFOR) to check the drive and ask what to do when the diskette holds files (N returns to TRSDOS Ready).
Original Source Code Comment: SEE IF DISK HAS DATA
577A
LD HL,4E98HLD HL,NAMEBF 21 98 4E
LET Register Pair HL = 4E98H (NAMEBF), the diskette name.
Original Source Code Comment: HL => DISK NAME
577D
LD DE,61D0HLD DE,FGAT+DID 11 D0 61
LET Register Pair DE = 61D0H (FGAT + DID), offset D0H of the new GAT, where the diskette name goes.
Original Source Code Comment: DE => WHERE DISK ID GOES
5780
PUSH DE D5
Save Register Pair DE (61D0H) on the STACK.
Original Source Code Comment: SAVE THE POINTER
5781
LD BC,0008HLD BC,8 01 08 00
LET Register Pair BC = 0008H (8 characters) for the LDIR.
Original Source Code Comment: NUMBER OF BYTES
5784
LDIR ED B0
Copy the name into the GAT at 61D0H-61D7H (LDIR); DE ends at 61D8H.
Original Source Code Comment: MOVE THE NAME
5786
LD HL,4E90HLD HL,DATBUF 21 90 4E
LET Register Pair HL = 4E90H (DATBUF), the date MM/DD/YY.
Original Source Code Comment: WHERE THE DATE GOES
5789
LD BC,0008HLD BC,8 01 08 00
LET Register Pair BC = 0008H (8 characters) for the LDIR.
Original Source Code Comment: NUMBER OF BYTES
578C
LDIR ED B0
Copy the date into the GAT at 61D8H-61DFH (offset D8H) (LDIR).
Original Source Code Comment: MOVE IT
578E
POP HL E1
Restore Register Pair HL (61D0H) from the STACK.
Original Source Code Comment: GET THE ID POINTER BACK
578F
DEC HL 2B
DECrement Register Pair HL by 1.
Original Source Code Comment: BACK UP TO THE PW SLOT
5790
DEC HL 2B
DECrement Register Pair HL by 1: HL = 61CEH, offset CEH of the GAT (DPASS), the master password field.
5791
LD DE,(4E88H)LD DE,(PTRAP) ED 5B 88 4E
Fetch the code of the master password typed from 4E88H-4E89H (PTRAP) into Register Pair DE.
Original Source Code Comment: PICK UP THE MASTER PW TRAP CODE
5795
LD (HL),ELD (HL),DE 73
Store Register E (the low byte of the code) at 61CEH.
Original Source Code Comment: STORE IT
5796
INC HL 23
INCrement Register Pair HL by 1.
5797
LD (HL),D 72
Store Register D (the high byte of the code) at 61CFH.
5798
GOSUB to 5803H (FOMAT) to format the diskette and write the boot sector, the system sector, the GAT, the HIT and the directory.
Original Source Code Comment: DO THE FORMAT
579B
GOSUB to 5509H (CKSYS) to ask for a system diskette when DATDSK is set (the source comment: see if drive 0 for the format). The release file has CALL 5138H here (CD 38 51, the zap of the zaps page), the code it put at 5138H in REFORM: LD A,(4E7DH) / CP 81H / JP Z,550DH / RET, which asks for the system diskette when the drive formatted was drive 0 (FDRIVE 81H).
Original Source Code Comment: SEE IF DRIVE 0 FOR THE FORMAT
579E
JUMP to 4E50H (EXIT) to return to TRSDOS Ready.
Original Source Code Comment: DONE

57A1H - BEGIN - The entry point of SYS7 (SYSLD jumps here with A = A7H for FORMAT, vector 429FH, or 97H for BACKUP, vector 42A2H, and HL at the command line)

57A1BEGIN
PUSH HL E5
BEGIN: Save Register Pair HL, the command line pointer (after the command name), on the STACK. SYSLD enters SYS7 here with Register A = A7H for FORMAT (vector 429FH) or 97H for BACKUP (vector 42A2H).
Original Source Code Comment: SAVE THE COMMAND LINE POINTER
57A2
LD HL,442BHLD HL,OVLFLG 21 2B 44
LET Register Pair HL = 442BH (OVLFLG, the overlay flags of SYS0).
Original Source Code Comment: HL => SYSTEM OVERLAY FLAGS
57A5
RES 4,(HL) CB A6
RESet bit 4 of OVLFLG: SYS6 is no longer resident, since SYS7 is loaded over its memory (4E00H-5D71H and the buffers above).
Original Source Code Comment: SHOW 'SYS6' NOT RES
57A7
POP HL E1
Restore Register Pair HL (the command line pointer) from the STACK.
Original Source Code Comment: GET COMMAND LINE POINTER BACK
57A8
PUSH AF F5
Save Register Pair AF (Register A = the request code) on the STACK.
Original Source Code Comment: SAVE THE SYSTEM VECTOR
57A9
LD A,55H 3E 55
LET Register A = 55H.
Original Source Code Comment: SET THE 'CLEAR RAM' FLAG
57AB
LD (42B4H),ALD (CFLAG),A 32 B4 42
Store 55H into 42B4H (CFLAG): SYS1 clears the user memory from 5200H to MEMEND at the next TRSDOS Ready, since SYS7 uses it for its buffers.
57AE
LD A,02HLD A,BCKTRY 3E 02
LET Register A = 02H (the source's BCKTRY), fewer retries for FORMAT and BACKUP.
Original Source Code Comment: LOWER THE RETRY COUNT
57B0
LD (467DH),ALD (TRY1),A 32 7D 46
Store 02H into 467DH (TRY1), the read retry count of SYS0's XREAD.
57B3
LD (460AH),ALD (TRY2),A 32 0A 46
Store 02H into 460AH (TRY2), the write retry count of SYS0's XWRITE.
57B6
POP AF F1
Restore Register Pair AF (Register A = the request code) from the STACK.
57B7
AND 0F0HAND 0F0H E6 F0
MASK Register A with F0H (1111 0000) to keep bits 7-4, the entry in the overlay (the SYS number in bits 3-0 goes).
Original Source Code Comment: MASK OFF SYSTEM NUMBER
57B9
CP 0A0HCP VECT20 FE A0
Compare Register A with A0H (the source's VECT20, entry 2).
Original Source Code Comment: FORMAT?
57BB
If the Z FLAG is set (FORMAT), JUMP to 5762H (FRMAT).
Original Source Code Comment: YES, DO IT
57BD
CP 90HCP VECT10 FE 90
Compare Register A with 90H (VECT10, entry 1).
Original Source Code Comment: BACKUP?
57BF
If the Z FLAG is set (BACKUP), JUMP to 5739H (BACKP).
Original Source Code Comment: YES, DO IT
57C2
RET C9
Any other entry: RETurn (the source: nothing supported).
Original Source Code Comment: EXIT. NOTHING SUPPORTED

57C3H - TRAP - Pad the password at HL (B characters) with spaces to 8 and compute its trap door code into HL (never 0000H)

57C3TRAP
EX DE,HL EB
TRAP: EXchange Register Pairs DE and HL. On entry HL points at the password typed (NAMBUF, 4EA1H) and Register B holds its length (0-8); now DE points at it.
57C4
LD H,D 62
LET Register H = Register D, the high byte of the password's address.
57C5
LD A,B 78
LET Register A = Register B, the length typed.
57C6
ADD A,E 83
ADD Register E (the low byte of the password's address) to Register A.
57C7
LD L,A 6F
LET Register L = Register A: HL points just past the last character typed.
57C8
LD A,08HLD A,8 3E 08
LET Register A = 08H, the length of a password field.
57CA
SUB B 90
SUBtract Register B (the length typed) from Register A: A = the number of spaces to add.
57CB
If the Z FLAG is set (8 characters typed), JUMP to 57D3H (NOSPC).
57CD
LD B,A 47
LET Register B = Register A, the number of spaces, as the count for the DJNZ at 57D1H.
57CEFILSPC
LD (HL),20HLD (HL),' ' 36 20
FILSPC: Store 20H (a space) at HL.
57D0
INC HL 23
INCrement Register Pair HL by 1.
57D1
DECrement Register B and, if it is not 0, LOOP BACK to 57CEH (FILSPC): the password is now 8 characters with spaces at the end.

57D3H - NOSPC / SETTD2 - The trap door code of the 8 characters at DE, taken from the last to the first

57D3NOSPC
LD HL,0FFFFHLD HL,-1 21 FF FF
NOSPC: LET Register Pair HL = FFFFH, the starting value of the trap door code.
57D6
LD B,08HLD B,8 06 08
LET Register B = 08H, the 8 characters, as the count for the DJNZ at 57FCH.
57D8
LD A,E 7B
LET Register A = Register E, the low byte of the password's address.
57D9
ADD A,07HADD A,7 C6 07
ADD 07H to Register A, to the address of the last (eighth) character.
57DB
LD E,A 5F
LET Register E = Register A.
57DC
If the NO CARRY FLAG is set (no carry out of the low byte), JUMP to 57DFH (SETTD2).
57DE
INC D 14
INCrement Register D by 1 for the carry: DE points at the eighth character.
57DFSETTD2
LD A,(DE) 1A
SETTD2: Fetch the character at DE into Register A (the characters are taken from the last to the first).
57E0
PUSH DE D5
Save Register Pair DE (the address of the character) on the STACK.
57E1
LD D,A 57
LET Register D = Register A, the character.
57E2
LD E,H 5C
LET Register E = Register H, the high byte of the code so far: DE = character times 256 plus the high byte.
57E3
LD A,L 7D
LET Register A = Register L, the low byte of the code so far.
57E4
AND 07HAND 7 E6 07
MASK Register A with 07H to keep bits 2-0.
57E6
RRCA 0F
Rotate Register A right (RRCA); three of these move bits 2-0 into bits 7-5.
57E7
RRCA 0F
Rotate Register A right again.
57E8
RRCA 0F
Rotate Register A right a third time.
57E9
XOR L AD
XOR Register L (the low byte of the code) into Register A.
57EA
LD L,A 6F
LET Register L = Register A.
57EB
LD H,00HLD H,0 26 00
LET Register H = 00H: HL = that byte.
57ED
SBC HL,DE ED 52
SUBtract Register Pair DE and the CARRY FLAG (clear after the XOR) from HL.
57EF
ADD HL,HL 29
ADD Register Pair HL to itself (HL times 2).
57F0
ADD HL,HL 29
ADD Register Pair HL to itself again (HL times 4).
57F1
XOR H AC
XOR Register H (the high byte of HL times 4) into Register A (the byte computed at 57E9H).
57F2
XOR D AA
XOR Register D (the character) into Register A.
57F3
LD D,A 57
LET Register D = Register A, the new high byte of the code.
57F4
LD A,L 7D
LET Register A = Register L, the low byte of HL times 4.
57F5
ADD HL,HL 29
ADD Register Pair HL to itself (HL times 8).
57F6
XOR H AC
XOR Register H (the high byte of HL times 8) into Register A.
57F7
XOR E AB
XOR Register E (the old high byte of the code) into Register A.
57F8
LD E,A 5F
LET Register E = Register A, the new low byte of the code.
57F9
EX DE,HL EB
EXchange Register Pairs DE and HL: HL = the new trap door code.
57FA
POP DE D1
Restore Register Pair DE (the address of the character) from the STACK.
57FB
DEC DE 1B
DECrement Register Pair DE by 1 to the character before it.
57FC
DECrement Register B and, if it is not 0, LOOP BACK to 57DFH (SETTD2) for the next character.
57FE
LD A,H 7C
LET Register A = Register H.
57FF
OR L B5
OR Register L into Register A: the Z FLAG is set when the code is 0000H.
5800
RET NZ C0
If the NZ FLAG is set, RETurn with the trap door code in Register Pair HL.
5801
INC L 2C
The code came out 0000H: INCrement Register L by 1, so the code is 0001H (a code is never 0000H).
5802
RET C9
RETurn with the trap door code in Register Pair HL.

5803H - FOMAT - Format the destination: Restore to track 0, FORM, Restore again, then BOTWRI

5803FOMAT
XOR A AF
FOMAT: Set Register A to 00H.
Original Source Code Comment: CLEAR A
5804
LD (5BD3H),ALD (DDTRK),A 32 D3 5B
Store 00H into 5BD3H (DDTRK), the track number byte of the track building table, before the first track.
Original Source Code Comment: SET TRACK AT 0
5807
LD A,(4E7DH)LD A,(FDRIVE) 3A 7D 4E
Fetch the drive select byte from 4E7DH (FDRIVE: the drive's bit and 80H for double density) into Register A.
Original Source Code Comment: GET DRIVE NUMBER
580A
GOSUB to 44E0H (DSEL0 in SYS0) to send Register A to port F4H, the drive select latch: the drive is selected and its motor started.
Original Source Code Comment: OUTPUT TO DRIVE SELECT
580D
LD A,0CHLD A,RSTORE 3E 0C
LET Register A = 0CH (the source's RSTORE): the FDC's Restore command (bits 7-4 0000) with bit 3 (load the head) and bit 2 (verify the track) set and bits 1-0 00 (step rate 6 ms).
Original Source Code Comment: TELL CONTROLLER TO RESTORE TO TRK 0
580F
OUTput 0CH to port F0H, the FDC command register: the head moves out to track 0.
5811
GOSUB to 4404H (SDELAY in SYS0), a short delay so the FDC can take the command.
Original Source Code Comment: STALL TIME
5814
LD B,05H 06 05
Code in the shipped file that the source text does not have: LET Register B = 05H as the count for the DJNZ at 5822H.
5816
INput the FDC status from port F0H into Register A.
5818
BIT 1,A CB 4F
Test bit 1 of the status (the index pulse during a Type I command such as Restore).
581A
If the Z FLAG is set (no index pulse at the moment), LOOP BACK to 5816H to read the status again.
581C
LD A,(4E7DH) 3A 7D 4E
Fetch the drive select byte from 4E7DH (FDRIVE) into Register A.
581F
GOSUB to 44E0H (DSEL0) to send it to port F4H again, so the drive stays selected and its motor running.
5822
DECrement Register B and, if it is not 0, LOOP BACK to 5816H: the loop ends after the index bit was found set five times, so the drive is turning a diskette before formatting starts.
5824L1OOP
L1OOP: INput the FDC status from port F0H into Register A.
Original Source Code Comment: SEE IF FDC AT TRACK 0
5826
BIT 2,A CB 57
Test bit 2 of the status (the head is at track 0).
5828
If the NZ FLAG is set (track 0 reached), JUMP to 5832H (L2OOP).
Original Source Code Comment: YES, GOT THERE
582A
LD A,(4E7DH)LD A,(FDRIVE) 3A 7D 4E
Fetch the drive select byte from 4E7DH (FDRIVE) into Register A.
Original Source Code Comment: NO, SO KEEP DRIVE SELECTED
582D
GOSUB to 44E0H (DSEL0) to send it to port F4H again, so the drive stays selected.
5830
LOOP BACK to 5824H (L1OOP).
Original Source Code Comment: AND CONTINUE

5832H - L2OOP - At track 0: FORM, the message (FORMAT only), back to track 0 and BOTWRI

5832L2OOP
L2OOP: GOSUB to 5CBDH (FORM) to format and verify every track and build the flaw table of the new GAT.
Original Source Code Comment: GO FORMAT THE DISK
5835
LD A,00HLD A,0 3E 00
LET Register A = the byte at 5836H (BCKFLG): 00H in the file; DOLLAR (551AH) stores 0FH there when BACKUP formats the destination.
Original Source Code Comment: GET THE BACKUP FLAG
5837
OR A B7
OR Register A with itself to set the flags from BCKFLG.
Original Source Code Comment: THIS BACKUP CALLING?
5838
If the NZ FLAG is set (BACKUP is the caller), JUMP to 5840H (BCKFL1) without the message.
Original Source Code Comment: YES, DON'T DISPLAY MESSAGES
583A
LD HL,5B6DHLD HL,WRTDIR 21 6D 5B
LET Register Pair HL = 5B6DH (WRTDIR), the text 0AH 'Writing System Information' 0DH.
Original Source Code Comment: HL => WRITING SYSTEM INFORMATION
583D
GOSUB to 021BH (the ROM's PRINT routine) to show it.
Original Source Code Comment: DISPLAY IT
5840BCKFL1
LD A,0CHLD A,RSTORE 3E 0C
BCKFL1: LET Register A = 0CH (RSTORE), the FDC's Restore command with head load and verify, step rate 6 ms.
Original Source Code Comment: TELL DISK TO RESTORE TO TRK 0
5842
OUTput 0CH to port F0H, the FDC command register: the head moves back to track 0.
5844
GOSUB to 4404H (SDELAY in SYS0), a short delay so the FDC can take the command.
Original Source Code Comment: GO STALL FOR TIME
5847L3OOP
L3OOP: INput the FDC status from port F0H into Register A.
Original Source Code Comment: GET FDC STATUS
5849
BIT 2,A CB 57
Test bit 2 of the status (the head is at track 0).
Original Source Code Comment: WE AT TRACK 0?
584B
If the Z FLAG is set (not there yet), LOOP BACK to 5847H (L3OOP).
Original Source Code Comment: NO
584E
GOSUB to 5A53H (BOTWRI) to write the boot sector, the system sector, the GAT, the HIT and the directory sectors.
Original Source Code Comment: GO WRITE OUT THE BOOT
5851
EI FB
Enable the maskable interrupts again (the disk routines left them off).
Original Source Code Comment: INTERRUPTS CAN COME ON NOW
5852
RET C9
RETurn to FRMAT or DOLLAR.
Original Source Code Comment: BACK TO DOS

5853H - BOOT / ENT - The boot sector (256 bytes, 5853H-5952H) BOTWRI writes to track 0, sector 1. It is assembled to run at 4300H (SETLOC BUFF1), where the ROM loads it: the absolute addresses in its instructions are run addresses (4300H-43FFH), the rows show the addresses in this file, and each comment gives both. It loads the load module from track 0, sector 2 on (drive 0) and jumps to its transfer address.

5853ENT
CP 11HCP 17 FE 11
ENT (4300H when it runs): FEH 11H, which the CPU takes as CP 11H, compare Register A with 11H; it changes only the flags. As data, byte 0 of the boot sector is FEH, the mark of a boot sector, and byte 1 is 11H (17), the directory track. The ROM loads this sector at 4300H and jumps there.
Original Source Code Comment: DIRECTORY TRACK PLACED AT '17'
5855TRYAGN
LD A,0D0HLD A,CTERM 3E D0
TRYAGN (4302H): LET Register A = D0H (the source's CTERM), the FDC's Force Interrupt command.
Original Source Code Comment: LET'S HALT THE GUY RIGHT
5857
OUTput D0H to port F0H, the FDC command register, to stop whatever the FDC is doing.
Original Source Code Comment: HERE IN HIS TRACKS
5859
LD HL,0002HLD HL,2 21 02 00
LET Register Pair HL = 0002H: Register H = track 00H, Register L = sector 02H, the first sector of the load module (SYS0) on a system diskette.
Original Source Code Comment: SET FOR TRACK 0, SECTOR 2
585C
LD (43EAH),HLLD (TRKSAV),HL 22 EA 43
Store HL into 43EAH-43EBH (TRKSAV, 593DH in this file), the track and sector GETBYT reads next.
585F
XOR A AF
Set Register A to 00H.
Original Source Code Comment: CLEAR THE EOF BYTE
5860
LD (43ECH),ALD (EOFBYT),A 32 EC 43
Store 00H into 43ECH (EOFBYT, 593FH in this file), the offset of the next byte in the sector buffer: 00H makes GETBYT read a new sector.
5863BOTLOP
BOTLOP (4310H): GOSUB to 433EH (GETBYT, 5891H in this file) to get the next byte of the load module into Register A: the type of the next record.
Original Source Code Comment: GET A BYTE FROM DISK
5866
CP 01HCP 1 FE 01
Compare Register A with 01H, the type of a load record.
Original Source Code Comment: LOAD FILE HEADER?
5868
If the Z FLAG is set (a load record), JUMP to 5876H (BOTLO1, 4323H when it runs).
Original Source Code Comment: YES, GET THE PROGRAM
586A
CP 02HCP 2 FE 02
Compare Register A with 02H, the type of the transfer record.
Original Source Code Comment: END OF PGM?
586C
If the NZ FLAG is set (any other type), JUMP to 5855H (TRYAGN, 4302H when it runs) to start again from track 0, sector 2.
Original Source Code Comment: NO, DO A RESTART
586E
GOSUB to 433EH (GETBYT): the length byte of the transfer record (not used).
Original Source Code Comment: GET THE COUNT
5871
GOSUB to 4335H (GETADD, 5888H in this file) to read the transfer address into Register Pair HL.
Original Source Code Comment: GET THE ADDRESS
5874
JP (HL) E9
JUMP to the address in Register Pair HL, the transfer address of the load module (4E00H for SYS0).
Original Source Code Comment: BY NOW.

5875H - CNT1 (4322H) - The backup counter of the diskette

5875CNT1
DEFB 0FFH FF
CNT1 (4322H when it runs): the backup counter of the diskette, FFH = no limit (the source's DEFB -1). RBOOT reads it at offset 22H of the boot sector (C1LOC) of a BACKUP source, lowers it on the source and writes 00H into the copy.
Original Source Code Comment: BACKUP PROTECTION COUNTER

5876H - BOTLO1 (4323H) - A load record: read its length and address and put its data into memory

5876BOTLO1
BOTLO1 (4323H): GOSUB to 433EH (GETBYT) to get the length byte of the load record into Register A (the 2 address bytes and the data).
Original Source Code Comment: GET THE COUNT
5879
SUB 02HSUB 2 D6 02
SUBtract 02H (the two address bytes) from Register A: A = the number of data bytes.
Original Source Code Comment: REMOVE THE ADDRESS COUNT
587B
LD B,A 47
LET Register B = Register A, the number of data bytes, as the count for the DJNZ at 5884H.
Original Source Code Comment: INTO B
587C
GOSUB to 4335H (GETADD) to read the load address of the record into Register Pair HL.
Original Source Code Comment: GET THE ADDRESS
587FBOTLO2
BOTLO2 (432CH): GOSUB to 433EH (GETBYT) to get the next data byte into Register A.
Original Source Code Comment: GET A BYTE
5882
LD (HL),A 77
Store the data byte at HL, its place in memory.
Original Source Code Comment: PUT IT INTO RAM
5883
INC HL 23
INCrement Register Pair HL by 1.
Original Source Code Comment: BUMP TO NEXT ADDR
5884
DECrement Register B and, if it is not 0, LOOP BACK to 587FH (BOTLO2, 432CH when it runs).
Original Source Code Comment: LOOP FOR COUNT
5886
JUMP to 5863H (BOTLOP, 4310H when it runs) for the next record.
Original Source Code Comment: GO GET MORE DATA

5888H - GETADD (4335H) - Read two bytes of the load module into HL (low byte first)

5888GETADD
GETADD (4335H): GOSUB to 433EH (GETBYT) to get the low byte of an address into Register A.
Original Source Code Comment: GET A BYTE
588B
LD L,A 6F
LET Register L = Register A, the low byte.
Original Source Code Comment: SET AS LSB OF ADDRESS
588C
GOSUB to 433EH (GETBYT) to get the high byte into Register A.
Original Source Code Comment: GET A BYTE
588F
LD H,A 67
LET Register H = Register A: HL = the address.
Original Source Code Comment: SET AS MSB OF ADDRESS
5890
RET C9
RETurn with the address in Register Pair HL.

5891H - GETBYT (433EH) - Return the next byte of the load module in A, reading the next sector into 4D00H when needed (9 tries, then ERROR and a stop)

5891GETBYT
PUSH BC C5
GETBYT (433EH): Save Register Pair BC on the STACK.
Original Source Code Comment: SAVE REGISTERS
5892
PUSH HL E5
Save Register Pair HL on the STACK.
5893
LD A,(43ECH)LD A,(EOFBYT) 3A EC 43
Fetch the offset of the next byte from 43ECH (EOFBYT) into Register A: 00H means the sector buffer is used up (or nothing was read yet).
Original Source Code Comment: GET THE NEXT BYTE TO READ
5896
OR A B7
OR Register A with itself to set the flags from EOFBYT.
Original Source Code Comment: WE NEED TO READ IN ANOTHER SECTOR?
5897
If the NZ FLAG is set (bytes left in the buffer), JUMP to 58C7H (GETOK1, 4374H when it runs) to take the next one.
Original Source Code Comment: NO, GET THE BYTE
5899
LD B,09HLD B,9 06 09
LET Register B = 09H, the number of tries to read the sector, as the count for the DJNZ at 58A8H.
Original Source Code Comment: NUMBER OF RETRIES
589BGETBY1
PUSH BC C5
GETBY1 (4348H): Save Register Pair BC (Register B = the tries left) on the STACK.
Original Source Code Comment: SAVE RETRY COUNT
589C
GOSUB to 437FH (BOTRED, 58D2H in this file) to read the sector at TRKSAV into 4D00H. It returns the FDC status in Register A.
Original Source Code Comment: READ IN A SECTOR
589F
POP BC C1
Restore Register Pair BC (Register B = the tries left) from the STACK.
Original Source Code Comment: GET RETRY COUNT BACK
58A0
AND 1DHAND 1DH E6 1D
MASK the status with 1DH (0001 1101): bit 0 busy, bit 2 lost data, bit 3 CRC error, bit 4 record not found.
Original Source Code Comment: ANY ERRORS?
58A2
If the Z FLAG is set (none of those bits, the read worked), JUMP to 58B7H (GETOK, 4364H when it runs).
Original Source Code Comment: IS OKAY, GET DATA
58A4
LD A,0D0HLD A,CTERM 3E D0
LET Register A = D0H (CTERM), the FDC's Force Interrupt command.
Original Source Code Comment: INTERRUPT INST
58A6
OUTput D0H to port F0H to stop the FDC.
58A8
DECrement Register B (the tries left) and, if it is not 0, LOOP BACK to 589BH (GETBY1, 4348H when it runs) to try again.
Original Source Code Comment: ELSE RETYR IT AGAIN
58AA
LD A,17HLD A,23 3E 17
Nine tries failed: LET Register A = 17H, the display code for 32 characters per line.
Original Source Code Comment: MAKE 32 CHAR MODE
58AC
GOSUB to 0033H (the ROM's display routine) to send 17H.
Original Source Code Comment: DISPLAY IT
58AF
LD HL,43EDHLD HL,DSKERR 21 ED 43
LET Register Pair HL = 43EDH (DSKERR, 5940H in this file), the text 17H 'ERROR' 0DH.
Original Source Code Comment: REPORT DISK ERROR
58B2
GOSUB to 021BH (the ROM's PRINT routine) to show it.
Original Source Code Comment: USE PRINT ROUTINE IN ROM
58B5GETBAD
GETBAD (4362H): JUMP to this same instruction: the computer stops here until it is reset.
Original Source Code Comment: SIT AND LOOP

58B7H - GETOK (4364H) - The sector was read: move TRKSAV on to the next sector and take its first byte

58B7GETOK
LD HL,(43EAH)LD HL,(TRKSAV) 2A EA 43
GETOK (4364H): Fetch the track and sector just read from 43EAH-43EBH (TRKSAV) into Register Pair HL: H = track, L = sector.
Original Source Code Comment: BUMP TO NEXT SECTOR
58BA
INC L 2C
INCrement Register L, the sector, for the next read.
Original Source Code Comment: BUMP TO NEXT SECTOR
58BB
LD A,L 7D
LET Register A = Register L.
58BC
CP 13HCP TRACK+1 FE 13
Compare Register A with 13H (19, TRACK + 1): the CARRY FLAG is set for sectors 1-18.
Original Source Code Comment: WE AT END OF THIS TRACK?
58BE
If the CARRY FLAG is set (still on this track), JUMP to 58C3H (GETOK0, 4370H when it runs).
Original Source Code Comment: NO, CONTINUE
58C0
LD L,01HLD L,1 2E 01
LET Register L = 01H, sector 1.
Original Source Code Comment: SET FOR SECTOR 1
58C2
INC H 24
INCrement Register H, the next track.
Original Source Code Comment: BUMP TO NEXT TRACK
58C3GETOK0
LD (43EAH),HLLD (TRKSAV),HL 22 EA 43
GETOK0 (4370H): Store the next track and sector into 43EAH-43EBH (TRKSAV).
Original Source Code Comment: SAVE FOR NEXT TIME
58C6
XOR A AF
Set Register A to 00H, the offset of the first byte of the sector just read.
Original Source Code Comment: SET FOR 1ST BYTE
58C7GETOK1
LD L,A 6F
GETOK1 (4374H): LET Register L = Register A, the offset of the byte wanted.
Original Source Code Comment: PUT THE BYTE OFFSET INTO HL
58C8
LD H,4DHLD H,BUFF2.HIGH. 26 4D
LET Register H = 4DH: HL = 4D00H (BUFF2) plus the offset, the byte in the sector buffer.
58CA
INC A 3C
INCrement Register A by 1, the offset of the next byte (after FFH it becomes 00H, so the next GETBYT reads a new sector).
Original Source Code Comment: BUMP TO NEXT BYTE
58CB
LD (43ECH),ALD (EOFBYT),A 32 EC 43
Store it into 43ECH (EOFBYT).
Original Source Code Comment: STORE FOR NEXT TIME
58CE
LD A,(HL) 7E
Fetch the byte at HL into Register A.
Original Source Code Comment: GET THE BYTE
58CF
POP HL E1
Restore Register Pair HL from the STACK.
Original Source Code Comment: RESTORE REGISTERS
58D0
POP BC C1
Restore Register Pair BC from the STACK.
58D1
RET C9
RETurn with the byte in Register A.

58D2H - BOTRED (437FH) - Read the sector in TRKSAV of drive 0 into 4D00H with the NMI pointed at BOTINT. Exit: A = the FDC status.

58D2BOTRED
BOTRED (437FH): GOSUB to 43C5H (XSEEK, 5918H in this file) to select drive 0, seek the track in TRKSAV and set the FDC's sector register to its sector.
Original Source Code Comment: SEEK THE SPECIFIED TRACK
58D5
LD BC,00F3HLD BC,CDATA 01 F3 00
LET Register Pair BC = 00F3H: Register C = F3H, the FDC data port, for the INI instructions; Register B = 00H, the count INI lowers (not used to end the loop).
Original Source Code Comment: B=0, C=DATA PORT
58D8
LD A,81HLD A,DOUBLE+1 3E 81
LET Register A = 81H (the source's DOUBLE + 1): bit 7 double density and bit 0 drive 0.
Original Source Code Comment: SET DOUBLE DENSITY, DRIVE 0
58DA
OUTput 81H to port F4H, the drive select latch.
Original Source Code Comment: OUTPUT TO THE SELECT REGISTER
58DC
LD D,A 57
LET Register D = Register A, a copy of the select byte for the loop at 5903H.
Original Source Code Comment: KEEP A COPY
58DD
LD HL,43B7HLD HL,BOTINT 21 B7 43
LET Register Pair HL = 43B7H (BOTINT, 590AH in this file), the routine the NMI at the end of the read is to run.
Original Source Code Comment: HL => PLACE TO GO TO ON INTERRUPT
58E0
LD (404AH),HLLD (DOS+1),HL 22 4A 40
Store 43B7H into 404AH-404BH, the address of the NMI vector at 4049H (the source's DOS+1).
Original Source Code Comment: SET THE JUMP VECTOR
58E3
LD A,0C3HLD A,0C3H 3E C3
LET Register A = C3H, the opcode of JP.
Original Source Code Comment: A 'JP' INSTRUCTION
58E5
LD (4049H),ALD (DOS),A 32 49 40
Store C3H into 4049H, the NMI vector: an NMI now runs JP 43B7H.
Original Source Code Comment: SET IT
58E8
DI F3
Disable the maskable interrupts.
Original Source Code Comment: INTERRUPTS OFF
58E9
LD A,0C0HLD A,NMIBIT 3E C0
LET Register A = C0H (the source's NMIBIT): bit 7 lets the FDC's interrupt request through as an NMI, bit 6 the motor time out.
Original Source Code Comment: ENABLE FDC INTRQ
58EB
OUTput C0H to port E4H, the NMI mask latch.
58ED
LD E,02HLD E,2 1E 02
LET Register E = 02H, the mask of the data request bit (bit 1) of the FDC status.
Original Source Code Comment: DATA REQUEST MASK
58EF
LD HL,4D00HLD HL,BUFF2 21 00 4D
LET Register Pair HL = 4D00H (BUFF2), where the sector goes.
Original Source Code Comment: PLACE TO STORE DATA
58F2
LD A,84HLD A,CREAD 3E 84
LET Register A = 84H (the source's CREAD): the FDC's Read Sector command (bits 7-5 100) with bit 2 set (15 ms head settle delay).
Original Source Code Comment: LOAD THE READ INSTRUCTION
58F4
OUTput 84H to port F0H, the FDC command register.
Original Source Code Comment: TO THE FDC
58F6
GOSUB to 43E0H (DELY, 5933H in this file), a short delay before reading the status.
Original Source Code Comment: DO A 12 MICRO SECOND DELAY
58F9FSTDRQ
FSTDRQ (43A6H): INput the FDC status from port F0H into Register A.
Original Source Code Comment: GET THE FDC STATUS
58FB
AND E A3
MASK it with Register E (02H): the Z FLAG is set while there is no data request.
Original Source Code Comment: DATA REQUEST?
58FC
If the Z FLAG is set (no byte yet), LOOP BACK to 58F9H (FSTDRQ, 43A6H when it runs).
Original Source Code Comment: NO, WAIT FOR ONE
58FE
INI ED A2
INI: read the first data byte from port C (F3H) into the memory at HL, add 1 to HL and subtract 1 from B.
Original Source Code Comment: GET A BYTE OF DATA
5900
LD A,D 7A
LET Register A = Register D, the select byte (81H).
Original Source Code Comment: GET THE DRIVE BACK
5901
OR 40HOR SYNC F6 40
OR Register A with 40H (the source's SYNC): bit 6 of port F4H makes the CPU wait until the FDC has the next byte.
Original Source Code Comment: ADD IN THE WAIT SYNC REQUEST
5903RDLOOP
RDLOOP (43B0H): OUTput Register A (C1H) to port F4H: drive 0, double density, wait for the data request.
Original Source Code Comment: OUTPUT TO THE SELECT LATCH
5905
INI ED A2
INI: read the next data byte from port F3H into the memory at HL, add 1 to HL and subtract 1 from B.
Original Source Code Comment: READ TILL INTERRUPT
5907
JUMP to 43B0H (RDLOOP, 5903H in this file). The loop has no exit: the NMI at the end of the read goes to BOTINT.

590AH - BOTINT (43B7H) - The NMI at the end of the read: drop the NMI's return address, turn the disk NMIs off and return the FDC status

590ABOTINT
POP HL E1
BOTINT (43B7H): Restore Register Pair HL from the STACK: this drops the return address the NMI pushed (inside RDLOOP), so the RET at 5917H goes back to the caller of BOTRED.
Original Source Code Comment: GET INTERRUPT PUSH OFF STACK
590B
XOR A AF
Set Register A to 00H.
Original Source Code Comment: CLEAR A
590C
OUTput 00H to port E4H, the NMI mask latch: no more disk NMIs.
Original Source Code Comment: SHUT OFF MASK INTERRUPT
590E
LD A,81HLD A,DOUBLE+1 3E 81
LET Register A = 81H (DOUBLE + 1), drive 0 and double density.
Original Source Code Comment: RESELECT THE DRIVE
5910
OUTput 81H to port F4H, the drive select latch (no wait bit).
5912
GOSUB to 43E6H (STILL, 5939H in this file), a short delay.
5915
INput the FDC status from port F0H into Register A: the result of the read.
Original Source Code Comment: GET THE FDC STATUS
5917
RET C9
RETurn to GETBYT with the FDC status in Register A.
Original Source Code Comment: DONE

5918H - XSEEK (43C5H) - Seek the track in TRKSAV on drive 0 and set the FDC's sector register

5918XSEEK
LD A,81HLD A,DOUBLE+1 3E 81
XSEEK (43C5H): LET Register A = 81H (DOUBLE + 1), drive 0 and double density.
Original Source Code Comment: SELECT THE DRIVE
591A
OUTput 81H to port F4H, the drive select latch.
591C
LD HL,(43EAH)LD HL,(TRKSAV) 2A EA 43
Fetch the track and sector from 43EAH-43EBH (TRKSAV) into Register Pair HL: H = track, L = sector.
Original Source Code Comment: GET THE TRACK/SECTOR
591F
LD A,H 7C
LET Register A = Register H, the track.
Original Source Code Comment: GET THE TRACK
5920
OUTput the track to port F3H, the FDC data register, as the destination of the Seek.
Original Source Code Comment: OUTPUT TO THE DATA PORT
5922
LD A,1CHLD A,CSEEK 3E 1C
LET Register A = 1CH (the source's CSEEK): the FDC's Seek command (bits 7-4 0001) with head load and verify, step rate 6 ms.
Original Source Code Comment: LOAD THE SEEK COMMAND
5924
OUTput 1CH to port F0H, the FDC command register.
Original Source Code Comment: AND OUTPUT TO THE FDC
5926
GOSUB to 43E6H (STILL), a short delay before reading the status.
Original Source Code Comment: DO A STALL
5929XSEEK1
XSEEK1 (43D6H): INput the FDC status from port F0H into Register A.
Original Source Code Comment: WAIT FOR DRIVE NOT BUSY
592B
BIT 0,A CB 47
Test bit 0 of the status (busy).
592D
If the NZ FLAG is set (the seek is still going on), LOOP BACK to 5929H (XSEEK1, 43D6H when it runs).
592F
LD A,L 7D
LET Register A = Register L, the sector.
Original Source Code Comment: GET THE SECTOR NUMBER
5930
OUTput the sector to port F2H, the FDC sector register, for the read.
Original Source Code Comment: OUTPUT TO THE SECTOR REGISTER
5932
RET C9
RETurn to BOTRED.

5933H - DELY (43E0H) / STILL (43E6H) - Short delays

5933DELY
PUSH AF F5
DELY (43E0H): Save Register Pair AF on the STACK. The PUSH AF / POP AF pairs only use up time; DELY gives four pairs and STILL one.
5934
POP AF F1
Restore Register Pair AF from the STACK (no change).
5935
PUSH AF F5
Save Register Pair AF on the STACK (delay).
5936
POP AF F1
Restore Register Pair AF from the STACK (delay).
5937
PUSH AF F5
Save Register Pair AF on the STACK (delay).
5938
POP AF F1
Restore Register Pair AF from the STACK (delay).
5939STILL
PUSH AF F5
STILL (43E6H): Save Register Pair AF on the STACK (delay).
593A
POP AF F1
Restore Register Pair AF from the STACK (delay).
593B
NOP 00
No operation (delay).
593C
RET C9
RETurn to the caller.

593DH - TRKSAV (43EAH) - The variables, the message and the fields at the end of the boot sector

593D-593ETRKSAV
DEFW 0002H 02 00
TRKSAV (43EAH-43EBH when it runs): the track (high byte) and sector (low byte) GETBYT reads next; 0002H here, and TRYAGN stores 0002H again.
593FEOFBYT
DEFB 00H 00
EOFBYT (43ECH): the offset in the sector buffer 4D00H of the next byte GETBYT returns; 00H = read a new sector.
5940DSKERR
DEFB 17H 17
DSKERR (43EDH): 17H, the display code for 32 characters per line.
5941-5945
DEFM "ERROR" 45 52 52 4F 52
'ERROR', the text shown when a sector of the load module cannot be read.
5946
DEFB 0DH 0D
0DH: ends DSKERR with a new line (the source's ~).
5947-594FS1SER
DEFB 00H x 9 00 x 9
S1SER (43F4H): 9 bytes of 00H that fill the boot sector up to S1SIDE (the source's DEFB 256-$+ENT-3%0). The source names offset F4H of the boot sector (S1SLOC) as the place of the serial number.
5950S1SIDE
DEFB 00H 00
S1SIDE (43FDH): 00H, offset FDH of the boot sector (S1LOC).
5951TYPES
DEFB 13H 13
TYPES (43FEH): 13H, the version of the diskette (TRSDOS 1.3), offset FEH (S1TYPE). RBOOT refuses a source whose byte here is below 12H.
Original Source Code Comment: TRSDOS VERSION 1.3
5952TRACKS
DEFB 28H 28
TRACKS (43FFH): 28H (40), the number of tracks, offset FFH (S1TRK).
Original Source Code Comment: 40 TRACKS

5953H - SYST - The sector BOTWRI writes to track 0, sector 2 (256 bytes, 5953H-5A52H): a load module of NOSYS, assembled to run at 4D00H (SETLOC BUFF2)

5953SEC3
DEFB 01H 01
SYST, SEC3: 01H, the type of a load record. The 256 bytes 5953H-5A52H are the sector BOTWRI writes to track 0, sector 2 of every diskette it formats: a load module that shows 'Not a SYSTEM Disk' when the boot sector loads it.
5954LEFT
DEFB 21H 21
LEFT: 21H (33), the length of the load record: the 2 address bytes and 31 bytes of NOSYS and its message (the source's RIGHT = $-NOSYS+2).
5955-5956
DEFW 4D00H 00 4D
4D00H (NOSYS), the load address of the record.

5957H - NOSYS (4D00H) - Show 'Not a SYSTEM Disk' and stop

5957NOSYS
LD A,17HLD A,23 3E 17
NOSYS (4D00H when it runs): LET Register A = 17H, the display code for 32 characters per line.
Original Source Code Comment: MAKE 32 CHARACTER MODE
5959
GOSUB to 0033H (the ROM's display routine) to send 17H.
Original Source Code Comment: DISPLAY IT
595C
LD HL,4D0DHLD HL,SYSTMG 21 0D 4D
LET Register Pair HL = 4D0DH (SYSTMG, 5964H in this file), the text 'Not a SYSTEM Disk' and 0DH.
Original Source Code Comment: HL => NO SYSTEM MSG
595F
GOSUB to 021BH (the ROM's PRINT routine) to show it.
Original Source Code Comment: PRINT IT ON THE SCREEN
5962NOSYS1
NOSYS1 (4D0BH): JUMP to this same instruction: the computer stops here until it is reset.
Original Source Code Comment: LOOP

5964H - SYSTMG (4D0DH) - The message, the transfer record and the fill bytes of the sector

5964-5974SYSTMG
DEFM "Not a SYSTEM Disk" 4E 6F 74 20 61 20 53 59 53 54 45 4D 20 44 69 73 6B
SYSTMG (4D0DH): 'Not a SYSTEM Disk'.
5975
DEFB 0DH 0D
0DH: ends SYSTMG with a new line (the source's ~).
5976
DEFB 02H 02
02H, the type of the transfer record.
5977
DEFB 02H 02
02H, its length (the 2 bytes of the address).
5978-5979
DEFW 4D00H 00 4D
4D00H (NOSYS), the transfer address: the boot sector's loader jumps there.
597A-5A52
DEFB 0E5H x 217 E5 x 217
E5H bytes that fill the sector up to 5A52H (the source's DEFB 256-$+NOSYS-4%0E5H).

5A53H - BOTWRI - Write the boot sector (track 0, sector 1), the NOSYS sector (sector 2), the GAT (track 17, sector 1), the empty HIT (sector 2) and the empty directory sectors (3-18)

5A53BOTWRI
LD DE,0001HLD DE,1 11 01 00
BOTWRI: LET Register Pair DE = 0001H: Register D = track 00H, Register E = sector 01H.
Original Source Code Comment: D=TRK 0, E=SEC 1
5A56
LD HL,5853HLD HL,BOOT 21 53 58
LET Register Pair HL = 5853H (BOOT), the boot sector (ENT, assembled to run at 4300H).
Original Source Code Comment: HL => BOOT STRAP PROGRAM
5A59
LD A,(4E7FH)LD A,(FDRIVD) 3A 7F 4E
Fetch the destination drive number from 4E7FH (FDRIVD) into Register A.
Original Source Code Comment: GET THE DRIVE NUMBER
5A5C
LD C,A 4F
LET Register C = Register A, the drive for XWRITE.
Original Source Code Comment: INTO C
5A5D
GOSUB to 45F7H (XWRITE in SYS0) to write the 256 bytes at HL to drive C, track D, sector E. Returns Z, or NZ with the error code in A.
Original Source Code Comment: WRITE IT OUT
5A60
If the NZ FLAG is set (the write failed, A = the error code), JUMP to 4E00H (FATAL).
Original Source Code Comment: EXIF IF ERROR
5A63
INC E 1C
INCrement Register E: sector 02H.
Original Source Code Comment: BUMP TO SECTOR 2
5A64
LD HL,5953HLD HL,SYST 21 53 59
LET Register Pair HL = 5953H (SYST), the sector with the NOSYS load module.
Original Source Code Comment: HL => 'NO SYSTEM' PGM
5A67
GOSUB to 45F7H (XWRITE in SYS0) to write it to track 0, sector 2. Returns Z, or NZ with the error code in A.
Original Source Code Comment: WRITE IT OUT
5A6A
If the NZ FLAG is set (the write failed, A = the error code), JUMP to 4E00H (FATAL).
5A6D
LD DE,1101H 11 01 11
LET Register Pair DE = 1101H: Register D = track 11H (17, the directory track), Register E = sector 01H, the GAT.
Original Source Code Comment: D=TRK 11, E=SEC 1 (DIRECTORY)
5A70
LD HL,6100HLD HL,FGAT 21 00 61
LET Register Pair HL = 6100H (FGAT), the new GAT: allocation bytes, flaw table, password code, name and date.
Original Source Code Comment: HL => GAT TABLE WITH NAME AND DATE
5A73
LD A,(4E7FH)LD A,(FDRIVD) 3A 7F 4E
Fetch the destination drive number from 4E7FH (FDRIVD) into Register A.
Original Source Code Comment: GET THE DRIVE NUMBER
5A76
LD C,A 4F
LET Register C = Register A, the drive for XWRITE.
Original Source Code Comment: INTO C
5A77
GOSUB to 45F7H (XWRITE in SYS0) to write the GAT to track 17, sector 1 (XWRITE writes the directory track with the data address mark of directory sectors). Returns Z, or NZ with the error code in A.
Original Source Code Comment: WRITE IT OUT
5A7A
If the NZ FLAG is set (the write failed, A = the error code), JUMP to 4E00H (FATAL).
Original Source Code Comment: EXIT IF ERROR
5A7DBOTWR1
INC E 1C
BOTWR1: INCrement Register E, the next sector of the directory track.
Original Source Code Comment: BUMP TO NEXT SECTOR
5A7E
LD A,E 7B
LET Register A = Register E.
Original Source Code Comment: GET THE SECTOR
5A7F
CP 13HCP TRACK+1 FE 13
Compare Register A with 13H (19, TRACK + 1): the NO CARRY FLAG is set after sector 18.
Original Source Code Comment: WE AT END OF DIRECTORY?
5A81
RET NC D0
If the NO CARRY FLAG is set (sectors 2-18 written), RETurn to FOMAT.
Original Source Code Comment: YES, EXIT
5A82
LD HL,5F00HLD HL,DUM1 21 00 5F
LET Register Pair HL = 5F00H (DUM1), the empty directory sector FORM built: 00H with FFH at offsets E0H-FFH, then (after sector 2) with the copyright text at F0H-FFH.
Original Source Code Comment: HL => DUMMY DIRECTORY
5A85
GOSUB to 45F7H (XWRITE in SYS0) to write it to track 17, sector E. Returns Z, or NZ with the error code in A.
Original Source Code Comment: WRITE OUT THE SECTOR
5A88
If the NZ FLAG is set (the write failed, A = the error code), JUMP to 4E00H (FATAL).
5A8B
LD A,E 7B
LET Register A = Register E, the sector just written.
Original Source Code Comment: GET THE SECTOR NUMBER
5A8C
CP 02HCP 2 FE 02
Compare Register A with 02H, the HIT: the HIT got DUM1 with FFH in its last 32 bytes, the system file pointers (no system files).
Original Source Code Comment: SECTOR 2?
5A8E
If the NZ FLAG is set (sector 3 or above), LOOP BACK to 5A7DH (BOTWR1).
Original Source Code Comment: NO, CONTINUE WRITING
5A90
PUSH BCSAVE C5
Save Register Pair BC (C = the drive) on the STACK.
5A91
PUSH DE D5
Save Register Pair DE (the track and sector) on the STACK.
5A92
PUSH HL E5
Save Register Pair HL on the STACK.
5A93
LD HL,5FE0HLD HL,DUM1+224 21 E0 5F
LET Register Pair HL = 5FE0H (DUM1 + 224), offset E0H of the directory sector.
Original Source Code Comment: CLEAR OUT THE SYSTEM FLAGS
5A96
LD DE,5FE1HLD DE,DUM1+225 11 E1 5F
LET Register Pair DE = 5FE1H (DUM1 + 225), so the LDIR copies the cleared byte forward.
5A99
LD BC,000FHLD BC,15 01 0F 00
LET Register Pair BC = 000FH (15) for the LDIR.
Original Source Code Comment: NUMBER OF BYTES
5A9C
LD (HL),00HLD (HL),0 36 00
Store 00H at 5FE0H.
Original Source Code Comment: CLEAR BYTE
5A9E
LDIR ED B0
Copy the 00H forward (LDIR): offsets E0H-EFH of DUM1 become 00H (the source: clear out the system flags).
5AA0
LD HL,5BF1HLD HL,COPY 21 F1 5B
LET Register Pair HL = 5BF1H (COPY), the text '(c) 1980 Tandy ' (16 bytes).
5AA3
LD DE,5FF0HLD DE,DUM1+240 11 F0 5F
LET Register Pair DE = 5FF0H (DUM1 + 240), offset F0H of the directory sector.
5AA6
LD BC,0010HLD BC,16 01 10 00
LET Register Pair BC = 0010H (16) for the LDIR.
5AA9
LDIR ED B0
Copy the copyright text into offsets F0H-FFH of DUM1 (LDIR): sectors 3-18 of the directory get it.
5AAB
POP HLRSTR E1
Restore Register Pair HL from the STACK.
5AAC
POP DE D1
Restore Register Pair DE (track 17 and sector 2) from the STACK.
5AAD
POP BC C1
Restore Register Pair BC (C = the drive) from the STACK.
5AAE
JUMP to 5A7DH (BOTWR1) for sector 3.

5AB0H - TRKWRT - Write the track image at HL with the FDC's Write Track command, on the side in DDSID; it ends through the NMI (BORNMI in SYS0)

5AB0TRKWRT
LD BC,00F3HLD BC,CDATA 01 F3 00
TRKWRT: LET Register Pair BC = 00F3H: Register C = F3H, the FDC data port, for the OUTI instructions; Register B = 00H, the count OUTI lowers (not used to end the loop). On entry HL = 6200H, the track image.
Original Source Code Comment: B=0, C=FDC DATA PORT
5AB3
LD A,(4E7DH)LD A,(FDRIVE) 3A 7D 4E
Fetch the drive select byte from 4E7DH (FDRIVE) into Register A.
Original Source Code Comment: GET THE DRIVE
5AB6
GOSUB to 44E0H (DSEL0 in SYS0) to send it to port F4H, the drive select latch; Register A keeps the select byte.
Original Source Code Comment: SELECT THE DRIVE
5AB9
OR 40HOR SYNC F6 40
OR Register A with 40H (the source's SYNC), the bit of port F4H that makes the CPU wait for the FDC's data request.
Original Source Code Comment: ADD THE WAIT SYNC BIT
5ABB
LD D,A 57
LET Register D = Register A, the select byte with the wait bit, for the loop at 5AE7H.
Original Source Code Comment: KEEP A COPY DRIVE
5ABC
LD A,(5BD6H)LD A,(DDSID) 3A D6 5B
Fetch the side number from 5BD6H (DDSID, the side byte of the track building table) into Register A.
Original Source Code Comment: GET THE SIDE NUMBER
5ABF
OR A B7
OR Register A with itself: the Z FLAG is set for side 0.
Original Source Code Comment: SIDE 1?
5AC0
If the Z FLAG is set (side 0), JUMP to 5AC6H (TRKWR1).
Original Source Code Comment: NO, CONTINUE
5AC2
LD A,10HLD A,SIDBIT 3E 10
LET Register A = 10H (the source's SIDBIT), the side 1 bit of port F4H.
Original Source Code Comment: BIT TO SELECT SIDE 1
5AC4
OR D B2
OR Register D (the select byte) into Register A.
Original Source Code Comment: ADD TO THE DRIVE NUMBER
5AC5
LD D,A 57
LET Register D = Register A, the select byte for side 1.
Original Source Code Comment: BACK INTO D
5AC6TRKWR1
TRKWR1: GOSUB to 459CH (BOTNMI in SYS0) to point the NMI vector (4049H) at BORNMI (45ADH); it reads the FDC status and returns with the maskable interrupts off.
Original Source Code Comment: SET UP THE INTERRUPT VECTOR
5AC9
LD A,0C0HLD A,NMIBIT 3E C0
LET Register A = C0H (NMIBIT), the bits of port E4H that let the FDC's interrupt request (and the motor time out) through as an NMI.
Original Source Code Comment: ENABLE INTRQ
5ACB
OUTput C0H to port E4H, the NMI mask latch.
5ACD
LD E,02HLD E,2 1E 02
LET Register E = 02H, the mask of the data request bit (bit 1) of the FDC status.
Original Source Code Comment: MASK FOR 'DATA REQUEST'
5ACF
LD A,0F0HLD A,TWRITE.AND.0FBH 3E F0
LET Register A = F0H: the FDC's Write Track command (F4H, the source's TWRITE) with bit 2 (the 15 ms head settle delay) cleared.
5AD1
OUTput F0H to port F0H, the FDC command register.
Original Source Code Comment: OUTPUT TO THE FDC
5AD3
GOSUB to 4400H (DELLY in SYS0), a short delay before reading the status.
Original Source Code Comment: DELAY FOR 12 uS
5AD6IMDRQ1
IMDRQ1: INput the FDC status from port F0H into Register A.
Original Source Code Comment: GET THE FDC STATUS
5AD8
AND E A3
MASK it with Register E (02H): the Z FLAG is set while there is no data request.
Original Source Code Comment: DATA REQUEST?
5AD9
If the Z FLAG is set, LOOP BACK to 5AD6H (IMDRQ1).
Original Source Code Comment: NO, WAIT FOR IT
5ADC
OUTI ED A3
OUTI: send the byte at HL (the first of the track image) to port C (F3H), add 1 to HL and subtract 1 from B.
Original Source Code Comment: OUTPUT A BYTE
5ADEIMDRQ2
IMDRQ2: INput the FDC status from port F0H into Register A.
Original Source Code Comment: GET THE FDC STATUS
5AE0
AND E A3
MASK it with Register E (02H): the Z FLAG is set while there is no data request.
Original Source Code Comment: DATA REQUEST?
5AE1
If the Z FLAG is set, LOOP BACK to 5ADEH (IMDRQ2).
Original Source Code Comment: NO, WAIT FOR IT
5AE4
OUTI ED A3
OUTI: send the second byte of the track image to port F3H.
5AE6
LD A,D 7A
LET Register A = Register D, the select byte with the wait bit.
Original Source Code Comment: GET THE DRIVE BACK
5AE7WRLP
WRLP: OUTput Register A to port F4H, so the CPU waits at the next OUTI until the FDC wants the byte.
Original Source Code Comment: OUTPUT TO SELECT LATCH
5AE9
OUTI ED A3
OUTI: send the next byte of the track image at HL to port F3H, HL up by 1.
Original Source Code Comment: OUTPUT THE DATA
5AEB
JUMP to 5AE7H (WRLP). The loop has no exit: the NMI at the end of the track runs BORNMI, which drops the NMI's return address and RETurns to the caller of TRKWRT (FORM) with the FDC status in Register A.
Original Source Code Comment: LOOP TILL INTERRUPTED

5AEEH - VERFIT - Read back sectors 1-18 of the track just written. Exit: Z = all read, NZ = a sector failed.

5AEEVERFIT
LD D,12HLD D,TRACK 16 12
VERFIT: LET Register D = 12H (18, the source's TRACK), the number of sectors to read back, counted down to 1.
Original Source Code Comment: SET FOR 18 SECTORS
5AF0
LD A,(4E7DH)LD A,(FDRIVE) 3A 7D 4E
Fetch the drive select byte from 4E7DH (FDRIVE) into Register A.
Original Source Code Comment: RESELECT THE DRIVE
5AF3
GOSUB to 44E0H (DSEL0 in SYS0) to send it to port F4H: select the drive again.
5AF6VER1
LD A,D 7A
VER1: LET Register A = Register D, the sectors left (18 down to 1).
Original Source Code Comment: GET THE SECTOR NUMBER
5AF7
SUB 13HSUB TRACK+1 D6 13
SUBtract 13H (19, TRACK + 1) from Register A: A = D minus 19.
Original Source Code Comment: SUB THE MAX
5AF9
NEG ED 44
NEGate Register A: A = 19 minus D, the sector to read (1 for D = 18 up to 18 for D = 1).
Original Source Code Comment: MAKE IT POSITIVE
5AFB
LD (5B1BH),ALD (FSVSEC),A 32 1B 5B
Store the sector number into 5B1BH (FSVSEC), the operand of the LD E at 5B1AH.
Original Source Code Comment: SAVE IT
5AFE
PUSH BCSAVE C5
Save Register Pair BC on the STACK.
5AFF
PUSH DE D5
Save Register Pair DE (D = the sectors left) on the STACK.
5B00
PUSH HL E5
Save Register Pair HL on the STACK.
5B01
LD HL,5B9AHLD HL,VERASC 21 9A 5B
LET Register Pair HL = 5B9AH (VERASC), the two digits of the sector number in 'Verifying sector 00'.
Original Source Code Comment: PLACE TO STORE ASCII SECTOR NUMBER
5B04
GOSUB to 5B55H (ASCII) to write the sector number in Register A as two decimal digits at 5B9AH-5B9BH.
Original Source Code Comment: CONVERT SEC IN (A)
5B07
LD A,(4020H)LD A,(CURSOR) 3A 20 40
Fetch the low byte of the cursor address from 4020H (CURSOR, the ROM's cursor position) into Register A.
Original Source Code Comment: GET THE CURSOR POSITION
5B0A
AND 0DFHAND 0DFH E6 DF
MASK Register A with DFH (1101 1111) to clear bit 5.
Original Source Code Comment: SET FOR MIDDLE OF SCREEN
5B0C
OR 1FHOR 1FH F6 1F
OR Register A with 1FH (0001 1111): bits 4-0 set, so the cursor goes to column 31 of the line, the middle of the screen, after 'Formatting track nn'.
5B0E
LD (4020H),ALD (CURSOR),A 32 20 40
Store the new low byte back into 4020H (CURSOR).
5B11
LD HL,5B89HLD HL,VERMSG 21 89 5B
LET Register Pair HL = 5B89H (VERMSG), the text 'Verifying sector nn' and 03H.
Original Source Code Comment: HL => 'VERIFY' MSG
5B14
GOSUB to 021BH (the ROM's PRINT routine) to show it.
Original Source Code Comment: PRINT IT OUT
5B17
LD HL,6200HLD HL,BUFF 21 00 62
LET Register Pair HL = 6200H (BUFF), where the sector is read to (over the track image, which is no longer needed).
Original Source Code Comment: PLACE TO READ TO
5B1A
LD E,00HLD E,0 1E 00
LET Register E = the sector number stored in 5B1BH (FSVSEC) at 5AFBH; 00H in the file.
Original Source Code Comment: SECTOR SAVED HERE
5B1C
LD A,(5BD3H)LD A,(DDTRK) 3A D3 5B
Fetch the track number from 5BD3H (DDTRK, the track byte of the track building table) into Register A.
Original Source Code Comment: GET THE TRACK NUMBER
5B1F
LD D,A 57
LET Register D = Register A, the track.
Original Source Code Comment: INTO (D)
5B20
LD A,(4E7FH)LD A,(FDRIVD) 3A 7F 4E
Fetch the destination drive number from 4E7FH (FDRIVD) into Register A.
Original Source Code Comment: GET THE DRIVE NUMBER
5B23
LD C,A 4F
LET Register C = Register A, the drive for XREAD.
Original Source Code Comment: INTO (C)
5B24
LD A,(5BD6H)LD A,(DDSID) 3A D6 5B
Fetch the side number from 5BD6H (DDSID) into Register A.
Original Source Code Comment: GET THE SIDE NUMBER
5B27
LD (4463H),ALD (CSIDE),A 32 63 44
Store it into 4463H (CSIDE, the current side for SYS0's disk I/O).
Original Source Code Comment: SET IT IN DOS
5B2A
GOSUB to 4675H (XREAD in SYS0) to read track D, sector E of drive C into 6200H. Returns Z, or NZ with the error code in A.
Original Source Code Comment: DO THE READ
5B2D
POP HLRSTR E1
Restore Register Pair HL from the STACK.
5B2E
POP DE D1
Restore Register Pair DE (D = the sectors left) from the STACK.
5B2F
POP BC C1
Restore Register Pair BC from the STACK (the flags of XREAD stay).
5B30
RET NZ C0
If the NZ FLAG is set (the sector could not be read), RETurn to FORM with NZ.
Original Source Code Comment: EXIT IF BAD READ
5B31VERFI2
DEC D 15
VERFI2: DECrement Register D, the sectors left.
5B32
If the NZ FLAG is set (more sectors), LOOP BACK to 5AF6H (VER1).
Original Source Code Comment: AND DO NEXT SECTOR
5B34
RET C9
RETurn to FORM with the Z FLAG set: all 18 sectors read back.

5B35H - STEPR - Step the head in one track and store the new track (C) into SEKTRK for the drive. Exit: Z.

5B35STEPR
LD A,(4E7DH)LD A,(FDRIVE) 3A 7D 4E
STEPR: Fetch the drive select byte from 4E7DH (FDRIVE) into Register A.
Original Source Code Comment: RESELECT THE DRIVE
5B38
GOSUB to 44E0H (DSEL0 in SYS0) to send it to port F4H: select the drive again.
Original Source Code Comment: RESELECT THE DRIVE
5B3B
LD A,58HLD A,STEPIN 3E 58
LET Register A = 58H (the source's STEPIN): the FDC's Step In command (bits 7-5 010) with bit 4 (update the track register) and bit 3 (load the head) set, step rate 6 ms.
Original Source Code Comment: TELL CONTROLLER TO STEP IN
5B3D
OUTput 58H to port F0H, the FDC command register: the head moves in one track.
5B3F
GOSUB to 4547H (CHKBSY in SYS0) to wait until the FDC is not busy (it selects the drive again while it waits).
Original Source Code Comment: WAIT FOR NOT BUSY
5B42
PUSH BCSAVE C5
Save Register Pair BC (C = the new track number from FORM) on the STACK.
5B43
PUSH DE D5
Save Register Pair DE on the STACK.
5B44
PUSH HL E5
Save Register Pair HL on the STACK.
5B45
LD A,(4E7FH)LD A,(FDRIVD) 3A 7F 4E
Fetch the destination drive number from 4E7FH (FDRIVD) into Register A.
Original Source Code Comment: GET THE DRIVE NUMBER
5B48
LD E,ALD DE,A 5F
LET Register E = Register A, the drive number.
Original Source Code Comment: INTO DE
5B49
LD D,00H 16 00
LET Register D = 00H: DE = the drive number.
5B4B
LD HL,445BHLD HL,SEKTRK 21 5B 44
LET Register Pair HL = 445BH (SEKTRK in SYS0), the table of the track each drive's head is on.
Original Source Code Comment: HL => DOS TRACK TABLE
5B4E
ADD HL,DE 19
ADD Register Pair DE to HL, so HL points at the byte of this drive.
Original Source Code Comment: HL => THIS DRIVE'S TRACK BYTE
5B4F
LD (HL),C 71
Store Register C (the track the head moved to) into it, so SYS0 knows where the head is.
Original Source Code Comment: INTO THE TABLE
5B50
POP HLRSTR E1
Restore Register Pair HL from the STACK.
5B51
POP DE D1
Restore Register Pair DE from the STACK.
5B52
POP BC C1
Restore Register Pair BC from the STACK.
5B53STEPR1
XOR A AF
STEPR1: Set Register A to 00H and the Z FLAG (the source: show good step).
Original Source Code Comment: SHOW GOOD STEP
5B54
RET C9
RETurn to FORM with the Z FLAG set.

5B55H - ASCII - Write Register A (0-99) as two decimal digits at HL and HL+1

5B55ASCII
PUSH BC C5
ASCII: Save Register Pair BC on the STACK. On entry Register A holds the number (0-99) and HL the place for its two digits.
Original Source Code Comment: SAVE BC
5B56
LD C,30HLD C,'0' 0E 30
LET Register C = 30H ('0'), the tens digit to start with.
Original Source Code Comment: SET '0' INTO C
5B58SUB
SUB 0AHSUB 10 D6 0A
SUB: SUBtract 0AH (10) from Register A.
5B5A
If the CARRY FLAG is set (Register A went below 0), JUMP to 5B5FH (ADD).
5B5C
INC C 0C
INCrement Register C, the tens digit.
5B5D
LOOP BACK to 5B58H (SUB).

5B5FH - ADD - The units digit, then store both digits

5B5FADD
ADD A,3AHADD A,3AH C6 3A
ADD: ADD 3AH ('0' + 10) to Register A: the subtraction went one ten too far, so this gives the units digit as a character.
5B61
LD B,A 47
LET Register B = Register A, the units digit.
5B62
LD (HL),C 71
Store Register C (the tens digit) at HL.
5B63
INC HL 23
INCrement Register Pair HL by 1.
5B64
LD (HL),B 70
Store Register B (the units digit) at HL.
5B65
POP BC C1
Restore Register Pair BC from the STACK.
Original Source Code Comment: GET BC BACK
5B66
RET C9
RETurn with HL at the units digit.

5B67H - PDATA - Show the text at HL, keeping DE (not called in SYS7)

5B67PDATA
PUSH DE D5
PDATA: Save Register Pair DE on the STACK. PDATA is not called in SYS7.
Original Source Code Comment: SAVE DE
5B68
GOSUB to 021BH (the ROM's PRINT routine) to show the text at HL.
Original Source Code Comment: PRINT IT ON THE SCREEN
5B6B
POP DE D1
Restore Register Pair DE from the STACK.
Original Source Code Comment: GET DE BACK
5B6C
RET C9
RETurn to the caller.

5B6DH - WRTDIR - The messages of the formatter

5B6DWRTDIR
DEFB 0AH 0A
WRTDIR: 0AH (line feed), first byte of the message FOMAT shows (583AH).
5B6E-5B87
DEFM "Writing System Information" 57 72 69 74 69 6E 67 20 53 79 73 74 65 6D 20 49 6E 66 6F 72 6D 61 74 69 6F 6E
'Writing System Information'.
5B88
DEFB 0DH 0D
0DH: ends WRTDIR with a new line (the source's ~).
5B89-5B99VERMSG
DEFM "Verifying sector " 56 65 72 69 66 79 69 6E 67 20 73 65 63 74 6F 72 20
VERMSG: 'Verifying sector ', shown by VERFIT (5B11H) at column 31 of the line.
5B9A-5B9BVERASC
DEFM "00" 30 30
VERASC: '00', the two digits of the sector number, written by ASCII (from 5B01H).
5B9C
DEFB 03H 03
03H: ends the text for PRINT without a new line.
5B9DFORMSG
DEFB 1DH 1D
FORMSG: 1DH (cursor to the start of the line), first byte of the message FORM shows for each track (5D00H).
5B9E-5BAE
DEFM "Formatting track " 46 6F 72 6D 61 74 74 69 6E 67 20 74 72 61 63 6B 20
'Formatting track '.
5BAF-5BB3FORASC
DEFM "00 " 30 30 20 20 20
FORASC: '00 ', the two digits of the track number (written by ASCII from 5CF7H) and three spaces.
5BB4
DEFB 03H 03
03H: ends the text for PRINT without a new line.

5BB5H - TRKNN / DDST / DDTAB - The track building table: the addresses of its three parts (TRKNN), the addresses of the track and sector bytes (DDST), and the entries: a 2 byte count and the byte to write that many times; the count FFFFH copies the 16 bytes that follow

5BB5-5BB6TRKNN
DEFW 5BC5H C5 5B
TRKNN: 5BC5H (DDTAB), the start of part 1 of the track building table (the gap at the start of the track). TBLBMP reads two addresses here: the start and the end of a part.
Original Source Code Comment: TABLE OF ADDRESSES FOR TRKS 0 - MAXTRK
5BB7-5BB8
DEFW 5BC8H C8 5B
5BC8H (DDREP), the start of part 2 (one sector, repeated for each sector of the track) and the end of part 1.
5BB9-5BBA
DEFW 5C07H 07 5C
5C07H (DDTRL), the start of part 3 (the gap at the end of the track) and the end of part 2.
5BBB-5BBC
DEFW 5C0AH 0A 5C
5C0AH (DDEND), the end of part 3.
5BBD-5BBEDDST
DEFW 5BD9H D9 5B
DDST: 5BD9H (DDSEC), the address of the sector number byte of the table; TRKIMG reads it through IX+0 and IX+1 (SECADD).
Original Source Code Comment: SECTOR INCREMENT ADDRESS
5BBF
DEFB 01H 01
01H, the first sector number on a track (BEGSEC; not used by the code).
Original Source Code Comment: BEGINNING SECTOR NUMBER
5BC0
DEFB 12H 12
12H (18), the last sector number on a track (ENDSEC; not used by the code).
Original Source Code Comment: ENDING SECTOR NUMBER
5BC1-5BC2
DEFW 5BD3H D3 5B
5BD3H (DDTRK), the address of the track number byte of the table; TRKIMG reads it through IX+4 and IX+5 (TRKADD).
Original Source Code Comment: TRACK NUMBER ADDRESS
5BC3-5BC4
DEFW 5BECH EC 5B
5BECH (DDDATA), the address of the data field entry (SECTBL; not used by the code).
Original Source Code Comment: DOUBLE DENS DATA SECTOR TABLE ENTRY ADDR
5BC5-5BC6DDTAB
DEFW 0040H 40 00
DDTAB: part 1, entry count 0040H (64).
Original Source Code Comment: NUMBER OF BYTES TO REPEAT
5BC7
DEFB 4EH 4E
4EH, written 64 times: the gap at the start of the track.
Original Source Code Comment: BYTE TO WRITE/REPEAT
5BC8-5BC9DDREP
DEFW 0008H 08 00
DDREP: part 2, the fields of one sector. Count 0008H.
5BCA
DEFB 00H 00
00H, written 8 times (the sync bytes before the ID field).
5BCB-5BCC
DEFW 0003H 03 00
Count 0003H.
5BCD
DEFB 0F5H F5
F5H, written 3 times: the FDC writes a sync byte A1H (with a missing clock) for each F5H.
5BCE-5BCF
DEFW 0001H 01 00
Count 0001H.
5BD0
DEFB 0FEH FE
FEH, the ID address mark.
5BD1-5BD2
DEFW 0001H 01 00
Count 0001H.
5BD3DDTRK
DEFB 00H 00
DDTRK: the track number of the ID field; TRKIMG stores the track here (through IX+4), FOMAT clears it, and FORM and VERFIT read it.
5BD4-5BD5
DEFW 0001H 01 00
Count 0001H.
5BD6DDSID
DEFB 00H 00
DDSID: the side number of the ID field (00H; no code stores into it). TRKWRT and VERFIT read it.
5BD7-5BD8
DEFW 0001H 01 00
Count 0001H.
5BD9DDSEC
DEFB 00H 00
DDSEC: the sector number of the ID field; TRKIMG stores each sector number from SECTAB here (through IX+0), with 80H added on tracks 40 and above.
5BDA-5BDB
DEFW 0001H 01 00
Count 0001H.
5BDC
DEFB 01H 01
01H, the sector length code (256 bytes).
5BDD-5BDE
DEFW 0001H 01 00
Count 0001H.
5BDF
DEFB 0F7H F7
F7H: the FDC writes the two CRC bytes of the ID field.
5BE0-5BE1
DEFW 0016H 16 00
Count 0016H (22).
5BE2
DEFB 4EH 4E
4EH, written 22 times: the gap after the ID field.
5BE3-5BE4
DEFW 000CH 0C 00
Count 000CH (12).
5BE5
DEFB 00H 00
00H, written 12 times (the sync bytes before the data field).
5BE6-5BE7
DEFW 0003H 03 00
Count 0003H.
5BE8
DEFB 0F5H F5
F5H, written 3 times (sync bytes A1H).
5BE9-5BEA
DEFW 0001H 01 00
Count 0001H.
5BEB
DEFB 0FBH FB
FBH, the data address mark.
5BEC-5BEDDDDATA
DEFW 00F0H F0 00
DDDATA: count 00F0H (240).
5BEE
DEFB 0E5H E5
E5H, written 240 times: the first 240 bytes of the sector's data.
5BEF-5BF0
DEFW 0FFFFH FF FF
Count FFFFH: EXPAND then copies the 16 bytes that follow as they are.
5BF1-5C00COPY
DEFM "(c) 1980 Tandy " 28 63 29 20 31 39 38 30 20 54 61 6E 64 79 20 20
COPY: '(c) 1980 Tandy ', the last 16 bytes of every sector's data. BOTWRI also copies it into offsets F0H-FFH of the directory sectors.
5C01-5C02
DEFW 0001H 01 00
Count 0001H.
5C03
DEFB 0F7H F7
F7H: the FDC writes the two CRC bytes of the data field.
5C04-5C05
DEFW 0018H 18 00
Count 0018H (24).
5C06
DEFB 4EH 4E
4EH, written 24 times: the gap after the data field.
5C07-5C08DDTRL
DEFW 0382H 82 03
DDTRL: part 3, count 0382H (898, the source's 598+300).
5C09
DEFB 4EH 4E
4EH, written 898 times: the gap to the end of the track.

5C0AH - SECTAB / CSECTB - The order of the sector numbers on a track and the pointer into it

5C0ASECTAB
DEFB 01H 01
SECTAB: the sector numbers in the order they are laid on the track (an interleave of 3): 1.
Original Source Code Comment: 1ST SECTOR NUMBER
5C0B
DEFB 04H 04
4.
5C0C
DEFB 07H 07
7.
5C0D
DEFB 0AH 0A
0AH (10).
5C0E
DEFB 0DH 0D
0DH (13).
5C0F
DEFB 10H 10
10H (16).
5C10
DEFB 02H 02
2.
5C11
DEFB 05H 05
5.
5C12
DEFB 08H 08
8.
5C13
DEFB 0BH 0B
0BH (11).
5C14
DEFB 0EH 0E
0EH (14).
5C15
DEFB 11H 11
11H (17).
5C16
DEFB 03H 03
3.
5C17
DEFB 06H 06
6.
5C18
DEFB 09H 09
9.
5C19
DEFB 0CH 0C
0CH (12).
5C1A
DEFB 0FH 0F
0FH (15).
5C1B
DEFB 12H 12
12H (18).
5C1C
DEFB 00H 00
00H: the end of SECTAB.
Original Source Code Comment: END OF TABLE MARKER
5C1D-5C1ECSECTB
DEFW 5C0AH 0A 5C
CSECTB: the address of the next entry of SECTAB that TRKIMG uses (5C0AH in the file; TRKIMG sets it to 5C0AH for each track).

5C1FH - TRKIMG - Build the image of track C (7010 bytes) at 6200H: part 1 once, part 2 for each sector of SECTAB, part 3 once

5C1FTRKIMG
PUSH BC C5
TRKIMG: Save Register Pair BC (Register C = the track number, Register B = FORM's track count) on the STACK. TRKIMG builds the image of track C at 6200H from the table parts TRKNN points at; IX = DDST, IY = the next entry of TRKNN.
Original Source Code Comment: SAVE REGISTERS
5C20
PUSH DE D5
Save Register Pair DE (Register D = FORM's retry count) on the STACK.
5C21
PUSH HL E5
Save Register Pair HL (FORM's pointer into the flaw table) on the STACK.
5C22
PUSH AF F5
Save Register Pair AF on the STACK.
5C23
PUSH IY FD E5
Save Register Pair IY (TRKNN) on the STACK, so each call starts again at part 1.
5C25
LD H,(IX+5)LD H,(IX+TRKADD+MSB) DD 66 05
Fetch the high byte of the track byte's address from IX+5 (TRKADD+MSB in DDST) into Register H.
Original Source Code Comment: TRACK NUMBER ADDRESS
5C28
LD L,(IX+4)LD L,(IX+TRKADD+LSB) DD 6E 04
Fetch the low byte from IX+4 into Register L: HL = 5BD3H (DDTRK).
5C2B
LD (HL),C 71
Store Register C (the track number) into DDTRK, the track byte of the ID fields.
Original Source Code Comment: SAVE CURRENT TRACK NUMBER IN TABLE
5C2C
LD A,C 79
LET Register A = Register C, the track number.
Original Source Code Comment: PUT IT INTO (A) AS WELL
5C2D
LD (5C4DH),ALD (SAVEA),A 32 4D 5C
Store it into 5C4DH (SAVEA), the operand of the LD A at 5C4CH.
Original Source Code Comment: SAVE IT
5C30
LD DE,6200HLD DE,BUFF 11 00 62
LET Register Pair DE = 6200H (BUFF), where the track image is built.
Original Source Code Comment: POINT TO BUFFER TO LAY TRK INFO INTO
5C33
GOSUB to 5C7BH (TBLBMP): HL = the start of part 1 (5BC5H), BC = its end (5BC8H), IY moved on by 2.
Original Source Code Comment: GET ADDRESSES FOR TABLE (PART 1)
5C36TRKIM1
TRKIM1: GOSUB to 5C8CH (EXPAND) to write the table entry at HL into the image at DE; the CARRY FLAG is set while HL is below BC.
Original Source Code Comment: GENERATE FROM TABLE ENTRY
5C39
If the CARRY FLAG is set (more entries in part 1), LOOP BACK to 5C36H (TRKIM1).
Original Source Code Comment: REPEAT WHILE HL .LT. BC
5C3B
GOSUB to 5C7BH (TBLBMP): HL = the start of part 2 (5BC8H), BC = its end (5C07H).
Original Source Code Comment: GET ADDRESSES FOR TABLE (PART 2) REPEATING
5C3E
PUSH HL E5
Save Register Pair HL (the start of part 2) on the STACK.
Original Source Code Comment: SAVE ADDR OF CURRENT TBL ENTRY
5C3F
LD HL,5C0AHLD HL,SECTAB 21 0A 5C
LET Register Pair HL = 5C0AH (SECTAB), the sector order table.
Original Source Code Comment: START OF SECTOR # TABLE
5C42
LD (5C1DH),HLLD (CSECTB),HL 22 1D 5C
Store it into 5C1DH-5C1EH (CSECTB), the pointer to the next sector number.
Original Source Code Comment: RESET TABLE POINTER SAVE AREA
5C45TRKIM2
LD HL,(5C1DH)LD HL,(CSECTB) 2A 1D 5C
TRKIM2: Fetch the pointer from 5C1DH-5C1EH (CSECTB) into Register Pair HL.
Original Source Code Comment: GET POSITION IN SECTOR NUMBER TBL
5C48
LD A,(HL) 7E
Fetch the next sector number from SECTAB into Register A.
Original Source Code Comment: GET NEXT SECTOR NUMBER TO USE
5C49
OR A B7
OR Register A with itself: the Z FLAG is set at the 00H that ends SECTAB.
Original Source Code Comment: END OF TABLE?
5C4A
If the Z FLAG is set (all 18 sectors laid out), JUMP to 5C6BH (TRKIM4).
Original Source Code Comment: YES, THRU
5C4C
LD A,00HLD A,0 3E 00
LET Register A = the track number stored in 5C4DH (SAVEA) at 5C2DH; 00H in the file.
Original Source Code Comment: TRACK NUMBER SAVED HERE
5C4E
CP 28HCP MAXTRK FE 28
Compare Register A with 28H (40, MAXTRK): the CARRY FLAG is set for tracks 0-39.
Original Source Code Comment: WE AT 'SECRET TRACK
5C50
LD A,(HL) 7E
Fetch the sector number from SECTAB into Register A again (the flags of the CP stay).
Original Source Code Comment: GET THE SECTOR NUMBER BACK
5C51
If the CARRY FLAG is set (track 0-39), JUMP to 5C55H (TRIM21).
Original Source Code Comment: NO, CONTINUE
5C53
OR 80HOR SSEC F6 80
OR Register A with 80H (SSEC): on tracks 40 and above the sector numbers have bit 7 set.
Original Source Code Comment: SET THE CORRECT SECTOR NUMBER
5C55TRIM21
INC HL 23
TRIM21: INCrement Register Pair HL to the next entry of SECTAB.
Original Source Code Comment: BUMP FOR NEXT TIME
5C56
LD (5C1DH),HLLD (CSECTB),HL 22 1D 5C
Store it into 5C1DH-5C1EH (CSECTB).
Original Source Code Comment: AND SAVE IT
5C59
LD H,(IX+1)LD H,(IX+SECADD+MSB) DD 66 01
Fetch the high byte of the sector byte's address from IX+1 (SECADD+MSB in DDST) into Register H.
Original Source Code Comment: WHERE TO PUT SECTOR NUMBER
5C5C
LD L,(IX+0)LD L,(IX+SECADD+LSB) DD 6E 00
Fetch the low byte from IX+0 into Register L: HL = 5BD9H (DDSEC).
Original Source Code Comment: IN EXPANDABLE TABLE
5C5F
LD (HL),A 77
Store the sector number (Register A) into DDSEC.
Original Source Code Comment: STORE SECTOR NUM IN EXPANDABLE TABLE
5C60
POP HL E1
Restore Register Pair HL (the start of part 2) from the STACK.
Original Source Code Comment: GET BACK ADDRESS OF TABLE ENTRY
5C61
PUSH HL E5
Save it on the STACK again for the next sector.
Original Source Code Comment: RE-SAVE FOR LOOPING
5C62TRKIM3
TRKIM3: GOSUB to 5C8CH (EXPAND) to write the table entry at HL into the image at DE; the CARRY FLAG is set while HL is below BC (5C07H).
Original Source Code Comment: EXPAND CURRENT TABLE ENTRY
5C65
If the CARRY FLAG is set (more entries in part 2), LOOP BACK to 5C62H (TRKIM3).
Original Source Code Comment: REPEAT WHILE HL .LT. BC
5C67
POP HL E1
Restore Register Pair HL (the start of part 2) from the STACK.
Original Source Code Comment: POINT BACK TO TABLE START (PART 2)
5C68
PUSH HL E5
Save it on the STACK again.
Original Source Code Comment: RE-SAVE FOR LOOPING
5C69
JUMP to 5C45H (TRKIM2) for the next sector.
Original Source Code Comment: REPEAT TILL ALL SECTORS EXPANDED

5C6BH - TRKIM4 - The last part, then restore the registers

5C6BTRKIM4
POP HL E1
TRKIM4: Restore Register Pair HL (the start of part 2) from the STACK and drop it.
Original Source Code Comment: CLEAN UP STACK
5C6C
GOSUB to 5C7BH (TBLBMP): HL = the start of part 3 (5C07H), BC = its end (5C0AH).
Original Source Code Comment: GET ADDRESSES FOR TABLE (PART 3)
5C6FTRKIM5
TRKIM5: GOSUB to 5C8CH (EXPAND) to write the table entry at HL into the image at DE; the CARRY FLAG is set while HL is below BC.
Original Source Code Comment: EXPAND TABLE
5C72
If the CARRY FLAG is set (more entries in part 3), LOOP BACK to 5C6FH (TRKIM5). The image is now 7010 bytes, 6200H-7D61H.
Original Source Code Comment: REPEAT WHILE HL .LT. BC
5C74
POP IY FD E1
Restore Register Pair IY (TRKNN) from the STACK.
Original Source Code Comment: RESTORE REGISTERS
5C76
POP AF F1
Restore Register Pair AF from the STACK.
5C77
POP HL E1
Restore Register Pair HL (FORM's pointer into the flaw table) from the STACK.
5C78
POP DE D1
Restore Register Pair DE (D = FORM's retry count) from the STACK.
5C79
POP BC C1
Restore Register Pair BC (C = the track number, B = FORM's track count) from the STACK.
5C7A
RET C9
RETurn to FORM.
Original Source Code Comment: AND EXIT

5C7BH - TBLBMP - Fetch the start (HL) and end (BC) of the next table part from TRKNN at IY and move IY on

5C7BTBLBMP
LD H,(IY+1)LD H,(IY+BEGADD+MSB) FD 66 01
TBLBMP: Fetch the high byte of the part's start address from IY+1 into Register H.
Original Source Code Comment: TABLE PART BEGINNING ADDRESS
5C7E
LD L,(IY+0)LD L,(IY+BEGADD+LSB) FD 6E 00
Fetch the low byte from IY+0 into Register L: HL = the start of the table part.
5C81
LD B,(IY+3)LD B,(IY+ENDADD+MSB) FD 46 03
Fetch the high byte of the part's end address from IY+3 into Register B.
Original Source Code Comment: TABLE PART ENDING ADDRESS
5C84
LD C,(IY+2)LD C,(IY+ENDADD+LSB) FD 4E 02
Fetch the low byte from IY+2 into Register C: BC = the end of the table part (the start of the next).
5C87
INC IY FD 23
INCrement Register Pair IY by 1.
Original Source Code Comment: BUMP IY TO NEXT TABLE ENTRY
5C89
INC IY FD 23
INCrement Register Pair IY by 1 again: IY points at the next entry of TRKNN (the end of this part is the start of the next).
5C8B
RET C9
RETurn with HL = the start and BC = the end of the part.
Original Source Code Comment: EXIT

5C8CH - EXPAND - Write the table entry at HL into the image at DE. Exit: HL = the next entry, DE after the bytes written, CARRY while HL is below BC (the end of the part), A as on entry.

5C8CEXPAND
LD (5CBCH),ALD (WORK),A 32 BC 5C
EXPAND: Store Register A (the sector number, when TRKIMG has one in A) into 5CBCH (WORK), to give it back at the end.
Original Source Code Comment: SAVE CURRENT SECTOR NUMBER
5C8F
PUSH BC C5
Save Register Pair BC (the end of the table part) on the STACK.
Original Source Code Comment: SAVE TABLE END ADDRESS
5C90
LD C,(HL) 4E
Fetch the low byte of the entry's count at HL into Register C.
Original Source Code Comment: GET LSB OF COUNT
5C91
INC HL 23
INCrement Register Pair HL by 1.
5C92
LD B,(HL) 46
Fetch the high byte of the count into Register B.
Original Source Code Comment: GET MSB OF COUNT
5C93
INC HL 23
INCrement Register Pair HL by 1 to the data byte of the entry.
5C94
INC BC 03
INCrement Register Pair BC by 1: a count of FFFFH becomes 0000H.
Original Source Code Comment: SEE IF THIS IS THE COPYRIGHT MSG
5C95
LD A,B 78
LET Register A = Register B.
5C96
OR C B1
OR Register C into Register A: the Z FLAG is set when the count was FFFFH (the copyright text).
5C97
DEC BC 0B
DECrement Register Pair BC by 1, back to the count (the flags stay).
Original Source Code Comment: PUT BC BACK CORRECTLY
5C98
If the NZ FLAG is set (an ordinary entry), JUMP to 5CA2H (NOCOPY).
Original Source Code Comment: NO, NOT COPYRIGHT MSG
5C9A
LD BC,0010H 01 10 00
LET Register Pair BC = 0010H (16), the length of the copyright text.
Original Source Code Comment: SET FOR 16 CHARS
5C9D
LDIR ED B0
Copy the 16 bytes at HL (COPY, 5BF1H) into the image at DE (LDIR): HL ends at the next entry, DE after the text.
Original Source Code Comment: PUT IT INTO THE SECTOR BUFFER
5C9F
PUSH HL E5
Save Register Pair HL (the next entry) on the STACK for EXPND1.
Original Source Code Comment: PUT IT ON THE STACK
5CA0
JUMP to 5CB1H (EXPND1).
Original Source Code Comment: AND EXIT

5CA2H - NOCOPY - An ordinary entry: write its byte as many times as its count

5CA2NOCOPY
LD A,(HL) 7E
NOCOPY: Fetch the data byte of the entry at HL into Register A.
Original Source Code Comment: GET THE BYTE OF DATA FROM TABLE
5CA3
INC HL 23
INCrement Register Pair HL by 1 to the next entry.
5CA4
PUSH HL E5
Save Register Pair HL (the next entry) on the STACK.
Original Source Code Comment: SAVE THE POINTER
5CA5
LD (DE),A 12
Store the data byte (Register A) into the image at DE.
Original Source Code Comment: STORE FIRST BYTE IN TRACK BUFFER
5CA6
INC DE 13
INCrement Register Pair DE by 1.
Original Source Code Comment: BUMP ADDRESS TO NEXT IN TRACK BUFFER
5CA7
DEC BC 0B
DECrement Register Pair BC (the count) by 1: one byte written.
Original Source Code Comment: NUMBER OF CHARS IS LESS ONE NOW
5CA8
LD A,BCR BC 78
LET Register A = Register B.
Original Source Code Comment: WE DONE?
5CA9
OR C B1
OR Register C into Register A: the Z FLAG is set when BC is 0000H.
5CAA
If the Z FLAG is set (the count was 1), JUMP to 5CB1H (EXPND1).
Original Source Code Comment: YES, EXIT
5CAC
PUSH DE D5
Save Register Pair DE (the next byte of the image) on the STACK.
Original Source Code Comment: ADDR OF NEXT CHAR IN TRACK BUFFER
5CAD
POP HL E1
Restore it into Register Pair HL.
Original Source Code Comment: DUPLICATE VALUE IN HL
5CAE
DEC HL 2B
DECrement Register Pair HL by 1: HL points at the byte just written.
Original Source Code Comment: POINT HL TO 1ST CHAR STORED
5CAF
LDIR ED B0
Copy it forward BC times (LDIR): the data byte fills the rest of the count; DE ends after the run.
Original Source Code Comment: FILL TRACK BUFFER WITH THIS CHAR
5CB1EXPND1
POP HL E1
EXPND1: Restore Register Pair HL (the next entry) from the STACK.
Original Source Code Comment: GET BACK CURRENT TABLE ENTRY ADDRESS
5CB2
POP BC C1
Restore Register Pair BC (the end of the table part) from the STACK.
Original Source Code Comment: GET BACK TABLE END ADDRESS
5CB3
PUSH HL E5
Save Register Pair HL (the next entry) on the STACK.
Original Source Code Comment: RESAVE CURRENT TABLE ENTRY ADDRESS
5CB4
OR A B7
OR Register A with itself to clear the CARRY FLAG for the SBC.
Original Source Code Comment: CLEAR CARRY FLAG
5CB5
SBC HL,BC ED 42
SUBtract Register Pair BC (the end of the part) from HL: the CARRY FLAG is set while the next entry is below the end.
Original Source Code Comment: SET FLAGS FOR TABLE END CHECK
5CB7
POP HL E1
Restore Register Pair HL (the next entry) from the STACK; the flags of the SBC stay.
Original Source Code Comment: RESTORE ORIGINAL VALUE TO HL
5CB8
LD A,(5CBCH)LD A,(WORK) 3A BC 5C
Fetch the byte saved at 5CBCH (WORK) back into Register A.
Original Source Code Comment: RESTORE CURRENT SECTOR NUMBER
5CBB
RET C9
RETurn to TRKIMG with CARRY (more entries in this part) or NC (the part is done).
Original Source Code Comment: EXIT WITH FLAGS SET
5CBCWORK
DEFB 00H 00
WORK: Register A as it was when EXPAND was called (the source: temp save location).
Original Source Code Comment: TEMP SAVE LOCATION

5CBDH - FORM - Format and verify the 40 tracks (4 tries each), mark the flawed tracks in the new GAT and show how many there are

5CBDFORM
LD HL,5F00HLD HL,DUM1 21 00 5F
FORM: LET Register Pair HL = 5F00H (DUM1), the 256 bytes that become the empty HIT and directory sectors.
Original Source Code Comment: HL => DUMMY DIRECTORY SECTOR
5CC0
LD DE,5F01HLD DE,DUM1+1 11 01 5F
LET Register Pair DE = 5F01H (DUM1 + 1), so the LDIR copies the cleared byte forward.
Original Source Code Comment: CLEAR IT OUT
5CC3
LD BC,00E0HLD BC,SECTOR-32 01 E0 00
LET Register Pair BC = 00E0H (224, SECTOR minus 32) for the LDIR.
5CC6
LD (HL),00HLD (HL),0 36 00
Store 00H at 5F00H.
Original Source Code Comment: THE CLEAR BYTE
5CC8
LDIR ED B0
Copy the 00H forward (LDIR): 5F00H-5FE0H become 00H; HL ends at 5FE0H, DE at 5FE1H.
Original Source Code Comment: CLEAR IT OUT
5CCA
LD BC,001FHLD BC,31 01 1F 00
LET Register Pair BC = 001FH (31) for the LDIR.
Original Source Code Comment: NUMBER OF BYTES TO WRITE
5CCD
LD (HL),0FFHLD (HL),-1 36 FF
Store FFH at 5FE0H.
Original Source Code Comment: FILL SYSTEM EXTENTS WITH FF'S
5CCF
LDIR ED B0
Copy the FFH forward (LDIR): 5FE0H-5FFFH (offsets E0H-FFH, the system file pointers of the HIT) become FFH.
5CD1
LD C,0FFHLD C,-1 0E FF
LET Register C = FFH, the track number before track 0 (INC C at 5CE4H makes it 00H).
Original Source Code Comment: SET FOR TRACK NUMBER 0-1
5CD3
LD B,28HLD B,MAXTRK 06 28
LET Register B = 28H (40, MAXTRK), the number of tracks to format, counted down at 5D45H.
Original Source Code Comment: SET FOR NUMBER OF TRACKS TO DO
5CD5
LD HL,6160HLD HL,FLAWD 21 60 61
LET Register Pair HL = 6160H (FLAWD), the flaw table (offset 60H) of the new GAT at 6100H: one byte per track, FFH = flawed.
Original Source Code Comment: POINT TO GAT FLAW AREA
5CD8
XOR A AF
Set Register A to 00H.
Original Source Code Comment: CLEAR A
5CD9
LD (4E80H),ALD (FLAWC),A 32 80 4E
Store 00H into 4E80H (FLAWC), the number of flawed tracks.
Original Source Code Comment: CLEAR FLAW COUNT
5CDC
LD IX,5BBDHLD IX,DDST DD 21 BD 5B
LET Register Pair IX = 5BBDH (DDST), the addresses of the track and sector bytes of the table, for TRKIMG.
Original Source Code Comment: SECTOR/TRACK UPDATA ADDRESS
5CE0
LD IY,5BB5HLD IY,TRKNN FD 21 B5 5B
LET Register Pair IY = 5BB5H (TRKNN), the addresses of the three table parts, for TBLBMP.
Original Source Code Comment: POINT TO DOUB DENS TRACK TABLE
5CE4FORMDD
INC C 0C
FORMDD: INCrement Register C, the track number: 00H on the first pass (Z FLAG set), then 01H-27H.
Original Source Code Comment: BUMP TRACK NUMBER TO NEXT ONE
5CE5
If the NZ FLAG is set (not track 0), GOSUB to 5B35H (STEPR) to step the head in one track and store C in SEKTRK; STEPR returns with the Z FLAG set.
Original Source Code Comment: IF C .NE. 0 THEN STEP IN
5CE8
If the NZ FLAG is set, JUMP to 4E4AH (ABRT). Both ways here the Z FLAG is set (INC C to 00H, or the XOR A at the end of STEPR), so the jump is not taken.
Original Source Code Comment: IF ERROR, EXIT
5CEB
LD D,04HLD D,BCKTRY+2 16 04
LET Register D = 04H (the source's BCKTRY + 2), the tries for this track.
Original Source Code Comment: SET A RETRY COUNT
5CEDRETRY2
RETRY2: GOSUB to 5C1FH (TRKIMG) to build the image of track C at 6200H.
Original Source Code Comment: BUILD A TRACK IN MEMORY
5CF0
PUSH BCSAVE C5
Save Register Pair BC (C = the track, B = the tracks left) on the STACK.
5CF1
PUSH DE D5
Save Register Pair DE (D = the tries left) on the STACK.
5CF2
PUSH HL E5
Save Register Pair HL (the flaw byte of this track) on the STACK.
5CF3
LD A,0D0HLD A,CTERM 3E D0
LET Register A = D0H (CTERM), the FDC's Force Interrupt command.
Original Source Code Comment: TERMINATE ANY OPERATION
5CF5
OUTput D0H to port F0H to stop whatever the FDC is doing.
5CF7
LD HL,5BAFHLD HL,FORASC 21 AF 5B
LET Register Pair HL = 5BAFH (FORASC), the two digits of the track number in 'Formatting track 00'.
Original Source Code Comment: PLACE TO STORE ASCII TRACK NUMBER
5CFA
LD A,(5BD3H)LD A,(DDTRK) 3A D3 5B
Fetch the track number from 5BD3H (DDTRK, stored by TRKIMG) into Register A.
Original Source Code Comment: GET THE TRACK
5CFD
GOSUB to 5B55H (ASCII) to write it as two decimal digits at 5BAFH-5BB0H.
Original Source Code Comment: MAKE IT ASCII
5D00
LD HL,5B9DHLD HL,FORMSG 21 9D 5B
LET Register Pair HL = 5B9DH (FORMSG), the text 1DH 'Formatting track nn '.
Original Source Code Comment: POINT TO 'FORMATTING' MESSAGE
5D03
GOSUB to 021BH (the ROM's PRINT routine) to show it.
Original Source Code Comment: PRINT IT ON THE SCREEN
5D06
LD A,(5BD3H)LD A,(DDTRK) 3A D3 5B
Fetch the track number from 5BD3H (DDTRK) into Register A.
Original Source Code Comment: GET THE TRACK NUMBER
5D09
CP 16HCP 22 FE 16
Compare Register A with 16H (22): the CARRY FLAG is set for tracks 0-21.
Original Source Code Comment: WE AT TRACK 22?
5D0B
If the CARRY FLAG is set (track 0-21), JUMP to 5D15H (NOCOMP).
Original Source Code Comment: NO, CONTINUE
5D0D
LD A,(4E7DH)LD A,(FDRIVE) 3A 7D 4E
Fetch the drive select byte from 4E7DH (FDRIVE) into Register A.
Original Source Code Comment: GET THE DRIVE BYTE
5D10
SET 5,A CB EF
SET bit 5 of Register A, the write precompensation bit of port F4H, for the inner tracks.
Original Source Code Comment: SET THE PRE-COMP BIT
5D12
LD (4E7DH),ALD (FDRIVE),A 32 7D 4E
Store the select byte back into 4E7DH (FDRIVE).
5D15NOCOMP
LD HL,6200HLD HL,BUFF 21 00 62
NOCOMP: LET Register Pair HL = 6200H (BUFF), the track image.
Original Source Code Comment: HL => FORMAT DATA
5D18
GOSUB to 5AB0H (TRKWRT) to write the track image with the FDC's Write Track command. The status it returns is not tested (the source has the test starred out).
Original Source Code Comment: DO A 'TRACK' WRITE
5D1B
POP HLRSTR E1
Restore Register Pair HL (the flaw byte) from the STACK.
5D1C
POP DE D1
Restore Register Pair DE (D = the tries left) from the STACK.
5D1D
POP BC C1
Restore Register Pair BC (the track and the count) from the STACK.
5D1E
PUSH BCSAVE C5
Save Register Pair BC on the STACK again.
5D1F
PUSH DE D5
Save Register Pair DE on the STACK again.
5D20
PUSH HL E5
Save Register Pair HL on the STACK again.
5D21
GOSUB to 5AEEH (VERFIT) to read back the 18 sectors of the track: Z = all read, NZ = a sector failed.
Original Source Code Comment: GO VERIFY TRACK
5D24
POP HLRSTR E1
Restore Register Pair HL (the flaw byte) from the STACK.
5D25
POP DE D1
Restore Register Pair DE (D = the tries left) from the STACK.
5D26
POP BC C1
Restore Register Pair BC (the track and the count) from the STACK; the flags of VERFIT stay.
5D27
If the Z FLAG is set (the track verified), JUMP to 5D44H (GOOD2).
Original Source Code Comment: GOOD VERIFY, GO
5D29WRTER2
WRTER2: GOSUB to 4566H (TERM in SYS0) to send the Force Interrupt command (D0H) to the FDC.
Original Source Code Comment: TERMINATE
5D2C
GOSUB to 4400H (DELLY in SYS0), a short delay.
5D2F
GOSUB to 4566H (TERM) again.
Original Source Code Comment: TERMINATE
5D32
GOSUB to 4400H (DELLY) again.
5D35
GOSUB to 4566H (TERM) a third time.
Original Source Code Comment: TERMINATE
5D38
DEC D 15
DECrement Register D, the tries left.
Original Source Code Comment: DEC THE RETRY COUNT
5D39
If the NZ FLAG is set (tries left), LOOP BACK to 5CEDH (RETRY2) to build and write the track again.
Original Source Code Comment: CONTINUE IF NOT EXHAUSTED
5D3B
LD A,(4E80H)LD A,(FLAWC) 3A 80 4E
Four tries failed: fetch the flaw count from 4E80H (FLAWC) into Register A.
Original Source Code Comment: GET FLAW COUNT
5D3E
INC A 3C
INCrement Register A by 1.
Original Source Code Comment: BUMP IT
5D3F
LD (4E80H),ALD (FLAWC),A 32 80 4E
Store it back into 4E80H (FLAWC).
Original Source Code Comment: SAVE IT
5D42
LD (HL),0FFHLD (HL),0FFH 36 FF
Store FFH into the flaw byte of this track at HL: the GAT marks the track flawed.
Original Source Code Comment: MARK GAT, THIS IS BAD TRACK
5D44GOOD2
INC HL 23
GOOD2: INCrement Register Pair HL to the flaw byte of the next track.
Original Source Code Comment: BUMP TO NEXT GAT LOCATION
5D45
DEC B 05
DECrement Register B, the tracks left.
Original Source Code Comment: DEC THE TRACK COUNTER
5D46
If the NZ FLAG is set (more tracks), JUMP to 5CE4H (FORMDD).
Original Source Code Comment: COUNTINUE FOR TRACK COUNT
5D49
LD A,(4E7DH)LD A,(FDRIVE) 3A 7D 4E
Fetch the drive select byte from 4E7DH (FDRIVE) into Register A.
Original Source Code Comment: GET THE DRIVE BITS
5D4C
RES 5,A CB AF
RESet bit 5 of Register A, the write precompensation bit.
Original Source Code Comment: INSURE PRE-COMP OFF
5D4E
LD (4E7DH),ALD (FDRIVE),A 32 7D 4E
Store the select byte back into 4E7DH (FDRIVE).
5D51
LD A,(4E80H)LD A,(FLAWC) 3A 80 4E
Fetch the flaw count from 4E80H (FLAWC) into Register A.
Original Source Code Comment: GET THE FLAW COUNT
5D54
LD HL,5D61HLD HL,FLAWX 21 61 5D
LET Register Pair HL = 5D61H (FLAWX), the two digits in 'nn Flawed Tracks'.
Original Source Code Comment: PLACE TO STORE ASCII
5D57
PUSH HL E5
Save Register Pair HL (5D61H) on the STACK.
Original Source Code Comment: SAVE POINTER
5D58
GOSUB to 5B55H (ASCII) to write the flaw count as two decimal digits at 5D61H-5D62H.
Original Source Code Comment: CONVERT IT
5D5B
POP HL E1
Restore Register Pair HL (5D61H) from the STACK.
Original Source Code Comment: GET POINTER BACK
5D5C
DEC HL 2B
DECrement Register Pair HL by 1 to 5D60H, the 0AH in front of the text (the source: this has to be here).
Original Source Code Comment: BACK UP TO THE CR/LF
5D5D
JUMP to 021BH (the ROM's PRINT routine) to show 0AH 'nn Flawed Tracks' 0DH; its RET returns to FOMAT.
Original Source Code Comment: PRINT AND RETURN

5D60H - FLAWX - The 'nn Flawed Tracks' message

5D60
DEFB 0AH 0A
0AH (line feed), the first byte of the message FORM shows at the end (5D5CH points HL here).
Original Source Code Comment: THIS HAS TO BE HERE!!!
5D61-5D70FLAWX
DEFM "00 Flawed Tracks" 30 30 20 46 6C 61 77 65 64 20 54 72 61 63 6B 73
FLAWX: '00 Flawed Tracks', the flaw count written into the first two characters by ASCII (5D58H).
5D71
DEFB 0DH 0D
0DH: ends the message with a new line (the source's ~).

5E00H - SPAR_ - The buffers (the source's BUFFERS). These are not in the file.

5D72-5DFF
ORG $,256
Not in the file: ORG $,256 moves on to the next 256 byte page for the buffers.
5E00-5EFFSPAR_
DEFS 0100H
SPAR_: 256 bytes where RBOOT keeps a copy of the boot sector of the source (5274H); CLRBUF clears it. Not in the file.
5F00-5FFFDUM1
DEFS 0100H
DUM1: 256 bytes, the empty sector FORM builds (00H, FFH at offsets E0H-FFH) and BOTWRI writes as the HIT and, with the copyright text at F0H-FFH, as the directory sectors 3-18. Not in the file.
6000-60FFSGAT
DEFS 0100H
SGAT: 256 bytes; the first 41 hold the allocation bytes of the source GAT (DGAT), which FALOC clears gran by gran as BACKUP copies them. CLRGAT and BPREPX clear 6000H-61FFH. Not in the file.
6100-615FFGAT
DEFS 60H
FGAT: the first 96 bytes (60H, the source's FLAW) of the GAT being built: the allocation bytes (one per track), for FORMAT the boot gran (01H at 6100H) and the directory track (3FH at 6111H), for BACKUP those of the source with the grans of files taken out released. Not in the file.
6160-61FFFLAWD
DEFS 0A0H
FLAWD: the rest of that GAT from offset 60H: the flaw table (6160H-6187H, FFH = flawed track), the master password code at 61CEH (offset CEH), the name at 61D0H (D0H) and the date at 61D8H (D8H). BOTWRI writes 6100H-61FFH as the GAT of a new diskette. Not in the file.
6200BUFF
EQU $
BUFF: the main buffer from 6200H up: the track image of FORM (6200H-7D61H), the gran records of BACKUP (770 bytes each, up to MEMTOP) and the directory track (6200H-7413H). Not in the file.
 
END 57A1H