Contents / Reference section / Previous chapter / Next chapter / Index
Model B computers are fitted with a socket at the back marked "analogue in". Into this socket you can plug "games paddles" and "joy-sticks" as well as voltages which the computer can measure. Games paddles usually consist of a box with a knob like a record player volume control. The computer can tell the position of the games paddle and so it can be used in games and more serious programs, for example, to move things around the screen. Joy-sticks, on the other hand, can be moved left and right as well as up and down. As a result you can move an object anywhere on the screen not just up and down a particular line. Both games paddles and joy-sticks can be fitted with push buttons and the computer can detect when these buttons are pressed. The BBC computer can be connected to 4 games paddles or 2 joy-sticks. The BASIC function ADVAL can be used to detect the position of each control and of the fire buttons.
A second use for the analogue input is to measure voltages. Each of the four inputs can accept voltages in the range 0 to 1.8V and will produce a corresponding number in the range 0 to 65520. Since it is possible to use a "transducer" to produce a voltage proportional to temperature, light intensity, smoke density, water pressure, gas concentration etc. it is possible to use the computer to monitor all these things. If the unit is to be used to measure absolute voltages then it should be calibrated individually. In practice 1.0V input typically produces a reading of 35168. Although the unit is fitted with a twelve bit converter the user should not rely on more than 10 bit accuracy unless great care is taken with screening and analogue ground connections.
Model B of the BBC computer contains an 8 bit user-port which can be connected to a wide range of devices such as bit-pads and general interfacing boxes. The user-port can be read from or written to in BASIC and in assembly language, but in either case the user will need to know how to use the 6522 Versatile Interface Adaptor integrated circuit. A 6522 data sheet will be essential and the user will discover that this extremely versatile chip is also quite difficult to master. What follows is essential information that you will need to work the chip rather than a course in using it. Once you have learned to use it you will realise that at least twenty pages would be needed to give a decent introduction to it!
The 6522 lives in the memory map between locations &FE60 and &FE6F. The A side is used for the parallel printer port and the B side is used for the user-port. The timers and shift register are also available for the user. When writing small programs the user can address the device directly either in BASIC or in assembly language. However programs that address the device directly will not work on the far side of the Tube®. Machine code calls are provided to address the device whichever side of the Tube the program is on. Firstly, though, here are some programs in BASIC and Assembly Language to read and write to the port.
10 REM Read data in
20 REM Set Data Direction Register B
30 REM for all inputs
50 REM read a value in and PRINT it
70 PRINT X
80 GOTO 60
The next program sets up the 6522 to output to the user-port and then transfers the bottom 8 bits of X to the port. Again the initialisation need only take place once.
10 REM ALL outputs
30 REM now put X out
And here are those two programs in assembly language. First to read data into the accumulator.
100 LDA #0
110 STA &FE62
120 LDA &FE60
And secondly to write data out to the user port. This time the program is presented as two subroutines. The first, called INIT, sets up the 6522 and the second subroutine, WRITE, actually puts the data out from the accumulator onto the user-port.
200 .INIT LDA #&FF
210 STA &FE62
230 .WRITE STA &FE60
As has been made clear above these programs will not work from the second processor. The 6522 is one of the memory mapped input/output devices in the area of memory referred to as SHEILA. SHEILA controls the section of memory map in the range &FE00 to &FEFF, and the VIA (Versatile Interface Adaptor) uses addresses between &FE60 and &FE6F which are therefore SHEILA+&60 to SHEILA+&6F. Two OSBYTE calls (see page 436) are provided to read and write to SHEILA. Here are the same two routines shown above but written so that they will work over the Tube®.
100 LDA #&97 OSBYTE to write to SHEILA
110 LDX #&62 Offset to Data direction reg.
120 LDY #0 Value to be written
130 JSR &FFF4 Call OSBYTE
140 LDA #&96 OSBYTE to read from SHEILA
150 LDX #&60 Offset to data register
160 JSR &FFF4 Call OSBYTE to get value
And next the routine to INIT and WRITE to the user port.
200 .INIT LDA #&97 OSBYTE to write to SHEILA
210 LDX #&62 Offset to Data direction reg.
220 LDY #&FF All outputs
230 JSR &FFF4 Call OSBYTE
250 .WRITE TAY Move value to Y
260 LDA #&97 Write-to-SHEILA code
270 LDX #&60 Offset to data register
280 JSR &FFF4 OSBYTE call
In practice the user will often wish to use the handshake lines with data transfers. For information on this topic you are referred to other books. Space simply does not permit an adequate explanation here.