You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
VirtualC64 calls rand() at multiple places. Although the returned sequences are deterministic, this causes issues in run-ahead mode, since both instances would query different numbers and diverge.
TODO: Implement a new Randomizer class that returns a deterministic pseudo-random sequence and instantiate this class in both the main instance and the run-ahead instance.
Fun fact: Bugs related to run-ahead mode result in funny behavior due to diverging emulator instances. In Barry McGuigan World Championship Boxing, I've thought to have knocked out my opponent.
However, this only happened in the run-ahead instance. After the next resync, I've been lying on the ground and lost the fight.
The text was updated successfully, but these errors were encountered:
An easy solution is to derive the pseudo-number directly from the current CPU cycle:
u32
C64::random()
{
returnrandom(u32(cpu.clock));
}
u32
C64::random(u32 seed)
{
// Parameters for the Linear Congruential Generator (LCG)
u64 a = 1664525;
u64 c = 1013904223;
u64 m = 1LL << 32;
// Apply the LCG formulareturnu32((a * seed + c) % m);
}
random() can be used as long as there is only one call per cycle. Otherwise, the same value would be returned twice.
Arrays such as colorRam can be initialized as follows:
// Initialize color RAM with random numbers
u32 seed = 0;
for (isize i = 0; i < isizeof(colorRam); i++) {
seed = c64.random(seed);
colorRam[i] = u8(seed);
}
VirtualC64 calls
rand()
at multiple places. Although the returned sequences are deterministic, this causes issues in run-ahead mode, since both instances would query different numbers and diverge.TODO: Implement a new Randomizer class that returns a deterministic pseudo-random sequence and instantiate this class in both the main instance and the run-ahead instance.
Fun fact: Bugs related to run-ahead mode result in funny behavior due to diverging emulator instances. In Barry McGuigan World Championship Boxing, I've thought to have knocked out my opponent.
However, this only happened in the run-ahead instance. After the next resync, I've been lying on the ground and lost the fight.
The text was updated successfully, but these errors were encountered: