srctree

Robin Linden parent dd623b4b 9a7ba84b
Make sure our lambda captures work in both C++20 and C++17

In C++20 lambdas capturing by value stopped capturing `this`, requiring you to capture it like `[=, this]` while in C++17 and earlier, explicitly capturing `this` like `[=, this]` is an error, so I made all lambda captures explicitly state what they want to capture.
core/src/membank_factory.cpp added: 128, removed: 146, total 0
@@ -9,11 +9,11 @@ namespace n_e_s::core {
namespace {
 
auto create_ppu_reader(IPpu *ppu) {
return [=](uint16_t addr) { return ppu->read_byte(addr); };
return [ppu](uint16_t addr) { return ppu->read_byte(addr); };
}
 
auto create_ppu_writer(IPpu *ppu) {
return [=](uint16_t addr, uint8_t byte) { ppu->write_byte(addr, byte); };
return [ppu](uint16_t addr, uint8_t byte) { ppu->write_byte(addr, byte); };
}
 
} // namespace
 
core/src/mmu.cpp added: 128, removed: 146, total 0
@@ -9,7 +9,7 @@ namespace n_e_s::core {
namespace {
 
auto equal(uint16_t addr) {
return [=](const std::unique_ptr<IMemBank> &mem_bank) {
return [addr](const std::unique_ptr<IMemBank> &mem_bank) {
return mem_bank->is_address_in_range(addr);
};
}
 
core/src/mos6502.cpp added: 128, removed: 146, total 0
@@ -98,19 +98,19 @@ Pipeline Mos6502::parse_next_instruction() {
Pipeline result;
switch (state_.current_opcode->instruction) {
case Instruction::BrkImplied:
result.push([=]() {
result.push([this]() {
// Dummy read
mmu_->read_byte(registers_->pc++);
});
result.push([=]() {
result.push([this]() {
stack_.push_byte(static_cast<uint8_t>(registers_->pc >> 8u));
});
result.push([=]() {
result.push([this]() {
stack_.push_byte(static_cast<uint8_t>(registers_->pc & 0xFFu));
});
result.push([=]() { stack_.push_byte(registers_->p | B_FLAG); });
result.push([=]() { tmp_ = mmu_->read_byte(kBrkAddress); });
result.push([=]() {
result.push([this]() { stack_.push_byte(registers_->p | B_FLAG); });
result.push([this]() { tmp_ = mmu_->read_byte(kBrkAddress); });
result.push([this]() {
const uint16_t pch = mmu_->read_byte(kBrkAddress + 1) << 8u;
registers_->pc = pch | tmp_;
});
@@ -124,21 +124,19 @@ Pipeline Mos6502::parse_next_instruction() {
create_left_shift_instruction(*state_.current_opcode, false));
break;
case Instruction::PhpImplied:
result.push([=]() {
/* Do nothing. */
});
result.push([=]() { stack_.push_byte(registers_->p | B_FLAG); });
result.push([]() { /* Do nothing. */ });
result.push([this]() { stack_.push_byte(registers_->p | B_FLAG); });
break;
case Instruction::BplRelative:
result.append(create_branch_instruction(
[=]() { return !(registers_->p & N_FLAG); }));
[this]() { return !(registers_->p & N_FLAG); }));
break;
case Instruction::BitZeropage:
case Instruction::BitAbsolute:
result.append(create_addressing_steps(
state_.current_opcode->address_mode, memory_access));
 
result.push([=]() {
result.push([this]() {
const uint8_t value = mmu_->read_byte(effective_address_);
set_zero(value & registers_->a);
set_negative(value);
@@ -150,13 +148,9 @@ Pipeline Mos6502::parse_next_instruction() {
});
break;
case Instruction::PlpImplied:
result.push([=]() {
/* Do nothing. */
});
result.push([=]() {
/* Do nothing. */
});
result.push([=]() {
result.push([]() { /* Do nothing. */ });
result.push([]() { /* Do nothing. */ });
result.push([this]() {
registers_->p = stack_.pop_byte();
set_flag(FLAG_5);
clear_flag(B_FLAG);
@@ -173,32 +167,30 @@ Pipeline Mos6502::parse_next_instruction() {
result.append(create_and_instruction(*state_.current_opcode));
break;
case Instruction::ClcImplied:
result.push([=]() { clear_flag(C_FLAG); });
result.push([this]() { clear_flag(C_FLAG); });
break;
case Instruction::JsrAbsolute:
result.push([=]() { tmp_ = mmu_->read_byte(registers_->pc++); });
result.push([=]() {
/* Internal operation. Do nothing. */
});
result.push([=]() {
result.push([this]() { tmp_ = mmu_->read_byte(registers_->pc++); });
result.push([]() { /* Do nothing. */ });
result.push([this]() {
const auto pch = static_cast<uint8_t>(registers_->pc >> 8u);
stack_.push_byte(pch);
});
result.push([=]() {
result.push([this]() {
const auto pcl = static_cast<uint8_t>(registers_->pc);
stack_.push_byte(pcl);
});
result.push([=]() {
result.push([this]() {
const uint16_t pch = mmu_->read_byte(registers_->pc) << 8u;
registers_->pc = pch | tmp_;
});
break;
case Instruction::BmiRelative:
result.append(create_branch_instruction(
[=]() { return registers_->p & N_FLAG; }));
[this]() { return registers_->p & N_FLAG; }));
break;
case Instruction::SecImplied:
result.push([=]() { set_flag(C_FLAG); });
result.push([this]() { set_flag(C_FLAG); });
break;
case Instruction::LsrZeropage:
case Instruction::LsrAbsolute:
@@ -209,27 +201,25 @@ Pipeline Mos6502::parse_next_instruction() {
create_right_shift_instruction(*state_.current_opcode, false));
break;
case Instruction::PhaImplied:
result.push([=]() {
/* Do nothing. */
});
result.push([=]() { stack_.push_byte(registers_->a); });
result.push([]() { /* Do nothing. */ });
result.push([this]() { stack_.push_byte(registers_->a); });
break;
case Instruction::JmpAbsolute:
result.push([=]() { tmp_ = mmu_->read_byte(registers_->pc++); });
result.push([=]() {
result.push([this]() { tmp_ = mmu_->read_byte(registers_->pc++); });
result.push([this]() {
const uint16_t pch = mmu_->read_byte(registers_->pc) << 8u;
registers_->pc = pch | tmp_;
});
break;
case Instruction::JmpIndirect:
result.push([=]() { tmp_ = mmu_->read_byte(registers_->pc++); });
result.push([=]() { tmp2_ = mmu_->read_byte(registers_->pc++); });
result.push([=]() {
result.push([this]() { tmp_ = mmu_->read_byte(registers_->pc++); });
result.push([this]() { tmp2_ = mmu_->read_byte(registers_->pc++); });
result.push([this]() {
const uint16_t ptraddress =
static_cast<uint16_t>(tmp2_ << 8u) | tmp_;
effective_address_ = mmu_->read_byte(ptraddress);
});
result.push([=]() {
result.push([this]() {
// The PCH will always be fetched from the same page
// as PCL, i.e. page boundary crossing is not handled.
const uint8_t low_address = tmp_ + 1u;
@@ -241,10 +231,10 @@ Pipeline Mos6502::parse_next_instruction() {
break;
case Instruction::BvcRelative:
result.append(create_branch_instruction(
[=]() { return !(registers_->p & V_FLAG); }));
[this]() { return !(registers_->p & V_FLAG); }));
break;
case Instruction::CliImplied:
result.push([=]() { clear_flag(I_FLAG); });
result.push([this]() { clear_flag(I_FLAG); });
break;
case Instruction::AdcZeropage:
case Instruction::AdcZeropageX:
@@ -268,58 +258,50 @@ Pipeline Mos6502::parse_next_instruction() {
result.append(create_sub_instruction(*state_.current_opcode));
break;
case Instruction::PlaImplied:
result.push([=]() {
/* Do nothing. */
});
result.push([=]() {
/* Do nothing. */
});
result.push([=]() {
result.push([]() { /* Do nothing. */ });
result.push([]() { /* Do nothing. */ });
result.push([this]() {
registers_->a = stack_.pop_byte();
set_zero(registers_->a);
set_negative(registers_->a);
});
break;
case Instruction::RtsImplied:
result.push([=]() {
result.push([this]() {
// Dummy read
mmu_->read_byte(registers_->pc);
});
result.push([=]() {
/* Do nothing. */
});
result.push([=]() { tmp_ = stack_.pop_byte(); });
result.push([=]() {
result.push([]() { /* Do nothing. */ });
result.push([this]() { tmp_ = stack_.pop_byte(); });
result.push([this]() {
const uint16_t pch = stack_.pop_byte() << 8u;
registers_->pc = pch | tmp_;
});
result.push([=]() { ++registers_->pc; });
result.push([this]() { ++registers_->pc; });
break;
case Instruction::RtiImplied:
result.push([=]() {
result.push([this]() {
// Dummy read
mmu_->read_byte(registers_->pc);
});
result.push([=]() {
/* Do nothing. */
});
result.push([=]() {
result.push([]() { /* Do nothing. */ });
result.push([this]() {
registers_->p = stack_.pop_byte();
set_flag(FLAG_5);
clear_flag(B_FLAG);
});
result.push([=]() { tmp_ = stack_.pop_byte(); });
result.push([=]() {
result.push([this]() { tmp_ = stack_.pop_byte(); });
result.push([this]() {
const uint16_t pch = stack_.pop_byte() << 8u;
registers_->pc = pch | tmp_;
});
break;
case Instruction::BvsRelative:
result.append(create_branch_instruction(
[=]() { return registers_->p & V_FLAG; }));
[this]() { return registers_->p & V_FLAG; }));
break;
case Instruction::SeiImplied:
result.push([=]() { set_flag(I_FLAG); });
result.push([this]() { set_flag(I_FLAG); });
break;
case Instruction::StaIndexedIndirect:
case Instruction::StaZeropage:
@@ -341,38 +323,38 @@ Pipeline Mos6502::parse_next_instruction() {
result.append(create_store_instruction(*state_.current_opcode));
break;
case Instruction::TxsImplied:
result.push([=]() { registers_->sp = registers_->x; });
result.push([this]() { registers_->sp = registers_->x; });
break;
case Instruction::TyaImplied:
result.push([=]() {
result.push([this]() {
registers_->a = registers_->y;
set_zero(registers_->a);
set_negative(registers_->a);
});
break;
case Instruction::TayImplied:
result.push([=]() {
result.push([this]() {
registers_->y = registers_->a;
set_zero(registers_->y);
set_negative(registers_->y);
});
break;
case Instruction::TaxImplied:
result.push([=]() {
result.push([this]() {
registers_->x = registers_->a;
set_zero(registers_->x);
set_negative(registers_->x);
});
break;
case Instruction::TsxImplied:
result.push([=]() {
result.push([this]() {
registers_->x = registers_->sp;
set_zero(registers_->x);
set_negative(registers_->x);
});
break;
case Instruction::TxaImplied:
result.push([=]() {
result.push([this]() {
registers_->a = registers_->x;
set_zero(registers_->a);
set_negative(registers_->a);
@@ -380,7 +362,7 @@ Pipeline Mos6502::parse_next_instruction() {
break;
case Instruction::BccRelative:
result.append(create_branch_instruction(
[=]() { return !(registers_->p & C_FLAG); }));
[this]() { return !(registers_->p & C_FLAG); }));
break;
case Instruction::LdaZeropage:
case Instruction::LdaImmediate:
@@ -404,17 +386,17 @@ Pipeline Mos6502::parse_next_instruction() {
break;
case Instruction::BcsRelative:
result.append(create_branch_instruction(
[=]() { return registers_->p & C_FLAG; }));
[this]() { return registers_->p & C_FLAG; }));
break;
case Instruction::ClvImplied:
result.push([=]() { clear_flag(V_FLAG); });
result.push([this]() { clear_flag(V_FLAG); });
break;
case Instruction::BneRelative:
result.append(create_branch_instruction(
[=]() { return !(registers_->p & Z_FLAG); }));
[this]() { return !(registers_->p & Z_FLAG); }));
break;
case Instruction::CldImplied:
result.push([=]() { clear_flag(D_FLAG); });
result.push([this]() { clear_flag(D_FLAG); });
break;
case Instruction::CpxImmediate:
case Instruction::CpxZeropage:
@@ -473,28 +455,28 @@ Pipeline Mos6502::parse_next_instruction() {
result.append(create_dec_instruction(*state_.current_opcode));
break;
case Instruction::InxImplied:
result.push([=]() {
result.push([this]() {
++registers_->x;
set_zero(registers_->x);
set_negative(registers_->x);
});
break;
case Instruction::DexImplied:
result.push([=]() {
result.push([this]() {
--registers_->x;
set_zero(registers_->x);
set_negative(registers_->x);
});
break;
case Instruction::InyImplied:
result.push([=]() {
result.push([this]() {
++registers_->y;
set_zero(registers_->y);
set_negative(registers_->y);
});
break;
case Instruction::DeyImplied:
result.push([=]() {
result.push([this]() {
--registers_->y;
set_zero(registers_->y);
set_negative(registers_->y);
@@ -502,10 +484,10 @@ Pipeline Mos6502::parse_next_instruction() {
break;
case Instruction::BeqRelative:
result.append(create_branch_instruction(
[=]() { return registers_->p & Z_FLAG; }));
[this]() { return registers_->p & Z_FLAG; }));
break;
case Instruction::SedImplied:
result.push([=]() { set_flag(D_FLAG); });
result.push([this]() { set_flag(D_FLAG); });
break;
case Instruction::EorIndirectX:
case Instruction::EorZeropage:
@@ -632,19 +614,19 @@ Pipeline Mos6502::create_nmi() {
mmu_->read_byte(registers_->pc);
Pipeline result;
 
result.push([=]() {
result.push([this]() {
// Dummy read
mmu_->read_byte(registers_->pc);
});
result.push([=]() {
result.push([this]() {
stack_.push_byte(static_cast<uint8_t>(registers_->pc >> 8u));
});
result.push([=]() {
result.push([this]() {
stack_.push_byte(static_cast<uint8_t>(registers_->pc & 0xFFu));
});
result.push([=]() { stack_.push_byte(registers_->p); });
result.push([=]() { tmp_ = mmu_->read_byte(0xFFFA); });
result.push([=]() {
result.push([this]() { stack_.push_byte(registers_->p); });
result.push([this]() { tmp_ = mmu_->read_byte(0xFFFA); });
result.push([this]() {
const uint16_t pch = mmu_->read_byte(0xFFFB) << 8u;
registers_->pc = pch | tmp_;
});
@@ -656,7 +638,7 @@ Pipeline Mos6502::create_branch_instruction(
const std::function<bool()> &condition) {
Pipeline result;
 
result.push_conditional([=]() {
result.push_conditional([this, condition]() {
if (!condition()) {
++registers_->pc;
return StepResult::Stop;
@@ -664,7 +646,7 @@ Pipeline Mos6502::create_branch_instruction(
return StepResult::Continue;
});
 
result.push_conditional([=]() {
result.push_conditional([this]() {
const uint8_t offset = mmu_->read_byte(registers_->pc++);
const uint16_t page = high_byte(registers_->pc);
 
@@ -677,7 +659,7 @@ Pipeline Mos6502::create_branch_instruction(
return StepResult::Stop;
});
 
result.push([=]() { /* Do nothing. */ });
result.push([]() { /* Do nothing. */ });
 
return result;
}
@@ -687,7 +669,7 @@ Pipeline Mos6502::create_inc_instruction(const Opcode opcode) {
Pipeline result;
result.append(create_addressing_steps(opcode.address_mode, memory_access));
 
result.push([=]() {
result.push([this]() {
const uint8_t new_value = tmp_ + static_cast<uint8_t>(1);
set_zero(new_value);
set_negative(new_value);
@@ -702,7 +684,7 @@ Pipeline Mos6502::create_dec_instruction(const Opcode opcode) {
Pipeline result;
result.append(create_addressing_steps(opcode.address_mode, memory_access));
 
result.push([=]() {
result.push([this]() {
const uint8_t new_value = tmp_ - static_cast<uint8_t>(1);
set_zero(new_value);
set_negative(new_value);
@@ -730,7 +712,7 @@ Pipeline Mos6502::create_add_instruction(Opcode opcode) {
Pipeline result;
result.append(create_addressing_steps(opcode.address_mode, memory_access));
 
result.push([=]() {
result.push([this]() {
const uint8_t addend = mmu_->read_byte(effective_address_);
adc_impl(addend);
});
@@ -743,7 +725,7 @@ Pipeline Mos6502::create_sub_instruction(Opcode opcode) {
Pipeline result;
result.append(create_addressing_steps(opcode.address_mode, memory_access));
 
result.push([=]() {
result.push([this]() {
// SBC simply takes the ones complement of the second value and then
// performs an ADC See:
// http://www.righto.com/2012/12/the-6502-overflow-flag-explained.html
@@ -759,7 +741,7 @@ Pipeline Mos6502::create_and_instruction(Opcode opcode) {
Pipeline result;
result.append(create_addressing_steps(opcode.address_mode, memory_access));
 
result.push([=]() {
result.push([this]() {
const uint8_t operand = mmu_->read_byte(effective_address_);
registers_->a &= operand;
 
@@ -786,7 +768,7 @@ Pipeline Mos6502::create_store_instruction(Opcode opcode) {
reg = &registers_->a;
reg2 = &registers_->x;
}
result.push([=]() {
result.push([this, reg, reg2]() {
const uint8_t value = reg2 == nullptr ? *reg : *reg & *reg2;
mmu_->write_byte(effective_address_, value);
});
@@ -812,7 +794,7 @@ Pipeline Mos6502::create_load_instruction(Opcode opcode) {
Pipeline result;
result.append(create_addressing_steps(opcode.address_mode, memory_access));
 
result.push([=]() {
result.push([this, reg, reg2]() {
const uint8_t value = mmu_->read_byte(effective_address_);
*reg = value;
set_zero(value);
@@ -838,7 +820,7 @@ Pipeline Mos6502::create_compare_instruction(Opcode opcode) {
const MemoryAccess memory_access = get_memory_access(opcode.family);
Pipeline result;
result.append(create_addressing_steps(opcode.address_mode, memory_access));
result.push([=]() {
result.push([this, reg]() {
const uint8_t value = mmu_->read_byte(effective_address_);
// Compare instructions are not affected be the
// carry flag when executing the subtraction.
@@ -854,7 +836,7 @@ Pipeline Mos6502::create_dcp_instruction(Opcode opcode) {
const MemoryAccess memory_access = get_memory_access(opcode.family);
Pipeline result;
result.append(create_addressing_steps(opcode.address_mode, memory_access));
result.push([=]() {
result.push([this]() {
// DEC
const uint8_t new_value = tmp_ - static_cast<uint8_t>(1);
mmu_->write_byte(effective_address_, new_value);
@@ -875,7 +857,7 @@ Pipeline Mos6502::create_eor_instruction(Opcode opcode) {
Pipeline result;
result.append(create_addressing_steps(opcode.address_mode, memory_access));
 
result.push([=]() {
result.push([this]() {
const uint8_t operand = mmu_->read_byte(effective_address_);
registers_->a ^= operand;
 
@@ -891,7 +873,7 @@ Pipeline Mos6502::create_ora_instruction(Opcode opcode) {
Pipeline result;
result.append(create_addressing_steps(opcode.address_mode, memory_access));
 
result.push([=]() {
result.push([this]() {
const uint8_t operand = mmu_->read_byte(effective_address_);
registers_->a |= operand;
 
@@ -908,7 +890,7 @@ Pipeline Mos6502::create_left_shift_instruction(Opcode opcode,
Pipeline result;
result.append(create_addressing_steps(opcode.address_mode, memory_access));
 
result.push([=]() {
result.push([this, opcode, shift_in_carry]() {
const uint8_t source_value =
opcode.address_mode == AddressMode::Accumulator ? registers_->a
: tmp_;
@@ -938,7 +920,7 @@ Pipeline Mos6502::create_right_shift_instruction(Opcode opcode,
Pipeline result;
result.append(create_addressing_steps(opcode.address_mode, memory_access));
 
result.push([=]() {
result.push([this, opcode, shift_in_carry]() {
const uint8_t source_value =
opcode.address_mode == AddressMode::Accumulator ? registers_->a
: tmp_;
@@ -1006,17 +988,17 @@ Pipeline Mos6502::create_addressing_steps(AddressMode address_mode,
Pipeline Mos6502::create_zeropage_addressing_steps(MemoryAccess access) {
Pipeline result;
if (access == MemoryAccess::Read || access == MemoryAccess::Write) {
result.push([=]() {
result.push([this]() {
effective_address_ = mmu_->read_byte(registers_->pc);
++registers_->pc;
});
} else {
result.push([=]() {
result.push([this]() {
effective_address_ = mmu_->read_byte(registers_->pc);
++registers_->pc;
});
result.push([=]() { tmp_ = mmu_->read_byte(effective_address_); });
result.push([=]() {
result.push([this]() { tmp_ = mmu_->read_byte(effective_address_); });
result.push([this]() {
// Extra write with the old value
mmu_->write_byte(effective_address_, tmp_);
});
@@ -1029,23 +1011,23 @@ Pipeline Mos6502::create_zeropage_indexed_addressing_steps(
MemoryAccess access) {
Pipeline result;
if (access == MemoryAccess::Read || access == MemoryAccess::Write) {
result.push([=]() { tmp_ = mmu_->read_byte(registers_->pc++); });
result.push([=]() {
result.push([this]() { tmp_ = mmu_->read_byte(registers_->pc++); });
result.push([this, index_reg]() {
// Dummy read
mmu_->read_byte(tmp_);
const uint8_t effective_address_low = tmp_ + *index_reg;
effective_address_ = effective_address_low;
});
} else if (access == MemoryAccess::ReadWrite) {
result.push([=]() { tmp_ = mmu_->read_byte(registers_->pc++); });
result.push([=]() {
result.push([this]() { tmp_ = mmu_->read_byte(registers_->pc++); });
result.push([this, index_reg]() {
// Dummy read
mmu_->read_byte(tmp_);
const uint8_t effective_address_low = tmp_ + *index_reg;
effective_address_ = effective_address_low;
});
result.push([=]() { tmp_ = mmu_->read_byte(effective_address_); });
result.push([=]() {
result.push([this]() { tmp_ = mmu_->read_byte(effective_address_); });
result.push([this]() {
// Extra write to effective address with old value.
mmu_->write_byte(effective_address_, tmp_);
});
@@ -1055,14 +1037,14 @@ Pipeline Mos6502::create_zeropage_indexed_addressing_steps(
 
Pipeline Mos6502::create_absolute_addressing_steps(const MemoryAccess access) {
Pipeline result;
result.push([=]() { tmp_ = mmu_->read_byte(registers_->pc++); });
result.push([=]() {
result.push([this]() { tmp_ = mmu_->read_byte(registers_->pc++); });
result.push([this]() {
const uint16_t upper = mmu_->read_byte(registers_->pc++) << 8u;
effective_address_ = upper | tmp_;
});
if (access == MemoryAccess::ReadWrite) {
result.push([=]() { tmp_ = mmu_->read_byte(effective_address_); });
result.push([=]() {
result.push([this]() { tmp_ = mmu_->read_byte(effective_address_); });
result.push([this]() {
// Extra write with the old value
mmu_->write_byte(effective_address_, tmp_);
});
@@ -1074,8 +1056,8 @@ Pipeline Mos6502::create_absolute_indexed_addressing_steps(
const uint8_t *index_reg,
const MemoryAccess access) {
Pipeline result;
result.push([=]() { tmp_ = mmu_->read_byte(registers_->pc++); });
result.push([=]() {
result.push([this]() { tmp_ = mmu_->read_byte(registers_->pc++); });
result.push([this, index_reg]() {
const uint16_t address_high = mmu_->read_byte(registers_->pc++) << 8u;
const uint16_t abs_address = address_high | tmp_;
const uint8_t offset = *index_reg;
@@ -1085,7 +1067,7 @@ Pipeline Mos6502::create_absolute_indexed_addressing_steps(
});
 
if (access == MemoryAccess::Write) {
result.push([=]() {
result.push([this]() {
if (is_crossing_page_boundary_) {
// The high byte of the effective address is invalid
// at this time (smaller by $100), but a read is still
@@ -1098,7 +1080,7 @@ Pipeline Mos6502::create_absolute_indexed_addressing_steps(
}
});
} else if (access == MemoryAccess::Read) {
result.push_conditional([=]() {
result.push_conditional([this]() {
if (is_crossing_page_boundary_) {
// The high byte of the effective address is invalid
// at this time (smaller by $100), but a read is still
@@ -1110,7 +1092,7 @@ Pipeline Mos6502::create_absolute_indexed_addressing_steps(
return StepResult::Skip;
});
} else {
result.push([=]() {
result.push([this]() {
if (is_crossing_page_boundary_) {
// The high byte of the effective address is invalid
// at this time (smaller by $100), but a read is still
@@ -1122,11 +1104,11 @@ Pipeline Mos6502::create_absolute_indexed_addressing_steps(
mmu_->read_byte(effective_address_);
}
});
result.push([=]() {
result.push([this]() {
// Extra read from effective address.
tmp_ = mmu_->read_byte(effective_address_);
});
result.push([=]() {
result.push([this]() {
// Extra write.
mmu_->write_byte(effective_address_, tmp_);
});
@@ -1137,24 +1119,24 @@ Pipeline Mos6502::create_absolute_indexed_addressing_steps(
Pipeline Mos6502::create_indexed_indirect_addressing_steps(
const MemoryAccess access) {
Pipeline result;
result.push([=]() { tmp_ = mmu_->read_byte(registers_->pc++); });
result.push([=]() {
result.push([this]() { tmp_ = mmu_->read_byte(registers_->pc++); });
result.push([this]() {
// Dummy read
mmu_->read_byte(tmp_);
});
result.push([=]() {
result.push([this]() {
const uint8_t address = tmp_ + registers_->x;
tmp2_ = mmu_->read_byte(address);
});
result.push([=]() {
result.push([this]() {
// Effective address is always fetched from zero page
const uint8_t address = tmp_ + registers_->x + 1u;
const uint16_t upper = mmu_->read_byte(address) << 8u;
effective_address_ = upper | tmp2_;
});
if (access == MemoryAccess::ReadWrite) {
result.push([=]() { tmp_ = mmu_->read_byte(effective_address_); });
result.push([=]() { mmu_->write_byte(effective_address_, tmp_); });
result.push([this]() { tmp_ = mmu_->read_byte(effective_address_); });
result.push([this]() { mmu_->write_byte(effective_address_, tmp_); });
}
return result;
}
@@ -1162,9 +1144,9 @@ Pipeline Mos6502::create_indexed_indirect_addressing_steps(
Pipeline Mos6502::create_indirect_indexed_addressing_steps(
const MemoryAccess access) {
Pipeline result;
result.push([=]() { tmp_ = mmu_->read_byte(registers_->pc++); });
result.push([=]() { tmp2_ = mmu_->read_byte(tmp_); });
result.push([=]() {
result.push([this]() { tmp_ = mmu_->read_byte(registers_->pc++); });
result.push([this]() { tmp2_ = mmu_->read_byte(tmp_); });
result.push([this]() {
// The effective address is always fetched from zero page
const uint16_t upper = mmu_->read_byte(static_cast<uint8_t>(tmp_ + 1u))
<< 8u;
@@ -1175,7 +1157,7 @@ Pipeline Mos6502::create_indirect_indexed_addressing_steps(
effective_address_ = address + offset;
});
if (access == MemoryAccess::Write) {
result.push([=]() {
result.push([this]() {
if (is_crossing_page_boundary_) {
// The high byte of the effective address is invalid
// at this time (smaller by $100), but a read is still
@@ -1188,7 +1170,7 @@ Pipeline Mos6502::create_indirect_indexed_addressing_steps(
}
});
} else if (access == MemoryAccess::Read) {
result.push_conditional([=]() {
result.push_conditional([this]() {
if (is_crossing_page_boundary_) {
// The high byte of the effective address is invalid
// at this time (smaller by $100), but a read is still
@@ -1200,7 +1182,7 @@ Pipeline Mos6502::create_indirect_indexed_addressing_steps(
return StepResult::Skip;
});
} else {
result.push([=]() {
result.push([this]() {
if (is_crossing_page_boundary_) {
// The high byte of the effective address is invalid
// at this time (smaller by $100), but a read is still
@@ -1212,8 +1194,8 @@ Pipeline Mos6502::create_indirect_indexed_addressing_steps(
mmu_->read_byte(effective_address_);
}
});
result.push([=]() { tmp_ = mmu_->read_byte(effective_address_); });
result.push([=]() { mmu_->write_byte(effective_address_, tmp_); });
result.push([this]() { tmp_ = mmu_->read_byte(effective_address_); });
result.push([this]() { mmu_->write_byte(effective_address_, tmp_); });
}
return result;
}
 
core/src/pipeline.cpp added: 128, removed: 146, total 0
@@ -3,7 +3,7 @@
namespace n_e_s::core {
 
void Pipeline::push(const StepT &step) {
steps_.emplace_back([=]() {
steps_.emplace_back([step]() {
step();
return StepResult::Continue;
});