Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge 7oxicshadow's Linux fixes #6

Open
wants to merge 6 commits into
base: retropie
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 28 additions & 4 deletions core/cfg/ini.cpp
Expand Up @@ -166,25 +166,49 @@ bool ConfigFile::get_bool(string section_name, string entry_name, bool default_v

void ConfigFile::set(string section_name, string entry_name, string value, bool is_virtual)
{
ConfigSection* section = this->get_section(section_name, is_virtual);
bool local_virtual;

#ifdef NO_VIRTUAL_CFG
local_virtual = false;
#else
local_virtual = is_virtual;
#endif

ConfigSection* section = this->get_section(section_name, local_virtual);
if(section == NULL)
{
section = this->add_section(section_name, is_virtual);
section = this->add_section(section_name, local_virtual);
}
section->set(entry_name, value);
};

void ConfigFile::set_int(string section_name, string entry_name, int value, bool is_virtual)
{
bool local_virtual;

#ifdef NO_VIRTUAL_CFG
local_virtual = false;
#else
local_virtual = is_virtual;
#endif

std::stringstream str_value;
str_value << value;
this->set(section_name, entry_name, str_value.str(), is_virtual);
this->set(section_name, entry_name, str_value.str(), local_virtual);
}

void ConfigFile::set_bool(string section_name, string entry_name, bool value, bool is_virtual)
{
bool local_virtual;

#ifdef NO_VIRTUAL_CFG
local_virtual = false;
#else
local_virtual = is_virtual;
#endif

string str_value = (value ? "yes" : "no");
this->set(section_name, entry_name, str_value, is_virtual);
this->set(section_name, entry_name, str_value, local_virtual);
}

void ConfigFile::parse(FILE* file)
Expand Down
14 changes: 13 additions & 1 deletion core/hw/pvr/Renderer_if.cpp
Expand Up @@ -229,6 +229,8 @@ bool rend_single_frame()
return do_swp;
}

int rend_en = true;

void* rend_thread(void* p)
{
#if FEAT_HAS_NIXPROF
Expand Down Expand Up @@ -269,12 +271,22 @@ void* rend_thread(void* p)
//we don't know if this is true, so let's not speculate here
//renderer->Resize(640, 480);

for(;;)
while(rend_en)
{
if (rend_single_frame())
renderer->Present();
}

return (0);
}

#if HOST_OS==OS_LINUX
void rend_terminate()
{
rend_en = false;
printf("rend_terminate called\n");
}
#endif

#if !defined(TARGET_NO_THREADS)
cThread rthd(rend_thread,0);
Expand Down
4 changes: 3 additions & 1 deletion core/linux-dist/evdev.cpp
Expand Up @@ -299,6 +299,8 @@
}
}

void start_shutdown(void);

bool input_evdev_handle(EvdevController* controller, u32 port)
{
#define SET_FLAG(field, mask, expr) field =((expr) ? (field & ~mask) : (field | mask))
Expand Down Expand Up @@ -331,7 +333,7 @@
} else if (ie.code == controller->mapping->Btn_Start) {
SET_FLAG(kcode[port], DC_BTN_START, ie.value);
} else if (ie.code == controller->mapping->Btn_Escape) {
die("death by escape key");
start_shutdown();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrong indent.

} else if (ie.code == controller->mapping->Btn_DPad_Left) {
SET_FLAG(kcode[port], DC_DPAD_LEFT, ie.value);
} else if (ie.code == controller->mapping->Btn_DPad_Right) {
Expand Down
55 changes: 54 additions & 1 deletion core/linux-dist/main.cpp
Expand Up @@ -223,6 +223,7 @@ void os_DoEvents()
{
#if defined(SUPPORT_X11)
input_x11_handle();
event_x11_handle();
#endif
}

Expand Down Expand Up @@ -427,9 +428,34 @@ std::vector<string> find_system_data_dirs()
return dirs;
}

#if HOST_OS==OS_LINUX

#if defined(SUPPORT_X11)
/* Required Prototypes */
void x11_gl_context_destroy();
void x11_window_destroy();
#endif

