diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index 187fbe73f..2703e9f09 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -157,6 +157,88 @@ "cStandard": "c11", "cppStandard": "c++17", "intelliSenseMode": "msvc-x64" + }, + { + "name": "SDL1 Debug MacOS", + "browse": { + "path": [ + "${workspaceFolder}" + ], + "limitSymbolsToIncludedHeaders": true + }, + "includePath": [ + "${workspaceFolder}/include", + "${workspaceFolder}/src", + "${workspaceFolder}/src/aviwriter", + "${workspaceFolder}/src/hardware/snd_pc98/cbus", + "${workspaceFolder}/src/hardware/snd_pc98/common", + "${workspaceFolder}/src/hardware/snd_pc98/generic", + "${workspaceFolder}/src/hardware/snd_pc98/sound", + "${workspaceFolder}/src/hardware/snd_pc98/sound/getsnd", + "${workspaceFolder}/src/hardware/snd_pc98/x11", + "${workspaceFolder}/src/hardware/opl3duoboard", + "${workspaceFolder}/src/mt32", + "${workspaceFolder}/vs2015", + "${workspaceFolder}/vs2015/libpdcurses", + "${workspaceFolder}/vs2015/libpng", + "${workspaceFolder}/vs2015/pcap", + "${workspaceFolder}/vs2015/sdl/include", + "${workspaceFolder}/vs2015/sdlnet", + "${workspaceFolder}/vs2015/zlib" + ], + "defines": [ + "_DEBUG", + "_MBCS", + "_CRT_SECURE_NO_WARNINGS", + "MACOSX", + "__MACOSX__", + "C_SDL1", + "_FILE_OFFSET_BITS=64" + ], + "cStandard": "c11", + "cppStandard": "c++17", + "intelliSenseMode": "macos-clang-x64" + }, + { + "name": "SDL2 Debug MacOS", + "browse": { + "path": [ + "${workspaceFolder}" + ], + "limitSymbolsToIncludedHeaders": true + }, + "includePath": [ + "${workspaceFolder}/include", + "${workspaceFolder}/src", + "${workspaceFolder}/src/aviwriter", + "${workspaceFolder}/src/hardware/snd_pc98/cbus", + "${workspaceFolder}/src/hardware/snd_pc98/common", + "${workspaceFolder}/src/hardware/snd_pc98/generic", + "${workspaceFolder}/src/hardware/snd_pc98/sound", + "${workspaceFolder}/src/hardware/snd_pc98/sound/getsnd", + "${workspaceFolder}/src/hardware/snd_pc98/x11", + "${workspaceFolder}/src/hardware/opl3duoboard", + "${workspaceFolder}/src/mt32", + "${workspaceFolder}/vs2015", + "${workspaceFolder}/vs2015/libpdcurses", + "${workspaceFolder}/vs2015/libpng", + "${workspaceFolder}/vs2015/pcap", + "${workspaceFolder}/vs2015/sdl/include", + "${workspaceFolder}/vs2015/sdlnet", + "${workspaceFolder}/vs2015/zlib" + ], + "defines": [ + "_DEBUG", + "_MBCS", + "_CRT_SECURE_NO_WARNINGS", + "MACOSX", + "__MACOSX__", + "C_SDL2", + "_FILE_OFFSET_BITS=64" + ], + "cStandard": "c11", + "cppStandard": "c++17", + "intelliSenseMode": "macos-clang-x64" } ], "version": 4 diff --git a/.vscode/launch.json b/.vscode/launch.json index 53d08899c..ec4a459ea 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -95,5 +95,16 @@ "environment": [], "externalConsole": true }, + { + "name": "(MacOS) Launch Debug", + "type": "lldb", + "request": "launch", + "program": "${workspaceFolder}/src/dosbox-x", + "args": [], + "stopAtEntry": true, + "cwd": "${workspaceFolder}/src", + "environment": [], + "externalConsole": true + } ] } \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 06e7ee5c0..09b647f97 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -141,6 +141,33 @@ "reveal": "silent" }, "problemMatcher": "$msCompile" + }, + { + "label": "build MacOS SDL1 Debug", + "type": "shell", + "command": "${workspaceFolder}/build-debug-macosx", + "group": "build", + "presentation": { + "reveal": "silent" + }, + "problemMatcher": [ + "$gcc" + ] + }, + { + "label": "build MacOS SDL2 Debug", + "type": "shell", + "command": "${workspaceFolder}/build-debug-macosx-sdl2", + "group": { + "kind": "build", + "isDefault": true + }, + "presentation": { + "reveal": "silent" + }, + "problemMatcher": [ + "$gcc" + ] } ] } \ No newline at end of file diff --git a/build-debug-macosx b/build-debug-macosx new file mode 100755 index 000000000..2c32f921f --- /dev/null +++ b/build-debug-macosx @@ -0,0 +1,62 @@ +#!/bin/bash + +# I'm sick and tired of all the churn the three versions of autoconf +# are causing in this repo. Stop committing the configure scripts +# and just autoregen. +./autogen.sh || exit 1 + +# where are we? +top=`pwd` +if test -z "$top" ; then exit 1; fi + +# fix +chmod +x vs2015/sdl/build-scripts/strip_fPIC.sh + +# prefer to compile against our own copy of SDL 1.x +echo Compiling our internal SDL 1.x +(cd vs2015/sdl && ./build-dosbox.sh) || exit 1 + +# FIXME: SDLnet will compile a static library that targets a foreign architecture, +# and then ld will complain about it???????? +# prefer to compile against our own copy of SDLnet 1.x +#echo Compiling our internal SDLnet 1.x +#(cd vs2015/sdlnet && ./build-dosbox.sh) || exit 1 + +# perfer to compile against our own zlib +echo Compiling our internal zlib +(cd vs2015/zlib && ./build-dosbox.sh) || exit 1 +new="-I$top/vs2015/zlib/linux-host/include " +nld="-L$top/vs2015/zlib/linux-host/lib " +export CFLAGS="$new$CFLAGS -g3" +export LDFLAGS="$nld$LDFLAGS -g3" +export CPPFLAGS="$new$CPPFLAGS -g3" +export CXXFLAGS="$new$CXXFLAGS -g3" + +# perfer to compile against our own libpng (comment this out to disable) +echo Compiling our internal libpng +(cd vs2015/libpng && ./build-dosbox.sh) || exit 1 +new="-I$top/vs2015/libpng/linux-host/include " +nld="-L$top/vs2015/libpng/linux-host/lib " +export CFLAGS="$new$CFLAGS -g3" +export LDFLAGS="$nld$LDFLAGS -g3" +export CPPFLAGS="$new$CPPFLAGS -g3" +export CXXFLAGS="$new$CXXFLAGS -g3" + +# perfer to compile against our own freetype +echo Compiling our internal freetype +(cd vs2015/freetype && ./build-dosbox.sh) || exit 1 +new="-I$top/vs2015/freetype/linux-host/include/freetype2 " +nld="-L$top/vs2015/freetype/linux-host/lib -lfreetype " +export CFLAGS="$new$CFLAGS -g3 " +export LDFLAGS="$nld$LDFLAGS -g3" +export CPPFLAGS="$new$CPPFLAGS -g3 " +export CXXFLAGS="$new$CXXFLAGS -g3" +export INTERNAL_FREETYPE=1 + +# now compile ourself +echo Compiling DOSBox-X + +chmod +x configure +./configure --enable-core-inline --enable-debug=heavy --prefix=/usr --disable-avcodec "$@" || exit 1 +make -j3 || exit 1 + diff --git a/build-debug-macosx-sdl2 b/build-debug-macosx-sdl2 new file mode 100755 index 000000000..e9f86dec8 --- /dev/null +++ b/build-debug-macosx-sdl2 @@ -0,0 +1,58 @@ +#!/bin/bash + +# I'm sick and tired of all the churn the three versions of autoconf +# are causing in this repo. Stop committing the configure scripts +# and just autoregen. +./autogen.sh || exit 1 + +# where are we? +top=`pwd` +if test -z "$top" ; then exit 1; fi + +# fix +chmod +x vs2015/sdl/build-scripts/strip_fPIC.sh + +# prefer to compile against our own copy of SDL 2.x IF the system does not provide one +#x=`which sdl2-config` +#if test -z "$x" ; then + echo Compiling our internal SDL 2.x + (cd vs2015/sdl2 && ./build-dosbox.sh) || exit 1 +#fi + +# perfer to compile against our own zlib +echo Compiling our internal zlib +(cd vs2015/zlib && ./build-dosbox.sh) || exit 1 +new="-I$top/vs2015/zlib/linux-host/include " +nld="-L$top/vs2015/zlib/linux-host/lib " +export CFLAGS="$new$CFLAGS -g3" +export LDFLAGS="$nld$LDFLAGS -g3" +export CPPFLAGS="$new$CPPFLAGS -g3" +export CXXFLAGS="$new$CXXFLAGS -g3" + +# perfer to compile against our own libpng (comment this out to disable) +echo Compiling our internal libpng +(cd vs2015/libpng && ./build-dosbox.sh) || exit 1 +new="-I$top/vs2015/libpng/linux-host/include " +nld="-L$top/vs2015/libpng/linux-host/lib " +export CFLAGS="$new$CFLAGS -g3" +export LDFLAGS="$nld$LDFLAGS -g3" +export CPPFLAGS="$new$CPPFLAGS -g3" +export CXXFLAGS="$new$CXXFLAGS -g3" + +# perfer to compile against our own freetype +echo Compiling our internal freetype +(cd vs2015/freetype && ./build-dosbox.sh) || exit 1 +new="-I$top/vs2015/freetype/linux-host/include/freetype2 " +nld="-L$top/vs2015/freetype/linux-host/lib -lfreetype " +export CFLAGS="$new$CFLAGS -g3" +export LDFLAGS="$nld$LDFLAGS -g3" +export CPPFLAGS="$new$CPPFLAGS -g3" +export CXXFLAGS="$new$CXXFLAGS -g3" +export INTERNAL_FREETYPE=1 + +# now compile ourself +echo Compiling DOSBox-X +chmod +x configure +./configure --enable-core-inline --enable-debug=heavy --prefix=/usr --enable-sdl2 --disable-avcodec "$@" || exit 1 +make -j3 || exit 1 + diff --git a/src/hardware/opl3duoboard/opl3duoboard.cpp b/src/hardware/opl3duoboard/opl3duoboard.cpp index 39a435fef..599e4ef20 100644 --- a/src/hardware/opl3duoboard/opl3duoboard.cpp +++ b/src/hardware/opl3duoboard/opl3duoboard.cpp @@ -12,15 +12,15 @@ void Opl3DuoBoard::connect(const char* port) { comport = 0; if (SERIAL_open(port, &comport)) { SERIAL_setCommParameters(comport, 115200, 'n', SERIAL_1STOP, 8); - printf("OK\n"); - + printf("OPL3 Duo! Board: COM Port OK.\n"); + #if !defined(HX_DOS) && !(defined(__MINGW32__) && !defined(__MINGW64_VERSION_MAJOR)) resetBuffer(); stopOPL3DuoThread = false; - thread = std::thread(&Opl3DuoBoard::writeBuffer, this); + thread = std::thread(&Opl3DuoBoard::writeBuffer,this); #endif } else { - printf("FAIL\n"); + printf("OPL3 Duo! Board: Unable to open COM port Failed.\n"); } } @@ -75,21 +75,49 @@ void Opl3DuoBoard::write(uint32_t reg, uint8_t val) { #if OPL3_DUO_BOARD_DEBUG printf("OPL3 Duo! Board: Write %d --> %d\n", val, reg); #endif - + #if !defined(HX_DOS) && !(defined(__MINGW32__) && !defined(__MINGW64_VERSION_MAJOR)) sendBuffer[bufferWrPos] = (reg >> 6) | 0x80; sendBuffer[bufferWrPos + 1] = ((reg & 0x3f) << 1) | (val >> 7); sendBuffer[bufferWrPos + 2] = (val & 0x7f); bufferWrPos = (bufferWrPos + 3) % OPL3_DUO_BUFFER_SIZE; + #else + uint8_t sendBuffer[3]; + + sendBuffer[0] = (reg >> 6) | 0x80; + sendBuffer[1] = ((reg & 0x3f) << 1) | (val >> 7); + sendBuffer[2] = (val & 0x7f); + + SERIAL_sendchar(comport, sendBuffer[0]); + SERIAL_sendchar(comport, sendBuffer[1]); + SERIAL_sendchar(comport, sendBuffer[2]); + #endif } } void Opl3DuoBoard::writeBuffer() { #if !defined(HX_DOS) && !(defined(__MINGW32__) && !defined(__MINGW64_VERSION_MAJOR)) - do { + + #if !defined(MACOS) + /* Note:(josephillips85) This is a workaround to fix the thread stop issue presented on MacOS + Probably hitting this BUG https://github.com/apple/darwin-libpthread/blob/main/src/pthread.c#L2177 + Already tested on MacOS Big Sur 11.2.1 */ + + while(!stopOPL3DuoThread) { + if (bufferRdPos != bufferWrPos){ + SERIAL_sendchar(comport, sendBuffer[bufferRdPos]); + bufferRdPos = (bufferRdPos + 1) % OPL3_DUO_BUFFER_SIZE; + + } + } + #else + + do { while(bufferRdPos != bufferWrPos) { SERIAL_sendchar(comport, sendBuffer[bufferRdPos]); bufferRdPos = (bufferRdPos + 1) % OPL3_DUO_BUFFER_SIZE; } } while(!stopOPL3DuoThread); + + #endif #endif } diff --git a/src/hardware/opl3duoboard/opl3duoboard.h b/src/hardware/opl3duoboard/opl3duoboard.h index bc10e7afb..07ce9799f 100644 --- a/src/hardware/opl3duoboard/opl3duoboard.h +++ b/src/hardware/opl3duoboard/opl3duoboard.h @@ -6,6 +6,7 @@ #ifndef OPL3_DUO_BOARD #define OPL3_DUO_BOARD #define OPL3_DUO_BUFFER_SIZE 9000 + // Output debug information to the DosBox console if set to 1 #define OPL3_DUO_BOARD_DEBUG 0 @@ -24,7 +25,8 @@ #if !defined(HX_DOS) && !(defined(__MINGW32__) && !defined(__MINGW64_VERSION_MAJOR)) std::thread thread; - bool stopOPL3DuoThread; + bool stopOPL3DuoThread = false; + #endif COMPORT comport; uint8_t sendBuffer[OPL3_DUO_BUFFER_SIZE];