Skip to content

Commit af81c62

Browse files
committed
feat(zaparoo): right-side Display Centering page with H/V offset
Adds a sibling page to the trimmed System Settings menu (reachable via right-arrow) hosting: - H Offset (-8..+7 pixels) - +/- to adjust - V Offset (-8..+7 lines) - +/- to adjust - CRT mode toggle (relocated from System Settings) - Exit Offsets persist via FileSaveConfig in zaparoo_video_offsets.bin (mirror of the existing zaparoo_launcher_crt.bin pattern). Loaded and pushed to the FPGA via user_io_status_set on menu init, so they apply on boot. The 4-bit two's-complement bit pattern matches Menu_MiSTer's signed status[13:10]/status[17:14] inputs which feed h_offset/v_offset on native_video_timing.sv. System Settings page now renders OSD_ARROW_LEFT|OSD_ARROW_RIGHT to indicate the new sibling, and the CRT row + its dispatcher entry have been removed (they live in display_menu now).
1 parent 54fbded commit af81c62

6 files changed

Lines changed: 216 additions & 16 deletions

File tree

menu.cpp

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
5151
#include "menu.h"
5252
#include "support/zaparoo/alt_launcher.h"
5353
#include "support/zaparoo/alt_launcher_menu.h"
54+
#include "support/zaparoo/display_menu.h"
5455
#include "support/zaparoo/menu_rbf.h"
5556
#include "user_io.h"
5657
#include "debug.h"
@@ -85,6 +86,11 @@ enum MENU
8586
MENU_MISC1,
8687
MENU_MISC2,
8788

89+
// Right-side companion to System Settings on the alt-launcher menu core.
90+
// Hosts H/V offset adjustment and the CRT mode toggle.
91+
MENU_ZAPAROO_DISPLAY1,
92+
MENU_ZAPAROO_DISPLAY2,
93+
8894
MENU_SELECT_INI1,
8995
MENU_SELECT_INI2,
9096

@@ -6888,10 +6894,59 @@ void HandleUI(void)
68886894
{
68896895
menustate = MENU_MISC1;
68906896
}
6897+
else if (right && alt_launcher_configured())
6898+
{
6899+
menustate = MENU_ZAPAROO_DISPLAY1;
6900+
menusub = 0;
6901+
}
68916902

68926903
if (!hold_cnt && reboot_req) fpga_load_rbf(menu_rbf_name());
68936904
break;
68946905

6906+
/******************************************************************/
6907+
/* zaparoo display centering page (right-side sibling of System) */
6908+
/******************************************************************/
6909+
case MENU_ZAPAROO_DISPLAY1:
6910+
if (!alt_launcher_configured())
6911+
{
6912+
menustate = MENU_NONE1;
6913+
break;
6914+
}
6915+
helptext_idx = 0;
6916+
parentstate = menustate;
6917+
display_menu_render(menusub, &menumask);
6918+
menustate = MENU_ZAPAROO_DISPLAY2;
6919+
break;
6920+
6921+
case MENU_ZAPAROO_DISPLAY2:
6922+
if (menu)
6923+
{
6924+
menustate = MENU_NONE1;
6925+
break;
6926+
}
6927+
if (left)
6928+
{
6929+
menustate = MENU_SYSTEM1;
6930+
menusub = 0;
6931+
break;
6932+
}
6933+
if (plus || minus)
6934+
{
6935+
display_menu_adjust(menusub, plus ? +1 : -1);
6936+
menustate = MENU_ZAPAROO_DISPLAY1;
6937+
break;
6938+
}
6939+
if (select)
6940+
{
6941+
if (!display_menu_handle_select(menusub))
6942+
{
6943+
menustate = MENU_NONE1;
6944+
break;
6945+
}
6946+
menustate = MENU_ZAPAROO_DISPLAY1;
6947+
}
6948+
break;
6949+
68956950
case MENU_JOYSYSMAP:
68966951
strcpy(joy_bnames[SYS_BTN_A - DPAD_NAMES], "A");
68976952
strcpy(joy_bnames[SYS_BTN_B - DPAD_NAMES], "B");

support/zaparoo/alt_launcher.cpp

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,17 @@ static const char s_tty[] = "tty2";
7474
static const char s_tty_path[] = "/dev/tty2";
7575
static const char s_fb_mode_path[] = "/sys/module/MiSTer_fb/parameters/mode";
7676
static const char s_crt_state_file[] = "zaparoo_launcher_crt.bin";
77+
static const char s_offsets_file[] = "zaparoo_video_offsets.bin";
78+
79+
static int8_t s_h_offset = 0;
80+
static int8_t s_v_offset = 0;
81+
82+
static int8_t clamp_offset(int8_t v)
83+
{
84+
if (v < -8) return -8;
85+
if (v > 7) return 7;
86+
return v;
87+
}
7788

7889
static bool load_persisted_native_crt(void)
7990
{
@@ -88,6 +99,20 @@ static void save_persisted_native_crt(bool crt)
8899
FileSaveConfig(s_crt_state_file, &v, sizeof(v));
89100
}
90101

