Advertisement
Guest User

Untitled

a guest
Sep 4th, 2015
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. /* WARNING: this is only an idea of how save states could be implemented
  2. in libretro, I didn't even tried to compile this code :)
  3. */
  4.  
  5. size_t retro_serialize_size(void)
  6. {
  7. /* You can ask the real size and pray that it doesn't change afterward... */
  8. size_t size;
  9.  
  10. YabSaveStateBuffer(NULL, &size);
  11.  
  12. return size;
  13.  
  14. /* Or you can try some "safe" value */
  15.  
  16. return 5000000;
  17. }
  18.  
  19. bool retro_serialize(void *data, size_t size)
  20. {
  21. void * buffer;
  22. size_t bufsize;
  23. int status;
  24.  
  25. status = YabSaveStateBuffer(&buffer, &bufsize);
  26. if (status != 0) return false;
  27.  
  28. if (bufsize > size)
  29. {
  30. free(buffer);
  31. return false;
  32. }
  33.  
  34. /* yeah... that means we don't fill the whole data area
  35. and there will be trailing random data */
  36. memcpy(data, buffer, bufsize);
  37. free(buffer);
  38.  
  39. return true;
  40. }
  41.  
  42. bool retro_unserialize(const void *data, size_t size)
  43. {
  44. /* again, size may be different from what yabause needs.
  45. If it's smaller, loading will fail.
  46. If it's larger, random data at the end is ignored */
  47. int status = YabLoadStateBuffer(data, size);
  48.  
  49. return status == 0;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement