×   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

918D PRINT

Submitted by Steve Fewell

Description:

Get the next non-space character from BASIC Text Pointer A. If the character is a '#' (hash), then jump to
the PRINT# routine (&9141); otherwise, decrement &0A (Text Pointer A offset).

[&91AB]: Start a new Output field (&14 is reset and so is &15)
Clear carry flag (as we are outputting numbers in decimal - not hexadecimal).
Store &0400 (the LSB byte of @%) [Print width] in location &14 [PRINT BYTES] (which specifies the number of
bytes in each output field).
[&91B1] Move the carry flag (specified output Hexadecimal (if set) or Decimal (if clear) for numeric values) to the
top bit of location &15 (PRINT FLAG).

Get the next non-space character from BASIC Text Pointer A (&0B,&0C plus offset &0A).
If the next character is ':', then we have an empty PRINT field/statement, so call &BA92 to Output a new line and
goto &9000 to process the next statement.
If the next character is '<cr>' (carriage return), then we have an empty PRINT field/statement, so call &BA92 to Output
a new line and goto &9000 to process the next statement.
If the next character is 'ELSE'-token, then we have an empty PRINT field/statement, so call &BA92 to Output a new line &
goto &9000 to process the next statement.

[&91DB]: If the next character is '~' [tilde], then jump back to &91B1 to set the top bit of &15 to 1
(print numeric values in hexadecimal notation) and check again for end of statement (newline if so).

