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.

This routine initializes the input buffer for an ASCII conversion. It is called by the FLOATING to ASCII Conversion Routine (at 0FBEH) and by the BINARY to ASCII Conversion Routine (at 0FAFH).

Note: 40D8H-40D9H holds the temporary storage location.

Note: 4130H-4149H holds Internal print buffer.

This routine gets called by the FLOATING to ASCII Conversion Routine (0FBEH-0FC0H) if the value being converted is either Single Precision or Double Precision.

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.

Note: 4130H-4149H holds Internal print buffer.

Alternative interpretation is Jump to 11A3H if the variable is a string; which will leave us now with only an integer value.

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

Note: 40F3H-40F4H holds the temporary storage location.

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.

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.

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

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=00H if REG 1 = BCDE
- A=01H if REG 1>BCDE; and
- A=FFH if REG 1<BCDE.

Note: 40F3H-40F4H holds the temporary storage location.

or

LD BC, 1E06H

1201 – 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).

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.

Note: 4127H-412EH holds REG 2.

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.

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=00H if REG 1 = BCDE
- A=01H if REG 1>BCDE; and
- A=FFH if REG 1<BCDE.

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.

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=00H if REG 1 = BCDE
- A=01H if REG 1>BCDE; and
- A=FFH if REG 1<BCDE.

This routine puts leading zeroes into the input buffer

Note: 40D8H-40D9H holds the temporary storage location.

1291 – Count the leading digits before the decimal point.

Note: 40F3H-40F4H holds the temporary storage location.

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

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.

Note: 411DH-4124H holds REG l.

12EA – 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.

130A – 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.

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

1348 – 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).

1364-136B – DOUBLE PRECISION CONSTANT STORAGE LOCATION

136C-1373 – DOUBLE PRECISION CONSTANT STORAGE LOCATION

1374-137B – DOUBLE PRECISION CONSTANT STORAGE LOCATION

137C-1383 – DOUBLE PRECISION CONSTANT STORAGE LOCATION

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.

1384-138B – DOUBLE PRECISION CONSTANT STORAGE LOCATION

138C-13D1 – DOUBLE PRECISION INTEGER CONSTANT STORAGE LOCATION

13D2-13D9 – SINGLE PRECISION INTEGER CONSTANT STORAGE LOCATION

13E1-13E6 – LEVEL II BASIC MATH ROUTINE

13E7-13F1 – 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.

“SQRT”

13F2-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).

- 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.

/0 ERROR entry point.

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=00H if REG 1 = BCDE
- A=01H if REG 1>BCDE; and
- A=FFH if REG 1<BCDE.

1439 – 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.

“EXP”

1479-1499 – SINGLE PRECISION CONSTANT STORAGE LOCATION

This represents 1/6, -1/5, 1/4, -1/3, 1/2, -1, and 1

149A-14C8 – 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.

POP DE

PUSH BC

14C9-1540 – 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.

“RNDM”

- 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.

POP DE

14F0 – 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.

Note: 40AAH-40ADH holds the random number seed.

Note: 40AAH-40ADH holds the random number seed.

Note: 4125H-4126H is used by floating point routines.

1541-1546 – 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.

“COSN”

1547-158A – 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:
- Assume X <= 360 degrees.
- Recompute x as x=x/360 so that x=< 1.
- If x <= 90 degrees go to step 7.
- If x <= 180 degrees then x=0.5-x and then go to step 7.
- If x <= 270 degrees then x=0.5-x.
- Recompute x as x=x-1.0.
- 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.

“SINE”

POP DE

POP DE

158B-158E – SINGLE PRECISION CONSTANT STORAGE LOCATION

158F-1592 – SINGLE PRECISION CONSTANT STORAGE LOCATION

1593-15A7 – SINGLE PRECISION CONSTANTS STORAGE LOCATION

15A8-15BC – LEVEL II BASIC TAN ROUTINE – “TAN”

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.

POP HL

15BD-15E2 – LEVEL II BASIC ATN ROUTINE – “ATAN”

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:- 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.
- 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.
- Evaluate the series: (((x^2*c0+c1) x^2+c2) … c8)x
- If the flag from step 1 is not set, then invert the sign of the series result.
- 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.

15E3-1607 – SINGLE PRECISION CONSTANTS STORAGE LOCATION

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

