| 1 |
#ifndef NALL_EMULATION_GAME_BOY_ADVANCE_HPP |
| 2 |
#define NALL_EMULATION_GAME_BOY_ADVANCE_HPP |
| 3 |
|
| 4 |
#include <nall/sha256.hpp> |
| 5 |
#include <nall/string.hpp> |
| 6 |
#include <nall/vector.hpp> |
| 7 |
|
| 8 |
namespace nall { |
| 9 |
|
| 10 |
struct GameBoyAdvanceCartridge { |
| 11 |
string markup; |
| 12 |
string identifiers; |
| 13 |
inline GameBoyAdvanceCartridge(const uint8_t *data, unsigned size); |
| 14 |
}; |
| 15 |
|
| 16 |
GameBoyAdvanceCartridge::GameBoyAdvanceCartridge(const uint8_t *data, unsigned size) { |
| 17 |
struct Identifier { |
| 18 |
string name; |
| 19 |
unsigned size; |
| 20 |
}; |
| 21 |
vector<Identifier> idlist; |
| 22 |
idlist.append({"SRAM_V", 6}); |
| 23 |
idlist.append({"SRAM_F_V", 8}); |
| 24 |
idlist.append({"EEPROM_V", 8}); |
| 25 |
idlist.append({"FLASH_V", 7}); |
| 26 |
idlist.append({"FLASH512_V", 10}); |
| 27 |
idlist.append({"FLASH1M_V", 9}); |
| 28 |
|
| 29 |
lstring list; |
| 30 |
for(auto &id : idlist) { |
| 31 |
for(signed n = 0; n < size - 16; n++) { |
| 32 |
if(!memcmp(data + n, (const char*)id.name, id.size)) { |
| 33 |
const char *p = (const char*)data + n + id.size; |
| 34 |
if(p[0] >= '0' && p[0] <= '9' |
| 35 |
&& p[1] >= '0' && p[1] <= '9' |
| 36 |
&& p[2] >= '0' && p[2] <= '9' |
| 37 |
) { |
| 38 |
char text[16]; |
| 39 |
memcpy(text, data + n, id.size + 3); |
| 40 |
text[id.size + 3] = 0; |
| 41 |
list.appendOnce(text); |
| 42 |
} |
| 43 |
} |
| 44 |
} |
| 45 |
} |
| 46 |
identifiers = list.merge(","); |
| 47 |
|
| 48 |
markup = ""; |
| 49 |
markup.append("cartridge\n"); |
| 50 |
markup.append(" rom name=program.rom size=0x", hex(size), "\n"); |
| 51 |
if(0); |
| 52 |
else if(identifiers.beginsWith("SRAM_V" )) markup.append(" ram name=save.ram type=SRAM size=0x8000\n"); |
| 53 |
else if(identifiers.beginsWith("SRAM_F_V" )) markup.append(" ram name=save.ram type=FRAM size=0x8000\n"); |
| 54 |
else if(identifiers.beginsWith("EEPROM_V" )) markup.append(" ram name=save.ram type=EEPROM size=0x0\n"); |
| 55 |
else if(identifiers.beginsWith("FLASH_V" )) markup.append(" ram name=save.ram type=FlashROM size=0x10000\n"); |
| 56 |
else if(identifiers.beginsWith("FLASH512_V")) markup.append(" ram name=save.ram type=FlashROM size=0x10000\n"); |
| 57 |
else if(identifiers.beginsWith("FLASH1M_V" )) markup.append(" ram name=save.ram type=FlashROM size=0x20000\n"); |
| 58 |
//if(identifiers.empty() == false) markup.append(" #detected: ", identifiers, "\n"); |
| 59 |
} |
| 60 |
|
| 61 |
} |
| 62 |
|
| 63 |
#endif |