dibble@cs.rochester.edu (Peter C. Dibble) (06/30/89)
I posted this program a while ago, but it seems to have gotten
stuck somewhere. Since I am unreasonably proud of this little thing
I'm posting it again.
==========================
The BIX-One-Page-Telecommunication-Program
Written by Peter C. Dibble and K. Schmitt (Lim) in a cooperative effort
(maybe more of a contest) in the OS-9 conference on BIX.
The goal was to create an assembly language telecomunication program
that fits on one page and uses signal-driven I/O. This program is
the result. It is 66 lines long even with a few lines of comments.
It makes a two-way connection between stdin/stdout and the device named
on the command line. It terminates when a control-O is typed at the
beginning of a line on stdin.
The termination character can be changed by changing EndChar and remaking
the program.
I use the following commands to make this program:
r68020 c.a -o=c.r
l68 -g -o=c c.r -l=/h0/lib/usr.l
=======================
This program is copyrighted by BIX, Peter C. Dibble, and K. Schmitt.
We welcome improvements in the spirit of the original effort: removal of
unnecessary code or addition of features without passing 66 lines. If you
make any changes please identify your work before you pass the program on.
We give permission for any form of distribution provided that BIX and the
two authors are clearly acknowledged. Of course, we don't even claim that this
program won't cause your machine to crumble into dust, much less that it is
a useful program. In other words, there is no guarantee of any sort.
=================== The C program starts here ========================
nam c
ttl Simplest _C_ommunication program (ed #3)
*
* Attach stdin/out to the named device. call: c /scf_device
*
use <oskdefs.d>
psect c,(Prgrm<<8)+Objct,(ReEnt<<8)+0,3,256,Entry
EndChar equ $0f control-O terminates 'c'ommunication program
vsect
Buffer: ds.b 1024+128+128 I/O & opts buffer (must be > scf drv buffer)
Const: dc.w 0,SS_Ready,3,1,0,EndChar,SS_SSig,8,SS_Ready,1,0,SS_Opt
ends
Entry: movea.l a5,a0 use parm ptr as path ptr (/dev)
moveq #3,d0 update mode
os9 I$Open open Modem (MPath == #3)
bcs.s Error
move.w d0,Const+4(a6) save MPath #
movem.w Const+6(a6),d3/d4 loop counter(1) & eof char(0)
SetOpts: moveq #SS_Opt,d1
lea Buffer+1024(a6),a0
os9 I$GetStt
bcs.s Error
lea Buffer+1024+128(a6),a0
os9 I$GetStt
moveq #(PD_OVF-PD_UPC)-1,d2 number of bytes
lea 1(a0),a1 point a1 at PD_UPC
InitOpt: clr.b (a1)+
dbra d2,InitOpt
move.b d4,PD_EOF-PD_DTP+1024+128+Buffer(a6) set end char
os9 I$SetStt
movem.w Const+8(a6),d0/d4 get stdin path & eof char
dbra d3,SetOpts
lea SigRtn(PC),a0 signal handler
os9 F$Icpt set up intercept routine
bcs.s Error
bsr.s SetSig for stdin path (still in d0)
move.w Const+4(a6),d0 get Mpath
bsr.s SetSig for Mpath
Loop: moveq.l #0,d0
os9 F$Sleep
bcc.s Loop
Done: moveq.l #0,d1 clear error code
Error: os9 F$Exit
SigRtn: movem.w Const(a6),d0/d1/d3 get stdin,SS_Ready,MPath
bsr.s IO read stdin, write to MPath
move.w d3,d0 copy MPath
movem.w Const+16(a6),d1/d3 get SS_Ready&output path
bsr.s IO read MPath, write to stdout
os9 F$RTE return from intercept
IO: os9 I$GetStt test for 'data ready'
bcs.s IOX no data
lea Buffer(a6),a0
os9 I$Read
bcs.s SigDone
exg d0,d3 swap input&output paths
os9 I$Write
exg d0,d3 swap input&output paths
SetSig: movem.w Const+12(a6),d1/d2 get SS_SSig function code & signal
os9 I$SetStt
bcs.s Error
IOX rts
SigDone: movem.w Const+20(a6),d0/d1 get stdin(0) & SS_Opt code
lea Buffer+1024(a6),a0 restore the old path options
os9 I$SetStt
bra.s Done
ends