header
lorom

!freespace	=	$308000

org $048965
	LDA $1F13	;
	ASL A		; Restore hijack

org $0485F0
	LDY #$00	;
	TYX		;
	LDA $00		; Restore hijack

org $0485E8
	JSL MAIN

org !freespace

db "STAR"				;\
dw MainEnd-MainStart-$01		; |Write RATS tag #1 to protect main code
dw MainEnd-MainStart-$01^$FFFF		;/

MainStart:
MAIN:
	PHB
	PHK
	PLB
	;PHA
	PHX
	PHY
	PHP
	SEP #$30
	JSR MAIN2
	PLP
	PLY
	PLX
	;PLA
	PLB
	LDA #$18	;
	STA $00		; Restore hijack
	RTL

MAIN2:
	LDA $0100
	SEC
	SBC #$0C
	CMP #$03
	BCC .checksubmap
	RTS

.checksubmap
	LDA $1F11
	CMP #$03
	BEQ OAMCode
	RTS

OAMCode:
	LDX #$13
	LDY #$00
.Loop
	LDA .XOff,x
	STA $0240,y
	LDA .YOff,x
	STA $0241,y
	LDA .TileNum,x
	STA $0242,y
	LDA .Prop,x
	STA $0243,y
	PHY
	TYA
	LSR #2
	TAY
	LDA #$02
	STA $0430,y
	PLY
	INY
	INY
	INY
	INY
	DEX
	BPL .Loop
	RTS

.XOff
	db $00,$00,$00,$00,$00,$00,$00,$00,$00,$00
	db $F0,$F0,$F0,$F0,$F0,$F0,$F0,$F0,$F0,$F0
.YOff
	db $27,$37,$47,$57,$67,$77,$87,$97,$A7,$B7
	db $27,$37,$47,$57,$67,$77,$87,$97,$A7,$B7
.TileNum
	db $CE,$CC,$EE,$EA,$CC,$CC,$CC,$EC,$E8,$CC
	db $CE,$CC,$EE,$EA,$CC,$CC,$CC,$EC,$E8,$CC
.Prop
	db $34,$34,$34,$34,$34,$34,$34,$34,$34,$34
	db $34,$34,$34,$34,$34,$34,$34,$34,$34,$34

MainEnd: