
ROMPAGE: EQU	017
RAMPAGE: EQU	016
JMPADDR: EQU	333
RSAVADR: EQU	336
CURADR:	 EQU	337
BUFADDR: EQU	340

KEYIN:  EQU 	004
KEYOUT: EQU     014

OUTWR:   EQU 	010	; S3 (WR = 0)
OUTLOAD: EQU 	011	; S2 (LOAD = 1)
OUTOSC:	 EQU    012	; S1 (OSC = 0)
OUTCHAR: EQU 	013

CURPTR:	ORG	RAMPAGE#CURADR
BUFFER:	ORG	RAMPAGE#BUFADDR


		ORG	002#000
START:		CAL	017#260
		LHI	\HB\COUNT
		LLI	\LB\COUNT
		LMI	001
		LLI	\LB\POINTR
		LMI	000
		INL
		LMI	005
NEWONE:		LHI	\HB\NEWWRD
		LLI	\LB\NEWWRD
		CAL	MSG
		CAL	INPUT
		CPI	316
		JTZ	NOMORE
		CPI	331
		JFZ	NEWONE
		CAL	MOVTAB
		JMP	GUESS
NOMORE:		LHI	\HB\BYE
		LLI	\LB\BYE
		CAL	MSG
                CAL	INPUT
		JMP     017#000

GUESS:		LHI	\HB\LETTR
		LLI	\LB\LETTR
                CAL	MSG2
		CAL	INPUT
		LCA

SCAN:		LBI	000
		LHI	003
		LLI	360

CKMTCH:		CPM            ; compare input to word
		JFZ	NOMTCH ; no match, branch
		INB            ; match goes here
		LAI	010    ; add 8 to 
		ADL            ; L register
		LLA            ; 
		LMC 		;save guess to mem
		LAL		; subtract 8 from L
		SUI	010    ; 
		LLA		;

NOMTCH:		INL	    	; ptr to next letter
		LAM		;
		NDA
		JTZ	EOWORD  ; have we reached end of word?
		LAI	007	; no, have we tried all eight letter?
		NDL             ; 
        	JTZ	EOWORD  ; we have counted up to eight letters
		LAC		; restore guess'd letter
		JMP	CKMTCH  ; check next letter

EOWORD:		INB
		DCB
		JTZ	HANGIT  ; no match found, branch
		LHI	\HB\GOOD ; found letter here
		LLI	\LB\GOOD
		CAL	MSG
		LHI	003 
                LLI	353
		LMI	000
		LLI	370

NOTEND:		LAM
		CPI	255
		JFZ	AHEAD2
		LEL
		LLI	353
		LBM
		INB
		LMB
		LLE

AHEAD2:		LDL
                CAL	PRINT
                LLD
                LHI	003
		INL
		LAL
		SUI	010
		LLA
		LAM
		NDA
		JTZ	ENDAGN
		LAL
		NDI	007
		JTZ	ENDAGN
		LAI	010
		ADL
		LLA
		JMP	NOTEND

ENDAGN:		LLI	353
		LBM
		INB
		DCB
		JFZ	GUESS
		LHI	\HB\CNGRAT
		LLI	\LB\CNGRAT
		CAL	MSG2
                CAL	INPUT
		JMP	NEWONE

HANGIT:		LHI	\HB\NOPE
		LLI	\LB\NOPE
		CAL	MSG
		LHI	\HB\COUNT
		LLI	\LB\COUNT
		LBM
		INB
		LMB
		INL
		LMB
		LAI	010
		SUB
		INL
		LMA	
		LEI 	\LB\HNGMAN

HANGMR:		LHI	\HB\HNGMAN
                LLE
		LAM
                LDL
		CAL	PRINT
                LLD
                LHI	003
		INL
		LEL
		LLI	351
		LBM
		DCB
		LMB
		JFZ	HANGMR
		LLI	352
		LCM
		INC
		DCC
		JFZ	NOTDONE
                CAL	INPUT
		JMP	NEWONE
NOTDONE: LAI	255

MRDASH:		LDL
                CAL	PRINT
                LLD
                LHI	003
		LCM
		DCC
		LMC
		JFZ	MRDASH
		JMP	GUESS

MOVTAB:		LHI	\HB\COUNT
		LLI	\LB\COUNT
		LBM
		LLI	370
		LCI	010
		LAI	255

DASHFL:		LMA
		INL
		DCC
		JFZ	DASHFL

NXWORD:		LLI	\LB\TRACK2
		LCI	010
		XRA