void dc_term();
void rend_terminate();
void ngen_terminate();

void start_shutdown(void)
{
printf("start_shutdown called\n");
rend_terminate();
ngen_terminate();
}

#endif
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrong ident.


int main(int argc, wchar* argv[])
{

#ifdef NO_VIRTUAL_CFG
printf("Virtual CFG support is disabled in this build! \n");
#endif

#ifdef TARGET_PANDORA
signal(SIGSEGV, clean_exit);
signal(SIGKILL, clean_exit);
Expand Down Expand Up @@ -476,11 +502,38 @@ int main(int argc, wchar* argv[])
emscripten_set_main_loop(&dc_run, 100, false);
#endif


#ifdef TARGET_PANDORA
clean_exit(0);
#endif

#if HOST_OS==OS_LINUX

printf("main loop ended\n");

dc_term();

#if defined(USE_EVDEV)
printf("closing any open controllers\n");

for (int port = 0; port < 4 ; port++)
{
if(evdev_controllers[port].fd >= 0)
{
close(evdev_controllers[port].fd);
}
}
#endif

#if defined(SUPPORT_X11)
/*Close the GL context */
x11_gl_context_destroy();
/* Destroy the window */
x11_window_destroy();
#endif

#endif

return 0;
}
#endif
Expand Down
35 changes: 34 additions & 1 deletion core/linux-dist/x11.cpp
Expand Up @@ -3,6 +3,7 @@
#include <X11/Xlib.h>
#include <X11/Xatom.h>
#include <X11/Xutil.h>
#include <iostream>

#if !defined(GLES)
#include <GL/gl.h>
Expand Down Expand Up @@ -37,6 +38,7 @@ int x11_height;
int ndcid = 0;
void* x11_glc;
bool x11_fullscreen = false;
Atom wmDeleteMessage;

void* x11_vis;

Expand Down Expand Up @@ -64,6 +66,23 @@ void x11_window_set_fullscreen(bool fullscreen)
XSendEvent((Display*)x11_disp, DefaultRootWindow((Display*)x11_disp), False, SubstructureNotifyMask, &xev);
}

void start_shutdown(void);

void event_x11_handle()
{
XEvent event;

while(XPending(x11_disp)) {
XNextEvent(x11_disp, &event);

if (event.type == ClientMessage &&
event.xclient.data.l[0] == wmDeleteMessage) {
printf("Caught window close event\n");
start_shutdown();
}
}
}

void input_x11_handle()
{
if (x11_win && x11_keyboard_input)
Expand All @@ -79,7 +98,7 @@ void input_x11_handle()
case KeyRelease:
if (e.type == KeyRelease && e.xkey.keycode == 9) // ESC button
{
die("death by escape key");
start_shutdown();
}
#if FEAT_HAS_NIXPROF
else if (e.type == KeyRelease && e.xkey.keycode == 76) // F10 button
Expand Down Expand Up @@ -254,6 +273,10 @@ void x11_window_create()
// Creates the X11 window
x11Window = XCreateWindow(x11Display, RootWindow(x11Display, x11Screen), (ndcid%3)*640, (ndcid/3)*480, x11_width, x11_height,
0, depth, InputOutput, x11Visual->visual, ui32Mask, &sWA);

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

if(x11_fullscreen)
{
Expand Down Expand Up @@ -320,8 +343,17 @@ void x11_window_set_text(const char* text)
}
}

void x11_gl_context_destroy()
{
printf("Destroy GL Context\n");
glXMakeCurrent((Display*)x11_disp, None, NULL);
glXDestroyContext((Display*)x11_disp, x11_glc);
}


void x11_window_destroy()
{
printf("Destroy X11 Window\n");
// close XWindow
if (x11_win)
{
Expand All @@ -334,4 +366,5 @@ void x11_window_destroy()
x11_disp = 0;
}
}

