
incsrc subroutinedefs_trasm.asm

dcb "INIT"
	RTL

dcb "MAIN"

	PHB		;\
	PHK		; | Change the data bank to the one our code is running from.
	PLB		; | This is a good practice.
	JSR SpriteCode	; | Jump to the sprite's function.
	PLB		; | Restore old data bank.
	RTL		;/ And return.

;===================================
;Sprite Function
;===================================

RETURN: 	RTS
SpriteCode:	JSR Graphics
		JSL SubOffscreenX0

		LDA $14C8,x		;\
		CMP #$08		; | If sprite dead,
		BNE RETURN		;/ Return.
		LDA $9D			;\
		BNE RETURN		;/ If locked, return.

		JSL $81A7DC
		BCC NoContact
		LDA $7FAB10,x 
		AND #$01
		BNE Hurt_Ball
		LDA #$60
		STA $18BD
		BRA DestroySprite
Hurt_Ball:	JSL $80F5B7
DestroySprite:	LDA #$04
		STA $14C8,x
		LDA #$20
		STA $1540,x
		RTS
NoContact:	LDA #$28
		STA $AA,x
		JSL $81801A
		RTS

;===================================
;Graphics Code
;===================================

TILEMAP: 	dcb $08,$0A
Graphics:	JSL GetDrawInfo 	; Before actually coding the graphics, we need a routine that will get the current sprite's value 
			 	 	; into the OAM.
			  		; The OAM being a place where the tile data for the current sprite will be stored.
		LDA $157C,x
		STA $02			; Store direction to $02 for use with property routine later.

		LDA $00			;\
		STA $0300,y		;/ Draw the X position of the sprite

		LDA $01			;\
		STA $0301,y		;/ Draw the Y position of the sprite

		PHX
		LDA $14
		LSR
		LSR
		LSR
		AND #$01
		TAX
		LDA TILEMAP,x
		STA $0302,y
		PLX			; Pull back X.

		LDA $7FAB10,x 
		AND #$01
		BNE Yellow_Color
		LDA #$2B
		STA $0303,y		; Store to properties byte.
		BRA Fin_Color
Yellow_Color:	LDA #$23
		STA $0303,y		; Store to properties byte.
Fin_Color:
;		INY			;\
;		INY			; | The OAM is 8x8, but our sprite is 16x16 ..
;		INY			; | So increment it 4 times.
;		INY			;/

		LDY #$02		; Y ends with the tile size .. 02 means it's 16x16
		LDA #$00		; A -> number of tiles drawn - 1.
					; I drew only 1 tile so I put in 1-1 = 00.
	
		JSL $81B7B3		; Call the routine that draws the sprite.
		RTS			; Never forget this!

