Skip to content

Commit 12277ad

Browse files
committed
rg_system: Renamed rg_emu_get/set_speed to rg_system_get/set_app_speed
1 parent b41e000 commit 12277ad

File tree

6 files changed

+63
-46
lines changed

6 files changed

+63
-46
lines changed

components/retro-go/rg_gui.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -625,16 +625,16 @@ void rg_gui_draw_status_bars(void)
625625
char footer[max_len];
626626

627627
const rg_app_t *app = rg_system_get_app();
628-
rg_stats_t stats = rg_system_get_counters();
628+
rg_stats_t stats = rg_system_get_stats();
629629

630630
if (!app->initialized || app->isLauncher)
631631
return;
632632

633633
snprintf(header, max_len, "SPEED: %d%% (%d %d) / BUSY: %d%%",
634-
(int)round(stats.totalFPS / app->tickRate * 100.f),
635-
(int)round(stats.totalFPS),
634+
(int)roundf(stats.speedPercent),
635+
(int)roundf(stats.totalFPS),
636636
(int)app->frameskip,
637-
(int)round(stats.busyPercent));
637+
(int)roundf(stats.busyPercent));
638638

639639
if (app->romPath && strlen(app->romPath) > max_len - 1)
640640
snprintf(footer, max_len, "...%s", app->romPath + (strlen(app->romPath) - (max_len - 4)));
@@ -1566,9 +1566,9 @@ static rg_gui_event_t speedup_update_cb(rg_gui_option_t *option, rg_gui_event_t
15661566
if (event == RG_DIALOG_PREV || event == RG_DIALOG_NEXT)
15671567
{
15681568
float change = (event == RG_DIALOG_NEXT) ? 0.5f : -0.5f;
1569-
rg_emu_set_speed(rg_emu_get_speed() + change);
1569+
rg_system_set_app_speed(rg_system_get_app_speed() + change);
15701570
}
1571-
sprintf(option->value, "%.1fx", rg_emu_get_speed());
1571+
sprintf(option->value, "%.1fx", rg_system_get_app_speed());
15721572
return RG_DIALOG_VOID;
15731573
}
15741574

@@ -2094,7 +2094,7 @@ void rg_gui_debug_menu(void)
20942094
char screen_res[20], source_res[20], scaled_res[20];
20952095
char stack_hwm[20], heap_free[20], block_free[20];
20962096
char local_time[32], timezone[32], uptime[20];
2097-
char battery_info[25], frame_time[32];
2097+
char battery_info[20], frame_time[20], overclock[20];
20982098
char app_name[32], network_str[64];
20992099

21002100
const rg_gui_option_t options[] = {
@@ -2111,8 +2111,8 @@ void rg_gui_debug_menu(void)
21112111
{0, "Uptime ", uptime, RG_DIALOG_FLAG_NORMAL, NULL},
21122112
{0, "Battery ", battery_info, RG_DIALOG_FLAG_NORMAL, NULL},
21132113
{0, "Blit time ", frame_time, RG_DIALOG_FLAG_NORMAL, NULL},
2114+
{0, "Overclock", overclock, RG_DIALOG_FLAG_NORMAL, NULL},
21142115
RG_DIALOG_SEPARATOR,
2115-
{0, "Overclock", "-", RG_DIALOG_FLAG_NORMAL, &overclock_cb},
21162116
{1, "Reboot to firmware", NULL, RG_DIALOG_FLAG_NORMAL, NULL},
21172117
{2, "Clear cache ", NULL, RG_DIALOG_FLAG_NORMAL, NULL},
21182118
{3, "Save screenshot", NULL, RG_DIALOG_FLAG_NORMAL, NULL},
@@ -2125,7 +2125,7 @@ void rg_gui_debug_menu(void)
21252125

21262126
const rg_display_t *display = rg_display_get_info();
21272127
rg_display_counters_t display_stats = rg_display_get_counters();
2128-
rg_stats_t stats = rg_system_get_counters();
2128+
rg_stats_t stats = rg_system_get_stats();
21292129
time_t now = time(NULL);
21302130

21312131
strftime(local_time, 32, "%F %T", localtime(&now));
@@ -2146,6 +2146,7 @@ void rg_gui_debug_menu(void)
21462146
snprintf(block_free, 20, "%d+%d", stats.freeBlockInt, stats.freeBlockExt);
21472147
snprintf(app_name, 32, "%s", rg_system_get_app()->name);
21482148
snprintf(uptime, 20, "%ds", (int)(rg_system_timer() / 1000000));
2149+
snprintf(overclock, 20, "%d (%dMhz)", rg_system_get_overclock(), rg_system_get_cpu_speed());
21492150

21502151
rg_battery_t battery;
21512152
if (rg_input_read_battery_raw(&battery))

components/retro-go/rg_system.c

Lines changed: 40 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ static RTC_NOINIT_ATTR panic_trace_t panicTrace;
8787
static RTC_NOINIT_ATTR time_t rtcValue;
8888
static bool panicTraceCleared = false;
8989
static bool exitCalled = false;
90+
static int overclockLevel, overclockMhz;
9091
static uint32_t indicators;
9192
static rg_color_t ledColor = -1;
9293
static rg_stats_t statistics;
@@ -209,11 +210,12 @@ static void update_statistics(void)
209210
// Hard to fix this sync issue without a lock, which I don't want to use...
210211
ticks = RG_MAX(ticks, frames);
211212

212-
statistics.busyPercent = busyTime / totalTime * 100.f;
213213
statistics.totalFPS = ticks / totalTimeSecs;
214214
statistics.skippedFPS = (ticks - frames) / totalTimeSecs;
215215
statistics.fullFPS = fullFrames / totalTimeSecs;
216216
statistics.partialFPS = partFrames / totalTimeSecs;
217+
statistics.busyPercent = busyTime / totalTime * 100.f;
218+
statistics.speedPercent = app.tickRate > 0 ? (statistics.totalFPS / app.tickRate * 100.f) : 100.f;
217219
}
218220
statistics.uptime = rg_system_timer() / 1000000;
219221

