	.title	MOTALK program to set up a modem using MO
	.mcall	.print,.serr,.csigen,.spfun,.writw,.twait,.close,.exit,.gtlin
	.macro	ioerror	mes,?a
	bcc	a
	jsr	r5,a
	.asciz	\mes\
	.even
a:	
	.endm
	.macro	dotsx	code
	mov	code,r0
	emt	375
	.endm
	.macro	intsx	flag=tsxflg,?a,?b,?c,?d
	clr	flag
	dotsx	#b
	bcs	a
	com	flag
	dotsx	#c
	bcc	a
	.print	#d
	clr	r0
	.exit
d:	.asciz	\TSX Lock failed\
	.even	
b:	.byte	0,110
c:	.byte	7,140
a:
	.endm
	

bs=50.		;read size
mochan=0	;modem channel
cr=15		;a carriage return
rd$on=377
rd$of=376
wrt$q=374
start:	.serr		;handle errors
	intsx		;set up for tsx
	.csigen		#free,#dtext,#str
	.spfun	#marea,#mochan,#rd$on,#rsize
	ioerror	<cannot connect>
	.gtlin	#buffer
	clr	r1
	mov	#buffer,r2
10$:	tstb	(r2)+
	beq	20$
	inc	r1
	br	10$
20$:	movb	#cr,-1(r2)	;r2 points past zero r1 has count
	clrb	(r2)+
	clrb	(r2)
	add	#3,r1
	ror	r1
	.writw	#marea,#mochan,#buffer,r1,#0
	ioerror	<write failed>
	tst	tsxflg
	beq	30$
	.twait	#marea,#time
	ioerror	<wait failed>
30$:	.spfun	#marea,#mochan,#rd$of
	ioerror	<off failed>
	.close	#mochan
	.exit
fatal:	.print	#errmes
	.print	r5
	clr	r0
	.exit
time:	.word	0,60.*2.
wrtflg:	.word	0
dtext:	.word	0,0,0,0
tsxflg:	.word	0
marea:	.blkw	6
;***these must be this way
rsize:	.word	bs,0,bs,0,0,0
	.blkb	bs
buffer:	.blkb	82.
str:	.asciz	\MO:=\
errmes:	.ascii	<7>\MOTALK-F-\<200>
	.even
free=.
	.end	start
