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+$33
    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

    STZ !TileX
	STZ !TileSize
	JSL !XIsValid
	BCS +
	PLB
	JML !Draw_Return
+
	LDA !TileSize
	STA !Iterator+1
    

    .NoFlip
..Loop
	LDX !maxtile_pointer+0
	CPX !maxtile_pointer+4
	BEQ ..End

    LDA YDisplacements,y
	STA !TileY
	JSL !YIsValid
	BCC ..next
	LDA !TileX
	STA $400000,x
	LDA !TileY
	STA $400001,x
	LDA #$02
	CLC
	ADC !Iterator+1
	STA !TileSize

    LDA !PoseOffset
	STA $400002,x
	LDA !Property
	STA $400003,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

YDisplacements:
MSSuperDevilBullet_Frame2_YDisplacements:
	db $02
MSSuperDevilBullet_Frame3_YDisplacements:
	db $02
MSSuperDevilBullet_Frame4_YDisplacements:
	db $01


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