;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;True levelinitASM Code lies ahead.
;If you are too lazy to search for a levelinit
;Use CTRL+F. The format is as following:
;levelinitx - levelinits 0-F
;levelinitxx - levelinits 10-FF
;levelinitxxx - levelinits 100-1FF
;Should be pretty obvious...
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

levelinit0:
levelinit1:
levelinit2:
levelinit3:
levelinit4:
levelinit5:
levelinit6:
levelinit7:
levelinit8:
levelinit9:
levelinitA:
levelinitB:
levelinitC:
levelinitD:
levelinitE:
levelinitF:
levelinit12:
levelinit13:
levelinit14:
levelinit15:
levelinit16:
levelinit17:
levelinit18:
levelinit19:
levelinit1A:
levelinit1B:
levelinit1C:
levelinit1D:
levelinit1E:
levelinit20:
levelinit21:
levelinit22:
levelinit23:
levelinit24:
levelinit25:
levelinit26:
levelinit27:
levelinit28:
levelinit29:
levelinit2A:
levelinit2B:
levelinit2C:
levelinit2F:
levelinit30:
levelinit31:
levelinit32:
levelinit33:
levelinit34:
levelinit35:
levelinit36:
levelinit37:
levelinit38:
levelinit39:
levelinit3D:
levelinit3E:
levelinit3F:
levelinit40:
levelinit41:
levelinit42:
levelinit43:
levelinit44:
levelinit45:
levelinit46:
levelinit47:
levelinit48:
levelinit49:
levelinit4A:
levelinit4B:
levelinit4C:
levelinit4D:
levelinit4E:
levelinit4F:
levelinit52:
levelinit53:
levelinit54:
levelinit55:
levelinit56:
levelinit57:
levelinit58:
levelinit59:
levelinit5A:
levelinit5C:
levelinit5D:
levelinit5E:
levelinit5F:
levelinit60:
levelinit61:
levelinit62:
levelinit63:
levelinit64:
levelinit65:
levelinit66:
levelinit67:
levelinit6C:
levelinit69:
levelinit6A:
levelinit6E:
levelinit6F:
levelinit70:
levelinit74:
levelinit76:
levelinit77:
levelinit79:
levelinit7A:
levelinit7B:
levelinit7D:
levelinit7E:
levelinit7F:
levelinit80:
levelinit81:
levelinit82:
levelinit83:
levelinit84:
levelinit85:
levelinit86:
levelinit87:
levelinit8B:
levelinit8C:
levelinit8D:
levelinit8E:
levelinit8F:
levelinit90:
levelinit91:
levelinit92:
levelinit93:
levelinit94:
levelinit95:
levelinit96:
levelinit97:
levelinit98:
levelinit99:
levelinit9A:
levelinit9B:
levelinit9C:
levelinit9D:
levelinit9E:
levelinit9F:
levelinitA0:
levelinitA1:
levelinitA2:
levelinitA3:
levelinitA4:
levelinitA5:
levelinitA6:
levelinitA7:
levelinitA8:
levelinitAB:
levelinitAD:
levelinitAE:
levelinitAF:
levelinitB0:
levelinitB1:
levelinitB2:
levelinitB3:
levelinitB4:
levelinitB5:
levelinitB6:
levelinitB7:
levelinitB8:
levelinitB9:
levelinitBA:
levelinitC1:
levelinitC4:
levelinitC5:
levelinitC6:
levelinitC7:
levelinitC8:
levelinitC9:
levelinitCA:
levelinitCB:
levelinitCC:
levelinitCD:
levelinitCE:
levelinitCF:
levelinitD0:
levelinitD1:
levelinitD2:
levelinitD3:
levelinitD4:
levelinitD5:
levelinitD6:
levelinitD7:
levelinitD8:
levelinitD9:
levelinitDA:
levelinitDB:
levelinitDC:
levelinitDD:
levelinitDE:
levelinitDF:
levelinitE0:
levelinitE1:
levelinitE2:
levelinitE3:
levelinitE4:
levelinitE5:
levelinitE6:
levelinitE7:
levelinitE8:
levelinitE9:
levelinitEA:
levelinitEB:
levelinitEC:
levelinitED:
levelinitF0:
levelinitF1:
levelinitF2:
levelinitF3:
levelinitF4:
levelinitF5:
levelinitF6:
levelinitF7:
levelinitF8:
levelinitF9:
levelinitFB:
levelinitFC:
levelinitFD:
levelinitFE:
levelinitFF:
levelinit100:
levelinit101:
levelinit104:
levelinit105:
levelinit106:
levelinit107:
levelinit108:
levelinit109:
levelinit10A:
levelinit10B:
levelinit10C:
levelinit10D:
levelinit10E:
levelinit10F:
levelinit110:
levelinit112:
levelinit113:
levelinit114:
levelinit115:
levelinit116:
levelinit117:
levelinit118:
levelinit119:
levelinit11A:
levelinit11C:
levelinit11D:
levelinit11E:
levelinit11F:
levelinit121:
levelinit122:
levelinit124:
levelinit125:
levelinit127:
levelinit128:
levelinit129:
levelinit12A:
levelinit12B:
levelinit12C:
levelinit12F:
levelinit131:
levelinit133:
levelinit134:
levelinit135:
levelinit136:
levelinit137:
levelinit139:
levelinit13A:
levelinit13B:
levelinit13C:
levelinit13D:
levelinit13E:
levelinit13F:
levelinit140:
levelinit141:
levelinit142:
levelinit143:
levelinit144:
	RTS
levelinit145:
	LDA $40     ;\
	ORA #$72    ; |Set the layer 3 bit of CGADDSUB
	STA $40     ;/
        LDA #$17    ;\
	STA $212D   ;/add some layer to the subscreen
	JSR level145

	LDA.b #autostim145
	STA $00
	LDA.b #autostim145>>8
	STA $01
	LDA.b #autostim145>>16
	STA $02
	PHK			; \ Jump to stripe image upload routine.
	PER .return-1		;  |
	PEA $84CE		;  |
	JML $00871E		; /
.return	
	RTS

levelinit147:
	STZ $0F42

	REP #$20	; 16 bit A
	LDA #$0000	; $43X0 = 00 
	STA $4330	; $43x1 = 00
	LDA #$0C00	; get pointer to brightness table
	STA $4332	; store it to low and high byte pointer
	PHK		; get bank
	PLY		;
	STY $4334	; store to bank pointer byte
	SEP #$20	; 8 bit A
	LDA #$08	; Enable HDMA on channel 3
	TSB $0D9F	;

	RTS
levelinit148:
	LDA #$04
	TSB $40
        LDA #$13    	;\
	STA $212d   	;/add some layer to the subscree

	LDA.b #autostim148
	STA $00
	LDA.b #autostim148>>8
	STA $01
	LDA.b #autostim148>>16
	STA $02
	PHK			; \ Jump to stripe image upload routine.
	PER .return-1		;  |
	PEA $84CE		;  |
	JML $00871E		; /
.return	
	RTS



