Skip to content

Commit

Permalink
Various changes (2)
Browse files Browse the repository at this point in the history
- Added scripts for building a multi-system OPK (opendingux/retrofw)
- Now the app autodetects if the OS supports IPU scaling and displays
the appropiate scaling options if applicable.
- Added support for per-game settings.
- Unified some redundant functions in the menu code.
- Added support for the PG2 dedicated menu button.
  • Loading branch information
hi-ban committed Jan 14, 2020
1 parent 0ce2400 commit b60d00c
Show file tree
Hide file tree
Showing 14 changed files with 478 additions and 314 deletions.
18 changes: 15 additions & 3 deletions build_opendingux.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
#!/bin/sh

BDAT=$(date +"%Y%m%d-%H%M%S")

echo '#define BUILDDATE "'$BDAT'"' >./gambatte_sdl/builddate.h

echo "cd libgambatte && scons"
(cd libgambatte && scons -Q target=opendingux) || exit

echo "cd gambatte_sdl && scons"
(cd gambatte_sdl && scons -Q target=opendingux)
mv gambatte_sdl/gambatte_sdl gambatte_sdl/gambatte.opendingux

rm -f gambatte-opendingux-r572u3-$BDAT.opk

mksquashfs ./dist/gcw0/default.gcw0.desktop ./gambatte_sdl/gambatte_sdl ./dist/gcw0/gambatte.png ./dist/gcw0/manual.txt gambatte-opendingux-r572u3-$BDAT.opk -all-root -no-xattrs -noappend -no-exports
mksquashfs ./dist/gcw0/default.gcw0.desktop ./gambatte_sdl/gambatte.opendingux ./dist/gcw0/gambatte.png ./dist/gcw0/manual.txt gambatte-opendingux-r572u3-$BDAT.opk -all-root -no-xattrs -noappend -no-exports

echo "cd gambatte_sdl && scons -c"
(cd gambatte_sdl && scons -c)
echo "cd libgambatte && scons -c"
(cd libgambatte && scons -c)
echo "rm -f *gambatte*/config.log"
rm -f *gambatte*/config.log
echo "rm -rf *gambatte*/.scon*"
rm -rf *gambatte*/.scon*
find . -type f -iname \*.o -delete
find . -type f -iname gambatte_sdl -delete

find . -type f -iname gambatte.opendingux -delete
13 changes: 11 additions & 2 deletions build_retrofw.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
#!/bin/sh

BDAT=$(date +"%Y%m%d-%H%M%S")

echo '#define BUILDDATE "'$BDAT'"' >./gambatte_sdl/builddate.h

echo "cd libgambatte && scons"
(cd libgambatte && scons -Q target=retrofw) || exit

echo "cd gambatte_sdl && scons"
(cd gambatte_sdl && scons -Q target=retrofw)

Expand All @@ -20,3 +18,14 @@ tar --owner=0 --group=0 -czvf /tmp/.gambatte-ipk/control.tar.gz -C /tmp/.gambatt
tar --owner=0 --group=0 -czvf /tmp/.gambatte-ipk/data.tar.gz -C /tmp/.gambatte-ipk/root/ .
echo 2.0 > /tmp/.gambatte-ipk/debian-binary
ar r gambatte-retrofw-r572u3-$BDAT.ipk /tmp/.gambatte-ipk/control.tar.gz /tmp/.gambatte-ipk/data.tar.gz /tmp/.gambatte-ipk/debian-binary

echo "cd gambatte_sdl && scons -c"
(cd gambatte_sdl && scons -c)
echo "cd libgambatte && scons -c"
(cd libgambatte && scons -c)
echo "rm -f *gambatte*/config.log"
rm -f *gambatte*/config.log
echo "rm -rf *gambatte*/.scon*"
rm -rf *gambatte*/.scon*
find . -type f -iname \*.o -delete
find . -type f -iname gambatte_sdl -delete
3 changes: 0 additions & 3 deletions clean.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
#!/bin/sh

echo "cd gambatte_qt && make distclean"
(cd gambatte_qt && make distclean)

