cfgfile_dwrite_strarr(f, _T("agnusmodel"), agnusmodel, p->cs_agnusmodel);
cfgfile_dwrite_strarr(f, _T("agnussize"), agnussize, p->cs_agnussize);
cfgfile_dwrite_strarr(f, _T("denisemodel"), denisemodel, p->cs_denisemodel);
+ if (p->seed) {
+ cfgfile_write(f, _T("rndseed"), _T("%d"), p->seed);
+ }
if (is_board_enabled(p, ROMTYPE_CD32CART, 0)) {
cfgfile_dwrite_bool(f, _T("cd32fmv"), true);
|| cfgfile_intval(option, value, _T("genlock_mix"), &p->genlock_mix, 1)
|| cfgfile_intval(option, value, _T("keyboard_handshake"), &p->cs_kbhandshake, 1)
|| cfgfile_intval(option, value, _T("eclockphase"), &p->cs_eclockphase, 1)
- || cfgfile_intval(option, value, _T("chipset_rtc_adjust"), &p->cs_rtc_adjust, 1))
+ || cfgfile_intval(option, value, _T("chipset_rtc_adjust"), &p->cs_rtc_adjust, 1)
+ || cfgfile_intval(option, value, _T("rndseed"), &p->seed, 1))
return 1;
if (cfgfile_strval(option, value, _T("comp_trustbyte"), &p->comptrustbyte, compmode, 0)
int cs_denisemodel;
bool cs_memorypatternfill;
bool cs_ipldelay;
+ uae_u32 seed;
struct boardromconfig expansionboard[MAX_EXPANSION_BOARDS];
extern void fetch_datapath(TCHAR *out, int size);
extern void fetch_rompath(TCHAR *out, int size);
extern void fetch_videopath(TCHAR *out, int size);
-extern uae_u32 uaerand (void);
-extern uae_u32 uaesrand (uae_u32 seed);
-extern uae_u32 uaerandgetseed (void);
+extern uae_u32 uaerand(void);
+extern uae_u32 uaesetrandseed(uae_u32 seed);
+extern uae_u32 uaerandgetseed(void);
/* the following prototypes should probably be moved somewhere else */
header_end2 = 0;
if (input_play) {
uae_u32 id;
- zfile_fseek (inprec_zf, 0, SEEK_END);
+ zfile_fseek(inprec_zf, 0, SEEK_END);
inprec_size = zfile_ftell32(inprec_zf);
- zfile_fseek (inprec_zf, 0, SEEK_SET);
+ zfile_fseek(inprec_zf, 0, SEEK_SET);
inprec_buffer = inprec_p = xmalloc (uae_u8, inprec_size);
- zfile_fread (inprec_buffer, inprec_size, 1, inprec_zf);
+ zfile_fread(inprec_buffer, inprec_size, 1, inprec_zf);
inprec_plastptr = inprec_buffer;
id = inprec_pu32();
if (id != 'UAE\0') {
- inprec_close (true);
+ inprec_close(true);
return 0;
}
- int v = inprec_pu8 ();
+ int v = inprec_pu8();
if (v != 3) {
- inprec_close (true);
+ inprec_close(true);
return 0;
}
- inprec_pu8 ();
- inprec_pu8 ();
- inprec_pu8 ();
+ inprec_pu8();
+ inprec_pu8();
+ inprec_pu8();
seed = inprec_pu32();
- seed = uaesrand (seed);
- vsync_counter = inprec_pu32 ();
- hsync_counter = inprec_pu32 ();
- i = inprec_pu32 ();
+ seed = uaesetrandseed(seed);
+ vsync_counter = inprec_pu32();
+ hsync_counter = inprec_pu32();
+ i = inprec_pu32();
while (i-- > 0)
- inprec_pu8 ();
+ inprec_pu8();
header_end = addrdiff(inprec_plastptr, inprec_buffer);
inprec_pstr (savestate_fname);
if (savestate_fname[0]) {
header_end2 = addrdiff(inprec_plastptr, inprec_buffer);
findlast ();
} else if (input_record) {
- seed = uaesrand (seed);
- inprec_buffer = inprec_p = xmalloc (uae_u8, inprec_size);
- inprec_ru32 ('UAE\0');
- inprec_ru8 (3);
- inprec_ru8 (UAEMAJOR);
- inprec_ru8 (UAEMINOR);
- inprec_ru8 (UAESUBREV);
- inprec_ru32 (seed);
- inprec_ru32 (vsync_counter);
- inprec_ru32 (hsync_counter);
- inprec_ru32 (0); // extra header size
+ seed = uaesetrandseed(seed);
+ inprec_buffer = inprec_p = xmalloc(uae_u8, inprec_size);
+ inprec_ru32('UAE\0');
+ inprec_ru8(3);
+ inprec_ru8(UAEMAJOR);
+ inprec_ru8(UAEMINOR);
+ inprec_ru8(UAESUBREV);
+ inprec_ru32(seed);
+ inprec_ru32(vsync_counter);
+ inprec_ru32(hsync_counter);
+ inprec_ru32(0); // extra header size
flush ();
header_end2 = header_end = zfile_ftell32(inprec_zf);
} else {
void inprec_startup (void)
{
- uaesrand (seed);
+ uaesetrandseed(seed);
}
bool inprec_prepare_record (const TCHAR *statefilename)
TCHAR optionsfile[256];
static uae_u32 randseed;
-static int oldhcounter;
-static uae_u32 xorshiftstate = 1;
+static uae_u32 xorshiftstate;
static uae_u32 xorshift32(void)
{
uae_u32 x = xorshiftstate;
return xorshiftstate;
}
-uae_u32 uaesrand(uae_u32 seed)
-{
- oldhcounter = -1;
- randseed = seed;
- return randseed;
-}
uae_u32 uaerand(void)
{
- if (oldhcounter != hsync_counter) {
- xorshiftstate = (hsync_counter ^ randseed) | 1;
- oldhcounter = hsync_counter;
+ if (xorshiftstate == 0) {
+ xorshiftstate = randseed;
+ if (!xorshiftstate) {
+ randseed = 1;
+ xorshiftstate = 1;
+ }
}
uae_u32 r = xorshift32();
return r;
}
+
uae_u32 uaerandgetseed(void)
{
+ if (!randseed) {
+ randseed = 1;
+ xorshiftstate = 1;
+ }
+ return randseed;
+}
+
+uae_u32 uaesetrandseed(uae_u32 seed)
+{
+ if (!seed) {
+ seed = 1;
+ }
+ randseed = seed;
+ xorshiftstate = seed;
return randseed;
}
#ifdef RETROPLATFORM
rp_fixup_options (&currprefs);
#endif
+ if (currprefs.seed == 0) {
+ uae_u32 t = getlocaltime();
+ uaesetrandseed(t);
+ } else {
+ uaesetrandseed(currprefs.seed);
+ }
copy_prefs(&currprefs, &changed_prefs);
target_run ();
/* force sound settings change */
}
cpu_hardreset = false;
cpu_keyboardreset = false;
- hardboot = 0;
event_wait = true;
unset_special(SPCFLAG_MODE_CHANGE);
+ if (!restored && hardboot) {
+ uae_u32 s = uaerandgetseed();
+ uaesetrandseed(s);
+ write_log("rndseed = %08x (%u)\n", s, s);
+ // add random delay before CPU starts
+ int t = uaerand() & 0x7fff;
+ while (t > 255) {
+ x_do_cycles(255 * CYCLE_UNIT);
+ t -= 255;
+ }
+ x_do_cycles(t * CYCLE_UNIT);
+ }
+
+ hardboot = 0;
+
#ifdef SAVESTATE
if (restored) {
restored = 0;