levelinit146:
levelinit149:
levelinit14A:
levelinit14B:
levelinit14C:
levelinit14D:
levelinit14E:
levelinit14F:
levelinit150:
levelinit151:
levelinit152:
levelinit153:
levelinit154:
levelinit155:
levelinit156:
levelinit157:
levelinit158:
levelinit159:
levelinit15A:
levelinit15B:
levelinit15C:
levelinit15D:
levelinit15E:
levelinit15F:
levelinit160:
levelinit161:
levelinit162:
levelinit163:
levelinit164:
levelinit165:
levelinit166:
levelinit167:
levelinit168:
levelinit169:
levelinit16A:
levelinit16B:
levelinit16C:
levelinit16D:
levelinit16E:
levelinit16F:
levelinit172:
levelinit173:
levelinit174:
levelinit175:
levelinit176:
levelinit17B:
levelinit17C:
levelinit17D:
levelinit17E:
levelinit17F:
levelinit180:
levelinit181:
levelinit182:
levelinit183:
levelinit184:
levelinit185:
levelinit186:
levelinit188:
levelinit189:
levelinit18A:
levelinit18B:
levelinit18C:
levelinit18D:
levelinit18E:
levelinit18F:
levelinit190:
levelinit191:
levelinit192:
levelinit193:
levelinit194:
levelinit195:
levelinit196:
levelinit197:
levelinit198:
levelinit199:
levelinit19A:
levelinit19B:
levelinit19C:
levelinit19F:
levelinit1A5:
levelinit1A6:
levelinit1A7:
levelinit1A9:
levelinit1AA:
levelinit1AB:
levelinit1AC:
levelinit1AD:
levelinit1AE:
levelinit1AF:
levelinit1B0:
levelinit1B1:
levelinit1B2:
levelinit1B3:
levelinit1B4:
levelinit1B5:
levelinit1B6:
levelinit1B7:
levelinit1B8:
levelinit1B9:
levelinit1BA:
levelinit1BB:
levelinit1BC:
levelinit1BD:
levelinit1BE:
levelinit1BF:
levelinit1C0:
levelinit1C1:
levelinit1C2:
levelinit1C3:
levelinit1C4:
levelinit1C5:
levelinit1C6:
levelinit1C7:
levelinit1C8:
levelinit1CA:
levelinit1CB:
levelinit1CC:
levelinit1CD:
levelinit1CE:
levelinit1CF:
levelinit1D0:
levelinit1D1:
levelinit1D3:
levelinit1D4:
levelinit1D5:
levelinit1D6:
levelinit1D7:
levelinit1D8:
levelinit1D9:
levelinit1DA:
levelinit1DB:
levelinit1DC:
levelinit1DD:
levelinit1DE:
levelinit1DF:
levelinit1E0:
levelinit1E1:
levelinit1E2:
levelinit1E3:
levelinit1E4:
levelinit1E5:
levelinit1E6:
levelinit1E7:
levelinit1E8:
levelinit1E9:
levelinit1EA:
levelinit1EB:
levelinit1EC:
levelinit1ED:
levelinit1EE:
levelinit1EF:
levelinit1F0:
levelinit1F1:
levelinit1F2:
levelinit1F3:
levelinit1F4:
levelinit1F5:
levelinit1F6:
levelinit1F7:
levelinit1F8:
levelinit1F9:
levelinit1FA:
levelinit1FB:
levelinit1FC:
levelinit1FD:
levelinit1FE:
levelinit1FF:
	RTS




levelinit10:
	LDA #$00		; HDMA gradient
	STA $4330
	LDA #$02
	STA $4340
	LDA #$32
	STA $4331
	STA $4341
	REP #$20
	LDA.w #.Table2
	STA $4332
	LDA.w #.Table1
	STA $4342
	SEP #$20
	LDA.b #.Table2>>16
	STA $4334
	LDA.b #.Table1>>16
	STA $4344
	LDA #$18
	TSB $0D9F
	RTS


	.Table1
	db $08,$3A,$4F
	db $08,$3B,$4F
	db $08,$3B,$50
	db $08,$3C,$51
	db $08,$3C,$52
	db $08,$3D,$53
	db $08,$3D,$54
	db $08,$3E,$55
	db $08,$3E,$56
	db $80,$3F,$57
	db $18,$3F,$57
	db $00

.Table2
	db $08,$8A
	db $28,$8B
	db $80,$8C
	db $30,$8C
	db $00


levelinit11:
  	LDA $40		;\
	ORA #$04	; |Set the layer 3 bit of CGADDSUB
	STA $40		;/
        LDA #$13	;\
	STA $212D	;/add some layer to the subscreen
	RTS		;Return





levelinit1F:
	LDA $24
        CLC
        ADC #$80
        STA $24
	LDA #$04
	TSB $40
        LDA #$13    	;\
	STA $212d   	;/add some layer to the subscree

	LDA.b #autostim1F
	STA $00
	LDA.b #autostim1F>>8
	STA $01
	LDA.b #autostim1F>>16
	STA $02
	PHK			; \ Jump to stripe image upload routine.
	PER .return-1		;  |
	PEA $84CE		;  |
	JML $00871E		; /
.return	
	JMP level1F

levelinit2D:
	LDA #$24
	STA $40
	LDA #$13
	STA $212D

	LDX #$18
.TileMap
	LDA IceWaterTilemap2D,x
	STA $7F837D,x
	DEX
	BPL .TileMap

	LDA #$00
	STA $4330
	LDA #$02
	STA $4340

	LDA #$32
	STA $4331
	STA $4341

	REP #$20
	LDA.w #Table2D_2
	STA $4332
	LDA.w #Table2D_1
	STA $4342

	SEP #$20

	LDA.b #Table2D_2>>16
	STA $4334
	LDA.b #Table2D_1>>16
	STA $4344

	LDA #$18
	TSB $0D9F

	JMP level2D

Table2D_1:
	db $18,$41,$82
	db $08,$42,$83
	db $10,$43,$84
	db $10,$44,$85
	db $08,$44,$86
	db $10,$45,$86
	db $10,$45,$87
	db $20,$46,$88
	db $20,$47,$89
	db $08,$48,$8A
	db $08,$48,$8B
	db $28,$49,$8B
	db $00

Table2D_2:
	db $18,$21
	db $28,$22
	db $38,$23
	db $30,$24
	db $38,$25
	db $00

IceWaterTilemap2D:
	incbin icewater.stim

levelinit2E:
	REP #$10

	LDX #$01B2
.Loop
	LDA Snowball2E,x
	STA $7F837D,x
	DEX
	BPL .Loop

	SEP #$10

	LDA #$00
	STA $7FA000
	STA $7FA001
	STA $7FA006
	STA $7FA007
	STA $7FA008
	STA $7FA009
	STA $7FA00A
	STA $7FA00B
	STA $7FA00C

	REP #$20
	LDA #$F1C0
	STA $7FA002	; Free RAM for Layer 3 X offset.
	LDA #$0020
	STA $7FA004	; Free RAM for Layer 3 Y offset.
	SEP #$20

	STZ $15E8	; Free RAM used to determine Mario's skating speed for this level.

	LDA.b #$00
	STA.l $7FB020
	STA.l $7FB021
	LDA.b #$00
	STA.l $7FB022
	STA.l $7FB023

	LDX #$09
LoopInit2E:
	LDA Table2E,x
	STA $7FB600,x
	DEX
	BPL LoopInit2E

	LDA #$01
	STA $4350

	LDA #$2C
	STA $4351

	REP #$20
	LDA #$B600
	STA $4352
	SEP #$20
	LDA #$7F
	STA $4354

	LDA #$20
	TSB $0D9F

	JMP level2E_Grp1

Table2E:
db $7F,$15,$0A
db $50,$15,$0A
db $10,$02,$1D
db $00

Snowball2E:
	incbin Snowball.stim

levelinit3A:
levelinit3B:
levelinit3C:
	LDA #$00	;Unused tile	(walking 1)
	STA $7F8800

	LDA #$A0	;Head tile 1	(walking 1)
	STA $7F8801

	LDA #$C0	;Body tile 1	(walking 1)
	STA $7F8802

	LDA #$00	;Unused tile	(walking 2)
	STA $7F8803

	LDA #$A0	;Head tile 2	(walking 2)
	STA $7F8804

	LDA #$C2	;Body tile 2	(walking 2)
	STA $7F8805

	LDA #$82	;Vial tile	(throwing)
	STA $7F8806

	LDA #$A4	;Head tile 3	(throwing)
	STA $7F8807

	LDA #$C4	;Body tile 3	(throwing)
	STA $7F8808


	LDA #$82	;Vial tile 1	(actual vial)
	STA $7F8809

	LDA #$88	;Vial tile 2	(actual vial)
	STA $7F880A

	LDA #$88	;Vial tile 3	(actual vial)
	STA $7F880B

	LDA #$82	;Vial tile 4	(actual vial)
	STA $7F880C

	LDA #$80	;Vial tile 5	(actual vial)
	STA $7F880D
	RTS

levelinit50:
levelinit51:
levelinit5B:
	LDA #$00		; HDMA gradient
	STA $4330
	LDA #$02
	STA $4340
	LDA #$32
	STA $4331
	STA $4341
	REP #$20
	LDA.w #.Table2
	STA $4332
	LDA.w #.Table1
	STA $4342
	SEP #$20
	LDA.b #.Table2>>16
	STA $4334
	LDA.b #.Table1>>16
	STA $4344

	PHP
	REP #$20
	LDY #$03
	STY $4350
	LDY #$21
	STY $4351
	LDA.w #.Table
	STA $4352
	LDY.b #.Table>>16
	STY $4354
	SEP #$20
	PLP
	LDA #$38
	TSB $0D9F
	RTS

.Table1
	db $33,$3A,$8A
	db $20,$3B,$8B
	db $21,$3C,$8B
	db $10,$3D,$8B
	db $10,$3D,$8C
	db $20,$3E,$8C
	db $11,$3F,$8D
	db $1B,$3F,$8C
	db $00
.Table2
	db $23,$4E
	db $20,$4F
	db $10,$50
	db $10,$51
	db $11,$52
	db $10,$53
	db $10,$54
	db $10,$55
	db $21,$56
	db $1B,$57
	db $00
.Table
	db $23 : dw $2F00,$29DA
	db $10 : dw $2F00,$29FA
	db $10 : dw $2F00,$2DFB
	db $10 : dw $2F00,$2E1B
	db $10 : dw $2F00,$2E3C
	db $11 : dw $2F00,$2E5C
	db $10 : dw $2F00,$2E7D
	db $10 : dw $2F00,$329D
	db $10 : dw $2F00,$32BE
	db $10 : dw $2F00,$32DE
	db $11 : dw $2F00,$36DF
	db $1B : dw $2F00,$32FF
	db $00





levelinit68:
	LDA #$48		; Initialize timer (see level68:)
	STA $14A8
	RTS

levelinit6B:
levelinit6D:
	LDA #$17		 	;\ Everything
	STA $212C			;| is on main screen
	LDA #$00 			;| Nothing
	STA $212D			;| is on sub screen
	LDA #$27			;| Affect layer 1,2,3
	STA $40				;/ and back enable

	LDA #$00
	STA $4330
	LDA #$02
	STA $4340

	LDA #$32
	STA $4331
	STA $4341

	REP #$20
	LDA.w #.Table2_6B
	STA $4332
	LDA.w #.Table1_6B
	STA $4342

	SEP #$20

	LDA.b #.Table2_6B>>16
	STA $4334
	LDA.b #.Table1_6B>>16
	STA $4344

	LDA #$18
	TSB $0D9F

	RTS

.Table1_6B
db $80,$2E,$80
db $22,$2E,$80
db $04,$2F,$80
db $04,$30,$80
db $03,$31,$80
db $03,$32,$80
db $03,$33,$80
db $03,$34,$80
db $03,$35,$80
db $04,$36,$80
db $04,$37,$80
db $17,$38,$80
db $08,$39,$80
db $00

.Table2_6B
db $80,$40
db $20,$40
db $04,$41
db $04,$42
db $03,$43
db $03,$44
db $03,$45
db $03,$46
db $03,$47
db $04,$48
db $04,$49
db $0E,$4A
db $02,$4B
db $01,$4C
db $01,$4D
db $01,$4E
db $01,$4F
db $01,$50
db $01,$51
db $01,$52
db $01,$53
db $01,$54
db $01,$55
db $02,$56
db $04,$57
db $00


levelinit75:
	LDA #$FF
	STA $1887
	LDA #$FF	; Fills the Air meter
	STA $7E005C
	RTS

levelinit78:
	LDA #$FF
	STA $1887
	RTS

levelinit7C:
levelinit123:
LDA #$17
STA $212C
STA $212D

LDA #$B4			;
STA $24				; set the initial Y position of Layer 3
STZ $25				;
LDA #$04			;
TRB $40				; disable Layer 3 from being affected by CGADSUB

        LDA #$13    	;\
	STA $212d   	;/add some layer to the subscree

	LDA.b #autostim123
	STA $00
	LDA.b #autostim123>>8
	STA $01
	LDA.b #autostim123>>16
	STA $02
	PHK			; \ Jump to stripe image upload routine.
	PER .return-1		;  |
	PEA $84CE		;  |
	JML $00871E		; /
.return	
	RTS

levelinit88:
	LDA #$BD
	STA $1468
	RTS
levelinit89:
levelinit8A:
	STZ $76
	RTS

levelinitA9:

REP #$20
LDA #$0000
STA $4330
LDA #InitCODE
STA $4332
PHK
PLY
STY $4334
SEP #$20
LDA #$08
TSB $0D9F
RTS

InitCODE:
db $03,$00
db $03,$01
db $03,$02
db $03,$03
db $03,$04
db $03,$05
db $03,$06
db $03,$07
db $03,$08
db $03,$09
db $03,$0A
db $03,$0B
db $03,$0C
db $03,$0D
db $03,$0E
db $80,$0F
db $03,$0E
db $03,$0D
db $03,$0C
db $03,$0B
db $03,$0A
db $03,$09
db $03,$08
db $03,$07
db $03,$06
db $03,$05
db $03,$04
db $03,$03
db $03,$02
db $03,$01
db $03,$00
db $00

