Skip to content

Commit e0f3aa9

Browse files
committed
Add RTC speed control in the IGM
1 parent d92a315 commit e0f3aa9

5 files changed

Lines changed: 80 additions & 37 deletions

File tree

res/messages.py

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,15 @@
295295
"IMENU_PLD_ERR": "Corrupted savestate!", # igm-alertmsg
296296

297297
"IMENU_SAVING_BLOCKED": "Saving in progress!",
298+
299+
"IMENU_RTCSPD": "~main.MSG_DEF_SPEED",
300+
"IMENU_SPD0": "~main.MSG_UIS_SPD0",
301+
"IMENU_SPD1": "~main.MSG_UIS_SPD1",
302+
"IMENU_SPD2": "~main.MSG_UIS_SPD2",
303+
"IMENU_SPD3": "~main.MSG_UIS_SPD3",
304+
"IMENU_SPD4": "~main.MSG_UIS_SPD4",
305+
"IMENU_FRZRTC": "~main.MSG_STILLRTC",
306+
298307
}),
299308
]
300309

@@ -303,19 +312,31 @@
303312
allentries = {}
304313
for e in [en_strings, en_menu_strings]:
305314
for _, d in e:
306-
allentries |= d
315+
for k, v in d.items():
316+
if not v.startswith("~"):
317+
allentries[k] = v
307318
print(json.dumps(allentries, indent=2))
308319
elif len(sys.argv) > 1 and sys.argv[1] == "h":
309-
todump = en_menu_strings if sys.argv[2] == "menu" else en_strings
310-
311-
strlist = []
312-
for c, entries in todump:
313-
for k, v in entries.items():
314-
strlist.append((k, v, c))
315-
strlist = sorted(strlist)
320+
all_entries = {
321+
"main": en_strings,
322+
"menu": en_menu_strings,
323+
}
324+
325+
strlist = {}
326+
strall = {}
327+
328+
# Flatten all strings
329+
for mname, smenu in all_entries.items():
330+
tmp = {}
331+
for c, entries in smenu:
332+
for k, v in entries.items():
333+
if mname == sys.argv[2]:
334+
strlist[k] = (v, c)
335+
tmp[k] = (v, c)
336+
strall[mname] = tmp
316337

317338
print("enum TranslationID {")
318-
for k, _, c in strlist:
339+
for k, (_, c) in sorted(strlist.items()):
319340
if c:
320341
print("#ifdef %s" % c)
321342
print(" %s," % k)
@@ -324,9 +345,13 @@
324345
print("};")
325346

326347
print("const char * const msg_en[] = {")
327-
for k, v, c in strlist:
348+
for k, (v, c) in sorted(strlist.items()):
328349
if c:
329350
print("#ifdef %s" % c)
351+
# Could be a reference to another menu, resolve it
352+
if v.startswith("~"):
353+
mn, mk = v[1:].split(".")
354+
v = strall[mn][mk][0]
330355
print(' /* %s */ "%s",' % (k.ljust(20), v))
331356
if c:
332357
print("#endif")
@@ -337,10 +362,14 @@
337362
for l in OTHER_LANGS:
338363
d = json.load(open(os.path.join(langdir, "%s.json" % l)))
339364
print("const char * const msg_%s[] = {" % l)
340-
for k, en_v, c in strlist:
365+
for k, (en_v, c) in sorted(strlist.items()):
341366
if c:
342367
print("#ifdef %s" % c)
343-
v = d[k] if k in d and d[k] else en_v
368+
if en_v.startswith("~"):
369+
mn, mk = en_v[1:].split(".")
370+
v = d[mk] if mk in d and d[mk] else en_v
371+
else:
372+
v = d[k] if k in d and d[k] else en_v
344373
print(' /* %s */ "%s",' % (k.ljust(20), v))
345374
if c:
346375
print("#endif")

