General:
SYS13/SYS handles the CMD “J”, CMD “O”, and CMD “X” functions.
CMD”J” converts a calendar date to julian.
The format is CMD”J”,s,d. S is the source date and D is the variable to contain the converted date.
CMD”O” sorts an array.
The format is CMD”O”,exp,array(start). exp is the number of elements.
CMD”X” is a cross reference utility.
The format is CMD”X”,target.
Disassembly:
4E00
[1E4AH]
4E13H – “SORT” Routine Main Routine. On Entry BASIC1 = Number of variables to sort and BASIC2 = VARPTR for the variables to sort.
4E1F
LD (NUMB1),HL
4E33
OR E
The next few instructions set HL = DE * 3
The next few instructions set HL = DE * 3
- If Register A equals the value held in Register B, the Z FLAG is set.
- If A < B/ 160/, the CARRY FLAG will be set.
- if A >= B/ 160/, the NO CARRY FLAG will be set.
[4E8FH]
[4EA1H]
4EBCH – “SORT” Routine Main Routine.
4ED5H – “SORT” Routine Byte Storage Area.
4ED5
4ED7
4ED9
4EDA
4EDC
4EDE
4EE0
4EE3H – Julian Date Conversion Routine Entry Point.
4EE3
4EE7
2C
It is a COMPARE SYMBOL routine which comparess the symbol in the input string pointed to by HL register to the value in the location following the RST 08 call.
If there is a match, control is returned to address of the RST 08 instruction 2 with the next symbol in the A register and HL incremented by one. If the two characters do not match, a syntax error message is given.
[2337H]
[29D7H]
[1E4AH]
[50BCH]
[4F34H]
[4F45H]
[4F3EH]
4F4D
POP HL
[50E6H]
4F5D
POP HL
2C
It is a COMPARE SYMBOL routine which comparess the symbol in the input string pointed to by HL register to the value in the location following the RST 08 call.
If there is a match, control is returned to address of the RST 08 instruction 2 with the next symbol in the A register and HL incremented by one. If the two characters do not match, a syntax error message is given.
[260DH]
[0AF4H]
[4F74H]
4F74H – Julian Date Conversion Routine. Jumped to if we need to allocate string space because the current length was 0.
[2857H]
4F92H – Julian Date Conversion Routine. Jumped point to convert JULIAN to GREGORIAN.
Start moving the characters around.
4FAD
POP BC
HL = HL * 10 … to make it the first 2 digits into 100s and 10s digits.
HL = HL + the 1s Digit.
4FB5
OR E
[1997H]
[4FC4H]
[1997H]
[4FD9H]
If we pass through, then it is December 31, so just hard code that date.
4FD9H – Continuation of the routine to convert JULIAN to GREGORIAN. Jumped here if we are not at the last day of the calendar year.
Top of Loop
[4FF5H]
4FED
OR E
[4FE0H]
End of Loop
4FF5H – Continuation of the routine to convert JULIAN to GREGORIAN. Jumped here if have calculated the MONTH.
4FF9
OR L
[5002H]
5008
POP HL
[5043H]
[5043H]
502C
LD D,00H
If we are here then we need to add in the leap day.
POP HL
2C
It is a COMPARE SYMBOL routine which comparess the symbol in the input string pointed to by HL register to the value in the location following the RST 08 call.
If there is a match, control is returned to address of the RST 08 instruction 2 with the next symbol in the A register and HL incremented by one. If the two characters do not match, a syntax error message is given.
504C
LD H,00H
505C
LD H,00H
506A
LD H,00H
[260DH]
[0AF4H]
5089H – Create a variable of 8 bytes to house the ASCII DATE.
[2857H]
5094H – Store the 8 byte ASCII DATE into a variable.
5094
50A6H – Move the value held in the temp area (4134H) to the memory location pointed to by Register Pair DE.
50BAH – Fetch 2 user supplied numbers (such as the day or year), which must follow a “/”, into Register A.
2F
It is a COMPARE SYMBOL routine which comparess the symbol in the input string pointed to by HL register to the value in the location following the RST 08 call.
If there is a match, control is returned to address of the RST 08 instruction 2 with the next symbol in the A register and HL incremented by one. If the two characters do not match, a syntax error message is given.
50C7
LD L,C
50C9
POP DE
50D3H – Fetch 1 user supplied number, into Register A. If not a number, exit with a SYNTAX ERROR
LD A,(HL)Fetch the value held in the memory location pointed to by Register Pair HL and store it into Register A.
50D4INC HLINCrement the TEXT POINTER (held in Register Pair HL) by 1.
50D5CP 20HCompare the value held in Register A against 20H (ASCII: SPACE). If the character is NOT a SPACE …
50D9LD A,30HLet Register A equal 0.
SUB 30HSUBtract the value 30H from Register A to test for a bad character. If it was < “0” then the value was bad …
50E0CP 0AHCompare the value held in Register A against 0AH (Decimal: 10). If the character is >= 10 then the value was bad …
50E5RETRETurn to the caller.
50E6H – Convert the hex JULIAN DATE to ASCII and edit the spaces.
OR 37HOR Register A against 37H (0011 0111). This has the effect of turning on bits 5, 4, 2, 1, 0, leaving only 8 possible remaining numbers. 37H If the 0’d bits were 000, 3FH (001), 77H (010), 7FH (011), 87H (100), 8FH (101), C7H (110), and CFH (111).
50E8PUSH AFSave the contents of Register Pair AF, which would be a flag to supress editing, to the top of the stack.
50E9CALL 0A9AH
[0A9AH]GOSUB to 0A9AH in the Model III ROM routine to put the value in HL into the single precision number storage area of 4121H and is flagged as an INTEGER.
50ECXOR ASet Register A to ZERO for no ascii editing.
50EDCALL 1034H
[1034H]GOSUB to 1034H to turn off the EDIT flag and initialize the 4130H input buffer for a FLOATING POINT to ASCII conversion by putting a SPACE into 4130H.
50F0OR (HL)Set the flags by merging the value held in Register A against the byte of the program pointed to by Register Pair HL. This also clears the CARRY FLAG.
50F1CALL 0FD9H
[0FD9H]GOSUB to 0FD9H in the Model III ROM to convert the integer value in 4124H to an ASCII string pointed to by Register Pair HL.
50F4POP AFPut the value held at the top of the STACK into Register Pair AF, and then remove the entry from the stack.
50F5RET CIf the C FLAG (Carry) has been set, then no editing is wanted, so RETurn to the caller.
50F6LD HL,4131HOTHERWISE … let Register Pair HL equal 4131H to opint to the ASCII character.
Top of Loop.
50FACP 20HCompare the value held in Register A against 20H (ASCII: SPACE). If the characeter is NOT a SPACE …
50FCRET NZ… we are done, so RETurn to the caller.
50FDLD (HL),30HStore a 0 over the SPACE.
50FFINC HLINCrement the value stored in Register Pair HL by 1 to point to the next character.
End of Loop.
5102H – “CROSS REFERENCE” Routine.
5104AND 0E0HMASK the value of Register A against E0H (1110 0000) to leave only bits 7, 6, 5 active. Bit 5: Device Select, Bit 6: Not Out of Paper, and Bit 7: Not Busy.
5106JR NZ,CROSS1
[510BH]If any of bits 7, 6, and 5 are ON, skip the next instruction by JUMPing to 510BH.
5108LD (PRTAVL),AIf bits 7, 6, and 5 were all OFF then printer is not available, so store the value held in Register A into memory location 51B4H to indicate that.
LD HL,(BASIC1)Fetch the TEXT POINTER (held in memory location 4272H) and store it into Register Pair HL.
510ERST 08H
2CRST 08H is used to look for expected characters (in this case, a ,) in a string and then return with (HL) pointing to the next non-blank character.
It is a COMPARE SYMBOL routine which comparess the symbol in the input string pointed to by HL register to the value in the location following the RST 08 call.
If there is a match, control is returned to address of the RST 08 instruction 2 with the next symbol in the A register and HL incremented by one. If the two characters do not match, a syntax error message is given.
5110LD A,(HL)Fetch the first byte (held in the memory location pointed to by Register Pair HL) and store it into Register A.
5111AND 80HMASK the value of Register A against 80H (1000 0000), leaving only Bit 7 active to test for a reserved word.
5113LD BC,0001HInitialize Register Pair BC to 0001H in case we have only 1 character.
5118INC HLIf we’re here, then Register A is holding a reserved word, so bump past it by INCrementing the value stored in Register Pair HL by 1.
5119LD (BASIC1),HLStore the current location (1 past a reserved word) into the TEXT POINTER.
511CDEC HLBack up to before the reserved word held in Register A by DECrementing the value stored in Register Pair HL by 1.
511FH – “CROSS REFERENCE” Routine. Jumped here if the character we just fetched into Register A was not a reserved word.
CALL 2337H
[2337H]GOSUB to 2337H to evaluate the BASIC expression pointed to by HL and return with the result in REG 1.
5122LD (BASIC1),HLStore the TEXT POINTER (held in Register Pair HL) into memory location 4272H.
5128LD A,(HL)Fetch the length of the string (held in the memory location pointed to by Register Pair HL) and store it into Register A.
5129OR ASince a LD command does not set any FLAGS, Set FLAGS based on the contents of Register A.
512AJP Z,1E4AH
[1E4AH]If Register A is 0, then we have a null string, which is bad, so exit with a “?FC ERROR” via a JUMP to 1E4AH.
512DLD C,AIf the string is NOT empty, continue. First copy the string length (held in Register A) into Register C.
512D
512ELD C,A
LD B,00HLet Register Pair BC = A (i.e., the length of the string)
5130INC HLINCrement the value stored in Register Pair HL by 1 to now point to the address of the string.
5131LD E,(HL)Fetch the LSB of the address of the string (held in the memory location pointed to by Register Pair HL) and store it into Register E.
5132INC HLINCrement the value stored in Register Pair HL by 1 to now point to the MSB of the address of the string.
5133LD D,(HL)Fetch the MSB of the address of the string (held in the memory location pointed to by Register Pair HL) and store it into Register D.
5134EX DE,HLEXchange the value stored in Register Pair HL with the value stored in Register Pair DE (the address of the string in RAM).
LD (NUMB0),BCStore the length of the string (held in Register Pair BC) into memory location 4ED5H.
5139LD (LAB15),HLStore the pointer to the search arguments (held in Register Pair HL) into memory location 4EDBH.
513CLD HL,(40A4H)Fetch the value held in memory location 40A4H and store it into Register Pair HL.
NOTE: 40A4H is the storage location for the BEGINNING OF THE BASIC PROGRAM IN RAM.
513FLD (VARPTR),HLStore the address of the buffer pointer (held in Register Pair HL) into memory location 4EE1H.
Top of a loop.
LD HL,(VARPTR)Fetch the buffer pointer (held in memory location 4EE1H) and store it into Register Pair HL.
5145LD A,(HL)Fetch the address (at the memory location pointed to by Register Pair HL) and store it into Register A.
5146INC HLINCrement the buffer pointer value stored in Register Pair HL by 1 to point to the byte after the one we just fetched into Register A.
5147OR (HL)Test to see if the next character is 00H by OR’ing Register A against the value of the next character in the program. If that next character was 00H then Register A will be unchanged, and the Z Flag will be set.
5148JR NZ,DOCR00
[514FH]If the NZ FLAG (Not Zero) has been set then the next character was not a 00H, so we continue by JUMPing to 514FH.
514ALD A,0DHIf we passed through to here, then we are at the end of the program. Let Register A equal CARRIAGE RETURN..
End of the loop.
514FH – “CROSS REFERENCE” Routine. Continued here as we narrow down the validity of the character and End-of-Line status.
INC HLINCrement the POINTER TO THE POSITION IN THE BASIC PROGRAM (held in Register Pair HL) so as to now point to the LINE NUMBER.
5150LD (NUMB1),HLStore the LINE NUMBER into memory location 4EDFH just in case we are going to need to track it.
5153
5154INC HL
INC HLBump POINTER TO THE POSITION IN THE BASIC PROGRAM (held in Register Pair HL) by TWO to pass the line number and the SPACE.
LD A,(HL)Fetch the next character in the program (held in the memory location pointed to by Register Pair HL) and store it into Register A.
5156OR ASince a LD command does not set any FLAGS, Set FLAGS based on the contents of Register A.
5157JR NZ,DOCRO3
[515FH]If it OR wasn’t 00H then we are not at the end of the line, and need to keep processing, so JUMP to 515FH.
5159INC HLIf we didn’t jump away, we are at the end of a line. INCrement the value stored in Register Pair HL by 1 to move to the beginning of the next line.
515ALD (VARPTR),HLStore the POINTER TO THE POSITION IN THE BASIC PROGRAM (held in Register Pair HL) into memory location 4EE1H.
515FH – “CROSS REFERENCE” Routine. Continued here as we narrow down the validity of the character and End-of-Line status.
LD DE,(LAB15)Fetch the pointer to the SEARCH ARGUMENT (held in memory location 4EDBH) and store it into Register Pair DE.
5163LD BC,(NUMB0)Fetch the length (held in memory location 4ED5H) and store it into Register Pair BC.
516AJR Z,DISPLY
[516FH]If the Z FLAG (Zero) has been set, then they match. JUMP to 516FH to display them.
516CINC HLIf we passed through then there was no match, so move onto the next character in the program by INCrementing the value stored in Register Pair HL by 1.
516FH – “CROSS REFERENCE” Routine DISPLAY routine. Starts by moving to the end of the program line.
LD A,(HL)Fetch a byte from the program held in the memory location pointed to by Register Pair HL and store it into Register A.
5170OR ASince a LD command does not set any FLAGS, Set FLAGS based on the contents of Register A (and, in all events, clear the CARRY FLAG).
5171JR Z,5176H
[5176H]If the Z FLAG (Zero) has been set then we have reached the end of a program line, so JUMP to 5176H.
5173INC HLIf not, move to the next byte of the program by 1 by INCrementing the value stored in Register Pair HL (POINTER TO THE POSITION IN THE BASIC PROGRAM) by 1.
5174JR DISPLY
[516FH]Loop back to the top of this routine to keep processing characters by JUMPing to 516FH.
5176H – “CROSS REFERENCE” Routine DISPLAY routine. Continues once we are at the end of a program line.
INC HLSince we entered this routine with HL at the end of the line, bump it by 1 to move to point to the next line in the program.
5177LD (VARPTR),HLHL now points to a line number. Store the POINTER TO THE POSITION IN THE BASIC PROGRAM (held in Register Pair HL) into memory location 4EE1H.
517ALD HL,(NUMB1)Fetch the line number (held in memory location 4EDFH) and store it into Register Pair HL.
517DLD E,(HL)Fetch the LSB of the line number pointer (held in the memory location pointed) to by Register Pair HL and store it into Register E.
517EINC HLINCrement the value stored in Register Pair HL by 1.
517FLD D,(HL)Fetch the MSB of the line number pointer (held in the memory location pointed) to by Register Pair HL and store it into Register D.
5180EX DE,HLEXchange the value stored in Register Pair HL (i.e., the MSB of the line number) with the value stored in Register Pair DE (i.e., the line number pointer).
5184INC HLMove past the SPACE after the line number by INCrementing the value stored in Register Pair HL by 1.
5185LD B,05HSince a line number is up to 5 characters, let Register B equal 05H for a DJNZ loop.
Start of a DJNZ loop of 5.
LD A,(HL)Fetch a digit from the line number (held in the memory location pointed to by Register Pair HL) and store it into Register A.
5188OR ASince a LD command does not set any FLAGS, Set FLAGS based on the contents of Register A (and, in all events, clear the CARRY FLAG).
5189JR Z,DISP22
[5191H]Was the digit in the line number a 00H (end of line number?). If so, the Z FLAG (Zero) has been set and we JUMP out of the loop to 5191H.
518BCALL DISOUT
[51B2H]If the line number digit was not a 00H, then output the byte held in Register A to the screen (and if requested, the printer) via a GOSUB to 51B2H.
518EINC HLINCrement the value stored in Register Pair HL by 1 to point to the next character in the line number.
518FDJNZ DISPL2
[5187H]LOOP back to 5187H, reducing Register B each time, and continue to LOOP until Register B has been reduced to ZERO, in which case, continue with the next instruction.
End of the DJNZ loop.
LD A,(4020H)Fetch the value held in memory location 4020H and store it into Register A.
NOTE: 4020H is the storage location for the CURSOR POSITION ON SCREEN.
5194AND 3FHMASK the value of Register A against 3FH (0011 1111) which, when applied to a location on the screen, isolates the COLUMN.
5196CP 3AHCompare the value held in Register A against 3AH (Decimal: 58) to see if we need to display a CARRIAGE RETURN). If A < 58, the CARRY FLAG will be set and we have room to display another set of information. If A >= 58, the NO CARRY FLAG will be set and we don’t have room.
519ALD A,0DHLet Register A equal CARRIAGE RETURN.
519CCALL DISOUT
[51B2H]Output the CARRIAGE RETURN held in Register A to the screen (and if requested, the printer) via a GOSUB to 51B2H.
51A2H – “CROSS REFERENCE” Routine DISPLAY routine. Move to a tab column.
51A4AND 07HMASK the value of Register A against 07H (0000 0111) to get a number which is no greater than 7 (because TAB columns are 8 characters).
51A6INC AWe NEVER want a 0 value, so INCrement the value stored in Register A by 1.
51A7LD B,ACopy the contents of Register A into Register B for a DJNZ loop.
Start of a DJNZ loop of up to 8 spaces.
51AACALL DISOUT
[51B2H]Output the SPACE held in Register A to the screen (and if requested, the printer) via a GOSUB to 51B2H.
51ADDJNZ 51A8H
[51A8H]LOOP back to 51A8H, reducing Register B each time, and continue to LOOP until Register B has been reduced to ZERO, in which case, continue with the next instruction.
End of the DJNZ loop.
51B2H – “CROSS REFERENCE” Routine DISPLAY routine. Subroutine to output the byte held in Register A to the screen (and if requested, the printer).
51B3LD A,** PRTAVL **Let Register A equal the value eplaced into 51B4H (PRTAVL) elsewhere in this Overlay. This is the Printer AVAILABLE/NOT AVAILABLE status flag.
51B5OR ASince a LD command does not set any FLAGS, Set FLAGS based on the contents of Register A (and, in all events, clear the CARRY FLAG).
51B6LD A,CCopy the byte to display (held in Register C) into Register A.
51B7JR Z,DISOU1
[51BEH]If the Z FLAG (Zero) has been set then the printer is NOT available, so skip over the next 3 instructions (which print) and JUMP to 51BEH.
51B9PUSH AFSave the byte to print (held in Register Pair AF) to the top of the stack.
51BACALL 003BH
[003BH]GOSUB to 003BH.
NOTE: 003BH is the Model III ROM routine to write the byte held in Register A to the printer, including waiting for the printer to be available OR getting a BREAK. Uses Register Pair DE.
51BDPOP AFRestore the byte to print (held at the top of the stack) back into Register A, and then remove the entry from the stack.
JP 0033H
[0033H]JUMP to 0033H.
NOTE: 0033H is the Model III ROM character print routine; displays the character held in Register A at the current cursor position. Since this was JUMPED to instead of CALLed, the RET at the end of this ROM routine will then RETurn to the caller of this subroutine instead of returning to this place.
51C1H – “CROSS REFERENCE” Routine Subroutine to compare the contents of DE and HL.
51C2PUSH DESave the contents of Register Pair DE to the top of the stack.
51C3PUSH HLSave the contents of Register Pair HL to the top of the stack.
Top of a loop.
51C5CP (HL)Compare the DE byte with the HL byte. If they are different …
51C8LDIIf they are the same, then move to the 2nd character of both HL and DE via LDI command; which copies BC number of characters from (HL) to (DE), dropping BC each time. When BC hits 0, the PE flag is reset.
51CAJP PE,51C4H
[51C4H]If the PARITY/OVERFLOW FLAG has been SET then we have more characters to process, so LOOP BACK to 51C4H.
End of the loop.
51CDXOR ASet Register A to ZERO and clear all Flags to signal a match (success!).
POP HLPut the value held at the top of the STACK into Register Pair HL, and then remove the entry from the stack.
51CFPOP DEPut the value held at the top of the STACK into Register Pair DE, and then remove the entry from the stack.
51D0POP BCPut the value held at the top of the STACK into Register Pair BC, and then remove the entry from the stack.
51D1RETRETurn to the caller.
END 4E00HThat’s it!
[0A9AH]
[1034H]
[0FD9H]
Top of Loop.
End of Loop.
[510BH]
2C
It is a COMPARE SYMBOL routine which comparess the symbol in the input string pointed to by HL register to the value in the location following the RST 08 call.
If there is a match, control is returned to address of the RST 08 instruction 2 with the next symbol in the A register and HL incremented by one. If the two characters do not match, a syntax error message is given.
[2337H]
[1E4AH]
512E
LD B,00H
NOTE: 40A4H is the storage location for the BEGINNING OF THE BASIC PROGRAM IN RAM.
Top of a loop.
[514FH]
End of the loop.
5154
INC HL
[515FH]
[516FH]
[5176H]
[516FH]
Start of a DJNZ loop of 5.
[5191H]
[51B2H]
[5187H]
End of the DJNZ loop.
NOTE: 4020H is the storage location for the CURSOR POSITION ON SCREEN.
[51B2H]
Start of a DJNZ loop of up to 8 spaces.
[51B2H]
[51A8H]
End of the DJNZ loop.
[51BEH]
[003BH]
NOTE: 003BH is the Model III ROM routine to write the byte held in Register A to the printer, including waiting for the printer to be available OR getting a BREAK. Uses Register Pair DE.
[0033H]
NOTE: 0033H is the Model III ROM character print routine; displays the character held in Register A at the current cursor position. Since this was JUMPED to instead of CALLed, the RET at the end of this ROM routine will then RETurn to the caller of this subroutine instead of returning to this place.
Top of a loop.
[51C4H]
End of the loop.