Skip to content

Commit

Permalink
Launcher: Disable certain things when there's no external RAM
Browse files Browse the repository at this point in the history
- Disable CRC caching
- Disable background images
- Disable previews

Many of those things already failed, this makes it more explicit. And it prevents wasting memory that's necessary for other basic operations.

I think all images should be disabled, really, but a text fallback must be added first...
  • Loading branch information
ducalex committed Nov 3, 2024
1 parent 998ca66 commit 0317235
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 14 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ You can configure automatic SRAM saving in the options menu. A longer delay will
of losing data when powering down too quickly. Also note that when *resuming* a game, Retro-Go will give priority
to a save state if present.

### ZIP files
Most Retro-Go applications now support ZIP files. ZIP archives should contain only one ROM file and nothing else. ZIP support also depends on available memory and larger ROMs may fail to load on some devices unfortunately.


# Development
If you wish to build or modify Retro-Go, you can find help in the following documents:
Expand Down
15 changes: 8 additions & 7 deletions components/retro-go/rg_system.c
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ rg_app_t *rg_system_init(int sampleRate, const rg_handlers_t *handlers, const rg
.frameskip = 1,
.overclock = 0,
.tickTimeout = 3000000,
.availableMemory = 0,
.lowMemoryMode = false,
.enWatchdog = true,
.isColdBoot = true,
.isLauncher = false,
Expand Down Expand Up @@ -440,6 +440,9 @@ rg_app_t *rg_system_init(int sampleRate, const rg_handlers_t *handlers, const rg
memset(&panicTrace, 0, sizeof(panicTrace));
panicTraceCleared = true;

update_memory_statistics();
app.lowMemoryMode = statistics.totalMemoryExt == 0;

rg_settings_init();
app.configNs = rg_settings_get_string(NS_BOOT, SETTING_BOOT_NAME, app.name);
app.bootArgs = rg_settings_get_string(NS_BOOT, SETTING_BOOT_ARGS, "");
Expand Down Expand Up @@ -467,13 +470,8 @@ rg_app_t *rg_system_init(int sampleRate, const rg_handlers_t *handlers, const rg
profile->lock = rg_mutex_create();
#endif

update_memory_statistics();
RG_LOGI("Available memory: %d/%d + %d/%d", statistics.freeMemoryInt / 1024, statistics.totalMemoryInt / 1024,
statistics.freeMemoryExt / 1024, statistics.totalMemoryExt / 1024);
app.availableMemory = statistics.freeMemoryInt + statistics.freeMemoryExt;

#ifdef ESP_PLATFORM
if (statistics.totalMemoryExt == 0)
if (app.lowMemoryMode)
rg_gui_alert("External memory not detected", "Boot will continue but it will surely crash...");

if (app.bootFlags & RG_BOOT_ONCE)
Expand All @@ -484,6 +482,9 @@ rg_app_t *rg_system_init(int sampleRate, const rg_handlers_t *handlers, const rg
rg_task_create("rg_sysmon", &system_monitor_task, NULL, 3 * 1024, RG_TASK_PRIORITY_5, -1);
app.initialized = true;

update_memory_statistics();
RG_LOGI("Available memory: %d/%d + %d/%d", statistics.freeMemoryInt / 1024, statistics.totalMemoryInt / 1024,
statistics.freeMemoryExt / 1024, statistics.totalMemoryExt / 1024);
RG_LOGI("Retro-Go ready.\n\n");

return &app;
Expand Down
2 changes: 1 addition & 1 deletion components/retro-go/rg_system.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ typedef struct
int frameskip;
int overclock;
int tickTimeout;
int availableMemory;
bool lowMemoryMode;
bool enWatchdog;
bool isColdBoot;
bool isLauncher;
Expand Down
10 changes: 5 additions & 5 deletions launcher/main/applications.c
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,6 @@ static void application(const char *desc, const char *name, const char *exts, co

void applications_init(void)
{
bool big_memory = rg_system_get_app()->availableMemory >= 0x600000;
application("Nintendo Entertainment System", "nes", "nes fc fds nsf zip", "retro-core", 16);
application("Super Nintendo", "snes", "smc sfc zip", "retro-core", 0);
application("Nintendo Gameboy", "gb", "gb gbc zip", "retro-core", 0);
Expand All @@ -697,13 +696,14 @@ void applications_init(void)
application("Coleco ColecoVision", "col", "col rom zip", "retro-core", 0);
application("NEC PC Engine", "pce", "pce zip", "retro-core", 0);
application("Atari Lynx", "lnx", "lnx zip", "retro-core", 64);
// application("Atari 2600", "a26", "a26", "stella-go", 0);
// application("Neo Geo Pocket Color", "ngp", "ngp ngc", "ngpocket-go", 0);
application("DOOM", "doom", big_memory ? "wad zip" : "wad", "prboom-go", 0);
// application("Atari 2600", "a26", "a26 zip", "stella-go", 0);
// application("Neo Geo Pocket Color", "ngp", "ngp ngc zip", "ngpocket-go", 0);
application("DOOM", "doom", "wad zip", "prboom-go", 0);
application("MSX", "msx", "rom mx1 mx2 dsk", "fmsx", 0);

// Special app to bootstrap native esp32 binaries from the SD card
// application("Bootstrap", "apps", "bin elf", "bootstrap", 0);

crc_cache_init();
if (!rg_system_get_app()->lowMemoryMode)
crc_cache_init();
}
12 changes: 11 additions & 1 deletion launcher/main/gui.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ void gui_init(bool cold_boot)
};
// Auto: Show carousel on cold boot, browser on warm boot (after cleanly exiting an emulator)
gui.browse = gui.start_screen == START_SCREEN_BROWSER || (gui.start_screen == START_SCREEN_AUTO && !cold_boot);
gui.http_lock = false;
gui.low_memory_mode = rg_system_get_app()->lowMemoryMode;
gui.surface = rg_surface_create(gui.width, gui.height, RG_PIXEL_565_LE, MEM_SLOW);
gui_update_theme();
}
Expand Down Expand Up @@ -375,6 +377,14 @@ void gui_redraw(void)

void gui_draw_background(tab_t *tab, int shade)
{
// In low memory mode we can't fit an entire background in memory, flood a single color instead
// FIXME: The color should be themable...
if (gui.low_memory_mode)
{
rg_gui_draw_rect(0, 0, gui.width, gui.height, 0, C_BLACK, C_BLACK);
return;
}

// We can't losslessly change shade, must reload!
if (tab->background && tab->background_shade > 0 && tab->background_shade != shade)
{
Expand Down Expand Up @@ -511,7 +521,7 @@ void gui_load_preview(tab_t *tab)

gui_set_preview(tab, NULL);

if (!item || !item->arg)
if (!item || !item->arg || gui.low_memory_mode)
return;

switch (gui.show_preview)
Expand Down
1 change: 1 addition & 0 deletions launcher/main/gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ typedef struct {
uint32_t idle_counter;
uint32_t joystick;
bool http_lock; // FIXME: should be a mutex...
bool low_memory_mode;
rg_surface_t *surface;
} retro_gui_t;

Expand Down

0 comments on commit 0317235

Please sign in to comment.