*ALPHABET MAZE - COPYRIGHT 1984 - BY JEFFREY STANTON
	ORG	$3800
***	TF	"D:MAZE.OBJ"
*ZERO PAGE EQUATES
SHPL	EQU	$F0
SHPH	EQU	$F1
SHPML	EQU	$F2
SHPMH	EQU	$F3
SHPMOL	EQU	$F4
SHPMOH	EQU	$F5
PMADR	EQU	$F6
MAPL	EQU	$F8
MAPH	EQU	$F9
*OTHER EQUATES
SCREEN	EQU	$8700		; ADR OF SCREEN
NDLIST	EQU	$9400		; ADR OF DISPLAY LIST
CHRSET	EQU	$9000		; ADR OF CHARACTER SET
SETSIZ	EQU	1024
SETVBK	EQU	$E45C
XITVBK	EQU	$E462
STICK	EQU	$278
CHBAS	EQU	$2F4		; CHARACTER SET BASE
COLOR4	EQU	$2C8
*PLAYER MISSILE EQUATES
PMBASE	EQU	$D407
PDATA	EQU	$8800		; ADR OF P/M AREA
GRACTL	EQU	$D01D
DMACTL	EQU	$22F
HITCLR	EQU	$D01E
SIZEP0	EQU	$D008		; PLAYER SIZES
SIZEP1	EQU	$D009
SIZEP2	EQU	$D00A
SIZEP3	EQU	$D00B
COLPM0	EQU	$2C0		; PLAYER COLORS
COLPM1	EQU	$2C1
COLPM2	EQU	$2C2
COLPM3	EQU	$2C3
HPOSP0	EQU	$D000		; HORIZ PLAYER POSITIONS
HPOSP1	EQU	$D001
HPOSP2	EQU	$D002
HPOSP3	EQU	$D003
P0PL	EQU	$D00C		; PLAYER TO PLAYER COLLISIONS
RANDOM	EQU	$D20A
CONSOL	EQU	$D01F
DSCRN	DB	$05,$0C,$0C,$0C,$0C,$0C,$0C,$0C,$06,$0F
	DB	$0F,$05,$0C,$0C,$0C,$0C,$0C,$0C,$0C,$06
	DB	$03,$05,$0C,$0C,$04,$0C,$0C,$0C,$00,$0C
	DB	$0C,$00,$0C,$0C,$0C,$04,$0C,$0C,$06,$03
	DB	$03,$03,$0F,$0F,$03,$05,$0C,$0C,$02,$0F
	DB	$0F,$01,$0C,$0C,$06,$03,$0F,$0F,$03,$03
	DB	$01,$0A,$0F,$0F,$09,$02,$0F,$0F,$01,$0C
	DB	$0C,$02,$0F,$0F,$01,$0A,$0F,$0F,$09,$02
	DB	$01,$0C,$0C,$0C,$0C,$02,$0F,$05,$0A,$0F
	DB	$0F,$09,$06,$0F,$01,$0C,$0C,$0C,$0C,$02
	DB	$03,$0F,$0F,$0F,$0F,$01,$0C,$02,$0F,$0F
	DB	$0F,$0F,$01,$0C,$02,$0F,$0F,$0F,$0F,$03
	DB	$03,$05,$0C,$0C,$0C,$02,$0F,$09,$06,$0F
	DB	$0F,$05,$0A,$0F,$01,$0C,$0C,$0C,$06,$03
	DB	$03,$01,$0C,$0C,$06,$03,$0F,$0F,$01,$04
	DB	$04,$02,$0F,$0F,$03,$05,$0C,$0C,$02,$03
	DB	$03,$03,$0F,$0F,$03,$09,$0C,$0C,$02,$03
	DB	$03,$01,$0C,$0C,$0A,$03,$0F,$0F,$03,$03
	DB	$03,$09,$0C,$06,$09,$0C,$0C,$0C,$0A,$03
	DB	$03,$09,$0C,$0C,$0C,$0A,$05,$0C,$0A,$03
	DB	$09,$0C,$0C,$08,$0C,$0C,$0C,$0C,$0C,$0A
	DB	$09,$0C,$0C,$0C,$0C,$0C,$08,$0C,$0C,$0A
	DB	$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
	DB	$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
	DS	$10
DSCRN2	DB	$05,$0C,$0C,$0C,$06,$0F,$05,$0C,$0C,$0C
	DB	$0C,$0C,$0C,$06,$0F,$05,$0C,$0C,$0C,$06
	DB	$01,$04,$04,$04,$08,$0C,$02,$05,$0C,$0C
	DB	$0C,$0C,$06,$01,$0C,$08,$04,$04,$04,$02
	DB	$03,$03,$03,$03,$05,$04,$08,$00,$0C,$04
	DB	$04,$0C,$00,$08,$04,$06,$03,$03,$03,$03
	DB	$03,$03,$03,$03,$01,$0A,$0F,$03,$0F,$09
	DB	$0A,$0F,$03,$0F,$09,$02,$03,$03,$03,$03
	DB	$01,$0A,$03,$03,$03,$0F,$05,$02,$0F,$0F
	DB	$0F,$0F,$01,$06,$0F,$03,$03,$03,$09,$02
	DB	$01,$0C,$02,$09,$08,$0C,$08,$00,$0C,$0C
	DB	$0C,$0C,$00,$08,$0C,$08,$0A,$01,$0C,$02
	DB	$03,$0F,$01,$0C,$0C,$0C,$0C,$02,$0F,$0F
	DB	$0F,$0F,$01,$0C,$0C,$0C,$0C,$0A,$0F,$03
	DB	$01,$04,$08,$04,$0C,$0C,$0C,$02,$0F,$05
	DB	$06,$0F,$01,$0C,$0C,$0C,$04,$0C,$04,$02
	DB	$01,$0A,$0F,$03,$05,$0C,$0C,$08,$0C,$02
	DB	$01,$0C,$08,$0C,$0C,$06,$03,$0F,$09,$02
	DB	$03,$0F,$05,$02,$03,$05,$0C,$0C,$0C,$0A
	DB	$09,$0C,$0C,$0C,$06,$03,$01,$06,$0F,$03
	DB	$09,$0C,$08,$08,$08,$08,$0C,$0C,$0C,$0C
	DB	$0C,$0C,$0C,$0C,$08,$08,$08,$08,$0C,$0A
	DB	$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
	DB	$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
	DS	$10
DLIST	DB	$70,$70,$70,$47,$00,$87,$07,$07
	DB	$07,$07,$07,$07,$07,$07,$07,$07
	DB	$07,$41,$00,$94
*MAP CHARACTER DATA
DCHAR	DB	$00,$00,$00,$00,$00,$00,$00,$00
	DB	$80,$80,$80,$80,$80,$80,$80,$80
	DB	$01,$01,$01,$01,$01,$01,$01,$01
	DB	$81,$81,$81,$81,$81,$81,$81,$81
	DB	$FF,$00,$00,$00,$00,$00,$00,$00
	DB	$FF,$80,$80,$80,$80,$80,$80,$80
	DB	$FF,$01,$01,$01,$01,$01,$01,$01
	DB	$FF,$81,$81,$81,$81,$81,$81,$81
	DB	$00,$00,$00,$00,$00,$00,$00,$FF
	DB	$80,$80,$80,$80,$80,$80,$80,$FF
	DB	$01,$01,$01,$01,$01,$01,$01,$FF
	DB	$81,$81,$81,$81,$81,$81,$81,$FF
	DB	$FF,$00,$00,$00,$00,$00,$00,$FF
	DB	$FF,$80,$80,$80,$80,$80,$80,$FF
	DB	$FF,$01,$01,$01,$01,$01,$01,$FF
	DB	$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF
TITLE	DB	$20,$20,$20,$41,$4C,$50,$48,$41,$42,$45
	DB	$54,$20,$4D,$41,$5A,$45,$20,$20,$20,$20
	DB	$20,$20,$20,$20,$20,$20,$20,$20,$20,$20
	DB	$20,$20,$20,$20,$20,$20,$20,$20,$20,$20
	DB	$20,$42,$59,$20,$4A,$45,$46,$46,$52,$45
	DB	$59,$20,$53,$54,$41,$4E,$54,$4F,$4E,$20
TITLE1
***	AT	SELECT: EASY
	DB	0,0,0,$33,$25,$2C,$25,$23,$34,$1A,$00,$25,$21,$33,$39,0,0,0,0,0
***	AT    	HARD
	DB	0,0,0,0,0,0,0,0,0,0,0,$28,$21,$32,$24,0,0,0,0,0
	DS	$08
TITLE2
***	AT	NEXT LEVEL
	DB	0,0,0,0,0,$2E,$25,$38,$34,$00,$2C,$25,$36,$25,$2C,0,0,0,0,0
*VARIABLES
X0	DS	1		; PLAYER'S MAN POSITION
XX	DS	4		; REST OF PLAYER POSITIONS
Y0	DS	1
YY	DS	4		; REST OF PLAYER POSITIONS
XB	DS	4		; BLOCK EACH PLAYER IN
YB	DS	4
FLAGL	DS	4		; LEGAL MOVE FLAGS FOR EACH PLAYER
FLAGR	DS	4
FLAGU	DS	4
FLAGD	DS	4
RELL	DS	4		; DIRECTION WANT TO MOVE IN FLAGS
RELR	DS	4
RELU	DS	4
RELD	DS	4
MFLAGL	DS	4		; MATCH FLAGS
MFLAGR	DS	4
MFLAGU	DS	4
MFLAGD	DS	4
TEMPX	DS	1
TEMPY	DS	1
TEMPL	DS	4
TEMPH	DS	4
BLOCK	DS	1		; OFFSET IN SCREEN MEMORY OF CURRENT BLOCK
POINT0	DB	1		; SHAPE PLAYER 0
POINT1	DB	2
POINT2	DB	3
POINT3	DB	0
DL	DS	$04		; AUTO FLAGS
DR	DS	$04
DU	DS	$04
DD	DS	$04
INHIBIT	DB	0		; PREVENTS OBTAINING TWO JOYSTICK DIRECTIONS
VBFLAG	DB	0		; VBLANK FINISHED FLAG $ON DIAGONAL
LFLAG	DB	0		; INDICATES WHETHER AT CENTER OF BLOCK
NUM	DB	0		; NUMBER OF DIRECTION MATCH FLAGS
PAUSE	DB	0		; PAUSE FLAG
SLOW	DB	0		; SETS MINUS SIGN TO HALF SPEED
HALF	DB	0		; COUNTER WHEN PLAYER MOVES AT HALF SPEED
LEVEL	DS	$01		; MAZE LEVEL
ONCE	DS	$01		; PREVENTS DOUBLE COLLISIONS @ HALF SPEED
*POINTERS TO PM DATA
SHPLO	DB	$00,$08,$10,$18,$20,$28,$30,$38
	DB	$40,$48,$50,$58,$60,$68,$70,$78
	DB	$80,$88,$90,$98,$A0,$A8,$B0,$B8
	DB	$C0,$C8,$D0,$D8,$E0
	DS	$65
*MAKE SURE STARTS @$2C00
*PLAYER MISSILE DATA
SHAPES	DB	$00,$00,$00,$3C,$3C,$00,$00,$00		; MINUS SIGN
	DB	$18,$3C,$66,$42,$7E,$42,$42,$42		; LETTER A
	DB	$7C,$42,$42,$7C,$42,$42,$42,$7C		; B
	DB	$1E,$20,$40,$40,$40,$40,$20,$1E		; C
	DB	$78,$44,$42,$42,$42,$42,$44,$78		; D
	DB	$7E,$40,$40,$7C,$40,$40,$40,$7E		; E
	DB	$7E,$40,$40,$7C,$40,$40,$40,$40		; F
	DB	$1E,$20,$40,$40,$4E,$42,$22,$1C		; G
	DB	$42,$42,$42,$7E,$42,$42,$42,$42		; H
	DB	$7C,$10,$10,$10,$10,$10,$10,$7C		; I
	DB	$04,$04,$04,$04,$04,$44,$44,$38		; J
	DB	$44,$48,$50,$60,$60,$50,$48,$44		; K
	DB	$40,$40,$40,$40,$40,$40,$40,$7E		; L
	DB	$41,$63,$55,$49,$41,$41,$41,$41		; M
	DB	$62,$62,$52,$52,$4A,$4A,$46,$46		; N
	DB	$18,$24,$42,$42,$42,$42,$24,$18		; 0
	DB	$7C,$42,$42,$42,$7C,$40,$40,$40		; P
	DB	$18,$24,$42,$42,$42,$42,$26,$1B		; Q
	DB	$7C,$42,$42,$42,$7C,$44,$42,$41		; R
	DB	$3E,$40,$40,$40,$3C,$02,$02,$7C		; S
	DB	$FE,$10,$10,$10,$10,$10,$10,$10		; T
	DB	$42,$42,$42,$42,$42,$42,$42,$3C		; U
	DB	$82,$82,$82,$82,$44,$44,$28,$10		; V
	DB	$41,$41,$41,$41,$49,$55,$63,$41		; W
	DB	$41,$22,$14,$08,$14,$22,$41,$00		; X
	DB	$42,$42,$24,$18,$10,$20,$40,$40		; Y
	DB	$7F,$02,$04,$08,$10,$20,$7F,$00		; Z
	DB	$00,$00,$00,$00,$00,$00,$00,$00		; BLANK
	DB	$00,$00,$00,$00,$00,$00,$00,$00		; BLANK