ZEROFL:		LMA
		INL
		DCC
		JFZ	ZEROFL
		LLI	\LB\POINTR
		LAM
		INL
		LHM
		LLA
		XRA
		CPM
		JFZ	AHEAD3
		LHI	005
		LLI	000

AHEAD3:		LDI	\HB\TRACK2
		LEI	\LB\TRACK2

BUFFMR:		LAM
		NDA
		JTZ	NEXT
		CAL	SWITCH
		LMA
		INL
		CAL	SWITCH
		INL
		JFZ	NOHIGH
		INH

NOHIGH:		JMP	BUFFMR

NEXT:		INL
		JFZ	NOTHI
		INH

NOTHI:		CAL	SWITCH
		LLI	\LB\POINTR
		LME
		INL	
		LMD
		DCB
		JFZ	NXWORD
		LLI	\LB\COUNT
		LMI	000
		RET

SWITCH:		LCH
		LHD
		LDC
		LCL
		LLE
		LEC
		RET

MSG:            LDH
                LEL
	        CAL     017#260
                LLE
		LHD
MSG2:		LDH
                LAM
		NDA
		RTZ
                LEL
		CAL	PRINT
                LHD
                LLE
		INL
		JFZ	MSG2
		INH
		JMP	MSG2

		ORG	003#340
HNGMAN:		DATA	"HANGMAN!"
COUNT:		DATA	000,000,000,000
                ORG	003#356
POINTR:		DATA	000,000
TRACK2:		DATA	000,000,000,000,000,000,000,000
		DATA	255,255,255,255,255,255,255,255
		ORG	004#000
NEWWRD:		DATA	"NEW WORD? "
		DATA	000
BYE:		DATA	"GOODBYE"
		DATA	000
LETTR:		DATA    " GUESS: "
		DATA    000
NOPE:		DATA	"NOPE! "
		DATA     000
GOOD:		DATA	"GOOD: "
		DATA 	000
CNGRAT:		DATA 	" CONGRATULATIONS!"
		DATA 	000

;
; HERE IS THE USER DEFINED CHARACTER INPUT TO READ FROM SERIAL PORT
; destroys C & D
; returns character in A
INPUT:
GETCHAR:
  		INP	KEYIN	; read keyboard 
		NDA		; is a new character present
		JFS	GETCHAR	
		OUT	KEYOUT	; ack character read
;		NDI	177	; clear MSB
;
; HERE IS THE USER DEFINED PRINT ROUTINE FOR SCOPEWRITER OUTPUT
; input:A
; destroys C (= A), L(=CURPTR), H(=CURPTR)

PRINT:
   	LHI	\HB\CURPTR
	LLI	\LB\CURPTR
	LCM			; current output ptr
	LLC			; to "L"
	LMA			; save new character to memory
	LLI	\LB\CURPTR	; current ptr to ptr
	INC			; bump ptr
	JTZ	OTPT2		; check for wrap
	LMC			; save updated ptr, skip if wrap
OTPT2:
	LCA			; save character to "C"
; saved new char, now display line of output
	INL			; Point to beginning of buffer
	LAI	001		;
	OUT	OUTOSC		; turn off oscillator
	XRA
	OUT	OUTWR		; enable write mode	

DSPLY2: LAM			; fetch character
	OUT	OUTCHAR		; OUTPUT character
	LAI	001		; write
	OUT	OUTLOAD		; pulse load
	XRA			; clear accumulator
	OUT	OUTLOAD		; finish load pulse
	INL
	JFZ	DSPLY2		; next char or end

	LAI	001
	OUT	OUTWR		; turn off write mode
	XRA			;
	OUT	OUTOSC		; enable oscillator/display

	LAC			; restore A (newest char) from "C"
	RET




		ORG	005#000
		DATA "HELLO"
		DATA	000
		DATA	"ARROW"
		DATA	000
		DATA	"COMPUTER"
		DATA	000
		DATA	"PREMIUM"
		DATA	000
		DATA	"NOTICE"
		DATA	000
		DATA	"FUN"
		DATA	000
		DATA	"HEAVY"
		DATA	000
		DATA	"RUBBER"
		DATA	000
		DATA	"RUSTLE"
		DATA	000
		DATA	"THWART"
		DATA	000
		DATA	"OYSTER"
		DATA	000
		DATA	"OXIDIZE"
		DATA	000
		DATA	"OSSIFY"
		DATA	000
		DATA	"OPINION"
		DATA	000
		DATA	"OOZY"
		DATA	000
		DATA	"ONEROUS"
		DATA	000
		DATA	"NOMAD"
		DATA	000
		DATA	"NOCTURNE"
		DATA	000
		DATA	"NOMINATE"
		DATA	000
		DATA	"NUMSKULL"
		DATA	000
		DATA	"DAFFODIL"
		DATA	000
		DATA "SIDEREAL"
		DATA	000
		DATA	"CRICKET"
		DATA	000
		DATA	"COURIER"
		DATA	000
		DATA	"COSMOS"
		DATA	000
		DATA	"CHEMIST"
		DATA	000
		DATA	"CHEMICAL"
		DATA	000
		DATA	"CHICORY"
		DATA	000
		DATA	"CHLORINE"
		DATA	000
		DATA	"CITIZEN"
		DATA	000
		DATA	"CITRUS"
		DATA	000
		DATA	"CLOSET"
		DATA	000
		DATA	"COGENT"
		DATA	000
		DATA	"BIRD"
		DATA	000
		DATA	"BEETLE"
		DATA	000
		DATA	"BELIEVE"
		DATA	000
		DATA	"BATHTUB"
		DATA	000
		DATA	"BASKET"
		DATA	000
		DATA	"BANQUET"
		DATA	000
		DATA	"BABBITT"
                DATA	000
		DATA	"BACKBONE"
		DATA	000
		DATA	"AUDIBLE"
		DATA	000
		DATA	"ASPIRIN"
		DATA	000
		DATA	"ASTEROID"
                DATA	000
		DATA	"APPROVAL"
                DATA	000
		DATA	"APOGEE"
		DATA	000
		DATA	"ANNUITY
                DATA	000
		DATA	"ANODIZE"
		DATA	000
		DATA	"ALUMINUM"
		DATA	000
		DATA	"AIR"
		DATA	000
		DATA	"AISLE"
		DATA	000
		DATA	"ADJOIN"
		DATA	000
		DATA	"ABYSS"
		DATA	000
		DATA	"ABOLISH"
		DATA	000
		DATA	"QUEUE"
		DATA	000
		DATA	"QUIVER"
		DATA	000
	DATA	"QUALM"
		DATA	000
		DATA	"QUITE"
		DATA	000
		DATA	"QUIXOTIC"
		DATA	000
		DATA	"QUOIN"
		DATA	000
	DATA	"QUOIT"
		DATA	000
		DATA	"QUOTIENT"
		DATA	000
		DATA	"RADIO"
		DATA	000
		DATA	"RAISIN"
		DATA	000
		DATA	"RAPT"
		DATA	000
		DATA	"RATIO"
		DATA	000
		DATA	"RAUCOUS"
		DATA	000
		DATA	"RAYON"
		DATA	000
		DATA	"RAZOR"
		DATA	000
		DATA	"REALM"
		DATA	000
		DATA	"REEK"
		DATA	000"
		DATA	"REGISTER"
		DATA	000
		DATA	"RIVET"
		DATA	000
		DATA	"SCHOONER"
		DATA	000
		DATA	"SAUNA"
		DATA	000
		DATA	"SATIN"
		DATA	000
		DATA	"SCEPTER"
		DATA	000
		DATA	"SCIENCE"
		DATA	000
		DATA	"SCRIBBLE"
		DATA	000
		DATA	"BEHIND"
		DATA	000
		DATA	"DIGNIFY"
		DATA	000
		DATA	"ELLIPTIC"
		DATA	000
		DATA	"ELOQUENT"
		DATA	000
		DATA	"ELUSIVE"
		DATA	000
		DATA	"FEATHER"
		DATA	000
		DATA	"GALLOWS"
		DATA	000
		DATA	"GARDEN"
		DATA	000
		DATA	"GAZELLE"
		DATA	000
		DATA	"MACABRE"
		DATA	000
		DATA	"VALIANT"
		DATA	000	
		DATA	"VENISON"
		DATA	000
		DATA	"VIVID"
		DATA	000
		DATA	"WEIGHT"
		DATA	000
		DATA	"WEIRD"
		DATA	000
		DATA	"WISE"
		DATA	000
		DATA	"ZERO"
		DATA	000
		DATA	"ZOOLOGY"
		DATA	000
		DATA	"ZENITH"
		DATA	000
		DATA	"YAWN"
		DATA	000
		DATA	"YOLK"
		DATA	000
		DATA	"YELLOW"
		DATA	000
		DATA	"YULE"
		DATA	000
		DATA	"TRICKLE"
		DATA	000	
		DATA	"END"
		DATA	000
		DATA	000
