Skip to content

Commit

Permalink
Config: Drop interactive menu, and add option to halve canvas res
Browse files Browse the repository at this point in the history
Some games for Nokia N80 actually run at 176x208 and are then scaled
to the phone's native 352x416 screen res. The same happens with
some Nokia 5800 XpressMusic games such as Harry Potter and the Deathly
Hallows, where the game itself renders at 180x320, and then scales
to the phones actual 360x640 screen. Since screen resolutions should
mirror phones and not game shenanigans, i think making this a
toggle instead of adding two new resolutions makes more sense.

At least until FreeJ2ME gets a comprehensive function to automatically
scale these without user intervention.

Working on Libretro as well, as for SDL, this one still needs a UI
overhaul, so it'd be a waste of time to keep tacking things onto
it right now. Although the removal of the config menu makes it
impossible to configure anything during runtime there.
  • Loading branch information
AShiningRay committed Sep 28, 2024
1 parent ab8369b commit 4f6d1ac
Show file tree
Hide file tree
Showing 7 changed files with 161 additions and 402 deletions.
50 changes: 31 additions & 19 deletions src/libretro/freej2me_libretro.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ char *outPath; /* Actual path of FreeJ2ME's jar to start */
char** params; /* Char matrix containing launch arguments */
unsigned int optstrlen; /* length of the string above */
unsigned long int screenRes[2]; /* {width, height} */
int rotateScreen; /* acts as a boolean */
int halveCanvasRes; /* acts as a boolean */
int rotateScreen; /* also acts as a boolean */
int phoneType; /* 0=standard, 1=nokia, 2=siemens, 3=motorola, 4=sonyEricsson */
int gameFPS; /* Auto(0), 60, 30, 15 */
int soundEnabled; /* also acts as a boolean */
Expand Down Expand Up @@ -303,6 +304,14 @@ static void check_variables(bool first_time_startup)
}