src/common.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ typedef struct {
212212
// RTC config data
213213
typedef struct {
214214
uint32_t timestamp; // RTC current (boot) timestamp.
215-
uint32_t ts_step; // Number of seconds to advance the RTC on events.
215+
uint32_t ts_step; // Speed factor to advance the RTC on events.
216216
} t_rtc_info;
217217

218218

@@ -245,12 +245,6 @@ static inline unsigned savetype_size(EnumSavetype st) {
245245
return 1 << lut[st];
246246
}
247247

248-
static inline unsigned rtc_speed(unsigned speed_class) {
249-
const uint8_t lut[] = {
250-
0, 4, 8, 16, 24, 36
251-
};
252-
return lut[speed_class];
253-
}
254248
static inline unsigned rtc_speed_cnt() {
255249
return 6;
256250
}

src/ingame_menu.c

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ void fast_mem_clr_256(void *addr, uint32_t value, unsigned count);
6060
void set_entrypoint_hook(bool process_cheats);
6161
uint32_t *get_cheat_table();
6262

63+
#define MAX_SPEED_OPTS 6 // Sync with common.h
64+
6365
#define MAX_DISK_SLOTS 5
6466
#define MAX_MEM_SLOTS 32
6567

@@ -85,6 +87,7 @@ uint32_t *get_cheat_table();
8587
static unsigned submenu;
8688
static unsigned copt;
8789
static t_dec_date rtc_date;
90+
static unsigned rtc_speed;
8891
static struct {
8992
const char *msg;
9093
void (*callback)();
@@ -630,24 +633,33 @@ void draw_rtc_menu(uint8_t *fb, unsigned framen) {
630633
char tmont[3] = {'0' + rtc_date.month/10, '0' + rtc_date.month%10, 0};
631634
char tyear[5] = {'2', '0', '0' + rtc_date.year/10, '0' + rtc_date.year%10, 0};
632635

633-
draw_text(tyear, fb, 54, 70, copt == 0 ? HI_COLOR : FG_COLOR);
634-
draw_text("-", fb, 86, 70, FG_COLOR);
635-
draw_text(tmont, fb, 95, 70, copt == 1 ? HI_COLOR : FG_COLOR);
636-
draw_text("-", fb, 111, 70, FG_COLOR);
637-
draw_text(tdays, fb, 120, 70, copt == 2 ? HI_COLOR : FG_COLOR);
638-
draw_text(thour, fb, 148, 70, copt == 3 ? HI_COLOR : FG_COLOR);
639-
draw_text(":", fb, 165, 70, FG_COLOR);
640-
draw_text(tmins, fb, 170, 70, copt == 4 ? HI_COLOR : FG_COLOR);
636+
draw_text(tyear, fb, 54, 56, copt == 0 ? HI_COLOR : FG_COLOR);
637+
draw_text("-", fb, 86, 56, FG_COLOR);
638+
draw_text(tmont, fb, 95, 56, copt == 1 ? HI_COLOR : FG_COLOR);
639+
draw_text("-", fb, 111, 56, FG_COLOR);
640+
draw_text(tdays, fb, 120, 56, copt == 2 ? HI_COLOR : FG_COLOR);
641+
draw_text(thour, fb, 148, 56, copt == 3 ? HI_COLOR : FG_COLOR);
642+
draw_text(":", fb, 165, 56, FG_COLOR);
643+
draw_text(tmins, fb, 170, 56, copt == 4 ? HI_COLOR : FG_COLOR);
641644

642645
if (copt < 5) {
643646
const uint8_t cox[] = {
644647
68, 103, 127, 156, 178
645648
};
646-
draw_text_center("⯅", fb, cox[copt], 54, HI_COLOR);
647-
draw_text_center("⯆", fb, cox[copt], 84, HI_COLOR);
649+
draw_text_center("⯅", fb, cox[copt], 40, HI_COLOR);
650+
draw_text_center("⯆", fb, cox[copt], 70, HI_COLOR);
651+
} else if (copt == 5) {
652+
draw_text_center("⯅", fb, SCREEN_WIDTH/2, 77, HI_COLOR);
653+
draw_text_center("⯆", fb, SCREEN_WIDTH/2, 107, HI_COLOR);
648654
}
649655

650-
draw_text_center(msgs[ingame_menu_lang][IMENU_UPDAT_RTC], fb, SCREEN_WIDTH/2, 120, copt == 5 ? HI_COLOR : FG_COLOR);
656+
char tmp[64];
657+
npf_snprintf(tmp, sizeof(tmp), "%s: %s",
658+
msgs[ingame_menu_lang][IMENU_RTCSPD],
659+
msgs[ingame_menu_lang][rtc_speed ? (IMENU_SPD0 + rtc_speed - 1) : IMENU_FRZRTC]);
660+
draw_text_center(tmp, fb, SCREEN_WIDTH/2, 92, copt == 5 ? HI_COLOR : FG_COLOR);
661+
662+
draw_text_center(msgs[ingame_menu_lang][IMENU_UPDAT_RTC], fb, SCREEN_WIDTH/2, 130, copt == 6 ? HI_COLOR : FG_COLOR);
651663
}
652664

653665
void draw_cheats_menu(uint8_t *fb, unsigned framen) {
@@ -1031,13 +1043,19 @@ void rtckey(uint16_t keyp) {
10311043
rval[copt]--;
10321044

10331045
fixdate(&rtc_date);
1046+
} else if (copt == 5) {
1047+
if (keyp & KEY_BUTTUP)
1048+
rtc_speed++;
1049+
if (keyp & KEY_BUTTDOWN)
1050+
rtc_speed--;
1051+
1052+
rtc_speed = rtc_speed % MAX_SPEED_OPTS;
10341053
}
10351054
}
10361055

10371056
bool action_write_rtc() {
10381057
// Write to the emulated RTC register
1039-
// TODO: Allow changing the RTC speed.
1040-
set_undef_lrsp(date2timestamp(&rtc_date), get_undef_sp());
1058+
set_undef_lrsp(date2timestamp(&rtc_date), rtc_speed);
10411059

10421060
submenu = MenuMain;
10431061
copt = 0;
@@ -1078,6 +1096,7 @@ const menu_action_fn rtcacts[] = {
10781096
NULL,
10791097
NULL,
10801098
NULL,
1099+
NULL,
10811100
action_write_rtc, // Apply RTC time.
10821101
};
10831102

@@ -1103,7 +1122,7 @@ const t_menu_def menudata [] = {
11031122
{ draw_reset_menu, resetacts, NULL, 4, NULL, true },
11041123
{ draw_save_menu, saveacts, NULL, 4, NULL, true },
11051124
{ draw_states_menu, statesacts, sstkey, 3, NULL, true },
1106-
{ draw_rtc_menu, rtcacts, rtckey, 6, NULL, false },
1125+
{ draw_rtc_menu, rtcacts, rtckey, 7, NULL, false },
11071126
{ draw_cheats_menu, cheatsacts, NULL, 0, cheats_cnt, true },
11081127
};
11091128

@@ -1191,8 +1210,9 @@ void ingame_menu_loop(uint32_t *use_cheats_hook) {
11911210
num_mem_savestates = MIN(MAX_MEM_SLOTS, (scratch_size >> 10) / SAVESTATE_SIZE_KB);
11921211
num_dsk_savestates = savestate_pattern[0] ? MAX_DISK_SLOTS : 0;
11931212

1194-
// Read RTC values
1213+
// Read RTC values and speed
11951214
timestamp2date(get_undef_lr(), &rtc_date);
1215+
rtc_speed = get_undef_sp();
11961216

11971217
// Lazy intialization of the SD card, to avoid blocking the menu
11981218
FATFS fs;

src/menu.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2481,7 +2481,7 @@ static void keypress_popup_loadgba(unsigned newkeys) {
24812481

24822482
t_rtc_info rtci = {
24832483
.timestamp = spop.p.load.l.rtcval,
2484-
.ts_step = rtc_speed(rtcspeed_default)
2484+
.ts_step = rtcspeed_default
24852485
};
24862486

24872487
unsigned err = load_gba_rom(
@@ -2738,7 +2738,7 @@ static void keypress_popup_norload(unsigned newkeys) {
27382738
}
27392739
t_rtc_info rtci = {
27402740
.timestamp = spop.p.norld.l.rtcval,
2741-
.ts_step = rtc_speed(rtcspeed_default)
2741+
.ts_step = rtcspeed_default
27422742
};
27432743

27442744
// TODO Handle errors, finish missing stuff.

src/patches.S

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,7 @@ START_FUNC(patch_rtc_gettimedate)
674674
1:
675675
mrs r3, CPSR // Save the current CPSR
676676
msr CPSR_c, $(0x1B | 0x80) // Move to undefined mode, no interrupts
677-
add lr, lr, sp // UNDEF[SP] contains the read-increment
677+
add lr, lr, sp, lsl #3 // UNDEF[SP] contains the RTC speed (0 to 5 -> 0,8,16,24,32,40)
678678
mov r5, lr // Read UNDEF[LR]
679679
msr CPSR_c, r3 // Restore original model and CPSR
680680

0 commit comments

Comments
 (0)