From c765ca5cc89fa97459afd6d78afd08dfe6a4301f Mon Sep 17 00:00:00 2001 From: Nick Briggs Date: Tue, 21 May 2024 12:07:13 -0700 Subject: [PATCH] Update SDL dependent code and makefile segments to prepare for SDL3 (#497) * Update SDL dependent code and makefile segments to prepare for SDL3 Many APIs have changed between SDL2 and SDL3. This update adds preprocessor conditionals to adapt the Maiko SDL code to allow selection of the SDL major version (2 or 3) from the -DSDL=n define. The SDL3 implementation is currently available as a preview release, 3.1.0, at https://github.com/libsdl-org/SDL/releases/tag/prerelease-3.1.0 * Add updates for makefile-haiku.x86_64-sdl to prepare for SDL3 * Allow makeright to accept sdl3 as display type to ease SDL3 experiments * Update CMakeLists.txt for SDL3 library * Replaces configuration option -DMAIKO_DISPLAY_SDL=ON/OFF with -DMAIKO_DISPLAY_SDL=OFF/2/3 * Replaces PUBLIC definitions with PRIVATE definitions on targets since we are not exporting definitions outside this local compilation * Update messages to indicate which version of SDL is being configured * Add fixup for SDL3.xcframework on macOS to compensate for missing RPATH specification (CMake issue 25998) --- CMakeLists.txt | 76 +++++++++++------ bin/makefile-cygwin.x86_64-sdl | 8 +- bin/makefile-darwin.aarch64-sdl | 9 +- bin/makefile-darwin.x86_64-sdl | 8 +- bin/makefile-emscripten.wasm-wasm | 8 +- bin/makefile-emscripten.wasm_nl-wasm_nl | 8 +- bin/makefile-freebsd.386-sdl | 8 +- bin/makefile-freebsd.aarch64-sdl | 8 +- bin/makefile-freebsd.x86_64-sdl | 8 +- bin/makefile-haiku.x86_64-sdl | 8 +- bin/makefile-linux.386-sdl | 8 +- bin/makefile-linux.aarch64-sdl | 8 +- bin/makefile-linux.armv7l-sdl | 8 +- bin/makefile-linux.x86_64-sdl | 8 +- bin/makeright | 2 +- src/sdl.c | 104 +++++++++++++++++++++++- 16 files changed, 246 insertions(+), 41 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9735c46..c40df4c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -46,7 +46,8 @@ SET(MAIKO_INIT_DEFINITIONS ) OPTION(MAIKO_DISPLAY_X11 "Use X11 for display." ON) -OPTION(MAIKO_DISPLAY_SDL "Use SDL for display." OFF) +SET(MAIKO_DISPLAY_SDL OFF CACHE STRING "Use SDL for display. Version: OFF, 2, 3") +SET_PROPERTY(CACHE MAIKO_DISPLAY_SDL PROPERTY STRINGS OFF 2 3) IF(MAIKO_DISPLAY_X11) FIND_PACKAGE(X11 REQUIRED) @@ -81,19 +82,34 @@ IF(MAIKO_DISPLAY_X11) MESSAGE("-- Configured for X11 display") ENDIF() -IF(MAIKO_DISPLAY_SDL) +IF(MAIKO_DISPLAY_SDL STREQUAL "2") FIND_PACKAGE(SDL2 REQUIRED) SET(MAIKO_DISPLAY_SDL_DEFINITIONS - "-DSDL" + "-DSDL=2" ) - SET(MAIKO_DISPLAY_SDL_LIBRARIES ${SDL2_LIBRARIES}) + SET(MAIKO_DISPLAY_SDL_INCLUDE_DIRS "${SDL2_INCLUDE_DIRS}") + SET(MAIKO_DISPLAY_SDL_LIBRARIES SDL2::SDL2) SET(MAIKO_DISPLAY_SDL_SRCS src/sdl.c ) SET(MAIKO_DISPLAY_SDL_HDRS inc/sdldefs.h ) - MESSAGE("-- Configured for SDL display") + MESSAGE("-- Configured for SDL2 display") +ELSEIF(MAIKO_DISPLAY_SDL STREQUAL "3") + FIND_PACKAGE(SDL3 REQUIRED) + SET(MAIKO_DISPLAY_SDL_DEFINITIONS + "-DSDL=3" + ) + SET(MAIKO_DISPLAY_SDL_INCLUDE_DIRS "${SDL3_INCLUDE_DIRS}") + SET(MAIKO_DISPLAY_SDL_LIBRARIES SDL3::SDL3) + SET(MAIKO_DISPLAY_SDL_SRCS + src/sdl.c + ) + SET(MAIKO_DISPLAY_SDL_HDRS + inc/sdldefs.h + ) + MESSAGE("-- Configured for SDL3 display") ENDIF() # according to: https://cmake.org/pipermail/cmake/2016-October/064342.html @@ -428,23 +444,23 @@ ADD_CUSTOM_TARGET(gen-vdate ) ADD_EXECUTABLE(lde src/ldeboot.c src/unixfork.c) -TARGET_COMPILE_DEFINITIONS(lde PUBLIC ${MAIKO_DEFINITIONS}) -TARGET_INCLUDE_DIRECTORIES(lde PUBLIC inc) +TARGET_COMPILE_DEFINITIONS(lde PRIVATE ${MAIKO_DEFINITIONS}) +TARGET_INCLUDE_DIRECTORIES(lde PRIVATE inc) IF(MAIKO_DISPLAY_X11) # Tell it that the X11 launcher is available. - TARGET_COMPILE_DEFINITIONS(lde PUBLIC ${MAIKO_DISPLAY_X11_DEFINITIONS}) + TARGET_COMPILE_DEFINITIONS(lde PRIVATE ${MAIKO_DISPLAY_X11_DEFINITIONS}) # This is needed so that it can call XOpenDisplay. TARGET_LINK_LIBRARIES(lde X11::X11) ENDIF() IF(MAIKO_DISPLAY_SDL) # Tell it that the SDL launcher is available. - TARGET_COMPILE_DEFINITIONS(lde PUBLIC ${MAIKO_DISPLAY_SDL_DEFINITIONS}) + TARGET_COMPILE_DEFINITIONS(lde PRIVATE ${MAIKO_DISPLAY_SDL_DEFINITIONS}) ENDIF() ADD_EXECUTABLE(ldeether src/ldeether.c src/dlpi.c) -TARGET_COMPILE_DEFINITIONS(ldeether PUBLIC ${MAIKO_DEFINITIONS}) -TARGET_INCLUDE_DIRECTORIES(ldeether PUBLIC inc) +TARGET_COMPILE_DEFINITIONS(ldeether PRIVATE ${MAIKO_DEFINITIONS}) +TARGET_INCLUDE_DIRECTORIES(ldeether PRIVATE inc) IF(MAIKO_DISPLAY_X11) ADD_EXECUTABLE(ldex @@ -455,8 +471,8 @@ IF(MAIKO_DISPLAY_X11) ${MAIKO_DISPLAY_X11_SRCS} ${MAIKO_DISPLAY_X11_HDRS} ) - TARGET_COMPILE_DEFINITIONS(ldex PUBLIC ${MAIKO_DEFINITIONS} ${MAIKO_DISPLAY_X11_DEFINITIONS}) - TARGET_INCLUDE_DIRECTORIES(ldex PUBLIC inc) + TARGET_COMPILE_DEFINITIONS(ldex PRIVATE ${MAIKO_DEFINITIONS} ${MAIKO_DISPLAY_X11_DEFINITIONS}) + TARGET_INCLUDE_DIRECTORIES(ldex PRIVATE inc) TARGET_LINK_LIBRARIES(ldex ${MAIKO_LIBRARIES} ${MAIKO_DISPLAY_X11_LIBRARIES}) ADD_EXECUTABLE(ldeinit @@ -467,8 +483,8 @@ IF(MAIKO_DISPLAY_X11) ${MAIKO_DISPLAY_X11_SRCS} ${MAIKO_DISPLAY_X11_HDRS} ) - TARGET_COMPILE_DEFINITIONS(ldeinit PUBLIC ${MAIKO_INIT_DEFINITIONS} ${MAIKO_DISPLAY_X11_DEFINITIONS}) - TARGET_INCLUDE_DIRECTORIES(ldeinit PUBLIC inc) + TARGET_COMPILE_DEFINITIONS(ldeinit PRIVATE ${MAIKO_INIT_DEFINITIONS} ${MAIKO_DISPLAY_X11_DEFINITIONS}) + TARGET_INCLUDE_DIRECTORIES(ldeinit PRIVATE inc) TARGET_LINK_LIBRARIES(ldeinit ${MAIKO_LIBRARIES} ${MAIKO_DISPLAY_X11_LIBRARIES}) ENDIF() @@ -481,20 +497,32 @@ IF(MAIKO_DISPLAY_SDL) ${MAIKO_DISPLAY_SDL_SRCS} ${MAIKO_DISPLAY_SDL_HDRS} ) - TARGET_COMPILE_DEFINITIONS(ldesdl PUBLIC ${MAIKO_DEFINITIONS} ${MAIKO_DISPLAY_SDL_DEFINITIONS}) - TARGET_INCLUDE_DIRECTORIES(ldesdl PUBLIC inc) - TARGET_INCLUDE_DIRECTORIES(ldesdl PRIVATE ${SDL2_INCLUDE_DIRS}) + TARGET_COMPILE_DEFINITIONS(ldesdl PRIVATE ${MAIKO_DEFINITIONS} ${MAIKO_DISPLAY_SDL_DEFINITIONS}) + TARGET_INCLUDE_DIRECTORIES(ldesdl PRIVATE inc) + TARGET_INCLUDE_DIRECTORIES(ldesdl PRIVATE ${MAIKO_DISPLAY_SDL_INCLUDE_DIRS}) + +IF(APPLE) + IF(MAIKO_DISPLAY_SDL STREQUAL "3") +# +# Until CMake properly supports .xcframeworks, https://gitlab.kitware.com/cmake/cmake/-/issues/25998 +# we need to manually set the RPATH to produce a working executable +# + MESSAGE("-- Applying fixup for macOS RPATH for SDL3.xcframework") + SET_PROPERTY(TARGET ldesdl APPEND PROPERTY BUILD_RPATH "/Library/Frameworks/SDL3.xcframework/macos-arm64_x86_64") +# + ENDIF() +ENDIF() TARGET_LINK_LIBRARIES(ldesdl ${MAIKO_LIBRARIES} ${MAIKO_DISPLAY_SDL_LIBRARIES}) ENDIF() ADD_EXECUTABLE(mkvdate src/mkvdate.c) -TARGET_COMPILE_DEFINITIONS(mkvdate PUBLIC ${MAIKO_DEFINITIONS}) -TARGET_INCLUDE_DIRECTORIES(mkvdate PUBLIC inc) +TARGET_COMPILE_DEFINITIONS(mkvdate PRIVATE ${MAIKO_DEFINITIONS}) +TARGET_INCLUDE_DIRECTORIES(mkvdate PRIVATE inc) ADD_EXECUTABLE(setsout src/setsout.c src/byteswap.c) -TARGET_COMPILE_DEFINITIONS(setsout PUBLIC ${MAIKO_DEFINITIONS}) -TARGET_INCLUDE_DIRECTORIES(setsout PUBLIC inc) +TARGET_COMPILE_DEFINITIONS(setsout PRIVATE ${MAIKO_DEFINITIONS}) +TARGET_INCLUDE_DIRECTORIES(setsout PRIVATE inc) ADD_EXECUTABLE(tstsout src/tstsout.c src/byteswap.c) -TARGET_COMPILE_DEFINITIONS(tstsout PUBLIC ${MAIKO_DEFINITIONS}) -TARGET_INCLUDE_DIRECTORIES(tstsout PUBLIC inc) +TARGET_COMPILE_DEFINITIONS(tstsout PRIVATE ${MAIKO_DEFINITIONS}) +TARGET_INCLUDE_DIRECTORIES(tstsout PRIVATE inc) diff --git a/bin/makefile-cygwin.x86_64-sdl b/bin/makefile-cygwin.x86_64-sdl index 62c5906..17a893e 100644 --- a/bin/makefile-cygwin.x86_64-sdl +++ b/bin/makefile-cygwin.x86_64-sdl @@ -5,7 +5,13 @@ CC = gcc -m64 $(GCC_CFLAGS) -I/usr/local/include XFILES = $(OBJECTDIR)sdl.o -XFLAGS = -DSDL +# +# For SDL version 2 +# -DSDL=2 in XFLAGS and -lSDL2 in LDFLAGS +# For SDL version 3 +# -DSDL=3 in XFLAGS and -lSDL3 in LDFLAGS +# +XFLAGS = -DSDL=2 # OPTFLAGS is normally -O2. OPTFLAGS = -O2 -g3 diff --git a/bin/makefile-darwin.aarch64-sdl b/bin/makefile-darwin.aarch64-sdl index d5ae47e..d55bf66 100644 --- a/bin/makefile-darwin.aarch64-sdl +++ b/bin/makefile-darwin.aarch64-sdl @@ -4,7 +4,14 @@ CC = clang -target aarch64-apple-darwin $(CLANG_CFLAGS) XFILES = $(OBJECTDIR)sdl.o -SDLFLAGS = -DSDL -F /Library/Frameworks +# +# For SDL version 2 +# -DSDL=2 in SDLFLAGS and -framework SDL2 in LDFLAGS +# For SDL version 3 +# -DSDL=3 in SDLFLAGS and -framework SDL3 in LDFLAGS +# + +SDLFLAGS = -DSDL=2 -F /Library/Frameworks # OPTFLAGS is normally -O2. OPTFLAGS = -O2 -g diff --git a/bin/makefile-darwin.x86_64-sdl b/bin/makefile-darwin.x86_64-sdl index 2d7f79b..86d7a9c 100644 --- a/bin/makefile-darwin.x86_64-sdl +++ b/bin/makefile-darwin.x86_64-sdl @@ -2,9 +2,15 @@ CC = clang -m64 -target x86_64-apple-darwin $(CLANG_CFLAGS) +# +# For SDL version 2 +# -DSDL=2 in SDLFLAGS and -framework SDL2 in LDFLAGS +# For SDL version 3 +# -DSDL=3 in SDLFLAGS and -framework SDL3 in LDFLAGS +# XFILES = $(OBJECTDIR)sdl.o -SDLFLAGS = -DSDL -F /Library/Frameworks +SDLFLAGS = -DSDL=2 -F /Library/Frameworks # OPTFLAGS is normally -O2. OPTFLAGS = -O2 -g diff --git a/bin/makefile-emscripten.wasm-wasm b/bin/makefile-emscripten.wasm-wasm index 8d88423..48c91b4 100644 --- a/bin/makefile-emscripten.wasm-wasm +++ b/bin/makefile-emscripten.wasm-wasm @@ -4,7 +4,13 @@ CC = emcc $(CLANG_CFLAGS) XFILES = $(OBJECTDIR)sdl.o -XFLAGS = -DSDL -sUSE_SDL=2 +# +# For SDL version 2 +# -DSDL=2 and -sUSE_SDL=2 in XFLAGS and -sUSE_SDL=2 in LDFLAGS +# For SDL version 3 +# -DSDL=3 and -sUSE_SDL=3 in XFLAGS and -sUSE_SDL=3 in LDFLAGS +# +XFLAGS = -DSDL=2 -sUSE_SDL=2 # OPTFLAGS is normally -O2. OPTFLAGS = -O2 diff --git a/bin/makefile-emscripten.wasm_nl-wasm_nl b/bin/makefile-emscripten.wasm_nl-wasm_nl index b9f5736..cf5a712 100644 --- a/bin/makefile-emscripten.wasm_nl-wasm_nl +++ b/bin/makefile-emscripten.wasm_nl-wasm_nl @@ -4,7 +4,13 @@ CC = emcc $(CLANG_CFLAGS) XFILES = $(OBJECTDIR)sdl.o -XFLAGS = -DSDL -sUSE_SDL=2 +# +# For SDL version 2 +# -DSDL=2 and -sUSE_SDL=2 in XFLAGS and -sUSE_SDL=2 in LDFLAGS +# For SDL version 3 +# -DSDL=3 and -sUSE_SDL=3 in XFLAGS and -sUSE_SDL=3 in LDFLAGS +# +XFLAGS = -DSDL=2 -sUSE_SDL=2 # OPTFLAGS is normally -O2. OPTFLAGS = -O2 diff --git a/bin/makefile-freebsd.386-sdl b/bin/makefile-freebsd.386-sdl index 8a843a6..774acff 100644 --- a/bin/makefile-freebsd.386-sdl +++ b/bin/makefile-freebsd.386-sdl @@ -4,7 +4,13 @@ CC = clang -m32 $(CLANG_CFLAGS) XFILES = $(OBJECTDIR)sdl.o -SDLFLAGS = -DSDL -I/usr/local/include +# +# For SDL version 2 +# -DSDL=2 in SDLFLAGS and -lSDL2 in LDFLAGS +# For SDL version 3 +# -DSDL=3 in SDLFLAGS and -lSDL3 in LDFLAGS +# +SDLFLAGS = -DSDL=2 -I/usr/local/include # OPTFLAGS is normally -O2. OPTFLAGS = -O2 -g diff --git a/bin/makefile-freebsd.aarch64-sdl b/bin/makefile-freebsd.aarch64-sdl index 01f967b..51b3b69 100644 --- a/bin/makefile-freebsd.aarch64-sdl +++ b/bin/makefile-freebsd.aarch64-sdl @@ -4,7 +4,13 @@ CC = clang -m64 $(CLANG_CFLAGS) XFILES = $(OBJECTDIR)sdl.o -SDLFLAGS = -DSDL -I/usr/local/include +# +# For SDL version 2 +# -DSDL=2 in SDLFLAGS and -lSDL2 in LDFLAGS +# For SDL version 3 +# -DSDL=3 in SDLFLAGS and -lSDL3 in LDFLAGS +# +SDLFLAGS = -DSDL=2 -I/usr/local/include # OPTFLAGS is normally -O2. OPTFLAGS = -O2 -g diff --git a/bin/makefile-freebsd.x86_64-sdl b/bin/makefile-freebsd.x86_64-sdl index 8087150..4a5ba02 100644 --- a/bin/makefile-freebsd.x86_64-sdl +++ b/bin/makefile-freebsd.x86_64-sdl @@ -4,7 +4,13 @@ CC = clang -m64 $(CLANG_CFLAGS) XFILES = $(OBJECTDIR)sdl.o -SDLFLAGS = -DSDL -I/usr/local/include +# +# For SDL version 2 +# -DSDL=2 in SDLFLAGS and -lSDL2 in LDFLAGS +# For SDL version 3 +# -DSDL=3 in SDLFLAGS and -lSDL3 in LDFLAGS +# +SDLFLAGS = -DSDL=2 -I/usr/local/include # OPTFLAGS is normally -O2. OPTFLAGS = -O2 -g diff --git a/bin/makefile-haiku.x86_64-sdl b/bin/makefile-haiku.x86_64-sdl index 1e68a87..57ddedd 100644 --- a/bin/makefile-haiku.x86_64-sdl +++ b/bin/makefile-haiku.x86_64-sdl @@ -5,7 +5,13 @@ CC = gcc -m64 $(GCC_CFLAGS) XFILES = $(OBJECTDIR)sdl.o -XFLAGS = -DSDL +# +# For SDL version 2 +# -DSDL=2 in XFLAGS and -lSDL2 in LDFLAGS +# For SDL version 3 +# -DSDL=3 in XFLAGS and -lSDL3 in LDFLAGS +# +XFLAGS = -DSDL=2 # OPTFLAGS is normally -O2. OPTFLAGS = -O2 -g3 diff --git a/bin/makefile-linux.386-sdl b/bin/makefile-linux.386-sdl index da04d80..39bea78 100644 --- a/bin/makefile-linux.386-sdl +++ b/bin/makefile-linux.386-sdl @@ -5,7 +5,13 @@ CC = gcc -m32 $(GCC_CFLAGS) XFILES = $(OBJECTDIR)sdl.o -XFLAGS = -DSDL +# +# For SDL version 2 +# -DSDL=2 in XFLAGS and -lSDL2 in LDFLAGS +# For SDL version 3 +# -DSDL=3 in XFLAGS and -lSDL3 in LDFLAGS +# +XFLAGS = -DSDL=2 # OPTFLAGS is normally -O2. OPTFLAGS = -O2 -g3 diff --git a/bin/makefile-linux.aarch64-sdl b/bin/makefile-linux.aarch64-sdl index 337b14d..b87f0c1 100644 --- a/bin/makefile-linux.aarch64-sdl +++ b/bin/makefile-linux.aarch64-sdl @@ -5,7 +5,13 @@ CC = gcc $(GCC_CFLAGS) XFILES = $(OBJECTDIR)sdl.o -SDLFLAGS = -DSDL +# +# For SDL version 2 +# -DSDL=2 in SDLFLAGS and -lSDL2 in LDFLAGS +# For SDL version 3 +# -DSDL=3 in SDLFLAGS and -lSDL3 in LDFLAGS +# +SDLFLAGS = -DSDL=2 # OPTFLAGS is normally -O2. OPTFLAGS = -O2 -g3 diff --git a/bin/makefile-linux.armv7l-sdl b/bin/makefile-linux.armv7l-sdl index f2b844c..a1adbe3 100644 --- a/bin/makefile-linux.armv7l-sdl +++ b/bin/makefile-linux.armv7l-sdl @@ -5,7 +5,13 @@ CC = gcc $(GCC_CFLAGS) XFILES = $(OBJECTDIR)sdl.o -XFLAGS = -DSDL +# +# For SDL version 2 +# -DSDL=2 in XFLAGS and -lSDL2 in LDFLAGS +# For SDL version 3 +# -DSDL=3 in XFLAGS and -lSDL3 in LDFLAGS +# +XFLAGS = -DSDL=2 # OPTFLAGS is normally -O2. OPTFLAGS = -O2 -g3 diff --git a/bin/makefile-linux.x86_64-sdl b/bin/makefile-linux.x86_64-sdl index 64819dc..0595b63 100644 --- a/bin/makefile-linux.x86_64-sdl +++ b/bin/makefile-linux.x86_64-sdl @@ -5,7 +5,13 @@ CC = gcc -m64 $(GCC_CFLAGS) XFILES = $(OBJECTDIR)sdl.o -XFLAGS = -DSDL +# +# For SDL version 2 +# -DSDL=2 in XFLAGS and -lSDL2 in LDFLAGS +# For SDL version 3 +# -DSDL=3 in XFLAGS and -lSDL3 in LDFLAGS +# +XFLAGS = -DSDL=2 # OPTFLAGS is normally -O2. OPTFLAGS = -O2 -g3 diff --git a/bin/makeright b/bin/makeright index 25f21f1..08a68ea 100755 --- a/bin/makeright +++ b/bin/makeright @@ -71,7 +71,7 @@ case "$display" in x) releasename=${osversion}.${architecture}-${display} ldename=ldex ;; - sdl) releasename=${osversion}.${architecture}-${display} + sdl*) releasename=${osversion}.${architecture}-${display} ldename=ldesdl ;; wasm) osversion=emscripten diff --git a/src/sdl.c b/src/sdl.c index 13bb53b..132dd6f 100644 --- a/src/sdl.c +++ b/src/sdl.c @@ -1,7 +1,8 @@ -#include -#include +#include "version.h" #include #include +#include +#include #include "sdldefs.h" #include "byteswapdefs.h" #include "lispemul.h" @@ -10,8 +11,20 @@ #include "lspglob.h" // for IOPage #include "display.h" // for CURSORHEIGHT, DisplayRegion68k +#if SDL == 2 +#include +#include +#elif SDL == 3 +#include +#include +#else +#error Unrecognized SDL version number, neither 2 nor 3 +#endif + /* if SDLRENDERING is defined, render to a texture rather than * using the window surface + * + * XXX: With SDL3, using the window surface results in a black screen */ #define SDLRENDERING 1 @@ -532,7 +545,11 @@ static void sdl_update_viewport(int width, int height) { r.w = w; r.h = h; #if defined(SDLRENDERING) +#if SDL_MAJOR_VERSION == 2 SDL_RenderSetViewport(sdl_renderer, &r); +#else + SDL_SetRenderViewport(sdl_renderer, &r); +#endif #endif printf("new viewport: %d / %d\n", w, h); } @@ -553,7 +570,11 @@ void sdl_setMousePosition(int x, int y) { #if defined(SDLRENDERING) void sdl_update_display() { sdl_bitblt_to_texture(min_x, min_y, max_x - min_x, max_y - min_y); +#if SDL_MAJOR_VERSION == 2 SDL_RenderCopy(sdl_renderer, sdl_texture, NULL, NULL); +#else + SDL_RenderTexture(sdl_renderer, sdl_texture, NULL, NULL); +#endif SDL_RenderPresent(sdl_renderer); } #else @@ -573,7 +594,11 @@ void sdl_update_display() { s.w = r.w * sdl_pixelscale; s.h = r.h * sdl_pixelscale; sdl_bitblt_to_buffer(r.x, r.y, r.w, r.h); +#if SDL_MAJOR_VERSION == 2 SDL_LowerBlitScaled(sdl_buffersurface, &r, sdl_windowsurface, &s); +#else + SDL_BlitSurfaceUncheckedScaled(sdl_buffersurface, &r, sdl_windowsurface, &s, SDL_SCALEMODE_NEAREST); +#endif SDL_UpdateWindowSurfaceRects(sdl_window, &s, 1); } } @@ -583,10 +608,15 @@ void process_SDLevents() { SDL_Event event; while (SDL_PollEvent(&event)) { switch (event.type) { +#if SDL_MAJOR_VERSION == 2 case SDL_QUIT: +#else + case SDL_EVENT_QUIT: +#endif printf("quitting\n"); exit(0); break; +#if SDL_MAJOR_VERSION == 2 case SDL_WINDOWEVENT: switch (event.window.event) { case SDL_WINDOWEVENT_RESIZED: @@ -597,7 +627,19 @@ void process_SDLevents() { break; } break; +#else + case SDL_EVENT_WINDOW_RESIZED: + /* XXX: what about integer multiple of 32 requirements here? */ + sdl_windowwidth = event.window.data1; + sdl_windowheight = event.window.data2; + sdl_update_viewport(sdl_windowwidth, sdl_windowheight); + break; +#endif +#if SDL_MAJOR_VERSION == 2 case SDL_KEYDOWN: +#else + case SDL_EVENT_KEY_DOWN: +#endif #if 0 printf("dn ts: %x, type: %x, state: %x, repeat: %x, scancode: %x, sym: %x <%s>, mod: %x\n", event.key.timestamp, event.key.type, event.key.state, event.key.repeat, @@ -610,7 +652,11 @@ void process_SDLevents() { } handle_keydown(event.key.keysym.sym, event.key.keysym.mod); break; +#if SDL_MAJOR_VERSION == 2 case SDL_KEYUP: +#else + case SDL_EVENT_KEY_UP: +#endif #if 0 printf("up ts: %x, type: %x, state: %x, repeat: %x, scancode: %x, sym: %x <%s>, mod: %x\n", event.key.timestamp, event.key.type, event.key.state, event.key.repeat, @@ -619,19 +665,36 @@ void process_SDLevents() { #endif handle_keyup(event.key.keysym.sym, event.key.keysym.mod); break; +#if SDL_MAJOR_VERSION == 2 case SDL_MOUSEMOTION: { int x, y; +#else + case SDL_EVENT_MOUSE_MOTION: { + int ix, iy; + float x, y; +#endif SDL_GetMouseState(&x, &y); x /= sdl_pixelscale; y /= sdl_pixelscale; *CLastUserActionCell68k = MiscStats->secondstmp; +#if SDL_MAJOR_VERSION == 2 *EmCursorX68K = (*((DLword *)EmMouseX68K)) = (short)(x & 0xFFFF); *EmCursorY68K = (*((DLword *)EmMouseY68K)) = (short)(y & 0xFFFF); +#else + ix = x; + iy = y; + *EmCursorX68K = (*((DLword *)EmMouseX68K)) = (short)(ix & 0xFFFF); + *EmCursorY68K = (*((DLword *)EmMouseY68K)) = (short)(iy & 0xFFFF); +#endif DoRing(); if ((KBDEventFlg += 1) > 0) Irq_Stk_End = Irq_Stk_Check = 0; break; } +#if SDL_MAJOR_VERSION == 2 case SDL_MOUSEBUTTONDOWN: { +#else + case SDL_EVENT_MOUSE_BUTTON_DOWN: { +#endif switch (event.button.button) { case SDL_BUTTON_LEFT: PUTBASEBIT68K(EmRealUtilin68K, MOUSE_LEFT, FALSE); break; case SDL_BUTTON_MIDDLE: PUTBASEBIT68K(EmRealUtilin68K, MOUSE_MIDDLE, FALSE); break; @@ -641,7 +704,11 @@ void process_SDLevents() { if ((KBDEventFlg += 1) > 0) Irq_Stk_End = Irq_Stk_Check = 0; break; } +#if SDL_MAJOR_VERSION == 2 case SDL_MOUSEBUTTONUP: { +#else + case SDL_EVENT_MOUSE_BUTTON_UP: { +#endif switch (event.button.button) { case SDL_BUTTON_LEFT: PUTBASEBIT68K(EmRealUtilin68K, MOUSE_LEFT, TRUE); break; case SDL_BUTTON_MIDDLE: PUTBASEBIT68K(EmRealUtilin68K, MOUSE_MIDDLE, TRUE); break; @@ -651,7 +718,11 @@ void process_SDLevents() { if ((KBDEventFlg += 1) > 0) Irq_Stk_End = Irq_Stk_Check = 0; break; } +#if SDL_MAJOR_VERSION == 2 case SDL_MOUSEWHEEL: +#else + case SDL_EVENT_MOUSE_WHEEL: +#endif /* printf("mousewheel mouse %d x %d y %d direction %s\n", event.wheel.which, event.wheel.x, event.wheel.y, @@ -698,8 +769,12 @@ int init_SDL(char *windowtitle, int w, int h, int s) { return 1; } printf("initialised\n"); +#if SDL_MAJOR_VERSION == 2 sdl_window = SDL_CreateWindow(windowtitle, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, sdl_windowwidth, sdl_windowheight, 0); +#else + sdl_window = SDL_CreateWindow(windowtitle, sdl_windowwidth, sdl_windowheight, 0); +#endif printf("Window created\n"); if (sdl_window == NULL) { printf("Window could not be created. SDL_Error: %s\n", SDL_GetError()); @@ -707,7 +782,11 @@ int init_SDL(char *windowtitle, int w, int h, int s) { } #if defined(SDLRENDERING) printf("Creating renderer...\n"); +#if SDL_MAJOR_VERSION == 2 sdl_renderer = SDL_CreateRenderer(sdl_window, -1, SDL_RENDERER_ACCELERATED); +#else + sdl_renderer = SDL_CreateRenderer(sdl_window, NULL, SDL_RENDERER_ACCELERATED); +#endif if (NULL == sdl_renderer) { printf("SDL Error: %s\n", SDL_GetError()); return 3; @@ -716,16 +795,25 @@ int init_SDL(char *windowtitle, int w, int h, int s) { SDL_SetRenderDrawColor(sdl_renderer, 127, 127, 127, 255); SDL_RenderClear(sdl_renderer); SDL_RenderPresent(sdl_renderer); +#if SDL_MAJOR_VERSION == 2 SDL_RenderSetScale(sdl_renderer, 1.0, 1.0); - printf("Creating texture...\n"); sdl_pixelformat = SDL_AllocFormat(sdl_rendererinfo.texture_formats[0]); +#else + SDL_SetRenderScale(sdl_renderer, 1.0, 1.0); + sdl_pixelformat = SDL_CreatePixelFormat(sdl_rendererinfo.texture_formats[0]); +#endif + printf("Creating texture...\n"); sdl_texture = SDL_CreateTexture(sdl_renderer, sdl_pixelformat->format, SDL_TEXTUREACCESS_STREAMING, width, height); sdl_black = SDL_MapRGB(sdl_pixelformat, 0, 0, 0); sdl_white = SDL_MapRGB(sdl_pixelformat, 255, 255, 255); sdl_foreground = sdl_black; sdl_background = sdl_white; +#if SDL_MAJOR_VERSION == 2 sdl_bytesperpixel = sdl_pixelformat->BytesPerPixel; +#else + sdl_bytesperpixel = sdl_pixelformat->bytes_per_pixel; +#endif #else printf("Creating window surface and buffer surface\n"); sdl_windowsurface = SDL_GetWindowSurface(sdl_window); @@ -734,12 +822,22 @@ int init_SDL(char *windowtitle, int w, int h, int s) { sdl_white = SDL_MapRGB(sdl_pixelformat, 255, 255, 255); sdl_foreground = sdl_black; sdl_background = sdl_white; +#if SDL_MAJOR_VERSION == 2 sdl_bytesperpixel = sdl_pixelformat->BytesPerPixel; +#else + sdl_bytesperpixel = sdl_pixelformat->bytes_per_pixel; +#endif buffer_size = width * height * sdl_bytesperpixel; buffer = malloc(buffer_size); +#if SDL_MAJOR_VERSION == 2 sdl_buffersurface = SDL_CreateRGBSurfaceWithFormatFrom( buffer, sdl_displaywidth, sdl_displayheight, sdl_bytesperpixel * 8, sdl_displaywidth * sdl_bytesperpixel, sdl_pixelformat->format); +#else + sdl_buffersurface = SDL_CreateSurfaceFrom( + buffer, sdl_displaywidth, sdl_displayheight, + sdl_displaywidth * sdl_bytesperpixel, sdl_pixelformat->format); +#endif #endif printf("SDL initialised\n"); return 0;