LDOS 5.3.1 for the Model III - PATCH/CMD Disassembled

Page Customization

Introduction/Summary

LDOS 5.3.1 PATCH/CMD Disassembly - Change, Remove and Yank Patches in a File (Model III)

PATCH changes the bytes of a disk file, or adds load records to a program, from patch lines: PATCH filespec1 [USING] filespec2 (parms) reads the lines from a file (/FIX by default), PATCH filespec (patch lines) takes them from the command line, separated by colons. The file to patch gets /CMD when it has no extension (5200H). The parameters are REMOVE, OPTION=N and YANK.

The file is a load module of 2379 bytes: a copyright record, the code and data 5200H-5AEFH in nine load blocks, and the transfer address 5200H.

The Patch Lines

LineWhat the code does with it
.A comment, passed over (538CH).
Drr,bb=dataWrites the data into record rr (hex) of the file from byte bb on, and writes the record back (539DH). The data is hex bytes with one character (a space or a comma) between them, or a quoted string; a semicolon starts a comment.
Frr,bb=dataThe bytes a D line expects in the file: it must be the next line that is not a comment, with the same rr,bb, and its data must be in the file, or nothing is written (FIND line mismatch, 57D4H). With OPTION=N or O=N the check is not made.
X'nnnn'=dataA load block for address nnnn, put with the other X lines and a record of type 07H naming the patch just before the transfer record of the program (5340H).
LnnThe member with member byte nn of a library file: the X lines that follow are put at the end of that member, and the starts of the members after it are moved on (54D3H).
REMOVE, REach D line and its F line change places, after the D line's data was found in the file, so the bytes of the F line are written back (581AH).
OPTION=N, O=ND lines are written without an F line check (54A4H).
YANK, YThe load blocks after the record of type 07H with the patch's name become records of type 10H, which the loader passes over (5411H). The name is the patch file's name, or CLP without one.

How It Works

The patch lines are first read into memory from 5F00H, a colon outside quotes ending a line, with 03H at the end (525EH, 52A5H). They are then gone through twice (52FCH): the first pass checks every D line against its F line and the file and writes nothing; the second pass does the work and closes the file. The new load records are built from 7300H and put into the file at its place with two control blocks of the same file, one reading the old bytes and one writing, so that every old byte after the place is moved on by the length of the records (5605H). PATCH makes no RST 28H request of its own: it uses the supervisor call vectors (402DH, 4030H, 4409H, 441CH-4467H and 428AH) and the ROM's byte routines.

About This Page

The Model III file is the Model I file of the same release with the same code at the same addresses; its 12 different bytes are the operands of nine calls of the resident vectors: @FEXT 444BH (521BH, 5237H; Model I 4473H), @PARAM 4454H (5272H; Model I 4476H), @LOGOT 428AH (5386H, 5883H, 5899H; Model I 447BH), @RWRIT 4461H (5402H, 547EH; Model I 4457H) and @RREAD 445EH (562AH; Model I 4454H).

Every byte of the file is shown at its address. The ROM routines named are those of the Model III ROM, version 3.1; the three it calls, 0013H, 001BH and 0033H, are the same as in the Level II ROM of the Model I. Found in the code: a record number of four hex digits keeps only its last two (53A6H), though the check of an F line expects that form; after an L line only X lines can follow (555BH); the member header search reads from wherever the file stands (56BFH); after the first member header it moves, the library map compares the others with 0000H (56FEH); the area from 7300H holds the rest of the file after the place of the new records with no test of the top of memory (5605H); the patch file is not closed; a last line that ends at the 03H with no 0DH leaves the line pointer past the text (538CH); the character after the closing apostrophe of X'nnnn' is not tested; a hex digit can also be one of the characters 57H-60H (W to the grave accent), and a first digit one of 3AH-40H (56ADH); the patch file is opened with the length of its name as the record length (52A5H); the yank passes over a load block whose length byte is 1 or 2 by that many bytes only (5411H); in a patch from the command line a colon or a right parenthesis ends a line even inside quotes.

Memory Map

Load Blocks

The file starts with a copyright record (type 1FH), then 9 load blocks with 2288 bytes, 5200H-5AEFH, and the transfer address 5200H.

AddressContents
5200H-52FFH256 bytes
5300H-53FFH256 bytes
5400H-54FFH256 bytes
5500H-55FFH256 bytes
5600H-56FFH256 bytes
5700H-57FFH256 bytes
5800H-58FFH256 bytes
5900H-59FFH256 bytes
5A00H-5AEFH240 bytes

The Parts of the File

AddressContents
5200H-52FBHThe start: the two files, the parameters, the patch text read into memory.
52FCH-5408HThe two passes, the end, a line passed over, the D line written.
5409H-54D2HR, Y (the yank) and O.
54D3H-5667HL, the load records read, the new records built and put into the file.
5668H-57A7HHex bytes, the member headers, a byte read, the library map.
57A8H-589EHThe first pass, the check of an F line, the removal, small routines and the errors.
589FH-5AEFHThe texts, the name of the patch, the table of @PARAM and the cells.
5AF0H-72FFHNot in the file: the control blocks, the buffers and the patch text.
7300H upNot in the file: the new records and the old bytes moved on, or the copy of the member headers.

Sections of the Disassembly

AddressContents
5200HThe Start: the Program File
5229HThe Patch File and Its Name
525EHThe Parameters or the Patch Lines in Parentheses
52A5HRead the Patch File
52FCHThe Patch Lines, Two Passes
5340HX: a Patch by Load Address
5375HThe End: Close the File
538CHPass Over a Line
539DHD: Change Bytes in the File
53A6HRead rr,bb and Position the File
53D0HThe Data After the Equals Sign
5409HR: Remove
5411HY: Yank a Patch
54A4HO: the Option
54D3HL: a Member of a Library File
5526HRead the Load Records to the End
555BHBuild the Patch Records
5605HPut the Records into the File
5668HRead a Hex Byte or a Quoted Character
56ADHThe Value of a Hex Digit
56BFHFind a Member Header
56F7HRead a Byte of the File
56FEHThe Library Map: Move the Members After the Patch
574CHThe Headers After It
577FHWrite the Headers Back
57A2HThe Second Pass
57A8HThe First Pass: Check a Line
57D4HThe First Pass: a D Line
57ECHCheck a Find Line
581AHThe First Pass: Remove a Patch
5834HThe Next Line That Is Not a Comment
5849HCompare or Write a Data Byte
585DHSmall Routines and the Errors
5870HThe Messages That End PATCH
589FHThe Texts
5AC0HThe Name, the Parameter Table and the Cells

Memory and Records PATCH Uses

AddressContents
0013H, 001BH, 0033HThe ROM: $GET (a byte from the file at Register Pair DE), $PUT (a byte to it), the display of a character.
402DH, 4030H@EXIT and @ABORT.
4409H, 441CH, 4424H, 4428H, 4436H, 4442H, 4445H, 445EH, 4461H@ERROR, @FSPEC, @OPEN, @CLOSE, @READ, @POSN, @BKSP, @RREAD, @RWRIT.
4467H, 444BH, 4454H, 428AH@DSPLY, @FEXT, @PARAM, @LOGOT.
Load recordsTypes 01H (a load block: length, address, data), 02H (the transfer address), 03H, 04H (the end of a library member), 05H, 07H (the name of a patch), 08H (a member header: member byte, entry, record, byte), 0AH (the end of the member headers), 10H (a yanked load block), 1FH (a copyright).

Variables

The data of the file and the cells and the buffers above it, then the operands PATCH changes while it runs.

Data in the File and the Memory Above It

Address
Size
Contents
589FH-58A1H
3 bytes
DEFM "CMD"
589FH-58A1H: CMD, the default extension of the file to patch (5218H).
58A2H-58A4H
3 bytes
DEFM "FIX"
58A2H-58A4H: FIX, the default extension of the patch file (5234H).
58A5H
1 byte
DEFB 0AH
58A5H: 0AH, a line feed, the start of the banner (5201H).
58A6H-58DBH
54 bytes
DEFM "PATCH - LDOS Object File Patch Utility - Version 5.3.1"
58A6H-58DBH: the first line of the banner, the name and the version.
58DCH
1 byte
DEFB 0AH
58DCH: 0AH, a line feed after the first line.
58DDH-590DH
49 bytes
DEFM "Copyright 1991 MISOSYS, Inc., All rights reserved"
58DDH-590DH: the second line of the banner, the copyright.
590EH-590FH
2 bytes
DEFB 0AH,0DH
590EH-590FH: 0AH and 0DH, the end of the banner.
5910H-592AH
27 bytes
DEFM "PROGRAM file name required" / DEFB 0DH
5910H-592AH: the message of 5880H and its 0DH.
592BH-5943H
25 bytes
DEFB 1DH / DEFM "Positioning load file" / DEFB 1EH,1DH,03H
592BH-5943H: the status text of 5526H, shown while the load records are read.
5944H-5954H
17 bytes
DEFB 1DH / DEFM "Reading input" / DEFB 1EH,1DH,03H
5944H-5954H: the status text of 52FFH, shown for each patch line.
5955H-5968H
20 bytes
DEFB 1DH / DEFM "Generating patch" / DEFB 1EH,1DH,03H
5955H-5968H: the status text of 555BH, shown while the records are built.
5969H-597CH
20 bytes
DEFB 1DH / DEFM "Installing patch" / DEFB 1EH,1DH,03H
5969H-597CH: the status text of 534FH and 5610H.
597DH-5997H
27 bytes
DEFB 1DH / DEFM "Re-building library map" / DEFB 1EH,1DH,03H
597DH-5997H: the status text of 5519H, shown while the member headers are changed.
5998H-59B2H
27 bytes
DEFB 1DH / DEFM "Yanking patch from file" / DEFB 1EH,1DH,03H
5998H-59B2H: the status text of 5418H, shown while a patch is yanked.
59B3H-59D6H
36 bytes
DEFB 0AH / DEFM "Can't yank, patch not in load file" / DEFB 0DH
59B3H-59D6H: the message of 549EH, after a line feed.
59D7H-59F0H
26 bytes
DEFM "Library overlay not found" / DEFB 0DH
59D7H-59F0H: the message of 5870H and its 0DH, after @LOGOT and before @ABORT.
59F1H-5A07H
23 bytes
DEFM "Invalid library format" / DEFB 0DH
59F1H-5A07H: the message of 5874H and its 0DH, after @LOGOT and before @ABORT.
5A08H-5A20H
25 bytes
DEFM "Patch input format error" / DEFB 0DH
5A08H-5A20H: the message of 588DH and its 0DH, shown after the patch line.
5A21H-5A37H
23 bytes
DEFM "Load file format error" / DEFB 0DH
5A21H-5A37H: the message of 5878H and its 0DH, after @LOGOT and before @ABORT.
5A38H-5A51H
26 bytes
DEFM "Non-hex digit encountered" / DEFB 0DH
5A38H-5A51H: the message of 5889H and its 0DH, shown after the patch line.
5A52H-5A72H
33 bytes
DEFB 0AH / DEFM "Patch(s) successfully installed" / DEFB 0DH
5A52H-5A72H: the closing message after a line feed, the operand of 5383H in the file.
5A73H-5A92H
32 bytes
DEFM "Fix file too big - partition it" / DEFB 0DH
5A73H-5A92H: the message of 587CH and its 0DH, after @LOGOT and before @ABORT.
5A93H-5AA5H
19 bytes
DEFM "FIND line mismatch" / DEFB 0DH
5A93H-5AA5H: the message of 5857H and its 0DH, shown after the patch line.
5AA6H-5ABFH
26 bytes
DEFM "Patch successfully yanked" / DEFB 0DH
5AA6H-5ABFH: the closing message after a yank (5490H).
5AC0H
1 byte
DEFB 03H
5AC0H: the length of the patch's name, 03H for CLP in the file; the length of the patch file's name (525AH). Read at 52A5H, 5450H and 5565H.
5AC1H-5AC8H
8 bytes
DEFM "CLP "
5AC1H-5AC8H: the name of the patch, CLP (command line patch) in the file, the patch file's name after 523DH; it goes into the record of type 07H (555BH) and is looked for by a yank (5456H).
5AC9H-5AD0H
8 bytes
DEFM "REMOVE" / DEFW 5AECH
5AC9H-5AD0H: the parameter REMOVE and the address of its result, 5AECH.
5AD1H-5AD8H
8 bytes
DEFM "R " / DEFW 5AECH
5AD1H-5AD8H: R, the short form of REMOVE, and 5AECH.
5AD9H-5AE0H
8 bytes
DEFM "OPTION" / DEFW 5AEEH
5AD9H-5AE0H: the parameter OPTION and the address of its result, 5AEEH.
5AE1H-5AE8H
8 bytes
DEFM "O " / DEFW 5AEEH
5AE1H-5AE8H: O, the short form of OPTION, and 5AEEH.
5AE9H
1 byte
DEFB 00H
5AE9H: 00H, the end of the table of @PARAM, after the four entries.
5AEAH-5AEBH
2 bytes
DEFW 0000H
5AEAH-5AEBH: the D line being checked in the first pass (57E0H), or its F line for a removal (581EH); read at 57F0H and 5829H.
5AECH-5AEDH
2 bytes
DEFW 0000H
5AECH-5AEDH: the result of REMOVE: 0000H, FFFFH when REMOVE is given; its low byte goes to 57DBH (527BH).
5AEEH-5AEFH
2 bytes
DEFW FFFFH
5AEEH-5AEFH: the result of OPTION: FFFFH, 0000H for OPTION=N; its low byte goes to 57D5H (5275H).
5AF0H-5B0FH
32 bytes
DEFS 32
5AF0H-5B0FH: not in the file. The control block of the file to patch: the file specification as text after @FSPEC (5211H), then the open file (@OPEN 5223H); +01H byte 5AF1H (bit 7 cleared at 54E9H), +05H offset 5AF5H (53CCH, 54FBH), +09H record length 5AF9H (01H for @BKSP, then 00H).
5B10H-5B2FH
32 bytes
DEFS 32
5B10H-5B2FH: not in the file. The control block of the patch file (@FSPEC 522DH, @OPEN 52B2H; its specification read for the name at 523AH); later the second control block of the file to patch, copied at 561FH, its buffer address +03H at 5B13H.
5C00H-5CFFH
256 bytes
DEFS 256
5C00H-5CFFH: not in the file. The buffer of the patch file (52AFH).
5D00H-5DFFH
256 bytes
DEFS 256
5D00H-5DFFH: not in the file. The buffer of the second control block of the file to patch, for the old bytes (5621H).
5E00H-5EFFH
256 bytes
DEFS 256
5E00H-5EFFH: not in the file. The buffer of the file to patch (521EH).
5F00H-72FFH
5120 bytes
DEFS 5120
5F00H-72FFH: not in the file. The patch text: its lines, each ended by 0DH, then 03H (52A0H, 52F9H). From 7300H up, memory the program uses too: the records built by 555BH and the old bytes kept by 5605H, or the copy of the member headers (56FEH).

