Prints something! It can be an empty line, a single expression/literal, or multiple expressions/literals seperated by tabulation directives (comma, semi-colon, or the TAB keyword).
If end of line has been reached than exit via NewLine. Note that the handler function starts on the third line. | ||||
0555 | 2B | DCX H | ||
0556 | D7 | RST NextChar | ||
0557 | CA8A05 | JZ NewLine | ||
055A | C8 | RZ | ||
If the start of a string literal (ie characters enclosed in double-quotes), then print it. If this function returns having found the end of the line then jump back (instead of simply RZ-ing) to the top so that NewLine gets called. | ||||
055B | FE22 | CPI '"' | ||
055D | CCA205 | CZ PrintString | ||
0560 | CA5505 | JZ Print-2 | ||
If TAB( keyword id, then jump to the Tab() handler. | ||||
0563 | FE94 | CPI KWID_TAB | ||
0565 | CAC705 | JZ Tab | ||
0568 | E5 | PUSH H | ||
If we have a comma, then that means we have to move to the next tab break. | ||||
0569 | FE2C | CPI ',' | ||
056B | CAB305 | JZ ToNextTabBreak | ||
If we have a semi-colon, then we don't need to do anything - just jump to the end of Tab() which restores the prog ptr and loops back to Print-2. | ||||
056E | FE3B | CPI ';' | ||
0570 | CADF05 | JZ ExitTab | ||
We've got an expression to print. First we discard the prog ptr kept on the stack, and evaluate the expression to print. | ||||
0573 | C1 | POP B | ||
0574 | CD8A06 | CALL EvalExpression | ||
Preserve the prog ptr and convert the numeric expression result (in FACCUM of course) to a string and print it.. | ||||
0577 | E5 | PUSH H | ||
0578 | CD420B | CALL FOut | ||
057B | CDA305 | CALL PrintString | ||
Print a space. Expressions are printed with a trailing space, don't know why. | ||||
057E | 3E20 | MVI A,' ' | ||
0580 | DF | RST OutChar | ||
Restore the prog ptr and jump back to continue with the rest of the print statement. | ||||
0581 | E1 | POP H | ||
0582 | C35505 | JMP Print-2 |
HL points to just beyond the last byte of a line of user input. Here we write a null byte to terminate it, reset HL to point to the start of the input line buffer, then fall into NewLine.
0585 | 3600 | TerminateInput | MVI M,00 | |
0587 | 211201 | LXI H,LINE_BUFFER-1 |
Prints carriage return + line feed, plus a series of nulls which was probably due to some peculiarity of the teletypes of the day.
Print carriage return and save the ASCII value 13 to TERMINAL_X | ||||
058A | 3E0D | NewLine | MVI A,'\r' | |
058C | 322700 | STA TERMINAL_X | ||
058F | DF | RST OutChar | ||
Print line feed. | ||||
0590 | 3E0A | MVI A,'\n' | ||
0592 | DF | RST OutChar | ||
Print nulls, the number of which is taken from TERMINAL_Y. TERMINAL_X is reset to 0. | ||||
0593 | 3A2600 | LDA TERMINAL_Y | ||
0596 | 3D | PrintNullLoop | DCR A | |
0597 | 322700 | STA TERMINAL_X | ||
059A | C8 | RZ | ||
059B | F5 | PUSH PSW | ||
059C | AF | XRA A | ||
059D | DF | RST OutChar | ||
059E | F1 | POP PSW | ||
059F | C39605 | JMP PrintNullLoop |
Prints a string to the terminal. Printing stops when a null byte or a '"' character is reached.
05A2 | 23 | INX H | ||
05A3 | 7E | PrintString | MOV A,M | |
05A4 | B7 | ORA A | ||
05A5 | C8 | RZ | ||
05A6 | 23 | INX H | ||
05A7 | FE22 | CPI '"' | ||
05A9 | C8 | RZ | ||
05AA | DF | RST OutChar | ||
05AB | FE0D | CPI '\r' | ||
05AD | CC8A05 | CZ NewLine | ||
05B0 | C3A305 | JMP PrintString |
Calculate how many spaces are needed to get us to the next tab-break then jump to PrintSpaces to do it.
If current character output position is beyond the last tab-break column, then call NewLine and jump to ExitTab. | ||||
05B3 | 3A2700 | ToNextTabBreak | LDA TERMINAL_X | |
05B6 | FE38 | CPI 38 | ||
05B8 | D48A05 | CNC NewLine | ||
05BB | D2DF05 | JNC ExitTab | ||
Get the number of spaces required to reach the next tab break. A = (14 - (A % 14)) - 1. | ||||
05BE | D60E | CalcSpaceCount | SUI 0E | |
05C0 | D2BE05 | JNC CalcSpaceCount | ||
05C3 | 2F | CMA | ||
Jump to print the required number of spaces. | ||||
05C4 | C3D605 | JMP PrintSpaces |
Tabulation. The TAB keyword takes an integer argument denoting the absolute column to print spaces up to.
Get positive integer argument (the function called errors out if it's not a positive integer) into E | ||||
05C7 | CD8804 | Tab | CALL GetSubscript | |
Syntax check for closing bracket. | ||||
05CA | CF | RST SyntaxCheck | ||
05CB | 29 | ')' | ||
Preserve prog ptr (minus one cos it gets incremented later). | ||||
05CC | 2B | DCX H | ||
05CD | E5 | PUSH H | ||
Get the number of spaces we need to print. This number is the argument in E minus TERMINAL_X. If this is 0 or a negative number then we can't print any spaces so jump ahead to ExitTab. Note the math is a bit backward - this is a better way of doing it, memory-wise. | ||||
05CE | 3A2700 | LDA TERMINAL_X | ||
05D1 | 2F | CMA | ||
05D2 | 83 | ADD E | ||
05D3 | D2DF05 | JNC ExitTab | ||
Print A+1 spaces. | ||||
05D6 | 3C | PrintSpaces | INR A | |
05D7 | 47 | MOV B,A | ||
05D8 | 3E20 | MVI A,' ' | ||
05DA | DF | PrintSpaceLoop | RST OutChar | |
05DB | 05 | DCR B | ||
05DC | C2DA05 | JNZ PrintSpaceLoop | ||
Restore the prog ptr, get the next character of program and jump back to the Print keyword handler. | ||||
05DF | E1 | ExitTab | POP H | |
05E0 | D7 | RST NextChar | ||
05E1 | C35A05 | JMP Print+3 |