File: famicom.cpp

package info (click to toggle)
higan 094-5
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 9,780 kB
  • ctags: 15,643
  • sloc: cpp: 103,963; ansic: 659; makefile: 531; sh: 25
file content (48 lines) | stat: -rwxr-xr-x 1,732 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
void Ananke::copyFamicomSaves(const string &pathname) {
  if(!file::exists({pathname, "save.ram"})) {
    if(file::exists({information.path, nall::basename(information.name), ".sav"})) {
      file::copy({information.path, nall::basename(information.name), ".srm"}, {pathname, "save.ram"});
    }
  }
}

string Ananke::createFamicomHeuristic(vector<uint8_t> &buffer) {
  string pathname = {
    libraryPath, "Famicom/",
    nall::basename(information.name),
    ".fc/"
  };

  FamicomCartridge info(buffer.data(), buffer.size());
  if (info.markup.size() == 0) {
    if(thread::primary()) MessageWindow().setText({
      "Error: ", information.name, "\n\n",
      "The selected game could not be added to the library"
      " because it was not recognized and contains no header."
    }).error();
    return "";
  }

  directory::create(pathname);
  string markup = {"unverified\n\n", info.markup};
  markup.append("\ninformation\n  title: ", nall::basename(information.name), "\n");
  if(!information.manifest.empty()) markup = information.manifest;  //override with embedded beat manifest, if one exists

  file::write({pathname, "manifest.bml"}, markup);
  file::write({pathname, "program.rom"}, buffer.data() + 16, info.prgrom);
  if(info.chrrom > 0) file::write({pathname, "character.rom"}, buffer.data() + 16 + info.prgrom, info.chrrom);

  copyFamicomSaves(pathname);
  return pathname;
}

string Ananke::openFamicom(vector<uint8_t> &buffer) {
  return createFamicomHeuristic(buffer);
}

//this currently cannot work:
//game folders discard iNES header required for heuristic detection
//a games database of all commercial Famicom software will be required
string Ananke::syncFamicom(const string &pathname) {
  return "";
}