Advertisement
Nickpips

NES Tetris ARE Logic

Feb 2nd, 2022
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.43 KB | None | 0 0
  1.  
  2. // Original NES PlayState order, including ARE/lineclear states
  3. // 1 Core game logic. When we try to drop a piece, but it can't be dropped, set to state 2 and vramRow should be partially reset
  4. // 2 Waits for VRAM to be okay, locks the piece into playfield (Gameover on failure), and then partially resets the vramRow again
  5. // 3 Waits for VRAM to be okay, and then takes 4 Frames to check for lineclears, then sets vramRow=0 (Which immediately becomes 4 at end of frame)
  6. // 4 is only for lineclears. If a lineclear happens, we wait for "five" iterations, only iterating when frame_count is a multiple of 4
  7. // NOTE: The first progression may happen on the same frame as PlayState 3
  8. // On the fifth iteration, vramRow = 0, but the vram is not updated in that frame
  9. // oooooooooo
  10. // ooooxxoooo <- First progression
  11. // oooxxxxooo <- Second progression
  12. // ooxxxxxxoo <- Third progression
  13. // oxxxxxxxxo <- Fourth progression
  14. // xxxxxxxxxx <- Fifth progression (vramRow will be 0 when this frame finishes)
  15. // 5 happens once in parallel with vram, [Audio is played at this time, and scores are updated]
  16. // 6 happens once in parallel with vram, does nothing in particular
  17. // 7 happens once in parallel with vram, does nothing in particular
  18. // 8 waits for VRAM to be okay, and then takes 1Frame, after which the current piece is ready-to-render and it goes back to 1
  19.  
  20. // Calculating VRAM Delay, based off of a partial reset of vramRow
  21. // Playstates 1/2 will partially update vramRow to be max(y-2, 0), where y is the tetromino location
  22. // VRAM will copy data over, 4 rows at a time, until vramRow >= 20
  23. // Some PlayStates will wait for VRAM to be copied, before acting
  24. // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 y
  25. // 0 0 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 max(y-2, 0)
  26. // ^---------^ ^-----^ ^---------^ ^---------^ ^---^
  27. // 4 3 2 1 0 <- Starts at 0, since it gets copied on that very frame
  28. //
  29. // Thus, partial_vram_delay(y) = 4 - Math.floor(max(y - 2, 0) / 4)
  30.  
  31. // PlayState1: When a piece failed to drop, sets vramRow = max(y-2, 0), and iterates PlayState
  32. // ~ Waiting for partial_vram_delay(y) Dead Frames
  33. // PlayState2: 1 Frame, sets vramRow = max(y-2, 0)
  34. // ~ Waiting for partial_vram_delay(y) Dead Frames
  35. // PlayState3: 4 Frames, sets vramRow = 0
  36. // [vramRow += 4 at the end of this frame, 4 Frames left for vram copy]
  37. // if LineClearingAnimation:
  38. // PlayState4: 5 Frame animation, iteration only on %4 == 0-Frames, which can overlap with End of PlayState3
  39. // vramRow does not get iterated during LineClearingAnimation
  40. // [vramRow = 0 at the end of this frame, 5 Frames left for vram copy]
  41. //
  42. // else:
  43. // Skip this PlayState entirely
  44. // PlayState5: 1 [If LineClearingAnimation, Frame 1 of copy, else Frame 2 of copy]
  45. // PlayState6: 1 [If LineClearingAnimation, Frame 2 of copy, else Frame 3 of copy]
  46. // PlayState7: 1 [If LineClearingAnimation, Frame 3 of copy, else Frame 4 of copy]
  47. // ~ If LineClearingAnimation:
  48. // Waiting for Frame 4 / Frame 5 of copy
  49. // Else:
  50. // Waiting for Frame 5 of copy
  51. // PlayState8: 1 Frame, Now ready to render nextpiece on playfield, with a new nextpiece
  52.  
  53. // Total Delay Math:
  54. // AREState 1 ~ Playing the game
  55. // AREState 2 ~ Do nothing for f_delay(x) Frames, on last Frame inc AREState and decide game-over
  56. // AREState 3 ~ Do Nothing for f_delay(x) + 4 Frames
  57. // AREState 4 ~ Lineclear State:
  58. // Go through 5 states of LineClearingAnimation, make progress only on %4==0 indices
  59. // Progress is allowed to be made, on the last frame of AREState 3
  60. // AREState 5 ~
  61. // If LineClearingAnimation:
  62. // Copy from board, to VRAM, starting at row=0, in groups of 4 [Will take 5 frames]
  63. // Else:
  64. // Do Nothing for 4 Frames
  65. // AREState 6 ~
  66. // On this Frame, make the spawn piece ready-to-render, and reset AREState to 1
  67. //
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement