	.LIST TTM
	.psect	clock
	.title	isc clock display
;
; this program displays a digital clock on the face of a isc display
;
; written by:
;	mark johnson, september 22, 1977.
; modified by r hughes sept 21.1978
;
	.mcall	ttyout,tinit,enter,leave
	.mcall	qio$s,gtim$s,mrkt$s,wtse$s
	.dsabl	gbl

;
esc=33	;escape code used to signal vt52 command
lf=12	;line feed code
cursr=103	;cursor right command
cursl=104	;cursor left command
cursu=101	;cursor up command
cursd=102	;cursor down command
;
digtop=12.	;code for top line of digits
diglin=20.	;number of lines in a digit
bits=16.	;number of columns in a digit
;
cohr10=2
cohr1=20.
colcol=38.
comn10=44.
comn1=62.
;
; SCREEN COLOR'S
; BLACK=0	RED=1		GREEN=2	YELLOW=3
; BLUE=4	MAGENTA=5	CYAN=6	WHITE=7
bs=3    ;screen background color
bl=4    ;letter  "    "      "
fl=3    ;  "    forground color
; COLOR ON EXIT
ebs=4	;background
efl=7	;forground
;
tc=25.	;code for title column
tr=3.	;code for title row
tb=0	;background title colour
tf=2	;forground title colour
;
dc=35.	;date colomn
dr=9.	;date row
db=3.	;date background colour
df=4.	;date forgroun colour
;
mc=44.	;message colomn
mr=40.	;message row
mb=2	;message background colour
mf=0	;message forground colour
tlet=tb*10+tf
mlet=mb*10+mf
screen=bs+20
let=bl*10+fl
dlet=db*10+df
;
	.globl	io.att		;attach command needed for output
io.wvb=410	;need to use write/pass all for cursor control
;
	.macro	fill	addr,char
	mov	addr,r3		;get address
	movb	char,(r3)+
	movb	char,(r3)+
	movb	char,(r3)+
	.endm
;
	.mcall ttsym$
	ttsym$
start:	tinit	5,1
	qio$s	#io.att!tf.ast,#5,,,,,<#int>
;
; initialize storage
;
cycle:	mov	#-1,hr10	;force display first time
	mov	#-1,hr1
	mov	#-1,mn10
	mov	#-1,mn1
;
	ttyout	#erase,#erasel	;erase the screen
	mrkt$s	#2,#50,#1
	wtse$s	#2
	ttyout #title,#titlel	;write title
	jsr  pc,gdate		;write date
;
loop:	gtim$s	#tbuf	;get time from system
	mov	tbuf+10,r5	;get minute
	clr	r4		;double precision
	div	#10.,r4		;tens dig in r4, units in r5
;
	cmp	r5,mn1		;minute digit ok?
	beq	4$		;ok, don't change it
2$:	jsr  pc,chkmes
	mov	r5,mn1		;update memory
	movb	#comn1,COLM	;set up column number
	jsr	pc,char		;show this one
;
	cmp	r4,mn10		;tens digit ok?
	beq	4$		;ok, don't change it
 	mov	r4,r5		;set up paramater
	mov	r4,mn10		;update memory
	movb	#comn10,COLM	;set up column number
	jsr	pc,char		;show the digit
;
	mov	tbuf+6,r5	;get hours
	clr	r4		;double precision
	div	#10.,r4		;tens digit in r4, ones in r5
;
	cmp	r5,hr1		;how is the units digit?
	beq	4$		;ok, don't change it
	mov	r5,hr1		;update memory
	movb	#cohr1,COLM	;set up column number
	jsr	pc,char		;show this one
;
	cmp	r4,hr10		;tens digit ok?
	beq	4$		;yes, skip this stuff
 	mov	r4,r5		;set up paramater
	mov	r4,hr10		;update memory
	movb	#cohr10,COLM	;set up column number
	jsr	pc,char		;display it
;
; update seconds
;
4$:	gtim$s	#tbuf		;fresh time for seconds accuracy
	mrkt$s  #2,#1,#2
	mov	tbuf+12,r5	;get seconds
	clr	r4		;dubble precise
	div	#10.,r4		;tens in r4, units in r5
	add	#'0,r4		;convert to ascii
	add	#'0,r5		;convert to ascii
;
	fill	#s101,r4
	fill	#s102,r4
	fill	#s103,r4
;
	fill	#s11,r5
	fill	#s12,r5
	fill	#s13,r5
;
	ttyout	#colon,#colen
	cmp  #66,r5
	beq  5$
	cmp  #61,r5
	bne  6$
5$:	tstb refr
	beq  55$
	movb #8.,cnt
	clrb refr
	jmp cycle
55$:	jsr  pc,tstblk
;
;wait for a while
;
;6$:	mrkt$s	#2,#1,#2	;wait one second
6$:	wtse$s	#2		;wait for it
;
	jmp	loop		;then go again
	.SBTTL INT - ROUTINE FOR UNCOLICITED INPUT
;
	.MCALL ASTX$S,EXIT$S
INT:
	MOV  (SP)+,REFR
	CMPB #3,REFR
	BNE  5$
	ttyout	#erasa,#erasal	;erase the screen
	EXIT$S
5$:	ASTX$S
REFR:	.WORD 0
	.page
	.sbttl	char - display one character
;
; char - display one character
;
; inputs:
;	r2 - column number of first column of character
;	r5 - digit to display in range 0-9.
;
; outputs: none
;
char:	enter	r0,r1,r2,r3,r4,r5
	movb	chtb(r5),r1	;set up character to use
	asl	r5		;convert to words
	mov	mptb(r5),r0	;get map address
;
; move to upper left corner of character
;
6$:	movb	#digtop,line	;set up top line address
	ttyout	#movit,#MOVITL	;send the command
	ttyout	#space,#bits+1
	incb line
	ttyout	#movit,#movitl
;
; main character loop
;
	mov	#diglin,r3	;number of lines per character
4$:	mov	(r0)+,r4		;one row of bits
	mov	#bits,r5	;number of bits per line
	mov	#linbuf+1,r2	;address of output buffer
;
; line loop
;
3$:	rol	r4		;get the next bit
	bcc	1$		;clear => don't write
	movb	r1,(r2)+	;set => insert character
	br	2$		;exit
;
1$:	movb	#40,(r2)+
;
2$:	sob	r5,3$	
	movb #40,(r2)
;
; line ready to send
;
	ttyout	#linbuf,#bits+2	;send one character line
;
; move to next line of character
;
	incb line
	ttyout  #movit,#movitl	;send command
;
	sob	r3,4$		;end of pass
	ttyout	#space,#bits+1
;
5$:	leave
	rts	pc
	.page
	.SBTTL GDATE
;
GDATE:	GTIM$S #TBUF
	MOV  TBUF,R5		;YEAR SINCE 1900
	CLR  R4
	DIV  #10.,R4		;10'S IN R4, 1'S IN R5
	BISB R4,YEAR+2
	BISB R5,YEAR+3
	MOV  TBUF+2,R4
	DEC  R4
	MUL #3,R4
	ADD  #MON,R5
	MOVB (R5)+,MONTH
	MOVB (R5)+,MONTH+1
	MOVB (R5),MONTH+2
	MOV  TBUF+4,R5		;DAY
	CLR  R4
	DIV  #10.,R4
	BISB R4,DAY
	BISB R5,DAY+1
	TTYOUT #DATE,#DATEL
	RTS PC
;
DATE:	.BYTE 3,81.,DC,DR,DLET
DAY:	.BYTE 60,60,55
MONTH:	.BYTE 0,0,0,55
YEAR:	.BYTE 61,71,60,60
	DATEL=.-DATE
MON:	.ASCII /JANFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC/
	.EVEN
	.PAGE
	.SBTTL CHKMSG
CHKMES:	ENTER R2,R3,R4,R5
	CLR  R3		;COUNTER
	MOV  #TIMES,R2	;TIMES ADDRESS
	MOV  (R2)+,R4	;# OF MESSAGES
10$:	CMP  TBUF+6,(R2)+	;CHECK HOURS
	BEQ  20$	;CORRECT HOUR.
	TST  (R2)+	;BUMP POINTER
15$:	TST  (R2)+
18$:	INC  R3		;BUMP COUNTER
	SOB  R4,10$
	BR   30$	;NO MESSAGES FOUND
