Skip to navigation


Text: PrintToken

Name: PrintToken [Show more] Type: Subroutine Category: Text Summary: Print a recursive token Deep dive: Text tokens
Addresses of token strings are in the (tokenHi tokenLo) table. Tokens are numbered from 0 to 54. Each token's string contains bytes that are printed as follows: * 0-159 Print character n * 160-199 Print n - 160 spaces (0 to 39) * 200-254 Print token n - 200 (0 to 54) * 255 End of token
Arguments: X The token number (0 to 54) (xCursor, yCursor) The on-screen position for the token
.PrintToken LDY #0 \ We are about to work our way through the token, one \ byte at a time, so set a byte counter in Y .toke1 LDA tokenHi,X \ Set (S R) = the X-th entry in (tokenHi tokenLo), which STA S \ points to the string of bytes in token X LDA tokenLo,X STA R .toke2 LDA (R),Y \ Set A to the Y-th byte at (S R), which contains the \ next character in the token CMP #255 \ If A = 255 then we have reached the end of the token, BEQ toke8 \ so jump to toke8 to return from the subroutine CMP #200 \ If A < 200 then this byte is not another token, so BCC toke5 \ jump to toke5 SEC \ A >= 200, so this is a pointer to another token SBC #200 \ embedded in the current token, so subtract 200 to get \ the embedded token's number STA T \ Store the embedded token's number in T TXA \ Store X and Y on the stack so we can retrieve them PHA \ after printing the embedded token TYA PHA LDX T \ Set X to the number of the embedded token we need to \ print CPX #54 \ If X <> 54, jump to toke3 to skip the following three BNE toke3 \ instructions and print the embedded token LDX #0 \ X = 54, so call PrintHeader with X = 0 to print JSR PrintHeader \ "FORMULA 3 CHAMPIONSHIP" as a double-height header \ at column 4, row 3, in yellow text on a red background JMP toke4 \ Skip the following instruction .toke3 JSR PrintToken \ Print token X (so if it also contains embedded tokens, \ they will also be expanded and printed) .toke4 PLA \ Retrieve X and Y from the stack TAY PLA TAX INY \ Increment the byte counter JMP toke1 \ Loop back to print the next byte in the token, making \ sure to recalculate (S R) as it will have been \ corrupted by the call to PrintToken .toke5 \ If we get here then A < 200, so this byte is not \ another token CMP #160 \ If A < 160, jump to toke6 to skip the following three BCC toke6 \ instructions SBC #160 \ A is in the range 160 to 199, so subtract 160 to get \ the number of spaces to print, in the range 0 to 39 JSR PrintSpaces \ Print the number of spaces in A BEQ toke7 \ Skip the following instruction (this BNE is \ effectively a JMP as PrintSpaces sets the Z flag) .toke6 JSR PrintCharacter \ Print the character in A (which is in the range 0 to \ 159) .toke7 INY \ Increment the byte counter JMP toke2 \ Loop back to print the next byte in the token .toke8 RTS \ Return from the subroutine