00001 /* 00002 * hack4u 00003 * Copyright (C) 2004-2006 emuWorks 00004 * http://games.technoplaza.net/ 00005 * 00006 * This file is part of hack4u. 00007 * 00008 * hack4u is free software; you can redistribute it and/or modify 00009 * it under the terms of the GNU General Public License as published by 00010 * the Free Software Foundation; either version 2 of the License, or 00011 * (at your option) any later version. 00012 * 00013 * hack4u is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 * GNU General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU General Public License 00019 * along with hack4u; if not, write to the Free Software 00020 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00021 */ 00022 00023 // $Id: SRAMFile.hh,v 1.2 2006/03/17 07:57:59 technoplaza Exp $ 00024 00025 #ifndef _SRAMFILE_HH_ 00026 #define _SRAMFILE_HH_ 00027 00028 #include <wx/string.h> 00029 00030 #include "exceptions/FileIOException.hh" 00031 #include "exceptions/InvalidSRAMException.hh" 00032 #include "model/ModelConstants.hh" 00033 00034 namespace hack4u { 00035 class SaveSlot; 00036 00037 class SRAMFile { 00038 private: 00039 SaveSlot *saveslot[3]; 00040 char sram[SRAM_SIZE]; 00041 bool valid[3]; 00042 00043 /** 00044 * Verifies the checksums of all three SaveSlots. 00045 */ 00046 void verifyChecksum(); 00047 00048 public: 00049 /** 00050 * Creates a new SRAMFile from a SAV file. 00051 * 00052 * @param filename The filename to read the SRAM data from. 00053 * 00054 * @throw InvalidSRAMException if the file is not a valid SRAMFile. 00055 */ 00056 SRAMFile(const wxString &filename) throw(InvalidSRAMException); 00057 00058 /** 00059 * Destructor for an SRAMFile. 00060 */ 00061 ~SRAMFile(); 00062 00063 /** 00064 * Gets one of the SaveSlots in this SRAMFile. 00065 * 00066 * @param game Which game's SaveSlot to get. 00067 * 00068 * @return The requested SaveSlot. 00069 */ 00070 SaveSlot *getSaveSlot(int game); 00071 00072 /** 00073 * Checks if this SRAMFile has been modified. 00074 * 00075 * @return true if modified; false otherwise. 00076 */ 00077 bool isModified() const; 00078 00079 /** 00080 * Queries the validity of one of the three SaveSlots. 00081 * 00082 * @param slot The slot to test. 00083 * 00084 * @return true if the SaveSlot is valid; false otherwise. 00085 */ 00086 bool isValid(int slot) const; 00087 00088 /** 00089 * Saves the SRAM data to disk. 00090 * 00091 * @param filename The filename to save to. 00092 * 00093 * @throw FileIOException if the data cannot be saved. 00094 */ 00095 void save(const wxString &filename) throw(FileIOException); 00096 }; 00097 00098 inline SaveSlot *SRAMFile::getSaveSlot(int game) { return saveslot[game]; } 00099 inline bool SRAMFile::isValid(int slot) const { return valid[slot]; } 00100 } 00101 00102 #endif 00103