Skip to content

Commit

Permalink
Change variable names to make more readable
Browse files Browse the repository at this point in the history
  • Loading branch information
wfd3 committed Feb 7, 2024
1 parent 8f71f39 commit 337f96b
Show file tree
Hide file tree
Showing 66 changed files with 136 additions and 136 deletions.
6 changes: 3 additions & 3 deletions 6502/6502.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@

//////////
// CPU Setup and reset
MOS6502::MOS6502(Memory<Word, Byte>& m) : mem(m),
_instructions(setupInstructionMap()),
_debugCommands(setupDebugCommands()) {
MOS6502::MOS6502(Memory<Word, Byte>& m) : _instructions(setupInstructionMap()),
mem(m),
_debugCommands(setupDebugCommands()) {

_inReset = true;
initDebugger();
Expand Down
8 changes: 4 additions & 4 deletions 6502/6502.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,10 @@ using Cycles_t = uint8_t;
// friend in class CPU.
extern "C" char **readlineCompletionCallback(const char* text, int start, int end);


class MOS6502 {
public:
// Last addressable byte
constexpr static Word MAX_MEM = 0xFFFF;
constexpr static Word LAST_ADDRESS = 0xFFFF;

// CPU initial vectors
constexpr static Byte INITIAL_SP = 0xFF;
Expand Down Expand Up @@ -283,8 +282,6 @@ class MOS6502 {
Cycles_t _cycles = 0; // Cycle counter
Cycles_t _expectedCyclesToUse = 0;

Memory<Word, Byte>& mem;

Word PC = 0; // Program counter
Byte SP = 0; // Stack pointer
Byte A = 0; // Accumulator
Expand Down Expand Up @@ -440,6 +437,9 @@ class MOS6502 {
void ins_tya(Byte);

private:

Memory<Word, Byte>& mem; // Moved from protected section

//////////
// Special addresses/vectors

Expand Down
6 changes: 3 additions & 3 deletions 6502/debug.cc
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,13 @@ bool MOS6502::isPCBreakpoint() {
}

bool MOS6502::isBreakpoint(const Word bp) {
if (bp > MAX_MEM)
if (bp > LAST_ADDRESS)
return false;
return breakpoints.find(bp) != breakpoints.end();
}

void MOS6502::deleteBreakpoint(const Word bp) {
if (bp > MAX_MEM)
if (bp > LAST_ADDRESS)
return;

if (breakpoints.erase(bp) == 0) {
Expand All @@ -117,7 +117,7 @@ void MOS6502::deleteBreakpoint(const Word bp) {
}

void MOS6502::addBreakpoint(const Word bp) {
if (bp > MAX_MEM) {
if (bp > LAST_ADDRESS) {
fmt::print("Error: Breakpoint address outside of available "
"address range\n");
return;
Expand Down
10 changes: 5 additions & 5 deletions 6502/debug_commands.cc
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ bool MOS6502::loadCmd(std::string& line) {
std::istringstream iss(line);
iss >> fname >> std::hex >> address;

if (address > MOS6502::MAX_MEM) {
if (address > MOS6502::LAST_ADDRESS) {
fmt::print("Invalid address: {:04x}\n", address);
return false;
}
Expand Down Expand Up @@ -392,7 +392,7 @@ bool MOS6502::resetListPCCmd(std::string& line) {

try {
i = (Word) std::stoul(line, nullptr, 16);
if (i > MAX_MEM) {
if (i > LAST_ADDRESS) {
fmt::print("Error: Program Counter address outside of "
"available address range\n");
return false;
Expand Down Expand Up @@ -425,7 +425,7 @@ bool MOS6502::memdumpCmd(std::string& line) {
Word addr1, addr2, value;

auto rangeCheckAddr = [](Word a) {
return a <= MAX_MEM;
return a <= LAST_ADDRESS;
};

auto rangeCheckValue =[](Word v) {
Expand Down Expand Up @@ -648,7 +648,7 @@ bool MOS6502::watchCmd(std::string& line) {

try {
addr = (Word) std::stoul(line, nullptr, 16);
if (addr > MAX_MEM) {
if (addr > LAST_ADDRESS) {
fmt::print("Error: Watchpoint address outside of "
"available address range\n");
return false;
Expand Down Expand Up @@ -699,7 +699,7 @@ bool MOS6502::labelCmd(std::string& line) {
size_t index = 0;
addr = (Word) std::stoul(line, &index, 16);

if (addr > MAX_MEM) {
if (addr > LAST_ADDRESS) {
fmt::print("Error: Label address outside of available address range\n");
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions 6502/disassembler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -277,15 +277,15 @@ Word MOS6502::disassembleAt(Word dPC, std::string& disassembly) {
Word MOS6502::disassemble(Word dPC, uint64_t cnt) {
std::string disassembly;

if (dPC > MAX_MEM) {
if (dPC > LAST_ADDRESS) {
fmt::print("PC at end of memory");
return dPC;
}

do {
dPC = disassembleAt(dPC, disassembly);
fmt::print("{}\n", disassembly);
} while (--cnt && dPC < MAX_MEM);
} while (--cnt && dPC < LAST_ADDRESS);

return dPC;
}
Expand Down
2 changes: 1 addition & 1 deletion apple1/65C02-apple1.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ constexpr int clockSpeedMHz = 1;
constexpr Address PIA_BASE_ADDRESS = 0xd010;

// Create the memory, CPU, PIA and bus clock
Memory<Address, Byte> mem(MOS6502::MAX_MEM);
Memory<Address, Byte> mem(MOS6502::LAST_ADDRESS);
MOS65C02 cpu(mem);
auto pia = std::make_shared<MOS6820<Address, Byte>>();
BusClock_t busClock(clockSpeedMHz);
Expand Down
2 changes: 1 addition & 1 deletion apple1/apple1.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ constexpr int clockSpeedMHz = 1;
constexpr Address PIA_BASE_ADDRESS = 0xd010;

// Create the memory, CPU, PIA and bus clock
Memory<Address, Byte> mem(MOS6502::MAX_MEM);
Memory<Address, Byte> mem(MOS6502::LAST_ADDRESS);
MOS6502 cpu(mem);
auto pia = std::make_shared<MOS6820<Address, Byte>>();
BusClock_t busClock(clockSpeedMHz);
Expand Down
4 changes: 2 additions & 2 deletions tests/6502/6502_tests_adc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@

class MOS6502ADCTests : public testing::Test {
public:
Memory<Word, Byte> mem{MOS6502::MAX_MEM};
Memory<Word, Byte> mem{MOS6502::LAST_ADDRESS};
MOS6502 cpu{mem};


virtual void SetUp() {
mem.mapRAM(0, MOS6502::MAX_MEM);
mem.mapRAM(0, MOS6502::LAST_ADDRESS);
}

virtual void TearDown() {
Expand Down
4 changes: 2 additions & 2 deletions tests/6502/6502_tests_and.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@

class MOS6502ANDTests : public testing::Test {
public:
Memory<Word, Byte> mem{MOS6502::MAX_MEM};
Memory<Word, Byte> mem{MOS6502::LAST_ADDRESS};
MOS6502 cpu{mem};

virtual void SetUp() {
mem.mapRAM(0, MOS6502::MAX_MEM);
mem.mapRAM(0, MOS6502::LAST_ADDRESS);
}

virtual void TearDown() {
Expand Down
4 changes: 2 additions & 2 deletions tests/6502/6502_tests_asl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
class MOS6502ASLTests : public testing::Test {
public:

Memory<Word, Byte> mem{MOS6502::MAX_MEM};
Memory<Word, Byte> mem{MOS6502::LAST_ADDRESS};
MOS6502 cpu{mem};

virtual void SetUp() {
mem.mapRAM(0, MOS6502::MAX_MEM);
mem.mapRAM(0, MOS6502::LAST_ADDRESS);
}

virtual void TearDown() {
Expand Down
4 changes: 2 additions & 2 deletions tests/6502/6502_tests_bit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@

class MOS6502BITTests : public testing::Test {
public:
Memory<Word, Byte> mem{MOS6502::MAX_MEM};
Memory<Word, Byte> mem{MOS6502::LAST_ADDRESS};
MOS6502 cpu{mem};

virtual void SetUp() {
mem.mapRAM(0, MOS6502::MAX_MEM);
mem.mapRAM(0, MOS6502::LAST_ADDRESS);
}

virtual void TearDown() {
Expand Down
4 changes: 2 additions & 2 deletions tests/6502/6502_tests_branches.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
class MOS6502BranchTests : public testing::Test {
public:

Memory<Word, Byte> mem{MOS6502::MAX_MEM};
Memory<Word, Byte> mem{MOS6502::LAST_ADDRESS};
MOS6502 cpu{mem};

virtual void SetUp() {
mem.mapRAM(0, MOS6502::MAX_MEM);
mem.mapRAM(0, MOS6502::LAST_ADDRESS);
}

virtual void TearDown() {
Expand Down
4 changes: 2 additions & 2 deletions tests/6502/6502_tests_brk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
class MOS6502BRKTests : public testing::Test {
public:

Memory<Word, Byte> mem{MOS6502::MAX_MEM};
Memory<Word, Byte> mem{MOS6502::LAST_ADDRESS};
MOS6502 cpu{mem};

virtual void SetUp() {
mem.mapRAM(0, MOS6502::MAX_MEM);
mem.mapRAM(0, MOS6502::LAST_ADDRESS);
}

virtual void TearDown() {
Expand Down
4 changes: 2 additions & 2 deletions tests/6502/6502_tests_cmp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
class MOS6502CMPTests : public testing::Test {
public:

Memory<Word, Byte> mem{MOS6502::MAX_MEM};
Memory<Word, Byte> mem{MOS6502::LAST_ADDRESS};
MOS6502 cpu{mem};

virtual void SetUp() {
mem.mapRAM(0, MOS6502::MAX_MEM);
mem.mapRAM(0, MOS6502::LAST_ADDRESS);
}

virtual void TearDown() {
Expand Down
4 changes: 2 additions & 2 deletions tests/6502/6502_tests_dec_dex_dey.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@

class MOS6502DECTests : public testing::Test {
public:
Memory<Word, Byte> mem{MOS6502::MAX_MEM};
Memory<Word, Byte> mem{MOS6502::LAST_ADDRESS};
MOS6502 cpu{mem};

virtual void SetUp() {
mem.mapRAM(0, MOS6502::MAX_MEM);
mem.mapRAM(0, MOS6502::LAST_ADDRESS);
}

virtual void TearDown() {
Expand Down
4 changes: 2 additions & 2 deletions tests/6502/6502_tests_eor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
class MOS6502EORTests : public testing::Test {
public:

Memory<Word, Byte> mem{MOS6502::MAX_MEM};
Memory<Word, Byte> mem{MOS6502::LAST_ADDRESS};
MOS6502 cpu{mem};

virtual void SetUp() {
mem.mapRAM(0, MOS6502::MAX_MEM);
mem.mapRAM(0, MOS6502::LAST_ADDRESS);
}

virtual void TearDown() {
Expand Down
4 changes: 2 additions & 2 deletions tests/6502/6502_tests_flags.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
class MOS6502FlagTests : public testing::Test {
public:

Memory<Word, Byte> mem{MOS6502::MAX_MEM};
Memory<Word, Byte> mem{MOS6502::LAST_ADDRESS};
MOS6502 cpu{mem};

virtual void SetUp() {
mem.mapRAM(0, MOS6502::MAX_MEM);
mem.mapRAM(0, MOS6502::LAST_ADDRESS);
}

virtual void TearDown() {
Expand Down
4 changes: 2 additions & 2 deletions tests/6502/6502_tests_functional_test_suite.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@

class MOS6502FunctionalTestSuite : public testing::Test {
public:
Memory<Word, Byte> mem{MOS6502::MAX_MEM};
Memory<Word, Byte> mem{MOS6502::LAST_ADDRESS};
MOS6502 cpu{mem};

virtual void SetUp() {
mem.mapRAM(0, MOS6502::MAX_MEM);
mem.mapRAM(0, MOS6502::LAST_ADDRESS);
std::cout << "## Functional tests will drop into debugger in case of failure" << std::endl;
}

Expand Down
4 changes: 2 additions & 2 deletions tests/6502/6502_tests_inc_inx_iny.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
class MOS6502INCTests : public testing::Test {
public:

Memory<Word, Byte> mem{MOS6502::MAX_MEM};
Memory<Word, Byte> mem{MOS6502::LAST_ADDRESS};
MOS6502 cpu{mem};

virtual void SetUp() {
mem.mapRAM(0, MOS6502::MAX_MEM);
mem.mapRAM(0, MOS6502::LAST_ADDRESS);
}

virtual void TearDown() {
Expand Down
4 changes: 2 additions & 2 deletions tests/6502/6502_tests_interrupt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
class MOS6502InterruptTests : public testing::Test {
public:

Memory<Word, Byte> mem{MOS6502::MAX_MEM};
Memory<Word, Byte> mem{MOS6502::LAST_ADDRESS};
MOS6502 cpu{mem};

virtual void SetUp() {
mem.mapRAM(0, MOS6502::MAX_MEM);
mem.mapRAM(0, MOS6502::LAST_ADDRESS);
}

virtual void TearDown() {
Expand Down
4 changes: 2 additions & 2 deletions tests/6502/6502_tests_invalid_instruction.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
class MOS6502OpcodeTests : public testing::Test {
public:

Memory<Word, Byte> mem{MOS6502::MAX_MEM};
Memory<Word, Byte> mem{MOS6502::LAST_ADDRESS};
MOS6502 cpu{mem};

virtual void SetUp() {
mem.mapRAM(0, MOS6502::MAX_MEM);
mem.mapRAM(0, MOS6502::LAST_ADDRESS);
}

virtual void TearDown() {
Expand Down
4 changes: 2 additions & 2 deletions tests/6502/6502_tests_jmp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
class MOS6502JMPTests : public testing::Test {
public:

Memory<Word, Byte> mem{MOS6502::MAX_MEM};
Memory<Word, Byte> mem{MOS6502::LAST_ADDRESS};
MOS6502 cpu{mem};

virtual void SetUp() {
mem.mapRAM(0, MOS6502::MAX_MEM);
mem.mapRAM(0, MOS6502::LAST_ADDRESS);
}

virtual void TearDown() {
Expand Down
4 changes: 2 additions & 2 deletions tests/6502/6502_tests_jsr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
class MOS6502JSRTests : public testing::Test {
public:

Memory<Word, Byte> mem{MOS6502::MAX_MEM};
Memory<Word, Byte> mem{MOS6502::LAST_ADDRESS};
MOS6502 cpu{mem};

virtual void SetUp() {
mem.mapRAM(0, MOS6502::MAX_MEM);
mem.mapRAM(0, MOS6502::LAST_ADDRESS);
}

virtual void TearDown() {
Expand Down
4 changes: 2 additions & 2 deletions tests/6502/6502_tests_lda_ldy_ldx.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
class MOS6502LDTests : public testing::Test {
public:

Memory<Word, Byte> mem{MOS6502::MAX_MEM};
Memory<Word, Byte> mem{MOS6502::LAST_ADDRESS};
MOS6502 cpu{mem};

enum class Registers {
Expand All @@ -32,7 +32,7 @@ class MOS6502LDTests : public testing::Test {
};

virtual void SetUp() {
mem.mapRAM(0, MOS6502::MAX_MEM);
mem.mapRAM(0, MOS6502::LAST_ADDRESS);
}

virtual void TearDown() {
Expand Down
Loading

0 comments on commit 337f96b

Please sign in to comment.