Home » CEEFAX disks » telesoftware11.adl » 27-11-88/T\MOU01

27-11-88/T\MOU01

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 » telesoftware11.adl
Filename: 27-11-88/T\MOU01
Read OK:
File size: 2C1B bytes
Load address: 0000
Exec address: 0000
File contents
Using a mouse with the BBC microcomputer - by - Gordon Horsington
-----------------------------------------------------------------

Module 1. Reading the mouse coordinates 
---------------------------------------

The X and Y coordinates assigned to the position of a mouse can be quite
arbitrary. The range of coordinates you choose to make available and the
rate at which they change with mouse movement is entirely under software
control. If, for example, you want to use a mouse to draw on a graphics
screen it would be a good idea to use a range of coordinates from 0 to
1279 for X and 0 to 1023 for Y, with increments of 4 for each interrupt
generated by the mouse.

The movement of the mouse ball can generate an interrupt using either CB1
or CB2. An interrupt generated by CB1 indicates a movement either left or
right and an interrupt generated by CB2 indicates a movement either up or
down. The plane of the change (either X or Y) is indicated by the
handshake lines but the direction (either increasing or decreasing) is
indicated by two bits in data register B (DRB, &FE60). If an interrupt is
generated by CB1 then your program should examine bit 0 of DRB. If bit 0
of DRB is set X is decreasing, if it is clear X is increasing. Similarly
if an interrupt is generated by CB2 then your program should examine bit 2
of DRB. If bit 2 of DRB is set Y is decreasing, if it is clear Y is
increasing.

It is possible to latch the data in DRB so that the values read from the
register are those that were present when a change of signal occured on
CB1. This means that, if latching is selected, the data for movement in
the X direction will remain available until a new movement is detected.
This would be very useful if it was also available for movement in the Y
direction, but latching is not available for signals on CB2. It is only
worth selecting the latching mode (by setting bit 1 of the ACR at &FE6B)
if you are only interested in movement from side to side. In practice this
could be useful with games software.

Because latching is unavailable for movements in the Y plane the mouse
generated interrupts have to be intercepted at the high priority IRQ1V
interrupt vector to ensure that bits 0 and 2 of DRB reflect the true
change of direction in the X and Y coordinates. If the interrupts are
intercepted at the low priority IRQ2V interrupt vector then the
non-latched DRB may or may not reflect the direction of the mouse
movement. In the demonstration programs which revector an interrupt
vector, IRQ1V is used and VIA-B is in the non-latched mode.

The program MOUSE illustrates how the IRQ1V vector is revectored to point
to the new code labeled interrupt. Data register B is selected as an input
by storing zero in data direction register B. CB1 and CB2 interrupts are
enabled by storing &98 (%10011000) in the interrupt enable register, both
CB1 and CB2 produce an interrupt on a positive transition, and the
interrupt is cleared by selecting (reading from) the data register B. In
this example the initial coordinates assigned to the current mouse
position are 0,0. The initial coordinates could be anything you like
within the range from 0 to 255.

All the example programs in this series use a range of from 0 to 255 for
both the X and Y coordinates. This simplifies the demonstration programs
because only one byte is used to store each coordinate. The X and Y
coordinates can then be read with the BASIC ? indirection operator. If you
decide to modify any of the demonstration programs to use a larger range
of coordinates it is a good idea to use four bytes for each coordinate
even if you only intend to use two of the four bytes to store the actual
number. Using four bytes will allow BASIC to read the coordinate with the
! indirection operator. If only two bytes are used then the ? indirection
operator will need to be used twice for each coordinate. You might also
like to consider storing the coordinates in the memory allocated to the
system integer variables (A% to Z%) and this will simplify reading the
coordinates even further.

The interrupt handling routine in MOUSE does not use either the X or Y
registers and so only the accumulator (from &FC) is stored on the stack at
the beginning of the routine and restored at the end. The interrupt
handling routine first examines bit 7 of the interrupt flag register. Bit
7 will always be set for a User Port interrupt. If a mouse connected to
the User Port is the source of an interrupt then either bit 3 or bit 4 of
the IFR will also be set. Bit 3 will be set for an interrupt generated by
CB2 and bit 4 will be set for an interrupt generated by CB1. If either bit
4 or bit 3 of the IFR is set then the direction of the movement is found
by examining either bit 0 or bit 2 of the DRB. If the direction is
increasing the the appropriate coordinate is incremented by 1 and if it is
decreasing then the appropriate coordinate is decremented by 1.

This demonstration program must run in the I/O processor and it uses the
most simple form of polling the mouse buttons from BASIC. The mouse
coordinates are peeked from the zero page memory locations and displayed
in an endless loop. Chain the program and move the mouse around to see the
range and sensitivity of the movement. To stop the program press either
the Escape key or the Break key. In module 2 I will show how the program
MOUSE can be modified to make it Tube compatible.


   10 REM> MOUSE
   20 DIM mcode &200 :REM: machine code at mcode
   30 xcoord=&80 :REM: x coordinate, range 0-255
   40 ycoord=&81 :REM: y coordinate, range 0-255
   50 savereg=&FC :REM: interrupt accumulator save register
   60 irq1v=&204 :REM: primary interrupt vector
   70 drb=&FE60 :REM: data register B
   80 ddrb=&FE62 :REM: data direction register B
   90 pcr=&FE6C :REM: peripheral control register
  100 ifr=&FE6D :REM: interrupt flag register
  110 ier=&FE6E :REM: interrupt enable register
  120 FOR pass=0 TO 2 STEP 2
  130 P%=mcode
  140 [       OPT pass
  150         LDX irq1v     \ current primary interrupt vector, low byte
  160         LDY irq1v+1   \ current primary interrupt vector, high byte
  170         CPY #interrupt DIV 256 \ compare high byte
  180         BEQ disable   \ restore old vector if altered
  190         STX oldirq1v  \ save original irq1 vector, low byte
  200         STY oldirq1v+1 \ save original irq1 vector, high byte
  210         LDX #interrupt MOD 256 \ new irq1 vector, low byte
  220         LDY #interrupt DIV 256 \ new irq1 vector, high byte
  230         SEI           \ set interrupt disable flag
  240         STX irq1v     \ alter irq1 vector, low byte
  250         STY irq1v+1   \ alter irq1 vector, high byte
  260         CLI           \ clear interrupt disable flag
  270         LDA #&98      \ %10011000, ie. enable CB1/2
  280         STA ier       \ interrupt enable register
  290         LDA pcr       \ peripheral control register
  300         AND #&0F      \ AND with %00001111, ie clear bits 4-7
  310         ORA #&50      \ OR with %01010000, ie. set bits 4 and 6
  320         STA pcr       \ interrupt on +ve transition, CB2 input,
                            \ DRB to clear
  330         LDA #&00      \ user port input
  340         STA ddrb      \ data direction register B
  350         STA xcoord    \ initial value for x coordinate
  360         STA ycoord    \ initial value for y coordinate
  370         RTS           \ return to BASIC
  380 .disable
  390         LDA #&18      \ %00011000, ready to clear bits 3 and 4 of ier
  400         LDX oldirq1v  \ original irq1 vector, low byte
  410         LDY oldirq1v+1 \ original irq1 vector, high byte
  420         SEI           \ set interrupt disable flag
  430         STA ier       \ interrupt enable register
  440         LDA pcr       \ peripheral control register
  450         AND #&0F      \ clear bits 4-7
  460         STA pcr       \ peripheral control register
  470         STX irq1v     \ restore the original irq1 vector, low byte
  480         STY irq1v+1   \ restore the original irq1 vector, high byte
  490         CLI           \ clear interrupt disable flag
  500         RTS           \ return to BASIC
  510 .interrupt
  520         LDA savereg   \ interrupt accumulator save register
  530         PHA           \ and push it on the stack
  540         LDA ifr       \ interrupt flag register
  550         BPL notuser   \ bit 7 is set if VIA-B interrupt
  560         AND #&18      \ AND with %00011000, ie. test bits 3 and 4
  570         BEQ notuser   \ exit if not CB1 or CB2
  580         AND #&10      \ AND with %00010000, ie. test CB1
  590         BNE xpulse    \ bit 4 set for an X direction movement
  600         LDA drb       \ Y direction, load data register B
  610         AND #&04      \ AND with %00000100, ie. test bit 2
  620         BNE ydown     \ if bit 2 is set then Y is going down
  630         INC ycoord    \ Y is going up so increment Y coordinate
  640         BNE exit      \ branch if in the range 1 to 255
  650         BEQ decy      \ if zero then alter to 255
  660 .ydown
  670         LDA ycoord    \ load Y coordinate
  680         BEQ exit      \ branch if zero because it can't go any lower
  690 .decy
  700         DEC ycoord    \ reduce Y coordinate by 1
  710         JMP exit      \ restore interrupt accumulator save
                            \ register and RTI
  720 .xpulse
  730         LDA drb       \ data register B
  740         ROR A         \ bit 0 into carry
  750         BCS xdown     \ X is going down if bit 0 is set
  760         INC xcoord    \ X is going up if bit 0 is clear
  770         BNE exit      \ exit if X coordinate is in the range
                            \ from 1 to 255
  780         BEQ decx      \ if X coordinate = 0 then make it 255
  790 .xdown
  800         LDA xcoord    \ load X coordinate
  810         BEQ exit      \ if it is zero it can't go any lower
  820 .decx
  830         DEC xcoord    \ decrease X coordinate by 1
  840 .exit
  850         PLA           \ pull interrupt accumulator save
                            \ register off the stack
  860         STA savereg   \ and restore zero page
  870         RTI           \ return from interrupt
  880 .notuser
  890         PLA           \ pull the interrupt accumulator save
                            \ register off the stack
  900         STA savereg   \ restore the zero page address
  910         JMP (oldirq1v) \ exit via the original vector
  920 .oldirq1v
  930         EQUW &00      \ original irq1v
  940 .lastbyte
  950 ]
  960 NEXT
  970 CALL mcode
  980 MODE7
  990 mouse$=CHR$141+CHR$132+CHR$157+CHR$131+
      "Mouse coordinates, range &00-&FF  "+CHR$156
 1000 PRINTTAB(0,1)mouse$
 1010 PRINTTAB(0,2)mouse$
 1020 VDU23,1,0;0;0;0;
 1030 ONERROR GOTO 1120
 1040 PRINTTAB(10,7)"Bytes used = &";~lastbyte-mcode
 1050 REPEAT
 1060 PRINTTAB(10,12)"X = &";~?&80;" "TAB(20,12);"Y = &";~?&81;" "
 1070 button=?drb :REM: data register B
 1080 IF (button AND &80)=0 PRINTTAB(22,17)"Right"
      ELSE PRINTTAB(22,17)"     "
 1090 IF (button AND &40)=0 PRINTTAB(15,17)"Centre"
      ELSE PRINTTAB(15,17)"      "
 1100 IF (button AND &20)=0 PRINTTAB(10,17)"Left"
      ELSE PRINTTAB(10,17)"    "
 1110 UNTIL FALSE
 1120 VDU23,1,1;0;0;0;
 1130 CALL mcode
