From 496708cffebb44b02bfad8b3c33a4dc8cf6e6eed Mon Sep 17 00:00:00 2001 From: Tim Allen Date: Mon, 5 Sep 2011 13:56:22 +1000 Subject: [PATCH] Update to v082r03 release. byuu says: Couple more fixes to audio from Jonas, and I converted all types from "unsigned" to the smallest sizes possible, which simplified a bit of the code. Love variable-length integers. Audio core should be really good now. Not perfect, but pretty close for 99% of games. Also fixed the window stuff for Cool World and such. --- bsnes/Makefile | 2 +- bsnes/gameboy/apu/master/master.hpp | 4 ++-- bsnes/gameboy/apu/noise/noise.cpp | 5 ++--- bsnes/gameboy/apu/noise/noise.hpp | 10 +++++----- bsnes/gameboy/apu/square1/square1.cpp | 16 ++++++---------- bsnes/gameboy/apu/square1/square1.hpp | 26 +++++++++++++------------- bsnes/gameboy/apu/square2/square2.cpp | 7 +++---- bsnes/gameboy/apu/square2/square2.hpp | 18 +++++++++--------- bsnes/gameboy/apu/wave/wave.cpp | 17 ++++++++--------- bsnes/gameboy/apu/wave/wave.hpp | 8 ++++---- bsnes/gameboy/gameboy.hpp | 2 +- bsnes/gameboy/lcd/lcd.cpp | 9 +++++++-- bsnes/gameboy/lcd/lcd.hpp | 1 + bsnes/gameboy/lcd/serialization.cpp | 1 + bsnes/snes/snes.hpp | 2 +- 15 files changed, 64 insertions(+), 64 deletions(-) diff --git a/bsnes/Makefile b/bsnes/Makefile index e4f8dd8e..224eeac9 100755 --- a/bsnes/Makefile +++ b/bsnes/Makefile @@ -3,7 +3,7 @@ include nall/Makefile snes := snes gameboy := gameboy profile := accuracy -ui := ui +ui := ui-gameboy # options += console # options += debugger diff --git a/bsnes/gameboy/apu/master/master.hpp b/bsnes/gameboy/apu/master/master.hpp index a2785966..31a1e9f0 100755 --- a/bsnes/gameboy/apu/master/master.hpp +++ b/bsnes/gameboy/apu/master/master.hpp @@ -1,8 +1,8 @@ struct Master { bool left_in_enable; - unsigned left_volume; + uint3 left_volume; bool right_in_enable; - unsigned right_volume; + uint3 right_volume; bool channel4_left_enable; bool channel3_left_enable; bool channel2_left_enable; diff --git a/bsnes/gameboy/apu/noise/noise.cpp b/bsnes/gameboy/apu/noise/noise.cpp index 4a0258e4..7a016fae 100755 --- a/bsnes/gameboy/apu/noise/noise.cpp +++ b/bsnes/gameboy/apu/noise/noise.cpp @@ -13,7 +13,7 @@ void APU::Noise::run() { } } - uint4 sample = (lfsr & 1) ? 0 : volume; + uint4 sample = (lfsr & 1) ? (uint4)0 : volume; if(enable == false) sample = 0; output = (sample * 4369) - 32768; @@ -26,9 +26,8 @@ void APU::Noise::clock_length() { } void APU::Noise::clock_envelope() { - if(envelope_period && --envelope_period == 0) { + if(enable && envelope_frequency && --envelope_period == 0) { envelope_period = envelope_frequency; - if(envelope_period == 0) envelope_period = 8; if(envelope_direction == 0 && volume > 0) volume--; if(envelope_direction == 1 && volume < 15) volume++; } diff --git a/bsnes/gameboy/apu/noise/noise.hpp b/bsnes/gameboy/apu/noise/noise.hpp index 199d380e..f92efbf3 100755 --- a/bsnes/gameboy/apu/noise/noise.hpp +++ b/bsnes/gameboy/apu/noise/noise.hpp @@ -1,18 +1,18 @@ struct Noise { bool enable; - unsigned envelope_volume; + uint4 envelope_volume; bool envelope_direction; - unsigned envelope_frequency; - unsigned frequency; + uint3 envelope_frequency; + uint4 frequency; bool narrow_lfsr; unsigned divisor; bool counter; int16 output; unsigned length; - unsigned envelope_period; - unsigned volume; + uint3 envelope_period; + uint4 volume; unsigned period; uint15 lfsr; diff --git a/bsnes/gameboy/apu/square1/square1.cpp b/bsnes/gameboy/apu/square1/square1.cpp index 09afefd5..e0fb5d20 100755 --- a/bsnes/gameboy/apu/square1/square1.cpp +++ b/bsnes/gameboy/apu/square1/square1.cpp @@ -7,7 +7,7 @@ bool APU::Square1::dac_enable() { void APU::Square1::run() { if(period && --period == 0) { period = 4 * (2048 - frequency); - phase = (phase + 1) & 7; + phase++; switch(duty) { case 0: duty_output = (phase == 6); break; //______-_ case 1: duty_output = (phase >= 6); break; //______-- @@ -16,7 +16,7 @@ void APU::Square1::run() { } } - uint4 sample = (duty_output ? volume : 0); + uint4 sample = (duty_output ? volume : (uint4)0); if(enable == false) sample = 0; output = (sample * 4369) - 32768; @@ -45,20 +45,16 @@ void APU::Square1::clock_length() { } void APU::Square1::clock_sweep() { - if(enable && --sweep_period == 0) { + if(enable && sweep_frequency && --sweep_period == 0) { sweep_period = sweep_frequency; - if(sweep_period == 0) sweep_period = 8; - if(sweep_frequency) { - sweep(1); - sweep(0); - } + sweep(1); + sweep(0); } } void APU::Square1::clock_envelope() { - if(envelope_period && --envelope_period == 0) { + if(enable && envelope_frequency && --envelope_period == 0) { envelope_period = envelope_frequency; - if(envelope_period == 0) envelope_period = 8; if(envelope_direction == 0 && volume > 0) volume--; if(envelope_direction == 1 && volume < 15) volume++; } diff --git a/bsnes/gameboy/apu/square1/square1.hpp b/bsnes/gameboy/apu/square1/square1.hpp index 36048fb8..2b45676f 100755 --- a/bsnes/gameboy/apu/square1/square1.hpp +++ b/bsnes/gameboy/apu/square1/square1.hpp @@ -1,27 +1,27 @@ struct Square1 { bool enable; - unsigned sweep_frequency; - unsigned sweep_direction; - unsigned sweep_shift; + uint3 sweep_frequency; + bool sweep_direction; + uint3 sweep_shift; bool sweep_negate; - unsigned duty; + uint2 duty; unsigned length; - unsigned envelope_volume; - unsigned envelope_direction; - unsigned envelope_frequency; - unsigned frequency; - unsigned counter; + uint4 envelope_volume; + bool envelope_direction; + uint3 envelope_frequency; + uint11 frequency; + bool counter; int16 output; bool duty_output; - unsigned phase; + uint3 phase; unsigned period; - unsigned envelope_period; - unsigned sweep_period; + uint3 envelope_period; + uint3 sweep_period; signed frequency_shadow; bool sweep_enable; - unsigned volume; + uint4 volume; bool dac_enable(); diff --git a/bsnes/gameboy/apu/square2/square2.cpp b/bsnes/gameboy/apu/square2/square2.cpp index 7e29e24a..e75c6d27 100755 --- a/bsnes/gameboy/apu/square2/square2.cpp +++ b/bsnes/gameboy/apu/square2/square2.cpp @@ -7,7 +7,7 @@ bool APU::Square2::dac_enable() { void APU::Square2::run() { if(period && --period == 0) { period = 4 * (2048 - frequency); - phase = (phase + 1) & 7; + phase++; switch(duty) { case 0: duty_output = (phase == 6); break; //______-_ case 1: duty_output = (phase >= 6); break; //______-- @@ -16,7 +16,7 @@ void APU::Square2::run() { } } - uint4 sample = (duty_output ? volume : 0); + uint4 sample = (duty_output ? volume : (uint4)0); if(enable == false) sample = 0; output = (sample * 4369) - 32768; @@ -29,9 +29,8 @@ void APU::Square2::clock_length() { } void APU::Square2::clock_envelope() { - if(envelope_period && --envelope_period == 0) { + if(enable && envelope_frequency && --envelope_period == 0) { envelope_period = envelope_frequency; - if(envelope_period == 0) envelope_period = 8; if(envelope_direction == 0 && volume > 0) volume--; if(envelope_direction == 1 && volume < 15) volume++; } diff --git a/bsnes/gameboy/apu/square2/square2.hpp b/bsnes/gameboy/apu/square2/square2.hpp index f32ac5f9..0a473348 100755 --- a/bsnes/gameboy/apu/square2/square2.hpp +++ b/bsnes/gameboy/apu/square2/square2.hpp @@ -1,20 +1,20 @@ struct Square2 { bool enable; - unsigned duty; + uint2 duty; unsigned length; - unsigned envelope_volume; - unsigned envelope_direction; - unsigned envelope_frequency; - unsigned frequency; - unsigned counter; + uint4 envelope_volume; + bool envelope_direction; + uint3 envelope_frequency; + uint11 frequency; + bool counter; int16 output; bool duty_output; - unsigned phase; + uint3 phase; unsigned period; - unsigned envelope_period; - unsigned volume; + uint3 envelope_period; + uint4 volume; bool dac_enable(); diff --git a/bsnes/gameboy/apu/wave/wave.cpp b/bsnes/gameboy/apu/wave/wave.cpp index 65d6a9dd..8525d0db 100755 --- a/bsnes/gameboy/apu/wave/wave.cpp +++ b/bsnes/gameboy/apu/wave/wave.cpp @@ -3,15 +3,14 @@ void APU::Wave::run() { if(period && --period == 0) { period = 2 * (2048 - frequency); - pattern_offset = (pattern_offset + 1) & 31; - pattern_sample = pattern[pattern_offset]; + pattern_sample = pattern[++pattern_offset]; } uint4 sample = pattern_sample; if(enable == false) sample = 0; output = (sample * 4369) - 32768; - output >>= volume; + output >>= volume_shift; } void APU::Wave::clock_length() { @@ -32,10 +31,10 @@ void APU::Wave::write(unsigned r, uint8 data) { if(r == 2) { //$ff1c NR32 switch((data >> 5) & 3) { - case 0: volume = 16; break; // 0% - case 1: volume = 0; break; //100% - case 2: volume = 1; break; // 50% - case 3: volume = 2; break; // 25% + case 0: volume_shift = 16; break; // 0% + case 1: volume_shift = 0; break; //100% + case 2: volume_shift = 1; break; // 50% + case 3: volume_shift = 2; break; // 25% } } @@ -68,7 +67,7 @@ void APU::Wave::power() { enable = 0; dac_enable = 0; - volume = 0; + volume_shift = 0; frequency = 0; counter = 0; @@ -86,7 +85,7 @@ void APU::Wave::serialize(serializer &s) { s.integer(enable); s.integer(dac_enable); - s.integer(volume); + s.integer(volume_shift); s.integer(frequency); s.integer(counter); s.array(pattern); diff --git a/bsnes/gameboy/apu/wave/wave.hpp b/bsnes/gameboy/apu/wave/wave.hpp index 20b24441..7f8d65d3 100755 --- a/bsnes/gameboy/apu/wave/wave.hpp +++ b/bsnes/gameboy/apu/wave/wave.hpp @@ -2,16 +2,16 @@ struct Wave { bool enable; bool dac_enable; - unsigned volume; - unsigned frequency; + unsigned volume_shift; + uint11 frequency; bool counter; uint8 pattern[32]; int16 output; unsigned length; unsigned period; - unsigned pattern_offset; - unsigned pattern_sample; + uint5 pattern_offset; + uint4 pattern_sample; void run(); void clock_length(); diff --git a/bsnes/gameboy/gameboy.hpp b/bsnes/gameboy/gameboy.hpp index b96d7fc9..3a169f03 100755 --- a/bsnes/gameboy/gameboy.hpp +++ b/bsnes/gameboy/gameboy.hpp @@ -5,7 +5,7 @@ namespace GameBoy { namespace Info { static const char Name[] = "bgameboy"; - static const char Version[] = "000.22"; + static const char Version[] = "000.23"; static unsigned SerializerVersion = 2; } } diff --git a/bsnes/gameboy/lcd/lcd.cpp b/bsnes/gameboy/lcd/lcd.cpp index 9ae975f4..ee2da967 100755 --- a/bsnes/gameboy/lcd/lcd.cpp +++ b/bsnes/gameboy/lcd/lcd.cpp @@ -7,6 +7,8 @@ namespace GameBoy { #include "serialization.cpp" LCD lcd; +static unsigned linectr; + void LCD::Main() { lcd.main(); } @@ -60,6 +62,7 @@ void LCD::frame() { cpu.mmio_joyp_poll(); status.ly = 0; + status.wyc = 0; scheduler.exit(Scheduler::ExitReason::FrameEvent); } @@ -112,8 +115,9 @@ void LCD::render_bg() { } void LCD::render_window() { - if(status.ly - status.wy >= 144U) return; - unsigned iy = status.ly - status.wy; + if(status.ly - status.wy >= 144u) return; + if(status.wx >= 167u) return; + unsigned iy = status.wyc++; unsigned ix = (7 - status.wx) & 255, tx = ix & 7; unsigned data = read_tile(status.window_tilemap_select, ix, iy); @@ -215,6 +219,7 @@ void LCD::power() { for(unsigned n = 0; n < 160 * 144; n++) screen[n] = 0x00; status.lx = 0; + status.wyc = 0; status.display_enable = 0; status.window_tilemap_select = 0; diff --git a/bsnes/gameboy/lcd/lcd.hpp b/bsnes/gameboy/lcd/lcd.hpp index 9bbe5c1a..9ae09d8d 100755 --- a/bsnes/gameboy/lcd/lcd.hpp +++ b/bsnes/gameboy/lcd/lcd.hpp @@ -3,6 +3,7 @@ struct LCD : Processor, MMIO { struct Status { unsigned lx; + unsigned wyc; //$ff40 LCDC bool display_enable; diff --git a/bsnes/gameboy/lcd/serialization.cpp b/bsnes/gameboy/lcd/serialization.cpp index ba85443e..a0f21f64 100755 --- a/bsnes/gameboy/lcd/serialization.cpp +++ b/bsnes/gameboy/lcd/serialization.cpp @@ -2,6 +2,7 @@ void LCD::serialize(serializer &s) { s.integer(status.lx); + s.integer(status.wyc); s.integer(status.display_enable); s.integer(status.window_tilemap_select); diff --git a/bsnes/snes/snes.hpp b/bsnes/snes/snes.hpp index 307271ac..b4b743b8 100755 --- a/bsnes/snes/snes.hpp +++ b/bsnes/snes/snes.hpp @@ -1,7 +1,7 @@ namespace SNES { namespace Info { static const char Name[] = "bsnes"; - static const char Version[] = "082.02"; + static const char Version[] = "082.03"; static const unsigned SerializerVersion = 21; } }