×   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

9141 PRINT#

Submitted by Steve Fewell

Description:

Copy BASIC Text pointer A values to Text Pointer B.
Check that '#' is the next non-space character - if it isn't then generate a 'Missing #' error.
Note: The next character will always be '#' as this routine is only called from the PRINT routine,
which checks for the '#' character before calling this routine!
Get the Integer value from PTR B (after the '#') and set Y to the LSB of this value.
This is the file channel number for the file that we will write to.
Push channel number to the stack.

If the next non-space character (after the channel number) is not a comma, then we have no
data to write to the file, so exit [if the end of statement was not reached then &9002 will
generate a 'Syntax Error'].

Call the expression handler (&9D3B) to obtain the result of the expression after the comma character.
Store the FWA value (in Floating-Point 5-byte packed format) to temporary Floating-Point location &046C-&0470.
This packs the FWA value (ready to be written to the file). This is done irrespective of whether the expression return
value is a Floating-Point value or not.
Retrieve the channel number (in Y) from the stack.

Store &27 (the returned value type) to the file [1-byte value] using OSBPUT (&FFD4)
[Y = channel handle & A = byte to write].

If the value type (&27) is Integer (positive &27 value) then write the 4-byte IWA value to the file
(using 4 calls to OSBPUT). The integer value is written Most-significant byte (&2D) first.

If the value type (&27) is Float (negative &27 value) then write the 5-byte packed FWA value at
location &046C-&0470 to the file (using 5 calls to OSBPUT). The Float value is written last byte (&0470) first.

If the value type (&27) is String (zero &27 value) then write the SWA value
to the file (using a separate OSBPUT call for each byte). Firstly, the string length is written (&36) [1-byte].
Next, the String value is written (last byte first (&0600+&36-1)-&0600).

After the returned value has been written, go back to &9144 to check if there are any more commas.
If another comma is present (after the expression) then another value is required to be written to the file,
so repeat the processing for the next data value. If no more values are found then goto &9187 to
pop the channel number value from the stack (clean up stack), store back the offset (in Y - set in &8EEB) to &0A
(Pointer A offset location), check for the end of statement (issuing Syntax error if not end of statement)
and start processing the next statement/program line (&9002).

Disassembly for the PRINT# routine

9141 < 032 060 186 20 3C BA JSR &BA3C PTR B=PTR A, Check for '#', Set Y to file channel number (PTR B)
9144 Z 090 5A PHY
9145   032 235 142 20 EB 8E JSR &8EEB Get next non-space char (PTR B) and compare with ','
9148 = 208 061 D0 3D BNE 61 --> &9187 No comma found, so exit
914A ; 032 059 157 20 3B 9D JSR &9D3B Get result of expression
914D   032 017 165 20 11 A5 JSR &A511 Store FWA to &046C & set argp=&046C
9150 z 122 7A PLY
9151 ' 165 039 A5 27 LDA &27
9153   032 212 255 20 D4 FF JSR &FFD4 OSBPUT [Store variable type to file]
9156   170 AA TAX
9157   240 027 F0 1B BEQ 27 --> &9174
9159 0 048 012 30 0C BMI 12 --> &9167
915B   162 003 A2 03 LDX#&03
915D * 181 042 B5 2A LDA &2A,X
915F   032 212 255 20 D4 FF JSR &FFD4 OSBPUT [Store IWA to file]
9162   202 CA DEX
9163   016 248 10 F8 BPL -8 --> &915D
9165   128 221 80 DD BRA -35 --> &9144
9167   162 004 A2 04 LDX#&04
9169 l 189 108 004 BD 6C 04 LDA &046C,X
916C   032 212 255 20 D4 FF JSR &FFD4 OSBPUT [Store FWA (packed) to file]
916F   202 CA DEX
9170   016 247 10 F7 BPL -9 --> &9169
9172   128 208 80 D0 BRA -48 --> &9144
9174 6 165 054 A5 36 LDA &36
9176   032 212 255 20 D4 FF JSR &FFD4 OSBPUT [Store string (SWA) length to file]
9179   170 AA TAX
917A   240 200 F0 C8 BEQ -56 --> &9144
917C   189 255 005 BD FF 05 LDA &05FF,X
917F   032 212 255 20 D4 FF JSR &FFD4 OSBPUT [Store SWA to file]
9182   202 CA DEX
9183   208 247 D0 F7 BNE -9 --> &917C
9185   128 189 80 BD BRA -67 --> &9144
9187 h 104 68 PLA
9188   132 010 84 0A STY &0A
918A L 076 002 144 4C 02 90 JMP &9002 'Syntax error' if not end of statement; otherwise, execute next statement/program line

Copy PTR A to PTR B, check for '#', get file channel number and set Y=channel number
BA3C   198 010 C6 0A DEC &0A
BA3E   165 010 A5 0A LDA &0A
BA40   133 027 85 1B STA &1B
BA42   165 011 A5 0B LDA &0B
BA44   133 025 85 19 STA &19
BA46   165 012 A5 0C LDA &0C
BA48   133 026 85 1A STA &1A
BA4A   032 213 142 20 D5 8E JSR &8ED5 Get next non-space char (PTR B)
BA4D # 201 035 C9 23 CMP#&23 check for '#'
BA4F   208 176 D0 B0 BNE -80 --> &BA01 'Missing #' error
BA51   032 180 150 20 B4 96 JSR &96B4 Get integer value (PTR B)
BA54 * 164 042 A4 2A LDY &2A
BA56   152 98 TYA
BA57 ` 096 60 RTS

 


 Back to 8BS
Or