file based save states, and improved file structure
This commit is contained in:
19
lib/cart.c
19
lib/cart.c
@ -1,6 +1,7 @@
|
||||
#include <cart.h>
|
||||
#include <common.h>
|
||||
#include <string.h>
|
||||
#include <windows.h>
|
||||
|
||||
static cart_context ctx;
|
||||
|
||||
@ -372,8 +373,11 @@ void cart_write(u16 address, u8 value){
|
||||
}
|
||||
|
||||
bool cart_battery_load(){
|
||||
char *filename = strrchr(ctx.filename, '\\');
|
||||
filename++;
|
||||
char fn[1048];
|
||||
sprintf(fn, "%s.battery", ctx.filename);
|
||||
char *profile = getenv("USERPROFILE");
|
||||
sprintf(fn, "%s/Documents/gbemu/saves/%s.battery", profile, filename);
|
||||
FILE *fp = fopen(fn, "rb");
|
||||
|
||||
if(!fp) {
|
||||
@ -386,8 +390,11 @@ bool cart_battery_load(){
|
||||
}
|
||||
|
||||
bool cart_battery_save(){
|
||||
char *filename = strrchr(ctx.filename, '\\');
|
||||
filename++;
|
||||
char fn[1048];
|
||||
sprintf(fn, "%s.battery", ctx.filename);
|
||||
char *profile = getenv("USERPROFILE");
|
||||
sprintf(fn, "%s/Documents/gbemu/saves/%s.battery", profile, filename);
|
||||
FILE *fp = fopen(fn, "wb");
|
||||
|
||||
if(!fp) {
|
||||
@ -432,6 +439,10 @@ void cart_load_state(const cart_state* state){
|
||||
ctx.ram_bank = ctx.ram_banks[0];
|
||||
}
|
||||
|
||||
if(ctx.battery) {
|
||||
cart_battery_load();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void cart_save_state(cart_state* state){
|
||||
@ -448,4 +459,8 @@ void cart_save_state(cart_state* state){
|
||||
memcpy((&state->ram_banks[i]), ctx.ram_banks[i], 0x2000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cart_context *cart_get_context(){
|
||||
return &ctx;
|
||||
}
|
Reference in New Issue
Block a user