Commit 277b0035 authored by deuce's avatar deuce
Browse files

Shuffle various SDL bits around in preperation for adding SDL suport to

xpdev.  Essentially, sdlfuncts and the *[Mm]ain* files will become part
of xpdev.
parent 99a912cc
......@@ -241,13 +241,13 @@ int console_main(int argc, char *argv[], char **env)
}
/* Run the application main() code */
SDL_main_env(argc, argv, env);
n=SDL_main_env(argc, argv, env);
/* Exit cleanly, calling atexit() functions */
exit(0);
exit(n);
/* Hush little compiler, don't you cry... */
return(0);
return(n);
}
/* This is where execution begins [windowed apps] */
......
......@@ -114,7 +114,7 @@ CIOLIBEXPORT char * CIOLIBCALL ciolib_getcliptext(void);
#ifdef WITH_SDL
int try_sdl_init(int mode)
{
if(!sdl_init(mode)) {
if(!sdl_initciolib(mode)) {
cio_api.mouse=1;
cio_api.puttext=sdl_puttext;
cio_api.gettext=sdl_gettext;
......
......@@ -35,10 +35,6 @@
#include "sdlfuncs.h"
#ifndef _WIN32
struct sdlfuncs sdl;
#endif
extern int CIOLIB_main(int argc, char **argv, char **enviro);
/********************************************************/
......@@ -495,12 +491,6 @@ int sdl_draw_char(unsigned short vch, int xpos, int ypos, int update)
return(0);
}
/* atexit() function */
void sdl_exit(void)
{
sdl.Quit();
}
/* Called from main thread only (Passes Event) */
int sdl_init(int mode)
{
......@@ -1342,18 +1332,6 @@ struct mainparams {
char **env;
};
/* Called from events thread only */
int sdl_runmain(void *data)
{
struct mainparams *mp=data;
SDL_Event ev;
sdl_exitcode=CIOLIB_main(mp->argc, mp->argv, mp->env);
ev.type=SDL_QUIT;
while(sdl.PeepEvents(&ev, 1, SDL_ADDEVENT, 0xffffffff)!=1);
return(0);
}
/* Mouse event/keyboard thread */
int sdl_mouse_thread(void *data)
{
......@@ -1364,77 +1342,11 @@ int sdl_mouse_thread(void *data)
}
/* Event Thread */
#ifndef main
int main(int argc, char **argv, char **env)
#else
int SDL_main_env(int argc, char **argv, char **env)
#endif
int sdl_video_event_thread(void *data)
{
unsigned int i;
SDL_Event ev;
struct mainparams mp;
char drivername[64];
#ifndef _WIN32
load_sdl_funcs(&sdl);
#endif
if(sdl.gotfuncs) {
#ifdef _WIN32
/* Fail to windib (ie: No mouse attached) */
if(sdl.Init(SDL_INIT_VIDEO)) {
if(getenv("SDL_VIDEODRIVER")==NULL) {
putenv("SDL_VIDEODRIVER=windib");
WinExec(GetCommandLine(), SW_SHOWDEFAULT);
exit(0);
}
sdl.gotfuncs=FALSE;
}
#else
/*
* On Linux, SDL doesn't properly detect availability of the
* framebuffer apparently. This results in remote connections
* displaying on the local framebuffer... a definate no-no.
* This ugly hack attempts to prevent this... of course, remote X11
* connections must still be allowed.
*/
if(getenv("REMOTEHOST")!=NULL && getenv("DISPLAY")==NULL)
sdl.gotfuncs=FALSE;
else {
if(sdl.Init(SDL_INIT_VIDEO))
sdl.gotfuncs=FALSE;
}
#endif
if(sdl.VideoDriverName(drivername, sizeof(drivername))!=NULL) {
/* Unacceptable drivers */
if((!strcmp(drivername, "caca")) || (!strcmp(drivername,"aalib")) || (!strcmp(drivername,"dummy"))) {
sdl.gotfuncs=FALSE;
sdl.Quit();
}
}
}
if(sdl.gotfuncs) {
atexit(sdl_exit);
mp.argc=argc;
mp.argv=argv;
mp.env=env;
sdl_key_pending=sdl.SDL_CreateSemaphore(0);
sdl_init_complete=sdl.SDL_CreateSemaphore(0);
sdl_ufunc_ret=sdl.SDL_CreateSemaphore(0);
sdl_updlock=sdl.SDL_CreateMutex();
sdl_keylock=sdl.SDL_CreateMutex();
sdl_vstatlock=sdl.SDL_CreateMutex();
sdl_ufunc_lock=sdl.SDL_CreateMutex();
#if !defined(NO_X) && defined(__unix__)
sdl_pastebuf_set=sdl.SDL_CreateSemaphore(0);
sdl_pastebuf_copied=sdl.SDL_CreateSemaphore(0);
sdl_copybuf_mutex=sdl.SDL_CreateMutex();
#endif
sdl.CreateThread(sdl_runmain, &mp);
while(1) {
if(sdl.WaitEvent(&ev)==1) {
switch (ev.type) {
......@@ -1849,7 +1761,27 @@ int SDL_main_env(int argc, char **argv, char **env)
}
}
}
else {
return(CIOLIB_main(argc, argv, env));
}
}
int sdl_initciolib(int mode)
{
if(!sdl.gotfuncs)
return(-1);
if(init_sdl_video()==-1)
return(-1);
sdl_key_pending=sdl.SDL_CreateSemaphore(0);
sdl_init_complete=sdl.SDL_CreateSemaphore(0);
sdl_ufunc_ret=sdl.SDL_CreateSemaphore(0);
sdl_updlock=sdl.SDL_CreateMutex();
sdl_keylock=sdl.SDL_CreateMutex();
sdl_vstatlock=sdl.SDL_CreateMutex();
sdl_ufunc_lock=sdl.SDL_CreateMutex();
#if !defined(NO_X) && defined(__unix__)
sdl_pastebuf_set=sdl.SDL_CreateSemaphore(0);
sdl_pastebuf_copied=sdl.SDL_CreateSemaphore(0);
sdl_copybuf_mutex=sdl.SDL_CreateMutex();
#endif
sdl.CreateThread(sdl_video_event_thread, NULL);
return(sdl_init(mode));
}
......@@ -22,7 +22,7 @@ int sdl_wherey(void);
int sdl_wherex(void);
int sdl_putch(int ch);
void sdl_gotoxy(int x, int y);
void sdl_initciolib(long inmode);
int sdl_initciolib(long inmode);
void sdl_gettextinfo(struct text_info *info);
void sdl_setcursortype(int type);
int sdl_getch(void);
......@@ -38,6 +38,7 @@ char *sdl_getcliptext(void);
int sdl_setfont(int font, int force);
int sdl_getfont(void);
int sdl_loadfont(char *filename);
int sdl_video_event_thread(void *data);
#ifdef __cplusplus
}
#endif
......
#include <stdio.h> /* NULL */
#include "gen_defs.h"
#include "sdlfuncs.h"
#ifndef _WIN32
struct sdlfuncs sdl;
#endif
static int sdl_funcs_loaded=0;
static int sdl_initialized=0;
static int sdl_audio_initialized=0;
static int sdl_video_initialized=0;
#ifdef STATIC_SDL
int load_sdl_funcs(struct sdlfuncs *sdlf)
{
......@@ -36,7 +46,10 @@ int load_sdl_funcs(struct sdlfuncs *sdlf)
sdlf->EnableKeyRepeat=SDL_EnableKeyRepeat;
sdlf->GetWMInfo=SDL_GetWMInfo;
sdlf->GetError=SDL_GetError;
sdlf->InitSubSystem=SDL_InitSubSystem;
sdlf->QuitSubSystem=SDL_QuitSubSystem;
sdlf->gotfuncs=1;
sdl_funcs_loaded=1;
return(0);
}
#else
......@@ -166,7 +179,16 @@ int load_sdl_funcs(struct sdlfuncs *sdlf)
FreeLibrary(sdl_dll);
return(-1);
}
if((sdlf->InitSubSystem=GetProcAddress(sdl_dll, "SDL_InitSubSystem"))==NULL) {
FreeLibrary(sdl_dll);
return(-1);
}
if((sdlf->QuitSubSystem=GetProcAddress(sdl_dll, "SDL_QuitSubSystem"))==NULL) {
FreeLibrary(sdl_dll);
return(-1);
}
sdlf->gotfuncs=1;
sdl_funcs_loaded=1;
return(0);
}
#elif defined(__unix__)
......@@ -291,8 +313,106 @@ int load_sdl_funcs(struct sdlfuncs *sdlf)
return(-1);
}
sdlf->gotfuncs=1;
sdl_funcs_loaded=1;
return(0);
}
#endif
#endif
int init_sdl_video(void)
{
/* This is all handled in SDL_main_env() */
if(sdl_video_initialized)
return(0);
else
return(-1);
}
int init_sdl_audio(void)
{
if(!sdl_initialized)
return(-1);
if(sdl_audio_initialized)
return(0);
if(sdl.InitSubSystem(SDL_INIT_AUDIO)==0) {
sdl_audio_initialized=TRUE;
return(0);
}
return(-1);
}
/* atexit() function */
static void sdl_exit(void)
{
sdl.Quit();
}
#ifndef main
int main(int argc, char **argv, char **env)
#else
int SDL_main_env(int argc, char **argv, char **env)
#endif
{
unsigned int i;
SDL_Event ev;
char drivername[64];
#ifndef _WIN32
load_sdl_funcs(&sdl);
#endif
if(sdl.gotfuncs) {
#ifdef _WIN32
/* Fail to windib (ie: No mouse attached) */
if(sdl.Init(SDL_INIT_VIDEO)) {
if(getenv("SDL_VIDEODRIVER")==NULL) {
putenv("SDL_VIDEODRIVER=windib");
WinExec(GetCommandLine(), SW_SHOWDEFAULT);
exit(0);
}
sdl.gotfuncs=FALSE;
}
else {
sdl_video_initialized=TRUE;
}
#else
/*
* On Linux, SDL doesn't properly detect availability of the
* framebuffer apparently. This results in remote connections
* displaying on the local framebuffer... a definate no-no.
* This ugly hack attempts to prevent this... of course, remote X11
* connections must still be allowed.
*/
if(getenv("REMOTEHOST")!=NULL && getenv("DISPLAY")==NULL) {
/* Sure ,we can't use video, but audio is still valid! */
if(sdl.Init(0)==0)
sdl_initialized=TRUE;
sdl.gotfuncs=FALSE;
}
else {
if(sdl.Init(SDL_INIT_VIDEO))
sdl.gotfuncs=FALSE;
else {
sdl_initialized=TRUE;
sdl_video_initialized=TRUE;
}
}
#endif
if(sdl_video_initialized && sdl.VideoDriverName(drivername, sizeof(drivername))!=NULL) {
/* Unacceptable drivers */
if((!strcmp(drivername, "caca")) || (!strcmp(drivername,"aalib")) || (!strcmp(drivername,"dummy"))) {
sdl.gotfuncs=FALSE;
sdl.QuitSubSystem(SDL_INIT_VIDEO);
sdl_video_initialized=FALSE;
}
else {
sdl_video_initialized=TRUE;
}
}
}
if(sdl_initialized)
atexit(sdl_exit);
return(CIOLIB_main(argc, argv, env));
}
......@@ -37,18 +37,20 @@ struct sdlfuncs {
int (*EnableKeyRepeat) (int delay, int interval);
int (*GetWMInfo) (struct SDL_SysWMinfo *info);
char *(*GetError) (void);
int (*InitSubSystem)(Uint32 flags);
void (*QuitSubSystem)(Uint32 flags);
int gotfuncs;
};
#ifdef _WIN32
/* Defined in SDL_win32_main.c */
/* Defined in SDL_win32_main.c for Win32 */
extern struct sdlfuncs sdl;
#endif
#ifdef __cplusplus
extern "C" {
#endif
int load_sdl_funcs(struct sdlfuncs *sdlf);
int init_sdl_audio(void);
int init_sdl_video(void);
#ifdef __cplusplus
}
#endif
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment