home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 345.lha / snap_v1.4 / source / handler.s < prev    next >
Encoding:
Text File  |  1990-02-13  |  17.4 KB  |  552 lines

  1.         include "exec/types.i"
  2.         include "exec/lists.i"
  3.         include "devices/inputevent.i"
  4.  
  5. waiting   equ 0
  6. selregion equ 1
  7. waitext   equ 2
  8. selgfx    equ 3
  9. waitgfx   equ 4
  10. inserting equ 5
  11. pendsnap  equ 6
  12. killbutt  equ 7
  13.  
  14. noaction  equ 0
  15. snapgfx   equ 1
  16. snaptext  equ 2
  17. snapinit  equ 3
  18. insert    equ 4
  19. cancel    equ 5
  20.  
  21. LMB       equ IECODE_LBUTTON
  22. LMB_UP    equ IECODE_UP_PREFIX+IECODE_LBUTTON
  23. RMB       equ IECODE_RBUTTON
  24. RMB_UP    equ IECODE_UP_PREFIX+IECODE_RBUTTON
  25. NO_BUTT   equ IECODE_NOBUTTON
  26. LCOM      equ IEQUALIFIER_LCOMMAND
  27. SHIFT     equ IEQUALIFIER_LSHIFT+IEQUALIFIER_RSHIFT
  28.  
  29.  
  30.         XDEF    _myhandler
  31.         XREF    _geta4
  32.         XREF    _LVOSignal
  33.         XREF    _SysBase
  34.         XREF    _MyTask
  35.         XREF    _action
  36.         XREF    _state
  37.         XREF    _modinsert
  38.         XREF    _startsignal
  39.         XREF    _insertsignal
  40.         XREF    _cancelsignal
  41.         XREF    _donesignal
  42.         XREF    _movesignal
  43.         XREF    _clicksignal
  44.         XREF    _timersignal
  45.         XREF    _initsignal
  46.         XREF    _cwsignal
  47.         XREF    _textqual                      ; qualifier for snapping text
  48.         XREF    _gfxqual                       ;    -"-    -"-   -"-    gfx
  49.         XREF    _insertkey
  50.         XREF    _cwkey
  51.  
  52.         SECTION CODE
  53.  
  54. _myhandler:
  55.  
  56. ; On entry: a0 : Pointer to event list
  57. ;           a1 : Pointer to data
  58.  
  59. ; In loop:  a1 : Pointer to event
  60. ;           d0 : scratch
  61.  
  62. ; Result:   d0 : New event list
  63.  
  64.         movem.l a4,-(sp)
  65.  
  66.         jsr     _geta4                         ; Get offset base a4
  67.  
  68.         move.l  a0,a1                          ; a1 = Event list = a0
  69.  
  70. .nextevent
  71.         cmpa.l  #0,a1                          ; Check for end of list
  72.         beq     .done
  73.  
  74.         cmp.w   #noaction,_action              ; forced noaction - cancel
  75.         bne     .notcanceled                   ; no, we're in action
  76.         move.w  #waiting,_state                ; no action -> wait state
  77.         bra     .dostate
  78. .notcanceled
  79.         cmp.w   #insert,_action                ; forced insert - cancel
  80.         bne     .dostate                       ; no
  81.         move.w  #inserting,_state              ; set correct state
  82.  
  83. .dostate
  84.         move.w  _state,d0
  85.         asl.w   #1,d0
  86.         move.w  JumpTable(pc,d0.w),d0
  87. Origin
  88.         jmp     0(pc,d0.w)
  89. JumpTable
  90.         dc.w    .Waiting-Origin-2
  91.         dc.w    .SelRegion-Origin-2
  92.         dc.w    .WaitExt-Origin-2
  93.         dc.w    .SelGfx-Origin-2
  94.         dc.w    .WaitGfx-Origin-2
  95.         dc.w    .Insert-Origin-2
  96.         dc.w    .PendSnap-Origin-2
  97.         dc.w    .CancelTxt-Origin-2
  98.  
  99. ; ********************************************************
  100. ; State: Waiting    ~TQ
  101. ; Actions     New state             Signal
  102. ; TQ          PendSnap              init
  103. ; LMB+GQ      SelGfx                init+start
  104. ; LCOM+IKEY   Inserting             insert
  105.  
  106. .Waiting
  107.         cmp.b   #IECLASS_RAWKEY,ie_Class(a1)   ; Is it RAWKEY?
  108.         bne     .wait_RAWMOUSE
  109.  
  110.         move.w  ie_Qualifier(a1),d0
  111.         and.w   _textqual,d0                   ; TQ?
  112.         bne     .signalinit                    ; Yes -- init
  113.  
  114.         move.w  ie_Qualifier(a1),d0
  115.         and.w   #LCOM,d0                       ; LCOM?
  116.         beq     .EventHandled                  ; No
  117.  
  118.         move.w  _cwkey,d0                      ; Control window key
  119.         cmp.w   ie_Code(a1),d0
  120.         beq     .signalcw
  121.  
  122.         move.w  _insertkey,d0
  123.         beq     .EventHandled                  ; Key = 0 -- disabled
  124.  
  125.         cmp.w   ie_Code(a1),d0                 ; The insert key?
  126.         bne     .EventHandled                  ; No, pass it on
  127.         bra     .signalinsert                  ; Tell'em to insert
  128.  
  129. .wait_RAWMOUSE
  130.         cmp.b   #IECLASS_RAWMOUSE,ie_Class(a1) ; Is it RAWMOUSE?
  131.         bne     .EventHandled                  ; Nope, pass it on
  132.  
  133.         move.w  ie_Qualifier(a1),d0
  134.         and.w   _textqual,d0                   ; TQ?
  135.         bne     .signalinit                    ; Yes
  136.  
  137.         cmp.w   #LMB,ie_Code(a1)               ; OK, is it SELECTDOWN?
  138.         bne     .EventHandled                  ; Too bad
  139.  
  140.         move.w  ie_Qualifier(a1),d0
  141.         and.w   _gfxqual,d0                    ; GQ?
  142.         beq     .EventHandled                  ; No, not interested
  143.  
  144. ; Handle event LMB+GQ
  145.         move.b  #IECLASS_NULL,ie_Class(a1)     ; Kill event
  146.         move.w  #snapgfx,_action               ; action snapgfx;
  147.         move.w  #selgfx,_state                 ; state selgfx
  148.         move.l  _initsignal,d0                 ; Signal init and
  149.         or.l    _startsignal,d0                ; start
  150.         bra     SignalTask
  151.  
  152. .signalinit
  153.         move.w  #pendsnap,_state
  154.         move.w  #snapinit,_action
  155.         move.l  _initsignal,d0                 ; Signal start
  156.         bsr     Signal
  157.         bra     .PendSnap
  158.  
  159.  
  160. ; *******************************************************
  161. ; State: PendSnap   TQ
  162. ; Actions     New state           Signal
  163. ; ~TQ         Waiting             cancel
  164. ; LCOM+IKEY   Inserting           insert
  165. ; LMB         SelRegion           start
  166. ; RMB         Inserting           insert
  167.  
  168. .PendSnap
  169.         cmp.b   #IECLASS_RAWKEY,ie_Class(a1)   ; RAWKEY?
  170.         bne     .ps_RAWMOUSE
  171.         move.w  ie_Qualifier(a1),d0
  172.         and.w   _textqual,d0                   ; TQ?
  173.         bne     .ps_IKEY                       ; Still down, continue
  174.  
  175. ;Handle event ~TQ
  176. .ps_TQ
  177.         move.w  #noaction,_action              ; no action
  178.         move.w  #waiting,_state                ; state waiting
  179.         move.l  _cancelsignal,d0               ; snap cancelled
  180.         bra     SignalTask
  181.  
  182. .ps_IKEY
  183.         move.w  ie_Qualifier(a1),d0
  184.         and.w   #LCOM,d0                       ; LCOM?
  185.         beq     .EventHandled                  ; No
  186.  
  187.         move.w  _cwkey,d0                      ; Control window key
  188.         cmp.w   ie_Code(a1),d0
  189.         beq     .signalcw
  190.  
  191.         move.w  _insertkey,d0
  192.         beq     .EventHandled                  ; Key = 0 -- disabled
  193.  
  194.         cmp.w   ie_Code(a1),d0                 ; The insert key?
  195.         bne     .EventHandled                  ; No, pass it on
  196.         bra     .signalinsert                  ; Tell'em to insert
  197.  
  198. .ps_RAWMOUSE
  199.         cmp.b   #IECLASS_RAWMOUSE,ie_Class(a1) ; Is it RAWMOUSE?
  200.         bne     .EventHandled                  ; Nope, pass it on
  201.  
  202.         move.w  ie_Qualifier(a1),d0            ; Might be TQ going up.
  203.         and.w   _textqual,d0                   ; TQ?
  204.         beq     .ps_TQ
  205.  
  206.         cmp.w   #LMB,ie_Code(a1)               ; OK, is it SELECTDOWN?
  207.         bne     .ps_RMB                        ; Too bad
  208.  
  209. ; Handle event LMB+TQ
  210.         move.b  #IECLASS_NULL,ie_Class(a1)     ; Kill event
  211.         move.w  #snaptext,_action              ; action snaptext
  212.         move.w  #selregion,_state              ; state selregion
  213.         move.l  _startsignal,d0                ; start
  214.         bra     SignalTask
  215.  
  216. .ps_RMB
  217.         cmp.w   #RMB,ie_Code(a1)               ; MENUDOWN
  218.         bne     .EventHandled
  219.  
  220. ; Handle event RMB+TQ
  221. .signalinsert
  222.         move.b  #IECLASS_NULL,ie_Class(a1)     ; Kill event
  223.  
  224.         move.w  #0,_modinsert
  225.         move.w  ie_Qualifier(a1),d0
  226.         and.w   #SHIFT,d0                      ; SHIFT?
  227.         beq     .NonModified                   ; No
  228.         move.w  #1,_modinsert
  229. .NonModified
  230.         move.w  #insert,_action
  231.         move.w  #inserting,_state
  232.         move.l  _insertsignal,d0               ; and insert
  233.         bra     SignalTask
  234.  
  235. .signalcw
  236.         move.b  #IECLASS_NULL,ie_Class(a1)     ; Kill event
  237.         move.w  #noaction,_action
  238.         move.w  #waiting,_state
  239.         move.l  _cancelsignal,d0               ; Exit pending snap
  240.         or.l    _cwsignal,d0                   ; and tell'em to open window
  241.         bra     SignalTask
  242.  
  243.  
  244. ; *******************************************************
  245. ; State: SelRegion  LMB+TQ
  246. ; Actions     New state           Signal
  247. ; ~TQ         Waiting             cancel
  248. ; ~LMB        WaitExt
  249. ; MOVE        SelRegion           move
  250. ; RMB         SelRegion           click
  251. ; ~RMB        SelRegion                      Needs no action
  252. ; TIMER       SelRegion           timer
  253.  
  254. .SelRegion
  255.         cmp.b   #IECLASS_TIMER,ie_Class(a1)    ; Timer event?
  256.         bne     .sr_RAWKEY
  257.  
  258. ;Handle timer event
  259.         move.l  _timersignal,d0
  260.         bra     SignalTask
  261.  
  262. .sr_RAWKEY
  263.         cmp.b   #IECLASS_RAWKEY,ie_Class(a1)   ; RAWKEY?
  264.         bne     .sr_LMB_UP
  265.         move.b  #IECLASS_NULL,ie_Class(a1)     ; Kill event
  266.         move.w  ie_Qualifier(a1),d0
  267.         and.w   _textqual,d0                   ; TQ?
  268.         bne     .EventHandled                  ; Still down, continue
  269.  
  270. ;Handle event ~TQ
  271. .sr_TQ
  272.         move.w  #cancel,_action                ; no action
  273.         move.w  #killbutt,_state              ; state waiting
  274.         move.l  _cancelsignal,d0               ; snap cancelled
  275.         bra     SignalTask
  276.  
  277. .sr_LMB_UP
  278.         cmp.b   #IECLASS_RAWMOUSE,ie_Class(a1) ; Is it RAWMOUSE?
  279.         bne     .EventHandled                  ; Nope, pass it on
  280.  
  281.         move.w  ie_Qualifier(a1),d0            ; Might be TQ going up.
  282.         and.w   _textqual,d0                   ; TQ?
  283.         beq     .sr_TQ
  284.  
  285.         cmp.w   #LMB_UP,ie_Code(a1)            ; SELECTUP
  286.         bne     .sr_MOVE                       ; no, check for move
  287.  
  288. ; Handle event ~LMB
  289.         move.w  #waitext,_state                ; state waitext
  290.         bra     KillEvent
  291.  
  292. .sr_MOVE
  293.         cmp.w   #NO_BUTT,ie_Code(a1)           ; MOVE
  294.         bne     .sr_RMB                        ; No, check for RMB
  295.         move.w  ie_Qualifier(a1),d0
  296.         and.w   #IEQUALIFIER_RELATIVEMOUSE,d0  ; RELATIVEMOUSE
  297.         beq     .sr_RMB
  298.  
  299. ; Handle event MOVE
  300.         move.l  _movesignal,d0
  301.         bra     SignalTask
  302.  
  303. .sr_RMB
  304.         cmp.w   #RMB,ie_Code(a1)               ; MENUDOWN
  305.         bne     .EventHandled                  ; No, not interested
  306.  
  307. ; Handle event RMB
  308.         move.b  #IECLASS_NULL,ie_Class(a1)     ; Kill event
  309.         move.l  _clicksignal,d0
  310.         bra     SignalTask
  311.  
  312. ; ***************************************************
  313. ; State WaitExt     TQ
  314. ; Actions     New state           Signal
  315. ; ~TQ         Waiting             done
  316. ; LMB         SelRegion           click
  317. ; MOVE        WaitExt                            No action needed.
  318. ; RMB         Inserting           done & insert
  319. ; TIMER       WaitExt             timer
  320.  
  321. .WaitExt
  322.         cmp.b   #IECLASS_TIMER,ie_Class(a1)    ; Timer event?
  323.         bne     .we_RAWKEY
  324.  
  325. ;Handle timer event
  326.         move.l  _timersignal,d0
  327.         bra     SignalTask
  328.  
  329. .we_RAWKEY
  330.         cmp.b   #IECLASS_RAWKEY,ie_Class(a1)   ; RAWKEY?
  331.         bne     .we_LMB
  332.         move.b  #IECLASS_NULL,ie_Class(a1)     ; Kill event
  333.         move.w  ie_Qualifier(a1),d0
  334.         and.w   _textqual,d0                   ; TQ?
  335.         bne     .EventHandled                  ; Still down, continue
  336.  
  337. ;Handle event ~TQ
  338. .we_TQ
  339.         move.w  #noaction,_action              ; no action
  340.         move.w  #waiting,_state                ; state waiting
  341.         move.l  _donesignal,d0                 ; snap finished
  342.         bra     SignalTask
  343.  
  344. .we_LMB
  345.         cmp.b   #IECLASS_RAWMOUSE,ie_Class(a1) ; Is it RAWMOUSE?
  346.         bne     .EventHandled                  ; Nope, pass it on
  347.  
  348.         move.w  ie_Qualifier(a1),d0            ; Might be TQ going up.
  349.         and.w   _textqual,d0                   ; TQ?
  350.         beq     .we_TQ                         ; No.
  351.  
  352.         cmp.w   #LMB,ie_Code(a1)               ; SELECTDOWN
  353.         bne     .we_RMB                        ; no, check for RMB
  354.  
  355. ; Handle event LMB
  356.         move.b  #IECLASS_NULL,ie_Class(a1)     ; Kill event
  357.         move.w  #selregion,_state              ; state waitext
  358.         move.l  _clicksignal,d0                ; Extend selection
  359.         bra     SignalTask
  360.  
  361. .we_RMB
  362.         cmp.w   #RMB,ie_Code(a1)               ; MENUDOWN
  363.         bne     .EventHandled                  ; No, not interested
  364.  
  365. ; Handle event RMB
  366.         move.b  #IECLASS_NULL,ie_Class(a1)     ; Kill event
  367.         move.w  #insert,_action
  368.         move.w  #inserting,_state
  369.         move.l  _donesignal,d0
  370.         or.l    _insertsignal,d0
  371.         bra     SignalTask
  372.  
  373. ; *******************************************************
  374. ; State: SelGfx     LMB+GQ
  375. ; Actions     New state           Signal
  376. ; ~GQ         Waiting             cancel
  377. ; ~LMB        WaitGfx
  378. ; MOVE        SelGfx              move
  379. ; TIMER       SelGfx              timer
  380. ; RMB         SelGfx                        removed
  381.  
  382. .SelGfx
  383.         cmp.b   #IECLASS_TIMER,ie_Class(a1)    ; Timer event?
  384.         bne     .sg_RAWKEY
  385.  
  386. ;Handle timer event
  387.         move.l  _timersignal,d0
  388.         bra     SignalTask
  389.  
  390. .sg_RAWKEY
  391.         cmp.b   #IECLASS_RAWKEY,ie_Class(a1)   ; RAWKEY?
  392.         bne     .sg_LMB_UP
  393.         move.b  #IECLASS_NULL,ie_Class(a1)     ; Kill event
  394.         move.w  ie_Qualifier(a1),d0
  395.         and.w   _gfxqual,d0                    ; GQ?
  396.         bne     .EventHandled                  ; Still down, continue
  397.  
  398. ;Handle event ~GQ
  399. .sg_GQ
  400.         move.w  #cancel,_action                ; cancelling snap
  401.         move.w  #killbutt,_state               ; Kill obsolete button
  402.         move.l  _cancelsignal,d0               ; snap cancelled
  403.         bra     SignalTask
  404.  
  405. .sg_LMB_UP
  406.         cmp.b   #IECLASS_RAWMOUSE,ie_Class(a1) ; Is it RAWMOUSE?
  407.         bne     .EventHandled                  ; Nope, pass it on
  408.  
  409.         move.w  ie_Qualifier(a1),d0            ; Might be GQ going up.
  410.         and.w   _gfxqual,d0                    ; GQ?
  411.         beq     .sg_GQ
  412.  
  413.         cmp.w   #LMB_UP,ie_Code(a1)            ; SELECTUP
  414.         bne     .sg_MOVE                       ; no, check for move
  415.  
  416. ; Handle event ~LMB
  417.         move.w  #waitgfx,_state                ; state waitext
  418.         bra     KillEvent
  419.  
  420. .sg_MOVE
  421.         cmp.w   #NO_BUTT,ie_Code(a1)           ; MOVE
  422.         bne     .EventHandled                  ; No, check for RMB
  423.         move.w  ie_Qualifier(a1),d0
  424.         and.w   #IEQUALIFIER_RELATIVEMOUSE,d0  ; RELATIVEMOUSE
  425.         beq     .EventHandled
  426.  
  427. ; Handle event MOVE
  428.         move.l  _movesignal,d0
  429.         bra     SignalTask
  430.  
  431. .sg_RMB
  432.         bra     KillEvent
  433.  
  434. ; ***************************************************
  435. ; State WaitGfx     GQ
  436. ; Actions     New state           Signal
  437. ; ~GQ         Waiting             done
  438. ; LMB         SelGfx              click
  439. ; MOVE        WaitGfx                            No action needed.
  440. ; TIMER       WaitGfx             timer
  441. ; RMB         WaitGfx             --             remove event
  442.  
  443. .WaitGfx
  444.         cmp.b   #IECLASS_TIMER,ie_Class(a1)    ; Timer event?
  445.         bne     .wg_RAWKEY
  446.  
  447. ;Handle timer event
  448.         move.l  _timersignal,d0
  449.         bra     SignalTask
  450.  
  451. .wg_RAWKEY
  452.         cmp.b   #IECLASS_RAWKEY,ie_Class(a1)   ; RAWKEY?
  453.         bne     .wg_LMB
  454.         move.b  #IECLASS_NULL,ie_Class(a1)     ; Kill event
  455.         move.w  ie_Qualifier(a1),d0
  456.         and.w   _gfxqual,d0                    ; GQ?
  457.         bne     .EventHandled                  ; Still down, continue
  458.  
  459. ;Handle event ~GQ
  460. .wg_GQ
  461.         move.w  #noaction,_action              ; no action
  462.         move.w  #waiting,_state                ; state waiting
  463.         move.l  _donesignal,d0                 ; snap finished
  464.         bra     SignalTask
  465.  
  466. .wg_LMB
  467.         cmp.b   #IECLASS_RAWMOUSE,ie_Class(a1) ; Is it RAWMOUSE?
  468.         bne     .EventHandled                  ; Nope, pass it on
  469.  
  470.         move.w  ie_Qualifier(a1),d0            ; Might be GQ going up
  471.         and.w   _gfxqual,d0                    ; GQ?
  472.         beq     .wg_GQ
  473.  
  474.         cmp.w   #LMB,ie_Code(a1)               ; SELECTDOWN
  475.         bne     .wg_RMB                          ; no -- finished
  476.  
  477. ; Handle event LMB
  478.         move.b  #IECLASS_NULL,ie_Class(a1)     ; Kill event
  479.         move.w  #selgfx,_state                 ; state waitext
  480.         move.l  _clicksignal,d0                ; Extend selection
  481.         bra     SignalTask
  482.  
  483. .wg_RMB
  484.         cmp.w   #NO_BUTT,ie_Code(a1)           ; Any button?
  485.         beq     .EventHandled                  ; No, moves are ok
  486.  
  487.         bra     KillEvent
  488.  
  489.  
  490. ; ***************************************************
  491. ; State CancelTxt
  492. ; Make sure that the Button Up event that we've got
  493. ; hanging around doesn't get through.
  494.  
  495. .CancelTxt
  496.         cmp.b   #IECLASS_RAWMOUSE,ie_Class(a1) ; Is it RAWMOUSE?
  497.         bne     .EventHandled                  ; Nope, just pass it on
  498.  
  499.         cmp.w   #LMB_UP,ie_Code(a1)            ; The button?
  500.         bne     .EventHandled                  ; No
  501.  
  502.         move.w  #noaction,_action
  503.         move.w  #waiting,_state
  504.         bra     KillEvent
  505.  
  506. ; ***************************************************
  507. ; State Insert
  508. ; Snap actions are removed, the rest are passed along.
  509.  
  510. .Insert
  511.         cmp.b   #IECLASS_RAWMOUSE,ie_Class(a1) ; Is it RAWMOUSE?
  512.         bne     .EventHandled                  ; Nope, pass it on
  513.  
  514.         cmp.w   #LMB,ie_Code(a1)               ; Left mouse button
  515.         bne     .insert_TQ                     ; No -- just kill
  516.  
  517.         move.w  #noaction,_action              ; Cancel paste
  518.  
  519. .insert_TQ
  520.         move.w  ie_Qualifier(a1),d0
  521.         and.w   _textqual,d0                   ; TQ?
  522.         beq     .EventHandled                  ; no
  523.  
  524.         cmp.w   #NO_BUTT,ie_Code(a1)           ; Any button?
  525.         beq     .EventHandled                  ; No, moves are ok
  526.  
  527. KillEvent:
  528.         move.b  #IECLASS_NULL,ie_Class(a1)     ; Kill event
  529.         bra     .EventHandled
  530.  
  531. SignalTask:
  532.         bsr     Signal
  533.  
  534. .EventHandled
  535.         move.l  ie_NextEvent(a1),a1             ; Get next event
  536.         bra     .nextevent
  537.  
  538. .done
  539.         movem.l (sp)+,a4
  540.         move.l  a0,d0
  541.         rts
  542.  
  543. Signal:
  544.         movem.l a0-a2/a6,-(sp)
  545.         move.l  _MyTask,a1
  546.         move.l  _SysBase,a6                     ;  Get ExecBase for Signal
  547.         jsr     _LVOSignal(a6)
  548.         movem.l (sp)+,a0-a2/a6
  549.         rts
  550.  
  551.         end
  552.