TRS-80 DOS - NEWDOS/80 v2.0 for the Model III - SYS10/SYS Disassembled

Page Customization

Introduction/Summary

NEWDOS/80 v2.0 SYS10/SYS Disassembly - GET and PUT (Model III)

SYS10/SYS carries out the Disk BASIC statements GET and PUT. It loads 4D00H-51E7H in five load records (transfer address 4D00H); the code ends at 51CDH and 51CEH-51E7H are 26 bytes of 00H. BASIC/CMD loads it with LD A,2CH / RST 28H at 610AH: the SYS0/SYS dispatcher calls 4D00H, which drops the dispatcher's return address so that the RET goes straight back to BASIC, and BASIC then jumps to 4D03H (from 6107H). Before that BASIC has pushed Register Pair AF (the Z FLAG set for GET, clear for PUT), read the file number and copied the file area's 2DH-byte header and FCB to the work area 5700H-572CH (Index Register IX = 5700H).

4D03H first sets BASIC's reload flag (the operand 6226H) to 01H, so that BASIC loads SYS10/SYS again after any DOS call it makes for the statement, then marks the mode byte at 5700H with bit 4 for a PUT and reads the position parameter. The file is positioned through BASIC's helpers (which call SYS0/SYS 444EH) and the record is moved: a plain random file moves one record between the file and its record buffer, an item file moves a list of variables or expressions. The statement ends through BASIC 641EH, which copies the work area back to the file area. SYS10/SYS does almost everything through BASIC/CMD's routines 5C9CH-662CH; every call names what the routine does.

The page shows every byte of the file once, in address order.

The Position Parameter

GET f [,position] [,item list] and PUT f [,position] [,item list]. Without a position (or with an empty one, two commas) the file's current position NEXT is used until a record start is known (5701H bit 6). After that a file with fixed-length records goes on to the next record (the record start plus the record length), type MU skips to the next record's 70H marker, and type MI continues where the last GET or PUT ended (4D20H-4D33H).

PositionMeaning
nA record number, 1 or more: the byte position is (n - 1) x the record length (4E5FH-4E97H). Only files with fixed-length records (mode bit 2).
multiplication signFor an item file with the second letter U or F and a known record start: continue where the last GET or PUT ended (5704H-5706H), inside the record. Type MI, or no record start yet, as without a position; a plain random file is error A6H (4D5CH-4D73H).
#The last record start again (5707H-5709H, 4D75H).
$Where the last statement started (570AH-570CH, 4D81H).
%No file access: each string variable of the item list is cut or padded with spaces to its length prefix (4D93H, 501CH).
& and &&Write the sector buffer if it was changed; && also writes the end of file into the directory through SYS0/SYS 4451H (4DA2H).
!n, !$n, !#n, !%, !$%A byte position: !n gets or puts there, !$n only positions the file, !#n sets the end of file to n (the file must be writable), !% and !$% use the end of file as the position. With fixed-length records the byte position must be a multiple of the record length (4DBCH-4E46H).

A bad position value (a string, a negative number, a value of 224 or more, a byte position inside a record) is error A6H BAD FILE POSITIONING PARAM; a record number of 0 or one whose position does not fit in 24 bits is 7EH BAD RECORD #.

Item Files

The mode byte at 5700H holds the file's type from OPEN: bit 7 random, bit 6 may be written, bit 5 may be read, bit 4 this statement is a PUT (set by SYS10/SYS), bit 3 the second letter U or F, bit 2 fixed-length records, bit 1 the letter F, bit 0 the letter M. The item file types are MI (01H), MU (09H), MF (0DH), FI and FF. A type M file stores every value with a marker byte: 72H an integer (2 bytes), 73H single precision (4 bytes), 74H double precision (8 bytes), 80H + n a string of n characters (below 128), 71H n a longer string, 00H a filler byte and 70H the start of a record (type MU). A type F file stores the raw bytes of each value, a string as exactly its length prefix in characters.

The item list follows the position: either the number of a program line that holds the list, or a second comma and the list in the statement. Items are separated by commas and the list may end with a semicolon. An item may start with a length prefix (n), 0-255, and # or $ items skip or write n bytes. Before a PUT into an existing record of a type M file, or into a type F file, the list is run once with bit 2 of 572DH set to count the bytes (BASIC 61C8H then writes nothing), so that a list that does not fit is error 8EH RECORD OVERFLOW before anything is written (4F3DH-4F87H).

Variables

ROM Addresses

Address
Size
Contents
40AFH
1 byte
Value Type
02H integer, 03H string, 04H single, 08H double precision; set to an item's type at 5086H, tested through RST 20H.
40D6H-40D7H
2 bytes
FRETOP
The bottom of the string space in use: a string above it is in the string space, one below it is a literal in the program (5036H, 50A6H).
40DFH-40E0H
2 bytes
TEMP
Where a numeric value was read, stored at 50D1H before the ROM's LET code at 1F33H stores it into the variable.
411DH-4124H
8 bytes
Double Precision REG 1
A double precision value is read to and written from 411DH (50CBH, 5169H).
4121H-4124H
4 bytes
REG 1
An integer (4121H-4122H) or single precision value; 4123H the high mantissa byte (bit 7 the sign) and 4124H the exponent (4DE6H, 4DEAH, 50BFH, 5164H).

DOS Addresses

Address
Size
Contents
4451H
3 bytes
Write End of File
SYS0/SYS vector, called through BASIC 621EH for the && position (4DB3H).

The Work Area (BASIC/CMD 5700H-572DH)

Address
Size
Contents
5700H
1 byte
Mode Byte
IX+00H. Bit 7 random, 6 writable, 5 readable, 4 PUT (4D0DH-4D13H), 3 second letter U or F, 2 fixed-length records, 1 letter F, 0 letter M. The % position stores A2H (4D97H).
5701H
1 byte
Second Mode Byte
IX+01H. Bit 7 the file may be extended (4EE9H, 4F61H), bit 6 a record start is known (4D23H, 4D64H; cleared by !$ at 4E30H).
5702H-5703H
2 bytes
Record Length
1-256 (4E74H, 4ED0H, 4F11H).
5704H-5706H
3 bytes
Last End
Where the last GET or PUT ended (BASIC 6110H, 610DH, 6122H; 4F70H reads the low 16 bits).
5707H-5709H
3 bytes
Record Start
Stored by BASIC 6117H (4D39H, 4E5AH), read by 6129H.
570AH-570CH
3 bytes
Statement Start
Where this statement started (4D4BH, 4D4EH), read back by the $ position (4D85H, 4D88H).
570DH-572CH
32 bytes
FCB
The file's FCB: 570EH (FCB+1) bit 4 buffer changed (4DA6H), 5710H-5711H (FCB+3) the sector buffer (4F0EH), NEXT 5712H and 5717H-5718H, EOF 5715H and 5719H-571AH.
572DH
1 byte
Statement Flags
IX+2DH. Bit 1 the list is in another line (4F2EH), bit 2 counting run (4F7CH, 4F87H), bit 3 the record runs to the end of file (4F5DH), bit 4 the position is at or past the end of file (BASIC 615EH), bit 5 the % position (4D9BH), bit 6 the item has a length prefix (4FE0H, 4FFAH).

Operands Changed at Run Time

