So,
is anyone doing a new run currently? Me, TehSeven and thelegendarymudkip started running this game a while back, but we got stuck without recording too much.
I managed to figure out the RNG calculation, so I thought I'd share the info if anyone needs it.
The RNG is located in four bytes at
E4 E5 E6 E7
Every frame, the contents are shifted right one bit. For example
00000
00 111111
11 00000000 11111111
would become
1000000 01111111 10000000 01111111
The new leftmost bit of E4 is created by XORing the second rightmost bit of E4 and E5. Bolded above.
How is the RNG used? This has not been extensively tested, only for the birds in Pharao Man stage. For these, the frame when the egg drops start, the game reads E7 and uses it to determine the random action, in this case the number of eggs to drop. (1 egg 50%, 2 eggs 25%, 3 eggs 25%, in case you wondered.) It then writes to E6 and E7 in an unknown way. Feel free to figure it out. But it's dangerous to go alone, take this:
http://nesdev.com/6502.txt
Can the player influence RNG? Yes. Both directly and indirectly.
- Indirectly, by waiting for one or more frames before scrolling an enemy into view.
- Directly, by shooting and sliding directly after each other. This locks E6 and E7 to a value dependent on which weapon you are using. For example, the mega buster locks to 0x05 0x05 and 0x85 0x05 (switching between them).
I have not seen E4 and E5 being written to. If this is indeed the case it means that all changes to the RNG are temporary, and get shifted out of the RNG in 16 frames.
Since the RNG is otherwise deterministic according to the formula above, it can be detected when the RNG was written to and didn't change as expected. Here's a lua script for FCEUX which does that, marking the addresses which didn't go to the expected value in red:
http://tasvideos.org/userfiles/info/24508776408376192
It's pretty crappy, but it gets the idea across. If you want to improve it you could add lag detection and load state handling. These give false positives at the moment.
Good luck, feel free to ask if something is unclear.