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