
		.TITLE ALARM
	.COMM TASK,5*400+4
	.ENT	START
	.EXTN	.TASK,.KILL,.XMTW,.REC,.XMT
	.NREL
	.TXTM	1
START:	SUB	0,0
	STA	0,@.TTYCT		;ZERO TTY MESAGE COUNT
	STA	0,@.LPTCT		;ZERO LPT MESSAGE COUNT
	STA	0,NSWIT		;SET NORMAT TO ZERO
	STA	0,@.LMSGN		;ZERO CURRENT MSG NUMBER LPT
	STA	0,@.TMSGN		;ZERO CURRENT MSG # FOR TTY
	LDA	0,NUM5		;LOAD PRIORITY TASK1
	LDA	1,.DELY1		;LOAD ADDRESS OF SCAN
	.TASK
	JSR	@.ERR		;CREATE SCANNING TASK
	LDA	0,NUM6
	LDA	1,.TYMSG		;CREATE ERROR MSG TASK
	.TASK			;CREATE TASK
	JSR	@.ERR
	LDA	0,NUM7
	LDA	1,.PTMSG	;CREATE PRINTER TASK
	JMP .+2   
	JSR	@.ERR
	LDA	0,NUM10
	LDA	1,.STAKM	;START STACKING PGM
	.TASK			;CREATE TASK
	JSR	@.ERR
	.KILL			;ALL DONE STOP
NSWIT:	0		;NORMAL VALUE OF SWITCHES
MSG1:	0
NUM5:	5
NUM6:	6
NUM7:	7
NUM10:	10
.DELY1:	DELY1
.TYMSG:	TYMSG
.STAKM:	STAKM
.PTMSG:	PTMSG
.STK:	STK
.LMSGN:	LMSGN
.TMSGN:	TMSGN
.TTYCT:	TTYCT
.LPTCT:	LPTCT
SCAN:	LDA	0,.STK
	STA	0,CSP		;RESET CURRENT STACK POINTER (CSP)
	READS	0		;READ DATA SWITCHES
	LDA	1,NSWIT		;LOAD LAST STATE
	SUB#	0,1,SZR		;CHECK FOR CHANGE OF POINT
	JMP	SWCHG
DELY1:	LDA	1,NUM10		;NO CHANGE
	.SYSTM
	.DELAY
	JSR	@.ERR
	JMP	SCAN		;CONTINUE SCAN
