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