;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; P-Switch, by Davros.
;;
;; Description: A P-switch that will set the blue timer, silver timer, turn sprites into 
;; coins, stun sprites with an earthquake, spawn sprites and spawn blocks depending on it's 
;; palette.
;;
;; Uses first extra bit: YES
;;
;; Green P-Switch:
;; When the first extra bit is clear, it will spawn normal sprites. When it's set, it will
;; spawn custom sprites.
;;
;; Gold P-Switch:
;; When the first extra bit is clear, it will spawn a question with a flower. When it's
;; set, it will spawn a question block with a feather.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Extra Property Byte 1
;;    Bit 0 - don't carry sprite
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

incsrc subroutinedefs_trasm.asm

                    BLUE_TIMER = $50              ; blue p-switch timer 
                    GREY_TIMER = $50              ; grey p-switch timer

                    QUAKE_TIMER = $20             ; shake ground timer
                    QUAKE_TIMER2 = $20            ; shake ground timer

                    SOUND_TO_GEN = $0B
                    SOUND_TO_GEN2 = $09
		    SOUND_TO_GEN3 = $02
		    SOUND_TO_GEN4 = $10

		    BLOCK_TILE1 = $011F           ; map16 value of the block in hex          
		    BLOCK_TILE2 = $0120           ; map16 value of the block in hex           

		    SPRITE_TO_GEN = $79           ; normal sprite to spwan
                    CUST_SPRITE_TO_GEN = $20      ; custom sprite to spawn

                    EXTRA_BITS = $7FAB10
                    EXTRA_PROP_1 = $7FAB28
                    NEW_SPRITE_NUM = $7FAB9E

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; sprite init JSL
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

                    dcb "INIT"
	            LDA $167A,x             ; \ don't hurt Mario when it touches the sprite 
	            STA $1528,x             ; / 
                    RTL                 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; sprite code JSL
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

                    dcb "MAIN"                                    
                    PHB                     ; \
                    PHK                     ;  | main sprite function, just calls local subroutine
                    PLB                     ;  |
	            CMP #$09                ;  |
	            BCS HANDLE_STUNNED      ;  |
                    JSR SPRITE_CODE_START   ;  |
                    PLB                     ;  |
                    RTL                     ; /

HANDLE_STUNNED      LDA $167A,x		    ; \ set to interact with Mario
	            AND #$7F                ;  |
	            STA $167A,x             ; /
	            
	            PHX                     ; \ set carried sprite graphics
                    JSR CARRIED_GFX         ;  |
	            PLX                     ; /
	            PLB
                    RTL

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; sprite main code 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
         
         
JUSTSPATOUT	    LDA #$08		    ; \ set normal
		    STA $14C8,x		    ; / sprite mode
		    LDA #$08	            ; \ set timer for
		    STA $1540,x	            ; / "solidification"
                    RTS                     ; return

SPRITE_CODE_START   JSR SUB_GFX             ; graphics routine
                    LDA $14C8,x             ; \ if it's a shell
		    CMP #$09		    ;  | that means yoshi
		    BCS JUSTSPATOUT	    ; /  just spat it out
		    CMP #$0B		    ; \ if it's carried
		    BCS JUSTSPATOUT	    ; /  just spat it out
                    LDA $9D                 ; \ if sprites locked, return
                    BNE RETURN              ; /

                    LDA $1558,x             ; \ if sprite not defeated (timer to show remains > 0)...
                    BEQ ALIVE               ; / ... go to ALIVE
                    STA $15D0,x             ; \ 
                    DEC A                   ;  } if sprite remains don't disappear next frame...
                    BNE RETURN              ; / ... return
                    STZ $14C8,x             ; disappear the sprite
                    JSR SUB_SMOKE           ; smoke routine

                    LDA $15F6,x             ; \ if the sprite palette is...
                    CMP #$00                ;  | ...gold
                    BEQ SET_BLOCK           ; /
                    CMP #$0A                ; \ ...green
                    BEQ SET_SPRITE          ; /
                    BRA RETURN

SET_BLOCK           JSR SPAWN_BLOCK         ; spawn block routine
                    BRA RETURN

SET_SPRITE          JSR SPAWN_SPRITE        ; spawn sprite routine

RETURN              RTS                     ; return