var.key = "freej2me_halvecanvasres";
if (Environ(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
{
if (!strcmp(var.value, "off")) { halveCanvasRes = 0; }
else if (!strcmp(var.value, "on")) { halveCanvasRes = 1; }
}


var.key = "freej2me_rotate";
if (Environ(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
{
Expand Down Expand Up @@ -449,7 +458,7 @@ static void check_variables(bool first_time_startup)
/* Prepare a string to pass those core options to the Java app */
options_update = malloc(sizeof(char) * PIPE_MAX_LEN);

snprintf(options_update, PIPE_MAX_LEN, "FJ2ME_LR_OPTS:|%lux%lu|%d|%d|%d|%d|%d|%d|%d", screenRes[0], screenRes[1], rotateScreen, phoneType, gameFPS, soundEnabled, customMidi, maxMidiPlayers, dumpAudioStreams);
snprintf(options_update, PIPE_MAX_LEN, "FJ2ME_LR_OPTS:|%lux%lu|%d|%d|%d|%d|%d|%d|%d|%d", screenRes[0], screenRes[1], halveCanvasRes, rotateScreen, phoneType, gameFPS, soundEnabled, customMidi, maxMidiPlayers, dumpAudioStreams);
optstrlen = strlen(options_update);

/* 0xD = 13, which is the special case where the java app will receive the updated configs */
Expand Down Expand Up @@ -508,9 +517,10 @@ void retro_init(void)
*/
check_variables(true);

char resArg[2][4], rotateArg[2], phoneArg[2], fpsArg[3], soundArg[2], midiArg[2], maxMidiArg[3], dumpAudioArg[2];
char resArg[2][4], halveCanvas[2], rotateArg[2], phoneArg[2], fpsArg[3], soundArg[2], midiArg[2], maxMidiArg[3], dumpAudioArg[2];
sprintf(resArg[0], "%lu", screenRes[0]); /* Libretro config Width */
sprintf(resArg[1], "%lu", screenRes[1]); /* Libretro config Height */
sprintf(halveCanvas, "%d", halveCanvasRes);
sprintf(rotateArg, "%d", rotateScreen);
sprintf(phoneArg, "%d", phoneType);
sprintf(fpsArg, "%d", gameFPS);
Expand All @@ -536,17 +546,18 @@ void retro_init(void)
params[2] = strdup(outPath);
params[3] = strdup(resArg[0]);
params[4] = strdup(resArg[1]);
params[5] = strdup(rotateArg);
params[6] = strdup(phoneArg);
params[7] = strdup(fpsArg);
params[8] = strdup(soundArg);
params[9] = strdup(midiArg);
params[10] = strdup(maxMidiArg);
params[11] = strdup(dumpAudioArg);
params[12] = NULL; // Null-terminate the array

log_fn(RETRO_LOG_INFO, "Passing params: %s | %s | %s | %s | %s | %s | %s | %s | %s\n", *(params+3),
*(params+4), *(params+5), *(params+6), *(params+7), *(params+8), *(params+9), *(params+10), *(params+11));
params[5] = strdup(halveCanvas);
params[6] = strdup(rotateArg);
params[7] = strdup(phoneArg);
params[8] = strdup(fpsArg);
params[9] = strdup(soundArg);
params[10] = strdup(midiArg);
params[11] = strdup(maxMidiArg);
params[12] = strdup(dumpAudioArg);
params[13] = NULL; // Null-terminate the array

log_fn(RETRO_LOG_INFO, "Passing params: %s | %s | %s | %s | %s | %s | %s | %s | %s | %s\n", *(params+3),
*(params+4), *(params+5), *(params+6), *(params+7), *(params+8), *(params+9), *(params+10), *(params+11), *(params+12));
}

log_fn(RETRO_LOG_INFO, "Preparing to open FreeJ2ME-Plus' Java app (make sure freej2me-lr.jar is inside system/).\n");
Expand Down Expand Up @@ -1042,8 +1053,8 @@ pid_t javaOpen(char *cmd, char **params)
log_fn(RETRO_LOG_INFO, "Setting up java app's process and pipes...\n");

log_fn(RETRO_LOG_INFO, "Opening: %s %s %s ...\n", *(params+0), *(params+1), *(params+2));
log_fn(RETRO_LOG_INFO, "Params: %s | %s | %s | %s | %s | %s | %s | %s | %s\n", *(params+3),
*(params+4), *(params+5), *(params+6), *(params+7), *(params+8), *(params+9), *(params+10), *(params+11));
log_fn(RETRO_LOG_INFO, "Params: %s | %s | %s | %s | %s | %s | %s | %s | %s | %s\n", *(params+3),
*(params+4), *(params+5), *(params+6), *(params+7), *(params+8), *(params+9), *(params+10), *(params+11), *(params+12));
}
else { log_fn(RETRO_LOG_INFO, "\n\nRESTARTING!!!\n\n"); restarting = false; }

Expand Down Expand Up @@ -1102,6 +1113,7 @@ bool isRunning(pid_t pid)
if(waitpid(pid, &status, WNOHANG) == 0) { return true; }

log_fn(RETRO_LOG_INFO, "Java app is not running anymore! Last known PID=%d \n", pid);
exit(0);
return false;
}
#elif _WIN32
Expand Down Expand Up @@ -1171,7 +1183,7 @@ void javaOpen(char *cmd, char **params)
sprintf(cmdWin, "javaw -jar %s", cmd);

log_fn(RETRO_LOG_INFO, "Opening: %s \n", cmd);
for (int i = 3; i <= 11; i++) /* There are 10 cmd arguments for now */
for (int i = 3; i <= 12; i++) /* There are 10 cmd arguments for now */
{
//log_fn(RETRO_LOG_INFO, "Processing arg %d: %s \n", i, *(params+i));
sprintf(cmdWin, "%s %s", cmdWin, *(params+i));
Expand All @@ -1184,8 +1196,8 @@ void javaOpen(char *cmd, char **params)
log_fn(RETRO_LOG_INFO, "Setting up java app's process and pipes...\n");

log_fn(RETRO_LOG_INFO, "Opening: %s %s %s ...\n", *(params+0), *(params+1), *(params+2));
log_fn(RETRO_LOG_INFO, "Params: %s | %s | %s | %s | %s | %s | %s | %s | %s\n", *(params+3),
*(params+4), *(params+5), *(params+6), *(params+7), *(params+8), *(params+9), *(params+10), *(params+11));
log_fn(RETRO_LOG_INFO, "Params: %s | %s | %s | %s | %s | %s | %s | %s | %s | %s\n", *(params+3),
*(params+4), *(params+5), *(params+6), *(params+7), *(params+8), *(params+9), *(params+10), *(params+11), *(params+12));
}
else { log_fn(RETRO_LOG_INFO, "\n\nRESTARTING!!!\n\n"); restarting = false; }

Expand Down
29 changes: 29 additions & 0 deletions src/libretro/freej2me_libretro.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,20 @@ struct retro_core_option_v2_definition core_options[] =
},
"240x320"
},
{
"freej2me_halvecanvasres",
"Virtual Phone Settings > Halve Canvas Res",
"Halve Canvas Res",
"While the 'Phone Resolution' setting follows device screen resolution, some games do, in fact, render at a lower resolution and then upscale to the phone's native res by a factor of 2. A few 352x416 Nokia N80 games do this, as well as Harry Potter and the Deathly Hallows for the Nokia N5800 XpressMusic (360x640). Enabling this will make those games fill the whole screen.",
"While the 'Phone Resolution' setting follows device screen resolution, some games do, in fact, render at a lower resolution and then upscale to the phone's native res by a factor of 2. A few 352x416 Nokia N80 games do this, as well as Harry Potter and the Deathly Hallows for the Nokia N5800 XpressMusic (360x640). Enabling this will make those games fill the whole screen.",
"vphone_settings",
{
{ "off", "Disabled" },
{ "on", "Enabled" },
{ NULL, NULL },
},
"off"
},
{
"freej2me_rotate",
"Virtual Phone Settings > Rotate Screen",
Expand Down Expand Up @@ -375,6 +389,17 @@ struct retro_core_option_definition core_options_v1 [] =
},
"240x320"
},
{
"freej2me_halvecanvasres",
"Halve Canvas Res",
"While the 'Phone Resolution' setting follows device screen resolution, some games do, in fact, render at a lower resolution and then upscale to the phone's native res by a factor of 2. A few 352x416 Nokia N80 games do this, as well as Harry Potter and the Deathly Hallows for the Nokia N5800 XpressMusic (360x640). Enabling this will make those games fill the whole screen.",
{
{ "off", "Disabled" },
{ "on", "Enabled" },
{ NULL, NULL },
},
"off"
},
{
"freej2me_rotate",
"Rotate Screen",
Expand Down Expand Up @@ -566,6 +591,10 @@ static const struct retro_variable vars[] =
"freej2me_resolution",
"Phone Resolution (Core Restart required); 240x320|96x65|101x64|101x80|128x128|130x130|128x142|128x160|132x176|176x204|176x208|176x220|220x176|208x208|208x320|320x240|240x400|240x432|240x480|352x416|360x640|640x360|640x480|480x800|800x480"
},
{ /* Screen Rotation */
"freej2me_halvecanvasres",
"Halve Canvas Res; off|on"
},
{ /* Screen Rotation */
"freej2me_rotate",
"Rotate Screen; off|on"
Expand Down
12 changes: 12 additions & 0 deletions src/org/recompile/freej2me/AWTGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ public final class AWTGUI
final CheckboxMenuItem enableAudio = new CheckboxMenuItem("Enable Audio", false);
final CheckboxMenuItem enableRotation = new CheckboxMenuItem("Rotate Screen", false);
final CheckboxMenuItem useCustomMidi = new CheckboxMenuItem("Use custom midi soundfont", false);
final CheckboxMenuItem halveCanvasRes = new CheckboxMenuItem("Halve Canvas Resolution", false);

final CheckboxMenuItem stdLayout = new CheckboxMenuItem("Standard", true);
final CheckboxMenuItem nokiaLayout = new CheckboxMenuItem("Nokia", false);
Expand Down Expand Up @@ -399,6 +400,15 @@ public void itemStateChanged(ItemEvent e)
}
});

