Skip to content

Commit

Permalink
Added savestate autoload/autosave feature
Browse files Browse the repository at this point in the history
  • Loading branch information
hi-ban committed Jul 31, 2021
1 parent 05cc148 commit 45b9ea7
Show file tree
Hide file tree
Showing 6 changed files with 231 additions and 61 deletions.
20 changes: 15 additions & 5 deletions dist/manual.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,11 @@ saving states.
The default slot is always Slot 0.

The default slot will always be selected when
starting the emulator. Selected savestate slot
will not be saved on emulator exit.
starting the emulator. The slot selection will
not be saved on emulator exit.

The default slot will be used by the savestate
autosave/autoload feature when enabled.


Emulator Options
Expand Down Expand Up @@ -74,9 +77,15 @@ Here is a list of the available config options:
with the same name as the ROM file, and it
will load the default border if it fails.

- System:
Allows to select the system priority when
- System Priority:
Allows to select the system to use when
a ROM supports both DMG and GBC modes.
Default is "GBC".

- Savestates:
Allows to set savestate related options,
like autoload on game boot and autosave
on game exit.

- Boot Logos:
Allows to use GB/GBC BIOS files to display
Expand All @@ -88,7 +97,8 @@ Here is a list of the available config options:
Default is "DMG only".

- Controls:
Allows the user to tune the controls.
Allows the user to tune the control related
settings.

- Sound:
Allows the user to select between Mono and
Expand Down
2 changes: 1 addition & 1 deletion gambatte_sdl/builddate.h
Original file line number Diff line number Diff line change
@@ -1 +1 @@
#define BUILDDATE "20210421-010751"
#define BUILDDATE "20210731-123313"
66 changes: 65 additions & 1 deletion gambatte_sdl/libmenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Mix_Chunk *menusound_move = NULL;
Mix_Chunk *menusound_ok = NULL;

// Default config values
int showfps = 0, ghosting = 1, biosenabled = 0, colorfilter = 0, gameiscgb = 0, buttonlayout = 0, stereosound = 1, prefercgb = 0, ffwhotkey = 1;
int showfps = 0, ghosting = 1, biosenabled = 0, colorfilter = 0, gameiscgb = 0, buttonlayout = 0, stereosound = 1, prefercgb = 1, ffwhotkey = 1, stateautoload = 0, stateautosave = 0;
uint32_t menupalblack = 0x000000, menupaldark = 0x505450, menupallight = 0xA8A8A8, menupalwhite = 0xF8FCF8;
int filtervalue[12] = {135, 20, 0, 25, 0, 125, 20, 25, 0, 20, 105, 30};
std::string selectedscaler= "No Scaling", dmgbordername = "DEFAULT", gbcbordername = "DEFAULT", palname = "DEFAULT", filtername = "NONE", currgamename = "default";
Expand Down Expand Up @@ -441,6 +441,60 @@ int textanim_reset(){
return 0;
}

void stateload_dms(int saveslot) {
gambatte_p->selectState_NoOsd(saveslot);
char overlaytext[20];
if(gambatte_p->loadState_NoOsd()){
can_reset = 1;//allow user to reset or save state once a savestate is loaded
sprintf(overlaytext, "State %d loaded", gambatte_p->currentState());
printOverlay(overlaytext);//print overlay text
} else {
sprintf(overlaytext, "State %d empty", gambatte_p->currentState());
printOverlay(overlaytext);//print overlay text
}
}

void statesave_dms(int saveslot) {
gambatte_p->selectState_NoOsd(saveslot);
if(can_reset == 1){//boot logo already ended, can save state safely
if(gameiscgb == 0){ //set palette to greyscale
Uint32 value;
for (int i = 0; i < 3; ++i) {
for (int k = 0; k < 4; ++k) {
if(k == 0)
value = 0xF8FCF8;
if(k == 1)
value = 0xA8A8A8;
if(k == 2)
value = 0x505450;
if(k == 3)
value = 0x000000;
gambatte_p->setDmgPaletteColor(i, k, value);
}
}
} else { // disable color filter
gambatte_p->setColorFilter(0, filtervalue);
}
//run the emulator for 1 frame, so the screen buffer is updated without color palettes
std::size_t fakesamples = 35112;
Array<Uint32> const fakeBuf(35112 + 2064);
gambatte_p->runFor(blitter_p->inBuf().pixels, blitter_p->inBuf().pitch, fakeBuf, fakesamples);
//save state. the snapshot will now be in greyscale
gambatte_p->saveState_NoOsd(blitter_p->inBuf().pixels, blitter_p->inBuf().pitch);
if(gameiscgb == 0){
loadPalette(palname); //restore palette
} else {
loadFilter(filtername); //restore color filter
}

char overlaytext[14];
sprintf(overlaytext, "State %d saved", gambatte_p->currentState());
printOverlay(overlaytext);//print overlay text
} else if (can_reset == 0){//boot logo is still running, can't save state
printOverlay("Unable to save");//print overlay text
}
}

int menu_main(menu_t *menu) {
SDL_Event event;
int dirty, loop, i;
Expand Down Expand Up @@ -2208,6 +2262,8 @@ void saveConfig(int pergame){
"DMGBORDERNAME %s\n"
"GBCBORDERNAME %s\n"
"PREFERCGB %d\n"
"STATEAUTOLOAD %d\n"
"STATEAUTOSAVE %d\n"
"BIOSENABLED %d\n"
"GHOSTING %d\n"
"BUTTONLAYOUT %d\n"
Expand All @@ -2220,6 +2276,8 @@ void saveConfig(int pergame){
dmgbordername.c_str(),
gbcbordername.c_str(),
prefercgb,
stateautoload,
stateautosave,
biosenabled,
ghosting,
buttonlayout,
Expand Down Expand Up @@ -2324,6 +2382,12 @@ void loadConfig(){
} else if (!strcmp(line, "PREFERCGB")) {
sscanf(arg, "%d", &value);
prefercgb = value;
} else if (!strcmp(line, "STATEAUTOLOAD")) {
sscanf(arg, "%d", &value);
stateautoload = value;
} else if (!strcmp(line, "STATEAUTOSAVE")) {
sscanf(arg, "%d", &value);
stateautosave = value;
} else if (!strcmp(line, "BIOSENABLED")) {
sscanf(arg, "%d", &value);
biosenabled = value;
Expand Down
5 changes: 4 additions & 1 deletion gambatte_sdl/libmenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ extern SDL_Surface *menuscreen;
extern SDL_Surface *surface_menuinout;
extern SDL_Surface *textoverlay;
extern SDL_Surface *textoverlaycolored;
extern int showfps, ghosting, biosenabled, colorfilter, gameiscgb, buttonlayout, stereosound, prefercgb, ffwhotkey;
extern int showfps, ghosting, biosenabled, colorfilter, gameiscgb, buttonlayout, stereosound, prefercgb, ffwhotkey, stateautoload, stateautosave;
extern uint32_t menupalblack, menupaldark, menupallight, menupalwhite;
extern int filtervalue[12];
extern std::string selectedscaler, dmgbordername, gbcbordername, palname, filtername, currgamename, homedir, ipuscaling;
Expand Down Expand Up @@ -185,6 +185,9 @@ void apply_cfilter(SDL_Surface *surface);
void printOverlay(const char *text);
void clearAllCheats();

void stateload_dms(int saveslot);
void statesave_dms(int saveslot);

#ifdef MIYOO_BATTERY_WARNING
void checkBatt();
#endif
Expand Down
Loading

0 comments on commit 45b9ea7

Please sign in to comment.