home *** CD-ROM | disk | FTP | other *** search
- *************************************************
- * *
- * (C)opyright 1993 *
- * *
- * by Tomi Blinnikka *
- * *
- * Don´t try to understand the code *
- * *
- * Version 0.01 02/04/1993 *
- * -0.99ö - *
- * *
- * BUGS: *
- * *
- *************************************************
-
- INCLUDE "JMPLibs.i"
- INCLUDE "exec/types.i"
- INCLUDE "exec/nodes.i"
- INCLUDE "exec/lists.i"
- INCLUDE "exec/ports.i"
- INCLUDE "exec/memory.i"
- INCLUDE "exec/devices.i"
- INCLUDE "exec/io.i"
- INCLUDE "exec/tasks.i"
- INCLUDE "exec/interrupts.i"
- INCLUDE "libraries/dos.i"
- INCLUDE "devices/input.i"
- INCLUDE "devices/inputevent.i"
-
- ; INCLUDE "XREF:2.0.xref"
- INCLUDE "XREF:intuition.xref"
- INCLUDE "XREF:exec.xref"
- INCLUDE "XREF:dos.xref"
-
- section SerialKeyBoard,CODE
-
- oldlib Dos,ShutDown
-
- ;Get a signal bit
-
- move.l #-1,d0
- lib Exec,AllocSignal
- move.l d0,SigBit2
- bmi ShutDown
-
- ;Open input.device
-
- lea.l InputName,a0
- move.l #$00,d0
- lea.l IORequest,a1
- move.l #$00,d1
- lib Exec,OpenDevice
- move.l d0,IDev
- bne ShutDown
-
- ;make a message port
-
- lea.l MsgPort,a2
- move.b #NT_MSGPORT,LN_TYPE(a2)
- clr.b MP_FLAGS(a2)
- clr.l LN_NAME(a2)
- move.l #-1,d0
- lib Exec,AllocSignal
- move.l d0,SigBit1
- bmi ShutDown
- move.b d0,MP_SIGBIT(a2)
-
- ;Find this task
-
- move.l #$00,a1
- lib Exec,FindTask
- move.l d0,MP_SIGTASK(a2)
- move.l d0,OurTask
-
- lea.l MP_MSGLIST(a2),a0
- NEWLIST a0
- lea.l IORequest,a1
- move.l a2,MN_REPLYPORT(a1)
-
- ;Install handler
-
- lea.l Interrupt,a5
- move.b #NT_INTERRUPT,LN_TYPE(a5)
- move.b #127,LN_PRI(a5)
- lea.l HandlerCode,a2
- move.l a2,IS_CODE(a5)
- move.l #$00,IS_DATA(a5)
- lea.l IORequest,a1
- move.w #IND_ADDHANDLER,IO_COMMAND(a1)
- move.l a5,IO_DATA(a1)
- lib Exec,DoIO
- tst.l d0
- bne ShutDown
-
- MainLoop: ;move.l #$00,d0
- move.l SigBit2,d0
- bset.l #SIGBREAKB_CTRL_C,d0
- lib Exec,Wait
-
- cmp.l SigBit2,d0
- beq ML1
- bra ShutDown
-
- ; Add stuff to be done here!
-
- ML1: print <"Auch."13,10>
- bra MainLoop
-
-
-
-
-
- ShutDown: lea.l IORequest,a1
- move.w #IND_REMHANDLER,IO_COMMAND(a1)
- move.l a5,IO_DATA(a1)
- lib Exec,DoIO
- tst.l d0
- beq ShutDown9000
-
- print <"ERROR: Can't remove handler!",13,10>
- print <"Press CTRL-C to abort, CTRL-D to try again.",13,10>
-
- move.l #$00,d0
- bset #SIGBREAKB_CTRL_C,d0
- bset #SIGBREAKB_CTRL_D,d0
- lib Exec,Wait
- btst #SIGBREAKB_CTRL_D,d0 ;Continue from
- beq ShutDown ;CTRL-D
-
- print <"Skipping...",13,10>
-
- ShutDown9000: move.l IDev,d0
- bne ShutDown8000
- lea.l IORequest,a1
- lib Exec,CloseDevice
-
- ShutDown8000: move.l SigBit1,d0
- bmi ShutDown7900
- lib Exec,FreeSignal
-
- ShutDown7900: move.l SigBit2,d0
- bmi ShutDown7000
- lib Exec,FreeSignal
-
- ShutDown7000: closlib Dos
- clr.l d0
- rts
-
- ;Handler code starts here
-
- HandlerCode: push d0-d7/a0-a6
- HandlerCode1: move.b ie_Class(a0),d2
- cmpi.b #IECLASS_RAWKEY,d2
- bne HandlerCode1.1 ;Process RAWKEY events only
- move.l #IEQUALIFIER_RCOMMAND!IEQUALIFIER_LCOMMAND,d0
- move.l d0,d1
- and.w ie_Qualifier(a0),d1
- cmp.w d0,d1
- beq HandlerCode2
-
- HandlerCode1.1: move.l ie_NextEvent(a0),d0
- move.l d0,a0
- bne HandlerCode1
- bra Handler_OUT
-
- HandlerCode2: cmp.w #$63,ie_Code(a0)
- bne Handler_OUT
- move.b #IECLASS_NULL,ie_Class(a0) ;Kill this event
- move.l OurTask,a1
- move.l SigBit2,d0
- lib Exec,Signal
- move.l #$00,a0
-
- Handler_OUT: pull d0-d7/a0-a6
- move.l a0,d0
- rts
-
- ;Structures
-
- libnames
-
- ;Other stuff, part I
-
- SigBit1: dc.l 0
- SigBit2: dc.l 0
- OurTask: dc.l 0
-
- ;Devices
-
- IDev: dc.l 0
-
- ;Strings, error
-
- ;Strings, part I
-
- VersionString: dc.b "$VER: SerialKeyBoard Server 0.11 (02.04.93) (C)opyright Tomi Blinnikka 1993",0
- InputName: dc.b "input.device",0
- ds.l 0
-
- ;Other stuff, part II
-
- IORequest: dcb.b IO_SIZE,0
- MsgPort: dcb.b MP_SIZE,0
- Interrupt: dcb.b IS_SIZE,0
- end
-