| ... | ... |
@@ -49,7 +49,7 @@ |
| 49 | 49 |
<ClCompile> |
| 50 | 50 |
<WarningLevel>Level4</WarningLevel> |
| 51 | 51 |
<Optimization>Disabled</Optimization> |
| 52 |
- <PreprocessorDefinitions>WIN32;_WINDOWS;_USRDLL;IN_GSF_EXPORTS;_CRT_SECURE_NO_WARNINGS;WINAMP_PLUGIN;NO_DEBUGGER;FINAL_VERSION;_DEBUG;_ITERATOR_DEBUG_LEVEL=0;%(PreprocessorDefinitions)</PreprocessorDefinitions> |
|
| 52 |
+ <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> |
|
| 53 | 53 |
<AdditionalIncludeDirectories>G:\Code\my_xsf\src;$(zlibRootDir)\include;$(WinampSDKDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> |
| 54 | 54 |
<DisableSpecificWarnings>4100;4127;4189;4244;4291;4310;4512;4800;%(DisableSpecificWarnings)</DisableSpecificWarnings> |
| 55 | 55 |
</ClCompile> |
| ... | ... |
@@ -66,7 +66,7 @@ |
| 66 | 66 |
<Optimization>MaxSpeed</Optimization> |
| 67 | 67 |
<FunctionLevelLinking>true</FunctionLevelLinking> |
| 68 | 68 |
<IntrinsicFunctions>true</IntrinsicFunctions> |
| 69 |
- <PreprocessorDefinitions>WIN32;_WINDOWS;_USRDLL;IN_GSF_EXPORTS;_CRT_SECURE_NO_WARNINGS;WINAMP_PLUGIN;NO_DEBUGGER;FINAL_VERSION;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> |
|
| 69 |
+ <PreprocessorDefinitions>WIN32;_WINDOWS;_USRDLL;IN_GSF_EXPORTS;_CRT_SECURE_NO_WARNINGS;WINAMP_PLUGIN;NO_DEBUGGER;FINAL_VERSION;C_CORE;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> |
|
| 70 | 70 |
<AdditionalIncludeDirectories>G:\Code\my_xsf\src;$(zlibRootDir)\include;$(WinampSDKDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> |
| 71 | 71 |
<DisableSpecificWarnings>4100;4127;4189;4244;4291;4310;4512;4800;%(DisableSpecificWarnings)</DisableSpecificWarnings> |
| 72 | 72 |
</ClCompile> |
| ... | ... |
@@ -81,7 +81,9 @@ |
| 81 | 81 |
</ItemDefinitionGroup> |
| 82 | 82 |
<ItemGroup> |
| 83 | 83 |
<ClCompile Include="vbam\apu\Blip_Buffer.cpp" /> |
| 84 |
- <ClCompile Include="vbam\apu\Effects_Buffer.cpp" /> |
|
| 84 |
+ <ClCompile Include="vbam\apu\Effects_Buffer.cpp"> |
|
| 85 |
+ <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild> |
|
| 86 |
+ </ClCompile> |
|
| 85 | 87 |
<ClCompile Include="vbam\apu\Gb_Apu.cpp" /> |
| 86 | 88 |
<ClCompile Include="vbam\apu\Gb_Oscs.cpp" /> |
| 87 | 89 |
<ClCompile Include="vbam\apu\Multi_Buffer.cpp" /> |
| ... | ... |
@@ -97,7 +99,6 @@ |
| 97 | 99 |
<ItemGroup> |
| 98 | 100 |
<ClInclude Include="vbam\apu\blargg_common.h" /> |
| 99 | 101 |
<ClInclude Include="vbam\apu\blargg_config.h" /> |
| 100 |
- <ClInclude Include="vbam\apu\blargg_source.h" /> |
|
| 101 | 102 |
<ClInclude Include="vbam\apu\Blip_Buffer.h" /> |
| 102 | 103 |
<ClInclude Include="vbam\apu\Effects_Buffer.h" /> |
| 103 | 104 |
<ClInclude Include="vbam\apu\Gb_Apu.h" /> |
| ... | ... |
@@ -83,9 +83,6 @@ |
| 83 | 83 |
<ClInclude Include="vbam\apu\blargg_config.h"> |
| 84 | 84 |
<Filter>Header Files\vbam\apu</Filter> |
| 85 | 85 |
</ClInclude> |
| 86 |
- <ClInclude Include="vbam\apu\blargg_source.h"> |
|
| 87 |
- <Filter>Header Files\vbam\apu</Filter> |
|
| 88 |
- </ClInclude> |
|
| 89 | 86 |
<ClInclude Include="vbam\apu\Blip_Buffer.h"> |
| 90 | 87 |
<Filter>Header Files\vbam\apu</Filter> |
| 91 | 88 |
</ClInclude> |
| ... | ... |
@@ -1,12 +1,11 @@ |
| 1 | 1 |
// Blip_Buffer 0.4.1. http://www.slack.net/~ant/ |
| 2 | 2 |
|
| 3 |
-#include "Blip_Buffer.h" |
|
| 4 |
- |
|
| 5 | 3 |
#include <numeric> |
| 6 | 4 |
#include <cassert> |
| 7 | 5 |
#include <cmath> |
| 8 | 6 |
#include <cstring> |
| 9 | 7 |
#include <cstdlib> |
| 8 |
+#include "Blip_Buffer.h" |
|
| 10 | 9 |
|
| 11 | 10 |
/* Copyright (C) 2003-2007 Shay Green. This module is free software; you |
| 12 | 11 |
can redistribute it and/or modify it under the terms of the GNU Lesser |
| ... | ... |
@@ -23,7 +22,7 @@ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ |
| 23 | 22 |
|
| 24 | 23 |
Blip_Buffer::Blip_Buffer() |
| 25 | 24 |
{
|
| 26 |
- this->factor_ = LONG_MAX; |
|
| 25 |
+ this->factor_ = static_cast<uint32_t>(LONG_MAX); |
|
| 27 | 26 |
this->buffer_.clear(); |
| 28 | 27 |
this->buffer_size_ = 0; |
| 29 | 28 |
this->sample_rate_ = 0; |
| ... | ... |
@@ -62,7 +61,7 @@ void Blip_Buffer::clear(int entire_buffer) |
| 62 | 61 |
} |
| 63 | 62 |
} |
| 64 | 63 |
|
| 65 |
-Blip_Buffer::blargg_err_t Blip_Buffer::set_sample_rate(long new_rate, int msec) |
|
| 64 |
+void Blip_Buffer::set_sample_rate(long new_rate, int msec) |
|
| 66 | 65 |
{
|
| 67 | 66 |
// start with maximum length that resampled time can represent |
| 68 | 67 |
long new_size = (ULONG_MAX >> BLIP_BUFFER_ACCURACY) - blip_buffer_extra_ - 64; |
| ... | ... |
@@ -92,8 +91,6 @@ Blip_Buffer::blargg_err_t Blip_Buffer::set_sample_rate(long new_rate, int msec) |
| 92 | 91 |
this->bass_freq(this->bass_freq_); |
| 93 | 92 |
|
| 94 | 93 |
this->clear(); |
| 95 |
- |
|
| 96 |
- return 0; // success |
|
| 97 | 94 |
} |
| 98 | 95 |
|
| 99 | 96 |
blip_resampled_time_t Blip_Buffer::clock_rate_factor(long rate) const |
| ... | ... |
@@ -153,7 +150,7 @@ void Blip_Buffer::remove_samples(long count) |
| 153 | 150 |
// copy remaining samples to beginning and clear old samples |
| 154 | 151 |
long remain = this->samples_avail() + blip_buffer_extra_; |
| 155 | 152 |
memmove(&this->buffer_[0], &this->buffer_[count], remain * sizeof(this->buffer_[0])); |
| 156 |
- memset(&this->buffer_[0] + remain, 0, count * sizeof(this->buffer_[0])); |
|
| 153 |
+ memset(&this->buffer_[remain], 0, count * sizeof(this->buffer_[0])); |
|
| 157 | 154 |
} |
| 158 | 155 |
} |
| 159 | 156 |
|
| ... | ... |
@@ -182,8 +179,9 @@ Blip_Synth_::Blip_Synth_(short *p, int w) : impulses(p), width(w) |
| 182 | 179 |
this->delta_factor = 0; |
| 183 | 180 |
} |
| 184 | 181 |
|
| 185 |
-#undef M_PI |
|
| 182 |
+#ifndef M_PI |
|
| 186 | 183 |
static const double M_PI = 3.1415926535897932384626433832795029; |
| 184 |
+#endif |
|
| 187 | 185 |
|
| 188 | 186 |
static void gen_sinc(float *out, int count, double oversample, double treble, double cutoff) |
| 189 | 187 |
{
|
| ... | ... |
@@ -251,7 +249,7 @@ void Blip_Synth_::adjust_impulse() |
| 251 | 249 |
} |
| 252 | 250 |
|
| 253 | 251 |
//for (int i = blip_res; i--; printf("\n"))
|
| 254 |
- //for (int j = 0; j < width / 2; ++j) |
|
| 252 |
+ //for (int j = 0; j < this->width / 2; ++j) |
|
| 255 | 253 |
//printf("%5ld,", this->impulses[j * blip_res + i + 1]);
|
| 256 | 254 |
} |
| 257 | 255 |
|
| ... | ... |
@@ -259,7 +257,7 @@ void Blip_Synth_::treble_eq(const blip_eq_t &eq) |
| 259 | 257 |
{
|
| 260 | 258 |
float fimpulse[blip_res / 2 * (blip_widest_impulse_ - 1) + blip_res * 2]; |
| 261 | 259 |
|
| 262 |
- static const int half_size = blip_res / 2 * (this->width - 1); |
|
| 260 |
+ int half_size = blip_res / 2 * (this->width - 1); |
|
| 263 | 261 |
eq.generate(&fimpulse[blip_res], half_size); |
| 264 | 262 |
|
| 265 | 263 |
int i; |
| ... | ... |
@@ -376,7 +374,7 @@ void Blip_Buffer::mix_samples(const blip_sample_t *in, long count) |
| 376 | 374 |
{
|
| 377 | 375 |
auto out = &this->buffer_[(this->offset_ >> BLIP_BUFFER_ACCURACY) + blip_widest_impulse_ / 2]; |
| 378 | 376 |
|
| 379 |
- int sample_shift = blip_sample_bits - 16; |
|
| 377 |
+ static const int sample_shift = blip_sample_bits - 16; |
|
| 380 | 378 |
int prev = 0; |
| 381 | 379 |
while (count--) |
| 382 | 380 |
{
|
| ... | ... |
@@ -17,12 +17,10 @@ enum { blip_sample_max = 32767 };
|
| 17 | 17 |
class Blip_Buffer |
| 18 | 18 |
{
|
| 19 | 19 |
public: |
| 20 |
- typedef const char *blargg_err_t; |
|
| 21 |
- |
|
| 22 | 20 |
// Sets output sample rate and buffer length in milliseconds (1/1000 sec, defaults |
| 23 | 21 |
// to 1/4 second) and clears buffer. If there isn't enough memory, leaves buffer |
| 24 | 22 |
// untouched and returns "Out of memory", otherwise returns NULL. |
| 25 |
- blargg_err_t set_sample_rate(long samples_per_sec, int msec_length = 1000 / 4); |
|
| 23 |
+ void set_sample_rate(long samples_per_sec, int msec_length = 1000 / 4); |
|
| 26 | 24 |
|
| 27 | 25 |
// Sets number of source time units per second |
| 28 | 26 |
void clock_rate(long clocks_per_sec); |
| ... | ... |
@@ -96,8 +94,6 @@ public: |
| 96 | 94 |
|
| 97 | 95 |
// Deprecated |
| 98 | 96 |
typedef blip_resampled_time_t resampled_time_t; |
| 99 |
- blargg_err_t sample_rate(long r) { return this->set_sample_rate(r); }
|
|
| 100 |
- blargg_err_t sample_rate(long r, int msec) { return this->set_sample_rate(r, msec); }
|
|
| 101 | 97 |
private: |
| 102 | 98 |
// noncopyable |
| 103 | 99 |
Blip_Buffer(const Blip_Buffer &); |
| ... | ... |
@@ -116,7 +112,6 @@ private: |
| 116 | 112 |
int bass_freq_; |
| 117 | 113 |
int length_; |
| 118 | 114 |
Blip_Buffer *modified_; // non-zero = true (more optimal than using bool, heh) |
| 119 |
- friend class Blip_Reader; |
|
| 120 | 115 |
}; |
| 121 | 116 |
|
| 122 | 117 |
// Number of bits in resample ratio fraction. Higher values give a more accurate ratio |
| ... | ... |
@@ -282,8 +277,6 @@ const int blip_reader_default_bass = 9; |
| 282 | 277 |
// experimental |
| 283 | 278 |
#define BLIP_READER_ADJ_(name, offset) (name##_reader_buf += offset) |
| 284 | 279 |
|
| 285 |
-const int32_t blip_reader_idx_factor = sizeof(Blip_Buffer::buf_t_); |
|
| 286 |
- |
|
| 287 | 280 |
#define BLIP_READER_NEXT_IDX_(name, bass, idx) \ |
| 288 | 281 |
{ \
|
| 289 | 282 |
name##_reader_accum -= name##_reader_accum >> (bass); \ |
| ... | ... |
@@ -292,15 +285,10 @@ const int32_t blip_reader_idx_factor = sizeof(Blip_Buffer::buf_t_); |
| 292 | 285 |
|
| 293 | 286 |
#define BLIP_READER_NEXT_RAW_IDX_(name, bass, idx) \ |
| 294 | 287 |
{ \
|
| 295 |
- name##_reader_accum -= name##_reader_accum >> (bass);\ |
|
| 296 |
- name##_reader_accum += *reinterpret_cast<const Blip_Buffer::buf_t_ *>(reinterpret_cast<const char *>(name##_reader_buf) + (idx));\ |
|
| 288 |
+ name##_reader_accum -= name##_reader_accum >> (bass); \ |
|
| 289 |
+ name##_reader_accum += *reinterpret_cast<const Blip_Buffer::buf_t_ *>(reinterpret_cast<const char *>(name##_reader_buf) + (idx)); \ |
|
| 297 | 290 |
} |
| 298 | 291 |
|
| 299 |
-// Compatibility with older version |
|
| 300 |
-const long blip_unscaled = 65535; |
|
| 301 |
-const int blip_low_quality = blip_med_quality; |
|
| 302 |
-const int blip_best_quality = blip_high_quality; |
|
| 303 |
- |
|
| 304 | 292 |
#if defined(_M_IX86) || defined(_M_IA64) || defined(__i486__) || defined(__x86_64__) || defined(__ia64__) || defined(__i386__) |
| 305 | 293 |
template<typename T> inline bool BLIP_CLAMP_(const T &in) { return in < -0x8000 || 0x7FFF < in; }
|
| 306 | 294 |
#else |
| ... | ... |
@@ -338,7 +326,7 @@ template<int quality, int range> inline void Blip_Synth<quality, range>::offset_ |
| 338 | 326 |
// sub-sample resolution. |
| 339 | 327 |
int32_t right = (delta >> BLIP_PHASE_BITS) * phase; |
| 340 | 328 |
left -= right; |
| 341 |
- right += buf [1]; |
|
| 329 |
+ right += buf[1]; |
|
| 342 | 330 |
|
| 343 | 331 |
buf[0] = left; |
| 344 | 332 |
buf[1] = right; |
| 345 | 333 |
deleted file mode 100644 |
| ... | ... |
@@ -1,609 +0,0 @@ |
| 1 |
-// Game_Music_Emu $vers. http://www.slack.net/~ant/ |
|
| 2 |
- |
|
| 3 |
-#include "Effects_Buffer.h" |
|
| 4 |
- |
|
| 5 |
-#include <cmath> |
|
| 6 |
-#include <cstring> |
|
| 7 |
- |
|
| 8 |
-/* Copyright (C) 2006-2007 Shay Green. This module is free software; you |
|
| 9 |
-can redistribute it and/or modify it under the terms of the GNU Lesser |
|
| 10 |
-General Public License as published by the Free Software Foundation; either |
|
| 11 |
-version 2.1 of the License, or (at your option) any later version. This |
|
| 12 |
-module is distributed in the hope that it will be useful, but WITHOUT ANY |
|
| 13 |
-WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
|
| 14 |
-FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
|
| 15 |
-details. You should have received a copy of the GNU Lesser General Public |
|
| 16 |
-License along with this module; if not, write to the Free Software Foundation, |
|
| 17 |
-Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ |
|
| 18 |
- |
|
| 19 |
-#include "blargg_source.h" |
|
| 20 |
- |
|
| 21 |
-static const int fixed_shift = 12; |
|
| 22 |
-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)); }
|
|
| 23 |
-static inline Effects_Buffer::fixed_t FROM_FIXED(Effects_Buffer::fixed_t f) { return f >> fixed_shift; }
|
|
| 24 |
- |
|
| 25 |
-static const int max_read = 2560; // determines minimum delay |
|
| 26 |
- |
|
| 27 |
-Effects_Buffer::Effects_Buffer(int max_bufs, long echo_size_) : Multi_Buffer(stereo) |
|
| 28 |
-{
|
|
| 29 |
- this->echo_size = std::max<long>(max_read * stereo, echo_size_ & ~1); |
|
| 30 |
- this->clock_rate_ = 0; |
|
| 31 |
- this->bass_freq_ = 90; |
|
| 32 |
- this->bufs.clear(); |
|
| 33 |
- this->bufs_size = 0; |
|
| 34 |
- this->bufs_max = std::max<int>(max_bufs, extra_chans); |
|
| 35 |
- this->no_echo = this->no_effects = true; |
|
| 36 |
- |
|
| 37 |
- // defaults |
|
| 38 |
- this->config_.enabled = false; |
|
| 39 |
- this->config_.delay[0] = 120; |
|
| 40 |
- this->config_.delay[1] = 122; |
|
| 41 |
- this->config_.feedback = 0.2f; |
|
| 42 |
- this->config_.treble = 0.4f; |
|
| 43 |
- |
|
| 44 |
- static const float sep = 0.8f; |
|
| 45 |
- this->config_.side_chans[0].pan = -sep; |
|
| 46 |
- this->config_.side_chans[1].pan = sep; |
|
| 47 |
- this->config_.side_chans[0].vol = this->config_.side_chans[1].vol = 1.0f; |
|
| 48 |
- |
|
| 49 |
- memset(&this->s, 0, sizeof(this->s)); |
|
| 50 |
- this->clear(); |
|
| 51 |
-} |
|
| 52 |
- |
|
| 53 |
-Effects_Buffer::~Effects_Buffer() |
|
| 54 |
-{
|
|
| 55 |
- this->delete_bufs(); |
|
| 56 |
-} |
|
| 57 |
- |
|
| 58 |
-// avoid using new [] |
|
| 59 |
-blargg_err_t Effects_Buffer::new_bufs(int size) |
|
| 60 |
-{
|
|
| 61 |
- this->delete_bufs(); |
|
| 62 |
- this->bufs.resize(size); |
|
| 63 |
- for (int i = 0; i < size; ++i) |
|
| 64 |
- this->bufs[i].reset(new buf_t); |
|
| 65 |
- this->bufs_size = size; |
|
| 66 |
- return 0; |
|
| 67 |
-} |
|
| 68 |
- |
|
| 69 |
-void Effects_Buffer::delete_bufs() |
|
| 70 |
-{
|
|
| 71 |
- this->bufs.clear(); |
|
| 72 |
- this->bufs_size = 0; |
|
| 73 |
-} |
|
| 74 |
- |
|
| 75 |
-blargg_err_t Effects_Buffer::set_sample_rate(long rate, int msec) |
|
| 76 |
-{
|
|
| 77 |
- // extra to allow farther past-the-end pointers |
|
| 78 |
- this->mixer.samples_read = 0; |
|
| 79 |
- this->echo.resize(echo_size + stereo); |
|
| 80 |
- return Multi_Buffer::set_sample_rate(rate, msec); |
|
| 81 |
-} |
|
| 82 |
- |
|
| 83 |
-void Effects_Buffer::clock_rate(long rate) |
|
| 84 |
-{
|
|
| 85 |
- this->clock_rate_ = rate; |
|
| 86 |
- for (int i = this->bufs_size; --i >= 0; ) |
|
| 87 |
- this->bufs[i]->clock_rate(this->clock_rate_); |
|
| 88 |
-} |
|
| 89 |
- |
|
| 90 |
-void Effects_Buffer::bass_freq(int freq) |
|
| 91 |
-{
|
|
| 92 |
- this->bass_freq_ = freq; |
|
| 93 |
- for (int i = this->bufs_size; --i >= 0; ) |
|
| 94 |
- this->bufs[i]->bass_freq(this->bass_freq_); |
|
| 95 |
-} |
|
| 96 |
- |
|
| 97 |
-blargg_err_t Effects_Buffer::set_channel_count(int count, const int *types) |
|
| 98 |
-{
|
|
| 99 |
- Multi_Buffer::set_channel_count(count, types); |
|
| 100 |
- |
|
| 101 |
- this->delete_bufs(); |
|
| 102 |
- |
|
| 103 |
- this->mixer.samples_read = 0; |
|
| 104 |
- |
|
| 105 |
- this->chans.resize(count + extra_chans); |
|
| 106 |
- |
|
| 107 |
- this->new_bufs(std::min(this->bufs_max, count + extra_chans)); |
|
| 108 |
- |
|
| 109 |
- for (int i = this->bufs_size; --i >= 0; ) |
|
| 110 |
- RETURN_ERR(this->bufs[i]->set_sample_rate(this->sample_rate(), this->length())); |
|
| 111 |
- |
|
| 112 |
- for (int i = this->chans.size(); --i >= 0; ) |
|
| 113 |
- {
|
|
| 114 |
- auto &ch = this->chans[i]; |
|
| 115 |
- ch.cfg.vol = 1.0f; |
|
| 116 |
- ch.cfg.pan = 0.0f; |
|
| 117 |
- ch.cfg.surround = ch.cfg.echo = false; |
|
| 118 |
- } |
|
| 119 |
- // side channels with echo |
|
| 120 |
- this->chans[2].cfg.echo = this->chans[3].cfg.echo = true; |
|
| 121 |
- |
|
| 122 |
- this->clock_rate(this->clock_rate_); |
|
| 123 |
- this->bass_freq(this->bass_freq_); |
|
| 124 |
- this->apply_config(); |
|
| 125 |
- this->clear(); |
|
| 126 |
- |
|
| 127 |
- return 0; |
|
| 128 |
-} |
|
| 129 |
- |
|
| 130 |
-void Effects_Buffer::clear_echo() |
|
| 131 |
-{
|
|
| 132 |
- if (!this->echo.empty()) |
|
| 133 |
- memset(&this->echo[0], 0, this->echo.size() * sizeof(echo[0])); |
|
| 134 |
-} |
|
| 135 |
- |
|
| 136 |
-void Effects_Buffer::clear() |
|
| 137 |
-{
|
|
| 138 |
- this->echo_pos = 0; |
|
| 139 |
- this->s.low_pass[0] = this->s.low_pass[1] = 0; |
|
| 140 |
- this->mixer.samples_read = 0; |
|
| 141 |
- |
|
| 142 |
- for (int i = this->bufs_size; --i >= 0; ) |
|
| 143 |
- this->bufs[i]->clear(); |
|
| 144 |
- this->clear_echo(); |
|
| 145 |
-} |
|
| 146 |
- |
|
| 147 |
-auto Effects_Buffer::channel(int i) -> channel_t |
|
| 148 |
-{
|
|
| 149 |
- i += extra_chans; |
|
| 150 |
- assert(extra_chans <= i && i < static_cast<int>(this->chans.size())); |
|
| 151 |
- return this->chans[i].channel; |
|
| 152 |
-} |
|
| 153 |
- |
|
| 154 |
-// Configuration |
|
| 155 |
- |
|
| 156 |
-// 3 wave positions with/without surround, 2 multi (one with same config as wave) |
|
| 157 |
-static const int simple_bufs = 3 * 2 + 2 - 1; |
|
| 158 |
- |
|
| 159 |
-Simple_Effects_Buffer::Simple_Effects_Buffer() : Effects_Buffer(extra_chans + simple_bufs, 18 * 1024L) |
|
| 160 |
-{
|
|
| 161 |
- this->config_.echo = 0.20f; |
|
| 162 |
- this->config_.stereo = 0.20f; |
|
| 163 |
- this->config_.surround = true; |
|
| 164 |
- this->config_.enabled = false; |
|
| 165 |
-} |
|
| 166 |
- |
|
| 167 |
-void Simple_Effects_Buffer::apply_config() |
|
| 168 |
-{
|
|
| 169 |
- auto &c = Effects_Buffer::config(); |
|
| 170 |
- |
|
| 171 |
- c.enabled = this->config_.enabled; |
|
| 172 |
- if (c.enabled) |
|
| 173 |
- {
|
|
| 174 |
- c.delay[0] = 120; |
|
| 175 |
- c.delay[1] = 122; |
|
| 176 |
- c.feedback = this->config_.echo * 0.7f; |
|
| 177 |
- c.treble = 0.6f - 0.3f * this->config_.echo; |
|
| 178 |
- |
|
| 179 |
- float sep = this->config_.stereo + 0.80f; |
|
| 180 |
- if (sep > 1.0f) |
|
| 181 |
- sep = 1.0f; |
|
| 182 |
- |
|
| 183 |
- c.side_chans[0].pan = -sep; |
|
| 184 |
- c.side_chans[1].pan = sep; |
|
| 185 |
- |
|
| 186 |
- for (int i = this->channel_count(); --i >= 0; ) |
|
| 187 |
- {
|
|
| 188 |
- auto &ch = Effects_Buffer::chan_config(i); |
|
| 189 |
- |
|
| 190 |
- ch.pan = 0.0f; |
|
| 191 |
- ch.surround = this->config_.surround; |
|
| 192 |
- ch.echo = false; |
|
| 193 |
- |
|
| 194 |
- int type = this->channel_types() ? this->channel_types()[i] : 0; |
|
| 195 |
- if (!(type & noise_type)) |
|
| 196 |
- {
|
|
| 197 |
- int index = (type & type_index_mask) % 6 - 3; |
|
| 198 |
- if (index < 0) |
|
| 199 |
- {
|
|
| 200 |
- index += 3; |
|
| 201 |
- ch.surround = false; |
|
| 202 |
- ch.echo = true; |
|
| 203 |
- } |
|
| 204 |
- if (index >= 1) |
|
| 205 |
- {
|
|
| 206 |
- ch.pan = this->config_.stereo; |
|
| 207 |
- if (index == 1) |
|
| 208 |
- ch.pan = -ch.pan; |
|
| 209 |
- } |
|
| 210 |
- } |
|
| 211 |
- else if (type & 1) |
|
| 212 |
- ch.surround = false; |
|
| 213 |
- } |
|
| 214 |
- } |
|
| 215 |
- |
|
| 216 |
- Effects_Buffer::apply_config(); |
|
| 217 |
-} |
|
| 218 |
- |
|
| 219 |
-int Effects_Buffer::min_delay() const |
|
| 220 |
-{
|
|
| 221 |
- assert(this->sample_rate()); |
|
| 222 |
- return max_read * 1000L / this->sample_rate(); |
|
| 223 |
-} |
|
| 224 |
- |
|
| 225 |
-int Effects_Buffer::max_delay() const |
|
| 226 |
-{
|
|
| 227 |
- assert(this->sample_rate()); |
|
| 228 |
- return (this->echo_size / stereo - max_read) * 1000L / this->sample_rate(); |
|
| 229 |
-} |
|
| 230 |
- |
|
| 231 |
-void Effects_Buffer::apply_config() |
|
| 232 |
-{
|
|
| 233 |
- if (!this->bufs_size) |
|
| 234 |
- return; |
|
| 235 |
- |
|
| 236 |
- this->s.treble = TO_FIXED(this->config_.treble); |
|
| 237 |
- |
|
| 238 |
- bool echo_dirty = false; |
|
| 239 |
- |
|
| 240 |
- fixed_t old_feedback = this->s.feedback; |
|
| 241 |
- this->s.feedback = TO_FIXED(this->config_.feedback); |
|
| 242 |
- if (!old_feedback && this->s.feedback) |
|
| 243 |
- echo_dirty = true; |
|
| 244 |
- |
|
| 245 |
- // delays |
|
| 246 |
- int i; |
|
| 247 |
- for (i = stereo; --i >= 0;) |
|
| 248 |
- {
|
|
| 249 |
- long delay = this->config_.delay[i] * this->sample_rate() / 1000 * stereo; |
|
| 250 |
- delay = std::max<long>(delay, max_read * stereo); |
|
| 251 |
- delay = std::min<long>(delay, this->echo_size - max_read * stereo); |
|
| 252 |
- if (this->s.delay[i] != delay) |
|
| 253 |
- {
|
|
| 254 |
- this->s.delay[i] = delay; |
|
| 255 |
- echo_dirty = true; |
|
| 256 |
- } |
|
| 257 |
- } |
|
| 258 |
- |
|
| 259 |
- // side channels |
|
| 260 |
- for (i = 2; --i >= 0; ) |
|
| 261 |
- {
|
|
| 262 |
- this->chans[i + 2].cfg.vol = this->chans[i].cfg.vol = this->config_.side_chans[i].vol * 0.5f; |
|
| 263 |
- this->chans[i + 2].cfg.pan = this->chans[i].cfg.pan = this->config_.side_chans[i].pan; |
|
| 264 |
- } |
|
| 265 |
- |
|
| 266 |
- // convert volumes |
|
| 267 |
- for (i = this->chans.size(); --i >= 0; ) |
|
| 268 |
- {
|
|
| 269 |
- auto &ch = this->chans[i]; |
|
| 270 |
- ch.vol[0] = TO_FIXED(ch.cfg.vol - ch.cfg.vol * ch.cfg.pan); |
|
| 271 |
- ch.vol[1] = TO_FIXED(ch.cfg.vol + ch.cfg.vol * ch.cfg.pan); |
|
| 272 |
- if (ch.cfg.surround) |
|
| 273 |
- ch.vol[0] = -ch.vol [0]; |
|
| 274 |
- } |
|
| 275 |
- |
|
| 276 |
- this->assign_buffers(); |
|
| 277 |
- |
|
| 278 |
- // set side channels |
|
| 279 |
- for (i = this->chans.size(); --i >= 0; ) |
|
| 280 |
- {
|
|
| 281 |
- auto &ch = chans[i]; |
|
| 282 |
- ch.channel.left = this->chans[ch.cfg.echo * 2].channel.center; |
|
| 283 |
- ch.channel.right = this->chans[ch.cfg.echo * 2 + 1].channel.center; |
|
| 284 |
- } |
|
| 285 |
- |
|
| 286 |
- bool old_echo = !this->no_echo && !this->no_effects; |
|
| 287 |
- |
|
| 288 |
- // determine whether effects and echo are needed at all |
|
| 289 |
- this->no_effects = this->no_echo = true; |
|
| 290 |
- for (i = this->chans.size(); --i >= extra_chans; ) |
|
| 291 |
- {
|
|
| 292 |
- auto &ch = this->chans[i]; |
|
| 293 |
- if (ch.cfg.echo && this->s.feedback) |
|
| 294 |
- this->no_echo = false; |
|
| 295 |
- |
|
| 296 |
- if (ch.vol[0] != TO_FIXED(1) || ch.vol[1] != TO_FIXED(1)) |
|
| 297 |
- this->no_effects = false; |
|
| 298 |
- } |
|
| 299 |
- if (!this->no_echo) |
|
| 300 |
- this->no_effects = false; |
|
| 301 |
- |
|
| 302 |
- 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)) |
|
| 303 |
- this->no_effects = false; |
|
| 304 |
- |
|
| 305 |
- if (!this->config_.enabled) |
|
| 306 |
- this->no_effects = true; |
|
| 307 |
- |
|
| 308 |
- if (this->no_effects) |
|
| 309 |
- {
|
|
| 310 |
- for (i = this->chans.size(); --i >= 0; ) |
|
| 311 |
- {
|
|
| 312 |
- auto &ch = this->chans[i]; |
|
| 313 |
- ch.channel.center = this->bufs[2].get(); |
|
| 314 |
- ch.channel.left = this->bufs[0].get(); |
|
| 315 |
- ch.channel.right = this->bufs[1].get(); |
|
| 316 |
- } |
|
| 317 |
- } |
|
| 318 |
- |
|
| 319 |
- this->mixer.bufs[0] = this->bufs[0].get(); |
|
| 320 |
- this->mixer.bufs[1] = this->bufs[1].get(); |
|
| 321 |
- this->mixer.bufs[2] = this->bufs[2].get(); |
|
| 322 |
- |
|
| 323 |
- if (echo_dirty || (!old_echo && (!this->no_echo && !this->no_effects))) |
|
| 324 |
- this->clear_echo(); |
|
| 325 |
- |
|
| 326 |
- this->channels_changed(); |
|
| 327 |
-} |
|
| 328 |
- |
|
| 329 |
-void Effects_Buffer::assign_buffers() |
|
| 330 |
-{
|
|
| 331 |
- // assign channels to buffers |
|
| 332 |
- int buf_count = 0; |
|
| 333 |
- for (int i = 0; i < static_cast<int>(this->chans.size()); ++i) |
|
| 334 |
- {
|
|
| 335 |
- // put second two side channels at end to give priority to main channels |
|
| 336 |
- // in case closest matching is necessary |
|
| 337 |
- int x = i; |
|
| 338 |
- if (i > 1) |
|
| 339 |
- x += 2; |
|
| 340 |
- if (x >= static_cast<int>(this->chans.size())) |
|
| 341 |
- x -= this->chans.size() - 2; |
|
| 342 |
- auto &ch = this->chans[x]; |
|
| 343 |
- |
|
| 344 |
- int b = 0; |
|
| 345 |
- for (; b < buf_count; ++b) |
|
| 346 |
- {
|
|
| 347 |
- 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)) |
|
| 348 |
- break; |
|
| 349 |
- } |
|
| 350 |
- |
|
| 351 |
- if (b >= buf_count) |
|
| 352 |
- {
|
|
| 353 |
- if (buf_count < this->bufs_max) |
|
| 354 |
- {
|
|
| 355 |
- this->bufs[b]->vol[0] = ch.vol[0]; |
|
| 356 |
- this->bufs[b]->vol[1] = ch.vol[1]; |
|
| 357 |
- this->bufs[b]->echo = ch.cfg.echo; |
|
| 358 |
- ++buf_count; |
|
| 359 |
- } |
|
| 360 |
- else |
|
| 361 |
- {
|
|
| 362 |
- // TODO: this is a mess, needs refinement |
|
| 363 |
- b = 0; |
|
| 364 |
- fixed_t best_dist = TO_FIXED(8); |
|
| 365 |
- for (int h = buf_count; --h >= 0; ) |
|
| 366 |
- {
|
|
| 367 |
- auto CALC_LEVELS = [&](fixed_t vols[], fixed_t &sum, fixed_t &diff, bool &surround) |
|
| 368 |
- {
|
|
| 369 |
- fixed_t vol_0 = vols[0]; |
|
| 370 |
- if (vol_0 < 0) |
|
| 371 |
- {
|
|
| 372 |
- vol_0 = -vol_0; |
|
| 373 |
- surround = true; |
|
| 374 |
- } |
|
| 375 |
- fixed_t vol_1 = vols[1]; |
|
| 376 |
- if (vol_1 < 0) |
|
| 377 |
- {
|
|
| 378 |
- vol_1 = -vol_1; |
|
| 379 |
- surround = true; |
|
| 380 |
- } |
|
| 381 |
- sum = vol_0 + vol_1; |
|
| 382 |
- diff = vol_0 - vol_1; |
|
| 383 |
- }; |
|
| 384 |
- fixed_t ch_sum, ch_diff, buf_sum, buf_diff; |
|
| 385 |
- bool ch_surround, buf_surround; |
|
| 386 |
- CALC_LEVELS(ch.vol, ch_sum, ch_diff, ch_surround); |
|
| 387 |
- CALC_LEVELS(this->bufs[h]->vol, buf_sum, buf_diff, buf_surround); |
|
| 388 |
- |
|
| 389 |
- fixed_t dist = std::abs(ch_sum - buf_sum) + std::abs(ch_diff - buf_diff); |
|
| 390 |
- |
|
| 391 |
- if (ch_surround != buf_surround) |
|
| 392 |
- dist += TO_FIXED(1) / 2; |
|
| 393 |
- |
|
| 394 |
- if (this->s.feedback && ch.cfg.echo != this->bufs[h]->echo) |
|
| 395 |
- dist += TO_FIXED(1) / 2; |
|
| 396 |
- |
|
| 397 |
- if (best_dist > dist) |
|
| 398 |
- {
|
|
| 399 |
- best_dist = dist; |
|
| 400 |
- b = h; |
|
| 401 |
- } |
|
| 402 |
- } |
|
| 403 |
- } |
|
| 404 |
- } |
|
| 405 |
- |
|
| 406 |
- ch.channel.center = this->bufs[b].get(); |
|
| 407 |
- } |
|
| 408 |
-} |
|
| 409 |
- |
|
| 410 |
-// Mixing |
|
| 411 |
- |
|
| 412 |
-void Effects_Buffer::end_frame(blip_time_t time) |
|
| 413 |
-{
|
|
| 414 |
- for (int i = bufs_size; --i >= 0; ) |
|
| 415 |
- this->bufs[i]->end_frame(time); |
|
| 416 |
-} |
|
| 417 |
- |
|
| 418 |
-long Effects_Buffer::read_samples(blip_sample_t *out, long out_size) |
|
| 419 |
-{
|
|
| 420 |
- out_size = std::min(out_size, this->samples_avail()); |
|
| 421 |
- |
|
| 422 |
- int pair_count = static_cast<int>(out_size >> 1); |
|
| 423 |
- assert(pair_count * stereo == out_size); // must read an even number of samples |
|
| 424 |
- if (pair_count) |
|
| 425 |
- {
|
|
| 426 |
- if (this->no_effects) |
|
| 427 |
- this->mixer.read_pairs(out, pair_count); |
|
| 428 |
- else |
|
| 429 |
- {
|
|
| 430 |
- int pairs_remain = pair_count; |
|
| 431 |
- do |
|
| 432 |
- {
|
|
| 433 |
- // mix at most max_read pairs at a time |
|
| 434 |
- int count = max_read; |
|
| 435 |
- if (count > pairs_remain) |
|
| 436 |
- count = pairs_remain; |
|
| 437 |
- |
|
| 438 |
- if (this->no_echo) |
|
| 439 |
- {
|
|
| 440 |
- // optimization: clear echo here to keep mix_effects() a leaf function |
|
| 441 |
- this->echo_pos = 0; |
|
| 442 |
- memset(&this->echo[0], 0, count * stereo * sizeof(this->echo[0])); |
|
| 443 |
- } |
|
| 444 |
- this->mix_effects(out, count); |
|
| 445 |
- |
|
| 446 |
- int32_t new_echo_pos = this->echo_pos + count * stereo; |
|
| 447 |
- if (new_echo_pos >= this->echo_size) |
|
| 448 |
- new_echo_pos -= this->echo_size; |
|
| 449 |
- this->echo_pos = new_echo_pos; |
|
| 450 |
- assert(this->echo_pos < this->echo_size); |
|
| 451 |
- |
|
| 452 |
- out += count * stereo; |
|
| 453 |
- this->mixer.samples_read += count; |
|
| 454 |
- pairs_remain -= count; |
|
| 455 |
- } while (pairs_remain); |
|
| 456 |
- } |
|
| 457 |
- |
|
| 458 |
- if (this->samples_avail() <= 0 || this->immediate_removal()) |
|
| 459 |
- {
|
|
| 460 |
- for (int i = this->bufs_size; --i >= 0; ) |
|
| 461 |
- {
|
|
| 462 |
- auto &b = this->bufs[i]; |
|
| 463 |
- // TODO: might miss non-silence settling since it checks END of last read |
|
| 464 |
- if (b->non_silent()) |
|
| 465 |
- b->remove_samples(this->mixer.samples_read); |
|
| 466 |
- else |
|
| 467 |
- b->remove_silence(this->mixer.samples_read); |
|
| 468 |
- } |
|
| 469 |
- this->mixer.samples_read = 0; |
|
| 470 |
- } |
|
| 471 |
- } |
|
| 472 |
- return out_size; |
|
| 473 |
-} |
|
| 474 |
- |
|
| 475 |
-void Effects_Buffer::mix_effects(blip_sample_t *out_, int pair_count) |
|
| 476 |
-{
|
|
| 477 |
- typedef fixed_t stereo_fixed_t[stereo]; |
|
| 478 |
- |
|
| 479 |
- // add channels with echo, do echo, add channels without echo, then convert to 16-bit and output |
|
| 480 |
- int echo_phase = 1; |
|
| 481 |
- do |
|
| 482 |
- {
|
|
| 483 |
- // mix any modified buffers |
|
| 484 |
- {
|
|
| 485 |
- size_t bufNum = 0; |
|
| 486 |
- int bufs_remain = this->bufs_size; |
|
| 487 |
- do |
|
| 488 |
- {
|
|
| 489 |
- auto &buf = this->bufs[bufNum++]; |
|
| 490 |
- if (buf->non_silent() && (buf->echo == !!echo_phase)) |
|
| 491 |
- {
|
|
| 492 |
- auto out = reinterpret_cast<stereo_fixed_t *>(&this->echo[this->echo_pos]); |
|
| 493 |
- int bass = BLIP_READER_BASS(*buf); |
|
| 494 |
- BLIP_READER_BEGIN(in, *buf); |
|
| 495 |
- BLIP_READER_ADJ_(in, this->mixer.samples_read); |
|
| 496 |
- fixed_t vol_0 = buf->vol[0]; |
|
| 497 |
- fixed_t vol_1 = buf->vol[1]; |
|
| 498 |
- |
|
| 499 |
- int count = static_cast<unsigned>(echo_size - echo_pos) / stereo; |
|
| 500 |
- int remain = pair_count; |
|
| 501 |
- if (count > remain) |
|
| 502 |
- count = remain; |
|
| 503 |
- do |
|
| 504 |
- {
|
|
| 505 |
- remain -= count; |
|
| 506 |
- BLIP_READER_ADJ_(in, count); |
|
| 507 |
- |
|
| 508 |
- out += count; |
|
| 509 |
- int offset = -count; |
|
| 510 |
- do |
|
| 511 |
- {
|
|
| 512 |
- fixed_t s = BLIP_READER_READ(in); |
|
| 513 |
- BLIP_READER_NEXT_IDX_(in, bass, offset); |
|
| 514 |
- |
|
| 515 |
- out[offset][0] += s * vol_0; |
|
| 516 |
- out[offset][1] += s * vol_1; |
|
| 517 |
- } while ( ++offset ); |
|
| 518 |
- |
|
| 519 |
- out = reinterpret_cast<stereo_fixed_t *>(&this->echo[0]); |
|
| 520 |
- count = remain; |
|
| 521 |
- } while (remain); |
|
| 522 |
- |
|
| 523 |
- BLIP_READER_END(in, *buf); |
|
| 524 |
- } |
|
| 525 |
- } while (--bufs_remain); |
|
| 526 |
- } |
|
| 527 |
- |
|
| 528 |
- // add echo |
|
| 529 |
- if (echo_phase && !this->no_echo) |
|
| 530 |
- {
|
|
| 531 |
- fixed_t feedback = this->s.feedback; |
|
| 532 |
- fixed_t treble = this->s.treble; |
|
| 533 |
- |
|
| 534 |
- int i = 1; |
|
| 535 |
- do |
|
| 536 |
- {
|
|
| 537 |
- fixed_t low_pass = this->s.low_pass[i]; |
|
| 538 |
- |
|
| 539 |
- auto echo_end = &this->echo[this->echo_size + i]; |
|
| 540 |
- auto in_pos = &this->echo[this->echo_pos + i]; |
|
| 541 |
- int32_t out_offset = this->echo_pos + i + this->s.delay[i]; |
|
| 542 |
- if (out_offset >= this->echo_size) |
|
| 543 |
- out_offset -= this->echo_size; |
|
| 544 |
- assert(out_offset < this->echo_size); |
|
| 545 |
- auto out_pos = &this->echo[out_offset]; |
|
| 546 |
- |
|
| 547 |
- // break into up to three chunks to avoid having to handle wrap-around |
|
| 548 |
- // in middle of core loop |
|
| 549 |
- int remain = pair_count; |
|
| 550 |
- do |
|
| 551 |
- {
|
|
| 552 |
- auto pos = in_pos; |
|
| 553 |
- if (pos < out_pos) |
|
| 554 |
- pos = out_pos; |
|
| 555 |
- int count = static_cast<uint32_t>(reinterpret_cast<char *>(echo_end) - reinterpret_cast<const char *>(pos)) / (stereo * sizeof(fixed_t)); |
|
| 556 |
- if (count > remain) |
|
| 557 |
- count = remain; |
|
| 558 |
- remain -= count; |
|
| 559 |
- |
|
| 560 |
- in_pos += count * stereo; |
|
| 561 |
- out_pos += count * stereo; |
|
| 562 |
- int offset = -count; |
|
| 563 |
- do |
|
| 564 |
- {
|
|
| 565 |
- low_pass += FROM_FIXED(in_pos[offset * stereo] - low_pass) * treble; |
|
| 566 |
- out_pos[offset * stereo] = FROM_FIXED(low_pass) * feedback; |
|
| 567 |
- } while (++offset); |
|
| 568 |
- |
|
| 569 |
- if (in_pos >= echo_end) |
|
| 570 |
- in_pos -= echo_size; |
|
| 571 |
- if (out_pos >= echo_end) |
|
| 572 |
- out_pos -= echo_size; |
|
| 573 |
- } while (remain); |
|
| 574 |
- |
|
| 575 |
- this->s.low_pass [i] = low_pass; |
|
| 576 |
- } while (--i >= 0); |
|
| 577 |
- } |
|
| 578 |
- } while (--echo_phase >= 0); |
|
| 579 |
- |
|
| 580 |
- // clamp to 16 bits |
|
| 581 |
- auto in = reinterpret_cast<stereo_fixed_t *>(&this->echo[this->echo_pos]); |
|
| 582 |
- typedef blip_sample_t stereo_blip_sample_t[stereo]; |
|
| 583 |
- auto out = reinterpret_cast<stereo_blip_sample_t *>(out_); |
|
| 584 |
- int count = static_cast<unsigned>(this->echo_size - this->echo_pos) / stereo; |
|
| 585 |
- int remain = pair_count; |
|
| 586 |
- if (count > remain) |
|
| 587 |
- count = remain; |
|
| 588 |
- do |
|
| 589 |
- {
|
|
| 590 |
- remain -= count; |
|
| 591 |
- in += count; |
|
| 592 |
- out += count; |
|
| 593 |
- int offset = -count; |
|
| 594 |
- do |
|
| 595 |
- {
|
|
| 596 |
- fixed_t in_0 = FROM_FIXED(in[offset][0]); |
|
| 597 |
- fixed_t in_1 = FROM_FIXED(in[offset][1]); |
|
| 598 |
- |
|
| 599 |
- BLIP_CLAMP(in_0, in_0); |
|
| 600 |
- out[offset][0] = static_cast<blip_sample_t>(in_0); |
|
| 601 |
- |
|
| 602 |
- BLIP_CLAMP(in_1, in_1); |
|
| 603 |
- out[offset][1] = static_cast<blip_sample_t>(in_1); |
|
| 604 |
- } while (++offset); |
|
| 605 |
- |
|
| 606 |
- in = reinterpret_cast<stereo_fixed_t *>(&this->echo[0]); |
|
| 607 |
- count = remain; |
|
| 608 |
- } while (remain); |
|
| 609 |
-} |
| 610 | 0 |
deleted file mode 100644 |
| ... | ... |
@@ -1,141 +0,0 @@ |
| 1 |
-// Multi-channel effects buffer with echo and individual panning for each channel |
|
| 2 |
- |
|
| 3 |
-// Game_Music_Emu $vers |
|
| 4 |
-#ifndef EFFECTS_BUFFER_H |
|
| 5 |
-#define EFFECTS_BUFFER_H |
|
| 6 |
- |
|
| 7 |
-#include <vector> |
|
| 8 |
-#include "Multi_Buffer.h" |
|
| 9 |
- |
|
| 10 |
-// See Simple_Effects_Buffer (below) for a simpler interface |
|
| 11 |
- |
|
| 12 |
-class Effects_Buffer : public Multi_Buffer |
|
| 13 |
-{
|
|
| 14 |
-public: |
|
| 15 |
- // To reduce memory usage, fewer buffers can be used (with a best-fit |
|
| 16 |
- // approach if there are too few), and maximum echo delay can be reduced |
|
| 17 |
- Effects_Buffer(int max_bufs = 32, long echo_size = 24 * 1024L); |
|
| 18 |
- |
|
| 19 |
- struct pan_vol_t |
|
| 20 |
- {
|
|
| 21 |
- float vol; // 0.0 = silent, 0.5 = half volume, 1.0 = normal |
|
| 22 |
- float pan; // -1.0 = left, 0.0 = center, +1.0 = right |
|
| 23 |
- }; |
|
| 24 |
- |
|
| 25 |
- // Global configuration |
|
| 26 |
- struct config_t |
|
| 27 |
- {
|
|
| 28 |
- bool enabled; // false = disable all effects |
|
| 29 |
- |
|
| 30 |
- // Current sound is echoed at adjustable left/right delay, |
|
| 31 |
- // with reduced treble and volume (feedback). |
|
| 32 |
- float treble; // 1.0 = full treble, 0.1 = very little, 0.0 = silent |
|
| 33 |
- int delay [2]; // left, right delays (msec) |
|
| 34 |
- float feedback; // 0.0 = no echo, 0.5 = each echo half previous, 1.0 = cacophony |
|
| 35 |
- pan_vol_t side_chans[2]; // left and right side channel volume and pan |
|
| 36 |
- }; |
|
| 37 |
- config_t &config() { return this->config_; }
|
|
| 38 |
- |
|
| 39 |
- // Limits of delay (msec) |
|
| 40 |
- int min_delay() const; |
|
| 41 |
- int max_delay() const; |
|
| 42 |
- |
|
| 43 |
- // Per-channel configuration. Two or more channels with matching parameters are |
|
| 44 |
- // optimized to internally use the same buffer. |
|
| 45 |
- struct chan_config_t : pan_vol_t |
|
| 46 |
- {
|
|
| 47 |
- // (inherited from pan_vol_t) |
|
| 48 |
- //float vol; // these only affect center channel |
|
| 49 |
- //float pan; |
|
| 50 |
- bool surround; // if true, negates left volume to put sound in back |
|
| 51 |
- bool echo; // false = channel doesn't have any echo |
|
| 52 |
- }; |
|
| 53 |
- chan_config_t &chan_config(int i) { return this->chans[i + extra_chans].cfg; }
|
|
| 54 |
- |
|
| 55 |
- // Apply any changes made to config() and chan_config() |
|
| 56 |
- virtual void apply_config(); |
|
| 57 |
- |
|
| 58 |
- ~Effects_Buffer(); |
|
| 59 |
- blargg_err_t set_sample_rate(long samples_per_sec, int msec = blip_default_length); |
|
| 60 |
- blargg_err_t set_channel_count(int, const int * = nullptr); |
|
| 61 |
- void clock_rate(long); |
|
| 62 |
- void bass_freq(int); |
|
| 63 |
- void clear(); |
|
| 64 |
- channel_t channel(int); |
|
| 65 |
- void end_frame(blip_time_t); |
|
| 66 |
- long read_samples(blip_sample_t *, long); |
|
| 67 |
- long samples_avail() const { return (this->bufs[0]->samples_avail() - this->mixer.samples_read) * 2; }
|
|
| 68 |
- enum { stereo = 2 };
|
|
| 69 |
- typedef int32_t fixed_t; |
|
| 70 |
-protected: |
|
| 71 |
- enum { extra_chans = stereo * stereo };
|
|
| 72 |
-private: |
|
| 73 |
- config_t config_; |
|
| 74 |
- long clock_rate_; |
|
| 75 |
- int bass_freq_; |
|
| 76 |
- |
|
| 77 |
- int32_t echo_size; |
|
| 78 |
- |
|
| 79 |
- struct chan_t |
|
| 80 |
- {
|
|
| 81 |
- fixed_t vol [stereo]; |
|
| 82 |
- chan_config_t cfg; |
|
| 83 |
- channel_t channel; |
|
| 84 |
- }; |
|
| 85 |
- std::vector<chan_t> chans; |
|
| 86 |
- |
|
| 87 |
- struct buf_t : Tracked_Blip_Buffer |
|
| 88 |
- {
|
|
| 89 |
- fixed_t vol[stereo]; |
|
| 90 |
- bool echo; |
|
| 91 |
- }; |
|
| 92 |
- std::vector<std::unique_ptr<buf_t>> bufs; |
|
| 93 |
- int bufs_size; |
|
| 94 |
- int bufs_max; // bufs_size <= bufs_max, to limit memory usage |
|
| 95 |
- Stereo_Mixer mixer; |
|
| 96 |
- |
|
| 97 |
- struct |
|
| 98 |
- {
|
|
| 99 |
- long delay[stereo]; |
|
| 100 |
- fixed_t treble; |
|
| 101 |
- fixed_t feedback; |
|
| 102 |
- fixed_t low_pass[stereo]; |
|
| 103 |
- } s; |
|
| 104 |
- |
|
| 105 |
- std::vector<fixed_t> echo; |
|
| 106 |
- int32_t echo_pos; |
|
| 107 |
- |
|
| 108 |
- bool no_effects; |
|
| 109 |
- bool no_echo; |
|
| 110 |
- |
|
| 111 |
- void assign_buffers(); |
|
| 112 |
- void clear_echo(); |
|
| 113 |
- void mix_effects(blip_sample_t *out, int pair_count); |
|
| 114 |
- blargg_err_t new_bufs(int size); |
|
| 115 |
- void delete_bufs(); |
|
| 116 |
-}; |
|
| 117 |
- |
|
| 118 |
-// Simpler interface and lower memory usage |
|
| 119 |
-class Simple_Effects_Buffer : public Effects_Buffer |
|
| 120 |
-{
|
|
| 121 |
-public: |
|
| 122 |
- struct config_t |
|
| 123 |
- {
|
|
| 124 |
- bool enabled; // false = disable all effects |
|
| 125 |
- float echo; // 0.0 = none, 1.0 = lots |
|
| 126 |
- float stereo; // 0.0 = channels in center, 1.0 = channels on left/right |
|
| 127 |
- bool surround; // true = put some channels in back |
|
| 128 |
- }; |
|
| 129 |
- config_t &config() { return this->config_; }
|
|
| 130 |
- |
|
| 131 |
- // Apply any changes made to config() |
|
| 132 |
- void apply_config(); |
|
| 133 |
- |
|
| 134 |
-public: |
|
| 135 |
- Simple_Effects_Buffer(); |
|
| 136 |
-private: |
|
| 137 |
- config_t config_; |
|
| 138 |
- void chan_config(); // hide |
|
| 139 |
-}; |
|
| 140 |
- |
|
| 141 |
-#endif |
| ... | ... |
@@ -14,8 +14,6 @@ details. You should have received a copy of the GNU Lesser General Public |
| 14 | 14 |
License along with this module; if not, write to the Free Software Foundation, |
| 15 | 15 |
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ |
| 16 | 16 |
|
| 17 |
-#include "blargg_source.h" |
|
| 18 |
- |
|
| 19 | 17 |
static const unsigned vol_reg = 0xFF24; |
| 20 | 18 |
static const unsigned stereo_reg = 0xFF25; |
| 21 | 19 |
static const unsigned status_reg = 0xFF26; |
| ... | ... |
@@ -76,7 +74,7 @@ void Gb_Apu::apply_volume() |
| 76 | 74 |
|
| 77 | 75 |
void Gb_Apu::volume(double v) |
| 78 | 76 |
{
|
| 79 |
- if (volume_ != v) |
|
| 77 |
+ if (this->volume_ != v) |
|
| 80 | 78 |
{
|
| 81 | 79 |
this->volume_ = v; |
| 82 | 80 |
this->apply_volume(); |
| ... | ... |
@@ -117,7 +115,7 @@ void Gb_Apu::reduce_clicks(bool reduce) |
| 117 | 115 |
this->oscs[i]->dac_off_amp = dac_off_amp; |
| 118 | 116 |
|
| 119 | 117 |
// AGB always eliminates clicks on wave channel using same method |
| 120 |
- if (wave.mode == mode_agb) |
|
| 118 |
+ if (this->wave.mode == mode_agb) |
|
| 121 | 119 |
this->wave.dac_off_amp = -Gb_Osc::dac_bias; |
| 122 | 120 |
} |
| 123 | 121 |
|
| ... | ... |
@@ -166,10 +164,10 @@ Gb_Apu::Gb_Apu() |
| 166 | 164 |
{
|
| 167 | 165 |
this->wave.wave_ram = &this->regs[wave_ram - start_addr]; |
| 168 | 166 |
|
| 169 |
- this->oscs [0] = &this->square1; |
|
| 170 |
- this->oscs [1] = &this->square2; |
|
| 171 |
- this->oscs [2] = &this->wave; |
|
| 172 |
- this->oscs [3] = &this->noise; |
|
| 167 |
+ this->oscs[0] = &this->square1; |
|
| 168 |
+ this->oscs[1] = &this->square2; |
|
| 169 |
+ this->oscs[2] = &this->wave; |
|
| 170 |
+ this->oscs[3] = &this->noise; |
|
| 173 | 171 |
|
| 174 | 172 |
for (int i = osc_count; --i >= 0; ) |
| 175 | 173 |
{
|
| ... | ... |
@@ -199,10 +197,10 @@ void Gb_Apu::run_until_(blip_time_t end_time) |
| 199 | 197 |
if (time > this->frame_time) |
| 200 | 198 |
time = this->frame_time; |
| 201 | 199 |
|
| 202 |
- this->square1.run(last_time, time); |
|
| 203 |
- this->square2.run(last_time, time); |
|
| 204 |
- this->wave.run(last_time, time); |
|
| 205 |
- this->noise.run(last_time, time); |
|
| 200 |
+ this->square1.run(this->last_time, time); |
|
| 201 |
+ this->square2.run(this->last_time, time); |
|
| 202 |
+ this->wave.run(this->last_time, time); |
|
| 203 |
+ this->noise.run(this->last_time, time); |
|
| 206 | 204 |
this->last_time = time; |
| 207 | 205 |
|
| 208 | 206 |
if (time == end_time) |
| ... | ... |
@@ -358,7 +356,7 @@ int Gb_Apu::read_register(blip_time_t time, unsigned addr) |
| 358 | 356 |
return this->wave.read(addr); |
| 359 | 357 |
|
| 360 | 358 |
// Value read back has some bits always set |
| 361 |
- static const uint8_t masks [] = |
|
| 359 |
+ static const uint8_t masks[] = |
|
| 362 | 360 |
{
|
| 363 | 361 |
0x80, 0x3F, 0x00, 0xFF, 0xBF, |
| 364 | 362 |
0xFF, 0x3F, 0x00, 0xFF, 0xBF, |
| ... | ... |
@@ -13,8 +13,6 @@ details. You should have received a copy of the GNU Lesser General Public |
| 13 | 13 |
License along with this module; if not, write to the Free Software Foundation, |
| 14 | 14 |
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ |
| 15 | 15 |
|
| 16 |
-#include "blargg_source.h" |
|
| 17 |
- |
|
| 18 | 16 |
static const bool cgb_02 = false; // enables bug in early CGB units that causes problems in some games |
| 19 | 17 |
static const bool cgb_05 = false; // enables CGB-05 zombie behavior |
| 20 | 18 |
|
| ... | ... |
@@ -45,14 +43,14 @@ void Gb_Osc::update_amp(blip_time_t time, int new_amp) |
| 45 | 43 |
|
| 46 | 44 |
void Gb_Osc::clock_length() |
| 47 | 45 |
{
|
| 48 |
- if ((this->regs [4] & length_enabled) && this->length_ctr) |
|
| 46 |
+ if ((this->regs[4] & length_enabled) && this->length_ctr) |
|
| 49 | 47 |
{
|
| 50 | 48 |
if (--this->length_ctr <= 0) |
| 51 | 49 |
this->enabled = false; |
| 52 | 50 |
} |
| 53 | 51 |
} |
| 54 | 52 |
|
| 55 |
-inline int Gb_Env::reload_env_timer() |
|
| 53 |
+int Gb_Env::reload_env_timer() |
|
| 56 | 54 |
{
|
| 57 | 55 |
int raw = this->regs[2] & 7; |
| 58 | 56 |
this->env_delay = raw ? raw : 8; |
| ... | ... |
@@ -154,7 +152,7 @@ int Gb_Osc::write_trig(int frame_phase, int max_len, int old_data) |
| 154 | 152 |
return data & trigger_mask; |
| 155 | 153 |
} |
| 156 | 154 |
|
| 157 |
-inline void Gb_Env::zombie_volume(int old, int data) |
|
| 155 |
+void Gb_Env::zombie_volume(int old, int data) |
|
| 158 | 156 |
{
|
| 159 | 157 |
int v = this->volume; |
| 160 | 158 |
if (this->mode == Gb_Apu::mode_agb || cgb_05) |
| ... | ... |
@@ -188,7 +186,7 @@ inline void Gb_Env::zombie_volume(int old, int data) |
| 188 | 186 |
this->volume = v & 0x0F; |
| 189 | 187 |
} |
| 190 | 188 |
|
| 191 |
-bool Gb_Env::write_register( int frame_phase, int reg, int old, int data ) |
|
| 189 |
+bool Gb_Env::write_register(int frame_phase, int reg, int old, int data) |
|
| 192 | 190 |
{
|
| 193 | 191 |
static const int max_len = 64; |
| 194 | 192 |
|
| ... | ... |
@@ -235,7 +233,7 @@ bool Gb_Square::write_register(int frame_phase, int reg, int old_data, int data) |
| 235 | 233 |
return result; |
| 236 | 234 |
} |
| 237 | 235 |
|
| 238 |
-inline void Gb_Noise::write_register( int frame_phase, int reg, int old_data, int data ) |
|
| 236 |
+void Gb_Noise::write_register(int frame_phase, int reg, int old_data, int data) |
|
| 239 | 237 |
{
|
| 240 | 238 |
if (Gb_Env::write_register(frame_phase, reg, old_data, data)) |
| 241 | 239 |
{
|
| ... | ... |
@@ -244,7 +242,7 @@ inline void Gb_Noise::write_register( int frame_phase, int reg, int old_data, in |
| 244 | 242 |
} |
| 245 | 243 |
} |
| 246 | 244 |
|
| 247 |
-inline void Gb_Sweep_Square::write_register(int frame_phase, int reg, int old_data, int data) |
|
| 245 |
+void Gb_Sweep_Square::write_register(int frame_phase, int reg, int old_data, int data) |
|
| 248 | 246 |
{
|
| 249 | 247 |
if (!reg && this->sweep_enabled && this->sweep_neg && !(data & 0x08)) |
| 250 | 248 |
this->enabled = false; // sweep negate disabled after used |
| ... | ... |
@@ -270,7 +268,7 @@ void Gb_Wave::corrupt_wave() |
| 270 | 268 |
this->wave_ram[i] = this->wave_ram[(pos & ~3) + i]; |
| 271 | 269 |
} |
| 272 | 270 |
|
| 273 |
-inline void Gb_Wave::write_register(int frame_phase, int reg, int old_data, int data) |
|
| 271 |
+void Gb_Wave::write_register(int frame_phase, int reg, int old_data, int data) |
|
| 274 | 272 |
{
|
| 275 | 273 |
static const int max_len = 256; |
| 276 | 274 |
|
| ... | ... |
@@ -455,7 +453,7 @@ static unsigned run_lfsr(unsigned s, unsigned mask, int count) |
| 455 | 453 |
} |
| 456 | 454 |
|
| 457 | 455 |
// Need to keep one extra bit of history |
| 458 |
- s = s << 1 & 0xFF; |
|
| 456 |
+ s = (s << 1) & 0xFF; |
|
| 459 | 457 |
|
| 460 | 458 |
// Convert from Fibonacci to Galois configuration, |
| 461 | 459 |
// shifted left 2 bits |
| ... | ... |
@@ -521,7 +519,7 @@ void Gb_Noise::run(blip_time_t time, blip_time_t end_time) |
| 521 | 519 |
int per2 = this->period2(); |
| 522 | 520 |
time += this->delay + ((this->divider ^ (per2 >> 1)) & (per2 - 1)) * period1; |
| 523 | 521 |
|
| 524 |
- int count = (extra < 0 ? 0 : (extra + period1 - 1) / period1); |
|
| 522 |
+ int count = extra < 0 ? 0 : (extra + period1 - 1) / period1; |
|
| 525 | 523 |
this->divider = (this->divider - count) & period2_mask; |
| 526 | 524 |
this->delay = count * period1 - extra; |
| 527 | 525 |
} |
| ... | ... |
@@ -579,7 +577,7 @@ void Gb_Wave::run(blip_time_t time, blip_time_t end_time) |
| 579 | 577 |
auto out = this->output; |
| 580 | 578 |
if (out) |
| 581 | 579 |
{
|
| 582 |
- int amp = dac_off_amp; |
|
| 580 |
+ int amp = this->dac_off_amp; |
|
| 583 | 581 |
if (this->dac_enabled()) |
| 584 | 582 |
{
|
| 585 | 583 |
// Play inaudible frequencies as constant amplitude |
| ... | ... |
@@ -589,7 +587,7 @@ void Gb_Wave::run(blip_time_t time, blip_time_t end_time) |
| 589 | 587 |
if (this->frequency() <= 0x7FB || this->delay > 15 * clk_mul) |
| 590 | 588 |
{
|
| 591 | 589 |
if (volume_mul) |
| 592 |
- playing = enabled; |
|
| 590 |
+ playing = this->enabled; |
|
| 593 | 591 |
|
| 594 | 592 |
amp = (this->sample_buf << ((this->phase << 2) & 4) & 0xF0) * playing; |
| 595 | 593 |
} |
| ... | ... |
@@ -634,7 +632,7 @@ void Gb_Wave::run(blip_time_t time, blip_time_t end_time) |
| 634 | 632 |
do |
| 635 | 633 |
{
|
| 636 | 634 |
// Extract nybble |
| 637 |
- int nybble = wave[ph >> 1] << ((ph << 2) & 4) & 0xF0; |
|
| 635 |
+ int nybble = (wave[ph >> 1] << ((ph << 2) & 4)) & 0xF0; |
|
| 638 | 636 |
ph = (ph + 1) & wave_mask; |
| 639 | 637 |
|
| 640 | 638 |
// Scale by volume |
| ... | ... |
@@ -14,8 +14,6 @@ details. You should have received a copy of the GNU Lesser General Public |
| 14 | 14 |
License along with this module; if not, write to the Free Software Foundation, |
| 15 | 15 |
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ |
| 16 | 16 |
|
| 17 |
-#include "blargg_source.h" |
|
| 18 |
- |
|
| 19 | 17 |
#ifdef BLARGG_ENABLE_OPTIMIZER |
| 20 | 18 |
# include BLARGG_ENABLE_OPTIMIZER |
| 21 | 19 |
#endif |
| ... | ... |
@@ -36,31 +34,6 @@ Multi_Buffer::channel_t Multi_Buffer::channel(int /*index*/) |
| 36 | 34 |
return ch; |
| 37 | 35 |
} |
| 38 | 36 |
|
| 39 |
-// Silent_Buffer |
|
| 40 |
- |
|
| 41 |
-Silent_Buffer::Silent_Buffer() : Multi_Buffer(1) // 0 channels would probably confuse |
|
| 42 |
-{
|
|
| 43 |
- // TODO: better to use empty Blip_Buffer so caller never has to check for NULL? |
|
| 44 |
- this->chan.left = this->chan.center = this->chan.right = nullptr; |
|
| 45 |
-} |
|
| 46 |
- |
|
| 47 |
-// Mono_Buffer |
|
| 48 |
- |
|
| 49 |
-Mono_Buffer::Mono_Buffer() : Multi_Buffer(1) |
|
| 50 |
-{
|
|
| 51 |
- this->chan.center = &this->buf; |
|
| 52 |
- this->chan.left = &this->buf; |
|
| 53 |
- this->chan.right = &this->buf; |
|
| 54 |
-} |
|
| 55 |
- |
|
| 56 |
-Mono_Buffer::~Mono_Buffer() { }
|
|
| 57 |
- |
|
| 58 |
-blargg_err_t Mono_Buffer::set_sample_rate(long rate, int msec) |
|
| 59 |
-{
|
|
| 60 |
- RETURN_ERR(this->buf.set_sample_rate(rate, msec)); |
|
| 61 |
- return Multi_Buffer::set_sample_rate(this->buf.sample_rate(), this->buf.length()); |
|
| 62 |
-} |
|
| 63 |
- |
|
| 64 | 37 |
// Tracked_Blip_Buffer |
| 65 | 38 |
|
| 66 | 39 |
Tracked_Blip_Buffer::Tracked_Blip_Buffer() |
| ... | ... |
@@ -86,7 +59,7 @@ uint32_t Tracked_Blip_Buffer::non_silent() const |
| 86 | 59 |
return this->last_non_silence | this->unsettled(); |
| 87 | 60 |
} |
| 88 | 61 |
|
| 89 |
-inline void Tracked_Blip_Buffer::remove_(long n) |
|
| 62 |
+void Tracked_Blip_Buffer::remove_(long n) |
|
| 90 | 63 |
{
|
| 91 | 64 |
if ((this->last_non_silence -= n) < 0) |
| 92 | 65 |
this->last_non_silence = 0; |
| ... | ... |
@@ -125,12 +98,12 @@ Stereo_Buffer::Stereo_Buffer() : Multi_Buffer(2) |
| 125 | 98 |
|
| 126 | 99 |
Stereo_Buffer::~Stereo_Buffer() { }
|
| 127 | 100 |
|
| 128 |
-blargg_err_t Stereo_Buffer::set_sample_rate(long rate, int msec) |
|
| 101 |
+void Stereo_Buffer::set_sample_rate(long rate, int msec) |
|
| 129 | 102 |
{
|
| 130 | 103 |
this->mixer.samples_read = 0; |
| 131 | 104 |
for (int i = bufs_size; --i >= 0; ) |
| 132 |
- RETURN_ERR(this->bufs[i].set_sample_rate(rate, msec)); |
|
| 133 |
- return Multi_Buffer::set_sample_rate(this->bufs[0].sample_rate(), this->bufs[0].length()); |
|
| 105 |
+ this->bufs[i].set_sample_rate(rate, msec); |
|
| 106 |
+ Multi_Buffer::set_sample_rate(this->bufs[0].sample_rate(), this->bufs[0].length()); |
|
| 134 | 107 |
} |
| 135 | 108 |
|
| 136 | 109 |
void Stereo_Buffer::clock_rate(long rate) |
| ... | ... |
@@ -196,7 +169,7 @@ void Stereo_Mixer::read_pairs(blip_sample_t *out, int count) |
| 196 | 169 |
// except that buffer isn't cleared, so caller can encounter |
| 197 | 170 |
// subtle problems and not realize the cause. |
| 198 | 171 |
this->samples_read += count; |
| 199 |
- if (this->bufs[0]->non_silent() || this->bufs[1]->non_silent()) |
|
| 172 |
+ if (this->bufs[0]->non_silent() | this->bufs[1]->non_silent()) |
|
| 200 | 173 |
this->mix_stereo(out, count); |
| 201 | 174 |
else |
| 202 | 175 |
this->mix_mono(out, count); |
| ... | ... |
@@ -238,8 +211,8 @@ void Stereo_Mixer::mix_stereo(blip_sample_t *out_, int count) |
| 238 | 211 |
BLIP_READER_BEGIN(side, **buf); |
| 239 | 212 |
BLIP_READER_BEGIN(center, *this->bufs[2]); |
| 240 | 213 |
|
| 241 |
- BLIP_READER_ADJ_(side, samples_read); |
|
| 242 |
- BLIP_READER_ADJ_(center, samples_read); |
|
| 214 |
+ BLIP_READER_ADJ_(side, this->samples_read); |
|
| 215 |
+ BLIP_READER_ADJ_(center, this->samples_read); |
|
| 243 | 216 |
|
| 244 | 217 |
int offset = -count; |
| 245 | 218 |
do |
| ... | ... |
@@ -256,7 +229,7 @@ void Stereo_Mixer::mix_stereo(blip_sample_t *out_, int count) |
| 256 | 229 |
|
| 257 | 230 |
BLIP_READER_END(side, **buf); |
| 258 | 231 |
|
| 259 |
- if (buf != bufs) |
|
| 232 |
+ if (buf != this->bufs) |
|
| 260 | 233 |
continue; |
| 261 | 234 |
|
| 262 | 235 |
// only end center once |
| ... | ... |
@@ -19,7 +19,7 @@ public: |
| 19 | 19 |
// (type information used by Effects_Buffer) |
| 20 | 20 |
enum { type_index_mask = 0xFF };
|
| 21 | 21 |
enum { wave_type = 0x100, noise_type = 0x200, mixed_type = wave_type | noise_type };
|
| 22 |
- virtual blargg_err_t set_channel_count(int, const int* types = nullptr); |
|
| 22 |
+ virtual void set_channel_count(int, const int* types = nullptr); |
|
| 23 | 23 |
int channel_count() const { return this->channel_count_; }
|
| 24 | 24 |
|
| 25 | 25 |
// Gets indexed channel, from 0 to channel count - 1 |
| ... | ... |
@@ -32,7 +32,7 @@ public: |
| 32 | 32 |
virtual channel_t channel(int index); |
| 33 | 33 |
|
| 34 | 34 |
// See Blip_Buffer.h |
| 35 |
- virtual blargg_err_t set_sample_rate(long rate, int msec = blip_default_length); |
|
| 35 |
+ virtual void set_sample_rate(long rate, int msec = blip_default_length); |
|
| 36 | 36 |
virtual void clock_rate(long) { }
|
| 37 | 37 |
virtual void bass_freq(int) { }
|
| 38 | 38 |
virtual void clear() { }
|
| ... | ... |
@@ -74,27 +74,6 @@ private: |
| 74 | 74 |
bool immediate_removal_; |
| 75 | 75 |
}; |
| 76 | 76 |
|
| 77 |
-// Uses a single buffer and outputs mono samples. |
|
| 78 |
-class Mono_Buffer : public Multi_Buffer |
|
| 79 |
-{
|
|
| 80 |
- Blip_Buffer buf; |
|
| 81 |
- channel_t chan; |
|
| 82 |
-public: |
|
| 83 |
- // Buffer used for all channels |
|
| 84 |
- Blip_Buffer *center() { return &this->buf; }
|
|
| 85 |
- |
|
| 86 |
- Mono_Buffer(); |
|
| 87 |
- ~Mono_Buffer(); |
|
| 88 |
- blargg_err_t set_sample_rate(long rate, int msec = blip_default_length); |
|
| 89 |
- void clock_rate(long rate) { this->buf.clock_rate(rate); }
|
|
| 90 |
- void bass_freq(int freq) { this->buf.bass_freq(freq); }
|
|
| 91 |
- void clear() { this->buf.clear(); }
|
|
| 92 |
- long samples_avail() const { return this->buf.samples_avail(); }
|
|
| 93 |
- long read_samples(blip_sample_t *p, long s) { return this->buf.read_samples(p, s); }
|
|
| 94 |
- channel_t channel(int) { return this->chan; }
|
|
| 95 |
- void end_frame(blip_time_t t) { this->buf.end_frame(t); }
|
|
| 96 |
-}; |
|
| 97 |
- |
|
| 98 | 77 |
class Tracked_Blip_Buffer : public Blip_Buffer |
| 99 | 78 |
{
|
| 100 | 79 |
public: |
| ... | ... |
@@ -137,7 +116,7 @@ public: |
| 137 | 116 |
|
| 138 | 117 |
Stereo_Buffer(); |
| 139 | 118 |
~Stereo_Buffer(); |
| 140 |
- blargg_err_t set_sample_rate(long, int msec = blip_default_length); |
|
| 119 |
+ void set_sample_rate(long, int msec = blip_default_length); |
|
| 141 | 120 |
void clock_rate(long); |
| 142 | 121 |
void bass_freq(int); |
| 143 | 122 |
void clear(); |
| ... | ... |
@@ -156,32 +135,10 @@ private: |
| 156 | 135 |
long samples_avail_; |
| 157 | 136 |
}; |
| 158 | 137 |
|
| 159 |
-// Silent_Buffer generates no samples, useful where no sound is wanted |
|
| 160 |
-class Silent_Buffer : public Multi_Buffer |
|
| 161 |
-{
|
|
| 162 |
- channel_t chan; |
|
| 163 |
-public: |
|
| 164 |
- Silent_Buffer(); |
|
| 165 |
- blargg_err_t set_sample_rate(long rate, int msec = blip_default_length); |
|
| 166 |
- void clock_rate(long) { }
|
|
| 167 |
- void bass_freq(int) { }
|
|
| 168 |
- void clear() { }
|
|
| 169 |
- channel_t channel(int) { return this->chan; }
|
|
| 170 |
- void end_frame(blip_time_t) { }
|
|
| 171 |
- long samples_avail() const { return 0; }
|
|
| 172 |
- long read_samples(blip_sample_t *, long) { return 0; }
|
|
| 173 |
-}; |
|
| 174 |
- |
|
| 175 |
-inline blargg_err_t Multi_Buffer::set_sample_rate(long rate, int msec) |
|
| 138 |
+inline void Multi_Buffer::set_sample_rate(long rate, int msec) |
|
| 176 | 139 |
{
|
| 177 | 140 |
this->sample_rate_ = rate; |
| 178 | 141 |
this->length_ = msec; |
| 179 |
- return 0; |
|
| 180 |
-} |
|
| 181 |
- |
|
| 182 |
-inline blargg_err_t Silent_Buffer::set_sample_rate(long rate, int msec) |
|
| 183 |
-{
|
|
| 184 |
- return Multi_Buffer::set_sample_rate(rate, msec); |
|
| 185 | 142 |
} |
| 186 | 143 |
|
| 187 | 144 |
inline int Multi_Buffer::samples_per_frame() const { return this->samples_per_frame_; }
|
| ... | ... |
@@ -190,11 +147,10 @@ inline long Multi_Buffer::sample_rate() const { return this->sample_rate_; }
|
| 190 | 147 |
|
| 191 | 148 |
inline int Multi_Buffer::length() const { return this->length_; }
|
| 192 | 149 |
|
| 193 |
-inline blargg_err_t Multi_Buffer::set_channel_count(int n, const int *types) |
|
| 150 |
+inline void Multi_Buffer::set_channel_count(int n, const int *types) |
|
| 194 | 151 |
{
|
| 195 | 152 |
this->channel_count_ = n; |
| 196 | 153 |
this->channel_types_ = types; |
| 197 |
- return 0; |
|
| 198 | 154 |
} |
| 199 | 155 |
|
| 200 | 156 |
#endif |
| ... | ... |
@@ -15,11 +15,6 @@ |
| 15 | 15 |
#ifndef BLARGG_COMMON_H |
| 16 | 16 |
#define BLARGG_COMMON_H |
| 17 | 17 |
|
| 18 |
-// blargg_err_t (0 on success, otherwise error string) |
|
| 19 |
-#ifndef blargg_err_t |
|
| 20 |
-typedef const char *blargg_err_t; |
|
| 21 |
-#endif |
|
| 22 |
- |
|
| 23 | 18 |
// BLARGG_COMPILER_HAS_BOOL: If 0, provides bool support for old compiler. If 1, |
| 24 | 19 |
// compiler is assumed to support bool. If undefined, availability is determined. |
| 25 | 20 |
#ifndef BLARGG_COMPILER_HAS_BOOL |
| 26 | 21 |
deleted file mode 100644 |
| ... | ... |
@@ -1,33 +0,0 @@ |
| 1 |
-/* Included at the beginning of library source files, AFTER all other #include lines. |
|
| 2 |
-Sets up helpful macros and services used in my source code. Since this is only "active" |
|
| 3 |
-in my source code, I don't have to worry about polluting the global namespace with |
|
| 4 |
-unprefixed names. */ |
|
| 5 |
- |
|
| 6 |
-// Gb_Snd_Emu 0.2.0 |
|
| 7 |
-#ifndef BLARGG_SOURCE_H |
|
| 8 |
-#define BLARGG_SOURCE_H |
|
| 9 |
- |
|
| 10 |
-// The following four macros are for debugging only. Some or all might be defined |
|
| 11 |
-// to do nothing, depending on the circumstances. Described is what happens when |
|
| 12 |
-// a particular macro is defined to do something. When defined to do nothing, the |
|
| 13 |
-// macros do NOT evaluate their argument(s). |
|
| 14 |
- |
|
| 15 |
-// If expr is false, prints file and line number, then aborts program. Meant for |
|
| 16 |
-// checking internal state and consistency. A failed assertion indicates a bug |
|
| 17 |
-// in MY code. |
|
| 18 |
-// |
|
| 19 |
-// void assert( bool expr ); |
|
| 20 |
-#include <cassert> |
|
| 21 |
- |
|
| 22 |
-// If expr yields non-NULL error string, returns it from current function, |
|
| 23 |
-// otherwise continues normally. |
|
| 24 |
-#undef RETURN_ERR |
|
| 25 |
-#define RETURN_ERR(expr) \ |
|
| 26 |
-do \ |
|
| 27 |
-{ \
|
|
| 28 |
- blargg_err_t blargg_return_err_ = (expr); \ |
|
| 29 |
- if (blargg_return_err_) \ |
|
| 30 |
- return blargg_return_err_; \ |
|
| 31 |
-} while (0) |
|
| 32 |
- |
|
| 33 |
-#endif |
| ... | ... |
@@ -24,8 +24,8 @@ static INSN_REGPARM void armUnknownInsn(uint32_t opcode) |
| 24 | 24 |
|
| 25 | 25 |
// Common macros ////////////////////////////////////////////////////////// |
| 26 | 26 |
|
| 27 |
-static inline uint32_t NEG(uint32_t i) { return i >> 31; }
|
|
| 28 |
-static inline uint32_t POS(uint32_t i) { return ~i >> 31; }
|
|
| 27 |
+template<typename T> static inline T NEG(const T &i) { return i >> 31; }
|
|
| 28 |
+template<typename T> static inline T POS(const T &i) { return ~i >> 31; }
|
|
| 29 | 29 |
|
| 30 | 30 |
// The following macros are used for optimization; any not defined for a |
| 31 | 31 |
// particular compiler/CPU combination default to the C core versions. |
| ... | ... |
@@ -240,11 +240,11 @@ static inline uint32_t POS(uint32_t i) { return ~i >> 31; }
|
| 240 | 240 |
# define esi "%%esi" |
| 241 | 241 |
# define edi "%%edi" |
| 242 | 242 |
# define movzx movzb |
| 243 |
-#else |
|
| 243 |
+# else |
|
| 244 | 244 |
# define ALU_HEADER __asm { __asm mov ecx, opcode
|
| 245 | 245 |
# define ALU_TRAILER } |
| 246 | 246 |
# define EMIT0(op) __asm op |
| 247 |
-# define EMIT1(op,arg) __asm op arg |
|
| 247 |
+# define EMIT1(op, arg) __asm op arg |
|
| 248 | 248 |
# define EMIT2(op, src, dest) __asm op dest, src |
| 249 | 249 |
# define KONST(val) val |
| 250 | 250 |
# define VAR(var) var |
| ... | ... |
@@ -310,7 +310,7 @@ static inline uint32_t POS(uint32_t i) { return ~i >> 31; }
|
| 310 | 310 |
EMIT2(and, KONST(0x3C), esi) |
| 311 | 311 |
|
| 312 | 312 |
# define LOAD_C_FLAG_YES EMIT2(mov, VAR(C_FLAG), bl) |
| 313 |
-# define LOAD_C_FLAG_NO /*nothing*/ |
|
| 313 |
+# define LOAD_C_FLAG_NO /*nothing*/ |
|
| 314 | 314 |
# define ALU_INIT_C ALU_INIT(LOAD_C_FLAG_YES) |
| 315 | 315 |
# define ALU_INIT_NC ALU_INIT(LOAD_C_FLAG_NO) |
| 316 | 316 |
|
| ... | ... |
@@ -579,7 +579,7 @@ static inline uint32_t POS(uint32_t i) { return ~i >> 31; }
|
| 579 | 579 |
# define OP_MVNS CHECK_PC(OP_MVN EMIT2(test, eax, eax), SETCOND_LOGICAL) |
| 580 | 580 |
|
| 581 | 581 |
// ALU cleanup macro |
| 582 |
-# define ALU_FINISH ALU_TRAILER |
|
| 582 |
+# define ALU_FINISH ALU_TRAILER |
|
| 583 | 583 |
|
| 584 | 584 |
// End of ALU macros |
| 585 | 585 |
//X//#endif //_MSC_VER |
| ... | ... |
@@ -599,7 +599,6 @@ static inline uint32_t POS(uint32_t i) { return ~i >> 31; }
|
| 599 | 599 |
"rcr $1, %0" \ |
| 600 | 600 |
: "=r" (offset) \ |
| 601 | 601 |
: "0" (offset)); |
| 602 |
- |
|
| 603 | 602 |
# else // !__GNUC__, i.e. Visual C++ |
| 604 | 603 |
# define ROR_IMM_MSR \ |
| 605 | 604 |
__asm \ |
| ... | ... |
@@ -621,7 +620,6 @@ static inline uint32_t POS(uint32_t i) { return ~i >> 31; }
|
| 621 | 620 |
__asm bt dword ptr C_FLAG, 0 \ |
| 622 | 621 |
__asm rcr offset, 1 \ |
| 623 | 622 |
} |
| 624 |
- |
|
| 625 | 623 |
# endif // !__GNUC__ |
| 626 | 624 |
# endif // !__POWERPC__ |
| 627 | 625 |
#endif // !C_CORE |
| ... | ... |
@@ -688,7 +686,7 @@ static inline uint32_t POS(uint32_t i) { return ~i >> 31; }
|
| 688 | 686 |
C_OUT = false; \ |
| 689 | 687 |
} \ |
| 690 | 688 |
} \ |
| 691 |
- else |
|
| 689 |
+ else \ |
|
| 692 | 690 |
value = rm; |
| 693 | 691 |
#endif |
| 694 | 692 |
// OP Rd,Rb,Rm LSR # |
| ... | ... |
@@ -733,7 +731,7 @@ static inline uint32_t POS(uint32_t i) { return ~i >> 31; }
|
| 733 | 731 |
C_OUT = false; \ |
| 734 | 732 |
} \ |
| 735 | 733 |
} \ |
| 736 |
- else |
|
| 734 |
+ else \ |
|
| 737 | 735 |
value = rm; |
| 738 | 736 |
#endif |
| 739 | 737 |
// OP Rd,Rb,Rm ASR # |
| ... | ... |
@@ -797,15 +795,14 @@ static inline uint32_t POS(uint32_t i) { return ~i >> 31; }
|
| 797 | 795 |
#ifndef VALUE_ROR_IMM_C |
| 798 | 796 |
# define VALUE_ROR_IMM_C \ |
| 799 | 797 |
unsigned shift = (opcode >> 7) & 0x1F; \ |
| 798 |
+ uint32_t v = reg[opcode & 0x0F].I; \ |
|
| 800 | 799 |
if (LIKELY(shift)) \ |
| 801 | 800 |
{ \
|
| 802 |
- uint32_t v = reg[opcode & 0x0F].I; \ |
|
| 803 | 801 |
C_OUT = !!((v >> (shift - 1)) & 1); \ |
| 804 | 802 |
value = (v << (32 - shift)) | (v >> shift); \ |
| 805 | 803 |
} \ |
| 806 | 804 |
else \ |
| 807 | 805 |
{ \
|
| 808 |
- uint32_t v = reg[opcode & 0x0F].I; \ |
|
| 809 | 806 |
C_OUT = !!(v & 1); \ |
| 810 | 807 |
value = (v >> 1) | (C_FLAG << 31); \ |
| 811 | 808 |
} |
| ... | ... |
@@ -815,12 +812,12 @@ static inline uint32_t POS(uint32_t i) { return ~i >> 31; }
|
| 815 | 812 |
# define VALUE_ROR_REG_C \ |
| 816 | 813 |
unsigned shift = reg[(opcode >> 8) & 15].B.B0; \ |
| 817 | 814 |
uint32_t rm = reg[opcode & 0x0F].I; \ |
| 818 |
- if ((opcode & 0x0F) == 15) |
|
| 815 |
+ if ((opcode & 0x0F) == 15) \ |
|
| 819 | 816 |
rm += 4; \ |
| 820 | 817 |
if (LIKELY(shift & 0x1F)) \ |
| 821 | 818 |
{ \
|
| 822 | 819 |
uint32_t v = rm; \ |
| 823 |
- C_OUT = !((v >> (shift - 1)) & 1); \ |
|
| 820 |
+ C_OUT = !!((v >> (shift - 1)) & 1); \ |
|
| 824 | 821 |
value = (v << (32 - shift)) | (v >> shift); \ |
| 825 | 822 |
} \ |
| 826 | 823 |
else \ |
| ... | ... |
@@ -912,7 +909,7 @@ static inline uint32_t POS(uint32_t i) { return ~i >> 31; }
|
| 912 | 909 |
reg[dest].I = res; |
| 913 | 910 |
#endif |
| 914 | 911 |
#ifndef OP_RSBS |
| 915 |
-# define OP_RSBS OP_RSB C_CHECK_PC(C_SETCOND_SUB) |
|
| 912 |
+# define OP_RSBS OP_RSB C_CHECK_PC(C_SETCOND_SUB) |
|
| 916 | 913 |
#endif |
| 917 | 914 |
#ifndef OP_ADD |
| 918 | 915 |
# define OP_ADD \ |
| ... | ... |
@@ -1075,7 +1072,7 @@ static inline uint32_t POS(uint32_t i) { return ~i >> 31; }
|
| 1075 | 1072 |
clockTicks = 3 + ISREGSHIFT + codeTicksAccess32(armNextPC) + codeTicksAccessSeq32(armNextPC) + codeTicksAccessSeq32(armNextPC); \ |
| 1076 | 1073 |
} |
| 1077 | 1074 |
|
| 1078 |
-#define MODECHANGE_NO /*nothing*/ |
|
| 1075 |
+#define MODECHANGE_NO /*nothing*/ |
|
| 1079 | 1076 |
#define MODECHANGE_YES CPUSwitchMode(reg[17].I & 0x1f, false); |
| 1080 | 1077 |
|
| 1081 | 1078 |
#define DEFINE_ALU_INSN_C(CODE1, CODE2, OP, MODECHANGE) \ |
| ... | ... |
@@ -1100,74 +1097,74 @@ static inline uint32_t POS(uint32_t i) { return ~i >> 31; }
|
| 1100 | 1097 |
static INSN_REGPARM void arm##CODE2##0(uint32_t opcode) { ALU_INSN(ALU_INIT_NC, VALUE_IMM_NC, OP_##OP, MODECHANGE_##MODECHANGE, 0); }
|
| 1101 | 1098 |
|
| 1102 | 1099 |
// AND |
| 1103 |
-DEFINE_ALU_INSN_NC(00, 20, AND, NO) |
|
| 1100 |
+DEFINE_ALU_INSN_NC(00, 20, AND, NO) |
|
| 1104 | 1101 |
// ANDS |
| 1105 | 1102 |
DEFINE_ALU_INSN_C(01, 21, ANDS, YES) |
| 1106 | 1103 |
|
| 1107 | 1104 |
// EOR |
| 1108 |
-DEFINE_ALU_INSN_NC(02, 22, EOR, NO) |
|
| 1105 |
+DEFINE_ALU_INSN_NC(02, 22, EOR, NO) |
|
| 1109 | 1106 |
// EORS |
| 1110 | 1107 |
DEFINE_ALU_INSN_C(03, 23, EORS, YES) |
| 1111 | 1108 |
|
| 1112 | 1109 |
// SUB |
| 1113 |
-DEFINE_ALU_INSN_NC(04, 24, SUB, NO) |
|
| 1110 |
+DEFINE_ALU_INSN_NC(04, 24, SUB, NO) |
|
| 1114 | 1111 |
// SUBS |
| 1115 | 1112 |
DEFINE_ALU_INSN_NC(05, 25, SUBS, YES) |
| 1116 | 1113 |
|
| 1117 | 1114 |
// RSB |
| 1118 |
-DEFINE_ALU_INSN_NC(06, 26, RSB, NO) |
|
| 1115 |
+DEFINE_ALU_INSN_NC(06, 26, RSB, NO) |
|
| 1119 | 1116 |
// RSBS |
| 1120 | 1117 |
DEFINE_ALU_INSN_NC(07, 27, RSBS, YES) |
| 1121 | 1118 |
|
| 1122 | 1119 |
// ADD |
| 1123 |
-DEFINE_ALU_INSN_NC(08, 28, ADD, NO) |
|
| 1120 |
+DEFINE_ALU_INSN_NC(08, 28, ADD, NO) |
|
| 1124 | 1121 |
// ADDS |
| 1125 | 1122 |
DEFINE_ALU_INSN_NC(09, 29, ADDS, YES) |
| 1126 | 1123 |
|
| 1127 | 1124 |
// ADC |
| 1128 |
-DEFINE_ALU_INSN_NC(0A, 2A, ADC, NO) |
|
| 1125 |
+DEFINE_ALU_INSN_NC(0A, 2A, ADC, NO) |
|
| 1129 | 1126 |
// ADCS |
| 1130 | 1127 |
DEFINE_ALU_INSN_NC(0B, 2B, ADCS, YES) |
| 1131 | 1128 |
|
| 1132 | 1129 |
// SBC |
| 1133 |
-DEFINE_ALU_INSN_NC(0C, 2C, SBC, NO) |
|
| 1130 |
+DEFINE_ALU_INSN_NC(0C, 2C, SBC, NO) |
|
| 1134 | 1131 |
// SBCS |
| 1135 | 1132 |
DEFINE_ALU_INSN_NC(0D, 2D, SBCS, YES) |
| 1136 | 1133 |
|
| 1137 | 1134 |
// RSC |
| 1138 |
-DEFINE_ALU_INSN_NC(0E, 2E, RSC, NO) |
|
| 1135 |
+DEFINE_ALU_INSN_NC(0E, 2E, RSC, NO) |
|
| 1139 | 1136 |
// RSCS |
| 1140 | 1137 |
DEFINE_ALU_INSN_NC(0F, 2F, RSCS, YES) |
| 1141 | 1138 |
|
| 1142 | 1139 |
// TST |
| 1143 |
-DEFINE_ALU_INSN_C(11, 31, TST, NO) |
|
| 1140 |
+DEFINE_ALU_INSN_C(11, 31, TST, NO) |
|
| 1144 | 1141 |
|
| 1145 | 1142 |
// TEQ |
| 1146 |
-DEFINE_ALU_INSN_C(13, 33, TEQ, NO) |
|
| 1143 |
+DEFINE_ALU_INSN_C(13, 33, TEQ, NO) |
|
| 1147 | 1144 |
|
| 1148 | 1145 |
// CMP |
| 1149 |
-DEFINE_ALU_INSN_NC(15, 35, CMP, NO) |
|
| 1146 |
+DEFINE_ALU_INSN_NC(15, 35, CMP, NO) |
|
| 1150 | 1147 |
|
| 1151 | 1148 |
// CMN |
| 1152 |
-DEFINE_ALU_INSN_NC(17, 37, CMN, NO) |
|
| 1149 |
+DEFINE_ALU_INSN_NC(17, 37, CMN, NO) |
|
| 1153 | 1150 |
|
| 1154 | 1151 |
// ORR |
| 1155 |
-DEFINE_ALU_INSN_NC(18, 38, ORR, NO) |
|
| 1152 |
+DEFINE_ALU_INSN_NC(18, 38, ORR, NO) |
|
| 1156 | 1153 |
// ORRS |
| 1157 | 1154 |
DEFINE_ALU_INSN_C(19, 39, ORRS, YES) |
| 1158 | 1155 |
|
| 1159 | 1156 |
// MOV |
| 1160 |
-DEFINE_ALU_INSN_NC(1A, 3A, MOV, NO) |
|
| 1157 |
+DEFINE_ALU_INSN_NC(1A, 3A, MOV, NO) |
|
| 1161 | 1158 |
// MOVS |
| 1162 | 1159 |
DEFINE_ALU_INSN_C(1B, 3B, MOVS, YES) |
| 1163 | 1160 |
|
| 1164 | 1161 |
// BIC |
| 1165 |
-DEFINE_ALU_INSN_NC(1C, 3C, BIC, NO) |
|
| 1162 |
+DEFINE_ALU_INSN_NC(1C, 3C, BIC, NO) |
|
| 1166 | 1163 |
// BICS |
| 1167 | 1164 |
DEFINE_ALU_INSN_C(1D, 3D, BICS, YES) |
| 1168 | 1165 |
|
| 1169 | 1166 |
// MVN |
| 1170 |
-DEFINE_ALU_INSN_NC(1E, 3E, MVN, NO) |
|
| 1167 |
+DEFINE_ALU_INSN_NC(1E, 3E, MVN, NO) |
|
| 1171 | 1168 |
// MVNS |
| 1172 | 1169 |
DEFINE_ALU_INSN_C(1F, 3F, MVNS, YES) |
| 1173 | 1170 |
|
| ... | ... |
@@ -1188,7 +1185,7 @@ DEFINE_ALU_INSN_C(1F, 3F, MVNS, YES) |
| 1188 | 1185 |
if (!(rs & 0xFFFFFF00)) \ |
| 1189 | 1186 |
; /* No-op */ \ |
| 1190 | 1187 |
else if (!(rs & 0xFFFF0000)) \ |
| 1191 |
- clockTicks += 1; \ |
|
| 1188 |
+ ++clockTicks; \ |
|
| 1192 | 1189 |
else if (!(rs & 0xFF000000)) \ |
| 1193 | 1190 |
clockTicks += 2; \ |
| 1194 | 1191 |
else \ |
| ... | ... |
@@ -1261,7 +1258,7 @@ static INSN_REGPARM void arm149(uint32_t opcode) |
| 1261 | 1258 |
{
|
| 1262 | 1259 |
uint32_t address = reg[(opcode >> 16) & 15].I; |
| 1263 | 1260 |
uint32_t temp = CPUReadByte(address); |
| 1264 |
- CPUWriteByte(address, reg[opcode&15].B.B0); |
|
| 1261 |
+ CPUWriteByte(address, reg[opcode & 15].B.B0); |
|
| 1265 | 1262 |
reg[(opcode >> 12) & 15].I = temp; |
| 1266 | 1263 |
clockTicks = 4 + dataTicksAccess32(address) + dataTicksAccess32(address) + codeTicksAccess32(armNextPC); |
| 1267 | 1264 |
} |
| ... | ... |
@@ -2043,7 +2040,7 @@ static INSN_REGPARM void arm7F6(uint32_t opcode) { LDR_PREINC_WB(OFFSET_ROR, OP_
|
| 2043 | 2040 |
STM_HIGH(STMW_REG); \ |
| 2044 | 2041 |
STMW_PC; |
| 2045 | 2042 |
#define LDM_ALL \ |
| 2046 |
- LDM_LOW \ |
|
| 2043 |
+ LDM_LOW; \ |
|
| 2047 | 2044 |
LDM_HIGH; \ |
| 2048 | 2045 |
if (opcode & (1U << 15)) \ |
| 2049 | 2046 |
{ \
|
| ... | ... |
@@ -2062,7 +2059,7 @@ static INSN_REGPARM void arm7F6(uint32_t opcode) { LDR_PREINC_WB(OFFSET_ROR, OP_
|
| 2062 | 2059 |
clockTicks += 1 + codeTicksAccessSeq32(armNextPC); \ |
| 2063 | 2060 |
} |
| 2064 | 2061 |
#define STM_ALL_2 \ |
| 2065 |
- STM_LOW(STM_REG) \ |
|
| 2062 |
+ STM_LOW(STM_REG); \ |
|
| 2066 | 2063 |
STM_HIGH_2(STM_REG); \ |
| 2067 | 2064 |
STM_PC; |
| 2068 | 2065 |
#define STMW_ALL_2 \ |
| ... | ... |
@@ -2244,9 +2241,9 @@ static INSN_REGPARM void arm8A0(uint32_t opcode) |
| 2244 | 2241 |
if (!busPrefetchCount) |
| 2245 | 2242 |
busPrefetch = busPrefetchEnable; |
| 2246 | 2243 |
int base = (opcode & 0x000F0000) >> 16; |
| 2244 |
+ uint32_t temp = reg[base].I + 4 * (cpuBitsSet[opcode & 0xFF] + cpuBitsSet[(opcode >> 8) & 255]); |
|
| 2247 | 2245 |
uint32_t address = reg[base].I & 0xFFFFFFFC; |
| 2248 | 2246 |
int count = 0; |
| 2249 |
- uint32_t temp = reg[base].I + 4 * (cpuBitsSet[opcode & 0xFF] + cpuBitsSet[(opcode >> 8) & 255]); |
|
| 2250 | 2247 |
STMW_ALL; |
| 2251 | 2248 |
clockTicks += 1 + codeTicksAccess32(armNextPC); |
| 2252 | 2249 |
} |
| ... | ... |
@@ -2297,9 +2294,9 @@ static INSN_REGPARM void arm8E0(uint32_t opcode) |
| 2297 | 2294 |
if (!busPrefetchCount) |
| 2298 | 2295 |
busPrefetch = busPrefetchEnable; |
| 2299 | 2296 |
int base = (opcode & 0x000F0000) >> 16; |
| 2297 |
+ uint32_t temp = reg[base].I + 4 * (cpuBitsSet[opcode & 0xFF] + cpuBitsSet[(opcode >> 8) & 255]); |
|
| 2300 | 2298 |
uint32_t address = reg[base].I & 0xFFFFFFFC; |
| 2301 | 2299 |
int count = 0; |
| 2302 |
- uint32_t temp = reg[base].I + 4 * (cpuBitsSet[opcode & 0xFF] + cpuBitsSet[(opcode >> 8) & 255]); |
|
| 2303 | 2300 |
STMW_ALL_2; |
| 2304 | 2301 |
clockTicks += 1 + codeTicksAccess32(armNextPC); |
| 2305 | 2302 |
} |
| ... | ... |
@@ -2460,9 +2457,9 @@ static INSN_REGPARM void arm9A0(uint32_t opcode) |
| 2460 | 2457 |
if (!busPrefetchCount) |
| 2461 | 2458 |
busPrefetch = busPrefetchEnable; |
| 2462 | 2459 |
int base = (opcode & 0x000F0000) >> 16; |
| 2460 |
+ uint32_t temp = reg[base].I + 4 * (cpuBitsSet[opcode & 0xFF] + cpuBitsSet[(opcode >> 8) & 255]); |
|
| 2463 | 2461 |
uint32_t address = (reg[base].I + 4) & 0xFFFFFFFC; |
| 2464 | 2462 |
int count = 0; |
| 2465 |
- uint32_t temp = reg[base].I + 4 * (cpuBitsSet[opcode & 0xFF] + cpuBitsSet[(opcode >> 8) & 255]); |
|
| 2466 | 2463 |
STMW_ALL; |
| 2467 | 2464 |
clockTicks += 1 + codeTicksAccess32(armNextPC); |
| 2468 | 2465 |
} |
| ... | ... |
@@ -2513,9 +2510,9 @@ static INSN_REGPARM void arm9E0(uint32_t opcode) |
| 2513 | 2510 |
if (!busPrefetchCount) |
| 2514 | 2511 |
busPrefetch = busPrefetchEnable; |
| 2515 | 2512 |
int base = (opcode & 0x000F0000) >> 16; |
| 2513 |
+ uint32_t temp = reg[base].I + 4 * (cpuBitsSet[opcode & 0xFF] + cpuBitsSet[(opcode >> 8) & 255]); |
|
| 2516 | 2514 |
uint32_t address = (reg[base].I + 4) & 0xFFFFFFFC; |
| 2517 | 2515 |
int count = 0; |
| 2518 |
- uint32_t temp = reg[base].I + 4 * (cpuBitsSet[opcode & 0xFF] + cpuBitsSet[(opcode >> 8) & 255]); |
|
| 2519 | 2516 |
STMW_ALL_2; |
| 2520 | 2517 |
clockTicks += 1 + codeTicksAccess32(armNextPC); |
| 2521 | 2518 |
} |
| ... | ... |
@@ -2565,7 +2562,7 @@ static INSN_REGPARM void armB00(uint32_t opcode) |
| 2565 | 2562 |
reg[15].I += 4; |
| 2566 | 2563 |
ARM_PREFETCH(); |
| 2567 | 2564 |
clockTicks = codeTicksAccessSeq32(armNextPC) + 1; |
| 2568 |
- clockTicks += 2 + codeTicksAccess32(armNextPC) + codeTicksAccessSeq32(armNextPC); |
|
| 2565 |
+ clockTicks = (clockTicks * 2) + codeTicksAccess32(armNextPC) + 1; |
|
| 2569 | 2566 |
busPrefetchCount = 0; |
| 2570 | 2567 |
} |
| 2571 | 2568 |
|
| ... | ... |
@@ -2846,7 +2843,6 @@ int armExecute() |
| 2846 | 2843 |
case 0x0E: // AL (impossible, checked above) |
| 2847 | 2844 |
cond_res = true; |
| 2848 | 2845 |
break; |
| 2849 |
- case 0x0F: |
|
| 2850 | 2846 |
default: |
| 2851 | 2847 |
// ??? |
| 2852 | 2848 |
cond_res = false; |
| ... | ... |
@@ -5,10 +5,6 @@ |
| 5 | 5 |
#include "Sound.h" |
| 6 | 6 |
#include "bios.h" |
| 7 | 7 |
|
| 8 |
-#ifdef _MSC_VER |
|
| 9 |
-# define snprintf _snprintf |
|
| 10 |
-#endif |
|
| 11 |
- |
|
| 12 | 8 |
/////////////////////////////////////////////////////////////////////////// |
| 13 | 9 |
|
| 14 | 10 |
static int clockTicks; |
| ... | ... |
@@ -20,8 +16,8 @@ static INSN_REGPARM void thumbUnknownInsn(uint32_t opcode) |
| 20 | 16 |
|
| 21 | 17 |
// Common macros ////////////////////////////////////////////////////////// |
| 22 | 18 |
|
| 23 |
-static inline uint32_t NEG(uint32_t i) { return i >> 31; }
|
|
| 24 |
-static inline uint32_t POS(uint32_t i) { return ~i >> 31; }
|
|
| 19 |
+template<typename T> static inline T NEG(const T &i) { return i >> 31; }
|
|
| 20 |
+template<typename T> static inline T POS(const T &i) { return ~i >> 31; }
|
|
| 25 | 21 |
|
| 26 | 22 |
#ifndef C_CORE |
| 27 | 23 |
# ifdef __GNUC__ |
| ... | ... |
@@ -82,7 +78,7 @@ static inline uint32_t POS(uint32_t i) { return ~i >> 31; }
|
| 82 | 78 |
V_FLAG = (Flags >> 26) & 1; \ |
| 83 | 79 |
} |
| 84 | 80 |
# define CMN_RD_RS \ |
| 85 |
-{\
|
|
| 81 |
+{ \
|
|
| 86 | 82 |
register int Flags; \ |
| 87 | 83 |
register int Result; \ |
| 88 | 84 |
asm volatile("addco. %0, %2, %3\n" \
|
| ... | ... |
@@ -105,7 +101,7 @@ static inline uint32_t POS(uint32_t i) { return ~i >> 31; }
|
| 105 | 101 |
asm volatile("mtspr 1, %4\n" \ /* reg 1 is xer */
|
| 106 | 102 |
"addeo. %0, %2, %3\n" \ |
| 107 | 103 |
"mcrxr cr1\n" \ |
| 108 |
- "mfcr %1\n" \ |
|
| 104 |
+ "mfcr %1\n" \ |
|
| 109 | 105 |
: "=r" (Result), \ |
| 110 | 106 |
"=r" (Flags) \ |
| 111 | 107 |
: "r" (reg[dest].I), \ |
| ... | ... |
@@ -221,7 +217,7 @@ static inline uint32_t POS(uint32_t i) { return ~i >> 31; }
|
| 221 | 217 |
"=r" (Flags) \ |
| 222 | 218 |
: "r" (reg[source].I), \ |
| 223 | 219 |
"r" (0) \ |
| 224 |
- ); \ |
|
| 220 |
+ ); \ |
|
| 225 | 221 |
reg[dest].I = Result; \ |
| 226 | 222 |
Z_FLAG = (Flags >> 29) & 1; \ |
| 227 | 223 |
N_FLAG = (Flags >> 31) & 1; \ |
| ... | ... |
@@ -259,7 +255,7 @@ static inline uint32_t POS(uint32_t i) { return ~i >> 31; }
|
| 259 | 255 |
# define ecx "%%ecx" |
| 260 | 256 |
# define edx "%%edx" |
| 261 | 257 |
# define ADD_RN_O8(d) \ |
| 262 |
- asm("andl $0xFF, %%eax;"\
|
|
| 258 |
+ asm("andl $0xFF, %%eax;" \
|
|
| 263 | 259 |
"addl %%eax, %0;" \ |
| 264 | 260 |
EMIT1(setsb, VAR(N_FLAG)) \ |
| 265 | 261 |
EMIT1(setzb, VAR(Z_FLAG)) \ |
| ... | ... |
@@ -352,7 +348,7 @@ static inline uint32_t POS(uint32_t i) { return ~i >> 31; }
|
| 352 | 348 |
EMIT1(setob, VAR(V_FLAG)) \ |
| 353 | 349 |
: \ |
| 354 | 350 |
: "r" (value), "r" (reg[dest].I) : "1"); |
| 355 |
-# define IMM5_INSN(OP,N) \ |
|
| 351 |
+# define IMM5_INSN(OP, N) \ |
|
| 356 | 352 |
asm("movl %%eax,%%ecx;" \
|
| 357 | 353 |
"shrl $1,%%eax;" \ |
| 358 | 354 |
"andl $7,%%ecx;" \ |
| ... | ... |
@@ -361,7 +357,7 @@ static inline uint32_t POS(uint32_t i) { return ~i >> 31; }
|
| 361 | 357 |
OP \ |
| 362 | 358 |
EMIT1(setsb, VAR(N_FLAG)) \ |
| 363 | 359 |
EMIT1(setzb, VAR(Z_FLAG)) \ |
| 364 |
- EMIT2(movl, edx, REGREF2(ecx,4)) \ |
|
| 360 |
+ EMIT2(movl, edx, REGREF2(ecx, 4)) \ |
|
| 365 | 361 |
: : "i" (N)) |
| 366 | 362 |
# define IMM5_INSN_0(OP) \ |
| 367 | 363 |
asm("movl %%eax,%%ecx;" \
|
| ... | ... |
@@ -372,25 +368,25 @@ static inline uint32_t POS(uint32_t i) { return ~i >> 31; }
|
| 372 | 368 |
OP \ |
| 373 | 369 |
EMIT1(setsb, VAR(N_FLAG)) \ |
| 374 | 370 |
EMIT1(setzb, VAR(Z_FLAG)) \ |
| 375 |
- EMIT2(movl, edx, REGREF2(ecx,4)) \ |
|
| 371 |
+ EMIT2(movl, edx, REGREF2(ecx, 4)) \ |
|
| 376 | 372 |
: : ) |
| 377 | 373 |
# define IMM5_LSL \ |
| 378 |
- "shll %0,%%edx;"\ |
|
| 374 |
+ "shll %0,%%edx;" \ |
|
| 379 | 375 |
EMIT1(setcb, VAR(C_FLAG)) |
| 380 | 376 |
# define IMM5_LSL_0 \ |
| 381 | 377 |
"testl %%edx,%%edx;" |
| 382 | 378 |
# define IMM5_LSR \ |
| 383 |
- "shrl %0,%%edx;"\ |
|
| 379 |
+ "shrl %0,%%edx;" \ |
|
| 384 | 380 |
EMIT1(setcb, VAR(C_FLAG)) |
| 385 | 381 |
# define IMM5_LSR_0 \ |
| 386 |
- "testl %%edx,%%edx;"\ |
|
| 382 |
+ "testl %%edx,%%edx;" \ |
|
| 387 | 383 |
EMIT1(setsb, VAR(C_FLAG)) \ |
| 388 | 384 |
"xorl %%edx,%%edx;" |
| 389 | 385 |
# define IMM5_ASR \ |
| 390 |
- "sarl %0,%%edx;"\ |
|
| 386 |
+ "sarl %0,%%edx;" \ |
|
| 391 | 387 |
EMIT1(setcb, VAR(C_FLAG)) |
| 392 |
-# define IMM5_ASR_0 \ |
|
| 393 |
- "sarl $31,%%edx;"\ |
|
| 388 |
+# define IMM5_ASR_0 \ |
|
| 389 |
+ "sarl $31,%%edx;" \ |
|
| 394 | 390 |
EMIT1(setsb, VAR(C_FLAG)) |
| 395 | 391 |
# define THREEARG_INSN(OP, N) \ |
| 396 | 392 |
asm("movl %%eax,%%edx;" \
|
| ... | ... |
@@ -401,7 +397,7 @@ static inline uint32_t POS(uint32_t i) { return ~i >> 31; }
|
| 401 | 397 |
OP(N) \ |
| 402 | 398 |
EMIT1(setsb, VAR(N_FLAG)) \ |
| 403 | 399 |
EMIT1(setzb, VAR(Z_FLAG)) \ |
| 404 |
- EMIT2(movl, ecx, REGREF2(eax,4)) \ |
|
| 400 |
+ EMIT2(movl, ecx, REGREF2(eax, 4)) \ |
|
| 405 | 401 |
: : ) |
| 406 | 402 |
# define ADD_RD_RS_RN(N) \ |
| 407 | 403 |
EMIT2(add, VAR(reg) "+" #N "*4", ecx) \ |
| ... | ... |
@@ -420,7 +416,7 @@ static inline uint32_t POS(uint32_t i) { return ~i >> 31; }
|
| 420 | 416 |
EMIT1(setncb, VAR(C_FLAG)) \ |
| 421 | 417 |
EMIT1(setob, VAR(V_FLAG)) |
| 422 | 418 |
# define SUB_RD_RS_O3(N) \ |
| 423 |
- "sub $"#N",%%ecx;" \ |
|
| 419 |
+ "sub $" #N ",%%ecx;" \ |
|
| 424 | 420 |
EMIT1(setncb, VAR(C_FLAG)) \ |
| 425 | 421 |
EMIT1(setob, VAR(V_FLAG)) |
| 426 | 422 |
# define SUB_RD_RS_O3_0(N) \ |
| ... | ... |
@@ -718,7 +714,7 @@ static inline uint32_t POS(uint32_t i) { return ~i >> 31; }
|
| 718 | 714 |
uint32_t lhs = reg[(d)].I; \ |
| 719 | 715 |
uint32_t rhs = opcode & 255; \ |
| 720 | 716 |
uint32_t res = lhs + rhs; \ |
| 721 |
- reg[(d)].I = res;\ |
|
| 717 |
+ reg[(d)].I = res; \ |
|
| 722 | 718 |
Z_FLAG = !res; \ |
| 723 | 719 |
N_FLAG = !!NEG(res); \ |
| 724 | 720 |
ADDCARRY(lhs, rhs, res); \ |
| ... | ... |
@@ -863,7 +859,7 @@ static inline uint32_t POS(uint32_t i) { return ~i >> 31; }
|
| 863 | 859 |
#ifndef ASR_RD_RS |
| 864 | 860 |
# define ASR_RD_RS \ |
| 865 | 861 |
{ \
|
| 866 |
- C_FLAG = !!((static_cast<int32_t>(reg[dest].I >> static_cast<int>(value - 1)) & 1); \ |
|
| 862 |
+ C_FLAG = !!((static_cast<int32_t>(reg[dest].I) >> static_cast<int>(value - 1)) & 1); \ |
|
| 867 | 863 |
value = static_cast<int32_t>(reg[dest].I) >> static_cast<int>(value); \ |
| 868 | 864 |
} |
| 869 | 865 |
#endif |
| ... | ... |
@@ -1224,7 +1220,7 @@ static INSN_REGPARM void thumb41_3(uint32_t opcode) |
| 1224 | 1220 |
|
| 1225 | 1221 |
if (value) |
| 1226 | 1222 |
{
|
| 1227 |
- value &= 0x1f; |
|
| 1223 |
+ value = value & 0x1f; |
|
| 1228 | 1224 |
if (!value) |
| 1229 | 1225 |
C_FLAG = !!(reg[dest].I & 0x80000000); |
| 1230 | 1226 |
else |
| ... | ... |
@@ -1233,9 +1229,9 @@ static INSN_REGPARM void thumb41_3(uint32_t opcode) |
| 1233 | 1229 |
reg[dest].I = value; |
| 1234 | 1230 |
} |
| 1235 | 1231 |
} |
| 1236 |
- clockTicks = codeTicksAccess16(armNextPC) + 2; |
|
| 1237 | 1232 |
N_FLAG = !!(reg[dest].I & 0x80000000); |
| 1238 | 1233 |
Z_FLAG = !reg[dest].I; |
| 1234 |
+ clockTicks = codeTicksAccess16(armNextPC) + 2; |
|
| 1239 | 1235 |
} |
| 1240 | 1236 |
|
| 1241 | 1237 |
// TST Rd, Rs |
| ... | ... |
@@ -1275,8 +1271,8 @@ static INSN_REGPARM void thumb43_0(uint32_t opcode) |
| 1275 | 1271 |
{
|
| 1276 | 1272 |
int dest = opcode & 7; |
| 1277 | 1273 |
reg[dest].I |= reg[(opcode >> 3) & 7].I; |
| 1278 |
- Z_FLAG = !reg[dest].I; |
|
| 1279 | 1274 |
N_FLAG = !!(reg[dest].I & 0x80000000); |
| 1275 |
+ Z_FLAG = !reg[dest].I; |
|
| 1280 | 1276 |
} |
| 1281 | 1277 |
|
| 1282 | 1278 |
// MUL Rd, Rs |
| ... | ... |
@@ -1289,7 +1285,7 @@ static INSN_REGPARM void thumb43_1(uint32_t opcode) |
| 1289 | 1285 |
if (static_cast<int32_t>(rm) < 0) |
| 1290 | 1286 |
rm = ~rm; |
| 1291 | 1287 |
if (!(rm & 0xFFFFFF00)) |
| 1292 |
- ; // No-op |
|
| 1288 |
+ ; /* No-op */ |
|
| 1293 | 1289 |
else if (!(rm & 0xFFFF0000)) |
| 1294 | 1290 |
++clockTicks; |
| 1295 | 1291 |
else if (!(rm & 0xFF000000)) |
| ... | ... |
@@ -1297,9 +1293,9 @@ static INSN_REGPARM void thumb43_1(uint32_t opcode) |
| 1297 | 1293 |
else |
| 1298 | 1294 |
clockTicks += 3; |
| 1299 | 1295 |
busPrefetchCount = (busPrefetchCount << clockTicks) | (0xFF >> (8 - clockTicks)); |
| 1300 |
- clockTicks += codeTicksAccess16(armNextPC) + 1; |
|
| 1301 |
- Z_FLAG = !reg[dest].I; |
|
| 1302 | 1296 |
N_FLAG = !!(reg[dest].I & 0x80000000); |
| 1297 |
+ Z_FLAG = !reg[dest].I; |
|
| 1298 |
+ clockTicks += codeTicksAccess16(armNextPC) + 1; |
|
| 1303 | 1299 |
} |
| 1304 | 1300 |
|
| 1305 | 1301 |
// BIC Rd, Rs |
| ... | ... |
@@ -1307,8 +1303,8 @@ static INSN_REGPARM void thumb43_2(uint32_t opcode) |
| 1307 | 1303 |
{
|
| 1308 | 1304 |
int dest = opcode & 7; |
| 1309 | 1305 |
reg[dest].I &= ~reg[(opcode >> 3) & 7].I; |
| 1310 |
- Z_FLAG = !reg[dest].I; |
|
| 1311 | 1306 |
N_FLAG = !!(reg[dest].I & 0x80000000); |
| 1307 |
+ Z_FLAG = !reg[dest].I; |
|
| 1312 | 1308 |
} |
| 1313 | 1309 |
|
| 1314 | 1310 |
// MVN Rd, Rs |
| ... | ... |
@@ -1316,8 +1312,8 @@ static INSN_REGPARM void thumb43_3(uint32_t opcode) |
| 1316 | 1312 |
{
|
| 1317 | 1313 |
int dest = opcode & 7; |
| 1318 | 1314 |
reg[dest].I = ~reg[(opcode >> 3) & 7].I; |
| 1319 |
- Z_FLAG = !reg[dest].I; |
|
| 1320 | 1315 |
N_FLAG = !!(reg[dest].I & 0x80000000); |
| 1316 |
+ Z_FLAG = !reg[dest].I; |
|
| 1321 | 1317 |
} |
| 1322 | 1318 |
|
| 1323 | 1319 |
// High-register instructions and BX ////////////////////////////////////// |
| ... | ... |
@@ -1339,7 +1335,7 @@ static INSN_REGPARM void thumb44_2(uint32_t opcode) |
| 1339 | 1335 |
reg[15].I += 2; |
| 1340 | 1336 |
THUMB_PREFETCH(); |
| 1341 | 1337 |
clockTicks = codeTicksAccessSeq16(armNextPC) * 2 + codeTicksAccess16(armNextPC) + 3; |
| 1342 |
- } |
|
| 1338 |
+ } |
|
| 1343 | 1339 |
} |
| 1344 | 1340 |
|
| 1345 | 1341 |
// ADD Hd, Hs |
| ... | ... |
@@ -1538,7 +1534,7 @@ static INSN_REGPARM void thumb5E(uint32_t opcode) |
| 1538 | 1534 |
if (!busPrefetchCount) |
| 1539 | 1535 |
busPrefetch = busPrefetchEnable; |
| 1540 | 1536 |
uint32_t address = reg[(opcode >> 3) & 7].I + reg[(opcode >> 6) & 7].I; |
| 1541 |
- reg[opcode & 7].I = (uint32_t)CPUReadHalfWordSigned(address); |
|
| 1537 |
+ reg[opcode & 7].I = static_cast<uint32_t>(CPUReadHalfWordSigned(address)); |
|
| 1542 | 1538 |
clockTicks = 3 + dataTicksAccess16(address) + codeTicksAccess16(armNextPC); |
| 1543 | 1539 |
} |
| 1544 | 1540 |
|
| ... | ... |
@@ -1803,7 +1799,7 @@ static INSN_REGPARM void thumbC0(uint32_t opcode) |
| 1803 | 1799 |
if (!busPrefetchCount) |
| 1804 | 1800 |
busPrefetch = busPrefetchEnable; |
| 1805 | 1801 |
uint32_t address = reg[regist].I & 0xFFFFFFFC; |
| 1806 |
- uint32_t temp = reg[regist].I + 4*cpuBitsSet[opcode & 0xff]; |
|
| 1802 |
+ uint32_t temp = reg[regist].I + 4 * cpuBitsSet[opcode & 0xff]; |
|
| 1807 | 1803 |
int count = 0; |
| 1808 | 1804 |
// store |
| 1809 | 1805 |
THUMB_STM_REG(1, 0, regist); |
| ... | ... |
@@ -1824,7 +1820,7 @@ static INSN_REGPARM void thumbC8(uint32_t opcode) |
| 1824 | 1820 |
if (!busPrefetchCount) |
| 1825 | 1821 |
busPrefetch = busPrefetchEnable; |
| 1826 | 1822 |
uint32_t address = reg[regist].I & 0xFFFFFFFC; |
| 1827 |
- uint32_t temp = reg[regist].I + 4*cpuBitsSet[opcode & 0xFF]; |
|
| 1823 |
+ uint32_t temp = reg[regist].I + 4 * cpuBitsSet[opcode & 0xFF]; |
|
| 1828 | 1824 |
int count = 0; |
| 1829 | 1825 |
// load |
| 1830 | 1826 |
THUMB_LDM_REG(1, 0); |
| ... | ... |
@@ -2057,7 +2053,6 @@ static INSN_REGPARM void thumbDD(uint32_t opcode) |
| 2057 | 2053 |
// SWI #comment |
| 2058 | 2054 |
static INSN_REGPARM void thumbDF(uint32_t opcode) |
| 2059 | 2055 |
{
|
| 2060 |
- uint32_t address = 0; |
|
| 2061 | 2056 |
clockTicks = 3; |
| 2062 | 2057 |
busPrefetchCount = 0; |
| 2063 | 2058 |
CPUSoftwareInterrupt(opcode & 0xFF); |
| ... | ... |
@@ -11,10 +11,6 @@ |
| 11 | 11 |
|
| 12 | 12 |
extern int mapgsf(uint8_t *a, int l, int &s); |
| 13 | 13 |
|
| 14 |
-#ifdef __GNUC__ |
|
| 15 |
-#define _stricmp strcasecmp |
|
| 16 |
-#endif |
|
| 17 |
- |
|
| 18 | 14 |
int SWITicks = 0; |
| 19 | 15 |
static int IRQTicks = 0; |
| 20 | 16 |
|
| ... | ... |
@@ -306,8 +302,7 @@ int CPULoadRom() |
| 306 | 302 |
mapgsf(rom, 0x2000000, romSize); |
| 307 | 303 |
|
| 308 | 304 |
uint16_t *temp = reinterpret_cast<uint16_t *>(rom + ((romSize + 1) & ~1)); |
| 309 |
- int i; |
|
| 310 |
- for (i = (romSize + 1) & ~1; i < 0x2000000; i += 2) |
|
| 305 |
+ for (int i = (romSize + 1) & ~1; i < 0x2000000; i += 2) |
|
| 311 | 306 |
{
|
| 312 | 307 |
WRITE16LE(temp, (i >> 1) & 0xFFFF); |
| 313 | 308 |
++temp; |
| ... | ... |
@@ -498,9 +493,6 @@ void CPUSoftwareInterrupt(int comment) |
| 498 | 493 |
comment >>= 16; |
| 499 | 494 |
if (comment == 0xfa) |
| 500 | 495 |
return; |
| 501 |
- // This would be correct, but it causes problems if uncommented |
|
| 502 |
- //else |
|
| 503 |
- //biosProtected = 0xe3a02004; |
|
| 504 | 496 |
|
| 505 | 497 |
switch (comment) |
| 506 | 498 |
{
|
| ... | ... |
@@ -543,7 +535,7 @@ void CPUSoftwareInterrupt(int comment) |
| 543 | 535 |
if ((reg[2].I >> 26) & 1) |
| 544 | 536 |
SWITicks = (7 + memoryWait32[(reg[1].I >> 24) & 0xF]) * (len >> 1); |
| 545 | 537 |
else |
| 546 |
- SWITicks = (8 + memoryWait[(reg[1].I >> 24) & 0xF]) * (len); |
|
| 538 |
+ SWITicks = (8 + memoryWait[(reg[1].I >> 24) & 0xF]) * len; |
|
| 547 | 539 |
} |
| 548 | 540 |
else |
| 549 | 541 |
{
|
| ... | ... |
@@ -638,7 +630,7 @@ void CPUSoftwareInterrupt(int comment) |
| 638 | 630 |
{
|
| 639 | 631 |
uint32_t len = CPUReadMemory(reg[0].I) >> 9; |
| 640 | 632 |
if (!(!(reg[0].I & 0xe000000) || !((reg[0].I + (len & 0x1fffff)) & 0xe000000))) |
| 641 |
- SWITicks = (39 + (memoryWait[(reg[0].I >> 24) & 0xF]<<1) + memoryWait[(reg[1].I >> 24) & 0xF]) * len; |
|
| 633 |
+ SWITicks = (39 + (memoryWait[(reg[0].I >> 24) & 0xF] << 1) + memoryWait[(reg[1].I >> 24) & 0xF]) * len; |
|
| 642 | 634 |
BIOS_Diff8bitUnFilterVram(); |
| 643 | 635 |
break; |
| 644 | 636 |
} |
| ... | ... |
@@ -786,8 +778,6 @@ void CPUCheckDMA(int reason, int dmamask) |
| 786 | 778 |
uint32_t destIncrement = 4; |
| 787 | 779 |
switch ((DM0CNT_H >> 7) & 3) |
| 788 | 780 |
{
|
| 789 |
- case 0: |
|
| 790 |
- break; |
|
| 791 | 781 |
case 1: |
| 792 | 782 |
sourceIncrement = static_cast<uint32_t>(-4); |
| 793 | 783 |
break; |
| ... | ... |
@@ -796,8 +786,6 @@ void CPUCheckDMA(int reason, int dmamask) |
| 796 | 786 |
} |
| 797 | 787 |
switch ((DM0CNT_H >> 5) & 3) |
| 798 | 788 |
{
|
| 799 |
- case 0: |
|
| 800 |
- break; |
|
| 801 | 789 |
case 1: |
| 802 | 790 |
destIncrement = static_cast<uint32_t>(-4); |
| 803 | 791 |
break; |
| ... | ... |
@@ -833,8 +821,6 @@ void CPUCheckDMA(int reason, int dmamask) |
| 833 | 821 |
uint32_t destIncrement = 4; |
| 834 | 822 |
switch ((DM1CNT_H >> 7) & 3) |
| 835 | 823 |
{
|
| 836 |
- case 0: |
|
| 837 |
- break; |
|
| 838 | 824 |
case 1: |
| 839 | 825 |
sourceIncrement = static_cast<uint32_t>(-4); |
| 840 | 826 |
break; |
| ... | ... |
@@ -843,8 +829,6 @@ void CPUCheckDMA(int reason, int dmamask) |
| 843 | 829 |
} |
| 844 | 830 |
switch ((DM1CNT_H >> 5) & 3) |
| 845 | 831 |
{
|
| 846 |
- case 0: |
|
| 847 |
- break; |
|
| 848 | 832 |
case 1: |
| 849 | 833 |
destIncrement = static_cast<uint32_t>(-4); |
| 850 | 834 |
break; |
| ... | ... |
@@ -883,8 +867,6 @@ void CPUCheckDMA(int reason, int dmamask) |
| 883 | 867 |
uint32_t destIncrement = 4; |
| 884 | 868 |
switch ((DM2CNT_H >> 7) & 3) |
| 885 | 869 |
{
|
| 886 |
- case 0: |
|
| 887 |
- break; |
|
| 888 | 870 |
case 1: |
| 889 | 871 |
sourceIncrement = static_cast<uint32_t>(-4); |
| 890 | 872 |
break; |
| ... | ... |
@@ -893,8 +875,6 @@ void CPUCheckDMA(int reason, int dmamask) |
| 893 | 875 |
} |
| 894 | 876 |
switch ((DM2CNT_H >> 5) & 3) |
| 895 | 877 |
{
|
| 896 |
- case 0: |
|
| 897 |
- break; |
|
| 898 | 878 |
case 1: |
| 899 | 879 |
destIncrement = static_cast<uint32_t>(-4); |
| 900 | 880 |
break; |
| ... | ... |
@@ -933,8 +913,6 @@ void CPUCheckDMA(int reason, int dmamask) |
| 933 | 913 |
uint32_t destIncrement = 4; |
| 934 | 914 |
switch ((DM3CNT_H >> 7) & 3) |
| 935 | 915 |
{
|
| 936 |
- case 0: |
|
| 937 |
- break; |
|
| 938 | 916 |
case 1: |
| 939 | 917 |
sourceIncrement = static_cast<uint32_t>(-4); |
| 940 | 918 |
break; |
| ... | ... |
@@ -943,8 +921,6 @@ void CPUCheckDMA(int reason, int dmamask) |
| 943 | 921 |
} |
| 944 | 922 |
switch ((DM3CNT_H >> 5) & 3) |
| 945 | 923 |
{
|
| 946 |
- case 0: |
|
| 947 |
- break; |
|
| 948 | 924 |
case 1: |
| 949 | 925 |
destIncrement = static_cast<uint32_t>(-4); |
| 950 | 926 |
break; |
| ... | ... |
@@ -952,6 +928,7 @@ void CPUCheckDMA(int reason, int dmamask) |
| 952 | 928 |
destIncrement = 0; |
| 953 | 929 |
} |
| 954 | 930 |
doDMA(dma3Source, dma3Dest, sourceIncrement, destIncrement, DM3CNT_L ? DM3CNT_L : 0x10000, DM3CNT_H & 0x0400); |
| 931 |
+ |
|
| 955 | 932 |
if (DM3CNT_H & 0x4000) |
| 956 | 933 |
{
|
| 957 | 934 |
IF |= 0x0800; |
| ... | ... |
@@ -1002,6 +979,8 @@ void CPUUpdateRegister(uint32_t address, uint16_t value) |
| 1002 | 979 |
if (!(DISPSTAT & 1)) |
| 1003 | 980 |
{
|
| 1004 | 981 |
lcdTicks = 1008; |
| 982 |
+ //VCOUNT = 0; |
|
| 983 |
+ //UPDATE_REG(0x06, VCOUNT); |
|
| 1005 | 984 |
DISPSTAT &= 0xFFFC; |
| 1006 | 985 |
UPDATE_REG(0x04, DISPSTAT); |
| 1007 | 986 |
CPUCompareVCOUNT(); |
| ... | ... |
@@ -1085,7 +1064,7 @@ void CPUUpdateRegister(uint32_t address, uint16_t value) |
| 1085 | 1064 |
UPDATE_REG(0x28, BG2X_L); |
| 1086 | 1065 |
break; |
| 1087 | 1066 |
case 0x2A: |
| 1088 |
- BG2X_H = (value & 0xFFF); |
|
| 1067 |
+ BG2X_H = value & 0xFFF; |
|
| 1089 | 1068 |
UPDATE_REG(0x2A, BG2X_H); |
| 1090 | 1069 |
break; |
| 1091 | 1070 |
case 0x2C: |
| ... | ... |
@@ -1476,7 +1455,7 @@ void applyTimer() |
| 1476 | 1455 |
timer2Ticks = (0x10000 - TM2D) << timer2ClockReload; |
| 1477 | 1456 |
UPDATE_REG(0x108, TM2D); |
| 1478 | 1457 |
} |
| 1479 |
- timer2On = !(timer2Value & 0x80); |
|
| 1458 |
+ timer2On = !!(timer2Value & 0x80); |
|
| 1480 | 1459 |
TM2CNT = timer2Value & 0xC7; |
| 1481 | 1460 |
UPDATE_REG(0x10A, TM2CNT); |
| 1482 | 1461 |
} |
| ... | ... |
@@ -1511,7 +1490,8 @@ void CPUInit() |
| 1511 | 1490 |
cpuBiosSwapped = true; |
| 1512 | 1491 |
} |
| 1513 | 1492 |
#endif |
| 1514 |
- memcpy(&bios[0], myROM, sizeof(myROM)); |
|
| 1493 |
+ |
|
| 1494 |
+ memcpy(&bios[0], &myROM[0], sizeof(myROM)); |
|
| 1515 | 1495 |
|
| 1516 | 1496 |
biosProtected[0] = 0x00; |
| 1517 | 1497 |
biosProtected[1] = 0xf0; |
| ... | ... |
@@ -1724,7 +1704,7 @@ void CPUReset() |
| 1724 | 1704 |
map[2].mask = 0x3FFFF; |
| 1725 | 1705 |
map[3].address = &internalRAM[0]; |
| 1726 | 1706 |
map[3].mask = 0x7FFF; |
| 1727 |
- map[4].address = ioMem; |
|
| 1707 |
+ map[4].address = &ioMem[0]; |
|
| 1728 | 1708 |
map[4].mask = 0x3FF; |
| 1729 | 1709 |
map[5].address = &paletteRAM[0]; |
| 1730 | 1710 |
map[5].mask = 0x3FF; |
| ... | ... |
@@ -20,7 +20,7 @@ extern int thumbExecute(); |
| 20 | 20 |
# define UNLIKELY(x) (x) |
| 21 | 21 |
#endif |
| 22 | 22 |
|
| 23 |
-inline void UPDATE_REG(uint32_t address, uint16_t value) { WRITE16LE(&ioMem[address],value); }
|
|
| 23 |
+inline void UPDATE_REG(uint32_t address, uint16_t value) { WRITE16LE(&ioMem[address], value); }
|
|
| 24 | 24 |
|
| 25 | 25 |
extern uint32_t cpuPrefetch[2]; |
| 26 | 26 |
|
| ... | ... |
@@ -98,8 +98,8 @@ inline uint32_t CPUReadMemory(uint32_t address) |
| 98 | 98 |
unreadable: |
| 99 | 99 |
if (armState) |
| 100 | 100 |
return CPUReadMemoryQuick(reg[15].I); |
| 101 |
- else |
|
| 102 |
- return CPUReadHalfWordQuick(reg[15].I) | CPUReadHalfWordQuick(reg[15].I) << 16; |
|
| 101 |
+ else |
|
| 102 |
+ return CPUReadHalfWordQuick(reg[15].I) | (CPUReadHalfWordQuick(reg[15].I) << 16); |
|
| 103 | 103 |
} |
| 104 | 104 |
|
| 105 | 105 |
if (oldAddress & 3) |
| ... | ... |
@@ -108,13 +108,13 @@ inline uint32_t CPUReadMemory(uint32_t address) |
| 108 | 108 |
int shift = (oldAddress & 3) << 3; |
| 109 | 109 |
value = (value >> shift) | (value << (32 - shift)); |
| 110 | 110 |
#else |
| 111 |
-#ifdef __GNUC__ |
|
| 111 |
+# ifdef __GNUC__ |
|
| 112 | 112 |
asm("and $3, %%ecx;"
|
| 113 | 113 |
"shl $3 ,%%ecx;" |
| 114 | 114 |
"ror %%cl, %0" |
| 115 | 115 |
: "=r" (value) |
| 116 | 116 |
: "r" (value), "c" (oldAddress)); |
| 117 |
-#else |
|
| 117 |
+# else |
|
| 118 | 118 |
__asm |
| 119 | 119 |
{
|
| 120 | 120 |
mov ecx, oldAddress; |
| ... | ... |
@@ -122,7 +122,7 @@ inline uint32_t CPUReadMemory(uint32_t address) |
| 122 | 122 |
shl ecx, 3; |
| 123 | 123 |
ror [dword ptr value], cl; |
| 124 | 124 |
} |
| 125 |
-#endif |
|
| 125 |
+# endif |
|
| 126 | 126 |
#endif |
| 127 | 127 |
} |
| 128 | 128 |
|
| ... | ... |
@@ -204,16 +204,12 @@ inline uint32_t CPUReadHalfWord(uint32_t address) |
| 204 | 204 |
else |
| 205 | 205 |
value = READ16LE(&rom[address & 0x1FFFFFE]); |
| 206 | 206 |
break; |
| 207 |
- case 13: |
|
| 208 |
- case 14: |
|
| 209 |
- return 0; |
|
| 210 |
- // default |
|
| 211 | 207 |
default: |
| 212 | 208 |
unreadable: |
| 213 | 209 |
if (armState) |
| 214 | 210 |
return CPUReadMemoryQuick(reg[15].I); |
| 215 | 211 |
else |
| 216 |
- return CPUReadHalfWordQuick(reg[15].I) | CPUReadHalfWordQuick(reg[15].I) << 16; |
|
| 212 |
+ return CPUReadHalfWordQuick(reg[15].I) | (CPUReadHalfWordQuick(reg[15].I) << 16); |
|
| 217 | 213 |
} |
| 218 | 214 |
|
| 219 | 215 |
if (oldAddress & 1) |
| ... | ... |
@@ -272,16 +268,12 @@ inline uint8_t CPUReadByte(uint32_t address) |
| 272 | 268 |
case 11: |
| 273 | 269 |
case 12: |
| 274 | 270 |
return rom[address & 0x1FFFFFF]; |
| 275 |
- case 13: |
|
| 276 |
- case 14: |
|
| 277 |
- return 0; |
|
| 278 |
- // default |
|
| 279 | 271 |
default: |
| 280 | 272 |
unreadable: |
| 281 | 273 |
if (armState) |
| 282 | 274 |
return CPUReadMemoryQuick(reg[15].I); |
| 283 | 275 |
else |
| 284 |
- return CPUReadHalfWordQuick(reg[15].I) | CPUReadHalfWordQuick(reg[15].I) << 16; |
|
| 276 |
+ return CPUReadHalfWordQuick(reg[15].I) | (CPUReadHalfWordQuick(reg[15].I) << 16); |
|
| 285 | 277 |
} |
| 286 | 278 |
} |
| 287 | 279 |
|
| ... | ... |
@@ -68,7 +68,7 @@ static Gba_Pcm_Fifo pcm[2]; |
| 68 | 68 |
static std::unique_ptr<Gb_Apu> gb_apu; |
| 69 | 69 |
static std::unique_ptr<Stereo_Buffer> stereo_buffer; |
| 70 | 70 |
|
| 71 |
-static Blip_Synth<blip_best_quality, 1> pcm_synth[3]; // 32 kHz, 16 kHz, 8 kHz |
|
| 71 |
+static Blip_Synth<blip_high_quality, 1> pcm_synth[3]; // 32 kHz, 16 kHz, 8 kHz |
|
| 72 | 72 |
|
| 73 | 73 |
static inline blip_time_t blip_time() |
| 74 | 74 |
{
|
| ... | ... |
@@ -104,7 +104,7 @@ void BIOS_BitUnPack() |
| 104 | 104 |
|
| 105 | 105 |
int bits = CPUReadByte(header + 2); |
| 106 | 106 |
int revbits = 8 - bits; |
| 107 |
- // u32 value = 0; |
|
| 107 |
+ //uint32_t value = 0; |
|
| 108 | 108 |
uint32_t base = CPUReadMemory(header + 4); |
| 109 | 109 |
bool addBase = !!(base & 0x80000000); |
| 110 | 110 |
base &= 0x7fffffff; |
| ... | ... |
@@ -346,7 +346,7 @@ void BIOS_Diff8bitUnFilterVram() |
| 346 | 346 |
uint32_t header = CPUReadMemory(source); |
| 347 | 347 |
source += 4; |
| 348 | 348 |
|
| 349 |
- if (!(source & 0xe000000) | !((source + ((header >> 8) & 0x1fffff)) & 0xe000000)) |
|
| 349 |
+ if (!(source & 0xe000000) || !((source + ((header >> 8) & 0x1fffff)) & 0xe000000)) |
|
| 350 | 350 |
return; |
| 351 | 351 |
|
| 352 | 352 |
int len = header >> 8; |
| ... | ... |
@@ -416,7 +416,7 @@ void BIOS_Div() |
| 416 | 416 |
reg[1].I = number % denom; |
| 417 | 417 |
int32_t temp = static_cast<int32_t>(reg[0].I); |
| 418 | 418 |
reg[3].I = static_cast<uint32_t>(temp < 0 ? -temp : temp); |
| 419 |
- } |
|
| 419 |
+ } |
|
| 420 | 420 |
} |
| 421 | 421 |
|
| 422 | 422 |
void BIOS_HuffUnComp() |