TITLE TRIVIA startup

.MLLIT==1

TTYCHN==1
SAVCHN==2
MUDCHN==3
DSKCHN==4

A=1
B=2
C=3
TIME=3
NOW=4
XUNAME=5
P=17
VBPTR:	440700,,A
VSBPTR:	140600,,B
DSKDEV:	SIXBIT	/DSK/
MSGDIR:	SIXBIT	/_MSGS_/
BADNAM:	SIXBIT	/BADBOY/
BADDIR:	SIXBIT	/VANISH/
SXUNAM:	BLOCK	2

START:	MOVE	P,[-30,,PDL-1]
	.OPEN	TTYCHN,[SIXBIT /  !TTY/]
	 .LOSE	1000
	.SUSET	[.RXUNAME,,XUNAME]
	LDB	A,[063600,,XUNAME]
	CAME	A,[SIXBIT / GUEST/]
	 CAMN	A,[SIXBIT / LUSER/]
	  JRST	LOSNAM
	CAMN	A,[SIXBIT / CHEAT/]
	 JRST	LOSNAM
	LDB	A,[063000,,A]
	CAMN	A,[SIXBIT /  TRIV/]
	 JRST	LOSNAM
	HLRZ	A,XUNAME
	CAIN	A,777777
	 JRST	LOGIN
	.CALL	DEATH
	 JRST	CKUSER
	.CALL	[SETZ				; GET FILE LENGTH IN A
		 SIXBIT /FILLEN/
		 MOVEI	DSKCHN
		 SETZM	A]
	 JRST	FAKMSG
	CAIN	A,
	 JRST	FAKMSG
	MOVE	B,BUFPTR
	.IOT	DSKCHN,B
	.CLOSE	DSKCHN,
	MOVE	B,[440700,,BUF]
MSGDTH:	PUSHJ	P,OUTMSG
MSGEND:	CAME	XUNAME,[SIXBIT /TAA/]
	 CAMN	XUNAME,[SIXBIT /MARC/]
	  JRST	WIN
	.BREAK	16,140000
FAKMSG:	MOVE	B,[440700,,MSG]
	JRST	MSGDTH

CKUSER:	.CALL	DIROPN				; REAL PERSON?
	 JRST	CKTIME				; NOPE
	.CALL	MSGOPN				; REALLY A REAL PERSON?
	 JRST	LOSNAM
	.CLOSE	DSKCHN,

WIN:	MOVE	B,[440700,,STMSG]
	PUSHJ	P,OUTMSG
	.CALL	SAVOPN
	 .VALUE	[ASCIZ /: No SAVE file?

/]
	.IOT	SAVCHN,[-1,,A]
	MOVSI	B,SIXBIT /   MUD/
	ILDB	C,VBPTR
	SUBI	C,40
	DPB	C,VSBPTR
	ILDB	C,VBPTR
	SUBI	C,40
	IDPB	C,VSBPTR
	.ACCES	SAVCHN,[0]

	.CALL	MUDOPN
	 .VALUE	[ASCIZ /: No TS MUDDLE ?

/]
	MOVSI 17,STUFF
	BLT 17,17
	JRST 1

LOSNAM:	MOVE	B,[440700,,NAMMSG]
	PUSHJ	P,OUTMSG
	MOVE	B,[440600,,XUNAME]
	MOVE	C,[440700,,SXUNAM]
SIXLOP:	ILDB	A,B
	JUMPE	A,SIXTOO
	ADDI	A,40
	IDPB	A,C
	JRST	SIXLOP
SIXTOO:	MOVE	B,[440700,,SXUNAM]
	PUSHJ	P,OUTMSG
	MOVE	B,[440700,,NAMEND]
	PUSHJ	P,OUTMSG
	.BREAK	16,160000

LOGIN:	MOVE	B,[440700,,LOGMSG]
	PUSHJ	P,OUTMSG
	.BREAK	16,160000

OFFHOR:	MOVE	B,[440700,,OFFMSG]
	PUSHJ	P,OUTMSG
	.BREAK	16,160000

CKTIME:	.RYEAR	A,
	 LDB	A,[320300,,A]			; IS IT A WEEKEND?
	JUMPE	A,CURFCK
	CAIN	A,6
	 JRST	CURFCK
	.RTIME	A,
	LDB	A,[301400,,A]			; IS IT OFFICE HOURS?
	CAIGE	A,'22
	 CAIGE	A,'09
	  JRST	CURFCK
	.RDATE	A,
	.CALL	HOLOPN				; IS IT A HOLIDAY?
	 JRST	FLUSH

CURFCK:	.CALL	CURFEW
	 JRST	WIN
	.CLOSE	DSKCHN,
	MOVE	B,[440700,,CURMSG]
	PUSHJ	P,OUTMSG
	.BREAK	16,160000

FLUSH:	.CALL	BADBOY
	 JRST	NEWBAD
	.CALL	RFDATE
	 JFCL
	.CALL	RQDATE
	 JFCL	
	.CALL	SFDATE
	 JFCL
	.CLOSE	DSKCHN,
	HLRZ	A,TIME				; DID THE TURKEY TRY <1/2 HR AGO?
	HLRZ	B,NOW
	CAME	A,B
	 JRST	OFFHOR
	SUB	NOW,TIME
	CAIGE	NOW,2400.
	 JRST	LOGOUT
	JRST	OFFHOR

