×   Main Menu ALL The 8BS News Manuals (New menu) Links Worth a Look Tools Disc and Basic Webring Site Map 8BS Guestbook Old Guest Book Me The Barnsley Rovers   
8-Bit Software

The BBC and Master Computer Public Domain Library

BD37 Output ASCII characeter or BASIC Token to screen


Submitted by Steve Fewell

Routine:PrintToken
Name: Output ASCII characeter or BASIC Token to screen
Starting Address: &BD37
Entry criteria: A contains the ASCII value to output to the screen.

Description:

Store A in location &37.
If A is less then #&80 then the ASCII character will be output via the &BD94 routine.

&BD94 outputs the character with correct handling of the following:
* The COUNT variable
* New line when COUNT exceeds the WIDTH value
* Redirection of output (to memory) when *EDIT-mode is active
* New line when character to output is &0D ('<cr>')
Otherwise, a BASIC token is been specified by the ASCII character, so output the BASIC Keyword (in ASCII text) as follows:
*1) Set pointer &38-&39 to point to address &8456 -> which is the address of the start of the Token table
*2) Save Y (the current program/command line position) to the Stack
*3) Set Y to 0 (to point to the start of the next Keyword in the &38-&39 token table list.
*4) Load the next character (of the token) from the Token Table (pointed to by (&38,&39) + Y)
*5) Skip all ASCII characters (less then #&80) [incrementing Y for each character skipped]
     Now, the character is the token number that represents the BASIC Keyword specified by the skipped characters
*6) Compare the character against the token we want to output (stored in location &37)
     If the token (character) is equal to &37 then output the Keyword text as follows [&BD5E]:
          * Reset Y to 0 (the start of the ASCII Text Keyword)
          * Load the next character of the Keyword from (&38-&39) + Y.
          * If the character is negative (the token number) then goto Step 9 to exit (as token is now printed).
          * Otherwise, call routine &BD94 to output the ASCII character to the screen.
          * Increment Y (to point to the next character of the BASIC Keyword)
          * If Y is not 0 (less than 255 characters have been printed) then jump back to load the next character of the Keyword
          * Jump to step 9 to exit.
*7) Set the token table pointer (&38,&39) to point to the position after the Token Number (i.e. Add Y + 1 to the pointer).
*8) Jump back to Step 3 to check the next BASIC Keyword in the Token Table list
*9) Retrieve Y from the Stack and exit


Disassembly for the Output ASCII characeter or BASIC Token to screen routine

BD37 7 133 055 85 37 STA &37
BD39   201 128 C9 80 CMP#&80
BD3B W 144 087 90 57 BCC 87 --> &BD94 Output character to the screen
BD3D V 169 086 A9 56 LDA#&56
BD3F 8 133 056 85 38 STA &38
BD41   169 132 A9 84 LDA#&84
BD43 9 133 057 85 39 STA &39
BD45 Z 090 5A PHY
BD46   160 000 A0 00 LDY#&00
BD48   200 C8 INY
BD49 8 177 056 B1 38 LDA (&38),Y
BD4B   016 251 10 FB BPL -5 --> &BD48
BD4D 7 197 055 C5 37 CMP &37
BD4F   240 013 F0 0D BEQ 13 --> &BD5E
BD51   200 C8 INY
BD52   152 98 TYA
BD53 8 056 38 SEC
BD54 e8 101 056 65 38 ADC &38
BD56 8 133 056 85 38 STA &38
BD58   144 236 90 EC BCC -20 --> &BD46
BD5A 9 230 057 E6 39 INC &39
BD5C   128 232 80 E8 BRA -24 --> &BD46
BD5E   160 000 A0 00 LDY#&00
BD60 8 177 056 B1 38 LDA (&38),Y
BD62 0 048 006 30 06 BMI 6 --> &BD6A
BD64   032 148 189 20 94 BD JSR &BD94 Output character to the screen
BD67   200 C8 INY
BD68   208 246 D0 F6 BNE -10 --> &BD60
BD6A z 122 7A PLY
BD6B ` 096 60 RTS

 


 Back to 8BS
Or