.Title	CLOCK	- for typing time.
.Enabl	lc,gbl
.Nlist	Bex,Toc

.Sbttl	V3C	21-Jan-83

.Mcall	.ttinr,.exit,.scca,.print

jsw=44
b.tinh=100
b.tspm=10000

esc=33
lf=12
cr=15

Start::
	Call	Datsub		;Put date at top of terminal

	mov	#str,sptr	;Reset pointers to user's type-in string
	movb	#200,str

	call	tthclr		;Set up terminal for clock
	call	ttasci
	call	tcrlf
	call	ttdhb
	call	tthome
	.scca	#area,#scblk
	bis	#b.tinh!b.tspm,@#jsw

10$:
	mov	#timblk,r2
	call	rstim

	.print	#ps
	call	ttrclr
	call	tcrlf

	mov	#'a,r5
	cmp	hours,#12.
	blo	20$
	beq	15$
	sub	#12.,hours
15$:
	mov	#'p,r5
20$:
	mov	#15.,r0
	call	ttpos

	mov	#-1,r0
	mov	#str1,r1
	call	wtim
	movb	#' ,(r1)+
	movb	r5,(r1)+
	movb	#'m,(r1)+
	clrb	(r1)

	call	tdset
	mov	#string,r0
	call	tdstr
	call	ttin
	bcs	10$

;User has typed something.  Wait 15 seconds and type a bell.

30$:
	call	ttin
	bcc	30$

	mov	rtim1,tima
	mov	rtim2,timb

	call	tthclr

	mov	#1,r4		;Counter
	mov	tclock,r5	;Initial typing point
	call	ttlite
70$:
	call	ttin		;If typed something, stop it
	bcc	100$

	mov	#timblk,r2
	call	rstim

	mov	rtim2,r3
	sub	timb,r3

	cmp	r3,r5		;See if want to display next number
	blo	80$

	.print	#ps
	call	ttrclr

	mov	#15.,r0
	call	ttpos
	call	tdset

	add	tclock,r5
	mov	r4,r0
	mov	#str1,r1
	call	wd
	clrb	(r1)
	mov	#string,r0
	call	tdstr
	inc	r4
80$:
	cmp	tclock,#50.
	beq	90$

	cmp	r3,#15.*60.
	bhis	100$
	br	70$
90$:
	cmp	r3,#15.*50.
	blo	70$

100$:
	.ttinr
	bcc	100$
	call	ttdark
	br	10$

ttin:
	.ttinr
	bcc	10$
	return
10$:
	cmpb	r0,#lf
	bne	20$

	call	tthclr
	mov	#str,r1
	jmp	exit$
20$:
	cmpb	r0,#3
	bne	30$

	call	tthclr
	.exit
30$:
	cmpb	r0,#'U-100
	bne	35$

	mov	#str,sptr
	movb	#200,str
	br	ttin
35$:
	cmpb	r0,#40
	bhi	40$
	bne	38$

	cmp	sptr,#str
	bne	40$
38$:
	clc
	return
40$:
	cmpb	r0,#177
	bne	50$

	dec	sptr
	cmp	sptr,#str
	bhis	60$
	inc	sptr
	br	60$
50$:
	movb	r0,@sptr
	inc	sptr
60$:
	movb	#200,@sptr
	br	ttin

string: .ascii	/            /
str1:	.blkb	14.
area:	.blkw	7
scblk:	.blkw	1
tima:	0
timb:	0
sptr:	0
ps:	.ascii	<esc>/[1;35f/
str:	.blkb	80.
	.even

.end	start
