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.

161 lines
2.7KB

  1. ;----------------
  2. ; Program Start
  3. ;----------------
  4. BUFFER EQU 160
  5. TRUE EQU $42
  6. FALSE EQU $69
  7. SECTION "Program Start", ROM0[$150]
  8. Start:
  9. ei
  10. ld a, IEF_VBLANK
  11. ld [rIE], a
  12. xor a
  13. ld [hVBlankFlag], a
  14. call Wait_VBlank
  15. xor a
  16. ldh [rLCDC], a
  17. call Clear_Map
  18. call Load_Tiles
  19. ; call Load_Map
  20. ld a, %11100100
  21. ld [rBGP], a
  22. ld [rOBP0], a
  23. xor a
  24. ld [rSCY], a
  25. ld [rSCX], a
  26. ld [rNR52], a
  27. ld a, LCDCF_ON | LCDCF_OBJON | LCDCF_BGON
  28. ld [rLCDC], a
  29. call CopyDMARoutine
  30. ld a, 72
  31. ld [rPlayerX], a
  32. ld a, 88
  33. ld [rPlayerY], a
  34. ;----
  35. ; Testing
  36. ;----
  37. ld a, HIGH(ANS)
  38. ld h, a
  39. ld a, LOW(ANS)
  40. ld l, a
  41. ; Case One: Camera@E100 vs Actor@E195 (Pass)
  42. ld a, $E1
  43. ld [N], a
  44. ld a, $E1
  45. ld [X], a
  46. ld a, $00
  47. ld [N+1], a
  48. ld a, $95
  49. ld [X+1], a
  50. call CheckBoundry
  51. ; Case One: Camera@E095 vs Actor@E120 (Pass)
  52. ld a, $E0
  53. ld [N], a
  54. ld a, $E1
  55. ld [X], a
  56. ld a, $95
  57. ld [N+1], a
  58. ld a, $20
  59. ld [X+1], a
  60. call CheckBoundry
  61. ; Case One: Camera@E100 vs Actor@E1FF (Fail)
  62. ld a, $E1
  63. ld [N], a
  64. ld a, $E1
  65. ld [X], a
  66. ld a, $00
  67. ld [N+1], a
  68. ld a, $FF
  69. ld [X+1], a
  70. call CheckBoundry
  71. ; Case One: Camera@E1F0 vs Actor@E2DE (Fail)
  72. ld a, $E1
  73. ld [N], a
  74. ld a, $E2
  75. ld [X], a
  76. ld a, $F0
  77. ld [N+1], a
  78. ld a, $DE
  79. ld [X+1], a
  80. call CheckBoundry
  81. game_loop:
  82. call Wait_VBlank
  83. call Read_Pad
  84. call PC_Update
  85. call Player_To_OAM
  86. ld a, HIGH(wShadowOAM)
  87. call hOAMDMA
  88. jr game_loop
  89. CheckBoundry::
  90. ;-----
  91. ; Check if word X is within BUFFER ahead of N
  92. ; BUFFER is always <= 255
  93. ; hl contains address to save result to
  94. ;-----
  95. ;= load high bytes
  96. ld a, [N]
  97. ld b, a
  98. ld a, [X]
  99. sub b
  100. ;= if carry is set, N is behind X, so skip
  101. jr c, .skipRender
  102. ld b, a
  103. ld a, 2
  104. cp b
  105. ;= if the difference is 2 or greater
  106. ;= we are not within BUFFER, so skip
  107. jr c, .skipRender
  108. jr z, .skipRender
  109. dec a
  110. cp b
  111. ;= if the high byte differ by 1, we
  112. ;= need to check over a a page
  113. jr z, .swap
  114. ;= load the low bytes
  115. ld a, [N+1]
  116. ld b, a
  117. ld a, [X+1]
  118. sub b
  119. ld b, a
  120. ld a, BUFFER
  121. cp b
  122. ;= if the difference is greater than
  123. ;= the buffer, skip
  124. jr c, .skipRender
  125. jr .render
  126. .swap
  127. ;= load the low bytes in the opposite order
  128. ld a, [X+1]
  129. ld b, a
  130. ld a, [N+1]
  131. sub b
  132. ld b, a
  133. ld a, $FF - BUFFER
  134. cp b
  135. ;= if they differ by the inverse of the buffer
  136. ;= they will not be within the gap between pages
  137. jr nc, .skipRender
  138. .render
  139. ;= success, do rendering stuff
  140. ; beep boop rendering stuff
  141. ld a, TRUE
  142. ld [hli], a
  143. ret
  144. .skipRender
  145. ;= failure, skip this one
  146. ; doing other stuff here
  147. ld a, FALSE
  148. ld [hli], a
  149. ret