game-boy-advance.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. struct GameBoyAdvance : Cartridge {
  2. auto name() -> string override { return "Game Boy Advance"; }
  3. auto extensions() -> vector<string> override { return {"gba"}; }
  4. auto export(string location) -> vector<uint8_t> override;
  5. auto heuristics(vector<uint8_t>& data, string location) -> string override;
  6. };
  7. auto GameBoyAdvance::export(string location) -> vector<uint8_t> {
  8. vector<uint8_t> data;
  9. append(data, {location, "program.rom"});
  10. return data;
  11. }
  12. auto GameBoyAdvance::heuristics(vector<uint8_t>& data, string location) -> string {
  13. vector<string> identifiers = {
  14. "SRAM_V",
  15. "SRAM_F_V",
  16. "EEPROM_V",
  17. "FLASH_V",
  18. "FLASH512_V",
  19. "FLASH1M_V",
  20. };
  21. vector<string> list;
  22. for(auto& identifier : identifiers) {
  23. for(int n : range(data.size() - 16)) {
  24. if(!memory::compare(&data[n], identifier.data(), identifier.size())) {
  25. auto p = (const char*)&data[n + identifier.size()];
  26. if(p[0] >= '0' && p[0] <= '9'
  27. && p[1] >= '0' && p[1] <= '9'
  28. && p[2] >= '0' && p[2] <= '9'
  29. ) {
  30. char text[16];
  31. memory::copy(text, &data[n], identifier.size() + 3);
  32. text[identifier.size() + 3] = 0;
  33. if(!list.find(text)) list.append(text);
  34. }
  35. }
  36. }
  37. }
  38. string s;
  39. s += "game\n";
  40. s +={" name: ", Media::name(location), "\n"};
  41. s +={" label: ", Media::name(location), "\n"};
  42. s += " board\n";
  43. s += " memory\n";
  44. s += " type: ROM\n";
  45. s +={" size: 0x", hex(data.size()), "\n"};
  46. s += " content: Program\n";
  47. if(list) {
  48. if(list.first().beginsWith("SRAM_V") || list.first().beginsWith("SRAM_F_V")) {
  49. s += " memory\n";
  50. s += " type: RAM\n";
  51. s += " size: 0x8000\n";
  52. s += " content: Save\n";
  53. }
  54. if(list.first().beginsWith("EEPROM_V")) {
  55. s += " memory\n";
  56. s += " type: EEPROM\n";
  57. s += " size: 0x0\n"; //auto-detected
  58. s += " content: Save\n";
  59. }
  60. if(list.first().beginsWith("FLASH_V") || list.first().beginsWith("FLASH512_V")) {
  61. s += " memory\n";
  62. s += " type: Flash\n";
  63. s += " size: 0x10000\n";
  64. s += " content: Save\n";
  65. s += " manufacturer: Macronix\n";
  66. }
  67. if(list.first().beginsWith("FLASH1M_V")) {
  68. s += " memory\n";
  69. s += " type: Flash\n";
  70. s += " size: 0x20000\n";
  71. s += " content: Save\n";
  72. s += " manufacturer: Macronix\n";
  73. }
  74. }
  75. return s;
  76. }