Marcus Sundberg wrote:
> Jay <[EMAIL PROTECTED]> writes:
>
> > Well, then what I'm doing is extreemly wrong. But if I do it any other way I get
> > a segfault. On the console I must do this to get anything to work:
> >
> > giiInit();
> > kbd=giiOpen("input-linux-kbd",NULL);
> > if (kbd==NULL) {
> > fprintf(stderr, "Error getting keyboard, bailing out...");
> > exit(1);
> > }
>
> I suspected something like this. You can't open input-linux-kbd
> if you are using LibGGI. And I still can't help you unless I know
> what your code looks like and what you are trying to achieve.
I can't show everything just yet, but here is what I can. This is all of the gii
stuff:
void S9xDeinitDisplay ()
{
S9xTextMode ();
if (GFX.Screen) free ((uint8 *) GFX.Screen);
if (GFX.SubScreen) free ((uint8 *) GFX.SubScreen);
if (GFX.ZBuffer) free ((uint8 *) GFX.ZBuffer);
if (GFX.SubZBuffer) free ((uint8 *) GFX.SubZBuffer);
GFX.Screen = NULL;
GFX.SubScreen = NULL;
GFX.ZBuffer = NULL;
GFX.SubZBuffer = NULL;
/* giiClose(inp);
giiExit(); */ /* If you close inp and call giiExit,
My system's keyboard screws up */
ggiClose(vis);
ggiExit();
sleep(1); /* Wait for another thread */
}
void S9xInitDisplay (int, char **)
{
unsigned int i, imagesize;
Settings.Transparency = TRUE;
Settings.SixteenBit = TRUE;
Settings.SupportHiRes = TRUE;
RenderRes = 0;
ShowFPS = FALSE;
S9xSetRenderPixelFormat (RGB555);
GFX.Pitch = 512 * 2;
imagesize=GFX.Pitch * 478;
GFX.Screen = (uint8 *) malloc (imagesize);
GFX.SubScreen = (uint8 *) malloc (imagesize);
GFX.ZBuffer = (uint8 *) malloc (imagesize);
GFX.SubZBuffer = (uint8 *) malloc (imagesize);
GFX.Delta = (GFX.SubScreen - GFX.Screen) >> 1;
/* This is where I have to do stuff wrong or my keyboard doesn't work
Keep in mind I am useing the SVGALIB target; it might be the problem */
giiInit();
inp=giiOpen("input-null", NULL);
if (inp==NULL) {
fprintf(stderr, "Error in input libgii, bailing out...");
S9xExit();
}
kbd=giiOpen("input-linux-kbd",NULL);
if (kbd==NULL) {
fprintf(stderr, "Error getting keyboard, bailing out...");
S9xExit();
}
mouse=giiOpen("input-linux-mouse",NULL);
/* I don't think the mouse has ever accually worked */
if (mouse==NULL) {
fprintf(stderr, "Error getting mouse, oh well...");
inp=giiJoinInputs(inp, kbd);
} else {
inp=giiJoinInputs(inp, kbd);
inp=giiJoinInputs(inp, mouse);
}
ggiInit();
vis=ggiOpen(NULL);
if (vis==NULL) {
fprintf(stderr, "Error getting visual");
S9xExit();
}
/* Fill all the buffers with zeros */
for(i=0;i<imagesize;i++)
{
GFX.Screen[i] = 0;
GFX.SubScreen[i] = 0;
GFX.ZBuffer[i] = 0;
GFX.SubZBuffer[i] = 0;
}
}
bool8 S9xReadMousePosition (int which1, int &x, int &y, uint32 &buttons)
{
if (which1 == 0)
{
x = mouse_x;
y = mouse_y;
buttons = mouse_buttons;
return (TRUE);
}
return (FALSE);
}
bool8 S9xReadSuperScopePosition (int &x, int &y, uint32 &buttons)
{
x = mouse_x;
y = mouse_y;
buttons = (mouse_buttons & 3) | (superscope_turbo << 2) |
(superscope_pause << 3);
return (TRUE);
}
void S9xGraphicsMode ()
{
if (RenderRes)
{
halfxres=640/2;
halfyres=480/2;
if (ggiSetGraphMode(vis, 640, 480, 640, 480, GT_32BIT)) {
fprintf(stderr, "Error getting visual");
S9xExit();
}
} else {
halfxres=320/2;
halfyres=240/2;
if (ggiSetGraphMode(vis, 320, 240, 320, 240, GT_32BIT)) {
fprintf(stderr, "Error getting visual");
S9xExit();
}
}
}
void S9xProcessEvents (bool8 block)
{
gii_event ev;
struct timeval tv = {0,0};
gii_event_mask mask;
uint32 keysym;
if ((!block) && ((mask=giiEventPoll(inp, emAll, &tv))==0)) {
return;
}
do {
giiEventRead(inp, &ev, emAll);
uint8 byte1 = 0;
uint8 byte2 = 0;
uint8 byte3 = 0;
uint8 byte4 = 0;
switch(ev.any.type) {
case evKeyRepeat:
break;
case evKeyPress:
case evKeyRelease:
keysym = ev.key.sym;
switch ( keysym) {
case 'k':
case GIIK_Right: byte2 = 1; break;
case 'h':
case GIIK_Left: byte2 = 2; break;
case 'j':
case 'n':
case GIIK_Down: byte2 = 4; break;
case 'u':
case GIIK_Up: byte2 = 8; break;
case GIIK_Enter: byte2 = 16; break; // Start
case ' ': byte2 = 32; break; // Select
case '.':
case 't':
case 'd': byte1 = 128; break; // A
case '/':
case 'y':
case 'c': byte2 = 128; break; // B
case 'm':
case 'e':
case 's': byte1 = 64; break; // X
case ',':
case 'r':
case 'x': byte2 = 64; break; // Y
case 'v':
case 'q':
case 'a': byte1 = 32; break; // TL
case 'b':
case 'w':
case 'z': byte1 = 16; break; // TR
case GIIK_P4: byte4 = 1; break;
case GIIK_P6: byte4 = 2; break;
case GIIK_P2: byte4 = 4; break;
case GIIK_P8: byte4 = 8; break;
case GIIK_PEnter: byte4 = 16; break; // Start
case GIIK_PPlus: byte4 = 32; break; // Select
case GIIK_PageDown: byte3 = 128; break; // A
case GIIK_PageUp: byte4 = 128; break; // B
case GIIK_Home: byte3 = 64; break; // X
case GIIK_End: byte4 = 64; break; // Y
case GIIK_Insert: byte3 = 32; break; // TL
case GIIK_Delete: byte3 = 16; break; // TR
case 27: S9xExit (); break;
case '0':
if (ev.any.type == evKeyPress)
Settings.DisableHDMA = !Settings.DisableHDMA;
break;
case '1':
if (ev.any.type == evKeyPress)
PPU.BG_Forced ^= 1;
if (PPU.BG_Forced & 1) S9xSetInfoString ("Graphic Layer 1 Disabled");
else S9xSetInfoString ("Graphic Layer 1 Enabled");
break;
case '2':
if (ev.any.type == evKeyPress)
PPU.BG_Forced ^= 2;
if (PPU.BG_Forced & 2) S9xSetInfoString ("Graphic Layer 2 Disabled");
else S9xSetInfoString ("Graphic Layer 2 Enabled");
break;
case '3':
if (ev.any.type == evKeyPress)
PPU.BG_Forced ^= 4;
if (PPU.BG_Forced & 4) S9xSetInfoString ("Graphic Layer 3 Disabled");
else S9xSetInfoString ("Graphic Layer 3 Enabled");
break;
case '4':
if (ev.any.type == evKeyPress)
PPU.BG_Forced ^= 8;
if (PPU.BG_Forced & 8) S9xSetInfoString ("Graphic Layer 4 Disabled");
else S9xSetInfoString ("Graphic Layer 4 Enabled");
break;
case '5':
if (ev.any.type == evKeyPress)
PPU.BG_Forced ^= 16;
if (PPU.BG_Forced & 16) S9xSetInfoString ("Graphic Layer 5 Disabled");
else S9xSetInfoString ("Graphic Layer 5 Enabled");
break;
case '6':
if (ev.any.type == evKeyPress)
Settings.SwapJoypads = !Settings.SwapJoypads;
if (Settings.SwapJoypads) S9xSetInfoString ("Joypads swapped");
else S9xSetInfoString ("Joypads swapped back to normal");
break;
case '9':
if (ev.any.type == evKeyPress)
if (Settings.SixteenBit)
Settings.Transparency = !Settings.Transparency;
break;
case '8':
if (ev.any.type == evKeyPress)
Settings.BGLayering = !Settings.BGLayering;
break;
case '7':
if (ev.any.type == evKeyPress)
S9xNextController ();
if (IPPU.Controller == 0) S9xSetInfoString ("Multiplayer 5 on #0");
if (IPPU.Controller == 1) S9xSetInfoString ("Joypad on #0");
if (IPPU.Controller == 2) S9xSetInfoString ("Mouse on #1");
if (IPPU.Controller == 3) S9xSetInfoString ("Mouse on #0");
if (IPPU.Controller == 4) S9xSetInfoString ("Superscope on #1");
break;
case '-':
if (ev.any.type == evKeyPress) {
if (Settings.SkipFrames <= 1)
Settings.SkipFrames = AUTO_FRAMERATE;
else
if (Settings.SkipFrames != AUTO_FRAMERATE)
Settings.SkipFrames--;
}
sprintf (InfoString, "Frame skip: %d", Settings.SkipFrames - 1);
S9xSetInfoString (InfoString);
break;
case '=':
case '+':
if (ev.any.type == evKeyPress) {
if (Settings.SkipFrames == AUTO_FRAMERATE)
Settings.SkipFrames = 1;
else
if (Settings.SkipFrames < 10)
Settings.SkipFrames++;
}
sprintf (InfoString, "Frame skip: %d", Settings.SkipFrames - 1);
S9xSetInfoString (InfoString);
break;
case GIIUC_BackSpace:
if (ev.any.type == evKeyPress) {
Settings.DisableGraphicWindows = !Settings.DisableGraphicWindows;
}
break;
case GIIK_Break:
if (ev.any.type == evKeyPress)
Settings.Paused ^= 1;
break;
case GIIUC_Tab:
if (ev.any.type == evKeyPress)
superscope_turbo = !superscope_turbo;
break;
case GIIK_Pause:
superscope_pause = ev.any.type == evKeyPress;
break;
case GIIK_F1:
#ifdef DEBUGGER
if (ev.any.type == evKeyPress && (ev.key.modifiers & (GII_MOD_ALT))) {
CPU.Flags |= DEBUG_MODE_FLAG;
break;
}
#endif
// Fall...
case GIIK_F2:
if (ev.any.type == evKeyPress && (ev.key.modifiers & (GII_MOD_ALT))) {
S9xLoadSnapshot (S9xChooseFilename (TRUE));
break;
}
// Fall...
case GIIK_F3:
if (ev.any.type == evKeyPress && (ev.key.modifiers & (GII_MOD_ALT))) {
Snapshot (S9xChooseFilename (FALSE));
break;
}
// Fall...
case GIIK_F4:
case GIIK_F5:
case GIIK_F6:
case GIIK_F7:
case GIIK_F8:
case GIIK_F9:
case GIIK_F10:
case GIIK_F11:
case GIIK_F12:
if (ev.any.type == evKeyPress) {
if (!(ev.key.modifiers & ((GII_MOD_SHIFT) | (GII_MOD_ALT)))) {
if (keysym == GIIK_F11) {
S9xLoadSnapshot (S9xChooseFilename (TRUE));
break;
} else if (keysym == GIIK_F12) {
Snapshot (S9xChooseFilename (FALSE));
break;
}
char def [PATH_MAX];
char filename [PATH_MAX];
char drive [_MAX_DRIVE];
char dir [_MAX_DIR];
char ext [_MAX_EXT];
_splitpath (Memory.ROMFilename, drive, dir, def, ext);
sprintf (filename, "%s%s%s.%03d",
S9xGetSnapshotDirectory (), SLASH_STR, def,
keysym - GIIK_F1);
S9xLoadSnapshot (filename);
} else
if (ev.key.modifiers & (GII_MOD_ALT)) {
if (keysym >= GIIK_F4)
S9xToggleSoundChannel (keysym - GIIK_F4);
} else {
char def [PATH_MAX];
char filename [PATH_MAX];
char drive [_MAX_DRIVE];
char dir [_MAX_DIR];
char ext [_MAX_EXT];
_splitpath (Memory.ROMFilename, drive, dir, def, ext);
sprintf (filename, "%s%s%s.%03d",
S9xGetSnapshotDirectory (), SLASH_STR, def,
keysym - GIIK_F1);
Snapshot (filename);
}
}
break;
case 'o':
if (ev.any.type == evKeyPress)
TakeScreenshot=1;
break;
case 'p':
if (ev.any.type == evKeyPress)
ShowFPS=!ShowFPS;
if (ShowFPS) S9xSetInfoString ("Show FPS Enabled");
else {
S9xSetInfoString ("Show FPS Disabled");
ggiPuts(vis, 0, 0, " ");
ggiPuts(vis, 0, 8, " ");
ggiFlush(vis);
}
break;
case 'l':
if (ev.any.type == evKeyPress) {
++RenderRes;
if (RenderRes==1) {
S9xSetInfoString ("Hi-res Mode");
S9xGraphicsMode();
}
else if (RenderRes==2) S9xSetInfoString ("Bi-linear Filtering
Enabled");
else if (RenderRes==3) S9xSetInfoString ("Aggressive Bi-linear
Filtering");
else {
RenderRes=0;
S9xSetInfoString ("Lo-res Mode");
S9xGraphicsMode();
}
}
break;
}
if (ev.any.type == evKeyPress) {
joypads [0] |= byte1;
joypads [0] |= (byte2 << 8);
joypads [1] |= byte3;
joypads [1] |= (byte4 << 8);
} else {
joypads [0] &= ~byte1;
joypads [0] &= ~(byte2 << 8);
joypads [1] &= ~byte3;
joypads [1] &= ~(byte4 << 8);
}
break;
case evPtrRelative:
mouse_x += ev.pmove.x;
mouse_y += ev.pmove.y;
break;
case evPtrAbsolute:
mouse_x = ev.pmove.x;
mouse_y = ev.pmove.y;
break;
case evPtrButtonPress:
mouse_buttons |= ev.pbutton.button;
break;
case evPtrButtonRelease:
mouse_buttons &= ~ev.pbutton.button;
break;
default:
break;
}
} while (giiEventPoll(inp, emAll, &tv)!=0);
}