Skip to content

Commit

Permalink
Miscellaneous compatibility tweaks
Browse files Browse the repository at this point in the history
* CMakeLists.txt: Retrieve SDL2 location using the sdl2-config utility
* CMakeLists.txt: Build for Mac OS 10.4 minimum
* .gitignore: ignore .DS_Store (macOS folder metadata)
* Supply strnlen() if necessary (missing on older macOS versions)
* Allow running without joystick support if SDL was built without it
  • Loading branch information
Falcury committed Aug 17, 2019
1 parent f1f6496 commit 368ba2a
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 24 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ build/
# Windows thumbnail cache
Thumbs.db

# macOS folder metadata
.DS_Store

# The desktop file has to be recreated from the template.
src/SDLPoP.desktop

Expand Down
18 changes: 13 additions & 5 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${SDLPoP_SOURCE_DIR}/..")

#set(SDL2 "/usr/local/Cellar/sdl2/2.0.5")

if (NOT(WIN32) AND (DEFINED SDL2))
include_directories(${SDL2}/include)
link_directories(${SDL2}/lib)
endif()
# If you don't specify the location of SDL2, this script will try to guess the location,
# or retrieve it using the sdl2-config utility.

if (WIN32)
if (MSVC)
Expand Down Expand Up @@ -49,6 +47,16 @@ if (WIN32)

include_directories(${SDL2}/${SDL2_ARCH}/include)
link_directories(${SDL2}/${SDL2_ARCH}/lib)
else()
if (DEFINED SDL2)
include_directories(${SDL2}/include)
link_directories(${SDL2}/lib)
else()
execute_process(COMMAND sdl2-config --prefix OUTPUT_VARIABLE SDL2_PREFIX)
string(STRIP ${SDL2_PREFIX} SDL2_PREFIX)
include_directories(${SDL2_PREFIX}/include)
link_directories(${SDL2_PREFIX}/lib)
endif()
endif()

set(SOURCE_FILES
Expand Down Expand Up @@ -89,7 +97,7 @@ else()

set(MACOSX_BUNDLE_ICON_FILE "icon.icns")
set_source_files_properties(${MACOSX_BUNDLE_ICON_FILE} PROPERTIES MACOSX_PACKAGE_LOCATION Resources)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mmacosx-version-min=10.6")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mmacosx-version-min=10.4")
set(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} -headerpad_max_install_names")
add_executable(prince MACOSX_BUNDLE ${SOURCE_FILES} ${MACOSX_BUNDLE_ICON_FILE})
set_target_properties(prince PROPERTIES MACOSX_BUNDLE_INFO_PLIST ${CMAKE_SOURCE_DIR}/Info.plist)
Expand Down
9 changes: 9 additions & 0 deletions src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,15 @@ extern "C" {
#define ABS(x) ((x)<0?-(x):(x))
#endif

#if defined(__APPLE__) && !defined(strnlen)
// Use this if strnlen is missing.
static inline size_t strnlen(const char *str, size_t max)
{
const char *end = memchr (str, 0, max);
return end ? (size_t)(end - str) : max;
}
#endif

#ifdef __cplusplus
}
#endif
Expand Down
1 change: 1 addition & 0 deletions src/data.h
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,7 @@ extern SDL_Texture* texture_fuzzy;
extern SDL_Texture* texture_blurry;
extern SDL_Texture* target_texture;

extern bool is_joyst_supported;
extern SDL_GameController* sdl_controller_ INIT( = 0 );
extern SDL_Joystick* sdl_joystick_; // in case our joystick is not compatible with SDL_GameController
extern byte using_sdl_joystick_interface;
Expand Down
32 changes: 13 additions & 19 deletions src/seg009.c
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,7 @@ void __pascal far draw_image_transp(image_type far *image,image_type far *mask,i
// seg009:157E
int __pascal far set_joy_mode() {
// stub
if (!is_joyst_supported) return;
if (SDL_NumJoysticks() < 1) {
is_joyst_mode = 0;
} else {
Expand All @@ -696,7 +697,6 @@ int __pascal far set_joy_mode() {
} else {
sdl_haptic = NULL;
}

is_keyboard_mode = !is_joyst_mode;
return is_joyst_mode;
}
Expand Down Expand Up @@ -1738,25 +1738,11 @@ void init_digi() {
// Open the audio device. Called once.
//printf("init_digi(): called\n");

SDL_AudioFormat desired_audioformat;
SDL_version version;
SDL_GetVersion(&version);
//printf("SDL Version = %d.%d.%d\n", version.major, version.minor, version.patch);
if (version.major <= 2 && version.minor <= 0 && version.patch <= 3) {
// In versions before 2.0.4, 16-bit audio samples don't work properly (the sound becomes garbled).
// See: https://bugzilla.libsdl.org/show_bug.cgi?id=2389
// Workaround: set the audio format to 8-bit, if we are linking against an older SDL2 version.
desired_audioformat = AUDIO_U8;
printf("Your SDL.dll is older than 2.0.4. Using 8-bit audio format to work around resampling bug.");
} else {
desired_audioformat = AUDIO_S16SYS;
}

SDL_AudioSpec *desired;
desired = (SDL_AudioSpec *)malloc(sizeof(SDL_AudioSpec));
memset(desired, 0, sizeof(SDL_AudioSpec));
desired->freq = digi_samplerate; //buffer->digi.sample_rate;
desired->format = desired_audioformat;
desired->format = AUDIO_S16SYS;
desired->channels = 2;
desired->samples = 1024;
desired->callback = audio_callback;
Expand Down Expand Up @@ -2128,11 +2114,16 @@ void __pascal far set_gr_mode(byte grmode) {
#ifdef SDL_HINT_WINDOWS_DISABLE_THREAD_NAMING
SDL_SetHint(SDL_HINT_WINDOWS_DISABLE_THREAD_NAMING, "1");
#endif
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_NOPARACHUTE |
SDL_INIT_GAMECONTROLLER | SDL_INIT_HAPTIC ) != 0) {
Uint32 init_flags = SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_NOPARACHUTE;
if (SDL_Init(init_flags) != 0) {
sdlperror("SDL_Init");
quit(1);
}

is_joyst_supported = (SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER | SDL_INIT_HAPTIC) == 0);
if (!is_joyst_supported) {
sdlperror("SDL_InitSubSystem");
}

//SDL_EnableUNICODE(1); //deprecated
Uint32 flags = 0;
Expand Down Expand Up @@ -2940,6 +2931,7 @@ void process_events() {
#endif
break;
case SDL_CONTROLLERAXISMOTION:
if (!is_joyst_supported) break;
if (event.caxis.axis < 6) {
joy_axis[event.caxis.axis] = event.caxis.value;

Expand All @@ -2952,6 +2944,7 @@ void process_events() {
}
break;
case SDL_CONTROLLERBUTTONDOWN:
if (!is_joyst_supported) break;
#ifdef USE_AUTO_INPUT_MODE
if (!is_joyst_mode) {
is_joyst_mode = 1;
Expand Down Expand Up @@ -2983,6 +2976,7 @@ void process_events() {
}
break;
case SDL_CONTROLLERBUTTONUP:
if (!is_joyst_supported) break;
switch (event.cbutton.button)
{
case SDL_CONTROLLER_BUTTON_DPAD_LEFT: joy_hat_states[0] = 0; break; // left
Expand All @@ -3001,6 +2995,7 @@ void process_events() {
case SDL_JOYBUTTONDOWN:
case SDL_JOYBUTTONUP:
case SDL_JOYAXISMOTION:
if (!is_joyst_supported) break;
// Only handle the event if the joystick is incompatible with the SDL_GameController interface.
// (Otherwise it will interfere with the normal action of the SDL_GameController API.)
if (!using_sdl_joystick_interface) {
Expand Down Expand Up @@ -3035,7 +3030,6 @@ void process_events() {
else if (event.jbutton.button == SDL_JOYSTICK_BUTTON_X) joy_X_button_state = 0; // X (shift)
}
break;

case SDL_TEXTINPUT:
last_text_input = event.text.text[0]; // UTF-8 formatted char text input
break;
Expand Down

0 comments on commit 368ba2a

Please sign in to comment.