sprite animation testing
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

164 lines
3.2KB

  1. ;----------------
  2. ; Animation Subs
  3. ;----------------
  4. struct Actor
  5. bytes 1, YPos
  6. bytes 1, XPos
  7. bytes 1, GFXCounter
  8. bytes 1, GFXState
  9. words 1, GFXData
  10. bytes 1, TileData
  11. end_struct
  12. SECTION "Actor STructs", WRAM0
  13. dstruct Actor, Player
  14. SECTION "Animation Variables", WRAM0
  15. wCameraX: dw
  16. wCameraY: dw
  17. wWorkingX: dw
  18. wWorkingY: dw
  19. wWorkingScreenX: db
  20. wWorkingScreenY: db
  21. wWorkingState: db
  22. wWorkingCounter: db
  23. wWorkingData: dw
  24. wWorkingTile: db
  25. wWorkingEnd:
  26. SECTION "Animations Subs", ROM0
  27. ; RenderActor:
  28. ; takes a pointer to an actor struct
  29. ; and renders it to shadow OAM, advancinc
  30. ; the animation frame and constructing
  31. ; each frame as needed.
  32. ; initial input:
  33. ; [hl] <- start of Actor Struct in WRAM
  34. ; output:
  35. ; an oam object for each line in the frame data,
  36. ; copied to shadowOAM (wShadowOAM)
  37. RenderActor::
  38. ; @input: hl <- Player
  39. ; @input: de <- ShadowOAM place
  40. ld a, [hli] ; a <- YPos
  41. ld [wWorkingScreenY], a
  42. ld a, [hli] ; a <- XPos
  43. ld [wWorkingScreenX], a
  44. push hl
  45. ld a, [hli] ; a <- GFXCounter
  46. ld [wWorkingCounter], a
  47. ld a, [hli] ; a <- GFXState
  48. ld [wWorkingState], a
  49. ld a, [hli] ; a <- GFXData(Low)
  50. ld [wWorkingData+1], a
  51. ld a, [hli] ; a <- GFXData (High)
  52. ld [wWorkingData], a
  53. ld a, [hl] ; a <- TileData
  54. ld [wWorkingTile], a
  55. ; fin loading data
  56. ld a, [wWorkingData]
  57. ld l, a
  58. ld a, [wWorkingData+1]
  59. ld h, a
  60. ; add actor struct offset saved in wWorkingState
  61. ld a, [wWorkingState]
  62. rlca ; double state offset because of word length
  63. add a, l
  64. ld l, a
  65. adc a, h
  66. sub l
  67. ld h, a ; hl contains state struct pointer
  68. ld a, [hli]
  69. ld b, a
  70. ld a, [hl]
  71. ld l, b
  72. ld h, a
  73. ld a, [hli] ; a <- state frame limit
  74. ld b, a
  75. ld a, [wWorkingCounter]
  76. inc a
  77. ld c, a
  78. ld a, b
  79. ld b, c
  80. cp b
  81. ld a, b
  82. jr nc, .continueAnimation
  83. xor a
  84. .continueAnimation
  85. ; TODO: make counter 0 indexed so doesnt skip first frame
  86. ld [wWorkingCounter], a
  87. ld b, h
  88. ld c, l
  89. pop hl
  90. ld [hl], a
  91. ld h, b
  92. ld l, c
  93. .loopFrameFind
  94. ld b, a ; b <- current frame count
  95. ld a, [hli] ; a <- next frame block
  96. ld c, a
  97. ld a, b
  98. ld b, c
  99. sub b
  100. jr z, .foundFrame
  101. jr c, .foundFrame
  102. inc hl
  103. inc hl
  104. jr .loopFrameFind
  105. .foundFrame
  106. ld a, [hli]
  107. ld b, a
  108. ld a, [hl]
  109. ld h, a
  110. ld l, b ; hl <- pointer to frame data
  111. ld a, [hli]
  112. ld b, a ; b <- sprite counter
  113. .spriteLoop
  114. ; load Y position, then offset by -16
  115. ld a, [hli]
  116. ld c, a
  117. ld a, [wWorkingScreenY]
  118. add c
  119. ld c, 16
  120. add c
  121. ld [de], a ; store YPos in shadowOAM
  122. inc de
  123. ; load X position, then offset by -8
  124. ld a, [hli]
  125. ld c, a
  126. ld a, [wWorkingScreenX]
  127. add c
  128. ld c, 8
  129. add c
  130. ld [de], a ; store YPos in shadowOAM
  131. inc de
  132. ; load tile offset, and add to base tile pointer
  133. ld a, [hli]
  134. ld c, a
  135. ld a, [wWorkingTile]
  136. add c
  137. ld [de], a
  138. inc de
  139. ; load attributes and xor them
  140. ld a, [hli]
  141. ld c, a
  142. ld a, 0 ; TO DO: set base attributes
  143. xor c
  144. ld [de], a
  145. inc de
  146. ; end of single sprite
  147. dec b
  148. jr nz, .spriteLoop
  149. ret
  150. BUFFER EQU 160
  151. TRUE EQU $42
  152. FALSE EQU $69