102+
static void load_persisted_offsets(void)
103+
{
104+
int8_t buf[2] = { 0, 0 };
105+
FileLoadConfig(s_offsets_file, buf, sizeof(buf));
106+
s_h_offset = clamp_offset(buf[0]);
107+
s_v_offset = clamp_offset(buf[1]);
108+
}
109+
110+
static void save_persisted_offsets(void)
111+
{
112+
int8_t buf[2] = { s_h_offset, s_v_offset };
113+
FileSaveConfig(s_offsets_file, buf, sizeof(buf));
114+
}
115+
91116
static void set_launcher_fb_mode(int fmt, int rb, int width, int height, int stride, bool log = true)
92117
{
93118
FILE *fp = fopen(s_fb_mode_path, "wt");
@@ -336,6 +361,31 @@ bool alt_launcher_native_crt(void)
336361
return s_native_crt && s_pid != 0;
337362
}
338363

364+
int8_t alt_launcher_h_offset(void)
365+
{
366+
return s_h_offset;
367+
}
368+
369+
int8_t alt_launcher_v_offset(void)
370+
{
371+
return s_v_offset;
372+
}
373+
374+
void alt_launcher_set_h_offset(int8_t v)
375+
{
376+
s_h_offset = clamp_offset(v);
377+
save_persisted_offsets();
378+
// 4-bit two's-complement bit pattern; FPGA reinterprets as signed -8..+7.
379+
user_io_status_set("[13:10]", (uint32_t)((uint8_t)s_h_offset & 0xF));
380+
}
381+
382+
void alt_launcher_set_v_offset(int8_t v)
383+
{
384+
s_v_offset = clamp_offset(v);
385+
save_persisted_offsets();
386+
user_io_status_set("[17:14]", (uint32_t)((uint8_t)s_v_offset & 0xF));
387+
}
388+
339389
void alt_launcher_toggle_crt(void)
340390
{
341391
bool current_crt = alt_launcher_native_crt();
@@ -497,6 +547,11 @@ void zaparoo_alt_launcher_init_for_core(void)
497547
void zaparoo_alt_launcher_init_for_menu(void)
498548
{
499549
bool crt = load_persisted_native_crt();
500-
printf("alt_launcher: initializing menu launcher (persisted crt=%d)\n", crt);
550+
load_persisted_offsets();
551+
printf("alt_launcher: initializing menu launcher (persisted crt=%d, h=%d, v=%d)\n",
552+
crt, s_h_offset, s_v_offset);
553+
// Push the persisted offsets to the FPGA now that the menu RBF is loaded.
554+
user_io_status_set("[13:10]", (uint32_t)((uint8_t)s_h_offset & 0xF));
555+
user_io_status_set("[17:14]", (uint32_t)((uint8_t)s_v_offset & 0xF));
501556
alt_launcher_init(crt);
502557
}

support/zaparoo/alt_launcher.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@ bool alt_launcher_native_crt(void);
1212
bool alt_launcher_active(void);
1313
bool alt_launcher_configured(void);
1414

15+
// Display centering: signed offsets clamped to -8..+7. Setters update the
16+
// in-memory cache, persist to the config dir, and push to the FPGA via
17+
// user_io_status_set so the change takes effect immediately.
18+
int8_t alt_launcher_h_offset(void);
19+
int8_t alt_launcher_v_offset(void);
20+
void alt_launcher_set_h_offset(int8_t v);
21+
void alt_launcher_set_v_offset(int8_t v);
22+
1523
void alt_launcher_cfg_apply(void);
1624
uint16_t alt_launcher_fb_terminal_key(uint32_t mask, bool osd_button);
1725

support/zaparoo/alt_launcher_menu.cpp

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@ int alt_launcher_render_system_menu(int menusub, uint64_t *menumask,
2323
char s[256];
2424
int m = 0;
2525

26-
OsdSetTitle("System Settings", OSD_ARROW_LEFT);
27-
*menumask = 0x1F;
26+
// Right arrow indicates a sibling page (Display Centering) accessible
27+
// via the right-arrow key — see MENU_ZAPAROO_DISPLAY1 in menu.cpp.
28+
OsdSetTitle("System Settings", OSD_ARROW_LEFT | OSD_ARROW_RIGHT);
29+
*menumask = 0xF;
2830

2931
OsdWrite(m++);
3032
sprintf(s, " MiSTer v%s", version + 5);
@@ -60,17 +62,14 @@ int alt_launcher_render_system_menu(int menusub, uint64_t *menumask,
6062
OsdWrite(m++, " Remap keyboard \x16", menusub == 0);
6163
OsdWrite(m++, " Define joystick buttons \x16", menusub == 1);
6264

63-
sprintf(s, " CRT mode: %-15s", alt_launcher_native_crt() ? "On" : "Off");
64-
OsdWrite(m++, s, menusub == 2);
65-
6665
OsdWrite(m++, "");
6766
int cr = m;
68-
OsdWrite(m++, " Reboot (hold \x16 cold reboot)", menusub == 3);
67+
OsdWrite(m++, " Reboot (hold \x16 cold reboot)", menusub == 2);
6968
*sysinfo_timer = 0;
7069
*reboot_req = 0;
7170

7271
while (m < OsdGetSize() - 1) OsdWrite(m++, "");
73-
OsdWrite(15, ALT_STD_EXIT, menusub == 4);
72+
OsdWrite(15, ALT_STD_EXIT, menusub == 3);
7473

7574
return cr;
7675
}
@@ -79,18 +78,15 @@ int alt_launcher_translate_system_select(int menusub)
7978
{
8079
if (!alt_launcher_configured()) return menusub;
8180

82-
if (menusub == 2)
83-
{
84-
alt_launcher_toggle_crt();
85-
return -1;
86-
}
87-
88-
static const int map[] = { 1, 2, -1, 5, 6 };
81+
// Maps trimmed-menu menusub to upstream MENU_SYSTEM2 dispatch index:
82+
// 0 Remap -> 1, 1 Define joy -> 2, 2 Reboot -> 5, 3 Exit -> 6.
83+
// CRT mode lives on the Display Centering page now, not here.
84+
static const int map[] = { 1, 2, 5, 6 };
8985
if (menusub < 0 || menusub >= (int)(sizeof(map) / sizeof(map[0]))) return -1;
9086
return map[menusub];
9187
}
9288

9389
bool alt_launcher_system_holding_reboot(int menusub)
9490
{
95-
return alt_launcher_configured() && menusub == 3;
91+
return alt_launcher_configured() && menusub == 2;
9692
}

support/zaparoo/display_menu.cpp

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#include "display_menu.h"
2+
#include "alt_launcher.h"
3+
#include "osd.h"
4+
5+
#include <stdio.h>
6+
7+
#define DISPLAY_STD_EXIT " exit"
8+
9+
void display_menu_render(int menusub, uint64_t *menumask)
10+
{
11+
OsdSetSize(16);
12+
OsdSetTitle("Display Centering", OSD_ARROW_LEFT);
13+
*menumask = 0xF; // 4 entries: H, V, CRT, Exit
14+
15+
char s[64];
16+
int m = 0;
17+
18+
OsdWrite(m++);
19+
OsdWrite(m++, "");
20+
OsdWrite(m++, "");
21+
OsdWrite(m++, "");
22+
23+
sprintf(s, " H Offset: %+3d (-/+)", alt_launcher_h_offset());
24+
OsdWrite(m++, s, menusub == 0);
25+
26+
sprintf(s, " V Offset: %+3d (-/+)", alt_launcher_v_offset());
27+
OsdWrite(m++, s, menusub == 1);
28+
29+
OsdWrite(m++, "");
30+
sprintf(s, " CRT mode: %-15s", alt_launcher_native_crt() ? "On" : "Off");
31+
OsdWrite(m++, s, menusub == 2);
32+
33+
while (m < OsdGetSize() - 1) OsdWrite(m++, "");
34+
OsdWrite(15, DISPLAY_STD_EXIT, menusub == 3);
35+
}
36+
37+
bool display_menu_handle_select(int menusub)
38+
{
39+
switch (menusub)
40+
{
41+
case 2:
42+
alt_launcher_toggle_crt();
43+
return true;
44+
case 3:
45+
return false;
46+
default:
47+
return true;
48+
}
49+
}
50+
51+
void display_menu_adjust(int menusub, int dir)
52+
{
53+
if (dir == 0) return;
54+
int8_t step = (int8_t)(dir > 0 ? 1 : -1);
55+
switch (menusub)
56+
{
57+
case 0:
58+
alt_launcher_set_h_offset((int8_t)(alt_launcher_h_offset() + step));
59+
break;
60+
case 1:
61+
alt_launcher_set_v_offset((int8_t)(alt_launcher_v_offset() + step));
62+
break;
63+
default:
64+
break;
65+
}
66+
}

support/zaparoo/display_menu.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#pragma once
2+
3+
#include <stdbool.h>
4+
#include <stdint.h>
5+
6+
// Right-side companion to the trimmed System Settings menu. Hosts the
7+
// display centering controls (H/V offset) and the CRT mode toggle that
8+
// used to live next to Reboot in alt_launcher_render_system_menu.
9+
//
10+
// menusub layout: 0 = H offset, 1 = V offset, 2 = CRT mode, 3 = Exit.
11+
12+
void display_menu_render(int menusub, uint64_t *menumask);
13+
14+
// Returns true if the press was consumed (re-render required without
15+
// dispatching to MENU_NONE1). Caller checks this before exiting.
16+
bool display_menu_handle_select(int menusub);
17+
18+
// Adjust the highlighted offset row by `dir` (-1 / +1). No-op when the
19+
// current row is not an offset row.
20+
void display_menu_adjust(int menusub, int dir);

0 commit comments

Comments
 (0)