; *********************
; *     ROCKS!        *
; *                   *
; *  BY DOUGLAS ENGEL *
; *                   *
; *********************
;
; OS EQUATES
;
ATRACT	= $4D
AUDC1	= $D201
AUDC2	= $D203
AUDC3	= $D205
AUDC4	= $D207
AUDCTL	= $D208
AUDF1	= $D200
AUDF2	= $D202
AUDF3	= $D204
AUDF4	= $D206
CH	= $02FC
CHBAS	= $02F4
COLOR0	= $02C4
COLOR4	= $02C8
COLPF0	= $D016
COLPM0	= $D012
COLRSH	= $4F
CONSOL	= $D01F
DRKMSK	= $4E
GRACTL	= $D01D
HITCLR	= $D01E
HPOSP0	= $D000
HPOSP1	= $D001
HPOSP2	= $D002
HPOSP3	= $D003
HPOSM0	= $D004
HSCROL	= $D404
KBCODE	= $D209
M2PF	= $D002
M2PL	= $D00A
NMIEN	= $D40E
P0PF	= $D004
P0PL	= $D00C
P1PF	= $D005
P1PL	= $D00D
P3PL	= $D00F
PCOLR0	= $02C0
PMBASE	= $D407
PRIOR	= $D01B
RANDOM	= $D20A
RUNAD	= $02E0
SDLSTL	= $0230
SDMCTL	= $022F
SETVBV	= $E45C
SIZEP0	= $D008
SKCTL	= $D20F
STICK0	= $0278
STRIG0	= $0284
VDSLST	= $0200
VKEYBD	= $0208
WSYNC	= $D40A
XITVBV	= $E462
;
; PROGRAM EQUATES
;
MISSLES	= PMTABL+768 	;PM missles
PLAYER0	= PMTABL+1024 	;PM players 0 & 1
PLAYER1	= PMTABL+1280
PMSATS	= PMTABL+1918 	;PM for sats
PMTABL	= $5000 	;Loc. of table
PMZAP	= PMSATS-180 	;PM for zap
SCOREBOARD	= SCREEN+$08 	;Print score here
SCREEN	= $3000 	;Screen mem.
;
; PROGRAM VARIABLES
;
	*= PMTABL
ACCOUNT	*= *+1 	;Velocity counter
ALT	*= *+1 	;1/30 sec counter
ANIMATE	*= *+1 	;Animation counter
ANIPTR	*= *+1 	;Offset to frame values
BEAMDLAY	*= *+1 	;Delay counter
BEAMFLG	*= *+1 	;Flags beam on
BEAMPOS	*= *+1 	;Beam length
BLEEP	*= *+1 	;Decay
BLINK	*= *+1 	;Light counter
BLINK1	*= *+1 	;Ditto
COMPLETED	*= *+1 	;Level done flag
COWNTER	*= *+1 	;Explosion counter
DIGIT	*= *+1 	;Current score dig.
DOOM	*= *+1 	;Doom flag
EMPTY	*= *+1 	;No fuel flag
ENDCNTR	*= *+1 	;Doom counter
ETC.	*= *+1 	;Misc. sound flag
EXPLOSION	*= *+1 	;Flag
FD	*= *+1 	;Flame dir.
FLASHME	*= *+1 	;Light counter
FLIP	*= *+1 	;Direction mask
FUEL	*= *+1 	;Amount of fuel
FUELMTR	*= *+1 	;Offset to needle
FUELUSE	*= *+1 	;Rate of use
GRAVITY	*= *+1 	;Counter for veloc. change
G.O	*= *+1 	;Game over flag
HOLDA	*= *+1 	;Temp accumulator
HOLDX	*= *+1 	;Temp index reg.
HPOSME	*= *+1 	;My horiz.
HPOSSAT	*= *+1 	;Sat horiz.
KONSOL	*= *+1 	;Former consol val.
LANDFLAG	*= *+1 	;Flag landing
LOADED	*= *+1 	;Flag  loaded
MISS	*= *+1 	;M2PF shadow (sort of)
MULTIPLY	*= *+1 	;Multiplier
NEWLEV	*= *+1 	;Next level flag
NEWSC	*= *+1 	;Flag show score
PAUSED	*= *+1 	;Pause flag
POWNTER	*= *+1 	;Explosion counter
RADCOUNT	*= *+1 	;Rate of rad increase
RADS	*= *+1 	;Amount of rads
RADSMTR	*= *+1 	;Offset to needle
RAND1	*= *+1 	;Saved random #
RESET	*= *+1 	;Set up me flag
ROAR	*= *+1 	;Rocket decay
SAT?	*= *+1 	;Active sat flag
SATCNT	*= *+1 	;Time between sats counter
SATCNT1	*= *+1 	;Sat move counter
SATCOLR	*= *+1 	;Color of sat
SATDIR	*= *+1 	;Move direction
SATEXP	*= *+1 	;Sat explosion flag
SATFRAME	*= *+1 	;Sat explosion counter
SATSPD	*= *+1 	;Speed of sat
SKY	*= *+1 	;Where fall happens
STARCNT	*= *+1 	;Star move counter
STROBE	*= *+1 	;Light counter
SUPER	*= *+1 	;Super sat flag
TEMPA	*= *+1 	;Temporary
TEMPB	*= *+1 	;Temporary
VELOCITY	*= *+1 	;Fall veloc.
VOL	*= *+1 	;Decay
VOL4	*= *+1 	;Decay
VPOSME	*= *+1 	;My vert.
WAITCNTR	*= *+1 	;Message delay
WAITING	*= *+1 	;Message flag
ZAPCNT	*= *+1 	;Zap counter
ZAPFLAG	*= *+1 	;Flags zap
;
; ZERO PAGE EQUATES
;
LINENO	= $CA 	;Current DL mode line
SHAPEA	= $E0 	;Player 0 bit pattern
SHAPEB	= $E2 	;same for Player 1
ZEROPA	= $CC 	;General usage
ZEROPB	= $CE 	;same here
;
; PROGRAM
;
	*= $2000
START	LDA #$03 	;Init serial port
	STA SKCTL
	LDA # <INKEY 	;Steal KB vector
	STA VKEYBD
	LDA # >INKEY
	STA VKEYBD+1
	LDA #$1D 	;Star color
	STA PCOLR0+3
	LDA #$00 	;Init sound
	STA AUDCTL
;
; Move portion of chars
;
	STA ZEROPA 	;Clear these
	STA ZEROPB
	LDA CHBAS 	;Point to chars
	STA ZEROPA+1
	LDA # >CHARS 	;Point to mine
	STA ZEROPB+1
	LDY #$40 	;16 already defined
	LDX #$01
CHLOOP	LDA (ZEROPA),Y 	;Move 'em
	STA (ZEROPB),Y
	INY 
	BNE CHLOOP
	INC ZEROPA+1
	INC ZEROPB+1
	DEX 
	BPL CHLOOP
	LDA # >CHARS 	;Tell OS where they went
	STA CHBAS
;
; Draw title
;
	LDY #$00
	LDX #$00
BITBLT	LDA BITS,X 	;Grab title byte
	STA HOLDA 	;Save it
	STX HOLDX 	;Save x
	LDX #$07 	;Rotate byte 8 times
SHFT	LDA HOLDA
	ASL A
	STA HOLDA
	BCC CC 	;See if 0 falls out
	LDA #$49 	;No, load Rock char
	BNE PLOT 	;Always
CC	LDA #$00 	;Space char
PLOT	STA TITLE,Y 	;Store in screen mem.
	INY 
	DEX 
	BPL SHFT
	LDX HOLDX 	;Get next byte
	INX 
	CPX #$19
	BNE BITBLT 	;Go back until done
SETUP	LDA #$40 	;DLI off
	STA NMIEN
	LDA #$00 	;DMA off
	STA SDMCTL
	LDY # <XITVBV 	;VBI off
	LDX # >XITVBV
	LDA #$07
	JSR SETVBV
	LDA # <DLIST1 	;New DL vectors
	STA SDLSTL
	LDA # >DLIST1
	STA SDLSTL+1
