[PANDORA] Add X11 32bits -> 16bits automatic conversion option

This commit is contained in:
ptitSeb 2019-08-15 15:08:14 +02:00
parent acedd159ad
commit f231f70d7f
6 changed files with 144 additions and 4 deletions

View File

@ -56,4 +56,9 @@ Try to load at 0xXXXXXX main binaray (if binary is a PIE)
#### BOX86_NOSIGSEGV
To disable handling of SigSEGV (to ease debugging mainly)
* 0 : default, let x86 program set sighandler for SEGV
* 1 : disable handling of SigSEGV
* 1 : disable handling of SigSEGV
#### BOX86_X11COLOR16
PANDORA only: to try convert X11 color from 32 bits to 16 bits (to avoid light green on light cyan windows
* 0 : default, don't touch X11 colors
* 1 : Change colors arguments in XSetForeground, XSetBackground and XCreateGC

View File

@ -34,6 +34,9 @@ int trace_xmm = 0;
#ifdef HAVE_TRACE
uint64_t start_cnt = 0;
#endif
#ifdef PANDORA
int x11color16 = 0;
#endif
FILE* ftrace = NULL;
@ -88,6 +91,16 @@ void LoadLogEnv()
dlsym_error = p[0]-'0';
}
}
#ifdef PANDORA
p = getenv("BOX86_X11COLOR16");
if(p) {
if(strlen(p)==1) {
if(p[0]>='0' && p[1]<='0'+1)
x11color16 = p[0]-'0';
}
printf_log(LOG_INFO, "Try to adjust X11 Color (32->16bits) : %s\n", x11color16?"Yes":"No");
}
#endif
}
void LoadEnvPath(path_collection_t *col, const char* defpath, const char* env)
@ -180,6 +193,9 @@ void PrintHelp() {
printf(" BOX86_DLSYM_ERROR with 1 to log dlsym errors\n");
printf(" BOX86_LOAD_ADDR=0xXXXXXX try to load at 0xXXXXXX main binaray (if binary is a PIE)\n");
printf(" BOX86_NOSIGSEGV=1 to disable handling of SigSEGV\n");
#ifdef PANDORA
printf(" BOX86_X11COLOR16=1 to try convert X11 color from 32 bits to 16 bits (to avoid light green on light cyan windows\n");
#endif
}
int main(int argc, const char **argv, const char **env) {

View File

@ -433,7 +433,6 @@ typedef void* (*pFpupu_t)(void*, uint32_t, void*, uint32_t);
typedef void* (*pFppii_t)(void*, void*, int32_t, int32_t);
typedef void* (*pFppip_t)(void*, void*, int32_t, void*);
typedef void* (*pFppuu_t)(void*, void*, uint32_t, uint32_t);
typedef void* (*pFppup_t)(void*, void*, uint32_t, void*);
typedef void* (*pFpppi_t)(void*, void*, void*, int32_t);
typedef void* (*pFpppu_t)(void*, void*, void*, uint32_t);
typedef void* (*pFpppp_t)(void*, void*, void*, void*);
@ -890,12 +889,20 @@ typedef uint32_t (*uFpppppppppppppppp_t)(void*, void*, void*, void*, void*, void
typedef void (*vFppuiiiiipuiiiiiiii_t)(void*, void*, uint32_t, int32_t, int32_t, int32_t, int32_t, int32_t, void*, uint32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t);
typedef void* (*pFipppppppppppppppppppppp_t)(int32_t, void*, void*, void*, void*, void*, void*, void*, void*, void*, void*, void*, void*, void*, void*, void*, void*, void*, void*, void*, void*, void*, void*);
#if defined(PANDORA)
typedef void* (*pFEppup_t)(x86emu_t*, void*, void*, uint32_t, void*);
#endif
#if defined(NOALIGN)
typedef int64_t (*IFpi_t)(void*, int32_t);
typedef double (*dFpi_t)(void*, int32_t);
typedef int32_t (*iFppiiiip_t)(void*, void*, int32_t, int32_t, int32_t, int32_t, void*);
#endif
#if !defined(PANDORA)
typedef void* (*pFppup_t)(void*, void*, uint32_t, void*);
#endif
#if !defined(NOALIGN)
typedef double (*dFEp_t)(x86emu_t*, void*);
typedef int32_t (*iFEpI_t)(x86emu_t*, void*, int64_t);
@ -1332,7 +1339,6 @@ void pFpupu(x86emu_t *emu, uintptr_t fcn) { pFpupu_t fn = (pFpupu_t)fcn; R_EAX=(
void pFppii(x86emu_t *emu, uintptr_t fcn) { pFppii_t fn = (pFppii_t)fcn; R_EAX=(uintptr_t)fn(*(void**)(R_ESP + 4), *(void**)(R_ESP + 8), *(int32_t*)(R_ESP + 12), *(int32_t*)(R_ESP + 16)); }
void pFppip(x86emu_t *emu, uintptr_t fcn) { pFppip_t fn = (pFppip_t)fcn; R_EAX=(uintptr_t)fn(*(void**)(R_ESP + 4), *(void**)(R_ESP + 8), *(int32_t*)(R_ESP + 12), *(void**)(R_ESP + 16)); }
void pFppuu(x86emu_t *emu, uintptr_t fcn) { pFppuu_t fn = (pFppuu_t)fcn; R_EAX=(uintptr_t)fn(*(void**)(R_ESP + 4), *(void**)(R_ESP + 8), *(uint32_t*)(R_ESP + 12), *(uint32_t*)(R_ESP + 16)); }
void pFppup(x86emu_t *emu, uintptr_t fcn) { pFppup_t fn = (pFppup_t)fcn; R_EAX=(uintptr_t)fn(*(void**)(R_ESP + 4), *(void**)(R_ESP + 8), *(uint32_t*)(R_ESP + 12), *(void**)(R_ESP + 16)); }
void pFpppi(x86emu_t *emu, uintptr_t fcn) { pFpppi_t fn = (pFpppi_t)fcn; R_EAX=(uintptr_t)fn(*(void**)(R_ESP + 4), *(void**)(R_ESP + 8), *(void**)(R_ESP + 12), *(int32_t*)(R_ESP + 16)); }
void pFpppu(x86emu_t *emu, uintptr_t fcn) { pFpppu_t fn = (pFpppu_t)fcn; R_EAX=(uintptr_t)fn(*(void**)(R_ESP + 4), *(void**)(R_ESP + 8), *(void**)(R_ESP + 12), *(uint32_t*)(R_ESP + 16)); }
void pFpppp(x86emu_t *emu, uintptr_t fcn) { pFpppp_t fn = (pFpppp_t)fcn; R_EAX=(uintptr_t)fn(*(void**)(R_ESP + 4), *(void**)(R_ESP + 8), *(void**)(R_ESP + 12), *(void**)(R_ESP + 16)); }
@ -1789,12 +1795,20 @@ void uFpppppppppppppppp(x86emu_t *emu, uintptr_t fcn) { uFpppppppppppppppp_t fn
void vFppuiiiiipuiiiiiiii(x86emu_t *emu, uintptr_t fcn) { vFppuiiiiipuiiiiiiii_t fn = (vFppuiiiiipuiiiiiiii_t)fcn; fn(*(void**)(R_ESP + 4), *(void**)(R_ESP + 8), *(uint32_t*)(R_ESP + 12), *(int32_t*)(R_ESP + 16), *(int32_t*)(R_ESP + 20), *(int32_t*)(R_ESP + 24), *(int32_t*)(R_ESP + 28), *(int32_t*)(R_ESP + 32), *(void**)(R_ESP + 36), *(uint32_t*)(R_ESP + 40), *(int32_t*)(R_ESP + 44), *(int32_t*)(R_ESP + 48), *(int32_t*)(R_ESP + 52), *(int32_t*)(R_ESP + 56), *(int32_t*)(R_ESP + 60), *(int32_t*)(R_ESP + 64), *(int32_t*)(R_ESP + 68), *(int32_t*)(R_ESP + 72)); }
void pFipppppppppppppppppppppp(x86emu_t *emu, uintptr_t fcn) { pFipppppppppppppppppppppp_t fn = (pFipppppppppppppppppppppp_t)fcn; R_EAX=(uintptr_t)fn(*(int32_t*)(R_ESP + 4), *(void**)(R_ESP + 8), *(void**)(R_ESP + 12), *(void**)(R_ESP + 16), *(void**)(R_ESP + 20), *(void**)(R_ESP + 24), *(void**)(R_ESP + 28), *(void**)(R_ESP + 32), *(void**)(R_ESP + 36), *(void**)(R_ESP + 40), *(void**)(R_ESP + 44), *(void**)(R_ESP + 48), *(void**)(R_ESP + 52), *(void**)(R_ESP + 56), *(void**)(R_ESP + 60), *(void**)(R_ESP + 64), *(void**)(R_ESP + 68), *(void**)(R_ESP + 72), *(void**)(R_ESP + 76), *(void**)(R_ESP + 80), *(void**)(R_ESP + 84), *(void**)(R_ESP + 88), *(void**)(R_ESP + 92)); }
#if defined(PANDORA)
void pFEppup(x86emu_t *emu, uintptr_t fcn) { pFEppup_t fn = (pFEppup_t)fcn; R_EAX=(uintptr_t)fn(emu, *(void**)(R_ESP + 4), *(void**)(R_ESP + 8), *(uint32_t*)(R_ESP + 12), *(void**)(R_ESP + 16)); }
#endif
#if defined(NOALIGN)
void IFpi(x86emu_t *emu, uintptr_t fcn) { IFpi_t fn = (IFpi_t)fcn; ui64_t r; r.i=fn(*(void**)(R_ESP + 4), *(int32_t*)(R_ESP + 8)); R_EAX=r.d[0]; R_EDX=r.d[1]; }
void dFpi(x86emu_t *emu, uintptr_t fcn) { dFpi_t fn = (dFpi_t)fcn; double db=fn(*(void**)(R_ESP + 4), *(int32_t*)(R_ESP + 8)); fpu_do_push(emu); ST0val = db; }
void iFppiiiip(x86emu_t *emu, uintptr_t fcn) { iFppiiiip_t fn = (iFppiiiip_t)fcn; R_EAX=fn(*(void**)(R_ESP + 4), *(void**)(R_ESP + 8), *(int32_t*)(R_ESP + 12), *(int32_t*)(R_ESP + 16), *(int32_t*)(R_ESP + 20), *(int32_t*)(R_ESP + 24), *(void**)(R_ESP + 28)); }
#endif
#if !defined(PANDORA)
void pFppup(x86emu_t *emu, uintptr_t fcn) { pFppup_t fn = (pFppup_t)fcn; R_EAX=(uintptr_t)fn(*(void**)(R_ESP + 4), *(void**)(R_ESP + 8), *(uint32_t*)(R_ESP + 12), *(void**)(R_ESP + 16)); }
#endif
#if !defined(NOALIGN)
void dFEp(x86emu_t *emu, uintptr_t fcn) { dFEp_t fn = (dFEp_t)fcn; double db=fn(emu, *(void**)(R_ESP + 4)); fpu_do_push(emu); ST0val = db; }
void iFEpI(x86emu_t *emu, uintptr_t fcn) { iFEpI_t fn = (iFEpI_t)fcn; R_EAX=fn(emu, *(void**)(R_ESP + 4), *(int64_t*)(R_ESP + 8)); }

View File

@ -432,7 +432,6 @@ void pFpupu(x86emu_t *emu, uintptr_t fnc);
void pFppii(x86emu_t *emu, uintptr_t fnc);
void pFppip(x86emu_t *emu, uintptr_t fnc);
void pFppuu(x86emu_t *emu, uintptr_t fnc);
void pFppup(x86emu_t *emu, uintptr_t fnc);
void pFpppi(x86emu_t *emu, uintptr_t fnc);
void pFpppu(x86emu_t *emu, uintptr_t fnc);
void pFpppp(x86emu_t *emu, uintptr_t fnc);
@ -889,12 +888,20 @@ void uFpppppppppppppppp(x86emu_t *emu, uintptr_t fnc);
void vFppuiiiiipuiiiiiiii(x86emu_t *emu, uintptr_t fnc);
void pFipppppppppppppppppppppp(x86emu_t *emu, uintptr_t fnc);
#if defined(PANDORA)
void pFEppup(x86emu_t *emu, uintptr_t fnc);
#endif
#if defined(NOALIGN)
void IFpi(x86emu_t *emu, uintptr_t fnc);
void dFpi(x86emu_t *emu, uintptr_t fnc);
void iFppiiiip(x86emu_t *emu, uintptr_t fnc);
#endif
#if !defined(PANDORA)
void pFppup(x86emu_t *emu, uintptr_t fnc);
#endif
#if !defined(NOALIGN)
void dFEp(x86emu_t *emu, uintptr_t fnc);
void iFEpI(x86emu_t *emu, uintptr_t fnc);

View File

@ -95,9 +95,11 @@ typedef void* (*pFpp_t)(void*, void*);
typedef void* (*pFpip_t)(void*, int32_t, void*);
typedef int32_t (*iFp_t)(void*);
typedef int32_t (*iFpi_t)(void*, int32_t);
typedef int32_t (*iFppu_t)(void*, void*, uint32_t);
typedef int32_t (*iFpppp_t)(void*, void*, void*, void*);
typedef uint32_t (*uFpii_t)(void*, int32_t, int32_t);
typedef int32_t (*iFpiiu_t)(void*, int32_t, int32_t, uint32_t);
typedef void* (*pFppup_t)(void*, void*, uint32_t, void*);
typedef void* (*pFpiiuu_t)(void*, int32_t, int32_t, uint32_t, uint32_t);
typedef void* (*pFppiiuuui_t)(void*, void*, int32_t, int32_t, uint32_t, uint32_t, uint32_t, int32_t);
typedef void* (*pFppuiipuuii_t)(void*, void*, uint32_t, int32_t, int32_t, void*, uint32_t, uint32_t, int32_t, int32_t);
@ -120,6 +122,9 @@ typedef struct x11_my_s {
vFp_t XDestroyImage;
#ifdef PANDORA
pFpp_t XLoadQueryFont;
pFppup_t XCreateGC;
iFppu_t XSetBackground;
iFppu_t XSetForeground;
#endif
} x11_my_t;
@ -141,6 +146,9 @@ void* getX11My(library_t* lib)
GO(XDestroyImage, vFp_t)
#ifdef PANDORA
GO(XLoadQueryFont, pFpp_t)
GO(XCreateGC, pFppup_t)
GO(XSetBackground, iFppu_t)
GO(XSetForeground, iFppu_t)
#endif
#undef GO
return my;
@ -512,4 +520,82 @@ EXPORT void* my_XLoadQueryFont(x86emu_t* emu, void* d, void* name)
return my->XLoadQueryFont(d, "6x13B");
return my->XLoadQueryFont(d, name);
}
extern int x11color16;
static uint32_t recode32to16(uint32_t c)
{
uint32_t r, g, b;
r = (c>>16)&0xff;
g = (c>>8)&0xff;
b = (c>>0)&0xff;
return ((r>>3)<<11) | ((g>>2)<<5) | ((b>>3));
}
EXPORT int32_t my_XSetBackground(x86emu_t* emu, void* d, void* gc, uint32_t c)
{
library_t * lib = GetLib(emu->context->maplib, libx11Name);
x11_my_t *my = (x11_my_t*)lib->priv.w.p2;
if(x11color16)
c = recode32to16(c);
return my->XSetBackground(d, gc, c);
}
EXPORT int32_t my_XSetForeground(x86emu_t* emu, void* d, void* gc, uint32_t c)
{
library_t * lib = GetLib(emu->context->maplib, libx11Name);
x11_my_t *my = (x11_my_t*)lib->priv.w.p2;
if(x11color16)
c = recode32to16(c);
return my->XSetForeground(d, gc, c);
}
typedef struct XGCValues_s {
int32_t function;
uint32_t plane_mask;
uint32_t foreground;
uint32_t background;
int32_t line_width;
int32_t line_style;
int32_t cap_style;
int32_t join_style;
int32_t fill_style;
int32_t fill_rule;
int32_t arc_mode;
void* tile;
void* stipple;
int32_t ts_x_origin;
int32_t ts_y_origin;
void* font;
int32_t subwindow_mode;
int graphics_exposures;
int32_t clip_x_origin;
int32_t clip_y_origin;
void* clip_mask;
int32_t dash_offset;
char dashes;
} XGCValues_t;
EXPORT void* my_XCreateGC(x86emu_t *emu, void* disp, void* d, uint32_t v, void* vs)
{
library_t * lib = GetLib(emu->context->maplib, libx11Name);
x11_my_t *my = (x11_my_t*)lib->priv.w.p2;
int setfore = 0;
int setback = 0;
uint32_t fore = 0;
uint32_t back = 0;
XGCValues_t *values = (XGCValues_t*)vs;
if(v&(1<<2)) {
setfore = 1;
fore = values->foreground;
}
if(v&(1<<3)) {
setback = 1;
back = values->background;
}
void* gc = my->XCreateGC(disp, d, v, vs);
if(x11color16) {
if(setfore)
my->XSetForeground(disp, gc, recode32to16(fore));
if(setback)
my->XSetBackground(disp, gc, recode32to16(back));
}
return gc;
}
#endif

View File

@ -223,7 +223,11 @@ GO(XCreateBitmapFromData, pFpppuu)
GO(XCreateColormap, uFpppi)
GO(XCreateFontCursor, pFpu)
GO(XCreateFontSet, pFppppp)
#ifdef PANDORA
GOM(XCreateGC, pFEppup)
#else
GO(XCreateGC, pFppup)
#endif
//GO(XCreateGlyphCursor
GO(XCreateIC, uFpppppppppppppppp) // use vararg, so putting an arbitrary number of args, also can have Callbacks ?! Allegro have 7 args and no callback
GOM(XCreateImage, pFEppuiipuuii)
@ -926,7 +930,11 @@ GO(XSetAccessControl, iFpi)
//GO(XSetAfterFunction
GO(XSetArcMode, iFppi)
//GO(XSetAuthorization
#ifdef PANDORA
GOM(XSetBackground, iFEppu)
#else
GO(XSetBackground, iFppu)
#endif
GO(XSetClassHint, iFppp)
GO(XSetClipMask, iFppp)
GO(XSetClipOrigin, iFppii)
@ -940,7 +948,11 @@ GO(XSetFillRule, iFppi)
GO(XSetFillStyle, iFppp)
GO(XSetFont, iFppp)
GO(XSetFontPath, iFppi)
#ifdef PANDORA
GOM(XSetForeground, iFEppu)
#else
GO(XSetForeground, iFppu)
#endif
GO(XSetFunction, iFppi)
GO(XSetGraphicsExposures, iFppu)
GO(XSetICFocus, vFu)