×   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

BD92 Output character to screen

Submitted by Steve Fewell

Description:

There are various routines which output to the screen. Here is the main one used when printing to the screen.

If called from &BD8F then routine &BD6C is executed before contining to &BD92.

&BD6C outputs the 2-digit Hexadecimal number (stored in A), as follows:
Store A to the Stack.
Divide A by 16 (to move the top 4-bits of the byte to the lower half, and clearing the top 4-bits).
Call routine &BD77 to output the upper Hex digit as follows:
  * Add #&06 to A if A is greater than or equal to &0A.
  * Add #&30 to A (to turn A from a binary Hex digit to an ASCII character).
  * Store A to the stack.
  * If WIDTH (&23) is less than COUNT (&1E) then call &BA92 to output a new line.
  * Retrieve A from the stack.
  * Increment COUNT (&1E).
  * Jump to the Operating System's Write Character vector (&020E) to output the ASCII character in A.

Retrieve A from the Stack (now A = the original value of A when the routine was entered).
AND A with #&0F to clear the top 4-bits (as the Hex character these represent has already been output).
Continue to routine &BD77, which outputs the lower Hex digit as follows:
  * Add #&06 to A if A is greater than or equal to &0A.
  * Add #&30 to A (to turn A from a binary Hex digit to an ASCII character).
  * Store A to the stack.
  * If WIDTH (&23) is less than COUNT (&1E) then call &BA92 to output a new line.
  * Retrieve A from the stack.
  * Increment COUNT (&1E).
  * Jump to the Operating System's Write Character vector (&020E) to output the ASCII character in A.
If called from &BD92 then Set A to #&20 (Space character). This forces the character to output to be a space.

&BD94 Overview. This routine 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>')
If called from &BD94 then Check whether &1F (LISTO Flag) is negative (indicating '*EDIT' mode), if it is then
goto &BDA2; otherwise, con tinue to &BD98. In '*EDIT' mode any output to the screen is instead redirected to memory so
that '*EDIT' can pickup the text (program listing) and allow the user to edit it. If we are not in '*EDIT' mode then continue
to &BD98. &BDA2 stores the ASCII code in A to VARTOP (the memory location pointed to by (&02, &03)),
and then increments VARTOP LSB (&02). If the VARTOP LSB (&02) doesn't overflow then exit;
otherwise, increment &03 also, and do the following check (storing A temporarily to the stack while it is done): If VARTOP
MSB byte (&03) = HIMEM MSB byte (&07), goto &BD31 to call the BASIC Initialise routine (to reset, VARTOP, LOMEM,
HIMEM, etc...) & generate a 'No Room' error. Otherwise, exit the output routine (as we are not out of memory for '*EDIT' data).

If called from &BD98 and the ASCII character to output (in A) is #&0D (Carriage return) then send the character
to the screen (JSR &FFEE), zero COUNT (&1E) and exit.
Otherwise (&BD7F):
* Store the character on the stack.
* If WIDTH (&23) is less than COUNT (&1E) then call &BA92 to output a new line.
* Retrieve A from the stack.
* Increment COUNT (&1E).
* Jump to the Operating System's Write Character vector (&020E) to output the ASCII character in A to the screen.
* Exit the output routine.

BDB3 routine

If called from &BDB3 then the following is done:
Clear carry flag.
AND A with &1F to clear the top 3 bits.
If A now contains zero then exit.
If X is negative (top bit set) then exit.
Multiply X by 2 (shift the bits left 1 position).
If X is now zero then exit.
continue to &BDBF to output X number of spaces.
[&BDBF] Output X number of Spaces, as follows:
[&BDBF] Call routine &BD92 to output a space.
Decrement X.
if X is still positive then jump back to &BDBF.
Exit.
Note: Line breaks are automatically made as needed (as X can be a maximum of 255).


Disassembly for the Output Character to screen routine

BD6C H 072 48 PHA
BD6D J 074 4A LSR A
BD6E J 074 4A LSR A
BD6F J 074 4A LSR A
BD70 J 074 4A LSR A
BD71 w 032 119 189 20 77 BD JSR &BD77
BD74 h 104 68 PLA
BD75 ) 041 015 29 0F AND#&0F
BD77   201 010 C9 0A CMP#&0A
BD79   144 002 90 02 BCC 2 --> &BD7D
BD7B i 105 006 69 06 ADC#&06
BD7D i0 105 048 69 30 ADC#&30
BD7F H 072 48 PHA
BD80 # 165 035 A5 23 LDA &23
BD82   197 030 C5 1E CMP &1E
BD84   176 003 B0 03 BCS 3 --> &BD89
BD86   032 146 186 20 92 BA JSR &BA92
BD89 h 104 68 PLA
BD8A   230 030 E6 1E INC &1E
BD8C l 108 014 002 6C 0E 02 JMP (&020E) WRCHV (OS Write Character vector)
BD8F l 032 108 189 20 6C BD JSR &BD6C
BD92   169 032 A9 20 LDA#&20
BD94 $ 036 031 24 1F BIT &1F
BD96 0 048 010 30 0A BMI 10 --> &BDA2
BD98   201 013 C9 0D CMP#&0D
BD9A   208 227 D0 E3 BNE -29 --> &BD7F
BD9C   032 238 255 20 EE FF JSR &FFEE OSWRCH (Output the <cr> character to the screen)
BD9F L 076 149 186 4C 95 BA JMP &BA95 Zero COUNT (&1E) and exit routine
BDA2   146 002 92 02 STA (&02)
BDA4   230 002 E6 02 INC &02
BDA6   208 029 D0 1D BNE 29 --> &BDC5
BDA8   230 003 E6 03 INC &03
BDAA H 072 48 PHA
BDAB   165 003 A5 03 LDA &03
BDAD E 069 007 45 07 EOR &07
BDAF   240 128 F0 80 BEQ -128 --> &BD31 Initialise page &7 etc... and generate 'No room' error
BDB1 h 104 68 PLA
BDB2 ` 096 60 RTS
BDB3   024 18 CLC
BDB4 037 031 25 1F AND &1F
BDB6   240 013 F0 0D BEQ 13 --> &BDC5
BDB8   138 8A TXA
BDB9 0 048 010 30 0A BMI 10 --> &BDC5
BDBB * 042 2A ROL A
BDBC   170 AA TAX
BDBD   240 006 F0 06 BEQ 6 --> &BDC5
BDBF   032 146 189 20 92 BD JSR &BD92 Output a Space
BDC2   202 CA DEX
BDC3   208 250 D0 FA BNE -6 --> &BDBF
BDC5 ` 096 60 RTS

Initialise page &7 (etc...) and generate 'No room' error

BD31   032 172 187 20 AC BB JSR &BBAC Initialise Page 7 & reset Variable pointers, etc...
BD34 L 076 161 144 4C A1 90 JMP &90A1 No room error

 


 Back to 8BS
Or