Skip to content

Commit 562b60c

Browse files
authored
Merge pull request #1 from ZaparooProject/codex/zaparoo-prelaunch-video-state
feat(zaparoo): add native CRT launch mode
2 parents f13a570 + f57b0b9 commit 562b60c

4 files changed

Lines changed: 126 additions & 6 deletions

File tree

input.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2472,7 +2472,7 @@ static void joy_digital(int jnum, uint32_t mask, uint32_t code, char press, int
24722472
}
24732473
input_cb(&ev, 0, 0, true);
24742474
}
2475-
else if (video_fb_state())
2475+
else if (video_fb_state() || alt_launcher_active())
24762476
{
24772477
uint16_t alt_key = alt_launcher_fb_terminal_key(mask, bnum == BTN_OSD);
24782478
if (alt_key)

support/zaparoo/alt_launcher.cpp

Lines changed: 120 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "cfg.h"
1414
#include "file_io.h"
1515
#include "hardware.h"
16+
#include "input.h"
1617
#include "user_io.h"
1718
#include "video.h"
1819

@@ -48,11 +49,35 @@ uint16_t alt_launcher_fb_terminal_key(uint32_t mask, bool osd_button)
4849
static pid_t s_pid = 0;
4950
static int s_crash_count = 0;
5051
static unsigned long s_respawn_timer = 0;
52+
static unsigned long s_native_status_timer = 0;
53+
static unsigned long s_native_fb_mode_timer = 0;
5154
static bool s_gave_up = false;
5255
static bool s_init_pending = false;
56+
static bool s_native_crt = false;
5357
static const int s_vt = 2;
5458
static const char s_tty[] = "tty2";
5559
static const char s_tty_path[] = "/dev/tty2";
60+
static const char s_fb_mode_path[] = "/sys/module/MiSTer_fb/parameters/mode";
61+
62+
static void set_launcher_fb_mode(int fmt, int rb, int width, int height, int stride, bool log = true)
63+
{
64+
FILE *fp = fopen(s_fb_mode_path, "wt");
65+
if (!fp)
66+
{
67+
printf("alt_launcher: unable to set fb mode: %s\n", strerror(errno));
68+
return;
69+
}
70+
71+
fprintf(fp, "%d %d %d %d %d\n", fmt, rb, width, height, stride);
72+
fclose(fp);
73+
if (log)
74+
printf("alt_launcher: fb mode set to %dx%d fmt=%d stride=%d\n", width, height, fmt, stride);
75+
}
76+
77+
static void set_native_crt_fb_mode(bool log = true)
78+
{
79+
set_launcher_fb_mode(8888, 1, 320, 240, 1280, log);
80+
}
5681

5782
static void clear_launcher_tty(void)
5883
{
@@ -109,6 +134,28 @@ static bool launcher_tty_ready(pid_t pid)
109134
return false;
110135
}
111136

137+
static void disable_native_crt_path(void)
138+
{
139+
user_io_status_set("[9]", 0);
140+
video_fb_enable(0);
141+
set_vga_fb(0);
142+
set_launcher_fb_mode(8888, 1, 960, 720, 3840);
143+
s_native_status_timer = 0;
144+
s_native_fb_mode_timer = 0;
145+
}
146+
147+
static void enable_native_crt_path(void)
148+
{
149+
set_vga_fb(0);
150+
video_fb_enable(0);
151+
set_native_crt_fb_mode();
152+
user_io_status_set("[9]", 1);
153+
s_native_status_timer = GetTimer(500);
154+
if (!s_native_status_timer) s_native_status_timer = 1;
155+
s_native_fb_mode_timer = GetTimer(1000);
156+
if (!s_native_fb_mode_timer) s_native_fb_mode_timer = 1;
157+
}
158+
112159
static void wait_launcher_tty_ready(pid_t pid)
113160
{
114161
for (int i = 0; i < 100; i++)
@@ -124,7 +171,9 @@ static void return_to_normal_mode(void)
124171
user_io_osd_key_enable(1);
125172
reset_launcher_tty();
126173
video_menu_bg(user_io_status_get("[3:1]"));
127-
video_fb_enable(0);
174+
if (s_native_crt) disable_native_crt_path();
175+
else video_fb_enable(0);
176+
s_native_crt = false;
128177
s_respawn_timer = 0;
129178
s_crash_count = 0;
130179
s_gave_up = true;
@@ -156,6 +205,9 @@ static void spawn(void)
156205
"export LC_ALL=en_US.UTF-8\n"
157206
"export HOME=/root\n"
158207
"printf '\\033[0m\\033[?25l\\033[37m\\033[40m\\033[2J\\033[H'\n"
208+
"if [ \"$ALT_LAUNCHER_CRT\" = \"1\" ]; then\n"
209+
" exec \"$ALT_LAUNCHER_PATH\" --crt\n"
210+
"fi\n"
159211
"exec \"$ALT_LAUNCHER_PATH\"\n";
160212

161213
unlink("/tmp/alt_launcher");
@@ -165,19 +217,32 @@ static void spawn(void)
165217
user_io_osd_key_enable(0);
166218
clear_launcher_tty();
167219

220+
printf("alt_launcher: native_crt=%d\n", s_native_crt);
221+
if (s_native_crt)
222+
{
223+
enable_native_crt_path();
224+
printf("alt_launcher: native CRT path enabled\n");
225+
}
226+
else
227+
{
228+
printf("alt_launcher: HPS framebuffer path enabled\n");
229+
}
230+
168231
s_pid = fork();
169232
if (s_pid < 0)
170233
{
171234
printf("alt_launcher: fork failed: %s\n", strerror(errno));
172235
s_pid = 0;
173236
user_io_osd_key_enable(1);
174-
video_fb_enable(0);
237+
if (s_native_crt) disable_native_crt_path();
238+
else video_fb_enable(0);
175239
return;
176240
}
177241
printf("alt_launcher: spawned pid=%d path=%s\n", s_pid, path);
178242
if (!s_pid)
179243
{
180244
setenv("ALT_LAUNCHER_PATH", path, 1);
245+
setenv("ALT_LAUNCHER_CRT", s_native_crt ? "1" : "0", 1);
181246
cpu_set_t set;
182247
CPU_ZERO(&set);
183248
CPU_SET(0, &set);
@@ -190,27 +255,47 @@ static void spawn(void)
190255

191256
wait_launcher_tty_ready(s_pid);
192257
video_chvt(s_vt);
193-
video_fb_enable(1);
258+
if (!s_native_crt)
259+
video_fb_enable(1);
260+
else
261+
{
262+
input_switch(0);
263+
user_io_status_set("[9]", 1);
264+
}
194265
}
195266

196267
bool alt_launcher_active(void)
197268
{
198269
return s_pid != 0;
199270
}
200271

201-
void alt_launcher_init(void)
272+
void alt_launcher_init(bool native_crt)
202273
{
203274
if (!cfg.alt_launcher[0] || !cfg.fb_terminal || s_pid || s_gave_up)
204275
return;
205276
s_crash_count = 0;
206277
s_respawn_timer = 0;
278+
s_native_crt = native_crt;
207279
s_init_pending = true;
208280
}
209281

210282
void alt_launcher_poll(void)
211283
{
212284
if (s_pid)
213285
{
286+
if (s_native_crt && s_native_status_timer && CheckTimer(s_native_status_timer))
287+
{
288+
user_io_status_set("[9]", 1);
289+
s_native_status_timer = GetTimer(500);
290+
if (!s_native_status_timer) s_native_status_timer = 1;
291+
}
292+
293+
if (s_native_crt && s_native_fb_mode_timer && CheckTimer(s_native_fb_mode_timer))
294+
{
295+
set_native_crt_fb_mode();
296+
s_native_fb_mode_timer = 0;
297+
}
298+
214299
int status;
215300
if (waitpid(s_pid, &status, WNOHANG) == s_pid)
216301
{
@@ -263,6 +348,11 @@ void alt_launcher_shutdown(void)
263348
if (!s_pid)
264349
{
265350
reset_launcher_state();
351+
if (s_native_crt)
352+
{
353+
s_native_crt = false;
354+
disable_native_crt_path();
355+
}
266356
return;
267357
}
268358

@@ -293,4 +383,30 @@ void alt_launcher_shutdown(void)
293383
}
294384

295385
reset_launcher_state();
386+
if (s_native_crt)
387+
{
388+
s_native_crt = false;
389+
disable_native_crt_path();
390+
}
391+
else
392+
{
393+
video_fb_enable(0);
394+
}
395+
}
396+
397+
bool zaparoo_is_native_core(void)
398+
{
399+
static const char *name = "Zaparoo Launcher";
400+
return !strcasecmp(user_io_get_core_name(0), name) ||
401+
!strcasecmp(user_io_get_core_name(1), name);
402+
}
403+
404+
void zaparoo_alt_launcher_init_for_core(void)
405+
{
406+
if (cfg.alt_launcher[0] && cfg.fb_terminal && zaparoo_is_native_core())
407+
{
408+
printf("alt_launcher: initializing CRT mode for core '%s' '%s'\n",
409+
user_io_get_core_name(1), user_io_get_core_name(0));
410+
alt_launcher_init(true);
411+
}
296412
}

support/zaparoo/alt_launcher.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@
44

55
#define ALT_LAUNCHER_MENUSUB 31
66

7-
void alt_launcher_init(void);
7+
void alt_launcher_init(bool native_crt = false);
88
void alt_launcher_poll(void);
99
void alt_launcher_shutdown(void);
1010
bool alt_launcher_active(void);
1111
bool alt_launcher_configured(void);
1212

1313
void alt_launcher_cfg_defaults(void);
1414
uint16_t alt_launcher_fb_terminal_key(uint32_t mask, bool osd_button);
15+
16+
bool zaparoo_is_native_core(void);
17+
void zaparoo_alt_launcher_init_for_core(void);

user_io.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1535,6 +1535,7 @@ void user_io_init(const char *path, const char *xml)
15351535
}
15361536
else
15371537
{
1538+
zaparoo_alt_launcher_init_for_core();
15381539
if (xml && isXmlName(xml) == 1)
15391540
{
15401541
arcade_send_rom(xml);

0 commit comments

Comments
 (0)