General:
SYS12/SYS handles the CMD “C” (Compress) and NAME (Renumber) functions.
Disassembly:
4E00
4E07H – “RENUMBER” Function.
This routine can take up to 3 parameters: RESEQ (NN(,MM(,INC)))
- NN = Starting line number to use in renumbering
- MM = Starting line to renumber (lines below do not get renumbered)
- INC = Increment (default = 10).
4E07
[1B61H]
NOTE:
- The RST 10H routine loads the next character from the string pointed to by the HL register into the A-register and clears the CARRY FLAG if it is alphabetic, or sets it if is alphanumeric.
- Blanks and control codes 09H and 0BH are ignored causing the following character to be loaded and tested.
- The HL register will be incremented before loading any character therfore on the first call the HL register should contain the string address minus one.
- The string must be terminated by a byte of zeros.
[4E3EH]
[1E4FH]
4E21
LD C,E
[4E3EH]
2C
It is a COMPARE SYMBOL routine which comparess the symbol in the input string pointed to by HL register to the value in the location following the RST 08 call.
If there is a match, control is returned to address of the RST 08 instruction 2 with the next symbol in the A register and HL incremented by one. If the two characters do not match, a syntax error message is given.
The prior instruction found a “,” meaning that we have a parameter to interpret. So the next instruction converts the parameter from ASCII to Decimal.
[1E4FH]
2C
It is a COMPARE SYMBOL routine which comparess the symbol in the input string pointed to by HL register to the value in the location following the RST 08 call.
If there is a match, control is returned to address of the RST 08 instruction 2 with the next symbol in the A register and HL incremented by one. If the two characters do not match, a syntax error message is given.
Next, we process a new “INC” value.
[1E5AH]
Stack = MM, Level II Jump Point. BC = New NN, DE = INC, HL = Pointer on the command line calling for the RENUM.
[1997H]
We now need to check to see if the new INC is a 0, which would be illegal.
4E37
OR E
[1E4AH]
Stack = MM, Level II Jump Point. BC = New NN, HL= INC, DE = Pointer on the command line calling for the RENUM.
Stack = INC, Level II Jump Point. BC = New NN, HL= MM, DE = Pointer on the command line calling for the RENUM.
Stack = INC, Level II Jump Point. BC = New NN, DE= MM, HL = Pointer on the command line calling for the RENUM.
4E3EH – Still in the Renumber Function, finished parsing the command line.
4E3E
Stack = NN, INC, Level II Jump Point. BC = New NN, DE= MM, HL = Pointer on the command line calling for the RENUM.
[1B2CH]
Stack = NN, INC, Level II Jump Point. BC = RAM location where line MM is to be found, DE= MM, HL = Pointer on the command line calling for the RENUM.
Stack = INC, Level II Jump Point. BC = RAM location where line MM is to be found, DE= NN, HL = Pointer on the command line calling for the RENUM. Why is MM gone? Since MM is the lowest line to work from, and BC now has that location, we no longer need to keep track of MM.
Stack = NN, INC, Level II Jump Point. BC = RAM location where line MM is to be found, DE= NN, HL = Pointer on the command line calling for the RENUM.
Stack = RAM location where line MM is to be found, NN, INC, Level II Jump Point. BC = RAM location where line MM is to be found, DE= NN, HL = Pointer on the command line calling for the RENUM.
[1B2CH]
Stack = RAM location where line MM is to be found, NN, INC, Level II Jump Point. BC = RAM location where line NN is to be found, DE= NN, HL = Pointer on the command line calling for the RENUM.
4E4D
LD L,C
Stack = RAM location where line MM is to be found, NN, INC, Level II Jump Point. BC = RAM location where line NN is to be found, DE= NN, HL = RAM location where line NN is to be found. What happened to HL? We don’t need to parse the RENUM command line anymore, and that’s what HL was pointing to.
Stack = NN, INC, Level II Jump Point. BC = RAM location where line NN is to be found, DE= RAM location where line MM is to be found, HL = RAM location where line NN is to be found. What happened to HL? We don’t need to parse the RENUM command line anymore, and that’s what HL was pointing to.
Stack = NN, INC, Level II Jump Point. BC = RAM location where line NN is to be found, HL= RAM location where line MM is to be found, DE = RAM location where line NN is to be found.
[1E4AH]
Stack = INC, Level II Jump Point. BC = RAM location where line NN is to be found, HL= RAM location where line MM is to be found, DE = NN.
Stack = Level II Jump Point. BC = INC, HL= RAM location where line MM is to be found, DE = NN.
Stack = EMPTY. BC = INC, HL= RAM location where line MM is to be found, DE = NN, AF = Level II Jump Point.
Stack = NN. BC = INC, HL= RAM location where line MM is to be found, DE = NN, AF = Level II Jump Point.
4E5AH – Bump the line number by the INC. This routine is not in order. It is jumped to by 4E77, but ultimately would flow down the 4E68H so this was a RAM saver.
[1E4AH]
[1E4AH]
4E68H – Continuation of RENUM from 4E58H (with BC = INC, HL= RAM location where line MM is to be found, DE = NN) -or- pass through from 4E5AH (from 4E77H) with HL holding the LINK FIELD and DE holding the current LINE NUMBER ACCUMULATOR.
4E68
[4E79H]
[4E5AH]
[1B2CH]
4E88
LD L,C
[4EA0H]
4EA0H – Convert all line numbers to pointers and back again; excluding “ON ERROR GOTO 0” which is left untouched.
4EA4
4EA6
4EAA
NOTE:
- The RST 10H routine loads the next character from the string pointed to by the HL register into the A-register and clears the CARRY FLAG if it is alphabetic, or sets it if is alphanumeric.
- Blanks and control codes 09H and 0BH are ignored causing the following character to be loaded and tested.
- The HL register will be incremented before loading any character therfore on the first call the HL register should contain the string address minus one.
- The string must be terminated by a byte of zeros.
[4EAEH]
4EBB
[4F2AH]
This routine will convert LINE NUMBERS into POINTERS.
[4EEAH]
NOTE:
- The RST 10H routine loads the next character from the string pointed to by the HL register into the A-register and clears the CARRY FLAG if it is alphabetic, or sets it if is alphanumeric.
- Blanks and control codes 09H and 0BH are ignored causing the following character to be loaded and tested.
- The HL register will be incremented before loading any character therfore on the first call the HL register should contain the string address minus one.
- The string must be terminated by a byte of zeros.
[4EB8H]
NOTE:
- The RST 10H routine loads the next character from the string pointed to by the HL register into the A-register and clears the CARRY FLAG if it is alphabetic, or sets it if is alphanumeric.
- Blanks and control codes 09H and 0BH are ignored causing the following character to be loaded and tested.
- The HL register will be incremented before loading any character therfore on the first call the HL register should contain the string address minus one.
- The string must be terminated by a byte of zeros.
If we are here then we have found “ERROR GOTO” and a line number constant. Need to see if this is the special case of a “0” or some other line number.
[4F71H]
4ED6
OR E
[4EF3H]
Note: 63BAH is used in this Overlay to hold the current pointer in the BASIC Program.
4EEAH – Continue converting LINE NUMBERS into POINTERS now that we know that we are not dealing with an ON ERROR.
[1B2CH]
[4F59H]
[20F9H]
[28A7H]
[0FAFH]
[0FA7H]
4F15
4F1BH – “RENUM” Message Storage Area.
4F2AH – “RENUM” – Change POINTERS into LINE NUMBERS.
4F2A
[4EB7H]
4F35
4F36
INC HL
INC HL
4F3C
LD L,C
[5088H]
Note: 63BAH is used in this Overlay to hold the current pointer in the BASIC Program.
[4F69H]
[4F4AH]
4F59H – Change a LINE NUMBER to a POINTER.
4F5D
Note: 63BAH is used in this Overlay to hold the current pointer in the BASIC Program to the character after a constant.
4F60
4F69H – Non-Fast RENUM. Fills C characters of (HL) with a SPACE and then JUMPs to NSPCFL.
4F71H – Get the line number pointed to by Register Pair HL – 1 and put it into Register Pair DE and then run a RST 10H to get the next character into Register A.
Note: 63BAH is used in this Overlay to hold the current pointer in the BASIC Program.
[1D78H]
4F7DH – Fill (BC), which points to the line number in the program, with 5 SPACES.
4F8BH – RENUM Token List.
4F97H – Convert all line number references to a binary line number + 2 spaces
“LINSCN”
4F97LD HL,(40A4H)Fetch the 2 byte RAM location for the beginning of the BASIC Program from 40A4H.
LD A,(HL)Fetch a character in the BASIC PROGRAM (at the memory memory location pointed to by Register Pair HL) and store it into Register A.
4F9BINC HLINCrement the value stored in Register Pair HL by 1 to point to the character after the one we just fetched into Register A.
4F9COR (HL)Test to see if the next character is 00H by OR’ing Register A against the value of the next character in the program. If that next character was 00H then Register A will be unchanged, and the Z Flag will be set.
4F9DJR Z,DOCNVR
[4FDBH]If the next character in the program is a 00H then we are done, so JUMP to 4FDBH.
4F9F
4FA0
4FA1INC HL
INC HL
INC HLINCrement the value stored in Register Pair HL by 3 to point to the first character after the line number.
LD A,(HL)Fetch a character in the BASIC PROGRAM (at the memory memory location pointed to by Register Pair HL) and store it into Register A.
4FA3OR ASince a LD command does not set any FLAGS, Set FLAGS based on the contents of Register A (and, in all events, clear the CARRY FLAG).
4FA4INC HLINCrement the value stored in Register Pair HL by 1 to point to the character after the one we just fetched into Register A.
4FA5JR Z,PNXTLN
[4F9AH]If the Z FLAG (Zero) has been set, JUMP to 4F9AH to process the next line in the program.
4FA7JP P,PNXTCH
[4FA2H]If the P FLAG has SET, LOOP BACK 5 instructions to 4FA2H to process the next character.
“ISTOKN”
4FAADEC HLBack up HL to point to the prior character by DECrementing the value stored in Register Pair HL by 1.
4FABLD DE,TOKLSTLet Register Pair DE point to the TOKEN LIST at 4F8BH.
4FAELD C,0CHThe TOKEN LIST is 12 long so set Register C equal 0CH.
LD A,(DE)Top of a loop to examine the tokens. First, fetch a token (i.e., the value held in the memory location pointed to by Register Pair DE) and store it into Register A.
4FB1CP (HL)Compare the token from the list agains the token in the program as pointed to by (HL). Results: If Register A equals the value held in Register HL, the Z FLAG is set; otherwise the NZ FLAG is set.
4FB4INC DEIf they didn’t match, then move to the next token in the list by INCrementing the value stored in Register Pair DE by 1.
4FB5DEC CReduce the loop counter by DECrementing the value stored in Register C by 1.
4FB6JR NZ,LOPTKS
[4FB0H]If we haven’t parsed all 12 token in the token list then LOOP BACK to 4FB0H.
4FB8LD A,(HL)Fetch a character in the BASIC PROGRAM (at the memory memory location pointed to by Register Pair HL) and store it into Register A.
4FB9CP 89HCompare that character against the token for the INPUT command.
4FBBINC HLINCrement the value stored in Register Pair HL by 1 to point to the next character in the BASIC Program.
4FBCJR NZ,4FA2H
[4FA2H]If the NZ FLAG (Not Zero) has been set, then we didn’t have an INPUT, so JUMP to 4FA2H to process the next character.
If we’re here, then we got an INPUT, but now we need to check to see if it was INPUT # or not.
4FBEPUSH HLSave the location of the character in the BASIC Program being examined in case it turns out not to be a INPUT # LEN <FORMULA>, <LINE NUMBER>; command and we need to process what we thought might have been the #.
4FBFDEC HLMove back 1 character in the BASIC program by DECrementing the value stored in Register Pair HL by 1.
4FC0RST 10HCall the EXAMINE NEXT SYMBOL routine at RST 10H.
NOTE:- The RST 10H routine loads the next character from the string pointed to by the HL register into the A-register and clears the CARRY FLAG if it is alphabetic, or sets it if is alphanumeric.
- Blanks and control codes 09H and 0BH are ignored causing the following character to be loaded and tested.
- The HL register will be incremented before loading any character therfore on the first call the HL register should contain the string address minus one.
- The string must be terminated by a byte of zeros.
4FC1CP 23HCompare the value held in Register A against 23H (ASCII: #). If the character following the INPUT wasn’t a # …
4FC3JR NZ,NOILEN
[4FD7H]… JUMP to 4FD7H to restore HL to after the INPUT token and continue processing the BASIC program line.
If we’re here, then we got an INPUT #, but now we need to check to see if it was INPUT # LEN or not.
4FC5RST 10HCall the EXAMINE NEXT SYMBOL routine at RST 10H.
NOTE:- The RST 10H routine loads the next character from the string pointed to by the HL register into the A-register and clears the CARRY FLAG if it is alphabetic, or sets it if is alphanumeric.
- Blanks and control codes 09H and 0BH are ignored causing the following character to be loaded and tested.
- The HL register will be incremented before loading any character therfore on the first call the HL register should contain the string address minus one.
- The string must be terminated by a byte of zeros.
4FC6CP 0F3HCompare the value held in Register A against 0F3H (BASIC Token: LEN). If the character following the INPUT # wasn’t a LEN …
4FC8JR NZ,NOILEN
[4FD7H]… JUMP to 4FD7H to restore HL to after the INPUT token and continue processing the BASIC program line.
If we’re here, then we got an INPUT # LEN, but now we need to check to see if it was INPUT # LEN , or not.
RST 10HCall the EXAMINE NEXT SYMBOL routine at RST 10H.
NOTE:- The RST 10H routine loads the next character from the string pointed to by the HL register into the A-register and clears the CARRY FLAG if it is alphabetic, or sets it if is alphanumeric.
- Blanks and control codes 09H and 0BH are ignored causing the following character to be loaded and tested.
- The HL register will be incremented before loading any character therfore on the first call the HL register should contain the string address minus one.
- The string must be terminated by a byte of zeros.
4FCBJP Z,NOILEN
[4FD7H]If there was no next character, and we ended with INPUT # LEN, JUMP to 4FD7H to restore HL to after the INPUT token and continue processing the BASIC program line.
4FCECP 2CHCompare the value held in Register A against 2CH (ASCII: ,). If the character following INPUT # LEN was NOT a , …
4FD3POP AFGet rid of the location of the character in the BASIC Program being examined held at the top of the stack, because we don’t need it, as we have found INPUT #LEN ,, which would need to be followed by a line number.
4FD7H – This is an exit to the prior routine where we ultimately figured out we were not going to be processing a INPUT #LEN <FORMULA>, <LINE NUMBER>; command.
POP HLRestore the pointer to the location of the character in the BASIC Program into Register Pair HL. This would be the character after the span class=”code”>INPUT token.
4FDBH – Part of the “Convert all line number references to a binary line number + 2 spaces” routine if we have determined that the next character is the end of the program.
LD HL,(40A4H)Fetch the 2 byte RAM location for the beginning of the BASIC Program from 40A4H.
4FDEEX DE,HLEXchange the value stored in Register Pair HL (i.e., the start of the BASIC program) with the value stored in Register Pair DE.
4FE1LD A,(HL)Fetch a byte of the BASIC program (held in the memory location pointed to by Register Pair HL) and store it into Register A.
4FE2INC HLINCrement the value stored in Register Pair HL by 1 to point to the character after the one we just fetched into Register A.
4FE3OR (HL)Test to see if the next character is 00H by OR’ing Register A against the value of the next character in the program. If that next character was 00H then Register A will be unchanged, and the Z Flag will be set.
4FE4JP Z,CLEARZ
[5067H]If the Z FLAG (Zero) has been set, JUMP to 5067H to zero out the ARRAY variable table and RETurn.
4FE7
4FE8
4FE9INC HL
INC HL
INC HLINCrement the value stored in Register Pair HL by 3 to point to the first character after the line number.
LD A,(HL)Top of a loop. Fetch a byte of the BASIC program (held in the memory location pointed to by Register Pair HL) and store it into Register A.
4FEBINC HLINCrement the pointer in the BASIC program (stored in Register Pair HL) by 1.
4FECCP 0EHCompare the value held in Register A against 0EH, which is the LINE NUMBER CONSTANT. If the current character is a LINE NUMBER CONSTANT, the Z FLAG will be set …
4FEEJR Z,TWOINX
[4FF9H]… so JUMP to the next routine at 4FF9H to skip over the 2 bytes of the line number and continue the loop.
4FF0OR ASet FLAGS based on the contents of Register A (and, in all events, clear the CARRY FLAG).
4FF1JR NZ,LZLOOP
[4FEAH]If the NZ FLAG (Not Zero) has been set, JUMP to the top of this loop at 4FEAH.
The next instructions swap out the line number with the binary version.
4FF3EX DE,HLEXchange the value stored in Register Pair HL (i.e., the pointer in the BASIC Program) with the value stored in Register Pair DE.
4FF4LD (HL),EStore the value held in Register E into the memory location pointed to by Register Pair HL.
4FF5INC HLINCrement the value stored in Register Pair HL by 1.
4FF6LD (HL),DStore the value held in Register D into the memory location pointed to by Register Pair HL.
4FF9H – Part of the “Convert all line number references to a binary line number + 2 spaces” routine if the chararacter in the BASIC program was a LINE NUMBER CONSTANT.
INC HL
INC HLINCrement the value stored in Register Pair HL by 2 to move the pointer in the BASIC program (held in Register Pair HL) past that line number constant.
4FFDH – Routine is out of sequence and is only called by 5049H if we determine the the character in A is not numeric
DEC HLBack up the pointer in the BASIC program (stored in Register Pair HL) by 1 in preparation for the RST 10H command which advances HL.
RST 10HWe are still looking for a line number. Call the EXAMINE NEXT SYMBOL routine at RST 10H.
NOTE:- The RST 10H routine loads the next character from the string pointed to by the HL register into the A-register and clears the CARRY FLAG if it is alphabetic, or sets it if is alphanumeric.
- Blanks and control codes 09H and 0BH are ignored causing the following character to be loaded and tested.
- The HL register will be incremented before loading any character therfore on the first call the HL register should contain the string address minus one.
- The string must be terminated by a byte of zeros.
4FFFPUSH HLSave the pointer in the BASIC Program (stored in Register Pair HL) to the top of the stack.
5000OR ASet FLAGS based on the contents of Register A to see if we are at end of line (00H) or not. If we are at the end of the line …
The LOKLF routine looks for a LINE FEED character.
5004LD A,(HL)Fetch a byte of the BASIC program (held in the memory location pointed to by Register Pair HL) and store it into Register A.
5005CP 0AHCompare the value held in Register A against 0AH (ASCII: LINE FEED). If the current character in the BASIC program is a LINE FEED …
5009OR ASet FLAGS based on the contents of Register A. If it is not end of line (i.e., 00H) ….
500AJR NZ,LOKLF
[5003H]LOOP back to the top of the LOKLF routine and keep looking for the LINE FEED.
Next we are going to put a “*” wherever there was a LINE FEED. If (HL) is not a line feed, then a dummy HL of 4121H is offered as the sacrificial location to put the “*“.
LD HL,4121HIf (HL) wasn’t pointing to a LINE FEED we don’t want the next line to overwrite that character with a *, so let Register Pair HL equal 4121H as a dummy location to put the *.
LD (HL),2AHStore a * into the memory location pointed to by Register Pair HL (which is either the dummy location if there wasn’t a LINE FEED there, or to overwrite a LINE FEED if it was there).
5011EX DE,HLPut the value stored in Register Pair HL (which could be either 4121H or the position in the BASIC program AFTER searching for the LINE FEED) into DE. HL is discarded so it doesn’t matter what was in DE.
5012POP HLRestore the pointer in the BASIC Program (before searching for the LF) held at the top of the STACK into Register Pair HL, and then remove the entry from the stack.
5013PUSH HLSave the pointer in the BASIC Program (before searching for the LF) to the top of the stack.
5014PUSH DESave the contents of Register Pair DE (which could be either 4121H or the position in the BASIC program AFTER searching for the LINE FEED) to the top of the stack.
5015CALL 1E5AH
[1E5AH]Convert the ASCII string pointed to by HL to an integer deposited into DE via a GOSUB to the Model III ROM routine at 1E5AH. After execution HL points to the delimiter and the A register contains the delimiter value. The Z flag is set if the delimiter equals 00 or 3A. Z is reset if any other delimiter is used. If the routine finds a non-numerical character, the conversion is stopped
5018LD A,0AHLet Register A equal 0AH (ASCII: LINE FEED.
501APOP BCPut the value held at the top of the STACK which could be either 4121H or the position in the BASIC program AFTER searching for the LINE FEED) into Register Pair BC, and then remove the entry from the stack.
501BLD (BC),ARestore the LINE FEED into the memory location pointed to by Register Pair BC.
Next we need to check to see if we advanced in the BASIC program.
501CPOP BCRestore the pointer in the BASIC Program (before searching for the LF) held at the top of the STACK into Register Pair BC, and then remove the entry from the stack.
501DLD A,LCopy the contents of Register L (i.e., the current location in the program) into Register A.
501ESUB CSubtract the LSB from the program before searching for the LF from the LSB of the current location of the program, to see if we have moved. If this is NZ, there was a Line Feed.
501FJR Z,NOLIN
[5045H]If the Z FLAG (Zero) has been set, go back to whence we came and continue processing characters via a JUMP to 5045H.
5021PUSH DEOtherwise, save the LINE NUMBER (held in Register Pair DE) to the top of the stack.
The next steps calculate the number of SPACES we need to add.
5022LD E,ACopy the contents of Register A into Register E.
5023LD A,02HAssume we want TWO spaces, so set Register A to 02H.
5025PUSH AFSave the contents of Register Pair AF to the top of the stack.
5026LD A,05HLet Register A equal 05H.
5028SUB ELET Register A = Register A – Register E. Register A now holds the number of spaces we need to insert to make room for a hard line number.
5029JR NC,MOVPR2
[5032H]If the number spaces is still positive, JUMP to 5032H to move the program to make room for the line number.
502BCPLIf, however, the number of spaces went negative because the line number was more than 5 characters including zeros and spaces, we need to make even more room. First, reverse each bit in Register A (which is the same as NOT) to become positive.
502CINC AINCrement the value stored in Register A by 1.
502DPOP DEPut the value held at the top of the STACK (which should be 02H) into Register Pair DE, and then remove the entry from the stack.
502EADD A,02HAdd two assumed spaces by letting Register A = Register A + 02H.
5030PUSH AFSave the space count (held in Register Pair AF) to the top of the stack.
5031XOR ASet Register A to ZERO and clear all Flags.
Next we make room for the hard line number, put in the hard line number indicator byte, the line number, and then spaces to fill the remainder.
PUSH BCSave the location that the LINE VALUE CONSTANT is going to be placed (held in Register Pair BC) to the top of the stack.
5033CALL NZ,MOVPRG
[5071H]If the NZ FLAG (Not Zero) has been set, ??? move (HL) for (A) bytes via a GOSUB to 5071H.
5036POP HLRestore the pointer to the to the BASIC program (held at the top of the Stack) into Register Pair HL). This should be the 5 bytes that need to be replaced with an actual hard line number.
5037LD (HL),0EHStore the flag for a LINE VALUE CONSTANT into the memory location pointed to by Register Pair HL.
5039INC HLINCrement the pointer to the BASIC program (held in Register Pair HL) by 1.
503APOP BCRestore the space count into Register B from the top of the STACK, as B acts as the counter of a DJNZ loop.
503BPOP DERestore the LINE VALUE CONSTANT (held at the top of the STACK) into Register Pair DE, and then remove the entry from the stack.
503CLD (HL),EStore the LSB of LINE VALUE CONSTANT (held in Register E) into the BASIC Program at the memory location pointed to by Register Pair HL.
503DINC HLINCrement the pointer to the BASIC program (held in Register Pair HL) by 1.
503ELD (HL),DStore the MSB of LINE VALUE CONSTANT (held in Register D) into the BASIC Program at the memory location pointed to by Register Pair HL.
INC HLTop of a DJNZ loop. INCrement the pointer to the BASIC program (held in Register Pair HL) by 1.
5040LD (HL),20HStore a SPACE into the BASIC Program at the memory location pointed to by Register Pair HL.
5042DJNZ SPCPUR
[503FH]LOOP back to 503FH, reducing Register B each time, and continue to LOOP until Register B has been reduced to ZERO, in which case, continue with the next instruction.
The line number and spaces are now present. If passing through, we need to bump HL because the routine starts off by reducing it because the RST 10H needs it to be HL-1.
5046RST 10HCall the EXAMINE NEXT SYMBOL routine at RST 10H.
NOTE:- The RST 10H routine loads the next character from the string pointed to by the HL register into the A-register and clears the CARRY FLAG if it is alphabetic, or sets it if is alphanumeric.
- Blanks and control codes 09H and 0BH are ignored causing the following character to be loaded and tested.
- The HL register will be incremented before loading any character therfore on the first call the HL register should contain the string address minus one.
- The string must be terminated by a byte of zeros.
5047
5048INC A
DEC ASet the Z or NZ flag based on the character in Register A.
5049JR C,LINFL1
[4FFDH]If the C FLAG (Carry) has been set then the character is alphabetic (and not alphanumeric), so JUMP to 4FFDH.
504BINC HLINCrement the pointer to the BASIC program (held in Register Pair HL) by 1.
504CJP Z,PNXTLN
[4F9AH]If the Z FLAG (Zero) has been set then the RST 10H returned a 0, which is end of line. With this, we need to move to process the next line via a JUMP to 4F9AH.
If we are here, we know that the character held in Register A is alphanumeric and not a 00H EOL marker.
504FDEC HLIn preparation for the next set of tests which would need such thing, we do a one time DECrement the pointer to the BASIC program (held in Register Pair HL) by 1.
5050CP 20HCompare the value held in Register A against 20H (ASCII: SPACE) since we want to skip any between line separators. If there is a SPACE there …
5052JR Z,SNOLIN
[5044H]… push HL to point to the next character in the BASIC Program via a JUMP to 5044H.
5054CP 2CHCompare the value held in Register A against 2CH (ASCII: ,). If it is a , …
5056JR Z,SNOLIN
[5044H]… push HL to point to the next character in the BASIC Program via a JUMP to 5044H.
5058CP 0CEHCompare the value held in Register A against CEH (Decimal: 206). Results: If Register A equals 0CEH …
505AJR Z,SNOLIN
[5044H]… push HL to point to the next character in the BASIC Program via a JUMP to 5044H.
505CCP 0D4HCompare the value held in Register A against D4H (Decimal: 212). If A < D4H, the CARRY FLAG will be set …
505EJR C,5064H
[5064H]If the C FLAG (Carry) has been set, JUMP to 5064H to zero out the array variable table and RETurn.
5060CP 0D7HCompare the value held in Register A against 0D7H (Decimal: 215). If A < 0D7H …
5062JR C,5044H
[5044H]… push HL to point to the next character in the BASIC Program via a JUMP to 5044H.
5067H – Zero out the ARRAY variable table and RETurn.
LD HL,(40F9H)Fetch the value held in memory location 40F9H and store it into Register Pair HL. 40F9H is commonly used to determine the location of the end of a BASIC program in RAM as it holds the starting address of the simple variables list table which is also one higher than the last of the three zero bytes marking the end of the BASIC program.
506ALD (40FBH),HLStore the END OF BASIC PROGRAM + 1 (held in Register Pair HL) into memory location 40FBH, which is the starting address of the ARRAY VARIABLE TABLE.
506DLD (40FDH),HLStore the END OF BASIC PROGRAM + 1 (held in Register Pair HL) into memory location 40FDH, which is the ending address of the ARRAY VARIABLE TABLE (a/k/a start of free memory pointer).
5070RETRETurn to the caller.
5071H – Routine to make room for line numbers. Moves the BASIC program down (A) bytes starting at (HL).
PUSH HLSave the pointer to the BASIC program (held in Register Pair HL) to the top of the stack.
5072LD HL,(40F9H)Fetch the value held in memory location 40F9H and store it into Register Pair HL. 40F9H is commonly used to determine the location of the end of a BASIC program in RAM as it holds the starting address of the simple variables list table which is also one higher than the last of the three zero bytes marking the end of the BASIC program.
5075EX DE,HLEXchange the value stored in Register Pair HL (i.e., the END OF BASIC PROGRAM pointer) with the value stored in Register Pair DE.
5076
5078LD H,00H
LD L,ALet Register Pair HL = the number of bytes to move the BASIC Program down (held in Register A).
5079ADD HL,DELET Register Pair HL = the offset (held in Register Pair HL) + the end of the BASIC Program in RAM (held in Register DE).
507ALD (40F9H),HLStore the new end of the BASIC program in RAM into memory location 40F9H which houses that very information.
507D
507ELD B,H
LD C,LLet BC = the new end of the BASIC program in RAM (held in Register Pair HL).
507FPOP HLRestore the currently being worked on pointer to the BASIC program (held at the top of the stack) into Register Pair HL, and then remove the entry from the stack.
LD A,(DE)Top of a loop that will ony exit if the variable address in DE and the variable address in HL are equal. Fetch a character from the BASIC program from the old end of the BASIC program in RAM (held in the memory location pointed to by Register Pair DE) and store it into Register A.
5081LD (BC),AStore that character at the new end of the BASIC program (at the memory location pointed to by Register Pair BC).
5082RST 18HRST 18 to see if the variable address in HL is the same as in DE, so we call the COMPARE DE:HL routine, which numerically compares DE and HL. Will not work for signed integers (except positive ones). Uses the A-register only. The result of the comparison is returned in the status register as: CARRY SET=HL<DE; NO CARRY=HL>DE; NZ=Unequal; Z=Equal).
5083RET ZIf the variable address in DE and the variable address in HL are equal, RETurn to the caller.
5084
5085DEC DE
DEC BCIf the variable address in DE and the variable address in HL are NOT the same, DECrement the value stored in Register Pair DE and BC each by 1.
5088H – Convert the value held in Register Pair HL into INTEGER and then into ASCII (held in Register Pair HL).
CALL 0A9AH
[0A9AH]GOSUB to 0A9AH in the Model III ROM routine to put the value in HL into the single precision number storage area of 4121H and is flagged as an INTEGER.
508BXOR ASet Register A to ZERO.
508CCALL 1034H
[1034H]GOSUB to 1034H to turn off the EDIT flag and initialize the 4130H input buffer for a FLOATING POINT to ASCII conversion by putting a SPACE into 4130H.
508FOR (HL)Set the flags by merging the value held in Register A against the byte of the program pointed to by Register Pair HL.
5090JP 0FD9H
[0FD9H]JUMP to 0FD9H in the Model III ROM to convert the integer value in 4124H to an ASCII string pointed to by Register Pair HL.
5093H – “COMPRESS” a BASIC Program Routine.
LD HL,(40A4H)Fetch the 2 byte RAM location for the beginning of the BASIC Program from 40A4H.
5096LD (BUFPNT),HLStore begining pointer to the BASIC program (held in Register Pair HL) into memory location 51AEH.
5099LD A,(HL)Fetch the value held at the beginning of the BASIC program and store it into Register A.
509AINC HLINCrement the pointer to the BASIC program (held in Register Pair HL) by 1.
509BOR (HL)Set the flags by merging the first byte of the program (held in Register A) against the second byte of the program (in the memory location pointed to by Register Pair HL)
509CRET ZIf the Z FLAG (Zero) has been set based on that OR, then there is no program present; so RETurn to the caller.
509DH – Continuation of “COMPRESS”. We at least know that there is a program in RAM.
509DLD A,ETest to see if there are spaces, REMs, or both via the next few instructions. First, copy the contents of Register E into Register A. I have no idea how E is loaded, but if E is 0, it will handle SPACES, if E is 1, it will handle REMarks, and if E is 2, it will handle both.
509EADD A,ALET Register A = Register E * 2, as the SWITCH TABLE is a table of 2 byte addresses.
509F
50A0LD E,A
LD D,00HLet Register Pair DE = old Register E * 2. This will serve as an offset in the SWITCH TABLE.
50A2LD HL,SWTABLet Register Pair HL equal 50ABH which is a SWITCH TABLE.
50A5ADD HL,DELET Register Pair HL = the SWITCH TABLE (held in Register Pair HL) + and offset of either 0, 2, or 4 (held in Register Pair DE).
50A6LD E,(HL)Fetch the LSB of the address from the SWITCH TABLE into Register E.
50A7INC HLINCrement to the next byte of the SWITCH TABLE.
50A8LD D,(HL)Fetch the MSB of the address from the SWITCH TABLE into Register D.
50A9EX DE,HLSince there is no JP (DE) comment in the Z-80, we need to EXchange the value stored in Register Pair HL (i.e., the pointer to the MSB in the SWITCH TABLE) with the value stored in Register Pair DE (i.e., the address from the SWITCH TABLE).
50ABH – “COMPRESS” – Switch Table.
“SWTAB”
50ABDEFW 6C 51HFor Spaces
50ADDEFW BAH 50HFor Remarks
50AFDEFW B1H 50HFor BOTH
50B1H – Continuation of “COMPRESS” – Jump Table Point for BOTH
50B4LD HL,(40A4H)Since we’re now going to pass through to REM, the pointers are no longer what they would have been if we jumped, so we need to fix that. Fetch the 2 byte RAM location for the beginning of the BASIC Program from 40A4H.
50B7LD (BUFPNT),HLStore the value held in Register Pair HL into memory location 51AEH.
50BAH – Continuation of “COMPRESS” – Jump Table Point for REMARK
This routine will remove all REMarks from a BASIC program. If REM is the first token on a line, the comment is removed but the REM stays (as there may be GOTOs to those lines). Otherwise, the :, the REM, and the comment are all struck.
“REMARK”
50BALD HL,(BUFPNT)Fetch the value held in memory location 51AEH and store it into Register Pair HL.
50BDLD A,(HL)Fetch a byte of the BASIC program (held in the memory location pointed to by Register Pair HL) and store it into Register A.
50BEINC HLINCrement the pointer to the BASIC program (held in Register Pair HL) by 1.
50BFOR (HL)Test to see if the next character is 00H by OR’ing Register A against the value of the next character in the program. If that next character was 00H then Register A will be unchanged, and the Z Flag will be set.
50C0JP Z,DOCLN
[5136H]If the Z FLAG (Zero) has been set based on that OR, then there is no program present (or we are at the end of the program); so clean up (and return to BASIC) via a JUMP to 5136H.
50C3LD DE,0003HSet up for an offset of 03 charagcters (Address of next line PLUS a line number) by setting Register Pair DE to 0003H.
50C6ADD HL,DELET Register Pair HL = the pointer to the BASIC program (held in Register Pair HL) + 03H (held in Register DE). HL now points to the first character of the line.
50C7LD E,00HPrepare a counter by setting Register E to 00H.
LD A,(HL)Fetch a byte of the BASIC program (held in the memory location pointed to by Register Pair HL) and store it into Register A.
50CAINC HLINCrement the pointer to the BASIC program (held in Register Pair HL) by 1.
50CBOR ASet FLAGS based on the contents of Register A to see if we are at the end of the line (Z) or not (NZ).
50CELD (BUFPNT),HLIf we are, however, at the end of the program line, then this program line is done; so set the buffer pointer (of 51AEH) to point to the next character of the program.
50D1JR REMARK
[50BAH]JUMP to the top of this REMARK (at 50BAH) routine and keep processing, now with the new HL.
50D3H – Continuation of “COMPRESS” routine processing REMarks. Jumped here if we are not at the end of the line and still need to process it.
50D4CP 93HCompare the value held in Register A against 93H (BASIC TOKEN: REM). If the character in the BASIC program pointed to by HL is a REM token …
50D8CP 27HCompare the value held in Register A against 27H (ASCII: ‘). If the character in the BASIC program pointed to by HL is a ‘ token …
50DCLD B,22HLet Register B equal 22H (ASCII: “).
50DECP 22HCompare the character in the BASIC Program (held in Register A) against a (ASCII: “). If Register A is a “ …
50E5H – Continuation of “COMPRESS” routine processing REMarks. See if the REMark is at the beginning of the line or not.
50E6CP 01HCheck to see if the REMark token or character was in first position. If not then …
50EALD A,(HL)If, however, the first character was not a REM, keep processing characters by fetching a byte of the BASIC program (held in the memory location pointed to by Register Pair HL) and store it into Register A.
50EBOR ASince a LD command does not set any FLAGS, Set FLAGS based on the contents of Register A (and, in all events, clear the CARRY FLAG).
50ECJR NZ,REMAR5
[50FCH]If that byte was NOT a zero, then we are NOT at the end of the line, so JUMP to 50FCH to clear the rest of the line.
50EEINC HLINCrement the pointer to the BASIC program (held in Register Pair HL) by 1.
50EFLD (51AEH),HLStore the current character into 51AEH to be the new pointer (thus erasing everything after it).
50F4H – Continuation of “COMPRESS” routine processing REMarks; deal with whatever followed the REM token.
DEC HL
DEC HLBack up the pointer to the BASIC program (held in Register Pair HL) by 1 to get to the :.
50F6LD A,(HL)Fetch a byte of the BASIC program (held in the memory location pointed to by Register Pair HL) and store it into Register A. This should be a :.
50F7CP 3AHCompare the value held in Register A against 3AH (ASCII: :). If Register A equals : …
50FBINC HLIf Register A was not the : we expected, we need to leave that character alone by INCrementing the pointer to the BASIC program (held in Register Pair HL) by 1.
LD (HL),00HEnd the program line by putting a 00H into the position in the BASIC program pointed to by Register Pair HL.
50FEINC HLINCrement the pointer to the BASIC program (held in Register Pair HL) by 1 to now be the character after the REM.
50FFLD (TEMPX),HLStore the pointer into memory location 51B0H.
The next instructions move us to the end of the line.
5102LD E,00HPrepare a counter by setting Register E to 00H.
LD A,(HL)Top of a loop. Fetch a byte of the BASIC program (held in the memory location pointed to by Register Pair HL) and store it into Register A.
5105OR ASince a LD command does not set any FLAGS, Set FLAGS based on the contents of Register A (and, in all events, clear the CARRY FLAG).
5106JR Z,510CH
[510CH]If the Z FLAG (Zero) has been set, then we are at the end of the line, so exit via a JUMP to 510CH.
5108INC EIf we are, however, not at the end of the line, we need to keep going. INCrement the counter (stored in Register E) by 1.
5109INC HLINCrement the pointer to the BASIC program (held in Register Pair HL) by 1.
510CH – Continuation of “COMPRESS” routine processing REMarks; deal with the end of line.
510DLD BC,(TEMPX)Fetch the “move to” pointer (held in memory location 51B0H) and store it into Register Pair BC.
5111INC HLINCrement the “move from” pointer (held in Register Pair HL) by 1.
5115LD HL,(TEMPX)Fetch the “move to” pointer (held in memory location 51B0H) and store it into Register Pair HL.
5118LD (BUFPNT),HLStore “move to” pointer (held in Register Pair HL) and put it as the current line (being tracked in memory location 51AEH).
511DH – Continuation of “COMPRESS” routine processing REMarks. Subroutine to skip over a QUOTE mark.
LD A,(HL)Fetch a byte of the BASIC program (held in the memory location pointed to by Register Pair HL) and store it into Register A.
511EINC HLINCrement the pointer to the BASIC program (held in Register Pair HL) by 1.
511FOR ASet FLAGS based on the contents of Register A (and, in all events, clear the CARRY FLAG).
5120JR NZ,SKQUO1
[5124H]If the NZ FLAG (Not Zero) has been set, then we are NOT at the end of the line, so JUMP to 5124H to check.
5122SCFOtherwise, we are at the end of the line and since the CARRY FLAG is going to be important, turn the CARRY FLAG on.
5123RETRETurn to the caller.
5124H – Continuation of “COMPRESS” routine processing REMarks. Continuation of the subroutine to skip over a QUOTE mark if we are NOT at the end of line.
5125CP BCompare the value held in Register A against the value held in Register B (which is a (ASCII: “). If the current character is a “ …
5126RET Z… RETurn to the caller.
5127JR SKQUOT
[511DH]… otherwise …, we need to keep looking for the close quote via a JUMP BACK to 511DH.
5129H – Continuation of “COMPRESS” routine, but called later in the program. This subroutine skips space and tabs.
LD A,(HL)Fetch a byte of the BASIC program (held in the memory location pointed to by Register Pair HL) and store it into Register A.
512AINC HLINCrement the pointer to the BASIC program (held in Register Pair HL) by 1.
512BCP 20HCompare the value held in Register A against 20H (ASCII: SPACE). If the current character is a SPACE …
512FCP 09HCompare the value held in Register A against 09H (ASCII: TAB). If the current character is a TAB …
5133DEC HLIf we’re here, then we are at a character in the BASIC program we don’t want remove, so back up the pointer to the BASIC program (held in Register Pair HL) by 1.
5134OR ABefore we return, we want to set the flags to see if we are at the END OF LINE (i.e., 00H), so do an OR A to set the Z FLAG.
5135RETRETurn to the caller.
5136H – Continuation of “COMPRESS” routine. Jumped to when it is time to clean up the linked addresses and then exit.
LD DE,(40A4H)Fetch the 2 byte RAM location for the beginning of the BASIC Program from 40A4H into Register Pair DE.
513CLD A,(HL)Fetch a byte of the BASIC program (held in the memory location pointed to by Register Pair HL) and store it into Register A. This byte should be a LINKED ADDRESS.
513DINC HLINCrement the pointer to the BASIC program (held in Register Pair HL) by 1.
513EOR (HL)Test to see if the next character is 00H by OR’ing Register A against the value of the next character in the program. If that next character was 00H then Register A will be unchanged, and the Z Flag will be set.
5141
5142
5143INC HL
INC HL
INC HLBump past the 3 characters for a line number by INCrementing the pointer to the BASIC program (held in Register Pair HL) by 3.
LD A,(HL)Top of a 4 instruction loop. Fetch a byte of the BASIC program (held in the memory location pointed to by Register Pair HL) and store it into Register A.
5145INC HLINCrement the pointer to the BASIC program (held in Register Pair HL) by 1.
5146OR ACheck to see if that prior byte (held in A) is an END OF LINE (i.e., 00H), and if NOT …
5149EX DE,HLAt this point, we are at the END OF A LINE and HL holds the byte after the END OF LINE BYTE. Put the LINKED ADDRESS into Register Pair DE.
514ALD (HL),EStore the LSB of the LINKED ADDRESS held in Register E into the memory location pointed to by Register Pair HL.
514BINC HLINCrement the value stored in Register Pair HL by 1.
514CLD (HL),DStore the MSB of the LINKED ADDRESS held in Register D into the memory location pointed to by Register Pair HL.
514DJR LDHEAD
[513AH]LOOP BACK to the 2nd line of this routine (513AH) to cycle through the entire BASIC program.
514FH – Continuation of “COMPRESS” routine. We are done so set the RAM Pointers to the new End of Program and then EXIT to BASIC.
“CLEARY”
514FLD HL,(40F9H)Fetch the value held in memory location 40F9H and store it into Register Pair HL. 40F9H is commonly used to determine the location of the end of a BASIC program in RAM as it holds the starting address of the simple variables list table which is also one higher than the last of the three zero bytes marking the end of the BASIC program.
5152LD (40FBH),HLStore the END OF BASIC PROGRAM + 1 (held in Register Pair HL) into memory location 40FBH, which is the starting address of the ARRAY VARIABLE TABLE.
5155LD (40FDH),HLStore the END OF BASIC PROGRAM + 1 (held in Register Pair HL) into memory location 40FDH, which is the ending address of the ARRAY VARIABLE TABLE (a/k/a start of free memory pointer).
5158RETRETurn to BASIC.
5159H – Subroutine in the COMPRESS” routine. This routine moves the BASIC program down starting at (HL) into (BC).
515ALD DE,(40F9H)Fetch the END OF BASIC PROGRAM pointer from memory location 40F9H and store it into Register Pair DE.
515EEX DE,HLSince DE will always be bigger than HL, and the Z-80 does not have an instruction to subtract against DE, swap them.
515FOR AThe CARRY FLAG will be important here so clear the CARRY FLAG.
5160SBC HL,DECalculate the number of bytes to move by SUBtracting DE from HL.
The next instructions move all the variables around so that they fit into the LDIR mold.
5162EX (SP),HLEXchange the value stored in Register Pair HL (i.e., the number of bytes to move) with the value stored at the top of the stack (i.e., the MOVE FROM address).
5163
5164PUSH BC
POP DECopy the “move to” address (held in Register Pair BC) to Register Pair DE.
5165POP BCPut the the number of bytes to move ( held at the top of the STACK) into Register Pair BC, and then remove the entry from the stack.
5166LDIRTransfers a byte of data from the memory location pointed to by HL to the memory location pointed to by DE. Then HL and DE are incremented and BC is decremented. If BC is not zero, this operation is repeated. Interrupts can trigger while this instruction is processing.
5168LD (40F9H),HLSet the END OF BASIC PROGRAM pointer in RAM to the end of the code we just moved (held in Register Pair HL).
516BRETRETurn to the caller.
516CH – – Continuation of “COMPRESS” – Jump Table Point for CLEAR SPACES processing. Routine will clear out SPACES and TABS except inside QUOTES and FIELD statements.
LD HL,(BUFPNT)Fetch the location in the BASIC program to process (held in memory location 51AEH) and store it into Register Pair HL.
516FLD A,(HL)Fetch a byte of the BASIC program (held in the memory location pointed to by Register Pair HL) and store it into Register A.
5170INC HLINCrement the value stored in Register Pair HL by 1 to point to the character after the one we just fetched into Register A.
5171OR (HL)Test to see if the next character is 00H by OR’ing Register A against the value of the next character in the program. If that next character was 00H then Register A will be unchanged, and the Z Flag will be set.
5172JP Z,DOCLN
[5136H]If the Z FLAG (Zero) has been set, we are at the end of the program so clean up (and return to BASIC) via a JUMP to 5136H.
5175LD DE,0003HWe want to skip over the 3 bytes of a line number and space so set Register Pair DE = 0003H.
5178ADD HL,DEAdvance our BASIC Pointer by 3 by setting Register Pair HL = Register Pair HL + Register DE.
LD A,(HL)Top of a Loop. Fetch a byte of the BASIC program (held in the memory location pointed to by Register Pair HL) and store it into Register A.
517AINC HLINCrement the value stored in Register Pair HL by 1 to point to the character after the one we just fetched into Register A.
517BOR ASet FLAGS based on the contents of Register A.
517ELD (BUFPNT),HLSave our current poition as the new line pointer in memory location 51AEH.
5181JR SPACES
[516CH]LOOP BACK to the top of this routine (516CH) to keep processing via the next line.
5183H – Continuation of CLEAR SPACES subroutine of the “COMPRESS” routine. Jumped to if we are past the line number + space and NOT at end of line.
5185CP 22HCompare the current character in the BASIC program (held in Register A) against 22H (ASCII: “). If it is a “ …
5187JR Z,DOSKIP
[518FH]… skip over processing it via a JUMP to 518FH because we aren’t removing spaces from quoted text.
5189LD B,3AHLet Register B equal :.
518BCP 0A3HCompare the value held in Register A against 0A3H (BASIC Token: FIELD). If the character of the BASIC program was not a FIELD token …
We are here either because we jumped here from 5187 because we are inside a quote, or because we passed through and we hit a FIELD token. Either way, we want to skip over deleting the spaces.
5192JR NC,SPACE1
[5179H]If the NC FLAG (No Carry) has been set by that routine, then we are NOT at the END OF LINE, so LOOP BACK to 5179H to keep processing.
5194LD (BUFPNT),HLIf we’re here then that routine indicated we are at the end of a line, so save our current position as the new line pointer in memory location 51AEH.
5199H – Continuation of CLEAR SPACES subroutine of the “COMPRESS” routine. Jumped here if we know that we are not within a QUOTE or in a FIELD statement.
CP 20HCompare the value held in Register A against 20H (ASCII: SPACE). If we are at a SPACE) …
519DCP 09HCompare the value held in Register A against 09H (ASCII: TAB). If we are NOT at a TAB) …
Actually elimiate the TAB or SPACE character.
51A2LD B,H
LD C,LLet BC = HL so that BC also points to the character being deleted.
51A4CALL SKIPSP
[5129H]Skip over spaces and tabs via a GOSUB to 5129H which will adjust HL to point to the first non-space and non-tab character (and set the Z flag if we are at the END OF LINE). BC is not modified by that routine.
51A7PUSH BCSave the pointer to the character being deleted (held in Register Pair BC) to the top of the stack.
51ABPOP HLRestore the pointer to the character being deleted from the top of the STACK into Register Pair HL, and then remove the entry from the stack.
51AEH – “COMPRESS” routine MESSAGE and BYTE storage area.
“BUFPNT”
51AEDEFS 02
“TEMPX”
51B0DEFS 02
END 4E00HThat’s it!
4F97
[4FDBH]
4FA0
4FA1
INC HL
INC HL
[4F9AH]
[4FA2H]
4FAA
[4FB0H]
[4FA2H]
If we’re here, then we got an INPUT, but now we need to check to see if it was INPUT # or not.
NOTE:
- The RST 10H routine loads the next character from the string pointed to by the HL register into the A-register and clears the CARRY FLAG if it is alphabetic, or sets it if is alphanumeric.
- Blanks and control codes 09H and 0BH are ignored causing the following character to be loaded and tested.
- The HL register will be incremented before loading any character therfore on the first call the HL register should contain the string address minus one.
- The string must be terminated by a byte of zeros.
[4FD7H]
If we’re here, then we got an INPUT #, but now we need to check to see if it was INPUT # LEN or not.
NOTE:
- The RST 10H routine loads the next character from the string pointed to by the HL register into the A-register and clears the CARRY FLAG if it is alphabetic, or sets it if is alphanumeric.
- Blanks and control codes 09H and 0BH are ignored causing the following character to be loaded and tested.
- The HL register will be incremented before loading any character therfore on the first call the HL register should contain the string address minus one.
- The string must be terminated by a byte of zeros.
[4FD7H]
If we’re here, then we got an INPUT # LEN, but now we need to check to see if it was INPUT # LEN , or not.
NOTE:
- The RST 10H routine loads the next character from the string pointed to by the HL register into the A-register and clears the CARRY FLAG if it is alphabetic, or sets it if is alphanumeric.
- Blanks and control codes 09H and 0BH are ignored causing the following character to be loaded and tested.
- The HL register will be incremented before loading any character therfore on the first call the HL register should contain the string address minus one.
- The string must be terminated by a byte of zeros.
[4FD7H]
[5067H]
4FE8
4FE9
INC HL
INC HL
[4FF9H]
[4FEAH]
The next instructions swap out the line number with the binary version.
INC HL
NOTE:
- The RST 10H routine loads the next character from the string pointed to by the HL register into the A-register and clears the CARRY FLAG if it is alphabetic, or sets it if is alphanumeric.
- Blanks and control codes 09H and 0BH are ignored causing the following character to be loaded and tested.
- The HL register will be incremented before loading any character therfore on the first call the HL register should contain the string address minus one.
- The string must be terminated by a byte of zeros.
The LOKLF routine looks for a LINE FEED character.
[5003H]
Next we are going to put a “*” wherever there was a LINE FEED. If (HL) is not a line feed, then a dummy HL of 4121H is offered as the sacrificial location to put the “*“.
[1E5AH]
Next we need to check to see if we advanced in the BASIC program.
[5045H]
The next steps calculate the number of SPACES we need to add.
[5032H]
Next we make room for the hard line number, put in the hard line number indicator byte, the line number, and then spaces to fill the remainder.
[5071H]
[503FH]
The line number and spaces are now present. If passing through, we need to bump HL because the routine starts off by reducing it because the RST 10H needs it to be HL-1.
NOTE:
- The RST 10H routine loads the next character from the string pointed to by the HL register into the A-register and clears the CARRY FLAG if it is alphabetic, or sets it if is alphanumeric.
- Blanks and control codes 09H and 0BH are ignored causing the following character to be loaded and tested.
- The HL register will be incremented before loading any character therfore on the first call the HL register should contain the string address minus one.
- The string must be terminated by a byte of zeros.
5048
DEC A
[4FFDH]
[4F9AH]
If we are here, we know that the character held in Register A is alphanumeric and not a 00H EOL marker.
[5044H]
[5044H]
[5044H]
[5064H]
[5044H]
5067H – Zero out the ARRAY variable table and RETurn.
5071H – Routine to make room for line numbers. Moves the BASIC program down (A) bytes starting at (HL).
5078
LD L,A
507E
LD C,L
5085
DEC BC
5088H – Convert the value held in Register Pair HL into INTEGER and then into ASCII (held in Register Pair HL).
[0A9AH]
[1034H]
[0FD9H]
5093H – “COMPRESS” a BASIC Program Routine.
509DH – Continuation of “COMPRESS”. We at least know that there is a program in RAM.
50A0
LD D,00H
50ABH – “COMPRESS” – Switch Table.
50AB
50B1H – Continuation of “COMPRESS” – Jump Table Point for BOTH
50B4LD HL,(40A4H)Since we’re now going to pass through to REM, the pointers are no longer what they would have been if we jumped, so we need to fix that. Fetch the 2 byte RAM location for the beginning of the BASIC Program from 40A4H.
50B7LD (BUFPNT),HLStore the value held in Register Pair HL into memory location 51AEH.
50BAH – Continuation of “COMPRESS” – Jump Table Point for REMARK
This routine will remove all REMarks from a BASIC program. If REM is the first token on a line, the comment is removed but the REM stays (as there may be GOTOs to those lines). Otherwise, the :, the REM, and the comment are all struck.
“REMARK”
50BALD HL,(BUFPNT)Fetch the value held in memory location 51AEH and store it into Register Pair HL.
50BDLD A,(HL)Fetch a byte of the BASIC program (held in the memory location pointed to by Register Pair HL) and store it into Register A.
50BEINC HLINCrement the pointer to the BASIC program (held in Register Pair HL) by 1.
50BFOR (HL)Test to see if the next character is 00H by OR’ing Register A against the value of the next character in the program. If that next character was 00H then Register A will be unchanged, and the Z Flag will be set.
50C0JP Z,DOCLN
[5136H]If the Z FLAG (Zero) has been set based on that OR, then there is no program present (or we are at the end of the program); so clean up (and return to BASIC) via a JUMP to 5136H.
50C3LD DE,0003HSet up for an offset of 03 charagcters (Address of next line PLUS a line number) by setting Register Pair DE to 0003H.
50C6ADD HL,DELET Register Pair HL = the pointer to the BASIC program (held in Register Pair HL) + 03H (held in Register DE). HL now points to the first character of the line.
50C7LD E,00HPrepare a counter by setting Register E to 00H.
LD A,(HL)Fetch a byte of the BASIC program (held in the memory location pointed to by Register Pair HL) and store it into Register A.
50CAINC HLINCrement the pointer to the BASIC program (held in Register Pair HL) by 1.
50CBOR ASet FLAGS based on the contents of Register A to see if we are at the end of the line (Z) or not (NZ).
50CELD (BUFPNT),HLIf we are, however, at the end of the program line, then this program line is done; so set the buffer pointer (of 51AEH) to point to the next character of the program.
50D1JR REMARK
[50BAH]JUMP to the top of this REMARK (at 50BAH) routine and keep processing, now with the new HL.
50D3H – Continuation of “COMPRESS” routine processing REMarks. Jumped here if we are not at the end of the line and still need to process it.
50D4CP 93HCompare the value held in Register A against 93H (BASIC TOKEN: REM). If the character in the BASIC program pointed to by HL is a REM token …
50D8CP 27HCompare the value held in Register A against 27H (ASCII: ‘). If the character in the BASIC program pointed to by HL is a ‘ token …
50DCLD B,22HLet Register B equal 22H (ASCII: “).
50DECP 22HCompare the character in the BASIC Program (held in Register A) against a (ASCII: “). If Register A is a “ …
50E5H – Continuation of “COMPRESS” routine processing REMarks. See if the REMark is at the beginning of the line or not.
50E6CP 01HCheck to see if the REMark token or character was in first position. If not then …
50EALD A,(HL)If, however, the first character was not a REM, keep processing characters by fetching a byte of the BASIC program (held in the memory location pointed to by Register Pair HL) and store it into Register A.
50EBOR ASince a LD command does not set any FLAGS, Set FLAGS based on the contents of Register A (and, in all events, clear the CARRY FLAG).
50ECJR NZ,REMAR5
[50FCH]If that byte was NOT a zero, then we are NOT at the end of the line, so JUMP to 50FCH to clear the rest of the line.
50EEINC HLINCrement the pointer to the BASIC program (held in Register Pair HL) by 1.
50EFLD (51AEH),HLStore the current character into 51AEH to be the new pointer (thus erasing everything after it).
50F4H – Continuation of “COMPRESS” routine processing REMarks; deal with whatever followed the REM token.
DEC HL
DEC HLBack up the pointer to the BASIC program (held in Register Pair HL) by 1 to get to the :.
50F6LD A,(HL)Fetch a byte of the BASIC program (held in the memory location pointed to by Register Pair HL) and store it into Register A. This should be a :.
50F7CP 3AHCompare the value held in Register A against 3AH (ASCII: :). If Register A equals : …
50FBINC HLIf Register A was not the : we expected, we need to leave that character alone by INCrementing the pointer to the BASIC program (held in Register Pair HL) by 1.
LD (HL),00HEnd the program line by putting a 00H into the position in the BASIC program pointed to by Register Pair HL.
50FEINC HLINCrement the pointer to the BASIC program (held in Register Pair HL) by 1 to now be the character after the REM.
50FFLD (TEMPX),HLStore the pointer into memory location 51B0H.
The next instructions move us to the end of the line.
5102LD E,00HPrepare a counter by setting Register E to 00H.
LD A,(HL)Top of a loop. Fetch a byte of the BASIC program (held in the memory location pointed to by Register Pair HL) and store it into Register A.
5105OR ASince a LD command does not set any FLAGS, Set FLAGS based on the contents of Register A (and, in all events, clear the CARRY FLAG).
5106JR Z,510CH
[510CH]If the Z FLAG (Zero) has been set, then we are at the end of the line, so exit via a JUMP to 510CH.
5108INC EIf we are, however, not at the end of the line, we need to keep going. INCrement the counter (stored in Register E) by 1.
5109INC HLINCrement the pointer to the BASIC program (held in Register Pair HL) by 1.
510CH – Continuation of “COMPRESS” routine processing REMarks; deal with the end of line.
510DLD BC,(TEMPX)Fetch the “move to” pointer (held in memory location 51B0H) and store it into Register Pair BC.
5111INC HLINCrement the “move from” pointer (held in Register Pair HL) by 1.
5115LD HL,(TEMPX)Fetch the “move to” pointer (held in memory location 51B0H) and store it into Register Pair HL.
5118LD (BUFPNT),HLStore “move to” pointer (held in Register Pair HL) and put it as the current line (being tracked in memory location 51AEH).
511DH – Continuation of “COMPRESS” routine processing REMarks. Subroutine to skip over a QUOTE mark.
LD A,(HL)Fetch a byte of the BASIC program (held in the memory location pointed to by Register Pair HL) and store it into Register A.
511EINC HLINCrement the pointer to the BASIC program (held in Register Pair HL) by 1.
511FOR ASet FLAGS based on the contents of Register A (and, in all events, clear the CARRY FLAG).
5120JR NZ,SKQUO1
[5124H]If the NZ FLAG (Not Zero) has been set, then we are NOT at the end of the line, so JUMP to 5124H to check.
5122SCFOtherwise, we are at the end of the line and since the CARRY FLAG is going to be important, turn the CARRY FLAG on.
5123RETRETurn to the caller.
5124H – Continuation of “COMPRESS” routine processing REMarks. Continuation of the subroutine to skip over a QUOTE mark if we are NOT at the end of line.
5125CP BCompare the value held in Register A against the value held in Register B (which is a (ASCII: “). If the current character is a “ …
5126RET Z… RETurn to the caller.
5127JR SKQUOT
[511DH]… otherwise …, we need to keep looking for the close quote via a JUMP BACK to 511DH.
5129H – Continuation of “COMPRESS” routine, but called later in the program. This subroutine skips space and tabs.
LD A,(HL)Fetch a byte of the BASIC program (held in the memory location pointed to by Register Pair HL) and store it into Register A.
512AINC HLINCrement the pointer to the BASIC program (held in Register Pair HL) by 1.
512BCP 20HCompare the value held in Register A against 20H (ASCII: SPACE). If the current character is a SPACE …
512FCP 09HCompare the value held in Register A against 09H (ASCII: TAB). If the current character is a TAB …
5133DEC HLIf we’re here, then we are at a character in the BASIC program we don’t want remove, so back up the pointer to the BASIC program (held in Register Pair HL) by 1.
5134OR ABefore we return, we want to set the flags to see if we are at the END OF LINE (i.e., 00H), so do an OR A to set the Z FLAG.
5135RETRETurn to the caller.
5136H – Continuation of “COMPRESS” routine. Jumped to when it is time to clean up the linked addresses and then exit.
LD DE,(40A4H)Fetch the 2 byte RAM location for the beginning of the BASIC Program from 40A4H into Register Pair DE.
513CLD A,(HL)Fetch a byte of the BASIC program (held in the memory location pointed to by Register Pair HL) and store it into Register A. This byte should be a LINKED ADDRESS.
513DINC HLINCrement the pointer to the BASIC program (held in Register Pair HL) by 1.
513EOR (HL)Test to see if the next character is 00H by OR’ing Register A against the value of the next character in the program. If that next character was 00H then Register A will be unchanged, and the Z Flag will be set.
5141
5142
5143INC HL
INC HL
INC HLBump past the 3 characters for a line number by INCrementing the pointer to the BASIC program (held in Register Pair HL) by 3.
LD A,(HL)Top of a 4 instruction loop. Fetch a byte of the BASIC program (held in the memory location pointed to by Register Pair HL) and store it into Register A.
5145INC HLINCrement the pointer to the BASIC program (held in Register Pair HL) by 1.
5146OR ACheck to see if that prior byte (held in A) is an END OF LINE (i.e., 00H), and if NOT …
5149EX DE,HLAt this point, we are at the END OF A LINE and HL holds the byte after the END OF LINE BYTE. Put the LINKED ADDRESS into Register Pair DE.
514ALD (HL),EStore the LSB of the LINKED ADDRESS held in Register E into the memory location pointed to by Register Pair HL.
514BINC HLINCrement the value stored in Register Pair HL by 1.
514CLD (HL),DStore the MSB of the LINKED ADDRESS held in Register D into the memory location pointed to by Register Pair HL.
514DJR LDHEAD
[513AH]LOOP BACK to the 2nd line of this routine (513AH) to cycle through the entire BASIC program.
514FH – Continuation of “COMPRESS” routine. We are done so set the RAM Pointers to the new End of Program and then EXIT to BASIC.
“CLEARY”
514FLD HL,(40F9H)Fetch the value held in memory location 40F9H and store it into Register Pair HL. 40F9H is commonly used to determine the location of the end of a BASIC program in RAM as it holds the starting address of the simple variables list table which is also one higher than the last of the three zero bytes marking the end of the BASIC program.
5152LD (40FBH),HLStore the END OF BASIC PROGRAM + 1 (held in Register Pair HL) into memory location 40FBH, which is the starting address of the ARRAY VARIABLE TABLE.
5155LD (40FDH),HLStore the END OF BASIC PROGRAM + 1 (held in Register Pair HL) into memory location 40FDH, which is the ending address of the ARRAY VARIABLE TABLE (a/k/a start of free memory pointer).
5158RETRETurn to BASIC.
5159H – Subroutine in the COMPRESS” routine. This routine moves the BASIC program down starting at (HL) into (BC).
515ALD DE,(40F9H)Fetch the END OF BASIC PROGRAM pointer from memory location 40F9H and store it into Register Pair DE.
515EEX DE,HLSince DE will always be bigger than HL, and the Z-80 does not have an instruction to subtract against DE, swap them.
515FOR AThe CARRY FLAG will be important here so clear the CARRY FLAG.
5160SBC HL,DECalculate the number of bytes to move by SUBtracting DE from HL.
The next instructions move all the variables around so that they fit into the LDIR mold.
5162EX (SP),HLEXchange the value stored in Register Pair HL (i.e., the number of bytes to move) with the value stored at the top of the stack (i.e., the MOVE FROM address).
5163
5164PUSH BC
POP DECopy the “move to” address (held in Register Pair BC) to Register Pair DE.
5165POP BCPut the the number of bytes to move ( held at the top of the STACK) into Register Pair BC, and then remove the entry from the stack.
5166LDIRTransfers a byte of data from the memory location pointed to by HL to the memory location pointed to by DE. Then HL and DE are incremented and BC is decremented. If BC is not zero, this operation is repeated. Interrupts can trigger while this instruction is processing.
5168LD (40F9H),HLSet the END OF BASIC PROGRAM pointer in RAM to the end of the code we just moved (held in Register Pair HL).
516BRETRETurn to the caller.
516CH – – Continuation of “COMPRESS” – Jump Table Point for CLEAR SPACES processing. Routine will clear out SPACES and TABS except inside QUOTES and FIELD statements.
LD HL,(BUFPNT)Fetch the location in the BASIC program to process (held in memory location 51AEH) and store it into Register Pair HL.
516FLD A,(HL)Fetch a byte of the BASIC program (held in the memory location pointed to by Register Pair HL) and store it into Register A.
5170INC HLINCrement the value stored in Register Pair HL by 1 to point to the character after the one we just fetched into Register A.
5171OR (HL)Test to see if the next character is 00H by OR’ing Register A against the value of the next character in the program. If that next character was 00H then Register A will be unchanged, and the Z Flag will be set.
5172JP Z,DOCLN
[5136H]If the Z FLAG (Zero) has been set, we are at the end of the program so clean up (and return to BASIC) via a JUMP to 5136H.
5175LD DE,0003HWe want to skip over the 3 bytes of a line number and space so set Register Pair DE = 0003H.
5178ADD HL,DEAdvance our BASIC Pointer by 3 by setting Register Pair HL = Register Pair HL + Register DE.
LD A,(HL)Top of a Loop. Fetch a byte of the BASIC program (held in the memory location pointed to by Register Pair HL) and store it into Register A.
517AINC HLINCrement the value stored in Register Pair HL by 1 to point to the character after the one we just fetched into Register A.
517BOR ASet FLAGS based on the contents of Register A.
517ELD (BUFPNT),HLSave our current poition as the new line pointer in memory location 51AEH.
5181JR SPACES
[516CH]LOOP BACK to the top of this routine (516CH) to keep processing via the next line.
5183H – Continuation of CLEAR SPACES subroutine of the “COMPRESS” routine. Jumped to if we are past the line number + space and NOT at end of line.
5185CP 22HCompare the current character in the BASIC program (held in Register A) against 22H (ASCII: “). If it is a “ …
5187JR Z,DOSKIP
[518FH]… skip over processing it via a JUMP to 518FH because we aren’t removing spaces from quoted text.
5189LD B,3AHLet Register B equal :.
518BCP 0A3HCompare the value held in Register A against 0A3H (BASIC Token: FIELD). If the character of the BASIC program was not a FIELD token …
We are here either because we jumped here from 5187 because we are inside a quote, or because we passed through and we hit a FIELD token. Either way, we want to skip over deleting the spaces.
5192JR NC,SPACE1
[5179H]If the NC FLAG (No Carry) has been set by that routine, then we are NOT at the END OF LINE, so LOOP BACK to 5179H to keep processing.
5194LD (BUFPNT),HLIf we’re here then that routine indicated we are at the end of a line, so save our current position as the new line pointer in memory location 51AEH.
5199H – Continuation of CLEAR SPACES subroutine of the “COMPRESS” routine. Jumped here if we know that we are not within a QUOTE or in a FIELD statement.
CP 20HCompare the value held in Register A against 20H (ASCII: SPACE). If we are at a SPACE) …
519DCP 09HCompare the value held in Register A against 09H (ASCII: TAB). If we are NOT at a TAB) …
Actually elimiate the TAB or SPACE character.
51A2LD B,H
LD C,LLet BC = HL so that BC also points to the character being deleted.
51A4CALL SKIPSP
[5129H]Skip over spaces and tabs via a GOSUB to 5129H which will adjust HL to point to the first non-space and non-tab character (and set the Z flag if we are at the END OF LINE). BC is not modified by that routine.
51A7PUSH BCSave the pointer to the character being deleted (held in Register Pair BC) to the top of the stack.
51ABPOP HLRestore the pointer to the character being deleted from the top of the STACK into Register Pair HL, and then remove the entry from the stack.
51AEH – “COMPRESS” routine MESSAGE and BYTE storage area.
“BUFPNT”
51AEDEFS 02
“TEMPX”
51B0DEFS 02
END 4E00HThat’s it!
This routine will remove all REMarks from a BASIC program. If REM is the first token on a line, the comment is removed but the REM stays (as there may be GOTOs to those lines). Otherwise, the :, the REM, and the comment are all struck.
50BA
[5136H]
[50BAH]
50D3H – Continuation of “COMPRESS” routine processing REMarks. Jumped here if we are not at the end of the line and still need to process it.
50E5H – Continuation of “COMPRESS” routine processing REMarks. See if the REMark is at the beginning of the line or not.
[50FCH]
50F4H – Continuation of “COMPRESS” routine processing REMarks; deal with whatever followed the REM token.
DEC HL
The next instructions move us to the end of the line.
[510CH]
510CH – Continuation of “COMPRESS” routine processing REMarks; deal with the end of line.
511DH – Continuation of “COMPRESS” routine processing REMarks. Subroutine to skip over a QUOTE mark.
[5124H]
5124H – Continuation of “COMPRESS” routine processing REMarks. Continuation of the subroutine to skip over a QUOTE mark if we are NOT at the end of line.
[511DH]
5129H – Continuation of “COMPRESS” routine, but called later in the program. This subroutine skips space and tabs.
5136H – Continuation of “COMPRESS” routine. Jumped to when it is time to clean up the linked addresses and then exit.
5142
5143
INC HL
INC HL
[513AH]
514FH – Continuation of “COMPRESS” routine. We are done so set the RAM Pointers to the new End of Program and then EXIT to BASIC.
514F
5159H – Subroutine in the COMPRESS” routine. This routine moves the BASIC program down starting at (HL) into (BC).
The next instructions move all the variables around so that they fit into the LDIR mold.
5164
POP DE
516CH – – Continuation of “COMPRESS” – Jump Table Point for CLEAR SPACES processing. Routine will clear out SPACES and TABS except inside QUOTES and FIELD statements.
[5136H]
[516CH]
5183H – Continuation of CLEAR SPACES subroutine of the “COMPRESS” routine. Jumped to if we are past the line number + space and NOT at end of line.
[518FH]
We are here either because we jumped here from 5187 because we are inside a quote, or because we passed through and we hit a FIELD token. Either way, we want to skip over deleting the spaces.
[5179H]
5199H – Continuation of CLEAR SPACES subroutine of the “COMPRESS” routine. Jumped here if we know that we are not within a QUOTE or in a FIELD statement.
Actually elimiate the TAB or SPACE character.
LD C,L
[5129H]
51AEH – “COMPRESS” routine MESSAGE and BYTE storage area.
51AE
51B0