18C9-18F6 – STORAGE LOCATION FOR LEVEL II BASIC ERROR MESSAGES

18F7-1904 – STORAGE LOCATION FOR THE SINGLE PRECISION DIVISION ROUTINE

This code is moved from 18F7-191DH to 4080H-40A5H during non-disk initial setup.

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

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

191D-1923 – MESSAGE STORAGE LOCATION

1924-1928 – MESSAGE STORAGE LOCATION

1929-192F – MESSAGE STORAGE LOCATION

1930-1935 – MESSAGE STORAGE LOCATION

1936-1954 – 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.

1955-1962 – 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.

1963-197D – MEMORY CHECK ROUTINE

- This routine computes the amount of space between HL and the end of memory at FFC6.

Note: 40FDH-40FEH holds Free memory pointer.

197A-197B – OM ERROR entry point.

197E-1AF7 – LEVEL II BASIC COMMAND MODE

Note: 40A2H-40A3H holds the current BASIC line number.

Note: 40F2H holds Error flag.

Note: 40DAH-40DBH holds DATA line number.

Note: 40A2H-40A3H holds the current BASIC line number.

SN ERROR entry point.

?NF ERROR entry point.

?RW ERROR entry point.

Note: 40A2H-40A3H holds the current BASIC line number.

Note: 40EAH-40EBH holds Line number with error.

Note: 40ECH-40EDH holds EDIT line number.

Note: 40E8H-40E9H holds Stack pointer pointer.

Note: 409AH holds the RESUME flag.

Note: 40E6H-40E7H holds the temporary storage location.

Note: 40EEH-40EFH is used by RESUME.

Note: 40EAH-40EBH holds Line number with error.

Note: 40F5H-40F6H holds the last line number executed.

Note: 40F7H-40F8H holds Last byte executed.

Note: 40F0H-40F1H is used by ON ERROR.

Note: 40F2H holds Error flag.

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.

NOTE:

- The string must be terminated by a byte of zeros.

Note: 40EAH-40EBH holds Line number with error.

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).

This basically reserves the line number 65534 as a trigger for the next few steps.

“BASIC”

Re-entry into BASIC command mode entry point. (see 6CCH also).

In NEWDOS 2.1, this is the start of BASIC just before BASIC shows the READY prompt.

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).

Note: 409AH holds the RESUME flag.

1A33 – 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.

Note: 40A2H-40A3H holds the current BASIC line number.

Note: 40E2H-40E3H holds Current BASIC line number.

Note: 40E4H-40E5H holds AUTO increment.

There is an explanation at 1E5AH as to why 65529 is the highest possible line number (vs 65535 which would make more sense).

Note: 40E2H-40E3H holds Current BASIC line number.

NOTE:

- The string must be terminated by a byte of zeros.

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

Note: 40E6H-40E7H holds the temporary storage location.

In NEWDOS 2.1, this is the input scanner after tokenizing the current statement.

Note: 40DDH holds INPUT flag.

NOTE:

- The string must be terminated by a byte of zeros.

Note: 40ECH-40EDH holds EDIT line number.

- Note: 40F9H-40FAH holds the starting address of the simple variable storage area.

- Note: 40F9H-40FAH holds the starting address of the simple variable storage area.

Note: 40A7H-40A8H holds Input Buffer pointer.

In NEWDOS 2.1, this is the input scanner after updating the PST (Program Statement Table).

In NEWDOS 2.1, this is the input scanner after reinitializing BASIC

1AF8-1B0F – 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.

- Note: 40A4H-40A5H holds the starting address of BASIC program text also known as the PROGRAM STATEMENT TABLE (PST).

1B10-1B48 – 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.

CEH

1B2C – 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.

- Note: 40A4H-40A5H holds the starting address of BASIC program text also known as the PROGRAM STATEMENT TABLE (PST).

1B49-1B5C – LEVEL II BASIC NEW ROUTINE

- Entry point of the NEW command.

- Note: 40A4H-40A5H holds the starting address of BASIC program text also known as the PROGRAM STATEMENT TABLE (PST).

- Note: 40F9H-40FAH holds the starting address of the simple variable storage area.

1B5D-1BB2 – 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.

Note: 40DFH-40E0H is used by DOS.

Note: 4101H-411AH holds Variable Declaration Table.

Note: 40F2H holds Error flag.

Note: 40F0H-40F1H is used by ON ERROR.

