BBC Micro Advanced User Guide
BBC Micro Advanced User Guide
USER GUIDE
FOR THE BBC MICRO
Andrew C. Bray,
St. Catharines College,
Dept. of Computer Science,
Cambridge University
Adrian C. Dickens,
Churchill College,
Dept. of Engineering,
Cambridge University
3
Hardware
Appendices
Bibliography 491
Glossary 493
Index 499
4
Introduction
The ‘Advanced User Guide for the BBC Microcomputer’ has
been designed to be an invaluable supplement to the User
Guide. Information already contained in the User Guide is
only repeated in this book in sections which contain much
new information and where omitting the duplicated details
would have left the section incomplete. Some parts of the
User Guide are factually inaccurate or incomplete and where
details in this book are at variance with corresponding
information in the User Guide the reader will find that a more
accurate description is usually found in these pages.
While this book gives the programmer full access to all the
BBC microcomputer’s extensive software and hardware
facilities using techniques which the designers of the machine
5
intended programmers to use, it also opens the door to a
multitude of ‘illegal’ programming techniques. For the
enthusiast, direct access to operating system variables or chip
registers may enable him to perform the bizarre or even the
merely curious. For the serious programmer, on the other
hand, attention to compatibility and machine standards will
enable him to write software which will run on BBC
Microcomputers of all configurations. The responsibility rests
with YOU, the user. The value of your machine depends on
continued software support of the highest quality; unlike
many machines the BBC microcomputer has been designed to
be used in a variety of different configurations and the
operating system software provides extensive information
about the current hardware and software status. The
operating system makes most of the allowances required for
the different configurations automatically, but only when the
legal techniques are adhered to, so please use them.
6
1 Introduction for those
new to machine code
There comes a time in every programmer’s life (well, most
programmers’, anyway) when the constraints of a high level
language (e.g. BASIC) prevents him from implementing a
particular program idea or from utilising some machine
facility. At this stage the programmer must often seek
recourse to the microprocessor’s native language, its machine
code.
7
arithmetic is available; there are no multiply or divide
instructions. There are no automatic loop structures such as
FOR…NEXT or REPEAT…UNTIL and any loops must be
explicitly set up by the programmer using conditional
branches (these approximate to IF … THEN GOTO … in
BASIC). The range of instructions available are sufficient to
enable extremely complex programs to be written, but a lot
more effort is required to implement the program. One of the
most grave disadvantages of machine code is that very little
error checking is made available to the programmer. A well
designed assembler will help the programmer, but once the
machine code program is running the only error checking is
that which is provided within the program itself.
8
great advantage of this independence of the language
program from the direct use of hardware is that the same
facilities can be offered to different languages.
9
10
2 Operating System
commands
The command-line interpreter resident within the operating
system will recognise a number of commands and act
appropriately upon receiving them. These commands are most
often used from the keyboard or in BASIC programs using the
‘*’ prefix. Commands may also be passed to the command-line
interpreter using the OSCLI call (&FFF7) from machine code
(see section 7.12 for details of OSCLI).
11
A number of commands are filing system dependent. Any
command which creates or uses files is described for the ROM
and cassette filing systems only.
2.1 *|
2.2 *.
12
2.5 *CAT (*.)
FILENAME 09 0904
13
For example:
10 DIM MC% 100
20 OSASCI=&FFE3
30 USERV=&200
40 FOR opt%=0 TO 3 STEP3
50 P%=MC%
60 [
70 OPT opt%
80 .write
90 CMP #0 \ is this *CODE ?
100 BEQ code \ if *CODE call act upon it
110 BRK \ anything else, print error message
120 ]
130 ?P%=255 : P%=P%+1 : REM error number
140 $P%="*CODE only please"
150 P%=P%+LEN$P%
160 [
170 OPT opt% \ reset OPT
180 BRK \ op code value=0
190 .code TXA \ transfer contents of X reg. to Acc.
200 JSR OSASCI \ print ASCII character
210 RTS \ return to BASIC
220 ]
230 NEXT
240 ?USERV=write MOD 256
250 ?(USERV+1)=write DIV 256
Text files from the currently selected filing system can be used
as if they were keyboard input using this command. A typical
application might involve the setting up of a user’s favourite
soft key definitions which are *EXECed in at the beginning of
a programming session.
14
2.8 *FXa,x,y (*F.)
OS 1.20
*HELP VIEW
*HELP UTILS
The ten red-topped function keys, the BREAK key, the COPY
key and the four cursor control keys may be set up using this
command. Using *KEYn with n in the range 0 to 9 sets up the
function keys. *KEY10 can be used to program the BREAK
key. Before the remaining programmable keys can be used a
*FX4,2 must be performed. This disables cursor editing and
enables the following soft keys:–
*KEY 11 COPY
15
*KEY 12 left cursor
*KEY 13 right cursor
*KEY 14 down cursor
*KEY 15 up cursor
16
an easy method of incorporating a user function into the
operating system command table.
10 DIM MC% 100
20 OSASCI=&FFE3
30 USERV=&200
40 FOR opt%=0 TO 3 STEP3
50 P%=MC%
60 [
70 OPT opt%
80 .write
90 CMP #1 \ is this *LINE?
100 BEQ code \ execute machine code if *LINE
110 BRK \ otherwise print out error message
120 ]
130 ?P%=255 : P%=P%+1 : REM error number
140 $P%="*LINE only please"
150 P%=P%+LEN$P%
160 [
170 OPT opt% \ reset OPT
180 BRK \ op code value 0
190 .code STX &70 \ *LINE code entry point and store
200 STY &71 \ string address; low-byte,high-byte
210 LDY #0 \ set up Y register for indexing
220 .loop LDA (&70),Y \ Post-Indexed Indirect addressing
230 JSR OSASCI \ print out character
240 INY \ increment index
250 CMP #&0D \ test for end of string
260 BNE loop \ if not last character go round again
270 RTS \ finished
280 ]
290 NEXT
300 ?USERV=write MOD 256
310 ?(USERV+1)=write DIV 256
17
2.12 *LOAD<filename><address> (*L.)
This command executed with n=0 opens the cassette relay (i.e.
switches the motor off) and with n=1 closes the cassette relay
(i.e. motor on).
file name – block no. – file length – start adr. – execution adr.
18
2.15 *ROM (RO.) OSBYTE with A=&8D (141)
+length
19
2.18 *SPOOL <filename> (*SP.)
20
3 The BASIC Assembler
One of the many attractive features of BBC BASIC is the
incorporation of a mnemonic assembler within the language
itself. This provides a powerful environment for the assembler
and allows machine code to be easily incorporated within
BASIC programs. Hybrid BASIC/machine code programs may
often lead to the use of the best features of each language, the
speed of machine code when it is required, coupled with the
increased power of BASIC when speed is not of paramount
importance.
10 OSWRCH=&FFEE
20 DIM MC% 100
25 DIM data &20
30 FOR opt%=0 TO 3 STEP 3
40 P%=MC%
50 [
60 OPT opt%
70 .entry LDX #0 \ set index count (in X reg.) to 0
75 LDA data \ load first item in accumulator
80 .loop JSR OSWRCH \ perform VDU command
90 INX \ increment index count
100 LDA data,X \ load next VDU parameter
110 CPX #&20 \ has count reached 32 (&20) ?
120 BNE loop \ if not then go round again
130 RTS \ back to BASIC
140 ]
150 NEXT opt%
160 !data=&04190516
170 data!4=&00C800C8
180 data!8=&00000119
190 data!&C=&01190064
200 data!&10=&000000C8
210 data!&14=&00000119
220 data!&18=&0119FF9C
230 data!&1C=&0000FF38
240 CALL entry
21
This program performs some simple graphics using the
BASIC VDU method to select the screen MODE and perform
PLOTting. All the VDU codes are contained within the block
of memory labelled ‘data’. Using the operator does not make
it immediately obvious what is going on. Four bytes are
inserted into memory with each ! operator. The least
significant byte being inserted at the address specified. Each
subsequent byte is inserted into the next byte of memory.
i.e.
!data=&04190416
data!4=&00C800C8
VDU &16,&04
VDU &19,&04,&00C8;&00C8;
or
22
Within the assembler delimiters the text of the assembly
language program may be written. The assembly language
program will consist of a number of assembler statements
separated by new lines or colons (as in BASIC).
location label/mnemonic/address
op.code/data \ comment
23
3.2 OPT, assembler option selection
24
3.3 The Location Counter P%
3.4 Labels
25
which the processor is to jump. When assembling the
machine code, the assembler works sequentially through the
program and in the case of a forward reference the assembler
will encounter the reference before the label. In the normal
course of events an error will be flagged (No such variable).
In order to resolve forward references, two passes of the
assembler are required. The first pass should be performed
with error trapping switched off and during this pass all the
labels will be initialised. A second pass will provide all the
correct values required for forward referencing. During this
second pass error trapping should be enabled to pick up any
genuine programming mistakes.
26
The example program, written in Level 2 BASIC, could have
been written with lines 30 and 170 to 240 replaced with:–
141 .data EQUD &04190516
142 EQUD &00C800C8
143 EQUD &00000119
144 EQUD &01190064
145 EQUD &000000C8
146 EQUD &00000119
147 EQUD &0119FF9C
148 EQUD &0000FF38
In Level 1 BASIC one way to reserve space for data within the
body of a machine code program is to leave the assembler
using a right-hand square bracket and insert the data using
the address contained in P%. P% should then be incremented
by the appropriate amount before entering the assembler.
27
3.7 Handling errors with BRK
The user can provide his own BRK handling routine which
may be useful when using machine code away from the
BASIC environment (see section 10.2 for more information
about the BRK vector).
28
CALL statement is used, the addresses and data types of
these parameters being available to the machine code in a
parameter block at location &600. The USR function allows the
machine code routine to return a value to the BASIC program
made up from the register contents. For more details of CALL
and USR refer to the ‘USER GUIDE’.
e.g.
10 DIM MC% 100
20 FOR opt%=0 TO 3 STEP 3
30 P%=MC%
40 [
50 OPT opt%
60 .add CLC \ clear carry
70 LDA &80 \ A=?&80
80 ADC &81 \ A=A+?&81+carry
90 STA &81 \ ?&81=A
100 OPT FNdebug(TRUE)
110 ]
120 NEXT
130 ?&80=1
29
140 ?&81=2
150 CALL add
160 PRINT'"Result of addition : ";?&81
170 PRINT'"A=&";~?&70,"X=&";~?&71,"Y=&";~?&72
180 END
190 DEF FNdebug(switch)
200 IF switch [OPT opt%:STA &70:STX &71:STY &72 \ save registers:]
210 [OPT opt%:RTS:]
220 =opt%
The locations from &0 to &6F which are part of BASIC’s zero
page workspace are available to the machine code program if
BASIC is not required while the code is running.
30
4 Machine Code Arithmetic
4.1 2’s Complement
and −5 + 5
11111011 −5
00000101 +5
31
The 6502 microprocessor can only perform its arithmetic
operations using 8 bit values. This limitation can lead to errors
when a carry is generated on the most significant bit so that
the result cannot be stored in 8 bits. The sign bit may also be
wrongly changed when a carry occurs into it. Two flags in the
status register are set when certain conditions occur. These
flags are the carry flag and the overflow flag.
The overflow flag is set when the sign of the result is incorrect
following an arithmetic operation. During additions overflow
will occur in two situations :–
(a) When a carry occurs from bit 6 into bit 7 without the
generation of an external carry.
32
negative values. The overflow and carry flags will also be set
as described above.
33
400 ]
410 NEXT
420 !&80=0
430 PRINT''"Binary Coded Decimal"''
440 PRINT"press key to add 1"
450 PRINT"press RETURN to exit"''
460 CALL start
34
5 Addressing Modes
When an assembly language instruction needs some data or
an address to work on this must be provided in the operand
field of the assembler statement. Although there are a limited
number of different machine code instructions which can be
used with the 6502, the power of the instruction set is
enhanced by a number of different addressing modes by
which the data or addresses used by each instruction may be
provided. The addressing mode used by the assembler
depends on the syntax of the assembly language statement.
The following text describes how the different addressing
modes work and the assembler syntax which is necessary.
e.g.
ASL A \ shift accumulator contents one bit left
ROR A \ rotate accumulator contents one bit right
35
5.3 Immediate addressing – using a data constant
e.g.
LDA #&FF \ load the accumulator with value &FF
LDX *count \ load X with value of the constant 'count'
e.g.
CMP &1900 \ compare A with contents of location &1900
JMP label \ goto address specified by 'label'
e.g.
CPY &80 \ compare y with contents of location &80
ASL &81 \ shift left contents of location &81 one bit
36
5.6 Indirect addressing – using an address stored in memory
i.e. JMP (&19FF) will use the contents of &19FF and &1900 for
the JMP address.
Indexed Addressing
37
The X and Y register contents are always taken as positive
values in the range 0 to 255 and so only forward offsets are
available (c.f. Relative addressing, below).
e.g.
LDA &2800,X \ load accumulator from &2800+X
ADC table,Y \ A=A+?(table+Y)
e.g.
LDX &72,Y \ load X with contents of (&72+Y)
LSR &80,X \ one bit right shift contents of (&80+X)
38
N.B. The Y register cannot be used for this addressing mode.
e.g.
?&80=&00
?&81=&40
?&82=&00
?&83=&41
LDX #0 \ set X to 0
LDA (&80,X) \ A=?&4000, address in (&80+X),(&81+X)
INX \ X=X+1, i.e. 1
INX \ X=X+1
LDA (&80,X) \ A=?&4100, address in (&82),(&83)
e.g.
39
5.11 Relative addressing
40
6 The 6502 Instruction Set
6.1 The 6502 registers and abbreviations
Accumulator – A
X Index Register – X
Y Index Register – Y
Status Register
Carry flag – C
Zero flag – Z
Interrupt disable – I
41
Decimal mode flag – D
Break flag – B
Unused flag
Overflow flag – V
Negative flag – N
Stack Pointer – SP
42
6.2 The Assembler Mnemonics
All the available addressing modes are listed together with the
number of bytes of memory which the instruction and its data
will occupy when this mode is used. The number of
instruction cycles taken for the execution of the instruction in
each addressing mode is also given (1 instruction cycle = 0.5
microseconds).
43
ADC
Add with carry A,C=A+M+C
immediate 2 2
zero page 2 3
zero page,X 2 4
absolute 3 4
absolute,X 3 4 (+1 if page crossed)
absolute,Y 3 4 (+1 if page crossed)
(indirect,X) 2 6
(indirect),Y 2 5 (+1 if page crossed)
44
AND
Logical AND A=A AND M
immediate 2 2
zero page 2 3
zero page,X 2 4
absolute 3 4
absolute,X 3 4 (+1 if page crossed)
absolute,Y 3 4 (+1 if page crossed)
(indirect,X) 2 6
(indirect),Y 2 5 (+1 if page crossed)
45
ASL
Arithmetic shift left M=M*2, C=M7 (or accumulator)
Cf 76543210 f0
accumulator 1 2
zero page 2 5
zero page,X 2 6
absolute 3 6
absolute,X 3 7
46
BCC
Branch on carry clear Branch if C=0
47
BCS
Branch on carry set Branch if C=1
A relative branch will occur if the carry flag is set. The branch
address given to the assembler must be within relative
addressing range.
48
BEQ
Branch on result zero Branch if Z=1
49
BIT
Test memory bits with accumulator A AND M, N=M7,
V=M6
zero page 2 3
absolute 3 4
50
BMI
Branch if negative flag set Branch if N=1
51
BNE
Branch on result not zero Branch if Z=0
52
BPL
Branch on positive result Branch if N=0
53
BRK
Forced interrupt PC and P pushed on stack
PCL=?&FFFE, PCH=?&FFFF
implied 1 7
54
BVC
Branch if overflow clear Branch if V=0
55
BVS
Branch if overflow set Branch if V=1
56
CLC
Clear carry flag C=0
implied 1 2
57
CLD
Clear decimal flag D=0
This flag is used to place the 6502 into decimal mode. This
instruction returns the processor into non-decimal mode.
implied 1 2
58
CLI
Clear interrupt disable flag I=0
implied 1 2
59
CLV
Clear overflow flag V=0
implied 1 2
60
CMP
Compare memory and accumulator A–M
immediate 2 2
zero page 2 3
zero page,X 2 4
absolute 3 4
absolute,X 3 4 (+1 if page crossed)
absolute,Y 3 4 (+1 if page crossed)
(indirect,X) 2 6
(indirect),Y 2 5 (+1 if page crossed)
61
A>=M or M<=A BCS somewhere
62
CPX
Compare memory with X register X–M
immediate 2 2
zero page 2 3
absolute 3 4
63
CPY
Compare memory with Y register Y–M
immediate 2 2
zero page 2 3
absolute 3 4
64
DEC
Decrement memory by one M=M–1
zero page 2 5
zero page,X 2 6
absolute 3 6
absolute,X 3 7
65
DEX
Decrement X register by one X=X–1
implied 1 2
66
DEY
Decrement Y register by one Y=Y–1
implied 1 2
67
EOR
Exclusive OR memory with accumulator A=A EOR M
immediate 2 2
zero page 2 3
zero page,X 2 4
absolute 3 4
absolute,X 3 4 (+1 if page crossed)
absolute,Y 3 4 (+1 if page crossed)
(indirect,X) 2 6
(indirect),Y 2 5 (+1 if page crossed)
68
INC
Increment memory by one M=M+1
zero page 2 5
zero page,X 2 6
absolute 3 6
absolute,X 3 7
69
INX
Increment X register by one X=X+1
implied 1 2
70
INY
Increment Y register by one Y=Y+1
implied 1 2
71
JMP
Jump to new location PC=new address
absolute 3 3
indirect 3 5
72
JSR
Jump to subroutine Push current PC onto stack;
PC=new address
absolute 3 6
73
LDA
Load accumulator from memory A=M
immediate 2 2
zero page 2 3
zero page,X 2 4
absolute 3 4
absolute,X 3 4 (+1 if page crossed)
absolute,Y 3 4 (+1 if page crossed)
(indirect,X) 2 6
(indirect),Y 2 5 (+1 if page crossed)
74
LDX
Load X register from memory X=M
immediate 2 2
zero page 2 3
zero page,Y 2 4
absolute 3 4
absolute,Y 3 4 (+1 if page crossed)
75
LDY
Load Y register from memory Y=M
immediate 2 2
zero page 2 3
zero page,X 2 4
absolute 3 4
absolute,X 3 4 (+1 if page crossed)
76
LSR
Logical shift right by one bit M=M/2 (or accumulator)
0g 76543210 gC
accumulator 1 2
zero page 2 5
zero page,X 2 6
absolute 3 6
absolute,X 3 7
77
NOP
No operation
implied 1 2
78
ORA
OR memory with accumulator A=A OR M
immediate 2 2
zero page 2 3
zero page,X 2 4
absolute 3 4
absolute,X 3 4 (+1 if page crossed)
absolute,Y 3 4 (+1 if page crossed)
(indirect,X) 2 6
(indirect), Y 2 5 (+1 if page crossed)
79
PHA
Push accumulator onto stack Push A
implied 1 3
80
PHP
Push status register onto stack Push P
implied 1 3
81
PLA
Pull accumulator off stack Pull A
implied 1 4
82
PLP
Pull status register off stack Pull P
implied 1 4
83
ROL
Rotate one bit left M=M*2, M0=C, C=M7 (A or M)
This instruction causes a shift left one bit. The bit shifted out
of the byte, bit 7, is placed in the carry flag. The contents of
the carry flag are placed in bit 0.
76543210 fCf
accumulator 1 2
zero page 2 5
zero page,X 2 6
absolute 3 6
absolute,X 3 7
84
ROR
Rotate one bit right M=M/2, M7=C, C=M0 (A or M)
This instruction causes a shift right one bit. The bit shifted out
of the location, bit 0 is placed in the carry flag. The contents of
the carry flag are placed in bit 7.
g 76543210 gC
accumulator 1 2
zero page 2 5
zero page,X 2 6
absolute 3 6
absolute,X 3 7
85
RTI
Return from interrupt Status register and PC pulled
from stack
implied 1 6
86
RTS
Return from subroutine Pull PC from stack
implied 1 6
87
SBC
Subtract memory from accumulator with carry
A,C=A–M–(1–C)
immediate 2 2
zero page 2 3
zero page,X 2 4
absolute 3 4
absolute,X 3 4 (+1 if page crossed)
absolute,Y 3 4 (+1 if page crossed)
(indirect,X) 2 6
(indirect), Y 2 5 (+1 if page crossed)
88
SEC
Set carry flag C=1
implied 1 2
89
SED
Set decimal mode D=1
implied 1 2
90
SEI
Set interrupt disable flag I=1
implied 1 2
91
STA
Store accumulator contents in memory M=A
zero page 2 3
zero page,X 2 4
absolute 3 4
absolute,X 3 5
absolute,Y 3 5
(indirect,X) 2 6
(indirect),Y 2 6
92
STX
Store X contents in memory M=X
zero page 2 3
zero page,Y 2 4
absolute 3 4
93
STY
Store Y contents in memory M=Y
zero page 2 3
zero page,X 2 4
absolute 3 4
94
TAX
Transfer A to X X=A
implied 1 2
95
TAY
Transfer A to Y Y=A
implied 1 2
96
TSX
Transfer S to X X=S
implied 1 2
97
TXA
Transfer X to A A=X
implied 1 2
98
TXS
Transfer X to S S=X
implied 1 2
99
TYA
Transfer Y to A A=Y
implied 1 2
100
7 Operating System calls
Input/Output
101
7.2 Non-Vectored OSWRCH
102
7.4 Non vectored OSRDCH
103
7.6 OSASCI Write character routine where OSNEWL is
called when A=&0D (13).
Call address &FFE3
Not indirected
104
7.8 GSINIT General string input initialise routine.
Call address &FFC2
If the carry flag is clear on entry then the first space or carriage
return or second quotation mark will be considered as the
terminating character for the string.
On exit,
Y contains the offset of the first non-blank character from
the address contained in &F2 and &F3.
This routine has not been documented by Acorn but has been
used in applications software.
105
7.9 GSREAD Read character from string input.
Call address &FFC5
On exit,
A contains the character read from the string.
Y contains the index for the next character to be read.
Carry flag is set if the end of string is reached.
X is preserved.
This routine has not been documented by Acorn but has been
used in applications software.
On entry,
Y=ROM number.
Locations &F6 and &F7 should contain the address of the
byte to be read.
On exit,
A contains the value of the byte read.
This routine has not been documented by Acorn but has been
used in applications software.
106
7.11 OSEVEN Generate an event.
Call address &FFBF
On entry,
X and Y should point to a line of text
(X= low-byte, Y= high-byte).
The line of text should be terminated by a carriage return
character (ASCII &0D/13)
107
108
8 *FX and OSBYTE calls
The OSBYTE call to the operating system is a powerful and
flexible way of invoking many of the available operating
system facilities. The *FX command can be used to make
OSBYTE calls from BASIC programs or directly from the
keyboard (see section 2.8).
On entry,
A selects an OSBYTE routine
X contains an OSBYTE parameter
Y contains an OSBYTE parameter
109
OSBYTE calls &A6/166 to &FF/255 can be used to read or write
operating system status flags or variables. In OS 1.20 these
memory locations extend from &236 to &28F. The action of
these calls is to replace the contents of the specified location
with
On exit,
X=old value, Y=value of next location
110
OSBYTE/*FX Call Summary
dec. hex. Function
111
128 80 Read ADC channel or get buffer status
129 81 Read key with time limit
130 82 Read machine high order address
131 83 Read top of OS RAM address (OSHWM)
132 84 Read bottom of display RAM address (HIMEM)
133 85 Read bottom of display address for a given
MODE
134 86 Read text cursor position (POS and VPOS)
135 87 Read character at cursor position
136 88 Perform *CODE
137 89 Perform *MOTOR
138 8A Insert value into buffer
139 8B Perform *OPT
140 8C Perform *TAPE
141 8D Perform *ROM
142 8E Enter language ROM
143 8F Issue paged ROM service request
144 90 Perform *TV
145 91 Get character from buffer
146 92 Read from FRED, 1 MHz bus
147 93 Write to FRED, 1 MHz bus
148 94 Read from JIM, 1 MHz bus
149 95 Write to JIM, 1 MHz bus
150 96 Read from SHEILA, mapped I/O
151 97 Write to SHEILA, mapped I/O
152 98 Examine buffer status
153 99 Insert character into input buffer
154 9A Write to video ULA control register and copy
155 9B Write to video ULA palette register and copy
156 9C Read/write 6850 control register and copy
157 9D Fast Tube BPUT
158 9E Read from speech processor
159 9F Write to speech processor
160 A0 Read VDU variable value
112
170 AA Read address of ROM information table (low
byte)
171 AB Read address of ROM information table (high
byte)
172 AC Read address of key translation table (low byte)
173 AD Read address of key translation table (high
byte)
174 AE Read start address of OS VDU variables (low
byte)
175 AF Read start address of OS VDU variables (high
byte)
176 B0 Read/write CFS timeout counter
177 B1 Read/write input source
178 B2 Read/write keyboard semaphore
179 B3 Read/write primary OSHWM
180 B4 Read/write current OSHWM
181 B5 Read/write RS423 mode
182 B6 Read character definition explosion state
183 B7 Read/write cassette/ROM filing system switch
184 B8 Read RAM copy of video ULA control register
185 B9 Read RAM copy of video ULA palette register
186 BA Read/write ROM number active at last BRK
(error)
187 BB Read/write number of ROM socket containing
BASIC
188 BC Read current ADC channel
189 BD Read/write maximum ADC channel number
190 BE Read/write ADC conversion type
191 BF Read/write RS423 use flag
192 C0 Read RS423 control flag
193 C1 Read/write flash counter
194 C2 Read/write mark period count
195 C3 Read/write space period count
196 C4 Read/write keyboard auto-repeat delay
197 C5 Read/write keyboard auto-repeat period
198 C6 Read/write *EXEC file handle
199 C7 Read/write *SPOOL file handle
200 C8 Read/write ESCAPE, BREAK effect
201 C9 Read/write Econet keyboard disable
202 CA Read/write keyboard status byte
203 CB Read/write RS423 handshake extent
204 CC Read/write RS423 input suppression flag
113
205 CD Read/write cassette/RS423 selection flag
206 CE Read/write Econet OS call interception status
207 CF Read/write Econet OSRDCH interception status
208 D0 Read/write Econet OSWRCH interception status
209 D1 Read/write speech suppression status
210 D2 Read/write sound suppression status
211 D3 Read/write BELL channel
212 D4 Read/write BELL envelope number/amplitude
213 D5 Read/write BELL frequency
214 D6 Read/write BELL duration
215 D7 Read/write startup message and !BOOT options
216 D8 Read/write length of soft key string
217 D9 Read/write number of lines printed since last
page
218 DA Read/write number of items in VDU queue
219 DB Read/write TAB character value
220 DC Read/write ESCAPE character value
221 DD Read/write character &C0 to &CF status
222 DE Read/write character &D0 to &DF status
223 DF Read/write character &E0 to &EF status
224 E0 Read/write character &F0 to &FF status
225 E1 Read/write function key status
226 E2 Read/write SHIFT+function key status
227 E3 Read/write CTRL+function key status
228 E4 Read/write CTRL+SHIFT+function key status
229 E5 Read/write ESCAPE key status
230 E6 Read/write flags determining ESCAPE effects
231 E7 Read/write IRQ bit mask for user 6522
232 E8 Read/write IRQ bit mask for 6850
233 E9 Read/write IRQ bit mask for system 6522
234 EA Read flag indicating Tube presence
235 EB Read flag indicating speech processor presence
236 EC Read/write write character destination status
237 ED Read/write cursor editing status
238 EE Read/write location &27E, not used by OS 1.20
239 EF Read/write location &27F, not used by OS 1.20
240 F0 Read/write location &280, not used by OS 1.20
241 F1 Read/write location &281, used by *FX 1
242 F2 Read RAM copy of serial processor ULA
243 F3 Read/write timer switch state
244 F4 Read/write soft key consistency flag
245 F5 Read/write printer destination flag
114
246 F6 Read/write character ignored by printer
247 F7 Read/write first byte of BREAK intercept code
248 F8 Read/write second byte of BREAK intercept
code
249 F9 Read/write third byte of BREAK intercept code
250 FA Read/write location &28A, not used by OS 1.20
251 FB Read/write location &28B, not used by OS 1.20
252 FC Read/write current language ROM number
253 FD Read/write last BREAK type
254 FE Read/write available RAM
255 FF Read/write start up options
115
OSBYTE &00 (0) *FX 0
Identify Operating System version
Entry parameters:
X=0 Execute BRK with a message giving the O.S. type
X<>0 RTS with O.S. type returned in X
On exit,
X=0, OS 1.00
X=1, OS 1.20
A and Y are preserved
C is undefined
116
OSBYTE &01 (1) *FX 1
Read/write the user flag
On exit,
X=old value
This call uses OSBYTE call with A=&F1 (241). This OSBYTE
call is left free for user applications and is not used by the
operating system. The user flag is stored in location &281 and
its default value is 0.
117
OSBYTE &02 (2) *FX 2
Select input stream
On exit,
X=0 if previous input was from the keyboard
X=1 if previous input was from RS423
After call,
A is preserved
Y and C are undefined
118
OSBYTE &03 (3) *FX 3
Select output stream
After call,
A is preserved
X contains the old *FX 3 status
Y and C are undefined
119
OSBYTE &04 (4) *FX 4
Enable/disable cursor editing
COPY 11
LEFT 12
RIGHT 13
DOWN 14
UP 15
After call,
A is preserved
X contains the previous *FX 4 setting
Y and C are undefined
120
OSBYTE &05 (5) *FX 5
Select printer destination
After call,
A is preserved
X contains the previous *FX 5 setting
Y and C are undefined
Interrupts are enabled by this call
This call is not reset to default by a soft break
121
OSBYTE &06 (6) *FX 6
Set character ignored by printer
After call,
A is preserved
X contains the previous *FX 6 setting
Y and C are undefined
122
OSBYTE &07 (7) *FX 7
Set RS423 baud rate for receiving data
After call,
A is preserved
X and Y contain the old serial ULA register contents
C is undefined
123
OSBYTE &08 (8) *FX 8
Set RS423 baud rate for data transmission
After call,
A is preserved
X and Y contain the old serial ULA register contents
C is undefined
124
OSBYTE &09 (9) *FX 9
Set duration of the mark state of flashing colours (Duration
of first named colour)
After call,
A and X are preserved
Y contains the old mark duration
C is undefined
125
OSBYTE &0A (10) *FX 10
Set duration of the space state of flashing colours (Duration
of second named colour)
After call,
A and X are preserved
Y contains the old space duration
C is undefined
126
OSBYTE &0B (11) *FX 11
Set keyboard auto-repeat delay
After call,
A is preserved
X contains the old setting
Y and C are undefined
127
OSBYTE &0C (12) *FX 12
Set keyboard auto-repeat rate
After call
A is preserved
X contains the old *FX 12 setting
Y and C are undefined
128
OSBYTE &0D (13) *FX 13
Disable events
After call,
A is preserved
X and Y contain the old enable state (0=disabled)
C is undefined
129
OSBYTE &0E (14) *FX 14
Enable events
After call,
A is preserved
X and Y contain the old enable state (>0=enabled)
C is undefined
130
OSBYTE &0F (15) *FX 15
Flush selected buffer class
After call,
Buffer contents are discarded
A is preserved
X, Y and C are undefined
131
OSBYTE &10 (16) *FX 16
Select ADC channels which are to be sampled
After call,
A is preserved
X contains the old *FX 16 value
132
OSBYTE &11 (17) *FX 17
Force an ADC conversion
After call,
A is preserved
X is preserved if it is in the range 0 to 4 otherwise it is
returned containing the value 4
Y and C are undefined
133
OSBYTE &12 (18) *FX 18
Reset soft keys
No parameters
This call clears the soft key buffer so the character strings are
no longer available
After call,
A and Y are preserved
X and C are undefined
134
OSBYTE &13 (19) *FX 19
Wait for vertical sync
No parameters
This call forces the machine to wait until the start of the next
frame of the display. This occurs 50 times per second on the
UK BBC Microcomputer and can be used for timing or
animation.
N.B. User trapping of IRQ1 may stop this call from working.
After call,
A is preserved
X, Y and C are undefined
135
OSBYTE &14 (20) *FX 20
Explode soft character RAM allocation
136
ASCII code Memory allocation
after call,
A is preserved
X contains the new OSHWM (high byte)
Y and C are undefined
137
OSBYTE &15 (21) *FX 21
Flush specific buffer
See also OSBYTE calls with A=&0F (*FX15) and A=&80 (128)
After call,
A and X are preserved
Y and C are undefined
138
OSBYTE &75 (117)
Read VDU status
No entry parameters
After call,
A and Y are preserved
C is undefined
139
OSBYTE &76 (118)
Reflect keyboard status in keyboard LEDs
On exit,
A is preserved
X has bit 7 set if CTRL is pressed
Y is undefined
140
OSBYTE &77 (119) *FX 119
Close any SPOOL or EXEC files
This call closes any open files being used as *SPOOLed output
or *EXECed input to be closed. This call also performs a paged
ROM call with A=&10 (16). See paged ROM section, 15.1.1.
On exit,
A is preserved
X, Y and C are undefined
141
OSBYTE &78 (120) *FX 120
Write current keys pressed information
142
&20 32 f0 &60 96 TAB
&21 33 W &61 97 Z
&22 34 E &62 98 SPACE
&23 35 T &63 99 V
&24 36 7 &64 100 B
&25 37 I &65 101 M
&26 38 9 &66 102 ,
&27 39 0 &67 103 .
&28 40 _ &68 104 /
&29 41 DOWN CURSOR &69 105 COPY
&30 48 1 &70 112 ESCAPE
&31 49 2 &71 113 f1
&32 50 D &72 114 f2
&33 51 R &73 115 f3
&34 52 6 &74 116 f5
&35 53 U &75 117 f6
&36 54 O &76 118 f8
&37 55 P &77 119 f9
&38 56 [ &78 120 \
&39 57 UP CURSOR &79 121 RIGHT CURSOR
After call,
A, X and Y are preserved
C is undefined
143
OSBYTE &79 (121)
Keyboard scan
After call,
A is preserved
Y and C are undefined
144
OSBYTE &7A (122)
Keyboard scan from 16 decimal
No entry parameters
After call,
A is preserved
Y and C are undefined
145
OSBYTE &7B (123)
Inform operating system of printer driver going dormant
After call,
A, X and Y are preserved
C is undefined
146
OSBYTE &7C (124) *FX 124
Clear ESCAPE condition
No entry parameters
The ESCAPE flag is stored as the top bit of location &FF and
should never be interfered with directly.
After call,
A, X and Y are preserved
C is undefined
147
OSBYTE &7D (125) *FX 125
Set Escape condition
No entry parameters
After call,
A, X and Y are preserved
C is undefined
148
OSBYTE &7E (126) *FX 126
Acknowledge detection of an ESCAPE condition
No entry parameters
On exit,
X=&FF if the ESCAPE condition cleared
X=0 if the ESCAPE condition not cleared
After call,
A is preserved
Y and C are undefined
149
OSBYTE &7F (127)
Check for end-of-file on an opened file
On exit,
X<>0 if end-of-file has been reached
X=0 if end-of-file has not been reached
After call,
A and Y are preserved
C is undefined
150
OSBYTE &80 (128)
Read ADC channel (ADVAL) or get buffer status
On entry On exit
151
For input buffers X contains the number of
characters in the buffer and for output buffers the
number of spaces remaining.
After call,
A is preserved
C is undefined
On exit,
X=0 BBC Microcomputer OS 0.10
X=1 Acorn Electron OS 1.00
X=&FF BBC Microcomputer OS 1.00 or 1.20
X=&FE BBC Microcomputer OS A1.0 (USA)
X=&FD Master 128 OS 3.20 or 3.50
X=&FC BBC Microcomputer OS 1.20 (West Germany)
X=&FB BBC B+ OS 2.00
X=&FA Acorn Business Computer OS 1.00 or 2.00
X=&F7 Master Econet Terminal OS 4.00
X=&F5 Master Compact OS 5.10
After call,
A is preserved
C is undefined
152
OSBYTE &81 (129)
Read key with time limit (INKEY)
On exit,
If a character is detected, X=ASCII value of key pressed,
Y=0 and C=0.
If a character is not detected within timeout then Y=&FF
and C=1.
If Escape is pressed then Y=&1B (27) and C=1.
If called with Y=&FF and X=0 this call returns the machine
type (see previous page).
153
OSBYTE &82 (130)
Read machine high order address
No entry parameters
This call provides a 16 bit high order address for filing system
addresses which require 32 bits. As the BBC microcomputer
uses 16 bit addresses internally a padding value must be
provided which associates a given address to that machine.
After call,
A is preserved
C is undefined
154
OSBYTE &83 (131)
Read top of operating system RAM address (OSHWM)
No entry parameters
After call,
A is preserved
C is undefined
155
OSBYTE &84 (132)
Read bottom of display RAM address (HIMEM)
No entry parameters
A is preserved
C is undefined
156
OSBYTE &85 (133)
Read bottom of display RAM address for a specified mode
After call,
A is preserved
C is undefined
157
OSBYTE &86 (134)
Read text cursor position (POS and VPOS)
No entry parameters
On exit,
X contains horizontal position of the cursor (POS)
Y contains vertical position of the cursor (VPOS)
After call,
A is preserved
C is undefined
158
OSBYTE &87 (135)
Read character at text cursor position
No entry parameters
On exit,
X contains character value (0 if char. not recognised)
Y contains graphics MODE number
After call,
A is preserved
C is undefined
159
OSBYTE &88 (136) *FX 136
Execute code indirected via USERV (*CODE equivalent)
160
OSBYTE &89 (137) *FX 137
Switch cassette relay (*MOTOR equivalent)
Entry parameters:
X=0 relay off
X=1 relay on
The cassette filing system calls this routine with Y=0 for write
operations and Y=1 for read operations.
After call,
A is preserved
X, Y and C are undefined
161
OSBYTE &8A (138) *FX 138
Insert value into buffer
Entry parameters:
X identifies the buffer (See OSBYTE call with
A=&15/*FX21 for buffer numbers)
Y contains the value to be inserted into buffer
On exit,
C=0 if value successfully inserted
C=1 if value not inserted e.g. if buffer full
After call,
A is preserved
162
OSBYTE &8B (139) *FX 139
Select file options (*OPT equivalent)
Entry parameters:
X contains the option number
Y contains the option value required
After call,
A is preserved
C is undefined
163
OSBYTE &8C (140) *FX 140
Select tape filing system (*TAPE equivalent)
Entry parameters:
X=0 default baud rate (1200)
X=3 300 baud
X=12 1200 baud
After call,
A and Y are preserved
X and C are undefined
164
OSBYTE &8D (141) *FX 141
Select ROM filing system (*ROM equivalent)
No entry parameters
After call,
A is preserved
X, Y and C are undefined
165
OSBYTE &8E (142) *FX 142
Enter language ROM
166
OSBYTE &8F (143) *FX 143
Issue paged ROM service request
Entry parameters:
X=service type
Y=argument for service
On exit,
Y may contain return argument (if appropriate)
X=0 if a paged ROM claimed the service request
After call,
A is preserved
C is undefined
167
OSBYTE &90 (144) *FX 144
Alter display parameters (*TV equivalent)
Entry parameters:
X=vertical screen shift in lines
Y=0 interlace on
Y=1 interlace off
After call,
A and C are preserved
168
OSBYTE &91 (145)
Get character from buffer
Entry parameters:
X contains buffer number (see OSBYTE with A=&15/*FX
21 for buffer numbers)
On exit,
Y contains the extracted character.
If the buffer was empty then C=1 otherwise C=0.
After call,
A is preserved
169
OSBYTEs &92 to &97 (146 to 151) *FX 146 to 151
Read or Write to mapped I/O
Entry parameters:
X contains offset within page
Y contains byte to be written (if write)
On exit,
Read operations return with the value read in the Y
register
After call,
A is preserved
C is undefined
170
OSBYTE &98 (152)
Examine Buffer status
On exit,
If the buffer is not empty
Y=pointer to next character to be read from the buffer
indexed from zero page locations &FA and &FB.
C=0
After call,
A and X are preserved
171
OSBYTE &99 (153) *FX 153
Insert character into input buffer, checking for ESCAPE
Entry parameters:
X contains buffer number (0 or 1) and
Y contains the character value
After call,
A is preserved
X, Y and C are undefined
172
OSBYTE &9A (154) *FX 154
Write to video ULA control register and OS copy
This call writes to register 0 of the video ULA and also writes
the value in location &248 of the operating system’s
workspace. For details of the effects of writing to this register
see Video Hardware chapter 19.
This call also sets the flash counter (stored in location &251) to
the mark value (stored in &252).
After call,
A, X, Y and C are preserved
173
OSBYTE &9B (155) *FX 155
Write to video ULA palette register and OS copy
This call writes to register 1 of the video ULA and also stores a
copy of this value at location &249. The actual value written to
the register and the internal copy is X EOR 7. See chapter 19,
The Video ULA, for further details.
After call,
A, X, Y and C are preserved
174
OSBYTE &9C (156) *FX 156
Read/update 6850 ACIA control register and OS copy
After call,
A and Y are preserved
C is undefined
175
OSBYTE &9D (157) *FX 157
Fast Tube BPUT
After call,
A is preserved
X, Y and C are undefined
176
OSBYTE &9E (158)
Read from speech processor
No entry parameters
This call may be used to read data from the serial speech ROM
or to read the status register of the speech processor. In order
to read from the speech ROM a read byte command must have
previously been sent to the speech processor using OSBYTE
call with A=&9F/*FX 159. If the speech processor has not been
primed in this way then a copy of the speech processor’s
status register is returned in the Y register.
After call,
A is preserved
X and C are undefined
177
OSBYTE &9F (159) *FX 159
Write to speech processor
After call,
A is preserved
X, Y and C are undefined
178
OSBYTE &A0 (160)
Read VDU variable value
After call,
A is preserved
C is undefined
179
OSBYTEs &A6 (166) and &A7 (167)
Read start address of OS variables
This call returns the start address of the memory used by the
operating system to store its internal variables.
After call,
A is preserved
X=&90 and Y=&01
C is undefined
180
OSBYTEs &A8 (168) and &A9 (169)
Read address of ROM pointer table
On exit,
X=&9F (low byte)
Y=&0D (high byte)
i.e. address returned is &0D9F for OS 1.2
After call,
A is preserved
C is undefined
181
OSBYTEs &AA (170) and &AB (171)
Read address of ROM information table
On exit,
X=&A1
Y=&02
i.e. origin address, &02A1 for OS 1.20
After call,
A is preserved
C is undefined
182
OSBYTEs &AC (172) and &AD (173)
Read address of keyboard translation table
On exit,
X=&2B
Y=&F0
i.e. address is &F02B for OS 1.20
183
OSBYTEs &AE (174) and &AF (175)
Read VDU variables origin
This call returns with the address of the table of internal VDU
variables. See memory section, 11.4, for list of these.
On exit,
X=&00
Y=&03
i.e. address is &300 for OS 1.20
184
OSBYTE &B0 (176)
Read/write CFS timeout counter
185
OSBYTE &B1 (177) *FX 177
Read/write input source (equivalent to OSBYTE with A=2)
186
OSBYTE &B2 (178) *FX 178
Read/write keyboard semaphore
187
OSBYTE &B3 (179) *FX 179
Read/write primary OSHWM (for imploded font)
188
OSBYTE &B4 (180) *FX 180
Read/write OSHWM (equivalent to OSBYTE &83 (131) on
read)
189
OSBYTE &B5 (181) *FX 181
Read/write RS423 mode
190
OSBYTE &B6 (182)
Read character definition explosion state
191
OSBYTE &B7 (183) *FX 183
Read/write cassette/ROM filing system switch
192
OSBYTEs &B8 (184) and &B9 (185)
Read video processor ULA registers (OS copies only)
See OSBYTE calls with A=&9A and A=&9B and the Video
Hardware chapter 19.
The last value written to the ULA registers can be read using
this method.
193
OSBYTE &BA (186)
Read ROM number active at last BRK (error)
194
OSBYTE &BB (187)
Read number of ROM socket containing BASIC
195
OSBYTE &BC (188)
Read current ADC channel
196
OSBYTE &BD (189)
Read maximum ADC channel number
197
OSBYTE &BE (190)
Read/write ADC conversion type, 12 or 8 bits
198
OSBYTE &BF (191) *FX 191
Read/write RS423 use flag
199
OSBYTE &C0 (192)
Read RS423 control flag
200
OSBYTE &C1 (193) *FX 193
Read/write flash counter
201
OSBYTE &C4 (196) *FX 196
Read/write keyboard auto-repeat delay
202
OSBYTE &C6 (198) *FX 198
Read/write *EXEC file handle
203
OSBYTE &C7 (199) *FX 199
Read/write *SPOOL file handle
204
OSBYTE &C8 (200) *FX 200
Read/write ESCAPE, BREAK effect
205
OSBYTE &C9 (201) *FX 201
Read/write keyboard disable
206
OSBYTE &CA (202) *FX 202
Read/write keyboard status byte
207
OSBYTE &CB (203) *FX 203
Read/write RS423 handshake extent
208
OSBYTE &CC (204) *FX 204
Read/write RS423 input suppression flag
209
OSBYTE &CD (205) *FX 205
Read/write cassette/RS423 selection flag
210
OSBYTE &CE (206) *FX 206
Read/write Econet OS call interception status
211
OSBYTE &D1 (209) *FX 209
Read/write speech suppression status
212
OSBYTE &D2 (210) *FX 210
Read/write sound suppression status
213
OSBYTE &D3 (211) *FX 211
Read/write BELL (CTRL G) channel
Default value 3.
214
OSBYTE &D4 (212) *FX 212
Read/write BELL (CTRL G) SOUND information
e.g. Try *FX 212,216 for a softer BELL sound (amplitude −4).
215
OSBYTE &D5 (213) *FX 213
Read/write bell (CTRL G) frequency
216
OSBYTE &D6 (214) *FX 214
Read/write bell (CTRL G) duration
Default value 6.
217
OSBYTE &D7 (215) *FX 215
Read/write start up message suppression and !BOOT option
status
218
OSBYTE &D8 (216) *FX 216
Read/write length of soft key string
219
OSBYTE &D9 (217) *FX 217
Read/write number of lines since last halt in page mode
220
OSBYTE &DA (218) *FX 218
Read/write number of items in the VDU queue
221
OSBYTE &DB (219) *FX 219
Read/write character value returned by pressing TAB key
222
OSBYTE &DC (220) *FX 220
Read/write Escape character
e.g. *FX 220,32 will make the SPACE bar the ESCAPE key.
223
OSBYTEs &DD (221) to &E0 (224) *FX 221 to 224
Read/write input buffer code interpretation status
224
OSBYTE &E1 (225) *FX 225
Read/write function key status (soft keys or codes)
225
The default settings are:–
226
OSBYTE &E5 (229) *FX 229
Read/write status of ESCAPE key (escape action or ASCII
code)
If this location contains 0 then the ESCAPE key has its normal
action. Otherwise treat currently selected ESCAPE key as an
ASCII code.
227
OSBYTE &E6 (230) *FX 230
Read/write flags determining ESCAPE effects
228
OSBYTE &E7 (231) *FX 231
Read/write IRQ bit mask for the user 6522
229
OSBYTE &EA (234)
Read flag indicating Tube presence
230
OSBYTE &EB (235)
Read flag indicating speech processor presence
231
OSBYTE &EC (236) *FX 236
Read/write write character destination status
232
OSBYTE &ED (237) *FX 237
Read/write cursor editing status
233
OSBYTEs &EE (238), &EF (239) and &F0 (240)
Read/write location &27E, &27F and &280
234
OSBYTE &F1 (241) *FX 241
Read/write location &281
Default value 0.
235
OSBYTE &F2 (242)
Read copy of the serial processor ULA register
236
OSBYTE &F3 (243)
Read timer switch state
237
OSBYTE &F4 (244) *FX 244
Read/write soft key consistency flag
238
OSBYTE &F5 (245) *FX 245
Read/write printer destination flag
239
OSBYTE &F6 (246) *FX 246
Read/write character ignored by printer
240
OSBYTEs &F7 (247), &F8 (248) and &F9 (249)
Read/write BREAK intercept code
241
OSBYTEs &FA (250) and &FB (251) *FX 250 to 251
Read/write locations &28A and &28B
Default values 0.
242
OSBYTE &FC (252) *FX 252
Read/write current language ROM number
243
OSBYTE &FD (253)
Read hard/soft BREAK
244
OSBYTE &FE (254) *FX 254
Read/write available RAM
245
OSBYTE &FF (255) *FX 255
Read/write start up options
246
9 OSWORD calls
The OSWORD routines are a similar concept to the OSBYTE
routines except that instead of the parameters being passed in
the X and Y registers parameters are placed in a parameter
block, the address of which is sent to the OSWORD routine in
the X (low byte) and Y (high byte) registers.
On entry,
A selects an OSWORD routine.
X contains low byte of the parameter block address.
Y contains high byte of the parameter block address.
OSWORD summary
247
A=9 Read pixel value.
A=&A Read character definition.
A=&B Read palette value for a given logical colour.
A=&C Write palette value for a given logical colour.
A=&D Read previous and current graphics cursor positions.
On exit,
C=0 if a carriage return terminated input.
C=1 if an ESCAPE condition terminated input.
Y contains line length, including carriage return if used.
This routine may be used to read the system clock (used for
the TIME function in BASIC). The five byte clock value is
written to the address contained in the X and Y registers. This
clock is incremented every hundredth of a second and is set to
0 by a hard BREAK.
248
9.4 OSWORD call with A=&2 Write system clock
This routine may be used to set the system clock to a five byte
value contained in memory at the address contained in the X
and Y registers.
This routine may be used to read the interval timer (Used for
events, see chapter 12). The five byte clock value is written to
the address contained in the X and Y registers.
On exit,
The byte read will be contained in location XY+4.
249
9.9 OSWORD call with A=&7 SOUND command
This call has exactly the same effect as the SOUND command.
250
On exit,
XY+4 contains the logical colour at the point or &FF if the
point specified was off screen.
1 3 physical colour
2 0 padding for future expansion
3 0
4 0
251
9.14 OSWORD call with A=&C Write palette
252
10 Vectors
One of the features of the BBC microcomputer that greatly
enhances its power is the extensive use of VECTORS. A vector
is a word in memory containing the address of a service
routine. Many of the more important operating system
routines are indirected through vectors. The write character
routine, OSWRCH, uses a vector called WRCHV. Each time
OSWRCH is called it jumps to the routine whose address is
contained in WRCHV. All of the vectors used for operating
system routines are initialised on reset by the operating
system. Normally each vector contains the address of the
relevant routine in the operating system.
253
a) The routine provided completely replaces the standard
code. In this case, the routine should exit with an RTS
instruction (or an RTI if it is one of the interrupt or
break vectors).
254
&204,5 IRQ1V. The primary interrupt vector. All
interrupts are directed through this vector.
255
&21E,F FSCV. Various filing system control functions.
256
A=0 *CODE has been executed (or OSBYTE &88),
X and Y contain the two parameters.
See OS commands, section 2.6.
257
Note also that the break vector only refers to the BRK
assembler instruction, it should not be confused with the
‘BREAK’ key on the keyboard, which causes a hardware reset.
This vector is changed to its default state during the course of
processing such a reset.
258
The user printer driver acts as an interface between the printer
buffer in memory and the printer hardware. The driver is
responsible for removing the characters from the printer
buffer when the printer is ready to accept them, and passing
them on to the printer hardware. The printer driver is
regularly entered, allowing it to poll its hardware and the
printer buffer, and informing it of relevant changes in printer
conditions.
259
A=3 Warning that a VDU 3 has been received.
260
4 Write character attempted. This call to the net
vector is only made when enabled by OSBYTE
&D0. On entry Y is the character to be output. On
exit, if the carry flag is set the output of the
character is not passed on to the operating system.
(1) VDU 23,n has been issued with n in the range 2..31. The
vector is entered with the carry flag set. The accumulator
contains ‘n’. Locations &31C..&323 contain the eight
parameters always sent with the VDU 23 command.
261
In cases (2) and (3), the vector is entered with the carry flag
clear. The accumulator contains the PLOT number. Locations
&320 to &323 contain the X and Y co-ordinates sent via the
PLOT command. If the command was issued within a
graphics mode, the co-ordinates are converted to internal
co-ordinates, with relative plots and the graphics origin taken
into account.
262
10.10 The buffer insert vector, INSV &22A,B
On entry,
A=character to be inserted.
X=buffer number. No range checking is done on this
number.
On exit,
A,X preserved.
Y is undefined.
On entry,
X=buffer number. No range checking is done on this
number.
The overflow flag is set if only an examination is needed.
On exit,
A is the next character to be removed, for the examine
option, undefined otherwise.
X is preserved.
Y is the character removed for the remove option.
C is set if the buffer was empty on entry.
263
10.12 The buffer count/purge vector, CNPV &22E,F
On entry,
X=buffer number. No range checking is done on this
number.
The overflow flag is set if the buffer is to be purged.
The overflow flag is clear if the buffer is to be counted.
On exit,
For purge: X and Y are preserved.
A is undefined.
V,C are preserved.
264
10.14 The default vector table
Location:
&FFB6 length of lookup table in bytes.
&FFB7 low byte of the address of the table.
&FFB8 high byte of the address of the table.
265
266
11 Memory usage
This chapter describes how the memory in the BBC
microcomputer is allocated between the different contenders.
The area allocated to the operating system is described in
some detail, but that used by the language and user programs
is only outlined, as it varies from language to language.
267
&A0–&A7 are allocated to the current NMI owner (see
section in paged ROMs number 15.3.2). This area is not used
on basic cassette machines. It is used extensively by the disc
and network filing systems.
&D1 contains a byte mask for the current graphics point. This
byte indicates which bits in the screen memory byte
correspond to the point. For example, for the rightmost pixel
in a two colour mode, this byte would contain &01, and for a
sixteen colour mode, &55.
&D2 and &D3 are the text colour bytes to be ORed and
EORed into memory, respectively. When writing text to the
screen in modes 0 to 6, the pattern byte to be written to the
screen is first ORed with the contents of &D2, and then
EORed with the contents of &D3. The pattern byte contains a
bit set where the pixel is to be the foreground colour, and a bit
clear where the pixel is to be the background colour. In four
and sixteen colour modes, the pattern byte is expanded before
using these locations to take account of the extra bits per
pixel.
268
data in these two bytes. The graphics mask at location &D1 is
used to mask out the bits in these bytes when they are used.
&D6 and &D7 contain the address of the top line of the
current graphics character cell (eight bytes long). (See location
&31A)
&D8 and &D9 contain the address of the top scan line of the
current text character.
Bits 0 and 1, the least significant bits of the nibble are used to
control what happens after a tape error. When accessing the
269
EXEC file the ‘retry’ and ‘ignore error’ options are ignored, so
the EXEC is always aborted. These bits have the following
meanings (note the higher bit is mentioned first:
00 Ignore errors
10 Retry after an error
01 Abort after an error
Bits 2 and 3, the most significant bits of the nibble are used to
control the printing of messages during access. These bits
have the following meanings (note the format given is high
bit, low bit):
00 No messages
10 Short messages
11 Long messages
&E8 and &E9 are a pointer to the input buffer into which data
is entered by OSWORD &00.
270
&ED contains the internal key number of the first key pressed
of those still pressed, or zero if one or no keys are pressed.
This is used to implement two key rollover.
271
&FC is used as an interrupt accumulator save register. This
location is only used temporarily at the very beginning of an
interrupt routine while it is setting up the stack.
&FD and &FE point to the byte after the last BRK instruction,
or to the language version string after a language has been
selected. See the section on the BRK vector, section 10.2 for
details of the standard layout of post-BRK data. See the paged
ROMs chapter 15 for details of language ROM version strings.
272
&29C–&2A0 are the countdown interval timer value. This is
used to cause an event after a certain time has elapsed. See the
chapters on events, number 12, and on OSWORD, number 9,
for more details of using the countdown timer.
&2B1 and &2B2 are the INKEY countdown timer. This is used
to time out an INKEY call.
&2CA is the first auto repeat count. This is the next value to
go into the auto repeat counter at &E7. This location can be
considered a one byte queue for the counter.
273
&2CE is the sound semaphore. If it is zero it means that an
envelope interrupt is being processed, so another must be
ignored. If it is &FF it means that the envelope software is
free.
&2E1–&2E9 are the buffer end indices. They contain the offset
of the last byte to be entered into each buffer. If this value is
the same as the start offset, the buffer is empty. If this value is
less than the start offset, it means the buffer has wrapped
around to the start.
274
command in BASIC. The internal graphics co-ordinate is
derived from the external by taking into account the graphics
origin and scaling so that it is measured in pixels horizontally
and vertically. Graphics co-ordinates are stored in four bytes,
with the low byte of the X co-ordinate first.
275
&31A contains the line within current graphics character of
the current graphics point. Because the BBC microcomputer
has a non linear address space for the graphics screen, it is
simpler to calculate the address of the byte at the top of the
character cell that contains a point, and then calculate the row
within the character. Thus the location of the byte containing
the current graphics point is ?&D6 + 256*?&D7 + ?&31A.
&34C and &34D contain the text window width in bytes, ie.
the number of characters wide * the number of horizontal
bytes per character * 8 for graphics modes or 1 for teletext.
This is used to control the number of bytes which are soft
scrolled for each line of scrolling.
&350 and &351 contain the address of the top left hand corner
of the displayed screen, as is sent to the 6845.
276
&352 and &353 contain the number of bytes taken per
character row of the screen. This is 40 for teletext mode, 320
for 8K and 10K modes and 640 for 16K and 20K modes.
&354 contains the high byte of the size of the screen memory
in bytes.
&35B and &35C contain the graphics plot mode for the
foreground and background plotting respectively. These are
set by the GCOL first parameter.
&35D and &35E are used as a general jump vector. The vector
is used for decoding VDU control codes and PLOT numbers.
&361 contains the number of pixels per byte minus one for
the current mode, or zero if text only mode.
277
&362 and &363 contain the left and right colour masks,
respectively. These bytes contain a bit set in each bit position
corresponding to the leftmost or rightmost pixel. For example
in a two colour mode, these bytes would contain &80 and
&01, and in a sixteen colour mode &AA and &55.
&367 contains the font flag. This byte marks whether or not a
particular font zone is being taken from ROM or RAM. If a bit
is set it indicates that that zone is in RAM. See OSBYTE &14
(20) for more information on fonts.
&36F–&37E form the colour palette. One byte is used for each
logical colour. That byte contains the physical colour
corresponding to the logical colour. The bytes are stored in
numerical order of logical colour.
278
&39D contains the offset of the next byte to be output into the
BPUT buffer.
&39E contains the offset of the next byte to be read from the
BGET buffer.
&3DF contains a copy of the block flags of the last block read.
This is used to control newlines whilst printing file
information during file searches.
279
11.6 Page eight, &800–&8FF
Uses (b) and (c) are largely compatible apart from speech, as
the 6850 can only be used by either the cassette or the RS423
system at any one time, and the cassette system waits until
the RS423 output has timed out before taking control of the
6850. At time out, the RS423 output buffer is usually clear.
This page is used for either the cassette input buffer, or for the
RS423 input buffer.
280
11.9 Page eleven, &B00–&BFF
This page is the soft key buffer. The first seventeen bytes
define the start and end locations of the sixteen soft keys. The
rest of the page is allocated to the keys themselves. The start
offset of soft key string n is held at location &B00+n. The
address of the first character of the string is &B01+?(&B00+n).
The address of the last character of the string is
&B00+?(&B01+n).
There exist near the start of the operating system ROM some
tables which are used by the operating system to assist in high
resolution graphics processing. The user may be interested in
the existence of these tables when disassembling the
operating system. While it is possible to use these tables to
speed up graphics routines, it should be noted that these
tables are not Acorn supported, so a copy of the tables should
be taken, rather than use them directly. These tables have not
moved between operating systems 1.00 and 1.20, but there is
no guarantee that these locations will not move in a future
operating system version.
Prepare a four bit binary number, with a bit set for each pixel
in a display byte to be changed. The leftmost pixel is the
highest bit. Index this table with the number generated to find
the mask. If this mask were stored directly in screen memory,
all the ‘changed’ pixels will be in colour 3, and all the
‘unchanged’ pixels in colour 0. By simple masking operations
with the AND, ORA, and EOR instructions the mask can be
used to only change those bits required, or to set a screen byte
to an appropriate mix of chosen foreground and background
colours.
282
&C32F–&C332 is a similar lookup table to that at
&C31F–&C32E, but is used for sixteen colour modes. The
table is only four entries long as only two pixels can be fitted
into a byte. The mask byte given in the table contains colour
15 for set bits in the index, and colour 0 for cleared bits.
283
&C409–&C40C contain the mask table for four colour modes.
There are four entries, one per pixel in the byte. Each mask
contains the value that would be stored in screen memory if
the appropriate pixel were set to colour 3, and all the others to
zero. The leftmost pixel is stored first byte in the table, and
the rightmost in the last.
284
&C447–&C458 contain various VDU section control numbers,
of no direct relation to any screen parameters. Note that this
zone overlaps the previous table.
285
&C4B6–&C4B9 are a teletext conversion table. The teletext
character generator uses slightly different character codes to
the rest of the BBC microcomputer. This table contains four
bytes, an ASCII value followed by the byte to be stored in
screen memory, for three characters.
&23 (#) is translated to &5F
&5F (_) is translated to &60
&60 (£) is translated to &23
286
12 Events and Event
Handling
The concept of events and event handling provides the user
with an easy to use, pre-packaged interrupt. A routine may be
written to perform a second function while another program
is running. Because the microprocessor can only do one thing
at a time the second function will be executed by interrupting
the first program and then returning control to allow it to
continue from where it was interrupted.
287
7 RS423 error detected
8 Econet generated event
9 User event
Disable/enable event
Address &220
288
Great care must be taken when using operating system calls
from within an event handling routine. Many operating
system calls may enable interrupts during execution (see
chapter 7). If an interrupt occurs while the user’s event
handling routine is being executed the interrupt may cause
the user’s routine to be re-entered before it has finished
processing the previous event. It may be possible to write the
event handling routine in such a way that this will not have
any ill effects. A routine which may be re-entered in this way
is described as re-entrant or re-enterable. While the event
facility has been designed to enable users easy access to a
form of interrupt handling this aspect of their use may
complicate the issue. For more information see interrupts,
chapter 13.
Event Descriptions
This event enters the event handling routine with the buffer
number (see OSBYTE &15/*FX21) in X. It is generated when a
buffer becomes empty (i.e. just after the last character is
removed).
This event enters the event handling routine with the buffer
number (see OSBYTE &15/*FX 21) in X. It is generated when
the operating system fails to enter a character into a buffer
because it is full. Y contains the character value which could
not be inserted.
289
12.7 Character entering input buffer 2
For example:
10 OSWORD=&FFF1
20 EVNTV=&220
30 DIM MC% 100
40 DIM sound_pars 8
50 FOR I=0 TO 3 STEP3
60 P%=MC%
70 [
80 OPT I
90 PHP
100 PHA
110 TXA
120 PHA
130 TYA
140 PHA \ save registers
150 STY sound_pars+4 \ SOUND pitch=key ASCII value
160 LDX #sound_pars AND 255
170 LDY #sound_pars DIV 256
180 LDA #7
190 JSR OSWORD \ perform SOUND command
200 PLA
210 TAY
220 PLA
230 TAX
240 PLA
250 PLP \ restore registers
260 RTS \ return from event handler
270 ]
280 NEXT I
290 ?EVNTV=MC% AND &FF
300 EVNTV?1=MC% DIV &100
310 !sound_pars=&FFF50001
320 sound_pars!4=&00010000 :REM set up SOUND 1,-11,x,1
330 *FX 14,2
340 :REM enable keyboard event
290
12.9 Start of vertical sync 4
This event uses the interval timer (see OSWORD calls &3 and
&4, sections 9.5 and 9.6). This timer is a 5 byte value
incremented 100 times per second. The event is generated
when the timer reaches zero.
For example:
10 MODE7
20 OSWORD=&FFF1
30 OSBYTE=&FFF4
40 OSWRCH=&FFEE
50 EVNTV=&220
60 DIM MC% 100
70 DIM clock_pars 5
80 DIM count 1
90 FOR I=0 TO 2 STEP 2
100 P%=MC%
110 [
120 .entry OPT I
130 PHP
140 PHA
150 TXA
160 PHA
170 TYA
180 PHA \ save registers
190 LDX #clock_pars AND 255
200 LDY #clock_pars DIV 256
210 LDA #4
220 JSR OSWORD \ write to interval timer
230 LDA #&86
240 JSR OSBYTE \ read current text cursor position
250 TYA \ and save it on the stack
260 PHA
270 TXA
280 PHA
290 LDA #31 \ reposition text cursor
300 JSR OSWRCH \ with VDU 31,38,1
310 LDA #38
320 JSR OSWRCH
330 LDA #1
340 JSR OSWRCH
350 LDA count \ put count in A
360 JSR OSWRCH \ write it out
370 CMP #ASC"9" \ has count reached 9
380 BNE over \ jump next bit if it hasn't
390 LDA #ASC"/"
400 STA count \ put '-1' in count
410 .over INC count \ count=count+1
420 LDA #31 \ restore old cursor position
430 JSR OSWRCH \ using VDU 31
291
440 PLA
450 JSR OSWRCH
460 PLA
470 JSR OSWRCH
480 PLA
490 TAY
500 PLA
510 TAX
520 PLA
530 PLP \ restore registers
540 RTS \ return from event handler
550 ]
560 NEXTI
570 ?EVNTV=MC% AND &FF
580 EVNTV?1=MC% DIV &100
590 !clock_pars=&FFFFFF9C
600 clock_pars?4=&FF :REM clock value -100 centiseconds
610 *FX 14,5
620 :REM interval timer event
630 ?count=ASC"0" :REM initialise count
640 CALL entry :REM initialise clock
292
12.13 Network error 8
This event number has been set aside for the user event. This
is most usefully generated from a user interrupt handling
routine to enable other user software to trap an interrupt
easily (e.g. an event generated from an interrupt driven utility
in paged ROM). An event may be generated using OSEVEN,
see section 7.11.
293
294
13 Interrupts
13.1 A brief introduction to interrupts
295
13.1.1 Non Maskable Interrupts
296
data to or from the interrupting unit, and clearing the
interrupt condition. The interrupt condition must be cleared
because most devices that use interrupts continue to signal an
interrupt until they have been serviced. The completion of
servicing often has to be signalled by the processor writing to
a special register in the device.
297
changing the two bytes of a vector, writing to the system VIA
(see the system VIA chapter 23) or handling an interrupt or
event. Interrupts should not be disabled for long, because
whilst interrupts are disabled, the clock stops, and all other
interrupt activity ceases. Interrupts are disabled by the SEI
assembler instruction, and re-enabled with CLI. Most devices
that generate interrupts will continue to signal an interrupt
until it is serviced, and so will wait through the period of
interrupts being disabled. For this reason most short periods
of interrupts disabled are safe, it is only if a second interrupt
occurs from a device before the first is serviced that problems
can occur.
298
routine handles all anticipated internal IRQs. Anticipated
IRQs include interrupts from the keyboard, system VIA, serial
system and the analogue to digital converter. Any interrupt
which cannot be dealt with by the operating system routine
(such as an interrupt from the user VIA or a piece of
specialised hardware) is passed on through the second
interrupt vector.
Note that the user supplied routine must return control to the
operating system routine to ensure clean handling of
interrupts. It is therefore advisable to store the original
contents of the indirection vector in memory somewhere. This
will enable the user routine to jump to the correct operating
system routine. Also, by using this method of jumping to the
old contents of the vector, several user routines can all
intercept it correctly.
299
13.8 Serial interrupt processing
The 6850 contains a status byte that enables the 6502 to locate
the cause of the interrupt. This byte is organised as:
Serial processing can be split into two parts, that done for the
cassette filing system, and that done for the RS423 system.
300
13.8.1 The cassette serial system
301
The RS423 system can be made to ignore any of the above
interrupts by use of OSBYTE &E8. The 6850 status register is
ANDed with the OSBYTE value. Any bit cleared by this is
ignored, and passed over to the user interrupt vector. The
user is then responsible for clearing the interrupt condition.
This is done by either reading the receive data register or
writing to the transmit data register of the 6850 (see serial
hardware chapter 20).
bit 5 Set if timer 2 has timed out. Used for the speech
system.
302
bit 7 Set if the system VIA was the source of the
interrupt.
The shift register of the system VIA is not used, and its
interrupt is passed over to the user.
303
Timer 2 is used by the operating system to count transitions
of the speech ‘ready’ output. When an interrupt occurs, there
is an attempt to speak another word.
304
The standard interrupt routine only uses the CA1 interrupt;
all others are passed over to the user. The CA1 interrupt is
used to signify that the parallel printer is ready to accept a
new character. A new character is sent to the printer if the
printer output buffer is not empty. OSBYTE call &E7 can be
used to mask out the CA1 interrupt and cause it to be passed
on to the user in the same way as interrupts are masked out of
the system VIA.
Note that the interrupt routine should not call any operating
system routines if at all possible. This is because it is possible
that the foreground process was using the desired routine at
the time of the interrupt. If the routine to be called is not
re-entrant, the foreground process will be disturbed, and may
crash.
305
If a non-re-entrant zone is entered (such as an operating
system routine, or an area that needs temporary storage),
keep a semaphore for that zone. If another interrupt then
occurs, that area of code must not be used again until it has
finished.
306
This example introduces some interesting points:
When a key is held down for some time, the machine seizes
up until the key is released. This is because keyboard
interrupts occur continuously so that the operating system
has no time for anything other than interrupt processing. The
operating system, on receiving a keyboard interrupt,
immediately disables it and polls the keyboard. The keyboard
interrupts are only re-enabled when all keys are released.
Note the clearing of the interrupt. If this was not done, the
keyboard interrupt would last for ever. It is the responsibility
of the interrupt routine to clear an interrupt, whether it is the
operating system interrupt routine, or a user provided one.
307
170 PHA
180 TXA
190 PHA
200 TYA
210 PHA
220 LDA &FE4D \ Get system VIA interrupt status
230 AND #&88 \ Mask out bits not interested in
240 CMP #&88 \ Is it a lightpen interrupt?
250 BNE exit \ No - exit
260 LDA &FE40 \ Clear interrupt
270 LDX #16 \ Lightpen register
280 STX &FE00 \ 6845 address
290 INX \ Ready for next read
300 LDA &FE01 \ 6845 data
310 CMP olp+1 \ =old value?
320 STA olp+1 \ Update with new value
330 BNE diff1
340 STX &FE00 \ Next register
350 LDA &FE01 \ Get low address
360 TAY \ Temporary store
370 SBC olp \ Is it nearly eq.
380 CLC
390 ADC #1 \ Nearly eq if 0,1,2
400 BMI diff2
410 CMP #3 \ Compare with 2+1
420 BCS diff2 \ >=3 so not nearly eq..
430 \ Have two values same so update lpen
440 STY lpen
450 LDA olp+1
460 STA lpen+1
470 JMP exit \ And depart
480 .diff1 STX &FE00 \ Next register
490 LDY &FE01
500 .diff2 STY olp \ Update olp
510 LDA #0 \ Mark lpen as invalid
520 STA lpen
530 STA lpen+1
540 .exit PLA \ Restore registers...
550 TAY
560 PLA
570 TAX
580 PLA
590 STA &FC \ Just in case it has changed
600 RTI
610 ]
620 NEXT opt%
630 REM Initialise workspace
640 !olp=0
650 !lpen=0
660 REM grab the vector
670 CALL init
680 REM grab lightpen interrupts
690 REM Using mask 11110111=247
700 *FX 233,247
710 REM Demonstrate action of lightpen interrupts
720 REM Refer to hardware section for adjustments etc.
730 REM Set up a text window to stop hardware scroll
740 VDU 28,0,23,39,0
750 REPEAT
760 IF !lpen = 0 THEN PRINT "Not valid":ELSE PRINT ~!lpen
770 UNTIL FALSE
308
14 The RS423 serial system
This chapter describes how the RS423 serial interface system
can be used. The flexibility provided by the BBC
microcomputer hardware and software enables the serial
system to be reconfigured in a variety of ways. Details on
using the RS423 system to run the cassette port are also
included in this chapter.
The serial interface has two channels, one for output and one
for input. Using OSBYTE calls 2 and 3, the input channel can
be used to replace the keyboard input, and the output channel
can be connected to the computer’s output stream. The RS423
system can also be used to control the cassette port.
309
14.2 Uses of the RS423 system
310
10 REM Enable RS423 input
20 *FX 2,2
30 REM Set baud rates to 4800
40 *FX 7,6
50 *FX 8,6
60 REM Disable escape
70 *FX 229,1
80 REM This to be an 80 column VDU
90 MODE 3
100 OSBYTE=&FFF4
110 REM Main loop
120 REPEAT
130 REM Set next OSBYTE to insert in buffer.
140 A%=138:X%=2
150 REM If character in input buffer..
160 IF ADVAL(-1)>0 AND ADVAL(-3)>0 THEN Y%=GET:CALL OSBYTE
170 REM Set next input to read RS423
180 *FX 2,1
190 REM Check RS423 buffer
200 IF ADVAL(-2)>0 THEN VDU GET
210 REM Restore old state
220 *FX 2,2
230 REM Forever so..
240 UNTIL FALSE
The user may wish to have direct control over the cassette
port, for doing such things as reading tapes from other
computers, or writing protected tapes for the BBC.
311
The cassette uses the RTS line to control the ‘carrier’. Data on
the cassette system is frequency modulated, one tone is used
to represent a ‘1’ state, and another is used for ‘0’. A third
state is also required – silence, this is used to indicate the gap
between blocks. When transmitting silence the carrier is said
to be absent. When the RTS line is at logical zero, the 2400Hz
carrier tone is enabled.
Note the use of ADVAL to sense the buffer going empty. This
is needed because if the tone were turned off immediately
after sending the last character, it is possible that the last few
characters remain in the buffer and be corrupted when sent to
the tape.
10 REM Fudge factor: put 2 dummy bytes in RS423 input buffer
20 REM to allow control of RTS flag by use of buffer
30 REM tolerance (OSBYTE &CB, 203)
40 *FX 138,1,1
50 *FX 138,1,1
60 REM Enable receive interrupts to allow control of RTS
70 *FX 2,2
80 REM Indicate that RS423 is cassette
90 *FX 205,64
100 REM Select baud rates
110 *FX 7,4
120 *FX 8,4
130 REM Reset 6850
140 *FX 156,3,252
150 *FX 156,2,252
160 REM Turn tone on
170 *FX 203,9
180 REM Turn motor on
190 *MOTOR 1
200 REM Inform user
210 PRINT "Press record and return"
220 DUMMY=GET
312
230 REM Select output route
240 *FX 3,1
250 REM Send ULA synchronisation
260 VDU &AA
270 REM Wait (header tone)
280 TIME=0
290 REPEAT UNTIL TIME=500
300 REM Send data with a '*' tape synchronisation
310 PRINT "*HELLO THERE"
320 REM Wait until buffer empty
330 REPEAT UNTIL ADVAL(-3)>&BE
340 REM Pause for a short period of tone
350 TIME=0
360 REPEAT UNTIL TIME=50
370 REM Disconnect RS423 output
380 *FX 3,0
390 REM Turn off tone
400 *FX 203,255
410 REM Wait (for an interblock gap of silence)
420 TIME=0
430 REPEAT UNTIL TIME=150
440 REM Turn motor off
450 *MOTOR 0
460 REM Restore RS423
470 *FX 205,0
480 REM Tidy up serial input
490 *FX 2,0
500 *FX 21,1
313
Thus a simple event must be set up that detects a DCD
interrupt. In the example program it only marks the condition
in a byte in the base page.
314
490 IF X%<>ASC"*" OR ?&70<>0 THEN 320
500 REM Sync found and carrier present, so can now input...
510 REPEAT
520 X%=GET
530 VDUX%
540 UNTIL X%=13
550 REM All done so.. reset input route
560 *FX 2,0
570 REM Turn motor off
580 *MOTOR 0
590 REM Disable event
600 *FX 13,7
610 REM Restore 6850
620 *FX 156,2,252
630 REM Restore RS423
640 *FX 205,0
315
316
15 Paged ROMs
Paged ROMs are ROMs that fit in the four rightmost ROM
sockets on the BBC microcomputer circuit board. They all
have the following features in common:
317
nn+4… Copyright message
xx Copyright message terminator (&00)
xx+1–xx+5 If applicable, second processor relocation
address.
bit 7 If set, this indicates that the ROM has a service entry.
Note that a ROM with no service entry is assumed to
be the BASIC ROM. ALL user ROMs should have a
service entry.
bit 4 This bit controls the Electron soft key expansions, and
is not relevant on the BBC microcomputer.
318
e) The binary version number is ignored by the operating
system. It should be used to indicate the version number to
anyone examining the ROM.
319
15.1.1 Service Call entries
320
02 Private workspace claim. On break, after absolute
workspace allocation, each ROM is offered the chance
to take some private workspace. This memory is
exclusive to the ROM claiming it. The ROM is entered
with the first page number of the workspace available
to it in the Y register. It should save this value in the
ROM workspace table at &DF0 to &DFF (for ROMs 0
to &F respectively), and add to the Y register the
length in 256 byte pages of the private workspace
required. Because the absolute workspace is shared
between all the paged ROMs, each ROM that uses it
should keep a flag within its private workspace which
indicates whether or not it currently has control of the
absolute workspace. This enables the ROM to claim
the workspace when it needs it, and to respond to
such a claim from other ROMs.
321
05 Unrecognised interrupt. When an interrupt occurs that
is either not recognised by the operating system, or
has been software masked out, the interrupt is first
offered to the paged ROMs, and then to the user via
the ‘IRQ2’ vector. A paged ROM accepting interrupts
should interrogate the device(s) that it will respond to,
to see if any of them are responsible for the interrupt,
and if so process it. If the interrupt is processed by a
ROM, it should set the accumulator to zero to prevent
it being offered elsewhere. Always return with an RTS
instruction, not RTI.
322
unrecognised channel number is used (in the range
&2000 to &FEFF), allowing for future sound channel
expansion over the 1MHz bus.
323
0D ROM filing system initialise. This call is issued when
the ROM filing system is active, and the paged ROMs
are being scanned for a particular file. On entry, the Y
register contains 15 minus the ROM number of the
next ROM to be scanned. If that adjusted ROM
number is less than the number of the ROM receiving
the call, the call should be ignored. Otherwise, the
number should be replaced by the ROM number of the
active ROM and stored at &F5 after adjusting it. The
current ROM should mark itself as active by returning
with the accumulator zero, and store in locations &F6
and &F7 a pointer to the data within the ROM. The
alteration of location &F5 is necessary because the
ROM filing system will abort a search if it gets no
response from any of the ROMs for any particular
ROM number. Altering &F5 causes non-existent ROMs
to be skipped over. See the example on ROM filing
system use in section 15.4.
324
11 Font implosion/explosion warning. Each time the fonts
are exploded or imploded the high water mark will
change. This call exists to inform languages that the
high water mark has changed, and that the Y register
contains the new value. This call should be used to get
your precious data out of the way before being
destroyed by the character set. BASIC, it should be
noted, ignores this warning, as it has no service entry.
325
The actual entry codes in the accumulator are:
326
15.2 Languages
327
The BRK vector does not need to be an extended vector, as the
operating system automatically switches to the current
language ROM on a BRK. When a BRK occurs, the currently
active paged ROM number is recorded, and can be read with
OSBYTE &BA. Service paged ROMs normally copy their error
messages into RAM, so that the language does not have to
read the error message from another ROM.
328
On initialisation a filing system should do the following:
Base page:
329
Main memory:
330
LDA (&F6),Y \ Get the data
TAY \ In the Y register ready for exit
INC &F6 \ Increment the address for next time
BNE ninc7 \ No need to increment &F?
INC &57
.ninc7 PLA \ Discard service type
LDA #0 \ Set service type to no-operation
RTS \ Exit
.data \ Data onward from here
331
332
16 Filing systems
16.1 Filing systems in general
16.1.1 Files
When a file is opened for single byte access the filing system
allocates the file a ‘channel’. The channel can be considered to
be a window into a file. A ‘handle’ is assigned to each channel
to identify it internally. A file may be opened more than once
for input, and so more than one channel can be associated
with one file at any one time. When the file is closed and no
further access is required then the channel is released and is
no longer valid. The channel that was in use is now available
to be assigned to another file if required. Any filing system
can only have a limited number of open channels at one time
and so there are only a limited number of handles available.
A sequential pointer is maintained for each open file. The
sequential pointer always points to the next byte to be read or
written. In the disc filing system it is possible to change the
value of this pointer to give random access within a file. Only
serial access is available with the tape filing system.
16.1.2 Directories
333
The user may also specify a ‘library’ directory, which is similar
to a ‘current’ directory. The library directory is searched for
unrecognised commands unless a different directory is
included in the command name.
The network and disc filing systems also use a ‘cycle number’
associated with the disc. The cycle number represents the
number of times that a particular disc catalogue has been
written to. It is of use in helping to identify a disc with greater
reliability.
334
16.2 OSFILE Read or write a whole file or its attributes
On entry,
X and Y points to a parameter block in memory (X=low
byte, Y=high byte).
335
The value in the accumulator has the following
interpretations:
A=&FF Load the named file, the address to which the file
is loaded being determined by the lowest byte of
the execution address in the control block (XY+6).
If this byte is zero, the address given in the control
block is used, otherwise the file’s own load
address is used.
Bit=1 Means: By
336
6 Executable Others
7 Not Deletable Others
0 Nothing found
1 File found
2 Directory found
On exit,
X and Y are preserved.
The accumulator contains the file type.
C, N, V and Z are undefined.
Interrupt status is preserved, but may be enabled during
a call.
On entry,
X points to a four byte zero page control block.
Y contains the file handle as provided by OSFIND, or
zero.
The accumulator contains a number specifying the action
required.
If Y is zero:
337
4 Disc filing system
5 Econet filing system
6 Telesoftware system
A=&FF Update all files onto the media, ie ensure that the
latest copy of the memory buffer is saved.
If Y is not zero:
On entry,
Y contains the file handle, as provided by OSFIND.
338
On exit,
X and Y are preserved.
A contains the byte read.
C is set if the end of the file has been reached, and
indicates that the byte obtained is invalid.
N, V and Z are undefined.
Interrupt state is preserved, but may be enabled during
the call.
On entry,
Y contains the file handle, as provided by OSFIND.
A contains the byte to be written.
On exit,
X, Y and A are preserved.
C, N, V and Z are undefined.
Interrupt state is preserved, but may be enabled during
the call.
On entry,
X and Y point to a control block in memory.
A defines the information to be transferred.
339
The control block format is:
00 File handle
340
A=3 Get bytes from media, using the new sequential
pointer.
341
The requested transfer cannot be completed if the end of the
file has been reached, or there are no more file names to be
transferred. In this case, the C flag is set on exit. If a transfer
has not been completed the number of bytes or names which
have not been transferred are written to the parameter block
in the ‘number of bytes to transfer’ field. The address field is
always adjusted to point to the next byte to be transferred,
and the sequential pointer always points to the next entry in
the file to be transferred.
On exit,
X,Y and the accumulator are preserved.
N, V and Z are undefined.
C is set if the transfer could not be completed.
Interrupt state is preserved, but may be enabled during
operation.
On entry,
The accumulator specifies the operation to be performed:
342
The accumulator can take the following values:
&40, a file is to be opened for input only.
&80, a file is to be opened for output only.
&C0, a file is to be opened for update (random access).
On exit,
X and Y are preserved.
A is preserved on closing, and on opening contains the
file handle assigned to the file. If A=0 on exit, the file
could not be opened.
C, N, V and Z are undefined.
Interrupt state is preserved, but may be enabled during
the call.
343
abbreviated way of *RUNning a file when
specifying a directory in the file name. e.g.
*/L.FORM80 (*L.FORM80 would load the program
FORM80 from the current directory).
344
A=8 This call is issued by the operating system each
time it is about to process an operating system
command. It is used by the disc system to
implement a protection mechanism on dangerous
commands, by insisting that the previous
operating system command was *ENABLE.
On exit,
All registers are undefined, where not defined as
described above.
Interrupt state is preserved, but may be enabled during
operation.
345
A operation parameter, this can take the following
values:
A=0 Initialise read of second processor memory
A=1 Initialise writing of second processor
memory
A=4 Start execution in the second processor
346
The file handles given are constant: 1 is the input file; 2 is the
output file.
347
different. When the cassette filing system saves data onto tape
it calculates the CRC for each block of data and includes it in
the cassette format. When data is reloaded from cassette a
CRC is calculated and compared with the CRC value stored
with the data. If the two CRC values are not the same then
the data has been corrupted.
348
16.11 ROM filing system
The internal format for ROMs is the same as the tape format,
with the following exceptions:
In the ROM filing system, the ‘four spare bytes’ in the cassette
header block are used to contain the address of the byte after
the end of the file, enabling file searches to be a lot faster. Fast
searching is used by the ROM filing system by default. Full
CRC checking of each block during a *CAT can be enabled by
issuing a *OPT 1,2 command.
349
ROM software may be resident in standard paged ROMs, or,
if the speech chips are fitted, in a PHROM (PHrase Read Only
Memory). Storing data in paged ROMs will be covered in the
section on paged ROMs. Data stored in PHROMs, is
recognised as data, as opposed to speech, by an identification
sequence. This has the following format:
00 ignored
01 &00
02 &28 ‘(’
03 &43 ‘C’
04 &29 ‘)’
05
. ignored
.
3D
3E address of data in internal format for the speech chip
indirection command.
350
File names are up to 7 ASCII characters long.
351
352
17 An Introduction to
Hardware
Most users of the BBC microcomputer will be familiar with
BASIC programs, but from BASIC the hardware is virtually
invisible. Commands are provided to deal with output to the
screen, input from the keyboard and analogue to digital
converter, plus all of the other hardware. The same applies to
machine code to a large extent through the use of OSBYTEs,
OSWORDs and other operating system commands. However,
a much more detailed understanding of the hardware and
how it can be controlled from machine code programs is very
useful and allows certain features to be implemented which
would have been impossible in BASIC.
353
UHF
ECONET ANALOGUE CASSETTE RS423 RGB VIDEO
MODULATOR
7002
ANALOGUE SERIAL
TO PROCESSOR PAL
ECONET DIGITAL ULA ENCODER
CONVERTER
68B54 VIDEO
PROCES-
SOR
ULA
CLOCK
6850
ACIA
CONTROL
5220
6100
SPEECH 5050
SPEECH
PROCESSOR TELETEXT
ROM
CONTROL VIA A
6522
6502A
SERIAL MICRO-
ROMS PROCESS-
OR
354
76489
SOUND
Fig 17.1 THE SYSTEM BLOCK DIAGRAM
16K RAM
GENERATOR
KEYBOARD
8271
FLOPPY VIA B
DISC
CONTROL- 6522
LER
ROM
SEL PAGED
ROMS
355
request (IRQ) which the 6502 can ignore under software
control. The other in the non-maskable interrupt (NMI) which
can never be ignored. Refer to chapter 13 on interrupts for
more information.
356
SHEILA Integrated Description Section
address circuit number
(offset from
&FE00)
&00–&07 6845 CRTC Video controller 18
&08–&0F 6850 ACIA Serial controller 20.3
&10–&1F Serial ULA Serial system chip 20.9
&20–&2F Video ULA Video system chip 19
&30–&3F 74LS161 Paged ROM selector 21
&40–&5F 6522 VIA SYSTEM VIA 23
&60–&7F 6522 VIA USER VIA 24
&80–&9F 8271 FDC Floppy disc controller 25.1
&A0–&BF 68B54 ADLC ECONET controller 25.2
&C0–&DF uPD7002 Analogue to digital converter 26
&E0–&FF Tube ULA Tube system interface 27
357
358
18 The 6845 CRTC
Sheila address &00–&07
The 6845 cathode ray tube controller chip (CRTC) forms the
heart of the BBC Micro’s video display circuitry. Its major
function is that of displaying the video data in memory on a
raster scan display device (a television or monitor). As an
extra bonus, the 6845 also refreshes all of the random access
memory so that the data stored there is not lost. This
refreshing process is inherent in the sequential nature of
accessing memory for the video display. The 6845 does not
interfere with processor access to the memory since the
processor and 6845 operate on alternate phases of the system
clock. The 6845 is responsible for producing the correct format
on the display device, positioning the cursor, performing
interlace if it is required and monitoring the light pen input.
Other video processing functions involving colour and
teletext are dealt with in conjunction with other sections in
Sheila.
359
General illustration of a CRT Format
ABCDE Line
Number of displayed vertical characters (Nvd)
Total number of vertical characters (Nvt+1)
HORIZONTAL
DISPLAY PERIOD RETRACE
PERIOD
360
18.3 THE HORIZONTAL TIMING REGISTERS
361
18.3.3 Horizontal sync position register (R2)
This 8 bit write only register defines both the horizontal and
the vertical sync. pulse times.
The upper 4 bits contain the number of scan line times for the
vertical sync. pulse. This is set to 2 in all modes.
362
18.5.1 Vertical total register (R4)
363
18.6 Interlace and delay register (R8)
This 6 bit write only register controls the raster scan mode and
cursor/display delay. The interlace options are:
SCAN LINE
ADDRESS
364
SCAN LINE ADDRESS
0
0
1
1
2
2
3
3
4
4
5
5
6
6
7
7
0
1
2
3
4
5
6
7
0
1
2
3
4
5
6
7
365
18.6.3 Cursor blanking delay (bits 6,7)
This 7 bit write only register controls the cursor format (see
figure 18.3). Bit 7 is not used. Bit 6 enables or disables the
blink feature. Bit 5 is the blink timing control bit. When bit
5=0, blink frequency = 16 times the field rate. When bit 5=1,
blink frequency = 32 times the field rate. When bit 6=0 and
bit 5=1, the cursor is disabled. The cursor start line is set by
the lower five bits.
366
0 0 0
1 1 1
2 2 2
3 3 3
4 4 4
5 5 5
6 6 6
7 7 7
8 8 8
9 9 9
10 10 10
11 11 11
This 5 bit write only register sets the cursor end scan line (see
diagram).
Mode 0 1 2 3 4 5 6 7
Cursor end 8 8 8 9 8 8 9 19
367
Light pens can be used for a multitude of tasks such as
drawing, ‘painting’, designing layouts, playing games etc.,
but their use in many applications is limited by the resolution.
The reason for this is that a fairly large area of screen (ie.
perhaps .5cm x .5cm) is usually required to provide sufficient
light to operate the pen. The maximum resolution for defining
the position of the light pen is therefore a patch on the screen
of this size, so accurate line drawings are impossible. The
position of the light pen is stored to the nearest character
position, so this limits the resolution to a character cell.
368
ANALOGUE PORT
CONNECTOR
0V +5V
8 7 6 5 4 3 2 1
9
15 14 13 12 11 10
LPSTB
1
2
3
UNDERSIDE VIEW
OF PHOTOSENSOR
1 = +5V
2
2 = OUTPUT
3 = 0V 1
3
PHOTOSENSOR
(see text)
PEN SHELL
369
This x value will be in terms of 6845 characters and will have
to be modified by multiplying by
370
screen up, down, left and right. Provided that the start
address is inside the screen memory of the mode being used,
a hardware wrap around feature will also operate. Characters
which would have scrolled off the top of the screen will
therefore reappear at the bottom. The wrap around circuit
simply detects whenever the 6845 tries to get video data from
a ROM (an address above &7FFF), and adds an offset to that
address. This has the effect of bringing the address back
inside the video RAM. Since the screen sizes are different in
the various modes, 2 bits on the SYSTEM VIA are used to
define the length of the hardware scrolled screen, see section
23.2.
371
than the official screen start address or greater than the official
screen end address in the mode being used. If this occurs then
areas of the main system memory will be displayed directly on
the screen. This produces some interesting results, especially if
zero page is displayed! Remember that the value put into
R12,R13 is the actual memory address DIV 8. See the example
program in section 18.14.
372
18.12 FAST ANIMATION
Mode 2 has several advantages over all of the other modes for
fast animation. It is for this reason, plus the fact that all 16
colours are available that this mode is used in most fast
graphics games. Provided that the programmer is prepared to
put up with a 2 pixel at a time movement instead of a 1 pixel
at a time movement, moving objects simplifies to moving
complete bytes in memory. Consider for a moment the layout
of each byte on a mode 2 screen.
P2d P1d P2c P1c P2b P1b P2a P1a
BIT 7 6 5 4 3 2 1 0
P1a-P1d are 4 bits defining the colour of pixel I
P2a-P2d are 4 bits defining the colour of pixel 2
373
then add the length of the screen to it. If it goes above the top
of screen address then subtract the length of screen from it.
374
18.15 6845 REGISTER SUMMARY TABLE
Register Register Program Data bit
number name unit 7 6 5 4 3 2 1 0
AR Address register – x x x A4 A3 A2 A1 A0
R0 Horizontal total Character D7 D6 D5 D4 D3 D2 D1 D0
R1 Horizontal Character D7 D6 D5 D4 D3 D2 D1 D0
displayed
R2 Horizontal sync Character D7 D6 D5 D4 D3 D2 D1 D0
position
R3 Horizontal sync Character H3 H2 H1 H0
width
Vertical sync Scan line V3 V2 V1 V0
width
R4 Vertical total Char. row x D6 D5 D4 D3 D2 D1 D0
R5 Vertical total Scan line x x x D4 D3 D2 D1 D0
adjust
R6 Vertical displayed Char. row x D6 D5 D4 D3 D2 D1 D0
R7 Vertical sync Char. row x D6 D5 D4 D3 D2 D1 D0
position
R8 Interlace mode V S
Display enable Character D1 D0
delay
Cursor enable Character C1 C0
delay
R9 Scan lines/ Scan line x x x D4 D3 D2 D1 D0
character
R10 Cursor start Scan line x D4 D3 D2 D1 D0
Cursor blink rate – R
Cursor blink – B
ON/OFF
R11 Cursor end Scan line x x x D4 D3 D2 D1 D0
R12 Screen start – x x H5 H4 H3 H2 H1 H0
address H
R13 Screen start – L7 L6 L5 L4 L3 L2 L1 L0
address L
R14 Cursor address H – x x H5 H4 H3 H2 H1 H0
R15 Cursor address L – L7 L6 L5 L4 L3 L2 L1 L0
R16 Light pen H – x x H5 H4 H3 H2 H1 H0
R17 Light pen L – L7 L6 L5 L4 L3 L2 L1 L0
x = not used
375
376
19 The video ULA
Sheila address &20–&21
7 6 5 4 3 2 1 0
MASTER WIDTH OF 6845 NUMBER OF TELETEXT/ FLASH
CURSOR CURSOR IN CLOCK CHARACTERS PER NORMAL COLOUR
SIZE BYTES RATE LINE SELECT SELECT
SELECT
377
19.1.1 Selected flash colour (bit 0)
This bit selects whether RGB input comes from the video
serialiser in the ULA or from the teletext chip.
The clock frequency sent to the 6845 can be varied using this
bit.
378
19.1.5 Width of cursor in bytes (bits 5,6)
379
The palette register consists of two 4 bit fields. Bits 0–3 are the
actual colour field. Bits 4–7 are the logical colour field, as
illustrated in figure 19.2.
7 6 5 4 3 2 1 0
‘LOGICAL’ COLOUR ‘ACTUAL’ COLOUR
REGISTER REGISTER
380
Logical colour bit 7 bit 6 bit 5 bit 4
0 0 0 0 0
0 0 0 1
0 1 0 0
0 1 0 1
1 0 0 1 0
0 0 1 1
0 1 1 0
0 1 1 1
2 1 0 0 0
1 0 0 1
1 1 0 0
1 1 0 1
3 1 0 1 0
1 0 1 1
1 1 1 0
1 1 I 1
381
19.2.3 Physical colour field
382
19.3 ‘MODE 8’ Implementation example
383
384
20 The serial system
Sheila address &08–&1F
385
Each character is transmitted serially according to a
predefined format. A start bit indicates that a character will
follow. 7 or 8 bits of character are then sent followed by a
parity bit, if parity is selected. This parity bit may be set to
either 1 or 0 to indicate whether the number of high bits in the
character were odd or even. The parity bit (if selected) is then
followed by one or two stop bits. The idea behind using a
parity bit is that the receiving device can check that parity is
correct. If it is incorrect then an error has occurred between
the transmitter and receiver. The following diagram
illustrates the format of an 8 bit word with odd parity and 1
stop bit selected.
START DATA DATA DATA DATA DATA DATA DATA DATA PARITY STOP
BIT BIT0 BIT1 BIT2 BIT3 BIT4 BIT5 BIT6 BIT7 BIT BIT
386
20.4 Transmit data register (TDR) Sheila &09 write only
387
toggles bits. Setting Y=&FF and X=0 will generate no change
at all. The routine returns with the old value of the control
register in the X register. This register is normally set to &56
when using a cassette based system which isn’t in the process
of transmitting or receiving anything.
Select bits are used to select word length, parity and the
number of stop bits. Any changes become effective
immediately.
CR4 CR3 CR2 Function
0 0 0 7 bits + even parity + 2 stop bits
0 0 1 7 bits + odd parity + 2 stop bits
0 1 0 7 bits + even parity + 1 stop bit
0 1 1 7 bits + odd parity + 1 stop bit
1 0 0 8 bits + 2 stop bits
1 0 1 8 bits + 1 stop bit
1 1 0 8 bits + even parity + 1 stop bit
1 1 1 8 bits + odd parity + 1 stop bit
388
20.6.3 Transmitter Control Bits (CR5 and CR6)
This bit goes high to indicate that the Transmit Data Register
contents have been transferred and that new data may now be
entered. The low state indicates that the TDR is full.
389
20.7.4 Clear To Send (CTS) Bit 3
This is always low when using the cassette. On the RS423 this
bit indicates that the RS423 is Clear To Send data out while
this bit is low. Master reset doesn’t affect the CTS bit since it
is an external input.
This indicates the state of the IRQ output. Whenever the IRQ
output is low the IRQ bit is high. IRQ is cleared by a read
operation to the Receive Data Register or a write operation
the Transmit Data Register.
Note that OSBYTE &E8 is used to mask the 6850 ACIA IRQ.
See chapter 13 on interrupts for further details about using
interrupts.
390
20.8 6850 ACIA Summary table
Bit Control Register Status Register
WRITE ONLY READ ONLY
0 Counter Divide select 1 (CR0) Receive Data Register Full
(RDRF)
1 Counter Divide select 2 (CR1) Transmit Data Register Empty
(TDRE)
2 Word select 1 (CR2) Data Carrier Detect
3 Word select 2 (CR3) Clear To Send
4 Word select 3 (CR4) Framing Error (FE)
5 Transmit control 1 (CR5) Receiver overrun
6 Transmit control 2 (CR6) Parity error (PE)
7 Receiver interrupt enable (CR7) Interrupt request (IRQ)
391
20.9 THE SERIAL ULA – SHEILA &10
392
20.9.3 Serial ULA bit 6
20.10 The ‘BUG’ fix required when using the cassette system
393
394
21 Paged ROM select
register
Sheila address &30
395
396
22 The 6522 Versatile
Interface Adapters
Sheila addresses &40–&7F
397
CA1, CA2 (port A control lines)
Inputs
Outputs
398
22.2 FUNCTIONAL DESCRIPTION
399
22.2.1 Operation of port A and port B
There are two data direction registers DDRA and DDRB which
specify whether the peripheral pins are to operate as inputs or
outputs. Placing a ‘0’ in a bit of a DDR will cause the
corresponding bit of that port to be defined as an input. A ‘1’
will cause it to be defined as an output.
400
REG 0 – ORB/IRB
7 6 5 4 3 2 1 0
PB0
PB1
PB2
OUTPUT REGISTER “B” (ORB)
PB3
OR
PB4
INPUT REGISTER “B” (IRB)
PB5
PB6
PB7
Pin
Data Direction WRITE READ
Selection
DDRB = “1” (OUTPUT) MPU writes Output Level MPU reads output register bit
(ORB) in ORB. Pin level has no effect.
DDRB = “0” (INPUT) MPU writes into ORB, but MPU reads input level on PB
(Input latching disabled) no effect on pin level until pin.
DDRB changed.
DDRB = “0” (INPUT) MPU reads IRB bit, which is
(Input latching enabled) the level of the PB pin at the
time of the last CB1 active
transition.
401
REG 1 – ORA/IRA
7 6 5 4 3 2 1 0
PA0
PA1
PA2
OUTPUT REGISTER “A” (ORA)
PA3
OR
PA4
INPUT REGISTER “A” (IRA)
PA5
PA6
PA7
Pin
Data Direction WRITE READ
Selection
DDRA = “1” (OUTPUT) MPU writes Output Level MPU reads level on PA pin.
(Input latching disabled) (ORA)
DDRA = “1” (OUTPUT) MPU reads IRA bit which is
(Input latching enabled) the level of the PA pin at the
time of the last CA1 active
transition.
DDRA = “0” (INPUT) MPU writes into ORA, but MPU reads level on PA pin.
(Input latching disabled) no effect on pin level until
DDRA = “0” (INPUT) DDRA changed. MPU reads IRA bit which is
(Input latching enabled) the level of the PA pin at the
time of the last CA1 active
transition.
7 6 5 4 3 2 1 0
PB0/PA0
PB1/PA1
PB2/PA2
PB3/PA3
DATA DIRECTION REGISTER
“B” OR “A” (DDRB/DDRA)
PB4/PA4
PB5/PA5
402
22.2.2 Write handshaking data transfer
1MHzE
“DATA READY”
HANDSHAKE MODE
(CA2, CB2)
“DATA READY”
PULSE MODE
(CA2, CB2)
“DATA TAKEN”
(CA1, CB1)
IRQ OUTPUT
403
Selection of operating modes for CA1, CA2, CB1 and CB2 is
controlled by the Peripheral Control Register, see figure 22.6.
7 6 5 4 3 2 1 0
404
REG 4 – TIMER 1 LOW-ORDER COUNTER REG 5 – TIMER 1 HIGH-ORDER COUNTER
7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0
1 256
2 512
4 1024
8 COUNT 2048 COUNT
16 VALUE 4096 VALUE
32 8192
64 16384
128 32768
WRITE – 8 BITS LOADED INTO T1 LOW ORDER WRITE – 8 BITS LOADED INTO T1 HIGH ORDER
LATCHES. LATCH CONTENTS ARE LATCHES. ALSO, AT THIS TIME BOTH
TRANSFERRED INTO LOW ORDER HIGH AND LOW ORDER LATCHES
COUNTER AT THE TIME THE HIGH TRANSFERRED INTO T1 COUNTER.
ORDER COUNTER IS LOADED (REG 5). T1 INTERRUPT FLAG IS ALSO RESET.
READ – 8 BITS FROM T1 LOW ORDER COUNTER READ – 8 BITS FROM T1 HIGH ORDER COUNTER
TRANSFERRED TO MPU. IN ADDITION, TRANSFERRED TO MPU.
T1 INTERRUPT FLAG IS RESET (BIT 6 IN
INTERRUPT FLAG REGISTER).
1 256
2 512
4 1024
8 COUNT 2048 COUNT
16 VALUE 4096 VALUE
32 8192
64 16384
128 32768
WRITE – 8 BITS LOADED INTO T1 LOW ORDER WRITE – 8 BITS LOADED INTO T1 HIGH ORDER
LATCHES. THIS OPERATION IS NO LATCHES. UNLIKE REG 5 OPERATION
DIFFERENT THAN A WRITE INTO NO LATCH TO COUNTER TRANSFER
REG 4. TAKES PLACE.
READ – 8 BITS FROM T1 LOW ORDER LATCHES READ – 8 BITS FROM T1 HIGH ORDER LATCHES
TRANSFERRED TO MPU. UNLIKE REG 4 TRANSFERRED TO MPU.
OPERATION, THIS DOES NOT CAUSE
RESET OF T1 INTERRUPT FLAG.
405
Writing into the high order latch has no effect on the
operation of T1 in the one-shot mode. It is however necessary
to ensure that the low order latch contains the correct data
before initiating the countdown by writing T1C-H. When the
6502 writes into the high order counter, the T1 interrupt flag
is cleared, the contents of the low order latch are transferred
into the low order counter, and the timer begins to decrement
at 1MHz. If PB7 output is enabled then it will go low after the
write operation. Upon reaching zero, the T1 interrupt flag is
set, an interrupt is generated (if enabled) and PB7 goes high.
The counter continues to decrement at the system clock rate.
The 6502 is then able to read the contents of the counter to
determine the time since the interrupt occurred. The T1
interrupt must be cleared before it can be set again.
406
the period of the next half cycle on the PB7 output will be
determined. Waveforms with complex mark-space ratios can
be generated in this way.
1 256
2 512
4 1024
8 COUNT 2048 COUNT
16 VALUE 4096 VALUE
32 8192
64 16384
128 32768
WRITE – 8 BITS LOADED INTO T2 LOW ORDER WRITE – 8 BITS LOADED INTO T2 HIGH ORDER
LATCHES. COUNTER. ALSO, LOW ORDER LATCHES
READ – 8 BITS FROM T2 LOW ORDER COUNTER TRANSFERRED TO LOW ORDER
TRANSFERRED TO MPU. T2 INTERRUPT COUNTER. IN ADDITION, T2 INTERRUPT
FLAG IS RESET. FLAG IS RESET.
READ – 8 BITS FROM T2 HIGH ORDER COUNTER
TRANSFERRED TO MPU.
407
22.2.8 Timer 2 pulse counting mode
7 6 5 4 3 2 1 0
PA LATCH ENABLE/DISABLE
T1 TIMER CONTROL
PB 0 = DISABLE
7 6 OPERATION PB7 1 = ENABLE LATCHING
0 0 TIMED INTERRUPT
EACH TIME T1 IS
LOADED DISABLED
0 1 CONTINUOUS
INTERRUPTS
1 0 TIMED INTERRUPT ONE SHOT
SHIFT REGISTER CONTROL
EACH TIME T1 IS OUTPUT
LOADED 4 3 2 OPERATION
1 1 CONTINUOUS SQUARE 0 0 0 DISABLED
INTERRUPTS WAVE 0 0 1 SHIFT IN UNDER CONTROL OF T2
OUTPUT 0 1 0 SHIFT IN UNDER CONTROL OF 1MHz CLK.
0 1 1 SHIFT IN UNDER CONTROL OF EXT. CLK.
T2 TIMER CONTROL 1 0 0 SHIFT OUT FREE-RUNNING AT T2 RATE
5 OPERATION 1 0 1 SHIFT OUT UNDER CONTROL OF T2
0 TIMED INTERRUPT 1 1 0 SHIFT OUT UNDER CONTROL OF 1MHz CLK.
1 COUNT DOWN WITH 1 1 1 SHIFT OUT UNDER CONTROL OF EXT. CLK.
PULSES ON PB6
408
REG 10 – SHIFT REGISTER
7 6 5 4 3 2 1 0
SHIFT
REGISTER
BITS
NOTES:
1. WHEN SHIFTING OUT, BIT 7 IS THE FIRST BIT
OUT AND SIMULTANEOUSLY IS ROTATED
BACK INTO BIT 0.
2. WHEN SHIFTING IN, BITS INITIALLY ENTER
BIT 0 AND ARE SHIFTED TOWARDS BIT 7.
409
write SR. Data is shifted first into the low order bit of the SR,
then into the next higher order bit and so on on the negative
edge of each shift clock pulse. The input data should then
change before the next positive going edge of CB1. Data is
shifted into the shift register on the positive going edge of the
CB1 pulse. After 8 CB1 clock pulses, the shift register
interrupt flag will be set and an interrupt will be requested of
the 6502.
1MHzE
WRITE OR READ
SHIFT REG.
N+2 CYCLES N+2
CYCLES
CB1 OUTPUT 1 2 3 8
SHIFT CLOCK
CB2 INPUT 1 2 3 8
DATA
IRQ
1MHzE
READ SR
OPERATION
CB1 OUTPUT
SHIFT CLOCK
CB2 INPUT 1 2 3 4 5 6 7 8
DATA
IRQ
410
Shift in under control of external CB1 clock (SRMODE 3)
1MHzE
CB1 INPUT 1 2 3 4 8
SHIFT CLOCK
CB2 INPUT 1 2 3 4 8
DATA
IRQ
1MHzE
WRITE SR
OPERATION
N+2 CYCLES N+2 CYCLES
CB1 OUTPUT 1 2 3 4 8 9
SHIFT CLOCK
CB2 OUTPUT 1 2 3 4 8 1
DATA
411
Shift out under control of T2 (SRMODE 5)
1MHzE
WRITE SR
OPERATION
N+2 CYCLES N+2 CYCLES
CB1 OUTPUT 1 2 3 8
SHIFT CLOCK
CB2 OUTPUT 1 2 3 8
DATA
IRQ
1MHzE
WRITE SR
OPERATION
CB1 OUTPUT
1 2 3 4 7 8
SHIFT CLOCK
CB2 OUTPUT
1 2 3 4 7 8
DATA
IRQ
412
Shift out under control of external CB1 clock (SRMODE 7)
1MHzE
WRITE SR
OPERATION
CB1 INPUT
1 2 8
SHIFT CLOCK
CB2 OUTPUT
1 2 8
DATA
IRQ
413
1 if the 6522 has generated the interrupt. In addition to
reading the IFR, individual bits may be cleared by writing a 1
into the appropriate bit of the IFR. Note however that IFR bit
7 is not a flag as such and will not be cleared by writing a 1
into it. It can only be cleared by clearing all the flags in the
register or by disabling ALL of the active interrupts.
The 6502 can set or clear selected bits in the interrupt enable
register without affecting the other bits. This is accomplished
by writing to the IER. If bit 7 of the byte written is a 0 then
each 1 in bits 0–6 will clear the corresponding bit in the IER.
For each zero in bits 0–6, the corresponding bit will not be
affected. Selected bits can be SET in a similar manner. In this
case, bit 7 of the written byte should be set to 1. Each 1 in bits
0–6 will then SET the selected bit. A zero will cause the
corresponding bit to remain unaffected. The contents of the
IER can be read by the 6502. Bit 7 is then always read as a logic
1.
7 6 5 4 3 2 1 0
SET BY CLEARED BY
414
REG 14 – INTERRUPT ENABLE REGISTER
7 6 5 4 3 2 1 0
CA2
CA1
SHIFT REG
TIMER 1
SET/CLEAR
NOTES:
1. IF BIT 7 IS A “0”, THEN EACH “1” IN BITS 0 - 6 DISABLES THE
CORRESPONDING INTERRUPT.
2. IF BIT 7 IS A “1” THEN EACH “1” IN BITS 0 - 6 ENABLES THE
CORRESPONDING INTERRUPT.
3. IF A READ OF THIS REGISTER IS DONE, BIT 7 WILL BE A “1” AND
ALL OTHER BITS WILL REFLECT THEIR ENABLE/DISABLE STATE.
415
416
23 The System VIA
Sheila addresses &40–&4F
PA0–PA7
The 6502 CPU does not talk to the speech system, sound
generator or keyboard directly over its data bus. Instead, it
writes to and reads from the 8 bit port A I/O lines. This forms
a ‘slow’ databus over which the CPU can communicate. To
write to this databus, the data direction register A at Sheila
&43 should set all lines as outputs. The 6502 can then write
directly into output register A at Sheila &41. To read from the
slow data bus, DDRA must set all lines as inputs by writing
&00 to Sheila address &43. A direct read from input register
A at Sheila &41 can then be made. NOTE that any reading or
writing over this slow databus will have to be done from
machine code with ALL 6502 interrupts disabled. This is
because the interrupt routines themselves will make extensive
use of the system VIA and keep changing the register values.
CA1 input
This is the vertical sync input from the 6845. CA1 is set up to
interrupt the 6502 every 20 ms (50 Hz) as a vertical sync from
the video circuitry is detected. The operating system changes
the flash colours on the display in this interrupt time so that
they maintain synchronisation with the rest of the picture.
417
CA2 input
PB0–PB2 outputs
PB3 output
These are the inputs from the joystick FIRE buttons. They are
normally at logic 1 with no button pressed and change to 0
when a button is pressed. OSBYTE &80 can be used to read
the status of the joystick fire buttons.
CB1 input
The CB1 input is the end of conversion (EOC) signal from the
7002 analogue to digital converter. It can be used to interrupt
the 6502 whenever a conversion is complete. See chapter 26
on the Analogue to Digital Converter.
CB2 input
This is the light pen strobe signal (LPSTB) from the light pen.
It also connects to the 6845 video processor, see section 18.9.
CB2 can be programmed to interrupt the processor whenever
a light pen strobe occurs. See the light pen example in the
interrupts chapter 13.
418
23.2 The addressable latch
419
be done. The data to be written into the sound chip is first of
all put onto the slow databus. Note that interrupts are
disabled before this is started. The sound generator write
enable line is then pulled low for at least 8 µs then pulled high
again.
0 0 0 0 15 (MAX)
0 0 0 1 14
0 0 1 0 13
0 0 1 1 12
0 1 0 0 11
0 1 0 1 10
0 1 1 0 9
0 1 1 1 8
1 0 0 0 7
1 0 0 1 6
1 0 1 0 5
1 0 1 1 4
1 1 0 0 3
1 1 0 1 2
1 1 1 0 1
1 1 1 1 0 (OFF)
420
23.3.2 Noise generator
0 0 low
0 1 medium
1 0 high
1 1 tone generator 1 frequency
R2 R1 R0 Description
0 0 0 Tone 3 frequency
0 0 1 Tone 3 volume
0 1 0 Tone 2 frequency
0 1 1 Tone 2 volume
1 0 0 Tone 1 frequency
1 0 1 Tone 1 volume
1 1 0 Noise control
1 1 1 Noise volume
421
23.4 PROGRAMMING BYTE FORMATS
Data
Bit 7 6 5 4 3 2 1 0
0 X F9 F8 F7 F6 F5 F4
Register Address
Bit 7 6 5 4 3 2 1 0
1 R2 R1 R0 X FB NF1 NF0
422
23.5 Example program for direct control of the sound
generator
Run the example program and enter &80, &20 and &90 to
generate a frequency at maximum volume on channel 3.
423
424
24 The User/Printer VIA
Sheila addresses &60–&6F
425
24.3 The USER PORT connector
BOTTOM
TOP
PB7 20 19 0V
PB6 18 17 0V
PB5 16 15 0V
PB4 14 13 0V
PB3 12 11 0V
PB2 10 9 0V
PB1 8 7 0V
PB0 6 5 0V
CB2 4 3 +5V
CB1 2 1 +5V
426
25 Floppy Disc and Econet
Sheila addresses &80–&BF
Sheila
address Read function Write function
&80 Status register Command register
&81 Result register Parameter register
&82 Reset register
&83 Not used Not used
&84 Read data Write data
(DMA Ack. set) (DMA Ack. set)
427
25.2 The 68B54 Advanced Data Link Controller – Sheila
&A0–&BF
The addresses of registers within the 68B54 are given here for
reference:
Sheila
address Write function Read function
&A0 Control Register 1 Status Register 1
&A1 Control Registers 2,3 Status Register 2
&A2 Transmit FIFO Receive FIFO
(Frame Continue)
&A3 Transmit FIFO Receive FIFO
(Frame Terminate)
428
26 The Analogue to Digital
converter
Sheila addresses &C0–&C2
429
26.1.1 Channel Summary:–
Relevant OSBYTEs which write to the ADC are &10, &11 and
&BD.
430
READING FROM THE ADC
431
26.2 Hardware connections for a joystick
8 7 6 5 4 3 2 1
ANALOGUE CH1 0V ANALOGUE CH3 0V 0V +5V
PB0 GROUND GROUND PB1
FIRE FIRE
BUTTON BUTTON
CH0 VREF PB0 CH2 VREF PB1 LPSTB
15 14 13 12 11 10 9
JOYSTICK 1
JOYSTICK 2
CH1
CH0
CH2 CH3
432
27 The Tube
Sheila addresses &E0–&FF
433
Data and messages are passed back and forth through the
various registers according to carefully designed software
protocols. Proper allocation of the registers to specific tasks
allows both systems to operate at maximum efficiency. For
example, complex VDU plot and colour fill commands can be
sent via the largest FIFO from the parasite to the host
processor. The parasite processor will not then have to wait
for the host to finish processing the laborious VDU
commands before continuing with its language processing.
434
program and data storage. Naturally, 16K of the parasite’s
RAM will be required for BASIC, but most of the remaining
48K is available to the programmer (compared with a
maximum of 27K on an ordinary BBC microcomputer). The
16K operating system ROM stays in the host processor’s
memory map and is not transferred across the Tube.
As with the 6502 and Z80 Tubes, the old BBC micro 6502 still
does all input/output and the 16032 runs languages. Unlike
the 6502 and Z80 which are both relatively old 8 bit
processors, the 16032 is one of a new generation of 16 bit
processors. Its internal structure operates on 32 bits, and it has
a very nicely organised instruction set which is very powerful.
With one of these sitting on the end of the Tube, and a Hard
Disc Drive connected to the host processor, the computing
power available will be equal that available on many
mainframe computers. One standard operating system
provided on 16032 Tube machines will be UNIX.
435
436
28 The One Megahertz bus
28.1 Introduction to the 1MHz bus
There are basically two routes which a user can take towards
adding his own hardware. One of these is the 6522 USER
port. The problem with the USER port is that there are only 8
I/O lines and a couple of control lines. For more complex
peripherals, direct access to the 6502 address and data buses
are required. This interface is provided by the one megahertz
bus.
437
&FC30 – &FC3F Cambridge Ring Interface
&FC40 – &FC47 Winchester Disc Interface
&FC48 – &FC7F Acorn Expansion, currently unused
&FC80 – &FC8F Test Hardware
&FC90 – &FCBF Acorn Expansion, currently unused
&FCC0 – &FCFE User Applications
&FCFF Paging Register for JIM
438
BOTTOM
TOP
A7 34 33 A6
A5 32 31 A4
A3 30 29 A2
A1 28 27 A0
0V 26 25 D7
D6 24 23 D5
D4 22 21 D3
D2 20 19 D1
D0 18 17 0V
AUDIO IN 16 15 0V
RST 14 13 0V
NPGFD 12 11 0V
NPGFC 10 9 0V
NIRQ 8 7 0V
NNMI 6 5 0V
1MHzE 4 3 0V
R/W 2 1 0V
439
28.4 Bus signal definitions
440
NIRQ (pin 8) Not Interrupt Request. This is connected
directly to the 6502 IRQ input. Any
devices connected to this input should
have open collector outputs. The line is
pulled up to +5 volts with a 3K3 resistor.
Interrupts from the 1MHz bus must not
occur until the software on the main
system is able to cope with them. All
interrupts must therefore be disabled
after a reset. Note that the main system
software may operate very slowly if
considerable use is made of interrupts.
Certain functions such as the real time
clock which is incremented every 10 mS
will be affected if interrupts are masked
for more than this period. Refer to the
chapter on interrupts, section 13.1 for
more information.
441
Audio Input This is an input to the audio amplifier on
(pin 16) the main computer. The amplified signal
is produced over the speaker on the
keyboard. Its input impedance is 9K
Ohms and a 3 volt RMS signal will
produce maximum volume on the
speaker. Note however that signals as
large as this will cause distortion if the
sound or speech is used at the same
time.
442
CPU CLOCK WITH
CYCLE STRETCHING
(MASTER 2MHz CLOCK
SHOWN DOTTED)
T U
1MHzE
ADDRESS BUS
NPGFC
443
(or NPGFD)
P Q P Q R
CNPGFC1
(or CNPGFD1)
Q Q S V
CNPGFC2
(or CNPGFD2) tlag tlag
This standard ‘clean up’ circuit for the page select signals is
shown in figure 28.3. Three NOR gates are used to create a
standard R-S flip-flop with a gated input. The ‘clean page
select’ output (CNPGFC1) can only be set low if 1MHzE is
low. The net effect of the circuit is illustrated in figure 28.2.
Both of the problems outlined above are overcome, since the
‘P’ glitches are removed and the page select only goes low at
‘S’, after the 1MHzE clock has gone low. The ‘Q’ glitches due
to spurious addresses whilst 1MHzE is low are still there. In
most applications, this will not affect circuit operation, but
occasionally a totally glitch free page select will be required.
Circuit 2 will provide this type of page select.
444
1 14 +5V
2 13
1MHzE
3 12
CLEAN NPGFC
NPGFC or
4 11 CLEAN NPGFD
or NPGFD
5 10
6 9
0V 7 8
445
28.5.4 ‘Clean up’ circuit 2
+5V
½LS74
1MHzE
CLK PR Q
¼LS32
446
28.6 Hardware requirements for 1MHz bus peripherals
447
1 MHzE
tas tah
ADDRESS AND
READ/WRITE LINES
tpgs tpgh
NPGFC, NPGFD
tdsw tdhw
tdsr
tdhr
448
Appendix A – *FX/OSBYTE call index
brief description dec. hex.
449
brief description dec. hex.
450
brief description dec. hex.
451
brief description dec. hex.
452
brief description dec. hex.
453
brief description dec. hex.
454
Appendix B – Operating System calls summary
Routine Vector Summary of function
Name Address Name Address
455
Appendix C – Key Values Summary
Key/ ASCII INKEY Internal Key No.
character dec. hex. dec. hex. dec. hex.
SPACE 32 20 – 99 9D 98 62
! 33 21
" 34 22
# 35 23
$ 36 24
% 37 25
& 38 26
‘ 39 27
( 40 28
) 41 29
* 42 2A
+ 43 2B
, 44 2C –103 99 102 66
– 45 2D – 24 E8 23 17
. 46 2E –104 98 103 67
/ 47 2F –105 97 104 68
0 48 30 – 40 D8 39 27
1 49 31 – 49 CF 48 30
2 50 32 – 50 CE 49 31
3 51 33 – 18 EE 17 11
4 52 34 – 19 ED 18 12
5 53 35 – 20 EC 19 13
6 54 36 – 53 CB 52 34
7 55 37 – 37 DB 36 24
8 56 38 – 22 EA 21 15
9 57 39 – 39 D9 38 26
: 58 3A – 73 B7 72 48
; 59 3B – 88 A8 87 57
< 60 3C
= 61 3D
> 62 3E
? 63 3F
@ 64 40 – 72 B8 71 47
A 65 41 – 66 BE 65 41
B 66 42 –101 9B 100 64
C 67 43 – 83 AD 82 52
D 68 44 – 51 CD 50 32
E 69 45 – 35 DD 34 22
F 70 46 – 68 BC 67 43
G 71 47 – 84 AC 83 53
H 72 48 – 85 AB 84 54
I 73 49 – 38 DA 37 25
J 74 4A – 70 BA 69 45
K 75 4B – 71 B9 70 46
L 76 4C – 87 A9 86 56
M 77 4D –102 9A 101 65
N 78 4E – 86 AA 85 55
O 79 4F – 55 C9 54 36
P 80 50 – 56 C8 55 37
Q 81 51 – 17 EF 16 10
456
Key/ ASCII INKEY Internal Key No.
character dec. hex. dec. hex. dec. hex.
R 82 52 – 52 CC 51 33
S 83 53 – 82 AE 81 51
T 84 54 – 36 DC 35 23
U 85 55 – 54 CA 53 35
V 86 56 –100 9C 99 63
W 87 57 – 34 DE 33 21
X 88 58 – 67 BD 66 42
Y 89 59 – 69 BB 68 44
Z 90 5A – 98 9E 97 61
[ 91 5B – 57 C7 56 38
\ 92 5C –121 87 120 78
] 93 5D – 89 A7 88 58
^ 94 5E – 25 E7 24 18
_ 95 5F – 41 D7 40 28
£ 96 60
a 97 61
b 98 62
c 99 63
d 100 64
e 101 65
f 102 66
g 103 67
h 104 68
i 105 69
j 106 6A
k 107 6B
l 108 6C
m 109 6D
n 110 6E
o 111 6F
p 112 70
q 113 71
r 114 72
s 115 73
t 116 74
u 117 75
v 118 76
w 119 77
x 120 78
y 121 79
z 122 7A
{ 123 7B
| 124 7C
} 125 7D
~ 126 7E
457
Key/ ASCII INKEY Internal Key No.
character dec. hex. dec. hex. dec. hex.
458
Appendix D – VDU Code Summary
dec hex CTRL +bytes function
0 00 @ 0 Does nothing
1 01 A 1 Send next character to printer only
2 02 B 0 Enable printer
3 03 C 0 Disable printer
4 04 D 0 Write text at text cursor
5 05 E 0 Write text at graphics cursor
6 06 F 0 Enable VDU drivers
7 07 G 0 Make a short beep (BEL)
8 08 H 0 Move cursor back one character
9 09 I 0 Move cursor forward one character
10 0A J 0 Move cursor down one line
11 0B K 0 Move cursor up one line
12 0C L 0 Clear text area
13 0D M 0 Carriage return
14 0E N 0 Paged mode on
15 0F O 0 Paged mode off
16 10 P 0 Clear graphics area
17 11 Q 1 Define text colour
18 12 R 2 Define graphics colour
19 13 S 5 Define logical colour
20 14 T 0 Restore default logical colours
21 15 U 0 Disable VDU drivers or delete current line
22 16 V 1 Select screen MODE
23 17 W 9 Re-program display character
24 18 X 8 Define graphics window
25 19 Y 5 PLOT K,X,Y
26 1A Z 0 Restore default windows
27 1B [ 0 ESCAPE value
28 1C \ 4 Define text window
29 ID ] 4 Define graphics origin
30 1E ^ 0 Home text cursor to top left of window
31 1F _ 2 Move text cursor to X,Y
127 7F DEL 0 Backspace and delete
459
Appendix E – Plot Number Summary
0 Move relative to last point
1 Draw relative to last point in current foreground colour
2 Draw relative to last point in logical inverse colour
3 Draw relative to last point in current background colour
4 Move absolute
5 Draw absolute in current foreground colour
6 Draw absolute in logical inverse colour
7 Draw absolute in current background colour
460
Horizontal line blanking right
461
Appendix F – Screen mode layouts
Registers
462
MODE 0
&7B06
&7B07
&7D80 &7D88 &7FF8
&7D81 &7D89 &7FF9
&7D82 &7D8A &7FFA
&7D83 &7D8B &7FFB
&7D84 &7D8C &7FFC
&7D85 &7D8D &7FFD
&7D86 &7D8E &7FFE
&7D87 &7D8F &7FFF
8 PIXELS
7 6 5 4 3 2 1 0
1 BIT/PIXEL
463
MODE 1 Screen layout
Graphics 320 x 256
Colours 4
Text 40 x 32
Registers
464
MODE 1
&7B06
&7B07
&7D80 &7D88 &7FF8
&7D81 &7D89 &7FF9
&7D82 &7D8A &7FFA
&7D83 &7D8B &7FFB
&7D84 &7D8C &7FFC
&7D85 &7D8D &7FFD
&7D86 &7D8E &7FFE
&7D87 &7D8F &7FFF
4 PIXELS
7 6 5 4 3 2 1 0
2 BITS/PIXEL
465
MODE 2 Screen layout
Graphics 160 x 256
Colours 16
Text 20 x 32
Registers
466
MODE 2
&7B06
&7B07
&7D80 &7D88 &7FF8
&7D81 &7D89 &7FF9
&7D82 &7D8A &7FFA
&7D83 &7D8B &7FFB
&7D84 &7D8C &7FFC
&7D85 &7D8D &7FFD
&7D86 &7D8E &7FFE
&7D87 &7D8F &7FFF
2 PIXELS
7 6 5 4 3 2 1 0
4 BITS/PIXEL
467
MODE 3 Screen layout
Graphics Not available
Colours 2
Text 80 x 25
Registers
468
MODE 3
&7987
BLANK BLANK BLANK
BLANK BLANK BLANK
&7C00 &7C08 &7E78
&7C01 &7C09 &7E79
&7C02 &7C0A &7E7A
&7C03 &7C0B &7E7B
&7C04 &7C0C &7E7C
&7C05 &7C0D &7E7D
&7C06 &700E &7E7E
&7C07 &700F &7E7F
BLANK BLANK BLANK
BLANK BLANK BLANK
8 PIXELS
7 6 5 4 3 2 1 0
1 BIT/PIXEL
469
MODE 4 Screen layout
Graphics 320 x 256
Colours 2
Text 40 x 32
Registers
470
MODE 4
&7D86
&7D87
&7EC0 &7EC8 &7FF8
&7EC1 &7EC9 &7FF9
&7EC2 &7ECA &7FFA
&7EC3 &7ECB &7FFB
&7EC4 &7ECC &7FFC
&7EC5 &7ECD &7FFD
&7EC6 &7ECE &7FFE
&7EC7 &7ECF &7FFF
8 PIXELS
7 6 5 4 3 2 1 0
1 BIT/PIXEL
471
MODE 5 Screen layout
Graphics 160 x 256
Colours 4
Text 20 x 32
Registers
472
MODE 5
&7D86
&7D87
&7EC0 &7EC8 &7FF8
&7EC1 &7EC9 &7FF9
&7EC2 &7ECA &7FFA
&7EC3 &7ECB &7FFB
&7EC4 &7ECC &7FFC
&7EC5 &7ECD &7FFD
&7EC6 &7ECE &7FFE
&7EC7 &7ECF &7FFF
4 PIXELS
7 6 5 4 3 2 1 0
2 BITS/PIXEL
473
MODE 6 Screen layout
Graphics Not available
Colours 2
Text 40 x 25
Registers
474
MODE 6
&7CC7
BLANK BLANK BLANK
BLANK BLANK BLANK
&7E00 &7E08 &7F38
&7E01 &7E09 &7F39
&7E02 &7E0A &7F3A
&7E03 &7E0B &7F3B
&7E04 &7E0C &7F3C
&7E05 &7E0D &7F3D
&7E06 &7E0E &7F3E
&7E07 &7E0F &7F3F
BLANK BLANK BLANK
BLANK BLANK BLANK
8 PIXELS
7 6 5 4 3 2 1 0
1 BIT/PIXEL
475
MODE 7 Screen layout
Graphics TELETEXT graphics only
Colours TELETEXT
Text 40 x 25
Registers
476
MODE 7
&7C28
&7FC0 &7FE7
477
Appendix G – The American MOS differences
This Appendix outlines the fundamental differences between
the English and American BBC Microcomputers. The
hardware is basically the same in both machines, except for
minor changes in the video circuitry. The software in the
MOS is however somewhat different to cope with the
difference in television display frequency.
In the U.K version, the MOS regards the screen as 1280 points
horizontally and 1024 points vertically in all modes.
In the U.S version, the MOS regards the screen as 1280 points
horizontally (the same as in the U.K) and 800 points vertically
(compared with 1024 in the U.K).
478
G.3 Actual graphics resolution
In the U.K. the frame sync occurs at 50Hz. In the U.S, the
video frame sync occurs at 60Hz.
479
Appendix H – Disc Upgrade
Ensure that the following ICs are present:–
IC 78 8271
ICs 79,80 7438
IC 82 74LS10
ICs 81,86 74LS393
ICs 83,84 CD4013B
IC 85 CD4020B
IC 87 74LS123
S18 – NORTH
S19 – EAST
S20 – NORTH
S21 – 2 x EAST/WEST
S22 – NORTH
S32 – WEST
S33 – WEST
480
For details of the power connections see the diagrams below.
Figure H.1 shows the power supply connector on the BBC
microcomputer. Figure H.2 shows a standard disc drive
connector.
TOP
0V 0V
NO CONNECTION -5 Volts
BOTTOM 75mA
+5V 0V 0V +12V
481
S39
S23
S6*
S2
S29
S28
S9
S19
482
S1
S15
Appendix I – Link Options
S27
S16
S30A S38
S4 S8 S10 S35 S36
S37 S30B
* ISSUE 3 ONLY
There are several options which can be selected using the
links on the main circuit board. These generally take one of
three forms, a printed circuit track, a soldered wire link or a
plug-in jumper. In the list which follows, the link positions
are described in points of the compass. On this basis NORTH
is the direction looking from the keyboard towards the back
of the BBC microcomputer. The default setting is marked
with a *. All of the link positions are illustrated in Figure I.
483
8. OPEN disconnects disc head load signal from
PL8
CLOSED * connects disc head load signal to PL8
484
15. OPEN enables fast access to page &FD via
IC23
CLOSED * disables fast access to page &FD
Note link 15 must be CLOSED and R72
fitted when link 14 is OPEN.
485
22. NORTH * ROMSEL provides the LOW ROM
select bit to IC20
SOUTH A12 provides the LOW ROM select bit
to IC20
486
31. WEST * positive CSYNC to RGB video output
EAST negative CSYNC to RGB video output
487
38. OPEN allows IC101 ROM to be
‘WIRE-OR’ed
CLOSED * use IC101 ROM select from IC20
Note Link only available on issue 4.
Replaced by R153 in issues 1–3.
488
Appendix J – The keyboard circuit
The keyboard circuit is connected to the main printed circuit
board by two ribbon cables. The larger of these is fitted to all
BBC microcomputers and carries all key pressed and start-up
option data. The smaller one is connected directly to the
speech processor. With the speech system installed, this extra
connector allows serial ROMs to be plugged in to the hole on
the left hand side of the keyboard.
1 2 3 4 5 6 7 8
2
1
CORNER OF KEYBOARD
BIT
7 6 5 4 3 2 1 0
NUMBER
SWITCH
1 2 3 4 5 6 7 8
NUMBER
DEFINES
NOT NOT DISC DRIVE ACTION OF SCREEN MODE
DESCRIPTION SHIFT + AT POWER UP
USED USED SPEED SELECT AND AFTER RESET
BREAK
489
PL1
+5V
3
1MHz
2 7 10 1
11 6 P T CLR 11
PA3 D QD
10 5 IC1 12
PA2 C QC
9 4 13
PA1 B QB
8 3 74LS163 14
PA0 A QA
LOAD
9 15 14 13 12
4 A B C D
KB EN IC3
7445
SW1 +5V
7 0 1 2 3 4 5 6 7 8 9
2 S 1 2 3 4 5 6 7 9 10 11
RST
R11
10KΩ
0V 12 11
12 6 D7
PA7 W +5V
¦ R10
ESCAPE F1 F2 F3 F5 F6 F8 F9 \ 10KΩ
PL2 SK1 SK2 13 12
D6
1 1 1 +5V
10 2 2 < > ? R9
TAB Z SPACE V B M , . / COPY 10KΩ
9 14 1
C6 D5
8 +5V
47nF
+ } R8
7 IC2
ROM SHIFT S C G H N L ; ] DELETE 10KΩ
6 6 6 LOCK
CARTRIDGE 15 2
D4
UPGRADE
ONLY 5 7 7 +5V
74LS251 * R7 8
4 8 8 IC4
CAPS A X F Y J K @ : RETURN 10KΩ
LOCK
3 9 9 1 3 74LS30
D3
10 10 +5V
490
2
{ R6
11 11
1 2 D R 6 U O P [ 10KΩ
12 12 2 4
D2
13 13 +5V
14 14 £ R5
FØ W E T 7 I 9 Ø — 10KΩ
15 15 3 5
D1
C6 +5V
PL1 = ~
Q 3 4 5 F4 8 F7 6
47nF – ^ R4
7 9 D1 D2 D3 D4 D5 D6 D7 D8 D9 D10
PA6 C 10KΩ
1N4116 1N4116 1N4116 1N4116 1N4116 1N4116 1N4116 1N4116 1N4116 1N4116
6 10 4
PA5 B D0
5 11
PA4 A 2x
CTRL
SHIFT
8 7 6 5 4 3 2 1
+5V 15
+5V
C1 C2 C3 C4
0V 1
0V
+5V
16 R1 LD1
LED 1
470
17 R2 LD2
LED 2
470
13 R3 LD3
LED 3
470
Bibliography
Acorn User Magazine, published monthly, Addison Wesley
491
R6522 Versatile Interface Adapter Data Sheet, Rockwell
International, 1981
492
Glossary
Address Bus – a set of 16 connections, each one of which can
be set to logic 0 or logic 1. This allows the CPU to address
&FFFF (65536) different memory locations.
Active low – signals which are ‘active low’ are said to be valid
when they are at logic level 0.
493
Byte of memory – 8 bits of memory. Data is normally
transferred between devices one byte at a time over the data
bus.
494
High – sometimes used to designate logic ‘1’
495
Page – a page of memory in the 6502 memory map is &100
(256) bytes long. There are therefore 256 pages in the entire
address space. 256 pages of 256 bytes each account for the
65536 bytes of addressable memory.
496
Rollover – this is a function provided on the keyboard to cope
with fast typists. Two keys can be pressed at once. The
previous key with a finger being removed, and the next key
with the finger hitting the key. The software in the operating
system ensures that rollover normally operates correctly. It
doesn’t operate at all when the shift key is held down.
497
498
*SPOOL 20
Index file closing
file handle
141
204
!BOOT 218 OSFSC 344
*. 12 paged ROM service call 324
*/ 12 *T. 20
OSFSC 343 *TAPE 20, 164, 192
*B. 12 *TAPE12 20
*BASIC 12 *TAPE3 20
*CAT 12 *TV 20, 168
OSFSC 344 OS variable locations 272
ROM filing system 349 *| 12
*CO. 13 16032 second processor 435
*CODE 13 1MHz bus see One megahertz bus
user vector 256 6502
*E. 14 break flag 42
*ENABLE 14 bug 37
OSFSC 345 carry flag 41
*EXEC 14 decimal mode flag 42
file closing 141 instruction 43
file handle 203 instruction set 41
files closed at ESCAPE 149 interrupt disable 41
OSFSC 344 mnemonics 43
paged ROM service call 324 negative flag 42
*F. 15 overflow flag 42
*FX 15 program counter 42
summary table 111 second processor 434
*FX calls 109 stack pointer 42
*H. 15 status register 41
*HELP 15 unused flag 42
paged ROM service call 323 zero flag 41
*KEY 15 6522
*L. 18 versatile interface adapter 395
*LI. 16 6845
*LINE 16 address register 360
user vector 256 characters per line 361
*LOAD 18 cursor blanking 366
*M. 18 cursor positions 367
*MOTOR 18, 161, 393 cursor shape 366
*O. 18 display blanking 365
*OPT 18, 163 fast animation 373
OSFSC 343 horizontal sync 362
ROM filing system 349 horizontal timing 361
*R. 19 interlace control 364
*REMOTE 206 introduction 359
*RO. 19 lightpen software 369
*ROM 165, 192 lightpens 367
filing system 19 number of character rows 363
paged ROM service calls 324 programming 360
paged ROM software 330 register summary 375
ROM filing system 349 scan lines per character 366
*RUN 19 screen display start address 370
address 13 scrolling 371
OSFSC 344 scrolling example 374
*S. 19 vertical sync 362, 363
*SAVE 19 vertical timing 362
*SP. 20 wrap around 373
499
6850 EQUB, EQUW, EQUD, EQUS 26
IRQ bit mask 229 errors 24
6850 ACIA forward referencing 25
read/modify control register 175 from BASIC 21
76489 label 23, 25
sound chip 419 listing 24
location counter 25
A macros 29
Absolute addressing 36 mnemonics 43
Absolute, X or Y addressing 37 operand 23
Accumulator 41 OPT (options) 24
Accumulator addressing 35 syntax 23
Active low 493 two pass 25
Actual colours 382 Asynchronous 493
ADC 493 Auto-repeat
conversion complete event 290 countdown timer in zero page 270
page two locations 273 countdown timer queue 273
ADC (Add with Carry) 44 Auto-repeat delay
ADC channel keyboard 127
read current channel 196 Auto-repeat rate 128
read maximum channel number 197 Available RAM 245
ADC channel read 151
ADC conversion forcing 133 B
ADC conversion type 198 Backslash
ADC end of conversion 418 in assembler programs 23
ADC number of channel select 132 BASIC
Address bus 493 level 1 21
Addressable latch 419 level 2 21, 26
Addressing new 21
absolute 36 ROM socket with BASIC 195
absolute, X or Y 37 Baud rate 493
accumulator 35 Baud rate selection for RS423 123, 124
immediate 36 BCC (Branch on Carry Clear) 47
implicit 35 BCD 33
indexed 37 BCS (Branch on Carry Set) 48
indirect 37 BELL
modes 35 channel 214
post-indexed indirect 39 duration 217
pre-indexed indirect 38 frequency 216
relative 40 sound 215
zero page 36 BEQ (Branch on result zero) 49
zero page, X or Y 38 BGETV
ADVAL 151 OSBGET 338
American MOS Bibliography 491
differences from UK 478 Bidirectional 493
Analogue to digital converter 429, 493 Binary 31
joystick connection 432 Binary Coded Decimal 33
AND (Logical AND) 45 Bit 493
Animation BIT (Test memory bits) 50
fast hardware 373 BMI (Branch if negative) 51
ARGSV BNE (Branch if not zero) 52
OSARGS 337 BPL (Branch on positive result) 53
ASL (Arithmetic Shift Left) 46 BPUT
Assemb1er fast for Tube 176
addressing modes 35 BPUTV
conditional assembly 29 OSBPUT 339
delimiters 22
EQU 26
500
BREAK 166 Cassette critical flag
effect control 205 zero page location 270
intercept code 241 Cassette filing system see CFS
status of last BREAK 244 Cassette LED 393
Break flag 42 Cassette motor
Break vector 257 control of 161
BRK Cassette Port
handling errors 28 example input program 314
paged ROM service call 322 example output program 312
pointer in zero page 272 reading from user software 313
BRK (errors) software control 311
reading active ROM after 194 Cassette relay 18, 393
BRK (Forced interrupt) 54 Cassette tape format 347
BRK vector 257 Cassette RS423 selection flag 210, 393
BRKV 257 Catalogue
Buffer 493 *CAT 13
count/purge vector 264 CFS 346
examine status 171 page three work space 278
flush class of buffer 131 page two work space 274
flush specific buffer 138 software select switch 192
input code interpretation 224 tape format 347
insert character 172 timeout counter 185
insert vector 263 CFS options byte
insertion into 162 zero page location 269
read status 151 CFS status byte 269
remove vector 263 Character definition OSWORD 251
removing characters from 169 Chip 494
RS423 buffer limit 208 CLC (Clear carry flag) 57
Buffer CLD (Clear decimal flag) 58
page eight addresses 280 CLI (Clear interrupt disable flag) 59
Buffer busy flags Clock see system clock
page two locations 274 Clock (electronic) 494
Buffer indices 274 Clocks in software 237
Buffers Closing files
events 289 OSFIND 342
flushing at ESCAPE 149 CLV (Clear the overflow flag) 60
Bug CMP (Compare memory with A) 61
in the 6502 37 CNPV 264
in the cassette system 393 Colour code
Bus 355 selection in ULA 378
1MHz 437 Colour palette
Bus signals read OSWORD 251
clock 355 selection in ULA 379
interrupt 355 write OSWORD 252
read/write 355 Colours
reset 355 actual 382
BVC (Branch if overflow clear) 55 flashing 125, 126
BVS (Branch if overflow set) 56 logical 380
Byte 494 Command-line interpreter (CLI) 107
Command-line interpreter 11
C Control codes
CALL insertion into text 16
from BASIC 28 Countdown timer see interval timer
Carry flag 32, 41, 89 CPU (Central processing unit) 494
Cassette CPX (Compare memory with X) 63
buffer storage 280 CPY (Compare memory with Y) 64
bug 393 CRC 348
interblock gaps 18 CRTC video controller see 6845
501
CTRL G Error handling
channel 214 after a BRK 28
duration 217 BRK vectoring 257
frequency 216 using BRK 54
sound 215 ESCAPE
Cursor effect control 205
editing status 233 event 172
position 367 Escape 292
position of text cursor 158 flag 147
positions storage in page 3 275 ESCAPE
reading graphics cursors 252 providing escape action 227
shape 366 read/write flags 228
Cursor control returning an ASCII value 227
in video ULA 379 Escape character
Cursor editing 120 insertion into text 16
Cursor keys ESCAPE character read/write 223
defining as soft keys 120 ESCAPE condition acknowledge 149
Cycle (Clock) 494 ESCAPE condition clear 147
Cycle numbers 334 ESCAPE condition set 148
Cyclic redundancy checking 348 ESCAPE flag
zero page location 272
D Event
Data bus 494 ESCAPE 172
Data carrier detect 313 keyboard 172
DCD see data carrier detect Event disable
DEC (Decrement memory by one) 65 ADC conversion complete 129
Decimal flag 33, 90 character entering buffer 129
Decimal mode flag 42 ESCAPE pressed 129
Default input buffer full 129
messages 13 interval counter crossing 0 129
Default vector table 265 network error 129
DEX (Decrement X by one) 66 output buffer empty 129
DEY (Decrement Y by one) 67 RS423 error 129
Directories 333 start of vertical sync 129
Disc drive timings 246 user 129
Disc filing system 350 Event enable
Disc upgrades 480 ADC conversion complete 130
character entering buffer 130
ESCAPE pressed 130
E input buffer full 130
Econet interval counter crossing 0 130
event 293 network error 130
hardware 427 output buffer empty 130
OS call interception status 211 RS423 error 130
read character status 211 start of vertical sync 130
write character status 211 user 130
zero page work space 267 Event vector 258, 288
Econet filing system 351 Events 287
Econet vector 260 ADC conversion complete 290
Editing status of cursor 233 character entering input buffer 290
Editing using the cursor 120 disabling 129
Electrical specification for 6522 398 Econet error 293
End-of-conversion for ADC 418 enabling 130
End-of-file check 150 ESCAPE condition detected 292
Envelope command OSWORD 250 generator of using OSEVEN 107
EOR (exclusive OR memory with A) 68 handling routines 288
EQU input buffer full 289
in assembler programs 26 interval timer crossing zero 291
502
output buffer empty 289 RS423 input suppression 209
page two flags 273 RS423 use 199
RS423 error 292 RS423/cassette selection 210
user 293 soft key consistency 238
vertical sync 291 user 117, 235
EVNTV 258, 288 Flags
Example determining ESCAPE effects 228
hardware scrolling 374 Flashing
MODE 8 implementation 383 control in ULA 378
Exploding soft character RAM 136 Flashing colours 173
Extended duration of 1st colour 125
messages 13, 18 duration of 2nd colour 126
Extended vector space 281 read/write flash counter 201
Extended vectors 326 read/write mark period 201
read/write space period 201
F Floppy disc
Field 494 hardware 427
File attributes upgrade 480
OSFILE 336 Flushing buffers 131
File handle for *EXEC file 203 Font
File handle for * SPOOL file 204 reading character definitions 251
File options 163 storage 281
Files 333 Font
Files opening/closing flags on page 2 278
OSFIND 342 Font explosion
FILEV paged ROM service call 325
OSFILE 335 read definition state 191
Filing system FRED
messages 18 expansion bus 437
Filing systems 333 reading and writing 170
control vector 343 Function keys
cycle numbers 334 plus CTRL 225
directories 333 plus SHIFT 225
files 333 plus SHIFT+CTRL 225
initialise paged ROM call 325 soft key status 225
paged ROM implementation 328
Tube 345 G
zero page work space 268 Get Byte
FINDV OSBGET 338
OSFIND 342 Graphics
Fire buttons on joysticks 418 OS ROM table 282
Flag Graphics byte mask
6502 break 42 zero page location 268
6502 carry 41 Graphics colour bytes
6502 interrupt disable 41 zero page locations 268
6502 negative 42 Graphic colour cell 269
6502 overflow 42 Graphics cursor OSWORD 252
6502 unused 42 Graphic origin
6502 zero 41 storage in page 3 275
carry 32, 89 GSINIT 105
decimal 33, 90 GSREAD 106
escape 147
indicating speech presence 231 H
indicating Tube presence 230 Handshaking 494
interrupt disable 59, 91 Hard BRK 244
overflow 32, 60 Hardware
printer destination 239 introduction 353
read RS423 control flag 200 screen wrap around 419
503
High order address 154 J
HIMEM 156 JIM
Host processor 433 expansion bus 438
reading and writing 170
I JMP (Jump to new location) 72
I/O processor memory Joysticks
read OSWORD 249 connections 432
write OSWORD 249 fire buttons 418
Immediate addressing 36 JSR (Jump subroutine) 73
Implicit addressing 35
INC (Increment memory by one) 69 K
Index registers 41 Key
indexed addressing 37 read with time limit 153
Indirect addressing 37 Key number table 142
INKEY 153 Key numbers
INKEY countdown timer summary 456
page two location 273 Keyboard
Input buffer (OSWORD 0) auto-repeat delay 127
zero page location 270 auto-repeat rate 128
Input line OSWORD 248 buffer status 151
input stream selection 118 control vector 262
Instruction disable 206
6502 43 empty keyboard buffer 138
cycle 43 event 172
Instruction set for the 6502 41 function keys f0–f9 225
INSV 263 input buffer storage 279
Interlace 168, 20 input select 186
Internal key numbers table 142 insert character in buffer 172
Interrupt 495 interrupts 187
bit masks 229 LEDs 139
disable flag 41, 59, 91 links 246
forced 54 locking 206
return from 86 read status 207
unrecognised (paged ROM) 322 scan from 16 145
Interrupt vectors 258 scanning 144
Interrupts 297 selection for input 18
example program 306, 307 semaphore 187
interception 305 translation table 183
keyboard 187 write status 207
maskable 296 Keyboard auto repeat count
non-maskable 296 page two location 273
OS processing 299 Keyboard auto repeat timer
serial processing 300 zero page location 270
system VIA 302 Keyboard auto-repeat delay
user VIA 304 read/write 202
vectors 298 Keyboard auto-repeat rate 202
VIAs 413 Keyboard scan ignore character
zero page accumulator storage 272 zero page location 271
Interval timer Keys
crossing zero event 291 function keys f0–f9 225
page two address 272 Keys pressed information 142
read OSWORD 249 KEYV 262
write OSWORD 249
INX (Increment X by one) 70
INY (Increment Y by one) 71
IRQ1V 258, 298
IRQ2V 258, 299
504
L N
Label Negative flag 42
in assembler programs 25 Negative numbers
Language in machine code 31
zero page work space 267 Net
Language ROM printer 121, 260
entering 166 station identity register 428
Language ROM number 243 NETV 260
Language workspace 279 NMI 296
Languages handling routine address 281
in paged ROMs 327 paged ROM service calls 323
paged ROM entry point 325 zero page work space 267
workspace available 328 Noise generator 421
Latch 495 Non maskable interrupts 296
LDA (Load A from memory) 74 NOP (No operation) 78
LDX (Load X from memory) 75
LDY (load Y from memory) 76 O
LED 495 On error
cassette motor 161 abort 18
LEDs prompt for re-entry 18
on the keyboard 140 One megahertz bus
Lightpens cleaning up 444
construction 368 FRED—for peripherals 437
software 369 hardware requirements 447
strobe unit 418 introduction 437
Line input OSWORD 248 JIM—memory expansion 438
Link options 482 signal definitions 440
Load file timing 447
OSFILE 335 Opcode 495
Location counter Open collector 495
in assembler programs 25 Open files
Logical colours 380 OSBGET 338
LPSTB signal 418 OSBPUT 339
LSR (Logical Shift Right) 77 OSFILE 337
OSGBPB 339
M Opening files
Machine code 495 OSFIND 342
arithmetic 31 Operand 495
Macros Operating system
in assembler programs 29 OSBYTES 109
Maskable interrupts 296 version number 116
Masks for interrupts 229 Operating system 101
Memory mapped I/O GSINIT 105
reading and writing from 170 GSREAD 106
Memory refresh 359 input 101
Memory usage 267 non-vectored OSRDCH 103
Messages non-vectored OSWRCH 102
default 13 OSASCI 104
extended 13, 18 OSCLI 107
filing system 18 OSEVEN 107
Mnemonic 495 OSNEWL 103
Mnemonics 43 OSRDCH 102
MODE 8 OSRDRM 106
implementation 383 OSWRCH 101
output 101
VDU character output 104
505
Operating system high-water mark 136, 155 read line 248
OPT 24 read palette 251
Options read pixel value 250
on files 163 read system clock 248
Options at start up 246 sound command 250
ORA (OR A with memory) 79 summary 247
OS command unrecognised 256
paged ROM activation 321 user 256
unrecognised command 321 write I/O processor memory 249
OS command, unrecognised write interval timer 249
OSFSC 344 write palette 252
OS commands write system clock 249
paged ROMs 11 zero page register storage 271
zero page text pointer 271 OSWRCH 101, 104
zero page work space 268 Output stream selection 119
OS ROM tables 282 Output stream status 232
OS variables Overflow flag 32, 42, 60, 232
read start address of 180
OS version number 15 P
OSARGS 337 Page 496
CFS 346 Page mode 220
OSASCI 104 Paged ROM select register
OSBGET 338 zero page RAM copy 271
CFS 346 Paged ROMs
OSBPUT 339 *HELP service call 323
CFS 346 *ROM software 330
ROM filing system 349 absolute workspace claim 320
OSBYTE address pointer 271
paged ROM service call 322 auto boot 321
summary table 111 BRK service call 322
zero page register storage 271 claim static work space 323
OSBYTES 109 copyright string 319
OSCLI 107 EXEC/SPOOL closure warning 324
OSEVEN 107 expanded vectors location 281
OSFILE 335 filing systems 328
CFS 346 font explosion warning 325
filing system 349 information table 273
OSFIND initialise filing system 325
CFS 346 language entry point 325
ROM filing system 349 language ROMs 327
OSFSC 343 NMI service calls 323
CFS 346 OS command 321
OSGBPB 339 OS commands 11
CFS 346 private work space addresses 281
OSHWM 136, 154, 188 private work space claim 321
read 189 read byte 106
write 189 read ROM info table address 182
OSNEWL 103 read ROM pointer table address 181
OSRDCH 102 recognition bytes 317
OSRDRM 106 ROM filing system 324
OSWORD 247 ROM type byte 317
envelope command 250 select register 393
paged ROM service call 322 service call entry 320
parameter block 247 service call types 320
read character definition 251 service request 167
read graphics cursor positions 252 sockets 395
read I/O processor memory 249 title string 319
read interval timer 249 Tube service calls 325
506
unrecognised interrupt 322 R
unrecognised OSBYTE 322 RAM 496
unrecognised OSWORD 322 RAM available 245
vectored entry 326 Raster scan display 359
vectors claimed service call 324 Read byte from an open file
version number 319 OSBGET 338
version string 319 OSGBPB 339
Palette Read byte in paged ROM 106
read OSWORD 251 Read character (OSRDCH) 102
write OSWORD 252 Read character from string 106
Palette selection Read file attributes
in video ULA 379 OSARGS 337
Parallel 496 OSFILE 335
Parallel printer 121 Read I/O processor memory 249
Parameter block 28 Read line OSWORD 248
Parasite processor 434 Read user flag 117
Pass Refresh 496
in assembling programs 25 Register 496
Peripheral 496 Relative addressing 40
PHA (Push A onto stack) 80 Relay for cassette motor 393
PHP (Push status onto stack) 81 REMV 263
Phrase ROM REPORT 21, 28
logical number storage 271 Reset
Physical colours 382 soft keys 134
Pixel value OSWORD 250 ROL (Rotate Left) 84
PLA (Pull A from stack) 82 Rollover 497
PLOT numbers Rollover on keyboard input 142
expansions 261 ROM 497
summary 460 current language ROM number 243
PLP (Pull Status from stack) 83 number containing BASIC 195
POINT ROM active at last BRK 194
read pixel value 250 ROM filing system 165, 349
Poll 496 address pointer 271
POS 158 data format 349
Post-indexed indirect addressing 39 logical ROM number storage 271
Power up 356 paged ROM service calls 324
Pre-indexed indirect addressing 38 software select switch 192
Printer ROM information table 182
buffer status 151 ROM pointer table 181
destination flag 239 ROR (Rotate Right) 85
empty printer buffer 138 Row multiplication table
ignore character 122 zero page locations 269
ignored character 240 RS423
networked 260 buffer storage 280
output enabled by VDU 2 139 controlling the cassette Port 311
port 425 DCD 313
select output destination 121 empty input buffer 138
sections for output 119 empty output buffer 138
user defined 258 error detected event 292
Printer driver example program 311
going dormant warning 146 handshaking extent 208
Printers input buffer status 151
RS423 309 input select 186
Program counter 42 input suppression flag 209
Put Byte insert character in buffer 172
OSBPUT 339 interrupt processing 301
output buffer status 151
printer output 121
507
printers 309 SHEILA
read control flag 200 address &20 428
read/write mode 190 address &30 395
read/write use flag 199 addresses &00–&07 356
receive baud rate 123 addresses &08–&1F 385
RTS 312 addresses &20–&21 377
selection for input 118 addresses &40–&7F 397
selection for output 119 addresses &80–&BF 427
terminals 310 addresses &C0–&C2 429
transmit baud rate 124 addresses &E0–&FF 433
RS423 timeout counter introduction 356
zero page location 270 reading and writing 170
RS423/cassette selection flag 210, 393 SHIFT+BREAK action 246
RTI (Return from interrupt) 86 Slow data bus 417
RTS 312 Sockets for paged ROMs 395
RTS (Return from subroutine) 87 Soft BREAK 166, 244
Soft character
S RAM allocation 136
Save file Soft character explosion state 191
OSFILE 335 Soft character RAM explosion 188
SBC (Subtract memory from A) 88 Soft key
Screen *KEY 15
selection for output 119 buffer storage 281
vertical position 20 string length 219
wrap around 373 Soft keys
Screen display see 6845 and video ULA 11–15 120
Screen format 360 consistency flag 238
Screen mode function key status 225
storage in page 3 276 page two expansion pointer 273
Screen mode at power up 246 plus CTRL 225
Screen modes 359 plus SHIFT 225
layouts 462 plus SHIFT+CTRL 225
Screen positioning 168 resetting 134
Scrolling using TAB key 222
disabling 139 Sound
example 374 buffer storage 280
hardware 371 channel status 151
paged scroll selected 139 chip 419
soft scrolling selected 139 empty a sound channel buffer 138
SEC (Set Carry flag) 89 input on 1MHz bus 442
Second processor suppression status 213
16032 435 Sound command OSWORD 250
6502 434 Sound semaphore
Z80 435 page two location 274
SED (Set Decimal mode) 90 Spare vectors 264
SEI (Set interrupt disable flag) 91 Speech
Select input stream 118 buffer status 151
Select output stream 119 buffer storage 280
Serial 497 empty speech buffer 138
Serial ROM presence flag 231
reading of 177 processor 418, 423
Serial ULA read from speech processor 177
read register 236 suppression status 212
Service call entry write to speech processor 178
paged ROMs 320 Spooling
Service call types 320 selection of 119
508
STA (Store A in memory) 92 Two key roll-over
Stack 497 zero page locations 270
position in memory 272 Two's complement 31
Stack pointer 4 TXA (Transfer X to A) 98
Start up message 218 TXS (Transfer X to S) 99
Start up options 246 TYA (Transfer Y to A) 100
String processing 105
STX (Store X in memory) 93 U
STY (Store Y in memory) 94 ULA 497
Subroutine video 377
jump to 73 Uncommitted logic array 497
return from 87 Upgrading to discs 480
Syntax UPTV 258
in assembler programs 35 US MOS
System 6522 see system VIA difference from UK 478
System clock User
page two address 272 vector 13, 16
read OSWORD 248 zero page 30
write OSWORD 249 User 6522
System VIA IRQ bit mask 229
hardware 417 User defined characters 136
interrupt processing 302 User defined keys
IRQ bit mask 229 *KEY 15
User event 293
User flag 117, 235
T User port 425
TAB key definition 222 User print routine 121
Tape filing system User print routines 258
selection of 164 User print vector 258
Tape format User vector 256
CFS 347 indirect via USERV 160
TAX (Transfer A to X) 95 User VIA
TAY (Transfer A to Y) 96 interrupt processing 304
Terminals USERV 160, 256
RS423 310 *CODE 13
Text colour bytes *LINE 16
zero page locations 268 use through OSWORDs 247, 256
Text cursor USR
read character from 159 from BASIC 28
Text cursor position 158
Timer see interval timer V
Timer switch 237 VDU
Tone generators 420 page three work space 274
Transducer 497 read VDU variable value 179
Tri state 497 unrecognised codes 261
TSX (Transfer S to X) 97 VDU character output
Tube entry point 104
16032 second processor 435 VDU codes
6502 second processor 434 summary 459
fast BPUT 176 VDU driver
filing systems 345 zero page work space 268
introduction 433 VDU extension vector 261
paged ROM service calls 325 VDU queue 221
presence flag 230 storage in page 3 276
Read I/O processor memory 249 VDU status 139
ULA 433 zero page location 268
Write I/O processor memory 249 VDU variables
Z80 second processor 435 read origin of table 184
509
VDUV 261 W
Vector 253 Wait until vertical sync 135
break (BRK) 257 Windows
buffer count/purge 264 storage in page 3 275
buffer insert 263 Wrap around for screen 419
buffer remove 263 Write a new line (OSNEWL) 103
default table 265 Write byte to an open file
extended 326 OSBPUT 339
extended vector storage 281 OSGBPB 339
keyboard control 262 Write character (OSWRCH) 101
network 260 Write file attributes
spare 264 OSARGS 337
user 13, 16, 254 OSFILE 335
user printer 258 Write I/O processor memory 249
user supplied routines 254 Write user flag 117
VDU extension 261
Vectors Z
filing system control 343 Z80 second processor 435
OSFSC 343 Zero flag 41
paged ROM service call 324 Zero flag
Versatile interface adapter see VIA OS usage 267
Version user 30
operating system 15 Zero page addressing 36
Version number 116 Zero page, X or Y addressing 38
Vertical sync
event 291
wait 135
VIA
counter 404
data direction registers 400
handshaking 403
interrupts 408
printer 425
pulse counting 408
register summary 399
shift register 408
system 417
user 425
Video RAM start address
for any screen mode 157
for currently selected mode 156
Video subsystem see 6845 and Video ULA
Video ULA 377
characters per line control 378
colour mode selection 378
cursor control 379
flash control 378
palette register 379
read registers 193
teletext selection 378
write control register 173
write palette register 174
Volume control 420
VPOS 158
510
THE ADVANCED USER GUIDE
FOR THE BBC MICROCOMPUTER
This book is an essential supplement to the ‘User Guide’ provided with the
BBC microcomputer. A vast amount of useful information has been laid out
within these pages to provide the user of the BBC micro with an invaluable
reference guide, and thorough indexing and cross referencing makes all this
new data highly accessible.
The three authors are members of Cambridge University and between them
have extensive experience of using, programming and writing about the
BBC micro in a wide range of applications. Instead of merely complaining
about the lack of a well written, accurate book containing advanced
programming information, the authors decided to write it.
Information contained in ‘The Advanced User Guide’ covers both the
software and the hardware of the BBC microcomputer. Some of the many
areas covered are:
l The BASIC assembler
l A full 6502 machine code reference section
l A complete description of ALL the *FX/OSBYTE calls
l How to implement paged ROM software
l Use of events and interrupts
l A complete description of operating system workspace
l Programming the video circuitry including how to implement a 10K, 16
colour graphics mode (model A or B)
l Full descriptions of the video and serial ULAs
l Full interfacing details including use of the user port, 1 MHz bus,
analogue port and the Tube
l A comprehensive description of the BBC micro’s internal hardware
l A full circuit diagram
No serious programmer of the BBC micro can consider not owning a copy
of this invaluable reference material.