home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD2.bin / bbs / dev / tbsource.lha / TBSource / RHand / RH.S < prev   
Text File  |  1993-12-21  |  3KB  |  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/keyboard.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    RHand,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 keyboard.device
  46.  
  47.         lea.l    KeyboardName,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    #32,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    #KBD_ADDRESETHANDLER,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.         bra    ShutDown
  102.  
  103. ; Add stuff to be done here!
  104.  
  105. ML1:        bsr    DoEffect
  106.  
  107. ;        move.l    #1*50,d1
  108. ;        lib    Dos,Delay
  109.  
  110.         lea.l    IORequest,a1
  111.         move.w    #KBD_RESETHANDLERDONE,IO_COMMAND(a1)
  112.         lib    Exec,DoIO
  113.         tst.l    d0
  114.         beq    ShutDown
  115.         bra    MainLoop
  116.  
  117. ShutDown:    lea.l    IORequest,a1
  118.         move.w    #KBD_REMRESETHANDLER,IO_COMMAND(a1)
  119.         move.l    a5,IO_DATA(a1)
  120.         lib    Exec,DoIO
  121.         tst.l    d0
  122.         beq    ShutDown9000
  123.  
  124.         print    <"ERROR: Can't remove handler!",13,10>
  125.         print    <"Press CTRL-C to abort, CTRL-D to try again.",13,10>
  126.  
  127.         move.l    #$00,d0
  128.         bset    #SIGBREAKB_CTRL_C,d0
  129.         bset    #SIGBREAKB_CTRL_D,d0
  130.         lib    Exec,Wait
  131.         btst    #SIGBREAKB_CTRL_D,d0        ;Continue from
  132.         beq    ShutDown            ;CTRL-D
  133.  
  134.         print    <"Skipping...",13,10>
  135.  
  136. ShutDown9000:    move.l    IDev,d0
  137.         bne    ShutDown8000
  138.         lea.l    IORequest,a1
  139.         lib    Exec,CloseDevice
  140.  
  141. ShutDown8000:    move.l    SigBit1,d0
  142.         bmi    ShutDown7900
  143.         lib    Exec,FreeSignal
  144.  
  145. ShutDown7900:    move.l    SigBit2,d0
  146.         bmi    ShutDown7000
  147.         lib    Exec,FreeSignal
  148.  
  149. ShutDown7000:    closlib    Dos
  150.         clr.l    d0
  151.         rts
  152.  
  153. DoEffect:    lea.l    CmdName1,a0
  154.         move.l    a0,d1
  155.         clr.l    d2
  156.         clr.l    d3
  157.         lib    Dos,Execute
  158.         rts
  159.  
  160. ;Handler code starts here
  161.  
  162. HandlerCode:    push    d0-d7/a0-a6
  163.  
  164.         move.l    OurTask,a1
  165.         move.l    SigBit2,d0
  166.         lib    Exec,Signal
  167.  
  168. Handler_OUT:    pull    d0-d7/a0-a6
  169.         rts
  170.  
  171. ;Structures
  172.  
  173.         libnames
  174.  
  175. ;Other stuff, part I
  176.  
  177. SigBit1:    dc.l    0
  178. SigBit2:    dc.l    0
  179. OurTask:    dc.l    0
  180.  
  181. ;Devices
  182.  
  183. IDev:        dc.l    0
  184.  
  185. ;Strings, part I
  186.  
  187. KeyboardName:    dc.b    "keyboard.device",0
  188. ;CmdName1:    dc.b    "SPlay SAMPLES:Arnold/IllBeBack",0
  189. CmdName1:    dc.b    "SPlay SAMPLES2:HATE.SND",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.