TITLE LIMERICK PROGRAM

VERSIO==.FNAM2


TYOC==2		; TTY OUTPUT CHANNEL

.INSRT SYSENG;$CALL MACRO
.INSRT EAK;MACROS >


LIMERICK:
	MOVE P,[-LPDL,,PDL-1]
	.OPEN TYOC,[.UAO,,'TTY]
	 .LOSE 1000
	.SUSET [.ROPTION,,A]	; CHECK IF THERE IS A COMMAND LINE TO READ
	TLNN A,OPTCMD
	 JRST RND
	SETZM CMD		; ZERO THE COMMAND BUFFER
	MOVE A,[CMD,CMD+1]
	BLT A,CMD+LCMD-1
	SETOM CMD+LCMD		; -1 (NONZERO) WILL STOP WRITING INTO BUFFER
	.BREAK 12,[5,,CMD]	; SUPERIOR WILL DEPOSIT INTO BUFFER

	MOVE D,[440700,,CMD]
SPACE:	ILDB A,D		; IGNORE LEADING SPACES
	CAIN A,40
	 JRST SPACE
	CAIN A,"*
	 JRST ALL

NUMBER:	MOVEI B,0
	CAIA
NUM1:	ILDB A,D
	CAIL A,"0
	 CAILE A,"9
	  JRST NUM2		; NO. IS TERMINATED BY NON DIGIT
	IMULI B,10.
	ADDI B,-"0(A)
	JRST NUM1
NUM2:	SOUT #TYOC,#%TJDIS,"C"
	MOVE A,B
	SUBI A,1
	PUSHJ P,PRINT
	JRST QUIT

RND:	SOUT #TYOC,#%TJDIS,"C"
	.RDTIME A,
	PUSHJ P,PRINT
	JRST QUIT

ALL:	MOVNI B,NLIMS
AL1:	SOUT #TYOC,,"
"
	MOVEI A,NLIMS(B)
	PUSHJ P,PRINT
	AOJL B,AL1
	JRST QUIT

PRINT:	PUSH P,B
	PUSH P,C
	MOVM B,A
	IDIVI B,NLIMS		; TAKE NO. MOD THE NO. OF LIMS WE HAVE
	MOVE A,LIMTBL(C)
	HLRZ B,A
	HRLI A,440700
	$CALL SIOT,[#TYOC,A,B]
	 .LOSE 1000
	POP P,C
	POP P,B
	POPJ P,

QUIT:	.SUSET [.RXJNAME,,A]
	CAMN A,[SIXBIT/./]
	 JRST DEATH
	$CALL FINISH,#TYOC	; WAIT FOR OUTPUT TO REACH TTY
	 .LOSE 1000
	MOVEI B,50.
	CAMN A,[SIXBIT/SOLONG/]
	 .SLEEP B,
DEATH:	.CLOSE TYOC,
	.LOGOUT
	.BREAK 16,160000
	.VALUE

LCMD==<80./5>+1
CMD:	BLOCK LCMD+1


DEFINE L N,TEXT
	%.TMP1==.
	ASCII TEXT
	%.TMP2==.
	LOC LIMTBL+NLIMS
	REPEAT N,[
	.LENGTH TEXT,,%.TMP1
]
	LOC %.TMP2
	NLIMS==NLIMS+N
TERMIN

NLIMS==0

LPDL==20
PDL:	BLOCK LPDL

LITRAL:	CONSTANTS
	VARIABLES

LIMTBL:	BLOCK 1700.

.INSRT LIMS >


END LIMERI