If the next character is ',' then jump to &9196 to complete the output field, as follows:
* If &0400 (Width of print field) is 0 then we do not need to pad the field, so jump to &91AB
to start a new output field.
* If COUNT is zero (we have just began a new line) then do not pad (as nothing has been output to the new line yet),
so jump to &91AB to start a new output field.
* Set A to COUNT (&1E).
* Subtract &0400 (field width) from A (COUNT).
* If the subtraction did not underflow and the result > 0 then jump to the previous step to subtract again.
* If the subtraction did not underflow and the result = 0 then jump to &91AB to start a new output field.
* Keep incrementing Y, calling &BD92 to output a space for each incrementation, until Y = 00.
* Now the field has been padded with the required number of spaces.
* Continue to &91AB to start a new output field.
If the next character is ';' then jump to &91C8 to end the current field, as follows:
* Zero number of bytes in print field (&14)
* Zero Print [Decimal/Hexadecimal] Flag (&15)
* Get the next non-space charater pointed to by BASIC Text pointer A.
* If the character is ':' then jump to &9000 (to process the next statement) without outputting a new line.
* If the character is <cr> (carriage-return) then jump to &9000 (to process the next statement) without outputting a new line.
* If the character is 'ELSE-token' then jump to &9000 (to process the next stetement) without outputting a new line.
* If not end of statement then continue with &91DB to check for '~', ',' or ';' again.
[&91E7] Not end of statement and not tilde, comma or semicolon - check ', TAB & SPC
Call routine &927A to check for specific characters and PRINT options, this routine checks the following:
* Copy BASIC Text pointer A details to BASIC Text Pointer B.
* If character = "'" [quote], then jump to routine &9267 to output a new line.
* If character = 'TAB('-token then jump to routine &9241 to go to the requested screen position.
* If character = 'SPC'-token then jump to routine &925B to output the requested number of spaces.
* Otherwise, set carry flag and exit.
If carry is clear on return from routine &927A, then a special function was carried out (either New line, TAB(
or SPC), so jump back to &91B3 to check for the end of statement, tilde, comma, semicolon and further
New line ("'"), TAB( and SPC commands before continuing.

[&91EC] Get result of the expression to output
Store &14 and &15 to the stack, decrement BASIC Text pointer B offset, and call &9D3B to get
the result of the expression at BASIC Text Pointer B.
Retrieve the &14 and &15 values from the stack.
Update BASIC Text Pointer A Offset to the BASIC Text Pointer B Offset value.

Check the variable type of the expression result (Y). If the variable type is not String (0) then convert as follows:
* Call routine &A118 (NUMASC) to convert the Numeric result value into a String value and place the result
in the SWA. This routine will convert in Hexadecimal-format if the Print flag (&15) is negative.
* Load A with the width of the PRINT field (&14).
* Subtract from this the length of the ASCII string (&36).
* If the SWA String value is less than the PRINT field width then:
*     Set Y to A (the difference in width).
*     call routine &BD92 for Y number of times, to pad the field with leading spaces until it is the
required width. This is to make sure that numerical values line up.
* Now the SWA output string (along with any spaces that have already been output) is greater than or equal to
the required field width.
[&9217] Output the value of the expression result
If the SWA length (&36) is zero then there is nothing to output, so jump back to &91B3 to check for end of
statement or to continue with the next PRINT field (if not end of statement).

Starting at the first character of the SWA, continue setting A to the next character and calling routine &BD98 to
output that character; until all &36 characters of the SWA have been output.

Jump back to &91B3 to check for end of statement or to continue with the next PRINT field (if not end of
statement).


Disassembly for the PRINT routine

918D   032 223 140 20 DF 8C JSR &8CDF Get next non-space char (PTR A) and compare with '#'
9190   240 175 F0 AF BEQ -81 --> &9141 PRINT#
9192   198 010 C6 0A DEC &0A
9194   128 021 80 15 BRA 21 --> &91AB Start new output field
9196   173 000 004 AD 00 04 LDA &0400
9199   240 016 F0 10 BEQ 16 --> &91AB Start new output field
919B   165 030 A5 1E LDA &1E
919D   240 012 F0 0C BEQ 12 --> &91AB Start new output field
919F   237 000 004 ED 00 04 SBC &0400
91A2   176 249 B0 F9 BCS -7 --> &919D
91A4   168 A8 TAY
91A5   032 146 189 20 92 BD JSR &BD92 Print a space to the screen
91A8   200 C8 INY
91A9   208 250 D0 FA BNE -6 --> &91A5
91AB   024 18 CLC
91AC   173 000 004 AD 00 04 LDA &0400
91AF   133 020 85 14 STA &14
91B1 f 102 021 66 15 ROR &15
91B3   032 224 142 20 E0 8E JSR &8EE0 Get next non-space character (PTR A)
91B6 : 201 058 C9 3A CMP#&3A
91B8   240 008 F0 08 BEQ 8 --> &91C2
91BA   201 013 C9 0D CMP#&0D
91BC   240 004 F0 04 BEQ 4 --> &91C2
91BE   201 139 C9 8B CMP#&8B
91C0   208 025 D0 19 BNE 25 --> &91DB
91C2   032 146 186 20 92 BA JSR &BA92 Output new line & Zero COUNT
91C5 L 076 000 144 4C 00 90 JMP &9000 End of PRINT. Check end of Statement & continue to process next program statement
91C8 d 100 020 64 14 STZ &14
91CA d 100 021 64 15 STZ &15
91CC   032 224 142 20 E0 8E JSR &8EE0 Get next non-space character (PTR A)
91CF : 201 058 C9 3A CMP#&3A
91D1   240 242 F0 F2 BEQ -14 --> &91C5
91D3   201 013 C9 0D CMP#&0D
91D5   240 238 F0 EE BEQ -18 --> &91C5
91D7   201 139 C9 8B CMP#&8B
91D9   240 234 F0 EA BEQ -22 --> &91C5
91DB ~ 201 126 C9 7E CMP#&7E
91DD   240 210 F0 D2 BEQ -46 --> &91B1
91DF , 201 044 C9 2C CMP#&2C
91E1   240 179 F0 B3 BEQ -77 --> &9196 Comma (pad field)
91E3 ; 201 059 C9 3B CMP#&3B
91E5   240 225 F0 E1 BEQ -31 --> &91C8 Semicolon (check for end of PRINT statement)
91E7 z 032 122 146 20 7A 92 JSR &927A Check for "'", 'TAB(' or 'SPC'
91EA   144 199 90 C7 BCC -57 --> &91B3
91EC   165 020 A5 14 LDA &14
91EE H 072 48 PHA
91EF   165 021 A5 15 LDA &15
91F1 H 072 48 PHA
91F2   198 027 C6 1B DEC &1B
91F4 ; 032 059 157 20 3B 9D JSR &9D3B Get the result of the expression at PTR B
91F7 h 104 68 PLA
91F8   133 021 85 15 STA &15
91FA h 104 68 PLA
91FB   133 020 85 14 STA &14
91FD   165 027 A5 1B LDA &1B
91FF   133 010 85 0A STA &0A
9201   152 98 TYA
9202   240 019 F0 13 BEQ 19 --> &9217 Print output string
9204   032 024 161 20 18 A1 JSR &A118 NUMASC (Convert Numeric value to ASCII String)
9207   165 020 A5 14 LDA &14
9209 8 056 38 SEC
920A 6 229 054 E5 36 SBC &36
920C   144 009 90 09 BCC 9 --> &9217 Print Output string
920E   240 007 F0 07 BEQ 7 --> &9217 Print output String
9210   168 A8 TAY
9211   032 146 189 20 92 BD JSR &BD92 Output a space character
9214   136 88 DEY
9215   208 250 D0 FA BNE -6 --> &9211
9217 6 165 054 A5 36 LDA &36
9219   240 152 F0 98 BEQ -104 --> &91B3
921B   160 000 A0 00 LDY#&00
921D   185 000 006 B9 00 06 LDA &0600,Y
9220   032 152 189 20 98 BD JSR &BD98 Output character in A
9223   200 C8 INY
9224 6 196 054 C4 36 CPY &36
9226   208 245 D0 F5 BNE -11 --> &921D
9228   128 137 80 89 BRA -119 --> &91B3

927A Check special print character (', TAB( and SPC)

927A   166 011 A6 0B LDX &0B
927C   134 025 86 19 STX &19
927E   166 012 A6 0C LDX &0C
9280   134 026 86 1A STX &1A
9282   166 010 A6 0A LDX &0A
9284   134 027 86 1B STX &1B
9286 ' 201 039 C9 27 CMP#&27 char = (')
9288   240 221 F0 DD BEQ -35 --> &9267 (PRINT) quote (')
928A   201 138 C9 8A CMP#&8A char = TAB(
928C   240 179 F0 B3 BEQ -77 --> &9241 (PRINT) TAB(
928E   201 137 C9 89 CMP#&89 char = SPC
9290   240 201 F0 C9 BEQ -55 --> &925B (PRINT) SPC
9292 8 056 38 SEC
9293 ` 096 60 RTS

 


 Back to 8BS
Or