levelinitAA:
levelinitAC:
	STZ $58
	RTS

levelinitBB:
	LDA $7F9A83
	ORA #$01
	STA $7F9A83
	LDA #$FF
	STA $1DEF	;freeram used for start of race timer
	RTS
levelinitBC:
	LDA $7F9A83
	ORA #$02
	STA $7F9A83
	RTS
levelinitBD:
	LDA $7F9A83
	ORA #$04
	STA $7F9A83
	RTS
levelinitBE:
	LDA $7F9A83
	ORA #$08
	STA $7F9A83
	LDA #$00	;number of targets hit
	STA $7F9A90
	LDA #$19	;number of shots allowed
	STA $7F9A91
	RTS
levelinitBF:

	LDA $7F9A83
	ORA #$10
	STA $7F9A83
	RTS
levelinitC0:	;7F9A7B-7D = answer submission digits
		;$7F9A7E-80 = correct answer digits
		;$7F9A81-82 = total points missed, points missed in previous game
		;$7F9A83 = which doors have been entered so far
		;$7F9A84 = initial time of timer sprite
	STZ $19	
	LDA $7F9A81	;total points missed
	CLC
	ADC $7F9A82	;points missed in last game
	STA $7F9A81
	LDA #$00
	STA $7F9A82

	LDA $7F9A81	;if points missed are too great, time for the consolation prize!
	CMP #$0B
	BCC StillTryC0
	lda #$05
	sta $71
StillTryC0:
	RTS

levelinitC2:
levelinitC3:
	LDA $7F8889
	STA $13BF
	RTS

levelinitEE:
JSR levelEE
LDA $24
ADC #$FB
ADC #$0B
STA $24

LDA #$04
TSB $40
LDA #$13
STA $212D
LDA.b #TidesEE
STA $00
LDA.b #TidesEE>>8
STA $01
LDA.b #TidesEE>>16
STA $02
PHK
PER $0006
PEA $84CE
JML $80871E
RTS

levelinitEF:
JSR levelEF

LDA $24
ADC #$0B
STA $24

LDA #$04
TSB $40
LDA #$13
STA $212D
LDA.b #TidesEE
STA $00
LDA.b #TidesEE>>8
STA $01
LDA.b #TidesEE>>16
STA $02
PHK
PER $0006
PEA $84CE
JML $80871E
RTS

levelinitFA:
	!BlocksHit = $7FB100
	LDA #$00
	LDX #$08
	.loop
	STA !BlocksHit,x
	DEX
	BPL .loop
	LDA #$01
	STA $14AF
	RTS

levelinit102:
STZ $19
STZ $0DBC
STZ $0DC2
LDX #$06 ;the amount of bytes in the scroll table. Should be a multiple of 3
LOOP:
LDA ScrollTable,x
STA $7FA000,x
DEX
BPL LOOP
RTS

ScrollTable:
db $79,$01,$01
db $10,$01,$01
db $00 ;end byte, don't remove it

levelinit103:
	LDA $40     ;\
	ORA #$72    ; |Set the layer 3 bit of CGADDSUB
	STA $40     ;/
        LDA #$17    ;\
	STA $212D   ;/add some layer to the subscreen
	LDA.b #autostim145
	STA $00
	LDA.b #autostim145>>8
	STA $01
	LDA.b #autostim145>>16
	STA $02
	PHK			; \ Jump to stripe image upload routine.
	PER .return-1		;  |
	PEA $84CE		;  |
	JML $00871E		; /
.return	
	JMP level103

levelinit111:
	STZ $19 
	LDA #$00
	STA $7F9A83
	STA $7F9A82
	STA $7F9A81	;total points missed
	RTS

levelinit11B:
	LDA #$3F
	STA $13BF
	RTS

levelinit71:
levelinit72:
levelinit73:
levelinit120:
	JMP level120

levelinit126:
		LDA #$00
		STA $4330
		LDA #$02
		STA $4340

		LDA #$32
		STA $4331
		STA $4341

		REP #$20
		LDA.w #level2E_Table2
		STA $4332
		LDA.w #level2E_Table1
		STA $4342

		SEP #$20

		LDA.b #level2E_Table2>>16
		STA $4334
		LDA.b #level2E_Table1>>16
		STA $4344

		LDA #$18
		TSB $0D9F

		RTS

levelinit12D:
STZ $18E6
STZ $1908
STZ $191B

JMP levelinit3A


levelinit12E:
	LDA #$00	;Unused tile	(walking 1)
	STA $7F8800

	LDA #$A0	;Head tile 1	(walking 1)
	STA $7F8801

	LDA #$C0	;Body tile 1	(walking 1)
	STA $7F8802

	LDA #$00	;Unused tile	(walking 2)
	STA $7F8803

	LDA #$A0	;Head tile 2	(walking 2)
	STA $7F8804

	LDA #$C2	;Body tile 2	(walking 2)
	STA $7F8805

	LDA #$82	;Vial tile	(throwing)
	STA $7F8806

	LDA #$A4	;Head tile 3	(throwing)
	STA $7F8807

	LDA #$C4	;Body tile 3	(throwing)
	STA $7F8808


	LDA #$82	;Vial tile 1	(actual vial)
	STA $7F8809

	LDA #$88	;Vial tile 2	(actual vial)
	STA $7F880A

	LDA #$88	;Vial tile 3	(actual vial)
	STA $7F880B

	LDA #$82	;Vial tile 4	(actual vial)
	STA $7F880C

	LDA #$80	;Vial tile 5	(actual vial)
	STA $7F880D

LDA #$01
STA $4300

LDA #$18
STA $4301

LDA.b #Background
STA $4302
LDA.b #Background>>8
STA $4303
LDA.b #Background>>16
STA $4304

REP #$20
LDA #$5000
STA $2116

LDA #$2000
STA $4305
SEP #$20

LDA #$01
STA $420B

LDA #$01
STA $4310

LDA #$18
STA $4301

LDA.b #EggShatterGFX
STA $4302
LDA.b #EggShatterGFX>>8
STA $4303
LDA.b #EggShatterGFX>>16
STA $4304

REP #$20
LDA #$76F0
STA $2116

LDA #$0032
STA $4305
SEP #$20

LDA #$01
STA $420B




REP #$20
LDA $1A
LSR
LSR
STA $22
LDA $1C
LSR
LSR
STA $24
SEP #$20

	RTS




EggShatterGFX:
db $00, $03, $02, $05, $06, $09, $0E, $11 
db $0C, $12, $18, $24, $10, $28, $00, $38 
db $00, $00, $00, $00, $00, $00, $00, $00 
db $00, $00, $00, $00, $00, $00, $00, $00

levelinit130:
LDA #$FF
STA $7E005C
RTS




levelinit138:
	JMP level138




levelinit132:
levelinit170:
LDX #$FF
Loop1702:
INX
CPX #$0C
BEQ Done1702

	LDA $9E,x
	CMP #$97
	BNE Loop1702
	STZ $14C8,x
	BRA Loop1702

Done1702:
	;Set up the KooPhD's tilemap
	LDA #$00	;Unused tile	(walking 1)
	STA $7F8800

	LDA #$A0	;Head tile 1	(walking 1)
	STA $7F8801

	LDA #$C0	;Body tile 1	(walking 1)
	STA $7F8802

	LDA #$00	;Unused tile	(walking 2)
	STA $7F8803

	LDA #$A0	;Head tile 2	(walking 2)
	STA $7F8804

	LDA #$C2	;Body tile 2	(walking 2)
	STA $7F8805

	LDA #$82	;Vial tile	(throwing)
	STA $7F8806

	LDA #$A4	;Head tile 3	(throwing)
	STA $7F8807

	LDA #$C4	;Body tile 3	(throwing)
	STA $7F8808


	LDA #$82	;Vial tile 1	(actual vial)
	STA $7F8809

	LDA #$88	;Vial tile 2	(actual vial)
	STA $7F880A

	LDA #$88	;Vial tile 3	(actual vial)
	STA $7F880B

	LDA #$82	;Vial tile 4	(actual vial)
	STA $7F880C

	LDA #$80	;Vial tile 5	(actual vial)
	STA $7F880D
	RTS
levelinit171:
LDA #$01
STA $4300

LDA #$18
STA $4301

LDA.b #Background
STA $4302
LDA.b #Background>>8
STA $4303
LDA.b #Background>>16
STA $4304

REP #$20
LDA #$5000
STA $2116

LDA #$2000
STA $4305
SEP #$20



LDA #$01
STA $420B
	RTS

