Skip to content
This repository was archived by the owner on Sep 29, 2025. It is now read-only.

Commit 9942bfc

Browse files
author
Flyinghead
committed
Merge branch clean-exit-light
2 parents a11dd3f + 5960450 commit 9942bfc

File tree

25 files changed

+157
-166
lines changed

25 files changed

+157
-166
lines changed

core/dispframe.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include "rend/TexCache.h"
55

66
extern cResetEvent rs;
7-
extern int rend_en;
7+
extern int renderer_enabled;
88
extern cResetEvent frame_finished;
99
extern TA_context* rqueue;
1010

@@ -33,7 +33,7 @@ void dc_run()
3333
double t1 = os_GetSeconds();
3434
printf("Loaded context in %g ms\n", (t1- t0) * 1000);
3535

36-
while(rend_en)
36+
while(renderer_enabled)
3737
{
3838
tad_context saved_tad = ctx->tad;
3939
rend_context saved_rend = ctx->rend;

core/hw/pvr/Renderer_if.cpp

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ u32 VertexCount=0;
7676
u32 FrameCount=1;
7777

7878
Renderer* renderer;
79+
bool renderer_enabled = true; // Signals the renderer thread to exit
7980

8081
#if !defined(TARGET_NO_THREADS)
8182
cResetEvent rs(false,true);
@@ -251,6 +252,9 @@ bool rend_single_frame()
251252
#if !defined(TARGET_NO_THREADS)
252253
rs.Wait();
253254
#endif
255+
if (!renderer_enabled)
256+
return false;
257+
254258
_pvrrc = DequeueRender();
255259
}
256260
while (!_pvrrc);
@@ -266,8 +270,6 @@ bool rend_single_frame()
266270
return do_swp;
267271
}
268272

269-
int rend_en = true;
270-
271273
void* rend_thread(void* p)
272274
{
273275
#if FEAT_HAS_NIXPROF
@@ -308,22 +310,14 @@ void* rend_thread(void* p)
308310
//we don't know if this is true, so let's not speculate here
309311
//renderer->Resize(640, 480);
310312

311-
while(rend_en)
313+
while (renderer_enabled)
312314
{
313315
if (rend_single_frame())
314316
renderer->Present();
315317
}
316318

317-
return 0;
318-
}
319-
320-
#if HOST_OS==OS_LINUX || HOST_OS==OS_DARWIN
321-
void rend_terminate()
322-
{
323-
rend_en = false;
324-
printf("rend_terminate called\n");
319+
return NULL;
325320
}
326-
#endif
327321

328322
#if !defined(TARGET_NO_THREADS)
329323
cThread rthd(rend_thread,0);
@@ -539,11 +533,20 @@ bool rend_init()
539533

540534
void rend_term()
541535
{
536+
renderer_enabled = false;
537+
#if !defined(TARGET_NO_THREADS)
538+
rs.Set();
539+
#endif
540+
542541
if (fCheckFrames)
543542
fclose(fCheckFrames);
544543

545544
if (fLogFrames)
546545
fclose(fLogFrames);
546+
547+
#if !defined(TARGET_NO_THREADS)
548+
rthd.WaitToEnd();
549+
#endif
547550
}
548551

549552
void rend_vblank()

core/linux-dist/evdev.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
libevdev_func1_t libevdev_event_code_from_name;
1717
libevdev_func2_t libevdev_event_code_get_name;
1818

19+
void dc_stop(void);
20+
1921
void load_libevdev()
2022
{
2123
if (libevdev_tried)
@@ -355,8 +357,7 @@
355357
} else if (ie.code == controller->mapping->Btn_Start) {
356358
SET_FLAG(kcode[port], DC_BTN_START, ie.value);
357359
} else if (ie.code == controller->mapping->Btn_Escape) {
358-
if (ie.value == 0)
359-
start_shutdown();
360+
dc_stop();
360361
} else if (ie.code == controller->mapping->Btn_DPad_Left) {
361362
SET_FLAG(kcode[port], DC_DPAD_LEFT, ie.value);
362363
} else if (ie.code == controller->mapping->Btn_DPad_Right) {

core/linux-dist/joystick.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
#include <unistd.h>
22
#include <fcntl.h>
33
#include <sys/types.h>
4-
#include <linux/joystick.h>
54
#include "linux-dist/joystick.h"
65

76
#if defined(USE_JOYSTICK)
7+
#include <linux/joystick.h>
8+
89
const u32 joystick_map_btn_usb[JOYSTICK_MAP_SIZE] = { DC_BTN_Y, DC_BTN_B, DC_BTN_A, DC_BTN_X, 0, 0, 0, 0, 0, DC_BTN_START };
910
const u32 joystick_map_axis_usb[JOYSTICK_MAP_SIZE] = { DC_AXIS_X, DC_AXIS_Y, 0, 0, 0, 0, 0, 0, 0, 0 };
1011

core/linux-dist/main.cpp

Lines changed: 12 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ void os_CreateWindow()
252252
void common_linux_setup();
253253
int dc_init(int argc,wchar* argv[]);
254254
void dc_run();
255+
void dc_term();
255256

256257
#ifdef TARGET_PANDORA
257258
void gl_term();
@@ -426,23 +427,6 @@ std::vector<string> find_system_data_dirs()
426427
return dirs;
427428
}
428429

429-
#if HOST_OS==OS_LINUX
430-
#if defined(SUPPORT_X11)
431-
void x11_gl_context_destroy();
432-
void x11_window_destroy();
433-
#endif
434-
void dc_term();
435-
void rend_terminate();
436-
void ngen_terminate();
437-
438-
void start_shutdown(void)
439-
{
440-
printf("start_shutdown called\n");
441-
rend_terminate();
442-
ngen_terminate();
443-
}
444-
#endif
445-
446430
int main(int argc, wchar* argv[])
447431
{
448432
#ifdef TARGET_PANDORA
@@ -491,31 +475,25 @@ int main(int argc, wchar* argv[])
491475
emscripten_set_main_loop(&dc_run, 100, false);
492476
#endif
493477

494-
495478
#ifdef TARGET_PANDORA
496479
clean_exit(0);
497480
#endif
498481

499-
#if HOST_OS==OS_LINUX
500482
dc_term();
501-
#if defined(USE_EVDEV)
502-
printf("closing any open controllers\n");
503483

504-
for (int port = 0; port < 4 ; port++)
505-
{
506-
if(evdev_controllers[port].fd >= 0)
484+
#if defined(USE_EVDEV)
485+
for (int port = 0; port < 4 ; port++)
507486
{
508-
close(evdev_controllers[port].fd);
487+
if(evdev_controllers[port].fd >= 0)
488+
{
489+
close(evdev_controllers[port].fd);
490+
}
509491
}
510-
}
511-
#endif
512-
#if defined(SUPPORT_X11)
513-
/* Close the GL context */
514-
x11_gl_context_destroy();
515-
/* Destroy the window */
516-
x11_window_destroy();
517-
#endif
518-
#endif
492+
#endif
493+
494+
#if defined(SUPPORT_X11)
495+
x11_window_destroy();
496+
#endif
519497

520498
return 0;
521499
}

core/linux-dist/x11.cpp

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,16 @@ int x11_width;
3535
int x11_height;
3636

3737
int ndcid = 0;
38-
void* x11_glc;
38+
void* x11_glc = NULL;
3939
bool x11_fullscreen = false;
40+
Atom wmDeleteMessage;
4041

4142
void* x11_vis;
42-
Atom wmDeleteMessage;
4343

4444
extern bool dump_frame_switch;
4545

46+
void dc_stop(void);
47+
4648
enum
4749
{
4850
_NET_WM_STATE_REMOVE =0,
@@ -67,19 +69,17 @@ void x11_window_set_fullscreen(bool fullscreen)
6769
XSendEvent((Display*)x11_disp, DefaultRootWindow((Display*)x11_disp), False, SubstructureNotifyMask, &xev);
6870
}
6971

70-
void start_shutdown(void);
71-
7272
void event_x11_handle()
7373
{
7474
XEvent event;
7575

76-
while(XPending((Display *)x11_disp)) {
76+
while(XPending((Display *)x11_disp))
77+
{
7778
XNextEvent((Display *)x11_disp, &event);
7879

7980
if (event.type == ClientMessage &&
80-
event.xclient.data.l[0] == wmDeleteMessage) {
81-
start_shutdown();
82-
}
81+
event.xclient.data.l[0] == wmDeleteMessage)
82+
dc_stop();
8383
}
8484
}
8585