20$:	CMP  TBUF+10,(R2)+	;CHECK START MINUTES
	BLT  15$		;TOO SOON
	CMP  TBUF+10,(R2)+		;CHECK END MIN.
	BLT  25$	;GO PRINT MESSAGE
	BNE  18$	;MUST BE TOO LATE
	TTYOUT #MES0,#MES0L	;ERASE MESSAGE
	BR   30$
25$:	ASL  R3		;WORD POINTER
	MOV  MESMAP(R3),R4
	MOVB (R4)+,R5
	TTYOUT  #MPOS,#MPOSL
	TTYOUT  R4,R5
30$:	LEAVE
	RTS  PC
;
MPOS:	.BYTE 3,81.,MC,MR,MLET
	MPOSL=.-MPOS
	.EVEN
TIMES:	.WORD 3
	.WORD 10.,00,15.
	.WORD 12.,00,30.
	.WORD 15.,00,15.
MESMAP:	.WORD MES1,MES2,MES1
MES0:	.BYTE MES0L,3,81.,MC,MR,BS*10
	.ASCII /            /
	MES0L=.-MES0
MES1:	.BYTE MES1L
	.ASCII /COFFEE TIME/
	MES1L=.-MES1
MES2:	.BYTE MES2L
	.ASCII /LUNCH TIME/
	MES2L=.-MES2
	.EVEN
	.PAGE
	.SBTTL TSTBLK
;
	TSTC=2
	TSTR=40.
;
TSTBLK:
	ENTER R0,R1
	CMPB #7,CNT	;CHECK FORGROUND CNT
	BGE  20$
	CLRB CNT
	INCB TSTB
	CMPB #7.,TSTB   ;CHECK BACKGROUND COLOUR
	BGE  15$
	CLRB TSTB
15$:
	MOVB TSTB,TSTF
	MOVB TSTB,R0
	MUL #10,R0
	MOVB R1,TSTF1+4	;SETUP COLOUR
	MOVB #TSTR,TSTF1+3	;SETUP TOW
	TTYOUT #TSTF1,#TSTF1L	;FILL BACKGROUND
	INCB TSTF1+3
	TTYOUT #TSTF1,#TSTF1L   ;FILL BACKGROUND
	INCB TSTF1+3
	TTYOUT #TSTF1,#TSTF1L   ;FILL BACKGROUND
20$:	MOVB TSTF1+4,R1	;GET BACKGROUND STATUS
	ADD TSTF,R1	;INCLUDE FORGROUND STATUS
	CMPB TSTF,TSTB	;FOR & BACK COL. THE SAME?
	BNE  30$
	ADD  #100,R1	;YES, MAKE TEXT FLASH
30$:	MOVB R1,TSTF3+4	;PUT STATUS IN BYTE ARRAY
	MOVB TSTF,R0
	MUL #7,R0
	ADD #COL,R1	;SHOULD BE ADDRESS OF ASCII STRING
	TTYOUT #TSTF3,#5	;POS'N CURSER
	TTYOUT R1,#7	;PRINT TEXT COLOUR
	INCB CNT
	INCB TSTF
	CMPB  #7,TSTF
	BGE  40$
	CLRB  TSTF
40$:	LEAVE
	RTS PC
;
TSTF:	.BYTE 8.
TSTB:	.BYTE 8.
CNT:	.BYTE 8.
TSTF1:	.BYTE 3,81.,TSTC,TSTR,0
	.ASCII /                 /
	TSTF1L=.-TSTF1
TSTF3:	.BYTE 3,81.,TSTC+5,TSTR+1,0
	.EVEN
COL:	.ASCII /BLACK  RED    GREEN  YELLOW BLUE   MAGENTA/
	.ASCII /CYAN   WHITE  /
	.PAGE
	.sbttl	buffers, etc.
;
;
;erase screen by home, erase to end of screen
;
erase:	.byte	30.,screen,12.
erasel=.-erase
erasa:	.byte 255.,2,3,0,0,255.
	.byte 30.,11.	;remove angle
	.byte 30.,20+ebs,12.	;set color and clr
	.byte 30.,108,30.,107,30.,102