Operands Changed While It Runs

Address
Size
Contents
52D1H
1 byte
The quote flag of the patch file reader: 22H inside quotes, 00H outside (52D2H, 52E7H, 538DH).
530BH
1 byte
The pass flag: 00H in the first pass, 03H in the second (57A2H).
5384H-5385H
2 bytes
The closing message: 5A52H in the file, 5AA6H after a yank (5493H).
5439H
1 byte
The type of the record being passed over by the yank (5431H).
5681H
1 byte
The quote flag of the hex reader: 22H inside a quoted string (5669H, 5676H).
5741H
1 byte
The member byte of the L line (54D8H).
5769H-576AH
2 bytes
The length of the new records (560DH), read at 5645H and 5658H too.
57D5H
1 byte
The option: FFH in the file, the OPTION result (5278H), AFH or 00H after O (54CCH); 00H writes D lines unchecked.
57DBH
1 byte
The remove flag: 00H in the file, the REMOVE result (527EH), FFH after R (540BH).
5897H-5898H
2 bytes
The patch line being worked on, shown with an error (5307H, 5579H, 57ECH).

Disassembly

5200H - The Start: the Program File

The transfer address, entered with Register Pair HL at the command line after PATCH. The banner is shown; @FSPEC reads the file to patch into the control block at 5AF0H (a device, or no file, gives PROGRAM file name required); it gets /CMD when it has no extension and is opened with the buffer 5E00H and 256 byte records.

5200
PUSH HL E5
Save Register Pair HL (the command line after PATCH) to the stack.
5201
LD HL,58A5H 21 A5 58
Point Register Pair HL to 58A5H, the banner: 0AH, the name and version, 0AH, the copyright, 0AH and 0DH.
5204
GOSUB to 4467H, @DSPLY, to display the text at Register Pair HL up to its 0DH.
5207
POP HL E1
Restore Register Pair HL (the command line) from the stack.
5208
LD DE,5AF0H 11 F0 5A
Point Register Pair DE to 5AF0H, the control block of the file to patch.
520B
GOSUB to 441CH, @FSPEC, to read the file specification at Register Pair HL into the control block at Register Pair DE: the Z FLAG when it is good, Register Pair HL after it.
520E
If the NZ FLAG is set (no file specification), JUMP to 5880H for PROGRAM file name required.
5211
LD A,(DE) 1A
Load Register A with the first character of the specification at Register Pair DE (5AF0H): @FSPEC keeps it there as text until @OPEN.
5212
CP 2AH FE 2A
Compare Register A against 2AH, an asterisk: a device.
5214
If the Z FLAG is set (a device), JUMP to 5880H for PROGRAM file name required.
5217
PUSH HL E5
Save Register Pair HL (the text after the file specification) to the stack.
5218
LD HL,589FH 21 9F 58
Point Register Pair HL to 589FH, the text CMD, the default extension of the file to patch.
521B
GOSUB to 444BH, @FEXT, to give the specification at Register Pair DE the extension at Register Pair HL when it has none.
521E
LD HL,5E00H 21 00 5E
Point Register Pair HL to 5E00H, the 256 byte buffer of the file to patch.
5221
LD B,00H 06 00
Load Register B with 00H, the record length: 256 byte records.
5223
GOSUB to 4424H, @OPEN, to open the file at Register Pair DE (5AF0H) with the buffer at Register Pair HL and the record length in Register B: the Z FLAG when it is open.
5226
If the NZ FLAG is set (it cannot be opened), JUMP to 5867H to show the error and end.

5229H - The Patch File and Its Name

A second file specification, when there is one, is the patch file: it goes into the control block at 5B10H with /FIX when it has no extension, and its name (up to the slash) is copied to 5AC1H with its length at 5AC0H: the name the patch gets in the file (5AC0H holds 03H and CLP from the file, the name of a patch from the command line).

5229
POP HL E1
Restore Register Pair HL (the text after the file to patch) from the stack.
522A
LD DE,5B10H 11 10 5B
Point Register Pair DE to 5B10H, the control block of the patch file.
522D
GOSUB to 441CH, @FSPEC, to read a file specification at Register Pair HL into the control block at Register Pair DE: the Z FLAG when there is one.
5230
If the NZ FLAG is set (no patch file named), JUMP to 525EH for the parameters.
5233
PUSH HL E5
Save Register Pair HL (the text after the patch file) to the stack.
5234
LD HL,58A2H 21 A2 58
Point Register Pair HL to 58A2H, the text FIX, the default extension of the patch file.
5237
GOSUB to 444BH, @FEXT, to give the specification at Register Pair DE (5B10H) the extension at Register Pair HL when it has none.
523A
LD HL,5B10H 21 10 5B
Point Register Pair HL to 5B10H, the specification of the patch file as text.
523D
LD DE,5AC1H 11 C1 5A
Point Register Pair DE to 5AC1H, the name of the patch.
5240
LD B,00H 06 00
Load Register B with 00H, the count of the characters of the name.
5242
LD A,(HL) 7E
Load Register A with the character of the specification at Register Pair HL.
5243
INC HL 23
INCrement Register Pair HL to the next character.
5244
CP 2FH FE 2F
Compare Register A against 2FH, the slash before the extension.
5246
If the Z FLAG is set (the slash), JUMP to 5259H: the name ends.
5248
CP 3AH FE 3A
Compare Register A against 3AH: the CARRY FLAG for a character below 3AH, a digit (or any other character below it).
524A
If the CARRY FLAG is set, JUMP to 5254H to keep the character.
524C
CP 41H FE 41
Compare Register A against 41H, the letter A: the CARRY FLAG for 3AH-40H.
524E
If the CARRY FLAG is set (3AH-40H), JUMP to 5259H: the name ends.
5250
CP 5BH FE 5B
Compare Register A against 5BH, one past Z: the NO CARRY FLAG above the letters.
5252
If the NO CARRY FLAG is set (above Z), JUMP to 5259H: the name ends.
5254
LD (DE),A 12
Store Register A (the character) at Register Pair DE, in the name at 5AC1H.
5255
INC DE 13
INCrement Register Pair DE to the next byte of the name.
5256
INC B 04
INCrement Register B, the count of the characters.
5257
LOOP BACK to 5242H for the next character of the specification.
5259
LD A,B 78
Copy Register B (the length of the name) into Register A.
525A
LD (5AC0H),A 32 C0 5A
Store Register A (the length) at 5AC0H, before the name.
525D
POP HL E1
Restore Register Pair HL (the text after the patch file) from the stack.

525EH - The Parameters or the Patch Lines in Parentheses

After spaces, the end of the line goes on to read the patch file. A left parenthesis must come next (else Parameter error): @PARAM reads REMOVE and OPTION with the table at 5AC9H, and the results go into the operands at 57DBH and 57D5H. When @PARAM can read the parentheses the patch file is read; when it cannot, the text in them is the patch itself: it is copied to 5F00H up to the right parenthesis or the end of the line, a colon becoming 0DH, with 0DH and 03H at the end.

525E
LD A,(HL) 7E
Load Register A with the character at Register Pair HL.
525F
CP 0DH FE 0D
Compare Register A against 0DH, the end of the command line.
5261
If the Z FLAG is set (the end), JUMP to 52A5H to read the patch file.
5263
INC HL 23
INCrement Register Pair HL to the next character.
5264
CP 20H FE 20
Compare Register A (the character) against 20H, a space.
5266
If the Z FLAG is set (a space), LOOP BACK to 525EH.
5268
CP 28H FE 28
Compare Register A against 28H, a left parenthesis.
526A
If the NZ FLAG is set (anything else), JUMP to 586CH for error 2CH, Parameter error.
526D
LD DE,5AC9H 11 C9 5A
Point Register Pair DE to 5AC9H, the table of the parameters REMOVE and OPTION for @PARAM.
5270
PUSH HL E5
Save Register Pair HL (the text after the left parenthesis) to the stack.
5271
DEC HL 2B
DECrement Register Pair HL back to the left parenthesis, where @PARAM starts.
5272
GOSUB to 4454H, @PARAM, to read the parameters at Register Pair HL with the table at Register Pair DE: the Z FLAG when they are good; the results go to 5AECH (REMOVE) and 5AEEH (OPTION).
5275
LD A,(5AEEH) 3A EE 5A
Load Register A with the low byte of the OPTION result from 5AEEH (FFH in the file; 00H for OPTION=N).
5278
LD (57D5H),A 32 D5 57
Store Register A at 57D5H, the operand of LD A at 57D4H: not 00H, a D line must have its F line match.
527B
LD A,(5AECH) 3A EC 5A
Load Register A with the low byte of the REMOVE result from 5AECH (00H in the file; FFH for REMOVE).
527E
LD (57DBH),A 32 DB 57
Store Register A at 57DBH, the operand of LD A at 57DAH: not 00H, the D and F lines are used to remove a patch.
5281
POP HL E1
Restore Register Pair HL (the text after the left parenthesis) from the stack. POP does not change the flags.
5282
If the Z FLAG is set (the parameters were good), JUMP to 52A5H to read the patch file.
5284
LD BC,5F00H 01 00 5F
Point Register Pair BC to 5F00H, the buffer of the patch text.
5287
LD A,(HL) 7E
Load Register A with the character at Register Pair HL.
5288
CP 0DH FE 0D
Compare Register A against 0DH, the end of the command line.
528A
If the Z FLAG is set (the end), JUMP to 529CH to end the text.
528D
CP 29H FE 29
Compare Register A against 29H, a right parenthesis.
528F
If the Z FLAG is set (the right parenthesis), JUMP to 529CH to end the text.
5291
INC HL 23
INCrement Register Pair HL to the next character.
5292
CP 3AH FE 3A
Compare Register A against 3AH, a colon, which separates two patch lines.
5294
If the NZ FLAG is set (not a colon), JUMP to 5298H to keep the character.
5296
LD A,0DH 3E 0D
Load Register A with 0DH: the colon ends a line.
5298
LD (BC),A 02
Store Register A (the character) at Register Pair BC, in the patch text.
5299
INC BC 03
INCrement Register Pair BC to the next byte of the text.
529A
LOOP BACK to 5287H for the next character of the command line.
529C
LD A,0DH 3E 0D
Load Register A with 0DH, the end of the last line.
529E
LD (BC),A 02
Store Register A (0DH) at Register Pair BC, the end of the last line.
529F
INC BC 03
INCrement Register Pair BC to the next byte of the patch text.
52A0
LD A,03H 3E 03
Load Register A with 03H, the end of the patch text.
52A2
LD (BC),A 02
Store Register A (03H) at Register Pair BC, after the last line.
52A3
JUMP to 52FCH to work through the patch text.

52A5H - Read the Patch File

The patch file (5B10H, buffer 5C00H) is opened, unless its name is empty (PROGRAM file name required), and read byte by byte into 5F00H with bit 7 cleared: a colon outside quotes becomes 0DH, so a line can hold two patch lines; the quote flag (52D1H) flips at each quote and is cleared at the end of each line. The end of the file or a 00H byte ends the text with 03H; the text must end below 72FFH (Fix file too big - partition it).

52A5
LD A,(5AC0H) 3A C0 5A
Load Register A with the length of the patch's name from 5AC0H.
52A8
OR A B7
OR Register A with itself: the Z FLAG for an empty name.
52A9
If the Z FLAG is set (no name), JUMP to 5880H for PROGRAM file name required.
52AC
LD DE,5B10H 11 10 5B
Point Register Pair DE to 5B10H, the control block of the patch file.
52AF
LD HL,5C00H 21 00 5C
Point Register Pair HL to 5C00H, the 256 byte buffer of the patch file.
52B2
GOSUB to 4424H, @OPEN, to open the file at Register Pair DE with the buffer at Register Pair HL: the Z FLAG when it is open. Register B, the record length, is not set here: it holds the length of the patch file's name (5256H), or what @PARAM left in it.
52B5
If the NZ FLAG is set (it cannot be opened), JUMP to 5867H to show the error and end.
52B8
LD HL,7300H 21 00 73
Load Register Pair HL with 7300H, the end of the buffer of the patch text.
52BB
DEC HL 2B
DECrement Register Pair HL: 72FFH, the last byte the text can use.
52BC
LD BC,5F00H 01 00 5F
Point Register Pair BC to 5F00H, the buffer of the patch text.
52BF
LD DE,5B10H 11 10 5B
Point Register Pair DE to 5B10H, the control block of the patch file (Register E is used below).
52C2
GOSUB to 0013H, the ROM's $GET, to read the next byte of the file at Register Pair DE into Register A: the NZ FLAG on an error or at the end.
52C5
If the NZ FLAG is set (an error or the end of the file), JUMP to 52F4H.
52C7
AND 7FH E6 7F
Mask Register A to bits 6-0 (AND 7FH): the Z FLAG for 00H.
52C9
If the Z FLAG is set (a 00H byte), JUMP to 52F9H to end the text.
52CB
LD E,A 5F
Copy Register A (the character) into Register E.
52CC
CP 22H FE 22
Compare Register A (the character) against 22H, a quote.
52CE
If the NZ FLAG is set (not a quote), JUMP to 52D5H.
52D0
XOR 00H EE 00
XOR Register A (22H) with the quote flag, the operand at 52D1H (00H outside quotes, 22H inside): Register A = 22H when the quote opens a string, 00H when it closes one.
52D2
LD (52D1H),A 32 D1 52
Store Register A at 52D1H, the quote flag, the operand of XOR at 52D0H.
52D5
LD A,(52D1H) 3A D1 52
Load Register A with the quote flag from 52D1H.
52D8
OR A B7
OR Register A with itself: the NZ FLAG inside quotes.
52D9
LD A,E 7B
Copy Register E (the character) back into Register A. LD does not change the flags.
52DA
If the NZ FLAG is set (inside quotes), JUMP to 52E2H to keep the character as it is.
52DC
CP 3AH FE 3A
Compare Register A (the character) against 3AH, a colon.
52DE
If the NZ FLAG is set (not a colon), JUMP to 52E2H.
52E0
LD A,0DH 3E 0D
Load Register A with 0DH: a colon outside quotes ends a patch line.
52E2
LD (BC),A 02
Store Register A (the character) at Register Pair BC, in the patch text.
52E3
SUB 0DH D6 0D
SUBtract 0DH from Register A: the Z FLAG for the end of a line, the CARRY FLAG for a character below 0DH.
52E5
If the NZ FLAG is set (not the end of a line), JUMP to 52EAH.
52E7
LD (52D1H),A 32 D1 52
Store Register A (00H) at 52D1H: the quote flag is cleared at the end of each line.
52EA
INC BC 03
INCrement Register Pair BC to the next byte of the text.
52EB
PUSH HL E5
Save Register Pair HL (72FFH, the last byte allowed) to the stack.
52EC
SBC HL,BC ED 42
SUBtract Register Pair BC (the next byte of the text) and the CARRY FLAG from Register Pair HL (72FFH): the CARRY FLAG when the text has passed 72FFH. The CARRY FLAG left by the SUB 0DH (a character below 0DH) is taken off too, which ends the text one byte sooner.
52EE
POP HL E1
Restore Register Pair HL (72FFH) from the stack.
52EF
If the CARRY FLAG is set (no more room), JUMP to 587CH for Fix file too big - partition it.
52F2
LOOP BACK to 52BFH for the next byte of the patch file.
52F4
CP 1CH FE 1C
Compare Register A (the error) against 1CH, the end of file.
52F6
If the NZ FLAG is set (another error), JUMP to 5867H to show it and end.
52F9
LD A,03H 3E 03
Load Register A with 03H, the end of the patch text.
52FB
LD (BC),A 02
Store Register A (03H) at Register Pair BC, after the last character.

52FCH - The Patch Lines, Two Passes

The text at 5F00H is gone through twice. Each line starts with its verb; 5897H keeps the start of the line, shown with an error. The first pass (the operand at 530BH is 00H, 57A8H) only checks: R and O are taken, a D line is checked against the F line after it and the bytes in the file, every other line is passed over; at the 03H the operand at 530BH gets 03H and the text is gone through again. The second pass (5311H) does the work: D writes its bytes, X, L and Y change the file, F and comments are passed over, and the 03H closes the file.

52FC
LD HL,5F00H 21 00 5F
Point Register Pair HL to 5F00H, the start of the patch text.
52FF
PUSH HL E5
Save Register Pair HL (the start of the line) to the stack.
5300
LD HL,5944H 21 44 59
Point Register Pair HL to 5944H, the text Reading input between 1DH (the cursor to the start of the line) and 1EH (clear to its end), then 1DH and 03H.
5303
GOSUB to 4467H, @DSPLY, to show the text at Register Pair HL up to its 03H, on the same line each time.
5306
POP HL E1
Restore Register Pair HL (the start of the line) from the stack.
5307
LD (5897H),HL 22 97 58
Store Register Pair HL (the start of the line) at 5897H-5898H, the operand of LD HL at 5896H: the line shown with an error.
530A
LD A,00H 3E 00
Load Register A with the pass flag, the operand at 530BH: 00H in the first pass, 03H in the second (57A2H).
530C
OR A B7
OR Register A with itself: the Z FLAG in the first pass.
530D
LD A,(HL) 7E
Load Register A with the verb, the first character of the line at Register Pair HL. LD does not change the flags.
530E
If the Z FLAG is set (the first pass), JUMP to 57A8H to check the line.
5311
LD A,(HL) 7E
Load Register A with the verb at Register Pair HL.
5312
CP 03H FE 03
Compare Register A against 03H, the end of the text.
5314
If the Z FLAG is set (the end), JUMP to 5375H to close the file and end.
5316
CP 2EH FE 2E
Compare Register A against 2EH, a period: a comment.
5318
If the Z FLAG is set (a comment), JUMP to 538CH to pass over the line.
531B
RES 5,A CB AF
Clear bit 5 of Register A: a lower case verb becomes upper case.
531D
CP 46H FE 46
Compare Register A against 46H, F: a find line, used in the first pass only.
531F
If the Z FLAG is set (F), JUMP to 538CH to pass over the line.
5322
CP 44H FE 44
Compare Register A against 44H, D: a direct change of the file.
5324
If the Z FLAG is set (D), JUMP to 539DH to write its bytes.
5327
CP 59H FE 59
Compare Register A against 59H, Y: from the YANK parameter.
5329
If the Z FLAG is set (Y), JUMP to 5411H to yank the patch.
532C
CP 4CH FE 4C
Compare Register A against 4CH, L: a member of a library file.
532E
If the Z FLAG is set (L), JUMP to 54D3H for the member.
5331
CP 52H FE 52
Compare Register A against 52H, R: from the REMOVE parameter.
5333
If the Z FLAG is set (R), JUMP to 5409H to set the remove flag again.
5336
CP 4FH FE 4F
Compare Register A against 4FH, O: from the OPTION parameter.
5338
If the Z FLAG is set (O), JUMP to 54A4H to read the option again.
533B
CP 58H FE 58
Compare Register A against 58H, X: a patch by load address.
533D
If the NZ FLAG is set (any other verb), JUMP to 588DH for Patch input format error.

5340H - X: a Patch by Load Address

The X lines become load records added to the file just before its transfer record (02H): the file is read from its start (5526H) to that record, the file is moved back one byte onto its type byte, and 555BH builds the records from this line and the X lines after it and puts them in. Every line after the first X must be an X line or a comment.

5340
LD DE,5AF0H 11 F0 5A
Point Register Pair DE to 5AF0H, the control block of the file to patch.
5343
LD BC,0000H 01 00 00
Load Register Pair BC with 0000H, the first record.
5346
GOSUB to 585DH to position the file at Register Pair DE at record 0000H (@POSN).
5349
GOSUB to 5526H to read the load records from there to the first record of type 02H, 03H, 04H or 0AH: Register A = its type.
534C
PUSH AF F5
Save Register Pair AF (Register A = the type found) to the stack.
534D
PUSH HL E5
Save Register Pair HL (the X line) to the stack.
534E
PUSH DE D5
Save Register Pair DE (5AF0H, the control block) to the stack.
534F
LD HL,5969H 21 69 59
Point Register Pair HL to 5969H, the text Installing patch with 1DH, 1EH, 1DH and 03H.
5352
GOSUB to 4467H, @DSPLY, to show the text at Register Pair HL on the status line.
5355
POP DE D1
Restore Register Pair DE (5AF0H) from the stack.
5356
POP HL E1
Restore Register Pair HL (the X line) from the stack.
5357
POP AF F1
Restore Register Pair AF (the type found) from the stack.
5358
CP 02H FE 02
Compare Register A against 02H, the transfer record.
535A
If the NZ FLAG is set (another record ends the program, such as a library's), JUMP to 5878H for Load file format error.
535D
LD A,01H 3E 01
Load Register A with 01H, a record length of one byte.
535F
LD (5AF9H),A 32 F9 5A
Store Register A (01H) at 5AF9H, the record length (+09H) of the control block, so that @BKSP moves back one byte.
5362
GOSUB to 4445H, @BKSP, to move the file at Register Pair DE back one byte, onto the type byte 02H of the transfer record.
5365
If the NZ FLAG is set (an error), JUMP to 5867H to show it and end.
5368
XOR A AF
Load Register A with 00H (XOR A) for the record length.
5369
LD (5AF9H),A 32 F9 5A
Store Register A (00H) at 5AF9H: the record length is 256 again.
536C
GOSUB to 555BH to build the records of the X lines from Register Pair HL on and put them into the file at its position; Register Pair HL comes back at the 03H.
536F
LD A,(HL) 7E
Load Register A with the character at Register Pair HL, the end of the text.
5370
CP 03H FE 03
Compare Register A against 03H: 555BH only RETurns at it.
5372
If the NZ FLAG is set, JUMP to 588DH for Patch input format error.

5375H - The End: Close the File

A new line, the file is closed and the message of the operand at 5384H is shown: Patch(s) successfully installed, or Patch successfully yanked after a yank (5493H); then back to LDOS with @EXIT.

5375
LD A,0DH 3E 0D
Load Register A with 0DH, a new line after the status line.
5377
GOSUB to 0033H, the ROM's display of the character in Register A.
537A
LD DE,5AF0H 11 F0 5A
Point Register Pair DE to 5AF0H, the control block of the file to patch.
537D
GOSUB to 4428H, @CLOSE, to close the file at Register Pair DE.
5380
If the NZ FLAG is set (an error), JUMP to 5867H to show it and end.
5383
LD HL,5A52H 21 52 5A
Point Register Pair HL to the message, the operand at 5384H: 5A52H, Patch(s) successfully installed, or 5AA6H, Patch successfully yanked (5493H).
5386
GOSUB to 428AH, @LOGOT, to show the message at Register Pair HL up to its 0DH and put it in the job log.
5389
JUMP to 402DH, @EXIT, back to LDOS with no error.

538CH - Pass Over a Line

The rest of the line is passed over, to after its 0DH, and the next line is taken; 52D1H, the quote flag of the reader, is cleared on the way. An 03H ends it too, but then Register Pair HL is past the 03H, past the end of the text: a last line with no 0DH before the 03H.

538C
XOR A AF
Load Register A with 00H (XOR A) to clear the quote flag.
538D
LD (52D1H),A 32 D1 52
Store Register A (00H) at 52D1H, the quote flag of the patch file reader.
5390
LD A,(HL) 7E
Load Register A with the character at Register Pair HL.
5391
INC HL 23
INCrement Register Pair HL to the next character.
5392
CP 03H FE 03
Compare Register A against 03H, the end of the text.
5394
If the Z FLAG is set (the end), JUMP to 539AH with Register Pair HL past it.
5396
CP 0DH FE 0D
Compare Register A against 0DH, the end of the line.
5398
If the NZ FLAG is set (not the end), LOOP BACK to 5390H.
539A
JUMP to 52FFH for the next line at Register Pair HL.

539DH - D: Change Bytes in the File

Second pass: Drr,bb=data. 53A6H reads the record and byte and reads the record into the buffer; 53D0H writes the data into it and writes the record back.

539D
GOSUB to 53A6H to read rr,bb at Register Pair HL and position the file there.
53A0
GOSUB to 53D0H to write the data after the equals sign at Register Pair HL into the record, and write it back.
53A3
JUMP to 52FFH for the next line at Register Pair HL.

53A6H - Read rr,bb and Position the File

Register Pair HL = the verb. The record number is one hex byte, or two (then only the second is kept: Register B stays 00H, so a four digit record number loses its first two digits); after the comma the record is read into the buffer of 5AF0H with @POSN and @READ, and the byte (one hex byte) goes into the offset (+05H) of the control block. It RETurns with Register Pair HL after the byte.

53A6
INC HL 23
INCrement Register Pair HL past the verb D or F.
53A7
GOSUB to 5668H to read a hex byte (or a quoted character) at Register Pair HL into Register A: the record number.
53AA
LD B,00H 06 00
Load Register B with 00H, the high byte of the record number.
53AC
LD C,A 4F
Copy Register A (the record number) into Register C: Register Pair BC = the record.
53AD
LD A,(HL) 7E
Load Register A with the character at Register Pair HL after the number.
53AE
CP 2CH FE 2C
Compare Register A (the character) against 2CH, a comma.
53B0
If the Z FLAG is set (a comma), JUMP to 53B6H: the record number is one byte.
53B2
GOSUB to 5668H to read the next hex byte into Register A.
53B5
LD C,A 4F
Copy Register A into Register C: Register Pair BC = 00H and this byte; the first byte is not kept.
53B6
LD DE,5AF0H 11 F0 5A
Point Register Pair DE to 5AF0H, the control block of the file to patch.
53B9
GOSUB to 585DH to position the file at Register Pair DE at record Register Pair BC (@POSN).
53BC
LD A,(HL) 7E
Load Register A with the character at Register Pair HL.
53BD
CP 2CH FE 2C
Compare Register A against 2CH, a comma before the byte.
53BF
If the NZ FLAG is set (no comma), JUMP to 588DH for Patch input format error.
53C2
INC HL 23
INCrement Register Pair HL past the comma to the byte.
53C3
GOSUB to 4436H, @READ, to read the record into the file's buffer at 5E00H.
53C6
If the NZ FLAG is set (an error), JUMP to 5867H to show it and end.
53C9
GOSUB to 5668H to read a hex byte at Register Pair HL into Register A: the byte in the record.
53CC
LD (5AF5H),A 32 F5 5A
Store Register A (the byte) at 5AF5H, the offset in the buffer (+05H) of the control block: the next byte read or written is that byte of the record.
53CF
RET C9
RETurn with Register Pair HL after the byte, at the equals sign.

53D0H - The Data After the Equals Sign

Register Pair HL = the equals sign. Each data byte is a hex byte followed by one character (a space or a comma), or the characters of a quoted string, which ends the line. In the first pass each byte is compared with the file (5849H, FIND line mismatch); in the second it is written into the buffer and the record is written back with @RWRIT at the end of the line. A semicolon outside quotes starts a comment. It RETurns with Register Pair HL after the line's 0DH.

53D0
LD A,(HL) 7E
Load Register A with the character at Register Pair HL.
53D1
CP 3DH FE 3D
Compare Register A against 3DH, an equals sign.
53D3
If the NZ FLAG is set (no equals sign), JUMP to 588DH for Patch input format error.
53D6
INC HL 23
INCrement Register Pair HL past the equals sign or the separator.
53D7
GOSUB to 566CH to read a hex byte, or the next character of a quoted string, at Register Pair HL into Register A; the quote flag (5681H) is kept from the call before.
53DA
GOSUB to 5849H to compare Register A with the next byte of the file (first pass) or write it there (second pass).
53DD
LD A,(HL) 7E
Load Register A with the character at Register Pair HL.
53DE
CP 0DH FE 0D
Compare Register A against 0DH, the end of the line.
53E0
If the Z FLAG is set (the end), JUMP to 53F9H.
53E2
CP 22H FE 22
Compare Register A against 22H, a quote: the end of a string, the last data of the line.
53E4
If the Z FLAG is set (a quote), JUMP to 53F8H to pass over the rest of the line.
53E6
SUB 3BH D6 3B
SUBtract 3BH from Register A: 00H for a semicolon.
53E8
LD C,A 4F
Copy Register A into Register C: 00H for a semicolon.
53E9
LD A,(5681H) 3A 81 56
Load Register A with the quote flag from 5681H: 22H inside a string.
53EC
OR A B7
OR Register A with itself: the NZ FLAG inside a string.
53ED
If the NZ FLAG is set (inside a string), JUMP to 53F3H.
53EF
INC C 0C
INCrement Register C (00H for a semicolon) by one.
53F0
DEC C 0D
DECrement Register C back: the Z FLAG for 00H, a semicolon; Register A is not changed.
53F1
If the Z FLAG is set (a semicolon), JUMP to 53F8H: the rest of the line is a comment.
53F3
OR A B7
OR Register A (the quote flag) with itself: the Z FLAG outside a string.
53F4
If the Z FLAG is set (outside a string), LOOP BACK to 53D6H to pass over the separator after the hex byte.
53F6
LOOP BACK to 53D7H for the next character of the string.
53F8
LD A,(HL) 7E
Load Register A with the character at Register Pair HL.
53F9
INC HL 23
INCrement Register Pair HL to the next character.
53FA
CP 0DH FE 0D
Compare Register A against 0DH, the end of the line.
53FC
If the NZ FLAG is set (not the end), LOOP BACK to 53F8H.
53FE
LD A,(530BH) 3A 0B 53
Load Register A with the pass flag from 530BH: 00H in the first pass.
5401
OR A B7
OR Register A with itself: the NZ FLAG in the second pass.
5402
If the NZ FLAG is set (the second pass), GOSUB to 4461H, @RWRIT, to write the buffer back to the record it came from: the Z FLAG when it is written.
5405
RET Z C8
If the Z FLAG is set (the first pass, or written), RETurn with Register Pair HL at the next line.
5406
JUMP to 5867H to show the error of @RWRIT and end.

5409H - R: Remove

From the REMOVE parameter given in the parentheses as a patch line: the operand at 57DBH gets FFH, so the D lines after it are used to take the patch out (581AH), and the line is passed over.

5409
LD A,FFH 3E FF
Load Register A with FFH, the mark of a removal.
540B
LD (57DBH),A 32 DB 57
Store Register A (FFH) at 57DBH, the operand of LD A at 57DAH: the D lines after it remove their patch.
540E
JUMP to 538CH to pass over the rest of the line.

5411H - Y: Yank a Patch

From the YANK parameter (it is not in the table of @PARAM, so it comes as a patch line). The file is read from its start, record by record, for a record of type 07H whose name is the patch's name (5AC0H: the patch file's name, or CLP). Each load record (type 01H) right after it gets the type 10H instead, which the loader passes over; the file is then closed with Patch successfully yanked. No such record gives Can't yank, patch not in load file. The lines after the Y line are not read.

