diff --git a/src/cheat/BankRomCheat.hxx b/src/cheat/BankRomCheat.hxx index 01930a4de..ea39ba66a 100644 --- a/src/cheat/BankRomCheat.hxx +++ b/src/cheat/BankRomCheat.hxx @@ -31,7 +31,7 @@ class BankRomCheat : public Cheat void evaluate() override; private: - uInt8 savedRom[16]; + std::array savedRom; uInt16 address; uInt8 value; uInt8 count; diff --git a/src/cheat/CheetahCheat.hxx b/src/cheat/CheetahCheat.hxx index 51c16a1d7..35fa958eb 100644 --- a/src/cheat/CheetahCheat.hxx +++ b/src/cheat/CheetahCheat.hxx @@ -31,7 +31,7 @@ class CheetahCheat : public Cheat void evaluate() override; private: - uInt8 savedRom[16]; + std::array savedRom; uInt16 address; uInt8 value; uInt8 count; diff --git a/src/common/Stack.hxx b/src/common/Stack.hxx index b0d9c55f8..03eefd548 100644 --- a/src/common/Stack.hxx +++ b/src/common/Stack.hxx @@ -18,7 +18,6 @@ #ifndef STACK_HXX #define STACK_HXX -#include #include #include "bspf.hxx" @@ -32,7 +31,7 @@ template class FixedStack { private: - array _stack; + std::array _stack; uInt32 _size; public: diff --git a/src/common/ZipHandler.hxx b/src/common/ZipHandler.hxx index 3d878bd3b..33e72f826 100644 --- a/src/common/ZipHandler.hxx +++ b/src/common/ZipHandler.hxx @@ -20,8 +20,6 @@ #ifndef ZIP_HANDLER_HXX #define ZIP_HANDLER_HXX -#include - #include "bspf.hxx" /** @@ -305,7 +303,7 @@ class ZipHandler void addToCache(); private: - static constexpr uInt32 DECOMPRESS_BUFSIZE = 16384; + static constexpr uInt32 DECOMPRESS_BUFSIZE = 16_KB; static constexpr uInt32 CACHE_SIZE = 8; // number of open files to cache ZipFilePtr myZip; diff --git a/src/debugger/CartDebug.hxx b/src/debugger/CartDebug.hxx index 77f24e070..84bc29975 100644 --- a/src/debugger/CartDebug.hxx +++ b/src/debugger/CartDebug.hxx @@ -47,7 +47,7 @@ class CartDebug : public DebuggerSystem friend class DiStella; public: - enum DisasmType { // TODO - make this 'enum class' + enum DisasmType { NONE = 0, REFERENCED = 1 << 0, /* 0x01, code somewhere in the program references it, i.e. LDA $F372 referenced $F372 */ @@ -283,10 +283,10 @@ class CartDebug : public DebuggerSystem // Information on equates used in the disassembly struct ReservedEquates { - bool TIARead[16]; - bool TIAWrite[64]; - bool IOReadWrite[24]; - bool ZPRAM[128]; + std::array TIARead; + std::array TIAWrite; + std::array IOReadWrite; + std::array ZPRAM; AddrToLabel Label; bool breakFound; }; diff --git a/src/debugger/Debugger.cxx b/src/debugger/Debugger.cxx index 9724c0ba2..2e4203b3b 100644 --- a/src/debugger/Debugger.cxx +++ b/src/debugger/Debugger.cxx @@ -178,13 +178,12 @@ string Debugger::autoExec(StringList* history) buf << myParser->exec(romname, history) << endl; // Init builtins - for(uInt32 i = 0; i < NUM_BUILTIN_FUNCS; ++i) + for(const auto& func: ourBuiltinFunctions) { // TODO - check this for memory leaks - int res = YaccParser::parse(ourBuiltinFunctions[i].defn); + int res = YaccParser::parse(func.defn); if(res == 0) - addFunction(ourBuiltinFunctions[i].name, ourBuiltinFunctions[i].defn, - YaccParser::getResult(), true); + addFunction(func.name, func.defn, YaccParser::getResult(), true); else cerr << "ERROR in builtin function!" << endl; } @@ -716,8 +715,8 @@ bool Debugger::addFunction(const string& name, const string& definition, // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool Debugger::isBuiltinFunction(const string& name) { - for(uInt32 i = 0; i < NUM_BUILTIN_FUNCS; ++i) - if(name == ourBuiltinFunctions[i].name) + for(const auto& func: ourBuiltinFunctions) + if(name == func.name) return true; return false; } @@ -758,7 +757,7 @@ const string& Debugger::getFunctionDef(const string& name) const } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -const FunctionDefMap Debugger::getFunctionDefMap() const +const Debugger::FunctionDefMap Debugger::getFunctionDefMap() const { return myFunctionDefs; } @@ -770,39 +769,39 @@ string Debugger::builtinHelp() const uInt32 len, c_maxlen = 0, i_maxlen = 0; // Get column widths for aligned output (functions) - for(uInt32 i = 0; i < NUM_BUILTIN_FUNCS; ++i) + for(const auto& func: ourBuiltinFunctions) { - len = uInt32(ourBuiltinFunctions[i].name.size()); + len = uInt32(func.name.size()); if(len > c_maxlen) c_maxlen = len; - len = uInt32(ourBuiltinFunctions[i].defn.size()); + len = uInt32(func.defn.size()); if(len > i_maxlen) i_maxlen = len; } buf << std::setfill(' ') << endl << "Built-in functions:" << endl; - for(uInt32 i = 0; i < NUM_BUILTIN_FUNCS; ++i) + for(const auto& func: ourBuiltinFunctions) { - buf << std::setw(c_maxlen) << std::left << ourBuiltinFunctions[i].name + buf << std::setw(c_maxlen) << std::left << func.name << std::setw(2) << std::right << "{" - << std::setw(i_maxlen) << std::left << ourBuiltinFunctions[i].defn + << std::setw(i_maxlen) << std::left << func.defn << std::setw(4) << "}" - << ourBuiltinFunctions[i].help + << func.help << endl; } // Get column widths for aligned output (pseudo-registers) c_maxlen = 0; - for(uInt32 i = 0; i < NUM_PSEUDO_REGS; ++i) + for(const auto& reg: ourPseudoRegisters) { - len = uInt32(ourPseudoRegisters[i].name.size()); + len = uInt32(reg.name.size()); if(len > c_maxlen) c_maxlen = len; } buf << endl << "Pseudo-registers:" << endl; - for(uInt32 i = 0; i < NUM_PSEUDO_REGS; ++i) + for(const auto& reg: ourPseudoRegisters) { - buf << std::setw(c_maxlen) << std::left << ourPseudoRegisters[i].name + buf << std::setw(c_maxlen) << std::left << reg.name << std::setw(2) << " " - << std::setw(i_maxlen) << std::left << ourPseudoRegisters[i].help + << std::setw(i_maxlen) << std::left << reg.help << endl; } @@ -822,9 +821,9 @@ void Debugger::getCompletions(const char* in, StringList& list) const list.push_back(l); } - for(uInt32 i = 0; i < NUM_PSEUDO_REGS; ++i) - if(BSPF::matches(ourPseudoRegisters[i].name, in)) - list.push_back(ourPseudoRegisters[i].name); + for(const auto& reg: ourPseudoRegisters) + if(BSPF::matches(reg.name, in)) + list.push_back(reg.name); } } @@ -849,7 +848,7 @@ bool Debugger::canExit() const } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Debugger::BuiltinFunction Debugger::ourBuiltinFunctions[NUM_BUILTIN_FUNCS] = { +std::array Debugger::ourBuiltinFunctions = { { // left joystick: { "_joy0left", "!(*SWCHA & $40)", "Left joystick moved left" }, { "_joy0right", "!(*SWCHA & $80)", "Left joystick moved right" }, @@ -873,11 +872,12 @@ Debugger::BuiltinFunction Debugger::ourBuiltinFunctions[NUM_BUILTIN_FUNCS] = { { "_diff0a", "*SWCHB & $40", "Left diff. set to A (hard)" }, { "_diff1b", "!(*SWCHB & $80)", "Right diff. set to B (easy)" }, { "_diff1a", "*SWCHB & $80", "Right diff. set to A (hard)" } -}; +} }; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // Names are defined here, but processed in YaccParser -Debugger::PseudoRegister Debugger::ourPseudoRegisters[NUM_PSEUDO_REGS] = { +std::array Debugger::ourPseudoRegisters = { { +// Debugger::PseudoRegister Debugger::ourPseudoRegisters[NUM_PSEUDO_REGS] = { { "_bank", "Currently selected bank" }, { "_cclocks", "Color clocks on current scanline" }, { "_cycleshi", "Higher 32 bits of number of cycles since emulation started" }, @@ -892,4 +892,4 @@ Debugger::PseudoRegister Debugger::ourPseudoRegisters[NUM_PSEUDO_REGS] = { // CPU address access functions: /*{ "__lastread", "last CPU read address" }, { "__lastwrite", "last CPU write address" },*/ -}; +} }; diff --git a/src/debugger/Debugger.hxx b/src/debugger/Debugger.hxx index f9f1ca925..7eda40551 100644 --- a/src/debugger/Debugger.hxx +++ b/src/debugger/Debugger.hxx @@ -49,9 +49,6 @@ class RewindManager; #include "FrameBufferConstants.hxx" #include "bspf.hxx" -using FunctionMap = std::map>; -using FunctionDefMap = std::map; - /** The base dialog for all debugging widgets in Stella. Also acts as the parent for all debugging operations in Stella (parser, 6502 debugger, etc). @@ -68,6 +65,9 @@ class Debugger : public DialogContainer friend class M6502; public: + using FunctionMap = std::map>; + using FunctionDefMap = std::map; + /** Create a new debugger parent object */ @@ -361,10 +361,8 @@ class Debugger : public DialogContainer struct PseudoRegister { string name, help; }; - static const uInt32 NUM_BUILTIN_FUNCS = 18; - static const uInt32 NUM_PSEUDO_REGS = 11; - static BuiltinFunction ourBuiltinFunctions[NUM_BUILTIN_FUNCS]; - static PseudoRegister ourPseudoRegisters[NUM_PSEUDO_REGS]; + static std::array ourBuiltinFunctions; + static std::array ourPseudoRegisters; private: // rewind/unwind n states diff --git a/src/debugger/DebuggerParser.cxx b/src/debugger/DebuggerParser.cxx index 3d61958a9..57c2bb5fc 100644 --- a/src/debugger/DebuggerParser.cxx +++ b/src/debugger/DebuggerParser.cxx @@ -108,7 +108,7 @@ string DebuggerParser::run(const string& command) getArgs(command, verb); commandResult.str(""); - for(uInt32 i = 0; i < NumCommands; ++i) + for(size_t i = 0; i < commands.size(); ++i) { if(BSPF::equalsIgnoreCase(verb, commands[i].cmdString)) { @@ -175,10 +175,10 @@ void DebuggerParser::outputCommandError(const string& errorMsg, int command) void DebuggerParser::getCompletions(const char* in, StringList& completions) const { // cerr << "Attempting to complete \"" << in << "\"" << endl; - for(uInt32 i = 0; i < NumCommands; ++i) + for(const auto& c: commands) { - if(BSPF::matches(commands[i].cmdString, in)) - completions.push_back(commands[i].cmdString); + if(BSPF::matches(c.cmdString, in)) + completions.push_back(c.cmdString); } } @@ -639,7 +639,7 @@ string DebuggerParser::saveScriptFile(string file) if(!out.is_open()) return "Unable to save script to " + node.getShortPath(); - FunctionDefMap funcs = debugger.getFunctionDefMap(); + Debugger::FunctionDefMap funcs = debugger.getFunctionDefMap(); for(const auto& f: funcs) if (!debugger.isBuiltinFunction(f.first)) out << "function " << f.first << " {" << f.second << "}" << endl; @@ -1300,27 +1300,26 @@ void DebuggerParser::executeHelp() { // Find length of longest command uInt32 clen = 0; - for(uInt32 i = 0; i < NumCommands; ++i) + for(const auto& c: commands) { - uInt32 len = uInt32(commands[i].cmdString.length()); + uInt32 len = uInt32(c.cmdString.length()); if(len > clen) clen = len; } commandResult << setfill(' '); - for(uInt32 i = 0; i < NumCommands; ++i) - commandResult << setw(clen) << right << commands[i].cmdString - << " - " << commands[i].description << endl; + for(const auto& c: commands) + commandResult << setw(clen) << right << c.cmdString + << " - " << c.description << endl; commandResult << debugger.builtinHelp(); } else // get help for specific command { - for(uInt32 i = 0; i < NumCommands; ++i) + for(const auto& c: commands) { - if(argStrings[0] == commands[i].cmdString) + if(argStrings[0] == c.cmdString) { - commandResult << " " << red(commands[i].description) << endl - << commands[i].extendedDesc; + commandResult << " " << red(c.description) << endl << c.extendedDesc; break; } } @@ -1521,7 +1520,7 @@ void DebuggerParser::executeListconfig() // "listfunctions" void DebuggerParser::executeListfunctions() { - const FunctionDefMap& functions = debugger.getFunctionDefMap(); + const Debugger::FunctionDefMap& functions = debugger.getFunctionDefMap(); if(functions.size() > 0) { @@ -2306,7 +2305,7 @@ void DebuggerParser::executeZ() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // List of all commands available to the parser -DebuggerParser::Command DebuggerParser::commands[NumCommands] = { +std::array DebuggerParser::commands = { { { "a", "Set Accumulator to ", @@ -3276,4 +3275,4 @@ DebuggerParser::Command DebuggerParser::commands[NumCommands] = { { Parameters::ARG_BOOL, Parameters::ARG_END_ARGS }, std::mem_fn(&DebuggerParser::executeZ) } -}; +} }; diff --git a/src/debugger/DebuggerParser.hxx b/src/debugger/DebuggerParser.hxx index 9da8e7ae1..26ea6acac 100644 --- a/src/debugger/DebuggerParser.hxx +++ b/src/debugger/DebuggerParser.hxx @@ -88,7 +88,6 @@ class DebuggerParser }; // List of commands available - static constexpr uInt32 NumCommands = 95; struct Command { string cmdString; string description; @@ -98,7 +97,7 @@ class DebuggerParser Parameters parms[10]; std::function executor; }; - static Command commands[NumCommands]; + static std::array commands; struct Trap { diff --git a/src/debugger/DiStella.cxx b/src/debugger/DiStella.cxx index afeea3e93..5aa588f85 100644 --- a/src/debugger/DiStella.cxx +++ b/src/debugger/DiStella.cxx @@ -1132,7 +1132,7 @@ DiStella::Settings DiStella::settings = { }; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -const DiStella::Instruction_tag DiStella::ourLookup[256] = { +const std::array DiStella::ourLookup = { { /**** Positive ****/ /* 00 */{"brk", AddressingMode::IMPLIED, AccessMode::NONE, RWMode::NONE, 7, 1}, /* Pseudo Absolute */ @@ -1458,4 +1458,4 @@ const DiStella::Instruction_tag DiStella::ourLookup[256] = { /* fd */{"sbc", AddressingMode::ABSOLUTE_X, AccessMode::ABSX, RWMode::READ, 4, 3}, /* Absolute,X */ /* fe */{"inc", AddressingMode::ABSOLUTE_X, AccessMode::ABSX, RWMode::WRITE, 7, 3}, /* Absolute,X */ /* ff */{"ISB", AddressingMode::ABSOLUTE_X, AccessMode::ABSX, RWMode::WRITE, 7, 3} -}; +} }; diff --git a/src/debugger/DiStella.hxx b/src/debugger/DiStella.hxx index 5ed4e8a33..16fe96592 100644 --- a/src/debugger/DiStella.hxx +++ b/src/debugger/DiStella.hxx @@ -192,7 +192,7 @@ class DiStella uInt8 cycles; uInt8 bytes; }; - static const Instruction_tag ourLookup[256]; + static const std::array ourLookup; private: // Following constructors and assignment operators not supported diff --git a/src/debugger/TIADebug.cxx b/src/debugger/TIADebug.cxx index 3ac7e57a7..bd9adac1c 100644 --- a/src/debugger/TIADebug.cxx +++ b/src/debugger/TIADebug.cxx @@ -28,14 +28,6 @@ TIADebug::TIADebug(Debugger& dbg, Console& console) : DebuggerSystem(dbg, console), myTIA(console.tia()) { - nusizStrings[0] = "1 copy"; - nusizStrings[1] = "2 copies - close (8)"; - nusizStrings[2] = "2 copies - med (24)"; - nusizStrings[3] = "3 copies - close (8)"; - nusizStrings[4] = "2 copies - wide (56)"; - nusizStrings[5] = "2x (16) sized player"; - nusizStrings[6] = "3 copies - med (24)"; - nusizStrings[7] = "4x (32) sized player"; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -1160,3 +1152,15 @@ string TIADebug::toString() // note: last line should not contain \n, caller will add. return buf.str(); } + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +const std::array TIADebug::nusizStrings = { + "1 copy", + "2 copies - close (8)", + "2 copies - med (24)", + "3 copies - close (8)", + "2 copies - wide (56)", + "2x (16) sized player", + "3 copies - med (24)", + "4x (32) sized player" +}; diff --git a/src/debugger/TIADebug.hxx b/src/debugger/TIADebug.hxx index 311aea4f0..823ee4434 100644 --- a/src/debugger/TIADebug.hxx +++ b/src/debugger/TIADebug.hxx @@ -189,7 +189,7 @@ class TIADebug : public DebuggerSystem TIA& myTIA; - string nusizStrings[8]; + static const std::array nusizStrings; private: // Following constructors and assignment operators not supported