halveCanvasRes.addItemListener(new ItemListener()
{
public void itemStateChanged(ItemEvent e)
{
if(halveCanvasRes.getState()){ config.updateCanvasScale("on"); hasPendingChange = true; }
else{ config.updateCanvasScale("off"); hasPendingChange = true; }
}
});

midiStreams[0].addItemListener(new ItemListener()
{
public void itemStateChanged(ItemEvent e)
Expand Down Expand Up @@ -798,6 +808,7 @@ private void buildMenuBar()
optionMenu.add(enableRotation);
optionMenu.add(useCustomMidi);
optionMenu.add(resChangeMenuItem);
optionMenu.add(halveCanvasRes);
optionMenu.add(phoneType);
optionMenu.add(fpsCap);
optionMenu.add(midiStreamNum);
Expand Down Expand Up @@ -832,6 +843,7 @@ public void updateOptions()
enableAudio.setState(config.settings.get("sound").equals("on"));
enableRotation.setState(config.settings.get("rotate").equals("on"));
useCustomMidi.setState(config.settings.get("soundfont").equals("Custom"));
halveCanvasRes.setState(config.settings.get("halveCanvasRes").equals("on"));
fpsCapNone.setState(config.settings.get("fps").equals("0"));
fpsCap15.setState(config.settings.get("fps").equals("15"));
fpsCap30.setState(config.settings.get("fps").equals("30"));
Expand Down
24 changes: 7 additions & 17 deletions src/org/recompile/freej2me/Anbu.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,7 @@ public void run()
int[] data;

// Send Frame to SDL interface
if(!config.isRunning) { data = Mobile.getPlatform().getLCD().getRGB(0, 0, lcdWidth, lcdHeight, null, 0, lcdWidth); }
else { data = config.getLCD().getRGB(0, 0, lcdWidth, lcdHeight, null, 0, lcdWidth);}
data = Mobile.getPlatform().getLCD().getRGB(0, 0, lcdWidth, lcdHeight, null, 0, lcdWidth);
byte[] frame = new byte[data.length * 3];
int cb = 0;

Expand Down Expand Up @@ -299,31 +298,22 @@ public void run()
private void keyDown(int key)
{
int mobikeyN = (key + 64) & 0x7F; //Normalized value for indexing the pressedKeys array
if(config.isRunning)
if (pressedKeys[mobikeyN] == false)
{
config.keyPressed(key);
Mobile.getPlatform().keyPressed(key);
}
else
{
if (pressedKeys[mobikeyN] == false)
{
Mobile.getPlatform().keyPressed(key);
}
else
{
Mobile.getPlatform().keyRepeated(key);
}
Mobile.getPlatform().keyRepeated(key);
}
pressedKeys[mobikeyN] = true;
}

private void keyUp(int key)
{
int mobikeyN = (key + 64) & 0x7F; //Normalized value for indexing the pressedKeys array
if(!config.isRunning)
{
Mobile.getPlatform().keyReleased(key);
}

Mobile.getPlatform().keyReleased(key);
pressedKeys[mobikeyN] = false;
}

Expand Down Expand Up @@ -395,7 +385,7 @@ else if(useMotorolaControls)

//if(keycode == 0x0F) return Mobile.GAME_C; // Screenshot, shouldn't really be used here

if(keycode == 0x1B) { config.start(); } // ESC, special key to bring up the config menu
//if(keycode == 0x1B) { config.start(); } // ESC, special key to bring up the config menu

return 0;
}
Expand Down
Loading

0 comments on commit 4f6d1ac

Please sign in to comment.