states.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. auto Emulator::saveState(uint slot) -> bool {
  2. if(!system.power) return false;
  3. if(auto cartridge = root->find<higan::Node::Peripheral>(0)) {
  4. if(auto location = cartridge->attribute("location")) {
  5. if(auto state = interface->serialize()) {
  6. directory::create({location, "State/"});
  7. if(file::write({location, "State/Slot ", slot, ".bst"}, {state.data(), state.size()})) {
  8. showMessage({"Saved state ", slot});
  9. return true;
  10. }
  11. }
  12. }
  13. }
  14. showMessage({"Failed to save state ", slot});
  15. return false;
  16. }
  17. auto Emulator::loadState(uint slot) -> bool {
  18. if(!system.power) return false;
  19. if(auto cartridge = root->find<higan::Node::Peripheral>(0)) {
  20. if(auto location = cartridge->attribute("location")) {
  21. if(auto memory = file::read({location, "State/Slot ", slot, ".bst"})) {
  22. serializer state{memory.data(), (uint)memory.size()};
  23. if(interface->unserialize(state)) {
  24. showMessage({"Loaded state ", slot});
  25. return true;
  26. }
  27. }
  28. }
  29. }
  30. showMessage({"Failed to load state ", slot});
  31. return false;
  32. }