Home » CEEFAX disks » telesoftware5.adl » 20-03-88/T\OSB18

20-03-88/T\OSB18

This website contains an archive of files for the Acorn Electron, BBC Micro, Acorn Archimedes, Commodore 16 and Commodore 64 computers, which Dominic Ford has rescued from his private collection of floppy disks and cassettes.

Some of these files were originally commercial releases in the 1980s and 1990s, but they are now widely available online. I assume that copyright over them is no longer being asserted. If you own the copyright and would like files to be removed, please contact me.

Tape/disk: Home » CEEFAX disks » telesoftware5.adl
Filename: 20-03-88/T\OSB18
Read OK:
File size: 5531 bytes
Load address: 0000
Exec address: FFFFFFFF
File contents
OSBITS - An Exploration of the BBC Micro at Machine Level

By Programmer

..........................................................


Part 18: Interrupts I


Bear with me while I repeat the definition of foreground
versus background I originally gave in the last module.

Here you are reading a module of OSbits when the telephone
rings.  You stop reading, answer the 'phone and talk to
whoever is ringing.  When you have finished you put the
'phone down and start reading again.

Reading was your main, or foreground task, but it was
interrupted by the telephone.  The ringing of the 'phone was
an interrupt and by answering the 'phone you handled (or
serviced) that interrupt.  When you had finished you
returned to your foreground task.

As I said last time one of the strengths of the 6502
microprocessor is its response to interrupts.  Essentially
pieces of hardware interrupt the 6502 and the OS has a
built-in pecking order for these devices so it knows in
which order to respond.

In the last module we looked at Events.  These are a
packaged form of interrupt and some of the difficult aspects
of handling interrupts are taken care of by the OS. This
time I plan to get down to a more basic level so that you
will know how to deal with an interrupt directly yourself.

Although an Event can be serviced in a second processor
(with limits on calling OS routines) interrupts can only be
serviced in the I/O processor.  So this module's program
will not work in a second processor and if it thinks you
have one it will ask you to turn it off.

Firstly we must mention that there are two different kinds
of interrupt recognised by the 6502.  They are the maskable
and non-maskable interrupts and in both cases are generated
by hardware changing the voltage on one of two separate pins
of the 6502.  Non-maskable interrupts (NMIs) are usually
generated by devices that need very fast response from the
micro.  The standard unexpanded BBC B has no such devices
and disc and Econet interfaces are usually the only
additional modules that use NMIs.  Page D of memory is used
for NMI workspace which is why the user can make use of that
page on an unexpanded B but not on any other machine.

The masking referred to in the name is the ability to make
the 6502 ignore the requests for interrupt handling by
using the interrupt flag.  Simply put, setting the interrupt
flag (with an SEI) will not stop the machine responding to
NMIs.  There is no way to stop an non-maskable interrupt.

There are three distinct aspects to interrupt handling:
intercepting the vector, checking that you are going to
handle the right interrupt, and the interrupt handling code
itself.

Intercepting the vector is carried out exactly as you would
when intercepting any other vector, although you should
understand the distinction between the two interrupt vectors
IRQ1 and IRQ2 (IRQ stands for Interrupt ReQuest).  IRQ1 and
IRQ2 have different priorities.  An interrupt request first
passes through IRQ1 to the standard interrupt handling
routines in the OS which do system housekeeping.  Then the
interrupt is passed through IRQ2.  Diagrammatically it's
like this:

            Interrupt Detected
            Vectored through IRQ1
            System interrupt handling
            Vectored through IRQ2
            User interrupt handling

This reflects what I called the pecking order.  The system
housekeeping has to be done urgently.  If your interrupt
routine is not urgent then it should intercept IRQ2.  Only
intercept IRQ1 if it is important for there to be a fast
response to your code.

The OS sets up various parameters in the micro in a standard
way so that you know the state of the machine when you
intercept IRQ1 or IRQ2.  It happens like this.

When a maskable interrupt is detected by the 6502 it
promptly checks to see if it has been caused by a BRK in the
code it was executing (by looking at the state of the BRK
flag).  If it was then the processor executes the current
error routine having found it by going through the break
vector.

If the break flag was not set then a hardware interrupt was
the cause of the interrupt.  This is the condition we are
studying in this module.

Having determined that an IRQ has indeed occurred the 6502
jumps to the contents of the IRQ1V vector.  Until now this
has happened automatically and the user does not need to
worry about it.  Now though the OS is preparing to hand over
to interrupt handling routines and the following is known
about the state of the micro because the OS has set it up
this way:

The value of the accumulator at the time of the interrupt is
stored in memory location &FC in the I/O processor.  The
status register and the return address (the address of the
instruction about to be actioned when the interrupt
occurred) are stored on the stack ready for an RTI (ReTurn
from Interrupt) at the end of the interrupt code.  The
original X and Y register values are still in place.

Any interrupt handling code you write should leave the micro
and registers in this state afterwards.

So, on entry to your code you must:

        Save the contents of &FC on the stack
        Save the X and Y registers on the stack
        Clear the decimal flag

and on exit you must
 
        Reload the Y and X registers from the stack
        Transfer the original accumulator value from the
            stack to &FC

Clearing the decimal flag is a safety measure in case the
routine being executed at the time of the interrupt was
working in decimal mode.  This is unlikely.  As the status
register is re-set by the RTI instruction at the very end of
the interrupt chain then you need not worry about the status
of the original flags yourself during interrupt handling
except for the effect decimal mode might have on your code. 
So clear it!

[There is a very strong argument for NEVER using decimal
mode on the BBC Micro.  The OS always assumes binary mode
and so, probably, do other people's interrupt routines.  You
should therefore always disable interrupts when using
decimal mode to avoid trashing somebody else's interrupts. 
I know I didn't do this back in module 6 but several people
have since pointed out the dangers.]

The code will look like this:

               LDA &FC
               PHA
               TXA
               PHA
               TYA
               PHA
               CLD

and on exit

               PLA
               TAY
               PLA
               TAX
               PLA
               STA &FC
               RTI

or you might JMP (old_IRQ) to continue down the IRQ chain.


Checking to see if you have the right interrupt is not as
simple as the Event system where you check the number in the
accumulator.  With an interrupt you have to look in the
registers of the piece of hardware to which your interrupt handling
routine refers.

With a single routine this is relatively simple, just be
thankful you don't have the job of the OS which has many
devices to service.  The OS has to look at the system VIA
(versatile interface adapter), the serial system (for the
cassette filing system and the RS423) and one part of the
user VIA which deals with parallel printers.  These
interrupt possibilities are all handled by the time program
execution has reached IRQ2.

The best place to look for details of these devices is in
your advanced guide.  It is a little beyond the scope of
this series to get into too much reference detail, that is
best done on paper.  However I will give an example which I
hope will serve for all system interrupts.

The BBC Micro has two VIAs.  These are very versatile chips
(as the name Versatile Interface Adapter suggests) and
contain timers, counters and other bits and pieces (!).  One
of these is set aside for the parallel printer and for the
user (you) and I will be dealing with two aspects of this in
detail later.  The other one is used by the OS for system
housekeeping.

The system VIA will generate an interrupt when ....

  a key is pressed
  the TV picture reaches the vertical interval and flies
      back (50 times a second)
  the lightpen detects the scan spot from the screen
  the A to D converter completes a conversion
  either of the two VIA timers reaches zero

It can also generate an interrupt when its shift register
(which counts pulses) times out, but this is not used by the
OS so should never happen.

The OS, when it detects an interrupt, needs to check its
pieces of hardware to see where the interrupt came from in
order to correctly handle it.  It can quickly check if an
interrupt came from a particular device since each device
has a flag that is set when any interrupt comes from it.
This is besides a flag to identify the actual part of the
device that caused the interrupt.

So the OS only has to look at the flag on each device and
then check the flag register on the device that says it
caused the interrupt.  It doesn't have to check all the
flags on all the devices.  This is important because
interrupts, like events, have to be handled very quickly. 
If it takes a long time to handle an interrupt then the OS
will stop some of its functions for a while, which could
cause problems.

After an IRQ has occurred the OS will check the interrupt
flag on the system VIA, the serial ULA and the user VIA
until it finds the device that caused the IRQ.  It will then
check the device itself to identify the particular cause. 
If this is one which the OS expects to service, it will do
so and then return.  If it is one which the OS doesn't
recognise it passes it on through IRQ2.

It is possible to stop the OS servicing an interrupt it
would normally do by using OSBYTE 231 to 233 which can force
the OS to pass a particular interrupt through IRQ2 for the
user to deal with.  This is known as masking the IRQ and you
should consult your advanced guide for details.  [There are
example programs which use IRQ masking on pages 306 and 308
of Bray, Dickens and Holmes.]

I hope you will see why interrupts are a 'risky' area for
experimentation, since it is all too easy to make the
computer hang up.  However, it is unlikely to explode so the
worst that can happen is that you will have to press BREAK
and start again.

I think it is best to proceed from here with examples.  I
plan to show you more of the VIA timers in the next module
but for now I will initiate you into the little known sport
of mouse driving.  A mouse driver is a piece of code that
keeps track of the movement of a mouse (i.e. a pointing
device) attached to the micro and enables you to implement a
pointer system on the screen.  I shall use the AMX mouse as
my example, although the Megamouse uses the same code.  Even
if you do not posses a mouse I hope you will find the
example useful.

This mouse is connected to the micro's user port and so to
the user VIA behind it.  As the mouse is moved a small
voltage (also taken from the user port) is applied to four
wires in the connecting cable in such a way that you can
detect the direction of motion at any instant.  The mouse
doesn't tell you where it is, it tells you in which
direction it is moving.

The waveform of the voltage is rectangular, like a square
wave, and if we call the connections X1 Y1 X2 and Y2 the
following rules apply.

If the mouse moves left to right (or vice versa) a waveform
if applied to the X1 and X2 wires such that if it moves one
way the signals are high at the same time and low at the
same time (i.e. in phase) and if it moves the other the
signals are different at any instant (i.e. out of phase). 
Similarly for the Y wires when the mouse moves backwards and
forwards.

X1 and Y1 are connected to the two interrupt lines on the
user port so they can be used to generate an interrupt from
the user VIA.  We will set the VIA to generate this
interrupt whenever the VIA line detects a positive going
voltage (i.e. the front porch of the rectangular waveform)
from either line.

When the interrupt occurs we look at the corresponding
second line (X2 or Y2) to see if it is high or low at that
moment and hence deduce which way the mouse is moving.

As I have said, the lines on the user port are connected to
the user VIA.  In fact the user port connects to the 'B'
side of this device and the parallel printer connects to the
other.  The VIA is a device called a 6522 and information on
how to use it can be gleaned (with a little difficulty) from
the specification sheets for the device.  Bray, Dickens and
Holmes (Advanced User Guide) also reprints the information
from the spec sheet.

In brief the device is set up by poking bits in its
registers.  On the BBC Micro those registers live in the
area of memory known as Sheila and the user VIA lives from
&FE60 to &FE6F.  There are 16 registers as follows:

 &FE60  I/O for the 'B' side of the VIA
     1  I/O for the 'A' side of the VIA
     2  Control of the direction of data on the 'B' side
     3  Control of the direction of data on the 'A' side
     4  Timer 1 control
     5  Timer 1 control
     6  Timer 1 control
     7  Timer 1 control
     8  Timer 2 control
     9  Timer 2 control
     A  Shift register
     B  Auxiliary control
     C  Peripheral control
     D  Interrupt flags
     E  Interrupt enabling
     F  Same as register 1 but without handshaking

There's a lot in the VIAs.  I'll show you an application
using a timer in the next module.  The shift register is
used for counting pulses.  The auxiliary control sets
parameters for the timers and shift register and the
peripheral control sets up the way the interrupt lines
respond to the voltages applied to them.

To access these sections of memory you would normally use
OSBYTE with A between 146 and 151.  These calls read from
and write to the memory-mapped I/O (Fred, Jim and Sheila) as
follows.

    OSBYTE 146 - Read Fred (&FC00 to &FCFF)
    OSBYTE 147 - Write Fred
    OSBYTE 148 - Read Jim (&FD00 to &FDFF)
    OSBYTE 149 - Write Jim
    OSBYTE 150 - Read Sheila (&FE00 to &FEFF)
    OSBYTE 151 - Write Sheila

In each case, on entry X contains the offset within the page
and, if a write, Y contains the byte.  On exit, if a read, Y
contains the byte read.  This call will presumably work
wherever Fred Jim and Sheila are located in future machines. 

Alternatively you could use OSWORDs 5 and 6 to read or write
to I/O processor memory.  The OSWORD parameter block, at the
location pointed to by the X and Y registers, contains the
address in the I/O processor in the first 4 bytes and in the
5th byte is put, or is read, the byte to be transferred
across.  The OSBYTE calls and the OSWORD calls work across
the tube, i.e. from a second processor.

In the case of interrupts your intercepting code has to be
in the I/O processor, so cross-tube requirements do not come
into it.  If we take the (small) risk that Sheila will move
in future the best thing to do is write and read the memory
locations directly.  Any interrupt code must be short and to
the point, so we should avoid unnecessary OS calls.  In any
case there is a restriction on which OS calls can be used
during interrupts.  I will give you more detail in the next
module.

In this module we shall deal directly with the registers of
the VIA.  To set up the VIA to detect the mouse we must do
three things.  We must enable the interrupts we are going to
use, set up the behaviour of the interrupt lines and set up
the relevant bits of the user port to act as inputs.

The first section of the machine code in B/osb18 resets the
IRQ vector.  I have used IRQ1 because we need a fast
response to the mouse interrupt.  When you have seen this
code in action you should change the value of 'irq1' in line
130 to &206 and compare the results.  [Note that if you have
an AMX mouse chip in your machine you must remove or disable
it before you can get ANY result from using IRQ2 at &206.] 

We must enable interrupts from the two 'B' side interrupt
lines, known as CB1 and CB2.  To do this we make sure that
bits 3 and 4 are set by ORing the current contents of this
register with 24 (8+16) and re-saving.

To make CB1 and CB2 operate as we wish, by interrupting on
the positive-going edge of the waveform, we have to set bits
4 and 6 of the peripheral control register.  This is also
best done by ORing the current contents with 80 (16+64).  As
you can see from the listing at lines 390 and 430 the BBC
assembler allows you to use an addition to define the bits
being used.  You could even change line 430 to ORA
#(2^4+2^6) if that makes it clearer to you.  This will make
no difference to the final code, it just makes the source
code more readable.

As we are going to use the user port as an input we write
zero into the data direction register which, as it clears
all the bits, makes all the lines function as inputs.  The
buttons of the mouse will be read from these lines if you
want them, so it is worth clearing all the bits.

You will notice that I disabled interrupts while modifying
the VIA registers.  This makes sure that another routine
can't get in and modify the registers while you are doing
it.  Of course it may well be that another routine that
uses this function of the VIA would cause a malfunction, but
if there is any chance of the two routines coexisting then
let's take it.  That's why this routine avoids affecting
other register bits unnecessarily.

The variables appear next.  You can change 'scale' if you
want finer or coarser pointer control but a value of 2 is a
good place to start.  The X and Y coordinates of the pointer
controlled by the mouse are stored next.  I have allocated
four bytes for each even though screen coordinates only have
two bytes.  This is to enable us to read the coordinate with
the ! operator from BASIC.  More on this later.  The final
variable space holds the old value of IRQ1 to allow
chaining.

When any interrupt (other than an NMI) is detected execution
jumps down the IRQ1 vector.  The first thing in that vector
is our code here.  The standard routine, to reclaim the
acumulator value from &FC and store the registers, is
carried out in lines 610 to 660.  In fact there is no need
to save the X and Y registers because this program does not
change them but, belt and braces, it's best to get into the
habit of saving all registers.  Similarly we make sure the
processor is in binary rather than decimal mode.

Next we have to make sure that the cause of the interrupt is
the one for our code.  Since interrupts are happening
continuously in the BBC Micro we must be sure we only
service the right ones.  If the user VIA caused an interrupt
than bit 7 of its interrupt flag register (IFR) will be set. 
Lines 730 and 740 check this.

If the user VIA did indeed cause the interrupt we must check
to see that it was CB1 or CB2, our two interrupt lines, that
were responsible.  If it was CB2 (caused by the Y1 line)
then bit 3 of the IFR will be set, if it was CB1 (caused by
the X1 line) then bit 4 of the IFR will be set.  Lines 760
to 820 check for this and route execution accordingly using
the BIT opcode.  This performs an AND but does not store the
result; indeed an AND would work equally well here.  If at
the end of this we know that the interrupt was not caused by
CB1 or CB2 then we must chain on down IRQ1 so someone else
can service the interrupt.

You must clear an interrupt when you service it, otherwise
the 6502 will still signal it.  In this case with interrupts
from CB1 and CB2 you do not have to clear explicitly. 
Reading from the data lines on the user port will do the job
automatically.

The code operates in a similar way whether an X or Y pulse
caused the interrupt. The relevant second line is tested to
see if it is high or low at the moment of the interrupt. 
[Note that if you use IRQ2 the delay before servicing the
interrupt is sufficient to cause false readings at this
point and the pointer can go the wrong way.  Using IRQ1
avoids this problem.]  If we move positively then the
relevant coordinate location is increased by 'scale' and
decreased of we move negatively.  After this has been done
the routine exits by restoring the registers and then
performing an RTI.

The BASIC shell around this program prints a pointer (a
cross) in the centre of the screen and smears it around as
you move the mouse.  The X and Y coordinates are read using
the ! operator to minimise errors due to the coordinates
changing while they are being read.  If you were to read the
two bytes of the coordinates separately using ? operators
you would get some incorrect results, try it and see.

This code will work with a Marconi Trackerball, although the
pin connections are different to the AMX mouse.  The data
sheet with the trackerball will advise you on which pins are
which.  CB1 and CB2 are used but the second lines are
different to those used in this program.  Lines 960 and 1240
would need to be changed to load 16 and 8 respectively
because bits 4 and 3 carry Y2 and X2.

Of course this code does not implement a proper mouse
pointer in the way Acorn's VFS or AMX's Super-Art ROM does,
but it should give you a basic idea of how an interrupt is
handled.

You should also notice that I have put the code in the
cassette/RS423 input buffer.  If you use a cassette (if you
do you should be saving for a disc drive) or have a modem or
something that uses RS423 inputs then running this code will
crash your computer.  Perhaps the safest thing to do would
be to raise PAGE by &100 (256) bytes and put the code in
there: but on most Bs and B+s PAGE is too high anyway.  I
leave it up to you.

Remember that the vectors are re-set on pressing BREAK. 
Also you will notice that this time I haven't allowed for
the code to be called twice without a BREAK.  Doing this
will lock up the computer.

