summaryrefslogtreecommitdiffstatshomepage
path: root/src/osd
diff options
context:
space:
mode:
author Couriersud <couriersud@users.noreply.github.com>2010-01-21 22:54:49 +0000
committer Couriersud <couriersud@users.noreply.github.com>2010-01-21 22:54:49 +0000
commit10bee5ce7812d7faaecf238cf9570b802e02d56e (patch)
treecf71fbbc9cb1fb53efefef35bb916df2860fad15 /src/osd
parenta63d3b5de485918abd8bca4079ac221fe62f1d15 (diff)
The return of the "misc"
- Added sdlmisc_<targetos>.c again. This was necessary since certain tools create stubs for e.g. osd_break_into_debugger. If we do not have this in a separate file, the link stage may break. - Applied OS/2 patch [Credit: KO Myung-Hun] - Cleaned up #includes. Removed stdlib.h were possible. - More malloc to osd_malloc rename. - SDL monitor modes are read now when they are needed. This is now consistent across platforms.
Diffstat (limited to 'src/osd')
-rw-r--r--src/osd/sdl/drawogl.c5
-rw-r--r--src/osd/sdl/gl_shader_mgr.c7
-rw-r--r--src/osd/sdl/gl_shader_mgr.h10
-rw-r--r--src/osd/sdl/gl_shader_tool.c4
-rw-r--r--src/osd/sdl/sdl.mak1
-rw-r--r--src/osd/sdl/sdldir.c27
-rw-r--r--src/osd/sdl/sdlfile.c33
-rw-r--r--src/osd/sdl/sdlmain.c46
-rw-r--r--src/osd/sdl/sdlmisc_macosx.c59
-rw-r--r--src/osd/sdl/sdlmisc_os2.c61
-rw-r--r--src/osd/sdl/sdlmisc_unix.c63
-rw-r--r--src/osd/sdl/sdlmisc_win32.c57
-rw-r--r--src/osd/sdl/sdlos.h29
-rw-r--r--src/osd/sdl/sdlos_macosx.c66
-rw-r--r--src/osd/sdl/sdlos_os2.c44
-rw-r--r--src/osd/sdl/sdlos_unix.c42
-rw-r--r--src/osd/sdl/sdlos_win32.c43
-rw-r--r--src/osd/sdl/sdlprefix.h5
-rw-r--r--src/osd/sdl/sdlsync_os2.c13
-rw-r--r--src/osd/sdl/sdlwork.c4
-rw-r--r--src/osd/sdl/sound.c3
-rw-r--r--src/osd/sdl/testkeys.c1
-rw-r--r--src/osd/sdl/video.c15
-rw-r--r--src/osd/sdl/video.h13
-rw-r--r--src/osd/sdl/window.c2
25 files changed, 409 insertions, 244 deletions
diff --git a/src/osd/sdl/drawogl.c b/src/osd/sdl/drawogl.c
index cd8c9ce0501..300b11fefd0 100644
--- a/src/osd/sdl/drawogl.c
+++ b/src/osd/sdl/drawogl.c
@@ -28,7 +28,10 @@
// OpenGL headers
#include "osd_opengl.h"
+#include "sdlos.h"
+
+#include "gl_shader_tool.h"
#include "gl_shader_mgr.h"
#if defined(SDLMAME_MACOSX)
@@ -748,7 +751,7 @@ static int drawogl_window_create(sdl_window_info *window, int width, int height)
sdl->glsl_vid_attributes = video_config.glsl_vid_attributes;
- if (getenv(SDLENV_VMWARE) != NULL)
+ if (osd_getenv(SDLENV_VMWARE) != NULL)
{
sdl->usetexturerect = 1;
sdl->texpoweroftwo = 1;
diff --git a/src/osd/sdl/gl_shader_mgr.c b/src/osd/sdl/gl_shader_mgr.c
index fa0915c3ab1..c834f5b5073 100644
--- a/src/osd/sdl/gl_shader_mgr.c
+++ b/src/osd/sdl/gl_shader_mgr.c
@@ -1,9 +1,16 @@
+#include <SDL/SDL.h>
+
#include "osdcomm.h"
#include "osdcore.h"
#include "osdepend.h"
+#include "osd_opengl.h"
+
#include "gl_shader_mgr.h"
+#include "gl_shader_tool.h"
+
+// OSD headers
#define GLSL_VERTEX_SHADER_INT_NUMBER 1 // general
#define GLSL_VERTEX_SHADER_MAX_NUMBER 2 // general + custom
diff --git a/src/osd/sdl/gl_shader_mgr.h b/src/osd/sdl/gl_shader_mgr.h
index 4f80024d376..9eee4b1e757 100644
--- a/src/osd/sdl/gl_shader_mgr.h
+++ b/src/osd/sdl/gl_shader_mgr.h
@@ -2,16 +2,6 @@
#ifndef GL_SHADER_MGR_H
#define GL_SHADER_MGR_H
-#include <SDL/SDL.h>
-
-// OpenGL headers
-#include "osd_opengl.h"
-
-#include "gl_shader_tool.h"
-
-// OSD headers
-#include "window.h"
-
// #define GLSL_SOURCE_ON_DISK 1
typedef enum {
diff --git a/src/osd/sdl/gl_shader_tool.c b/src/osd/sdl/gl_shader_tool.c
index 6c501a456bd..c56874a793b 100644
--- a/src/osd/sdl/gl_shader_tool.c
+++ b/src/osd/sdl/gl_shader_tool.c
@@ -27,10 +27,6 @@
*
*/
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-
#include "emu.h"
#include "gl_shader_tool.h"
diff --git a/src/osd/sdl/sdl.mak b/src/osd/sdl/sdl.mak
index 2eabc519abf..f88b1d5af9e 100644
--- a/src/osd/sdl/sdl.mak
+++ b/src/osd/sdl/sdl.mak
@@ -257,6 +257,7 @@ OSDCOREOBJS = \
$(SDLOBJ)/strconv.o \
$(SDLOBJ)/sdldir.o \
$(SDLOBJ)/sdlfile.o \
+ $(SDLOBJ)/sdlmisc_$(BASE_TARGETOS).o \
$(SDLOBJ)/sdlos_$(BASE_TARGETOS).o \
$(SDLOBJ)/sdlsync_$(SYNC_IMPLEMENTATION).o \
$(SDLOBJ)/sdlwork.o
diff --git a/src/osd/sdl/sdldir.c b/src/osd/sdl/sdldir.c
index ed9705a4317..af9c8eead36 100644
--- a/src/osd/sdl/sdldir.c
+++ b/src/osd/sdl/sdldir.c
@@ -23,13 +23,9 @@
#define _XOPEN_SOURCE 500
#endif
-#include <sys/types.h>
+//#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
-#include <unistd.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
#ifndef __USE_BSD
#define __USE_BSD // to get DT_xxx on Linux
#endif
@@ -37,6 +33,7 @@
#include <dirent.h>
#include "osdcore.h"
+#include "sdlos.h"
#if defined(SDLMAME_WIN32) || defined(SDLMAME_OS2)
#define PATHSEPCH '\\'
@@ -113,20 +110,20 @@ osd_directory *osd_opendir(const char *dirname)
char *tmpstr, *envstr;
int i, j;
- dir = (osd_directory *) malloc(sizeof(osd_directory));
+ dir = (osd_directory *) osd_malloc(sizeof(osd_directory));
if (dir)
{
memset(dir, 0, sizeof(osd_directory));
dir->fd = NULL;
}
- tmpstr = (char *) malloc(strlen(dirname)+1);
+ tmpstr = (char *) osd_malloc(strlen(dirname)+1);
strcpy(tmpstr, dirname);
if (tmpstr[0] == '$')
{
char *envval;
- envstr = (char *) malloc(strlen(tmpstr)+1);
+ envstr = (char *) osd_malloc(strlen(tmpstr)+1);
strcpy(envstr, tmpstr);
@@ -138,12 +135,12 @@ osd_directory *osd_opendir(const char *dirname)
envstr[i] = '\0';
- envval = getenv(&envstr[1]);
+ envval = osd_getenv(&envstr[1]);
if (envval != NULL)
{
j = strlen(envval) + strlen(tmpstr) + 1;
- free(tmpstr);
- tmpstr = (char *) malloc(j);
+ osd_free(tmpstr);
+ tmpstr = (char *) osd_malloc(j);
// start with the value of $HOME
strcpy(tmpstr, envval);
@@ -154,19 +151,19 @@ osd_directory *osd_opendir(const char *dirname)
}
else
fprintf(stderr, "Warning: osd_opendir environment variable %s not found.\n", envstr);
- free(envstr);
+ osd_free(envstr);
}
dir->fd = opendir(tmpstr);
if (dir && (dir->fd == NULL))
{
- free(dir);
+ osd_free(dir);
dir = NULL;
}
if (tmpstr)
- free(tmpstr);
+ osd_free(tmpstr);
return dir;
}
@@ -205,6 +202,6 @@ void osd_closedir(osd_directory *dir)
{
if (dir->fd != NULL)
closedir(dir->fd);
- free(dir);
+ osd_free(dir);
}
diff --git a/src/osd/sdl/sdlfile.c b/src/osd/sdl/sdlfile.c
index 51afed76d92..a220ff335ed 100644
--- a/src/osd/sdl/sdlfile.c
+++ b/src/osd/sdl/sdlfile.c
@@ -23,18 +23,15 @@
#define _XOPEN_SOURCE 500
#endif
-#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <ctype.h>
#include <errno.h>
// MAME headers
#include "osdcore.h"
+#include "sdlos.h"
#if defined(SDLMAME_WIN32) || defined(SDLMAME_OS2)
#define PATHSEPCH '\\'
@@ -114,7 +111,7 @@ file_error osd_open(const char *path, UINT32 openflags, osd_file **file, UINT64
tmpstr = NULL;
// allocate a file object, plus space for the converted filename
- *file = (osd_file *) malloc(sizeof(**file) + sizeof(char) * strlen(path));
+ *file = (osd_file *) osd_malloc(sizeof(**file) + sizeof(char) * strlen(path));
if (*file == NULL)
{
filerr = FILERR_OUT_OF_MEMORY;
@@ -143,14 +140,14 @@ file_error osd_open(const char *path, UINT32 openflags, osd_file **file, UINT64
goto error;
}
- tmpstr = (char *) malloc(strlen((*file)->filename)+1);
+ tmpstr = (char *) osd_malloc(strlen((*file)->filename)+1);
strcpy(tmpstr, (*file)->filename);
// does path start with an environment variable?
if (tmpstr[0] == '$')
{
char *envval;
- envstr = (char *) malloc(strlen(tmpstr)+1);
+ envstr = (char *) osd_malloc(strlen(tmpstr)+1);
strcpy(envstr, tmpstr);
@@ -162,12 +159,12 @@ file_error osd_open(const char *path, UINT32 openflags, osd_file **file, UINT64
envstr[i] = '\0';
- envval = getenv(&envstr[1]);
+ envval = osd_getenv(&envstr[1]);
if (envval != NULL)
{
j = strlen(envval) + strlen(tmpstr) + 1;
- free(tmpstr);
- tmpstr = (char *) malloc(j);
+ osd_free(tmpstr);
+ tmpstr = (char *) osd_malloc(j);
// start with the value of $HOME
strcpy(tmpstr, envval);
@@ -178,7 +175,7 @@ file_error osd_open(const char *path, UINT32 openflags, osd_file **file, UINT64
}
else
fprintf(stderr, "Warning: osd_open environment variable %s not found.\n", envstr);
- free(envstr);
+ osd_free(envstr);
}
#if defined(SDLMAME_WIN32) || defined(SDLMAME_OS2)
@@ -218,12 +215,12 @@ file_error osd_open(const char *path, UINT32 openflags, osd_file **file, UINT64
}
}
- // if we still failed, clean up and free
+ // if we still failed, clean up and osd_free
if ((*file)->handle == -1)
{
- free(*file);
+ osd_free(*file);
*file = NULL;
- free(tmpstr);
+ osd_free(tmpstr);
return error_to_file_error(errno);
}
}
@@ -242,11 +239,11 @@ error:
// cleanup
if (filerr != FILERR_NONE && *file != NULL)
{
- free(*file);
+ osd_free(*file);
*file = NULL;
}
if (tmpstr)
- free(tmpstr);
+ osd_free(tmpstr);
return filerr;
}
@@ -316,7 +313,7 @@ file_error osd_close(osd_file *file)
{
// close the file handle and free the file structure
close(file->handle);
- free(file);
+ osd_free(file);
return FILERR_NONE;
}
@@ -487,7 +484,7 @@ osd_directory_entry *osd_stat(const char *path)
// create an osd_directory_entry; be sure to make sure that the caller can
// free all resources by just freeing the resulting osd_directory_entry
- result = (osd_directory_entry *) malloc(sizeof(*result) + strlen(path) + 1);
+ result = (osd_directory_entry *) osd_malloc(sizeof(*result) + strlen(path) + 1);
strcpy(((char *) result) + sizeof(*result), path);
result->name = ((char *) result) + sizeof(*result);
result->type = S_ISDIR(st.st_mode) ? ENTTYPE_DIR : ENTTYPE_FILE;
diff --git a/src/osd/sdl/sdlmain.c b/src/osd/sdl/sdlmain.c
index 4d07878dcf0..7a2f3f6bf06 100644
--- a/src/osd/sdl/sdlmain.c
+++ b/src/osd/sdl/sdlmain.c
@@ -14,9 +14,6 @@
#include <SDL/SDL_version.h>
// standard includes
-#include <time.h>
-#include <ctype.h>
-#include <stdlib.h>
// MAME headers
#include "osdepend.h"
@@ -29,15 +26,11 @@
#include "input.h"
#include "output.h"
#include "osdsdl.h"
+#include "sdlos.h"
// we override SDL's normal startup on Win32
// please see sdlprefix.h as well
-#ifdef SDLMAME_UNIX
-#include <signal.h>
-#include <unistd.h>
-#endif
-
#if defined(SDLMAME_X11) && (SDL_MAJOR_VERSION == 1) && (SDL_MINOR_VERSION == 2)
#include <X11/Xlib.h>
#include <X11/Xutil.h>
@@ -248,33 +241,6 @@ static const options_entry mame_sdl_options[] =
{ NULL }
};
-#ifdef SDLMAME_WIN32
-
-/* mingw has no setenv */
-
-static int setenv(const char *name, const char *value, int overwrite)
-{
- char *buf;
- int result;
-
- if (!overwrite)
- {
- if (getenv(name) != NULL)
- return 0;
- }
- buf = (char *) osd_malloc(strlen(name)+strlen(value)+2);
- sprintf(buf, "%s=%s", name, value);
- result = putenv(buf);
-
- /* will be referenced by environment
- * Therefore it is not freed here
- */
-
- return result;
-}
-
-#endif
-
//============================================================
// main
//============================================================
@@ -328,7 +294,7 @@ int main(int argc, char *argv[])
char buf[130];
if (XMatchVisualInfo(display, DefaultScreen(display), 24, TrueColor, &vi)) {
snprintf(buf, sizeof(buf), "0x%lx", vi.visualid);
- setenv(SDLENV_VISUALID, buf, 0);
+ osd_setenv(SDLENV_VISUALID, buf, 0);
}
}
if (display)
@@ -507,14 +473,14 @@ void osd_init(running_machine *machine)
if (stemp != NULL && strcmp(stemp, SDLOPTVAL_AUTO) != 0)
{
mame_printf_verbose("Setting SDL audiodriver '%s' ...\n", stemp);
- setenv(SDLENV_AUDIODRIVER, stemp, 1);
+ osd_setenv(SDLENV_AUDIODRIVER, stemp, 1);
}
stemp = options_get_string(mame_options(), SDLOPTION_VIDEODRIVER);
if (stemp != NULL && strcmp(stemp, SDLOPTVAL_AUTO) != 0)
{
mame_printf_verbose("Setting SDL videodriver '%s' ...\n", stemp);
- setenv(SDLENV_VIDEODRIVER, stemp, 1);
+ osd_setenv(SDLENV_VIDEODRIVER, stemp, 1);
}
if (SDL_VERSION_ATLEAST(1,3,0))
@@ -523,7 +489,7 @@ void osd_init(running_machine *machine)
if (stemp != NULL && strcmp(stemp, SDLOPTVAL_AUTO) != 0)
{
mame_printf_verbose("Setting SDL renderdriver '%s' ...\n", stemp);
- setenv(SDLENV_RENDERDRIVER, stemp, 1);
+ osd_setenv(SDLENV_RENDERDRIVER, stemp, 1);
}
}
@@ -535,7 +501,7 @@ void osd_init(running_machine *machine)
stemp = options_get_string(mame_options(), SDLOPTION_GL_LIB);
if (stemp != NULL && strcmp(stemp, SDLOPTVAL_AUTO) != 0)
{
- setenv("SDL_VIDEO_GL_DRIVER", stemp, 1);
+ osd_setenv("SDL_VIDEO_GL_DRIVER", stemp, 1);
mame_printf_verbose("Setting SDL_VIDEO_GL_DRIVER = '%s' ...\n", stemp);
}
diff --git a/src/osd/sdl/sdlmisc_macosx.c b/src/osd/sdl/sdlmisc_macosx.c
new file mode 100644
index 00000000000..b80e74745c5
--- /dev/null
+++ b/src/osd/sdl/sdlmisc_macosx.c
@@ -0,0 +1,59 @@
+//============================================================
+//
+// sdlos_*.c - OS specific low level code
+//
+// Copyright (c) 1996-2010, Nicola Salmoria and the MAME Team.
+// Visit http://mamedev.org for licensing and usage restrictions.
+//
+// SDLMAME by Olivier Galibert and R. Belmont
+//
+//============================================================
+
+// standard sdl header
+#include <SDL/SDL.h>
+#include <sys/types.h>
+#include <sys/mman.h>
+#include <signal.h>
+
+
+// MAME headers
+#include "osdcore.h"
+
+//============================================================
+// osd_alloc_executable
+//
+// allocates "size" bytes of executable memory. this must take
+// things like NX support into account.
+//============================================================
+
+void *osd_alloc_executable(size_t size)
+{
+ return (void *)mmap(0, size, PROT_EXEC|PROT_READ|PROT_WRITE, MAP_ANON|MAP_SHARED, -1, 0);
+}
+
+//============================================================
+// osd_free_executable
+//
+// frees memory allocated with osd_alloc_executable
+//============================================================
+
+void osd_free_executable(void *ptr, size_t size)
+{
+ munmap(ptr, size);
+}
+
+//============================================================
+// osd_break_into_debugger
+//============================================================
+
+void osd_break_into_debugger(const char *message)
+{
+ #ifdef MAME_DEBUG
+ printf("MAME exception: %s\n", message);
+ printf("Attempting to fall into debugger\n");
+ kill(getpid(), SIGTRAP);
+ #else
+ printf("Ignoring MAME exception: %s\n", message);
+ #endif
+}
+
diff --git a/src/osd/sdl/sdlmisc_os2.c b/src/osd/sdl/sdlmisc_os2.c
new file mode 100644
index 00000000000..65986c078b4
--- /dev/null
+++ b/src/osd/sdl/sdlmisc_os2.c
@@ -0,0 +1,61 @@
+//============================================================
+//
+// sdlos_*.c - OS specific low level code
+//
+// Copyright (c) 1996-2010, Nicola Salmoria and the MAME Team.
+// Visit http://mamedev.org for licensing and usage restrictions.
+//
+// SDLMAME by Olivier Galibert and R. Belmont
+//
+//============================================================
+
+// standard sdl header
+#include <SDL/SDL.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <string.h>
+#include <ctype.h>
+#include <stdlib.h>
+
+#define INCL_DOS
+#include <os2.h>
+
+// MAME headers
+#include "osdepend.h"
+#include "osdcore.h"
+
+//============================================================
+// osd_alloc_executable
+//
+// allocates "size" bytes of executable memory. this must take
+// things like NX support into account.
+//============================================================
+
+void *osd_alloc_executable(size_t size)
+{
+ void *p;
+
+ DosAllocMem( &p, size, fALLOC );
+ return p;
+}
+
+//============================================================
+// osd_free_executable
+//
+// frees memory allocated with osd_alloc_executable
+//============================================================
+
+void osd_free_executable(void *ptr, size_t size)
+{
+ DosFreeMem( ptr );
+}
+
+//============================================================
+// osd_break_into_debugger
+//============================================================
+
+void osd_break_into_debugger(const char *message)
+{
+ printf("Ignoring MAME exception: %s\n", message);
+}
+
diff --git a/src/osd/sdl/sdlmisc_unix.c b/src/osd/sdl/sdlmisc_unix.c
new file mode 100644
index 00000000000..efd2d27d4a1
--- /dev/null
+++ b/src/osd/sdl/sdlmisc_unix.c
@@ -0,0 +1,63 @@
+//============================================================
+//
+// sdlos_*.c - OS specific low level code
+//
+// Copyright (c) 1996-2010, Nicola Salmoria and the MAME Team.
+// Visit http://mamedev.org for licensing and usage restrictions.
+//
+// SDLMAME by Olivier Galibert and R. Belmont
+//
+//============================================================
+
+#include <sys/mman.h>
+#include <signal.h>
+
+// MAME headers
+#include "osdcore.h"
+
+
+//============================================================
+// osd_alloc_executable
+//
+// allocates "size" bytes of executable memory. this must take
+// things like NX support into account.
+//============================================================
+
+void *osd_alloc_executable(size_t size)
+{
+#if defined(SDLMAME_BSD)
+ return (void *)mmap(0, size, PROT_EXEC|PROT_READ|PROT_WRITE, MAP_ANON|MAP_SHARED, -1, 0);
+#elif defined(SDLMAME_UNIX)
+ return (void *)mmap(0, size, PROT_EXEC|PROT_READ|PROT_WRITE, MAP_ANON|MAP_SHARED, 0, 0);
+#endif
+}
+
+//============================================================
+// osd_free_executable
+//
+// frees memory allocated with osd_alloc_executable
+//============================================================
+
+void osd_free_executable(void *ptr, size_t size)
+{
+#ifdef SDLMAME_SOLARIS
+ munmap((char *)ptr, size);
+#else
+ munmap(ptr, size);
+#endif
+}
+
+//============================================================
+// osd_break_into_debugger
+//============================================================
+
+void osd_break_into_debugger(const char *message)
+{
+ #ifdef MAME_DEBUG
+ printf("MAME exception: %s\n", message);
+ printf("Attempting to fall into debugger\n");
+ kill(getpid(), SIGTRAP);
+ #else
+ printf("Ignoring MAME exception: %s\n", message);
+ #endif
+}
diff --git a/src/osd/sdl/sdlmisc_win32.c b/src/osd/sdl/sdlmisc_win32.c
new file mode 100644
index 00000000000..96404de6843
--- /dev/null
+++ b/src/osd/sdl/sdlmisc_win32.c
@@ -0,0 +1,57 @@
+//============================================================
+//
+// sdlos_*.c - OS specific low level code
+//
+// Copyright (c) 1996-2010, Nicola Salmoria and the MAME Team.
+// Visit http://mamedev.org for licensing and usage restrictions.
+//
+// SDLMAME by Olivier Galibert and R. Belmont
+//
+//============================================================
+
+// standard sdl header
+#include <SDL/SDL.h>
+
+
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+
+// MAME headers
+#include "osdcore.h"
+
+//============================================================
+// osd_alloc_executable
+//
+// allocates "size" bytes of executable memory. this must take
+// things like NX support into account.
+//============================================================
+
+void *osd_alloc_executable(size_t size)
+{
+ return VirtualAlloc(NULL, size, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
+}
+
+//============================================================
+// osd_free_executable
+//
+// frees memory allocated with osd_alloc_executable
+//============================================================
+
+void osd_free_executable(void *ptr, size_t size)
+{
+ VirtualFree(ptr, 0, MEM_RELEASE);
+}
+
+//============================================================
+// osd_break_into_debugger
+//============================================================
+
+void osd_break_into_debugger(const char *message)
+{
+ if (IsDebuggerPresent())
+ {
+ OutputDebugStringA(message);
+ DebugBreak();
+ }
+}
+
diff --git a/src/osd/sdl/sdlos.h b/src/osd/sdl/sdlos.h
index a0db5dacad1..9b9f5d8a7e2 100644
--- a/src/osd/sdl/sdlos.h
+++ b/src/osd/sdl/sdlos.h
@@ -26,4 +26,33 @@
int osd_num_processors(void);
+/*-----------------------------------------------------------------------------
+ osd_getenv: return pointer to environment variable
+
+ Parameters:
+
+ name - name of environment variable
+
+ Return value:
+
+ pointer to value
+-----------------------------------------------------------------------------*/
+char *osd_getenv(const char *name);
+
+/*-----------------------------------------------------------------------------
+ osd_setenv: set environment variable
+
+ Parameters:
+
+ name - name of environment variable
+ value - value to write
+ overwrite - overwrite if it exists
+
+ Return value:
+
+ 0 on success
+-----------------------------------------------------------------------------*/
+
+int osd_setenv(const char *name, const char *value, int overwrite);
+
#endif /* __SDLOS__ */
diff --git a/src/osd/sdl/sdlos_macosx.c b/src/osd/sdl/sdlos_macosx.c
index eb6bf195fdc..0995e13d473 100644
--- a/src/osd/sdl/sdlos_macosx.c
+++ b/src/osd/sdl/sdlos_macosx.c
@@ -11,15 +11,7 @@
// standard sdl header
#include <SDL/SDL.h>
-#include <unistd.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <ctype.h>
-#include <sys/types.h>
-#include <sys/mman.h>
-#include <signal.h>
+
#include <unistd.h>
#include <mach/mach.h>
@@ -169,44 +161,6 @@ int osd_num_processors(void)
}
//============================================================
-// osd_alloc_executable
-//
-// allocates "size" bytes of executable memory. this must take
-// things like NX support into account.
-//============================================================
-
-void *osd_alloc_executable(size_t size)
-{
- return (void *)mmap(0, size, PROT_EXEC|PROT_READ|PROT_WRITE, MAP_ANON|MAP_SHARED, -1, 0);
-}
-
-//============================================================
-// osd_free_executable
-//
-// frees memory allocated with osd_alloc_executable
-//============================================================
-
-void osd_free_executable(void *ptr, size_t size)
-{
- munmap(ptr, size);
-}
-
-//============================================================
-// osd_break_into_debugger
-//============================================================
-
-void osd_break_into_debugger(const char *message)
-{
- #ifdef MAME_DEBUG
- printf("MAME exception: %s\n", message);
- printf("Attempting to fall into debugger\n");
- kill(getpid(), SIGTRAP);
- #else
- printf("Ignoring MAME exception: %s\n", message);
- #endif
-}
-
-//============================================================
// osd_malloc
//============================================================
@@ -232,3 +186,21 @@ void osd_free(void *ptr)
#error "MALLOC_DEBUG not yet supported"
#endif
}
+
+//============================================================
+// osd_getenv
+//============================================================
+
+char *osd_getenv(const char *name)
+{
+ return getenv(name);
+}
+
+//============================================================
+// osd_setenv
+//============================================================
+
+int osd_setenv(const char *name, const char *value, int overwrite)
+{
+ return setenv(name, value, overwrite);
+}
diff --git a/src/osd/sdl/sdlos_os2.c b/src/osd/sdl/sdlos_os2.c
index 4c20ae815d0..a3c3b607460 100644
--- a/src/osd/sdl/sdlos_os2.c
+++ b/src/osd/sdl/sdlos_os2.c
@@ -21,7 +21,6 @@
#include <os2.h>
// MAME headers
-#include "osdepend.h"
#include "osdcore.h"
@@ -184,40 +183,47 @@ int osd_num_processors(void)
return numprocs;
}
+//============================================================
+// osd_malloc
+//============================================================
+
+void *osd_malloc(size_t size)
+{
+#ifndef MALLOC_DEBUG
+ return malloc(size);
+#else
+#error "MALLOC_DEBUG not yet supported"
+#endif
+}
//============================================================
-// osd_alloc_executable
-//
-// allocates "size" bytes of executable memory. this must take
-// things like NX support into account.
+// osd_free
//============================================================
-void *osd_alloc_executable(size_t size)
+void osd_free(void *ptr)
{
- void *p;
-
- DosAllocMem( &p, size, fALLOC );
- return p;
+#ifndef MALLOC_DEBUG
+ free(ptr);
+#else
+#error "MALLOC_DEBUG not yet supported"
+#endif
}
//============================================================
-// osd_free_executable
-//
-// frees memory allocated with osd_alloc_executable
+// osd_getenv
//============================================================
-void osd_free_executable(void *ptr, size_t size)
+char *osd_getenv(const char *name)
{
- DosFreeMem( ptr );
+ return getenv(name);
}
//============================================================
-// osd_break_into_debugger
+// osd_setenv
//============================================================
-void osd_break_into_debugger(const char *message)
+int osd_setenv(const char *name, const char *value, int overwrite)
{
- printf("Ignoring MAME exception: %s\n", message);
+ return setenv(name, value, overwrite);
}
-
diff --git a/src/osd/sdl/sdlos_unix.c b/src/osd/sdl/sdlos_unix.c
index e7551ee0d6a..8b489727081 100644
--- a/src/osd/sdl/sdlos_unix.c
+++ b/src/osd/sdl/sdlos_unix.c
@@ -9,13 +9,11 @@
//
//============================================================
-#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/mman.h>
#include <time.h>
#include <sys/time.h>
-#include <signal.h>
// MAME headers
#include "osdcore.h"
@@ -104,48 +102,20 @@ void osd_free(void *ptr)
}
//============================================================
-// osd_alloc_executable
-//
-// allocates "size" bytes of executable memory. this must take
-// things like NX support into account.
+// osd_getenv
//============================================================
-void *osd_alloc_executable(size_t size)
+char *osd_getenv(const char *name)
{
-#if defined(SDLMAME_BSD)
- return (void *)mmap(0, size, PROT_EXEC|PROT_READ|PROT_WRITE, MAP_ANON|MAP_SHARED, -1, 0);
-#elif defined(SDLMAME_UNIX)
- return (void *)mmap(0, size, PROT_EXEC|PROT_READ|PROT_WRITE, MAP_ANON|MAP_SHARED, 0, 0);
-#endif
+ return getenv(name);
}
-//============================================================
-// osd_free_executable
-//
-// frees memory allocated with osd_alloc_executable
-//============================================================
-
-void osd_free_executable(void *ptr, size_t size)
-{
-#ifdef SDLMAME_SOLARIS
- munmap((char *)ptr, size);
-#else
- munmap(ptr, size);
-#endif
-}
//============================================================
-// osd_break_into_debugger
+// osd_setenv
//============================================================
-void osd_break_into_debugger(const char *message)
+int osd_setenv(const char *name, const char *value, int overwrite)
{
- #ifdef MAME_DEBUG
- printf("MAME exception: %s\n", message);
- printf("Attempting to fall into debugger\n");
- kill(getpid(), SIGTRAP);
- #else
- printf("Ignoring MAME exception: %s\n", message);
- #endif
+ return setenv(name, value, overwrite);
}
-
diff --git a/src/osd/sdl/sdlos_win32.c b/src/osd/sdl/sdlos_win32.c
index 3d5c7192740..bfe6cec6ba3 100644
--- a/src/osd/sdl/sdlos_win32.c
+++ b/src/osd/sdl/sdlos_win32.c
@@ -11,8 +11,6 @@
// standard sdl header
#include <SDL/SDL.h>
-#include <unistd.h>
-#include <stdio.h>
#define WIN32_LEAN_AND_MEAN
@@ -241,38 +239,35 @@ void osd_free(void *ptr)
}
//============================================================
-// osd_alloc_executable
-//
-// allocates "size" bytes of executable memory. this must take
-// things like NX support into account.
+// osd_getenv
//============================================================
-void *osd_alloc_executable(size_t size)
+char *osd_getenv(const char *name)
{
- return VirtualAlloc(NULL, size, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
+ return getenv(name);
}
//============================================================
-// osd_free_executable
-//
-// frees memory allocated with osd_alloc_executable
+// osd_setenv
//============================================================
-void osd_free_executable(void *ptr, size_t size)
+int osd_setenv(const char *name, const char *value, int overwrite)
{
- VirtualFree(ptr, 0, MEM_RELEASE);
-}
-
-//============================================================
-// osd_break_into_debugger
-//============================================================
+ char *buf;
+ int result;
-void osd_break_into_debugger(const char *message)
-{
- if (IsDebuggerPresent())
+ if (!overwrite)
{
- OutputDebugStringA(message);
- DebugBreak();
+ if (osd_getenv(name) != NULL)
+ return 0;
}
-}
+ buf = (char *) osd_malloc(strlen(name)+strlen(value)+2);
+ sprintf(buf, "%s=%s", name, value);
+ result = putenv(buf);
+ /* will be referenced by environment
+ * Therefore it is not freed here
+ */
+
+ return result;
+}
diff --git a/src/osd/sdl/sdlprefix.h b/src/osd/sdl/sdlprefix.h
index aed6f845421..866bed428db 100644
--- a/src/osd/sdl/sdlprefix.h
+++ b/src/osd/sdl/sdlprefix.h
@@ -27,14 +27,13 @@
#if defined(__sun__) && defined(__svr4__)
#define SDLMAME_SOLARIS 1
-//#undef _XOPEN_SOURCE
+#undef _XOPEN_SOURCE
+#undef _XOPEN_VERSION
#undef _XOPEN_SOURCE_EXTENDED
#undef _XPG6
#undef _XPG5
#undef _XPG4_2
-#undef _XOPEN_SOURCE
-#undef _XOPEN_VERSION
#define _XOPEN_SOURCE
#define _XOPEN_VERSION 4
diff --git a/src/osd/sdl/sdlsync_os2.c b/src/osd/sdl/sdlsync_os2.c
index f3271e154e0..242ce62d4ff 100644
--- a/src/osd/sdl/sdlsync_os2.c
+++ b/src/osd/sdl/sdlsync_os2.c
@@ -56,6 +56,8 @@ struct _osd_event {
struct _osd_thread {
pthread_t thread;
+ osd_thread_callback callback;
+ void *param;
};
struct _osd_scalable_lock
@@ -400,12 +402,21 @@ int osd_event_wait(osd_event *event, osd_ticks_t timeout)
// osd_thread_create
//============================================================
+static void worker_thread_entry(void *param)
+{
+ osd_thread *thread = (osd_thread *) param;
+
+ thread->callback(thread->param);
+}
+
osd_thread *osd_thread_create(osd_thread_callback callback, void *cbparam)
{
osd_thread *thread;
thread = (osd_thread *)calloc(1, sizeof(osd_thread));
- thread->thread = _beginthread(callback, NULL, 65535, cbparam);
+ thread->callback = callback;
+ thread->param = cbparam;
+ thread->thread = _beginthread(worker_thread_entry, NULL, 65535, thread);
if ( thread->thread == -1 )
{
free(thread);
diff --git a/src/osd/sdl/sdlwork.c b/src/osd/sdl/sdlwork.c
index 2cd602c36bc..4edfcad6463 100644
--- a/src/osd/sdl/sdlwork.c
+++ b/src/osd/sdl/sdlwork.c
@@ -571,7 +571,7 @@ static int effective_num_processors(void)
else
{
// if the OSDPROCESSORS environment variable is set, use that value if valid
- procsoverride = getenv(SDLENV_PROCESSORS);
+ procsoverride = osd_getenv(SDLENV_PROCESSORS);
if (procsoverride != NULL && sscanf(procsoverride, "%d", &numprocs) == 1 && numprocs > 0)
return MIN(4 * physprocs, numprocs);
@@ -590,7 +590,7 @@ static UINT32 effective_cpu_mask(int index)
char buf[5];
UINT32 mask = 0xFFFF;
- s = getenv(SDLENV_CPUMASKS);
+ s = osd_getenv(SDLENV_CPUMASKS);
if (s != NULL && strcmp(s,"none"))
{
if (!strcmp(s,"auto"))
diff --git a/src/osd/sdl/sound.c b/src/osd/sdl/sound.c
index 99395100bb2..3383560fd2d 100644
--- a/src/osd/sdl/sound.c
+++ b/src/osd/sdl/sound.c
@@ -11,12 +11,9 @@
// standard sdl header
#include <SDL/SDL.h>
-#include <unistd.h>
-#include <math.h>
// MAME headers
#include "emu.h"
-#include "options.h"
#include "emuopts.h"
#include "osdepend.h"
diff --git a/src/osd/sdl/testkeys.c b/src/osd/sdl/testkeys.c
index f757ebb9dbb..504c8a60256 100644
--- a/src/osd/sdl/testkeys.c
+++ b/src/osd/sdl/testkeys.c
@@ -12,7 +12,6 @@
#include <stdio.h>
#include <ctype.h>
-#include <stdlib.h>
#include <string.h>
#include <wchar.h>
diff --git a/src/osd/sdl/video.c b/src/osd/sdl/video.c
index 09378e8f98c..3bf06c33fcb 100644
--- a/src/osd/sdl/video.c
+++ b/src/osd/sdl/video.c
@@ -41,10 +41,6 @@
#include <os2.h>
#endif
-// standard C headers
-#include <math.h>
-#include <unistd.h>
-
// MAME headers
#include "emu.h"
#include "rendutil.h"
@@ -60,8 +56,7 @@
#include "debugwin.h"
#include "osdsdl.h"
-
-#include "osd_opengl.h"
+#include "sdlos.h"
#ifdef MESS
#include "menu.h"
@@ -251,7 +246,7 @@ void sdlvideo_monitor_refresh(sdl_monitor_info *monitor)
SDL_VideoDriverName(monitor->monitor_device, sizeof(monitor->monitor_device)-1);
if (first_call==0)
{
- char *dimstr = getenv(SDLENV_DESKTOPDIM);
+ char *dimstr = osd_getenv(SDLENV_DESKTOPDIM);
const SDL_VideoInfo *sdl_vi;
sdl_vi = SDL_GetVideoInfo();
@@ -431,11 +426,6 @@ static BOOL CALLBACK monitor_enum_callback(HMONITOR handle, HDC dc, LPRECT rect,
// guess the aspect ratio assuming square pixels
monitor->aspect = (float)(info.rcMonitor.right - info.rcMonitor.left) / (float)(info.rcMonitor.bottom - info.rcMonitor.top);
- // SDL will crash if monitors are queried here
- // This will be done in window.c (Ughh, ugly)
-
- monitor->modes = NULL;
-
// save the primary monitor handle
if (info.dwFlags & MONITORINFOF_PRIMARY)
primary_monitor = monitor;
@@ -505,7 +495,6 @@ static void init_monitors(void)
EnumDisplayMonitors(NULL, NULL, monitor_enum_callback, (LPARAM)&tailptr);
#else
add_primary_monitor((void *)&tailptr);
- sdl_monitor_list->modes = SDL_ListModes(NULL, SDL_FULLSCREEN | SDL_DOUBLEBUF);
#endif
}
diff --git a/src/osd/sdl/video.h b/src/osd/sdl/video.h
index 1e3b7492d42..7d1871d5b87 100644
--- a/src/osd/sdl/video.h
+++ b/src/osd/sdl/video.h
@@ -12,8 +12,6 @@
#ifndef __SDLVIDEO__
#define __SDLVIDEO__
-#include <SDL/SDL.h>
-
//============================================================
// CONSTANTS
//============================================================
@@ -52,6 +50,13 @@ enum {
// TYPE DEFINITIONS
//============================================================
+typedef struct _sdl_mode sdl_mode;
+struct _sdl_mode
+{
+ int width;
+ int height;
+};
+
typedef struct _sdl_monitor_info sdl_monitor_info;
struct _sdl_monitor_info
{
@@ -67,10 +72,6 @@ struct _sdl_monitor_info
float aspect; // computed/configured aspect ratio of the physical device
int center_width; // width of first physical screen for centering
int center_height; // height of first physical screen for centering
-#if !SDL_VERSION_ATLEAST(1,3,0)
- //FIXME: This should not be a SDL-type
- SDL_Rect **modes; // supported modes
-#endif
};
diff --git a/src/osd/sdl/window.c b/src/osd/sdl/window.c
index 0bc2277abb5..5ce119b21b6 100644
--- a/src/osd/sdl/window.c
+++ b/src/osd/sdl/window.c
@@ -934,7 +934,7 @@ static void pick_best_mode(sdl_window_info *window, int *fswidth, int *fsheight)
minimum_height -= 4;
}
-#if defined(SDLMAME_WIN32)
+#if 1 // defined(SDLMAME_WIN32)
/*
* We need to do this here. If SDL_ListModes is
* called in init_monitors, the call will crash