Model 4 ROM Explained

PageCustomization:

Display OPCODEs
Display Labels
Display Gen 1
Display Gen 2 and Student Network



0000H-0004H – POWER UP ROUTINE – “START”

0000-0002 Disables the interrupts, clears the A register, then jumps to initialisation routine at 674H
0000
 ↳ START
DIF3
Disables the interrupts and turns off clock
0001
XOR AAF
Clears the A Register and status
0002
Go to the Boostrap/Initialization routine at 3015H (which just jumps to 3455H which is the BOOTSTRAP (sets interrupts, clears ports, checks for a BREAK key and tries to work with the disk controller).
0005-0007
JP 4000HJP RST1$C3 00 40
Go to RST 0008H code via 4000H
0008 (RST 8H) Jumps to 4000H. 4000H passes control to 1C96H. This routine is used for scanning strings. It compares the character pointed to by the HL Register Pair with the character pointed to by the return address on the top of the STACK (Note that a RST instruction is in effect a CALL and places a return address on the STACK) formula: (HL)=((SP))? If they are not equal an SN ERROR will result; if they are equal then the return address on the STACK will be incremented to bypass the test character and control will be passed to RST 10H logic. RST 8H is used to look for expected characters in a string and then return with (HL) pointing to the next non-blank character. (see RST l0H) (BC and DE registers unaffected.). This routine can be used by CALLing 1C96H or RST 8H
0008
 ↳ SYNTAX

(RST 008H)
JP 4000HJP RST1$C3 00 40
Jumps to 4000H. 4000H passes control to 1C96H. This routine is used for scanning strings. It compares the character pointed to by the HL Register Pair with the character pointed to by the return address on the top of the STACK (Note that a RST instruction is in effect a CALL and places a return address on the STACK) formula: (HL)=((SP))? If they are not equal an SN ERROR will result; if they are equal then the return address on the STACK will be incremented to bypass the test character and control will be passed to RST 10H logic. RST 8H is used to look for expected characters in a string and then return with (HL) pointing to the next non-blank character. (see RST l0H) (BC and DE registers unaffected.). This routine can be used by CALLing 1C96H or RST 8H.
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 in Register A 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)

000BH-000CH – DISK ROUTINE – “WHERE”

000B
 ↳ WHERE
POP HLE1
Get the address from the STACK and put it in Register Pair HL

000DH-000FH – DISK BOOTSTRAP – “$BOOT”

000C
JP (HL)E9
Jump to the location of the address in Register Pair HL
000D
JUMP to the disk load and run sector routine at 069FH.

0010H-0012H – RST 10 – GET A CHARACTER FROM THE BUFFER

0010 (RST 10H) jumps to 1D78H through 4003H. This routine INCrements HL and tests the characters pointed to by the HL Register Pair. It will bypass any spaces and CHAR’S 9 and 10 (shifted left and down arrows respectively). Upon return from this routine HL will point to the next non-blank character; the carry flag will be SET if HL is pointing to a numeric ASCII character and the Z flag will be SET if the character pointed to happens to be zero (ASCII 30H) or 3AH (“:”). (BC and DE registers are unaffected) This routine can be used by CALLing 1D78H or RST l0H
0010
(RST 010H)
JP 4003HJP RST2$C3 03 40
Jumps to 1D78H (RST 0010H vector) through 4003H.

This routine INCrements HL and tests the characters pointed to by the HL Register Pair. It will bypass any spaces and CHAR’S 9 and 10 (shifted left and down arrows respectively). Upon return from this routine HL will point to the next non-blank character; the carry flag will be SET (C=1) if HL is pointing to a number and the Z flag will be SET if the character pointed to happens to be zero (ASCII 30H) or 3AH (“:”). The carry flag will be RESET (0) if the character is non-numeric. (BC and DE registers are unaffected) This routine can be used by CALLing 1D78H or RST l0H

0013H-0017H – INPUT ROUTINE – $GET

This routine Inputs a byte from an input device. When calling, DE = starting address of DCB of device. On exit, A = byte received from device, Z set if device ready. Uses AF.
0013
 ↳ $GET
PUSH BCC5
Save the value in Register Pair BC on the STACK
0014-0015
LD B,01H06 01
Load Register B with the device type entry code of 01H
0016-0017
JR 0046HJR CIOJ18 2E
Jump to the Level II BASIC driver entry routine at 0046H
0018 (RST 18H) Jumps to 1C90H through 4006H. This routine can be called by using RST 18H or CALL 1C90H. It compares two 16 bit values in HL and DE and sets the S and Z flags accordingly (they are set in the same way as for a normal 8 bit CP). All registers are unchanged except for A
0018
 ↳ RST18
JP 4006HJP RST3$C3 06 40
Jumps to 1C90H through 4006H. This routine can be called by using RST 18H or CALL lC90H. It compares two 16 bit values in HL and DE and sets the S and Z flags accordingly (they are set in the same way as for a normal 8 bit CP). All registers are unchanged except for A.
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)

001BH-001EH – DRIVER ENTRY ROUTINE – Part 1 – “PUT”

This routine outputs a byte to a device. When calling, A = output byte, DE = starting address of DCB of device. On exit, Z set if device ready. Uses AF.
001B
 ↳ PUT
PUSH BCC5
Save the value in Register Pair BC on the STACK
001C-001D
LD B,02H06 02
Load Register B with the device type entry code of 02H
001E-001F
JR 0046HJR CIOJ18 26
Jump to the Level II BASIC driver entry routine at 0046H
0020 (RST 20H) This routine jumps to 25D9H through 4009H. If the NTF=8 then C=RESET or else C=SET, Z flag will be SET if NTF=3 (S flag is valid also.). After execution of RST 20H or CALL 25D9H, A will contain the value NTF-3, all other registers are unchanged. (The NTF will be discussed in the arithmetic section.)
0020
(RST 020H)
JP 4009HJP RST4$C3 09 40
This routine jumps to 25D9H through 4009H. If the NTF=8 then C=RESET or else C=SET, Z flag will be SET if NTF=3 (S flag is valid also.). After execution of RST 20H or CALL 25D9H, A will contain the value NTF-3, all other registers are unchanged.
Returns a combination of STATUS flags and unique numeric values in the A Register according to the data mode flag (40AFH). 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. This CALL is usually made to determine the type of the current value in the ACCumulator (i.e., 4121H-4122H). It should be used with caution, however since the mode flag and ACCumulator can get out of phase particularly if some of the CALLS described here are used to load ACCumulator

0023H-0027H – DISK ROUTINE – “$CTL”

0023
 ↳ $CTL
PUSH BCC5
Save the value in Register Pair BC on the STACK
0024-0025
LD B,04H06 04
Load Register B with the device type entry code of 04H
0026-0027
JR 0046HJR CIOJ18 1E
Jump to the Level II BASIC driver entry routine at 0046H
0028 (RST 28H) Jumps to 400CH which contains C9H (RET) under Level II BASIC. This vector is only used by Disk BASIC. It is called by the BREAK key routine, and can be used to intercept the BREAK key logic
0028
(RST 028H)
JP 400CHJP RST5$C3 0C 40
Jumps to 400CH which contains C9H (RET) under Level II BASIC. This vector is only used by Disk BASIC. It is called by the BREAK key routine, and can be used to intercept the BREAK key logic.
This is the DOS FUNCTION CALL routine at RST 28 (which passes request code in A-register to DOS for processing. Returns for non-disk system. For disk systems, the A Register must contain a legitimate DOS function code. If the code is positive, the CALL is ignored and control returns to the caller. Note that the DOS routine discards the return address stored on the STACK by the RST instruction. After processing control will be returned to the previous address on the STACK)

002BH-002FH – KEYBOARD ROUTINE – “$KBD”

Keyboard scanning routine. After CALLing 2BH, the A Register will contain the ASCII value for the key that was pressed. The A Register will contain 00H if no key was pressed at the time. Apart from the AF Register Pair the DE Register Pair is also used by the routine.
This Routine Performs an instantaneous scan of the keyboard. If no key is depressed control is returned to the caller with the A Register and status Register set to zero. If any key (except the BREAK key) is active the ASCII value for that character is returned in the A-register. If the BREAK key is active, a RST 28 with a system request code of 01 is executed. The RST instruction results in a JUMP to the DOS Exit 400C. On non-disk systems the Exit returns, on disk systems control is passed to SYS0 where the request code will be inspected and ignored, because system request codes must have bit 8 on. After inspection of the code, control is returned to the caller of 002B. Characters detected at 002B are not displayed. Uses DE, status, and A register

Of the 3 keyboard scanning routines, this is the most fundamental one. If no key is pressed when the CALL is executed, the code falls through with A = 00H. If you want to wait for a key to be pressed, you would use CALL 0049 or you would write a routine that jumps back to the call if A is 0.

This routine loads DE with address of keyboard DCB and scans keyboard. On exit, if no key pressed the A Register will contain a zero byte, else the character input from the keyboard wi 11 be returned in A. Character is not echoed to video. Uses AF,DE (to save DE use routine at 03588).

Scan Keyboard: Performs an instantaneous scan of the keyboard. If no key is depressed control is returned to the caller with in Register A and status Register set to zero. If any key (except the BREAK key) is active the ASCII value for that character is returned in the A-register. If the BREAK key is active, a RST 28 with a system request code of 01 is executed. The RST instruction results in a JUMP to the DOS Exit 400C. On non-disk Systems the Exit returns, on disk systems control is passed to SYS0 where the request code will be inspected and ignored, because system request codes must have bit 8 on. After inspection of the code, control is returned to the caller of 002B. Characters detected at 002B are not displayed. Uses DE, status, and A register
002B-002D
 ↳ $KBD
LD DE,4015HLD DE,KDCB$11 15 40
Load Register Pair DE with the starting address of the keyboard device control block.
Note: 4015H holds Keyboard DCB – Device type
002E-002F
JR 0013HJR $GET18 E3
Jump to the Level II BASIC driver entry routine
0030
(RST 030H)
JP 400FHJP RST6$C3 0F 40
This location passes control to 400FH which contains a RET (C9H) under Level II. This location is only used by a Disk system.
This is the LOAD DEBUG routine, and loads the DEBUG program and transfers control to it. When DEBUG processing is complete, control is returned to the orginal caller. For non-disk systems control is returned immediately

0033H-0037H – VIDEO ROUTINE – “$DSP”

Character print routine. A CALL 33H will print a character at the current cursor position. The A Register must contain the ASCII code for the character or graphics figure that is to be printed before CALLing this routine. The DE Register Pair is used by the routine.
A call to 0033H displays the character in the A-register on the video. Control codes are permitted. All registers are used.
0033-0035
 ↳ $DSP
LD DE,401DHLD DE,DDCB$11 1D 40
Load Register Pair DE with the starting address of the video display device control block.
Note: 401DH holds Video DCB – Device type
0036-0037
JR 001BHJR $PUT18 E3
Jump to the Level II BASIC driver entry routine at 001BH
0038 (RST 38H) This location will pass control to 4012H. This location is only used by a Disk system
0038
(RST 038H)
JP 4012HJP RST7$C3 12 40
This location will pass control to 4012H. This location is only used by a Disk system.
This is the INTERRUPT ENTRY POINT routine at RST 38H which is the system entry point for all interrupts. It contains a jump to a section of code in the Communications Region designed to field interrupts. That section of code consists of a DI (disables further interrupts) followed by a RET (returns to the point of interrupt) for non-disk systems, or a jump to an interrupt processor in SYSO if it is a DOS system. For DOS systems the interrupt handler consists of a task scheduler, where the exact cause of the interrupt is determined (usually a clock interrupt) and the next task from the task control block is executed. After task completion, control returns to the point of interrupt

003BH-003FH – PRINTER ROUTINE – “$PRT”

Character LPRINT routine. Same as 33H but outputs to line printer. (Contents of A Register will be printed).

A call to 003BH causes the character contained in the A-register to be sent to the printer. A line count is maintained by the driver in the DCB. When a full page has been printed (66 lines), the line count is reset and the status Register returned to the caller is set to zero. Control codes recognized by the printer driver are:
  • 00=Returns the printer status in the upper two bits of the A-register and sets the status as zero if not busy, and non-zero if busy.
  • OB=Unconditionally skips to the top of the next page.
  • OC=Resets the line count (DCB 4) and compares its previous value to the lines per page (DCB 3) value. If the line count was zero, no action is taken. If the line count was non-zero then a skip to the top form is performed.
  • OD=Line terminator. Causes line count to be incremented and tested for full page. Usually causes the printer to begin printing.

Character LPRINT routine. Same as 33H but outputs to line printer. (Contents of A Register will be printed.)
003B-003D
 ↳ $PRT
LD DE,4025HLD DE,PDCB$11 25 40
Load Register Pair DE with the starting address of the printer device control block.
Note: 4025H holds Printer DCB – Device type
003E-003F
JR 001BHJR $PUT18 DB
Jump to the Level II BASIC printer driver entry routine

0040H-0042H – INPUT ROUTINE – “$KEYIN”

0040-0042
 ↳ $KEYIN
JP 05D9HJP KEYINC3 D9 05
Jump to the “WAIT FOR NEXT LINE” keyboard input routine at 05D9 (which takes keyboard entry until a carriage return, a break, or buffer overrun occurs)

*0043H-0045H – Model 4 Gen 1 Routine – Unused Code

*0043
RET
*0044
NOP
*0045
NOP

*0043H-0045H – Model 4 Gen 2 Routine – Called from new routine at 3790H

*0043-0045
JP 0434HC3 34 04
Jump into the new PRINT SCREEN routine

0046H-0048H – DRIVER ENTRY ROUTINE – Part 2 – “CIOJ”

0046
JUMP to 0674H which is the is the Level II BASIC keyboard driver entry routine.

0049H-004FH – KEYBOARD ROUTINE – “$KEY”

A call to 0049H returns as soon as any key on keyboard is pressed, exactly how the INKEY$ function works in BASIC. ASCII value for character entered is returned in A register. If you don’t want the program to hold while waiting for a key, you would use CALL 002BH instead.

Character input routine. This routine is the same as 2BH except that it will not return until a key is pressed, which often makes it often more useful than 2BH. Character is returned in the A Register (AF and DE used)

Wait For Keyboard Input: Returns as soon as any key on keyboard is pressed. ASCII value for character entered is returned in A- register. Uses A, status and DE registers
0049-004B
 ↳ $KEY
CALL 002BHCALL $KBDCD 2B 00
Go scan the keyboard and return with the key pressed, if any, in Register A.
A CALL to this memory location returns as soon as any key on keyboard is pressed. ASCII value for character entered is returned in A register. Uses A, status, and DE registers.

Character input routine. This routine is the same as 2BH (=Scan the Keyboard routine) except that it will not return until a key is pressed
004C
OR AB7
Check the value in Register A to see if a key was pressed
004D
RET NZC0
Return if a key was pressed
004E-004F
JR 0049HJR $KEY18 F9
Loop until a key is pressed

0050H-005FH – KEYBOARD LOOKUP TABLE – “KEYTAB”

This is a table of control characters used by BASIC.
0050
Load DE with the RS-232 Input DCB of 41E5H.
0053
Input a Byte from the RS-232
0055
Load DE with the RS-232 Output DCB of 41EDH
0058
Output a Byte to the RS-232
005A
Load DE with the RS-232 Controller DCB of 41F5H
005D
Set up the RS-232
005F00
NOP

*0060H – Model 4 Gen 1 – DELAY ROUTINE – “$PAUSE”

This is a delay loop. The BC Register Pair is used as the loop counter. The duration of the delay, in microseconds, is the value of BC times 14.66. Register A is used.
*0060
JUMP to the delay routine at 01FBH, which uses BC as a loop counter. It RETs when done, so the next instruction is NOT a pass-through!
0063-0064
JR NZ,0060HJR NZ,PAUSE20 FB
Loop until the counter in Register Pair BC is equal to zero
0065
RETC9
RETurn to CALLer

*0060H – Model 4 Gen 2 – DELAY ROUTINE – “$PAUSE”

This is a delay loop. The BC Register Pair is used as the loop counter. The duration of the delay, in microseconds, is the value of BC times 14.66. Register A is used.
*0060
JUMP to the delay routine at 01FBH, which uses BC as a loop counter. It RETs when done, so the next instruction is NOT a pass-through!
0063-0065
JP 041FHC3 1F 04
Jump to the printer routine

0066H – Program control jumps when the RESET button is pressed (Non Maskable Interrupt address)

0066
Go to the non-maskable interrupt routine at 3039H.

0069H-0074H NMI INTERRUPT ROUTINE (RESET) – “$INITIO”

*This part of the initialization routine checks to see if a disk drive is connected. If so, it will jump to 00H. (This is why the reset button will reinitialize DOS.)
*0069
Initialize all I/O Drivers by jumping to 0452

*006C-0074H – Model 4 Gen 1 – Unused Code

*006C
Load DE with the $ Routine DCB at 421DH
*006F
Set the I/O Routine by jumping to 001BH
*0071
NOP
*0072-0074
JP 06CCHJP RESETRC3 CC 06
Since we are without disk drives at this, this would be for power on or reset … so jump to the Level II BASIC READY routine at 06CCH

*006C-0074H – Model 4 Gen 2

*006C
RETC9
RETurn to Caller

*006D-0070H – Model 4 Gen 2 – New Code for Gen 2 – Called from 02C3H when the BREAK key is hit

*006D
LD BC,1A18H01 18 1A
Set Register Pair BC to point to the STPRDY Routine
*0070
JP 19AEHC3 AE 19
JUMP to 19AEH to reset the stack and reinitialize the system variables, including reinitializing the STACK to the location now held in SAVSTK
*0073
NOP00
No Operation
*0074
NOP00
Operation

0075H-0104H – INITIALIZATION ROUTINE – “INIT2”

This is part of the Level II initialization procedure. It moves a block of memory from 18F7H to 191EH up to 4080H to 40A7H. (reserved RAM. area).

NOTE: 4080H-408DH is a division support routine.
0075-0077
LD DE,4080HLD DE,RAMLOW11 80 40
Load Register Pair DE with the ROM storage location of the Level II BASIC division routine.
Note: 4080H-408DH is a division support routine
0078-007A
LD HL,18F7HLD HL,CONSTR21 F7 18
Load Register Pair HL with the RAM storage location of the Level II BASIC division routine
007B-007D
LD BC,0027HLD BC,CNSLNR+101 27 00
Load Register Pair BC with the length of the Level II BASIC division routine (39 bytes)
007E-007F
LDIRED B0
Move the Level II BASIC division routine in ROM (18F7H-191DH) to RAM (4080H-40A6H)
0080
Continue with the communication region initialization by loading register pair HL with 42E5H.
0083-0084
LD (HL),3AHLD (HL),”:”36 3A
Save a 3AH (which a “:”) at the location of the memory pointer in Register Pair HL (which is 41E5H)
0085
INC HL23
Increment the memory pointer in Register Pair HL from 41E5H to 41E6H
0086
LD (HL),B70
Zero out 41E6H (the location of the memory pointer in Register Pair HL)
0087
INC HL23
Increment the memory pointer in Register Pair HL from 41E6H to 41E7H
0088-0089
LD (HL),2CHLD (HL),”,”36 2C
Save a 2CH (which is a “,”) at 41E7H (the location of the memory pointer in Register Pair HL)
008A
INC HL23
Increment the memory pointer in Register Pair HL from 41E7H to 41E8H, which is the input/output buffer BUFINI
This loads 40A7H with the I/O buffer location address 41E8H. (40A7H is the I/O buffer pointer and can be changed to relocate the buffer.)
008B-008D
LD (40A7H),HLLD (BUFPNT),HL22 A7 40
This loads the input buffer pointer (held at 40A7H) with the keyboard buffer location address of 41E8H. (40A7H is the I/O buffer pointer and can be changed to relocate the buffer.). Save the value in Register Pair HL as the starting address of the keyboard input buffer area.
Note: 40A7H-40A8H holds the input Buffer pointer
008E-0090
LD DE,012DHLD DE,NAVERR11 2D 01
In prepartaion for a jump, load Register Pair DE with the starting address of the ?L3 ERROR routine
0091H-0104H – The rest of the initialization routine. First, it fills the RAM locations pointing to all 28 DOS BASIC commands, set them to pointo ?L3 ERROR, ask MEMORY SIZE ?, sets the memory pointers accordingly and prints RADIO SHACK LEVEL II BASIC , then it jumps to 1A19H which is the entry point for the BASIC command mode

The rest of the initialization routine. Asks MEMORY SIZE ?, sets the memory pointers accordingly and prints RADIO SHACK LEVEL II BASIC , then it jumps to lAl9H which is the entry point for the BASIC command mode
0091-0092
LD B,1CHLD B,ERCNT06 1C
Since there are 28 pre-defined DOS BASIC commands in ROM, load Register B with the number of times (=28) to save the jump to the ?L3 ERROR routine
0093-0095
LD HL,4152HLD HL,ERCALL21 52 41
Load Register Pair HL with the starting address of the Disk Basic links (which is 4152H) in preparation for generating an error if disk basic commands are attempted.
Note: 4152H-41A3H holds Disk Basic links
0096
LD (HL),C3H
Save a C3H to the location of the memory pointer in register pair HL.
NOTE: C3H is the first byte of a 3 byte JUMP xxxxH command.
0098
INC HL23
Increment the memory pointer in Register Pair HL to point to the 2nd of each 3 byte instruction in the Disk Basic command list
0099
LD (HL),E73
Save the LSB of the ?L3 ERROR routine’s starting address in Register E (i.e., a 2DH) to the 2nd of each 3 byte instruction in the Disk Basic command list
009A
INC HL23
Increment the memory pointer in Register Pair HL to the 3rd of each 3 byte instruction in the Disk Basic command list
009B
LD (HL),D72
Save the MSB of the ?L3 ERROR routine’s starting address in Register D (i.e., a 01H) to the 3rd of each 3 byte instruction in the Disk Basic command list
009C
INC HL23
Increment the memory pointer in Register Pair HL to the 1st byte of the next Disk Basic command in the list
009D-009E
DJNZ 0096HDJNZ ERLOPS10 F7
Do this 28 times (=84 locations) until all of the Disk Basic links have been set to jump to the ?L3 ERROR routine
009F-00A0
LD B,15HLD B,RETCNT06 15
Load Register B with the number of DOS links to set to RETs. Note: HL is 41A6H at this point.. In the original ROM source, this was “LD B,RETCNT”
00A1
LD (HL),C9H
Save a C9H to the location of the memory pointer in register pair HL.
NOTE: C9H is a RET instruction.
00A3
INC HL23
Increment the memory pointer in Register Pair HL, as it is irrelevant what this memory location holds since RET is a single OPCODE
00A4
INC HL23
Increment the memory pointer in Register Pair HL, as it is irrelevant what this memory location holds since RET is a single OPCODE
00A5
INC HL23
Increment the memory pointer in Register Pair HL to point to the next error jump instruction
00A6-00A7
DJNZ 00A1HDJNZ LOPRTS10 F9
Loop from 4156H until all of the DOS links have been set to RETs

00A8H – VIDEO AND PRINTER ROUTINE

00A8
Load register pair HL with the starting address of user RAM (which is 42E8H).
00AB
LD (HL),B70
Zero the end of the buffer (i.e., 42E8H, the location of the memory pointer in Register Pair HL)
00AC
Set the current STACK pointer to 42F8H.
00AF-00B1
CALL 1B8FHCALL STKINICD 8F 1B
Go initialize the Level II BASIC variables and pointers
00B2
NOP
00B3
NOP
00B4
NOP
00B5-00B7
 ↳ MEMGET
LD HL,0105HLD HL,MEMMSG21 05 01
Load Register Pair HL with the starting address of the MEMORY SIZE? message in ROM. In the original ROM source, this address was set as “LD HL,MEMMSG”
00B8-00BA
CALL 28A7HCALL STROUTCD A7 28
Call the WRITE MESSAGE routine at 28A7H to print the message pointed to by HL.
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).
00BB-00BD
CALL 1BB3HCALL QINLINCD B3 1B
Print a “?” and get input from the keyboard
00BE-00BF
JR C,00B5HJR C,MEMGET38 F5
If the BREAK key was pressed, ask again. Note: 1BB3H jumps around A LOT but it is 0661H which processes a BREAK key, and starts by setting the carry flag
00C0
RST 10HCHRGETD7
Since we now need to increment the input buffer pointer until it points to the first character of the input, call the EXAMINE NEXT SYMBOL routine at RST 10H.

The RST 10H routine parses the characters starting at HL+1 for the first non-SPACE,non-09H,non-0BH character it finds. On exit, Register A will hold that character, and the C FLAG is set if its alphabetic, and NC FLAG if its alphanumeric. All strings must have a 00H at the end.
00C1
OR AB7
Set the status flag based on if the character at the location of the input buffer pointer in Register A is an end of the input character (00H)
00C2-00C3
JR NZ,00D6HJR NZ,TYPMEM20 12
Jump forward to 00D6H if there was a response to the MEMORY SIZE? question
00C4
If we are here then just an ENTER was hit in response to the MEMORY SIZE? question, so we need to figure it out dynamically, so load register pair HL with the starting address for the memory size check.Difference between M1 and M3: The instruction starting at 00C4H loads HL with 434CH in the Model I, 444CH in the Model III. If only “ENTER” was pressed in response to the “MEMORY SIZE?” prompt, a memory test is initiated starting at the location pointed to by HL, and continuing upward until the end of memory (or a bad memory location) is reached.
00C7
 ↳ LOOPMM
INC HL23
We are going to start testing RAM at 17229 (i.e., 434DH) toward 65535, so increment the memory pointer in Register Pair HL
00C8-00C9
LD A,H
OR L7C
There is no way to COMPARE HL against anything, so the common “trick” is to load Register A with Register H and then OR it against Register L. If you do this, Register A can only be zero if both Registers H and L are zero
00CA-00CB
JR Z,00E7HJR Z,USEDEF28 1B
Since we need to scan all the way up to 65535, jump to 00E7H (which drops the memory size pointer by 1) if the current memory pointer in Register Pair HL is equal to zero
00CC
LD A,(HL)7E
Load Register A with the value at the location of the current memory pointer in Register Pair HL
00CD
LD B,A47
Load Register B with the value in Register A to preserve it, as A is about to get used
00CE
CPL2F
Complement the value in Register A (which is basically a test pattern)
00CF
LD (HL),A77
Save the test pattern in Register A to the location of the current memory pointer in Register Pair HL
00D0
CP (HL)BE
Check to see if the value at the location of the memory pointer in Register Pair HL is the same as the value in Register A
00D1
LD (HL),B70
Put back the original memory value (which was saved in B) to the location of the memory pointed in Register Pair HL
00D2-00D3
JR Z,00C7HJR Z,LOOPMM28 F3
If the address exists, loop back to 00C7H until the end of memory is found
00D4-00D5
JR 00E7HJR USEDEF18 11
If the address didn’t exist, jump to 00E7H (which goes to he next address and tries again)
00D6-00D8
 ↳ TYPMEM
CALL 1E5AHCALL LINGETCD 5A 1E
Here the MEMORY SIZE? answer is in HL so call the ASCII TO INTEGER routine at 1E5AH (which will put the answer into DE in integer format).
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
00D9
OR AB7
Check to see if Register A is equal to zero
00DA-00DC
JP NZ,1997HJP NZ,SNERRC2 97 19
Display a ?SN ERROR if Register A is not equal to zero
00DD
EX DE,HLEB
Swap DE (where the integer version of the MEMORY SIZE? answer is located) and HL, so that Register Pair HL now has with the MEMORY SIZE answer again, but in integer format
00DE
DEC HL2B
Decrement the MEMORY SIZE? in Register Pair HL
00DF-00E0
LD A,8FH3E 8F
Load Register A with a memory test value of 8F or 10001111
00E1
LD B,(HL)46
Load Register B with the value at the location of the MEMORY SIZE? pointer in Register Pair HL (to save the data thats there)
00E2
LD (HL),A77
Put the test pattern (in A which is 8FH) into that the location of the MEMORY SIZE? pointer in Register Pair HL
00E3
CP (HL)BE
Check to see if the value in the memory location set in HL matches the test pattern in A
00E4
LD (HL),B70
Restore the old memory contents back
00E5-00E6
JR NZ,00B5HJR NZ,MEMGET20 CE
The test at MEMORY SIZE? -1 failed so we have to ask MEMORY SIZE again by jumping to 00B5H
00E7
 ↳ USEDEF
DEC HL2B
Decrement the memory size pointer in Register Pair HL, so it is the amount of memory – 2
00E8
Load register pair DE with the minimum MEMORY SIZE? response (held at 4514H).
00EB
RST 18HCOMPARDF
Now we need to check to see if the MEMORY SIZE? pointer (in HL) is less than the minimum MEMORY SIZE? response (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)
00EC-00EE
JP C,197AHJR C,OMERRDA 7A 19
If C is set, then the amount of actual memory (in HL) is less than the minimum memory required (in DE), so we have to go to the Level II BASIC error routine and display an OM ERROR
00EF-00F1
 ↳ STRSZD
LD DE,FFCEHLD DE,65536-STRSZD11 CE FF
Load Register Pair DE with the default size of the string area (i.e., negative fifty)
00F2-00F4
LD (40B1H),HLLD (MEMSIZ),HL22 B1 40
Save the MEMORY SIZE? amount (which is in HL) to 40B1H (which holds the MEMORY SIZE? pointer)
00F5
ADD HL,DE19
Subtract the size of the string data (which was -50) from the highest memory address (stored in HE)
00F6-00F8
LD (40A0H),HLLD (STKTOP),HL22 A0 40
Save the start of string space pointer (which is now held Register Pair HL) to 40A0H.
Note: 40A0H-40A1H holds the start of string space pointer
00F9-00FB
CALL 1B4DHCALL SCRTCHCD 4D 1B
Go initialize/reset the Level II BASIC variables and pointers
00FC-00FE
LD HL,0111HLD HL,HDGMSG21 11 01
Load Register Pair HL with the starting address of the RADIO SHACK LEVEL II BASIC message. 00FFH-0101H Go display the RADIO SHACK LEVEL II BASIC message

*00FFH – Model 4 Gen 1 Code

*00FF
Different ROM Versions handle this differently. Both will display the message pointed to by HL.
*0102-0104
JP 1A19HJP READYC3 19 1A
Go to the Level II BASIC READY routine

*00FFH – Model 4 Gen 2 Code

*00FF
CALL 021BHCD 1B 02
GOSUB to 021BH. Note; 021BH will display the character at (HL) until a 03H is found.
*0102
JP 01E6HC3 E6 01
JUMP to 01E6H to keep processing. In this case, next, display the COPYRIGHT message

0105H-0110H – MESSAGE STORAGE

The “MEMORY SIZE” message is located here
0105
“MEMORY SIZE” + 00H
MEMORY SIZE message storage area.
0111
“RADIO SHACK MODEL-III BASIC” + 0DH
RADIO SHACK MODEL-III BASIC message storage area.

012DH-0131H – ?L3 ERROR ROUTINE – “NAVERR”

012D-012E
 ↳ NAVERR
LD E,2CHLD E,ERRNAV1E 2C
Load Register E with the ?L3 ERROR code of 2CH
012F-0131
JP 19A2HJP ERRORC3 A2 19
Go to the Level II BASIC error routine with 2CH loaded into Register E

0132H-0134H – LEVEL II BASIC POINT COMMAND ENTRY POINT – “GRPHCS” or “POINT”

0132
 ↳ GRPHCS
RST 10HCHRGETD7
Since we need to bump the current BASIC program pointer until it points to the next character, call the EXAMINE NEXT SYMBOL routine at RST 10H.

The RST 10H routine parses the characters starting at HL+1 for the first non-SPACE,non-09H,non-0BH character it finds. On exit, Register A will hold that character, and the C FLAG is set if its alphabetic, and NC FLAG if its alphanumeric. All strings must have a 00H at the end.
0133
XOR AAF
A will wind up being 0 if the POINT command was entered … otherwise
0134
LD BC,803EH01 3E 80
Z-80 Trick! The byte at this memory location, 01H, is there to turn the real instruction that follows (the operative action of the SET command) into a harmless LD BC,xxxx. This way, they didn’t have to jump over SET or RESET to get to the common graphics code. If parsing straight down, this loads BC with 0380H and then moves to 0136H. But if jump straight to 0136H, you skip that 01H opcode, and get a real instruciton of 3EH 80H

0135H-0137H – LEVEL II BASIC SET COMMAND – “SET”

0135
LD A,80H
Load register A with 80H (Decimal:128) which is SET.
0137
LD BC,013EH01 3E 80
Z-80 Trick! The byte at this memory location, 01H, is there to turn the real instruction that follows (the operative action of the SET command) into a harmless LD BC,xxxx. This way, they didn’t have to jump over SET or RESET to get to the common graphics code. If parsing straight down, this loads BC with 0380H and then moves to 0136H. But if jump straight to 0136H, you skip that 01H opcode, and get a real instruciton of 3EH 80H

0138H-0139H – LEVEL II BASIC RESET COMMAND ENTRY POINT – “RESET”

0138
LD A,01H
Load register A with 01H which is RESET.

013AH-019CH GRAPHICS ROUTINE

Common code for SET/RESET/POINT – A will be 0 if POINT, 80H if SET and 1 for RESET.
013A
PUSH AFF5
Save the flag which indicates which command was requested (held in Register A) to the STACK
013B
RST 08H + 28H
Since SET/RESET/POINT all need a “(” to start with, 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 Register A 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).
013D
Go evaluate the expression at the location of the current BASIC program pointer in register pair HL (which is the X variable) and return with the 8-bit value in register A.
0140-0141
CP 80HFE 80
Check to see if the X value in Register A is greater than 128
0142-0144
JP NC,1E4AHJP NC,FCERRD2 4A 1E
If A is greater than 128, go to 1E4AH to display a ?FC ERROR
0145
PUSH AFF5
Save the requested coordinate’s X value in Register A on the STACK
0146
RST 08H + “,”
At this point we have SET/RESET/POINT, an open parenthesis, and an X variable, so now we must find a ,. To do this 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).
0148-014A
CALL 2B1CHCALL GETBYTCD 1C 2B
Go evaluate the expression at the location of the current BASIC program pointer in Register Pair HL (which is the Y variable) and return with the 8-bit value in Register A
014B-014C
CP 30HFE 30
Check to see if the Y value in Register A is greater than 48
014D-014F
JP NC,1E4AHJP NC,FCERRD2 4A 1E
If the Y value is greater than 48, go to 1E4AH to display a ?FC ERROR
This is a suitable entry point for the graphics routines. (see Part 2)
0150
 ↳ SETRES
LD D,FFH
Prepare to divide Y coordinate by 3 … load register D with starting quotient of FFH (which will turn into 00 once it enters the loop).
0152
 ↳ LOPMD3
INC D14
Increment the quotient in Register D
0153-0154
SUB 03HD6 03
Divide by subtraction; in this case subtract 3 from Register A
0155-0156
JR NC,0152HJP NC,LOPMD330 FB
Loop until Register D equals the Y value divided by 3
0157-0158
ADD 03HC6 03
Make the remainder positive by adjust the remainder in Register A by adding back 3
0159
LD C,A4F
Save the remainder in Register C
015A
POP AFF1
Get the requested coordindate’s X value from the STACK and put it in Register A
015B
ADD A,A87
Multiply the X value in Register A by two, storing the result in Register A
015C
LD E,A5F
Load Register E with the newly doubled Register A
015D-015E
LD B,02H06 02
Load Register B with the number of times to shift Register Pair DE right (which is 2)
015F
 ↳ SHFTW
LD A,D7A
Load Register A with the adjusted Y value in Register D
0160
RRA1F
Divide the adjusted Y value in Register A by two. RRA rotates the contents of Register A right one bit position, with Bit 0 going to the CARRY FLAG, and the CARRY FLAG going to Bit 7. RRA also can be used to divide a number in 2.
0161
LD D,A57
Save the new Y value in Register A in Register D
0162
LD A,E7B
Load Register A with the adjusted X value in Register E
0163
RRA1F
Divide the adjusted X value in Register A by two. RRA rotates the contents of Register A right one bit position, with Bit 0 going to the CARRY FLAG, and the CARRY FLAG going to Bit 7. RRA also can be used to divide a number in 2.
0164
LD E,A5F
Load Register E with the new X value in Register A
0165-0166
DJNZ 015FHDJNZ DHFTW10 F8
Loop until the memory offset in Register Pair DE has been figured
0167
LD A,C79
Now we need to computer the position of the point so load Register A with the value in Register C
0168
ADC A,A8F
Multiply the value in Register A by two and add the value of the Carry flag to Register A
0169
INC A3C
Increment the value in Register A
016A
LD B,A47
Save the bit position in Register A in Register B
016B
XOR AAF
Zero Register A and reset the Carry flag
016C
SCF37
Set the Carry flag
016D
 ↳ PWR2
ADC A,A8F
Add the value of the Carry flag to Register A
016E-016F
DJNZ 016DHDJNZ PWR210 FD
Loop back to the prior instruction until the graphic mask has been completed in Register A
0170
LD C,A4F
Save the graphic mask in Register A in Register C
0171
LD A,D7A
Load Register A with the MSB of the video memory offset in Register D
0172-0173
OR 3CHOR 0011 1100F6 3C
Mask the MSB of the video memory offset in Register A with 0011 1100 so that it will point to the correct location in video RAM (i.e., the applicable screen RAM address)
0174
LD D,A57
Save the MSB of the video memory pointer in Register A in Register D
0175
LD A,(DE)1A
Load Register A with the character at the location of the video memory pointer in Register Pair DE
0176
OR AB7
Check to see if the character in Register A is a graphic character
0177-0179
JP M,017CHJP M,FND4FA 7C 01
Skip over the next instruction if the character in Register A is a graphic character
017A-017B
LD A,80H3E 80
Since the character at the screen location turned out not to be a graphics character, we need to set it to a blank graphics character, so load Register A with a blank graphic character which is CHR$(128)
017C
 ↳ FND4
LD B,A47
Save the character which is being modified by the SET/RESET (held in Register A) into Register B
017D
POP AFF1
Get the graphic character and the flags from the STACK and put it in Register A
017E
OR AB7
Set the flags according to the graphic mode in Register A
017F
LD A,B78
Get the existing graphic character on the screen (held in Register B) and put it in Register A
0180-0181
JR Z,0192HJR Z,TBIT28 10
Jump forward to 0192H if the graphic mode is POINT
0182
LD (DE),A12
Save the graphic character in Register A at the location of the video memory pointer in Register Pair DE
0183-0185
JP M,018FHJP M,SBITFA 8F 01
Jump forward to 018FH if the graphic mode is SET
0186
LD A,C79
Load Register A with the graphic mask in Register C
0187
CPL2F
Reverse the graphic mask in Register A
0188
LD C,A4F
Load Register C with the adjusted graphic mask in Register A
0189
LD A,(DE)1A
Load Register A with the character at the location of the video memory pointer in Register Pair DE
018A
AND CA1
RESET the graphic bit by combining the graphic mask in Register C with the graphic character in Register A
018B
 ↳ FINSTB
LD (DE),A12
Save the adjusted graphic character in Register A at the location of the video memory pointer in Register Pair DE
018C
RST 08H + “)”
We need to check HL against 29H (ASCII: )) so we 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).
018E
RETC9
RETurn to CALLer
018F
 ↳ SBIT
OR CB1
SET the graphic bit by combining the graphic mask in Register C with the graphic character in Register A
0190-0191
JR 018BHJP FINSTB18 F9
Jump back a few bytes to 018BH
0192
 ↳ TBIT
AND CA1
POINT the graphic bit by combining the graphic mask in Register C with the graphic character in Register A
0193
ADD FFH
Subtract one from the value in register A.
0195
SBC A,A9F
Adjust the value in Register A so that A will equal zero if the bit was off in Register A
0196
PUSH HLE5
Save the current BASIC program pointer in Register Pair HL on the STACK
0197-0199
CALL 098DHCALL CONIACD 8D 09
Save the value in Register A as the current result in the ACCumulator (i.e., 4121H-4122H)
019A
POP HLE1
Get the current BASIC program pointer from the STACK and put it in Register Pair HL
019B-019C
JR 018CHJR FINPTB18 EF
Jump to 018CH

019DH-01C8H – LEVEL II BASIC INKEY$ ROUTINE – “INKEY”

019D
 ↳ INKEY
RST 10HCHRGETD7
Since we need to bump the current BASIC program pointer in Register Pair HL until it points to the next character, call the EXAMINE NEXT SYMBOL routine at RST 10H.

The RST 10H routine parses the characters starting at HL+1 for the first non-SPACE,non-09H,non-0BH character it finds. On exit, Register A will hold that character, and the C FLAG is set if its alphabetic, and NC FLAG if its alphanumeric. All strings must have a 00H at the end.
019E
PUSH HLE5
Save the current BASIC program pointer in Register Pair HL on the STACK
019F-01A1
LD A,(4099H)LD A,(CHARC)3A 99 40
Put the last key pressed (stored at 4099H) and put it in Register A
01A2
OR AB7
Set the status flags
01A3-01A4
JR NZ,01ABHJR NZ,BUFCIN20 06
Jump to 01ABH (to skip the next character scan) if a key has been pressed
01A5-01A7
 ↳ MRCHRI
CALL 0358HCALL ISCHARCD 58 03
Go scan the keyboard
01A8
OR AB7
Set the status flags
01A9-01AA
JR Z,01BCHJR Z,NULRT28 11
Jump to 01BCH if a key wasn’t pressed
01AB
 ↳ BUFCIN
PUSH AFF5
Save the key pressed (held in Register A) to the top of STACK
01AC
XOR AAF
Clear the buffered character by zeroing Register A
01AD-01AF
LD (4099H),ALD (CHARC),A32 99 40
Save the value in Register A as the last key pressed (which is kept at 16537).
Note: 4099H holds the last key pressed
01B0
INC A3C
Increment the value in Register A (which is going to represet the size of the character string to be built)
01B1-01B3
CALL 2857HCALL STRINICD 57 28
Make sure there is room 1 byte of space in the string space RAM area by calling 2857H to make an entry in string space
01B4
POP AFF1
Get the last key pressed from the STACK and put it in Register A
01B5-01B7
LD HL,(40D4H)LD HL,(DSCTMP+1)2A D4 40
Load Register Pair HL with 2nd byte of the VARPTR for the string being created (which starts at 40D3H)
01B8
LD (HL),A77
Save the last key pressed in Register A at the location of the string pointer in Register Pair HL
01B9-01BB
JP 2884HJP PUTNEWC3 84 28
Go save the string’s VARPTR as the current result
01BC-01BE
 ↳ NULRT
LD HL,1928HLD HL,REDDY-121 28 19
Load Register Pair HL with the starting address of the “READY” message (which is 6440)
01BF-01C1
LD (4121H),HLLD (FACLO),HL22 21 41
Save the address in Register Pair HL as the current result in the ACCumulator (i.e., 4121H-4122H)
01C2-01C3
LD A,03H3E 03
Load Register A with a string number type flag
01C4-01C6
LD (40AFH),ALD (VALTYP),A32 AF 40
Save the value in Register A as the current number type (which is at 16559).
Note: 40AFH holds current variable’s type flag
01C7
POP HLE1
Get the current BASIC program pointer from the STACK and put it in Register Pair HL
01C8
RETC9
RETurn to CALLer

01C9H-01D2H – LEVEL II BASIC CLS ROUTINE – “CLS”

A CALL 1C9H will clear the screen, select 64 characters and home the cursor. All registers are used.

To use a ROM call to clear the screen, CALL 01C9H. The cursor is reset to the home position, which is 3C00H.
01C9-01CA
 ↳ CLS
LD A,1CH3E 1C
Load Register A with the ASCII character to home the cursor
01CB-01CD
CALL 033AHCALL OUT2DCD 3A 03
Go send the character in Register A (i.e., the ASCII character to home the cursor) to the video display
01CE-01CF
LD A,1FH3E 1F
Load Register A with the ASCII character to clear to the end of the screen
01D0-01D2
JP 033AHJP OUT2DC3 3A 03
Go send the character in Register A (i.e., the ASCII character to clear to the end of the screen) to the video display

01D3H-01D8H – LEVEL II BASIC RANDOM ROUTINE – “RANDOM”

This is part of the RANDOM routine which takes a value out of the REFRESH register, stores it in location 40ABH and then returns.

A call to 01D3H reseeds the random number seed (location 40AB) with the current contents of the refresh register.

NOTE: To run a RANDOM (seed the random number generator) via a ROM call just call CALL 01D3H. This causes the contents of R (memory refresh) to be stored in 40ABH. The entire 24 bit seed is stored in 40AAH-40ACH.
01D3
 ↳ RANDOM
LD A,RED 5F
Load Register A with the current value of the refresh register
01D5-01D7
LD (40ABH),ALD (RNDX+1),A32 AB 40
Save the pseudi-random value in Register A to 40ABH (the random number seed)
01D8
RETC9
RETurn to CALLer

*01D9-01F7H – Model 4 Gen 1 Routine – Print Screen Routine – “$PRSCN”
This routine copies all 1024 characters from the screen to the printer. If the printer is unavailable, this routine waits until the printer becomes available. If BREAK is pressed, this routine returns to the caller.

*01D9
“PRSCN”
Load HL with the memory location for the beginning of the video RAM.
Difference between M1 and M3: The routine to print the contents of the screen on the line printer is located from 01D9H to 01F4H on the Model III. On the Model I, 01D9H – 01F7H contains the routine to output one bit to the cassette.
*01DC
LD A,(HL)
Put the character at the screen location stored in HL into A.
*01DD
CP 80H
Check A against 80H, which represets the lowest graphic character. If A < 80H then the character is NOT graphic and the the CARRY will be set. Otherwise NC is set to show that the character is a graphic character.
*01DF
If the CARRY FLAG is set, we have a non-graphic characters, so skip the next instruction.
*01E1
LD A,2EH
Overwrite the current character held in Register A with a ., so that all graphic characters are printed as .‘s.
*01E3
Call the PRINT CHARACTER routine at 003BH (which sends the character in the A register to the printer).
*01E6
INC HL
Bump HL to the next character on the screen.
*01E7
BIT 6,H
Check the 6th Bit in H to see if we are at the end of the line (meaning that H is now 64; 1 character beyond the 63 maximum per lime).
*01E9
If we are at 64, then JUMP to 0214H for a new line.
*01EB
LD A,L
Prepare to test of end of line by loading Register A with Register L.
*01EC
AND 03FH
AND the contents of A with 3FH (Binary: 00111111) to turn off Bits 7 and 6, making the maximum number A can be 3FH (Decimal: 63).
*01EE
If any of the bits 5-0 are still “1”, then we are not at the end of the line. With this, loop back to 01DCH for the next character.
*01F0
GOSUB to 0214H for a new line.
Difference between M1 and M3: 01F0H contains CALL 0221H instruction on Model I, and CALL 0214H instruction on Model III.
*01F3
Loop back to 01DCH for the next character.
Difference between M1 and M3: Contains LD B,5CH instruction on Model I, JR 01DCH instruction on Model III.
*01F5-01F6
 ↳ CT3
DJNZ 01F5HDJNZ CT310 FE
Loop for delay
*01F7
RETC9
RETurn to CALLer

*01D9 – Model 4 Gen 2 Routine

*01D9
JP 3027HC3 27 30
Jump to the new PRINT SCREEN by first jumping to 3027H, which is just a JUMP to 37A5H.

*01DC-01E5H – Model 4 Gen 2 Routine to wait for either PRINTER READY or a BREAK key

*01DC
CALL 044BHCD 4B 04
GOSUB to 044BH which will check to see if PRINTER READY by polling port F8H
*01DF
RET ZC8
If it is ready (because Z is set) then RETURN.
*01E0
CALL 028DHCD 8D 02
GOSUB to the $KBBRK routine to check for a BREAK key only
*01E3
Loop back to 01DCH to retry the printer if the BREAK wasn’t pressed
*01E5
RETC9
If the BREAK key was pressed, then RETurn to caller

*01E6-01F7H – Model 4 Gen 2 Routine – Called from 0102H after displaying the CASS, MEMORY SIZE, and RADIO SHACK messages

*01E6
LD HL,0202H21 02 02
Point HL to 0202H which is where the copyright message is stored.
*01E9
NOP00
No Operation
*01EA
CALL 021BHCD 1B 02
GOSUB to 021BH. Note; 021BH will display the character at (HL) until a 03H is found.
*01ED
LD HL,3030H213030
Set HL to 3030H, which is a JUMP to 37EAH for STRING=DATE$+””+TIME$.
*01F0
LD (4177H),HL
Load the memory location held at 4177H with HL.

NOTE: 4177H is the TIME$ vector.
*01F3
JP 022EHC3 2E 02
JUMP to 022EH to do the final cleanup before entering BASIC … Enable Interrupts and JUMP to READY prompt
*01F6
NOP00
No Operation
*01F7
NOP00
No Operation

01F8 – Turn Off The Cassette Motor – “$CSOFF”
After writing data to the cassette, this routine should be called to turn off the cassette drive. There are no entry conditions and no registers are modified.

01F8
“CSOFF”
JUMP to 300CH to turn the cassette off.
Difference between M1 and M3: In the Model I, the routine to turn off the cassette recorder is located from 01F8H to 0211H. In the Model III, 01F8H contains a jump to 300CH ( the location of a vector to the “turn off cassette” routine in the Model III). 01FBH through 0201H contain the time delay routine (see notes on 0060H), and 0202H through 020FH contains the text “(c) ’80 Tandy” and a carriage return.

01FB-0201 – DELAY ROUTINE – “$DELAY”

  • This is a delay loop. The BC register pair is used as the loop counter. The duration of the delay, in microseconds, is the value of BC times 14.65. Register A is used.
01FB
LD A,A
Top of the loop – Load A with A … just a waste of some cycles.
01FC
DEC BC
Decrement the counter in register pair BC
01FD-01FE
LD A,B
OR C
The easiest way to test a 2 byte register for zero is to load the MSB into A and then OR it with the LSB. If the MSB was 0 and the LSB was 0, then A will be 0.
01FF
Loop until the counter in register pair BC is equal to zero.
0201
RET
Return.

202 – Message Storage Location

0202
(C) “80 Tandy” + 0DH
Copyright message storage area.

*0210 – Model 4 Gen 1 – These instructions are never called or used.

*0210-0211
LD E,3DH
I do not see that this command is ever executed as it is never called. However, it loads E with 3DH, most likely to toss off an error.

*0210 – Model 4 Gen 2 – These instructions are never called or used.

*0211
NOP
No Operation
*0211
NOP
No Operation

0212H – This continues a subroutine and was JUMPed to from 022CH. It zeroes A and all flags everything and RETURNs.
Difference between M1 and M3: In the Model I, routines to define cassette drive (0212H – 021DH), reset the cassette input port FFH (021EH – 022BH), and to blink the asterisk while reading a cassette (022CH – 0234H). In the Model III, a routine to insure compatibility with programs that define the cassette drive (XOR A followed by RET, located at 0212H & 0213H), a subroutine used by the routine that begins at 01D9H (0214H 0227H), a couple of cassette-related segments (0228H – 022DH), and an EI instruction followed by JP 1Al9H (enable interrupts and return to BASIC “READY”, located at 022EH – 0231H).

0212
XOR A
Set A to ZERO and clear all status flags.
0213
RET
Return.

0216-021A – Display a Carriage Return

0214
LD A,0DH
Load A with 0DH (ASCII: Carriage Return).
0216
Call the PRINT CHARACTER routine at 003B (which sends the character in the A register to the printer).
0219
XOR A
Set A to ZERO and clear all status flags.
021A
RET
Return.

021B-0227 – “$VDLINE” – Display a Line Until 03H or 0DH Reached.
This subroutine displays a line. The line must be terminated with an ASCII ETX (X’03’) or carriage return (X’0D’). If the terminator is a carriage return, it will be printed; if it is an ETX, it will not be printed. This allows VDLINE to position the cursor to the beginning of the next line or leave it at the position after the last text character. On entry (HL) shuold contain the output text, terminated by a 03H or a 0DH.

021B
“VIDLINE”
LD A,(HL)
Put the memory contents of (HL) into Register A.
021C
INC HL
Bump HL.
021D
CP 03H
Check those memory contents against 03H to see if it is the end of message.
021F
RET Z
If it was the end of message, RETURN.
0220
If it was NOT the end of message, call the PRINT CHARACTER routine at 0033 (which sends the character in the A register to the printer).
0223
CP 0DH
Check to see if it was a carriage return.
0225
If it was NOT a carriage return, loop back to load A with the next character.
0227
RET
If it WAS a carriage return, RETURN.

0228H – This continues a subroutine and was JUMPed to from 023DH. It puts 3000H into the memory location pointed to by the stack pointer, and JUMPs to 302AH.

0228
EX (SP),HL
Put HL (which presumably has a return address in it) into the memory location of the STACK pointer.
0229
JUMP to 302AH.

NOTE: 302AH is an entry in a jump vector table that JUMPs to 31F7H. 31F7H checks to see if we have a PRINT #.

022CH – BLINK ASTERISK routine – This routine is CALLED from 02E7 and alternatively displays and clears an asterisk in the upper right hand corner of the video display.

022C
JUMP to 0212H to zero the flags and RETURN.

022EH – Final cleanup before entering BASIC … Enable Interrupts and JUMP to READY prompt

022E
EI
Enable Interrupts.
022F
Show READY prompt by jumping to 1A19H.

*0232 – Model 1 Gen 1 – These instructions are never called or used.

*0232
CCF
*0233
INC A
*0234
RET

*0232 – Model 1 Gen 2 – These instructions are never called or used.

*0232
NOP
*0233
NOP
*0234
NOP

0235-0240 – CASSETTE ROUTINE – Read a Byte from Cassette – “CSIN”
After the completion of a $CSHIN call, this $CSIN routine begins inputting data, one byte at a time. This routine MUST be called often enough to keep up with the baud rate. There are no entry conditions. A is modified to hold the data byte.
Difference between M1 and M3: In the Model I, 0235H – 0240H contains the routine to read one byte from the cassette, and 0241H – 0260H contains the routine to get one bit from the cassette. In the Model III, 0235H – 023CH contain the start of the Model III routine to read one byte from cassette, 023DH – 0242H is part of the routine that begins at 0287H (writes cassette leader and sync byte), 0243H – 024CH is the actual start of the routine to search for the cassette leader and aync byte, 024DH – 0252H is the actual start of the routine to write a byte to tape, and 0253H – 025EH is a subroutine used by the system to select 500 or 1500 baud tape speed.

0235
“CSIN”
PUSH DE
Save the value in register pair DE on the STACK.
0236
PUSH BC
Save the value in register pair BC on the STACK.
0237
PUSH HL
Save the value in register pair HL on the STACK.
0238
LD HL,(420EH)
Put the TAPE READ VECTOR (stored at 420EH) into HL.
023B
EX (SP),HL
Replace the value at the top of the stack with the TAPE READ VECTOR (stored at 420EH), and what used to HL at the top of this routine into Register Pair HL.
023C
RET
Go to the TAPE READ VECTOR.
NOTE: When a routine is CALLed, the RETurn address is put at the top of the stack; so RET jumps to the value at the top of the STACK.

023D – This continues a subroutine and was JUMPed to from 028BH to to set the cassette write vector. It just PUSHes HL, puts 3000H into HL, and JUMPs out to 0228H.

023D
PUSH HL
Save the value in register pair HL on the STACK.
023E
Load HL with 3000H.
0241
JUMP back to 0228H.

0243-024B – CASSETTE ROUTINE – Read a Byte from Cassette

0243
DI
Disable interrupts.
0244
GOSUB to 300FH to start the cassette.
0247
PUSH HL
Save the value in register pair HL on the STACK.
0248-024A
HL = 3006H
024B
JUMP back to 0228H.

024D-0252 – CASSETTE ROUTINE – Write a Byte to Cassette

024D
PUSH HL
Save the value in register pair HL on the STACK.
024E
LD HL,(420CH)
Load HL with the memory contents of the TAPE WRITE VECTOR.
0251
EX (SP),HL
Put the TAPE WRITE VECTOR (stored at 420CH) into the memory location pointed to by the STACK, and the memory location pointed to the STACK into HL.
0252
RET
RETURN to the memory address held in the TAPE WRITE VECTOR.
NOTE: When a routine is CALLed, the RETurn address is put at the top of the stack; so RET jumps to the value at the top of the STACK.
0253
EX (SP),HL
Take the RETURN ADDRESS of whoever called this routine and put it into HL.
0254
LD A,(4211H)
Load A with the contents of memory location 4211H. Memory location 4211H is the Cassette Baud Rate Select. It will be Z for 500 baud, and NZ for 1500 baud.
0257
OR A
Set flags for A.
0258
If A was a zero, jump to 025DH to leave the routine with HL as is.
025A
INC HL
If A was not zero, bump HL 3 times to move to the fast vector.
025B
INC HL
(Bump 2).
025C
INC HL
(Bump 3).
025D
EX (SP),HL
Put HL as the RETURN ADDRESS and restore HL.
025E
RET
RETURN.
025F
POP BCC1
Clear out the STACK
0260
RETC9
RETurn to CALLer
0261
GOSUB to the very next instruction.

0261H-0263H – CASSETTE ROUTINE – “TWOCSO”

0261-0263
 ↳ TWOCSO
CALL 0264HCALL CASOUTCD 64 02
Write the clock pulse by calling the WRITE ONE BYTE TO CASSETTE routine at 0264H (which writes the byte in the A Register to the cassette drive selected in the A register)

0264 – “$CSOUT” – Output a byte to cassette.
After writing the header with $CSHWR, use this $CSOUT to write the data, one byte at a time. You MUST call $CSOUT often enough to keep up with the baud rate. Register A needs to hold the data byte on entry.
Difference between M1 and M3: In the Model I, 0264H – 0283H contains the routine to output one byte to the cassette. In the Model III, 0264H – 0266H contains a jump to 024DH (the start of the Model III routine to output one byte to cassette), followed by time data (60 seconds, 60 minutes, 24 hours) at 0266H – 0268H, followed by twelve bytes which contain the length of each of the twelve months (0264H – 0274H). This is followed by two NOPs, then starting at 0277H is a 1DH byte, a 1EH byte, the message “Diskette?”, and finally a 03H byte (at 0282H).

0264
JUMP to 024DH to write a byte to cassette.

0266 – Storage location for the maximum number of seconds in a minute, minutes in an hour, hours in a day, and days in a month.

0266
3C 3C 18
Time Data (60, 60, 24).
0269
1F 1C 1F 1E
Month Lengths.
026D
1F 1E 1F 1F
For DATE$.
0271
1E 1F 1E 1F
0275
00 00
Unused.
0277
1D
Group Separator.
0278
1E
Record Separator.
0279
“DISKETTE?” + 03H
Message Space.
0283
F2
UNUSED.

0284 – This subroutine is called by 2076H to turn the tape on, no header – it jumps out to 023DH.
Difference between M1 and M3: In the Model I, this area contains several cassette I/O routines, including turn on cassette, write leader and sync byte (0284H); write leader and sync byte (0287H); turn on cassette, search for leader and sync byte (0293H); search for leader and sync byte (0296H), put 2 asterisks in upper right corner of video ( part of previous routines, begins at 029FH). In the Model III, 0284H contains a JP 0287H instruction (faster than three NOPs), while 0287H is the start of the routine to turn on the cassette, write leader and sync byte. 028DH – 0292H contains the fast routine to check if BREAK is depressed. 0293H contains a JP 0243H instruction, while 0296H contains a JR 0243H (0243H is the actual start of the routine to turn on the cassette, search for leader and sync byte). 0298H – 02A0H is the machine language routine to turn on the built-in clock display (in the upper right hand corner of the video display), while 02A1H – 02A8H is the location of the corresponding routine to turn the clock display back off.

0284
JUMP to 0287H (the very next instruction anyway!), which was the the “$CSHWR” routine in the Model I ROM. That routine writes tape leader and the A5H sync byte. DE and HL are unchanged.

Load register B with the number of bytes to be written.

0287 – Write Leader and Sync Byte – “$CSHWR”
Each cassette record begins with a header consisting of a leader sequence and a synchronization byte. This $CSHWR routine turns on the cassette and writes out this header. There are no entry conditions. A is altered by this routine.

0287
“CSHWR”
DI
Disable Interrupts.
0288
GOSUB to 300FH to turn on the cassette.
028B
JUMP to 023DH to set the CASSETTE WRITE VECTOR.

028DH – “$KBBRK” -Check for a BREAK key only. This is a fast key scan routine which looks solely for the BREAK key. Use this routine if you want to minimize the keyboard scan time without totally locking out the keyboard. On exit NZ will be set if BREAK was set. This subroutine is called by 0444H (in the middle of the PRINTER ROUTINE) to check for a BREAK key.

028D
“KBBRK”
LD A,(3840H)
Check for BREAK Key. First, load A with the memory contents of 3840H (which is the keyboard scan of 14400, the 7th keyboard line), to check for a BREAK. 14400 is ENTER (01) CLEAR (02) BREAK (04) RIGHT ARROW (08) LINE FEED (16) LEFT ARROW (32) SPACE (64)
0290
AND 4
AND the memory contents of 3840H with 04H (Binary: 0000 0100) to isolate only Bit 3. This a precursor to a future test to see if it was a BREAK key.
0292
RET
RETURN.

0293 – CASSETTE ROUTINE – Read the Header and Sync Bytes

0293
JUMP to 0243H to read the cassette header.

0296 – CASSETTE ROUTINE – “CSHIN” – Search for Cassette Header and Sync Byte
Each cassette record begins with a header consisting of a leader sequence and synchronization byte. $CSHIN turns on the cassette drive and begins searching for this header information. The subroutine returns to the calling program after the sync-byte has been read. There are no entry conditions. Register A is altered by the routine.

0296
JUMP to 0243H to read the cassette header.

0298 – Enable the Clock Display – “CLKON”
No entry conditions. A is altered by this routine.

0298
“CLKON”
LD A,(4210H)
Put the contents of memory location 4210H into A.

NOTE: 4210H holds the bit mask for port ECH. Port ECH stores miscellaneous controls.
029B
SET 0,A
Set BIT 0 of A.
029D
LD (4210H),A
Put the modified Clock Bit (stored in A) into the memory location 4210H.

NOTE: 4210H holds the bit mask for port ECH. Port ECH stores miscellaneous controls.
02A0
RET
RETURN.

02A1 – Disable the Clock Display – “CLKOFF”
No entry conditions. A is altered by this routine.

02A1
“CLKOFF”
LD A,(4210H)
Put the clock bit stored in memory location 4210H into A.

NOTE: 4210H holds the bit mask for port ECH. Port ECH stores miscellaneous controls.
02A4
RES 0,A
Reset BIT 0 of A.
02A6
JUMP to 029DH.

*02A8 – Model 4 Gen 1 – These instructions are never called or used.

*02A8
RETC9
RETurn to CALLer

*02A8 – Model 4 Gen 2 – These instructions are never called or used.

*02A8
NOP

02A9H-0329H – LEVEL II SYSTEM ROUTINE-ENTRY POINT – “ENBLK”

02A9-02AB
 ↳ ENBLK
CALL 0314HCALL CADRINCD 14 03
Go read 2 bytes from the cassette, which should be the start/execution address, and return with it in Register Pair HL
02AC-02AE
LD (40DFH),HLLD (TEMP),HL22 DF 40
Save the just read execution address from HL into 40DFH.
Note: 40DFH-40E0H is also used by DOS
02AF-02B1
CALL 01F8HCALL CTOFFCD F8 01
Go turn off the cassette motor
02B2-02B4
 ↳ SYSTEM
CALL 41E2HCALL SYSOUTCD E2 41
Go call the DOS link at 41E2H.
In NEWDOS 2.1, this is called during a SYSTEM operation

*02B5-02B7 – Model 4 Gen 1 – Set the STACK Pointer.

*02B5-02B7
LD SP,4288HLD SP,BUFINI+16031 88 42
Set the STACK pointer to 4288H (which is the assumed load address). This location passes control to the routine used by the BASIC command SYSTEM

*02B5-02B7 – Model 4 Gen 2 – Set the STACK Pointer.

*02B5-02B7
LD SP,42E8HLD SP,BUFINI+25631 E8 42
Set the STACK pointer to 42E8H (which is the assumed load address). This location passes control to the routine used by the BASIC command SYSTEM
02B8-02BA
CALL 20FEHCALL CRDOCD FE 20
GOSUB to display a carriage return on the video display if necessary
02BB-02BC
LD A,2AHLD A,”*”3E 2A
Load Register A with an character (which will form the next prompt)
02BD-02BF
CALL 032AHCALL OUTDOCD 2A 03
Go display the character in Register A on the video display
02C0-02C2
CALL 1BB3HCALL QINLINCD B3 1B
We need a filename now, so go get the input from the keyboard

*02C3-02C5 – Model 4 Gen 1 – Deal with the BREAK Key.

*02C3-02C5
JP C,06CCHJP C,RESETRDA CC 06
If a BREAK key was hit (because the Carry flag is now on), go to the Level II BASIC READY routine

*02C3-02C5 – Model 4 Gen 2 – Deal with the BREAK Key.

*02C3
JP C,006DHDA 6D 00
If a BREAK key was hit (because the Carry flag is now on), go to new routine at 006DH
02C6
RST 10HCHRGETD7
Since we need to bump the input buffer pointer in Register Pair HL until it points to the first character input, call the EXAMINE NEXT SYMBOL routine at RST 10H.

The RST 10H routine parses the characters starting at HL+1 for the first non-SPACE,non-09H,non-0BH character it finds. On exit, Register A will hold that character, and the C FLAG is set if its alphabetic, and NC FLAG if its alphanumeric. All strings must have a 00H at the end.
02C7-02C9
JP Z,1997HJP Z,SNERRCA 97 19
Display a ?SN ERROR if there wasn’t any input
02CA-02CB
CP 2FHLD A,”/”FE 2F
Check to see if the character at the location of the input buffer pointer in Register A is a / character
02CC-02CD
JR Z,031DHJR Z, GOOD28 4F
Jump to 031DH if the character at the location of the input buffer pointer in Register A is a /
02CE-02D0
CALL 0293HCALL CSRDONCALL CSRDONCD 93 02
Go turn on the cassette motor
02D1-02D3
LOPHD
CALL 0235HCALL CASINCD 35 02
Top of a small loop. Calls the READ ONE BYTE FROM CASSETTE routine at 0235H (whichh reads one byte from the cassette drive specified in Register A, and returns the byte in Register A)
02D4-02D5
CP 55HFE 55
Check to see if the byte read from the cassette in Register A is a header byte (=55H)
02D6-02D7
JR NZ,02D1HJR NZ,LOPHD20 F9
Loop until the header byte is found
02D8-02D9
LD B,06H06 06
If were here, we got the header byte, so load Register B with the length of the filename to read from the cassette (which is 6 characters)
02DA
 ↳ CHKBYT
LD A,(HL)7E
Load Register A with the character at the location of the current input buffer pointer in Register Pair HL
02DB
OR AB7
Check to see if the character at the location of the current input buffer pointer in Register A is an end of input character
02DC-02DD
JR Z,02E7HJR Z,GETDT28 09
Jump out of this ‘read the filename from the cassette’ routine if the character at the location of the current input buffer pointer in Register A is an end of input character
02DE-02E0
CALL 0235HCALL CASINCD 35 02
Calls the READ ONE BYTE FROM CASSETTE routine at 0235H (which reads one byte from the cassette drive specified in Register A, and returns the byte in Register A)
02E1
CP (HL)BE
Check to see if the character at the location of the current input buffer pointer in Register Pair HL is the same as the character read from the cassette in Register A
02E2
INC HL23
Increment the input buffer pointer in Register Pair HL
02E3-02E4
JR NZ,02D1HJR NZ,LOPHD20 EC
Jump to 02D1H (skip to the next program on cassette) if the character at the location of the current input buffer pointer in Register Pair HL isn’t the same as the character read from the cassette in Register A
02E5-02E6
DJNZ 02DAHDJNZ CHKBYT10 F3
Loop until the whole of the filename has been read from the cassette and checked against the user response
02E7-02E9
GETDT
CALL 022CHCALL BCASINCD 2C 02
Call the BLINK ASTERISK routine at 022CH which alternatively displays and clears an asterisk in the upper right hand corner of the video display
02EA-02EC
 ↳ GETDT2
CALL 0235HCALL CASINCD 35 02
Calls the READ ONE BYTE FROM CASSETTE routine at 0235H (whichh reads one byte from the cassette drive specified in Register A, and returns the byte in Register A)
02ED-02EE
CP 78HFE 78
Check to see if the byte read from the cassette in Register A is an execution address header byte (which is 78H)
02EF-02F0
JR Z,02A9HJR Z,ENBLK28 B8
Jump if the byte read from the cassette in Register A is an execution address header byte
02F1-02F2
CP 3CHFE 3C
Check to see if the byte read from the cassette in Register A is a file block header byte (which is 3CH)
02F3-02F4
JR NZ,02EAHJR NZ,GETDT220 F5
Loop until either an execution address header byte or a file block header byte is read from the cassette
02F5-02F7
CALL 0235HCALL CASINCD 35 02
Calls the READ ONE BYTE FROM CASSETTE routine at 0235H (which reads one byte from the cassette drive specified in Register A, and returns the byte in Register A)
02F8
LD B,A47
Load Register B with the count of bytes to be loaded in Register A
02F9-02FB
CALL 0314HCALL CADRINCD 14 03
Read the file block’s starting address from the cassette and return with it in Register Pair HL
02FC
ADD A,L85
For purposes of calculating a checksum, add the LSB of the file block’s starting address in Register L to the MSB of the file block’s starting address in Register A
02FD
LD C,A4F
Load Register C with the file block’s starting checksum in Register A
02FE-0300
 ↳ LDATIN
CALL 0235HCALL CASINCD 35 02
Calls the READ ONE BYTE FROM CASSETTE routine at 0235H (which reads one byte from the cassette drive specified in Register A, and returns the byte in Register A)
0301
LD (HL),A77
Save the byte read from the cassette in Register A at the location of the memory pointer in Register Pair HL
0302
INC HL23
Increment the memory pointer in Register Pair HL
0303
ADD A,C81
Add the value of the current checksum in Register C to the value in Register A
0304
LD C,A4F
Load Register C with the updated checksum in Register A
0305-0306
DJNZ 02FEHDJNZ LDATIN10 F7
Loop until the whole file block has been read
0307-0309
CALL 0235HCALL CASINCD 35 02
Calls the READ ONE BYTE FROM CASSETTE routine at 0235H (which reads one byte from the cassette drive specified in Register A, and returns the byte in Register A). This reads in the checksum from cassette
030A
CP CB9
Check to see if the computed checksum in Register C is the same as the checksum read from the cassette in Register A
030B-030C
JR Z,02E7HJR Z,GETDT28 DA
If its the same, jump to 02E7H because the next instructions are for bad checksums
030D-030E
LD A,43H3E 43
Load Register A with a C character
030F-0311
LD (3C3EH),A32 3E 3C
Display the C character in Register A on the video display (at 15422)
0312-0313
JR 02EAHJR GETDT218 D6
Jump to 02EAH and keep reading bytes

0314H – Read 2 bytes from the tape into Register Pair HL – “CADRIN”

0314
 ↳ CADRIN
CALL 0235HCALL CASINCD 35 02
Calls the READ ONE BYTE FROM CASSETTE routine at 0235H (whichh reads one byte from the cassette drive specified in Register A, and returns the byte in Register A)
0317
LD L,A6F
Load Register L with the byte read from the cassette in Register A (which is the LSB of the 16 bit value)
0318-031A
CALL 0235HCALL CASINCD 35 02
Calls the READ ONE BYTE FROM CASSETTE routine at 0235H (whichh reads one byte from the cassette drive specified in Register A, and returns the byte in Register A)
031B
LD H,A67
Load Register H with the byte read from the cassette in Register A (which is the MSB of the 16 bit value)
031C
RETC9
RETurn to CALLer

031DH – Execute the Cassette Program which was Loaded – “GODO”

031D
 ↳ GODO
EX DE,HLEB
Load Register Pair DE with the pointer to the BASIC command line being processed (held in Register Pair HL)
031E-0320
LD HL,(40DFH)LD HL,(TEMP)2A DF 40
Load Register Pair HL with the execution address (which is stored at 40DFH).
Note: 40DFH-40E0H is also used by DOS
0321
EX DE,HLEB
So that we can run a RST 10H in the next instruction, we need to exchange the execution address in Register Pair HL with the input buffer pointer in Register Pair DE
0322
RST 10HCHRGETD7
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.

The RST 10H routine parses the characters starting at HL+1 for the first non-SPACE,non-09H,non-0BH character it finds. On exit, Register A will hold that character, and the C FLAG is set if its alphabetic, and NC FLAG if its alphanumeric. All strings must have a 00H at the end.
0323-0325
CALL NZ,1E5AHCALL NZ,LINGETC4 5A 1E
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-numeric character, the conversion is stopped
0326-0327
JR NZ,02B2HJR NZ,SYSTEM20 8A
Jump if it turns out there weren’t any digits (i.e., bad input) in the input
0328
EX DE,HLEB
Since there were digits (or else we would have jumped in the prior instruction), exchange the input buffer pointer in Register Pair HL with the execution address in Register Pair DE
0329
JP (HL)E9
Jump to the execution address (i.e. “/xxxx”) which is in Register Pair HL

032AH-0347H – OUTPUT ROUTINE – “OUTCH1” and “OUTDO”

This is a general purpose output routine which outputs a byte from the A Register to video, tape or printer. In order to use it, the location 409CH must be loaded with -1 for tape, 0 for video or 1 for the line printer.
Note: 409CH holds the current output device flag: -1=cassette, 0=video and 1=printer.

This routine outputs a byte to device determined by byte stored at (409CH) – FFH=Tape, 0=Video, l=Printer. When calling, A = output byte. Uses AF. Warning: This routine CALLs a Disk BASIC link at address 41ClH which may have to be “plugged” with a RETurn (C9H) instruction.
032A
 ↳ OUTDO
PUSH BCC5
We are going to need to use Register C, so push Register Pair BC into the STACK
032B
LD C,A4F
Load Register C with the character to be output in Register A
032C-032E
CALL 41C1HCALL EXOUTCCD C1 41
Go call the DOS link at 41ClH.
In NEWDOS 2.1, this writes to the system output device
032F-0331
LD A,(409CH)LD A,(PRTFLG)3A 9C 40
Load Register A with the current output device number stored in 409CH.
Note: 409CH holds the current output device flag: -1=cassette, 0=video and 1=printer
0332
OR AB7
Since LD doesn’t set flags, in order to be able to test Register A using flags we need to execute an OR A first. This will enable us to set the flags according to the current output device number in Register A
0333
LD A,C79
Load Register A with the character to be output in Register C
0334
POP BCC1
Get the value from the STACK and put it in Register Pair BC
0335-0337
JP M,0264HJP M,CASOUTFA 64 02
If the value of the current output device number is positive it means CASSETTE, so jump to the the WRITE ONE BYTE TO CASSETTE routine at 0264H (which writes the byte in the A Register to the cassette drive selected in the A register)
0338-0339
JR NZ,039CHJR NZ,OUTLPT20 62
Jump to 039CH if the character in Register A is to be sent to the printer

033AH-0347H – OUTPUT ROUTINE – “OUT2D”

A Print routine which performs the same function as 33H except that it doesn’t destroy the contents of the DE Register Pair. This means that all the general purpose registers are saved, which is often desirable

To use a ROM call to print a single character at the current cursor position, and to update the cursor position, load the ASCII value of the character into the A Register And then CALL 033AH.

To display special functions using a ROM call, load the A Register with the value given below for the special function and then CALL 033AH.
  1. Backspace and erase previous character – 08H
  2. Carriage return and linefeed – 0DH
  3. Turn on cursor – 0EH
  4. Turn off cursor – 0FH
  5. Convert to 32 characters per line mode – 17H
  6. Backspace cursor – 18H
  7. Advance cursor one position – 19H
  8. Downward line feed – 1AH
  9. Upward line feed – 1BH
  10. Home (cursor to upper left corner) – 1CH
  11. Move cursor to beginning of current line – 1DH
  12. Erase from cursor position to end of line – 1EH
  13. Erase from cursor position to end of screen – 1FH
033A
 ↳ OUT2D
PUSH DED5
If we’re here, then that value in A wasn’t going to the cassette or the printer, so it must be going to the video. This routine performs the same function as 33H except that it doesn’t destroy the contents of the DE Register Pair. This means that all the general purpose registers are saved, which is often desirable.

Save the value in Register Pair DE on the STACK
033B-033D
CALL 0033HCALL $DSPCD 33 00
Call the DISPLAY A CHARACTER routine at 0033H (which puts the character in Register A on the video screen)
033E
PUSH AFF5
Save the character in Register A on the STACK
033F-0341
CALL 0348HCALL DSPPOSCD 48 03
Go update the current cursor position and test to see if the display memory is full
0342-0344
LD (40A6H),ALD (TTYPOS),A32 A6 40
Save the current cursor line position stored in 40A6H to Register A.
Note: 40A6H holds the current cursor line position
0345
POP AFF1
Get the character from the STACK and put it in Register A
0346
POP DED1
Get the value from the STACK and put it in Register Pair DE
0347
RETC9
RETurn to CALLer

0348H-0357H – VIDEO ROUTINE – “DSPPOS”

0348-034A
 ↳ DSPPOS
LD A,(403DH)LD A,(CAST$)3A 3D 40
Load Register A with the contents of 403DH, which contains, among other things, the screen resolution (32 or 64 wide; Bit 3) the tape relay on/off instruction (Bit 2) and the positive/negative audio pulses (Bits 0-1).
Note: 403DH-4040H is used by DOS
034B-034C
AND 08HAND 0000 1000E6 08
Mask Register A against 00001000 to isolate Bit 3 (the 32/64 character per line flag) in Register A
034D-034F
LD A,(4020H)LD A,(CURSOR)3A 20 40
Load Register A with the LSB of the current cursor position.
Note: 4020H-4021H holds Video DCB – Cursor location
0350-0351
JR Z,0355HJR Z,NT32PS28 03
If Bit 3 of 403DH was a zero, then we have 64 characters per line mode so JUMP down a few instructions to skip over the division needed to drop everything by half to 32 character mode
0352
RRCA0F
Divide the LSB of the current cursor position in Register A by two
0353-0354
AND 1FHAND 0001 1111E6 1F
Mask the cursor line position in Register A for 32 character per line (AND against 0001 1111) to force its position to be no less than 3C00H
0355-0356
AND 3FHAND 0011 1111E6 3F
Mask the cursor line position in Register A for 64 characters per line (AND against 0011 1111) to force its position to be no more than 3FFFH
0357
RETC9
RETurn to CALLer

0358H-0360H – KEYBOARD ROUTINE – “ISCHAR”
Here is the routine to simulate the INKEY$ function. It performs exactly the same function as 2BH but it restores all registers, whereas 2BH destroys the contents of the DE Register Pair. This makes 35BH more useful than 2BH

0358-035A
 ↳ ISCHAR
CALL 41C4HCALL EXINCCD C4 41
Go call the DOS link at 41C4H
035B
PUSH DED5
Since the next routine uses DE, save the value in Register Pair DE on the STACK
035C-035E
CALL 002BHCALL $KBDCD 2B 00
Call the SCAN KEYBOARD routine at 002BH
035F
POP DED1
Get the value from the STACK and put it in Register Pair DE
0360
RETC9
RETurn to CALLer

0361H-0383H – INPUT ROUTINE – “INLIN”

This is one of the general purpose input routines (see 5D9 and 1BB3 also). This routine inputs a string from the keyboard, up to a maximum of 240 characters (F0H), and echoes them to the screen. It puts this data into a buffer located at the address pointed to by the buffer pointer at 40A7H. (e.g. If 40A7H contains 5000H the data will be stored from 5000H onwards). The string is terminated with a zero byte. The program returns from this routine as soon as the ENTER key has been pressed. When it does so, HL contains the start address of the input string and B contains the length of the string. (RST 10H can be used to make HL point to the first character of the string, if required.).
Note: 40A7H-40A8H holds the input Buffer pointer.
0361
 ↳ INLIN
XOR AAF
Zero Register A to clear the buffered character
0362-0364
LD (4099H),ALD (CHARC),A32 99 40
Save the value in Register A as the last key pressed (which is stored in 4099H).
Note: 4099H holds the Last key pressed
0365-0367
LD (40A6H),ALD (TTYPOS),A32 A6 40
Save the value in Register A as the current cursor line position (which is stored in 40A6H).
Note: 40A6H holds the current cursor line position
0368-036A
CALL 41AFHCALL INLINECD AF 41
Go call the DOS link at 41AFH.
In NEWDOS 2.1, this is the satrt of keyboard input
036B
PUSH BCC5
Save Register Pair BC on the STACK
036C-036E
LD HL,(40A7H)LD HL,(BUFPNT)2A A7 40
Load Register Pair HL with the starting address of the input buffer (which is stored in 40A7H).
Note: 40A7H-40A8H holds the input Buffer pointer
036F
LD B,0F0H
Load register B with the length of the input buffer (which is 240).
0371-0373
CALL 05D9HCALL KEYINCD D9 05
“WAIT FOR NEXT LINE” keyboard input routine at 05D9H (which takes keyboard entry until a carriage return, a break, or buffer overrun occurs)
0374
PUSH AFF5
Save the flags on the STACK
0375
LD C,B48
Load Register C with the length of the input in Register B
0376-0377
LD B,00H06 00
Zero Register B so that Register Pair BC will have the length of the input
0378
ADD HL,BC09
Add the length of the input in Register Pair BC to the starting address of the input buffer in Register Pair HL
0379-037A
LD (HL),00H36 00
Save an end of the input character at the location of the end of input pointer in Register Pair HL
037B-037D
LD HL,(40A7H)LD HL,(BUFPNT)2A A7 40
Load Register Pair HL with the starting address of the input buffer (which is 40A7H).
Note: 40A7H-40A8H holds the input Buffer pointer
037E
POP AFF1
Get the flags from the STACK
037F
POP BCC1
Get the value from the STACK and put it in Register Pair BC
0380
DEC HL2B
Decrement the input buffer pointer in Register Pair HL (so that HL is the input area pointer – 1)
0381
RET CD8
Return if the BREAK key was pressed
0382
XOR AAF
Otherwise (i.e., the BREAK key was not pressed), zero all the status flags
0383
RETC9
RETurn to CALLer

0384H-038AH – KEYBOARD ROUTINE – “INCHR”

Waits for keypress
0384-0386
 ↳ INCHR
CALL 0358HCALL ISCHARCD 58 03
Go scan the keyboard
0387
OR AB7
Check to see if a key was pressed
0388
RET NZC0
Return if a key was pressed (meaning OR A was set to NZ)
0389-038A
JR 0384HJR INCHR18 F9
Loop until a key is pressed

038BH-039BH – PRINTER ROUTINE – “FINLPT”

038B
 ↳ FINLPT
XOR AAF
Zero Register A, which then means it contains the device code for VIDEO
038C-038E
LD (409CH),ALD (PRTFLG),A32 9C 40
Save the value in Register A (the current output device code of video) to 409CH.
Note: 409CH holds the current output device flag: -1=cassette, 0=video and 1=printer
038F-0391
LD A,(409BH)LD A,(LPTPOS)3A 9B 40
Load Register A with the current printer carriage position (which is stored at 409BH).
Note: 409BH holds the printer carriage position
0392
OR AB7
Set the flags for the carriage position in Register A
0393
RET ZC8
Return if the carriage position in Register A is equal to zero
0394-0395
LD A,0DHLD A,ENTER3E 0D
Load Register A with a “CARRIAGE RETURN
0396
PUSH DED5
Save the value in Register Pair DE on the STACK
0397-0399
CALL 039CHCALL OUTPUTCD 9C 03
Go send the carriage return character in Register A to the printer
039A
POP DED1
Get the value from the STACK and put it in Register Pair DE
039B
RETC9
RETurn to CALLer

039CH-03C1H – PRINTER ROUTINE – “OUTLPT”

This is the LPRINT routine. All registers are saved. The byte to be printed should be in the A register.
039C
 ↳ OUTLPT
PUSH AFF5
Save the value in Register Pair AF on the STACK
039D
PUSH DED5
Save the value in Register Pair DE on the STACK
039E
PUSH BCC5
Save the value in Register Pair BC on the STACK
039F
LD C,A4F
Load Register C with the character to be sent to the printer in Register A
03A0-03A1
LD E,00H1E 00
Zero Register E (which will ultimately hold the new character/line count of 0CH, 0DH, or 0AH)
03A2-03A3
 ↳ OUTDO
CP 0CHFE 0C
Check to see if the character to be sent to the printer in Register A is equal to 0CH (which is ‘skip to next line’)
03A4-03A5
JR Z,03B6HJR Z,LZRPOS28 10
Jump to 03B6H if the character to be sent to the printer in Register A is equal to 0CH
03A6-03A7
CP 0AHLD A,LINE FEEDFE 0A
Check to see if the character to be sent to the printer in Register A is a line feed character (i.e., 0AH)
03A8-03A9
JR NZ,03ADHJR NZ,LZRNOT20 03
Jump to 03ADH if the character to be sent to the printer in Register A isn’t a line feed character
03AA-03AB
LD A,0DHLD A,CARRIAGE RETURN3E 0D
Load Register A with a carriage return character (i.e., 0DH)
03AC
LD C,A4F
Load Register C with the character to be sent to printer in Register A
03AD-03AE
 ↳ LZRNOT
CP 0DHFE 0D
Check to see if the character to be sent to the printer in Register A is a carriage return character
03AF-03B0
JR Z,03B6HJR Z,LZRPOS28 05
Jump to 03B6H if the character to be sent to the printer in Register A is a carriage return character
03B1-03B3
LD A,(409BH)LD A,(LPTPOS)3A 9B 40
Load Register A with the current printer carriage position (stored in 409BH).
Note: 409BH holds the printer carriage position
03B4
INC A3C
Increment the current carriage position in Register A
03B5
LD E,A5F
Load Register E with the current carriage position in Register A
03B6
 ↳ LZRPOS
LD A,E7B
Load Register A with the current carriage position in Register E. Why do this since its obviously already done? Becasuse this is a jump point!
03B7-03B9
LD (409BH),ALD (LPTPOS),A32 9B 40
Save the current carriage position (which is stored in 409BH) in Register A.
Note: 409BH holds the printer carriage position
03BA
LD A,C79
Load Register A with the character to be sent to the printer in Register C
03BB-03BD
CALL 003BHCALL $PRTCD 3B 00
Call the PRINT CHARACTER routine at 003B (which sends the character in the C Register to the printer)
03BE
POP BCC1
Get the value from the STACK and put it in Register Pair BC
03BF
POP DED1
Get the value from the STACK and put it in Register Pair DE
03C0
POP AFF1
Get the value from the STACK and put it in Register Pair AF
03C1
RETC9
RETurn to CALLer

03C2H-0451H – Model 4 Gen 1 PRINTER ROUTINE

In the Model III, 03C2H – 0451H is the line printer driver routine, 0452H – 0468H is the actual location of the routine to initialize all I/O drivers, 046BH – 0472H is a routine used by the RUN/EDIT/NEW commands to unprotect the video display and to load HL with the start of BASIC program pointer at 40A4H-40A5H, and 0473H-05D0H is the video driver routine and the keyboard driver begins at 3024H in the Model III).
*03C2
LD A,C
A = C (the current character).
*03C3
CP 20H
Check to see if the character is a control character by testing A – 20H. Results:
  • If A=20H it sets the ZERO FLAG
  • If A<20H then the CARRY FLAG will be set
  • if A>=20H then the NO CARRY FLAG will be set.
If A is a CONTROL CHARACTER then C will be set.
*03C5
If A was >= a SPACE, the NC would be set meaning A is a control character, jump to 03E5H to skip a bunch of needless tests.
*03C7
CP 0DH
Check to see if the character is a carriage return.
*03C9
If it is a carriage return, jump to 03F5H.

NOTE: 03F5H prints a character while maintaining page height and width.
*03CB
CP 0CH
Check to see if the character is a FORM FEED.
*03CD
JUMP to 03FFH if it is not a FORM FEED.
*03CF
LD A,(IX+03H)
If we are here then the character must be a printable one, so we need to get the number of lines left in the page and put them into B for a DJNZ countdown.
*03D2
SUB (IX+04H)
Subtract the number of lines printed from A.

NOTE: IX+4 is the number of lines printed.
*03D5
LD B,A
LET B = A
*03D6
GOSUB to 0440H to wait until the printer is ready (honoring BREAK, if hit).
*03D9
LD A,0AH
Put a LINE FEED character into A.
*03DB
OUT (0F8H),A
Output the LINE FEED character to port 0F8H.
NOTE: 0F8H is the printer port. If you put data to it, it prints it. Otherwise, Bits 4-7 hold printer status.
*03DD
JUMP back to 03D6H until the number of lines left in the page is zero.
*03DF
LD (IX+05H),00H
Load the memory location pointed to by IX+5 with a zero. NOTE: IX+5 is the number of characters printed.
*03E3
JUMP to 0439H to set the number of lines printed to 01 and exit

03E5H – Model 4 Gen 1 Inside the PRINTER ROUTINE – If we are here, the characters to be sent to the printer are NOT control characters, so test for graphics (and jump away), and if not, put the character from the PRINTER LOOKUP TABLE into C.

*03E5
CP 80H
Test for a graphics character by comparing A to 80H. If it is a graphics character than NC will be set.
*03E7
JUMP to 0419H to handle the graphics character.
*03E9
LD B,00H
Load B with a 00 (to set a MSB = 0).
*03EB
SUB 20H
Subtract 20H from A to adjust the character to the table.
*03ED
LD C,A
Load C with A. Now BC has the adjusted character value.
*03EE
Load HL with 3145H.

NOTE: 3145H is the PRINTER CHARACTER LOOKUP TABLE.
*03F1
ADD HL,BC
Add BC to HL so that HL will have the character location in the character table.
*03F2
LD C,(HL)
Load C with the character at the position of HL in the character table.
*03F3
JUMP to 0403H to continue.

03F5-0424 – Model 4 Gen 1 Inside the PRINTER ROUTINE – Print A Character Honoring Page Height and Width

*03F5
LD A,(IX+05H)
Load the A with the number of characters printed.

NOTE: IX+5 is the number of characters printed.
*03F8
OR A
Set the flags for A, including a test for zero/none.
*03F9
LD A,C
Put the character held in C into A.
*03FA
If there were ANY characters printed (so A is not zero), jump to 033FH.
*03FC
LD A,0AH
If there weren’t sny characters printed, the load A with 0AH.
*03FE
LD C,A
Load C with 0AH.
*03FF
CP 20H
Check to see if the character is a control character by testing A – 20H. If A=20H it sets the ZERO FLAG. If A<20H then the CARRY FLAG will be set and if A>=20H then the NO CARRY FLAG will be set. If A is a CONTROL CHARACTER then C will be set.
*0401
If it is a control character, jump to 0419H.

0403 – Model 4 Gen 1 Inside the PRINTER ROUTINE – If we are here, then C holds the printable character to be printed as determined by the PRINTER CHARACTER TABLE.

*0403
LD A,(IX+06H)
Load A with the MAXIMUM PRINT WIDTH.

NOTE: IX+06H holds the MAXIMUM PRINT WIDTH.
*0406
INC A
Bump A to one beyond that (i.e., unlimited).
*0407
If the maximum print width is unlimited, jump to 0419H.
*0409
CP (IX+05H)
Check to see if the line is full by comparing A with IX+5.

NOTE: IX+5 is the number of characters printed.
*040C
If the line is NOT full, jump to 0419H.
*040E
GOSUB to 0440H to wait until the printer is ready (honoring BREAK, if hit).
*0411
LD A,0DH
Load A with a carriage return.
*0413
OUT (0F8H),A
Send the carriage return to port 0F8H.

NOTE: 0F8H is the printer port. If you put data to it, it prints it. Otherwise, Bits 4-7 hold printer status.
*0415
LD (IX+05H),00H
Set the number of characters printed to zero.

NOTE: IX+5 is the number of characters printed.
*0419
GOSUB to 0440H to wait until the printer is ready (honoring BREAK, if hit).
*041C
LD A,C
Restore the character held in C back into A.
*041D
OUT (F8H),A
Send the character to port F8H.

NOTE: F8H is the printer port. If you put data to it, it prints it. Otherwise, Bits 4-7 hold printer status.
*041F
INC (IX+05H)
Bump the number of characters printed.

NOTE: IX+5 is the number of characters printed.
*0422
CP 0DH
Check A for a carriage return.
*0424
If A was a carriage return, skip the next few instructions and jump to 042AH.
*0426
CP 0AH
Check to see if the character in register A is 0AH (ASCII: LINE FEED character).
*0428
IF A is not a LINE FEED then jump to 043DH.

042A – Model 4 Gen 1 Inside the PRINTER ROUTINE – If we are here, then we have a LINE FEED or a CARRIAGE RETURN in A.

*042A
LD (IX+05H),00H
Reset the number of characters printed.

NOTE: IX+5 is the number of characters printed.
*042E
INC (IX+04H)
Bump IX+04.

NOTE: IX+4 is the number of lines printed.
*0431
LD A,(IX+04H)
Load A with the number of lines printed.
*0434
CP (IX+03H)
Compare that to the maximum number of lines per page.

NOTE: IX+3 is the maximum number of lines per page.
*0437
Skip the next instruction by JUMPing to 043DH if the number of lines printed is less than maximum number of lines per page.
*0439
LD (IX+04H),01H
We must be at top of page so set the number of lines printed to 01.

NOTE: IX+4 is the number of lines printed.
*043D
XOR A
Clear A and the status bits.
*043E
LD A,C
Load the character into A.
*043F
RET
RETURN.

0440-044A – Model 4 Gen 1 – Inside the PRINTER ROUTINE – Subroutine to wait for PRINTER READY, but Honor a BREAK Key

*0440
GOSUB to 044BH to check the printer.
*0443
RET Z
If it is ready (because Z is set) then RETURN.
*0444
if we are here, the printer is not ready. GOSUB to 028DH to check for a BREAK key being pressed.
*0447
Loop back to 0440H if BREAK wasn’t pressed.
*0449
POP AF
Restore AF from the STACK.
*044A
RET
RETURN.

03C2H-044AH – Model 4 Gen 2 PRINTER ROUTINE

*03C2
LD A,C
A = C (the current character).
*03C3
CP 20H
Check to see if the character is a control character by testing A – 20H. Results:
  • If A=20H it sets the ZERO FLAG
  • If A<20H then the CARRY FLAG will be set
  • if A>=20H then the NO CARRY FLAG will be set.
If A is a CONTROL CHARACTER then C will be set.
*03C5
If A was >= a SPACE, the NC would be set meaning A is a control character, jump to 03E9H to skip a bunch of needless tests.
*03C7
CP 0DH
Check to see if the character is a carriage return.
*03C9
JR Z,0414H28 49
If it is a carriage return, jump to 0414H.

NOTE: 0414H will process a carriage return.
*03CB
CP 0CH
Check to see if the character is a FORM FEED.
*03CD
If it is not a FORM FEED, JUMP to 041DH
*03CF
LD A,(IX+03H)DD 7E 03
If we are here then the character must be a printable one, so we need to get the number of lines left in the page and put them into B for a DJNZ countdown.
*03D2
SUB (IX+04H)DD 96 04
Subtract the number of lines printed from A.

NOTE: IX+4 is the number of lines printed.
*03D5
LD B,A47
Preserve Register A into Register B
*03D6
CALL 01DCHCD DC 01
GOSUB to 01DCH to wait for either PRINTER READY or BREAK key
*03D9
LD A,0AH3E 0A
Put a LINE FEED character into A.
*03DB
OUT (F8H),AD3 F8
Output the LINE FEED character to port 0F8H.
NOTE: 0F8H is the printer port. If you put data to it, it prints it. Otherwise, Bits 4-7 hold printer status.
*03DD
JUMP back to 03D6H until the number of lines left in the page is zero.
*03DF
LD (IX+05H),05HDD 36 05 00
Load the memory location pointed to by IX+5 with a 05H.
NOTE: IX+5 is the number of characters printed.
*03E3
LD (IX+04H),04HDD 36 04 01
Load the memory location pointed to by IX+4 with a 04H.
NOTE: IX+4 is the number of number of lines printed.
*03E7
JUMP to 0448H will will XOR A, Load C into A, and RETurn

03C2H-044AH – Model 4 Gen 2 PRINTER ROUTINE – Jumped here from 03C5 if the character in A was >= a SPACE

*03E9
LD A,(41FBH)3A FB 41
Put the character stored at (41FBH) into Register A
*03EC
OR AB7
Set the FLAGS based on Register A
*03ED
If that character was NULL, then skip the rest of this routine and pick up at 03F6H
*03EF
CP 01HFE 01
If the character in 41FBH was not a 00H, then let’s check to see if it was an 01H
*03F1
JP Z,3045HCA 45 30
If the character in 41FBH was an 01H, JUMP 3045H which simply JUMPs to 378DH to a new routine for Rom GEN 2 which processes printing when a 01H or Line Feed or Carriage Return is the current character being printed
*03F4
JR 041FH18 29
If the character in 41FBH was not a 00H or 01H then JUMP to 041FH to check for exceeding a printer line, advancing if needed, and sending the character to the printer

03F6 – Model 4 Gen 2 PRINTER ROUTINE – Jumped here from 03EDH if the character stored at 41FBH is a ZERO

*03F6
LD A,(41FCH)3A FC 41
Put the character stored at (41FCH) into Register A
*03F9
OR AB7
Set the FLAGS based on Register A
*03FA
If the character stored at (41FCH) was NOT 0, then JUMP to 040AH to check for SPECIAL CHARACTERS, CONTROL CHARACTERS, or TABs
*03FC
LD A,C79
Copy the character held in Register C into Register A for testing
*03FD
CP A0HFE A0
Check to see if the character which was held in Register A is LESS than A0H.
*03FF
If the character is LESS than A0H then the CARRY FLAG will be sent, so JUMP to 041FH to check for exceeding a printer line, advancing if needed, and sending the character to the printer
*0401
CP C0HFE C0
Check to see if the character is a control character by comparing A to C0H
*0403
If A >=C0H then the NO CARRY FLAG will be set and we have either a TAB or a SPECIAL CHARACTER.
*0405
ADD 40HC6 40
If we are here then the character is > A0H but < than C0H, so add 40H to it.
*0407
LD C,A4F
Store the adjusted character back into Register C
*0408
JR 041FH18 15
JUMP to 041FH to check for exceeding a printer line, advancing if needed, and sending the character to the printer

040A – Model 4 Gen 2 PRINTER ROUTINE – Jumped here from 03FAH if the character stored at 41FCH is NOT a ZERO

*040A
LD A,C79
Copy the character held in Register C into Register A for testing
*040B
CP C0HFE C0
Check to see if the character is a control character by comparing A to C0H
*040D
If the character held in Register C was < C0H then the CARRY FLAG will be set and we have a TAB or SPECIAL CHARACTER so JUMP 041FH to check for exceeding a printer line, advancing if needed, and sending the character to the printer
*040F
SUB 20HD6 20
Subtract 20H from the TAB or SPECIAL CHARACTER
*0411
LD C,A4F
Store the adjusted character back into Register C
*0412
JUMP to 041FH to check for exceeding a printer line, advancing if needed, and sending the character to the printer

0414 – Model 4 Gen 2 PRINTER ROUTINE – Jumped here from 03C9 if the character held in REGISTER C (the current character) is a CARRIAGE RETURN

*0414
LD A,(IX+05H)DD 7E 05
Load the Register A with the contents of (IX+5), which is the number of characters printed.
*0417
OR AB7
Set the FLAGS based on the contents of (IX+5)
*0418
If there were NO characters printed, then JUMP to 0434H to print a character and check to see if the line needs to be advanced
*041A
LD A,0AH3E 0A
If there were characters printed, then put a LINE FEED character into Register A
*041C
LD C,A4F
Store the LINE FEED character held in Register A into Register C (which tracks the current character)
*041D
JUMP to 0434H to print a character and check to see if the line needs to be advanced

041F – Model 4 Gen 2 PRINTER ROUTINE – Checks to see if we are at the end of a ilne, advances if needed, and sends the character to the printer

*041F
LD A,(IX+06H)DD 7E 06
Load A with the value stored at (IX+06H) which is the MAXIMUM PRINT WIDTH.
*0422
INC A3C
Bump Register A by 1
*0423
If the MAXIMUM PRINT WIDTH had been reached (meaning that it rolled to 0 when A was bumped), JUMP to 0434H to print a character and check to see if the line needs to be advanced
*0425
CP (IX+05H)DD BE 05
Check to see if the line is full by comparing A with (IX+05H) which holds the number of characters printed.
*0428
If the line is NOT full, then JUMP to 0434H to print a character and check to see if the line needs to be advanced
*042A
CALL 01DCHCD DC 01
GOSUB to 01DCH to wait for either PRINTER READY or BREAK key
*042D
LD A,0DH3E 0D
Load A with a carriage return.
*042F
OUT (F8H),AD3 F8
Send the carriage return to port 0F8H.
NOTE: 0F8H is the printer port. If you put data to it, it prints it. Otherwise, Bits 4-7 hold printer status.
*0431
CALL 3048HCD 48 30
GOSUB to 3048H which just JUMPs to 377AH to check to see if we are on a new printable page and set the pointers accordingly.
*0434
CALL 01DCHCD DC 01
GOSUB to 01DCH to wait for either PRINTER READY or BREAK key
*0437
LD A,C79
Put the character held in C back into A so it can be sent to the PRINTER
*0438
OUT (F8H),AD3 F8
Send the character to port F8H.
NOTE: F8H is the printer port. If you put data to it, it prints it. Otherwise, Bits 4-7 hold printer status.
*043A
INC (IX+05H)DD 34 05
Bump the number of characters printed.
NOTE: IX+5 is the number of characters printed.
*043D
CP 0DHFE 0D
Check A for a carriage return.
*043F
If A was a carriage return, skip the next few instructions and jump to 0445H to GOSUB to 3048H to JUMP to 377AH to check to see if we are on a new printable page and set the pointers accordingly.
*0441
CP 0AHFE 0A
Check to see if the character in register A is 0AH (ASCII: LINE FEED character).
*0443
IF A is not a LINE FEED then jump to 0448H to skip the next instruction.
*0445
CALL 3048HCD 48 30
GOSUB to 3048H which just JUMPs to 377AH to check to see if we are on a new printable page and set the pointers accordingly.
*0448
XOR AAF
Clear Register A and RESET all FLAGS
*0449
LD A,C79
Put the character held in Register C into Register A
*044A
RETC9
RETurn to CALLER

044B-0451 – Inside the PRINTER ROUTINE – Subroutine to check to see if PRINTER READY by polling port F8H

044B
IN A,(F8H)
Set A with the Printer Status Byte.

NOTE: F8H is the printer port. If Bit 7 is set, the printer is not busy. If Bit 6 is set the printer is not out of paper. If bit 5 is set, the device is selected. If Bit 4 is set, no printer fault.
044D
AND 0F0H
AND A against F0H (Binary: 11110000) to strip off BITS 3-0, leaving BITS 7-4 intact.
044F
CP 30H
Check the already masked A against 30H (Binary: 00110000) to see if the printer is ready.

NOTE: This translates to PRINTER NOT BUSY (Bit 7=0), PRINTER NOT OUT OF PAPER (Bit 6=0), PRINTER SELECTED (Bit 5=1), and NO PRINTER FAULT (Bit 4=1).
0451
RET
Return.

0452-0468 – Initialize KB, DI, PR, RI, RO and RN

0452
Initialize to Keyboard, Display Drive, and Printer …
0455
… by moving the 24 bytes starting at 36BFH …
0458
… to 4015H-402DH.
045B
LDIR
045D
Initialize RI, RO, and RN …
0460
… by moving the 24 bytes starting at 36F9H …
0463
… to 41E5H-41FDH.
0466
LDIR
0468
RET
RETURN.

*0469-046A – Model 4 Gen 1 – These instructions are never called or used.

*0469-046A
JUMP to 00DA to JUMP to display a ?SN ERROR.

*0469-046A – Model 4 Gen 2 – These instructions are never called or used.

*0469
NOP
*046A
NOP

046B-0472 – This subroutine zeroes out the PROTECTED SCREEN LINES (if any) and point HL to the start of data

046B
XOR A
Clear A and all Status Bits.
046C
LD (4214H),A
Set memory location 4214H to zero.
NOTE: 4214H is the number of protected video lines.
046F
LD HL,(40A4H)
Load HL with the memory contents of 40A4H.
NOTE: 40A4 is the DATA POINTER.
0472
RET
Return.

0473H-04B1H – Video Display DCB.

0473
DI
Disable Interrupts.
0474-0479
LD L,(IX+03H)
LD H,(IX+04H)
Load HL with the MSB and LSB of the current cursor position (Held in IX+3 and IX+4).
047A
LD A,(IX+05H)
Load A with the character at the current cursor position.

NOTE: IX+05H holds the character at the cursor position.
047D
OR A
Set flags. It will be Z if the cursor is off.
047E
Skip the next instruction (i.e., JUMP to 0481H) if the cursor is off.
0480
LD (HL),A
If we are here, the cursor is on so display the character held in A at the current cursor position held in HL.
0481
LD A,C
Load A with C (which should be the character to display).
0482
CP 20H
Check to see if the character is a control character by comparing A to 20H. Results:
  • If A=20H it sets the ZERO FLAG.
  • If A<20H then the CARRY FLAG will be set
  • If A>=20H then the NO CARRY FLAG will be set.
If A is a CONTROL CHARACTER then the CARRY FLAG will be set.
0484
If the CARRY FLAG is set (i.e., we have a control character), JUMP to 0521H.
0487
CP C0H
Check to see if the character is a control character by comparing A to 20H. Results:
  • If A=C0H it sets the ZERO FLAG.
  • If A<C0H then the CARRY FLAG will be set
  • If A>=C0H then the NO CARRY FLAG will be set.
If A is a TAB or SPECIAL CHARACTER then NC will be set.
0489
If the CARRY FLAG is NOT set (i.e., we have a TAB or SPECIAL CHARACTER), JUMP to 04B7H.

048B – Inside the CURSOR MANAGEMENT ROUTINE – If we are here, the character is not a control character, tab, or special characters.

048B
GOSUB to 0576H to display the character on the screen.
048E
LD A,H
Now we need to make sure the cursor is still on the screen. First Load A with H (which is the MSB of the screen location).
048F
AND 03H
Mask A against 03H (0000 0011), so that only the last 2 bits are live (so it can be only 0, 1, 2 or 3).
0491
OR 3CH
OR it against 3CH (0011 1100), so that it is 0011 11xx where xx are those 2 bits (so it can be only 60, 61, 62, or 63).
0493
LD H,A
Load H with the masked A.
0494
LD D,(HL)
Get the character at the cursor position (held in the memory location pointed to by HL) and put it in D.
0495
LD A,(IX+05H)
Load A with IX+5 to see if the cursor is on.

NOTE: IX+05H holds the character at the cursor position.
0498
OR A
Set flags for A.
0499
If the cursor is NOT on (A is Zero), then jump to 04A8H.
049B
LD (IX+05H),D
The cursor is on so put the character which is supposed to be there, there.

NOTE: IX+05H holds the character at the cursor position.
049E
LD A,(IX+06H)
Load A with the cursor character.

NOTE: IX+6 holds the cursor character.
04A1
CP 20H
Check to see if the character is a control character by testing A – 20H. If A=20H it sets the ZERO FLAG. If A<20H then the CARRY FLAG will be set and if A>=20H then the NO CARRY FLAG will be set. If A is a CONTROL CHARACTER then C will be set.
04A3
If it is not a control character, us it by jumping to 04A7H.
04A5
LD A,0B0H
If it is a control character, then load A with the default cursor of B0H.

NOTE: B0H is a two pixel wide graphic character located below the letter line.
04A7
LD (HL),A
Display the character held in A into the memory location pointed to be HL. This should display the cursor.
04A8
LD (IX+03H),L
Save the cursor position by loading IX+3 with L and …
04AB
LD (IX+04H),H
… by loading IX+4 with H.
04AE
XOR A
Zero A and clear all status flags.
04AF
LD A,C
Load A with the character.
04B0
EI
Enable Interrupts.
04B1
RET
RETURN.

04B2 – Cursor Management – Move to the start of the line.

04B2
LD A,L
Load register A with the LSB of the current position in register L.
04B3-04A3
AND C0H
Point to the beginning of the line by ANDing it against 1100 0000 to keep only Bits 6 and 7 (so it will be XX00H, XX40H, XX80H, or XXC0H).
04B5
LD L,A
Load register L with the updated value in register A.
04B6
RET
Return with the new video buffer address stored in HL.

04B7 – Cursor Management – We have EITHER a TAB or SPECIAL CHARACTER, so figure it out, and proceed accordingly.

04B7
LD A,(IX+07H)
Load A with IX+7 to check for TABS or SPECIAL CHARACTERS.
04BA
OR A
Set the Flags for A.
04BB
LD A,C
Put the current character into A.
04BC
If A is Not Zero, jump to 048BH to display the special character set.
04BE
SUB C0H
Subtract C0H (Binary: 1100 0000) to compute a TAB.
04C0
If TAB(0) then jump to 048EH.
04C2
LD B,A
Load B with the number of spaces needed.
04C3
LD A,20H
Load A with a SPACE.
04C5
GOSUB to 0576H to display the character on screen.
04C8
Loop back 2 Instructions until B is exhausted.
04CA
JUMP to 048EH.

04CC – Cursor Management – CURSOR ON.

04CC
LD A,(HL)
Store the character at the cursor into A.
04CD
LD (IX+05H),A
Put the character held in A at the cursor position.

NOTE: IX+05H holds the character at the cursor position.
04D0
RET
RETURN.

04D1 – Cursor Management – CURSOR OFF (Jumped to from 0539H)

04D1
XOR A
Zero A and all Flags.
04D2
JUMP to 04CDH to put the character held in A at the cursor position.

04D4 – Cursor Management – HOME CURSOR

04D4
Getting ready to HOME the cursor, so load HL with 3C00H.

NOTE: 3C00H is the start of the video display RAM.
04D7
LD A,(4210H)
Load A with the memory contents of 4210H.

NOTE: 4210H holds the bit mask for port ECH. Port ECH stores miscellaneous controls. In this case, we are looking for the bit which holds whether we are in LARGE characters or SMALL characters.
04DA
AND FBH
Mask A with FBH (Binary: 1111 1011) to turn off Bit 2.
04DC
GOSUB to 0570H Put A into memory location 4210H (4210H holds the bit mask for port ECH) and then output A to Port ECH.
04DF
LD A,(4214H)
Load A with the memory contents of 4214H.

NOTE: 4214H is the number of protected video lines.
04E2
AND 07H
AND A with 07H (Binary: 0000 0111) to keep only Bits 0, 1, and 2. This means that the only possibilities for A are 0-7.
04E4
RET Z
If A is ZERO (no lines to protect) then RETURN.
04E5
Since A is not ZERO, we have to protect some lines. First, GOSUB to 0504H to move the cursor down.
04E8
DEC A
Decrement A.
04E9
Loop back to 04E4H to either RETURN if we are at zero, or move down another line and try again.

04EB – Cursor Management – BACKSPACE

04EB
DEC HL
Decrement HL to back up the cursor.
04EC
LD A,(4210H)
Load A with the memory contents of 4210H.

NOTE: 4210H holds the bit mask for port ECH. Port ECH stores miscellaneous controls. In this case, we are looking for the bit which holds whether we are in LARGE characters or SMALL characters.
04EF
AND 04H
Mask A with 04H (0000 0100) to leave only bit 3 live, allowing Z to be set if Bit 3 is high, and NZ to be set if Bit 3 is low.
04F1
If it is Z is set, then we have small characters, so jump to skip the next instruction.
04F3
DEC HL
Decrement HL to back up the cursor another space.
04F4
LD (HL),20H
Put a space in the current cursor position.
04F6
RET
RETURN.

04F7 – Cursor Management – CURSOR BACK

04F7
LD A,(4210H)
Load A with the memory contents of 4210H.

NOTE: 4210H holds the bit mask for port ECH. Port ECH stores miscellaneous controls. In this case, we are looking for the bit which holds whether we are in LARGE characters or SMALL characters.
04FA
AND 04H
Mask A with 04H (0000 0100) to leave only bit 3 live, allowing Z to be set if Bit 3 is high, and NZ to be set if Bit 3 is low.
04FC
If A is not zero (which means A is 4), then GOSUB to the next instruction, which is a clever way to run that routine twice since we are in LARGE type.
04FF
LD A,L
Put the contents of L into A.
0500
AND 3FH
Mask A with 3F (0011 1111) to strip off Bits 6 and 7. A can now be no higher than 3F (Decimal: 63).
0502
DEC HL
Decrement HL to back up the cursor.
0503
RET NZ
RETURN if we are not at the start of the screen.

0504 – Cursor Management – CURSOR DOWN

0504
(If we are at the start of the screen) we need to move down one line, so load DE with 40H (64).
0507
ADD HL,DE
Add DE (64 characters) to HL (current cursor position).
0508
RET
RETURN.

0509 – Cursor Management – CURSOR FORWARD.

0509
INC HL
HL should be holding the current cursor position. Bump HL one forward.
050A
LD A,L
Load A with L to check the position in the line.
050B
AND 3FH
Mask A with 3F (0011 1111) to keep only Bits 0-5, so that it will be no higher than 3F/63.
050D
RET NZ
If A is not zero, then we are not at the end of the line, so RETURN.

050E – Cursor Management – CURSOR UP

050E
If we are here, then we are at the end of the line, so we need to move up one line. Start by putting FFC0H into DE.

NOTE: FFC0H is -64, or 1 line length.
0511
ADD HL,DE
Subtract 64 (the length a line on screen) from HL to move it to the previous line.
0512
RET
RETURN.

0513-0520 – Cursor Management – Turn on DOUBLE SIZE and put the cursor on EVEN columns only.

0513
LD A,(4210H)
Load A with the memory contents of 4210H.

NOTE: 4210H holds the bit mask for port ECH. Port ECH stores miscellaneous controls. In this case, we are looking for the bit which holds whether we are in LARGE characters or SMALL characters.
0516
OR 04H
OR A against 04 (0000 0100) to turn on the 3rd bit. This will turn on DOUBLE SIZE characters.
0518
GOSUB to 0570H to put A into memory location 4210H (4210H holds the bit mask for port ECH) and then output A to Port ECH.
051B
INC HL
Bump HL to move the cursor + 1.
051C
LD A,L
Load A with the LSB of the cursor position.
051D
AND FEH
Mask A (the LSB of the cursor position) with FE (1111 1110) which turns off BIT 0. This is to set to an even position.
051F
LD L,A
Put the newly “evened” A into L. This will then make HL only be on every other column.
0520
RET
RETURN.

0521-055F – Cursor Management – Process Special Characters

0521
Put 048EH into DE. This will eventually act as the RETURN location and is the routine that makes sure the cursor is still on the screen.
0524
PUSH DE
Put that RETurn address into the STACK.
0525
CP 08H
Compare A with 08H.

NOTE: 08H is a BACKSPACE.
0527
If A is BACKSPACE, jump to 04EBH to deal with it.
0529
CP 0AH
Compare A with 0AH.

NOTE: 0AH is a LINE FEED.
052B
If A is LINE FEED, jump to 05AFH to deal with it.
052E
CP 0DH
Compare A with 0DH.

NOTE: 0DH is a CARRIAGE RETURN.
0530
If A is CARRIAGE RETURN, jump to 05AFH to deal with it.
0533
CP 0EH
Compare A with 0EH.

NOTE: 0EH is a CURSOR ON.
0535
If A is CURSOR ON, jump to 04CCH to deal with it.
0537
CP 0FH
Compare A with 0FH.

NOTE: 0FH is a CURSOR OFF.
0539
If A is CURSOR OFF, jump to 04D1H to deal with it.
053B
SUB 15H
Subtract 15H (Decimal: 21) from A to bring it down into the control character range.
053D
If A is 0, jump to 0560H to deal with it.
053F
DEC A
Decrement A by 1. This would test for special and alternative characters.
0540
If A is 0, jump to 056BH to deal with it.
0542
DEC A
Decrement A by 1. This would test for DOUBLE SIZE.
0543
If A is DOUBLE SIZE, jump to 0513H to deal with it.
0545
DEC A
Decrement A by 1. This would test for CURSOR BACK.
0546
If A is CURSOR BACK, jump to 04F7H to deal with it.
0548
DEC A
Decrement A by 1. This would test for CURSOR FORWARD.
0549
If A is CURSOR FORWARD, jump to 0509H to deal with it.
054B
DEC A
Decrement A by 1. This would test for CURSOR DOWN.
054C
If A is CURSOR DOWN, jump to 0504H to deal with it.
054E
DEC A
Decrement A by 1. This would test for CURSOR UP.
054F
If A is CURSOR UP, jump to 050EH to deal with it.
0551
DEC A
Decrement A by 1. This would test for HOME CURSOR.
0552
If A is HOME CURSOR, jump to 04D4H to deal with it.
0555
DEC A
Decrement A by 1. This would test for RESTART LINE.
0556
If A is RESTART LINE, jump to 04B2H to deal with it.
0559
DEC A
Decrement A by 1. This would test for CLEAR TO END OF LINE.
055A
If A is CLEAR TO END OF LINE, jump to 05BCH to deal with it.
055C
DEC A
Decrement A by 1. This would test for CLEAR TO END OF SCREEN.
055D
If A is CLEAR TO END OF SCREEN, jump to 05C5H to deal with it.
055F
RET
RETURN (to 048EH to makes sure the cursor is still on the screen).

0560 – Cursor Management – Control Characters.

0560
LD A,(IX+07H)
Load A with the contents of IX+07H, which toggles TAB and ALTERNATIVE.
0563
AND 01H
MASK A with 0000 0001, to keep only the character flag bit.
0565
XOR 01H
XOR A with 0000 0001 to toggle the character flag bit.
0567
LD (IX+07H),A
Put the MASKED and XORed value back into IX+07H, which toggles TAB and ALTERNATIVE.
056A
RET
RETURN.

056B – Cursor Management – Special and Alternative Characters

056B
LD A,(4210H)
Put the contents of memory location 4210H into A.

NOTE: 4210H holds the bit mask for port ECH. Port ECH stores miscellaneous controls.
056E
XOR 08H
XOR A with 08H (0000 1000). This will toggle bit 3 to deal with special/alternative characters.

NOTE: Bit 3 of ECH is the SPECIAL CHARACTER SELECT. It will be 0 for KANA and 1 for MISC.
0570
LD (4210H),A
Put the toggled A back into memory location 4210H.

NOTE: 4210H holds the bit mask for port ECH. Port ECH stores miscellaneous controls.
0573
OUT (ECH),A
Output A to Port ECH.
0575
RET
RETURN.

0576 – This routine displays a character, moves forward either 1 or 2 spaces depending on if we are double size or not, and advances the screen if that character pushed the cursor beyond the end of the screen.

0576
LD (HL),A
Display the character on screen.

NOTE: HL should be the current screen location and A should be the character.
0577
INC HL
Bump HL to advance the cursor.
0578
LD A,(4210H)
Put the contents of memory location 4210H into A.

NOTE: 4210H holds the bit mask for port ECH. Port ECH stores miscellaneous controls.
057B
AND 04H
Mask A with 04H (0000 0100), so the only possibilties are 4 (0000 0100) or 0 (0000 0000).
057D
If it is zero, then we are SMALL SIZE, and JUMP to 0580H.
057F
INC HL
If we are here, then we are DOUBLE SIZE, so need to bump HL again to advance the cursor (even columns only).
0580
LD A,H
We need to test to see if we just fell off the screen, so load A with the MSB of the cursor location.
0581
CP 40H
Compare the MSB of the cursor location held in A against 40H (Binary: 0100 0000, Decimal: 64).
0583
RET NZ
If it is not zero then we did not fall off the screen, then RETURN.
0584
If we are here then we fell off the screen so first GOSUB to 050EH to move up a line.
0587
PUSH HL
Save the cursor location held in HL to the STACK.

0588 – Cursor Management – Scroll the Screen

0588
LD A,(4214H)
Load A with the memory contents of 4214H.

NOTE: 4214H is the number of protected video lines.
058B
AND 07H
AND A with 07H (0000 0111) to turn off all bits except for Bits 0, 1, and 2. This means that the only possibilities for A are 0-7.
058D
Load HL with the start of the screen.
0590
Load DE with the size of the screen (1024 characters).
0593
PUSH BC
Save the value in Register Pair BC to the STACK.
0594
Load BC with the number of characters per line (64 characters).
0597
INC A
Increase A which is holding the number of lines to protect.
0598
ADD HL,BC
Add BC (the number of characers per line) to HL (the current cursor position), which then moves us down one line.
0599
EX DE,HL
Swap DE and HL which will then reduce the screen size by one line.
059A
OR A
Set the flags for A.
059B
SBC HL,BC
Subtract, with carry, BC from HL.
059D
EX DE,HL
Swap DE and HL.
059E
DEC A
Reduce A by one, so that we have one less line to protect.
059F
Loop back to 0598H until we have finished this for all protectable lines.
05A1
PUSH DE
Save DE to the STACK.
05A2
PUSH HL
Save HL to the STACK.
05A3
OR A
Set the flags for A, as we prepare to move the start back up.
05A4
SBC HL,BC
Subtract, with carry, BC from HL to move up one line.
05A6
EX DE,HL
Swap DE and HL so that the source is now the start of screen plus one line.
05A7
POP HL
Restore HL from the STACK. HL will be the START OF SCREEN.
05A8
POP BC
Restore BC from the STACK. BC will be the COUNT = SCREEN SIZE – ONE LINE.
05A9
LDIR
Scroll the unprotected portions of the screen.
05AB
POP BC
Restore BC from the STACK (it was pushed in 0593H).
05AC
EX DE,HL
Swap DE and HL, so now HL = CURSOR POSITION.
05AD
JUMP to 05C6H to clear to the end of screen without changing HL.

05AF – Cursor Management – CARRIAGE RETURN or LINE FEED

05AF
GOSUB to 04B2H to move to the start of the line.
05B2
PUSH HL
Save HL (the cursor position) to the STACK.
05B3
GOSUB to 0504H to move the cursor down one line.
05B6
LD A,H
We need to test to see if we just fell off the screen, so load A with the MSB of the cursor location.
05B7
CP 40H
Compare the MSB of the cursor location held in A against 40H (64).
05B9
If we fell off the screen the JUMP to 0588H to scroll the screen.
05BB
POP DE
Otherwise restore DE from the STACK to get the old cursor position.

05BC – Cursor Management – CLEAR TO END OF LINE

05BC
PUSH HL
Save HL (contaning the NEW CURSOR POSITION) to the STACK.
05BD
LD D,H
DE currently holds the END OF LINE. Put the MSB into H.
05BE
LD A,L
Put the LSB into A.
05BF
OR 3FH
MASK the LSB of the END OF THE LINE with 3F (63).
05C1
LD E,A
Load E with the masked value of the END OF THE LINE.
05C2
INC DE
Bump DE by one so it now points to the start of the next line.
05C3
JUMP to 05C9H to clear to the end of the line.

05C5 – Cursor Management – CLEAR TO END OF SCREEN

05C5
PUSH HL
Save HL (containing the CURSOR POSITION) to the STACK.
05C6
Set DE to 4000H which is 1 character off the screen.
05C9
LD (HL),20H
Put a BLANK into the current cursor position.
05CB
INC HL
Bump the current cursor position by one.
05CC
RST 18H
We need to check to see if the integer value in HL is greater than or equal to DE (which is 1 character off the screen) 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).
05CD
If that RST 18H call is not zero, then we are not off the screen, so loop back to 05C9H until we are done.
05CF
POP HL
We have cleared the screen so now restore the cursor position back to HL from the STACK.
05D0
RETC9
RETurn to CALLer

*05D1-05D8 – Model 4 Gen 1 Message Storage Area

*05D1-05D3
“RON”52 4F 4E
*05D4
AND F0HE6 F0
I don’t think this is used
*05D6
CP 30HFE 30
I don’t think this is used

*05D1-05D8 – Model 4 Gen 2 Message Storage Area

*05D1-05D8
0EH + “Cass ? + 03H”

05D9H-0673H – Part of the Keyboard Routine – “KEYIN”
Keyboard Line Handler Routine

This is the most basic of the string input routines and is used by the two others (1BB3H and 0361H) as a subroutine. To use it, load HL with the required buffer address and the B Register with the maximum buffer length required. Keyboard input over the specified maximum buffer length is ignored, and after pressing the (ENTER) key it will return with HL containing the original buffer address and B with the string length.

A call to this memory location Accepts keyboard input and stores each character in a buffer supplied by caller. Input continues until either a carriage return or a BREAK is typed, or until the buffer is full. All edit control codes are recognized, e.g. TAB, BACKSPACE, etc.

On exit the registers contain: HL=Buffer address, B=Number of characters transmitted excluding last, C=Orginal buffer size, A=Last character received if a carriage return or BREAK is typed. Carry Set if break key was terminator, reset otherwise. If the buffer is full, the A Register will contain the buffer size.

Accepts keyboard input and stores each character in a buffer supplied by caller. Input continues until either a carriage return or a BREAK is typed, or until the buffer is full. All edit control codes are recognized, e.g. TAB, BACKSPACE, etc

To use a ROM call to accept a restricted number of keyboard characters for input (n), use:
LD HL,(40A7H)
LD B,n
CALL 05D9H
.

Up to n characters will be accepted, after which the keyboard will simply be ignored until the ENTER (or LEFT ARROW, or BREAK, or CLEAR) key is pressed. These characters will be stored in consecutive memory cells starting at the address contained in 40A7H-40A8H (the keyboard buffer area), with a 0DH (carriage return) byte at the end. Upon completion, the HL Register Pair will contain the address of the first character of the stored input, and the B Register will contain the number of characters entered. NOTE: No “?” is displayed as a result of the execution of the above program. If the “?” display is desired to prompt the typing of the input, precede the above program segment with:
LD A,3FH
CALL 033AH
LD A,20H
CALL 033AH


According to the original ROM comments, on entry, HL to point to the input line address in RAM and Register B to hold the maximum number of input characters to fetch. On exit, Register A should hold the number of characters entered
05D9
 ↳ KEYIN
PUSH HLE5
Save the start of the input buffer area pointer in Register Pair HL on the STACK
05DA-05DB
LD A,0EH3E 0E
Load Register A with a turn on the cursor character (which is 14)
05DC-05DE
CALL 0033HCALL $DSPCD 33 00
Display a cursor by calling the DISPLAY A CHARACTER routine at 0033H (which puts the character in Register A on the video screen)
05DF
LD C,B48
Load Register C with the size of the input buffer in Register B
05E0-05E2
 ↳ KLNNXT
CALL 0049HCALL $KEYCD 49 00
Call the “WAIT FOR KEYBOARD INPUT” routine at 0049H, so as to wait until a key is pressed
05E3-05E4
CP 20HCP ” “FE 20
Check to see if the key that was pressed in Register A is greater than a SPACE
05E5-05E6
JR NC,060CHJR NC,KLNCHR30 25
Jump if the key that was pressed in Register A is displayable (i.e., greater than or equal to a SPACE)
05E7-05E8
CP 0DHFE 0D
Check to see if the key that was pressed in Register A is a CARRIAGE RETURN
05E9-05EB
JP Z,0662HJP Z,KLNCRCA 62 06
Jump if the key that was pressed in Register A is a CARRIAGE RETURN
05EC-05ED
CP 1FHFE 1F
Check to see if the key that was pressed in Register A is the CLEAR key
05EE-05EF
JR Z,0619HJR Z,KLNCLR28 29
Jump if the key that was pressed in Register A is the CLEAR key
05F0-05F1
CP 01HFE 01
Check to see if the key that was pressed in Register A is the BREAK key
05F2-05F3
JR Z,0661HJR Z,KLNBRK28 6D
Jump if the key that was pressed in Register A is the BREAK key
05F4-05F6
LD DE,05E0HLD DE,KLNNXT11 E0 05
Load Register Pair DE with the return address of 05E0H
05F7
PUSH DED5
Save the return address in Register Pair DE on the STACK
05F8-05F9
CP 08HFE 08
Check to see if the key that was pressed in Register A is a backspace (which is 08) the cursor and erase character
05FA-05FB
JR Z,0630HJR Z,KLNBSP28 34
Jump if the key was pressed in Register A is a backspace the cursor and erase character
05FC-05FD
CP 18HFE 18
Check to see if the key that was pressed in Register A is a backspace character
05FE-05FF
JR Z,062BHJR Z,KLNCAN28 2B
Jump if the key that was pressed in Register A is a backspace character
0600-0601
CP 09HFE 09
Check to see if the key that was pressed in Register A is a tab character
0602-0603
JR Z,0646HJR Z,KLNHT28 42
Jump if the key that was pressed in Register A is a tab character
0604-0605
CP 19HFE 19
Check to see if the key that was pressed in Register A is a turn on the 32 character per line mode character
0606-0607
JR Z,0641HJR Z,KLNETB28 39
Jump if the key that was pressed in Register A is a turn on the 32 character per line mode character
0608-0609
CP 0AHFE 0A
Check to see if the key that was pressed in Register A is a line feed character of CHR$(10)
060A
RET NZC0
Return (to 05E0H) if the key that was pressed in Register A isn’t a line feed character
060B
POP DED1
Get the return address from the STACK and put it in Register Pair DE (so that it isn’t 05E0H anymore)
060C
 ↳ KLNCHR
LD (HL),A77
We now know that the key pressed is a printable character so save the key that was pressed in Register A at the location of the input buffer pointer in Register Pair HL
060D
LD A,B78
Load Register A with the length of the buffer remaining in Register B
060E
OR AB7
Check to see if there is any more of the input buffer remaining (and set status)
060F-0610
JR Z,05E0HJR Z,KLNNXT28 CF
Jump to 05E0H if the end of the input buffer has been reached
0611
LD A,(HL)7E
Now we know the end of the input buffer has not been reached, so load Register A with the value at the location of the input buffer pointer in Register Pair HL
0612
INC HL23
Increment the input buffer pointer in Register Pair HL
0613-0615
CALL 0033HCALL $DSPCD 33 00
Display the character by calling the DISPLAY A CHARACTER routine at 0033H (which puts the character in Register A on the video screen)
0616
DEC B05
Decrement the number of bytes remaining in the input buffer area in Register B
0617-0618
JR 05E0HJR KLNNXT18 C7
Jump to 05E0H to get the next character

0619H – Part of the Display routine – “KLNCLR”
Clear the screen

0619H-061B
 ↳ KLNCLR
CALL 01C9HCALL CLSCD C9 01
Call the CLEAR SCREEN routine at 01C9H (which clears the screen, changes to 64 characters, and homes the screen)
061C
LD B,C41
Load Register B with the length of the input buffer in Register C (which resets the counter of characters transmitted)
061D
POP HLE1
Get the starting address for the input buffer area from the STACK and put it in Register Pair HL (which resets the buffer address)
061E
PUSH HLE5
Save the starting address for the input buffer area in Register Pair HL on the STACK
061F
JUMP to 05E0H (to get the next character, which is now the first character in the buffer).

0622H – Part of the Display routine – “KLNCNL”

Cancel the accumulated line
0622-0624
 ↳ KLNCNL
CALL 0630HCALL KLNBSPCD 30 06
Gosub to wait for the next key and back up the input buffer pointer in Register Pair HL if necessary
0625
DEC HL2B
Backup to the previous character (the one before the CARRIAGE RETURN) by decrementing the input buffer pointer in Register Pair HL
0626
LD A,(HL)7E
Load Register A with the character at the location of the input buffer pointer in Register Pair HL
0627
INC HL23
Increment the input buffer pointer in Register Pair HL to the net availabile position
0628-0629
CP 0AHFE 0A
Check to see if the character in Register A is the line feed character of CHR$(10)
062A
RET ZC8
Return if the character in Register A is a line feed character
062B
 ↳ KLNCAN
LD A,B78
Now we know that character wasn’t a line feed, so we need to test for a buffer full. This loads Register A with the number of bytes remaining in the input buffer area in Register B
062C
CP CB9
Check to see if the number of characters remaining in the input buffer area in Register A is the same as the length of the input buffer area in Register C
062D-062E
JR NZ,0622HJR NZ,KLNCNL20 F3
Jump to 0622H if there is room for more characters
062F
RETC9
The buffer is full! Return

0630H – Part of the Display routine – “KLNBSP”

Backspace one character. On entry Register B to hold the number of characters received, and Register C to hold the size of the buffer
0630
 ↳ KLNBSP
LD A,B78
Load Register A with the number of bytes remaining in the input buffer area in Register B
0631
CP CB9
Compare the number of bytes remaining in the input buffer (held in Register A) against the size of the buffer (held in Register C) to see if the buffer is full
0632
RET ZC8
Return if the input buffer area is full
0633
DEC HL2B
Decrement the input buffer area pointer in Register Pair HL to backspace the previous character .
0634
LD A,(HL)7E
… and then get that character into Register A
0635-0636
CP 0AHFE 0A
Check to see if the character in Register A is the line feed character of CHR$(10)
0637
INC HL23
Increment the input buffer area pointer in Register Pair HL
0638
RET ZC8
Return if the character in Register A is a line feed character
0639
DEC HL2B
Decrement the input buffer area pointer in Register Pair HL to backspace the previous character in the buffer .
063A-063B
LD A,08H3E 08
Load Register A with a backspace of CHR$(08) and then .
063C-063E
CALL 0033HCALL $DSPCD 33 00
Effectuate the backspace by calling the DISPLAY A CHARACTER routine at 0033H (which puts the character in Register A on the video screen)
063F
INC B04
Increment the number of characters remaining in the input buffer area in Register B
0640
RETC9
RETurn to CALLer

0641H – Part of the Display routine – “KLNETB”

Turn on 32 Character Mode
0641-0642
 ↳ KLNETB
LD A,17HLD A,0001 01113E 17
Load Register A with mask of 00010111 so as to turn on the 32 character per line mode character
0643-0645
JP 0033HJP $DSPC3 33 00
Call the DISPLAY A CHARACTER routine at 0033H (which puts the character in Register A on the video screen). Since that is the 32 character per line mode, that’s what happens

0646H – Part of the Display routine – “KLNHT”

Process a horizontal tab
0646
GOSUB to 0348H to get the cursor line position and return with it in register A.
0649-064A
AND 07H<ADD 0000 0111span class=”opcode2″>E6 07
Turn off some bits so we can mask the cursor line position in Register A by ANDing it against 0000 0111
064B
CPL2F
Inverse the value in Register A
064C
INC A3C
Increment the value in Register A so that it is 1 <= A <= 8
064D-064E
ADD 08HC6 08
Clear the upper bits of the counter
064F
LD E,A5F
Load Register E with the number of spaces to be added in Register A
0650
 ↳ KLNHTL
LD A,B78
Load Register A with the number of bytes remaining in the input buffer area in Register B
0651
OR AB7
Check to see if the buffer is full
0652
RET ZC8
Return if the input buffer is full
0653-0654
LD A,20HLD A,” “3E 20
Load Register A with a space character
0655
LD (HL),A77
Save the space character in Register A at the location of the input buffer area pointer in Register Pair HL
0656
INC HL23
Increment the input buffer area pointer in Register Pair HL
0657
PUSH DED5
Save the value in Register Pair DE on the STACK
0658-065A
CALL 0033HCALL $DSPCD 33 00
Display the space by calling the DISPLAY A CHARACTER routine at 0033H (which puts the character in Register A on the video screen)
065B
POP DED1
Get the value from the STACK and put it in Register Pair DE
065C
DEC B05
Since you just displayed one of the spaces, decrement the number of bytes remaining in the input buffer area in Register B .
065D
DEC E1D
… and decrement the number of spaces to be added in Register E
065E
RET ZC8
Return if the number of spaces has been added to the input buffer
065F
Loop back to 0650H until all the spaces have been added to the input buffer.

0661H – Part of the Display routine – “KLNBRK”

Process a Carriage Return and Automatic Line Feed
0661
 ↳ KLNBRK
SCF37
Set the Carry flag. This is done because the routine is going to exit with the CARRY flag set as an indication that BREAK was hit
0662
 ↳ KLNCR
PUSH AFF5
Save the value in Register Pair AF on the STACK, which saves the CARRY flag
0663-0664
LD A,0DH3E 0D
Load Register A with a carriage return character
0665
LD (HL),A77
Save the carriage return character in Register A at the location of the input buffer area pointer in Register Pair HL
0666-0668
CALL 0033HCALL $DSPCD 33 00
Display the carriage return by calling the DISPLAY A CHARACTER routine at 0033H (which puts the character in Register A on the video screen). Since that is a CARRIAGE RETURN, that’s what happens
0669-066A
LD A,0FH3E 0F
Load Register A with a turn off the cursor character
066B-066D
CALL 0033HCALL $DSPCD 33 00
Turn off the cursor by calling the DISPLAY A CHARACTER routine at 0033H (which puts the character in Register A on the video screen)
066E
LD A,C79
Load Register A with the length of the input (=buffer size) in Register C
066F
SUB B90
Subtract the number of bytes remaining in the input buffer area in Register B from the length of the input buffer area in Register A
0670
LD B,A47
Load Register B with the number of characters in the input buffer area in Register A
0671
POP AFF1
Get the value from the STACK and put it in Register Pair AF. This also sets the CARRY flag if BREAK and unsets it if CARRIAGE RETURN
0672
POP HLE1
Get the starting address of the input buffer area from the STACK and put it in Register Pair HL
0673
RETC9
RETurn to CALLer

0674 – KEYBOARD DRIVER ENTRY ROUTINE

0674
PUSH HL
Save register pair HL to the STACK.
0675
PUSH IX
Save Special Index Register IX to the STACK.
0677
PUSH DE
Save register pair DE (= the starting address of the device control block) to the STACK.
0678
POP IX
Get the starting address of the device control block from the STACK and put it in Special Index Register IX.
067A
PUSH DE
Save register pair DE (= the starting address of the device control block) to the STACK.
067B
Load register pair HL with a return address of 0694H (to restore all registers and RETurn).
067E
PUSH HL
Save the return address in register pair HL on the STACK.
067F
LD C,A
Save the character to output (current held in register A) to register C.
0680
LD A,(DE)
Load register A with the device type code at the location of the device control block pointer in register pair DE.
0681
BIT 7,A
Test Bit 7 of A, which is the bit for a DISK FILE.
0683
If not a disk file, then skip the next 3 instructions and JUMP to 068AH.
0685
AND B
Isolate the device code bits in A by AND’ing with the device codes in B.
0686
CP B
Check to see if the updated device type code in register A is the same as the driver entry code in register B.
0687
JUMP to the DOS exit link at 4033H if the updated device type code in register A isn’t the same as the driver entry code in register B.
068A
AND B
Masking A against B also sets Z for WRITE.
068B
CP 02H
At this point we know that the updated device type code in A is the same as the driver code entry, so let’s move on. First, reset the flags.
068D
LD L,(IX+01H)
Load register L with the LSB of the driver entry address at the location of the device control block pointer in Special Index Register IX plus one.
0690
LD H,(IX+02H)
Load register H with the MSB of the driver entry address at the location of the device control block pointer in Special Index Register IX plus one.
0693
JP (HL)
JUMP to the driver entry address in register pair HL.
0694
POP DE
Get the value from the STACK and put it in register pair DE.
0695
POP IX
Get the value from the STACK and put it in Special Index Register IX.
0697
POP HL
Get the value from the STACK and put it in register pair HL.
0698
POP BC
Get the value from the STACK and put it in register pair BC.
0699
RET
Return.

069AH – This subroutine CLEARS the DATA FLAG, sets up a buffer of 255 bytes (held in D) and JUMPS to 2B8DH.

069A
XOR A
Clear A and all status flags.
069B
LD (409FH),A
Load the DATA FLAG in 409FH with 0 (since A was just XOR’d against itself).
069E
LD D,FFH
Load D with 255, which will represent a buffer of 255 bytes.
06A0
JUMP to 2B8DH which is in the middle of the TOKENize routine. This address loads A with the current character at the BASIC line pointer, tests for end of line, puts it into the memory location pointed to by BC, and exits.
06A3
AND FDH
Mask A with FDH (1111 1101) to turn off Bit 1.
06A5
LD (409FH),A
Put A into the DATA FLAG held in 409FH. Note: Bit 0 HIGH means inside a quote. Bit 1 HIGH means inside a DATA. Bit 2 HIGH means inside a REM.
06A8
LD A,3AH
Load A with 3AH (which is a :).
06AA
OR A
Set the flags, to start a check for a reserved word.
06AB
JUMP to 06E2H (to exit this routine back to 2B89H) if it is not a reserved word.
06AE
LD A,(409FH)
Load A with the DATA FLAG in 409FH. This is to see if we are currently in a quote string.
06B1
RRA
Rotate A right one bit, with the bit that falls off (BIT 0) being moved to the CARRY FLAG, and the CARRY FLAG is moved to BIT 7.
06B2
If CARRY is set then we are in quoted string so JUMP to 06E2H which then JUMPs to 2B89H which is in the middle of the TOKENize routing. This address bumps BC (the input buffer pointer), reduces D (the buffer counter), moves the BASIC line pointer forward, and continues.
06B4
RRA
Rotate A right one bit, with the bit that falls off (BIT 0) being moved to the CARRY FLAG, and the CARRY FLAG is moved to BIT 7.
06B5
RRA
Rotate A right one bit, with the bit that falls off (BIT 0) being moved to the CARRY FLAG, and the CARRY FLAG is moved to BIT 7. This tests for a REM.
06B6
If C is set, we are in a REM, so JUMP to 06F6H if we are NOT in a REM.
06B8
LD A,(HL)
At this point, we assume this is a TOKEN. So load A with the contents of HL to get the token.
06B9
CP FBH
Check A against FBH (Binary: 1111 1011) to see if it is a REM TOKEN.
06BB
PUSH HL
Save HL (Position in Text) to the STACK.
06BC
PUSH BC
Save BC (Position in Buffer) to the STACK.
06BD
Set HL to 06DFH, which will act as a RETURN.
06C0
PUSH HL
Save HL (the return) to the STACK.
06C1
RET NZ
RETURN if this is NOT a REM TOKEN.

The next set of instructions tests the buffer backwards for M, E, and R, and RETURNS out if those are not found.

06C2
DEC BC
Decrement the Buffer to back up one character.
06C3
LD A,(BC)
Put the character in the buffer into A.
06C4
CP 4DH
Test A for a 4DH (ASCII: M).
06C6
RET NZ
If it is not a M then RETURN.
06C7
DEC BC
Decrement the Buffer to back up one character.
06C8
LD A,(BC)
Put the character in the buffer into A.
06C9
CP 45H
Test A for a E.
06CB
RET NZ
If it is not a E then RETURN.
06CC
DEC BC
Decrement the Buffer to back up one character.
06CD
LD A,(BC)
Put the character in the buffer into A.
06CE
CP 52H
Test A for a R.
06D0
RET NZ
If it is not a R then RETURN.

At this point BC, BC+1, and BC+2 were REM, so check backwards again for a : and if not, RETURN.

06D1
DEC BC
Decrement the Buffer to back up one character.
06D2
LD A,(BC)
Put the character in the buffer into A.
06D3
CP 3AH
Test A for a :.
06D5
RET NZ
If it is not a : then RETURN.

At this point BC, BC+1, BC+2, and BC+3 were :REM.

06D6
POP AF
Restore AF from the STACK (to clear the STACK).
06D7
POP AF
Restore AF from the STACK (to clear the STACK).
06D8
POP HL
Restore HL from the STACK (to get the position).
06D9
INC D
INC D
INC D
INC D
We need to decrease the buffer size by 4.
06DD
JUMP to 0704H to load the next character held in (HL) into A and JUMP to 2BA0H to see if the current token is ELSE and then keep processing.
06DF
POP BC
Restore BC (the buffer position) from the STACK.
06E0
POP HL
Restore HL (the text position) from the STACK.
06E1
LD A,(HL)
Put the character at the current text position into A.
06E2
JUMP to 2B89H which is in the middle of the TOKENize routing. This address bumps BC (the input buffer pointer), reduces D (the buffer counter), moves the BASIC line pointer forward, and continues.

06E5H – This subroutine sets the DATA FLAG to “BIT 1 HIGH” to indicate that we are in a DATA command.

06E5
LD A,(409FH)
Load A with the DATA FLAG in 409FH.
06E8
OR 02H
OR A against 02H (0000 0010) to set BIT 1, the DATA bit.
06EA
LD (409FH),A
Put the revised A into the DATA FLAG.
06ED
XOR A
Clear A and all flags.
06EE
RET
RETURN.

06EFH – This subroutine sets the DATA FLAG to “BIT 2 HIGH” to indicate that we are in a REM command.

06EF
LD A,(409FH)
Load A with the DATA FLAG in 409FH.
06F2
OR 04H
OR A against 04H (Binary: 0000 0100) to turn on Bit 2, the REM bit.
06F4
RETURN.
06F6
RLA
Rotate A left one bit, with the bit that falls off (BIT 7) being moved to the CARRY FLAG, and the CARRY FLAG is moved to BIT 0. If this results in the CARRY FLAG being set, then we are in a DATA statement.
06F7
If A had Bit 7 high (which was rotated into CARRY for thsi test), then we are in a DATA statement, JUMP to 06E2H which then JUMPs to 2B89H which is in the middle of the TOKENize routing. This address bumps BC (the input buffer pointer), reduces D (the buffer counter), moves the BASIC line pointer forward, and continues.
06F9
LD A,(HL)
Load the next character into A.
06FA
CP 88H
Compare A to 88H to see if it is DATA.
06FC
If it is DATA then GOSUB to 06E5H to set the flag accordingly.
06FF
CP 93H
Compare A to 93H to see if it is REM.
0701
If it is REM then GOSUB to 06EFH to set the DATA FLAG to indicate that we are inside a REM.
0704
LD A,(HL)
Load the next character into A.
0705
JUMP to 2BA0H to see if the current token is ELSE and then keep processing.

070BH-070FH – SINGLE PRECISION ADDITION, ACCumulator = (HL) + ACCumulator – “FADDH”

Single-precision addition (ACCumulator=(HL)+ACC) involving a buffer pointed to by the HL Register Pair and ACCumulator (i.e., 4121H-4122H). This part of the program loads the BCDE registers with the value from the buffer, then passes control to 716H.
0708-070A
 ↳ FADDH
21 80 13
LD HL,1380HLD HL,FHALF
Load Register Pair HL address of the single precision value 1/2, which is stored in ROM at 1380H. This would be applicable if the entry jump was to this address (FADDH). If the entry is to FADDS, then this wouldn’t occur.
070B-070D
 ↳ FADDS
CALL 09C2HCALL MOVRMCD C2 09
Move the argument from (HL) into the registers via a call to 09C2H (which loads a SINGLE PRECISION value pointed to by Register Pair HL into Register Pairs BC and DE)
070E-070F
JR 0716HJR FADD18 06
Actually do the addition via a JUMP to the SINGLE PRECISION ADD routine at 0716H (which adds the single precision value in (BC/DE) to the single precision value in the ACCumulator (i.e., 4121H-4122H). The sum is left in the ACCumulator

0710H-0712H – SINGLE PRECISION SUBTRACTION, ACCumulator = (HL) – ACCumulator
“FSUBS”

Single-precision subtraction (ACC=(HL)-ACC). This loads the BCDE registers with the value from (HL), then passes control to 713H.
0710-0712
 ↳ FSUBS
CALL 09C2HCALL MOVRMCD C2 09
Load a SINGLE PRECISION value pointed to by Register Pair HL into Register Pairs BC and DE via a GOSUB to MOVRM

– “FSUB”

Single-precision subtraction (ACCumulator=BCDE-ACCumulator). The routine actually inverts ACCumulator (i.e., 4121H-4122H) and adds it to the contents of the BCDE registers which, in effect, is a subtraction. The result will be stored in the ACCumulator (i.e., 4121H-4122H).

Single Precision Subtract: Subtracts the single precision value in (BC/DE) from the single precision value in the ACCumulator. The difference is left in the ACCumulator

Single-precision subtraction (ACC=BCDE-ACC). The routine actually inverts the ACC and adds it to the contents of the BCDE registers which, in effect, is a subtraction. The result will be stored in the arithmetic work area (ACC)

Note: If you wanted to subtract two single precision numbers, store the minuend in the BCDE registers and store the subtrahend in 4121H-4124H and then CALL 0713H. The result (in single precision format) is in 4121H-4124H in approximately 670 microseconds.

0713-0715
 ↳ FSUB
CALL 0982HCALL NEGCD 82 09
Go reverse the sign of the single precision value in Register Pairs BC and DE so that the addition routine just below can be used.

0716H-0752H – SINGLE PRECISION ADDITION, ACCumulator = BCDE + ACCumulator – “FADD”

Single-precision addition (ACCumulator=BCDE+ACC). This routine adds two single-precision values and stores the result in the ACCumulator area.

Note: If you wanted to add 2 single precision numbers via a ROM call, store one input into BCDE (with the exponent in B and the LSB in E) and the other into 4121H-4124H, and then call 0716H. The single precision result will be in 4121H-4124H approximately 1.3 milliseconds later.

Single Precision Add: Add the single precision value in (BC/DE) to the single precision value in the ACCumulator. The sum is left in the ACCumulator

Single-precision addition (ACC=BCDE+ACC). This routine adds two singleprecision values and stores the result in the ACC area

Formula: FAC:=ARG+FAC

Routine ALTERS A,B,C,D,E,H,L

If INTFSF=1 the format of floating point numbers will be:
  • Reg B – SIGN AND BITS 1-7 OF EXPONENT
  • Reg C – Bit 8 of exponent ;and bits 2-8 of mantissa
  • Reg D – Bits 9-16 of mantissa
  • Reg E – Bits 17-24 of mantissa, and likewise for the ACCumulator format
  • Note: The exponent for intel will be 7FH
0716
 ↳ FADD
LD A,B78
First we need to check to see if the first argument is zero, so we load Register A with the exponent of the single precision value in Register B
0717
OR AB7
Set the flags based on Register B to check to see if the single precision value in Register Pairs BC and DE is equal to zero
0718
RET ZC8
Return if the single precision value in Register Pairs BC and DE is equal to zero because the result is already in the ACCumulator.
0719-071B
LD A,(4124H)LD A,(FAC)3A 24 41
Next, we want to test to see if the exponent is zero, because if it is, then the answer is already in the registers. First, load Register A with the exponent of the single precision value in the ACCumulator (i.e., 4121H-4122H)
071C
OR AB7
Set the flags based on the exponent (now in A) is equal to zero
071D-071F
JP Z,09B4HJP Z,MOVFRCA B4 09
If the exponent is zero, then the result is already in BCDE, so CALL MOVFR to move the SINGLE PRECISION value in DC/DE into ACCumulator.

At this point we know that we are going to actually do the math, so the next step is to get the smaller number into the registers (BCDE) so we can just shift it rith and align the binary points of both numbers. If we do this, then we just add or subtract them bytewise.

0720
SUB B90
Subtract the value of the exponent for the single precision value in Register B from the value of the exponent for the single precision value in the ACCumulator (i.e., 4121H-4122H) in Register A so we can see which is smaller. NC will be set if BCDE < ACCumulator.
0721-0722
JR NC,072FHJR NC,FADD130 0C
If the single precision value in Register Pairs BC and DE is smaller than the single precision value in the ACCumulator (i.e., 4121H-4122H), JUMP to FADD1 since they are in the right order.
0723
CPL2F
If we are here, then we want to swap the two numbers. First, we negate the shift count (adjust the difference in the exponents in Register A so that it is positive)
0724
INC A3C
Increment the difference in the exponents in Register A so that it will be the correct positive number
0725
EX DE,HLEB
Swap the ACCumulator and the Registers
0726-0728
CALL 09A4HCALL PUSHFCD A4 09
Call 09A4 which moves the SINGLE PRECISION value in the ACCumulator to the STACK (stored in LSB/MSB/Exponent order)
0729
EX DE,HLEB
Load Register Pair DE with the 16-bit value in Register Pair HL
072A-072C
CALL 09B4HCALL MOVFRCD B4 09
Call 09B4H which moves the SINGLE PRECISION value in DC/DE into ACCumulator
072D
POP BCC1
Next we finish the swap buyt putting the old ACCumulator into the registers with two POPs. First, get the 16-bit value from the STACK and put it in Register Pair BC
072E
POP DED1
Get the 16-bit value from the STACK and put it in Register Pair DE
At this point, the smaller number is in ABCD, so we proceed with the math.
072F-0730
 ↳ FADD1
CP 19HFE 19
The highest math we can do is 24 bits, so first check to make sure we are not going to exceed that. To do this we check to see if the difference in the exponents in Register A is greater than 24
0731
RET NCD0
If the math is going to exceed 24 bits, then we need to fail and RETurn
0732
PUSH AFF5
Save the shift count (the difference in the exponents in Register A) on the STACK
0733-0735
CALL 09DFHCALL UNPACKCD DF 09
Set the sign bits for the single precision values and return with the equality of the sign bits in Register A
0736
LD H,A67
Save the sign bits (the subtraction flag) into Register A
0737
POP AFF1
Get shift count (the difference of the exponents) back from the STACK and put it in Register A
If the numbers have the same sign, then we add them. if the signs are different, then we have to subtract them. we have to do this because the mantissas are positive. judging by the exponents, the larger number is in the ACCumulator, so if we subtract, the sign of the result should be the sign of the ACCumulator; however, if the exponents are the same, the number in the registers could be bigger, so after we subtract them, we have to check if the result was negative. if it was, we negate the number in the registers and complement the sign of the ACCumulator. (here the ACCumulator is unpacked) if we have to add the numbers, the sign of the result is the sign of the ACCumulator. so, in either case, when we are all done, the sign of the result will be the sign of the ACCumulator.
0738-073A
CALL 07D7HCALL SHIFTRCD D7 07
Shift the single precision value in Register Pairs BC and DE until it lines up with the single precision value in the ACCumulator
073B
OR HB4
Get the subtraction flag to see if the sign bits are equal
073C-073E
LD HL,4121HLD HL,FACLO21 21 41
Load Register Pair HL with the starting address of ACCumulator
073F-0741
JP P,0754HJP P,FADD3F2 54 07
If the signs were differet, then we move to subtractions
0742-0744
CALL 07B7HCALL FADDACD B7 07
Otherwise, we add the single precision value in BCDE to the single precision value in the ACCumulator
0745-0747
JP NC,0796HJP NC,ROUNDD2 96 07
If there was NO overflow then we will JUMP away to round
0748
INC HL23
If we’re still here, then there was an overflow, but the most it can overflow is 1 bit, so we increment the memory pointer in Register Pair HL, so that it points to the exponent in the ACCumulator
0749
INC (HL)34
Increment the exponent in the ACCumulator at the location of the memory pointer in Register Pair HL
074A-074C
JP Z,07B2HJP Z,OVERRCA B2 07
Check for another overflow (i.e., the exponent in the ACCumulator is too large) in which case go to 07B2H to output an OV ERROR message
074D-074E
LD L,01H2E 01
Prepare to shift the result one one bit and shift the CARRY FLAG in by load ingRegister L with the number of bits to shift the single precision result in Register Pairs BC and DE
074F-0751
CALL 07EBHCALL SHRADDCD EB 07
Go shift the single precision result in Register Pairs BC and DE
0752-0753
JR 0796HJR ROUND18 42
Finish up by rounding the results via a JUMP to 0796H

0754H-077CH – SINGLE PRECISION MATH ROUTINE – “FADD3”

This routine will subtract CDEB from ((HL)+0,1,2),0.
0754
 ↳ FADD3
XOR AAF
Zero Register A to negate the unflow byte and subtract the numbers.
0755
SUB B90
Subtract the 8-bit value in Register B from the value in Register A
0756
LD B,A47
Save the result into Register A
0757
LD A,(HL)7E
Prepare to subtract the low order numbers. First, load Register A with the value at the memory pointer in Register Pair HL
0758
SBC A,E9B
Subtract the value in Register E from the value in Register A
0759
LD E,A5F
Load Register E with the result in Register A
075A
INC HL23
Increment the memory pointer in Register Pair HL to point to the next byte (the middle order numbers) to deal with
075B
LD A,(HL)7E
Prepare to subtract the middle order numbers. First, load Register A with the value at the location of the memory pointer in Register Pair HL
075C
SBC A,D9A
Subtract the value in Register D from the value in Register A
075D
LD D,A57
Load Register D with the result in Register A
075E
INC HL23
Increment the memory pointer in Register Pair HL to point to the next byte (the high order numbers) to deal with
075F
LD A,(HL)7E
Load Register A with the value at the location of the memory pointer in Register Pair HL
0760
SBC A,C99
Subtract the value in Register C from the value in Register A
0761
LD C,A4F
Load Register C with the result in Register A
With that out the way, we need to make sure we have a positive mantissa (or else we will need to negate the number).
0762-0764
 ↳ FADFLT
CALL C,07C3HCALL C,NEGRDC C3 07
If the Carry flag is set (which is to indicate that the number was negative), go convert the single precision value to a positive number
This next routine normalizes CDEB. In doing so, ABCDE and HL are all modified. This routine shifts the mantissa left until the MSB is a 1.
0765
 ↳ NORMAL
LD L,B68
Put the lowest two bytes into (HL)
0766
LD H,E63
Load Register H with the LSB of the single precision value in Register E
0767
XOR AAF
Zero Register A so that Register B can track the shift count.
0768
 ↳ NORM1
LD B,A47
Save the shift count from Register A into Register B.
0769
LD A,C79
Load Register A with the MSB of the single precision value in Register C
076A
OR AB7
Check to see if the value in Register A is equal to zero
076B-076C
JR NZ,0785HJR NZ,NORM320 18
So long as we have a non-Zero value, JUMP to shift one place
076D
LD C,D4A
Shift the NMSB into the MSB by loading Register C with the value in Register D
076E
LD D,H54
Shift the LSB into the NMSB by loading Register D with the value in Register H
076F
LD H,L65
Load Register H with the value in Register L
0770
LD L,A6F
Load Register L with the value in Register A
0771
LD A,B78
Load Register A with the new shift count (exponent counter) in Register B
0772-0773
SUB 08HD6 08
Subtract the number of bits just shifted from the new exponent counter in Register A
0774-0775
CP E0HFE E0
Check to see if we shifted 4 bytes of zeroes. If no (NZ) we will need to shift over 8 more.
0776-0777
JR NZ,0768HJR NZ,NORM120 F0
If we did not shift 4 bytes of ZERO’es, shift 8 more via a loop until shift is completed
This routine will ZERO out the ACCumulator, changing only Register A in the process. A will exit as 0.
0778
 ↳ ZERO
XOR AAF
Zero Register A
0779-077B
 ↳ ZERO0
LD (4124H),ALD (FAC),A32 24 41
Make the ACCUmulator’s exponent = whatever is in A. If entered from above, then it will be 0. This is done because Level II treats a number as zero if its exponent is zero.
077C
RETC9
Return with a single precision value of zero in the ACCumulator

077DH-07A7H – SINGLE PRECISION MATH SUPPORT ROUTINE – “NORM2”

077D
 ↳ NORM2
DEC B05
Decrement the shift count (exponent counter) in Register B
077E
ADD HL,HL29
Rotate (HL) left by 1 and shift in a 0
077F
LD A,D7A
Rotate the next higher order (NMSB) left 1 as well.
0780
RLA17
Shift the NMSB in Register A left one bit and shift a bit from Register Pair HL if necessary
0781
LD D,A57
Save the adjusted NMSB in Register A into Register D
0782
LD A,C79
Load Register A with the MSB in Register C
0783
ADC A,A8F
Shift the MSB in Register A left one bit and shift a bit from Register D if necessary. The flags will get set as well.
0784
LD C,A4F
Load Register C with the adjusted value in Register A
0785-0787
 ↳ NORM3
JP P,077DHJP P,NORM2F2 7D 07
IF the P FLAG is set, then we have more normalization to do so loop until the most significant bit of the single precision value is equal to one
If we are here, then we have a fully normalized result, so let us continue.
0788
LD A,B78
Load Register A with the new shift count (exponent counter) in Register B
0789
LD E,H5C
Load Register E with the LSB of the low order part of the single precision value
078A
LD B,L45
Load Register B with the MSB of the low order part of the single precision value
078B
OR AB7
Check to see if there were any bits shifted
078C-078D
JR Z,0796HJR Z,ROUND28 08
Jump if there weren’t any bits shifted
078E-0790
LD HL,4124HLD HL,FAC21 24 41
Load Register Pair HL with the address of the exponent in the ACCumulator
0791
ADD A,(HL)86
Add the value of the original exponent at the location of the memory pointer in Register Pair HL to the number of bits shifted in Register A
0792
LD (HL),A77
Save the new exponent in Register A at the location of the memory pointer in Register Pair HL
0793-0794
JR NC,0778HR NC,ZERO30 E3
Jump if exponent is too small (i.e., an underflow). This jump is to code which just zeroes out A, puts it into (4124H), and RETurns
0795
RET ZC8
Return if exponent is equal to zero. Otherwise, we will pass down to the “ROUND” routine
The “ROUND” routine rounds the result in CDEB and puts the result into the ACCumulator. All registers are affected. CDE is rounded up or down based on the MSB of Register B.

Vernon Hester has flagged an error in the rounding of math routines. In base 10, rounding to k-digits examines digit k+1. If digit k+1 is 5 through 9, then digit k is adjusted up by one and carries to the most significant digit, if necessary. If digit k+1 is less than 5, then digit k is not adjusted. This should not get muddled with the conversion of base 2 to base 10. Nevertheless, four divided by nine should be: .444444 and not .444445
0796
 ↳ ROUND
LD A,B78
Load Register A with the LSB of the single precision value in Register B
0797-0799
 ↳ ROUNDB
LD HL,4124HLD HL,FAC21 24 41
Load Register Pair HL with the address of the exponent in the ACCumulator. Note: The FDIV ROM Routine enters the routine here at ROUNDB with Register A set differently.
079A
OR AB7
Set the status flags to enable us to see if we need if we need to round up. If the M FLAG is set (the most significant bit of the value in Register A), we will need to round up.
079B-079D
CALL M,07A8HCALL M,ROUNDAFC A8 07
If the M FLAG is set (if the most significant bit in the value in Register A is set), GOSUB to round up
079E
LD B,(HL)46
Put the exponent (modified or not), whcih is currently held in the RAM location pointed to by HL, into Register B.
079F
INC HL23
Increment the memory pointer in Register Pair HL to now point to the sign
07A0
LD A,(HL)7E
Load Register A with the value of the sign at the location of the memory pointer in Register Pair HL
07A1-07A2
AND 80HAND 1000 0000E6 80
Turn off some bits so we can mask the sign bit in Register A (1000 0000)
07A3
XOR CA9
Set the sign bit in Register A
07A4
LD C,A4F
Load Register C with the sign
07A5-07A7
JP 09B4HJP MOVFRC3 B4 09
Save the number into the ACCumulator via a JUMP to 09B4H which moves the SINGLE PRECISION value in BC/DE into ACCumulator

07A8H-07B6H – SINGLE PRECISION MATH SUPPORT ROUTINE – “ROUNDA”

This is a subroutine within the ROUND round. This will add one to C/D/E.
07A8
 ↳ ROUNDA
INC E1C
Increment the LSB of the single precision value (which is stored in Register E). Note: This is the entry point from QUINT.
07A9
RET NZC0
If the NZ FLAG is set, then we have no overflow, so we are done!
07AAH
INC D14
Increment the NMSB of the single precision value (which is stored in Register D)
07AB
RET NZC0
If the NZ FLAG is set, then we have no overflow, so we are done!
07AC
INC C0C
Increment the MSB of the single precision value (which is stored in Register C).
07AD
RET NZC0
If the NZ FLAG is set, then we have no overflow, so we are done!
07AE-07AF
LD C,800E 80
If we are still here then the number overflowed all 3 registers. With this, we need to adjust the MSB of the single precision value in Register C and then …
07B0
INC (HL)34
… update the exponent (which is stored in the RAM location pointed to by HL)
07B1
RET NZC0
If the NZ FLAG is set, then we have no overflow, so we are done! If that overflowed as well, then we are out of luck and we pass through to an error.

– “OVERR”

07B2H-07B3
 ↳ OVERR
LD E,0AHLD E,ERROV1E 0A
Load Register E with an ?OV ERROR code.
07B4-07B6
JP 19A2HJP ERRORC3 A2 19
Go to the Level II BASIC error routine and display an OV ERROR message if the value has overflowed

07B7H-07C2H SINGLE PRECISION MATH ROUTINE – “FADDA”

This routine adds (HL+2),(HL+1),(HL+0) to C,D,E. This is called by FADD and FOUT.
07B7
 ↳ FADDA
LD A,(HL)7E
Load Register A with the LSB of the single precision value in the ACCumulator (pointed to by Register Pair HL)
07B8
ADD A,E83
Add Register E (the LSB of the other number being added; stored in Register E) to the LSB of the single precision value in the ACCumulator
07B9
LD E,A5F
… and put that sum into Register E
07BA
INC HL23
Onto the middle number/NMSB. Increment the memory pointer in Register Pair HL to point to the NMSB (ACCumulator + 1).
07BB
LD A,(HL)7E
Load Register A with the NMSB of the single precision value in the ACCumulator at the location of the memory pointer in Register Pair HL
07BC
ADC A,D8A
Add the NMSB of the single precision value in Register D to the NMSB of the single precision value in Register A
07BD
LD D,A57
Load Register D with the result in Register A
07BE
INC HL23
Onto the high order number/MSB. Increment the memory pointer in Register Pair HL to point to the MSB (ACCumulator + 2).
07BF
LD A,(HL)7E
Load Register A with the MSB of the single precision value in the ACCumulator at the location of the memory pointer in Register Pair HL
07C0
ADC A,C89
Add the MSB of the single precision value in Register C to the MSB of the single precision value in Register A
07C1
LD C,A4F
Load Register C with the result in Register A
07C2
RETC9
RETurn to CALLer

07C3H-07D6H – SINGLE PRECISION MATH ROUTINE – NEGR

This routine negates the number in C/D/E/B. CALLd by FADD and QUINT. Alters everything except Register H.
07C3-07C5
 ↳ NEGR
LD HL,4125HLD HL,FAC+121 25 41
Load Register Pair HL with the address of the sign flag storage location.
07C6
LD A,(HL)7E
Load Register A with the value of the sign flag at the location of the memory pointer in Register Pair HL
07C7
CPL2F
Complement the sign flag in Register A
07C8
LD (HL),A77
Save the adjusted sign flag in Register A back to (FAC+1)
07C9
XOR AAF
Zero Register A. This will allow us to zero Register L and to do negative math
07CA
LD L,A6F
Load Register L with a 0 (held in Register A) so that we can keep getting a zero back into Register A for the below math using less code.
07CB
SUB B90
NEGate the low order/LSB number by subtracting Register B from zero (held in Register A)
07CC
LD B,A47
Save that negated Register B back to Register B
07CD
LD A,L7D
Load Register A with zero
07CE
SBC A,E9B
NEGate the next highest order number by subtracting Register E from zero (held in Register A)
07CF
LD E,A5F
Save that negated Register E back to Register E
07D0
LD A,L7D
Load Register A with zero
07D1
SBC A,D9A
NEGate the next highest order number by subtracting Register D from zero (held in Register A)
07D2
LD D,A57
Save that negated Register D back to Register D
07D3
LD A,L7D
Load Register A with zero
07D4
SBC A,C99
NEGate the highest order number/MSB by subtracting Register C from zero (held in Register A)
07D5
LD C,A4F
Save that negated Register C back to Register C
07D6
RETC9
RETurn to CALLer

07D7H-07F7H – SINGLE PRECISION MATH ROUTINE – “SHIFTR”

This routine will shift the number in C/D/E right the number of times held in Register A. The general idea is to shift right 8 places as many times as is possible within the number of times in A, and then jump out to shift single bits once you can’t shift 8 at a time anymore. Alters everything except Register H.
07D7-07D8
 ↳ SHIFTR
LD B,00H06 00
Load Register B, which will hold the overflow byte, with zero to reset the overflow byte
07D9-07DA
 ↳ SHFTR1
SUB 08HD6 08
Top of a loop. For speed, first check to see if the shift counter in Register A still indicates at least 8 bits have to be shifted right
07DB-07DC
JR C,07E4HJR C,SHFTR238 07
If the CARRY FLAG is set, then there isn’t room to shift 8 bytes, so we are going to need to shift only 1 byte, by JUMPing away to SHFTR2. This is the routine’s exit.
If we are here, then we are good to shift 8 bytes at once. So B to E, E to D, D to C, and then Zero out C …
07DD
LD B,E43
Load Register B with the LSB of the single precision value in Register E
07DE
LD E,D5A
Load Register E with the NMSB of the single precision value in Register D
07DF
LD D,C51
Load Register D with the MSB of the single precision value in Register C
07E0-07E1
LD C,00H0E 00
Load Register C with zero
07E2-07E3
JR 07D9HJR SHFTR118 F5
Loop back to see if we can keep shifting

07E4 – SINGLE PRECISION MATH ROUTINE – “SHFTR2”

This routine will shift the number in C/D/E right the number of times held in Register A, but one byte at a time.
07E4-07E5
 ↳ SHFTR2
ADD 09HC6 09
Adjust the shift counter in Register A to its correct value for working with individual bits instead of bytes
07E6
LD L,A6F
Load Register L with the shift counter in Register A so that L will hold the counter for shifts at the single bit level
07E7
 ↳ SHFTR3
XOR AAF
Top of a loop. Clear the CARRY FLAG.
07E8
DEC L2D
Decrement the bit shift counter (held in Register L)
07E9
RET ZC8
Return if there are no more bits to be shifted. This is the routine’s exit.
07EA
LD A,C79
If we are here, then there are L bits to shift. First, load Register A with the High Order/MSB of the single precision value in Register C
07EB
 ↳ SHRADD
RRA1F
Shift the MSB of the single precision value in Register A one place to the right. Note: FADD enters at this point withRegister A set differently. RRA rotates the contents of Register A right one bit position, with Bit 0 going to the CARRY FLAG, and the CARRY FLAG going to Bit 7. RRA also can be used to divide a number in 2.
07EC
LD C,A4F
Save the bit shifted MSB (held in Register A) back into Register C
07ED
LD A,D7A
Load Register A with the NMSB of the single precision value in Register D
07EE
RRA1F
Shift the NMSB of the single precision value in Register A one place to the right and pick up the value of the Carry flag. RRA rotates the contents of Register A right one bit position, with Bit 0 going to the CARRY FLAG, and the CARRY FLAG going to Bit 7. RRA also can be used to divide a number in 2.
07EF
LD D,A57
Save the bit shifted NMSB (held in Register A) back into Register D
07F0
LD A,E7B
Load Register A with the LSB of the single precision value in Register E
07F1
RRA1F
Shift the LSB of the single precision value in Register A one place to the right and pick up the value of the Carry flag. RRA rotates the contents of Register A right one bit position, with Bit 0 going to the CARRY FLAG, and the CARRY FLAG going to Bit 7. RRA also can be used to divide a number in 2.
07F2
LD E,A5F
Save the bit shifted LSB (held in Register A) back into Register D
07F3
LD A,B78
Load Register A with the overflow byte (held in Register B)
07F4
RRA1F
Shift the overflow byte one place to the right and pick up the value of the Carry flag. RRA rotates the contents of Register A right one bit position, with Bit 0 going to the CARRY FLAG, and the CARRY FLAG going to Bit 7. RRA also can be used to divide a number in 2.
07F5
LD B,A47
Save the bit shifted overflow byte (held in Register A) back into Register B
07F6-07F7
JR 07E7HJR SHFTR318 EF
Loop until all of the bits have been shifted

07F8-07FB – SINGLE PRECISION CONSTANT STORAGE LOCATION

07F8-07FB
00 00 00 81
A single precision constant equal to 1.0 is stored here.

07FC-0808 – SINGLE PRECISION CONSTANTS STORAGE LOCATION2

07FC
03
The number of single precision constants which follows is stored here.
07FD-0800
AA 56 19 80
A single precision constant equal to .598978 is stored here.
0801-0804
F1 22 76 80
A single precision constant equal to .961471 is stored here.
0805-0808
45 AA 38 82
A single precision constant equal to 2.88539 is stored here.

0809H-0846H – LEVEL II BASIC LOG ROUTINE – “LOG”

The LOG(n) routine, (ACCumulator=LOG (ACCumulator)). This routine finds the natural log (base E) of the single precision value in the ACCumulator area.

The result is returned as a single precision value in the ACCumulator

To use a ROM call to find LOG(n), where X is a positive single precision variable, store the value of n in 4121H-4124H and then CALL 0809H. The result (in single precision format) is in 4121H-4124Hin approximately 19 milliseconds. NOTE: A fatal error occurs if the value of the input variable is zero or negative.

Vernon Hester has identified a bug in the LOG() routine. Regardless of the base, if the argument is 1 then the logarithm is zero, if the argument is > 1 then the logarithm is positive, and if the argument is > 0 and < 1 then the logarithm is negative. However, if the argument is just under 1, the ROM’s LOG function produces a positive value. e.g., 10 PRINT LOG(.99999994)
0809-080B
 ↳ LOG
CALL 0955HCALL SIGNCD 55 09
Go check the sign (or zero value) of the single precision value in the ACCumulator
080C
OR AB7
Set the flags.
080D-080F
JP PE,1E4AHJP PE,FCERREA 4A 1E
If the ACCumulator value is <= ZERO then we cannot proceed so go the Level II BASIC error routine and display a ?FC ERROR message. The SIGN routine will only return 00H, 01H, or FFH, so PE will be set if its 00H or FFH, but not 01H
0810-0812
LD HL,4124HLD HL,FAC21 24 41
Load Register Pair HL with the address of the exponent in the ACCumulator
0813
LD A,(HL)7E
Load Register A with the exponent of the single precision value in the ACCumulator (held at the location of the memory pointer in Register Pair HL)
The next two instructions are commented in the original ROM source code as: Get SQR(.5)
0814-0816
LD BC,8035H01 35 80
Load Register BC with the exponent and the MSB of a single precision constant (which is 32821)
0817-0819
LD DE,04F3H11 F3 04
Load Register DE with the NMSB and the LSB of a single precision constant (which is 1267). Register Pairs BC and DE are now equal to the single precision constant of .707107
081A
SUB B90
Remove the excess 80H (held in Register B) from the exponent of the n-value (of LOG (n)) held in Register A
081B
PUSH AFF5
Save the modified exponent to the the STACK for later
081C
LD (HL),B70
Set the exponent to 80H
The next two instructions save SQR(.5) to the STACK
081D
PUSH DED5
Save the NMSB and the LSB of the single precision value in Register Pair DE on the STACK
081E
PUSH BCC5
Save the exponent and the MSB of the single value in Register Pair BC on the STACK
081F-0831
CALL 0716HCALL FADDCD 16 07
Calculate (F-SQR(.5))/(F+SQR(.5)) where F = the number in the ACCumulator by GOSUBing to FADD which will add the x-value to the single precision constant in Register Pairs BC and DE and return with the result in the ACCumulator, by calling the SINGLE PRECISION ADD routine at 0716H (which adds the single precision value in (BC/DE) to the single precision value in the ACCumulator. The sum is left in the ACCumulator)
The next two instructions restore SQR(.5) from the STACK
0822
POP BCC1
Get the exponent and the MSB of the single precision value from the STACK and put it in Register Pair BC
0823
POP DED1
Get the NMSB and the LSB of the single precision value from the STACK and put it in Register Pair DE
The next two instructions get SQR(2)
0824
INC B04
Multiply the single precision value in Register Pairs BC and DE by two by bumping the exponent in Register B
0825-0827
CALL 08A2HCALL FDIVCD A2 08
Go divide the single precision value in Register Pairs BC and DE by the x-value in the ACCumulator and return with the result in the ACCumulator
0828-082A
LD HL,07F8HLD HL,FONE21 F8 07
Load Register Pair HL with the starting address of a single precision constant (which is at 2040)
082B-082D
CALL 0710HCALL FSUBSCD 10 07
Go subtract the x-value in the ACCumulator from the single precision constant of 1. 0 at the location of the memory pointer in Register Pair HL and return with the result in the ACCumulator
082E-0830
LD HL,07FCHLD HL,LOGCN221 FC 07
Load Register Pair HL with the starting address of a storage location for the single precision constants of a “approximation polynomial” to be used.
0831-0833
CALL 149AHCALL POLYXCD 9A 14
Go do a series of computations and return with the result in the ACCumulator
The next two instructions are commented in the original ROM source code as: Get -1/2
0834-0836
LD BC,8080H01 80 80
Load Register BC with the exponent and the MSB of a single precision constant
0837-0839
LD DE,0000H11 00 00
Load Register Pair DE with the NMSB and the LSB of a single precision. Register Pairs BC and DE are now equal to a single precision of -0.5
083A-083C
CALL 0716HCALL FADDCD 16 07
Add in the last constant via a GOSUB to FADD which will add the x-value in the ACCumulator to the single precision constant in Register Pairs BC and DE and return with the result in the ACCumulator, by calling the SINGLE PRECISION ADD routine at 0716H (which adds the single precision value in (BC/DE) to the single precision value in the ACCumulator. The sum is left in the ACCumulator)
083D
POP AFF1
Retrieve the original exponent from the STACK and put it in Register A
083E-0840
CALL 0F89HCALL FINLOGCD 89 0F
Go convert the value in Register A to a single precision number and add it to the x-value in the ACCumulator. Return with the result in the ACCumulator
The instructions are commented in the original ROM source code as: Get LN(2)
0841-0843
 ↳ MULLN2
LD BC,8031H01 31 80
Load Register Pair BC with the exponent and the MSB of a single precision constant
0844-0846
LD DE,7218H11 18 72
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 value of 0.693147
The original ROM source code had a jump to the muptlication routine; but to save bytes, the ROM was restructured to just fall into the MULTiplocation routine instead.

0847H-0891H – SINGLE PRECISION MULTIPLICATION, – “FMULT”

Single-precision multiplication (ACCumulator=BCDE*ACC or ACC = ARG * FAC)).
Multiplies the current value in the ACCumulator by the value in (BC/DE). the product is left in the ACCumulator.

Note: If you wanted to multiply two single precision numbers store one operand in the BCDE registers, the other in 4121H-4124H CALL 0847H. The result (in single precision format) is in 4121H-4124H in approximately 2.2 milliseconds.

Single Precision Multiply Multiplies the current value in the ACCumulator by the value in (BC/DE). the product is left in the ACCumulator

This routine alters every Register.
0847-0849
 ↳ FMULT
CALL 0955HCALL SIGNCD 55 09
Go check to see if the single precision value in the ACCumulator is equal to zero
084A
RET ZC8
Return if the single precision value in the ACCumulator is equal to zero
084B-084C
LD L,00H2E 00
Since we don’t have a zero, the next step is to add the two exponents using L as a flag, so load Register L with 0
084D-084F
CALL 0914HCALL MULDIVCD 14 09
Next we need to fix up the exponents and save the numbers in the registers for faster addition.
0850
LD A,C79
Load Register A with the single precision value’s High Order/MSB in Register C
0851-0853
LD (414FH),ALD (FMLTT1),A32 4F 41
Save the MSB of the single precision value in Register A at memory location 414FH
0854
EX DE,HLEB
Load Register Pair HL with the NMSB and the LSB of the single precision value in Register Pair DE
0855-0857
LD (4150H),HLLD (FMLTT2),HL22 50 41
Save the NMSB and the LSB of the single precision value in Register Pair HL at memory locations 4150H and 4151H
0858-085A
LD BC,0000H01 00 00
Load Register Pair BC with a zero, which we will also put into Register D and Register E
085B
LD D,B50
Load Register D with the value in Register B
085C
LD E,B58
Load Register E with the value in Register B
085D-085F
LD HL,0765HLD HL,NORMAL21 65 07
Load Register Pair HL with the return address
0860
PUSH HLE5
Save the return address in Register Pair HL on the STACK
0861-0863
LD HL,0869HLD HL,FMULT221 69 08
Load Register Pair HL with the return address
0864
PUSH HLE5
Save the return address in Register Pair HL on the STACK
0865
PUSH HLE5
Save the return address in Register Pair HL on the STACK
0866-0868
LD HL,4121HLD HL,FACLO21 21 41
Load Register Pair HL with the low order/LSB address of the single precision value in the ACCumulator
0869
 ↳ FMULT2
LD A,(HL)7E
Load Register A with the byte to multiply by (on entry its the LSB of the single precision value in the ACCumulator)
086A
INC HL23
Increment the memory pointer in Register Pair HL to point to the next byte of the number in the ACCumulator
086B
OR AB7
Check to see if the LSB of the single precision value in the ACCumulator in Register A is equal to zero
086C-086D
JR Z,0892HJR Z,FMULT328 24
Jump if the LSB of the single precision value in the ACCumulator is equal to zero
086E
PUSH HLE5
Save the memory pointer to the number in the ACCumulator (tracked by Register HL) on the STACK
086F-0870
LD L,08H2E 08
Load Register L with the bit shift counter
The original source code explains what is being done next. The product will be formed in C/D/E/B. This will be in C/H/L/B part of the time in order to use the “DAD” instruction. At FMULT2, we get the next byte of the mantissa in the ACCumulator to multiply by, which is tracked by HL and unchanged by FMULT2. If the byte is zero, we just shift the product 8 bits to the right. This byte is then shifted right and saved in Register D. The CARRY FLAG determines if we should add in the second factor, and, if we do, we add it to C/H/L. Register B is only used to determine which way we round. We then shift C/H/L/B right one to get ready for the next time through the loop. Note: The CARRY is shifted into the MSB of Register C. Register E has the count to determine when we have looked at all the bits of Register D.
0871
 ↳ FMULT4
RRA1F
Shift the LSB of the single precision value in the ACCumulator in Register A one place to the right. RRA rotates the contents of Register A right one bit position, with Bit 0 going to the CARRY FLAG, and the CARRY FLAG going to Bit 7. RRA also can be used to divide a number in 2.
0872
LD H,A67
Load Register H with the adjusted LSB in Register A
0873
LD A,C79
Load Register A with the MSB of the single precision value in Register C
0874-0875
JR NC,0881HJR NC,FMULT530 0B
If the bit was zero, don’t add in any numbers and, instead, jump forward to 0881H
0876
PUSH HLE5
Save the counters (tracked in Register Pair HL) to the STACK
0877-0879
LD HL,(4150H)LD HL,(FMLTT2)2A 50 41
Load Register Pair HL with the NMSB and the LSB of the original value in Register Pairs BC and DE
087A
ADD HL,DE19
Add the NMSB and the LSB of the total figured so far in Register Pair DE to the NMSB and the LSB of the original value in Register Pair HL
087B
EX DE,HLEB
Load Register Pair DE with the adjusted total in Register Pair HL
087C
POP HLE1
Get the counters back from the STACK and put it in Register Pair HL
087D-087F
LD A,(414FH)LD A,(FMLTT1)3A 4F 41
Load Register A with the MSB of the original value in Register Pairs BC and DE
0880
ADC A,C89
Add the MSB of the original value in Register A to the MSB of the total figured so far in Register C
0881
 ↳ FMULT5
RRA1F
Shift the adjusted MSB of the total in Register A one place to the right. RRA rotates the contents of Register A right one bit position, with Bit 0 going to the CARRY FLAG, and the CARRY FLAG going to Bit 7. RRA also can be used to divide a number in 2.
0882
LD C,A4F
Load Register C with the adjusted MSB of the total in Register A
0883
LD A,D7A
Load Register A with the NMSB of the total in Register D
0884
RRA1F
Shift the NMSB of the total in Register A one place to the right. RRA rotates the contents of Register A right one bit position, with Bit 0 going to the CARRY FLAG, and the CARRY FLAG going to Bit 7. RRA also can be used to divide a number in 2.
0885
LD D,A57
Load Register D with the adjusted NMSB of the total in Register A
0886
LD A,E7B
Load Register A with the LSB of the total in Register E
0887
RRA1F
Shift the LSB of the total in Register A one place to the right. RRA rotates the contents of Register A right one bit position, with Bit 0 going to the CARRY FLAG, and the CARRY FLAG going to Bit 7. RRA also can be used to divide a number in 2.
0888
LD E,A5F
Load Register E with the adjusted LSB of the total in Register A
0889
LD A,B78
Load Register A with the value in Register B
088A
RRA1F
Shift the value in Register A one place to the right. RRA rotates the contents of Register A right one bit position, with Bit 0 going to the CARRY FLAG, and the CARRY FLAG going to Bit 7. RRA also can be used to divide a number in 2.
088B
LD B,A47
Load Register B with the adjusted value in Register A
088C
DEC L2D
Decrement the bit counter in Register L and set the flags accordingly
088D
LD A,H7C
Load Register A with the LSB of the number we are multiplying
088E-088F
JR NZ,0871HJR NZ,FMULT420 E1
Loop until 8 bits have been shifted
0890
 ↳ POPHRT
POP HLE1
Get the memory pointer to the number to multiply by from the STACK and put it in Register Pair HL
0891
RETC9
RETurn to CALLer

0892H-0896H – SINGLE PRECISION MATH ROUTINE – “FMULT3”

This is accomplished by a circular shift of BC/DE one byte – B is lost, C is replaced by A

This is a multiply by zero, where we just shift everything 8 bits to the right.

0892
 ↳ FMULT3
LD B,E43
Load Register B with the LSB of the single precision value in Register E
0893
LD E,D5A
Load Register E with the NMSB of the single precision value in Register D
0894
LD D,C51
Load Register D with the MSB of the single precision value in Register C
0895
LD C,A4F
Load Register C with the value in Register A (which should be all 0’s, which will now be on the left)
0896
RETC9
RETurn to CALLer

0897H-08A1H – SINGLE PRECISION MATH ROUTINE
– “DIV10”

This routine divides the ACCumulator by 10. Every Register is used.
0897-0899
 ↳ DIV10
CALL 09A4HCALL PUSHFCD A4 09
Save the number via a GOSUB to 09A4 which moves the SINGLE PRECISION value in the ACCumulator to the STACK (stored in LSB/MSB/Exponent order)
089A-089C
LD HL,0DD8HLD HL,FTEN21 D8 0D
Load Register Pair HL with the starting address of a single precision constant equal to 10
089D-089F
CALL 09B1HCALL MOVFMCD B1 09
Move the “10” into the ACCUulator via a call to 09B1H (which moves a SINGLE PRECISION number pointed to by HL to ACCumulator)
08A0
 ↳ FDIVT
POP BCC1
Get the exponent and the MSB of the single precision value on the STACK and put it in Register Pair BC
With the numbers in their places, we now just fall into the floating division routine.

08A2H-0903H – SINGLE PRECISION DIVISION – “FDIV”

Single-precision division (ACCumulator=BCDE/ACCumulator or ACC = ARG / ACC). If ACCumulator=0 a ” /0 ERROR ” will result.

This routine will divide the SINGLE PRECISION value in Register Pairs BC and DE by the single precision value in the ACCumulator. The result is returned in the ACCumulator. Every register is used.

To use a ROM call to divide two single precision numbers, store the dividend in registers BCDE, and the divisor in 4121H-4124H and then CALL 08A2H. The result (in single precision format) is in 4121H-4124H and then pproximately 4.8 milliseconds. Overflow or /0 will error out and return to Level II.
08A1
POP DED1
Get the NMSB and the LSB of the single precision value from the STACK and put it in Register Pair DE
08A2-08A4
 ↳ FDIV
CALL 0955HCALL SIGNCD 55 09
Go check to see if the single precision value in the ACCumulator is equal to zero so as to process that error.
08A5-08A7
JP Z,199AHJP Z,DV0ERRCA 9A 19
If the SIGN routine retuns Z FLAG set, then we have a division by zero problem so JUMP to the Level II BASIC error routine and display an /0 ERROR message
08A8-08A9
LD L,FFH2E FF
Load Register L with a flag for use when subtracting the two exponents.
08AA-08AC
CALL 0914HCALL MULDIVCD 14 09
Go adjust the exponent in the ACCumulator for division
08AD
08AE
INC (HL)
INC (HL)34
Add two to the exponent pointed to by (HL) to correct scaling
08AF
DEC HL2B
Decrement the value of the memory pointer in Register Pair HL to now point to the High Order/MSB of the single precision number in the ACCumulator
08B0
LD A,(HL)7E
Load Register A with the MSB of the single precision value in the ACCumulator
08B1-08B3
LD (4089H),ALD (FDIVA+1),A32 89 40
Save the MSB of the single precision value in the ACCumulator in Register A at memory location 4089H
08B4
DEC HL2B
Decrement the value of the memory pointer in Register Pair HL to point to the Middle Order/NMSB of the single precision number in the ACCumulator
08B5
LD A,(HL)7E
Load Register A with the NMSB of the single precision value in the ACCumulator at the location of the memory pointer in Register Pair HL
08B6-08B8
LD (4085H),ALD (FDIVB+1),A32 85 40
Save the NMSB of the single precision value in the ACCumulator in Register A at memory location 4085H
08B9
DEC HL2B
Decrement the value of the memory pointer in Register Pair HL to point to the Low Order/LSB of the single precision number in the ACCumulator
08BA
LD A,(HL)7E
Load Register A with the LSB of the single precision value in the ACCumulator at the location of the memory pointer in Register Pair HL
08BB-08BD
LD (4081H),ALD (FDIVC+1),A32 81 40
Save the LSB of the single precision value in the ACCumulator in Register A at memory location 4081H
At this point, the memory locations are set up, and it’s time to get to work. According to the original ROM source:

The numerator will be kept in Registers B/H/L. The quotient will be formed in Registers C/D/E. To get a bit of the quotient, we first save Registers B/H/L on the stack, and then subtract the denominator that we saved in memory. The CARRY FLAG will indicate whether or not Registers B/H/L was bigger than the denominator. If Registers B/H/L are bigger, the next bit of the quotient is a one. To get the old Registers B/H/L off the stack, they are POPped into the PSW. If the denominator was bigger, the next bit of the quotient is zero, and we get the old Registers B/H/L back by POPping them off the stack. We have to keep an extra bit of the quotient in FDIVG+1 in case the denominator was bigger, in which case Registers B/H/L will get shifted left. If the MSB of Register B is one, it has to be stored somewhere, so we store it in FDIVG+1. Then the next time through the loop Registers B/H/L will look bigger because it has an extra High Order bit in FDIVG+1. We are done dividing when the MSB of Register C is a one, which occurs when we have calculated 24 bits of the quotient. When we jump to ROUND, the 25th bit of the quotient (whcih is in the MSB of Register A) determines whether we round or not. If initially the denominator is bigger than the numerator, the first bit of the quotient will be zero. This means we will go through the divide loop 26 times, since it stops on the 25th bit after the first non-zero bit of the exponent. So, this quotient will look shifted left one from the quotient of two numbers in which the numerator is bigger. This can only occur on the first time through the loop, so Registers C/D/E are all zero. So, if we finish the loop and Registers C/D/E are all zero, then we must decrement the exponent to correct for this.
08BE
LD B,C41
First, we need to get the number into B/H/L. First, load Register B with the MSB of the single precision dividend (held in in Register C)
08BF
EX DE,HLEB
Then, get the NMSB and LSB of the dividend from DE into Register Pair HL
08C0
XOR AAF
Next, we need to zero out C, D, E, and the Highest Order
08C1
LD C,A4F
Zero the MSB of the total by loading Register C with the value in Register A
08C2
LD D,A57
Zero the NMSB of the total by loading Register D with the value in Register A
08C3
LD E,A5F
Zero the LSB of the total by loading Register E with the value in Register A
08C4-08C6
LD (408CH),ALD (FDIVG+1),A32 8C 40
Zero memory location 408CH (which is holding the highest order)
08C7
 ↳ FDIV1
PUSH HLE5
Save the NMSB and LSB of the single precision dividend (held in Register Pair HL) on the STACK
08C8
PUSH BCC5
Save the MSB of the dividend in Register B on the STACK
08C9
LD A,L7D
Next we will need to subtract the number that was in the ACCumulator, so load Register A with the LSB of the dividend in Register L
08CA-08CC
CALL 4080HCALL FDIVCCD 80 40
Go to the Level II BASIC division routine. Note: Per the original ROM source code, this division routine was moved to RAM for speed; it didn’t HAVE to be moved!
08CD-08CE
SBC 00HDE 00
Subtract the CARRY FLAG from it
08CF
CCF3F
Set the CARRY FLAG to correspond to the next quotient bit
08D0-08D1
JR NC,08D9HJR NC,FDIV230 07
If we subtracted too much then the NC flag will be set, in which case we need to get the old number back! To do this, JUMP down to 08D9H (which is a mid-instruction Z-80 trick)
08D2-08D4
LD (408CH),ALD (FDIVG+1),A32 8C 40
Update the highest order number held at FDIVG+1
08D5
POP AFF1
We want to clear the previous number off the stack since the subtraction didn’t cause an error
08D6
POP AFF1
And again
08D7
SCF37
Set the CARRY FLAG so that the next bit in the quotient is a 1 to indicate that the subtraction was good
08D8
D2
Z-80 Trick – See the note at 0134H for an explanation.
08D9
POP BC
Get the value from the STACK and put it in register pair BC.
08DA
POP HL
Get the value from the STACK and put it in register pair HL.
08DB
LD A,C79
We want to see if we are done by testing Register C, so load Register A with the MSB of the total in Register C
08DC
08DD
INC A
DEC A3C
Increment and then Decrement the MSB of the total in Register A. This will set the SIGN FLAG without affecting the CARRY FLAG
08DE
RRA1F
Shift the CARRY into the MSB (held in Register A). RRA rotates the contents of Register A right one bit position, with Bit 0 going to the CARRY FLAG, and the CARRY FLAG going to Bit 7. RRA also can be used to divide a number in 2.
08DF-08E1
JP M,0797HJP M,ROUNDBFA 97 07
If we are done, JUMP back to ROUNDB
08E2
RLA17
If we are here, then we aren’t done. First, we need to get the old CARRY FLAG back via a RLA
08E3
LD A,E7B
Next, we are going to rotate EVERYTHING left 1 bit. Load Register A with the LSB of the total in Register E
08E4
RLA17
Rotate the next bit of the quotient in
08E5
LD E,A5F
Load Register E with the adjusted LSB of the total in Register A
08E6
LD A,D7A
Load Register A with the NMSB of the total in Register D
08E7
RLA17
Rotate the next bit of the quotient in
08E8
LD D,A57
Load Register D with the adjusted NMSB of the total in Register A
08E9
LD A,C79
Load Register A with the MSB of the total in Register C
08EA
RLA17
Rotate the next bit of the quotient in
08EB
LD C,A4F
Load Register C with the adjusted MSB of the total in Register A
08EC
ADD HL,HL29
Almost done! Rotate a zero into the right end of the number
08ED
LD A,B78
Next, rotate the High Order/MSB of the dividend in Register B
08EE
RLA17
Rotate the next bit of the quotient in
08EF
LD B,A47
Load Register B with the adjusted MSB of the dividend in Register A
08F0-08F2
LD A,(408CH)LD A,(FDIVG+1)3A 8C 40
Next, rotate the HIGHEST order. Load Register A with the value at memory location 408CH
08F3
RLA17
Rotate the next bit of the quotient in
08F4-08F6
LD (408CH),ALD (FDIVG+1),A32 8C 40
Save the adjusted value in Register A at memory location 408CH
08F7
LD A,C79
Next we need to add one to the exponent if the first subtraction didn’t work. To do so, first load Register A with the MSB of the total in Register C
08F8
OR DB2
Combine the NMSB of the total in Register D with the value in Register A
08F9
OR EB3
Combine the LSB of the total in Register E with the value in Register A
08FA-08FB
JR NZ,08C7HJR NZ,FDIV120 CB
Jump back to 08C7H if the total isn’t equal to zero
08FC
PUSH HLE5
Save the NMSB and the LSB of the dividend in Register Pair HL on the STACK
08FD-08FF
LD HL,4124HLD HL,FAC21 24 41
Load Register Pair HL with the address of the exponent in the ACCumulator
0900
DEC (HL)35
Decrement the exponent in the ACCumulator at the location of the memory pointer in Register Pair HL
0901
POP HLE1
Get the NMSB and the LSB of the dividend from the STACK and put it in Register Pair HL
0902-0903
JR NZ,08C7HJR NZ,FDIV120 C3
Keep dividing if there was no overflow by JUMPING back to 08C7H if the exponent in the ACCumulator isn’t equal to zero
0904-0906
JP 07B2HJP OVERRC3 B2 07
Display an ?OV ERROR

0907H-0913H – DOUBLE PRECISION MATH ROUTINE – “MULDVS”

This routine is to check for special cases and to add exponents for the FMULT and FDIV routines. Registers A, B, H and L are modified.
0907-0908
 ↳ MULDVS
LD A,FFH3E FF
This is the entry point from the DDIV routine. With this, we need to set up to subtract exponents. To do this we load Register A with an appropriate bit mask
0909
2E
Z-80 Trick – See the note at 0134H for an explanation.
090A
XOR A
Zero A and clear the flags.
090B-090D
LD HL,412DHLD HL,ARG-121 2D 41
Load Register Pair HL with the address of the SIGN and the High/Order MSB in ARG (a/k/a REG 2) (a/k/a ARG)
090E
LD C,(HL)4E
Load Register C with the High Order/MSB and the sign of the value in ARG (a/k/a REG 2) for unpacking
090F
INC HL23
Increment the value of the memory pointer in Register Pair HL to now point to the exponent
0910
XOR (HL)AE
Get the exponent by XORing the mask in Register A (which varied based on where this routine was entered from)
0911
LD B,A47
Save the adjusted exponent into Register B for processing below
0912-0913
LD L,00H2E 00
Load Register L with a 00H which will indicate that the below routine needs to ADD the exponents and then pass through to the MULDIV routine

0914H-0930H – SINGLE PRECISION MATH ROUTINE – “MULDIV”

0914
 ↳ MULDIV
LD A,B78
First we should test to make sure that the number isn’t zero, so Load Register A with the exponent in Register B
0915
OR AB7
Check to see if the exponent in Register A is equal to zero
0916-0917
JR Z,0937HJR Z,MULDV228 1F
If the exponent in Register A is equal to zero then we just need to ZERO out the ACCumulator and we are done. Do that by JUMPing to 0937H
0918
LD A,L7D
Next, we need to determine if we are ADDing or SUBtracting, which is held in Register L. So load Register A with the bit mask in Register L
0919-091B
LD HL,4124HLD HL,FAC21 24 41
Load Register Pair HL with the address of the exponent in the ACCumulator
091C
XOR (HL)AE
Combine the value of the exponent at the location of the memory pointer in Register Pair HL with the bit mask in Register A (formerly of Register L)
091D
ADD A,B80
Add the value of the exponent in Register B to the value of the exponent in Register A
091E
LD B,A47
Load Register B with the combined exponents (currently held in Register A)
091F
RRA1F
Shift the value of the combined exponents in Register A one place to the right so that we can check for an overflow. RRA rotates the contents of Register A right one bit position, with Bit 0 going to the CARRY FLAG, and the CARRY FLAG going to Bit 7. RRA also can be used to divide a number in 2.
0920
XOR BA8
Check to see if the Carry flag was set by combining the two exponents. This will cause an overflow if the sign is the same as the carry.
0921
LD A,B78
Load Register A with the combined/summed exponents value in Register B
0922-0924
JP P,0936HJP P,MULDV1F2 36 09
If we have an overflow, Jump away to 0936H
0925-0926
ADD 80HC6 80
If we don’t have an overflow, then we need to make an exponent in excess of 80H (and turn on bit 8)
0927
LD (HL),A77
Save the value of the combined exponent in Register A as the exponent in the ACCumulator at the location of the memory pointer in Register Pair HL
0928-092A
JP Z,0890HJP Z,POPHRTCA 90 08
If the ADD 80H triggered a ZERO FLAG, then we have an underflow! Jump to POPHRT to put the numbers back and RETurn
092B-092D
CALL 09DFHCALL UNPACKCD DF 09
Unpack the arguments by a GODUB to UNPACK, which will turn on the sign bit of the MSB in the ACCumulator and Register B and save the sign bits
092E
LD (HL),A77
Save the new sign (held in Register A) to the ACCumulator at the location of the memory pointer in Register Pair HL
092F
 ↳ DCXHRT
DEC HL2B
Decrement the memory pointer in Register Pair HL so that it points to the exponent in the ACCumulator
0930
RETC9
RETurn to CALLer, with the HIGH ORDER/MSB in Register A

0931H-093DH – SINGLE PRECISION MATH ROUTINE – “MLDVEX”

This routine is called from EXP. If jumped here will checks if ACC=0. If so, the Z flag will be set
0931-0933
 ↳ MLDVEX
CALL 0955HCALL SIGNCD 55 09
Go check the value of the sign bit for the value in the ACCumulator and choose UNDERFLOW if negative
0934
CPL2F
Pick OVERFLOW if it was positive
0935
POP HLE1
Get the value from the STACK and put it in Register HL
0936
 ↳ MULDV1
OR AB7
Weneed to test to see if the error was an OVERFLOW or an UNDERFLOW, so set the flags according to the value of the sign bit test
0937
 ↳ MULDV2
POP HLE1
Clean the old RETurn address off the stack
0938-093A
JP P,0778HJP P,ZEROF2 78 07
If the value in the ACCumulator is negative, JUMP to 0778H to handle the underflow
093B-093D
JP 07B2HJP OVERRC3 B2 07
If its not negative, jump to 07B2H to throw an error because we have an overflow

093EH-0954H – SINGLE PRECISION MATH ROUTINE – “MUL10”

This routine multiplies the ACCumulator by 10. Every register is modified.
093E-0940
 ↳ MUL10
CALL 09BFHCALL MOVRFCD BF 09
Call 09BF which loads the SINGLE PRECISION value in the ACCumulator into Register Pair BC/DE
0941
LD A,B78
Load Register A with the value of the exponent (from Register B)
0942
OR AB7
Check to see if the exponent in Register A is equal to zero, because if the exponent is 0 then so is the number!
0943
RET ZC8
If the single precision value in Register Pairs BC and DE is equal to zero, then RETurn
0944-0945
ADD 02HC6 02
Multiply the value of the exponent in Register A by four (by adding 2 to the exponent)
0946-0948
JP C,07B2HJP C,OVERRDA B2 07
Display an ?OV ERROR if the adjusted exponent in Register A is too large
0949
LD B,A47
Put the exponent back into Register B
094A-094C
CALL 0716HCALL FADDCD 16 07
Multiply the number by 5 by adding the original value in the ACCumulator to the adjusted value in Register Pairs BC and DE and return with the original result in the ACCumulator by calling the SINGLE PRECISION ADD routine at 0716H (which adds the single precision value in (BC/DE) to the single precision value in the ACCumulator. The sum is left in the ACCumulator)
094D-094F
LD HL,4124HLD HL,FAC21 24 41
Prepare to add 1 to the expenent (to thus multiply it by 2, which is then 10 times the original number). First, load Register Pair HL with the address of the exponent in the ACCumulator
0950
INC (HL)34
Increment the value of the exponent in the ACCumulator at the location of the memory pointer in Register Pair HL. ACCumulator now holds the original value times ten
0951
RET NZC0
Return if the new value in the ACCumulator is in an acceptable range
0952-0954
JP 07B2HJP OVERRC3 B2 07
Display an ?OV ERROR if the value of the exponent at the location of the memory pointer in Register Pair HL is too large

0955H-0963H – SINGLE PRECISION MATH ROUTINE – “SIGN”

Puts the SIGN of the ACCumulator into Register A. Only Register A is modified by this routine; the ACCumulator is left untouched.

To take advantage of the RST instructions to save bytes, FSIGN is defined to be an RST. “FSIGN” is equivalent to “call sign” the first few instructions of SIGN (the ones before SIGNC) are done in the 8 bytes at the RST location.
0955-0957
 ↳ SIGN
LD A,(4124H)LD A,(FAC)3A 24 41
Prepare to check to see if the number in the ACCumulator is ZERO by loading Register A with the value of the exponent in the ACCumulator
0958
OR AB7
Check to see if the exponent in Register A is equal to zero
0959
RET ZC8
Return if the single precision value in the ACCumulator is equal to zero
095A-095C
 ↳ SIGNC
LD A,(4123H)LD A,(FAC-1)3A 23 41
Load Register A with the SIGN of the ACCumulator
095D-095E
CP 2FHFE 2F
Z-80 Trick. If passing through, this will check the value of Register A and skip the next CPL instruction.
095F
 ↳ ICOMPS
RLA17
Put the value of the sign bit in Register A into the CARRY FLAG
0960
“SIGNS”
SBC A,A9F
If the CARRY FLAG is 0 (i.e., POSITIVE), then make Register A = 0. If the CARRY FLAG is 1 (i.e., NEGATIVE), make Register A = FFH
0961
RET NZC0
If the CARRY FLAG was 1, then the number is negative, and we want to RETurn
0962
 ↳ INRART
INC A3C
Increment the value in Register A so that Register A will be equal to 1 if the single precision value in the ACCumulator is positive
0963
RETC9
RETurn to CALLer

0964H-0976H – SINGLE PRECISION MATH ROUTINE – “FLOAT”

This routine will take a signed integer held in Register A and turn it into a floating point number. All registers are modified.
0964-0965
 ↳ FLOAT
LD B,88H06 88
Load Register B with an exponent for an integer value
0966-0968
LD DE,0000H11 00 00
Load Register Pair DE with zero
This routine will float the singed number in B/A/D/E. All registers are modified.
0969-096B
 ↳ FLOATR
LD HL,4124HLD HL,FAC21 24 41
Load Register Pair HL with the address of the exponent in the ACCumulator
096C
LD C,A4F
Load Register C with the High Order/MSB of the integer value
096D
LD (HL),B70
Save the exponent in Register B into the ACCumulator at the location of the memory pointer in Register Pair HL
096E-096F
LD B,00H06 00
Load Register B with zero to zero the overflow byte
0970
INC HL23
Increment the memory pointer in Register Pair HL to now point to the sign of the number in the ACCumulator
0971-0972
LD (HL),80H36 80
Assume a positive number by putting an 80H there
0973
RLA17
Shift the value of the sign bit into the CARRY FLAG
0974-0976
JP 0762HJP FADFLTC3 62 07
Jump to 0762H to float the number

0977H-0989H – LEVEL II BASIC ABS() ROUTINE – “ABS”

ABS routine (ACCumulator=ABS(ACCumulator)) input and output can be integer, single-precision or double-precision, depending on what is placed in the NTF (NTF=2, 4 or 8).
A call to 0977H converts the value in Working Register Area 1 (the ACCumulator) to its positive equivalent. The result is left in the ACCumulator. If a negative integer greater than 2** 15 is encountered, it is converted to a single precision value. The data type or mode flag (40AFH) will be updated to reflect any change in mode. All registers are modified.

NOTE: To use a ROM call to find ABS(X),store the value of X in 4121H-4122H (integer), in 4121H-4124H (single precision), or in 411DH and then H (double precision), and store the variable type (2, 4, or 8, respectively) in 40AFH. Then CALL 0977H. The result (in the same format as the input variable) is in the same locations in which the input variable was stored. If the input was an integer, the result is also in the HL Register Pair.

ABS routine (ACC=ABS(ACC)) input and output can be integer, single-precision or double-precision, depending on what is placed in the NTF (NTF=2, 4 or 8). (For a definition of NTF, see Part 2.)

Absolute Value: Converts the value in Working Register Area 1 (ACCumulator) to its positive equivalent. The result is left in the ACCumulator. If a negative integer greater than 2**15 is encountered, it is converted to a single precision value. The data type or mode flag (40AF) will be updated to reflect any change in mode
0977-0979
 ↳ ABS
CALL 0994HCALL VSIGNCD 94 09
GOSUB to VSIGN to get the SGN of the ACCumulator into Register A
097A
RET PF0
If that sign is POSITIVE, then I guess we are done, so just RETurn
This routine will negate any value in the ACCumulator. Every Register is affected.
097B
 ↳ VNEG
RST 20HGETYPEE7
We need to check the value of the current number type flag, so we call the TEST DATA MODE routine at RST 20H which determines the type of the current value in the ACCumulator and returns a combination of STATUS flags and unique numeric values in the register A according to the data mode flag (40AFH). The results are returned as follows:
Variable
Type
FlagsRegister A
IntegerNZ/C/M/E-1
StringZ/C/P/E0
Single PrecisionNZ/C/P/O1
Double PrecisionNZ/NC/P/E5
097C-097E
JP M,0C5BHJP M,INEGFA 5B 0C
If that test showed INTEGER, JUMP to 0C5BH to negate an integer
097F-0981
JP Z,0AF6HJP Z,TMERRCA F6 0A
If that test showed STRING, Display a ?TM ERROR message
This routine will negate the single or double precision number in the ACCumulator. Registers A, H, and L are affected.
  • To use this routine, the number must already be PACKed.
  • 0982-0984
     ↳ NEG
    LD HL,4123HLD HL,FAC-121 23 41
    Load Register Pair HL with the address of the MSB (which holds the SIGN bit) in the ACCumulator.
    0985
    LD A,(HL)7E
    Load Register A with the MSB (which holds the SIGN bit) in the ACCumulator at the location of the memory pointer in Register Pair HL
    0986-0987
    XOR 80HXOR 1000 0000EE 80
    Complement the sign bit in the MSB in Register A. Since we know the number is negative, this is really just switching it to positive.
    0988
    LD (HL),A77
    Save the adjusted MSB (which holds the SIGN bit) in Register A in the ACCumulator at the location of the memory pointer in Register Pair HL
    0989
    RETC9
    RETurn to CALLer

    098AH-0993H – LEVEL II BASIC SGN() ROUTINE – “SGN”

    SGN function (ACCumulator=SGN(ACCumulator)). After execution, NTF=2 and ACCumulator=-l, 0 or 1 depending on sign and value of ACC before execution. Registers A, H, and L are affected.

    NOTE: To use a ROM call to find SGN(X), store the value of X in 4121H-4122H (integer), in 4121H-4124H (single precision), or in, s-4124H (double precision) and then store the variable type (2, 4, or 8, respectively) in 40AFH and then CALL 098AH. The result (in integer format) is in 4121H-4122H and in the HL Register Pair.

    SGN function (ACC=SGN(ACC)). After execution, NTF=2 and ACC=-l, 0 or 1 depending on sign and value of ACC be fore execution. 0994 This routine checks the sign of the ACC. NTF must be set. After execution A register=00 if ACC=0, A=01 if ACC > 0 or A=FFH if A < 1. The Flags are also valid
    098A-098C
     ↳ SGN
    CALL 0994HCALL VSIGNCD 94 09
    Get the sign of the ACCumulator into Register A
    This routine will convert a signed number (held in Register A) into an integer.
    098D
     ↳ CONIA
    LD L,A6F
    Load Register L with the result of the sign test in Register A
    098E
    RLA17
    Shift the sign bit in Register A into the Carry flag
    098F
    SBC A,A9F
    Adjust the value in Register A so that it will be equal to zero if the current value in the ACCumulator is positive and equal to -1 if the current value in the ACCumulator is negative
    0990
    LD H,A67
    Save the adjusted value in Register A in Register H
    0991-0993
    JP 0A9AHJP MAKINTC3 9A 0A
    Jump to 0A9AH to return the result and set the VALTYP

    0994H-09A3H – LEVEL II BASIC MATH ROUTINE – “VSIGN”

    This routine checks the sign of the ACCumulator. NTF must be set. After execution A register=00 if ACCumulator=0, A=01 if ACC > 0 or A=FFH if A < 1. The Flags are also valid.
    0994
     ↳ VSIGN
    RST 20HGETYPEE7
    We need to check the value of the current number type flag, so we call the TEST DATA MODE routine at RST 20H which determines the type of the current value in the ACCumulator and returns a combination of STATUS flags and unique numeric values in the register A according to the data mode flag (40AFH). The results are returned as follows:
    Variable TypeFlagsRegister A
    IntegerNZ/C/M/E-1
    StringZ/C/P/E0
    Single PrecisionNZ/C/P/O1
    Double PrecisionNZ/NC/P/E5
    0995-0997
    JP Z,0AF6HJP Z,TMERRCA F6 0A
    If that test showed STRING, Display a ?TM ERROR message
    0998-099A
    JP P,0955HJP P,SIGNF2 55 09
    Since P means string, single precision, or double precision; and if it was a string it would have jumped already, this line says jump to 0955H if the current value in the ACCumulator is single precision or double precision, as those are processed the same way
    099B-099D
    LD HL,(4121H)LD HL,(FACLO)2A 21 41
    At this point, we know we have an integer. Load Register Pair HL with the integer value in the ACCumulator
    This routine finds the sign of the value held at (HL). Only Register A is altered.
    099E
     ↳ ISIGN
    LD A,H7C
    Load Register A with the MSB (which holds the SIGN bit) of the integer value in Register H
    099F
    OR LB5
    Check to see if the integer value in the ACCumulator is equal to zero
    09A0
    RET ZC8
    Return if the integer value in the ACCumulator is equal to zero
    09A1
    LD A,H7C
    If its not zero, then the sign of the number is the same as the sign of Register H so load Register A with the MSB (which holds the SIGN bit) of the integer value in Register H
    09A2-09A3
    JR 095FHJR ICOMPS18 BB
    Jump to 095FH to set Register A accordingly

    09A4H-09B0H – SINGLE PRECISION MATH ROUTINE – “PUSHF”

    Move ACCumulator To STACK: Moves the single precision value in the ACCumulator to the STACK. It is stored in LSB/MSB/Exponent order. Registers D and E are affected. Note, the mode flag is not tested by the move routine, it is simply assumed that ACCumulator contains a single precision value

    Loads Single-precision value from ACC to STACK ((SP)=ACC). To retrieve this value, POP BC followed by POP DE. A, BC and HL are unchanged by this function.
    09A4
     ↳ PUSHF
    EX DE,HLEB
    Preserve (HL) by swapping HL and DE
    09A5-09A7
    LD HL,(4121H)LD HL,(FACLO)2A 21 41
    Load Register Pair HL with the LSB and the NMSB of the single precision value in the ACCumulator
    09A8
    EX (SP),HLE3
    Swap (SP) and HL so that the return address is now in HL and the NMSB and the LSB of the single precision value are now at the top of the STACK
    09A9
    PUSH HLE5
    Save the return address in Register Pair HL on the STACK
    09AA-09AC
    LD HL,(4123H)LD HL,(FAC-1)2A 23 41
    Load Register Pair HL with the exponent and the High Order/MSB of the single precision value in the ACCumulator
    09AD
    EX (SP),HLE3
    Swap (SP) and HL so that the return address is now in HL and the MSB of the single precision value is now at the top of the STACK
    09AE
    PUSH HLE5
    Save the return address in Register Pair HL on the STACK
    09AF
    EX DE,HLEB
    Restore the original Register Pair HL from DE
    09B0
    RETC9
    RETurn to CALLer

    09B1H-09BEH – SINGLE PRECISION MATH ROUTINE – “MOVFM”

    This routine moves a number from memory (pointed to by HL) into the ACCumulator — (ACCumulator=(HL)). All registers except Register A are affected, with HL = HL + 4 on exit.
    09B1-09B3
     ↳ MOVFM
    CALL 09C2HCALL MOVRMCD C2 09
    Load the SINGLE PRECISION value pointed to by Register Pair HL into Register Pairs BC/DE via a CALL to 09C2H Then fall into the MOVFR routine.
    This routine loads the ACC with the contents of the BC and DE Register Pairs. (ACC=BCDE). Only Registers D and E are modified.

    Move SP Value In BC/DC Into ACCumulator: Moves the single precision value in BC/DE into ACCumulator. HL is destroyed BC/DE is left intact. Note – the mode flag is not updated!
    09B4
     ↳ MOVFR
    EX DE,HLEB
    Load Register Pair HL with the NMSB and the LSB of the single precision value in Register Pair DE.
    09B5-09B7
    LD (4121H),HLLD (FACLO),HL22 21 41
    Save the NMSB and the LSB of the single precision value into the ACCumulator (at the locations pointed to by Register Pair HL)
    09B8
    LD H,B60
    Let HL = BC (so the High Orders/MSB + Exponent) … part 1 …
    09B9
    LD L,C59
    … part 2
    09BA-09BC
    LD (4123H),HLLD (FAC-1),HL22 23 41
    Save the exponent and the MSB of the single precision value into the ACCumulator pointed to by Register Pair HL
    09BD
    EX DE,HLEB
    Restore the original HL from DE
    09BE
    RETC9
    RETurn to CALLer

    09BF-09CA – SINGLE PRECISION MATH ROUTINE
    “LDRASA”

    • This routine is the opposite of the 09B4H routine. It loads four bytes from REG 1 (single-precision) into the BC and DE register pairs. (BCDE=ACC). A is unchanged.
    • Move FAC to registers (B,C,D,E). Alters B,C,D,E,H,L
    09BF-09C1
    Load register pair HL with the starting address for a single precision value in REG 1.
    09C2
     ↳ MOVRM
    LD E,(HL)5E
    Load Register E with the LSB of the single precision value in the ACCumulator at the location of the memory pointer in Register Pair HL.

    This routine will load the BCDE Register Pairs with four bytes from the location pointed to by HL. (BCDE=(HL)). With these types of data movements, the E Register is loaded with the LSB and the B register. with the MSB
    09C3
    INC HL23
    Increment the value of the memory pointer in Register Pair HL to point to the middle order/NMSB number
    09C4
     ↳ GETBCD
    LD D,(HL)56
    Load Register D with the NMSB of the single precision value in the ACCumulator at the location of the memory pointer in Register Pair HL
    09C5
    INC HL23
    Increment the value of the memory pointer in Register Pair HL to point to the high order/MSB number
    09C6
    LD C,(HL)4E
    Load Register C with the MSB of the single precision value in the ACCumulator at the location of the memory pointer in Register Pair HL
    09C7
    INC HL23
    Increment the value of the memory pointer in Register Pair HL to point to the exponent
    09C8
    LD B,(HL)46
    Load Register B with the exponent of the single precision value in the ACCumulator at the location of the memory pointer in Register Pair HL
    09C9
     ↳ INXHRT
    INC HL23
    Increment the value of the memory pointer in Register Pair HL so that it points to the beginning of the next number
    09CA
    RETC9
    RETurn to CALLer

    09CBH-09D1H – SINGLE PRECISION MATH ROUTINE – “MOVMF”

    This routine is the opposite of the 09B1H routine. It loads the number from the ACCumulator to the memory location pointed to by HL. ((HL)=ACC). Modifies all Registers except for Register C
    09CB-09CD
     ↳ MOVMF
    LD DE,4121HLD DE,FACLO11 21 41
    Load Register Pair DE with the starting address for a single precision value in the ACCumulator. Then pass throgh to the following routine.
    Data move routine. This moves four bytes from the location pointed to by DE into the location pointed to by HL. ((HL)=(DE)). Modifies all Registers except for Register C
    09CE-09CF
     ↳ MOVE
    LD B,04H06 04
    Load Register B with the number of bytes to be moved for a single precision value so that B will act as a counter.
    09D0-09D1
    JR 09D7HJR MOVE118 05
    Jump to 09D7H (which is the GENERAL PURPOSE MOVE routine and moves the contents of the B Register Bytes from the address in DE to the address in HL)

    09D2H-09DEH – MOVE VALUE POINTED TO BY HL TO THE LOCATION POINTED TO BY DE – “MOVVFM”

    This is the VARIABLE MOVE routine which moves the number of bytes specified in the variable type flag (40AFH) from the address in DE to the address in HL. Uses A, B, DE and HL.

    Data move routine. The location pointed to by DE is loaded with bytes from the location pointed to by HL. The number of bytes moved is determined by the value in the NTF. ((DE)=(HL))
    09D2
     ↳ MOVVFM
    EX DE,HLEB
    Exchange the value in Register Pair HL with the value in Register Pair DE, and then fall through to the VMOVE routine.
    This routine is similar to 9D2H above. The only difference is that it moves data in the opposite direction. ((HL) = (DE))
    09D3-09D5
     ↳ VMOVE
    LD A,(40AFH)LD A,(VALTYP)3A AF 40
    Load Register A with the current value of the number type flag (which is in 40AFH). This, not coincidentally, is also the length of the number being worked on!
    09D6
    LD B,A47
    Load Register B with the number of bytes to be moved in Register A.
    This routine is the same as 9D6H except that the number of bytes shifted is determined by the value in the B Register ((HL)=(DE))
  • Moves contents of B-register bytes from the address in DE to the address given in HL. Uses all registers except C
  • 09D7
     ↳ MOVE1
    LD A,(DE)1A
    Top of a loop to move (DE)’s content into (HL). First, load Register A with the value at the location of the memory pointer in Register Pair DE.

    This routine is the same as 9D6H except that the number of bytes shifted is determined by the value in the B Register ((HL)=(DE)).
    This is the GENERAL PURPOSE MOVE routine and moves the contents of the B Register Bytes from the address in DE to the address in HL)
    09D8
    LD (HL),A77
    and then Save the value in Register A at the location of the memory pointer in Register Pair HL
    09D9
    INC DE13
    Increment the value of the memory pointer in Register Pair DE
    09DA
    INC HL23
    Increment the value of the memory pointer in Register Pair HL
    09DB
    DEC B05
    Decrement the value of the byte counter in Register B
    09DC-09DD
    JR NZ,09D7HJR NZ,MOVE120 F9
    Loop until all of the bytes have been moved
    09DE
    RETC9
    RETurn to CALLer

    09DFH-09F3H – SINGLE PRECISION MATH ROUTINE – “UNPACK”

    This routine “UNPACKS” the ACCumulator and the Registers. Registers A, C, H, and L are altered.

    When the number in the ACCumulator is unpacked, the assumed one in the mantissa is restored, and the complement of the sign is placed in ACCumulator+1.
    09DF-09E1
     ↳ UNPACK
    LD HL,4123HLD HL,FAC-121 23 41
    Load Register Pair HL with the address of the MSB (including the SIGN) of the value in the ACCumulator
    09E2
    LD A,(HL)7E
    Load Register A with the MSB (and SIGN) of the value in the ACCumulator at the location of the memory pointer in Register Pair HL
    09E3
    RLCA07
    Duplicate the sign into the CARRY and the LSB
    09E4
    SCF37
    Set the Carry flag to restore the hidden “1” for the mantissa
    09E5
    RRA1F
    Turn off the sign bit in Register A by moving the value of the Carry flag into Register A and moving the previous value of the sign bit from bit 0 of Register A into the Carry flag. RRA rotates the contents of Register A right one bit position, with Bit 0 going to the CARRY FLAG, and the CARRY FLAG going to Bit 7. RRA also can be used to divide a number in 2.
    09E6
    LD (HL),A77
    Save the adjusted High Order/MSB+Sign in Register A in the ACCumulator at the location of the memory pointer in Register Pair HL
    09E7
    CCF3F
    Invert the value of the sign bit in the Carry flag
    09E8
    RRA1F
    Move the inverted sign bit from the Carry flag into Register A. RRA rotates the contents of Register A right one bit position, with Bit 0 going to the CARRY FLAG, and the CARRY FLAG going to Bit 7. RRA also can be used to divide a number in 2.
    09E9
    INC HL
    INC HL23
    Increment the value of the memory pointer in Register Pair HL twice to now point to the temporary sign byte
    09EB
    LD (HL),A77
    Save the complemented sign (in Register A) to the location of the memory pointer in Register Pair HL
    09EC
    LD A,C79
    Load Register A with the MSB+SIGN of the single precision value in Register C
    09ED
    RLCA07
    Duplicate the sign in both the CARRY FLAG and the LSB
    09EE
    SCF37
    Set the Carry flag to restore the hidden “1” for the mantissa
    09EF
    RRA1F
    Restore the High Order (MSB+Sign) in A. RRA rotates the contents of Register A right one bit position, with Bit 0 going to the CARRY FLAG, and the CARRY FLAG going to Bit 7. RRA also can be used to divide a number in 2.
    09F0
    LD C,A4F
    Load Register C with the adjusted High Order (MSB+Sign) in Register A
    09F1
    RRA1F
    Move the value of the sign bit from the Carry flag into Register A. RRA rotates the contents of Register A right one bit position, with Bit 0 going to the CARRY FLAG, and the CARRY FLAG going to Bit 7. RRA also can be used to divide a number in 2.
    09F2
    XOR (HL)AE
    Combine the value of the sign bit of the ACCUMULATOR and the SIGN BIT of the Registers
    09F3
    RETC9
    RETurn to CALLer

    09F4H-09FBH – LEVEL II BASIC MATH ROUTINE – “VMOVFA”

    This routine moves a number of bytes (the number depending on the value stored in the VALTYPE) from (HL) to the ACCumulator. All Registers except C are affected.
    09F4-09F6
     ↳ VMOVFA
    LD HL,4127HLD HL,ARGLO21 27 41
    This is the entry point from the DADD routine. To facilitate, we need to set HL to point to ARG (a/k/a REG 2)) instead of the ACCumulator
    09F7-09F9
     ↳ VMOVFM
    LD DE,09D2HLD DE,MOVVFM11 D2 09
    Load Register Pair DE with the return address of the routine that does an exchange and then falls into the MOVE1 routine.
    09FA-09FB
    JR 0A02HJR VMVVFM18 06
    Jump to 0A02

    09FCH-0A0BH – LEVEL II BASIC MATH ROUTINE – “VMOVAF”

    This is the opposite of 9F4H. This routine moves a number of bytes (the number depending on the value stored in the VALTYPE) from the ACCumulator to (HL). All Registers except C are affected.
    09FC-09FE
     ↳ VMOVAF
    LD HL,4127HLD HL,ARGLO21 27 41
    Entered here from FIN, DMUL10, and DDIV10. They require that Register Pair HL to point to ARG (a/k/a REG 2) instead of the ACCumulator
    09FF-0A01
     ↳ VMOVMF
    LD DE,09D3HLD DE,VMOVE11 D3 09
    When entered from here, we need to load Register Pair DE with the return address of the MOVE routine.
    0A02
     ↳ VMVVFM
    PUSH DED5
    When entered here, save Register Pair DE (which, if passed through, is a return address) on the STACK
    0A03-0A05
     ↳ VDFACS
    LD DE,4121HLD DE,FACLO11 21 41
    Entered here from INT, STR, and SNG. In that case, we must load Register Pair DE with the starting address for a single precision value in the ACCumulator
    0A06
    RST 20HGETYPEE7
    We need to check the value of the current number type flag, so we call the TEST DATA MODE routine at RST 20H which determines the type of the current value in the ACCumulator and returns a combination of STATUS flags and unique numeric values in the register A according to the data mode flag (40AFH). The results are returned as follows:
    Variable TypeFlagsRegister A
    IntegerNZ/C/M/E-1
    StringZ/C/P/E0
    Single PrecisionNZ/C/P/O1
    Double PrecisionNZ/NC/P/E5
    0A07
    RET CD8
    If that test is anything other than double precision, return out of this subroutine to the address which was fed in
    0A08-0A0A
    LD DE,411DHLD DE,DFACLO11 1D 41
    If we are here, then we have a double precision number, so set Register Pair DE to point to the the LSB of a double precision number.
    0A0B
    RETC9
    RETurn to the place we set up to return to

    0A0CH-0A25H – SINGLE PRECISION COMPARE – “FCOMP”

    According to the original ROM source code, this routine will compare two single precision numbers. On Exit, A=1 if ARG < ACCumulator, A=0 if ARG=Accmulator, and A=-1 if ARG > ACCumulator. This routine exits with the CARRY FLAG on. Alters Registers A, H, and L.

    Single-precision compare. Compares ACCumulator with the contents of BCDE registers. After execution of this routine, the A Register will contain: A=0 if ACCumulator=BCDE, A=1 if ACC>BCDE or A=FFH if ACC<BCDE.

    Single Precision Comparison: Algebraically compares the single precision value in (BC/DE) to the single precision value ACCumulator. The result of the comparison is returned in the A and status as: IF (BC/DE) > ACCumulator A = -1, IF (BC/DE) < ACCumulator A = +1, IF (BC/DE) = ACCumulator A = 0

    NOTE: To use a ROM call to compare two single precision numbers, store the first input in registers BCDE, the second input in 4121H-4124H and then CALL 0A0CH. If the numbers are equal, the Z (zero) flag will be set. If they are not equal, the Z flag will be turned off. If the first input number is the smaller, the S (sign) and C (carry) flags will also be turned off. If the second input number is the smaller, the S and C flags will both be set.

    0A0C
     ↳ FCOMP
    LD A,B78
    First we need to check to see if ARG is zero, so load Register A with the value of the exponent in Register B
    0A0D
    OR AB7
    Set the flags based on Register A
    0A0E-0A10
    JP Z,0955HJP Z,SIGNCA 55 09
    If the exponent in Register A is equal to zero, then JUMP to SIGN
    0A11-0A13
    LD HL,095EHLD HL,FCOMPS21 5E 09
    Set up the destination address to use on a RETurn by first loading Register Pair HL with the address to the FCOMPS routine
    0A14
    PUSH HLE5
    Save the return address in Register Pair HL on the STACK
    0A15-0A17
    CALL 0955HCALL SIGNCD 55 09
    Check to see if the ACCumulator is zero via a GOSUB to SIGN
    0A18
    LD A,C79
    If the ACCumulator is ZERO, then the result is simply the NEGative of ARG, so, to prepare for that, load Register A with the MSB of the single precision value in Register C
    0A19
    RET ZC8
    If the ACCumulator was zero, RETurn with Register A holding Register C
    0A1A-0A1C
    LD HL,4123HLD HL,FAC-121 23 41
    Load Register Pair HL with the address of the MSB+SIGN in Register A
    0A1D
    XOR (HL)AE
    Check to see if the signs of the ACCumulator and the ARG are the same via a XOR
    0A1E
    LD A,C79
    If they are different, then the result of that XOR will be the sign of the number in ARG, so load Register A with the MSB+SIGN of Register C
    0A1F
    RET MF8
    If the signs are different, RETurn
    0A20-0A22
    CALL 0A26HCALL FCOMP2CD 26 0A
    Now that we have resolved the signs, JUMP to FCOMP2 to check the rest of the numbers
    0A23
     ↳ FCOMPD
    RRA1F
    If are are here, then the numbers are different, so the next step is to change the signs if both numbers are negative. To do this, first move the value of the Carry flag from the comparison into Register A. RRA rotates the contents of Register A right one bit position, with Bit 0 going to the CARRY FLAG, and the CARRY FLAG going to Bit 7. RRA also can be used to divide a number in 2.
    0A24
    XOR CA9
    Combine the value of the MSB/SIGN of the single precision value in Register C with the value in Register A
    0A25
    RETC9
    With Register A now set, RETurn to CALLer

    0A26H-0A38H – Part of the SINGLE PRECISION COMPARISON ROUTINE – “FCOMP2”

    0A26
    INC HL23
    Increment the value of the memory pointer in Register Pair HL so that it points to the exponent of the single precision number in the ACCumulator
    0A27
    LD A,B78
    Load Register A with the value of the exponent for the single precision value held in ARG (stored in Register B)
    0A28
    CP (HL)BE
    Check to see if the exponent for the single precision value in the ACCumulator at the location of the memory pointer in Register Pair HL is the same as the value of the exponent for the single precision value in Register A
    0A29
    RET NZC0
    If the value of the exponent for the single precision number in the ACCumulator isn’t the same as the value of the exponent for the single precision number in ARG (held in Register A), RETurn
    0A2A
    DEC HL2B
    Decrement the value of the memory pointer in Register Pair HL so it now will point to the HIGH ORDER/MSB of the single precision number in the ACCumulator
    0A2B
    LD A,C79
    Load Register A with the HIGH ORDER/MSB of the single precision number in ARG (stored in Register C)
    0A2C
    CP (HL)BE
    Check to see if the HIGH ORDER/MSB for the single precision value in the ACCumulator at the location of the memory pointer in Register Pair HL is the same as the value of the MSB for the single precision value in Register A
    0A2D
    RET NZC0
    If the value of the HIGH ORDER/MSB for the single precision number in the ACCumulator isn’t the same as the value of the HIGH ORDER/MSB for the single precision number in ARG (held in Register A), RETurn
    0A2E
    DEC HL2B
    Decrement the value of the memory pointer in Register Pair HL so it now will point to the MIDDLE ORDER/NMSB of the single precision number in the ACCumulator
    0A2F
    LD A,D7A
    Load Register A with the MIDDLE ORDER/NMSB of the single precision number in ARG (stored in Register D)
    0A30
    CP (HL)BE
    Check to see if the MIDDLE ORDER/NMSB for the single precision value in the ACCumulator at the location of the memory pointer in Register Pair HL is the same as the value of the MIDDLE ORDER/NMSB for the single precision value in Register A
    0A31
    RET NZC0
    If the value of the MIDDLE ORDER/NMSB for the single precision number in the ACCumulator isn’t the same as the value of the MIDDLE ORDER/NMSB for the single precision number in ARG (held in Register A), RETurn
    0A32
    DEC HL2B
    Decrement the value of the memory pointer in Register Pair HL so it now will point to the LOW ORDER/LSB of the single precision number in the ACCumulator
    0A33
    LD A,E7B
    Load Register A with the LOW ORDER/LSB of the single precision number in ARG (stored in Register E)
    0A34
    SUB (HL)96
    Use subtraction to check to see if the LOW ORDER/LSB for the single precision value in the ACCumulator at the location of the memory pointer in Register Pair HL is the same as the value of the LOW ORDER/LSB for the single precision value in Register A. We use subtraction so that if the numbers are the same then Register A will be filled with the 0 response.
    0A35
    RET NZC0
    Return if the value of the LSB in the ACCumulator isn’t the same as the value of the LSB in Register A
    0A36
    POP HLE1
    If we are here then the numbers are the same so we need to get the extra data off of the STACK
    0A37
    POP HLE1
    Clear the stack
    0A38
    RET
    Return to Caller

    0A39H-0A48H – INTEGER COMPARISON ROUTINE
    – “ICOMP”

    According to the original ROM source code, this routine will compare two integers. On Exit, A=1 if (DE) < (HL), A=0 if (DE)=(HL), and A=-1 if (DE) > (HL). Alters only Register A.

    Integer compare. Compares HL with DE. After execution, A=0 if HL=DE, A=1 if HL>DE or A=FFH if HL<DE. The S and Z flags are valid.

    NOTE: To use a ROM call to compare two integers, store the first input in DE, the second in HL and then CALL 0A39H. If the numbers are equal, the Z (zero) flag will be set. If they are not equal, the Z flag will be turned off. If the first input number is the smaller, the S (sign) and C (carry) flags will also be turned off. If the second input number is the smaller, the S and C flags will both be set.

    Compares HL with DE. After execution, A=0 if HL=DE, A=1 if HL>DE or A=FFH if HL<DE. The S and Z flags are valid

    Algebraically compares two integer values in DE and HL. The contents of DE and HL are left intact. The result of the comparison is left in the A Register and status register: If DE > HL A = -1, IF DE < HL A = +1, IF DE = HL A = 0

    0A39
     ↳ ICOMP
    LD A,D7A
    First we test the signs, so load Register A with the SIGN of the integer value in Register D
    0A3A
    XOR HAC
    Check to see if the sign bit for the MSB of the integer value in Register H is the same as the sign bit for the SIGN for the integer value in Register A
    0A3B
    LD A,H7C
    If the signs are NOT the same, then the result is the sign of (HL), so put the SIGN of the number in (HL) into the response register of Register A.
    0A3C-0A3E
    JP M,095FHJP M,ICOMPSFA 5F 09
    If the sign bits are NOT the same, JUMP to ICOMPS to check the numbers
    0A3F
    CP DBA
    If we are here, then the signs are the same, so now check to see if the HIGH ORDER/MSB for the integer value in Register D is the same as the HIGH ORDER/MSB for the integer value in Register A
    0A40-0A42
    JP NZ,0960HJP NZ,SIGNSC2 60 09
    if the HIGH ORDER/MSB for the integer value in Register D isn’t the same as the HIGH ORDER/MSB for the integer value in Register A, JUMP to SIGNS to set up the appropriate response in Register A
    0A43
    LD A,L
    Load register A with the LSB of the integer value in register L.
    0A44
    SUB E93
    Use subtraction to check to see if the LOW ORDER/LSB for the integer value in Register E is the same as the LOW ORDER/LSB for the integer value in Register A
    0A45-0A47
    JP NZ,0960HJP NZ,SIGNSC2 60 09
    If the LSB for the integer value in Register E isn’t the same as the LSB for the integer value in Register A, JUMP to SIGNS to set up the appropriate response in Register A
    0A48
    RETC9
    If we are here, then two things. First, they are the same. Second, A is zero. So RETurn to CALLer
    0A49-0A4B
     ↳ DCOMPD
    LD HL,4127HLD HL,ARGLO21 27 41
    Load Register Pair HL with the starting address of ARG (a/k/a REG 2). If entering here, then (DE) already needs to be set with the pointer to ARG.
    Note: 4127H-412EH holds ARG (a/k/a REG 2)
    0A4C-0A4E
    CALL 09D3HCALL VMOVECD D3 09
    Go move the double precision value pointed to by Register Pair DE to ARG (a/k/a REG 2)
    0A4F-0A51
     ↳ XDCOMP
    LD DE,412EHLD DE,ARG11 2E 41
    Load Register Pair DE with the address of the exponent in ARG (a/k/a REG 2)
    0A52
    LD A,(DE)1A
    Load Register A with the exponent for the double precision value in ARG (a/k/a REG 2) at the location of the memory pointer in Register Pair DE
    0A53
    OR AB7
    Check to see if the double precision value in ARG (a/k/a REG 2) is equal to zero
    0A54-0A56
    JP Z,0955HJP Z,SIGNCA 55 09
    If the double precision value in ARG (a/k/a REG 2) is equal to zero, then we are done, so JUMP to SIGN to set up Register A with the appropriate response.
    0A57-0A59
    LD HL,095EHLD HL,FCOMPS21 5E 09
    Load Register Pair HL with a return address to the FCOMPS routine
    0A5A
    PUSH HLE5
    Save the return address in Register Pair HL on the STACK
    0A5B-0A5D
    CALL 0955HCALL SIGNCD 55 09
    Go check to see if the double precision value in the ACCumulator is equal to zero
    0A5E
    DEC DE1B
    Decrement the value of the memory pointer in Register Pair DE so that DE now points to the MSB+SIGN of the number in ARG (a/k/a REG 2)
    0A5F
    LD A,(DE)1A
    Load Register A with the MSB+SIGN of the double precision value in ARG (a/k/a REG 2) at the location of the memory pointer in Register Pair DE
    0A60
    LD C,A4F
    Presetve the MSB+SIGN of the double precision value in ARG (a/k/a REG 2) into Register C
    0A61
    RET ZC8
    If the number in the ACCumulator = 0, then the sign of the result is the sign of ARG, so RETurn wto FCOMPS
    0A62-0A64
    LD HL,4123HLD HL,FAC-121 23 41
    Load Register Pair HL with the address of the SIGN of the double precision value in the ACCumulator
    0A65
    XOR (HL)AE
    Check to see if the sign bit the double precision value in the ACCumulator at the location of the memory pointer in Register Pair HL is the same as the sign bit of the double precision value in ARG (a/k/a REG 2) in Register A
    0A66
    LD A,C79
    In case they are the same, get the sign from C into Register A.
    0A67
    RET MF8
    If they are NOT the same, RETurn to FCOMPS to set set Register A
    0A68
    INC DE13
    Increment the value of the memory pointer in Register Pair DE so that DE now points to the exponent of ARG
    0A69
    INC HL23
    Increment the value of the memory pointer in Register Pair HL so that HL now points to the exponent of the ACCumulator
    0A6A-OA6B
    LD B,08H06 08
    Load Register B with the number of bytes to be compared, as B will act as a counter
    0A6C
     ↳ DCOMP1
    LD A,(DE)1A
    Load Register A with a byte from the double precision number in ARG (pointed to by Register Pair DE)
    0A6D
    SUB (HL)96
    Use subtraction to compare that byte from ARG with the correspondible byte from the ACCumulator (pointed to by Register Pair HL)
    0A6E-0A70
    JP NZ,0A23HJP NZ,FCOMPDC2 23 0A
    If the NZ is set, then the numbers are different o JUMP to FCOMPD to set up Register A
    0A71
    DEC DE1B
    If we are here, then they are the same, so we need to move to the next byte of ARG (so decrement the value of the memory pointer in Register Pair DE)
    0A72
    DEC HL2B
    and the next byte of the ACCumulator (so decrement the value of the memory pointer in Register Pair HL)
    0A73
    DEC B05
    and to decrease the byte counter (so Decrement the number of bytes remaining to be compared in Register B)
    0A74-0A75
    JR NZ,0A6CHJR NZ,DCOMP120 F6
    The DEC of B will set the flags. If B is NOT ZERO, then Loop back to DCOMP1 until all of the bytes have been compared
    0A76
    POP BCC1
    If we are here, then the numbers are the same, so we need to clean the RETurn to FCOMPS off the stack, as that is not where we want to RETurn to
    0A77
    RETC9
    RETurn to the actual CALLer

    0A78H-0A7EH – DOUBLE PRECISION COMPARE – “DCOMP”

    According to the original ROM source code, this routine will compare two double precision numbers, but is the opposite of the ICOMP, FCOMP, and XDCOMP routines. This one swaps ARC and ACC, so on Exit, A=1 if ARG > ACCumulator, A=0 if ARG=Accmulator, and A=-1 if ARG < ACCumulator. Every register is affected.

    Double-precision compare. This compare is the opposite of the A4FH compare. It compares the ARG (a/k/a REG 2) with the ACC. (Remember that a compare is actually a subtraction that is never executed therefore a compare can be done in two ways with the same values. (A-B and B-A)). The results are the same as the A4FH routine.

    Double Precision Compare: Compares the double precision value in the ACCumulator to the value in ARG (a/k/a REG 2). Both Register areas are left intact. The result of the comparison is left in the A and status registers as: IF ACCumulator > ARG (a/k/a REG 2) A = -1, IF ACCumulator < ARG (a/k/a REG 2) A = +1, IF ACCumulator = ARG (a/k/a REG 2) A = 0

    NOTE: To use a ROM call to compare two double precision number, store the first input in 411DH-4124H, and store the second input in 4127H-412EH and then CALL 0A78H. If the numbers are equal, the Z (zero) flag will be set. If they are not equal, the Z flag will be turned off. If the first input number is the smaller, the S (sign) and C (carry) flags will also be turned off. If the second input number is the smaller, the S and C flags will both be set.
    0A78-0A7A
     ↳ DCOMP
    CALL 0A4FHCALL XDCOMPCD 4F 0A
    GOSUB to compare the double precision value in ARG (a/k/a REG 2) to the double precision value in the ACCumulator
    0A7B-0A7D
    JP NZ,095EHJP NZ,FCOMPSC2 5E 09
    If the double precision value in the ACCumulator and the double precision value in ARG (a/k/a REG 2) aren’t the same then JUMP to FCOMPS to negate the answer and set up the CARRY FLAG for the DOCMP routine
    0A7E
    RETC9
    RETurn to CALLer

    0A7FH-0AB0H – LEVEL II BASIC CINT ROUTINE – “FRCINT”

    CINT routine. Takes a value from ACC, converts it to an integer value and puts it back into the ACC. On completion, the HL Register Pair contains the LSB of the integer value, and the NTF contains 2 (Integer=2). If NTF=3 (string) a TM ERROR will be generated and control will be passed to BASIC. Every register is affected. No rounding is performed

    NOTE: To use a ROM call to call the CINT routine, store the single precision input variable in 4121H-4124H and then call to 0A8AH and bypass all the foregoing. After the call, the integer result would be in 4121H-4122H and in the HL Register Pair. Too big a number will generate a ?OV Error.
    0A7F
     ↳ FRCINT
    RST 20HGETYPEE7
    We need to check the value of the current number type flag, so we call the TEST DATA MODE routine at RST 20H which determines the type of the current value in the ACCumulator and returns a combination of STATUS flags and unique numeric values in the register A according to the data mode flag (40AFH). The results are returned as follows:
    Variable TypeFlagsRegister A
    IntegerNZ/C/M/E-1
    StringZ/C/P/E0
    Single PrecisionNZ/C/P/O1
    Double PrecisionNZ/NC/P/E5
    0A80-0A82
    LD HL,(4121H)LD HL,(FACLO)2A 21 41
    Just in acse we already have an integer, Load Register Pair HL with the integer value in the ACCumulator (which is stored at FACLO and FACLO+1)
    0A83
    RET MF8
    If that test showed we have an INTEGER, then return out of this subroutine
    0A84-0A86
    JP Z,0AF6HJP Z,TMERRCA F6 0A
    If that test showed we have a STRING, Display a ?TM ERROR message
    0A87-0A89
    CALL NC,0AB9HCALL NC,CONSDD4 B9 0A
    If that test shows we have DOUBLE PRECISION, call 0AB9H to convert the number to single precision
    0A8A-0A8C
    LD HL,07B2HLD HL,OVERR21 B2 07
    Just in case the number is too big, pre-load HL with the RETurn address to the ?OV ERROR routine
    0A8D
    PUSH HLE5
    Save the return address in Register Pair HL on the STACK and fall into the “CONIS” routine to continue.

    0A8EH – LEVEL II BASIC CONVERSION ROUTINE – “CONIS”

    This routine will convert a single precision number to an integer. Every register is affected.
    0A8E-0A90
     ↳ CONIS
    LD A,(4124H)LD A,(FAC)3A 24 41
    Load Register A with the exponent for the single precision value in the ACCumulator
    0A91-0A92
    CP 90HFE 90
    Check to see if the exponent for the single precision value in the ACCumulator in Register A indicates more than 16 bits of precision
    0A93-0A94
    JR NC,0AA3HJR NC,CONIS230 0E
    If the exponent for the single precision value in the ACCumulator in Register A indicates more than 16 bits of precision, JUMP to CONIS2 to make sure that the reason it is “too big” isn’t because it is -32768
    0A95-0A97
    CALL 0AFBHCALL QINTCD FB 0A
    If we are here then the number isn’t too big, so GOSUB to QINT to convert the single precision value in the ACCumulator to an integer and return with the integer value in Register Pair DE
    0A98
    EX DE,HLEB
    Load Register Pair HL with the integer value that was put into Register Pair DE by QINT
    0A99
     ↳ CONIS1
    POP DED1
    Get the error address from the STACK and put it in Register Pair DE

    0A9AH – LEVEL II BASIC CONVERSION ROUTINE – “MAKINT”

    This is the routine that returns the value in the HL Register Pair to the BASIC program that called it. In effect it moves the content of HL into the ACCumulator so it is ACCumulator = (HL) with VALTYPE set accordingly
    0A9A-0A9C
     ↳ MAKINT
    LD (4121H),HLLD (FACLO),HL22 21 41
    Save the integer value in Register Pair HL as the current value in the ACCumulator.
    0A9D-0A9E
     ↳ VALINT
    LD A,02H3E 02
    Load Register A with an integer number type flag.
    0A9F-0AA1
     ↳ CONISD
    LD (40AFH),ALD (VALTYP),A32 AF 40
    Save the integer number type flag in Register A as the current value of the number type flag.
    Note: 40AFH holds Current number type flag. This is the entry point from the CONDS routine
    0AA2
    RETC9
    RETurn to CALLer

    0AA3H – LEVEL II BASIC CONVERSION ROUTINE – “CONIS2”

    0AA3-0AA5
     ↳ CONIS2
    LD BC,9080H01 80 90
    This routine’s purpose is to check to see if a number from the FIN routine is -32768. First, load up the register paird BCDE with 9080H/0000H for purposes of using FCOMP to test
    0AA6-0AA8
    LD DE,0000H11 00 00
    Load Register Pair DE with the NMSB and the LSB of a single precision value. Register Pairs BC and DE now hold a single precision value equal to -32768
    0AA9-0AAB
    CALL 0A0CHCALL FCOMPCD 0C 0A
    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 ACCumulator.
    The results are stored in A as follows:
    • A=0 if ACCumulator = BCDE
    • A=1 if ACCumulator>BCDE; and
    • A=FFH if ACCumulator<BCDE.
    0AAC
    RET NZC0
    If FCOMP returns a NZ, then there was an error and the number could NOT be converted into an integer. In this case, display an ?OV ERROR
    0AAD
    LD H,C61
    If we are here, then the value is -32768, so we need to put that into (HL). First, load Register H with the MSB of the single precision value in Register C
    0AAE
    LD L,D6A
    Load Register L with the NMSB of the single precision value in Register D
    0AAF-0AB0
    JR 0A99HJR CONIS118 E8
    Jump to 0A99H to store (HL) into the ACCumulator and set the VALTYPE accordingly.

    0AB1H-0ACBH – LEVEL II BASIC CSNG ROUTINE – “FRCSNG”

    Force the number in the ACCumulator to be a single-precision number. Every register is affected.

    CSNG routine. Takes value from ACC and converts it to single-precision. The result is put in ACC and NTF contains 4.

    CSNG routine. Takes value from ACC and converts it to single-precision. The result is put in ACC and NTF contains 4

    Integer To Single: The contents of ACCumulator are converted from integer or double precision to single precision. All registers are used

    0AB1
     ↳ FRCSNG
    RST 20HGETYPEE7
    We need to check the value of the current number type flag, so we call the TEST DATA MODE routine at RST 20H which determines the type of the current value in the ACCumulator and returns a combination of STATUS flags and unique numeric values in the register A according to the data mode flag (40AFH). The results are returned as follows:
    Variable TypeFlagsRegister A
    IntegerNZ/C/M/E-1
    StringZ/C/P/E0
    Single PrecisionNZ/C/P/O1
    Double PrecisionNZ/NC/P/E5
    0AB2
    RET POE0
    IF PO is set, then we have SINGLE PRECISION number already, so nothing to do! RETurn out of this subroutine
    0AB3-0AB5
    JP M,0ACCHJP M,CONSIFA CC 0A
    If that test shows we have an INTEGER, jump to 0ACCH to convert it
    0AB6-0AB8
    JP Z,0AF6HJP Z,TMERRCA F6 0A
    If that test shows we have a STRING, display a ?TM ERROR. Otherwise, fall into the DOUBLE PRECISION routine, located just after to avoid a JUMP to it.

    0AB9 – LEVEL II BASIC NUMBER CONVERSION ROUTINE – “CONSD”

    Convert a double-prevision number to single-precision. Every register is affected.
    0AB9-0ABB
     ↳ CONSD
    CALL 09BFHCALL MOVRFCD BF 09
    Move the HIGH ORDER/MSB’s into the registers via a call to MOVRF which loads the SINGLE PRECISION value in the ACCumulator (which is currently the most significant four bytes of the double precision value in the ACCumulator) into Register Pair BC/DE
    0ABC-0ABE
    CALL 0AEFHCALL VALSNGCD EF 0A
    Go set the current number type flag to single precision
    0ABF
    LD A,B78
    Next we need to see if the number is zero, so load Register A with the exponent of the double precision value in Register B
    0AC0
    OR AB7
    Check to see if the exponent in the ACCumulator is equal to zero
    0AC1
    RET ZC8
    If the exponent is zero, then the number is zero, so RETurn
    0AC2-0AC4
    CALL 09DFHCALL UNPACKCD DF 09
    We now know the number isn’t zero, so we need to unpack the number via a CALL to UNPACK which will turn on the most significant bit of the single precision value in the ACCumulator
    0AC5-0AC7
    LD HL,4120HLD HL,FACLO-121 20 41
    Load Register Pair HL with the address of the first byte below a single-prevision value (i.e., chop off the MSB of a double double precision value)
    0AC8
    LD B,(HL)46
    Loaded Register B with the chopped number, as that is where the ROUND routine expects the number to be
    0AC9-0ACB
    JP 0796HJP ROUNDC3 96 07
    Jump to 0796H to round the chopped number up and RETurn

    0ACCH-0ADAH -LEVEL II BASIC NUMBER CONVERSION ROUTINE – “CONSI”

    Convert Integer to Single Precision. Every register is affected.

    Note: If you wanted to convert integer to single precision via a ROM call, you would store the integer input variable in 4121H-4122H and then call to 0ACCH. The result (as a single precision number) will be in 4121H-4124H.
    0ACC-0ACE
     ↳ CONSI
    LD HL,(4121H)LD HL,(FACLO)2A 21 41
    Load Register Pair HL with the integer value from the ACCumulator
    0ACF-0AD1
     ↳ CONSIH
    CALL 0AEFHCALL VALSNGCD EF 0A
    Go set the current number type flag to single precision
    0AD2
    LD A,H7C
    Now we need to prepare the registers for the FLOATR routine. First, load Register A with the MSB of the integer value in Register H
    0AD3
    LD D,L55
    Load Register D with the LSB of the integer value in Register L
    0AD4-0AD5
    LD E,00H1E 00
    Zero Register E
    0AD6-0AD7
    LD B,90H06 90
    Load Register B with the initial maximum exponent
    0AD8-0ADA
    JP 0969HJP FLOATRC3 69 09
    Jump to 0969H to float the integer into single precision

    0ADBH-0AEDH – LEVEL II BASIC CDBL ROUTINE – “FRCDBL”

    CDBL routine. Takes a value from ACCumulator (regardless of integer or single precision) and convert it to double-precision. The result will be in ACC and NTF will be 8.
    0ADB
     ↳ FRCDBL
    RST 20HGETYPEE7
    We need to check the value of the current number type flag, so we call the TEST DATA MODE routine at RST 20H which determines the type of the current value in the ACCumulator and returns a combination of STATUS flags and unique numeric values in the register A according to the data mode flag (40AFH). The results are returned as follows:
    Variable TypeFlagsRegister A
    IntegerNZ/C/M/E-1
    StringZ/C/P/E0
    Single PrecisionNZ/C/P/O1
    Double PrecisionNZ/NC/P/E5
    0ADC
    RET NCD0
    If that test shows we have already a DOUBLE PRECISION number, then we are done, so RETurn out of the subroutine
    0ADD-0ADF
    JP Z,0AF6HJP Z,TMERRCA F6 0A
    If that test shows we have a STRING, Display a TM ERROR message
    0AE0-0AE2
    CALL M,0ACCHCALL M,CONSIFC CC 0A
    If that test shows we have an INTEGER, then go to 0ACCH to convert that integer to SINGLE PRECISION and then fall into the CONDS routine to convert a single precision number into double precision.

    0AE3H – LEVEL II BASIC CDBL ROUTINE – “CONDS”

    Convert a single precision number to double precisions. Modifies Registers A, H, and L.
    0AE3-0AE5
     ↳ CONDS
    LD HL,0000H21 00 00
    Load Register Pair HL with zero so we can zero out the ACCumulator
    0AE6-0AE8
    LD (411DH),HLLD (DFACLO),HL22 1D 41
    Zero out the first and second bytes of the double precision number in the ACCumulator.
    Note: 411DH-4124H holds ACCumulator
    0AE9-0AEB
    LD (411FH),HLLD (DFACLO+2),HL22 1F 41
    Zero out the third and fourth bytes of the double precision number in the ACCumulator
    0AEC-0AED
     ↳ VALDBL
    LD A,08H3E 08
    Load Register A with a double precision number type flag

    0AEEH-0AF3H – LEVEL II BASIC MATH ROUTINE – “VALSNG”

    0AEE
    LD BC,043EH01 3E 04
    Z-80 Trick. If passing through to this routine, BC will be modified but the next instruction will be skipped.
    0AF1-0AF3
    JP 0A9FHJP CONISDC3 9F 0A
    However we got here, Register A now holds the desired VALTYPE, so jump away to 0A9FH to save the value in Register A as the VALTYPE and RETurn

    0AF4H-0AFAH – LEVEL II BASIC MATH ROUTINE – “CHKSTR”

    This routine will force the ACCUmlator to be a STRING. Only Register A is modified.
    0AF4
     ↳ CHKSTR
    RST 20HGETYPEE7
    We need to check the value of the current number type flag, so we call the TEST DATA MODE routine at RST 20H which determines the type of the current value in the ACCumulator and returns a combination of STATUS flags and unique numeric values in the register A according to the data mode flag (40AFH). The results are returned as follows:
    Variable TypeFlagsRegister A
    IntegerNZ/C/M/E-1
    StringZ/C/P/E0
    Single PrecisionNZ/C/P/O1
    Double PrecisionNZ/NC/P/E5
    0AF5
    RET ZC8
    If that test shows we already have a STRING then we are done, so RETturn out of the subroutine. Otherwise, fall into the ?TM ERROR routine, placed here to save bytes and avoid a JUMP.

    0AF6 – ?TM Error Routine – “TMERR”

    0AF6-0AF7
     ↳ TMERR
    LD E,18H1E 18
    Load Register E with a ?TM ERROR code.

    This is the entry point for the TM ERROR
    0AF8-0AFA
    JP 19A2HJP ERRORC3 A2 19
    Display a TM ERROR message if the current value in the ACCumulator isn’t a string

    0AFBH-0B1EH – LEVEL II BASIC MATH ROUTINE – “QINT”

    This routine is a quick “Greatest Integer” function. Registers A-E are affected.

    The result of INT(ACCumulator) is left in C/D/E as a signed number

    This routine assumes that the number in the ACCumulator is less than 8,388,608 (i.e., 2^23) and that the exponent of the ACCumulator is held in Register A on entry.

    This routine can also be used to reset the BC and DE Register Pairs if the A Register contains 0. (XOR A before calling this routine).
    0AFB
     ↳ QINT
    LD B,A47
    Load Register B with the exponent of the single precision number in Register A. If a XOR A was executed before calling this routine, then the following will zero all of the registers.
    0AFC
    LD C,A4F
    Load Register C with the exponent of the single precision number in Register A
    0AFD
    LD D,A57
    Load Register D with the exponent of the single precision number in Register A
    0AFE
    LD E,A5F
    Load Register E with the exponent of the single precision number in Register A
    0AFF
    OR AB7
    Check to see if the single precision number in the ACCumulator is equal to zero
    0B00
    RET ZC8
    If Register A was 0 on entry (meaning that the exponent of the number is 0), then RETurn the same way but with C/D/E = 0, as any number whose exponent is 0 is 0.
    The original ROM source code has this to say about the next set of instructions:

    The hard case in QINT is negative non-integers. To handle this, if the number is negative, we regard the 3-byte mantissa as a 3-byte integer and subtract one. Then all the fractional bits are shifted out by shifting the mantissa right. Then, if the number was negative, we add one.

    So, if we had a negative integer, all the bits to the right of the binary point were zero and the net effect is we have the original number in C/D/E.

    If the number was a negative non-integer, there is at least one non-zero bit to the right of the binary point and the net effect is that we get the absolute value of int(fac) in C/D/E. C/D/E is then negated if the original number was negative so the result will be signed.
    0B01
    PUSH HLE5
    Save the value in Register Pair HL on the STACK
    0B02-0B04
    CALL 09BFHCALL MOVRFCD BF 09
    Call 09BF which loads the SINGLE PRECISION value in the ACCumulator into Register Pair BC/DE
    0B05-0B07
    CALL 09DFHCALL UNPACKCD DF 09
    Go turn on the sign bit of the single precision value in Register Pairs BC and DE
    0B08
    XOR (HL)AE
    Set the sign bit according to the sign of the value at the location of the memory pointer in Register Pair HL
    0B09
    LD H,A67
    Preserve the sign of the numbers into Register H
    0B0A-0B0C
    CALL M,0B1FHCALL M,QINTAFC 1F 0B
    If the number was negative, we need to substract 1 from the LOW ORDER/LSB and to do that we GOSUB to QINTA
    0B0D-0B0E
    LD A,98H3E 98
    Next we need to see how many number of bits we need to shift to change the number to an integer, so start that calculation by loading Register A with the maximum exponent
    0B0F
    SUB B90
    and then subtract the exponent in Register B from the exponent in Register A
    0B10-0B12
    CALL 07D7HCALL SHIFTRCD D7 07
    Shift the single precision value in Register Pairs BC and DE to get rid of any fractional bits via a GOSUB to SHIFTR.
    0B13
    LD A,H7C
    Restore the SIGN back into Register A from Register H
    0B14
    RLA17
    Put the sign bit into the Carry flag so that it won’t get changed.
    0B15-0B17
    CALL C,07A8HCALL C,ROUNDADC A8 07
    If the original number was negative (and thus the CARRY FLAG is set), GOSUB to ROUNDA to bump the value in Register Pairs BC and DE by 1
    0B18-0B19
    LD B,00H06 00
    Clear our Register B
    0B1A-0B1C
    CALL C,07C3HCALL C,NEGRDC C3 07
    If the original number was negative, we need to negate the number because we need a signed mantissa
    0B1D
    POP HLE1
    Restore HL from the STACK where it was saved at the top of this routine
    0B1E
    RETC9
    RETurn to CALLer

    0B1FH-0B25H – LEVEL II BASIC MATH ROUTINE – “QINTA”

    0B1F
     ↳ QINTA
    DEC DE1B
    Decrement C/D/E by 1
    0B20
    LD A,D7A
    Now we need to see if we need to carry that further and subtract one from C, so load Register A with the value of the NMSB for the single precision value which is held in Register D
    0B21
    AND EA3
    Combine the LSB of the single precision value in Register E with the NMSB of the single precision value in Register A
    0B22
    INC A3C
    Increment the combined value in Register A
    0B23
    RET NZC0
    If both D and E were -1 (i.e., DE was FFFFH) then RETurn
    0B24
     ↳ DCXBRT
    DEC BC0B
    Decrement the value of the exponent and the MSB of the single precision value in Register Pair BC. A note in the original ROM source said that this was put in specifically at the request of Bill Gates and that Register C would never be ZERO, so DEC BC and DEC C would be functionally equivalent.
    0B25
    RETC9
    RETurn to CALLer

    0B26H-0B58H – LEVEL II BASIC FIX ROUTINE
    – “FIX”

    This is the FIX(n) routine. It returns SGN(n)*INT(ABS(n))

    Takes a value from ACC and converts it to an integer value. The result will be in ACC. NTF will be 2 if value is smaller than 32767 else it will be 4. An error will be generated if NTF=3 (string).
    A call to 0B26H unconditionally truncates the fractional part of a floating point number in the ACCumulator. The result is stored in the ACCumulator and the type flag is set to integer.

    Note: If you wanted to call the FIX routine via a ROM call, you would store the single-precision input variable in 4121H-4124H, then put a 4 into 40AFH to flag as single precision, and then call to 0B26H. If the result can be an integer, it will be in 4121H-4122H and in the HL Register Pair. If single precision, the result will be in 4121H-4124H. If double precision, in 411DH-4124H. In all cases 40AFH will have the data mode flag as 2, 4, or 8, accordingly.

    FIX routine. Takes a value from ACC and converts it to an integer value. The result will be in ACC. NTF will be 2 if value is smaller than 32767 else it will be 4. An error will be generated if NTF=3 (string)

    Floating To Integer: Unconditionally truncates the fractional part of a floating point number in the ACCumulator. The result is stored in the ACCumulator and the type flag is set to integer
    0B26
     ↳ FIX
    RST 20HGETYPEE7
    We need to check the value of the current number type flag, so we call the TEST DATA MODE routine at RST 20H which determines the type of the current value in the ACCumulator and returns a combination of STATUS flags and unique numeric values in the register A according to the data mode flag (40AFH). The results are returned as follows:
    Variable TypeFlagsRegister A
    IntegerNZ/C/M/E-1
    StringZ/C/P/E0
    Single PrecisionNZ/C/P/O1
    Double PrecisionNZ/NC/P/E5
    0B27
    RET MF8
    If that test shows we have an INTEGER then we are all done, so RETurn to the caller
    0B28-0B2A
    CALL 0955HCALL SIGNCD 55 09
    Go check the sign of the current value in the ACCumulator
    0B2B-0B2D
    JP P,0B37HJP P,VINTF2 37 0B
    If the current value in the ACCumulator is positive, then we only need to do a regular INT(n), so JUMP to 0B37H (which returns the integer portion of a floating point number. If the value is positive, the integer portion is returned. If the value is negative with a fractional part, it is rounded up before truncation. The integer portion is left in the ACCumulator. The mode flag is updated.)
    0B2E-0B30
    CALL 0982HCALL NEGCD 82 09
    If we are here then the number was negative, and we need it to be positive, so GOSUB the NEG routine to convert the current value in the ACCumulator to positive
    0B31-0B33
    CALL 0B37HCALL VINTCD 37 0B
    Now that ACCumulator is positive, GOSUB to do a regular INT(n), so JUMP to 0B37H (which returns the integer portion of a floating point number. If the value is positive, the integer portion is returned. If the value is negative with a fractional part, it is rounded up before truncation. The integer portion is left in the ACCumulator. The mode flag is updated.)
    0B34-0B36
    JP 097BHJP VNEGC3 7B 09
    Since it was negative, we now need to make it negative again so JUMP to 097BH to re-NEGate the number and RETurn to the caller of this routine

    0B37H – LEVEL II BASIC INT( ROUTINE – “VINT”

    Return Integer: Returns the integer portion of a floating point number. Every flag is affected. If the value is positive, the integer portion is returned. If the value is negative with a fractional part, it is rounded up before truncation. The integer portion is left in the ACCumulator

    Note: If you wanted to call the INT routine via a ROM call, you would store the single precision input variable in 4121H-4124H, put a 4 into 40AFH (to flag as single precision), and then call 0B3DH and bypass all the foregoing. After the call, the integer result would be in 4121H-4122H and in the HL Register Pair IF the absolute value of the input did not exceed 32767. Otherwise it will be in 4121H-4124H in single precision format, and 40AF will be a 2 for integer or 4 for single precision
    According to Vernon Hester, there is are a number of bugs in this routine.
    First, INT(value) should produce a result equal to or less than value. However, if the value is double-precision (by definition), the ROM rounds value to single-precision first, then performs the INT function. e.g., PRINT INT(2.9999999) produces 3 instead of 2.
    Next, INT(value) should never overflow. However, if the value is double-precision 32767.9999#, the ROM overflows.
    Next, INT(value) should produce a result equal to or less than value. However, if the value is double-precision equal to ?2″n+2″(n-7) where n is an integer >14, the ROM produces an incorrect value. e.g., PRINT INT(?44800#) produces ?45056
    0B37
     ↳ VINT
    RST 20HGETYPEE7
    We need to check the value of the current number type flag, so we call the TEST DATA MODE routine at RST 20H which determines the type of the current value in the ACCumulator and returns a combination of STATUS flags and unique numeric values in the register A according to the data mode flag (40AFH). The results are returned as follows:
    Variable TypeFlagsRegister A
    IntegerNZ/C/M/E-1
    StringZ/C/P/E0
    Single PrecisionNZ/C/P/O1
    Double PrecisionNZ/NC/P/E5
    0B38
    RET MF8
    If that test shows we have an INTEGER then we are done, so RETurn to CALLer.
    0B39-0B3A
    JR NC,0B59HJR NC,DINT30 1E
    If the NC FLAG is set, then we have a double density number, so JUMP to DINT to handle the conversion.
    0B3B-0B3C
    JR Z,0AF6HJP Z,TMERR28 B9
    Display a ?TM ERROR if the current value in the ACCumulator isa string
    0B3D-0B3F
    CALL 0A8EHCALL CONISCD 8E 0A
    Now we try to use the CONIS routine to convert the single precision value in the ACCumulator to an integer. If we can’t we will return here to give a single precision result instead.
    0B40-0B42
     ↳ INT
    LD HL,4124HLD HL,FAC21 24 41
    Load Register Pair HL with the address of the exponent in the ACCumulator
    0B43
    LD A,(HL)7E
    Load Register A with the value of the exponent in the ACCumulator (held at the location of the memory pointer in Register Pair HL)
    0B44-0B45
    CP 98HFE 98
    Check to see if there are fractional bits used by the current value in the ACCumulator. If are none, then the NC CARRY flag will be set.
    0B46-0B48
    LD A,(4121H)LD A,(FACLO)3A 21 41
    Load Register A with the LSB of the single precision number in the ACCumulator
    0B49
    RET NCD0
    If there are no fractional bits, then we are done, so RETurn with Register A holding the single precision value in the ACCumulator
    0B4A
    LD A,(HL)7E
    Load Register A with the exponent of the single precision number in the ACCumulator
    0B4B-0B4D
    CALL 0AFBHCALL QINTCD FB 0A
    If we are here, then there were fractional bits, so GOSUB to QINT to convert the single precision number in the ACCumulator to an integer
    0B4E-0B4F
    LD (HL),98H36 98
    Adjust the exponent to be a correct one post-normalization
    0B50
    LD A,E7B
    Load Register A with the LSB of the integer value in Register E
    0B51
    PUSH AFF5
    Save the LSB of the integer value in Register A on the STACK
    0B52
    LD A,C79
    If the number was negative then we need to negate it, so first load Register A with the value in Register C
    0B53
    RLA17
    Move the sign bit in Register A into the CARRY FLAG
    0B54-0B56
    CALL 0762HCALL FADFLTCD 62 07
    GOSUB to FADLT to re-float the number
    0B57
    POP AFF1
    Get the LSB of the single precision value from the STACK and put it in Register A
    0B58
    RETC9
    RETurn to CALLer

    0B59H-0B9DH – LEVEL II BASIC MATH ROUTINE – “DINT”

    Greated Integer function for double-precision numbers. All registers are affected.
    0B59-0B5B
     ↳ DINT
    LD HL,4124HLD HL,FAC21 24 41
    Load Register Pair HL with the address of the exponent in the ACCumulator
    0B5C
    LD A,(HL)7E
    Load Register A with the value of the exponent for the double precision number in the ACCumulator (stored at the location of the memory pointer in Register Pair HL)
    0B5D-0B5E
    CP 90HFE 90
    Check to see if the double precision number in the ACCumulator uses more or less than 16 bits of precision
    0B5F-0B61
    JP C,0A7FHJP C,FRCINTDA 7F 0A
    If the double precision value in the ACCumulator uses less than 16 bits of precision, then we can use the FRCINT routine to do it, so JUMP to the CONVERT TO INTEGER routine at 0A7F (where the contents of ACCumulator are converted from single or double precision to integer and stored in HL)
    0B62-0B63
    JR NZ,0B78HJR NZ,DINT220 14
    If the NZ flag was set, we still need to make sure we didn’t have the special case number of -32768, so JUMP to DINT2
    0B64
    LD C,A4F
    If we’re here then we have to do it the hard way. First, load Register C with the exponent for the double precision number in Register A
    0B65
    DEC HL2B
    Decrement the value of the memory pointer in Register Pair HL to point to the HIGH ORDER (MSB+SIGN) portion of the double precision number
    0B66
    LD A,(HL)7E
    Load Register A with the HIGH ORDER (MSB+SIGN) of the double precision value in the ACCumulator at the location of the memory pointer in Register Pair HL
    0B67-0B68
    XOR 80HXOR 1000 0000EE 80
    Complement the value of the sign bit in Register A (which is 1000 0000)
    0B69-0B6A
    LD B,06H06 06
    Next we need to check to see if the rest of the number is ZERO, so load Register B with the number of bytes to be checked
    0B6B
     ↳ DINT1
    DEC HL2B
    Top of a loop. Decrement the value of the memory pointer in Register Pair HL to point to the next byte of the number
    0B6C
    OR (HL)B6
    Combine the value at the location of the memory pointer in Register HL with the value in Register A. If any of the bits are non-zero, then A will then be non-zero
    0B6D
    DEC B05
    Decrement the byte counter in Register B
    0B6E-0B6F
    JR NZ,0B6BHJR NZ,DINT120 FB
    Loop until all of the bytes have been checked
    0B70
    OR AB7
    The above loop kept ORing A with bits, so now we need to see what A actually holds, so set the flag.
    0B71-0B73
    LD HL,8000H21 00 80
    Just in case, put -32768 into Register Pair HL. Note that -32768 is negative 0 in double precision
    0B74-0B76
    JP Z,0A9AHJP Z,MAKINTCA 9A 0A
    If the P flag is set, then Register A was zero (-32768), so JUMP to 0A9AH to deal with it
    0B77
    LD A,C79
    Register A wasn’t zero, so let’s keep calcuating. Load Register A with the exponent for the double precision value in Register C
    0B78-0B79
     ↳ DINT2
    CP B8HFE B8
    Check to see if there are fractional bits in for the double precision value in the ACCumulator
    0B7A
    RET NCD0
    If the NO CARRY FLAG is set, then there are no fractional bits so we already have an integer! With this, RETurn
    0B7B
     ↳ DINTFO

     ↳ “DINTFO”
    PUSH AFF5
    Save the exponent in Register A on the STACK. This is the entry point from FOUT, and if that’s the case, the CARRY FLAG will be set.
    0B7C-0B7E
    CALL 09BFHCALL MOVRFCD BF 09
    Gosub to 09BF which loads the HIGH ORDER (the most significant four bytes) of the double precision value in the ACCumulator into Register Pair BC/DE
    0B7F-0B81
    CALL 09DFHCALL UNPACKCD DF 09
    Gosub to 09DFH to turn on the sign bit and return with the value of the sign
    0B82
    XOR (HL)AE
    Get the sign back by XORing A against (HL)
    0B83
    DEC HL2B
    Decrement the value of the memory pointer in Register Pair HL to point to the exponent of the double-precision number
    0B84-0B85
    LD (HL),B8H36 B8
    Save an exponent at the location of the memory pointer in Register HL for post-normalization
    0B86
    PUSH AFF5
    Save the value of the sign test in Register A on the STACK
    0B87-0B89
    CALL M,0BA0HCALL M,DINTAFC A0 0B
    If the number was negative, then the M FLAG will be set, in which case GOSUB to DINTA to subtract 1 from the LSB of the ACCumulato
    0B8A-0B8C
    LD HL,4123HLD HL,FAC-121 23 41
    Load Register Pair HL with the address of the HIGH ORDER/MSB in the ACCumulator
    0B8D-0B8E
    LD A,B8H3E B8
    Next we need to see how many bits we need to shift, so start off with Register A being the the maximum value of an exponent
    0B8F
    SUB B90
    Subtract the value of the exponent at the location of the memory pointer in Register Pair HL from the value in Register A
    0B90-0B92
    CALL 0D69HCALL DSHFTRCD 69 0D
    Shift the ACCumulator bits B times
    0B93
    POP AFF1
    Get the value of the sign test from the STACK and put it in Register A
    0B94-0B96
    CALL M,0D20HCALL M,DROUNAFC 20 0D
    If the sign is negative, GOSUB to DROUNA to add 1 to the value in the ACCumulator
    0B97
    XOR AAF
    Zero Register A so we can put a zero into the extra LOW ORDER byte, so that when we normalize it, we shift in zeroes
    0B98-0B9A
    LD (411CH),ALD (DFACLO-1),A32 1C 41
    Put a ZERO into the starting address of ACCumulator minus one
    0B9B
    POP AFF1
    Get the value of the original exponent test from the STACK and put it in Register Pair AF. This also will restore the CARRY FLAG if we entered here FOUT to indicate that we should NOT re-float the number
    0B9C
    RET NCD0
    IF called from FOUT, then RETurn to skip re-floating the number.
    0B9D-0B9F
    JP 0CD8HJP DNORMLC3 D8 0C
    Jump to 0CD8H to re-float (“normalize”) the number

    0BA0H-0BA9H – LEVEL II BASIC MATH ROUTINE – “DINTA”

    0BA0-0BA2
     ↳ DINTA
    LD HL,411DHLD HL,DFACLO21 1D 41
    If we enter from DINTA, our purpose is to subtract 1 from the ACCumulator, so we point HL to the LSB of the ACCumulator.
    0BA3
     ↳ DINTA1
    LD A,(HL)7E
    Regardless of how we enter this routine, the purpose now is to subtract 1 from (HL). To do that, first get the value into A
    0BA4
    DEC (HL)35
    Decrement the value at the location of the memory pointer in Register Pair HL by 1
    0BA5
    OR AB7
    We really only want to continue if the byte uCheck to see if the byte used to be ZERO, so test the byte
    0BA6
    INC HL23
    Increment the value of the memory pointer in Register Pair HL to point to the next byte
    0BA7-0BA8
    JR Z,0BA3HJR Z,DINTA128 FA
    Loop until the value at the location of the memory pointer in Register Pair HL is equal to a nonzero value
    0BA9
    RETC9
    RETurn to CALLer

    0BAAH-0BC6H – LEVEL II BASIC MATH ROUTINE – “UMULT”

    This is the integer multiply routine for multiplying dimensioned array. It will calculate DE = BC * DE. If there is an overflow, a ?BS ERROR will get thrown. Every register except HL is affected.
    0BAA
     ↳ UMULT
    PUSH HLE5
    Save the value in Register Pair HL on the STACK
    0BAB-0BAD
    LD HL,0000H21 00 00
    Load Register Pair HL with zero to zero the product registers
    0BAE
    0BAF
    LD A,B
    OR C78 B1
    First let’s see if (BC) is zero by loading Register A with the MSB of the integer value in Register B and then ORing the LSB held in Register C
    0BB0-0BB1
    JR Z,0BC4HJR Z,MULRET28 12
    If BC is already zero, then just return, since HL is already zero
    0BB2-0BB3
    LD A,10H3E 10
    Load Register A with the counter value (which is 16)
    0BB4
     ↳ UMULT1
    ADD HL,HL29
    Top of a loop. Multiply the result in Register Pair HL by two
    0BB5-0BB7
    JP C,273DHJP C,BSERRDA 3D 27
    If the CARRY FLAG was set, then we have an overflow, which we handle by displaying a ?BS ERROR message
    0BB8
    EX DE,HLEB
    Save the product so far into Register Pair DE
    0BB9
    ADD HL,HL29
    Multiply the integer value in Register Pair HL by two
    0BBA
    EX DE,HLEB
    Swap DE and HL so DE now holds HL * 4 and HL holds HL * 2
    0BBB-0BBC
    JR NC,0BC1HJR NC,UMULT230 04
    If the HIGH ORDER/MSB from the HL addition was 1, then we need to add in (BC) so JUMP to UMULT2 to do that
    0BBD
    ADD HL,BC09
    Add the integer value in Register Pair BC to the result in Register Pair HL
    0BBE-0BC0
    JP C,273DHJP C,BSERRDA 3D 27
    Display a BS ERROR message if the result in Register Pair HL has overflowed
    0BC1
     ↳ UMULT2
    DEC A3D
    Decrement the counter in Register A
    0BC2-0BC3
    Loop until the multiplication has been completed
    0BC4
     ↳ MULRET
    EX DE,HLEB
    Swap so that the return result is in DE. We don’t care about HL because …
    0BC5
    POP HLE1
    … restore the original HL from the STACK
    0BC6
    RETC9
    RETurn to CALLer
    The next bunch of routines are the integer arithmetic routines. According to the original ROM source code, the conventions are.
    • Integer variables are 2 byte signed numbers, with the LSB coming first
    • For one argument functions, the argument is in (HL) and the results are put into (HL)
    • For two argument operations, the first argument is in (DE), the second in (HL), and the restuls are left in the ACCumulator and, if there was no overflow, (HL). If there was an overflow, then the arguments are converted to single precision.
    • When integers are stored in the ACCumulator, they are stored at FACLO+0 and FACLO+1, with VALTYPE=2

    0BC7H-0BD1H – INTEGER SUBTRACTION – “ISUB”

    Integer subtract. (ACCumulator=DE-HL) The result is returned in both ACCumulator and, if there was no overflow, the HL Register Pair.
    Subtracts the value in DE from the value in HL. The difference is left in the HL Register Pair. DE is preserved. In the event of underflow, both values are converted to single precision and the subtraction is repeated. The result is left in the ACCumulator and the mode flag is updated accordingly.

    Note: If you wanted to subtract 2 integers via a ROM call, store one into DE and the subtrahend in HL (i.e., to do 26-17, DE gets 26), and then call 0BC7H. The integer result will be stored in 4121H-4122H approximately 210 microseconds later, and 40AFH will be set to 2 (to flag it as an integer). If there is an overflow, it will be converted to single precision (with 40AFH being a 4 in that case) and will be stored in 4121H-4124H.

    Every register is affected.

    Integer Subtraction: Subtracts the value in DE from the value in HL. The difference is left in the HL Register Pair. DE is preserved. In the event of underflow, both values are converted to single precision and the subtraction is repeated. The result is left in the ACCumulator and the mode flag is updated accordingly
    0BC7
     ↳ ISUB
    LD A,H7C
    The first thing we need to do is to extend the sign of (HL) into Register B. That’s the next 4 instructions. First, load Register A with the MSB+SIGN of the integer value in Register H
    0BC8
    RLA17
    Rotate the value of the sign bit into the CARRY FLAG
    0BC9
    SBC A,A9F
    Adjust Register A according to the value of the sign bit
    0BCA
    LD B,A47
    Load Register B with the result of the sign test
    0BCB-0BCD
    CALL 0C51HCALL INEGHLCD 51 0C
    Negate (HL) via a GOSUB to INEGHL
    0BCE
    LD A,C79
    Load Register A with zero
    0BCF
    SBC A,B98
    Negate the sign
    0BD0-0BD1
    JR 0BD5HJR IADDS18 03
    Jump to 0BD5H to add the numbers

    0BD2H-0BF1H – INTEGER ADDITION – “IADD”

    Integer addition (ACCumulator=DE+HL), where ACCumulator = 4121H-4122H. After execution NTF=2, or 4 if overflow has occurred, in which case the result in the ACCumulator will be single-precision. The result is returned in both ACCumulator and the HL Register Pair.

    Adds the integer value in DE to the integer in HL. The sum is left in HL and the orginal contents of DE are preserved. If overflow occurs (sum exceeds 2**15), both values are converted to single precision and then added. The result would be left in the ACCumulator and the mode flag would be updated.

    Every register is affected.

    Note: If you wanted to add 2 integers via a ROM call, store one input into DE and the other into HL, and then call 0BD2H. The result will be in 4121H-4122H and in HL, with a 2 in 40AFH, and will take about 130 microseconds. If there is an overflow, the result will be converted to Single Precision and put into 4121H-4124H (with a 4 in 40AFH).
    0BD2
     ↳ IADD
    LD A,H7C
    The first thing we need to do is to extend the sign of (HL) into Register B. That’s the next 4 instructions. First, load Register A with the MSB+SIGN of the integer value in Register H
    0BD3
    RLA17
    Rotate the value of the sign bit into the CARRY FLAG
    0BD4
    SBC A,A9F
    Adjust Register A according to the value of the sign bit
    0BD5
     ↳ IADDS
    LD B,A47
    Load Register B with the result of the sign test
    0BD6
    PUSH HLE5
    Save the second argument (held in Register Pair HL) to the the STACK in case we have an overflow
    0BD7
    LD A,D7A
    The next 4 instructions extend the sign of (DE) into Register A. First, load Register A with the MSB+SIGN of the integer value in Register Pair DE
    0BD8
    RLA17
    Rotate the value of the sign bit into the CARRY FLAG
    0BD9
    SBC A,A9F
    Adjust Register A according to the value of the sign bit
    0BDA
    ADD HL,DE19
    Add the two LSBs, result in Register Pair HL
    0BDB
    ADC A,B88
    Add the extra HIGH ORDER (held in Register B) to the value of the sign test for the integer value in Register Pair DE in Register A
    0BDC
    RRCA0F
    The next 2 instructions are to see if the LSB of A is different from the MSB of H, in which ase an overflow occurred. So, put the value of the Carry flag in Register A
    0BDD
    XOR HAC
    Combine the value of the sign bit for the result in Register H with the value in Register A
    0BDE-0BE0
    JP P,0A99HJP P,CONIS1F2 99 0A
    If the P FLAG is set, then we had no overflow. In this case, we need to restore the original (HL) from the stack and we are done. So JUMP to CONIS1 to do all that AND put (HL) into the ACCumulator as well.
    0BE1
    PUSH BCC5
    If we are here then we have an overflow. First, save the extended sign of (HL) (held in Register B) to the STACK
    0BE2
    EX DE,HLEB
    Load Register Pair HL with the integer value in Register Pair DE
    0BE3-0BE5
    CALL 0ACFHCALL CONSIHCD CF 0A
    Go float the Register value in Register Pair HL to single precision and return with the result in the ACCumulator
    0BE6
    POP AFF1
    Get the sign of (HL) from the STACK and put it in Register A
    0BE7
    POP HLE1
    Get the old (HL) back from the STACK
    0BE8-0BEA
    CALL 09A4HCALL PUSHFCD A4 09
    Call 09A4 which moves the SINGLE PRECISION value in the ACCumulator to the STACK (stored in LSB/MSB/Exponent order)
    0BEB
    EX DE,HLEB
    Load Register Pair DE with the integer value in Register Pair HL, as FLOATR needs DE to hold the value
    0BEC-0BEE
    CALL 0C6BHCALL INEGADCD 6B 0C
    Go float the integer value in Register Pair DE to single precision and return with the result in the ACCumulator
    0BEF-0BF1
    JP 0F8FHJP FADDTC3 8F 0F
    At this point the basic values are good enough to be added via single precision, so JUMP to FADDT to do that

    0BF2H-0C1EH – INTEGER MULTIPLICATION – “IMULT”

    Integer multiply. (ACCumulator (and HL) =DE*HL). Multiplies HL by DE. The product is left in HL and DE is preserved. If overflow occurs, both values are converted to single precision and the operation is restarted. The product would be left in the ACCumulator.

    Note: If you wanted to multiply two integers, store one input in DE, the other in HL CALL 0BF2H. The result is in 4121H-4122H and in HL, with a 2 in 40AFH (but in an overflow the result is converted to single precision format and stored in 4121H-4124H, with a 4 in 40AFH. Process takes approximately 900 microseconds.
    0BF2
     ↳ IMULT
    LD A,H7C
    Load Register A with the MSB of the integer value in Register H
    0BF3
    OR LB5
    Combine the LSB of the integer value in Register L with the MSB of the integer value in Register A
    0BF4-0BF6
    JP Z,0A9AHJP Z,MAKINTCA 9A 0A
    If the ZERO flag is set, then HL is zero, and if so, just return
    0BF7
    PUSH HLE5
    In case of an overflow, we are going to need our original arguments. Save the integer value in Register Pair HL on the STACK
    0BF8
    PUSH DED5
    Save the integer value in Register Pair DE on the STACK
    0BF9-0BFB
    CALL 0C45HCALL IMULDVCD 45 0C
    Go convert any negative integer values to positive and return with Register B set according to the value of the sign bits
    0BFC
    PUSH BCC5
    Save the value of the sign bit test in Register B on the STACK
    0BFD
    0BFE
    LD B,H
    LD C,L44
    Copy the second argument from HL into BC
    0BFF-0C01
    LD HL,0000H21 00 00
    Start Register Pair HL at zero, as the result will go into HL
    0C02-0C03
    LD A,10H3E 10
    Load Register A with the counter value (which is 16)
    0C04
     ↳ IMULT1
    ADD HL,HL29
    Multiply the result in Register Pair HL by two
    0C05-0C06
    JR C,0C26HJR C,IMULT538 1F
    If that caused an overflow, then JUMP to IMULT5
    The next 6 instruction are to roate the first argument left one to see if we need to add BC to it or not. If the NC FLAG is set, then we don’t add in BC. Otherwise we do.
    0C07
    EX DE,HLEB
    Exchange the integer value in Register Pair DE with the integer result in Register Pair HL
    0C08
    ADD HL,HL29
    Multiply the integer value in Register Pair HL by two
    0C09
    EX DE,HLEB
    Exchange the integer result in Register Pair DE with the integer value in Register Pair HL
    0C0A-0C0B
    JR NC,0C10HJR NC,IMULT230 04
    If the NC FLAG is set, then skip the next instructions which add in BC
    0C0C
    ADD HL,BC09
    Add the integer value in Register Pair BC to the integer result in Register Pair HL
    0C0D-0C0F
    JP C,0C26HJP C,IMULT5DA 26 0C
    If we have overflowed by adding in BC, then JUMP to IMULT5
    0C10
     ↳ IMULT2
    DEC A3D
    Decrement the value of the counter in Register A
    0C11-0C12
    JR NZ,0C04HJR NZ,IMULT120 F1
    Loop until the multiplication has been completed
    0C13
    POP BCC1
    At this point we are done, so we need to finish up. First, get the value of the sign test from the STACK and put it in Register B
    0C14
    POP DED1
    Get the original FIRST argument from the STACK and put it in Register Pair DE
    This is the entry from IDIV. The next instructions test to see if the result is => 32768 or is -32768.
    0C15
     ↳ IMLDIV
    LD A,H7C
    Load Register A with the MSB of the result in Register H
    0C16
    OR AB7
    Test Register H
    0C17-0C19
    JP M,0C1FHJP M,IMULT3FA 1F 0C
    If the M FLAG is set, then the result is =gt; 32768, so JUMP to IMULT3 to make sure it isn’t -32768.
    0C1A
    POP DED1
    If we are here, then the number is OK, so get the SECOND argument off the stack and into Register Pair DE
    0C1B
    LD A,B78
    Load Register A with the value of the sign test in Register B
    0C1C-0C1E
    JP 0C4DHJP INEGAC3 4D 0C
    Jump to 0C4DH to NEGate the number, if needed and RETurn

    0C1FH-0C34H – LEVEL II BASIC MATH ROUTINE – “IMULT3”

    0C1F-0C20
     ↳ IMULT3
    XOR 80HEE 80
    Clear the sign bit for the MSB of the integer value in Register A which is 1000 0000
    0C21
    OR LB5
    Combine the value of the LSB for the integer value in Register L with the adjusted MSB of the integer value in Register A
    0C22-0C23
    JR Z,0C37HJR Z,IMULT428 13
    If the Z FLAG is set, then the result is 32768, so JUMP to IMULT4
    0C24
    EX DE,HLEB
    If we are hre, then it is > 32768 giving us an overflow, so Load Register Pair HL with the integer value in Register Pair DE
    0C25-0C28
    LD BC,E1C1H01 C1 E1
    Z-80 Trick – See the note at 0134H for an explanation
    0C28-0C2A
    CALL 0ACFHCALL CONSIHCD CF 0A
    Go float the FIRST argument (held in in Register Pair HL) to single precision and return with the result in the ACCumulator
    0C2B
    POP HLE1
    Get the original SECOND argument from the STACK and put it in Register Pair HL
    0C2C-0C2E
    CALL 09A4HCALL PUSHFCD A4 09
    Save the floated FIRST agument via a GOSUB to 09A4 which moves the SINGLE PRECISION value in the ACCumulator to the STACK (stored in LSB/MSB/Exponent order)
    0C2F-0C31
    CALL 0ACFHCALL CONSIHCD CF 0A
    Go float the SECOND argument (held in in Register Pair HL) to single precision and return with the result in the ACCumulator
    0C32
     ↳ FMULTT
    POP BCC1
    Get the FIRST argument off the stack and put it in Register Pair BC. POLYX jumps here.
    0C33
    POP DED1
    Get the NMSB and the LSB of the single precision value from the STACK and put it in Register Pair DE
    0C34-0C36
    JP 0847HJP FMULTC3 47 08
    Multiply the arguments via regular old FMULT – the SINGLE PRECISION MULTIPLY routine at 0847H (which multiplies the current value in the ACCumulator by the value in (BC/DE). The product is left in the ACCumulator

    0C37H-0C44H – LEVEL II BASIC MATH ROUTINE – “IMULT4”

    0C37
     ↳ IMULT4
    LD A,B78
    We need to see if the result is +/- 32768. First, load Register A with the result of the sign test in Register B
    0C38
    OR AB7
    Check the result
    0C39
    POP BCC1
    Discard the original SECOND argument from the STACK
    0C3A-0CJC
    JP M,0A9AHJP M,MAKINTFA 9A 0A
    Jump if the result is supposed to be negative
    0C3D
    PUSH DED5
    If we are here, then the result is positive. Save the remainder for MOD to the STACK
    0C3E-0C40
    CALL 0ACFHCALL CONSIHCD CF 0A
    Go float -32768 and return with the result in the ACCumulator
    0C41
    POP DED1
    Get the MOD’s remainder from the STACK and put it in Register Pair DE
    0C42-0C44
    JP 0982HJP NEGC3 82 09
    Jump to 0982H to turn -32768 into 32768 and finish up

    0C45H-0C5AH – LEVEL II BASIC MATH ROUTINE – “IMULDV”

    This is the integer division routine HL = DE / HL. The remainder will be left in DE and the quotient will be left in HL. Every register is affected.
    0C45
     ↳ IMULDV
    LD A,H7C
    Load Register A with the MSB+SIGN of the integer value in Register H
    0C46
    XOR DAA
    Combine the MSB of the integer value in Register D with the MSB+SIGN of the integer value in Register A
    0C47
    LD B,A47
    Save the result of the combined signs in Register A into Register B
    0C48-0C4A
    CALL 0C4CHCALL INEGHCD 4C 0C
    If necessary, NEGate the SECOND argument (i.e., the value in Register Pair HL) to positive
    0C4B
    EX DE,HLEB
    Presetve the contents of Register DE into Register Pair HL, and fall through to the negation routine below.
    0C4C
     ↳ INEGH
    LD A,H7C
    Load Register A with the MSB+SIGN of the integer value in Register H
    0C4D
     ↳ INEGA
    OR AB7
    Set the condition codes so we can see the sign of HL
    0C4E-0C50
    JP P,0A9AHJP P,MAKINTF2 9A 0A
    If the P FLAG is set, then the integer value in Register Pair HL is positive and we don’t need to NEGate it. So we JUMP to MAKINT to save the result into the ACCumulator for when the operators come back tt this routine.
    Negate HL routine. This routine changes the sign of the HL Register Pair and stores it in the ACC. (HL=ACCumulator=-HL) The result is returned in both the HL Register Pair and the ACC.
    0C51
     ↳ INEGHL
    XOR AAF
    Zero Register A.
    0C52
    LD C,A4F
    Load Register C with the ZERO held in Register A
    0C53
    SUB L95
    Subtract the LSB of the integer value in Register L from the ZERO in Register A
    0C54
    LD L,A6F
    Save the adjusted value in Register A in Register L
    0C55
    LD A,C79
    Load Register A with a ZERO
    0C56
    SBC A,H9C
    Subtract the HIGH ORDER (MSB+SIGN) of the integer value in Register H from the value in Register A
    0C57
    LD H,A67
    Save the adjusted value in Register A into Register H
    0C58-0C5A
    JP 0A9AHJP MAKINTC3 9A 0A
    Jump to 0A9AH to save the result into the ACCumulator for when the operations jump back here.

    0C5BH-0C6FH – LEVEL II BASIC MATH ROUTINE – “INEG”

    Integer Negation Routine. All registers are altered.
    0C5B-0C5D
     ↳ INEG
    LD HL,(4121H)LD HL,(FACLO)2A 21 41
    Load Register Pair HL with the integer value in the ACCumulator
    0C5E-0C60
    CALL 0C51HCALL INEGHLCD 51 0C
    Go convert the integer value in Register Pair HL to positive if it’s negative
    0C61
    LD A,H7C
    Load Register A with the HIGH ORDER (i.e., MSB+SIGN) of the integer value in Register H
    0C62-0C63
    XOR 80HXOR 1000 0000EE 80
    Invert the value of the sign bit in Register A which is 1000 0000 so that we can check for the special case of -32768
    0C64
    OR LB5
    Combine the LSB of the integer value in Register L with the adjusted MSB of the integer value in Register A
    0C65
    RET NZC0
    Return if the integer value in the ACCumulator isn’t equal to -32768
    0C66
     ↳ INEG2
    EX DE,HLEB
    If we are here, the magic -32768 was found, so we need to float it. First, load Register Pair DE with the integer value in Register Pair HL
    0C67-0C69
    CALL 0AEFHCALL VALSNGCD EF 0A
    Go set the number type flag to single precision
    0C6A
    XOR AAF
    Zero Register A, which we will use for the HIGH ORDER
    0C6B-0C6C
     ↳ INEGAD
    LD B,98H06 98
    Load Register B with an exponent. IADD jumps here.
    0C6D-0C6F
    JP 0969HJP FLOATRC3 69 09
    Float the number via a JUMP to 0969H

    DOUBLE PRECISION ROUTINES

    The next bunch of routines are the double precision arithmetic routines. According to the original ROM source code, the conventions are.
    • Double prevision numbers are 8 bytes long: The first 4 bytes are 32 low order bits of precision and the last 4 bytes are are in the same format as single precision numbers. The lowest order byte comes first in RAM.
    • For one argument gunctions: The argument is in the ACCumulator, and the results is put there too.
    • For two argument operations, the first argument is in the ACCumulator and the second argument is in ARG-7,-6,-5,-4,-3,-2,-1,-0. ARGLO=ARG-7. The result is left in the ACCumulator.
    • Note that the order of the numbers is reversed from integers and single precisions values

    0C70H-0C76H – DOUBLE PRECISION SUBTRACTION – “DSUB”

    Double-precision subtraction (ACCumulator = ACCumulator – ARG).
    Subtracts the double precision value in ARG (a/k/a REG 2) from the value in the ACCumulator. The difference is left in the ACCumulator.

    Note: If you wanted to subtract two double precision numbers, store the minuend in 411DH-4124H and the subtrahend in 4127H-412EH, and CALL 0C70H. The result (in double precision format) is in 411DH-4124H in approximately 1.3 milliseconds.

    Vernon Hester has flagged a bug. Double-precision subtraction should produce an difference accurate to 16 digits. However, the difference resulting from doubleprecision subtraction is erroneous when the smaller operand’s value is significantly less than the larger operand’s value
      Example: In the code Y# = .20# : X# = 1D16 : J# = X# – Y# : PRINT J# – X# J# is incorrect and J#-X# shows a positive result when it is negative.
    0C70-0C72
     ↳ DSUB
    LD HL,412DHLD HL,ARG-121 2D 41
    Since addition is easier than subtraction, first we need to negate the SECOND argument by first loading Register Pair HL with the address of the MSB in ARG (a/k/a REG 2)
    0C73
    LD A,(HL)7E
    Load Register A with the HIGH ORDER (i.e., MSB+SIGN) of the double precision value in ARG (a/k/a REG 2) at the location of the memory pointer in Register Pair HL
    0C74-0C75
    XOR 80HXOR 1000 0000EE 80
    Invert the value of the sign bit for the MSB of the double precision value in Register A which is 1000 0000
    0C76
    LD (HL),A77
    Save the adjusted HIGH ORDER (i.e., MSB+SIGN) of the double precision value in Register A in ARG (a/k/a REG 2) at the location of the memory pointer in Register Pair HL. To save RAM we now fall into the DADD addition routine.

    0C77H-0CCEH -DOUBLE PRECISION ADDITION – “DADD”

    Double-precision addition (ACCumulator=ACCumulator+ARG (a/k/a REG 2)).
    Adds the double precision value in ARG (a/k/a REG 2) to the value in the ACCumulator. Sum is left in the ACCumulator. All registers are affected.

    Note: If you wanted to add 2 double precision numbers via a ROM call, store one input into 411DH-4124H and the other in 4127H-412EH. Then call 0C77H. The double precision result will be stored in 411DH-4124H approximately 1.3 milliseconds later.
    0C77-0C79
     ↳ DADD
    LD HL,412EHLD HL,ARG21 2E 41
    Load Register Pair HL with the address of the exponent in the FIRST argument held at ARG (a/k/a REG 2)
    0C7A
    LD A,(HL)7E
    Prepare to test that for ZERO by first loading Register A with the exponent of the double precision value in ARG (a/k/a REG 2) at the location of the memory pointer in Register Pair HL
    0C7B
    OR AB7
    Check to see if the double precision value in ARG (a/k/a REG 2) is equal to zero
    0C7C
    RET ZC8
    Return if the double precision value in ARG (a/k/a REG 2) is equal to zero, since that means that the ACCumulator (i.e., the FIRST argument) is actually the sum
    0C7D
    LD B,A47
    Preserve the exponent for the double precision value in Register A into Register C
    0C7E
    DEC HL2B
    Decrement the value of the memory pointer in Register Pair HL to now point to the HIGH ORDER (i.e., MSB + SIGN) for unpacking
    0C7F
    LD C,(HL)4E
    Load Register C with the value of the HIGH ORDER (i.e., MSB + SIGN) of the double precision value in ARG (a/k/a REG 2) at the location of the memory pointer in Register Pair HL
    0C80-0C82
    LD DE,4124HLD DE,FAC11 24 41
    Load Register Pair DE with the address of the exponent of the SECOND argument (held in the ACCumulator)
    0C83
    LD A,(DE)1A
    Fetch the value of the exponent of the double precision value in the ACCumulator at the location of the memory pointer in Register Pair DE
    0C84
    OR AB7
    Set the flags to see if the double precision value in the ACCumulator is equal to zero
    0C85-0C87
    JP Z,09F4HJP Z,MOVFACA F4 09
    If the exponent is zero, then the number is zero, so we are once again adding 0 to a number. In this case, the non-zero number is in the wrong reghister, so JUMP to VMOVFA to move ARG to the ACCumulator and exit.
    0C88
    SUB B90
    Now we know we do not have any zero’s, so we next need to get the shift count by subtracting the exponents. First, subtract the value of the exponent for the double precision value in ARG (a/k/a REG 2) in Register B from the value of the exponent for the double precision value in the ACCumulator in Register A
    0C89-0C8A
    JR NC,0CA1HJR NC,DADD230 16
    If the NC FLAG is set, then the we need to put the smaller number into the ACCumulator, so JUMP to DADD2 to do that
    0C8B
    CPL2F
    Negate the shift count held in Register A
    0C8C
    INC A3C
    Increment the value of the difference for the exponents in Register A so that Register A will hold the positive difference
    0C8D
    PUSH AFF5
    Save the shift count (i.e., the difference for the exponents, held in Register A) to the STACK
    Next we are going to switch ARG and the ACCumulator.
    0C8E-0C8F
    LD C,08H0E 08
    Load Register C with a counter value which is 8
    0C90
    INC HL23
    Increment the value of the memory pointer in Register Pair HL so that it will be pointing to the exponent of the double precision value in ARG (a/k/a REG 2)
    0C91
    PUSH HLE5
    Save the value of the memory pointer in Register Pair HL (which is pointing to ARG) on the STACK
    0C92
     ↳ DADD1
    LD A,(DE)1A
    Top of a loop. Load Register A with the value of the ACCumulator pointed to by Register Pair DE
    0C93
    LD B,(HL)46
    Load Register B with the value of ARG (a/k/a REG 2) pointed to by Register Pair DE
    0C94
    LD (HL),A77
    Save the ACCumulator value into the corresponding ARG (a/k/a REG 2) byte.
    0C95
    LD A,B78
    Load Register A with the ARG byte (held in Register B)
    0C96
    LD (DE),A12
    Save the ARG byte (held in Register A) into the corresopnding ACCumulator byte (pointed to by Register Pair DE)
    0C97
    DEC DE1B
    Decrement the value of the memory pointer in Register Pair DE to the next lower byte of the ACCumulator
    0C98
    DEC HL2B
    Decrement the value of the memory pointer in Register Pair HL to the next lower byte in ARG
    0C99
    DEC C0D
    Decrement the value of the counter in Register C
    0C9A-0C9B
    JR NZ,0C92HJR NZ,DADD120 F6
    Loop until the double precision values in the ACCumulator and ARG (a/k/a REG 2) have been exchanged
    0C9C
    POP HLE1
    Get the HIGH ORDER back from the stack into Register Pair HL
    0C9D
    LD B,(HL)46
    Fetch the exponent for the double precision value in ARG (a/k/a REG 2) pointed to by Register Pair HL
    0C9E
    DEC HL2B
    Decrement the value of the memory pointer in Register Pair HL to now point to the HIGH ORDER (MSB + SIGN)
    0C9F
    LD C,(HL)4E
    Load Register C with the value of the MSB+SIGN for the double precision value in ARG (a/k/a REG 2) at the location of the memory pointer in Register Pair HL
    0CA0
    POP AFF1
    Get the shift count (i.e., difference for the exponents) back into Register A
    0CA1-0CA2
     ↳ DADD2
    CP 39HFE 39
    Check to see if the difference between the two exponents is greater than 56 bits
    0CA3
    RET NCD0
    Return if the difference between the two exponents is greater than 56 bits
    0CA4
    PUSH AFF5
    Save the shift count (i.e., difference for the exponents) from Register A onto the STACK
    0CA5-0CA7
    CALL 09DFHCALL UNPACKCD DF 09
    Go turn on the sign bits for the double precision numbers
    0CA8
    INC HL23
    Increment the value of the memory pointer in Register Pair HL to now point to ARGLO-1
    0CA9-0CAA
    LD (HL),00H36 00
    Zero the temporary LSB (held at the location of the memory pointer in Register Pair HL)
    0CAB
    LD B,A47
    Preserve the sign test into Register B
    0CAC
    POP AFF1
    Restore the shift count (i.e., difference for the exponents) from the STACK into Register A
    0CAD-0CAF
    LD HL,412DHLD HL,ARG-121 2D 41
    Load Register Pair HL with the address of the HIGH ORDER in ARG (a/k/a REG 2)
    0CB0-0CB2
    CALL 0D69HCALL DSHFTRCD 69 0D
    Go shift the double precision value in ARG (a/k/a REG 2) until it lines up with the double precision value in the ACCumulator
    0CB3-0CB5
    LD A,(4126H)LD A,(ARGLO-1)3A 26 41
    We next need to transfer the OVERFLOW byte from ARG to ACCumulator, so first put it in Register A
    0CB6-0CB8
    LD (411CH),ALD (DFACLO-1),A32 1C 41
    Save the value in Register A to ARG
    0CB9
    LD A,B78
    Load Register A with the value of the sign test in Register B
    0CBA
    OR AB7
    Check to see if the signs are equal
    0CBB-0CBD
    JP P,0CCFHJP P,DADD3F2 CF 0C
    If the P FLAG is set, then the signs of the numbers are different, so JUMP to DADD3 to subtract the values
    0CBE-0CC0
    CALL 0D33HCALL DADDAACD 33 0D
    Otherwise (i.e., the signs are the same) GOSUB to DADDAA to add the numbers
    0CC1-0CC3
    JP NC,0D0EHJP NC,DROUNDD2 0E 0D
    If that didn’t trigger a NC FLAG, then JUMP to 0D0EH to ROUND the result and continue on.
    0CC4
    EX DE,HLEB
    If that DID trigger the NC FLAG, then put the pointer to the exponent of the ACCumulator into HL
    0CC5
    INC (HL)34
    Add one to the exponent (since we had an overflow)
    0CC6-0CC8
    JP Z,07B2HJP Z,OVERRCA B2 07
    Check for OVERFLOW because of that too! If the Z FLAG is set, then display an ?OV ERROR if the exponent for the double precision result in the ACCumulator is too large
    0CC9-0CCB
    CALL 0D90HCALL DSHFRBCD 90 0D
    If we still have no overflow, then we need to shift the number right one so as to shift in the CARRY FLAG. To do this we GOSUB to DSHFRB
    0CCC-0CCE
    JP 0D0EHJP DROUNDC3 0E 0D
    JUMP to 0D0EH to ROUND the result and continue on.

    0CCFH-0D1FH – DOUBLE PRECISION MATH ROUTINE – “DADD3”

    0CCF-0CD1
     ↳ DADD3
    CALL 0D45HCALL DADDASCD 45 0D
    Go subtract the double precision values
    0CD2-0CD4
    LD HL,4125HLD HL,FAC+121 25 41
    Right now HL isn’t pointing where we need it to point for a call to DNEGR, so load Register Pair HL with the address of the sign, and then, to save RAM, fall through into DNORML.
    0CD5-0CD7
    CALL C,0D57HCALL C,DNEGRDC 57 0D
    Go complement the result in the ACCumulator if the Carry flag is set

    0CD8H – DOUBLE PRECISION MATH ROUTINE – “DNORML” and “DNORM1”

    0CD8
     ↳ DNORML
    XOR AAF
    Zero Register A, which will act as a byte shift counter
    0CD9
     ↳ DNORM1
    LD B,A47
    Preserve the shift counter into Register Register B
    0CDA-0CDC
    LD A,(4123H)LD A,(FAC-1)3A 23 41
    Load Register A with the value of the HIGH ORDER (i.e., MSB+SIGN) of the double precision result in the ACCumulator
    0CDD
    OR AB7
    Check to see if we can shift 8 numbers to the left
    0CDE-0CDF
    JR NZ,0CFEHJR NZ,DNORM520 1E
    If the NZ FLAG is set, then we cannot shift 8 numbers left, so we need to JUMP to see if the number is already normalized.
    0CE0-0CE2
    LD HL,411CHLD HL,DFACLO-121 1C 41
    If we are here then we CAN shift 8 numbers left, so first load Register Pair HL with the starting address of ACCumulator minus one.
    0CE3-0CE4
    LD C,08H0E 08
    Load Register C with the number of bytes to be shifted (i.e., 8)
    0CE5
     ↳ DNORM2
    LD D,(HL)56
    Top of a loop. Load Register D with a byte from the ACCumulator (pointed to by Register Pair HL)
    0CE6
    LD (HL),A77
    Save the value in Register A to the newly vacated location at the memory pointer in Register Pair HL. Note that on the FIRST loop, this is a zero.
    0CE7
    LD A,D7A
    Put the current byte from the ACCumulator (preserved in D) into Register A for writing on the next iteration
    0CE8
    INC HL23
    Increment the value of the memory pointer in registerpair HL
    0CE9
    DEC C0D
    Decrement the number of bytes to be shifted in Register C
    0CEA-0CEB
    JR NZ,0CE5HJR NZ,DNORM220 F9
    Loop until all of the bytes in the double precision value have been shifted
    0CEC
    LD A,B78
    Now that we did an 8 byte shift, we need to subtract 8 from the shift counter. First, load Register A with the number of bits shifted in Register B
    0CED-0CEE
    SUB 08HD6 08
    Subtract the number of bits just shifted from the shift counter in Register A
    0CEF-0CF0
    CP C0HFE C0
    Check to see if the whole of the double precision value has been shifted
    0CF1-0CF2
    JR NZ,0CD9HJR NZ,DNORM120 E6
    If the whole of the double precision value hasn’t been shifted, JUMP back to DNORM1 to shift some more
    0CF3-0CF5
    JP 0778HJP ZEROC3 78 07
    If we are here, then we have shifted all the bytes so JUMP to ZERO

    0CF6H – Part of the “DNORML” and “DNORM1” Routine

    0CF6
     ↳ DNORM3
    DEC B05
    Decrement the shift counter held in Register B
    0CF7-0CF9
    LD HL,411CHLD HL,DFACLO-121 1C 41
    Load Register Pair HL with the starting address of ACCumulator minus one.
    0CFA-0CFC
    CALL 0D97HCALL DSHFLCCD 97 0D
    Shift the double precision value in the ACCumulator once to the left
    0CFD
    OR AB7
    Check to see if the number has been normalized yet
    0CFE-0D00
     ↳ DNORM5
    JP P,0CF6HJP P,DNORM3F2 F6 0C
    If the P FLAG is set, then we are not yet normalized, so LOOP back to DNORM3 and keep shifting
    0D01
    LD A,B78
    Load Register A with the value of the shift counter from Register B
    0D02
    OR AB7
    Check to see if the shift counter in Register A is equal to zero
    0D03-0D04
    JR Z,0D0EHJR Z,DROUND28 09
    If the shift counter is zero, then proceed to round the number and finish up by JUMPing to DROUND
    0D05-0D07
    LD HL,4124HLD HL,FAC21 24 41
    Load Register Pair HL with the address of the exponent in the ACCumulator
    0D08
    ADD A,(HL)86
    Add the value of the exponent for the double precision value in the ACCumulator at the location of the memory pointer in Register Pair HL to the value of the shift counter in Register A
    0D09
    LD (HL),A77
    Save the adjusted exponent for the double precision value in Register A at the location of the memory pointer in Register Pair HL
    0D0A-0D0C
    JP NC,0778HP NC,ZEROD2 78 07
    If the NC FLAG was triggered, then we have an UNDERFLOW, so JUMP to ZERO
    0D0D
    RET ZC8
    If the Z FLAG is set, then the result is already zero and we are done, so FALL into the DROUND routine and round the result.

    0D0EH – DOUBLE PRECISION MATH ROUTINE – “DROUND” and “DROUNB”

    This routine will round the ACCumulator. Registers A, B, H, and L are affected.
    0D0E-0D10
     ↳ DROUND
    LD A,(411CH)LD A,(DFACLO-1)3A 1C 41
    Load Register A with the value of the rounding byte at the location of the starting address of ACCumulator minus one.
    0D11
     ↳ DROUNB
    OR AB7
    Check to see if there is a bit to be shifted into the double precision value in the ACCumulator
    0D12-0D14
    CALL M,0D20HCALL M,DROUNAFC 20 0D
    Go move the bit into the double precision value if necessary
    0D15-0D17
    LD HL,4125HLD HL,FAC+121 25 41
    Load Register Pair HL with the address of the unpacked sign for the result.
    0D18
    LD A,(HL)7E
    Load Register A with the value of the sign for the result at the location of the memory pointer in Register Pair HL
    0D19-0D1A
    AND 80HAND 1000 0000E6 80
    Turn off some bits so we can mask the value of the sign for the result in Register A which is 1000 0000 to isolate the sign bit.
    0D1B
    0D1C
    DEC HL
    DEC HL2B
    Decrement the value of the memory pointer in Register Pair HL twice so that it points to HIGH ORDER (MSB) byte in the ACCumulator
    0D1D
    XOR (HL)AE
    Pack the SIGN and the MSB together
    0D1E
    LD (HL),A77
    Save the packed sign and MSB combination byte to the ACCumulator at the location of the memory pointer in Register Pair HL
    0D1F
    RETC9
    RETurn to CALLer

    0D20H-0D32H – DOUBLE PRECISION MATH support routine – “DROUNA”

    0D20-0D22
     ↳ DROUNA
    LD HL,411DHLD HL,DFACLO21 1D 41
    Set up HL to point to the LSB of the the ACCumulator.
    Note: 411DH-4124H holds ACCumulator
    0D23-0D24
    LD B,07H06 07
    Load Register B with the number of bytes to be bumped for the double precision value in the ACCumulator
    0D25
     ↳ DRON1
    INC (HL)34
    Top of a loop. Increment a byte of the ACCumulator at the location of the memory pointer in Register Pair HL
    0D26
    RET NZC0
    Return if the value at the location of the memory pointer in Register Pair HL isn’t equal to zero
    0D27
    INC HL23
    Increment the value of the memory pointer in Register Pair HL to point to the next highest order in the ACCumulator
    0D28
    DEC B05
    Decrement the value of the byte counter in Register B
    0D29-0D2A
    JR NZ,0D25HJR NZ,DRONA120 FA
    Loop until all of the necessary bytes have been bumped
    0D2B
    INC (HL)34
    We have bumped all the bytes, so now we need to increment the value of the exponent at the location of the memory pointer in Register Pair HL
    0D2C-0D2E
    JP Z,07B2HJP Z,OVERRCA B2 07
    Check for overflow. If the Z FLAG is set, then JUMP to the Level II BASIC error routine and display an OV ERROR message if the exponent for the double precision value in the ACCumulator is too large
    0D2F
    DEC HL2B
    Decrement the value of the memory pointer in Register Pair HL to point to the HIGH ORDER
    0D30-0D31
    LD (HL),80H36 80
    Save a new MSB+SIGN at the location of the memory pointer in Register Pair HL
    0D32
    RETC9
    RETurn to CALLer

    0D33H-0D44H – DOUBLE PRECISION MATH ROUTINE – “DADDAA” and “DADDA”

    0D33-0D35
     ↳ DADDAA
    LD HL,4127HLD HL,ARGLO21 27 41
    DADD enters here, so we need to set both HL and DE. In that case, set HL to point to ARG (a/k/a REG 2).
    Note: 4127H-412EH holds ARG (a/k/a REG 2)
    0D36-0D38
     ↳ DADDFO
    LD DE,411DHLD DE,DFACLO11 1D 41
    FOUT enters here, and DADD passes through to here. Load Register Pair DE with the starting address of ACCumulator.
    Note: 411DH-4124H holds ACCumulator
    0D39-0D3A
     ↳ DADDS
    LD C,07H0E 07
    Load Register C with the number of bytes to be added
    0D3B
    XOR AAF
    Clear the Carry flag
    0D3C
     ↳ DADDLS
    LD A,(DE)1A
    Top of a loop. Load Register A with the value in the ACCumulator at the location of the memory pointer in Register Pair DE
    0D3D
    ADC A,(HL)8E
    Add the value in ARG (a/k/a REG 2) at the location of the memory value in Register A
    0D3E
    LD (DE),A12
    Save the result of that addition into the ACCumulator at the location of the memory pointer in Register Pair DE
    0D3F
    INC DE13
    Increment the value of the memory pointer in Register Pair DE
    0D40
    INC HL23
    Increment the value of the memory pointer in Register Pair HL
    0D41
    DEC C0D
    Decrement the number of bytes to be added in Register C
    0D42-0D43
    JR NZ,0D3CHJR NZ,DADDLS20 F8
    Loop until all of the bytes for the double precision values have been added
    0D44
    RETC9
    RETurn to CALLer

    0D45H-0D56H – DOUBLE PRECISION MATH ROUTINE – “DADDAS”

    This routine subtracts numbers in the pure version. This needs to be done in two subroutines since the ROM cannot be modified.
    0D45-0D47
     ↳ DADDAS
    LD HL,4127HLD HL,ARGLO21 27 41
    DADD enters here, so we need to set both HL and DE. In that case, set Register Pair HL with the starting address of ARG (a/k/a REG 2).
    Note: 4127H-412EH holds ARG (a/k/a REG 2)
    0D48-0D4A
     ↳ DADDFS
    LD DE,411DHLD DE,DFACLO11 1D 41
    FOUT enters here, and DADD passes through to here. Load Register Pair DE with the starting address of ACCumulator.
    Note: 411DH-4124H holds ACCumulator
    0D4B-0D4C
     ↳ DADDSS
    LD C,07H0E 07
    Load Register C with the number of bytes to be subtracted
    0D4D
    XOR AAF
    Clear the Carry flag
    0D4E
     ↳ DADDLS
    LD A,(DE)1A
    Top of a loop. Load Register A with the value in the ACCumulator at the location of the memory pointer in Register Pair DE
    0D4F
    SBC A,(HL)9E
    Subtract the value in ARG (a/k/a REG 2) at the location of the memory pointer in Register Pair HL from the value in Register A
    0D50
    LD (DE),A12
    Save the result in Register A in the ACCumulator at the location of the memory pointer in Register Pair DE
    0D51
    INC DE13
    Increment the value of the memory pointer in Register Pair DE
    0D52
    INC HL23
    Increment the value of the memory pointer in Register Pair HL
    0D53
    DEC C0D
    Decrement the number of bytes to be subtracted for the double precision values in Register C
    0D54-0D55
    JR NZ,0D4EHJR NZ,DADDLS20 F8
    Loop until all of the bytes for the double precision values have been subtracted
    0D56
    RETC9
    RETurn to CALLer

    0D57H-0D68H – DOUBLE PRECISION MATH ROUTINE – “DNEGR”

    This routine will negate the signed number held in the ACCumulator. Registers A, B, C, H, and L are affected. This routine is called by DADD and DINT.
    0D57
     ↳ DNEGR
    LD A,(HL)7E
    Load Register A with the value of the sign from the ACCumulator at the location of the memory pointer in Register Pair HL
    0D58
    CPL2F
    Complement the value of the sign in Register A
    0D59
    LD (HL),A77
    Save the value of the sign in Register A at the location of the memory pointer in Register Pair HL
    0D5A-0D5C
    LD HL,411CHLD HL,DFACLO-121 1C 41
    Load Register Pair HL with the starting address of ACCumulator minus one.
    0D5D-0D5E
    LD B,08H06 08
    Load Register B with the number of bytes to be reversed
    0D5F
    XOR AAF
    Zero Register A and clear the CARRY FLAG
    0D60
    LD C,A4F
    Load Register C with the ZERO
    0D61
     ↳ DNEGR1
    LD A,C79
    Top of a loop. Load Register A with the value in Register C
    0D62
    SBC A,(HL)9E
    NEGate a byte to the ACCumulator
    0D63
    LD (HL),A77
    Save the NEGated value in Register A back to the location of the memory pointer in Register Pair HL
    0D64
    INC HL23
    Increment the value of the memory pointer in Register Pair HL
    0D65
    DEC B05
    Decrement the number of bytes to be reversed in Register B
    0D66-0D67
    JR NZ,0D61HJR NZ,DNEGR120 F9
    Loop until all of the bytes for the double precision number in the ACCumulator have been reversed
    0D68
    RETC9
    RETurn to CALLer

    0D69H-0D8FH – DOUBLE PRECISION MATH ROUTINE – “DSHFTR”

    This routine wwill shift the double precision value held in the ACCumulator to the right once.
    0D69
     ↳ DSHFTR
    LD (HL),C71
    Save the unpacked MSB of the double precision value in Register C at the location of the memory pointer in Register Pair HL
    0D6A
    PUSH HLE5
    Save the value of the memory pointer in Register Pair HL on the STACK
    0D6B-0D6C
     ↳ DSHFR1
    SUB 08HD6 08
    Subtract 8 from the number of bits to be shifted from the number of bits to be shifted in Register A
    0D6D-0D6E
    JR C,0D7DHJR C,DSHFR338 0E
    If we can shift 8 bits at once (which is then shifting a byte at a time) the NC FLAG will be set. If not, the CARRY FLAG will be sent and we need to JUMP to DSHFR3 to do it one byte at a time.
    0D6F
    POP HLE1
    Get the value of the memory pointer from the STACK and put it in Register Pair HL
    0D70
     ↳ DSHFRM
    PUSH HLE5
    Save the value of the memory pointer in Register Pair HL on the STACK. This is the entry point from DMULT.
    0D71-0D73
    LD DE,0800H11 00 08
    This LD command shifts a zero into the HIGH ORDER byte and sets up a counter
    0D74
     ↳ DSHFR2
    LD C,(HL)4E
    Top of a loop. Preserve a byte of the ACCumulator into Register C
    0D75
    LD (HL),E73
    Overwrite that location with the last byte (held in Register E)
    0D76
    LD E,C59
    Load Register E with the value in Register C so that THIS is the byte to write next.
    0D77
    DEC HL2B
    Decrement the value of the memory pointer in Register Pair HL to point to the next lower order byte
    0D78
    DEC D15
    Decrement the number of bits shifted in Register D
    0D79-0D7A
    JR NZ,0D74HJR NZ,DSHFR220 F9
    Loop until all of the bits have been shifted
    0D7B-0D7C
    JR 0D6BHJR DSHFR118 EE
    LOOP back to the top to see we can shift another 8 bits.

    0D7D-0D7EH – DOUBLE PRECISION MATH ROUTINE – “DSHFR3”

    0D7D-0D7E
     ↳ DSHFR3
    ADD 09HC6 09
    At this point, we cannot shift 8 bytes at once and need to do them individually. First, set a corrected shift counter
    0D7F
    LD D,A57
    Preserve the adjusted shift counter into Register D
    0D80
     ↳ DSHFR4
    XOR AAF
    Clear the CARRY FLAG
    0D81
    POP HLE1
    Restore the pointer to the HIGH ORDER byte into Register Pair HL
    0D82
    DEC D15
    Decrement the number of bits to be shifted in Register D
    0D83
    RET ZC8
    Return if all of the bits have been shifted
    0D84
     ↳ DSHFRA
    PUSH HLE5
    If all the bits have not been shifted, first save the pointer to the LOW ORDER byte. This is the entry from DADD and DMULT.
    0D85-0D86
    LD E,08H1E 08
    Load Register E with the counter of the number of bytes to be shifted
    0D87
     ↳ DSHFR5
    LD A,(HL)7E
    Top of a loop. Load Register A with a byte from the ACCumulator pointed to by HL
    0D88
    RRA1F
    Shift the value in Register A. RRA rotates the contents of Register A right one bit position, with Bit 0 going to the CARRY FLAG, and the CARRY FLAG going to Bit 7. RRA also can be used to divide a number in 2.
    0D89
    LD (HL),A77
    Put the rotated byte back
    0D8A
    DEC HL2B
    Decrement the value of the memory pointer in Register Pair HL so we deal with the next lower order byte
    0D8B
    DEC E1D
    Decrement the number of bytes to be shifted in Register E
    0D8C-0D8D
    JR NZ,0D87HJR NZ,DSHFR520 F9
    Loop until all of the bits have been shifted
    0D8E-0D8F
    JR 0D80HJR DSHFR418 F0
    Loop until all of the bits have been shifted

    0D90H-0D96H – DOUBLE PRECISION MATH ROUTINE – “DSHFRB”

    This is the entry from DADD and DMULT.
    0D90-0D92
     ↳ DSHFRB
    LD HL,4123HLD HL,FAC-121 23 41
    Load Register Pair HL with the address of the HIGH PRDER (MSB) of the double precision value in the ACCumulator
    0D93-0D94
    LD D,01H16 01
    Load Register D with the number of bits to be shifted
    0D95-0D96
    JR 0D84HJR DSHFRA18 ED
    Jump to 0D84H to shift HL D bits to the right

    0D97H-0DA0H – DOUBLE PRECISION MATH ROUTINE – “DSHFLC”

    This routine will rotate the ACCumulator left one. Register A, C, H, and L are affected.
    0D97-0D98
     ↳ DSHFLC
    LD C,08H0E 08
    Load Register C with the number of bytes to be shifted
    0D99
     ↳ DSHFTL
    LD A,(HL)7E
    Top of a loop. Load Register A with a byte from the ACCumulator pointed to by HL
    0D9A
    RLA17
    Rotate that byte left one bit
    0D9B
    LD (HL),A77
    Save the shifted byte (held in Register A) back to the ACCumulator at the location of the memory pointer in Register Pair HL
    0D9C
    INC HL23
    Increment the value of the memory pointer in Register Pair HL to point to the next higher order byte
    0D9D
    DEC C0D
    Decrement the byte counter in Register C
    0D9E-0D9F
    JR NZ,0D99HJR NZ,DSHFTL20 F9
    Loop until all of the bytes have been shifted
    0DA0
    RETC9
    RETurn to CALLer

    0DA1H-0DD3H – DOUBLE PRECISION MULTIPLICATION – “DMULT”

    Double-precision multiplication (ACCumulator=ACC*ARG (a/k/a REG 2)).
    Multiplies the double precision value in the ACCumulator by the value in ARG (a/k/a REG 2). The product is left in the ACCumulator.

    Note: If you wanted to multiply two double precision numbers store one operand in 411DH-4124H, and store the other in 4127H-412EH and then CALL 0DA1H. The result (in double precision format) is in 411DH-4124H in approximately 22 milliseconds.
    0DA1-0DA3
     ↳ DMULT
    CALL 0955HCALL SIGNCD 55 09
    As always, we first start by checking to see if we are operating with any ZEROes. First, go check to see if the value in the ACCumulator is equal to zero
    0DA4
    RET ZC8
    If the double precision value in the ACCumulator is equal to zero then we already have our answer (i.e., 0) in the ACCumulator, so RETurn
    0DA5-0DA7
    CALL 090AHCALL MULDVACD 0A 09
    Add the exponents and take care of processing the signs of the numbers via a GOSUB to MULDVA
    0DA8-0DAA
    CALL 0E39HCALL DMULDVCD 39 0E
    Zero out the ACCumulator and put the move the double precision value in the ACCumulator to a temporary work area via a GOSUB to DMULDV
    0DAB
    LD (HL),C71
    Put the unpacked HIGH ORDER byte (pointed to by Register Pair HL in ARG) into Register C
    0DAC
    INC DE13
    Increment Register Pair DE so that it points to the LSB of the double precision value in ARG
    0DAD-0DAE
    LD B,07H06 07
    Load Register B with the number of bytes to be figured
    0DAF
     ↳ DMULT2
    LD A,(DE)1A
    Top of a big loop. Fetch a byte of ARG (at the location pointed to by DE) to multiply by into Register A
    0DB0
    INC DE13
    Increment the value of the memory pointer in Register Pair DE to point to the next higher byte.
    0DB1
    OR AB7
    Check to see if the value in Register A is equal to zero
    0DB2
    PUSH DED5
    Save the value of the memory pointer to ARG (held in Register Pair DE) to the STACK
    0DB3-0DB4
    JR Z,0DCCHJR Z,DMULT528 17
    If Register A is zero, then we are multiplying by ZERO, so JUMP to DMULT5
    0DB5-0DB6
    LD C,08H0E 08
    Otherwise, we need to set up for another loop for bit rotation. First, load Register C with the numberof bits to be shifted
    0DB7
     ↳ DMULT3
    PUSH BCC5
    Top of a loop. Save the counters (held in Register Pair BC) to the STACK
    0DB8
    RRA1F
    Shift the multiplier value (held in Register A) one place to the right. RRA rotates the contents of Register A right one bit position, with Bit 0 going to the CARRY FLAG, and the CARRY FLAG going to Bit 7. RRA also can be used to divide a number in 2.
    0DB9
    LD B,A47
    Preserve the shifted multiplier byte into Register B
    0DBA-0DBC
    CALL C,0D33HCALL C,DADDAADC 33 0D
    If the bit of the multiplier that got shifted into the CARRY FLAG was a 1, we need to add in the old ACCumulator value via a GOSUB to DADDAA which adds the value in ARG (a/k/a REG 2) to the total in the ACCumulator
    0DBD-0DBF
    CALL 0D90HCALL DSHFRBCD 90 0D
    Rotate the production right one bit via a GOSUB to DSHFRB which shifts the value of the total in the ACCumulator
    0DC0
    LD A,B78
    Restore the shifted multiplier byte (held in Register B) back into Register A
    0DC1
    POP BCC1
    Restore the counters from the STACK into Register Pair BC
    0DC2
    DEC C0D
    Decrement the number of bits to be shifted from the ARG (tracked in Register C)
    0DC3-0DC4
    JR NZ,0DB7HJR NZ,DMULT320 F2
    If we have not hit 0 on the counter, LOOP back to 0DB7H to multiply by the next bit of the multiplier until all of the bits have been shifted
    0DC5
     ↳ DMULT4
    POP DED1
    If we are here, then we finished rotating that one byte. Top of a loop. First, get the pointer to ARG back from the STACK and put it in Register Pair DE
    0DC6
    DEC B05
    Decrement the number of bytes to be figured (tracked in Register B)
    0DC7-0DC8
    JR NZ,0DAFHJR NZ,DMULT220 E6
    Loop back to 0DAFH to multiply by the next higher order byte in ARG until all of the bytes in ARG have been figured
    0DC9-0DCB
    JP 0CD8HJP DNORMLC3 D8 0C
    If we are here then we are done (first, all the bits in each number were rotated, then that was done by all the bytes). Jump to 0CD8H to normalize and round the result.

    0DCCH – DOUBLE PRECISION MULTIPLICATION Support Routine – “DMULT5”

    This routine handles multiplying by zero.
    0DCC-0DCE
     ↳ DMULT5
    LD HL,4123HLD HL,FAC-121 23 41
    Load Register Pair HL with the address of the HIGH ORDER/MSB of the ACCumulator
    0DCF-0DD1
    CALL 0D70HCALL DSHFRMCD 70 0D
    Go shift the double precision total in the ACCumulator right one byte
    0DD2-0DD3
    JR 0DC5HJR DMULT418 F1
    Jump back into DMULT at the point where we finalize the number

    0DD4H-0DDBH – DOUBLE PRECISION CONSTANT STORAGE AREA – “DTEN” and “FTEN”

    0DD4-0DDB
     ↳ DTEN
    00 00 00 00 00 00 20 8400
    A double precision constant equal to 10 is stored here. Note: 0DD8 is also a reference point.
    0DD8-0DDB
     ↳ FTEN
    00 00 20 8400
    A double precision constant equal to 10.0 is stored here. Note: 0DD8 is also a reference point.

    0DDCH-0DE4H – DOUBLE PRECISION MATH ROUTINE – “DDIV10”

    Double precision divide routine. Divides the ACCumulator by 10. All registers are affected.
    0DDC-0DDE
     ↳ DDIV10
    LD DE,0DD4HLD DE,DTEN11 D4 0D
    Load Register Pair DE with the starting address of the double precision constant for 10
    0DDF-0DE1
    LD HL,4127HLD HL,ARGLO21 27 41
    Load Register Pair HL with the starting address of ARG (a/k/a REG 2).
    Note: 4127H-412EH holds ARG (a/k/a REG 2)
    0DE2-0DE4
    CALL 09D3HCALL VMOVECD D3 09
    GOSUB to VMOVE to move the 10 into ARG and then fall through to the DDIV routine to divide by 10.

    0DE5H-0E38H – DOUBLE PRECISION DIVISION – “DDIV”

    Double-precision division (ACCumulator=ACC / ARG).

    Divides the double precision value in the ACCumulator by the value in ARG (a/k/a REG 2). The quotient is left in the ACCumulator. All registers are affected
    To use a ROM call to divide two double precision numbers, store the dividend in 411DH-4124H, and the divisor in 4127H-412EH and then CALL 0DE5H. The result (in double precision format) is in 411DH-4124H and then pproximately 42 milliseconds. Overflow or /0 will error out and return to Level II.

    According to Vernon Hester, there is a bug this routine. Double-precision division should return a zero quotient when the dividend is zero. However, when the dividend is zero and the divisor is less than .25#, the ROM’s double-precision division produces an non-zero quotient. e.g., PRINT 0 / .24# produces a quotient of 1.171859195766034D-38. If the divisor is 2.938735877055719D-39 then the quotient is .5

    Another bug is that double-precision division should perform correctly for absolute values that are from 2.938735877055719D-39 to 1.701411834604692D+38. If the divisor is the minimum magnitude or the minimum magnitude times 2, then double-precision division errors.
    10 Z# = 1 / (2^125 + 2^125) * .25 ‘This values Z# with 2.938735877055719D-39
    20 PRINT 1 / Z# ‘displays 2.938735877055719D-39 instead of overflow
    0DE5-0DE7
     ↳ DDIV
    LD A,(412EH)LD A,(ARG)3A 2E 41
    As always, start by checking to see if we are dealing with a ZERO. First, load Register A with the value of the exponent for the double precision value in ARG (a/k/a REG 2)
    0DE8
    OR AB7
    Check to see if the double precision value in ARG (a/k/a REG 2) is equal to zero
    0DE9-0DEB
    JP Z,199AHJP Z,DV0ERRCA 9A 19
    Display a ?/0 ERROR message if the double precision value in ARG (a/k/a REG 2) is equal to zero
    0DEC-0DEE
    CALL 0907HCALL MULDVSCD 07 09
    Subtract the exponents and check the signs via a GOSUB to MULDVS
    0DEF
    0DF0
    INC (HL)
    INC (HL)34
    Increment the value of the exponent in the ACCumulator TWICE to correct the scaling
    0DF1-0DF3
    CALL 0E39HCALL DMULDVCD 39 0E
    Zero the ACCumulator and move the double precision value from ACCumulator into ARG (a/k/a REG 2)
    0DF4-0DF6
    LD HL,4151HLD HL,FBUFFR+3421 51 41
    Load Register Pair HL with the address of the extra HIGH ORDER byte we will use in ARG
    0DF7
    LD (HL),C71
    Zero the that byte
    0DF8
    LD B,C41
    Zero Register B, which will be the flag that tells us when start dividing
    0DF9-0DFB
     ↳ DDIV1
    LD DE,414AHLD DE,FBUFFR+2711 4A 41
    Top of a large loop. First, get the pointer to the end of the BUFFR into Register Pair DE
    0DFC-0DFE
    LD HL,4127HLD HL,ARGLO21 27 41
    Load Register Pair HL with the address of the END of the double precision value in ARG (a/k/a REG 2)
    0DFF-0E01
    CALL 0D4BHCALL DADDSSCD 4B 0D
    Go subtract the those two double precision values
    0E02
    LD A,(DE)1A
    Prepare to subtract from the extra HIGH ORDER byte by first loading Register A with the value at the location of the memory pointer in Register Pair DE
    0E03
    SBC A,C99
    Subtract the value in Register C from the value in Register A
    0E04
    CCF3F
    If the subtraction was good then the CARRY FLAG will be set, so complement the value of the CARRY FLAG so that NC FLAG will mean good
    0E05-0E06
    JR C,0E12HJR C,DDIV238 0B
    If the subtraction was bad, meaning that the double precision value in ARG (a/k/a REG 2) is greater than the double precision value in FBUFFER, then JUMP to DDIV2
    0E07-0E09
    LD DE,414AHLD DE,FBUFFR+2711 4A 41
    Put the pointer to the end of the BUFFR into Register Pair DE
    0E0A-0E0C
    LD HL,4127HLD HL,ARGLO21 27 41
    Load Register Pair HL with the address of the END of the double precision value in ARG (a/k/a REG 2)
    0E0D-0E0F
    CALL 0D39HCALL DADDSCD 39 0D
    Go add the double precision value in ARG (a/k/a REG 2) to the double precision value in FBUFFR
    0E10
    XOR AAF
    Clear the CARRY FLAG for the Z-80 trick in the next instruction.
    0E11-0E13
    JP C,0412HDA 12 04
    Z-80 TRICK. Since the CARRY was just cleared, this cannot ever execute and it won’t even see the next instruction. It is designed to allow for passing through but not running the next 2 instructions.
    0E14-0E16
    LD A,(4123H)LD A,(FAC-1)3A 23 41
    Prepare the check to see if we are finished dividing. First, getch the byte at FAC-1
    0E17
    0E18
    INC A
    DEC A3C
    INCrement and DECrement Register A so that the SIGN FLAG will be set without chaning the status of the CARRY FLAG
    0E19
    RRA1F
    In preparation for DROUNB, put the CARRY FLAG into the MSB via a RRA rotation. RRA rotates the contents of Register A right one bit position, with Bit 0 going to the CARRY FLAG, and the CARRY FLAG going to Bit 7. RRA also can be used to divide a number in 2.
    0E1A-0E1C
    JP M,0D11HJP M,DROUNBFA 11 0D
    If the M FLAG is set, then we are done and have 57 bits of accuracy, so JUMP to DROUNB to finish up.
    0E1D
    RLA17
    Restore the CARRY BIT to where it belongs
    0E1E-0E20
    LD HL,411DHLD HL,DFACLO21 1D 41
    Load Register Pair HL with the starting address of the LOW ORDER/LSB byte of the double precision result in the ACCumulator.
    Note: 411DH-4124H holds ACCumulator
    0E21-0E22
    LD C,07H0E 07
    Load Register C with the number of bytes to be shifted
    0E23-0E25
    CALL 0D99HCALL DSHFTLCD 99 0D
    GOSUB to DSHFTL to shit in the next bit in the quotient (held in the ACCumulator)
    0E26-0E28
    LD HL,414AHLD HL,FBUFFR+2721 4A 41
    Load Register Pair HL with the pointo the LOW ORDER byte in FBUFFR
    0E29R-0E2BH
    CALL 0D97HCALL DSHFLCCD 97 0D
    Go shift the double precision value dividend (in FBUFFR) one to the left
    0E2C
    LD A,B78
    Test to see if this was the first time by first loading Register A with the value of the counter in Register B. Note that B will get changed on the first or second subtraction
    0E2D
    OR AB7
    Set the flags based on Register B
    0E2E-0E2F
    JR NZ,0DF9HJR NZ,DDIV120 C9
    If Register B is not ZERO, then we have more to go so LOOP back up to DDIV1
    0E30-0E32
    LD HL,4124HLD HL,FAC21 24 41
    If we are here, then this was the first iteration, so we need to subtract one from the exponent to correct scaling. To do that, first load Register Pair HL with the address of the exponent for the double precision result in the ACCumulator
    0E33
    DEC (HL)35
    Decrement the value of the exponent for the double precision result in the ACCumulator at the location of the memory pointer in Register Pair HL. If (HL) is reduced to zero then we have a problem!
    0E34-0E35
    JR NZ,0DF9HJR NZ,DDIV120 C3
    Continue dividing so long as we don’t have an overflow by LOOPING back to DDIV
    0E36-0E38
    JP 07B2HJP OVERRC3 B2 07
    Display an ?OV ERROR if the exponent for the result in the ACCumulator is too small

    0E39H-0E4CH – DOUBLE PRECISION MATH ROUTINE – “DMULDV”

    This routine will transfer the double prevision number held in the ACCumulator to FBUFFR for the DMULT and DDIV routines. All registers are affected.
    0E39
     ↳ DMULDV
    LD A,C79
    We need to put the unpacked HIGH ORDER back into ARG, so first load Register A with the HIGH ORDER of the double precision value in ARG (a/k/a REG 2) in Register C
    0E3A-0E3C
    LD (412DH),ALD (ARG-1),A32 2D 41
    Save the MSB of the double precision value in ARG (a/k/a REG 2) in Register A
    0E3D
    DEC HL2B
    Decrement the value of the memory pointer in Register Pair HL to now point to the HIGH ORDER of the ACCumulator
    0E3E-0E40
    LD DE,4150HLD DE,FMLTT211 50 41
    Load Register Pair DE with the end of FBUFFR
    0E41-0E43
    LD BC,0700H01 00 07
    Load Register B with the number of bytes to be moved (which is 7) and put a zero into Register C
    0E44
     ↳ DMLDV1
    LD A,(HL)7E
    Top of a loop. Fetch a byte from the ACCumulator (tracked by Register Pair HL) into Register A
    0E45
    LD (DE),A12
    Save that byte into FBUFFR (tracked by Register Pair DE)
    0E46
    LD (HL),C71
    Zero out that location in the ACCumulator
    0E47
    DEC DE1B
    Decrement the value of the memory pointer to FBUFFR (tracked by Register Pair DE)
    0E48
    DEC HL2B
    Decrement the value of the memory pointer to the ACCumulator (tracked by Register Pair HL)
    0E49
    DEC B05
    Decrement the value of the byte counter in Register B to see if we are done
    0E4A-0E4B
    JR NZ,0E44HJR NZ,DMLDV120 F8
    Loop until the double precision value has been moved from the ACCumulator to FBUFFR
    0E4C
    RETC9
    RETurn to CALLer

    0E4DH-0E64H – LEVEL II BASIC MATH ROUTINE – “DMUL10”

    This routine multiplies the current double-precision value by 10 by adding it to itself. First the current value is moved to a saved location, and then DP add routine adds the current value to that saved value. All registers are affected
    0E4D-0E4F
     ↳ DMUL10
    CALL 09FCHCALL VMOVAFCD FC 09
    Go move the value in the ACCumulator to ARG (a/k/a REG 2)
    0E50
    EX DE,HLEB
    Since VMOVAF exits with DE pointing to ACCumulator + 1 we need to swap those so that HL points to the ACCumulator
    0E51
    DEC HL2B
    As always, the first thing we need to do is see if we are deadling with a 0. First, decrement the value of the memory pointer in Register Pair HL to point to the exponent of the number in the ACCumulator
    0E52
    LD A,(HL)7E
    Fetch the exponent from the ACCumulator
    0E53
    OR AB7
    Check to see if the value in the ACCumulator is equal to zero
    0E54
    RET ZC8
    Return if the value in the ACCumulator is equal to zero
    0E55-0E56
    ADD 02HC6 02
    Add two to the exponent which is the same as multiplying the ACCumulator by 4
    0E57-0E59
    JP C,07B2HJP C,OVERRDA B2 07
    Display an ?OV ERROR if the adjusted exponent in Register A is too large
    0E5A
    LD (HL),A77
    Save the adjusted exponent back into the ACCumulator at the location of the memory pointer in Register Pair HL
    0E5B
    PUSH HLE5
    Save pointer to the ACCumulator onto the STACK
    0E5C-0E5E
    CALL 0C77HCALL DADDCD 77 0C
    Add in that number one more time (so now it is time 5) by GOSUBing to the DOUBLE PRECISION ADD function (whcih adds the double precision value in ARG (a/k/a REG 2) to the value in the ACCumulator. Result is left in the ACCumulator)
    0E5F
    POP HLE1
    Get the memory pointer to the ACCumulator from the STACK and put it in Register Pair HL
    0E60
    INC (HL)34
    Add 1 to the exponent, thus doubling the number.
    0E61
    RET NZC0
    Return if overflow didn’t occur
    0E62-0E64
    JP 07B2HJP OVERRC3 B2 07
    Display an ?OV ERROR if the exponent in the ACCumulator at the location of the memory pointer in Register Pair HL is too large

    0E65H-0F88H – ASCII to Double Precision Converter – “FINDBL”

    This routine converts an ASCII string (pointed to by HL) to a double-precision value and stores it in the ACCumulator. The NTF is fixed accordingly. The string must be terminated with a , or zero byte. Note that the ARG (a/k/a REG 2) is destroyed in the process and that HL will point to the delimiter at the end of the string. The string formats must follow the same rules as in BASIC. All registers are affected

    On entry (HL) must point to the first character in the string buffer, with the first character being in A. On exit, the the double precision number is left in the ACCumulator.

    In processing, the digits are packed into the ACCumulator as an integer, with tracking for the decimal point. C=80H if we have not seen a decimal point, and 00H if we have. Register B holds the number of digits after the decimal point.

    At the end, Register B and the exponent (held in Register E) are used to determine how many times we multiply or divide the number by 10 to get the correct number.
    0E65-0E67
     ↳ FINDBL
    CALL 0778HCALL ZEROCD 78 07
    GOSUB to ZERO to zero the ACCumulator
    0E68-0E6A
    CALL 0AECHCALL VALDBLCD EC 0A
    GOSUB to VALDBL to force the VALTYP to to double precision
    0E6B
    OR 0AFH
    F6 AFF6 AF
    Part of a Z-80 Trick. If passing through, the next instruction of XOR A will not execute. This is done so that if passing through, the XOR A doesn’t cause us to CALL MAKINT. If the next instruction is JUMPed to, and executes, MAKINT will be CALLed

    0E6CH – ASCII to Binary Converter – “FIN”

    A call to 0E6CH converts the ASCII string pointed to by HL to binary. If the value is less than 2** 16 and does not contain a decimal point or an E or D descriptor (exponent), the string will be converted to its integer equivalent. If the string contains a decimal point or an E, or D descriptor or if it exceeds 2** 16 it will be converted to single or double precision. The binary value will be left in the ACCumulator and the mode flag will be to the proper value.

    Evaluate a numeric string that begins at the address pointed to by the HL Register Pair, store it in ACCUM and set the NTF. This routine stops as soon as it encounters a character that is not part of the number (it will return a value of zero if no valid numeric characters are found). It will accept signed values in Integer, Real or Scientific Notation. Number returned will be in integer format if possible, else single precision unless the string has over seven digits (not including exponent), in which case number will be returned as double precision.

    This routine will convert the ASCII string pointed to by register pair HL to binary. The result will be returned in the ACCumulator, and the number type flag will be updated accordingly. The routine will convert the ASCII string to the least amount of precision required.

    Note: If you wanted to do this conversion via a ROM call, first have the characters assembled in consecutive memory locations, with either a comma or a 00H at the end. Load HL with the address of the first character. Call 0E6CH. If the output can be an integer, it will be in 4121H-4122H (with 40AFH being a 2). If the output has to be single precision, it will be in 4121H-4124H (with 40AFH being a 4). If the output has to be double precision, it will be in 411DH-4124H (with 40AFH being an 8).
    0E6B
    “ASTOR”
    OR AFH
    Zero register A (by issuing an OR against 1010 1111).
    This routine is the same as E65H above, except that it fixes REG 1 and NTF to the smallest possible number type.
    0E6D
     ↳ FINCHR
    EX DE,HLEB
    Load Register Pair DE with the pointer to the current BASIC line being interpreted
    0E6E-0E70
    LD BC,00FFH01 FF 00
    Load Register Pair BC with a zero and a negative one. Register B will track the decimal point location and C will be a flag.
    0E71
    LD H,B60
    Load Register H with zero
    0E72
    LD L,B68
    Load Register L with zero. Now HL is zero.
    0E73-0E75
    CALL Z,0A9AHCALL Z,MAKINTCC 9A 0A
    A CALL to MAKINT will clear the ACCumulator and force VALTYP into Integer
    0E76
    EX DE,HLEB
    Restore the pointer to the BASIC line being interpreted into HL and zero out Register Pair DE
    0E77
    LD A,(HL)7E
    Retrieve the first character at at the location of the current input buffer pointer in Register Pair HL
    0E78-0E79
    CP 2DHCP “-“FE 2D
    Check to see if the character at the current position in the string being interpreted is a
    0E7A
    PUSH AFF5
    Save the sign in Register Pair AF on the STACK
    0E7B-0E7D
    JP Z,0E83HJP Z,FINCCA 83 0E
    If the character at the current position in the string being interpreted is a then JUMP to FINC to ignore it
    0E7E-0E7F
    CP 2BHCP “+”FE 2B
    Check to see if the character at the current position in the string being interpreted is a
    0E80-0E81
    JR Z,0E83HJR Z,FINC28 01
    If the character at the current position in the string being interpreted is a then JUMP to FINC to process it
    0E82
    DEC HL2B
    Decrement the value of the current input buffer pointer in Register Pair HL to point to the first character in the string being interpreted

    0E83H – Process a + or at the location of the current input buffer.

    0E83
     ↳ FINC
    RST 10HCHRGETD7
    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 (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)
    0E84-0E86
    JP C,0F29HJP C,FINDIGDA 29 0F
    If the character at the location of the current input buffer pointer in Register A is numeric then JUMP to FINDIG
    0E87-0E88
    CP 2EHCP “.”FE 2E
    Check to see if the character at the location of the current input buffer pointer in Register A is a .
    0E89-0E8B
    JP Z,0EE4HJP Z,FINDPCA E4 0E
    Jump if the character at the location of the current input buffer pointer in Register A is a .
    0E8C-0E8D
    CP 45HCP “E”FE 45
    Check to see if the character at the location of the current input buffer pointer in Register A is an E (which is a single precision exponent)
    0E8E-0E8F
    JR Z,0EA4HJR Z,FINEX28 14
    Jump if the character at the location of the current input buffer pointer in Register A is an E
    0E90-0E91
    CP 25HCP “%”FE 25
    Check to see if the character at the location of the current input buffer pointer in Register A is a %
    0E92-0E94
    JP Z,0EEEHJP Z,FININTCA EE 0E
    Jump to FININT (since this HAS to be an integer) if the character at the location of the current input buffer pointer in Register A is a %
    0E95-0E96
    CP 23HCP “#”FE 23
    Check to see if the character at the location of the current input buffer pointer in Register A is a #
    0E97-0E99
    JP Z,0EF5HJP Z,FINDBFCA F5 0E
    Jump to FINDBF (since this needs to be forced into double precision) if the character at the location of the current input buffer pointer in Register A is a #
    0E9A-0E9B
    CP 21HCP “!”FE 21
    Check to see if the character at the location of the current input buffer pointer in Register A is a !
    0E9C-0E9E
    JP Z,0EF6HJP Z,FINSNFCA F6 0E
    Jump to FINSNF (since this needs to be forced into single precision) if the character at the location of the current input buffer pointer in Register A is a !
    0E9F-0EA0
    CP 44HCP “D”FE 44
    Check to see if the character at the location of the current input buffer pointer in Register A is a D
    0EA1-0EA2
    JR NZ,0EC7HJR NZ,FINE20 24
    If the character ISN’T a D, then we must be finished with the number, so JUMP to FINE
    0EA3
     ↳ FINEX1
    OR AB7
    Set the flags according to the value of the character at the location of the current input buffer pointer in Register A

    0EA4H – Inside the ASCII TO BINARY CONVERTER routine. Process a E at the location of the current input buffer.

    0EA4-0EA6
     ↳ FINEX
    CALL 0EFBHCALL FINFRCCD FB 0E
    Convert the current value in the ACCumulator to either single precision or double precision
    0EA7
    PUSH HLE5
    Save the current input buffer pointer to the string being processed (tracked in Register Pair HL) to the STACK
    0EA8-0EAA
    LD HL,0EBDHLD HL,FINEC21 BD 0E
    Load Register Pair HL with the return address to the FINEC routine
    0EAB
    EX (SP),HLE3
    Swap (SP) and HL, so that the return address goes into Register Pair HL and the current input buffer pointer to the text string goes to the top of the STACK
    0EAC
    RST 10HCHRGETD7
    Next we need the first character of the exponent. 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.

    The RST 10H routine parses the characters starting at HL+1 for the first non-SPACE,non-09H,non-0BH character it finds. On exit, Register A will hold that character, and the C FLAG is set if its alphabetic, and NC FLAG if its alphanumeric. All strings must have a 00H at the end.
    0EAD
    DEC D15
    Decrement the value in Register D to turn the sign of the exponent to NEGATIVE
    0EAE-0EAF
    CP 0CEHCP “-“FE CE
    Check to see if the character at the location of the current input buffer pointer in Register A is a token
    0EB0
    RET ZC8
    If the character at the location of the current input buffer pointer in Register A is a minus sign token then RET
    0EB1-0EB2
    CP 2DHCP “-“FE 2D
    Check to see if the character at the location of the current input buffer pointer in Register A is a sign (not token)
    0EB3
    RET ZC8
    If the character at the location of the current input buffer pointer in Register A is a minus sign then RET
    0EB4
    INC D14
    If we are here then the exponent is still positive, so increment the value in Register D to re-set that flag, as we are now going to process the notations for positive
    0EB5-0EB6
    CP 0CDHCP “+”FE CD
    Check to see if the character at the location of the current input buffer pointer in Register A is a + token (0CDH)
    0EB7
    RET ZC8
    Return if the character at the location of the current input buffer pointer in Register A is a + token (CDH)
    0EB8-0EB9
    CP 2BHCP “+”FE 2B
    Check to see if the character at the location of the current input buffer pointer in Register A is a +
    0EBB
    RET Z2B
    Return if the character at the location of the current input buffer pointer in Register A is a +
    0EBA
    DEC HLC8
    If we are still here then the first character wasn’t a sign, so we are going to need to check it for a digit. Since CHARGET INC’s HL, we need to DEC HL
    0EBC
    POP AFF1
    Discard the FINCE return address as we no longer need it … we are now passing right to it!
    0EBD
    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.
    0EBC
     ↳ FINEC
    RST 10HCHRGETF1
    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.

    The RST 10H routine parses the characters starting at HL+1 for the first non-SPACE,non-09H,non-0BH character it finds. On exit, Register A will hold that character, and the C FLAG is set if its alphabetic, and NC FLAG if its alphanumeric. All strings must have a 00H at the end.
    0EBE-0EC0
    JP C,0F94HJP C,FINEDGDA 94 0F
    If the character at the location of the input buffer pointer in Register A is numeric, then JUMP to FINEDG to pack the digit into the exponent
    0EC1
    INC D14
    If we didn’t JUMP away to FINEDG, then we didn’t get a digit, so we need to adjust the sign of the exponent again … to positive by INCrementing the value in Register D
    0EC2-0EC3
    JR NZ,0EC7HJR NZ,FINE20 03
    So long as the exponent isn’t a ZERO, JUMP to FINE to skip over the handling of a negative exponent
    0EC4
    XOR AAF
    If we are here, then the exponent is negative. Zero Register A
    0EC5
    SUB E93
    NEGate the value of the exponent in Register E (i.e., A = 0 – E)
    0EC6
    LD E,A5F
    Load Register E with the negated version of itself
    0EC7
     ↳ FINE
    PUSH HLE5
    Save the current input buffer pointer to the string being converted (tracked in Register Pair HL) to the STACK
    0EC8
    LD A,E7B
    Load Register A with the value of the exponent in Register E
    0EC9
    SUB B90
    Subtract the value in Register B from the exponent in Register A to get the number of times we have to multiply or divide by 10
    This “FINE2” routine will multiply or divide by 10 the correct number of times. If A=0 the number is an integer.
    0ECA-0ECC
     ↳ FINE2
    CALL P,0F0AHCALL P,FINMLTF4 0A 0F
    If the P FLAG is set, then we need to multiply. So multiply the current value by ten
    0ECD-0ECF
    CALL M,0F18HCALL M,FINDIVFC 18 0F
    If the M FLAG is set, then we need to divide. So multiply the current value by ten
    0ED0-0ED1
    JR NZ,0ECAHJR NZ,FINE220 F8
    Whichever of those two routines applied, if they returned a NZ then we need to do it again … so Loop until the value is adjusted correctly
    Next we need to put the correct sign on the number.
    0ED2
    POP HLE1
    Get the value of the current input buffer pointer of the string being parsed from the STACK and put it in Register Pair HL
    0ED3
    POP AFF1
    Get the sign value from the STACK and put it in Register A
    0ED4
    PUSH HLE5
    Save the value of the current input buffer pointer of the string being parsed in Register Pair HL on the STACK
    0ED5-0ED7
    CALL Z,097BHCALL Z,VNEGCC 7B 09
    If the Z FLAG is set, then convert the current value to negative
    0ED8
    POP HLE1
    Get the value of the current input buffer pointer of the string being parsed from the STACK and put it in Register Pair HL
    Next we want -32768 to be an integer (it would be single precision at this point)
    0ED9
    RST 20HGETYPEE7
    We need to check the value of the current number type flag, so we call the TEST DATA MODE routine at RST 20H which determines the type of the current value in the ACCumulator and returns a combination of STATUS flags and unique numeric values in the register A according to the data mode flag (40AFH). The results are returned as follows:
    IntegerNZ/C/M/E and A is -1
    StringZ/C/P/E and A is 0
    Single PrecisionNZ/C/P/O and A is 1
    Double PrecisionNZ/NC/P/E and A is 5.
    0EDA
    RET PEE8
    If that test shows we have anything other than a SINGLE PRECISION number, then we do no thave -32678, so RETurn
    0EDB
    PUSH HLE5
    If we are here, then we have a single preciosin number. Save the value of the current input buffer pointer of the string being parsed in Register Pair HL to the STACK
    0EDC-0EDE
    LD HL,0890HLD HL,POPHRT21 90 08
    Load Register Pair HL with the return address of the POPHRT routine because CONIS2 does funny things to the stack.
    0EDF
    PUSH HLE5
    Save the value of the return address in Register Pair HL on the STACK
    0EE0-0EE2
    CALL 0AA3HCALL CONIS2CD A3 0A
    Check to see if we have -32768 via a GOSUB to CONIS2 which will convert the current value in the ACCumulator to an integer if possible
    0EE3
    RETC9
    RETurn to CALLer. If we didn’t have -32768 then this will RETurn to POPHRT

    0EE4 – Math Routine – “FINDP”

    This routine checks to see if we have seen TWO decimal points and to set the decimal point flag. We jumped here when we found a single decimal point.
    0EE4
     ↳ FINDP
    RST 20HGETYPEE7
    We need to check the value of the current number type flag, so we call the TEST DATA MODE routine at RST 20H which determines the type of the current value in the ACCumulator and returns a combination of STATUS flags and unique numeric values in the register A according to the data mode flag (40AFH). The results are returned as follows:
    Variable TypeFlagsRegister A
    IntegerNZ/C/M/E-1
    StringZ/C/P/E0
    Single PrecisionNZ/C/P/O1
    Double PrecisionNZ/NC/P/E5
    0EE5
    INC C0C
    Increment the value in Register C to adjust the flag
    0EE6-0EE7
    JR NZ,0EC7HJR NZ,FINE20 DF
    If the INC C is NOT ZERO then we have 2 decimal points, so we are DONE.
    0EE8-0EEA
    CALL C,0EFBHCALL C,FINFRCDC FB 0E
    If we are still here, then we have 1 decimal point, so convert the ACCumulator to single prevision via a GOSUB to 0EFBH to convert the current value in the ACCumulator to single precision
    0EEB-0EED
    JP 0E83HJP FINCC3 83 0E
    Jump to 0E83H to continue looking for digits

    0EEE – Math Routine – “FININT”

    0EEE
     ↳ FININT
    RST 20HGETYPEE7
    We need to check the value of the current number type flag, so we call the TEST DATA MODE routine at RST 20H which determines the type of the current value in the ACCumulator and returns a combination of STATUS flags and unique numeric values in the register A according to the data mode flag (40AFH). The results are returned as follows:
    Variable TypeFlagsRegister A
    IntegerNZ/C/M/E-1
    StringZ/C/P/E0
    Single PrecisionNZ/C/P/O1
    Double PrecisionNZ/NC/P/E5
    0EEF-0EF1
    JP P,1997HJP P,SNERRF2 97 19
    If that test shows anything but an INTEGER, jump to the Level II BASIC error routine and display a ?SN ERROR message
    0EF2
     ↳ INFINE
    INC HL23
    Top of a loop. If we are here, then we have something other than a single precision number. Next we move past the % character at the input buffer pointer to the sting being processed (tracked in Register Pair HL). We know this is the last character (a trailing %).
    0EF3-0EF4
    JR 0EC7HJR FINE18 D2
    We are now done, so Jump to 0EC7H to finish.
    0EF5
     ↳ FINDBF
    OR AB7
    If we are here then we need to force double precision, so set the NZ FLAG
    0EF6-0EF8
     ↳ FINSNF
    CALL 0EFBHCALL FINFRCCD FB 0E
    Force a type conversion via a GOSUB to FINFRC to convert the current value in the ACCumulator to either single precision or double precision, based on the concents of Register A (Z=Force to Single or NZ=Force to Double)
    0EF9-0EFA
    JR 0EF2HJR INFINE18 F7
    Bump the pointer in HL and go to FINE via a JUMP to INFINE

    0EFB – Math Routine – “FINFRC”

    This routine will force the ACCumulator to be either single precision or double precision based on the Z FLAG. Z FLAG = Force to single precision; NZ FLAG = Force to double precision.
    0EFB
     ↳ FINFRC
    PUSH HLE5
    Save the value of the current input buffer pointer of the string being parsed in Register Pair HL on the STACK
    0EFC
    PUSH DED5
    Save the exponent (held in Register Pair DE) to the STACK
    0EFD
    PUSH BCC5
    Save the decimal point information (held in Register Pair BC) to the STACK
    0EFE
    PUSH AFF5
    Save the sp/dp value flag for the conversion (held in Register A) to the STACK
    0EFF-0F01
    CALL Z,0AB1HCALL Z,FRCSNGCC B1 0A
    If the Z FLAG is set, call the CONVERT TO SINGLE PRECISION routine at 0AB1H (which converts the contents of ACCumulator from integer or double precision into single precision)
    0F02
    POP AFF1
    Restore the sp/dp value flag for the conversion from the STACK and put it in Register Pair AF
    0F03-0F05
    CALL NZ,0ADBHCALL NZ,FRCDBLC4 DB 0A
    If the NZ FLAG is set, Call the CONVERT TO DOUBLE PRECISION routine at 0ADBH (where the contents of ACCumulator are converted from integer or single precision to double precision)
    0F06
    POP BCC1
    Restore the decimal point information from the STACK and put it in Register Pair BC
    0F07
    POP DED1
    Restore the exponent from the STACK and put it in Register Pair DE
    0F08
    POP HLE1
    Restore the value of the current input buffer pointer of the string being parsed from the STACK and put it in Register Pair HL
    0F09
    RETC9
    RETurn to CALLer

    0F0A – Math Routine – “FINMUL” and “FINMLT”

    This subroutine multiplies a number by 10 once. The original ROM source notes that the reason this is a subroutine is that it can also double as a check to see if A is ZERO, thus saving bytes. All registers are affected.
    0F0A
     ↳ FINMUL
    RET ZC8
    If the exponent is ZERO then exit right back out
    0F0B
     ↳ FINMLT
    PUSH AFF5
    Save the exponent (held in Register Pair AF) to the STACK. FOUT enters the routine here.
    0F0C
    RST 20HGETYPEE7
    We need to check the value of the current number type flag, so we call the TEST DATA MODE routine at RST 20H which determines the type of the current value in the ACCumulator and returns a combination of STATUS flags and unique numeric values in the register A according to the data mode flag (40AFH). The results are returned as follows:
    Variable TypeFlagsRegister A
    IntegerNZ/C/M/E-1
    StringZ/C/P/E0
    Single PrecisionNZ/C/P/O1
    Double PrecisionNZ/NC/P/E5
    0F0D
    PUSH AFF5
    Save exponent and the value type from AF to the STACK
    0F0E-0F10
    CALL PO,093EHCALL PO,MUL10E4 3E 09
    If that test shows SINGLE PRECISION, go to 093EH to multiply the current value in the ACCumulator by “10.0”
    0F11
    POP AFF1
    Get the exponent and the value type from the STACK back into AF
    0F12-0F14
    CALL PE,0E4DHCALL PE,DMUL10EC 4D 0E
    If that test shows DOUBLE PRECISION, go to 0E4DH to multiply the current value in the ACCumulator by “10D0”
    0F15
    POP AFF1
    Get the exponent and the value type from the STACK and put it in Register Pair AF
    0F16
     ↳ DCRART
    DEC A3D
    Decrement the exponent (held in Register A) since we have now multiplied by 1 since (x^10 = 10x^9).
    0F17
    RETC9
    RETurn to CALLer

    0F18 – Math Routine – “FINDIV”

    This subroutine divides a number by 10 once. FIN and FOUT use this routine. Registers A, B, and C are affected.
    0F18
     ↳ FINDIV
    PUSH DED5
    Preserve DE to the STACK for POPing at the end
    0F19
    PUSH HLE5
    Preserve HL to the STACK for POPing at the end
    0F1A
    PUSH AFF5
    Since we need to divide we need to preserve the exponent, so save the value in Register A on the STACK
    0F1B
    RST 20HGETYPEE7
    We need to check the value of the current number type flag, so we call the TEST DATA MODE routine at RST 20H which determines the type of the current value in the ACCumulator and returns a combination of STATUS flags and unique numeric values in the register A according to the data mode flag (40AFH). The results are returned as follows:
    Variable TypeFlagsRegister A
    IntegerNZ/C/M/E-1
    StringZ/C/P/E0
    Single PrecisionNZ/C/P/O1
    Double PrecisionNZ/NC/P/E5
    0F1C
    PUSH AFF5
    Save the value of the FLAGS from the RST 20H call to the STACK
    0F1D-0F1F
    CALL PO,0897HCALL PO,DIV10E4 97 08
    If that test shows SINGLE PRECISION, go to 0897H to divide the current value in the ACCumulator by “10.0”
    0F20
    POP AFF1
    Get the value from the STACK and put it in Register Pair AF
    0F21-0F23
    CALL PE,0DDCHCALL PE,DDIV10EC DC 0D
    If that test shows DOUBLE PRECISION, go to 0DDCH to divide the current value in the ACCumulator by “10D0”
    0F24
    POP AFF1
    Restore the flags from the STACK and put it in Register Pair F
    0F25
    POP HLE1
    Get the value from the STACK and put it in Register Pair HL
    0F26
    POP DED1
    Get the value from the STACK and put it in Register Pair DE
    0F27
    INC A3C
    Increment the exponent (stored in Register A) since 10x^9 = x^10
    0F28
    RETC9
    RETurn to CALLer

    0F29 – Math Routine – “FINDIG”

    This routine will pack the next digit of the number into the ACCumulator. To do this, the ACCumulator is multipled by ten to shift everything over and make room for the digit, and then the digit is added in.
    0F29
     ↳ FINDIG
    PUSH DED5
    Save the exponent (held in Register Pair DE) on the STACK
    0F2A
    LD A,B78
    We need to check where the decimal point is, so load Register A with the value in Register B
    0F2B
    ADC A,C89
    Increement the decimal place count if we are past the decimal point by adding the value in Register C to the value in Register A
    0F2C
    LD B,A47
    Save the revised decimal point location (tracked in Register B)
    0F2D
    PUSH BCC5
    Save the decimal point information (tracked in Register Pair BC) on the STACK
    0F2E
    PUSH HLE5
    Save the value of the current input buffer pointer of the string being parsed in Register Pair HL on the STACK
    0F2F
    LD A,(HL)7E
    Fetch the digit we want to pack at the location of the current input buffer pointer in Register Pair HL
    0F30-0F31
    SUB 30HSUB “0”D6 30
    Subtract 30H from the ASCII value in Register A so that it will be binary
    0F32
    PUSH AFF5
    Save the adjusted value in the digit (held in Register A) to the STACK
    0F33
    RST 20HGETYPEE7
    We need to check the value of the current number type flag, so we call the TEST DATA MODE routine at RST 20H which determines the type of the current value in the ACCumulator and returns a combination of STATUS flags and unique numeric values in the register A according to the data mode flag (40AFH). The results are returned as follows:
    Variable TypeFlagsRegister A
    IntegerNZ/C/M/E-1
    StringZ/C/P/E0
    Single PrecisionNZ/C/P/O1
    Double PrecisionNZ/NC/P/E5
    0F34-0FJ6
    JP P,0F5DHJP P,FINDGVF2 5D 0F
    If that test shows we have anything but an INTEGER, jump to FINDGV to handle the cases of a a single precision or double precision number
    If we are here, then we re packing the next digit of an integer.
    0F37-0FJ9
    LD HL,(4121H)LD HL,(FACLO)2A 21 41
    Now that we know we have an integer, put it into the ACCumulator at (HL)
    0F3A-0FJC
    LD DE,0CCDH11 CD 0C
    Load Register Pair DE with 3277 to see if we will overflow
    0F3D
    RST 18HCOMPARDF
    Now we need to check to see if the integer value in HL is greater than or equal to 0CCDH (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)
    0F3E-0F3F
    JR NC,0F59HJR NC,FINDG230 19
    If the NC FLAG is set then HL (the number we are working on) > DE (an overflow value), so the number is too big. JUMP to FING2
    0F40
    0F41
    LD D,H
    LD E,L54
    Let DE = HL
    0F42
    ADD HL,HL29
    Multiply the integer value in Register Pair HL by two
    0F43
    ADD HL,HL29
    Multiply the integer value in Register Pair HL by two. Register Pair HL now holds the original integer value times four
    0F44
    ADD HL,DE19
    Add the original integer value in Register Pair DE to the integer value in Register Pair HL. Register Pair HL now holds the original integer value times five
    0F45
    ADD HL,HL29
    Multiply the integer value in Register Pair HL by two. Register Pair HL now holds the origmal integer value times ten
    At this point, the number has shifted over to make room for the new digit in the ones place.
    0F46
    POP AFF1
    Get the binary value for the number we want to pack in from the STACK and put it in Register A
    0F47
    LD C,A4F
    Load Register C with the value of the character in Register A. Why C? The DAD routine needs it there and B is already zero.
    0F48
    ADD HL,BC09
    Add the value of the character in Register Pair BC to the newly shifted integer value in Register Pair HL
    0F49
    LD A,H7C
    We next need to test for an overflow, so load Register A with the MSB of the integer value in Register H
    0F4A
    OR AB7
    Set the flags based on the MSB
    0F4B-0F4D
    JP M,0F57HJP M,FINDG1FA 57 0F
    If the M FLAG is set, then we have overflowed, so JUMP to FINDG1
    0F4E-0F50
    LD (4121H),HLLD (FACLO),HL22 21 41
    If we are here, then we did not overflow so save the new integer back into the ACCumulator
    0F51
     ↳ FINDGE
    POP HLE1
    Restore the value of the current input buffer pointer of the string being parsed into Register Pair HL
    0F52
    POP BCC1
    Restore the the decimal point information (tracked in Register Pair BC) from the STACK
    0F53
    POP DED1
    Restore the exponent (held in Register Pair DE) from the STACK
    0F54-0F56
    JP 0E83HJP FINCC3 83 0E
    Jump to 0E83H to process the next character

    0F57 – Math Routine – “FINDG1”

    This routine handles 32768 and 32769
    0F57
     ↳ FINDG1
    LD A,C79
    Load Register A with the binary value of the character in Register C
    0F58
    PUSH AFF5
    Save the value in Register A on the STACK

    0F59 – Math Routine – “FINDG2”

    Convert integer digits into single precision digits
    0F59-0F5B
     ↳ FINDG2
    CALL 0ACCHCALL CONSICD CC 0A
    Go convert the current value in the ACCumulator to single precision
    0F5C
    SCF37
    Set the Carry flag to avoid the next instruction jumping away

    0F5D – Math Routine – “FINDGV”

    Determine if we have a single precision or a double prevision number
    0F5D-0F5E
     ↳ FINDGV
    JR NC,0F77HJR NC,FINDGD30 18
    If the current value in the ACCumulator is double precision, then JUMP to FINGD to use the double precision routine to pack in the next digit
    These next 2 instruction set up BCDE to hold “1000000”
    0F5F-0F61
    LD BC,9474H01 74 94
    Load Register Pair BC with the exponent and the MSB of a single precision constant
    0F62-0F64
    LD DE,2400H11 00 24
    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 1E6
    0F65-0F67
    CALL 0A0CHCALL FCOMPCD 0C 0A
    Call the SINGLE PRECISION COMPARISON routine at 0A0CH to algebraically compare the single precision value in BC/DE (which is 1000000) to the single precision value ACCumulator. The results are stored in A as follows:
    • A=0 if ACCumulator = BCDE
    • A=1 if ACCumulator>BCDE; and
    • A=FFH if ACCumulator<BCDE.
    0F68-0F6A
    JP P,0F74HJP P,FINDG3F2 74 0F
    If the single precision value in the ACCumulator is greater than or equal to 1000000 then we need to change from single precision to double precision, so JUMP to FINDG3 to covert the number to double precision.
    0F6B-0F6D
    CALL 093EHCALL MUL10CD 3E 09
    Go multiply the single precision value in the ACCumulator by 10
    0F6E
    POP AFF1
    Get the binary value of the number we want to pack in from the STACK and put it in Register A
    0F6F-0F71
    CALL 0F89HCALL FINLOGCD 89 0F
    Add the value in Register A to the single precision value in the ACCumulator
    0F72-0F33
    JR 0F51HJR FINDGE18 DD
    Jump to 0F51H to get the flags off of the stack and finish.

    0F74 – Math Routine – “FINDG3” and “FINDGD”

    The routine will convert a 7 digit single precision number into a double precision number
    0F74-0F76
     ↳ FINDG3
    CALL 0AE3HCALL CONDSCD E3 0A
    Go convert the single precision value in the ACCumulator to double precision
    This routine will pack in a digit into a double precision number
    0F77-0F79
     ↳ FINDGD
    CALL 0E4DHCALL DMUL10CD 4D 0E
    Go multiply the double precision value in the ACCumulator by ten
    0F7A-0F7C
    CALL 09FCHCALL VMOVAFCD FC 09
    Go move the double precision value in the ACCumulator to ARG (a/k/a REG 2)
    0F7D
    POP AFF1
    Get the binary value for the number to pack in from the STACK and put it in Register A
    0F7E-0F80
    CALL 0964HCALL FLOATCD 64 09
    Go convert that binary value to single precision
    0F81-0F83
    CALL 0AE3HCALL CONDSCD E3 0A
    Go convert that single precision value to double precision
    0F84-0F86
    CALL 0C77HCALL DADDCD 77 0C
    Call the DOUBLE PRECISION ADD function (whcih adds the double precision value in ARG (a/k/a REG 2) to the value in the ACCumulator. Result is left in the ACCumulator)
    0F87-0F88
    JR 0F51HJR FINDGE18 C8
    Jump to 0F51H to get the flags off of the stack and finish.

    0F89H-0F93H – SINGLE PRECISION MATH ROUTINE – “FINLOG”

    This is a subroutine for FIN and for LOG
    0F89-0F8B
     ↳ FINLOG
    CALL 09A4HCALL PUSHFCD A4 09
    Call 09A4 which moves the SINGLE PRECISION value in the ACCumulator to the STACK (stored in LSB/MSB/Exponent order)
    0F8C-0F8E
    CALL 0964HCALL FLOATCD 64 09
    Go convert the value in Register A to a single precision floating number and return with the result in the ACCumulator
    0F8F
    POP BCC1
    Clear off the stack
    0F90
    POP DED1
    Clear off the stack
    0F91-0F93
    JP 0716HJP FADDC3 16 07
    Jump to the SINGLE PRECISION ADD routine at 0716H (which adds the single precision value in (BC/DE) to the single precision value in the ACCumulator. The sum is left in the ACCumulator)

    0F94H-0FA6H – LEVEL II BASIC MATH ROUTINE – “FINEDG”

    Pack in a digit of the exponent. This is done by multiplying the old exponent by 10 and then adding in the desired digit. Note: This routine does NOT check for overflow.
    0F94
     ↳ FINEDG
    LD A,E7B
    Load Register A with the value of the exponent in Register E
    0F95-0F96
    CP 0AHFE 0A
    Test for overfly by checking to see if the value of the exponent in Register A is greater than or equal to 10. This is necessary because if it overflows the Register E will be corrupted
    0F97-0F98
    JR NC,0FA2HJR NC,FINEDO30 09
    If the value of the exponent in Register A is greater than or equal to 10 then we already have two digits, so JUMP to FINEDO to keep processing
    0F99
    RLCA07
    Multiply the value in Register A by two
    0F9A
    RLCA07
    Multiply the value in Register A by two. Register A now holds the original value of the exponent times four
    0F9B
    ADD A,E83
    Add the original value of the exponent in Register E to the adjusted value of the exponent in Register A
    0F9C
    RLCA07
    Multiply the value in Register A by two. Register A now holds the original value of the exponent times ten
    0F9D
    ADD A,(HL)86
    Add the value of the number at the location of the input buffer pointer in Register Pair HL to the adjusted value in Register A
    0F9E-0F9F
    SUB 30HSUB “0”D6 30
    Convert the adjusted value in Register A to it’s binary equivalent (which is subtracting 0011 0000)
    0FA0
    LD E,A5F
    Save the adjusted exponent into Register E
    0FA1-0FA3
    JP M,321EHFA 1E 32
    Z-80 TRICK. If passing through, this sill never trigger, but neither will the next instruction!
    0FA4-0FA6
    JP 0EBDHJP FINECC3 BD 0E
    Jump to 0EBDH to continue the routine

    0FA7H-0FAEH – DISPLAY MESSAGE ROUTINE – “INPRT”

    This routine is to output a floating point number.
    0FA7
     ↳ INPRT
    PUSH HLE5
    Save the line number (held in Register Pair HL) to the STACK
    0FA8-0FAA
    LD HL,1924HLD HL,INTXT21 24 19
    Load Register Pair HL with the starting address of the ” IN ” +00H message (which is 1924H)
    0FAB-0FAD
    CALL 28A7HCALL STROUTCD A7 28
    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).
    0FAE
    POP HLE1
    Get the value from the STACK and put it in Register Pair HL and then pass through to the LINPRT routine.

    0FAFH-0FBCH – CONVERT BINARY TO ASCII AND DISPLAY RESULT – “LINPRT”

    This routine converts the two byte number in the HL Register Pair (which is assumed to be an integer) to ASCII and displays it at the current cursor position on the video screen. The space for the sign at the beginning of a line is removed. All registers are affected.
    0FAF-0FB1
     ↳ LINPRT
    CALL 0A9AHCALL MAKINTCD 9A 0A
    Go save the line number (held in the ACCumulator) as an integer into Register Pair HL
    0FB2
    XOR AAF
    Zero Register A to indicate that the output should be a free format
    0FB3-0FB5
    CALL 1034HCALL FOUINICD 34 10
    Go initialize the input buffer for the ASCII conversion. This will set up the sign.
    0FB6
    OR (HL)B6
    Turn off the Z FLAG.
    0FB7-0FB9
    CALL 0FD9HCALL FOUT2CD D9 0F
    Go convert the integer value in the ACCumulator to an ASCII string. Return with Register Pair HL pointing to the result
    0FBA-0FBC
    JP 28A6HJP STROUIC3 A6 28
    Go display the message pointed to by Register Pair HL

    0FBDH-1363H – BINARY TO ASCII CONVERSION ROUTINE – “FOUT”

    According to the original ROM source code:
    This routine will output the value held in the ACCumulator according to the format specifications held in Registers A, B, and C. The ACCumulator contents are lost and all registers are affected.

    The format codes are as follows:
    • Register A:
      • Bit 7:
        • 0 means free format output, i.e. the other bits of a must be zero, trailing zeros are suppressed, a number is printed in fixed or floating point notation according to its magnitude, the number is left justified in its field, and Registers B and C are ignored.
        • 1 means fixed format output, i.e. the other bits of a are checked for formatting information, the number is right justified in its field, trailing zeros are not suppressed. this is used for print using.
      • Bit 6:
        • 0 means means don’t print the number with commas.
        • 1 means group the digits in the integer part of the number into groups of three and separate the groups by commas.
      • Bit 5: 1 means fill the leading spaces in the field with asterisks (“*”)
      • Bit 4: 1 means output the number with a floating dollar sign (“$”)
      • Bit 3: 1 means print the sign of a positive number as a plus sign (“+”) instead of a space
      • Bit 2: 1 means print the sign of the number after the number
      • Bit 1: Unused
      • Bit 0:
        • 1 means print the number in floating point notation i.e. “e notation”. If this bit is on, the comma specification (bit 6) is ignored.
        • 0 means print the number in fixed point notation. Numbers > 1e16 cannot be printed in fixed point notation.
      • Register B: The number of places in the field to the left of the decimal point (B does not include the decimal point)
      • Register C: The number of places in the field to the right of the decimal point (C includes the decimal point)
      • Note 1: B and C do not include the 4 positions for the exponent. If bit 0 is on FOUT assumes b+c <= 24 (decimal)
      • Note 2: If the number is too big to fit in the field, a percent sign (“%”) is printed and the field is extended to hold the number.
    According to other sources:
    Conversion routine. Converts the value from ACCumulator to an ASCII string delimited with a zero byte. The number type can be any of Integer, single or double-precision. After execution HL will be pointing to the start of the string. ACCumulator and ARG (a/k/a REG 2) are destroyed by the process.

    To use a ROM call to convert a number to a string of digits, and to display the latter on the video screen starting at the current cursor position, store the number in 4121H-4122H (if it’s an integer), or in 4121H-4124H (if it’s single precision), or in 411DH-4124H (if it’s double precision). Then store the variable type (2, 4, or 8, respectively) in 40AFH. Call 0FBDH and then call the WRITE MESSAGE routine at 28A7H.
    • NOTE 1: The subroutine at 28A7H is a general program for displaying a string of characters and updating the cursor position. The string to be displayed must be terminated by a zero byte, and the HL Register Pair must contain the address of the first character of the string before 28A7H is called. (The routine at 0FBDH effects this setup automatically.)
    • NOTE 2: DISK SYSTEM CAUTION: The subroutine at 28A7H has two exits to DISK BASIC, with RAM transfer points at 41C1H and 41D0H. To use this routine safely, either be certain that DISK BASIC is in place or have your assembly language program fill locations 41C1H and 41D0H with RET’s (C9H), before calling the routine.
    0FBD
     ↳ FOUT
    XOR AAF
    Zero Register A so that the format is set for free output

    0FBEH-0FC0H – FLOATING to ASCII Conversion Routine– “PUFOUT”

    This routine converts a single or double precision number in the ACCumulator to its ASCII equivalent. The ASCII value is stored at the buffer pointed to by the HL Register Pair. As the value is converted from binary to ASCII, it is formatted as it would be if a PRINT USING statement had been invoked. The format modes that can be specified are selected by loading the following values into the A, B, and C registers as follows:
    • A=0 means do not edit; this is a binary to ASCII conversion
    • A=X means edit as follows: Bit 7=1 means edit the value, Bit 6=Print commas every third digit, Bit 5=Include leading asterisks, Bit 4=Print a leading $, Bit 3=Sign Follows Value, and Bit 1=Exponential Notation
    • B = The number of digits to the left of the decimal point.
    • C = The number of digits after the decimal point.
    Note: If you wanted to convert any integer/single/double into its character string, store the variable in 4121H-4122H for integer, 4121H-4124H for single, or in 411DH-4124H for double. Then load 40AFH with a 2, 4, or 8 depending on whether that variable was integer, single, or double. Then call 0FBDH. Upon return, the character string is stored in 4130H and on, ending with a 00H.
    0FBE-0FC0
     ↳ PUFOUT
    CALL 1034HCALL FOUINICD 34 10
    Save the formt specification in Register A and put a space for positive numbers into the buffer and loads HL with the starting address of the input buffer
    0FC1-0FC2
    AND 08HE6 08
    Turn off some bits so we can check the value of Register A to see if a plus sign is required to be included for positive numbers
    0FC3-0FC4
    JR Z,0FC7HJR Z,FOUT128 02
    If a plus sign is NOT required to be added to the ASCII output string, then Jump to 0FC7H
    0FC5-0FC6
    LD (HL),2BHLD (HL),”+”36 2B
    If we are here, then it is required, so put a into the buffer pointed to by Register Pair HL
    0FC7
     ↳ FOUT1
    EX DE,HLEB
    Load Register Pair DE with the value of the buffer pointer (held in Register Pair HL)
    0FC8-0FCA
    CALL 0994HCALL VSIGNCD 94 09
    Go determine the value of the sign for the current value in the ACCumulator
    0FCB
    EX DE,HLEB
    Restore the buffer pointer back to HL
    0FCC-0FCE
    JP P,0FD9HJP P,FOUT2F2 D9 0F
    If the P FLAG is set then we have a negative number, so we need to negate it by JUMPing to FOUT2
    0FCF-0FD0
    LD (HL),2DHLD (HL),”-“36 2D
    Save a minus sign (-) at the location of the buffer pointer in Register Pair HL
    0FD1
    PUSH BCC5
    Save the field length specifications held in B and C to the STACK
    0FD2
    PUSH HLE5
    Save the buffer pointer to the STACK
    0FD3-0FD5
    CALL 097BHCALL VNEGCD 7B 09
    GOSUB to 097BH to convert the negative value in the ACCumulator to its positive equivalent
    0FD6
    POP HLE1
    Restore the buffer pointer from the STACK into HL
    0FD7
    POP BCC1
    Restore the field length specifications from the STACK into B and C
    0FD8
    OR HB4
    Turn off the Z FLAG. This relies on the fact that FBUFR is never on page 0
    0FD9
     ↳ FOUT2
    INC HL23
    Increment the buffer pointer in Register Pair HL to where the next character will be placed
    0FDA-0FDB
    LD (HL),30H36 30
    Save an ASCII zero (0) at the location of the input buffer pointer in Register Pair HL EITHER because a “0” will ultimately go there (if we are processing in free format) OR to to reserve a space fro a floating dollar sign (if we are processing in fixed format)
    0FDC-0FDE
    LD A,(40D8H)LD A,(TEMP3)3A D8 40
    Load Register A with the format specification (held in a temporary storage location)
    0FDF
    LD D,A57
    Preserve the format specification into Register D
    0FE0
    RLA17
    Move the “free format” or “fixed format” bit into the Carry flag
    0FE1-0FE3
    LD A,(40AFH)LD A,(VALTYP)3A AF 40
    Since VNEG may have changed VALTYP, re-fetch it (as -32768 is and integer but 32768 is single-precision).
    0FE4-0FE6
    JP C,109AHJP C,FOUTFXDA 9A 10
    The comment in the original source says to JUMP to FOUTFX because “the man wants fixed formatted output here to print numbers in free format”
    0FE7-0FE9
    JP Z,1092HJP Z,FOUTZRCA 92 10
    If the Z FLAG is set, then JUMP to FOUTZR to finish it up
    0FEA-0FEB
    CP 04HFE 04
    Check to see if the current value in the ACCumulator is single or double precision
    0FEC-0FEE
    JP NC,103DHJP NC,FOUFRVD2 3D 10
    If the current value in the ACCumulator is single or double precision JUMP to FOUFRV
    0FEF-0FF1
    LD BC,0000H01 00 00
    If we are here (and didn’t jump away) then we are dealing with an INTEGER. First, set the decimal point counter and comma counter to ZERO
    0FF2-0FF4
    CALL 132FHCALL FOUTCICD 2F 13
    Call the INTEGER TO ASCII routine at 1232F to convert the integer in the ACCumulator to ASCII and stores the ASCII string in the buffer pointed to in HL. We then fall through to FOUTZS
    This routine will zero suppress the digits in FBUFFR and asterisk fill and zero suppress if necessary.
    0FF5-0FF7
     ↳ FOUTZS
    LD HL,4130HLD HL,FBUFFR+121 30 41
    Load Register Pair HL with the starting address of the buffer, which will hold the SIGN
    0FF8
    LD B,(HL)46
    Load Register B with the sign (i.e., the character at the location of the buffer pointer in Register Pair HL)
    0FF9-0FFA
    LD C,20HLD C,” “0E 20
    Load Register C with a SPACE
    0FFB-0FFD
    LD A,(40D8H)LD A,(TEMP3)3A D8 40
    Load Register A with format specifications
    0FFE
    LD E,A5F
    Put the format specifications into Register E
    0FFF-1000
    AND 20HAND 0010 0000E6 20
    MASK the format specifications (by AND against 0010 0000) to see an asterisk fill is required
    1001-1002
    JR Z,100AHJR Z,FOTZS128 07
    If we do NOT need to do an asterisk fill in the ASCII string, JUMP to FOTZS1.
    1003
    LD A,B78
    If we’re here, then we do need to do the asterisk fill, so first lets see what the sign was. Load Register A with the character at the location of the input buffer pointer in Register B
    1004
    CP CB9
    Check to see if the character at the location of the input buffer pointer in Register A is a SPACE. The Z FLAG will be set if it was a SPACE
    1005-1006
    LD C,2AHLD C,”*”0E 2A
    Load Register C with a the fill character, which, in this case, will be a
    1007-1008
    JR NZ,100AHJR NZ,FOTZS120 01
    If the character at the location of the input buffer pointer in Register A isn’t SPACEthen JUMP to FOTS1 to change the SPACEwhere the sign would be into a .
    1009
    LD B,C41
    Load Register B with the character in Register C
    1001-1002
    JR Z,100AHJR Z,FOTZS128 07
    If we do NOT need to do an asterisk fill in the ASCII string, JUMP to FOTZS1.
    1003
    LD A,B78
    If we’re here, then we do need to do the asterisk fill, so first lets see what the sign was. Load Register A with the character at the location of the input buffer pointer in Register B
    1004
    CP CB9
    Check to see if the character at the location of the input buffer pointer in Register A is a SPACE. The Z FLAG will be set if it was a SPACE
    1005-1006
    LD C,2AHLD C,”*”0E 2A
    Load Register C with a the fill character, which, in this case, will be a
    1007-1008
    JR NZ,100AHJR NZ,FOTZS120 01
    If the character at the location of the input buffer pointer in Register A isn’t SPACEthen JUMP to FOTS1 to change the SPACEwhere the sign would be into a .
    1009
    LD B,C41
    Load Register B with the character in Register C
    100A
     ↳ FOTZS1
    LD (HL),C71
    Fill the zero or the sign with the filler character held in Register C at the location of the input buffer pointer in Register Pair HL
    100B
    RST 10HCHRGETD7
    We need the next character from the buffer. Using CHRGET is, however, a RAM saving method since there is no SPACEto skip, so the RST 10H really just does INC HL and LD A,(HL)
    100C-100D
    JR Z,1022HJR Z,FOTZS428 14
    If the character at the location of the input buffer pointer in Register Pair HL is the end of the input buffer character (00H) then we are done with the number. In this casse, we need to back up and put in a ZERO, so JUMP to FOTZS4. CHRGET would have set the ZERO FLAG on any 00H or :, but there are no :going to be found.
    100E-100F
    CP 45HCP “E”FE 45
    Check to see if the character at the location of the input buffer pointer in Register A is an E
    1010-1011
    JR Z,1022HJR Z,FOTZS428 10
    If the character is an Ewe need to put a 0in the floating point nontation with the C format 0, so JUMP to FOTZS4 to put into that ZERO.
    1012-1013
    CP 44HCP “D”FE 44
    Check to see if the character at the location of the input buffer pointer in Register A is a D
    1014-1015
    JR Z,1022HJR Z,FOTZS428 0C
    If the character is an Dwe need to put a 0in the floating point nontation with the C format 0, so JUMP to FOTZS4 to put into that ZERO.
    1016-1017
    CP 30HCP “0”FE 30
    Check to see if the character at the location of the input buffer pointer in Register A is a 0
    1018-1019
    JR Z,100AHJR Z,FOTZS128 F0
    If the character is a 0then we need to suppress it, so JUMP to FOTZS1.
    101A-101B
    CP 2CHCP “,”FE 2C
    Check to see if the character at the location of the input buffer pointer in Register A is a ,
    101C-101D
    JR Z,100AHJR Z,FOTZS128 EC
    If the character is a ,then we need to suppress it, so JUMP to FOTZS1.
    101E-101F
    CP 2EHCP “.”FE 2E
    Check to see if the character at the location of the input buffer pointer in Register A is a .
    1020-1021
    JR NZ,1025HJR NZ,FOTZS220 03
    If we do not have a ., then JUMP to FOTZS2
    1022
     ↳ FOTZS4
    DEC HL2B
    If we are here then we need to back up the string and put a 0before it. First, step back one location in the string
    1023-1024
    LD (HL),30HLD (HL),”0″36 30
    Save a 0at the location of the input buffer pointer in Register Pair HL
    1025
     ↳ FOTZS2
    LD A,E7B
    Next we need to check to see if we need a floating dollar sign. First, load the format specs into Register A
    1026-1027
    AND 10HAND 0001 0000E6 10
    Check to see if a $is to be included in the ASCII string
    1028-1029
    JR Z,102DHJR Z,FOTZS328 03
    If the Z FLAG is set, then we don’t have a dollar sign, so skip the next 2 instructions (which puts in a $) if a $isn’t to be included in the ASCII string
    102A
    DEC HL2B
    Need to add a $, so first we decrement the value of the input buffer pointer in Register Pair HL …
    102B-102C
    LD (HL),24HLD (HL),”$”36 24
    … and then put a $there
    102D
     ↳ FOTZS3
    LD A,E7B
    Next we need to check to see if we need a trailing sign. First, load the format specs into Register A
    102E-102F
    AND 04HAND 0000 0100E6 04
    Turn off every bit except Bit 2 (by ANDing against 00000100). If Bit 2 was on, then NZ will be set. If Bit 2 was off, then Z will be set. So this checks to see if the sign is to follow the ASCII string
    1030
    RET NZC0
    If the sign isn’t to follow the ASCII string, then we are done so RETurn
    1031
    DEC HL2B
    Decrement the value of the input buffer pointer in Register Pair HL
    1032
    LD (HL),B70
    Save the sign (in Register B) to the location of the input buffer pointer in Register Pair HL
    1033
    RETC9
    RETurn to CALLer

    1034 – LEVEL II BASIC MATH ROUTINE– “FOUINI”

    Initially set up the format specs and put in a SPACEfor the sign of a positive number. This routine gets called by the FLOATING to ASCII Conversion Routine (at 0FBEH) and by the BINARY to ASCII Conversion Routine (at 0FAFH)
    1034-1036
     ↳ FOUINI
    LD (40D8H),ALD (TEMP3),A32 D8 40
    Save the format specification (in Register A) to 40D8H.
    Note: 40D8H-40D9H holds the temporary storage location
    1037-1039
    LD HL,4130HLD HL,FBUFFR+121 30 41
    Set up a pointer into FBUFFR, starting at FBUFFR+1 just in case the number will overflow its field, in which case there is still room in FBUFFR for the %character.
    103A-103B
    LD (HL),” “36 20
    Save a SPACEat the location of the input buffer pointer in Register Pair HL
    103C
    RETC9
    RETurn to CALLer

    103D – LEVEL II BASIC MATH ROUTINE– “FOUFRV”

    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. This will print a single or double precision number in free format
    103D-103E
     ↳ FOUFRV
    CP 05HFE 05
    Company Register A against 05H and if A < 05H, set the C FLAG. With this, the CARRY FLAG will be set if we are dealing with a double precision number.
    103F
    PUSH HLE5
    Save the pointer to the buffer (held in Register Pair HL) to the STACK
    OK, this is fun. The next instructions are supposed to set Register D to be the counter for the number of digits to display. There is no agreement on what the next two instructions do:

    “Microsoft BASIC Decoded & Other Mysteries” says it turns 04 (SP) and 08 (SP) into 08 (SP) and 10 (DP) into 09 (SP) and 0B (DP)

    “Model III ROM Commented” says it turns D into 07 (SP) and 17 (DP)

    The original ROM Source Code comment says it turns D into 04 to 06 (SP) and 10 to 20 (DP)
    1040-1041
    SBC A,00HDE 00
    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
    1042
    RLA17
    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
    1043
    LD D,A57
    Load Register D with the adjusted value of the number type in Register A
    1044
    INC D14
    Bump the value of the number type in Register D (so D will be 09H if SINGLE precision and 0BH if DOUBLE precision)
    1045-1047
    CALL 1201HCALL FOUTNVCD 01 12
    Go scale (normalize) the current value in ACCumulator so that all the significant digits will be in the integer portion (i.e., 99,999 <= X <= 999,999). Returns wihth A being the number of times the DOUBLE precision value was scaled up or down
    1048-104A
    LD BC,0300H01 00 03
    Load Register B to be the decimal point count of 3 (as we will assume it will come in E Notation), and Register C to be the comma count (currently 0).
    104B
    ADD A,D82
    Test to see if we are going to actually need E Notation by first adding the value in Register D to the value in Register A
    104C-104E
    JP M,1057HJP M,FOFRS1FA 57 10
    If D is less than .01 then we will need E Notation, so JUMP to FOFRS1
    104F
    INC D14
    Now we need to see if the number is too big. Bump the value in Register D
    1050
    CP DBA
    Compare the bumped Register D to Register A
    1051-1052
    JR NC,1057HJR NC,FOFRS130 04
    If the number is too big (i.e., greater than 10^D-1), JUMP to FOFRS1
    1053
    INC A3C
    If we are here, then we are able to display the number in fixed point notation, so we must bump the number of decimal point count
    1054
    LD B,A47
    Load Register B with the decimal point count (stored in Register A)
    1055-1056
    LD A,02H3E 02
    Set up for fixed point output. Fixed point notation has no exponent, so loading Register A with a two so that the next instruction will turn A (which is tracking the exponent) to 0.
    1057-1058
     ↳ FOFRS1
    SUB A,02HD6 02
    Compute the exponent value (which will be a zero if we were passing through), so now D-2 will be added to it
    1059
    POP HLE1
    Get the pointer to the string buffer from the STACK and put it in Register Pair HL
    105A
    PUSH AFF5
    Save the exponent value (currently in Register A) to the STACK
    105B-105D
    CALL 1291HCALL FOUTEDCD 91 12
    GOSUB to FOUTED to test to see if the number is .01 < number < .1 for purposes of putting a comma or decimal point in the input buffer if necessary
    105E-105F
    LD (HL),30HLD (HL),”0″36 30
    If the number is within that range, then add a 0at the location of the buffer pointer in Register Pair HL
    1060-1062
    CALL Z,09C9HCALL Z,INXHRTCC C9 09
    If there was no scaling, GOSUB to 09C9H to bump HL and return
    1063-1065
    CALL 12A4HCALL FOUTCVCD A4 12
    Next we need to convert the number to decimal digits by a GOSUB to FOUTCV which will convert the binary value in ACCumulator to ASCII, the result being stored in the input buffer pointer
    The FOFRS2 routine will suppress trailing zeroes.
    1066
     ↳ FOFRS2
    DEC HL2B
    Backspace to the last character by decrementing the value of the input buffer pointer in Register Pair HL
    1067
    LD A,(HL)7E
    Fetch the last character (at the location of the input buffer pointer in Register Pair HL)
    1068-1069
    CP 30HCP “0”FE 30
    Check to see if the value in Register A is a 0
    106A-106B
    JR Z,1066HJR Z,FOFRS228 FA
    If it is a zero, then we want to suppress it, so loop back to FOFRS2 to decrement again and keep suppressing ending zeroes.
    At this point, all trailing zeroes are now gone and HL points to the last non-zero character.
    106C-106D
    CP 2EHCP “.”FE 2E
    Check to see if the last character in the buffer (now that all ending zeroes have been supressed) is is a .
    106E-1070
    CALL NZ,09C9HCALL NZ,INXHRTC4 C9 09
    If its NOT a decimal point, GOSUB to bump the value of the input buffer pointer in Register Pair HL. Otherwise, HL is now sitting at the decimal point to suppress that character too.
    1071
    POP AFF1
    Restore the exponent from the STACK into Register A
    1072-10731
    JR Z,1093HJR Z,FOUTDN28 1F
    If the exponent is zero then we are done, so jump to 1093H. Otherwise, pass down to FOFLDN.

    1074 – LEVEL II BASIC MATH ROUTINE– “FOFLDN”

    This routine will put the exponent and a Dor Einto the buffer. On entry, Register A holds the exponent and it is assumed that all FLAGs are set correctly.
    1074
     ↳ FOFLDN
    PUSH AFF5
    Save the exponent (stored in A) to the STACK
    1075
    RST 20HGETYPEE7
    Determine the precision by checking the value of the current number type flag. In this case, this is a really cool trick. The purpose is to load a bit into the CARRY flag if we are going to display an Einstead of a D. We start off with 1/2 of the ascii value for the “D”, then, in 1 instruction, multiply it by 2 and add in the carry bit. So if the CARRY FLAG is off, then it is a “D” and if the CARRY FLAG is on, then it is an “E”
    1076-1077
    LD A,22H3E 22
    Load Register A with the starting value for a D or E character. In this case, A is set for 1/2 of the ASCII code for D
    1078
    ADC A,A8F
    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 Dif the value is SINGLE precision and an Eif the value is DOUBLE precision
    1079
    LD (HL),A77
    Save the exponent designation (the Dor Ein Register A) at the location of the input buffer pointer in Register Pair HL
    107A
    INC HL23
    Bump the value of the buffer pointer in Register Pair HL, which is the first position of the exponent in the buffer
    107B
    POP AFF1
    Get the value of the exponent from the STACK and put it in Register A
    107C-107D
    LD (HL),2BHLD (HL),”+”36 2B
    Save a +at the location of the input buffer pointer in Register Pair HL. This is done to save bytes. Instead of testing for + or – and then putting in the appropriate character, a +is put in, and then it is overwritten if a should be there.
    107E-1080
    JP P,1085HJP P,FOUCE1F2 85 10
    If the exponent is positive, then the +we just put into the buffer (and HL is still pointing to that location) is good, so skip the next 3 instructions (by jumping to 1085H) if the exponent is positive
    1081-1082
    LD (HL),2DHLD (HL),”-“36 2D
    Save a (which is 2DH) at the location of the input buffer pointer in Register Pair HL, thus overwriting the initially placed +in that same location
    1083
    CPL2F
    If we are here then we have a negative exponent (or we would have jumped to 1085H back in 107EH), so convert the negative exponent to positive by reversing the value of the exponent in Register A
    1084
    INC A3C
    We also need to bump the value of the exponent in Register A by 1 when switching from negative to positive. We then pass through and rejoin where we would have jumped if the number had been positive.

    1085 – LEVEL II BASIC MATH ROUTINE– “FOUCE1” and “FOUCE2”

    This routine will calculate the two digit exponent.
    1085-1086
     ↳ FOUCE1
    LD B,2FHLD B,”0″-106 2F
    At this point, the exponent is positive. Next step is to load Register B with a 0minus one. This is because the next instruction, which is the top of a loop, bumps it by one.
    1087
     ↳ FOUCE2
    INC B04
    Top of a loop. Bump the value of the ASCII character in Register B. This is the start of a 3 Opcode routine to divide by 10 using compound subtraction
    1088-1089
    SUB A,0AHD6 0A
    Subtract ten from the value of the exponent in Register A
    108A-108B
    JR NC,1087HJR NC,FOUCE230 FB
    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)
    108C-108D
    ADD A,3AHC6 3A
    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 + 10
    108E
    INC HL23
    Bump the value of the buffer pointer in Register Pair HL
    108F
    LD (HL),B70
    Save the ASCII character in Register B (which is the first digit of the exponent in ASCII – the 10’s digit) at the location of the input buffer pointer in Register Pair HL
    1090
    INC HL23
    Bump the value of the buffer pointer in Register Pair HL
    1091
    LD (HL),A77
    Save the value of the ASCII character in Register A (which is the second digit of the exponent in ASCII – the 1’s digit) at the location of the input buffer pointer in Register Pair HL
    1092
     ↳ FOUTZR
    INC HL23
    Bump the value of the buffer pointer in Register Pair HL

    1093 – LEVEL II BASIC MATH ROUTINE– “FOUTDN”

    This routine will print a free format zero.
    1093-1094
     ↳ FOUTDN
    LD (HL),00H36 00
    Save an end of the ASCII string character (designated as 00H) at the location of the input buffer pointer in Register Pair HL
    1095
    EX DE,HLEB
    Since the FFXFLV routine will need the buffer pointer in DE instead of HL, swap those registers
    1096-1098
    LD HL,4130HLD HL,FBUFFR+121 30 41
    Load Register Pair HL with the starting address of the buffer pointer.
    Note: 4130H-4149H holds an internal print buffer
    1099
    RETC9
    DONE! RETurn to CALLer

    109A- LEVEL II BASIC MATH ROUTINE– “FOUTFX”

    This routine will print a number in fixed format.
    109A
     ↳ FOUTFX
    INC HL23
    Bump the value of the buffer pointer in Register Pair HL
    109B
    PUSH BCC5
    Save the field length specifiers (B has the number of #‘s before the current vale of the input buffer pointer and C has the number of #’s after) to the STACK
    109C-109D
    CP 04HFE 04
    Check to see if the current number type in ACCumulator is single or double precision
    109E
    LD A,D7A
    Load Register A with the format specifiers (held in Register D)
    109F-10A1
    JP NC,1109HP NC,FOUFXVD2 09 11
    If the current value in ACCumulator is either single precision or double precision then JUMP away to FOUFXV. If its an integer we will pass through.
    10A2
    RRA1F
    Rotate Register A so that we can check to see if this has to be printed in floating format or not. RRA rotates Register A right one bit, with Bit 0 going to CARRY and CARRY going to Bit 7.
    10A3-10A5
    JP C,11A3HJP C,FFXIFLDA A3 11
    If we need to print it in floating point (exponential) notation, JUMP TO FFXIFL.
    If we are here then we are going to print an integer in fixed format/fixed point notation.
    10A6-10A8
    LD BC,0603H01 03 06
    Load Register B to a decimal counte of 6 and Load Register C with a comma count of 3
    10A9-10AB
    CALL 1289HCALL FOUICCCD 89 12
    Go check to see if commas are needed. If no comma is needed, set C to zero
    10AC
    POP DED1
    Restore the field lengths (the number of #’s to the left and right of the decimal point) from the STACK into Register DE
    10AD
    LD A,D7A
    Load Register A with the number of digits requested to the left of the decimal point in Register D
    10AE-10AF
    SUB A,05HD6 05
    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. This will test to see if we have to print extra spaces because the field is too big.
    10B0-10B2
    CALL P,1269HCALL P,FOTZERF4 69 12
    If the field is too big, and we have to print extra spaces, we GOSUB to FOTZER to put in zeroes which will later be converted to either SPACEor by FOUTZS
    10B3-10B5
    CALL 132FHCALL FOUTCICD 2F 13
    Convert the number to decimal digits by GOSUBing to the INTEGER TO ASCII routine at 1232F (which converts the integer in ACCumulator to ASCII and stores the ASCII string in the buffer pointed to in HL)
    10B6
     ↳ FOUTTD
    LD A,E7B
    Next we need to test to see if we need a decimal point. First, load Register A with the number of digits to the right of the decimal point requested (which is stored in Register E)
    10B7
    OR AB7
    Check to see if there are any digits to the right of the decimal point requested and set the status flags accordingly
    10B8-10BA
    CALL Z,092FHCALL Z,DCXHRTCC 2F 09
    If the Z FLAG is set, then we do NOT need a decimal point, and need to backspace over it, so GOSUB to DCXHRT to decrement the value of the buffer pointer in Register Pair HL
    10BB
    DEC A3D
    Next we need to test to see how many trailing zeroes we need to print. Decrement the number of digits to the right of the decimal point in Register A.
    10BC-10BE
    CALL P,1269HCALL P,FOTZERF4 69 12
    If the POSITIVE flag is set, then print the trailing zeroes via GOSUB to 1269H

    10BF – LEVEL II BASIC MATH ROUTINE– “FOUTTS”

    This routine will finish up the printing of a fixed format number.
    10BF
     ↳ FOUTTS
    PUSH HLE5
    Save the current buffer pointer (stored in Register Pair HL) to the STACK. We then pss through to the FOUTTS routine to finish up the number.
    10C0-10C2
    CALL 0FF5HCALL FOUTZSCD F5 0F
    Go edit the ASCII string in the input buffer to suppress any zeroes, if needed.
    10C3
    POP HLE1
    Get the saved buffer pointer value from the STACK and put it in Register Pair HL
    10C4-10C5
    JR Z,10C8HJR Z,FFXIX128 02
    If the Z FLAG is set, then we do NOT have a trailing sign, so we JUMP away to 10C8H
    10C6
    LD (HL),B70
    So now we know a sign does follow the value so we save sign (held in Register B) at the location of the buffer pointer in Register Pair HL
    10C7
    INC HL23
    Bump the value of the input buffer pointer in Register Pair HL
    10C8-10C9
     ↳ FFXIX1
    LD (HL),00H36 00
    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
    Now we need to check to see if the fixed format/fixed point number overflowed its field length. The location if the decimal point needs to be in TEMP2.
    10CA-10CC
    LD HL,412FHLD HL,FBUFFR21 2F 41
    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)
    10CD
     ↳ FOUBE1
    INC HL23
    Bump the value of the buffer pointer in Register Pair HL
    10CE-10D0
     ↳ FOUBE5
    LD A,(40F3H)LD A,(TEMP2)3A F3 40
    Load Register A with the LSB of the address of the decimal point for the ASCII string. Why just the LSB? FBUFFR is only 35 bytes long, so we only need to check the LSB to see if the field is big enough.
    10D1
    SUB A,L95
    First, subtract the LSB of the input buffer pointer address in Register L from the value in Register A to see how much space we have taken up
    10D2
    SUB A,D92
    Next, set the flags by subtract the number of digits to the left of the decimal point in Register D from the adjusted value in Register A to determine if we have taken the right amount of space. Z FLAG will mean we did!
    10D3
    RET ZC8
    If we have taken the right amount of space, then we are done, so we RETurn
    10D4
    LD A,(HL)7E
    If we are here, then we took too much space. How do we know it is too much instead of just “different”? Well, we started checking from the beginning of the buffer, and the field must be small enough to fit into the buffer. With this, we need to fetch the next character from the buffer into Register A
    10D5-10D6
    CP 20HCP ” “FE 20
    Check to see if the character at the location of the buffer pointer in Register A is a space, meaning we can just ignore the character to make the field shorter
    10D7-10D8
    JR Z,10CDHJR Z,FOUBE128 F4
    If it is a space, then LOOP back to FOUBE1 to ignore it
    10D9-10DA
    CP 2AHCP “*”FE 2A
    Check to see if the character at the location of the input buffer pointer in Register A is a , meaning we can just ignore the character to make the field shorter
    10DD
    DEC HL2B
    Since we want to ignore ‘s we decrement the value of the input buffer pointer in Register Pair HL so it will get re-tested
    10DE
    PUSH HLE5
    Save the value of the buffer pointer in Register Pair HL to the STACK

    10DF – LEVEL II BASIC MATH ROUTINE– “FOUBE2”

    In this routine, we check to see if we can ignore the leading zero before a decimal point. We can do this if if we see the following: (in order)
    +,-a sign (either “-” or “+”)[optional]
    $a dollar sign[optional]
    0a zero[mandatory]
    .a decimal point[mandatory]
    0-9another digit[mandatory]

    If we see a leading zero, it must be the one before a decimal point or else FOUTZS would have akready suppressed it. In that case, we just INC HLover the character following the zero, and not have to check for the decimal point explicitly.
    10DF
     ↳ FOUBE2
    PUSH AFF5
    Save the the current character (which is the value in Register Pair AF) to the STACK. This also saves the ZERO FLAG.
    10E0-10E2
    LD BC,10DFHLD BC,FOUBE201 DF 10
    Load Register Pair BC with the return address for use in case we have a , a +, or a $
    10E3
    PUSH BCC5
    Save the return address in Register Pair BC to the STACK
    10E4
    RST 10HCHRGETD7
    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.

    The RST 10H routine parses the characters starting at HL+1 for the first non-SPACE,non-09H,non-0BH character it finds. On exit, Register A will hold that character, and the C FLAG is set if its alphabetic, and NC FLAG if its alphanumeric. All strings must have a 00H at the end.
    10E5-10E6
    CP 2DHCP “-“FE 2D
    Check to see if the character at the location of the input buffer pointer in Register A is a
    10E7
    RET ZC8
    Return (to 10DFH) if the character at the location of the input buffer pointer in Register A is a
    10E8-10E9
    CP 2BHCP “+”FE 2B
    Check to see if the character at the location of the input buffer pointer in Register A is a +
    10EA
    RET ZC8
    Return (to 10DFH) if the character at the location of the input buffer pointer in Register A is a +
    10EB-10EC
    CP 24HCP “$”FE 24
    Check to see if the character at the location of the input buffer pointer in Register A is a $
    10ED
    RET ZC8
    Return (to 10DFH) if the character at the location of the input buffer pointer in Register A is a $
    10EE
    POP BCC1
    We don’t need a shortcut to jump to 10DFH anymore, so let’s get rid of the now unneeded return address from the STACK
    10EF-10F0
    CP 30HCP “0”FE 30
    Check to see if the character at the location of the input buffer pointer in Register A is a 0
    10F1-10F2
    JR NZ,1102HJR NZ,FOUBE420 0F
    If the character at the location of the input buffer pointer in Register A isn’t a 0then we can no longer just get rid of the characters, so JUMP to FOUBE4 to continue
    10F3
    INC HL23
    Bump the value of the input buffer pointer in Register Pair HL so that we skip over the decimal point to the next character
    10F4
    RST 10HCHRGETD7
    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.

    The RST 10H routine parses the characters starting at HL+1 for the first non-SPACE,non-09H,non-0BH character it finds. On exit, Register A will hold that character, and the C FLAG is set if its alphabetic, and NC FLAG if its alphanumeric. All strings must have a 00H at the end.
    10F5-10F6
    JR NC,1102HJR NC,FOUBE430 0B
    If the character after the decimal point is not a digit then we can’t shorten the field anymore, so JUMP to FOUBE4
    10F7
    DEC HL2B
    If we didn’t jump away, then we can shorten the field by one, so DECrement the value of the buffer pointer in Register Pair HL to backspace
    10F8
    LD BC,772BH01 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

    10F9 – LEVEL II BASIC MATH ROUTINE– “FOUBE3”

    If we can get rid of the zero, we put the characters on the STACK back into the buffer one position in front of where they originally were.

    Note that the maximum number of STACK levels this uses is three — one for the last entry flag, one for a possible sign, and one for a possible dollar sign.

    We don’t have to worry about the first character being in the buffer twice because the pointer when FOUT exits will be pointing to the second occurance.
    10F9
     ↳ FOUBE3
    DEC HL2B
    If passing through, this instruction won’t get executed. If JUMPed to, decrement the value of the buffer pointer in Register Pair HL (we needed that Z-80 trick to avoid a double backspace if passing through)
    10FA
    LD (HL),A77
    If passing through, this instruction won’t get executed. If JUMPed to, save the character in Register A at the location of the input buffer pointer in Register Pair HL
    10FB
    POP AFF1
    Get the character from the STACK and put it in Register Pair AF
    10FC-10FD
    JR Z,10F9HJR Z,FOUBE328 FB
    If the Z FLAG is set, then we LOOP back to FOUBE3 to put the character back into the buffer
    10FE
    POP BCC1
    Restore the buffer pointer from the top of the STACK into Register Pair BC
    10FF-1101
    JP 10CEHJP FOUBE5C3 CE 10
    LOOP back to 10CEH to see if the field is NOW small enough.

    1102 – LEVEL II BASIC MATH ROUTINE– “FOUBE4”

    If the number is too big for the field, we wind up here to deal with that.
    1102
     ↳ FOUBE4
    POP AFF1
    Restore the character from the STACK and put it in Register Pair AF
    1103-1104
    JR Z,1102HJR Z,FOUBE428 FD
    If the Z FLAG is set, then LOOP back 1 instruction to leave the number in the buffer alone
    1105
    POP HLE1
    Get the starting address of the field from the STACK and put it in Register Pair HL. This will be the pointer to the beginning of the number – 1
    1106-1107
    LD (HL),25HLD (HL),”%”36 25
    Show that we have overflowed the field by putting a %character at the front.
    1108
    RETC9
    All done! RETurn to CALLer

    1109 – LEVEL II BASIC MATH ROUTINE– “FOUFXV”

    This is where the PRINT USING routine will print a single or double precision number in a fixed format
    1109
     ↳ FOUFXV
    PUSH HLE5
    Save the buffer pointer in Register Pair HL to the STACK
    110A
    RRA1F
    Rotate Register A so that the “fixed notation” or “floating notation” flag bit moves into the CARRY FLAG for testing. RRA rotates Register A right one bit, with Bit 0 going to CARRY and CARRY going to Bit 7.
    110B-110D
    JP C,11AAHJP C,FFXFLVDA AA 11
    If the CARRY FLAG was set, then we know we are printing the number in “E” notation, so JUMP to FFXFLV
    110E-110F
    JR Z,1124HJR Z,FFXSFX28 14
    If the Z FLAG was set, the we have a SINGLE PRECISION number to print, so JUMP to FFXSFC to do that
    If we are here, then we are printing a DOUBLE PRECISION number in fixed format/fixed point notation
    1110-1112
    LD DE,1384HLD DE,FFXDXM11 84 13
    Load Register Pair DE with the address of the DOUBLE PRECISION value to be compared to the current value in ACCumulator. Register Pair DE points to a double precision constant equal to 1D16
    1113-1115
    CALL 0A49HCALL DCOMPDCD 49 0A
    Since we can’t print a number which is greater than 10^16 in fixed format, GOSUB to compare the double precision constant pointed to by Register Pair DE (which is 1Dl6) to the double precision value in ACCumulator
    1116-1117
    LD D,10H16 10
    Load Register D with the maximum length of a double precision value (which is 16 in decimal)
    1118-111A
    JP M,1132HJP M,FFXSDCFA 32 11
    If the M FLAG is set, then the number in the ACCumulator is small enough to print (i.e., less than or equal to 1Dl6), so JUMP to 1132H

    111B – LEVEL II BASIC MATH ROUTINE– “FFXSDO”

    This routine will print a number which is greaster than 10^16 in free format with a percent sign
    111B
     ↳ FFXSDO
    POP HLE1
    Get the current buffer pointer from the STACK and put it in Register Pair HL
    111C
    POP BCC1
    Get the field specifier 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
    111D-111F
    CALL 0FBDHCALL FOUTCD BD 0F
    Print the number in free format via a GOSUB to FOUT (which will convert a double precision value in ACCumulator to an ASCII string)
    1120
    DEC HL2B
    Decrement the input buffer pointer in Register Pair HL to point in front of the number
    1121-1122
    LD (HL),25HLD (HL),”%”36 25
    Save a %character at the location of the input buffer pointer in Register Pair HL
    1123
    RETC9
    All done! RETurn to CALLer

    1124 – LEVEL II BASIC MATH ROUTINE– “FFXSFX”

    This routine will print a SINGLE PRECISION number in fixed format/fixed point notation
    1124-1126
     ↳ FFXSFX
    LD BC,B60EH01 0E B6
    Load Register Pair BC/DE with 1E16
    1127-1129
    LD DE,1BCAH11 CA 1B
    Register Pairs BC and DE now hold a single precision constant equal to 1×10^16
    112A-112C
    CALL 0A0CHCALL FCOMPCD 0C 0A
    Call the SINGLE PRECISION COMPARISON routine at routine at 0A0CH which algebraically compares the single precision value in BC/DE to the single precision value ACCumulator.
    The results are stored in A as follows:
    If ACCumulator = BCDEA=00
    If ACCumulator > BCDEA=01
    If ACCumulator < BCDEA=FF
    112D-112F
    JP P,111BHJP P,FFXSDOF2 1B 11
    If the P FLAG is set then the number is too big, so we need to JUMP to FFXSDO to print it in free format with a %overflow symbol
    1130-1131
    LD D,06H16 06
    Now we know that the SINGLE precision value in ACCumulator is less than 1×10^16. Load Register D with the maximum length of a single precision value (which is 6) and then fall through to the FFXSDC routine

    1124 – LEVEL II BASIC MATH ROUTINE– “FFXSDC”

    This routine will print a SINGLE PRECISION or DOUBLE PRECISION number in fixed format/fixed point notation
    1132-1134
     ↳ FFXSDC
    CALL 0955HCALL SIGNCD 55 09
    GOSUB to SIGN to see if we have a ZERO in the ACCumulator
    1135-1137
    CALL NZ,1201HCALL NZ,FOUTNVC4 01 12
    If we do NOT have a ZERO, then GOSUB to FOUTNV to normalize the number so that all digits to be printed are located in the initeger part
    1138
    POP HLE1
    Get the buffer pointer from the STACK and put it in Register Pair HL
    1139
    POP BCC1
    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
    113A-113C
    JP M,1157HJP M,FFXXVSFA 57 11
    If the exponent is negative, JUMP to FFXXVS to handle that
    This routine will print a number that has no fractional digits
    113D
    PUSH BCC5
    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
    113E
    LD E,A5F
    Load Register E with the exponent
    If the field length is higher than the number of characters we actually have, we are going to need to put in that number of leading zeroes.
    113F
    LD A,B78
    Load Register A with the number of digits before the decimal point requested
    1140
    SUB A,D92
    Subtract the maximum length for the current number type in Register D (which is 6) from the number of digits requested in Register A
    1141
    SUB A,E93
    Subtract the number of times the current value in ACCumulator was divided in Register E from the adjusted value in Register A
    1142-1144
    CALL P,1269HCALL P,FOTZERF4 69 12
    If B-D-E is still POSITIVE, then we have to fill with some zeroes so GOSUB to 1269H to put leading zeros into the input buffer if necessary
    1145-1147
    CALL 127DHCALL FOUTCDCD 7D 12
    Next, set up the decimal point and comma counts via a GOSUB to DOUTCD
    1148-114A
    CALL 12A4HCALL FOUTCVCD A4 12
    Then, convert the number to decimal digits via a GOSUB to FOUTCV to convert the integer portion of the current value in ACCumulator to an ASCII string
    114B
    OR EB3
    Merge in the number of digits after the number, if the field is big enough of course.
    114C-114E
    CALL NZ,1277HCALL NZ,FOTZECC4 77 12
    If there are number to be put there (i.e., merging in E leaves a number greater than Zero), then GOSUB to FOTZEC to put trailing zeros into the input buffer if necessary
    114F
    OR EB3
    Check to see if commas or the decimal point is needed
    1150-1152
    CALL NZ,1291HCALL NZ,FOUTEDC4 91 12
    Go put commas and the decimal point into the input buffer if necessary
    1153
    POP DED1
    Retrieve the field length specs from the STACK and put it in Register Pair DE
    1154-1156
    JP 10B6HJP FOUTTDC3 B6 10
    Jump to 10B6H to check the size, run zero suppression, and convert the fractional portion of the number to ASCII to finish up

    1157 – LEVEL II BASIC MATH ROUTINE– “FFXXVS”

    This routine will print a SINGLE PRECISION or DOUBLE PREVISION number that has fractional digits
    1157
     ↳ FFXXVS
    LD E,A5F
    Preserve the exponent into Register E
    1158
    LD A,C79
    Prepare to divide by 10 the right number of times so that the result will be rounded correctly and have the correct number of significant digits. First, load Register A with the number of digits requested to the right of the decimal point
    1159
    OR AB7
    Check to see if any digits to the right of the decimal point was requested
    115A-115C
    CALL NZ,0F16HCALL NZ,DCRARTC4 16 0F
    Go decrement the number of digits requested to the right of the decimal point if necessary
    115D
    ADD A,E83
    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
    115E-1160
    JP M,1162HJP M,FFXXV8FA 62 11
    If the value in ACCumulator must be scaled down then skip the next instruction, as we want a ZERO FLAG only if the result was not negative
    1161
    XOR AAF
    Zero Register A
    1162
     ↳ FFXXV8
    PUSH BCC5
    Save the field specifications held in Register Pair BC (B was the number of #‘s before and C is the number of #‘s after) to the STACK
    1163
    PUSH AFF5
    Save the the scale count (held in Register Pair AF) to the STACK
    1164-1166
     ↳ FFXXV2
    CALL M,0F18HCALL M,FINDIVFC 18 0F
    Top of a divide loop. GOSUB to 0F18H to divide the value in ACCumulator by ten, A times, if necessary
    1167-1169
    JP M,1164HJP M,FFXXV2FA 64 11
    Loop until the value in ACCumulator is properly adjusted. When this is done, A will hold the number of times it was divided by 10
    116A
    POP BCC1
    Get the original scale count from the STACK and put it in Register Pair BC
    116B
    LD A,E7B
    We now need to test as to whether the number has integer digits or not. First, load Register A with the number of times the value in ACCumulator was multiplied in Register E
    116C
    SUB A,B90
    Subtract the value in Register B from the value in Register A
    116D
    POP BCC1
    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
    116E
    LD E,A5F
    Calculate the number of decimal places before the number ends by first loading Register E with the adjusted scale factor value in Register A …
    116F
    ADD A,D82
    … and then adding 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
    1170
    LD A,B78
    Load Register A with the number of #‘s before (stored in B)
    1171-1173
    JP M,117FHJP M,FFXXV3FA 7F 11
    Jump to 117FH if there are no digits to the left of the decimal point
    This routine will print numbers with integer digits, and will print some leading zeroes if the field is bigger than the number of digits we need to print.
    1174
    SUB A,D92
    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
    1175
    SUB A,E93
    Then, subtract the adjusted scale value in Register E from the adjusted value in Register A
    1176-1178
    CALL P,1269HCALL P,FOTZERF4 69 12
    If that subtraction leads to a positive number, go put leading zeros into the input buffer
    1179
    PUSH BCC5
    Save the field specs held in Register Pair BC (B was the number of #‘s before and C is the number of #‘s after) to the STACK
    117A-117C
    CALL 127DHCALL FOUTCDCD 7D 12
    GOSUB to set up BC for decimal point and comma counters
    117D-117E
    JR 1190HJR FFXXV618 11
    Jump to 1190H to convert the digits before the decimal point and trim the number

    117F – LEVEL II BASIC MATH ROUTINE– “FFXXV3”

    This routine will print a number without integer digits.
    117F-1181
     ↳ FFXXV3
    CALL 1269HCALL FOTZERCD 69 12
    Go put leading zeros (as needed) into the input buffer
    1182
    LD A,C79
    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
    1183-1185
    CALL 1294HCALL FOUTDPCD 94 12
    GOSUB to 1294H to put a decimal point into the input buffer
    1186
    LD C,A4F
    Reload Register C with the number of digits requested to the right of the decimal point in Register A
    1187
    XOR AAF
    Next we need to calculate how many zeroes to put between the decimal point and the first digit, so start by zeroing Register A
    1188
    SUB A,D92
    Then – subtract the maximum length for the current value in Register D from the value in Register A
    1189
    SUB A,E93
    Then – subtract the value in Register E from the adjusted value in Register A
    118A-118C
    CALL 1269HCALL FOTZERCD 69 12
    GOSUB to put that many zeroes into the buffer
    118D
    PUSH BCC5
    Save the value in Register Pair BC (B is the exponent and C is the number of #‘s after) to the STACK
    118E
    LD B,A47
    Load Register B (i.e., the decimal place count) with the value in Register A (which is 0)
    118F
    LD C,A4F
    Load Register C (i..e, the comma count) with the value in Register A (which is 0)
    1190-1192
     ↳ FFXXV6
    CALL 12A4HCALL FOUTCVCD A4 12
    GOSUB to 12A4H to convert the integer portion of the SINGLE precision value in ACCumulator to an ASCII string. These will be the decimal digits.
    1193
    POP BCC1
    Get the number of #‘s before and number of #‘s after and put it back in Register Pair BC
    1194
    OR CB1
    Check to see if we need to print any zeroes after the last digit (i.e., if there are any digits to the right of the decimal point requested) and set the status accordingly
    1195-1196
    JR NZ,119AHJR NZ,FFXXV720 03
    If the NZ FLAG is set, then there are digits to the right of the decimal point to fill, so JUMP to 119AH to do that
    1197-1199
    LD HL,(40F3H)LD HL,(TEMP2)2A F3 40
    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 is a temporary storage location

    119A – LEVEL II BASIC MATH ROUTINE– “FFXXV7”

    This routine will print trailing zeroes.
    119A
     ↳ FFXXV7
    ADD A,E83
    Add the value in Register E to the value in Register A to get the number of digits before the decimal point
    119B
    DEC A3D
    Decrement the adjusted value in Register A
    119C-119E
    CALL P,1269HCALL P,FOTZERF4 69 12
    If dropping A by 1 still results in a positive number, GOSUB 1269H to put that number of zeros into the input buffer
    119F
    LD D,B50
    Load Register D with the number of digits to the left of the decimal point requested (from Register B)
    11A0-11A2
    JP 10BFHJP FOUTTSC3 BF 10
    Jump to 10BFH to finish up

    11A3 – LEVEL II BASIC MATH ROUTINE– “FFXIFL”

    This routine will print an integer in fixed format/floating point notation.
    11A3
     ↳ FFXIFL
    PUSH HLE5
    Save the current position of the buffer (in Register Pair HL) to the STACK
    11A4
    PUSH DED5
    Generally save Register Pair DE to be POPped after the CALL. DE currently holds the format specs
    11A5-11A7
    CALL 0ACCHCALL CONSICD CC 0A
    GOSUB 0ACCH to convert the integer value in ACCumulator to a SINGLE precision value
    11A8
    POP DED1
    Restore DE from the STACK
    11A9
    XOR AAF
    Zero Register A, clear the status flags. This will denote to the next routine that we are printing a number as a SINGLE PRECISION number, and then fall into the FFXFLV routine

    11AA – LEVEL II BASIC MATH ROUTINE– “FFXFLV”

    This routine will print a SINGLE or DOUBLE PRECISION number in fixed format/floating point notation.
    11AA-11AC
     ↳ FFXFLV
    JP Z,11B0HJP Z,FFXSFLCA B0 11
    If we have a SINGLE PRECISION number (because the Z FLAG is set), Jump to 11B0H to set the flags appropriately
    11AD-11AE
    LD E,10H1E 10
    We know we have a DOUBLE PRECISION so load Register E with the maximum length of a double precision value (which is 16)
    11AF-11B2
    LD BC,1E06H01 1E 06
    Z-80 Trick! If passing through then this just modifies the Register Pair BC. However, if JUMPing to 11B0, a LD E,06H occurs, changing E
    11B0-11B1
     ↳ FFXSFL
    LD E,06H1E 06
    Load Register E with the maximum length of a single precision value (which is 6)
    11B2-11B4
    CALL 0955HCALL SIGNCD 55 09
    GOSUB 0955H to check to see if we have a zero in the ACCumulator
    11B5
    SCF37
    Set the Carry flag to determine if we are printing a zero or not. This works because FOUTNV exits with the NC FLAG set
    11B6-11B8
    CALL NZ,1201HCALL NZ,FOUTNVC4 01 12
    If we do not have a zero, then we need to normalize the number so that all digits to be printed are in the integer portion, so GOSUB to 1201H to scale the current value in ACCumulator
    11B9
    POP HLE1
    Get the buffer position from the STACK and put it in Register Pair HL
    11BA
    POP BCC1
    Get the number of #‘s before and the number of #‘s after from the STACK and put it in Register Pair BC
    11BB
    PUSH AFF5
    Save the exponent in Register Pair AF to the STACK
    11BC
    LD A,C79
    We need to calculate how many significant digits we must print, so load Register A with the number of digits to the right of the decimal point requested (stored in Register C)
    11BD
    OR AB7
    Set the status so we can see if there are any digits to the right of the decimal point requested through a zero register
    11BE
    PUSH AFF5
    Save the original trailing digit count (in Register Pair AF) to the STACK
    11BF-11C1
    CALL NZ,0F16HCALL NZ,DCRARTC4 16 0F
    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
    11C2
    ADD A,B80
    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
    11C3
    LD C,A4F
    Load Register C with the total digit count (held in Register A)
    11C4
    LD A,D7A
    Load Register A with the value of the edit flag in Register D
    11C5-11C6
    AND 04HAND 0000 0100E6 04
    Check to see if the sign follows the ASCII string (i.e., is a “trailing” sign)
    11C7-11C8
    CP 01HFE 01
    Set the Carry flag according to the sign following the ASCII string test (it will be No Carry if a sign follows, and will be CARRY if A=0)
    11C9
    SBC A,A9F
    If we have a trailing sign, this will set Register D to 0. Otherwise, D will be FFH if we don’t have a trailing sign.
    11CA
    LD D,A57
    Load Register D with those results
    11CB
    ADD A,C81
    Add the value in Register C to the value in Register A so as to set the number of significant digits to print
    11CC
    LD C,A4F
    Load Register C with the adjusted value in Register A
    11CD
    SUB A,E93
    If the number of significant digits to print is less than E, then we have to get rid of some numbers! 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
    11CE
    PUSH AFF5
    Save the divisor count (from Register Pair AF) to the STACK. This is the result of the comparison of the number of significant digits and the number of digits we will actually print.
    11CF
    PUSH BCC5
    Save the “B” field spec and the number of significant digits (from Register Pair BC) to the STACK
    11D0-11D2
     ↳ FFXLV1
    CALL M,0F18HCALL M,FINDIVFC 18 0F
    GOSUB 0F18H to divide the current value in ACCumulator by ten, Register A number of times
    11D3-11D5
    JP M,11D0HJP M,FFXLV1FA D0 11
    Loop back 1 instruction (divide by 10) until the division has been completed
    11D6
    POP BCC1
    Retrieve the “B” field spec and the number of significant digits from the STACK back into Register Pair BC
    11D7
    POP AFF1
    Get the number of trailing zeroes to print from the STACK and put it in Register Pair A
    11D8
    PUSH BCC5
    Save the “B” field spec and the number of significant digits (from Register Pair BC) to the STACK
    11D9
    PUSH AFF5
    Save the number of trailing zeroes to print to the STACK
    11DA-11DC
    JP M,11DEHJP M,FFXLV3FA DE 11
    Skip the next instruction (i.e., jump to 11DEH) if there are any trailing zeroes
    11DD
    XOR AAF
    Zero Register A and all status flags
    11DE
     ↳ FFXLV3
    CPL2F
    Make the trailing zero count posivite by inverting the value in Register A
    11DF
    INC A3C
    Bump the value in Register A so that it will be positive
    11E0
    ADD A,B80
    Set the decimal place count by adding the number of digits requested to the left of the decimal point in Register B to the adjusted value in Register A
    11E1
    INC A3C
    Bump the adjusted value in Register A
    11E2
    ADD A,D82
    Take into account if the sign is trailing by adding 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
    11E3
    LD B,A47
    Copy Register A into Register B so that B holds the number of digits before the decimal point
    11E4-11E5
    LD C,00H0E 00
    Set the comma count to zero by loading Register C with zero (so that there are no commas)
    11E6-11E8
    CALL 12A4HCALL FOUTCVCD A4 12
    GOSUB to 12A4H to convert the current value in ACCumulator to decimal digits
    11E9
    POP AFF1
    Get the number of #’s before from the STACK and put it in Register Pair AF
    11EA-11EC
    CALL P,1271HCALL P,FOTZNCF4 71 12
    GOSUB 1271H to put zeros into the trailing input buffer
    11ED
    POP BCC1
    Get the number of #’s before and the number of #‘s after from the STACK and put it in Register Pair BC
    11EE
    POP AFF1
    Get the C count (numbers before the decimal point) from the STACK and put it in Register Pair A and restore the FLAGS
    11EF-11F1
    CALL Z,092FHCALL Z,DCXHRTCC 2F 09
    If C = 0 then the last character was a decimal point, so ignore it via a GOSUB to 092FH to decrement the input buffer pointer in Register Pair HL if there are none
    11F2
    POP AFF1
    Get the exponent back from from the STACK and put it in Register Pair AF
    11F3-11F4
    JR C,11F8HJR C,FFXLV238 03
    If the number is zero, then the exponent is zero, so JUMP to 11F8H (to add the exponent) if the carry flag was set
    11F5
    ADD A,E83
    Otherwise, we need to scale the number – so first add the value in Register E to the value in Register A
    11F6
    SUB A,B90
    Subtract the number of digits to the left of the decimal point requested in Register B from the adjusted value in Register A
    11F7
    SUB A,D92
    Subtract the value in Register D from the value in Register A to get the size of the exponent
    11F8
     ↳ FFXLV2
    PUSH BCC5
    Save the “B” field spec to the STACK
    11F9-11FB
    CALL 1074HCALL FOFLDNCD 74 10
    Put the exponent into the buffer via a GOSUB to 1074H to figure the value of the exponent for the current value in ACCumulator
    11FC
    EX DE,HLEB
    Swap DE and HL so that the pointer to the end of the buffer is put into Register Pair HL just in case we have a trailing sign we need to add.
    11FD
    POP DED1
    Restore the “B” field spec into Register D in case we need to put on a trailing sign.
    11FE-1200
    JP 10BFHJP FOUTTSC3 BF 10
    Jump to 10BFH to put on the trailing sign and finish up

    1201 – Test the magnitude of SP and DP numbers, and clear the times the value was scaled– “FOUTNV”

    This routine will scale (normalize) the number in the accumulator so that all the digits are in the integer part (i.e., between 99,999 and 999,999). The signed base 10 exponent is returned in Register A. Registers D and E are unchanged.
    1201
     ↳ FOUTNV
    PUSH DED5
    Save the value in Register Pair DE to the STACK. We are going to pop this back at the end of the routine.
    1202
    XOR AAF
    Zero Register A, which will be the exponent
    1203
    PUSH AFF5
    Save the exponent in Register Pair A to the STACK
    1204
    RST 20HGETYPEE7
    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 ACCumulator 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.
    1205-1207
    JP PO,1222HJP PO,FOUNDBE2 22 12
    If that test shows we have a SINGLE PRECISION number (through getting a Parity-Odd flag), jump to 1222H to handle. Otherwise, pass through
    1208-120A
     ↳ FORBIG
    LD A,(4124H)LD A,(FAC)3A 24 41
    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 ACCumulator
    120B-120C
    CP 91HFE 91
    Check to see if the double precision value in ACCumulator uses is less than 1D5 (i.e., the integer portion of the double precision value)
    120D-120F
    JP NC,1222HP NC,FOUNDBD2 22 12
    If the double precision value in ACCumulator is not less than 1D5, then ship over the following multiplcation code and go to FOUNDB.
    1210-1212
    LD DE,1364HLD DE,TENTEN11 64 13
    Load Register Pair DE with 1D10
    1213-1215
    LD HL,4127HLD HL,ARGLO21 27 41
    In praration for VMOVE and DMULT, point HL to REG2
    1216-1218
    CALL 09D3HCALL VMOVECD D3 09
    GOSUB to 09D3H to move the double precision constant into REG2
    1219-121B
    CALL 0DA1HCALL DMULTCD A1 0D
    GOSUB to 0DA1H to call the DOUBLE PRECISION MULTIPLY routine at 0DA1H (which multiplies the double precision value in ACCumulator by the value in REG 2. The product is left in ACCumulator)
    121C
    POP AFF1
    Retrieve the original exponent from the STACK into Register A
    121D-121E
    SUB A,0AHD6 0A
    Subtract ten from the value in Register A to do a proper offset for an exponent
    121F
    PUSH AFF5
    Save the adjusted exponent (held in Register A) to the STACK
    1220-1221
    JR 1208HJR FORBIG18 E6
    Force it to be bigger via a JUMP to 1208H so as to loop until the integer portion exceeds 2e16

    1222 – LEVEL II BASIC MATH ROUTINE– “FOUNDB”

    There is a big bug in this routine which was fixed in v1.2 of the ROM. The fixing of that bug caused a renumbering from 1228H-124CH. The numbering here will show both.
    1222-1224
     ↳ FOUNDB
    CALL 124FHCALL FOUNVCCD 4F 12
    Check to see if the number in the ACCumulator is too big or too small via a GOSUB to 124FH to compare the current value in ACCumulator to 999999.5
    1225
     ↳ FOUNV1
    RST 20HGETYPEE7
    In order to determine if the ACCumulator is big enough, we need to know what kind of value we have in the ACCumulator so call the TEST DATA MODE routine at RST 20H.
    NOTE:The RST 20H routine determines the type of the current value in ACCumulator 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.
    1226-1228
    JP PE,1234HJP PE,FOUNV4EA 34 12
    If that test shows we have a DOUBLE PRECISION or a STRING, jump to 1234H
    1226-1228
    In ROM 1.2 this is a big bug fix. Now if the shows we do NOT have a STRING, jump to 1233H
    The next two instructions load BCDE with 99999.95 so as to check to see if the number in FAC is too big.
    1229-122B
    1228-122A
    LD BC,9143H01 43 91
    Load Register Pair BC with the exponent and the MSB of a single precision constant
    122C-122E
    122B-122D
    LD DE,4FF9H11 F9 4F
    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
    122F-1231
    122E-1230
    CALL 0A0CHCALL FCOMPCD 0C 0A
    GOSUB to routine at 0A0CH which algebraically compares the single precision value in BC/DE to the single precision value ACCumulator.
    The results are stored in A as follows:
    If ACCumulator = BCDEA=00
    If ACCumulator > BCDEA=01
    If ACCumulator < BCDEA=FF
    1232-1233
    JR 123AHJR FOUNV518 06
    Jump down two instructions to 123AH to test the results of the comparison
    1231-1232
    JR 1239HJR FOUNV5
    Jump down two instructions to 123AH to test the results of the comparison
    1234-1236
     ↳ FOUNV4

    1233-1235
    LD DE,136CHLD DE,FOUTDL11 6C 13
    Load Register Pair DE with the starting address of a double precision constant equal to 999,999,999,999,999.95
    1237-1239
    1236-1238
    CALL 0A49HCALL DCOMPDCD 49 0A
    Go compare the double precision constant pointed to by Register Pair DE to the double precision value in ACCumulator to see if the number is still too small
    123A-123C
     ↳ FOUNV5

    1239-123B
    JP P,124CHJP P,FOUNV3F2 4C 12
    If the number isn’t too small anymore then we are done so JUMP to 124CH
    1239-123B
     ↳ FOUNV5
    If the number isn’t too small anymore then we are done so JUMP to 124BH
    123D
    123C
    POP AFF1
    If we are here then the number is still too small so we will need to multiply it by 10. Get the value of the scaled counter from the STACK and put it in Register Pair AF
    123E-1240
    123D-123F
    CALL 0F0BHCALL FINMLTCD 0B 0F
    GOSUB to 0F0BH to multiply the current value in ACCumulator by ten
    1241
    1240
    PUSH AFF5
    Save the exponent value (the negative of the number of times the value was multiplied) in Register Pair AF to the STACK.
    1242-1243
    1241-1242
    JR 1225HJR FOUNV118 E1
    Keep looping back to see if the number is big enough (i.e., between 999,999 and 99,999)
    1244
    1243
    POP AFF1
    At this point, the ACCumulator is too big. First, fetch the exponent (i.e., the scaled count) from the STACK and put it in Register A
    1245-1247
    1244-1246
    CALL 0F18HCALL FINDIVCD 18 0F
    GOSUB to 0F18H to divide the current value in ACCumulator by ten
    1248
    1247
    PUSH AFF5
    Save the exponent to the STACK. A is the count of the number of times it was divided
    1249-124B
    1248-124A
    CALL 124FHCALL FOUNVCCD 4F 12
    We need to see if the ACCumulator is small enough so GOSUB to 124FH to loop until the value in ACCumulator is < 999,999
    124C
     ↳ FOUNV3

    124B
    POP AFF1
    At this point, we are done scaling, so restore the exponent into Register A. A = + times divided or – times multiplied
    124D
    124C
    POP DED1
    Restore DE from where it was preserved at the top of this routine
    N/A
    124D
    OR A
    In ROM v1.2 sets the status flags. This also realigns the memory addresses from changes to v1.2 ROM
    124E
    RETC9
    RETurn to CALLer

    124F – LEVEL II BASIC MATH ROUTINE– “FOUNVC”

    This routine will see if the number in the ACCumulator is small enough yet
    124F
     ↳ FOUNVC
    RST 20HGETYPEE7
    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 ACCumulator 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.
    1250-1252
    JP PE,125EHJP PE,FONVC1EA 5E 12
    If that test shows we have a DOUBLE PRECISION number, jump to 125EH
    The next two instructions load BCDE with 999999.5 to see if the number in the FAC is too large.
    1253-1255
    LD BC,9474H01 74 94
    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
    1256-1258
    LD DE,23F8H11 F8 23
    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
    1259-125B
    CALL 0A0CHCALL FCOMPCD 0C 0A
    Call the SINGLE PRECISION COMPARISON routine at routine at 0A0CH which algebraically compares the single precision value in BC/DE to the single precision value ACCumulator.
    The results are stored in A as follows:
    If ACCumulator = BCDEA=00
    If ACCumulator > BCDEA=01
    If ACCumulator < BCDEA=FF
    125C-125D
    JR 1264HJR FONVC218 06
    Jump to 1264H to test the result of the comparison
    125E-1260
     ↳ FONVC1
    LD DE,1374HLD DE,FOUTDU11 74 13
    If we are here, then we have a DOUBLE PRECISION number to deal with, so start by loading Register Pair DE with the starting address of a double precision constant equal to 9,999,999,999,999,999.5
    1261-1263
    CALL 0A49HCALL DCOMPDCD 49 0A
    Check to see if the number is too big via a GOSUB to 0A49H to compare the double precision constant pointed to by Register Pair DE to the double precision value in ACCumulator
    1264
     ↳ FONVC2
    POP HLE1
    Get the return address from the STACK and put it in Register Pair HL so we can go to 1244H
    1265-1267
    JP P,1244HJP P,FOUNV2F2 44 12
    If the P FLAG is set, then the number is still too big (i.e., the number in the ACCumulator has more than 6 digits in the integer portion), so JUMP to 1244H
    1265-1267
    In ROM v1.2 the ROM addresses had moved 1 byte
    1268
    JP (HL)E9
    If the number isn’t too big, then just RETurn by JUMPing to (HL)

    1269H – LEVEL II BASIC MATH ROUTINE– “FOTZER”

    This routine puts leading zeroes into the input buffer. The count is held in Register A and it can be zero, but the Z FLAG needs to be set in that case. Only (HL) and Register A are affected.
    1269
     ↳ FOTZER
    OR AB7
    This is the entry point from FFXXV3 where the flags have not yet been set, so set the flags, particularly the Z FLAG
    126A
     ↳ FOTZR1
    RET ZC8
    Top of a loop. If the number of 0’s we need to display is zero, then just RETurn
    126B
    DEC A3D
    Decrement the value in Register A to show that an ASCII zero was moved to the print buffer
    126C-126D
    LD (HL),30HLD (HL),”0″36 30
    Save a 0at the location of the input buffer pointer in Register Pair HL
    126E
    INC HL23
    Bump the input buffer pointer in Register Pair HL
    126F-1270
    JR 126AHJR FOTZR118 F9
    Jump back to 126AH until the number in Register A of ASCII zeroes were moved

    1271 – LEVEL II BASIC MATH ROUTINE– “FOTZNC”

    This routine will put zeroes in the buffer along with commans or a decimal point in the middle. The count is held in Register A and it can be zero, but the Z FLAG needs to be set in that case. Registers B (decimal point count) and C (comma count) are updated accordingly. Everything but DE is affected.
    1271-1272
     ↳ FOTZNC
    JR NZ,1277HJR NZ,FOTZEC20 04
    So long as we are adding zeroes, Jump to 1277H
    1273
     ↳ FOTZRC
    RET ZC8
    Top of a loop. If there are no more zeroes to add, RETurn
    1274-1276
    CALL 1291HCALL FOUTEDCD 91 12
    Check to see if we need to insert a comma or a decimal prior to the zero at the current positiuon via a GOSUB to FOUTED
    1277-1278
     ↳ FOTZEC
    LD (HL),30HLD (HL),”0″36 30
    Save a 0at the location of the input buffer pointer in Register Pair HL
    1279
    INC HL23
    Bump the input buffer pointer in Register Pair HL
    127A
    DEC A3D
    Decrement the counter of trailing zeroes to add in Register A
    127B-127C
    JR 1273HJR FOTZRC18 F6
    Loop back and keep looping until the number of zeroes to add is 0.

    127D – LEVEL II BASIC MATH ROUTINE– “FOUTCD”

    This routine will put a possible comma count into Register C and will zero Register C if we are not using commas in the specification.
    127D
     ↳ FOUTCD
    LD A,E7B
    The next bunch of math is to set up the decimal point count. First, load Register A with the value in Register E so that A holds the decimal point countcount of the times the value was scaled up or down
    127E
    ADD A,D82
    Add the number of digits to print (from Register D) to the value in Register A
    127F
    INC A3C
    Bump the adjusted value in Register A so now A holds the number of digits before the decimal point
    1280
    LD B,A47
    Load Register B with the leading digit count (from Register A)
    1281
    INC A3C
    Next, we are going to set up the comma count. First bump the value in Register A so not A holds the leading digits + 2
    1282-1283
     ↳ FOTCD1
    SUB A,03HD6 03
    Subtract three from the adjusted value in Register A which, when combined with the next instruction as a loop, divides modulo 3
    1284-1285
    JR NC,1282HJR NC,FOTCD130 FC
    Loop back 1 instruction until the value in Register A is -1, -2, or -3
    1286-1287
    ADD A,05HC6 05
    Add 5 (which is 3 back plus 2 more for scaling) to A to get a positive remainder. This will give 4, 3, or 2 as the comma count
    1288
    LD C,A4F
    Save the possible comma count into Register A
    1289-128B
     ↳ FOUICC
    LD A,(40D8H)LD A,(TEMP3)3A D8 40
    Load Register A with the format specs from the temporary storage location
    128C-128D
    AND 40HAND 0100 0000E6 40
    Mask against 0100 0000 to isolate the comma bit to see if commas are requested
    128E
    RET NZC0
    If the NZ FLAG is set then we are using commas, so just RETurn
    128F
    LD C,A4F
    If we are here, then we aren’t using commas, so Zero the comma counter in Register C
    1290
    RETC9
    RETurn to CALLer

    1291 – LEVEL II BASIC MATH ROUTINE– “FOUTED”

    This routine will put decimal points and commas in their correct places. This subroutine should be called before the next digit is put in the buffer. Register B = the decimal point count and Register C = the comma count.

    The counts tell how many more digits have to go in before the comma ;or decimal point go in.

    The comma or decimal point then goes before the last digit in the count. For example, if the decimal point should come after the first digit, the decimal point count should be 2.
    1291
     ↳ FOUTED
    DEC B05
    First we need to test to see if it is time to put in a decimal point. To do this, we DECrement the decimal point counter in Register B to see if the zero flag sets or not
    1292-1293
    JR NZ,129CHJR NZ,FOUED120 08
    If the decimal point position hasn’t been reached then JUMP to FOUED1 to see if a comma needs to go there.
    1294-1295
     ↳ FOUTDP
    LD (HL),2EHLD (HL),”.”36 2E
    If we are here, then the decimal point time has come. Save a decimal point at the location of the input buffer pointer in Register Pair HL
    1296-1298
    LD (40F3H),HLLD (TEMP2),HL22 F3 40
    Save the address of the decimal point position (held in Register Pair HL).
    Note: 40F3H-40F4H is a temporary storage location
    1299
    INC HL23
    Bump the buffer pointer in Register Pair HL
    129A
    LD C,B48
    We just put in a decimal point, so we KNOW we don’t need to put a comma here, so ZERO out the comma counter
    129B
    RETC9
    RETurn to CALLer

    129C – LEVEL II BASIC MATH ROUTINE– “FOUED1”

    Part of the above routine, jumped here to test to see if a comma needs to be placed at (HL).
    129C
     ↳ FOUED1
    DEC C0D
    First, we need to test to see if it is time to put in a comma by DECrementing the comma counter in Register C
    129D
    RET NZC0
    If the NZ FLAG is set, then we are not putting in a comma, so RETurn
    129E-129F
    LD (HL),2CHLD (HL),”,”36 2C
    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
    12A0
    INC HL23
    Bump the input buffer pointer (to account for the new comma) in Register Pair HL
    12A1-12A2
    LD C,03H0E 03
    Reset the comma counter by setting it to 3 (since commas come after units of 3 numbers)
    12A3
    RETC9
    RETurn to CALLer

    12A4 – LEVEL II BASIC MATH ROUTINE– “FOUTCV”

    This routine will convert a SINGLE PRECISION or a DOUBLE PRECISION number that has been normalized to decimal digits. The decimal point count is in Register B and the comma count is in Register C. (HL) points to where the first digit will go. Routine will exit with A=0.
    12A4
     ↳ FOUTCV
    PUSH DED5
    Generally preserve Register Pair DE. This will get POPped when the subroutine is done.
    12A5
    RST 20HGETYPEE7
    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 ACCumulator 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.
    12A6-12A8
    JP PO,12EAHJP PO,FOUTCSE2 EA 12
    If we have a single precision number (by the Parity Odd flag being set) JUMP to 12EAH to convert a SINGLE precision number into its INTEGER equivalent)
    12A9
    PUSH BCC5
    Now that we know we have a DOUBLE PRECISION number, save decimal/comma count (in Register Pair BC) to the STACK
    12AA
    PUSH HLE5
    Save the buffer address (in Register Pair HL) to the STACK
    12AB-12AD
    CALL 09FCHCALL VMOVAFCD FC 09
    GOSUB to 09FCH to mmove the double precision value in ACCumulator to REG2
    12AE-12B0
    LD HL,137CHLD HL,DHALF21 7C 13
    Load Register Pair HL with the starting address of a double precision constant equal to 0.5D0
    12B1-12B3
    CALL 09F7HCALL VMOVFMCD F7 09
    GOSUB to 09F7H to move 0.5D0 to the ACCumulator
    12B4-12B6
    CALL 0C77HCALL DADDCD 77 0C
    Call the DOUBLE PRECISION ADD function (which adds the double precision value in REG 2 to the value in ACCumulator (which is the constant 0.5D0). Result is left in ACCumulator)
    12B7
    XOR AAF
    Zero Register A and clear the status flags; particularly the CARRY FLAG
    12B8-12BA
    CALL 0B7BHCALL DINTFOCD 7B 0B
    Isolate the integer part of the double precision number via a GOSUB to 0B7BH
    12BB
    POP HLE1
    Restore the buffer address from the STACK and put it in Register Pair HL
    12BC
    POP BCC1
    Restore the decimal and comma counters from the STACK and put it in Register Pair BC
    12BD-12BF
    LD DE,138CHLD DE,FODTBL11 8C 13
    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
    12C0-12C1
    LD A,0AH3E 0A
    We are going to want to convert ten digits, so load Register A with the number of times to divide the double precision value in ACCumulator by a power of 10
    Top of a loop to convert the next digit. It is executed “A” times.
    12C2-12C4
     ↳ FOUCD1
    CALL 1291HCALL FOUTEDCD 91 12
    Check to see if we need to put in a decimal point or a comma at the location pointed to by HL via a GOSUB to 1291H
    12C5
    PUSH BCC5
    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
    12C6
    PUSH AFF5
    Save the number of digits to process / division count (stored in Register Pair A) to the STACK
    12C7
    PUSH HLE5
    Save the current buffer address (stored in Register Pair HL) to the STACK
    12C8
    PUSH DED5
    Save the address of the power of 10 table (stored in Register Pair DE) to the STACK
    12C9-12CA
    LD B,2FHLD B,”0″-106 2F
    Load Register B (which will be the quotient in ASCII for each division) with the ASCII value for a zero character minus one since the loop which follows starts by INCrementing the value
    12CB
     ↳ FOUCD2
    INC B04
    Top of a loop. Bump the ASCII value for the digit in Register B so as to start with ASCII “0”
    12CC
    POP HLE1
    Get the address of the power of 10 table (i.e., the divisor) from the STACK and put it in Register Pair HL and
    12CD
    PUSH HLE5
    …. put it right back into the STACK so that it can be restored during the loop
    12CE-12D0
    CALL 0D48HCALL DADDFSCD 48 0D
    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)
    12D1-12D2
    JR NC,12CBHJR NC,FOUCD230 F8
    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)
    12D3
    POP HLE1
    If we are here because the C FLAG fired, then we have subtracted once too many times. So we need to un-subtract once. To do that we first need to get the address of the power table from the STACK and put it in Register Pair HL
    12D4-12D6
    CALL 0D36HCALL DADDFOCD 36 0D
    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 ACCumulator to make it a positive value. Return with the correct remainder in ACCumulator
    12D7
    EX DE,HLEB
    Swap DE and HL so that th eopoert of ten pointer is now in DE.
    12D8
    POP HLE1
    Get the current buffer address from the STACK and put it in Register Pair HL
    12D9
    LD (HL),B70
    Save the ASCII value for the digit in Register B at the location of the input buffer pointer (stored in Register Pair HL)
    12DA
    INC HL23
    Bump the buffer pointer in Register Pair HL since we have just put a digit there
    12DB
    POP AFF1
    Get the loop counter back into Register A
    12DC
    POP BCC1
    Get the decimal point and comma counter from the STACK and put it in Register Pair BC
    12DD
    DEC A3D
    Decrement the loop counter value in Register A (we are going to loop 10 times)
    12DE-12DF
    JR NZ,12C2HJR NZ,FOUCD120 E2
    Loop 10 times until the ASCII string has been figured
    12E0
    PUSH BCC5
    At this point, we have finished printing the last digit, so now we want to convert the remaining digits using single precision routines (which are faster). First, save the decimal and comma counters (stored in Register Pair BC) to the STACK
    12E1
    PUSH HLE5
    Save the input buffer pointer (stored in Register Pair HL) to the STACK
    12E2-12E4
    LD HL,411DHLD HL,DFACLO21 1D 41
    Point HL to the remaining digits for processing as a single precision number
    12E5-12E7
    CALL 09B1HCALL MOVRMCD B1 09
    Move the numbers that are left to ACCumulator via a GOSUB to MOVRM
    12E8-12E9
    JR 12F6HJR FOUCDC18 0C
    Jump to 12F6H to convert that last half to ASCII

    12EA – LEVEL II BASIC MATH ROUTINE– “FOUTCS”

    This routine is to convert a SINGLE precision value to an INTEGER which will be the decimal digits. Divide the integer equivalent by 100,000 and 10,000. Use the code at 1335H to convert the last 1000 to ASCII.
    12EA
     ↳ FOUTCS
    PUSH BCC5
    Save the decimal/comma count (in Register Pair BC) to the STACK
    12EB
    PUSH HLE5
    Save the buffer pointer (stored in Register Pair HL) to the STACK
    12EC-12EE
    CALL 0708HCALL FADDHCD 08 07
    Round the number to the nearest integer via a GOSUB to 0708H which will add a single precision value of 0.5 to the single precision value in ACCumulator. The result is stored in BC/DE
    12EF
    INC A3C
    When a number is positive and non-zero, a FADDH call to round will always exit with the HIGH ORDER of 0 in Register A. So we add 1 to force A to be non-zero.
    12F0-12F2
    CALL 0AFBHCALL QINTCD FB 0A
    GOSUB to 0AFBH to convert the positive single precision value in ACCumulator to an integer. The result is stored in C/D/E
    12F3-12F5
    CALL 09B4HCALL MOVFRCD B4 09
    Save the C/D/E number into the ACCumulator via a GOSUB to MOVFR
    12F6
     ↳ FOUCDC
    POP HLE1
    Get the current buffer pointer value from the STACK and put it in Register Pair HL
    12F7
    POP BCC1
    Get the decimal/comma count value from the STACK and put it in Register Pair BC
    12F8
    XOR AAF
    Clear the CARRY FLAG, which is our flag to calculate two digits
    12F9-12FB
    LD DE,13D2HLD DE,FOSTBL11 D2 13
    Load Register Pair DE with the starting address for a series of integer values (in this case, 100,000) and then fall through to FOUCS1

    12FC – LEVEL II BASIC MATH ROUTINE– “FOUCS1”

    This routine is to calculate the next digit of the number.
    12FC
     ↳ FOUCS1
    CCF3F
    Complement the Carry flag, which tracks when we are done with the division loop of 12FC-1327H
    12FD-12FF
    CALL 1291HCALL FOUTEDCD 91 12
    Check to see if we need to put a decimal point or a comma before the current number via GOSUB to FOUTED
    1300
    PUSH BCC5
    Save the decimal and comma counter (stored in Register Pair BC) to the STACK
    1301
    PUSH AFF5
    Save the carry flag (which acts as our digit count for the count of the number of times through this loop) to the STACK
    1302
    PUSH HLE5
    Save the current buffer pointer value (stored in Register Pair HL) to the STACK
    1303
    PUSH DED5
    Save the power of 10 table pointer (stored in Register Pair DE) to the STACK
    1304-1306
    CALL 09BFHCALL MOVRFCD BF 09
    Loads the SINGLE PRECISION value in ACCumulator into Register Pair BC/DE via A GOSUB to MOVRF.
    1307
    POP HLE1
    Get the power of 10 table address (the integer value for 100,000) from the STACK and put it in Register Pair HL
    1308-1309
    LD B,2FHLD B,”0″-106 2F
    Set B to be the next digit to print. Since the next step INCremenets B, we need to start off with B one too low.

    130A – LEVEL II BASIC MATH ROUTINE– “FOUCS2”

    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.
    130A
     ↳ FOUCS2
    INC B04
    Bump the ASCII value from the digit in Register B to increase the ASCII value from 0 and upward
    130B
    LD A,E7B
    Load Register A with the Low Order/LSB of the single precision value in Register E
    130C
    SUB (HL)96
    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
    130D
    LD E,A5F
    Load Register E with the adjusted LSB of the single precision value in Register A
    130E
    INC HL23
    Bump the value of the memory pointer in Register Pair HL to the next digit of 100,000
    130F
    LD A,D7A
    Load Register A with the Middle Order/NMSB of the single precision value in Register D
    1310
    SBC A,(HL)9E
    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
    1311
    LD D,A57
    Load Register D with the adjusted NMSB of the single precision value in Register A
    1312
    INC HL23
    Bump the value of the memory pointer in Register Pair HL to the MSB of 100,000
    1313
    LD A,C79
    Load Register A with the High Order/MSB of the single precision value in Register C
    1314
    SBC A,(HL)9E
    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)
    1315
    LD C,A4F
    Load Register C with the adjusted MSB of the single precision value in Register A
    1316
    DEC HL2B
    Decrement the value of the memory pointer in Register Pair HL to the NMSB of 100,000
    1317
    DEC HL2B
    Decrement the value of the memory pointer in Register Pair HL again, now to the LSB of 100,000
    1318-1319
    JR NC,130AHJR NC,FOUCS230 F0
    Loop until the ASCII value for the digit under 100,000 has been figured
    131A-131C
    CALL 07B7HCALL FADDACD B7 07
    We need to add 100,000 to C/D/E 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
    131D
    INC HL23
    Bump the value of the memory pointer in Register Pair HL to now point to the 10,000 constant
    131E-1320
    CALL 09B4HCALL MOVFRCD B4 09
    Save the remainder as a current value by GOSUB to 09B4H (which moves the SINGLE PRECISION value in DC/DE into ACCumulator)
    1321
    EX DE,HLEB
    Load Register Pair DE with the address of the next value to divide the current value in ACCumulator by (which is the constant of 10,000)
    1322
    POP HLE1
    Get the value of the memory pointer from the STACK and put it in Register Pair HL
    1323
    LD (HL),B70
    Save the ASCII value for the digit in Register B at the location of the input buffer pointer in Register Pair HL
    1324
    INC HL23
    Bump the value of the input buffer pointer in Register Pair HL
    1325
    POP AFF1
    Get the carry flag from the STACK and put it in Register Pair AF
    1326
    POP BCC1
    Get the value from the STACK and put it in Register Pair BC so it can be saved later
    1327-1328
    JR C,12FCHJR C,FOUCS138 D3
    If the carry flag is set, then reset it and loop the dividing by 10,000 until the integer portion is found
    1329
    INC DE13
    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
    132A
    INC DE13
    and again bump the value of the memory pointer in Register Pair DE, so now DE points to the constant 1,000
    132B-132C
    LD A,04H3E 04
    Load Register A with the number of digits for the ASCII string to be figured
    132D-132E
    JR 1335HJR FOUCI118 06
    Jump to 1335H to convert the remainder to 4 ASCII digits. Note that the CARRY FLAG will be off.

    132F – This routine will convert an INTEGER to ASCII– “FOUTCI”

    This routine converts an integer into decimal digits by dividing the integer portion of the current value by 100,000 using compound subtraction. The quotient is kept in Register B as an ASCII value and A=0 on exit.
    132F
     ↳ FOUTCI
    PUSH DED5
    Generally preserve DE. This will be POPped just before the RETurn
    1330-1332
    LD DE,13D8HLD DE,FOITBL11 D8 13
    Load Register Pair DE with the starting address of the descending powers of 10 starting at 10,000
    1333-1334
    LD A,05H3E 05
    Load Register A with the number of digits for the ASCII string to be built (i.e., 5 since the maximum positive integer is 32768)
    1335-1337
     ↳ FOUCI1
    CALL 1291HCALL FOUTEDCD 91 12
    Top of the big loop. Check to see if a decimal point or comma needs to be placed before the digit being processed via a GOSUB to FOUTED
    1338
    PUSH BCC5
    Save the decimal and comma counter (stored in Register Pair BC) to the STACK
    1339
    PUSH AFF5
    Save the number of digits-to-process counter (stored in Register A) to the STACK
    133A
    PUSH HLE5
    Save the address of the power table (stored in Register Pair HL) to the STACK
    133B
    EX DE,HLEB
    Load Register Pair HL with the starting address of the descending powers of 10 starting at 10,000 (stored in Register Pair DE)
    133C
    LD C,(HL)4E
    Load Register C with the LSB for the power of 10 stored in Register Pair HL
    133D
    INC HL23
    Bump the value of the memory pointer in Register Pair HL to be the MDB of the power of 10
    133E
    LD B,(HL)46
    Load Register B with the MSB for the integer value at the location of the memory pointer in Register Pair HL
    133F
    PUSH BCC5
    Save the integer value of the power of 10 in Register Pair BC to the STACK
    1340
    INC HL23
    Bump the value of the memory pointer in Register Pair HL to the next value in the power of 10 table
    1341
    EX (SP),HLE3
    Swap (SP) and HL so that the pointer to the power of 10 table is in the STACK and the power of ten is in HL
    1342
    EX DE,HLEB
    Put the power of ten into DE
    1343-1345
    LD HL,(4121H)LD HL,(FACLO)2A 21 41
    Load Register Pair HL with the integer value in ACCumulator
    1346-1347
    LD B,2FHLD B,”0″ – 106 2F
    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
    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).
    1348
     ↳ FOUCI2
    INC B04
    Bump the ASCII value for the digit in Register B (so it starts at 0 and moves up each loop)
    1349
    LD A,L7D
    Load Register A with the LSB of the integer value in Register L
    134A
    SUB E93
    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
    134B
    LD L,A6F
    Load Register L with the adjusted value of the LSB of the integer value in Register A
    134C
    LD A,H7C
    Load Register A with the value of the MSB of the integer value in Register H
    134D
    SBC A,D9A
    Subtract the MSB of the integer value in Register D from the value of the MSB of the integer value in Register A
    134E
    LD H,A67
    Load Register H with the adjusted value of the MSB of the integer value in Register A
    134F-1350
    JR NC,1348HJR NC,FOUCI230 F7
    If the quotient (stored in HL) >= the current power of 10 (stored in DE) then we need to loop back to 1348H
    1351
    ADD HL,DE19
    The problem with using the CARRY FLAG as a trigger is that it triggers once you have already gone too far. So we need to go back 1. To do this, add the remainder (stored as an integer in Register Pair DE) to the quotient (stored in Register Pair HL as an integer)
    1352-1354
    LD (4121H),HLLD (FACLO),HL22 21 41
    Save the integer remainder (stored in Register Pair HL) in ACCumulator
    1355
    POP DED1
    Get the address of the next power of 10 from the STACK and put it in Register Pair DE
    1356
    POP HLE1
    Get the memory pointer for the buffer from the STACK and put it in Register Pair HL
    1357
    LD (HL),B70
    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)
    1358
    INC HL23
    Bump the value of the buffer pointer in Register Pair HL since we just filled that spot with an ASCII value
    1359
    POP AFF1
    Get the number of digits to convert (i.e., the digit counter) from the STACK and put it in A
    135A
    POP BCC1
    Get the decimal/comma counts from the STACK and put it into Register Pair BC
    135B
    DEC A3D
    Decrement the value of the counter in Register A (which is a countdown from 5)
    135C-135D
    JR NZ,1335HJR NZ,FOUCI120 D7
    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
    135E-1360
    CALL 1291HCALL FOUTEDCD 91 12
    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
    1361
    LD (HL),A77
    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. Note that we do not advance HL, so we can overwrite this trailing zero if necessary.
    1362
    POP DED1
    Get the value from the STACK (which was whatever value was in DE when this routine started) and put it in Register Pair DE
    1363
    RETC9
    RETurn to CALLer with A=0

    1364-136B – DOUBLE PRECISION CONSTANT STORAGE LOCATION– “TENTEN”

    1364-136B
     ↳ TENTEN
    00 00 00 00 F9 02 15 A2
    A double precision constant equal to 10000000000 is stored here

    136C-1373 – DOUBLE PRECISION CONSTANT STORAGE LOCATION– “FOUTDL”

    136C-1373
     ↳ FOUTDL
    FD FF 9F 31 A9 5F 63 B2
    A double precision constant equal to 999,999,999,999,999.95 is stored here

    1374-137B – DOUBLE PRECISION CONSTANT STORAGE LOCATION– “FOUTDU”

    1374-137B
     ↳ FOUTDU
    FE FF 03 BF C9 1B 0E B6
    A double precision constant equal to 9,999,999,999,999,999.5 is stored here

    137C-1383 – DOUBLE PRECISION CONSTANT STORAGE LOCATION– “DHALF”

    137C-137F
     ↳ DHALF
    00 00 00 00
    A double precision constant equal to 0.5D0 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
    1380-1383
     ↳ FHALF
    00 00 00 80
    A double precision constant equal to 0.5E0 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

    1384-138B – DOUBLE PRECISION CONSTANT STORAGE LOCATION– “FFXDXM”

    1384-138B
     ↳ FFXDXM
    00 00 04 BF C9 1B 0E B6
    A double precision constant equal to 1D16

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

    138C-1392
     ↳ FODTBL
    00 80 C6 A5 7E 8D 03
    1D15
    1393-1399
    00 40 7A 10 F3 5A 00
    1D14
    139A-13A0
    00 A0 72 4E 18 09 00
    1D13
    13A1-13A7
    00 10 A5 D5 E8 00 00
    1D12
    13A1-13A7
    00 10 A5 D5 E8 00 00
    1D11
    13A8-13AE
    00 E8 76 48 17 00 00
    1D10
    13AF-13B5
    00 E4 0B 54 02 00 00
    1D9
    13B6-13BC
    00 CA 9A 3B 00 00 00
    1D8
    13BD-13C3
    00 E1 F4 05 00 00 00
    1D7
    13C4-13CA
    80 96 98 00 00 00 00
    1D6
    13CB-13D1
    40 42 0F 00 00 00 00
    1D5

    13D2-13D9 – SINGLE PRECISION POWER OF TEN TABLE LOCATION– “FOSTBL

    13D2-13D4
     ↳ FOSTBL
    A0 86 01
    1E5
    13D5-13D7
    10 27 00
    1E4

    13D8 – SINGLE PRECISION POWER OF TEN TABLE LOCATION– “FOITBL

    13D8-13D9
     ↳ FOITBL
    10 27
    10,000
    13DA-13DB
    E8 03
    1,000
    13DC-13DD
    64 00
    100
    13DE-13DF
    0A 00
    10
    13E0-13E1
    01 00
    1

    13E2-13E6 – LEVEL II BASIC MATH ROUTINE– “PSHNEG”

    13E2-13E4
     ↳ PSHNEG
    LD HL,0982HLD HL,NEG21 82 09
    Load Register Pair HL with the address of the routine for conversion of floating point numbers from negative to positive
    13E5
    EX (SP),HLE3
    Exchange the value of that routines jump address to the STACK with the value of the return address in Register Pair HL
    135E-1360
    CALL 1291HCALL FOUTEDCD 91 12
    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

    13E7-13F1 – LEVEL II BASIC SQR(n)– “SQR”

    This routine computes the square root of any value in ACCumulator. It processes it by raising n to the power of 0.5. The root is left in ACCumulator as a single precision value. Single-precision values only should be used
    13E7-13F1
     ↳ SQR
    CALL 09A4HCALL PUSHFCD A4 09
    GOSUB 09A4 which moves the SINGLE PRECISION value in ACCumulator to the STACK (stored in LSB/MSB/Exponent order)
    13EA-13EC
    LD HL,1380HLD HL,FHALF21 80 13
    Load Register Pair HL with the starting address of a single precision constant equal to 0.5 (which will be the exponent)
    13ED-13EF
    CALL 09B1HCALL MOVRMCD B1 09
    GOSUB 09B1H (which moves a SINGLE PRECISION number pointed to by HL to ACCumulator)
    13F0-13F1
    JR 13F5HJR FPWRT18 03
    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

    13F2-1478H LEVEL II BASIC X to the Y Power (X^Y) ROUTINE– “FPWRQ”

    A call to 13F2H raises the single precision value which has been saved to the STACK to the power specified in ACCumulator. The result will be returned in ACCumulator. The method of computation is e ** (y ln x).
    13F2-13F4
     ↳ FPWRQ
    CALL 0AB1HCALL FRCSNGCD B1 0A
    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 ACCumulator from integer or double precision into single precision)
    13F5
     ↳ FPWRT
    POP BCC1
    Get the MSB of the single precision value from the STACK and put it in Register Pair BC
    13F6
    POP DED1
    Get the NMSB and the LSB of the single precision value from the STACK and put it in Register Pair DE

    13F7 – LEVEL II BASIC Exponentiation routine– “FPWR”

    This routine handles the exponentiation routine of X^Y. To do so, first Y is checked for 0 and, if so, then the answer is simply 1. Then we check X for 0 and, if so, then the answer is simply 0.

    If neither of those scenarios is the case, then must check to see if X is positive and, if not, check to see if Y is negative and if it is even or odd.

    If Y is negative, the we negate it to avoid the LOG routine giving a ?FC ERROR when we call it.

    If X is negative and Y is odd, the NEG routine is pushed to the STACK as the exit rouine so that the result will be negative.

    The actual math here is X^Y = EXP(Y*LOG(X)).
    13F7-13F9
     ↳ FPWR
    CALL 0955HCALL SIGNCD 55 09
    First, check Y to see if Y is zero via a GOSUB 0955H to check the sign for the single precision value in ACCumulator (the exponent)
    13FA
    LD A,B78
    Next, check to see if X is zero by first loading Register A with the MSB of the number to be raised (stored as a single precision value in Register B)
    13FB-13FC
    JR Z,1439HJR Z,EXP28 3C
    If it is zero then we already know our ansder which is, mathematically, a 1 so JUMP to the EXP(n)routine at 1439H
    13FD-13FF
    JP P,1404HJP P,POSEXPF2 04 14
    After knowing that X isn’t 0, we must check the sign of Y. If it is positive, then JUMP to POSEXP to skip the next 2 opcodes (which check to see if zero is involved) if the exponent (the single precision value in ACCumulator) is positive
    1400
    OR AB7
    Check to see if this is a ZERO raised to the minus power.
    1401-1403
    JP Z,199AHJP Z,DV0ERRCA 9A 19
    If it is 0 raised to a minus power, display a ?/0 ERRORmessage since the single precision value in ACCumulator is negative and the single precision value in Register Pairs BC and DE is equal to zero.
    /0 ERROR entry point
    1404
     ↳ POSEXP
    OR AB7
    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
    1405-1407
    JP Z,0779HJP Z,DV0ERRCA 79 07
    If the value to be raised (i.e., the single precision value in Register Pairs BC and DE) is equal to zero, then we already know the result will be zero, so JUMP to ZERO0.
    1408
    PUSH DED5
    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
    1409
    PUSH BCC5
    Save the exponent and the MSB of the single precision value in Register Pair BC to the STACK
    140A
    LD A,C79
    Now we want to check the sign of X. First, load Register A with the value of the MSB of the single precision value to be raised (which is stored in Register C)
    140B-140C
    OR 7FHF6 7F
    Turn the Z FLAG off by ORing against 7FH (0111 1111) in Register A
    140D-140F
    CALL 09BFHCALL MOVRFCD BF 09
    Load the Y (the power) into BC/DE by GOSUB to 09BF which loads the SINGLE PRECISION value in ACCumulator (the exponent) into Register Pair BC/DE
    1410-1412
    JP P,1421HJP P,FPWR1F2 21 14
    If X is positive, then jump down to FPWR1 as we have nothing advanced to process
    1413
    PUSH DED5
    Otherwise, we need to do some more math. Save the Y value to the STACK first by saving the NMSB and the LSB of the exponent (the single precision value in Register Pair DE) to the STACK
    1414
    PUSH BCC5
    and then Save the exponent and the LSB of the single precision value in Register Pair BC to the STACK
    1415-1417
    CALL 0B40HCALL INTCD 40 0B
    Check to see if the Y is an integer via a GOSUB to 0B40H to figure the integer portion of the exponent (i.e., the single precision value in ACCumulator) into A with the truncated floating point portion into ACCumulator
    1418
    POP BCC1
    Restore the exponent and the MSB of the Y value from the STACK and put it in Register Pair BC
    1419
    POP DED1
    Restore the NMSB and the LSB of the Y value from the STACK and put it in Register Pair DE
    141A
    PUSH AFF5
    Save the LSB of the integer to the STACK for even and odd information
    141B-141D
    CALL 0A0CHCALL FCOMPCD 0C 0A
    Make sure we have an integer by GOSUBing to FCOMP which will compare the original exponent to the truncated one by GOSUB to routine at 0A0CH which algebraically compares the single precision value in BC/DE to the single precision value ACCumulator.
    The results are stored in A as follows:
    If ACCumulator = BCDEA=00
    If ACCumulator > BCDEA=01
    If ACCumulator < BCDEA=FF
    141E
    POP HLE1
    Get the exponent as an integer from the STACK and put it in Register H. This will help us determine if it is even or odd.
    141F
    LD A,H7C
    Load Register A with the exponent as an integer (as stored in Register H)
    1420
    RRA1F
    Rotate that exponent right by one, so we can tell if it is even or odd. If the exponent (as an integer) is odd, set the CARRY FLAG. RRA rotates Register A right one bit, with Bit 0 going to CARRY and CARRY going to Bit 7.
    1421
     ↳ FPWR1
    POP HLE1
    Prepare to get the X back into the ACCumulator by fetching the number from the top of the STACK into Register Pair HL
    1422-1424
    LD (4123H),HLLD (FAC-1),HL22 23 41
    Save the HIGH ORDERs of X to the ACCumulator
    1425
    POP HLE1
    Get the LOW ORDERS of X from the STACK and put it in Register Pair HL
    1426-1428
    LD (4121H),HLLD (FACLO),HL22 21 41
    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 ACCumulator
    1429-142B
    CALL C,13E2HCALL C,PSHNEGDC E2 13
    If the exponent is odd then we need to negate the final result, so GOSUB to 13E2H to PUSH the address of the NEG routine into the STACK
    142C-142E
    CALL Z,0982HCALL Z,NEGCC 82 09
    If the exponent is an integer and the base is negative, GOSUB to 0983H to invert the value of the exponent
    142F
    PUSH DED5
    Save the NMSB and the LSB of the Y/exponent (i.e., the single precision value in Register Pair DE) to the STACK
    1430
    PUSH BCC5
    Save the MSB of the Y/exponent (i.e., the single precision value in Register Pair BC) to the STACK
    1431-1433
    CALL 0809HCALL LOGCD 09 08
    Now we want to compute EXP(Y*LOG(X)) so we CALL the LOG(N) routine at 0809H (which computes the natural log (base E) of the single precision value in ACCumulator. The result is returned as a single precision value in ACCumulator. Can give an ILLEGAL FUNCTION CALL erro if a negative base is raised to a power with a fraction)
    1434
    POP BCC1
    Get the exponent and the MSB of the single precision value from the STACK and put it in Register Pair BC
    1435
    POP DED1
    Get the NMSB and the LSB of the single precision from the STACK and put it in Register Pair DE
    1436-1438
    CALL 0847HCALL FMULTCD 47 08
    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 ACCumulator by the value in (BC/DE). The product is left in ACCumulator

    1439 – LEVEL II ROM EXPROUTINE.

    Single-precision only. (ACCumulator = EXP(REG1)).

    To process this function we first save the original argument and multiply the ACCumulator by log2(e). The result of that is then used to determine if we will get overflow, since exp(x)=2^(x*log2(e)) where log2(e)=log(e) base 2.

    We then save the integer part of this to scale the answer at the end, since 2^y=2^int(y)*2^(y-int(y)) and 2^int(y) is easy to compute.

    So in the end we compute 2^(x*log2(e)-int(x*log2(e))) by p(ln(2)*(int(x*log2(e))+1)-x) where p is an approximation polynomial.

    The result is then scaled by the power of 2 we previously saved.

    A call to 1439H raises E (natural base) to the value in ACCumulator which must be a single precision value. The result will be returned in ACCumulator as a single precision number.
    1439-143B
     ↳ EXP
    CALL 09A4HCALL PUSHFCD A4 09
    Save the argument via a GOSUB to 09A4 to move the SINGLE PRECISION value in ACCumulator (the exponent) to the STACK (stored in LSB/MSB/Exponent order)
    143C-143E
    LD BC,8138H01 38 81
    Next we want to do a LOG(E) in base 2, so load Register Pair BC with the exponent and MSB of a single precision constant
    143F-1441
    LD DE,AA3BH11 3B AA
    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)
    1442-1444
    CALL 0847HCALL FMULTCD 47 08
    We next want to calculate INT(ARG/LN(2)) = INT(ARG*LOG2(E)). So we will 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 ACCumulator by the value in (BC/DE). The product is left in ACCumulator
    1445-1447
    LD A,(4124H)LD A,(FAC)3A 24 41
    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 ACCumulator.
    1448-1449
    CP 88HFE 88
    Next we want to see if ABS(ACCumulator) is >= 128 (i.e., if the integer portion of the single precision value in ACCumulator uses more than 7 bits of precision) by comparing it against a mask of 1000 1000
    144A-144C
    JP NC,0931HP NC,MLDVEXD2 31 09
    If the single precision value in ACCumulator uses more than 7 bits of precision for its integer portion then it is too big and we need to JUMP to MLDVEX to deal with that.
    144D-144F
    CALL 0B40HCALL INTCD 40 0B
    So now that we know the integer portion is not too big, but we need to see if the argument is too big as well so we GOSUB to 0B40H to get the integer portion of the value in ACCumulator and return with it in Register A
    1450-1451
    ADD A,80HC6 80
    Adjust the value in Register A by masking it against 1000 0000
    1452-1453
    ADD A,02HC6 02
    Adjust the value in Register A by adding 2 more. We will either get an overflow (C FLAG) or we wont (NC FLAG)
    1454-1456
    JP C,0931HJP C,MLDVEXDA 31 09
    If (exponent * 2 ln 2) is => 126 (meaning when 2 was added it it, it overflowed with a 128), jump to 0931H
    1457
    PUSH AFF5
    So now neither has overflowed, so save the scale factor +82H (as stored in Register Pair AF) to the STACK
    1458-145A
    LD HL,07F8HLD HL,FONE21 F8 07
    Load Register Pair HL with a single precision constant equal to 1.0 (as found at 1458H)
    145B-145D
    CALL 070BHCALL FADDSCD 0B 07
    Go add the single precision constant 1.0 (as pointed to by Register Pair HL) to the current value in ACCumulator which is EXP * 2 ln 2
    145E-1460
    CALL 0841HCALL MULLN2CD 41 08
    Need to multiply that by ln 2, so GOSUB to 0841H to multiply (1 + [EXP * 2 ln 2]) (as stored in ACCumulator) by 0.693147
    1461
    POP AFF1
    Get the scale factor (as stored in the STACK) and put it in Register Pair AF
    1462
    POP BCC1
    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
    1463
    POP DED1
    and then get the NMSB and the LSB of the single precision value from the STACK and put it in Register Pair DE
    1464
    PUSH AFF5
    Put the scale factor (the integerized EXP * 2 ln 2) as stored in Register Pair AF onto the STACK
    1465-1467
    CALL 0713HCALL FSUBCD 13 07
    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 ACCumulator. The difference is left in ACCumulator)
    1468-146A
    CALL 0982HCALL NEGCD 82 09
    To force that difference to be a positive number we GOSUB to 0982H which makes the current single precision value in ACCumulator positive
    146B-146D
    LD HL,1479HLD HL,EXPCON21 79 14
    Load Register Pair HL with the starting address for a series of 8 coefficients so as to enable us to evaluate the approximation polynomial in the next instruction
    146E-1470
    CALL 14A9HCALL POLYCD A9 14
    GOSUB to 14A9H to do that series of computations
    1471-1473
    LD DE,0000H11 00 00
    We want to make sure that FMULT will check for an exponent overflow at the end of this routine, so we can’t just add it to the exponent. Rather, we will multiply it by 2^(B-1) so that FMULT will check. So first, load the integerized equivalent of EXP * 2 lnt 2 into BC/DE so first we load Register Pair DE with zero …
    1474
    POP BCC1
    … and then get the value from the STACK and put it in Register Pair BC
    1475
    LD C,D4A
    Load Register C with zero (since Register D was filled with a zero in 1471H)
    1476-1478
    JP 0847HJP FMULTC3 47 08
    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 ACCumulator by the value in (BC/DE). The product is left in ACCumulator

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

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

    149A-14C8 – LEVEL II BASIC MATH ROUTINE– “POLYX”

    This is a general purpose summation routine which computes the series C0*X+C1*X^3+C2*X^5+C3*X^7+…+C(N)*X^(2*N+1) 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.

    The pointer to degree+1 is in (HL) and the constants should follow the egree, stored in reverse order. X is in the ACCumulator.
    149A-149C
     ↳ POLYX
    CALL 09A4HCALL PUSHFCD A4 09
    Save X to the STACK via a GOSUB to 09A4 to which move the SINGLE PRECISION value in ACCumulator to the STACK (stored in LSB/MSB/Exponent order)
    149D-149F
    LD DE,0C32HLD DE,FMULTT11 32 0C
    Load Register Pair DE with the return address of the FMULTT routine …
    14A0
    PUSH DED5
    … and push it to the STACK, so that once this routine ends, it will be multiplied by X
    14A1
    PUSH HLE5
    Save pointer to the constant (as stored in Register Pair HL) to the STACK
    14A2-14A4
    CALL 09BFHCALL MOVRFCD BF 09
    We need to square X, so we do that in the next two steps. First, GOSUB to 09BFH which loads the SINGLE PRECISION value in ACCumulator into Register Pair BC/DE
    14A5-14A7
    CALL 0847HCALL FMULTCD 47 08
    Since ACCumulator 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 ACCumulator by the value in (BC/DE). The product is left in ACCumulator)
    14A8
    POP HLE1
    Restore the consatnt pointer from the STACK and put it in Register Pair HL, and then fall through into the POLY routine

    14A9 – LEVEL II BASIC MATH ROUTINE– “POLY”

    General polynomial evaluator routine. Pointer to degree+1 is in (HL), and that gets updated through the computation. The Constants follow the degree and should be stored in reverse order. The ACCumulator has the X. The formula is c0+c1*x+c2*x^2+c3*x^3+…+c(n-1)*x^(n-1)+c(n)*x^n
    14A9-14AB
     ↳ POLY
    CALL 09A4HCALL PUSHFCD A4 09
    Save the “X” to the STACK. 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 ACCumulator to the STACK (stored in LSB/MSB/Exponent order)
    14AC
    LD A,(HL)7E
    Fetch the degree (i.e., the number of values to be figured at the location of the memory pointer in Register Pair HL) into Register A
    14AD
    INC HL23
    Bump the value of the memory pointer in Register Pair HL so that it points to the first constant/coefficient
    14AE-14B0
    CALL 09B1HCALL MOVRMCD B1 09
    Now load that constant/coefficient (stored in HL) and move it to ACCumulator by GOSUB to 09B1H (which moves a SINGLE PRECISION number pointed to by HL to ACCumulator)
    14B1
    LD B,0F106 F1
    Z-80 Trick! If passing through, this will simply alter Register B and the next instruction of POP AF will not be processed.
    14B2
     ↳ POLY1
    POP AFF1
    Get the degree (count of coefficients left) from the STACK and put it in Register A
    14B3
    POP BCC1
    Get the value of “X” from the STACK and put it in Register Pair BC/DE – Step 1 and …
    14B4
    POP DED1
    … Step 2
    14B5
    DEC A3D
    Count 1 of the terms as computed by decrementing the counter in Register A
    14B6
    RET ZC8
    If that decrement results in a zero (meaning the series of computations has been completed) return out of the subroutine
    14B7-14B8
    PUSH DE
    PUSH BCD5
    Save the NMSB and the LSB of “X” from DE to the STACK and save the MSB of “X” from BC to the STACK
    14B9
    PUSH AFF5
    Save counter of the remaining degrees (terms to compute) as tracked by Register A into the STACK
    14BA
    PUSH HLE5
    Save the value of the memory pointer to the next constant/coefficient (stored in Register Pair HL) to the STACK
    14BB-14BD
    CALL 0847HCALL FMULTCD 47 08
    Compute C(I)*x by GOSUB to 0847H which is the SINGLE PRECISION MULTIPLY routine (which multiplies the current value in ACCumulator by the value in (BC/DE). The product is left in ACCumulator
    14BE
    POP HLE1
    Restore the coefficient table address (from the STACK) to Register Pair HL
    14BF-14C1
    CALL 09C2HCALL MOVRMCD C2 09
    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)
    14C2
    PUSH HLE5
    Save the next coefficient (stored in Register Pair HL) to the STACK
    14C3-14C5
    CALL 0716HCALL FADDCD 16 07
    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 ACCumulator. The sum is left in ACCumulator)
    14C6
    POP HLE1
    Restore the coefficient table address (from the STACK) to Register Pair HL
    14C7-14C8
    JR 14B2HJR POLY118 E9
    Jump back to 14B2H to continue the series. ACCumulator contains the current term

    14C9-1540 – LEVEL II BASIC RND(n)ROUTINE– “RND”.

    If the passed argument is 0, the last random number generated is returned. If the argument is < 0, a new sequence of random numbers is started using the argument.

    To form the next random number in the sequence, we multiply the previous random number by a random constant, and add in another random constant. Then the HIGH ORDER and LOW ORDER bytes are switched, the exponent is put where it will be shifted in by normal, and the exponent in the ACCUMULATOR is set to 80H so the result will be less than 1. This is then normalized and saved for the next time.

    The reason we switch the HIGH ORDER and LOW ORDER bytes is so we have a random chance of getting a number less than or greater than .5

    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 ACCumulator, The random value is returned in ACCumulator 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.

    There is a bug in the operation of this command. According to Vernon Hester RND(n) where n is an integer from 1 to 32767 is supposed to return an integer from 1 to n. However, when n is a power of two raised to a positive integer exponent from 0 to 14 sometimes returns n+1
    14C9-14CB
     ↳ RND
    CALL 0A7FHCALL FRCINTCD 7F 0A
    First convert the argument to an integer via a GOSUB to the CONVERT TO INTEGER routine at 0A7FH (where the contents of ACCumulator are converted from single or double precision to integer and deposited into HL)
    14CC
    LD A,H7C
    Load Register A with the value of the MSB for the integer value in Register H
    14CD
    OR AB7
    Check to see if the integer value in Register Pair HL is negative
    14CE-14D0
    JP M,1E4AHJP M,FCERRFA 4A 1E
    Since we won’t accept a negative number, display a ?FC ERRORmessage if the integer value in Register Pair HL is negative
    14D1
    OR LB5
    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
    14D2-14D4
    JP Z,14F0HJP Z,RND0CA F0 14
    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), which is a number between 0 and 1)
    14D5
    PUSH HLE5
    Since it wasn’t zero, we need to save the argument (as stored in Register Pair HL) to the STACK
    14D6-14D8
    CALL 14F0HCALL RND0CD F0 14
    Generate a random number between 0 and 1 via a call to GOSUB to 14F0H (which generates RND(0)) and return with the single precision result in ACCumulator
    14D9-14DB
    CALL 09BFHCALL MOVRFCD BF 09
    Move the random number we just generated into BC/DE via a GOSUB to 09BFH which loads the SINGLE PRECISION value in ACCumulator into Register Pair BC/DE
    14DC
    EX DE,HLEB
    Swap some registers so that the random number is now in B/C/H/L
    14DD
    EX (SP),HLE3
    Swap (SP) and HL so that the LOW ORDER bytes of the random number are at the top of the STACK, and HL now holds the integer argument
    14DE
    PUSH BCC5
    Save the HIGH ORDER bytes of the random number value to the STACK
    14DF-14E1
    CALL 0ACFHCALL CONSIHCD CF 0A
    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 ACCumulator
    14E2-14E3
    POP BC
    POP DEC1
    Restore the RND(0) value from the STACK and put it into Register Pair BC/DE
    14E4-14E6
    CALL 0847HCALL FMULTCD 47 08
    Multiply the RND(0) value (currently in BC/DE) by the n of RND(n)(currently in ACCumulator) by GOSUB to 0847H which is the SINGLE PRECISION MULTIPLY routine (which multiplies the current value in ACCumulator by the value in (BC/DE). The product is left in ACCumulator
    14E7-14E9
    LD HL,07F8HLD HL,FONE21 F8 07
    Load Register Pair HL with the starting address of a single precision constant equal to 1.0
    14EA-14EC
    CALL 070BHCALL FADDSCD 0B 07
    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 ACCumulator (which is the random number). Return with the single precision result in ACCumulator
    14ED-14EF
    JP 0B40HJP INTC3 40 0B
    With the random number now in ACCumulator, jump to 0B40H (which will convert it to an integer and RETurn to the subroutine caller, thus exiting out of this routine)

    14F0 – This routine calculates RND(0)– “RND0”.

    14F0-14F2
    LD HL,4090HLD HL,MULTR21 90 40
    Load Register Pair HL with the starting address for a multiplier table used for figuring random numbers
    14F3
    PUSH HLE5
    Save the starting address for the table used for figuring random numbers (stored in HL) to the STACK
    14F4-14F6
    LD DE,0000H11 00 00
    Load Register Pair DE with zero (which will be the NMLSB and LSB of the starting value)
    14F7
    LD C,E4B
    Load Register C with zero (C will be the MSB of the starting value). Now C/D/E is zero.
    14F8-14F9
    LD H,03H26 03
    Load Register H with the counter value for the multiplication loop (which will be 3)
    14FA-14FB
     ↳ RNDO0
    LD L,08H2E 08
    Load Register L with a counter value of 8 bits
    14FC
     ↳ RND1
    EX DE,HLEB
    Swap DE and HL so that the counters are now in DE and the NMSB and the LSB of the random number is in Register Pair HL
    14FD
    ADD HL,HL29
    Multiply the NMSB and the LSB of the random number in Register Pair HL by two
    14FE
    EX DE,HLEB
    Exchange the newly doubled NMSB and the LSB of the random number to DE and the counters to Register Pair HL
    14FF
    LD A,C79
    Next we want to shift the HIGH ORDER byte (Register C), so first load Register A with the MSB of the random number in Register C
    1500
    RLA17
    Multiply the HIGH ORDER byte of the random number in Register A by two
    1501
    LD C,A4F
    Load Register C with the adjusted MSB of the random number in Register A
    1502
    EX (SP),HLE3
    Swap (SP) and HL so that the counters are now at the top of the STACK and the pointer to the multiplier is in Register Pair HL
    1503
    LD A,(HL)7E
    Fetch a multiplier from the the table value (held at the location of the memory pointer in Register Pair HL) into Register A
    1504
    RLCA07
    Rotate the bits of Register A
    1505
    LD (HL),A77
    Save the doubled value (stored in Register A) at the location of the memory pointer in Register Pair HL
    1506
    EX (SP),HLE3
    Swap (SP) and HL so that the counters are now in HL and the pointer to the multiplication table is at the top of the STACK
    1507-1509
    JP NC,1516HJP NC,RND2D2 16 15
    If that rotation set a NC FLAG, JUMP forward to 1516H
    150A
    PUSH HLE5
    Save the counter values in Register Pair HL to the STACK
    150B-150D
    LD HL,(40AAH)LD HL,(RNDX)2A AA 40
    Load Register Pair HL with the NMSB and the LSB of the random number seed.
    Note: 40AAH-40ADH holds the random number seed
    150E
    ADD HL,DE19
    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
    150F
    EX DE,HLEB
    Load Register Pair DE with the adjusted NMSB and LSB of the random number in Register Pair HL
    1510-1512
    LD A,(40ACH)LD A,(RNDX+2)3A AC 40
    Load Register A with the MSB of the random number seed
    1513
    ADC A,C89
    Add the MSB of the random number in Register C to the MSB of the random number seed in Register A
    1514
    LD C,A4F
    Load Register C with the adjusted MSB of the random number in Register A
    1515
    POP HLE1
    Get the counter values from the STACK and put it in Register Pair HL
    1516
     ↳ RND2
    DEC L2D
    Decrement the loop counter in Register L
    1517-1519
    JP NZ,14FCHJP NZ,RND1C2 FC 14
    Loop back to 14FCH until the above has been done eight times
    151A
    EX (SP),HLE3
    Swap (SP) and HL so that HL will now point to the table of multipliers
    151B
    INC HL23
    Bump to the next table of multipliers value
    151C
    EX (SP),HLE3
    Exchange the bumped pointer to the table value in Register Pair HL with the counter value to the STACK
    151D
    DEC H25
    Decrement the counter value of the outer loop (in Register H) to see if there are more bytes to deal with
    151E-1520
    JP NZ,14FAHJP NZ,RNDO0C2 FA 14
    Loop back to 14FAH three times until the random number has been figured
    1521
    POP HLE1
    Clear the flag table address from the STACK. The fact that it is going into HL is not important
    1522-1524
    LD HL,B065H21 65 B0
    Load Register Pair HL with the value to re-seed the random number seed
    1525
    ADD HL,DE19
    Add the seed (from Register Pair HL) to the NMSB and the LSB of the random number in Register Pair DE
    1526-1528
    LD (40AAH),HLLD (RNDX),HL22 AA 40
    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
    1529-152B
    CALL 0AEFHCALL VALSNGCD EF 0A
    Go set the current number type to single precision
    152C-152D
    LD A,05H3E 05
    Load Register A with a 5
    152E
    ADC A,C89
    Add 5 (the value held in A) and the MSB of the random number in Register C
    152F-1531
    LD (40ACH),ALD (RNDX+2),A32 AC 40
    Save the adjusted value in Register A as the MSB of the random number seed, so now the result is in A/H/L
    1532
    EX DE,HLEB
    Swap DE and HL so that the result is now in A/D/E
    1533-1534
    LD B,80H06 80
    Load Register B with a value for the sign flag and the exponent (i.e, 1000 0000)
    1535-1537
    LD HL,4125HLD HL,FAC+121 25 41
    Load Register Pair HL with the address for the sign value storage location.
    Note: 4125H-4126H is used by floating point routines
    1538
    LD (HL),B70
    Save the sign result (1000 0000) in Register B at the location of the memory pointer in Register Pair HL
    1539
    DEC HL2B
    Decrement to exponent (held in Register Pair HL)
    153A
    LD (HL),B70
    Set the exponent to (1000 0000) so that the value will be < 1
    153B
    LD C,A4F
    Now we just want to normalize C/D/E. First, load Register C with the value of the MSB for the single precision random number in Register A
    153C-153D
    LD B,00H06 00
    Zero the value of any overflow in Register B
    153E-1540
    JP 0765HJP NORMALC3 65 07
    Jump to 0765H which will normalize the value and then jump to 14D9H unless RND(0)was called in which case return to caller

    1541-1546 – LEVEL II BASIC COS
    ROUTINE– “COS”.

    Single-precision only.(ACCumulator = COS(ACCumulator)). A call to 1541H computes the cosine for an angle given in radians. The angle must be a floating point value in ACCumulator; the cosine will be returned in ACCumulator as a floating point value.

    The formula being used is COS(X) = SIN(X+PI/2)
    1541-1543
     ↳ COS
    LD HL,158BHLD HL,PI221 8B 15
    Load Register Pair HL with the starting address of a single precision constant equal to 1.57079637029 (which is pi / 2)
    1544-1546
    CALL 070BHCALL FADDSCD 0B 07
    GOSUB to 070BH to add 1.57079637029 (stored in HL) to the single precision value in ACCumulator and then pass through to the SIN() routine which is next

    1547-158A – LEVEL II BASIC SINROUTINE– “SIN”

    Single-precision only.(ACCumulator = SIN(ACCumulator)).

    A call to 1549H returns the sine as a single precision value in ACCumulator. The sine must be given in radians in ACCumulator.

    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.
    1547-1549H
    “SIN”
    CALL 09A4HCALL PUSHFCD A4 09
    First we want to divide the ACCumulator by 2*PI. First, GOSUB to 09A4 which moves the SINGLE PRECISION value in ACCumulator (the x in a SIN(x) call) to the STACK (stored in LSB/MSB/Exponent order)
    154A-154C
    LD BC,8349H01 49 83
    Load Register Pair BC with the exponent and the MSB of a single precision constant
    154D-154F
    LD DE,0FDBH11 DB 0F
    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)
    1550-1552
    CALL 09B4HCALL MOVFRCD B4 09
    Move 2 x pi value (held in DC/BE) into ACCumulator by GOSUB to 09B4H (which moves the SINGLE PRECISION value in DC/DE into ACCumulator)
    1553-1554
    POP BC
    POP DEC1
    Put the x from a SIN(x) call into BC/DE
    1555-1557
    CALL 08A2HCALL FDIVCD A2 08
    To divide the x from a SIN(x) call (held in BC/DE) by pi*2 (held in ACCumulator) we must GOSUB 80A2H to divide the single precision value in Register Pairs BC and DE by the single precision value in ACCumulator. Return with the single precision result in ACCumulator
    1558-155A
    CALL 09A4HCALL PUSHFCD A4 09
    Move that value (x / 2*pi) from ACCumulator to the STACK by GOSUB to 09A4H which moves the SINGLE PRECISION value in ACCumulator to the STACK (stored in LSB/MSB/Exponent order)
    155B-155D
    CALL 0B40HCALL INTCD 40 0B
    Go figure the integer portion for the single precision value in ACCumulator by calling 0B40H. We need to do this so we can isolate the remainder
    155E,155F
    POP BC
    POP DEC1
    Put the quotient and remainder of x/2*pi into BC/DE
    1560-1562
    CALL 0713HCALL FSUBCD 13 07
    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 ACCumulator (the integer part of the result). The difference is left in ACCumulator)
    1563-1564
    LD HL,158FHLD HL,FR421 8F 15
    Load Register Pair HL with the starting address of a single precision constant equal to 0.25
    1566-1568
    CALL 0710HCALL FSUBSCD 10 07
    Next in calculating a SIN we would need to subtract .25 (held in HL) from the fractional part (held in ACCumulator) so as to see if it is <= to 90 degrees. To do this we GOSUB 0710H to subtract the single precision value in ACCumulator from the single precision constant pointed to by Register Pair HL. Return with the result in ACCumulator
    1569-156B
    CALL 0955HCALL SIGNCD 55 09
    Go check the sign of the result of that (.25 – fractional part) subtraction which is held in ACCumulator
    156C
    SCF37
    Set the Carry flag
    156D-156F
    JP P,1577HJP P,SIN1F2 77 15
    Jump to 1577H if the single precision value in ACCumulator is positive (meaning it is < than 90 degrees)
    1570-1572
    CALL 0708HCALL FADDHCD 08 07
    If we are here, it is => 90 degrees, so we need to add .5 to the single precision value in ACCumulator. Return with the result in ACCumulator
    1573-1575
    CALL 0955HCALL SIGNCD 55 09
    Go check the sign for the single precision value in ACCumulator which basically checks to see if it is > 0.75 (meaning < 270 degrees)
    1576
    OR AB7
    Test the value of the sign test in Register A
    1577
     ↳ SIN1
    PUSH AFF5
    Save the sign indicator (+ or -1) in Register Pair AF to the STACK
    1578-157A
    CALL P,0982HCALL P,NEGF4 82 09
    If it is positive, make it negative by GOSUB to 0982H
    157B-157D
    LD HL,158FHLD HL,FR421 8F 15
    Load Register Pair HL with the starting address of a single precision constant equal to 0.25
    157E-1580
    CALL 070BHCALL FADDSCD 0B 07
    Add .25 (stored in HL) to the current value in ACCumulator by GOSUB to 070BH (result is saved in ACCumulator)
    1581
    POP AFF1
    Get the sign reversal flag from the STACK and put it in Register Pair AF
    1582-1584
    CALL NC,0982HCALL NC,NEGD4 82 09
    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
    1585-1587
    LD HL,1593HLD HL,SINCON21 93 15
    Load Register Pair HL with 1593H (which is the starting address for a series of single precision values for a set of computations)
    1588-158A
    JP 149AHJP POLYXC3 9A 14
    Go to 149AH to compute the series and then RETURN

    158B-158E – SINGLE PRECISION CONSTANT STORAGE LOCATION– “PI2”

    158B-158EH
     ↳ PI2
    DB 0F 49 81DB 0F
    A single precision constant equal to 1.57079637029 is stored here

    158F-1592 – SINGLE PRECISION CONSTANT STORAGE LOCATION– “FR4”

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

    1593-15A7 – SINGLE PRECISION CONSTANTS STORAGE LOCATION– “SINCON”

    1593
     ↳ SINCON
    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)
    1594-1597H
    BAH D7H 1EH 86H
    A single precision constant equal to 39.7106704708 is stored here
    1598-159BH
    64H 26H 99H 87H
    A single precision constant equal to -76.5749816893 is stored here
    159C-159FH
    58H 34H 23H 87H
    A single precision constant equal to 81.6022338865 is stored here
    15A0-15A3H
    E0H 6DH A5H 86H
    A single precision constant equal to -41.3416748045 is stored here
    15A4-15A7H
    DAH 0FH 49H 83H
    A single precision constant equal to 6.28318500497 is stored here

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

    Single-precision only.(ACCumulator = TAN(ACCumulator)).
    A call to 15A8H computes the tangent of an angle in radians. The angle must be specified as a single precision value in ACCumulator. The tangent will be left in ACCumulator.
    Uses the fact that TAN(x) = SIN(x) / COS(x)
    15A8-15AA
     ↳ TAN
    CALL 09A4HCALL PUSHFCD A4 09
    Save the argument via a GOSUB to 09A4 which moves the SINGLE PRECISION value in ACCumulator to the STACK (stored in LSB/MSB/Exponent order)
    15AB-15AD
    CALL 1547HCALL SINCD 47 15
    Call the SIN(n)routine at 1547H (which returns the sine as a single precision value in ACCumulator. The sine must be given in radians in ACCumulator
    15AE,15AF
    POP BC
    POP HLC1
    Get the original exponent and value from the STACK and put it in Register Pair BC/HL
    15B0-15B2
    CALL 09A4HCALL PUSHFCD A4 09
    Call 09A4 which moves the SIN(x) single precision value (stored in REG) 1 to the STACK (stored in LSB/MSB/Exponent order)
    15B3
    EX DE,HLEB
    Load Register Pair DE with the NMSB and the LSB of the single precision value in Register Pair HL
    15B4-15B6H 
    CALL 09B4HCALL MOVFRCD B4 09
    Call 09B4H (which moves the original value in BC/DE into ACCumulator)
    15B7-15B9
    CALL 1541HCALL COSCD 41 15
    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 ACCumulator as a floating point value
    15BA-15BC
    JP 08A0HJP FDIVTC3 A0 08
    Jump to 08A0H to compute SIN(n)/ COS(n)and return the value as TAN(n)

    15BD-15E2 – LEVEL II BASIC ATN(n)ROUTINE– “ATN”.

    Single-precision only.(ACCumulator = ATN(ACCumulator)).
    A call to 15BD returns the angle in radians, for the floating point tangent value in ACCumulator. The angle will be left as a single precision value in ACCumulator.

    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.
    15BD-15BF
     ↳ ATN
    CALL 0955HCALL SIGNCD 55 09
    Go check the sign of argument (i.e., the single precision value in the ACCumulator)
    15C0-15C2
    CALL M,13E2HCALL M,PSHNEGFC E2 13
    If the single precision value in ACCumulator is negative then put a return address of 13E2H to the STACK
    15C3-15C5
    CALL M,0982HCALL M,NEGFC 82 09
    Go convert the negative number in ACCumulator to positive if necessary
    15C6-15C8
    LD A,(4124H)LD A,(FAC)3A 24 41
    We next want to see if the ACCumulator is > 1, so load Register A with the exponent of the tangent (which is a single precision value in ACCumulator)
    15C9-15CA
    CP 81HFE 81
    Check to see if the the exponent of the tangent (which is a single precision value in ACCumulator) is less than one
    15CB-15CC
    JR C,15D9HJR C,ATN238 0C
    Jump to forward 15D9H if the carry flag is set (i.e., the single precision value in ACCumulator is less than one)
    15CD-15CF
    LD BC,8100H01 00 81
    Load Register Pair BC with an exponent and a MSB for a single precision value
    15D0
    LD D,C51
    Zero the NMSB of the single precision value in Register D
    15D1
    LD E,C59
    Zero the LSB of the single precision value in Register E
    15D2-15D4
    CALL 08A2HCALL FDIVCD A2 08
    GOSUB 082AH to get the reciprocal of the tangent. This routine divides the single precision value in ACCumulator into the single precision constant in Register Pairs BC and DE
    15D5-15D7
    LD HL,0710HLD HL,FSUBS21 10 07
    Load Register Pair HL with a return address of 0710H (which is the subtract routine to be called once the series is calculated)
    15D8
    PUSH HLE5
    Save the value of the return address in Register Pair HL to the STACK
    15D9-15DB
     ↳ ATN2
    LD HL,15E3HLD HL,ATNCON21 E3 15
    Load Register Pair HL with the starting address for a series of single precision numbers for a set of computations
    15DC-15DE
    CALL 149AHCALL POLYXCD 9A 14
    Go do the set of computations
    15DF-15E1
    LD HL,158BHLD HL,PI221 8B 15
    Load Register Pair HL with the starting address of a single precision constant equal to 1.57079637029 (which is pi/2)
    15E2
    RETC9
    Return. The return address was set to 0710H above, which will then subtract the last term from pi/2 and then return

    15E3-1607 – SINGLE PRECISION CONSTANTS STORAGE LOCATION– “ATNCON”

    15E3
     ↳ ATNCON
    09
    The number of single precision constants (9) which follows is stored here
    15E4-15E7
    4A D7 3B 78
    A single precision constant equal to 0.00286622549 is stored here
    15E8-15EB
    02 6E 84 7B
    A single precision constant equal to -0.01616573699 is stored here
    15EC-15EF
    FE C1 2F 7C
    A single precision constant equal to 0.04290961441 is stored here
    15F0-15F3
    74 31 9A 3D
    A single precision constant equal to 0.07528963666 is stored here
    15F4-15F7
    84 3D 5A 7D
    A single precision constant equal to 0.10656264407 is stored here
    15F8-15FB
    C8 7F 91 7E
    A single precision constant equal to -0.14208900905 is stored here
    15FC-15FF
    E4 BB 4C 7E
    A single precision constant equal to 0.19993549561 is stored here
    1600-1603
    6C AA AA 7F
    A single precision constant equal to -0.33333146561 is stored here
    1604-1607
    00 00 00 01
    A single precision constant equal to 1.0 is stored here

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

    The original ROM source code makes an interesting note about the order of these reserved words. Some reserved words are contained in other reserved words, which will cause a problem. They given examples of:
    • IF J=F OR T=5will process a FOR
    • INPis part of INPUT
    • IF T OR Q THENwill process a TO
    SO, the smaller word always has to appear later in the reserved word table.
    ABSD90977|ANDD225FD
    ASCF62A0F|ATNE415BD
    AUTOB72008|CDBLF10ADB
    CHR$(F72A1F|CINTEF0A7F
    CLEARB81E7A|CLOADB92C1F
    CLOSEA64185|CLS8401C9
    CMD854173|CONTB31DE4
    COSEl1541|CSAVEBA2BF5
    CSNGF00ABl|CVDE8415E
    CVIE64152|CVSE74158
    DATA881F05|DEFDD415B
    DEFDBL9B1E09|DEFINT991E03
    DEFSNG9A1E06|DEFSTR981E00
    DELETEB62BC6|DIM8A2608
    EDIT9D2E60|ELSE951F07
    END801DAE|EOFE94161
    ERLC224DD|ERRC324CF
    ERROR9E1FF4|EXPE01439
    FIELDA3417C|FIXF20B26
    FNBE4155|FOR811CA1
    FREDA27D4|GETA44174
    GOSUB911EB1|GOTO5D1EC2
    IF8F2039|INKEY$C9019D
    INPDB2AEF|INPUT89219A
    INSTRC5419D|INTD80B37
    KILLAA4191|LEFT$F82A61
    LENF32A03|LET8C1F21
    LINE9C41A3|LISTB42B2E
    LLISTB52B29|LOADA74188
    LOCEA4164|LOFEB4167
    LOGDF0809|LPRINTAF2067
    LSETAB4197|MEMC827C9
    MERGEA8418B|MID$FA2A9A
    MKD$EE4170|NAMEA9418E
    NEWBB1B49H|NEXT8722B6
    NOTCB25C4|ONA11FC6
    OPENA24179|ORD325F7
    OUTAO2AFB|PEEKE52CAA
    POINTC60132|POKEB12CB1
    POSDC27F5|PRINTB2206F
    PUTA54182|RANDOM8601D3
    READ8B21EF|REM931F07
    RESET820138|RESTORE901D91
    RESUME9F1FAFH|RETURN921EDEH
    RIGHT$F92A91|RNDDE14C9
    RSETAC419A|RUN8E1EA3
    SAVEAD41A0|SET830135
    SGND7098A|SINE21547
    SQRCD13E7|STEPcc2B01
    STOP941DA9|STR$F42836
    STRING$C42A2F|SYSTEMAE02B2
    TAB(BC2137|TANE315A8
    THENCA|TIME$C74176
    TOBD|TROFF971DF8
    TRON961DF8|USINGBF2CBD
    USRC127FE|VALFF2AC5
    VARPTRC024EB|+CD249F
    CE2532|CF
    /D0|?D1
    >D4|=D5
    <D6|&26
    FB3A93

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

    18C9
    “NF”
    NEXT without FOR Error Message (Error 00H)
    18CB
    “SN”
    Syntax Error Error Message (Error 02H)
    18CD
    “RG”
    RETURN without GOSUB Error Message (Error 04H)
    18CF
    “OD”
    Out of DATA) Error Message (Error 06H)
    18D1
    “FC”
    Illegal Function Call Error Message (Error 08H)
    18D3
    “OV”
    Overflow Error Message (Error 0AH)
    18D5
    “OM”
    Out of Memory Error Message (Error 0CH)
    18D7
    “UL”
    Underfined Line Number Error Message (Error 0EH)
    18D9
    “BS”
    Subscript out of Range Error Message (Error 10H)
    18DB
    “DD”
    Redimensioned Array Error Message (Error 12H)
    18DD
    “/0”
    Division by Zero Error Message (Error 14H)
    18DF
    “ID”>
    Illegal Direct Operation Error Message (Error 16H)
    18E1
    “TM”
    Type Mismatch Error Message (Error 18H)
    18E3
    “OS”
    Out of String Message (Error 1AH)
    18E5
    “LS”
    Out of Memory Error Message (Error 1CH)
    18E7
    “ST”
    String Too Long Error Message (Error 1EH)
    18E9
    “CN”
    Can’t Continue Error Message (Error 20H)
    18EB
    “NR”
    No RESUME Error Message (Error 22H)
    18ED
    “RW”
    RESUME Without Error Error Message (Error 24H)
    18EF
    “UE”
    Unprintable Error Error Message (Error 26H)
    18F1
    “HO”
    Missing Operand Error Message (Error 28H)
    18F3
    “FD”
    Bad file Data Error Message (Error 2AH)
    18F5
    “L3”
    Disk BASIC Command Error Message (Error 2CH)

    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.

    18F7
    SUB 00HD6 00
    Subtract the LSB
    18F9
    LD L,A6F
    Restore the value to L
    18FA
    LD A,H7C
    Get the middle byte
    18FB
    SBC A,00HDE 00
    Subtract the middle byte
    18FD
    LD H,A67
    Move the difference to H
    18FE
    LD A,B78
    Get the MSB
    18FF
    SBC A,00HDE 00
    Subtract the MSB
    1901
    LD B,A47
    Move it back to A
    1902
    LD A,00H3E 00
    Clear A
    1904
    RETC9
    RETurn to CALLer

    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– “ERR”

    191D-1923
     ↳ ERR
    “Error” + 00H20 45
    The word “ERROR”
    1924-1928
     ↳ INTX
    ” in ” + 00H
    The word ” IN “

    1929-192F – MESSAGE STORAGE LOCATION– “REDDY”

    1929-192F
     ↳ REDDY
    “READY” + 0DH + 00H
    The Level II BASIC READY message is stored here

    1930-1935 – MESSAGE STORAGE LOCATION– “BRKTXT”

    1930-1935
     ↳ BNKTXT
    “Break” + 00H
    The Level II BASIC BREAK message is stored here

    1936-1954 – SCAN STACK ROUTINE– “FNDFOR”

    This routine is called with DE as the address of the NEXT index. It scans the STACK backwards looking for a FORpush. 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.

    According to the original ROM source, this routine is part of the general storage management routines, and if designed to find a FORentry on the STACK with the variable pointer passed in Register Pair DE.
    1936-1938
     ↳ FNDFOR
    LD HL,0004H21 04 00
    Load Register Pair HL with 4 so that we can backspace
    1939
    ADD HL,SP39
    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
    193A
     ↳ LOOPER
    LD A,(HL)7E
    Load Register A with the value held at the current STACK point MINUS 4. This is to enable seeing what type of data is on the STACK
    193B
    INC HL23
    Bump the value of the memory pointer in Register Pair HL so as to backspace one more byte in case a FORtoken is located
    193C-193D
    CP 81HFE 81
    Check to see if the value in Register A (which is the current STACK pointer – 4) is a FORtoken to make sure that the item in the STACK was associated with a FOR loop
    193E
    RET NZC0
    If the item isn’t associated with a FOR statement (as the value in Register A isn’t a FORtoken), exit out of this routine. This returns with A being non-zero because there was no FORpush
    193F
    LD C,(HL)4E
    If we are here, then the entry on the STACK is associated with a FOR statement. Load Register C with the LSB of the FOR‘s variable address
    1940
    INC HL23
    Bump the value of the memory pointer in Register Pair HL so as to backspace the current STACK pointer by yet another byte
    1941
    LD B,(HL)46
    Load Register B with the MSB of the FOR‘s variable address
    1942
    INC HL23
    Bump the value of the memory pointer in Register Pair HL so now HL will be the address of the FORvariable on the STACK
    1943
    PUSH HLE5
    Save the value in Register Pair HL (which is the address of the FORvariable) to the STACK
    1944
    LD L,C69
    Load Register L with the LSB of the FORvariable’s address in Register C
    1945
    LD H,B60
    Load Register H with the MSB of the FORvariable’s address in Register B
    1946-1947
    LD A,D
    OR E7A
    Z-80 Trick to check a Register Pair (in this case DE) for zero. Load D into A and then OR that against E. If both D and E are zero, then A will be zero. This sets up to handle a NEXT statement that doesn’t have a variable argument
    1948
    EX DE,HLEB
    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 FORvariable from the STACK. This is to ensure that we return with DE pointing to the variable
    1949-194A
    JR Z,194DHJR Z,POPGOF28 02
    Skip the next 2 opcodes if the variable address in Register Pair DE was equal to zero, meaning that DE was not, in fact, pointing to the variable as we needed it to be
    194B
    EX DE,HLEB
    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 FORvariable from the STACK
    194C
    RST 18HCOMPARDF
    This routine was entered with DE being the address of the NEXTindex, 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)
    194D-194F
     ↳ POPGOF
    LD BC,000EH
    LD BC,FORSIZ01 0E 00
    Load Register Pair BC with the value to backspace (i.e., erase) the FORtoken (which is 10)
    1950
    POP HLE1
    Get the memory pointer from the STACK of the sign of the increment flag and put it in Register Pair HL
    1951
    RET ZC8
    If the variable in the FORblock matched the NEXTindex block, then RETURN with HL pointing to the bottom of the entry
    1952
    ADD HL,BC09
    If it didn’t match, execute that 10 byte stepback in BC for the next possible FORpush
    1953-1954
    JR 193AHJR LOOPER18 E5
    At this point, we should be pointing to the start of the NEXTentry, so JUMP to keep looking until the appropriate FORblock has been located

    1955-1962 – DATA MOVEMENT ROUTINE– “BLTU”

    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.

    According to the original ROM source, this routine is part of the general storage management routines, and if designed to make space by shoving everything forward and to check to make sure a reasonable amount of space remains between the top of the STACK and the highest location transferred to. On Entry, HL should be the destination of the high address, DE should be the low address to be transferred there, and BC should be the high address to be transferred there. On exit, HL=DE=Low BC=The location LOW was moved to.
    1955-1957
     ↳ BLTU
    CALL 196CH
    CALL REASONCD 6C 19
    GOSUB to 196CH to make sure there’s enough room in memory for the string area and make sure the STACK won’t be overrun
    1958
     ↳ BLTUC
    PUSH BCC5
    The next 3 instructions are really just to exchange HL and BC. First, save the end address of the list to move (stored in BC) to the STACK
    1959
    EX (SP),HLE3
    Save the end address of the list to move (stored in the STACK now) to Register Pair HL
    195A
    POP BCC1
    Get the end address of the move from the STACK and put it in Register Pair BC
    195B
     ↳ BLTLOP
    RST 18HCOMPARDF
    Check is we are done by checking 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)
    195C
    LD A,(HL)7E
    Get a byte from the source list to transfer and put it in Register A
    195D
    LD (BC),A02
    Transfer it by saving the byte into wherever BC is pointing
    195E
    RET ZC8
    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)
    195F
    DEC BC0B
    Decrement the source address (in Register Pair BC)
    1960
    DEC HL2B
    Decrement the destination address (in Register Pair HL)
    1961-1962
    JR 195BHJR BLTLOP18 F8
    Loop until the entire block was moved

    1963-197D – MEMORY CHECK ROUTINE– “GETSTK”

    This routine computes the amount of space between HL and the end of memory at FFC6. On entry, Register C should hold the number of desired bytes.

    According to the original ROM source, this routine is part of the general storage management routines, and if designed to make sure that a certain number of locations remain available for the STACK. To use this routine, Register C needs to hold the number of two byte entries needed, and then do a CALL GETSTK. This routine must be called by any reoutine which puts an arbitrary amount of stuff into the STACK (such as a recursive routine like FRMEVL). It is also called by routines such as GOSUBand FORwhich make permanent entries in the STACK.
    1963
     ↳ GETSTK
    PUSH HLE5
    Save the value in Register Pair HL to the STACK
    1964-1966
    LD HL,(40FDH)LD HL,(STREND)2A FD 40
    Load Register Pair HL with the starting address of free memory (which is stored at 40FDH).
    Note: 40FDH-40FEH holds Free memory pointer
    1967-1968
    LD B,00H06 00
    Load Register B with zero
    1969
    ADD HL,BC09
    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
    196A
    ADD HL,BC09
    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
    196B-196C
    LD A,0E5H3E E5
    Z-80 Trick! See the general explanation at 10F8H
    196C
     ↳ REASON
    PUSH HLE5
    Now we check t omake sure there is at least “NUMLEV” bytes between the address and the top of the STACK. First, save the new free area pointer (which is the start) to the STACK
    196D-196E
    LD A,C6H
    LD A,256-(2*NUMLEV)3E C6
    Load Register A with C6H (which is the the LSB of FFC6H; the top of memory)
    196F
    SUB L95
    Subtract the LSB of the value of the new memory pointer in Register L from the value in Register A
    1970
    LD L,A6F
    Load Register L with the adjusted value in Register A (i.e., the free memory pointer resulting from subtracting the new starting address)
    1971-1972
    LD A,FFH3E FF
    Load Register A with the MSB of the top of memory
    1973
    SBC A,H9C
    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
    1974-1975
    JR C,197AHJR C,OMERR38 04
    If the CARRY flag is set then HL was simply too big. So we need to display a ?OM ERRORsince we are out of memory
    1976
    LD H,A67
    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
    1977
    ADD HL,SP39
    Add the value of the STACK pointer to the adjusted value in Register Pair HL. If we are OK, the CARRY FLAG will be set
    1978
    POP HLE1
    Restore the original HL on entry back into Register Pair HL
    1979
    RET CD8
    If the carry flag is set, then we have no overflow – so RETURN to CALLer

    197A-197B – ?OM ERROR ENTRY POINT– “OMERR”

    197A-197B
     ↳ OMERR
    LD E,0CHLD E,ERROM1E 0C
    Load Register E with the ?OM ERROR
    197C-197D
    JR 19A2HJR ERROR18 24
    Display an ?OM ERRORmessage

    197E-1AF7 – LEVEL II BASIC COMMAND MODE ERROR HANDLING– “PRGEND”

    197E-1980
     ↳ PRGEND
    LD HL,(40A2H)LD HL,(CURLIN)2A A2 40
    Load Register Pair HL with the value of the current BASIC line number.
    Note: 40A2H-40A3H holds the current BASIC line number
    1981
    LD A,H7C
    Test to see if this was a direct command instead a line number by first loading Register A with the MSB of the current BASIC line number in Register H
    1982
    AND LA5
    Combine the LSB of the current BASIC line number in Register L with the MSB of the current line number in Register A
    1983
    INC A3C
    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)
    1984-1985
    JR Z,198EHJR Z,ENDCNJ28 08
    Jump to 198EH if Level II BASIC is still in the command mode (rather than being in execution mode)
    1986-1988
    LD A,(40F2H)LD A,(ONEFLG)3A F2 40
    Load Register A with the error override flag (i.e., if there is an ON ERROR GOTO active)
    1989
    OR AB7
    Check to see if the error flag is set
    198A-198B
    LD E,22HLD E,ERRNR1E 22
    Load Register E with a ?NR ERRORcode
    198C-198D
    JR NZ,19A2HJR NZ,ERROR20 14
    Jump to 19A2H if the error flag is set (meaning there was no RESUMEaddress)
    198E-1990
     ↳ ENDCNJ
    JP 1DC1HJP ENDCONC3 C1 1D
    Otherwise, jump to 1DC1H (to END) because there was an error in the input phase
    1991-1993
     ↳ DATSNE
    LD HL,(40DAH)LD HL,(DATLIN)2A DA 40
    Load Register Pair HL with the DATAline number (which is stored at 16602).
    Note: 40DAH-40DBH holds DATA line number
    1994-1996
    LD (40A2H),HLLD (CURLIN),HL22 A2 40
    Make the DATA line number into the CURRENT line number by saving it in Register Pair HL.
    Note: 40A2H-40A3H holds the current BASIC line number
    1997-1998
     ↳ SNERR
    LD E,02HLD E,ERRSN1E 02
    Load Register E with a ?SN ERRORcode.
    SN ERROR entry point
    The next few instructions are all Z-80 tricks to allow Register E to hold its value while passing through them all.
    1999-199B
     ↳ DV0ERR
    LD BC,141EH01 1E 14
    Z-80 Trick. JUMPing here will load BC but skip the reload of Register E as follows
    199A-199B
    LD E,14HLD E,ERRDV001 1E 14
    Load Register E with a ?/0 ERRORcode
    199C-199E
     ↳ NFERR
    LD BC,001EH01 1E 00
    Z-80 Trick. JUMPing here will load BC but skip the reload of Register E as follows
    199D-199E
    LD E,00HLD E,ERRNF1E 00
    Load Register E with a ?NF ERRORcode.
    ?NF ERRORentry point
    199F-19A1
     ↳ REERR
    LD BC,241EHLD E,ERRRE01 1E 24
    Z-80 Trick. JUMPing here will load BC but skip the reload of Register E as follows
    19A0-19A1
    LD E,24HLD E,ERRRE1E 24
    Load Register E with a ?RW ERRORcode.
    ?RW ERRORentry point
    19A2-19A4
     ↳ ERROR
    LD HL,(40A2H)LD HL,(CURLIN)2A A2 40
    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
    19A5-19A7
    LD (40EAH),HLLD (ERRLIN),HL22 EA 40
    Save the value of the current BASIC line number with the error into the RAM Location which tracks the ERL variable.
    Note: 40EAH-40EBH holds Line number with error
    19A8-19AA
    LD (40ECH),HLLD (DOT),HL22 EC 40
    Save the value of the current BASIC line number with the error into the RAM location used for EDIT or LIST
    19AB-19AD
     ↳ ERRESM
    LD BC,19B4HLD BC,ERRMOR01 B4 19
    Load Register Pair BC with the return address of 19B4H which is the continuation address after a reinitialization

    19AEH – Routine used when a catastropic BREAK key occurs

    19AE-19B0
     ↳ ERESET
    LD HL,(40E8H)LD HL,(SAVSTK)2A E8 40
    Load Register Pair HL with the value of the STACK pointer (which is stored at 40E8H).
    Note: 40E8H-40E9H holds STACK pointer pointer
    19B1-19B3
    JP 1B9AHJP STKERRC3 9A 1B
    Jump to 1B9AH to reinitialize the system variables, including reinitializing the STACK to the location now held in SAVSTK

    19B4 – LEVEL II BASIC COMMAND MODE ERROR HANDLING– “ERRMOR”

    19B4
     ↳ ERRMOR
    POP BCC1
    Discard the entry at the top of the STACK (which is the FNDFOR Stopper)
    19B5
    LD A,E7B
    Load Register A with the value of the error code in Register E
    19B6
    LD C,E4B
    Load Register C with the value of the error code in Register E, as we will need to restore it later as well
    19B7-19B9
    LD (409AH),ALD (ERRFLG),A32 9A 40
    Save the value of the error code (from in Register A) into 409AH.
    Note: 409AH holds the RESUME flag
    19BA-19BC
    LD HL,(40E6H)LD (SAVTXT),A2A E6 40
    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
    19BD-19BF
    LD (40EEH),HLLD (ERRTXT),HL22 EE 40
    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
    19C0
    EX DE,HLEB
    Load Register Pair DE with the value of the current BASIC program pointer in Register Pair HL so that the SAVTXT is preserved in Register Pair DE
    19C1-19C3
    LD HL,(40EAH)LD HL,(ERRLIN)2A EA 40
    Load Register Pair HL with the line number where the error occurred.
    Note: 40EAH-40EBH holds Line number with error
    19C4,19C4
    LD A,H
    AND L7C
    Z-80 Trick to test if HL is zero or not – If H AND L are 0, then they are each zero
    19C6
    INC A3C
    Bump the value of the combined current BASIC line number. If the line with the error was a direct command, this would have been FFFF, so the INC A will then set the ZERO flag if it was direct
    19C7-19C8
    JR Z,19D0HJR Z,NTMDCN28 07
    If this was a direct command (and ZERO FLAG is set), then we do not want to modify OLDTXT or OLDLIN, so jump to 19D0H
    19C9-19CB
    LD (40F5H),HLLD (OLDLIN),HL22 F5 40
    Let OLDLIN = ERRLIN by saving the value of the current BASIC line number in Register Pair HL to (40F5H).
    Note: 40F5H-40F6H holds the last line number executed
    19CC
    EX DE,HLEB
    Get bacK SAVTXT by swapping HL and DE
    19CD-19CF
    LD (40F7H),HLLD (OLDTXT),HL22 F7 40
    Let OLDTXT = SAVTXT by saving the value of the current BASIC program pointer in Register Pair HL.
    Note: 40F7H-40F8H holds Last byte executed
    19D0-19D2
     ↳ NTMDCN
    LD HL,(40F0H)LD HL,(ONELIN)2A F0 40
    See if we are trapping errors by first loading Register Pair HL with the current ON ERRORaddress.
    Note: 40F0H-40F1H is used by ON ERROR
    19D3,19D4
    LD A,H
    OR L7C
    Z-80 Trick to test if HL is zero or not – If H OR L are 0, then they are each zero
    19D5
    EX DE,HLEB
    Load Register Pair DE with the ON ERRORaddress to go to if there’s an error which is currently in Register Pair HL
    19D6-19D8
    LD HL,40F2HLD HL,ONEFLG21 F2 40
    Load Register Pair HL with the address of the error flag (which is 40F2H).
    Note: 40F2H holds Error flag
    19D9-19DA
    JR Z,19E3HJR Z,NOTRAP28 08
    Jump to 19E3H (to error out) if we aren’t otherwise trapping errors (because there isn’t an ON ERRORaddress)
    19DB
    AND (HL)A6
    Since Register A is currently non-zero (or we would have jumped away in the prior instruction), combining that number with with the ONEFLG will result in either a 0 or non-zero based on whether whether the flag was already set
    19DC-19DD
    JR NZ,19E3HJR NZ,NOTRAP20 05
    If the NZ FLAG is set, then it was already set, so JUMP to 19E3H (to error out)
    19DE
    DEC (HL)35
    Force an error
    19DF
    EX DE,HLEB
    Load Register Pair HL with the ON ERRORline address pointer held in Register Pair DE
    19E0-19E2
    JP 1D36HJP GONE4C3 36 1D
    Jump to 1D36H to make that happen

    19E3 – LEVEL II BASIC COMMAND MODE ERROR HANDLING– “NOTRAP”

    19E3
     ↳ NOTRAP
    XOR AAF
    Zero Register A
    19E4
    LD (HL),A77
    Reset ONMEFLG. 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
    19E5
    LD E,C59
    Restore the error code (which was tucked away in Register C at 19B6H) into Register E
    19E6-19E8
    CALL 20F9HCALL CRDONZCD F9 20
    We need to position the video to the next line, so go display a carriage return on the video display if necessary
    19E9-19EB
    LD HL,18C9HLD HL,ERRTAB21 C9 18
    Load Register Pair HL with the starting address for the table of error messages
    19E6-19E8
    CALL 41A6HCALL EXDSKRCD F9 20
    Check to see if DOS should be handling this
    19EF
    LD D,A57
    Since we are non-DOS, we continue by loading Register D with zero
    19F0-19F1
    LD A,3FHLD A,”?”3E 3F
    Load Register A with a ?
    19F2-19F4
    CALL 032AHCALL OUTDOCD 2A 03
    GOSUB to 032AH to display the question mark in Register A
    19F5
    ADD HL,DE19
    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
    19F6
    LD A,(HL)7E
    Load Register A with the first character of the error message at the location of the table pointer in Register Pair HL
    19F7-19F9
    CALL 032AHCALL OUTDOCD 2A 03
    GOSUB to 032AH to display the first character of the error message in Register A
    19FA
    RST 10HCHRGETD7
    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.

    The RST 10H routine parses the characters starting at HL+1 for the first non-SPACE,non-09H,non-0BH character it finds. On exit, Register A will hold that character, and the C FLAG is set if its alphabetic, and NC FLAG if its alphanumeric. All strings must have a 00H at the end.
    19FB-19FD
    CALL 032AHCALL OUTDOCD 2A 03
    GOSUB to 032AH to display the second character of the error message in Register A
    19FE-1A00
    LD HL,191DHLD HL,ERR21 1D 19
    Load Register Pair HL with 191DH which is the starting address of the word “ERROR” message
    1A01
    PUSH HLE5
    Save the starting address of the word “ERROR” (held in HL) to the STACK
    1A02-1A04
    LD HL,(40EAH)LD HL,(ERRLIN)2A EA 40
    Load Register Pair HL with the value of the BASIC line number causing the error.
    Note: 40EAH-40EBH holds Line number with error
    1A05
    EX (SP),HLE3
    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
    1A06
     ↳ ERRFIN
    CALL 28A7HCALL STROUTCD A7 28
    GOSUB to 28A7 to display the entire word ERROR on screen
    1A09
    POP HLE1
    Get the value of the BASIC line number with the error from the STACK and put it in Register Pair HL
    1A0A-1A0C
    LD DE,FFFEHLD DE,0 + 6553411 FE FF
    Load Register Pair DE with FFFEH.

    This basically reserves the line number 65534 as a trigger for the next few steps
    1A0D
    RST 18HCOMPARDF
    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)
    1A0E-1A10
    JP Z,0674HJP Z,INITCA 74 06
    Jump to 0674H if we are in the initialization routine because the error line number was FFFEH
    1A11
    LD A,H7C
    Next, let’s see if we were in direct mode (i.e., entered from the command line). Load Register A with the MSB of the current BASIC line number in Register H
    1A12
    AND LA5
    Combine the LSB of the current BASIC line number in Register L with the MSB of the current BASIC line number in Register A
    1A13
    INC A3C
    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)
    1A14-1A16
    CALL NZ,0FA7HCALL NZ,INPRTC4 A7 0F
    GOSUB to 0FA7H to display the current BASIC line number in Register Pair HL if Level II BASIC isn’t in the command mode
    The original ROM has this note: The following code is for “LIST” command stopping and for returning from a failed “CVER” and to correct a direct GOSUB which does input.
    1A17
    LD A,0C1H3E C1
    Z-80 Trick! If passing through from the above routine, then A will loaded and the instruction at 1A18 will be skipped.
    1A18
     ↳ STPRDY
    POP BCC1
    Get the value from the STACK and put it in Register Pair BC
    1A19-1A1BH
    “READY”
    CALL 038BHCALL FINLPTCD 8B 03
    Go set the current output device to the video display.
    Re-entry into BASIC command mode entry point. (see 6CCH also)
    1A1C-1A1EH
    CALL 41ACHCALL PRGFINCD AC 41
    1A1F-1A21
    CALL 01F8HCALL CTOFFCD F8 01
    Go turn off the cassette recorder
    1A22-1A24
    CALL 20F9HCALL CRDONZCD F9 20
    Go display a carriage return if necessary
    1A25-1A27
    LD HL,1929HLD HL,REDDY21 29 19
    Load Register Pair HL with the starting address of word “READY”
    1A28-1A2A
     ↳ REPINI
    CALL 28A7HCALL STROUTCD A7 28
    Display the word “READY”
    1A2B-1A2D
    LD A,(409AH)LD A,(ERRFLG)3A 9A 40
    Load Register A with the value of the current error code
    1A2E-1A2F
    SUB 02HD6 02
    Check to see if the current error code is a ?SN ERRORcode by subtracting 2 from the error code, resulting in a zero if its a SN ERROR and any other number if it isn’t
    1A30-1A32
    CALL Z,2E53HCALL Z,ERREDTCC 53 2E
    If the current error code is a SN ERROR code, then automatically enter EDIT mode on that line via this CALL

    1A33 – MAIN LEVEL II BASIC INTERPRETER ENTRY– “MAIN”

    If the jump here was from an AUTOcall, (40E4H) will have the increment number, (40E1H) will be 0 if no AUTOand non-zero if AUTO, and (40E2H) will have the starting line number.
    While not for this specific routine, this is the best place to mention it. Vernon Hester has pointed out that while BASIC is supposed to ignore spaces in commands, it fails to properly handle some commands because of spaces
    If you have a statement with a type declaration tag after a number and a space before an add or subtract arithmetic operator, the ROM applies the operator as a unary operator for the following argument
      Example: PRINT 2% + N will display two numbers. PRINT 2%+N will display one number.
    Also, if you have a statement with a type declaration tag after a number and a space before a multiply or divide arithmetic operator, the ROM willl throw a ?SN ERROR
      Example: PRINT 2%*N will display a number. PRINT 2% * N will display a ?SN ERROR.
    1A33-1A35
     ↳ MAIN
    LD HL,FFFFH21 FF FF
    Load Register Pair HL with the command mode line number
    1A36-1A38
    LD (40A2H),HLLD (CURLIN),HL22 A2 40
    Set CURLIN up for direct command mode by saving FFFFH as the current BASIC line number.
    Note: 40A2H-40A3H holds the current BASIC line number
    1A39-1A3B
    LD A,(40E1H)LD A,(AUTFLG)3A E1 40
    Load Register A with the value of the AUTOflag. It will be zero if not in AUTO, and anything else if in AUTO
    1A3C
    OR AB7
    Check to see if in the AUTOmode
    1A3D-1A3E
    JR Z,1A76HJR Z,NTAUTO28 37
    Jump to 1A76H if not in the AUTOmode
    1A3F-1A41
    LD HL,(40E2H)LD HL,(AUTLIN)2A E2 40
    We are in AUTOmode so load Register Pair HL with the current AUTOline number.
    Note: 40E2H-40E3H holds Current BASIC line number
    1A42
    PUSH HLE5
    Save the current AUTOline number (stored in Register Pair HL) to the STACK
    1A43-1A45
    CALL 0FAFHCALL LINPRTCD AF 0F
    Display the current AUTO line number on the screen via a 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
    1A46
    POP DED1
    Get the current AUTOline number from the STACK and put it in Register Pair DE
    1A47
    PUSH DED5
    Save the current AUTOline number in Register Pair DE to the STACK
    1A48-1A4A
    CALL 1B2CHCALL FNDLINCD 2C 1B
    See if the line number already exists 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
    1A4B-1A4C
    LD A,2AH3E 2A
    Load Register A with a