Home » CEEFAX disks » telesoftware11.adl » 11-12-88/T\MOU03

11-12-88/T\MOU03

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: 11-12-88/T\MOU03
Read OK:
File size: 33DB bytes
Load address: 0000
Exec address: 0000
File contents
Using a mouse with the BBC microcomputer - by - Gordon Horsington
-----------------------------------------------------------------

Module 3. Reading the mouse buttons
-----------------------------------

The status of the mouse buttons can be read from data register B (DRB,
&FE60) if the data direction register B (DDRB, &FE62) is first cleared to
zero to make DRB an input. The mouse buttons are not connected to a
handshake line and do not produce an IRQ interrupt. For this reason the
buttons are read by polling the DRB. It is quite undesirable to poll this
register continuously and far better to either poll it at set intervals or
poll it whenever the keyboard is scanned for a keypress. Both these ideas
will be demonstrated in this module.

If the DRB is polled at set intervals then the intervals should be chosen
to be most suitable for the particular application. If the mouse buttons
are to be used as an addition to the keyboard to provide, for example,
three extra function keys, then the DRB needs to be polled about four
times a second. This gives a quick response but does not repeat before the
user can take his finger off the button.

The program EVENT demonstrates how the interval timer can be used to
generate the timer crossing zero event at 0.25 second intervals. This
event is used to poll the DRB and insert an "R" into the keyboard buffer
if the right mouse button is pressed, a "C" if the centre button is
pressed and an "L" if the left button is pressed. I have used the interval
timer in this demonstration, rather than use one of the VIA timers to
produce an interrupt, because the polling routine uses an Osbyte call to
insert a character into the keyboard buffer. Operating system calls must
not be used by interrupt routines but they can be used by event handling
routines running in the I/O processor.

The interval timer uses a five byte number which is incremented every
centisecond. One centisecond after the timer reaches &FFFFFFFFFF it is
incremented and crosses zero. If the timer crossing zero event is enabled
this generates event number 5.

To find the number with which to seed the timer use BASIC to print the
negative hexadecimal value of the number of centiseconds in the required
interval. For example, if an interval of 0.25 seconds is required then
type:

  PRINT ~ -25

and BASIC will give the four least significant bytes of the asnswer:

  FFFFFFE7

you can then add the most significant byte which, in this application
will always be &FF, to give &FFFFFFFFE7. The interval used by the
demonstration program is 0.25 seconds and the five byte number is
specified in lines 890 and 900 of EVENT.

Event number 5 is enabled with Osbyte 14, X=5, and disabled with Osbyte
13, X=5, Y=0. Osword 4 is used to write to the timer when the routine is
initialised and again after processing event 5 when it is used to restart
the timer for the next interval.

Chain the program EVENT and press the mouse buttons. The program can be
modified to enter a string of characters into the keyboard buffer rather
than just one character and this will have the effect of producing extra
function keys.


   10 REM> EVENT
   20 DIM mcode &100 :REM: machine code at mcode
   30 evntv=&220 :REM: event vector
   40 drb=&FE60 :REM: data register B
   50 ddrb=&FE62 :REM: data direction register B
   60 osword=&FFF1
   70 osbyte=&FFF4
   80 FOR pass=0 TO 2 STEP 2
   90 P%=mcode
  100 [       OPT pass
  110         LDX evntv
  120         LDY evntv+1
  130         CPY #timeout DIV 256
  140         BEQ disable   \ branch if event vector altered
  150         STX oldevntv  \ store original event vector
  160         STY oldevntv+1
  170         LDX #timeout MOD 256
  180         LDY #timeout DIV 256
  190         STX evntv     \ install new event vector
  200         STY evntv+1
  210         LDA #0        \ user port input
  220         STA ddrb      \ data direction register B
  230         LDA #&0E      \ enable events
  240         LDX #&05      \ interval timer crossing zero
  250         JSR osbyte
  260 .writetimer
  270         LDA #&04      \ write interval timer
  280         LDX #clock MOD 256
  290         LDY #clock DIV 256
  300         JMP osword    \ Osword and return
  310 .disable
  320         LDA #&0D      \ disable events
  330         LDX #&05      \ interval timer crossing zero
  340         LDY #&00
  350         JSR osbyte
  360         LDX oldevntv  \ restore event vector
  370         LDY oldevntv+1
  380         STX evntv
  390         STY evntv+1
  400         RTS           \ return to BASIC
  410 .timeout
  420         PHP           \ push status register
  430         CMP #&05      \ is this interval timer crossing zero?
  440         BEQ interval  \ branch if it is
  450         PLP           \ restore status register
  460         JMP (oldevntv) \ exit via original vector
  470 .interval
  480         PHA           \ store A
  490         TXA
  500         PHA           \ store X
  510         TYA
  520         PHA           \ store Y
  530         LDA drb       \ data register B
  540         ROL A         \ bit 7 into carry
  550         BCC right     \ branch if right button pressed
  560         ROL A         \ bit 6 into carry
  570         BCC centre    \ branch if centre button pressed
  580         ROL A         \ bit 5 into carry
  590         BCS pullout   \ exit if left button not pressed
  600         LDY leftkey   \ left button pressed
  610         BNE intobuffer
  620 .centre
  630         LDY centrekey
  640         BNE intobuffer
  650 .right
  660         LDY rightkey
  670 .intobuffer
  680         LDA #&8A      \ insert value into buffer
  690         LDX #&00      \ keyboard buffer
  700         JSR osbyte
  710 .pullout
  720         JSR writetimer \ reset timer
  730         PLA
  740         TAY           \ restore Y
  750         PLA
  760         TAX           \ restore X
  770         PLA
  780         PLP
  790         RTS
  800 .leftkey
  810         EQUB ASC("L")
  820 .centrekey
  830         EQUB ASC("C")
  840 .rightkey
  850         EQUB ASC("R")
  860 .oldevntv
  870         EQUW &00
  880 .clock
  890         EQUD &FFFFFFE7
  900         EQUB &FF
  910 ]
  920 NEXT
  930 CALL mcode


The program BUTTONS demonstrates a second method of polling the DRB to see
if any of the mouse buttons are pressed. In this program the INKEY
function is intercepted so that the mouse buttons can be tested as if they
are keys on the keyboard.

The BASIC function INKEY with a negative number in the brackets, eg.
INKEY(-74), can be used to test whether a particular key is pressed when
the function is called. The INKEY function is executed via the Osbyte
indirection vector using Osbyte &81 with X = the (negative) INKEY value
and Y = &FF. The function can be intercepted by redirecting the Osbyte
vector to a new INKEY routine. The program BUTTONS duplicates the negative
INKEY function for the Z, X and Return keys so that these key can be
scanned both on the keyboard and on the mouse.

The revectored Osbyte indirection vector used in BUTTONS points to the
code labeled newinkey which checks to see if a negative INKEY function is
being executed. If it is not a negative INKEY then the new routine exits
via the original Osbyte vector. If a negative INKEY is being executed then
the new routine first of all executes the original code to see if the
required keyboard button is pressed. If it is then the new routine returns
control to the operating system. If the key being scanned is not pressed
on the keyboard then the new routine checks to see if the key is one which
has been allocated to one of the mouse buttons. If it is then the DRB is
polled to see if the appropriate mouse button is pressed.

If the required mouse button is pressed then a return from Osbyte &81 is
made with both the X=&FF and Y=&FF. This has the effect of simulating a
TRUE return from the negative INKEY function. If the required mouse button
is not pressed then the return from Osbyte &81 has the X and Y registers
storing the same numbers with which they returned from the original INKEY
routine and this has the effect of a FALSE return from the function.

Chain the program BUTTONS and press either the Z, X or Return keys on the
keyboard or the mouse buttons. The technique demonstrated in the program
is probably the most useful one to use if you want to use the mouse
buttons for arcade type games. This type of game often uses the negative
INKEY or its machine code equivalent to scan the keyboard and by using the
ideas demonstrated in the program the game player will be able to use
either the keyboard or the mouse buttons or even both at the same time.

You have already been shown how to detect and record the movement of a
mouse. In module 4 I will demonstrate how the stored X and Y coordinates
can be used with a modified version of the negative INKEY technique so
that mouse movement can become a substitute for pressing the cursor keys.


   10 REM> BUTTONS
   20 DIM mcode &100 :REM: machine code at mcode
   30 bytev=&20A :REM: Osbyte indirection vector
   40 drb=&FE60 :REM: data register B
   50 ddrb=&FE62 :REM: data direction register B
   60 FOR pass=0 TO 2 STEP 2
   70 P%=mcode
   80 [       OPT pass
   90         LDX bytev
  100         LDY bytev+1
  110         CPY #newinkey DIV 256
  120         BEQ disable   \ branch if Osbyte vector altered
  130         STX oldbytev  \ store original Osbyte vector
  140         STY oldbytev+1
  150         LDX #newinkey MOD 256
  160         LDY #newinkey DIV 256
  170         STX bytev     \ install new Osbyte vector
  180         STY bytev+1
  190         LDA #0        \ user port input
  200         STA ddrb      \ data direction register B
  210         RTS           \ return to BASIC
  220 .disable
  230         LDX oldbytev  \ restore Osbyte indirection vector
  240         LDY oldbytev+1
  250         STX bytev
  260         STY bytev+1
  270         RTS           \ return to BASIC
  280 .newinkey
  290         PHP           \ push status register
  300         CMP #&81      \ is this Osbyte &81?
  310         BNE notinkey  \ branch if not Osbyte &81
  320         CPY #&FF      \ is this a -ve INKEY?
  330         BEQ inkey     \ branch if -ve INKEY
  340 .notinkey
  350         PLP           \ pull status register
  360 .oldcode
  370         JMP (oldbytev) \ exit via original vector
  380 .inkey
  390         TXA           \ -ve INKEY value in X register
  400         PHA           \ push X onto stack
  410         LDA #&81
  420         JSR oldcode   \ execute original code
  430         CPX #&FF      \ key pressed if X and Y =&FF
  440         BNE notpressed \ branch if key not pressed
  450         CPY #&FF      \ key pressed if X and Y =&FF
  460         BNE notpressed \ branch if key not pressed
  470         PLA           \ pull X off stack
  480 .pullout
  490         LDA #&81      \ restore A
  500         PLP           \ restore status register
  510         RTS           \ return to operating system
  520 .notpressed
  530         PLA           \ pull -ve INKEY number off stack
  540         CMP centre    \ compare with number allocated to centre
                            \ mouse button
  550         BNE tryright  \ branch if not centre button
  560         LDA drb       \ data register B
  570         JMP two       \ check bit 6
  580 .tryright
  590         CMP right     \ compare with number allocated to right
                            \ mouse button
  600         BNE tryleft   \ branch if not right button
  610         LDA drb       \ data register B
  620         JMP one       \ check bit 7
  630 .tryleft
  640         CMP left      \ compare with number allocated to left
                            \ mouse button
  650         BNE pullout   \ exit if not left button
  660         LDA drb       \ data register B
  670         ROL A         \ bit 7 into carry
  680 .two
  690         ROL A         \ bit 6/7 into carry
  700 .one
  710         ROL A         \ bit 5/6/7 into carry
  720         BCS pullout   \ exit if bit 5/6/7 set
  730 .found
  740         LDA #&81      \ Osbyte &81
  750         LDX #&FF      \ X and Y = &FF when key pressed
  760         LDY #&FF
  770         PLP           \ pull status register
  780         RTS           \ return to operating system
  790 .oldbytev
  800         EQUW &00      \ original Osbyte indirection vector
  810 .right
  820         EQUB -67      \ -ve INKEY for X
  830 .centre
  840         EQUB -74      \ -ve INKEY for <return>
  850 .left
  860         EQUB -98      \ -ve INKEY for Z
  870 .lastbyte
  880 ]
  890 NEXT
  900 CALL mcode :REM: enable new code
  910 MODE7
  920 mouse$=CHR$141+CHR$132+CHR$157+CHR$131
      +"Press keyboard or mouse buttons  "+CHR$156
  930 PRINTTAB(0,2)mouse$
  940 PRINTTAB(0,3)mouse$
  950 ONERROR GOTO 1030
  960 VDU23,1,0;0;0;0;
  970 REPEAT
  980 IF INKEY(-67) PRINTTAB(26,12)"X" ELSE PRINTTAB(26,12)" "
  990 IF INKEY(-74) PRINTTAB(16,12)"Return" ELSE PRINTTAB(16,12)"      "
 1000 IF INKEY(-98) PRINTTAB(11,12)"Z" ELSE PRINTTAB(11,12)" "
 1010 IF INKEY(-99) PRINTTAB(16,17)"Space" ELSE PRINTTAB(16,17)"     "
 1020 UNTIL FALSE
 1030 CALL mcode :REM: disable new code
 1040 VDU23,1,1;0;0;0;31,0,23
 1050 END
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 33 2e 20 52  |---..Module 3. R|
00000090  65 61 64 69 6e 67 20 74  68 65 20 6d 6f 75 73 65  |eading the mouse|
000000a0  20 62 75 74 74 6f 6e 73  0d 2d 2d 2d 2d 2d 2d 2d  | buttons.-------|
000000b0  2d 2d 2d 2d 2d 2d 2d 2d  2d 2d 2d 2d 2d 2d 2d 2d  |----------------|
000000c0  2d 2d 2d 2d 2d 2d 2d 2d  2d 2d 2d 2d 0d 0d 54 68  |------------..Th|
000000d0  65 20 73 74 61 74 75 73  20 6f 66 20 74 68 65 20  |e status of the |
000000e0  6d 6f 75 73 65 20 62 75  74 74 6f 6e 73 20 63 61  |mouse buttons ca|
000000f0  6e 20 62 65 20 72 65 61  64 20 66 72 6f 6d 20 64  |n be read from d|
00000100  61 74 61 20 72 65 67 69  73 74 65 72 20 42 20 28  |ata register B (|
00000110  44 52 42 2c 0d 26 46 45  36 30 29 20 69 66 20 74  |DRB,.&FE60) if t|
00000120  68 65 20 64 61 74 61 20  64 69 72 65 63 74 69 6f  |he data directio|
00000130  6e 20 72 65 67 69 73 74  65 72 20 42 20 28 44 44  |n register B (DD|
00000140  52 42 2c 20 26 46 45 36  32 29 20 69 73 20 66 69  |RB, &FE62) is fi|
00000150  72 73 74 20 63 6c 65 61  72 65 64 20 74 6f 0d 7a  |rst cleared to.z|
00000160  65 72 6f 20 74 6f 20 6d  61 6b 65 20 44 52 42 20  |ero to make DRB |
00000170  61 6e 20 69 6e 70 75 74  2e 20 54 68 65 20 6d 6f  |an input. The mo|
00000180  75 73 65 20 62 75 74 74  6f 6e 73 20 61 72 65 20  |use buttons are |
00000190  6e 6f 74 20 63 6f 6e 6e  65 63 74 65 64 20 74 6f  |not connected to|
000001a0  20 61 0d 68 61 6e 64 73  68 61 6b 65 20 6c 69 6e  | a.handshake lin|
000001b0  65 20 61 6e 64 20 64 6f  20 6e 6f 74 20 70 72 6f  |e and do not pro|
000001c0  64 75 63 65 20 61 6e 20  49 52 51 20 69 6e 74 65  |duce an IRQ inte|
000001d0  72 72 75 70 74 2e 20 46  6f 72 20 74 68 69 73 20  |rrupt. For this |
000001e0  72 65 61 73 6f 6e 20 74  68 65 0d 62 75 74 74 6f  |reason the.butto|
000001f0  6e 73 20 61 72 65 20 72  65 61 64 20 62 79 20 70  |ns are read by p|
00000200  6f 6c 6c 69 6e 67 20 74  68 65 20 44 52 42 2e 20  |olling the DRB. |
00000210  49 74 20 69 73 20 71 75  69 74 65 20 75 6e 64 65  |It is quite unde|
00000220  73 69 72 61 62 6c 65 20  74 6f 20 70 6f 6c 6c 20  |sirable to poll |
00000230  74 68 69 73 0d 72 65 67  69 73 74 65 72 20 63 6f  |this.register co|
00000240  6e 74 69 6e 75 6f 75 73  6c 79 20 61 6e 64 20 66  |ntinuously and f|
00000250  61 72 20 62 65 74 74 65  72 20 74 6f 20 65 69 74  |ar better to eit|
00000260  68 65 72 20 70 6f 6c 6c  20 69 74 20 61 74 20 73  |her poll it at s|
00000270  65 74 20 69 6e 74 65 72  76 61 6c 73 20 6f 72 0d  |et intervals or.|
00000280  70 6f 6c 6c 20 69 74 20  77 68 65 6e 65 76 65 72  |poll it whenever|
00000290  20 74 68 65 20 6b 65 79  62 6f 61 72 64 20 69 73  | the keyboard is|
000002a0  20 73 63 61 6e 6e 65 64  20 66 6f 72 20 61 20 6b  | scanned for a k|
000002b0  65 79 70 72 65 73 73 2e  20 42 6f 74 68 20 74 68  |eypress. Both th|
000002c0  65 73 65 20 69 64 65 61  73 0d 77 69 6c 6c 20 62  |ese ideas.will b|
000002d0  65 20 64 65 6d 6f 6e 73  74 72 61 74 65 64 20 69  |e demonstrated i|
000002e0  6e 20 74 68 69 73 20 6d  6f 64 75 6c 65 2e 0d 0d  |n this module...|
000002f0  49 66 20 74 68 65 20 44  52 42 20 69 73 20 70 6f  |If the DRB is po|
00000300  6c 6c 65 64 20 61 74 20  73 65 74 20 69 6e 74 65  |lled at set inte|
00000310  72 76 61 6c 73 20 74 68  65 6e 20 74 68 65 20 69  |rvals then the i|
00000320  6e 74 65 72 76 61 6c 73  20 73 68 6f 75 6c 64 20  |ntervals should |
00000330  62 65 20 63 68 6f 73 65  6e 0d 74 6f 20 62 65 20  |be chosen.to be |
00000340  6d 6f 73 74 20 73 75 69  74 61 62 6c 65 20 66 6f  |most suitable fo|
00000350  72 20 74 68 65 20 70 61  72 74 69 63 75 6c 61 72  |r the particular|
00000360  20 61 70 70 6c 69 63 61  74 69 6f 6e 2e 20 49 66  | application. If|
00000370  20 74 68 65 20 6d 6f 75  73 65 20 62 75 74 74 6f  | the mouse butto|
00000380  6e 73 0d 61 72 65 20 74  6f 20 62 65 20 75 73 65  |ns.are to be use|
00000390  64 20 61 73 20 61 6e 20  61 64 64 69 74 69 6f 6e  |d as an addition|
000003a0  20 74 6f 20 74 68 65 20  6b 65 79 62 6f 61 72 64  | to the keyboard|
000003b0  20 74 6f 20 70 72 6f 76  69 64 65 2c 20 66 6f 72  | to provide, for|
000003c0  20 65 78 61 6d 70 6c 65  2c 0d 74 68 72 65 65 20  | example,.three |
000003d0  65 78 74 72 61 20 66 75  6e 63 74 69 6f 6e 20 6b  |extra function k|
000003e0  65 79 73 2c 20 74 68 65  6e 20 74 68 65 20 44 52  |eys, then the DR|
000003f0  42 20 6e 65 65 64 73 20  74 6f 20 62 65 20 70 6f  |B needs to be po|
00000400  6c 6c 65 64 20 61 62 6f  75 74 20 66 6f 75 72 0d  |lled about four.|
00000410  74 69 6d 65 73 20 61 20  73 65 63 6f 6e 64 2e 20  |times a second. |
00000420  54 68 69 73 20 67 69 76  65 73 20 61 20 71 75 69  |This gives a qui|
00000430  63 6b 20 72 65 73 70 6f  6e 73 65 20 62 75 74 20  |ck response but |
00000440  64 6f 65 73 20 6e 6f 74  20 72 65 70 65 61 74 20  |does not repeat |
00000450  62 65 66 6f 72 65 20 74  68 65 0d 75 73 65 72 20  |before the.user |
00000460  63 61 6e 20 74 61 6b 65  20 68 69 73 20 66 69 6e  |can take his fin|
00000470  67 65 72 20 6f 66 66 20  74 68 65 20 62 75 74 74  |ger off the butt|
00000480  6f 6e 2e 0d 0d 54 68 65  20 70 72 6f 67 72 61 6d  |on...The program|
00000490  20 45 56 45 4e 54 20 64  65 6d 6f 6e 73 74 72 61  | EVENT demonstra|
000004a0  74 65 73 20 68 6f 77 20  74 68 65 20 69 6e 74 65  |tes how the inte|
000004b0  72 76 61 6c 20 74 69 6d  65 72 20 63 61 6e 20 62  |rval timer can b|
000004c0  65 20 75 73 65 64 20 74  6f 0d 67 65 6e 65 72 61  |e used to.genera|
000004d0  74 65 20 74 68 65 20 74  69 6d 65 72 20 63 72 6f  |te the timer cro|
000004e0  73 73 69 6e 67 20 7a 65  72 6f 20 65 76 65 6e 74  |ssing zero event|
000004f0  20 61 74 20 30 2e 32 35  20 73 65 63 6f 6e 64 20  | at 0.25 second |
00000500  69 6e 74 65 72 76 61 6c  73 2e 20 54 68 69 73 0d  |intervals. This.|
00000510  65 76 65 6e 74 20 69 73  20 75 73 65 64 20 74 6f  |event is used to|
00000520  20 70 6f 6c 6c 20 74 68  65 20 44 52 42 20 61 6e  | poll the DRB an|
00000530  64 20 69 6e 73 65 72 74  20 61 6e 20 22 52 22 20  |d insert an "R" |
00000540  69 6e 74 6f 20 74 68 65  20 6b 65 79 62 6f 61 72  |into the keyboar|
00000550  64 20 62 75 66 66 65 72  0d 69 66 20 74 68 65 20  |d buffer.if the |
00000560  72 69 67 68 74 20 6d 6f  75 73 65 20 62 75 74 74  |right mouse butt|
00000570  6f 6e 20 69 73 20 70 72  65 73 73 65 64 2c 20 61  |on is pressed, a|
00000580  20 22 43 22 20 69 66 20  74 68 65 20 63 65 6e 74  | "C" if the cent|
00000590  72 65 20 62 75 74 74 6f  6e 20 69 73 0d 70 72 65  |re button is.pre|
000005a0  73 73 65 64 20 61 6e 64  20 61 6e 20 22 4c 22 20  |ssed and an "L" |
000005b0  69 66 20 74 68 65 20 6c  65 66 74 20 62 75 74 74  |if the left butt|
000005c0  6f 6e 20 69 73 20 70 72  65 73 73 65 64 2e 20 49  |on is pressed. I|
000005d0  20 68 61 76 65 20 75 73  65 64 20 74 68 65 20 69  | have used the i|
000005e0  6e 74 65 72 76 61 6c 0d  74 69 6d 65 72 20 69 6e  |nterval.timer in|
000005f0  20 74 68 69 73 20 64 65  6d 6f 6e 73 74 72 61 74  | this demonstrat|
00000600  69 6f 6e 2c 20 72 61 74  68 65 72 20 74 68 61 6e  |ion, rather than|
00000610  20 75 73 65 20 6f 6e 65  20 6f 66 20 74 68 65 20  | use one of the |
00000620  56 49 41 20 74 69 6d 65  72 73 20 74 6f 0d 70 72  |VIA timers to.pr|
00000630  6f 64 75 63 65 20 61 6e  20 69 6e 74 65 72 72 75  |oduce an interru|
00000640  70 74 2c 20 62 65 63 61  75 73 65 20 74 68 65 20  |pt, because the |
00000650  70 6f 6c 6c 69 6e 67 20  72 6f 75 74 69 6e 65 20  |polling routine |
00000660  75 73 65 73 20 61 6e 20  4f 73 62 79 74 65 20 63  |uses an Osbyte c|
00000670  61 6c 6c 20 74 6f 0d 69  6e 73 65 72 74 20 61 20  |all to.insert a |
00000680  63 68 61 72 61 63 74 65  72 20 69 6e 74 6f 20 74  |character into t|
00000690  68 65 20 6b 65 79 62 6f  61 72 64 20 62 75 66 66  |he keyboard buff|
000006a0  65 72 2e 20 4f 70 65 72  61 74 69 6e 67 20 73 79  |er. Operating sy|
000006b0  73 74 65 6d 20 63 61 6c  6c 73 20 6d 75 73 74 0d  |stem calls must.|
000006c0  6e 6f 74 20 62 65 20 75  73 65 64 20 62 79 20 69  |not be used by i|
000006d0  6e 74 65 72 72 75 70 74  20 72 6f 75 74 69 6e 65  |nterrupt routine|
000006e0  73 20 62 75 74 20 74 68  65 79 20 63 61 6e 20 62  |s but they can b|
000006f0  65 20 75 73 65 64 20 62  79 20 65 76 65 6e 74 20  |e used by event |
00000700  68 61 6e 64 6c 69 6e 67  0d 72 6f 75 74 69 6e 65  |handling.routine|
00000710  73 20 72 75 6e 6e 69 6e  67 20 69 6e 20 74 68 65  |s running in the|
00000720  20 49 2f 4f 20 70 72 6f  63 65 73 73 6f 72 2e 0d  | I/O processor..|
00000730  0d 54 68 65 20 69 6e 74  65 72 76 61 6c 20 74 69  |.The interval ti|
00000740  6d 65 72 20 75 73 65 73  20 61 20 66 69 76 65 20  |mer uses a five |
00000750  62 79 74 65 20 6e 75 6d  62 65 72 20 77 68 69 63  |byte number whic|
00000760  68 20 69 73 20 69 6e 63  72 65 6d 65 6e 74 65 64  |h is incremented|
00000770  20 65 76 65 72 79 0d 63  65 6e 74 69 73 65 63 6f  | every.centiseco|
00000780  6e 64 2e 20 4f 6e 65 20  63 65 6e 74 69 73 65 63  |nd. One centisec|
00000790  6f 6e 64 20 61 66 74 65  72 20 74 68 65 20 74 69  |ond after the ti|
000007a0  6d 65 72 20 72 65 61 63  68 65 73 20 26 46 46 46  |mer reaches &FFF|
000007b0  46 46 46 46 46 46 46 20  69 74 20 69 73 0d 69 6e  |FFFFFFF it is.in|
000007c0  63 72 65 6d 65 6e 74 65  64 20 61 6e 64 20 63 72  |cremented and cr|
000007d0  6f 73 73 65 73 20 7a 65  72 6f 2e 20 49 66 20 74  |osses zero. If t|
000007e0  68 65 20 74 69 6d 65 72  20 63 72 6f 73 73 69 6e  |he timer crossin|
000007f0  67 20 7a 65 72 6f 20 65  76 65 6e 74 20 69 73 20  |g zero event is |
00000800  65 6e 61 62 6c 65 64 0d  74 68 69 73 20 67 65 6e  |enabled.this gen|
00000810  65 72 61 74 65 73 20 65  76 65 6e 74 20 6e 75 6d  |erates event num|
00000820  62 65 72 20 35 2e 0d 0d  54 6f 20 66 69 6e 64 20  |ber 5...To find |
00000830  74 68 65 20 6e 75 6d 62  65 72 20 77 69 74 68 20  |the number with |
00000840  77 68 69 63 68 20 74 6f  20 73 65 65 64 20 74 68  |which to seed th|
00000850  65 20 74 69 6d 65 72 20  75 73 65 20 42 41 53 49  |e timer use BASI|
00000860  43 20 74 6f 20 70 72 69  6e 74 20 74 68 65 0d 6e  |C to print the.n|
00000870  65 67 61 74 69 76 65 20  68 65 78 61 64 65 63 69  |egative hexadeci|
00000880  6d 61 6c 20 76 61 6c 75  65 20 6f 66 20 74 68 65  |mal value of the|
00000890  20 6e 75 6d 62 65 72 20  6f 66 20 63 65 6e 74 69  | number of centi|
000008a0  73 65 63 6f 6e 64 73 20  69 6e 20 74 68 65 20 72  |seconds in the r|
000008b0  65 71 75 69 72 65 64 0d  69 6e 74 65 72 76 61 6c  |equired.interval|
000008c0  2e 20 46 6f 72 20 65 78  61 6d 70 6c 65 2c 20 69  |. For example, i|
000008d0  66 20 61 6e 20 69 6e 74  65 72 76 61 6c 20 6f 66  |f an interval of|
000008e0  20 30 2e 32 35 20 73 65  63 6f 6e 64 73 20 69 73  | 0.25 seconds is|
000008f0  20 72 65 71 75 69 72 65  64 20 74 68 65 6e 0d 74  | required then.t|
00000900  79 70 65 3a 0d 0d 20 20  50 52 49 4e 54 20 7e 20  |ype:..  PRINT ~ |
00000910  2d 32 35 0d 0d 61 6e 64  20 42 41 53 49 43 20 77  |-25..and BASIC w|
00000920  69 6c 6c 20 67 69 76 65  20 74 68 65 20 66 6f 75  |ill give the fou|
00000930  72 20 6c 65 61 73 74 20  73 69 67 6e 69 66 69 63  |r least signific|
00000940  61 6e 74 20 62 79 74 65  73 20 6f 66 20 74 68 65  |ant bytes of the|
00000950  20 61 73 6e 73 77 65 72  3a 0d 0d 20 20 46 46 46  | asnswer:..  FFF|
00000960  46 46 46 45 37 0d 0d 79  6f 75 20 63 61 6e 20 74  |FFFE7..you can t|
00000970  68 65 6e 20 61 64 64 20  74 68 65 20 6d 6f 73 74  |hen add the most|
00000980  20 73 69 67 6e 69 66 69  63 61 6e 74 20 62 79 74  | significant byt|
00000990  65 20 77 68 69 63 68 2c  20 69 6e 20 74 68 69 73  |e which, in this|
000009a0  20 61 70 70 6c 69 63 61  74 69 6f 6e 0d 77 69 6c  | application.wil|
000009b0  6c 20 61 6c 77 61 79 73  20 62 65 20 26 46 46 2c  |l always be &FF,|
000009c0  20 74 6f 20 67 69 76 65  20 26 46 46 46 46 46 46  | to give &FFFFFF|
000009d0  46 46 45 37 2e 20 54 68  65 20 69 6e 74 65 72 76  |FFE7. The interv|
000009e0  61 6c 20 75 73 65 64 20  62 79 20 74 68 65 0d 64  |al used by the.d|
000009f0  65 6d 6f 6e 73 74 72 61  74 69 6f 6e 20 70 72 6f  |emonstration pro|
00000a00  67 72 61 6d 20 69 73 20  30 2e 32 35 20 73 65 63  |gram is 0.25 sec|
00000a10  6f 6e 64 73 20 61 6e 64  20 74 68 65 20 66 69 76  |onds and the fiv|
00000a20  65 20 62 79 74 65 20 6e  75 6d 62 65 72 20 69 73  |e byte number is|
00000a30  0d 73 70 65 63 69 66 69  65 64 20 69 6e 20 6c 69  |.specified in li|
00000a40  6e 65 73 20 38 39 30 20  61 6e 64 20 39 30 30 20  |nes 890 and 900 |
00000a50  6f 66 20 45 56 45 4e 54  2e 0d 0d 45 76 65 6e 74  |of EVENT...Event|
00000a60  20 6e 75 6d 62 65 72 20  35 20 69 73 20 65 6e 61  | number 5 is ena|
00000a70  62 6c 65 64 20 77 69 74  68 20 4f 73 62 79 74 65  |bled with Osbyte|
00000a80  20 31 34 2c 20 58 3d 35  2c 20 61 6e 64 20 64 69  | 14, X=5, and di|
00000a90  73 61 62 6c 65 64 20 77  69 74 68 20 4f 73 62 79  |sabled with Osby|
00000aa0  74 65 0d 31 33 2c 20 58  3d 35 2c 20 59 3d 30 2e  |te.13, X=5, Y=0.|
00000ab0  20 4f 73 77 6f 72 64 20  34 20 69 73 20 75 73 65  | Osword 4 is use|
00000ac0  64 20 74 6f 20 77 72 69  74 65 20 74 6f 20 74 68  |d to write to th|
00000ad0  65 20 74 69 6d 65 72 20  77 68 65 6e 20 74 68 65  |e timer when the|
00000ae0  20 72 6f 75 74 69 6e 65  20 69 73 0d 69 6e 69 74  | routine is.init|
00000af0  69 61 6c 69 73 65 64 20  61 6e 64 20 61 67 61 69  |ialised and agai|
00000b00  6e 20 61 66 74 65 72 20  70 72 6f 63 65 73 73 69  |n after processi|
00000b10  6e 67 20 65 76 65 6e 74  20 35 20 77 68 65 6e 20  |ng event 5 when |
00000b20  69 74 20 69 73 20 75 73  65 64 20 74 6f 20 72 65  |it is used to re|
00000b30  73 74 61 72 74 0d 74 68  65 20 74 69 6d 65 72 20  |start.the timer |
00000b40  66 6f 72 20 74 68 65 20  6e 65 78 74 20 69 6e 74  |for the next int|
00000b50  65 72 76 61 6c 2e 0d 0d  43 68 61 69 6e 20 74 68  |erval...Chain th|
00000b60  65 20 70 72 6f 67 72 61  6d 20 45 56 45 4e 54 20  |e program EVENT |
00000b70  61 6e 64 20 70 72 65 73  73 20 74 68 65 20 6d 6f  |and press the mo|
00000b80  75 73 65 20 62 75 74 74  6f 6e 73 2e 20 54 68 65  |use buttons. The|
00000b90  20 70 72 6f 67 72 61 6d  20 63 61 6e 20 62 65 0d  | program can be.|
00000ba0  6d 6f 64 69 66 69 65 64  20 74 6f 20 65 6e 74 65  |modified to ente|
00000bb0  72 20 61 20 73 74 72 69  6e 67 20 6f 66 20 63 68  |r a string of ch|
00000bc0  61 72 61 63 74 65 72 73  20 69 6e 74 6f 20 74 68  |aracters into th|
00000bd0  65 20 6b 65 79 62 6f 61  72 64 20 62 75 66 66 65  |e keyboard buffe|
00000be0  72 20 72 61 74 68 65 72  0d 74 68 61 6e 20 6a 75  |r rather.than ju|
00000bf0  73 74 20 6f 6e 65 20 63  68 61 72 61 63 74 65 72  |st one character|
00000c00  20 61 6e 64 20 74 68 69  73 20 77 69 6c 6c 20 68  | and this will h|
00000c10  61 76 65 20 74 68 65 20  65 66 66 65 63 74 20 6f  |ave the effect o|
00000c20  66 20 70 72 6f 64 75 63  69 6e 67 20 65 78 74 72  |f producing extr|
00000c30  61 0d 66 75 6e 63 74 69  6f 6e 20 6b 65 79 73 2e  |a.function keys.|
00000c40  0d 0d 0d 20 20 20 31 30  20 52 45 4d 3e 20 45 56  |...   10 REM> EV|
00000c50  45 4e 54 0d 20 20 20 32  30 20 44 49 4d 20 6d 63  |ENT.   20 DIM mc|
00000c60  6f 64 65 20 26 31 30 30  20 3a 52 45 4d 3a 20 6d  |ode &100 :REM: m|
00000c70  61 63 68 69 6e 65 20 63  6f 64 65 20 61 74 20 6d  |achine code at m|
00000c80  63 6f 64 65 0d 20 20 20  33 30 20 65 76 6e 74 76  |code.   30 evntv|
00000c90  3d 26 32 32 30 20 3a 52  45 4d 3a 20 65 76 65 6e  |=&220 :REM: even|
00000ca0  74 20 76 65 63 74 6f 72  0d 20 20 20 34 30 20 64  |t vector.   40 d|
00000cb0  72 62 3d 26 46 45 36 30  20 3a 52 45 4d 3a 20 64  |rb=&FE60 :REM: d|
00000cc0  61 74 61 20 72 65 67 69  73 74 65 72 20 42 0d 20  |ata register B. |
00000cd0  20 20 35 30 20 64 64 72  62 3d 26 46 45 36 32 20  |  50 ddrb=&FE62 |
00000ce0  3a 52 45 4d 3a 20 64 61  74 61 20 64 69 72 65 63  |:REM: data direc|
00000cf0  74 69 6f 6e 20 72 65 67  69 73 74 65 72 20 42 0d  |tion register B.|
00000d00  20 20 20 36 30 20 6f 73  77 6f 72 64 3d 26 46 46  |   60 osword=&FF|
00000d10  46 31 0d 20 20 20 37 30  20 6f 73 62 79 74 65 3d  |F1.   70 osbyte=|
00000d20  26 46 46 46 34 0d 20 20  20 38 30 20 46 4f 52 20  |&FFF4.   80 FOR |
00000d30  70 61 73 73 3d 30 20 54  4f 20 32 20 53 54 45 50  |pass=0 TO 2 STEP|
00000d40  20 32 0d 20 20 20 39 30  20 50 25 3d 6d 63 6f 64  | 2.   90 P%=mcod|
00000d50  65 0d 20 20 31 30 30 20  5b 20 20 20 20 20 20 20  |e.  100 [       |
00000d60  4f 50 54 20 70 61 73 73  0d 20 20 31 31 30 20 20  |OPT pass.  110  |
00000d70  20 20 20 20 20 20 20 4c  44 58 20 65 76 6e 74 76  |       LDX evntv|
00000d80  0d 20 20 31 32 30 20 20  20 20 20 20 20 20 20 4c  |.  120         L|
00000d90  44 59 20 65 76 6e 74 76  2b 31 0d 20 20 31 33 30  |DY evntv+1.  130|
00000da0  20 20 20 20 20 20 20 20  20 43 50 59 20 23 74 69  |         CPY #ti|
00000db0  6d 65 6f 75 74 20 44 49  56 20 32 35 36 0d 20 20  |meout DIV 256.  |
00000dc0  31 34 30 20 20 20 20 20  20 20 20 20 42 45 51 20  |140         BEQ |
00000dd0  64 69 73 61 62 6c 65 20  20 20 5c 20 62 72 61 6e  |disable   \ bran|
00000de0  63 68 20 69 66 20 65 76  65 6e 74 20 76 65 63 74  |ch if event vect|
00000df0  6f 72 20 61 6c 74 65 72  65 64 0d 20 20 31 35 30  |or altered.  150|
00000e00  20 20 20 20 20 20 20 20  20 53 54 58 20 6f 6c 64  |         STX old|
00000e10  65 76 6e 74 76 20 20 5c  20 73 74 6f 72 65 20 6f  |evntv  \ store o|
00000e20  72 69 67 69 6e 61 6c 20  65 76 65 6e 74 20 76 65  |riginal event ve|
00000e30  63 74 6f 72 0d 20 20 31  36 30 20 20 20 20 20 20  |ctor.  160      |
00000e40  20 20 20 53 54 59 20 6f  6c 64 65 76 6e 74 76 2b  |   STY oldevntv+|
00000e50  31 0d 20 20 31 37 30 20  20 20 20 20 20 20 20 20  |1.  170         |
00000e60  4c 44 58 20 23 74 69 6d  65 6f 75 74 20 4d 4f 44  |LDX #timeout MOD|
00000e70  20 32 35 36 0d 20 20 31  38 30 20 20 20 20 20 20  | 256.  180      |
00000e80  20 20 20 4c 44 59 20 23  74 69 6d 65 6f 75 74 20  |   LDY #timeout |
00000e90  44 49 56 20 32 35 36 0d  20 20 31 39 30 20 20 20  |DIV 256.  190   |
00000ea0  20 20 20 20 20 20 53 54  58 20 65 76 6e 74 76 20  |      STX evntv |
00000eb0  20 20 20 20 5c 20 69 6e  73 74 61 6c 6c 20 6e 65  |    \ install ne|
00000ec0  77 20 65 76 65 6e 74 20  76 65 63 74 6f 72 0d 20  |w event vector. |
00000ed0  20 32 30 30 20 20 20 20  20 20 20 20 20 53 54 59  | 200         STY|
00000ee0  20 65 76 6e 74 76 2b 31  0d 20 20 32 31 30 20 20  | evntv+1.  210  |
00000ef0  20 20 20 20 20 20 20 4c  44 41 20 23 30 20 20 20  |       LDA #0   |
00000f00  20 20 20 20 20 5c 20 75  73 65 72 20 70 6f 72 74  |     \ user port|
00000f10  20 69 6e 70 75 74 0d 20  20 32 32 30 20 20 20 20  | input.  220    |
00000f20  20 20 20 20 20 53 54 41  20 64 64 72 62 20 20 20  |     STA ddrb   |
00000f30  20 20 20 5c 20 64 61 74  61 20 64 69 72 65 63 74  |   \ data direct|
00000f40  69 6f 6e 20 72 65 67 69  73 74 65 72 20 42 0d 20  |ion register B. |
00000f50  20 32 33 30 20 20 20 20  20 20 20 20 20 4c 44 41  | 230         LDA|
00000f60  20 23 26 30 45 20 20 20  20 20 20 5c 20 65 6e 61  | #&0E      \ ena|
00000f70  62 6c 65 20 65 76 65 6e  74 73 0d 20 20 32 34 30  |ble events.  240|
00000f80  20 20 20 20 20 20 20 20  20 4c 44 58 20 23 26 30  |         LDX #&0|
00000f90  35 20 20 20 20 20 20 5c  20 69 6e 74 65 72 76 61  |5      \ interva|
00000fa0  6c 20 74 69 6d 65 72 20  63 72 6f 73 73 69 6e 67  |l timer crossing|
00000fb0  20 7a 65 72 6f 0d 20 20  32 35 30 20 20 20 20 20  | zero.  250     |
00000fc0  20 20 20 20 4a 53 52 20  6f 73 62 79 74 65 0d 20  |    JSR osbyte. |
00000fd0  20 32 36 30 20 2e 77 72  69 74 65 74 69 6d 65 72  | 260 .writetimer|
00000fe0  0d 20 20 32 37 30 20 20  20 20 20 20 20 20 20 4c  |.  270         L|
00000ff0  44 41 20 23 26 30 34 20  20 20 20 20 20 5c 20 77  |DA #&04      \ w|
00001000  72 69 74 65 20 69 6e 74  65 72 76 61 6c 20 74 69  |rite interval ti|
00001010  6d 65 72 0d 20 20 32 38  30 20 20 20 20 20 20 20  |mer.  280       |
00001020  20 20 4c 44 58 20 23 63  6c 6f 63 6b 20 4d 4f 44  |  LDX #clock MOD|
00001030  20 32 35 36 0d 20 20 32  39 30 20 20 20 20 20 20  | 256.  290      |
00001040  20 20 20 4c 44 59 20 23  63 6c 6f 63 6b 20 44 49  |   LDY #clock DI|
00001050  56 20 32 35 36 0d 20 20  33 30 30 20 20 20 20 20  |V 256.  300     |
00001060  20 20 20 20 4a 4d 50 20  6f 73 77 6f 72 64 20 20  |    JMP osword  |
00001070  20 20 5c 20 4f 73 77 6f  72 64 20 61 6e 64 20 72  |  \ Osword and r|
00001080  65 74 75 72 6e 0d 20 20  33 31 30 20 2e 64 69 73  |eturn.  310 .dis|
00001090  61 62 6c 65 0d 20 20 33  32 30 20 20 20 20 20 20  |able.  320      |
000010a0  20 20 20 4c 44 41 20 23  26 30 44 20 20 20 20 20  |   LDA #&0D     |
000010b0  20 5c 20 64 69 73 61 62  6c 65 20 65 76 65 6e 74  | \ disable event|
000010c0  73 0d 20 20 33 33 30 20  20 20 20 20 20 20 20 20  |s.  330         |
000010d0  4c 44 58 20 23 26 30 35  20 20 20 20 20 20 5c 20  |LDX #&05      \ |
000010e0  69 6e 74 65 72 76 61 6c  20 74 69 6d 65 72 20 63  |interval timer c|
000010f0  72 6f 73 73 69 6e 67 20  7a 65 72 6f 0d 20 20 33  |rossing zero.  3|
00001100  34 30 20 20 20 20 20 20  20 20 20 4c 44 59 20 23  |40         LDY #|
00001110  26 30 30 0d 20 20 33 35  30 20 20 20 20 20 20 20  |&00.  350       |
00001120  20 20 4a 53 52 20 6f 73  62 79 74 65 0d 20 20 33  |  JSR osbyte.  3|
00001130  36 30 20 20 20 20 20 20  20 20 20 4c 44 58 20 6f  |60         LDX o|
00001140  6c 64 65 76 6e 74 76 20  20 5c 20 72 65 73 74 6f  |ldevntv  \ resto|
00001150  72 65 20 65 76 65 6e 74  20 76 65 63 74 6f 72 0d  |re event vector.|
00001160  20 20 33 37 30 20 20 20  20 20 20 20 20 20 4c 44  |  370         LD|
00001170  59 20 6f 6c 64 65 76 6e  74 76 2b 31 0d 20 20 33  |Y oldevntv+1.  3|
00001180  38 30 20 20 20 20 20 20  20 20 20 53 54 58 20 65  |80         STX e|
00001190  76 6e 74 76 0d 20 20 33  39 30 20 20 20 20 20 20  |vntv.  390      |
000011a0  20 20 20 53 54 59 20 65  76 6e 74 76 2b 31 0d 20  |   STY evntv+1. |
000011b0  20 34 30 30 20 20 20 20  20 20 20 20 20 52 54 53  | 400         RTS|
000011c0  20 20 20 20 20 20 20 20  20 20 20 5c 20 72 65 74  |           \ ret|
000011d0  75 72 6e 20 74 6f 20 42  41 53 49 43 0d 20 20 34  |urn to BASIC.  4|
000011e0  31 30 20 2e 74 69 6d 65  6f 75 74 0d 20 20 34 32  |10 .timeout.  42|
000011f0  30 20 20 20 20 20 20 20  20 20 50 48 50 20 20 20  |0         PHP   |
00001200  20 20 20 20 20 20 20 20  5c 20 70 75 73 68 20 73  |        \ push s|
00001210  74 61 74 75 73 20 72 65  67 69 73 74 65 72 0d 20  |tatus register. |
00001220  20 34 33 30 20 20 20 20  20 20 20 20 20 43 4d 50  | 430         CMP|
00001230  20 23 26 30 35 20 20 20  20 20 20 5c 20 69 73 20  | #&05      \ is |
00001240  74 68 69 73 20 69 6e 74  65 72 76 61 6c 20 74 69  |this interval ti|
00001250  6d 65 72 20 63 72 6f 73  73 69 6e 67 20 7a 65 72  |mer crossing zer|
00001260  6f 3f 0d 20 20 34 34 30  20 20 20 20 20 20 20 20  |o?.  440        |
00001270  20 42 45 51 20 69 6e 74  65 72 76 61 6c 20 20 5c  | BEQ interval  \|
00001280  20 62 72 61 6e 63 68 20  69 66 20 69 74 20 69 73  | branch if it is|
00001290  0d 20 20 34 35 30 20 20  20 20 20 20 20 20 20 50  |.  450         P|
000012a0  4c 50 20 20 20 20 20 20  20 20 20 20 20 5c 20 72  |LP           \ r|
000012b0  65 73 74 6f 72 65 20 73  74 61 74 75 73 20 72 65  |estore status re|
000012c0  67 69 73 74 65 72 0d 20  20 34 36 30 20 20 20 20  |gister.  460    |
000012d0  20 20 20 20 20 4a 4d 50  20 28 6f 6c 64 65 76 6e  |     JMP (oldevn|
000012e0  74 76 29 20 5c 20 65 78  69 74 20 76 69 61 20 6f  |tv) \ exit via o|
000012f0  72 69 67 69 6e 61 6c 20  76 65 63 74 6f 72 0d 20  |riginal vector. |
00001300  20 34 37 30 20 2e 69 6e  74 65 72 76 61 6c 0d 20  | 470 .interval. |
00001310  20 34 38 30 20 20 20 20  20 20 20 20 20 50 48 41  | 480         PHA|
00001320  20 20 20 20 20 20 20 20  20 20 20 5c 20 73 74 6f  |           \ sto|
00001330  72 65 20 41 0d 20 20 34  39 30 20 20 20 20 20 20  |re A.  490      |
00001340  20 20 20 54 58 41 0d 20  20 35 30 30 20 20 20 20  |   TXA.  500    |
00001350  20 20 20 20 20 50 48 41  20 20 20 20 20 20 20 20  |     PHA        |
00001360  20 20 20 5c 20 73 74 6f  72 65 20 58 0d 20 20 35  |   \ store X.  5|
00001370  31 30 20 20 20 20 20 20  20 20 20 54 59 41 0d 20  |10         TYA. |
00001380  20 35 32 30 20 20 20 20  20 20 20 20 20 50 48 41  | 520         PHA|
00001390  20 20 20 20 20 20 20 20  20 20 20 5c 20 73 74 6f  |           \ sto|
000013a0  72 65 20 59 0d 20 20 35  33 30 20 20 20 20 20 20  |re Y.  530      |
000013b0  20 20 20 4c 44 41 20 64  72 62 20 20 20 20 20 20  |   LDA drb      |
000013c0  20 5c 20 64 61 74 61 20  72 65 67 69 73 74 65 72  | \ data register|
000013d0  20 42 0d 20 20 35 34 30  20 20 20 20 20 20 20 20  | B.  540        |
000013e0  20 52 4f 4c 20 41 20 20  20 20 20 20 20 20 20 5c  | ROL A         \|
000013f0  20 62 69 74 20 37 20 69  6e 74 6f 20 63 61 72 72  | bit 7 into carr|
00001400  79 0d 20 20 35 35 30 20  20 20 20 20 20 20 20 20  |y.  550         |
00001410  42 43 43 20 72 69 67 68  74 20 20 20 20 20 5c 20  |BCC right     \ |
00001420  62 72 61 6e 63 68 20 69  66 20 72 69 67 68 74 20  |branch if right |
00001430  62 75 74 74 6f 6e 20 70  72 65 73 73 65 64 0d 20  |button pressed. |
00001440  20 35 36 30 20 20 20 20  20 20 20 20 20 52 4f 4c  | 560         ROL|
00001450  20 41 20 20 20 20 20 20  20 20 20 5c 20 62 69 74  | A         \ bit|
00001460  20 36 20 69 6e 74 6f 20  63 61 72 72 79 0d 20 20  | 6 into carry.  |
00001470  35 37 30 20 20 20 20 20  20 20 20 20 42 43 43 20  |570         BCC |
00001480  63 65 6e 74 72 65 20 20  20 20 5c 20 62 72 61 6e  |centre    \ bran|
00001490  63 68 20 69 66 20 63 65  6e 74 72 65 20 62 75 74  |ch if centre but|
000014a0  74 6f 6e 20 70 72 65 73  73 65 64 0d 20 20 35 38  |ton pressed.  58|
000014b0  30 20 20 20 20 20 20 20  20 20 52 4f 4c 20 41 20  |0         ROL A |
000014c0  20 20 20 20 20 20 20 20  5c 20 62 69 74 20 35 20  |        \ bit 5 |
000014d0  69 6e 74 6f 20 63 61 72  72 79 0d 20 20 35 39 30  |into carry.  590|
000014e0  20 20 20 20 20 20 20 20  20 42 43 53 20 70 75 6c  |         BCS pul|
000014f0  6c 6f 75 74 20 20 20 5c  20 65 78 69 74 20 69 66  |lout   \ exit if|
00001500  20 6c 65 66 74 20 62 75  74 74 6f 6e 20 6e 6f 74  | left button not|
00001510  20 70 72 65 73 73 65 64  0d 20 20 36 30 30 20 20  | pressed.  600  |
00001520  20 20 20 20 20 20 20 4c  44 59 20 6c 65 66 74 6b  |       LDY leftk|
00001530  65 79 20 20 20 5c 20 6c  65 66 74 20 62 75 74 74  |ey   \ left butt|
00001540  6f 6e 20 70 72 65 73 73  65 64 0d 20 20 36 31 30  |on pressed.  610|
00001550  20 20 20 20 20 20 20 20  20 42 4e 45 20 69 6e 74  |         BNE int|
00001560  6f 62 75 66 66 65 72 0d  20 20 36 32 30 20 2e 63  |obuffer.  620 .c|
00001570  65 6e 74 72 65 0d 20 20  36 33 30 20 20 20 20 20  |entre.  630     |
00001580  20 20 20 20 4c 44 59 20  63 65 6e 74 72 65 6b 65  |    LDY centreke|
00001590  79 0d 20 20 36 34 30 20  20 20 20 20 20 20 20 20  |y.  640         |
000015a0  42 4e 45 20 69 6e 74 6f  62 75 66 66 65 72 0d 20  |BNE intobuffer. |
000015b0  20 36 35 30 20 2e 72 69  67 68 74 0d 20 20 36 36  | 650 .right.  66|
000015c0  30 20 20 20 20 20 20 20  20 20 4c 44 59 20 72 69  |0         LDY ri|
000015d0  67 68 74 6b 65 79 0d 20  20 36 37 30 20 2e 69 6e  |ghtkey.  670 .in|
000015e0  74 6f 62 75 66 66 65 72  0d 20 20 36 38 30 20 20  |tobuffer.  680  |
000015f0  20 20 20 20 20 20 20 4c  44 41 20 23 26 38 41 20  |       LDA #&8A |
00001600  20 20 20 20 20 5c 20 69  6e 73 65 72 74 20 76 61  |     \ insert va|
00001610  6c 75 65 20 69 6e 74 6f  20 62 75 66 66 65 72 0d  |lue into buffer.|
00001620  20 20 36 39 30 20 20 20  20 20 20 20 20 20 4c 44  |  690         LD|
00001630  58 20 23 26 30 30 20 20  20 20 20 20 5c 20 6b 65  |X #&00      \ ke|
00001640  79 62 6f 61 72 64 20 62  75 66 66 65 72 0d 20 20  |yboard buffer.  |
00001650  37 30 30 20 20 20 20 20  20 20 20 20 4a 53 52 20  |700         JSR |
00001660  6f 73 62 79 74 65 0d 20  20 37 31 30 20 2e 70 75  |osbyte.  710 .pu|
00001670  6c 6c 6f 75 74 0d 20 20  37 32 30 20 20 20 20 20  |llout.  720     |
00001680  20 20 20 20 4a 53 52 20  77 72 69 74 65 74 69 6d  |    JSR writetim|
00001690  65 72 20 5c 20 72 65 73  65 74 20 74 69 6d 65 72  |er \ reset timer|
000016a0  0d 20 20 37 33 30 20 20  20 20 20 20 20 20 20 50  |.  730         P|
000016b0  4c 41 0d 20 20 37 34 30  20 20 20 20 20 20 20 20  |LA.  740        |
000016c0  20 54 41 59 20 20 20 20  20 20 20 20 20 20 20 5c  | TAY           \|
000016d0  20 72 65 73 74 6f 72 65  20 59 0d 20 20 37 35 30  | restore Y.  750|
000016e0  20 20 20 20 20 20 20 20  20 50 4c 41 0d 20 20 37  |         PLA.  7|
000016f0  36 30 20 20 20 20 20 20  20 20 20 54 41 58 20 20  |60         TAX  |
00001700  20 20 20 20 20 20 20 20  20 5c 20 72 65 73 74 6f  |         \ resto|
00001710  72 65 20 58 0d 20 20 37  37 30 20 20 20 20 20 20  |re X.  770      |
00001720  20 20 20 50 4c 41 0d 20  20 37 38 30 20 20 20 20  |   PLA.  780    |
00001730  20 20 20 20 20 50 4c 50  0d 20 20 37 39 30 20 20  |     PLP.  790  |
00001740  20 20 20 20 20 20 20 52  54 53 0d 20 20 38 30 30  |       RTS.  800|
00001750  20 2e 6c 65 66 74 6b 65  79 0d 20 20 38 31 30 20  | .leftkey.  810 |
00001760  20 20 20 20 20 20 20 20  45 51 55 42 20 41 53 43  |        EQUB ASC|
00001770  28 22 4c 22 29 0d 20 20  38 32 30 20 2e 63 65 6e  |("L").  820 .cen|
00001780  74 72 65 6b 65 79 0d 20  20 38 33 30 20 20 20 20  |trekey.  830    |
00001790  20 20 20 20 20 45 51 55  42 20 41 53 43 28 22 43  |     EQUB ASC("C|
000017a0  22 29 0d 20 20 38 34 30  20 2e 72 69 67 68 74 6b  |").  840 .rightk|
000017b0  65 79 0d 20 20 38 35 30  20 20 20 20 20 20 20 20  |ey.  850        |
000017c0  20 45 51 55 42 20 41 53  43 28 22 52 22 29 0d 20  | EQUB ASC("R"). |
000017d0  20 38 36 30 20 2e 6f 6c  64 65 76 6e 74 76 0d 20  | 860 .oldevntv. |
000017e0  20 38 37 30 20 20 20 20  20 20 20 20 20 45 51 55  | 870         EQU|
000017f0  57 20 26 30 30 0d 20 20  38 38 30 20 2e 63 6c 6f  |W &00.  880 .clo|
00001800  63 6b 0d 20 20 38 39 30  20 20 20 20 20 20 20 20  |ck.  890        |
00001810  20 45 51 55 44 20 26 46  46 46 46 46 46 45 37 0d  | EQUD &FFFFFFE7.|
00001820  20 20 39 30 30 20 20 20  20 20 20 20 20 20 45 51  |  900         EQ|
00001830  55 42 20 26 46 46 0d 20  20 39 31 30 20 5d 0d 20  |UB &FF.  910 ]. |
00001840  20 39 32 30 20 4e 45 58  54 0d 20 20 39 33 30 20  | 920 NEXT.  930 |
00001850  43 41 4c 4c 20 6d 63 6f  64 65 0d 0d 0d 54 68 65  |CALL mcode...The|
00001860  20 70 72 6f 67 72 61 6d  20 42 55 54 54 4f 4e 53  | program BUTTONS|
00001870  20 64 65 6d 6f 6e 73 74  72 61 74 65 73 20 61 20  | demonstrates a |
00001880  73 65 63 6f 6e 64 20 6d  65 74 68 6f 64 20 6f 66  |second method of|
00001890  20 70 6f 6c 6c 69 6e 67  20 74 68 65 20 44 52 42  | polling the DRB|
000018a0  20 74 6f 20 73 65 65 0d  69 66 20 61 6e 79 20 6f  | to see.if any o|
000018b0  66 20 74 68 65 20 6d 6f  75 73 65 20 62 75 74 74  |f the mouse butt|
000018c0  6f 6e 73 20 61 72 65 20  70 72 65 73 73 65 64 2e  |ons are pressed.|
000018d0  20 49 6e 20 74 68 69 73  20 70 72 6f 67 72 61 6d  | In this program|
000018e0  20 74 68 65 20 49 4e 4b  45 59 0d 66 75 6e 63 74  | the INKEY.funct|
000018f0  69 6f 6e 20 69 73 20 69  6e 74 65 72 63 65 70 74  |ion is intercept|
00001900  65 64 20 73 6f 20 74 68  61 74 20 74 68 65 20 6d  |ed so that the m|
00001910  6f 75 73 65 20 62 75 74  74 6f 6e 73 20 63 61 6e  |ouse buttons can|
00001920  20 62 65 20 74 65 73 74  65 64 20 61 73 20 69 66  | be tested as if|
00001930  20 74 68 65 79 0d 61 72  65 20 6b 65 79 73 20 6f  | they.are keys o|
00001940  6e 20 74 68 65 20 6b 65  79 62 6f 61 72 64 2e 0d  |n the keyboard..|
00001950  0d 54 68 65 20 42 41 53  49 43 20 66 75 6e 63 74  |.The BASIC funct|
00001960  69 6f 6e 20 49 4e 4b 45  59 20 77 69 74 68 20 61  |ion INKEY with a|
00001970  20 6e 65 67 61 74 69 76  65 20 6e 75 6d 62 65 72  | negative number|
00001980  20 69 6e 20 74 68 65 20  62 72 61 63 6b 65 74 73  | in the brackets|
00001990  2c 20 65 67 2e 0d 49 4e  4b 45 59 28 2d 37 34 29  |, eg..INKEY(-74)|
000019a0  2c 20 63 61 6e 20 62 65  20 75 73 65 64 20 74 6f  |, can be used to|
000019b0  20 74 65 73 74 20 77 68  65 74 68 65 72 20 61 20  | test whether a |
000019c0  70 61 72 74 69 63 75 6c  61 72 20 6b 65 79 20 69  |particular key i|
000019d0  73 20 70 72 65 73 73 65  64 20 77 68 65 6e 0d 74  |s pressed when.t|
000019e0  68 65 20 66 75 6e 63 74  69 6f 6e 20 69 73 20 63  |he function is c|
000019f0  61 6c 6c 65 64 2e 20 54  68 65 20 49 4e 4b 45 59  |alled. The INKEY|
00001a00  20 66 75 6e 63 74 69 6f  6e 20 69 73 20 65 78 65  | function is exe|
00001a10  63 75 74 65 64 20 76 69  61 20 74 68 65 20 4f 73  |cuted via the Os|
00001a20  62 79 74 65 0d 69 6e 64  69 72 65 63 74 69 6f 6e  |byte.indirection|
00001a30  20 76 65 63 74 6f 72 20  75 73 69 6e 67 20 4f 73  | vector using Os|
00001a40  62 79 74 65 20 26 38 31  20 77 69 74 68 20 58 20  |byte &81 with X |
00001a50  3d 20 74 68 65 20 28 6e  65 67 61 74 69 76 65 29  |= the (negative)|
00001a60  20 49 4e 4b 45 59 20 76  61 6c 75 65 0d 61 6e 64  | INKEY value.and|
00001a70  20 59 20 3d 20 26 46 46  2e 20 54 68 65 20 66 75  | Y = &FF. The fu|
00001a80  6e 63 74 69 6f 6e 20 63  61 6e 20 62 65 20 69 6e  |nction can be in|
00001a90  74 65 72 63 65 70 74 65  64 20 62 79 20 72 65 64  |tercepted by red|
00001aa0  69 72 65 63 74 69 6e 67  20 74 68 65 20 4f 73 62  |irecting the Osb|
00001ab0  79 74 65 0d 76 65 63 74  6f 72 20 74 6f 20 61 20  |yte.vector to a |
00001ac0  6e 65 77 20 49 4e 4b 45  59 20 72 6f 75 74 69 6e  |new INKEY routin|
00001ad0  65 2e 20 54 68 65 20 70  72 6f 67 72 61 6d 20 42  |e. The program B|
00001ae0  55 54 54 4f 4e 53 20 64  75 70 6c 69 63 61 74 65  |UTTONS duplicate|
00001af0  73 20 74 68 65 20 6e 65  67 61 74 69 76 65 0d 49  |s the negative.I|
00001b00  4e 4b 45 59 20 66 75 6e  63 74 69 6f 6e 20 66 6f  |NKEY function fo|
00001b10  72 20 74 68 65 20 5a 2c  20 58 20 61 6e 64 20 52  |r the Z, X and R|
00001b20  65 74 75 72 6e 20 6b 65  79 73 20 73 6f 20 74 68  |eturn keys so th|
00001b30  61 74 20 74 68 65 73 65  20 6b 65 79 20 63 61 6e  |at these key can|
00001b40  20 62 65 0d 73 63 61 6e  6e 65 64 20 62 6f 74 68  | be.scanned both|
00001b50  20 6f 6e 20 74 68 65 20  6b 65 79 62 6f 61 72 64  | on the keyboard|
00001b60  20 61 6e 64 20 6f 6e 20  74 68 65 20 6d 6f 75 73  | and on the mous|
00001b70  65 2e 0d 0d 54 68 65 20  72 65 76 65 63 74 6f 72  |e...The revector|
00001b80  65 64 20 4f 73 62 79 74  65 20 69 6e 64 69 72 65  |ed Osbyte indire|
00001b90  63 74 69 6f 6e 20 76 65  63 74 6f 72 20 75 73 65  |ction vector use|
00001ba0  64 20 69 6e 20 42 55 54  54 4f 4e 53 20 70 6f 69  |d in BUTTONS poi|
00001bb0  6e 74 73 20 74 6f 20 74  68 65 0d 63 6f 64 65 20  |nts to the.code |
00001bc0  6c 61 62 65 6c 65 64 20  6e 65 77 69 6e 6b 65 79  |labeled newinkey|
00001bd0  20 77 68 69 63 68 20 63  68 65 63 6b 73 20 74 6f  | which checks to|
00001be0  20 73 65 65 20 69 66 20  61 20 6e 65 67 61 74 69  | see if a negati|
00001bf0  76 65 20 49 4e 4b 45 59  20 66 75 6e 63 74 69 6f  |ve INKEY functio|
00001c00  6e 20 69 73 0d 62 65 69  6e 67 20 65 78 65 63 75  |n is.being execu|
00001c10  74 65 64 2e 20 49 66 20  69 74 20 69 73 20 6e 6f  |ted. If it is no|
00001c20  74 20 61 20 6e 65 67 61  74 69 76 65 20 49 4e 4b  |t a negative INK|
00001c30  45 59 20 74 68 65 6e 20  74 68 65 20 6e 65 77 20  |EY then the new |
00001c40  72 6f 75 74 69 6e 65 20  65 78 69 74 73 0d 76 69  |routine exits.vi|
00001c50  61 20 74 68 65 20 6f 72  69 67 69 6e 61 6c 20 4f  |a the original O|
00001c60  73 62 79 74 65 20 76 65  63 74 6f 72 2e 20 49 66  |sbyte vector. If|
00001c70  20 61 20 6e 65 67 61 74  69 76 65 20 49 4e 4b 45  | a negative INKE|
00001c80  59 20 69 73 20 62 65 69  6e 67 20 65 78 65 63 75  |Y is being execu|
00001c90  74 65 64 20 74 68 65 6e  0d 74 68 65 20 6e 65 77  |ted then.the new|
00001ca0  20 72 6f 75 74 69 6e 65  20 66 69 72 73 74 20 6f  | routine first o|
00001cb0  66 20 61 6c 6c 20 65 78  65 63 75 74 65 73 20 74  |f all executes t|
00001cc0  68 65 20 6f 72 69 67 69  6e 61 6c 20 63 6f 64 65  |he original code|
00001cd0  20 74 6f 20 73 65 65 20  69 66 20 74 68 65 0d 72  | to see if the.r|
00001ce0  65 71 75 69 72 65 64 20  6b 65 79 62 6f 61 72 64  |equired keyboard|
00001cf0  20 62 75 74 74 6f 6e 20  69 73 20 70 72 65 73 73  | button is press|
00001d00  65 64 2e 20 49 66 20 69  74 20 69 73 20 74 68 65  |ed. If it is the|
00001d10  6e 20 74 68 65 20 6e 65  77 20 72 6f 75 74 69 6e  |n the new routin|
00001d20  65 20 72 65 74 75 72 6e  73 0d 63 6f 6e 74 72 6f  |e returns.contro|
00001d30  6c 20 74 6f 20 74 68 65  20 6f 70 65 72 61 74 69  |l to the operati|
00001d40  6e 67 20 73 79 73 74 65  6d 2e 20 49 66 20 74 68  |ng system. If th|
00001d50  65 20 6b 65 79 20 62 65  69 6e 67 20 73 63 61 6e  |e key being scan|
00001d60  6e 65 64 20 69 73 20 6e  6f 74 20 70 72 65 73 73  |ned is not press|
00001d70  65 64 0d 6f 6e 20 74 68  65 20 6b 65 79 62 6f 61  |ed.on the keyboa|
00001d80  72 64 20 74 68 65 6e 20  74 68 65 20 6e 65 77 20  |rd then the new |
00001d90  72 6f 75 74 69 6e 65 20  63 68 65 63 6b 73 20 74  |routine checks t|
00001da0  6f 20 73 65 65 20 69 66  20 74 68 65 20 6b 65 79  |o see if the key|
00001db0  20 69 73 20 6f 6e 65 20  77 68 69 63 68 0d 68 61  | is one which.ha|
00001dc0  73 20 62 65 65 6e 20 61  6c 6c 6f 63 61 74 65 64  |s been allocated|
00001dd0  20 74 6f 20 6f 6e 65 20  6f 66 20 74 68 65 20 6d  | to one of the m|
00001de0  6f 75 73 65 20 62 75 74  74 6f 6e 73 2e 20 49 66  |ouse buttons. If|
00001df0  20 69 74 20 69 73 20 74  68 65 6e 20 74 68 65 20  | it is then the |
00001e00  44 52 42 20 69 73 0d 70  6f 6c 6c 65 64 20 74 6f  |DRB is.polled to|
00001e10  20 73 65 65 20 69 66 20  74 68 65 20 61 70 70 72  | see if the appr|
00001e20  6f 70 72 69 61 74 65 20  6d 6f 75 73 65 20 62 75  |opriate mouse bu|
00001e30  74 74 6f 6e 20 69 73 20  70 72 65 73 73 65 64 2e  |tton is pressed.|
00001e40  0d 0d 49 66 20 74 68 65  20 72 65 71 75 69 72 65  |..If the require|
00001e50  64 20 6d 6f 75 73 65 20  62 75 74 74 6f 6e 20 69  |d mouse button i|
00001e60  73 20 70 72 65 73 73 65  64 20 74 68 65 6e 20 61  |s pressed then a|
00001e70  20 72 65 74 75 72 6e 20  66 72 6f 6d 20 4f 73 62  | return from Osb|
00001e80  79 74 65 20 26 38 31 20  69 73 0d 6d 61 64 65 20  |yte &81 is.made |
00001e90  77 69 74 68 20 62 6f 74  68 20 74 68 65 20 58 3d  |with both the X=|
00001ea0  26 46 46 20 61 6e 64 20  59 3d 26 46 46 2e 20 54  |&FF and Y=&FF. T|
00001eb0  68 69 73 20 68 61 73 20  74 68 65 20 65 66 66 65  |his has the effe|
00001ec0  63 74 20 6f 66 20 73 69  6d 75 6c 61 74 69 6e 67  |ct of simulating|
00001ed0  20 61 0d 54 52 55 45 20  72 65 74 75 72 6e 20 66  | a.TRUE return f|
00001ee0  72 6f 6d 20 74 68 65 20  6e 65 67 61 74 69 76 65  |rom the negative|
00001ef0  20 49 4e 4b 45 59 20 66  75 6e 63 74 69 6f 6e 2e  | INKEY function.|
00001f00  20 49 66 20 74 68 65 20  72 65 71 75 69 72 65 64  | If the required|
00001f10  20 6d 6f 75 73 65 20 62  75 74 74 6f 6e 0d 69 73  | mouse button.is|
00001f20  20 6e 6f 74 20 70 72 65  73 73 65 64 20 74 68 65  | not pressed the|
00001f30  6e 20 74 68 65 20 72 65  74 75 72 6e 20 66 72 6f  |n the return fro|
00001f40  6d 20 4f 73 62 79 74 65  20 26 38 31 20 68 61 73  |m Osbyte &81 has|
00001f50  20 74 68 65 20 58 20 61  6e 64 20 59 20 72 65 67  | the X and Y reg|
00001f60  69 73 74 65 72 73 0d 73  74 6f 72 69 6e 67 20 74  |isters.storing t|
00001f70  68 65 20 73 61 6d 65 20  6e 75 6d 62 65 72 73 20  |he same numbers |
00001f80  77 69 74 68 20 77 68 69  63 68 20 74 68 65 79 20  |with which they |
00001f90  72 65 74 75 72 6e 65 64  20 66 72 6f 6d 20 74 68  |returned from th|
00001fa0  65 20 6f 72 69 67 69 6e  61 6c 20 49 4e 4b 45 59  |e original INKEY|
00001fb0  0d 72 6f 75 74 69 6e 65  20 61 6e 64 20 74 68 69  |.routine and thi|
00001fc0  73 20 68 61 73 20 74 68  65 20 65 66 66 65 63 74  |s has the effect|
00001fd0  20 6f 66 20 61 20 46 41  4c 53 45 20 72 65 74 75  | of a FALSE retu|
00001fe0  72 6e 20 66 72 6f 6d 20  74 68 65 20 66 75 6e 63  |rn from the func|
00001ff0  74 69 6f 6e 2e 0d 0d 43  68 61 69 6e 20 74 68 65  |tion...Chain the|
00002000  20 70 72 6f 67 72 61 6d  20 42 55 54 54 4f 4e 53  | program BUTTONS|
00002010  20 61 6e 64 20 70 72 65  73 73 20 65 69 74 68 65  | and press eithe|
00002020  72 20 74 68 65 20 5a 2c  20 58 20 6f 72 20 52 65  |r the Z, X or Re|
00002030  74 75 72 6e 20 6b 65 79  73 20 6f 6e 20 74 68 65  |turn keys on the|
00002040  0d 6b 65 79 62 6f 61 72  64 20 6f 72 20 74 68 65  |.keyboard or the|
00002050  20 6d 6f 75 73 65 20 62  75 74 74 6f 6e 73 2e 20  | mouse buttons. |
00002060  54 68 65 20 74 65 63 68  6e 69 71 75 65 20 64 65  |The technique de|
00002070  6d 6f 6e 73 74 72 61 74  65 64 20 69 6e 20 74 68  |monstrated in th|
00002080  65 20 70 72 6f 67 72 61  6d 0d 69 73 20 70 72 6f  |e program.is pro|
00002090  62 61 62 6c 79 20 74 68  65 20 6d 6f 73 74 20 75  |bably the most u|
000020a0  73 65 66 75 6c 20 6f 6e  65 20 74 6f 20 75 73 65  |seful one to use|
000020b0  20 69 66 20 79 6f 75 20  77 61 6e 74 20 74 6f 20  | if you want to |
000020c0  75 73 65 20 74 68 65 20  6d 6f 75 73 65 0d 62 75  |use the mouse.bu|
000020d0  74 74 6f 6e 73 20 66 6f  72 20 61 72 63 61 64 65  |ttons for arcade|
000020e0  20 74 79 70 65 20 67 61  6d 65 73 2e 20 54 68 69  | type games. Thi|
000020f0  73 20 74 79 70 65 20 6f  66 20 67 61 6d 65 20 6f  |s type of game o|
00002100  66 74 65 6e 20 75 73 65  73 20 74 68 65 20 6e 65  |ften uses the ne|
00002110  67 61 74 69 76 65 0d 49  4e 4b 45 59 20 6f 72 20  |gative.INKEY or |
00002120  69 74 73 20 6d 61 63 68  69 6e 65 20 63 6f 64 65  |its machine code|
00002130  20 65 71 75 69 76 61 6c  65 6e 74 20 74 6f 20 73  | equivalent to s|
00002140  63 61 6e 20 74 68 65 20  6b 65 79 62 6f 61 72 64  |can the keyboard|
00002150  20 61 6e 64 20 62 79 20  75 73 69 6e 67 20 74 68  | and by using th|
00002160  65 0d 69 64 65 61 73 20  64 65 6d 6f 6e 73 74 72  |e.ideas demonstr|
00002170  61 74 65 64 20 69 6e 20  74 68 65 20 70 72 6f 67  |ated in the prog|
00002180  72 61 6d 20 74 68 65 20  67 61 6d 65 20 70 6c 61  |ram the game pla|
00002190  79 65 72 20 77 69 6c 6c  20 62 65 20 61 62 6c 65  |yer will be able|
000021a0  20 74 6f 20 75 73 65 0d  65 69 74 68 65 72 20 74  | to use.either t|
000021b0  68 65 20 6b 65 79 62 6f  61 72 64 20 6f 72 20 74  |he keyboard or t|
000021c0  68 65 20 6d 6f 75 73 65  20 62 75 74 74 6f 6e 73  |he mouse buttons|
000021d0  20 6f 72 20 65 76 65 6e  20 62 6f 74 68 20 61 74  | or even both at|
000021e0  20 74 68 65 20 73 61 6d  65 20 74 69 6d 65 2e 0d  | the same time..|
000021f0  0d 59 6f 75 20 68 61 76  65 20 61 6c 72 65 61 64  |.You have alread|
00002200  79 20 62 65 65 6e 20 73  68 6f 77 6e 20 68 6f 77  |y been shown how|
00002210  20 74 6f 20 64 65 74 65  63 74 20 61 6e 64 20 72  | to detect and r|
00002220  65 63 6f 72 64 20 74 68  65 20 6d 6f 76 65 6d 65  |ecord the moveme|
00002230  6e 74 20 6f 66 20 61 0d  6d 6f 75 73 65 2e 20 49  |nt of a.mouse. I|
00002240  6e 20 6d 6f 64 75 6c 65  20 34 20 49 20 77 69 6c  |n module 4 I wil|
00002250  6c 20 64 65 6d 6f 6e 73  74 72 61 74 65 20 68 6f  |l demonstrate ho|
00002260  77 20 74 68 65 20 73 74  6f 72 65 64 20 58 20 61  |w the stored X a|
00002270  6e 64 20 59 20 63 6f 6f  72 64 69 6e 61 74 65 73  |nd Y coordinates|
00002280  0d 63 61 6e 20 62 65 20  75 73 65 64 20 77 69 74  |.can be used wit|
00002290  68 20 61 20 6d 6f 64 69  66 69 65 64 20 76 65 72  |h a modified ver|
000022a0  73 69 6f 6e 20 6f 66 20  74 68 65 20 6e 65 67 61  |sion of the nega|
000022b0  74 69 76 65 20 49 4e 4b  45 59 20 74 65 63 68 6e  |tive INKEY techn|
000022c0  69 71 75 65 20 73 6f 0d  74 68 61 74 20 6d 6f 75  |ique so.that mou|
000022d0  73 65 20 6d 6f 76 65 6d  65 6e 74 20 63 61 6e 20  |se movement can |
000022e0  62 65 63 6f 6d 65 20 61  20 73 75 62 73 74 69 74  |become a substit|
000022f0  75 74 65 20 66 6f 72 20  70 72 65 73 73 69 6e 67  |ute for pressing|
00002300  20 74 68 65 20 63 75 72  73 6f 72 20 6b 65 79 73  | the cursor keys|
00002310  2e 0d 0d 0d 20 20 20 31  30 20 52 45 4d 3e 20 42  |....   10 REM> B|
00002320  55 54 54 4f 4e 53 0d 20  20 20 32 30 20 44 49 4d  |UTTONS.   20 DIM|
00002330  20 6d 63 6f 64 65 20 26  31 30 30 20 3a 52 45 4d  | mcode &100 :REM|
00002340  3a 20 6d 61 63 68 69 6e  65 20 63 6f 64 65 20 61  |: machine code a|
00002350  74 20 6d 63 6f 64 65 0d  20 20 20 33 30 20 62 79  |t mcode.   30 by|
00002360  74 65 76 3d 26 32 30 41  20 3a 52 45 4d 3a 20 4f  |tev=&20A :REM: O|
00002370  73 62 79 74 65 20 69 6e  64 69 72 65 63 74 69 6f  |sbyte indirectio|
00002380  6e 20 76 65 63 74 6f 72  0d 20 20 20 34 30 20 64  |n vector.   40 d|
00002390  72 62 3d 26 46 45 36 30  20 3a 52 45 4d 3a 20 64  |rb=&FE60 :REM: d|
000023a0  61 74 61 20 72 65 67 69  73 74 65 72 20 42 0d 20  |ata register B. |
000023b0  20 20 35 30 20 64 64 72  62 3d 26 46 45 36 32 20  |  50 ddrb=&FE62 |
000023c0  3a 52 45 4d 3a 20 64 61  74 61 20 64 69 72 65 63  |:REM: data direc|
000023d0  74 69 6f 6e 20 72 65 67  69 73 74 65 72 20 42 0d  |tion register B.|
000023e0  20 20 20 36 30 20 46 4f  52 20 70 61 73 73 3d 30  |   60 FOR pass=0|
000023f0  20 54 4f 20 32 20 53 54  45 50 20 32 0d 20 20 20  | TO 2 STEP 2.   |
00002400  37 30 20 50 25 3d 6d 63  6f 64 65 0d 20 20 20 38  |70 P%=mcode.   8|
00002410  30 20 5b 20 20 20 20 20  20 20 4f 50 54 20 70 61  |0 [       OPT pa|
00002420  73 73 0d 20 20 20 39 30  20 20 20 20 20 20 20 20  |ss.   90        |
00002430  20 4c 44 58 20 62 79 74  65 76 0d 20 20 31 30 30  | LDX bytev.  100|
00002440  20 20 20 20 20 20 20 20  20 4c 44 59 20 62 79 74  |         LDY byt|
00002450  65 76 2b 31 0d 20 20 31  31 30 20 20 20 20 20 20  |ev+1.  110      |
00002460  20 20 20 43 50 59 20 23  6e 65 77 69 6e 6b 65 79  |   CPY #newinkey|
00002470  20 44 49 56 20 32 35 36  0d 20 20 31 32 30 20 20  | DIV 256.  120  |
00002480  20 20 20 20 20 20 20 42  45 51 20 64 69 73 61 62  |       BEQ disab|
00002490  6c 65 20 20 20 5c 20 62  72 61 6e 63 68 20 69 66  |le   \ branch if|
000024a0  20 4f 73 62 79 74 65 20  76 65 63 74 6f 72 20 61  | Osbyte vector a|
000024b0  6c 74 65 72 65 64 0d 20  20 31 33 30 20 20 20 20  |ltered.  130    |
000024c0  20 20 20 20 20 53 54 58  20 6f 6c 64 62 79 74 65  |     STX oldbyte|
000024d0  76 20 20 5c 20 73 74 6f  72 65 20 6f 72 69 67 69  |v  \ store origi|
000024e0  6e 61 6c 20 4f 73 62 79  74 65 20 76 65 63 74 6f  |nal Osbyte vecto|
000024f0  72 0d 20 20 31 34 30 20  20 20 20 20 20 20 20 20  |r.  140         |
00002500  53 54 59 20 6f 6c 64 62  79 74 65 76 2b 31 0d 20  |STY oldbytev+1. |
00002510  20 31 35 30 20 20 20 20  20 20 20 20 20 4c 44 58  | 150         LDX|
00002520  20 23 6e 65 77 69 6e 6b  65 79 20 4d 4f 44 20 32  | #newinkey MOD 2|
00002530  35 36 0d 20 20 31 36 30  20 20 20 20 20 20 20 20  |56.  160        |
00002540  20 4c 44 59 20 23 6e 65  77 69 6e 6b 65 79 20 44  | LDY #newinkey D|
00002550  49 56 20 32 35 36 0d 20  20 31 37 30 20 20 20 20  |IV 256.  170    |
00002560  20 20 20 20 20 53 54 58  20 62 79 74 65 76 20 20  |     STX bytev  |
00002570  20 20 20 5c 20 69 6e 73  74 61 6c 6c 20 6e 65 77  |   \ install new|
00002580  20 4f 73 62 79 74 65 20  76 65 63 74 6f 72 0d 20  | Osbyte vector. |
00002590  20 31 38 30 20 20 20 20  20 20 20 20 20 53 54 59  | 180         STY|
000025a0  20 62 79 74 65 76 2b 31  0d 20 20 31 39 30 20 20  | bytev+1.  190  |
000025b0  20 20 20 20 20 20 20 4c  44 41 20 23 30 20 20 20  |       LDA #0   |
000025c0  20 20 20 20 20 5c 20 75  73 65 72 20 70 6f 72 74  |     \ user port|
000025d0  20 69 6e 70 75 74 0d 20  20 32 30 30 20 20 20 20  | input.  200    |
000025e0  20 20 20 20 20 53 54 41  20 64 64 72 62 20 20 20  |     STA ddrb   |
000025f0  20 20 20 5c 20 64 61 74  61 20 64 69 72 65 63 74  |   \ data direct|
00002600  69 6f 6e 20 72 65 67 69  73 74 65 72 20 42 0d 20  |ion register B. |
00002610  20 32 31 30 20 20 20 20  20 20 20 20 20 52 54 53  | 210         RTS|
00002620  20 20 20 20 20 20 20 20  20 20 20 5c 20 72 65 74  |           \ ret|
00002630  75 72 6e 20 74 6f 20 42  41 53 49 43 0d 20 20 32  |urn to BASIC.  2|
00002640  32 30 20 2e 64 69 73 61  62 6c 65 0d 20 20 32 33  |20 .disable.  23|
00002650  30 20 20 20 20 20 20 20  20 20 4c 44 58 20 6f 6c  |0         LDX ol|
00002660  64 62 79 74 65 76 20 20  5c 20 72 65 73 74 6f 72  |dbytev  \ restor|
00002670  65 20 4f 73 62 79 74 65  20 69 6e 64 69 72 65 63  |e Osbyte indirec|
00002680  74 69 6f 6e 20 76 65 63  74 6f 72 0d 20 20 32 34  |tion vector.  24|
00002690  30 20 20 20 20 20 20 20  20 20 4c 44 59 20 6f 6c  |0         LDY ol|
000026a0  64 62 79 74 65 76 2b 31  0d 20 20 32 35 30 20 20  |dbytev+1.  250  |
000026b0  20 20 20 20 20 20 20 53  54 58 20 62 79 74 65 76  |       STX bytev|
000026c0  0d 20 20 32 36 30 20 20  20 20 20 20 20 20 20 53  |.  260         S|
000026d0  54 59 20 62 79 74 65 76  2b 31 0d 20 20 32 37 30  |TY bytev+1.  270|
000026e0  20 20 20 20 20 20 20 20  20 52 54 53 20 20 20 20  |         RTS    |
000026f0  20 20 20 20 20 20 20 5c  20 72 65 74 75 72 6e 20  |       \ return |
00002700  74 6f 20 42 41 53 49 43  0d 20 20 32 38 30 20 2e  |to BASIC.  280 .|
00002710  6e 65 77 69 6e 6b 65 79  0d 20 20 32 39 30 20 20  |newinkey.  290  |
00002720  20 20 20 20 20 20 20 50  48 50 20 20 20 20 20 20  |       PHP      |
00002730  20 20 20 20 20 5c 20 70  75 73 68 20 73 74 61 74  |     \ push stat|
00002740  75 73 20 72 65 67 69 73  74 65 72 0d 20 20 33 30  |us register.  30|
00002750  30 20 20 20 20 20 20 20  20 20 43 4d 50 20 23 26  |0         CMP #&|
00002760  38 31 20 20 20 20 20 20  5c 20 69 73 20 74 68 69  |81      \ is thi|
00002770  73 20 4f 73 62 79 74 65  20 26 38 31 3f 0d 20 20  |s Osbyte &81?.  |
00002780  33 31 30 20 20 20 20 20  20 20 20 20 42 4e 45 20  |310         BNE |
00002790  6e 6f 74 69 6e 6b 65 79  20 20 5c 20 62 72 61 6e  |notinkey  \ bran|
000027a0  63 68 20 69 66 20 6e 6f  74 20 4f 73 62 79 74 65  |ch if not Osbyte|
000027b0  20 26 38 31 0d 20 20 33  32 30 20 20 20 20 20 20  | &81.  320      |
000027c0  20 20 20 43 50 59 20 23  26 46 46 20 20 20 20 20  |   CPY #&FF     |
000027d0  20 5c 20 69 73 20 74 68  69 73 20 61 20 2d 76 65  | \ is this a -ve|
000027e0  20 49 4e 4b 45 59 3f 0d  20 20 33 33 30 20 20 20  | INKEY?.  330   |
000027f0  20 20 20 20 20 20 42 45  51 20 69 6e 6b 65 79 20  |      BEQ inkey |
00002800  20 20 20 20 5c 20 62 72  61 6e 63 68 20 69 66 20  |    \ branch if |
00002810  2d 76 65 20 49 4e 4b 45  59 0d 20 20 33 34 30 20  |-ve INKEY.  340 |
00002820  2e 6e 6f 74 69 6e 6b 65  79 0d 20 20 33 35 30 20  |.notinkey.  350 |
00002830  20 20 20 20 20 20 20 20  50 4c 50 20 20 20 20 20  |        PLP     |
00002840  20 20 20 20 20 20 5c 20  70 75 6c 6c 20 73 74 61  |      \ pull sta|
00002850  74 75 73 20 72 65 67 69  73 74 65 72 0d 20 20 33  |tus register.  3|
00002860  36 30 20 2e 6f 6c 64 63  6f 64 65 0d 20 20 33 37  |60 .oldcode.  37|
00002870  30 20 20 20 20 20 20 20  20 20 4a 4d 50 20 28 6f  |0         JMP (o|
00002880  6c 64 62 79 74 65 76 29  20 5c 20 65 78 69 74 20  |ldbytev) \ exit |
00002890  76 69 61 20 6f 72 69 67  69 6e 61 6c 20 76 65 63  |via original vec|
000028a0  74 6f 72 0d 20 20 33 38  30 20 2e 69 6e 6b 65 79  |tor.  380 .inkey|
000028b0  0d 20 20 33 39 30 20 20  20 20 20 20 20 20 20 54  |.  390         T|
000028c0  58 41 20 20 20 20 20 20  20 20 20 20 20 5c 20 2d  |XA           \ -|
000028d0  76 65 20 49 4e 4b 45 59  20 76 61 6c 75 65 20 69  |ve INKEY value i|
000028e0  6e 20 58 20 72 65 67 69  73 74 65 72 0d 20 20 34  |n X register.  4|
000028f0  30 30 20 20 20 20 20 20  20 20 20 50 48 41 20 20  |00         PHA  |
00002900  20 20 20 20 20 20 20 20  20 5c 20 70 75 73 68 20  |         \ push |
00002910  58 20 6f 6e 74 6f 20 73  74 61 63 6b 0d 20 20 34  |X onto stack.  4|
00002920  31 30 20 20 20 20 20 20  20 20 20 4c 44 41 20 23  |10         LDA #|
00002930  26 38 31 0d 20 20 34 32  30 20 20 20 20 20 20 20  |&81.  420       |
00002940  20 20 4a 53 52 20 6f 6c  64 63 6f 64 65 20 20 20  |  JSR oldcode   |
00002950  5c 20 65 78 65 63 75 74  65 20 6f 72 69 67 69 6e  |\ execute origin|
00002960  61 6c 20 63 6f 64 65 0d  20 20 34 33 30 20 20 20  |al code.  430   |
00002970  20 20 20 20 20 20 43 50  58 20 23 26 46 46 20 20  |      CPX #&FF  |
00002980  20 20 20 20 5c 20 6b 65  79 20 70 72 65 73 73 65  |    \ key presse|
00002990  64 20 69 66 20 58 20 61  6e 64 20 59 20 3d 26 46  |d if X and Y =&F|
000029a0  46 0d 20 20 34 34 30 20  20 20 20 20 20 20 20 20  |F.  440         |
000029b0  42 4e 45 20 6e 6f 74 70  72 65 73 73 65 64 20 5c  |BNE notpressed \|
000029c0  20 62 72 61 6e 63 68 20  69 66 20 6b 65 79 20 6e  | branch if key n|
000029d0  6f 74 20 70 72 65 73 73  65 64 0d 20 20 34 35 30  |ot pressed.  450|
000029e0  20 20 20 20 20 20 20 20  20 43 50 59 20 23 26 46  |         CPY #&F|
000029f0  46 20 20 20 20 20 20 5c  20 6b 65 79 20 70 72 65  |F      \ key pre|
00002a00  73 73 65 64 20 69 66 20  58 20 61 6e 64 20 59 20  |ssed if X and Y |
00002a10  3d 26 46 46 0d 20 20 34  36 30 20 20 20 20 20 20  |=&FF.  460      |
00002a20  20 20 20 42 4e 45 20 6e  6f 74 70 72 65 73 73 65  |   BNE notpresse|
00002a30  64 20 5c 20 62 72 61 6e  63 68 20 69 66 20 6b 65  |d \ branch if ke|
00002a40  79 20 6e 6f 74 20 70 72  65 73 73 65 64 0d 20 20  |y not pressed.  |
00002a50  34 37 30 20 20 20 20 20  20 20 20 20 50 4c 41 20  |470         PLA |
00002a60  20 20 20 20 20 20 20 20  20 20 5c 20 70 75 6c 6c  |          \ pull|
00002a70  20 58 20 6f 66 66 20 73  74 61 63 6b 0d 20 20 34  | X off stack.  4|
00002a80  38 30 20 2e 70 75 6c 6c  6f 75 74 0d 20 20 34 39  |80 .pullout.  49|
00002a90  30 20 20 20 20 20 20 20  20 20 4c 44 41 20 23 26  |0         LDA #&|
00002aa0  38 31 20 20 20 20 20 20  5c 20 72 65 73 74 6f 72  |81      \ restor|
00002ab0  65 20 41 0d 20 20 35 30  30 20 20 20 20 20 20 20  |e A.  500       |
00002ac0  20 20 50 4c 50 20 20 20  20 20 20 20 20 20 20 20  |  PLP           |
00002ad0  5c 20 72 65 73 74 6f 72  65 20 73 74 61 74 75 73  |\ restore status|
00002ae0  20 72 65 67 69 73 74 65  72 0d 20 20 35 31 30 20  | register.  510 |
00002af0  20 20 20 20 20 20 20 20  52 54 53 20 20 20 20 20  |        RTS     |
00002b00  20 20 20 20 20 20 5c 20  72 65 74 75 72 6e 20 74  |      \ return t|
00002b10  6f 20 6f 70 65 72 61 74  69 6e 67 20 73 79 73 74  |o operating syst|
00002b20  65 6d 0d 20 20 35 32 30  20 2e 6e 6f 74 70 72 65  |em.  520 .notpre|
00002b30  73 73 65 64 0d 20 20 35  33 30 20 20 20 20 20 20  |ssed.  530      |
00002b40  20 20 20 50 4c 41 20 20  20 20 20 20 20 20 20 20  |   PLA          |
00002b50  20 5c 20 70 75 6c 6c 20  2d 76 65 20 49 4e 4b 45  | \ pull -ve INKE|
00002b60  59 20 6e 75 6d 62 65 72  20 6f 66 66 20 73 74 61  |Y number off sta|
00002b70  63 6b 0d 20 20 35 34 30  20 20 20 20 20 20 20 20  |ck.  540        |
00002b80  20 43 4d 50 20 63 65 6e  74 72 65 20 20 20 20 5c  | CMP centre    \|
00002b90  20 63 6f 6d 70 61 72 65  20 77 69 74 68 20 6e 75  | compare with nu|
00002ba0  6d 62 65 72 20 61 6c 6c  6f 63 61 74 65 64 20 74  |mber allocated t|
00002bb0  6f 20 63 65 6e 74 72 65  0d 20 20 20 20 20 20 20  |o centre.       |
00002bc0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00002bd0  20 20 20 20 20 5c 20 6d  6f 75 73 65 20 62 75 74  |     \ mouse but|
00002be0  74 6f 6e 0d 20 20 35 35  30 20 20 20 20 20 20 20  |ton.  550       |
00002bf0  20 20 42 4e 45 20 74 72  79 72 69 67 68 74 20 20  |  BNE tryright  |
00002c00  5c 20 62 72 61 6e 63 68  20 69 66 20 6e 6f 74 20  |\ branch if not |
00002c10  63 65 6e 74 72 65 20 62  75 74 74 6f 6e 0d 20 20  |centre button.  |
00002c20  35 36 30 20 20 20 20 20  20 20 20 20 4c 44 41 20  |560         LDA |
00002c30  64 72 62 20 20 20 20 20  20 20 5c 20 64 61 74 61  |drb       \ data|
00002c40  20 72 65 67 69 73 74 65  72 20 42 0d 20 20 35 37  | register B.  57|
00002c50  30 20 20 20 20 20 20 20  20 20 4a 4d 50 20 74 77  |0         JMP tw|
00002c60  6f 20 20 20 20 20 20 20  5c 20 63 68 65 63 6b 20  |o       \ check |
00002c70  62 69 74 20 36 0d 20 20  35 38 30 20 2e 74 72 79  |bit 6.  580 .try|
00002c80  72 69 67 68 74 0d 20 20  35 39 30 20 20 20 20 20  |right.  590     |
00002c90  20 20 20 20 43 4d 50 20  72 69 67 68 74 20 20 20  |    CMP right   |
00002ca0  20 20 5c 20 63 6f 6d 70  61 72 65 20 77 69 74 68  |  \ compare with|
00002cb0  20 6e 75 6d 62 65 72 20  61 6c 6c 6f 63 61 74 65  | number allocate|
00002cc0  64 20 74 6f 20 72 69 67  68 74 0d 20 20 20 20 20  |d to right.     |
00002cd0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00002ce0  20 20 20 20 20 20 20 5c  20 6d 6f 75 73 65 20 62  |       \ mouse b|
00002cf0  75 74 74 6f 6e 0d 20 20  36 30 30 20 20 20 20 20  |utton.  600     |
00002d00  20 20 20 20 42 4e 45 20  74 72 79 6c 65 66 74 20  |    BNE tryleft |
00002d10  20 20 5c 20 62 72 61 6e  63 68 20 69 66 20 6e 6f  |  \ branch if no|
00002d20  74 20 72 69 67 68 74 20  62 75 74 74 6f 6e 0d 20  |t right button. |
00002d30  20 36 31 30 20 20 20 20  20 20 20 20 20 4c 44 41  | 610         LDA|
00002d40  20 64 72 62 20 20 20 20  20 20 20 5c 20 64 61 74  | drb       \ dat|
00002d50  61 20 72 65 67 69 73 74  65 72 20 42 0d 20 20 36  |a register B.  6|
00002d60  32 30 20 20 20 20 20 20  20 20 20 4a 4d 50 20 6f  |20         JMP o|
00002d70  6e 65 20 20 20 20 20 20  20 5c 20 63 68 65 63 6b  |ne       \ check|
00002d80  20 62 69 74 20 37 0d 20  20 36 33 30 20 2e 74 72  | bit 7.  630 .tr|
00002d90  79 6c 65 66 74 0d 20 20  36 34 30 20 20 20 20 20  |yleft.  640     |
00002da0  20 20 20 20 43 4d 50 20  6c 65 66 74 20 20 20 20  |    CMP left    |
00002db0  20 20 5c 20 63 6f 6d 70  61 72 65 20 77 69 74 68  |  \ compare with|
00002dc0  20 6e 75 6d 62 65 72 20  61 6c 6c 6f 63 61 74 65  | number allocate|
00002dd0  64 20 74 6f 20 6c 65 66  74 0d 20 20 20 20 20 20  |d to left.      |
00002de0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00002df0  20 20 20 20 20 20 5c 20  6d 6f 75 73 65 20 62 75  |      \ mouse bu|
00002e00  74 74 6f 6e 0d 20 20 36  35 30 20 20 20 20 20 20  |tton.  650      |
00002e10  20 20 20 42 4e 45 20 70  75 6c 6c 6f 75 74 20 20  |   BNE pullout  |
00002e20  20 5c 20 65 78 69 74 20  69 66 20 6e 6f 74 20 6c  | \ exit if not l|
00002e30  65 66 74 20 62 75 74 74  6f 6e 0d 20 20 36 36 30  |eft button.  660|
00002e40  20 20 20 20 20 20 20 20  20 4c 44 41 20 64 72 62  |         LDA drb|
00002e50  20 20 20 20 20 20 20 5c  20 64 61 74 61 20 72 65  |       \ data re|
00002e60  67 69 73 74 65 72 20 42  0d 20 20 36 37 30 20 20  |gister B.  670  |
00002e70  20 20 20 20 20 20 20 52  4f 4c 20 41 20 20 20 20  |       ROL A    |
00002e80  20 20 20 20 20 5c 20 62  69 74 20 37 20 69 6e 74  |     \ bit 7 int|
00002e90  6f 20 63 61 72 72 79 0d  20 20 36 38 30 20 2e 74  |o carry.  680 .t|
00002ea0  77 6f 0d 20 20 36 39 30  20 20 20 20 20 20 20 20  |wo.  690        |
00002eb0  20 52 4f 4c 20 41 20 20  20 20 20 20 20 20 20 5c  | ROL A         \|
00002ec0  20 62 69 74 20 36 2f 37  20 69 6e 74 6f 20 63 61  | bit 6/7 into ca|
00002ed0  72 72 79 0d 20 20 37 30  30 20 2e 6f 6e 65 0d 20  |rry.  700 .one. |
00002ee0  20 37 31 30 20 20 20 20  20 20 20 20 20 52 4f 4c  | 710         ROL|
00002ef0  20 41 20 20 20 20 20 20  20 20 20 5c 20 62 69 74  | A         \ bit|
00002f00  20 35 2f 36 2f 37 20 69  6e 74 6f 20 63 61 72 72  | 5/6/7 into carr|
00002f10  79 0d 20 20 37 32 30 20  20 20 20 20 20 20 20 20  |y.  720         |
00002f20  42 43 53 20 70 75 6c 6c  6f 75 74 20 20 20 5c 20  |BCS pullout   \ |
00002f30  65 78 69 74 20 69 66 20  62 69 74 20 35 2f 36 2f  |exit if bit 5/6/|
00002f40  37 20 73 65 74 0d 20 20  37 33 30 20 2e 66 6f 75  |7 set.  730 .fou|
00002f50  6e 64 0d 20 20 37 34 30  20 20 20 20 20 20 20 20  |nd.  740        |
00002f60  20 4c 44 41 20 23 26 38  31 20 20 20 20 20 20 5c  | LDA #&81      \|
00002f70  20 4f 73 62 79 74 65 20  26 38 31 0d 20 20 37 35  | Osbyte &81.  75|
00002f80  30 20 20 20 20 20 20 20  20 20 4c 44 58 20 23 26  |0         LDX #&|
00002f90  46 46 20 20 20 20 20 20  5c 20 58 20 61 6e 64 20  |FF      \ X and |
00002fa0  59 20 3d 20 26 46 46 20  77 68 65 6e 20 6b 65 79  |Y = &FF when key|
00002fb0  20 70 72 65 73 73 65 64  0d 20 20 37 36 30 20 20  | pressed.  760  |
00002fc0  20 20 20 20 20 20 20 4c  44 59 20 23 26 46 46 0d  |       LDY #&FF.|
00002fd0  20 20 37 37 30 20 20 20  20 20 20 20 20 20 50 4c  |  770         PL|
00002fe0  50 20 20 20 20 20 20 20  20 20 20 20 5c 20 70 75  |P           \ pu|
00002ff0  6c 6c 20 73 74 61 74 75  73 20 72 65 67 69 73 74  |ll status regist|
00003000  65 72 0d 20 20 37 38 30  20 20 20 20 20 20 20 20  |er.  780        |
00003010  20 52 54 53 20 20 20 20  20 20 20 20 20 20 20 5c  | RTS           \|
00003020  20 72 65 74 75 72 6e 20  74 6f 20 6f 70 65 72 61  | return to opera|
00003030  74 69 6e 67 20 73 79 73  74 65 6d 0d 20 20 37 39  |ting system.  79|
00003040  30 20 2e 6f 6c 64 62 79  74 65 76 0d 20 20 38 30  |0 .oldbytev.  80|
00003050  30 20 20 20 20 20 20 20  20 20 45 51 55 57 20 26  |0         EQUW &|
00003060  30 30 20 20 20 20 20 20  5c 20 6f 72 69 67 69 6e  |00      \ origin|
00003070  61 6c 20 4f 73 62 79 74  65 20 69 6e 64 69 72 65  |al Osbyte indire|
00003080  63 74 69 6f 6e 20 76 65  63 74 6f 72 0d 20 20 38  |ction vector.  8|
00003090  31 30 20 2e 72 69 67 68  74 0d 20 20 38 32 30 20  |10 .right.  820 |
000030a0  20 20 20 20 20 20 20 20  45 51 55 42 20 2d 36 37  |        EQUB -67|
000030b0  20 20 20 20 20 20 5c 20  2d 76 65 20 49 4e 4b 45  |      \ -ve INKE|
000030c0  59 20 66 6f 72 20 58 0d  20 20 38 33 30 20 2e 63  |Y for X.  830 .c|
000030d0  65 6e 74 72 65 0d 20 20  38 34 30 20 20 20 20 20  |entre.  840     |
000030e0  20 20 20 20 45 51 55 42  20 2d 37 34 20 20 20 20  |    EQUB -74    |
000030f0  20 20 5c 20 2d 76 65 20  49 4e 4b 45 59 20 66 6f  |  \ -ve INKEY fo|
00003100  72 20 3c 72 65 74 75 72  6e 3e 0d 20 20 38 35 30  |r <return>.  850|
00003110  20 2e 6c 65 66 74 0d 20  20 38 36 30 20 20 20 20  | .left.  860    |
00003120  20 20 20 20 20 45 51 55  42 20 2d 39 38 20 20 20  |     EQUB -98   |
00003130  20 20 20 5c 20 2d 76 65  20 49 4e 4b 45 59 20 66  |   \ -ve INKEY f|
00003140  6f 72 20 5a 0d 20 20 38  37 30 20 2e 6c 61 73 74  |or Z.  870 .last|
00003150  62 79 74 65 0d 20 20 38  38 30 20 5d 0d 20 20 38  |byte.  880 ].  8|
00003160  39 30 20 4e 45 58 54 0d  20 20 39 30 30 20 43 41  |90 NEXT.  900 CA|
00003170  4c 4c 20 6d 63 6f 64 65  20 3a 52 45 4d 3a 20 65  |LL mcode :REM: e|
00003180  6e 61 62 6c 65 20 6e 65  77 20 63 6f 64 65 0d 20  |nable new code. |
00003190  20 39 31 30 20 4d 4f 44  45 37 0d 20 20 39 32 30  | 910 MODE7.  920|
000031a0  20 6d 6f 75 73 65 24 3d  43 48 52 24 31 34 31 2b  | mouse$=CHR$141+|
000031b0  43 48 52 24 31 33 32 2b  43 48 52 24 31 35 37 2b  |CHR$132+CHR$157+|
000031c0  43 48 52 24 31 33 31 0d  20 20 20 20 20 20 2b 22  |CHR$131.      +"|
000031d0  50 72 65 73 73 20 6b 65  79 62 6f 61 72 64 20 6f  |Press keyboard o|
000031e0  72 20 6d 6f 75 73 65 20  62 75 74 74 6f 6e 73 20  |r mouse buttons |
000031f0  20 22 2b 43 48 52 24 31  35 36 0d 20 20 39 33 30  | "+CHR$156.  930|
00003200  20 50 52 49 4e 54 54 41  42 28 30 2c 32 29 6d 6f  | PRINTTAB(0,2)mo|
00003210  75 73 65 24 0d 20 20 39  34 30 20 50 52 49 4e 54  |use$.  940 PRINT|
00003220  54 41 42 28 30 2c 33 29  6d 6f 75 73 65 24 0d 20  |TAB(0,3)mouse$. |
00003230  20 39 35 30 20 4f 4e 45  52 52 4f 52 20 47 4f 54  | 950 ONERROR GOT|
00003240  4f 20 31 30 33 30 0d 20  20 39 36 30 20 56 44 55  |O 1030.  960 VDU|
00003250  32 33 2c 31 2c 30 3b 30  3b 30 3b 30 3b 0d 20 20  |23,1,0;0;0;0;.  |
00003260  39 37 30 20 52 45 50 45  41 54 0d 20 20 39 38 30  |970 REPEAT.  980|
00003270  20 49 46 20 49 4e 4b 45  59 28 2d 36 37 29 20 50  | IF INKEY(-67) P|
00003280  52 49 4e 54 54 41 42 28  32 36 2c 31 32 29 22 58  |RINTTAB(26,12)"X|
00003290  22 20 45 4c 53 45 20 50  52 49 4e 54 54 41 42 28  |" ELSE PRINTTAB(|
000032a0  32 36 2c 31 32 29 22 20  22 0d 20 20 39 39 30 20  |26,12)" ".  990 |
000032b0  49 46 20 49 4e 4b 45 59  28 2d 37 34 29 20 50 52  |IF INKEY(-74) PR|
000032c0  49 4e 54 54 41 42 28 31  36 2c 31 32 29 22 52 65  |INTTAB(16,12)"Re|
000032d0  74 75 72 6e 22 20 45 4c  53 45 20 50 52 49 4e 54  |turn" ELSE PRINT|
000032e0  54 41 42 28 31 36 2c 31  32 29 22 20 20 20 20 20  |TAB(16,12)"     |
000032f0  20 22 0d 20 31 30 30 30  20 49 46 20 49 4e 4b 45  | ". 1000 IF INKE|
00003300  59 28 2d 39 38 29 20 50  52 49 4e 54 54 41 42 28  |Y(-98) PRINTTAB(|
00003310  31 31 2c 31 32 29 22 5a  22 20 45 4c 53 45 20 50  |11,12)"Z" ELSE P|
00003320  52 49 4e 54 54 41 42 28  31 31 2c 31 32 29 22 20  |RINTTAB(11,12)" |
00003330  22 0d 20 31 30 31 30 20  49 46 20 49 4e 4b 45 59  |". 1010 IF INKEY|
00003340  28 2d 39 39 29 20 50 52  49 4e 54 54 41 42 28 31  |(-99) PRINTTAB(1|
00003350  36 2c 31 37 29 22 53 70  61 63 65 22 20 45 4c 53  |6,17)"Space" ELS|
00003360  45 20 50 52 49 4e 54 54  41 42 28 31 36 2c 31 37  |E PRINTTAB(16,17|
00003370  29 22 20 20 20 20 20 22  0d 20 31 30 32 30 20 55  |)"     ". 1020 U|
00003380  4e 54 49 4c 20 46 41 4c  53 45 0d 20 31 30 33 30  |NTIL FALSE. 1030|
00003390  20 43 41 4c 4c 20 6d 63  6f 64 65 20 3a 52 45 4d  | CALL mcode :REM|
000033a0  3a 20 64 69 73 61 62 6c  65 20 6e 65 77 20 63 6f  |: disable new co|
000033b0  64 65 0d 20 31 30 34 30  20 56 44 55 32 33 2c 31  |de. 1040 VDU23,1|
000033c0  2c 31 3b 30 3b 30 3b 30  3b 33 31 2c 30 2c 32 33  |,1;0;0;0;31,0,23|
000033d0  0d 20 31 30 35 30 20 45  4e 44 0d                 |. 1050 END.|
000033db
11-12-88/T\MOU03.m0
11-12-88/T\MOU03.m1
11-12-88/T\MOU03.m2
11-12-88/T\MOU03.m4
11-12-88/T\MOU03.m5