RNG

In Legend of Kage, the randomness function does not actually take samples of player input, or any other volatile data. Legend of Kage has a function "UpdateRandom" at address $A4E5, that simply multiplies the value of RndSeed (memory address $0F) by 5 and adds 11. It uses the memory address $0E as a temporary, but it does not use its prior value.
The function is called contiguously in an infinite loop by the main program. It's also called manually each time a sample of the RndSeed is taken.
The actual randomness of it comes from the fact that depending on the duration of the NMI (in number of CPU cycles), a different number of iterations of the UpdateRandom function is called. The more time the NMI takes, the less time elapses after the NMI before the next NMI occurs, and thus, the less iterations the UpdateRandom function experiences between the two NMIs.
The duration of the NMI is influenced by everything the game does, including the music, checking for collisions, checking for input, etc. This makes the randomness in Legend of Kage extremely volatile, and extremely non-portable between different emulators. Differences between timings of memory accesses, timings of CPU instructions, timings of DMA transfers, timings of NMI trigger, all timing differences can throw the randomness off.

GameResources/NES/TheLegendOfKage last edited by Randomno on 7/3/2023 1:27 PM
Page History Latest diff List referrers View Source