home *** CD-ROM | disk | FTP | other *** search
/ HomeWare 14 / HOMEWARE14.bin / utils2 / mymous12.arj / MM-HANDL.ASM < prev    next >
Assembly Source File  |  1994-01-06  |  10KB  |  375 lines

  1. ; MyMouse
  2. ; Input handler bit (to cut down the size of the source file)
  3. ; Andrew Forrest
  4. ;****************************************************************************
  5. ; Routine can't get semaphore since this causes deadlock when we try to
  6. ; change the parameters. For this reason, we must use only atomic variables.
  7. ;***************************************************************************
  8. ;***************************************************************************
  9.  
  10. ; Takes a0=^oldEventChain; a1=^GlobalPtr; Returns d0=^newEventChain;
  11. ; Scratches d1, a0, a1
  12. ; Uses a4=^first link; a5=^global structure; d1=TimeStamp of last event
  13. IntRoutine:            ;Start of input handler code
  14.     pushm.l    a4-a5
  15.     lea    (a0),a4    ; First link in event chain
  16.     lea    (a1),a5    ; Global Ptr
  17. .loop      push.l      a0
  18.       bsr.s      Do_Event
  19.       pop.l      a0
  20.       move.l      ie_NextEvent(a0),d0
  21.     beq.s    .end_loop
  22.       move.l      d0,a0
  23.     bra.s    .loop
  24. .end_loop    move.l    ie_TimeStamp+TV_SECS(a0),d1    ; time in seconds
  25.     bsr    Time_Outs
  26.     move.l    a4,d0
  27.     popm.l    a4-a5
  28.     rts
  29.  
  30. ;****************************************************************************
  31. Do_Event:
  32. ; Takes a0=^Event; a5=^GlobalPtr; 
  33. ; scratches d1, a0, a1
  34.     pushm.l    a2/a6
  35.     move.l    IntBase(a5),a6
  36.  
  37.     ;*╗╗  Perform SunMouse (Activate window)
  38.     tst.l    SunMouseOption(a5)
  39.       beq.s      .SkipSunMouse1
  40.     cmp.b    #IECLASS_TIMER,ie_Class(a0)
  41.       bne.s      .SkipSunMouse1
  42.     bclr    #STB_SunMouse,Status(a5)
  43.       beq.s      .SkipSunMouse1    ; Skip if already Sunned
  44.     bsr    GetWindow
  45.     push.l    a0
  46.     move.l    d0,a0
  47.     cmp.l    ib_ActiveWindow(a6),a0
  48.       beq.s      .EndSun
  49.     just    ActivateWindow
  50. .EndSun:    pop.l    a0
  51. .SkipSunMouse1:
  52.  
  53.     cmp.b    #IECLASS_TIMER,ie_Class(a0)
  54.       beq      .not_key    ; If it's a timer event, don't unblank
  55.  
  56.     ;*╗╗  Reset screen blank
  57.     move.l    ie_TimeStamp(a0),ScreenTime(a5)
  58.     bclr    #STB_SBlanked,Status(a5)
  59.     beq.s    .SkipSRestore
  60.       UnBkScreen
  61. .SkipSRestore
  62.  
  63.     cmp.b    #IECLASS_RAWKEY,ie_Class(a0)
  64.       bne      .not_key        ; skip this bit if not a key
  65.  
  66.  
  67.     ;*╗╗  Do Northgate keyboard mapping.
  68.     tst.l    NorthgateOption(a5)
  69.       beq.s      .SkipNorthgate
  70.     lea    NorthgateTable(pc),a2
  71.     move.w    ie_Code(a0),d0
  72.     bclr    #IECODEB_UP_PREFIX,d0
  73. .NorthgateLoop:
  74.     move.b    (a2),d1
  75.       beq.s      .EndNorthgate
  76.     addq.l    #3,a2
  77.     cmp.b    d0,d1
  78.       bne.s      .NorthgateLoop
  79.     and.w    #IECODE_UP_PREFIX,ie_Code(a0)
  80.     move.b    -2(a2),d0
  81.     or.b    d0,ie_Code+1(a0)
  82.     move.b    -1(a2),d0
  83.     or.b    d0,ie_Qualifier+1(a0)
  84. .EndNorthgate
  85. .SkipNorthgate
  86.  
  87.     move.w    ie_Code(a0),d0
  88.     tst.b    d0
  89.       bmi      .end_event    ;henceforth ignore key-ups
  90.     btst    #IEQUALIFIERB_LCOMMAND,ie_Qualifier+1(a0)
  91.       bne.s      .do_LAmiga
  92.  
  93.     ;*╗╗  Blank mouse pointer if not a qualifier key pressed
  94.     tst.l    MouseBlank(a5)
  95.     bmi.s    .NoMBlank
  96.       and.b      #%11111000,d0    ; If raw key is 60 thru 67,
  97.       cmp.b      #$60,d0        ; ...we shouldn't blank mouse
  98.       beq.s      .NoMBlank    ; ...('cos it was shift or something).
  99.         bset        #STB_DoMBlank,Status(a5)
  100.         bsr        SignalMouseBlank    ; Blank mouse on keypress
  101. .NoMBlank    bra    .end_event
  102.     
  103. .do_LAmiga:
  104.     ;*╗╗  Check for Amiga-ESC
  105.     tst.l    CmdOption(a5)
  106.       beq      .end_event
  107.     cmp.w    #KEYCODE_ESC,ie_Code(a0)
  108.       bne      .end_event
  109.     clr.b    ie_Class(a0)
  110.     move.l    CLISig(a5),d0
  111.     bsr    SignalTask
  112.       bra      .end_event
  113.  
  114. .not_key:
  115.     move.w    ib_MouseX(a6),d0
  116.     move.w    ib_MouseY(a6),d1
  117.     cmp.b    #IECLASS_RAWMOUSE,ie_Class(a0)
  118.       beq.s      .do_mouse
  119.     cmp.w    CurrentX(a5),d0
  120.       bne.s      .do_mouse
  121.     cmp.w    CurrentY(a5),d1
  122.       beq      .end_event
  123.  
  124. .do_mouse:    move.w    d0,CurrentX(a5)
  125.     move.w    d1,CurrentY(a5)
  126.     ;*╗╗  Restore mouse pointer if the mouse moves
  127.     move.l    ie_TimeStamp(a0),MouseTime(a5)
  128.     btst    #STB_MBlanked,Status(a5)
  129.       bne.s      .restore    ; Restore mouse if we _know_ it's blanked
  130.     move.l    ib_ActiveWindow(a6),d0    ; Examine active window
  131.       beq.s      .no_restore    ; Exit if no active window(!)
  132.     move.l    d0,a1
  133.     move.l    wd_Pointer(a1),d0
  134.     cmp.l    MouseChipData(a5),d0
  135.     bne.s    .no_restore    ; Restore if it _turns out_ to be blanked
  136. .restore      bclr      #STB_DoMBlank,Status(a5)
  137.       bsr      SignalMouseBlank
  138. .no_restore
  139.  
  140.     ;*╗╗  Test Sunnyness of mouse
  141.     tst.l    SunMouseOption(a5)
  142.       beq.s      .noSunMouse
  143.     move.w    ie_Qualifier(a0),d0
  144.     and.w    #IEQUALIFIER_LEFTBUTTON+IEQUALIFIER_RBUTTON+IEQUALIFIER_MIDBUTTON,d0
  145.       bne.s      .noSunMouse
  146.     cmp.w    #IECODE_LBUTTON+IECODE_UP_PREFIX,ie_Code(a0)
  147.       beq.s      .noSunMouse
  148.     bset    #STB_SunMouse,Status(a5)
  149. .noSunMouse
  150.  
  151.     ;*╗╗  Perform click-to-back.
  152.     tst.l    CTBOption(a5)
  153.       beq      .no_CTB
  154.     cmp.w    #IECODE_RBUTTON,ie_Code(a0)
  155.       bne      .no_CTB
  156.     move.w    ie_Qualifier(a0),d0
  157.     btst    #IEQUALIFIERB_LEFTBUTTON,d0
  158.       beq      .no_CTB
  159.     pushm.l    d2/a0-a1
  160.     bsr    GetWindow
  161.     tst.l    d0
  162.       beq.s      .end_CTB
  163.     move.l    d0,a1
  164.     move.l    wd_Flags(a1),d2
  165.     and.l    #WFLG_BACKDROP,d2
  166.       bne.s      .end_CTB
  167.     ;Is this the only window on this screen, except for backdrop windows?
  168.     move.l    wd_WScreen(a1),a1
  169.     move.l    sc_FirstWindow(a1),a1
  170. .back_loop      cmp.l      a1,d0
  171.     beq.s    .endback_lp
  172.       move.l      wd_Flags(a1),d2
  173.       and.l      #WFLG_BACKDROP,d2
  174.     beq.s    .flipwindow
  175. .endback_lp      move.l      wd_NextWindow(a1),a1
  176.       move.l      a1,d2
  177.     bne.s    .back_loop
  178.     bra.s    .end_CTB
  179. .flipwindow    move.l    d0,a0
  180.     just    WindowToBack
  181. .end_CTB    popm.l    d2/a0-a1
  182.     clr.b    ie_Class(a0)
  183.     bra    .end_event
  184. .no_CTB
  185.  
  186.     ;*╗╗  Perform click-to-front.
  187.     tst.l    CTF(a5)
  188.       ble      .no_CTF
  189.     cmp.w    #IECODE_LBUTTON,ie_Code(a0)
  190.       bne      .no_CTF
  191.     btst    #IEQUALIFIERB_LCOMMAND,ie_Qualifier+1(a0)
  192.       bne      .no_CTF    ;to avoid interferring with Snap
  193.     bsr    GetWindow
  194.     tst.l    d0
  195.       beq      .no_CTF
  196.     push.l    d2
  197.     move.l    CTFB(a5),d2
  198.     bmi.s    .no_border
  199.       move.l      d0,a1
  200.       btst      #BBB_LEFT,d2
  201.       beq.s      .test_right
  202. .test_left        move.w        wd_MouseX(a1),d1
  203.         move.b        wd_BorderLeft(a1),d0
  204.         ext.w        d0
  205.         cmp.w        d0,d1
  206.           blo.s          .in_border
  207. .test_right      btst      #BBB_RIGHT,d2
  208.       beq.s      .test_top
  209.         move.b        wd_BorderRight(a1),d0
  210.         ext.w        d0
  211.         add.w        d0,d1
  212.         cmp.w        wd_Width(a1),d1
  213.           bhs.s          .in_border
  214. .test_top      btst      #BBB_TOP,d2
  215.       beq.s      .test_botto
  216.         move.w        wd_MouseY(a1),d1
  217.         move.b        wd_BorderTop(a1),d0
  218.         ext.w        d0
  219.         cmp.w        d0,d1
  220.           blo.s          .in_border
  221. .test_botto      btst      #BBB_BOTTOM,d2
  222.       beq      .end_CTF
  223.         move.b        wd_BorderBottom(a1),d0
  224.         ext.w        d0
  225.         add.w        d0,d1
  226.         cmp.w        wd_Height(a1),d1
  227.           blo          .end_CTF
  228. .in_border      move.l      a1,d0      
  229. .no_border    move.l    CTF(a5),d1
  230.     cmp.l    #1,d1
  231.     bhi.s    .more_thn_1
  232.     bsr    DoWindowToFront
  233.       bra      .end_CTF
  234. .more_thn_1    cmp.l    ClickWindow(a5),d0
  235.       beq.s      .same_win
  236.     move.l    d0,ClickWindow(a5)
  237.     moveq    #1,d0
  238.     move.l    d0,ClickCount(a5)
  239.     bra.s    .save_time
  240. .same_win    ; Check to see whether MaxClickDelay has been exceeded. If not
  241.     ; increment ClickCount and compare with (CTFOption). If equal, do
  242.     ; a WindowToFront. Window under pointer in D0.
  243.     push.l    d0
  244.     pushm.l    d2-d3/a0
  245.     move.l    ClickTime+TV_SECS(a5),d0
  246.     move.l    ClickTime+TV_MICRO(a5),d1
  247.     move.l    ie_TimeStamp+TV_SECS(a0),d2
  248.     move.l    ie_TimeStamp+TV_MICRO(a0),d3
  249.     just    DoubleClick
  250.     popm.l    d2-d3/a0
  251.     tst.l    d0
  252.       beq.s      .time_exceeded
  253.     addq.l    #1,ClickCount(a5)
  254.     move.l    CTF(a5),d0
  255.     cmp.l    ClickCount(a5),d0
  256.       bhi.s      .need_more_clicks
  257.     clr.l    ClickCount(a5)
  258.     pop.l    d0
  259.     bsr    DoWindowToFront
  260.       bra.s      .end_CTF
  261. .time_exceeded
  262.     moveq    #1,d0
  263.     move.l    d0,ClickCount(a5)
  264. .need_more_clicks
  265.     pop.l    d0
  266. .save_time    move.l    ie_TimeStamp+TV_SECS(a0),ClickTime+TV_SECS(a5)
  267.     move.l    ie_TimeStamp+TV_MICRO(a0),ClickTime+TV_MICRO(a5)
  268. .end_CTF    pop.l    d2
  269. .no_CTF
  270.  
  271.     ;*╗╗  Perform acceleration.
  272.     tst.l    Acceleration(a5)
  273.       bmi      .end_event
  274.     move.l    Threshold(a5),d0
  275.     bpl.s    .T1
  276.       moveq      #0,d0
  277. .T1    move.w    ie_X(a0),d1
  278.       bpl.s      .PosX
  279.     neg.w    d1
  280. .PosX    cmp.w    d0,d1
  281.       bls.s      .SkipX    ;below threshold
  282.     move.l    Acceleration(a5),d1
  283.     muls.w    ie_X(a0),d1
  284.       bpl.s      .SubDampX
  285.     add.w    DampingConstant(a5),d1
  286.       bra.s      .DampX
  287. .SubDampX    sub.w    DampingConstant(a5),d1
  288. .DampX    move.w    d1,ie_X(a0)
  289. .SkipX    move.w    ie_Y(a0),d1
  290.       bpl.s      .PosY
  291.     neg.w    d1
  292. .PosY    cmp.w    d0,d1
  293.       bls.s      .EndAccel
  294.     move.l    Acceleration(a5),d1
  295.     muls.w    ie_Y(a0),d1
  296.       bpl.s      .SubDampY
  297.     add.w    DampingConstant(a5),d1
  298.       bra.s      .DampY
  299. .SubDampY    sub.w    DampingConstant(a5),d1
  300. .DampY    move.w    d1,ie_Y(a0)
  301. .EndAccel
  302.  
  303. .end_event    popm.l    a2/a6
  304.     rts
  305.  
  306. ;***************************************************************************
  307. Time_Outs:    ;*╗╗  Check for time-outs (mouse and screen blanking)
  308. ; Takes d1=TimeStamp seconds; a5=GlobalPtr
  309. ; scratches d0, d1, a0, a1
  310.     push.l    a6
  311.     move.l    IntBase(a5),a6
  312.  
  313.     ;*╗╗  Check if window has changed with blanked pointer
  314.     btst    #STB_MBlanked,Status(a5)
  315.       beq.s      .EndMBW    ; (Skip if not blanked)
  316.     move.l    MBlankWindow(a5),d0
  317.     cmp.l    ib_ActiveWindow(a6),d0
  318.       beq.s      .EndMBW
  319.     bset    #STB_DoMBlank,Status(a5)
  320.     bsr    SignalMouseBlank    ; Blank mouse for this new window
  321. .EndMBW:
  322.  
  323.     ;*╗╗  Check if mouse should be timed out
  324.     tst.l    MouseBlank(a5)
  325.       ble.s      .end_MBlank ; If user-mouse-blank-time=0, don't blank
  326.     move.l    d1,d0
  327.     sub.l    MouseBlank(a5),d0    ; this_time - user_pause
  328.     tst.l    MouseTime(a5)
  329.     bne.s    .else_MBlnk    ; If last-used mouse time is zero, then
  330.       move.l      d1,MouseTime(a5)    ; reset last-used mouse time
  331.     bra.s    .end_MBlank    ; else
  332. .else_MBlnk      sub.l      MouseTime(a5),d0    ; sub last mouse move time
  333.       blo.s      .end_MBlank    ; If this_time - last_move > user_pause
  334.         move.l        d0,MouseTime(a5)
  335.         bset        #STB_DoMBlank,Status(a5)
  336.         bsr        SignalMouseBlank
  337. .end_MBlank    ;endif
  338.  
  339.     tst.l    ScreenBlank(a5)
  340.       ble.s      .end_SBlank ; If screen-blank time-out=0, don't blank
  341.     move.l    d1,d0
  342.     sub.l    ScreenBlank(a5),d0    ; this_time - user_pause
  343.     tst.l    ScreenTime(a5)
  344.     bne.s    .else_SBlnk    ; If last-used screen time is zero then
  345.       move.l      d1,ScreenTime(a5)    ; reset last-used screen time
  346.     bra.s    .end_SBlank    ;else
  347. .else_SBlnk      sub.l      ScreenTime(a5),d0
  348.       blo.s      .end_SBlank
  349.         bset        #STB_SBlanked,Status(a5)
  350.       bne.s      .end_SBlank    ; Don't blank if already blanked
  351.         BlankScreen
  352. .end_SBlank    ;endif
  353.  
  354.     pop.l    a6
  355.     rts
  356.  
  357. ;****************************************************************************
  358.  
  359. SignalMouseBlank:    ; Takes a5=GlobalPtr; Returns, Trashes nil
  360.     push.l    d0
  361.     move.l    MouseBlankSig(a5),d0
  362.     bsr.s    SignalTask
  363.     pop.l    d0
  364.     rts
  365.  
  366. SignalTask:        ; Takes a5=GlobalPtr; d0=signal; Trashes nil
  367.     pushm.l    d0-d1/a0-a1/a6
  368.     move.l    Task(a5),a1
  369.     move.l    Execbase,a6
  370.     just    Signal
  371.     popm.l    d0-d1/a0-a1/a6
  372.     rts
  373.  
  374.  
  375. ;****************************************************************************