1001H-1002H
Jump if leading * aren’t to be included in the ASCII string.
1003H
LD A,B
Load register A with the character at the location of the input buffer pointer in register B.
1004H
CP C
Check to see if the character at the location of the input buffer pointer in register A is a space.
1005H-1006H
LD C,2AH
Load register C with an * character.
1007H-1008H
Skip the next opcode (which loads B with a *, if the character at the location of the input buffer pointer in register A isn’t a space.
1009H
LD B,C
Load register B with the * character in register C.
l00AH
LD (HL),C
Save the * character in register C at the location of the input buffer pointer in register pair HL.
100BH
RST 10H
Since we need to bump the current input buffer pointer in register pair HL until it points to the next character, 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.
100CH-100DH
Jump down to 1022H if the character at the location of the input buffer pointer in register pair HL is the end of the input buffer character (00H).
100EH-100FH
CP 45H
Check to see if the character at the location of the input buffer pointer in register A is an E.
1010H-1011H
Jump down to 1022H if the character at the location of the input buffer pointer in register A is an E.
1012H-1013H
CP 44H
Check to see if the character at the location of the input buffer pointer in register A is a D.
1014H-1015H
Jump down to 1022H if the character at the location of the input buffer pointer in register A is a D.
1016H-1017H
CP 30H
Check to see if the character at the location of the input buffer pointer in register A is a 0.
1018H-1019H
Jump back to 100AH if the character at the location of the input buffer pointer in register A is a 0.
101AH-101BH
CP 2CH
Check to see if the character at the location of the input buffer pointer in register A is a ,.
101CH-101DH
Jump back to 100AH if the character at the location of the input buffer pointer in register A is a ,.
101EH-101FH
CP 2EH
Check to see if the character at the location of the input buffer pointer in register A is a ..
1020H-1021H
Jump down to 1025H if the character at the location of the input buffer pointer in register A isn’t a ..
1022H
DEC HL
Now we know we have an E, D, 0, ,, or . so we need to backspace it out by decrementing the value of the input buffer pointer in register pair HL.
1023H-1024H
LD (HL),30H
Save a zero character (0) at the location of the input buffer pointer in register pair HL.
1025H
LD A,E
Load register A with the value of the edit flag in register E.
1026H-1027H
AND 10H
Check to see if a $ is to be included in the ASCII string.
1028H-1029H
Skip the next 2 instructions (which put in a $) if a $ isn’t to be included in the ASCII string.
102AH
DEC HL
Need to add a “$”, so first we decrement the value of the input buffer pointer in register pair HL …
102BH-102CH
LD (HL),24H
… and then put a $ there.
102DH
LD A,E
Load register A with the value of the input flag in register E.
102EH-102FH
AND 04H
Check to see if the sign is to follow the ASCII string.
1030H
RET NZ
Return if the sign isn’t to follow the ASCII string.
1031H
DEC HL
Decrement the value of the input buffer pointer in register pair HL.
1032H
LD (HL),B
Save the character in register B at the location of the input buffer pointer in register pair HL.
1033H
RET
Return.

1034H-1036H
LD (40D8H),A
Save the value of the edit flag (stored at 40D8H) in register A.
Note: 40D8H-40D9H holds the temporary storage location.
1037H-1039H
LD HL,4130H
Load register pair HL with the starting address of the input buffer (which is 4130H).
Note: 4130H-4149H holds Internal print buffer.
103AH-103BH
LD (HL),20H
Save a space at the location of the input buffer pointer in register pair HL.
103CH
RET
Return.

103DH-103EH
CP 05H
Set the Carry flag according to whether the current value in REG 1 is single precision or double precision (Carry set if double precision).
103FH
PUSH HL
Save the value in register pair HL to the stack.
1040H-1041H
SBC A,00H
Adjust the value of the number type in register A. It will be 04H if SINGLE PRECISION and it will be 08H if DOUBLE precision.
1042H
RLA
Multiply the value of the number type in register A by two, so now A will be 08H if SINGLE precision and 0AH if DOUBLE precision.
1043H
LD D,A
Load register D with the adjusted value of the number type in register A.
1044H
INC D
Bump the value of the number type in register D (so D will be 09H if SINGLE precision and 0BH if DOUBLE precision).
1045H-1047H
Go scale the current value in REG 1 to be 99,999 <= X <= 999,999. Returns wihth A being the number of times the DOUBLE precision value was scaled up or down.
1048H-104AH
LD BC,0300H
Load register pair BC with a default value of 768.
104BH
ADD A,D
Add the value in register D to the value in register A.
104CH-104EH
Jump to 1057H if the number of digits in register A is too large (i.e., if scaled down more than 9 or 11 places).
104FH
INC D
Bump the value in register D (so D will be 0AH if SINGLE precision or 0CH if DOUBLE precision).
1050H
CP D
Check to see if the number of digits in register A is equal to the value in register D (meaning that the number wasn’t scaled at all).
1051H-1052H
If the number was scaled up or down (meaning that A and D are the same), jump to 1057H.
1053H
INC A
Now we know the number was scaled, so we must bump the number of digits in register A so that it holds the number of digits in the value.
1054H
LD B,A
Load register B with the number of digits in the value (stored in register A).
1055H-1056H
LD A,02H
Load register A with a two because the next step (which is a common code jump point) will force the exponent to be zero.
1057H-1058H
SUB A,02H
Compute the exponent value (which will be a zero if we were passing through).
1059H
POP HL
Get the value from the stack (the Program Buffer) and put it in register pair HL.
105AH
PUSH AF
Save the exponent value (currently in register pair AF) to the stack.
105BH-105DH
Go put a comma or decimal point in the input buffer if necessary.
105EH-105FH
LD (HL),30H
Save a 0 character at the location of the input buffer pointer in register pair HL.
1060H-1062H
If there was no scaling, GOSUB to 09C9H to bump the value of the input buffer pointer in register pair HL if necessary.
1063H-1065H
Go convert the binary value in REG 1 to ASCII, the result being stored in the input buffer pointer.
1066H
DEC HL
Backspace the last character by decrementing the value of the input buffer pointer in register pair HL.
1067H
LD A,(HL)
Load register A with the value at the location of the input buffer pointer in register pair HL (which is the previous character).
1068H-1069H
CP 30H
Check to see if the value in register A is a 0 (which is 30H).
106AH-106BH
Loop until the character at the location of the input buffer pointer in register pair HL is not a zero character.
106CH-106DH
CP 2EH
Check to see if the character at the location of the input buffer pointer in register A is a . (which is 2E).
106EH-1070H
If its NOT a decimal point, GOSUB to bump the value of the input buffer pointer in register pair HL.
1071H
POP AF
Get the value from the stack (i.e., the exponent) and put it in register pair HL.
1072H-10731
If the exponent is zero, jump to 1093H.
1074H
PUSH AF
Save the exponent (stored in AF) back to the stack.
1075H
RST 20H
We need to check the value of the current number type flag, so we call the TEST DATA MODE routine at RST 20H.
NOTE: The RST 20H routine determines the type of the current value in REG 1 and returns a combination of STATUS flags and unique numeric values in the A Register according to the data mode flag (40AFH).

The results are returned as follows:
  • Integer = NZ/C/M/E and A is -1
  • String = Z/C/P/E and A is 0
  • Single Precision = NZ/C/P/O and A is 1
  • and Double Precision is NZ/NC/P/E and A is 5.
1076H-1077H
LD A,22H
Load register A with the starting value for a D or E character.
1078H
ADC A,A
Multiply the value of the character in register A by two and add in the value of the Carry flag from the number type flag test. This will result with A it being a D if the value is SINGLE precision and an E if the value is DOUBLE precision.
1079H
LD (HL),A
Save the exponent designation (the D or E in register A) at the location of the input buffer pointer in register pair HL.
107AH
INC HL
Bump the value of the input buffer pointer in register pair HL, which is the first position of the exponent in the buffer.
107BH
POP AF
Get the value of the exponent from the stack and put it in register A.
107CH-107DH
LD (HL),2BH
Save a + (=2BH) at the location of the input buffer pointer in register pair HL.
107EH-1080H
Skip the next 3 instructions (by jumping to 1085H) if the exponent is positive.
1081H-1082H
LD (HL),2DH
Save a - (which is 2DH) at the location of the input buffer pointer in register pair HL.
1083H
CPL
Convert the negative exponent to positive by reversing the value of the exponent in register A and …
1084H
INC A
… bumping the value of the exponent in register A.
1085H-1086H
LD B,2FH
At this point, the exponent is positive. Next step is to load register B with a 0 minus one (which is a /).
1087H
INC B
Bump the value of the ASCII character in register B (so now it is an 0). This is the start of a 3 Opcode routine to divide by 10 using compound subtraction.
1088H-1089H
SUB A,0AH
Subtract ten from the value of the exponent in register A.
108AH-108BH
Loop until the value of the exponent in register A is less than ten. B holds the quotient (e.g., the number of times the subtraction had to occur to get to a remainder less than 10).
108CH-108DH
ADD A,3AH
Since A is holding the remainder of the ‘divide-by-10’ routine above, add 3AH to it so that it will be an ASCII digit.
108EH
INC HL
Bump the value of the input buffer pointer in register pair HL.
108FH
LD (HL),B
Save the ASCII character in register B (which is the first digit of the exponent in ASCII) at the location of the input buffer pointer in register pair HL.
1090H
INC HL
Bump the value of the input buffer pointer in register pair HL.
1091H
LD (HL),A
Save the value of the ASCII character in register A (which is the second digit of the exponent in ASCII) at the location of the input buffer pointer in register pair HL.
1092H
INC HL
Bump the value of the input buffer pointer in register pair HL.
1093H-1094H
LD (HL),00H
Save an end of the ASCII string character (designated as 00H) at the location of the input buffer pointer in register pair HL.
1095H
EX DE,HL
Load register pair DE with the ending address of the input buffer pointer.
1096H-1098H
LD HL,4130H
Load register pair HL with the starting address of the input buffer pointer.
Note: 4130H-4149H holds Internal print buffer.
1099H
RET
Return.

109AH
INC HL
Bump the value of the input buffer pointer in register pair HL.
109BH
PUSH BC
Save the value in register pair BC to the stack (currently B has the number of #‘s before the current vale of the input buffer pointer and C has the number of #’s after).
109CH-109DH
CP 04H
Check to see if the current number type in REG 1 is single or double precision .
109EH
LD A,D
Load register A with the value of the edit flag in register D.
109FH-10A1H
Jump to 1109H if the current value in REG 1 is either single precision or double precision .
10A2H
RRA
Put the value of the exponential notation flag into the Carry flag.
10A3H-10A5H
Jump to 11A3H if exponential notation is requested.
Alternative interpretation is Jump to 11A3H if the variable is a string; which will leave us now with only an integer value.

10A6H – This is where the PRINT USING routine will edit for INTEGER values.

10A6H-10A8H
LD BC,0603H
Load register pair BC with a default value of 0603H (so that B has the number of leading digits and C has the comma counter).
10A9H-10ABH
Go check to see if commas are requested. If no comma is requrest, set C to zero.
10ACH
POP DE
Get the value from the stack and put it in register pair DE. This will put the number of #’s to the left of the decimal point into D.
10ADH
LD A,D
Load register A with the number of digits requested to the left of the decimal point in register D.
10AEH-10AFH
SUB A,05H
Since the maximim number of digits allowed for an integer to the left of the decimal point is 5, subtract 5 from the number of digits to the left of the decimal point requested.
10B0H-10B2H
Go put leading zeros into the input buffer if the number of digits to the left of the decimal point requested is greater than the number of digits to the left of the decimal point for the maximum length of an integer value (meaning, the POSITIVE flag has been set).
10B3H-10B5H
Call the INTEGER TO ASCII routine at 1232F (which converts the integer in REG 1 to ASCII and stores the ASCII string in the buffer pointed to in HL).
10B6H
LD A,E
Load register A with the number of digits to the right of the decimal point requested (which is stored in register E).
10B7H
OR A
Check to see if there are any digits to the right of the decimal point requested and set the status flags accordingly.
10B8H-10BAH
Go decrement the value of the input buffer pointer in register pair HL if there are no digits to the right of the decimal point requested.
10BBH
DEC A
Decrement the number of digits to the right of the decimal point in register A. This tests to see if no count was given.
10BCH-10BEH
If the POSITIVE flag is set, gosub to 1269H to add trailing zeros to the ASCII string if necessary.
10BFH
PUSH HL
Save the current input buffer pointer (stored in register pair HL) to the stack.
10C0H-10C2H
Go edit the ASCII string in the input buffer.
10C3H
POP HL
Get the saved input buffer pointer value from the stack and put it in register pair HL.
10C4H-10C5H
Jump to 10C8H if the sign follows the ASCII string.
10C6H
LD (HL),B
So now we know a sign does not follow the value so we save the character in register B (which should be a space) at the location of the input buffer pointer in register pair HL.
10C7H
INC HL
Bump the value of the input buffer pointer in register pair HL
10C8H-10C9H
LD (HL),00H
Terminate the buffer by saving an end of the ASCII string character (=00H) at the location of the input buffer pointer in register pair HL.
10CAH-10CCH
LD HL,412FH
Load register pair HL with the starting address of the input buffer pointer (which is 412FH) minus 1 (because the first instruction of the following common code is add 1 to HL).
10CDH
INC HL
Bump the value of the input buffer pointer in register pair HL.
10CEH-10D0H
LD A,(40F3H)
Load register A with the LSB of the address of the decimal point for the ASCII string.
Note: 40F3H-40F4H holds the temporary storage location.
10D1H
SUB A,L
Subtract the LSB of the input buffer pointer address in register L from the value in register A.
10D2H
SUB A,D
Subtract the number of digits to the left of the decimal point in register D from the adjusted value in register A.
10D3H
RET Z
Return if the input buffer pointer in register pair HL points to the start of the ASCII string.
10D4H
LD A,(HL)
So now we know we are not at the start of the field, so we fetch the character at the location of the input buffer pointer in register pair HL into Register A.
10D5H-10D6H
CP 20H
Check to see if the character at the location of the input buffer pointer in register A is a space (which is a blank).
10D7H-10D8H
Jump back to 10CDH if the character at the location of the input buffer pointer in register pair HL is a space so that we keep looking until we are either at the start of the field, or a “+”, “-“, or “$” is found.
10D9H-10DAH
CP 2AH
Check to see if the character at the location of the input buffer pointer in register A is a *.
10DDH
DEC HL
Since we want to ignore “*”‘s decrement the value of the input buffer pointer in register pair HL so it will get re-tested.
10DEH
PUSH HL
Save the value of the input buffer pointer in register pair HL to the stack.
10DFH
PUSH AF
Save the value in register pair AF (which is the current character) to the stack.
10E0H-10E2H
LD BC,10DFH
Load register pair BC with the return address for use in case we have a -, a +, or a $.
10E3H
PUSH BC
Save the return address in register pair BC to the stack.
10E4H
RST 10H
Since we need to bump the current input buffer pointer in register pair HL until it points to the next character, 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.
10E5H-10E6H
CP 2DH
Check to see if the character at the location of the input buffer pointer in register A is a -.
10E7H
RET Z
Return (to 10DFH) if the character at the location of the input buffer pointer in register A is a -.
10E8H-10E9H
CP 2BH
Check to see if the character at the location of the input buffer pointer in register A is a +.
10EAH
RET Z
Return (to 10DFH) if the character at the location of the input buffer pointer in register A is a +.
10EBH-10ECH
CP 24H
Check to see if the character at the location of the input buffer pointer in register A is a $.
10EDH
RET Z
Return (to 10DFH) if the character at the location of the input buffer pointer in register A is a $.
10EEH
POP BC
We don’t need a shortcut to jump to 10DFH anymore, so let’s get the real return address from the stack and put it in register pair BC.
10EFH-10F0H
CP 30H
Check to see if the character at the location of the input buffer pointer in register A is a 0.
10F1H-10F2H
Jump to 1102H if the character at the location of the input buffer pointer in register A isn’t a 0.
10F3H
INC HL
Bump the value of the input buffer pointer in register pair HL so that we skip to the next character.
10F4H
RST 10H
Since we need to bump the current input buffer pointer in register pair HL until it points to the next character, 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.
10F5H-10F6H
Jump to 1102H if the character at the location of the input buffer pointer in register A isn’t a numeric character.
10F7H
DEC HL
Decrement the value of the input buffer pointer in register pair HL to backspace to the last character examined.
10F8H
01 2B 77
Z-80 Trick! The byte at this memory location, 01H, is there to turn the real instruction that follows in 10F9H into a harmless LD BC,xxxx. This way, if you are processing straight down in order, it skips the next command at 10F9H (in this case a DEC HL) because it wasn’t a command, it was a hex number to be loaded into BC! Instead, if you jump to 10F9H, you skip this byte and it is an DEC HL.
10F9H
DEC HL
Decrement the value of the input buffer pointer in register pair HL (we needed that Z-80 trick to avoid a double backspace in passing through).
10FAH
LD (HL),A
Save the character in register A at the location of the input buffer pointer in register pair HL.
10FBH
POP AF
Get the value from the stack and put it in register pair AF.
10FCH-10FDH
Loop until the end of the field is reached (by finding a 00H).
10FEH
POP BC
Clear the stack.
10FFH-1101H
Jump back to 10CEH to restart the scan.
1102H
POP AF
Restore the character at the start of the field from the stack and put it in register pair AF.
1103H-1104H
Loop until the beginning of the field is found.
1105H
POP HL
Get the starting address of the field from the stack and put it in register pair HL.
1106H-1107H
LD (HL),25H
Save a % character at the location of the input buffer pointer in register pair HL (which is the starting address).
1108H
RET
Return.

1109H – This is where the PRINT USING routine will edit for FLOATING POINT values.

1109H
PUSH HL
Save the current input buffer pointer in register pair HL to the stack.
110AH
RRA
Test bit 0 of the edit flags to see if exponential notation is requested by the edit flag in register A.
110BH-110DH
JP C,11AAH
Jump to 11AAH if exponential notation is requested by the edit flag in register A on a floating point number.
110EH-110FH
Jump to 1124H if the current value in REG 1 is single precision.
1110H-1112H
LD DE,1384H
Load register pair DE with the address of the DOUBLE PRECISION value to be compared to the current value in REG 1. Register pair DE points to a double precision constant equal to 1el6.
1113H-1115H
Go compare the double precision constant pointed to by register pair DE (which is 1el6) to the double precision value in REG 1.
1116H-1117H
LD D,10H
Load register D with the maximum length of a double precision value (which is 16).
1118H-111AH
Jump to 1132H if the double precision value in REG 1 is less than or equal to 1el6.
111BH
POP HL
So now we know the double precision value in REG 1 exceeds 1×10^16. Get the current input buffer pointer from the stack and put it in register pair HL.
111CH
POP BC
Get the value from the stack and put it in register pair BC, resulting in B containing the number of #‘s before and C containing the number of #‘s after.
111DH-111FH
Go convert the double precision value in REG 1 to an ASCII string. The goal is to reenter the edit routine until the double precision value is less than 1×10^16.
1120H
DEC HL
Decrement the input buffer pointer in register pair HL to get it back to the current position.
1121H-1122H
LD (HL),25H
Save a % character at the location of the input buffer pointer in register pair HL.
1123H
RET
Return.

1124H-1126H
LD BC,B60EH
Load register pair BC with the exponent and the MSB of a single precision constant.
1127H-1129H
LD DE,1BCAH
Load register pair DE with the NMSB and the LSB of a single precision constant. Register pairs BC and DE now hold a single precision constant equal to 1×10^16.
112AH-112CH
Call the SINGLE PRECISION COMPARISON routine at 0A0CH.

NOTE: The routine at 0A0CH algebraically compares the single precision value in BC/DE to the single precision value REG 1.
The results are stored in A as follows:
  • A=0 if REG 1 = BCDE
  • A=1 if REG 1>BCDE; and
  • A=FFH if REG 1<BCDE.
112DH-112FH
Jump to 111BH if the the POSITIVE flag is set (meaning the single precision value in REG 1 is greater than 1×10^16).
1130H-1131H
LD D,06H
Now we know that the SINGLE precision value in REG 1 is less than 1×10^16. Load register D with the maximum length of a single precision value (which is 6).
1132H-1134H
Go check the sign of the value in REG 1.
1135H-1137H
GOSUB to 1201H to adjust the current value of REG 1 so that the single precision value is 99,999 < X < 999,999. On the return from that GOSUB, A will equal the number of times the value was scaled up or down as a + or -.
1138H
POP HL
Get the origin of the ASCII buffer from the stack and put it in register pair HL.
1139H
POP BC
Get the value from the stack and put it in register pair BC, resulting in B containing the number of #‘s before and C containing the number of #‘s after.
113AH-113CH
Jump forward to 1157H if the value in REG 1 had to be scaled up (multiplied by 10) to get it in range.
113DH
PUSH BC
Save the value in register pair BC (B was the number of #‘s before and C is the number of #‘s after) to the stack.
113EH
LD E,A
Load register E with the number of times the current value in REG 1 was divided.
113FH
LD A,B
Load register A with the number of digits before the decimal point requested.
1140H
SUB A,D
Subtract the maximum length for the current number type in register D (which is 6) from the number of digits requested in register A.
1141H
SUB A,E
Subtract the number of times the current value in REG 1 was divided in register E from the adjusted value in register A.
1142H-1144H
If the POSITIVE flag is set, gosub to 1269H to put leading zeros into the input buffer if necessary.
1145H-1147H
Go figure the comma count and the position of the decimal point.
1148H-114AH
Go convert the integer portion of the current value in REG 1 to an ASCII string.
114BH
OR E
Check to see if there are any trailing zeros needed by testing the number of times the value was scaled.
114CH-114EH
Go put trailing zeros into the input buffer if necessary.
114FH
OR E
Check to see if commas or the decimal point is needed.
1150H-1152H
Go put commas and the decimal point into the input buffer if necessary.
1153H
POP DE
Get the edit counts value from the stack and put it in register pair DE.
1154H-1156H
Jump to 10B6H to convert the fractional portion fo the number to ASCII.
1157H
LD E,A
Load register E with the number of times the current value in REG 1 was scaled (multiplied by 10).
1158H
LD A,C
Load register A with the number of digits requested to the right of the decimal point.
1159H
OR A
Check to see if any digits to the right of the decimal point was requested.
115AH-115CH
Go decrement the number of digits requested to the right of the decimal point if necessary.
115DH
ADD A,E
Add the number of times the current value was multiplied in register E to the number of digits to the right of the decimal point requested in register A.
115EH-1160H
Jump if the value in REG 1 must be scaled down.
1161H
XOR A
Zero register A and indicate that there is on scaling down needed.
1162H
PUSH BC
Save the value in register pair BC (B was the number of #‘s before and C is the number of #‘s after) to the stack.
1163H
PUSH AF
Save the value in register pair AF (the scale count) to the stack.
1164H-1166H
GOSUB to 0F18H to divide the value in REG 1 by ten, A times, if necessary.
1167H-1169H
Loop until the value in REG 1 is properly adjusted. When this is done, A will hold the number of times it was divided by 10.
116AH
POP BC
Get the original scale count from the stack and put it in register pair BC.
116BH
LD A,E
Load register A with the number of times the value in REG 1 was multiplied in register E.
116CH
SUB A,B
Subtract the value in register B from the value in register A.
116DH
POP BC
Get the before/after value from the stack and put it in register pair BC.
116EH
LD E,A
Load register E with the adjusted scale factor value in register A.
116FH
ADD A,D
Add the length of the maximum size for the current value in register D to the adjusted scale factor value in register A. This will set the sign flag.
1170H
LD A,B
Load register A with the number of #‘s before (stored in B).
1171H-1173H
Jump to 117FH if there are no digits to the left of the decimal point.
1174H
SUB A,D
We now know there are leading digits so, subtract the maximum length for the current value in register D (6 for SINGLE precision and 10 for DOUBLE precision) from the adjusted value in register A.
1175H
SUB A,E
Then, subtract the adjusted scale value in register E from the adjusted value in register A.
1176H-1178H
If that subtraction leads to a positive number, go put leading zeros into the input buffer.
1179H
PUSH BC
Save the value in register pair BC (B was the number of #‘s before and C is the number of #‘s after) to the stack.
117AH-117CH
GOSUB to set up BC for decimal point and comma counters.
117DH-117EH
Jump to 1190H to edit the numbers before the decimal point.
117FH-1181H
Go put leading zeros into the input buffer if necessary.
1182H
LD A,C
Load register A with the number of bytes requested to the right of the decimal point (in register C) because C is about to get wiped.
1183H-1185H
GOSUB to 1294H to put a decimal point into the input buffer.
1186H
LD C,A
Reload register C with the number of digits requested to the right of the decimal point in register A.
1187H
XOR A
Zero register A.
1188H
SUB A,D
Subtract the maximum length for the current value in register D from the value in register A.
1189H
SUB A,E
Subtract the value in register E from the adjusted value in register A.
118AH-118CH
GOSUB to put that many zeroes into the input buffer (if necessary).
118DH
PUSH BC
Save the value in register pair BC (B was the number of #‘s before and C is the number of #‘s after) to the stack.
118EH
LD B,A
Load register B with the value in register A (which is 0).
118FH
LD C,A
Load register C with the value in register A (which is 0).
1190H-1192H
GOSUB to 12A4H to convert the integer portion of the SINGLE precision value in REG 1 to an ASCII string.
1193H
POP BC
Get the number of #‘s before and number of #‘s after and put it back in register pair BC.
1194H
OR C
Check to see if there are any digits to the right of the decimal point requested and set the status accordingly.
1195H-1196H
Jump to 119AH if there are digits to the right of the decimal point requested.
1197H-1199H
LD HL,(40F3H)
Now we know that there are no digits to the right of the decimal point. Load register pair HL with the position of the decimal point (which is stored in 40F3H).
Note: 40F3H-40F4H holds the temporary storage location.
119AH
ADD A,E
Add the value in register E to the value in register A to get the number of digits before the decimal point.
119BH
DEC A
Decrement the adjusted value in register A.
119CH-119EH
If dropping A by 1 still results in a positive number, GOSUB 1269H to put that number of zeros into the input buffer.
119FH
LD D,B
Load register D with the number of digits to the left of the decimal point requested (from Register B).
11A0H-11A2H
Jump to 10BFH to edit the ASCII value.
11A3H
PUSH HL
Save the current position of the input buffer (in register pair HL) to the stack.
11A4H
PUSH DE
Save the edit flags (in register pair BC) to the stack.
11A5H-11A7H
GOSUB 0ACCH to convert the integer value in REG 1 to a SINGLE precision value.
11A8H
POP DE
Get the edit flags from the stack and put it in register pair DE.
11A9H
XOR A
Zero register A, clear the status flags.
11AAH-11ACH
Jump to 11B0H (using a Z-80 trick) to skip the next instruction if the current value in REG 1 is SINGLE precision.
11ADH-11AEH
LD E,10H
Load register E with the maximum length of a double precision value (which is 16).
11AFH
01 1E 06
Z-80 Trick! See the general explanation at 10F8H.
11B0H-11B1H
LD E,06H
Load register E with the maximum length of a single precision value (which is 6).
11B2H-11B4H
GOSUB 0955H to check the sign for the current value in REG 1.
11B5H
SCF
Set the Carry flag (to furce a jump at 11F3 on the first pass).
11B6H-11B8H
GOSUB to 1201H to scale the current value in REG 1 if its nonzero.
11B9H
POP HL
Get the input buffer position from the stack and put it in register pair HL.
11BAH
POP BC
Get the number of #‘s before and the number of #‘s after from the stack and put it in register pair BC.
11BBH
PUSH AF
Save the decimal point and the flag for test at 11F3H in register pair AF to the stack.
11BCH
LD A,C
Load register A with the number of digits to the right of the decimal point requested (stored in register C).
11BDH
OR A
Set the status so we can see if there are any digits to the right of the decimal point requested through a zero register.
11BEH
PUSH AF
Save the original trailing digit count (in register pair AF) to the stack.
11BFH-11C1H
If the trail count is not zero, then GOSUB to 0F16H to decrement the number of digits requested to the right of the decimal point in register A.
11C2H
ADD A,B
Add the number of digits requested for the left of the decimal point in register B to the number of digits requested to the right of the decimal point in register A.
11C3H
LD C,A
Load register C with the total digit count (held in register A).
11C4H
LD A,D
Load register A with the value of the edit flag in register D.
11C5H-11C6H
AND 04H
Check to see if the sign follows the ASCII string.
11C7H-11C8H
CP 01H
Set the Carry flag according to the sign following the ASCII string test (it will be No Carry if a sign follows).
11C9H
SBC A,A
Adjust register A so that it will reflect the sign following the ASCII string test (A will be 0 if there is no sign, and FEH otherwise).
11CAH
LD D,A
Load register D with the edit flag (from register A).
11CBH
ADD A,C
Add the value in register C to the value in register A so as to adjust the count of the digits to print if a sign follows.
11CCH
LD C,A
Load register C with the adjusted value in register A.
11CDH
SUB A,E
Subtract the value in register E from the adjusted value in register A so that A will now contain the number of times to divide by 10.
11CEH
PUSH AF
Save the divisor count (from register pair AF) to the stack.
11CFH
PUSH BC
Save the character count (from register pair BC) to the stack.
11D0H-11D2H
GOSUB 0F18H to divide the current value in REG 1 by ten, Register A number of times.
11D3H-11D5H
Loop back 1 instruction (divide by 10) until the division has been completed.
11D6H
POP BC
Get the counter of the #‘s from the stack and put it in register pair BC.
11D7H
POP AF
Get the division count from the stack and put it in register pair AF.
11D8H
PUSH BC
Save the value in register pair BC to the stack.
11D9H
PUSH AF
Save the value in register pair AF to the stack.
11DAH-11DCH
Jump to 11DEH if there are any trailing zeroes.
11DDH
XOR A
Zero register A and all status flags.
11DEH
CPL
Make the trailing zero count posivite by inverting the value in register A.
11DFH
INC A
Bump the value in register A so that it will be positive.
11E0H
ADD A,B
Add the number of digits requested to the left of the decimal point in register B to the adjusted value in register A.
11E1H
INC A
Bump the adjusted value in register A.
11E2H
ADD A,D
Add the value of the maximum length for the current number type in register D (6 for single precision, 16 fo double precision) to the adjusted value in register A.
11E3H
LD B,A
Copy Register A into Register B so that B holds the number of digits before the decimal point.
11E4H-11E5H
LD C,00H
Load register C with zero (so that there are no commas).
11E6H-11E8H
GOSUB to 12A4H to convert the current value in REG 1 to an ASCII string.
11E9H
POP AF
Get the number of #’s before from the stack and put it in register pair AF.
11EAH-11ECH
GOSUB 1271H to put zeros into the trailing input buffer.
11EDH
POP BC
Get the number of #’s before and the number of #‘s after from the stack and put it in register pair BC.
11EEH
POP AF
Get the count of numbers before the decimal point from the stack and put it in register pair AF.
11EFH-11F1H
GOSUB to 092FH to decrement the input buffer pointer in register pair HL if there are none.
11F2H
POP AF
Get the first time flag from the stack and put it in register pair AF.
11F3H-11F4H
Jump to 11F8H (to add the exponent) if the carry flag was set during the first pass.
11F5H
ADD A,E
Add the value in register E to the value in register A.
11F6H
SUB A,B
Subtract the number of digits to the left of the decimal point requested in register B from the adjusted value in register A.
11F7H
SUB A,D
Subtract the value in register D from the value in register A to get the size of the exponent.
11F8H
PUSH BC
Save the value in register pair BC to the stack.
11F9H-11FBH
GOSUB to 1074H to figure the value of the exponent for the current value in REG 1
11FCH
EX DE,HL
Load register pair HL with the value of the input buffer pointer in register pair DE.
11FDH
POP DE
Get the value from the stack and put it in register pair DE. Clear the stack.
11FEH-1200H
Jump to 10BFH to edit the ASCII value.

1201H – Test the magnitude of SP and DP numbers, and clear the times the value was scaled.

  • Scales so that the number lies between 99,999 and 999,999.
  • On exit, A = +(times value divided) or A=-(times value multiplied).
1201H
PUSH DE
Save the value in register pair DE to the stack.
1202H
XOR A
Zero register A and all the flags.
1203H
PUSH AF
Save the value in register pair AF to the stack.
1204H
RST 20H
We need to check the value of the current number type flag, so we call the TEST DATA MODE routine at RST 20H.
NOTE: The RST 20H routine determines the type of the current value in REG 1 and returns a combination of STATUS flags and unique numeric values in the A Register according to the data mode flag (40AFH).

The results are returned as follows:
  • Integer = NZ/C/M/E and A is -1
  • String = Z/C/P/E and A is 0
  • Single Precision = NZ/C/P/O and A is 1
  • and Double Precision is NZ/NC/P/E and A is 5.
1205H-1207H
If that test shows we have a SINGLE PRECISION number (through getting a Parity-Odd flag), jump to 1222H.
1208H-120AH
LD A,(4124H)
At this point we know we have a DOUBLE precision value. Load register A with the value of the exponent for the double precision value in REG 1.
120BH-120CH
CP 91H
Check to see if the double precision value in REG 1 uses more than 16 bits of precision for the integer portion of the double precision value.
120DH-120FH
JP NC,1222H
Jump to 1222H if the double precision value in REG 1 uses more than 16 bits of precision for its integer portion.
1210H-1212H
LD DE,1364H
Load register pair DE with the starting address for the double precision constant equal to 5.5x10e2.
1213H-1215H
LD HL,4127H
Load register pair HL with the starting address for REG2.
Note: 4127H-412EH holds REG 2.
1216H-1218H
GOSUB to 09D3H to move the double precision constant of 5.5x10e2 into REG2.
1219H-121BH
GOSUB to 0DA1H to call the DOUBLE PRECISION MULTIPLY routine at 0DA1H (which multiplies the double precision value in REG 1 by the value in REG 2. The product is left in REG 1).
121CH
POP AF
Get the number of times the DOUBLE precision value was multiplied to scale it up from the stack and put it in register pair AF.
121DH-121EH
SUB A,0AH
Subtract ten from the value in register A.
121FH
PUSH AF
Save the value in register pair AF to the stack.
1220H-1221H
Jump to 1208H so as to loop until the integer portion exceeds 2e16.
1222H-1224H
GOSUB to 124FH to compare the current value in REG 1 to 999999.5.
1225H
RST 20H
We need to check the value of the current number type flag, so we call the TEST DATA MODE routine at RST 20H.
NOTE: The RST 20H routine determines the type of the current value in REG 1 and returns a combination of STATUS flags and unique numeric values in the A Register according to the data mode flag (40AFH).

The results are returned as follows:
  • Integer = NZ/C/M/E and A is -1
  • String = Z/C/P/E and A is 0
  • Single Precision = NZ/C/P/O and A is 1
  • and Double Precision is NZ/NC/P/E and A is 5.
1226H-1228H
If that test shows we have a DOUBLE PRECISION or a STRING, jump to 1234H.
*1226H-1228H
In ROM 1.2 this is a big bug fix. Now if the shows we do NOT have a STRING, jump to 1233H
1229H-122BH
LD BC,9143H
Load register pair BC with the exponent and the MSB of a single precision constant.
122CH-122EH
LD DE,4FF9H
Load register pair DE with the NMSB and the LSB of a single precision constant. Register pairs BC and DE are now equal to a single precision constant of 99,999.945.
122FH-1231H
GOSUB to 0A0CH to call the SINGLE PRECISION COMPARISON routine at 0A0CH.

NOTE: The routine at 0A0CH algebraically compares the single precision value in BC/DE to the single precision value REG 1.
The results are stored in A as follows:
  • A=0 if REG 1 = BCDE
  • A=1 if REG 1>BCDE; and
  • A=FFH if REG 1<BCDE.
1232H-1233H
Jump down two instructions to 123AH to test the results of the comparison.
*1233H-1235H
LD DE,136CH
Load register pair DE with the starting address of a double precision constant equal to 9.9921El4.
1234H-1236H
LD DE,136CH
Load register pair DE with the starting address of a double precision constant equal to 9.9921El4.
1237H-1239H
Go compare the double precision constant pointed to by register pair DE to the double precision value in REG 1.
123AH-123CH
Jump to 124CH if the current value in REG 1 is greater than the constant compared to it (more than 5 digits in integer or less than 17 digits in DOUBLE precision).
123DH
POP AF
Get the value of the scaled counter from the stack and put it in register pair AF.
123EH-1240H
GOSUB to 0F0BH to multiply the current value in REG 1 by ten.
1241H
PUSH AF
Save the value in register pair AF to the stack. A is the negative of the number of times the value was multiplied.
1242H-1243H
Jump to 1225H to loop until it is between 999,999 and 99,999.
1244H
POP AF
Get the scaled count from the stack and put it in Register A.
1245H-12137H
GOSUB to 0F18H to divide the current value in REG 1 by ten.
12148H
PUSH AF
Save the value in register pair AF to the stack. A is the count of the number of times it was divided.
1249H-1214BH
GOSUB to 124FH to loop until the value in REG 1 is < 999,999.
124CH
POP AF
Get the value from the stack and put it in register pair AF. A = + times divided or – times multiplied.
124DH
POP DE
Get the value from the stack and put it in register pair DE.
*124DH
OR A
In ROM v1.2 sets the status flags. This also realigns the memory addresses from changes to v1.2 ROM.
124EH
RET
Return.

124FH
RST 20H
We need to check the value of the current number type flag, so we call the TEST DATA MODE routine at RST 20H.
NOTE: The RST 20H routine determines the type of the current value in REG 1 and returns a combination of STATUS flags and unique numeric values in the A Register according to the data mode flag (40AFH).

The results are returned as follows:
  • Integer = NZ/C/M/E and A is -1
  • String = Z/C/P/E and A is 0
  • Single Precision = NZ/C/P/O and A is 1
  • and Double Precision is NZ/NC/P/E and A is 5.
1250H-1252H
If that test shows we have a DOUBLE PRECISION number, jump to 125EH.
1253H-1255H
LD BC,9474H
Now that we know we have a single precision number, load register pair BC with the exponent and the MSB of a single precision constant.
1256H-1258H
LD DE,23F8H
Load register pair DE with the NMSB and the LSB of a single precision constant. Register pairs BC and DE are now equal to a single precision constant of 999,999.5.
1259H-125BH
Call the SINGLE PRECISION COMPARISON routine at 0A0CH.

NOTE: The routine at 0A0CH algebraically compares the single precision value in BC/DE to the single precision value REG 1.
The results are stored in A as follows:
  • A=0 if REG 1 = BCDE
  • A=1 if REG 1>BCDE; and
  • A=FFH if REG 1<BCDE.
125CH-125DH
Jump to 1264H to test the result of the comparison.
125EH-1260H
LD DE,1374H
Load register pair DE with the starting address of a double precision constant equal to 1El6H.
1261H-1263H
GOSUB to 0A49H to compare the double precision constant pointed to by register pair DE to the double precision value in REG 1.
1264H
POP HL
Get the return address from the stack and put it in register pair HL so we can go to 1244H.
1265H-1267H
Jump to 1244H if the current value in REG 1 has more than 6 digits in the integer portion.
*1265H-1267H
In ROM v1.2 the ROM addresses had moved 1 byte.
1268H
JP (HL)
Jump to the caller (which was POPed from the stack).

1269H
OR A
Check to see if the value in register A is equal to zero.
126AH
RET Z
Return if the value in register A is equal to zero.
126BH
DEC A
Decrement the value in register A to show that an ASCII zero was moved to the print buffer.
126CH-126DH
LD (HL),30H
Save a 0 (which is 30H) at the location of the input buffer pointer in register pair HL.
126EH
INC HL
Bump the input buffer pointer in register pair HL.
126FH-1270H
Jump back to 126AH until the number in Register A of ASCII zeroes were moved.
1271H-1272H
Jump to 1277H if not done adding trailing zeroes.
1273H
RET Z
Return if done adding trailing zeroes.
1274H-1276H
Go put decimal point and commas into the input buffer.
1277H-1278H
LD (HL),30H
Save a zero character (which is 30H) at the location of the input buffer pointer in register pair HL.
1279H
INC HL
Bump the input buffer pointer in register pair HL.
127AH
DEC A
Decrement the counter of trailing zeroes to add in register A.
127BH-127CH
Jump back up to 1273H to RET.
127DH
LD A,E
Load register A with the value in register E so that A holds the count of the times the value was scaled up or down.
127EH
ADD A,D
Add the number of digits to print (from register D) to the value in register A.
127FH
INC A
Bump the adjusted value in register A so now A holds the number of digits before the decimal point.
1280H
LD B,A
Load register B with the leading digit count (from register A).
1281H
INC A
Bump the value in register A so not A holds the leading digits + 2.
1282H-1283H
SUB A,03H
Subtract three from the adjusted value in register A which, when combined with the next instruction as a loop, divides modulo 3.
1284H-1285H
Loop back 1 instruction until the value in register A is -1, -2, or -3.
1286H-1287H
ADD A,05H
Add 5 to A to get a positive remainder. This will give 4, 3, or 2 as the comma count.
1288H
LD C,A
Load register C with the comma count in register A.
1289H-128BH
LD A,(40D8H)
Load register A with the value of the edit flag (stored at 40D8H).
Note: 40D8H-40D9H holds the temporary storage location.
128CH-128DH
AND 40H
Isolate the comma bit in the edit flag word to see if commas are requested.
128EH
RET NZ
Return with C = Comma count if commas are requested.
128FH
LD C,A
Zero the comma counter in register C.
1290H
RET
Return.

1291H – Count the leading digits before the decimal point.

1291H
DEC B
Decrement the decimal point counter in register B to see if the zero flag sets or not.
1292H-1293H
Jump to 129CH if the decimal point position hasn’t been reached.
1294H-1295H
LD (HL),2EH
Save a decimal point at the location of the input buffer pointer in register pair HL.
1296H-1298H
LD (40F3H),HL
Save the address of the decimal point position (which is 16627) in register pair HL.
Note: 40F3H-40F4H holds the temporary storage location.
1299H
INC HL
Bump the input buffer pointer in register pair H to the first character of the fractional part of a numberL.
129AH
LD C,B
Zero the comma/decimal counter in register C (because B is zero since the above jump didn’t fire) to stop any more decimal points and commas.
129BH
RET
Return.

129CH
DEC C
Decrement the decimal/comma counter in register C.
129DH
RET NZ
Return if this location is not the end of a 3 character group (and so it doesn’t need a comma).
129EH-129FH
LD (HL),2CH
If didn’t jump out, then we need a comma here so put a comma (which is ASCII code 2CH) at the location of the input buffer pointer in register pair HL.
12A0H
INC HL
Bump the input buffer pointer (to account for the new comma) in register pair HL.
12A1H-12A2H
LD C,03H
Reset the comma counter by setting it to 3.
12A3H
RET
Return.

12A4H – Convert the INTEGER porton of a DOUBLE precision value to its ASCII equivalent.

12A4H
PUSH DE
Save the edit flags (stored in register pair DE) to the stack.
12A5H
RST 20H
We need to check the value of the current number type flag, so we call the TEST DATA MODE routine at RST 20H.
NOTE: The RST 20H routine determines the type of the current value in REG 1 and returns a combination of STATUS flags and unique numeric values in the A Register according to the data mode flag (40AFH).

The results are returned as follows:
  • Integer = NZ/C/M/E and A is -1
  • String = Z/C/P/E and A is 0
  • Single Precision = NZ/C/P/O and A is 1
  • and Double Precision is NZ/NC/P/E and A is 5.
12A6H-12A8H
Jump to 12EAH (which converts a SINGLE precision number into its INTEGER equivalent) if that test shows we have a SINGLE PRECISION number (by the Parity Odd flag being set).
12A9H
PUSH BC
Now that we know we have a DOUBLE PRECISION number, save leading digit count/comma count (in register pair BC) to the stack.
12AAH
PUSH HL
Save the input buffer address (in register pair HL) to the stack.
12ABH-12ADH
GOSUB to 09FCH to mmove the double precision value in REG 1 to REG2.
12AEH-12B0H
LD HL,137CH
Load register pair HL with the starting address of a double precision constant equal to 0.5.
12B1H-12B3H
GOSUB to 09F7H to move the double precision value pointed to by register pair HL to REG 1.
12B4H-12B6H
Call the DOUBLE PRECISION ADD function (which adds the double precision value in REG 2 to the value in REG 1 (which is the constant 0.5). Result is left in REG 1).
12B7H
XOR A
Zero register A and clear the status flags.
12B8H-12BAH
GOSUB to 0B7BH to adjust the double precision result in REG 1.
12BBH
POP HL
Get the input buffer address from the stack and put it in register pair HL.
12BCH
POP BC
Get the counters from the stack and put it in register pair BC.
12BDH-12BFH
LD DE,138CH
Load register pair DE with the starting address of a series of double precision constants (i.e., a table of powers of 10 from 1.0x10E15 – 1.0x10E6) for the binary to ASCII conversion.
12C0H-12C1H
LD A,0AH
Load register A with the number of times to divide the double precision value in REG 1 by a power of 10.
12C2H-12C4H
GOSUB to 1291H to add a decimal point or comma (as applicable) into the input buffer if necessary.
12C5H
PUSH BC
Save the count of digits before the decimal point and the count of digts after the decimal point (stored in register pair BC) to the stack.
12C6H
PUSH AF
Save the division count (stored in register pair AF) to the stack.
12C7H
PUSH HL
Save the current input buffer address (stored in register pair HL) to the stack.
12C8H
PUSH DE
Save the address of the power table (stored in register pair DE) to the stack.
12C9H-12CAH
LD B,2FH
Load register B (which will be the quotient in ASCII for each division) with the ASCII value for a zero character minus one.
12CBH
INC B
Bump the ASCII value for the digit in register B so as to start with ASCII “0”.
12CCH
POP HL
Get the address of the power table (i.e., the divisor) from the stack and put it in register pair HL and …
12CDH
PUSH HL
… put it right back into the stack so that it can be restored during the loop.
12CEH-12D0H
GOSUB to 0D48H to subtract the double precision value pointed to by register pair HL from the double precision value in REG l. This is to divide the current integer value by of a power of 10 starting at 10e15 working its way down to 10e6 in a loop until the remainder is less than the current power).
12D1H-12D2H
Jump back to do another subtraction and keep looping until the Carry flag gets set by the subtraction (meaning that the remainder is now less than the current power).
12D3H
POP HL
Get the address of the power table from the stack and put it in register pair HL.
12D4H-12D6H
GOSUB to 0D36H to add the double precision value pointed to by register pair HL (which is the table of powers of 10) to the double precision remainder in REG 1 to make it a positive value. Return with the correct remainder in REG 1.
12D7H
EX DE,HL
Load register pair DE with the starting address for the current power of 10 (stored in register pair HL).
12D8H
POP HL
Get the current input buffer address from the stack and put it in register pair HL.
12D9H
LD (HL),B
Save the ASCII value for the digit in register B at the location of the input buffer pointer (stored in register pair HL).
12DAH
INC HL
Bump the input buffer pointer in register pair HL since we have just put a digit there.
12DBH
POP AF
Get the status flags from the stack and put it in register pair AF so that we can test for 10 times.
12DCH
POP BC
Get the counts of digits before/after the decimal point value from the stack and put it in register pair BC.
12DDH
DEC A
Decrement the counter value in register A (we are going to loop 10 times).
12DEH-12DFH
Loop 10 times until the ASCII string has been figured.
12E0H
PUSH BC
Save the the counts of digits before/after the decimal point value (stored in register pair BC) to the stack.
12E1H
PUSH HL
Save the current input buffer pointer (stored in register pair HL) to the stack.
12E2H-12E4H
LD HL,411DH
Load register pair HL with the starting address for REG 1 (which holds the last half of the DOUBLE prevision value)
Note: 411DH-4124H holds REG l.
12E5H-12E7H
Call 09B1H (which moves a SINGLE PRECISION number pointed to by HL to REG 1).
12E8H-12E9H
Jump to 12F6H to convert that last half to ASCII.

12EAH – This routine is to convert a SINGLE precision value to an INTEGER.

  • Divide the integer equivalent by 100,000 and 10,000. Use the code at 1335H to convert the last 1000 to ASCII.
12EAH
PUSH BC
Save the leading digit count/comma count (in register pair BC) to the stack.
12EBH
PUSH HL
Save the current input buffer pointer (stored in register pair HL) to the stack.
12ECH-12EEH
GOSUB to 0708H to add a single precision value of 0.5 to the single precision value in REG 1. The result is stored in BC/DE.
12EFH
INC A
Bump the MSB.
12F0H-12F2H
GOSUB to 0AFBH to convert the positive single precision value in REG 1 to an integer. The result is stored in BC/DE.
12F3H-12F5H
GOSUB to 09B4H (which moves the SINGLE PRECISION value in DC/DE [which is the integer portion of the original single precision value] into REG 1).
12F6H
POP HL
Get the current input buffer pointer value from the stack and put it in register pair HL.
12F7H
POP BC
Get the leading digit count/comma count value from the stack and put it in register pair BC.
12F8H
XOR A
Zero register A.
12F9H-12FBH
LD DE,13D2H
Load register pair DE with the starting address for a series of integer values (in this case, 100,000).
12FCH
CCF
Complement the Carry flag. This is the first time switch for the division loop of 12FCH-1327H.
12FDH-12FFH
GOSUB to 1291H to put a decimal point or a comma into the input buffer if necessary .
1300H
PUSH BC
Save the counts of digits before/after the decimal point value (stored in register pair BC) to the stack.
1301H
PUSH AF
Save the carry flag for the count of the number of times through this loop (stored in register pair AF) to the stack.
1302H
PUSH HL
Save the current input buffer pointer value (stored in register pair HL) to the stack.
1303H
PUSH DE
Save the division table address (stored in register pair DE) to the stack.
1304H-1306H
GOSUB to 09BFH (which loads the SINGLE PRECISION value in REG 1 into register pair BC/DE).
1307H
POP HL
Get the division table address (the integer value for 100,000) from the stack and put it in register pair HL.
1308H-1309H
LD B,2FH
Load register B with the ASCII value for a zero character minus one.

130AH – This routine divides the integer portion of the current value by 100,000 using compound subtraction. The quotient is kept in Register B as an ASCII value.

130AH
INC B
Bump the ASCII value from the digit in register B to increase the ASCII value from 0 and upward.
130BH
LD A,E
Load register A with the LSB of the single precision value in register E.
130CH
SUB (HL)
Subtract the value at the location of the memory pointer in register pair HL (the LSB of 100,000) from the value of the LSB of the single precision value in register A.
130DH
LD E,A
Load register E with the adjusted LSB of the single precision value in register A.
130EH
INC HL
Bump the value of the memory pointer in register pair HL to the next digit of 100,000.
130FH
LD A,D
Load register A with the NMSB of the single precision value in register D.
1310H
SBC A,(HL)
Subtract the value at the location of the memory pointer in register pair HL (the middle byte of 100,000) from the value of the NMSB of the single precision value in register A.
1311H
LD D,A
Load register D with the adjusted NMSB of the single precision value in register A.
1312H
INC HL
Bump the value of the memory pointer in register pair HL to the MSB of 100,000.
1313H
LD A,C
Load register A with the MSB of the single precision value in register C.
1314H
SBC A,(HL)
Subtract the value at the location of the memory pointer in register pair HL from the value of the MSB of 100,000 (a single precision value in register A).
1315H
LD C,A
Load register C with the adjusted MSB of the single precision value in register A.
1316H
DEC HL
Decrement the value of the memory pointer in register pair HL to the NMSB of 100,000.
1317H
DEC HL
Decrement the value of the memory pointer in register pair HL again, now to the LSB of 100,000.
1318H-1319H
Loop until the ASCII value for the digit under 100,000 has been figured.
131AH-131CH
We need to add 100,000 to C/DE and make it positive so we GOSUB to 07B7H to add the value at the location of the memory pointer in register pair HL to the value in register pairs BC and DE.
131DH
INC HL
Bump the value of the memory pointer in register pair HL to now point to the 10,000 constant.
131EH-1320H
Save the remainder as a current value by GOSUB to 09B4H (which moves the SINGLE PRECISION value in DC/DE into REG 1).
1321H
EX DE,HL
Load register pair DE with the address of the next value to divide the current value in REG 1 by (which is the constant of 10,000).
1322H
POP HL
Get the value of the memory pointer from the stack and put it in register pair HL.
1323H
LD (HL),B
Save the ASCII value for the digit in register B at the location of the input buffer pointer in register pair HL.
1324H
INC HL
Bump the value of the input buffer pointer in register pair HL.
1325H
POP AF
Get the carry flag from the stack and put it in register pair AF.
1326H
POP BC
Get the value from the stack and put it in register pair BC so it can be saved later.
1327H-1328H
If the carry flag is set, then reset it and loop the dividing by 10,000 until the integer portion is found.
1329H
INC DE
If we fall through to here, we have divided the integer part of the single precision variable by 100,000 and then by 10,000 with the remainder being positive and saved as the current value. With this we bump the value of the memory pointer in register pair DE.
132AH
INC DE
and again bump the value of the memory pointer in register pair DE, so now DE points to the constant 1,000.
132BH-132CH
LD A,04H
Load register A with the number of digits for the ASCII string to be figured.
132DH-132EH
Jump to 1335H to convert the remainder to 4 ASCII digits.

132FH – This routine will convert an INTEGER to ASCII.

132FH
PUSH DE
Save the edit flags (stored in register pair DE) to the stack.
1330H-1332H
LD DE,13D8H
Load register pair DE with the starting address of the descending powers of 10 starting at 10,000.
1333H-1334H
LD A,05H
Load register A with the number of digits for the ASCII string to be built (i.e., 5).
1335H-1337H
Go put a decimal point or a comma into the input buffer if necessary.
1338H
PUSH BC
Save the counts of digits before/after the decimal point value (stored in register pair BC) to the stack.
1339H
PUSH AF
Save the number of digits counter (stored in register A) to the stack.
133AH
PUSH HL
Save the address of the power table (stored in register pair HL) to the stack.
133BH
EX DE,HL
Load register pair HL with the starting address of the descending powers of 10 starting at 10,000 (stored in register pair DE).
133CH
LD C,(HL)
Load register C with the LSB for the power of 10 stored in register pair HL.
133DH
INC HL
Bump the value of the memory pointer in register pair HL to be the MDB of the power of 10.
133EH
LD B,(HL)
Load register B with the MSB for the integer value at the location of the memory pointer in register pair HL.
133FH
PUSH BC
Save the integer value of the power of 10 in register pair BC to the stack.
1340H
INC HL
Bump the value of the memory pointer in register pair HL to the next value in the power of 10 table.
1341H
EX (SP),HL
Exchange the memory pointer of the next power of 10 (stored in register pair HL) with the value in the stack, and vice versa.
1342H
EX DE,HL
Load register pair DE with the current value from the stack (stored in register pair HL).
1343H-1345H
LD HL,(4121H)
Load register pair HL with the integer value in REG 1.
1346H-1347H
LD B,2FH
Since we are about to start a loop which starts with an INC, compensate by loading register B with the ASCII value for a zero character minus one.

1348H – This loop divides the current value by a power of 10 starting at 10,000 and working down to 10. The remainder frome ach division is added to the division and the sum becomes the dividend for the next division until done. The quotient is +2FH (which is the ASCII equivalent of a quotient).

1348H
INC B
Bump the ASCII value for the digit in register B (so it starts at 0 and moves up each loop).
1349H
LD A,L
Load register A with the LSB of the integer value in register L.
134AH
SUB E
Subtract the value of the LSB of the integer value in register E from the value of the LSB of the integer value in register A.
134BH
LD L,A
Load register L with the adjusted value of the LSB of the integer value in register A.
134CH
LD A,H
Load register A with the value of the MSB of the integer value in register H.
134DH
SBC A,D
Subtract the MSB of the integer value in register D from the value of the MSB of the integer value in register A.
134EH
LD H,A
Load register H with the adjusted value of the MSB of the integer value in register A.
134FH-1350H
Loop back to 1348H until the carry flag is triggered because the quotient (stored in HL) is less than the current power of 10.
1351H
ADD HL,DE
Add the remainder (stored as an integer in register pair DE) to the quotient (stored in register pair HL as an integer).
1352H-1354H
LD (4121H),HL
Save the integer remainder (stored in register pair HL) in REG 1.
1355H
POP DE
Get the address of the next power of 10 from the stack and put it in register pair DE.
1356H
POP HL
Get the memory pointer for the output buffer from the stack and put it in register pair HL.
1357H
LD (HL),B
Save the ASCII value for the digit (from register B that tracked the number of divisions) to the location of the output buffer pointer (stored in register pair HL).
1358H
INC HL
Bump the value of the input buffer pointer in register pair HL since we just filled that spot with an ASCII value.
1359H
POP AF
Get the number of digits to convert from the stack and put it in A.
135AH
POP BC
Get the counts of digits before/after the decimal point value from the stack and put it into register pair BC.
135BH
DEC A
Decrement the value of the counter in register A (which is a countdown from 5).
135CH-135DH
If the counter of the number of digits (from 5) is still not zero, jump back to 1335H until all of the digits have been figured.
135EH-1360H
So now all the digits have been calculated in ASCII, so GOSUB 1291H to put a decimal point or comma into the input buffer if necessary.
1361H
LD (HL),A
Save a zero (the value in register A which hit zero when the loop from 5 finished) to the input buffer, pointed to by register pair HL.
1362H
POP DE
Get the value from the stack (which was whatever value was in DE when this routine started) and put it in register pair DE.
1363H
RET
Return.

1364H-136BH – DOUBLE PRECISION CONSTANT STORAGE LOCATION

1364H-136BH
00 00 00 00 F9 02 15 A2
A double precision constant equal to 1E10 (or 10 x 10E9)is stored here.

136CH-1373H – DOUBLE PRECISION CONSTANT STORAGE LOCATION

136CH-1373H
FD FF 9F 31 A9 5F 63 B2
A double precision constant equal to 9.9921E14 (or 1 x 10e15) is stored here.

1374H-137BH – DOUBLE PRECISION CONSTANT STORAGE LOCATION

1374H-137BH
FE FF 03 BF C9 1B 0E B6
A double precision constant equal to 1×10^16 is stored here.

137CH-1383H – DOUBLE PRECISION CONSTANT STORAGE LOCATION

137CH-1383H
00 00 00 00 00 00 00 80
A double precision constant equal to 0.5 is stored here.
BYTE SAVING NOTE: Referencing 1380H, which is half-way through this double precision value of .5, results in a single precision value of 0.5.

1384H-138BH – DOUBLE PRECISION CONSTANT STORAGE LOCATION

1384H-138BH
00 00 04 BF C9 1B 0E B6
A double precision constant equal to 1×10^16 is stored here.
138AH-138DH
0E B5 00 80
BYTE SAVING NOTE: A double precision constant equal to .502778.

138CH-13D1H – DOUBLE PRECISION INTEGER CONSTANT STORAGE LOCATION

138CH-1392H
00 80 C6 A5 7E 8D 03
1 x 10e15.
1393H-1399H
00 40 7A 10 F3 5A 00
1 x 10e14.
139AH-13A0H
00 A0 72 4E 18 09 00
1 x 10e13.
13A1H-13A7H
00 10 A5 D5 E8 00 00
1 x 10e12.
13A1H-13A7H
00 10 A5 D5 E8 00 00
1 x 10e12.
13A8H-13AEH
00 E8 76 48 17 00 00
1 x 10e11.
13AFH-13B5H
00 E4 0B 54 02 00 00
1 x 10e10 (which is 10,000,000,000).
13B6H-13BCH
00 CA 9A 3B 00 00 00
1 x 10e09 (which is 1,000,000,000).
13BDH-13C3H
00 E1 F4 05 00 00 00
1 x 10e08 (which is 100,000,000).
13C4H-13CAH
80 96 98 00 00 00 00
1 x 10e07 (which is 10,000,000).
13CBH-13D1H
40 42 0F 00 00 00 00
1 x 10e06 (which is 1,000,000).

13D2H-13D9H – SINGLE PRECISION INTEGER CONSTANT STORAGE LOCATION

13D2H-13D4H
A0 86 01
1 x 10e04 (which is 100,000).
13D5H-13D7H
10 27 00
1 x 10e03 (which is 10,000).
13D8H-13D9H
E8 03
1 x 10e02 (which is 1,000).
13DAH-13DBH
E8 03
1 x 10e01 (which is 100).
13DEH
10
1 x 10e00 (which is 10).
13DFH
NOP
Nothing.

13E1H-13E6H – LEVEL II BASIC MATH ROUTINE

13E1H
NOP
Do nothing.
13E2H-13E4H
LD HL,0982H
Load register pair HL with the address of the routine for conversion of floating point numbers from negative to positive.
13E5H
EX (SP),HL
Exchange the value of that routines jump address to the stack with the value of the return address in register pair HL.
13E6H
JP (HL)
Jump to the address in register pair HL, which is basically a return to caller.

13E7H-13F1H – LEVEL II BASIC SQUARE ROOT ROUTINE – SQR(n) routine.

  • Single-precision values only should be used. (REG 1 = SQR(REG 1)).
    Computes the square root of any value in REG 1. The root is left in REG 1 as a single precision value.
  • NOTE: To use a ROM call to find the square root of a nonnegative single precision numbers, store the number in 4121H-4124H and then CALL 13E7H. The result (in single precision format) is in 4121H-4124Hin approximately 48 milliseconds. NOTE: A fatal error (returning control to the Level II monitor) occurs if the input number is negative.
13E7H-13F1H
“SQRT”
GOSUB 09A4 which moves the SINGLE PRECISION value in REG 1 to the stack (stored in LSB/MSB/Exponent order).
13EAH-13ECH
LD HL,1380H
Load register pair HL with the starting address of a single precision constant equal to 0.5 (which will be the exponent).
13EDH-13EFH
GOSUB 09B1H (which moves a SINGLE PRECISION number pointed to by HL to REG 1).
13F0H-13F1H
Jump to the EXP(n) routine at 13F5H (which will be using a .5 exponent to do the square root) skipping 13F2H since the exponent is already single precision.

13F2H-1478H LEVEL II BASIC X to the Y Power (X^Y) ROUTINE

  • A call to 13F2H raises the single precision value which has been saved to the stack to the power specified in REG 1. The result will be returned in REG 1. The method of computation is e ** (y ln x).
13F2H-13F4H
Make sure that the exponent is single precision by GOSUB to 0AB1H which is the CONVERT TO SINGLE PRECISION routine at 0AB1H (which converts the contents of REG 1 from integer or double precision into single precision).
13F5H
POP BC
Get the MSB of the single precision value from the stack and put it in register pair BC.
13F6H
POP DE
Get the NMSB and the LSB of the single precision value from the stack and put it in register pair DE.
  • NOTE: To use a ROM call to raise a single precision number (the base) to a single precision power (the exponent), store the base (single precision) in registers BCDE, and store the exponent (also single precision) in 4121H-4124H and then CALL 13F7H. The result (in single precision format) is in 4121H-4124H and in approximately 50 milliseconds.
13F7H-13F9H
GOSUB 0955H to check the sign for the single precision value in REG 1 (the exponent).
13FAH
LD A,B
Load register A with the MSB of the number to be raised (stored as a single precision value in register B).
13FBH-13FCH
Jump to the EXP(n) routine at 1439H if the exponent (the single precision value in REG 1) is equal to zero.
13FDH-13FFH
Skip the next 2 opcodes (which check to see if zero is involved) if the exponent (the single precision value in REG 1) is positive.
1400H
OR A
Check to see if the value to be raised (i.e., the single precision value in register pairs BC and DE) is equal to zero.
1401H-1403H
Display a ?/0 ERROR message if the single precision value in REG 1 is negative and the single precision value in register pairs BC and DE is equal to zero.
/0 ERROR entry point.
1404H
OR A
ANOTHER check to see if the value to be raised (i.e., the single precision value in register pairs BC and DE) is equal to zero.
1405H-1407H
Jump to 0779H if the value to be raised (i.e., the single precision value in register pairs BC and DE) is equal to zero.
1408H
PUSH DE
At this point we know that none of the values are zero, and we are raising the number to a positive power. Save the value to be raised (the NMSB and the LSB of the single precision value in register pair DE) to the stack.
1409H
PUSH BC
Save the exponent and the MSB of the single precision value in register pair BC to the stack.
140AH
LD A,C
Load register A with the value of the MSB of the single precision value to be raised (which is stored in register C).
140BH-140CH
OR 7FH
Test the sign of the based by masking bits 0-6 of the MSB of the single precision value (0111 1111) in register A.
140DH-140FH
Load the exponent (the power) into BC/DE by GOSUB to 09BF which loads the SINGLE PRECISION value in REG 1 (the exponent) into register pair BC/DE.
1410H-1412H
Jump down to 1421H if the base (the single precision value to the stack) is positive.
1413H
PUSH DE
Save the NMSB and the LSB of the exponent (the single precision value in register pair DE) to the stack.
1414H
PUSH BC
Save the exponent and the LSB of the single precision value in register pair BC to the stack.
1415H-1417H
GOSUB to 0B40H to figure the integer portion of the exponent (i.e., the single precision value in REG 1) into A with the truncated floating point portion into REG 1.
1418H
POP BC
Restore the exponent and the MSB of the single precision value from the stack and put it in register pair BC.
1419H
POP DE
Restore the NMSB and the LSB of the single precision value from the stack and put it in register pair DE.
141AH
PUSH AF
Save the integer portion of the exponent (i.e., the value in register pair AF) to the stack.
141BH-141DH
Compare the original exponent to the truncated one by GOSUB to 0A0CH.

NOTE: The routine at 0A0CH algebraically compares the single precision value in BC/DE to the single precision value REG 1.
The results are stored in A as follows:
  • A=0 if REG 1 = BCDE
  • A=1 if REG 1>BCDE; and
  • A=FFH if REG 1<BCDE.
141EH
POP HL
Get the exponent as an integer from the stack and put it in register H.
141FH
LD A,H
Load register A with the exponent as an integer (as stored in register H).
1420H
RRA
If the exponent (as an integer) is odd, set the carry flag.
1421H
POP HL
Get the original exponent from the stack and put it in register pair HL.
1422H-1424H
LD (4123H),HL
Save the value of the original exponent and the MSB of the single precision value (stored in register pair HL) in REG 1.
1425H
POP HL
Get the rest of the exponent from the stack and put it in register pair HL.
1426H-1428H
LD (4121H),HL
Save the rest of the exponent (i.e., as stored in register pair HL as the NMSB and the LSB of the single precision value) in REG 1.
1429H-142BH
If the exponent is odd and the base is negative, GOSUB to 13E2H.
142CH-142EH
If the exponent is an integer and the base is negative, GOSUB to 0983H to invert the value of the exponent.
142FH
PUSH DE
Save the NMSB and the LSB of the exponent (i.e., the single precision value in register pair DE) to the stack.
1430H
PUSH BC
Save the MSB of the exponent (i.e., the single precision value in register pair BC) to the stack.
1431H-1433H
CALL the LOG(N) routine at 0809H (which computes the natural log (base E) of the single precision value in REG 1. The result is returned as a single precision value in REG 1. Can give an ILLEGAL FUNCTION CALL erro if a negative base is raised to a power with a fraction).
1434H
POP BC
Get the exponent and the MSB of the single precision value from the stack and put it in register pair BC.
1435H
POP DE
Get the NMSB and the LSB of the single precision from the stack and put it in register pair DE.
1436H-1438H
We need to multiply the ln(value) * the exponent so we have to GOSUB to 0847H to SINGLE PRECISION MULTIPLY routine (which multiplies the current value in REG 1 by the value in (BC/DE). The product is left in REG 1.

1439H – EXP routine. Single-precision only. (REG 1 = EXP(REG1)).

  • A call to 1439H raises E (natural base) to the value in REG 1 which must be a single precision value. The result will be returned in REG 1 as a single precision number.
  • NOTE: To use a ROM call to find EXP(X), where X is a single precision variable, store the value of X in 4121H-4124H and then CALL 1439H. The result (in single precision format) is in 4121H-4124Hin approximately 28 milliseconds. NOTE: A fatal error occurs if the result is as large as 2 to the power of 127.
1439H-143BH
“EXP”
Call 09A4 to move the SINGLE PRECISION value in REG 1 (the exponent) to the stack (stored in LSB/MSB/Exponent order).
143CH-143EH
LD BC,8138H
Load register pair BC with the exponent and MSB of a single precision constant.
143FH-1441H
LD DE,AA3BH
Load register pair DE with the NMSB and the LSB of a single precision constant. Register pairs BC and DE are now equal to a single precision constant of 1.442695 (which is approximately 2 + ln 2).
1442H-1444H
We need to multiply the exponent value by 2 ln 2 so we call the SINGLE PRECISION MULTIPLY routine at 0847H (which multiplies the current value in REG 1 by the value in (BC/DE). The product is left in REG 1.
1445H-1447H
LD A,(4124H)
Load register A with the result of the math just done (i.e., which was multiplying the exponent value by 2 ln 2) which was stored in REG 1.
1448H-1449H
CP 88H
Check to see if the integer portion of the single precision value in REG 1 uses more than 7 bits of precision by comparing it against a mask of 1000 1000.
144AH-144CH
Jump to 0931H if the single precision value in REG 1 uses more than 7 bits of precision for its integer portion.
144DH-144FH
So now that we know the integer portion is less than 8 bits, we need to get the integer and put it into Register A by GOSUB to 0B40H to get the integer portion of the value in REG 1 and return with it in register A.
1450H-1451H
ADD A,80H
Adjust the value in register A by masking it against 1000 0000.
1452H-1453H
ADD A,02H
Adjust the value in register A by adding 2 more.
1454H-1456H
If (exponent * 2 ln 2) is => 126 (meaning when 2 was added it it, it overflowed with a 128), jump to 0931H.
1457H
PUSH AF
Save the integer value (+82H) (as stored in register pair AF) to the stack.
1458H-145AH
LD HL,07F8H
Load register pair HL with a single precision constant equal to 1.0 (as found at 1458H).
145BH-145DH
Go add the single precision constant 1.0 (as pointed to by register pair HL) to the current value in REG 1 which is EXP * 2 ln 2.
145EH-1460H
Need to multiply that by ln 2, so GOSUB to 0841H to multiply (1 + [EXP * 2 ln 2]) (as stored in REG 1) by 0.693147.
1461H
POP AF
Get the integerized value of EXP * 2 ln 2 (as stored in the stack) and put it in register pair AF.
1462H
POP BC
Get the original exponent into BC/DE in 2 steps fist get the exponent and the MSB of the single precision value from the stack and put it in register pair BC …
1463H
POP DE
and then get the NMSB and the LSB of the single precision value from the stack and put it in register pair DE.
1464H
PUSH AF
Save the integerized EXP * 2 ln 2 (stored in register pair AF) to the stack.
1465H-1467H
Now we need to subtract the original exponent from the integerized exponent so we GOSUB to 0713H which is the SINGLE PRECISION SUBTRACT routine (which subtracts the single precision value in BC/DE from the single precision value in REG 1. The difference is left in REG 1).
1468H-146AH
To force that difference to be a positive number we GOSUB to 0982H which makes the current single precision value in REG 1 positive.
146BH-146DH
LD HL,1479H
Load register pair HL with the starting address for a series of 8 coefficients.
146EH-1470H
GOSUB to 14A9H to do that series of computations.
1471H-1473H
LD DE,0000H
We need to load the integerized equivalent of EXP * 2 lnt 2 into BC/DE so first we load register pair DE with zero …
1474H
POP BC
… and then get the value from the stack and put it in register pair BC.
1475H
LD C,D
Load register C with zero (since Register D was filled with a zero in 1471H).
1476H-1478H
JP 0847H
We need to multiply by the sum from the series and return so we jump to 0847H which is the the SINGLE PRECISION MULTIPLY routine at 0847H (which multiplies the current value in REG 1 by the value in (BC/DE). The product is left in REG 1.

1479H-1499H – SINGLE PRECISION CONSTANT STORAGE LOCATION
This represents 1/6, -1/5, 1/4, -1/3, 1/2, -1, and 1

1479H
09
The number of single precision constants (9) which follow are stored here.
147AH-147DH
40 2E 94 74
A single precision constant equal to -0.00014171607 (-1.413165 * 10e-4) is stored here.
147EH-1481H
70 4F 2E 77
A single precision constant equal to 0.00132988204 (1.32988 * 10e-3, roughly -1/6) is stored here.
1482H-1485H
6E 02 88 7A
A single precision constant equal to -0.00830136052 (-8.30136 * 10e-3, roughly -1/5) is stored here.
1486H-1489H
E7 A0 2A 7C
A single precision constant equal to 0.04165735095 (roughly 1/4) is stored here.
148AH-148DH
50 AA AA 7E
A single precision constant equal to -0.16666531543 (roughly -1/3) is stored here.
148EH-1491H
FF FF 7F 7F
A single precision constant equal to 0.49999996981 (roughly 1/2) is stored here.
1492H-1495H
00 00 80 81
A single precision constant equal to -1.0 is stored here.
1496H-1499H
00 00 00 81
A single precision constant equal to 1.0 is stored here.

149AH-14C8H – LEVEL II BASIC MATH ROUTINE

  • This is a general purpose summation routine which computes the series SUM ((((x^2 * c0+c1)x^2 +c2)x^2 + … cN)x for I=0 to N when entered at 149AH If entered at 14A9H the series changes to SUM ((((x*c0+c1)x*c2)x+c3)x+…cN. On entry, the x is held in BC/DE and HL points to a list containing the number of terms followed by the coefficients.
149AH-149CH
GOSUB to 09A4 to which move the SINGLE PRECISION value in REG 1 to the stack (stored in LSB/MSB/Exponent order).
149DH-149FH
LD DE,0C32H
Load register pair DE with the return address of 0C32H …
14A0H
PUSH DE
… and push it to the stack.
14A1H
PUSH HL
Save the memory pointer of list containing the number of terms followed by the coefficients (as stored in register pair HL) to the stack.
14A2H-14A4H
GOSUB to 09BFH which loads the SINGLE PRECISION value in REG 1 into register pair BC/DE.
14A5H-14A7H
Since REG 1 and BC/DE now hold the same number, you can square that by a GOSUB to 0847H which is the SINGLE PRECISION MULTIPLY routine (which multiplies the current value in REG 1 by the value in (BC/DE). The product is left in REG 1).
14A8H
POP HL
Restore the address of the coefficient from the stack and put it in register pair HL.
14A9H-14ABH
We need to move either x or x**2 (depending on the routine entry point) to the stack so we GOSUB to 09A4 which moves the SINGLE PRECISION value in REG 1 to the stack (stored in LSB/MSB/Exponent order).
14ACH
LD A,(HL)
Load register A with the number of values to be figured at the location of the memory pointer in register pair HL.
14ADH
INC HL
Bump the value of the memory pointer in register pair HL so that it points to the next coefficient.
14AEH-14B0H
Now load the coefficient (stored in HL) and move it to REG 1 by GOSUB to 09B1H (which moves a SINGLE PRECISION number pointed to by HL to REG 1).
14B1H
06 F1
Z-80 Trick! See the general explanation at 10F8H.
14B2H
POP AF
Get the count of coefficients left (from the stack) and put it in register A.
14B3H-14B4H
POP BC
POP DE
Get the value of x from the stack and put it in register pair BC/DE.
14B5H
DEC A
Count 1 of the terms as computed by decrementing the counter in register A.
14B6H
RET Z
If that decrement results in a zero (meaning the series of computations has been completed) return out of the subroutine.
14B7H-14B8H
PUSH DE
PUSH BC
Save the NMSB and the LSB of x from DE to the stack and save the MSB of x from BC to the stack.
14B9H
PUSH AF
Save counter of remaining terms to compute (stored in register A) to the stack.
14BAH
PUSH HL
Save the value of the memory pointer to the next coefficient (stored in register pair HL) to the stack.
14BBH-14BDH
Compute C(I)*x by GOSUB to 0847H which is the SINGLE PRECISION MULTIPLY routine (which multiplies the current value in REG 1 by the value in (BC/DE). The product is left in REG 1.
14BEH
POP HL
Restore the coefficient table address (from the stack) to register pair HL.
14BFH-14C1H
Get the next coefficient from HL into BC/DE by GOSUB to 09C2H (which loads a SINGLE PRECISION value pointed to by register pair HL into register pairs BC and DE).
14C2H
PUSH HL
Save the next coefficient (stored in register pair HL) to the stack.
14C3H-14C5H
Compute C(I)*x+C(I+1) by GOSUB to 0716H which is the SINGLE PRECISION ADD routine (which adds the single precision value in (BC/DE) to the single precision value in REG 1. The sum is left in REG 1).
14C6H
POP HL
Restore the coefficient table address (from the stack) to register pair HL.
14C7H-14C8H
Jump back to 14B2H to continue the series. REG 1 contains the current term.

14C9H-1540H – LEVEL II BASIC RND(n)

  • Integer, single or double-precision. Output will be single-precision. (ACC=RND (ACC)).
    A call to 14C9H Generates a random number between 0 and 1, or 1 and n depending on the parameter passed in REG 1, The random value is returned in REG 1 as an integer with the mode flag set. The parameter passed will determine the range of the random number returned. A parameter of 0 will return an interger between 0 and 1. A parameter greater than 0 will have any fraction portion truncated and will cause a value between 1 and the integer portion of the parameter to be returned.
14C9H-14CBH
“RNDM”
Call the CONVERT TO INTEGER routine at 0A7FH (where the contents of REG 1 are converted from single or double precision to integer and deposited into HL).
  • NOTE: To run a RND(J) function via a ROM call just The RND(J) function (with J a nonzero integer) load the value of J into the HL register pair. Then CALL 14CCH and then CALL 0A7FH. The result (in integer format) is in 4121H-4122H and in HL in approximately 5.7 milliseconds. The input variable J must have a value between 1 and 32767, inclusive, or an FC error will occur.
14CCH
LD A,H
Load register A with the value of the MSB for the integer value in register H.
14CDH
OR A
Check to see if the integer value in register pair HL is negative.
14CEH-14D0H
Display a ?FC ERROR message if the integer value in register pair HL is negative.
14D1H
OR L
Combine the MSB and LSB and set status flags so we can see if the integer value in register pair HL is equal to zero.
14D2H-14D4H
If it is zero, we don’t need the rest of the below which functions to generate RND(n) so we just jump to 14F0H (which generates RND(0)) if the integer value in register pair HL is equal to zero (meaning the call was for RND(0)).
14D5H
PUSH HL
Since it wasn’t zero, we need to save the x of RND(n) (as stored in register pair HL) to the stack.
14D6H-14D8H
GOSUB to 14F0H (which generates RND(0)) and return with the single precision result in REG 1.
14D9H-14DBH
Load the random number into BC/DE by a GOSUB to 09BFH which loads the SINGLE PRECISION value in REG 1 into register pair BC/DE.
14DCH
EX DE,HL
Load register pair HL with the NMSB and the LSB of the single precision value in register pair DE.
14DDH
EX (SP),HL
Exchange the integer value to the stack with NMSB and the LSB of the single precision value in register pair HL. At this point, the random number is in the stack and the n (of RND(n)) is stored in register pair HL.
14DEH
PUSH BC
Save the RND(0) value to the stack.
14DFH-14E1H
Convert the original x of RND(x) to single precision by GOSUB to 0ACFH which converts the integer value in register pair HL to single precision and return with the result in REG 1.
14E2H-14E3H
POP BC
POP DE
Restore the RND(0) value from the stack and put it into register pair BC/DE.
14E4H-14E6H
Multiply the RND(0) value (currently in BC/DE) by the n of RND(n) (currently in REG 1) by GOSUB to 0847H which is the SINGLE PRECISION MULTIPLY routine (which multiplies the current value in REG 1 by the value in (BC/DE). The product is left in REG 1.
14E7H-14E9H
LD HL,07F8H
Load register pair HL with the starting address of a single precision constant equal to 1.0.
14EAH-14ECH
Increase the random number by one by GOSUB to 070BH which adds the single precision constant pointed to by register pair HL (which is 1.0) to the single precision value in REG 1 (which is the random number). Return with the single precision result in REG 1
14EDH-14EFH
JP 0B40H
With the random number now in REG 1, jump to 0B40H (which will convert it to an integer and RETurn to the subroutine caller).

14F0H – This routine calculates RND(0).

  • NOTE: To run a RND(0) function via a ROM call just CALL 14F0H. No input variable is necessary. The result (in single precision format) is in 4121H-4124H in approximately 2.4 milliseconds.
14F0H-14F2H
LD HL,4090H
Load register pair HL with the starting address for a table used for figuring random numbers.
14F3H
PUSH HL
Save the starting address for a table used for figuring random numbers (stored in HL) to the stack.
14F4H-14F6H
LD DE,0000H
Load register pair DE with zero (which will be the NMLSB and LSB of the starting value).
14F7H
LD C,E
Load register C with zero (C will be the MSB of the starting value).
14F8H-14F9H
LD H,03H
Load register H with the counter value for the loop (which will be 3).
14FAH-14FBH
LD L,08H
Load register L with a counter value of 8.
14FCH
EX DE,HL
Exchange the counters in register pair HL with the NMSB and the LSB of the random number in register pair DE.
14FDH
ADD HL,HL
Multiply the NMSB and the LSB of the random number in register pair HL by two.
14FEH
EX DE,HL
Exchange the NMSB and the LSB of the random number in register pair HL with the counters in register pair DE.
14FFH
LD A,C
Load register A with the MSB of the random number in register C.
1500H
RLA
Multiply the MSB of the random number in register A by two.
1501H
LD C,A
Load register C with the adjusted MSB of the random number in register A.
1502H
EX (SP),HL
Exchange the counter values in register pair HL with the value of the memory pointer to the stack.
1503H
LD A,(HL)
Load register A with the table value (held at the location of the memory pointer in register pair HL).
1504H
RLCA
Multiply the value in register A by two.
1505H
LD (HL),A
Save the doubled value (stored in register A) at the location of the memory pointer in register pair HL.
1506H
EX (SP),HL
Exchange the memory pointer in register pair HL with the counter values to the stack.
1507H-1509H
Jump forward to 1516H if the table value hasn’t overflowed.
150AH
PUSH HL
If we are here, the table value overflowed so we need to save the counter values in register pair HL to the stack.
150BH-150DH
LD HL,(40AAH)
Load register pair HL with the NMSB and the LSB of the random number seed.
Note: 40AAH-40ADH holds the random number seed.
150EH
ADD HL,DE
Add the NMSB and the LSB of the random number in register pair DE to the NMSB and the LSB of the random number seed in register pair HL.
150FH
EX DE,HL
Load register pair DE with the adjusted NMSB and LSB of the random number in register pair HL.
1510H-1512H
LD A,(40ACH)
Load register A with the MSB of the random number seed.
1513H
ADC A,C
Add the MSB of the random number in register C to the MSB of the random number seed in register A.
1514H
LD C,A
Load register C with the adjusted MSB of the random number in register A.
1515H
POP HL
Get the counter values from the stack and put it in register pair HL.
1516H
DEC L
Decrement the loop counter in register L.
1517H-1519H
Loop back to 14FCH until the above has been done eight times.
151AH
EX (SP),HL
Exchange the counter values in register pair HL with the memory pointer of the table value to the stack.
151BH
INC HL
Bump to the next table value.
151CH
EX (SP),HL
Exchange the value of the table value in register pair HL with the counter value to the stack.
151DH
DEC H
Decrement the counter value of the outer loop (in register H).
151EH-1520H
Loop back to 14FAH three times until the random number has been figured.
1521H
POP HL
Clear the flag table address from the stack. The fact that it is going into HL is not important.
1522H-1524H
LD HL,B065H
Load register pair HL with the value to reseed the random number seed.
1525H
ADD HL,DE
Add the seed (from register pair HL) to the NMSB and the LSB of the random number in register pair DE.
1526H-1528H
LD (40AAH),HL
Save the adjusted value in register pair HL as the NMSB and the LSB of the random number seed.
Note: 40AAH-40ADH holds the random number seed.
1529H-152BH
Go set the current number type to single precision.
152CH-152DH
LD A,05H
Load register A with a 5.
152EH
ADC A,C
Add 5 (the value held in A) and the MSB of the random number in register C.
152FH-1531H
LD (40ACH),A
Save the adjusted value in register A as the MSB of the random number seed.
1532H
EX DE,HL
Swap DE and HL so as to move the NMSB and LSB to DE so that we will have a BC/DE pair for the random number.
1533H-1534H
LD B,80H
Load register B with a value for the sign flag and the exponent (i.e, 1000 0000).
1535H-1537H
LD HL,4125H
Load register pair HL with the address for the sign value storage location.
Note: 4125H-4126H is used by floating point routines.
1538H
LD (HL),B
Save the sign result (1000 0000) in register B at the location of the memory pointer in register pair HL.
1539H
DEC HL
Decrement to exponent (held in register pair HL).
153AH
LD (HL),B
Set the exponent to (1000 0000) so that the value will be < 1.
153BH
LD C,A
Load register C with the value of the MSB for the single precision random number in register A.
153CH-153DH
LD B,00H
Zero the value of the exponent in register B.
153EH-1540H
JP 0765H
Jump to 0765H which will normalize the value and then jump to 14D9H unless RND(0) was called in which case return to caller.

1541H-1546H – LEVEL II BASIC COS

  • COS routine. Single-precision only.(REG 1 = COS(REG 1)).
    A call to 1541H computes the cosine for an angle given in radians. The angle must be a floating point value in REG 1; the cosine will be returned in REG 1 as a floating point value.
  • NOTE: To use a ROM call to find COS(X), where X is a single precision variable (in radians), store the value of X in 4121H-4124H and then CALL 1541H. The result (in single precision format) is in 4121H-4124Hin approximately 25 milliseconds.
1541H-1543H
“COSN”
LD HL,158BH
Load register pair HL with the starting address of a single precision constant equal to 1.57079637029 (which is pi / 2).
1544H-1546H
GOSUB to 070BH to add 1.57079637029 (stored in HL) to the single precision value in REG 1 and then pass through to the SIN() routine which is next.

1547H-158AH – LEVEL II BASIC SIN

  • SIN(n) routine. Single-precision only.(REG 1 = SIN(REG 1)).
  • A call to 1549H returns the sine as a single precision value in REG 1. The sine must be given in radians in REG 1.
  • The actual calculation routine is:
    1. Assume X <= 360 degrees.
    2. Recompute x as x=x/360 so that x=< 1.
    3. If x <= 90 degrees go to step 7.
    4. If x <= 180 degrees then x=0.5-x and then go to step 7.
    5. If x <= 270 degrees then x=0.5-x.
    6. Recompute x as x=x-1.0.
    7. Compute SIN using the power series.
  • NOTE: To use a ROM call to find SIN(X), where X is a single precision variable, store the value of X in 4121H-4124H and then CALL 1547H. The result (in single precision format) is in 4121H-4124Hin approximately 25 milliseconds. NOTE: The argument (X) must be in radians.
1547H-1549H
“SINE”
Call 09A4 which moves the SINGLE PRECISION value in REG 1 (the x in a SIN(x) call) to the stack (stored in LSB/MSB/Exponent order).
154AH-154CH
LD BC,8349H
Load register pair BC with the exponent and the MSB of a single precision constant.
154DH-154FH
LD DE,0FDBH
Load register pair DE with the NMSB and the LSB of a single precision constant. Register pairs BC and DE now hold a single precision constant equal to 6.2831855 (which is pi * 2).
1550H-1552H
Move 2 x pi value (held in DC/BE) into REG 1 by GOSUB to 09B4H (which moves the SINGLE PRECISION value in DC/DE into REG 1).
1553H-1554H
POP BC
POP DE
Put the x from a SIN(x) call into BC/DE.
1555H-1557H
To divide the x from a SIN(x) call (held in BC/DE) by pi*2 (held in REG 1) we must GOSUB 80A2H to divide the single precision value in register pairs BC and DE by the single precision value in REG 1. Return with the single precision result in REG 1.
1558H-155AH
Move that value (x / 2*pi) from REG 1 to the stack by GOSUB to 09A4H which moves the SINGLE PRECISION value in REG 1 to the stack (stored in LSB/MSB/Exponent order).
155BH-155DH
Go figure the integer portion for the single precision value in REG 1 by calling 0B40H. We need to do this so we can isolate the remainder.
155EH,155FH
POP BC
POP DE
Put the quotient and remainder of x/2*pi into BC/DE.
1560H-1562H
To get the remainder we need to subtract the integer portion from the full portion so we GOSUB 0713H (the SINGLE PRECISION SUBTRACT routine) to subtract the single precision value in BC/DE (the entire result) from the single precision value in REG 1 (the integer part of the result). The difference is left in REG 1).
1563H-1565H
LD HL,158FH
Load register pair HL with the starting address of a single precision constant equal to 0.25.
1566H-1568H
Next in calculating a SIN we would need to subtract .25 (held in HL) from the fractional part (held in REG 1) so as to see if it is <= to 90 degrees. To do this we GOSUB 0710H to subtract the single precision value in REG 1 from the single precision constant pointed to by register pair HL. Return with the result in REG 1.
1569H-156BH
Go check the sign of the result of that (.25 – fractional part) subtraction which is held in REG 1.
156CH
SCF
Set the Carry flag.
156DH-156FH
Jump to 1577H if the single precision value in REG 1 is positive (meaning it is < than 90 degrees).
1570H-1572H
If we are here, it is => 90 degrees, so we need to add .5 to the single precision value in REG 1. Return with the result in REG 1
1573H-1575H
Go check the sign for the single precision value in REG 1 which basically checks to see if it is > 0.75 (meaning < 270 degrees).
1576H
OR A
Test the value of the sign test in register A.
1577H
PUSH AF
Save the sign indicator (+ or -1) in register pair AF to the stack.
1578H-157AH
If it is positive, make it negative by GOSUB to 0982H.
157BH-157DH
LD HL,158FH
Load register pair HL with the starting address of a single precision constant equal to 0.25.
157EH-1580H
Add .25 (stored in HL) to the current value in REG 1 by GOSUB to 070BH (result is saved in REG 1).
1581H
POP AF
Get the sign reversal flag from the stack and put it in register pair AF.
1582H-1584H
Set the sign of the x term according to the quadrant by GOSUB to 0982H if if the Carry flag wasn’t set from above.
1585H-1587H
LD HL,1593H
Load register pair HL with 1593H (which is the starting address for a series of single precision values for a set of computations).
1588H-158AH
Go to 149AH to compute the series and then RETURN.

158BH-158EH – SINGLE PRECISION CONSTANT STORAGE LOCATION

158BH-158EH
DB 0F 49 81
A single precision constant equal to 1.57079637029 is stored here.

158FH-1592H – SINGLE PRECISION CONSTANT STORAGE LOCATION

158FH-1592H
00 00 00 7F
A single precision constant equal to 0.25 is stored here.

1593H-15A7H – SINGLE PRECISION CONSTANTS STORAGE LOCATION

1593H
05H
The number of single precision constants (05) which follows is stored here. These are the coefficients used in the power series to compute SIN(x).
1594H-1597H
BAH D7H 1EH 86H
A single precision constant equal to 39.7106704708 is stored here.
1598H-159BH
64H 26H 99H 87H
A single precision constant equal to -76.5749816893 is stored here.
159CH-159FH
58H 34H 23H 87H
A single precision constant equal to 81.6022338865 is stored here.
15A0H-15A3H
E0H 6DH A5H 86H
A single precision constant equal to -41.3416748045 is stored here.
15A4H-15A7H
DAH 0FH 49H 83H
A single precision constant equal to 6.28318500497 is stored here.

15A8H-15BCH – LEVEL II BASIC TAN ROUTINE
TAN(n)

  • Single-precision only.(REG 1 = TAN(REG 1)).
    A call to 15A8H computes the tangent of an angle in radians. The angle must be specified as a single precision value in REG 1. The tangent will be left in REG 1.
    Uses the fact that TAN(x) = SIN(x) / COS(x)
  • NOTE: To use a ROM call to find TAN(X), where X is a single precision variable (in radians), store the value of X in 4121H-4124H and then CALL 15A8H. The result (in single precision format) is in 4121H-4124Hin approximately 54 milliseconds. NOTE: A fatal error occurs if the result is as large as 2 to the power of 127, which will be the case if the value of X is sufficiently close to any odd multiple of pi/2 radians.
15A8H-15AAH
“TAN”
Call 09A4 which moves the SINGLE PRECISION value in REG 1 to the stack (stored in LSB/MSB/Exponent order).
15ABH-15ADH
Call the SIN(n) routine at 1547H (which returns the sine as a single precision value in REG 1. The sine must be given in radians in REG 1.
15AEH,15AFH
POP BC
POP HL
Get the original exponent and value from the stack and put it in register pair BC/HL.
15B0H-15B2H
Call 09A4 which moves the SIN(x) single precision value (stored in REG) 1 to the stack (stored in LSB/MSB/Exponent order).
15B3H
EX DE,HL
Load register pair DE with the NMSB and the LSB of the single precision value in register pair HL.
15B4H-15B6H 
Call 09B4H (which moves the original value in BC/DE into REG 1).
15B7H-15B9H
Call the COSINE routine at 1541H (which computes the cosine for an angle given in radians. The angle must be a floating point value; the cosine will be returned in REG 1 as a floating point value.
15BAH-15BCH
JP 08A0H
Jump to 08A0H to compute SIN(n) / COS(n) and return the value as TAN(n).

15BDH-15E2H – LEVEL II BASIC ATN ROUTINE
ATN(n) routine.

  • Single-precision only.(REG 1 = ATN(REG 1)).
    A call to 15BD returns the angle in radians, for the floating point tangent value in REG 1. The angle will be left as a single precision value in REG 1.
    The method of computation used in this routine is:
    1. Test the sign of the tangent to see if a negative angle is in the 2nd or 4th quadrant. Set the flag to force the result to positive on exit. If the value is negative, invert the sign.
    2. Test magnitude of tangent. If it is < 1 go to step 3. Otherwise, compute its reciprocal and put the return address on the stack that will calculate pi/2 – series value.
    3. Evaluate the series: (((x^2*c0+c1) x^2+c2) … c8)x
    4. If the flag from step 1 is not set, then invert the sign of the series result.
    5. If the original value is < 1 then return to the caller. Otherwise, compute pi/2-value from step 4 and then return.
  • NOTE: To use a ROM call to find ATN(X), where X is a single precision variable, store the value of X in 4121H-4124H and then CALL 15BDH. The result (in single precision format, in radians) is in 4121H-4124Hin approximately 27 milliseconds.
15BDH-15BFH
“ATAN”
Go check the sign of the single precision value in REG 1
15C0H-15C2H
If the single precision value in REG 1 is negative then put a return address of 13E2H to the stack.
15C3H-15C5H
Go convert the negative number in REG 1 to positive if necessary.
15C6H-15C8H
LD A,(4124H)
Load register A with the exponent of the tangent (which is a single precision value in REG 1).
15C9H-15CAH
CP 81H
Check to see if the the exponent of the tangent (which is a single precision value in REG 1) is less than one.
15CBH-15CCH
Jump to forward 15D9H if the carry flag is set (i.e., the single precision value in REG 1 is less than one).
15CDH-15CFH
LD BC,8100H
Load register pair BC with an exponent and a MSB for a single precision value.
15D0H
LD D,C
Zero the NMSB of the single precision value in register D.
15D1H
LD E,C
Zero the LSB of the single precision value in register E.
15D2H-15D4H
GOSUB 082AH to get the reciprocal of the tangent. This routine divides the single precision value in REG 1 into the single precision constant in register pairs BC and DE.
15D5H-15D7H
LD HL,0710H
Load register pair HL with a return address of 0710H (which is the subtract routine to be called once the series is calculated).
15D8H
PUSH HL
Save the value of the return address in register pair HL to the stack.
15D9H-15DBH
LD HL,15E3H
Load register pair HL with the starting address for a series of single precision numbers for a set of computations.
15DCH-15DEH
Go do the set of computations.
15DFH-15E1H
LD HL,158BH
Load register pair HL with the starting address of a single precision constant equal to 1.57079637029 (which is pi/2).
15E2H
RET
Return. The return address was set to 0710H above, which will then subtract the last term from pi/2 and then return.

15E3H-1607H – SINGLE PRECISION CONSTANTS STORAGE LOCATION

15E3H
09H
The number of single precision constants (9) which follows is stored here
15E4H-15E7H
4A D7 3B 78
A single precision constant equal to 0.00286622549 is stored here.
15E8H-15EBH
02 6E 84 7B
A single precision constant equal to -0.01616573699 is stored here.
15ECH-15EFH
FE C1 2F 7C
A single precision constant equal to 0.04290961441 is stored here.
15F0H-15F3H
74 31 9A 3D
A single precision constant equal to 0.07528963666 is stored here.
15F4H-15F7H
84 3D 5A 7D
A single precision constant equal to 0.10656264407 is stored here.
15F8H-15FBH
C8 7F 91 7E
A single precision constant equal to -0.14208900905 is stored here.
15FCH-15FFH
E4 BB 4C 7E
A single precision constant equal to 0.19993549561 is stored here.
1600H-1603H
6C AA AA 7F
A single precision constant equal to -0.33333146561 is stored here.
1604H-1607H
00 00 00 01
A single precision constant equal to 1.0 is stored here.

1608H-18C8H – LIST OF BASIC RESERVED WORDS, TOKENS, AND ENTRY LOCATIONS AS FOLLOWS:

ABS
D9
AND
D2
25FD
ASC
F6
2A0F
ATN
E4
AUTO
B7
2008
CDBL
Fl
0ADB
CHR$(
F7
2A11F
CINT
EF
0A7F
CLEAR
B8
CLOAD
B9
2C1F
CLOSE
A6
4185
CLS
84
01C9
CMD
85
4173
CONT
B3
COS
El
CSAVE
BA
2BF5
CSNG
F0
0ABl
CVD
E8
415E
CVI
E6
4152
CVS
E7
4158
DATA
88
DEF
DD
415B
DEFDBL
9B
DEFINT
99
DEFSNG
9A
DEFSTR
98
lE00
DELETE
B6
2BC6
DIM
8A
2608
EDIT
9D
2E60
ELSE
95
END
80
lDAE
EOF
E9
4161
ERL
C2
24DD
ERR
C3
24CF
ERROR
9E
EXP
E0
FIELD
A3
417C
FIX
F2
0B26
FN
BE
4155
FOR
81
FRE
DA
27D4
GET
A4
4174
GOSUB
91
GOTO
5D
IF
8F
2039
INKEY$
C9
019D
INP
DB
2AEF
INPUT
89
219A
INSTR
C5
419D
INT
D8
0B37
KILL
AA
4191
LEFT$
F8
2A61
LEN
F3
2A03
LET
8C
LINE
9C
41A3
LIST
B4
2B2E
LLIST
B5
2B29
LOAD
A7
4188
LOC
EA
4164
LOF
EB
4167
LOG
DF
0809
LPRINT
AF
2067
LSET
AB
4197
MEM
C8
27C9
MERGE
A8
418B
MID$
FA
2A9A
MKD$
EE
4170
NAME
A9
418E
NEW
BB
NEXT
87
22B6
NOT
CB
25C4
ON
A1
OPEN
A2
4179
OR
D3
25F7
OUT
AO
2AFB
PEEK
E5
2CAA
POINT
C6
0132
POKE
B1
2CB1
POS
DC
27F5
PRINT
B2
206F
PUT
A5
4182
RANDOM
86
01D3
READ
8B
21EF
REM
93
RESET
82
0138
RESTORE
90
RESUME
9F
lFAF
RETURN
92
lEDE
RIGHT$
F9
2A91
RND
DE
RSET
AC
419A
RUN
8E
SAVE
AD
41A0
SET
83
0135
SGN
D7
098A
SIN
E2
SQR
CD
STEP
cc
2B01
STOP
94
STR$
F4
2836
STRING$
C4
2A2F
SYSTEM
AE
02B2
TAB(
BC
2137
TAN
E3
THEN
CA
———
TIME$
C7
4176
TO
BD
———
TROFF
97
TRON
96
USING
BF
2CBD
USR
C1
27FE
VAL
FF
2AC5
VARPTR
C0
24EB
+
CD
249F
CE
2532
*
CF
———
/
D0
———
D1
———
>
D4
———
=
D5
———
<
D6
———
&
26
———
‘3A93
FB
———

18C9H-18F6H – STORAGE LOCATION FOR LEVEL II BASIC ERROR MESSAGES

00
NEXT without FOR
02
Syntax Error
04
RETURN without GOSUB
06
Out of DATA
08
Illegal Function Call
10
Overflow
12
Out of Memory
14
Underfined line number
16
Subscript out of Range
18
Redimensioned Array
20
Division by zero
22
Illegal direct operation
24
Type mismatch
26
Out of string space
28
String too long
30
String formula too complex
32
Can’t continue
34
No RESUME
36
RESUME without error
38
Unprintable error
40
Missing operand
42
Bad file data
44
Disk BASIC command

18F7H-1904H – STORAGE LOCATION FOR THE SINGLE PRECISION DIVISION ROUTINE
This code is moved from 18F7H-191DH to 4080H-40A5H during non-disk initial setup.

18F7H
SUB 00H
Subtract the LSB
18F9H
LD L,A
Restore the value to L
18FAH
LD A,H
Get the middle byte
18FBH
SBC A,00H
Subtract the middle byte
18FDH
LD H,A
Move the difference to H
18FEH
LD A,B
Get the MSB
18FFH
SBC A,00H
Subtract the MSB
1901H
LD B,A
Move it back to A
1902H
LD A,00H
Clear A
1904H
RET
RETurn.

1905H-191CH – STORAGE LOCATION FOR VALUES PLACED IN RAM UPON INITIALIZATION.

  • This code is moved to 408E during non-disk initial setup.

191DH-1923H – MESSAGE STORAGE LOCATION

191DH-1923H
“Error”
The Level II BASIC ERROR message is stored here.

1924H-1928H – MESSAGE STORAGE LOCATION

1924H-1928H
“in”
The Level II BASIC IN message is stored here.

1929H-192FH – MESSAGE STORAGE LOCATION

1929H-192FH
“READY”
The Level II BASIC READY message is stored here.

1930H-1935H – MESSAGE STORAGE LOCATION

1930H-1935H
“Break”
The Level II BASIC BREAK message is stored here.

1936H-1954H – SCAN STACK ROUTINE

  • This routine is called with DE as the address of the NEXT index. It scans the stack backwards looking for a FOR push. If one is found, it gets the address of the index and compares with the DE that was in place when this routine was called. If it is equal, then it exits with A=0 and HL=Address of the variable. If it is not equal it will keep scanning until no FOR push is found and then exit with A<>0.
1936H-1938H
LD HL,0004H
Load register pair HL with 4 so that we can backspace.
1939H
ADD HL,SP
Add the 4 (held in HL) to the current value of the stack pointer. HL will hold the current stack pointer, the stack point will bump forward 4.
193AH
LD A,(HL)
Load register A with the value held at the current stack point MINUS 4.
193BH
INC HL
Bump the value of the memory pointer in register pair HL so as to backspace one more byte in case a FOR token is located.
193CH-193DH
CP 81H
Check to see if the value in register A (which is the current stack pointer – 4) is a FOR token.
193EH
RET NZ
Return if the value in register A isn’t a FOR token. This returns with A being non-zero because there was no FOR push.
193FH
LD C,(HL)
Load register C with the LSB of the FOR‘s variable address.
1940H
INC HL
Bump the value of the memory pointer in register pair HL so as to backspace the current stack pointer by yet another byte.
1941H
LD B,(HL)
Load register B with the MSB of the FOR‘s variable address.
1942H
INC HL
Bump the value of the memory pointer in register pair HL so now HL will be the address of the FOR variable on the stack.
1943H
PUSH HL
Save the value in register pair HL (which is the address of the FOR variable) to the stack.
1944H
LD L,C
Load register L with the LSB of the FOR variable’s address in register C.
1945H
LD H,B
Load register H with the MSB of the FOR variable’s address in register B.
1946H
LD A,D
Load register A with the MSB of the variable address in register D. This sets up fto test the user specified variable address.
1947H
OR E
Check to see if the variable address in register pair DE is equal to zero.
1948H
EX DE,HL
Exchange the variable address in register pair HL with the variable address in register pair DE so that DE will now hold the address of the FOR variable from the stack.
1949H-194AH
Skip the next 2 opcodes if the variable address in register pair DE was equal to zero.
194BH
EX DE,HL
Exchange the variable address in register pair HL with the variable address in register pair DE so that HL will now have the address of the FOR variable from the stack.
194CH
RST 18H
This routine was entered with DE being the address of the NEXT index, so we need to compare that against the index from the stack. To do this, we RST 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).
194DH-194FH
LD BC,000EH
Load register pair BC with the value to backspace to next FOR token (which is 10).
1950H
POP HL
Get the memory pointer from the stack of the sign of the increment flag and put it in register pair HL.
1951H
RET Z
Return if the FOR block matched the NEXT index block.
1952H
ADD HL,BC
If it didn’t match, execute that 10 byte stepback in BC for the next possible FOR push.
1953H-1954H
Keep looking until the appropriate FOR block has been located.

1955H-1962H – DATA MOVEMENT ROUTINE

  • This routine moves a variable into another area specified by the caller. On entry BC is set as the end address of the list to move (which is the upper limit); DE is set as the start address of the list to move; and HL is the end of the area to move it to.
1955H-1957H
GOSUB to 196CH to make sure there’s enough room in memory for the string area.
1958H
PUSH BC
Save the end address of the list to move (stored in BC) to the stack.
1959H
EX (SP),HL
Save the end address of the list to move (stored in the stack now) to register pair HL.
195AH
POP BC
Get the end address of the move from the stack and put it in register pair BC.
195BH
RST 18H
Now we need to check to see if the memory pointer in HL is the same as the memory pointer in DE (to see if the move is finished), 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).
195CH
LD A,(HL)
Get a byte from the source list and put it in register A.
195DH
LD (BC),A
Save the byte into wherever BC is pointing.
195EH
RET Z
Return if finished with the move (i.e., the memory pointer in register pair HL is the same as the value of the memory pointer in register pair DE).
195FH
DEC BC
Decrement the source address (in register pair BC).
1960H
DEC HL
Decrement the destination address (in register pair HL).
1961H-1962H
Loop until the list was moved.

1963H-197DH – MEMORY CHECK ROUTINE

  • This routine computes the amount of space between HL and the end of memory at FFC6.
1963H
PUSH HL
Save the value in register pair HL to the stack.
1964H-1966H
LD HL,(40FDH)
Load register pair HL with the starting address of free memory (which is stored at 40FDH).
Note: 40FDH-40FEH holds Free memory pointer.
1967H-1968H
LD B,00H
Load register B with zero.
1969H
ADD HL,BC
Add 2 times the number of bytes required to start of free area (held in register pair BC) to the value in register pair HL.
196AH
ADD HL,BC
Add the value in register pair BC to the value in register pair HL leaving HL to now contain the end of the free area.
196BH-196CH
3EH E5H
Z-80 Trick! See the general explanation at 10F8H.
196CH
PUSH HL
Save the new free area pointer (which is the start) to the stack.
196DH-196EH
LD A,C6H
Load register A with C6H (which is the the LSB of FFC6H; the top of memory).
196FH
SUB L
Subtract the LSB of the value of the new memory pointer in register L from the value in register A.
1970H
LD L,A
Load register L with the adjusted value in register A (i.e., the free memory pointer resulting from subtracting the new starting address).
1971H-1972H
LD A,FFH
Load register A with the MSB of the top of memory.
1973H
SBC A,H
Subtract the MSB of the new memory pointer in register H from the value in register A. If the free space list exceeds 7FFC6 then the Carry flag gets set, meaning memory overflowed.
1974H-1975H
If the CARRY flag is set, display a ?OM ERROR since we are out of memory.
1976H
LD H,A
Next we need to determine if the free space list has overflowed the stack area so first we load register H with the adjusted value in register A.
1977H
ADD HL,SP
Add the value of the stack pointer to the adjusted value in register pair HL.
1978H
POP HL
Get the value from the stack and put it in register pair HL.
1979H
RET C
If the carry flag is set, then we have no overflow – so we better RETURN because the next step is an OM error processor.

197AH-197BH – OM ERROR entry point.

197AH-197BH
LD E,0CH
Load register E with the ?OM ERROR.
197CH-197DH
Display an ?OM ERROR message.

197EH-1AF7H – LEVEL II BASIC COMMAND MODE

197EH-1980H
LD HL,(40A2H)
Load register pair HL with the value of the current BASIC line number.
Note: 40A2H-40A3H holds the current BASIC line number.
1981H
LD A,H
Load register A with the MSB of the current BASIC line number in register H.
1982H
AND L
Combine the LSB of the current BASIC line number in register L with the MSB of the current line number in register A.
1983H
INC A
Bump the value of the combined BASIC line number in register A. If the current line is FFFFH then we have not started execution of a BASIC program yet (meaning we are still in the inputting phase).
1984H-1985H
Jump to 198EH if Level II BASIC is still in the command mode (rather than being in execution mode).
1986H-1988H
LD A,(40F2H)
Load register A with the error override flag.
Note: 40F2H holds Error flag.
1989H
OR A
Check to see if the error flag is set.
198AH-198BH
LD E,22H
Load register E with a ?NR ERROR code.
198CH-198DH
Jump to 19A2H if the error flag is set (meaning there was no RESUME address).
198EH-1990H
Otherwise, jump to 1DC1H (the READY routine) because there was an error in the input phase.
1991H-1993H
LD HL,(40DAH)
Load register pair HL with the DATA line number (which is stored at 16602).
Note: 40DAH-40DBH holds DATA line number.
1994H-1996H
LD (40A2H),HL
Save the DATA line number in register pair HL.
Note: 40A2H-40A3H holds the current BASIC line number.
1997H-1998H
LD E,02H
Load register E with a ?SN ERROR code.
SN ERROR entry point.
199AH-199BH
LD BC,141EH
Load register E with a ?/0 ERROR code.
199DH-199EH
LD BC,001EH
Load register E with a ?NF ERROR code.
?NF ERROR entry point.
19A0H-19A1H
LD BC,241EH
Load register E with a ?RW ERROR code.
?RW ERROR entry point.
19A2H-19A4H
LD HL,(40A2H)
Load register pair HL with the value of the current BASIC line number which has the error.
Note: 40A2H-40A3H holds the current BASIC line number.
19A5H-19A7H
LD (40EAH),HL
Save the value of the current BASIC line number with the error in register pair HL.
Note: 40EAH-40EBH holds Line number with error.
19A8H-19AAH
LD (40ECH),HL
Save the value of the current BASIC line number with the error in register pair HL.
Note: 40ECH-40EDH holds EDIT line number.
19ABH-19ADH
LD BC,19B4H
Load register pair BC with the return address of 19B4H which is the continuation address after a reinitialization.
19AEH-19B0H
LD HL,(40E8H)
Load register pair HL with the value of the stack pointer (which is stored at 40E8H).
Note: 40E8H-40E9H holds Stack pointer pointer.
19B1H-19B3H
Jump to 1B9AH to reinitialize the system variables.
19B4H
POP BC
Get the value from the stack and put it in register pair BC, which should be 0000H.
19B5H
LD A,E
Load register A with the value of the error code in register E.
19B6H
LD C,E
Load register C with the value of the error code in register E.
19B7H-19B9H
LD (409AH),A
Save the value of the error code (from in register A) into 409AH.
Note: 409AH holds the RESUME flag.
19BAH-19BCH
LD HL,(40E6H)
Load register pair HL with the value of the current BASIC program pointer (which is stored in 40E6H) (i.e., the address of the last byte executed in the current line).
Note: 40E6H-40E7H holds the temporary storage location.
19BDH-19BFH
LD (40EEH),HL
Save the value of the current BASIC program pointer (which is stored in 40EEH) in register pair HL.
Note: 40EEH-40EFH is used by RESUME.
19C0H
EX DE,HL
Load register pair DE with the value of the current BASIC program pointer in register pair HL.
19C1H-19C3H
LD HL,(40EAH)
Load register pair HL with the value of the last number line executed (which is stored in 16618).
Note: 40EAH-40EBH holds Line number with error.
19C4H
LD A,H
Load register A with the MSB of the last number line executed in register H.
19C5H
AND L
Combine the LSB of the last number line executed in register L with the MSB of the current BASIC line number in register A.
19C6H
INC A
Bump the value of the combined current BASIC line number. This will test to against FFFFH which would mean we are still in the input phase.
19C7H-19C8H
Jump to 19D0H if Level II BASIC is in the command mode (meaning the line number was FFFFH, which then flipped to zero on the prior INC command).
19C9H-19CBH
LD (40F5H),HL
Save the value of the current BASIC line number in register pair HL to (40F5H).
Note: 40F5H-40F6H holds the last line number executed.
19CCH
EX DE,HL
Load register pair HL with the value of the current BASIC program pointer in register pair DE.
19CDH-19CFH
LD (40F7H),HL
Save the value of the current BASIC program pointer (which is stored in 16631) in register pair HL.
Note: 40F7H-40F8H holds Last byte executed.
19D0H-19D2H
LD HL,(40F0H)
Load register pair HL with the current ON ERROR address.
Note: 40F0H-40F1H is used by ON ERROR.
19D3H
LD A,H
Load register A with the MSB of the ON ERROR address in register H.
19D4H
OR L
Combine the LSB of the ON ERROR address in register L with the MSB of the ON ERROR address in register A.
19D5H
EX DE,HL
Load register pair DE with the ON ERROR address in register pair HL.
19D6H-19D8H
LD HL,40F2H
Load register pair HL with the address of the error flag (which is 40F2H).
Note: 40F2H holds Error flag.
19D9H-19DAH
Jump to 19E3H (to error out) if there isn’t an ON ERROR address.
19DBH
AND (HL)
Combine the value of the error flag at the location of the memory pointer in register pair HL with the combined value of the ON ERROR address in register A.
19DCH-19DDH
Jump to 19E3H (to error out) if register A is non zero (meaning that there was no ON ERROR address).
19DEH
DEC (HL)
Decrement the value of the error flag at the location of the memory pointer in register pair HL so that RESUME will work.
19DFH
EX DE,HL
Load register pair HL with the ON ERROR address in register pair DE.
19E0H-19E2H
Jump to 1D36H to make that happen.
19E3H
XOR A
Zero register A.
19E4H
LD (HL),A
Clear the error override flag by save a zero (from register A) as the current error flag at the location of the memory pointer in register pair HL..
19E5H
LD E,C
Load register E with the value of the error code in register C.
19E6H-19E8H
We need to position the video to the next line, so go display a carriage return on the video display if necessary.
19E9H-19EBH
LD HL,18C9H
Load register pair HL with the starting address for the table of error messages.
19ECH-19EEH
Go to the DOS link at 41A6H (whcih would load and execute BASIC error messages as supplied by DOS).
Note: 41A6H-41E4H holds DOS links.
In NEWDOS 2.1, this would be a call to load a DISK BASIC error, with Register E holding the error number.
19EFH
LD D,A
Since we are non-DOS, we continue by loading register D with zero.
19F0H-19F1H
LD A,3FH
Load register A with a “?” (which is ASCII code 3FH).
19F2H-19F4H
GOSUB to 032AH to display the question mark in register A.
19F5H
ADD HL,DE
Add the value of the error code in register pair DE to the starting address of the table of error messages in register pair HL.
19F6H
LD A,(HL)
Load register A with the first character of the error message at the location of the table pointer in register pair HL.
19F7H-19F9H
GOSUB to 032AH to display the first character of the error message in register A.
19FAH
RST 10H
Error codes are 2 characters so we need to set the second character of the error in register A, 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.
19FBH-19FDH
GOSUB to 032AH to display the second character of the error message in register A.
19FEH-1A00H
LD HL,191DH
Load register pair HL with 191DH which is the starting address of the READY message.
1A01H
PUSH HL
Save the starting address of the READY message (held in HL) to the stack.
1A02H-1A04H
LD HL,(40EAH)
Load register pair HL with the value of the current BASIC line number (i.e., the statement causing the error).
Note: 40EAH-40EBH holds Line number with error.
1A05H
EX (SP),HL
Exchange the value of the current BASIC line number in register pair HL with the starting address of the Level II BASIC ERROR message to the stack.
1A06H-1A08H
We need to display the Level II BASIC ERROR message so we call the WRITE MESSAGE routine at 28A7H.
NOTE:
  • The routine at 28A7 displays the message pointed to by HL on current system output device (usually video).
  • The string to be displayed must be terminated by a byte of machine zeros or a carriage return code 0D.
  • If terminated with a carriage return, control is returned to the caller after taking the DOS exit at 41D0H (JP 5B99H).
1A09H
POP HL
Get the value of the BASIC line number with the error from the stack and put it in register pair HL.
1A0AH-1A0CH
LD DE,FFFEH
Load register pair DE with FFFEH.
1A0DH
RST 18H
Now we need to compare the BASIC line number causing the error (held in HL) with FFFEH (held in DE) so as to see if we are in the initialization routine, 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).
1A0EH-1A10H
Jump to 0674H if we are in the initialization routine because the error line number was FFFEH.
1A11H
LD A,H
Load register A with the MSB of the current BASIC line number in register H.
1A12H
AND L
Combine the LSB of the current BASIC line number in register L with the MSB of the current BASIC line number in register A.
1A13H
INC A
Bump the combined value of the current BASIC line number in register A to test to see if the line number is 00H (meaning command mode).
1A14H-1A16H
GOSUB to 0FA7H to display the current BASIC line number in register pair HL if Level II BASIC isn’t in the command mode.
1A17H
3E C1
Z-80 Trick! See the general explanation at 10F8H.
1A18H
POP BC
Get the value from the stack and put it in register pair BC.
1A19H-1A1BH
“BASIC”
Go set the current output device to the video display.
Re-entry into BASIC command mode entry point. (see 6CCH also).
1A1CH-1A1EH
Go call the DOS link at 41ACH.
In NEWDOS 2.1, this is the start of BASIC just before BASIC shows the READY prompt.
1A1FH-1A21H
Go turn off the cassette recorder.
1A22H-1A24H
Go display a carriage return if necessary.
1A25H-1A27H
LD HL,1929H
Load register pair HL with the starting address of the Level II BASIC READY message.
1A28H-1A2AH
We need to display the Level II BASIC READY message, so we call the WRITE MESSAGE routine at 28A7H.
NOTE:
  • The routine at 28A7 displays the message pointed to by HL on current system output device (usually video).
  • The string to be displayed must be terminated by a byte of machine zeros or a carriage return code 0D.
  • If terminated with a carriage return, control is returned to the caller after taking the DOS exit at 41D0H (JP 5B99H).
1A2BH-1A2DH
LD A,(409AH)
Load register A with the value of the current error code.
Note: 409AH holds the RESUME flag.
1A2EH-1A2FH
SUB 02H
Check to see if the current error code is a ?SN ERROR code by subtracting 2 from the error code, resulting in a zero if its a SN ERROR and any other number if it isn’t..
1A30H-1A32H
GOSUB to 2E53H to the EDIT mode if the current error code is a SN ERROR code.

1A33H – Many routines jump here as the start of the Level II BASIC interpreter.

  • If the jump here was from an AUTO call, (40E4H) will have the increment number, (40E1H) will be 0 if no AUTO and non-zero if AUTO, and (40E2H) will have the starting line number.
1A33H-1A35H
LD HL,FFFFH
Load register pair HL with the command mode line number.
1A36H-1A38H
LD (40A2H),HL
Save the line number in register pair HL as the current BASIC line number.
Note: 40A2H-40A3H holds the current BASIC line number.
1A39H-1A3BH
LD A,(40E1H)
Load register A with the value of the AUTO flag. It will be zero if not in AUTO, and anything else if in AUTO.
1A3CH
OR A
Check to see if in the AUTO mode.
1A3DH-1A3EH
Jump to 1A76H if not in the AUTO mode.
1A3FH-1A41H
LD HL,(40E2H)
We are in AUTO mode so load register pair HL with the current AUTO line number.
Note: 40E2H-40E3H holds Current BASIC line number.
1A42H
PUSH HL
Save the current AUTO line number (stored in register pair HL) to the stack.
1A43H-1A45H
GOSUB to 0FAFH to call the HL TO ASCII routine at 0FAFH (which converts the value in the HL register pair (assumed to be an integer) to ASCII and display it at the current cursor position on the video screen) to display the AUTO line number.
1A46H
POP DE
Get the current AUTO line number from the stack and put it in register pair DE.
1A47H
PUSH DE
Save the current AUTO line number in register pair DE to the stack.
1A48H-1A4AH
Call the SEARCH FOR LINE NUMBER routine at 1B2CH which looks for the line number specified in DE. Returns C/Z with the line found in BC, NC/Z with line number is too large and HL/BC having the next available location, or NC/NZ with line number not found, and BC has the first available one after that.
1A4BH-1A4CH
LD A,2AH
Load register A with a * (which will be code for a matching line number).
1A4DH-1A4EH
If the call to 1B2CH shows a matching line number was found in the BASIC program (by returning a C), skip the next instruction so that register A keeps the “*”.
1A4FH-1A50H
LD A,20H
If we are here, then there was no matching line number so we need to change the next character from a “*” (which is loaded into register A which but is not applicable) to a space.
1A51H-1A53H
Go display the character in register A on the video display (which will be a “*” if a matching line number was found).
1A54H-1A56H
GOSUB to 0361H to get input into the buffer.
1A57H
POP DE
Get the current line number from the stack and put it in register pair DE.
1A58H-1A59H
Skip the next 3 opcodes if the BREAK key wasn’t pressed.
1A5AH
XOR A
The BREAK key was pressed so we need to zero register A to clear the AUTO increment flag.
1A5BH-1A5DH
LD (40E1H),A
Save the value in register A as the current AUTO flag (to turn off AUTO).
1A5EH-1A5FH
Jump to the normal command mode “READY” routine at 1A19H.
1A60H-1A62H
LD HL,(40E4H)
Load register pair HL with the value of the AUTO increment.
Note: 40E4H-40E5H holds AUTO increment.
1A63H
ADD HL,DE
Since we didn’t BREAK out of the routine we need to keep processing the AUTO so we add the value of the AUTO line number in register pair DE with the AUTO increment value in register pair HL.
1A64H-1A65H
If that addition to the next AUTO line number causes an overflow (by triggering the Carry flag), jump to 1A5AH which is the same as if the BREAK key was hit.
1A66H
PUSH DE
Save the current AUTO line number in register pair DE to the stack.
1A67H-1A69H
LD DE,FFF9H
Load register pair DE with the maximum BASIC line number of FFF9H (=65529).
1A6AH
RST 18H
Now we need to compare the adjusted AUTO line number (in HL) with the maximum BASIC line number (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).
1A6BH
POP DE
Get the current AUTO line number from the stack and put it in register pair DE.
1A6CH-1A6DH
If the adjusted AUTO line number in register pair HL is too large, jump to 1A5AH which is the same as if the BREAK key was hit.
1A6EH-1A70H
LD (40E2H),HL
Save the adjusted AUTO line number in register pair HL as the current AUTO line number.
Note: 40E2H-40E3H holds Current BASIC line number.
1A71H-1A72H
OR 0FFH
Load register A with the AUTO flag value.
1A73H-1A75H
JP 2FEBH
Jump to the EDIT routine to save the current BASIC line.
1A76H-1A77H
LD A,3EH
Load register A with a > (the prompt that follows READY)
1A78H-1A7AH
Go display the Level II BASIC prompt in register A on the video display.
1A7BH-1A7DH
GOSUB to 0361H to accept input. HL will hold the buffer address for that input.
1A7EH-1A80H
JP C,1A33H
Jump to 1A33H if the BREAK key was pressed.
1A81H
RST 10H
Since we need to bump the current input buffer pointer in register pair HL until it points to the first character, 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.
1A82H
INC A
Bump the value of the character in register A. This sets the status flags but saves the carry flag.
1A83H
DEC A
Decrement the value of the character in register A so we can test for an end of statement.
1A84H-1A86H
Jump to 1A33H if we have an end of statement.
1A87H
PUSH AF
Save the value in register pair AF to the stack (including the carry flag).
1A88H-1A8AH
Call the ASCII TO INTEGER routine at 1E5AH.
NOTE:
  • The routine at 1E5A converts the ASCII string pointed to by HL to an integer deposited into DE. If the routine finds a non-numerica character, the conversion is stopped
1A8BH
This little looping routine is to clear any trailing blanks between the line number and the statement.
1A8BH
DEC HL
Decrement the value of the input buffer pointer in register pair HL.
1A8CH
LD A,(HL)
Load register A with the value of the character at the location of the input buffer pointer in register pair HL.
1A8DH-1A8EH
CP 20H
Check to see if the character at the location of the input buffer pointer in register A is a space.
1A8FH-1A90H
Loop back to 1A8BH if the character at the location of the input buffer pointer in register A is a space.
1A91H
INC HL
Bump the value of the input buffer pointer in register pair HL so that it points to the first character following a line number.
1A92H
LD A,(HL)
Load register A with that character.
1A93H-1A94H
CP 20H
Check to see if the character at the location of the input buffer pointer in register A is a space.
1A95H-1A97H
If it is a space then skip it by a GOSUB to 09C9H which bumps the value of the input buffer pointer in register pair HL if necessary.
1A98H
PUSH DE
Save the BASIC line number in register pair DE (which was converted from ASCII to an integer in 1A88H through a call to 1E5AH) to the stack.
1A99H-1A9BH
GOSUB to 1BC0H to tokenize the input. BC will equal the length of the encoded statement when its done.
1A9CH
POP DE
Get the value of the BASIC line number (which is an integer) from the stack.
1A9DH
POP AF
Get the carry flag (from the 1A81H character fetch) and put it in register pair AF.
1A9EH-1AA0H
LD (40E6H),HL
Save the input buffer pointer in register pair HL.
Note: 40E6H-40E7H holds the temporary storage location.
1AA1H-1AA3H
Go call the DOS line at 4182H.
In NEWDOS 2.1, this is the input scanner after tokenizing the current statement.
1AA4H-1AA6H
JP NC,1D5AH
Jump to 1D5AH if there wasn’t a line number with the input (meaning it was a direct statement or a system command).
1AA7H
PUSH DE
Save the BASIC line number (as an integer stored in register pair DE) to the stack.
1AA8H
PUSH BC
Save the length of the tokenized input (stored in register pair BC) to the stack.
1AA9H
XOR A
Zero register A.
1AAAH-1AACH
LD (40DDH),A
Save the value in register A (which is a 00H) as the input flag.
Note: 40DDH holds INPUT flag.
1AADH
RST 10H
Since we need find the first token, we have to bump the current input buffer pointer in register pair HL until it points to the next character by calling 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.
1AAEH
OR A
Set the flags.
1AAFH
PUSH AF
Save the status flag to the stack.
1AB0H
EX DE,HL
Load register pair HL with the integer value of the BASIC line number (held in register pair DE).
1AB1H-1AB3H
LD (40ECH),HL
Save the integer value of the line number (held in register pair HL) to 40ECH.
Note: 40ECH-40EDH holds EDIT line number.
1AB4H
EX DE,HL
Exchange the value of the input buffer pointer in register pair DE with the integer value of the BASIC line number in register pair HL. This will fill DE with the line number for the search routine in the next instruction.
1AB5H-1AB7H
Call the SEARCH FOR LINE NUMBER routine at 1B2CH which looks for the line number specified in DE. Returns C/Z with the line found in BC, NC/Z with line number is too large and HL/BC having the next available location, or NC/NZ with line number not found, and BC has the first available one after that.
1AB8H
PUSH BC
Save the address of the line number in the BASIC program (if it exists) in register pair BC to the stack.
1AB9H-1ABBH
If there wasn’t a matching line number in the BASIC program, GOSUB to 2BE4H to move the closest line number up in memory to make room for another line.
1ABCH
POP DE
Get the integer address of the BASIC line number from the stack and put it in register pair DE.
1ABDH
POP AF
Restore the status from the 1AADH token scan into register pair AF.
1ABEH
PUSH DE
Save the integer address of the BASIC line number to the stack.
1ABFH-1AC0H
Jump to 1AE8H if there was a matching line number in the BASIC program; otherwise we move on and a new line has to be added as follows.
1AC1H
POP DE
Get the address of the BASIC line number from the stack and put it in register pair DE.
1AC2H-1AC4H
LD HL,(40F9H)
Load register pair HL with the end of the BASIC program pointer.
  • Note: 40F9H-40FAH holds the starting address of the simple variable storage area.
1AC5H
EX (SP),HL
Exchange the length of the tokenized input to the stack with the end of the BASIC program pointer in register pair HL.
1AC6H
POP BC
Get the end of the BASIC program pointer from the stack and put it in register pair BC.
1AC7H
ADD HL,BC
Add the end of the BASIC program pointer in register pair BC to the value of the length of the tokenized input in register pair HL.
1AC8H
PUSH HL
Save the adjusted end of the BASIC program pointer in register pair HL to the stack.
1AC9H-1ACBH
Go check to see if there is enough room in memory for the new BASIC line by GOSUB to 1955H.
1ACCH
POP HL
Get the new end of the BASIC program pointer from the stack and put it in register pair HL.
1ACDH-1ACFH
LD (40F9H),HL
Save the new end of the BASIC program pointer in register pair HL.
  • Note: 40F9H-40FAH holds the starting address of the simple variable storage area.
1AD0H
EX DE,HL
Load register pair HL with the address of the BASIC line.
1AD1H
LD (HL),H
Save the MSB of the address of the BASIC line in register H.
1AD2H
POP DE
Get the value of the BASIC line number from the stack and put it in register pair DE.
1AD3H
PUSH HL
Save the value of the memory pointer in register pair HL to the stack.
1AD4H
INC HL
Bump the value of the memory pointer in register pair HL (which bumps it to the LSB of the line number entry).
1AD5H
INC HL
Bump the value of the memory pointer in register pair HL (which bumps it to the MSB of the line number entry).
1AD6H
LD (HL),E
Save the LSB of the BASIC line number in register E at the location of the memory pointer in register pair HL.
1AD7H
INC HL
Bump the value of the memory pointer in register pair HL.
1AD8H
LD (HL),D
Save the MSB of the BASIC line number in register D at the location of the memory pointer in register pair HL. At this point DE should have the binary value for the new line number.
1AD9H
INC HL
Bump the value of the BASIC line number in register pair HL.
1ADAH
EX DE,HL
Load register pair DE with first data byte address following the line number (held in register pair HL).
1ADBH-1ADDH
LD HL,(40A7H)
Load register pair HL with the value of the tokenized input pointer
Note: 40A7H-40A8H holds Input Buffer pointer.
1ADEH
EX DE,HL
Exchange the value of the memory pointer in register pair DE with the value of the tokenized input pointer in register pair HL.
1ADFH
DEC DE
Decrement the value of the tokenized input buffer pointer in register pair DE.
1AE0H
DEC DE
Decrement the value of the tokenized input buffer pointer in register pair DE.
1AE1H
LD A,(DE)
Load register A with the value at the location of the tokenized input buffer pointer in register pair DE.
1AE2H
LD (HL),A
Save the value in register A at the location of the memory pointer in register pair HL.
1AE3H
INC HL
Bump the store address (held in register pair HL).
1AE4H
INC DE
Bump the fetch address (held in register pair DE).
1AE5H
OR A
Check to see if the character in register A is an end of the line character.
1AE6H-1AE7H
Loop until the whole of the new BASIC line has been stored in memory.
1AE8H
POP DE
Get the address of the line in the program table from the stack and put it in register pair DE.
1AE9H-1AEBH
Go update line pointers for all lines following the new line.
1AECH-1AEEH
Go call the DOS link at 41B5H.
In NEWDOS 2.1, this is the input scanner after updating the PST (Program Statement Table).
1AEFH-1AF1H
Update all the BASIC line pointers.
1AF2H-1AF4H
Go call the DOS link at 41B8H.
In NEWDOS 2.1, this is the input scanner after reinitializing BASIC
1AF5H-1AF7H
Go get the input again.

1AF8H-1B0FH – LINE POINTERS ROUTINE

  • This routine fixes the line pointers in a BASIC program. This is useful, for instance for a renumber program which has to move BASIC program lines from one location in memory to an other, which means that the line pointers would no longer be valid. This routine will fix them. Registers A, HL and DE are used.
1AF8H-1AFAH
LD HL,(40A4H)
Load register pair HL with the start of the BASIC program pointer (called the PST).
  • Note: 40A4H-40A5H holds the starting address of BASIC program text also known as the PROGRAM STATEMENT TABLE (PST).
1AFBH
EX DE,HL
Move the PST address to DE.
1AFCH
LD H,D
Load register H with the MSB of the memory pointer in register D.
1AFDH
LD L,E
Load register L with the LSB of the memory pointer in register E.
1AFEH
LD A,(HL)
Load register A with the value at the location of the memory pointer in register pair HL.
1AFFH
INC HL
Bump the value of the memory pointer in register pair HL.
1B00H
OR (HL)
Since the first 2 bytes of each line contains the address of the next line, a 0000H would signify the end byte. With this, check to see if the character at the location of the memory pointer in register pair HL is an end of the BASIC program character.
1B01H
RET Z
Return if done.
1B02H
INC HL
Since HL is the ‘beginning of statment pointer’, we need to skip over the 3rd and 4th bytes, so bump the value of the memory pointer in register pair HL.
1B03H
INC HL
Bump the value of the memory pointer in register pair HL.
1B04H
INC HL
Bump the value of the memory pointer in register pair HL.
1B05H
XOR A
Zero register A and clear the flags.
1B06H
CP (HL)
Check to see if the character at the location of the memory pointer in register HL is an end of the BASIC line character.
1B07H
INC HL
Bump the value of the memory pointer in register pair HL.
1B08H-1B09H
Loop until the end of the BASIC line character is found.
1B0AH
EX DE,HL
Exchange the starting address of the current BASIC line in register pair DE with the starting address of the next BASIC line in register pair HL.
1B0BH
LD (HL),E
Save the LSB of the next BASIC line’s starting address in register E at the location of the memory pointer in register pair HL.
1B0CH
INC HL
Bump the value of the memory pointer in register pair HL.
1B0DH
LD (HL),D
Save the MSB of the next BASIC line’s starting address in register D at the location of the memory pointer in register pair HL.
1B0EH-1B0FH
Loop until the end of the program has been found.

1B10H-1B48H – EVALUATE LINE NUMBERS

  • This is called by LIST and DELETE. It converts the starting and ending linbers (X-Y) to binary and saves the ending line number on the stack. Then the code locates the program table address for the starting line. The routine leaves the address of the starting line in BC and the ending line number in the stack.
1B10H-1B12H
LD DE,0000H
Load register pair DE (which will be the line counter) with zero.
1B13H
PUSH DE
Save the value in register pair DE to the stack.
1B14H-1B15H
Jump to 1B1FH if there aren’t any line numbers to be evaluated.
1B16H
POP DE
Get the value from the stack and put it in register pair DE (which will be the line number).
1B17H-1B19H
Go evaluate the line number at the location of the current BASIC program pointer in register pair HL and return with the line number’s binary value in register pair DE.
1B1AH
PUSH DE
Save the first line number’s value (stored in register pair DE) to the stack.
1B1BH-1B1CH
Jump if there isn’t a second line number to be evaluated given (i.e, LIST 3000-).
1B1DH-1B1EH
RST 08H
CEH
If we are here, there is a second line number. That that would have to be preceded by a - at the location of the current BASIC program pointer in register pair HL, call the 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 Aregister and HL incremented by one. If the two characters do not match, a syntax error message is given and control returns to the Input Phase).
1B1FH-1B21H
LD DE,FFFAH
Load register pair DE with the default second line number of FFAFH.
1B22H-1B24H
Go evaluate the second line number at the location of the current BASIC program pointer in register pair HL and return with the line number’s binary value in register pair DE. Will return with Z flag set if it was a number.
1B25H-1B27H
Go to the Level II BASIC error routine and display a SN ERROR message if the data which followed the token wasn’t a line number.
1B28H
EX DE,HL
Load register pair HL with the value of the second line number in register pair DE and load register pair DE with the value of the current BASIC program pointer in register pair HL.
1B29H
POP DE
Get the value of the first line number from the stack and put it in register pair DE.
1B2AH
EX (SP),HL
Exchange the return address to the stack with the value of the second line number in register pair HL.
1B2BH
PUSH HL
Save the value of the return address in register pair HL to the stack so we can properly exit later.

1B2CH – This routine searches a BASIC program for a BASIC line with a line number matching the value in the DE register pair.

To use this routine, the required line number must be placed in the DE register pair. When a match is found, this routine sets the carry flag; the BC register pair points to the start of the required line, and the HL register points to the start of the next line. HL, AF and BC are used.

This is the the SEARCH FOR LINE NUMBER routine at 1B2C, which searches the Program Statement Table (PST) for a BASIC statement with the line number specified in the DE register pair. All registers are used. The exit conditions are:

C/Z=Line Found and BC is the starting address of the line in the PST and HL is the address following;

NC/Z=Line not found or too large and HL/BC will have the address of the next available PST location; and

NC/NZ=Line not found and BC=Address of the first line number greater than the one specified and HL will be the address of the following line.


1B2CH-1B2EH
LD HL,(40A4H)
Load register pair HL with the value of the start of the BASIC program pointer.
  • Note: 40A4H-40A5H holds the starting address of BASIC program text also known as the PROGRAM STATEMENT TABLE (PST).
1B2FH
LD B,H
Load register B with the value of the MSB of the memory pointer in register H.
1B30H
LD C,L
Load register C with the LSB of the memory pointer in register L. Now BC will hold the address of the current line in the PST.
1B31H
LD A,(HL)
Load register A with the LSB of the address of the next line (held in register pair HL).
1B32H
INC HL
Bump the value of the memory pointer in register pair HL to the MSB of the address of the next line.
1B33H
OR (HL)
Combine the value at the location of the memory pointer in register pair HL with the value in register A and set the status flags.
1B34H
DEC HL
Restore HL to the start of the current line.
1B35H
RET Z
Return if this is the end of PST (=the end of the BASIC program).
1B36H
INC HL
It’s not the end so we need HL to point the line number for the current line which means it must advance by 2. Bump the value of the memory pointer in register pair HL.
1B37H
INC HL
Bump the value of the memory pointer in register pair HL.
1B38H
LD A,(HL)
Load register A with the LSB of the current BASIC line number at the location of the memory pointer in register pair HL.
1B39H
INC HL
Bump the value of the memory pointer in register pair HL to point to the MSB of the current BASIC line number.
1B3AH
LD H,(HL)
Load register H with the MSB of the current BASIC line number at the location of the memory pointer in register pair HL.
1B3BH
LD L,A
Load register L with the LSB of the current BASIC line number in register A.
1B3CH
RST 18H
Now we need to compare the value of the current BASIC line number in HL and the first line number (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).
1B3DH
LD H,B
Load register H with the MSB of the memory pointer in register B.
1B3EH
LD L,C
Load register L with the LSB of the memory pointer in register C.
1B3FH
LD A,(HL)
Load register A with the value at the location of the memory pointer in register pair HL.
1B40H
INC HL
Bump the value of the memory pointer in register pair HL.
1B41H
LD H,(HL)
Load register H with the MSB of the next BASIC line pointer at the location of the memory pointer in register pair HL.
1B42H
LD L,A
Load register L with the LSB of the next BASIC line pointer in register A to form the address of the next line in HL.
1B43H
CCF
Complement the value of the Carry flag. The carry will be set if the current line number is < the value in DE. This will clear the Carry flag.
1B44H
RET Z
Return if the first line number in register pair DE is the same as the current BASIC line number. The line numbers match, so exit C, Z, BC=address of the current line, and HL=address of the next line.
1B45H
CCF
We have no match, so complement (reverse) the Carry flag and exit …
1B46H
RET NC
if the first line number in register pair DE is less than the current BASIC line number. BC will be the address of the current line and HL will be the address of the next line.
1B47H-1B48H
Loop until the location of the line number has been found in the BASIC program.

1B49H-1B5CH – LEVEL II BASIC NEW ROUTINE

  • Entry point of the NEW command.
1B49H
RET NZ
Go to the Level II BASIC error routine and display a ?SN ERROR message if there is any input following the NEW token.
1B4AH-1B4CH
Call the CLEAR SCREEN routine at 01C9 (which cleanrts the screen, changes to 64 characters, and homes the screen).
1B4DH-1B4FH
LD HL,(40A4H)
Load register pair HL with the start of the PST (the start of the BASIC program).
  • Note: 40A4H-40A5H holds the starting address of BASIC program text also known as the PROGRAM STATEMENT TABLE (PST).
1B50H-1B52H
GOSUB to the TROFF routine at 1DF8H (which just loads A with a zero for TROFF, and puts that 0 into 411BH).
1B53H-1B55H
LD (40E1H),A
Reset the AUTO flag by putting a zero (which is in A due to the GOSUB to the TROFF statement in the above instruction) into 40E1H.
1B56H
LD (HL),A
We need to initialize the PST, and the way to do that is to zero the first two bytes so … save a zero at the location of the memory pointer in register pair HL.
1B57H
INC HL
… bump the value of the memory pointer in register pair HL …
1B58H
LD (HL),A
… and save a zero at the location of the memory pointer in register pair HL.
1B59H
INC HL
Bump the value of the memory pointer in register pair HL.
1B5AH-1B5CH
LD (40F9H),HL
Save the value in register pair HL at 40F9H to initialize the start of the variable list table as the end of the PST.
  • Note: 40F9H-40FAH holds the starting address of the simple variable storage area.

1B5DH-1BB2H – LEVEL II BASIC RUN ROUTINE

  • This routine does a lot of variable resets and other things that are common to NEW as well, so NEW just does the special NEW stuff and than passes right through to here to reset the rest.
  • To use a ROM call to RUN a BASIC program, starting with its first line, execute the following instructions:
    LD HL,1D1EH
    PUSH HL
    JP 1B5DH
    The ability to RUN a BASIC program from an assembly language program is valuable for linking the two programs.
1B5DH-1B5FH
LD HL,(40A4H)
Load register pair HL with the PST (the start of the BASIC program pointer).
  • Note: 40A4H-40A5H holds the starting address of BASIC program text also known as the PROGRAM STATEMENT TABLE (PST).
1B60H
DEC HL
Decrement the value in register pair HL to backspace.
1B61H-1B63H
LD (40DFH),HL
Save the adjusted value in register pair HL into 40DFH.
Note: 40DFH-40E0H is used by DOS.
1B64H-1B65H
LD B,1AH
Load register B with the number of variable names to be initialized (which is 26).
1B66H-1B68H
LD HL,4101H
Load register pair HL with the starting address of the variable declaration table (which is 4101H).
Note: 4101H-411AH holds Variable Declaration Table.
1B69H-1B6AH
LD (HL),04H
Set the variable at the location of the memory pointer in register pair HL to a single precision variable.
1B6BH
INC HL
Bump the value of the memory pointer in register pair HL to the next variable.
1B6CH-1B6DH
DJNZ 1B69H
Loop until all 26 variables have been set to single precision.
1B6EH
XOR A
Zero register A.
1B6FH-1B71H
LD (40F2H),A
Save the value in register A (which is a zero) as the current value of the RESUME flag to say that there is no error for RESUME to handle.
Note: 40F2H holds Error flag.
1B72H
LD L,A
Zero register L.
1B73H
LD H,A
Zero register H.
1B74H-1B76H
LD (40F0H),HL
Save a zero (held in register pair HL) as the current ON ERROR address.
Note: 40F0H-40F1H is used by ON ERROR.
1B77H-1B79H
LD (40F7H),HL
Save a zero (held in register pair HL) as the current BREAK, STOP, or END address.
Note: 40F7H-40F8H holds Last byte executed.
1B7AH-1B7CH
LD HL,(40B1H)
Load register pair HL with the top of the memory pointer held in 40B1H.
Note: 40B1H-40B2H holds MEMORY SIZE? pointer.
1B7DH-1B7FH
LD (40D6H),HL
Save the top of memory pointer (held in register pair HL) as the next available address in the string space pointer.
Note: 40D6H-40D7H holds Next available location in string space pointer.
1B80H-1B82H
Go do a RESTORE (which will mess with DE and HL).
1B83H-1B85H
LD HL,(40F9H)
Load register pair HL with the end of the BASIC program pointer.
  • Note: 40F9H-40FAH holds the starting address of the simple variable storage area.
1B86H-1B88H
LD (40FBH),HL
Save the value in register pair HL as the new simple variables pointer.
  • Note: 40FBH-40FCH holds the starting address of the BASIC array variable storage area.
1B89H-1B8BH
LD (40FDH),HL
Save the value in register pair HL as the new array variables pointer.
Note: 40FDH-40FEH holds Free memory pointer.
1B8CH-1B8EH
Go call the DOS line at 41BBH.
In NEWDOS 2.1 this initializes BASIC for a new routine.
1B8FH
POP BC
Get the return address from the stack because we are about to change the stack pointer.
1B90H-1B92H
LD HL,(40A0H)
Load register pair HL with the start of string space pointer.
  • Note: 40A0H-40A1H holds the start of string space pointer.
1B93H
DEC HL
Decrement the value of the memory pointer in register pair HL.
1B94H
DEC HL
Decrement the value of the memory pointer in register pair HL (so now HL has the sart of the string space pointer – 2).
1B95H-1B97H
LD (40E8H),HL
Save the string space pointer – 2 (in register pair HL) as the stack pointer
Note: 40E8H-40E9H holds Stack pointer pointer.
1B98H
INC HL
Bump the value of the memory pointer in register pair HL.
1B99H
INC HL
Bump the value of the memory pointer in register pair HL so it is back to being the start of the string space pointer.
1B9AH
LD SP,HL
Load the stack pointer with the start of the string space pointer (held in register pair HL).
1B9BH-1B9DH
LD HL,40B5H
Load register pair HL with the start of the string work area (which is 40B5H).
Note: 40B5H-40D2H holds Temporary string work area.
1B9EH-1BA0H
LD (40B3H),HL
Save the value in register pair HL as the next available location in the string work area pointer.
Note: 40B3H-40B4H holds Next available location in the temporary string work area pointer.
1BA1H-1BA3H
GOSUB 038BH to set the current output device to the video display.
1BA4H-1BA6H
Go turn off the cassette recorder.
1BA7H
XOR A
Zero register A.
1BA8H
LD H,A
Zero register H.
1BA9H
LD L,A
Zero register L.
1BAAH-1BACH
LD (40DCH),A
Clear the FOR statement flag.
Note: 40DCH holds FOR flag.
1BADH
PUSH HL
Save the value in register pair HL (which is RUN) to the stack.
1BAEH
PUSH BC
Save the value in register pair BC (which is the address to continue executing code) to the stack.
1BAFH-1BB1H
LD HL,(40DFH)
Load register pair HL with the current value of the BASIC program pointer.
Note: 40DFH-40E0H holds Used by DOS.
1BB2H
RET
Return.

1BB3H-1BBFH – KEYBOARD INPUT ROUTINE

  • This is the last of the general purpose input routines. This routine functions identically to the 361H routine with the exception that it prints a “?” on the screen (like INPUT does with BASIC) before allowing input from the keyboard.
  • To use a ROM call to display “?” on the video screen at the current cursor position (Non-DOS Systems Only), and then to input a string of up to 240 characters, execute CALL 1BB3H. The input string will be in consecutive memory locations starting at the address contained in 40A7H-40A8H, with a zero byte at the end. The HL register pair will contain an address one less than the starting address of the stored input.
1BB3H-1BB4H
“INPUT”
LD A,3FH
Load register A with a ?.
1BB5H-1BB7H
Go display the ? (stored in register A) on the video display.
1BB8H-1BB9H
LD A,20H
Load register A with a space.
1BBAH-1BBCH
Go display the space in register A on the video display.
1BBDH-1BBFH
Jump to the keyboard input routine at 0361H.

1BC0H-1C8FH – TOKENIZE INPUT ROUTINE

1BC0H
XOR A
Zero register A.
1BC1H-1BC3H
LD (40B0H),A
Save the value in register A as the current value of the tokenization flag.
Note: 40B0H holds the temporary storage location.
1BC4H
LD C,A
Zero register C.
1BC5H
EX DE,HL
Load register pair DE with the address of the first character after the line number (as stored in register pair HL).
1BC6H-1BC8H
LD HL,(40A7H)
Load register pair HL with the starting address of the input buffer.
Note: 40A7H-40A8H holds Input Buffer pointer.
1BC9H
DEC HL
We need to backspace twice so … decrement the value of the input buffer pointer in register pair HL.
1BCAH
DEC HL
… and again decrement the value of the input buffer pointer in register pair HL.
1BCBH
EX DE,HL
Exchange the string address – 2 from HL into DE, and the current input string address from DE into HL.
1BCCH
LD A,(HL)
Load register A with the character at the current input string address (in register pair HL).
1BCDH-1BCEH
CP 20H
Check to see if the character in register A is a space.
1BCFH-1BD1H
Jump to 1C5BH if the character in register A is a .
1BD2H
LD B,A
Load register B with the value of the character in register A.
1BD3H-1BD4H
CP 22H
Check to see if the character in register A is a ".
1BD5H-1BD7H
Jump to 1C77H if the character in register A is a ". 1C77H will move the entire field between the quotes into the a code string.
1BD8H
OR A
Check to see if the character in register A is an end of the input character and set the status flags.
1BD9H-1BDBH
Jump to 1C7DH if the character in register A is an end of the input character.
1BDCH-1BDEH
LD A,(40B0H)
Load register A with the value of the tokenization flag for DATA.
Note: 40B0H holds the temporary storage location.
1BDFH
OR A
Check to see if a DATA statement is being processed.
1BE0H
LD A,(HL)
Load register A with the value of the next character.
1BE1H-1BE3H
Jump to 1C5BH if a DATA statement is being processed.
1BE4H-1BE5H
CP 3FH
Check to see if the character in register A is a ? (meaning a PRINT statement).
1BE6H-1BE7H
LD A,B2H
Load register A with a PRINT token.
1BE8H-1BEAH
Jump to 1C5BH if the character at the location of the input buffer pointer in register pair HL is a ?. This will replace the ? with PRINT.
1BEBH
LD A,(HL)
Re-fetch the current character (from the memory location of the input buffer pointer in register pair HL) and put it into Register A.
1BECH-1BEDH
CP 30H
Check to see if the character in register A is less than a zero character (alpha numeric).
1BEEH-1BEFH
Jump to 1BF5H if the character in register A is less than a zero character, meaning it is not a digit or letter.
1BF0H-1BF1H
CP 3CH
Check to see if the character in register A is less than < character (which is a test to see if it is 0-9, :, ;, <, constant or special character.
1BF2H-1BF4H
JP C,1C5BH
Jump to 1C5BH if the character in register A is 0-9, :, ;, <, constant or special character.
1BF5H
PUSH DE
Save the value of the input buffer pointer in register pair DE to the stack.
1BF6H-1BF8H
LD DE,164FH
Load register pair DE with the starting address of the reserved words list.
1BF9H
PUSH BC
Save the value in register pair BC to the stack.
1BFAH-1BFCH
LD BC,1C3DH
Load register pair BC with the return address after matching the reserved word list.
1BFDH
PUSH BC
Save the return address in register pair BC to the stack .
1BFEH-1BFFH
LD B,7FH
Load register B with the initial reserved words counter.
1C00H
LD A,(HL)
Load register A with the character at the location of the input buffer pointer in register pair HL.
1C01H-1C02H
CP 61H
Check to see if the character in register A is lower­case.
1C03H-1C04H
Jump to 1C0CH if the character in register A isn’t lowercase.
1C05H-1C06H
CP 7BH
Check to see if the character in register A is lower­case.
1C07H-1C08H
Jump down 2 instructions to 1C0CH if the character in register A isn’t lowercase.
1C09H-1C0AH
AND 5FH
Make the lowercase character in register A upper­case.
1C0BH
LD (HL),A
Save the adjusted character in register A at the location of the input buffer pointer in register pair HL.
1C0CH
LD C,(HL)
Load register C with the character at the location of the input buffer pointer in register pair HL.
1C0DH
EX DE,HL
Exchange the input buffer pointer in register pair HL with the reserved words list pointer in register pair DE.
1C0EH
INC HL
Bump the value of the reserved words list pointer to the next reserved word and put that in register pair HL.
1C0FH
OR (HL)
Check to see if bit 7 of the character at the location of the reserved words list pointer in register pair HL is set.
1C10H-1C12H
Jump to 1C0EH if the character at the location of the reserved words list pointer in register pair HL doesn’t have bit 7 set.
1C13H
INC B
Bump the value of the reserved words counter in register B.
1C14H
LD A,(HL)
Load register A with the character at the location of the reserved words list pointer in register pair HL.
1C15H-1C16H
AND 7FH
Reset bit 7 (the sign bit) of the character in register A.
1C17H
RET Z
Return if this is the end of the reserved words list.
1C18H
CP C
Check to see if the character in register C is the same as the character at the location of the reserved words list pointer in register A.
1C19H-1C1AH
Jump to 1C0EH if the characters don’t match.
1C1BH
EX DE,HL
Exchange the value of the reserved words list pointer in register pair HL with the value of the input buffer pointer in register pair DE.
1C1CH
PUSH HL
Save the starting address of the current symbol (stored register pair HL) to the stack.
1C1DH
INC DE
Bump the value of the reserved words list pointer in register pair DE.
1C1EH
LD A,(DE)
Load register A with the character at the location of the reserved words list pointer in register pair DE.
1C1FH
OR A
Check to see if bit 7 of the character in register A is set.
1C20H-1C22H
Jump to 1C39H if we have the control element (i.e., bit 7 of the character in register A is set).
1C23H
LD C,A
Load register C with the character in register A.
1C24H
LD A,B
Load register A with the value of the reserved words counter in register B.
1C25H-1C26H
CP 8DH
Check to see if the current reserved word being checked is GOTO.
1C27H-1C28H
Jump to 1C2BH if the current reserved word being checked isn’t GOTO.
1C29H
RST 10H
Since we need to skip spaces we need to bump the current input buffer pointer in register pair HL until it points to the next character, 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.
1C2AH
DEC HL
Decrement the value of the input buffer pointer in register pair HL.
1C2BH
INC HL
Bump the value of the input buffer pointer in register pair HL to point to the next character.
1C2CH
LD A,(HL)
Load register A with the next element from the string input (i.e., the character at the location of the input buffer pointer in register pair HL).
1C2DH-1C2EH
CP 61H
Check to see if the character in register A is lower-case.
1C2FH-1C30H
Jump to 1C33H if the character in register A isn’t lowercase.
1C31H-1C32H
AND 5FH
Test to see if the character in register A is uppercase.
1C33H
CP C
Check to see if the character in register A (the input element) matches the character in register C (the syntax element).
1C34H-1C35H
Jump back to 1C1DH if the character in the input matches the reserved words character.
1C36H
POP HL
If we didn’t just jump away, we need to restart the scan from the last point in the syntax list (which is stored in the stack) and put it into HL.
1C37H-1C38H
Jump back to 1C0CH.
1C39H
LD C,B
Load register C with the value of the reserved words counter in register B.
1C3AH
POP AF
Get the value from the stack and put it in register pair AF (which is just disposing of the HL push from 1C1CH).
1C3BH
EX DE,HL
Exchange the current string with the syntax tree address for the string.
1C3CH
RET
Return.

1C3DH
EX DE,HL
Exchange the reserved words list pointer in register pair HL with the input buffer pointer in register pair DE.
1C3EH
LD A,C
Load register A with the value of the reserved words counter in register C.
1C3FH
POP BC
Get the value from the stack and put it in register pair BC (basically to clear the return address from the stack).
1C40H
POP DE
Get the input buffer pointer -2 from the stack and put it in register pair DE.
1C41H
EX DE,HL
Exchange the input buffer pointer in register pair HL with the input buffer pointer in register pair DE. HL will be the buffer origin – 2 and DE will be the current string address.
1C42H-1C43H
CP 95H
Check to see if the token in register A is an ELSE token.
1C44H-1C45H
LD (HL),3AH
Save a colon at the location of the input buffer pointer -2 in register pair HL.
1C46H-1C47H
Jump to 1C4AH if the token in register A isn’t an ELSE token.
1C48H
INC C
Bump the value of the counter in register C (which is tracking the token buffer).
1C49H
INC HL
Bump the value of the input buffer pointer in register pair HL (which is the token buffer).
1C4AH‑1C4BH
CP 0FBH
Check to see if the token in register A is a REM token.
1C4CH-1C4DH
Jump to 1C5AH if the token in register A isn’t a REM token.
1C4EH-1C4FH
LD (HL),3AH
Save a “:” at the location of the input buffer pointer in register pair HL.
1C50H
INC HL
Bump the value of the input buffer pointer in register pair HL (because we just inserted a :).
1C51H-1C52H
LD B,93H
Load register B with a REM token.
1C53H
LD (HL),B
Save the REM token in register B at the location of the input buffer pointer in register pair HL.
1C54H
INC HL
Bump the value of the input buffer pointer in register pair HL (because we just inserted a REM token).
1C55H
EX DE,HL
Exchange the value of the input buffer pointer in register pair HL with the value of the input buffer pointer in register pair DE.
1C56H
INC C
Bump the value of the counter in register C.
1C57H
INC C
Bump the value of the counter in register C.
1C58H-1C59H
Jump to 1C77H to move the comment to the token buffer.

1C5AH
EX DE,HL
Exchange the value of the input buffer pointer in register pair HL with the value of the input buffer pointer in register pair DE.
1C5BH
INC HL
Bump the value of the input buffer pointer in register pair HL.
1C5CH
LD (DE),A
Save the value of the token in register A at the location of the input buffer pointer in register pair DE.
1C5DH
INC DE
Bump the value of the input buffer pointer in register pair DE.
1C5EH
INC C
Bump the value of the counter in register C (which is the index/counter for the next syntax element).
1C5FH-1C60H
SUB 3AH
Check to see if the character in register A is a : to flag a multi-statement line.
1C61H-1C62H
Jump to 1C67H if the character in register A is a colon and we have a multi-statement line.
1C63H-1C64H
CP 4EH
Check to see if the token in register A is a DATA token.
1C65H-1C66H
Jump to 1C6AH if the token in register A isn’t a DATA token.
1C67H-1C69H
LD (40B0H),A
Save the value in register A as the tokenization flag for DATA.
Note: 40B0H holds the temporary storage location.
1C6AH-1C6BH
SUB 59H
Check to see if the token in register A is a REM token.
1C6CH-1C6EH
Jump to 1BCCH if the token in register A isn’t a REM token.
1C6FH
LD B,A
Load register B with a zero.
1C70H
LD A,(HL)
Load register A with the character at the location of the input buffer pointer in register pair HL.
1C71H
OR A
Check to see if the character in register A is an end of the input character.
1C72H-1C73H
Jump out of this loop to 1C7DH if the character in register A is an end of the input character.
1C74H
CP B
Check to see if the character in register B matches the character in register A.
1C75H-1C76H
Jump to 1C5BH if the character in register B matches the character in register A.
1C77H
INC HL
Bump the value of the input buffer pointer in register pair HL.
1C78H
LD (DE),A
Save the character in register A at the location of the input buffer pointer in register pair DE.
1C79H
INC C
Bump the value of the counter in register C.
1C7AH
INC DE
Bump the value of the input buffer pointer in register pair DE.
1C7BH-1C7CH
Loop until a ‘end of statement’ or a ending quote is found.
1C7DH-1C7FH
LD HL,0005H
Load register pair HL with a five.
1C80H
LD B,H
Load register B with zero.
1C81H
ADD HL,BC
Add 5 to the length of the token buffer so far.
1C82H
LD B,H
Load register B with the MSB of the value in register H.
1C83H
LD C,L
Load register C with the LSB of the value in register L.
1C84H-1C86H
LD HL,(40A7H)
Load register pair HL with the start address of the input buffer.
Note: 40A7H-40A8H holds Input Buffer pointer.
1C87H
DEC HL
Decrement the value of the input buffer pointer in register pair HL.
1C88H
DEC HL
Decrement the value of the input buffer pointer in register pair HL.
1C89H
DEC HL
Decrement the value of the input buffer pointer in register pair HL.
1C8AH
LD (DE),A
Zero the location of the input buffer pointer in register pair DE.
1C8BH
INC DE
Bump the value of the input buffer pointer in register pair DE.
1C8CH
LD (DE),A
Zero the location of the input buffer pointer in register pair DE.
1C8DH
INC DE
Bump the value of the input buffer pointer in register pair DE.
1C8EH
LD (DE),A
Zero the location of the input buffer pointer in register pair DE.
1C8FH
RET
Return.

1C90H-1C95H – RST 0018H CODE
The RST 18H code is located here. (Unsigned compare (HL-DE)).

  • This is 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).
1C90H
“CHLDE”
LD A,H
Load register A with the MSB of the value in register H.
1C91H
SUB D
Subtract the value of the MSB of the value in register D from the MSB of the value in register A.
1C92H
RET NZ
Return if the MSB of the value in register D doesn’t equal the MSB of the value in register H.
1C93H
LD A,L
Load register A with the LSB of the value in register L.
1C94H
SUB E
Subtract the LSB of the value in register E from the LSB of the value in register A.
1C95H
RET
Return.

1C96H-1CA0H – RST 0008H CODE

  • The RST 8H code is located here.
    This is the 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 Aregister and HL incremented by one. If the two characters do not match, a syntax error message is given and control returns to the Input Phase).
1C96H
LD A,(HL)
Load register A with the character at the location of the current BASIC program pointer in register pair HL.
1C97H
EX (SP),HL
Save the return address of the routine by exchanging the value of the current BASIC program pointer in register pair HL with the value of the return address to the stack.
1C98H
CP (HL)
Check to see if the character at the location following the RST 08H call (stored in register pair HL) is the same as the character in register A.
1C99H
INC HL
Bump the value of the return address in register pair HL.
1C9AH
EX (SP),HL
Restore the return address (meaning the RST 08H plus 1 byte plus 1 byte) to the stack pointer.
1C9BH-1C9DH
Jump to the RST 0010H code if the characters match.
1C9EH-1C90H
If they don’t match, jump to the ?SN ERROR routine.

1CA1H-1D1DH – Level II BASIC FOR ROUTINE

  • FOR entry point.
1CA1H‑1CA2H
LD A,64H
Load register A with the value for the FOR flag.
1CA3H-1CA5H
LD (40DCH),A
Save the value in register A as the current value of the FOR flag.
Note: 40DCH holds FOR flag.
1CA6H-1CA8H
Go evaluate the N=M portion of the expression.
1CA9H
EX (SP),HL
Exchange the value of the current BASIC program pointer in register pair HL with the value to the stack.
1CAAH-1CACH
Go check to see if there is a FOR statement to the stack already using the same variable name (called the index).
1CADH
POP DE
Get the current BASIC program pointer from the stack (which should be the TO token and put it in register pair DE.
1CAEH-1CAFH
If there isn’t a matching FOR statement to the stack, skip the next 4 instructions (which are preparing for a NEXT WITHOUT FOR error) and jump to 1CB5H. If one is found, on exit HL will equal the starting address of the FOR push.
1CB0H
ADD HL,BC
Add the value in register pair BC (which is the offset to the end of the stack frame) to the value in register pair HL. After this addition, we should be pointing to the end of the first FOR frame push.
1CB1H
LD SP,HL
Reset the stack pointer to end of the first FOR frame push. This also frees up the stack space and prepares for a NF error.
1CB2H-1CB4H
LD (40E8H),HL
Save the value in register pair HL as the stack pointer, get ready for a NF error.
Note: 40E8H-40E9H holds Stack pointer pointer.
1CB5H
EX DE,HL
Exchange the value of the current BASIC program pointer in register pair DE with the value of the stack pointer address in register pair HL.
1CB6H-1CB7H
LD C,08H
Load register C with the 1/2 the amount of space needed.
1CB8H-1CBAH
Go check to see if there is enough memory (i.e., 16 bytes) left by calling 1963H (which is the MEMORY CHECK ROUTINE).
1CBBH
PUSH HL
Save the value of the current BASIC program pointer (which is the code string address before the TO) in register pair HL to the stack.
1CBCH-1CBEH
Keep scanning the current BASIC program (pointer is in register pair HL) until it points to the end of the BASIC statement.
1CBFH
EX (SP),HL
Exchange the adjusted value of the current BASIC program pointer in register pair HL with the value of the current BASIC program pointer to the stack.
1CC0H
PUSH HL
Save the value of the current BASIC program pointer in register pair HL to the stack. This should be pointing to the TO token.
1CC1H-1CC3H
LD HL,(40A2H)
Load register pair HL with the value (in binary) of the current BASIC line number.
Note: 40A2H-40A3H holds the current BASIC line number.
1CC4H
EX (SP),HL
Exchange the value of the current BASIC line number in register pair HL with the value of the current BASIC program pointer to the stack.
1CC5H-1CC6H
RST 08H
BDH
Since the character at the location of the current BASIC program pointer in register pair HL must be TO token (BDH) so call the 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 Aregister and HL incremented by one. If the two characters do not match, a syntax error message is given and control returns to the Input Phase).
1CC7H
RST 20H
We need to check the value of the current number type flag, so we call the TEST DATA MODE routine at RST 20H.
NOTE: The RST 20H routine determines the type of the current value in REG 1 and returns a combination of STATUS flags and unique numeric values in the A Register according to the data mode flag (40AFH).

The results are returned as follows:
  • Integer = NZ/C/M/E and A is -1
  • String = Z/C/P/E and A is 0
  • Single Precision = NZ/C/P/O and A is 1
  • and Double Precision is NZ/NC/P/E and A is 5.
1CC8H-1CCAH
If that test shows we have a STRING, go to the Level II BASIC error routine and display a TM ERROR message.
1CCBH-1CCDH
JP NC,0AF6H
If that test shows we have a DOUBLE PRECISION number, go display a ?TM ERROR message.
1CCEH
PUSH AF
We have an integer, so let’s keep going and save the value in register pair AF (the type flags) to the stack.
lCCFH-lCDlH
Go evaluate the expression at the location of the current BASIC program pointer in register pair HL (which should be the TO side) and return with the result in REG 1.
1CD2H
POP AF
Restore the index type flags from the from the stack and put it in register pair AF.
1CD3H
PUSH HL
Save the value of the current BASIC program pointer (which is the code string after the TO pointer) in register pair HL to the stack.
1CD4H-1CD6H
Jump if the current number type is single precision.
1CD7H-1CD9H
Call the CONVERT TO INTEGER routine at 0A7FH (where the contents of REG 1 are converted from single or double precision to integer and deposited into HL).
1CDAH
EX (SP),HL
Exchange the integer value in register pair HL (the current TO value) with the value of the current BASIC program pointer to the stack.
1CDBH-1CCDH
LD DE,0001H
Load register pair DE with a default STEP value of 1.
1CDEH
LD A,(HL)
Load register A with the character at the location of the current BASIC program pointer in register pair HL.
1CDFH-1CE0H
CP 0CCH
Check to see if the character in register A is a STEP token.
1CE1H-1CE3H
So now we have a STEP token so we have to get the step value into DE. To do this, GOSUB to 2B01H to evaluate the expression at the location of the current BASIC program pointer in register pair HL and return with the integer value in register pair DE if the character in register A is a STEP token.
1CE4H
PUSH DE
Save the STEP index value (in register pair DE) to the stack.
1CE5H
PUSH HL
Save the current BASIC program pointer (in register pair HL) to the stack.
1CE6H
EX DE,HL
Exchange the STEP value (from DE) with the value of the current BASIC program pointer (in register pair HL). Now HL will have the value so the next call can test its size.
1CE7H-1CE9H
GOSUB to 099EH to get the sign of the STEP value into A. It will be A=+1 if positive and A=-1 if negative.
1CEAH-1CEBH
Jump down to 1D0EH to skip the convert to single precision code which follows.
1CECH-1CEEH
Need the TO value to be integer so GOSUB to the CONVERT TO SINGLE PRECISION routine at 0AB1H (which converts the contents of REG 1 from integer or double precision into single precision).
1CEFH-1CF1H
Call 09BF which loads the SINGLE PRECISION value in REG 1 (the TO value in integer) into register pair BC/DE.
1CF2H
POP HL
Get the value of the current BASIC program pointer from the stack (which should be the end of the TO expression) and put it in register pair HL.
1CF3H,1CF4H
PUSH BC
PUSH DE
Save all 4 bytes of the TO value to the stack.
1CF5H-1CF7H
LD BC,8100H
Load register pair BC with the exponent and the MSB for a single precision constant.
1CF8H
LD D,C
Zero the NMSB for the single precision constant in register D.
1CF9H
LD E,D
Zero the LSB for the single precision constant in register E. Register pairs BC and DE now hold a single precision constant equal to one.
1CFAH
LD A,(HL)
Load register A with the character at the location of the current BASIC program pointer in register pair HL.
1CFBH-1CFCH
CP 0CCH
Check to see if the character in register A is a STEP token.
1CFDH-1CFEH
LD A,01H
Load register A with the default STEP value (in this case, 1).
1CFFH-1D00H
Skip over the next unstructions by jumping down to 1D0FH if the character at the location of the current BASIC program pointer in register A isn’t a STEP token.
1D01H-1D03H
Go evaluate the expression at the location of the current BASIC program pointer (which is the STEP instruction and return with the result in REG 1
1D04H
PUSH HL
Save the value of the current BASIC program pointer in register pair HL to the stack.
1D05H-1D07H
Convert the STEP value to single precision by calling the CONVERT TO SINGLE PRECISION routine at 0AB1H (which converts the contents of REG 1 from integer or double precision into single precision).
1D08H-1D0AH
Load the STEP value into BC/DE by calling 09BF which loads the SINGLE PRECISION value in REG 1 into register pair BC/DE.
1D0BH-1D0DH
Go get the sign for the STEP value (held in REG 1) into register A. A will be +1 if positive, and -1 if negative.
1D0EH
POP HL
Get the value of the current BASIC program pointer from the stack and put it in register pair HL.
1D0FH
PUSH BC
Save the exponent and the NMSB for the single precision value in register pair BC to the stack.
1D10H
PUSH DE
Save the NMSB and the LSB for the single precision value in register pair DE to the stack.
1D11H
LD C,A
Load register C with the sign value for the STEP value in register A.
1D12H
RST 20H
We need to check the value of the current number type flag, so we call the TEST DATA MODE routine at RST 20H.
NOTE: The RST 20H routine determines the type of the current value in REG 1 and returns a combination of STATUS flags and unique numeric values in the A Register according to the data mode flag (40AFH).

The results are returned as follows:
  • Integer = NZ/C/M/E and A is -1
  • String = Z/C/P/E and A is 0
  • Single Precision = NZ/C/P/O and A is 1
  • and Double Precision is NZ/NC/P/E and A is 5.
1D13H
LD B,A
Load register B with type-adjusted and sign value of the number type flag test in register A.
1D14H
PUSH BC
Save the type-adjusted and sign value in register pair BC to the stack.
1D15H
PUSH HL
Save the value of the current BASIC program pointer in register pair HL to the stack.
1D16H-1D18H
LD HL,(40DFH)
Load register B with a FOR x=y token.
Note: 40DFH-40E0H holds Used by DOS.
1D19H
EX (SP),HL
Put the code address string into HL and put the address of the x variable into the stack.
1D1AH-1D1BH
LD B,81H
Load register B with the FOR token.
1D1CH
PUSH BC
Save the FOR and token and the sign of the STEP increment BC to the stack.
1D1DH
INC SP
Bump the value of the stack pointer to leave a one byte gap. By continuing onward, we will wind up continuing the execution of the code string.

1D1EH-1D77H – LEVEL II BASIC INTERPRETER

1D1EH-1D20H
Go check to see if a key has been pressed.
1D21H
OR A
Set the flags. If a key was hit, test for SHIFT-@.
1D22H-1D24H
GOSUB to 1DA0H if the key pressed was a SHIFT-@. This will save the address of the last byte executed in the current line.
1D25H-1D27H
LD (40E6H),HL
Save the value of the current BASIC program pointer.
Note: 40E6H-40E7H holds the temporary storage location.
1D28H-1D2BH
LD (40E8H),SP
Save the value of the stack pointer.
Note: 40E8H-40E9H holds Stack pointer pointer.
1D2CH
LD A,(HL)
Load register A with the value at the location of the current BASIC program pointer in register pair HL.
1D2DH-1D2EH
CP 3AH
Check to see if the character in register A is a :.
1D2FH-1D30H
If the character is a :, jump to 1D5AH since that means this is a brand new statement on this line.
1D31H
OR A
There wasn’t a colon, so the only valid thing we can find now is an END OF LINE character. This will check to see if the character in register A is an end of the BASIC line character.
1D32H-1D34H
Go to the Level II BASIC error routine and display a ?SN ERROR message if the character in register A isn’t an end of the BASIC line character.
1D35H
INC HL
So now we know that we have another line number to check, so bump the value of the current BASIC program pointer in register pair HL.
1D36H
LD A,(HL)
Load register A with the LSB of the next BASIC line pointer at the location of the current BASIC program pointer in register pair HL.
1D37H
INC HL
Bump the value of the current BASIC program pointer in register pair HL.
1D38H
OR (HL)
Check to see if the next BASIC line pointer is equal to zero.
1D39H-1D3BH
Jump to 197EH if this is the end of the BASIC program.
1D3CH
INC HL
If we are here, it was not the end of the BASIC program so we need to bump the value of the current BASIC program pointer in register pair HL.
1D3DH
LD E,(HL)
Load register E with the LSB of the BASIC line number at the location of the current BASIC program pointer in register pair HL.
1D3EH
INC HL
Bump the value of the current BASIC program pointer in register pair HL.
1D3FH
LD D,(HL)
Load register D with the MSB of the BASIC line number at the location of the current BASIC program pointer in register pair HL.
1D40H
EX DE,HL
Exchange the value of the BASIC line number in register pair DE with the value of the current BASIC program pointer in register pair HL.
1D41H-1D43H
LD (40A2H),HL
Save the value of the BASIC line number in register pair HL.
Note: 40A2H-40A3H holds the current BASIC line number.

1D44H – Honor a TRON by showing the line number if it is in effect.

1D44H-1D46H
LD A,(411BH)
Before we move on, we need to honor a TRON, if its in effect so first we load register A with the value of the TRON flag.
Note: 411BH holds TRON/TROFF flag.
1D47H
OR A
Check for TRON.
1D48H-1D49H
Jump out of this routine to 1D59H if TROFF.
1D4AH
PUSH DE
If we are here, we have to process the code to show the “<nnnn>” of a TRON. First, save the value of the current BASIC program pointer in register pair DE to the stack.
1D4BH-1D4CH
LD A,3CH
Load register A with a <.
1D4DH-1D4FH
Go display the < that preceeds the line number in TRON output
1D50H-1D52H
Call the HL TO ASCII routine at 0FAFH (which converts the value in the HL register pair (assumed to be an integer) to ASCII and display it at the current cursor position on the video screen) to display the current BASIC line number.
1D53H-1D54H
LD A,3EH
Load register A with a >
1D55H-1D57H
Go display the > that follows the line number in TRON output
1D58H
POP DE
Get the value of the current BASIC program pointer from the stack and put it in register pair DE.

1D59H – Done with the TRON, so let us continue.

1D59H
EX DE,HL
Load register pair HL with the value of the current BASIC program pointer in register pair DE.
1D5AH
RST 10H
We need to get the next token. We bump the current input buffer pointer in register pair HL until it points to the next character, 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.
1D5BH-1D5DH
LD DE,1D1EH
Load register pair DE with the return address to go to after executing one verb.
1D5EH
PUSH DE
Save that return address in register pair DE to the stack.
1D5FH
RET Z
Return (back to 1D1EH) if the character at the location of the current BASIC program pointer (in register pair HL) is an end of the BASIC line character.
1D60H-1D61H
SUB 80H
Check to see if the character at the location of the current BASIC program pointer in register A is a token. This is accomplished because tokens range from 80H-FBH so this would give an index of the current token.
1D62H-1D64H
JP C,1F21H
Jump to 1F21H if the character in register A isn’t a BASIC token.
1D65H-1D66H
CP 3CH
Check to see if the token in register A is below the TAB( token.
1D67H-1D69H
JP NC,2AE7H
Jump out of here to 2AE7H if the token in register A is greater than or equal to a TAB( token, meaning TAB( to MID$(.
1D6AH
RLCA
Multiply the token value in register A by two. This doubles the remainder of the routine address offset.
1D6BH
LD C,A
Load the adjusted token value in register C from register A.
1D6CH-1D6DH
LD B,00H
Load register B with zero so that BC now holds “00” and (2 x the token).
1D6EH
EX DE,HL
Load register pair DE with the value of the current BASIC program pointer in register pair HL.
1D6FH-1D71H
LD HL,1822H
Load register pair HL with the list of BASIC execution addresses.
1D72H
ADD HL,BC
Add the value of the token offset in register pair BC to the starting address of the list of BASIC execution addresses in register pair HL.
1D73H
LD C,(HL)
Load register C with the LSB of the execution address at the location of the memory pointer in register pair HL.
1D74H
INC HL
Bump the value of the memory pointer in register pair HL.
1D75H
LD B,(HL)
Load register B with the MSB of the execution address at the location of the memory pointer in register pair HL.
1D76H
PUSH BC
Save the value of the execution address in register pair BC to the stack.
1D77H
EX DE,HL
Load register pair HL with the value of the current BASIC program pointer in register pair DE (i.e., restore the code string address).

1D78H-1D90H – RST 0010H CODE

  • The RST 10H code is located here. This is the EXAMINE NEXT SYMBOL routine which loads the next character from the string pointed to by the HL register set into the A-register and clears the CARRY flag if it is alphabetic, or sets it if is alphanumeric. Blanks and control codes 09 and OB 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).
1D78H
“FETCH”
INC HL
Bump the value of the current BASIC program pointer in register pair HL to the next character.
1D79H
LD A,(HL)
Load register A with the value of the character at the location of the current BASIC program pointer in register pair HL.
1D7AH-1D7BH
CP 3AH
Check to see if the character at the location of the current BASIC program pointer in register A is greater than or equal to a :.
1D7CH
RET NC
Return if the character at the location of the current BASIC program pointer in register A is greater than or equal to a : (meaning :, ;, <Y, Z.
1D7DH-1D7EH
CP 20H
Check to see if the character at the location of the current BASIC program pointer in register A is a space.
1D7FH-1D81H
Loop if the character at the location of the current BASIC program pointer in register A is a space.
1D82H-1D83H
CP 0BH
Check to see if the character at the location of the current BASIC program pointer in register A is greater than or equal to 0BH (meaning it is not a control code).
1D84H-1D85H
Jump if the character at the location of the current BASIC program pointer in register A if greater than or equal to 0BH.
1D86H-1D87H
CP 09H
Check to see if the character at the location of the current BASIC program pointer in register A is greater than or equal to 09H (meaning a horizontal tab).
1D88H-1D8AH
JP NC,1D78H
Loop back up to get the next character if if the character at the location of the current BASIC program pointer in register A is greater than or equal to 09H.
1D8BH-1D8CH
CP 30H
Check to see if the character at the location of the current BASIC program pointer in register A is greater than or equal to a zero character.
1D8DH
CCF
Set the carry flag if that ascii character is numeric (i..e, greater than or equal to 30H).
1D8EH
INC A
Clear the carry flag if it is not numeric (i.e., it is less than 30).
1D8FH
DEC A
Set the status flags (except for the carry flag) according to the character at hand.
1D90H
RET
Return.

1D91H-1D9AH – LEVEL II BASIC RESTORE ROUTINE

  • RESTORE logic is located here.
1D91H
EX DE,HL
Save the contents of HL by loading its contents into DE.
1D92H-1D94H
LD HL,(40A4H)
Load register pair HL with the start of the BASIC program pointer.
  • Note: 40A4H-40A5H holds the starting address of BASIC program text also known as the PROGRAM STATEMENT TABLE (PST).
1D95H
DEC HL
Backspace from the start of the BASIC program pointer.
1D96H-1D98H
LD (40FFH),HL
Save the start of the program pointer -1 into 40FFH.
Note: 40FFH-4100H holds READ pointer.
1D99H
EX DE,HL
Restore the HL.
1D9AH
RET
Return.

1D9BH-1DADH – SCAN KEYBOARD ROUTINE

1D9BH-1D9DH
Go scan the keyboard.
1D9EH
OR A
Check to see if a key was pressed.
1D9FH
RET Z
Return if a key wasn’t pressed.
1DA0H-1DA1H
CP 60H
Check to see if the key pressed in register A is a SHIFT-@.
1DA2H-1DA4H
If you got a SHIFT-@ we now need to honor that by waiting for yet another key to be pressed.
1DA5H-1DA7H
LD (4099H),A
Save the key pressed in register A as the value of the last key pressed.
Note: 4099H holds the Last key pressed.
1DA8H
DEC A
Check to see if the BREAK key was pressed.

1DA9-1DADH – STOP ROUTINE

1DA9H
RET NZ
Return if the BREAK key wasn’t pressed.
This is the STOP entry point.
1DAAH
INC A
Readjust the value of the key pressed in register A.
1DABH-1DADH
Jump into the applicable portion of the code that processes END.

1DAEH-1DE3H – LEVEL II BASIC END ROUTINE

  • The is the END statement entry point.
1DAEH
RET NZ
Return and display a ?SN ERROR message if there is anything following the END token.
1DAFH
PUSH AF
Save the value in register pair AF to the stack.
1DB0H-1DB2H
If this is a DOS system, then call the DOS link at 41BBH instead of continuing here.
1DB3H
POP AF
Restore the END status to the A register.
1DB4H-1DB6H
LD (40E6H),HL
Save the value of the current BASIC program pointer in register pair HL.
Note: 40E6H-40E7H holds the temporary storage location.
1DB7H-1DB9H
LD HL,40B5H
Load register pair HL with the starting address of the temporary string work area.
Note: 40B5H-40D2H holds Temporary string work area.
1DBAH-1DBCH
LD (40B3H),HL
Save the value in register pair HL as the new temporary string work area pointer.
Note: 40B3H-40B4H holds Next available location in the temporary string work area pointer.
1DBDH-1DBFH
21 F6 FF
Z-80 space saving trick
1DBEH-1DBFH
OR FFH
Set the flags.
1DC0H
POP BC
Get the value from the stack and put it in register pair BC. This clears out the stack.
1DC1H-1DC3H
LD HL,(40A2H)
Load register pair HL with the value of the current BASIC line number in binary.
Note: 40A2H-40A3H holds the current BASIC line number.
1DC4H
PUSH HL
Save the value of the current BASIC line number (in binary) in register pair HL to the stack.
1DC5H
PUSH AF
Save the value in register pair AF to the stack. A will be 0 if it is an END and A will be a 1 if it is a STOP.
1DC6H
LD A,L
These 3 instructions test to see if we are in command mode by testing for an uninitialized line (meaning a line number of FFFF). First, load register A with the LSB of the current BASIC line number in register L.
1DC7H
AND H
Combine the MSB of the current BASIC line number in register H with the LSB of the current BASIC line number in register A.
1DC8H
INC A
Bump the combined value of the current BASIC line number in register A.
1DC9H-1DCAH
Increasing FFFF by 1 would flip the Z flag on, meaning there was no line number. If there was no line number, skip the nex 3 instructions and go to 1D44H.
1DCBH-1DCDH
LD (40F5H),HL
If we are here, we have a line number so save the line number we ended on in register pair HL.
Note: 40F5H-40F6H holds the last line number executed.
1DCEH-1DD0H
LD HL,(40E6H)
Load register pair HL with the value of the current BASIC program pointer .
Note: 40E6H-40E7H holds the temporary storage location.
1DD1H-1DD3H
LD (40F7H),HL
Save the value of the current BASIC program pointer in register pair HL.
Note: 40F7H-40F8H holds Last byte executed.
1DD4H-1DD6H
Go set the current output device to the video display.
1DD7H-1DD9H
Go display a carriage return if necessary.
1DDAH
POP AF
Restore A so we can see if this is an END (where A=0) or a STOP (where A=1).
1DDBH-1DDDH
LD HL,1930H
Load register pair HL with the starting address of the BREAK message.
1DDEH-1DE0H
Jump to 1A06H if it was a BREAK or a STOP that halted program execution.
1DE1H-1DE3H
At this point it was either due to an END statement or an error while in command mode so jump to 1A18H (note: This uses a Z-80 trick as 1A18H is in the middle of a 2 Opcode instruction starting at 1A17H).

1DE4H-1DF6H – LEVEL II BASIC CONT ROUTINE
This is the CONT statement entry point.

1DE4H-1DE6H
LD HL,(40F7H)
Load register pair HL with the value of the continuation address.
Note: 40F7H-40F8H holds Last byte executed.
1DE7H
LD A,H
Load register A with the MSB of the continuation address in register H.
1DE8H
OR L
Combine the LSB of the continuation address in register L with the MSB of the continuation address in register A. If there was nothing in HL, this would trigger a Z flag.
1DE9H-1DEAH
LD E,20H
Load register E with a ?CN ERROR code.
1DEBH-1DEDH
Go to the ?CN ERROR routine if CONT isn’t possible (meaning the line number was zero).
1DEEH
EX DE,HL
If we are here, there was a valid return line number, so load register pair DE with the value of the continuation line number in register pair HL.
1DEFH-1DF1H
LD HL,(40F5H)
Load HL with the value of the last BASIC line number executed.
Note: 40F5H-40F6H holds the last line number executed.
1DF2H-1DF4H
LD (40A2H),HL
Save the last line number executed in register pair HL (which had the error) as the current BASIC line number.
Note: 40A2H-40A3H holds the current BASIC line number.
1DF5H
EX DE,HL
Swap so that HL will be the address of the continuation line.
1DF6H
RET
Return (continue running but from the CONT line number).

1DF7H-1DF8H – TRON ENTRY POINT

  • Turns TRON feature on. Causes line numbers for each BASIC statement executed to be displayed. Uses A register.
1DF7H-1DF8H
LD A,AFH
Load register A with a nonzero value.

1DF8H – TROFF ENTRY POINT
Disables tracing feature. Uses A register.

1DF8H
XOR A
Z-80 trick. This command is only visible if jumped to. This zeros register A.

1DF9H-1DFCH – COMMON CODE SHARED BY TRON AND TROFF

1DF9H-1DFBH
LD (411BH),A
Save the value in register A as the current value of the TRON/TROFF flag.
Note: 411BH holds TRON/TROFF flag.
1DFCH
RET
Return.

1DFDH-1DFFH – DISK ROUTINE NOT USED BY LEVEL II BASIC.

1DFD
POP AF
1DFE
POP HL
1DFF
RET

1E00H-1E02H – DEFSTR ENTRY POINT

1E00H-1E01H
LD E,03H
Load register E with the DEFSTR string number type flag (03H).
1E02H
32 1B 41
Z-80 Trick! See the general explanation at 10F8H.

1E03H-1E05H – DEFINT ENTRY POINT

1E03H-1E04H
LD E,02H
Load register E with the DEFINT integer number type flag (02H).
1E05H
011 1E 04
Z-80 Trick! See the general explanation at 10F8H.

1E06H-1E08H – DEFSNG ENTRY POINT

1E06H-1E07H
LD E,04H
Load register E with the DEFSNG single precision number type flag (04H).
1E08H
011 E0 08
Z-80 Trick! See the general explanation at 10F8H.

1E09H-1E0AH – DEFDBL ENTRY POINT

1E09H-1E0AH
LD E,08H
Load register E with the DEFDBL double precision number type flag (08H).

1E0BH-1E3CH – COMMON CODE SHARED BY DEFSTR, DEFINT, DEFSNG, AND DEFDBL – All of those can either have a - for a range of values or be separated by ,. This code needs to figure out the variables that followed the DEF??? instruction and then set the variable type (which is currently sitting in Register E) in the variable table.

1E0BH-1E0DH
A call to 1E3DH checks the value at memory location (HL), which would be the current BASIC program pointer, to see if it is a letter. If its not, CARRY is set. If it is, CARRY is clear.
1E0EH-1E10H
LD BC,1997H
Load register pair BC with a return address which will return to the ?SN ERROR routine.
1E11H
PUSH BC
Save the ?SN ERROR address (in register pair BC) to the stack.
1E12H
RET C
Return if the character at the location of the current BASIC program pointer in register A isn’t alphabetic (meaning that DEF??? wasn’t followed by a letter).
1E13H-1E14H
SUB 41H
Subtract 41H from the letter’s value in register A so that it will be in the range of 0-25.
1E15H
LD C,A
Load register C with the adjusted value in register A.
1E16H
LD B,A
Load register B with the adjusted value in register A.
1E17H
RST 10H
Since we now need bump the value of the current BASIC program pointer until it points to the next character, 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.
1E18H-1E19H
CP 0CEH
Check to see if the character at the location of the current BASIC program pointer in register A is a -.
1E1AH-1E1BH
If it’s not a - we know this isn’t a range, so jump to 1E25H because we don’t need to get any more variables.
1E1CH
RST 10H
If we are here, then we know the DEF??? has a range, so we need another character. We bump the value of the current BASIC program pointer until it points to the next character, 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.
1E1DH-1E1FH
A call to 1E3DH checks the value at memory location (HL), which would be the current BASIC program pointer, to see if it is a letter. If its not, CARRY is set. If it is, CARRY is clear.
1E20H
RET C
Return if the character at the location of the current BASIC program pointer in register A isn’t alphabetic.
1E21H-1E22H
SUB 41H
Subtract 41H from the letter’s value in register A so that it will be in the range of 0-25.
1E23H
LD B,A
Load register B with the adjusted value in register A.
1E24H
RST 10H
Since we now need bump the value of the current BASIC program pointer until it points to the next character, 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.
1E25H
LD A,B
Load register A with the value of the second letter in register B.
1E26H
SUB C
Subtract the value of the first letter in register C from the value of the second letter in register A.
1E27H
RET C
If the varible names are not in ascending order (the one in C is earlier than the one in A), return (to a syntax error).
1E28H
INC A
Bump the value in register A so that it holds the number of variable names to be changed.
1E29H
EX (SP),HL
Clear the error address and save the current code string address.
1E2AH-1E2CH
LD HL,4101H
Load register pair HL with the starting address of the variable declaration table.
Note: 4101H-411AH holds Variable Declaration Table.
1E2DH-1E2EH
LD B,00H
Load register B with zero.
1E2FH
ADD HL,BC
Find the next entry in the type table by adding the value of the first letter in register pair BC to the value of the starting address of the variable declaration table in register pair HL.
1E30H
LD (HL),E
E was set on entry to string, integer, single precision, or double precision as applicable. Save the number type flag in register E at the location of the memory pointer in register pair HL.
1E31H
INC HL
Bump the value of the memory pointer in register pair HL.
1E32H
DEC A
Decrement the count of the number of variables to be changed in register A.
1E33H-1E34H
Loop until all of the variables in the DEFSTR range have been changed.
1E35H
POP HL
Restore the code string pointer into register pair HL.
1E36H
LD A,(HL)
Load A with the character at the location of the current BASIC program pointer in register pair HL.
1E37H-1E38H
CP 2CH
Check to see if the character at the location of the current BASIC program pointer in register A is a ,.
1E39H
RET NZ
Return if the character at the location of the current BASIC program pointer in register A isn’t a ,.
1E3AH
RST 10H
Since we now need bump the value of the current BASIC program pointer until it points to the next character, 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.
1E3BH-1E3CH
Loop until done with all the variables.

1E3DH-1E44H – EXAMINE VARIABLE

  • This routine tests the value pointed to by the HL register pair and sets the C flag if it is an ASCII letter value. Otherwise it resets the C flag.
1E3DH
LD A,(HL)
Load register A with the character at the location of the current BASIC program pointer in register pair HL.
1E3EH-1E3FH
CP 41H
Check to see if the character at the location of the current BASIC program pointer in register A is less than an A.
1E40H
RET C
Return if the character at the location of the current BASIC program pointer in register A is less than an A.
1E41H-1E42H
CP 5BH
Check to see if the character at the location of the current BASIC program pointer in register A is greater than a Z.
1E43H
CCF
Complement the value of the Carry flag. On exit this routine will have the Carry flag set if the character at the location of the current BASIC program pointer in register A isn’t alphabetic and will have the Carry flag cleared if the character at the location of the current BASIC program pointer in register A is alphabetic.
1E44H
RET
Return.

1E45H-1E4EH – EXAMINE VARIABLE

  • This is called when evaluating a subscript for a variable reference. It will evaluate if the value is positive or negative.
1E45H
RST 10H
Get the next symbol from the input. Bump the value of the current BASIC program pointer until it points to the next character, 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.
1E46H-1E48H
Go evaluate the expression at the current location of the BASIC program pointer in register pair HL and return with the integer result in register pair DE.
1E49H
RET P
Return if the integer result in register pair DE is positive. If it is negative, flow down to the ?FC ERROR.

1E4AH – FC ERROR entry point.

1E4AH-1E4BH
LD E,08H
Load register E with an ?FC ERROR code.
1E4CH-1E4EH
Display a ?FC ERROR message. If this is from a pass through, the error wll show if the integer result in register pair DE is negative.

1E4FH-1E79H – ASCII TO BINARY

1E4FH
LD A,(HL)
Load register A with the character at the location of the current BASIC program pointer in register pair HL.
1E50H-1E51H
CP 2EH
Check to see if the character at the location of the current BASIC program pointer in register A is a ..
1E52H
EX DE,HL
Load register pair DE with the value of the current BASIC program pointer in register pair HL.
1E53H-1E55H
LD HL,(40ECH)
Load register pair HL with the current BASIC line number.
Note: 40ECH-40EDH holds EDIT line number.
1E56H
EX DE,HL
Exchange the value of the current BASIC program pointer in register pair DE with the current BASIC line number in register pair HL.
1E57H-1E59H
Jump to the RST 10H (EXAMINE NEXT SYMBOL) routine if the character at the location of the current BASIC program pointer in register A is a ..

1E5AH – Converts numeric ASCII string pointed to by the HL register pair, to HEX and places the result in the DE register pair. 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 there is no string at the location pointed to by HL the routine will return a MO ERROR (missing operand). If the result in the DE register pair exceeds FFFFH an OV ERROR (overflow) results.

1E5AH
“DECBIN”
DEC HL
Backspace HL (the current BASIC program pointer) to the current character.
1E5BH-1E5DH
LD DE,0000H
Load register pair DE with zero.
1E5EH
RST 10H
Re-process that previous character through a RST 10H call.
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.
1E5FH
RET NC
Return if the character at the location of the current BASIC program pointer in register A isn’t numeric.
1E60H
PUSH HL
Save the value of the current BASIC program pointer in register pair HL to the stack.
1E61H
PUSH AF
Save the value in register pair AF (which is the digit plus flags resulting from the RST 10H call) to the stack.
1E62H-1E64H
LD HL,1998H
Load register pair HL with 6552.
1E65H
RST 18H
Now we need to check to see if the integer value in DE is greater than 6552, 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).
1E66H-1E68H
JP C,1997H
Go to the Level II BASIC error routine and display a SN ERROR message if the value in register pair DE is greater than 6552.
1E69H
LD H,D
Load register H with the MSB of the integer total in register D.
1E6AH
LD L,E
Load register L with the LSB of the integer total in register E.
1E6BH
ADD HL,DE
Multiply the integer value in register pair HL by two.
1E6CH
ADD HL,HL
Multiply the integer value in register pair HL by two. The integer result in register pair HL is now equal to the integer value in register pair DE times four.
1E6DH
ADD HL,DE
Add the integer value in register pair DE to the integer value in register pair HL. The integer result in register pair HL is now equal to the integer value in register pair DE times five.
1E6EH
ADD HL,HL
Multiply the integer value in register pair HL by two. The integer result in register pair HL is now equal to the integer value in register pair DE times ten.
1E6FH
POP AF
Put the last ASCII digit (from the stack) into AF.
1E70H-1E71H
SUB 30H
Convert the ASCII digit in register A to binary.
1E72H
LD E,A
Load register E with the binary value of the character in register A.
1E73H-1E74H
LD D,00H
Load register D with zero so that DE will be 0000 through 0009 (the binary equivalent of the digit).
1E75H
ADD HL,DE
Add the binary value of the character in register pair DE to the integer value in register pair HL.
1E76H
EX DE,HL
Set DE to be 10(base 10) * DE + A.
1E77H
POP HL
Restore the pointer to the next digit (from the stack) into HL.
1E78H-1E79H
Loop until the ASCII to binary conversion has been completed.

1E7AH-1EA0H – LEVEL II BASIC CLEAR ROUTINE

1E7AH-1E7CH
Jump to 1B61H (which will set all 26 variables to single precision) if there isn’t a number of bytes specified to clear for string space.
1E7DH-1D7FH
Go evaluate the number of bytes to be reserved for string space and return with the integer result in register pair DE.
1E80H
DEC HL
Decrement the current BASIC program pointer in register pair HL.
1E81H
RST 10H
Evaluate the next instruction through a RST 10H call. This will bump the value of the current BASIC program pointer until it points to the next character, 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.
1E82H
RET NZ
Return out of the routine if the character at the location of the current BASIC program pointer isn’t an end of the BASIC statement character.
1E83H
PUSH HL
Save the value of the current BASIC program pointer in register pair HL to the stack.
1E84H-1E86H
LD HL,(40B1H)
Load the top of memory pointer into register pair HL.
Note: 40B1H-40B2H holds MEMORY SIZE? pointer.
1E87H
LD A,L
Load register A with the LSB of the top of memory pointer in register L.
1E88H
SUB E
Subtract the LSB of the number of bytes for string space in register E from the LSB of the top of memory pointer in register A.
1E89H
LD E,A
Load register E with the LSB of the start of string space in register A.
1E8AH
LD A,H
Load register A with the MSB of the top of memory pointer in register H.
1E8BH
SBC A,D
Subtract the MSB of the number of bytes for string space in register D from the MSB of the top of memory pointer in register A.
1E8CH
LD D,A
Load register D with the MSB of the start of string space pointer in register A.
1E8DH-1E8FH
JP C,197AH
If the CARRY flag was triggered there isn’t enough memory for the amount of string space specified, so go show a ?OM ERROR message.
1E90H-1E92H
LD HL,(40F9H)
Load register pair HL with the end of the BASIC program pointer.
  • Note: 40F9H-40FAH holds the starting address of the simple variable storage area.
1E93H-1E95H
LD BC,0028H
Load register pair BC with the least amount of space needed for BASIC program variables.
1E96H
ADD HL,BC
Add the value in register pair BC to the end of BASIC program pointer in register pair HL.
1E97H
RST 18H
Now we need to check to the adjusted end of the BASIC program pointer (in HL) with the start of the string space pointer (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).
1E98H-1E9AH
JP NC,197AH
Display an ?OM ERROR message if the start of string space pointer in register pair DE is less than the adjusted end of the BASIC program pointer in register pair HL.
1E9BH
EX DE,HL
Put the new start of the string area address into HL.
1E9CH-1E9EH
LD (40A0H),HL
Load the start of string space pointer with HL.
  • Note: 40A0H-40A1H holds the start of string space pointer.
1E9FH
POP HL
Restore the code string pointer back into HL.
1EA0H-1EA2H
Jump to 1B61H.

1EA3H-1EB0H – LEVEL II BASIC RUN ROUTINE

1EA3H-1EA5H
Jump to 1B5DH if there isn’t a line number specified after the RUN token.
1EA6H-1EA8H
Call the DOS line at 41C7H.
In NEWDOS 2.1, this processes a RUN nnnn statement.
1EA9H-1EABH
GOSUB to 1B61H to initialize the BASIC variables and pointers.
1EACH-1EAEH
LD BC,1D1EH
Load register pair BC with the continuation addres in the execution driver.
1EAFH-1EB0H
Jump to 1EC1H to use the GOTO code to begin execution at the nnnn line.

1EB1H-1EC1H – LEVEL II BASIC GOSUB ROUTINE
Can be used to execute the equivalent of a GOSUB statement from an assembly program. It allows a BASIC subroutine to be called from an assembly subroutine. After the BASIC subroutine executes, control returns to the next statement in the assembly program. All registers are used. On entry, the HL must contain an ASCII string with the starting line number of the subroutine.

1EB1H-1EB2H
LD C,03H
Load register B with the number of bytes needed for the GOSUB push.
1EB3H-1EB5H
Go make sure that there’s enough memory for the GOSUB push.
1EB6H
POP BC
Get the return address from the stack and put it in register pair BC.
1EB7H
PUSH HL
Save the value of the current BASIC program pointer in register pair HL to the stack.
1EB8H
PUSH HL
Create a hole to be filled in later by once again saving the value of the current BASIC program pointer to the stack.
1EB9H-1EBBH
LD HL,(40A2H)
Load register pair HL with the value of the current BASIC line number in binary.
Note: 40A2H-40A3H holds the current BASIC line number.
1EBCH
EX (SP),HL
Put the binary value for the current line number into the hole in the stack AND restore the code string pointer.
1EBDH-1EBEH
LD A,91H
Load register A with a GOSUB token.
1EBFH
PUSH AF
Save the GOSUB marker (in register pair AF) to the stack.
1EC0H
INC SP
Bump the value of the stack pointer.
1EC1H
PUSH BC
Save the return address in register pair BC (which is to the GOTO code) to the stack.

1EC2H-1EDDH – LEVEL II BASIC GOTO ROUTINE

1EC2H-1EC4H
We need to put the line number to branch to into DE so we call ASCII TO INTEGER routine at 1E5A.
NOTE:
  • The routine at 1E5A converts the ASCII string pointed to by HL to an integer deposited into DE. If the routine finds a non-numerica character, the conversion is stopped
1EC5H-1EC7H
Go bump the current BASIC program pointer in register pair HL until it points to the end of the current BASIC line.
1EC8H
PUSH HL
Save the value of the current BASIC program pointer in register pair HL to the stack.
1EC9H-1ECBH
LD HL,(40A2H)
Load register pair HL with the binary equivalent of the last line number.
Note: 40A2H-40A3H holds the current BASIC line number.
1ECCH
RST 18H
Now we need to compare the value of the current BASIC line number (in HL) with the value of the line number to branch to (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).
1ECDH
POP HL
Get the value of the current BASIC program pointer from the stack and put it in register pair HL.
1ECEH
INC HL
Bump the value of the current BASIC program pointer in register pair HL so as to restore the code string address. DE holds the line number specified.
1ECFH-1ED1
If the line number to branch to (in register pair DE) is greater than the current BASIC line number then go find where the line number is located.
1ED2H-1ED4
If the line number to branch to (in register pair DE) is less than the current BASIC line number, then go find where the line number is located by calling the SEARCH FOR LINE NUMBER routine at 1B2CH which looks for the line number specified in DE. Returns C/Z with the line found in BC, NC/Z with line number is too large and HL/BC having the next available location, or NC/NZ with line number not found, and BC has the first available one after that.
1ED5H
LD H,B
Load register H with the MSB of the new BASIC program pointer in register B. BC is still holding the address of the requested line number.
1ED6H
LD L,C
Load register L with the LSB of the new BASIC program pointer in register C.
1ED7H
DEC HL
Decrement the value of the current BASIC program pointer in register pair HL to get to the start of the line.
1ED8H
RET C
If a line number was found, RETURN from this routine to the execution driver (to start execution at the new line number).
1ED9H-1EDAH
LD E,0EH
Load register E with an ?UL ERROR code.
1EDBH-1EDDH
Since the line number wasn’t found, display a ?UL ERROR message.

1EDEH-1E04H – LEVEL II BASIC RETURN ROUTINE

  • Returns control to the BASIC statement following the last GOSUB call. An assembly program called by a BASIC subroutine may wish to return directly to the orginal caller without returning through the subroutine entry point. This exit can be used for that return. The return address to the stack for the call to the assembly program must be cleared before returning via 1EDFH.
1EDEH
RET NZ
Display a ?SN ERROR message if there is anything following the RETURN token.
1EDFH-1EE0H
LD D,FFH
Load register D with FFH (a dummy address for the search routine).
1EE1H-1EE3H
Go backspace the stack pointer by four and return with the value at the location of the stack pointer in register A.
1EE4H
LD SP,HL
Load the stack pointer with the new value in register pair HL.
1EE5H-1EE7HS
LD (40E8H),HL
Save the stack pointer position in register pair HL.
Note: 40E8H-40E9H holds Stack pointer pointer.
1EE8H-1EE9H
CP 91H
Check to see if the value in register A is a GOSUB token.
1EEAH-1EEBH
LD E,04H
Load register E with a ?RG ERROR code.

1EECH – RG ERROR entry point.

1EECH-1EEEH
Display a ?RG ERROR message if there isn’t a GOSUB push to the stack.
1EEFH
POP HL
Get the binary value of the GOSUB line number from the stack and put it in register pair HL.
1EF0H-1EF2H
LD (40A2H),HL
Save the GOSUB line number in register pair HL as the current BASIC line number.
Note: 40A2H-40A3H holds the current BASIC line number.
1EF3H
INC HL
Bump the value of the current BASIC line number in register pair HL.
1EF4H
LD A,H
Load register A with the MSB of the adjusted current BASIC 1ine number in register pair HL.
1EF5H
OR L
Combine the LSB of the adjusted current BASIC line number in register L with the adjusted MSB of the current BASIC line number in register A. This is a test for an overflow or command mode
1EF6H-1EF7H
Jump if Level II BASIC is in the command mode.
1EF8H-lEFAH
LD A,(40DDH)
If we are here, we may have a one liner! Load register A with the command mode flag.
Note: 40DDH holds INPUT flag.
lEFBH
OR A
Check for the command mode.
1EFCH-1EFEH
Jump to 1A18H if Level II BASIC is in the command mode.
1EFFH-1F01H
LD HL,1D1EH
Load register pair HL with the return address.
1F02H
EX (SP),HL
Exchange the value of the current BASIC program pointer to the stack with the return address in register pair HL.
1F03H
3E E1
Z-80 Trick! See the general explanation at 10F8H.
1F04H
POP HL
Scan to the end of the GOSUB.

1F05H-1F20H – SCAN ROUTINE

  • This is also the DATA entry point.
1F05H
01
Z-80 Trick! See the general explanation at 10F8H.
1F06H
3A
Z-80 Trick! See the general explanation at 10F8H.
1F07H-1F08H
LD C,00H
Load register C with zero.
1F09H-1F0AH
LD B,00H
Load register B with zero.
1F0BH
LD A,C
Load register A with the stop scan character in register C.
1F0CH
LD C,B
Load register C with the stop scan character in register B.
1F0DH
LD B,A
Load register B with the stop scan character in register A.
1F0EH
LD A,(HL)
Load register A with the character at the location of the current BASIC program pointer in register pair HL.
1F0FH
OR A
Check to see if the character at the location of the current BASIC program pointer in register A is an end of the BASIC line character.
1F10H
RET Z
Return if the character at the location of the current BASIC program pointer in register A is an end of the BASIC line character.
1F11H
CP B
Check to see if the character at the location of the current BASIC program pointer in register A is the same as the stop scan character in register B.
1F12H
RET Z
Return if the character at the location of the current BASIC program pointer in register A is the same as the stop scan character in register B.
1F13H
INC HL
Bump the value of the current BASIC program pointer in register pair HL.
1F14H-1F15H
CP 22H
Check to see if the character at the location of the current BASIC program pointer in register A is a quote.
1F16H-1F17H
Loop if the character at the location of the current BASIC program pointer in register A is a quote.
1F18H-1F19H
SUB 8FH
Check to see if the character at the location of the current BASIC program pointer in register A is a IF token.
1F1AH-1F1BH
Loop back to 1F0EH if the character at the location of the current BASIC program pointer in register A isn’t an IF token.
1F1CH
CP B
Check to see if the character at the location of the current BASIC program pointer in register A is the same as the character in register B.
1F1DH
ADC A,D
Add the value in register D to the value in register A.
1F1EH
LD D,A
Load register D with the value in register A.
1F1FH-1F20H
Loop back to 1F0EH until scan is completed.

1F21H-1F6BH – LEVEL II BASIC LET ROUTINE

1F21H-1F23H
Call the FIND ADDRESS OF VARIABLE routine at 260DH which searches the Variable List Table for a variable name which matches the name in the string pointed to in HL, and return the address of that variable in DE (and if there is no variable, it creates it, zeroes it, and returns THAT location).
1F24H-1F25H
RST 08H
D5H
Test if the variable name is followed by a =. Since the character at the location of the current BASIC program pointer in register pair HL must be an EQUAL sign (D5) so call the 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 Aregister and HL incremented by one. If the two characters do not match, a syntax error message is given and control returns to the Input Phase).
1F25H
PUSH DE
1F26H
EX DE,HL
Exchange the address of the variable in register pair DE with the value of the current BASIC program pointer in register pair HL.
1F27H-1F29H
LD (40DFH),HL
Save the addres of the variable in register pair HL.
Note: 40DFH-40E0H holds Used by DOS.
1F2AH
EX DE,HL
Exchange the value of the current BASIC program pointer in register pair DE with the address of the variable in register pair HL.
1F2BH
PUSH DE
Save the address of the variable in register pair DE to the stack.
1F2CH
RST 20H
We need to check the value of the current number type flag, so we call the TEST DATA MODE routine at RST 20H.
NOTE: The RST 20H routine determines the type of the current value in REG 1 and returns a combination of STATUS flags and unique numeric values in the A Register according to the data mode flag (40AFH).

The results are returned as follows:
  • Integer = NZ/C/M/E and A is -1
  • String = Z/C/P/E and A is 0
  • Single Precision = NZ/C/P/O and A is 1
  • and Double Precision is NZ/NC/P/E and A is 5.
1F2DH
PUSH AF
Save the value in register pair AF to the stack. A will be -1 for an integer, 0 for a string, 1 for single precision, and 5 for double precision.
1F2EH-1F30H
Go evaluate the expression at the location of the current BASIC program pointer in register pair HL and return with the result in REG 1.
1F31H
POP AF
Get the value from the stack and put it in register pair AF.
1F32H
EX (SP),HL
Exchange the address of the variable to the stack with the value of the current BASIC program pointer in register pair HL.
1F33H-1F34H
ADD A,03H
Adjust the value in register A so that it will hold the correct number type flag (i.e., A will be 2 for integer, 3 for string, 4 for single precision, and 8 for double precision).
1F35H-1F37H
Go to 2819H to convert the result in REG 1 to the same number type for the variable .
1F38H-1F3AH
Go save the result of the expression.
1F3BH
PUSH HL
Save the address of the variable in register pair DE to the stack.
1F3CH-1F3DH
Jump if the result of the expression wasn’t a string.
1F3EH-1F40H
LD HL,(4121H)
Load register pair HL with the starting address of the string’s VARPTR in REG 1.
1F41H
PUSH HL
Save the VARPTR for the string result in register pair HL to the stack.
1F42H
INC HL
Bump the value of the VARPTR for the string result in register pair HL.
1F43H
LD E,(HL)
Load register E with the LSB of the address for the string at the location of the VARPTR for the string in register pair HL.
1F44H
INC HL
Bump the value of the VARPTR for the string result in register pair HL.
1F45H
LD D,(HL)
Load register D with the MSB of the address for the string at the location of the VARPTR for the string in register pair HL.
1F46H-1F48H
LD HL,(40A4H)
Load register pair HL with the start of the BASIC program.
  • Note: 40A4H-40A5H holds the starting address of BASIC program text also known as the PROGRAM STATEMENT TABLE (PST).
1F49H
RST 18H
Now we need to compare the start of the BASIC program area (in HL) with the address of the string result 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).
1F4AH-1F4BH
Jump if the address of the string result in register pair DE is less than the start of the BASIC program area in register pair HL.
1F4CH-1F4EH
LD HL,(40A0H)
Load register pair HL with the start of the string space pointer.
  • Note: 40A0H-40A1H holds the start of string space pointer.
1F4FH
RST 18H
Now we need to compare the start of the string space pointer (in HL) with the address of the string result 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).
1F50H
POP DE
Get the VARPTR for the string result from the stack and put it in register pair DE.
1F51H-1F52H
Jump if the address of the string result in register pair DE was less than the start of the string space pointer in register pair HL.
1F53H-1F55H
LD HL,(40F9H)
Load register pair HL with the simple variables pointer.
  • Note: 40F9H-40FAH holds the starting address of the simple variable storage area.
1F56H
RST 18H
Now we need to compare the address of the VARPTR for the string result in register pair DE with the simple variables pointer in register pair HL, 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).
1F57H-1F58H
Jump if the address of the VARPTR for the string result in register pair DE is less than the simple variables pointer in register pair HL.
1F59H-1F5AH
3E D1
LD A,D1H
Z-80 Trick
1F5AH
POP DE
Get the VARPTR for the string result from the stack and put it in register pair DE.
1F5BH-1F5DH
Go adjust the temporary string work area pointers.
1F5EH
EX DE,HL
Exchange the VARPTR for the string in register pair DE with the string’s address in register pair HL.
1F5FH-1F61H
Go move the string into string space.
1F62H-1F64H
Go adjust the temporary string work area pointers.
1F65H
EX (SP),HL
Exchange the address of the variable in register pair BL with the address of the variable to the stack.
1F66H-1F68H
Go move the result to its proper location in memory.
1F69H
POP DE
Get the address of the variable from the stack and put it in register pair DE.
1F6AH
POP HL
Get the value of the current BASIC program pointer from the stack and put it in register pair HL.
1F6BH
RET
Return.

1F6CH-1FAEH – LEVEL II BASIC ERROR ON ROUTINE

1F6CH-1F6DH
CP 9EH
Check to see if the character at the location of the current BASIC program pointer in register A is an ERROR token (since this is supposed to be ON ERROR.
1F6EH-1F6FH
Jump down to 1F95H if the character at the location of the current BASIC program pointer in register A isn’t an ERROR token.
1F70H
RST 10H
If we are here, we have ON ERROR but we do need to see what’s next. Since we now need bump the value of the current BASIC program pointer until it points to the next character, 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.
1F71H-1F72H
RST 08H
8DH
The next valid character at the location of the current BASIC program pointer in register pair HL must be a GOTO token (=8DH) so call the 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 Aregister and HL incremented by one. If the two characters do not match, a syntax error message is given and control returns to the Input Phase).
1F73H-1F75H
Convert the next constant into binary (with the result in DE). To do this, call the ASCII TO INTEGER routine at 1E5A.
NOTE:
  • The routine at 1E5A converts the ASCII string pointed to by HL to an integer deposited into DE. If the routine finds a non-numerica character, the conversion is stopped
1F76H
LD A,D
Load register A with the MSB of the line number in register D.
1F77H
OR E
Combine the LSB of the line number in register E with the MSB of the line number in register A to see if we have a zero as in ON ERROR GOTO 0000.
1F78H-1F79H
Jump to 1F83H if the line number in register pair DE is equal to zero.
1F7AH-1F7CH
Go find the location of the line number in register pair DE and return with the location of the line number in register pair BC.
1F7DH,1F7EH
LD D,B
LD E,C
Put the line number from BC into DE
1F7FH
POP HL
Get the value of the current BASIC program pointer from the stack and put it in register pair HL.
1F80H-1F82H
JP NC,1ED9H
Display a ?UL ERROR message if the BASIC line doesn’t exist.
1F83H
EX DE,HL
Exchange the location of the BASIC line in register pair DE with the value of the current BASIC pro gram pointer in register pair HL.
1F84H-1F86H
LD (40F0H),HL
Save the location of the BASIC line in register pair HL.
Note: 40F0H-40F1H is used by ON ERROR.
1F87H
EX DE,HL
Exchange the value of the current BASIC program pointer in register pair DE with the location of the BASIC line in register pair HL.
1F88H
RET C
RETURN out of this routine to the execution driver if it was not ON ERROR GOTO 0000.
1F89H-1F8BH
LD A,(40F2H)
Load register A with the value of the error flag.
Note: 40F2H holds Error flag.
1F8CH
OR A
Check to see if the error flag is set.
1F8DH
RET Z
RETURN out of this routine to the execution driver if the override flag is not set.
1F8EH-1F90H
LD A,(409AH)
Load register A with the error code.
Note: 409AH holds the RESUME flag.
1F91H
LD E,A
Load register E with the value of the error code in register A.
1F92H-1F94H
Go to the Level II error routine and display the error message for the error code in register E.

1F95H – Still in the ON routine, but we know it isn’t ON ERROR. We now need to deal with the possibility that it was an ON n GOTO or ON n GOSUB.

1F95H-1F97H
First we need to get the n so go evaluate the expression at the location of the current BASIC program pointer and return with the result in register pair DE.
1F98H
LD A,(HL)
Load register A with the next character (which should be a token) at the location of the current BASIC program pointer in register pair HL.
1F99H
LD B,A
Save that token into register B.
1F9AH-1F9BH
CP 91H
Check to see if the character at the location of the current BASIC program pointer in register A is a GOSUB token.
1F9CH-1F9DH
Skip the next 2 opcodes if the character at the location of current BASIC program pointer in register A is a GOSUB token .
1F9EH-1F9FH
RST 08H
8DH
Now let’s test to see if the next character is the token for a GOTO, call the 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 Aregister and HL incremented by one. If the two characters do not match, a syntax error message is given and control returns to the Input Phase).
1FA0H
DEC HL
Decrement the value of the current BASIC program pointer in register pair HL to point to the GOTO token.
1FA1H
LD C,E
Load register C with the LSB of the expression after the ON token in register E (i.e., the “n” from ON n GOTO).
1FA2H
DEC C
Decrement the line number counter in register C.
1FA3H
LD A,B
Load register A with the token in register B (which is either a GOSUB or GOTO token).
1FA4H-1FA6H
Jump to 1D60H if the line number has been found.
1FA7H-1FA9H
Evaluate the line number at the location of the current BASIC program pointer and return with the result in register pair DE.
1FAAH-1FABH
CP 2CH
Check to see if the character at the location of the current BASIC program pointer in register A is a comma. If not, it is the ent of the statement.
1FACH
RET NZ
Return if the character at the location of the current BASIC program pointer in register A isn’t a ,.
1FADH-1FAEH
Loop until the line number has been located.

1FAFH-1FF3H – LEVEL II BASIC RESUME ROUTINE

1FAFH-1FB1H
LD DE,40F2H
Load register pair DE with the address of the Level II BASIC error flag.
Note: 40F2H holds Error flag.
1FB2H
LD A,(DE)
Load register A with the error flag at the location of the memory pointer in register pair DE. It will be FF if there is an error, and a zero otherwise.
1FB3H
OR A
Check for an error.
1FB4H-1FB6H
If there was no error, then display an ?RW ERROR message.
1FB7H
INC A
Clear the error flag in register A.
1FB8H-1FBAH
LD (409AH),A
Save the new error flag in register A.
Note: 409AH holds the RESUME flag.
1FBBH
LD (DE),A
Save the new error flag in register A at the location of the memory pointer in register pair DE.
1FBCH
LD A,(HL)
Load register A with the character at the location of the current BASIC program pointer in register pair HL.
1FBDH-1FBEH
CP 87H
Check to see if the character at the location of the current BASIC program pointer in register A is a NEXT token.
1FBFH-1FC0H
Jump down to 1FCDH if the character at the location of the current BASIC program pointer in register A is a NEXT token (as in RESUME NEXT).
1FC1H-1FC3H
Get the binary equivalent of the line number into DE by calling the ASCII TO INTEGER routine at 1E5A.
NOTE:
  • The routine at 1E5A converts the ASCII string pointed to by HL to an integer deposited into DE. If the routine finds a non-numerica character, the conversion is stopped
1FC4H
RET NZ
Return to the execution driver if there wasn’t a line number at the location of the current BASIC program pointer.
1FC5H
LD A,D
Load register A with the MSB of the line number in register D.
1FC6H
OR E
Combine the LSB of the line number in register E with the MSB of the line number in register A.
1FC7H-1FC9H
Jump to the GOTO code at 1EC5H if the line number in register pair DE isn’t equal to zero (i.e., it was RESUME nnnn).
1FCAH
INC A
Bump the value in register A so that it will indicate RESUME 0.
1FCBH-1FCCH
Jump to the RESUME 0 at 1FCFH.
1FCDH
RST 10H
Since we now need bump the value of the current BASIC program pointer until it points to the next character, 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.
1FCEH
RET NZ
Return if this is the end of the BASIC statement.

1FCFH – This is the RESUME 0 routine

1FCFH-1FD1H
LD HL,(40EEH)
Get the value of the current BASIC program pointer and put it in register pair HL.
Note: 40EEH-40EFH is used by RESUME.
1FD2H
EX DE,HL
Load register pair DE with the value of the current BASIC program pointer in register pair HL.
1FD3H-1FD5H
LD HL,(40EAH)
Load register pair HL with the current BASIC line number.
Note: 40EAH-40EBH holds Line number with error.
1FD6H-1FD8H
LD (40A2H),HL
Save the value of the current BASIC line number in register pair HL. This is where we will resume execution.
Note: 40A2H-40A3H holds the current BASIC line number.
1FD9H
EX DE,HL
Load register pair HL with the value of the current BASIC program pointer in register pair DE.
1FDAH
RET NZ
Return to the execution driver if this is RESUME 0.
1FDBH
LD A,(HL)
Get the character at the location of the current BASIC program pointer in register pair HL and put it in register A.
1FDCH
OR A
Check the character at the location of the current BASIC program pointer in register A to see if its an end of the BASIC line character.
1FDDH-1FDEH
Jump forward to 1FE3H if the character at the location of the current BASIC program pointer in register A isn’t an end of the BASIC line character.
1FDFH
INC HL
Bump the value of the current BASIC program pointer in register pair HL to skip over the zero byte terminator.
1FE0H
INC HL
Bump the value of the current BASIC program pointer in register pair HL to skip over the LSB of the pointer to the next statement.
1FE1H
INC HL
Bump the value of the current BASIC program pointer in register pair HL to skip over the MSB of the pointer to the next statement.
1FE2H
INC HL
Bump the value of the current BASIC program pointer in register pair HL to skip over the LSB of the line number in binary for the line following the error.
1FE3H
INC HL
Bump the value of the current BASIC program pointer in register pair HL to skip over the MSB of the line number in binary for the line following the error.
1FE4H
LD A,D
Load register A with the MSB of the line number with the error in register D.
1FE5H
AND E
Combine the LSB of the line number with the error in register E with the MSB of the line number with the error in register A. This begins the test for the end of program marker.
1FE6H
INC A
Bump the combined value of the line number with the error in register A. This will finish the test of DE by turning the FFFFH into 0000H.
1FE7H-1FE9H
Jump to 1F05H if Level II BASIC isn’t in the command mode.
1FEAH-1FECH
LD A,(40DDH)
Load register A with the command mode flag.
Note: 40DDH holds INPUT flag.
1FEDH
DEC A
Check to see if the command mode flag in register A is set.
1FEEH-1FF0H
Jump to 1DBEH if Level II BASIC is in the command mode.
1FF1H-1FF3H
Exit the routine by jumping to 1F05H.

1FF4H-2007H – LEVEL II BASIC ERROR ROUTINE

  • This evaluates n for ERROR n.
1FF4H-1FF6H
Go evaluate the expression at the location of the current BASIC program pointer in register pair HL and return with the result in A.
1FF7H
RET NZ
Return if this isn’t the end of the BASIC statement.
1FF8H
OR A
Set up to check to see if the error number in register A is equal to zero.
1FF9H-1FFBH
Display an ?FC ERROR message if the error code in register A is equal to zero.
1FFCH
DEC A
Subtract one from the error code in register A.
1FFDH
ADD A,A
Multiply the error code in register A by two (so now A = 2(A-1)).
1FFEH
LD E,A
Load register E with 2(A-1).
1FFFH-2000H
CP 2DH
Check to see if the error code in register A is less than 45.
2001H-2002H
Jump forward 1 instruction (i.e., skip the line that sets up for an error of ?UE ERROR) if the error code (in register A) is in range (i.e., less than 45).