- Moved OS specific low level code to osd/modules/lib.

- Removed duplicate code 
- Should support LIB/BASELIB separation better going forward
This commit is contained in:
couriersud 2015-01-09 03:01:20 +01:00
parent 944805f253
commit 14e96b6f9d
26 changed files with 70 additions and 555 deletions

View File

@ -1,16 +1,24 @@
//============================================================
//
// sdlos.h - SDLMAME OS dependent functions
// osdlib.h
//
// Copyright (c) 1996-2007, Nicola Salmoria and the MAME Team.
// Copyright (c) 1996-2014, Nicola Salmoria and the MAME Team.
// Visit http://mamedev.org for licensing and usage restrictions.
//
// SDLMAME by Olivier Galibert and R. Belmont
//
// - Common low level routines
// - Source files also provide the following from osdcore.h
//
// - osd_ticks
// - osd_sleep
// - osd_malloc
// - osd_malloc_array
// - osd_free
//============================================================
#ifndef __SDLOS__
#define __SDLOS__
#ifndef __OSDLIB__
#define __OSDLIB__
/*-----------------------------------------------------------------------------
osd_num_processors: return the number of processors
@ -25,6 +33,18 @@
-----------------------------------------------------------------------------*/
int osd_get_num_processors(void);
/*-----------------------------------------------------------------------------
osd_process_kill: kill the current process
Parameters:
None.
Return value:
None.
-----------------------------------------------------------------------------*/
void osd_process_kill(void);
/*-----------------------------------------------------------------------------
osd_getenv: return pointer to environment variable
@ -55,4 +75,4 @@ char *osd_getenv(const char *name);
int osd_setenv(const char *name, const char *value, int overwrite);
#endif /* __SDLOS__ */
#endif /* __OSDLIB__ */

View File

@ -172,19 +172,6 @@ int osd_thread_cpu_affinity(osd_thread *thread, UINT32 mask);
-----------------------------------------------------------------------------*/
void osd_thread_wait_free(osd_thread *thread);
/*-----------------------------------------------------------------------------
osd_process_kill: kill the current process
Parameters:
None.
Return value:
None.
-----------------------------------------------------------------------------*/
void osd_process_kill(void);
//============================================================
// Scalable Locks
//============================================================

View File

@ -161,11 +161,3 @@ void osd_thread_wait_free(osd_thread *thread)
{
}
//============================================================
// osd_process_kill
//============================================================
void osd_process_kill(void)
{
}

View File

@ -524,11 +524,3 @@ void osd_thread_wait_free(osd_thread *thread)
free(thread);
}
//============================================================
// osd_process_kill
//============================================================
void osd_process_kill(void)
{
kill(getpid(), SIGKILL);
}

View File

@ -359,11 +359,3 @@ void osd_thread_wait_free(osd_thread *thread)
free(thread);
}
//============================================================
// osd_process_kill
//============================================================
void osd_process_kill(void)
{
kill(getpid(), SIGKILL);
}

View File

@ -382,11 +382,3 @@ void osd_thread_wait_free(osd_thread *thread)
free(thread);
}
//============================================================
// osd_process_kill
//============================================================
void osd_process_kill(void)
{
kill(getpid(), SIGKILL);
}

View File

@ -311,15 +311,6 @@ int osd_thread_cpu_affinity(osd_thread *thread, UINT32 mask)
return TRUE;
}
//============================================================
// osd_process_kill
//============================================================
void osd_process_kill(void)
{
TerminateProcess(GetCurrentProcess(), -1);
}
//============================================================
// Scalable Locks
//============================================================

View File

@ -26,13 +26,7 @@
#include "osdcore.h"
#include "modules/sync/osdsync.h"
#if defined(OSD_WINDOWS)
#include "winos.h"
#elif defined(OSD_SDL)
#include "sdlos.h"
typedef void *PVOID;
#endif
#include "modules/lib/osdlib.h"
#include "eminline.h"
@ -40,6 +34,9 @@ typedef void *PVOID;
#include "osxutils.h"
#endif
#if defined(OSD_SDL)
typedef void *PVOID;
#endif
//============================================================
// DEBUGGING

View File

@ -82,13 +82,3 @@ char *osd_get_clipboard_text(void)
return NULL;
}
//============================================================
// osd_get_slider_list
//============================================================
const void *osd_get_slider_list()
{
// nothing to slide in mini OSD
return NULL;
}

View File

