From d27238751ff8e0f757d91feffb2536c5ad3350eb Mon Sep 17 00:00:00 2001 From: Ozkan Sezer Date: Wed, 14 Oct 2020 23:01:06 +0300 Subject: [PATCH] os2: integrate the port into main tree. --- Makefile.os2 | 17 ++++++++++++++++- include/SDL_config_os2.h | 10 ++++++---- include/SDL_syswm.h | 23 +++++++++++++++++++++++ src/SDL.c | 17 +++++++++++++++++ src/audio/SDL_audio.c | 3 +++ src/audio/SDL_sysaudio.h | 1 + src/events/SDL_mouse.c | 6 ++++++ src/thread/SDL_thread_c.h | 2 ++ src/video/SDL_sysvideo.h | 2 ++ src/video/SDL_video.c | 17 +++++++++++++++-- test/Makefile.os2 | 6 +++++- test/testnative.c | 3 +++ test/testnative.h | 5 +++++ 13 files changed, 104 insertions(+), 8 deletions(-) diff --git a/Makefile.os2 b/Makefile.os2 index b23be1373..68eece1b3 100644 --- a/Makefile.os2 +++ b/Makefile.os2 @@ -12,6 +12,7 @@ LNKFILE = $(LIBNAME).lnk INCPATH = -I"$(%WATCOM)/h/os2" -I"$(%WATCOM)/h" INCPATH+= -Iinclude +INCPATH+= -I"src/core/os2" -I"src/core/os2/geniconv" LIBM = libm.lib LIBS = mmpm2.lib libuls.lib libconv.lib $(LIBM) @@ -26,6 +27,12 @@ CFLAGS+= $(INCPATH) # building SDL itself (for DECLSPEC): CFLAGS+= -DBUILD_SDL +# Debug options: +# - debug messages from OS/2 related code to stdout: +#CFLAGS+= -DOS2DEBUG +# - debug messages from OS/2 code via SDL_LogDebug(): +#CFLAGS+= -DOS2DEBUG=2 + MSRCS= e_atan2.c e_exp.c e_fmod.c e_log10.c e_log.c e_pow.c e_rem_pio2.c e_sqrt.c & k_cos.c k_rem_pio2.c k_sin.c k_tan.c & s_atan.c s_copysign.c s_cos.c s_fabs.c s_floor.c s_scalbn.c s_sin.c s_tan.c @@ -58,6 +65,11 @@ SRCS+= SDL_dummysensor.c SRCS+= SDL_locale.c SDL_syslocale.c SRCS+= SDL_url.c SDL_sysurl.c +SRCS+= SDL_os2.c geniconv.c os2cp.c os2iconv.c sys2utf8.c +SRCS+= SDL_os2audio.c +SRCS+= SDL_os2video.c SDL_os2util.c SDL_os2dive.c SDL_os2vman.c & + SDL_os2mouse.c SDL_os2messagebox.c + SRCS+= SDL_dynapi.c OBJS = $(SRCS:.c=.obj) @@ -68,7 +80,7 @@ MOBJS= $(MSRCS:.c=.obj) .c: ./src;./src/dynapi;./src/audio;./src/cpuinfo;./src/events;./src/file;./src/haptic;./src/joystick;./src/power;./src/render;./src/render/software;./src/sensor;./src/stdlib;./src/thread;./src/timer;./src/video;./src/video/yuv2rgb;./src/atomic;./src/audio/disk; .c: ./src/haptic/dummy;./src/joystick/dummy;./src/audio/dummy;./src/video/dummy;./src/sensor/dummy; -.c: ./src/loadso/dummy;./src/filesystem/dummy;./src/timer/dummy;./src/thread/generic; +.c: ./src/core/os2;./src/core/os2/geniconv;./src/audio/os2;./src/loadso/os2;./src/filesystem/os2;./src/thread/os2;./src/timer/os2;./src/video/os2; .c: ./src/locale/;./src/locale/unix;./src/misc;./src/misc/dummy; all: $(DLLFILE) $(LIBFILE) .symbolic @@ -84,6 +96,9 @@ $(LIBFILE): $(DLLFILE) .c.obj: wcc386 $(CFLAGS) -fo=$^@ $< +SDL_syscond.obj: "src/thread/generic/SDL_syscond.c" + wcc386 $(CFLAGS) -fo=$^@ $< + SDL_cpuinfo.obj: SDL_cpuinfo.c wcc386 $(CFLAGS) -wcd=200 -fo=$^@ $< diff --git a/include/SDL_config_os2.h b/include/SDL_config_os2.h index eedf79c13..ea483b68f 100644 --- a/include/SDL_config_os2.h +++ b/include/SDL_config_os2.h @@ -27,6 +27,7 @@ #define SDL_AUDIO_DRIVER_DUMMY 1 #define SDL_AUDIO_DRIVER_DISK 1 +#define SDL_AUDIO_DRIVER_OS2 1 #define SDL_POWER_DISABLED 1 #define SDL_JOYSTICK_DISABLED 1 @@ -34,6 +35,7 @@ #define SDL_SENSOR_DUMMY 1 #define SDL_VIDEO_DRIVER_DUMMY 1 +#define SDL_VIDEO_DRIVER_OS2 1 /* Enable OpenGL support */ /* #undef SDL_VIDEO_OPENGL */ @@ -41,10 +43,10 @@ /* Enable Vulkan support */ /* #undef SDL_VIDEO_VULKAN */ -#define SDL_LOADSO_DISABLED 1 -#define SDL_THREADS_DISABLED 1 -#define SDL_TIMERS_DISABLED 1 -#define SDL_FILESYSTEM_DUMMY 1 +#define SDL_THREAD_OS2 1 +#define SDL_LOADSO_OS2 1 +#define SDL_TIMER_OS2 1 +#define SDL_FILESYSTEM_OS2 1 /* Enable assembly routines */ #define SDL_ASSEMBLY_ROUTINES 1 diff --git a/include/SDL_syswm.h b/include/SDL_syswm.h index e877b2aad..f0e9675d7 100644 --- a/include/SDL_syswm.h +++ b/include/SDL_syswm.h @@ -106,6 +106,11 @@ typedef void *EGLSurface; #if defined(SDL_VIDEO_DRIVER_VIVANTE) #include "SDL_egl.h" #endif + +#if defined(SDL_VIDEO_DRIVER_OS2) +#define INCL_WIN +#include +#endif #endif /* SDL_PROTOTYPES_ONLY */ @@ -186,6 +191,16 @@ struct SDL_SysWMmsg int dummy; /* No Vivante window events yet */ } vivante; +#endif +#if defined(SDL_VIDEO_DRIVER_OS2) + struct + { + BOOL fFrame; /**< TRUE if hwnd is a frame window */ + HWND hwnd; /**< The window receiving the message */ + ULONG msg; /**< The message identifier */ + MPARAM mp1; /**< The first first message parameter */ + MPARAM mp2; /**< The second first message parameter */ + } os2; #endif /* Can't have an empty union */ int dummy; @@ -280,6 +295,14 @@ struct SDL_SysWMinfo } android; #endif +#if defined(SDL_VIDEO_DRIVER_OS2) + struct + { + HWND hwnd; /**< The window handle */ + HWND hwndFrame; /**< The frame window handle */ + } os2; +#endif + #if defined(SDL_VIDEO_DRIVER_VIVANTE) struct { diff --git a/src/SDL.c b/src/SDL.c index 680ed2e7d..02e131bb0 100644 --- a/src/SDL.c +++ b/src/SDL.c @@ -27,6 +27,12 @@ #elif !defined(__WINRT__) #include /* For _exit(), etc. */ #endif +#if defined(__OS2__) +#include "core/os2/SDL_os2.h" +#endif +#if SDL_THREAD_OS2 +#include "thread/os2/SDL_systls_c.h" +#endif #if defined(__EMSCRIPTEN__) #include @@ -159,6 +165,10 @@ SDL_InitSubSystem(Uint32 flags) flags |= SDL_INIT_EVENTS; } +#if SDL_THREAD_OS2 + SDL_OS2TLSAlloc(); /* thread/os2/SDL_systls.c */ +#endif + #if SDL_VIDEO_DRIVER_WINDOWS if ((flags & (SDL_INIT_HAPTIC|SDL_INIT_JOYSTICK))) { if (SDL_HelperWindowCreate() < 0) { @@ -294,6 +304,13 @@ SDL_Init(Uint32 flags) void SDL_QuitSubSystem(Uint32 flags) { +#if SDL_THREAD_OS2 + SDL_OS2TLSFree(); /* thread/os2/SDL_systls.c */ +#endif +#if defined(__OS2__) + SDL_OS2Quit(); +#endif + /* Shut down requested initialized subsystems */ #if !SDL_SENSOR_DISABLED if ((flags & SDL_INIT_SENSOR)) { diff --git a/src/audio/SDL_audio.c b/src/audio/SDL_audio.c index 313749323..bacee6c90 100644 --- a/src/audio/SDL_audio.c +++ b/src/audio/SDL_audio.c @@ -104,6 +104,9 @@ static const AudioBootStrap *const bootstrap[] = { #if SDL_AUDIO_DRIVER_JACK &JACK_bootstrap, #endif +#if SDL_AUDIO_DRIVER_OS2 + &OS2AUDIO_bootstrap, +#endif #if SDL_AUDIO_DRIVER_DISK &DISKAUDIO_bootstrap, #endif diff --git a/src/audio/SDL_sysaudio.h b/src/audio/SDL_sysaudio.h index 7359adcc9..350a6d0a0 100644 --- a/src/audio/SDL_sysaudio.h +++ b/src/audio/SDL_sysaudio.h @@ -207,6 +207,7 @@ extern AudioBootStrap openslES_bootstrap; extern AudioBootStrap ANDROIDAUDIO_bootstrap; extern AudioBootStrap PSPAUDIO_bootstrap; extern AudioBootStrap EMSCRIPTENAUDIO_bootstrap; +extern AudioBootStrap OS2AUDIO_bootstrap; #endif /* SDL_sysaudio_h_ */ diff --git a/src/events/SDL_mouse.c b/src/events/SDL_mouse.c index 03bae6b74..50065e4e8 100644 --- a/src/events/SDL_mouse.c +++ b/src/events/SDL_mouse.c @@ -32,6 +32,10 @@ #ifdef __WIN32__ #include "../core/windows/SDL_windows.h" // For GetDoubleClickTime() #endif +#if defined(__OS2__) +#define INCL_WIN +#include +#endif /* #define DEBUG_MOUSE */ @@ -54,6 +58,8 @@ SDL_MouseDoubleClickTimeChanged(void *userdata, const char *name, const char *ol } else { #ifdef __WIN32__ mouse->double_click_time = GetDoubleClickTime(); +#elif defined(__OS2__) + mouse->double_click_time = WinQuerySysValue(HWND_DESKTOP, SV_DBLCLKTIME); #else mouse->double_click_time = 500; #endif diff --git a/src/thread/SDL_thread_c.h b/src/thread/SDL_thread_c.h index ac0071e1b..c82b59e23 100644 --- a/src/thread/SDL_thread_c.h +++ b/src/thread/SDL_thread_c.h @@ -36,6 +36,8 @@ #include "psp/SDL_systhread_c.h" #elif SDL_THREAD_STDCPP #include "stdcpp/SDL_systhread_c.h" +#elif SDL_THREAD_OS2 +#include "os2/SDL_systhread_c.h" #else #error Need thread implementation for this platform #include "generic/SDL_systhread_c.h" diff --git a/src/video/SDL_sysvideo.h b/src/video/SDL_sysvideo.h index 81322b3c4..056703539 100644 --- a/src/video/SDL_sysvideo.h +++ b/src/video/SDL_sysvideo.h @@ -436,6 +436,8 @@ extern VideoBootStrap VIVANTE_bootstrap; extern VideoBootStrap Emscripten_bootstrap; extern VideoBootStrap QNX_bootstrap; extern VideoBootStrap OFFSCREEN_bootstrap; +extern VideoBootStrap OS2DIVE_bootstrap; +extern VideoBootStrap OS2VMAN_bootstrap; extern SDL_VideoDevice *SDL_GetVideoDevice(void); extern int SDL_AddBasicVideoDisplay(const SDL_DisplayMode * desktop_mode); diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c index 3f89c4374..36d42ce1e 100644 --- a/src/video/SDL_video.c +++ b/src/video/SDL_video.c @@ -112,6 +112,10 @@ static VideoBootStrap *bootstrap[] = { #if SDL_VIDEO_DRIVER_OFFSCREEN &OFFSCREEN_bootstrap, #endif +#if SDL_VIDEO_DRIVER_OS2 + &OS2DIVE_bootstrap, + &OS2VMAN_bootstrap, +#endif #if SDL_VIDEO_DRIVER_DUMMY &DUMMY_bootstrap, #endif @@ -3926,9 +3930,11 @@ SDL_IsScreenKeyboardShown(SDL_Window *window) #if SDL_VIDEO_DRIVER_HAIKU #include "haiku/SDL_bmessagebox.h" #endif +#if SDL_VIDEO_DRIVER_OS2 +#include "os2/SDL_os2messagebox.h" +#endif - -#if SDL_VIDEO_DRIVER_WINDOWS || SDL_VIDEO_DRIVER_WINRT || SDL_VIDEO_DRIVER_COCOA || SDL_VIDEO_DRIVER_UIKIT || SDL_VIDEO_DRIVER_X11 || SDL_VIDEO_DRIVER_HAIKU +#if SDL_VIDEO_DRIVER_WINDOWS || SDL_VIDEO_DRIVER_WINRT || SDL_VIDEO_DRIVER_COCOA || SDL_VIDEO_DRIVER_UIKIT || SDL_VIDEO_DRIVER_X11 || SDL_VIDEO_DRIVER_HAIKU || SDL_VIDEO_DRIVER_OS2 static SDL_bool SDL_MessageboxValidForDriver(const SDL_MessageBoxData *messageboxdata, SDL_SYSWM_TYPE drivertype) { SDL_SysWMinfo info; @@ -4027,6 +4033,13 @@ SDL_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid) HAIKU_ShowMessageBox(messageboxdata, buttonid) == 0) { retval = 0; } +#endif +#if SDL_VIDEO_DRIVER_OS2 + if (retval == -1 && + SDL_MessageboxValidForDriver(messageboxdata, SDL_SYSWM_OS2) && + OS2_ShowMessageBox(messageboxdata, buttonid) == 0) { + retval = 0; + } #endif if (retval == -1) { SDL_SetError("No message system available"); diff --git a/test/Makefile.os2 b/test/Makefile.os2 index f9ec898fc..76763691f 100644 --- a/test/Makefile.os2 +++ b/test/Makefile.os2 @@ -13,7 +13,7 @@ TARGETS = testatomic.exe testdisplayinfo.exe testbounds.exe testdraw2.exe & testviewport.exe testwm2.exe torturethread.exe checkkeys.exe & controllermap.exe testhaptic.exe testqsort.exe testresample.exe & testaudioinfo.exe testaudiocapture.exe loopwave.exe loopwavequeue.exe & - testyuv.exe testgl2.exe testvulkan.exe testautomation.exe + testyuv.exe testgl2.exe testvulkan.exe testnative.exe testautomation.exe # SDL2test.lib sources (../src/test) @@ -69,6 +69,10 @@ testautomation.exe: $(TAOBJS) @%make $(TESTLIB) wlink SYS os2v2 libpath $(LIBPATH) lib {$(LIBS)} op q op el file {$<} name $@ +testnative.exe: testnative.obj testnativeos2.obj + @%make $(TESTLIB) + wlink SYS os2v2 libpath $(LIBPATH) lib {$(LIBS)} op q op el file {$<} name $@ + testoverlay2.exe: testoverlay2.obj testyuv_cvt.obj @%make $(TESTLIB) wlink SYS os2v2 libpath $(LIBPATH) lib {$(LIBS)} op q op el file {$<} name $@ diff --git a/test/testnative.c b/test/testnative.c index 353262b74..675c8f41e 100644 --- a/test/testnative.c +++ b/test/testnative.c @@ -31,6 +31,9 @@ static NativeWindowFactory *factories[] = { #endif #ifdef TEST_NATIVE_COCOA &CocoaWindowFactory, +#endif +#ifdef TEST_NATIVE_OS2 + &OS2WindowFactory, #endif NULL }; diff --git a/test/testnative.h b/test/testnative.h index 428d607d4..d7b40fb3d 100644 --- a/test/testnative.h +++ b/test/testnative.h @@ -44,3 +44,8 @@ extern NativeWindowFactory X11WindowFactory; #define TEST_NATIVE_COCOA extern NativeWindowFactory CocoaWindowFactory; #endif + +#ifdef SDL_VIDEO_DRIVER_OS2 +#define TEST_NATIVE_OS2 +extern NativeWindowFactory OS2WindowFactory; +#endif