NEWBAD:	.CALL	MAKBAD
	 .LOSE	1000
	.CLOSE	DSKCHN,
	JRST	OFFHOR

LOGOUT:	.VALUE	[ASCIZ /:You don't believe me, eh?  That makes me MAD!!!
:LOGOUT
/]
	.BREAK	16,160000

OUTMSG:	PUSH	P,A			; GIVEN BYTE POINTER, PRINT FROB OUT
	PUSH	P,C
	PUSH	P,B
	MOVEI	C,
OUTLOP:	ILDB	A,B			; LIKES BYTE POINTER TO FROB IN B
	CAIE	A,0
	 CAIN	A,3
	  JRST	OUTEND
	AOJA	C,OUTLOP
OUTEND:	POP	P,B			; GET BYTE POINTER IN B, COUNT IS IN C
	.CALL	[SETZ
		 SIXBIT	/SIOT/
		 MOVEI	TTYCHN
		 B
		 SETZ	C]
	 .LOSE	1000
	POP	P,C
	POP	P,A
	POPJ	P,

DEATH:	SETZ
	SIXBIT /OPEN/
	MOVSI	.BII
	MOVEI	DSKCHN
	DSKDEV
	[SIXBIT /TRIVIA/]
	[SIXBIT /DEATH/]
	SETZ	MSGDIR

DIROPN:	SETZ
	SIXBIT /OPEN/
	MOVSI	.BII
	MOVEI	DSKCHN
	DSKDEV
	[SIXBIT /.FILE./]
	[SIXBIT /(DIR)/]
	SETZ	XUNAME

MSGOPN:	SETZ
	SIXBIT /OPEN/
	MOVSI	.BII
	MOVEI	DSKCHN
	DSKDEV
	MSGDIR
	XUNAME
	SETZ	XUNAME

MUDOPN:	SETZ
	SIXBIT /OPEN/
	MOVSI	4
	MOVEI	MUDCHN
	DSKDEV
	[SIXBIT /TS/]
	B
	SETZ [SIXBIT /SYS1/]

SAVOPN:	SETZ
	SIXBIT /OPEN/
	MOVSI	6
	MOVEI	SAVCHN
	DSKDEV
	[SIXBIT /TRV/]
	[SIXBIT /SAVFIL/]
	SETZ [SIXBIT /MADMAN/]

HOLOPN:	SETZ
	SIXBIT /OPEN/
	MOVSI	.BII
	MOVEI	DSKCHN
	DSKDEV
	[SIXBIT /HLIDAY/]
	A
	SETZ [SIXBIT /COMBAT/]

CURFEW:	SETZ
	SIXBIT /OPEN/
	MOVSI	.BII
	MOVEI	DSKCHN
	DSKDEV
	[SIXBIT /TRIVIA/]
	[SIXBIT /CURFEW/]
	SETZ MSGDIR

BADBOY:	SETZ
	SIXBIT /OPEN/
	MOVSI	.BII
	MOVEI	DSKCHN
	DSKDEV
	BADNAM
	XUNAME
	SETZ	BADDIR

RFDATE:	SETZ
	SIXBIT /RFDATE/
	MOVEI	DSKCHN
	SETZM	TIME

RQDATE:	SETZ
	SIXBIT /RQDATE/
	SETZM	NOW

SFDATE:	SETZ
	SIXBIT /SFDATE/
	MOVEI	DSKCHN
	SETZ	NOW

MAKBAD:	SETZ
	SIXBIT /OPEN/
	MOVSI	1
	MOVEI	DSKCHN
	DSKDEV
	BADNAM
	XUNAME
	SETZ	BADDIR

STUFF:	OFFSET -.
	2
	.CALL LOAD
	.VALUE
	.IOT MUDCHN,A
	.CLOSE MUDCHN,
	ADDI	A,1
	JRST @A

LOAD:	SETZ
	SIXBIT /LOAD/
	1000,,-1
	SETZI MUDCHN

	OFFSET 0

MSG:	ASCIZ	/
TRIVIA is down for repairs.  Sigh.
/
OFFMSG:	ASCIZ	/
TRIVIA is not available during office hours (9 AM to 10 PM, Eastern time.)
/
NAMMSG:	ASCIZ	/
Losers with the name /
NAMEND:	ASCIZ	/ cannot play TRIVIA!
/
LOGMSG:	ASCIZ	/
Losers who are not logged in cannot play TRIVIA!
/
CURMSG:	ASCIZ	/
The system is VERY loaded.  Please try again later.
/
STMSG:	ASCIZ	/
Documentation in MADMAN;TVDOC >.
Describe bugs with TS TVBUG.
If TRIVIA absolutely refuses to work, bring it down with TS TVBUG.
/
BUF:	BLOCK	200
BUFPTR:	BUF-.,,BUF

PDL:	BLOCK 30

END	START
