TITLE TRIVIA startup

.MLLIT==1

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

O=0
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	/ABADBO/
BADDIR:	SIXBIT	/VANISH/
SXUNAM:	BLOCK	2

START:	MOVE	P,[-30,,PDL-1]
	.OPEN	TTYCHN,[SIXBIT /  !TTY/]
	 .LOSE	1000
	.SUSET	[.RXUNAME,,XUNAME]
	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:	PUSHJ	P,WINNER
	 JRST	WIN
	.BREAK	16,140000
FAKMSG:	MOVE	B,[440700,,MSG]
	.CLOSE	DSKCHN,
	JRST	MSGDTH

CKUSER:	PUSHJ	P,WINNER
	 JRST	WIN
	LDB	A,[063600,,XUNAME]
	CAMN	A,[SIXBIT / GUEST/]
	 JRST	CKTIME
	.CALL	DIROPN				; REAL PERSON?
	 JRST	CKTIME				; NOPE
	.CALL	MSGOPN				; REALLY A REAL PERSON?
	 JRST	LOSNAM
	.CLOSE	DSKCHN,
CKNUM:	PUSHJ	P,ZKCNT
	 JRST	TOOMNY

WIN:	.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
TOOMNY:	MOVE	B,[440700,,TOOMSG]
	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,'20
	 CAIGE	A,'09
	  JRST	CURFCK
	.RDATE	A,
	.CALL	HOLOPN				; IS IT A HOLIDAY?
	 JRST	FLUSH

CURFCK:	.CALL	CURFEW
	 JRST	CKNUM
	.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!!!
0U
/]
	.BREAK	16,160000

ZKCNT:	MOVEI	B,40
	MOVEI	O,3
ZKLOP:	SOJL	B,[AOS	(P)
		   POPJ	P,]
	SKIPN	@MSUSER
	 JRST	ZKLOP
	MOVE	A,@MSRED2
	CAME	A,[SIXBIT /ZORK/]
	 JRST	ZKLOP
	SOJG	O,ZKLOP
	POPJ	P,

	SQUOZE	0,MSUSER
MSUSER:	0
	SQUOZE	0,MSRED2
MSRED2:	0
INIT:	MOVE	B,[-200,,200]
	MOVEI	A,0
	.CALL	[SETZ
		 SIXBIT	/CORBLK/
		 MOVEI	%CBRED
		 MOVEI	%JSELF
		 B
		 MOVEI	%JSABS
		 SETZ	A]
	 .LOSE	1000
	MOVE	A,MSUSER-1
	.EVAL	A,
	 .LOSE	1000
	ADD	A,[B,,400000]
	MOVEM	A,MSUSER
	MOVE	A,MSRED2-1
	.EVAL	A,
	 .LOSE	1000
	ADD	A,[B,,400000]
	MOVEM	A,MSRED2
	.VALUE	[ASCIZ	/K
:PDUMP SYS2;TS ZORK
:KILL
/]

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,

WINNER:	CAME	XUNAME,[SIXBIT	/TAA/]
	 CAMN	XUNAME,[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ETZ
	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	/
ZORK is down for repairs.  Sigh.
/
OFFMSG:	ASCIZ	/
ZORK is not available during office hours (9 AM to 8 PM, Eastern time.)
/
TOOMSG:	ASCIZ	/
There appears before you a threatening figure clad all over
in heavy black armor.  His legs seem like the massive trunk
of the oak tree.  His broad shoulders and helmeted head loom
high over your own puny frame and you realize that his powerful
arms could easily crush the very life from your body.  There
hangs from his belt a veritable arsenal of deadly weapons:
sword, mace, ball and chain, dagger, lance, and trident.
He speaks with a commanding voice:

		"YOU SHALL NOT PASS "

As he grabs you by the neck all grows dim about you./
NAMMSG:	ASCIZ	/
Losers with the name /
NAMEND:	ASCIZ	/ cannot play ZORK!
/
LOGMSG:	ASCIZ	/
Losers who are not logged in cannot play ZORK!
/
CURMSG:	ASCIZ	/
The system is VERY loaded.  Please try again later.
/
BUF:	BLOCK	200
BUFPTR:	BUF-.,,BUF

PDL:	BLOCK 30

END	START