ALIVE               JSL SubOffscreenX3   ; handle off screen situation
                    
                    LDA $1588,x             ; \ if sprite is in contact with an object...
                    AND #$03                ;  |
                    BEQ CEILING_CONTACT     ;  |
                    LDA $157C,x             ;  | flip the direction status
                    EOR #$01                ;  |
                    STA $157C,x             ; /
                    LDA $B6,x               ; \ flip speed
                    EOR #$FF                ;  |
                    STA $B6,x               ; /

CEILING_CONTACT     LDA $1588,x             ; \ if sprite is in contact with the ceiling...
                    AND #$08                ;  |
                    BEQ GROUND              ; /
                    STZ $AA,x               ; no y speed
                    BRA SET_GROUND_SPEED

GROUND              LDA $1588,x             ; \ if sprite is in contact with the ground...
                    AND #$04                ;  |
                    BEQ IN_AIR              ; /

SET_GROUND_SPEED    JSR GROUND_SPEED        ; ground speed routine

IN_AIR              JSL $81802A             ; update position based on speed values

	            LDA $1528,x             ; \ don't hurt Mario when it touches the sprite
	            STA $167A,x             ; /

                    JSL $81A7DC             ; check for Mario/sprite contact
                    BCC RETURN              ; return if no contact
                    JSL SubVertPos        ; vertical Mario/sprite check routine
                    LDA $0E                 ; \ if Mario isn't above sprite, and there's vertical contact...
                    CMP #$E6                ;  | ... sprite wins
                    BPL SET_CARRIED         ; /
                    LDA $7D                 ; \  if Mario's y speed < 10 ...
                    CMP #$10                ;  } ... sprite will move Mario
                    BMI SET_CARRIED         ; /                       
                   
MARIO_WINS          JSL $81AA33             ; set Mario speed
                    JSL $81AB99             ; display contact graphic
                    LDA #$20                ; \ ... time to show defeated sprite = $20
                    STA $1558,x             ; / 
		    LDA #SOUND_TO_GEN       ; \ set sound effect
		    STA $1DF9               ; /

                    LDA $15F6,x             ; \ if the sprite palette is...
                    CMP #$02                ;  | ...gray
                    BEQ SET_MUSIC           ; /
                    CMP #$04                ; \ ...yellow
                    BEQ TURN_INTO_A_COIN    ; /
                    CMP #$06                ; \ ...blue
                    BEQ SET_MUSIC           ; /
                    CMP #$08                ; \ ...red
                    BEQ QUAKE               ; /
                    BRA RETURN2

SET_MUSIC	    LDA $163E,x             ; \ if the timer is set...
		    BNE RETURN2             ; /
		    LDA $0DDA               ; \ if the music is playing...
		    BMI SET_TIMER           ; /
		    LDA #$0E                ; \ set P-switch music
		    STA $1DFB               ; /
SET_TIMER	    LDA #$20                ; \ set timer
		    STA $163E,x             ; /
		    LDA #QUAKE_TIMER        ; \ shake ground timer
		    STA $1887               ; /

                    LDA $15F6,x             ; \ if the sprite palette is...
                    CMP #$02                ;  | ...gray
                    BEQ SET_GREY_TIMER      ; /
                    CMP #$06                ; \ ...blue
                    BEQ SET_BLUE_TIMER      ; /
                    BRA RETURN2

SET_GREY_TIMER      LDA #GREY_TIMER         ; \ set grey P-switch timer
		    STA $14AE               ; /
		    JSL $82B9BD             ; change on screen sprites into silver coins routine
                    BRA RETURN2

SET_BLUE_TIMER	    LDA #BLUE_TIMER         ; \ set blue P-switch timer
		    STA $14AD               ; /
                    BRA RETURN2

TURN_INTO_A_COIN    JSL $80FA80             ; change on screen sprites into a coin routine
                    BRA RETURN2

QUAKE               LDA #QUAKE_TIMER2       ; \ shake ground
                    STA $1887               ; /
                    LDA #SOUND_TO_GEN2      ; \ play sound effect
                    STA $1DFC               ; /
                    JSL $8294C1             ; earthquake routine
RETURN2             RTS                     ; return

OFFSET		    dcb $01,$00,$FF,$FF
		        
SET_CARRIED         BIT $15		    ; \ don't pick up sprite if not pressing button
                    BVC NO_MARIO_X_SPEED    ; /
                    LDA $1470               ; \ if carrying an enemy...
                    ORA $187A               ; / ...or on Yoshi
                    BNE NO_MARIO_X_SPEED    ; don't carry
                    LDA EXTRA_PROP_1,x      ; \ don't carry if the extra property 1 is set...
	            AND #$01                ;  |
	            BNE NO_MARIO_X_SPEED    ; / 
	            LDA #$0B		    ; \ sprite status = Carried
	            STA $14C8,x             ; /

NO_MARIO_X_SPEED    STZ $7B                 ; no Mario x speed
		    JSL SubHorizPos        ; horizontal Mario/sprite check routine
		    TYA                     ;
		    ASL A                   ;
		    TAY                     ;
		    REP #$20                ; Accum (16 bit)
		    LDA $94                 ; \ set Mario's x position
		    CLC                     ;  |
		    ADC OFFSET,y            ;  |
		    STA $94                 ; /
		    SEP #$20                ; Accum (8 bit) 
	            RTS                     ; return


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; ground speed routine
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


Y_SPEED_TABLE       dcb $00,$00,$00,$F8,$F8,$F8,$F8,$F8
                    dcb $F8,$F7,$F6,$F5,$F4,$F3,$F2,$E8
                    dcb $E8,$E8,$E8,$00


GROUND_SPEED        LDA $B6,x               ;
                    PHP                     ; push processor
                    BPL SKIP_FLIP           ;
                    EOR #$FF		    ; \ set A to -A
                    INC A                   ; /  
SKIP_FLIP           LSR                     ;
                    PLP                     ; pull processor
                    BPL STORE_X_SPEED       ;
                    EOR #$FF		    ; \ set A to -A
                    INC A                   ; /  
STORE_X_SPEED       STA $B6,x               ;
                    LDA $AA,x               ;
                    PHA                     ;
                    JSR SET_SOME_Y_SPEED    ; set y speed
                    PLA                     ;
                    LSR                     ;
                    LSR                     ;
                    TAY                     ;
                    LDA Y_SPEED_TABLE,y     ; y speed table
                    LDY $1588,x             ; \ if touching an object...
                    BMI SET_RETURN          ; /
                    STA $AA,x               ; store y speed
SET_RETURN          RTS                     ; return

SET_SOME_Y_SPEED    LDA $1588,x             ; \ if touching an object...
                    BMI SET_THE_Y_SPEED     ; /
                    LDA #$00                ; \ sprite Y speed = #$00 or #$18
                    LDY $15B8,x             ;  | depending on 15B8,x ???
                    BEQ STORE_Y_SPEED	    ;  | 
SET_THE_Y_SPEED     LDA #$18                ;  | 
STORE_Y_SPEED       STA $AA,x		    ; / 
                    RTS			    ; return 
	
	
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; display smoke effect
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


SUB_SMOKE           LDY #$03                ; \ find a free slot to display effect
FINDFREE            LDA $17C0,y             ;  |
                    BEQ FOUNDONE            ;  |
                    DEY                     ;  |
                    BPL FINDFREE            ;  |
                    RTS                     ; / return if no slots open

FOUNDONE            LDA #$01                ; \ set effect graphic to smoke graphic
                    STA $17C0,y             ; /
                    LDA #$1B                ; \ set time to show smoke
                    STA $17CC,y             ; /
                    LDA $D8,x               ; \ smoke y position = generator y position
                    STA $17C4,y             ; /
                    LDA $E4,x               ; \ load generator x position and store it for later
                    STA $17C8,y             ; /
                    RTS                     ; return


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; spawn sprite routine
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


SPAWN_SPRITE        LDA EXTRA_BITS,x        ; \ generate a custom sprite if the extra bit is set
                    AND #$04                ;  |
                    BNE CUSTOM              ; /

NORMAL		    LDA #$08                ; \ set sprite status for new sprite
                    STA $14C8,x             ; /

                    LDA #SPRITE_TO_GEN      ; \ sprite type
		    STA $9E,x               ; /
		    JSL $87F7D2             ; reset sprite properties
                    BRA SHARED

CUSTOM              LDA #$08                ; \ set sprite status for new sprite
                    STA $14C8,x             ; /

                    LDA #CUST_SPRITE_TO_GEN ; \ sprite type
                    STA NEW_SPRITE_NUM,x    ; /
                    JSL $87F7D2             ; reset sprite properties
                    JSL $8187A7             ; get table values for custom sprite
                    LDA #$88                ; \ mark as initialized
                    STA EXTRA_BITS,x        ; /
  
SHARED		    LDA #$20                ; \ time to disable sprite's contact with Mario
		    STA $154C,x             ; /

		    LDA $D8,x               ; \ set y position (low byte)
		    SEC                     ;  |
		    SBC #$0F                ;  |
		    STA $D8,x               ; /
		    LDA $14D4,x             ; \ set y position (high byte)
		    SBC #$00                ;  |
		    STA $14D4,x             ; /

		    LDA #$00                ; \ set sprite direction depending on Mario's x speed
		    LDY $7B                 ;  | 
		    BPL DIRECTION           ;  |
		    INC A                   ;  |
DIRECTION	    STA $157C,x             ; /

		    LDA #$C0                ; \ set y speed
		    STA $AA,x               ; /

		    LDA #SOUND_TO_GEN3      ; \ sound effect
		    STA $1DFC               ; /
		    RTS                     ; return


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; spawn block routine
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


SPAWN_BLOCK         LDA #SOUND_TO_GEN4      ; \ sound effect
                    STA $1DF9               ; /

                    LDA EXTRA_BITS,x        ; \ generate other block if the extra bit is set
                    AND #$04                ;  |
                    BNE BLOCK2              ; /

                    LDA $E4,x               ; \ setup block properties
                    STA $9A                 ;  |
                    LDA $14E0,x             ;  |
                    STA $9B                 ;  |
                    LDA $D8,x               ;  |
		    SEC                     ;  |
		    SBC #$30                ;  | set higher y position
                    STA $98                 ;  |
                    LDA $14D4,x             ;  |
                    STA $99                 ; /
                  
BLOCK1              PHP
                    REP #$30                ; \ change sprite to block 
                    LDA.W #BLOCK_TILE1      ;  |
                    STA $03                 ;  |
                    JSL SubSetMap16     ;  |
                    PLP                     ; / 
                    BRA END_BLOCK

BLOCK2              LDA $E4,x               ; \ setup block properties
                    STA $9A                 ;  |
                    LDA $14E0,x             ;  |
                    STA $9B                 ;  |
                    LDA $D8,x               ;  |
		    SEC                     ;  |
		    SBC #$30                ;  | set higher y position
                    STA $98                 ;  |
                    LDA $14D4,x             ;  |
                    STA $99                 ; /

                    PHP
                    REP #$30                ; \ change sprite to block 
                    LDA.W #BLOCK_TILE2      ;  |
                    STA $03                 ;  |
                    JSL SubSetMap16      ;  |
                    PLP                     ; / 
END_BLOCK           RTS


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; sprite graphics routine
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

                    ;frame 1, squashed (2 bytes each)
TILE_SIZE           dcb $02,$02,$00,$00
HORZ_DISP           dcb $00,$00,$00,$08
VERT_DISP           dcb $00,$00,$08,$08
TILEMAP             dcb $42,$42,$FE,$FE
PROPERTIES          dcb $40,$00,$00,$40


SUB_GFX             JSL GetDrawInfo      ; after: Y = index to sprite OAM ($0300)      
                    LDA $151C,x             ; \
                    ASL A                   ;  | $03 = index to frame start (frame to show * 2 tile per frame)
                    STA $03                 ; /
                    LDA $157C,x             ; \ $02 = sprite direction
                    STA $02                 ; /
                    PHX                     ; push x

                    LDA $14C8,x             ; \ if the sprite is defeated...
                    CMP #$02                ;  |
                    BNE NO_STAR             ; /
                    LDA #$02                ; \ set squashed image
                    STA $03                 ; /

NO_STAR             LDA $1558,x             ; \ if time to show sprite remains > 0...
                    BEQ NOT_DEAD            ; /
                    LDA #$02                ; \ set squashed image
                    STA $03                 ; /
                    STX $15E9