CDLI1	LDA # <DLI1 	;New DLI vector
	STA VDSLST
	LDA # >DLI1
	STA VDSLST+1
	LDA #$C0 	;DLI on
	STA NMIEN
	JSR INITPM 	;Clear PM regs.
	JSR SILENT 	;No sound
	STA ATRACT 	;No attract
	STA COLOR0+4 	;Black
	LDA #$02
	STA COLOR0 	;Dk grey
	LDA #$04
	STA COLOR0+1 	;Grey
	LDA #$06
	STA COLOR0+2 	;Lt grey
	LDA #$86
	STA COLOR0+3 	;Blue
	LDA SLEVEL 	;Use start level
	STA LEVEL
	LDA #$22 	;Screen DMA on
	STA SDMCTL
;
INPUT	LDA CONSOL 	;Consol input
	CMP #$07 	;No key, try again
	BEQ INPUT
	STA ATRACT 	;Off
SEL	CMP #$05 	;Select?
	BNE STA
	INC LEVEL 	;Update level
	LDA LEVEL
	CMP #$1A 	;Insure wrap at 10
	BNE DEBOUNCE
	LDA #$10
	STA LEVEL
	BNE DEBOUNCE 	;Always
STA	CMP #$06 	;Start?
	BNE INPUT
LG	LDA CONSOL 	;Wait for release
	CMP #$07
	BNE LG
	BEQ UNPRESS 	;Always
DEBOUNCE	STA SLEVEL 	;New start level
	LDX #$40 	;Debounce delay
	LDY #$00
ASIA	INY 
	BNE ASIA
	DEX 
	BNE ASIA
BOINK	LDX #$70 	;Wait for release
	LDY #$00
PRESSED	LDA TEMPA 	;Waste time
	INY 
	BNE PRESSED
	LDA CONSOL 	;Let go, go back
	CMP #$07
	BEQ INPUT
	DEX 
	BNE PRESSED
	JMP INPUT 	;go back now
;
UNPRESS	LDA #$00
	STA SDMCTL
	STA TOTAL 	;Levels done=0
	STA ATRACT 	;Off
CLRSCR	LDX #$07 	;Put ATASCII 0's in score
	LDA #$10
GEM	STA SCORE,X
	DEX 
	BPL GEM
	LDA #$13 	;ATASCII 3 ships
	STA SHIPS
	LDA SLEVEL 	;Start at start level
	STA LEVEL
	STA PAINT 	;Planet color mask
;
INIT	LDA # >PMTABL 	;Clear all those vars
	LDY # <PMTABL
	LDX #$01
	JSR CLEER 	;Use this routine
	JSR SILENT 	;Sound off
	JSR INITPM 	;Reset PM regs.
	LDA #$05 	;Make sure that we
	STA CHARS+641 	;Start with original
	STA CHARS+646 	;Char shapes
	LDA #$A8
	STA CHARS+677
	LDA #$15
	STA CANISTERS
	STA PAUSED 	;Start paused
ACROSS	LDA #$03 	;PM on
	STA GRACTL
	LDA # >PMTABL 	;Tell OS where pm is
	STA PMBASE
	LDA #$00 	;Clear scroll tables
	LDX #$A7
CLR	STA SCRLST,X
	DEX 
	BPL CLR
	LDA # >MISSLES 	;Clear PM area
	LDY # <MISSLES
	LDX #$05
	JSR CLEER
	LDA # >MISSLES 	;Put stars in missile 3
	STA ZEROPA+1
	LDA # <MISSLES
	STA ZEROPA
	LDA #$29 	;Starting line
SPOT	TAY 
	LDA #$80 	;Put $80
	STA (ZEROPA),Y 	; on 2 consecutive
	INC ZEROPA 	; bytes
	STA (ZEROPA),Y
	DEC ZEROPA
	TYA 
	CLC 
	ADC #$08 	;Then skip 8 bytes
	BCC SPOT 	; and put in more
;
	LDX #$D7 	;Draw guage needles
NEEDLE	LDA MISSLES,X
	ORA #$05 	;Missiles 0 & 1
	STA MISSLES,X
	INX 
	CPX #$E0
	BNE NEEDLE
;
	LDX #$0A 	;Create random distances
STARS	LDA RANDOM 	; between the horiz.
	BEQ STARS 	; positions of the consecutive
	STA MPOS,X 	; star bits.
OFS	LDA RANDOM
	BEQ OFS
	STA OFFSET,X
	DEX 
	BPL STARS
;
FIELDCLR	LDA # >SCREEN 	;Clear asteroid field
	LDY # <SCREEN
	LDX #$09
	JSR CLEER
;
; Put rock chars on screen
;
	LDX #$02
	LDA # >SCREEN+768 	;Start location
	STA ZEROPA+1
ROCKS	LDA #$00
	STA ZEROPA 	;Start at 0
ASTRO	JSR R16 	;Random #
	CMP #$06 	;<6?
	BCC DOUBLE 	;Yes, make big rock
	CLC 
	ADC #$40 	;Offset to char code
	LDY #$00
	STA (ZEROPA),Y 	;Put in char
	JSR R16 	;Find spacing for next rock
	STA TEMPA
	JSR GETLEV 	;Based on level
	STA TEMPB
	LDA #$0D 	;By subtracting level from 14
	SEC 
	SBC TEMPB
	CLC 
	ADC TEMPA 	; and adding random #
	CLC 
	ADC ZEROPA 	;Point to new spot
	BCS COMPLE 	;Done at page end
	STA ZEROPA
	BCC ASTRO 	;Always
DOUBLE	STA HOLDA 	;Save
	LDA ZEROPA 	;See if near page end
	CMP #$FE
	BCS ASTRO 	;Too close try again
	LDA HOLDA 	;Get char code
	AND #$FE 	;Make even
	ADC #$40 	;Char offset
	LDY #$00
	STA (ZEROPA),Y 	;Put in mem
	CLC 
	ADC #$01 	;Next char
	INY 
	STA (ZEROPA),Y 	; goes in next byte
	JSR R16 	;Random spacing by level again.
	STA TEMPA
	JSR GETLEV
	STA TEMPB
	LDA #$0E
	SEC 
	SBC TEMPB
	CLC 
	ADC TEMPA
	CLC 
	ADC ZEROPA
	BCS COMPLE
	STA ZEROPA
	BCC ASTRO
COMPLE	INC ZEROPA+1 	;Point to next page
	INC ZEROPA+1
	DEX 
	BPL ROCKS 	;Do more
;
; Put fleet on screen
	LDA # >SCREEN+256 	;Set addr.
	STA ZEROPA+1
	LDA # <SCREEN+256
	STA ZEROPA
PUTSHP	LDY #$00 	;Set index
	LDA #$D0 	;Rear char code
	STA (ZEROPA),Y 	;Place
	INY  	;Next byte
	LDA #$51 	;Engines char
	STA (ZEROPA),Y 	;Place
	INY  	;Next
	JSR R07 	;Random # <=7 but >3
	CLC 
	ADC #$03
	STA HOLDA
	LDA #$52 	;Pod back char
SHIP	STA (ZEROPA),Y
	INY  	;Next
	CPY HOLDA 	;Done enough?
	BNE SHIP
	LDA #$53 	;Bridge char
	STA (ZEROPA),Y
	INY  	;Next
	LDA #$D4 	;Nose char
	STA (ZEROPA),Y
	INY 
	TYA 
	CLC 
	ADC ZEROPA 	;Start addr is now at
	STA ZEROPA 	;Front of ship
	JSR R16 	;Spacing = 2*level+Rnd
	ADC LEVEL
	ADC LEVEL
	ADC #$20 	;+ $20
	CLC 
	ADC ZEROPA 	;Add to start
	BCS OVER 	;Page done?
	STA ZEROPA 	;See if too close to
	CMP #$F0 	;Page boundary
	BCC PUTSHP
;
; Copy for scroll wrap
;
OVER	LDX #$03 	;# of pages
	LDA # <SCREEN+256 	Set up
	STA ZEROPA
	LDA # >SCREEN+256
	STA ZEROPA+1
WRAP	LDY #$00 	;# of bytes moved
COPY	LDA (ZEROPA),Y 	;Get one
	INC ZEROPA+1 	;Put on next page
	STA (ZEROPA),Y
	DEC ZEROPA+1 	;Point to ogir. page
	INY 
	CPY #$30
	BNE COPY 	;Done?
	INC ZEROPA+1 	;Skip a page
	INC ZEROPA+1
	DEX  	;Done?
	BPL WRAP
;
;Random scroll directions and speeds
;
	LDA #$02
	STA SCRLST+1 	;Fleet dir
	LDA #$03
	STA LIMIT+1 	;Fleet speed
	LDX #$04
SETDIR	LDA RANDOM 	;Random rock dir
	AND #$03
	BEQ SETDIR 	;no 0's
	CMP #$03 	;no 3's
	BEQ SETDIR
	STA SCRLST,X
	CMP #$01 	;Set counter
	BNE RD 	; to right value
	LDA #$04 	; for left
	STA CURR,X
	BNE ZC 	;Always
RD	LDA #$00 	;Also for right
	STA CURR,X
ZC	LDA #$00 	;Set 0 color clocks
	STA COLCKS,X
	INX 
	CPX #$0B 	;Done?
	BNE SETDIR
SPEED	LDX #$04 	;Set 5 (speed) counters
SETSPD	JSR R16 	;Random # 1-16
	ADC #$01
	STA LIMIT,X 	;Store it
	LDA RANDOM 	;Bias the speeds
	CMP #$30 	; if <$30
	BCC CONTIN
	AND #$03 	;High speed
	STA LIMIT,X
CONTIN	INX 
	CPX #$0B 	;Done?
	BNE SETSPD
;
	LDA # <DLIST 	;New DL vector
	STA SDLSTL
	LDA # >DLIST
	STA SDLSTL+1
	JSR OLDC 	;Set color table
CDLI	LDA # <DLI 	;New DLI vector
	STA VDSLST
	LDA # >DLI
	STA VDSLST+1
	LDY # <VBLANK 	;New VBI vector
	LDX # >VBLANK
	LDA #$07
	JSR SETVBV
FAT	LDA #$3F 	;Wide screen DMA
	STA SDMCTL
	BNE RESETME 	;Always
;
; PROGRAM LOOP
;
LOOP	LDA RESET 	;Reset flag?
	BEQ SPCLKEYS 	;No, check consol
	BNE RESETME 	;Yes, reset
SPCLKEYS	LDA CONSOL 	;Get consol
	CMP #$07 	;Any pressed
	BNE AAAAAC 	;Yes, go ahead
	LDA KONSOL 	;No, get former
	LDX #$00
	STX KONSOL 	;Clear it
SEL1	CMP #$05 	;Select?
	BNE STA1
	JMP SETUP 	;Go to title screen
STA1	CMP #$06 	;Start?
	BNE AAAAAB
	JMP UNPRESS 	;Restart game
AAAAAC	STA KONSOL 	;Save Console in former
AAAAAB	LDA NEWLEV 	;Check for new level
	BEQ LOOP
	JMP INIT 	;Start new level
;
RESETME	JSR BEAMOFF 	;No beam
	JSR SILENT 	;No sound
	LDA #$30 	;Init my positions
	STA VPOSME
	LDA #$7E
	STA HPOSME
	JSR CLRME 	;Erase me
	LDA EXPLOSION 	;See if I exploded
	BEQ RS232 	;No? skip this
SUBTRACT	DEC SHIPS 	;Another on bites the dust
	LDA SHIPS 	;Any left?
	CMP #$10
	BNE RS232 	;Yes skip this
	LDX #$12 	;Game over message and flag
	JSR DLPRINT
	LDA #$FF
	STA G.O
