linux-dist: Fix indentation and reformat code

This commit is contained in:
Jan Holthuis 2015-08-12 01:57:29 +02:00
parent 5fbfc0fb8b
commit ab33f473b3
1 changed files with 691 additions and 645 deletions

View File

@ -19,8 +19,6 @@
#include <emscripten.h>
#endif
#if defined(SUPPORT_X11)
#include <X11/Xlib.h>
#include <X11/Xatom.h>
@ -45,14 +43,15 @@
#include <signal.h>
#include <execinfo.h>
#include <sys/soundcard.h>
#define WINDOW_WIDTH 800
#else
#define WINDOW_WIDTH 640
#endif
#define WINDOW_HEIGHT 480
void* x11_win=0,* x11_disp=0;
void* x11_win = 0;
void* x11_disp = 0;
void* libPvr_GetRenderTarget()
{
return x11_win;
@ -84,7 +83,8 @@ u32 vks[4];
s8 joyx[4],joyy[4];
u8 rt[4],lt[4];
enum DCPad {
enum DCPad
{
Btn_C = 1,
Btn_B = 1<<1,
Btn_A = 1<<2,
@ -150,9 +150,11 @@ void SetupInput()
char name[256]= "Unknown";
if ((kbfd = open(device, O_RDONLY)) > 0) {
if ((kbfd = open(device, O_RDONLY)) > 0)
{
fcntl(kbfd, F_SETFL, O_NONBLOCK);
if(ioctl(kbfd, EVIOCGNAME(sizeof(name)), name) < 0) {
if(ioctl(kbfd, EVIOCGNAME(sizeof(name)), name) < 0)
{
perror("evdev ioctl");
}
@ -193,15 +195,17 @@ void SetupInput()
#endif
}
bool HandleKb(u32 port) {
bool HandleKb(u32 port)
{
#if HOST_OS != OS_DARWIN && !defined(TARGET_EMSCRIPTEN)
if (kbfd < 0)
{
return false;
}
input_event ie;
#if defined(TARGET_GCW0)
#define KEY_A 0x1D
#define KEY_B 0x38
#define KEY_X 0x2A
@ -217,10 +221,13 @@ bool HandleKb(u32 port) {
#define KEY_LOCK 0x77 // Note that KEY_LOCK is a switch and remains pressed until it's switched back
static int keys[13];
while(read(kbfd,&ie,sizeof(ie))==sizeof(ie)) {
while(read(kbfd, &ie, sizeof(ie)) == sizeof(ie))
{
//printf("type %i key %i state %i\n", ie.type, ie.code, ie.value);
if (ie.type = EV_KEY)
switch (ie.code) {
{
switch (ie.code)
{
case KEY_SELECT: keys[ 9] = ie.value; break;
case KEY_UP: keys[ 1] = ie.value; break;
case KEY_DOWN: keys[ 2] = ie.value; break;
@ -233,6 +240,7 @@ bool HandleKb(u32 port) {
case KEY_START: keys[12] = ie.value; break;
}
}
}
if (keys[ 6]) { kcode[port] &= ~Btn_A; }
if (keys[ 7]) { kcode[port] &= ~Btn_B; }
if (keys[ 5]) { kcode[port] &= ~Btn_Y; }
@ -243,14 +251,15 @@ bool HandleKb(u32 port) {
if (keys[ 4]) { kcode[port] &= ~DPad_Right; }
if (keys[12]) { kcode[port] &= ~Btn_Start; }
if (keys[ 9]) { die("death by escape key"); }
if (keys[10]) rt[port]=255;
if (keys[11]) lt[port]=255;
if (keys[10]) { rt[port] = 255; }
if (keys[11]) { lt[port] = 255; }
return true;
#elif defined(TARGET_PANDORA)
static int keys[13];
while(read(kbfd,&ie,sizeof(ie))==sizeof(ie)) {
while(read(kbfd,&ie,sizeof(ie))==sizeof(ie))
{
if (ie.type=EV_KEY)
//printf("type %i key %i state %i\n", ie.type, ie.code, ie.value);
switch (ie.code) {
@ -281,24 +290,27 @@ bool HandleKb(u32 port) {
if (keys[ 4]) { kcode[port] &= ~DPad_Right; }
if (keys[12]) { kcode[port] &= ~Btn_Start; }
if (keys[ 9]) { die("death by escape key"); }
if (keys[10]) rt[port]=255;
if (keys[11]) lt[port]=255;
if (keys[10]) { rt[port] = 255; }
if (keys[11]) { lt[port] = 255; }
return true;
#else
while(read(kbfd,&ie,sizeof(ie))==sizeof(ie)) {
while(read(kbfd, &ie, sizeof(ie)) == sizeof(ie))
{
printf("type %i key %i state %i\n", ie.type, ie.code, ie.value);
}
#endif
#endif
return true;
}
bool HandleJoystick(u32 port)
{
// Joystick must be connected
if(JoyFD<0) return false;
if(JoyFD < 0) {
return false;
}
#if HOST_OS != OS_DARWIN && !defined(TARGET_EMSCRIPTEN)
struct js_event JE;
@ -332,24 +344,33 @@ bool HandleJoystick(u32 port)
}
else if (mt == 1)
{
if (v>=0) v++; //up to 255
if (v >= 0)
{
v++; //up to 255
}
//printf("AXIS %d,%d Mapped to %d %d %d\n",JE.number,JE.value,mo,v,v+127);
if (mo == 0)
lt[port]=v+127;
{
lt[port] = (v + 127);
}
else if (mo == 1)
rt[port]=v+127;
{
rt[port] = (v + 127);
}
}
else if (mt == 2)
{
// printf("AXIS %d,%d Mapped to %d %d [%d]",JE.number,JE.value,mo,v);
if (mo == 0)
{
joyx[port] = v;
}
else if (mo == 1)
{
joyy[port] = v;
}
}
}
break;
case JS_EVENT_BUTTON:
@ -363,26 +384,33 @@ bool HandleJoystick(u32 port)
{
// printf("Mapped to %d\n",mo);
if (JE.value)
{
kcode[port] &= ~mo;
}
else
{
kcode[port] |= mo;
}
}
else if (mt==1)
{
// printf("Mapped to %d %d\n",mo,JE.value?255:0);
if (mo==0)
{
lt[port] = JE.value ? 255 : 0;
}
else if (mo==1)
{
rt[port] = JE.value ? 255 : 0;
}
}
}
break;
}
}
#endif
return true;
return true;
}
extern bool KillTex;
@ -431,13 +459,14 @@ void UpdateInputState(u32 port)
#if defined(TARGET_GCW0) || defined(TARGET_PANDORA)
return;
#endif
for(;;)
{
key = 0;
read(STDIN_FILENO, &key, 1);
if (0 == key || EOF == key) break;
if ('k' == key) KillTex=true;
if (0 == key || EOF == key) { break; }
if ('k' == key) { KillTex=true; }
#ifdef TARGET_PANDORA
if (' ' == key) { kcode[port] &= ~Btn_C; }
@ -454,13 +483,18 @@ return;
#endif
//if (0x1b == key){ die("death by escape key"); } //this actually quits when i press left for some reason
if ('a' == key) rt[port]=255;
if ('s' == key) lt[port]=255;
if ('a' == key) { rt[port] = 255; }
if ('s' == key) { lt[port] = 255; }
#if FEAT_SHREC != DYNAREC_NONE
if ('b' == key) emit_WriteCodeCache();
if ('n' == key) bm_Reset();
if ('m' == key) bm_Sort();
if (',' == key) { emit_WriteCodeCache(); bm_Sort(); }
if ('b' == key) { emit_WriteCodeCache(); }
if ('n' == key) { bm_Reset(); }
if ('m' == key) { bm_Sort(); }
if (',' == key)
{
emit_WriteCodeCache();
bm_Sort();
}
#endif
}
}
@ -468,23 +502,28 @@ return;
void os_DoEvents()
{
#if defined(SUPPORT_X11)
if (x11_win) {
if (x11_win)
{
//Handle X11
XEvent e;
if(XCheckWindowEvent((Display*)x11_disp, (Window)x11_win, KeyPressMask | KeyReleaseMask, &e))
{
switch(e.type)
{
case KeyPress:
case KeyRelease:
{
int dc_key = x11_keymap[e.xkey.keycode];
if (e.type == KeyPress)
{
x11_dc_buttons &= ~dc_key;
}
else
{
x11_dc_buttons |= dc_key;
}
//printf("KEY: %d -> %d: %d\n",e.xkey.keycode, dc_key, x11_dc_buttons );
}
@ -505,9 +544,12 @@ void os_DoEvents()
void os_SetWindowText(const char * text)
{
if (0==x11_win || 0==x11_disp || 1)
{
printf("%s\n",text);
}
#if defined(SUPPORT_X11)
else if (x11_win) {
else if (x11_win)
{
XChangeProperty((Display*)x11_disp, (Window)x11_win,
XInternAtom((Display*)x11_disp, "WM_NAME", False), //WM_NAME,
XInternAtom((Display*)x11_disp, "UTF8_STRING", False), //UTF8_STRING,
@ -641,6 +683,7 @@ void os_CreateWindow()
// Creates the X11 window
x11Window = XCreateWindow(x11Display, RootWindow(x11Display, x11Screen), (ndcid%3)*640, (ndcid/3)*480, width, height,
0, depth, InputOutput, x11Visual->visual, ui32Mask, &sWA);
#ifdef TARGET_PANDORA
// fullscreen
Atom wmState = XInternAtom(x11Display, "_NET_WM_STATE", False);
@ -652,18 +695,15 @@ void os_CreateWindow()
XMapWindow(x11Display, x11Window);
#if !defined(GLES)
#define GLX_CONTEXT_MAJOR_VERSION_ARB 0x2091
#define GLX_CONTEXT_MINOR_VERSION_ARB 0x2092
typedef GLXContext (*glXCreateContextAttribsARBProc)(Display*, GLXFBConfig, GLXContext, Bool, const int*);
glXCreateContextAttribsARBProc glXCreateContextAttribsARB = 0;
glXCreateContextAttribsARB = (glXCreateContextAttribsARBProc)
glXGetProcAddressARB( (const GLubyte *) "glXCreateContextAttribsARB" );
glXCreateContextAttribsARB = (glXCreateContextAttribsARBProc)glXGetProcAddressARB((const GLubyte*)"glXCreateContextAttribsARB");
verify(glXCreateContextAttribsARB != 0);
int context_attribs[] = {
int context_attribs[] =
{
GLX_CONTEXT_MAJOR_VERSION_ARB, 3,
GLX_CONTEXT_MINOR_VERSION_ARB, 1,
GLX_CONTEXT_FLAGS_ARB, GLX_CONTEXT_DEBUG_BIT_ARB,
@ -674,21 +714,23 @@ void os_CreateWindow()
x11_glc = glXCreateContextAttribsARB(x11Display, bestFbc, 0, True, context_attribs);
XSync(x11Display, False);
if (!x11_glc) {
if (!x11_glc)
{
die("Failed to create GL3.1 context\n");
}
#endif
#endif
XFlush(x11Display);
//(EGLNativeDisplayType)x11Display;
x11_disp = (void*)x11Display;
x11_win = (void*)x11Window;
}
else
{
printf("Not creating X11 window ..\n");
}
#endif
}
@ -741,30 +783,36 @@ void dc_run();
#ifdef TARGET_PANDORA
void gl_term();
void clean_exit(int sig_num) {
void clean_exit(int sig_num)
{
void* array[10];
size_t size;
// close files
if (JoyFD>=0) close(JoyFD);
if (kbfd>=0) close(kbfd);
if (JoyFD >= 0) { close(JoyFD); }
if (kbfd >= 0) { close(kbfd); }
// Close EGL context ???
if (sig_num!=0)
{
gl_term();
}
// close XWindow
if (x11_win) {
if (x11_win)
{
XDestroyWindow(x11_disp, x11_win);
x11_win = 0;
}
if (x11_disp) {
if (x11_disp)
{
XCloseDisplay(x11_disp);
x11_disp = 0;
}
// finish cleaning
if (sig_num!=0) {
if (sig_num!=0)
{
write(2, "\nSignal received\n", sizeof("\nSignal received\n"));
size = backtrace(array, 10);
@ -772,20 +820,20 @@ void clean_exit(int sig_num) {
exit(1);
}
}
#endif
int main(int argc, wchar* argv[])
{
//if (argc==2)
//ndcid=atoi(argv[1]);
if (setup_curses() < 0) printf("failed to setup curses!\n");
if (setup_curses() < 0)
{
printf("failed to setup curses!\n");
}
#ifdef TARGET_PANDORA
signal(SIGSEGV, clean_exit);
signal(SIGKILL, clean_exit);
#endif
/* Set home dir */
string home = ".";
#if defined(USES_HOMEDIR)
if(getenv("HOME") != NULL)
@ -839,13 +887,11 @@ int main(int argc, wchar* argv[])
return 0;
}
#endif
int get_mic_data(u8* buffer) { return 0; }
int push_vmu_screen(u8* buffer) { return 0; }
void os_DebugBreak()
{
#if !defined(TARGET_EMSCRIPTEN)