mirror of https://github.com/stella-emu/stella.git
Some more optimizations and small code cleanups.
git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@3066 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
parent
1d1851dc3c
commit
b863b55594
|
@ -128,13 +128,11 @@ void CheatManager::addPerFrame(Cheat* cheat, bool enable)
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
void CheatManager::addOneShot(const string& name, const string& code)
|
void CheatManager::addOneShot(const string& name, const string& code)
|
||||||
{
|
{
|
||||||
Cheat* cheat = createCheat(name, code);
|
unique_ptr<Cheat> cheat(createCheat(name, code));
|
||||||
if(!cheat)
|
|
||||||
return;
|
|
||||||
|
|
||||||
// Evaluate this cheat once, and then immediately delete it
|
// Evaluate this cheat once, and then immediately delete it
|
||||||
|
if(cheat)
|
||||||
cheat->evaluate();
|
cheat->evaluate();
|
||||||
delete cheat;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
@ -218,14 +216,14 @@ void CheatManager::parse(const string& cheats)
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
void CheatManager::enable(const string& code, bool enable)
|
void CheatManager::enable(const string& code, bool enable)
|
||||||
{
|
{
|
||||||
for(unsigned int i = 0; i < myCheatList.size(); i++)
|
for(const auto& cheat: myCheatList)
|
||||||
{
|
{
|
||||||
if(myCheatList[i]->code() == code)
|
if(cheat->code() == code)
|
||||||
{
|
{
|
||||||
if(enable)
|
if(enable)
|
||||||
myCheatList[i]->enable();
|
cheat->enable();
|
||||||
else
|
else
|
||||||
myCheatList[i]->disable();
|
cheat->disable();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -327,7 +325,7 @@ void CheatManager::saveCheats(const string& md5sum)
|
||||||
// Only update the list if absolutely necessary
|
// Only update the list if absolutely necessary
|
||||||
if(changed)
|
if(changed)
|
||||||
{
|
{
|
||||||
CheatCodeMap::iterator iter = myCheatMap.find(md5sum);
|
auto iter = myCheatMap.find(md5sum);
|
||||||
|
|
||||||
// Erase old entry and add a new one only if it's changed
|
// Erase old entry and add a new one only if it's changed
|
||||||
if(iter != myCheatMap.end())
|
if(iter != myCheatMap.end())
|
||||||
|
@ -350,16 +348,16 @@ void CheatManager::clear()
|
||||||
// the following loop
|
// the following loop
|
||||||
myPerFrameList.clear();
|
myPerFrameList.clear();
|
||||||
|
|
||||||
for(unsigned int i = 0; i < myCheatList.size(); i++)
|
for(auto cheat: myCheatList)
|
||||||
delete myCheatList[i];
|
delete cheat;
|
||||||
myCheatList.clear();
|
myCheatList.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
bool CheatManager::isValidCode(const string& code) const
|
bool CheatManager::isValidCode(const string& code) const
|
||||||
{
|
{
|
||||||
for(unsigned int i = 0; i < code.size(); i++)
|
for(auto c: code)
|
||||||
if(!isxdigit(code[i]))
|
if(!isxdigit(c))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
uInt32 length = (uInt32)code.length();
|
uInt32 length = (uInt32)code.length();
|
||||||
|
|
|
@ -28,7 +28,6 @@ class OSystem;
|
||||||
#include "bspf.hxx"
|
#include "bspf.hxx"
|
||||||
|
|
||||||
typedef vector<Cheat*> CheatList;
|
typedef vector<Cheat*> CheatList;
|
||||||
typedef map<string,string> CheatCodeMap;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
This class provides an interface for performing all cheat operations
|
This class provides an interface for performing all cheat operations
|
||||||
|
@ -156,7 +155,7 @@ class CheatManager
|
||||||
CheatList myCheatList;
|
CheatList myCheatList;
|
||||||
CheatList myPerFrameList;
|
CheatList myPerFrameList;
|
||||||
|
|
||||||
CheatCodeMap myCheatMap;
|
map<string,string> myCheatMap;
|
||||||
string myCheatFile;
|
string myCheatFile;
|
||||||
|
|
||||||
// This is set each time a new cheat/ROM is loaded, for later
|
// This is set each time a new cheat/ROM is loaded, for later
|
||||||
|
|
|
@ -326,15 +326,13 @@ void PNGLibrary::writeComments(png_structp png_ptr, png_infop info_ptr,
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
void PNGLibrary::png_read_data(png_structp ctx, png_bytep area, png_size_t size)
|
void PNGLibrary::png_read_data(png_structp ctx, png_bytep area, png_size_t size)
|
||||||
{
|
{
|
||||||
ifstream* stream = (ifstream *) png_get_io_ptr(ctx);
|
((ifstream *) png_get_io_ptr(ctx))->read((char *)area, size);
|
||||||
stream->read((char *)area, size);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
void PNGLibrary::png_write_data(png_structp ctx, png_bytep area, png_size_t size)
|
void PNGLibrary::png_write_data(png_structp ctx, png_bytep area, png_size_t size)
|
||||||
{
|
{
|
||||||
ofstream* stream = (ofstream *) png_get_io_ptr(ctx);
|
((ofstream *) png_get_io_ptr(ctx))->write((const char *)area, size);
|
||||||
stream->write((const char *)area, size);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
|
|
@ -268,7 +268,7 @@ bool CartDebug::disassemble(bool force)
|
||||||
if(bankChanged || !pcfound)
|
if(bankChanged || !pcfound)
|
||||||
{
|
{
|
||||||
AddressList::const_iterator i;
|
AddressList::const_iterator i;
|
||||||
for(i = addresses.begin(); i != addresses.end(); ++i)
|
for(auto i = addresses.begin(); i != addresses.end(); ++i)
|
||||||
{
|
{
|
||||||
if(PC < *i)
|
if(PC < *i)
|
||||||
{
|
{
|
||||||
|
@ -537,11 +537,11 @@ bool CartDebug::addLabel(const string& label, uInt16 address)
|
||||||
bool CartDebug::removeLabel(const string& label)
|
bool CartDebug::removeLabel(const string& label)
|
||||||
{
|
{
|
||||||
// Only user-defined labels can be removed
|
// Only user-defined labels can be removed
|
||||||
LabelToAddr::iterator iter = myUserAddresses.find(label);
|
const auto& iter = myUserAddresses.find(label);
|
||||||
if(iter != myUserAddresses.end())
|
if(iter != myUserAddresses.end())
|
||||||
{
|
{
|
||||||
// Erase the address assigned to the label
|
// Erase the address assigned to the label
|
||||||
AddrToLabel::iterator iter2 = myUserLabels.find(iter->second);
|
const auto& iter2 = myUserLabels.find(iter->second);
|
||||||
if(iter2 != myUserLabels.end())
|
if(iter2 != myUserLabels.end())
|
||||||
myUserLabels.erase(iter2);
|
myUserLabels.erase(iter2);
|
||||||
|
|
||||||
|
@ -612,8 +612,8 @@ bool CartDebug::getLabel(ostream& buf, uInt16 addr, bool isRead, int places) con
|
||||||
{
|
{
|
||||||
// RAM can use user-defined labels; otherwise we default to
|
// RAM can use user-defined labels; otherwise we default to
|
||||||
// standard mnemonics
|
// standard mnemonics
|
||||||
AddrToLabel::const_iterator iter;
|
auto iter = myUserLabels.find(addr);
|
||||||
if((iter = myUserLabels.find(addr)) != myUserLabels.end())
|
if(iter != myUserLabels.end())
|
||||||
{
|
{
|
||||||
buf << iter->second;
|
buf << iter->second;
|
||||||
}
|
}
|
||||||
|
@ -634,8 +634,8 @@ bool CartDebug::getLabel(ostream& buf, uInt16 addr, bool isRead, int places) con
|
||||||
case ADDR_ROM:
|
case ADDR_ROM:
|
||||||
{
|
{
|
||||||
// These addresses can never be in the system labels list
|
// These addresses can never be in the system labels list
|
||||||
AddrToLabel::const_iterator iter;
|
const auto& iter = myUserLabels.find(addr);
|
||||||
if((iter = myUserLabels.find(addr)) != myUserLabels.end())
|
if(iter != myUserLabels.end())
|
||||||
{
|
{
|
||||||
buf << iter->second;
|
buf << iter->second;
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -403,15 +403,15 @@ bool DebuggerParser::getArgs(const string& command, string& verb)
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
for(int i = 0; i < argCount; i++) {
|
for(int i = 0; i < argCount; i++)
|
||||||
int err = YaccParser::parse(argStrings[i].c_str());
|
{
|
||||||
if(err) {
|
if(!YaccParser::parse(argStrings[i].c_str()))
|
||||||
args.push_back(-1);
|
{
|
||||||
} else {
|
unique_ptr<Expression> expr(YaccParser::getResult());
|
||||||
Expression* e = YaccParser::getResult();
|
args.push_back(expr->evaluate());
|
||||||
args.push_back( e->evaluate() );
|
|
||||||
delete e;
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
args.push_back(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -220,9 +220,8 @@ void EventHandler::poll(uInt64 time)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
#ifdef CHEATCODE_SUPPORT
|
#ifdef CHEATCODE_SUPPORT
|
||||||
const CheatList& cheats = myOSystem.cheat().perFrame();
|
for(auto& cheat: myOSystem.cheat().perFrame())
|
||||||
for(uInt32 i = 0; i < cheats.size(); i++)
|
cheat->evaluate();
|
||||||
cheats[i]->evaluate();
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Handle continuous snapshots
|
// Handle continuous snapshots
|
||||||
|
|
|
@ -43,10 +43,6 @@ System::System(const OSystem& osystem, M6502& m6502, M6532& m6532,
|
||||||
// Re-initialize random generator
|
// Re-initialize random generator
|
||||||
randGenerator().initSeed();
|
randGenerator().initSeed();
|
||||||
|
|
||||||
// Allocate page table and dirty list
|
|
||||||
myPageAccessTable = new PageAccess[NUM_PAGES];
|
|
||||||
myPageIsDirtyTable = new bool[NUM_PAGES];
|
|
||||||
|
|
||||||
// Initialize page access table
|
// Initialize page access table
|
||||||
PageAccess access(&myNullDevice, System::PA_READ);
|
PageAccess access(&myNullDevice, System::PA_READ);
|
||||||
for(int page = 0; page < NUM_PAGES; ++page)
|
for(int page = 0; page < NUM_PAGES; ++page)
|
||||||
|
@ -62,9 +58,6 @@ System::System(const OSystem& osystem, M6502& m6502, M6532& m6532,
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
System::~System()
|
System::~System()
|
||||||
{
|
{
|
||||||
// Free my page access table and dirty list
|
|
||||||
delete[] myPageAccessTable;
|
|
||||||
delete[] myPageIsDirtyTable;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
@ -218,7 +211,7 @@ void System::poke(uInt16 addr, uInt8 value)
|
||||||
uInt8 System::getAccessFlags(uInt16 addr) const
|
uInt8 System::getAccessFlags(uInt16 addr) const
|
||||||
{
|
{
|
||||||
#ifdef DEBUGGER_SUPPORT
|
#ifdef DEBUGGER_SUPPORT
|
||||||
PageAccess& access = myPageAccessTable[(addr & ADDRESS_MASK) >> PAGE_SHIFT];
|
const PageAccess& access = myPageAccessTable[(addr & ADDRESS_MASK) >> PAGE_SHIFT];
|
||||||
|
|
||||||
if(access.codeAccessBase)
|
if(access.codeAccessBase)
|
||||||
return *(access.codeAccessBase + (addr & PAGE_MASK));
|
return *(access.codeAccessBase + (addr & PAGE_MASK));
|
||||||
|
|
|
@ -396,11 +396,11 @@ class System : public Serializable
|
||||||
// Null device to use for page which are not installed
|
// Null device to use for page which are not installed
|
||||||
NullDevice myNullDevice;
|
NullDevice myNullDevice;
|
||||||
|
|
||||||
// Pointer to a dynamically allocated array of PageAccess structures
|
// The list of PageAccess structures
|
||||||
PageAccess* myPageAccessTable;
|
PageAccess myPageAccessTable[NUM_PAGES];
|
||||||
|
|
||||||
// Pointer to a dynamically allocated array for dirty pages
|
// The list of dirty pages
|
||||||
bool* myPageIsDirtyTable;
|
bool myPageIsDirtyTable[NUM_PAGES];
|
||||||
|
|
||||||
// The current state of the Data Bus
|
// The current state of the Data Bus
|
||||||
uInt8 myDataBusState;
|
uInt8 myDataBusState;
|
||||||
|
|
Loading…
Reference in New Issue