Rename CPU to Cpu

This commit is contained in:
scawful
2024-04-13 23:33:35 -05:00
parent ad08d998b5
commit ca076164ce
10 changed files with 129 additions and 129 deletions

View File

@@ -10,7 +10,7 @@ namespace yaze {
namespace app { namespace app {
namespace emu { namespace emu {
void CPU::Update(UpdateMode mode, int stepCount) { void Cpu::Update(UpdateMode mode, int stepCount) {
int cycles = (mode == UpdateMode::Run) ? clock.GetCycleCount() : stepCount; int cycles = (mode == UpdateMode::Run) ? clock.GetCycleCount() : stepCount;
// Execute the calculated number of cycles // Execute the calculated number of cycles
@@ -31,7 +31,7 @@ void CPU::Update(UpdateMode mode, int stepCount) {
} }
} }
void CPU::ExecuteInstruction(uint8_t opcode) { void Cpu::ExecuteInstruction(uint8_t opcode) {
uint8_t cycles = 0; uint8_t cycles = 0;
uint8_t instruction_length = 0; uint8_t instruction_length = 0;
uint32_t operand = 0; uint32_t operand = 0;
@@ -1475,7 +1475,7 @@ void CPU::ExecuteInstruction(uint8_t opcode) {
UpdatePC(instruction_length); UpdatePC(instruction_length);
} }
void CPU::LogInstructions(uint16_t PC, uint8_t opcode, uint16_t operand, void Cpu::LogInstructions(uint16_t PC, uint8_t opcode, uint16_t operand,
bool immediate, bool accumulator_mode) { bool immediate, bool accumulator_mode) {
if (flags()->kLogInstructions) { if (flags()->kLogInstructions) {
std::ostringstream oss; std::ostringstream oss;
@@ -1583,7 +1583,7 @@ void CPU::LogInstructions(uint16_t PC, uint8_t opcode, uint16_t operand,
} }
} }
uint8_t CPU::GetInstructionLength(uint8_t opcode) { uint8_t Cpu::GetInstructionLength(uint8_t opcode) {
switch (opcode) { switch (opcode) {
case 0x00: // BRK case 0x00: // BRK
case 0x02: // COP case 0x02: // COP
@@ -1928,7 +1928,7 @@ uint8_t CPU::GetInstructionLength(uint8_t opcode) {
} }
// TODO: Implement 65816 interrupts. // TODO: Implement 65816 interrupts.
void CPU::HandleInterrupts() { void Cpu::HandleInterrupts() {
if (GetInterruptFlag()) { if (GetInterruptFlag()) {
return; return;
} }

View File

@@ -38,9 +38,9 @@ class InstructionEntry {
const int kCpuClockSpeed = 21477272; // 21.477272 MHz const int kCpuClockSpeed = 21477272; // 21.477272 MHz
class CPU : public Memory, public Loggable, public core::ExperimentFlags { class Cpu : public Memory, public Loggable, public core::ExperimentFlags {
public: public:
explicit CPU(Memory& mem, Clock& vclock) : memory(mem), clock(vclock) {} explicit Cpu(Memory& mem, Clock& vclock) : memory(mem), clock(vclock) {}
enum class UpdateMode { Run, Step, Pause }; enum class UpdateMode { Run, Step, Pause };
void Init(bool verbose = false) { clock.SetFrequency(kCpuClockSpeed); } void Init(bool verbose = false) { clock.SetFrequency(kCpuClockSpeed); }

View File

@@ -4,92 +4,92 @@ namespace yaze {
namespace app { namespace app {
namespace emu { namespace emu {
uint32_t CPU::Absolute(CPU::AccessType access_type) { uint32_t Cpu::Absolute(Cpu::AccessType access_type) {
auto operand = FetchWord(); auto operand = FetchWord();
uint32_t bank = uint32_t bank =
(access_type == CPU::AccessType::Data) ? (DB << 16) : (PB << 16); (access_type == Cpu::AccessType::Data) ? (DB << 16) : (PB << 16);
return bank | (operand & 0xFFFF); return bank | (operand & 0xFFFF);
} }
uint32_t CPU::AbsoluteIndexedX() { uint32_t Cpu::AbsoluteIndexedX() {
uint16_t address = memory.ReadWord((PB << 16) | (PC + 1)); uint16_t address = memory.ReadWord((PB << 16) | (PC + 1));
uint32_t effective_address = (DB << 16) | ((address + X) & 0xFFFF); uint32_t effective_address = (DB << 16) | ((address + X) & 0xFFFF);
return effective_address; return effective_address;
} }
uint32_t CPU::AbsoluteIndexedY() { uint32_t Cpu::AbsoluteIndexedY() {
uint16_t address = memory.ReadWord((PB << 16) | (PC + 1)); uint16_t address = memory.ReadWord((PB << 16) | (PC + 1));
uint32_t effective_address = (DB << 16) | address + Y; uint32_t effective_address = (DB << 16) | address + Y;
return effective_address; return effective_address;
} }
uint16_t CPU::AbsoluteIndexedIndirect() { uint16_t Cpu::AbsoluteIndexedIndirect() {
uint16_t address = FetchWord() + X; uint16_t address = FetchWord() + X;
return memory.ReadWord((DB << 16) | address & 0xFFFF); return memory.ReadWord((DB << 16) | address & 0xFFFF);
} }
uint16_t CPU::AbsoluteIndirect() { uint16_t Cpu::AbsoluteIndirect() {
uint16_t address = FetchWord(); uint16_t address = FetchWord();
return memory.ReadWord((PB << 16) | address); return memory.ReadWord((PB << 16) | address);
} }
uint32_t CPU::AbsoluteIndirectLong() { uint32_t Cpu::AbsoluteIndirectLong() {
uint16_t address = FetchWord(); uint16_t address = FetchWord();
return memory.ReadWordLong((PB << 16) | address); return memory.ReadWordLong((PB << 16) | address);
} }
uint32_t CPU::AbsoluteLong() { return FetchLong(); } uint32_t Cpu::AbsoluteLong() { return FetchLong(); }
uint32_t CPU::AbsoluteLongIndexedX() { return FetchLong() + X; } uint32_t Cpu::AbsoluteLongIndexedX() { return FetchLong() + X; }
void CPU::BlockMove(uint16_t source, uint16_t dest, uint16_t length) { void Cpu::BlockMove(uint16_t source, uint16_t dest, uint16_t length) {
for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {
memory.WriteByte(dest + i, memory.ReadByte(source + i)); memory.WriteByte(dest + i, memory.ReadByte(source + i));
} }
} }
uint16_t CPU::DirectPage() { uint16_t Cpu::DirectPage() {
uint8_t dp = FetchByte(); uint8_t dp = FetchByte();
return D + dp; return D + dp;
} }
uint16_t CPU::DirectPageIndexedX() { uint16_t Cpu::DirectPageIndexedX() {
uint8_t operand = FetchByte(); uint8_t operand = FetchByte();
uint16_t x_by_mode = GetAccumulatorSize() ? X : X & 0xFF; uint16_t x_by_mode = GetAccumulatorSize() ? X : X & 0xFF;
return D + operand + x_by_mode; return D + operand + x_by_mode;
} }
uint16_t CPU::DirectPageIndexedY() { uint16_t Cpu::DirectPageIndexedY() {
uint8_t operand = FetchByte(); uint8_t operand = FetchByte();
return (operand + Y) & 0xFF; return (operand + Y) & 0xFF;
} }
uint16_t CPU::DirectPageIndexedIndirectX() { uint16_t Cpu::DirectPageIndexedIndirectX() {
uint8_t operand = FetchByte(); uint8_t operand = FetchByte();
uint16_t indirect_address = D + operand + X; uint16_t indirect_address = D + operand + X;
uint16_t effective_address = memory.ReadWord(indirect_address & 0xFFFF); uint16_t effective_address = memory.ReadWord(indirect_address & 0xFFFF);
return effective_address; return effective_address;
} }
uint16_t CPU::DirectPageIndirect() { uint16_t Cpu::DirectPageIndirect() {
uint8_t dp = FetchByte(); uint8_t dp = FetchByte();
uint16_t effective_address = D + dp; uint16_t effective_address = D + dp;
return memory.ReadWord(effective_address); return memory.ReadWord(effective_address);
} }
uint32_t CPU::DirectPageIndirectLong() { uint32_t Cpu::DirectPageIndirectLong() {
uint8_t dp = FetchByte(); uint8_t dp = FetchByte();
uint16_t effective_address = D + dp; uint16_t effective_address = D + dp;
return memory.ReadWordLong((0x00 << 0x10) | effective_address); return memory.ReadWordLong((0x00 << 0x10) | effective_address);
} }
uint16_t CPU::DirectPageIndirectIndexedY() { uint16_t Cpu::DirectPageIndirectIndexedY() {
uint8_t operand = FetchByte(); uint8_t operand = FetchByte();
uint16_t indirect_address = D + operand; uint16_t indirect_address = D + operand;
return memory.ReadWord(indirect_address) + Y; return memory.ReadWord(indirect_address) + Y;
} }
uint32_t CPU::DirectPageIndirectLongIndexedY() { uint32_t Cpu::DirectPageIndirectLongIndexedY() {
uint8_t operand = FetchByte(); uint8_t operand = FetchByte();
uint16_t indirect_address = D + operand; uint16_t indirect_address = D + operand;
uint16_t y_by_mode = GetAccumulatorSize() ? Y : Y & 0xFF; uint16_t y_by_mode = GetAccumulatorSize() ? Y : Y & 0xFF;
@@ -98,7 +98,7 @@ uint32_t CPU::DirectPageIndirectLongIndexedY() {
return effective_address; return effective_address;
} }
uint16_t CPU::Immediate(bool index_size) { uint16_t Cpu::Immediate(bool index_size) {
bool bit_mode = index_size ? GetIndexSize() : GetAccumulatorSize(); bool bit_mode = index_size ? GetIndexSize() : GetAccumulatorSize();
if (bit_mode) { if (bit_mode) {
return memory.ReadByte((PB << 16) | PC + 1); return memory.ReadByte((PB << 16) | PC + 1);
@@ -107,13 +107,13 @@ uint16_t CPU::Immediate(bool index_size) {
} }
} }
uint16_t CPU::StackRelative() { uint16_t Cpu::StackRelative() {
uint8_t sr = FetchByte(); uint8_t sr = FetchByte();
uint16_t effective_address = SP() + sr; uint16_t effective_address = SP() + sr;
return effective_address; return effective_address;
} }
uint32_t CPU::StackRelativeIndirectIndexedY() { uint32_t Cpu::StackRelativeIndirectIndexedY() {
uint8_t sr = FetchByte(); uint8_t sr = FetchByte();
return (DB << 0x10) | (memory.ReadWord(SP() + sr) + Y); return (DB << 0x10) | (memory.ReadWord(SP() + sr) + Y);
} }

View File

@@ -14,7 +14,7 @@ namespace emu {
* TODO: STP, WDM * TODO: STP, WDM
*/ */
void CPU::ADC(uint16_t operand) { void Cpu::ADC(uint16_t operand) {
bool C = GetCarryFlag(); bool C = GetCarryFlag();
if (GetAccumulatorSize()) { // 8-bit mode if (GetAccumulatorSize()) { // 8-bit mode
uint16_t result = static_cast<uint16_t>(A & 0xFF) + uint16_t result = static_cast<uint16_t>(A & 0xFF) +
@@ -47,7 +47,7 @@ void CPU::ADC(uint16_t operand) {
} }
} }
void CPU::AND(uint32_t value, bool isImmediate) { void Cpu::AND(uint32_t value, bool isImmediate) {
uint16_t operand; uint16_t operand;
if (GetAccumulatorSize()) { // 8-bit mode if (GetAccumulatorSize()) { // 8-bit mode
operand = isImmediate ? value : memory.ReadByte(value); operand = isImmediate ? value : memory.ReadByte(value);
@@ -63,14 +63,14 @@ void CPU::AND(uint32_t value, bool isImmediate) {
} }
// New function for absolute long addressing mode // New function for absolute long addressing mode
void CPU::ANDAbsoluteLong(uint32_t address) { void Cpu::ANDAbsoluteLong(uint32_t address) {
uint32_t operand32 = memory.ReadWordLong(address); uint32_t operand32 = memory.ReadWordLong(address);
A &= operand32; A &= operand32;
SetZeroFlag(A == 0); SetZeroFlag(A == 0);
SetNegativeFlag(A & 0x8000); SetNegativeFlag(A & 0x8000);
} }
void CPU::ASL(uint16_t address) { void Cpu::ASL(uint16_t address) {
uint8_t value = memory.ReadByte(address); uint8_t value = memory.ReadByte(address);
SetCarryFlag(!(value & 0x80)); // Set carry flag if bit 7 is set SetCarryFlag(!(value & 0x80)); // Set carry flag if bit 7 is set
value <<= 1; // Shift left value <<= 1; // Shift left
@@ -80,53 +80,53 @@ void CPU::ASL(uint16_t address) {
SetZeroFlag(value); SetZeroFlag(value);
} }
void CPU::BCC(int8_t offset) { void Cpu::BCC(int8_t offset) {
if (!GetCarryFlag()) { // If the carry flag is clear if (!GetCarryFlag()) { // If the carry flag is clear
next_pc_ = offset; next_pc_ = offset;
} }
} }
void CPU::BCS(int8_t offset) { void Cpu::BCS(int8_t offset) {
if (GetCarryFlag()) { // If the carry flag is set if (GetCarryFlag()) { // If the carry flag is set
next_pc_ = offset; next_pc_ = offset;
} }
} }
void CPU::BEQ(int8_t offset) { void Cpu::BEQ(int8_t offset) {
if (GetZeroFlag()) { // If the zero flag is set if (GetZeroFlag()) { // If the zero flag is set
next_pc_ = offset; next_pc_ = offset;
} }
} }
void CPU::BIT(uint16_t address) { void Cpu::BIT(uint16_t address) {
uint8_t value = memory.ReadByte(address); uint8_t value = memory.ReadByte(address);
SetNegativeFlag(value & 0x80); SetNegativeFlag(value & 0x80);
SetOverflowFlag(value & 0x40); SetOverflowFlag(value & 0x40);
SetZeroFlag((A & value) == 0); SetZeroFlag((A & value) == 0);
} }
void CPU::BMI(int8_t offset) { void Cpu::BMI(int8_t offset) {
if (GetNegativeFlag()) { // If the negative flag is set if (GetNegativeFlag()) { // If the negative flag is set
next_pc_ = offset; next_pc_ = offset;
} }
} }
void CPU::BNE(int8_t offset) { void Cpu::BNE(int8_t offset) {
if (!GetZeroFlag()) { // If the zero flag is clear if (!GetZeroFlag()) { // If the zero flag is clear
// PC += offset; // PC += offset;
next_pc_ = offset; next_pc_ = offset;
} }
} }
void CPU::BPL(int8_t offset) { void Cpu::BPL(int8_t offset) {
if (!GetNegativeFlag()) { // If the negative flag is clear if (!GetNegativeFlag()) { // If the negative flag is clear
next_pc_ = offset; next_pc_ = offset;
} }
} }
void CPU::BRA(int8_t offset) { next_pc_ = offset; } void Cpu::BRA(int8_t offset) { next_pc_ = offset; }
void CPU::BRK() { void Cpu::BRK() {
next_pc_ = PC + 2; // Increment the program counter by 2 next_pc_ = PC + 2; // Increment the program counter by 2
memory.PushWord(next_pc_); memory.PushWord(next_pc_);
memory.PushByte(status); memory.PushByte(status);
@@ -138,32 +138,32 @@ void CPU::BRK() {
} }
} }
void CPU::BRL(int16_t offset) { next_pc_ = offset; } void Cpu::BRL(int16_t offset) { next_pc_ = offset; }
void CPU::BVC(int8_t offset) { void Cpu::BVC(int8_t offset) {
if (!GetOverflowFlag()) { // If the overflow flag is clear if (!GetOverflowFlag()) { // If the overflow flag is clear
next_pc_ = offset; next_pc_ = offset;
} }
} }
void CPU::BVS(int8_t offset) { void Cpu::BVS(int8_t offset) {
if (GetOverflowFlag()) { // If the overflow flag is set if (GetOverflowFlag()) { // If the overflow flag is set
next_pc_ = offset; next_pc_ = offset;
} }
} }
void CPU::CLC() { status &= ~0x01; } void Cpu::CLC() { status &= ~0x01; }
void CPU::CLD() { status &= ~0x08; } void Cpu::CLD() { status &= ~0x08; }
void CPU::CLI() { status &= ~0x04; } void Cpu::CLI() { status &= ~0x04; }
void CPU::CLV() { status &= ~0x40; } void Cpu::CLV() { status &= ~0x40; }
// n Set if MSB of result is set; else cleared // n Set if MSB of result is set; else cleared
// z Set if result is zero; else cleared // z Set if result is zero; else cleared
// c Set if no borrow; else cleared // c Set if no borrow; else cleared
void CPU::CMP(uint32_t value, bool isImmediate) { void Cpu::CMP(uint32_t value, bool isImmediate) {
if (GetAccumulatorSize()) { // 8-bit if (GetAccumulatorSize()) { // 8-bit
uint8_t result; uint8_t result;
if (isImmediate) { if (isImmediate) {
@@ -189,7 +189,7 @@ void CPU::CMP(uint32_t value, bool isImmediate) {
} }
} }
void CPU::COP() { void Cpu::COP() {
next_pc_ += 2; // Increment the program counter by 2 next_pc_ += 2; // Increment the program counter by 2
memory.PushWord(next_pc_); memory.PushWord(next_pc_);
memory.PushByte(status); memory.PushByte(status);
@@ -202,7 +202,7 @@ void CPU::COP() {
SetDecimalFlag(false); SetDecimalFlag(false);
} }
void CPU::CPX(uint32_t value, bool isImmediate) { void Cpu::CPX(uint32_t value, bool isImmediate) {
if (GetIndexSize()) { // 8-bit if (GetIndexSize()) { // 8-bit
uint8_t memory_value = isImmediate ? value : memory.ReadByte(value); uint8_t memory_value = isImmediate ? value : memory.ReadByte(value);
compare(X, memory_value); compare(X, memory_value);
@@ -212,7 +212,7 @@ void CPU::CPX(uint32_t value, bool isImmediate) {
} }
} }
void CPU::CPY(uint32_t value, bool isImmediate) { void Cpu::CPY(uint32_t value, bool isImmediate) {
if (GetIndexSize()) { // 8-bit if (GetIndexSize()) { // 8-bit
uint8_t memory_value = isImmediate ? value : memory.ReadByte(value); uint8_t memory_value = isImmediate ? value : memory.ReadByte(value);
compare(Y, memory_value); compare(Y, memory_value);
@@ -222,7 +222,7 @@ void CPU::CPY(uint32_t value, bool isImmediate) {
} }
} }
void CPU::DEC(uint32_t address, bool accumulator) { void Cpu::DEC(uint32_t address, bool accumulator) {
if (accumulator) { if (accumulator) {
if (GetAccumulatorSize()) { // 8-bit if (GetAccumulatorSize()) { // 8-bit
A = (A - 1) & 0xFF; A = (A - 1) & 0xFF;
@@ -251,7 +251,7 @@ void CPU::DEC(uint32_t address, bool accumulator) {
} }
} }
void CPU::DEX() { void Cpu::DEX() {
if (GetIndexSize()) { // 8-bit if (GetIndexSize()) { // 8-bit
X = static_cast<uint8_t>(X - 1); X = static_cast<uint8_t>(X - 1);
SetZeroFlag(X == 0); SetZeroFlag(X == 0);
@@ -263,7 +263,7 @@ void CPU::DEX() {
} }
} }
void CPU::DEY() { void Cpu::DEY() {
if (GetIndexSize()) { // 8-bit if (GetIndexSize()) { // 8-bit
Y = static_cast<uint8_t>(Y - 1); Y = static_cast<uint8_t>(Y - 1);
SetZeroFlag(Y == 0); SetZeroFlag(Y == 0);
@@ -275,7 +275,7 @@ void CPU::DEY() {
} }
} }
void CPU::EOR(uint32_t address, bool isImmediate) { void Cpu::EOR(uint32_t address, bool isImmediate) {
if (GetAccumulatorSize()) { if (GetAccumulatorSize()) {
A ^= isImmediate ? address : memory.ReadByte(address); A ^= isImmediate ? address : memory.ReadByte(address);
SetZeroFlag(A == 0); SetZeroFlag(A == 0);
@@ -287,7 +287,7 @@ void CPU::EOR(uint32_t address, bool isImmediate) {
} }
} }
void CPU::INC(uint32_t address, bool accumulator) { void Cpu::INC(uint32_t address, bool accumulator) {
if (accumulator) { if (accumulator) {
if (GetAccumulatorSize()) { // 8-bit if (GetAccumulatorSize()) { // 8-bit
A = (A + 1) & 0xFF; A = (A + 1) & 0xFF;
@@ -316,7 +316,7 @@ void CPU::INC(uint32_t address, bool accumulator) {
} }
} }
void CPU::INX() { void Cpu::INX() {
if (GetIndexSize()) { // 8-bit if (GetIndexSize()) { // 8-bit
X = static_cast<uint8_t>(X + 1); X = static_cast<uint8_t>(X + 1);
SetZeroFlag(X == 0); SetZeroFlag(X == 0);
@@ -328,7 +328,7 @@ void CPU::INX() {
} }
} }
void CPU::INY() { void Cpu::INY() {
if (GetIndexSize()) { // 8-bit if (GetIndexSize()) { // 8-bit
Y = static_cast<uint8_t>(Y + 1); Y = static_cast<uint8_t>(Y + 1);
SetZeroFlag(Y == 0); SetZeroFlag(Y == 0);
@@ -340,28 +340,28 @@ void CPU::INY() {
} }
} }
void CPU::JMP(uint16_t address) { void Cpu::JMP(uint16_t address) {
next_pc_ = address; // Set program counter to the new address next_pc_ = address; // Set program counter to the new address
} }
void CPU::JML(uint32_t address) { void Cpu::JML(uint32_t address) {
next_pc_ = static_cast<uint16_t>(address & 0xFFFF); next_pc_ = static_cast<uint16_t>(address & 0xFFFF);
// Set the PBR to the upper 8 bits of the address // Set the PBR to the upper 8 bits of the address
PB = static_cast<uint8_t>((address >> 16) & 0xFF); PB = static_cast<uint8_t>((address >> 16) & 0xFF);
} }
void CPU::JSR(uint16_t address) { void Cpu::JSR(uint16_t address) {
memory.PushWord(PC); // Push the program counter onto the stack memory.PushWord(PC); // Push the program counter onto the stack
next_pc_ = address; // Set program counter to the new address next_pc_ = address; // Set program counter to the new address
} }
void CPU::JSL(uint32_t address) { void Cpu::JSL(uint32_t address) {
memory.PushLong(PC); // Push the program counter onto the stack as a long memory.PushLong(PC); // Push the program counter onto the stack as a long
// value (24 bits) // value (24 bits)
next_pc_ = address; // Set program counter to the new address next_pc_ = address; // Set program counter to the new address
} }
void CPU::LDA(uint16_t address, bool isImmediate, bool direct_page, bool data_bank) { void Cpu::LDA(uint16_t address, bool isImmediate, bool direct_page, bool data_bank) {
uint8_t bank = PB; uint8_t bank = PB;
if (direct_page) { if (direct_page) {
bank = 0; bank = 0;
@@ -377,7 +377,7 @@ void CPU::LDA(uint16_t address, bool isImmediate, bool direct_page, bool data_ba
} }
} }
void CPU::LDX(uint16_t address, bool isImmediate) { void Cpu::LDX(uint16_t address, bool isImmediate) {
if (GetIndexSize()) { if (GetIndexSize()) {
X = isImmediate ? address : memory.ReadByte(address); X = isImmediate ? address : memory.ReadByte(address);
SetZeroFlag(X == 0); SetZeroFlag(X == 0);
@@ -389,7 +389,7 @@ void CPU::LDX(uint16_t address, bool isImmediate) {
} }
} }
void CPU::LDY(uint16_t address, bool isImmediate) { void Cpu::LDY(uint16_t address, bool isImmediate) {
if (GetIndexSize()) { if (GetIndexSize()) {
Y = isImmediate ? address : memory.ReadByte(address); Y = isImmediate ? address : memory.ReadByte(address);
SetZeroFlag(Y == 0); SetZeroFlag(Y == 0);
@@ -401,7 +401,7 @@ void CPU::LDY(uint16_t address, bool isImmediate) {
} }
} }
void CPU::LSR(uint16_t address, bool accumulator) { void Cpu::LSR(uint16_t address, bool accumulator) {
if (accumulator) { if (accumulator) {
if (GetAccumulatorSize()) { // 8-bit if (GetAccumulatorSize()) { // 8-bit
SetCarryFlag(A & 0x01); SetCarryFlag(A & 0x01);
@@ -424,7 +424,7 @@ void CPU::LSR(uint16_t address, bool accumulator) {
SetZeroFlag(value == 0); SetZeroFlag(value == 0);
} }
void CPU::MVN(uint16_t source, uint16_t dest, uint16_t length) { void Cpu::MVN(uint16_t source, uint16_t dest, uint16_t length) {
for (uint16_t i = 0; i < length; i++) { for (uint16_t i = 0; i < length; i++) {
memory.WriteByte(dest, memory.ReadByte(source)); memory.WriteByte(dest, memory.ReadByte(source));
source++; source++;
@@ -432,7 +432,7 @@ void CPU::MVN(uint16_t source, uint16_t dest, uint16_t length) {
} }
} }
void CPU::MVP(uint16_t source, uint16_t dest, uint16_t length) { void Cpu::MVP(uint16_t source, uint16_t dest, uint16_t length) {
for (uint16_t i = 0; i < length; i++) { for (uint16_t i = 0; i < length; i++) {
memory.WriteByte(dest, memory.ReadByte(source)); memory.WriteByte(dest, memory.ReadByte(source));
source--; source--;
@@ -440,11 +440,11 @@ void CPU::MVP(uint16_t source, uint16_t dest, uint16_t length) {
} }
} }
void CPU::NOP() { void Cpu::NOP() {
// Do nothing // Do nothing
} }
void CPU::ORA(uint16_t address, bool isImmediate) { void Cpu::ORA(uint16_t address, bool isImmediate) {
if (GetAccumulatorSize()) { if (GetAccumulatorSize()) {
A |= isImmediate ? address : memory.ReadByte(address); A |= isImmediate ? address : memory.ReadByte(address);
SetZeroFlag(A == 0); SetZeroFlag(A == 0);
@@ -456,22 +456,22 @@ void CPU::ORA(uint16_t address, bool isImmediate) {
} }
} }
void CPU::PEA() { void Cpu::PEA() {
uint16_t address = FetchWord(); uint16_t address = FetchWord();
memory.PushWord(address); memory.PushWord(address);
} }
void CPU::PEI() { void Cpu::PEI() {
uint16_t address = FetchWord(); uint16_t address = FetchWord();
memory.PushWord(memory.ReadWord(address)); memory.PushWord(memory.ReadWord(address));
} }
void CPU::PER() { void Cpu::PER() {
uint16_t address = FetchWord(); uint16_t address = FetchWord();
memory.PushWord(PC + address); memory.PushWord(PC + address);
} }
void CPU::PHA() { void Cpu::PHA() {
if (GetAccumulatorSize()) { if (GetAccumulatorSize()) {
memory.PushByte(static_cast<uint8_t>(A)); memory.PushByte(static_cast<uint8_t>(A));
} else { } else {
@@ -479,15 +479,15 @@ void CPU::PHA() {
} }
} }
void CPU::PHB() { memory.PushByte(DB); } void Cpu::PHB() { memory.PushByte(DB); }
void CPU::PHD() { memory.PushWord(D); } void Cpu::PHD() { memory.PushWord(D); }
void CPU::PHK() { memory.PushByte(PB); } void Cpu::PHK() { memory.PushByte(PB); }
void CPU::PHP() { memory.PushByte(status); } void Cpu::PHP() { memory.PushByte(status); }
void CPU::PHX() { void Cpu::PHX() {
if (GetIndexSize()) { if (GetIndexSize()) {
memory.PushByte(static_cast<uint8_t>(X)); memory.PushByte(static_cast<uint8_t>(X));
} else { } else {
@@ -495,7 +495,7 @@ void CPU::PHX() {
} }
} }
void CPU::PHY() { void Cpu::PHY() {
if (GetIndexSize()) { if (GetIndexSize()) {
memory.PushByte(static_cast<uint8_t>(Y)); memory.PushByte(static_cast<uint8_t>(Y));
} else { } else {
@@ -503,7 +503,7 @@ void CPU::PHY() {
} }
} }
void CPU::PLA() { void Cpu::PLA() {
if (GetAccumulatorSize()) { if (GetAccumulatorSize()) {
A = memory.PopByte(); A = memory.PopByte();
SetNegativeFlag((A & 0x80) != 0); SetNegativeFlag((A & 0x80) != 0);
@@ -514,23 +514,23 @@ void CPU::PLA() {
SetZeroFlag(A == 0); SetZeroFlag(A == 0);
} }
void CPU::PLB() { void Cpu::PLB() {
DB = memory.PopByte(); DB = memory.PopByte();
SetNegativeFlag((DB & 0x80) != 0); SetNegativeFlag((DB & 0x80) != 0);
SetZeroFlag(DB == 0); SetZeroFlag(DB == 0);
} }
// Pull Direct Page Register from Stack // Pull Direct Page Register from Stack
void CPU::PLD() { void Cpu::PLD() {
D = memory.PopWord(); D = memory.PopWord();
SetNegativeFlag((D & 0x8000) != 0); SetNegativeFlag((D & 0x8000) != 0);
SetZeroFlag(D == 0); SetZeroFlag(D == 0);
} }
// Pull Processor Status Register from Stack // Pull Processor Status Register from Stack
void CPU::PLP() { status = memory.PopByte(); } void Cpu::PLP() { status = memory.PopByte(); }
void CPU::PLX() { void Cpu::PLX() {
if (GetIndexSize()) { if (GetIndexSize()) {
X = memory.PopByte(); X = memory.PopByte();
SetNegativeFlag((A & 0x80) != 0); SetNegativeFlag((A & 0x80) != 0);
@@ -542,7 +542,7 @@ void CPU::PLX() {
SetZeroFlag(X == 0); SetZeroFlag(X == 0);
} }
void CPU::PLY() { void Cpu::PLY() {
if (GetIndexSize()) { if (GetIndexSize()) {
Y = memory.PopByte(); Y = memory.PopByte();
SetNegativeFlag((A & 0x80) != 0); SetNegativeFlag((A & 0x80) != 0);
@@ -553,12 +553,12 @@ void CPU::PLY() {
SetZeroFlag(Y == 0); SetZeroFlag(Y == 0);
} }
void CPU::REP() { void Cpu::REP() {
auto byte = FetchByte(); auto byte = FetchByte();
status &= ~byte; status &= ~byte;
} }
void CPU::ROL(uint32_t address, bool accumulator) { void Cpu::ROL(uint32_t address, bool accumulator) {
if (accumulator) { if (accumulator) {
if (GetAccumulatorSize()) { // 8-bit if (GetAccumulatorSize()) { // 8-bit
uint8_t carry = GetCarryFlag() ? 0x01 : 0x00; uint8_t carry = GetCarryFlag() ? 0x01 : 0x00;
@@ -588,7 +588,7 @@ void CPU::ROL(uint32_t address, bool accumulator) {
SetZeroFlag(value == 0); SetZeroFlag(value == 0);
} }
void CPU::ROR(uint32_t address, bool accumulator) { void Cpu::ROR(uint32_t address, bool accumulator) {
if (accumulator) { if (accumulator) {
if (GetAccumulatorSize()) { // 8-bit if (GetAccumulatorSize()) { // 8-bit
uint8_t carry = GetCarryFlag() ? 0x80 : 0x00; uint8_t carry = GetCarryFlag() ? 0x80 : 0x00;
@@ -618,21 +618,21 @@ void CPU::ROR(uint32_t address, bool accumulator) {
SetZeroFlag(value == 0); SetZeroFlag(value == 0);
} }
void CPU::RTI() { void Cpu::RTI() {
status = memory.PopByte(); status = memory.PopByte();
PC = memory.PopWord(); PC = memory.PopWord();
} }
void CPU::RTL() { void Cpu::RTL() {
next_pc_ = memory.PopWord(); next_pc_ = memory.PopWord();
PB = memory.PopByte(); PB = memory.PopByte();
} }
void CPU::RTS() { void Cpu::RTS() {
last_call_frame_ = memory.PopWord(); last_call_frame_ = memory.PopWord();
} }
void CPU::SBC(uint32_t value, bool isImmediate) { void Cpu::SBC(uint32_t value, bool isImmediate) {
uint16_t operand; uint16_t operand;
if (!GetAccumulatorSize()) { // 16-bit mode if (!GetAccumulatorSize()) { // 16-bit mode
operand = isImmediate ? value : memory.ReadWord(value); operand = isImmediate ? value : memory.ReadWord(value);
@@ -665,18 +665,18 @@ void CPU::SBC(uint32_t value, bool isImmediate) {
} }
} }
void CPU::SEC() { status |= 0x01; } void Cpu::SEC() { status |= 0x01; }
void CPU::SED() { status |= 0x08; } void Cpu::SED() { status |= 0x08; }
void CPU::SEI() { status |= 0x04; } void Cpu::SEI() { status |= 0x04; }
void CPU::SEP() { void Cpu::SEP() {
auto byte = FetchByte(); auto byte = FetchByte();
status |= byte; status |= byte;
} }
void CPU::STA(uint32_t address) { void Cpu::STA(uint32_t address) {
if (GetAccumulatorSize()) { if (GetAccumulatorSize()) {
memory.WriteByte(address, static_cast<uint8_t>(A)); memory.WriteByte(address, static_cast<uint8_t>(A));
} else { } else {
@@ -686,12 +686,12 @@ void CPU::STA(uint32_t address) {
// TODO: Make this work with the Clock class of the CPU // TODO: Make this work with the Clock class of the CPU
void CPU::STP() { void Cpu::STP() {
// During the next phase 2 clock cycle, stop the processors oscillator input // During the next phase 2 clock cycle, stop the processors oscillator input
// The processor is effectively shut down until a reset occurs (RES` pin). // The processor is effectively shut down until a reset occurs (RES` pin).
} }
void CPU::STX(uint16_t address) { void Cpu::STX(uint16_t address) {
if (GetIndexSize()) { if (GetIndexSize()) {
memory.WriteByte(address, static_cast<uint8_t>(X)); memory.WriteByte(address, static_cast<uint8_t>(X));
} else { } else {
@@ -699,7 +699,7 @@ void CPU::STX(uint16_t address) {
} }
} }
void CPU::STY(uint16_t address) { void Cpu::STY(uint16_t address) {
if (GetIndexSize()) { if (GetIndexSize()) {
memory.WriteByte(address, static_cast<uint8_t>(Y)); memory.WriteByte(address, static_cast<uint8_t>(Y));
} else { } else {
@@ -707,7 +707,7 @@ void CPU::STY(uint16_t address) {
} }
} }
void CPU::STZ(uint16_t address) { void Cpu::STZ(uint16_t address) {
if (GetAccumulatorSize()) { if (GetAccumulatorSize()) {
memory.WriteByte(address, 0x00); memory.WriteByte(address, 0x00);
} else { } else {
@@ -715,79 +715,79 @@ void CPU::STZ(uint16_t address) {
} }
} }
void CPU::TAX() { void Cpu::TAX() {
X = A; X = A;
SetZeroFlag(X == 0); SetZeroFlag(X == 0);
SetNegativeFlag(X & 0x80); SetNegativeFlag(X & 0x80);
} }
void CPU::TAY() { void Cpu::TAY() {
Y = A; Y = A;
SetZeroFlag(Y == 0); SetZeroFlag(Y == 0);
SetNegativeFlag(Y & 0x80); SetNegativeFlag(Y & 0x80);
} }
void CPU::TCD() { void Cpu::TCD() {
D = A; D = A;
SetZeroFlag(D == 0); SetZeroFlag(D == 0);
SetNegativeFlag(D & 0x80); SetNegativeFlag(D & 0x80);
} }
void CPU::TCS() { memory.SetSP(A); } void Cpu::TCS() { memory.SetSP(A); }
void CPU::TDC() { void Cpu::TDC() {
A = D; A = D;
SetZeroFlag(A == 0); SetZeroFlag(A == 0);
SetNegativeFlag(A & 0x80); SetNegativeFlag(A & 0x80);
} }
void CPU::TRB(uint16_t address) { void Cpu::TRB(uint16_t address) {
uint8_t value = memory.ReadByte(address); uint8_t value = memory.ReadByte(address);
SetZeroFlag((A & value) == 0); SetZeroFlag((A & value) == 0);
value &= ~A; value &= ~A;
memory.WriteByte(address, value); memory.WriteByte(address, value);
} }
void CPU::TSB(uint16_t address) { void Cpu::TSB(uint16_t address) {
uint8_t value = memory.ReadByte(address); uint8_t value = memory.ReadByte(address);
SetZeroFlag((A & value) == 0); SetZeroFlag((A & value) == 0);
value |= A; value |= A;
memory.WriteByte(address, value); memory.WriteByte(address, value);
} }
void CPU::TSC() { void Cpu::TSC() {
A = SP(); A = SP();
SetZeroFlag(A == 0); SetZeroFlag(A == 0);
SetNegativeFlag(A & 0x80); SetNegativeFlag(A & 0x80);
} }
void CPU::TSX() { void Cpu::TSX() {
X = SP(); X = SP();
SetZeroFlag(X == 0); SetZeroFlag(X == 0);
SetNegativeFlag(X & 0x80); SetNegativeFlag(X & 0x80);
} }
void CPU::TXA() { void Cpu::TXA() {
A = X; A = X;
SetZeroFlag(A == 0); SetZeroFlag(A == 0);
SetNegativeFlag(A & 0x80); SetNegativeFlag(A & 0x80);
} }
void CPU::TXS() { memory.SetSP(X); } void Cpu::TXS() { memory.SetSP(X); }
void CPU::TXY() { void Cpu::TXY() {
Y = X; Y = X;
SetZeroFlag(X == 0); SetZeroFlag(X == 0);
SetNegativeFlag(X & 0x80); SetNegativeFlag(X & 0x80);
} }
void CPU::TYA() { void Cpu::TYA() {
A = Y; A = Y;
SetZeroFlag(A == 0); SetZeroFlag(A == 0);
SetNegativeFlag(A & 0x80); SetNegativeFlag(A & 0x80);
} }
void CPU::TYX() { void Cpu::TYX() {
X = Y; X = Y;
SetZeroFlag(Y == 0); SetZeroFlag(Y == 0);
SetNegativeFlag(Y & 0x80); SetNegativeFlag(Y & 0x80);
@@ -795,20 +795,20 @@ void CPU::TYX() {
// TODO: Make this communicate with the SNES class // TODO: Make this communicate with the SNES class
void CPU::WAI() { void Cpu::WAI() {
// Pull the RDY pin low // Pull the RDY pin low
// Power consumption is reduced(?) // Power consumption is reduced(?)
// RDY remains low until an external hardware interupt // RDY remains low until an external hardware interupt
// (NMI, IRQ, ABORT, or RESET) is received from the SNES class // (NMI, IRQ, ABORT, or RESET) is received from the SNES class
} }
void CPU::XBA() { void Cpu::XBA() {
uint8_t lowByte = A & 0xFF; uint8_t lowByte = A & 0xFF;
uint8_t highByte = (A >> 8) & 0xFF; uint8_t highByte = (A >> 8) & 0xFF;
A = (lowByte << 8) | highByte; A = (lowByte << 8) | highByte;
} }
void CPU::XCE() { void Cpu::XCE() {
uint8_t carry = status & 0x01; uint8_t carry = status & 0x01;
status &= ~0x01; status &= ~0x01;
status |= E; status |= E;

View File

@@ -259,7 +259,7 @@ void Emulator::RenderBreakpointList() {
} }
} }
void Emulator::RenderCpuState(CPU& cpu) { void Emulator::RenderCpuState(Cpu& cpu) {
if (ImGui::CollapsingHeader("Register Values", if (ImGui::CollapsingHeader("Register Values",
ImGuiTreeNodeFlags_DefaultOpen)) { ImGuiTreeNodeFlags_DefaultOpen)) {
ImGui::Columns(2, "RegistersColumns"); ImGui::Columns(2, "RegistersColumns");

View File

@@ -24,7 +24,7 @@ class Emulator : public SharedROM {
void RenderEmulator(); void RenderEmulator();
void RenderSnesPpu(); void RenderSnesPpu();
void RenderBreakpointList(); void RenderBreakpointList();
void RenderCpuState(CPU& cpu); void RenderCpuState(Cpu& cpu);
void RenderMemoryViewer(); void RenderMemoryViewer();
struct Bookmark { struct Bookmark {

View File

@@ -9,7 +9,7 @@
#include "app/emu/memory/memory.h" #include "app/emu/memory/memory.h"
using yaze::app::emu::Clock; using yaze::app::emu::Clock;
using yaze::app::emu::CPU; using yaze::app::emu::Cpu;
using yaze::app::emu::Memory; using yaze::app::emu::Memory;
class MockClock : public Clock { class MockClock : public Clock {

View File

@@ -257,7 +257,7 @@ void SNES::Run() {
void SNES::StepRun() { void SNES::StepRun() {
// Update the CPU // Update the CPU
cpu_.UpdateClock(0.0); cpu_.UpdateClock(0.0);
cpu_.Update(CPU::UpdateMode::Step); cpu_.Update(Cpu::UpdateMode::Step);
// Update the PPU // Update the PPU
ppu_.UpdateClock(0.0); ppu_.UpdateClock(0.0);

View File

@@ -61,13 +61,13 @@ class SNES : public DMA {
bool running() const { return running_; } bool running() const { return running_; }
auto cpu() -> CPU& { return cpu_; } auto cpu() -> Cpu& { return cpu_; }
auto ppu() -> Ppu& { return ppu_; } auto ppu() -> Ppu& { return ppu_; }
auto Memory() -> MemoryImpl* { return &memory_; } auto Memory() -> MemoryImpl* { return &memory_; }
void SetCpuMode(int mode) { cpu_mode_ = mode; } void SetCpuMode(int mode) { cpu_mode_ = mode; }
CPU::UpdateMode GetCpuMode() const { Cpu::UpdateMode GetCpuMode() const {
return static_cast<CPU::UpdateMode>(cpu_mode_); return static_cast<Cpu::UpdateMode>(cpu_mode_);
} }
void SetupMemory(ROM& rom) { void SetupMemory(ROM& rom) {
@@ -90,7 +90,7 @@ class SNES : public DMA {
ClockImpl clock_; ClockImpl clock_;
audio::AudioRamImpl audio_ram_; audio::AudioRamImpl audio_ram_;
CPU cpu_{memory_, clock_}; Cpu cpu_{memory_, clock_};
Ppu ppu_{memory_, clock_}; Ppu ppu_{memory_, clock_};
audio::Apu apu_{memory_, audio_ram_, clock_}; audio::Apu apu_{memory_, audio_ram_, clock_};

View File

@@ -48,7 +48,7 @@ class DungeonObjectRenderer : public SharedROM {
std::vector<uint8_t> rom_data_; std::vector<uint8_t> rom_data_;
emu::MemoryImpl memory_; emu::MemoryImpl memory_;
emu::ClockImpl clock_; emu::ClockImpl clock_;
emu::CPU cpu{memory_, clock_}; emu::Cpu cpu{memory_, clock_};
emu::Ppu ppu{memory_, clock_}; emu::Ppu ppu{memory_, clock_};
gfx::Bitmap bitmap_; gfx::Bitmap bitmap_;
PseudoVram vram_; PseudoVram vram_;