@ -28,7 +28,7 @@
// OpenGL headers
#include "osd_opengl.h"
#include "sdlos.h"
#include "modules/lib/osdlib.h"
#include "gl_shader_tool.h"

View File

@ -391,7 +391,7 @@ endif
SDLSRC = $(SRC)/osd/$(OSD)
SDLOBJ = $(OBJ)/osd/$(OSD)
OBJDIRS += $(SDLOBJ) $(OSDOBJ)/modules/sync
OBJDIRS += $(SDLOBJ) $(OSDOBJ)/modules/sync $(OSDOBJ)/modules/lib
#-------------------------------------------------
# OSD core library
@ -405,6 +405,7 @@ OSDCOREOBJS = \
$(SDLOBJ)/sdlsocket.o \
$(SDLOBJ)/sdlmisc_$(BASE_TARGETOS).o \
$(SDLOBJ)/sdlos_$(SDLOS_TARGETOS).o \
$(OSDOBJ)/modules/lib/osdlib_$(SDLOS_TARGETOS).o \
$(OSDOBJ)/modules/sync/sync_$(SYNC_IMPLEMENTATION).o
ifdef NOASM

View File

@ -37,7 +37,7 @@
#include <dirent.h>
#include "osdcore.h"
#include "sdlos.h"
#include "modules/lib/osdlib.h"
#if defined(SDLMAME_WIN32) || defined(SDLMAME_OS2)
#define PATHSEPCH '\\'

View File

@ -41,7 +41,7 @@
// MAME headers
#include "sdlfile.h"
#include "modules/lib/osdlib.h"
//============================================================
// GLOBAL IDENTIFIERS

View File

@ -10,7 +10,6 @@
//============================================================
#include "osdcore.h"
#include "sdlos.h"
//============================================================
// ENUM DEFINITIONS

View File

@ -52,7 +52,7 @@
#include "video.h"
#include "input.h"
#include "osdsdl.h"
#include "sdlos.h"
#include "modules/lib/osdlib.h"
#include "modules/sound/sdl_sound.h"
#if defined(SDLMAME_EMSCRIPTEN)
#include "modules/sound/js_sound.h"
@ -269,21 +269,17 @@ sdl_options::sdl_options()
// we do some special sauce on Win32...
#if !defined(SDLMAME_WIN32)
int main(int argc, char **argv)
{
int res = 0;
#else
#if defined(SDLMAME_WIN32)
/* gee */
extern "C" DECLSPEC void SDLCALL SDL_SetModuleHandle(void *hInst);
#endif
// translated to utf8_main
int main(int argc, char *argv[])
{
int res = 0;
#if defined(SDLMAME_WIN32)
#if !(SDLMAME_SDL2)
/* Load SDL dynamic link library */
if ( SDL_Init(SDL_INIT_NOPARACHUTE) < 0 ) {
@ -293,6 +289,7 @@ int main(int argc, char *argv[])
SDL_SetModuleHandle(GetModuleHandle(NULL));
#endif
#endif
// disable I/O buffering
setvbuf(stdout, (char *) NULL, _IONBF, 0);
setvbuf(stderr, (char *) NULL, _IONBF, 0);
@ -527,6 +524,7 @@ static void osd_sdl_info(void)
{
osd_printf_verbose("\t%-20s\n", SDL_GetAudioDriver(i));
}
#endif
}

View File

@ -139,88 +139,6 @@ void osd_sleep(osd_ticks_t duration)
}
}
//============================================================
// osd_num_processors
//============================================================
int osd_get_num_processors(void)
{
int processors = 1;
struct host_basic_info host_basic_info;
unsigned int count;
kern_return_t r;
mach_port_t my_mach_host_self;
count = HOST_BASIC_INFO_COUNT;
my_mach_host_self = mach_host_self();
if ( ( r = host_info(my_mach_host_self, HOST_BASIC_INFO, (host_info_t)(&host_basic_info), &count)) == KERN_SUCCESS )
{
processors = host_basic_info.avail_cpus;
}
mach_port_deallocate(mach_task_self(), my_mach_host_self);
return processors;
}
//============================================================
// osd_malloc
//============================================================
void *osd_malloc(size_t size)
{
#ifndef MALLOC_DEBUG
return malloc(size);
#else
#error "MALLOC_DEBUG not yet supported"
#endif
}
//============================================================
// osd_malloc_array
//============================================================
void *osd_malloc_array(size_t size)
{
#ifndef MALLOC_DEBUG
return malloc(size);
#else
#error "MALLOC_DEBUG not yet supported"
#endif
}
//============================================================
// osd_free
//============================================================
void osd_free(void *ptr)
{
#ifndef MALLOC_DEBUG
free(ptr);
#else
#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);
}
//============================================================
// osd_get_clipboard_text
@ -364,15 +282,6 @@ const char *osd_get_volume_name(int idx)
return "/";
}
//============================================================
// osd_get_slider_list
//============================================================
const void *osd_get_slider_list()
{
return NULL;
}
//============================================================
// osd_get_full_path
//============================================================

