| ... | ... |
@@ -93,7 +93,7 @@ public: |
| 93 | 93 |
return; |
| 94 | 94 |
if (bytes > bleft) |
| 95 | 95 |
bytes = bleft; |
| 96 |
- std::fill(&this->buf[this->fil], &this->buf[this->fil + bytes], 0); |
|
| 96 |
+ std::fill_n(&this->buf[this->fil], bytes, 0); |
|
| 97 | 97 |
S9xMixSamples(&this->buf[this->fil], bytes >> 1); |
| 98 | 98 |
this->fil += bytes; |
| 99 | 99 |
} |
| ... | ... |
@@ -122,7 +122,7 @@ static void Map2SFSection(const std::vector<uint8_t> §ion, int level) |
| 122 | 122 |
data.resize(finalSize, 0); |
| 123 | 123 |
else if (data.size() < size + offset) |
| 124 | 124 |
data.resize(offset + finalSize); |
| 125 |
- std::copy(§ion[8], §ion[8 + size], &data[offset]); |
|
| 125 |
+ std::copy_n(§ion[8], size, &data[offset]); |
|
| 126 | 126 |
} |
| 127 | 127 |
|
| 128 | 128 |
static bool Map2SF(XSFFile *xSF, int level) |
| ... | ... |
@@ -148,7 +148,7 @@ static bool Map2SF(XSFFile *xSF, int level) |
| 148 | 148 |
if (size > 4 && loaderwork.sram.size() > offset) |
| 149 | 149 |
{
|
| 150 | 150 |
auto len = std::min(size - 4, loaderwork.sram.size() - offset); |
| 151 |
- std::copy(&reservedSection[reservedPosition + 12], &reservedSection[reservedPosition + 12 + len], &loaderwork.sram[offset]); |
|
| 151 |
+ std::copy_n(&reservedSection[reservedPosition + 12], len, &loaderwork.sram[offset]); |
|
| 152 | 152 |
} |
| 153 | 153 |
} |
| 154 | 154 |
reservedPosition += size + 8; |
| ... | ... |
@@ -276,7 +276,7 @@ void XSFPlayer_SNSF::GenerateSamples(std::vector<uint8_t> &buf, unsigned offset, |
| 276 | 276 |
unsigned len = remain; |
| 277 | 277 |
if (len > bytes) |
| 278 | 278 |
len = bytes; |
| 279 |
- std::copy(&buffer.buf[buffer.cur], &buffer.buf[buffer.cur + len], &buf[offset]); |
|
| 279 |
+ std::copy_n(&buffer.buf[buffer.cur], len, &buf[offset]); |
|
| 280 | 280 |
bytes -= len; |
| 281 | 281 |
offset += len; |
| 282 | 282 |
buffer.cur += len; |
| ... | ... |
@@ -63,9 +63,9 @@ void SNES_SPC::enable_rom(bool enable) |
| 63 | 63 |
{
|
| 64 | 64 |
this->m.rom_enabled = this->dsp.rom_enabled = enable; |
| 65 | 65 |
if (enable) |
| 66 |
- std::copy(&this->m.ram.ram[rom_addr], &this->m.ram.ram[rom_addr + rom_size], &this->m.hi_ram[0]); |
|
| 66 |
+ std::copy_n(&this->m.ram.ram[rom_addr], static_cast<int>(rom_size), &this->m.hi_ram[0]); |
|
| 67 | 67 |
auto data = enable ? &this->m.rom[0] : &this->m.hi_ram[0]; |
| 68 |
- std::copy(&data[0], &data[rom_size], &this->m.ram.ram[rom_addr]); |
|
| 68 |
+ std::copy_n(&data[0], static_cast<int>(rom_size), &this->m.ram.ram[rom_addr]); |
|
| 69 | 69 |
// TODO: ROM can still get overwritten when DSP writes to echo buffer |
| 70 | 70 |
} |
| 71 | 71 |
} |
| ... | ... |
@@ -173,10 +173,7 @@ void SNES_SPC::cpu_write_smp_reg_(int data, rel_time_t time, int addr) |
| 173 | 173 |
t = this->run_timer(t, time); |
| 174 | 174 |
t->enabled = enabled; |
| 175 | 175 |
if (enabled) |
| 176 |
- {
|
|
| 177 |
- t->divider = 0; |
|
| 178 |
- t->counter = 0; |
|
| 179 |
- } |
|
| 176 |
+ t->divider = t->counter = 0; |
|
| 180 | 177 |
} |
| 181 | 178 |
} |
| 182 | 179 |
this->enable_rom(!!(data & 0x80)); |
| ... | ... |
@@ -296,28 +293,6 @@ int SNES_SPC::cpu_read(int addr, rel_time_t time) |
| 296 | 293 |
|
| 297 | 294 |
//// Run |
| 298 | 295 |
|
| 299 |
-// Prefix and suffix for CPU emulator function |
|
| 300 |
-#define SPC_CPU_RUN_FUNC \ |
|
| 301 |
-uint8_t *SNES_SPC::run_until_(time_t end_time) \ |
|
| 302 |
-{ \
|
|
| 303 |
- rel_time_t rel_time = this->m.spc_time - end_time; \ |
|
| 304 |
- /*assert( rel_time <= 0 );*/ \ |
|
| 305 |
- this->m.spc_time = end_time; \ |
|
| 306 |
- this->m.dsp_time += rel_time; \ |
|
| 307 |
- this->m.timers[0].next_time += rel_time; \ |
|
| 308 |
- this->m.timers[1].next_time += rel_time; \ |
|
| 309 |
- this->m.timers[2].next_time += rel_time; |
|
| 310 |
- |
|
| 311 |
-#define SPC_CPU_RUN_FUNC_END \ |
|
| 312 |
- this->m.spc_time += rel_time; \ |
|
| 313 |
- this->m.dsp_time -= rel_time; \ |
|
| 314 |
- this->m.timers[0].next_time -= rel_time; \ |
|
| 315 |
- this->m.timers[1].next_time -= rel_time; \ |
|
| 316 |
- this->m.timers[2].next_time -= rel_time; \ |
|
| 317 |
- /*assert( m.spc_time >= end_time );*/ \ |
|
| 318 |
- return &this->m.smp_regs[0][r_cpuio0]; \ |
|
| 319 |
-} |
|
| 320 |
- |
|
| 321 | 296 |
static const int cpu_lag_max = 12 - 1; // DIV YA,X takes 12 clocks |
| 322 | 297 |
|
| 323 | 298 |
void SNES_SPC::end_frame(time_t end_time) |
| ... | ... |
@@ -70,7 +70,7 @@ void SNES_SPC::init() |
| 70 | 70 |
|
| 71 | 71 |
void SNES_SPC::init_rom(const uint8_t in[rom_size]) |
| 72 | 72 |
{
|
| 73 |
- std::copy(&in[0], &in[rom_size], &this->m.rom[0]); |
|
| 73 |
+ std::copy_n(&in[0], static_cast<int>(rom_size), &this->m.rom[0]); |
|
| 74 | 74 |
} |
| 75 | 75 |
|
| 76 | 76 |
void SNES_SPC::set_tempo(int t) |
| ... | ... |
@@ -100,7 +100,7 @@ void SNES_SPC::set_tempo(int t) |
| 100 | 100 |
// reset timer prescalers or dividers. |
| 101 | 101 |
void SNES_SPC::timers_loaded() |
| 102 | 102 |
{
|
| 103 |
- for (int i = 0; i < timer_count; ++i) |
|
| 103 |
+ for (int i = 0; i < timer_count; ++i) |
|
| 104 | 104 |
{
|
| 105 | 105 |
auto &t = this->m.timers[i]; |
| 106 | 106 |
t.period = IF_0_THEN_256(this->m.smp_regs[0][r_t0target + i]); |
| ... | ... |
@@ -114,8 +114,8 @@ void SNES_SPC::timers_loaded() |
| 114 | 114 |
// Loads registers from unified 16-byte format |
| 115 | 115 |
void SNES_SPC::load_regs(const uint8_t in[reg_count]) |
| 116 | 116 |
{
|
| 117 |
- std::copy(&in[0], &in[reg_count], &this->m.smp_regs[0][0]); |
|
| 118 |
- std::copy(&this->m.smp_regs[0][0], &this->m.smp_regs[0][reg_count], &this->m.smp_regs[1][0]); |
|
| 117 |
+ std::copy_n(&in[0], static_cast<int>(reg_count), &this->m.smp_regs[0][0]); |
|
| 118 |
+ std::copy_n(&this->m.smp_regs[0][0], static_cast<int>(reg_count), &this->m.smp_regs[1][0]); |
|
| 119 | 119 |
|
| 120 | 120 |
// These always read back as 0 |
| 121 | 121 |
this->m.smp_regs[1][r_test] = this->m.smp_regs[1][r_control] = this->m.smp_regs[1][r_t0target] = this->m.smp_regs[1][r_t1target] = this->m.smp_regs[1][r_t2target] = 0; |
| ... | ... |
@@ -145,12 +145,11 @@ void SNES_SPC::reset_time_regs() |
| 145 | 145 |
this->m.spc_time = 0; |
| 146 | 146 |
this->m.dsp_time = 0; |
| 147 | 147 |
|
| 148 |
- for (int i = 0; i < timer_count; ++i) |
|
| 148 |
+ std::for_each(&this->m.timers[0], &this->m.timers[timer_count], [](Timer &t) |
|
| 149 | 149 |
{
|
| 150 |
- auto &t = this->m.timers[i]; |
|
| 151 | 150 |
t.next_time = 1; |
| 152 | 151 |
t.divider = 0; |
| 153 |
- } |
|
| 152 |
+ }); |
|
| 154 | 153 |
|
| 155 | 154 |
this->regs_loaded(); |
| 156 | 155 |
|
| ... | ... |
@@ -160,8 +159,7 @@ void SNES_SPC::reset_time_regs() |
| 160 | 159 |
|
| 161 | 160 |
void SNES_SPC::reset_common(int timer_counter_init) |
| 162 | 161 |
{
|
| 163 |
- for (int i = 0; i < timer_count; ++i) |
|
| 164 |
- this->m.smp_regs[1][r_t0out + i] = timer_counter_init; |
|
| 162 |
+ std::fill_n(&this->m.smp_regs[1][r_t0out], static_cast<int>(timer_count), timer_counter_init); |
|
| 165 | 163 |
|
| 166 | 164 |
// Run IPL ROM |
| 167 | 165 |
memset(&this->m.cpu_regs, 0, sizeof(this->m.cpu_regs)); |
| ... | ... |
@@ -169,7 +167,7 @@ void SNES_SPC::reset_common(int timer_counter_init) |
| 169 | 167 |
|
| 170 | 168 |
this->m.smp_regs[0][r_test] = 0x0A; |
| 171 | 169 |
this->m.smp_regs[0][r_control] = 0xB0; // ROM enabled, clear ports |
| 172 |
- std::fill(&this->m.smp_regs[1][r_cpuio0], &this->m.smp_regs[1][r_cpuio0 + port_count], 0); |
|
| 170 |
+ std::fill_n(&this->m.smp_regs[1][r_cpuio0], static_cast<int>(port_count), 0); |
|
| 173 | 171 |
|
| 174 | 172 |
this->reset_time_regs(); |
| 175 | 173 |
} |
| ... | ... |
@@ -186,7 +184,7 @@ void SNES_SPC::reset() |
| 186 | 184 |
this->m.cpu_regs.a = this->m.cpu_regs.x = this->m.cpu_regs.y = 0x00; |
| 187 | 185 |
this->m.cpu_regs.psw = 0x02; |
| 188 | 186 |
this->m.cpu_regs.sp = 0xEF; |
| 189 |
- std::fill(&this->m.ram.ram[0], &this->m.ram.ram[0x10000], 0); |
|
| 187 |
+ std::fill_n(&this->m.ram.ram[0], 0x10000, 0); |
|
| 190 | 188 |
this->ram_loaded(); |
| 191 | 189 |
this->reset_common(0x0F); |
| 192 | 190 |
this->dsp.reset(); |
| ... | ... |
@@ -38,8 +38,16 @@ const int c01 = 0x01; // c |
| 38 | 38 |
|
| 39 | 39 |
const int nz_neg_mask = 0x880; // either bit set indicates N flag set |
| 40 | 40 |
|
| 41 |
-SPC_CPU_RUN_FUNC |
|
| 41 |
+uint8_t *SNES_SPC::run_until_(time_t end_time) |
|
| 42 | 42 |
{
|
| 43 |
+ rel_time_t rel_time = this->m.spc_time - end_time; |
|
| 44 |
+ /*assert( rel_time <= 0 );*/ |
|
| 45 |
+ this->m.spc_time = end_time; |
|
| 46 |
+ this->m.dsp_time += rel_time; |
|
| 47 |
+ this->m.timers[0].next_time += rel_time; |
|
| 48 |
+ this->m.timers[1].next_time += rel_time; |
|
| 49 |
+ this->m.timers[2].next_time += rel_time; |
|
| 50 |
+ |
|
| 43 | 51 |
auto ram = this->m.ram.ram; |
| 44 | 52 |
int a = this->m.cpu_regs.a; |
| 45 | 53 |
int x = this->m.cpu_regs.x; |
| ... | ... |
@@ -155,7 +163,6 @@ cbranch_taken_loop: |
| 155 | 163 |
inc_pc_loop: |
| 156 | 164 |
++pc; |
| 157 | 165 |
loop: |
| 158 |
-{
|
|
| 159 | 166 |
unsigned data; |
| 160 | 167 |
|
| 161 | 168 |
unsigned opcode = *pc; |
| ... | ... |
@@ -167,20 +174,6 @@ loop: |
| 167 | 174 |
#ifdef SPC_CPU_OPCODE_HOOK |
| 168 | 175 |
SPC_CPU_OPCODE_HOOK(GET_PC(), opcode); |
| 169 | 176 |
#endif |
| 170 |
- /* |
|
| 171 |
- //SUB_CASE_COUNTER( 1 ); |
|
| 172 |
- #define PROFILE_TIMER_LOOP( op, addr, len )\ |
|
| 173 |
- if ( opcode == op )\ |
|
| 174 |
- {\
|
|
| 175 |
- int cond = (unsigned) ((addr) - 0xFD) < 3 &&\ |
|
| 176 |
- pc [len] == 0xF0 && pc [len+1] == 0xFE - len;\ |
|
| 177 |
- SUB_CASE_COUNTER( op && cond );\ |
|
| 178 |
- } |
|
| 179 |
- |
|
| 180 |
- PROFILE_TIMER_LOOP( 0xEC, get_le16( pc + 1 ), 3 ); |
|
| 181 |
- PROFILE_TIMER_LOOP( 0xEB, pc [1], 2 ); |
|
| 182 |
- PROFILE_TIMER_LOOP( 0xE4, pc [1], 2 ); |
|
| 183 |
- */ |
|
| 184 | 177 |
|
| 185 | 178 |
// TODO: if PC is at end of memory, this will get wrong operand (very obscure) |
| 186 | 179 |
data = *++pc; |
| ... | ... |
@@ -268,7 +261,7 @@ loop: |
| 268 | 261 |
++pc; |
| 269 | 262 |
{
|
| 270 | 263 |
int i = dp + data; |
| 271 |
- ram [i] = static_cast<uint8_t>(a); |
|
| 264 |
+ ram[i] = static_cast<uint8_t>(a); |
|
| 272 | 265 |
i -= 0xF0; |
| 273 | 266 |
if (static_cast<unsigned>(i) < 0x10) // 39% |
| 274 | 267 |
{
|
| ... | ... |
@@ -411,23 +404,19 @@ loop: |
| 411 | 404 |
// 3. 8-BIT DATA TRANSMISSIN COMMANDS, GROUP 3. |
| 412 | 405 |
|
| 413 | 406 |
case 0x7D: // MOV A,X |
| 414 |
- a = x; |
|
| 415 |
- nz = x; |
|
| 407 |
+ a = nz = x; |
|
| 416 | 408 |
goto loop; |
| 417 | 409 |
|
| 418 | 410 |
case 0xDD: // MOV A,Y |
| 419 |
- a = y; |
|
| 420 |
- nz = y; |
|
| 411 |
+ a = nz = y; |
|
| 421 | 412 |
goto loop; |
| 422 | 413 |
|
| 423 | 414 |
case 0x5D: // MOV X,A |
| 424 |
- x = a; |
|
| 425 |
- nz = a; |
|
| 415 |
+ x = nz = a; |
|
| 426 | 416 |
goto loop; |
| 427 | 417 |
|
| 428 | 418 |
case 0xFD: // MOV Y,A |
| 429 |
- y = a; |
|
| 430 |
- nz = a; |
|
| 419 |
+ y = nz = a; |
|
| 431 | 420 |
goto loop; |
| 432 | 421 |
|
| 433 | 422 |
case 0x9D: // MOV X,SP |
| ... | ... |
@@ -1157,7 +1146,7 @@ loop: |
| 1157 | 1146 |
} // switch |
| 1158 | 1147 |
|
| 1159 | 1148 |
assert(0); // catch any unhandled instructions |
| 1160 |
-} |
|
| 1149 |
+ |
|
| 1161 | 1150 |
out_of_time: |
| 1162 | 1151 |
rel_time -= this->m.cycle_table[*pc]; // undo partial execution of opcode |
| 1163 | 1152 |
stop: |
| ... | ... |
@@ -1168,10 +1157,15 @@ stop: |
| 1168 | 1157 |
m.cpu_regs.a = static_cast<uint8_t>(a); |
| 1169 | 1158 |
m.cpu_regs.x = static_cast<uint8_t>(x); |
| 1170 | 1159 |
m.cpu_regs.y = static_cast<uint8_t>(y); |
| 1171 |
- {
|
|
| 1172 |
- int temp; |
|
| 1173 |
- GET_PSW(temp); |
|
| 1174 |
- m.cpu_regs.psw = static_cast<uint8_t>(temp); |
|
| 1175 |
- } |
|
| 1160 |
+ int temp; |
|
| 1161 |
+ GET_PSW(temp); |
|
| 1162 |
+ m.cpu_regs.psw = static_cast<uint8_t>(temp); |
|
| 1163 |
+ |
|
| 1164 |
+ this->m.spc_time += rel_time; |
|
| 1165 |
+ this->m.dsp_time -= rel_time; |
|
| 1166 |
+ this->m.timers[0].next_time -= rel_time; |
|
| 1167 |
+ this->m.timers[1].next_time -= rel_time; |
|
| 1168 |
+ this->m.timers[2].next_time -= rel_time; |
|
| 1169 |
+ /*assert( m.spc_time >= end_time );*/ |
|
| 1170 |
+ return &this->m.smp_regs[0][r_cpuio0]; |
|
| 1176 | 1171 |
} |
| 1177 |
-SPC_CPU_RUN_FUNC_END |
| ... | ... |
@@ -317,7 +317,8 @@ void SPC_DSP::misc_28() |
| 317 | 317 |
} |
| 318 | 318 |
void SPC_DSP::misc_29() |
| 319 | 319 |
{
|
| 320 |
- if ((this->m.every_other_sample = !this->m.every_other_sample)) |
|
| 320 |
+ this->m.every_other_sample = !this->m.every_other_sample; |
|
| 321 |
+ if (this->m.every_other_sample) |
|
| 321 | 322 |
this->m.new_kon &= ~this->m.kon; // clears KON 63 clocks after it was last read |
| 322 | 323 |
} |
| 323 | 324 |
void SPC_DSP::misc_30() |
| ... | ... |
@@ -697,38 +698,38 @@ V(V9_V6_V3,2) -> V(V9,2) V(V6,3) V(V3,4) */ |
| 697 | 698 |
|
| 698 | 699 |
// Voice 0 1 2 3 4 5 6 7 |
| 699 | 700 |
#define GEN_DSP_TIMING \ |
| 700 |
-PHASE( 0) V(V5,0)V(V2,1)\ |
|
| 701 |
-PHASE( 1) V(V6,0)V(V3,1)\ |
|
| 702 |
-PHASE( 2) V(V7_V4_V1,0)\ |
|
| 703 |
-PHASE( 3) V(V8_V5_V2,0)\ |
|
| 704 |
-PHASE( 4) V(V9_V6_V3,0)\ |
|
| 705 |
-PHASE( 5) V(V7_V4_V1,1)\ |
|
| 706 |
-PHASE( 6) V(V8_V5_V2,1)\ |
|
| 707 |
-PHASE( 7) V(V9_V6_V3,1)\ |
|
| 708 |
-PHASE( 8) V(V7_V4_V1,2)\ |
|
| 709 |
-PHASE( 9) V(V8_V5_V2,2)\ |
|
| 710 |
-PHASE(10) V(V9_V6_V3,2)\ |
|
| 711 |
-PHASE(11) V(V7_V4_V1,3)\ |
|
| 712 |
-PHASE(12) V(V8_V5_V2,3)\ |
|
| 713 |
-PHASE(13) V(V9_V6_V3,3)\ |
|
| 714 |
-PHASE(14) V(V7_V4_V1,4)\ |
|
| 715 |
-PHASE(15) V(V8_V5_V2,4)\ |
|
| 716 |
-PHASE(16) V(V9_V6_V3,4)\ |
|
| 717 |
-PHASE(17) V(V1,0) V(V7,5)V(V4,6)\ |
|
| 718 |
-PHASE(18) V(V8_V5_V2,5)\ |
|
| 719 |
-PHASE(19) V(V9_V6_V3,5)\ |
|
| 720 |
-PHASE(20) V(V1,1) V(V7,6)V(V4,7)\ |
|
| 721 |
-PHASE(21) V(V8,6)V(V5,7) V(V2,0) /* t_brr_next_addr order dependency */\ |
|
| 722 |
-PHASE(22) V(V3a,0) V(V9,6)V(V6,7) echo_22();\ |
|
| 723 |
-PHASE(23) V(V7,7) echo_23();\ |
|
| 724 |
-PHASE(24) V(V8,7) echo_24();\ |
|
| 725 |
-PHASE(25) V(V3b,0) V(V9,7) echo_25();\ |
|
| 726 |
-PHASE(26) echo_26();\ |
|
| 727 |
-PHASE(27) misc_27(); echo_27();\ |
|
| 728 |
-PHASE(28) misc_28(); echo_28();\ |
|
| 729 |
-PHASE(29) misc_29(); echo_29();\ |
|
| 730 |
-PHASE(30) misc_30();V(V3c,0) echo_30();\ |
|
| 731 |
-PHASE(31) V(V4,0) V(V1,2)\ |
|
| 701 |
+PHASE(0) V(V5, 0) V(V2, 1) \ |
|
| 702 |
+PHASE(1) V(V6, 0) V(V3, 1) \ |
|
| 703 |
+PHASE(2) V(V7_V4_V1, 0) \ |
|
| 704 |
+PHASE(3) V(V8_V5_V2, 0) \ |
|
| 705 |
+PHASE(4) V(V9_V6_V3, 0) \ |
|
| 706 |
+PHASE(5) V(V7_V4_V1, 1) \ |
|
| 707 |
+PHASE(6) V(V8_V5_V2, 1) \ |
|
| 708 |
+PHASE(7) V(V9_V6_V3, 1) \ |
|
| 709 |
+PHASE(8) V(V7_V4_V1, 2) \ |
|
| 710 |
+PHASE(9) V(V8_V5_V2, 2) \ |
|
| 711 |
+PHASE(10) V(V9_V6_V3, 2) \ |
|
| 712 |
+PHASE(11) V(V7_V4_V1, 3) \ |
|
| 713 |
+PHASE(12) V(V8_V5_V2, 3) \ |
|
| 714 |
+PHASE(13) V(V9_V6_V3, 3) \ |
|
| 715 |
+PHASE(14) V(V7_V4_V1, 4) \ |
|
| 716 |
+PHASE(15) V(V8_V5_V2, 4) \ |
|
| 717 |
+PHASE(16) V(V9_V6_V3, 4) \ |
|
| 718 |
+PHASE(17) V(V1, 0) V(V7, 5) V(V4, 6) \ |
|
| 719 |
+PHASE(18) V(V8_V5_V2, 5) \ |
|
| 720 |
+PHASE(19) V(V9_V6_V3, 5) \ |
|
| 721 |
+PHASE(20) V(V1, 1) V(V7, 6) V(V4, 7) \ |
|
| 722 |
+PHASE(21) V(V8, 6) V(V5, 7) V(V2, 0) /* t_brr_next_addr order dependency */ \ |
|
| 723 |
+PHASE(22) V(V3a, 0) V(V9, 6) V(V6, 7) echo_22(); \ |
|
| 724 |
+PHASE(23) V(V7, 7) echo_23(); \ |
|
| 725 |
+PHASE(24) V(V8, 7) echo_24(); \ |
|
| 726 |
+PHASE(25) V(V3b, 0) V(V9, 7) echo_25(); \ |
|
| 727 |
+PHASE(26) echo_26(); \ |
|
| 728 |
+PHASE(27) misc_27(); echo_27(); \ |
|
| 729 |
+PHASE(28) misc_28(); echo_28(); \ |
|
| 730 |
+PHASE(29) misc_29(); echo_29(); \ |
|
| 731 |
+PHASE(30) misc_30(); V(V3c, 0) echo_30(); \ |
|
| 732 |
+PHASE(31) V(V4, 0) V(V1, 2) |
|
| 732 | 733 |
|
| 733 | 734 |
#if !SPC_DSP_CUSTOM_RUN |
| 734 | 735 |
void SPC_DSP::run(int clocks_remain) |
| ... | ... |
@@ -748,7 +749,6 @@ void SPC_DSP::run(int clocks_remain) |
| 748 | 749 |
goto loop; |
| 749 | 750 |
} |
| 750 | 751 |
} |
| 751 |
- |
|
| 752 | 752 |
#endif |
| 753 | 753 |
|
| 754 | 754 |
//// Setup |
| ... | ... |
@@ -807,7 +807,7 @@ void SPC_DSP::soft_reset() |
| 807 | 807 |
|
| 808 | 808 |
void SPC_DSP::load(const uint8_t regs[register_count]) |
| 809 | 809 |
{
|
| 810 |
- std::copy(®s[0], ®s[register_count], &this->m.regs[0]); |
|
| 810 |
+ std::copy_n(®s[0], static_cast<int>(register_count), &this->m.regs[0]); |
|
| 811 | 811 |
memset(&this->m.regs[register_count], 0, offsetof(state_t, ram) - register_count); |
| 812 | 812 |
|
| 813 | 813 |
// Internal state |
| ... | ... |
@@ -235,11 +235,10 @@ namespace spc |
| 235 | 235 |
|
| 236 | 236 |
static void EightBitize(uint8_t *buffer, int sample_count) |
| 237 | 237 |
{
|
| 238 |
- uint8_t *buf8 = buffer; |
|
| 239 | 238 |
int16_t *buf16 = reinterpret_cast<int16_t *>(buffer); |
| 240 | 239 |
|
| 241 | 240 |
for (int i = 0; i < sample_count; ++i) |
| 242 |
- buf8[i] = static_cast<uint8_t>((buf16[i] / 256) + 128); |
|
| 241 |
+ buffer[i] = static_cast<uint8_t>((buf16[i] / 256) + 128); |
|
| 243 | 242 |
} |
| 244 | 243 |
|
| 245 | 244 |
static void DeStereo(uint8_t *buffer, int sample_count) |
| ... | ... |
@@ -287,7 +286,7 @@ bool S9xMixSamples(uint8_t *buffer, int sample_count) |
| 287 | 286 |
|
| 288 | 287 |
if (Settings.Mute) |
| 289 | 288 |
{
|
| 290 |
- std::fill(&dest[0], &dest[sample_count << 1], 0); |
|
| 289 |
+ std::fill_n(&dest[0], sample_count << 1, 0); |
|
| 291 | 290 |
spc::resampler->clear(); |
| 292 | 291 |
|
| 293 | 292 |
return false; |
| ... | ... |
@@ -302,7 +301,7 @@ bool S9xMixSamples(uint8_t *buffer, int sample_count) |
| 302 | 301 |
} |
| 303 | 302 |
else |
| 304 | 303 |
{
|
| 305 |
- std::fill(&buffer[0], &buffer[(sample_count << (Settings.SixteenBitSound ? 1 : 0)) >> (Settings.Stereo ? 0 : 1)], Settings.SixteenBitSound ? 0 : 128); |
|
| 304 |
+ std::fill_n(&buffer[0], (sample_count << (Settings.SixteenBitSound ? 1 : 0)) >> (Settings.Stereo ? 0 : 1), Settings.SixteenBitSound ? 0 : 128); |
|
| 306 | 305 |
if (!spc::lag) |
| 307 | 306 |
spc::lag = spc::lag_master; |
| 308 | 307 |
|
| ... | ... |
@@ -324,7 +323,7 @@ bool S9xMixSamples(uint8_t *buffer, int sample_count) |
| 324 | 323 |
if (!Settings.SixteenBitSound) |
| 325 | 324 |
EightBitize(dest, sample_count); |
| 326 | 325 |
|
| 327 |
- std::copy(&dest[0], &dest[sample_count << (Settings.SixteenBitSound ? 1 : 0)], &buffer[0]); |
|
| 326 |
+ std::copy_n(&dest[0], sample_count << (Settings.SixteenBitSound ? 1 : 0), &buffer[0]); |
|
| 328 | 327 |
} |
| 329 | 328 |
|
| 330 | 329 |
return true; |
| ... | ... |
@@ -349,12 +348,7 @@ void S9xFinalizeSamples() |
| 349 | 348 |
} |
| 350 | 349 |
} |
| 351 | 350 |
|
| 352 |
- if (!Settings.SoundSync || Settings.TurboMode || Settings.Mute) |
|
| 353 |
- spc::sound_in_sync = true; |
|
| 354 |
- else if (spc::resampler->space_empty() >= spc::resampler->space_filled()) |
|
| 355 |
- spc::sound_in_sync = true; |
|
| 356 |
- else |
|
| 357 |
- spc::sound_in_sync = false; |
|
| 351 |
+ spc::sound_in_sync = !Settings.SoundSync || Settings.TurboMode || Settings.Mute || spc::resampler->space_empty() >= spc::resampler->space_filled(); |
|
| 358 | 352 |
|
| 359 | 353 |
spc_core->set_output(reinterpret_cast<SNES_SPC::sample_t *>(spc::landing_buffer.get()), spc::buffer_size >> 1); |
| 360 | 354 |
} |
| ... | ... |
@@ -19,9 +19,7 @@ public: |
| 19 | 19 |
{
|
| 20 | 20 |
this->buffer_size = buffer_size; |
| 21 | 21 |
this->buffer = new unsigned char[this->buffer_size]; |
| 22 |
- std::fill(&this->buffer[0], &this->buffer[this->buffer_size], 0); |
|
| 23 |
- |
|
| 24 |
- this->size = this->start = 0; |
|
| 22 |
+ this->clear(); |
|
| 25 | 23 |
} |
| 26 | 24 |
|
| 27 | 25 |
~ring_buffer() |
| ... | ... |
@@ -37,7 +35,7 @@ public: |
| 37 | 35 |
int end = (this->start + this->size) % this->buffer_size; |
| 38 | 36 |
int first_write_size = std::min(bytes, this->buffer_size - end); |
| 39 | 37 |
|
| 40 |
- std::copy(&src[0], &src[first_write_size], &this->buffer[end]); |
|
| 38 |
+ std::copy_n(&src[0], first_write_size, &this->buffer[end]); |
|
| 41 | 39 |
|
| 42 | 40 |
if (bytes > first_write_size) |
| 43 | 41 |
std::copy(&src[first_write_size], &src[bytes], &this->buffer[0]); |
| ... | ... |
@@ -60,7 +58,7 @@ public: |
| 60 | 58 |
void clear() |
| 61 | 59 |
{
|
| 62 | 60 |
this->start = this->size = 0; |
| 63 |
- std::fill(&this->buffer[0], &this->buffer[this->buffer_size], 0); |
|
| 61 |
+ std::fill_n(&this->buffer[0], this->buffer_size, 0); |
|
| 64 | 62 |
} |
| 65 | 63 |
|
| 66 | 64 |
void resize(int size) |
| ... | ... |
@@ -68,9 +66,7 @@ public: |
| 68 | 66 |
delete[] this->buffer; |
| 69 | 67 |
this->buffer_size = size; |
| 70 | 68 |
this->buffer = new unsigned char[this->buffer_size]; |
| 71 |
- std::fill(&this->buffer[0], &this->buffer[this->buffer_size], 0); |
|
| 72 |
- |
|
| 73 |
- this->size = this->start = 0; |
|
| 69 |
+ this->clear(); |
|
| 74 | 70 |
} |
| 75 | 71 |
}; |
| 76 | 72 |
|
| ... | ... |
@@ -81,8 +81,8 @@ public: |
| 81 | 81 |
{
|
| 82 | 82 |
ring_buffer::clear(); |
| 83 | 83 |
this->r_frac = 1.0; |
| 84 |
- std::fill(&this->r_left[0], &this->r_left[SINC_WIDTH * 2], 0); |
|
| 85 |
- std::fill(&this->r_right[0], &this->r_right[SINC_WIDTH * 2], 0); |
|
| 84 |
+ std::fill_n(&this->r_left[0], SINC_WIDTH * 2, 0); |
|
| 85 |
+ std::fill_n(&this->r_right[0], SINC_WIDTH * 2, 0); |
|
| 86 | 86 |
} |
| 87 | 87 |
|
| 88 | 88 |
void read(short *data, int num_samples) |
| ... | ... |
@@ -125,10 +125,10 @@ public: |
| 125 | 125 |
|
| 126 | 126 |
if (this->r_frac > 1.0) |
| 127 | 127 |
{
|
| 128 |
- std::copy(&this->r_left[1], &this->r_left[SINC_WIDTH * 2], &this->r_left[0]); |
|
| 128 |
+ std::copy_n(&this->r_left[1], SINC_WIDTH * 2 - 1, &this->r_left[0]); |
|
| 129 | 129 |
this->r_left[SINC_WIDTH * 2 - 1] = s_left; |
| 130 | 130 |
|
| 131 |
- std::copy(&this->r_right[1], &this->r_right[SINC_WIDTH * 2], &this->r_right[0]); |
|
| 131 |
+ std::copy_n(&this->r_right[1], SINC_WIDTH * 2 - 1, &this->r_right[0]); |
|
| 132 | 132 |
this->r_right[SINC_WIDTH * 2 - 1] = s_right; |
| 133 | 133 |
|
| 134 | 134 |
this->r_frac -= 1.0; |
| ... | ... |
@@ -218,10 +218,7 @@ static void S9xSoftResetCPU() |
| 218 | 218 |
Timings.H_Max = Timings.H_Max_Master; |
| 219 | 219 |
Timings.V_Max = Timings.V_Max_Master; |
| 220 | 220 |
Timings.NMITriggerPos = 0xffff; |
| 221 |
- if (Model->_5A22 == 2) |
|
| 222 |
- Timings.WRAMRefreshPos = SNES_WRAM_REFRESH_HC_v2; |
|
| 223 |
- else |
|
| 224 |
- Timings.WRAMRefreshPos = SNES_WRAM_REFRESH_HC_v1; |
|
| 221 |
+ Timings.WRAMRefreshPos = Model->_5A22 == 2 ? SNES_WRAM_REFRESH_HC_v2 : SNES_WRAM_REFRESH_HC_v1; |
|
| 225 | 222 |
|
| 226 | 223 |
S9xSetPCBase(Registers.PC.xPBPC); |
| 227 | 224 |
|
| ... | ... |
@@ -242,9 +239,9 @@ static void S9xResetCPU() |
| 242 | 239 |
|
| 243 | 240 |
void S9xReset() |
| 244 | 241 |
{
|
| 245 |
- std::fill(&Memory.RAM[0], &Memory.RAM[0x20000], 0x55); |
|
| 246 |
- std::fill(&Memory.VRAM[0], &Memory.VRAM[0x10000], 0); |
|
| 247 |
- std::fill(&Memory.FillRAM[0], &Memory.FillRAM[0x8000], 0); |
|
| 242 |
+ std::fill_n(&Memory.RAM[0], 0x20000, 0x55); |
|
| 243 |
+ std::fill_n(&Memory.VRAM[0], 0x10000, 0); |
|
| 244 |
+ std::fill_n(&Memory.FillRAM[0], 0x8000, 0); |
|
| 248 | 245 |
|
| 249 | 246 |
S9xResetCPU(); |
| 250 | 247 |
S9xResetPPU(); |
| ... | ... |
@@ -209,8 +209,7 @@ static inline bool addCyclesInDMA(uint8_t dma_channel) |
| 209 | 209 |
|
| 210 | 210 |
bool S9xDoDMA(uint8_t Channel) |
| 211 | 211 |
{
|
| 212 |
- CPU.InDMA = true; |
|
| 213 |
- CPU.InDMAorHDMA = true; |
|
| 212 |
+ CPU.InDMA = CPU.InDMAorHDMA = true; |
|
| 214 | 213 |
CPU.CurrentDMAorHDMAChannel = Channel; |
| 215 | 214 |
|
| 216 | 215 |
SDMA *d = &DMA[Channel]; |
| ... | ... |
@@ -325,9 +324,7 @@ bool S9xDoDMA(uint8_t Channel) |
| 325 | 324 |
p += inc; |
| 326 | 325 |
if (!addCyclesInDMA(Channel)) |
| 327 | 326 |
{
|
| 328 |
- CPU.InDMA = false; |
|
| 329 |
- CPU.InDMAorHDMA = false; |
|
| 330 |
- CPU.InWRAMDMAorHDMA = false; |
|
| 327 |
+ CPU.InDMA = CPU.InDMAorHDMA = CPU.InWRAMDMAorHDMA = false; |
|
| 331 | 328 |
CPU.CurrentDMAorHDMAChannel = -1; |
| 332 | 329 |
return false; |
| 333 | 330 |
} |
| ... | ... |
@@ -836,9 +833,7 @@ bool S9xDoDMA(uint8_t Channel) |
| 836 | 833 |
d->AAddress += inc; |
| 837 | 834 |
if (!addCyclesInDMA(Channel)) |
| 838 | 835 |
{
|
| 839 |
- CPU.InDMA = false; |
|
| 840 |
- CPU.InDMAorHDMA = false; |
|
| 841 |
- CPU.InWRAMDMAorHDMA = false; |
|
| 836 |
+ CPU.InDMA = CPU.InDMAorHDMA = CPU.InWRAMDMAorHDMA = false; |
|
| 842 | 837 |
CPU.CurrentDMAorHDMAChannel = -1; |
| 843 | 838 |
return false; |
| 844 | 839 |
} |
| ... | ... |
@@ -1148,8 +1143,7 @@ void S9xStartHDMA() |
| 1148 | 1143 |
|
| 1149 | 1144 |
PPU.HDMAEnded = 0; |
| 1150 | 1145 |
|
| 1151 |
- CPU.InHDMA = true; |
|
| 1152 |
- CPU.InDMAorHDMA = true; |
|
| 1146 |
+ CPU.InHDMA = CPU.InDMAorHDMA = true; |
|
| 1153 | 1147 |
int32_t tmpch = CPU.CurrentDMAorHDMAChannel; |
| 1154 | 1148 |
|
| 1155 | 1149 |
// XXX: Not quite right... |
| ... | ... |
@@ -1186,8 +1180,7 @@ uint8_t S9xDoHDMA(uint8_t byte) |
| 1186 | 1180 |
|
| 1187 | 1181 |
int d = 0; |
| 1188 | 1182 |
|
| 1189 |
- CPU.InHDMA = true; |
|
| 1190 |
- CPU.InDMAorHDMA = true; |
|
| 1183 |
+ CPU.InHDMA = CPU.InDMAorHDMA = true; |
|
| 1191 | 1184 |
CPU.HDMARanInDMA = CPU.InDMA ? byte : 0; |
| 1192 | 1185 |
bool temp = CPU.InWRAMDMAorHDMA; |
| 1193 | 1186 |
int32_t tmpch = CPU.CurrentDMAorHDMAChannel; |
| ... | ... |
@@ -270,10 +270,10 @@ bool CMemory::Init() |
| 270 | 270 |
return false; |
| 271 | 271 |
} |
| 272 | 272 |
|
| 273 |
- std::fill(&this->RAM[0], &this->RAM[0x20000], 0); |
|
| 274 |
- std::fill(&this->SRAM[0], &this->SRAM[0x20000], 0); |
|
| 275 |
- std::fill(&this->VRAM[0], &this->VRAM[0x10000], 0); |
|
| 276 |
- std::fill(&this->RealROM[0], &this->RealROM[MAX_ROM_SIZE + 0x200 + 0x8000], 0); |
|
| 273 |
+ std::fill_n(&this->RAM[0], 0x20000, 0); |
|
| 274 |
+ std::fill_n(&this->SRAM[0], 0x20000, 0); |
|
| 275 |
+ std::fill_n(&this->VRAM[0], 0x10000, 0); |
|
| 276 |
+ std::fill_n(&this->RealROM[0], MAX_ROM_SIZE + 0x200 + 0x8000, 0); |
|
| 277 | 277 |
|
| 278 | 278 |
// FillRAM uses first 32K of ROM image area, otherwise space just |
| 279 | 279 |
// wasted. Might be read by the SuperFX code. |
| ... | ... |
@@ -409,7 +409,7 @@ bool CMemory::LoadROMSNSF(const uint8_t *lrombuf, int32_t lromsize, const uint8_ |
| 409 | 409 |
{
|
| 410 | 410 |
int retry_count = 0; |
| 411 | 411 |
|
| 412 |
- std::fill(&this->ROM[0], &this->ROM[MAX_ROM_SIZE], 0); |
|
| 412 |
+ std::fill_n(&this->ROM[0], static_cast<int>(MAX_ROM_SIZE), 0); |
|
| 413 | 413 |
|
| 414 | 414 |
again: |
| 415 | 415 |
this->CalculatedSize = 0; |
| ... | ... |
@@ -418,18 +418,17 @@ again: |
| 418 | 418 |
int32_t totalFileSize = std::min<int32_t>(MAX_ROM_SIZE, lromsize); |
| 419 | 419 |
if (!totalFileSize) |
| 420 | 420 |
return false; |
| 421 |
- std::copy(&lrombuf[0], &lrombuf[totalFileSize], &this->ROM[0]); |
|
| 422 |
- SNESGameFixes.SRAMInitialValue = 0xff; |
|
| 423 |
- std::fill(&this->SRAM[0], &this->SRAM[0x20000], SNESGameFixes.SRAMInitialValue); |
|
| 421 |
+ std::copy_n(&lrombuf[0], totalFileSize, &this->ROM[0]); |
|
| 422 |
+ std::fill_n(&this->SRAM[0], 0x20000, 0xff); |
|
| 424 | 423 |
if (srambuf && sramsize) |
| 425 |
- std::copy(&srambuf[0], &srambuf[sramsize], &this->SRAM[0]); |
|
| 424 |
+ std::copy_n(&srambuf[0], sramsize, &this->SRAM[0]); |
|
| 426 | 425 |
|
| 427 | 426 |
int hi_score = this->ScoreHiROM(false); |
| 428 | 427 |
int lo_score = this->ScoreLoROM(false); |
| 429 | 428 |
|
| 430 | 429 |
if (((hi_score > lo_score && this->ScoreHiROM(true) > hi_score) || (hi_score <= lo_score && this->ScoreLoROM(true) > lo_score))) |
| 431 | 430 |
{
|
| 432 |
- memmove(&this->ROM[0], &this->ROM[512], totalFileSize - 512); |
|
| 431 |
+ std::copy_n(&this->ROM[512], totalFileSize - 512, &this->ROM[0]); |
|
| 433 | 432 |
totalFileSize -= 512; |
| 434 | 433 |
// modifying ROM, so we need to rescore |
| 435 | 434 |
hi_score = this->ScoreHiROM(false); |
| ... | ... |
@@ -486,7 +485,6 @@ again: |
| 486 | 485 |
|
| 487 | 486 |
// ignore map type byte if not 0x2x or 0x3x |
| 488 | 487 |
if ((RomHeader[0x7fd5] & 0xf0) == 0x20 || (RomHeader[0x7fd5] & 0xf0) == 0x30) |
| 489 |
- {
|
|
| 490 | 488 |
switch (RomHeader[0x7fd5] & 0xf) |
| 491 | 489 |
{
|
| 492 | 490 |
case 1: |
| ... | ... |
@@ -494,11 +492,8 @@ again: |
| 494 | 492 |
break; |
| 495 | 493 |
|
| 496 | 494 |
case 5: |
| 497 |
- interleaved = true; |
|
| 498 |
- tales = true; |
|
| 499 |
- break; |
|
| 495 |
+ interleaved = tales = true; |
|
| 500 | 496 |
} |
| 501 |
- } |
|
| 502 | 497 |
} |
| 503 | 498 |
else |
| 504 | 499 |
{
|
| ... | ... |
@@ -506,24 +501,19 @@ again: |
| 506 | 501 |
this->HiROM = true; |
| 507 | 502 |
|
| 508 | 503 |
if ((RomHeader[0xffd5] & 0xf0) == 0x20 || (RomHeader[0xffd5] & 0xf0) == 0x30) |
| 509 |
- {
|
|
| 510 | 504 |
switch (RomHeader[0xffd5] & 0xf) |
| 511 | 505 |
{
|
| 512 | 506 |
case 0: |
| 513 | 507 |
case 3: |
| 514 | 508 |
interleaved = true; |
| 515 |
- break; |
|
| 516 | 509 |
} |
| 517 |
- } |
|
| 518 | 510 |
} |
| 519 | 511 |
|
| 520 | 512 |
// this two games fail to be detected |
| 521 | 513 |
if (!strncmp(reinterpret_cast<char *>(&this->ROM[0x7fc0]), "YUYU NO QUIZ DE GO!GO!", 22) || !strncmp(reinterpret_cast<char *>(&this->ROM[0xffc0]), "BATMAN--REVENGE JOKER", 21)) |
| 522 | 514 |
{
|
| 523 | 515 |
this->LoROM = true; |
| 524 |
- this->HiROM = false; |
|
| 525 |
- interleaved = false; |
|
| 526 |
- tales = false; |
|
| 516 |
+ this->HiROM = interleaved = tales = false; |
|
| 527 | 517 |
} |
| 528 | 518 |
|
| 529 | 519 |
if (!Settings.ForceNotInterleaved && interleaved) |
| ... | ... |
@@ -567,13 +557,12 @@ again: |
| 567 | 557 |
if (tales) |
| 568 | 558 |
{
|
| 569 | 559 |
auto tmp = std::vector<uint8_t>(this->CalculatedSize - 0x400000); |
| 570 |
- memmove(&tmp[0], &this->ROM[0], this->CalculatedSize - 0x400000); |
|
| 571 |
- memmove(&this->ROM[0], &this->ROM[this->CalculatedSize - 0x400000], 0x400000); |
|
| 572 |
- memmove(&this->ROM[0x400000], &tmp[0], this->CalculatedSize - 0x400000); |
|
| 560 |
+ std::copy_n(&this->ROM[0], this->CalculatedSize - 0x400000, &tmp[0]); |
|
| 561 |
+ std::copy_n(&this->ROM[this->CalculatedSize - 0x400000], 0x400000, &this->ROM[0]); |
|
| 562 |
+ std::copy_n(&tmp[0], this->CalculatedSize - 0x400000, &this->ROM[0x400000]); |
|
| 573 | 563 |
} |
| 574 | 564 |
|
| 575 | 565 |
memset(&SNESGameFixes, 0, sizeof(SNESGameFixes)); |
| 576 |
- SNESGameFixes.SRAMInitialValue = 0x60; |
|
| 577 | 566 |
|
| 578 | 567 |
this->InitROM(); |
| 579 | 568 |
|
| ... | ... |
@@ -626,14 +615,14 @@ void CMemory::ParseSNESHeader(uint8_t *RomHeader) |
| 626 | 615 |
this->ROMType = RomHeader[0x26]; |
| 627 | 616 |
this->ROMRegion = RomHeader[0x29]; |
| 628 | 617 |
|
| 629 |
- std::copy(&RomHeader[0x02], &RomHeader[0x06], &this->ROMId[0]); |
|
| 618 |
+ std::copy_n(&RomHeader[0x02], 4, &this->ROMId[0]); |
|
| 630 | 619 |
} |
| 631 | 620 |
|
| 632 | 621 |
void CMemory::InitROM() |
| 633 | 622 |
{
|
| 634 | 623 |
//// Parse ROM header and read ROM informatoin |
| 635 | 624 |
|
| 636 |
- std::fill(&this->ROMId[0], &this->ROMId[5], 0); |
|
| 625 |
+ std::fill_n(&this->ROMId[0], 5, 0); |
|
| 637 | 626 |
|
| 638 | 627 |
uint8_t *RomHeader = &this->ROM[0x7FB0]; |
| 639 | 628 |
if (this->ExtendedFormat == BIGFIRST) |
| ... | ... |
@@ -817,7 +806,6 @@ void CMemory::map_space(uint32_t bank_s, uint32_t bank_e, uint32_t addr_s, uint3 |
| 817 | 806 |
|
| 818 | 807 |
void CMemory::map_index(uint32_t bank_s, uint32_t bank_e, uint32_t addr_s, uint32_t addr_e, int index, int type) |
| 819 | 808 |
{
|
| 820 |
- bool isROM = !(type == MAP_TYPE_I_O || type == MAP_TYPE_RAM); |
|
| 821 | 809 |
bool isRAM = type != MAP_TYPE_I_O; |
| 822 | 810 |
|
| 823 | 811 |
for (uint32_t c = bank_s; c <= bank_e; ++c) |
| ... | ... |
@@ -825,7 +813,7 @@ void CMemory::map_index(uint32_t bank_s, uint32_t bank_e, uint32_t addr_s, uint3 |
| 825 | 813 |
{
|
| 826 | 814 |
uint32_t p = (c << 4) | (i >> 12); |
| 827 | 815 |
this->Map[p] = reinterpret_cast<uint8_t *>(index); |
| 828 |
- this->BlockIsROM[p] = isROM; |
|
| 816 |
+ this->BlockIsROM[p] = false; |
|
| 829 | 817 |
this->BlockIsRAM[p] = isRAM; |
| 830 | 818 |
} |
| 831 | 819 |
} |
| ... | ... |
@@ -862,7 +850,7 @@ void CMemory::map_HiROMSRAM() |
| 862 | 850 |
|
| 863 | 851 |
void CMemory::map_WriteProtectROM() |
| 864 | 852 |
{
|
| 865 |
- std::copy(&this->Map[0], &this->Map[0x1000], &this->WriteMap[0]); |
|
| 853 |
+ std::copy_n(&this->Map[0], 0x1000, &this->WriteMap[0]); |
|
| 866 | 854 |
|
| 867 | 855 |
for (int c = 0; c < 0x1000; ++c) |
| 868 | 856 |
if (this->BlockIsROM[c]) |
| ... | ... |
@@ -1119,17 +1107,6 @@ void CMemory::ApplyROMFixes() |
| 1119 | 1107 |
SRAMMask = ((1 << (SRAMSize + 3)) * 128) - 1; |
| 1120 | 1108 |
} |
| 1121 | 1109 |
|
| 1122 |
- // SRAM value fixes |
|
| 1123 |
- if (this->match_na("SUPER DRIFT OUT") || // Super Drift Out
|
|
| 1124 |
- this->match_na("SATAN IS OUR FATHER!") ||
|
|
| 1125 |
- this->match_na("goemon 4")) // Ganbare Goemon Kirakira Douchuu
|
|
| 1126 |
- SNESGameFixes.SRAMInitialValue = 0x00; |
|
| 1127 |
- |
|
| 1128 |
- // Additional game fixes by sanmaiwashi ... |
|
| 1129 |
- // XXX: unnecessary? |
|
| 1130 |
- if (this->match_na("SFX \xC5\xB2\xC4\xB6\xDE\xDD\xC0\xDE\xD1\xD3\xC9\xB6\xDE\xC0\xD8 1")) // SD Gundam Gaiden - Knight Gundam Monogatari
|
|
| 1131 |
- SNESGameFixes.SRAMInitialValue = 0x6b; |
|
| 1132 |
- |
|
| 1133 | 1110 |
// others: BS and ST-01x games are 0x00. |
| 1134 | 1111 |
|
| 1135 | 1112 |
//// OAM hacks :( |
| ... | ... |
@@ -229,15 +229,11 @@ void S9xSetPPU(uint8_t Byte, uint16_t Address) |
| 229 | 229 |
// write_port will run the APU until given clock before writing value |
| 230 | 230 |
S9xAPUWritePort(Address & 3, Byte); |
| 231 | 231 |
else if (Address <= 0x2183) |
| 232 |
- {
|
|
| 233 | 232 |
switch (Address) |
| 234 | 233 |
{
|
| 235 | 234 |
case 0x2100: // INIDISP |
| 236 |
- if (Byte != Memory.FillRAM[0x2100]) |
|
| 237 |
- {
|
|
| 238 |
- if ((Memory.FillRAM[0x2100] & 0x80) != (Byte & 0x80)) |
|
| 239 |
- PPU.ForcedBlanking = !!((Byte >> 7) & 1); |
|
| 240 |
- } |
|
| 235 |
+ if (Byte != Memory.FillRAM[0x2100] && (Memory.FillRAM[0x2100] & 0x80) != (Byte & 0x80)) |
|
| 236 |
+ PPU.ForcedBlanking = !!((Byte >> 7) & 1); |
|
| 241 | 237 |
|
| 242 | 238 |
if ((Memory.FillRAM[0x2100] & 0x80) && CPU.V_Counter == PPU.ScreenHeight + FIRST_VISIBLE_LINE) |
| 243 | 239 |
{
|
| ... | ... |
@@ -434,10 +430,7 @@ void S9xSetPPU(uint8_t Byte, uint16_t Address) |
| 434 | 430 |
PPU.WRAM |= Byte << 16; |
| 435 | 431 |
PPU.WRAM &= 0x1ffff; |
| 436 | 432 |
} |
| 437 |
- |
|
| 438 |
- break; |
|
| 439 | 433 |
} |
| 440 |
- } |
|
| 441 | 434 |
|
| 442 | 435 |
Memory.FillRAM[Address] = Byte; |
| 443 | 436 |
} |
| ... | ... |
@@ -658,7 +651,7 @@ void S9xSetCPU(uint8_t Byte, uint16_t Address) |
| 658 | 651 |
DMA[d].UnusedBit43x0 = !!(Byte & 0x20); |
| 659 | 652 |
DMA[d].AAddressDecrement = !!(Byte & 0x10); |
| 660 | 653 |
DMA[d].AAddressFixed = !!(Byte & 0x08); |
| 661 |
- DMA[d].TransferMode = (Byte & 7); |
|
| 654 |
+ DMA[d].TransferMode = Byte & 7; |
|
| 662 | 655 |
return; |
| 663 | 656 |
|
| 664 | 657 |
case 0x1: // 0x43x1: BBADx |
| ... | ... |
@@ -775,9 +768,9 @@ void S9xSetCPU(uint8_t Byte, uint16_t Address) |
| 775 | 768 |
uint16_t div = Byte ? a / Byte : 0xffff; |
| 776 | 769 |
uint16_t rem = Byte ? a % Byte : a; |
| 777 | 770 |
// FIXME: The update occurs 16 machine cycles after $4206 is set. |
| 778 |
- Memory.FillRAM[0x4214] = static_cast<uint8_t>(div); |
|
| 771 |
+ Memory.FillRAM[0x4214] = div & 0xff; |
|
| 779 | 772 |
Memory.FillRAM[0x4215] = div >> 8; |
| 780 |
- Memory.FillRAM[0x4216] = static_cast<uint8_t>(rem); |
|
| 773 |
+ Memory.FillRAM[0x4216] = rem & 0xff; |
|
| 781 | 774 |
Memory.FillRAM[0x4217] = rem >> 8; |
| 782 | 775 |
break; |
| 783 | 776 |
} |
| ... | ... |
@@ -844,12 +837,7 @@ void S9xSetCPU(uint8_t Byte, uint16_t Address) |
| 844 | 837 |
|
| 845 | 838 |
case 0x420d: // MEMSEL |
| 846 | 839 |
if ((Byte & 1) != (Memory.FillRAM[0x420d] & 1)) |
| 847 |
- {
|
|
| 848 |
- if (Byte & 1) |
|
| 849 |
- CPU.FastROMSpeed = ONE_CYCLE; |
|
| 850 |
- else |
|
| 851 |
- CPU.FastROMSpeed = SLOW_ONE_CYCLE; |
|
| 852 |
- } |
|
| 840 |
+ CPU.FastROMSpeed = Byte & 1 ? ONE_CYCLE : SLOW_ONE_CYCLE; |
|
| 853 | 841 |
|
| 854 | 842 |
break; |
| 855 | 843 |
|
| ... | ... |
@@ -948,8 +936,7 @@ uint8_t S9xGetCPU(uint16_t Address) |
| 948 | 936 |
|
| 949 | 937 |
case 0x4211: // TIMEUP |
| 950 | 938 |
byte = CPU.IRQLine ? 0x80 : 0; |
| 951 |
- CPU.IRQLine = false; |
|
| 952 |
- CPU.IRQTransition = false; |
|
| 939 |
+ CPU.IRQLine = CPU.IRQTransition = false; |
|
| 953 | 940 |
return byte | (OpenBus & 0x7f); |
| 954 | 941 |
|
| 955 | 942 |
case 0x4212: // HVBJOY |
| ... | ... |
@@ -1011,7 +998,7 @@ void S9xSoftResetPPU() |
| 1011 | 998 |
PPU.OAMPriorityRotation = false; |
| 1012 | 999 |
PPU.OAMFlip = 0; |
| 1013 | 1000 |
PPU.OAMWriteRegister = 0; |
| 1014 |
- std::fill(&PPU.OAMData[0], &PPU.OAMData[512 + 32], 0); |
|
| 1001 |
+ std::fill_n(&PPU.OAMData[0], sizeof(PPU.OAMData), 0); |
|
| 1015 | 1002 |
|
| 1016 | 1003 |
PPU.FirstSprite = 0; |
| 1017 | 1004 |
|
| ... | ... |
@@ -1038,12 +1025,12 @@ void S9xSoftResetPPU() |
| 1038 | 1025 |
IPPU.Interlace = false; |
| 1039 | 1026 |
|
| 1040 | 1027 |
for (int c = 0; c < 0x8000; c += 0x100) |
| 1041 |
- std::fill(&Memory.FillRAM[c], &Memory.FillRAM[c + 0x100], c >> 8); |
|
| 1042 |
- std::fill(&Memory.FillRAM[0x2100], &Memory.FillRAM[0x2200], 0); |
|
| 1043 |
- std::fill(&Memory.FillRAM[0x4200], &Memory.FillRAM[0x4300], 0); |
|
| 1044 |
- std::fill(&Memory.FillRAM[0x4000], &Memory.FillRAM[0x4100], 0); |
|
| 1028 |
+ std::fill_n(&Memory.FillRAM[c], 0x100, c >> 8); |
|
| 1029 |
+ std::fill_n(&Memory.FillRAM[0x2100], 0x0100, 0); |
|
| 1030 |
+ std::fill_n(&Memory.FillRAM[0x4200], 0x0100, 0); |
|
| 1031 |
+ std::fill_n(&Memory.FillRAM[0x4000], 0x0100, 0); |
|
| 1045 | 1032 |
// For BS Suttehakkun 2... |
| 1046 |
- std::fill(&Memory.FillRAM[0x1000], &Memory.FillRAM[0x2000], 0); |
|
| 1033 |
+ std::fill_n(&Memory.FillRAM[0x1000], 0x1000, 0); |
|
| 1047 | 1034 |
|
| 1048 | 1035 |
Memory.FillRAM[0x4201] = Memory.FillRAM[0x4213] = 0xff; |
| 1049 | 1036 |
} |
| ... | ... |
@@ -178,7 +178,6 @@ |
| 178 | 178 |
#include <algorithm> |
| 179 | 179 |
#include "snes9x.h" |
| 180 | 180 |
#include "memmap.h" |
| 181 |
-#include "sdd1.h" |
|
| 182 | 181 |
|
| 183 | 182 |
void S9xSetSDD1MemoryMap(uint32_t bank, uint32_t value) |
| 184 | 183 |
{
|
| ... | ... |
@@ -188,17 +187,13 @@ void S9xSetSDD1MemoryMap(uint32_t bank, uint32_t value) |
| 188 | 187 |
for (int c = 0; c < 0x100; c += 16) |
| 189 | 188 |
{
|
| 190 | 189 |
uint8_t *block = &Memory.ROM[value + (c << 12)]; |
| 191 |
- for (int i = c; i < c + 16; ++i) |
|
| 192 |
- Memory.Map[i + bank] = block; |
|
| 190 |
+ std::fill_n(&Memory.Map[bank + c], 16, block); |
|
| 193 | 191 |
} |
| 194 | 192 |
} |
| 195 | 193 |
|
| 196 | 194 |
void S9xResetSDD1() |
| 197 | 195 |
{
|
| 198 |
- std::fill(&Memory.FillRAM[0x4800], &Memory.FillRAM[0x4804], 0); |
|
| 199 |
- for (int i = 0; i < 4; ++i) |
|
| 200 |
- {
|
|
| 201 |
- Memory.FillRAM[0x4804 + i] = i; |
|
| 202 |
- S9xSetSDD1MemoryMap(i, i); |
|
| 203 |
- } |
|
| 196 |
+ std::fill_n(&Memory.FillRAM[0x4800], 4, 0); |
|
| 197 |
+ int i = 0; |
|
| 198 |
+ std::generate_n(&Memory.FillRAM[0x4804], 4, [&]() -> int { S9xSetSDD1MemoryMap(i, i); return i++; });
|
|
| 204 | 199 |
} |