NOT_DEAD            LDX #$01                ; run loop 2 times, cuz 2 tiles per frame
LOOP_START          PHX                     ; push, current tile

                    TXA                     ; \ X = index of frame start + current tile
                    CLC                     ;  |
                    ADC $03                 ;  |
                    TAX                     ; /

                    PHY                     ; set tile to be 8x8 or 16x16
                    TYA                     ;
                    LSR A                   ;
                    LSR A                   ;
                    TAY                     ;
                    LDA TILE_SIZE,x         ; 
                    STA $0460,y             ;
                    PLY                     ;
                    
                    LDA $00                 ; \ tile x position = sprite x location ($00) + tile displacement
                    CLC                     ;  | 
                    ADC HORZ_DISP,x         ;  |
                    STA $0300,y             ; /
                    
                    LDA $01                 ; \ tile y position = sprite y location ($01) + tile displacement
                    CLC                     ;  | 
                    ADC VERT_DISP,x         ;  |
                    STA $0301,y             ; /

                    LDA TILEMAP,x           ; \ store tile
                    STA $0302,y             ; /

                    PHX                     ;
                    LDX $15E9               ;
                    LDA $15F6,x             ; get palette info
                    PLX                     ;
                    ORA PROPERTIES,x        ; flip tile if necessary
                    ORA $64                 ; add in tile priority of level
                    STA $0303,y             ; store tile properties

                    PLX                     ; \ pull, current tile
                    INY                     ;  | increase index to sprite tile map ($300)...
                    INY                     ;  |    ...we wrote 1 16x16 tile...
                    INY                     ;  |    ...sprite OAM is 8x8...
                    INY                     ;  |    ...so increment 4 times
                    DEX                     ;  | go to next tile of frame and loop
                    BPL LOOP_START          ; /

                    PLX                     ; pull, X = sprite index
                    LDY #$FF                ; \ we've already set 460 so use FF
                    LDA #$01                ;  | A = number of tiles drawn - 1
                    JSL $81B7B3             ; / don't draw if offscreen
                    RTS                     ; return


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; graphics routine 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


HORZ_DISP           dcb $00,$08,$00,$08
VERT_DISP           dcb $00,$00,$08,$08
TILEMAP             dcb $42,$43,$52,$53


CARRIED_GFX         JSL GetDrawInfo      ; after: Y = index to sprite OAM ($300)
                    LDA $151C,x             ; \
                    ASL A                   ;  | $03 = index to frame start (frame to show * 2 tile per frame)
                    STA $03                 ; /
                    LDA $157C,x             ; \ $02 = direction
                    STA $02                 ; / 
                    PHX                     ; push x

                    LDX #$03                ; run loop 4 times, cuz 4 tiles per frame
LOOP_START_2        PHX                     ; push, current tile

                    TXA                     ; \ X = index of frame start + current tile
                    CLC                     ;  |
                    ADC $03                 ;  |
                    TAX                     ; /

                    LDA $00                 ; \ tile x position = sprite x location ($00) + tile displacement
                    CLC                     ;  |
                    ADC HORZ_DISP,x         ;  |
                    STA $0300,y             ; /
                    
                    LDA $01                 ; \
                    CLC                     ;  | tile y position = sprite y location ($01) + tile displacement
                    ADC VERT_DISP,x         ;  |
                    STA $0301,y             ; /

                    LDA TILEMAP,x           ; \ store tile
                    STA $0302,y             ; /

                    PHX                     ;
                    LDX $15E9               ;
                    LDA $15F6,x             ; get palette info
                    PLX                     ;
                    ORA $64                 ; add in tile priority of level
                    STA $0303,y             ; store tile properties

                    PLX                     ; \ pull, current tile
                    INY                     ;  | increase index to sprite tile map ($300)...
                    INY                     ;  |    ...we wrote 1 16x16 tile...
                    INY                     ;  |    ...sprite OAM is 8x8...
                    INY                     ;  |    ...so increment 4 times
                    DEX                     ;  | go to next tile of frame and loop
                    BPL LOOP_START_2        ; /

                    PLX                     ; pull, X = sprite index
                    LDY #$00                ; \ we've already set 460 so use FF
                    LDA #$03                ;  | A = number of tiles drawn - 1
                    JSL $81B7B3             ; / don't draw if offscreen
                    RTS                     ; return 