Address
Size
Contents
4F8CH-4F8DH
2 bytes
Room in the Record
Operand of LD DE,nnnn at 4F8BH: stored at 4F1BH (from BASIC 6331H) and 4F77H (the existing record's length), copied to 61CAH at 4F8EH.
5094H
1 byte
Length Prefix
Operand of LD A,nn at 5093H: the item's prefix n or FFH for none (500CH); BASIC 6136H and 62D8H read it.
5D38H-5D39H
2 bytes
Item Number
Operand of BASIC's LD DE,nnnn at 5D37H, used in its error messages (4F95H, 5193H).
61CAH-61CBH
2 bytes
Room Counter
Operand of BASIC's LD HL,nnnn at 61C9H, lowered by every item written (4F8EH).
6226H
1 byte
Reload Flag
Operand of BASIC's LD A,nn at 6225H: 01H makes BASIC reload SYS10/SYS after a DOS call (4D05H).

Outside Routines

WhereAddresses
ROM09D6H (copy a string), 0A7FH (CINT), 0AF6H (TYPE MISMATCH), 1E5AH (LINGET), 1EC5H (find a line), 1F33H (LET), 260DH (PTRGET), 29E3H (inside FREFAC); RST 10H, RST 18H, RST 20H.
BASIC/CMD5C9CH, 5CACH, 5CBCH, 5D9DH, 5DA9H, 5DB2H, 5DBEH, 5DC1H, 5DCDH, 5DD0H, 5DD3H, 5DDCH (errors), 5EE1H, 6031H, 603EH, 60EBH, 610DH, 6110H, 6117H, 6122H, 6129H, 612FH, 6136H, 614CH, 615EH, 6190H, 619CH, 61A3H, 61A6H, 61ACH, 61B3H, 61C8H, 61DFH, 620FH, 6214H, 621EH, 6232H, 6237H, 6245H, 6246H, 6258H, 626CH, 62C7H, 62CEH, 62D0H, 62D8H, 62FFH, 6331H, 6346H, 635AH, 6362H, 6368H, 641EH, 661CH, 6623H, 662CH.
Entries from BASIC/CMD4D03H (from 6107H), 4DE4H (from 6629H), 4E17H (from 6620H).

Disassembly

4D00H - Load Entry

BASIC loads SYS10/SYS with LD A,2CH / RST 28H (BASIC 610AH). The SYS0/SYS dispatcher (4BC2H) has already dropped the RST's own return address and calls 4D00H with the return to 4BC5H on top of the stack. SYS10/SYS discards that word, so the RET goes straight back to the caller of 610AH: BASIC then jumps to 4D03H (from 6107H), or simply carries on when 610AH only reloaded SYS10/SYS after a DOS call. Because 4BC5H is skipped, 4289H bit 6 stays set; BASIC clears it at the end of the statement (643AH).

4D00
INC SP 33
Increment the Stack Pointer SP past the low byte of the return address into SYS0/SYS 4BC5H, discarding it.
4D01
INC SP 33
Increment the Stack Pointer SP past the high byte: the word at the top of the stack is now the return address into the caller of BASIC 610AH.
4D02
RET C9
RETURN to the caller of BASIC 610AH; the SYS10/SYS code is now in memory at 4D00H-51E7H.

4D03H - GET and PUT

Entered by JP 4D03H at BASIC 6107H. BASIC's GET (60FFH, vector 417FH) and PUT (60FEH, vector 4182H) push Register Pair AF with the Z FLAG set for GET and clear for PUT, read the file number through 5F53H, copy the file area's 2DH-byte header to 5700H-572CH (Index Register IX = 5700H; 570DH-572CH is the file's FCB) and clear the statement flags at 572DH (IX+2DH). Register Pair HL is the BASIC text pointer after the file number. The statement is GET f / PUT f, optionally followed by a position (a record number, or one of the characters * # $ % & !) and an item list (see 4F18H).

4D03
LD A,01H 3E 01
Load Register A with 01H, the value that 4D05H stores into BASIC's reload flag (the operand 6226H of BASIC's LD A,nn at 6225H); 01H there tells BASIC that SYS10/SYS must be loaded again after a DOS call.
4D05
LD (6226H),A 32 26 62
Self-Modifying Code
Store Register A (01H) at 6226H, the operand of BASIC's LD A,nn at 6225H: from now on BASIC reloads SYS10/SYS (through 610AH) after every DOS call it makes, since a DOS call may bring another overlay into 4D00H.
4D08
POP AF F1
Restore Register Pair AF from the stack: the GET/PUT flag BASIC pushed, the Z FLAG set for GET and clear for PUT.
4D09
LD DE,(5700H) ED 5B 00 57
Load Register Pair DE with the 16-bit value at 5700H: E = the file's mode byte (5700H), D = the second mode byte (5701H).
4D0D
RES 4,E CB A3
Clear bit 4 of Register E, the mode byte's PUT bit (bit 4 = this statement is a PUT). RES does not change the flags.
4D0F
If the Z FLAG is set (the Z FLAG restored from the AF that BASIC pushed: a GET), JUMP to 4D13H with bit 4 of Register E, the mode byte from 5700H, left clear.
4D11
SET 4,E CB E3
It is a PUT (the Z FLAG from the AF that BASIC pushed was clear): set bit 4 of Register E, the copy of the mode byte read from 5700H at 4D09H, so bit 4 marks this statement as a PUT.
4D13
LD (IX+00H),E DD 73 00
Store Register E (the mode byte with bit 4 = PUT) at Index Register IX+00H, the mode byte at 5700H.
4D16
GOSUB to BASIC 6368H with Register Pair HL = the text pointer: the Z FLAG is set if the statement ends here; otherwise it requires a comma and returns the NZ FLAG with Register A = the character after it.
4D19
If the Z FLAG is set (the statement ends after the file number), JUMP to 4D1FH: no position given.
4D1B
CP 2CH FE 2C
Compare Register A (the character after the comma) against 2CH, a second comma: no position given, an item list follows.
4D1D
If the NZ FLAG is set (Register A, the character after the comma, is not a second comma), JUMP to 4D5AH to read the position parameter at Register Pair HL.
4D1F
PUSH HL E5
Save Register Pair HL (the BASIC text pointer, at the end of the statement or at the second comma) on the stack; 4D36H-4D57H keep it there until the statement ends at 51B1H.
4D20
GOSUB to BASIC 61ACH, which returns Register C and Register Pair HL = the file's current position NEXT (FCB+5 at 5712H, FCB+10/11 at 5717H-5718H): C the low byte, L the middle, H the high byte.
4D23
BIT 6,D CB 72
Test bit 6 of Register D (the second mode byte, 5701H), set once a GET or PUT has stored a record start at 5707H-5709H.
4D25
If the Z FLAG is set (no record start yet), JUMP to 4D36H and use NEXT in Register C and Register Pair HL.
4D27
GOSUB to BASIC 6122H, which returns Register C and Register Pair HL = the position where the last GET or PUT ended (5704H-5706H).
4D2A
BIT 3,E CB 5B
Test bit 3 of Register E, the mode byte: set for item files of the second letter U or F, and for the plain random file.
4D2C
If the Z FLAG is set (second letter I), JUMP to 4D36H: continue where the last statement ended.
4D2E
BIT 2,E CB 53
Test bit 2 of Register E, the mode byte: set for fixed-length records (second letter F, and the plain random file).
4D30
If the Z FLAG is set (bit 2 of Register E, the mode byte from 5700H, is clear: the item file of type MU, records of marked items), JUMP to 4E48H to skip to the next record's 70H marker; Register C and Register Pair HL still hold the end of the last GET or PUT.
4D33
Fixed-length records: GOSUB to BASIC 603EH, which returns Register C and Register Pair HL = the last record start (5707H-5709H) plus the record length (5702H-5703H): the next record.
4D36
GOSUB to BASIC 614CH, which checks the mode byte in Register E allows the statement (bit 7 = random, then bit 5 for GET or bit 6 for PUT), else error 6CH BAD FILE MODE.
4D39
GOSUB to BASIC 6117H, which stores Register C and Register Pair HL as the record start (5707H-5709H) and sets bit 6 of 5701H.
4D3C
BIT 4,E CB 63
Test bit 4 of Register E, the mode byte from 5700H with bit 4 set at 4D11H for a PUT and cleared at 4D0DH for a GET; the Z FLAG is set for a GET.
4D3E
If the NZ FLAG is set (a PUT), GOSUB to BASIC 615EH: a position (Register C and Register Pair HL) at or past the end of file sets bit 4 of 572DH; past it, the file must have fixed-length records (else error A6H BAD FILE POSITIONING PARAM) and an item file is padded with records of 00H bytes up to the position.
4D41
LD A,(5700H) 3A 00 57
Load Register A with the byte at 5700H, the mode byte of the file area's working copy (Index Register IX = 5700H); 4D3EH may have changed the flags, so it is read again here.
4D44
AND 0FH E6 0F
Mask Register A (the mode byte read from 5700H) against 0FH (0000 1111) to keep the file type in bits 0-3 (bit 0 M, bit 1 F, bit 2 fixed-length records, bit 3 second letter U or F).
4D46
CP 09H FE 09
Compare Register A (the file type, bits 0-3 of the mode byte at 5700H) against 09H, the type MU (bit 3 = second letter U or F, bit 0 = letter M, bit 2 clear = no fixed-length records): the Z FLAG is set for MU.
4D48
If the Z FLAG is set (Register A, the file type from 5700H, is 09H, type MU), JUMP to 4E9AH to position the file at Register C / L / H and handle the 70H record marker.
4D4B
LD (570BH),HL 22 0B 57
Store Register Pair HL (the position's middle and high bytes) at 570BH-570CH, where this statement started.
4D4E
LD (IX+0AH),C DD 71 0A
Store Register C (the low byte of the position) at Index Register IX+0AH, 570AH: with 570BH-570CH it is where this statement started, read back by the $ position (4D85H).
4D51
GOSUB to BASIC 6110H, which stores Register C and Register Pair HL at 5704H-5706H as well, the position of the last GET or PUT.
4D54
GOSUB to BASIC 61A6H, which positions the file to Register C / L / H (SYS0/SYS 444EH through the FCB at 570DH).
4D57
JUMP to 4EBEH for the transfer, with the file positioned at Register C (low), Register L (middle) and Register H (high) and the BASIC text pointer on the stack.

4D5AH - The Position Characters

Register A holds the first character of the position parameter and Register Pair HL points at it. The multiplication sign (token CFH) continues at the position where the last GET or PUT ended, # uses the last record start again, $ the position where the last statement started, % formats string variables to their item lengths without any file access, & writes the buffer (&& also the end of file), ! takes a byte position. Anything else is a record number (4E5FH).

4D5A
INC HL 23
Increment Register Pair HL, the BASIC text pointer, past the position character held in Register A.
4D5B
PUSH HL E5
Save Register Pair HL (the BASIC text pointer after the position character) on the stack; 4DA1H takes it back, or it stays there for the end of the statement.
4D5C
CP CFH FE CF
Compare Register A (the character at Register Pair HL) against CFH, the token BASIC stores for the multiplication sign.
4D5E
If the NZ FLAG is set (Register A is not the multiplication sign token CFH), JUMP to 4D75H to test the other position characters.
4D60
BIT 3,E CB 5B
Test bit 3 of Register E, the mode byte (item files of the second letter U or F, and the plain random file).
4D62
If the Z FLAG is set (bit 3 of Register E, the mode byte from 5700H, is clear: second letter I), JUMP to 4D20H and treat the statement as having no position.
4D64
BIT 6,D CB 72
Test bit 6 of Register D, the second mode byte read from 5701H at 4D09H: set once a record start has been stored at 5707H-5709H.
4D66
If the Z FLAG is set (bit 6 of Register D, the second mode byte from 5701H, is clear: no record start has been stored at 5707H-5709H yet), JUMP to 4D20H as well and use NEXT as the position.
4D68
LD A,(5700H) 3A 00 57
Load Register A with the byte at 5700H, the mode byte of the working copy of the file area (Index Register IX = 5700H).
4D6B
AND 03H E6 03
Mask Register A against 03H (0000 0011) to keep bits 0-1, the item file letters M and F.
4D6D
If the Z FLAG is set (not an item file), JUMP to 4E06H for error A6H BAD FILE POSITIONING PARAM.
4D70
GOSUB to BASIC 6122H, which returns Register C and Register Pair HL = the position where the last GET or PUT ended.
4D73
JUMP to 4D8EH to check the mode byte in Register E for GET or PUT (BASIC 614CH) with the position in Register C and Register Pair HL, the end of the last GET or PUT read from 5704H-5706H.
4D75
CP 23H FE 23
Compare Register A (the character of the position parameter at Register Pair HL, the BASIC text pointer, minus one) against 23H, a #: the Z FLAG is set if the position is #, use the last record start again.
4D77
If the NZ FLAG is set (Register A, the position character, is not 23H #), JUMP to 4D81H to test for $.
4D79
GOSUB to BASIC 6129H, which returns Register C and Register Pair HL = the last record start; error 6CH BAD FILE MODE if bit 6 of 5701H is clear.
4D7C
GOSUB to BASIC 614CH to check the mode byte in Register E (from 5700H, bit 4 = PUT) for GET or PUT: the file must be random and readable or writable, else error 6CH.
4D7F
JUMP to 4D41H to go on with the position in Register C and Register Pair HL, the last record start read from 5707H-5709H by BASIC 6129H.
4D81
CP 24H FE 24
Compare Register A (the position character read from the BASIC text) against 24H, a $: the Z FLAG is set if the position is $, the position where the last statement started (570AH-570CH).
4D83
If the NZ FLAG is set (Register A, the position character, is not 24H $), JUMP to 4D93H to test for %.
4D85
LD C,(IX+0AH) DD 4E 0A
Load Register C with the byte at Index Register IX+0AH (570AH), the low byte of the position where the last statement started.
4D88
LD HL,(570BH) 2A 0B 57
Load Register Pair HL with the 16-bit value at 570BH, the middle and high bytes of that position.
4D8B
GOSUB to BASIC 612FH: error 6CH BAD FILE MODE if bit 6 of 5701H is clear (no statement has run yet).
4D8E
GOSUB to BASIC 614CH to check the mode byte in Register E (from 5700H, bit 4 = PUT) for GET or PUT: the file must be random and readable or writable, else error 6CH.
4D91
JUMP to 4D4BH to store the position in Register C and Register Pair HL and position the file.
4D93
CP 25H FE 25
Compare Register A (the position character read from the BASIC text) against 25H, a %: the Z FLAG is set for %, which formats string variables without any file access.
4D95
If the NZ FLAG is set (Register A, the position character, is not 25H %), JUMP to 4DA1H to test for & and !.
4D97
LD (IX+00H),A2H DD 36 00 A2
Store A2H at Index Register IX+00H, the working copy's mode byte (5700H): random (bit 7), GET allowed (bit 5), type letter F (bit 1), not a PUT. The file area keeps its own mode byte because the copy is not written back (51C3H).
4D9B
SET 5,(IX+2DH) DD CB 2D EE
Set bit 5 of the byte at Index Register IX+2DH (572DH, the statement flags): the item list only formats string variables (501DH).
4D9F
JUMP to 4D57H, which jumps on to 4EBEH, with Index Register IX = 5700H and the stack holding the text pointer pushed at 4D5BH; the file is not positioned for the % position.
4DA1
POP HL E1
Restore Register Pair HL from the stack: the BASIC text pointer after the position character, pushed at 4D5BH.
4DA2
CP 26H FE 26
Compare Register A (the position character read from the BASIC text) against 26H, an &: the Z FLAG is set for &, which writes the sector buffer of the file.
4DA4
If the NZ FLAG is set (Register A, the position character, is not 26H &), JUMP to 4DBCH to test for !.
4DA6
BIT 4,(IX+0EH) DD CB 0E 66
Test bit 4 of the byte at Index Register IX+0EH (570EH, FCB+1): set when the sector buffer has been changed.
4DAA
If the NZ FLAG is set (changed), GOSUB to BASIC 6237H to write the buffer (SYS0/SYS 443CH, write with verify).
4DAD
LD A,(HL) 7E
Load Register A with the byte at Register Pair HL, the next character of the statement.
4DAE
CP 26H FE 26
Compare Register A (the character after the &, read from Register Pair HL) against 26H, a second &: && also writes the end of file into the directory.
4DB0
If the NZ FLAG is set (Register A is not 26H: a single &), JUMP to 51BEH to end the statement with Register Pair HL, the BASIC text pointer.
4DB3
LD DE,4451H 11 51 44
Load Register Pair DE with 4451H, the SYS0/SYS vector that writes the end of file into the directory.
4DB6
GOSUB to BASIC 621EH, which calls the vector in Register Pair DE with the FCB at 570DH (errors are handled through BASIC 5DEFH).
4DB9
JUMP to 51BFH to end the statement with Register Pair HL = the BASIC text pointer at the second &, which RST 10H steps past.
4DBC
CP 21H FE 21
Compare Register A (the position character read from the BASIC text) against 21H, a !: the Z FLAG is set for !, a byte position in the file.
4DBE
If the NZ FLAG is set (Register A is not 21H !, so the character is the start of an expression), JUMP to 4E5FH to read a record number.
4DC1
LD B,00H 06 00
Load Register B with 00H, the kind of ! position: plain ! (GET or PUT at a byte position); 4DCCH and 4DDEH-4DDFH raise it for !$ and !#.
4DC3
LD A,(HL) 7E
Load Register A with the byte at Register Pair HL, the BASIC text pointer: the character after the ! (4D5AH stepped past the !).
4DC4
CP 25H FE 25
Compare Register A (the character after the !, read from Register Pair HL, the BASIC text pointer) against 25H, a %: !% positions the file at its end.
4DC6
If the Z FLAG is set (Register A is 25H: !%), JUMP to 4E37H with Register B = 00H: the position is the end of file.
4DC8
CP 24H FE 24
Compare Register A (the character after the !, read from the BASIC text at Register Pair HL) against 24H, a $: !$ only positions the file.
4DCA
If the NZ FLAG is set (Register A, the character after the !, is not 24H $), JUMP to 4DD5H to test for #, with Register B still 00H.
4DCC
INC B 04
Increment Register B, the kind of ! position, from 00H to 01H: !$ only positions the file.
4DCD
INC HL 23
Increment Register Pair HL, the BASIC text pointer, past the $ of !$, so that it points at the next character.
4DCE
LD A,(HL) 7E
Load Register A with the byte at Register Pair HL, the BASIC text pointer: the character after the $.
4DCF
CP 25H FE 25
Compare Register A (the character after the $, read from the BASIC text at Register Pair HL) against 25H, a %: !$% positions the file at its end.
4DD1
If the Z FLAG is set (Register A is 25H: !$%), JUMP to 4E37H with Register B = 01H to position the file at its end.
4DD3
JUMP to 4DE0H to push the kind in Register B (01H, !$) and read the position expression at Register Pair HL, the BASIC text pointer.
4DD5
CP 23H FE 23
Compare Register A (the character after the !, read from the BASIC text at Register Pair HL) against 23H, a #: !# sets the end of file to the position.
4DD7
If the NZ FLAG is set (Register A, the character after the !, is not 23H #), JUMP to 4DE0H with Register B = 00H, plain !.
4DD9
BIT 6,E CB 73
Test bit 6 of Register E, the mode byte read from 5700H: set if the file may be written (!# changes the end of file).
4DDB
If the Z FLAG is set (read only), JUMP to 4E06H for error A6H BAD FILE POSITIONING PARAM.
4DDD
INC HL 23
Increment Register Pair HL, the BASIC text pointer, past the # of !#, so that it points at the position expression.
4DDE
INC B 04
Increment Register B, the kind of ! position, from 00H (loaded at 4DC1H) to 01H; 4DDFH makes it 02H, the value for !#.
4DDF
INC B 04
Increment Register B, the kind of ! position, from 01H to 02H: !# sets the end of file to the position (4E42H).
4DE0
PUSH BC C5
Save Register Pair BC on the stack: Register B = the kind of ! position (00H !, 01H !$, 02H !#), popped into Register A at 4E28H.
4DE1
JUMP to BASIC 661CH, which evaluates the expression at Register Pair HL (6190H), comes back to 4DE4H to convert the value and then jumps to 4E17H.

4DE4H - Convert the Position Value

Entered by JP 4DE4H at BASIC 6629H, after 6190H has evaluated an expression (the Z FLAG set if it is a string) and left the text pointer on the stack. Returns the value as a 24-bit number in Register C (low), Register L and Register H (high), with any fraction dropped. A string, a negative value or a value of 224 or more gives error A6H BAD FILE POSITIONING PARAM.

4DE4
If the Z FLAG is set (BASIC 6190H, called through 6623H, found the expression to be a string), JUMP to 4E06H for error A6H BAD FILE POSITIONING PARAM.
4DE6
LD BC,(4121H) ED 4B 21 41
Load Register Pair BC with the 16-bit value at 4121H, REG 1's low bytes: an integer (C low, B high), or the low (C) and middle (B) mantissa bytes.
4DEA
LD DE,(4123H) ED 5B 23 41
Load Register Pair DE with the 16-bit value at 4123H: E = the high mantissa byte (bit 7 the sign), D = the exponent (4124H).
4DEE
LD A,D 7A
Load Register A with Register D, the exponent byte of REG 1 read from 4124H at 4DEAH (an integer's type flags were set by the type test before 4DE4H; for a number the exponent decides how many bits to shift).
4DEF
LD L,B 68
Load Register L with Register B, the byte read from 4122H: the middle mantissa byte, or the high byte of an integer.
4DF0
LD H,00H 26 00
Load Register H with 00H, the high byte of the 24-bit position: an integer has only 16 bits (Register L = its high byte from Register B, Register C = its low byte).
4DF2
If the SIGN FLAG is set (from the type test: an integer), JUMP to 4E12H with the value in Register C and Register Pair HL.
4DF5
OR A B7
OR Register A (the exponent) with itself to set the flags: the Z FLAG is set for an exponent of 0, the value 0.
4DF6
If the NZ FLAG is set (Register A, the exponent read from 4124H, is not 00H, so the value is not zero), JUMP to 4DFCH to convert the mantissa.
4DF8
LD C,A 4F
The value is 0 (exponent 00H): load Register C, the low byte of the position, with Register A (00H).
4DF9
LD L,A 6F
Load Register L with Register A (00H), the middle byte of the position; Register H is already 00H from 4DF0H.
4DFA
RET C9
RETURN to BASIC 661FH (after the CALL 6623H at 661CH) or to 4E63H (after the CALL 6623H at 4E60H) with the position 0 in Register C (00H) and Register Pair HL (0000H).
4DFB
NOP 00
A 00H byte after the RET at 4DFAH; no instruction in SYS10/SYS jumps here, so it is never executed as the NOP it decodes to.
4DFC
LD H,E 63
Load Register H with Register E, the high mantissa byte read from 4123H (bit 7 the sign, set back to the implied 1 at 4DFEH); Register L already holds the middle byte and Register C the low byte.
4DFD
LD B,E 43
Load Register B with Register E, the high mantissa byte from 4123H, as well: its bit 7 is the sign, tested at 4E12H.
4DFE
SET 7,H CB FC
Set bit 7 of Register H to put back the mantissa's implied top bit (the sign bit's place).
4E00
SUB 98H D6 98
Subtract 98H from Register A (the exponent): 98H means the 24-bit mantissa in Register H / L / C is already an integer.
4E02
If the Z FLAG is set (Register A, the exponent minus 98H, is 0: the 24-bit mantissa in Register H / L / C is already the whole number), JUMP to 4E12H to test the sign.
4E04
If the CARRY FLAG is set (exponent below 98H), JUMP to 4E09H to shift the fraction out.
4E06
JUMP to BASIC 5DDCH for error A6H BAD FILE POSITIONING PARAM (here: the value is 224 or more).

SHIFT OUT THE FRACTION
Register H / L / C = the mantissa, Register A counts up from (exponent - 98H) to 0.

4E09
SRL H CB 3C
Shift Register H (the high byte of the mantissa) right, a 0 into bit 7 and bit 0 into the CARRY FLAG.
4E0B
RR L CB 1D
Rotate Register L (the middle byte of the mantissa) right through the CARRY FLAG: bit 0 of Register H comes in at bit 7.
4E0D
RR C CB 19
Rotate Register C (the low byte) right through the CARRY FLAG; the bit shifted out is dropped.
4E0F
INC A 3C
Increment Register A, the shift count (the exponent minus 98H, below 0), towards 0, the exponent at which the mantissa is a whole number.
4E10
If the NZ FLAG is set (Register A, the shift count counting up from the exponent minus 98H, is not yet 0), LOOP back to 4E09H for another shift of Register H / L / C.
4E12
BIT 7,B CB 78
Test bit 7 of Register B, the sign: the high byte of the integer (from 4122H), or the high mantissa byte (from 4123H) for a number.
4E14
If the NZ FLAG is set (bit 7 of Register B is set: the value is negative), JUMP to 4E06H for error A6H BAD FILE POSITIONING PARAM.
4E16
RET C9
RETURN with the value in Register C (low), Register L (middle) and Register H (high): to BASIC 661FH for a ! position (after the CALL 6623H at 661CH), or to 4E63H for a record number (after the CALL 6623H at 4E60H).

4E17H - Apply the ! Position

Entered by JP 4E17H at BASIC 6620H with the position in Register C, Register L and Register H (Register Pair HL also pushed). The stack holds, from the top, Register Pair HL, the text pointer and the kind pushed at 4DE0H (0 = !, 1 = !$, 2 = !#). 4E37H comes here too with the end of file as the position.

4E17
PUSH BC C5
Save Register Pair BC on the stack: Register C = the low byte of the position (from 4DE4H or, at 4E3DH, of the end of file).
4E18
BIT 2,(IX+00H) DD CB 00 56
Test bit 2 of the byte at Index Register IX+00H (5700H, the mode byte): set for fixed-length records.
4E1C
If the Z FLAG is set (bit 2 of 5700H, the mode byte, is clear: the file has no fixed-length records), JUMP to 4E25H; any byte position is allowed.
4E1E
GOSUB to BASIC 5EE1H, which divides the position in Register C / L / H by the record length (5702H): the NZ FLAG is set if there is a remainder.
4E21
NOP 00
No operation: a spare byte between the CALL 5EE1H at 4E1EH and the JR NZ at 4E23H; the flags from BASIC 5EE1H pass through unchanged.
4E22
NOP 00
No operation: a second spare byte; the flags from BASIC 5EE1H pass through unchanged.
4E23
If the NZ FLAG is set (the position is not at a record boundary), JUMP to 4E06H for error A6H BAD FILE POSITIONING PARAM.
4E25
POP BC C1
Restore Register Pair BC from the stack: Register C = the low byte of the position, pushed at 4E17H.
4E26
POP HL E1
Restore Register Pair HL from the stack: the position's middle and high bytes, pushed by BASIC 6620H.
4E27
POP DE D1
Restore Register Pair DE from the stack: the BASIC text pointer after the position expression, pushed by BASIC 6190H (from 661CH) or at 4E39H.
4E28
POP AF F1
Restore Register Pair AF from the stack: the kind, pushed as Register Pair BC at 4DE0H, so Register A = the old Register B.
4E29
PUSH DE D5
Save Register Pair DE (the BASIC text pointer after the position expression) on the stack again: 51BDH (through 4E34H) or the GET and PUT code from 4D36H takes it back when the statement ends.
4E2A
LD B,A 47
Load Register B with Register A, the kind of ! position (00H !, 01H !$, 02H !#) restored at 4E28H.
4E2B
Decrement Register B, the kind; if the NZ FLAG is set (the kind was not 01H, !$), JUMP to 4E40H to test the other kinds.
4E2D
!$: GOSUB to BASIC 61A6H, which positions the file to Register C (low), Register L (middle) and Register H (high) through SYS0/SYS 444EH.
4E30
RES 6,(IX+01H) DD CB 01 B6
Clear bit 6 of the byte at Index Register IX+01H (5701H): there is no record start now.
4E34
JUMP to 51BDH to end the statement; the BASIC text pointer pushed at 4E29H is on the stack.
4E37
INC HL 23
!% or !$%: increment Register Pair HL, the BASIC text pointer, past the %.
4E38
PUSH BC C5
Save Register Pair BC on the stack: Register B = the kind of ! position (00H for !%, 01H for !$%), popped into Register A at 4E28H.
4E39
PUSH HL E5
Save Register Pair HL (the BASIC text pointer after the %) on the stack, popped into Register Pair DE at 4E27H.
4E3A
GOSUB to BASIC 61B3H, which returns Register A and Register Pair HL = the end of file (5715H, 5719H-571AH).
4E3D
LD C,A 4F
Load Register C with Register A, the low byte of the end of file returned by BASIC 61B3H (FCB+8 at 5715H); Register Pair HL holds its middle and high bytes (5719H-571AH).
4E3E
JUMP to 4E27H with the end of file as the position in Register C (low) and Register Pair HL (middle and high).
4E40
Decrement Register B (the kind minus 1); if the NZ FLAG is set (the kind was 0, plain !), JUMP to 4E97H: GET or PUT at that position.
4E42
LD A,C 79
!#: load Register A with Register C, the low byte of the new end of file (the position converted at 4DE4H), for BASIC 60EBH.
4E43
GOSUB to BASIC 60EBH, which stores Register A and Register Pair HL as the new end of file (FCB+8, FCB+12/13).
4E46
JUMP to 4E34H to end the statement; the BASIC text pointer pushed at 4E29H is on the stack.

4E48H - Type MU: Skip to the Next Record

Reached from 4D30H for a type MU file (records of marked items, each starting with a 70H byte) when a record start is known and no position was given. Register C and Register Pair HL hold the position where the last statement ended. A PUT carries on from there; a GET skips the rest of the current record, up to the next 70H byte.

4E48
BIT 4,E CB 63
Test bit 4 of Register E, the mode byte from 5700H with bit 4 set at 4D11H for a PUT: the Z FLAG is set for a GET.
4E4A
If the NZ FLAG is set (bit 4 of Register E, the mode byte, is set: a PUT), JUMP to 4E97H and continue at Register C / L / H, the end of the last GET or PUT.
4E4C
GOSUB to BASIC 614CH to check the mode byte in Register E (from 5700H): the file must be random and readable for a GET, else error 6CH BAD FILE MODE.
4E4F
GOSUB to BASIC 61A6H, which positions the file to Register C (low), Register L (middle) and Register H (high), the end of the last GET or PUT.

FIND THE NEXT RECORD
Register C and Register Pair HL = the position of the marker about to be read.

4E52
GOSUB to BASIC 61ACH, which returns Register C and Register Pair HL = the file's current position.
4E55
GOSUB to BASIC 6258H, which reads one item marker and skips the item (see 4EA3H for the markers): the Z FLAG is set when the marker was 70H.
4E58
If the NZ FLAG is set (not 70H), LOOP back to 4E52H until the 70H byte of the next record is found.
4E5A
GOSUB to BASIC 6117H, which stores Register C and Register Pair HL (the position of that 70H byte) as the record start.
4E5D
JUMP to 4EA9H, where BASIC 61ACH returns Register C and Register Pair HL = NEXT, the position after the 70H byte just read.

4E5FH - A Record Number

The position parameter is an expression: a record number, 1 or more. The byte position is (number - 1) times the record length. Only files with fixed-length records (mode bit 2) accept it.

4E5F
DEC HL 2B
Decrement Register Pair HL, the text pointer, back to the first character of the expression.
4E60
GOSUB to BASIC 6623H, which evaluates it and converts it through 4DE4H into Register C, Register L and Register H; the text pointer is left on the stack.
4E63
LD A,H 7C
Load Register A with Register H, the high byte of the record number converted at 4DE4H, for the zero test at BASIC 662CH.
4E64
GOSUB to BASIC 662CH: error 7EH BAD RECORD # if the number in Register C / L / H is 0; returns Register A = the low byte (Register C) and the Z FLAG set if it is 0.
4E67
If the NZ FLAG is set (Register A, the low byte from Register C, is not 00H), JUMP to 4E6AH: decrementing Register C needs no borrow.
4E69
DEC HL 2B
Decrement Register Pair HL (the middle and high bytes of the record number): the borrow for the decrement of Register C from 00H.
4E6A
DEC C 0D
Decrement Register C, the low byte of the record number: Register C / L / H = the record number minus 1.
4E6B
BIT 2,(IX+00H) DD CB 00 56
Test bit 2 of the byte at Index Register IX+00H (5700H, the mode byte): fixed-length records.
4E6F
If the Z FLAG is set (no fixed-length records), JUMP to BASIC 5DA9H for error 6CH BAD FILE MODE.
4E72
EX DE,HL EB
Exchange Register Pairs DE and HL: D = the high byte and E = the middle byte of the number.
4E73
LD A,C 79
Load Register A with Register C, the low byte of the record number minus 1; 4E7BH moves it into the alternate Register A' as the low byte of the multiplier.
4E74
LD BC,(5702H) ED 4B 02 57
Load Register Pair BC with the 16-bit value at 5702H, the record length of the file (1-256), the multiplicand of the loop.
4E78
LD HL,0000H 21 00 00
Load Register Pair HL with 0000H, the high 16 bits of the 40-bit product (Register Pair HL, Register D, Register E, Register A) that the loop builds.
4E7B
EX AF,AF' 08
Exchange Register Pair AF with the alternate AF': the number's low byte goes to Register A'.
4E7C
LD A,19H 3E 19
Load Register A with 19H, a count of 25 shift steps: 24 for the bits of the record number in Register D / E / A' and one more to shift the last addition into place.
4E7E
EX AF,AF' 08
Exchange Register Pair AF with the alternate AF': Register A = the low byte of the 40-bit shift register (the record number's low byte, from Register C at 4E73H, on the first pass), and the shift count goes to Register A'.

MULTIPLY LOOP
Register Pair HL, Register D, Register E and Register A shift right together as one 40-bit value; each 1 bit shifted out of Register A adds Register Pair BC, the record length from 5702H, to Register Pair HL.

4E7F
SRL H CB 3C
Shift Register H (the top byte of the product) right, a 0 into bit 7 and bit 0 into the CARRY FLAG, the first step of shifting the 40-bit Register H / L / D / E / A right by one bit.
4E81
RR L CB 1D
Rotate Register L (the second byte of the product) right through the CARRY FLAG: the bit from Register H goes into bit 7, bit 0 into the CARRY FLAG.
4E83
RR D CB 1A
Rotate Register D (the high byte of the record number, and of the product as it shifts down) right through the CARRY FLAG.
4E85
RR E CB 1B
Rotate Register E (the middle byte of the record number, and of the product as it shifts down) right through the CARRY FLAG.
4E87
RRA 1F
Rotate Register A right through the CARRY FLAG: the bit shifted out is in the CARRY FLAG.
4E88
If the NO CARRY FLAG is set (the multiplier bit shifted out of Register A was 0), JUMP to 4E8BH without adding.
4E8A
ADD HL,BC 09
The bit was 1: add Register Pair BC, the record length from 5702H, to Register Pair HL, the high part of the product.
4E8B
EX AF,AF' 08
Exchange Register Pair AF with the alternate AF': Register A = the shift count (from 4E7CH), and the multiplier byte goes back to Register A'.
4E8C
DEC A 3D
Decrement Register A, the shift count of 25 started at 4E7CH; the Z FLAG is set after the last shift.
4E8D
If the NZ FLAG is set (Register A, the shift count of 25 started at 4E7CH, is not yet 0), LOOP back to 4E7EH for the next step.
4E8F
LD A,H 7C
Load Register A with Register H, the top byte of the 40-bit product (bits 32-39), to test whether the product fits in 24 bits.
4E90
OR L B5
OR Register A (Register H, the top byte of the product) with Register L: the NZ FLAG is set if Register Pair HL, bits 24-39 of the product, is not 0.
4E91
If the NZ FLAG is set (the product does not fit in 24 bits), JUMP to BASIC 5DB2H for error 7EH BAD RECORD #.
4E94
EX AF,AF' 08
Exchange Register Pair AF with the alternate AF': Register A = the low byte of the product (bits 0-7 of the record's byte position), and the spent shift count goes to Register A'.
4E95
EX DE,HL EB
Exchange Register Pairs DE and HL: Register Pair HL = the product's middle (Register L) and high (Register H) bytes from Register Pair DE.
4E96
LD C,A 4F
Load Register C with Register A, the low byte of the product (the byte position of the record), so that Register C / L / H holds the position.
4E97
JUMP to 4D36H to check the mode byte in Register E and GET or PUT at the position in Register C (low), Register L (middle) and Register H (high).

4E9AH - Type MU: the Record Marker

For type MU every record starts with a 70H byte. Register C and Register Pair HL hold the position.

4E9A
GOSUB to BASIC 61A6H, which positions the file to Register C (low), Register L (middle) and Register H (high) through SYS0/SYS 444EH.
4E9D
BIT 4,(IX+00H) DD CB 00 66
Test bit 4 of the byte at Index Register IX+00H (5700H, the mode byte; bit 4 set at 4D11H for a PUT): the Z FLAG is set for a GET.
4EA1
If the NZ FLAG is set (bit 4 of 5700H, the mode byte, is set: a PUT), JUMP to 4EAFH to write the 70H marker at the end of file.
4EA3
GOSUB to BASIC 626CH, which reads an item marker. It returns the Z FLAG and NO CARRY for 00H (a filler byte), the Z FLAG and CARRY for 70H (a record start), and the NZ FLAG with Register A = the type (2 integer 72H, 3 string 71H n or 80H + n, 4 single 73H, 8 double 74H) and Register B = the length for the others; any other byte is error 2AH BAD FILE DATA.
4EA6
If the NO CARRY FLAG is set (not the 70H byte), JUMP to BASIC 5D9DH for error 2AH BAD FILE DATA.
4EA9
GOSUB to BASIC 61ACH, which returns Register C and Register Pair HL = the position after the marker.
4EAC
JUMP to 4D4BH to store the position in Register C and Register Pair HL (after the 70H marker) at 570AH-570CH and 5704H-5706H, position the file there and transfer the items.
4EAF
BIT 4,(IX+2DH) DD CB 2D 66
PUT: test bit 4 of the byte at Index Register IX+2DH (572DH): set if the position is at the end of file.
4EB3
If the Z FLAG is set (bit 4 of 572DH is clear: the position is inside the file, the record exists), JUMP to 4EA3H: it must start with a 70H marker.
4EB5
LD A,70H 3E 70
Load Register A with 70H, the marker that starts every record of a type MU file, for BASIC 61DFH to write.
4EB7
LD B,00H 06 00
Load Register B with 00H, the count of data bytes that BASIC 61DFH writes after the byte in Register A: only the marker is written.
4EB9
GOSUB to BASIC 61DFH, which writes the byte in Register A (the 70H marker) and Register B (00H) bytes from Register Pair HL; writing past the end of file needs bit 7 of 5701H.
4EBC
JUMP to 4EA9H, where BASIC 61ACH returns Register C and Register Pair HL = NEXT, the position after the 70H marker just written.

4EBEH - Transfer a Plain Record

The file is positioned. Item files (types with the letter M or F) go to the item list at 4F18H. A plain random file moves one record between the file and its record buffer (the FIELD buffer, see 4F0EH): a whole sector for a record length of 256, or the record in record mode (FCB+1 bit 7, LRL = the length) otherwise.

4EBE
LD A,(5700H) 3A 00 57
Load Register A with the byte at 5700H, the mode byte of the working copy of the file area (Index Register IX = 5700H).
4EC1
AND 03H E6 03
Mask Register A against 03H (0000 0011) to keep bits 0-1, the item file letters M and F.
4EC3
If the NZ FLAG is set (Register A, bits 0-1 of the mode byte from 5700H, is not 0: an item file with the letter M or F), JUMP to 4F18H for the item list.
4EC5
GOSUB to BASIC 6031H, which returns Register C and Register Pair HL = NEXT, with the CARRY FLAG set if NEXT is below the end of file.
4EC8
If the CARRY FLAG is set (BASIC 6031H found NEXT, in Register C / L / H, below the end of file: the record exists), JUMP to 4EF0H to read or write it.
4ECA
BIT 4,(IX+00H) DD CB 00 66
Test bit 4 of the byte at Index Register IX+00H (5700H, the mode byte; bit 4 set at 4D11H for a PUT): the Z FLAG is set for a GET.
4ECE
If the NZ FLAG is set (bit 4 of 5700H, the mode byte, is set: a PUT), JUMP to 4EE9H to check that the file may be extended.
4ED0
LD A,(5702H) 3A 02 57
GET past the end of file: load Register A with the byte at 5702H, the low byte of the record length.
4ED3
ADD A,C 81
Add Register C (the low byte of NEXT, returned by BASIC 6031H) to Register A (the low byte of the record length from 5702H): the low byte of the position after the record.
4ED4
LD C,A 4F
Load Register C with Register A, the new low byte of the position (NEXT's low byte plus the low byte of the record length from 5702H).
4ED5
LD A,(5703H) 3A 03 57
Load Register A with the byte at 5703H, the high byte of the record length (01H for a length of 256, else 00H).
4ED8
ADC A,L 8D
Add Register L (the middle byte of NEXT from BASIC 6031H) and the CARRY FLAG from 4ED3H to Register A (the high byte of the record length).
4ED9
LD L,A 6F
Load Register L with Register A, the middle byte of the position after the missing record (NEXT's middle byte plus the record length's high byte from 5703H, plus the carry).
4EDA
If the NO CARRY FLAG is set (the middle byte did not overflow), JUMP to 4EDDH: nothing to carry into Register H.
4EDC
INC H 24
Increment Register H, the high byte of the position: the carry from the middle byte in Register L.
4EDD
GOSUB to BASIC 61A6H, which positions the file to Register C / L / H, after the missing record.
4EE0
GOSUB to 4F0EH, which returns Register Pair HL = the record buffer and Register A = the low byte of the record length.
4EE3
LD B,A 47
Load Register B with Register A, the low byte of the record length from 5702H returned by 4F0EH: the number of bytes to clear (00H = 256 bytes).
4EE4
GOSUB to BASIC 6362H to clear Register B bytes of the record buffer at Register Pair HL: the record reads as zeros.
4EE7
JUMP to 4F0BH, which jumps on to 51B1H to finish the statement; the BASIC text pointer is on the stack.
4EE9
BIT 7,(IX+01H) DD CB 01 7E
PUT past the end of file: test bit 7 of the byte at Index Register IX+01H (5701H), set by the OPEN modes O, E and R.
4EED
If the Z FLAG is set (the file may not be extended), JUMP to BASIC 5DC1H for error 90H ILLEGAL TO EXTEND FILE.
4EF0
GOSUB to 4F0EH, which returns Register Pair HL = the record buffer and Register A = the low byte of the record length, with the Z FLAG set for 256.
4EF3
If the Z FLAG is set (Register A, the low byte of the record length from 5702H, is 00H: the record length is 256), JUMP to 4F01H to read or write the whole sector.
4EF5
BIT 4,(IX+00H) DD CB 00 66
Test bit 4 of the byte at Index Register IX+00H (5700H, the mode byte; bit 4 set at 4D11H for a PUT): the Z FLAG is set for a GET.
4EF9
If the Z FLAG is set (a GET), GOSUB to BASIC 6214H to read the record into the buffer at Register Pair HL in record mode (SYS0/SYS 4436H).
4EFC
If the NZ FLAG is set (a PUT), GOSUB to BASIC 620FH to write the record from Register Pair HL in record mode (SYS0/SYS 443CH, write with verify).
4EFF
JUMP to 4F0BH, which jumps on to 51B1H to finish the statement; the BASIC text pointer is on the stack.
4F01
BIT 4,(IX+00H) DD CB 00 66
A 256-byte record: test bit 4 of the byte at Index Register IX+00H (5700H, the mode byte), the PUT bit.
4F05
If the Z FLAG is set (a GET), GOSUB to BASIC 6232H to read the sector (SYS0/SYS 4436H).
4F08
If the NZ FLAG is set (a PUT), GOSUB to BASIC 6237H to write the sector (SYS0/SYS 443CH).
4F0B
JUMP to 51B1H to finish the statement; the BASIC text pointer is on the stack (pushed at 4D1FH, 4D5BH or 4E29H).

4F0EH - The Record Buffer

Returns Register Pair HL = the record buffer of the file. The FCB's buffer address (5710H-5711H) is the sector buffer; a file with a record length that is not a multiple of 256 has its record buffer in the 256 bytes before it. Register A = the low byte of the record length, with the Z FLAG set if it is 0.

4F0E
LD HL,(5710H) 2A 10 57
Load Register Pair HL with the 16-bit value at 5710H, the FCB's buffer address (FCB+3/4): the sector buffer.
4F11
LD A,(5702H) 3A 02 57
Load Register A with the byte at 5702H, the low byte of the record length (00H for a record length of 256).
4F14
OR A B7
OR Register A with itself to set the flags: the Z FLAG is set for a record length of 256.
4F15
RET Z C8
If the Z FLAG is set (Register A, the low byte of the record length, is 00H: length 256), RETURN with Register Pair HL = the sector buffer from 5710H.
4F16
DEC H 25
Decrement Register H: Register Pair HL = the record buffer, 256 bytes below the sector buffer.
4F17
RET C9
RETURN with Register Pair HL = the record buffer and Register A = the record length's low byte.

4F18H - The Item List (IGEL)

Item files (types MI, MU, MF, FI, FF from OPEN's fourth parameter) move the values of a list of variables or expressions. The list follows a comma after the position: either the number of the program line that holds it, or a second comma and the list in the statement itself. Items are separated by commas and the list ends with a semicolon; a list may run on over several program lines, and ' comments are skipped. Type F files hold the values as bare bytes (a string takes the length given by a (n) prefix); type M files put a marker before each value (72H integer, 73H single, 74H double, 80H + n or 71H n for a string, 00H filler, 70H end of record). The available room in the record is counted in BASIC's 61CAH; a PUT to types MU, MF, FI and FF first runs the whole list without writing (572DH bit 2) to count it.

4F18
GOSUB to BASIC 6331H, which returns Register Pair HL = the room left in the record (the record length minus the bytes from the record start to here); error 8EH RECORD OVERFLOW if there is none.
4F1B
LD (4F8CH),HL 22 8C 4F
Self-Modifying Code
Store Register Pair HL (the room left in the record, returned by BASIC 6331H) at 4F8CH, the operand of LD DE,nnnn at 4F8BH.
4F1E
POP HL E1
Restore Register Pair HL from the stack: the BASIC text pointer after the position (pushed at 4D1FH or 4D5BH, or at 4E29H for a ! position).
4F1F
GOSUB to BASIC 6368H with Register Pair HL = the text pointer: the Z FLAG is set at the end of the statement, else it takes a comma.
4F22
If the Z FLAG is set (BASIC 6368H found the end of the statement: there is no item list), JUMP to 51B0H to finish with Register Pair HL, the text pointer.
4F25
DEC HL 2B
Decrement Register Pair HL, the BASIC text pointer (at the character after the comma), back one character for RST 10H.
4F26
RST 10H D7
RST 10H: step Register Pair HL to the next character after the comma and load it into Register A; the Z FLAG is set at the end of the statement.
4F27
If the Z FLAG is set (the statement ends there), JUMP to BASIC 5DCDH for error 9AH IGEL SYNTAX ERROR.
4F2A
CP 2CH FE 2C
Compare Register A (the character after the comma, from RST 10H) against 2CH, another comma: the list follows in this statement.
4F2C
If the Z FLAG is set (Register A is 2CH, a comma), JUMP to 4F3DH with Register Pair HL at that comma, ready for RST 10H.
4F2E
SET 1,(IX+2DH) DD CB 2D CE
Otherwise it is a line number: set bit 1 of the byte at Index Register IX+2DH (572DH, the statement flags): the list is in another line.
4F32
GOSUB to ROM 1E5AH (LINGET), which converts the digits at Register Pair HL to the line number in Register Pair DE.
4F35
PUSH HL E5
Save Register Pair HL (the text pointer of the statement, after the line number) on the stack.
4F36
GOSUB to ROM 1EC5H, inside the GOTO routine, to find the line numbered Register Pair DE (error UNDEFINED LINE # if it does not exist); Register Pair HL comes back pointing at that line.
4F39
LD BC,0004H 01 04 00
Load Register Pair BC with 0004H, the size of a program line's link field (2 bytes) and line number (2 bytes).
4F3C
ADD HL,BC 09
Add Register Pair BC (4) to Register Pair HL: skip the link and the line number, ready for RST 10H.
4F3D
LD C,(IX+00H) DD 4E 00
Load Register C with the byte at Index Register IX+00H (5700H, the mode byte, with bit 4 set at 4D11H for a PUT).
4F40
BIT 4,C CB 61
Test bit 4 of Register C, the mode byte read from 5700H at 4F3DH (bit 4 set at 4D11H for a PUT): the Z FLAG is set for a GET.
4F42
If the Z FLAG is set (bit 4 of Register C, the mode byte, is clear: a GET), JUMP to 4F87H: a GET needs no counting run.
4F44
BIT 4,(IX+2DH) DD CB 2D 66
Test bit 4 of the byte at Index Register IX+2DH (572DH): set if the position is at the end of file.
4F48
If the NZ FLAG is set (bit 4 of 572DH is set: the position is at the end of file), JUMP to 4F87H: there is no existing record to fit into.
4F4A
BIT 0,C CB 41
Test bit 0 of Register C, the mode byte from 5700H: set for the item file letter M (marked items), clear for the letter F (fixed-length items).
4F4C
If the Z FLAG is set (bit 0 of Register C, the mode byte, is clear: a type F file), JUMP to 4F7BH to run the counting pass with the room from 4F1BH.
4F4E
BIT 3,C CB 59
Test bit 3 of Register C, the mode byte from 5700H: set for the second letter U or F, clear for I (type MI).
4F50
If the Z FLAG is set (type MI), JUMP to BASIC 5DA9H for error 6CH BAD FILE MODE: type MI is only written at the end of file.
4F53
BIT 2,C CB 51
Test bit 2 of Register C, the mode byte from 5700H: set for the second letter F (fixed-length records), clear for U.
4F55
If the NZ FLAG is set (bit 2 of Register C, the mode byte, is set: type MF), JUMP to 4F7BH to run the counting pass with the room from 4F1BH.
4F57
PUSH HL E5
Type MU: save Register Pair HL (the BASIC text pointer at the item list) on the stack while the existing record is measured.

MEASURE THE EXISTING RECORD
Register C and Register Pair HL = the file's position as each item of the old record is skipped.

4F58
GOSUB to BASIC 6031H, which returns Register C and Register Pair HL = NEXT, with the CARRY FLAG set if it is below the end of file.
4F5B
If the CARRY FLAG is set (BASIC 6031H found NEXT, in Register C / L / H, below the end of file: more of the file follows), JUMP to 4F69H to skip one item.
4F5D
SET 3,(IX+2DH) DD CB 2D DE
The record runs to the end of file: set bit 3 of the byte at Index Register IX+2DH (572DH).
4F61
BIT 7,(IX+01H) DD CB 01 7E
Test bit 7 of the byte at Index Register IX+01H (5701H): set if the file may be extended.
4F65
If the NZ FLAG is set (bit 7 of 5701H is set: the file may be extended), JUMP to 4F7AH: the room from 4F1BH is not limited by the existing record.
4F67
Otherwise (the file may not be extended), JUMP to 4F6EH to take the length of the existing record, up to the end of file, as the room.
4F69
GOSUB to BASIC 6258H to skip one item of the existing record: the Z FLAG is set at the 70H byte of the next record.
4F6C
If the NZ FLAG is set (BASIC 6258H did not find a 70H marker), LOOP back to 4F58H until the end of the existing record.
4F6E
LD H,L 65
Load Register H with Register L, the middle byte of NEXT (the end of the existing record) returned by BASIC 6031H.
4F6F
LD L,C 69
Load Register L with Register C, the low byte. Register Pair HL = the low 16 bits of the position.
4F70
LD DE,(5704H) ED 5B 04 57
Load Register Pair DE with the 16-bit value at 5704H, the low 16 bits of the record's start.
4F74
OR A B7
OR Register A with itself to clear the CARRY FLAG for the SBC HL,DE at 4F75H (Register A is not changed).
4F75
SBC HL,DE ED 52
Subtract Register Pair DE (the start) from Register Pair HL: HL = the length of the existing record.
4F77
LD (4F8CH),HL 22 8C 4F
Self-Modifying Code
Store Register Pair HL (the record's length) at 4F8CH, the operand of 4F8BH: the new record must fit into it.
4F7A
POP HL E1
Restore Register Pair HL from the stack: the BASIC text pointer at the item list, saved at 4F57H.
4F7B
PUSH HL E5
Save Register Pair HL (the BASIC text pointer at the item list) on the stack for after the counting run.
4F7C
SET 2,(IX+2DH) DD CB 2D D6
Set bit 2 of the byte at Index Register IX+2DH (572DH, the statement flags): count only, do not write (BASIC 61C8H tests it).
4F80
GOSUB to 4F8BH to run the item list once with bit 2 of 572DH set; the counting run returns from 51AAH.
4F83
GOSUB to BASIC 61A3H to position the file back to where the last GET or PUT ended (5704H-5706H, the record's start).
4F86
POP HL E1
Restore Register Pair HL from the stack: the BASIC text pointer at the item list, pushed at 4F7BH.
4F87
RES 2,(IX+2DH) DD CB 2D 96
Clear bit 2 of the byte at Index Register IX+2DH (572DH, the statement flags): now the list is transferred.
4F8B
LD DE,0000H 11 00 00
Self-Modifying Code
Load Register Pair DE with the room in the record, the operand 4F8CH (0000H in the file, stored at 4F1BH and 4F77H).
4F8E
LD (61CAH),DE ED 53 CA 61
Self-Modifying Code
Store Register Pair DE (the room) at 61CAH, BASIC's room counter (the operand of LD HL,nnnn at 61C9H).
4F92
LD DE,0001H 11 01 00
Load Register Pair DE with 0001H, the number of the first item of the list; 4F95H stores it at 5D38H for BASIC's error messages.

ITEM LOOP
Register Pair HL = the text pointer, Register Pair DE = the item number (kept at BASIC 5D38H for error messages).

4F95
LD (5D38H),DE ED 53 38 5D
Self-Modifying Code
Store Register Pair DE (the item number) at 5D38H, the operand of LD DE,nnnn at BASIC 5D37H.
4F99
GOSUB to 4FC1H, which returns the next character of the list in Register A with Register Pair HL at it.
4F9C
CP 2CH FE 2C
Compare Register A (the list's next character returned by 4FC1H) against 2CH, a comma: the Z FLAG is set for an empty item (two commas).
4F9E
If the Z FLAG is set (Register A is 2CH: an empty item), JUMP to 4FAAH to skip an item of the file.
4FA0
CP 3BH FE 3B
Compare Register A (the list's character returned by 4FC1H) against 3BH, a semicolon, which ends the list.
4FA2
If the NZ FLAG is set (Register A, the list's character, is not 3BH, a semicolon), JUMP to 4FDFH to take it as the start of an item.
4FA4
DEC DE 1B
Decrement Register Pair DE, the item number stored at 5D38H, so that it is 0000H if the semicolon is the first item.
4FA5
LD A,D 7A
Load Register A with Register D, the high byte of the item number minus 1, to test Register Pair DE for zero.
4FA6
OR E B3
OR Register A with Register E: the Z FLAG is set if the semicolon came first (item number 1).
4FA7
If the Z FLAG is set (Register Pair DE, the item number minus 1, is 0: the list is just ;), JUMP to 51A2H to end it.
4FAA
LD A,(IX+00H) DD 7E 00
Skip one item: load Register A with the byte at Index Register IX+00H (5700H, the mode byte).
4FAD
AND 12H E6 12
Mask Register A (the mode byte from 5700H) against 12H (0001 0010) to keep bit 4 (PUT) and bit 1 (letter F).
4FAF
If the NZ FLAG is set (a PUT, or a type F file), JUMP to BASIC 5DD0H for error 9CH IGEL ITEM SYNTAX ERROR: skipping needs a GET from a type M file.
4FB2
PUSH HL E5
Save Register Pair HL (the BASIC text pointer at the item) on the stack; 518EH takes it back after the skipped item.
4FB3
GOSUB to BASIC 626CH to read the next item marker (see 4EA3H): Register A = the type, Register B = the length.
4FB6
If the CARRY FLAG is set (the 70H byte, the end of the record), JUMP to BASIC 5DBEH for error 8EH RECORD OVERFLOW.
4FB9
If the Z FLAG is set (the marker read by BASIC 626CH was a 00H filler byte), LOOP back to 4FB3H to read the next marker.
4FBB
GOSUB to BASIC 6245H to move NEXT forward by Register B, the item's length returned with the marker by BASIC 626CH.
4FBE
JUMP to 518EH for the next item; the BASIC text pointer pushed at 4FB2H is on the stack.

4FC1H - Next Character of the List

RST 10H with two extensions: at the end of a program line the list continues with the next line, and a ' comment (a colon followed by the REM token 93H) skips the rest of the line. A list that runs off the end of the program is error 9AH IGEL SYNTAX ERROR.

4FC1
RST 10H D7
RST 10H: step Register Pair HL to the next character and load it into Register A; the Z FLAG is set for 00H or a colon.
4FC2
If the NZ FLAG is set (Register A, the character from RST 10H, is not 00H or a colon), JUMP to 4FCDH to test it for a comment.
4FC4
OR A B7
OR Register A (00H or a colon, from RST 10H) with itself: the Z FLAG is set for 00H, the end of the line.
4FC5
If the Z FLAG is set (Register A, the character from RST 10H, is 00H: the end of the program line), JUMP to 4FD4H to continue with the next line.
4FC7
RST 10H D7
A colon: RST 10H steps Register Pair HL to the next character and loads it into Register A.
4FC8
CP 93H FE 93
Compare Register A against 93H, the REM token (a ' comment is stored as a colon and 93H).
4FCA
If the NZ FLAG is set (another statement), JUMP to BASIC 5DCDH for error 9AH IGEL SYNTAX ERROR.
4FCD
CP 93H FE 93
Compare Register A (the character returned by RST 10H) against 93H, the REM token: the Z FLAG is set at a comment.
4FCF
RET NZ C0
If the NZ FLAG is set (Register A is not 93H, the REM token), RETURN with the character in Register A and Register Pair HL at it.

SKIP THE COMMENT
Register Pair HL steps to the line's 00H end.

4FD0
RST 10H D7
RST 10H: step Register Pair HL, the program pointer, to the next character of the comment and load it into Register A.
4FD1
OR A B7
OR Register A (the character from RST 10H) with itself: the Z FLAG is set for 00H, the end of the line.
4FD2
If the NZ FLAG is set (Register A, the character from RST 10H, is not 00H, the end of the line), LOOP back to 4FD0H.
4FD4
INC HL 23
Increment Register Pair HL from the line's 00H end to the next line's link field (its low byte).
4FD5
LD A,(HL) 7E
Load Register A with the byte at Register Pair HL, the low byte of the next line's link field.
4FD6
INC HL 23
Increment Register Pair HL, the program pointer, to the high byte of the next line's link field.
4FD7
OR (HL) B6
OR Register A with the byte at Register Pair HL: the Z FLAG is set for a 0000H link, the end of the program.
4FD8
If the Z FLAG is set (the end of the program), JUMP to BASIC 5DCDH for error 9AH IGEL SYNTAX ERROR.
4FDB
INC HL 23
Increment Register Pair HL, the program pointer, from the link's high byte to the low byte of the next line's number.
4FDC
INC HL 23
Increment Register Pair HL to the high byte of the next line's number, just before the line's text, where RST 10H starts.
4FDD
JUMP to 4FC1H, where RST 10H reads the first character of the next line's text at Register Pair HL + 1.

4FDFH - One Item: the (n) Prefix

Register Pair HL points at the item and Register A holds its first character. An item may start with a length in parentheses, (n) with n = 0 to 255, stored at 5094H (FFH when there is none). A parenthesised expression that is followed by a comma, a semicolon or the end is taken as the item itself.

4FDF
PUSH HL E5
Save Register Pair HL (the BASIC text pointer at the item's first character) on the stack; 4FFEH replaces it with the pointer after a prefix.
4FE0
RES 6,(IX+2DH) DD CB 2D B6
Clear bit 6 of the byte at Index Register IX+2DH (572DH, the statement flags): no length prefix has been found for this item yet.
4FE4
CP 28H FE 28
Compare Register A (the item's first character, returned by 4FC1H) against 28H, an opening parenthesis.
4FE6
If the NZ FLAG is set (Register A, the item's first character, is not 28H, an opening parenthesis), JUMP to 500AH: the item has no length prefix.
4FE8
GOSUB to BASIC 6190H, which evaluates the parenthesised expression at Register Pair HL (the Z FLAG set if it is a string) and leaves the text pointer after it on the stack.
4FEB
POP HL E1
Restore Register Pair HL from the stack: the BASIC text pointer after the parenthesised expression, left there by BASIC 6190H.
4FEC
If the Z FLAG is set (BASIC 6190H found the parenthesised expression to be a string), JUMP to 500AH: a string cannot be a length prefix.
4FEE
DEC HL 2B
Decrement Register Pair HL, the BASIC text pointer, back one character for RST 10H.
4FEF
RST 10H D7
RST 10H: step Register Pair HL to the next character and load it into Register A; the Z FLAG is set at the end of the statement.
4FF0
If the Z FLAG is set (RST 10H found the end of the statement after the parentheses), JUMP to 500AH: the parentheses were the item.
4FF2
CP 2CH FE 2C
Compare Register A (the character after the parentheses, from RST 10H) against 2CH, a comma.
4FF4
If the Z FLAG is set (Register A is 2CH, a comma), JUMP to 500AH: the parentheses were the item.
4FF6
CP 3BH FE 3B
Compare Register A (the character after the parentheses, from RST 10H) against 3BH, a semicolon.
4FF8
If the Z FLAG is set (Register A is 3BH, a semicolon), JUMP to 500AH: the parentheses were the item.
4FFA
SET 6,(IX+2DH) DD CB 2D F6
Something follows: it is a prefix. Set bit 6 of the byte at Index Register IX+2DH (572DH).
4FFE
EX (SP),HL E3
Exchange Register Pair HL with the word at the top of the stack (at the Stack Pointer SP): the text pointer after the prefix replaces the item's start there, and HL = the item's start.
4FFF
GOSUB to ROM 0A7FH (CINT), which converts the value in REG 1 to an integer in Register Pair HL.
5002
LD A,H 7C
Load Register A with Register H, the high byte of the integer that ROM 0A7FH (CINT) returned in Register Pair HL.
5003
OR A B7
OR Register A (Register H, the high byte of the integer from ROM 0A7FH) with itself: the Z FLAG is set if the value is 255 or less.
5004
LD A,L 7D
Load Register A with Register L, the integer's low byte: the length n. LD does not change the flags.
5005
If the Z FLAG is set (Register H, the integer's high byte, is 00H: the prefix n is 0-255), JUMP to 500CH to store n from Register A.
5007
JUMP to BASIC 5DD3H for error 9EH BAD/ILLEGAL/MISSING IGEL ITEM PREFIX: the prefix in Register Pair HL is above 255.
500A
LD A,FFH 3E FF
No prefix: load Register A with FFH, the value that 500CH stores at 5094H to mean that the item has no length prefix.
500C
LD (5094H),A 32 94 50
Self-Modifying Code
Store Register A (the length prefix, FFH = none) at 5094H, the operand of 5093H (BASIC's 6136H and 62DDH read it there too).
500F
BIT 4,(IX+00H) DD CB 00 66
Test bit 4 of the byte at Index Register IX+00H (5700H, the mode byte; bit 4 set at 4D11H for a PUT): the Z FLAG is set for a GET.
5013
If the NZ FLAG is set (bit 4 of 5700H, the mode byte, is set: a PUT), JUMP to 50F6H to write the item.
5016
POP HL E1
GET: restore Register Pair HL from the stack: the text pointer at the item (after any prefix).
5017
GOSUB to BASIC 62D8H. For a type M file it returns the Z FLAG. For a type F file it returns the NZ FLAG with Register C = the length prefix, and either Register A = # or $ (Register Pair DE = the text pointer after it) or Register A = 00H with Register Pair HL = the variable's address (found through PTRGET 260DH), Register Pair DE = the text pointer and Register B = its first byte; a string variable without a prefix is error 9EH.
501A
If the Z FLAG is set (BASIC 62D8H found bit 1 of 5700H, the mode byte, clear: a type M file), JUMP to 506AH.

501CH - GET from a Type F File

Each item is a variable (its bytes are read raw, a string takes exactly n bytes), or (n)# / (n)$ to skip n bytes. With the % position (572DH bit 5) no file is read: each string variable is cut or padded with spaces to its length prefix. Register Pair HL = the variable's address, Register C = the prefix, Register A = 00H or the # / $ character.

501C
PUSH DE D5
Save Register Pair DE (the BASIC text pointer after the item, returned by BASIC 62D8H) on the stack for 518EH.
501D
BIT 5,(IX+2DH) DD CB 2D 6E
Test bit 5 of the byte at Index Register IX+2DH (572DH, the statement flags): set at 4D9BH for the % position.
5021
If the Z FLAG is set (bit 5 of 572DH, the statement flags, is clear: not the % position), JUMP to 5056H for a normal GET.
5023
OR A B7
%: OR Register A (00H for a variable, or # / $, from BASIC 62D8H) with itself: the NZ FLAG is set if the item is # or $.
5024
If the NZ FLAG is set (Register A from BASIC 62D8H is # or $, not 00H for a variable), JUMP to 5053H: the % position ignores them.
5026
RST 20H E7
RST 20H: test the variable's type (VALTYP, 40AFH, set by PTRGET inside BASIC 62D8H); the Z FLAG is set for a string.
5027
If the NZ FLAG is set (the variable's type in VALTYP 40AFH is not a string), JUMP to 5053H: the % position only formats strings.
5029
GOSUB to BASIC 5C9CH, which returns Register A = the string's length and Register Pair DE = its address, from the descriptor at Register Pair HL.
502C
LD B,A 47
Load Register B with Register A, the string's current length returned by BASIC 5C9CH from the descriptor at Register Pair HL.
502D
LD A,C 79
Load Register A with Register C, the length prefix n returned by BASIC 62D8H (from 5094H).
502E
SUB B 90
Subtract Register B (the length) from Register A (the prefix): the number of spaces to add.
502F
If the NO CARRY FLAG is set (the string is not longer than the prefix), JUMP to 5034H.
5031
XOR A AF
Longer: load Register A with 00H (XOR A with itself): no spaces to add, since the string is cut to the prefix.
5032
LD (HL),C 71
Store Register C (the prefix) at Register Pair HL, the descriptor's length byte: the string is cut.
5033
LD B,C 41
Load Register B with Register C, the length prefix n: the cut string keeps n characters.
5034
LD C,A 4F
Load Register C with Register A, the number of spaces to add (the prefix minus the length, or 00H when the string was cut at 5031H).
5035
PUSH HL E5
Save Register Pair HL (the address of the string variable's descriptor) on the stack during the FRETOP compare.
5036
LD HL,(40D6H) 2A D6 40
Load Register Pair HL with the 16-bit value at 40D6H, FRETOP: the bottom of the string space in use.
5039
RST 18H DF
RST 18H: compare Register Pair HL (FRETOP) with Register Pair DE (the string's address). The CARRY FLAG is set if the string lies above FRETOP, in the string space.
503A
POP HL E1
Restore Register Pair HL from the stack: the address of the string variable's descriptor, pushed at 5035H.
503B
If the NO CARRY FLAG is set (the string is not in the string space: a literal in the program), JUMP to 5041H to copy it.
503D
LD A,C 79
Load Register A with Register C, the number of spaces to add, computed at 502EH or set to 00H at 5031H.
503E
OR A B7
OR Register A (the number of spaces to add) with itself: the Z FLAG is set if there are none.
503F
If the Z FLAG is set (Register A, the number of spaces, is 0, and the string is already in the string space), JUMP to 5053H: the string is right as it is.
5041
PUSH BC C5
Save Register Pair BC on the stack: Register B = the characters kept, Register C = the spaces to add.
5042
PUSH DE D5
Save Register Pair DE (the address of the old string's characters, from BASIC 5C9CH) on the stack.
5043
LD A,B 78
Load Register A with Register B, the number of characters kept (the old length, or the prefix when it was cut).
5044
ADD A,C 81
Add Register C (the number of spaces) to Register A (the characters kept): the new length, equal to the prefix n.
5045
GOSUB to BASIC 5CACH, which allocates Register A bytes of string space (GETSPA 28BFH) and sets the descriptor at Register Pair HL; Register Pair DE = the new string's address.
5048
EX DE,HL EB
Exchange Register Pairs DE and HL: Register Pair HL = the address of the new string's characters, returned by BASIC 5CACH in Register Pair DE.
5049
POP DE D1
Restore Register Pair DE from the stack: the address of the old string's characters, pushed at 5042H.
504A
POP BC C1
Restore Register Pair BC from the stack: Register B = the characters kept, Register C = the spaces to add (pushed at 5041H).
504B
LD A,B 78
Load Register A with Register B, the number of characters kept from the old string (restored from the stack at 504AH).
504C
OR A B7
OR Register A (the characters kept) with itself: the Z FLAG is set if no character is kept.
504D
If the NZ FLAG is set, GOSUB to ROM 09D6H (VMOVEA), which copies Register A bytes from Register Pair DE (the old characters) to Register Pair HL (the new string).
5050
GOSUB to BASIC 5CBCH to store Register C spaces at Register Pair HL, after the characters copied by ROM 09D6H.
5053
JUMP to 518EH for the next item; the BASIC text pointer pushed at 501CH is on the stack.
5056
OR A B7
Normal GET: OR Register A with itself: the Z FLAG is set for a variable (00H), clear for # or $.
5057
If the Z FLAG is set (Register A from BASIC 62D8H is 00H: the item is a variable), JUMP to 5062H to read into it.
5059
LD A,C 79
(n)# or (n)$: load Register A with Register C, the count n (the length prefix returned by BASIC 62D8H, or by 510EH for a PUT).
505A
GOSUB to BASIC 6246H to move NEXT forward by Register A (n) bytes, skipping them in the file.
505D
GOSUB to BASIC 6346H: error 8EH RECORD OVERFLOW if NEXT, moved forward by n, is now past the end of the record.
5060
JUMP to 5053H, which jumps on to 518EH for the next item; the text pointer is on the stack.
5062
PUSH HL E5
Save Register Pair HL (the variable's address returned by BASIC 62D8H through PTRGET) on the stack.
5063
RST 20H E7
RST 20H: test the variable's type (VALTYP, 40AFH, set by PTRGET inside BASIC 62D8H); the Z FLAG is set for a string.
5064
PUSH AF F5
Save Register Pair AF on the stack: the flags from RST 20H, the Z FLAG for a string, the SIGN FLAG for an integer, the CARRY FLAG for single precision.
5065
If the NZ FLAG is set (the variable's type in VALTYP 40AFH is numeric), JUMP to 50BFH to read its bytes into REG 1.
5067
LD A,C 79
A string variable: load Register A with Register C, the length prefix n from BASIC 62D8H (a type F string takes exactly n bytes).
5068
JUMP to 5098H with Register A = n, the number of bytes to read into the string variable at the address on the stack.

506AH - GET from a Type M File

Register Pair HL = the item. Each item is # (skip an item, needs a prefix), or a variable. The file's marker decides the value's type: a numeric value is stored through the ROM's LET code (so it is converted to the variable's type), a string needs a string variable and is cut to the length prefix if one is given.

506A
LD A,(HL) 7E
Load Register A with the byte at Register Pair HL, the BASIC text pointer: the item's first character.
506B
CP 23H FE 23
Compare Register A (the item's first character, read from Register Pair HL) against 23H, a #: # skips one item of the file.
506D
If the NZ FLAG is set (Register A, the item's first character, is not 23H #), JUMP to 5076H: the item is a variable.
506F
INC HL 23
Increment Register Pair HL, the BASIC text pointer, past the # of the item.
5070
GOSUB to BASIC 62D0H: error 9EH BAD/ILLEGAL/MISSING IGEL ITEM PREFIX unless a prefix was given.
5073
JUMP to 4FAAH to skip an item of the file; the text pointer in Register Pair HL is saved there.
5076
GOSUB to ROM 260DH (PTRGET), which finds the variable named at Register Pair HL: Register Pair DE = its address, HL = the text pointer after the name.
5079
PUSH HL E5
Save Register Pair HL (the BASIC text pointer after the variable's name, from PTRGET) on the stack.
507A
PUSH DE D5
Save Register Pair DE (the variable's address returned by PTRGET at 260DH) on the stack.
507B
RST 20H E7
RST 20H: test the variable's type (VALTYP, 40AFH, set by PTRGET); the Z FLAG is set for a string.
507C
PUSH AF F5
Save Register Pair AF on the stack: the variable's type flags from RST 20H (the Z FLAG for a string).

READ THE MARKER
00H filler bytes are skipped; the 70H byte ends the record.

507D
GOSUB to BASIC 626CH to read the item marker (see 4EA3H): Register A = the type, Register B = the length.
5080
If the CARRY FLAG is set (the 70H byte, the end of the record), JUMP to BASIC 5DBEH for error 8EH RECORD OVERFLOW.
5083
If the Z FLAG is set (the marker read by BASIC 626CH is a 00H filler byte), LOOP back to 507DH to read the next marker.
5085
LD C,B 48
Load Register C with Register B, the item's length in the file as BASIC 626CH returned it with the marker.
5086
LD (40AFH),A 32 AF 40
Store Register A (the item's type) at 40AFH, VALTYP: the item's type becomes the current value type.
5089
RST 20H E7
RST 20H: test the item's type, just stored in VALTYP at 40AFH; the Z FLAG is set for a string item.
508A
If the NZ FLAG is set (the item's type, now in VALTYP 40AFH, is numeric), JUMP to 50BFH to read its bytes into REG 1.
508C
POP AF F1
A string item: restore Register Pair AF from the stack, the variable's type flags pushed at 507CH (the Z FLAG for a string variable).
508D
POP HL E1
Restore Register Pair HL from the stack: the variable's address pushed at 507AH.
508E
PUSH HL E5
Save Register Pair HL (the variable's address) on the stack again, for 50EAH.
508F
PUSH AF F5
Save Register Pair AF (the variable's type flags) on the stack again, for 50E9H.
5090
If the NZ FLAG is set (the variable is not a string), JUMP to ROM 0AF6H, which gives the error TYPE MISMATCH (Register E = 18H).
5093
LD A,00H 3E 00
Self-Modifying Code
Load Register A with the length prefix, the operand 5094H (00H in the file, stored at 500CH; FFH = none).
5095
CP B B8
Compare Register A (the prefix) against Register B (the item's length): the CARRY FLAG is set if the prefix is shorter.
5096
If the NO CARRY FLAG is set (the prefix is not shorter), JUMP to 5099H with Register B = the item's length.
5098
LD B,A 47
Load Register B with Register A: the number of bytes to read is the prefix (5068H also enters here with the type F prefix).
5099
PUSH BC C5
Save Register Pair BC (B = the bytes to read, C = the bytes in the file) on the stack.
509A
GOSUB to BASIC 5C9CH, which returns Register A = the variable's current length and Register Pair DE = its address, from the descriptor at Register Pair HL.
509D
LD B,D 42
Load Register B with Register D, the high byte of the old string's address returned by BASIC 5C9CH.
509E
LD C,E 4B
Load Register C with Register E, the low byte: Register Pair BC = the address of the old string's characters.
509F
LD D,H 54
Load Register D with Register H, the high byte of the address of the variable's descriptor.
50A0
LD E,L 5D
Load Register E with Register L, the low byte: Register Pair DE = the address of the variable's descriptor.
50A1
XOR A AF
Load Register A with 00H (XOR A with itself) for ROM 29E3H; the ZERO FLAG is set.
50A2
CALL 29E3H CD E3 29
GOSUB to ROM 29E3H, inside FREFAC (29DAH-29F4H, which frees a string temporary through FRETMS 29F5H), entered with Register Pair DE = the descriptor's address; it returns Register Pair HL = the descriptor's address.
50A5
PUSH HL E5
Save Register Pair HL (the address of the string variable's descriptor, returned by ROM 29E3H) on the stack.
50A6
LD HL,(40D6H) 2A D6 40
Load Register Pair HL with the 16-bit value at 40D6H, FRETOP: the bottom of the string space in use.
50A9
RST 18H DF
RST 18H: compare Register Pair HL (FRETOP) with Register Pair DE as the ROM routine left it, taken here as the old string's address. The CARRY FLAG is set if it lies above FRETOP, in the string space.
50AA
POP HL E1
Restore Register Pair HL from the stack: the address of the variable's descriptor, pushed at 50A5H.
50AB
If the CARRY FLAG is set (the old string lies above FRETOP from 40D6H, in the string space), JUMP to 50AFH and reuse its space.
50AD
LD (HL),00H 36 00
It is a literal in the program: store 00H at Register Pair HL, the descriptor's length, so new space is taken.
50AF
POP BC C1
Restore Register Pair BC from the stack: B = the bytes to read, C = the bytes in the file.
50B0
LD A,(HL) 7E
Load Register A with the byte at Register Pair HL, the old length from the descriptor.
50B1
CP B B8
Compare Register A (the old length) against Register B (the new length): the CARRY FLAG is set if the new string is longer.
50B2
PUSH BC C5
Save Register Pair BC (Register B = the bytes to read, Register C = the item's bytes in the file) on the stack again.
50B3
LD (HL),B 70
Store Register B (the new length, the bytes to read) at Register Pair HL, the descriptor's length byte.
50B4
LD A,B 78
Load Register A with Register B, the new length, for BASIC 5CACH. LD does not change the flags from the CP at 50B1H.
50B5
If the CARRY FLAG is set (the new string is longer), GOSUB to BASIC 5CACH to allocate Register A bytes of string space for it and set the descriptor at Register Pair HL.
50B8
GOSUB to BASIC 5C9CH, which returns Register Pair DE = the string's address from the descriptor at Register Pair HL.
50BB
EX DE,HL EB
Exchange Register Pairs DE and HL: Register Pair HL = the address of the string's characters, from BASIC 5C9CH, to read into.
50BC
POP BC C1
Restore Register Pair BC from the stack: B = the bytes to read, C = the bytes in the file.
50BD
JUMP to 50DCH to read Register B bytes into the string at Register Pair HL and skip the rest of the item's Register C bytes.
50BF
LD HL,4121H 21 21 41
Numeric: load Register Pair HL with 4121H, REG 1 (the integer or single precision value), where the value is read.
50C2
LD B,02H 06 02
Load Register B with 02H, the byte count of an integer value in REG 1 (4121H-4122H).
50C4
If the SIGN FLAG is set (from the type test RST 20H at 5063H or 5089H: an integer), JUMP to 50D0H with Register B = 02H.
50C7
LD B,04H 06 04
Load Register B with 04H, the byte count of a single precision value in REG 1 (4121H-4124H).
50C9
If the CARRY FLAG is set (from the type test: single precision), JUMP to 50D0H with Register B = 04H.
50CB
LD HL,411DH 21 1D 41
Double precision: load Register Pair HL with 411DH, the low end of the double precision REG 1.
50CE
LD B,08H 06 08
Load Register B with 08H, the byte count of a double precision value (411DH-4124H).
50D0
LD C,B 48
Load Register C with Register B: the item's length in the file is the number of bytes read (2, 4 or 8).
50D1
LD (40DFH),HL 22 DF 40
Store Register Pair HL (where the value is read: 4121H or 411DH) at 40DFH, the ROM's TEMP.
50D4
POP AF F1
Restore Register Pair AF from the stack: the variable's type flags pushed at 5064H or 507CH.
50D5
If the Z FLAG is set (the variable is a string), JUMP to ROM 0AF6H, which gives the error TYPE MISMATCH (Register E = 18H).
50D8
PUSH AF F5
Save Register Pair AF (the variable's type flags) on the stack again, for 50E9H.
50D9
GOSUB to BASIC 62C7H: a numeric item may not have a length prefix (bit 6 of 572DH), else error 9EH.
50DC
LD A,B 78
Load Register A with Register B, the number of bytes to read into the variable or REG 1 at Register Pair HL.
50DD
OR A B7
OR Register A (the number of bytes to read) with itself: the Z FLAG is set if there are none.
50DE
If the NZ FLAG is set, GOSUB to BASIC 6214H to read Register B bytes into Register Pair HL in record mode (SYS0/SYS 4436H with LRL = Register B).
50E1
LD A,C 79
Load Register A with Register C, the item's length in the file (from BASIC 626CH, or the prefix for a type F string).
50E2
SUB B 90
Subtract Register B (the bytes read) from Register A (the item's length in the file): the bytes left over.
50E3
If the NZ FLAG is set (a string was cut), GOSUB to BASIC 6246H to skip the Register A bytes that are left.
50E6
GOSUB to BASIC 6346H: error 8EH RECORD OVERFLOW if NEXT is now past the end of the record.
50E9
POP AF F1
Restore Register Pair AF from the stack: the variable's type flags (the Z FLAG for a string variable).
50EA
POP HL E1
Restore Register Pair HL from the stack: the variable's address (pushed at 5062H or 507AH).
50EB
If the Z FLAG is set (the variable's type flags restored at 50E9H show a string), JUMP to 518EH: the characters are already in it.
50EE
LD DE,518EH 11 8E 51
A number: load Register Pair DE with 518EH, the address the LET code in the ROM returns to after the store.
50F1
PUSH DE D5
Push Register Pair DE (518EH) on the stack as the return address for the LET code in the ROM.
50F2
PUSH DE D5
Push Register Pair DE (518EH) on the stack a second time, so two copies of the way back are stacked.
50F3
JUMP to ROM 1F33H, inside the LET routine (1F21H-1F6BH), to store the value in REG 1 into the variable at Register Pair HL, converting it to the variable's type.

50F6H - PUT an Item

For a type F file an item is a variable, (n)# (write n 00H bytes) or (n)$ (keep the n bytes in the file; at the end of file write n 00H bytes). Numbers go out as their raw bytes, a string as exactly n characters, padded with spaces. For a type M file see 5144H. Every write goes through BASIC 61C8H, which writes Register A and then Register B bytes from Register Pair HL, counting B + 1 against the room in the record (error 8EH RECORD OVERFLOW) and only counting while 572DH bit 2 is set.

50F6
POP HL E1
Restore Register Pair HL from the stack: the text pointer at the item (after any prefix).
50F7
GOSUB to BASIC 62D8H (see 5017H): the Z FLAG for a type M file; for a type F file Register C = the prefix, Register A = 00H (Register Pair HL = the variable) or # / $, Register Pair DE = the text pointer after the item.
50FA
If the Z FLAG is set (BASIC 62D8H found bit 1 of 5700H, the mode byte, clear: a type M file), JUMP to 5144H.
50FC
PUSH DE D5
Save Register Pair DE (the BASIC text pointer after the item, returned by BASIC 62D8H) on the stack for 518EH.
50FD
OR A B7
OR Register A (00H for a variable, or # / $, from BASIC 62D8H) with itself: the Z FLAG is set if the item is a variable.
50FE
If the Z FLAG is set (Register A from BASIC 62D8H is 00H: the item is a variable), JUMP to 511EH to write its value.
5100
CP 23H FE 23
Compare Register A (the item's character returned by BASIC 62D8H) against 23H, a #: (n)# writes n 00H bytes.
5102
If the Z FLAG is set (Register A is 23H #), JUMP to 5111H to write Register C (n) bytes of 00H.
5104
LD A,(IX+2DH) DD 7E 2D
$: load Register A with the byte at Index Register IX+2DH (572DH, the statement flags).
5107
BIT 2,A CB 57
Test bit 2 of Register A, the statement flags from 572DH: set during the counting run started at 4F7CH.
5109
If the NZ FLAG is set (counting only), JUMP to 518EH: $ takes no room from the count.
510C
BIT 4,A CB 67
Test bit 4 of Register A, the statement flags from 572DH: set if the position is at the end of file.
510E
If the Z FLAG is set (inside the file), JUMP to 5059H to skip Register C (n) bytes in the file.
5111
INC C 0C
Increment Register C (n) for the loop, which decrements before it tests (5158H also enters here).
5112
JUMP to 5119H to decrement Register C, the count plus 1, first, so that a count n of 0 writes nothing.

WRITE n ZERO BYTES
Register C counts the bytes left plus 1.

5114
XOR A AF
Load Register A with 00H (XOR A with itself), the byte for BASIC 61C8H to write.
5115
LD B,A 47
Load Register B with Register A (00H): BASIC 61C8H writes no data bytes after the byte in Register A.
5116
GOSUB to BASIC 61C8H, which lowers the room at 61CAH by Register B + 1 and writes the 00H byte in Register A (nothing is written during the counting run).
5119
DEC C 0D
Decrement Register C, the count of 00H bytes still to write plus 1 (set at 5111H from n).
511A
If the NZ FLAG is set (Register C, the count, is not yet 0), LOOP back to 5114H until n bytes are written.
511C
JUMP to 518EH for the next item; the BASIC text pointer pushed at 50FCH is on the stack.
511E
RST 20H E7
A variable: RST 20H tests its type (VALTYP, 40AFH, set by PTRGET inside BASIC 62D8H); the Z FLAG is set for a string.
511F
If the NZ FLAG is set (numeric), JUMP to 516CH with Register Pair HL = the variable's address.
5121
LD A,C 79
Load Register A with Register C, the length prefix n returned by BASIC 62D8H (from 5094H).
5122
GOSUB to BASIC 619CH, which returns Register B = the string's length and Register Pair HL = its address.
5125
LD C,B 48
Load Register C with Register B, the string's length returned by BASIC 619CH.
5126
LD B,A 47
Load Register B with Register A, the length prefix n (from Register C at 5121H).
5127
LD A,C 79
Load Register A with Register C, the string's length (copied from Register B at 5125H).
5128
SUB B 90
Subtract Register B (the prefix n) from Register A (the string's length): the string's length minus n.
5129
If the NO CARRY FLAG is set (the string is at least n long), JUMP to 517EH to write n characters from Register Pair HL.
512B
PUSH AF F5
Save Register Pair AF (Register A = the negative difference, minus the spaces to add) on the stack.
512C
LD A,C 79
Load Register A with Register C, the string's length, to test it for 0.
512D
OR A B7
OR Register A (the string's length) with itself: the Z FLAG is set if the string is empty.
512E
If the Z FLAG is set (Register A, the string's length, is 0), JUMP to 5137H to write only spaces.
5130
LD A,(HL) 7E
Load Register A with the byte at Register Pair HL (the string's address from BASIC 619CH): the string's first character.
5131
LD B,C 41
Load Register B with Register C, the string's length, the count of bytes for BASIC 61C8H.
5132
INC HL 23
Increment Register Pair HL, the address of the string's characters, past the first character (Register A holds it).
5133
DEC B 05
Decrement Register B, the string's length: the number of characters after the first one, which BASIC 61C8H writes from Register Pair HL.
5134
GOSUB to BASIC 61C8H to write Register A and then Register B bytes from Register Pair HL: the whole string.
5137
POP HL E1
Restore Register Pair HL from the stack: Register H = the old Register A, minus the number of spaces to add.
5138
LD B,00H 06 00
Load Register B with 00H: BASIC 61C8H writes no data bytes after each space in Register A.

PAD WITH SPACES
Register H counts up from minus the spaces to 0.

513A
LD A,20H 3E 20
Load Register A with 20H, a space, the byte for BASIC 61C8H to write.
513C
GOSUB to BASIC 61C8H to write the space in Register A (Register B = 00H, no data bytes; the room at 61CAH is lowered by 1).
513F
INC H 24
Increment Register H, minus the number of spaces still to write (from 5137H), towards 0.
5140
If the NZ FLAG is set (Register H, minus the spaces still to write, is not yet 0), LOOP back to 513AH until the field is full.
5142
JUMP to 518EH for the next item; the BASIC text pointer pushed at 50FCH is on the stack.

5144H - PUT to a Type M File

Register Pair HL = the item. Each item is an expression (evaluated through BASIC 6190H), or (n)# for a string item of n 00H bytes. A number is written as its marker (72H, 73H or 74H) and its bytes; a string as 80H + length (or 71H and the length for 128 or more) and its characters, cut to the prefix n if one is given.

5144
LD A,(HL) 7E
Load Register A with the byte at Register Pair HL, the BASIC text pointer: the item's first character.
5145
CP 23H FE 23
Compare Register A (the item's first character, read from Register Pair HL) against 23H, a #: (n)# writes a string item of n 00H bytes.
5147
If the NZ FLAG is set (Register A, the item's first character, is not 23H #), JUMP to 515AH to evaluate the item as an expression.
5149
GOSUB to BASIC 62CEH, which steps past the # (error 9EH unless a prefix was given) and returns Register Pair DE = the text pointer after it.
514C
PUSH DE D5
Save Register Pair DE (the BASIC text pointer after the #, returned by BASIC 62CEH) on the stack.
514D
LD B,FFH 06 FF
Load Register B with FFH, the longest string length, so that BASIC 6136H cuts it to the prefix n at 5094H.
514F
GOSUB to BASIC 6136H, which returns Register B = the prefix n and the string marker for that length: 80H + n in Register A, or 71H written and n in Register A.
5152
LD C,B 48
Load Register C with Register B, the count n returned by BASIC 6136H: the number of 00H bytes to write after the marker.
5153
LD B,00H 06 00
Load Register B with 00H: BASIC 61C8H writes no data bytes after the marker in Register A.
5155
GOSUB to BASIC 61C8H to write the string marker in Register A (80H + n, or n after a 71H that 6136H has written).
5158
JUMP to 5111H to write Register C (n, from BASIC 6136H) bytes of 00H as the string's characters.
515A
GOSUB to BASIC 6190H, which evaluates the expression at Register Pair HL and leaves the text pointer on the stack: the NZ FLAG for a number; for a string the Z FLAG, Register B = its length and Register Pair HL = its address.
515D
If the NZ FLAG is set (BASIC 6190H found the expression to be a number, in REG 1), JUMP to 5164H.
515F
A string: GOSUB to BASIC 6136H for the length in Register B (the prefix, if shorter) and the marker in Register A.
5162
JUMP to 518BH to write the marker in Register A and Register B characters from Register Pair HL, the string's address.
5164
LD HL,4121H 21 21 41
Load Register Pair HL with 4121H, REG 1, where the integer or single precision value evaluated by BASIC 6190H is.
5167
If the CARRY FLAG is set (from BASIC 6190H's type test: an integer or single precision value), JUMP to 516CH with Register Pair HL = 4121H.
5169
LD HL,411DH 21 1D 41
Double precision: load Register Pair HL with 411DH, the low end of the double precision REG 1.
516C
LD A,72H 3E 72
Load Register A with 72H, the integer marker (511FH also enters here for a numeric type F variable, Register Pair HL = its address).
516E
LD B,02H 06 02
Load Register B with 02H, the byte count of an integer, written from Register Pair HL.
5170
If the SIGN FLAG is set (from the type test: an integer), JUMP to 517BH with Register A = 72H and Register B = 02H.
5173
INC A 3C
Increment Register A to 73H, the single precision marker (INC does not change the CARRY FLAG).
5174
LD B,04H 06 04
Load Register B with 04H, the byte count of a single precision value (4121H-4124H).
5176
If the CARRY FLAG is set (from the type test: single precision), JUMP to 517BH with Register A = 73H and Register B = 04H.
5178
INC A 3C
Increment Register A to 74H, the double precision marker (INC does not change the CARRY FLAG).
5179
LD B,08H 06 08
Load Register B with 08H, the byte count of a double precision value (411DH-4124H).
517B
GOSUB to BASIC 62C7H: a numeric item may not have a length prefix (bit 6 of 572DH), else error 9EH.
517E
BIT 1,(IX+00H) DD CB 00 4E
Test bit 1 of the byte at Index Register IX+00H (5700H, the mode byte): letter F (5129H also enters here for a string).
5182
If the Z FLAG is set (a type M file), JUMP to 518BH to write the marker in Register A and the bytes.
5184
LD A,B 78
Type F: load Register A with Register B, the number of bytes of the value (2, 4 or 8, or the string's length).
5185
OR A B7
OR Register A (the number of bytes) with itself: the Z FLAG is set if there are none (an empty string).
5186
If the Z FLAG is set (Register A, the number of bytes, is 0), JUMP to 518EH: nothing to write.
5188
LD A,(HL) 7E
Load Register A with the byte at Register Pair HL, the first byte, written in the marker's place.
5189
DEC B 05
Decrement Register B, the number of bytes: the first byte goes in Register A, so one fewer follows from Register Pair HL.
518A
INC HL 23
Increment Register Pair HL, the address of the value or of the string's characters, past the first byte.
518B
GOSUB to BASIC 61C8H to write Register A and then Register B bytes from Register Pair HL.

518EH - After an Item

The text pointer is on the stack. A comma takes the next item; a semicolon ends the list, and nothing may follow it.

518E
POP HL E1
Restore Register Pair HL from the stack: the BASIC text pointer after the item.
518F
DEC HL 2B
Decrement Register Pair HL, the BASIC text pointer, back one character for RST 10H in 4FC1H.
5190
GOSUB to 4FC1H, which returns the next character of the list in Register A with Register Pair HL at it.
5193
LD DE,(5D38H) ED 5B 38 5D
Load Register Pair DE with the 16-bit value at 5D38H, the item number (the operand of LD DE,nnnn at BASIC 5D37H).
5197
INC DE 13
Increment Register Pair DE, the item number read from 5D38H, for the next item.
5198
CP 2CH FE 2C
Compare Register A (the list's character returned by 4FC1H) against 2CH, a comma: another item follows.
519A
If the Z FLAG is set (a comma), JUMP to 4F95H to store Register Pair DE and take the next item.
519D
CP 3BH FE 3B
Compare Register A (the list's character returned by 4FC1H) against 3BH, a semicolon, which ends the list.
519F
If the NZ FLAG is set (Register A is neither a comma nor a semicolon), JUMP to 51CBH for error 9CH IGEL ITEM SYNTAX ERROR.
51A2
GOSUB to 51C9H with Register Pair HL at the semicolon: the statement must end after it (else error 9CH).
51A5
LD A,(IX+2DH) DD 7E 2D
Load Register A with the byte at Index Register IX+2DH (572DH, the statement flags: bit 1 list in another line, bit 2 counting run).
51A8
BIT 2,A CB 57
Test bit 2 of Register A, the statement flags from 572DH: set during the counting run started at 4F7CH.
51AA
RET NZ C0
If the NZ FLAG is set (the counting run), RETURN to 4F83H, after the CALL 4F8BH at 4F80H.
51AB
BIT 1,A CB 4F
Test bit 1 of Register A, the statement flags from 572DH: set at 4F2EH when the list was in another program line.
51AD
If the Z FLAG is set (bit 1 of Register A, from 572DH, is clear: the list was in the statement), JUMP to 51B0H.
51AF
POP HL E1
Restore Register Pair HL from the stack: the statement's own text pointer saved at 4F35H, in place of the pointer into the list's line.

51B0H - End the Statement

Register Pair HL = the text pointer. Store where the statement ended as the new position of the last GET or PUT, pad a written item record where needed, copy the work area back to the file area and return to BASIC.

51B0
PUSH HL E5
Save Register Pair HL (the BASIC text pointer of the statement) on the stack for 51BDH.
51B1
BIT 5,(IX+2DH) DD CB 2D 6E
Test bit 5 of the byte at Index Register IX+2DH (572DH): set for the % position (4F0BH enters here).
51B5
If the NZ FLAG is set (bit 5 of 572DH, the statement flags, is set: the % position), JUMP to 51C3H; the file was not used.
51B7
GOSUB to BASIC 610DH, which stores NEXT (Register C and Register Pair HL) at 5704H-5706H, where the last GET or PUT ended.
51BA
GOSUB to BASIC 62FFH: after a PUT to an item file, fill the rest of the record with 00H bytes where the type needs it.
51BD
POP HL E1
Restore Register Pair HL from the stack: the BASIC text pointer of the statement (4E34H enters here).
51BE
DEC HL 2B
Decrement Register Pair HL, the text pointer, back one character for RST 10H (4DB0H enters here).
51BF
RST 10H D7
RST 10H: step Register Pair HL to the current character and load it into Register A, with the Z FLAG set at the end of the statement (4DB9H enters here).
51C0
JUMP to BASIC 641EH, which finishes the file statement (copies 5700H-572CH back to the file area, clears 6225H's reload flag and 4289H bit 6) and returns to BASIC.
51C3
%: GOSUB to BASIC 635AH to clear 5700H-572DH and release the file area without writing it back.
51C6
POP HL E1
Restore Register Pair HL from the stack: the BASIC text pointer of the statement, pushed at 51B0H.
51C7
RET C9
RETURN to BASIC with Register Pair HL = the text pointer (the end-of-statement code at 641EH is not run).
51C8
DEC HL 2B
Unreferenced: decrement Register Pair HL, the text pointer (nothing jumps to 51C8H; 51A2H calls 51C9H).
51C9
RST 10H D7
RST 10H: step Register Pair HL to the next character and load it into Register A; the Z FLAG is set at the end of the statement.
51CA
RET Z C8
If the Z FLAG is set (the character from RST 10H is 00H or a colon: the statement ends here), RETURN to 51A5H.
51CB
JUMP to BASIC 5DD0H for error 9CH IGEL ITEM SYNTAX ERROR: something other than the end of the statement follows the item list.

51CEH - Unused Bytes

The rest of the file.

51CE-51E7
DEFB 00H x 26 00 x 26
26 bytes of 00H to the end of the file (51E7H). Nothing in SYS10/SYS reads or writes them.
51E8-51FF
DEFS 24
Not in the file: the rest of the overlay area. SYS10/SYS neither reads nor writes these bytes.