Skip to navigation

Elite on the BBC Micro and NES

Text: TT27

[NES version, Bank 2]

Name: TT27 [Show more] Type: Subroutine Category: Text Summary: Print a text token Deep dive: Printing text tokens
Context: See this subroutine in context in the source code References: This subroutine is called as follows: * DETOK2 calls TT27 * ex calls TT27 * JMTB calls TT27 * MT17 calls TT27 * TT27_b2 calls TT27 * TT43 calls TT27

Print a text token (i.e. a character, control code, two-letter token or recursive token).
Arguments: A The text token to be printed
.TT27S JMP PrintCtrlCode_b0 ; We jump here from below if the character to print is ; in the range 0 to 9, so jump to PrintCtrlCode to print ; the control code and return from the subroutine using ; a tail call .TT27 PHA ; Store A on the stack, so we can retrieve it below SETUP_PPU_FOR_ICON_BAR ; If the PPU has started drawing the icon bar, configure ; the PPU to use nametable 0 and pattern table 0 PLA ; Restore A from the stack TAX ; Copy the token number from A to X. We can then keep ; decrementing X and testing it against zero, while ; keeping the original token number intact in A; this ; effectively implements a switch statement on the ; value of the token BMI TT43 ; If token > 127, this is either a two-letter token ; (128-159) or a recursive token (160-255), so jump ; to TT43 to process tokens CMP #10 ; If token < 10 then this is a control code, so jump to BCC TT27S ; PrintCtrlCode via TT27S to print it CMP #96 ; By this point, token is either 7, or in 10-127. BCS ex ; Check token number in A and if token >= 96, then the ; token is in 96-127, which is a recursive token, so ; jump to ex, which prints recursive tokens in this ; range (i.e. where the recursive token number is ; correct and doesn't need correcting) CMP #14 ; If token < 14, skip the following two instructions BCC P%+6 CMP #32 ; If token < 32, then this means token is in 14-31, so BCC qw ; this is a recursive token that needs 114 adding to it ; to get the recursive token number, so jump to qw ; which will do this ; By this point, token is either 7 (beep) or in 10-13 ; (line feeds and carriage returns), or in 32-95 ; (ASCII letters, numbers and punctuation) LDX QQ17 ; Fetch QQ17, which controls letter case, into X BEQ TT44 ; If QQ17 = 0, then ALL CAPS is set, so jump to TT44 ; to print this character as is (i.e. as a capital) BMI TT41 ; If QQ17 has bit 7 set, then we are using Sentence ; Case, so jump to TT41, which will print the ; character in upper or lower case, depending on ; whether this is the first letter in a word BIT QQ17 ; If we get here, QQ17 is not 0 and bit 7 is clear, so BVS TT44 ; either it is bit 6 that is set, or some other flag in ; QQ17 is set (bits 0-5). So check whether bit 6 is set. ; If it is, then ALL CAPS has been set (as bit 7 is ; clear), so jump to TT26 via TT44 to print the ; character in upper case ; If we get here, some other flag is set in QQ17 (one ; of bits 0-5 is set), which shouldn't happen in this ; version of Elite. If this were the case, then we ; would fall through into TT42 to print in lower case, ; which is how printing all words in lower case could ; be supported (by setting QQ17 to 1, say)