neo-geo-pocket.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. struct NeoGeoPocket : Cartridge {
  2. auto name() -> string override { return "Neo Geo Pocket"; }
  3. auto extensions() -> vector<string> override { return {"ngp"}; }
  4. auto export(string location) -> vector<uint8_t> override;
  5. auto heuristics(vector<uint8_t>& data, string location) -> string override;
  6. auto title(vector<uint8_t>& data) -> string;
  7. };
  8. auto NeoGeoPocket::export(string location) -> vector<uint8_t> {
  9. vector<uint8_t> data;
  10. append(data, {location, "program.flash"});
  11. return data;
  12. }
  13. auto NeoGeoPocket::heuristics(vector<uint8_t>& data, string location) -> string {
  14. //expand ROMs that are smaller than valid flash chip sizes (homebrew games)
  15. if(data.size() <= 0x080000) data.resize(0x080000); // 4mbit
  16. else if(data.size() <= 0x100000) data.resize(0x100000); // 8mbit
  17. else if(data.size() <= 0x200000) data.resize(0x200000); //16mbit
  18. else if(data.size() <= 0x280000) data.resize(0x280000); //16mbit + 4mbit
  19. else if(data.size() <= 0x300000) data.resize(0x300000); //16mbit + 8mbit
  20. else if(data.size() <= 0x400000) data.resize(0x400000); //16mbit + 16mbit
  21. string s;
  22. s += "game\n";
  23. s +={" name: ", Media::name(location), "\n"};
  24. s +={" label: ", Media::name(location), "\n"};
  25. s +={" title: ", title(data), "\n"};
  26. s += " board\n";
  27. s += " memory\n";
  28. s += " type: Flash\n";
  29. s +={" size: 0x", hex(data.size()), "\n"};
  30. s += " content: Program\n";
  31. return s;
  32. }
  33. auto NeoGeoPocket::title(vector<uint8_t>& data) -> string {
  34. string title;
  35. title.size(12);
  36. for(uint index : range(12)) {
  37. char letter = data[0x24 + index];
  38. if(letter >= 0x20 && letter <= 0x7e) title.get()[index] = letter;
  39. }
  40. return title.strip();
  41. }