SWCHG:	STA	0,TEMP1
	STA	0,NSWIT		;SAVE NEW STATE
	MOV	1,3		;MOVE AC1 TO AC3
	ANDZL	0,3		;2(AC0 AND AC3
	ADD	0,1
	SUB	3,1		;XOR
	LDA	2,.TABLE	;LOAD ADDRESS OF TABLE
CONT1:	LDA	0,0,2		;LOAD TABLE ENTRY
	AND#	0,1,SZR		;HAS THIS BIT CHANGED
	JSR	STSK		;YES
	INC	2,2		;NO
	LDA	3,TBLEN		;LOAD END OF TABLE
	SUB#	3,2,SZR		;END OF TABLE?
	JMP	CONT1		;NO GO ON
	LDA	0,.MSG1		;YES
	LDA	1,CSP		;LOAD CURRENT STACK POINTER
	.XMTW		;WAKE UPSTACK PGM
	JSR	@.ERR
	LDA	0,.MSG2
	.REC
	JMP	DELY1
STSK:	STA	0,@CSP		;SET BIT CHANGE ON STACK
	ISZ	CSP
	JMP	0,3		;CONTINUE SEARCH
TEMP1:	0
.TABLE:	TABLE
.MSG1:	MSG1
.MSG2:	MSG2
TABLE:
** I = 0
	.DO	16.		;CREATE TABLE
	1BI
**	I=I+1
**	.ENDC
TBLEN:	.
CSP:	0
STK:	.BLK	16.
.ERR:	ERR
; ********************************************************************
; 	TASK TO STACK MESSAGES
; 	  FOR TTY AND LPT
; *********************************************************************
STAKM:	LDA	0,.MSG1	; LOAD MESSAGE ADDRESS
	.REC			; WAIT FOR DATA
	STA	1,ECSP		; CURRENT END OF STACK
	LDA	2,.STK		; START AT TOP OF STACK
	STA	2,CRVAL
CONT3:	LDA	2,CRVAL		; LOAD FIRST VALUE
	LDA	3,ECSP
	SUB#	3,2,SNR		; CHECK FOR END OF CS
	JMP	STOVR		;  END START OVER
	LDA	0,0,2		; LOAD VALUE OF STACK
	SUB	1,1
	MOVZL	0,0,SZC		; KEEP SHIFTING
	JMP	.+3		; FOUND BIT
	INC	1,1		; CHECK BIT POSITION
	JMP	.-3
	LDA	3,.1B2		; SET ACTIVE BIT
	ADD	3,1
	LDA	0,0,2		; RELOAD BIT PMSITION
	LDA	3,TEMP1		; RELOAD ORIGINAL CHANGE
	AND	3,0,SZR		; CHENK FOR ALARM OF RTN
	LDA	0,.1B0		; SET BIT INDICATES ALARM
	ADD	0,1		;AND INTO STATUS
	JSR	STTY		;LOAD TTY STACK
	JMP .+1		; LOAD LPT STACK
	ISZ	CRVAL		; INC CURRENT VALUE OF STACK
	JMP	CONT3
STOVR:	LDA	0,.MSG2
	ADC	1,1
	.XMT
	JSR	@.ERR
	JMP	STAKM
STTY:	STA	3,RTN		; SAVE RETURN
	LDA	2,.TTY1S	; LOAD START OF TTY STACK
CONT4:	LDA	0,0,2		;LOAD STACKED VALUE
	MOV	0,0,SNR		;IS THIS VALUE FREE
	JMP	PUTV
	INC	2,2		;NO
	LDA	3,ENTTY
	SUB#	3,2,SNR		;END OF STACK 
	JMP	STTY+1		;START OVR
	JMP	CONT4
PUTV:	STA	1,0,2		;LOAD STACK
	ISZ	TTYCT		;INCREMENT STACK COUNT
	LDA	0,.MSGTY
	.XMT
	JMP	.+1		;IGNORE IF REC NOT DONE
	JMP	@RTN
STLPS:	STA	3,RTN1
	LDA	2,.LPTST	;LOAD START OF LPT STACK
CONT5:	LDA	0,0,2		;LOAD STACKED VALUE
	MOV	0,0,SNR		;IS THIS VALUE FREE
	JMP	PUTLV		;YES STACK IT
	INC	2,2		;NO
	LDA	3,ENLPT
	SUB#	3,2,SNR		;END OF STACK
	JMP	STLPS+1		;START OVER
	JMP	CONT5
PUTLV:	STA	1,0,2		;LOAD STACK
	ISZ	@..LPTCT		;INCREMENT LPT STACK COUNT
	LDA	0,.MGLPT
	.XMT
	JMP	.+1		;IGNORE OF REC NOT DONE
	JMP	@RTN1
RTN1:	0
MGLPT:	0
RTN:	0
MSGTY:	0
CRVAL:	0
TTY1S:	.BLK	16.
ENTTY:	.
LPTST:	.BLK	16.
ENLPT:	.
ECSP:	0
TTYSP:	0
LPTSP:	0
MSG2:	0
.LPTST:	LPTST
.1B2:	1B2
.1B0:	1B0
..LPTCT:	LPTCT
.MSGTY:	MSGTY
.TTY1S:	TTY1S
;*********************************************************************
;	TYPE MESSAGE TASK
;***********************************************************************
TYMSG:	LDA	0,FIL1		;LOAD BYTE POINTER
	SUB	1,1
	.SYSTM
	.OPEN	0
	JSR	@.ERR
	LDA	0,TTYO
	SUB	1,1
	.SYSTM
	.OPEN	1		;OPEN TTY OUTPUT
	JSR	@.ERR
	
	LDA	3,ENTTY		;LOAD END OF TTY STK
	SUB	0,0
	LDA	2,.TTY1S	;LOAD START OF TTY STK
	STA	0,0,2		;ZERO STACK
	INC	2,2
	SUB#	3,2,SZR		;IS THIS END OF STACK?
	JMP	.-3		;NO GO ON
T1MSG:	LDA	0,.MSGTY
	.REC			;WAIT FOR DATA
	LDA	2,.TTY1S		;LOAD ADDRESS OF STACK
NXTMG:	LDA	0,0,2		;LOAD MESSAGE
	MOV	0,0,SZR		;IS THERE A MESSAGE HERE
	JSR	FOMSG		;YES
	LDA	0,TTYCT		;LOAD COUNT
	MOV	0,0,SNR		;IS COUNT EMPTY
	JMP	T1MSG		;YES GO TO SLEEP
	INC	2,2
	LDA	1,ENTTY		;LOAD END OF TTY BLK
	SUB#	1,2,SZR
	JMP	NXTMG		;GET NEXT MESSAGE
	JMP	NXTMG-1		;START AT TOP OF STACK
SAC2:	0
TRTN:	0
FIL1:	.+1*2
	.TXT	'MSGTXT'
TTYO:	.+1*2
	.TXT	'$TTO'
.MGLPT:	MGLPT
TTYCT:	0
FOMSG:	STA	3,TRTN
	DSZ	TTYCT		;DECREMENT MSG COUNTER
	JMP	.+1
	
	ISZ	TMSGN		;INCREMENT MSG NUMBER
	JMP	.+1
	STA	2,SAC2
	LDA	1,MSK17		;LOAD MASK
	ANDZR	0,1		;LEAVE RECORD #
	LDA	0,.MSGA
	.SYSTM			;READ RANDOM CORRECT RECORD #
	.RDR	0
	JSR	@.AERR
	LDA	2,.CSTK		;LOAD STACK ADDRESS
	LDA	0,TMSGN		;LOAD MESSAGE NUMBER
	JSR	@ZBIDS		;DO BINARY TO ASCII CONVERSION
	STA	0,TMSG		;STORE IT
	JSR	TYPE		;TYPE IT
	TMSG
	LDA	0,@SAC2		;LOAD MESSAGE AGAIN
	MOVZL	0,0,SZC		;CHECK FOR RETURN TO NORMAL
	JMP	.+4		;ALARM
	JSR	TYPE		;YES RETURN TO NORMAL
	MSRTN
	JMP	.+3		;SKP OVER ALARM MESSAGE
	JSR	TYPE
	MSALM
	LDA	0,@SAC2		;LOAD ERROR MSG AGAIN
	SUB	1,1
	STA	1,@SAC2		;ZERO LOC ON STACK
	MOVZR	0,0,SZC		;WHICH HALF OF RECORD
	JMP	.+4
	JSR	TYPE		;TYPE FIRST HALF OF RECORD
	MSGA
	JMP	.+3
	JSR	TYPE		;YTPE SECOND HALF
	MSGB
	.SYSTM			;GET TIME OF DAY
	.GTOD
	JMP	.+1
	STA	0,SECS		;STORE SECONDS
	STA	1,MINUT
	STA	2,HOUR
	LDA	2,.CSTK		;LOAD ADDRESS OF STACK FOR CONV
	JSR	@ZCONV		;CONVERT TIME TO ASCII
	JSR	TYPE		;TYPE TIME OF DAY
	HOUR
	JSR	TYPE
	MINUT
	JSR	TYPE
	SECS
	JSR	TYPE		;TYPE CARRIAGE RETURN
	CRLF
	LDA	2,SAC2
	JMP	@TRTN		;RETURN
TYPE:	STA	3,T1RTN		;SAVE RETURN
	ISZ	T1RTN
	LDA	0,0,3		;LOAD MESSAGE POINTER
	MOVZL	0,0		;FORM BYTE POINTER
	.SYSTM		;WRITE A LINE TO TTY
	.WRL	1
	JSR	@.AERR
	JMP	@T1RTN
LPTCT:	0
T1RTN:	0
MSRTN:	.TXT	'<7>RETURN '
MSALM:	.TXT	'<7>ALARM  '
CRLF:	.TXT	'<15>'
CHAR = 0
HORDC = 1
QRTN =	2
DHOUR =	3
DMINUT = 5
DSECS = 7
CRTN = 11
TMSG:	0
	'  '
	0
ZBIDS:	BIDS
.CSTK:	CSTK
.MSGA:	MSGA
TMSGN:	0
;********************************************************************
;	PRINT TO LINE PRINTER TASK
;**********************************************************************
PTMSG:	LDA	0,FIL1	;LOAD BYTE POINTER
	SUB	1,1
	.SYSTM			;OPEN INPUT MSGTXT FILE
	.OPEN	2
	JSR	@.AERR
	LDA	0,LPTO		;BYTE POINTER TO LPT
	SUB	1,1
	.SYSTM			;OPEN LINE PRINTER
	.OPEN	3
	JSR	@.AERR
	LDA	3,@ZENLPT		;LOAD END OF LINE PRINTER BUFFER
	SUB	0,0
	LDA	2,ALPTST	;LOAD START OF LPT STACK
	STA	0,0,2		;ZERO STACK
	INC	2,2
	SUB#	3,2,SZR		;IS THIS END OF STACK
	JMP	.-3		; NO GO ON
L1MSG:	LDA	0,.MGLPT	;LOAD MESSAGE AREA
	.REC			;WAIT FOR DATA
	LDA	2,ALPTST	;LOAD ADDRESS OF STACK
NXTLP:	LDA	0,0,2		;LOAD MESSAGE
	MOV	0,0,SZR		;IS THERE A MESSAGE THERE
	JSR	LFMSG		;YES
	LDA	0,LPTCT		;LOAD MSG COUNT
	MOV	0,0,SNR		;IS COUNT EMPTY
	JMP	L1MSG		;UES GO TO SLEEP
	INC	2,2
	LDA	1,@ZENLPT		;LOAD END OF LPT BLK
	SUB#	1,2,SZR	;END OF BLK?
	JMP	NXTLP		;NO GET NEXT MESSAGE
	JMP	NXTLP-1		;START AT TOP OF STACK
CSTK:	0
	0
	0
HOUR:	0
	035000
MINUT:	0
	035000
SECS:	0
	020000
	0		;SAVE RETURN FOR CONV PGM
ZENLPT:	ENLPT
ALPTST:	LPTST
MSK17:	17
ZCONV:	CONV
.AERR:	ERR
LFMSG:	STA	3,LRTN
	DSZ	LPTCT		;DECREMENT MSG COUNTER
	JMP	.+1
	ISZ	LMSGN		;INCREMENT MESSAGE NUMBER
	JMP	.+1
	STA	2,S1AC2
	LDA	1,MSK17		;LOAD MASK
	ANDZR	0,1		;LEAVE RECOURD NUMBER
	LDA	0,ALMSGA		;READ MSGTXT
	.SYSTM
	.RDR	2		;READ RANDOM MSGTXT
	JSR	@.AERR
	LDA	2,.LSTK	;LOAD ADDRESS OF STACK
	LDA	0,LMSGN		;LOAD MESSAGE NUMBER
	JSR	@ZBIDS		;DO CONVERSION
	STA	0,LMSG		;STORE CONVERTED NUMBER
	JSR	PRINT
	LMSG			;TYPE MESSAGE NUMBER
	LDA	0,@S1AC2		;LOAD MESSAGE AGAIN
	MOVZL	0,0,SZC		;CHECK FOR RETURN TO NORMAL
	JMP	.+4
	JSR	PRINT		;UES RETURN TO NORMAL
	MSRTN
	JMP	.+3
	JSR	PRINT		;PRINT ALARM MESSAGE
	MSALM
	LDA	@0,S1AC2		;LOAD ERROR AGAIN
	SUB	1,1
	STA	1,@S1AC2	;ZERO STACK LOCATION
	MOVZR	0,0,SZC		;WHICH HALF OF RECORD
	JMP	.+4
	JSR	PRINT 		;PRINT TEXT FIRST HALF
	LMSGA
	JMP	.+3
	JSR	PRINT		;PRINT LEFT HALF OF RECORD
	LMSGB
	.SYSTM
	.GTOD
	JMP	.+1
	STA	0,LSECS
	STA	1,LMINUT
	STA	2,LHOUR
	LDA	2,.LSTK		;LOAD STACK ADDRESS FOR CONV
	JSR	@ZCONV		;CONVERT TIME TO ASCII
	JSR	PRINT		;PRINT TIME
	LHOUR
	JSR	PRINT
	LMINUT
	JSR	PRINT
	LSECS
	JSR	PRINT		;PRINT CARRIAGE RETURN
	CRLF
	LDA	2,S1AC2
	JMP	@LRTN
LSTK:	0
	0
	0
LHOUR:	0
	035000
LMINUT:	0
	035000
LSECS:	0
	020000
	0
LMSG:	0
	'  '
	0
PRINT:	STA	3,PTRTN
	ISZ	PTRTN
	LDA	0,0,3		;LOAD MESSAGE POINTER
	MOVZL	0,0
	.SYSTM
	.WRL	3
	JSR	@.AERR
	JMP	@PTRTN
PTRTN:	0
LPTO:	.+1*2
	.TXT	'$LPT'
LMSGN:	0
ALMSGA:	LMSGA
.LSTK:	LSTK
S1AC2:	0
LRTN:	0
CONV:	STA	3,CRTN,2	;STORE RETURN IN STACK
	LDA	0,DHOUR,2	;LOAD HOUR FOR CONVERSION
	JSR	BIDS		;DO CONVERSION
	STA	0,DHOUR,2	;RESTORE VALUE
	LDA	0,DMINUT,2	;LOAD MINUTES TO BE CONVERTED
	JSR	BIDS		;DO CONVERSION
	STA	0,DMINUT,2	;STORE CONVERTED VALUE
	LDA	0,DSECS,2	;LOAD SECONDS TO BE CONVERTED
	JSR	BIDS		;DO CONVERSION
	STA	0,DSECS,2	;STORE CONVERTED VALUE ON STACK
	JMP	@CRTN,2		;RETURN TO CALLER
	;	BIDS IS A BINARY TO  ASCII CONVERSION
	;	ROUTINE.  CAUTION THIS ROUTINE ASSUMES THAT
	;	THE BINARY NUMBER IS NO GREATER THAN 99 DECIMAL
	;	AS IS THE CASE FOR TIME OF DAY.
BIDS:	STA	3,QRTN,2	;SAVE RETURN FOR BINARY CONVERSION
	STA	0,CHAR,2	;SAVE BINARY INPUT
	SUB	1,1
	STA	1,HORDC,2	;ZERO HIGH ORDER STORAGE
	LDA	1,MSK17		;LOAD FOUR BIT MASK
	AND	1,0		;LEAVE FIRST CHARACTER
	LDA	3,CHAR,2	;RELOAD CHARACTER
	MOVZR	3,3
	MOVZR	3,3
	MOVZR	3,3
	MOVZR	3,3
	MOVZR	3,3,SNC		;CHECK FOR 2^4 BIT TO BE SET
	JMP	.+4		;NOT SET GO ON
	LDA	1,ANUM6		;IT IS SET ADD LSD DIGIT
	ADD	1,0		;TO CURRENT LDS
	ISZ	HORDC,2		;INCREMENT HIGH ORDER BIT
	MOVZR	3,3,SNC		;CHECK FOR 2^5 BIT
	JMP	.+6		;NOT SET GO ON
	LDA	1,NUM2		;LOAD LSD TO BE ADDED
	ADD	1,0		;TO LSD
	ISZ	HORDC,2		;INCREMENT HOB THREE TIMES
	ISZ	HORDC,2
	ISZ	HORDC,2
	LDA	1,MAXN		;LOAD DECIMAL 10
	SUBZ#	1,0,SNC		;IS 10. >= TO NUMBER
	JMP	.+4		;NO NUMBER NOT > THAN 10.
	SUB	1,0		;YES MUST SUB 10.
	ISZ	HORDC,2		;INCREMENT HIGH ORDER BIT
	JMP	.-4		;CHECK IF STILL OVER 10
	LDA	1,CONTN		;LOAD CONTROL BITS
	ADD	1,0		;ADD CONTROL BITS TO MAKE ASCII
	LDA	3,HORDC,2	;LOAD HIGH ORDER BITS
	ADDS	3,1		;ADD HIGH ORDER OVERFLOW ANS SWAP
	ADD	1,0		;ADD TO LOW ORDER CHARACTER
	JMP	@QRTN,2		;RETURN
MAXN:	10.
CONTN:	60
NUM2:	2
ANUM6:	6
ERR:	.SYSTM
	.ERTN
	JMP	.	;WHAT AM I DOING HERE ???
LMSGA:	.BLK	32.
LMSGB:	.BLK	32.
MSGA:	.BLK	32.
MSGB:	.BLK	32.
	.END	START