Next time we will set up a VIA timer to palette switch on
the screen to get several colours in mode 3, in a limited
way.
00000000  4f 53 42 49 54 53 20 2d  20 41 6e 20 45 78 70 6c  |OSBITS - An Expl|
00000010  6f 72 61 74 69 6f 6e 20  6f 66 20 74 68 65 20 42  |oration of the B|
00000020  42 43 20 4d 69 63 72 6f  20 61 74 20 4d 61 63 68  |BC Micro at Mach|
00000030  69 6e 65 20 4c 65 76 65  6c 0d 0d 42 79 20 50 72  |ine Level..By Pr|
00000040  6f 67 72 61 6d 6d 65 72  0d 0d 2e 2e 2e 2e 2e 2e  |ogrammer........|
00000050  2e 2e 2e 2e 2e 2e 2e 2e  2e 2e 2e 2e 2e 2e 2e 2e  |................|
*
00000080  2e 2e 2e 2e 0d 0d 0d 50  61 72 74 20 31 38 3a 20  |.......Part 18: |
00000090  49 6e 74 65 72 72 75 70  74 73 20 49 0d 0d 0d 42  |Interrupts I...B|
000000a0  65 61 72 20 77 69 74 68  20 6d 65 20 77 68 69 6c  |ear with me whil|
000000b0  65 20 49 20 72 65 70 65  61 74 20 74 68 65 20 64  |e I repeat the d|
000000c0  65 66 69 6e 69 74 69 6f  6e 20 6f 66 20 66 6f 72  |efinition of for|
000000d0  65 67 72 6f 75 6e 64 0d  76 65 72 73 75 73 20 62  |eground.versus b|
000000e0  61 63 6b 67 72 6f 75 6e  64 20 49 20 6f 72 69 67  |ackground I orig|
000000f0  69 6e 61 6c 6c 79 20 67  61 76 65 20 69 6e 20 74  |inally gave in t|
00000100  68 65 20 6c 61 73 74 20  6d 6f 64 75 6c 65 2e 0d  |he last module..|
00000110  0d 48 65 72 65 20 79 6f  75 20 61 72 65 20 72 65  |.Here you are re|
00000120  61 64 69 6e 67 20 61 20  6d 6f 64 75 6c 65 20 6f  |ading a module o|
00000130  66 20 4f 53 62 69 74 73  20 77 68 65 6e 20 74 68  |f OSbits when th|
00000140  65 20 74 65 6c 65 70 68  6f 6e 65 0d 72 69 6e 67  |e telephone.ring|
00000150  73 2e 20 20 59 6f 75 20  73 74 6f 70 20 72 65 61  |s.  You stop rea|
00000160  64 69 6e 67 2c 20 61 6e  73 77 65 72 20 74 68 65  |ding, answer the|
00000170  20 27 70 68 6f 6e 65 20  61 6e 64 20 74 61 6c 6b  | 'phone and talk|
00000180  20 74 6f 0d 77 68 6f 65  76 65 72 20 69 73 20 72  | to.whoever is r|
00000190  69 6e 67 69 6e 67 2e 20  20 57 68 65 6e 20 79 6f  |inging.  When yo|
000001a0  75 20 68 61 76 65 20 66  69 6e 69 73 68 65 64 20  |u have finished |
000001b0  79 6f 75 20 70 75 74 20  74 68 65 0d 27 70 68 6f  |you put the.'pho|
000001c0  6e 65 20 64 6f 77 6e 20  61 6e 64 20 73 74 61 72  |ne down and star|
000001d0  74 20 72 65 61 64 69 6e  67 20 61 67 61 69 6e 2e  |t reading again.|
000001e0  0d 0d 52 65 61 64 69 6e  67 20 77 61 73 20 79 6f  |..Reading was yo|
000001f0  75 72 20 6d 61 69 6e 2c  20 6f 72 20 66 6f 72 65  |ur main, or fore|
00000200  67 72 6f 75 6e 64 20 74  61 73 6b 2c 20 62 75 74  |ground task, but|
00000210  20 69 74 20 77 61 73 0d  69 6e 74 65 72 72 75 70  | it was.interrup|
00000220  74 65 64 20 62 79 20 74  68 65 20 74 65 6c 65 70  |ted by the telep|
00000230  68 6f 6e 65 2e 20 20 54  68 65 20 72 69 6e 67 69  |hone.  The ringi|
00000240  6e 67 20 6f 66 20 74 68  65 20 27 70 68 6f 6e 65  |ng of the 'phone|
00000250  20 77 61 73 0d 61 6e 20  69 6e 74 65 72 72 75 70  | was.an interrup|
00000260  74 20 61 6e 64 20 62 79  20 61 6e 73 77 65 72 69  |t and by answeri|
00000270  6e 67 20 74 68 65 20 27  70 68 6f 6e 65 20 79 6f  |ng the 'phone yo|
00000280  75 20 68 61 6e 64 6c 65  64 20 28 6f 72 0d 73 65  |u handled (or.se|
00000290  72 76 69 63 65 64 29 20  74 68 61 74 20 69 6e 74  |rviced) that int|
000002a0  65 72 72 75 70 74 2e 20  20 57 68 65 6e 20 79 6f  |errupt.  When yo|
000002b0  75 20 68 61 64 20 66 69  6e 69 73 68 65 64 20 79  |u had finished y|
000002c0  6f 75 0d 72 65 74 75 72  6e 65 64 20 74 6f 20 79  |ou.returned to y|
000002d0  6f 75 72 20 66 6f 72 65  67 72 6f 75 6e 64 20 74  |our foreground t|
000002e0  61 73 6b 2e 0d 0d 41 73  20 49 20 73 61 69 64 20  |ask...As I said |
000002f0  6c 61 73 74 20 74 69 6d  65 20 6f 6e 65 20 6f 66  |last time one of|
00000300  20 74 68 65 20 73 74 72  65 6e 67 74 68 73 20 6f  | the strengths o|
00000310  66 20 74 68 65 20 36 35  30 32 0d 6d 69 63 72 6f  |f the 6502.micro|
00000320  70 72 6f 63 65 73 73 6f  72 20 69 73 20 69 74 73  |processor is its|
00000330  20 72 65 73 70 6f 6e 73  65 20 74 6f 20 69 6e 74  | response to int|
00000340  65 72 72 75 70 74 73 2e  20 20 45 73 73 65 6e 74  |errupts.  Essent|
00000350  69 61 6c 6c 79 0d 70 69  65 63 65 73 20 6f 66 20  |ially.pieces of |
00000360  68 61 72 64 77 61 72 65  20 69 6e 74 65 72 72 75  |hardware interru|
00000370  70 74 20 74 68 65 20 36  35 30 32 20 61 6e 64 20  |pt the 6502 and |
00000380  74 68 65 20 4f 53 20 68  61 73 20 61 0d 62 75 69  |the OS has a.bui|
00000390  6c 74 2d 69 6e 20 70 65  63 6b 69 6e 67 20 6f 72  |lt-in pecking or|
000003a0  64 65 72 20 66 6f 72 20  74 68 65 73 65 20 64 65  |der for these de|
000003b0  76 69 63 65 73 20 73 6f  20 69 74 20 6b 6e 6f 77  |vices so it know|
000003c0  73 20 69 6e 0d 77 68 69  63 68 20 6f 72 64 65 72  |s in.which order|
000003d0  20 74 6f 20 72 65 73 70  6f 6e 64 2e 0d 0d 49 6e  | to respond...In|
000003e0  20 74 68 65 20 6c 61 73  74 20 6d 6f 64 75 6c 65  | the last module|
000003f0  20 77 65 20 6c 6f 6f 6b  65 64 20 61 74 20 45 76  | we looked at Ev|
00000400  65 6e 74 73 2e 20 20 54  68 65 73 65 20 61 72 65  |ents.  These are|
00000410  20 61 0d 70 61 63 6b 61  67 65 64 20 66 6f 72 6d  | a.packaged form|
00000420  20 6f 66 20 69 6e 74 65  72 72 75 70 74 20 61 6e  | of interrupt an|
00000430  64 20 73 6f 6d 65 20 6f  66 20 74 68 65 20 64 69  |d some of the di|
00000440  66 66 69 63 75 6c 74 20  61 73 70 65 63 74 73 0d  |fficult aspects.|
00000450  6f 66 20 68 61 6e 64 6c  69 6e 67 20 69 6e 74 65  |of handling inte|
00000460  72 72 75 70 74 73 20 61  72 65 20 74 61 6b 65 6e  |rrupts are taken|
00000470  20 63 61 72 65 20 6f 66  20 62 79 20 74 68 65 20  | care of by the |
00000480  4f 53 2e 20 54 68 69 73  0d 74 69 6d 65 20 49 20  |OS. This.time I |
00000490  70 6c 61 6e 20 74 6f 20  67 65 74 20 64 6f 77 6e  |plan to get down|
000004a0  20 74 6f 20 61 20 6d 6f  72 65 20 62 61 73 69 63  | to a more basic|
000004b0  20 6c 65 76 65 6c 20 73  6f 20 74 68 61 74 20 79  | level so that y|
000004c0  6f 75 0d 77 69 6c 6c 20  6b 6e 6f 77 20 68 6f 77  |ou.will know how|
000004d0  20 74 6f 20 64 65 61 6c  20 77 69 74 68 20 61 6e  | to deal with an|
000004e0  20 69 6e 74 65 72 72 75  70 74 20 64 69 72 65 63  | interrupt direc|
000004f0  74 6c 79 20 79 6f 75 72  73 65 6c 66 2e 0d 0d 41  |tly yourself...A|
00000500  6c 74 68 6f 75 67 68 20  61 6e 20 45 76 65 6e 74  |lthough an Event|
00000510  20 63 61 6e 20 62 65 20  73 65 72 76 69 63 65 64  | can be serviced|
00000520  20 69 6e 20 61 20 73 65  63 6f 6e 64 20 70 72 6f  | in a second pro|
00000530  63 65 73 73 6f 72 0d 28  77 69 74 68 20 6c 69 6d  |cessor.(with lim|
00000540  69 74 73 20 6f 6e 20 63  61 6c 6c 69 6e 67 20 4f  |its on calling O|
00000550  53 20 72 6f 75 74 69 6e  65 73 29 20 69 6e 74 65  |S routines) inte|
00000560  72 72 75 70 74 73 20 63  61 6e 20 6f 6e 6c 79 20  |rrupts can only |
00000570  62 65 0d 73 65 72 76 69  63 65 64 20 69 6e 20 74  |be.serviced in t|
00000580  68 65 20 49 2f 4f 20 70  72 6f 63 65 73 73 6f 72  |he I/O processor|
00000590  2e 20 20 53 6f 20 74 68  69 73 20 6d 6f 64 75 6c  |.  So this modul|
000005a0  65 27 73 20 70 72 6f 67  72 61 6d 0d 77 69 6c 6c  |e's program.will|
000005b0  20 6e 6f 74 20 77 6f 72  6b 20 69 6e 20 61 20 73  | not work in a s|
000005c0  65 63 6f 6e 64 20 70 72  6f 63 65 73 73 6f 72 20  |econd processor |
000005d0  61 6e 64 20 69 66 20 69  74 20 74 68 69 6e 6b 73  |and if it thinks|
000005e0  20 79 6f 75 0d 68 61 76  65 20 6f 6e 65 20 69 74  | you.have one it|
000005f0  20 77 69 6c 6c 20 61 73  6b 20 79 6f 75 20 74 6f  | will ask you to|
00000600  20 74 75 72 6e 20 69 74  20 6f 66 66 2e 0d 0d 46  | turn it off...F|
00000610  69 72 73 74 6c 79 20 77  65 20 6d 75 73 74 20 6d  |irstly we must m|
00000620  65 6e 74 69 6f 6e 20 74  68 61 74 20 74 68 65 72  |ention that ther|
00000630  65 20 61 72 65 20 74 77  6f 20 64 69 66 66 65 72  |e are two differ|
00000640  65 6e 74 20 6b 69 6e 64  73 0d 6f 66 20 69 6e 74  |ent kinds.of int|
00000650  65 72 72 75 70 74 20 72  65 63 6f 67 6e 69 73 65  |errupt recognise|
00000660  64 20 62 79 20 74 68 65  20 36 35 30 32 2e 20 20  |d by the 6502.  |
00000670  54 68 65 79 20 61 72 65  20 74 68 65 20 6d 61 73  |They are the mas|
00000680  6b 61 62 6c 65 0d 61 6e  64 20 6e 6f 6e 2d 6d 61  |kable.and non-ma|
00000690  73 6b 61 62 6c 65 20 69  6e 74 65 72 72 75 70 74  |skable interrupt|
000006a0  73 20 61 6e 64 20 69 6e  20 62 6f 74 68 20 63 61  |s and in both ca|
000006b0  73 65 73 20 61 72 65 20  67 65 6e 65 72 61 74 65  |ses are generate|
000006c0  64 0d 62 79 20 68 61 72  64 77 61 72 65 20 63 68  |d.by hardware ch|
000006d0  61 6e 67 69 6e 67 20 74  68 65 20 76 6f 6c 74 61  |anging the volta|
000006e0  67 65 20 6f 6e 20 6f 6e  65 20 6f 66 20 74 77 6f  |ge on one of two|
000006f0  20 73 65 70 61 72 61 74  65 20 70 69 6e 73 0d 6f  | separate pins.o|
00000700  66 20 74 68 65 20 36 35  30 32 2e 20 20 4e 6f 6e  |f the 6502.  Non|
00000710  2d 6d 61 73 6b 61 62 6c  65 20 69 6e 74 65 72 72  |-maskable interr|
00000720  75 70 74 73 20 28 4e 4d  49 73 29 20 61 72 65 20  |upts (NMIs) are |
00000730  75 73 75 61 6c 6c 79 0d  67 65 6e 65 72 61 74 65  |usually.generate|
00000740  64 20 62 79 20 64 65 76  69 63 65 73 20 74 68 61  |d by devices tha|
00000750  74 20 6e 65 65 64 20 76  65 72 79 20 66 61 73 74  |t need very fast|
00000760  20 72 65 73 70 6f 6e 73  65 20 66 72 6f 6d 20 74  | response from t|
00000770  68 65 0d 6d 69 63 72 6f  2e 20 20 54 68 65 20 73  |he.micro.  The s|
00000780  74 61 6e 64 61 72 64 20  75 6e 65 78 70 61 6e 64  |tandard unexpand|
00000790  65 64 20 42 42 43 20 42  20 68 61 73 20 6e 6f 20  |ed BBC B has no |
000007a0  73 75 63 68 20 64 65 76  69 63 65 73 0d 61 6e 64  |such devices.and|
000007b0  20 64 69 73 63 20 61 6e  64 20 45 63 6f 6e 65 74  | disc and Econet|
000007c0  20 69 6e 74 65 72 66 61  63 65 73 20 61 72 65 20  | interfaces are |
000007d0  75 73 75 61 6c 6c 79 20  74 68 65 20 6f 6e 6c 79  |usually the only|
000007e0  0d 61 64 64 69 74 69 6f  6e 61 6c 20 6d 6f 64 75  |.additional modu|
000007f0  6c 65 73 20 74 68 61 74  20 75 73 65 20 4e 4d 49  |les that use NMI|
00000800  73 2e 20 20 50 61 67 65  20 44 20 6f 66 20 6d 65  |s.  Page D of me|
00000810  6d 6f 72 79 20 69 73 20  75 73 65 64 0d 66 6f 72  |mory is used.for|
00000820  20 4e 4d 49 20 77 6f 72  6b 73 70 61 63 65 20 77  | NMI workspace w|
00000830  68 69 63 68 20 69 73 20  77 68 79 20 74 68 65 20  |hich is why the |
00000840  75 73 65 72 20 63 61 6e  20 6d 61 6b 65 20 75 73  |user can make us|
00000850  65 20 6f 66 20 74 68 61  74 0d 70 61 67 65 20 6f  |e of that.page o|
00000860  6e 20 61 6e 20 75 6e 65  78 70 61 6e 64 65 64 20  |n an unexpanded |
00000870  42 20 62 75 74 20 6e 6f  74 20 6f 6e 20 61 6e 79  |B but not on any|
00000880  20 6f 74 68 65 72 20 6d  61 63 68 69 6e 65 2e 0d  | other machine..|
00000890  0d 54 68 65 20 6d 61 73  6b 69 6e 67 20 72 65 66  |.The masking ref|
000008a0  65 72 72 65 64 20 74 6f  20 69 6e 20 74 68 65 20  |erred to in the |
000008b0  6e 61 6d 65 20 69 73 20  74 68 65 20 61 62 69 6c  |name is the abil|
000008c0  69 74 79 20 74 6f 20 6d  61 6b 65 0d 74 68 65 20  |ity to make.the |
000008d0  36 35 30 32 20 69 67 6e  6f 72 65 20 74 68 65 20  |6502 ignore the |
000008e0  72 65 71 75 65 73 74 73  20 66 6f 72 20 69 6e 74  |requests for int|
000008f0  65 72 72 75 70 74 20 68  61 6e 64 6c 69 6e 67 20  |errupt handling |
00000900  62 79 0d 75 73 69 6e 67  20 74 68 65 20 69 6e 74  |by.using the int|
00000910  65 72 72 75 70 74 20 66  6c 61 67 2e 20 20 53 69  |errupt flag.  Si|
00000920  6d 70 6c 79 20 70 75 74  2c 20 73 65 74 74 69 6e  |mply put, settin|
00000930  67 20 74 68 65 20 69 6e  74 65 72 72 75 70 74 0d  |g the interrupt.|
00000940  66 6c 61 67 20 28 77 69  74 68 20 61 6e 20 53 45  |flag (with an SE|
00000950  49 29 20 77 69 6c 6c 20  6e 6f 74 20 73 74 6f 70  |I) will not stop|
00000960  20 74 68 65 20 6d 61 63  68 69 6e 65 20 72 65 73  | the machine res|
00000970  70 6f 6e 64 69 6e 67 20  74 6f 0d 4e 4d 49 73 2e  |ponding to.NMIs.|
00000980  20 20 54 68 65 72 65 20  69 73 20 6e 6f 20 77 61  |  There is no wa|
00000990  79 20 74 6f 20 73 74 6f  70 20 61 6e 20 6e 6f 6e  |y to stop an non|
000009a0  2d 6d 61 73 6b 61 62 6c  65 20 69 6e 74 65 72 72  |-maskable interr|
000009b0  75 70 74 2e 0d 0d 54 68  65 72 65 20 61 72 65 20  |upt...There are |
000009c0  74 68 72 65 65 20 64 69  73 74 69 6e 63 74 20 61  |three distinct a|
000009d0  73 70 65 63 74 73 20 74  6f 20 69 6e 74 65 72 72  |spects to interr|
000009e0  75 70 74 20 68 61 6e 64  6c 69 6e 67 3a 0d 69 6e  |upt handling:.in|
000009f0  74 65 72 63 65 70 74 69  6e 67 20 74 68 65 20 76  |tercepting the v|
00000a00  65 63 74 6f 72 2c 20 63  68 65 63 6b 69 6e 67 20  |ector, checking |
00000a10  74 68 61 74 20 79 6f 75  20 61 72 65 20 67 6f 69  |that you are goi|
00000a20  6e 67 20 74 6f 0d 68 61  6e 64 6c 65 20 74 68 65  |ng to.handle the|
00000a30  20 72 69 67 68 74 20 69  6e 74 65 72 72 75 70 74  | right interrupt|
00000a40  2c 20 61 6e 64 20 74 68  65 20 69 6e 74 65 72 72  |, and the interr|
00000a50  75 70 74 20 68 61 6e 64  6c 69 6e 67 20 63 6f 64  |upt handling cod|
00000a60  65 0d 69 74 73 65 6c 66  2e 0d 0d 49 6e 74 65 72  |e.itself...Inter|
00000a70  63 65 70 74 69 6e 67 20  74 68 65 20 76 65 63 74  |cepting the vect|
00000a80  6f 72 20 69 73 20 63 61  72 72 69 65 64 20 6f 75  |or is carried ou|
00000a90  74 20 65 78 61 63 74 6c  79 20 61 73 20 79 6f 75  |t exactly as you|
00000aa0  20 77 6f 75 6c 64 0d 77  68 65 6e 20 69 6e 74 65  | would.when inte|
00000ab0  72 63 65 70 74 69 6e 67  20 61 6e 79 20 6f 74 68  |rcepting any oth|
00000ac0  65 72 20 76 65 63 74 6f  72 2c 20 61 6c 74 68 6f  |er vector, altho|
00000ad0  75 67 68 20 79 6f 75 20  73 68 6f 75 6c 64 0d 75  |ugh you should.u|
00000ae0  6e 64 65 72 73 74 61 6e  64 20 74 68 65 20 64 69  |nderstand the di|
00000af0  73 74 69 6e 63 74 69 6f  6e 20 62 65 74 77 65 65  |stinction betwee|
00000b00  6e 20 74 68 65 20 74 77  6f 20 69 6e 74 65 72 72  |n the two interr|
00000b10  75 70 74 20 76 65 63 74  6f 72 73 0d 49 52 51 31  |upt vectors.IRQ1|
00000b20  20 61 6e 64 20 49 52 51  32 20 28 49 52 51 20 73  | and IRQ2 (IRQ s|
00000b30  74 61 6e 64 73 20 66 6f  72 20 49 6e 74 65 72 72  |tands for Interr|
00000b40  75 70 74 20 52 65 51 75  65 73 74 29 2e 20 20 49  |upt ReQuest).  I|
00000b50  52 51 31 20 61 6e 64 0d  49 52 51 32 20 68 61 76  |RQ1 and.IRQ2 hav|
00000b60  65 20 64 69 66 66 65 72  65 6e 74 20 70 72 69 6f  |e different prio|
00000b70  72 69 74 69 65 73 2e 20  20 41 6e 20 69 6e 74 65  |rities.  An inte|
00000b80  72 72 75 70 74 20 72 65  71 75 65 73 74 20 66 69  |rrupt request fi|
00000b90  72 73 74 0d 70 61 73 73  65 73 20 74 68 72 6f 75  |rst.passes throu|
00000ba0  67 68 20 49 52 51 31 20  74 6f 20 74 68 65 20 73  |gh IRQ1 to the s|
00000bb0  74 61 6e 64 61 72 64 20  69 6e 74 65 72 72 75 70  |tandard interrup|
00000bc0  74 20 68 61 6e 64 6c 69  6e 67 0d 72 6f 75 74 69  |t handling.routi|
00000bd0  6e 65 73 20 69 6e 20 74  68 65 20 4f 53 20 77 68  |nes in the OS wh|
00000be0  69 63 68 20 64 6f 20 73  79 73 74 65 6d 20 68 6f  |ich do system ho|
00000bf0  75 73 65 6b 65 65 70 69  6e 67 2e 20 20 54 68 65  |usekeeping.  The|
00000c00  6e 20 74 68 65 0d 69 6e  74 65 72 72 75 70 74 20  |n the.interrupt |
00000c10  69 73 20 70 61 73 73 65  64 20 74 68 72 6f 75 67  |is passed throug|
00000c20  68 20 49 52 51 32 2e 20  20 44 69 61 67 72 61 6d  |h IRQ2.  Diagram|
00000c30  6d 61 74 69 63 61 6c 6c  79 20 69 74 27 73 0d 6c  |matically it's.l|
00000c40  69 6b 65 20 74 68 69 73  3a 0d 0d 20 20 20 20 20  |ike this:..     |
00000c50  20 20 20 20 20 20 20 49  6e 74 65 72 72 75 70 74  |       Interrupt|
00000c60  20 44 65 74 65 63 74 65  64 0d 20 20 20 20 20 20  | Detected.      |
00000c70  20 20 20 20 20 20 56 65  63 74 6f 72 65 64 20 74  |      Vectored t|
00000c80  68 72 6f 75 67 68 20 49  52 51 31 0d 20 20 20 20  |hrough IRQ1.    |
00000c90  20 20 20 20 20 20 20 20  53 79 73 74 65 6d 20 69  |        System i|
00000ca0  6e 74 65 72 72 75 70 74  20 68 61 6e 64 6c 69 6e  |nterrupt handlin|
00000cb0  67 0d 20 20 20 20 20 20  20 20 20 20 20 20 56 65  |g.            Ve|
00000cc0  63 74 6f 72 65 64 20 74  68 72 6f 75 67 68 20 49  |ctored through I|
00000cd0  52 51 32 0d 20 20 20 20  20 20 20 20 20 20 20 20  |RQ2.            |
00000ce0  55 73 65 72 20 69 6e 74  65 72 72 75 70 74 20 68  |User interrupt h|
00000cf0  61 6e 64 6c 69 6e 67 0d  0d 54 68 69 73 20 72 65  |andling..This re|
00000d00  66 6c 65 63 74 73 20 77  68 61 74 20 49 20 63 61  |flects what I ca|
00000d10  6c 6c 65 64 20 74 68 65  20 70 65 63 6b 69 6e 67  |lled the pecking|
00000d20  20 6f 72 64 65 72 2e 20  20 54 68 65 20 73 79 73  | order.  The sys|
00000d30  74 65 6d 0d 68 6f 75 73  65 6b 65 65 70 69 6e 67  |tem.housekeeping|
00000d40  20 68 61 73 20 74 6f 20  62 65 20 64 6f 6e 65 20  | has to be done |
00000d50  75 72 67 65 6e 74 6c 79  2e 20 20 49 66 20 79 6f  |urgently.  If yo|
00000d60  75 72 20 69 6e 74 65 72  72 75 70 74 0d 72 6f 75  |ur interrupt.rou|
00000d70  74 69 6e 65 20 69 73 20  6e 6f 74 20 75 72 67 65  |tine is not urge|
00000d80  6e 74 20 74 68 65 6e 20  69 74 20 73 68 6f 75 6c  |nt then it shoul|
00000d90  64 20 69 6e 74 65 72 63  65 70 74 20 49 52 51 32  |d intercept IRQ2|
00000da0  2e 20 20 4f 6e 6c 79 0d  69 6e 74 65 72 63 65 70  |.  Only.intercep|
00000db0  74 20 49 52 51 31 20 69  66 20 69 74 20 69 73 20  |t IRQ1 if it is |
00000dc0  69 6d 70 6f 72 74 61 6e  74 20 66 6f 72 20 74 68  |important for th|
00000dd0  65 72 65 20 74 6f 20 62  65 20 61 20 66 61 73 74  |ere to be a fast|
00000de0  0d 72 65 73 70 6f 6e 73  65 20 74 6f 20 79 6f 75  |.response to you|
00000df0  72 20 63 6f 64 65 2e 0d  0d 54 68 65 20 4f 53 20  |r code...The OS |
00000e00  73 65 74 73 20 75 70 20  76 61 72 69 6f 75 73 20  |sets up various |
00000e10  70 61 72 61 6d 65 74 65  72 73 20 69 6e 20 74 68  |parameters in th|
00000e20  65 20 6d 69 63 72 6f 20  69 6e 20 61 20 73 74 61  |e micro in a sta|
00000e30  6e 64 61 72 64 0d 77 61  79 20 73 6f 20 74 68 61  |ndard.way so tha|
00000e40  74 20 79 6f 75 20 6b 6e  6f 77 20 74 68 65 20 73  |t you know the s|
00000e50  74 61 74 65 20 6f 66 20  74 68 65 20 6d 61 63 68  |tate of the mach|
00000e60  69 6e 65 20 77 68 65 6e  20 79 6f 75 0d 69 6e 74  |ine when you.int|
00000e70  65 72 63 65 70 74 20 49  52 51 31 20 6f 72 20 49  |ercept IRQ1 or I|
00000e80  52 51 32 2e 20 20 49 74  20 68 61 70 70 65 6e 73  |RQ2.  It happens|
00000e90  20 6c 69 6b 65 20 74 68  69 73 2e 0d 0d 57 68 65  | like this...Whe|
00000ea0  6e 20 61 20 6d 61 73 6b  61 62 6c 65 20 69 6e 74  |n a maskable int|
00000eb0  65 72 72 75 70 74 20 69  73 20 64 65 74 65 63 74  |errupt is detect|
00000ec0  65 64 20 62 79 20 74 68  65 20 36 35 30 32 20 69  |ed by the 6502 i|
00000ed0  74 0d 70 72 6f 6d 70 74  6c 79 20 63 68 65 63 6b  |t.promptly check|
00000ee0  73 20 74 6f 20 73 65 65  20 69 66 20 69 74 20 68  |s to see if it h|
00000ef0  61 73 20 62 65 65 6e 20  63 61 75 73 65 64 20 62  |as been caused b|
00000f00  79 20 61 20 42 52 4b 20  69 6e 20 74 68 65 0d 63  |y a BRK in the.c|
00000f10  6f 64 65 20 69 74 20 77  61 73 20 65 78 65 63 75  |ode it was execu|
00000f20  74 69 6e 67 20 28 62 79  20 6c 6f 6f 6b 69 6e 67  |ting (by looking|
00000f30  20 61 74 20 74 68 65 20  73 74 61 74 65 20 6f 66  | at the state of|
00000f40  20 74 68 65 20 42 52 4b  0d 66 6c 61 67 29 2e 20  | the BRK.flag). |
00000f50  20 49 66 20 69 74 20 77  61 73 20 74 68 65 6e 20  | If it was then |
00000f60  74 68 65 20 70 72 6f 63  65 73 73 6f 72 20 65 78  |the processor ex|
00000f70  65 63 75 74 65 73 20 74  68 65 20 63 75 72 72 65  |ecutes the curre|
00000f80  6e 74 0d 65 72 72 6f 72  20 72 6f 75 74 69 6e 65  |nt.error routine|
00000f90  20 68 61 76 69 6e 67 20  66 6f 75 6e 64 20 69 74  | having found it|
00000fa0  20 62 79 20 67 6f 69 6e  67 20 74 68 72 6f 75 67  | by going throug|
00000fb0  68 20 74 68 65 20 62 72  65 61 6b 0d 76 65 63 74  |h the break.vect|
00000fc0  6f 72 2e 0d 0d 49 66 20  74 68 65 20 62 72 65 61  |or...If the brea|
00000fd0  6b 20 66 6c 61 67 20 77  61 73 20 6e 6f 74 20 73  |k flag was not s|
00000fe0  65 74 20 74 68 65 6e 20  61 20 68 61 72 64 77 61  |et then a hardwa|
00000ff0  72 65 20 69 6e 74 65 72  72 75 70 74 20 77 61 73  |re interrupt was|
00001000  0d 74 68 65 20 63 61 75  73 65 20 6f 66 20 74 68  |.the cause of th|
00001010  65 20 69 6e 74 65 72 72  75 70 74 2e 20 20 54 68  |e interrupt.  Th|
00001020  69 73 20 69 73 20 74 68  65 20 63 6f 6e 64 69 74  |is is the condit|
00001030  69 6f 6e 20 77 65 20 61  72 65 0d 73 74 75 64 79  |ion we are.study|
00001040  69 6e 67 20 69 6e 20 74  68 69 73 20 6d 6f 64 75  |ing in this modu|
00001050  6c 65 2e 0d 0d 48 61 76  69 6e 67 20 64 65 74 65  |le...Having dete|
00001060  72 6d 69 6e 65 64 20 74  68 61 74 20 61 6e 20 49  |rmined that an I|
00001070  52 51 20 68 61 73 20 69  6e 64 65 65 64 20 6f 63  |RQ has indeed oc|
00001080  63 75 72 72 65 64 20 74  68 65 20 36 35 30 32 0d  |curred the 6502.|
00001090  6a 75 6d 70 73 20 74 6f  20 74 68 65 20 63 6f 6e  |jumps to the con|
000010a0  74 65 6e 74 73 20 6f 66  20 74 68 65 20 49 52 51  |tents of the IRQ|
000010b0  31 56 20 76 65 63 74 6f  72 2e 20 20 55 6e 74 69  |1V vector.  Unti|
000010c0  6c 20 6e 6f 77 20 74 68  69 73 0d 68 61 73 20 68  |l now this.has h|
000010d0  61 70 70 65 6e 65 64 20  61 75 74 6f 6d 61 74 69  |appened automati|
000010e0  63 61 6c 6c 79 20 61 6e  64 20 74 68 65 20 75 73  |cally and the us|
000010f0  65 72 20 64 6f 65 73 20  6e 6f 74 20 6e 65 65 64  |er does not need|
00001100  20 74 6f 0d 77 6f 72 72  79 20 61 62 6f 75 74 20  | to.worry about |
00001110  69 74 2e 20 20 4e 6f 77  20 74 68 6f 75 67 68 20  |it.  Now though |
00001120  74 68 65 20 4f 53 20 69  73 20 70 72 65 70 61 72  |the OS is prepar|
00001130  69 6e 67 20 74 6f 20 68  61 6e 64 20 6f 76 65 72  |ing to hand over|
00001140  0d 74 6f 20 69 6e 74 65  72 72 75 70 74 20 68 61  |.to interrupt ha|
00001150  6e 64 6c 69 6e 67 20 72  6f 75 74 69 6e 65 73 20  |ndling routines |
00001160  61 6e 64 20 74 68 65 20  66 6f 6c 6c 6f 77 69 6e  |and the followin|
00001170  67 20 69 73 20 6b 6e 6f  77 6e 0d 61 62 6f 75 74  |g is known.about|
00001180  20 74 68 65 20 73 74 61  74 65 20 6f 66 20 74 68  | the state of th|
00001190  65 20 6d 69 63 72 6f 20  62 65 63 61 75 73 65 20  |e micro because |
000011a0  74 68 65 20 4f 53 20 68  61 73 20 73 65 74 20 69  |the OS has set i|
000011b0  74 20 75 70 0d 74 68 69  73 20 77 61 79 3a 0d 0d  |t up.this way:..|
000011c0  54 68 65 20 76 61 6c 75  65 20 6f 66 20 74 68 65  |The value of the|
000011d0  20 61 63 63 75 6d 75 6c  61 74 6f 72 20 61 74 20  | accumulator at |
000011e0  74 68 65 20 74 69 6d 65  20 6f 66 20 74 68 65 20  |the time of the |
000011f0  69 6e 74 65 72 72 75 70  74 20 69 73 0d 73 74 6f  |interrupt is.sto|
00001200  72 65 64 20 69 6e 20 6d  65 6d 6f 72 79 20 6c 6f  |red in memory lo|
00001210  63 61 74 69 6f 6e 20 26  46 43 20 69 6e 20 74 68  |cation &FC in th|
00001220  65 20 49 2f 4f 20 70 72  6f 63 65 73 73 6f 72 2e  |e I/O processor.|
00001230  20 20 54 68 65 0d 73 74  61 74 75 73 20 72 65 67  |  The.status reg|
00001240  69 73 74 65 72 20 61 6e  64 20 74 68 65 20 72 65  |ister and the re|
00001250  74 75 72 6e 20 61 64 64  72 65 73 73 20 28 74 68  |turn address (th|
00001260  65 20 61 64 64 72 65 73  73 20 6f 66 20 74 68 65  |e address of the|
00001270  0d 69 6e 73 74 72 75 63  74 69 6f 6e 20 61 62 6f  |.instruction abo|
00001280  75 74 20 74 6f 20 62 65  20 61 63 74 69 6f 6e 65  |ut to be actione|
00001290  64 20 77 68 65 6e 20 74  68 65 20 69 6e 74 65 72  |d when the inter|
000012a0  72 75 70 74 0d 6f 63 63  75 72 72 65 64 29 20 61  |rupt.occurred) a|
000012b0  72 65 20 73 74 6f 72 65  64 20 6f 6e 20 74 68 65  |re stored on the|
000012c0  20 73 74 61 63 6b 20 72  65 61 64 79 20 66 6f 72  | stack ready for|
000012d0  20 61 6e 20 52 54 49 20  28 52 65 54 75 72 6e 0d  | an RTI (ReTurn.|
000012e0  66 72 6f 6d 20 49 6e 74  65 72 72 75 70 74 29 20  |from Interrupt) |
000012f0  61 74 20 74 68 65 20 65  6e 64 20 6f 66 20 74 68  |at the end of th|
00001300  65 20 69 6e 74 65 72 72  75 70 74 20 63 6f 64 65  |e interrupt code|
00001310  2e 20 20 54 68 65 0d 6f  72 69 67 69 6e 61 6c 20  |.  The.original |
00001320  58 20 61 6e 64 20 59 20  72 65 67 69 73 74 65 72  |X and Y register|
00001330  20 76 61 6c 75 65 73 20  61 72 65 20 73 74 69 6c  | values are stil|
00001340  6c 20 69 6e 20 70 6c 61  63 65 2e 0d 0d 41 6e 79  |l in place...Any|
00001350  20 69 6e 74 65 72 72 75  70 74 20 68 61 6e 64 6c  | interrupt handl|
00001360  69 6e 67 20 63 6f 64 65  20 79 6f 75 20 77 72 69  |ing code you wri|
00001370  74 65 20 73 68 6f 75 6c  64 20 6c 65 61 76 65 20  |te should leave |
00001380  74 68 65 20 6d 69 63 72  6f 0d 61 6e 64 20 72 65  |the micro.and re|
00001390  67 69 73 74 65 72 73 20  69 6e 20 74 68 69 73 20  |gisters in this |
000013a0  73 74 61 74 65 20 61 66  74 65 72 77 61 72 64 73  |state afterwards|
000013b0  2e 0d 0d 53 6f 2c 20 6f  6e 20 65 6e 74 72 79 20  |...So, on entry |
000013c0  74 6f 20 79 6f 75 72 20  63 6f 64 65 20 79 6f 75  |to your code you|
000013d0  20 6d 75 73 74 3a 0d 0d  20 20 20 20 20 20 20 20  | must:..        |
000013e0  53 61 76 65 20 74 68 65  20 63 6f 6e 74 65 6e 74  |Save the content|
000013f0  73 20 6f 66 20 26 46 43  20 6f 6e 20 74 68 65 20  |s of &FC on the |
00001400  73 74 61 63 6b 0d 20 20  20 20 20 20 20 20 53 61  |stack.        Sa|
00001410  76 65 20 74 68 65 20 58  20 61 6e 64 20 59 20 72  |ve the X and Y r|
00001420  65 67 69 73 74 65 72 73  20 6f 6e 20 74 68 65 20  |egisters on the |
00001430  73 74 61 63 6b 0d 20 20  20 20 20 20 20 20 43 6c  |stack.        Cl|
00001440  65 61 72 20 74 68 65 20  64 65 63 69 6d 61 6c 20  |ear the decimal |
00001450  66 6c 61 67 0d 0d 61 6e  64 20 6f 6e 20 65 78 69  |flag..and on exi|
00001460  74 20 79 6f 75 20 6d 75  73 74 0d 20 0d 20 20 20  |t you must. .   |
00001470  20 20 20 20 20 52 65 6c  6f 61 64 20 74 68 65 20  |     Reload the |
00001480  59 20 61 6e 64 20 58 20  72 65 67 69 73 74 65 72  |Y and X register|
00001490  73 20 66 72 6f 6d 20 74  68 65 20 73 74 61 63 6b  |s from the stack|
000014a0  0d 20 20 20 20 20 20 20  20 54 72 61 6e 73 66 65  |.        Transfe|
000014b0  72 20 74 68 65 20 6f 72  69 67 69 6e 61 6c 20 61  |r the original a|
000014c0  63 63 75 6d 75 6c 61 74  6f 72 20 76 61 6c 75 65  |ccumulator value|
000014d0  20 66 72 6f 6d 20 74 68  65 0d 20 20 20 20 20 20  | from the.      |
000014e0  20 20 20 20 20 20 73 74  61 63 6b 20 74 6f 20 26  |      stack to &|
000014f0  46 43 0d 0d 43 6c 65 61  72 69 6e 67 20 74 68 65  |FC..Clearing the|
00001500  20 64 65 63 69 6d 61 6c  20 66 6c 61 67 20 69 73  | decimal flag is|
00001510  20 61 20 73 61 66 65 74  79 20 6d 65 61 73 75 72  | a safety measur|
00001520  65 20 69 6e 20 63 61 73  65 20 74 68 65 0d 72 6f  |e in case the.ro|
00001530  75 74 69 6e 65 20 62 65  69 6e 67 20 65 78 65 63  |utine being exec|
00001540  75 74 65 64 20 61 74 20  74 68 65 20 74 69 6d 65  |uted at the time|
00001550  20 6f 66 20 74 68 65 20  69 6e 74 65 72 72 75 70  | of the interrup|
00001560  74 20 77 61 73 0d 77 6f  72 6b 69 6e 67 20 69 6e  |t was.working in|
00001570  20 64 65 63 69 6d 61 6c  20 6d 6f 64 65 2e 20 20  | decimal mode.  |
00001580  54 68 69 73 20 69 73 20  75 6e 6c 69 6b 65 6c 79  |This is unlikely|
00001590  2e 20 20 41 73 20 74 68  65 20 73 74 61 74 75 73  |.  As the status|
000015a0  0d 72 65 67 69 73 74 65  72 20 69 73 20 72 65 2d  |.register is re-|
000015b0  73 65 74 20 62 79 20 74  68 65 20 52 54 49 20 69  |set by the RTI i|
000015c0  6e 73 74 72 75 63 74 69  6f 6e 20 61 74 20 74 68  |nstruction at th|
000015d0  65 20 76 65 72 79 20 65  6e 64 20 6f 66 0d 74 68  |e very end of.th|
000015e0  65 20 69 6e 74 65 72 72  75 70 74 20 63 68 61 69  |e interrupt chai|
000015f0  6e 20 74 68 65 6e 20 79  6f 75 20 6e 65 65 64 20  |n then you need |
00001600  6e 6f 74 20 77 6f 72 72  79 20 61 62 6f 75 74 20  |not worry about |
00001610  74 68 65 20 73 74 61 74  75 73 0d 6f 66 20 74 68  |the status.of th|
00001620  65 20 6f 72 69 67 69 6e  61 6c 20 66 6c 61 67 73  |e original flags|
00001630  20 79 6f 75 72 73 65 6c  66 20 64 75 72 69 6e 67  | yourself during|
00001640  20 69 6e 74 65 72 72 75  70 74 20 68 61 6e 64 6c  | interrupt handl|
00001650  69 6e 67 0d 65 78 63 65  70 74 20 66 6f 72 20 74  |ing.except for t|
00001660  68 65 20 65 66 66 65 63  74 20 64 65 63 69 6d 61  |he effect decima|
00001670  6c 20 6d 6f 64 65 20 6d  69 67 68 74 20 68 61 76  |l mode might hav|
00001680  65 20 6f 6e 20 79 6f 75  72 20 63 6f 64 65 2e 20  |e on your code. |
00001690  0d 53 6f 20 63 6c 65 61  72 20 69 74 21 0d 0d 5b  |.So clear it!..[|
000016a0  54 68 65 72 65 20 69 73  20 61 20 76 65 72 79 20  |There is a very |
000016b0  73 74 72 6f 6e 67 20 61  72 67 75 6d 65 6e 74 20  |strong argument |
000016c0  66 6f 72 20 4e 45 56 45  52 20 75 73 69 6e 67 20  |for NEVER using |
000016d0  64 65 63 69 6d 61 6c 0d  6d 6f 64 65 20 6f 6e 20  |decimal.mode on |
000016e0  74 68 65 20 42 42 43 20  4d 69 63 72 6f 2e 20 20  |the BBC Micro.  |
000016f0  54 68 65 20 4f 53 20 61  6c 77 61 79 73 20 61 73  |The OS always as|
00001700  73 75 6d 65 73 20 62 69  6e 61 72 79 20 6d 6f 64  |sumes binary mod|
00001710  65 0d 61 6e 64 20 73 6f  2c 20 70 72 6f 62 61 62  |e.and so, probab|
00001720  6c 79 2c 20 64 6f 20 6f  74 68 65 72 20 70 65 6f  |ly, do other peo|
00001730  70 6c 65 27 73 20 69 6e  74 65 72 72 75 70 74 20  |ple's interrupt |
00001740  72 6f 75 74 69 6e 65 73  2e 20 20 59 6f 75 0d 73  |routines.  You.s|
00001750  68 6f 75 6c 64 20 74 68  65 72 65 66 6f 72 65 20  |hould therefore |
00001760  61 6c 77 61 79 73 20 64  69 73 61 62 6c 65 20 69  |always disable i|
00001770  6e 74 65 72 72 75 70 74  73 20 77 68 65 6e 20 75  |nterrupts when u|
00001780  73 69 6e 67 0d 64 65 63  69 6d 61 6c 20 6d 6f 64  |sing.decimal mod|
00001790  65 20 74 6f 20 61 76 6f  69 64 20 74 72 61 73 68  |e to avoid trash|
000017a0  69 6e 67 20 73 6f 6d 65  62 6f 64 79 20 65 6c 73  |ing somebody els|
000017b0  65 27 73 20 69 6e 74 65  72 72 75 70 74 73 2e 20  |e's interrupts. |
000017c0  0d 49 20 6b 6e 6f 77 20  49 20 64 69 64 6e 27 74  |.I know I didn't|
000017d0  20 64 6f 20 74 68 69 73  20 62 61 63 6b 20 69 6e  | do this back in|
000017e0  20 6d 6f 64 75 6c 65 20  36 20 62 75 74 20 73 65  | module 6 but se|
000017f0  76 65 72 61 6c 20 70 65  6f 70 6c 65 0d 68 61 76  |veral people.hav|
00001800  65 20 73 69 6e 63 65 20  70 6f 69 6e 74 65 64 20  |e since pointed |
00001810  6f 75 74 20 74 68 65 20  64 61 6e 67 65 72 73 2e  |out the dangers.|
00001820  5d 0d 0d 54 68 65 20 63  6f 64 65 20 77 69 6c 6c  |]..The code will|
00001830  20 6c 6f 6f 6b 20 6c 69  6b 65 20 74 68 69 73 3a  | look like this:|
00001840  0d 0d 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |..              |
00001850  20 4c 44 41 20 26 46 43  0d 20 20 20 20 20 20 20  | LDA &FC.       |
00001860  20 20 20 20 20 20 20 20  50 48 41 0d 20 20 20 20  |        PHA.    |
00001870  20 20 20 20 20 20 20 20  20 20 20 54 58 41 0d 20  |           TXA. |
00001880  20 20 20 20 20 20 20 20  20 20 20 20 20 20 50 48  |              PH|
00001890  41 0d 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |A.              |
000018a0  20 54 59 41 0d 20 20 20  20 20 20 20 20 20 20 20  | TYA.           |
000018b0  20 20 20 20 50 48 41 0d  20 20 20 20 20 20 20 20  |    PHA.        |
000018c0  20 20 20 20 20 20 20 43  4c 44 0d 0d 61 6e 64 20  |       CLD..and |
000018d0  6f 6e 20 65 78 69 74 0d  0d 20 20 20 20 20 20 20  |on exit..       |
000018e0  20 20 20 20 20 20 20 20  50 4c 41 0d 20 20 20 20  |        PLA.    |
000018f0  20 20 20 20 20 20 20 20  20 20 20 54 41 59 0d 20  |           TAY. |
00001900  20 20 20 20 20 20 20 20  20 20 20 20 20 20 50 4c  |              PL|
00001910  41 0d 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |A.              |
00001920  20 54 41 58 0d 20 20 20  20 20 20 20 20 20 20 20  | TAX.           |
00001930  20 20 20 20 50 4c 41 0d  20 20 20 20 20 20 20 20  |    PLA.        |
00001940  20 20 20 20 20 20 20 53  54 41 20 26 46 43 0d 20  |       STA &FC. |
00001950  20 20 20 20 20 20 20 20  20 20 20 20 20 20 52 54  |              RT|
00001960  49 0d 0d 6f 72 20 79 6f  75 20 6d 69 67 68 74 20  |I..or you might |
00001970  4a 4d 50 20 28 6f 6c 64  5f 49 52 51 29 20 74 6f  |JMP (old_IRQ) to|
00001980  20 63 6f 6e 74 69 6e 75  65 20 64 6f 77 6e 20 74  | continue down t|
00001990  68 65 20 49 52 51 20 63  68 61 69 6e 2e 0d 0d 0d  |he IRQ chain....|
000019a0  43 68 65 63 6b 69 6e 67  20 74 6f 20 73 65 65 20  |Checking to see |
000019b0  69 66 20 79 6f 75 20 68  61 76 65 20 74 68 65 20  |if you have the |
000019c0  72 69 67 68 74 20 69 6e  74 65 72 72 75 70 74 20  |right interrupt |
000019d0  69 73 20 6e 6f 74 20 61  73 0d 73 69 6d 70 6c 65  |is not as.simple|
000019e0  20 61 73 20 74 68 65 20  45 76 65 6e 74 20 73 79  | as the Event sy|
000019f0  73 74 65 6d 20 77 68 65  72 65 20 79 6f 75 20 63  |stem where you c|
00001a00  68 65 63 6b 20 74 68 65  20 6e 75 6d 62 65 72 20  |heck the number |
00001a10  69 6e 20 74 68 65 0d 61  63 63 75 6d 75 6c 61 74  |in the.accumulat|
00001a20  6f 72 2e 20 20 57 69 74  68 20 61 6e 20 69 6e 74  |or.  With an int|
00001a30  65 72 72 75 70 74 20 79  6f 75 20 68 61 76 65 20  |errupt you have |
00001a40  74 6f 20 6c 6f 6f 6b 20  69 6e 20 74 68 65 0d 72  |to look in the.r|
00001a50  65 67 69 73 74 65 72 73  20 6f 66 20 74 68 65 20  |egisters of the |
00001a60  70 69 65 63 65 20 6f 66  20 68 61 72 64 77 61 72  |piece of hardwar|
00001a70  65 20 74 6f 20 77 68 69  63 68 20 79 6f 75 72 20  |e to which your |
00001a80  69 6e 74 65 72 72 75 70  74 20 68 61 6e 64 6c 69  |interrupt handli|
00001a90  6e 67 0d 72 6f 75 74 69  6e 65 20 72 65 66 65 72  |ng.routine refer|
00001aa0  73 2e 0d 0d 57 69 74 68  20 61 20 73 69 6e 67 6c  |s...With a singl|
00001ab0  65 20 72 6f 75 74 69 6e  65 20 74 68 69 73 20 69  |e routine this i|
00001ac0  73 20 72 65 6c 61 74 69  76 65 6c 79 20 73 69 6d  |s relatively sim|
00001ad0  70 6c 65 2c 20 6a 75 73  74 20 62 65 0d 74 68 61  |ple, just be.tha|
00001ae0  6e 6b 66 75 6c 20 79 6f  75 20 64 6f 6e 27 74 20  |nkful you don't |
00001af0  68 61 76 65 20 74 68 65  20 6a 6f 62 20 6f 66 20  |have the job of |
00001b00  74 68 65 20 4f 53 20 77  68 69 63 68 20 68 61 73  |the OS which has|
00001b10  20 6d 61 6e 79 0d 64 65  76 69 63 65 73 20 74 6f  | many.devices to|
00001b20  20 73 65 72 76 69 63 65  2e 20 20 54 68 65 20 4f  | service.  The O|
00001b30  53 20 68 61 73 20 74 6f  20 6c 6f 6f 6b 20 61 74  |S has to look at|
00001b40  20 74 68 65 20 73 79 73  74 65 6d 20 56 49 41 0d  | the system VIA.|
00001b50  28 76 65 72 73 61 74 69  6c 65 20 69 6e 74 65 72  |(versatile inter|
00001b60  66 61 63 65 20 61 64 61  70 74 65 72 29 2c 20 74  |face adapter), t|
00001b70  68 65 20 73 65 72 69 61  6c 20 73 79 73 74 65 6d  |he serial system|
00001b80  20 28 66 6f 72 20 74 68  65 0d 63 61 73 73 65 74  | (for the.casset|
00001b90  74 65 20 66 69 6c 69 6e  67 20 73 79 73 74 65 6d  |te filing system|
00001ba0  20 61 6e 64 20 74 68 65  20 52 53 34 32 33 29 20  | and the RS423) |
00001bb0  61 6e 64 20 6f 6e 65 20  70 61 72 74 20 6f 66 20  |and one part of |
00001bc0  74 68 65 0d 75 73 65 72  20 56 49 41 20 77 68 69  |the.user VIA whi|
00001bd0  63 68 20 64 65 61 6c 73  20 77 69 74 68 20 70 61  |ch deals with pa|
00001be0  72 61 6c 6c 65 6c 20 70  72 69 6e 74 65 72 73 2e  |rallel printers.|
00001bf0  20 20 54 68 65 73 65 0d  69 6e 74 65 72 72 75 70  |  These.interrup|
00001c00  74 20 70 6f 73 73 69 62  69 6c 69 74 69 65 73 20  |t possibilities |
00001c10  61 72 65 20 61 6c 6c 20  68 61 6e 64 6c 65 64 20  |are all handled |
00001c20  62 79 20 74 68 65 20 74  69 6d 65 20 70 72 6f 67  |by the time prog|
00001c30  72 61 6d 0d 65 78 65 63  75 74 69 6f 6e 20 68 61  |ram.execution ha|
00001c40  73 20 72 65 61 63 68 65  64 20 49 52 51 32 2e 0d  |s reached IRQ2..|
00001c50  0d 54 68 65 20 62 65 73  74 20 70 6c 61 63 65 20  |.The best place |
00001c60  74 6f 20 6c 6f 6f 6b 20  66 6f 72 20 64 65 74 61  |to look for deta|
00001c70  69 6c 73 20 6f 66 20 74  68 65 73 65 20 64 65 76  |ils of these dev|
00001c80  69 63 65 73 20 69 73 20  69 6e 0d 79 6f 75 72 20  |ices is in.your |
00001c90  61 64 76 61 6e 63 65 64  20 67 75 69 64 65 2e 20  |advanced guide. |
00001ca0  20 49 74 20 69 73 20 61  20 6c 69 74 74 6c 65 20  | It is a little |
00001cb0  62 65 79 6f 6e 64 20 74  68 65 20 73 63 6f 70 65  |beyond the scope|
00001cc0  20 6f 66 0d 74 68 69 73  20 73 65 72 69 65 73 20  | of.this series |
00001cd0  74 6f 20 67 65 74 20 69  6e 74 6f 20 74 6f 6f 20  |to get into too |
00001ce0  6d 75 63 68 20 72 65 66  65 72 65 6e 63 65 20 64  |much reference d|
00001cf0  65 74 61 69 6c 2c 20 74  68 61 74 20 69 73 0d 62  |etail, that is.b|
00001d00  65 73 74 20 64 6f 6e 65  20 6f 6e 20 70 61 70 65  |est done on pape|
00001d10  72 2e 20 20 48 6f 77 65  76 65 72 20 49 20 77 69  |r.  However I wi|
00001d20  6c 6c 20 67 69 76 65 20  61 6e 20 65 78 61 6d 70  |ll give an examp|
00001d30  6c 65 20 77 68 69 63 68  20 49 0d 68 6f 70 65 20  |le which I.hope |
00001d40  77 69 6c 6c 20 73 65 72  76 65 20 66 6f 72 20 61  |will serve for a|
00001d50  6c 6c 20 73 79 73 74 65  6d 20 69 6e 74 65 72 72  |ll system interr|
00001d60  75 70 74 73 2e 0d 0d 54  68 65 20 42 42 43 20 4d  |upts...The BBC M|
00001d70  69 63 72 6f 20 68 61 73  20 74 77 6f 20 56 49 41  |icro has two VIA|
00001d80  73 2e 20 20 54 68 65 73  65 20 61 72 65 20 76 65  |s.  These are ve|
00001d90  72 79 20 76 65 72 73 61  74 69 6c 65 20 63 68 69  |ry versatile chi|
00001da0  70 73 0d 28 61 73 20 74  68 65 20 6e 61 6d 65 20  |ps.(as the name |
00001db0  56 65 72 73 61 74 69 6c  65 20 49 6e 74 65 72 66  |Versatile Interf|
00001dc0  61 63 65 20 41 64 61 70  74 65 72 20 73 75 67 67  |ace Adapter sugg|
00001dd0  65 73 74 73 29 20 61 6e  64 0d 63 6f 6e 74 61 69  |ests) and.contai|
00001de0  6e 20 74 69 6d 65 72 73  2c 20 63 6f 75 6e 74 65  |n timers, counte|
00001df0  72 73 20 61 6e 64 20 6f  74 68 65 72 20 62 69 74  |rs and other bit|
00001e00  73 20 61 6e 64 20 70 69  65 63 65 73 20 28 21 29  |s and pieces (!)|
00001e10  2e 20 20 4f 6e 65 0d 6f  66 20 74 68 65 73 65 20  |.  One.of these |
00001e20  69 73 20 73 65 74 20 61  73 69 64 65 20 66 6f 72  |is set aside for|
00001e30  20 74 68 65 20 70 61 72  61 6c 6c 65 6c 20 70 72  | the parallel pr|
00001e40  69 6e 74 65 72 20 61 6e  64 20 66 6f 72 20 74 68  |inter and for th|
00001e50  65 0d 75 73 65 72 20 28  79 6f 75 29 20 61 6e 64  |e.user (you) and|
00001e60  20 49 20 77 69 6c 6c 20  62 65 20 64 65 61 6c 69  | I will be deali|
00001e70  6e 67 20 77 69 74 68 20  74 77 6f 20 61 73 70 65  |ng with two aspe|
00001e80  63 74 73 20 6f 66 20 74  68 69 73 20 69 6e 0d 64  |cts of this in.d|
00001e90  65 74 61 69 6c 20 6c 61  74 65 72 2e 20 20 54 68  |etail later.  Th|
00001ea0  65 20 6f 74 68 65 72 20  6f 6e 65 20 69 73 20 75  |e other one is u|
00001eb0  73 65 64 20 62 79 20 74  68 65 20 4f 53 20 66 6f  |sed by the OS fo|
00001ec0  72 20 73 79 73 74 65 6d  0d 68 6f 75 73 65 6b 65  |r system.houseke|
00001ed0  65 70 69 6e 67 2e 0d 0d  54 68 65 20 73 79 73 74  |eping...The syst|
00001ee0  65 6d 20 56 49 41 20 77  69 6c 6c 20 67 65 6e 65  |em VIA will gene|
00001ef0  72 61 74 65 20 61 6e 20  69 6e 74 65 72 72 75 70  |rate an interrup|
00001f00  74 20 77 68 65 6e 20 2e  2e 2e 2e 0d 0d 20 20 61  |t when ......  a|
00001f10  20 6b 65 79 20 69 73 20  70 72 65 73 73 65 64 0d  | key is pressed.|
00001f20  20 20 74 68 65 20 54 56  20 70 69 63 74 75 72 65  |  the TV picture|
00001f30  20 72 65 61 63 68 65 73  20 74 68 65 20 76 65 72  | reaches the ver|
00001f40  74 69 63 61 6c 20 69 6e  74 65 72 76 61 6c 20 61  |tical interval a|
00001f50  6e 64 20 66 6c 69 65 73  0d 20 20 20 20 20 20 62  |nd flies.      b|
00001f60  61 63 6b 20 28 35 30 20  74 69 6d 65 73 20 61 20  |ack (50 times a |
00001f70  73 65 63 6f 6e 64 29 0d  20 20 74 68 65 20 6c 69  |second).  the li|
00001f80  67 68 74 70 65 6e 20 64  65 74 65 63 74 73 20 74  |ghtpen detects t|
00001f90  68 65 20 73 63 61 6e 20  73 70 6f 74 20 66 72 6f  |he scan spot fro|
00001fa0  6d 20 74 68 65 20 73 63  72 65 65 6e 0d 20 20 74  |m the screen.  t|
00001fb0  68 65 20 41 20 74 6f 20  44 20 63 6f 6e 76 65 72  |he A to D conver|
00001fc0  74 65 72 20 63 6f 6d 70  6c 65 74 65 73 20 61 20  |ter completes a |
00001fd0  63 6f 6e 76 65 72 73 69  6f 6e 0d 20 20 65 69 74  |conversion.  eit|
00001fe0  68 65 72 20 6f 66 20 74  68 65 20 74 77 6f 20 56  |her of the two V|
00001ff0  49 41 20 74 69 6d 65 72  73 20 72 65 61 63 68 65  |IA timers reache|
00002000  73 20 7a 65 72 6f 0d 0d  49 74 20 63 61 6e 20 61  |s zero..It can a|
00002010  6c 73 6f 20 67 65 6e 65  72 61 74 65 20 61 6e 20  |lso generate an |
00002020  69 6e 74 65 72 72 75 70  74 20 77 68 65 6e 20 69  |interrupt when i|
00002030  74 73 20 73 68 69 66 74  20 72 65 67 69 73 74 65  |ts shift registe|
00002040  72 0d 28 77 68 69 63 68  20 63 6f 75 6e 74 73 20  |r.(which counts |
00002050  70 75 6c 73 65 73 29 20  74 69 6d 65 73 20 6f 75  |pulses) times ou|
00002060  74 2c 20 62 75 74 20 74  68 69 73 20 69 73 20 6e  |t, but this is n|
00002070  6f 74 20 75 73 65 64 20  62 79 20 74 68 65 0d 4f  |ot used by the.O|
00002080  53 20 73 6f 20 73 68 6f  75 6c 64 20 6e 65 76 65  |S so should neve|
00002090  72 20 68 61 70 70 65 6e  2e 0d 0d 54 68 65 20 4f  |r happen...The O|
000020a0  53 2c 20 77 68 65 6e 20  69 74 20 64 65 74 65 63  |S, when it detec|
000020b0  74 73 20 61 6e 20 69 6e  74 65 72 72 75 70 74 2c  |ts an interrupt,|
000020c0  20 6e 65 65 64 73 20 74  6f 20 63 68 65 63 6b 20  | needs to check |
000020d0  69 74 73 0d 70 69 65 63  65 73 20 6f 66 20 68 61  |its.pieces of ha|
000020e0  72 64 77 61 72 65 20 74  6f 20 73 65 65 20 77 68  |rdware to see wh|
000020f0  65 72 65 20 74 68 65 20  69 6e 74 65 72 72 75 70  |ere the interrup|
00002100  74 20 63 61 6d 65 20 66  72 6f 6d 20 69 6e 0d 6f  |t came from in.o|
00002110  72 64 65 72 20 74 6f 20  63 6f 72 72 65 63 74 6c  |rder to correctl|
00002120  79 20 68 61 6e 64 6c 65  20 69 74 2e 20 20 49 74  |y handle it.  It|
00002130  20 63 61 6e 20 71 75 69  63 6b 6c 79 20 63 68 65  | can quickly che|
00002140  63 6b 20 69 66 20 61 6e  0d 69 6e 74 65 72 72 75  |ck if an.interru|
00002150  70 74 20 63 61 6d 65 20  66 72 6f 6d 20 61 20 70  |pt came from a p|
00002160  61 72 74 69 63 75 6c 61  72 20 64 65 76 69 63 65  |articular device|
00002170  20 73 69 6e 63 65 20 65  61 63 68 20 64 65 76 69  | since each devi|
00002180  63 65 0d 68 61 73 20 61  20 66 6c 61 67 20 74 68  |ce.has a flag th|
00002190  61 74 20 69 73 20 73 65  74 20 77 68 65 6e 20 61  |at is set when a|
000021a0  6e 79 20 69 6e 74 65 72  72 75 70 74 20 63 6f 6d  |ny interrupt com|
000021b0  65 73 20 66 72 6f 6d 20  69 74 2e 0d 54 68 69 73  |es from it..This|
000021c0  20 69 73 20 62 65 73 69  64 65 73 20 61 20 66 6c  | is besides a fl|
000021d0  61 67 20 74 6f 20 69 64  65 6e 74 69 66 79 20 74  |ag to identify t|
000021e0  68 65 20 61 63 74 75 61  6c 20 70 61 72 74 20 6f  |he actual part o|
000021f0  66 20 74 68 65 0d 64 65  76 69 63 65 20 74 68 61  |f the.device tha|
00002200  74 20 63 61 75 73 65 64  20 74 68 65 20 69 6e 74  |t caused the int|
00002210  65 72 72 75 70 74 2e 0d  0d 53 6f 20 74 68 65 20  |errupt...So the |
00002220  4f 53 20 6f 6e 6c 79 20  68 61 73 20 74 6f 20 6c  |OS only has to l|
00002230  6f 6f 6b 20 61 74 20 74  68 65 20 66 6c 61 67 20  |ook at the flag |
00002240  6f 6e 20 65 61 63 68 20  64 65 76 69 63 65 20 61  |on each device a|
00002250  6e 64 0d 74 68 65 6e 20  63 68 65 63 6b 20 74 68  |nd.then check th|
00002260  65 20 66 6c 61 67 20 72  65 67 69 73 74 65 72 20  |e flag register |
00002270  6f 6e 20 74 68 65 20 64  65 76 69 63 65 20 74 68  |on the device th|
00002280  61 74 20 73 61 79 73 20  69 74 0d 63 61 75 73 65  |at says it.cause|
00002290  64 20 74 68 65 20 69 6e  74 65 72 72 75 70 74 2e  |d the interrupt.|
000022a0  20 20 49 74 20 64 6f 65  73 6e 27 74 20 68 61 76  |  It doesn't hav|
000022b0  65 20 74 6f 20 63 68 65  63 6b 20 61 6c 6c 20 74  |e to check all t|
000022c0  68 65 0d 66 6c 61 67 73  20 6f 6e 20 61 6c 6c 20  |he.flags on all |
000022d0  74 68 65 20 64 65 76 69  63 65 73 2e 20 20 54 68  |the devices.  Th|
000022e0  69 73 20 69 73 20 69 6d  70 6f 72 74 61 6e 74 20  |is is important |
000022f0  62 65 63 61 75 73 65 0d  69 6e 74 65 72 72 75 70  |because.interrup|
00002300  74 73 2c 20 6c 69 6b 65  20 65 76 65 6e 74 73 2c  |ts, like events,|
00002310  20 68 61 76 65 20 74 6f  20 62 65 20 68 61 6e 64  | have to be hand|
00002320  6c 65 64 20 76 65 72 79  20 71 75 69 63 6b 6c 79  |led very quickly|
00002330  2e 20 0d 49 66 20 69 74  20 74 61 6b 65 73 20 61  |. .If it takes a|
00002340  20 6c 6f 6e 67 20 74 69  6d 65 20 74 6f 20 68 61  | long time to ha|
00002350  6e 64 6c 65 20 61 6e 20  69 6e 74 65 72 72 75 70  |ndle an interrup|
00002360  74 20 74 68 65 6e 20 74  68 65 20 4f 53 0d 77 69  |t then the OS.wi|
00002370  6c 6c 20 73 74 6f 70 20  73 6f 6d 65 20 6f 66 20  |ll stop some of |
00002380  69 74 73 20 66 75 6e 63  74 69 6f 6e 73 20 66 6f  |its functions fo|
00002390  72 20 61 20 77 68 69 6c  65 2c 20 77 68 69 63 68  |r a while, which|
000023a0  20 63 6f 75 6c 64 0d 63  61 75 73 65 20 70 72 6f  | could.cause pro|
000023b0  62 6c 65 6d 73 2e 0d 0d  41 66 74 65 72 20 61 6e  |blems...After an|
000023c0  20 49 52 51 20 68 61 73  20 6f 63 63 75 72 72 65  | IRQ has occurre|
000023d0  64 20 74 68 65 20 4f 53  20 77 69 6c 6c 20 63 68  |d the OS will ch|
000023e0  65 63 6b 20 74 68 65 20  69 6e 74 65 72 72 75 70  |eck the interrup|
000023f0  74 0d 66 6c 61 67 20 6f  6e 20 74 68 65 20 73 79  |t.flag on the sy|
00002400  73 74 65 6d 20 56 49 41  2c 20 74 68 65 20 73 65  |stem VIA, the se|
00002410  72 69 61 6c 20 55 4c 41  20 61 6e 64 20 74 68 65  |rial ULA and the|
00002420  20 75 73 65 72 20 56 49  41 0d 75 6e 74 69 6c 20  | user VIA.until |
00002430  69 74 20 66 69 6e 64 73  20 74 68 65 20 64 65 76  |it finds the dev|
00002440  69 63 65 20 74 68 61 74  20 63 61 75 73 65 64 20  |ice that caused |
00002450  74 68 65 20 49 52 51 2e  20 20 49 74 20 77 69 6c  |the IRQ.  It wil|
00002460  6c 20 74 68 65 6e 0d 63  68 65 63 6b 20 74 68 65  |l then.check the|
00002470  20 64 65 76 69 63 65 20  69 74 73 65 6c 66 20 74  | device itself t|
00002480  6f 20 69 64 65 6e 74 69  66 79 20 74 68 65 20 70  |o identify the p|
00002490  61 72 74 69 63 75 6c 61  72 20 63 61 75 73 65 2e  |articular cause.|
000024a0  20 0d 49 66 20 74 68 69  73 20 69 73 20 6f 6e 65  | .If this is one|
000024b0  20 77 68 69 63 68 20 74  68 65 20 4f 53 20 65 78  | which the OS ex|
000024c0  70 65 63 74 73 20 74 6f  20 73 65 72 76 69 63 65  |pects to service|
000024d0  2c 20 69 74 20 77 69 6c  6c 20 64 6f 0d 73 6f 20  |, it will do.so |
000024e0  61 6e 64 20 74 68 65 6e  20 72 65 74 75 72 6e 2e  |and then return.|
000024f0  20 20 49 66 20 69 74 20  69 73 20 6f 6e 65 20 77  |  If it is one w|
00002500  68 69 63 68 20 74 68 65  20 4f 53 20 64 6f 65 73  |hich the OS does|
00002510  6e 27 74 0d 72 65 63 6f  67 6e 69 73 65 20 69 74  |n't.recognise it|
00002520  20 70 61 73 73 65 73 20  69 74 20 6f 6e 20 74 68  | passes it on th|
00002530  72 6f 75 67 68 20 49 52  51 32 2e 0d 0d 49 74 20  |rough IRQ2...It |
00002540  69 73 20 70 6f 73 73 69  62 6c 65 20 74 6f 20 73  |is possible to s|
00002550  74 6f 70 20 74 68 65 20  4f 53 20 73 65 72 76 69  |top the OS servi|
00002560  63 69 6e 67 20 61 6e 20  69 6e 74 65 72 72 75 70  |cing an interrup|
00002570  74 20 69 74 0d 77 6f 75  6c 64 20 6e 6f 72 6d 61  |t it.would norma|
00002580  6c 6c 79 20 64 6f 20 62  79 20 75 73 69 6e 67 20  |lly do by using |
00002590  4f 53 42 59 54 45 20 32  33 31 20 74 6f 20 32 33  |OSBYTE 231 to 23|
000025a0  33 20 77 68 69 63 68 20  63 61 6e 20 66 6f 72 63  |3 which can forc|
000025b0  65 0d 74 68 65 20 4f 53  20 74 6f 20 70 61 73 73  |e.the OS to pass|
000025c0  20 61 20 70 61 72 74 69  63 75 6c 61 72 20 69 6e  | a particular in|
000025d0  74 65 72 72 75 70 74 20  74 68 72 6f 75 67 68 20  |terrupt through |
000025e0  49 52 51 32 20 66 6f 72  20 74 68 65 0d 75 73 65  |IRQ2 for the.use|
000025f0  72 20 74 6f 20 64 65 61  6c 20 77 69 74 68 2e 20  |r to deal with. |
00002600  20 54 68 69 73 20 69 73  20 6b 6e 6f 77 6e 20 61  | This is known a|
00002610  73 20 6d 61 73 6b 69 6e  67 20 74 68 65 20 49 52  |s masking the IR|
00002620  51 20 61 6e 64 20 79 6f  75 0d 73 68 6f 75 6c 64  |Q and you.should|
00002630  20 63 6f 6e 73 75 6c 74  20 79 6f 75 72 20 61 64  | consult your ad|
00002640  76 61 6e 63 65 64 20 67  75 69 64 65 20 66 6f 72  |vanced guide for|
00002650  20 64 65 74 61 69 6c 73  2e 20 20 5b 54 68 65 72  | details.  [Ther|
00002660  65 20 61 72 65 0d 65 78  61 6d 70 6c 65 20 70 72  |e are.example pr|
00002670  6f 67 72 61 6d 73 20 77  68 69 63 68 20 75 73 65  |ograms which use|
00002680  20 49 52 51 20 6d 61 73  6b 69 6e 67 20 6f 6e 20  | IRQ masking on |
00002690  70 61 67 65 73 20 33 30  36 20 61 6e 64 20 33 30  |pages 306 and 30|
000026a0  38 0d 6f 66 20 42 72 61  79 2c 20 44 69 63 6b 65  |8.of Bray, Dicke|
000026b0  6e 73 20 61 6e 64 20 48  6f 6c 6d 65 73 2e 5d 0d  |ns and Holmes.].|
000026c0  0d 49 20 68 6f 70 65 20  79 6f 75 20 77 69 6c 6c  |.I hope you will|
000026d0  20 73 65 65 20 77 68 79  20 69 6e 74 65 72 72 75  | see why interru|
000026e0  70 74 73 20 61 72 65 20  61 20 27 72 69 73 6b 79  |pts are a 'risky|
000026f0  27 20 61 72 65 61 20 66  6f 72 0d 65 78 70 65 72  |' area for.exper|
00002700  69 6d 65 6e 74 61 74 69  6f 6e 2c 20 73 69 6e 63  |imentation, sinc|
00002710  65 20 69 74 20 69 73 20  61 6c 6c 20 74 6f 6f 20  |e it is all too |
00002720  65 61 73 79 20 74 6f 20  6d 61 6b 65 20 74 68 65  |easy to make the|
00002730  0d 63 6f 6d 70 75 74 65  72 20 68 61 6e 67 20 75  |.computer hang u|
00002740  70 2e 20 20 48 6f 77 65  76 65 72 2c 20 69 74 20  |p.  However, it |
00002750  69 73 20 75 6e 6c 69 6b  65 6c 79 20 74 6f 20 65  |is unlikely to e|
00002760  78 70 6c 6f 64 65 20 73  6f 20 74 68 65 0d 77 6f  |xplode so the.wo|
00002770  72 73 74 20 74 68 61 74  20 63 61 6e 20 68 61 70  |rst that can hap|
00002780  70 65 6e 20 69 73 20 74  68 61 74 20 79 6f 75 20  |pen is that you |
00002790  77 69 6c 6c 20 68 61 76  65 20 74 6f 20 70 72 65  |will have to pre|
000027a0  73 73 20 42 52 45 41 4b  0d 61 6e 64 20 73 74 61  |ss BREAK.and sta|
000027b0  72 74 20 61 67 61 69 6e  2e 0d 0d 49 20 74 68 69  |rt again...I thi|
000027c0  6e 6b 20 69 74 20 69 73  20 62 65 73 74 20 74 6f  |nk it is best to|
000027d0  20 70 72 6f 63 65 65 64  20 66 72 6f 6d 20 68 65  | proceed from he|
000027e0  72 65 20 77 69 74 68 20  65 78 61 6d 70 6c 65 73  |re with examples|
000027f0  2e 20 20 49 0d 70 6c 61  6e 20 74 6f 20 73 68 6f  |.  I.plan to sho|
00002800  77 20 79 6f 75 20 6d 6f  72 65 20 6f 66 20 74 68  |w you more of th|
00002810  65 20 56 49 41 20 74 69  6d 65 72 73 20 69 6e 20  |e VIA timers in |
00002820  74 68 65 20 6e 65 78 74  20 6d 6f 64 75 6c 65 0d  |the next module.|
00002830  62 75 74 20 66 6f 72 20  6e 6f 77 20 49 20 77 69  |but for now I wi|
00002840  6c 6c 20 69 6e 69 74 69  61 74 65 20 79 6f 75 20  |ll initiate you |
00002850  69 6e 74 6f 20 74 68 65  20 6c 69 74 74 6c 65 20  |into the little |
00002860  6b 6e 6f 77 6e 20 73 70  6f 72 74 0d 6f 66 20 6d  |known sport.of m|
00002870  6f 75 73 65 20 64 72 69  76 69 6e 67 2e 20 20 41  |ouse driving.  A|
00002880  20 6d 6f 75 73 65 20 64  72 69 76 65 72 20 69 73  | mouse driver is|
00002890  20 61 20 70 69 65 63 65  20 6f 66 20 63 6f 64 65  | a piece of code|
000028a0  20 74 68 61 74 0d 6b 65  65 70 73 20 74 72 61 63  | that.keeps trac|
000028b0  6b 20 6f 66 20 74 68 65  20 6d 6f 76 65 6d 65 6e  |k of the movemen|
000028c0  74 20 6f 66 20 61 20 6d  6f 75 73 65 20 28 69 2e  |t of a mouse (i.|
000028d0  65 2e 20 61 20 70 6f 69  6e 74 69 6e 67 0d 64 65  |e. a pointing.de|
000028e0  76 69 63 65 29 20 61 74  74 61 63 68 65 64 20 74  |vice) attached t|
000028f0  6f 20 74 68 65 20 6d 69  63 72 6f 20 61 6e 64 20  |o the micro and |
00002900  65 6e 61 62 6c 65 73 20  79 6f 75 20 74 6f 20 69  |enables you to i|
00002910  6d 70 6c 65 6d 65 6e 74  20 61 0d 70 6f 69 6e 74  |mplement a.point|
00002920  65 72 20 73 79 73 74 65  6d 20 6f 6e 20 74 68 65  |er system on the|
00002930  20 73 63 72 65 65 6e 2e  20 20 49 20 73 68 61 6c  | screen.  I shal|
00002940  6c 20 75 73 65 20 74 68  65 20 41 4d 58 20 6d 6f  |l use the AMX mo|
00002950  75 73 65 20 61 73 0d 6d  79 20 65 78 61 6d 70 6c  |use as.my exampl|
00002960  65 2c 20 61 6c 74 68 6f  75 67 68 20 74 68 65 20  |e, although the |
00002970  4d 65 67 61 6d 6f 75 73  65 20 75 73 65 73 20 74  |Megamouse uses t|
00002980  68 65 20 73 61 6d 65 20  63 6f 64 65 2e 20 20 45  |he same code.  E|
00002990  76 65 6e 0d 69 66 20 79  6f 75 20 64 6f 20 6e 6f  |ven.if you do no|
000029a0  74 20 70 6f 73 73 65 73  20 61 20 6d 6f 75 73 65  |t posses a mouse|
000029b0  20 49 20 68 6f 70 65 20  79 6f 75 20 77 69 6c 6c  | I hope you will|
000029c0  20 66 69 6e 64 20 74 68  65 0d 65 78 61 6d 70 6c  | find the.exampl|
000029d0  65 20 75 73 65 66 75 6c  2e 0d 0d 54 68 69 73 20  |e useful...This |
000029e0  6d 6f 75 73 65 20 69 73  20 63 6f 6e 6e 65 63 74  |mouse is connect|
000029f0  65 64 20 74 6f 20 74 68  65 20 6d 69 63 72 6f 27  |ed to the micro'|
00002a00  73 20 75 73 65 72 20 70  6f 72 74 20 61 6e 64 20  |s user port and |
00002a10  73 6f 20 74 6f 0d 74 68  65 20 75 73 65 72 20 56  |so to.the user V|
00002a20  49 41 20 62 65 68 69 6e  64 20 69 74 2e 20 20 41  |IA behind it.  A|
00002a30  73 20 74 68 65 20 6d 6f  75 73 65 20 69 73 20 6d  |s the mouse is m|
00002a40  6f 76 65 64 20 61 20 73  6d 61 6c 6c 0d 76 6f 6c  |oved a small.vol|
00002a50  74 61 67 65 20 28 61 6c  73 6f 20 74 61 6b 65 6e  |tage (also taken|
00002a60  20 66 72 6f 6d 20 74 68  65 20 75 73 65 72 20 70  | from the user p|
00002a70  6f 72 74 29 20 69 73 20  61 70 70 6c 69 65 64 20  |ort) is applied |
00002a80  74 6f 20 66 6f 75 72 0d  77 69 72 65 73 20 69 6e  |to four.wires in|
00002a90  20 74 68 65 20 63 6f 6e  6e 65 63 74 69 6e 67 20  | the connecting |
00002aa0  63 61 62 6c 65 20 69 6e  20 73 75 63 68 20 61 20  |cable in such a |
00002ab0  77 61 79 20 74 68 61 74  20 79 6f 75 20 63 61 6e  |way that you can|
00002ac0  0d 64 65 74 65 63 74 20  74 68 65 20 64 69 72 65  |.detect the dire|
00002ad0  63 74 69 6f 6e 20 6f 66  20 6d 6f 74 69 6f 6e 20  |ction of motion |
00002ae0  61 74 20 61 6e 79 20 69  6e 73 74 61 6e 74 2e 20  |at any instant. |
00002af0  20 54 68 65 20 6d 6f 75  73 65 0d 64 6f 65 73 6e  | The mouse.doesn|
00002b00  27 74 20 74 65 6c 6c 20  79 6f 75 20 77 68 65 72  |'t tell you wher|
00002b10  65 20 69 74 20 69 73 2c  20 69 74 20 74 65 6c 6c  |e it is, it tell|
00002b20  73 20 79 6f 75 20 69 6e  20 77 68 69 63 68 0d 64  |s you in which.d|
00002b30  69 72 65 63 74 69 6f 6e  20 69 74 20 69 73 20 6d  |irection it is m|
00002b40  6f 76 69 6e 67 2e 0d 0d  54 68 65 20 77 61 76 65  |oving...The wave|
00002b50  66 6f 72 6d 20 6f 66 20  74 68 65 20 76 6f 6c 74  |form of the volt|
00002b60  61 67 65 20 69 73 20 72  65 63 74 61 6e 67 75 6c  |age is rectangul|
00002b70  61 72 2c 20 6c 69 6b 65  20 61 20 73 71 75 61 72  |ar, like a squar|
00002b80  65 0d 77 61 76 65 2c 20  61 6e 64 20 69 66 20 77  |e.wave, and if w|
00002b90  65 20 63 61 6c 6c 20 74  68 65 20 63 6f 6e 6e 65  |e call the conne|
00002ba0  63 74 69 6f 6e 73 20 58  31 20 59 31 20 58 32 20  |ctions X1 Y1 X2 |
00002bb0  61 6e 64 20 59 32 20 74  68 65 0d 66 6f 6c 6c 6f  |and Y2 the.follo|
00002bc0  77 69 6e 67 20 72 75 6c  65 73 20 61 70 70 6c 79  |wing rules apply|
00002bd0  2e 0d 0d 49 66 20 74 68  65 20 6d 6f 75 73 65 20  |...If the mouse |
00002be0  6d 6f 76 65 73 20 6c 65  66 74 20 74 6f 20 72 69  |moves left to ri|
00002bf0  67 68 74 20 28 6f 72 20  76 69 63 65 20 76 65 72  |ght (or vice ver|
00002c00  73 61 29 20 61 20 77 61  76 65 66 6f 72 6d 0d 69  |sa) a waveform.i|
00002c10  66 20 61 70 70 6c 69 65  64 20 74 6f 20 74 68 65  |f applied to the|
00002c20  20 58 31 20 61 6e 64 20  58 32 20 77 69 72 65 73  | X1 and X2 wires|
00002c30  20 73 75 63 68 20 74 68  61 74 20 69 66 20 69 74  | such that if it|
00002c40  20 6d 6f 76 65 73 20 6f  6e 65 0d 77 61 79 20 74  | moves one.way t|
00002c50  68 65 20 73 69 67 6e 61  6c 73 20 61 72 65 20 68  |he signals are h|
00002c60  69 67 68 20 61 74 20 74  68 65 20 73 61 6d 65 20  |igh at the same |
00002c70  74 69 6d 65 20 61 6e 64  20 6c 6f 77 20 61 74 20  |time and low at |
00002c80  74 68 65 0d 73 61 6d 65  20 74 69 6d 65 20 28 69  |the.same time (i|
00002c90  2e 65 2e 20 69 6e 20 70  68 61 73 65 29 20 61 6e  |.e. in phase) an|
00002ca0  64 20 69 66 20 69 74 20  6d 6f 76 65 73 20 74 68  |d if it moves th|
00002cb0  65 20 6f 74 68 65 72 20  74 68 65 0d 73 69 67 6e  |e other the.sign|
00002cc0  61 6c 73 20 61 72 65 20  64 69 66 66 65 72 65 6e  |als are differen|
00002cd0  74 20 61 74 20 61 6e 79  20 69 6e 73 74 61 6e 74  |t at any instant|
00002ce0  20 28 69 2e 65 2e 20 6f  75 74 20 6f 66 20 70 68  | (i.e. out of ph|
00002cf0  61 73 65 29 2e 20 0d 53  69 6d 69 6c 61 72 6c 79  |ase). .Similarly|
00002d00  20 66 6f 72 20 74 68 65  20 59 20 77 69 72 65 73  | for the Y wires|
00002d10  20 77 68 65 6e 20 74 68  65 20 6d 6f 75 73 65 20  | when the mouse |
00002d20  6d 6f 76 65 73 20 62 61  63 6b 77 61 72 64 73 20  |moves backwards |
00002d30  61 6e 64 0d 66 6f 72 77  61 72 64 73 2e 0d 0d 58  |and.forwards...X|
00002d40  31 20 61 6e 64 20 59 31  20 61 72 65 20 63 6f 6e  |1 and Y1 are con|
00002d50  6e 65 63 74 65 64 20 74  6f 20 74 68 65 20 74 77  |nected to the tw|
00002d60  6f 20 69 6e 74 65 72 72  75 70 74 20 6c 69 6e 65  |o interrupt line|
00002d70  73 20 6f 6e 20 74 68 65  0d 75 73 65 72 20 70 6f  |s on the.user po|
00002d80  72 74 20 73 6f 20 74 68  65 79 20 63 61 6e 20 62  |rt so they can b|
00002d90  65 20 75 73 65 64 20 74  6f 20 67 65 6e 65 72 61  |e used to genera|
00002da0  74 65 20 61 6e 20 69 6e  74 65 72 72 75 70 74 20  |te an interrupt |
00002db0  66 72 6f 6d 0d 74 68 65  20 75 73 65 72 20 56 49  |from.the user VI|
00002dc0  41 2e 20 20 57 65 20 77  69 6c 6c 20 73 65 74 20  |A.  We will set |
00002dd0  74 68 65 20 56 49 41 20  74 6f 20 67 65 6e 65 72  |the VIA to gener|
00002de0  61 74 65 20 74 68 69 73  0d 69 6e 74 65 72 72 75  |ate this.interru|
00002df0  70 74 20 77 68 65 6e 65  76 65 72 20 74 68 65 20  |pt whenever the |
00002e00  56 49 41 20 6c 69 6e 65  20 64 65 74 65 63 74 73  |VIA line detects|
00002e10  20 61 20 70 6f 73 69 74  69 76 65 20 67 6f 69 6e  | a positive goin|
00002e20  67 0d 76 6f 6c 74 61 67  65 20 28 69 2e 65 2e 20  |g.voltage (i.e. |
00002e30  74 68 65 20 66 72 6f 6e  74 20 70 6f 72 63 68 20  |the front porch |
00002e40  6f 66 20 74 68 65 20 72  65 63 74 61 6e 67 75 6c  |of the rectangul|
00002e50  61 72 20 77 61 76 65 66  6f 72 6d 29 0d 66 72 6f  |ar waveform).fro|
00002e60  6d 20 65 69 74 68 65 72  20 6c 69 6e 65 2e 0d 0d  |m either line...|
00002e70  57 68 65 6e 20 74 68 65  20 69 6e 74 65 72 72 75  |When the interru|
00002e80  70 74 20 6f 63 63 75 72  73 20 77 65 20 6c 6f 6f  |pt occurs we loo|
00002e90  6b 20 61 74 20 74 68 65  20 63 6f 72 72 65 73 70  |k at the corresp|
00002ea0  6f 6e 64 69 6e 67 0d 73  65 63 6f 6e 64 20 6c 69  |onding.second li|
00002eb0  6e 65 20 28 58 32 20 6f  72 20 59 32 29 20 74 6f  |ne (X2 or Y2) to|
00002ec0  20 73 65 65 20 69 66 20  69 74 20 69 73 20 68 69  | see if it is hi|
00002ed0  67 68 20 6f 72 20 6c 6f  77 20 61 74 20 74 68 61  |gh or low at tha|
00002ee0  74 0d 6d 6f 6d 65 6e 74  20 61 6e 64 20 68 65 6e  |t.moment and hen|
00002ef0  63 65 20 64 65 64 75 63  65 20 77 68 69 63 68 20  |ce deduce which |
00002f00  77 61 79 20 74 68 65 20  6d 6f 75 73 65 20 69 73  |way the mouse is|
00002f10  20 6d 6f 76 69 6e 67 2e  0d 0d 41 73 20 49 20 68  | moving...As I h|
00002f20  61 76 65 20 73 61 69 64  2c 20 74 68 65 20 6c 69  |ave said, the li|
00002f30  6e 65 73 20 6f 6e 20 74  68 65 20 75 73 65 72 20  |nes on the user |
00002f40  70 6f 72 74 20 61 72 65  20 63 6f 6e 6e 65 63 74  |port are connect|
00002f50  65 64 20 74 6f 0d 74 68  65 20 75 73 65 72 20 56  |ed to.the user V|
00002f60  49 41 2e 20 20 49 6e 20  66 61 63 74 20 74 68 65  |IA.  In fact the|
00002f70  20 75 73 65 72 20 70 6f  72 74 20 63 6f 6e 6e 65  | user port conne|
00002f80  63 74 73 20 74 6f 20 74  68 65 20 27 42 27 0d 73  |cts to the 'B'.s|
00002f90  69 64 65 20 6f 66 20 74  68 69 73 20 64 65 76 69  |ide of this devi|
00002fa0  63 65 20 61 6e 64 20 74  68 65 20 70 61 72 61 6c  |ce and the paral|
00002fb0  6c 65 6c 20 70 72 69 6e  74 65 72 20 63 6f 6e 6e  |lel printer conn|
00002fc0  65 63 74 73 20 74 6f 20  74 68 65 0d 6f 74 68 65  |ects to the.othe|
00002fd0  72 2e 20 20 54 68 65 20  56 49 41 20 69 73 20 61  |r.  The VIA is a|
00002fe0  20 64 65 76 69 63 65 20  63 61 6c 6c 65 64 20 61  | device called a|
00002ff0  20 36 35 32 32 20 61 6e  64 20 69 6e 66 6f 72 6d  | 6522 and inform|
00003000  61 74 69 6f 6e 20 6f 6e  0d 68 6f 77 20 74 6f 20  |ation on.how to |
00003010  75 73 65 20 69 74 20 63  61 6e 20 62 65 20 67 6c  |use it can be gl|
00003020  65 61 6e 65 64 20 28 77  69 74 68 20 61 20 6c 69  |eaned (with a li|
00003030  74 74 6c 65 20 64 69 66  66 69 63 75 6c 74 79 29  |ttle difficulty)|
00003040  20 66 72 6f 6d 0d 74 68  65 20 73 70 65 63 69 66  | from.the specif|
00003050  69 63 61 74 69 6f 6e 20  73 68 65 65 74 73 20 66  |ication sheets f|
00003060  6f 72 20 74 68 65 20 64  65 76 69 63 65 2e 20 20  |or the device.  |
00003070  42 72 61 79 2c 20 44 69  63 6b 65 6e 73 20 61 6e  |Bray, Dickens an|
00003080  64 0d 48 6f 6c 6d 65 73  20 28 41 64 76 61 6e 63  |d.Holmes (Advanc|
00003090  65 64 20 55 73 65 72 20  47 75 69 64 65 29 20 61  |ed User Guide) a|
000030a0  6c 73 6f 20 72 65 70 72  69 6e 74 73 20 74 68 65  |lso reprints the|
000030b0  20 69 6e 66 6f 72 6d 61  74 69 6f 6e 0d 66 72 6f  | information.fro|
000030c0  6d 20 74 68 65 20 73 70  65 63 20 73 68 65 65 74  |m the spec sheet|
000030d0  2e 0d 0d 49 6e 20 62 72  69 65 66 20 74 68 65 20  |...In brief the |
000030e0  64 65 76 69 63 65 20 69  73 20 73 65 74 20 75 70  |device is set up|
000030f0  20 62 79 20 70 6f 6b 69  6e 67 20 62 69 74 73 20  | by poking bits |
00003100  69 6e 20 69 74 73 0d 72  65 67 69 73 74 65 72 73  |in its.registers|
00003110  2e 20 20 4f 6e 20 74 68  65 20 42 42 43 20 4d 69  |.  On the BBC Mi|
00003120  63 72 6f 20 74 68 6f 73  65 20 72 65 67 69 73 74  |cro those regist|
00003130  65 72 73 20 6c 69 76 65  20 69 6e 20 74 68 65 0d  |ers live in the.|
00003140  61 72 65 61 20 6f 66 20  6d 65 6d 6f 72 79 20 6b  |area of memory k|
00003150  6e 6f 77 6e 20 61 73 20  53 68 65 69 6c 61 20 61  |nown as Sheila a|
00003160  6e 64 20 74 68 65 20 75  73 65 72 20 56 49 41 20  |nd the user VIA |
00003170  6c 69 76 65 73 20 66 72  6f 6d 0d 26 46 45 36 30  |lives from.&FE60|
00003180  20 74 6f 20 26 46 45 36  46 2e 20 20 54 68 65 72  | to &FE6F.  Ther|
00003190  65 20 61 72 65 20 31 36  20 72 65 67 69 73 74 65  |e are 16 registe|
000031a0  72 73 20 61 73 20 66 6f  6c 6c 6f 77 73 3a 0d 0d  |rs as follows:..|
000031b0  20 26 46 45 36 30 20 20  49 2f 4f 20 66 6f 72 20  | &FE60  I/O for |
000031c0  74 68 65 20 27 42 27 20  73 69 64 65 20 6f 66 20  |the 'B' side of |
000031d0  74 68 65 20 56 49 41 0d  20 20 20 20 20 31 20 20  |the VIA.     1  |
000031e0  49 2f 4f 20 66 6f 72 20  74 68 65 20 27 41 27 20  |I/O for the 'A' |
000031f0  73 69 64 65 20 6f 66 20  74 68 65 20 56 49 41 0d  |side of the VIA.|
00003200  20 20 20 20 20 32 20 20  43 6f 6e 74 72 6f 6c 20  |     2  Control |
00003210  6f 66 20 74 68 65 20 64  69 72 65 63 74 69 6f 6e  |of the direction|
00003220  20 6f 66 20 64 61 74 61  20 6f 6e 20 74 68 65 20  | of data on the |
00003230  27 42 27 20 73 69 64 65  0d 20 20 20 20 20 33 20  |'B' side.     3 |
00003240  20 43 6f 6e 74 72 6f 6c  20 6f 66 20 74 68 65 20  | Control of the |
00003250  64 69 72 65 63 74 69 6f  6e 20 6f 66 20 64 61 74  |direction of dat|
00003260  61 20 6f 6e 20 74 68 65  20 27 41 27 20 73 69 64  |a on the 'A' sid|
00003270  65 0d 20 20 20 20 20 34  20 20 54 69 6d 65 72 20  |e.     4  Timer |
00003280  31 20 63 6f 6e 74 72 6f  6c 0d 20 20 20 20 20 35  |1 control.     5|
00003290  20 20 54 69 6d 65 72 20  31 20 63 6f 6e 74 72 6f  |  Timer 1 contro|
000032a0  6c 0d 20 20 20 20 20 36  20 20 54 69 6d 65 72 20  |l.     6  Timer |
000032b0  31 20 63 6f 6e 74 72 6f  6c 0d 20 20 20 20 20 37  |1 control.     7|
000032c0  20 20 54 69 6d 65 72 20  31 20 63 6f 6e 74 72 6f  |  Timer 1 contro|
000032d0  6c 0d 20 20 20 20 20 38  20 20 54 69 6d 65 72 20  |l.     8  Timer |
000032e0  32 20 63 6f 6e 74 72 6f  6c 0d 20 20 20 20 20 39  |2 control.     9|
000032f0  20 20 54 69 6d 65 72 20  32 20 63 6f 6e 74 72 6f  |  Timer 2 contro|
00003300  6c 0d 20 20 20 20 20 41  20 20 53 68 69 66 74 20  |l.     A  Shift |
00003310  72 65 67 69 73 74 65 72  0d 20 20 20 20 20 42 20  |register.     B |
00003320  20 41 75 78 69 6c 69 61  72 79 20 63 6f 6e 74 72  | Auxiliary contr|
00003330  6f 6c 0d 20 20 20 20 20  43 20 20 50 65 72 69 70  |ol.     C  Perip|
00003340  68 65 72 61 6c 20 63 6f  6e 74 72 6f 6c 0d 20 20  |heral control.  |
00003350  20 20 20 44 20 20 49 6e  74 65 72 72 75 70 74 20  |   D  Interrupt |
00003360  66 6c 61 67 73 0d 20 20  20 20 20 45 20 20 49 6e  |flags.     E  In|
00003370  74 65 72 72 75 70 74 20  65 6e 61 62 6c 69 6e 67  |terrupt enabling|
00003380  0d 20 20 20 20 20 46 20  20 53 61 6d 65 20 61 73  |.     F  Same as|
00003390  20 72 65 67 69 73 74 65  72 20 31 20 62 75 74 20  | register 1 but |
000033a0  77 69 74 68 6f 75 74 20  68 61 6e 64 73 68 61 6b  |without handshak|
000033b0  69 6e 67 0d 0d 54 68 65  72 65 27 73 20 61 20 6c  |ing..There's a l|
000033c0  6f 74 20 69 6e 20 74 68  65 20 56 49 41 73 2e 20  |ot in the VIAs. |
000033d0  20 49 27 6c 6c 20 73 68  6f 77 20 79 6f 75 20 61  | I'll show you a|
000033e0  6e 20 61 70 70 6c 69 63  61 74 69 6f 6e 0d 75 73  |n application.us|
000033f0  69 6e 67 20 61 20 74 69  6d 65 72 20 69 6e 20 74  |ing a timer in t|
00003400  68 65 20 6e 65 78 74 20  6d 6f 64 75 6c 65 2e 20  |he next module. |
00003410  20 54 68 65 20 73 68 69  66 74 20 72 65 67 69 73  | The shift regis|
00003420  74 65 72 20 69 73 0d 75  73 65 64 20 66 6f 72 20  |ter is.used for |
00003430  63 6f 75 6e 74 69 6e 67  20 70 75 6c 73 65 73 2e  |counting pulses.|
00003440  20 20 54 68 65 20 61 75  78 69 6c 69 61 72 79 20  |  The auxiliary |
00003450  63 6f 6e 74 72 6f 6c 20  73 65 74 73 0d 70 61 72  |control sets.par|
00003460  61 6d 65 74 65 72 73 20  66 6f 72 20 74 68 65 20  |ameters for the |
00003470  74 69 6d 65 72 73 20 61  6e 64 20 73 68 69 66 74  |timers and shift|
00003480  20 72 65 67 69 73 74 65  72 20 61 6e 64 20 74 68  | register and th|
00003490  65 0d 70 65 72 69 70 68  65 72 61 6c 20 63 6f 6e  |e.peripheral con|
000034a0  74 72 6f 6c 20 73 65 74  73 20 75 70 20 74 68 65  |trol sets up the|
000034b0  20 77 61 79 20 74 68 65  20 69 6e 74 65 72 72 75  | way the interru|
000034c0  70 74 20 6c 69 6e 65 73  0d 72 65 73 70 6f 6e 64  |pt lines.respond|
000034d0  20 74 6f 20 74 68 65 20  76 6f 6c 74 61 67 65 73  | to the voltages|
000034e0  20 61 70 70 6c 69 65 64  20 74 6f 20 74 68 65 6d  | applied to them|
000034f0  2e 0d 0d 54 6f 20 61 63  63 65 73 73 20 74 68 65  |...To access the|
00003500  73 65 20 73 65 63 74 69  6f 6e 73 20 6f 66 20 6d  |se sections of m|
00003510  65 6d 6f 72 79 20 79 6f  75 20 77 6f 75 6c 64 20  |emory you would |
00003520  6e 6f 72 6d 61 6c 6c 79  20 75 73 65 0d 4f 53 42  |normally use.OSB|
00003530  59 54 45 20 77 69 74 68  20 41 20 62 65 74 77 65  |YTE with A betwe|
00003540  65 6e 20 31 34 36 20 61  6e 64 20 31 35 31 2e 20  |en 146 and 151. |
00003550  20 54 68 65 73 65 20 63  61 6c 6c 73 20 72 65 61  | These calls rea|
00003560  64 20 66 72 6f 6d 0d 61  6e 64 20 77 72 69 74 65  |d from.and write|
00003570  20 74 6f 20 74 68 65 20  6d 65 6d 6f 72 79 2d 6d  | to the memory-m|
00003580  61 70 70 65 64 20 49 2f  4f 20 28 46 72 65 64 2c  |apped I/O (Fred,|
00003590  20 4a 69 6d 20 61 6e 64  20 53 68 65 69 6c 61 29  | Jim and Sheila)|
000035a0  20 61 73 0d 66 6f 6c 6c  6f 77 73 2e 0d 0d 20 20  | as.follows...  |
000035b0  20 20 4f 53 42 59 54 45  20 31 34 36 20 2d 20 52  |  OSBYTE 146 - R|
000035c0  65 61 64 20 46 72 65 64  20 28 26 46 43 30 30 20  |ead Fred (&FC00 |
000035d0  74 6f 20 26 46 43 46 46  29 0d 20 20 20 20 4f 53  |to &FCFF).    OS|
000035e0  42 59 54 45 20 31 34 37  20 2d 20 57 72 69 74 65  |BYTE 147 - Write|
000035f0  20 46 72 65 64 0d 20 20  20 20 4f 53 42 59 54 45  | Fred.    OSBYTE|
00003600  20 31 34 38 20 2d 20 52  65 61 64 20 4a 69 6d 20  | 148 - Read Jim |
00003610  28 26 46 44 30 30 20 74  6f 20 26 46 44 46 46 29  |(&FD00 to &FDFF)|
00003620  0d 20 20 20 20 4f 53 42  59 54 45 20 31 34 39 20  |.    OSBYTE 149 |
00003630  2d 20 57 72 69 74 65 20  4a 69 6d 0d 20 20 20 20  |- Write Jim.    |
00003640  4f 53 42 59 54 45 20 31  35 30 20 2d 20 52 65 61  |OSBYTE 150 - Rea|
00003650  64 20 53 68 65 69 6c 61  20 28 26 46 45 30 30 20  |d Sheila (&FE00 |
00003660  74 6f 20 26 46 45 46 46  29 0d 20 20 20 20 4f 53  |to &FEFF).    OS|
00003670  42 59 54 45 20 31 35 31  20 2d 20 57 72 69 74 65  |BYTE 151 - Write|
00003680  20 53 68 65 69 6c 61 0d  0d 49 6e 20 65 61 63 68  | Sheila..In each|
00003690  20 63 61 73 65 2c 20 6f  6e 20 65 6e 74 72 79 20  | case, on entry |
000036a0  58 20 63 6f 6e 74 61 69  6e 73 20 74 68 65 20 6f  |X contains the o|
000036b0  66 66 73 65 74 20 77 69  74 68 69 6e 20 74 68 65  |ffset within the|
000036c0  20 70 61 67 65 0d 61 6e  64 2c 20 69 66 20 61 20  | page.and, if a |
000036d0  77 72 69 74 65 2c 20 59  20 63 6f 6e 74 61 69 6e  |write, Y contain|
000036e0  73 20 74 68 65 20 62 79  74 65 2e 20 20 4f 6e 20  |s the byte.  On |
000036f0  65 78 69 74 2c 20 69 66  20 61 20 72 65 61 64 2c  |exit, if a read,|
00003700  20 59 0d 63 6f 6e 74 61  69 6e 73 20 74 68 65 20  | Y.contains the |
00003710  62 79 74 65 20 72 65 61  64 2e 20 20 54 68 69 73  |byte read.  This|
00003720  20 63 61 6c 6c 20 77 69  6c 6c 20 70 72 65 73 75  | call will presu|
00003730  6d 61 62 6c 79 20 77 6f  72 6b 0d 77 68 65 72 65  |mably work.where|
00003740  76 65 72 20 46 72 65 64  20 4a 69 6d 20 61 6e 64  |ver Fred Jim and|
00003750  20 53 68 65 69 6c 61 20  61 72 65 20 6c 6f 63 61  | Sheila are loca|
00003760  74 65 64 20 69 6e 20 66  75 74 75 72 65 20 6d 61  |ted in future ma|
00003770  63 68 69 6e 65 73 2e 20  0d 0d 41 6c 74 65 72 6e  |chines. ..Altern|
00003780  61 74 69 76 65 6c 79 20  79 6f 75 20 63 6f 75 6c  |atively you coul|
00003790  64 20 75 73 65 20 4f 53  57 4f 52 44 73 20 35 20  |d use OSWORDs 5 |
000037a0  61 6e 64 20 36 20 74 6f  20 72 65 61 64 20 6f 72  |and 6 to read or|
000037b0  20 77 72 69 74 65 0d 74  6f 20 49 2f 4f 20 70 72  | write.to I/O pr|
000037c0  6f 63 65 73 73 6f 72 20  6d 65 6d 6f 72 79 2e 20  |ocessor memory. |
000037d0  20 54 68 65 20 4f 53 57  4f 52 44 20 70 61 72 61  | The OSWORD para|
000037e0  6d 65 74 65 72 20 62 6c  6f 63 6b 2c 20 61 74 20  |meter block, at |
000037f0  74 68 65 0d 6c 6f 63 61  74 69 6f 6e 20 70 6f 69  |the.location poi|
00003800  6e 74 65 64 20 74 6f 20  62 79 20 74 68 65 20 58  |nted to by the X|
00003810  20 61 6e 64 20 59 20 72  65 67 69 73 74 65 72 73  | and Y registers|
00003820  2c 20 63 6f 6e 74 61 69  6e 73 20 74 68 65 0d 61  |, contains the.a|
00003830  64 64 72 65 73 73 20 69  6e 20 74 68 65 20 49 2f  |ddress in the I/|
00003840  4f 20 70 72 6f 63 65 73  73 6f 72 20 69 6e 20 74  |O processor in t|
00003850  68 65 20 66 69 72 73 74  20 34 20 62 79 74 65 73  |he first 4 bytes|
00003860  20 61 6e 64 20 69 6e 20  74 68 65 0d 35 74 68 20  | and in the.5th |
00003870  62 79 74 65 20 69 73 20  70 75 74 2c 20 6f 72 20  |byte is put, or |
00003880  69 73 20 72 65 61 64 2c  20 74 68 65 20 62 79 74  |is read, the byt|
00003890  65 20 74 6f 20 62 65 20  74 72 61 6e 73 66 65 72  |e to be transfer|
000038a0  72 65 64 0d 61 63 72 6f  73 73 2e 20 20 54 68 65  |red.across.  The|
000038b0  20 4f 53 42 59 54 45 20  63 61 6c 6c 73 20 61 6e  | OSBYTE calls an|
000038c0  64 20 74 68 65 20 4f 53  57 4f 52 44 20 63 61 6c  |d the OSWORD cal|
000038d0  6c 73 20 77 6f 72 6b 20  61 63 72 6f 73 73 0d 74  |ls work across.t|
000038e0  68 65 20 74 75 62 65 2c  20 69 2e 65 2e 20 66 72  |he tube, i.e. fr|
000038f0  6f 6d 20 61 20 73 65 63  6f 6e 64 20 70 72 6f 63  |om a second proc|
00003900  65 73 73 6f 72 2e 0d 0d  49 6e 20 74 68 65 20 63  |essor...In the c|
00003910  61 73 65 20 6f 66 20 69  6e 74 65 72 72 75 70 74  |ase of interrupt|
00003920  73 20 79 6f 75 72 20 69  6e 74 65 72 63 65 70 74  |s your intercept|
00003930  69 6e 67 20 63 6f 64 65  20 68 61 73 20 74 6f 20  |ing code has to |
00003940  62 65 0d 69 6e 20 74 68  65 20 49 2f 4f 20 70 72  |be.in the I/O pr|
00003950  6f 63 65 73 73 6f 72 2c  20 73 6f 20 63 72 6f 73  |ocessor, so cros|
00003960  73 2d 74 75 62 65 20 72  65 71 75 69 72 65 6d 65  |s-tube requireme|
00003970  6e 74 73 20 64 6f 20 6e  6f 74 20 63 6f 6d 65 0d  |nts do not come.|
00003980  69 6e 74 6f 20 69 74 2e  20 20 49 66 20 77 65 20  |into it.  If we |
00003990  74 61 6b 65 20 74 68 65  20 28 73 6d 61 6c 6c 29  |take the (small)|
000039a0  20 72 69 73 6b 20 74 68  61 74 20 53 68 65 69 6c  | risk that Sheil|
000039b0  61 20 77 69 6c 6c 20 6d  6f 76 65 0d 69 6e 20 66  |a will move.in f|
000039c0  75 74 75 72 65 20 74 68  65 20 62 65 73 74 20 74  |uture the best t|
000039d0  68 69 6e 67 20 74 6f 20  64 6f 20 69 73 20 77 72  |hing to do is wr|
000039e0  69 74 65 20 61 6e 64 20  72 65 61 64 20 74 68 65  |ite and read the|
000039f0  20 6d 65 6d 6f 72 79 0d  6c 6f 63 61 74 69 6f 6e  | memory.location|
00003a00  73 20 64 69 72 65 63 74  6c 79 2e 20 20 41 6e 79  |s directly.  Any|
00003a10  20 69 6e 74 65 72 72 75  70 74 20 63 6f 64 65 20  | interrupt code |
00003a20  6d 75 73 74 20 62 65 20  73 68 6f 72 74 20 61 6e  |must be short an|
00003a30  64 20 74 6f 0d 74 68 65  20 70 6f 69 6e 74 2c 20  |d to.the point, |
00003a40  73 6f 20 77 65 20 73 68  6f 75 6c 64 20 61 76 6f  |so we should avo|
00003a50  69 64 20 75 6e 6e 65 63  65 73 73 61 72 79 20 4f  |id unnecessary O|
00003a60  53 20 63 61 6c 6c 73 2e  20 20 49 6e 20 61 6e 79  |S calls.  In any|
00003a70  0d 63 61 73 65 20 74 68  65 72 65 20 69 73 20 61  |.case there is a|
00003a80  20 72 65 73 74 72 69 63  74 69 6f 6e 20 6f 6e 20  | restriction on |
00003a90  77 68 69 63 68 20 4f 53  20 63 61 6c 6c 73 20 63  |which OS calls c|
00003aa0  61 6e 20 62 65 20 75 73  65 64 0d 64 75 72 69 6e  |an be used.durin|
00003ab0  67 20 69 6e 74 65 72 72  75 70 74 73 2e 20 20 49  |g interrupts.  I|
00003ac0  20 77 69 6c 6c 20 67 69  76 65 20 79 6f 75 20 6d  | will give you m|
00003ad0  6f 72 65 20 64 65 74 61  69 6c 20 69 6e 20 74 68  |ore detail in th|
00003ae0  65 20 6e 65 78 74 0d 6d  6f 64 75 6c 65 2e 0d 0d  |e next.module...|
00003af0  49 6e 20 74 68 69 73 20  6d 6f 64 75 6c 65 20 77  |In this module w|
00003b00  65 20 73 68 61 6c 6c 20  64 65 61 6c 20 64 69 72  |e shall deal dir|
00003b10  65 63 74 6c 79 20 77 69  74 68 20 74 68 65 20 72  |ectly with the r|
00003b20  65 67 69 73 74 65 72 73  20 6f 66 0d 74 68 65 20  |egisters of.the |
00003b30  56 49 41 2e 20 20 54 6f  20 73 65 74 20 75 70 20  |VIA.  To set up |
00003b40  74 68 65 20 56 49 41 20  74 6f 20 64 65 74 65 63  |the VIA to detec|
00003b50  74 20 74 68 65 20 6d 6f  75 73 65 20 77 65 20 6d  |t the mouse we m|
00003b60  75 73 74 20 64 6f 0d 74  68 72 65 65 20 74 68 69  |ust do.three thi|
00003b70  6e 67 73 2e 20 20 57 65  20 6d 75 73 74 20 65 6e  |ngs.  We must en|
00003b80  61 62 6c 65 20 74 68 65  20 69 6e 74 65 72 72 75  |able the interru|
00003b90  70 74 73 20 77 65 20 61  72 65 20 67 6f 69 6e 67  |pts we are going|
00003ba0  20 74 6f 0d 75 73 65 2c  20 73 65 74 20 75 70 20  | to.use, set up |
00003bb0  74 68 65 20 62 65 68 61  76 69 6f 75 72 20 6f 66  |the behaviour of|
00003bc0  20 74 68 65 20 69 6e 74  65 72 72 75 70 74 20 6c  | the interrupt l|
00003bd0  69 6e 65 73 20 61 6e 64  20 73 65 74 20 75 70 0d  |ines and set up.|
00003be0  74 68 65 20 72 65 6c 65  76 61 6e 74 20 62 69 74  |the relevant bit|
00003bf0  73 20 6f 66 20 74 68 65  20 75 73 65 72 20 70 6f  |s of the user po|
00003c00  72 74 20 74 6f 20 61 63  74 20 61 73 20 69 6e 70  |rt to act as inp|
00003c10  75 74 73 2e 0d 0d 54 68  65 20 66 69 72 73 74 20  |uts...The first |
00003c20  73 65 63 74 69 6f 6e 20  6f 66 20 74 68 65 20 6d  |section of the m|
00003c30  61 63 68 69 6e 65 20 63  6f 64 65 20 69 6e 20 42  |achine code in B|
00003c40  2f 6f 73 62 31 38 20 72  65 73 65 74 73 20 74 68  |/osb18 resets th|
00003c50  65 0d 49 52 51 20 76 65  63 74 6f 72 2e 20 20 49  |e.IRQ vector.  I|
00003c60  20 68 61 76 65 20 75 73  65 64 20 49 52 51 31 20  | have used IRQ1 |
00003c70  62 65 63 61 75 73 65 20  77 65 20 6e 65 65 64 20  |because we need |
00003c80  61 20 66 61 73 74 0d 72  65 73 70 6f 6e 73 65 20  |a fast.response |
00003c90  74 6f 20 74 68 65 20 6d  6f 75 73 65 20 69 6e 74  |to the mouse int|
00003ca0  65 72 72 75 70 74 2e 20  20 57 68 65 6e 20 79 6f  |errupt.  When yo|
00003cb0  75 20 68 61 76 65 20 73  65 65 6e 20 74 68 69 73  |u have seen this|
00003cc0  0d 63 6f 64 65 20 69 6e  20 61 63 74 69 6f 6e 20  |.code in action |
00003cd0  79 6f 75 20 73 68 6f 75  6c 64 20 63 68 61 6e 67  |you should chang|
00003ce0  65 20 74 68 65 20 76 61  6c 75 65 20 6f 66 20 27  |e the value of '|
00003cf0  69 72 71 31 27 20 69 6e  20 6c 69 6e 65 0d 31 33  |irq1' in line.13|
00003d00  30 20 74 6f 20 26 32 30  36 20 61 6e 64 20 63 6f  |0 to &206 and co|
00003d10  6d 70 61 72 65 20 74 68  65 20 72 65 73 75 6c 74  |mpare the result|
00003d20  73 2e 20 20 5b 4e 6f 74  65 20 74 68 61 74 20 69  |s.  [Note that i|
00003d30  66 20 79 6f 75 20 68 61  76 65 0d 61 6e 20 41 4d  |f you have.an AM|
00003d40  58 20 6d 6f 75 73 65 20  63 68 69 70 20 69 6e 20  |X mouse chip in |
00003d50  79 6f 75 72 20 6d 61 63  68 69 6e 65 20 79 6f 75  |your machine you|
00003d60  20 6d 75 73 74 20 72 65  6d 6f 76 65 20 6f 72 20  | must remove or |
00003d70  64 69 73 61 62 6c 65 0d  69 74 20 62 65 66 6f 72  |disable.it befor|
00003d80  65 20 79 6f 75 20 63 61  6e 20 67 65 74 20 41 4e  |e you can get AN|
00003d90  59 20 72 65 73 75 6c 74  20 66 72 6f 6d 20 75 73  |Y result from us|
00003da0  69 6e 67 20 49 52 51 32  20 61 74 20 26 32 30 36  |ing IRQ2 at &206|
00003db0  2e 5d 20 0d 0d 57 65 20  6d 75 73 74 20 65 6e 61  |.] ..We must ena|
00003dc0  62 6c 65 20 69 6e 74 65  72 72 75 70 74 73 20 66  |ble interrupts f|
00003dd0  72 6f 6d 20 74 68 65 20  74 77 6f 20 27 42 27 20  |rom the two 'B' |
00003de0  73 69 64 65 20 69 6e 74  65 72 72 75 70 74 0d 6c  |side interrupt.l|
00003df0  69 6e 65 73 2c 20 6b 6e  6f 77 6e 20 61 73 20 43  |ines, known as C|
00003e00  42 31 20 61 6e 64 20 43  42 32 2e 20 20 54 6f 20  |B1 and CB2.  To |
00003e10  64 6f 20 74 68 69 73 20  77 65 20 6d 61 6b 65 20  |do this we make |
00003e20  73 75 72 65 20 74 68 61  74 0d 62 69 74 73 20 33  |sure that.bits 3|
00003e30  20 61 6e 64 20 34 20 61  72 65 20 73 65 74 20 62  | and 4 are set b|
00003e40  79 20 4f 52 69 6e 67 20  74 68 65 20 63 75 72 72  |y ORing the curr|
00003e50  65 6e 74 20 63 6f 6e 74  65 6e 74 73 20 6f 66 20  |ent contents of |
00003e60  74 68 69 73 0d 72 65 67  69 73 74 65 72 20 77 69  |this.register wi|
00003e70  74 68 20 32 34 20 28 38  2b 31 36 29 20 61 6e 64  |th 24 (8+16) and|
00003e80  20 72 65 2d 73 61 76 69  6e 67 2e 0d 0d 54 6f 20  | re-saving...To |
00003e90  6d 61 6b 65 20 43 42 31  20 61 6e 64 20 43 42 32  |make CB1 and CB2|
00003ea0  20 6f 70 65 72 61 74 65  20 61 73 20 77 65 20 77  | operate as we w|
00003eb0  69 73 68 2c 20 62 79 20  69 6e 74 65 72 72 75 70  |ish, by interrup|
00003ec0  74 69 6e 67 20 6f 6e 0d  74 68 65 20 70 6f 73 69  |ting on.the posi|
00003ed0  74 69 76 65 2d 67 6f 69  6e 67 20 65 64 67 65 20  |tive-going edge |
00003ee0  6f 66 20 74 68 65 20 77  61 76 65 66 6f 72 6d 2c  |of the waveform,|
00003ef0  20 77 65 20 68 61 76 65  20 74 6f 20 73 65 74 20  | we have to set |
00003f00  62 69 74 73 0d 34 20 61  6e 64 20 36 20 6f 66 20  |bits.4 and 6 of |
00003f10  74 68 65 20 70 65 72 69  70 68 65 72 61 6c 20 63  |the peripheral c|
00003f20  6f 6e 74 72 6f 6c 20 72  65 67 69 73 74 65 72 2e  |ontrol register.|
00003f30  20 20 54 68 69 73 20 69  73 20 61 6c 73 6f 0d 62  |  This is also.b|
00003f40  65 73 74 20 64 6f 6e 65  20 62 79 20 4f 52 69 6e  |est done by ORin|
00003f50  67 20 74 68 65 20 63 75  72 72 65 6e 74 20 63 6f  |g the current co|
00003f60  6e 74 65 6e 74 73 20 77  69 74 68 20 38 30 20 28  |ntents with 80 (|
00003f70  31 36 2b 36 34 29 2e 20  20 41 73 0d 79 6f 75 20  |16+64).  As.you |
00003f80  63 61 6e 20 73 65 65 20  66 72 6f 6d 20 74 68 65  |can see from the|
00003f90  20 6c 69 73 74 69 6e 67  20 61 74 20 6c 69 6e 65  | listing at line|
00003fa0  73 20 33 39 30 20 61 6e  64 20 34 33 30 20 74 68  |s 390 and 430 th|
00003fb0  65 20 42 42 43 0d 61 73  73 65 6d 62 6c 65 72 20  |e BBC.assembler |
00003fc0  61 6c 6c 6f 77 73 20 79  6f 75 20 74 6f 20 75 73  |allows you to us|
00003fd0  65 20 61 6e 20 61 64 64  69 74 69 6f 6e 20 74 6f  |e an addition to|
00003fe0  20 64 65 66 69 6e 65 20  74 68 65 20 62 69 74 73  | define the bits|
00003ff0  0d 62 65 69 6e 67 20 75  73 65 64 2e 20 20 59 6f  |.being used.  Yo|
00004000  75 20 63 6f 75 6c 64 20  65 76 65 6e 20 63 68 61  |u could even cha|
00004010  6e 67 65 20 6c 69 6e 65  20 34 33 30 20 74 6f 20  |nge line 430 to |
00004020  4f 52 41 0d 23 28 32 5e  34 2b 32 5e 36 29 20 69  |ORA.#(2^4+2^6) i|
00004030  66 20 74 68 61 74 20 6d  61 6b 65 73 20 69 74 20  |f that makes it |
00004040  63 6c 65 61 72 65 72 20  74 6f 20 79 6f 75 2e 20  |clearer to you. |
00004050  20 54 68 69 73 20 77 69  6c 6c 20 6d 61 6b 65 0d  | This will make.|
00004060  6e 6f 20 64 69 66 66 65  72 65 6e 63 65 20 74 6f  |no difference to|
00004070  20 74 68 65 20 66 69 6e  61 6c 20 63 6f 64 65 2c  | the final code,|
00004080  20 69 74 20 6a 75 73 74  20 6d 61 6b 65 73 20 74  | it just makes t|
00004090  68 65 20 73 6f 75 72 63  65 0d 63 6f 64 65 20 6d  |he source.code m|
000040a0  6f 72 65 20 72 65 61 64  61 62 6c 65 2e 0d 0d 41  |ore readable...A|
000040b0  73 20 77 65 20 61 72 65  20 67 6f 69 6e 67 20 74  |s we are going t|
000040c0  6f 20 75 73 65 20 74 68  65 20 75 73 65 72 20 70  |o use the user p|
000040d0  6f 72 74 20 61 73 20 61  6e 20 69 6e 70 75 74 20  |ort as an input |
000040e0  77 65 20 77 72 69 74 65  0d 7a 65 72 6f 20 69 6e  |we write.zero in|
000040f0  74 6f 20 74 68 65 20 64  61 74 61 20 64 69 72 65  |to the data dire|
00004100  63 74 69 6f 6e 20 72 65  67 69 73 74 65 72 20 77  |ction register w|
00004110  68 69 63 68 2c 20 61 73  20 69 74 20 63 6c 65 61  |hich, as it clea|
00004120  72 73 0d 61 6c 6c 20 74  68 65 20 62 69 74 73 2c  |rs.all the bits,|
00004130  20 6d 61 6b 65 73 20 61  6c 6c 20 74 68 65 20 6c  | makes all the l|
00004140  69 6e 65 73 20 66 75 6e  63 74 69 6f 6e 20 61 73  |ines function as|
00004150  20 69 6e 70 75 74 73 2e  20 20 54 68 65 0d 62 75  | inputs.  The.bu|
00004160  74 74 6f 6e 73 20 6f 66  20 74 68 65 20 6d 6f 75  |ttons of the mou|
00004170  73 65 20 77 69 6c 6c 20  62 65 20 72 65 61 64 20  |se will be read |
00004180  66 72 6f 6d 20 74 68 65  73 65 20 6c 69 6e 65 73  |from these lines|
00004190  20 69 66 20 79 6f 75 0d  77 61 6e 74 20 74 68 65  | if you.want the|
000041a0  6d 2c 20 73 6f 20 69 74  20 69 73 20 77 6f 72 74  |m, so it is wort|
000041b0  68 20 63 6c 65 61 72 69  6e 67 20 61 6c 6c 20 74  |h clearing all t|
000041c0  68 65 20 62 69 74 73 2e  0d 0d 59 6f 75 20 77 69  |he bits...You wi|
000041d0  6c 6c 20 6e 6f 74 69 63  65 20 74 68 61 74 20 49  |ll notice that I|
000041e0  20 64 69 73 61 62 6c 65  64 20 69 6e 74 65 72 72  | disabled interr|
000041f0  75 70 74 73 20 77 68 69  6c 65 20 6d 6f 64 69 66  |upts while modif|
00004200  79 69 6e 67 0d 74 68 65  20 56 49 41 20 72 65 67  |ying.the VIA reg|
00004210  69 73 74 65 72 73 2e 20  20 54 68 69 73 20 6d 61  |isters.  This ma|
00004220  6b 65 73 20 73 75 72 65  20 74 68 61 74 20 61 6e  |kes sure that an|
00004230  6f 74 68 65 72 20 72 6f  75 74 69 6e 65 0d 63 61  |other routine.ca|
00004240  6e 27 74 20 67 65 74 20  69 6e 20 61 6e 64 20 6d  |n't get in and m|
00004250  6f 64 69 66 79 20 74 68  65 20 72 65 67 69 73 74  |odify the regist|
00004260  65 72 73 20 77 68 69 6c  65 20 79 6f 75 20 61 72  |ers while you ar|
00004270  65 20 64 6f 69 6e 67 0d  69 74 2e 20 20 4f 66 20  |e doing.it.  Of |
00004280  63 6f 75 72 73 65 20 69  74 20 6d 61 79 20 77 65  |course it may we|
00004290  6c 6c 20 62 65 20 74 68  61 74 20 61 6e 6f 74 68  |ll be that anoth|
000042a0  65 72 20 72 6f 75 74 69  6e 65 20 74 68 61 74 0d  |er routine that.|
000042b0  75 73 65 73 20 74 68 69  73 20 66 75 6e 63 74 69  |uses this functi|
000042c0  6f 6e 20 6f 66 20 74 68  65 20 56 49 41 20 77 6f  |on of the VIA wo|
000042d0  75 6c 64 20 63 61 75 73  65 20 61 20 6d 61 6c 66  |uld cause a malf|
000042e0  75 6e 63 74 69 6f 6e 2c  20 62 75 74 0d 69 66 20  |unction, but.if |
000042f0  74 68 65 72 65 20 69 73  20 61 6e 79 20 63 68 61  |there is any cha|
00004300  6e 63 65 20 6f 66 20 74  68 65 20 74 77 6f 20 72  |nce of the two r|
00004310  6f 75 74 69 6e 65 73 20  63 6f 65 78 69 73 74 69  |outines coexisti|
00004320  6e 67 20 74 68 65 6e 0d  6c 65 74 27 73 20 74 61  |ng then.let's ta|
00004330  6b 65 20 69 74 2e 20 20  54 68 61 74 27 73 20 77  |ke it.  That's w|
00004340  68 79 20 74 68 69 73 20  72 6f 75 74 69 6e 65 20  |hy this routine |
00004350  61 76 6f 69 64 73 20 61  66 66 65 63 74 69 6e 67  |avoids affecting|
00004360  0d 6f 74 68 65 72 20 72  65 67 69 73 74 65 72 20  |.other register |
00004370  62 69 74 73 20 75 6e 6e  65 63 65 73 73 61 72 69  |bits unnecessari|
00004380  6c 79 2e 0d 0d 54 68 65  20 76 61 72 69 61 62 6c  |ly...The variabl|
00004390  65 73 20 61 70 70 65 61  72 20 6e 65 78 74 2e 20  |es appear next. |
000043a0  20 59 6f 75 20 63 61 6e  20 63 68 61 6e 67 65 20  | You can change |
000043b0  27 73 63 61 6c 65 27 20  69 66 20 79 6f 75 0d 77  |'scale' if you.w|
000043c0  61 6e 74 20 66 69 6e 65  72 20 6f 72 20 63 6f 61  |ant finer or coa|
000043d0  72 73 65 72 20 70 6f 69  6e 74 65 72 20 63 6f 6e  |rser pointer con|
000043e0  74 72 6f 6c 20 62 75 74  20 61 20 76 61 6c 75 65  |trol but a value|
000043f0  20 6f 66 20 32 20 69 73  20 61 0d 67 6f 6f 64 20  | of 2 is a.good |
00004400  70 6c 61 63 65 20 74 6f  20 73 74 61 72 74 2e 20  |place to start. |
00004410  20 54 68 65 20 58 20 61  6e 64 20 59 20 63 6f 6f  | The X and Y coo|
00004420  72 64 69 6e 61 74 65 73  20 6f 66 20 74 68 65 20  |rdinates of the |
00004430  70 6f 69 6e 74 65 72 0d  63 6f 6e 74 72 6f 6c 6c  |pointer.controll|
00004440  65 64 20 62 79 20 74 68  65 20 6d 6f 75 73 65 20  |ed by the mouse |
00004450  61 72 65 20 73 74 6f 72  65 64 20 6e 65 78 74 2e  |are stored next.|
00004460  20 20 49 20 68 61 76 65  20 61 6c 6c 6f 63 61 74  |  I have allocat|
00004470  65 64 0d 66 6f 75 72 20  62 79 74 65 73 20 66 6f  |ed.four bytes fo|
00004480  72 20 65 61 63 68 20 65  76 65 6e 20 74 68 6f 75  |r each even thou|
00004490  67 68 20 73 63 72 65 65  6e 20 63 6f 6f 72 64 69  |gh screen coordi|
000044a0  6e 61 74 65 73 20 6f 6e  6c 79 20 68 61 76 65 0d  |nates only have.|
000044b0  74 77 6f 20 62 79 74 65  73 2e 20 20 54 68 69 73  |two bytes.  This|
000044c0  20 69 73 20 74 6f 20 65  6e 61 62 6c 65 20 75 73  | is to enable us|
000044d0  20 74 6f 20 72 65 61 64  20 74 68 65 20 63 6f 6f  | to read the coo|
000044e0  72 64 69 6e 61 74 65 20  77 69 74 68 0d 74 68 65  |rdinate with.the|
000044f0  20 21 20 6f 70 65 72 61  74 6f 72 20 66 72 6f 6d  | ! operator from|
00004500  20 42 41 53 49 43 2e 20  20 4d 6f 72 65 20 6f 6e  | BASIC.  More on|
00004510  20 74 68 69 73 20 6c 61  74 65 72 2e 20 20 54 68  | this later.  Th|
00004520  65 20 66 69 6e 61 6c 0d  76 61 72 69 61 62 6c 65  |e final.variable|
00004530  20 73 70 61 63 65 20 68  6f 6c 64 73 20 74 68 65  | space holds the|
00004540  20 6f 6c 64 20 76 61 6c  75 65 20 6f 66 20 49 52  | old value of IR|
00004550  51 31 20 74 6f 20 61 6c  6c 6f 77 0d 63 68 61 69  |Q1 to allow.chai|
00004560  6e 69 6e 67 2e 0d 0d 57  68 65 6e 20 61 6e 79 20  |ning...When any |
00004570  69 6e 74 65 72 72 75 70  74 20 28 6f 74 68 65 72  |interrupt (other|
00004580  20 74 68 61 6e 20 61 6e  20 4e 4d 49 29 20 69 73  | than an NMI) is|
00004590  20 64 65 74 65 63 74 65  64 20 65 78 65 63 75 74  | detected execut|
000045a0  69 6f 6e 0d 6a 75 6d 70  73 20 64 6f 77 6e 20 74  |ion.jumps down t|
000045b0  68 65 20 49 52 51 31 20  76 65 63 74 6f 72 2e 20  |he IRQ1 vector. |
000045c0  20 54 68 65 20 66 69 72  73 74 20 74 68 69 6e 67  | The first thing|
000045d0  20 69 6e 20 74 68 61 74  20 76 65 63 74 6f 72 0d  | in that vector.|
000045e0  69 73 20 6f 75 72 20 63  6f 64 65 20 68 65 72 65  |is our code here|
000045f0  2e 20 20 54 68 65 20 73  74 61 6e 64 61 72 64 20  |.  The standard |
00004600  72 6f 75 74 69 6e 65 2c  20 74 6f 20 72 65 63 6c  |routine, to recl|
00004610  61 69 6d 20 74 68 65 0d  61 63 75 6d 75 6c 61 74  |aim the.acumulat|
00004620  6f 72 20 76 61 6c 75 65  20 66 72 6f 6d 20 26 46  |or value from &F|
00004630  43 20 61 6e 64 20 73 74  6f 72 65 20 74 68 65 20  |C and store the |
00004640  72 65 67 69 73 74 65 72  73 2c 20 69 73 0d 63 61  |registers, is.ca|
00004650  72 72 69 65 64 20 6f 75  74 20 69 6e 20 6c 69 6e  |rried out in lin|
00004660  65 73 20 36 31 30 20 74  6f 20 36 36 30 2e 20 20  |es 610 to 660.  |
00004670  49 6e 20 66 61 63 74 20  74 68 65 72 65 20 69 73  |In fact there is|
00004680  20 6e 6f 20 6e 65 65 64  0d 74 6f 20 73 61 76 65  | no need.to save|
00004690  20 74 68 65 20 58 20 61  6e 64 20 59 20 72 65 67  | the X and Y reg|
000046a0  69 73 74 65 72 73 20 62  65 63 61 75 73 65 20 74  |isters because t|
000046b0  68 69 73 20 70 72 6f 67  72 61 6d 20 64 6f 65 73  |his program does|
000046c0  20 6e 6f 74 0d 63 68 61  6e 67 65 20 74 68 65 6d  | not.change them|
000046d0  20 62 75 74 2c 20 62 65  6c 74 20 61 6e 64 20 62  | but, belt and b|
000046e0  72 61 63 65 73 2c 20 69  74 27 73 20 62 65 73 74  |races, it's best|
000046f0  20 74 6f 20 67 65 74 20  69 6e 74 6f 20 74 68 65  | to get into the|
00004700  0d 68 61 62 69 74 20 6f  66 20 73 61 76 69 6e 67  |.habit of saving|
00004710  20 61 6c 6c 20 72 65 67  69 73 74 65 72 73 2e 20  | all registers. |
00004720  20 53 69 6d 69 6c 61 72  6c 79 20 77 65 20 6d 61  | Similarly we ma|
00004730  6b 65 20 73 75 72 65 20  74 68 65 0d 70 72 6f 63  |ke sure the.proc|
00004740  65 73 73 6f 72 20 69 73  20 69 6e 20 62 69 6e 61  |essor is in bina|
00004750  72 79 20 72 61 74 68 65  72 20 74 68 61 6e 20 64  |ry rather than d|
00004760  65 63 69 6d 61 6c 20 6d  6f 64 65 2e 0d 0d 4e 65  |ecimal mode...Ne|
00004770  78 74 20 77 65 20 68 61  76 65 20 74 6f 20 6d 61  |xt we have to ma|
00004780  6b 65 20 73 75 72 65 20  74 68 61 74 20 74 68 65  |ke sure that the|
00004790  20 63 61 75 73 65 20 6f  66 20 74 68 65 20 69 6e  | cause of the in|
000047a0  74 65 72 72 75 70 74 20  69 73 0d 74 68 65 20 6f  |terrupt is.the o|
000047b0  6e 65 20 66 6f 72 20 6f  75 72 20 63 6f 64 65 2e  |ne for our code.|
000047c0  20 20 53 69 6e 63 65 20  69 6e 74 65 72 72 75 70  |  Since interrup|
000047d0  74 73 20 61 72 65 20 68  61 70 70 65 6e 69 6e 67  |ts are happening|
000047e0  0d 63 6f 6e 74 69 6e 75  6f 75 73 6c 79 20 69 6e  |.continuously in|
000047f0  20 74 68 65 20 42 42 43  20 4d 69 63 72 6f 20 77  | the BBC Micro w|
00004800  65 20 6d 75 73 74 20 62  65 20 73 75 72 65 20 77  |e must be sure w|
00004810  65 20 6f 6e 6c 79 0d 73  65 72 76 69 63 65 20 74  |e only.service t|
00004820  68 65 20 72 69 67 68 74  20 6f 6e 65 73 2e 20 20  |he right ones.  |
00004830  49 66 20 74 68 65 20 75  73 65 72 20 56 49 41 20  |If the user VIA |
00004840  63 61 75 73 65 64 20 61  6e 20 69 6e 74 65 72 72  |caused an interr|
00004850  75 70 74 0d 74 68 61 6e  20 62 69 74 20 37 20 6f  |upt.than bit 7 o|
00004860  66 20 69 74 73 20 69 6e  74 65 72 72 75 70 74 20  |f its interrupt |
00004870  66 6c 61 67 20 72 65 67  69 73 74 65 72 20 28 49  |flag register (I|
00004880  46 52 29 20 77 69 6c 6c  20 62 65 20 73 65 74 2e  |FR) will be set.|
00004890  20 0d 4c 69 6e 65 73 20  37 33 30 20 61 6e 64 20  | .Lines 730 and |
000048a0  37 34 30 20 63 68 65 63  6b 20 74 68 69 73 2e 0d  |740 check this..|
000048b0  0d 49 66 20 74 68 65 20  75 73 65 72 20 56 49 41  |.If the user VIA|
000048c0  20 64 69 64 20 69 6e 64  65 65 64 20 63 61 75 73  | did indeed caus|
000048d0  65 20 74 68 65 20 69 6e  74 65 72 72 75 70 74 20  |e the interrupt |
000048e0  77 65 20 6d 75 73 74 20  63 68 65 63 6b 0d 74 6f  |we must check.to|
000048f0  20 73 65 65 20 74 68 61  74 20 69 74 20 77 61 73  | see that it was|
00004900  20 43 42 31 20 6f 72 20  43 42 32 2c 20 6f 75 72  | CB1 or CB2, our|
00004910  20 74 77 6f 20 69 6e 74  65 72 72 75 70 74 20 6c  | two interrupt l|
00004920  69 6e 65 73 2c 20 74 68  61 74 0d 77 65 72 65 20  |ines, that.were |
00004930  72 65 73 70 6f 6e 73 69  62 6c 65 2e 20 20 49 66  |responsible.  If|
00004940  20 69 74 20 77 61 73 20  43 42 32 20 28 63 61 75  | it was CB2 (cau|
00004950  73 65 64 20 62 79 20 74  68 65 20 59 31 20 6c 69  |sed by the Y1 li|
00004960  6e 65 29 0d 74 68 65 6e  20 62 69 74 20 33 20 6f  |ne).then bit 3 o|
00004970  66 20 74 68 65 20 49 46  52 20 77 69 6c 6c 20 62  |f the IFR will b|
00004980  65 20 73 65 74 2c 20 69  66 20 69 74 20 77 61 73  |e set, if it was|
00004990  20 43 42 31 20 28 63 61  75 73 65 64 20 62 79 0d  | CB1 (caused by.|
000049a0  74 68 65 20 58 31 20 6c  69 6e 65 29 20 74 68 65  |the X1 line) the|
000049b0  6e 20 62 69 74 20 34 20  6f 66 20 74 68 65 20 49  |n bit 4 of the I|
000049c0  46 52 20 77 69 6c 6c 20  62 65 20 73 65 74 2e 20  |FR will be set. |
000049d0  20 4c 69 6e 65 73 20 37  36 30 0d 74 6f 20 38 32  | Lines 760.to 82|
000049e0  30 20 63 68 65 63 6b 20  66 6f 72 20 74 68 69 73  |0 check for this|
000049f0  20 61 6e 64 20 72 6f 75  74 65 20 65 78 65 63 75  | and route execu|
00004a00  74 69 6f 6e 20 61 63 63  6f 72 64 69 6e 67 6c 79  |tion accordingly|
00004a10  20 75 73 69 6e 67 0d 74  68 65 20 42 49 54 20 6f  | using.the BIT o|
00004a20  70 63 6f 64 65 2e 20 20  54 68 69 73 20 70 65 72  |pcode.  This per|
00004a30  66 6f 72 6d 73 20 61 6e  20 41 4e 44 20 62 75 74  |forms an AND but|
00004a40  20 64 6f 65 73 20 6e 6f  74 20 73 74 6f 72 65 20  | does not store |
00004a50  74 68 65 0d 72 65 73 75  6c 74 3b 20 69 6e 64 65  |the.result; inde|
00004a60  65 64 20 61 6e 20 41 4e  44 20 77 6f 75 6c 64 20  |ed an AND would |
00004a70  77 6f 72 6b 20 65 71 75  61 6c 6c 79 20 77 65 6c  |work equally wel|
00004a80  6c 20 68 65 72 65 2e 20  20 49 66 20 61 74 0d 74  |l here.  If at.t|
00004a90  68 65 20 65 6e 64 20 6f  66 20 74 68 69 73 20 77  |he end of this w|
00004aa0  65 20 6b 6e 6f 77 20 74  68 61 74 20 74 68 65 20  |e know that the |
00004ab0  69 6e 74 65 72 72 75 70  74 20 77 61 73 20 6e 6f  |interrupt was no|
00004ac0  74 20 63 61 75 73 65 64  20 62 79 0d 43 42 31 20  |t caused by.CB1 |
00004ad0  6f 72 20 43 42 32 20 74  68 65 6e 20 77 65 20 6d  |or CB2 then we m|
00004ae0  75 73 74 20 63 68 61 69  6e 20 6f 6e 20 64 6f 77  |ust chain on dow|
00004af0  6e 20 49 52 51 31 20 73  6f 20 73 6f 6d 65 6f 6e  |n IRQ1 so someon|
00004b00  65 20 65 6c 73 65 0d 63  61 6e 20 73 65 72 76 69  |e else.can servi|
00004b10  63 65 20 74 68 65 20 69  6e 74 65 72 72 75 70 74  |ce the interrupt|
00004b20  2e 0d 0d 59 6f 75 20 6d  75 73 74 20 63 6c 65 61  |...You must clea|
00004b30  72 20 61 6e 20 69 6e 74  65 72 72 75 70 74 20 77  |r an interrupt w|
00004b40  68 65 6e 20 79 6f 75 20  73 65 72 76 69 63 65 20  |hen you service |
00004b50  69 74 2c 20 6f 74 68 65  72 77 69 73 65 0d 74 68  |it, otherwise.th|
00004b60  65 20 36 35 30 32 20 77  69 6c 6c 20 73 74 69 6c  |e 6502 will stil|
00004b70  6c 20 73 69 67 6e 61 6c  20 69 74 2e 20 20 49 6e  |l signal it.  In|
00004b80  20 74 68 69 73 20 63 61  73 65 20 77 69 74 68 20  | this case with |
00004b90  69 6e 74 65 72 72 75 70  74 73 0d 66 72 6f 6d 20  |interrupts.from |
00004ba0  43 42 31 20 61 6e 64 20  43 42 32 20 79 6f 75 20  |CB1 and CB2 you |
00004bb0  64 6f 20 6e 6f 74 20 68  61 76 65 20 74 6f 20 63  |do not have to c|
00004bc0  6c 65 61 72 20 65 78 70  6c 69 63 69 74 6c 79 2e  |lear explicitly.|
00004bd0  20 0d 52 65 61 64 69 6e  67 20 66 72 6f 6d 20 74  | .Reading from t|
00004be0  68 65 20 64 61 74 61 20  6c 69 6e 65 73 20 6f 6e  |he data lines on|
00004bf0  20 74 68 65 20 75 73 65  72 20 70 6f 72 74 20 77  | the user port w|
00004c00  69 6c 6c 20 64 6f 20 74  68 65 20 6a 6f 62 0d 61  |ill do the job.a|
00004c10  75 74 6f 6d 61 74 69 63  61 6c 6c 79 2e 0d 0d 54  |utomatically...T|
00004c20  68 65 20 63 6f 64 65 20  6f 70 65 72 61 74 65 73  |he code operates|
00004c30  20 69 6e 20 61 20 73 69  6d 69 6c 61 72 20 77 61  | in a similar wa|
00004c40  79 20 77 68 65 74 68 65  72 20 61 6e 20 58 20 6f  |y whether an X o|
00004c50  72 20 59 20 70 75 6c 73  65 0d 63 61 75 73 65 64  |r Y pulse.caused|
00004c60  20 74 68 65 20 69 6e 74  65 72 72 75 70 74 2e 20  | the interrupt. |
00004c70  54 68 65 20 72 65 6c 65  76 61 6e 74 20 73 65 63  |The relevant sec|
00004c80  6f 6e 64 20 6c 69 6e 65  20 69 73 20 74 65 73 74  |ond line is test|
00004c90  65 64 20 74 6f 0d 73 65  65 20 69 66 20 69 74 20  |ed to.see if it |
00004ca0  69 73 20 68 69 67 68 20  6f 72 20 6c 6f 77 20 61  |is high or low a|
00004cb0  74 20 74 68 65 20 6d 6f  6d 65 6e 74 20 6f 66 20  |t the moment of |
00004cc0  74 68 65 20 69 6e 74 65  72 72 75 70 74 2e 20 0d  |the interrupt. .|
00004cd0  5b 4e 6f 74 65 20 74 68  61 74 20 69 66 20 79 6f  |[Note that if yo|
00004ce0  75 20 75 73 65 20 49 52  51 32 20 74 68 65 20 64  |u use IRQ2 the d|
00004cf0  65 6c 61 79 20 62 65 66  6f 72 65 20 73 65 72 76  |elay before serv|
00004d00  69 63 69 6e 67 20 74 68  65 0d 69 6e 74 65 72 72  |icing the.interr|
00004d10  75 70 74 20 69 73 20 73  75 66 66 69 63 69 65 6e  |upt is sufficien|
00004d20  74 20 74 6f 20 63 61 75  73 65 20 66 61 6c 73 65  |t to cause false|
00004d30  20 72 65 61 64 69 6e 67  73 20 61 74 20 74 68 69  | readings at thi|
00004d40  73 0d 70 6f 69 6e 74 20  61 6e 64 20 74 68 65 20  |s.point and the |
00004d50  70 6f 69 6e 74 65 72 20  63 61 6e 20 67 6f 20 74  |pointer can go t|
00004d60  68 65 20 77 72 6f 6e 67  20 77 61 79 2e 20 20 55  |he wrong way.  U|
00004d70  73 69 6e 67 20 49 52 51  31 0d 61 76 6f 69 64 73  |sing IRQ1.avoids|
00004d80  20 74 68 69 73 20 70 72  6f 62 6c 65 6d 2e 5d 20  | this problem.] |
00004d90  20 49 66 20 77 65 20 6d  6f 76 65 20 70 6f 73 69  | If we move posi|
00004da0  74 69 76 65 6c 79 20 74  68 65 6e 20 74 68 65 0d  |tively then the.|
00004db0  72 65 6c 65 76 61 6e 74  20 63 6f 6f 72 64 69 6e  |relevant coordin|
00004dc0  61 74 65 20 6c 6f 63 61  74 69 6f 6e 20 69 73 20  |ate location is |
00004dd0  69 6e 63 72 65 61 73 65  64 20 62 79 20 27 73 63  |increased by 'sc|
00004de0  61 6c 65 27 20 61 6e 64  0d 64 65 63 72 65 61 73  |ale' and.decreas|
00004df0  65 64 20 6f 66 20 77 65  20 6d 6f 76 65 20 6e 65  |ed of we move ne|
00004e00  67 61 74 69 76 65 6c 79  2e 20 20 41 66 74 65 72  |gatively.  After|
00004e10  20 74 68 69 73 20 68 61  73 20 62 65 65 6e 20 64  | this has been d|
00004e20  6f 6e 65 0d 74 68 65 20  72 6f 75 74 69 6e 65 20  |one.the routine |
00004e30  65 78 69 74 73 20 62 79  20 72 65 73 74 6f 72 69  |exits by restori|
00004e40  6e 67 20 74 68 65 20 72  65 67 69 73 74 65 72 73  |ng the registers|
00004e50  20 61 6e 64 20 74 68 65  6e 0d 70 65 72 66 6f 72  | and then.perfor|
00004e60  6d 69 6e 67 20 61 6e 20  52 54 49 2e 0d 0d 54 68  |ming an RTI...Th|
00004e70  65 20 42 41 53 49 43 20  73 68 65 6c 6c 20 61 72  |e BASIC shell ar|
00004e80  6f 75 6e 64 20 74 68 69  73 20 70 72 6f 67 72 61  |ound this progra|
00004e90  6d 20 70 72 69 6e 74 73  20 61 20 70 6f 69 6e 74  |m prints a point|
00004ea0  65 72 20 28 61 0d 63 72  6f 73 73 29 20 69 6e 20  |er (a.cross) in |
00004eb0  74 68 65 20 63 65 6e 74  72 65 20 6f 66 20 74 68  |the centre of th|
00004ec0  65 20 73 63 72 65 65 6e  20 61 6e 64 20 73 6d 65  |e screen and sme|
00004ed0  61 72 73 20 69 74 20 61  72 6f 75 6e 64 20 61 73  |ars it around as|
00004ee0  0d 79 6f 75 20 6d 6f 76  65 20 74 68 65 20 6d 6f  |.you move the mo|
00004ef0  75 73 65 2e 20 20 54 68  65 20 58 20 61 6e 64 20  |use.  The X and |
00004f00  59 20 63 6f 6f 72 64 69  6e 61 74 65 73 20 61 72  |Y coordinates ar|
00004f10  65 20 72 65 61 64 20 75  73 69 6e 67 0d 74 68 65  |e read using.the|
00004f20  20 21 20 6f 70 65 72 61  74 6f 72 20 74 6f 20 6d  | ! operator to m|
00004f30  69 6e 69 6d 69 73 65 20  65 72 72 6f 72 73 20 64  |inimise errors d|
00004f40  75 65 20 74 6f 20 74 68  65 20 63 6f 6f 72 64 69  |ue to the coordi|
00004f50  6e 61 74 65 73 0d 63 68  61 6e 67 69 6e 67 20 77  |nates.changing w|
00004f60  68 69 6c 65 20 74 68 65  79 20 61 72 65 20 62 65  |hile they are be|
00004f70  69 6e 67 20 72 65 61 64  2e 20 20 49 66 20 79 6f  |ing read.  If yo|
00004f80  75 20 77 65 72 65 20 74  6f 20 72 65 61 64 20 74  |u were to read t|
00004f90  68 65 0d 74 77 6f 20 62  79 74 65 73 20 6f 66 20  |he.two bytes of |
00004fa0  74 68 65 20 63 6f 6f 72  64 69 6e 61 74 65 73 20  |the coordinates |
00004fb0  73 65 70 61 72 61 74 65  6c 79 20 75 73 69 6e 67  |separately using|
00004fc0  20 3f 20 6f 70 65 72 61  74 6f 72 73 0d 79 6f 75  | ? operators.you|
00004fd0  20 77 6f 75 6c 64 20 67  65 74 20 73 6f 6d 65 20  | would get some |
00004fe0  69 6e 63 6f 72 72 65 63  74 20 72 65 73 75 6c 74  |incorrect result|
00004ff0  73 2c 20 74 72 79 20 69  74 20 61 6e 64 20 73 65  |s, try it and se|
00005000  65 2e 0d 0d 54 68 69 73  20 63 6f 64 65 20 77 69  |e...This code wi|
00005010  6c 6c 20 77 6f 72 6b 20  77 69 74 68 20 61 20 4d  |ll work with a M|
00005020  61 72 63 6f 6e 69 20 54  72 61 63 6b 65 72 62 61  |arconi Trackerba|
00005030  6c 6c 2c 20 61 6c 74 68  6f 75 67 68 20 74 68 65  |ll, although the|
00005040  0d 70 69 6e 20 63 6f 6e  6e 65 63 74 69 6f 6e 73  |.pin connections|
00005050  20 61 72 65 20 64 69 66  66 65 72 65 6e 74 20 74  | are different t|
00005060  6f 20 74 68 65 20 41 4d  58 20 6d 6f 75 73 65 2e  |o the AMX mouse.|
00005070  20 20 54 68 65 20 64 61  74 61 0d 73 68 65 65 74  |  The data.sheet|
00005080  20 77 69 74 68 20 74 68  65 20 74 72 61 63 6b 65  | with the tracke|
00005090  72 62 61 6c 6c 20 77 69  6c 6c 20 61 64 76 69 73  |rball will advis|
000050a0  65 20 79 6f 75 20 6f 6e  20 77 68 69 63 68 20 70  |e you on which p|
000050b0  69 6e 73 20 61 72 65 0d  77 68 69 63 68 2e 20 20  |ins are.which.  |
000050c0  43 42 31 20 61 6e 64 20  43 42 32 20 61 72 65 20  |CB1 and CB2 are |
000050d0  75 73 65 64 20 62 75 74  20 74 68 65 20 73 65 63  |used but the sec|
000050e0  6f 6e 64 20 6c 69 6e 65  73 20 61 72 65 0d 64 69  |ond lines are.di|
000050f0  66 66 65 72 65 6e 74 20  74 6f 20 74 68 6f 73 65  |fferent to those|
00005100  20 75 73 65 64 20 69 6e  20 74 68 69 73 20 70 72  | used in this pr|
00005110  6f 67 72 61 6d 2e 20 20  4c 69 6e 65 73 20 39 36  |ogram.  Lines 96|
00005120  30 20 61 6e 64 20 31 32  34 30 0d 77 6f 75 6c 64  |0 and 1240.would|
00005130  20 6e 65 65 64 20 74 6f  20 62 65 20 63 68 61 6e  | need to be chan|
00005140  67 65 64 20 74 6f 20 6c  6f 61 64 20 31 36 20 61  |ged to load 16 a|
00005150  6e 64 20 38 20 72 65 73  70 65 63 74 69 76 65 6c  |nd 8 respectivel|
00005160  79 0d 62 65 63 61 75 73  65 20 62 69 74 73 20 34  |y.because bits 4|
00005170  20 61 6e 64 20 33 20 63  61 72 72 79 20 59 32 20  | and 3 carry Y2 |
00005180  61 6e 64 20 58 32 2e 0d  0d 4f 66 20 63 6f 75 72  |and X2...Of cour|
00005190  73 65 20 74 68 69 73 20  63 6f 64 65 20 64 6f 65  |se this code doe|
000051a0  73 20 6e 6f 74 20 69 6d  70 6c 65 6d 65 6e 74 20  |s not implement |
000051b0  61 20 70 72 6f 70 65 72  20 6d 6f 75 73 65 0d 70  |a proper mouse.p|
000051c0  6f 69 6e 74 65 72 20 69  6e 20 74 68 65 20 77 61  |ointer in the wa|
000051d0  79 20 41 63 6f 72 6e 27  73 20 56 46 53 20 6f 72  |y Acorn's VFS or|
000051e0  20 41 4d 58 27 73 20 53  75 70 65 72 2d 41 72 74  | AMX's Super-Art|
000051f0  20 52 4f 4d 20 64 6f 65  73 2c 0d 62 75 74 20 69  | ROM does,.but i|
00005200  74 20 73 68 6f 75 6c 64  20 67 69 76 65 20 79 6f  |t should give yo|
00005210  75 20 61 20 62 61 73 69  63 20 69 64 65 61 20 6f  |u a basic idea o|
00005220  66 20 68 6f 77 20 61 6e  20 69 6e 74 65 72 72 75  |f how an interru|
00005230  70 74 20 69 73 0d 68 61  6e 64 6c 65 64 2e 0d 0d  |pt is.handled...|
00005240  59 6f 75 20 73 68 6f 75  6c 64 20 61 6c 73 6f 20  |You should also |
00005250  6e 6f 74 69 63 65 20 74  68 61 74 20 49 20 68 61  |notice that I ha|
00005260  76 65 20 70 75 74 20 74  68 65 20 63 6f 64 65 20  |ve put the code |
00005270  69 6e 20 74 68 65 0d 63  61 73 73 65 74 74 65 2f  |in the.cassette/|
00005280  52 53 34 32 33 20 69 6e  70 75 74 20 62 75 66 66  |RS423 input buff|
00005290  65 72 2e 20 20 49 66 20  79 6f 75 20 75 73 65 20  |er.  If you use |
000052a0  61 20 63 61 73 73 65 74  74 65 20 28 69 66 20 79  |a cassette (if y|
000052b0  6f 75 0d 64 6f 20 79 6f  75 20 73 68 6f 75 6c 64  |ou.do you should|
000052c0  20 62 65 20 73 61 76 69  6e 67 20 66 6f 72 20 61  | be saving for a|
000052d0  20 64 69 73 63 20 64 72  69 76 65 29 20 6f 72 20  | disc drive) or |
000052e0  68 61 76 65 20 61 20 6d  6f 64 65 6d 20 6f 72 0d  |have a modem or.|
000052f0  73 6f 6d 65 74 68 69 6e  67 20 74 68 61 74 20 75  |something that u|
00005300  73 65 73 20 52 53 34 32  33 20 69 6e 70 75 74 73  |ses RS423 inputs|
00005310  20 74 68 65 6e 20 72 75  6e 6e 69 6e 67 20 74 68  | then running th|
00005320  69 73 20 63 6f 64 65 20  77 69 6c 6c 0d 63 72 61  |is code will.cra|
00005330  73 68 20 79 6f 75 72 20  63 6f 6d 70 75 74 65 72  |sh your computer|
00005340  2e 20 20 50 65 72 68 61  70 73 20 74 68 65 20 73  |.  Perhaps the s|
00005350  61 66 65 73 74 20 74 68  69 6e 67 20 74 6f 20 64  |afest thing to d|
00005360  6f 20 77 6f 75 6c 64 0d  62 65 20 74 6f 20 72 61  |o would.be to ra|
00005370  69 73 65 20 50 41 47 45  20 62 79 20 26 31 30 30  |ise PAGE by &100|
00005380  20 28 32 35 36 29 20 62  79 74 65 73 20 61 6e 64  | (256) bytes and|
00005390  20 70 75 74 20 74 68 65  20 63 6f 64 65 20 69 6e  | put the code in|
000053a0  0d 74 68 65 72 65 3a 20  62 75 74 20 6f 6e 20 6d  |.there: but on m|
000053b0  6f 73 74 20 42 73 20 61  6e 64 20 42 2b 73 20 50  |ost Bs and B+s P|
000053c0  41 47 45 20 69 73 20 74  6f 6f 20 68 69 67 68 20  |AGE is too high |
000053d0  61 6e 79 77 61 79 2e 20  20 49 0d 6c 65 61 76 65  |anyway.  I.leave|
000053e0  20 69 74 20 75 70 20 74  6f 20 79 6f 75 2e 0d 0d  | it up to you...|
000053f0  52 65 6d 65 6d 62 65 72  20 74 68 61 74 20 74 68  |Remember that th|
00005400  65 20 76 65 63 74 6f 72  73 20 61 72 65 20 72 65  |e vectors are re|
00005410  2d 73 65 74 20 6f 6e 20  70 72 65 73 73 69 6e 67  |-set on pressing|
00005420  20 42 52 45 41 4b 2e 20  0d 41 6c 73 6f 20 79 6f  | BREAK. .Also yo|
00005430  75 20 77 69 6c 6c 20 6e  6f 74 69 63 65 20 74 68  |u will notice th|
00005440  61 74 20 74 68 69 73 20  74 69 6d 65 20 49 20 68  |at this time I h|
00005450  61 76 65 6e 27 74 20 61  6c 6c 6f 77 65 64 20 66  |aven't allowed f|
00005460  6f 72 0d 74 68 65 20 63  6f 64 65 20 74 6f 20 62  |or.the code to b|
00005470  65 20 63 61 6c 6c 65 64  20 74 77 69 63 65 20 77  |e called twice w|
00005480  69 74 68 6f 75 74 20 61  20 42 52 45 41 4b 2e 20  |ithout a BREAK. |
00005490  20 44 6f 69 6e 67 20 74  68 69 73 0d 77 69 6c 6c  | Doing this.will|
000054a0  20 6c 6f 63 6b 20 75 70  20 74 68 65 20 63 6f 6d  | lock up the com|
000054b0  70 75 74 65 72 2e 0d 0d  4e 65 78 74 20 74 69 6d  |puter...Next tim|
000054c0  65 20 77 65 20 77 69 6c  6c 20 73 65 74 20 75 70  |e we will set up|
000054d0  20 61 20 56 49 41 20 74  69 6d 65 72 20 74 6f 20  | a VIA timer to |
000054e0  70 61 6c 65 74 74 65 20  73 77 69 74 63 68 20 6f  |palette switch o|
000054f0  6e 0d 74 68 65 20 73 63  72 65 65 6e 20 74 6f 20  |n.the screen to |
00005500  67 65 74 20 73 65 76 65  72 61 6c 20 63 6f 6c 6f  |get several colo|
00005510  75 72 73 20 69 6e 20 6d  6f 64 65 20 33 2c 20 69  |urs in mode 3, i|
00005520  6e 20 61 20 6c 69 6d 69  74 65 64 0d 77 61 79 2e  |n a limited.way.|
00005530  0d                                                |.|
00005531
20-03-88/T\OSB18.m0
20-03-88/T\OSB18.m1
20-03-88/T\OSB18.m2
20-03-88/T\OSB18.m4
20-03-88/T\OSB18.m5