@@ -98,7 +98,7 @@ void input_x11_handle()
9898
case KeyRelease:
9999
if (e.type == KeyRelease && e.xkey.keycode == KEY_ESC)
100100
{
101-
start_shutdown();
101+
dc_stop();
102102
}
103103
#ifndef RELEASE
104104
else if (e.xkey.keycode == KEY_F10)
@@ -269,7 +269,7 @@ void x11_window_create()
269269

270270
// Get a visual
271271
XVisualInfo *vi = glXGetVisualFromFBConfig(x11Display, bestFbc);
272-
printf("Chosen visual ID = 0x%x\n", vi->visualid);
272+
printf("Chosen visual ID = 0x%lx\n", vi->visualid);
273273

274274

275275
depth = vi->depth;
@@ -308,6 +308,7 @@ void x11_window_create()
308308
x11Window = XCreateWindow(x11Display, RootWindow(x11Display, x11Screen), (ndcid%3)*640, (ndcid/3)*480, x11_width, x11_height,
309309
0, depth, InputOutput, x11Visual->visual, ui32Mask, &sWA);
310310

311+
// Capture the close window event
311312
wmDeleteMessage = XInternAtom(x11Display, "WM_DELETE_WINDOW", False);
312313
XSetWMProtocols(x11Display, x11Window, &wmDeleteMessage, 1);
313314

@@ -390,12 +391,18 @@ void x11_window_destroy()
390391
if (x11_win)
391392
{
392393
XDestroyWindow((Display*)x11_disp, (Window)x11_win);
393-
x11_win = 0;
394+
x11_win = NULL;
394395
}
395396
if (x11_disp)
396397
{
398+
if (x11_glc)
399+
{
400+
glXMakeCurrent((Display*)x11_disp, None, NULL);
401+
glXDestroyContext((Display*)x11_disp, (GLXContext)x11_glc);
402+
x11_glc = NULL;
403+
}
397404
XCloseDisplay((Display*)x11_disp);
398-
x11_disp = 0;
405+
x11_disp = NULL;
399406
}
400407
}
401408
#endif

core/linux-dist/x11.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ extern void* x11_glc;
44
extern void input_x11_init();
55
extern void event_x11_handle();
66
extern void input_x11_handle();
7+
extern void event_x11_handle();
78
extern void x11_window_create();
89
extern void x11_window_set_text(const char* text);
10+
extern void x11_window_destroy();
911

1012
// numbers
1113
const int KEY_1 = 10;

core/linux/common.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#include <sys/param.h>
1919
#include <sys/mman.h>
2020
#include <sys/time.h>
21-
#if !defined(_ANDROID) && !defined(TARGET_IPHONE) && !defined(TARGET_NACL32) && !defined(TARGET_EMSCRIPTEN) && !defined(TARGET_OSX) && !defined(TARGET_OSX_X64)
21+
#if !defined(TARGET_BSD) && !defined(_ANDROID) && !defined(TARGET_IPHONE) && !defined(TARGET_NACL32) && !defined(TARGET_EMSCRIPTEN) && !defined(TARGET_OSX) && !defined(TARGET_OSX_X64)
2222
#include <sys/personality.h>
2323
#include <dlfcn.h>
2424
#endif
@@ -292,15 +292,15 @@ void enable_runfast()
292292
}
293293

294294
void linux_fix_personality() {
295-
#if HOST_OS == OS_LINUX && !defined(_ANDROID) && !defined(TARGET_OS_IPHONE) && !defined(TARGET_NACL32) && !defined(TARGET_EMSCRIPTEN)
295+
#if !defined(TARGET_BSD) && !defined(_ANDROID) && !defined(TARGET_OS_IPHONE) && !defined(TARGET_NACL32) && !defined(TARGET_EMSCRIPTEN)
296296
printf("Personality: %08X\n", personality(0xFFFFFFFF));
297297
personality(~READ_IMPLIES_EXEC & personality(0xFFFFFFFF));
298298
printf("Updated personality: %08X\n", personality(0xFFFFFFFF));
299299
#endif
300300
}
301301