*SETUP DLIST
BEGIN
	LDX	#$00
DLOOP	LDA	DLIST,X
	STA	NDLIST,X
	INX
	CPX	#$15		; 21 ELEMENTS
	BNE	DLOOP
	LDA	#NDLIST		; LOCATION OF DISPLAY LIST
	STA	$230
	LDA	#<NDLIST
	STA	$231
*ERASE SCREEN
START	LDX	#$00
	LDA	#$00
ALOOP	STA	SCREEN,X
	INX
	BNE	ALOOP
*WRITE TITLE & AUTHOR
	LDA	#$E0		; ROM CHARACTER SET
	STA	CHBAS
	LDX	#$00
BLOOP	LDA	TITLE,X
	SEC
	SBC	#$20
	STA	$873C,X
	INX
	CPX	#$3C
	BNE	BLOOP
*WRITE SELECT EASY & HARD
	LDX	#$00
RLOOP	LDA	TITLE1,X	; PUT IN 8TH ROW
	STA	$87A0,X
	INX
	CPX	#$28
	BNE	RLOOP
	LDA	#$0A		; WRITE BESIDE HARD
	STA	$87C3
*READ CONSOLE KEYS
	LDA	#$00
	STA	SLOW
	STA	LEVEL
KEY	LDA	CONSOL
	CMP	#$06
	BEQ	MAIN
	CMP	#$05
	BNE	KEY
	LDA	SLOW
	BNE	AA2
AA1	LDA	#$0A		; WRITE * BESIDE EASY
	STA	$87AF
	LDA	#$00		; ERASE * BESIDE HARD
	STA	$87C3
	LDA	#$01
	STA	SLOW
	JMP	AA3
AA2	LDA	#$0A		; WRITE * BESIDE HARD
	STA	$87C3
	LDA	#$00		; ERASE * BESIDE EASY
	STA	$87AF
	LDA	#$00
	STA	SLOW
AA3	LDA	#$E8
	STA	$14
	LDA	#$00
	STA	$13
AA4	LDA	$13		; DELAY 24 JIFFIES
	BEQ	AA4
	JMP	KEY
*SETUP CHARACTER SET
MAIN	LDX	#$00
CLOOP	LDA	DCHAR,X
	STA	CHRSET,X
	INX
	CPX	#$80
	BNE	CLOOP
	LDA	#<CHRSET
	STA	CHBAS
*SETUP SCREEN
	LDX	#$00
SLOOP	LDA	DSCRN,X
	STA	SCREEN,X
	INX
	CPX	#$F0		; 220 BYTES
	BNE	SLOOP
	LDA	#DSCRN
	STA	MAPL
	LDA	#<DSCRN
	STA	MAPH
	LDA	#$00		; BACKGROUND BLACK
	STA	COLOR4
*INITALIZE PLAYERS
	LDA	#$88
	STA	PMBASE
	LDA	#$03
	STA	GRACTL
	LDA	#$3E
	STA	DMACTL
	LDA	#$00
	STA	SIZEP0
	STA	SIZEP1
	STA	SIZEP2
	STA	SIZEP3
RESTART	STA	HITCLR		; CLEAR COLLISION REG
*PLAYER #0
	LDA	#$7A		; PLAYER #0 122 BLUE LUM10
	STA	COLPM0
	LDA	#$30		; INITIAL POS X=48,Y=36
	STA	X0
	STA	XX
	STA	HPOSP0		; TELL ANTIC
	LDA	#$24
	STA	Y0
	STA	YY
*INITIAL OLD PLAYER #0 MEMORY POINTERS
	LDA	#$40
	STA	TEMPL
	LDA	#<PDATA
	CLC
	ADC	#$04
	STA	TEMPH
*PLAYER #1
	LDX	#$01
	LDA	#$C8		; PLAYER #1 200 GREEN LUM8
	STA	COLPM1
	LDA	#$88		; INITIAL POSITION X=136,Y=164
	STA	XX,X
	STA	HPOSP1
	LDA	#$A4
	STA	YY,X
*OLD PLAYER #1 MEMORY POINTERS
	LDA	#$40
	STA	TEMPL,X
	LDA	#<PDATA
	CLC
	ADC	#$05
	STA	TEMPH,X
*PLAYER #2
	LDX	#$02
	LDA	#$C8		; PLAYER #2 200 GREEN LUM8
	STA	COLPM2
	LDA	#$A0		; INITIAL POSITION X=160,Y=52
	STA	XX,X
	STA	HPOSP2
	LDA	#$34
	STA	YY,X
*OLD PLAYER #2 MEMORY POINTERS
	LDA	#$40
	STA	TEMPL,X
	LDA	#<PDATA
	CLC
	ADC	#$06
	STA	TEMPH,X
*PLAYER #3
	LDX	#$03
	LDA	#$44		; PLAYER #3 68 RED LUM4
	STA	COLPM3
	LDA	#$C8		; INITIAL POSITION X=200,Y=196
	STA	XX,X
	STA	HPOSP3
	LDA	#$C4
	STA	YY,X
*OLD PLAYER #3 MEMORY POINTERS
	LDA	#$40
	STA	TEMPL,X
	LDA	#<PDATA
	CLC
	ADC	#$07
	STA	TEMPH,X
*INIT POINT# VALUES
	LDA	#$01
	STA	POINT0
	LDA	#$02
	STA	POINT1
	LDA	#$03
	STA	POINT2
	LDA	#$00
	STA	POINT3
	STA	ONCE
*INIT AUTO FLAGS
INAUTO	LDX	#$00
	LDA	#$00
AB1	STA	DL,X
	STA	DR,X
	STA	DU,X
	STA	DD,X
	INX
	CPX	#$04
	BNE	AB1