00000000  55 73 69 6e 67 20 61 20  6d 6f 75 73 65 20 77 69  |Using a mouse wi|
00000010  74 68 20 74 68 65 20 42  42 43 20 6d 69 63 72 6f  |th the BBC micro|
00000020  63 6f 6d 70 75 74 65 72  20 2d 20 62 79 20 2d 20  |computer - by - |
00000030  47 6f 72 64 6f 6e 20 48  6f 72 73 69 6e 67 74 6f  |Gordon Horsingto|
00000040  6e 0d 2d 2d 2d 2d 2d 2d  2d 2d 2d 2d 2d 2d 2d 2d  |n.--------------|
00000050  2d 2d 2d 2d 2d 2d 2d 2d  2d 2d 2d 2d 2d 2d 2d 2d  |----------------|
*
00000080  2d 2d 2d 0d 0d 4d 6f 64  75 6c 65 20 31 2e 20 52  |---..Module 1. R|
00000090  65 61 64 69 6e 67 20 74  68 65 20 6d 6f 75 73 65  |eading the mouse|
000000a0  20 63 6f 6f 72 64 69 6e  61 74 65 73 20 0d 2d 2d  | coordinates .--|
000000b0  2d 2d 2d 2d 2d 2d 2d 2d  2d 2d 2d 2d 2d 2d 2d 2d  |----------------|
*
000000d0  2d 2d 2d 2d 2d 0d 0d 54  68 65 20 58 20 61 6e 64  |-----..The X and|
000000e0  20 59 20 63 6f 6f 72 64  69 6e 61 74 65 73 20 61  | Y coordinates a|
000000f0  73 73 69 67 6e 65 64 20  74 6f 20 74 68 65 20 70  |ssigned to the p|
00000100  6f 73 69 74 69 6f 6e 20  6f 66 20 61 20 6d 6f 75  |osition of a mou|
00000110  73 65 20 63 61 6e 20 62  65 20 71 75 69 74 65 0d  |se can be quite.|
00000120  61 72 62 69 74 72 61 72  79 2e 20 54 68 65 20 72  |arbitrary. The r|
00000130  61 6e 67 65 20 6f 66 20  63 6f 6f 72 64 69 6e 61  |ange of coordina|
00000140  74 65 73 20 79 6f 75 20  63 68 6f 6f 73 65 20 74  |tes you choose t|
00000150  6f 20 6d 61 6b 65 20 61  76 61 69 6c 61 62 6c 65  |o make available|
00000160  20 61 6e 64 20 74 68 65  0d 72 61 74 65 20 61 74  | and the.rate at|
00000170  20 77 68 69 63 68 20 74  68 65 79 20 63 68 61 6e  | which they chan|
00000180  67 65 20 77 69 74 68 20  6d 6f 75 73 65 20 6d 6f  |ge with mouse mo|
00000190  76 65 6d 65 6e 74 20 69  73 20 65 6e 74 69 72 65  |vement is entire|
000001a0  6c 79 20 75 6e 64 65 72  20 73 6f 66 74 77 61 72  |ly under softwar|
000001b0  65 0d 63 6f 6e 74 72 6f  6c 2e 20 49 66 2c 20 66  |e.control. If, f|
000001c0  6f 72 20 65 78 61 6d 70  6c 65 2c 20 79 6f 75 20  |or example, you |
000001d0  77 61 6e 74 20 74 6f 20  75 73 65 20 61 20 6d 6f  |want to use a mo|
000001e0  75 73 65 20 74 6f 20 64  72 61 77 20 6f 6e 20 61  |use to draw on a|
000001f0  20 67 72 61 70 68 69 63  73 0d 73 63 72 65 65 6e  | graphics.screen|
00000200  20 69 74 20 77 6f 75 6c  64 20 62 65 20 61 20 67  | it would be a g|
00000210  6f 6f 64 20 69 64 65 61  20 74 6f 20 75 73 65 20  |ood idea to use |
00000220  61 20 72 61 6e 67 65 20  6f 66 20 63 6f 6f 72 64  |a range of coord|
00000230  69 6e 61 74 65 73 20 66  72 6f 6d 20 30 20 74 6f  |inates from 0 to|
00000240  0d 31 32 37 39 20 66 6f  72 20 58 20 61 6e 64 20  |.1279 for X and |
00000250  30 20 74 6f 20 31 30 32  33 20 66 6f 72 20 59 2c  |0 to 1023 for Y,|
00000260  20 77 69 74 68 20 69 6e  63 72 65 6d 65 6e 74 73  | with increments|
00000270  20 6f 66 20 34 20 66 6f  72 20 65 61 63 68 20 69  | of 4 for each i|
00000280  6e 74 65 72 72 75 70 74  0d 67 65 6e 65 72 61 74  |nterrupt.generat|
00000290  65 64 20 62 79 20 74 68  65 20 6d 6f 75 73 65 2e  |ed by the mouse.|
000002a0  0d 0d 54 68 65 20 6d 6f  76 65 6d 65 6e 74 20 6f  |..The movement o|
000002b0  66 20 74 68 65 20 6d 6f  75 73 65 20 62 61 6c 6c  |f the mouse ball|
000002c0  20 63 61 6e 20 67 65 6e  65 72 61 74 65 20 61 6e  | can generate an|
000002d0  20 69 6e 74 65 72 72 75  70 74 20 75 73 69 6e 67  | interrupt using|
000002e0  20 65 69 74 68 65 72 20  43 42 31 0d 6f 72 20 43  | either CB1.or C|
000002f0  42 32 2e 20 41 6e 20 69  6e 74 65 72 72 75 70 74  |B2. An interrupt|
00000300  20 67 65 6e 65 72 61 74  65 64 20 62 79 20 43 42  | generated by CB|
00000310  31 20 69 6e 64 69 63 61  74 65 73 20 61 20 6d 6f  |1 indicates a mo|
00000320  76 65 6d 65 6e 74 20 65  69 74 68 65 72 20 6c 65  |vement either le|
00000330  66 74 20 6f 72 0d 72 69  67 68 74 20 61 6e 64 20  |ft or.right and |
00000340  61 6e 20 69 6e 74 65 72  72 75 70 74 20 67 65 6e  |an interrupt gen|
00000350  65 72 61 74 65 64 20 62  79 20 43 42 32 20 69 6e  |erated by CB2 in|
00000360  64 69 63 61 74 65 73 20  61 20 6d 6f 76 65 6d 65  |dicates a moveme|
00000370  6e 74 20 65 69 74 68 65  72 20 75 70 20 6f 72 0d  |nt either up or.|
00000380  64 6f 77 6e 2e 20 54 68  65 20 70 6c 61 6e 65 20  |down. The plane |
00000390  6f 66 20 74 68 65 20 63  68 61 6e 67 65 20 28 65  |of the change (e|
000003a0  69 74 68 65 72 20 58 20  6f 72 20 59 29 20 69 73  |ither X or Y) is|
000003b0  20 69 6e 64 69 63 61 74  65 64 20 62 79 20 74 68  | indicated by th|
000003c0  65 0d 68 61 6e 64 73 68  61 6b 65 20 6c 69 6e 65  |e.handshake line|
000003d0  73 20 62 75 74 20 74 68  65 20 64 69 72 65 63 74  |s but the direct|
000003e0  69 6f 6e 20 28 65 69 74  68 65 72 20 69 6e 63 72  |ion (either incr|
000003f0  65 61 73 69 6e 67 20 6f  72 20 64 65 63 72 65 61  |easing or decrea|
00000400  73 69 6e 67 29 20 69 73  0d 69 6e 64 69 63 61 74  |sing) is.indicat|
00000410  65 64 20 62 79 20 74 77  6f 20 62 69 74 73 20 69  |ed by two bits i|
00000420  6e 20 64 61 74 61 20 72  65 67 69 73 74 65 72 20  |n data register |
00000430  42 20 28 44 52 42 2c 20  26 46 45 36 30 29 2e 20  |B (DRB, &FE60). |
00000440  49 66 20 61 6e 20 69 6e  74 65 72 72 75 70 74 20  |If an interrupt |
00000450  69 73 0d 67 65 6e 65 72  61 74 65 64 20 62 79 20  |is.generated by |
00000460  43 42 31 20 74 68 65 6e  20 79 6f 75 72 20 70 72  |CB1 then your pr|
00000470  6f 67 72 61 6d 20 73 68  6f 75 6c 64 20 65 78 61  |ogram should exa|
00000480  6d 69 6e 65 20 62 69 74  20 30 20 6f 66 20 44 52  |mine bit 0 of DR|
00000490  42 2e 20 49 66 20 62 69  74 20 30 0d 6f 66 20 44  |B. If bit 0.of D|
000004a0  52 42 20 69 73 20 73 65  74 20 58 20 69 73 20 64  |RB is set X is d|
000004b0  65 63 72 65 61 73 69 6e  67 2c 20 69 66 20 69 74  |ecreasing, if it|
000004c0  20 69 73 20 63 6c 65 61  72 20 58 20 69 73 20 69  | is clear X is i|
000004d0  6e 63 72 65 61 73 69 6e  67 2e 20 53 69 6d 69 6c  |ncreasing. Simil|
000004e0  61 72 6c 79 0d 69 66 20  61 6e 20 69 6e 74 65 72  |arly.if an inter|
000004f0  72 75 70 74 20 69 73 20  67 65 6e 65 72 61 74 65  |rupt is generate|
00000500  64 20 62 79 20 43 42 32  20 74 68 65 6e 20 79 6f  |d by CB2 then yo|
00000510  75 72 20 70 72 6f 67 72  61 6d 20 73 68 6f 75 6c  |ur program shoul|
00000520  64 20 65 78 61 6d 69 6e  65 20 62 69 74 20 32 0d  |d examine bit 2.|
00000530  6f 66 20 44 52 42 2e 20  49 66 20 62 69 74 20 32  |of DRB. If bit 2|
00000540  20 6f 66 20 44 52 42 20  69 73 20 73 65 74 20 59  | of DRB is set Y|
00000550  20 69 73 20 64 65 63 72  65 61 73 69 6e 67 2c 20  | is decreasing, |
00000560  69 66 20 69 74 20 69 73  20 63 6c 65 61 72 20 59  |if it is clear Y|
00000570  20 69 73 0d 69 6e 63 72  65 61 73 69 6e 67 2e 0d  | is.increasing..|
00000580  0d 49 74 20 69 73 20 70  6f 73 73 69 62 6c 65 20  |.It is possible |
00000590  74 6f 20 6c 61 74 63 68  20 74 68 65 20 64 61 74  |to latch the dat|
000005a0  61 20 69 6e 20 44 52 42  20 73 6f 20 74 68 61 74  |a in DRB so that|
000005b0  20 74 68 65 20 76 61 6c  75 65 73 20 72 65 61 64  | the values read|
000005c0  20 66 72 6f 6d 20 74 68  65 0d 72 65 67 69 73 74  | from the.regist|
000005d0  65 72 20 61 72 65 20 74  68 6f 73 65 20 74 68 61  |er are those tha|
000005e0  74 20 77 65 72 65 20 70  72 65 73 65 6e 74 20 77  |t were present w|
000005f0  68 65 6e 20 61 20 63 68  61 6e 67 65 20 6f 66 20  |hen a change of |
00000600  73 69 67 6e 61 6c 20 6f  63 63 75 72 65 64 20 6f  |signal occured o|
00000610  6e 0d 43 42 31 2e 20 54  68 69 73 20 6d 65 61 6e  |n.CB1. This mean|
00000620  73 20 74 68 61 74 2c 20  69 66 20 6c 61 74 63 68  |s that, if latch|
00000630  69 6e 67 20 69 73 20 73  65 6c 65 63 74 65 64 2c  |ing is selected,|
00000640  20 74 68 65 20 64 61 74  61 20 66 6f 72 20 6d 6f  | the data for mo|
00000650  76 65 6d 65 6e 74 20 69  6e 0d 74 68 65 20 58 20  |vement in.the X |
00000660  64 69 72 65 63 74 69 6f  6e 20 77 69 6c 6c 20 72  |direction will r|
00000670  65 6d 61 69 6e 20 61 76  61 69 6c 61 62 6c 65 20  |emain available |
00000680  75 6e 74 69 6c 20 61 20  6e 65 77 20 6d 6f 76 65  |until a new move|
00000690  6d 65 6e 74 20 69 73 20  64 65 74 65 63 74 65 64  |ment is detected|
000006a0  2e 0d 54 68 69 73 20 77  6f 75 6c 64 20 62 65 20  |..This would be |
000006b0  76 65 72 79 20 75 73 65  66 75 6c 20 69 66 20 69  |very useful if i|
000006c0  74 20 77 61 73 20 61 6c  73 6f 20 61 76 61 69 6c  |t was also avail|
000006d0  61 62 6c 65 20 66 6f 72  20 6d 6f 76 65 6d 65 6e  |able for movemen|
000006e0  74 20 69 6e 20 74 68 65  20 59 0d 64 69 72 65 63  |t in the Y.direc|
000006f0  74 69 6f 6e 2c 20 62 75  74 20 6c 61 74 63 68 69  |tion, but latchi|
00000700  6e 67 20 69 73 20 6e 6f  74 20 61 76 61 69 6c 61  |ng is not availa|
00000710  62 6c 65 20 66 6f 72 20  73 69 67 6e 61 6c 73 20  |ble for signals |
00000720  6f 6e 20 43 42 32 2e 20  49 74 20 69 73 20 6f 6e  |on CB2. It is on|
00000730  6c 79 0d 77 6f 72 74 68  20 73 65 6c 65 63 74 69  |ly.worth selecti|
00000740  6e 67 20 74 68 65 20 6c  61 74 63 68 69 6e 67 20  |ng the latching |
00000750  6d 6f 64 65 20 28 62 79  20 73 65 74 74 69 6e 67  |mode (by setting|
00000760  20 62 69 74 20 31 20 6f  66 20 74 68 65 20 41 43  | bit 1 of the AC|
00000770  52 20 61 74 20 26 46 45  36 42 29 0d 69 66 20 79  |R at &FE6B).if y|
00000780  6f 75 20 61 72 65 20 6f  6e 6c 79 20 69 6e 74 65  |ou are only inte|
00000790  72 65 73 74 65 64 20 69  6e 20 6d 6f 76 65 6d 65  |rested in moveme|
000007a0  6e 74 20 66 72 6f 6d 20  73 69 64 65 20 74 6f 20  |nt from side to |
000007b0  73 69 64 65 2e 20 49 6e  20 70 72 61 63 74 69 63  |side. In practic|
000007c0  65 20 74 68 69 73 0d 63  6f 75 6c 64 20 62 65 20  |e this.could be |
000007d0  75 73 65 66 75 6c 20 77  69 74 68 20 67 61 6d 65  |useful with game|
000007e0  73 20 73 6f 66 74 77 61  72 65 2e 0d 0d 42 65 63  |s software...Bec|
000007f0  61 75 73 65 20 6c 61 74  63 68 69 6e 67 20 69 73  |ause latching is|
00000800  20 75 6e 61 76 61 69 6c  61 62 6c 65 20 66 6f 72  | unavailable for|
00000810  20 6d 6f 76 65 6d 65 6e  74 73 20 69 6e 20 74 68  | movements in th|
00000820  65 20 59 20 70 6c 61 6e  65 20 74 68 65 20 6d 6f  |e Y plane the mo|
00000830  75 73 65 0d 67 65 6e 65  72 61 74 65 64 20 69 6e  |use.generated in|
00000840  74 65 72 72 75 70 74 73  20 68 61 76 65 20 74 6f  |terrupts have to|
00000850  20 62 65 20 69 6e 74 65  72 63 65 70 74 65 64 20  | be intercepted |
00000860  61 74 20 74 68 65 20 68  69 67 68 20 70 72 69 6f  |at the high prio|
00000870  72 69 74 79 20 49 52 51  31 56 0d 69 6e 74 65 72  |rity IRQ1V.inter|
00000880  72 75 70 74 20 76 65 63  74 6f 72 20 74 6f 20 65  |rupt vector to e|
00000890  6e 73 75 72 65 20 74 68  61 74 20 62 69 74 73 20  |nsure that bits |
000008a0  30 20 61 6e 64 20 32 20  6f 66 20 44 52 42 20 72  |0 and 2 of DRB r|
000008b0  65 66 6c 65 63 74 20 74  68 65 20 74 72 75 65 0d  |eflect the true.|
000008c0  63 68 61 6e 67 65 20 6f  66 20 64 69 72 65 63 74  |change of direct|
000008d0  69 6f 6e 20 69 6e 20 74  68 65 20 58 20 61 6e 64  |ion in the X and|
000008e0  20 59 20 63 6f 6f 72 64  69 6e 61 74 65 73 2e 20  | Y coordinates. |
000008f0  49 66 20 74 68 65 20 69  6e 74 65 72 72 75 70 74  |If the interrupt|
00000900  73 20 61 72 65 0d 69 6e  74 65 72 63 65 70 74 65  |s are.intercepte|
00000910  64 20 61 74 20 74 68 65  20 6c 6f 77 20 70 72 69  |d at the low pri|
00000920  6f 72 69 74 79 20 49 52  51 32 56 20 69 6e 74 65  |ority IRQ2V inte|
00000930  72 72 75 70 74 20 76 65  63 74 6f 72 20 74 68 65  |rrupt vector the|
00000940  6e 20 74 68 65 0d 6e 6f  6e 2d 6c 61 74 63 68 65  |n the.non-latche|
00000950  64 20 44 52 42 20 6d 61  79 20 6f 72 20 6d 61 79  |d DRB may or may|
00000960  20 6e 6f 74 20 72 65 66  6c 65 63 74 20 74 68 65  | not reflect the|
00000970  20 64 69 72 65 63 74 69  6f 6e 20 6f 66 20 74 68  | direction of th|
00000980  65 20 6d 6f 75 73 65 0d  6d 6f 76 65 6d 65 6e 74  |e mouse.movement|
00000990  2e 20 49 6e 20 74 68 65  20 64 65 6d 6f 6e 73 74  |. In the demonst|
000009a0  72 61 74 69 6f 6e 20 70  72 6f 67 72 61 6d 73 20  |ration programs |
000009b0  77 68 69 63 68 20 72 65  76 65 63 74 6f 72 20 61  |which revector a|
000009c0  6e 20 69 6e 74 65 72 72  75 70 74 0d 76 65 63 74  |n interrupt.vect|
000009d0  6f 72 2c 20 49 52 51 31  56 20 69 73 20 75 73 65  |or, IRQ1V is use|
000009e0  64 20 61 6e 64 20 56 49  41 2d 42 20 69 73 20 69  |d and VIA-B is i|
000009f0  6e 20 74 68 65 20 6e 6f  6e 2d 6c 61 74 63 68 65  |n the non-latche|
00000a00  64 20 6d 6f 64 65 2e 0d  0d 54 68 65 20 70 72 6f  |d mode...The pro|
00000a10  67 72 61 6d 20 4d 4f 55  53 45 20 69 6c 6c 75 73  |gram MOUSE illus|
00000a20  74 72 61 74 65 73 20 68  6f 77 20 74 68 65 20 49  |trates how the I|
00000a30  52 51 31 56 20 76 65 63  74 6f 72 20 69 73 20 72  |RQ1V vector is r|
00000a40  65 76 65 63 74 6f 72 65  64 20 74 6f 20 70 6f 69  |evectored to poi|
00000a50  6e 74 0d 74 6f 20 74 68  65 20 6e 65 77 20 63 6f  |nt.to the new co|
00000a60  64 65 20 6c 61 62 65 6c  65 64 20 69 6e 74 65 72  |de labeled inter|
00000a70  72 75 70 74 2e 20 44 61  74 61 20 72 65 67 69 73  |rupt. Data regis|
00000a80  74 65 72 20 42 20 69 73  20 73 65 6c 65 63 74 65  |ter B is selecte|
00000a90  64 20 61 73 20 61 6e 20  69 6e 70 75 74 0d 62 79  |d as an input.by|
00000aa0  20 73 74 6f 72 69 6e 67  20 7a 65 72 6f 20 69 6e  | storing zero in|
00000ab0  20 64 61 74 61 20 64 69  72 65 63 74 69 6f 6e 20  | data direction |
00000ac0  72 65 67 69 73 74 65 72  20 42 2e 20 43 42 31 20  |register B. CB1 |
00000ad0  61 6e 64 20 43 42 32 20  69 6e 74 65 72 72 75 70  |and CB2 interrup|
00000ae0  74 73 20 61 72 65 0d 65  6e 61 62 6c 65 64 20 62  |ts are.enabled b|
00000af0  79 20 73 74 6f 72 69 6e  67 20 26 39 38 20 28 25  |y storing &98 (%|
00000b00  31 30 30 31 31 30 30 30  29 20 69 6e 20 74 68 65  |10011000) in the|
00000b10  20 69 6e 74 65 72 72 75  70 74 20 65 6e 61 62 6c  | interrupt enabl|
00000b20  65 20 72 65 67 69 73 74  65 72 2c 20 62 6f 74 68  |e register, both|
00000b30  0d 43 42 31 20 61 6e 64  20 43 42 32 20 70 72 6f  |.CB1 and CB2 pro|
00000b40  64 75 63 65 20 61 6e 20  69 6e 74 65 72 72 75 70  |duce an interrup|
00000b50  74 20 6f 6e 20 61 20 70  6f 73 69 74 69 76 65 20  |t on a positive |
00000b60  74 72 61 6e 73 69 74 69  6f 6e 2c 20 61 6e 64 20  |transition, and |
00000b70  74 68 65 0d 69 6e 74 65  72 72 75 70 74 20 69 73  |the.interrupt is|
00000b80  20 63 6c 65 61 72 65 64  20 62 79 20 73 65 6c 65  | cleared by sele|
00000b90  63 74 69 6e 67 20 28 72  65 61 64 69 6e 67 20 66  |cting (reading f|
00000ba0  72 6f 6d 29 20 74 68 65  20 64 61 74 61 20 72 65  |rom) the data re|
00000bb0  67 69 73 74 65 72 20 42  2e 20 49 6e 0d 74 68 69  |gister B. In.thi|
00000bc0  73 20 65 78 61 6d 70 6c  65 20 74 68 65 20 69 6e  |s example the in|
00000bd0  69 74 69 61 6c 20 63 6f  6f 72 64 69 6e 61 74 65  |itial coordinate|
00000be0  73 20 61 73 73 69 67 6e  65 64 20 74 6f 20 74 68  |s assigned to th|
00000bf0  65 20 63 75 72 72 65 6e  74 20 6d 6f 75 73 65 0d  |e current mouse.|
00000c00  70 6f 73 69 74 69 6f 6e  20 61 72 65 20 30 2c 30  |position are 0,0|
00000c10  2e 20 54 68 65 20 69 6e  69 74 69 61 6c 20 63 6f  |. The initial co|
00000c20  6f 72 64 69 6e 61 74 65  73 20 63 6f 75 6c 64 20  |ordinates could |
00000c30  62 65 20 61 6e 79 74 68  69 6e 67 20 79 6f 75 20  |be anything you |
00000c40  6c 69 6b 65 0d 77 69 74  68 69 6e 20 74 68 65 20  |like.within the |
00000c50  72 61 6e 67 65 20 66 72  6f 6d 20 30 20 74 6f 20  |range from 0 to |
00000c60  32 35 35 2e 0d 0d 41 6c  6c 20 74 68 65 20 65 78  |255...All the ex|
00000c70  61 6d 70 6c 65 20 70 72  6f 67 72 61 6d 73 20 69  |ample programs i|
00000c80  6e 20 74 68 69 73 20 73  65 72 69 65 73 20 75 73  |n this series us|
00000c90  65 20 61 20 72 61 6e 67  65 20 6f 66 20 66 72 6f  |e a range of fro|
00000ca0  6d 20 30 20 74 6f 20 32  35 35 20 66 6f 72 0d 62  |m 0 to 255 for.b|
00000cb0  6f 74 68 20 74 68 65 20  58 20 61 6e 64 20 59 20  |oth the X and Y |
00000cc0  63 6f 6f 72 64 69 6e 61  74 65 73 2e 20 54 68 69  |coordinates. Thi|
00000cd0  73 20 73 69 6d 70 6c 69  66 69 65 73 20 74 68 65  |s simplifies the|
00000ce0  20 64 65 6d 6f 6e 73 74  72 61 74 69 6f 6e 20 70  | demonstration p|
00000cf0  72 6f 67 72 61 6d 73 0d  62 65 63 61 75 73 65 20  |rograms.because |
00000d00  6f 6e 6c 79 20 6f 6e 65  20 62 79 74 65 20 69 73  |only one byte is|
00000d10  20 75 73 65 64 20 74 6f  20 73 74 6f 72 65 20 65  | used to store e|
00000d20  61 63 68 20 63 6f 6f 72  64 69 6e 61 74 65 2e 20  |ach coordinate. |
00000d30  54 68 65 20 58 20 61 6e  64 20 59 0d 63 6f 6f 72  |The X and Y.coor|
00000d40  64 69 6e 61 74 65 73 20  63 61 6e 20 74 68 65 6e  |dinates can then|
00000d50  20 62 65 20 72 65 61 64  20 77 69 74 68 20 74 68  | be read with th|
00000d60  65 20 42 41 53 49 43 20  3f 20 69 6e 64 69 72 65  |e BASIC ? indire|
00000d70  63 74 69 6f 6e 20 6f 70  65 72 61 74 6f 72 2e 20  |ction operator. |
00000d80  49 66 20 79 6f 75 0d 64  65 63 69 64 65 20 74 6f  |If you.decide to|
00000d90  20 6d 6f 64 69 66 79 20  61 6e 79 20 6f 66 20 74  | modify any of t|
00000da0  68 65 20 64 65 6d 6f 6e  73 74 72 61 74 69 6f 6e  |he demonstration|
00000db0  20 70 72 6f 67 72 61 6d  73 20 74 6f 20 75 73 65  | programs to use|
00000dc0  20 61 20 6c 61 72 67 65  72 20 72 61 6e 67 65 0d  | a larger range.|
00000dd0  6f 66 20 63 6f 6f 72 64  69 6e 61 74 65 73 20 69  |of coordinates i|
00000de0  74 20 69 73 20 61 20 67  6f 6f 64 20 69 64 65 61  |t is a good idea|
00000df0  20 74 6f 20 75 73 65 20  66 6f 75 72 20 62 79 74  | to use four byt|
00000e00  65 73 20 66 6f 72 20 65  61 63 68 20 63 6f 6f 72  |es for each coor|
00000e10  64 69 6e 61 74 65 0d 65  76 65 6e 20 69 66 20 79  |dinate.even if y|
00000e20  6f 75 20 6f 6e 6c 79 20  69 6e 74 65 6e 64 20 74  |ou only intend t|
00000e30  6f 20 75 73 65 20 74 77  6f 20 6f 66 20 74 68 65  |o use two of the|
00000e40  20 66 6f 75 72 20 62 79  74 65 73 20 74 6f 20 73  | four bytes to s|
00000e50  74 6f 72 65 20 74 68 65  20 61 63 74 75 61 6c 0d  |tore the actual.|
00000e60  6e 75 6d 62 65 72 2e 20  55 73 69 6e 67 20 66 6f  |number. Using fo|
00000e70  75 72 20 62 79 74 65 73  20 77 69 6c 6c 20 61 6c  |ur bytes will al|
00000e80  6c 6f 77 20 42 41 53 49  43 20 74 6f 20 72 65 61  |low BASIC to rea|
00000e90  64 20 74 68 65 20 63 6f  6f 72 64 69 6e 61 74 65  |d the coordinate|
00000ea0  20 77 69 74 68 20 74 68  65 0d 21 20 69 6e 64 69  | with the.! indi|
00000eb0  72 65 63 74 69 6f 6e 20  6f 70 65 72 61 74 6f 72  |rection operator|
00000ec0  2e 20 49 66 20 6f 6e 6c  79 20 74 77 6f 20 62 79  |. If only two by|
00000ed0  74 65 73 20 61 72 65 20  75 73 65 64 20 74 68 65  |tes are used the|
00000ee0  6e 20 74 68 65 20 3f 20  69 6e 64 69 72 65 63 74  |n the ? indirect|
00000ef0  69 6f 6e 0d 6f 70 65 72  61 74 6f 72 20 77 69 6c  |ion.operator wil|
00000f00  6c 20 6e 65 65 64 20 74  6f 20 62 65 20 75 73 65  |l need to be use|
00000f10  64 20 74 77 69 63 65 20  66 6f 72 20 65 61 63 68  |d twice for each|
00000f20  20 63 6f 6f 72 64 69 6e  61 74 65 2e 20 59 6f 75  | coordinate. You|
00000f30  20 6d 69 67 68 74 20 61  6c 73 6f 0d 6c 69 6b 65  | might also.like|
00000f40  20 74 6f 20 63 6f 6e 73  69 64 65 72 20 73 74 6f  | to consider sto|
00000f50  72 69 6e 67 20 74 68 65  20 63 6f 6f 72 64 69 6e  |ring the coordin|
00000f60  61 74 65 73 20 69 6e 20  74 68 65 20 6d 65 6d 6f  |ates in the memo|
00000f70  72 79 20 61 6c 6c 6f 63  61 74 65 64 20 74 6f 20  |ry allocated to |
00000f80  74 68 65 0d 73 79 73 74  65 6d 20 69 6e 74 65 67  |the.system integ|
00000f90  65 72 20 76 61 72 69 61  62 6c 65 73 20 28 41 25  |er variables (A%|
00000fa0  20 74 6f 20 5a 25 29 20  61 6e 64 20 74 68 69 73  | to Z%) and this|
00000fb0  20 77 69 6c 6c 20 73 69  6d 70 6c 69 66 79 20 72  | will simplify r|
00000fc0  65 61 64 69 6e 67 20 74  68 65 0d 63 6f 6f 72 64  |eading the.coord|
00000fd0  69 6e 61 74 65 73 20 65  76 65 6e 20 66 75 72 74  |inates even furt|
00000fe0  68 65 72 2e 0d 0d 54 68  65 20 69 6e 74 65 72 72  |her...The interr|
00000ff0  75 70 74 20 68 61 6e 64  6c 69 6e 67 20 72 6f 75  |upt handling rou|
00001000  74 69 6e 65 20 69 6e 20  4d 4f 55 53 45 20 64 6f  |tine in MOUSE do|
00001010  65 73 20 6e 6f 74 20 75  73 65 20 65 69 74 68 65  |es not use eithe|
00001020  72 20 74 68 65 20 58 20  6f 72 20 59 0d 72 65 67  |r the X or Y.reg|
00001030  69 73 74 65 72 73 20 61  6e 64 20 73 6f 20 6f 6e  |isters and so on|
00001040  6c 79 20 74 68 65 20 61  63 63 75 6d 75 6c 61 74  |ly the accumulat|
00001050  6f 72 20 28 66 72 6f 6d  20 26 46 43 29 20 69 73  |or (from &FC) is|
00001060  20 73 74 6f 72 65 64 20  6f 6e 20 74 68 65 20 73  | stored on the s|
00001070  74 61 63 6b 20 61 74 0d  74 68 65 20 62 65 67 69  |tack at.the begi|
00001080  6e 6e 69 6e 67 20 6f 66  20 74 68 65 20 72 6f 75  |nning of the rou|
00001090  74 69 6e 65 20 61 6e 64  20 72 65 73 74 6f 72 65  |tine and restore|
000010a0  64 20 61 74 20 74 68 65  20 65 6e 64 2e 20 54 68  |d at the end. Th|
000010b0  65 20 69 6e 74 65 72 72  75 70 74 0d 68 61 6e 64  |e interrupt.hand|
000010c0  6c 69 6e 67 20 72 6f 75  74 69 6e 65 20 66 69 72  |ling routine fir|
000010d0  73 74 20 65 78 61 6d 69  6e 65 73 20 62 69 74 20  |st examines bit |
000010e0  37 20 6f 66 20 74 68 65  20 69 6e 74 65 72 72 75  |7 of the interru|
000010f0  70 74 20 66 6c 61 67 20  72 65 67 69 73 74 65 72  |pt flag register|
00001100  2e 20 42 69 74 0d 37 20  77 69 6c 6c 20 61 6c 77  |. Bit.7 will alw|
00001110  61 79 73 20 62 65 20 73  65 74 20 66 6f 72 20 61  |ays be set for a|
00001120  20 55 73 65 72 20 50 6f  72 74 20 69 6e 74 65 72  | User Port inter|
00001130  72 75 70 74 2e 20 49 66  20 61 20 6d 6f 75 73 65  |rupt. If a mouse|
00001140  20 63 6f 6e 6e 65 63 74  65 64 20 74 6f 0d 74 68  | connected to.th|
00001150  65 20 55 73 65 72 20 50  6f 72 74 20 69 73 20 74  |e User Port is t|
00001160  68 65 20 73 6f 75 72 63  65 20 6f 66 20 61 6e 20  |he source of an |
00001170  69 6e 74 65 72 72 75 70  74 20 74 68 65 6e 20 65  |interrupt then e|
00001180  69 74 68 65 72 20 62 69  74 20 33 20 6f 72 20 62  |ither bit 3 or b|
00001190  69 74 20 34 20 6f 66 0d  74 68 65 20 49 46 52 20  |it 4 of.the IFR |
000011a0  77 69 6c 6c 20 61 6c 73  6f 20 62 65 20 73 65 74  |will also be set|
000011b0  2e 20 42 69 74 20 33 20  77 69 6c 6c 20 62 65 20  |. Bit 3 will be |
000011c0  73 65 74 20 66 6f 72 20  61 6e 20 69 6e 74 65 72  |set for an inter|
000011d0  72 75 70 74 20 67 65 6e  65 72 61 74 65 64 20 62  |rupt generated b|
000011e0  79 0d 43 42 32 20 61 6e  64 20 62 69 74 20 34 20  |y.CB2 and bit 4 |
000011f0  77 69 6c 6c 20 62 65 20  73 65 74 20 66 6f 72 20  |will be set for |
00001200  61 6e 20 69 6e 74 65 72  72 75 70 74 20 67 65 6e  |an interrupt gen|
00001210  65 72 61 74 65 64 20 62  79 20 43 42 31 2e 20 49  |erated by CB1. I|
00001220  66 20 65 69 74 68 65 72  20 62 69 74 0d 34 20 6f  |f either bit.4 o|
00001230  72 20 62 69 74 20 33 20  6f 66 20 74 68 65 20 49  |r bit 3 of the I|
00001240  46 52 20 69 73 20 73 65  74 20 74 68 65 6e 20 74  |FR is set then t|
00001250  68 65 20 64 69 72 65 63  74 69 6f 6e 20 6f 66 20  |he direction of |
00001260  74 68 65 20 6d 6f 76 65  6d 65 6e 74 20 69 73 20  |the movement is |
00001270  66 6f 75 6e 64 0d 62 79  20 65 78 61 6d 69 6e 69  |found.by examini|
00001280  6e 67 20 65 69 74 68 65  72 20 62 69 74 20 30 20  |ng either bit 0 |
00001290  6f 72 20 62 69 74 20 32  20 6f 66 20 74 68 65 20  |or bit 2 of the |
000012a0  44 52 42 2e 20 49 66 20  74 68 65 20 64 69 72 65  |DRB. If the dire|
000012b0  63 74 69 6f 6e 20 69 73  0d 69 6e 63 72 65 61 73  |ction is.increas|
000012c0  69 6e 67 20 74 68 65 20  74 68 65 20 61 70 70 72  |ing the the appr|
000012d0  6f 70 72 69 61 74 65 20  63 6f 6f 72 64 69 6e 61  |opriate coordina|
000012e0  74 65 20 69 73 20 69 6e  63 72 65 6d 65 6e 74 65  |te is incremente|
000012f0  64 20 62 79 20 31 20 61  6e 64 20 69 66 20 69 74  |d by 1 and if it|
00001300  20 69 73 0d 64 65 63 72  65 61 73 69 6e 67 20 74  | is.decreasing t|
00001310  68 65 6e 20 74 68 65 20  61 70 70 72 6f 70 72 69  |hen the appropri|
00001320  61 74 65 20 63 6f 6f 72  64 69 6e 61 74 65 20 69  |ate coordinate i|
00001330  73 20 64 65 63 72 65 6d  65 6e 74 65 64 20 62 79  |s decremented by|
00001340  20 31 2e 0d 0d 54 68 69  73 20 64 65 6d 6f 6e 73  | 1...This demons|
00001350  74 72 61 74 69 6f 6e 20  70 72 6f 67 72 61 6d 20  |tration program |
00001360  6d 75 73 74 20 72 75 6e  20 69 6e 20 74 68 65 20  |must run in the |
00001370  49 2f 4f 20 70 72 6f 63  65 73 73 6f 72 20 61 6e  |I/O processor an|
00001380  64 20 69 74 20 75 73 65  73 20 74 68 65 0d 6d 6f  |d it uses the.mo|
00001390  73 74 20 73 69 6d 70 6c  65 20 66 6f 72 6d 20 6f  |st simple form o|
000013a0  66 20 70 6f 6c 6c 69 6e  67 20 74 68 65 20 6d 6f  |f polling the mo|
000013b0  75 73 65 20 62 75 74 74  6f 6e 73 20 66 72 6f 6d  |use buttons from|
000013c0  20 42 41 53 49 43 2e 20  54 68 65 20 6d 6f 75 73  | BASIC. The mous|
000013d0  65 0d 63 6f 6f 72 64 69  6e 61 74 65 73 20 61 72  |e.coordinates ar|
000013e0  65 20 70 65 65 6b 65 64  20 66 72 6f 6d 20 74 68  |e peeked from th|
000013f0  65 20 7a 65 72 6f 20 70  61 67 65 20 6d 65 6d 6f  |e zero page memo|
00001400  72 79 20 6c 6f 63 61 74  69 6f 6e 73 20 61 6e 64  |ry locations and|
00001410  20 64 69 73 70 6c 61 79  65 64 0d 69 6e 20 61 6e  | displayed.in an|
00001420  20 65 6e 64 6c 65 73 73  20 6c 6f 6f 70 2e 20 43  | endless loop. C|
00001430  68 61 69 6e 20 74 68 65  20 70 72 6f 67 72 61 6d  |hain the program|
00001440  20 61 6e 64 20 6d 6f 76  65 20 74 68 65 20 6d 6f  | and move the mo|
00001450  75 73 65 20 61 72 6f 75  6e 64 20 74 6f 20 73 65  |use around to se|
00001460  65 20 74 68 65 0d 72 61  6e 67 65 20 61 6e 64 20  |e the.range and |
00001470  73 65 6e 73 69 74 69 76  69 74 79 20 6f 66 20 74  |sensitivity of t|
00001480  68 65 20 6d 6f 76 65 6d  65 6e 74 2e 20 54 6f 20  |he movement. To |
00001490  73 74 6f 70 20 74 68 65  20 70 72 6f 67 72 61 6d  |stop the program|
000014a0  20 70 72 65 73 73 20 65  69 74 68 65 72 0d 74 68  | press either.th|
000014b0  65 20 45 73 63 61 70 65  20 6b 65 79 20 6f 72 20  |e Escape key or |
000014c0  74 68 65 20 42 72 65 61  6b 20 6b 65 79 2e 20 49  |the Break key. I|
000014d0  6e 20 6d 6f 64 75 6c 65  20 32 20 49 20 77 69 6c  |n module 2 I wil|
000014e0  6c 20 73 68 6f 77 20 68  6f 77 20 74 68 65 20 70  |l show how the p|
000014f0  72 6f 67 72 61 6d 0d 4d  4f 55 53 45 20 63 61 6e  |rogram.MOUSE can|
00001500  20 62 65 20 6d 6f 64 69  66 69 65 64 20 74 6f 20  | be modified to |
00001510  6d 61 6b 65 20 69 74 20  54 75 62 65 20 63 6f 6d  |make it Tube com|
00001520  70 61 74 69 62 6c 65 2e  0d 0d 0d 20 20 20 31 30  |patible....   10|
00001530  20 52 45 4d 3e 20 4d 4f  55 53 45 0d 20 20 20 32  | REM> MOUSE.   2|
00001540  30 20 44 49 4d 20 6d 63  6f 64 65 20 26 32 30 30  |0 DIM mcode &200|
00001550  20 3a 52 45 4d 3a 20 6d  61 63 68 69 6e 65 20 63  | :REM: machine c|
00001560  6f 64 65 20 61 74 20 6d  63 6f 64 65 0d 20 20 20  |ode at mcode.   |
00001570  33 30 20 78 63 6f 6f 72  64 3d 26 38 30 20 3a 52  |30 xcoord=&80 :R|
00001580  45 4d 3a 20 78 20 63 6f  6f 72 64 69 6e 61 74 65  |EM: x coordinate|
00001590  2c 20 72 61 6e 67 65 20  30 2d 32 35 35 0d 20 20  |, range 0-255.  |
000015a0  20 34 30 20 79 63 6f 6f  72 64 3d 26 38 31 20 3a  | 40 ycoord=&81 :|
000015b0  52 45 4d 3a 20 79 20 63  6f 6f 72 64 69 6e 61 74  |REM: y coordinat|
000015c0  65 2c 20 72 61 6e 67 65  20 30 2d 32 35 35 0d 20  |e, range 0-255. |
000015d0  20 20 35 30 20 73 61 76  65 72 65 67 3d 26 46 43  |  50 savereg=&FC|
000015e0  20 3a 52 45 4d 3a 20 69  6e 74 65 72 72 75 70 74  | :REM: interrupt|
000015f0  20 61 63 63 75 6d 75 6c  61 74 6f 72 20 73 61 76  | accumulator sav|
00001600  65 20 72 65 67 69 73 74  65 72 0d 20 20 20 36 30  |e register.   60|
00001610  20 69 72 71 31 76 3d 26  32 30 34 20 3a 52 45 4d  | irq1v=&204 :REM|
00001620  3a 20 70 72 69 6d 61 72  79 20 69 6e 74 65 72 72  |: primary interr|
00001630  75 70 74 20 76 65 63 74  6f 72 0d 20 20 20 37 30  |upt vector.   70|
00001640  20 64 72 62 3d 26 46 45  36 30 20 3a 52 45 4d 3a  | drb=&FE60 :REM:|
00001650  20 64 61 74 61 20 72 65  67 69 73 74 65 72 20 42  | data register B|
00001660  0d 20 20 20 38 30 20 64  64 72 62 3d 26 46 45 36  |.   80 ddrb=&FE6|
00001670  32 20 3a 52 45 4d 3a 20  64 61 74 61 20 64 69 72  |2 :REM: data dir|
00001680  65 63 74 69 6f 6e 20 72  65 67 69 73 74 65 72 20  |ection register |
00001690  42 0d 20 20 20 39 30 20  70 63 72 3d 26 46 45 36  |B.   90 pcr=&FE6|
000016a0  43 20 3a 52 45 4d 3a 20  70 65 72 69 70 68 65 72  |C :REM: peripher|
000016b0  61 6c 20 63 6f 6e 74 72  6f 6c 20 72 65 67 69 73  |al control regis|
000016c0  74 65 72 0d 20 20 31 30  30 20 69 66 72 3d 26 46  |ter.  100 ifr=&F|
000016d0  45 36 44 20 3a 52 45 4d  3a 20 69 6e 74 65 72 72  |E6D :REM: interr|
000016e0  75 70 74 20 66 6c 61 67  20 72 65 67 69 73 74 65  |upt flag registe|
000016f0  72 0d 20 20 31 31 30 20  69 65 72 3d 26 46 45 36  |r.  110 ier=&FE6|
00001700  45 20 3a 52 45 4d 3a 20  69 6e 74 65 72 72 75 70  |E :REM: interrup|
00001710  74 20 65 6e 61 62 6c 65  20 72 65 67 69 73 74 65  |t enable registe|
00001720  72 0d 20 20 31 32 30 20  46 4f 52 20 70 61 73 73  |r.  120 FOR pass|
00001730  3d 30 20 54 4f 20 32 20  53 54 45 50 20 32 0d 20  |=0 TO 2 STEP 2. |
00001740  20 31 33 30 20 50 25 3d  6d 63 6f 64 65 0d 20 20  | 130 P%=mcode.  |
00001750  31 34 30 20 5b 20 20 20  20 20 20 20 4f 50 54 20  |140 [       OPT |
00001760  70 61 73 73 0d 20 20 31  35 30 20 20 20 20 20 20  |pass.  150      |
00001770  20 20 20 4c 44 58 20 69  72 71 31 76 20 20 20 20  |   LDX irq1v    |
00001780  20 5c 20 63 75 72 72 65  6e 74 20 70 72 69 6d 61  | \ current prima|
00001790  72 79 20 69 6e 74 65 72  72 75 70 74 20 76 65 63  |ry interrupt vec|
000017a0  74 6f 72 2c 20 6c 6f 77  20 62 79 74 65 0d 20 20  |tor, low byte.  |
000017b0  31 36 30 20 20 20 20 20  20 20 20 20 4c 44 59 20  |160         LDY |
000017c0  69 72 71 31 76 2b 31 20  20 20 5c 20 63 75 72 72  |irq1v+1   \ curr|
000017d0  65 6e 74 20 70 72 69 6d  61 72 79 20 69 6e 74 65  |ent primary inte|
000017e0  72 72 75 70 74 20 76 65  63 74 6f 72 2c 20 68 69  |rrupt vector, hi|
000017f0  67 68 20 62 79 74 65 0d  20 20 31 37 30 20 20 20  |gh byte.  170   |
00001800  20 20 20 20 20 20 43 50  59 20 23 69 6e 74 65 72  |      CPY #inter|
00001810  72 75 70 74 20 44 49 56  20 32 35 36 20 5c 20 63  |rupt DIV 256 \ c|
00001820  6f 6d 70 61 72 65 20 68  69 67 68 20 62 79 74 65  |ompare high byte|
00001830  0d 20 20 31 38 30 20 20  20 20 20 20 20 20 20 42  |.  180         B|
00001840  45 51 20 64 69 73 61 62  6c 65 20 20 20 5c 20 72  |EQ disable   \ r|
00001850  65 73 74 6f 72 65 20 6f  6c 64 20 76 65 63 74 6f  |estore old vecto|
00001860  72 20 69 66 20 61 6c 74  65 72 65 64 0d 20 20 31  |r if altered.  1|
00001870  39 30 20 20 20 20 20 20  20 20 20 53 54 58 20 6f  |90         STX o|
00001880  6c 64 69 72 71 31 76 20  20 5c 20 73 61 76 65 20  |ldirq1v  \ save |
00001890  6f 72 69 67 69 6e 61 6c  20 69 72 71 31 20 76 65  |original irq1 ve|
000018a0  63 74 6f 72 2c 20 6c 6f  77 20 62 79 74 65 0d 20  |ctor, low byte. |
000018b0  20 32 30 30 20 20 20 20  20 20 20 20 20 53 54 59  | 200         STY|
000018c0  20 6f 6c 64 69 72 71 31  76 2b 31 20 5c 20 73 61  | oldirq1v+1 \ sa|
000018d0  76 65 20 6f 72 69 67 69  6e 61 6c 20 69 72 71 31  |ve original irq1|
000018e0  20 76 65 63 74 6f 72 2c  20 68 69 67 68 20 62 79  | vector, high by|
000018f0  74 65 0d 20 20 32 31 30  20 20 20 20 20 20 20 20  |te.  210        |
00001900  20 4c 44 58 20 23 69 6e  74 65 72 72 75 70 74 20  | LDX #interrupt |
00001910  4d 4f 44 20 32 35 36 20  5c 20 6e 65 77 20 69 72  |MOD 256 \ new ir|
00001920  71 31 20 76 65 63 74 6f  72 2c 20 6c 6f 77 20 62  |q1 vector, low b|
00001930  79 74 65 0d 20 20 32 32  30 20 20 20 20 20 20 20  |yte.  220       |
00001940  20 20 4c 44 59 20 23 69  6e 74 65 72 72 75 70 74  |  LDY #interrupt|
00001950  20 44 49 56 20 32 35 36  20 5c 20 6e 65 77 20 69  | DIV 256 \ new i|
00001960  72 71 31 20 76 65 63 74  6f 72 2c 20 68 69 67 68  |rq1 vector, high|
00001970  20 62 79 74 65 0d 20 20  32 33 30 20 20 20 20 20  | byte.  230     |
00001980  20 20 20 20 53 45 49 20  20 20 20 20 20 20 20 20  |    SEI         |
00001990  20 20 5c 20 73 65 74 20  69 6e 74 65 72 72 75 70  |  \ set interrup|
000019a0  74 20 64 69 73 61 62 6c  65 20 66 6c 61 67 0d 20  |t disable flag. |
000019b0  20 32 34 30 20 20 20 20  20 20 20 20 20 53 54 58  | 240         STX|
000019c0  20 69 72 71 31 76 20 20  20 20 20 5c 20 61 6c 74  | irq1v     \ alt|
000019d0  65 72 20 69 72 71 31 20  76 65 63 74 6f 72 2c 20  |er irq1 vector, |
000019e0  6c 6f 77 20 62 79 74 65  0d 20 20 32 35 30 20 20  |low byte.  250  |
000019f0  20 20 20 20 20 20 20 53  54 59 20 69 72 71 31 76  |       STY irq1v|
00001a00  2b 31 20 20 20 5c 20 61  6c 74 65 72 20 69 72 71  |+1   \ alter irq|
00001a10  31 20 76 65 63 74 6f 72  2c 20 68 69 67 68 20 62  |1 vector, high b|
00001a20  79 74 65 0d 20 20 32 36  30 20 20 20 20 20 20 20  |yte.  260       |
00001a30  20 20 43 4c 49 20 20 20  20 20 20 20 20 20 20 20  |  CLI           |
00001a40  5c 20 63 6c 65 61 72 20  69 6e 74 65 72 72 75 70  |\ clear interrup|
00001a50  74 20 64 69 73 61 62 6c  65 20 66 6c 61 67 0d 20  |t disable flag. |
00001a60  20 32 37 30 20 20 20 20  20 20 20 20 20 4c 44 41  | 270         LDA|
00001a70  20 23 26 39 38 20 20 20  20 20 20 5c 20 25 31 30  | #&98      \ %10|
00001a80  30 31 31 30 30 30 2c 20  69 65 2e 20 65 6e 61 62  |011000, ie. enab|
00001a90  6c 65 20 43 42 31 2f 32  0d 20 20 32 38 30 20 20  |le CB1/2.  280  |
00001aa0  20 20 20 20 20 20 20 53  54 41 20 69 65 72 20 20  |       STA ier  |
00001ab0  20 20 20 20 20 5c 20 69  6e 74 65 72 72 75 70 74  |     \ interrupt|
00001ac0  20 65 6e 61 62 6c 65 20  72 65 67 69 73 74 65 72  | enable register|
00001ad0  0d 20 20 32 39 30 20 20  20 20 20 20 20 20 20 4c  |.  290         L|
00001ae0  44 41 20 70 63 72 20 20  20 20 20 20 20 5c 20 70  |DA pcr       \ p|
00001af0  65 72 69 70 68 65 72 61  6c 20 63 6f 6e 74 72 6f  |eripheral contro|
00001b00  6c 20 72 65 67 69 73 74  65 72 0d 20 20 33 30 30  |l register.  300|
00001b10  20 20 20 20 20 20 20 20  20 41 4e 44 20 23 26 30  |         AND #&0|
00001b20  46 20 20 20 20 20 20 5c  20 41 4e 44 20 77 69 74  |F      \ AND wit|
00001b30  68 20 25 30 30 30 30 31  31 31 31 2c 20 69 65 20  |h %00001111, ie |
00001b40  63 6c 65 61 72 20 62 69  74 73 20 34 2d 37 0d 20  |clear bits 4-7. |
00001b50  20 33 31 30 20 20 20 20  20 20 20 20 20 4f 52 41  | 310         ORA|
00001b60  20 23 26 35 30 20 20 20  20 20 20 5c 20 4f 52 20  | #&50      \ OR |
00001b70  77 69 74 68 20 25 30 31  30 31 30 30 30 30 2c 20  |with %01010000, |
00001b80  69 65 2e 20 73 65 74 20  62 69 74 73 20 34 20 61  |ie. set bits 4 a|
00001b90  6e 64 20 36 0d 20 20 33  32 30 20 20 20 20 20 20  |nd 6.  320      |
00001ba0  20 20 20 53 54 41 20 70  63 72 20 20 20 20 20 20  |   STA pcr      |
00001bb0  20 5c 20 69 6e 74 65 72  72 75 70 74 20 6f 6e 20  | \ interrupt on |
00001bc0  2b 76 65 20 74 72 61 6e  73 69 74 69 6f 6e 2c 20  |+ve transition, |
00001bd0  43 42 32 20 69 6e 70 75  74 2c 0d 20 20 20 20 20  |CB2 input,.     |
00001be0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00001bf0  20 20 20 20 20 20 20 5c  20 44 52 42 20 74 6f 20  |       \ DRB to |
00001c00  63 6c 65 61 72 0d 20 20  33 33 30 20 20 20 20 20  |clear.  330     |
00001c10  20 20 20 20 4c 44 41 20  23 26 30 30 20 20 20 20  |    LDA #&00    |
00001c20  20 20 5c 20 75 73 65 72  20 70 6f 72 74 20 69 6e  |  \ user port in|
00001c30  70 75 74 0d 20 20 33 34  30 20 20 20 20 20 20 20  |put.  340       |
00001c40  20 20 53 54 41 20 64 64  72 62 20 20 20 20 20 20  |  STA ddrb      |
00001c50  5c 20 64 61 74 61 20 64  69 72 65 63 74 69 6f 6e  |\ data direction|
00001c60  20 72 65 67 69 73 74 65  72 20 42 0d 20 20 33 35  | register B.  35|
00001c70  30 20 20 20 20 20 20 20  20 20 53 54 41 20 78 63  |0         STA xc|
00001c80  6f 6f 72 64 20 20 20 20  5c 20 69 6e 69 74 69 61  |oord    \ initia|
00001c90  6c 20 76 61 6c 75 65 20  66 6f 72 20 78 20 63 6f  |l value for x co|
00001ca0  6f 72 64 69 6e 61 74 65  0d 20 20 33 36 30 20 20  |ordinate.  360  |
00001cb0  20 20 20 20 20 20 20 53  54 41 20 79 63 6f 6f 72  |       STA ycoor|
00001cc0  64 20 20 20 20 5c 20 69  6e 69 74 69 61 6c 20 76  |d    \ initial v|
00001cd0  61 6c 75 65 20 66 6f 72  20 79 20 63 6f 6f 72 64  |alue for y coord|
00001ce0  69 6e 61 74 65 0d 20 20  33 37 30 20 20 20 20 20  |inate.  370     |
00001cf0  20 20 20 20 52 54 53 20  20 20 20 20 20 20 20 20  |    RTS         |
00001d00  20 20 5c 20 72 65 74 75  72 6e 20 74 6f 20 42 41  |  \ return to BA|
00001d10  53 49 43 0d 20 20 33 38  30 20 2e 64 69 73 61 62  |SIC.  380 .disab|
00001d20  6c 65 0d 20 20 33 39 30  20 20 20 20 20 20 20 20  |le.  390        |
00001d30  20 4c 44 41 20 23 26 31  38 20 20 20 20 20 20 5c  | LDA #&18      \|
00001d40  20 25 30 30 30 31 31 30  30 30 2c 20 72 65 61 64  | %00011000, read|
00001d50  79 20 74 6f 20 63 6c 65  61 72 20 62 69 74 73 20  |y to clear bits |
00001d60  33 20 61 6e 64 20 34 20  6f 66 20 69 65 72 0d 20  |3 and 4 of ier. |
00001d70  20 34 30 30 20 20 20 20  20 20 20 20 20 4c 44 58  | 400         LDX|
00001d80  20 6f 6c 64 69 72 71 31  76 20 20 5c 20 6f 72 69  | oldirq1v  \ ori|
00001d90  67 69 6e 61 6c 20 69 72  71 31 20 76 65 63 74 6f  |ginal irq1 vecto|
00001da0  72 2c 20 6c 6f 77 20 62  79 74 65 0d 20 20 34 31  |r, low byte.  41|
00001db0  30 20 20 20 20 20 20 20  20 20 4c 44 59 20 6f 6c  |0         LDY ol|
00001dc0  64 69 72 71 31 76 2b 31  20 5c 20 6f 72 69 67 69  |dirq1v+1 \ origi|
00001dd0  6e 61 6c 20 69 72 71 31  20 76 65 63 74 6f 72 2c  |nal irq1 vector,|
00001de0  20 68 69 67 68 20 62 79  74 65 0d 20 20 34 32 30  | high byte.  420|
00001df0  20 20 20 20 20 20 20 20  20 53 45 49 20 20 20 20  |         SEI    |
00001e00  20 20 20 20 20 20 20 5c  20 73 65 74 20 69 6e 74  |       \ set int|
00001e10  65 72 72 75 70 74 20 64  69 73 61 62 6c 65 20 66  |errupt disable f|
00001e20  6c 61 67 0d 20 20 34 33  30 20 20 20 20 20 20 20  |lag.  430       |
00001e30  20 20 53 54 41 20 69 65  72 20 20 20 20 20 20 20  |  STA ier       |
00001e40  5c 20 69 6e 74 65 72 72  75 70 74 20 65 6e 61 62  |\ interrupt enab|
00001e50  6c 65 20 72 65 67 69 73  74 65 72 0d 20 20 34 34  |le register.  44|
00001e60  30 20 20 20 20 20 20 20  20 20 4c 44 41 20 70 63  |0         LDA pc|
00001e70  72 20 20 20 20 20 20 20  5c 20 70 65 72 69 70 68  |r       \ periph|
00001e80  65 72 61 6c 20 63 6f 6e  74 72 6f 6c 20 72 65 67  |eral control reg|
00001e90  69 73 74 65 72 0d 20 20  34 35 30 20 20 20 20 20  |ister.  450     |
00001ea0  20 20 20 20 41 4e 44 20  23 26 30 46 20 20 20 20  |    AND #&0F    |
00001eb0  20 20 5c 20 63 6c 65 61  72 20 62 69 74 73 20 34  |  \ clear bits 4|
00001ec0  2d 37 0d 20 20 34 36 30  20 20 20 20 20 20 20 20  |-7.  460        |
00001ed0  20 53 54 41 20 70 63 72  20 20 20 20 20 20 20 5c  | STA pcr       \|
00001ee0  20 70 65 72 69 70 68 65  72 61 6c 20 63 6f 6e 74  | peripheral cont|
00001ef0  72 6f 6c 20 72 65 67 69  73 74 65 72 0d 20 20 34  |rol register.  4|
00001f00  37 30 20 20 20 20 20 20  20 20 20 53 54 58 20 69  |70         STX i|
00001f10  72 71 31 76 20 20 20 20  20 5c 20 72 65 73 74 6f  |rq1v     \ resto|
00001f20  72 65 20 74 68 65 20 6f  72 69 67 69 6e 61 6c 20  |re the original |
00001f30  69 72 71 31 20 76 65 63  74 6f 72 2c 20 6c 6f 77  |irq1 vector, low|
00001f40  20 62 79 74 65 0d 20 20  34 38 30 20 20 20 20 20  | byte.  480     |
00001f50  20 20 20 20 53 54 59 20  69 72 71 31 76 2b 31 20  |    STY irq1v+1 |
00001f60  20 20 5c 20 72 65 73 74  6f 72 65 20 74 68 65 20  |  \ restore the |
00001f70  6f 72 69 67 69 6e 61 6c  20 69 72 71 31 20 76 65  |original irq1 ve|
00001f80  63 74 6f 72 2c 20 68 69  67 68 20 62 79 74 65 0d  |ctor, high byte.|
00001f90  20 20 34 39 30 20 20 20  20 20 20 20 20 20 43 4c  |  490         CL|
00001fa0  49 20 20 20 20 20 20 20  20 20 20 20 5c 20 63 6c  |I           \ cl|
00001fb0  65 61 72 20 69 6e 74 65  72 72 75 70 74 20 64 69  |ear interrupt di|
00001fc0  73 61 62 6c 65 20 66 6c  61 67 0d 20 20 35 30 30  |sable flag.  500|
00001fd0  20 20 20 20 20 20 20 20  20 52 54 53 20 20 20 20  |         RTS    |
00001fe0  20 20 20 20 20 20 20 5c  20 72 65 74 75 72 6e 20  |       \ return |
00001ff0  74 6f 20 42 41 53 49 43  0d 20 20 35 31 30 20 2e  |to BASIC.  510 .|
00002000  69 6e 74 65 72 72 75 70  74 0d 20 20 35 32 30 20  |interrupt.  520 |
00002010  20 20 20 20 20 20 20 20  4c 44 41 20 73 61 76 65  |        LDA save|
00002020  72 65 67 20 20 20 5c 20  69 6e 74 65 72 72 75 70  |reg   \ interrup|
00002030  74 20 61 63 63 75 6d 75  6c 61 74 6f 72 20 73 61  |t accumulator sa|
00002040  76 65 20 72 65 67 69 73  74 65 72 0d 20 20 35 33  |ve register.  53|
00002050  30 20 20 20 20 20 20 20  20 20 50 48 41 20 20 20  |0         PHA   |
00002060  20 20 20 20 20 20 20 20  5c 20 61 6e 64 20 70 75  |        \ and pu|
00002070  73 68 20 69 74 20 6f 6e  20 74 68 65 20 73 74 61  |sh it on the sta|
00002080  63 6b 0d 20 20 35 34 30  20 20 20 20 20 20 20 20  |ck.  540        |
00002090  20 4c 44 41 20 69 66 72  20 20 20 20 20 20 20 5c  | LDA ifr       \|
000020a0  20 69 6e 74 65 72 72 75  70 74 20 66 6c 61 67 20  | interrupt flag |
000020b0  72 65 67 69 73 74 65 72  0d 20 20 35 35 30 20 20  |register.  550  |
000020c0  20 20 20 20 20 20 20 42  50 4c 20 6e 6f 74 75 73  |       BPL notus|
000020d0  65 72 20 20 20 5c 20 62  69 74 20 37 20 69 73 20  |er   \ bit 7 is |
000020e0  73 65 74 20 69 66 20 56  49 41 2d 42 20 69 6e 74  |set if VIA-B int|
000020f0  65 72 72 75 70 74 0d 20  20 35 36 30 20 20 20 20  |errupt.  560    |
00002100  20 20 20 20 20 41 4e 44  20 23 26 31 38 20 20 20  |     AND #&18   |
00002110  20 20 20 5c 20 41 4e 44  20 77 69 74 68 20 25 30  |   \ AND with %0|
00002120  30 30 31 31 30 30 30 2c  20 69 65 2e 20 74 65 73  |0011000, ie. tes|
00002130  74 20 62 69 74 73 20 33  20 61 6e 64 20 34 0d 20  |t bits 3 and 4. |
00002140  20 35 37 30 20 20 20 20  20 20 20 20 20 42 45 51  | 570         BEQ|
00002150  20 6e 6f 74 75 73 65 72  20 20 20 5c 20 65 78 69  | notuser   \ exi|
00002160  74 20 69 66 20 6e 6f 74  20 43 42 31 20 6f 72 20  |t if not CB1 or |
00002170  43 42 32 0d 20 20 35 38  30 20 20 20 20 20 20 20  |CB2.  580       |
00002180  20 20 41 4e 44 20 23 26  31 30 20 20 20 20 20 20  |  AND #&10      |
00002190  5c 20 41 4e 44 20 77 69  74 68 20 25 30 30 30 31  |\ AND with %0001|
000021a0  30 30 30 30 2c 20 69 65  2e 20 74 65 73 74 20 43  |0000, ie. test C|
000021b0  42 31 0d 20 20 35 39 30  20 20 20 20 20 20 20 20  |B1.  590        |
000021c0  20 42 4e 45 20 78 70 75  6c 73 65 20 20 20 20 5c  | BNE xpulse    \|
000021d0  20 62 69 74 20 34 20 73  65 74 20 66 6f 72 20 61  | bit 4 set for a|
000021e0  6e 20 58 20 64 69 72 65  63 74 69 6f 6e 20 6d 6f  |n X direction mo|
000021f0  76 65 6d 65 6e 74 0d 20  20 36 30 30 20 20 20 20  |vement.  600    |
00002200  20 20 20 20 20 4c 44 41  20 64 72 62 20 20 20 20  |     LDA drb    |
00002210  20 20 20 5c 20 59 20 64  69 72 65 63 74 69 6f 6e  |   \ Y direction|
00002220  2c 20 6c 6f 61 64 20 64  61 74 61 20 72 65 67 69  |, load data regi|
00002230  73 74 65 72 20 42 0d 20  20 36 31 30 20 20 20 20  |ster B.  610    |
00002240  20 20 20 20 20 41 4e 44  20 23 26 30 34 20 20 20  |     AND #&04   |
00002250  20 20 20 5c 20 41 4e 44  20 77 69 74 68 20 25 30  |   \ AND with %0|
00002260  30 30 30 30 31 30 30 2c  20 69 65 2e 20 74 65 73  |0000100, ie. tes|
00002270  74 20 62 69 74 20 32 0d  20 20 36 32 30 20 20 20  |t bit 2.  620   |
00002280  20 20 20 20 20 20 42 4e  45 20 79 64 6f 77 6e 20  |      BNE ydown |
00002290  20 20 20 20 5c 20 69 66  20 62 69 74 20 32 20 69  |    \ if bit 2 i|
000022a0  73 20 73 65 74 20 74 68  65 6e 20 59 20 69 73 20  |s set then Y is |
000022b0  67 6f 69 6e 67 20 64 6f  77 6e 0d 20 20 36 33 30  |going down.  630|
000022c0  20 20 20 20 20 20 20 20  20 49 4e 43 20 79 63 6f  |         INC yco|
000022d0  6f 72 64 20 20 20 20 5c  20 59 20 69 73 20 67 6f  |ord    \ Y is go|
000022e0  69 6e 67 20 75 70 20 73  6f 20 69 6e 63 72 65 6d  |ing up so increm|
000022f0  65 6e 74 20 59 20 63 6f  6f 72 64 69 6e 61 74 65  |ent Y coordinate|
00002300  0d 20 20 36 34 30 20 20  20 20 20 20 20 20 20 42  |.  640         B|
00002310  4e 45 20 65 78 69 74 20  20 20 20 20 20 5c 20 62  |NE exit      \ b|
00002320  72 61 6e 63 68 20 69 66  20 69 6e 20 74 68 65 20  |ranch if in the |
00002330  72 61 6e 67 65 20 31 20  74 6f 20 32 35 35 0d 20  |range 1 to 255. |
00002340  20 36 35 30 20 20 20 20  20 20 20 20 20 42 45 51  | 650         BEQ|
00002350  20 64 65 63 79 20 20 20  20 20 20 5c 20 69 66 20  | decy      \ if |
00002360  7a 65 72 6f 20 74 68 65  6e 20 61 6c 74 65 72 20  |zero then alter |
00002370  74 6f 20 32 35 35 0d 20  20 36 36 30 20 2e 79 64  |to 255.  660 .yd|
00002380  6f 77 6e 0d 20 20 36 37  30 20 20 20 20 20 20 20  |own.  670       |
00002390  20 20 4c 44 41 20 79 63  6f 6f 72 64 20 20 20 20  |  LDA ycoord    |
000023a0  5c 20 6c 6f 61 64 20 59  20 63 6f 6f 72 64 69 6e  |\ load Y coordin|
000023b0  61 74 65 0d 20 20 36 38  30 20 20 20 20 20 20 20  |ate.  680       |
000023c0  20 20 42 45 51 20 65 78  69 74 20 20 20 20 20 20  |  BEQ exit      |
000023d0  5c 20 62 72 61 6e 63 68  20 69 66 20 7a 65 72 6f  |\ branch if zero|
000023e0  20 62 65 63 61 75 73 65  20 69 74 20 63 61 6e 27  | because it can'|
000023f0  74 20 67 6f 20 61 6e 79  20 6c 6f 77 65 72 0d 20  |t go any lower. |
00002400  20 36 39 30 20 2e 64 65  63 79 0d 20 20 37 30 30  | 690 .decy.  700|
00002410  20 20 20 20 20 20 20 20  20 44 45 43 20 79 63 6f  |         DEC yco|
00002420  6f 72 64 20 20 20 20 5c  20 72 65 64 75 63 65 20  |ord    \ reduce |
00002430  59 20 63 6f 6f 72 64 69  6e 61 74 65 20 62 79 20  |Y coordinate by |
00002440  31 0d 20 20 37 31 30 20  20 20 20 20 20 20 20 20  |1.  710         |
00002450  4a 4d 50 20 65 78 69 74  20 20 20 20 20 20 5c 20  |JMP exit      \ |
00002460  72 65 73 74 6f 72 65 20  69 6e 74 65 72 72 75 70  |restore interrup|
00002470  74 20 61 63 63 75 6d 75  6c 61 74 6f 72 20 73 61  |t accumulator sa|
00002480  76 65 0d 20 20 20 20 20  20 20 20 20 20 20 20 20  |ve.             |
00002490  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 5c  |               \|
000024a0  20 72 65 67 69 73 74 65  72 20 61 6e 64 20 52 54  | register and RT|
000024b0  49 0d 20 20 37 32 30 20  2e 78 70 75 6c 73 65 0d  |I.  720 .xpulse.|
000024c0  20 20 37 33 30 20 20 20  20 20 20 20 20 20 4c 44  |  730         LD|
000024d0  41 20 64 72 62 20 20 20  20 20 20 20 5c 20 64 61  |A drb       \ da|
000024e0  74 61 20 72 65 67 69 73  74 65 72 20 42 0d 20 20  |ta register B.  |
000024f0  37 34 30 20 20 20 20 20  20 20 20 20 52 4f 52 20  |740         ROR |
00002500  41 20 20 20 20 20 20 20  20 20 5c 20 62 69 74 20  |A         \ bit |
00002510  30 20 69 6e 74 6f 20 63  61 72 72 79 0d 20 20 37  |0 into carry.  7|
00002520  35 30 20 20 20 20 20 20  20 20 20 42 43 53 20 78  |50         BCS x|
00002530  64 6f 77 6e 20 20 20 20  20 5c 20 58 20 69 73 20  |down     \ X is |
00002540  67 6f 69 6e 67 20 64 6f  77 6e 20 69 66 20 62 69  |going down if bi|
00002550  74 20 30 20 69 73 20 73  65 74 0d 20 20 37 36 30  |t 0 is set.  760|
00002560  20 20 20 20 20 20 20 20  20 49 4e 43 20 78 63 6f  |         INC xco|
00002570  6f 72 64 20 20 20 20 5c  20 58 20 69 73 20 67 6f  |ord    \ X is go|
00002580  69 6e 67 20 75 70 20 69  66 20 62 69 74 20 30 20  |ing up if bit 0 |
00002590  69 73 20 63 6c 65 61 72  0d 20 20 37 37 30 20 20  |is clear.  770  |
000025a0  20 20 20 20 20 20 20 42  4e 45 20 65 78 69 74 20  |       BNE exit |
000025b0  20 20 20 20 20 5c 20 65  78 69 74 20 69 66 20 58  |     \ exit if X|
000025c0  20 63 6f 6f 72 64 69 6e  61 74 65 20 69 73 20 69  | coordinate is i|
000025d0  6e 20 74 68 65 20 72 61  6e 67 65 0d 20 20 20 20  |n the range.    |
000025e0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
000025f0  20 20 20 20 20 20 20 20  5c 20 66 72 6f 6d 20 31  |        \ from 1|
00002600  20 74 6f 20 32 35 35 0d  20 20 37 38 30 20 20 20  | to 255.  780   |
00002610  20 20 20 20 20 20 42 45  51 20 64 65 63 78 20 20  |      BEQ decx  |
00002620  20 20 20 20 5c 20 69 66  20 58 20 63 6f 6f 72 64  |    \ if X coord|
00002630  69 6e 61 74 65 20 3d 20  30 20 74 68 65 6e 20 6d  |inate = 0 then m|
00002640  61 6b 65 20 69 74 20 32  35 35 0d 20 20 37 39 30  |ake it 255.  790|
00002650  20 2e 78 64 6f 77 6e 0d  20 20 38 30 30 20 20 20  | .xdown.  800   |
00002660  20 20 20 20 20 20 4c 44  41 20 78 63 6f 6f 72 64  |      LDA xcoord|
00002670  20 20 20 20 5c 20 6c 6f  61 64 20 58 20 63 6f 6f  |    \ load X coo|
00002680  72 64 69 6e 61 74 65 0d  20 20 38 31 30 20 20 20  |rdinate.  810   |
00002690  20 20 20 20 20 20 42 45  51 20 65 78 69 74 20 20  |      BEQ exit  |
000026a0  20 20 20 20 5c 20 69 66  20 69 74 20 69 73 20 7a  |    \ if it is z|
000026b0  65 72 6f 20 69 74 20 63  61 6e 27 74 20 67 6f 20  |ero it can't go |
000026c0  61 6e 79 20 6c 6f 77 65  72 0d 20 20 38 32 30 20  |any lower.  820 |
000026d0  2e 64 65 63 78 0d 20 20  38 33 30 20 20 20 20 20  |.decx.  830     |
000026e0  20 20 20 20 44 45 43 20  78 63 6f 6f 72 64 20 20  |    DEC xcoord  |
000026f0  20 20 5c 20 64 65 63 72  65 61 73 65 20 58 20 63  |  \ decrease X c|
00002700  6f 6f 72 64 69 6e 61 74  65 20 62 79 20 31 0d 20  |oordinate by 1. |
00002710  20 38 34 30 20 2e 65 78  69 74 0d 20 20 38 35 30  | 840 .exit.  850|
00002720  20 20 20 20 20 20 20 20  20 50 4c 41 20 20 20 20  |         PLA    |
00002730  20 20 20 20 20 20 20 5c  20 70 75 6c 6c 20 69 6e  |       \ pull in|
00002740  74 65 72 72 75 70 74 20  61 63 63 75 6d 75 6c 61  |terrupt accumula|
00002750  74 6f 72 20 73 61 76 65  0d 20 20 20 20 20 20 20  |tor save.       |
00002760  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00002770  20 20 20 20 20 5c 20 72  65 67 69 73 74 65 72 20  |     \ register |
00002780  6f 66 66 20 74 68 65 20  73 74 61 63 6b 0d 20 20  |off the stack.  |
00002790  38 36 30 20 20 20 20 20  20 20 20 20 53 54 41 20  |860         STA |
000027a0  73 61 76 65 72 65 67 20  20 20 5c 20 61 6e 64 20  |savereg   \ and |
000027b0  72 65 73 74 6f 72 65 20  7a 65 72 6f 20 70 61 67  |restore zero pag|
000027c0  65 0d 20 20 38 37 30 20  20 20 20 20 20 20 20 20  |e.  870         |
000027d0  52 54 49 20 20 20 20 20  20 20 20 20 20 20 5c 20  |RTI           \ |
000027e0  72 65 74 75 72 6e 20 66  72 6f 6d 20 69 6e 74 65  |return from inte|
000027f0  72 72 75 70 74 0d 20 20  38 38 30 20 2e 6e 6f 74  |rrupt.  880 .not|
00002800  75 73 65 72 0d 20 20 38  39 30 20 20 20 20 20 20  |user.  890      |
00002810  20 20 20 50 4c 41 20 20  20 20 20 20 20 20 20 20  |   PLA          |
00002820  20 5c 20 70 75 6c 6c 20  74 68 65 20 69 6e 74 65  | \ pull the inte|
00002830  72 72 75 70 74 20 61 63  63 75 6d 75 6c 61 74 6f  |rrupt accumulato|
00002840  72 20 73 61 76 65 0d 20  20 20 20 20 20 20 20 20  |r save.         |
00002850  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00002860  20 20 20 5c 20 72 65 67  69 73 74 65 72 20 6f 66  |   \ register of|
00002870  66 20 74 68 65 20 73 74  61 63 6b 0d 20 20 39 30  |f the stack.  90|
00002880  30 20 20 20 20 20 20 20  20 20 53 54 41 20 73 61  |0         STA sa|
00002890  76 65 72 65 67 20 20 20  5c 20 72 65 73 74 6f 72  |vereg   \ restor|
000028a0  65 20 74 68 65 20 7a 65  72 6f 20 70 61 67 65 20  |e the zero page |
000028b0  61 64 64 72 65 73 73 0d  20 20 39 31 30 20 20 20  |address.  910   |
000028c0  20 20 20 20 20 20 4a 4d  50 20 28 6f 6c 64 69 72  |      JMP (oldir|
000028d0  71 31 76 29 20 5c 20 65  78 69 74 20 76 69 61 20  |q1v) \ exit via |
000028e0  74 68 65 20 6f 72 69 67  69 6e 61 6c 20 76 65 63  |the original vec|
000028f0  74 6f 72 0d 20 20 39 32  30 20 2e 6f 6c 64 69 72  |tor.  920 .oldir|
00002900  71 31 76 0d 20 20 39 33  30 20 20 20 20 20 20 20  |q1v.  930       |
00002910  20 20 45 51 55 57 20 26  30 30 20 20 20 20 20 20  |  EQUW &00      |
00002920  5c 20 6f 72 69 67 69 6e  61 6c 20 69 72 71 31 76  |\ original irq1v|
00002930  0d 20 20 39 34 30 20 2e  6c 61 73 74 62 79 74 65  |.  940 .lastbyte|
00002940  0d 20 20 39 35 30 20 5d  0d 20 20 39 36 30 20 4e  |.  950 ].  960 N|
00002950  45 58 54 0d 20 20 39 37  30 20 43 41 4c 4c 20 6d  |EXT.  970 CALL m|
00002960  63 6f 64 65 0d 20 20 39  38 30 20 4d 4f 44 45 37  |code.  980 MODE7|
00002970  0d 20 20 39 39 30 20 6d  6f 75 73 65 24 3d 43 48  |.  990 mouse$=CH|
00002980  52 24 31 34 31 2b 43 48  52 24 31 33 32 2b 43 48  |R$141+CHR$132+CH|
00002990  52 24 31 35 37 2b 43 48  52 24 31 33 31 2b 0d 20  |R$157+CHR$131+. |
000029a0  20 20 20 20 20 22 4d 6f  75 73 65 20 63 6f 6f 72  |     "Mouse coor|
000029b0  64 69 6e 61 74 65 73 2c  20 72 61 6e 67 65 20 26  |dinates, range &|
000029c0  30 30 2d 26 46 46 20 20  22 2b 43 48 52 24 31 35  |00-&FF  "+CHR$15|
000029d0  36 0d 20 31 30 30 30 20  50 52 49 4e 54 54 41 42  |6. 1000 PRINTTAB|
000029e0  28 30 2c 31 29 6d 6f 75  73 65 24 0d 20 31 30 31  |(0,1)mouse$. 101|
000029f0  30 20 50 52 49 4e 54 54  41 42 28 30 2c 32 29 6d  |0 PRINTTAB(0,2)m|
00002a00  6f 75 73 65 24 0d 20 31  30 32 30 20 56 44 55 32  |ouse$. 1020 VDU2|
00002a10  33 2c 31 2c 30 3b 30 3b  30 3b 30 3b 0d 20 31 30  |3,1,0;0;0;0;. 10|
00002a20  33 30 20 4f 4e 45 52 52  4f 52 20 47 4f 54 4f 20  |30 ONERROR GOTO |
00002a30  31 31 32 30 0d 20 31 30  34 30 20 50 52 49 4e 54  |1120. 1040 PRINT|
00002a40  54 41 42 28 31 30 2c 37  29 22 42 79 74 65 73 20  |TAB(10,7)"Bytes |
00002a50  75 73 65 64 20 3d 20 26  22 3b 7e 6c 61 73 74 62  |used = &";~lastb|
00002a60  79 74 65 2d 6d 63 6f 64  65 0d 20 31 30 35 30 20  |yte-mcode. 1050 |
00002a70  52 45 50 45 41 54 0d 20  31 30 36 30 20 50 52 49  |REPEAT. 1060 PRI|
00002a80  4e 54 54 41 42 28 31 30  2c 31 32 29 22 58 20 3d  |NTTAB(10,12)"X =|
00002a90  20 26 22 3b 7e 3f 26 38  30 3b 22 20 22 54 41 42  | &";~?&80;" "TAB|
00002aa0  28 32 30 2c 31 32 29 3b  22 59 20 3d 20 26 22 3b  |(20,12);"Y = &";|
00002ab0  7e 3f 26 38 31 3b 22 20  22 0d 20 31 30 37 30 20  |~?&81;" ". 1070 |
00002ac0  62 75 74 74 6f 6e 3d 3f  64 72 62 20 3a 52 45 4d  |button=?drb :REM|
00002ad0  3a 20 64 61 74 61 20 72  65 67 69 73 74 65 72 20  |: data register |
00002ae0  42 0d 20 31 30 38 30 20  49 46 20 28 62 75 74 74  |B. 1080 IF (butt|
00002af0  6f 6e 20 41 4e 44 20 26  38 30 29 3d 30 20 50 52  |on AND &80)=0 PR|
00002b00  49 4e 54 54 41 42 28 32  32 2c 31 37 29 22 52 69  |INTTAB(22,17)"Ri|
00002b10  67 68 74 22 0d 20 20 20  20 20 20 45 4c 53 45 20  |ght".      ELSE |
00002b20  50 52 49 4e 54 54 41 42  28 32 32 2c 31 37 29 22  |PRINTTAB(22,17)"|
00002b30  20 20 20 20 20 22 0d 20  31 30 39 30 20 49 46 20  |     ". 1090 IF |
00002b40  28 62 75 74 74 6f 6e 20  41 4e 44 20 26 34 30 29  |(button AND &40)|
00002b50  3d 30 20 50 52 49 4e 54  54 41 42 28 31 35 2c 31  |=0 PRINTTAB(15,1|
00002b60  37 29 22 43 65 6e 74 72  65 22 0d 20 20 20 20 20  |7)"Centre".     |
00002b70  20 45 4c 53 45 20 50 52  49 4e 54 54 41 42 28 31  | ELSE PRINTTAB(1|
00002b80  35 2c 31 37 29 22 20 20  20 20 20 20 22 0d 20 31  |5,17)"      ". 1|
00002b90  31 30 30 20 49 46 20 28  62 75 74 74 6f 6e 20 41  |100 IF (button A|
00002ba0  4e 44 20 26 32 30 29 3d  30 20 50 52 49 4e 54 54  |ND &20)=0 PRINTT|
00002bb0  41 42 28 31 30 2c 31 37  29 22 4c 65 66 74 22 0d  |AB(10,17)"Left".|
00002bc0  20 20 20 20 20 20 45 4c  53 45 20 50 52 49 4e 54  |      ELSE PRINT|
00002bd0  54 41 42 28 31 30 2c 31  37 29 22 20 20 20 20 22  |TAB(10,17)"    "|
00002be0  0d 20 31 31 31 30 20 55  4e 54 49 4c 20 46 41 4c  |. 1110 UNTIL FAL|
00002bf0  53 45 0d 20 31 31 32 30  20 56 44 55 32 33 2c 31  |SE. 1120 VDU23,1|
00002c00  2c 31 3b 30 3b 30 3b 30  3b 0d 20 31 31 33 30 20  |,1;0;0;0;. 1130 |
00002c10  43 41 4c 4c 20 6d 63 6f  64 65 0d                 |CALL mcode.|
00002c1b
27-11-88/T\MOU01.m0
27-11-88/T\MOU01.m1
27-11-88/T\MOU01.m2
27-11-88/T\MOU01.m4
27-11-88/T\MOU01.m5