
                            E0B3P0 MACHINE CODE WITH AMOS B0P1E3
P4

This machine code support program was written for two reasons:-
P2
        1. I was fed up with a locked up mouse when using
           "Multi No" under the Turbo+ extension, which is much
           the same as using the e=execall(-132) in Amos.
           
        2. My Amos version corrected this problem, but this method was
           slowing things down.  So I wrote the MC version.
P5           
           
The Ultimate Amiga Reference was great for helping me carry out this task.
It shows all the internal registers in the Amiga, such as the locations
of the mouse input ports.  Without it I would have been completely in the dark.

First off, I'll start with the Amos version as an example.
Both the Amos and the MC routines make use of the registers which hold the
mouse port information.  This has to be done, as its the only way to get hold
of the mouse values with "multi no".
You may ask why bother using "multi no", well in some cases its speeds up
programs by about 40%, but around 20% is the norm.
P3
                                 E0 Example In Amos E1
P4

        X=100 : Y=100
        Do 
           _MOUSE_OX=_MOUSE_SX
           _MOUSE_OY=_MOUSE_SY
           _MOUSE_SX=Peek($DFE00B)
           _MOUSE_SY=Peek($DFE00A)
           If _MOUSE_SX<>_MOUSE_OX or _MOUSE_SY<>_MOUSE_OY
              _MOVE_X=_MOUSE_SX-_MOUSE_OX
              _MOVE_Y=_MOUSE_SY-_MOUSE_OY
              '
              If _MOVE_X<-127
                 _MOVE_X=256+_MOVE_X
              End If 
              If _MOVE_X>127
                 _MOVE_X=_MOVE_X-256
              End If 
              '
              If _MOVE_Y<-127
                 _MOVE_Y=256+_MOVE_Y
              End If 
              If _MOVE_Y>127
                 _MOVE_Y=_MOVE_Y-256
              End If 
              '
              Add X,_MOVE_X
              Add Y,_MOVE_Y
              '
              Plot X,Y
           End If 
        Loop

P5
               P0B1 Mouse Registers held in the Amiga's memory are B0P1
P0
        B3 Mouse X-Axis & Y-Axis B0P5
        Location $dfe00b <byte>, holds x mouse counter.
        Location $df300a <byte>, holds y mouse counter.

        B3P0 Mouse Left & Right button B0P5
        Location $dff016 <byte>, Bit 10  holds Right button.
        Location $bfe001 <byte>, Bit  6 holds left button.



P0B3The MC program below, follows the same method B0
P6
NOTE:This routine is to be found in Paul_Overys_code, named Mouse.asm
P5
;Mouse driver for use with Amos with Multi No or "nil=Execall(-132)"
;
;Author: Paul Overy -95- Ver2
;My very first MC program.

TEST_X: move.b  x,ox
        move.b  $dff00b,d0
        move.b  d0,x
        move.b  ox,d1
        sub.l   d1,d0
        bmi.s   X_NEG
        bpl.s   X_POS
        
TEST_Y: move.b  y,oy
        move.b  $dff00a,d2
        move.b  d2,y
        move.b  oy,d3
        sub.l   d3,d2
        bmi.s   Y_NEG
        bpl.s   Y_POS
        bra.s   CLIP
        
X_POS:  cmp     #127,d0
        blt.s   TEST_Y
        sub.l   #256,d0
        bra.s   TEST_Y
        

X_NEG:  cmp     #-127,d0
        bgt.s   TEST_Y
        add.l   #256,d0
        bra     TEST_Y
       
Y_POS:  cmp     #127,d2
        blt.s   CLIP
        sub.l   #256,d2
        bra.s   CLIP
        
Y_NEG:  cmp     #-127,d2
        BGT.s   CLIP
        add.l   #256,d2
        
CLIP:   add.l   d0,d4
        cmp     #128,d4
        bgt.s   INSIDE_SCREEN_X1
        move.l #128,d4
        INSIDE_SCREEN_X1:
        cmp 	#446,d4
        blt.s   INSIDE_SCREEN_X2
        move.l  #446,d4
        INSIDE_SCREEN_X2:

        add.l   d2,d5
        cmp     #51,d5
        bgt.s   INSIDE_SCREEN_Y1
        moveq.l #51,d5
        INSIDE_SCREEN_Y1:
        cmp     #290,d5
        blt.s   INSIDE_SCREEN_Y2
        move.l  #290,d5
        INSIDE_SCREEN_Y2:
        rts
        
        EVEN               
x       dc.w	0
y       dc.w    0
ox      dc.w    0
oy      dc.w    0


P3Before use, the MC program must be:-
P5        
        * Assembled (using DevPac is fine)
        
Then under Amos you must then:-
        
        * Load Code into a bank  (i.e Pload "mouse",10) 
        
To Run under Amos:-

        First Clear Dreg(0)..Dreg(3) at top of Amos program.
        * Dreg(0)=0
        * Dreg(1)=0
        * Dreg(2)=0
        * Dreg(3)=0
        
and call this in your loop:-
        * Call 10
        * X=Dreg(4)  ' Acts just like "X Mouse"
        * Y=Dreg(5)  ' Acts just like "Y Mouse"

        

P3           E0 Below is a full example in Amos, using the MC routine. E1
P4

Pload "RAM:mouse",10   'Place code in bank, only needs to be done once.
                       'Rem out above line after first run.
Dreg(0)=0:Dreg(1)=0    'Clear (not Automatic in Amos Pro)
Dreg(2)=0:Dreg(3)=0

E=Execall(-132)  'Switch Multitasking off

Do
   Call 10       'Run MC program in bank 10
   X=Dreg(4)     'Store results
   Y=dreg(5)     '  "     "
   
   _RIGHT_CLICK=Not Btst(10,$dff016)
   _LEFT_CLICK=Not Btst(6,$bfe001)
      
   If _RIGHT_CLICK
      plot X,Y
   End If
Loop
E=Execall(-138)  'Switch Multitasking back on.
