mirror of
https://github.com/LIV2/WinUAE.git
synced 2025-12-06 00:12:52 +00:00
Randomize emulator startup state by default, configurable random seed.
This commit is contained in:
parent
af1a4f3ee6
commit
62bace6406
@ -2755,6 +2755,9 @@ void cfgfile_save_options (struct zfile *f, struct uae_prefs *p, int type)
|
||||
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);
|
||||
@ -5971,7 +5974,8 @@ static int cfgfile_parse_hardware (struct uae_prefs *p, const TCHAR *option, TCH
|
||||
|| 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)
|
||||
|
||||
@ -729,6 +729,7 @@ struct uae_prefs {
|
||||
int cs_denisemodel;
|
||||
bool cs_memorypatternfill;
|
||||
bool cs_ipldelay;
|
||||
uae_u32 seed;
|
||||
|
||||
struct boardromconfig expansionboard[MAX_EXPANSION_BOARDS];
|
||||
|
||||
|
||||
@ -86,9 +86,9 @@ extern void fetch_inputfilepath(TCHAR *out, int size);
|
||||
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 */
|
||||
|
||||
|
||||
@ -393,32 +393,32 @@ int inprec_open (const TCHAR *fname, const TCHAR *statefilename)
|
||||
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]) {
|
||||
@ -466,17 +466,17 @@ int inprec_open (const TCHAR *fname, const TCHAR *statefilename)
|
||||
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 {
|
||||
@ -494,7 +494,7 @@ int inprec_open (const TCHAR *fname, const TCHAR *statefilename)
|
||||
|
||||
void inprec_startup (void)
|
||||
{
|
||||
uaesrand (seed);
|
||||
uaesetrandseed(seed);
|
||||
}
|
||||
|
||||
bool inprec_prepare_record (const TCHAR *statefilename)
|
||||
|
||||
39
main.cpp
39
main.cpp
@ -71,9 +71,8 @@ TCHAR warning_buffer[256];
|
||||
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;
|
||||
@ -84,23 +83,35 @@ static uae_u32 xorshift32(void)
|
||||
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;
|
||||
}
|
||||
|
||||
@ -1183,6 +1194,12 @@ static int real_main2 (int argc, TCHAR **argv)
|
||||
#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 */
|
||||
|
||||
16
newcpu.cpp
16
newcpu.cpp
@ -6626,10 +6626,24 @@ void m68k_go (int may_quit)
|
||||
}
|
||||
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;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user