home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD2.bin / bbs / dev / tbsource.lha / TBSource / Tests / IHand / IH.bak next >
Text File  |  1993-12-21  |  4KB  |  198 lines

  1. *************************************************
  2. *                        *
  3. *         (C)opyright 1991        *
  4. *                        *
  5. *        by  Tomi Blinnikka        *
  6. *                        *
  7. *    Don´t try to understand the code    *
  8. *                        *
  9. * Version 0.01    14/12/1991            *
  10. *                        *
  11. * BUGS:                        *
  12. *                        *
  13. *************************************************
  14.  
  15.     INCLUDE    "JMPLibs.i"
  16.     INCLUDE    "exec/types.i"
  17.     INCLUDE    "exec/nodes.i"
  18.     INCLUDE    "exec/lists.i"
  19.     INCLUDE    "exec/ports.i"
  20.     INCLUDE    "exec/memory.i"
  21.     INCLUDE    "exec/devices.i"
  22.     INCLUDE    "exec/io.i"
  23.     INCLUDE    "exec/tasks.i"
  24.     INCLUDE    "exec/interrupts.i"
  25.     INCLUDE    "libraries/dos.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.         section    IHand,CODE
  35.  
  36.         openlib    Dos,ShutDown
  37.  
  38. ;Get a signal bit
  39.  
  40.         move.l    #-1,d0
  41.         lib    Exec,AllocSignal
  42.         move.l    d0,SigBit2
  43.         bmi    ShutDown
  44.  
  45. ;Open input.device
  46.  
  47.         lea.l    InputName,a0
  48.         move.l    #$00,d0
  49.         lea.l    IORequest,a1
  50.         move.l    #$00,d1
  51.         lib    Exec,OpenDevice
  52.         move.l    d0,IDev
  53.         bne    ShutDown
  54.  
  55. ;make a message port
  56.  
  57.         lea.l    MsgPort,a2
  58.         move.b    #NT_MSGPORT,LN_TYPE(a2)
  59.         clr.b    MP_FLAGS(a2)
  60.         clr.l    LN_NAME(a2)
  61.         move.l    #-1,d0
  62.         lib    Exec,AllocSignal
  63.         move.l    d0,SigBit1
  64.         bmi    ShutDown
  65.         move.b    d0,MP_SIGBIT(a2)
  66.  
  67. ;Find this task
  68.  
  69.         move.l    #$00,a1
  70.         lib    Exec,FindTask
  71.         move.l    d0,MP_SIGTASK(a2)
  72.         move.l    d0,OurTask
  73.  
  74.         lea.l    MP_MSGLIST(a2),a0
  75.         NEWLIST    a0
  76.         lea.l    IORequest,a1
  77.         move.l    a2,MN_REPLYPORT(a1)
  78.  
  79. ;Install handler
  80.  
  81.         lea.l    Interrupt,a5
  82.         move.b    #NT_INTERRUPT,LN_TYPE(a5)
  83.         move.b    #127,LN_PRI(a5)
  84.         lea.l    HandlerCode,a2
  85.         move.l    a2,IS_CODE(a5)
  86.         move.l    #$00,IS_DATA(a5)
  87.         lea.l    IORequest,a1
  88.         move.w    #IND_ADDHANDLER,IO_COMMAND(a1)
  89.         move.l    a5,IO_DATA(a1)
  90.         lib    Exec,DoIO
  91.         tst.l    d0
  92.         bne    ShutDown
  93.  
  94. MainLoop:    ;move.l    #$00,d0
  95.         move.l    SigBit2,d0
  96.         bset.l    #SIGBREAKB_CTRL_C,d0
  97.         lib    Exec,Wait
  98.  
  99.         cmp.l    SigBit2,d0
  100.         beq    ML1
  101.         jmp    ShutDown
  102.  
  103. ; Add stuff to be done here!
  104.  
  105. ML1:        print    <"Auch."13,10>
  106.         jmp    MainLoop
  107.  
  108. ShutDown:    lea.l    IORequest,a1
  109.         move.w    #IND_REMHANDLER,IO_COMMAND(a1)
  110.         move.l    a5,IO_DATA(a1)
  111.         lib    Exec,DoIO
  112.         tst.l    d0
  113.         beq    ShutDown9000
  114.  
  115.         print    <"ERROR: Can't remove handler!",13,10>
  116.         print    <"Press CTRL-C to abort, CTRL-D to try again.",13,10>
  117.  
  118.         move.l    #$00,d0
  119.         bset    #SIGBREAKB_CTRL_C,d0
  120.         bset    #SIGBREAKB_CTRL_D,d0
  121.         lib    Exec,Wait
  122.         btst    #SIGBREAKB_CTRL_D,d0        ;Continue from
  123.         beq    ShutDown            ;CTRL-D
  124.  
  125.         print    <"Skipping...",13,10>
  126.  
  127. ShutDown9000:    move.l    IDev,d0
  128.         bne    ShutDown8000
  129.         lea.l    IORequest,a1
  130.         lib    Exec,CloseDevice
  131.  
  132. ShutDown8000:    move.l    SigBit1,d0
  133.         bmi    ShutDown7900
  134.         lib    Exec,FreeSignal
  135.  
  136. ShutDown7900:    move.l    SigBit2,d0
  137.         bmi    ShutDown7000
  138.         lib    Exec,FreeSignal
  139.  
  140. ShutDown7000:    closlib    Dos
  141.         clr.l    d0
  142.         rts
  143.  
  144. ;Handler code starts here
  145.  
  146. HandlerCode:    push    d0-d7/a0-a6
  147. HandlerCode1:    move.b    ie_Class(a0),d2
  148.         cmpi.b    #IECLASS_RAWKEY,d2
  149.         bne    HandlerCode1.1        ;Process RAWKEY events only
  150.         move.l    #IEQUALIFIER_RCOMMAND!IEQUALIFIER_LCOMMAND,d0
  151.         move.l    d0,d1
  152.         and.w    ie_Qualifier(a0),d1
  153.         cmp.w    d0,d1
  154.         beq    HandlerCode2
  155.  
  156. HandlerCode1.1:    move.l    ie_NextEvent(a0),d0
  157.         move.l    d0,a0
  158.         bne    HandlerCode1
  159.         jmp    Handler_OUT
  160.  
  161. HandlerCode2:    cmp.w    #$63,ie_Code(a0)
  162.         bne    Handler_OUT
  163.         move.b    #IECLASS_NULL,ie_Class(a0)    ;Kill this event
  164.         move.l    OurTask,a1
  165.         move.l    SigBit2,d0
  166.         lib    Exec,Signal
  167.         clr.l    a0
  168.  
  169. Handler_OUT:    pull    d0-d7/a0-a6
  170.         move.l    a0,d0
  171.         rts
  172.  
  173. ;Structures
  174.  
  175.         libnames
  176.  
  177. ;Other stuff, part I
  178.  
  179. SigBit1:    dc.l    0
  180. SigBit2:    dc.l    0
  181. OurTask:    dc.l    0
  182.  
  183. ;Devices
  184.  
  185. IDev:        dc.l    0
  186.  
  187. ;Strings, part I
  188.  
  189. InputName:    dc.b    "input.device",0
  190.         ds.l    0
  191.  
  192. ;Other stuff, part II
  193.  
  194. IORequest:    dcb.b    IO_SIZE,0
  195. MsgPort:    dcb.b    MP_SIZE,0
  196. Interrupt:    dcb.b    IS_SIZE,0
  197.         end
  198.