*START PLAYERS MOVING
	LDA	#$01
	STA	DR+1
	STA	DR+2
	STA	DL+3
*CLEAR P/M AREA
CLEAR	LDA	#$00		; PDATL
	STA	PMADR
	LDA	#<PDATA
	STA	PMADR+1
	LDY	#$00
	TYA
	LDX	#$08
AC1	STA	(PMADR),Y
	INY
	BNE	AC1
	INC	PMADR+1		; NEXT 256 BYTES
	DEX
	BNE	AC1
*PLOT INITIAL PLAYER POSITIONS
	LDX	#$00
	JSR	PLTST0
	LDX	#$01
	JSR	PLTST1
*SET VBLANK
	LDA	#$07
	LDX	#<FRAME		; HI BYTE VBLANK ROUTINE
	LDY	#FRAME		; LO BYTE
	JSR	SETVBK
*MAIN CODE LOOP
LOOPM	LDA	#$00
	STA	VBFLAG
*CHECK COLLISIONS
	LDA	P0PL		; CHECK COLLISION PLAYER 0&1
	CMP	#$02
	BNE	AD1
	SEC
	LDA	POINT1		; IS THERE A 1 LETTER DIFFERENCE
	SBC	POINT0
	CMP	#$02
	BGE	AD1
	INC	POINT0		; PLAYER BECOMES NEXT LETTER
	INC	POINT1		; OLD LETTER JUMPS 2 LETTERS
	INC	POINT1
	LDY	#$01
	JSR	PLACE		; PUT PLAYER#1 IN NEW PLACE
AD1	LDA	P0PL		; CHECK COLLISION PLAYER 0&2
	CMP	#$04
	BNE	AD2
	SEC
	LDA	POINT2		; IS THERE A I LETTER DIFFERENCE
	SBC	POINT0
	CMP	#$02
	BGE	AD2
	INC	POINT0
	INC	POINT2
	INC	POINT2
	LDY	#$02
	JSR	PLACE
AD2	LDA	P0PL		; CHECK COLLISION PLAYER 0&3
	CMP	#$08
	BNE	AD3
	LDA	ONCE		; MUST MOVE PLAYER #3 BEFORE TESTING
	BNE	AD3		; FOR NEW COLLISION
	LDA	POINT0
	CMP	#$01
	BEQ	AD25
	DEC	POINT0
	DEC	POINT1
	DEC	POINT2
	INC	ONCE
AD25	LDY	#$03
	LDA	XB		; PUT PLAYER #3 OPPOSITE SIDE AS PLAYER #0
	CMP	#$0A
	BGE	AD27
	LDA	#$C8		; PUT PLAYER #3-AT BOTTOM LEFT (200,196)
	STA	XX,Y
	LDA	#$C4
	STA	YY,Y
	LDA	#$00
	STA	DU,Y
	STA	DR,Y
	STA	DD,Y
	LDA	#$01
	STA	DL,Y
	JMP	AD3
AD27	LDA	#$40
	STA	XX,Y		; PUT PLAYER #3 AT BOTTOM RT (48,196)
	LDA	#$C4
	STA	YY,Y
	LDA	#$00
	STA	DU,Y
	STA	DD,Y
	STA	DL,Y
	LDA	#$01
	STA	DR,Y
AD3	STA	HITCLR
	LDA	#$00		; STOP ATTRACT MODE
	STA	$4D
*PLAYER #1 CODE
	LDX	#$01
	JSR	MOVEPL
	JSR	PLTST1
*PLAYER #2
	LDX	#$02
	JSR	MOVEPL
	JSR	PLTST2
*PLAYER3
	LDA	SLOW
	CMP	#$00
	BEQ	P3
	INC	HALF		; INCREMENT COUNTER
	LDA	HALF
	LSR			; DIVIDE BY 2
	BCC	RESET		; SKIPS ON EVEN CYCLES
P3	LDX	#$03
	JSR	MOVEPL
	JSR	PLTST3
	LDA	#$00
	STA	ONCE
*IF PLAYER #0 BECOMES Z RESET TO SECOND SCREEN
RESET	LDA	POINT0
	CMP	#$1A
	BNE	FOREVER
	LDA	#$80
	STA	$14
DELAY	LDA	$14		; ABOUT 2 SEC
	BNE	DELAY
*MOVE PLAYERS TEMP OFF SCREEN
	LDA	#$00
	STA	COLPM0		; TERP BLACKOUT PLAYER#O IN VBLANK
	STA	HPOSP1
	STA	HPOSP2
	STA	HPOSP3
*DONE WITH 2ND LEVEL
	LDA	LEVEL
	CMP	#$01
	BNE	AE1
	JMP	START
*ERASE SCREEN
AE1	LDX	#$00
	LDA	#$00
FLOOP	STA	SCREEN,X
	INX
	BNE	FLOOP
*WRITE 'NEXT LEVEL'
	LDA	#$E0		; BACK TO ROM CHARACTER SET
	STA	CHBAS
	INC	LEVEL
	LDX	#$00
GLOOP	LDA	TITLE2,X
	STA	$878C,X
	INX
	CPX	#$14
	BNE	GLOOP
	LDA	#$80
	STA	$14		; 2 SECOND DELAY
	LDA	#$00
	STA	$13
AF1	LDA	$13
	BEQ	AF1
	LDA	#<CHRSET	; RAM CHARACTER SET
	STA	CHBAS
*SETUP SECOND SCREEN
	LDX	#$00
SLOOP1	LDA	DSCRN2,X
	STA	SCREEN,X
	INX
	CPX	#$F0
	BNE	SLOOP1
	LDA	#DSCRN2
	STA	MAPL
	LDA	#<DSCRN2
	STA	MAPH
	LDA	#$7A		; RESTORE PLAYER #0 COLOR
	STA	COLPM0
	JMP	RESTART
FOREVER	LDA	VBFLAG		; STAYS IN THIS LOOP UNTIL
	CMP	#$01		; VBLANK ROUTINE SETS VBFLAG=1
	BNE	AG1
	JMP	LOOPM
AG1	JMP	FOREVER
MOVEPL	JSR	LEGAL
	LDA	LFLAG		; EQUAL TO I IF AT CENTER OF BLOCK
	BNE	AH1
	JSR	AUTOP
	JMP	FIN