Note: 40F7H-40F8H holds Last byte executed.

Note: 40B1H-40B2H holds MEMORY SIZE? pointer.

Note: 40D6H-40D7H holds Next available location in string space pointer.

- Note: 40F9H-40FAH holds the starting address of the simple variable storage area.

- Note: 40FBH-40FCH holds the starting address of the BASIC array variable storage area.

Note: 40FDH-40FEH holds Free memory pointer.

In NEWDOS 2.1 this initializes BASIC for a new routine.

- Note: 40A0H-40A1H holds the start of string space pointer.

Note: 40E8H-40E9H holds Stack pointer pointer.

Note: 40B5H-40D2H holds Temporary string work area.

Note: 40B3H-40B4H holds Next available location in the temporary string work area pointer.

Note: 40DCH holds FOR flag.

Note: 40DFH-40E0H holds Used by DOS.

1BB3-1BBF – 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.

“INPUT”

1BC0-1C8F – TOKENIZE INPUT ROUTINE

Note: 40B0H holds the temporary storage location.

Note: 40A7H-40A8H holds Input Buffer pointer.

Note: 40B0H holds the temporary storage location.

NOTE:

- The string must be terminated by a byte of zeros.

Note: 40B0H holds the temporary storage location.

Note: 40A7H-40A8H holds Input Buffer pointer.

1C90-1C95 – 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).

“CHLDE”

1C96-1CA0 – 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).

1CA1-1D1D – Level II BASIC FOR ROUTINE

- FOR entry point.

Note: 40DCH holds FOR flag.

Note: 40E8H-40E9H holds Stack pointer pointer.

Note: 40A2H-40A3H holds the current BASIC line number.

BDH

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.

PUSH DE

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.

Note: 40DFH-40E0H holds Used by DOS.

1D1E-1D77 – LEVEL II BASIC INTERPRETER

Note: 40E6H-40E7H holds the temporary storage location.

Note: 40E8H-40E9H holds Stack pointer pointer.

Note: 40A2H-40A3H holds the current BASIC line number.

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

Note: 411BH holds TRON/TROFF flag.

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

NOTE:

- The string must be terminated by a byte of zeros.

1D78-1D90 – 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).

“FETCH”

1D91-1D9A – LEVEL II BASIC RESTORE ROUTINE

- RESTORE logic is located here.

Note: 40FFH-4100H holds READ pointer.

1D9B-1DAD – SCAN KEYBOARD ROUTINE

Note: 4099H holds the Last key pressed.

1DA9-1DAD – STOP ROUTINE

This is the STOP entry point.

1DAE-1DE3 – LEVEL II BASIC END ROUTINE

- The is the END statement entry point.

Note: 40E6H-40E7H holds the temporary storage location.

Note: 40B5H-40D2H holds Temporary string work area.

Note: 40B3H-40B4H holds Next available location in the temporary string work area pointer.

Note: 40A2H-40A3H holds the current BASIC line number.

Note: 40F5H-40F6H holds the last line number executed.

Note: 40E6H-40E7H holds the temporary storage location.

Note: 40F7H-40F8H holds Last byte executed.

1DE4-1DF6 – LEVEL II BASIC CONT ROUTINE

This is the CONT statement entry point.

Note: 40F7H-40F8H holds Last byte executed.

Note: 40F5H-40F6H holds the last line number executed.

Note: 40A2H-40A3H holds the current BASIC line number.

1DF7-1DF8 – TRON ENTRY POINT

- Turns TRON feature on. Causes line numbers for each BASIC statement executed to be displayed. Uses A register.

1DF8 – TROFF ENTRY POINT

Disables tracing feature. Uses A register.

1DF9-1DFC – COMMON CODE SHARED BY TRON AND TROFF

Note: 411BH holds TRON/TROFF flag.

1DFD-1DFF – DISK ROUTINE NOT USED BY LEVEL II BASIC.

1E00-1E02 – DEFSTR ENTRY POINT

1E03-1E05 – DEFINT ENTRY POINT

1E06-1E08 – DEFSNG ENTRY POINT

1E09-1E0A – DEFDBL ENTRY POINT

1E0B-1E3C – 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.

NOTE:

- The string must be terminated by a byte of zeros.

NOTE:

- The string must be terminated by a byte of zeros.

NOTE:

- The string must be terminated by a byte of zeros.

