From a92a554d7b58b0a5fedbd21368229877dda27d1a Mon Sep 17 00:00:00 2001 From: Tim Allen Date: Mon, 21 Mar 2011 00:57:55 +1100 Subject: [PATCH] Update to v077r01 release. byuu says: Changelog: - fixed auto joypad polling bug (fixes Super Star Wars start button input) - added pseudo-random class; so far it is RAM only [WRAM, APURAM, VRAM, OAM, CGRAM] - added new system configuration options to bsnes.cfg The pseudo-random class is optional. For right now, I am defaulting it to enabled. bsnes.cfg::snes.random = true. You can of course turn it off if you want. This will break Death Brade and Unnamed Euro Racer, no questions about it. So I don't know if I want to leave this on or off by default. Leaving it on will thwart emulator detection code and help to keep code that relies on uninitialized memory from working, but leaving it off will increase compatibility. --- bsnes/Makefile | 2 +- bsnes/gameboy/apu/wave/wave.cpp | 2 +- bsnes/nall/random.hpp | 18 +++++++++++++----- bsnes/snes/config/config.cpp | 1 + bsnes/snes/config/config.hpp | 1 + bsnes/snes/cpu/cpu.cpp | 2 +- bsnes/snes/cpu/timing/joypad.cpp | 16 ++++++---------- bsnes/snes/ppu/ppu.cpp | 6 +++--- bsnes/snes/random/random.cpp | 18 ++++++++++++++++++ bsnes/snes/random/random.hpp | 11 +++++++++++ bsnes/snes/smp/smp.cpp | 2 +- bsnes/snes/snes.hpp | 4 ++-- bsnes/snes/system/serialization.cpp | 1 + bsnes/snes/system/system.cpp | 3 +++ bsnes/snes/system/system.hpp | 1 + bsnes/ui/config.cpp | 10 ++++++++++ 16 files changed, 74 insertions(+), 24 deletions(-) create mode 100755 bsnes/snes/random/random.cpp create mode 100755 bsnes/snes/random/random.hpp diff --git a/bsnes/Makefile b/bsnes/Makefile index 4af870869..d415b9d8d 100755 --- a/bsnes/Makefile +++ b/bsnes/Makefile @@ -5,7 +5,7 @@ profile := accuracy ui := ui # debugger -options := +options := debugger # compiler c := $(compiler) -std=gnu99 diff --git a/bsnes/gameboy/apu/wave/wave.cpp b/bsnes/gameboy/apu/wave/wave.cpp index bce6f444e..3b0cfb6cf 100755 --- a/bsnes/gameboy/apu/wave/wave.cpp +++ b/bsnes/gameboy/apu/wave/wave.cpp @@ -73,7 +73,7 @@ void APU::Wave::power() { frequency = 0; counter = 0; - random_cyclic r; + random_lfsr r; foreach(n, pattern) n = r() & 15; output = 0; diff --git a/bsnes/nall/random.hpp b/bsnes/nall/random.hpp index 74ebc2d2d..409c45610 100755 --- a/bsnes/nall/random.hpp +++ b/bsnes/nall/random.hpp @@ -8,12 +8,20 @@ namespace nall { return n = (n >> 1) ^ (((n & 1) - 1) & 0xedb88320); } - struct random_cyclic { - unsigned seed; - inline unsigned operator()() { - return seed = (seed >> 1) ^ (((seed & 1) - 1) & 0xedb88320); + struct random_lfsr { + inline void seed(unsigned seed__) { + seed_ = seed__; } - random_cyclic() : seed(0) {} + + inline unsigned operator()() { + return seed_ = (seed_ >> 1) ^ (((seed_ & 1) - 1) & 0xedb88320); + } + + random_lfsr() : seed_(0) { + } + + private: + unsigned seed_; }; } diff --git a/bsnes/snes/config/config.cpp b/bsnes/snes/config/config.cpp index 4c47ccd10..701af94c0 100755 --- a/bsnes/snes/config/config.cpp +++ b/bsnes/snes/config/config.cpp @@ -7,6 +7,7 @@ Configuration::Configuration() { controller_port2 = Input::Device::Joypad; expansion_port = System::ExpansionPortDevice::BSX; region = System::Region::Autodetect; + random = true; cpu.version = 2; cpu.ntsc_frequency = 21477272; //315 / 88 * 6000000 diff --git a/bsnes/snes/config/config.hpp b/bsnes/snes/config/config.hpp index 7188d2092..1f4d037cf 100755 --- a/bsnes/snes/config/config.hpp +++ b/bsnes/snes/config/config.hpp @@ -3,6 +3,7 @@ struct Configuration { Input::Device controller_port2; System::ExpansionPortDevice expansion_port; System::Region region; + bool random; struct CPU { unsigned version; diff --git a/bsnes/snes/cpu/cpu.cpp b/bsnes/snes/cpu/cpu.cpp index 477cc8096..55cf37614 100755 --- a/bsnes/snes/cpu/cpu.cpp +++ b/bsnes/snes/cpu/cpu.cpp @@ -124,7 +124,7 @@ void CPU::enable() { void CPU::power() { cpu_version = config.cpu.version; - foreach(n, wram) n = config.cpu.wram_init_value; + foreach(n, wram) n = random(config.cpu.wram_init_value); regs.a = regs.x = regs.y = 0x0000; regs.s = 0x01ff; diff --git a/bsnes/snes/cpu/timing/joypad.cpp b/bsnes/snes/cpu/timing/joypad.cpp index 145942e44..bd694b339 100755 --- a/bsnes/snes/cpu/timing/joypad.cpp +++ b/bsnes/snes/cpu/timing/joypad.cpp @@ -2,18 +2,12 @@ //called every 256 clocks; see CPU::add_clocks() void CPU::step_auto_joypad_poll() { - if(vcounter() >= (ppu.overscan() == false ? 225 : 240) && status.auto_joypad_counter <= 16) { - if(status.auto_joypad_counter == 0) { - status.auto_joypad_active = true; - input.poll(); - } else if(status.auto_joypad_counter == 16) { - status.auto_joypad_active = false; - return; - } + if(vcounter() >= (ppu.overscan() == false ? 225 : 240)) { + status.auto_joypad_active = status.auto_joypad_counter <= 15; - status.auto_joypad_counter++; + if(status.auto_joypad_active && status.auto_joypad_poll) { + if(status.auto_joypad_counter == 0) input.poll(); - if(status.auto_joypad_poll) { uint8 port0 = input.port_read(0); uint8 port1 = input.port_read(1); @@ -22,6 +16,8 @@ void CPU::step_auto_joypad_poll() { status.joy3 = (status.joy3 << 1) | (bool)(port0 & 2); status.joy4 = (status.joy4 << 1) | (bool)(port1 & 2); } + + status.auto_joypad_counter++; } } diff --git a/bsnes/snes/ppu/ppu.cpp b/bsnes/snes/ppu/ppu.cpp index fe4d1fe24..44352b3a3 100755 --- a/bsnes/snes/ppu/ppu.cpp +++ b/bsnes/snes/ppu/ppu.cpp @@ -91,9 +91,9 @@ void PPU::power() { ppu1_version = config.ppu1.version; ppu2_version = config.ppu2.version; - foreach(n, vram) n = 0x00; - foreach(n, oam) n = 0x00; - foreach(n, cgram) n = 0x00; + foreach(n, vram) n = random(0x00); + foreach(n, oam) n = random(0x00); + foreach(n, cgram) n = random(0x00); reset(); } diff --git a/bsnes/snes/random/random.cpp b/bsnes/snes/random/random.cpp new file mode 100755 index 000000000..a92a980aa --- /dev/null +++ b/bsnes/snes/random/random.cpp @@ -0,0 +1,18 @@ +Random random; + +void Random::seed(unsigned seed_iter) { + iter = seed_iter; +} + +unsigned Random::operator()(unsigned result) { + if(config.random == false) return result; + return iter = (iter >> 1) ^ (((iter & 1) - 1) & 0xedb88320); +} + +void Random::serialize(serializer &s) { + s.integer(iter); +} + +Random::Random() { + iter = 0; +} diff --git a/bsnes/snes/random/random.hpp b/bsnes/snes/random/random.hpp new file mode 100755 index 000000000..927d71725 --- /dev/null +++ b/bsnes/snes/random/random.hpp @@ -0,0 +1,11 @@ +struct Random { + void seed(unsigned seed); + unsigned operator()(unsigned result = 0); + void serialize(serializer&); + Random(); + +private: + unsigned iter; +}; + +extern Random random; diff --git a/bsnes/snes/smp/smp.cpp b/bsnes/snes/smp/smp.cpp index 791fffe1b..6bb2a68f0 100755 --- a/bsnes/snes/smp/smp.cpp +++ b/bsnes/snes/smp/smp.cpp @@ -71,7 +71,7 @@ void SMP::reset() { regs.sp = 0xef; regs.p = 0x02; - foreach(n, apuram) n = 0x00; + foreach(n, apuram) n = random(0x00); status.clock_counter = 0; status.dsp_counter = 0; diff --git a/bsnes/snes/snes.hpp b/bsnes/snes/snes.hpp index f8520bcdc..6375e249b 100755 --- a/bsnes/snes/snes.hpp +++ b/bsnes/snes/snes.hpp @@ -1,8 +1,8 @@ namespace SNES { namespace Info { static const char Name[] = "bsnes"; - static const char Version[] = "077"; - static const unsigned SerializerVersion = 18; + static const char Version[] = "077.01"; + static const unsigned SerializerVersion = 19; } } diff --git a/bsnes/snes/system/serialization.cpp b/bsnes/snes/system/serialization.cpp index 7e3820d24..693247dd4 100755 --- a/bsnes/snes/system/serialization.cpp +++ b/bsnes/snes/system/serialization.cpp @@ -51,6 +51,7 @@ void System::serialize(serializer &s) { void System::serialize_all(serializer &s) { cartridge.serialize(s); system.serialize(s); + random.serialize(s); cpu.serialize(s); smp.serialize(s); ppu.serialize(s); diff --git a/bsnes/snes/system/system.cpp b/bsnes/snes/system/system.cpp index 03c7e3287..e22e5514b 100755 --- a/bsnes/snes/system/system.cpp +++ b/bsnes/snes/system/system.cpp @@ -8,6 +8,7 @@ System system; #include #include #include +#include #include #include @@ -147,6 +148,8 @@ void System::unload() { } void System::power() { + random.seed(0x62797575); + region = config.region; expansion = config.expansion_port; if(region == Region::Autodetect) { diff --git a/bsnes/snes/system/system.hpp b/bsnes/snes/system/system.hpp index 2382de8de..8bfbeddc1 100755 --- a/bsnes/snes/system/system.hpp +++ b/bsnes/snes/system/system.hpp @@ -51,5 +51,6 @@ private: #include #include #include +#include extern System system; diff --git a/bsnes/ui/config.cpp b/bsnes/ui/config.cpp index a23518155..df3a78a0c 100755 --- a/bsnes/ui/config.cpp +++ b/bsnes/ui/config.cpp @@ -9,6 +9,16 @@ void Configuration::save() { } void Configuration::create() { + attach(SNES::config.random, "snes.random"); + attach(SNES::config.cpu.version, "snes.cpu.version"); + attach(SNES::config.cpu.ntsc_frequency, "snes.cpu.ntscFrequency"); + attach(SNES::config.cpu.pal_frequency, "snes.cpu.palFrequency"); + attach(SNES::config.smp.ntsc_frequency, "snes.smp.ntscFrequency"); + attach(SNES::config.smp.pal_frequency, "snes.smp.palFrequency"); + attach(SNES::config.ppu1.version, "snes.ppu1.version"); + attach(SNES::config.ppu2.version, "snes.ppu2.version"); + attach(SNES::config.superfx.speed, "snes.superfx.speed"); + attach(video.driver = "", "video.driver"); attach(video.synchronize = false, "video.synchronize"); attach(video.smooth = true, "video.smooth");