// ALSO CHECK OUT .CameraSubPix_Add in LEVEL CODE

//GOES IN LEVEL CODE 1D3


!RAM =		$7FC210 (Change this in Init.asm and also in tank.asm (boss sprite) if changed here)
;; 4 bytes

!HDMARAM =	$7FC200 (Change this in Init.asm if changed here)
;; 10 bytes

; parallax start
	REP #$20
	LDA #$0F02
	STA $4350
	SEP #$20
	LDA #$00
	STA $4352
	LDA #$A0
	STA $4353
	LDA #$7F
	STA $4354
	LDA #$20
	TSB $0D9F
	REP #$20
	LDA $1466
	STA !HDMARAM+$1
	STA !HDMARAM+$3+$3+$3+$1
	LSR
	STA !HDMARAM+$3+$3+$1
	STA !HDMARAM+$3+$1
	SEP #$20
; parallax end

	LDA $9D
	ORA $13D4
	BEQ +
	RTS
+	LDA #$70
	STA $13E4
	LDA !RAM+$2
	BEQ +
	DEC A
	STA !RAM+$2
+	LDA !RAM+$3
	BEQ +
	DEC A
	STA !RAM+$3
+	JSL Layer2Gravity
	LDA !RAM+$2
	BNE +++
	LDA !RAM
	CMP #$2C
	BCS +++
	LDA !RAM
	INC A
	STA !RAM
+++	LDA !RAM+$3
	BEQ +
	CMP #$19
	BNE +
	JSL SpawnBlk
	LDA #$16
	STA $1DFC
	LDA #$01
	STA !RAM+$3

; all this does is make smoke, sprites, etc. move to the left with layer 2
+	LDX #$09
-	LDY #$00
	LDA $1491
	EOR #$FF
	INC A
	BPL +
	DEY
+	CLC
	ADC $171F,x
	STA $171F,x
	TYA
	ADC $1729,x
	STA $1729,x
	DEX
	BPL -

	LDX #$03
-	LDY #$00
	LDA $1491
	EOR #$FF
	INC A
	BPL +
	DEY
+	CLC
	ADC $17C8,x
	STA $17C8,x
	DEX
	BPL -

	LDX #$0B
-	LDA $7FAB9E,x
	CMP #$05
	BEQ ++
	LDY #$00
	LDA $1491
	EOR #$FF
	INC A
	BPL +
	DEY
+	CLC
	ADC $E4,x
	STA $E4,x
	TYA
	ADC $14E0,x
	STA $14E0,x
++	DEX
	BPL -
.lvlrts	RTS
; this ends the moving sprite stuff code
; this is the code that spawns block shards from the left side of the screen
SpawnBlk:
	LDX #$07
-	LDY #$0B
--	LDA $17F0,y
	BEQ +
	DEY
	BPL --
	RTL
+	LDA #$01
	STA $17F0,y

	PHX
	JSL $01ACF9
	AND #$07
	TAX
	LDA .yspeed,x
	PLX
	STA $1820,y
	PHX
	JSL $01ACF9
	AND #$07
	TAX
	LDA .xspeed,x
	PLX
	STA $182C,y

	LDA #$00	; active
	STA $1850,y

	PHX
	JSL $01ACF9
	AND #$07
	TAX
	LDA .ylow,x
	PLX
	STA $17FC,y

	LDA $1462
	CLC
	ADC #$02
	STA $1808,y

	LDA #$01	; y high
	STA $1814,y

	LDA #$00	; x high
	STA $18EA,y
	DEX
	BPL -
.Return	RTL
.ylow	db $50,$54,$58,$5C,$60,$64,$68,$6C
.yhigh	db $01,$01,$01,$01
.yspeed	db $00,$FF,$01,$FE,$00,$FD,$00,$FC
.xspeed	db $03,$03,$04,$04,$05,$05,$06,$06
; this is the end of the code for block shards.
; this is layer 2 horizontal gravity.
; it allows layer 2 to move smoothly (like sprites) based on !RAM
Layer2Gravity:
	LDA !RAM
	BEQ +
	ASL
	ASL
	ASL
	ASL
	CLC
	ADC !RAM+$1
	STA !RAM+$1
	PHP
	PHP
	LDY #$00
	LDA !RAM
	LSR
	LSR
	LSR
	LSR
	CMP #$08
	BCC ++
	ORA #$F0
	DEY
++	PLP
	PHA
	ADC $1466
	STA $1466
	TYA
	ADC $1467
	STA $1467
	PLA
	PLP
	ADC #$00
+	STA $1491
	LDY #$00
	LDA $1491
	EOR #$FF
	INC A
	BPL +
	DEY
+	CLC
	ADC $94
	STA $94
	TYA
	ADC $95
	STA $95
	RTL
; end of layer 2 code





///GOES IN LEVEL INIT_CODE 1D3 FOR TAKE BOSS
!RAM =		$7FC210 (Change this in Main.asm and also in tank.asm (boss sprite) if changed here)
;; 4 bytes $7FA010

!HDMARAM =	$7FC200 (Change this in Main.asm if changed here)
;; 10 bytes $7FA000

	LDA #$00
	STA !RAM
	STA !RAM+$1
	LDA #$80
	STA !RAM+$2
	LDA #$C0
	STA !RAM+$3
; parallax start
	LDX #$09
-	LDA .ScrollTable,x
	STA !HDMARAM,x
	DEX
	BPL -
	RTS
.ScrollTable
	db $20,$01,$01
	db $7F,$01,$01
	db $20,$01,$01
	db $7F,$01,$01
	db $00
; parallax end











