Skip to navigation

Text: PrintCharacter

Name: PrintCharacter [Show more] Type: Subroutine Category: Text Summary: Print a single-byte VDU command or character from a text token, optionally printing a drop shadow if the character is alphanumeric
Context: See this subroutine in context in the source code References: This subroutine is called as follows: * PrintDigit calls PrintCharacter * PrintVduCharacter calls PrintCharacter

Arguments: A The one-byte character to be printed
Returns: X X is preserved
.PrintCharacter BIT textDropShadow \ If bit 7 of textDropShadow is set, jump to byte2 to BMI byte2 \ print the character in A as-is (i.e. without a drop \ shadow if it is alphanumeric) CMP #' ' \ If the character in A is a control character, jump to BCC byte2 \ byte2 to print the character as-is CMP #127 \ If the character in A is a top-bit-set character, jump BCS byte2 \ jump to byte2 to print the character as-is \ If we get here then bit 7 of textDropShadow is clear \ and the character in A is alphanumeric, so now we \ print the character with a drop shadow \ \ We do this by printing the sequence of VDU commands at \ vduShadowRear and vduShadowFront, which produce the \ drop shadow effect \ \ The drop shadow is printed by first printing the VDU \ commands in vduShadowRear, to print the rear character \ in yellow, and then in vduShadowFront, to print the \ front character in red or cyan \ \ The rear character is offset down from the front \ character by four graphics units, which equates to an \ offset of one pixel in mode 5 \ \ The VDU commands are printed backwards, because that \ makes the loop condition slightly simpler, and it also \ means we can poke the character to print into the \ start of each block of VDU commands, knowing that they \ will then be printed last in each VDU sequence STA vduShadowFront \ Insert the character to be printed into the sequence STA vduShadowRear \ of VDU commands at vduShadowRear and vduShadowFront, \ so that they print the required character with a drop \ shadow TXA \ Store X on the stack so we can preserve it PHA LDX #22 \ The vduShadowRear and vduShadowFront variables contain \ a total of 23 VDU command bytes, so set a byte counter \ in X so we can work through them from the end of \ vduShadowRear backwards to the start of vduShadowFront .byte1 LDA vduShadowFront,X \ Print the X-th character from the vduShadowRear and JSR OSWRCH \ vduShadowFront variables DEX \ Decrement the byte counter BPL byte1 \ Loop back until we have printed all 23 command bytes PLA \ Retrieve X from the stack so it is preserved across TAX \ calls to the routine RTS \ Return from the subroutine .byte2 JMP OSWRCH \ We jump here if drop shadows are disabled, or if A is \ not alphanumeric, in which case print the character in \ A and return from the subroutine using a tail call