;
;
;  SHOOTING STARS -- A BRAIN TEASER GAME
;  AN INTERACTIVE GAME FOR 8080 COMPUTER
;  THIS VERSION IMPLEMENTED FOR Sol
;  DEVELOPED AND DEBUGGED WITH ALS-8
;  PROGRAM DEVELOPMENT SYSTEM
; 
;  PROGRAM ORIGINALLY SUBMITTED TO THE
;  HEWLETT-PACKARD SOFTWARE LIBRARY IN BASIC
;  SUBSEQUENTLY PUBLISHED BY PEOPLE'S COMPUTER
;  COMPANY IN SEPT 74 AS "TEASER"
;  WRITTEN IN 8008 CODE BY WILLARD I. NICO
;  IN BYTE MAY 76 AS "SHOOTING STARS"
;  ADAPTED TO 8080 CODE FOR USE WITH VDM-1
;  BY JERRY BACON
;  S.I.L. PROGRAMMING LABORATORY
;  BRASILIA, D.F. BRASIL
;
;  DATE:  14 JAN 77
;
;
	ORG	0000H
SHSDR	LXI	H,HEADR	;POINT TO HEADER MESSAGE
	CALL	SCRN	;DISPLAY IT
	CALL	KBD
	CPI	'N'	;CHECK IF RULES WANTED
	JZ	START	;IF NOT, START GAME
	LXI	H,PAGE1	;OTHERWISE POINT TO 1ST PAGE
	CALL	SCRN
	CALL	KBD
	LXI	H,PAGE2	;POINT TO 2ND PAGE
	CALL	SCRN
	CALL	KBD
START	LXI	D,VDM1
	CALL	CLER	;CLEAR THE SCREEN
	LXI	B,0001H	;INITIALIZE UNIVERSE
	MOV	D,B	;CLEAR SHOT COUNTER
CNTST	INR	D	;INCREMENT SHOT COUNTER
DISP	LXI	H,STR1	;DISPLAY UNIVERSE
	CALL	TYPE
	LXI	H,STR2
	CALL	TYPE
	LXI	H,STR3
	CALL	TYPE
	LXI	H,STR4
	CALL	TYPE
	LXI	H,STR6
	CALL	TYPE
	LXI	H,STR7
	CALL	TYPE
	LXI	H,STR8
	CALL	TYPE
	LXI	H,STR9
	CALL	TYPE
	XRA	A
	MOV	A,C
	RRC
	LXI	H,STR5
	CALL	TYPE1
WNTST	MOV	A,B	;GET UNIVERSE PATTERN
	CPI	0FFH	;CHECK FOR FRINGE STARS
	JNZ	LSTST	;IF NOT ALL PRESENT, CHECK FOR LOSS
	MOV	A,C
	ORA	A	;GET CENTER STAR
	JNZ	GTSTR	;CONTINUE IF PRESENT
	LXI	H,MESS4	;IF NOT, GAME IS WON. POINT TO WIN MESS
	CALL	SCRNB
;
;
;
;
;
;
	MVI	E,'0'	;INITIALIZE BINARY TO DECIMAL CONV.
	MOV	B,E
	MOV	C,E
	DCR	D	;GET RID OF LAST SHOT
	MVI	A,'9'+1	;SET OVERFLOW CHECK
MRDEC	INR	E	;INCREMENT 1'S
	CMP	E	;CHECK FOR OVERFLOW
	JNZ	TALLY	;CONTINUE IF NOT
	MVI	E,'0'	;OTHERWISE, RESET 1'S
	INR	C	;INCREMENT 10'S
	CMP	C
	JNZ	TALLY
	MVI	C,'0'
	INR	B	;INCREMENT 100'S
TALLY	DCR	D	;DECREMENT SHOT COUNTER
	JNZ	MRDEC
	MVI	A,'0'
	CMP	B	;CHECK FOR LEADING 0
	JNZ	THREE	;IF NOT, DISPLAY 3 DIGITS
	CMP	C
	JNZ	TWO
	JMP	ONE
THREE	MOV	M,B	;DISPLAY SCORE
	INX	H
TWO	MOV	M,C
	INX	H
ONE	MOV	M,E
	INX	H
	XCHG
	LXI	H,MESS5	;POINT TO REST OF WIN MESS.
	CALL	SCRN2
PRNT1	CALL	KBD
	CPI	'Y'	;CHECK FOR RESTART
	JZ	START	;IF YES, START AGAIN
	RET		;IF NOT RETURN TO ALS-8
LSTST	ORA	A	;CHECK FOR NO FRINGE STARS
	JNZ	GTSTR	;IF ANY ARE PRESENT CONTINUE GAME
	MOV	A,C
	ORA	A	;IF NOT, CHECK FOR CENTER STAR
	JNZ	GTSTR	;IF PRESENT CONTINUE
	LXI	H,MESS3	;OTHERWISE POINT TO LOST MESS.
	CALL	SCRNB
	JMP	PRNT1
