Compucolor.org – Virtual Media

Listing of file='MOVSHP.MAC;03' on disk='vmedia/laser_gun_joystick-sector.ccvf'

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;	MOVE A SHIP GRAPHIC
;
	EXTRN	DELAY	;TIME DELAY
	EXTRN	DRWSYM	;DRAW A SHIP
	EXTRN	RANDOM	;RANDOM NUMBER GENERATOR

	EXTRN	BMPSCT,GETSCT,PUTSCT
;
;	EXTERNAL VARIABLES IN MAIN PROGRAM
;
	EXTRN	LOST
	EXTRN	SCT,HLSCT,NSHIP,SHPTYP,GRPTR,XPOS,YPOS
	EXTRN	HORCNT,VRTCNT,HORDRN,VRTDRN,HORSPD,VRTSPD
	EXTRN	XPLCNT
;
;	PROGRAM PARAMETERS
;
SHPWID	EQU	10	;WIDTH OF SHIP GRAPHIC (IN BYTES,
			; INCLUDING CCI'S)
SHPHGT	EQU	3	;HEIGHT OF SHIP GRAPHIC (IN LINES)
XMAX	EQU	63	;MAXIMUM X-COORD FOR SHIPS
YMAX	EQU	31	;MAXIMUM Y-COORD FOR SHIPS

;..............................................................
;
;	MOVE THE SHIPS
;
	ENTRY	MOVSHP

MOVSHP:	LXI	H,SCT	;SHIP CONTROL TABLE
	LDA	NSHIP	;NUMBER OF SHIPS
	MOV	B,A
MOVS1:	PUSH	B
	SHLD	HLSCT
	CALL	MOVE
	LHLD	HLSCT
	CALL	BMPSCT
	POP	B
	DCR	B
	JNZ	MOVS1
	RET

MOVE:	MOV	A,M	;GET SHIP TYPE
	ORA	A
	RZ		;RETURN IF NO SHIP
	XRA	A
	STA	MOVED	;MARK SHIP AS NOT HAVING MOVED
	CALL	GETSCT
	LDA	XPOS	;GET PREVIOUS POSITIONS AS "NEW" IN
	STA	NEWX	;  CASE ONE OF THEM IS NOT UPDATED
	LDA	YPOS
	STA	NEWY
	LDA	HORCNT	;SEE IF TIME IS UP FOR MOVE IN X-DIRN
	DCR	A
	STA	HORCNT
	JNZ	YMOVE	;NO, CHECK Y-DIRN

	LDA	HORSPD	;YES, RESET COUNTER
	STA	HORCNT
	LDA	XPLCNT	;DON'T REVERSE DIRECTION IF EXPLODING
	ORA	A
	JNZ	MOVE1

	LDA	XPOS	;DON'T REVERSE DIRECTION IF NEAR
	ORA	A	;  EDGES OF SCREEN
	JM	MOVE1
	CPI	SHPWID/2
	JC	MOVE1
	CPI	XMAX-SHPWID/2
	JNC	MOVE1

	MVI	A,20	;RANDOMLY REVERSE DIRECTION
	CALL	RANDOM	;  ROUGHLY ONCE EACH PASS ACROSS SCREEN
	CPI	17
	JNZ	MOVE1
	LDA	HORDRN	;COMPLEMENT DIRECTION
	CMA
	ADI	1
	STA	HORDRN
MOVE1:	MVI	A,0FFH
	STA	MOVED	;SET FLAG SAYING SHIP MOVED
	LDA	XPOS	;UPDATE X-COORD
	MOV	B,A
	LDA	HORDRN
	ADD	B	;MAKE THE MOVE
	STA	NEWX	;AND SAVE NEW X-COORD
	ADI	SHPWID/2	;CHECK IF MOVED OFF SCREEN
	JM	CLRSHP	;LEFT SIDE FIRST
	CPI	XMAX+SHPWID/2+1	;RIGHT SIDE
	JNC	CLRSHP

YMOVE:	LDA	VRTCNT	;SEE IF READY FOR MOVE IN Y-DIRN
	DCR	A
	STA	VRTCNT
	JNZ	MOVFIN

	LDA	VRTSPD	;RESTORE COUNTER
	STA	VRTCNT
	LDA	XPLCNT	;SEE IF EXPLODING
	ORA	A
	JNZ	MOVE2

	LDA	YPOS
	ORA	A
	JM	MOVE2
	CPI	SHPHGT
	JC	MOVE2
	CPI	YMAX-SHPHGT
	JNC	MOVE2

	MVI	A,20	;CHANGE DIRECTION ?
	CALL	RANDOM
	CPI	9
	JNZ	MOVE2
	LDA	VRTDRN
	CMA
	ADI	1
	STA	VRTDRN
MOVE2:	MVI	A,0FFH
	STA	MOVED	;MARK SHIP AS HAVING MOVED
	LDA	YPOS
	MOV	C,A
	LDA	VRTDRN
	ADD	C
	STA	NEWY	;SAVE NEW Y-COORD
	ADI	SHPHGT	;CHECK IF SHIP HAS MOVED OFF SCREEN
	JM	CLRSHP	;AT TOP,
	CPI	YMAX+SHPHGT+1	;AND AT BOTTOM
	JNC	CLRSHP

MOVFIN:	LDA	MOVED
	ORA	A
	JZ	MOVEND	;RETURN IF SHIP HAS NOT MOVED
	LXI	H,XPLCNT	;CHECK FOR EXPLODING SHIP
	MOV	A,M
	ORA	A
	JZ	MOVDRW
	DCR	M
	JZ	CLRSHP	;TIME-OUT ON EXPLOSION
MOVDRW:	CALL	WIPOUT	;ERASE OLD SHIP GRAPHIC
	LDA	NEWX	;UPDATE THE COORDS
	STA	XPOS
	MOV	B,A
	LDA	NEWY
	STA	YPOS
	MOV	C,A
	LHLD	GRPTR	;GET POINTER TO GRAPHIC
	XCHG
	MVI	H,SHPWID
	MVI	L,SHPHGT
	CALL	DRWSYM	;DRAW SHIP IN NEW POSITION

	LDA	XPLCNT	;DON'T WORRY ABOUT LASER IF SHIP
	ORA	A	;   IS EXPLODING
	JNZ	MOVEND
	LDA	NEWY	;SEE IF SHIP IS ON TOP OF LASER
	CPI	13
	JC	MOVEND
	CPI	16
	JNC	MOVEND
	LDA	NEWX
	CPI	28
	JC	MOVEND
	CPI	33
	JNC	MOVEND
	MVI	A,0FFH	;   AND SET FLAG FOR USER LOSES
	STA	LOST

MOVEND:	CALL	PUTSCT	;SAVE SCT ENTRY
	RET

CLRSHP:	CALL	WIPOUT	;ERASE SHIP FROM SCREEN
	XRA	A
	STA	SHPTYP	;SET NO SHIP
	JMP	MOVEND

MOVED:	DB	0	;FLAG FOR SHIP MOVED
NEWX:	DB	0	;NEW SHIP COORDS
NEWY:	DB	0
;
;	REMOVE SHIP FROM SCREEN
;
WIPOUT:	LDA	XPOS
	MOV	B,A
	LDA	YPOS
	MOV	C,A
	LXI	D,BLANK
	MVI	H,SHPWID
	MVI	L,SHPHGT
	CALL	DRWSYM
	RET

;..............................................................
;
;	DATA AREA
;
;	BLANKS FOR ERASING A SHIP

BLANK:	DB	20H,0,20H,0,20H,0,20H,0,20H,0
	DB	20H,0,20H,0,20H,0,20H,0,20H,0
	DB	20H,0,20H,0,20H,0,20H,0,20H,0

	END