File: states.cpp

package info (click to toggle)
ares 126-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 32,600 kB
  • sloc: cpp: 356,508; ansic: 20,394; makefile: 16; sh: 2
file content (30 lines) | stat: -rw-r--r-- 920 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
auto Program::stateSave(u32 slot) -> bool {
  if(!emulator) return false;

  auto location = emulator->locate(emulator->game->location, {".bs", slot}, settings.paths.saves);
  if(auto state = emulator->root->serialize()) {
    if(file::write(location, {state.data(), state.size()})) {
      showMessage({"Saved state to slot ", slot});
      return true;
    }
  }

  showMessage({"Failed to save state to slot ", slot});
  return false;
}

auto Program::stateLoad(u32 slot) -> bool {
  if(!emulator) return false;

  auto location = emulator->locate(emulator->game->location, {".bs", slot}, settings.paths.saves);
  if(auto memory = file::read(location)) {
    serializer state{memory.data(), (u32)memory.size()};
    if(emulator->root->unserialize(state)) {
      showMessage({"Loaded state from slot ", slot});
      return true;
    }
  }

  showMessage({"Failed to load state from slot ", slot});
  return false;
}