levelinit177:
	LDA #$0F
	STA $13BF
	STZ $0D9C
	RTS
levelinit178:
	RTS
levelinit179:
levelinit17A:
	REP #$20
	LDA #$0000
	STA $1466
	SEP #$20
	LDX #$48
LoopYYY:
	LDA LVLYYY_HDMA,x
	STA $7FB100,x	; Parallax HDMA RAM table.
	DEX
	BPL LoopYYY
	JMP Parallax_INIT2

LVLYYY_HDMA:
db $06,$00,$00	; No scrolling
db $0D,$00,$00	; Slow scrolling
db $0E,$00,$00	; Medium scrolling
db $02,$00,$00	; Slow scrolling
db $01,$00,$00	; Very slow scrolling
db $0A,$00,$00	; Medium scrolling
db $03,$00,$00	; No scrolling
db $13,$00,$00	; Fast scrolling
db $0A,$00,$00	; Medium scrolling
db $03,$00,$00	; Slow scrolling
db $0B,$00,$00	; Medium scrolling
db $02,$00,$00	; Very slow scrolling
db $03,$00,$00	; Fast scrolling
db $0B,$00,$00	; Very fast scrolling
db $05,$00,$00	; No scrolling
db $0F,$00,$00	; Slow scrolling
db $11,$00,$00	; Medium scrolling
db $0D,$00,$00	; Slow scrolling
db $01,$00,$00	; Very slow scrolling
db $06,$00,$00	; Medium scrolling
db $10,$00,$00	; Fast scrolling
db $16,$00,$00	; Very slow scrolling
db $04,$00,$00	; Slow scrolling
db $01,$00,$00	; No scrolling
db $0E,$00,$00	; Very fast scrolling
db $00

levelinit187:
	STZ $15
	STZ $16
	STZ $17
	STZ $18
	RTS




levelinit19D:
levelinit19E:
levelinit1A0:
levelinit1A1:
levelinit1A2:
levelinit1A3:
	JSR level1A0
Darkness:
	REP #$20	; 16 bit A
	LDA #$0000	; $43X0 = 00 
	STA $4330	; $43x1 = 00
	LDA #LVL1BRIGHT	; get pointer to brightness table
	STA $4332	; store it to low and high byte pointer
	PHK		; get bank
	PLY		;
	STY $4334	; store to bank pointer byte
	SEP #$20	; 8 bit A
	LDA #$08	; Enable HDMA on channel 3
	TSB $0D9F	;
	RTS		; return

LVL1BRIGHT:
db $03,$00
db $03,$01
db $03,$02
db $03,$03
db $03,$04
db $03,$05
db $03,$06
db $03,$07
db $03,$08
db $03,$09
db $03,$0A
db $03,$0B
db $03,$0C
db $03,$0D
db $03,$0E
db $80,$0F
db $03,$0E
db $03,$0D
db $03,$0C
db $03,$0B
db $03,$0A
db $03,$09
db $03,$08
db $03,$07
db $03,$06
db $03,$05
db $03,$04
db $03,$03
db $03,$02
db $03,$01
db $03,$00
db $00
	RTS


levelinit1A4:
	LDA #$27
	STA $7B
	LDA #$A0
	STA $7D

	REP #$20	; 16 bit A
	LDA #$0000	; $43X0 = 00 
	STA $4330	; $43x1 = 00
	LDA #LVL2BRIGHT	; get pointer to brightness table
	STA $4332	; store it to low and high byte pointer
	PHK		; get bank
	PLY		;
	STY $4334	; store to bank pointer byte
	SEP #$20	; 8 bit A
	LDA #$08	; Enable HDMA on channel 3
	TSB $0D9F	;
	JMP level1A3		; return

LVL2BRIGHT:
db $80,$0F
db $39,$0F
db $03,$0E
db $03,$0D
db $03,$0C
db $03,$0B
db $03,$0A
db $03,$09
db $03,$08
db $03,$07
db $03,$06
db $03,$05
db $03,$04
db $03,$03
db $03,$02
db $03,$01
db $03,$00
db $00

	RTS

levelinit1A8:
	JMP level1A8

levelinit1C9:
	JMP level138

levelinit1D2:
;!RAM =		$7FA010 
;; 4 bytes
;
;!HDMARAM =	$7FA000 
;; 10 bytes
;
;	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
RTS