[win32/sdl] improved SDL port (thanks to Enik)

This commit is contained in:
EkeEke 2012-11-22 21:46:19 +01:00
parent 1ace7445f6
commit 5dd1876419

View File

@ -152,7 +152,6 @@ static int sdl_video_init()
sdl_video.surf_bitmap = SDL_CreateRGBSurface(SDL_SWSURFACE, 720, 576, 16, 0, 0, 0, 0); sdl_video.surf_bitmap = SDL_CreateRGBSurface(SDL_SWSURFACE, 720, 576, 16, 0, 0, 0, 0);
sdl_video.frames_rendered = 0; sdl_video.frames_rendered = 0;
SDL_ShowCursor(0); SDL_ShowCursor(0);
return 1; return 1;
} }
@ -263,19 +262,25 @@ struct {
unsigned ticks; unsigned ticks;
} sdl_sync; } sdl_sync;
/* sync */
static Uint32 sdl_sync_timer_callback(Uint32 interval) static Uint32 sdl_sync_timer_callback(Uint32 interval)
{ {
char caption[100];
SDL_SemPost(sdl_sync.sem_sync); SDL_SemPost(sdl_sync.sem_sync);
sdl_sync.ticks++; sdl_sync.ticks++;
if (sdl_sync.ticks == (vdp_pal ? 50 : 20)) if (sdl_sync.ticks == (vdp_pal ? 50 : 20))
{ {
int fps = vdp_pal ? (sdl_video.frames_rendered / 3) : sdl_video.frames_rendered; SDL_Event event;
SDL_UserEvent userevent;
userevent.type = SDL_USEREVENT;
userevent.code = vdp_pal ? (sdl_video.frames_rendered / 3) : sdl_video.frames_rendered;
userevent.data1 = NULL;
userevent.data2 = NULL;
sdl_sync.ticks = sdl_video.frames_rendered = 0; sdl_sync.ticks = sdl_video.frames_rendered = 0;
sprintf(caption,"%d fps - %s", fps, (rominfo.international[0] != 0x20) ? rominfo.international : rominfo.domestic);
SDL_WM_SetCaption(caption, NULL); event.type = SDL_USEREVENT;
event.user = userevent;
SDL_PushEvent(&event);
} }
return interval; return interval;
} }
@ -318,6 +323,13 @@ static int sdl_control_update(SDLKey keystate)
break; break;
} }
case SDLK_F1:
{
if (SDL_ShowCursor(-1)) SDL_ShowCursor(0);
else SDL_ShowCursor(1);
break;
}
case SDLK_F2: case SDLK_F2:
{ {
if (fullscreen) fullscreen = 0; if (fullscreen) fullscreen = 0;
@ -490,13 +502,15 @@ int sdl_input_update(void)
{ {
case DEVICE_LIGHTGUN: case DEVICE_LIGHTGUN:
{ {
/* get mouse (absolute values) */ /* get mouse coordinates (absolute values) */
int x,y; int x,y;
int state = SDL_GetMouseState(&x,&y); int state = SDL_GetMouseState(&x,&y);
/* Calculate X Y axis values */ /* X axis */
input.analog[joynum][0] = (x * bitmap.viewport.w) / VIDEO_WIDTH; input.analog[joynum][0] = x - (VIDEO_WIDTH-bitmap.viewport.w)/2;
input.analog[joynum][1] = (y * bitmap.viewport.h) / VIDEO_HEIGHT;
/* Y axis */
input.analog[joynum][1] = y - (VIDEO_HEIGHT-bitmap.viewport.h)/2;
/* TRIGGER, B, C (Menacer only), START (Menacer & Justifier only) */ /* TRIGGER, B, C (Menacer only), START (Menacer & Justifier only) */
if(state & SDL_BUTTON_LMASK) input.pad[joynum] |= INPUT_A; if(state & SDL_BUTTON_LMASK) input.pad[joynum] |= INPUT_A;
@ -838,13 +852,25 @@ int main (int argc, char **argv)
{ {
switch(event.type) switch(event.type)
{ {
case SDL_USEREVENT:
{
char caption[100];
sprintf(caption,"Genesis Plus GX - %d fps - %s)", event.user.code, (rominfo.international[0] != 0x20) ? rominfo.international : rominfo.domestic);
SDL_WM_SetCaption(caption, NULL);
break;
}
case SDL_QUIT: case SDL_QUIT:
{
running = 0; running = 0;
break; break;
}
case SDL_KEYDOWN: case SDL_KEYDOWN:
{
running = sdl_control_update(event.key.keysym.sym); running = sdl_control_update(event.key.keysym.sym);
break; break;
}
} }
} }