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.

156 lines
4.4KB

  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. bytes 1, TileData
  10. words 1, GFXData
  11. end_struct
  12. SECTION "Actor STructs", WRAM0
  13. dstruct Actor, Player
  14. dstruct Actor, NPC01
  15. dstruct Actor, NPC02
  16. dstruct Actor, NPC03
  17. dstruct Actor, NPC04
  18. dstruct Actor, NPC05
  19. SECTION "Animation Variables", HRAM
  20. hCameraX: dw
  21. hCameraY: dw
  22. hWorkingX: dw
  23. hWorkingY: dw
  24. hWorkingScreenX: db
  25. hWorkingScreenY: db
  26. hWorkingState: db
  27. hWorkingCounter: db
  28. hWorkingData: dw
  29. hWorkingTile: db
  30. SECTION "Animations Subs", ROM0
  31. ; RenderActor:
  32. ; takes a pointer to an actor struct
  33. ; and renders it to shadow OAM, advancinc
  34. ; the animation frame and constructing
  35. ; each frame as needed.
  36. ; initial input:
  37. ; [hl] <- start of Actor Struct in WRAM
  38. ; output:
  39. ; an oam object for each line in the frame data,
  40. ; copied to shadowOAM (wShadowOAM)
  41. RenderActor::
  42. ; @input: hl <- Player
  43. ; @input: de <- ShadowOAM place
  44. ; clobbers af, bc, de, hl
  45. ld a, [hli] ; a <- YPos
  46. ldh [hWorkingScreenY], a
  47. ld a, [hli] ; a <- XPos
  48. ldh [hWorkingScreenX], a
  49. push hl ; save counter pointer on stack
  50. ld a, [hli] ; a <- GFXCounter
  51. ldh [hWorkingCounter], a
  52. ld a, [hli] ; a <- GFXState
  53. ldh [hWorkingState], a
  54. ld a, [hli] ; a <- TileData
  55. ldh [hWorkingTile], a
  56. ld a, [hli] ; a <- GFXData(Low)
  57. ld h, [hl] ; a <- GFXData (High)
  58. ld l, a
  59. ld a, [hWorkingState] ; add actor struct offset saved in wWorkingState
  60. rlca ; double state offset because of word length
  61. add a, l
  62. ld l, a
  63. adc a, h
  64. sub l
  65. ld h, a ; hl contains state struct pointer
  66. ld a, [hli] ;
  67. ld h, [hl] ; derefence [hl]
  68. ld l, a ;
  69. ld a, [hWorkingCounter]
  70. inc a
  71. ld b, a
  72. ld a, [hli] ; a <- state frame limit
  73. cp b
  74. ld a, b
  75. jr nc, .continueAnimation
  76. xor a
  77. .continueAnimation
  78. ldh [hWorkingCounter], a
  79. ld b, h ;
  80. ld c, l ; save current hl
  81. pop hl ; restore counter wram pointer
  82. ld [hl], a ;
  83. ld h, b ; restore hl
  84. ld l, c ;
  85. ld c, a ; save current frame in c
  86. xor a ; set a = 0
  87. .loopFrameFind ;
  88. ld b, a ; b <- current total
  89. ld a, [hli] ; a <- next frame tick limit
  90. add b ; add to limit
  91. cp c ; compare to limit
  92. jr nc, .foundFrame ; if no carry, cum total > current frame
  93. inc hl
  94. inc hl
  95. jr .loopFrameFind
  96. .foundFrame
  97. ld a, [hli]
  98. ld h, [hl]
  99. ld l, a ; hl <- pointer to frame data
  100. ld a, [hli]
  101. ld b, a ; b <- sprite counter
  102. .spriteLoop
  103. ld a, [hli] ; load Y position, then offset by -16
  104. ld c, a
  105. ld a, [hWorkingScreenY]
  106. add c
  107. ld c, 16
  108. add c
  109. ld [de], a ; store YPos in shadowOAM
  110. inc de
  111. ld a, [hli] ; load X position, then offset by -8
  112. ld c, a
  113. ld a, [hWorkingScreenX]
  114. add c
  115. ld c, 8
  116. add c
  117. ld [de], a ; store XPos in shadowOAM
  118. inc de
  119. ld a, [hli] ; load tile offset, and add to base tile pointer
  120. ld c, a
  121. ld a, [hWorkingTile]
  122. add c
  123. ld [de], a
  124. inc de
  125. ld a, [hli] ; load attributes and xor them
  126. ld c, a
  127. ld a, 0 ; TO DO: set base attributes
  128. xor c
  129. ld [de], a
  130. inc de
  131. dec b ; end of single sprite
  132. jr nz, .spriteLoop
  133. ret