erasal=.-erasa
;
;
;title buffer
title:	.byte 3,81.,tc,tr,tlet
space:	.ASCII /                              /
	.byte 3,81.,tc,tr+1,tlet
	.ascii / HUMAN INFORMATION PROCESSING /
        .byte 3,81.,tc,tr+2,tlet
        .ASCII /                              /
        .byte 3,81.,tc,tr+3,tlet
	.ASCII /      -DISPLAY RESEARCH-      /
        .byte 3,81.,tc,tr+4,tlet
        .ASCII /                              /
	titlel=.-title
; direct cursor addressing command buffer
;
	.even
movit:	.byte	3
	.byte	81.
colm:	.byte	1	;1 is top line
line:	.byte 0
	.byte	let
	.byte 0,0,0,0
MOVITL=.-MOVIT
;
;
; instructions to draw a colon
;
colon:	.byte	3
	.byte	81.
	.byte	colcol
	.byte	digtop+6
	.byte	let	;colour
	.byte	0,0,0,0,0,0,40
s101:	.ascii	/:::/
	.byte	40,3,81.,colcol,digtop+7,let,40
s102:	.ascii	/:::/
	.byte	40,3,81.,colcol,digtop+8.,let,40
s103:	.ascii	/:::/
	.byte	40,3,81.,colcol,digtop+11.,let,40
s11:	.ascii	/:::/
	.byte	40,3,81.,colcol,digtop+12.,let,40
s12:	.ascii	/:::/
	.byte	40,3,81.,colcol,digtop+13.,let,40
s13:	.ascii	/:::/
	.byte 40
colen=.-colon
;
; output line buffer
;
linbuf:	.byte	0	;null for good measure
	.blkb	bits+1
;
	.even
tbuf:	.blkw	8.
;
hr10:	.word	0
hr1:	.word	0
mn10:	.word	0
mn1:	.word	0
;
; tables
;
chtb:	.ascii	/0123456789/
mptb:	.word	map0,map1,map2,map3,map4,map5,map6,map7,map8,map9
;
	.page
	.sbttl	bit maps
	.nlist	bex
	.even
;
; character 0
;
map0:	.word	03760,17774,30006,60003,60003
	.word	60003,60003,60003,60003,60003
	.word	60003,60003,60003,60003,60003
	.word	60003,60003,30006,17774,03760
;
map1:	.word	00300,00700,01700,03700,00300
	.word	00300,00300,00300,00300,00300
	.word	00300,00300,00300,00300,00300
	.word	00300,00300,00300,07776,07776
;
map2:	.word	03760,17774,30006,60003,00003
	.word	00003,00003,00006,00014,00030
	.word	00060,00140,00300,00600,01400
	.word	03000,06000,14000,37777,77777
;
map3:	.word	03760,17774,30006,60003,00003
	.word	00003,00003,00003,00006,00014
	.word	00014,00006,00003,00003,00003
	.word	00003,60003,30006,17774,03760
;
map4:	.word	00030,00070,00170,00330,00630
	.word	01430,03030,06030,14030,30030
	.word	77777,77777,00030,00030,00030
	.word	00030,00030,00030,00030,00030
;
map5:	.word	77777,77777,60000,60000,60000
	.word	60000,60000,77000,37740,00770
	.word	00014,00006,00003,00003,00003
	.word	00003,60003,30006,17774,03760
map6:	.word	03760,17774,30006,60003,60000
	.word	60000,60000,60000,60000,63760
	.word	77774,70006,60003,60003,60003
	.word	60003,60003,30006,17774,03760
map7:	.word	77777,77777,00003,00006,00014
	.word	00030,00030,00060,00140,00140
	.word	00300,00600,01400,03000,06000
	.word	14000,30000,60000,60000,60000
map8:	.word	03760,17774,30006,60003,60003
	.word	60003,60003,60003,30006,17774
	.word	17774,30006,60003,60003,60003
	.word	60003,60003,30006,17774,03760
map9:	.word	03760,17774,30006,60003,60003
	.word	60003,60003,60003,30007,17777
	.word	03763,00003,00003,00003,00003
	.word	00003,60003,30006,17774,03760
;
mapsiz=map1-map0
	.end	start