GTSTR	LXI	H,MESS7	;ASK FOR SHOT
	CALL	SCRNB
NXTST	CALL	KBD
	INX	H
	MOV	M,A	;ECHO SHOT
	CALL	DELAY
	MVI	E,9	;SET MASK COUNTER
	LXI	H,MASK	;POINT TO MASKS
NXGRP	CMP	M	;CHECK FOR SHOT
	JZ	FOUND
	DCR	E
	JZ	INVAL	;INVALID SHOT IF NOT FOUND
	INX	H	;POINT TO NEXT ENTRY
	INX	H
	INX	H
	INX	H
	JMP	NXGRP
FOUND	INX	H
	MOV	A,M
	ORA	A	;CHECK STAR POSITION
	JNZ	UNIV2	;JMP IF FRINGE STAR
	MOV	A,C
	CPI	1	;CHECK FOR CENTER STAR
	JNZ	BDFEL	;IF NOT PRESENT, BAD SHOT
	JMP	NXBYT
UNIV2	MOV	A,B
	ANA	M	;ISOLATE STAR SHOT
	JZ	BDFEL	;IF NOT PRESENT, BAD SHOT
;
;
;
;
;
NXBYT	INX	H
	MOV	A,B
	XRA	M	;ALTER GALAXY
	MOV	B,A	;SAVE NEW PATTERN
	INX	H
	MOV	A,C
	XRA	M	;CHANGE CENTER STAR, IF NECESSARY
	MOV	C,A
	JMP	CNTST	;COUNT SHOT AND DISPLAY NEW UNIVERSE
INVAL	CPI	ESC	;CHECK IF INVALID SHOT WAS AN ESCAPE
	JNZ	NTVAL
	LXI	H,MESS6	;IF SO POINT TO SURRENDER MESSAGE
	CALL	SCRNB
	JMP	PRNT1
NTVAL	LXI	H,MESS2	;POINT TO INVALID STAR MESSAGE
	CALL	SCRNB
	JMP	NXTST	;GO TO NEXT SHOT
SCRN	MOV	A,D
	STA	TEMP	;SAVE D (SHOT COUNTER)
	LXI	D,VDM1	;SET SCREEN ADDRESS
SCRN1	CALL	CLER	; CLEAR & INITIALIZE SCREEN
SCRN2	MOV	A,M
	CPI	EM	;CHECK FOR END OF MESSAGE
	JZ	ENDL
	STAX	D	;DISPLAY CHARACTER
	INX	H
	INX	D
	JMP	SCRN2
ENDL	LDA	TEMP	;GET SAVED SHOT COUNTER
	XCHG
	MOV	D,A	;PUT IT BACK IN D
	RET
SCRNB	MOV	A,D
	STA	TEMP
	LXI	D,SCRBT	;SET LOWER DISPLAY ADDRESS
	JMP	SCRN1
CLER	PUSH	 D	;SAVE STARTING ADDRESS
	XRA	A
	OUT	VDM	;INITIALIZE VDM-1
CLER1	MVI	A,' '	;GET A SPACE
	STAX	D
	INX	D
	MOV	A,D
	CPI	BOTT	;CHECK FOR END OF SCREEN
	JNZ	CLER1
	POP	D	;RESTORE STARTING ADDRESS
	RET
TYPE	XRA	A	;CLEAR A & CARRY
	MOV	A,B	;GET UNIVERSE
	RRC
	MOV	B,A
TYPE1	JC	STAR
	MVI	M,'0'	;DISPLAY HOLE
	RET
STAR	MVI	M,'*'	;DISPLAY STAR
	RET
KBD	CALL	DAV	;KEYBOARD INPUT ROUTINE
	JZ	KBD
	IN	DATA
	ANI	127
	RET
DAV	IN	STAT
	CMA		;CAN BE CHANGED TO A NOP
	ANI	DAVM
	RET
BDFEL	LXI	H,MESS1	;POINT TO ERROR MESSAGE
	CALL	SCRNB
	JMP	NXTST
DELAY	PUSH	D	;2 SECOND DELAY ROUTINE
	PUSH	PSW
	MVI	D,2
DLY1	MVI	E,100
DLY2	XRA	A
DLY3	DCR	A
	JNZ	DLY3
	DCR	E
	JNZ	DLY2
	DCR	D
	JNZ	DLY1
	POP	PSW
	POP	D
	RET
TEMP	DS	1
;
;
;
;
;
;
;
MESS1	DB 'HEY! YOU CAN ONLY SHOOT STARS, NOT BLACK HOLES.'
	DB ' TRY AGAIN.'
	DB EM