RS232	LDA #$57 	;Reset all variables
	STA RADSMTR
	LDA #$98
	STA FUELMTR
	LDA #$7D
	STA SKY
	LDA #$6C
	STA PCOLR0+1
	LDA #$95
	STA PCOLR0
	JSR FLAGS 	;Reset landed flags
	STA POWNTER
	STA EXPLOSION
	STA GRAVITY
	STA EMPTY
	STA ROAR
	STA ETC.
	STA RESET
	STA COMPLETED
	LDA #$FF 	;Fill 'er up
	STA FUEL
	LDA #$01
	STA FLIP
	STA NEWSC 	;Flag new score
	LDA LEVEL 	;Get right ATASCII value
	CLC  	; for displaying level
	ADC #$C0
	STA PLEVEL
	LDA LEVEL 	;Find multiplier
	CMP #$19 	;If level<9 then
	BNE ONEDIGIT 	;Mult. <10
	LDA #$D1 	;Mult must be 10
	STA PMULT 	;Show "1"
	LDA #$D0
	STA PMULT+1 	;Show "0"
	BNE THX1138 	;Always
ONEDIGIT	CLC  	;Mult. = level+1
	ADC #$C1 	;+$C0 for correct ATASCII
	STA PMULT+1
	LDA #$D0
	STA PMULT 	;" " in second digit
THX1138	LDA G.O 	;See if game over
	BNE NEO
	LDX #$06 	;Yes, show message
	JSR DLPRINT
	LDA #$00
	STA WAITING
	LDA #$FF 	;Permanent pause
	STA PAUSED
	LDA #$B4
	STA WAITCNTR
NEO	JSR SHOW 	;Show me
	JMP LOOP 	;Back to main
;
; SUBROUTINE LIBRARY
;
; routine to find score
;
MATH	LDY MULTIPLY 	;# of iterations
	CLD 
STEP	LDX DIGIT 	;Digit to operate on
ADDNUM	LDA SCORE,X 	;Current val
	CLC 
	ADC #$01 	;+1 for each iteration
	CMP #$1A 	;Over 10?
	BCS NEXTPLACE 	;Yes, next digit
FIN	STA SCORE,X 	;New val
	DEY  	;Next
	BNE STEP 	;Another iteration
	LDA #$FF
	STA NEWSC 	;Flag score
	RTS  	;Done!
NEXTPLACE	CLC  	;Sub 9 from val
	SBC #$09
	STA SCORE,X 	;Save
	DEX  	;Next higher digit
	BPL ADDNUM 	;Always
EGG	JMP LOOP 	;Easter egg could go here
;
;Routine to clear me form PM table
;
CLRME	LDA # >PLAYER0
	LDY # <PLAYER0
	LDX #$02
	JSR CLEER
	RTS 
;
; PM register clear routine
;
INITPM	LDX #$11 	;17 registers
INITP	LDA #$00 	;Entry point if other than 17
IPM	STA HPOSP0,X
	DEX 
	BPL IPM
	RTS 
;
; Routine for color attracting
;
MIXUP	EOR COLRSH
	AND DRKMSK
	RTS 
;
; Routint to initialize color tables
;
OLDC	LDX #$77
SETCOLR	LDA COLTAB,X 	;Orig color
	STA ACOLTAB,X 	;Attract table
	STA DCOLTAB,X 	;Display table
	CPX #$46
	BEQ CHANGE 	;Test to see if color in question
	CPX #$2E
	BEQ CHANGE 	; is a planet color
	CPX #$16
	BEQ CHANGE 	; and alter it
	DEX 
	BPL SETCOLR 	;Done?
	RTS  	;Return
CHANGE	LDY #$0A 	;Change next 11
SILLY	LDA PAINT 	;Get mask
	AND #$0F 	;Make lower bits high
	ASL A
	ASL A
	ASL A
	ASL A
	EOR PAINT 	;Scramble it
	ASL A 	;Scramble more
	AND #$F7 	;Mask high intensity
	EOR COLTAB,X 	;Use it to scramble colors
	STA ACOLTAB,X
	STA DCOLTAB,X
	DEX 
	DEY 
	BPL SILLY 	;All done?
	BMI SETCOLR 	;NO, go back
;
; Routine to set my PM shape pointers
;
SETSHAPE	LDA # <SHAPE1A 	;Player 0
	STA SHAPEA
	LDA # >SHAPE1A
	STA SHAPEA+1
	LDA # <SHAPE1B 	;Player 1
	STA SHAPEB
	LDA # >SHAPE1B
	STA SHAPEB+1
	RTS 
;
; Routine to put flames on ship
;
BURN	LDA RANDOM 	;Bits for top and bottom
	AND #$18 	;Flames here
PUT	PHA  	;Entry point from side routine
	ORA PLAYER0,X 	;"OR" into player 0
	STA PLAYER0,X
	PLA 
	ORA PLAYER1,X 	;Ditto
	STA PLAYER1,X
	INC FUELUSE 	;Rockets use fuel
	INC FUELUSE
	RTS 
;
BURN1	LDA RANDOM 	;Bits for side flames
	LDY FD 	;Mov!ng left or right	;!!!!!!!! SPECIAL CHARS !!!!!!!!
	CPY #$01
	BNE RF 	;Right. skip this
	AND #$03 	;Mask bits
	JMP PUT 	;Show them
RF	AND #$C0 	;Mask bits
	JMP PUT 	;Show them
;
; Routine to show me
;
SHOW	LDA HPOSME 	;Set horiz. regs.
	STA HPOSP0
	STA HPOSP1
	CLC 
	ADC #$03 	;+3 for beam horiz.
	STA HPOSM0+2
	LDX VPOSME 	;My vert
	DEX 
	LDA #$00
	STA PLAYER0,X 	;Erase flames above
	STA PLAYER1,X
	INX 
	LDY #$00
LPRINT	LDA (SHAPEA),Y 	;Move shape data
	STA PLAYER0,X
	LDA (SHAPEB),Y 	;For both players
	STA PLAYER1,X
	INX 
	INY 
	CPY #$0C 	;12 bytes?
	BNE LPRINT
	LDA NEWSC 	;See if score updated
	BEQ AAAAAD 	;No, skip this
	LDX #$07 	;Yes, Put score in screen mem
RMK	LDA SCORE,X
	STA SCOREBOARD,X
	DEX 
	BPL RMK
	LDA #$00 	;Clear flag
	STA NEWSC
AAAAAD	RTS  	;Return
;
; Routine to display messages
; by altering Display list
;
DLPRINT	LDY #$00 	;Counter
LLLLLL	LDA DLTABL,X 	;New DL val
	STA DLIST+40,Y 	;Store
	INX 
	INY 
	CPY #$06 	;6 vals altered
	BNE LLLLLL 	;No, do,it again
	RTS 
;
; Routine to clear satellites form PM table
;
CSAT	LDA #$00
	LDX #$19 	;Zero 64 bytes
RUB	STA PMSATS-10,X
	DEX 
	BPL RUB
	RTS 
;
; General purpose clearing routine
;
CLEER	STA ZEROPA+1 	;Save high byte
	STY ZEROPA 	;Save low byte
	LDA #$00 	;X reg. is # of pages
	TAY 
CLEAN	STA (ZEROPA),Y 	;Clear
	INY 
	BNE CLEAN
	INC ZEROPA+1
	DEX 
	BNE CLEAN 	;Do until done
	RTS 
;
; Routine to mirror bits in a byte
;
MYRNA	STA HOLDA 	;Entry point for random mirror
	JSR R01
	BNE RET 	;Don't mirror
	LDA HOLDA
MIRROR	STA HOLDA 	;Entry point for mirror always
	STX HOLDX 	;Save x
	LDX #$07 	;8 bits
MM	ROL A 	;Rotate bit in carry
	ROR HOLDA 	;Rotate out reverse
	DEX 
	BPL MM 	;Do all 8
	LDX HOLDX 	;Restore X & A
RET	LDA HOLDA
	RTS  	;Done!
;
; Routine to turn off sound
;
SILENT	LDA #$00 	;No explanation needed
	LDX #$07
HUH	STA AUDC1,X
	DEX 
	BPL HUH
	RTS 
;
; Routine to get actual level
;
GETLEV	LDA LEVEL
	AND #$0F
	RTS 
