00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef LOZSRAME_SRAMFILE_HH_
00025 #define LOZSRAME_SRAMFILE_HH_
00026
00027 #include <QString>
00028
00029 #include "exceptions/invalidsramfileexception.hh"
00030
00031 namespace lozsrame {
00032
00033 const int ARROWS_OFFSET = 0x2;
00034
00035
00036 const int BOMBCAPACITY_OFFSET = 0x25;
00037
00038
00039 const int BOMBS_OFFSET = 0x1;
00040
00041
00042 const int CANDLE_OFFSET = 0x4;
00043
00044
00045 const int CHECKSUM_OFFSET = 0x524;
00046
00047
00048 const int COMPASS_OFFSET = 0x10;
00049
00050
00051 const int COMPASS9_OFFSET = 0x12;
00052
00053
00054 const int HEARTCONTAINERS_OFFSET = 0x18;
00055
00056
00057 const int INVENTORY_DATA = 0x1A;
00058
00059
00060 const int INVENTORY_DATA_SIZE = 0x28;
00061
00062
00063 const int KEYS_OFFSET = 0x17;
00064
00065
00066 const int MAP_DATA = 0x92;
00067
00068
00069 const int MAP_DATA_SIZE = 0x180;
00070
00071
00072 const int MAP_OFFSET = 0x11;
00073
00074
00075 const int MAP9_OFFSET = 0x13;
00076
00077
00078 const int MISC_DATA = 0x512;
00079
00080
00081 const int MISC_DATA_SIZE = 0x4;
00082
00083
00084 const int NAME_DATA = 0x2;
00085
00086
00087 const int NAME_DATA_SIZE = 0x8;
00088
00089
00090 const int NOTE_OFFSET = 0xF;
00091
00092
00093 const int QUEST_OFFSET = 0x9;
00094
00095
00096 const int PLAYCOUNT_OFFSET = 0x6;
00097
00098
00099 const int POTION_OFFSET = 0x7;
00100
00101
00102 const int RING_OFFSET = 0xB;
00103
00104
00105 const int RUPEES_OFFSET = 0x16;
00106
00107
00108 const int SRAM_SIZE = 0x2000;
00109
00110
00111 const int SWORD_OFFSET = 0x0;
00112
00113
00114 const int TRIFORCE_OFFSET = 0x1A;
00115
00116
00117 enum sf_arrow {
00118 ARROW_NONE, ARROW_WOODEN, ARROW_SILVER
00119 };
00120
00121
00122 enum sf_candle {
00123 CANDLE_NONE, CANDLE_BLUE, CANDLE_RED
00124 };
00125
00126
00127 enum sf_item {
00128 ITEM_BOW = 3, ITEM_WHISTLE = 5, ITEM_BAIT, ITEM_WAND = 8, ITEM_RAFT,
00129 ITEM_BOOK, ITEM_LADDER = 12, ITEM_MAGICKEY, ITEM_POWERBRACELET,
00130 ITEM_BOOMERANG = 29, ITEM_MAGICBOOMERANG, ITEM_MAGICSHIELD
00131 };
00132
00133
00134 enum sf_note {
00135 NOTE_OLDMAN, NOTE_LINK, NOTE_OLDWOMAN
00136 };
00137
00138
00139 enum sf_potion {
00140 POTION_NONE, POTION_BLUE, POTION_RED
00141 };
00142
00143
00144 enum sf_quest {
00145 QUEST_FIRST, QUEST_SECOND
00146 };
00147
00148
00149 enum sf_ring {
00150 RING_NONE, RING_BLUE, RING_RED
00151 };
00152
00153
00154 enum sf_sword {
00155 SWORD_NONE, SWORD_WOODEN, SWORD_WHITE, SWORD_MASTER
00156 };
00157
00158
00159
00160
00161 class SRAMFile {
00162 private:
00163 int game;
00164 char sram[SRAM_SIZE];
00165 bool modified, valid[3];
00166
00167
00168
00169
00170
00171
00172
00173
00174 quint16 checksum(int game) const;
00175
00176
00177
00178
00179
00180
00181
00182
00183 quint16 getChecksum(int game) const;
00184
00185
00186
00187
00188
00189
00190
00191 void setChecksum(int game, quint16 checksum);
00192
00193 public:
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203 SRAMFile(const QString &filename) throw(InvalidSRAMFileException);
00204
00205
00206
00207
00208
00209
00210
00211
00212 bool save(const QString &filename);
00213
00214
00215
00216
00217
00218
00219 enum sf_arrow getArrows() const;
00220
00221
00222
00223
00224
00225
00226 void setArrows(sf_arrow arrows);
00227
00228
00229
00230
00231
00232
00233 int getBombCapacity() const;
00234
00235
00236
00237
00238
00239
00240 void setBombCapacity(int capacity);
00241
00242
00243
00244
00245
00246
00247 int getBombs() const;
00248
00249
00250
00251
00252
00253
00254 void setBombs(int bombs);
00255
00256
00257
00258
00259
00260
00261 enum sf_candle getCandle() const;
00262
00263
00264
00265
00266
00267
00268 void setCandle(enum sf_candle candle);
00269
00270
00271
00272
00273
00274
00275
00276
00277 bool hasCompass(int level) const;
00278
00279
00280
00281
00282
00283
00284
00285 void setCompass(int level, bool give);
00286
00287
00288
00289
00290
00291
00292 int getGame() const;
00293
00294
00295
00296
00297
00298
00299 void setGame(int game);
00300
00301
00302
00303
00304
00305
00306 int getHeartContainers() const;
00307
00308
00309
00310
00311
00312
00313 void setHeartContainers(int containers);
00314
00315
00316
00317
00318
00319
00320
00321
00322 bool hasItem(sf_item item) const;
00323
00324
00325
00326
00327
00328
00329
00330 void setItem(sf_item item, bool give);
00331
00332
00333
00334
00335
00336
00337 int getKeys() const;
00338
00339
00340
00341
00342
00343
00344 void setKeys(int keys);
00345
00346
00347
00348
00349
00350
00351
00352
00353 bool hasMap(int level) const;
00354
00355
00356
00357
00358
00359
00360
00361 void setMap(int level, bool give);
00362
00363
00364
00365
00366
00367
00368 bool isModified() const;
00369
00370
00371
00372
00373
00374
00375 QString getName() const;
00376
00377
00378
00379
00380
00381
00382 void setName(const QString &name);
00383
00384
00385
00386
00387
00388
00389 enum sf_note getNote() const;
00390
00391
00392
00393
00394
00395
00396 void setNote(enum sf_note note);
00397
00398
00399
00400
00401
00402
00403 int getPlayCount() const;
00404
00405
00406
00407
00408
00409
00410 void setPlayCount(int count);
00411
00412
00413
00414
00415
00416
00417 enum sf_potion getPotion() const;
00418
00419
00420
00421
00422
00423
00424 void setPotion(enum sf_potion potion);
00425
00426
00427
00428
00429
00430
00431 enum sf_quest getQuest() const;
00432
00433
00434
00435
00436
00437
00438 void setQuest(enum sf_quest quest);
00439
00440
00441
00442
00443
00444
00445 enum sf_ring getRing() const;
00446
00447
00448
00449
00450
00451
00452 void setRing(enum sf_ring ring);
00453
00454
00455
00456
00457
00458
00459 int getRupees() const;
00460
00461
00462
00463
00464
00465
00466 void setRupees(int rupees);
00467
00468
00469
00470
00471
00472
00473 enum sf_sword getSword() const;
00474
00475
00476
00477
00478
00479
00480 void setSword(enum sf_sword sword);
00481
00482
00483
00484
00485
00486
00487
00488
00489 bool hasTriforce(int piece) const;
00490
00491
00492
00493
00494
00495
00496
00497 void setTriforce(int piece, bool give);
00498
00499
00500
00501
00502
00503
00504
00505
00506 bool isValid(int game) const;
00507 };
00508
00509 inline int SRAMFile::getGame() const
00510 {
00511 return game;
00512 }
00513
00514 inline void SRAMFile::setGame(int game)
00515 {
00516 Q_ASSERT(isValid(game));
00517
00518 this->game = game;
00519 }
00520
00521 inline bool SRAMFile::isModified() const
00522 {
00523 return modified;
00524 }
00525
00526 inline bool SRAMFile::isValid(int game) const
00527 {
00528 Q_ASSERT((game >= 0) && (game <= 2));
00529
00530 return valid[game];
00531 }
00532 }
00533
00534 #endif
00535