home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d6xx / d602 / mbpress.lha / MBPress / Source / MBPress.asm
Assembly Source File  |  1992-02-20  |  4KB  |  123 lines

  1. **********************  MBPress.asm  ******************************
  2.  
  3. ; by Steve Anderson on Jan 28, 1992
  4. ; using the Dvpac Assembler
  5.  
  6. ; Purpose:
  7. ;  - little CLI command to detect mouse button presses for
  8. ;    gameport 1 (unit 0)
  9.  
  10. ; Return:
  11. ;  - 0 for no button pressed
  12. ;  - 1 (or 001b) for lmb
  13. ;  - 2 (or 010b) for rmb
  14. ;  - 4 (or 100b) for mmb
  15. ;  - 5 (or 101b) for both lmb + mmb (OR the individual results)
  16. ;  - ...
  17. ;  - 20 or 21 for error conditions
  18.  
  19. ; Linking:
  20. ;  blink MBPress.o lib lib:small.lib ND SC SD
  21.  
  22.  
  23. *********************************************************************
  24.  
  25.  
  26.     INCLUDE     "exec/types.i"
  27.     INCLUDE     "exec/exec_lib.i"
  28.     INCLUDE     "hardware/cia.i"
  29.     INCLUDE     "hardware/custom.i"
  30.     INCLUDE     "resources/potgo_lib.i"
  31.  
  32.  
  33.     XREF    _ciaa
  34.     XREF    _custom
  35.     XREF    _potinp
  36.  
  37.  
  38. SETBITS    equ    $FFFF        ;which POTGO bits to set (masked later)
  39. UNSETBITS    equ    $0000        ;which POTGO bits to clear
  40. LBIT    equ    (1<<0)        ;bit mask for Lmb return value
  41. RBIT    equ    (1<<1)        ;bit mask for Rmb return value
  42. MBIT    equ    (1<<2)        ;bit mask for Mmb return value
  43. OUTLY    equ    (1<<11)        ;bit mask for Rmb enable (port 1, unit 0)
  44. DATLY    equ    (1<<10)        ;bit mask for Rmb data
  45. OUTLX    equ    (1<<9)        ;bit mask for Mmb enable
  46. DATLX    equ    (1<<8)        ;bit mask for Mmb data
  47. DATLY_POS    equ    10        ;bit position for Rmb data
  48. DATLX_POS    equ    8        ;bit position for Mmb data
  49. RES_FAIL    equ    20        ;return value if can't open resource    
  50. ALOC_FAIL    equ    21        ;return value if can't allocate bits
  51.  
  52.  
  53. *********************************************************************
  54.  
  55.  
  56. Start:    movem.l    d2-d7/a2-a6,-(sp)    ;save registers per convention
  57.     moveq.l    #0,d0        ;clear d0 before using
  58.     moveq.l    #0,d1        ;clear d1 before using
  59.     moveq.l    #0,d2        ;clear d2, used to store return value
  60.  
  61. Prep1:    lea.l    _ciaa,a4        ;base address of CIAA
  62.     move.b    ciapra(a4),d1    ;move CIAAPRA bits into d1
  63.  
  64. Lmb:    btst    #CIAB_GAMEPORT0,d1    ;check left button
  65.     bne.s    Prep2        ;if not pressed, continue checking
  66.     or.b    #LBIT,d2        ;if pressed, set bit 0 of return value
  67.  
  68. Prep2:    lea.l    PotgoName(pc),a1    ;load a1 with resource name string
  69.     CALLEXEC    OpenResource    ;open 'potgo.resource'
  70.     move.l    d0,d7        ;stash resource base
  71.     bne.s    Prep3        ;resource ok, so continue preps
  72.     moveq.l    #RES_FAIL,d2    ;return error value
  73.     bra    Done        ;halt prematurely
  74.  
  75. Prep3:    exg.l    d7,a6        ;put resource base in a6
  76.     moveq.l    #0,d0        ;clear d0
  77.     or.w    #OUTLY,d0        ;or OUTLY bit
  78.     or.w    #DATLY,d0        ;or DATLY bit
  79.     or.w    #OUTLX,d0        ;or OUTLX bit
  80.     or.w    #DATLX,d0        ;or DATLX bit
  81.     jsr    _LVOAllocPotBits(a6);call resource preparation function
  82.     tst.l    d0        ;check whether bits allocated
  83.     beq.s    Prep4        ;bits allocated, so continue preps
  84.     jsr    _LVOFreePotBits(a6)    ;free any bits that did allocate
  85.     moveq.l    #ALOC_FAIL,d2    ;return error value
  86.     bra    Done        ;halt prematurely
  87.     
  88. Prep4:    move.l    d0,d1        ;move bit mask to proper register
  89.     move.l    #SETBITS,d0    ;prepare to set all masked potgo bits
  90.     jsr    _LVOWritePotgo(a6)    ;set chosen potgo bits            
  91.     lea.l    _potinp,a4    ;address of POTINP register
  92.     move.w    (a4),d0        ;move current POTbits to d0 for testing
  93.  
  94. Rmb:    btst.l    #DATLY_POS,d0    ;test POTINP with bit DATLY_POS
  95.     bne.s    Mmb        ;if not pressed, continue checking
  96.     or.b    #RBIT,d2        ;if pressed, set bit 1 of return value
  97.         
  98. Mmb:    btst.l    #DATLX_POS,d0    ;test POTINP with bit DATLX_POS
  99.     bne.s    Unprep        ;if not pressed, let's cleanup and exit
  100.     or.b    #MBIT,d2        ;if pressed, set bit 2 of return value
  101.  
  102. Unprep:    move.l    #UNSETBITS,d0    ;prepare to clear all masked potgo bits
  103.     jsr    _LVOWritePotgo(a6)    ;clear chosen potgo bits
  104.     move.l    d1,d0        ;move bit mask to proper register
  105.     jsr    _LVOFreePotBits(a6)    ;free any allocated potgo bits
  106.  
  107. Done:    move.l    d2,d0        ;move return value to d0 for CLI
  108.     movem.l    (sp)+,d2-d7/a2-a6    ;restore the registers we saved
  109.     rts            ;this takes us back to DOS
  110.  
  111.  
  112. *********************************************************************
  113.  
  114.  
  115. vers:    dc.b    0,'$VER: MBPress 1.0',0
  116. PotgoName:
  117.     dc.b    'potgo.resource',0
  118.     ds.w    0
  119.     
  120.     END
  121.  
  122. *********************************************************************
  123.