*IS THERE AN AVAILABLE DIRECTION OTHER THAN FORWARD OR REVERSE
AH1	LDA	DL,X
	BEQ	AH2
	LDA	FLAGU,X
	BNE	AH11
	JMP	YES
AH11	LDA	FLAGD,X
	BNE	AH12
	JMP	YES
*CONTINUE MOVING IN SAME DIRECTION UNLESS BLOCKED
AH12	LDA	FLAGL,X
	BNE	AH13
	DEC	XX,X
	JMP	FIN
AH13	LDA	#$00		; REVERSE DIRECTION
	STA	DL,X
	LDA	#$01
	STA	DR,X
	INC	XX,X
	JMP	FIN
AH2	LDA	DR,X
	BEQ	AH3
	LDA	FLAGU,X
	BNE	AH21
	JMP	YES
AH21	LDA	FLAGD,X
	BNE	AH22
	JMP	YES
AH22	LDA	FLAGR,X
	BNE	AH23
	INC	XX,X
	JMP	FIN
AH23	LDA	#$00		; REVERSE DIRECTION
	STA	DR,X
	LDA	#$01
	STA	DL,X
	DEC	XX,X
	JMP	FIN
AH3	LDA	DU,X
	BEQ	AH4
	LDA	FLAGL,X
	BNE	AH31
	JMP	YES
AH31	LDA	FLAGR,X
	BNE	AH32
	JMP	YES
AH32	LDA	FLAGU,X
	BNE	AH33
	DEC	YY,X
	JMP	FIN
AH33	LDA	#$00		; REVERSE DIRECTION
	STA	DU,X
	LDA	#$01
	STA	DD,X
	INC	YY,X
	JMP	FIN
AH4	LDA	DD,X
	BEQ	FIN
	LDA	FLAGL,X
	BNE	AH41
	JMP	YES
AH41	LDA	FLAGR,X
	BNE	AH42
	JMP	YES
AH42	LDA	FLAGD,X
	BNE	AH43
	INC	YY,X
	JMP	FIN
AH43	LDA	#$00		; REVERSE DIRECTION
	STA	DD,X
	LDA	#$01
	STA	DU,X
	DEC	YY,X
FIN	JMP	EE
YES	NOP
*SET ALL REL,X FLAGS
*VALUE OF 0 WOULDN'T WANT TO MOVE BUT VALUE OF I WOULD HOME
*PLAYER 1&2 FLEES - PLAYER 3 CHASES IN ON PLAYER
TESTRX	LDA	#$00		; ZERO REL,X FLAGS
	STA	RELL,X
	STA	RELR,X
	STA	RELD,X
	STA	RELU,X
	LDA	XB,X
	SEC
	SBC	XB
	BEQ	AK4
	BPL	AK1
	CPX	#$03
	BEQ	AK2
	LDA	#$01
	STA	RELL,X		; ACTUALLY RELR,X=-1 BUT RELL,X=1
	JMP	TESTRY
AK2	LDA	#$01
	STA	RELR,X
	JMP	TESTRY
AK1	CPX	#$03
	BEQ	AK3
	LDA	#$01
	STA	RELR,X		; ACTUALLY RELL,X=-1
	JMP	TESTRY
AK3	LDA	#$01
	STA	RELL,X
	JMP	TESTRY
AK4	CPX	#$03
	BEQ	TESTRY
	LDA	#$01
	STA	RELL,X
	STA	RELR,X
TESTRY	LDA	YB,X
	SEC
	SBC	YB
	BPL	AM1
	BEQ	AM4
	CPX	#$03
	BEQ	AM2
	LDA	#$01
	STA	RELU,X		; ACTUALLY RELD,X=-1
	JMP	MATCHT
AM2	LDA	#$01
	STA	RELD,X
	JMP	MATCHT
AM1	CPX	#$03
	BEQ	AM3
	LDA	#$01
	STA	RELD,X		; ACTUALLY RELU,X=-1
	JMP	MATCHT
AM3	LDA	#$01
	STA	RELU,X
	STA	RELU,X
	JMP	MATCHT
AM4	CPX	#$03
	BEQ	MATCHT
	LDA	#$01
	STA	RELD,X
	STA	RELU,X
MATCHT	LDA	#$00
	STA	NUM
	STA	MFLAGL,X
	STA	MFLAGR,X
	STA	MFLAGU,X
	STA	MFLAGD,X
	LDA	FLAGL,X
	BNE	AN2
	LDA	RELL,X
	CMP	#$01
	BNE	AN2
	INC	NUM
	LDA	#$01
	STA	MFLAGL,X	; SET MATCH FLAG
AN2	LDA	FLAGR,X
	BNE	AN3
	LDA	RELR,X
	CMP	#$01
	BNE	AN3
	INC	NUM
	LDA	#$01
	STA	MFLAGR,X
AN3	LDA	FLAGU,X
	BNE	AN4
	LDA	RELU,X
	CMP	#$01
	BNE	AN4
	INC	NUM
	LDA	#$01
	STA	MFLAGU,X
AN4	LDA	FLAGD,X
	BNE	PP
	LDA	RELD,X
	CMP	#$01
	BNE	PP
	INC	NUM
	LDA	#$01
	STA	MFLAGD,X
*IF MATCH CAUSES PLAYER TO REVERSE PREVENT IT
PP	LDA	DL,X
	BEQ	AP42
	LDA	MFLAGR,X
	BEQ	AP42
	LDA	#$00
	STA	MFLAGR,X
	DEC	NUM
	JMP	AP5
AP42	LDA	DR,X
	BEQ	AP43
	LDA	MFLAGL,X
	BEQ	AP43
	LDA	#$00
	STA	MFLAGL,X
	DEC	NUM
	JMP	AP5
AP43	LDA	DU,X
	BEQ	AP44
	LDA	MFLAGD,X
	BEQ	AP44
	LDA	#$00
	STA	MFLAGD,X
	DEC	NUM
	JMP	AP5
AP44	LDA	DD,X
	BEQ	AP5
	LDA	MFLAGU,X
	BEQ	AP5
	LDA	#$00
	STA	MFLAGU,X
	DEC	NUM
*IF TWO MATCHES THEN CHOOSE A DIRECTION RANDOMILY
AP5	LDA	NUM		; THEN MOVE IN DIRECTION
	BNE	AP55
	JSR	CORECT
	JMP	EE
AP55	LDA	NUM
	CMP	#$01
	BEQ	AP6
	LDA	RANDOM
	CMP	#80
	BL	AP8
AP6	LDA	MFLAGL,X
	CMP	#$01
	BNE	AP7
	LDA	#$01
	STA	DL,X
	LDA	#$00
	STA	DD,X
	STA	DR,X
	STA	DU,X
	DEC	XX,X
	JMP	EE
AP7	LDA	MFLAGR,X
	CMP	#$01
	BNE	AP8
	LDA	#$01
	STA	DR,X
	LDA	#$00
	STA	DL,X
	STA	DU,X
	STA	DD,X
	INC	XX,X
	JMP	EE
AP8	LDA	MFLAGU,X
	CMP	#$01
	BNE	AP9
	LDA	#$01
	STA	DU,X
	LDA	#$00
	STA	DL,X
	STA	DR,X
	STA	DD,X
	DEC	YY,X
	JMP	EE
AP9	LDA	MFLAGD,X
	CMP	#$01
	BNE	EE
	LDA	#$01
	STA	DD,X
	LDA	#$00
	STA	DU,X
	STA	DL,X
	STA	DR,X
	INC	YY,X
EE	RTS
*VBLANK ROUTINE
FRAME	NOP
PAUSEI	LDA	$2FC		; KEY PRESSED?
	CMP	#$FF
	BEQ	AR2
	CMP	#$21		; SPACE BAR?
	BNE	AR3
	LDA	PAUSE		; PAUSE=I?
	CMP	#$01
	BEQ	AR1
	LDA	#$01		; NOT PAUSED-THEN SET PAUSE
	STA	PAUSE
	LDA	#$FF
	STA	$2FC
	JMP	XITVBK
AR1	LDA	#$00		; PAUSED-THEN RELEASE PAUSE
	STA	PAUSE
	LDA	#$FF
	STA	$2FC
	JMP	AR3
AR2	LDA	PAUSE		; PAUSED?
	CMP	#$01
	BNE	AR3
	JMP	XITVBK
AR3	LDA	#01
	STA	VBFLAG
	LDX	#$00
	JSR	LEGAL
*READ JOYSTICK
	LDA	STICK		; JOYSTICK CENTERED?
	CMP	#$0F
	BNE	DUR
	JSR	AUTO		; IF STICK NOT TOUCHED CONTINUE IN SAME DIR
	JMP	STAY
DUR	LDA	STICK		; TEST DIAGONAL UP&RT
	CMP	#$06
	BNE	DDR
	LDA	DR
	BEQ	AS01
	JMP	CHKUP
AS01	LDA	DU
	BNE	AS02
	JSR	AUTO
	JMP	STAY
AS02	LDA	#$01		; SET TO RT ONLY
	STA	INHIBIT
	JMP	CHKRT
DDR	LDA	STICK		; TEST DIAGONAL DOWN&RT
	CMP	#$05
	BNE	DUL
	LDA	DR
	BEQ	AS03
	JMP	CHKDN
AS03	LDA	DD
	BNE	AS04
	JSR	AUTO
	JMP	STAY
AS04	LDA	#$01		; SET TO RT ONLY
	STA	INHIBIT
	JMP	CHKRT
DUL	LDA	STICK		; TEST DIAGONAL UP&LEFT
	CMP	#$0A
	BNE	DDL
	LDA	DL
	BEQ	AS05
	JMP	CHKUP
AS05	LDA	DU
	BNE	AS06
	JSR	AUTO
	JMP	STAY
AS06	LDA	#$01		; SET TO LEFT ONLY
	STA	INHIBIT
	JMP	CHKLF
DDL	LDA	STICK		; TEST DIAGONAL DOWN&LEFT
	CMP	#$09
	BNE	CHKRT
	LDA	DL
	BEQ	AS07
	JMP	CHKDN
AS07	LDA	DD
	BNE	AS08
	JSR	AUTO
	JMP	STAY
AS08	LDA	#$01		; SET TO LEFT ONLY
	STA	INHIBIT
	JMP	CHKLF
CHKRT	LDA	STICK
	AND	#$08		; RT BIT?
	BNE	CHKLF
	LDA	FLAGR
	BEQ	AT2
	JSR	AUTO
	JMP	STAY
AT2	LDA	#$00
	STA	DL		; SHUT OFF AUTO FLAGS
	STA	DU
	STA	DD
	STA	FLAGL		; RESET LEGAL FLAGS-ONLY CAN TRAVEL
	LDA	#$01		; BETWEEN TWO BLOCKS
	STA	FLAGU
	STA	FLAGD
	STA	DR		; TURN ON AUT014ATIC FLAG
	INC	X0		; X0--XG+1
	INC	XX
CHKLF	LDA	STICK
	AND	#$04		; LEFT BIT
	BNE	CHK
	LDA	FLAGL
	BEQ	AT3
	JSR	AUTO
	JMP	STAY
AT3	LDA	#$00
	STA	DR
	STA	DU
	STA	DD
	STA	FLAGR
	LDA	#$01
	STA	FLAGU
	STA	FLAGD
	STA	DL
	DEC	X0		; X0-X0-1
	DEC	XX
CHK	LDA	INHIBIT		; THIS PREVENTS GETTING BOTH DIRECTIONS
	BEQ	CHKUP		; ON DIAGONAL
	JMP	STAY
CHKUP	LDA	STICK
	AND	#$01		; UP BIT?
	BNE	CHKDN
	LDA	FLAGU
	BEQ	AT4
	JSR	AUTO
	JMP	STAY
AT4	LDA	#$00
	STA	DD
	STA	DR
	STA	DL
	STA	FLAGD
	LDA	#$01
	STA	FLAGL
	STA	MFLAGR				;  ???  FLAGR  ???
	STA	DU
	DEC	Y0		; Y0--Y0-1
	DEC	YY
CHKDN	LDA	STICK
	AND	#$02
	BNE	STAY
	LDA	FLAGD
	BEQ	AT5
	JSR	AUTO
	JMP	STAY
AT5	LDA	#$00
	STA	DU
	STA	DR
	STA	DL
	STA	FLAGU
	LDA	#$01
	STA	FLAGL
	STA	FLAGR
	STA	DD
	INC	Y0		; Y0-Y0+1
	INC	YY
STAY	LDA	#$00
	STA	INHIBIT
	LDX	#$00
	JSR	PLTST0
	JMP	XITVBK
