Skip to content

Commit

Permalink
const'ify all the things, cleanup functional test names
Browse files Browse the repository at this point in the history
  • Loading branch information
wfd3 committed Feb 4, 2024
1 parent b0c956a commit 78e72f5
Show file tree
Hide file tree
Showing 13 changed files with 218 additions and 198 deletions.
38 changes: 19 additions & 19 deletions 6502/6502.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
// You should have received a copy of the GNU General Public License along with
// this program. If not, see <http://www.gnu.org/licenses/>.

#include "6502.h"
#include <6502.h>

//////////
// CPU Setup and reset
Expand All @@ -28,11 +28,11 @@ MOS6502::MOS6502(Memory<Address_t, Byte>& m) : mem(m),
initDebugger();
}

void MOS6502::setResetVector(Word address) {
void MOS6502::setResetVector(const Word address) {
writeWord(RESET_VECTOR, address);
}

void MOS6502::setInterruptVector(Word address) {
void MOS6502::setInterruptVector(const Word address) {
writeWord(INTERRUPT_VECTOR, address);
}
void MOS6502::setPendingReset() {
Expand Down Expand Up @@ -64,7 +64,7 @@ void MOS6502::unsetHaltAddress() {
_haltAddressSet = false;
}

void MOS6502::setHaltAddress(Address_t _pc) {
void MOS6502::setHaltAddress(const Word _pc) {
_haltAddress = _pc;
_haltAddressSet = true;
}
Expand All @@ -73,7 +73,7 @@ bool MOS6502::isPCAtHaltAddress() {
return _haltAddressSet && (PC == _haltAddress);
}

void MOS6502::loopDetection(bool l) {
void MOS6502::loopDetection(const bool l) {
debug_loopDetection = l;
}

Expand All @@ -85,7 +85,7 @@ bool MOS6502::isInDebugMode() {
return _debugMode;
}

void MOS6502::setDebugMode(bool m) {
void MOS6502::setDebugMode(const bool m) {
_debugMode = m;
}

Expand Down Expand Up @@ -130,7 +130,7 @@ void MOS6502::exitReset() {
// Stack Pointer values, exits reset so that the next call to execute...()
// executes code.
#ifdef TEST_BUILD
void MOS6502::TestReset(Word initialPC, Byte initialSP) {
void MOS6502::TestReset(const Word initialPC, const Byte initialSP) {
_inReset = true;
_pendingReset = true;
_testReset = true;
Expand Down Expand Up @@ -190,7 +190,7 @@ bool MOS6502::IRQ() {

//////////
// CPU Exception
void MOS6502::exception(const std::string &message) {
void MOS6502::exception(const std::string& message) {
std::string msg = "CPU Exception: " + message;
_hitException = true;

Expand All @@ -202,15 +202,15 @@ void MOS6502::exception(const std::string &message) {

//////////
// Flags
bool MOS6502::isNegative(Byte val) {
bool MOS6502::isNegative(const Byte val) {
return (val & NegativeBit);
}

void MOS6502::setFlagNByValue(Byte val) {
void MOS6502::setFlagNByValue(const Byte val) {
Flags.N = isNegative(val);
}

void MOS6502::setFlagZByValue(Byte val) {
void MOS6502::setFlagZByValue(const Byte val) {
Flags.Z = (val == 0);
}

Expand All @@ -220,23 +220,23 @@ bool MOS6502::IRQBlocked() {

//////////
// Memory access
Byte MOS6502::readByte(Word address) {
Byte MOS6502::readByte(const Word address) {
Byte data = mem.Read(address);
Cycles++;
return data;
}

void MOS6502::writeByte(Word address, Byte value) {
void MOS6502::writeByte(const Word address, const Byte value) {
mem.Write(address, value);
Cycles++;
}

Word MOS6502::readWord(Word address) {
Word MOS6502::readWord(const Word address) {
Word w = readByte(address) | (readByte(address + 1) << 8);
return w;
}

void MOS6502::writeWord(Word address, Word word) {
void MOS6502::writeWord(const Word address, const Word word) {
writeByte(address, word & 0xff);
writeByte(address + 1, (Byte) (word >> 8));
}
Expand All @@ -254,7 +254,7 @@ Byte MOS6502::readByteAtPC() {

//////////
// Stack operations
void MOS6502::push(Byte value) {
void MOS6502::push(const Byte value) {
Word SPAddress = STACK_FRAME + SP;
writeByte(SPAddress, value);
SP--;
Expand All @@ -267,7 +267,7 @@ Byte MOS6502::pop() {
return readByte(SPAddress);
}

void MOS6502::pushWord(Word value) {
void MOS6502::pushWord(const Word value) {
push((Byte) (value >> 8)); // value high
push((Byte) value & 0xff); // value low
}
Expand All @@ -292,7 +292,7 @@ void MOS6502::popPS() {

//////////
// Address decoding
Word MOS6502::getAddress(Byte opcode) {
Word MOS6502::getAddress(const Byte opcode) {
Word address;
SByte rel;

Expand Down Expand Up @@ -379,7 +379,7 @@ Word MOS6502::getAddress(Byte opcode) {
return address;
}

Byte MOS6502::getData(Byte opcode) {
Byte MOS6502::getData(const Byte opcode) {
Byte data = 0;
Word address;

Expand Down
50 changes: 25 additions & 25 deletions 6502/6502.h
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ class MOS6502 {
using _instructionMap_t = std::map<Byte, instruction>;
_instructionMap_t _instructions;

std::map<Byte, instruction> setupInstructionMap();
const _instructionMap_t setupInstructionMap();

// CPU functions
void exception(const std::string &);
Expand Down Expand Up @@ -528,30 +528,30 @@ class MOS6502 {

static std::vector<debugCommand> setupDebugCommands();
bool matchCommand(const std::string &, debugFn_t &);
bool helpCmd(std::string &);
bool listCmd(std::string &);
bool loadCmd(std::string &);
bool stackCmd(std::string &);
bool breakpointCmd(std::string &);
bool cpustateCmd(std::string &);
bool autostateCmd(std::string &);
bool resetListPCCmd(std::string &);
bool memdumpCmd(std::string &);
bool memmapCmd(std::string &);
bool setCmd(std::string &);
bool resetCmd(std::string &);
bool continueCmd(std::string &);
bool loopdetectCmd(std::string &);
bool backtraceCmd(std::string &);
bool labelCmd(std::string &);
bool whereCmd(std::string &);
bool watchCmd(std::string &);
bool quitCmd(std::string &);
bool findCmd(std::string &);
bool clockCmd(std::string &);
bool loadScriptCmd(std::string &);
bool savememCmd(std::string &);
bool loadhexCmd(std::string &);
bool helpCmd(std::string&);
bool listCmd(std::string&);
bool loadCmd(std::string&);
bool stackCmd(std::string&);
bool breakpointCmd(std::string&);
bool cpustateCmd(std::string&);
bool autostateCmd(std::string&);
bool resetListPCCmd(std::string&);
bool memdumpCmd(std::string&);
bool memmapCmd(std::string&);
bool setCmd(std::string&);
bool resetCmd(std::string&);
bool continueCmd(std::string&);
bool loopdetectCmd(std::string&);
bool backtraceCmd(std::string&);
bool labelCmd(std::string&);
bool whereCmd(std::string&);
bool watchCmd(std::string&);
bool quitCmd(std::string&);
bool findCmd(std::string&);
bool clockCmd(std::string&);
bool loadScriptCmd(std::string&);
bool savememCmd(std::string&);
bool loadhexCmd(std::string&);

// Hex file
bool loadHexFile(const std::string&);
Expand Down
12 changes: 6 additions & 6 deletions 6502/debug.cc
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,13 @@ bool MOS6502::isPCBreakpoint() {
return isBreakpoint(PC);
}

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

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

Expand All @@ -116,7 +116,7 @@ void MOS6502::deleteBreakpoint(Word bp) {
fmt::print("\n");
}

void MOS6502::addBreakpoint(Word bp) {
void MOS6502::addBreakpoint(const Word bp) {
if (bp > MAX_MEM) {
fmt::print("Error: Breakpoint address outside of available "
"address range\n");
Expand Down Expand Up @@ -151,13 +151,13 @@ void MOS6502::showBacktrace() {
fmt::print("#{:02d}: {}\n", cnt++, (*i).c_str());
}

void MOS6502::addBacktrace(Word backtracePC) {
void MOS6502::addBacktrace(const Word backtracePC) {
std::string ins;
disassembleAt(backtracePC, ins);
backtrace.push_back(ins);
}

void MOS6502::addBacktraceInterrupt(Word backtracePC) {
void MOS6502::addBacktraceInterrupt(const Word backtracePC) {
std::string ins;
disassembleAt(backtracePC, ins);
ins += " [IRQ/NMI]";
Expand Down Expand Up @@ -339,7 +339,7 @@ bool MOS6502::saveToHexFile(const std::string& filename, const std::vector<std::
return true;
}

bool MOS6502::saveToHexFile(const std::string& filename, Word startAddress, Word endAddress) {
bool MOS6502::saveToHexFile(const std::string& filename, const Word startAddress, const Word endAddress) {
std::vector<std::pair<Word, Word>> range = {{startAddress, endAddress}};
return saveToHexFile(filename, range);
}
Expand Down
Loading

0 comments on commit 78e72f5

Please sign in to comment.