SRAMFile.hh

Go to the documentation of this file.
00001 /*
00002  * Super Metroid SRAM Editor
00003  * Copyright (C) 2005,2007-2008 emuWorks
00004  * http://games.technoplaza.net/
00005  *
00006  * This file is part of Super Metroid SRAM Editor.
00007  *
00008  * Super Metroid SRAM Editor is free software; you can redistribute it and/or
00009  * modify 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  * Super Metroid SRAM Editor 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 Super Metroid SRAM Editor; 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.42 2008/12/17 04:14:15 jdratlif Exp $
00024 
00025 #ifndef SMSE_SRAMFILE_HH_
00026 #define SMSE_SRAMFILE_HH_
00027 
00028 #include <utility>
00029 
00030 #include <wx/string.h>
00031 
00032 #include "AppConstants.hh"
00033 #include "exceptions/FileIOException.hh"
00034 #include "exceptions/InvalidButtonException.hh"
00035 #include "exceptions/InvalidSRAMFileException.hh"
00036 
00037 namespace smse {
00038     /// names for the SRAM offsets
00039     enum {
00040         // Samus status
00041         SO_CURRENTENERGY, SO_MAXENERGY, SO_CURRENTRESERVE, SO_MAXRESERVE,
00042         SO_CURRENTMISSILES, SO_MAXMISSILES, SO_CURRENTSMISSILES,
00043         SO_MAXSMISSILES, SO_CURRENTPBOMBS, SO_MAXPBOMBS,
00044         
00045         // Samus' Items 
00046         SO_MORPHINGBALL, SO_BOMBS = 13, SO_SPRINGBALL = 16,
00047         SO_HIGHJUMPBOOTS = 19, SO_VARIASUIT = 22, SO_GRAVITYSUIT = 25,
00048         SO_SPEEDBOOSTER = 28, SO_SPACEJUMP = 31, SO_SCREWATTACK = 34,
00049         SO_CHARGEBEAM = 37, SO_ICEBEAM = 40, SO_WAVEBEAM = 43, SO_SPAZER = 46,
00050         SO_PLASMABEAM = 49, SO_GRAPPLINGBEAM = 52, SO_XRAYSCOPE = 55,
00051         
00052         // Bosses
00053         SO_SILVERTORIZO = 58, SO_SPORESPAWN, SO_KRAID, SO_PHANTOON = 62,
00054         SO_BOTWOON = 64, SO_DRAYGON, SO_CROCOMIRE = 67, SO_GOLDENTORIZO,
00055         SO_RIDLEY, SO_METROIDROOMS = 71, SO_ZEBETITES = 75,
00056         
00057         // Misc Game Progress
00058         SO_TOURIANELEVATOR, SO_MARIDIATUBEBROKEN, SO_RESCUEDANIMALS,
00059         
00060         // Missile Packs
00061         SO_CMISSILEPACKS, SO_BSMISSILEPACKS = 87, SO_NFMISSILEPACKS = 99,
00062         SO_WSMISSILEPACKS = 114, SO_MMISSILEPACKS = 117,
00063         
00064         // Super Missile Packs
00065         SO_CSMISSILEPACKS = 125, SO_BSSMISSILEPACKS, SO_NFSMISSILEPACKS = 129,
00066         SO_WSSMISSILEPACKS, SO_MSMISSILEPACKS = 132,
00067         
00068         // Power Bomb Packs
00069         SO_CPBOMBPACKS = 135, SO_BSPBOMBPACKS, SO_NFPBOMBPACKS = 141,
00070         SO_MPBOMBPACKS = 144,
00071         
00072         // Energy and Reserve Tanks
00073         SO_CETANKS, SO_BSETANKS = 147,  SO_NFETANKS = 152, SO_WSETANKS = 156,
00074         SO_METANKS, SO_BSRTANK = 159, SO_NFRTANK, SO_WSRTANK, SO_MRTANK,
00075         
00076         // Red Doors
00077         SO_CRDOORS, SO_BSRDOORS = 166, SO_NFRDOORS = 176, SO_WSRDOORS = 183,
00078         SO_MRDOORS, SO_TRDOORS = 191,
00079         
00080         // Green Doors
00081         SO_CGDOORS = 193, SO_BSGDOORS = 195, SO_NFGDOORS = 205,
00082         SO_WSGDOORS = 211, SO_MGDOORS,
00083         
00084         // Yellow Doors
00085         SO_CYDOORS = 216, SO_BSYDOORS = 222, SO_NFYDOORS = 226,
00086         
00087         // Metal Doors
00088         SO_CMDOORS = 229, SO_BSMDOORS, SO_NFMDOORS = 246,
00089         SO_WSMDOORS = 252, SO_MMDOORS = 257, SO_TMDOORS = 264,
00090         
00091         // Eye Doors
00092         SO_BSEDOOR = 269, SO_NFEDOOR, SO_WSEDOOR, SO_MEDOOR, SO_TEDOOR,
00093         
00094         // Maps
00095         SO_CMAP, SO_BSMAP, SO_NFMAP, SO_WSMAP, SO_MMAP, SO_TMAP,
00096         
00097         // Misc Game Information
00098         SO_SAVEAREA, SO_SAVEPOINT, SO_GAMEHOURS, SO_GAMEMINUTES,
00099         
00100         // Game Configuration
00101         SO_SHOTBUTTON, SO_JUMPBUTTON, SO_DASHBUTTON, SO_ITEMCANCELBUTTON,
00102         SO_ITEMSELECTBUTTON, SO_ANGLEDOWNBUTTON, SO_ANGLEUPBUTTON, SO_LANGUAGE,
00103         SO_MOONWALK, SO_ICONCANCEL
00104     };
00105     
00106     /// semi-typesafe names for Samus' actions
00107     enum Action {
00108         ACTION_SHOT, ACTION_JUMP, ACTION_DASH, ACTION_ITEMCANCEL,
00109         ACTION_ITEMSELECT, ACTION_ANGLEDOWN, ACTION_ANGLEUP
00110     };
00111     
00112     /// semi-typesafe names for the areas on Zebes
00113     enum Area {
00114         AREA_C, AREA_BS, AREA_NF, AREA_WS, AREA_M, AREA_T
00115     };
00116     
00117     /// semi-typesafe names for the bosses
00118     enum Boss {
00119         BOSS_SILVERTORIZO = 58, BOSS_SPORESPAWN, BOSS_KRAID, BOSS_PHANTOON = 62,
00120         BOSS_BOTWOON = 64, BOSS_DRAYGON, BOSS_CROCOMIRE = 67, BOSS_GOLDENTORIZO,
00121         BOSS_RIDLEY
00122     };
00123     
00124     /// semi-typesafe names for the controller buttons
00125     enum Button {
00126         BUTTON_A, BUTTON_B, BUTTON_X, BUTTON_Y,
00127         BUTTON_L, BUTTON_R, BUTTON_SELECT
00128     };
00129     
00130     /// names for the doors
00131     enum Door {
00132         // Crateria Red Doors
00133         RD_C_MAP = 163, RD_C_BOMBS, RD_C_TELEVATOR,
00134         
00135         // Brinstar Red Doors
00136         RD_BS1, RD_BS_MAP, RD_BS2, RD_BS3, RD_BS4, RD_BS_RTANK,
00137         RD_BS_SPORESPAWN, RD_BS5, RD_BS6, RD_BS_XRAYSCOPE,
00138         
00139         // Norfair Red Doors
00140         RD_NF1, RD_NF_HJBOOTS, RD_NF2, RD_NF3,
00141         RD_NF_SPEEDBOOSTER, RD_NF4, RD_NF_WAVEBEAM,
00142         
00143         // Wrecked Ship Red Doors
00144         RD_WS_RTANK,
00145         
00146         // Maridia Red Doors
00147         RD_M1, RD_M2, RD_M3, RD_M_MAP, RD_M4, RD_M5, RD_M6,
00148         
00149         // Tourian Red Doors
00150         RD_T1, RD_T_MB,
00151         
00152         // Crateria Green Doors
00153         GD_C1, GD_C_WS,
00154         
00155         // Brinstar Green Doors
00156         GD_BS1, GD_BS_SPORESPAWNEXIT, GD_BS2, GD_BS3, GD_BS4,
00157         GD_BS5, GD_BS6, GD_BS7, GD_BS_SPAZER, GD_BS8,
00158         
00159         // Norfair Green Doors
00160         GD_NF1, GD_NF_ICEBEAM, GD_NF2, GD_NF3, GD_NF_SPEEDBOOSTER, GD_NF4,
00161         
00162         // Wrecked Ship Green Doors
00163         GD_WS,
00164         
00165         // Maridia Green Doors
00166         GD_M1, GD_M2, GD_M3, GD_M_DRAYGON,
00167         
00168         // Crateria Yellow Doors
00169         YD_C1, YD_C2, YD_C3, YD_C4, YD_C5, YD_C6,
00170         
00171         // Brinstar Yellow Doors
00172         YD_BS1, YD_BS2, YD_BS_XRAYSCOPE, YD_BS3,
00173         
00174         // Norfair Yellow Doors
00175         YD_NF_MAP, YD_NF1, YD_NF2,
00176         
00177         // Crateria Metal Doors
00178         MD_C_BOMBSEXIT,
00179         
00180         // Brinstar Metal Doors
00181         MD_BS_OLDTRIGHT, MD_BS_OLDTLEFT, MD_BS_MAPEXIT, MD_BS1, MD_BS2, MD_BS3,
00182         MD_BS4, MD_BS5, MD_BS6, MD_BS7, MD_BS8, MD_BS9, MD_BS_MINIKRAIDRIGHT,
00183         MD_BS_MINIKRAIDLEFT, MD_BS_VARIASUIT, MD_BS_KRAIDEXIT,
00184         
00185         // Norfair Metal Doors
00186         MD_NF_CROCOMIREEXIT, MD_NF_HJBOOTSEXIT, MD_NF_SCREWATTACK,
00187         MD_NF_RIDLEYEXIT, MD_NF_RIDLEYLEFT, MD_NF_GOLDSPACEPIRATES,
00188         
00189         // Wrecked Ship Metal Doors
00190         MD_WS1, MD_WS_PHANTOONEXIT, MD_WS2, MD_WS3, MD_WS4,
00191         
00192         // Maridia Metal Doors
00193         MD_M_PLASMAEXIT, MD_M_PLASMA, MD_M1, MD_M2,
00194         MD_M_BOTWOONEXIT, MD_M_DRAYGONEXIT, MD_M_SPACEJUMP,
00195         
00196         // Tourian Metal Doors
00197         MD_T1, MD_T2, MD_T3, MD_T4, MD_T5,
00198         
00199         // Eye Doors
00200         ED_KRAID, ED_RIDLEY, ED_PHANTOON, ED_DRAYGON, ED_T
00201     };
00202     
00203     /// semi-typesafe names for Samus' equipment
00204     enum Item {
00205         ITEM_MORPHINGBALL = 10, ITEM_BOMBS = 13, ITEM_SPRINGBALL = 16,
00206         ITEM_HJBOOTS = 19, ITEM_VARIASUIT = 22, ITEM_GRAVITYSUIT = 25,
00207         ITEM_SPEEDBOOSTER = 28, ITEM_SPACEJUMP = 31, ITEM_SCREWATTACK = 34,
00208         ITEM_CHARGEBEAM = 37, ITEM_ICEBEAM = 40, ITEM_WAVEBEAM = 43,
00209         ITEM_SPAZER = 46, ITEM_PLASMA = 49, ITEM_GRAPPLINGBEAM = 52,
00210         ITEM_XRAYSCOPE = 55
00211     };
00212     
00213     /// semi-typesafe names for the miscellaneous bits
00214     enum MiscBit {
00215         MB_TELEVATOR = 76, MB_MTUBEBROKEN, MB_RESCUEDANIMALS,
00216         MB_LANGUAGE = 291, MB_MOONWALK, MB_ICONCANCEL
00217     };
00218     
00219     /// semi-typesafe names for the Metroid rooms in Tourian
00220     enum MetroidRoom {
00221         MR1, MR2, MR3, MR4
00222     };
00223     
00224     /// semi-typesafe names for the boss statues
00225     enum Statue {
00226         STATUE_KRAID = 61, STATUE_PHANTOON = 63,
00227         STATUE_DRAYGON = 66, STATUE_RIDLEY = 70
00228     };
00229     
00230     /// save points in Crateria
00231     const int C_SAVEPOINTS = 2;
00232     
00233     /// save points in Brinstar
00234     const int BS_SAVEPOINTS = 5;
00235     
00236     /// save points in Norfair
00237     const int NF_SAVEPOINTS = 6;
00238     
00239     /// save points in Wrecked Ship
00240     const int WS_SAVEPOINTS = 1;
00241     
00242     /// save points in Maridia
00243     const int M_SAVEPOINTS = 4;
00244     
00245     /// save points in Tourian
00246     const int T_SAVEPOINTS = 2;
00247     
00248     /// Class to encapsulate a Super Metroid SRAM File
00249     class SRAMFile {
00250     public:
00251         /// size of the SRAM file
00252         static const unsigned int SRAM_SIZE = 0x2000;
00253         
00254         /// number of save games in the SRAM data
00255         static const unsigned int GAMES = 3;
00256         
00257         /// size of each individual save game
00258         static const unsigned int GAME_SIZE = 0x65C;
00259         
00260         /// offset to the beginning of the game data
00261         static const int GAME_OFFSET = 0x10;
00262         
00263         /// offset of the checksums
00264         static const int CHECKSUM_OFFSET = 0;
00265         
00266         /// offset of the redundant checksums
00267         static const int CHECKSUM_OFFSET2 = 0x1FF0;
00268         
00269         /// offset of the checksum compliments
00270         static const int COMPLIMENT_OFFSET = 0x8;
00271         
00272         /// offset of the redundant checksum compliments
00273         static const int COMPLIMENT_OFFSET2 = 0x1FF8;
00274         
00275     private:
00276         /// all the SRAM offsets
00277         static const std::pair<int, unsigned char> SRAM_OFFSET[];
00278         
00279         /// the controller button values
00280         static const std::pair<unsigned char, unsigned char> BUTTON_VALUE[];
00281         
00282         wxString filename;
00283         char sram[SRAM_SIZE];
00284         char *game;
00285         bool valid[3], modified;
00286         
00287         /**
00288          * Checks if a bit is set in the SRAM.
00289          *
00290          * @param bit The bit to check.
00291          *
00292          * @return true if the bit is set; false otherwise.
00293          */
00294         bool getBit(const std::pair<int, unsigned char> &bit) const;
00295         
00296         /**
00297          * Sets one of the bits in the SRAM.
00298          *
00299          * @param bit The bit to set.
00300          * @param on true to set the bit; false otherwise.
00301          */
00302         void setBit(const std::pair<int, unsigned char> &bit, bool on = true);
00303         
00304         /**
00305          * Gets the checksum for a particular save game.
00306          *
00307          * @param game The game whose checksum to get.
00308          * @param redundant true for the redundant checksum; false otherwise.
00309          *
00310          * @return The checksum.
00311          */
00312         std::pair<unsigned char,
00313                   unsigned char> getChecksum(int game,
00314                                              bool redundant = false) const;
00315                                   
00316         /**
00317          * Gets the checksum compliment for a particular save game.
00318          *
00319          * @param game The game whose checksum compliment to get.
00320          * @param redundant true for the redundant compliment; false otherwise.
00321          *
00322          * @return The checksum compliment.
00323          */
00324         std::pair<unsigned char,
00325                   unsigned char> getCompliment(int game,
00326                                                bool redundant = false) const;
00327                                                
00328         /**
00329          * Sets the maximum energy Samus can have.
00330          *
00331          * @param energy The max energy.
00332          */
00333         void setMaxEnergy(wxUint16 energy = 0x5DB);
00334         
00335         /**
00336          * Sets the maximum number of missiles Samus can carry.
00337          *
00338          * @param missiles The max missiles.
00339          */
00340         void setMaxMissiles(unsigned char missiles = 0xE6);
00341         
00342         /**
00343          * Sets the maximum number of power bombs Samus can carry.
00344          *
00345          * @param bombs The max power bombs.
00346          */
00347         void setMaxPowerBombs(unsigned char bombs = 0x32);
00348         
00349         /**
00350          * Sets the maximum reserve energy Samus can have.
00351          *
00352          * @param energy The max reserve energy.
00353          */
00354         void setMaxReserveEnergy(wxUint16 energy = 0x190);
00355         
00356         /**
00357          * Sets the maximum number of super missiles Samus can carry.
00358          *
00359          * @param missiles The max super missiles.
00360          */
00361         void setMaxSuperMissiles(unsigned char missiles = 0x32);
00362         
00363         /**
00364          * Calculates the checksum for one of the save games.
00365          *
00366          * @param game The game to checksum (0-2).
00367          */
00368         std::pair<unsigned char, 
00369                   unsigned char> checksum(int game) const;
00370                   
00371         /**
00372          * Recalculates and updates the checksum for this SRAMFile.
00373          */
00374         void checksum();
00375                   
00376         /**
00377          * Calculates the compliment for a given checksum.
00378          *
00379          * @param checksum The checksum to compliment.
00380          *
00381          * @return The checksum compliment.
00382          */
00383         std::pair<unsigned char, unsigned char>
00384             compliment(std::pair<unsigned char, unsigned char> checksum) const;
00385 
00386         /**
00387          * Checks if the SRAM contains a valid game.
00388          *
00389          * @return true if the SRAM has a valid game; false otherwise.
00390          */
00391         bool hasValidGame();
00392         
00393         /**
00394          * Reads the SRAM data from disk.
00395          *
00396          * @throw FileIOException if the file cannot be read.
00397          * @throw InvalidSRAMFileException is the file is not a valid SRAM file.
00398          */
00399         void read() throw(FileIOException, InvalidSRAMFileException);
00400         
00401         /**
00402          * Writes the SRAM data to the disk.
00403          *
00404          * @throw FileIOException if the file cannot be written.
00405          */
00406         void write() throw(FileIOException);
00407         
00408     public:
00409         /**
00410          * Creates a new SRAMFile.
00411          *
00412          * @param filename The SRAM file to open.
00413          *
00414          * @throw InvalidSRAMFileException if the given file is not a valid
00415          *                                 SRAM file.
00416          */
00417         SRAMFile(const wxString &filename) throw(InvalidSRAMFileException);
00418         
00419         /**
00420          * Gets whether a boss has been killed or not.
00421          *
00422          * @param boss The boss to check.
00423          *
00424          * @return true if the boss is dead; false otherwise.
00425          */
00426         bool getBoss(enum Boss boss) const;
00427         
00428         /**
00429          * Sets whether a boss has been killed or not.
00430          *
00431          * @param boss The boss.
00432          * @param dead true to kill the boss; false otherwise.
00433          */
00434         void setBoss(enum Boss boss, bool dead = true);
00435         
00436         /**
00437          * Gets the button associated with an action.
00438          *
00439          * @param action The action the button is associated with.
00440          *
00441          * @return The button.
00442          *
00443          * @throw InvalidButtonException if the action has no valid button
00444          *                               associated with it.
00445          */
00446         enum Button getButton(enum Action action) const
00447             throw(InvalidButtonException);
00448         
00449         /**
00450          * Sets the button associated with an action.
00451          *
00452          * @param action The action the button is to be associated with.
00453          * @param button The button to associate with the action.
00454          */
00455         void setButton(enum Action action, enum Button button);
00456         
00457         /**
00458          * Checks if a door is open.
00459          *
00460          * @param door The door to check.
00461          *
00462          * @return true if the door is open; false otherwise.
00463          */
00464         bool getDoor(int door) const;
00465         
00466         /**
00467          * Sets whether a door is open or not.
00468          *
00469          * @param door The door.
00470          * @param open true to open the door; false otherwise.
00471          */
00472         void setDoor(int door, bool open = true);
00473         
00474         /**
00475          * Gets the amount of energy Samus has.
00476          *
00477          * @return Samus' energy.
00478          */
00479         wxUint16 getEnergy() const;
00480         
00481         /**
00482          * Sets the amount of energy Samus has.
00483          *
00484          * @param energy Samus' energy.
00485          */
00486         void setEnergy(wxUint16 energy = 0x5DB);
00487         
00488         /**
00489          * Checks if Samus has a particular energy tank.
00490          *
00491          * @param tank The tank to check for.
00492          *
00493          * @return true if Samus has the energy tank; false otherwise.
00494          */
00495         bool hasEnergyTank(int tank) const;
00496         
00497         /**
00498          * Sets whether Samus has a particular energy tank or not.
00499          *
00500          * @param tank The tank to set.
00501          * @param give true to give the energy tank; false otherwise.
00502          */
00503         void setEnergyTank(int tank, bool give = true);
00504         
00505         /**
00506          * Gets the current game being edited.
00507          *
00508          * @return The current game (0-2).
00509          */
00510         int getGame() const;
00511         
00512         /**
00513          * Sets the game to be edited.
00514          *
00515          * @param game The game number (0-2).
00516          */
00517         void setGame(int game = 0);
00518         
00519         /**
00520          * Gets the number of game hours played.
00521          *
00522          * @return The game hours.
00523          */
00524         unsigned char getGameHours() const;
00525         
00526         /**
00527          * Sets the number of game hours played.
00528          *
00529          * @param hours The game hours.
00530          */
00531         void setGameHours(unsigned char hours = 0);
00532         
00533         /**
00534          * Gets the number of game minutes played.
00535          *
00536          * @return The game minutes.
00537          */
00538         unsigned char getGameMinutes() const;
00539         
00540         /**
00541          * Sets the number of game minutes played.
00542          *
00543          * @param minutes The game minutes.
00544          */
00545         void setGameMinutes(unsigned char minutes = 0);
00546         
00547         /**
00548          * Checks if Samus has an item in her inventory.
00549          *
00550          * @param item The item to check for.
00551          *
00552          * @return true if Samus has the item; false otherwise.
00553          */
00554         bool hasItem(enum Item item) const;
00555         
00556         /**
00557          * Sets whether Samus has a particular item.
00558          *
00559          * @param item The item to set.
00560          * @param have true for Samus to have the item; false otherwise.
00561          */
00562         void setItem(enum Item item, bool have = true);
00563         
00564         /**
00565          * Checks whether an item is equipped.
00566          *
00567          * @param item The item to check for.
00568          *
00569          * @return true if the item is equipped; false otherwise.
00570          */
00571         bool isItemEquipped(enum Item item) const;
00572         
00573         /**
00574          * Sets whether an item is equipped or not.
00575          *
00576          * @param item The item to (un)equip.
00577          * @param equipped true to equip the item; false otherwise.
00578          */
00579         void setItemEquipped(enum Item item, bool equipped = true);
00580         
00581         /**
00582          * Checks if Samus has a particular area map.
00583          *
00584          * @param area The area whose map to check for.
00585          *
00586          * @return true if Samus has the map; false otherwise.
00587          */
00588         bool hasMap(enum Area area) const;
00589         
00590         /**
00591          * Sets whether Samus has a particular area map or not.
00592          *
00593          * @param area The area for the map.
00594          * @param give true to give the map; false otherwise.
00595          */
00596         void setMap(enum Area area, bool give = true);
00597         
00598         /**
00599          * Gets the maximum energy Samus can have.
00600          *
00601          * @return The max energy.
00602          */
00603         wxUint16 getMaxEnergy() const;
00604         
00605         /**
00606          * Gets the maximum number of missiles Samus can carry.
00607          *
00608          * @return The max missiles.
00609          */
00610         unsigned char getMaxMissiles() const;
00611         
00612         /**
00613          * Gets the maximum number of power bombs Samus can carry.
00614          *
00615          * @return The max power bombs.
00616          */
00617         unsigned char getMaxPowerBombs() const;
00618         
00619         /**
00620          * Gets the maximum reserve energy Samus can have.
00621          *
00622          * @return The max reserve energy.
00623          */
00624         wxUint16 getMaxReserveEnergy() const;
00625         
00626         /**
00627          * Gets the maximum number of super missiles Samus can carry.
00628          *
00629          * @return The max super missiles.
00630          */
00631         unsigned char getMaxSuperMissiles() const;
00632         
00633         /**
00634          * Checks if one of the Metroid rooms in Tourian has been cleared.
00635          *
00636          * @param room The room to check.
00637          *
00638          * @return true if the room has been cleared; false otherwise.
00639          */
00640         bool getMetroidRoom(enum MetroidRoom room) const;
00641         
00642         /**
00643          * Sets whether one of the Metroid rooms in Tourian is clear or not;
00644          *
00645          * @param room The room.
00646          * @param clear true to clear the room; false otherwise.
00647          */
00648         void setMetroidRoom(enum MetroidRoom room, bool clear = true);
00649         
00650         /**
00651          * Gets one of the miscellaneous bits that don't fit in with any other
00652          * group of data.
00653          *
00654          * @param bit The bit to get.
00655          *
00656          * @return true if the bit is active; false otherwise.
00657          */
00658         bool getMiscBit(enum MiscBit bit) const;
00659         
00660         /**
00661          * Sets one of the miscellaneous bits that don't fit in with any other
00662          * group of data.
00663          *
00664          * @param bit The bit to set.
00665          * @param on true to set the bit; false otherwise.
00666          */
00667         void setMiscBit(enum MiscBit bit, bool on = true);
00668         
00669         /**
00670          * Checks if Samus has a particular missile pack.
00671          *
00672          * @param pack The missile pack to check.
00673          *
00674          * @return true if Samus has the missile pack; false otherwise.
00675          */
00676         bool hasMissilePack(int pack) const;
00677         
00678         /**
00679          * Sets whether Samus has a particular missile pack or not.
00680          *
00681          * @param pack The missile pack.
00682          * @param give true to give the missile pack; false otherwise.
00683          */
00684         void setMissilePack(int pack, bool give = true);
00685         
00686         /**
00687          * Gets the number of missiles in Samus' inventory.
00688          *
00689          * @return The number of missiles.
00690          */
00691         unsigned char getMissiles() const;
00692         
00693         /**
00694          * Sets the number of missiles in Samus' inventory.
00695          *
00696          * @param missiles The number of missiles.
00697          */
00698         void setMissiles(unsigned char missiles = 0xE6);
00699         
00700         /**
00701          * Checks if this SRAMFile has been modified.
00702          *
00703          * @return true if the SRAMFile has been modified; false otherwise.
00704          */
00705         bool isModified() const;
00706         
00707         /**
00708          * Checks if Samus has a particular power bomb pack.
00709          *
00710          * @param pack The power bomb pack to check.
00711          *
00712          * @return true if Samus has the power bomb pack; false otherwise.
00713          */
00714         bool hasPowerBombPack(int pack) const;
00715         
00716         /**
00717          * Sets whether Samus has a particular power bomb pack or not.
00718          *
00719          * @param pack The power bomb pack.
00720          * @param give true to give the power bomb pack; false otherwise.
00721          */
00722         void setPowerBombPack(int pack, bool give = true);
00723         
00724         /**
00725          * Gets the number of power bombs in Samus' inventory.
00726          *
00727          * @return The number of power bombs.
00728          */
00729         unsigned char getPowerBombs() const;
00730         
00731         /**
00732          * Sets the number of power bombs in Samus' inventory.
00733          *
00734          * @param bombs The number of power bombs.
00735          */
00736         void setPowerBombs(unsigned char bombs = 0x32);
00737         
00738         /**
00739          * Gets the amount of reserve energy Samus has.
00740          *
00741          * @return Samus' reserve energy.
00742          */
00743         wxUint16 getReserveEnergy() const;
00744         
00745         /**
00746          * Sets the amount of reserve energy Samus has.
00747          *
00748          * @param energy Samus' reserve energy.
00749          */
00750         void setReserveEnergy(wxUint16 energy = 0x190);
00751         
00752         /**
00753          * Checks if Samus has a particular reserve tank.
00754          *
00755          * @param tank The reserve tank to check.
00756          *
00757          * @return true if Samus has the reserve tank; false otherwise.
00758          */
00759         bool hasReserveTank(int tank) const;
00760         
00761         /**
00762          * Sets whether Samus has a particular reserve tank or not.
00763          *
00764          * @param tank The reserve tank.
00765          * @param give true to give the reserve tank; false otherwise.
00766          */
00767         void setReserveTank(int tank, bool give = true);
00768         
00769         /**
00770          * Gets the save point.
00771          *
00772          * @return The save point as a std::pair consisting of the area and the
00773          *         specific save point within the area.
00774          */
00775         std::pair<enum Area, int> getSavePoint() const;
00776         
00777         /**
00778          * Sets the save point.
00779          *
00780          * @param area The area of the save point.
00781          * @param point The specific save point within the area.
00782          */
00783         void setSavePoint(enum Area area, int point = 0);
00784         
00785         /**
00786          * Gets whether a boss statue has been activated or not.
00787          *
00788          * @param statue The statue to check.
00789          *
00790          * @return true if the statue has been activated; false otherwise.
00791          */
00792         bool getStatue(enum Statue statue) const;
00793         
00794         /**
00795          * Sets whether a boss statue has been activated or not.
00796          *
00797          * @param statue The statue.
00798          * @param active true to activate the statue; false otherwise.
00799          */
00800         void setStatue(enum Statue statue, bool active = true);
00801         
00802         /**
00803          * Checks if Samus has a particular super missile pack.
00804          *
00805          * @param pack The super missile pack to check.
00806          *
00807          * @return true if Samus has the super missile pack; false otherwise.
00808          */
00809         bool hasSuperMissilePack(int pack) const;
00810         
00811         /**
00812          * Sets whether Samus has a particular super missile pack or not.
00813          *
00814          * @param pack The super missile pack.
00815          * @param give true to give the super missile pack; false otherwise.
00816          */
00817         void setSuperMissilePack(int pack, bool give = true);
00818         
00819         /**
00820          * Gets the number of super missiles in Samus' inventory.
00821          *
00822          * @return The number of super missiles.
00823          */
00824         unsigned char getSuperMissiles() const;
00825         
00826         /**
00827          * Sets the number of super missiles in Samus' inventory.
00828          *
00829          * @param missiles The number of super missiles.
00830          */
00831         void setSuperMissiles(unsigned char missiles = 0x32);
00832         
00833         /**
00834          * Checks if a particular game is valid.
00835          *
00836          * @param game The game to check.
00837          *
00838          * @return true if the game is valid; false otherwise.
00839          */
00840         bool isValidGame(int game = 0) const;
00841         
00842         /**
00843          * Gets the number of Zebetites destroyed.
00844          *
00845          * @return The number of destroyed Zebetites.
00846          */
00847         int getZebetites() const;
00848         
00849         /**
00850          * Sets the number of Zebetites destroyed.
00851          *
00852          * @param count The number of destroyed Zebetites.
00853          */
00854         void setZebetites(int count = 4);
00855         
00856         /**
00857          * Clears a game.
00858          *
00859          * @param game The game to clear (0-2).
00860          */
00861         void clear(int game);
00862         
00863         /**
00864          * Copies one game over another.
00865          *
00866          * @param src The source game (0-2).
00867          * @param dest The destination game (0-2).
00868          */
00869         void copy(int src, int dest);
00870         
00871         /**
00872          * Saves this SRAMFile to disk.
00873          *
00874          * @param filename The filename to save as or wxEmptyString to overwrite
00875          *                 the original file.
00876          *
00877          * @throw FileIOException if the SRAMFile cannot be saved.
00878          */
00879         void save(const wxString &filename = wxEmptyString)
00880             throw(FileIOException);
00881     };
00882     
00883     inline bool SRAMFile::getBit(const std::pair<int, unsigned char> &bit) const
00884         { return (game[bit.first] & bit.second); }
00885         
00886     inline bool SRAMFile::getBoss(enum Boss boss) const
00887         { return getBit(SRAM_OFFSET[boss]); }
00888         
00889     inline void SRAMFile::setBoss(enum Boss boss, bool dead)
00890         { setBit(SRAM_OFFSET[boss], dead); }
00891         
00892     inline int SRAMFile::getGame() const
00893         { return (static_cast<int>(game - sram - GAME_OFFSET) / GAME_SIZE); }
00894         
00895     inline bool SRAMFile::isItemEquipped(enum Item item) const
00896         { return getBit(SRAM_OFFSET[item + 2]); }
00897         
00898     inline void SRAMFile::setItemEquipped(enum Item item, bool equipped)
00899         { setBit(SRAM_OFFSET[item + 2], equipped); }
00900         
00901     inline bool SRAMFile::hasMap(enum Area area) const
00902         { return getBit(SRAM_OFFSET[area + SO_CMAP]); }
00903         
00904     inline void SRAMFile::setMap(enum Area area, bool give)
00905         { setBit(SRAM_OFFSET[area + SO_CMAP], give); }
00906         
00907     inline bool SRAMFile::getMetroidRoom(enum MetroidRoom room) const
00908         { return getBit(SRAM_OFFSET[SO_METROIDROOMS + room]); }
00909         
00910     inline void SRAMFile::setMetroidRoom(enum MetroidRoom room, bool clear)
00911         { setBit(SRAM_OFFSET[SO_METROIDROOMS + room], clear); }
00912         
00913     inline bool SRAMFile::getMiscBit(enum MiscBit bit) const
00914         { return getBit(SRAM_OFFSET[bit]); }
00915         
00916     inline void SRAMFile::setMiscBit(enum MiscBit bit, bool on)
00917         { setBit(SRAM_OFFSET[bit], on); }
00918         
00919     inline bool SRAMFile::isModified() const { return modified; }
00920     
00921     inline bool SRAMFile::getStatue(enum Statue statue) const
00922         { return getBit(SRAM_OFFSET[statue]); }
00923         
00924     inline void SRAMFile::setStatue(enum Statue statue, bool active)
00925         { setBit(SRAM_OFFSET[statue], active); }
00926 }
00927 
00928 #endif
00929 

Generated on Mon Dec 29 01:15:53 2008 for Super Metroid SRAM Editor by  doxygen 1.5.4