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