diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index db34bbdd..80619803 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -2,6 +2,7 @@ include(FindPkgConfig) pkg_check_modules(YAML REQUIRED yaml-0.1) pkg_check_modules(MINIZIP REQUIRED minizip) +pkg_check_modules(ZLIB REQUIRED zlib) pkg_check_modules(SLIRP slirp) if ("${SLIRP_FOUND}" STREQUAL "") @@ -228,7 +229,16 @@ set(HEADER_FILES Z80VICE/daa.h ) -add_library(appleii SHARED +if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") +# Applle's linker does not like the link-time interface of libappleii +# we need link everything at once + message("Mac OS X detected, libappleii as static library") + set(LIBRARY_TYPE "STATIC") +else() + set(LIBRARY_TYPE "SHARED") +endif() + +add_library(appleii "${LIBRARY_TYPE}" ${SOURCE_FILES} ${HEADER_FILES} ) @@ -239,6 +249,7 @@ target_include_directories(appleii PRIVATE ${PCAP_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS} ${SLIRP_INCLUDE_DIRS} + ${ZLIB_INCLUDE_DIRS} Debugger ) @@ -252,13 +263,15 @@ target_link_libraries(appleii PRIVATE ${MINIZIP_LIBRARIES} ${PCAP_LIBRARIES} ${SLIRP_LIBRARIES} + ${ZLIB_LIBRARIES} ) target_link_directories(appleii PRIVATE - ${YAML_LIBRARY_DIR} - ${MINIZIP_LIBRARY_DIR} - ${PCAP_LIBRARY_DIR} - ${SLIRP_LIBRARY_DIR} + ${YAML_LIBRARY_DIRS} + ${MINIZIP_LIBRARY_DIRS} + ${PCAP_LIBRARY_DIRS} + ${SLIRP_LIBRARY_DIRS} + ${ZLIB_LIBRARY_DIRS} ) target_compile_options(appleii PUBLIC diff --git a/source/frontends/common2/CMakeLists.txt b/source/frontends/common2/CMakeLists.txt index ac55599d..f55bd165 100644 --- a/source/frontends/common2/CMakeLists.txt +++ b/source/frontends/common2/CMakeLists.txt @@ -34,8 +34,9 @@ target_include_directories(common2 PRIVATE ${Boost_INCLUDE_DIRS} ) -target_link_libraries(common2 PUBLIC +target_link_libraries(common2 PRIVATE Boost::program_options + appleii ) file(RELATIVE_PATH ROOT_PATH ${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR}) diff --git a/source/frontends/qt/memorycontainer.cpp b/source/frontends/qt/memorycontainer.cpp index 4087ab4e..ac459ae4 100644 --- a/source/frontends/qt/memorycontainer.cpp +++ b/source/frontends/qt/memorycontainer.cpp @@ -3,7 +3,7 @@ #include "StdAfx.h" #include "Memory.h" -#include "Debugger/DebugDefs.h" +#include "Debugger/Debugger_Types.h" #include "viewbuffer.h" diff --git a/source/frontends/sdl/CMakeLists.txt b/source/frontends/sdl/CMakeLists.txt index 3b0ed505..a0ffc2b2 100644 --- a/source/frontends/sdl/CMakeLists.txt +++ b/source/frontends/sdl/CMakeLists.txt @@ -1,12 +1,30 @@ include(FindPkgConfig) -find_package(SDL2 REQUIRED) -pkg_search_module(SDL2_IMAGE REQUIRED SDL2_image) -pkg_search_module(GLES2 REQUIRED glesv2) +add_executable(sa2) + set(IMGUI_PATH "imgui/imgui") set(IMGUI_CLUB_PATH "imgui/imgui_club") -add_executable(sa2) +find_package(SDL2 REQUIRED) +pkg_search_module(SDL2_IMAGE REQUIRED SDL2_image) + +# the default is to use GLES +set (SA2_USE_OPENGL 0) + +if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") + set (SA2_USE_OPENGL 1) +endif() + + +if (${SA2_USE_OPENGL}) + pkg_search_module(GLES2 REQUIRED opengl) +else() + pkg_search_module(GLES2 REQUIRED glesv2) + target_compile_definitions(sa2 PRIVATE + IMGUI_IMPL_OPENGL_ES2 + ) +endif() + set(SOURCE_FILES main.cpp @@ -65,7 +83,7 @@ target_sources(sa2 PRIVATE imgui/settingshelper.h imgui/sdlsettings.h imgui/imconfig.h - imgui/gles.h + imgui/glselector.h ${IMGUI_PATH}/imgui.h ${IMGUI_PATH}/imgui.cpp @@ -86,7 +104,6 @@ target_include_directories(sa2 PRIVATE ) target_compile_definitions(sa2 PRIVATE - IMGUI_IMPL_OPENGL_ES2 IMGUI_USER_CONFIG="frontends/sdl/imgui/imconfig.h" ) diff --git a/source/frontends/sdl/imgui/gles.h b/source/frontends/sdl/imgui/gles.h deleted file mode 100644 index 80bef59e..00000000 --- a/source/frontends/sdl/imgui/gles.h +++ /dev/null @@ -1,35 +0,0 @@ -#pragma once - -#if defined(IMGUI_IMPL_OPENGL_ES2) - -// Pi3 with Fake KMS -// "OpenGL ES 2.0 Mesa 19.3.2" -// "Supported versions are: 1.00 ES" - -#include -#define SDL_CONTEXT_MAJOR 2 - -#elif defined(IMGUI_IMPL_OPENGL_ES3) - -// Pi4 with Fake KMS -// "OpenGL ES 3.1 Mesa 19.3.2" -// "Supported versions are: 1.00 ES, 3.00 ES, and 3.10 ES" - -// On my desktop -// "OpenGL ES 3.1 Mesa 20.2.6" -// "Supported versions are: 1.00 ES, 3.00 ES, and 3.10 ES" - -#include -#define SDL_CONTEXT_MAJOR 3 -// "310 es" is accepted on a Pi4, but the imgui shaders do not compile - -#endif - -// this is used in all cases for GL_BGRA_EXT -#include - -#include "imgui.h" -#include "imgui_impl_sdl.h" -#include "imgui_impl_opengl3.h" - -#include "imgui_memory_editor.h" diff --git a/source/frontends/sdl/imgui/glselector.h b/source/frontends/sdl/imgui/glselector.h new file mode 100644 index 00000000..5cfff4e1 --- /dev/null +++ b/source/frontends/sdl/imgui/glselector.h @@ -0,0 +1,75 @@ +#pragma once + +#if defined(IMGUI_IMPL_OPENGL_ES2) + +// Pi3 with Fake KMS +// "OpenGL ES 2.0 Mesa 19.3.2" +// "Supported versions are: 1.00 ES" + +#include +#include + +#define SA2_CONTEXT_FLAGS 0 +#define SA2_CONTEXT_PROFILE_MASK SDL_GL_CONTEXT_PROFILE_ES +#define SA2_CONTEXT_MAJOR_VERSION 2 +#define SA2_CONTEXT_MINOR_VERSION 0 + +// this is defined in gl2ext.h and nowhere in gl3.h +#define SA2_IMAGE_FORMAT_INTERNAL GL_BGRA_EXT +#define SA2_IMAGE_FORMAT GL_BGRA_EXT + +#elif defined(IMGUI_IMPL_OPENGL_ES3) + +// Pi4 with Fake KMS +// "OpenGL ES 3.1 Mesa 19.3.2" +// "Supported versions are: 1.00 ES, 3.00 ES, and 3.10 ES" + +// On my desktop +// "OpenGL ES 3.1 Mesa 20.2.6" +// "Supported versions are: 1.00 ES, 3.00 ES, and 3.10 ES" + +// "310 es" is accepted on a Pi4, but the imgui shaders do not compile + +#include +#include + +#define SA2_CONTEXT_FLAGS 0 +#define SA2_CONTEXT_PROFILE_MASK SDL_GL_CONTEXT_PROFILE_ES +#define SA2_CONTEXT_MAJOR_VERSION 3 +#define SA2_CONTEXT_MINOR_VERSION 0 + +// this is defined in gl2ext.h and nowhere in gl3.h +#define SA2_IMAGE_FORMAT_INTERNAL GL_BGRA_EXT +#define SA2_IMAGE_FORMAT GL_BGRA_EXT + +#elif defined(__APPLE__) + +#include + +#define SA2_CONTEXT_FLAGS SDL_GL_CONTEXT_FORWARD_COMPATIBLE_FLAG +#define SA2_CONTEXT_PROFILE_MASK SDL_GL_CONTEXT_PROFILE_CORE +#define SA2_CONTEXT_MAJOR_VERSION 3 +#define SA2_CONTEXT_MINOR_VERSION 2 + +#define SA2_IMAGE_FORMAT_INTERNAL GL_RGBA +#define SA2_IMAGE_FORMAT GL_BGRA + +#else + +#include + +#define SA2_CONTEXT_FLAGS 0 +#define SA2_CONTEXT_PROFILE_MASK SDL_GL_CONTEXT_PROFILE_CORE +#define SA2_CONTEXT_MAJOR_VERSION 3 +#define SA2_CONTEXT_MINOR_VERSION 2 + +#define SA2_IMAGE_FORMAT_INTERNAL GL_RGBA +#define SA2_IMAGE_FORMAT GL_BGRA + +#endif + +#include "imgui.h" +#include "imgui_impl_sdl.h" +#include "imgui_impl_opengl3.h" + +#include "imgui_memory_editor.h" diff --git a/source/frontends/sdl/imgui/image.cpp b/source/frontends/sdl/imgui/image.cpp index fff0e5d2..d429076a 100644 --- a/source/frontends/sdl/imgui/image.cpp +++ b/source/frontends/sdl/imgui/image.cpp @@ -31,10 +31,8 @@ namespace sa2 { glBindTexture(GL_TEXTURE_2D, texture); - const GLenum format = GL_BGRA_EXT; // this is defined in gl2ext.h and nowhere in gl3.h const GLenum type = GL_UNSIGNED_BYTE; - glTexImage2D(GL_TEXTURE_2D, 0, format, width, height, 0, format, type, nullptr); - + glTexImage2D(GL_TEXTURE_2D, 0, SA2_IMAGE_FORMAT_INTERNAL, width, height, 0, SA2_IMAGE_FORMAT, type, nullptr); } void loadTextureFromData(GLuint texture, const uint8_t * data, size_t width, size_t height, size_t pitch) @@ -48,9 +46,8 @@ namespace sa2 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - const GLenum format = GL_BGRA_EXT; // this is defined in gl2ext.h and nowhere in gl3.h const GLenum type = GL_UNSIGNED_BYTE; - glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, format, type, data); + glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, SA2_IMAGE_FORMAT, type, data); // reset to default state glPixelStorei(UGL_UNPACK_LENGTH, 0); } diff --git a/source/frontends/sdl/imgui/image.h b/source/frontends/sdl/imgui/image.h index 19aedbd3..b0778edb 100644 --- a/source/frontends/sdl/imgui/image.h +++ b/source/frontends/sdl/imgui/image.h @@ -1,7 +1,7 @@ #pragma once #include -#include "frontends/sdl/imgui/gles.h" +#include "frontends/sdl/imgui/glselector.h" namespace sa2 { diff --git a/source/frontends/sdl/imgui/sdlimguiframe.cpp b/source/frontends/sdl/imgui/sdlimguiframe.cpp index fdb7a5bb..d0462ab2 100644 --- a/source/frontends/sdl/imgui/sdlimguiframe.cpp +++ b/source/frontends/sdl/imgui/sdlimguiframe.cpp @@ -12,16 +12,35 @@ #include +namespace +{ + + std::string safeGlGetString(GLenum name) + { + const char * str = reinterpret_cast(glGetString(name)); + if (str) + { + return str; + } + else + { + return ""; + } + } + +} + + namespace sa2 { SDLImGuiFrame::SDLImGuiFrame(const common2::EmulatorOptions & options) : SDLFrame(options) { - SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, 0); - SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES); - SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, SDL_CONTEXT_MAJOR); // from local gles.h - SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SA2_CONTEXT_FLAGS); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SA2_CONTEXT_PROFILE_MASK); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, SA2_CONTEXT_MAJOR_VERSION); // from local gles.h + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, SA2_CONTEXT_MINOR_VERSION); // Create window with graphics context SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); @@ -49,11 +68,11 @@ namespace sa2 // Setup Platform/Renderer backends std::cerr << "IMGUI_VERSION: " << IMGUI_VERSION << std::endl; - std::cerr << "GL_VENDOR: " << glGetString(GL_VENDOR) << std::endl; - std::cerr << "GL_RENDERER: " << glGetString(GL_RENDERER) << std::endl; - std::cerr << "GL_VERSION: " << glGetString(GL_VERSION) << std::endl; - std::cerr << "GL_SHADING_LANGUAGE_VERSION: " << glGetString(GL_SHADING_LANGUAGE_VERSION) << std::endl; - // const char* runtime_gl_extensions = (const char*)glGetString(GL_EXTENSIONS); + std::cerr << "GL_VENDOR: " << safeGlGetString(GL_VENDOR) << std::endl; + std::cerr << "GL_RENDERER: " << safeGlGetString(GL_RENDERER) << std::endl; + std::cerr << "GL_VERSION: " << safeGlGetString(GL_VERSION) << std::endl; + std::cerr << "GL_SHADING_LANGUAGE_VERSION: " << safeGlGetString(GL_SHADING_LANGUAGE_VERSION) << std::endl; + // const char* runtime_gl_extensions = (const char*)safeGlGetString(GL_EXTENSIONS); // std::cerr << "GL_EXTENSIONS: " << runtime_gl_extensions << std::endl; // Setup Dear ImGui context diff --git a/source/frontends/sdl/imgui/sdlimguiframe.h b/source/frontends/sdl/imgui/sdlimguiframe.h index c9df2dd2..b18472f5 100644 --- a/source/frontends/sdl/imgui/sdlimguiframe.h +++ b/source/frontends/sdl/imgui/sdlimguiframe.h @@ -2,7 +2,7 @@ #include "frontends/sdl/sdlframe.h" #include "frontends/sdl/imgui/sdlsettings.h" -#include "frontends/sdl/imgui/gles.h" +#include "frontends/sdl/imgui/glselector.h" namespace common2 { diff --git a/source/frontends/sdl/imgui/sdlsettings.cpp b/source/frontends/sdl/imgui/sdlsettings.cpp index 9d3ea78e..e683f842 100644 --- a/source/frontends/sdl/imgui/sdlsettings.cpp +++ b/source/frontends/sdl/imgui/sdlsettings.cpp @@ -19,7 +19,7 @@ #include "Utilities.h" #include "Memory.h" -#include "Debugger/DebugDefs.h" +#include "Debugger/Debugger_Types.h" #include "Tfe/tfe.h" #include "Tfe/tfesupp.h" diff --git a/source/frontends/sdl/imgui/sdlsettings.h b/source/frontends/sdl/imgui/sdlsettings.h index d3920ec7..7e2f1327 100644 --- a/source/frontends/sdl/imgui/sdlsettings.h +++ b/source/frontends/sdl/imgui/sdlsettings.h @@ -1,6 +1,6 @@ #pragma once -#include "frontends/sdl/imgui/gles.h" +#include "frontends/sdl/imgui/glselector.h" #include "frontends/sdl/sdirectsound.h" #include "Debugger/Debug.h" #include "Debugger/Debugger_Console.h" diff --git a/source/frontends/sdl/imgui/settingshelper.cpp b/source/frontends/sdl/imgui/settingshelper.cpp index 70da6d15..00025e9f 100644 --- a/source/frontends/sdl/imgui/settingshelper.cpp +++ b/source/frontends/sdl/imgui/settingshelper.cpp @@ -8,7 +8,7 @@ #include "Tfe/tfe.h" #include "frontends/sdl/imgui/settingshelper.h" -#include "frontends/sdl/imgui/gles.h" +#include "frontends/sdl/imgui/glselector.h" #include "imgui_internal.h" diff --git a/source/linux/network/uthernet2.cpp b/source/linux/network/uthernet2.cpp index f5d5af51..d768b9b6 100644 --- a/source/linux/network/uthernet2.cpp +++ b/source/linux/network/uthernet2.cpp @@ -2,10 +2,20 @@ #include "linux/network/uthernet2.h" #include +#include +#include #include #include #include +// fix SOCK_NONBLOCK for e.g. macOS +#ifndef SOCK_NONBLOCK +// DISCALIMER +// totally untested, use at your own risk +#include +#define SOCK_NONBLOCK O_NONBLOCK +#endif + #define MAX_RXLENGTH 1518 // #define U2_LOG_VERBOSE