302302
void linux_rpi2_init() {
303-
#if (HOST_OS == OS_LINUX) && !defined(_ANDROID) && !defined(TARGET_NACL32) && !defined(TARGET_EMSCRIPTEN) && defined(TARGET_VIDEOCORE)
303+
#if !defined(TARGET_BSD) && !defined(_ANDROID) && !defined(TARGET_NACL32) && !defined(TARGET_EMSCRIPTEN) && defined(TARGET_VIDEOCORE)
304304
void* handle;
305305
void (*rpi_bcm_init)(void);
306306

core/linux/context.cpp

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,12 @@ void context_segfault(rei_host_context_t* reictx, void* segfault_ctx, bool to_se
3131

3232
#if !defined(TARGET_NO_EXCEPTIONS)
3333
#if HOST_CPU == CPU_ARM
34-
#if HOST_OS == OS_LINUX
34+
#if defined(__FreeBSD__)
35+
bicopy(reictx->pc, MCTX(.__gregs[_REG_PC]), to_segfault);
36+
37+
for (int i = 0; i < 15; i++)
38+
bicopy(reictx->r[i], MCTX(.__gregs[i]), to_segfault);
39+
#elif HOST_OS == OS_LINUX
3540
bicopy(reictx->pc, MCTX(.arm_pc), to_segfault);
3641
u32* r =(u32*) &MCTX(.arm_r0);
3742

@@ -47,7 +52,12 @@ void context_segfault(rei_host_context_t* reictx, void* segfault_ctx, bool to_se
4752
#error HOST_OS
4853
#endif
4954
#elif HOST_CPU == CPU_X86
50-
#if HOST_OS == OS_LINUX
55+
#if defined(__FreeBSD__)
56+
bicopy(reictx->pc, MCTX(.mc_eip), to_segfault);
57+
bicopy(reictx->esp, MCTX(.mc_esp), to_segfault);
58+
bicopy(reictx->eax, MCTX(.mc_eax), to_segfault);
59+
bicopy(reictx->ecx, MCTX(.mc_ecx), to_segfault);
60+
#elif HOST_OS == OS_LINUX
5161
bicopy(reictx->pc, MCTX(.gregs[REG_EIP]), to_segfault);
5262
bicopy(reictx->esp, MCTX(.gregs[REG_ESP]), to_segfault);
5363
bicopy(reictx->eax, MCTX(.gregs[REG_EAX]), to_segfault);
@@ -61,11 +71,15 @@ void context_segfault(rei_host_context_t* reictx, void* segfault_ctx, bool to_se
6171
#error HOST_OS
6272
#endif
6373
#elif HOST_CPU == CPU_X64
64-
#if HOST_OS == OS_LINUX
65-
bicopy(reictx->pc, MCTX(.gregs[REG_RIP]), to_segfault);
66-
#elif HOST_OS == OS_DARWIN
67-
bicopy(reictx->pc, MCTX(->__ss.__rip), to_segfault);
68-
#endif
74+
#if defined(__FreeBSD__) || defined(__DragonFly__)
75+
bicopy(reictx->pc, MCTX(.mc_rip), to_segfault);
76+
#elif defined(__NetBSD__)
77+
bicopy(reictx->pc, MCTX(.__gregs[_REG_RIP]), to_segfault);
78+
#elif HOST_OS == OS_LINUX
79+
bicopy(reictx->pc, MCTX(.gregs[REG_RIP]), to_segfault);
80+
#else
81+
#error HOST_OS
82+
#endif
6983
#elif HOST_CPU == CPU_MIPS
7084
bicopy(reictx->pc, MCTX(.pc), to_segfault);
7185
#elif HOST_CPU == CPU_GENERIC

core/nullDC.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,13 @@ void dc_term()
255255
SaveSettings();
256256
#endif
257257
SaveRomFiles(get_writable_data_path("/data/"));
258+
259+
TermAudio();
260+
}
261+
262+
void dc_stop()
263+
{
264+
sh4_cpu.Stop();
258265
}
259266

260267
void LoadSettings()

0 commit comments

Comments
 (0)