Commit 2bbbb6ee authored by deuce's avatar deuce
Browse files

Do a crappy main() shuffle for Darwin.

parent 7875edca
......@@ -1875,3 +1875,44 @@ CIOLIBEXPORT enum ciolib_codepage CIOLIBCALL ciolib_getcodepage(void)
return CIOLIB_CP437;
return conio_fontdata[font].cp;
}
#if defined(__DARWIN__)
#ifdef main
#undef main
#endif
sem_t initsdl_sem;
sem_t main_sem;
struct main_args {
int argc;
char **argv;
int ret;
int no_sdl;
};
int CIOLIB_main(int, char **);
void main_stub(void *argptr)
{
struct main_args *args = (struct main_args *)argptr;
args->ret = CIOLIB_main(args->argc, args->argv);
args->no_sdl = 1;
sem_post(&initsdl_sem);
sem_post(&main_sem);
exit_sdl_con();
}
int main(int argc, char **argv)
{
struct main_args ma = {argc, argv, -1, 0};
sem_init(&initsdl_sem, 0, 0);
sem_init(&main_sem, 0, 0);
_beginthread(main_stub, 0, &ma);
sem_wait(&initsdl_sem);
if (!ma.no_sdl) {
sdl_video_event_thread(NULL);
}
sem_wait(&main_sem);
return ma.ret;
}
#endif
......
......@@ -35,6 +35,9 @@
#define _CIOLIB_H_
#include <string.h> /* size_t */
#if defined(__DARWIN__)
#include <semwrap.h>
#endif
#include "gen_defs.h"
#include "utf8_codepages.h"
......@@ -548,12 +551,17 @@ CIOLIBEXPORT void CIOLIBCALL ansi_ciolib_setdoorway(int enable);
#include <gen_defs.h>
#include <SDL.h>
#ifdef _WIN32
#if defined(_WIN32) || defined(__DARWIN__)
#ifdef main
#undef main
#endif
#define main CIOLIB_main
#endif
#if defined(__DARWIN__)
extern sem_t initsdl_sem;
extern sem_t main_sem;
#endif
#endif
#define CIOLIB_BUTTON_1 1
......
......@@ -181,7 +181,7 @@ const struct sdl_keyvals sdl_keyval[] =
{0, 0, 0, 0, 0} /** END **/
};
static void sdl_video_event_thread(void *data);
void sdl_video_event_thread(void *data);
static void sdl_user_func(int func, ...)
{
......@@ -371,7 +371,11 @@ int sdl_init(int mode)
if(mode==CIOLIB_MODE_SDL_FULLSCREEN)
fullscreen=1;
// Needs to be *after* bitmap_drv_init()
#if defined(__DARWIN__)
sem_post(&initsdl_sem);
#else
_beginthread(sdl_video_event_thread, 0, NULL);
#endif
sdl_user_func_ret(SDL_USEREVENT_INIT);
sdl_init_mode(3);
......@@ -752,7 +756,7 @@ static int win_to_text_ypos(int winpos)
return ret;
}
static void sdl_video_event_thread(void *data)
void sdl_video_event_thread(void *data)
{
SDL_Event ev;
int old_w, old_h;
......
......@@ -38,6 +38,12 @@ int sdl_setpalette(uint32_t index, uint16_t r, uint16_t g, uint16_t b);
void sdl_setwinsize(int w, int h);
void sdl_setwinposition(int x, int y);
void sdl_beep(void);
#if defined(__DARWIN__)
void sdl_init_darwin(void *args);
void sdl_video_event_thread(void *data);
#endif
#ifdef __cplusplus
}
#endif
......
......@@ -346,7 +346,9 @@ int init_sdl_audio(void)
static void QuitWrap(void)
{
if (sdl_initialized) {
#if !defined(__DARWIN__)
exit_sdl_con();
#endif
if(sdl.Quit)
sdl.Quit();
}
......
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