home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD2.bin / bbs / dev / tbsource.lha / TBSource / SerialKeyBoard / SKH.S next >
Text File  |  1993-12-21  |  4KB  |  206 lines

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