[GSF] Some more code cleanup, also removed a few files that were unneeded.
--- a/src/in_gsf/in_gsf.vcxproj
+++ b/src/in_gsf/in_gsf.vcxproj
@@ -49,7 +49,7 @@
<ClCompile>
<WarningLevel>Level4</WarningLevel>
<Optimization>Disabled</Optimization>
- <PreprocessorDefinitions>WIN32;_WINDOWS;_USRDLL;IN_GSF_EXPORTS;_CRT_SECURE_NO_WARNINGS;WINAMP_PLUGIN;NO_DEBUGGER;FINAL_VERSION;_DEBUG;_ITERATOR_DEBUG_LEVEL=0;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <PreprocessorDefinitions>WIN32;_WINDOWS;_USRDLL;IN_GSF_EXPORTS;_CRT_SECURE_NO_WARNINGS;WINAMP_PLUGIN;NO_DEBUGGER;FINAL_VERSION;C_CORE;_DEBUG;_ITERATOR_DEBUG_LEVEL=0;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>G:\Code\my_xsf\src;$(zlibRootDir)\include;$(WinampSDKDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<DisableSpecificWarnings>4100;4127;4189;4244;4291;4310;4512;4800;%(DisableSpecificWarnings)</DisableSpecificWarnings>
</ClCompile>
@@ -66,7 +66,7 @@
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
- <PreprocessorDefinitions>WIN32;_WINDOWS;_USRDLL;IN_GSF_EXPORTS;_CRT_SECURE_NO_WARNINGS;WINAMP_PLUGIN;NO_DEBUGGER;FINAL_VERSION;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <PreprocessorDefinitions>WIN32;_WINDOWS;_USRDLL;IN_GSF_EXPORTS;_CRT_SECURE_NO_WARNINGS;WINAMP_PLUGIN;NO_DEBUGGER;FINAL_VERSION;C_CORE;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>G:\Code\my_xsf\src;$(zlibRootDir)\include;$(WinampSDKDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<DisableSpecificWarnings>4100;4127;4189;4244;4291;4310;4512;4800;%(DisableSpecificWarnings)</DisableSpecificWarnings>
</ClCompile>
@@ -81,7 +81,9 @@
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="vbam\apu\Blip_Buffer.cpp" />
- <ClCompile Include="vbam\apu\Effects_Buffer.cpp" />
+ <ClCompile Include="vbam\apu\Effects_Buffer.cpp">
+ <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
+ </ClCompile>
<ClCompile Include="vbam\apu\Gb_Apu.cpp" />
<ClCompile Include="vbam\apu\Gb_Oscs.cpp" />
<ClCompile Include="vbam\apu\Multi_Buffer.cpp" />
@@ -97,7 +99,6 @@
<ItemGroup>
<ClInclude Include="vbam\apu\blargg_common.h" />
<ClInclude Include="vbam\apu\blargg_config.h" />
- <ClInclude Include="vbam\apu\blargg_source.h" />
<ClInclude Include="vbam\apu\Blip_Buffer.h" />
<ClInclude Include="vbam\apu\Effects_Buffer.h" />
<ClInclude Include="vbam\apu\Gb_Apu.h" />
--- a/src/in_gsf/in_gsf.vcxproj.filters
+++ b/src/in_gsf/in_gsf.vcxproj.filters
@@ -83,9 +83,6 @@
<ClInclude Include="vbam\apu\blargg_config.h">
<Filter>Header Files\vbam\apu</Filter>
</ClInclude>
- <ClInclude Include="vbam\apu\blargg_source.h">
- <Filter>Header Files\vbam\apu</Filter>
- </ClInclude>
<ClInclude Include="vbam\apu\Blip_Buffer.h">
<Filter>Header Files\vbam\apu</Filter>
</ClInclude>
--- a/src/in_gsf/vbam/apu/Blip_Buffer.cpp
+++ b/src/in_gsf/vbam/apu/Blip_Buffer.cpp
@@ -1,12 +1,11 @@
// Blip_Buffer 0.4.1. http://www.slack.net/~ant/
-
-#include "Blip_Buffer.h"
#include <numeric>
#include <cassert>
#include <cmath>
#include <cstring>
#include <cstdlib>
+#include "Blip_Buffer.h"
/* Copyright (C) 2003-2007 Shay Green. This module is free software; you
can redistribute it and/or modify it under the terms of the GNU Lesser
@@ -23,7 +22,7 @@
Blip_Buffer::Blip_Buffer()
{
- this->factor_ = LONG_MAX;
+ this->factor_ = static_cast<uint32_t>(LONG_MAX);
this->buffer_.clear();
this->buffer_size_ = 0;
this->sample_rate_ = 0;
@@ -62,7 +61,7 @@
}
}
-Blip_Buffer::blargg_err_t Blip_Buffer::set_sample_rate(long new_rate, int msec)
+void Blip_Buffer::set_sample_rate(long new_rate, int msec)
{
// start with maximum length that resampled time can represent
long new_size = (ULONG_MAX >> BLIP_BUFFER_ACCURACY) - blip_buffer_extra_ - 64;
@@ -92,8 +91,6 @@
this->bass_freq(this->bass_freq_);
this->clear();
-
- return 0; // success
}
blip_resampled_time_t Blip_Buffer::clock_rate_factor(long rate) const
@@ -153,7 +150,7 @@
// copy remaining samples to beginning and clear old samples
long remain = this->samples_avail() + blip_buffer_extra_;
memmove(&this->buffer_[0], &this->buffer_[count], remain * sizeof(this->buffer_[0]));
- memset(&this->buffer_[0] + remain, 0, count * sizeof(this->buffer_[0]));
+ memset(&this->buffer_[remain], 0, count * sizeof(this->buffer_[0]));
}
}
@@ -182,8 +179,9 @@
this->delta_factor = 0;
}
-#undef M_PI
+#ifndef M_PI
static const double M_PI = 3.1415926535897932384626433832795029;
+#endif
static void gen_sinc(float *out, int count, double oversample, double treble, double cutoff)
{
@@ -251,7 +249,7 @@
}
//for (int i = blip_res; i--; printf("\n"))
- //for (int j = 0; j < width / 2; ++j)
+ //for (int j = 0; j < this->width / 2; ++j)
//printf("%5ld,", this->impulses[j * blip_res + i + 1]);
}
@@ -259,7 +257,7 @@
{
float fimpulse[blip_res / 2 * (blip_widest_impulse_ - 1) + blip_res * 2];
- static const int half_size = blip_res / 2 * (this->width - 1);
+ int half_size = blip_res / 2 * (this->width - 1);
eq.generate(&fimpulse[blip_res], half_size);
int i;
@@ -376,7 +374,7 @@
{
auto out = &this->buffer_[(this->offset_ >> BLIP_BUFFER_ACCURACY) + blip_widest_impulse_ / 2];
- int sample_shift = blip_sample_bits - 16;
+ static const int sample_shift = blip_sample_bits - 16;
int prev = 0;
while (count--)
{
--- a/src/in_gsf/vbam/apu/Blip_Buffer.h
+++ b/src/in_gsf/vbam/apu/Blip_Buffer.h
@@ -17,12 +17,10 @@
class Blip_Buffer
{
public:
- typedef const char *blargg_err_t;
-
// Sets output sample rate and buffer length in milliseconds (1/1000 sec, defaults
// to 1/4 second) and clears buffer. If there isn't enough memory, leaves buffer
// untouched and returns "Out of memory", otherwise returns NULL.
- blargg_err_t set_sample_rate(long samples_per_sec, int msec_length = 1000 / 4);
+ void set_sample_rate(long samples_per_sec, int msec_length = 1000 / 4);
// Sets number of source time units per second
void clock_rate(long clocks_per_sec);
@@ -96,8 +94,6 @@
// Deprecated
typedef blip_resampled_time_t resampled_time_t;
- blargg_err_t sample_rate(long r) { return this->set_sample_rate(r); }
- blargg_err_t sample_rate(long r, int msec) { return this->set_sample_rate(r, msec); }
private:
// noncopyable
Blip_Buffer(const Blip_Buffer &);
@@ -116,7 +112,6 @@
int bass_freq_;
int length_;
Blip_Buffer *modified_; // non-zero = true (more optimal than using bool, heh)
- friend class Blip_Reader;
};
// Number of bits in resample ratio fraction. Higher values give a more accurate ratio
@@ -282,8 +277,6 @@
// experimental
#define BLIP_READER_ADJ_(name, offset) (name##_reader_buf += offset)
-const int32_t blip_reader_idx_factor = sizeof(Blip_Buffer::buf_t_);
-
#define BLIP_READER_NEXT_IDX_(name, bass, idx) \
{ \
name##_reader_accum -= name##_reader_accum >> (bass); \
@@ -292,14 +285,9 @@
#define BLIP_READER_NEXT_RAW_IDX_(name, bass, idx) \
{ \
- name##_reader_accum -= name##_reader_accum >> (bass);\
- name##_reader_accum += *reinterpret_cast<const Blip_Buffer::buf_t_ *>(reinterpret_cast<const char *>(name##_reader_buf) + (idx));\
-}
-
-// Compatibility with older version
-const long blip_unscaled = 65535;
-const int blip_low_quality = blip_med_quality;
-const int blip_best_quality = blip_high_quality;
+ name##_reader_accum -= name##_reader_accum >> (bass); \
+ name##_reader_accum += *reinterpret_cast<const Blip_Buffer::buf_t_ *>(reinterpret_cast<const char *>(name##_reader_buf) + (idx)); \
+}
#if defined(_M_IX86) || defined(_M_IA64) || defined(__i486__) || defined(__x86_64__) || defined(__ia64__) || defined(__i386__)
template<typename T> inline bool BLIP_CLAMP_(const T &in) { return in < -0x8000 || 0x7FFF < in; }
@@ -338,7 +326,7 @@
// sub-sample resolution.
int32_t right = (delta >> BLIP_PHASE_BITS) * phase;
left -= right;
- right += buf [1];
+ right += buf[1];
buf[0] = left;
buf[1] = right;
--- a/src/in_gsf/vbam/apu/Effects_Buffer.cpp
+++ /dev/null
@@ -1,610 +1,1 @@
-// Game_Music_Emu $vers. http://www.slack.net/~ant/
-#include "Effects_Buffer.h"
-
-#include <cmath>
-#include <cstring>
-
-/* Copyright (C) 2006-2007 Shay Green. This module is free software; you
-can redistribute it and/or modify it under the terms of the GNU Lesser
-General Public License as published by the Free Software Foundation; either
-version 2.1 of the License, or (at your option) any later version. This
-module is distributed in the hope that it will be useful, but WITHOUT ANY
-WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
-FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
-details. You should have received a copy of the GNU Lesser General Public
-License along with this module; if not, write to the Free Software Foundation,
-Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */
-
-#include "blargg_source.h"
-
-static const int fixed_shift = 12;
-template<typename T> static inline Effects_Buffer::fixed_t TO_FIXED(const T &f) { return static_cast<Effects_Buffer::fixed_t>(f * (static_cast<Effects_Buffer::fixed_t>(1) << fixed_shift)); }
-static inline Effects_Buffer::fixed_t FROM_FIXED(Effects_Buffer::fixed_t f) { return f >> fixed_shift; }
-
-static const int max_read = 2560; // determines minimum delay
-
-Effects_Buffer::Effects_Buffer(int max_bufs, long echo_size_) : Multi_Buffer(stereo)
-{
- this->echo_size = std::max<long>(max_read * stereo, echo_size_ & ~1);
- this->clock_rate_ = 0;
- this->bass_freq_ = 90;
- this->bufs.clear();
- this->bufs_size = 0;
- this->bufs_max = std::max<int>(max_bufs, extra_chans);
- this->no_echo = this->no_effects = true;
-
- // defaults
- this->config_.enabled = false;
- this->config_.delay[0] = 120;
- this->config_.delay[1] = 122;
- this->config_.feedback = 0.2f;
- this->config_.treble = 0.4f;
-
- static const float sep = 0.8f;
- this->config_.side_chans[0].pan = -sep;
- this->config_.side_chans[1].pan = sep;
- this->config_.side_chans[0].vol = this->config_.side_chans[1].vol = 1.0f;
-
- memset(&this->s, 0, sizeof(this->s));
- this->clear();
-}
-
-Effects_Buffer::~Effects_Buffer()
-{
- this->delete_bufs();
-}
-
-// avoid using new []
-blargg_err_t Effects_Buffer::new_bufs(int size)
-{
- this->delete_bufs();
- this->bufs.resize(size);
- for (int i = 0; i < size; ++i)
- this->bufs[i].reset(new buf_t);
- this->bufs_size = size;
- return 0;
-}
-
-void Effects_Buffer::delete_bufs()
-{
- this->bufs.clear();
- this->bufs_size = 0;
-}
-
-blargg_err_t Effects_Buffer::set_sample_rate(long rate, int msec)
-{
- // extra to allow farther past-the-end pointers
- this->mixer.samples_read = 0;
- this->echo.resize(echo_size + stereo);
- return Multi_Buffer::set_sample_rate(rate, msec);
-}
-
-void Effects_Buffer::clock_rate(long rate)
-{
- this->clock_rate_ = rate;
- for (int i = this->bufs_size; --i >= 0; )
- this->bufs[i]->clock_rate(this->clock_rate_);
-}
-
-void Effects_Buffer::bass_freq(int freq)
-{
- this->bass_freq_ = freq;
- for (int i = this->bufs_size; --i >= 0; )
- this->bufs[i]->bass_freq(this->bass_freq_);
-}
-
-blargg_err_t Effects_Buffer::set_channel_count(int count, const int *types)
-{
- Multi_Buffer::set_channel_count(count, types);
-
- this->delete_bufs();
-
- this->mixer.samples_read = 0;
-
- this->chans.resize(count + extra_chans);
-
- this->new_bufs(std::min(this->bufs_max, count + extra_chans));
-
- for (int i = this->bufs_size; --i >= 0; )
- RETURN_ERR(this->bufs[i]->set_sample_rate(this->sample_rate(), this->length()));
-
- for (int i = this->chans.size(); --i >= 0; )
- {
- auto &ch = this->chans[i];
- ch.cfg.vol = 1.0f;
- ch.cfg.pan = 0.0f;
- ch.cfg.surround = ch.cfg.echo = false;
- }
- // side channels with echo
- this->chans[2].cfg.echo = this->chans[3].cfg.echo = true;
-
- this->clock_rate(this->clock_rate_);
- this->bass_freq(this->bass_freq_);
- this->apply_config();
- this->clear();
-
- return 0;
-}
-
-void Effects_Buffer::clear_echo()
-{
- if (!this->echo.empty())
- memset(&this->echo[0], 0, this->echo.size() * sizeof(echo[0]));
-}
-
-void Effects_Buffer::clear()
-{
- this->echo_pos = 0;
- this->s.low_pass[0] = this->s.low_pass[1] = 0;
- this->mixer.samples_read = 0;
-
- for (int i = this->bufs_size; --i >= 0; )
- this->bufs[i]->clear();
- this->clear_echo();
-}
-
-auto Effects_Buffer::channel(int i) -> channel_t
-{
- i += extra_chans;
- assert(extra_chans <= i && i < static_cast<int>(this->chans.size()));
- return this->chans[i].channel;
-}
-
-// Configuration
-
-// 3 wave positions with/without surround, 2 multi (one with same config as wave)
-static const int simple_bufs = 3 * 2 + 2 - 1;
-
-Simple_Effects_Buffer::Simple_Effects_Buffer() : Effects_Buffer(extra_chans + simple_bufs, 18 * 1024L)
-{
- this->config_.echo = 0.20f;
- this->config_.stereo = 0.20f;
- this->config_.surround = true;
- this->config_.enabled = false;
-}
-
-void Simple_Effects_Buffer::apply_config()
-{
- auto &c = Effects_Buffer::config();
-
- c.enabled = this->config_.enabled;
- if (c.enabled)
- {
- c.delay[0] = 120;
- c.delay[1] = 122;
- c.feedback = this->config_.echo * 0.7f;
- c.treble = 0.6f - 0.3f * this->config_.echo;
-
- float sep = this->config_.stereo + 0.80f;
- if (sep > 1.0f)
- sep = 1.0f;
-
- c.side_chans[0].pan = -sep;
- c.side_chans[1].pan = sep;
-
- for (int i = this->channel_count(); --i >= 0; )
- {
- auto &ch = Effects_Buffer::chan_config(i);
-
- ch.pan = 0.0f;
- ch.surround = this->config_.surround;
- ch.echo = false;
-
- int type = this->channel_types() ? this->channel_types()[i] : 0;
- if (!(type & noise_type))
- {
- int index = (type & type_index_mask) % 6 - 3;
- if (index < 0)
- {
- index += 3;
- ch.surround = false;
- ch.echo = true;
- }
- if (index >= 1)
- {
- ch.pan = this->config_.stereo;
- if (index == 1)
- ch.pan = -ch.pan;
- }
- }
- else if (type & 1)
- ch.surround = false;
- }
- }
-
- Effects_Buffer::apply_config();
-}
-
-int Effects_Buffer::min_delay() const
-{
- assert(this->sample_rate());
- return max_read * 1000L / this->sample_rate();
-}
-
-int Effects_Buffer::max_delay() const
-{
- assert(this->sample_rate());
- return (this->echo_size / stereo - max_read) * 1000L / this->sample_rate();
-}
-
-void Effects_Buffer::apply_config()
-{
- if (!this->bufs_size)
- return;
-
- this->s.treble = TO_FIXED(this->config_.treble);
-
- bool echo_dirty = false;
-
- fixed_t old_feedback = this->s.feedback;
- this->s.feedback = TO_FIXED(this->config_.feedback);
- if (!old_feedback && this->s.feedback)
- echo_dirty = true;
-
- // delays
- int i;
- for (i = stereo; --i >= 0;)
- {
- long delay = this->config_.delay[i] * this->sample_rate() / 1000 * stereo;
- delay = std::max<long>(delay, max_read * stereo);
- delay = std::min<long>(delay, this->echo_size - max_read * stereo);
- if (this->s.delay[i] != delay)
- {
- this->s.delay[i] = delay;
- echo_dirty = true;
- }
- }
-
- // side channels
- for (i = 2; --i >= 0; )
- {
- this->chans[i + 2].cfg.vol = this->chans[i].cfg.vol = this->config_.side_chans[i].vol * 0.5f;
- this->chans[i + 2].cfg.pan = this->chans[i].cfg.pan = this->config_.side_chans[i].pan;
- }
-
- // convert volumes
- for (i = this->chans.size(); --i >= 0; )
- {
- auto &ch = this->chans[i];
- ch.vol[0] = TO_FIXED(ch.cfg.vol - ch.cfg.vol * ch.cfg.pan);
- ch.vol[1] = TO_FIXED(ch.cfg.vol + ch.cfg.vol * ch.cfg.pan);
- if (ch.cfg.surround)
- ch.vol[0] = -ch.vol [0];
- }
-
- this->assign_buffers();
-
- // set side channels
- for (i = this->chans.size(); --i >= 0; )
- {
- auto &ch = chans[i];
- ch.channel.left = this->chans[ch.cfg.echo * 2].channel.center;
- ch.channel.right = this->chans[ch.cfg.echo * 2 + 1].channel.center;
- }
-
- bool old_echo = !this->no_echo && !this->no_effects;
-
- // determine whether effects and echo are needed at all
- this->no_effects = this->no_echo = true;
- for (i = this->chans.size(); --i >= extra_chans; )
- {
- auto &ch = this->chans[i];
- if (ch.cfg.echo && this->s.feedback)
- this->no_echo = false;
-
- if (ch.vol[0] != TO_FIXED(1) || ch.vol[1] != TO_FIXED(1))
- this->no_effects = false;
- }
- if (!this->no_echo)
- this->no_effects = false;
-
- if (this->chans[0].vol[0] != TO_FIXED(1) || this->chans[0].vol[1] != TO_FIXED(0) || this->chans[1].vol[0] != TO_FIXED(0) || this->chans[1].vol[1] != TO_FIXED(1))
- this->no_effects = false;
-
- if (!this->config_.enabled)
- this->no_effects = true;
-
- if (this->no_effects)
- {
- for (i = this->chans.size(); --i >= 0; )
- {
- auto &ch = this->chans[i];
- ch.channel.center = this->bufs[2].get();
- ch.channel.left = this->bufs[0].get();
- ch.channel.right = this->bufs[1].get();
- }
- }
-
- this->mixer.bufs[0] = this->bufs[0].get();
- this->mixer.bufs[1] = this->bufs[1].get();
- this->mixer.bufs[2] = this->bufs[2].get();
-
- if (echo_dirty || (!old_echo && (!this->no_echo && !this->no_effects)))
- this->clear_echo();
-
- this->channels_changed();
-}
-
-void Effects_Buffer::assign_buffers()
-{
- // assign channels to buffers
- int buf_count = 0;
- for (int i = 0; i < static_cast<int>(this->chans.size()); ++i)
- {
- // put second two side channels at end to give priority to main channels
- // in case closest matching is necessary
- int x = i;
- if (i > 1)
- x += 2;
- if (x >= static_cast<int>(this->chans.size()))
- x -= this->chans.size() - 2;
- auto &ch = this->chans[x];
-
- int b = 0;
- for (; b < buf_count; ++b)
- {
- if (ch.vol[0] == this->bufs[b]->vol[0] && ch.vol[1] == this->bufs[b]->vol[1] && (ch.cfg.echo == this->bufs[b]->echo || !this->s.feedback))
- break;
- }
-
- if (b >= buf_count)
- {
- if (buf_count < this->bufs_max)
- {
- this->bufs[b]->vol[0] = ch.vol[0];
- this->bufs[b]->vol[1] = ch.vol[1];
- this->bufs[b]->echo = ch.cfg.echo;
- ++buf_count;
- }
- else
- {
- // TODO: this is a mess, needs refinement
- b = 0;
- fixed_t best_dist = TO_FIXED(8);
- for (int h = buf_count; --h >= 0; )
- {
- auto CALC_LEVELS = [&](fixed_t vols[], fixed_t &sum, fixed_t &diff, bool &surround)
- {
- fixed_t vol_0 = vols[0];
- if (vol_0 < 0)
- {
- vol_0 = -vol_0;
- surround = true;
- }
- fixed_t vol_1 = vols[1];
- if (vol_1 < 0)
- {
- vol_1 = -vol_1;
- surround = true;
- }
- sum = vol_0 + vol_1;
- diff = vol_0 - vol_1;
- };
- fixed_t ch_sum, ch_diff, buf_sum, buf_diff;
- bool ch_surround, buf_surround;
- CALC_LEVELS(ch.vol, ch_sum, ch_diff, ch_surround);
- CALC_LEVELS(this->bufs[h]->vol, buf_sum, buf_diff, buf_surround);
-
- fixed_t dist = std::abs(ch_sum - buf_sum) + std::abs(ch_diff - buf_diff);
-
- if (ch_surround != buf_surround)
- dist += TO_FIXED(1) / 2;
-
- if (this->s.feedback && ch.cfg.echo != this->bufs[h]->echo)
- dist += TO_FIXED(1) / 2;
-
- if (best_dist > dist)
- {
- best_dist = dist;
- b = h;
- }
- }
- }
- }
-
- ch.channel.center = this->bufs[b].get();
- }
-}
-
-// Mixing
-
-void Effects_Buffer::end_frame(blip_time_t time)
-{
- for (int i = bufs_size; --i >= 0; )
- this->bufs[i]->end_frame(time);
-}
-
-long Effects_Buffer::read_samples(blip_sample_t *out, long out_size)
-{
- out_size = std::min(out_size, this->samples_avail());
-
- int pair_count = static_cast<int>(out_size >> 1);
- assert(pair_count * stereo == out_size); // must read an even number of samples
- if (pair_count)
- {
- if (this->no_effects)
- this->mixer.read_pairs(out, pair_count);
- else
- {
- int pairs_remain = pair_count;
- do
- {
- // mix at most max_read pairs at a time
- int count = max_read;
- if (count > pairs_remain)
- count = pairs_remain;
-
- if (this->no_echo)
- {
- // optimization: clear echo here to keep mix_effects() a leaf function
- this->echo_pos = 0;
- memset(&this->echo[0], 0, count * stereo * sizeof(this->echo[0]));
- }
- this->mix_effects(out, count);
-
- int32_t new_echo_pos = this->echo_pos + count * stereo;
- if (new_echo_pos >= this->echo_size)
- new_echo_pos -= this->echo_size;
- this->echo_pos = new_echo_pos;
- assert(this->echo_pos < this->echo_size);
-
- out += count * stereo;
- this->mixer.samples_read += count;
- pairs_remain -= count;
- } while (pairs_remain);
- }
-
- if (this->samples_avail() <= 0 || this->immediate_removal())
- {
- for (int i = this->bufs_size; --i >= 0; )
- {
- auto &b = this->bufs[i];
- // TODO: might miss non-silence settling since it checks END of last read
- if (b->non_silent())
- b->remove_samples(this->mixer.samples_read);
- else
- b->remove_silence(this->mixer.samples_read);
- }
- this->mixer.samples_read = 0;
- }
- }
- return out_size;
-}
-
-void Effects_Buffer::mix_effects(blip_sample_t *out_, int pair_count)
-{
- typedef fixed_t stereo_fixed_t[stereo];
-
- // add channels with echo, do echo, add channels without echo, then convert to 16-bit and output
- int echo_phase = 1;
- do
- {
- // mix any modified buffers
- {
- size_t bufNum = 0;
- int bufs_remain = this->bufs_size;
- do
- {
- auto &buf = this->bufs[bufNum++];
- if (buf->non_silent() && (buf->echo == !!echo_phase))
- {
- auto out = reinterpret_cast<stereo_fixed_t *>(&this->echo[this->echo_pos]);
- int bass = BLIP_READER_BASS(*buf);
- BLIP_READER_BEGIN(in, *buf);
- BLIP_READER_ADJ_(in, this->mixer.samples_read);
- fixed_t vol_0 = buf->vol[0];
- fixed_t vol_1 = buf->vol[1];
-
- int count = static_cast<unsigned>(echo_size - echo_pos) / stereo;
- int remain = pair_count;
- if (count > remain)
- count = remain;
- do
- {
- remain -= count;
- BLIP_READER_ADJ_(in, count);
-
- out += count;
- int offset = -count;
- do
- {
- fixed_t s = BLIP_READER_READ(in);
- BLIP_READER_NEXT_IDX_(in, bass, offset);
-
- out[offset][0] += s * vol_0;
- out[offset][1] += s * vol_1;
- } while ( ++offset );
-
- out = reinterpret_cast<stereo_fixed_t *>(&this->echo[0]);
- count = remain;
- } while (remain);
-
- BLIP_READER_END(in, *buf);
- }
- } while (--bufs_remain);
- }
-
- // add echo
- if (echo_phase && !this->no_echo)
- {
- fixed_t feedback = this->s.feedback;
- fixed_t treble = this->s.treble;
-
- int i = 1;
- do
- {
- fixed_t low_pass = this->s.low_pass[i];
-
- auto echo_end = &this->echo[this->echo_size + i];
- auto in_pos = &this->echo[this->echo_pos + i];
- int32_t out_offset = this->echo_pos + i + this->s.delay[i];
- if (out_offset >= this->echo_size)
- out_offset -= this->echo_size;
- assert(out_offset < this->echo_size);
- auto out_pos = &this->echo[out_offset];
-
- // break into up to three chunks to avoid having to handle wrap-around
- // in middle of core loop
- int remain = pair_count;
- do
- {
- auto pos = in_pos;
- if (pos < out_pos)
- pos = out_pos;
- int count = static_cast<uint32_t>(reinterpret_cast<char *>(echo_end) - reinterpret_cast<const char *>(pos)) / (stereo * sizeof(fixed_t));
- if (count > remain)
- count = remain;
- remain -= count;
-
- in_pos += count * stereo;
- out_pos += count * stereo;
- int offset = -count;
- do
- {
- low_pass += FROM_FIXED(in_pos[offset * stereo] - low_pass) * treble;
- out_pos[offset * stereo] = FROM_FIXED(low_pass) * feedback;
- } while (++offset);
-
- if (in_pos >= echo_end)
- in_pos -= echo_size;
- if (out_pos >= echo_end)
- out_pos -= echo_size;
- } while (remain);
-
- this->s.low_pass [i] = low_pass;
- } while (--i >= 0);
- }
- } while (--echo_phase >= 0);
-
- // clamp to 16 bits
- auto in = reinterpret_cast<stereo_fixed_t *>(&this->echo[this->echo_pos]);
- typedef blip_sample_t stereo_blip_sample_t[stereo];
- auto out = reinterpret_cast<stereo_blip_sample_t *>(out_);
- int count = static_cast<unsigned>(this->echo_size - this->echo_pos) / stereo;
- int remain = pair_count;
- if (count > remain)
- count = remain;
- do
- {
- remain -= count;
- in += count;
- out += count;
- int offset = -count;
- do
- {
- fixed_t in_0 = FROM_FIXED(in[offset][0]);
- fixed_t in_1 = FROM_FIXED(in[offset][1]);
-
- BLIP_CLAMP(in_0, in_0);
- out[offset][0] = static_cast<blip_sample_t>(in_0);
-
- BLIP_CLAMP(in_1, in_1);
- out[offset][1] = static_cast<blip_sample_t>(in_1);
- } while (++offset);
-
- in = reinterpret_cast<stereo_fixed_t *>(&this->echo[0]);
- count = remain;
- } while (remain);
-}
-
--- a/src/in_gsf/vbam/apu/Effects_Buffer.h
+++ /dev/null
@@ -1,142 +1,1 @@
-// Multi-channel effects buffer with echo and individual panning for each channel
-// Game_Music_Emu $vers
-#ifndef EFFECTS_BUFFER_H
-#define EFFECTS_BUFFER_H
-
-#include <vector>
-#include "Multi_Buffer.h"
-
-// See Simple_Effects_Buffer (below) for a simpler interface
-
-class Effects_Buffer : public Multi_Buffer
-{
-public:
- // To reduce memory usage, fewer buffers can be used (with a best-fit
- // approach if there are too few), and maximum echo delay can be reduced
- Effects_Buffer(int max_bufs = 32, long echo_size = 24 * 1024L);
-
- struct pan_vol_t
- {
- float vol; // 0.0 = silent, 0.5 = half volume, 1.0 = normal
- float pan; // -1.0 = left, 0.0 = center, +1.0 = right
- };
-
- // Global configuration
- struct config_t
- {
- bool enabled; // false = disable all effects
-
- // Current sound is echoed at adjustable left/right delay,
- // with reduced treble and volume (feedback).
- float treble; // 1.0 = full treble, 0.1 = very little, 0.0 = silent
- int delay [2]; // left, right delays (msec)
- float feedback; // 0.0 = no echo, 0.5 = each echo half previous, 1.0 = cacophony
- pan_vol_t side_chans[2]; // left and right side channel volume and pan
- };
- config_t &config() { return this->config_; }
-
- // Limits of delay (msec)
- int min_delay() const;
- int max_delay() const;
-
- // Per-channel configuration. Two or more channels with matching parameters are
- // optimized to internally use the same buffer.
- struct chan_config_t : pan_vol_t
- {
- // (inherited from pan_vol_t)
- //float vol; // these only affect center channel
- //float pan;
- bool surround; // if true, negates left volume to put sound in back
- bool echo; // false = channel doesn't have any echo
- };
- chan_config_t &chan_config(int i) { return this->chans[i + extra_chans].cfg; }
-
- // Apply any changes made to config() and chan_config()
- virtual void apply_config();
-
- ~Effects_Buffer();
- blargg_err_t set_sample_rate(long samples_per_sec, int msec = blip_default_length);
- blargg_err_t set_channel_count(int, const int * = nullptr);
- void clock_rate(long);
- void bass_freq(int);
- void clear();
- channel_t channel(int);
- void end_frame(blip_time_t);
- long read_samples(blip_sample_t *, long);
- long samples_avail() const { return (this->bufs[0]->samples_avail() - this->mixer.samples_read) * 2; }
- enum { stereo = 2 };
- typedef int32_t fixed_t;
-protected:
- enum { extra_chans = stereo * stereo };
-private:
- config_t config_;
- long clock_rate_;
- int bass_freq_;
-
- int32_t echo_size;
-
- struct chan_t
- {
- fixed_t vol [stereo];
- chan_config_t cfg;
- channel_t channel;
- };
- std::vector<chan_t> chans;
-
- struct buf_t : Tracked_Blip_Buffer
- {
- fixed_t vol[stereo];
- bool echo;
- };
- std::vector<std::unique_ptr<buf_t>> bufs;
- int bufs_size;
- int bufs_max; // bufs_size <= bufs_max, to limit memory usage
- Stereo_Mixer mixer;
-
- struct
- {
- long delay[stereo];
- fixed_t treble;
- fixed_t feedback;
- fixed_t low_pass[stereo];
- } s;
-
- std::vector<fixed_t> echo;
- int32_t echo_pos;
-
- bool no_effects;
- bool no_echo;
-
- void assign_buffers();
- void clear_echo();
- void mix_effects(blip_sample_t *out, int pair_count);
- blargg_err_t new_bufs(int size);
- void delete_bufs();
-};
-
-// Simpler interface and lower memory usage
-class Simple_Effects_Buffer : public Effects_Buffer
-{
-public:
- struct config_t
- {
- bool enabled; // false = disable all effects
- float echo; // 0.0 = none, 1.0 = lots
- float stereo; // 0.0 = channels in center, 1.0 = channels on left/right
- bool surround; // true = put some channels in back
- };
- config_t &config() { return this->config_; }
-
- // Apply any changes made to config()
- void apply_config();
-
-public:
- Simple_Effects_Buffer();
-private:
- config_t config_;
- void chan_config(); // hide
-};
-
-#endif
-
--- a/src/in_gsf/vbam/apu/Gb_Apu.cpp
+++ b/src/in_gsf/vbam/apu/Gb_Apu.cpp
@@ -14,8 +14,6 @@
License along with this module; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */
-#include "blargg_source.h"
-
static const unsigned vol_reg = 0xFF24;
static const unsigned stereo_reg = 0xFF25;
static const unsigned status_reg = 0xFF26;
@@ -76,7 +74,7 @@
void Gb_Apu::volume(double v)
{
- if (volume_ != v)
+ if (this->volume_ != v)
{
this->volume_ = v;
this->apply_volume();
@@ -117,7 +115,7 @@
this->oscs[i]->dac_off_amp = dac_off_amp;
// AGB always eliminates clicks on wave channel using same method
- if (wave.mode == mode_agb)
+ if (this->wave.mode == mode_agb)
this->wave.dac_off_amp = -Gb_Osc::dac_bias;
}
@@ -166,10 +164,10 @@
{
this->wave.wave_ram = &this->regs[wave_ram - start_addr];
- this->oscs [0] = &this->square1;
- this->oscs [1] = &this->square2;
- this->oscs [2] = &this->wave;
- this->oscs [3] = &this->noise;
+ this->oscs[0] = &this->square1;
+ this->oscs[1] = &this->square2;
+ this->oscs[2] = &this->wave;
+ this->oscs[3] = &this->noise;
for (int i = osc_count; --i >= 0; )
{
@@ -199,10 +197,10 @@
if (time > this->frame_time)
time = this->frame_time;
- this->square1.run(last_time, time);
- this->square2.run(last_time, time);
- this->wave.run(last_time, time);
- this->noise.run(last_time, time);
+ this->square1.run(this->last_time, time);
+ this->square2.run(this->last_time, time);
+ this->wave.run(this->last_time, time);
+ this->noise.run(this->last_time, time);
this->last_time = time;
if (time == end_time)
@@ -358,7 +356,7 @@
return this->wave.read(addr);
// Value read back has some bits always set
- static const uint8_t masks [] =
+ static const uint8_t masks[] =
{
0x80, 0x3F, 0x00, 0xFF, 0xBF,
0xFF, 0x3F, 0x00, 0xFF, 0xBF,
--- a/src/in_gsf/vbam/apu/Gb_Oscs.cpp
+++ b/src/in_gsf/vbam/apu/Gb_Oscs.cpp
@@ -13,8 +13,6 @@
License along with this module; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */
-#include "blargg_source.h"
-
static const bool cgb_02 = false; // enables bug in early CGB units that causes problems in some games
static const bool cgb_05 = false; // enables CGB-05 zombie behavior
@@ -45,14 +43,14 @@
void Gb_Osc::clock_length()
{
- if ((this->regs [4] & length_enabled) && this->length_ctr)
+ if ((this->regs[4] & length_enabled) && this->length_ctr)
{
if (--this->length_ctr <= 0)
this->enabled = false;
}
}
-inline int Gb_Env::reload_env_timer()
+int Gb_Env::reload_env_timer()
{
int raw = this->regs[2] & 7;
this->env_delay = raw ? raw : 8;
@@ -154,7 +152,7 @@
return data & trigger_mask;
}
-inline void Gb_Env::zombie_volume(int old, int data)
+void Gb_Env::zombie_volume(int old, int data)
{
int v = this->volume;
if (this->mode == Gb_Apu::mode_agb || cgb_05)
@@ -188,7 +186,7 @@
this->volume = v & 0x0F;
}
-bool Gb_Env::write_register( int frame_phase, int reg, int old, int data )
+bool Gb_Env::write_register(int frame_phase, int reg, int old, int data)
{
static const int max_len = 64;
@@ -235,7 +233,7 @@
return result;
}
-inline void Gb_Noise::write_register( int frame_phase, int reg, int old_data, int data )
+void Gb_Noise::write_register(int frame_phase, int reg, int old_data, int data)
{
if (Gb_Env::write_register(frame_phase, reg, old_data, data))
{
@@ -244,7 +242,7 @@
}
}
-inline void Gb_Sweep_Square::write_register(int frame_phase, int reg, int old_data, int data)
+void Gb_Sweep_Square::write_register(int frame_phase, int reg, int old_data, int data)
{
if (!reg && this->sweep_enabled && this->sweep_neg && !(data & 0x08))
this->enabled = false; // sweep negate disabled after used
@@ -270,7 +268,7 @@
this->wave_ram[i] = this->wave_ram[(pos & ~3) + i];
}
-inline void Gb_Wave::write_register(int frame_phase, int reg, int old_data, int data)
+void Gb_Wave::write_register(int frame_phase, int reg, int old_data, int data)
{
static const int max_len = 256;
@@ -455,7 +453,7 @@
}
// Need to keep one extra bit of history
- s = s << 1 & 0xFF;
+ s = (s << 1) & 0xFF;
// Convert from Fibonacci to Galois configuration,
// shifted left 2 bits
@@ -521,7 +519,7 @@
int per2 = this->period2();
time += this->delay + ((this->divider ^ (per2 >> 1)) & (per2 - 1)) * period1;
- int count = (extra < 0 ? 0 : (extra + period1 - 1) / period1);
+ int count = extra < 0 ? 0 : (extra + period1 - 1) / period1;
this->divider = (this->divider - count) & period2_mask;
this->delay = count * period1 - extra;
}
@@ -579,7 +577,7 @@
auto out = this->output;
if (out)
{
- int amp = dac_off_amp;
+ int amp = this->dac_off_amp;
if (this->dac_enabled())
{
// Play inaudible frequencies as constant amplitude
@@ -589,7 +587,7 @@
if (this->frequency() <= 0x7FB || this->delay > 15 * clk_mul)
{
if (volume_mul)
- playing = enabled;
+ playing = this->enabled;
amp = (this->sample_buf << ((this->phase << 2) & 4) & 0xF0) * playing;
}
@@ -634,7 +632,7 @@
do
{
// Extract nybble
- int nybble = wave[ph >> 1] << ((ph << 2) & 4) & 0xF0;
+ int nybble = (wave[ph >> 1] << ((ph << 2) & 4)) & 0xF0;
ph = (ph + 1) & wave_mask;
// Scale by volume
--- a/src/in_gsf/vbam/apu/Gb_Oscs.h
+++ b/src/in_gsf/vbam/apu/Gb_Oscs.h
@@ -186,7 +186,7 @@
{
int index = this->access(addr);
if (index >= 0)
- this->wave_bank()[index] = data;;
+ this->wave_bank()[index] = data;
}
#endif
--- a/src/in_gsf/vbam/apu/Multi_Buffer.cpp
+++ b/src/in_gsf/vbam/apu/Multi_Buffer.cpp
@@ -14,8 +14,6 @@
License along with this module; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */
-#include "blargg_source.h"
-
#ifdef BLARGG_ENABLE_OPTIMIZER
# include BLARGG_ENABLE_OPTIMIZER
#endif
@@ -36,31 +34,6 @@
return ch;
}
-// Silent_Buffer
-
-Silent_Buffer::Silent_Buffer() : Multi_Buffer(1) // 0 channels would probably confuse
-{
- // TODO: better to use empty Blip_Buffer so caller never has to check for NULL?
- this->chan.left = this->chan.center = this->chan.right = nullptr;
-}
-
-// Mono_Buffer
-
-Mono_Buffer::Mono_Buffer() : Multi_Buffer(1)
-{
- this->chan.center = &this->buf;
- this->chan.left = &this->buf;
- this->chan.right = &this->buf;
-}
-
-Mono_Buffer::~Mono_Buffer() { }
-
-blargg_err_t Mono_Buffer::set_sample_rate(long rate, int msec)
-{
- RETURN_ERR(this->buf.set_sample_rate(rate, msec));
- return Multi_Buffer::set_sample_rate(this->buf.sample_rate(), this->buf.length());
-}
-
// Tracked_Blip_Buffer
Tracked_Blip_Buffer::Tracked_Blip_Buffer()
@@ -86,7 +59,7 @@
return this->last_non_silence | this->unsettled();
}
-inline void Tracked_Blip_Buffer::remove_(long n)
+void Tracked_Blip_Buffer::remove_(long n)
{
if ((this->last_non_silence -= n) < 0)
this->last_non_silence = 0;
@@ -125,12 +98,12 @@
Stereo_Buffer::~Stereo_Buffer() { }
-blargg_err_t Stereo_Buffer::set_sample_rate(long rate, int msec)
+void Stereo_Buffer::set_sample_rate(long rate, int msec)
{
this->mixer.samples_read = 0;
for (int i = bufs_size; --i >= 0; )
- RETURN_ERR(this->bufs[i].set_sample_rate(rate, msec));
- return Multi_Buffer::set_sample_rate(this->bufs[0].sample_rate(), this->bufs[0].length());
+ this->bufs[i].set_sample_rate(rate, msec);
+ Multi_Buffer::set_sample_rate(this->bufs[0].sample_rate(), this->bufs[0].length());
}
void Stereo_Buffer::clock_rate(long rate)
@@ -196,7 +169,7 @@
// except that buffer isn't cleared, so caller can encounter
// subtle problems and not realize the cause.
this->samples_read += count;
- if (this->bufs[0]->non_silent() || this->bufs[1]->non_silent())
+ if (this->bufs[0]->non_silent() | this->bufs[1]->non_silent())
this->mix_stereo(out, count);
else
this->mix_mono(out, count);
@@ -238,8 +211,8 @@
BLIP_READER_BEGIN(side, **buf);
BLIP_READER_BEGIN(center, *this->bufs[2]);
- BLIP_READER_ADJ_(side, samples_read);
- BLIP_READER_ADJ_(center, samples_read);
+ BLIP_READER_ADJ_(side, this->samples_read);
+ BLIP_READER_ADJ_(center, this->samples_read);
int offset = -count;
do
@@ -256,7 +229,7 @@
BLIP_READER_END(side, **buf);
- if (buf != bufs)
+ if (buf != this->bufs)
continue;
// only end center once
--- a/src/in_gsf/vbam/apu/Multi_Buffer.h
+++ b/src/in_gsf/vbam/apu/Multi_Buffer.h
@@ -19,7 +19,7 @@
// (type information used by Effects_Buffer)
enum { type_index_mask = 0xFF };
enum { wave_type = 0x100, noise_type = 0x200, mixed_type = wave_type | noise_type };
- virtual blargg_err_t set_channel_count(int, const int* types = nullptr);
+ virtual void set_channel_count(int, const int* types = nullptr);
int channel_count() const { return this->channel_count_; }
// Gets indexed channel, from 0 to channel count - 1
@@ -32,7 +32,7 @@
virtual channel_t channel(int index);
// See Blip_Buffer.h
- virtual blargg_err_t set_sample_rate(long rate, int msec = blip_default_length);
+ virtual void set_sample_rate(long rate, int msec = blip_default_length);
virtual void clock_rate(long) { }
virtual void bass_freq(int) { }
virtual void clear() { }
@@ -72,27 +72,6 @@
const int samples_per_frame_;
const int *channel_types_;
bool immediate_removal_;
-};
-
-// Uses a single buffer and outputs mono samples.
-class Mono_Buffer : public Multi_Buffer
-{
- Blip_Buffer buf;
- channel_t chan;
-public:
- // Buffer used for all channels
- Blip_Buffer *center() { return &this->buf; }
-
- Mono_Buffer();
- ~Mono_Buffer();
- blargg_err_t set_sample_rate(long rate, int msec = blip_default_length);
- void clock_rate(long rate) { this->buf.clock_rate(rate); }
- void bass_freq(int freq) { this->buf.bass_freq(freq); }
- void clear() { this->buf.clear(); }
- long samples_avail() const { return this->buf.samples_avail(); }
- long read_samples(blip_sample_t *p, long s) { return this->buf.read_samples(p, s); }
- channel_t channel(int) { return this->chan; }
- void end_frame(blip_time_t t) { this->buf.end_frame(t); }
};
class Tracked_Blip_Buffer : public Blip_Buffer
@@ -137,7 +116,7 @@
Stereo_Buffer();
~Stereo_Buffer();
- blargg_err_t set_sample_rate(long, int msec = blip_default_length);
+ void set_sample_rate(long, int msec = blip_default_length);
void clock_rate(long);
void bass_freq(int);
void clear();
@@ -156,32 +135,10 @@
long samples_avail_;
};
-// Silent_Buffer generates no samples, useful where no sound is wanted
-class Silent_Buffer : public Multi_Buffer
-{
- channel_t chan;
-public:
- Silent_Buffer();
- blargg_err_t set_sample_rate(long rate, int msec = blip_default_length);
- void clock_rate(long) { }
- void bass_freq(int) { }
- void clear() { }
- channel_t channel(int) { return this->chan; }
- void end_frame(blip_time_t) { }
- long samples_avail() const { return 0; }
- long read_samples(blip_sample_t *, long) { return 0; }
-};
-
-inline blargg_err_t Multi_Buffer::set_sample_rate(long rate, int msec)
+inline void Multi_Buffer::set_sample_rate(long rate, int msec)
{
this->sample_rate_ = rate;
this->length_ = msec;
- return 0;
-}
-
-inline blargg_err_t Silent_Buffer::set_sample_rate(long rate, int msec)
-{
- return Multi_Buffer::set_sample_rate(rate, msec);
}
inline int Multi_Buffer::samples_per_frame() const { return this->samples_per_frame_; }
@@ -190,11 +147,10 @@
inline int Multi_Buffer::length() const { return this->length_; }
-inline blargg_err_t Multi_Buffer::set_channel_count(int n, const int *types)
+inline void Multi_Buffer::set_channel_count(int n, const int *types)
{
this->channel_count_ = n;
this->channel_types_ = types;
- return 0;
}
#endif
--- a/src/in_gsf/vbam/apu/blargg_common.h
+++ b/src/in_gsf/vbam/apu/blargg_common.h
@@ -14,11 +14,6 @@
#include "blargg_config.h"
#ifndef BLARGG_COMMON_H
#define BLARGG_COMMON_H
-
-// blargg_err_t (0 on success, otherwise error string)
-#ifndef blargg_err_t
-typedef const char *blargg_err_t;
-#endif
// BLARGG_COMPILER_HAS_BOOL: If 0, provides bool support for old compiler. If 1,
// compiler is assumed to support bool. If undefined, availability is determined.
--- a/src/in_gsf/vbam/apu/blargg_source.h
+++ /dev/null
@@ -1,34 +1,1 @@
-/* Included at the beginning of library source files, AFTER all other #include lines.
-Sets up helpful macros and services used in my source code. Since this is only "active"
-in my source code, I don't have to worry about polluting the global namespace with
-unprefixed names. */
-// Gb_Snd_Emu 0.2.0
-#ifndef BLARGG_SOURCE_H
-#define BLARGG_SOURCE_H
-
-// The following four macros are for debugging only. Some or all might be defined
-// to do nothing, depending on the circumstances. Described is what happens when
-// a particular macro is defined to do something. When defined to do nothing, the
-// macros do NOT evaluate their argument(s).
-
-// If expr is false, prints file and line number, then aborts program. Meant for
-// checking internal state and consistency. A failed assertion indicates a bug
-// in MY code.
-//
-// void assert( bool expr );
-#include <cassert>
-
-// If expr yields non-NULL error string, returns it from current function,
-// otherwise continues normally.
-#undef RETURN_ERR
-#define RETURN_ERR(expr) \
-do \
-{ \
- blargg_err_t blargg_return_err_ = (expr); \
- if (blargg_return_err_) \
- return blargg_return_err_; \
-} while (0)
-
-#endif
-
--- a/src/in_gsf/vbam/gba/GBA-arm.cpp
+++ b/src/in_gsf/vbam/gba/GBA-arm.cpp
@@ -24,8 +24,8 @@
// Common macros //////////////////////////////////////////////////////////
-static inline uint32_t NEG(uint32_t i) { return i >> 31; }
-static inline uint32_t POS(uint32_t i) { return ~i >> 31; }
+template<typename T> static inline T NEG(const T &i) { return i >> 31; }
+template<typename T> static inline T POS(const T &i) { return ~i >> 31; }
// The following macros are used for optimization; any not defined for a
// particular compiler/CPU combination default to the C core versions.
@@ -240,11 +240,11 @@
# define esi "%%esi"
# define edi "%%edi"
# define movzx movzb
-#else
+# else
# define ALU_HEADER __asm { __asm mov ecx, opcode
# define ALU_TRAILER }
# define EMIT0(op) __asm op
-# define EMIT1(op,arg) __asm op arg
+# define EMIT1(op, arg) __asm op arg
# define EMIT2(op, src, dest) __asm op dest, src
# define KONST(val) val
# define VAR(var) var
@@ -310,7 +310,7 @@
EMIT2(and, KONST(0x3C), esi)
# define LOAD_C_FLAG_YES EMIT2(mov, VAR(C_FLAG), bl)
-# define LOAD_C_FLAG_NO /*nothing*/
+# define LOAD_C_FLAG_NO /*nothing*/
# define ALU_INIT_C ALU_INIT(LOAD_C_FLAG_YES)
# define ALU_INIT_NC ALU_INIT(LOAD_C_FLAG_NO)
@@ -579,7 +579,7 @@
# define OP_MVNS CHECK_PC(OP_MVN EMIT2(test, eax, eax), SETCOND_LOGICAL)
// ALU cleanup macro
-# define ALU_FINISH ALU_TRAILER
+# define ALU_FINISH ALU_TRAILER
// End of ALU macros
//X//#endif //_MSC_VER
@@ -599,7 +599,6 @@
"rcr $1, %0" \
: "=r" (offset) \
: "0" (offset));
-
# else // !__GNUC__, i.e. Visual C++
# define ROR_IMM_MSR \
__asm \
@@ -621,7 +620,6 @@
__asm bt dword ptr C_FLAG, 0 \
__asm rcr offset, 1 \
}
-
# endif // !__GNUC__
# endif // !__POWERPC__
#endif // !C_CORE
@@ -688,7 +686,7 @@
C_OUT = false; \
} \
} \
- else
+ else \
value = rm;
#endif
// OP Rd,Rb,Rm LSR #
@@ -733,7 +731,7 @@
C_OUT = false; \
} \
} \
- else
+ else \
value = rm;
#endif
// OP Rd,Rb,Rm ASR #
@@ -797,15 +795,14 @@
#ifndef VALUE_ROR_IMM_C
# define VALUE_ROR_IMM_C \
unsigned shift = (opcode >> 7) & 0x1F; \
+ uint32_t v = reg[opcode & 0x0F].I; \
if (LIKELY(shift)) \
{ \
- uint32_t v = reg[opcode & 0x0F].I; \
C_OUT = !!((v >> (shift - 1)) & 1); \
value = (v << (32 - shift)) | (v >> shift); \
} \
else \
{ \
- uint32_t v = reg[opcode & 0x0F].I; \
C_OUT = !!(v & 1); \
value = (v >> 1) | (C_FLAG << 31); \
}
@@ -815,12 +812,12 @@
# define VALUE_ROR_REG_C \
unsigned shift = reg[(opcode >> 8) & 15].B.B0; \
uint32_t rm = reg[opcode & 0x0F].I; \
- if ((opcode & 0x0F) == 15)
+ if ((opcode & 0x0F) == 15) \
rm += 4; \
if (LIKELY(shift & 0x1F)) \
{ \
uint32_t v = rm; \
- C_OUT = !((v >> (shift - 1)) & 1); \
+ C_OUT = !!((v >> (shift - 1)) & 1); \
value = (v << (32 - shift)) | (v >> shift); \
} \
else \
@@ -912,7 +909,7 @@
reg[dest].I = res;
#endif
#ifndef OP_RSBS
-# define OP_RSBS OP_RSB C_CHECK_PC(C_SETCOND_SUB)
+# define OP_RSBS OP_RSB C_CHECK_PC(C_SETCOND_SUB)
#endif
#ifndef OP_ADD
# define OP_ADD \
@@ -1075,7 +1072,7 @@
clockTicks = 3 + ISREGSHIFT + codeTicksAccess32(armNextPC) + codeTicksAccessSeq32(armNextPC) + codeTicksAccessSeq32(armNextPC); \
}
-#define MODECHANGE_NO /*nothing*/
+#define MODECHANGE_NO /*nothing*/
#define MODECHANGE_YES CPUSwitchMode(reg[17].I & 0x1f, false);
#define DEFINE_ALU_INSN_C(CODE1, CODE2, OP, MODECHANGE) \
@@ -1100,74 +1097,74 @@
static INSN_REGPARM void arm##CODE2##0(uint32_t opcode) { ALU_INSN(ALU_INIT_NC, VALUE_IMM_NC, OP_##OP, MODECHANGE_##MODECHANGE, 0); }
// AND
-DEFINE_ALU_INSN_NC(00, 20, AND, NO)
+DEFINE_ALU_INSN_NC(00, 20, AND, NO)
// ANDS
DEFINE_ALU_INSN_C(01, 21, ANDS, YES)
// EOR
-DEFINE_ALU_INSN_NC(02, 22, EOR, NO)
+DEFINE_ALU_INSN_NC(02, 22, EOR, NO)
// EORS
DEFINE_ALU_INSN_C(03, 23, EORS, YES)
// SUB
-DEFINE_ALU_INSN_NC(04, 24, SUB, NO)
+DEFINE_ALU_INSN_NC(04, 24, SUB, NO)
// SUBS
DEFINE_ALU_INSN_NC(05, 25, SUBS, YES)
// RSB
-DEFINE_ALU_INSN_NC(06, 26, RSB, NO)
+DEFINE_ALU_INSN_NC(06, 26, RSB, NO)
// RSBS
DEFINE_ALU_INSN_NC(07, 27, RSBS, YES)
// ADD
-DEFINE_ALU_INSN_NC(08, 28, ADD, NO)
+DEFINE_ALU_INSN_NC(08, 28, ADD, NO)
// ADDS
DEFINE_ALU_INSN_NC(09, 29, ADDS, YES)
// ADC
-DEFINE_ALU_INSN_NC(0A, 2A, ADC, NO)
+DEFINE_ALU_INSN_NC(0A, 2A, ADC, NO)
// ADCS
DEFINE_ALU_INSN_NC(0B, 2B, ADCS, YES)
// SBC
-DEFINE_ALU_INSN_NC(0C, 2C, SBC, NO)
+DEFINE_ALU_INSN_NC(0C, 2C, SBC, NO)
// SBCS
DEFINE_ALU_INSN_NC(0D, 2D, SBCS, YES)
// RSC
-DEFINE_ALU_INSN_NC(0E, 2E, RSC, NO)
+DEFINE_ALU_INSN_NC(0E, 2E, RSC, NO)
// RSCS
DEFINE_ALU_INSN_NC(0F, 2F, RSCS, YES)
// TST
-DEFINE_ALU_INSN_C(11, 31, TST, NO)
+DEFINE_ALU_INSN_C(11, 31, TST, NO)
// TEQ
-DEFINE_ALU_INSN_C(13, 33, TEQ, NO)
+DEFINE_ALU_INSN_C(13, 33, TEQ, NO)
// CMP
-DEFINE_ALU_INSN_NC(15, 35, CMP, NO)
+DEFINE_ALU_INSN_NC(15, 35, CMP, NO)
// CMN
-DEFINE_ALU_INSN_NC(17, 37, CMN, NO)
+DEFINE_ALU_INSN_NC(17, 37, CMN, NO)
// ORR
-DEFINE_ALU_INSN_NC(18, 38, ORR, NO)
+DEFINE_ALU_INSN_NC(18, 38, ORR, NO)
// ORRS
DEFINE_ALU_INSN_C(19, 39, ORRS, YES)
// MOV
-DEFINE_ALU_INSN_NC(1A, 3A, MOV, NO)
+DEFINE_ALU_INSN_NC(1A, 3A, MOV, NO)
// MOVS
DEFINE_ALU_INSN_C(1B, 3B, MOVS, YES)
// BIC
-DEFINE_ALU_INSN_NC(1C, 3C, BIC, NO)
+DEFINE_ALU_INSN_NC(1C, 3C, BIC, NO)
// BICS
DEFINE_ALU_INSN_C(1D, 3D, BICS, YES)
// MVN
-DEFINE_ALU_INSN_NC(1E, 3E, MVN, NO)
+DEFINE_ALU_INSN_NC(1E, 3E, MVN, NO)
// MVNS
DEFINE_ALU_INSN_C(1F, 3F, MVNS, YES)
@@ -1188,7 +1185,7 @@
if (!(rs & 0xFFFFFF00)) \
; /* No-op */ \
else if (!(rs & 0xFFFF0000)) \
- clockTicks += 1; \
+ ++clockTicks; \
else if (!(rs & 0xFF000000)) \
clockTicks += 2; \
else \
@@ -1261,7 +1258,7 @@
{
uint32_t address = reg[(opcode >> 16) & 15].I;
uint32_t temp = CPUReadByte(address);
- CPUWriteByte(address, reg[opcode&15].B.B0);
+ CPUWriteByte(address, reg[opcode & 15].B.B0);
reg[(opcode >> 12) & 15].I = temp;
clockTicks = 4 + dataTicksAccess32(address) + dataTicksAccess32(address) + codeTicksAccess32(armNextPC);
}
@@ -2043,7 +2040,7 @@
STM_HIGH(STMW_REG); \
STMW_PC;
#define LDM_ALL \
- LDM_LOW \
+ LDM_LOW; \
LDM_HIGH; \
if (opcode & (1U << 15)) \
{ \
@@ -2062,7 +2059,7 @@
clockTicks += 1 + codeTicksAccessSeq32(armNextPC); \
}
#define STM_ALL_2 \
- STM_LOW(STM_REG) \
+ STM_LOW(STM_REG); \
STM_HIGH_2(STM_REG); \
STM_PC;
#define STMW_ALL_2 \
@@ -2244,9 +2241,9 @@
if (!busPrefetchCount)
busPrefetch = busPrefetchEnable;
int base = (opcode & 0x000F0000) >> 16;
+ uint32_t temp = reg[base].I + 4 * (cpuBitsSet[opcode & 0xFF] + cpuBitsSet[(opcode >> 8) & 255]);
uint32_t address = reg[base].I & 0xFFFFFFFC;
int count = 0;
- uint32_t temp = reg[base].I + 4 * (cpuBitsSet[opcode & 0xFF] + cpuBitsSet[(opcode >> 8) & 255]);
STMW_ALL;
clockTicks += 1 + codeTicksAccess32(armNextPC);
}
@@ -2297,9 +2294,9 @@
if (!busPrefetchCount)
busPrefetch = busPrefetchEnable;
int base = (opcode & 0x000F0000) >> 16;
+ uint32_t temp = reg[base].I + 4 * (cpuBitsSet[opcode & 0xFF] + cpuBitsSet[(opcode >> 8) & 255]);
uint32_t address = reg[base].I & 0xFFFFFFFC;
int count = 0;
- uint32_t temp = reg[base].I + 4 * (cpuBitsSet[opcode & 0xFF] + cpuBitsSet[(opcode >> 8) & 255]);
STMW_ALL_2;
clockTicks += 1 + codeTicksAccess32(armNextPC);
}
@@ -2460,9 +2457,9 @@
if (!busPrefetchCount)
busPrefetch = busPrefetchEnable;
int base = (opcode & 0x000F0000) >> 16;
+ uint32_t temp = reg[base].I + 4 * (cpuBitsSet[opcode & 0xFF] + cpuBitsSet[(opcode >> 8) & 255]);
uint32_t address = (reg[base].I + 4) & 0xFFFFFFFC;
int count = 0;
- uint32_t temp = reg[base].I + 4 * (cpuBitsSet[opcode & 0xFF] + cpuBitsSet[(opcode >> 8) & 255]);
STMW_ALL;
clockTicks += 1 + codeTicksAccess32(armNextPC);
}
@@ -2513,9 +2510,9 @@
if (!busPrefetchCount)
busPrefetch = busPrefetchEnable;
int base = (opcode & 0x000F0000) >> 16;
+ uint32_t temp = reg[base].I + 4 * (cpuBitsSet[opcode & 0xFF] + cpuBitsSet[(opcode >> 8) & 255]);
uint32_t address = (reg[base].I + 4) & 0xFFFFFFFC;
int count = 0;
- uint32_t temp = reg[base].I + 4 * (cpuBitsSet[opcode & 0xFF] + cpuBitsSet[(opcode >> 8) & 255]);
STMW_ALL_2;
clockTicks += 1 + codeTicksAccess32(armNextPC);
}
@@ -2565,7 +2562,7 @@
reg[15].I += 4;
ARM_PREFETCH();
clockTicks = codeTicksAccessSeq32(armNextPC) + 1;
- clockTicks += 2 + codeTicksAccess32(armNextPC) + codeTicksAccessSeq32(armNextPC);
+ clockTicks = (clockTicks * 2) + codeTicksAccess32(armNextPC) + 1;
busPrefetchCount = 0;
}
@@ -2846,7 +2843,6 @@
case 0x0E: // AL (impossible, checked above)
cond_res = true;
break;
- case 0x0F:
default:
// ???
cond_res = false;
--- a/src/in_gsf/vbam/gba/GBA-thumb.cpp
+++ b/src/in_gsf/vbam/gba/GBA-thumb.cpp
@@ -5,10 +5,6 @@
#include "Sound.h"
#include "bios.h"
-#ifdef _MSC_VER
-# define snprintf _snprintf
-#endif
-
///////////////////////////////////////////////////////////////////////////
static int clockTicks;
@@ -20,8 +16,8 @@
// Common macros //////////////////////////////////////////////////////////
-static inline uint32_t NEG(uint32_t i) { return i >> 31; }
-static inline uint32_t POS(uint32_t i) { return ~i >> 31; }
+template<typename T> static inline T NEG(const T &i) { return i >> 31; }
+template<typename T> static inline T POS(const T &i) { return ~i >> 31; }
#ifndef C_CORE
# ifdef __GNUC__
@@ -82,7 +78,7 @@
V_FLAG = (Flags >> 26) & 1; \
}
# define CMN_RD_RS \
-{\
+{ \
register int Flags; \
register int Result; \
asm volatile("addco. %0, %2, %3\n" \
@@ -105,7 +101,7 @@
asm volatile("mtspr 1, %4\n" \ /* reg 1 is xer */
"addeo. %0, %2, %3\n" \
"mcrxr cr1\n" \
- "mfcr %1\n" \
+ "mfcr %1\n" \
: "=r" (Result), \
"=r" (Flags) \
: "r" (reg[dest].I), \
@@ -221,7 +217,7 @@
"=r" (Flags) \
: "r" (reg[source].I), \
"r" (0) \
- ); \
+ ); \
reg[dest].I = Result; \
Z_FLAG = (Flags >> 29) & 1; \
N_FLAG = (Flags >> 31) & 1; \
@@ -259,7 +255,7 @@
# define ecx "%%ecx"
# define edx "%%edx"
# define ADD_RN_O8(d) \
- asm("andl $0xFF, %%eax;"\
+ asm("andl $0xFF, %%eax;" \
"addl %%eax, %0;" \
EMIT1(setsb, VAR(N_FLAG)) \
EMIT1(setzb, VAR(Z_FLAG)) \
@@ -352,7 +348,7 @@
EMIT1(setob, VAR(V_FLAG)) \
: \
: "r" (value), "r" (reg[dest].I) : "1");
-# define IMM5_INSN(OP,N) \
+# define IMM5_INSN(OP, N) \
asm("movl %%eax,%%ecx;" \
"shrl $1,%%eax;" \
"andl $7,%%ecx;" \
@@ -361,7 +357,7 @@
OP \
EMIT1(setsb, VAR(N_FLAG)) \
EMIT1(setzb, VAR(Z_FLAG)) \
- EMIT2(movl, edx, REGREF2(ecx,4)) \
+ EMIT2(movl, edx, REGREF2(ecx, 4)) \
: : "i" (N))
# define IMM5_INSN_0(OP) \
asm("movl %%eax,%%ecx;" \
@@ -372,25 +368,25 @@
OP \
EMIT1(setsb, VAR(N_FLAG)) \
EMIT1(setzb, VAR(Z_FLAG)) \
- EMIT2(movl, edx, REGREF2(ecx,4)) \
+ EMIT2(movl, edx, REGREF2(ecx, 4)) \
: : )
# define IMM5_LSL \
- "shll %0,%%edx;"\
+ "shll %0,%%edx;" \
EMIT1(setcb, VAR(C_FLAG))
# define IMM5_LSL_0 \
"testl %%edx,%%edx;"
# define IMM5_LSR \
- "shrl %0,%%edx;"\
+ "shrl %0,%%edx;" \
EMIT1(setcb, VAR(C_FLAG))
# define IMM5_LSR_0 \
- "testl %%edx,%%edx;"\
+ "testl %%edx,%%edx;" \
EMIT1(setsb, VAR(C_FLAG)) \
"xorl %%edx,%%edx;"
# define IMM5_ASR \
- "sarl %0,%%edx;"\
+ "sarl %0,%%edx;" \
EMIT1(setcb, VAR(C_FLAG))
-# define IMM5_ASR_0 \
- "sarl $31,%%edx;"\
+# define IMM5_ASR_0 \
+ "sarl $31,%%edx;" \
EMIT1(setsb, VAR(C_FLAG))
# define THREEARG_INSN(OP, N) \
asm("movl %%eax,%%edx;" \
@@ -401,7 +397,7 @@
OP(N) \
EMIT1(setsb, VAR(N_FLAG)) \
EMIT1(setzb, VAR(Z_FLAG)) \
- EMIT2(movl, ecx, REGREF2(eax,4)) \
+ EMIT2(movl, ecx, REGREF2(eax, 4)) \
: : )
# define ADD_RD_RS_RN(N) \
EMIT2(add, VAR(reg) "+" #N "*4", ecx) \
@@ -420,7 +416,7 @@
EMIT1(setncb, VAR(C_FLAG)) \
EMIT1(setob, VAR(V_FLAG))
# define SUB_RD_RS_O3(N) \
- "sub $"#N",%%ecx;" \
+ "sub $" #N ",%%ecx;" \
EMIT1(setncb, VAR(C_FLAG)) \
EMIT1(setob, VAR(V_FLAG))
# define SUB_RD_RS_O3_0(N) \
@@ -718,7 +714,7 @@
uint32_t lhs = reg[(d)].I; \
uint32_t rhs = opcode & 255; \
uint32_t res = lhs + rhs; \
- reg[(d)].I = res;\
+ reg[(d)].I = res; \
Z_FLAG = !res; \
N_FLAG = !!NEG(res); \
ADDCARRY(lhs, rhs, res); \
@@ -863,7 +859,7 @@
#ifndef ASR_RD_RS
# define ASR_RD_RS \
{ \
- C_FLAG = !!((static_cast<int32_t>(reg[dest].I >> static_cast<int>(value - 1)) & 1); \
+ C_FLAG = !!((static_cast<int32_t>(reg[dest].I) >> static_cast<int>(value - 1)) & 1); \
value = static_cast<int32_t>(reg[dest].I) >> static_cast<int>(value); \
}
#endif
@@ -1224,7 +1220,7 @@
if (value)
{
- value &= 0x1f;
+ value = value & 0x1f;
if (!value)
C_FLAG = !!(reg[dest].I & 0x80000000);
else
@@ -1233,9 +1229,9 @@
reg[dest].I = value;
}
}
- clockTicks = codeTicksAccess16(armNextPC) + 2;
N_FLAG = !!(reg[dest].I & 0x80000000);
Z_FLAG = !reg[dest].I;
+ clockTicks = codeTicksAccess16(armNextPC) + 2;
}
// TST Rd, Rs
@@ -1275,8 +1271,8 @@
{
int dest = opcode & 7;
reg[dest].I |= reg[(opcode >> 3) & 7].I;
+ N_FLAG = !!(reg[dest].I & 0x80000000);
Z_FLAG = !reg[dest].I;
- N_FLAG = !!(reg[dest].I & 0x80000000);
}
// MUL Rd, Rs
@@ -1289,7 +1285,7 @@
if (static_cast<int32_t>(rm) < 0)
rm = ~rm;
if (!(rm & 0xFFFFFF00))
- ; // No-op
+ ; /* No-op */
else if (!(rm & 0xFFFF0000))
++clockTicks;
else if (!(rm & 0xFF000000))
@@ -1297,9 +1293,9 @@
else
clockTicks += 3;
busPrefetchCount = (busPrefetchCount << clockTicks) | (0xFF >> (8 - clockTicks));
+ N_FLAG = !!(reg[dest].I & 0x80000000);
+ Z_FLAG = !reg[dest].I;
clockTicks += codeTicksAccess16(armNextPC) + 1;
- Z_FLAG = !reg[dest].I;
- N_FLAG = !!(reg[dest].I & 0x80000000);
}
// BIC Rd, Rs
@@ -1307,8 +1303,8 @@
{
int dest = opcode & 7;
reg[dest].I &= ~reg[(opcode >> 3) & 7].I;
+ N_FLAG = !!(reg[dest].I & 0x80000000);
Z_FLAG = !reg[dest].I;
- N_FLAG = !!(reg[dest].I & 0x80000000);
}
// MVN Rd, Rs
@@ -1316,8 +1312,8 @@
{
int dest = opcode & 7;
reg[dest].I = ~reg[(opcode >> 3) & 7].I;
+ N_FLAG = !!(reg[dest].I & 0x80000000);
Z_FLAG = !reg[dest].I;
- N_FLAG = !!(reg[dest].I & 0x80000000);
}
// High-register instructions and BX //////////////////////////////////////
@@ -1339,7 +1335,7 @@
reg[15].I += 2;
THUMB_PREFETCH();
clockTicks = codeTicksAccessSeq16(armNextPC) * 2 + codeTicksAccess16(armNextPC) + 3;
- }
+ }
}
// ADD Hd, Hs
@@ -1538,7 +1534,7 @@
if (!busPrefetchCount)
busPrefetch = busPrefetchEnable;
uint32_t address = reg[(opcode >> 3) & 7].I + reg[(opcode >> 6) & 7].I;
- reg[opcode & 7].I = (uint32_t)CPUReadHalfWordSigned(address);
+ reg[opcode & 7].I = static_cast<uint32_t>(CPUReadHalfWordSigned(address));
clockTicks = 3 + dataTicksAccess16(address) + codeTicksAccess16(armNextPC);
}
@@ -1803,7 +1799,7 @@
if (!busPrefetchCount)
busPrefetch = busPrefetchEnable;
uint32_t address = reg[regist].I & 0xFFFFFFFC;
- uint32_t temp = reg[regist].I + 4*cpuBitsSet[opcode & 0xff];
+ uint32_t temp = reg[regist].I + 4 * cpuBitsSet[opcode & 0xff];
int count = 0;
// store
THUMB_STM_REG(1, 0, regist);
@@ -1824,7 +1820,7 @@
if (!busPrefetchCount)
busPrefetch = busPrefetchEnable;
uint32_t address = reg[regist].I & 0xFFFFFFFC;
- uint32_t temp = reg[regist].I + 4*cpuBitsSet[opcode & 0xFF];
+ uint32_t temp = reg[regist].I + 4 * cpuBitsSet[opcode & 0xFF];
int count = 0;
// load
THUMB_LDM_REG(1, 0);
@@ -2057,7 +2053,6 @@
// SWI #comment
static INSN_REGPARM void thumbDF(uint32_t opcode)
{
- uint32_t address = 0;
clockTicks = 3;
busPrefetchCount = 0;
CPUSoftwareInterrupt(opcode & 0xFF);
--- a/src/in_gsf/vbam/gba/GBA.cpp
+++ b/src/in_gsf/vbam/gba/GBA.cpp
@@ -10,10 +10,6 @@
#include "../common/Port.h"
extern int mapgsf(uint8_t *a, int l, int &s);
-
-#ifdef __GNUC__
-#define _stricmp strcasecmp
-#endif
int SWITicks = 0;
static int IRQTicks = 0;
@@ -306,8 +302,7 @@
mapgsf(rom, 0x2000000, romSize);
uint16_t *temp = reinterpret_cast<uint16_t *>(rom + ((romSize + 1) & ~1));
- int i;
- for (i = (romSize + 1) & ~1; i < 0x2000000; i += 2)
+ for (int i = (romSize + 1) & ~1; i < 0x2000000; i += 2)
{
WRITE16LE(temp, (i >> 1) & 0xFFFF);
++temp;
@@ -498,9 +493,6 @@
comment >>= 16;
if (comment == 0xfa)
return;
- // This would be correct, but it causes problems if uncommented
- //else
- //biosProtected = 0xe3a02004;
switch (comment)
{
@@ -543,7 +535,7 @@
if ((reg[2].I >> 26) & 1)
SWITicks = (7 + memoryWait32[(reg[1].I >> 24) & 0xF]) * (len >> 1);
else
- SWITicks = (8 + memoryWait[(reg[1].I >> 24) & 0xF]) * (len);
+ SWITicks = (8 + memoryWait[(reg[1].I >> 24) & 0xF]) * len;
}
else
{
@@ -638,7 +630,7 @@
{
uint32_t len = CPUReadMemory(reg[0].I) >> 9;
if (!(!(reg[0].I & 0xe000000) || !((reg[0].I + (len & 0x1fffff)) & 0xe000000)))
- SWITicks = (39 + (memoryWait[(reg[0].I >> 24) & 0xF]<<1) + memoryWait[(reg[1].I >> 24) & 0xF]) * len;
+ SWITicks = (39 + (memoryWait[(reg[0].I >> 24) & 0xF] << 1) + memoryWait[(reg[1].I >> 24) & 0xF]) * len;
BIOS_Diff8bitUnFilterVram();
break;
}
@@ -786,8 +778,6 @@
uint32_t destIncrement = 4;
switch ((DM0CNT_H >> 7) & 3)
{
- case 0:
- break;
case 1:
sourceIncrement = static_cast<uint32_t>(-4);
break;
@@ -796,8 +786,6 @@
}
switch ((DM0CNT_H >> 5) & 3)
{
- case 0:
- break;
case 1:
destIncrement = static_cast<uint32_t>(-4);
break;
@@ -833,8 +821,6 @@
uint32_t destIncrement = 4;
switch ((DM1CNT_H >> 7) & 3)
{
- case 0:
- break;
case 1:
sourceIncrement = static_cast<uint32_t>(-4);
break;
@@ -843,8 +829,6 @@
}
switch ((DM1CNT_H >> 5) & 3)
{
- case 0:
- break;
case 1:
destIncrement = static_cast<uint32_t>(-4);
break;
@@ -883,8 +867,6 @@
uint32_t destIncrement = 4;
switch ((DM2CNT_H >> 7) & 3)
{
- case 0:
- break;
case 1:
sourceIncrement = static_cast<uint32_t>(-4);
break;
@@ -893,8 +875,6 @@
}
switch ((DM2CNT_H >> 5) & 3)
{
- case 0:
- break;
case 1:
destIncrement = static_cast<uint32_t>(-4);
break;
@@ -933,8 +913,6 @@
uint32_t destIncrement = 4;
switch ((DM3CNT_H >> 7) & 3)
{
- case 0:
- break;
case 1:
sourceIncrement = static_cast<uint32_t>(-4);
break;
@@ -943,8 +921,6 @@
}
switch ((DM3CNT_H >> 5) & 3)
{
- case 0:
- break;
case 1:
destIncrement = static_cast<uint32_t>(-4);
break;
@@ -952,6 +928,7 @@
destIncrement = 0;
}
doDMA(dma3Source, dma3Dest, sourceIncrement, destIncrement, DM3CNT_L ? DM3CNT_L : 0x10000, DM3CNT_H & 0x0400);
+
if (DM3CNT_H & 0x4000)
{
IF |= 0x0800;
@@ -1002,6 +979,8 @@
if (!(DISPSTAT & 1))
{
lcdTicks = 1008;
+ //VCOUNT = 0;
+ //UPDATE_REG(0x06, VCOUNT);
DISPSTAT &= 0xFFFC;
UPDATE_REG(0x04, DISPSTAT);
CPUCompareVCOUNT();
@@ -1085,7 +1064,7 @@
UPDATE_REG(0x28, BG2X_L);
break;
case 0x2A:
- BG2X_H = (value & 0xFFF);
+ BG2X_H = value & 0xFFF;
UPDATE_REG(0x2A, BG2X_H);
break;
case 0x2C:
@@ -1476,7 +1455,7 @@
timer2Ticks = (0x10000 - TM2D) << timer2ClockReload;
UPDATE_REG(0x108, TM2D);
}
- timer2On = !(timer2Value & 0x80);
+ timer2On = !!(timer2Value & 0x80);
TM2CNT = timer2Value & 0xC7;
UPDATE_REG(0x10A, TM2CNT);
}
@@ -1511,7 +1490,8 @@
cpuBiosSwapped = true;
}
#endif
- memcpy(&bios[0], myROM, sizeof(myROM));
+
+ memcpy(&bios[0], &myROM[0], sizeof(myROM));
biosProtected[0] = 0x00;
biosProtected[1] = 0xf0;
@@ -1724,7 +1704,7 @@
map[2].mask = 0x3FFFF;
map[3].address = &internalRAM[0];
map[3].mask = 0x7FFF;
- map[4].address = ioMem;
+ map[4].address = &ioMem[0];
map[4].mask = 0x3FF;
map[5].address = &paletteRAM[0];
map[5].mask = 0x3FF;
--- a/src/in_gsf/vbam/gba/GBAcpu.h
+++ b/src/in_gsf/vbam/gba/GBAcpu.h
@@ -20,7 +20,7 @@
# define UNLIKELY(x) (x)
#endif
-inline void UPDATE_REG(uint32_t address, uint16_t value) { WRITE16LE(&ioMem[address],value); }
+inline void UPDATE_REG(uint32_t address, uint16_t value) { WRITE16LE(&ioMem[address], value); }
extern uint32_t cpuPrefetch[2];
--- a/src/in_gsf/vbam/gba/GBAinline.h
+++ b/src/in_gsf/vbam/gba/GBAinline.h
@@ -98,8 +98,8 @@
unreadable:
if (armState)
return CPUReadMemoryQuick(reg[15].I);
- else
- return CPUReadHalfWordQuick(reg[15].I) | CPUReadHalfWordQuick(reg[15].I) << 16;
+ else
+ return CPUReadHalfWordQuick(reg[15].I) | (CPUReadHalfWordQuick(reg[15].I) << 16);
}
if (oldAddress & 3)
@@ -108,13 +108,13 @@
int shift = (oldAddress & 3) << 3;
value = (value >> shift) | (value << (32 - shift));
#else
-#ifdef __GNUC__
+# ifdef __GNUC__
asm("and $3, %%ecx;"
"shl $3 ,%%ecx;"
"ror %%cl, %0"
: "=r" (value)
: "r" (value), "c" (oldAddress));
-#else
+# else
__asm
{
mov ecx, oldAddress;
@@ -122,7 +122,7 @@
shl ecx, 3;
ror [dword ptr value], cl;
}
-#endif
+# endif
#endif
}
@@ -204,16 +204,12 @@
else
value = READ16LE(&rom[address & 0x1FFFFFE]);
break;
- case 13:
- case 14:
- return 0;
- // default
default:
unreadable:
if (armState)
return CPUReadMemoryQuick(reg[15].I);
else
- return CPUReadHalfWordQuick(reg[15].I) | CPUReadHalfWordQuick(reg[15].I) << 16;
+ return CPUReadHalfWordQuick(reg[15].I) | (CPUReadHalfWordQuick(reg[15].I) << 16);
}
if (oldAddress & 1)
@@ -272,16 +268,12 @@
case 11:
case 12:
return rom[address & 0x1FFFFFF];
- case 13:
- case 14:
- return 0;
- // default
default:
unreadable:
if (armState)
return CPUReadMemoryQuick(reg[15].I);
else
- return CPUReadHalfWordQuick(reg[15].I) | CPUReadHalfWordQuick(reg[15].I) << 16;
+ return CPUReadHalfWordQuick(reg[15].I) | (CPUReadHalfWordQuick(reg[15].I) << 16);
}
}
--- a/src/in_gsf/vbam/gba/Sound.cpp
+++ b/src/in_gsf/vbam/gba/Sound.cpp
@@ -68,7 +68,7 @@
static std::unique_ptr<Gb_Apu> gb_apu;
static std::unique_ptr<Stereo_Buffer> stereo_buffer;
-static Blip_Synth<blip_best_quality, 1> pcm_synth[3]; // 32 kHz, 16 kHz, 8 kHz
+static Blip_Synth<blip_high_quality, 1> pcm_synth[3]; // 32 kHz, 16 kHz, 8 kHz
static inline blip_time_t blip_time()
{
--- a/src/in_gsf/vbam/gba/bios.cpp
+++ b/src/in_gsf/vbam/gba/bios.cpp
@@ -104,7 +104,7 @@
int bits = CPUReadByte(header + 2);
int revbits = 8 - bits;
- // u32 value = 0;
+ //uint32_t value = 0;
uint32_t base = CPUReadMemory(header + 4);
bool addBase = !!(base & 0x80000000);
base &= 0x7fffffff;
@@ -346,7 +346,7 @@
uint32_t header = CPUReadMemory(source);
source += 4;
- if (!(source & 0xe000000) | !((source + ((header >> 8) & 0x1fffff)) & 0xe000000))
+ if (!(source & 0xe000000) || !((source + ((header >> 8) & 0x1fffff)) & 0xe000000))
return;
int len = header >> 8;
@@ -416,7 +416,7 @@
reg[1].I = number % denom;
int32_t temp = static_cast<int32_t>(reg[0].I);
reg[3].I = static_cast<uint32_t>(temp < 0 ? -temp : temp);
- }
+ }
}
void BIOS_HuffUnComp()