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;
private:
uInt8 savedRom[16];
std::array<uInt8, 16> savedRom;
uInt16 address;
uInt8 value;
uInt8 count;

View File

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

View File

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

View File

@ -20,8 +20,6 @@
#ifndef ZIP_HANDLER_HXX
#define ZIP_HANDLER_HXX
#include <array>
#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;

View File

@ -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<bool, 16> TIARead;
std::array<bool, 64> TIAWrite;
std::array<bool, 24> IOReadWrite;
std::array<bool, 128> ZPRAM;
AddrToLabel Label;
bool breakFound;
};

View File

@ -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::BuiltinFunction, 18> 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::PseudoRegister, 11> 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" },*/
};
} };

View File

@ -49,9 +49,6 @@ class RewindManager;
#include "FrameBufferConstants.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
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<string, unique_ptr<Expression>>;
using FunctionDefMap = std::map<string, string>;
/**
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<BuiltinFunction, 18> ourBuiltinFunctions;
static std::array<PseudoRegister, 11> ourPseudoRegisters;
private:
// rewind/unwind n states

View File

@ -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::Command, 95> DebuggerParser::commands = { {
{
"a",
"Set Accumulator to <value>",
@ -3276,4 +3275,4 @@ DebuggerParser::Command DebuggerParser::commands[NumCommands] = {
{ Parameters::ARG_BOOL, Parameters::ARG_END_ARGS },
std::mem_fn(&DebuggerParser::executeZ)
}
};
} };

View File

@ -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<void (DebuggerParser*)> executor;
};
static Command commands[NumCommands];
static std::array<Command, 95> commands;
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 ****/
/* 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}
};
} };

View File

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

View File

@ -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<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;
string nusizStrings[8];
static const std::array<string, 8> nusizStrings;
private:
// Following constructors and assignment operators not supported