@@ -276,9 +278,9 @@ static void system_monitor_task(void *arg)
276278

277279
// Auto frameskip
278280
// TODO: Use a rolling average of frameTimes instead of this mess
279-
if (statistics.ticks > app.tickRate * 2)
281+
if (app.tickRate > 0 && statistics.ticks > app.tickRate * 2)
280282
{
281-
float speed = ((float)statistics.totalFPS / app.tickRate) * 100.f / app.speed;
283+
float speed = statistics.speedPercent / app.speed;
282284
// We don't fully go back to 0 frameskip because if we dip below 95% once, we're clearly
283285
// borderline in power and going back to 0 is just asking for stuttering...
284286
if (speed > 99.f && statistics.busyPercent < 85.f && app.frameskip > 1)
@@ -411,8 +413,6 @@ rg_app_t *rg_system_init(int sampleRate, const rg_handlers_t *handlers, void *_u
411413
.tickTimeout = 3000000,
412414
.frameTime = 1000000 / 60,
413415
.frameskip = 1, // This can be overriden on a per-app basis if needed, do not set 0 here!
414-
.overclock_level = 0,
415-
.overclock_mhz = 240,
416416
.lowMemoryMode = false,
417417
.enWatchdog = true,
418418
.isColdBoot = true,
@@ -802,7 +802,7 @@ rg_app_t *rg_system_get_app(void)
802802
return &app;
803803
}
804804

805-
rg_stats_t rg_system_get_counters(void)
805+
rg_stats_t rg_system_get_stats(void)
806806
{
807807
return statistics;
808808
}
@@ -1092,9 +1092,24 @@ int rg_system_get_log_level(void)
10921092
return app.logLevel;
10931093
}
10941094

1095-
int rg_system_get_cpu_speed(void)
1095+
void rg_system_set_app_speed(float speed)
10961096
{
1097-
return app.overclock_mhz;
1097+
float newSpeed = RG_MIN(2.5f, RG_MAX(0.5f, speed));
1098+
if (newSpeed == app.speed)
1099+
return;
1100+
// FIXME: We need to store the actual default frameskip so we can return to it...
1101+
app.frameskip = (newSpeed - 0.5f) * 3;
1102+
app.frameTime = 1000000.f / (app.tickRate * newSpeed);
1103+
app.speed = newSpeed;
1104+
// There's a bug in esp-idf v4.4.8 where many frequencies play at the wrong speed.
1105+
// Still trying to find how to work around that...
1106+
rg_audio_set_sample_rate(app.sampleRate * newSpeed);
1107+
rg_system_event(RG_EVENT_SPEEDUP, NULL);
1108+
}
1109+
1110+
float rg_system_get_app_speed(void)
1111+
{
1112+
return app.speed;
10981113
}
10991114

11001115
void rg_system_set_overclock(int level)
@@ -1157,10 +1172,11 @@ void rg_system_set_overclock(int level)
11571172
if (!original_tickRate)
11581173
original_tickRate = app.tickRate;
11591174
app.tickRate = original_tickRate * (240.f / real_mhz);
1160-
app.overclock_level = level;
1161-
app.overclock_mhz = real_mhz;
11621175
app.frameskip = 1;
11631176

1177+
overclockLevel = level;
1178+
overclockMhz = real_mhz;
1179+
11641180
RG_LOGW("Overclock level %d applied: %dMhz", level, real_mhz);
11651181
#else
11661182
RG_LOGE("Overclock not supported on this platform!");
@@ -1169,7 +1185,19 @@ void rg_system_set_overclock(int level)
11691185

11701186
int rg_system_get_overclock(void)
11711187
{
1172-
return app.overclock_level;
1188+
return overclockLevel;
1189+
}
1190+
1191+
int rg_system_get_cpu_speed(void)
1192+
{
1193+
if (overclockMhz)
1194+
return overclockMhz;
1195+
#if CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ
1196+
return CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ;
1197+
#elif CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ
1198+
return CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ;
1199+
#endif
1200+
return 0;
11731201
}
11741202

