;********************************
;ATALAN nes sprite functions
;********************************
; created by Marcel Cevani 31.01.2011
; added Functions for Sprite controlling
; tnx to Atalan the snake & rudla :)


; Defines for Sprite Pal
type sprPal:array(15)
out oamArray@$0300:array(0..255)

; setMultiSprite var
_SPR_XSIZE:byte
_SPR_YSIZE:byte
_SPR_XPOS:byte
_SPR_YPOS:byte

_TEMPADRSPR:adr
_SPR_NR:byte
_SPR_ANIM_NR:byte
_SPR_ATTR:byte

_SPR_PRECALC:array(7)

out _OAM_INDEX:byte
out _LAST_FRAME_OAM_INDEX:byte

;--------------------------------------------FUNCTIONS FOR SPRITE-MODULE---------------------------------------------
sprLoadPal:proc a@(_a,_x):adr of sprPal @_a @_x @_y @_TEMPADR
resetUnusedSprites:proc @_a @_x @_y
setMultiSprite:proc a@(_a,_x):adr xPos@_SPR_XPOS yPos@_SPR_YPOS sprNr@_SPR_NR sprAnim@_SPR_ANIM_NR sprAttr@_SPR_ATTR @_a @_x @_y @_TEMPADR @_TEMPADRSPR @_SPR_NR @_SPR_XPOS @_SPR_YPOS @_SPR_ATTR @_SPR_XSIZE @_SPR_YSIZE @_OAM_INDEX @_SPR_ANIM_NR @_SPR_PRECALC

;Information: Function write's one sprite to OAM ram
;  Important: For moving more Sprites on the screen,its better to use setMultiSprite
setSprite:proc(<oamnr:byte <nr:byte <palNr:byte <x:byte <y:byte) = 
          index = oamnr * 4
          oamArray(index) = y
          oamArray(index + 1) = nr
          oamArray(index + 2) = palNr
          oamArray(index + 3) = x				