home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 2 / FFMCD02.bin / new / dev / asm / tbsource / questions / qihandler.s < prev    next >
Encoding:
Text File  |  1993-12-21  |  4.2 KB  |  231 lines

  1. *************************************************
  2. *                        *
  3. *         (C)opyright 1991        *
  4. *                        *
  5. *        by  Tomi Blinnikka        *
  6. *                        *
  7. *    DonĀ“t try to understand the code    *
  8. *                        *
  9. * Version: See info from main source code    *
  10. *                        *
  11. *************************************************
  12.  
  13.  
  14.     INCLUDE    "JMPLibs.i"
  15.     INCLUDE    "exec/types.i"
  16.     INCLUDE    "exec/nodes.i"
  17.     INCLUDE    "exec/lists.i"
  18.     INCLUDE    "exec/ports.i"
  19.     INCLUDE    "exec/memory.i"
  20.     INCLUDE    "exec/devices.i"
  21.     INCLUDE    "exec/io.i"
  22.     INCLUDE    "exec/tasks.i"
  23.     INCLUDE    "exec/interrupts.i"
  24.     INCLUDE    "libraries/dos.i"
  25.     INCLUDE    "intuition/intuition.i"
  26.     INCLUDE    "devices/input.i"
  27.     INCLUDE    "devices/inputevent.i"
  28.  
  29.     INCLUDE    "XREF:2.0.xref"
  30.     INCLUDE    "XREF:intuition.xref"
  31.     INCLUDE    "XREF:exec.xref"
  32.     INCLUDE    "XREF:dos.xref"
  33.  
  34.     XREF    _DosBase
  35.     XREF    OurTask
  36.     XREF    DesStrGad1
  37.     XREF    IHandler
  38.     XREF    _stdout
  39.  
  40.     XDEF    OurIntuiMsg
  41.     XDEF    MakeIHand
  42.     XDEF    RemIHand
  43.     XDEF    SigBit2
  44.  
  45. OURCODE:    EQU    $DEADBEEF
  46.  
  47.         section    IHand,CODE
  48.  
  49. ;Get a signal bit
  50.  
  51. MakeIHand:    move.l    #-1,d0
  52.         lib    Exec,AllocSignal
  53.         move.l    d0,SigBit2
  54.         bmi    RemIHand
  55.  
  56. ;Open input.device
  57.  
  58.         lea.l    InputName,a0
  59.         move.l    #$00,d0
  60.         lea.l    IORequest,a1
  61.         move.l    #$00,d1
  62.         lib    Exec,OpenDevice
  63.         move.l    d0,IDev
  64.         bne    RemIHand
  65.  
  66. ;Make a message port
  67.  
  68.         lea.l    MsgPort,a2
  69.         move.b    #NT_MSGPORT,LN_TYPE(a2)
  70.         clr.b    MP_FLAGS(a2)
  71.         clr.l    LN_NAME(a2)
  72.         move.l    #-1,d0
  73.         lib    Exec,AllocSignal
  74.         move.l    d0,SigBit1
  75.         bmi    RemIHand
  76.         move.b    d0,MP_SIGBIT(a2)
  77.  
  78.  
  79.         move.l    OurTask,MP_SIGTASK(a2)
  80.  
  81.         lea.l    MP_MSGLIST(a2),a0
  82.         NEWLIST    a0
  83.         lea.l    IORequest,a1
  84.         move.l    a2,MN_REPLYPORT(a1)
  85.  
  86. ;Install handler
  87.  
  88.         lea.l    Interrupt,a5
  89.         move.b    #NT_INTERRUPT,LN_TYPE(a5)
  90.         move.b    #120,LN_PRI(a5)
  91.         lea.l    HandlerCode,a2
  92.         move.l    a2,IS_CODE(a5)
  93.         lea.l    OurIntuiMsg,a1
  94.         move.l    a1,IS_DATA(a5)
  95.         lea.l    IHandName,a1
  96.         move.l    a1,LN_NAME(a5)
  97.         lea.l    IORequest,a1
  98.         move.w    #IND_ADDHANDLER,IO_COMMAND(a1)
  99.         move.l    a5,IO_DATA(a1)
  100.         lib    Exec,DoIO
  101.         tst.l    d0
  102.         bne    RemIHand
  103.         move.l    #-1,d0
  104.         rts
  105.  
  106. RemIHand:    lea.l    Interrupt,a5
  107.         lea.l    IORequest,a1
  108.         move.w    #IND_REMHANDLER,IO_COMMAND(a1)
  109.         move.l    a5,IO_DATA(a1)
  110.         lib    Exec,DoIO
  111.         tst.l    d0
  112.         beq    RemIHand9000
  113.  
  114.         print    <"ERROR: Can't remove handler!",13,10>,_stdout
  115.         print    <"Press CTRL-C to abort, CTRL-D to try again.",13,10>,_stdout
  116.  
  117.         move.l    #$00,d0
  118.         bset    #SIGBREAKB_CTRL_C,d0
  119.         bset    #SIGBREAKB_CTRL_D,d0
  120.         lib    Exec,Wait
  121.         btst    #SIGBREAKB_CTRL_D,d0        ;Continue from
  122.         beq    RemIHand            ;CTRL-D
  123.  
  124.         print    <"Skipping...",13,10>,_stdout
  125.  
  126. RemIHand9000:    move.l    IDev,d0
  127.         bne    RemIHand8000
  128.         lea.l    IORequest,a1
  129.         lib    Exec,CloseDevice
  130.  
  131. RemIHand8000:    move.l    SigBit1,d0
  132.         bmi    RemIHand7900
  133.         lib    Exec,FreeSignal
  134.  
  135. RemIHand7900:    move.l    SigBit2,d0
  136.         bmi    RemIHand7000
  137.         lib    Exec,FreeSignal
  138.  
  139. RemIHand7000:    clr.l    d0
  140.         rts
  141.  
  142. ;Handler code starts here
  143.  
  144. HandlerCode:    push    d0-d7/a0-a6
  145.         tst.w    IHandler
  146.         beq    Handler_OUT
  147. HandlerCode1:    move.b    ie_Class(a0),d2
  148.         cmpi.b    #IECLASS_RAWKEY,d2
  149.         bne    HandlerCode2            ;Process RAWKEY events only
  150.         cmp.w    #IECODE_UP_PREFIX,ie_Code(a0)    ;Process only key going
  151.         bne    HandlerCode3            ;down
  152.  
  153. HandlerCode2:    move.l    ie_NextEvent(a0),d0
  154.         move.l    d0,a0
  155.         bne    HandlerCode1
  156.         jmp    Handler_OUT
  157.  
  158. HandlerCode3:    move.l    #IEQUALIFIER_RCOMMAND,d0
  159.         move.l    d0,d1
  160.         and.w    ie_Qualifier(a0),d1
  161.         cmp.w    d0,d1
  162.         bne    Handler_OUT
  163.  
  164. HandlerCode4:    jsr    TestGads
  165.         tst.l    d0
  166.         bne    Handler_OUT
  167.         cmp.w    #$32,ie_Code(a0)        ;Don't do Q or
  168.         beq    Handler_OUT            ;Z, cos' there
  169.         cmp.w    #$10,ie_Code(a0)        ;in use by system
  170.         beq    Handler_OUT
  171.         move.b    #IECLASS_NULL,ie_Class(a0)    ;Kill this event
  172.         move.w    ie_Code(a0),im_Code(a1)
  173.         move.l    #OURCODE,im_Class(a1)
  174.         move.l    OurTask,a1
  175.         move.l    SigBit2,d0
  176.         lib    Exec,Signal
  177.  
  178. Handler_OUT:    pull    d0-d7/a0-a6
  179.         move.l    a0,d0
  180.         rts
  181.  
  182. ;Test if any string gadgets are active.
  183. ;d0 = 0 if one is
  184. ;d0 = -1 if none are
  185.  
  186. TestGads:    push    d1/a1
  187.         lea.l    DesStrGad1,a1
  188. TestGads1:    move.w    #SELECTED,d0
  189.         move.w    d0,d1
  190.         and.w    gg_Flags(a1),d1
  191.         cmp.w    d0,d1
  192.         beq    TestGads2
  193.  
  194.         move.l    (a1),a1
  195.         cmp.l    #$00,a1
  196.         bne    TestGads1
  197.         pull    d1/a1
  198.         move.l    #$-1,d0
  199.         rts
  200.  
  201. TestGads2:    pull    d1/a1
  202.         move.l    #$00,d0
  203.         rts
  204.  
  205. ;Structures
  206.  
  207.         libnames
  208.  
  209. ;Other stuff, part I
  210.  
  211. SigBit1:    dc.l    0
  212. SigBit2:    dc.l    0
  213.  
  214. ;Devices
  215.  
  216. IDev:        dc.l    0
  217.  
  218. ;Strings, part I
  219.  
  220. InputName:    dc.b    "input.device",0
  221. IHandName:    dc.b    "Questions",0
  222.         ds.l    0
  223.  
  224. ;Other stuff, part II
  225.  
  226. IORequest:    dcb.b    IO_SIZE,0
  227. MsgPort:    dcb.b    MP_SIZE,0
  228. Interrupt:    dcb.b    IS_SIZE,0
  229. OurIntuiMsg:    dcb.b    52,0
  230.         end
  231.