11751203
char *rg_emu_get_path(rg_path_type_t pathType, const char *filename)
@@ -1403,28 +1431,12 @@ rg_emu_states_t *rg_emu_get_states(const char *romPath, size_t slots)
14031431

14041432
bool rg_emu_reset(bool hard)
14051433
{
1406-
if (app.speed != 1.f)
1407-
rg_emu_set_speed(1.f);
1434+
rg_system_set_app_speed(1.f);
14081435
if (app.handlers.reset)
14091436
return app.handlers.reset(hard);
14101437
return false;
14111438
}
14121439

1413-
void rg_emu_set_speed(float speed)
1414-
{
1415-
app.speed = RG_MIN(2.5f, RG_MAX(0.5f, speed));
1416-
// FIXME: We need to store the actual default frameskip so we can return to it...
1417-
app.frameskip = (app.speed - 0.5f) * 3;
1418-
app.frameTime = 1000000.f / (app.tickRate * app.speed);
1419-
rg_audio_set_sample_rate(app.sampleRate * app.speed);
1420-
rg_system_event(RG_EVENT_SPEEDUP, NULL);
1421-
}
1422-
1423-
float rg_emu_get_speed(void)
1424-
{
1425-
return app.speed;
1426-
}
1427-
14281440
#ifdef RG_ENABLE_PROFILING
14291441
// Note this profiler might be inaccurate because of:
14301442
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=28205

components/retro-go/rg_system.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,6 @@ typedef struct
169169
int tickTimeout;
170170
int frameTime;
171171
int frameskip;
172-
int overclock_level;
173-
int overclock_mhz;
174172
bool lowMemoryMode;
175173
bool enWatchdog;
176174
bool isColdBoot;
@@ -190,6 +188,7 @@ typedef struct
190188
float partialFPS;
191189
float fullFPS;
192190
float totalFPS;
191+
float speedPercent;
193192
float busyPercent;
194193
int64_t busyTime;
195194
int64_t lastTick;
@@ -230,9 +229,11 @@ bool rg_system_save_trace(const char *filename, bool append);
230229
void rg_system_event(int event, void *data);
231230
int64_t rg_system_timer(void);
232231
rg_app_t *rg_system_get_app(void);
233-
rg_stats_t rg_system_get_counters(void);
232+
rg_stats_t rg_system_get_stats(void);
234233

235-
// Overclock
234+
// Speed and Overclock
235+
void rg_system_set_app_speed(float speed);
236+
float rg_system_get_app_speed(void);
236237
void rg_system_set_overclock(int level);
237238
int rg_system_get_overclock(void);
238239
int rg_system_get_cpu_speed(void);
@@ -282,8 +283,6 @@ bool rg_emu_reset(bool hard);
282283
bool rg_emu_screenshot(const char *filename, int width, int height);
283284
rg_emu_states_t *rg_emu_get_states(const char *romPath, size_t slots);
284285
uint8_t rg_emu_get_last_used_slot(const char *romPath);
285-
void rg_emu_set_speed(float speed);
286-
float rg_emu_get_speed(void);
287286

288287
/* Utilities */
289288

prboom-go/main/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ void I_StartTic(void)
439439
Z_FreeTags(PU_CACHE, PU_CACHE); // At this point the heap is usually full. Let's reclaim some!
440440
rg_gui_game_menu();
441441
}
442-
realtic_clock_rate = app->speed * 100;
442+
realtic_clock_rate = rg_system_get_app_speed() * 100;
443443
R_InitInterpolation();
444444
}
445445
else

retro-core/main/main_nes.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,13 +298,12 @@ void nes_main(void)
298298

299299
if (skipFrames == 0)
300300
{
301-
int frameTime = 1000000 / (nes->refresh_rate * app->speed);
302301
int elapsed = rg_system_timer() - startTime;
303302
if (nsfPlayer)
304303
skipFrames = 10, nsf_draw_overlay();
305304
else if (app->frameskip > 0)
306305
skipFrames = app->frameskip;
307-
else if (elapsed > frameTime + 1500) // Allow some jitter
306+
else if (elapsed > app->frameTime + 1500) // Allow some jitter
308307
skipFrames = 1; // (elapsed / frameTime)
309308
else if (drawFrame && slowFrame)
310309
skipFrames = 1;

updater/main/main.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@
1414
#define DOWNLOAD_LOCATION RG_BASE_PATH
1515
#endif
1616

17+
#if CONFIG_SPI_FLASH_DANGEROUS_WRITE_ALLOWED
18+
#define CAN_UPDATE_PARTITION_TABLE 1
19+
#else
20+
#define CAN_UPDATE_PARTITION_TABLE 0
21+
#endif
22+
1723
void app_main(void)
1824
{
1925
rg_app_t *app = rg_system_init(32000, NULL, NULL);

0 commit comments

Comments
 (0)