;
; Routine to erase beam
;
BEAMOFF	LDX VPOSME 	;Beam starts at me+2
	INX 
	INX 
	LDY #$23 	;Erase this much
OFFLOOP	LDA #$CF
	AND MISSLES,X
	STA MISSLES,X
	DEX 
	DEY 
	BNE OFFLOOP 	;Do it all
	LDA #$00 	;Clear all beam flags
	STA BEAMFLG
	STA BEAMDLAY
	STA BEAMPOS
	STA LOADED
	STA AUDC4
	JSR SETSHAPE 	;Set original shape
	RTS 
;
; Random number routines
;
R01	LDA RANDOM
	AND #$01
	RTS 
R07	LDA RANDOM
	AND #$07
	RTS 
R16	LDA RANDOM
	AND #$0F
	RTS 
;
; Landing flag clearing routine
;
FLAGS	LDA #$00
	STA LANDFLAG
	STA ACCOUNT
	STA ANIPTR
	STA ANIMATE
	RTS 
;
; DISPLAY LIST INTERRUPT ROUTINE
;         FOR GAME SCREEN
;
DLI	PHA  	;Save 6502 regs.
	TXA 
	PHA 
	LDX LINENO 	;Current mode line
	STA WSYNC
	LDA DCOLTAB+96,X 	;Background color
	STA COLPF0+4
	LDA CURR,X 	;Current HSCROL val
	STA HSCROL
	STA WSYNC
	LDA DCOLTAB+24,X 	;Color1
	STA COLPF0+1
	LDA DCOLTAB+48,X 	;Color2
	STA COLPF0+2
	LDA DCOLTAB+72,X 	;Color3
	STA COLPF0+3
	LDA DCOLTAB,X 	;Color0
	STA COLPF0
	LDA MPOS,X 	;Stars on this line?
	BEQ NOSTAR 	;No? skip this
	STA WSYNC
	STA HPOSM0+3 	;Horiz. pos. of star
	LDA MPOS,X 	;Find pos. of star next line
	CLC 
	ADC OFFSET,X
	STA WSYNC 	;Wait for next line
NOSTAR	STA HPOSM0+3 	;Save pos for it
	INC LINENO
	LDA PRITAB,X 	;Set priority this line
	STA WSYNC
	STA PRIOR
	CPX #$02 	;Is it line #2?
	BNE NADA 	;No, skip
	LDA M2PF 	;Hold collisions for line
	STA MISS
NADA	CPX #$0B 	;Line 11 yet?
	BNE NAY 	;No, skip
	LDA SATCOLR 	;Change color for sats
	JSR MIXUP 	;Attract them first
	STA COLPM0+3
NAY	PLA  	;Restore 6502
	TAX 
	PLA 
	RTI 
;
; DISPLAY LIST INTERRUPT ROUTINE
;         FOR TITLE SCREEN
;
DLI1	PHA  	;Save
	LDA #$36 	;Red
	JSR MIXUP 	;Attract
	STA COLPF0 	;Color0
	PLA  	;Restore
	RTI 
;
; KEYBOARD INTERRUPT ROUTINE
;
INKEY	LDA KBCODE 	;Key code (A saved by OS)
	STA CH 	;Save
	PLA  	;Restore
	RTI 
;
; COMMON LABELS
;
ACOLTAB	= $3EC8
BITS	= $46D8
CANISTERS	= $3BB7
CHARS	= $4000
COLCKS	= $3E08
COLTAB	= $3E50
CURR	= $3DF0
DCOLTAB	= $3F40
DLIST	= $3D30
DLIST1	= $3D88
DLTABL	= $3D70
LEVEL	= $3CC9
LIMIT	= $3DD8
MPOS	= $3E20
OFFSET	= $3E38
PAINT	= $4761
PLEVEL	= $3CDF
PMULT	= $3CF9
PRITAB	= $4709
SCORE	= $4757
SCRLST	= $3DA8
SHAPE1A	= $4400
SHAPE1B	= $440C
SHIPS	= $3BDA
SLEVEL	= $475F
TITLE	= $3BE0
TOTAL	= $4760
VBLANK	= $261E
	.END 
