_PoY

Stuff about RTC - Crystal

Aug 27th, 2016
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.30 KB | None | 0 0
  1. Stuff about RTC, RTA and RNG Manip in Pokémon Crystal [last update : 28/08/2016 #2]
  2. - - - - - - - - - - - - - - - - - - - - - - - - - - -
  3.  
  4. -1) Convert code references
  5. For X an address : (X / $4000):(X % $4000) + $4000
  6.  
  7. 0) Addresses
  8. RTC hour : $ff8f
  9. RTC minute : $ff90
  10. RTC second : $ff91
  11.  
  12. 1) About RTC
  13.  
  14. RTC is the way for some Pokémon Games (Yellow, Gold/Silver/Crystal, else ?) to store the amount of time a player has played the game between each save wipe. This information is not accessible inside the game, but is used to manipulate the RNG. RTC is not directly linked to IGT, because the RTC clock always runs as long as you're "indide" the game : credits, copyright screen, menus. (contrary to IGT that only starts when you reach the overworld after hitting 'New Game', or when the game displays your save data after hitting 'Continue')
  15.  
  16. It being hidden doesn't help with how to estimate it accurately during a run, but (on BGB at least), this timing method is really accurately linked to RTA timing. There still exists delays (consistent ones) that must be denoted :
  17. 1) after clearing a save, there's a delay between when you hit A on the 'Yes' textbox, and when the RTC is actually back to 0.
  18. * the main process about a save wipe is, in part, to fill the 4 SRAM banks with 0s, then the 'Init' function does its job to clear the HRAM where the RTC is stored .
  19. * According to Dabomstew, this takes ~197.052 cycles for each SRAM bank to be cleared. The whole process takes close to 800.000 cycles (788.208 + all the assembly around the SRAM banks wipes).
  20. * the GBC running at ~4.194MHz (or ~4.3MHz ?), we can say it takes ~0.19s for the RTC to be reinitialized.
  21.  
  22. 2) when doing a Hard Reset, it takes time for the bootrom (cgbbios) to play, then to launch the game and to reach the function StartClock.
  23. * so far (manual timings), it takes ~3.22s-3.29s for the RTC to start running again after the Hard Reset button is pressed down.
  24.  
  25. 2) Idea(s) to work around RTC problems
  26.  
  27. RTC behaves even weirder than this (as noted from recent observations). Here's a table to describe if the bootrom counts towards RTC, depending on the situation :
  28. CONTINUE NEW GAME
  29. SAVEFILE YES YES
  30. NO SAVEFILE X NO
  31.  
  32. This leads to considering the chain of events which leads to the potential Roamer manipulation with adaptations to track RTC :
  33. (1) Wipe a save -> Hard Reset -> New Game for LID
  34. (2) -> Hard Reset -> New Game for TID -> Play
  35. (3) -> Hard Reset for Roamer -> 'Continue'
  36.  
  37. (1) has no savefile, and we reset afterwards, so no need to have an RTA timer as an RTC reference for this part.
  38. (2) is the current game session, still without savefile, so bootrom doesn't count towards RTC and it starts after 3.25s as expected.
  39. Start the timer when hitting the Hard Reset button with an offset of -3.25s.
  40. (3) has a savefile, but we hit 'Continue', so the bootrom counts towards RTC. No further RTA modifications needed.
  41.  
  42. For convenience, all the incoming manipulation will reset when RTA is very slightly off the 0th second (~XX:XX:00.10) to ensure the RTC when continuing the game is a full second.
  43.  
  44. ##########################################################
  45. OLD (SEEMS VERY FALSE)
  46.  
  47. The raw scheme of RTC interruptions is described as this :
  48. * start the RTA timer at the moment you hit A on the 'Yes' textbox. This initializes the RTC to 0 and "pauses" it for ~0.19s.
  49. * Hard Reset to manip for the LID. This "pauses" the RTC for ~3.25s.
  50. * Hard Reset to manip for the TID. This "pauses" the RTC for ~3.25s once again.
  51. * Save after you're set up for Raikou/Entei chase in Ecruteak City. For now, it's believed that setting the RTC to a fixed second would be enough to have a "consistent" RNG for DV manipulation. NOTE THAT SAVING DOESN'T STOP THE RTC, SO NO NEED TO SAVE AT A SPECIFIC TIME, only the Hard Reset moment is important (1).
  52.  
  53. Raw setup :
  54. * set RTA timer to -6.69s to balance the RTC pauses described above.
  55. * for every hard reset to manip a Roamer which is strictly after the 1st attempt, substract 3.25s to the RTA to have a "precise" relation between RTA and RTC. (this is tricky to achieve in runs, can Hard Reset twice [6.50s] for the RTA conversion to be a bit more natural)
  56.  
  57. Footnotes :
  58. (1) As far as we know. We don't have a real understanding on how the RTC can completely f*ck our setups (probably never will ?).
Add Comment
Please, Sign In to add comment