View File

@ -308,15 +308,6 @@ const char *osd_get_volume_name(int idx)
return szDrive;
}
//============================================================
// osd_get_slider_list
//============================================================
const void *osd_get_slider_list()
{
return NULL;
}
//============================================================
// osd_get_full_path
//============================================================

View File

@ -70,80 +70,6 @@ void osd_sleep(osd_ticks_t duration)
}
}
//============================================================
// osd_num_processors
//============================================================
int osd_get_num_processors(void)
{
int processors = 1;
#if defined(_SC_NPROCESSORS_ONLN)
processors = sysconf(_SC_NPROCESSORS_ONLN);
#endif
return processors;
}
//============================================================
// osd_malloc
//============================================================
void *osd_malloc(size_t size)
{
#ifndef MALLOC_DEBUG
return malloc(size);
#else
#error "MALLOC_DEBUG not yet supported"
#endif
}
//============================================================
// osd_malloc_array
//============================================================
void *osd_malloc_array(size_t size)
{
#ifndef MALLOC_DEBUG
return malloc(size);
#else
#error "MALLOC_DEBUG not yet supported"
#endif
}
//============================================================
// osd_free
//============================================================
void osd_free(void *ptr)
{
#ifndef MALLOC_DEBUG
free(ptr);
#else
#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);
}
#if (SDLMAME_SDL2)
//============================================================
@ -308,15 +234,6 @@ const char *osd_get_volume_name(int idx)
return "/";
}
//============================================================
// osd_get_slider_list
//============================================================
const void *osd_get_slider_list()
{
return NULL;
}
//============================================================
// osd_get_full_path
//============================================================

View File

@ -20,8 +20,6 @@
#include "osdcore.h"
#include "strconv.h"
#include "../windows/winos.c"
//============================================================
// PROTOTYPES
//============================================================
@ -159,112 +157,6 @@ void osd_sleep(osd_ticks_t duration)
}
}
//============================================================
// osd_malloc
//============================================================
void *osd_malloc(size_t size)
{
#ifndef MALLOC_DEBUG
return HeapAlloc(GetProcessHeap(), 0, size);
#else
// add in space for the size
size += sizeof(size_t);
// basic objects just come from the heap
void *result = HeapAlloc(GetProcessHeap(), 0, size);
// store the size and return and pointer to the data afterward
*reinterpret_cast<size_t *>(result) = size;
return reinterpret_cast<UINT8 *>(result) + sizeof(size_t);
#endif
}
//============================================================
// osd_malloc_array
//============================================================
void *osd_malloc_array(size_t size)
{
#ifndef MALLOC_DEBUG
return HeapAlloc(GetProcessHeap(), 0, size);
#else
// add in space for the size
size += sizeof(size_t);
// round the size up to a page boundary
size_t rounded_size = ((size + sizeof(void *) + PAGE_SIZE - 1) / PAGE_SIZE) * PAGE_SIZE;
// reserve that much memory, plus two guard pages
void *page_base = VirtualAlloc(NULL, rounded_size + 2 * PAGE_SIZE, MEM_RESERVE, PAGE_NOACCESS);
if (page_base == NULL)
return NULL;
// now allow access to everything but the first and last pages
page_base = VirtualAlloc(reinterpret_cast<UINT8 *>(page_base) + PAGE_SIZE, rounded_size, MEM_COMMIT, PAGE_READWRITE);
if (page_base == NULL)
return NULL;
// work backwards from the page base to get to the block base
void *result = GUARD_ALIGN_START ? page_base : (reinterpret_cast<UINT8 *>(page_base) + rounded_size - size);
// store the size at the start with a flag indicating it has a guard page
*reinterpret_cast<size_t *>(result) = size | 0x80000000;
return reinterpret_cast<UINT8 *>(result) + sizeof(size_t);
#endif
}
//============================================================
// osd_free
//============================================================
void osd_free(void *ptr)
{
#ifndef MALLOC_DEBUG
HeapFree(GetProcessHeap(), 0, ptr);
#else
size_t size = reinterpret_cast<size_t *>(ptr)[-1];
// if no guard page, just free the pointer
if ((size & 0x80000000) == 0)
HeapFree(GetProcessHeap(), 0, reinterpret_cast<UINT8 *>(ptr) - sizeof(size_t));
// large items need more care
else
{
ULONG_PTR page_base = (reinterpret_cast<ULONG_PTR>(ptr) - sizeof(size_t)) & ~(PAGE_SIZE - 1);
VirtualFree(reinterpret_cast<void *>(page_base - PAGE_SIZE), 0, MEM_RELEASE);
}
#endif
}
//============================================================
// osd_setenv
//============================================================
int osd_setenv(const char *name, const char *value, int overwrite)
{
char *buf;
int result;
if (!overwrite)
{
if (osd_getenv(name) != NULL)
return 0;
}
buf = (char *) osd_malloc_array(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;
}
//============================================================
// get_clipboard_text_by_format
//============================================================
@ -459,15 +351,6 @@ const char *osd_get_volume_name(int idx)
return p;
}
//============================================================
// osd_get_slider_list
//============================================================
const void *osd_get_slider_list()
{
return NULL;
}
//============================================================
// win_error_to_mame_file_error
//============================================================

View File

@ -50,7 +50,7 @@
#include "window.h"
#include "input.h"
#include "osdsdl.h"
#include "sdlos.h"
#include "modules/lib/osdlib.h"
//============================================================
// CONSTANTS

View File

@ -18,6 +18,7 @@
#endif
#include "watchdog.h"
#include "modules/lib/osdlib.h"
static void *watchdog_thread(void *param)
{

View File

@ -235,6 +235,7 @@ bool sdl_osd_interface::window_init()
if (work_queue == NULL)
return false;
osd_work_item_queue(work_queue, &sdlwindow_thread_id, NULL, WORK_ITEM_FLAG_AUTO_RELEASE);
sdlwindow_sync();
}
else
{
@ -264,6 +265,31 @@ bool sdl_osd_interface::window_init()
return false;
}
#if SDLMAME_SDL2
/* We may want to set a number of the hints SDL2 provides.
* The code below will document which hints were set.
*/
const char * hints[] = { SDL_HINT_RENDER_DRIVER, SDL_HINT_RENDER_OPENGL_SHADERS,
SDL_HINT_RENDER_DIRECT3D_THREADSAFE, SDL_HINT_RENDER_SCALE_QUALITY,
SDL_HINT_RENDER_VSYNC, SDL_HINT_VIDEO_ALLOW_SCREENSAVER,
SDL_HINT_VIDEO_X11_XVIDMODE, SDL_HINT_VIDEO_X11_XINERAMA,
SDL_HINT_VIDEO_X11_XRANDR, SDL_HINT_GRAB_KEYBOARD,
SDL_HINT_MOUSE_RELATIVE_MODE_WARP,
SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS, SDL_HINT_IDLE_TIMER_DISABLED,
SDL_HINT_ORIENTATIONS, SDL_HINT_ACCELEROMETER_AS_JOYSTICK,
SDL_HINT_XINPUT_ENABLED, SDL_HINT_GAMECONTROLLERCONFIG,
SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, SDL_HINT_ALLOW_TOPMOST,
SDL_HINT_TIMER_RESOLUTION, SDL_HINT_MAC_CTRL_CLICK_EMULATE_RIGHT_CLICK,
SDL_HINT_VIDEO_WIN_D3DCOMPILER, SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT,
SDL_HINT_VIDEO_MAC_FULLSCREEN_SPACES,
NULL
};
osd_printf_verbose("\nHints:\n");
for (int i = 0; hints[i] != NULL; i++)
osd_printf_verbose("\t%-40s %s\n", hints[i], SDL_GetHint(hints[i]));
#endif
// set up the window list
last_window_ptr = &sdl_window_list;
osd_printf_verbose("Leave sdlwindow_init\n");

View File

@ -84,7 +84,7 @@ WINOBJ = $(OBJ)/osd/$(OSD)
OSDSRC = $(SRC)/osd
OSDOBJ = $(OBJ)/osd
OBJDIRS += $(WINOBJ) $(OSDOBJ)/modules/sync
OBJDIRS += $(WINOBJ) $(OSDOBJ)/modules/sync $(OSDOBJ)/modules/lib
ifdef USE_QTDEBUG
OBJDIRS += $(OSDOBJ)/modules/debugger/qt
@ -350,8 +350,8 @@ OSDCOREOBJS = \
$(WINOBJ)/winclip.o \
$(WINOBJ)/winsocket.o \
$(OSDOBJ)/modules/sync/work_osd.o \
$(OSDOBJ)/modules/lib/osdlib_win32.o \
$(WINOBJ)/winptty.o \
$(WINOBJ)/winos.o \
#-------------------------------------------------