#endif
1 change: 1 addition & 0 deletions core/linux-dist/x11.h
Expand Up @@ -3,5 +3,6 @@
extern void* x11_glc;
extern void input_x11_init();
extern void input_x11_handle();
extern void event_x11_handle();
extern void x11_window_create();
extern void x11_window_set_text(const char* text);
17 changes: 13 additions & 4 deletions core/nullDC.cpp
Expand Up @@ -143,15 +143,24 @@ int dc_init(int argc,wchar* argv[])
webui_thd.Start();
#endif

if(ParseCommandLine(argc,argv))
{
return 69;
}
if(!cfgOpen())
{
msgboxf("Unable to open config file",MBX_ICONERROR);
return -4;
}

// Command line parsing moved after cfgopen as it allows
// the command line to make changes to the "settings" after
// they have been read. This helps with the NO_VIRTUAL_CFG
// option.
// After the command line has been parsed the settings are
// loaded using LoadSettings().

if(ParseCommandLine(argc,argv))
{
return 69;
}

LoadSettings();
#ifndef _ANDROID
os_CreateWindow();
Expand Down
14 changes: 13 additions & 1 deletion core/rec-ARM/ngen_arm.S
Expand Up @@ -170,8 +170,18 @@ do_iter:
mov r4,r0

.global CSYM(no_update)
.extern ngen_required
HIDDEN(no_update)
CSYM(no_update): @ next_pc _MUST_ be on r4 *R4 NOT R0 anymore*
CSYM(no_update): @ next_pc _MUST_ be on r4 *R4 NOT R0 anymore*

@ Note: I suspect that the exit thread routine
@ below is inefficient. If anyone is familiar
@ with asm please consider optimising!

ldr r3, =ngen_required @ load r3 with the address of c variable ngen_required
ldr r0,[r3] @ dereference and store in r0
cmp r0,#0 @ compare r0 with numerical value 0
beq CSYM(cleanup) @ if compare is true jump to cleanup label and exit thread

#if DC_PLATFORM == DC_PLATFORM_NAOMI
sub r2,r8,#0x4100000
Expand All @@ -185,6 +195,8 @@ CSYM(no_update): @ next_pc _MUST_ be on r4 *R4 NOT R0 anymore*
@bic r1,r4,#0xFF000000
@ldr pc,[r2,r1,lsl #1]

HIDDEN(cleanup)
CSYM(cleanup):

pop {r4-r12,lr}
bx lr
Expand Down
15 changes: 15 additions & 0 deletions core/rec-ARM/rec_arm.cpp
Expand Up @@ -2339,4 +2339,19 @@ RuntimeBlockInfo* ngen_AllocateBlock()
return new DynaRBI();
};

/* This is declared outside the #if so that any
the .s file will still build and run in an infinity
loop if ngen_terminate is not available */
unsigned int ngen_required = true;

#if HOST_OS==OS_LINUX

void ngen_terminate(void)
{
printf("ngen_terminate called\n");
ngen_required = false;
}

#endif

#endif
16 changes: 13 additions & 3 deletions core/rec-x64/rec_x64.cpp
Expand Up @@ -38,13 +38,15 @@ void ngen_FailedToFindBlock_internal() {

void(*ngen_FailedToFindBlock)() = &ngen_FailedToFindBlock_internal;

unsigned int ngen_required = true;

void ngen_mainloop(void* v_cntx)
{
Sh4RCB* ctx = (Sh4RCB*)((u8*)v_cntx - sizeof(Sh4RCB));

cycle_counter = 0;

for (;;) {
do{
cycle_counter = SH4_TIMESLICE;
do {
DynarecCodeEntryPtr rcb = bm_GetCode(ctx->cntx.pc);
Expand All @@ -54,8 +56,16 @@ void ngen_mainloop(void* v_cntx)
if (UpdateSystem()) {
rdv_DoInterrupts_pc(ctx->cntx.pc);
}
}
}while(ngen_required);
}

#if HOST_OS==OS_LINUX
void ngen_terminate()
{
ngen_required = false;
printf("ngen thread stopped\n");
}
#endif

void ngen_init()
{
Expand Down Expand Up @@ -474,4 +484,4 @@ void ngen_CC_Finish(shil_opcode* op)
{

}
#endif
#endif