A few more std::array updates.

This commit is contained in:
Stephen Anthony 2019-09-22 20:42:46 -02:30
parent 700fbd9c91
commit f591ba92ce
13 changed files with 73 additions and 76 deletions

View File

@ -31,7 +31,7 @@ class BankRomCheat : public Cheat
void evaluate() override; void evaluate() override;
private: private:
uInt8 savedRom[16]; std::array<uInt8, 16> savedRom;
uInt16 address; uInt16 address;
uInt8 value; uInt8 value;
uInt8 count; uInt8 count;

View File

@ -31,7 +31,7 @@ class CheetahCheat : public Cheat
void evaluate() override; void evaluate() override;
private: private:
uInt8 savedRom[16]; std::array<uInt8, 16> savedRom;
uInt16 address; uInt16 address;
uInt8 value; uInt8 value;
uInt8 count; uInt8 count;

View File

@ -18,7 +18,6 @@
#ifndef STACK_HXX #ifndef STACK_HXX
#define STACK_HXX #define STACK_HXX
#include <array>
#include <functional> #include <functional>
#include "bspf.hxx" #include "bspf.hxx"
@ -32,7 +31,7 @@ template <class T, uInt32 CAPACITY = 50>
class FixedStack class FixedStack
{ {
private: private:
array<T, CAPACITY> _stack; std::array<T, CAPACITY> _stack;
uInt32 _size; uInt32 _size;
public: public:

View File

@ -20,8 +20,6 @@
#ifndef ZIP_HANDLER_HXX #ifndef ZIP_HANDLER_HXX
#define ZIP_HANDLER_HXX #define ZIP_HANDLER_HXX
#include <array>
#include "bspf.hxx" #include "bspf.hxx"
/** /**
@ -305,7 +303,7 @@ class ZipHandler
void addToCache(); void addToCache();
private: 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 static constexpr uInt32 CACHE_SIZE = 8; // number of open files to cache
ZipFilePtr myZip; ZipFilePtr myZip;

View File

@ -47,7 +47,7 @@ class CartDebug : public DebuggerSystem
friend class DiStella; friend class DiStella;
public: public:
enum DisasmType { // TODO - make this 'enum class' enum DisasmType {
NONE = 0, NONE = 0,
REFERENCED = 1 << 0, /* 0x01, code somewhere in the program references it, REFERENCED = 1 << 0, /* 0x01, code somewhere in the program references it,
i.e. LDA $F372 referenced $F372 */ i.e. LDA $F372 referenced $F372 */
@ -283,10 +283,10 @@ class CartDebug : public DebuggerSystem
// Information on equates used in the disassembly // Information on equates used in the disassembly
struct ReservedEquates { struct ReservedEquates {
bool TIARead[16]; std::array<bool, 16> TIARead;
bool TIAWrite[64]; std::array<bool, 64> TIAWrite;
bool IOReadWrite[24]; std::array<bool, 24> IOReadWrite;
bool ZPRAM[128]; std::array<bool, 128> ZPRAM;
AddrToLabel Label; AddrToLabel Label;
bool breakFound; bool breakFound;
}; };

View File

@ -178,13 +178,12 @@ string Debugger::autoExec(StringList* history)
buf << myParser->exec(romname, history) << endl; buf << myParser->exec(romname, history) << endl;
// Init builtins // Init builtins
for(uInt32 i = 0; i < NUM_BUILTIN_FUNCS; ++i) for(const auto& func: ourBuiltinFunctions)
{ {
// TODO - check this for memory leaks // TODO - check this for memory leaks
int res = YaccParser::parse(ourBuiltinFunctions[i].defn); int res = YaccParser::parse(func.defn);
if(res == 0) if(res == 0)
addFunction(ourBuiltinFunctions[i].name, ourBuiltinFunctions[i].defn, addFunction(func.name, func.defn, YaccParser::getResult(), true);
YaccParser::getResult(), true);
else else
cerr << "ERROR in builtin function!" << endl; 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) bool Debugger::isBuiltinFunction(const string& name)
{ {
for(uInt32 i = 0; i < NUM_BUILTIN_FUNCS; ++i) for(const auto& func: ourBuiltinFunctions)
if(name == ourBuiltinFunctions[i].name) if(name == func.name)
return true; return true;
return false; 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; return myFunctionDefs;
} }
@ -770,39 +769,39 @@ string Debugger::builtinHelp() const
uInt32 len, c_maxlen = 0, i_maxlen = 0; uInt32 len, c_maxlen = 0, i_maxlen = 0;
// Get column widths for aligned output (functions) // 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; 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; if(len > i_maxlen) i_maxlen = len;
} }
buf << std::setfill(' ') << endl << "Built-in functions:" << endl; 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(2) << std::right << "{"
<< std::setw(i_maxlen) << std::left << ourBuiltinFunctions[i].defn << std::setw(i_maxlen) << std::left << func.defn
<< std::setw(4) << "}" << std::setw(4) << "}"
<< ourBuiltinFunctions[i].help << func.help
<< endl; << endl;
} }
// Get column widths for aligned output (pseudo-registers) // Get column widths for aligned output (pseudo-registers)
c_maxlen = 0; 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; if(len > c_maxlen) c_maxlen = len;
} }
buf << endl << "Pseudo-registers:" << endl; 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(2) << " "
<< std::setw(i_maxlen) << std::left << ourPseudoRegisters[i].help << std::setw(i_maxlen) << std::left << reg.help
<< endl; << endl;
} }
@ -822,9 +821,9 @@ void Debugger::getCompletions(const char* in, StringList& list) const
list.push_back(l); list.push_back(l);
} }
for(uInt32 i = 0; i < NUM_PSEUDO_REGS; ++i) for(const auto& reg: ourPseudoRegisters)
if(BSPF::matches(ourPseudoRegisters[i].name, in)) if(BSPF::matches(reg.name, in))
list.push_back(ourPseudoRegisters[i].name); list.push_back(reg.name);
} }
} }
@ -849,7 +848,7 @@ bool Debugger::canExit() const
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Debugger::BuiltinFunction Debugger::ourBuiltinFunctions[NUM_BUILTIN_FUNCS] = { std::array<Debugger::BuiltinFunction, 18> Debugger::ourBuiltinFunctions = { {
// left joystick: // left joystick:
{ "_joy0left", "!(*SWCHA & $40)", "Left joystick moved left" }, { "_joy0left", "!(*SWCHA & $40)", "Left joystick moved left" },
{ "_joy0right", "!(*SWCHA & $80)", "Left joystick moved right" }, { "_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)" }, { "_diff0a", "*SWCHB & $40", "Left diff. set to A (hard)" },
{ "_diff1b", "!(*SWCHB & $80)", "Right diff. set to B (easy)" }, { "_diff1b", "!(*SWCHB & $80)", "Right diff. set to B (easy)" },
{ "_diff1a", "*SWCHB & $80", "Right diff. set to A (hard)" } { "_diff1a", "*SWCHB & $80", "Right diff. set to A (hard)" }
}; } };
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Names are defined here, but processed in YaccParser // Names are defined here, but processed in YaccParser
Debugger::PseudoRegister Debugger::ourPseudoRegisters[NUM_PSEUDO_REGS] = { std::array<Debugger::PseudoRegister, 11> Debugger::ourPseudoRegisters = { {
// Debugger::PseudoRegister Debugger::ourPseudoRegisters[NUM_PSEUDO_REGS] = {
{ "_bank", "Currently selected bank" }, { "_bank", "Currently selected bank" },
{ "_cclocks", "Color clocks on current scanline" }, { "_cclocks", "Color clocks on current scanline" },
{ "_cycleshi", "Higher 32 bits of number of cycles since emulation started" }, { "_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: // CPU address access functions:
/*{ "__lastread", "last CPU read address" }, /*{ "__lastread", "last CPU read address" },
{ "__lastwrite", "last CPU write address" },*/ { "__lastwrite", "last CPU write address" },*/
}; } };

View File

@ -49,9 +49,6 @@ class RewindManager;
#include "FrameBufferConstants.hxx" #include "FrameBufferConstants.hxx"
#include "bspf.hxx" #include "bspf.hxx"
using FunctionMap = std::map<string, unique_ptr<Expression>>;
using FunctionDefMap = std::map<string, string>;
/** /**
The base dialog for all debugging widgets in Stella. Also acts as the parent The base dialog for all debugging widgets in Stella. Also acts as the parent
for all debugging operations in Stella (parser, 6502 debugger, etc). for all debugging operations in Stella (parser, 6502 debugger, etc).
@ -68,6 +65,9 @@ class Debugger : public DialogContainer
friend class M6502; friend class M6502;
public: public:
using FunctionMap = std::map<string, unique_ptr<Expression>>;
using FunctionDefMap = std::map<string, string>;
/** /**
Create a new debugger parent object Create a new debugger parent object
*/ */
@ -361,10 +361,8 @@ class Debugger : public DialogContainer
struct PseudoRegister { struct PseudoRegister {
string name, help; string name, help;
}; };
static const uInt32 NUM_BUILTIN_FUNCS = 18; static std::array<BuiltinFunction, 18> ourBuiltinFunctions;
static const uInt32 NUM_PSEUDO_REGS = 11; static std::array<PseudoRegister, 11> ourPseudoRegisters;
static BuiltinFunction ourBuiltinFunctions[NUM_BUILTIN_FUNCS];
static PseudoRegister ourPseudoRegisters[NUM_PSEUDO_REGS];
private: private:
// rewind/unwind n states // rewind/unwind n states

View File

@ -108,7 +108,7 @@ string DebuggerParser::run(const string& command)
getArgs(command, verb); getArgs(command, verb);
commandResult.str(""); 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)) 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 void DebuggerParser::getCompletions(const char* in, StringList& completions) const
{ {
// cerr << "Attempting to complete \"" << in << "\"" << endl; // 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)) if(BSPF::matches(c.cmdString, in))
completions.push_back(commands[i].cmdString); completions.push_back(c.cmdString);
} }
} }
@ -639,7 +639,7 @@ string DebuggerParser::saveScriptFile(string file)
if(!out.is_open()) if(!out.is_open())
return "Unable to save script to " + node.getShortPath(); return "Unable to save script to " + node.getShortPath();
FunctionDefMap funcs = debugger.getFunctionDefMap(); Debugger::FunctionDefMap funcs = debugger.getFunctionDefMap();
for(const auto& f: funcs) for(const auto& f: funcs)
if (!debugger.isBuiltinFunction(f.first)) if (!debugger.isBuiltinFunction(f.first))
out << "function " << f.first << " {" << f.second << "}" << endl; out << "function " << f.first << " {" << f.second << "}" << endl;
@ -1300,27 +1300,26 @@ void DebuggerParser::executeHelp()
{ {
// Find length of longest command // Find length of longest command
uInt32 clen = 0; 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; if(len > clen) clen = len;
} }
commandResult << setfill(' '); commandResult << setfill(' ');
for(uInt32 i = 0; i < NumCommands; ++i) for(const auto& c: commands)
commandResult << setw(clen) << right << commands[i].cmdString commandResult << setw(clen) << right << c.cmdString
<< " - " << commands[i].description << endl; << " - " << c.description << endl;
commandResult << debugger.builtinHelp(); commandResult << debugger.builtinHelp();
} }
else // get help for specific command 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 commandResult << " " << red(c.description) << endl << c.extendedDesc;
<< commands[i].extendedDesc;
break; break;
} }
} }
@ -1521,7 +1520,7 @@ void DebuggerParser::executeListconfig()
// "listfunctions" // "listfunctions"
void DebuggerParser::executeListfunctions() void DebuggerParser::executeListfunctions()
{ {
const FunctionDefMap& functions = debugger.getFunctionDefMap(); const Debugger::FunctionDefMap& functions = debugger.getFunctionDefMap();
if(functions.size() > 0) if(functions.size() > 0)
{ {
@ -2306,7 +2305,7 @@ void DebuggerParser::executeZ()
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// List of all commands available to the parser // List of all commands available to the parser
DebuggerParser::Command DebuggerParser::commands[NumCommands] = { std::array<DebuggerParser::Command, 95> DebuggerParser::commands = { {
{ {
"a", "a",
"Set Accumulator to <value>", "Set Accumulator to <value>",
@ -3276,4 +3275,4 @@ DebuggerParser::Command DebuggerParser::commands[NumCommands] = {
{ Parameters::ARG_BOOL, Parameters::ARG_END_ARGS }, { Parameters::ARG_BOOL, Parameters::ARG_END_ARGS },
std::mem_fn(&DebuggerParser::executeZ) std::mem_fn(&DebuggerParser::executeZ)
} }
}; } };

View File

@ -88,7 +88,6 @@ class DebuggerParser
}; };
// List of commands available // List of commands available
static constexpr uInt32 NumCommands = 95;
struct Command { struct Command {
string cmdString; string cmdString;
string description; string description;
@ -98,7 +97,7 @@ class DebuggerParser
Parameters parms[10]; Parameters parms[10];
std::function<void (DebuggerParser*)> executor; std::function<void (DebuggerParser*)> executor;
}; };
static Command commands[NumCommands]; static std::array<Command, 95> commands;
struct Trap struct Trap
{ {

View File

@ -1132,7 +1132,7 @@ DiStella::Settings DiStella::settings = {
}; };
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
const DiStella::Instruction_tag DiStella::ourLookup[256] = { const std::array<DiStella::Instruction_tag, 256> DiStella::ourLookup = { {
/**** Positive ****/ /**** Positive ****/
/* 00 */{"brk", AddressingMode::IMPLIED, AccessMode::NONE, RWMode::NONE, 7, 1}, /* Pseudo Absolute */ /* 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 */ /* 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 */ /* fe */{"inc", AddressingMode::ABSOLUTE_X, AccessMode::ABSX, RWMode::WRITE, 7, 3}, /* Absolute,X */
/* ff */{"ISB", AddressingMode::ABSOLUTE_X, AccessMode::ABSX, RWMode::WRITE, 7, 3} /* ff */{"ISB", AddressingMode::ABSOLUTE_X, AccessMode::ABSX, RWMode::WRITE, 7, 3}
}; } };

View File

@ -192,7 +192,7 @@ class DiStella
uInt8 cycles; uInt8 cycles;
uInt8 bytes; uInt8 bytes;
}; };
static const Instruction_tag ourLookup[256]; static const std::array<Instruction_tag, 256> ourLookup;
private: private:
// Following constructors and assignment operators not supported // Following constructors and assignment operators not supported

View File

@ -28,14 +28,6 @@ TIADebug::TIADebug(Debugger& dbg, Console& console)
: DebuggerSystem(dbg, console), : DebuggerSystem(dbg, console),
myTIA(console.tia()) 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. // note: last line should not contain \n, caller will add.
return buf.str(); return buf.str();
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
const std::array<string, 8> 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"
};

View File

@ -189,7 +189,7 @@ class TIADebug : public DebuggerSystem
TIA& myTIA; TIA& myTIA;
string nusizStrings[8]; static const std::array<string, 8> nusizStrings;
private: private:
// Following constructors and assignment operators not supported // Following constructors and assignment operators not supported