home *** CD-ROM | disk | FTP | other *** search
/ Amoszine 4 / Amoszine 4 (Disk 1 of 3).adf / READERS_SOURCE.LHA / READERS_SOURCE / Paul_Overy's_code / readMouse.AMOS / readMouse.amosSourceCode
Encoding:
AMOS Source Code  |  1992-02-26  |  6.3 KB  |  201 lines

  1. 'Program  : Read mouse registers (all Amiga's)   
  2. 'Carbon14 : Paul Overy   
  3. '  
  4. 'I wrote this program after seeing the sticks extension which was
  5. 'rather amusingly priced at ï¿½10.  Sticks allows you to read the  
  6. 'mouse with the multitasking system turned off.
  7. 'This program does not cover all the Sticks commands can but it should   
  8. 'do all you will ever really neeed to know.  As half the commands in 
  9. 'Sticks will only be used by 1% of Amos users. 
  10. '
  11. 'Hmmm, might have a go at writing an extension, think all call it PDsticks.  
  12. '
  13. 'Oh yeh, this program also shows you how to draw to just one bitplane    
  14. '
  15. '(Buy the Turbo Plus Extension for Amos & Amos pro.) 
  16. '(It cuts down on code & speeds up Amos.           )   
  17. '(I hate writing code without turbo instructions.  )   
  18. '
  19. Screen Open 0,320,256,4,Lowres : Flash Off : Curs Off : Palette 0,$222,$FFF,$F0F
  20. Get Sprite 1,0,0 To 16,16
  21. Centre Border$("Mouse Registers by Paul Overy",1)
  22. Text 0,30,"Horizontal position counter."
  23. Text 0,40,"Vertical position counter..."
  24. Text 0,50,"Left button................."
  25. Text 0,60,"Right button................"
  26. Text 0,100,"Left draw plane 1  (does not draw over text)"
  27. Text 0,110,"Right draw plane 0 (draws only on text)"
  28. Text 0,140,"Both mouse buttons to quit"
  29. Text 0,160,"Amos can't do this with the multitasking "
  30. Text 0,170,"system turned off"
  31. Text 0,180,"i.e   X mouse ="
  32. Text 0,190,"      Y mouse =       No values returned"
  33. MX=160 : MY=100
  34. OLD_MX=MX : OLD_MY=MY
  35. Doke $DFF036,0 : Rem Reset both mouse counters  
  36. Change Mouse 2
  37. '
  38. '*** Turn of multi task system, programs run faster now ***  
  39. NULL=Execall(-132)
  40. '  
  41. Repeat 
  42.    '*** Read mouse regesters ***
  43.    'Because the pointers are so small extra work now needs to 
  44.    'be carried out on them. 
  45.    Y_BYTE=Peek($DFF00A) : Rem like "x mouse" but only values 0-255 
  46.    X_BYTE=Peek($DFF00B) : Rem like "y mouse" but only values 0-255 
  47.    'Read mouse buttons
  48.    LEFT_CLICK=(Btst(6,$BFE001)=0)
  49.    RIGHT_CLICK=(Btst(10,$DFF016)=0)
  50.    'Port 2 mouse, bits 7 & 14 with $dff00c & $dff00d
  51.    '
  52.    '*** display info ***
  53.    Ink 2,1
  54.    Text 168,30,Str$(X_BYTE)-" "+"  "
  55.    Text 168,40,Str$(Y_BYTE)-" "+"  "
  56.    Text 168,50,Str$(LEFT_CLICK)
  57.    Text 168,60,Str$(RIGHT_CLICK)
  58.    Text 88,180,Str$(X Mouse)
  59.    Text 88,190,Str$(Y Mouse)
  60.    '
  61.    '*** mouse controll system *** 
  62.    'Extra work to convert mouse byte pointers, to screen size.
  63.    DX=X_BYTE-OX : DY=Y_BYTE-OY : OX=X_BYTE : OY=Y_BYTE
  64.    'check for under/overflow correct with difference  
  65.    '2 if's could be used here,ie. Abs(DX)>127 then reseting mouse difference      
  66.    'But this is one of the better methods 
  67.    If DX<-127 Then DX=256+DX
  68.    If DX>127 Then DX=DX-256
  69.    If DY<-127 Then DY=256+DY
  70.    If DY>127 Then DY=DY-256
  71.    Add MX,DX : Add MY,DY
  72.    '
  73.    '*** Keep cursor inside screen *** 
  74.    'This cuts down on 4 if's
  75.    MY=Max(Min(MY,255),0)
  76.    MX=Max(Min(MX,319),0)
  77.    '
  78.    ' Move mouse pointer using new Mouse Driver values   
  79.    '   X Mouse=X Hard(MX) :rem if you want to move Amos pointer 
  80.    '   Y Mouse=Y Hard(MY) 
  81.    Sprite 2,X Hard(MX),Y Hard(MY),1
  82.    If LEFT_CLICK
  83.       LINE_ONE_PLANE[OLD_MX,OLD_MY,MX,MY,1]
  84.    Else 
  85.       If RIGHT_CLICK
  86.          LINE_ONE_PLANE[OLD_MX,OLD_MY,MX,MY,0]
  87.       Else 
  88.          '         Hslider 20,251 To 275,255,256,X_BYTE,0 
  89.          '         Vslider 315,0 To 319,255,256,Y_BYTE,0
  90.       End If 
  91.    End If 
  92.    OLD_MX=MX : OLD_MY=MY : Rem for connecting line
  93. Until LEFT_CLICK and RIGHT_CLICK
  94. '
  95. NULL=Execall(-138)
  96. '
  97. '
  98. Procedure LINE_ONE_PLANE[X1,Y1,X2,Y2,PLANE]
  99.    '
  100.    'Oh'my whats this? 
  101.    'I think its a ID header for a procedure 
  102.    'Yes thats right..... Come on you people you don't 
  103.    'write a procedure and let people guess the rest.  
  104.    '
  105.    '***************************************   
  106.    '* Procedure: Draw line on 1 bitplane. * 
  107.    '*     Bloke: Paul Overy               * 
  108.    '*    Inputs: X1,Y1 = starting points  *   
  109.    '*            X2,Y2 = end points       *   
  110.    '*            PLANE = 0 to 4           * 
  111.    '*   Outputs: None                     * 
  112.    '*                                     * 
  113.    '* NOTE: No error checking is done.    * 
  114.    '* Make sure a plane is there before   * 
  115.    '* you wrire to it.                    * 
  116.    '*                                     *   
  117.    '* ie. 4col screen has 2 planes        *   
  118.    '*     8col screen has 3 planes        * 
  119.    '*    16col screen has 4 planes        * 
  120.    '*    32col screen has 5 planes        * 
  121.    '*                                     * 
  122.    '* Dont forget planes start at ZERO.   * 
  123.    '*************************************** 
  124.    '    
  125.    PRE_CALC=Screen Width/8
  126.    PH=Phybase(PLANE)
  127.    XD=X2-X1
  128.    YD=Y2-Y1
  129.    SS=1
  130.    If XD<0
  131.       XD=Abs(XD)
  132.       SS=-SS
  133.    End If 
  134.    If YD<0
  135.       YD=Abs(YD)
  136.       SS=-SS
  137.    End If 
  138.    If XD>YD
  139.       CC=XD/2
  140.       If X1>X2
  141.          Swap X1,X2
  142.          Swap Y1,Y2
  143.       End If 
  144.       YT=Y1
  145.       For XT=X1 To X2
  146.          P=Peek(XT/8+YT*PRE_CALC+PH)
  147.          Bset(7-(XT-(XT/8*8))),P
  148.          Poke(XT/8+YT*PRE_CALC+PH),P
  149.          Add CC,YD
  150.          If CC>XD
  151.             Add YT,SS
  152.             Add CC,-XD
  153.          End If 
  154.       Next XT
  155.    Else 
  156.       CC=YD/2
  157.       If Y1>Y2
  158.          Swap Y1,Y2
  159.          Swap X1,X2
  160.       End If 
  161.       XT=X1
  162.       For YT=Y1 To Y2
  163.          P=Peek(XT/8+YT*PRE_CALC+PH)
  164.          Bset(7-(XT-(XT/8*8))),P
  165.          Poke(XT/8+YT*PRE_CALC+PH),P
  166.          Add CC,XD
  167.          If CC>=YD
  168.             Add XT,SS
  169.             Add CC,-YD
  170.          End If 
  171.       Next YT
  172.    End If 
  173. End Proc
  174. Procedure _PLOT[X,Y,PLANE]
  175.    '
  176.    '***************************************   
  177.    '* Procedure: Plot pixel on 1 bitplane * 
  178.    '*     Bloke: Paul Overy               * 
  179.    '*    Inputs: X,Y = pixel location     *   
  180.    '*            PLANE = 0 to 4           * 
  181.    '*   Outputs: None                     * 
  182.    '*                                     * 
  183.    '* NOTE: No error checking is done.    * 
  184.    '* Make sure a plane is there before   * 
  185.    '* you wrire to it.                    * 
  186.    '*                                     *   
  187.    '* ie. 4col screen has 2 planes        *   
  188.    '*     8col screen has 3 planes        * 
  189.    '*    16col screen has 4 planes        * 
  190.    '*    32col screen has 5 planes        * 
  191.    '*                                     * 
  192.    '* Dont forget planes start at ZERO.   * 
  193.    '*************************************** 
  194.    '    
  195.    PRE_CALC=Screen Width/8
  196.    PH=Phybase(PLANE)
  197.    XC=X/8
  198.    P=Peek(XC+Y*PRE_CALC+PH)
  199.    Bset(7-(X-(XC*8))),P
  200.    Poke(XC+Y*PRE_CALC+PH),P
  201. End Proc