1
AGI Syntax Help / AGI Random Number Generator
« on: November 19, 2017, 12:38:22 AM »
Hi,
I'm trying to crack the RNG behind the slot machine in SQ1 to help someone with a TAS of the game. We've found the code for NAGI's random function:
where agi_rand() calls:
and this seems to be correct some of the time, but not always. JAGI seems to have a completely different function.
Does anyone know how I can find out the random logic used in the actual AGI interpreter?
I'm trying to crack the RNG behind the slot machine in SQ1 to help someone with a TAS of the game. We've found the code for NAGI's random function:
Code: [Select]
u16 diff;
u16 min;
u16 max;
min = *(c++);
max = *(c++);
diff = max - min +1;
state.var[*(c++)] = (agi_rand() % diff) + min;
return c;
where agi_rand() calls:
Code: [Select]
if (agi_rand_seed == 0)
{
//printf("Creating new randomised seed...\n");
/* ah = 0; int(1Ah); */ // number of ticks since midnight
#ifndef RAD_LINUX
_ftime (&t); // time since 1970 but that's ok
#else
ftime(&t);
#endif
//printf("time = %ld seconds %ld milliseconds\n", t.time, t.millitm );
agi_rand_seed = t.time * TANDY_CLOCK_PER_SEC;
agi_rand_seed += (u16) ((double)t.millitm / 1000 * TANDY_CLOCK_PER_SEC);
//printf("seed = 0x%04X\n\n", agi_rand_seed);
}
agi_rand_seed = 0x7C4D * agi_rand_seed + 1;
r = agi_rand_seed ^ (agi_rand_seed>>8);
return( r );
and this seems to be correct some of the time, but not always. JAGI seems to have a completely different function.
Does anyone know how I can find out the random logic used in the actual AGI interpreter?