echo "cd gambatte_sdl && scons -c"
(cd gambatte_sdl && scons -c)

Expand Down
4 changes: 2 additions & 2 deletions dist/gcw0/default.gcw0.desktop
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[Desktop Entry]
Name=Gambatte
Comment=Gameboy emulator
Exec=gambatte_sdl %f
Comment=GB/GBC emulator
Exec=gambatte.opendingux %f
Terminal=false
Type=Application
StartupNotify=true
Expand Down
3 changes: 1 addition & 2 deletions gambatte_sdl/SConstruct
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# OPTIONAL DEFINES:
# -DHW_SCALING: Enables hardware scaling (only for systems which support it)
# -DROM_BROWSER: Enables internal rom browser (gb and gbc romdirs are hardcoded for each system)
# -DPOWEROFF: Replaces the "Quit" option with a "Power Off" option.

Expand All @@ -8,7 +7,7 @@ if target == 'opendingux':
include_path = ' -I/opt/gcw0-toolchain/usr/mipsel-gcw0-linux-uclibc/sysroot/usr/include'
bin_path = '/opt/gcw0-toolchain/usr/bin/mipsel-linux-'
sdl_path = '/opt/gcw0-toolchain/usr/mipsel-gcw0-linux-uclibc/sysroot/usr/bin/'
version_defines = ' -DVERSION_OPENDINGUX -DHW_SCALING'
version_defines = ' -DVERSION_OPENDINGUX'
extra_cflags = ''
print "Building Gambatte SDL with OpenDingux toolchain..."
elif target == 'retrofw':
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 "20191124-160457"
#define BUILDDATE "20200111-133838"
81 changes: 59 additions & 22 deletions gambatte_sdl/libmenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@ Mix_Chunk *menusound_ok = NULL;
int selectedscaler = 0, showfps = 0, ghosting = 1, biosenabled = 0, colorfilter = 0, gameiscgb = 0, buttonlayout = 0, stereosound = 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 dmgbordername = "DEFAULT", gbcbordername = "DEFAULT", palname = "DEFAULT", filtername = "NONE", currgamename = "DEFAULT";
std::string dmgbordername = "DEFAULT", gbcbordername = "DEFAULT", palname = "DEFAULT", filtername = "NONE", currgamename = "default";
std::string homedir = getenv("HOME");
std::string ipuscaling = "NONE";
int numcodes_gg = NUM_GG_CODES, numcodes_gs = NUM_GS_CODES, selectedcode = 0, editmode = 0, blink = 0, footer_alt = 0;
int textanim = 0, textanimpos = 0, textanimdirection = 0, textanimtimer = 0, textanimwidth = 0, textanimspeed = 0;
int ggcheats[NUM_GG_CODES *9] = {0};
Expand Down Expand Up @@ -819,6 +820,16 @@ static void display_menu(SDL_Surface *surface, menu_t *menu) {
SFont_WriteCenter(surface, font, (line * font_height), menu->header);
line ++;
SFont_WriteCenter(surface, font, (line * font_height), menu->title);
if((gambatte_p->isLoaded()) && (currgamename != "default") && ((strcmp(menu->title, "Settings") == 0) || (strcmp(menu->title, " Settings ") == 0) || (strcmp(menu->title, " Settings ") == 0))){
std::string tempconfigfile = (homedir + "/.gambatte/settings/");
tempconfigfile += (currgamename + ".cfg");
FILE * cfile;
cfile = fopen(tempconfigfile.c_str(), "r");
if (cfile != NULL) { //if per-game config file exists for the current ROM, draw PG (per-game) marker on settings menu title
fclose(cfile);
SFont_Write(surface, font, 111, 4, ".");
}
}
if(uparrow == 1){
line ++;
SFont_WriteCenter(surface, font, line * font_height, "{"); // up arrow
Expand Down Expand Up @@ -894,12 +905,14 @@ static void display_menu(SDL_Surface *surface, menu_t *menu) {
}
}
#ifdef VERSION_BITTBOY
if((num_selectable == 0) && (menu->n_entries < 4) && (strcmp(menu->title, "Game Genie") == 0)){
if(strcmp(menu->title, " Game Genie ") == 0){
SFont_WriteCenter(surface, font, 17 * font_height, "A-Cancel Apply-TA"); // footer while in "Apply Cheats" confirmation screen
} else if((num_selectable == 0) && (menu->n_entries < 4) && (strcmp(menu->title, "Settings") == 0)){
} else if((strcmp(menu->title, " Settings ") == 0) || (strcmp(menu->title, " Per-Game Settings ") == 0)){
SFont_WriteCenter(surface, font, 17 * font_height, "A-Cancel Save-TA"); // footer while in "Save Settings" confirmation screen
} else if (num_selectable == 0){
SFont_WriteCenter(surface, font, 17 * font_height, "A-Back Back-TA"); // footer while in "About" screen
} else if((strcmp(menu->title, " Settings ") == 0) || (strcmp(menu->title, " Per-Game Settings ") == 0)){
SFont_WriteCenter(surface, font, 17 * font_height, "A-Cancel Delete-TA"); // footer while in "Delete Settings" confirmation screen
} else if(strcmp(menu->title, "Credits") == 0){
SFont_WriteCenter(surface, font, 17 * font_height, "A-Back Back-TA"); // footer while in "Credits" screen
} else {
if((gambatte_p->isLoaded()) || (strcmp(menu->title, "Main Menu") != 0)){
SFont_WriteCenter(surface, font, 17 * font_height, "A-Back Select-TA"); // footer in normal menus
Expand All @@ -908,12 +921,14 @@ static void display_menu(SDL_Surface *surface, menu_t *menu) {
}
}
#else
if((num_selectable == 0) && (menu->n_entries < 4) && (strcmp(menu->title, "Game Genie") == 0)){
if(strcmp(menu->title, " Game Genie ") == 0){
SFont_WriteCenter(surface, font, 17 * font_height, "B-Cancel Apply-A"); // footer while in "Apply Cheats" confirmation screen
} else if((num_selectable == 0) && (menu->n_entries < 4) && (strcmp(menu->title, "Settings") == 0)){
} else if((strcmp(menu->title, " Settings ") == 0) || (strcmp(menu->title, " Per-Game Settings ") == 0)){
SFont_WriteCenter(surface, font, 17 * font_height, "B-Cancel Save-A"); // footer while in "Save Settings" confirmation screen
} else if (num_selectable == 0){
SFont_WriteCenter(surface, font, 17 * font_height, "B-Back Back-A"); // footer while in "About" screen
} else if((strcmp(menu->title, " Settings ") == 0) || (strcmp(menu->title, " Per-Game Settings ") == 0)){
SFont_WriteCenter(surface, font, 17 * font_height, "B-Cancel Delete-A"); // footer while in "Delete Settings" confirmation screen
} else if(strcmp(menu->title, "Credits") == 0){
SFont_WriteCenter(surface, font, 17 * font_height, "B-Back Back-A"); // footer while in "Credits" screen
} else {
if((gambatte_p->isLoaded()) || (strcmp(menu->title, "Main Menu") != 0)){
SFont_WriteCenter(surface, font, 17 * font_height, "B-Back Select-A"); // footer in normal menus
Expand Down Expand Up @@ -1319,13 +1334,11 @@ void createBorderSurface(){
break;
case 5: /* Ayla's fullscreen scaler */
case 6: /* Bilinear fullscreen scaler */
#ifdef HW_SCALING
case 7: /* Hardware 1.25x */
case 8: /* Hardware 1.36x */
case 9: /* Hardware 1.5x */
case 10: /* Hardware 1.66x */
case 11: /* Hardware Fullscreen */
#endif
default:
borderimg = SDL_CreateRGBSurface(SDL_SWSURFACE, 320, 240, 16, 0, 0, 0, 0);
break;
Expand Down Expand Up @@ -1476,7 +1489,6 @@ void paint_border(SDL_Surface *surface){
rect.h = 0;
SDL_BlitSurface(borderimg, &rect, surface, NULL);
break;
#ifdef HW_SCALING
case 7: /* Hardware 1.25x */
rect.x = 32;
rect.y = 24;
Expand Down Expand Up @@ -1512,7 +1524,6 @@ void paint_border(SDL_Surface *surface){
rect.h = 0;
SDL_BlitSurface(borderimg, &rect, surface, NULL);
break;
#endif
default:
rect.x = 0;
rect.y = 0;
Expand Down Expand Up @@ -1995,15 +2006,20 @@ void loadFilter(std::string filterfile){
}
}

void saveConfig(){
std::string configfile = (homedir + "/.gambatte/config.cfg");
void saveConfig(int pergame){
std::string configfile = (homedir + "/.gambatte/settings/");
if (pergame == 0) {
configfile += ("default.cfg");
} else {
configfile += (currgamename + ".cfg");
}
FILE * cfile;
cfile = fopen(configfile.c_str(), "w");
if (cfile == NULL) {
printf("Failed to open config file for writing.\n");
return;
}
fprintf(cfile,
if (fprintf(cfile,
"SHOWFPS %d\n"
"SELECTEDSCALER %d\n"
"PALNAME %s\n"
Expand All @@ -2023,24 +2039,45 @@ void saveConfig(){
biosenabled,
ghosting,
buttonlayout,
stereosound);
stereosound) < 0) {
printf("Failed to save config file.\n");
} else {
printf("Config file successfully saved.\n");
}
fclose(cfile);
}

void deleteConfig(){
std::string configfile = (homedir + "/.gambatte/settings/");
configfile += (currgamename + ".cfg");
if (currgamename != "default"){
if (remove(configfile.c_str()) == 0){
printf("Config file successfully deleted.\n");
} else {
printf("Failed deleting config file.\n");
}
}
}

void loadConfig(){
std::string configfile = (homedir + "/.gambatte/config.cfg");
std::string configfile = (homedir + "/.gambatte/settings/");
configfile += (currgamename + ".cfg");
FILE * cfile;
char line[4096];
cfile = fopen(configfile.c_str(), "r");
if (cfile == NULL) {
printf("Failed to open config file for reading.\n");
return;
printf("Per-Game config not found. Loading default config...\n");
configfile = (homedir + "/.gambatte/settings/default.cfg");
cfile = fopen(configfile.c_str(), "r");
if (cfile == NULL) {
printf("Failed to open config file for reading.\n");
return;
}
}
while (fgets(line, sizeof(line), cfile)) {
char *arg = strchr(line, ' ');
int value;
char charvalue[32];
std::string stringvalue;
char charvalue[64];
if (!arg) {
continue;
}
Expand Down
5 changes: 3 additions & 2 deletions gambatte_sdl/libmenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ extern SDL_Surface *textoverlaycolored;
extern int selectedscaler, showfps, ghosting, biosenabled, colorfilter, gameiscgb, buttonlayout, stereosound;
extern uint32_t menupalblack, menupaldark, menupallight, menupalwhite;
extern int filtervalue[12];
extern std::string dmgbordername, gbcbordername, palname, filtername, currgamename, homedir;
extern std::string dmgbordername, gbcbordername, palname, filtername, currgamename, homedir, ipuscaling;
extern int numcodes_gg, numcodes_gs, selectedcode, editmode;
extern int ggcheats[NUM_GG_CODES*9];
extern int gscheats[NUM_GS_CODES*8];
Expand Down Expand Up @@ -118,7 +118,8 @@ int currentEntryInList(menu_t *menu, std::string text);
void clear_surface(SDL_Surface *surface, Uint32 color);
void loadPalette(std::string palettefile);
void loadFilter(std::string filterfile);
void saveConfig();
void saveConfig(int pergame = 0);
void deleteConfig();
void loadConfig();

void openMenuAudio();
Expand Down
Loading

0 comments on commit b60d00c

Please sign in to comment.