View File

@ -20,18 +20,6 @@
#include "strconv.h"
//============================================================
// MACROS
//============================================================
// presumed size of a page of memory
#define PAGE_SIZE 4096
// align allocations to start or end of the page?
#define GUARD_ALIGN_START 0
//============================================================
// GLOBAL VARIABLES
//============================================================
@ -39,89 +27,6 @@
void (*s_debugger_stack_crawler)() = NULL;
//============================================================
// osd_malloc
//============================================================
void *osd_malloc(size_t size)
{
#ifndef MALLOC_DEBUG
return HeapAlloc(GetProcessHeap(), 0, size);
#else
// add in space for the size
size += sizeof(size_t);
// basic objects just come from the heap
void *result = HeapAlloc(GetProcessHeap(), 0, size);
// store the size and return and pointer to the data afterward
*reinterpret_cast<size_t *>(result) = size;
return reinterpret_cast<UINT8 *>(result) + sizeof(size_t);
#endif
}
//============================================================
// osd_malloc_array
//============================================================
void *osd_malloc_array(size_t size)
{
#ifndef MALLOC_DEBUG
return HeapAlloc(GetProcessHeap(), 0, size);
#else
// add in space for the size
size += sizeof(size_t);
// round the size up to a page boundary
size_t rounded_size = ((size + sizeof(void *) + PAGE_SIZE - 1) / PAGE_SIZE) * PAGE_SIZE;
// reserve that much memory, plus two guard pages
void *page_base = VirtualAlloc(NULL, rounded_size + 2 * PAGE_SIZE, MEM_RESERVE, PAGE_NOACCESS);
if (page_base == NULL)
return NULL;
// now allow access to everything but the first and last pages
page_base = VirtualAlloc(reinterpret_cast<UINT8 *>(page_base) + PAGE_SIZE, rounded_size, MEM_COMMIT, PAGE_READWRITE);
if (page_base == NULL)
return NULL;
// work backwards from the page base to get to the block base
void *result = GUARD_ALIGN_START ? page_base : (reinterpret_cast<UINT8 *>(page_base) + rounded_size - size);
// store the size at the start with a flag indicating it has a guard page
*reinterpret_cast<size_t *>(result) = size | 0x80000000;
return reinterpret_cast<UINT8 *>(result) + sizeof(size_t);
#endif
}
//============================================================
// osd_free
//============================================================
void osd_free(void *ptr)
{
#ifndef MALLOC_DEBUG
HeapFree(GetProcessHeap(), 0, ptr);
#else
size_t size = reinterpret_cast<size_t *>(ptr)[-1];
// if no guard page, just free the pointer
if ((size & 0x80000000) == 0)
HeapFree(GetProcessHeap(), 0, reinterpret_cast<UINT8 *>(ptr) - sizeof(size_t));
// large items need more care
else
{
ULONG_PTR page_base = (reinterpret_cast<ULONG_PTR>(ptr) - sizeof(size_t)) & ~(PAGE_SIZE - 1);
VirtualFree(reinterpret_cast<void *>(page_base - PAGE_SIZE), 0, MEM_RELEASE);
}
#endif
}
//============================================================
// osd_alloc_executable
//============================================================

View File

@ -1,36 +0,0 @@
//============================================================
//
// winos.c - Win32 OS specific low level code
//
//============================================================
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <stdlib.h>
// MAME headers
#include "osdcore.h"
//============================================================
// osd_num_processors
//============================================================
int osd_get_num_processors(void)
{
SYSTEM_INFO info;
// otherwise, fetch the info from the system
GetSystemInfo(&info);
// max out at 4 for now since scaling above that seems to do poorly
return MIN(info.dwNumberOfProcessors, 4);
}
//============================================================
// osd_getenv
//============================================================
char *osd_getenv(const char *name)
{
return getenv(name);
}

View File

@ -1,32 +0,0 @@
//============================================================
//
// winos.h - Win32 OS specific low level code
//
//============================================================
/*-----------------------------------------------------------------------------
osd_num_processors: return the number of processors
Parameters:
None.
Return value:
Number of processors
-----------------------------------------------------------------------------*/
int osd_get_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);