MESS2	DB 'THAT WASN''T A VALID STAR NUMBER. TRY AGAIN.'
	DB EM
MESS3	DB 'YOU LOST THE GAME! WANT TO SHOOT SOME MORE'
	DB 'STARS?'
	DB EM
MESS4	DB 'YOU WIN!! GOOD SHOOTING! YOU FIRED '
	DB EM
MESS5	DB ' SHOTS. BEST POSSIBLE    SCORE IS 11 SHOTS.'
	DB 'WANT TO SHOOT AGAIN, DEADEYE?'
	DB EM
MESS6	DB 'YOU GIVE UP T00 EASILY! WANT TO SHOOT SOME MORE'
	DB ' STARS?'
	DB EM
MESS7	DB 'YOUR SHOT?'
	DB EM
HEADR	DB ' * * * * * * * * *  S H 0 0 T I N G  S T A R'
	DB ' S * * * * * * * * '
	DB '. . . . . . . . . . . . . . . . . . . . . . . . . .'
	DB ' . . . . . . . '
	DB ' A    B R A I N   T E A S E R   G A M E ! ! !'
	DB '. . . . . . . . . . . . . . . . . . . . . . . . . .'
	DB ' . . . . . . . . . . . . . . . . '
	DB 'DO YOU WANT THE RULES?  (TYPE N FOR NO)'
	DB EM
PAGE1	DB 'THERE ARE STARS: *  AND THERE ARE HOLES: 0  IN'
	DB ' THE UNIVERSE.    '
	DB 'YOU SHOOT A STAR, (NOT A BLACK HOLE) BY TYPING '
	DB 'ITS NUMBER.        '
	DB ' 1 2 3                    '
	DB ' * * *                    '
	DB ' 0 0 0      '
	DB ' 4 5 6                    '
	DB ' * 0 *                    '
	DB ' 0 0 0      '
	DB ' 7 8 9                    '
	DB ' * * *                    '
	DB ' 0 0 0     '
	DB 'YOU WIN IF YOU GET THE PATTERN IN THE MIDDLE. '
	DB 'YOU LOSE IF YOU   GET THE PATTERN ON THE RIGHT.'
	DB EM
PAGE2	DB 'EACH STAR IS IN A GALAXY. WHEN YOU SHOOT A STAR'
	DB ' EVERYTHING IN   ITS GALAXY CHANGES. ALL STARS BECO'
	DB 'ME BLACK  HOLES AND ALL BLACK HOLES BECOME STARS.'
	DB ' . . . . . .GALAXIES:    '
	DB '. . .!. . . .       '
	DB '  1  *  0    *  2  *    0  *  3    *  0  0    '
	DB '0  *  0           '
	DB '  *  *  0    0  0  0    0  *  *    4  0  0    '
	DB '*  5  *           '
	DB '  0  0  0    0  0  0    0  0  0    *  0  0    '
	DB '0  *  0           '
	DB ' . . . . . . . . . . . . . . . . . . . . . . '
	DB ' . . . . . . .      '
	DB ' 0  0  *    0  0  0    0  0  0    '
	DB '0  0  0                       '
	DB ' 0  0  6    *  *  0    0  0  0    '
	DB '0  *  *                       '
	DB ' 0  0  *    7  *  0    *  8  *    '
	DB '0  *  9                     '
	DB ' READY TO PLAY. '
	DB 'TYPE ANY KEY TO START.  GOOD LUCK!'
	DB EM
;
;
;
;
;
;
MASK	DW 0131		;MASKS FOR CHANGING UNIVERSE
	DW 010BH
	DW 0232H
	DW 0007H
	DW 0433H
	DW 0116H
	DW 0834H
	DW 0029H
	DW 0035H
	DW 015AH
	DW 1036H
	DW 0094H
	DW 2037H
	DW 0168H
	DW 4038H
	DW 00E0H
	DW 8039H
	DW 01D0H
VDM1	EQU 0CC00H
SCRBT	EQU 0CF00H
VDM	EQU 0FEH	;CHANGE TO 0C8H FOR USE WITH VDM-1
STR1	EQU 0CD1BH	;STAR LOCATIONS
STR2	EQU 0CD20H
STR3	EQU 0CD25H
STR4	EQU 0CD9BH
STR5	EQU 0CDA0H
STR6	EQU 0CDA5H
STR7	EQU 0CE1BH
STR8	EQU 0CE20H
STR9	EQU 0CE25H
STAT	EQU 0FAH	;KEYBOARD STATUS PORT
DATA	EQU 0FCH	;KEYBOARD DATA PORT
DAVM	EQU 01H		;DATA AVAILABLE MASK
BOTT	EQU 0D0H
EM	EQU 01H
ESC	EQU 1BH
