From 91279556cdc7604dd7196943ce26434b00e2115b Mon Sep 17 00:00:00 2001 From: Ilari Liusvaara Date: Sat, 12 Nov 2011 00:38:37 +0200 Subject: [PATCH] Control bsnes random seeding Even if bsnes randomness is disabled, the random seed is in savefiles, so control it to make debugging easier. --- ...ow-frontend-to-control-random-number-seed.patch | 53 ++++++++++++++++++++++ manual.lyx | 16 ++++--- src/core/mainloop.cpp | 6 +++ src/core/moviedata.cpp | 3 ++ 4 files changed, 72 insertions(+), 6 deletions(-) create mode 100644 bsnes-patches/0006-Allow-frontend-to-control-random-number-seed.patch diff --git a/bsnes-patches/0006-Allow-frontend-to-control-random-number-seed.patch b/bsnes-patches/0006-Allow-frontend-to-control-random-number-seed.patch new file mode 100644 index 00000000..97453b59 --- /dev/null +++ b/bsnes-patches/0006-Allow-frontend-to-control-random-number-seed.patch @@ -0,0 +1,53 @@ +From 4ecaccfe88f57ee3ba3a91e22aaa40fdebc4655c Mon Sep 17 00:00:00 2001 +From: Ilari Liusvaara +Date: Fri, 11 Nov 2011 19:49:46 +0200 +Subject: [PATCH] Allow frontend to control random number seed + +--- + snes/interface/interface.cpp | 5 +++++ + snes/interface/interface.hpp | 1 + + snes/system/system.cpp | 2 +- + 3 files changed, 7 insertions(+), 1 deletions(-) + +diff --git a/snes/interface/interface.cpp b/snes/interface/interface.cpp +index b3017c9..0a21a13 100755 +--- a/snes/interface/interface.cpp ++++ b/snes/interface/interface.cpp +@@ -23,4 +23,9 @@ time_t Interface::currentTime() + return time(0); + } + ++time_t Interface::randomSeed() ++{ ++ return time(0); ++} ++ + } +diff --git a/snes/interface/interface.hpp b/snes/interface/interface.hpp +index df975e8..30ee7fd 100755 +--- a/snes/interface/interface.hpp ++++ b/snes/interface/interface.hpp +@@ -6,6 +6,7 @@ struct Interface { + virtual string path(Cartridge::Slot slot, const string &hint) = 0; + virtual void message(const string &text); + virtual time_t currentTime(); ++ virtual time_t randomSeed(); + }; + + extern Interface *interface; +diff --git a/snes/system/system.cpp b/snes/system/system.cpp +index 6881810..8583595 100755 +--- a/snes/system/system.cpp ++++ b/snes/system/system.cpp +@@ -147,7 +147,7 @@ void System::unload() { + } + + void System::power() { +- random.seed((unsigned)time(0)); ++ random.seed((unsigned)interface->randomSeed()); + + region = config.region; + expansion = config.expansion_port; +-- +1.7.8.rc0.38.g761c4 + diff --git a/manual.lyx b/manual.lyx index b3508418..5bf54e7e 100644 --- a/manual.lyx +++ b/manual.lyx @@ -3658,28 +3658,32 @@ make ui=ui-libsnes profile=accuracy \end_layout \begin_layout Standard -For Bsnes v084 You need to apply the four patches in bsnes-patches/. +For Bsnes v084 You need to apply the six patches in bsnes-patches/. These fix the following: \end_layout \begin_layout Enumerate -Make libsnes actually compile +Make libsnes actually compile (it won't compile without!) \end_layout \begin_layout Enumerate -Bump the version number to be correct +Bump the version number to be correct (nice to have) \end_layout \begin_layout Enumerate -Make RTC emulation time cleanly overridable +Make RTC emulation time cleanly overridable (needed by games using RTC) \end_layout \begin_layout Enumerate -Save/Load controller state on savestate/loadstate. +Save/Load controller state on savestate/loadstate (many games screw up without) \end_layout \begin_layout Enumerate -Fix unserialization of 64-bit integers. +Fix unserialization of 64-bit integers (needed) +\end_layout + +\begin_layout Enumerate +Allow frontend to control random number seed (just nice to have) \end_layout \begin_layout Subsection diff --git a/src/core/mainloop.cpp b/src/core/mainloop.cpp index fb42d8b4..50aa504a 100644 --- a/src/core/mainloop.cpp +++ b/src/core/mainloop.cpp @@ -33,6 +33,7 @@ #define SPECIAL_NONE 3 void update_movie_state(); +time_t random_seed_value = 0; namespace { @@ -335,6 +336,11 @@ class my_interface : public SNES::Interface return our_movie.rtc_second; } + time_t randomSeed() + { + return random_seed_value; + } + void videoRefresh(const uint32_t* data, bool hires, bool interlace, bool overscan) { last_hires = hires; diff --git a/src/core/moviedata.cpp b/src/core/moviedata.cpp index 4ddf0e37..84a78204 100644 --- a/src/core/moviedata.cpp +++ b/src/core/moviedata.cpp @@ -176,6 +176,8 @@ void do_save_movie(const std::string& filename) throw(std::bad_alloc, std::runti } } +extern time_t random_seed_value; + //Load state from loaded movie file (does not catch errors). void do_load_state(struct moviefile& _movie, int lmode) { @@ -229,6 +231,7 @@ void do_load_state(struct moviefile& _movie, int lmode) rrdata::add_internal(); try { our_rom->region = gtype::toromregion(_movie.gametype); + random_seed_value = _movie.rtc_second; our_rom->load(); if(_movie.is_savestate && lmode != LOAD_STATE_MOVIE) { -- 2.11.4.GIT