states.cpp 931 B

12345678910111213141516171819202122232425262728293031
  1. auto Program::stateSave(uint slot) -> bool {
  2. if(!emulator) return false;
  3. auto location = emulator->locate(emulator->game.location, {".bs", slot}, settings.paths.saves);
  4. if(auto state = emulator->interface->serialize()) {
  5. if(file::write(location, {state.data(), state.size()})) {
  6. showMessage({"Saved state to slot ", slot});
  7. return true;
  8. }
  9. }
  10. showMessage({"Failed to save state to slot ", slot});
  11. return false;
  12. }
  13. auto Program::stateLoad(uint slot) -> bool {
  14. if(!emulator) return false;
  15. auto location = emulator->locate(emulator->game.location, {".bs", slot}, settings.paths.saves);
  16. if(auto memory = file::read(location)) {
  17. serializer state{memory.data(), (uint)memory.size()};
  18. if(emulator->interface->unserialize(state)) {
  19. showMessage({"Loaded state from slot ", slot});
  20. return true;
  21. }
  22. }
  23. showMessage({"Failed to load state from slot ", slot});
  24. return false;
  25. }