linux compat

This commit is contained in:
2025-06-13 15:33:13 -06:00
parent 84952c134c
commit 800dcb2706
7 changed files with 74 additions and 19 deletions

View File

@ -287,6 +287,7 @@ bool cart_load(char *cart) {
if(ctx.battery) {
cart_battery_load();
}
return true;
}
@ -493,11 +494,21 @@ void cart_write(u16 address, u8 value){
}
bool cart_battery_load(){
#ifdef __windows__
char *filename = strrchr(ctx.filename, '\\');
#else
char *filename = strrchr(ctx.filename, '/');
#endif
filename++;
char fn[1048];
#ifdef __windows__
char *profile = getenv("USERPROFILE");
sprintf(fn, "%s/Documents/gbemu/saves/%s.battery", profile, filename);
#else
char *profile = getenv("HOME");
sprintf(fn, "%s/.config/gbemu/saves/%s.battery", profile, filename);
#endif
printf("loading %s\n", fn);
FILE *fp = fopen(fn, "rb");
if(!fp) {
@ -510,11 +521,20 @@ bool cart_battery_load(){
}
bool cart_battery_save(){
#ifdef __windows__
char *filename = strrchr(ctx.filename, '\\');
#else
char *filename = strrchr(ctx.filename, '/');
#endif
filename++;
char fn[1048];
#ifdef __windows__
char *profile = getenv("USERPROFILE");
sprintf(fn, "%s/Documents/gbemu/saves/%s.battery", profile, filename);
#else
char *profile = getenv("HOME");
sprintf(fn, "%s/.config/gbemu/saves/%s.battery", profile, filename);
#endif
FILE *fp = fopen(fn, "wb");
if(!fp) {