5411
LD A,(HL) 7E
Load Register A with the character at Register Pair HL, in the Y line.
5412
INC HL 23
INCrement Register Pair HL to the next character of the line.
5413
CP 0DH FE 0D
Compare Register A against 0DH, the end of the Y line.
5415
If the NZ FLAG is set (not the end), LOOP BACK to 5411H.
5417
PUSH HL E5
Save Register Pair HL (the next line) to the stack.
5418
LD HL,5998H 21 98 59
Point Register Pair HL to 5998H, the text Yanking patch from file with 1DH, 1EH, 1DH and 03H.
541B
GOSUB to 4467H, @DSPLY, to show the text at Register Pair HL on the status line.
541E
LD BC,0000H 01 00 00
Load Register Pair BC with 0000H, the first record of the file.
5421
LD DE,5AF0H 11 F0 5A
Point Register Pair DE to 5AF0H, the control block of the file to patch.
5424
GOSUB to 585DH to position the file at Register Pair DE at record 0000H (@POSN).
5427
GOSUB to 0013H, the ROM's $GET, to read the type of the next record into Register A: the NZ FLAG on an error or at the end.
542A
If the NZ FLAG is set (an error or the end of the file), JUMP to 5499H.
542D
CP 07H FE 07
Compare Register A (the type) against 07H, the record of a patch's name.
542F
If the Z FLAG is set (a name), JUMP to 544CH to compare it.
5431
LD (5439H),A 32 39 54
Store Register A (the type) at 5439H, the operand of LD A at 5438H.
5434
GOSUB to 56F7H to read the length of the record into Register A.
5437
LD B,A 47
Copy Register A (the length) into Register B, the count of bytes to pass over.
5438
LD A,00H 3E 00
Load Register A with the type of the record, the operand at 5439H (00H in the file).
543A
DEC A 3D
DECrement Register A: the Z FLAG for type 01H, a load block.
543B
If the NZ FLAG is set (another type), JUMP to 5445H to pass over Register B bytes.
543D
GOSUB to 56F7H to read the low byte of the load address.
5440
DEC B 05
DECrement Register B: the address bytes count in the length.
5441
GOSUB to 56F7H to read the high byte of the load address.
5444
DEC B 05
DECrement Register B again: a length of 0, 1 or 2 leaves 254, 255 or 256 data bytes.
5445
GOSUB to 56F7H to read the next byte of the record, passed over.
5448
DECrement Register B and LOOP BACK to 5445H while it is not 0.
544A
LOOP BACK to 5427H for the next record of the file.
544C
GOSUB to 56F7H to read the length of the name record into Register A.
544F
LD B,A 47
Copy Register A (the length of the name) into Register B.
5450
LD A,(5AC0H) 3A C0 5A
Load Register A with the length of the patch's name from 5AC0H.
5453
CP B B8
Compare Register A against Register B (the length in the record): the Z FLAG when they are the same.
5454
If the NZ FLAG is set (another length), LOOP BACK to 5445H to pass over the name.
5456
LD HL,5AC1H 21 C1 5A
Point Register Pair HL to 5AC1H, the name of the patch.
5459
GOSUB to 56F7H to read the next character of the name in the record.
545C
CP (HL) BE
Compare Register A against the character of the patch's name at Register Pair HL.
545D
INC HL 23
INCrement Register Pair HL to the next character of the patch's name.
545E
If the NZ FLAG is set (another name), JUMP to 5448H to pass over the rest of it, Register B less this character.
5460
DECrement Register B and LOOP BACK to 5459H while it is not 0: the whole name is the same.
5462
GOSUB to 56F7H to read the type of the next record into Register A.
5465
CP 01H FE 01
Compare Register A against 01H, a load block of the patch.
5467
If the NZ FLAG is set (the patch's load blocks are done), JUMP to 548FH.
546A
LD A,01H 3E 01
Load Register A with 01H, a record length of one byte.
546C
LD (5AF9H),A 32 F9 5A
Store Register A (01H) at 5AF9H, the record length (+09H) of the control block, so that @BKSP moves back one byte.
546F
GOSUB to 4445H, @BKSP, to move the file at Register Pair DE back one byte, onto the type byte 01H.
5472
If the NZ FLAG is set (an error), JUMP to 5867H to show it and end.
5475
XOR A AF
Load Register A with 00H (XOR A) for the record length.
5476
LD (5AF9H),A 32 F9 5A
Store Register A (00H) at 5AF9H: the record length is 256 again.
5479
LD A,10H 3E 10
Load Register A with 10H, a type of record the loader passes over.
547B
GOSUB to 5863H to write Register A (10H) over the type byte 01H.
547E
GOSUB to 4461H, @RWRIT, to write the buffer back to the record it came from.
5481
If the NZ FLAG is set (an error), JUMP to 5867H to show it and end.
5484
GOSUB to 56F7H to read the length of the load block into Register A. Unlike 5526H, the address bytes are not counted apart, so a length of 1 or 2 (257 or 258 bytes after it) passes over only 1 or 2 bytes and the yank loses its place in the file.
5487
LD B,A 47
Copy Register A (the length) into Register B, the count of bytes to pass over.
5488
GOSUB to 56F7H to read the next byte of the load block, passed over.
548B
DECrement Register B and LOOP BACK to 5488H while it is not 0.
548D
LOOP BACK to 5462H for the next record after the name.
548F
POP HL E1
Restore Register Pair HL (the line after the Y line) from the stack.
5490
LD HL,5AA6H 21 A6 5A
Point Register Pair HL to 5AA6H, the message Patch successfully yanked.
5493
LD (5384H),HL 22 84 53
Store Register Pair HL (5AA6H) at 5384H, the operand of LD HL at 5383H, the closing message.
5496
JUMP to 5375H to close the file and show the message.
5499
CP 1CH FE 1C
Compare Register A (the error) against 1CH, the end of file.
549B
If the NZ FLAG is set (another error), JUMP to 5867H to show it and end.
549E
LD HL,59B3H 21 B3 59
Point Register Pair HL to 59B3H, the message Can't yank, patch not in load file.
54A1
JUMP to 5883H to show the message with @LOGOT and end with @ABORT.

54A4H - O: the Option

O=Y or O=ON puts AFH in the operand at 57D5H: a D line needs its F line to match; O=N, O=OFF, or O= with nothing after it, puts 00H there; anything else is Patch input format error. 54CAH is LD A,AFH; 54CBH, inside it, is XOR A.

54A4
INC HL 23
INCrement Register Pair HL past the verb O to the equals sign.
54A5
LD A,(HL) 7E
Load Register A with the character at Register Pair HL.
54A6
CP 3DH FE 3D
Compare Register A against 3DH, an equals sign.
54A8
If the NZ FLAG is set (no equals sign), JUMP to 54C7H, whose JP NZ gives Patch input format error.
54AA
INC HL 23
INCrement Register Pair HL past the equals sign.
54AB
LD A,(HL) 7E
Load Register A with the character at Register Pair HL after the equals sign.
54AC
CP 0DH FE 0D
Compare Register A against 0DH, the end of the line.
54AE
If the Z FLAG is set (nothing after the equals sign), JUMP to 54CBH: the option is off.
54B0
RES 5,A CB AF
Clear bit 5 of Register A: a lower case letter becomes upper case.
54B2
CP 4EH FE 4E
Compare Register A (the letter) against 4EH, N: the option off.
54B4
If the Z FLAG is set (N), JUMP to 54CBH: the option is off.
54B6
CP 59H FE 59
Compare Register A (the letter) against 59H, Y: the option on.
54B8
If the Z FLAG is set (Y), JUMP to 54CAH: the option is on.
54BA
CP 4FH FE 4F
Compare Register A against 4FH, O: ON or OFF.
54BC
If the NZ FLAG is set (another letter), JUMP to 54C7H for Patch input format error.
54BE
GOSUB to 5844H for the character after the O, in upper case, in Register A; Register Pair HL past it.
54C1
CP 46H FE 46
Compare Register A (the letter) against 46H, F: OFF, the option off.
54C3
If the Z FLAG is set (OFF), JUMP to 54CBH: the option is off.
54C5
CP 4EH FE 4E
Compare Register A (the letter) against 4EH, N: ON, the option on.
54C7
If the NZ FLAG is set (neither), JUMP to 588DH for Patch input format error.
54CA
LD A,AFH 3E AF
Load Register A with AFH: the option is on. Entered at 54CBH, the byte AFH is XOR A: Register A = 00H, the option is off.
54CC
LD (57D5H),A 32 D5 57
Store Register A (AFH on, 00H off) at 57D5H, the operand of LD A at 57D4H.
54CF
DEC HL 2B
DECrement Register Pair HL by one, so that 538CH looks at the line from there.
54D0
JUMP to 538CH to pass over the rest of the line.

54D3H - L: a Member of a Library File

Second pass: Lnn, where nn (hex) is the member byte of a member header (type 08H) of a library file such as SYS6/SYS. The member byte goes into the operand at 5741H; 56BFH finds the header and its start (record and byte), the member is read from there to its end record (04H), the file is moved back onto that 04H, and 555BH puts the records of the X lines after the L line there. 56FEH then moves on by the patch's length the start of every member after it in the headers. Only X lines and comments can follow an L line.

54D3
INC HL 23
INCrement Register Pair HL past the verb L to the member byte.
54D4
GOSUB to 5668H to read a hex byte at Register Pair HL into Register A: the member byte.
54D7
LD C,A 4F
Copy Register A (the member byte) into Register C, for 56BFH.
54D8
LD (5741H),A 32 41 57
Store Register A (the member byte) at 5741H, the operand of CP at 5740H, for 56FEH.
54DB
LD A,(HL) 7E
Load Register A with the character at Register Pair HL after the member byte.
54DC
INC HL 23
INCrement Register Pair HL to the next line of the patch text.
54DD
CP 0DH FE 0D
Compare Register A against 0DH: nothing can follow the member byte.
54DF
If the NZ FLAG is set (more on the line), JUMP to 588DH for Patch input format error.
54E2
GOSUB to 56BFH to find the member header of member Register C: Register Pair BC = the record, Register A = the byte where the member starts.
54E5
PUSH AF F5
Save Register Pair AF (Register A = the byte of the start) to the stack.
54E6
LD A,(5AF1H) 3A F1 5A
Load Register A with byte +01H of the control block from 5AF1H.
54E9
RES 7,A CB BF
Clear bit 7 of Register A, the byte mode bit that the ROM's $GET and $PUT set, before the @POSN and @READ below.
54EB
LD (5AF1H),A 32 F1 5A
Store Register A at 5AF1H, byte +01H of the control block.
54EE
LD DE,5AF0H 11 F0 5A
Point Register Pair DE to 5AF0H, the control block of the file to patch.
54F1
GOSUB to 585DH to position the file at Register Pair DE at record Register Pair BC (@POSN).
54F4
GOSUB to 4436H, @READ, to read that record into the file's buffer.
54F7
If the NZ FLAG is set (an error), JUMP to 5867H to show it and end.
54FA
POP AF F1
Restore Register Pair AF (Register A = the byte of the start) from the stack.
54FB
LD (5AF5H),A 32 F5 5A
Store Register A at 5AF5H, the offset (+05H) of the control block: the next byte read is the member's first.
54FE
GOSUB to 5526H to read the member's load records to the first record of type 02H, 03H, 04H or 0AH: Register A = its type.
5501
CP 04H FE 04
Compare Register A against 04H, the end of a member.
5503
If the NZ FLAG is set (another type), JUMP to 5878H for Load file format error.
5506
LD A,01H 3E 01
Load Register A with 01H, a record length of one byte.
5508
LD (5AF9H),A 32 F9 5A
Store Register A (01H) at 5AF9H, the record length (+09H) of the control block, so that @BKSP moves back one byte.
550B
GOSUB to 4445H, @BKSP, to move the file at Register Pair DE back one byte, onto the type byte 04H.
550E
If the NZ FLAG is set (an error), JUMP to 5867H to show it and end.
5511
XOR A AF
Load Register A with 00H (XOR A) for the record length.
5512
LD (5AF9H),A 32 F9 5A
Store Register A (00H) at 5AF9H: the record length is 256 again.
5515
GOSUB to 555BH to build the records of the X lines from Register Pair HL on and put them into the file before the 04H; Register Pair HL comes back at the 03H.
5518
PUSH HL E5
Save Register Pair HL (the end of the text) to the stack.
5519
LD HL,597DH 21 7D 59
Point Register Pair HL to 597DH, the text Re-building library map with 1DH, 1EH, 1DH and 03H.
551C
GOSUB to 4467H, @DSPLY, to show the text at Register Pair HL on the status line.
551F
GOSUB to 56FEH to move on the starts of the members after this one in the member headers.
5522
POP HL E1
Restore Register Pair HL (the end of the text) from the stack.
5523
JUMP to 52FFH: the 03H there ends the second pass.

5526H - Read the Load Records to the End

From the file's position, each record's type is read: 02H (transfer), 03H, 04H (end of a member) or 0AH (end of the member headers) RETurns with the type in Register A and the file just after that type byte; a type of 20H or more is Load file format error; any other record is passed over by its length (a load block, 01H, as its address and data: a length of 0, 1 or 2 is 254, 255 or 256 data bytes).

5526
PUSH HL E5
Save Register Pair HL (the patch line) to the stack.
5527
PUSH DE D5
Save Register Pair DE (5AF0H, the control block) to the stack.
5528
LD HL,592BH 21 2B 59
Point Register Pair HL to 592BH, the text Positioning load file with 1DH, 1EH, 1DH and 03H.
552B
GOSUB to 4467H, @DSPLY, to show the text at Register Pair HL on the status line.
552E
POP DE D1
Restore Register Pair DE (5AF0H, the control block) from the stack.
552F
POP HL E1
Restore Register Pair HL (the patch line) from the stack.
5530
GOSUB to 56F7H to read the type of the next record into Register A.
5533
CP 20H FE 20
Compare Register A against 20H: the NO CARRY FLAG for 20H or more, not a record type.
5535
If the NO CARRY FLAG is set, JUMP to 5878H for Load file format error.
5538
CP 02H FE 02
Compare Register A against 02H, the transfer record.
553A
RET Z C8
If the Z FLAG is set (02H), RETurn with Register A = 02H.
553B
CP 03H FE 03
Compare Register A against 03H, a record that ends the file.
553D
RET Z C8
If the Z FLAG is set (03H), RETurn with Register A = 03H.
553E
CP 04H FE 04
Compare Register A against 04H, the end of a member.
5540
RET Z C8
If the Z FLAG is set (04H), RETurn with Register A = 04H.
5541
CP 0AH FE 0A
Compare Register A against 0AH, the end of the member headers.
5543
RET Z C8
If the Z FLAG is set (0AH), RETurn with Register A = 0AH.
5544
LD C,A 4F
Copy Register A (the type of the record) into Register C.
5545
GOSUB to 56F7H to read the length of the record into Register A.
5548
LD B,A 47
Copy Register A (the length) into Register B, the count of bytes to pass over.
5549
DEC C 0D
DECrement Register C (the type): the Z FLAG for 01H, a load block.
554A
If the NZ FLAG is set (another type), JUMP to 5554H to pass over Register B bytes.
554C
GOSUB to 56F7H to read the low byte of the load address.
554F
DEC B 05
DECrement Register B: the address bytes count in the length.
5550
GOSUB to 56F7H to read the high byte of the load address.
5553
DEC B 05
DECrement Register B again for the second address byte.
5554
GOSUB to 56F7H to read the next byte of the record, passed over.
5557
DECrement Register B and LOOP BACK to 5554H while it is not 0.
5559
LOOP BACK to 5530H for the next record of the file.

555BH - Build the Patch Records

From 7300H: a record of type 07H with the patch's name (5AC0H, its length and the characters) when it has one, then for each X line a load block (type 01H): its length, the address from X'nnnn' (the byte after the closing quote is passed over without a test) and the data: hex bytes (spaces between them are passed over) or quoted strings, up to the 0DH or a semicolon. Only X lines and comments can follow; at the 03H, 5605H puts the records into the file.

555B
PUSH HL E5
Save Register Pair HL (the X line) to the stack.
555C
LD HL,5955H 21 55 59
Point Register Pair HL to 5955H, the text Generating patch with 1DH, 1EH, 1DH and 03H.
555F
GOSUB to 4467H, @DSPLY, to show the text at Register Pair HL on the status line.
5562
LD DE,7300H 11 00 73
Point Register Pair DE to 7300H, where the records are built.
5565
LD HL,5AC0H 21 C0 5A
Point Register Pair HL to 5AC0H, the length of the patch's name.
5568
LD A,(HL) 7E
Load Register A with the length of the name at Register Pair HL.
5569
OR A B7
OR Register A with itself: the Z FLAG for no name.
556A
If the Z FLAG is set (no name), JUMP to 5578H.
556C
LD A,07H 3E 07
Load Register A with 07H, the type of the record of a patch's name.
556E
LD (DE),A 12
Store Register A (07H) at Register Pair DE, at 7300H.
556F
INC DE 13
INCrement Register Pair DE to the next byte of the records.
5570
LD B,(HL) 46
Load Register B with the length of the name at Register Pair HL (5AC0H).
5571
INC B 04
INCrement Register B: the length byte and the characters are copied.
5572
LD A,(HL) 7E
Load Register A with the byte at Register Pair HL, from 5AC0H on.
5573
INC HL 23
INCrement Register Pair HL to the next byte of the name.
5574
LD (DE),A 12
Store Register A at Register Pair DE, in the record of the name.
5575
INC DE 13
INCrement Register Pair DE to the next byte of the records.
5576
DECrement Register B and LOOP BACK to 5572H while it is not 0.
5578
POP HL E1
Restore Register Pair HL (the X line) from the stack.
5579
LD (5897H),HL 22 97 58
Store Register Pair HL (the line) at 5897H-5898H, the operand of LD HL at 5896H, the line shown with an error.
557C
LD A,(HL) 7E
Load Register A with the verb of the line at Register Pair HL.
557D
CP 03H FE 03
Compare Register A against 03H, the end of the text.
557F
If the Z FLAG is set (the end), JUMP to 5605H to put the records into the file.
5582
INC HL 23
INCrement Register Pair HL past the verb of the line.
5583
CP 2EH FE 2E
Compare Register A against 2EH, a period: a comment.
5585
If the Z FLAG is set (a comment), JUMP to 5590H to pass over it.
5587
RES 5,A CB AF
Clear bit 5 of Register A: a lower case verb becomes upper case.
5589
CP 58H FE 58
Compare Register A (the verb) against 58H, X.
558B
If the Z FLAG is set (X), JUMP to 559DH for its load block.
558D
JUMP to 588DH for Patch input format error: another verb after an X or L line.
5590
LD A,(HL) 7E
Load Register A with the character of the comment at Register Pair HL.
5591
INC HL 23
INCrement Register Pair HL to the next character.
5592
CP 03H FE 03
Compare Register A against 03H, the end of the text inside a line.
5594
If the Z FLAG is set (03H), JUMP to 588DH for Patch input format error.
5597
CP 0DH FE 0D
Compare Register A against 0DH, the end of the line.
5599
If the NZ FLAG is set (not the end), LOOP BACK to 5590H.
559B
LOOP BACK to 5579H for the next line of the patch text.
559D
LD A,01H 3E 01
Load Register A with 01H, the type of a load block.
559F
LD (DE),A 12
Store Register A (01H) at Register Pair DE, in the records.
55A0
INC DE 13
INCrement Register Pair DE to the length byte of the block.
55A1
PUSH DE D5
Save Register Pair DE (the length byte) to the stack, for 55FFH.
55A2
INC DE 13
INCrement Register Pair DE to the place of the address.
55A3
LD A,(HL) 7E
Load Register A with the character at Register Pair HL after the X.
55A4
INC HL 23
INCrement Register Pair HL to the next character.
55A5
CP 27H FE 27
Compare Register A against 27H, the apostrophe of X'nnnn'.
55A7
If the NZ FLAG is set (no apostrophe), JUMP to 588DH for Patch input format error.
55AA
GOSUB to 5668H to read a hex byte at Register Pair HL into Register A: the high byte of the address.
55AD
LD B,A 47
Copy Register A (the high byte) into Register B.
55AE
GOSUB to 5668H to read the next hex byte into Register A: the low byte of the address.
55B1
LD (DE),A 12
Store Register A (the low byte) at Register Pair DE, the first address byte of the block.
55B2
INC DE 13
INCrement Register Pair DE to the next byte of the block.
55B3
LD A,B 78
Copy Register B (the high byte) into Register A.
55B4
LD (DE),A 12
Store Register A (the high byte) at Register Pair DE.
55B5
INC DE 13
INCrement Register Pair DE to the place of the data.
55B6
LD A,(HL) 7E
Load Register A with the character at Register Pair HL after the address.
55B7
CP 3DH FE 3D
Compare Register A against 3DH, an equals sign.
55B9
If the Z FLAG is set (an equals sign), JUMP to 55C1H to step past it.
55BB
CP 27H FE 27
Compare Register A against 27H, the closing apostrophe.
55BD
If the NZ FLAG is set (neither), JUMP to 588DH for Patch input format error.
55C0
INC HL 23
INCrement Register Pair HL past the apostrophe.
55C1
INC HL 23
INCrement Register Pair HL past the equals sign; after an apostrophe this byte is not tested.
55C2
LD B,02H 06 02
Load Register B with 02H, the length so far: the two address bytes.
55C4
LD A,(HL) 7E
Load Register A with the character at Register Pair HL.
55C5
CP 22H FE 22
Compare Register A against 22H, a quote: a string.
55C7
If the Z FLAG is set (a string), JUMP to 55E8H.
55C9
LD A,(HL) 7E
Load Register A with the character at Register Pair HL.
55CA
INC HL 23
INCrement Register Pair HL to the next character.
55CB
CP 3BH FE 3B
Compare Register A against 3BH, a semicolon: a comment to the end of the line.
55CD
If the Z FLAG is set (a semicolon), JUMP to 55E0H.
55CF
CP 0DH FE 0D
Compare Register A against 0DH, the end of the line.
55D1
If the Z FLAG is set (the end), JUMP to 55FFH to store the length.
55D3
CP 20H FE 20
Compare Register A against 20H, a space between the bytes.
55D5
If the Z FLAG is set (a space), LOOP BACK to 55C4H.
55D7
DEC HL 2B
DECrement Register Pair HL back to the hex byte.
55D8
GOSUB to 566CH to read the hex byte at Register Pair HL into Register A.
55DB
LD (DE),A 12
Store Register A (the data byte) at Register Pair DE, in the block.
55DC
INC DE 13
INCrement Register Pair DE to the next byte of the block.
55DD
INC B 04
INCrement Register B, the length of the block.
55DE
LOOP BACK to 55C9H for the next character of the X line.
55E0
LD A,(HL) 7E
Load Register A with the character of the comment at Register Pair HL.
55E1
INC HL 23
INCrement Register Pair HL to the next character.
55E2
CP 0DH FE 0D
Compare Register A against 0DH, the end of the line.
55E4
If the NZ FLAG is set (not the end), LOOP BACK to 55E0H.
55E6
JUMP to 55FFH to store the length of the block.
55E8
INC HL 23
INCrement Register Pair HL past the quote or the character before.
55E9
LD A,(HL) 7E
Load Register A with the character of the string at Register Pair HL.
55EA
CP 03H FE 03
Compare Register A against 03H, the end of the text inside a string.
55EC
If the Z FLAG is set (03H), JUMP to 588DH for Patch input format error.
55EF
INC HL 23
INCrement Register Pair HL to the next character.
55F0
CP 0DH FE 0D
Compare Register A against 0DH, the end of the line: it also ends the string.
55F2
If the Z FLAG is set (the end), JUMP to 55FFH to store the length.
55F5
CP 22H FE 22
Compare Register A against 22H, the closing quote.
55F7
If the Z FLAG is set (the closing quote), JUMP to 55C9H for more data.
55F9
DEC HL 2B
DECrement Register Pair HL back to the character, for the INC at 55E8H.
55FA
LD (DE),A 12
Store Register A (the character) at Register Pair DE, in the block.
55FB
INC DE 13
INCrement Register Pair DE to the next byte of the block.
55FC
INC B 04
INCrement Register B, the length of the block.
55FD
LOOP BACK to 55E8H for the next character of the string.
55FF
EX (SP),HL E3
Exchange Register Pair HL with the top of the stack at the Stack Pointer: Register Pair HL = the length byte of the block, the next line on the stack.
5600
LD (HL),B 70
Store Register B (the length: 2 and the count of data bytes) at Register Pair HL, the length byte.
5601
POP HL E1
Restore Register Pair HL (the next line) from the stack.
5602
JUMP to 5579H for the next line of the patch text.

5605H - Put the Records into the File

Register Pair DE = the end of the records built from 7300H; their length goes into the operand at 5769H. A second control block at 5B10H is made from the file's (with the buffer 5D00H) to read the old bytes from the file's position on while the first writes the new ones: each byte read is kept the length of the records further on at 7300H, so the records go in and every old byte after them is moved on by that length. At the end of the file the bytes still kept are written. The area from 7300H holds the rest of the file after the place; no test of the top of memory is made.

5605
PUSH HL E5
Save Register Pair HL (the end of the text) to the stack.
5606
EX DE,HL EB
Exchange Register Pairs DE and HL: Register Pair HL = the end of the records.
5607
LD DE,7300H 11 00 73
Point Register Pair DE to 7300H, the start of the records.
560A
XOR A AF
Load Register A with 00H (XOR A), which clears the CARRY FLAG for the SBC.
560B
SBC HL,DE ED 52
SUBtract Register Pair DE (7300H) from Register Pair HL: the length of the records.
560D
LD (5769H),HL 22 69 57
Store Register Pair HL (the length) at 5769H-576AH, the operand of LD DE at 5768H, read also at 5645H and 5658H.
5610
LD HL,5969H 21 69 59
Point Register Pair HL to 5969H, the text Installing patch with 1DH, 1EH, 1DH and 03H.
5613
GOSUB to 4467H, @DSPLY, to show the text at Register Pair HL on the status line.
5616
LD HL,5AF0H 21 F0 5A
Point Register Pair HL to 5AF0H, the control block of the file to patch.
5619
LD DE,5B10H 11 10 5B
Point Register Pair DE to 5B10H, the control block of the patch file, not used any more; it is not closed.
561C
LD BC,0020H 01 20 00
Load Register Pair BC with 0020H, the 32 bytes of a control block.
561F
LDIR ED B0
Copy Register Pair BC (32) bytes from Register Pair HL to Register Pair DE (LDIR): a second control block of the same file at the same place.
5621
LD HL,5D00H 21 00 5D
Point Register Pair HL to 5D00H, a buffer for the second control block.
5624
LD (5B13H),HL 22 13 5B
Store Register Pair HL (5D00H) at 5B13H-5B14H, the buffer address (+03H-+04H) of the second control block.
5627
LD DE,5B10H 11 10 5B
Point Register Pair DE to 5B10H, the second control block.
562A
GOSUB to 445EH, @RREAD, to have the record at the file's place read again, into 5D00H, at the next byte.
562D
If the NZ FLAG is set (an error), JUMP to 5867H to show it and end.
5630
LD HL,7300H 21 00 73
Point Register Pair HL to 7300H, the first byte of the records.
5633
LD DE,5B10H 11 10 5B
Point Register Pair DE to 5B10H, the second control block (the old bytes).
5636
GOSUB to 0013H, the ROM's $GET, to read the old byte at the place into Register A: the NZ FLAG at the end of the file.
5639
If the NZ FLAG is set (the end or an error), JUMP to 5650H.
563C
PUSH HL E5
Save Register Pair HL (the byte to write next) to the stack.
563D
PUSH AF F5
Save Register Pair AF (Register A = the old byte) to the stack.
563E
LD DE,5AF0H 11 F0 5A
Point Register Pair DE to 5AF0H, the first control block (the new bytes).
5641
LD A,(HL) 7E
Load Register A with the byte to write at Register Pair HL: from the records, then the old bytes kept.
5642
GOSUB to 5863H to write Register A at the file's place (the ROM's $PUT).
5645
LD BC,(5769H) ED 4B 69 57
Load Register Pair BC with the length of the records from 5769H-576AH.
5649
ADD HL,BC 09
ADD Register Pair BC (the length) to Register Pair HL: the place where the old byte is kept, the length further on.
564A
POP AF F1
Restore Register Pair AF (Register A = the old byte) from the stack.
564B
LD (HL),A 77
Store Register A (the old byte) at Register Pair HL, to be written the length of the records later.
564C
POP HL E1
Restore Register Pair HL (the byte just written) from the stack.
564D
INC HL 23
INCrement Register Pair HL to the next byte to write.
564E
LOOP BACK to 5633H for the next old byte of the file.
5650
CP 1CH FE 1C
Compare Register A (the error) against 1CH, the end of file.
5652
If the NZ FLAG is set (another error), JUMP to 5878H for Load file format error.
5655
LD DE,5AF0H 11 F0 5A
Point Register Pair DE to 5AF0H, the first control block.
5658
LD BC,(5769H) ED 4B 69 57
Load Register Pair BC with the length of the records from 5769H-576AH: as many old bytes are still kept.
565C
LD A,(HL) 7E
Load Register A with the next kept byte at Register Pair HL.
565D
INC HL 23
INCrement Register Pair HL to the next kept byte.
565E
GOSUB to 5863H to write Register A at the end of the file (the ROM's $PUT).
5661
DEC BC 0B
DECrement Register Pair BC, the bytes still to write.
5662
LD A,B 78
Copy Register B (the high byte of the count) into Register A.
5663
OR C B1
OR Register C into Register A: the Z FLAG when every kept byte is written.
5664
If the NZ FLAG is set (more), LOOP BACK to 565CH.
5666
POP HL E1
Restore Register Pair HL (the end of the text) from the stack.
5667
RET C9
RETurn with Register Pair HL at the end of the text.

5668H - Read a Hex Byte or a Quoted Character

5668H clears the quote flag (5681H, the operand of LD A at 5680H) first; 566CH keeps it. A quote at Register Pair HL sets the flag. With the flag set the character at Register Pair HL is RETurned as it is, the NZ FLAG set; else one or two hex digits are read into Register A (a single digit when the next character is below 30H or is 3AH-40H; any character from 41H up is taken as the second digit). An 03H gives Patch input format error, a bad digit Non-hex digit encountered. Register Pair HL ends after what was read.

5668
XOR A AF
Load Register A with 00H (XOR A), for the quote flag.
5669
LD (5681H),A 32 81 56
Store Register A (00H) at 5681H, the quote flag: outside a string.
566C
LD A,(HL) 7E
Load Register A with the character at Register Pair HL.
566D
CP 03H FE 03
Compare Register A against 03H, the end of the text.
566F
If the Z FLAG is set (03H), JUMP to 588DH for Patch input format error.
5672
CP 22H FE 22
Compare Register A against 22H, a quote: the start of a string.
5674
If the NZ FLAG is set (no quote), JUMP to 5680H.
5676
LD (5681H),A 32 81 56
Store Register A (22H) at 5681H, the quote flag: inside a string.
5679
INC HL 23
INCrement Register Pair HL past the quote to the first character.
567A
LD A,(HL) 7E
Load Register A with the character at Register Pair HL.
567B
CP 03H FE 03
Compare Register A against 03H, the end of the text.
567D
If the Z FLAG is set (03H), JUMP to 588DH for Patch input format error.
5680
LD A,00H 3E 00
Load Register A with the quote flag, the operand at 5681H (00H in the file): 22H inside a string.
5682
OR A B7
OR Register A with itself: the NZ FLAG inside a string.
5683
LD A,(HL) 7E
Load Register A with the character at Register Pair HL. LD does not change the flags.
5684
INC HL 23
INCrement Register Pair HL past the character.
5685
RET NZ C0
If the NZ FLAG is set (inside a string), RETurn with the character in Register A.
5686
GOSUB to 56ADH to turn the character in Register A into the value of a hex digit.
5689
LD C,A 4F
Copy Register A (the first digit) into Register C.
568A
LD A,(HL) 7E
Load Register A with the next character at Register Pair HL.
568B
INC HL 23
INCrement Register Pair HL past the second character.
568C
CP 03H FE 03
Compare Register A against 03H, the end of the text.
568E
If the Z FLAG is set (03H), JUMP to 588DH for Patch input format error.
5691
CP 30H FE 30
Compare Register A against 30H, the digit 0: the CARRY FLAG below it.
5693
If the CARRY FLAG is set (not a digit), JUMP to 56AAH: a byte of one digit.
5695
CP 3AH FE 3A
Compare Register A against 3AH: the CARRY FLAG for a digit 0-9.
5697
If the CARRY FLAG is set (a digit), JUMP to 569DH for the second digit.
5699
CP 41H FE 41
Compare Register A against 41H, the letter A: the CARRY FLAG for 3AH-40H.
569B
If the CARRY FLAG is set (3AH-40H), JUMP to 56AAH: a byte of one digit.
569D
RLC C CB 01
Rotate Register C (the first digit) left once (RLC C).
569F
RLC C CB 01
Rotate Register C (the first digit) left again (RLC C).
56A1
RLC C CB 01
Rotate Register C (the first digit) left a third time (RLC C).
56A3
RLC C CB 01
Rotate Register C left a fourth time (RLC C): the first digit is the high half of the byte.
56A5
GOSUB to 56ADH to turn the second character in Register A into the value of a hex digit.
56A8
OR C B1
OR Register C (the high half) into Register A: the byte.
56A9
RET C9
RETurn with the byte in Register A and Register Pair HL after it.
56AA
LD A,C 79
Copy Register C (the single digit) into Register A, the byte.
56AB
DEC HL 2B
DECrement Register Pair HL back to the character after the digit.
56AC
RET C9
RETurn with the byte in Register A and Register Pair HL after the digit.

56ADH - The Value of a Hex Digit

0-9 and A-F (upper or lower case) give 00H-0FH; a character below 30H, or one whose value after the steps is 10H or more, gives Non-hex digit encountered. The steps also let through 57H-5FH (W to the underline) as 00H-08H and 60H as 09H, as either digit, and 3AH-40H as 03H-09H as the first digit.

56AD
SUB 30H D6 30
SUBtract 30H from Register A: the digits 0-9 become 00H-09H; the CARRY FLAG below 30H.
56AF
If the CARRY FLAG is set (below the digit 0), JUMP to 5889H for Non-hex digit encountered.
56B2
CP 0AH FE 0A
Compare Register A against 0AH: the CARRY FLAG for a digit 0-9.
56B4
RET C D8
If the CARRY FLAG is set (0-9), RETurn with its value in Register A.
56B5
RES 5,A CB AF
Clear bit 5 of Register A: a lower case letter's value becomes the upper case one (a, 31H, becomes 11H).
56B7
SUB 07H D6 07
SUBtract 07H from Register A: A-F (11H-16H) become 0AH-0FH.
56B9
CP 10H FE 10
Compare Register A against 10H: the CARRY FLAG for a value below 10H.
56BB
RET C D8
If the CARRY FLAG is set, RETurn with the value of the digit in Register A.
56BC
JUMP to 5889H for the message Non-hex digit encountered.

56BFH - Find a Member Header

From the file's present position (its first record when nothing has moved it), each record is read: a member header (type 08H: length, member byte, entry address, record, byte) whose member byte is Register C ends the search; 0AH, the end of the headers, gives Library overlay not found; a load block (01H) before it, Invalid library format; any other record is passed over. It RETurns with Register Pair BC = the record and Register A = the byte where the member starts.

56BF
LD DE,5AF0H 11 F0 5A
Point Register Pair DE to 5AF0H, the control block of the file to patch.
56C2
GOSUB to 56F7H to read the type of the next record into Register A.
56C5
CP 08H FE 08
Compare Register A against 08H, a member header.
56C7
If the Z FLAG is set (a header), JUMP to 56DEH to compare its member byte.
56C9
CP 0AH FE 0A
Compare Register A against 0AH, the end of the member headers.
56CB
If the Z FLAG is set (0AH), JUMP to 5870H for Library overlay not found.
56CE
CP 01H FE 01
Compare Register A against 01H, a load block.
56D0
If the Z FLAG is set (a load block among the headers), JUMP to 5874H for Invalid library format.
56D3
GOSUB to 56F7H to read the length of the record into Register A.
56D6
LD B,A 47
Copy Register A (the length) into Register B, the count of bytes to pass over.
56D7
GOSUB to 56F7H to read the next byte of the record, passed over.
56DA
DECrement Register B and LOOP BACK to 56D7H while it is not 0.
56DC
LOOP BACK to 56C2H for the next record of the file.
56DE
GOSUB to 56F7H to read the length of the header into Register A.
56E1
LD B,A 47
Copy Register A (the length) into Register B.
56E2
GOSUB to 56F7H to read the member byte of the header into Register A.
56E5
DEC B 05
DECrement Register B (the bytes left) for the member byte.
56E6
CP C B9
Compare Register A (the member byte) against Register C (the member wanted).
56E7
If the NZ FLAG is set (another member), JUMP to 56D7H to pass over the rest of the header.
56E9
GOSUB to 56F7H to read the low byte of the member's entry address, not used.
56EC
GOSUB to 56F7H to read the high byte of the entry address, not used.
56EF
GOSUB to 56F7H to read the low byte of the record where the member starts.
56F2
LD C,A 4F
Copy Register A into Register C, the low byte of the record.
56F3
GOSUB to 56F7H to read the high byte of the record.
56F6
LD B,A 47
Copy Register A into Register B: Register Pair BC = the record; then 56F7H reads the byte where the member starts into Register A.

56F7H - Read a Byte of the File

The ROM's $GET reads the next byte of the file at Register Pair DE into Register A; an error, the end of the file too, is shown and ends PATCH.

56F7
GOSUB to 0013H, the ROM's $GET, to read the next byte of the file at Register Pair DE into Register A.
56FA
RET Z C8
If the Z FLAG is set (read), RETurn with the byte in Register A.
56FB
JUMP to 5867H to show the error in Register A and end.

56FEH - The Library Map: Move the Members After the Patch

The records before the end of the headers (0AH) are read from the start of the file into 7300H (types below 04H there, such as a load block, give Invalid library format). The header of the patched member (its member byte at 5741H) gives its start in Register Pairs DE and B; every member header after it whose start is another one gets the length of the patch (5769H) added to its byte and record. Then the records are written back over the old ones. FINDING: from the first header moved, Register Pair DE is 0000H (577AH), not the member's start, so the test at 5758H then keeps only a header whose start is record 0000H and the member's byte.

56FE
LD DE,5AF0H 11 F0 5A
Point Register Pair DE to 5AF0H, the control block of the file to patch.
5701
LD BC,0000H 01 00 00
Load Register Pair BC with 0000H, the first record of the file.
5704
GOSUB to 585DH to position the file at Register Pair DE at record 0000H (@POSN).
5707
LD HL,7300H 21 00 73
Point Register Pair HL to 7300H, where the records of the headers are kept.
570A
GOSUB to 56F7H to read the type of the next record into Register A.
570D
CP 04H FE 04
Compare Register A against 04H: the CARRY FLAG for 00H-03H.
570F
If the CARRY FLAG is set (a load block or another such record among the headers), JUMP to 5874H for Invalid library format.
5712
CP 0AH FE 0A
Compare Register A against 0AH, the end of the member headers.
5714
If the Z FLAG is set (0AH, the end of the headers), JUMP to 5727H.
5716
LD (HL),A 77
Store Register A (the type) at Register Pair HL, in the copy at 7300H.
5717
INC HL 23
INCrement Register Pair HL to the next byte of the copy.
5718
GOSUB to 56F7H to read the length of the record into Register A.
571B
LD B,A 47
Copy Register A (the length) into Register B, the count of bytes to copy.
571C
LD (HL),A 77
Store Register A (the length) at Register Pair HL, in the copy.
571D
INC HL 23
INCrement Register Pair HL to the next byte of the copy.
571E
GOSUB to 56F7H to read the next byte of the record into Register A.
5721
LD (HL),A 77
Store Register A at Register Pair HL, in the copy.
5722
INC HL 23
INCrement Register Pair HL to the next byte of the copy.
5723
DECrement Register B and LOOP BACK to 571EH while it is not 0.
5725
LOOP BACK to 570AH for the next record of the file.
5727
LD (HL),A 77
Store Register A (0AH) at Register Pair HL: the end of the copy.
5728
LD HL,7300H 21 00 73
Point Register Pair HL to 7300H, the first record of the copy.
572B
LD A,(HL) 7E
Load Register A with the type of the record at Register Pair HL.
572C
INC HL 23
INCrement Register Pair HL to the length of the record.
572D
LD B,(HL) 46
Load Register B with the length of the record at Register Pair HL.
572E
INC HL 23
INCrement Register Pair HL to the first byte of the record.
572F
CP 08H FE 08
Compare Register A (the type) against 08H, a member header.
5731
If the Z FLAG is set (a header), JUMP to 573DH to compare its member byte.
5733
CP 0AH FE 0A
Compare Register A (the type) against 0AH, the end of the copy.
5735
If the Z FLAG is set (0AH), JUMP to 5870H for Library overlay not found.
5738
INC HL 23
INCrement Register Pair HL past a byte of the record.
5739
DECrement Register B and LOOP BACK to 5738H while it is not 0.
573B
LOOP BACK to 572BH for the next record of the copy.
573D
LD A,(HL) 7E
Load Register A with the member byte of the header at Register Pair HL.
573E
INC HL 23
INCrement Register Pair HL to the next byte of the header.
573F
DEC B 05
DECrement Register B (the bytes left) for the member byte.
5740
CP 00H FE 00
Compare Register A against the member byte of the L line, the operand at 5741H (00H in the file, stored by 54D8H).
5742
If the NZ FLAG is set (another member), JUMP to 5738H to pass over the rest of the header.
5744
INC HL 23
INCrement Register Pair HL past the low byte of the entry address.
5745
INC HL 23
INCrement Register Pair HL past the high byte of the entry address.
5746
LD E,(HL) 5E
Load Register E with the low byte of the record where the member starts, at Register Pair HL.
5747
INC HL 23
INCrement Register Pair HL to the high byte of the record.
5748
LD D,(HL) 56
Load Register D with the high byte of the record at Register Pair HL: Register Pair DE = the record.
5749
INC HL 23
INCrement Register Pair HL to the byte in the record.
574A
LD B,(HL) 46
Load Register B with the byte in the record where the member starts, at Register Pair HL.
574B
INC HL 23
INCrement Register Pair HL to the next record of the copy.

574CH - The Headers After It

Each header after the patched member's: a start equal to Register Pair DE and Register B (the same member under another member byte) is kept; any other start is moved on by the length of the patch.

574C
LD A,(HL) 7E
Load Register A with the type of the record at Register Pair HL.
574D
CP 0AH FE 0A
Compare Register A against 0AH, the end of the copy.
574F
If the Z FLAG is set (the end), JUMP to 577FH to write the copy back.
5751
INC HL 23
INCrement Register Pair HL past the type 08H.
5752
INC HL 23
INCrement Register Pair HL past the length of the header.
5753
INC HL 23
INCrement Register Pair HL past the member byte.
5754
INC HL 23
INCrement Register Pair HL past the low byte of the entry address.
5755
INC HL 23
INCrement Register Pair HL past the high byte of the entry address.
5756
LD A,(HL) 7E
Load Register A with the low byte of this header's record at Register Pair HL.
5757
INC HL 23
INCrement Register Pair HL to the high byte of the record.
5758
CP E BB
Compare Register A against Register E: the Z FLAG when it is the same low byte.
5759
If the NZ FLAG is set (another record), JUMP to 5767H to move the start.
575B
LD A,(HL) 7E
Load Register A with the high byte of this header's record at Register Pair HL.
575C
INC HL 23
INCrement Register Pair HL to the byte in the record.
575D
CP D BA
Compare Register A against Register D: the Z FLAG when it is the same high byte.
575E
If the NZ FLAG is set (another record), JUMP to 5768H to move the start.
5760
LD A,(HL) 7E
Load Register A with the byte in the record of this header at Register Pair HL.
5761
CP B B8
Compare Register A against Register B (the member's byte): the Z FLAG for the same start.
5762
If the NZ FLAG is set (another start), JUMP to 5768H to move it.
5764
INC HL 23
INCrement Register Pair HL to the next record of the copy.
5765
LOOP BACK to 574CH for the next header, this one kept as it is.
5767
INC HL 23
INCrement Register Pair HL to the byte in the record of this header.
5768
LD DE,0000H 11 00 00
Load Register Pair DE with the length of the patch, the operand at 5769H stored by 560DH (0000H in the file).
576B
LD A,(HL) 7E
Load Register A with the byte in the record of this header at Register Pair HL.
576C
ADD A,E 83
ADD Register E (the low byte of the length) to Register A.
576D
LD (HL),A 77
Store Register A at Register Pair HL: the new byte; the CARRY FLAG is kept for the record.
576E
DEC HL 2B
DECrement Register Pair HL to the high byte of the record.
576F
DEC HL 2B
DECrement Register Pair HL to the low byte of the record.
5770
LD A,(HL) 7E
Load Register A with the low byte of the record at Register Pair HL.
5771
ADC A,D 8A
ADD Register D (the high byte of the length) and the CARRY FLAG to Register A.
5772
LD (HL),A 77
Store Register A at Register Pair HL: the new low byte of the record.
5773
INC HL 23
INCrement Register Pair HL to the high byte of the record.
5774
LD A,(HL) 7E
Load Register A with the high byte of the record at Register Pair HL.
5775
ADC A,00H CE 00
ADD the CARRY FLAG to Register A (ADC A,00H).
5777
LD (HL),A 77
Store Register A at Register Pair HL: the new high byte of the record.
5778
INC HL 23
INCrement Register Pair HL back to the byte in the record.
5779
INC HL 23
INCrement Register Pair HL to the next record of the copy.
577A
LD DE,0000H 11 00 00
Load Register Pair DE with 0000H. Nothing writes this operand, so the member's start is not in Register Pair DE any more.
577D
LOOP BACK to 574CH for the next header after the moved one.

577FH - Write the Headers Back

From the start of the file, every record of the copy at 7300H up to the 0AH is written over the old one, with the ROM's $PUT.

577F
LD DE,5AF0H 11 F0 5A
Point Register Pair DE to 5AF0H, the control block of the file to patch.
5782
LD BC,0000H 01 00 00
Load Register Pair BC with 0000H, the first record of the file.
5785
GOSUB to 585DH to position the file at Register Pair DE at record 0000H (@POSN).
5788
LD HL,7300H 21 00 73
Point Register Pair HL to 7300H, the first record of the copy.
578B
LD A,(HL) 7E
Load Register A with the type of the record at Register Pair HL.
578C
CP 0AH FE 0A
Compare Register A against 0AH, the end of the copy.
578E
RET Z C8
If the Z FLAG is set (the end), RETurn: the 0AH record in the file is not written again.
578F
INC HL 23
INCrement Register Pair HL to the length of the record.
5790
GOSUB to 5863H to write the type in Register A into the file.
5793
LD A,(HL) 7E
Load Register A with the length of the record at Register Pair HL.
5794
INC HL 23
INCrement Register Pair HL to the first byte of the record.
5795
LD B,A 47
Copy Register A (the length) into Register B, the count of bytes to write.
5796
GOSUB to 5863H to write the length in Register A into the file.
5799
LD A,(HL) 7E
Load Register A with the next byte of the record at Register Pair HL.
579A
INC HL 23
INCrement Register Pair HL to the next byte of the copy.
579B
GOSUB to 5863H to write Register A into the file.
579E
DECrement Register B and LOOP BACK to 5799H while it is not 0.
57A0
LOOP BACK to 578BH for the next record of the copy.

57A2H - The Second Pass

Register A = 03H: the operand at 530BH gets it, so the text is gone through again doing the work.

57A2
LD (530BH),A 32 0B 53
Store Register A (03H) at 530BH, the pass flag, the operand of LD A at 530AH: the second pass.
57A5
JUMP to 52FCH to go through the patch text again from 5F00H.

57A8H - The First Pass: Check a Line

Register A = the verb. A comment, F, Y, L and X lines are passed over; R and O are taken now as in the second pass; a D line goes to 57D4H; the 03H starts the second pass (57A2H); any other verb is Patch input format error.

57A8
CP 2EH FE 2E
Compare Register A (the verb) against 2EH, a period: a comment.
57AA
If the Z FLAG is set (a comment), JUMP to 57D1H to pass over the line.
57AC
CP 03H FE 03
Compare Register A (the verb) against 03H, the end of the text.
57AE
If the Z FLAG is set (the end), LOOP BACK to 57A2H for the second pass.
57B0
RES 5,A CB AF
Clear bit 5 of Register A: a lower case verb becomes upper case.
57B2
CP 44H FE 44
Compare Register A (the verb) against 44H, D.
57B4
If the Z FLAG is set (D), JUMP to 57D4H to check the line.
57B6
CP 52H FE 52
Compare Register A (the verb) against 52H, R.
57B8
If the Z FLAG is set (R), JUMP to 5409H to set the remove flag.
57BB
CP 4FH FE 4F
Compare Register A (the verb) against 4FH, O.
57BD
If the Z FLAG is set (O), JUMP to 54A4H to read the option.
57C0
CP 46H FE 46
Compare Register A (the verb) against 46H, F.
57C2
If the Z FLAG is set (F), JUMP to 57D1H: it is checked with its D line.
57C4
CP 59H FE 59
Compare Register A (the verb) against 59H, Y.
57C6
If the Z FLAG is set (Y), JUMP to 57D1H: it is done in the second pass.
57C8
CP 4CH FE 4C
Compare Register A (the verb) against 4CH, L.
57CA
If the Z FLAG is set (L), JUMP to 57D1H: it is done in the second pass.
57CC
CP 58H FE 58
Compare Register A (the verb) against 58H, X.
57CE
If the NZ FLAG is set (any other verb), JUMP to 588DH for Patch input format error.
57D1
JUMP to 538CH to pass over the line (an X line too).

57D4H - The First Pass: a D Line

With the option off (the operand at 57D5H is 00H) a D line is not checked. To remove a patch (the operand at 57DBH not 00H) 581AH is used. Else the D line is kept at 5AEAH, 5834H finds the next line that is not a comment (its F line), and 57ECH checks that it names the same record and byte and that its data is in the file.

57D4
LD A,FFH 3E FF
Load Register A with the option flag, the operand at 57D5H: FFH in the file, AFH or 00H after O, the OPTION result of @PARAM.
57D6
OR A B7
OR Register A with itself: the Z FLAG for 00H, the option off.
57D7
If the Z FLAG is set (the option off), JUMP to 538CH to pass over the D line unchecked.
57DA
LD A,00H 3E 00
Load Register A with the remove flag, the operand at 57DBH: 00H in the file, FFH after R or REMOVE.
57DC
OR A B7
OR Register A with itself: the NZ FLAG to remove a patch.
57DD
If the NZ FLAG is set (remove), JUMP to 581AH.
57E0
LD (5AEAH),HL 22 EA 5A
Store Register Pair HL (the D line) at 5AEAH-5AEBH.
57E3
GOSUB to 5834H to move Register Pair HL to the next line that is not a comment: the F line.
57E6
GOSUB to 57ECH to check the F line at Register Pair HL against the D line at 5AEAH and against the file.
57E9
JUMP to 52FFH for the next line at Register Pair HL.

57ECH - Check a Find Line

Register Pair HL = the line to check, 5AEAH = the line it belongs to. Their text after the verb must be the same up to the equals sign: the three characters rr, and then three more (bb=) when the third was a comma, else five (for a record of four digits). Then 53A6H positions the file at its record and byte and 53D0H, in the first pass, compares its data with the bytes of the file. FIND line mismatch when anything differs. It RETurns with Register Pair HL after the line.

57EC
LD (5897H),HL 22 97 58
Store Register Pair HL (the line to check) at 5897H-5898H, the line shown with an error.
57EF
PUSH HL E5
Save Register Pair HL (the line to check) to the stack.
57F0
LD DE,(5AEAH) ED 5B EA 5A
Load Register Pair DE with the line it belongs to from 5AEAH-5AEBH.
57F4
LD B,03H 06 03
Load Register B with 03H, the first characters to compare.
57F6
INC HL 23
INCrement Register Pair HL to the next character of the line to check.
57F7
INC DE 13
INCrement Register Pair DE to the next character of the other line.
57F8
LD A,(DE) 1A
Load Register A with the character of the other line at Register Pair DE.
57F9
CP (HL) BE
Compare Register A against the character at Register Pair HL: the Z FLAG when they are the same.
57FA
If the NZ FLAG is set (they differ), JUMP to 5857H for FIND line mismatch.
57FD
DECrement Register B and LOOP BACK to 57F6H while it is not 0.
57FF
LD B,03H 06 03
Load Register B with 03H, the characters still to compare after a record of two digits.
5801
LD A,2CH 3E 2C
Load Register A with 2CH, a comma, the end of a record of two digits.
5803
CP (HL) BE
Compare Register A against the third character at Register Pair HL: the Z FLAG for a comma.
5804
If the Z FLAG is set (a comma), JUMP to 5808H with Register B = 03H.
5806
LD B,05H 06 05
Load Register B with 05H, the characters still to compare after a record of four digits.
5808
INC HL 23
INCrement Register Pair HL to the next character of the line to check.
5809
INC DE 13
INCrement Register Pair DE to the next character of the other line.
580A
LD A,(DE) 1A
Load Register A with the character of the other line at Register Pair DE.
580B
CP (HL) BE
Compare Register A against the character at Register Pair HL: the Z FLAG when they are the same.
580C
If the NZ FLAG is set (they differ), JUMP to 5857H for FIND line mismatch.
580F
DECrement Register B and LOOP BACK to 5808H while it is not 0.
5811
EX (SP),HL E3
Exchange Register Pair HL (the equals sign) with the top of the stack at the Stack Pointer: Register Pair HL = the line to check, its equals sign kept on the stack.
5812
GOSUB to 53A6H to read rr,bb of the line and position the file there.
5815
POP HL E1
Restore Register Pair HL from the stack: the equals sign of the line.
5816
GOSUB to 53D0H to compare the data after it with the file (in the first pass); Register Pair HL after the line.
5819
RET C9
RETurn with Register Pair HL at the next line.

581AH - The First Pass: Remove a Patch

The D line and its F line change places: the F line (the next line that is not a comment) is checked with the D line's text against the file, so the patch must be in it; the D line becomes a comment (a period) and the F line a D line, so the second pass writes back the bytes the F line names.

581A
PUSH HL E5
Save Register Pair HL (the D line) to the stack.
581B
GOSUB to 5834H to move Register Pair HL to the next line that is not a comment: the F line.
581E
LD (5AEAH),HL 22 EA 5A
Store Register Pair HL (the F line) at 5AEAH-5AEBH, as the line the check belongs to.
5821
POP HL E1
Restore Register Pair HL (the D line) from the stack.
5822
PUSH HL E5
Save Register Pair HL (the D line) to the stack again.
5823
GOSUB to 57ECH to check the D line at Register Pair HL against the F line and its data against the file: the patch must be there.
5826
POP HL E1
Restore Register Pair HL (the D line) from the stack.
5827
LD (HL),2EH 36 2E
Store 2EH, a period, over the verb D at Register Pair HL: the line is a comment now.
5829
LD HL,(5AEAH) 2A EA 5A
Load Register Pair HL with the F line from 5AEAH-5AEBH.
582C
LD (HL),44H 36 44
Store 44H, D, over the verb F at Register Pair HL: the second pass writes its bytes.
582E
GOSUB to 5834H to move Register Pair HL past that line and the comments after it.
5831
JUMP to 52FFH for the next line at Register Pair HL.

5834H - The Next Line That Is Not a Comment

583DH moves Register Pair HL to after the next 0DH; 5834H does that again while the line there starts with a period. 5844H reads the character at Register Pair HL in upper case and steps past it.

5834
GOSUB to 583DH to move Register Pair HL past the next 0DH, to the next line.
5837
LD A,(HL) 7E
Load Register A with the first character of the line at Register Pair HL.
5838
CP 2EH FE 2E
Compare Register A against 2EH, a period: a comment.
583A
If the Z FLAG is set (a comment), LOOP BACK to 5834H.
583C
RET C9
RETurn with Register Pair HL at the line, its first character in Register A.
583D
LD A,(HL) 7E
Load Register A with the character at Register Pair HL.
583E
INC HL 23
INCrement Register Pair HL to the next character.
583F
CP 0DH FE 0D
Compare Register A against 0DH, the end of the line.
5841
RET Z C8
If the Z FLAG is set (the end), RETurn with Register Pair HL at the next line.
5842
LOOP BACK to 583DH for the next character of the line.
5844
LD A,(HL) 7E
Load Register A with the character at Register Pair HL.
5845
INC HL 23
INCrement Register Pair HL past the character.
5846
RES 5,A CB AF
Clear bit 5 of Register A: a lower case letter becomes upper case.
5848
RET C9
RETurn with the character in Register A, in upper case.

5849H - Compare or Write a Data Byte

Register A = a data byte. In the first pass (530BH is 00H) it is compared with the next byte of the file, FIND line mismatch when they differ; in the second it is written there (5863H).

5849
LD C,A 4F
Copy Register A (the data byte) into Register C.
584A
LD A,(530BH) 3A 0B 53
Load Register A with the pass flag from 530BH: 00H in the first pass.
584D
OR A B7
OR Register A with itself: the NZ FLAG in the second pass.
584E
LD A,C 79
Copy Register C (the data byte) back into Register A. LD does not change the flags.
584F
If the NZ FLAG is set (the second pass), JUMP to 5863H to write Register A into the file.
5852
GOSUB to 56F7H to read the next byte of the file into Register A.
5855
CP C B9
Compare Register A (the byte of the file) against Register C (the data byte).
5856
RET Z C8
If the Z FLAG is set (the same), RETurn to the caller.
5857
LD HL,5A93H 21 93 5A
Point Register Pair HL to 5A93H, the message FIND line mismatch.
585A
JUMP to 5890H to show the line, then the message, and end.

585DH - Small Routines and the Errors

585DH positions the file at Register Pair DE at record Register Pair BC (@POSN); 5863H writes Register A into the file at Register Pair DE (the ROM's $PUT). An error from either goes to 5867H: @ERROR with bit 6 set shows the short message of the error code and ends the program. 586CH is error 2CH, Parameter error.

585D
GOSUB to 4442H, @POSN, to position the file at Register Pair DE at record Register Pair BC.
5860
RET Z C8
If the Z FLAG is set (no error), RETurn to the caller.
5861
JUMP to 5867H to show the error in Register A and end.
5863
GOSUB to 001BH, the ROM's $PUT, to write Register A into the file at Register Pair DE.
5866
RET Z C8
If the Z FLAG is set (no error), RETurn to the caller.
5867
OR 40H F6 40
Set bit 6 of Register A (OR 40H, the error code): the short form of the message.
5869
JUMP to 4409H, @ERROR, to show the message of the error in Register A; with bit 7 clear it does not come back, and the program ends.
586C
LD A,2CH 3E 2C
Load Register A with 2CH, the error code of Parameter error.
586E
LOOP BACK to 5867H to show the error and end.

5870H - The Messages That End PATCH

Each entry loads Register Pair HL with a message; the DDH before the next entry turns its LD HL into LD IX, so only the message entered at counts: 5870H Library overlay not found, 5874H Invalid library format, 5878H Load file format error, 587CH Fix file too big - partition it, 5880H PROGRAM file name required. The message is shown with @LOGOT and PATCH ends with @ABORT. 5889H (Non-hex digit encountered) and 588DH (Patch input format error), and 5890H for FIND line mismatch, first show the patch line at 5897H.

5870
LD HL,59D7H 21 D7 59
Point Register Pair HL to 59D7H, the message Library overlay not found.
5873
LD IX,59F1H DD 21 F1 59
Load Index Register IX with 59F1H; nothing reads it. Entered at 5874H, the bytes 21 F1 59 are LD HL,59F1H, the message Invalid library format.
5877
LD IX,5A21H DD 21 21 5A
Load Index Register IX with 5A21H; nothing reads it. Entered at 5878H, the bytes are LD HL,5A21H, the message Load file format error.
587B
LD IX,5A73H DD 21 73 5A
Load Index Register IX with 5A73H; nothing reads it. Entered at 587CH, the bytes are LD HL,5A73H, the message Fix file too big - partition it.
587F
LD IX,5910H DD 21 10 59
Load Index Register IX with 5910H; nothing reads it. Entered at 5880H, the bytes are LD HL,5910H, the message PROGRAM file name required.
5883
GOSUB to 428AH, @LOGOT, to show the message at Register Pair HL up to its 0DH and put it in the job log.
5886
JUMP to 4030H, @ABORT, back to LDOS with the program ended in error.
5889
LD HL,5A38H 21 38 5A
Point Register Pair HL to 5A38H, the message Non-hex digit encountered.
588C
LD IX,5A08H DD 21 08 5A
Load Index Register IX with 5A08H; nothing reads it. Entered at 588DH, the bytes are LD HL,5A08H, the message Patch input format error.
5890
PUSH HL E5
Save Register Pair HL (the message) to the stack.
5891
LD A,0DH 3E 0D
Load Register A with 0DH, a new line after the status line.
5893
GOSUB to 0033H, the ROM's display of the character in Register A.
5896
LD HL,0000H 21 00 00
Load Register Pair HL with the patch line being worked on, the operand at 5897H (0000H in the file; set at 5307H, 5579H, 57ECH).
5899
GOSUB to 428AH, @LOGOT, to show the line at Register Pair HL up to its 0DH and put it in the job log.
589C
POP HL E1
Restore Register Pair HL (the message) from the stack.
589D
LOOP BACK to 5883H to show the message and end.

589FH - The Texts

The default extensions, the banner, the status texts (each between 1DH, the cursor to the start of the line, and 1EH, clear to the end of the line, then 1DH and 03H, so each one is shown over the one before), and the messages, each ended by 0DH.

589F-58A1
DEFM "CMD" 43 4D 44
589FH-58A1H: CMD, the default extension of the file to patch (5218H).
58A2-58A4
DEFM "FIX" 46 49 58
58A2H-58A4H: FIX, the default extension of the patch file (5234H).
58A5
DEFB 0AH 0A
58A5H: 0AH, a line feed, the start of the banner (5201H).
58A6-58DB
DEFM "PATCH - LDOS Object File Patch Utility - Version 5.3.1" 50 41 54 43 48 20 2D 20 4C 44 4F 53 20 4F 62 6A 65 63 74 20 46 69 6C 65 20 50 61 74 63 68 20 55 74 69 6C 69 74 79 20 2D 20 56 65 72 73 69 6F 6E 20 35 2E 33 2E 31
58A6H-58DBH: the first line of the banner, the name and the version.
58DC
DEFB 0AH 0A
58DCH: 0AH, a line feed after the first line.
58DD-590D
DEFM "Copyright 1991 MISOSYS, Inc., All rights reserved" 43 6F 70 79 72 69 67 68 74 20 31 39 39 31 20 4D 49 53 4F 53 59 53 2C 20 49 6E 63 2E 2C 20 41 6C 6C 20 72 69 67 68 74 73 20 72 65 73 65 72 76 65 64
58DDH-590DH: the second line of the banner, the copyright.
590E-590F
DEFB 0AH,0DH 0A 0D
590EH-590FH: 0AH and 0DH, the end of the banner.
5910-592A
DEFM "PROGRAM file name required" / DEFB 0DH 50 52 4F 47 52 41 4D 20 66 69 6C 65 20 6E 61 6D 65 20 72 65 71 75 69 72 65 64 0D
5910H-592AH: the message of 5880H and its 0DH.
592B-5943
DEFB 1DH / DEFM "Positioning load file" / DEFB 1EH,1DH,03H 1D 50 6F 73 69 74 69 6F 6E 69 6E 67 20 6C 6F 61 64 20 66 69 6C 65 1E 1D 03
592BH-5943H: the status text of 5526H, shown while the load records are read.
5944-5954
DEFB 1DH / DEFM "Reading input" / DEFB 1EH,1DH,03H 1D 52 65 61 64 69 6E 67 20 69 6E 70 75 74 1E 1D 03
5944H-5954H: the status text of 52FFH, shown for each patch line.
5955-5968
DEFB 1DH / DEFM "Generating patch" / DEFB 1EH,1DH,03H 1D 47 65 6E 65 72 61 74 69 6E 67 20 70 61 74 63 68 1E 1D 03
5955H-5968H: the status text of 555BH, shown while the records are built.
5969-597C
DEFB 1DH / DEFM "Installing patch" / DEFB 1EH,1DH,03H 1D 49 6E 73 74 61 6C 6C 69 6E 67 20 70 61 74 63 68 1E 1D 03
5969H-597CH: the status text of 534FH and 5610H.
597D-5997
DEFB 1DH / DEFM "Re-building library map" / DEFB 1EH,1DH,03H 1D 52 65 2D 62 75 69 6C 64 69 6E 67 20 6C 69 62 72 61 72 79 20 6D 61 70 1E 1D 03
597DH-5997H: the status text of 5519H, shown while the member headers are changed.
5998-59B2
DEFB 1DH / DEFM "Yanking patch from file" / DEFB 1EH,1DH,03H 1D 59 61 6E 6B 69 6E 67 20 70 61 74 63 68 20 66 72 6F 6D 20 66 69 6C 65 1E 1D 03
5998H-59B2H: the status text of 5418H, shown while a patch is yanked.
59B3-59D6
DEFB 0AH / DEFM "Can't yank, patch not in load file" / DEFB 0DH 0A 43 61 6E 27 74 20 79 61 6E 6B 2C 20 70 61 74 63 68 20 6E 6F 74 20 69 6E 20 6C 6F 61 64 20 66 69 6C 65 0D
59B3H-59D6H: the message of 549EH, after a line feed.
59D7-59F0
DEFM "Library overlay not found" / DEFB 0DH 4C 69 62 72 61 72 79 20 6F 76 65 72 6C 61 79 20 6E 6F 74 20 66 6F 75 6E 64 0D
59D7H-59F0H: the message of 5870H and its 0DH, after @LOGOT and before @ABORT.
59F1-5A07
DEFM "Invalid library format" / DEFB 0DH 49 6E 76 61 6C 69 64 20 6C 69 62 72 61 72 79 20 66 6F 72 6D 61 74 0D
59F1H-5A07H: the message of 5874H and its 0DH, after @LOGOT and before @ABORT.
5A08-5A20
DEFM "Patch input format error" / DEFB 0DH 50 61 74 63 68 20 69 6E 70 75 74 20 66 6F 72 6D 61 74 20 65 72 72 6F 72 0D
5A08H-5A20H: the message of 588DH and its 0DH, shown after the patch line.
5A21-5A37
DEFM "Load file format error" / DEFB 0DH 4C 6F 61 64 20 66 69 6C 65 20 66 6F 72 6D 61 74 20 65 72 72 6F 72 0D
5A21H-5A37H: the message of 5878H and its 0DH, after @LOGOT and before @ABORT.
5A38-5A51
DEFM "Non-hex digit encountered" / DEFB 0DH 4E 6F 6E 2D 68 65 78 20 64 69 67 69 74 20 65 6E 63 6F 75 6E 74 65 72 65 64 0D
5A38H-5A51H: the message of 5889H and its 0DH, shown after the patch line.
5A52-5A72
DEFB 0AH / DEFM "Patch(s) successfully installed" / DEFB 0DH 0A 50 61 74 63 68 28 73 29 20 73 75 63 63 65 73 73 66 75 6C 6C 79 20 69 6E 73 74 61 6C 6C 65 64 0D
5A52H-5A72H: the closing message after a line feed, the operand of 5383H in the file.
5A73-5A92
DEFM "Fix file too big - partition it" / DEFB 0DH 46 69 78 20 66 69 6C 65 20 74 6F 6F 20 62 69 67 20 2D 20 70 61 72 74 69 74 69 6F 6E 20 69 74 0D
5A73H-5A92H: the message of 587CH and its 0DH, after @LOGOT and before @ABORT.
5A93-5AA5
DEFM "FIND line mismatch" / DEFB 0DH 46 49 4E 44 20 6C 69 6E 65 20 6D 69 73 6D 61 74 63 68 0D
5A93H-5AA5H: the message of 5857H and its 0DH, shown after the patch line.
5AA6-5ABF
DEFM "Patch successfully yanked" / DEFB 0DH 50 61 74 63 68 20 73 75 63 63 65 73 73 66 75 6C 6C 79 20 79 61 6E 6B 65 64 0D
5AA6H-5ABFH: the closing message after a yank (5490H).

5AC0H - The Name, the Parameter Table and the Cells

The name the patch gets in the file, the table of @PARAM (6 characters and the address of the result, ended by 00H), the D line pointer and the two results. From 5AF0H on is memory the file does not load: the control blocks, the buffers and the patch text.

5AC0
DEFB 03H 03
5AC0H: the length of the patch's name, 03H for CLP in the file; the length of the patch file's name (525AH). Read at 52A5H, 5450H and 5565H.
5AC1-5AC8
DEFM "CLP " 43 4C 50 20 20 20 20 20
5AC1H-5AC8H: the name of the patch, CLP (command line patch) in the file, the patch file's name after 523DH; it goes into the record of type 07H (555BH) and is looked for by a yank (5456H).
5AC9-5AD0
DEFM "REMOVE" / DEFW 5AECH 52 45 4D 4F 56 45 EC 5A
5AC9H-5AD0H: the parameter REMOVE and the address of its result, 5AECH.
5AD1-5AD8
DEFM "R " / DEFW 5AECH 52 20 20 20 20 20 EC 5A
5AD1H-5AD8H: R, the short form of REMOVE, and 5AECH.
5AD9-5AE0
DEFM "OPTION" / DEFW 5AEEH 4F 50 54 49 4F 4E EE 5A
5AD9H-5AE0H: the parameter OPTION and the address of its result, 5AEEH.
5AE1-5AE8
DEFM "O " / DEFW 5AEEH 4F 20 20 20 20 20 EE 5A
5AE1H-5AE8H: O, the short form of OPTION, and 5AEEH.
5AE9
DEFB 00H 00
5AE9H: 00H, the end of the table of @PARAM, after the four entries.
5AEA-5AEB
DEFW 0000H 00 00
5AEAH-5AEBH: the D line being checked in the first pass (57E0H), or its F line for a removal (581EH); read at 57F0H and 5829H.
5AEC-5AED
DEFW 0000H 00 00
5AECH-5AEDH: the result of REMOVE: 0000H, FFFFH when REMOVE is given; its low byte goes to 57DBH (527BH).
5AEE-5AEF
DEFW FFFFH FF FF
5AEEH-5AEFH: the result of OPTION: FFFFH, 0000H for OPTION=N; its low byte goes to 57D5H (5275H).
5AF0-5B0F
DEFS 32
5AF0H-5B0FH: not in the file. The control block of the file to patch: the file specification as text after @FSPEC (5211H), then the open file (@OPEN 5223H); +01H byte 5AF1H (bit 7 cleared at 54E9H), +05H offset 5AF5H (53CCH, 54FBH), +09H record length 5AF9H (01H for @BKSP, then 00H).
5B10-5B2F
DEFS 32
5B10H-5B2FH: not in the file. The control block of the patch file (@FSPEC 522DH, @OPEN 52B2H; its specification read for the name at 523AH); later the second control block of the file to patch, copied at 561FH, its buffer address +03H at 5B13H.
5C00-5CFF
DEFS 256
5C00H-5CFFH: not in the file. The buffer of the patch file (52AFH).
5D00-5DFF
DEFS 256
5D00H-5DFFH: not in the file. The buffer of the second control block of the file to patch, for the old bytes (5621H).
5E00-5EFF
DEFS 256
5E00H-5EFFH: not in the file. The buffer of the file to patch (521EH).
5F00-72FF
DEFS 5120
5F00H-72FFH: not in the file. The patch text: its lines, each ended by 0DH, then 03H (52A0H, 52F9H). From 7300H up, memory the program uses too: the records built by 555BH and the old bytes kept by 5605H, or the copy of the member headers (56FEH).