if read1($00FFD5) == $23
    fullsa1rom
else
    lorom
endif

!rom = $800000
if read1($00FFD5) == $23
    !rom = $000000
endif

!Routines #= (read3($00821F))|!rom

!PoseWasLoaded = read3(!Routines+$00)
!TakeDynamicRequest = read3(!Routines+$03)
!Draw = read3(!Routines+$06)
!IsValid = read3(!Routines+$09)
!RemapOamTile = read3(!Routines+$0C)
!XIsValid = read3(!Routines+$0F)
!YIsValid = read3(!Routines+$12)
!Draw_Return = read3(!Routines+$15)
!ResourceTable = read3(!Routines+$18)
!GraphicRoutinesTable = read3(!Routines+$1B)

org !GraphicRoutinesTable+$12
    dl snestopc(GraphicRoutine)+$1F8

reset freespaceuse
freecode cleaned

!XOffSet = $00
!YOffSet = $02
!Property = $04
!Tile = $05
!PoseID = $06
!PoseOffset = $08
!MaxTilePriority = $0A

!GraphicRoutine = $45
!Iterator = !GraphicRoutine+3
!maxtile_pointer = !Iterator+2

!maxtile_pointer_max        = $6180       ; 16 bytes
!maxtile_pointer_high       = $6190       ; 16 bytes
!maxtile_pointer_normal     = $61A0       ; 16 bytes
!maxtile_pointer_low        = $61B0       ; 16 bytes

!TileX = $0B
!TileY = $0D
!TileSize = $0F

GraphicRoutine:
    PHB
    PHK
    PLB

    
    

    LDA !Property
	BIT #$40
	BNE .FlipX
.NoFlip
..Loop
	LDX !maxtile_pointer+0
	CPX !maxtile_pointer+4
	BEQ ..End

    LDA XDisplacements,y
	STA !TileX
	LDA YDisplacements,y
	STA !TileY
	LDA #$00
	STA !TileSize
	JSL !IsValid
	BCC ..next
	LDA !TileX
	STA $400000,x
	LDA !TileY
	STA $400001,x

    LDA Tiles,y
	JSL !RemapOamTile
	ORA !Property
	STA $400003,x
	LDA $8A
	STA $400002,x

    DEX #4
    STX !maxtile_pointer+0

    LDX !maxtile_pointer+2
    LDA !TileSize
    STA $400000,x
    DEX
    STX !maxtile_pointer+2

..next
    DEY

    DEC !Iterator
    BPL ..Loop

..End
    PLB
    JML !Draw_Return
.FlipX
..Loop
	LDX !maxtile_pointer+0
	CPX !maxtile_pointer+4
	BEQ ..End

    LDA XDisplacementsFlip,y
	STA !TileX
	LDA YDisplacements,y
	STA !TileY
	LDA #$00
	STA !TileSize
	JSL !IsValid
	BCC ..next
	LDA !TileX
	STA $400000,x
	LDA !TileY
	STA $400001,x

    LDA Tiles,y
	JSL !RemapOamTile
	ORA !Property
	STA $400003,x
	LDA $8A
	STA $400002,x

    DEX #4
    STX !maxtile_pointer+0

    LDX !maxtile_pointer+2
    LDA !TileSize
    STA $400000,x
    DEX
    STX !maxtile_pointer+2

..next
    DEY

    DEC !Iterator
    BPL ..Loop

..End
    PLB
    JML !Draw_Return

Tiles:
MSBombWick_Frame4_Tiles:
	db $10,$00,$01
MSBombWick_Frame8_Tiles:
	db $00,$01
MSBombWick_Frame10_Tiles:
	db $00,$01
MSBombWick_Frame11_Tiles:
	db $00,$01
MSBombWick_Frame12_Tiles:
	db $00,$01
MSBombWick_Frame13_Tiles:
	db $00,$01
MSBombWick_Frame15_Tiles:
	db $00,$01
XDisplacements:
MSBombWick_Frame4_XDisplacements:
	db $0B,$0E,$0E
MSBombWick_Frame8_XDisplacements:
	db $00,$08
MSBombWick_Frame10_XDisplacements:
	db $FE,$FE
MSBombWick_Frame11_XDisplacements:
	db $FD,$FD
MSBombWick_Frame12_XDisplacements:
	db $FE,$FE
MSBombWick_Frame13_XDisplacements:
	db $FE,$FE
MSBombWick_Frame15_XDisplacements:
	db $FF,$07
XDisplacementsFlip:
MSBombWick_Frame4_XDisplacementsFlip:
	db $FD,$FA,$FA
MSBombWick_Frame8_XDisplacementsFlip:
	db $08,$00
MSBombWick_Frame10_XDisplacementsFlip:
	db $0A,$0A
MSBombWick_Frame11_XDisplacementsFlip:
	db $0B,$0B
MSBombWick_Frame12_XDisplacementsFlip:
	db $0A,$0A
MSBombWick_Frame13_XDisplacementsFlip:
	db $0A,$0A
MSBombWick_Frame15_XDisplacementsFlip:
	db $09,$01
YDisplacements:
MSBombWick_Frame4_YDisplacements:
	db $0D,$01,$09
MSBombWick_Frame8_YDisplacements:
	db $0F,$0F
MSBombWick_Frame10_YDisplacements:
	db $0B,$13
MSBombWick_Frame11_YDisplacements:
	db $08,$10
MSBombWick_Frame12_YDisplacements:
	db $05,$0D
MSBombWick_Frame13_YDisplacements:
	db $03,$0B
MSBombWick_Frame15_YDisplacements:
	db $01,$01


End:
print dec(snestopc(GraphicRoutine)-8)
print freespaceuse