*SUBROUTINE-TEST FOR LEGAL MOVES
*INPUT X,Y PLAYER POSITION; X REG PLAYER
*OUTPUT FLAGL,X;FLAGR,X;FLACU,X;FLAGD,X-0-OPEN,1-CLOSE
LEGAL	LDA	#$00
	STA	LFLAG
	LDA	XX,X		; PLAYER HOR POSITION
	SEC
	SBC	#$30		; SUBTRACT 48
	STA	TEMPX
	LSR			; DIVIDE BY 8
	LSR
	LSR
	STA	XB,X
	LDA	YY,X		; PLAYER VERT POSITION
	SEC
	SBC	#$24		; SUBTRACT 36
	STA	TEMPY
	LSR			; DIVIDE BY 16
	LSR
	LSR
	LSR
	STA	YB,X
*TEST IF AT CENTER OF BLOCK
	LDA	TEMPY
	AND	#$0F		; TEST AGAINST FIRST 4 BITS-ONLY MULTIPLE
	BNE	DONE		; OF 16 @CENTER
	LDA	TEMPX
	AND	#$07		; TEST AGAINST FIRST 3 BITS-ONLY MULTIPLE
	BNE	DONE		; OF 8 @CENTER
	LDA	#$01
	STA	LFLAG
*AT CENTER-TEST&RESET LEGAL MOVE FLAGS
*BLOCK=(YB*20)+XB
	LDA	#$00
	LDY	YB,X
	CPY	#$00		; IF 0 SKIP ADD & DECREMENT
	BEQ	AW5
AW1	CLC
	ADC	#$14
	DEY
	CPY	#$00
	BNE	AW1
AW5	CLC
	ADC	XB,X
	STA	BLOCK
	LDA	#$00		; OPEN ALL FLAGS FOR PLAYER
	STA	FLAGL,X
	STA	FLAGR,X
	STA	FLAGU,X
	STA	FLAGD,X
*TEST BLOCK MAN IN FOR LEGAL MOVES
	LDY	BLOCK
	LDA	(MAPL),Y
	AND	#$01
	BEQ	AW2
	LDA	#$01
	STA	FLAGL,X
AW2	LDA	(MAPL),Y
	AND	#$02
	BEQ	AW3
	LDA	#$01
	STA	FLAGR,X
AW3	LDA	(MAPL),Y
	AND	#$04
	BEQ	AW4
	LDA	#$01
	STA	FLAGU,X
AW4	LDA	(MAPL),Y
	AND	#$08
	BEQ	DONE
	LDA	#$01
	STA	FLAGD,X
DONE	RTS
*PUT SHAPE IN P/M AREA
PLOT	LDY	#$00		; COUNTER
	LDA	#$00		; NEED 0 TO ERASE EACH TIME
AX1	STA	(SHPMOL),Y	; ERASE OLD SHAPE FIRST
	INY
	CPY	#$08
	BL	AX1
	LDY	#$00
AX2	LDA	(SHPL),Y	; GET BYTE FROM PROPER SHAPE TABLE
	STA	(SHPML),Y	; PUT IN P/M AREA
	INY
	CPY	#$08
	BL	AX2
	LDA	SHPML		; TRANSFER NEW P/M POS TO OLD POS
	STA	TEMPL,X
	LDA	SHPMH
	STA	TEMPH,X
	RTS
*SUBROUTINE PLOTSET0
PLTST0	LDA	X0
	STA	XX
	STA	HPOSP0
	LDA	Y0
	STA	YY
	STA	SHPML
	LDA	#<PDATA
	CLC
	ADC	#$04		; PLAYER IS 1K BEY0ND START
	STA	SHPMH
	LDY	POINT0
	LDA	SHPLO,Y		; POINTER TO CORRECT SHAPE
	STA	SHPL
	LDA	#<SHAPES
	STA	SHPH
	LDX	#$00
	LDA	TEMPL,X
	STA	SHPMOL
	LDA	TEMPH,X
	STA	SHPMOH
	JSR	PLOT
	RTS
*CONTINUE MOVING IN LAST DIR UNLESS HIT WALL
*AUTO ON - #1
AUTO	LDA	DR
	CMP	#$01
	BNE	AY1
	LDA	FLAGR
	CMP	#$00
	BNE	AY4
	LDA	#$00
	STA	FLAGL
	LDA	#$01
	STA	FLAGU
	STA	FLAGD
	INC	X0
	JMP	AY4
AY1	LDA	DL
	CMP	#$01
	BNE	AY2
	LDA	FLAGL
	CMP	#$00
	BNE	AY4
	LDA	#$00
	STA	FLAGR
	LDA	#$01
	STA	FLAGU
	STA	FLAGD
	DEC	X0
	JMP	AY4
AY2	LDA	DU
	CMP	#$01
	BNE	AY3
	LDA	FLAGU
	CMP	#$00
	BNE	AY4
	LDA	#$00
	STA	FLAGD
	LDA	#$01
	STA	FLAGR
	STA	FLAGL
	DEC	Y0
	JMP	AY4
AY3	LDA	DD
	CMP	#$01
	BNE	AY4
	LDA	FLAGD
	CMP	#$00
	BNE	AY4
	LDA	#$00
	STA	FLAGU
	LDA	#$01
	STA	FLAGR
	STA	FLAGL
	INC	Y0
AY4	NOP
	RTS
*AUTO CODE FOR PLAYERS 1,2 & 3
*NEEDS PLAYER # IN X-REGISTER
*CODE DOESN'T REQUIRE LATCHES SINCE JOYSTICK CAN'T SEND
AUTOP	LDA	DR,X		; THOSE PLAYERS ORDERS
	CMP	#$01
	BNE	AZ1
	LDA	FLAGR,X
	CMP	#$00
	BNE	AZ4
	INC	XX,X
	JMP	AZ4
AZ1	LDA	DL,X
	CMP	#$01
	BNE	AZ2
	LDA	FLAGL,X
	CMP	#$00
	BNE	AZ4
	DEC	XX,X
	JMP	AZ4
AZ2	LDA	DU,X
	CMP	#$01
	BNE	AZ3
	LDA	FLAGU,X
	CMP	#$00
	BNE	AZ4
	DEC	YY,X
	JMP	AZ4
AZ3	LDA	DD,X
	CMP	#$01
	BNE	AZ4
	LDA	FLAGD,X
	CMP	#$00
	BNE	AZ4
	INC	YY,X
AZ4	RTS
*SUBROUTINE PLOTSET1
PLTST1	LDA	XX,X
	STA	HPOSP1
	LDA	YY,X
	STA	SHPML
	LDA	#<PDATA
	CLC
	ADC	#$05		; PLAYER IS 1.25K BEYOND START
	STA	SHPMH
	LDY	POINT1
	LDA	SHPLO,Y		; POINTER TO CORRECT SHAPE
	STA	SHPL
	LDA	#<SHAPES
	STA	SHPH
	LDX	#$01
	LDA	TEMPL,X
	STA	SHPMOL
	LDA	TEMPH,X
	STA	SHPMOH
	JSR	PLOT
	RTS
*SUBROUTINE PLOTSET2
PLTST2	LDA	XX,X
	STA	HPOSP2
	LDA	YY,X
	STA	SHPML
	LDA	#<PDATA
	CLC
	ADC	#$06		; PLAYER IS 1.5K BEYOND START
	STA	SHPMH
	LDY	POINT2
	LDA	SHPLO,Y		; POINTER TO CORRECT SHAPE
	STA	SHPL
	LDA	#<SHAPES
	STA	SHPH
	LDX	#$02
	LDA	TEMPL,X
	STA	SHPMOL
	LDA	TEMPH,X
	STA	SHPMOH
	JSR	PLOT
	RTS
*SUBROUTINE PLOTSET3
PLTST3	LDA	XX,X
	STA	HPOSP3
	LDA	YY,X
	STA	SHPML
	LDA	#<PDATA
	CLC
	ADC	#$07		; PLAYER IS 1.75K BEYOND START
	STA	SHPMH
	LDY	POINT3
	LDA	SHPLO,Y		; POINTER TO CORRECT SHAPE
	STA	SHPL
	LDA	#<SHAPES
	STA	SHPH
	LDX	#$03
	LDA	TEMPL,X
	STA	SHPMOL
	LDA	TEMPH,X
	STA	SHPMOH
	JSR	PLOT
	RTS
CORECT	LDA	DR,X
	BEQ	BA2
BA11	LDA	FLAGR,X
	BNE	BA12
	JSR	AUTOP
	JMP	FF
BA12	LDA	FLAGU,X
	BNE	BA13
	DEC	YY,X
	LDA	#$00
	STA	DR,X
	LDA	#$01
	STA	DU,X
	JMP	FF
BA13	LDA	FLAGD,X
	BNE	BA14
	INC	YY,X
	LDA	#$00
	STA	DR,X
	LDA	#$01
	STA	DD,X
BA14	JMP	FF
BA2	LDA	DL,X
	BEQ	BA3
BA21	LDA	FLAGL,X
	BNE	BA22
	JSR	AUTOP
	JMP	FF
BA22	LDA	FLAGU,X
	BNE	BA23
	DEC	YY,X
	LDA	#$00
	STA	DL,X
	LDA	#$01
	STA	DU,X
	JMP	FF
BA23	LDA	FLAGR,X
	BNE	BA24
	INC	YY,X
	LDA	#$00
	STA	DL,X
	LDA	#$01
	STA	DD,X
BA24	JMP	FF
BA3	LDA	DU,X
	BEQ	BA4
BA31	LDA	FLAGU,X
	BNE	BA32
	JSR	AUTOP
	JMP	FF
BA32	LDA	FLAGL,X
	BNE	BA33
	DEC	XX,X
	LDA	#$00
	STA	DU,X
	LDA	#$01
	STA	DL,X
	JMP	FF
BA33	LDA	FLAGR,X
	CMP	#$01
	BEQ	BA34
	INC	XX,X
	LDA	#$00
	STA	DU,X
	LDA	#$01
	STA	DR,X
BA34	JMP	FF
BA4	LDA	DD,X
	BNE	BA41
	JMP	FF
BA41	LDA	FLAGD,X
	BNE	BA42
	JSR	AUTOP
	JMP	FF
BA42	LDA	FLAGL,X
	BNE	BA43
	DEC	XX,X
	LDA	#$00
	STA	DD,X
	LDA	#$01
	STA	DL,X
	JMP	FF
BA43	LDA	FLAGR,X
	CMP	#$01
	BEQ	FF
	INC	XX,X
	LDA	#$00
	STA	DD,X
	LDA	#$01
	STA	DR,X
FF	RTS
PLACE	LDA	XB		; PLAYER #0 ON LEFT SIDE SCREEN?
	CMP	#$0A
	BGE	BB3
	LDA	YB		; PLAYER #0 ON TOP HALF SCREEN?
	CMP	#$06
	BGE	BB2
	LDA	#$B8		; PUT PLAYER AT BLOCK 17,7 (164,148)
	STA	XX,Y
	LDA	#$94
	STA	YY,Y
	LDA	#$00
	STA	DU,Y
	STA	DD,Y
	STA	DR,Y
	STA	DL,Y
	LDA	RANDOM		; VARY THE START LEFT OR RT
	CMP	#$80
	BL	BB15
	LDA	#$01
	STA	DR,Y
	STA	FLAGD,Y
	JMP	EXIT
BB15	LDA	#$01
	STA	DL,Y
	STA	FLAGD,Y
	JMP	EXIT
BB2	LDA	#$A8		; PUT PLAYER AT BLOCK 15,2 (168,68)
	STA	XX,Y
	LDA	#$44
	STA	YY,Y
	LDA	#$00
	STA	DU,Y
	STA	DR,Y
	STA	DL,Y
	LDA	#$01
	STA	DD,Y
	STA	FLAGR,Y
	JMP	EXIT
BB3	LDA	YB		; IS PLAYER ON TOP HALF SCREEN?
	CMP	#$06
	BGE	BB4
	LDA	#$40		; PUT PLAYER AT BLOCK 2,7 (64,148)
	STA	XX,Y
	LDA	#$94
	STA	YY,Y
	LDA	#$00
	STA	DU,Y
	STA	DD,Y
	STA	DL,Y
	STA	DR,Y
	LDA	RANDOM		; VARY THE START LEFT OR RT
	CMP	#$80
	BL	BB35
	LDA	#$01
	STA	DL,Y
	JMP	EXIT
BB35	LDA	#$01
	STA	DR,Y
	STA	FLAGD,Y
	JMP	EXIT
BB4	LDA	#$50		; PUT PLAYER AT BLOCK 4,2 (80,68)
	STA	XX,Y
	LDA	#$44
	STA	YY,Y
	LDA	#$00
	STA	DL,Y
	STA	DR,Y
	STA	DU,Y
	LDA	#$01
	STA	DD,Y
EXIT	RTS
