saveState: return success. based on patch from Robert Broglia.

git-svn-id: https://gambatte.svn.sourceforge.net/svnroot/gambatte@342 9dfb2916-2d38-0410-aef4-c5fe6c9ffc24
This commit is contained in:
sinamas 2012-09-04 20:09:00 +00:00
parent cb03e9c355
commit c3c3aebada
4 changed files with 22 additions and 14 deletions

View File

@ -97,10 +97,11 @@ public:
/** Saves emulator state to the state slot selected with selectState().
* The data will be stored in the directory given by setSaveDir().
*
* @param videoBuf 160x144 RGB32 (native endian) video frame buffer or 0. Used for storing a thumbnail.
* @param pitch distance in number of pixels (not bytes) from the start of one line to the next in videoBuf.
* @param videoBuf 160x144 RGB32 (native endian) video frame buffer or 0. Used for saving a thumbnail.
* @param pitch distance in number of pixels (not bytes) from the start of one line to the next in videoBuf.
* @return success
*/
void saveState(const gambatte::uint_least32_t *videoBuf, int pitch);
bool saveState(const gambatte::uint_least32_t *videoBuf, int pitch);
/** Loads emulator state from the state slot selected with selectState().
*/
@ -108,10 +109,11 @@ public:
/** Saves emulator state to the file given by 'filepath'.
*
* @param videoBuf 160x144 RGB32 (native endian) video frame buffer or 0. Used for storing a thumbnail.
* @param pitch distance in number of pixels (not bytes) from the start of one line to the next in videoBuf.
* @param videoBuf 160x144 RGB32 (native endian) video frame buffer or 0. Used for saving a thumbnail.
* @param pitch distance in number of pixels (not bytes) from the start of one line to the next in videoBuf.
* @return success
*/
void saveState(const gambatte::uint_least32_t *videoBuf, int pitch, const std::string &filepath);
bool saveState(const gambatte::uint_least32_t *videoBuf, int pitch, const std::string &filepath);
/** Loads emulator state from the file given by 'filepath'.
*/

View File

@ -141,24 +141,28 @@ void GB::loadState(const std::string &filepath, const bool osdMessage) {
}
}
void GB::saveState(const gambatte::uint_least32_t *const videoBuf, const int pitch) {
if (p_->cpu.loaded()) {
saveState(videoBuf, pitch, statePath(p_->cpu.saveBasePath(), p_->stateNo));
bool GB::saveState(const gambatte::uint_least32_t *const videoBuf, const int pitch) {
if (saveState(videoBuf, pitch, statePath(p_->cpu.saveBasePath(), p_->stateNo))) {
p_->cpu.setOsdElement(newStateSavedOsdElement(p_->stateNo));
return true;
}
return false;
}
void GB::loadState() {
loadState(statePath(p_->cpu.saveBasePath(), p_->stateNo), true);
}
void GB::saveState(const gambatte::uint_least32_t *const videoBuf, const int pitch, const std::string &filepath) {
bool GB::saveState(const gambatte::uint_least32_t *const videoBuf, const int pitch, const std::string &filepath) {
if (p_->cpu.loaded()) {
SaveState state;
p_->cpu.setStatePtrs(state);
p_->cpu.saveState(state);
StateSaver::saveState(state, videoBuf, pitch, filepath);
return StateSaver::saveState(state, videoBuf, pitch, filepath);
}
return false;
}
void GB::loadState(const std::string &filepath) {

View File

@ -409,13 +409,13 @@ static SaverList list;
namespace gambatte {
void StateSaver::saveState(const SaveState &state,
bool StateSaver::saveState(const SaveState &state,
const uint_least32_t *const videoBuf,
const int pitch, const std::string &filename) {
std::ofstream file(filename.c_str(), std::ios_base::binary);
if (file.fail())
return;
return false;
{ static const char ver[] = { 0, 1 }; file.write(ver, sizeof(ver)); }
@ -425,6 +425,8 @@ void StateSaver::saveState(const SaveState &state,
file.write(it->label, it->labelsize);
(*it->save)(file, state);
}
return !file.fail();
}
bool StateSaver::loadState(SaveState &state, const std::string &filename) {

View File

@ -35,7 +35,7 @@ public:
enum { SS_WIDTH = 160 >> SS_SHIFT };
enum { SS_HEIGHT = 144 >> SS_SHIFT };
static void saveState(const SaveState &state,
static bool saveState(const SaveState &state,
const uint_least32_t *videoBuf, int pitch, const std::string &filename);
static bool loadState(SaveState &state, const std::string &filename);
};