00001 /* 00002 * ffse 00003 * Copyright (C) 2004-2005 emuWorks 00004 * http://games.technoplaza.net/ 00005 * 00006 * This file is part of ffse. 00007 * 00008 * ffse 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 * ffse 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 ffse; if not, write to the Free Software 00020 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00021 */ 00022 00023 // $Id: SaveSlot.hh,v 1.9 2007/02/18 22:02:58 technoplaza Exp $ 00024 00025 #ifndef _SAVE_SLOT_HH 00026 #define _SAVE_SLOT_HH 00027 00028 /// The size of the save game in SRAM 00029 #define GAME_SIZE 0x400 00030 00031 /// The size of the SRAM 00032 #define SRAM_SIZE 0x2000 00033 00034 /// The offset of the game data in the SRAM 00035 #define GAME_OFFSET 0x400 00036 00037 /// Checksum offset within the GAME data 00038 #define CHECKSUM_OFFSET 0xFD 00039 00040 /// SRAM offset of the gold 00041 #define GOLD_OFFSET 0x1C 00042 00043 /// Starting SRAM offset for the game items 00044 #define ITEM_OFFSET 0x12 00045 00046 /// Offset beween similar member attributes 00047 #define MEMBER_GAP 0x40 00048 00049 /// SRAM offset for the member's name 00050 #define NAME_OFFSET 0x102 00051 00052 /// SRAM offset for the member's class 00053 #define CLASS_OFFSET 0x100 00054 00055 /// SRAM offset for the member's condition 00056 #define CONDITION_OFFSET 0x101 00057 00058 /// SRAM offset for member's current HP 00059 #define CURRENT_HP_OFFSET 0x10A 00060 00061 /// SRAM offset for member's max HP 00062 #define MAX_HP_OFFSET 0x10C 00063 00064 /// SRAM offset for member's experience 00065 #define EXPERIENCE_OFFSET 0x107 00066 00067 /// SRAM offset for member's strength 00068 #define STRENGTH_OFFSET 0x110 00069 00070 /// SRAM offset for member's agility 00071 #define AGILITY_OFFSET 0x111 00072 00073 /// SRAM offset for member's intelligence 00074 #define INTELLIGENCE_OFFSET 0x112 00075 00076 /// SRAM offset for member's vitality 00077 #define VITALITY_OFFSET 0x113 00078 00079 /// SRAM offset for member's luck 00080 #define LUCK_OFFSET 0x114 00081 00082 /// SRAM offset for member's damage 00083 #define DAMAGE_OFFSET 0x120 00084 00085 /// SRAM offset for member's hit percent 00086 #define HIT_PERCENT_OFFSET 0x121 00087 00088 /// Starting SRAM offset for member's weapons 00089 #define WEAPON_OFFSET 0x118 00090 00091 /// Starting SRAM offset for member's armor 00092 #define ARMOR_OFFSET 0x11C 00093 00094 /// Starting SRAM offset for member's current magic 00095 #define CURRENT_MAGIC_OFFSET 0x320 00096 00097 /// Starting SRAM offset for member's max magic 00098 #define MAX_MAGIC_OFFSET 0x328 00099 00100 /// Starting SRAM offset for member's magic spells 00101 #define MAGIC_OFFSET 0x300 00102 00103 namespace ffse { 00104 /// The known game items 00105 enum Items { 00106 CANOE, LUTE = 15, CROWN, CRYSTAL, HERB, KEY, TNT, ADAMENT, SLAB, RUBY, 00107 ROD, FLOATER, CHIME, TAIL, CUBE, BOTTLE, OXYALE, INVALID, FIREORB, 00108 WATERORB, WINDORB, EARTHORB, TENT, CABIN, HOUSE, HEALP, PUREP, SOFTP 00109 }; 00110 00111 /** 00112 * Class to encapsulate SRAM data and provide I/O within its framework. 00113 */ 00114 class SaveSlot { 00115 friend class MainFrame; 00116 00117 public: 00118 /** 00119 * Constructor for a SaveSlot. 00120 * 00121 * @param nvram The SRAM game data, which must be 0x400 bytes long. 00122 */ 00123 SaveSlot(const char *nvram); 00124 00125 /** 00126 * Destructor for a SaveSlot. 00127 */ 00128 ~SaveSlot(); 00129 00130 /** 00131 * Checks if this SaveSlot is valid. 00132 * 00133 * @return true if valid; false otherwise. 00134 */ 00135 bool isValid() { return valid; } 00136 00137 /** 00138 * Checks if this SaveSlot has been modified; 00139 * 00140 * @return true if modified; false otherwise. 00141 */ 00142 bool isModified() { return modified; } 00143 00144 /** 00145 * Generates a checksum for the current game data. 00146 * 00147 * @return The generated checksum. 00148 */ 00149 unsigned char checksum(); 00150 00151 /** 00152 * Gets the current amount of gold help by the party. 00153 * 00154 * @return The current gold. 00155 */ 00156 wxInt32 getGold(); 00157 00158 /** 00159 * Sets the current amount of gold help by the party. 00160 * 00161 * @param value The new value. 00162 */ 00163 void setGold(wxInt32 value); 00164 00165 /** 00166 * Gets the current amount of a particular item. 00167 * 00168 * @param item The item whose amount to retrieve. Valid values are any 00169 * of the Items enumeration. 00170 * 00171 * @return The current amount of the item. 00172 */ 00173 int getItem(int item); 00174 00175 /** 00176 * Sets the current amount of a particular item. 00177 * 00178 * @param item The item whose amount to set. Valid values are any 00179 * of the Items enumeration. 00180 * @param value The new amount. 00181 */ 00182 void setItem(int item, unsigned char value = 1); 00183 00184 /** 00185 * Gets the name for a particular party member. 00186 * 00187 * @param member The party member. Valid values are 0-3. 00188 * 00189 * @return The name. 00190 */ 00191 wxString getName(int member); 00192 00193 /** 00194 * Sets the name for a particular party member. 00195 * 00196 * @param member The party member. Valid values are 0-3. 00197 * @param value The new value. 00198 */ 00199 void setName(int member, wxString &value); 00200 00201 /** 00202 * Gets the class of a particular party member. 00203 * 00204 * @param member The party member. Valid values are 0-3. 00205 * 00206 * @return The class. 00207 */ 00208 int getClass(int member); 00209 00210 /** 00211 * Sets the class of a particular party member. 00212 * 00213 * @param member The party member. Valid values are 0-3. 00214 * @param value The new value. 00215 */ 00216 void setClass(int member, unsigned char value); 00217 00218 /** 00219 * Gets the condition of a party member. 00220 * 00221 * @param member The party member. Valid values are 0-3. 00222 * 00223 * @return The condition. 00224 */ 00225 int getCondition(int member); 00226 00227 /** 00228 * Sets the condition of a party member. 00229 * 00230 * @param member The party member. Valid values are 0-3. 00231 * @param value The new value. 00232 */ 00233 void setCondition(int member, unsigned char value); 00234 00235 /** 00236 * Gets the experience of a party member. 00237 * 00238 * @param member The party member. Valid values are 0-3. 00239 * 00240 * @return The experience. 00241 */ 00242 wxInt32 getExperience(int member); 00243 00244 /** 00245 * Gets the current HP of a party member. 00246 * 00247 * @param member The party member. Valid values are 0-3. 00248 * 00249 * @return The current HP. 00250 */ 00251 wxInt16 getCurrentHP(int member); 00252 00253 /** 00254 * Sets the current HP of a party member. 00255 * 00256 * @param member The party member. Valid values are 0-3. 00257 * @param value The new value. 00258 */ 00259 void setCurrentHP(int member, wxInt16 value); 00260 00261 /** 00262 * Gets the max HP of a party member. 00263 * 00264 * @param member The party member. Valid values are 0-3. 00265 * 00266 * @return The max HP. 00267 */ 00268 wxInt16 getMaxHP(int member); 00269 00270 /** 00271 * Sets the max HP of a party member. 00272 * 00273 * @param member The party member. Valid values are 0-3. 00274 * @param value The new value. 00275 */ 00276 void setMaxHP(int member, wxInt16 value); 00277 00278 /** 00279 * Sets the experience of a party member. 00280 * 00281 * @param member The party member. Valid values are 0-3. 00282 * @param value The new value. 00283 */ 00284 void setExperience(int member, wxInt32 value); 00285 00286 /** 00287 * Gets the strength of a party member. 00288 * 00289 * @param member The party member. Valid values are 0-3. 00290 * 00291 * @return The strength. 00292 */ 00293 int getStrength(int member); 00294 00295 /** 00296 * Sets the strength of a party member. 00297 * 00298 * @param member The party member. Valid values are 0-3. 00299 * @param value The new value. 00300 */ 00301 void setStrength(int member, unsigned char value); 00302 00303 /** 00304 * Gets the agility of a party member. 00305 * 00306 * @param member The party member. Valid values are 0-3. 00307 * 00308 * @return The agility. 00309 */ 00310 int getAgility(int member); 00311 00312 /** 00313 * Sets the agility of a party member. 00314 * 00315 * @param member The party member. Valid values are 0-3. 00316 * @param value The new value. 00317 */ 00318 void setAgility(int member, unsigned char value); 00319 00320 /** 00321 * Gets the intelligence of a party member. 00322 * 00323 * @param member The party member. Valid values are 0-3. 00324 * 00325 * @return The intelligence. 00326 */ 00327 int getIntelligence(int member); 00328 00329 /** 00330 * Sets the intelligence of a party member. 00331 * 00332 * @param member The party member. Valid values are 0-3. 00333 * @param value The new value. 00334 */ 00335 void setIntelligence(int member, unsigned char value); 00336 00337 /** 00338 * Gets the vitality of a party member. 00339 * 00340 * @param member The party member. Valid values are 0-3. 00341 * 00342 * @return The vitality. 00343 */ 00344 int getVitality(int member); 00345 00346 /** 00347 * Sets the vitality of a party member. 00348 * 00349 * @param member The party member. Valid values are 0-3. 00350 * @param value The new value. 00351 */ 00352 void setVitality(int member, unsigned char value); 00353 00354 /** 00355 * Gets the luck of a party member. 00356 * 00357 * @param member The party member. Valid values are 0-3. 00358 * 00359 * @return The luck. 00360 */ 00361 int getLuck(int member); 00362 00363 /** 00364 * Sets the luck of a party member. 00365 * 00366 * @param member The party member. Valid values are 0-3. 00367 * @param value The new value. 00368 */ 00369 void setLuck(int member, unsigned char value); 00370 00371 /** 00372 * Gets the damage of a party member. 00373 * 00374 * @param member The party member. Valid values are 0-3. 00375 * 00376 * @return The damage. 00377 */ 00378 int getDamage(int member); 00379 00380 /** 00381 * Sets the damage of a party member. 00382 * 00383 * @param member The party member. Valid values are 0-3. 00384 * @param value The new value. 00385 */ 00386 void setDamage(int member, unsigned char value); 00387 00388 /** 00389 * Gets the hit percent of a party member. 00390 * 00391 * @param member The party member. Valid values are 0-3. 00392 * 00393 * @return The hit percent. 00394 */ 00395 int getHitPercent(int member); 00396 00397 /** 00398 * Sets the hit percent of a party member. 00399 * 00400 * @param member The party member. Valid values are 0-3. 00401 * @param value The new value. 00402 */ 00403 void setHitPercent(int member, unsigned char value); 00404 00405 /** 00406 * Gets the weapon of a party member at a given slot. 00407 * 00408 * @param member The party member. Valid values are 0-3. 00409 * @param slot The slot. Valid values are 0-3. 00410 * 00411 * @return The weapon. 00412 */ 00413 int getWeapon(int member, int slot); 00414 00415 /** 00416 * Sets the weapon of a party member at a given slot. 00417 * 00418 * @param member The party member. Valid values are 0-3. 00419 * @param slot The slot. Valid values are 0-3. 00420 * @param value The new value. 00421 */ 00422 void setWeapon(int member, int slot, unsigned char value); 00423 00424 /** 00425 * Gets the armor of a party member at a given slot. 00426 * 00427 * @param member The party member. Valid values are 0-3. 00428 * @param slot The slot. Valid values are 0-3. 00429 * 00430 * @return The armor. 00431 */ 00432 int getArmor(int member, int slot); 00433 00434 /** 00435 * Sets the armor of a party member at a given slot. 00436 * 00437 * @param member The party member. Valid values are 0-3. 00438 * @param slot The slot. Valid values are 0-3. 00439 * @param value The new value. 00440 */ 00441 void setArmor(int member, int slot, unsigned char value); 00442 00443 /** 00444 * Gets the current magic of a party member at a given level. 00445 * 00446 * @param member The party member. Valid values are 0-3. 00447 * @param level The magic level. Valid values are 0-7. 00448 * 00449 * @return The current magic. 00450 */ 00451 int getCurrentMagic(int member, int level); 00452 00453 /** 00454 * Sets the current magic of a party member at a given level. 00455 * 00456 * @param member The party member. Valid values are 0-3. 00457 * @param level The magic level. Valid values are 0-7. 00458 * @param value The new value. 00459 */ 00460 void setCurrentMagic(int member, int level, unsigned char value); 00461 00462 /** 00463 * Gets the max magic of a party member at a given level. 00464 * 00465 * @param member The party member. Valid values are 0-3. 00466 * @param level The magic level. Valid values are 0-7. 00467 * 00468 * @return The max magic. 00469 */ 00470 int getMaxMagic(int member, int level); 00471 00472 /** 00473 * Sets the max magic of a party member at a given level. 00474 * 00475 * @param member The party member. Valid values are 0-3. 00476 * @param level The magic level. Valid values are 0-7. 00477 * @param value The new value. 00478 */ 00479 void setMaxMagic(int member, int level, unsigned char value); 00480 00481 /** 00482 * Gets the magic of a party member at a given level. 00483 * 00484 * @param member The party member. Valid values are 0-3. 00485 * @param level The magic level. Valid values are 0-7. 00486 * @param slot The slot. Valid values are 0-2. 00487 * 00488 * @return The magic. 00489 */ 00490 int getMagic(int member, int level, int slot); 00491 00492 /** 00493 * Sets the magic of a party member at a given level. 00494 * 00495 * @param member The party member. Valid values are 0-3. 00496 * @param level The magic level. Valid values are 0-7. 00497 * @param slot The slot. Valid values are 0-2. 00498 * @param value The new value. 00499 */ 00500 void setMagic(int member, int level, int slot, unsigned char value); 00501 00502 private: 00503 /** 00504 * Performs an add with carry operation. 00505 * 00506 * @param current The current value. 00507 * @param value The value to add. 00508 * 00509 * @return The combined value plus the carry value, if applicable. 00510 */ 00511 unsigned char adc(unsigned char current, unsigned char value); 00512 00513 /** 00514 * Sets or clears the carry flag used by adc. 00515 * 00516 * @param set Whether to set the carry flag or not. 00517 */ 00518 void setCarry(bool set = true) { carry = (set ? 1 : 0); } 00519 00520 /** 00521 * Sets whether this SaveSlot has been modified or not. 00522 * 00523 * @param modified true if modified; false otherwise. 00524 */ 00525 void setModified(bool modified = true); 00526 00527 /** 00528 * Translates a character from ASCII to the Final Fantasy alphabet. 00529 * 00530 * @param letter The letter to translate. 00531 * 00532 * @return The translated letter. 00533 */ 00534 static unsigned char toNES(char letter); 00535 00536 /** 00537 * Translates a character from the Final Fantasy alphabet to ASCII. 00538 * 00539 * @param letter The letter to translate. 00540 * 00541 * @return The translated letter. 00542 */ 00543 static char fromNES(unsigned char letter); 00544 00545 unsigned char *nvram; 00546 int carry; 00547 bool valid, modified; 00548 }; 00549 } 00550 00551 #endif 00552