Note: 4101H-411AH holds Variable Declaration Table.

NOTE:

- The string must be terminated by a byte of zeros.

1E3D-1E44 – 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.

1E45-1E4E – EXAMINE VARIABLE

- This is called when evaluating a subscript for a variable reference. It will evaluate if the value is positive or negative.

NOTE:

- The string must be terminated by a byte of zeros.

1E4A – FC ERROR entry point.

1E4F-1E79 – ASCII TO BINARY

Note: 40ECH-40EDH holds EDIT line number.

1E5A – “DECBIN” – 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.

NOTE:

- The string must be terminated by a byte of zeros.

Why 6552? Well, since the Z-80 has no multiply function, checking for any possible arbitrary number would require 4 branches for each step in the ‘add to itself until it hits * 10’ plus another 4 when adding the last digit. The TRS-80 ROM didn’t have that kind of room, nor the time to do all that, so they needed a cheat and that cheat was to let it go as high 65529. After all, 6552 + 1 more digit can NEVER exceed 65535, but 6553 + 1 digit sure can!

So with this trick, the ROM just needs to first check the number against 6552, which, when multiplied by 10, and adding one more digit, will never exceed 65529 (because 9 is the highest one number can go).

By using this trick, only 1 comparison is needed (is it greater or less than 6552) … at the cost of 4 usable line numbers/memory size setting in the 6553x range.

Wait, you say. 65535-65529 is 6 numbers, so why do you say 4. Well, another shortcut the ROM uses is that it assumes anything at line number 65535 is being entered in direct mode (i.e., no line number; just a command), so 65535 couldn’t be a line number. Similarly, in 1A09, 65534 is reserved to trigger the BASIC interpreter to jump to the initial powerup routine in the ROM (i.e., a reboot) so you couldn’t use that line number either.

This is so we can multiply HL (which should hold the number 6552) by 10.

This is so we can multiply HL (which should hold the number 6552) by 10.

As noted above, adding in any digit can only result in HL going to 65529.

1E7A-1EA0 – LEVEL II BASIC CLEAR ROUTINE

NOTE:

- The string must be terminated by a byte of zeros.

Note: 40B1H-40B2H holds MEMORY SIZE? pointer.

- Note: 40F9H-40FAH holds the starting address of the simple variable storage area.

- Note: 40A0H-40A1H holds the start of string space pointer.

1EA3-1EB0 – LEVEL II BASIC RUN ROUTINE

In NEWDOS 2.1, this processes a RUN nnnn statement.

1EB1-1EC1 – 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.

Note: 40A2H-40A3H holds the current BASIC line number.

1EC2-1EDD – LEVEL II BASIC GOTO ROUTINE

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

Note: 40A2H-40A3H holds the current BASIC line number.

1EDE-1E04 – 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.

Note: 40E8H-40E9H holds Stack pointer pointer.

1EEC – RG ERROR entry point.

Note: 40A2H-40A3H holds the current BASIC line number.

Note: 40DDH holds INPUT flag.

1F05-1F20 – SCAN ROUTINE

- This is also the DATA entry point.

1F21-1F6B – LEVEL II BASIC LET ROUTINE

D5H

Note: 40DFH-40E0H holds Used by DOS.

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.

- Note: 40A0H-40A1H holds the start of string space pointer.

- Note: 40F9H-40FAH holds the starting address of the simple variable storage area.

LD A,D1H

1F6C-1FAE – LEVEL II BASIC ERROR ON ROUTINE

NOTE:

- The string must be terminated by a byte of zeros.

8DH

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

LD E,C

Note: 40F0H-40F1H is used by ON ERROR.

Note: 40F2H holds Error flag.

Note: 409AH holds the RESUME flag.

1F95 – 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.

8DH

1FAF-1FF3 – LEVEL II BASIC RESUME ROUTINE

Note: 40F2H holds Error flag.

Note: 409AH holds the RESUME flag.

NOTE:

NOTE:

- The string must be terminated by a byte of zeros.

1FCF – This is the RESUME 0 routine

Note: 40EEH-40EFH is used by RESUME.

Note: 40EAH-40EBH holds Line number with error.

Note: 40A2H-40A3H holds the current BASIC line number.

Note: 40DDH holds INPUT flag.

1FF4H-2007 – LEVEL II BASIC ERROR ROUTINE

- This evaluates n for ERROR n.