Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get libretro core compiling for Windows #198

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
9 changes: 9 additions & 0 deletions .github/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,15 @@ You can use `sudo apt-get -y install $(cat AppleWin/source/linux/raspbian.list.t

See [Travis](/.travis.yml) CI too.

### Windows (libretro core only)

Build using msys2, using the standard build instructions below.

Install the following packages (for x64 build):
```
pacman -S mingw-w64-x86_64-cmake mingw-w64-x86_64-libyaml mingw-w64-x86_64-minizip mingw-w64-x86_64-libslirp
```

### Building

```
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -249,3 +249,6 @@ CMakeLists.txt.user*

# VSCode
.vscode

# libretro
source/frontends/libretro/*.inl
8 changes: 7 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
add_compile_options(-Werror=format -Wno-error=format-overflow -Wno-error=format-truncation -Wno-psabi)
endif()

if (BUILD_LIBRETRO)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-libgcc -static-libstdc++")
endif()
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

libretro should statically link to as much as possible to prevent possible missing dependency errors and/or conflicting versions of dependencies between the core and the frontend.


MESSAGE("CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")
MESSAGE("CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}")
MESSAGE("CMAKE_CXX_FLAGS_RELEASE: ${CMAKE_CXX_FLAGS_RELEASE}")
Expand Down Expand Up @@ -54,7 +58,9 @@ endif()
include_directories(source)

add_subdirectory(source)
add_subdirectory(source/linux/libwindows)
if (NOT WIN32)
add_subdirectory(source/linux/libwindows)
endif()
add_subdirectory(test/TestCPU6502)

if (BUILD_LIBRETRO OR BUILD_APPLEN OR BUILD_SA2)
Expand Down
96 changes: 62 additions & 34 deletions source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ if ("${SLIRP_FOUND}" STREQUAL "")
endif()
endif()

find_package(Boost REQUIRED)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

boost is now only pulled in to the common2 library, and only if building the files dependent on it.


set(SOURCE_FILES
Tfe/tfesupp.cpp
Tfe/NetworkBackend.cpp
Expand Down Expand Up @@ -103,19 +101,13 @@ set(SOURCE_FILES
FrameBase.cpp
CmdLine.cpp

Configuration/PropertySheetHelper.cpp
Configuration/Config.cpp

linux/resources.cpp
linux/benchmark.cpp
linux/context.cpp
linux/linuxframe.cpp
linux/paddle.cpp
linux/version.cpp
linux/registryclass.cpp
linux/linuxframe.cpp
linux/context.cpp
linux/cassettetape.cpp
linux/network/slirp2.cpp
linux/network/portfwds.cpp
linux/resources.cpp
linux/soundbuffer.cpp
linux/version.cpp
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This directory should be moved. They're no longer linux-specific. I couldn't think of a good name. Maybe they should be moved into the common2 folder?


linux/duplicates/Debugger_Display.cpp
linux/duplicates/Debugger_Win32.cpp
Expand All @@ -132,12 +124,15 @@ set(SOURCE_FILES
linux/duplicates/PageSound.cpp
linux/duplicates/PageDisk.cpp
linux/duplicates/PageAdvanced.cpp

Configuration/PropertySheetHelper.cpp
Configuration/Config.cpp

Z80VICE/z80.cpp
Z80VICE/z80mem.cpp
Z80VICE/daa.cpp
)

set(HEADER_FILES
Tfe/tfearch.h
Tfe/tfesupp.h
Expand Down Expand Up @@ -218,28 +213,63 @@ set(HEADER_FILES
Configuration/PropertySheetHelper.h
Configuration/Config.h

linux/resources.h
linux/linuxinterface.h
linux/benchmark.h
linux/paddle.h
linux/version.h
linux/registryclass.h
linux/keyboardbuffer.h
linux/linuxframe.h
linux/cassettetape.h
linux/network/slirp2.h
linux/network/portfwds.h

Z80VICE/z80.h
Z80VICE/z80mem.h
Z80VICE/z80regs.h
Z80VICE/daa.h
)

if(WIN32)
set(SOURCE_FILES_PLATFORM
Registry.cpp
Keyboard.cpp
Speech.cpp
Tape.cpp
)
set(HEADER_FILES_PLATFORM
Registry.h
Keyboard.h
)
set(EXTRA_LIBS -lwsock32 -liphlpapi -ldsound -ldxguid -lwinmm -ldinput8 -luser32 -lgdi32 -lcomctl32 -lsapi -lstrmiids)

# force static link of dependent libraries
if(EXISTS "${YAML_LIBRARY_DIRS}/libyaml.a")
set(YAML_LIBRARIES -L${YAML_LIBRARY_DIRS};libyaml.a)
endif()
if(EXISTS "${MINIZIP_LIBRARY_DIRS}/libminizip.a")
set(MINIZIP_LIBRARIES -L${MINIZIP_LIBRARY_DIRS};libminizip.a;libz.a;libbz2.a)
endif()
if(EXISTS "${SLIRP_LIBDIR}/libslirp.a")
set(SLIRP_LIBRARIES -L${SLIRP_LIBDIR};libslirp.a;libintl.a)
endif()
else()
set(SOURCE_FILES_PLATFORM
linux/benchmark.cpp
linux/cassettetape.cpp
linux/network/slirp2.cpp
linux/network/portfwds.cpp
)

set(HEADER_FILES_PLATFORM
linux/resources.h
linux/benchmark.h
linux/paddle.h
linux/version.h
linux/registryclass.h
linux/keyboardbuffer.h
linux/linuxframe.h
linux/cassettetape.h
linux/network/slirp2.h
linux/network/portfwds.h
)

set(EXTRA_LIBS windows)
endif()

# we used to generate a shared object, but it turns out there are more cons than pros
add_library(appleii STATIC
${SOURCE_FILES}
${HEADER_FILES}
${SOURCE_FILES} ${SOURCE_FILES_PLATFORM}
${HEADER_FILES} ${HEADER_FILES_PLATFORM}
)

if ("${PCAP_FOUND}" STREQUAL "1")
Expand All @@ -251,7 +281,6 @@ endif()
target_include_directories(appleii PRIVATE
${YAML_INCLUDE_DIRS}
${PCAP_INCLUDE_DIRS}
${Boost_INCLUDE_DIRS}
${SLIRP_INCLUDE_DIRS}
Debugger
)
Expand All @@ -268,10 +297,8 @@ target_link_libraries(appleii PRIVATE
${PCAP_LIBRARIES}
${SLIRP_LIBRARIES}
ZLIB::ZLIB
)

target_link_libraries(appleii PUBLIC
windows
common2
${EXTRA_LIBS}
)

target_link_directories(appleii PRIVATE
Expand All @@ -287,7 +314,8 @@ target_compile_options(appleii PUBLIC

add_custom_command(
TARGET appleii POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/bin/*.SYM ${CMAKE_BINARY_DIR}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

msys2 didn't like the *.SYM, so I split it into two statements.

COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/bin/A2_BASIC.SYM ${CMAKE_BINARY_DIR}
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/bin/APPLE2E.SYM ${CMAKE_BINARY_DIR}
)

configure_file(linux/config.h.in linux/config.h)
2 changes: 1 addition & 1 deletion source/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ enum AppMode_e
#define WM_USER_FULLSCREEN WM_USER+8
#define VK_SNAPSHOT_TEXT WM_USER+9 // PrintScreen+Ctrl

#ifdef _MSC_VER
#ifdef _WIN32
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_MSC_VER is only defined when building with Visual Studio. I've changed most of the _MSC_VER checks to _WIN32.

#define PATH_SEPARATOR '\\'
#else
#define PATH_SEPARATOR '/'
Expand Down
4 changes: 3 additions & 1 deletion source/Debugger/Debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6538,7 +6538,9 @@ bool ParseAssemblyListing ( bool bBytesToMemory, bool bAddSymbols )
{
*p = 0;
// sscanf( sLine, "%s %s %s %s %s %s %s %s", sAddr1, sByte1, sByte2, sByte3, sLineN, sLabel, sAsm, sParam );
sscanf( sLine, "%X", &nAddress );
unsigned nScanAddress; // helper variable in case sizeof(DWORD) != sizeof(unsigned)
sscanf( sLine, "%X", &nScanAddress );
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suspect this will require more care.

I must define DWORD as unsigned int. Can you check what your version of gcc uses?

We will probably have to use a macro to select the correct print format like we already do for size_t and ptrdiff

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on my comments here, mingw uses unsigned long int for DWORD.

By sscanfing into a secondary variable, we know exactly which format to use ("%X" is appropriate for unsigned - see here). The assignment then converts that to whatever DWORD is defined as.

nAddress = nScanAddress;

if (nAddress >= INVALID_ADDRESS) // || (sName[0] == 0) )
continue;
Expand Down
2 changes: 1 addition & 1 deletion source/DiskImage.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

#include "DiskDefs.h"

#ifdef _MSC_VER
#ifdef _WIN32

#define RAND_THRESHOLD(num, den) ((RAND_MAX * num) / den)

Expand Down
4 changes: 2 additions & 2 deletions source/Log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

FILE* g_fh = NULL;

#ifdef _MSC_VER
#ifdef _WIN32
#define LOG_FILENAME "AppleWin.log"
#else
// save to /tmp as otherwise it creates a file in the current folder which can be a bit everywhere
Expand All @@ -49,7 +49,7 @@ inline std::string GetTimeStamp()
{
time_t ltime;
time(&ltime);
#ifdef _MSC_VER
#ifdef _WIN32
char ct[32];
ctime_s(ct, sizeof(ct), &ltime);
#else
Expand Down
8 changes: 4 additions & 4 deletions source/Memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
// This is not available in Windows CRT:
// https://en.cppreference.com/w/c/memory/aligned_alloc

#ifdef _MSC_VER
#ifdef _WIN32
// VirtualAlloc is aligned
#define ALIGNED_ALLOC(size) (LPBYTE)VirtualAlloc(NULL, size, MEM_COMMIT, PAGE_READWRITE)
#define ALIGNED_FREE(ptr) VirtualFree(ptr, 0, MEM_RELEASE)
Expand Down Expand Up @@ -244,7 +244,7 @@ static const UINT kNumAnnunciators = 4;
static bool g_Annunciator[kNumAnnunciators] = {};

static const UINT num64KPages = 2; // number of 64K pages used to create hardware circular buffer
#ifdef _MSC_VER
#ifdef _WIN32
static HANDLE g_hMemImage = NULL; // NB. When not initialised, this handle is NULL (not INVALID_HANDLE_VALUE)
#else
static FILE * g_hMemTempFile = NULL;
Expand Down Expand Up @@ -1528,7 +1528,7 @@ bool MemIsAddrCodeMemory(const USHORT addr)

static void FreeMemImage(void)
{
#ifdef _MSC_VER
#ifdef _WIN32
if (g_hMemImage)
{
for (UINT i = 0; i < num64KPages; i++)
Expand Down Expand Up @@ -1559,7 +1559,7 @@ static void FreeMemImage(void)

static LPBYTE AllocMemImage(void)
{
#ifdef _MSC_VER
#ifdef _WIN32
LPBYTE baseAddr = NULL;

// Allocate memory for 'memimage' (and the alias 'mem')
Expand Down
26 changes: 26 additions & 0 deletions source/SoundBufferBase.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#pragma once

class SoundBufferBase
{
public:
typedef SoundBufferBase* (*CreateSoundBufferFunc)(void);
static CreateSoundBufferFunc Create;

virtual HRESULT Init(DWORD dwFlags, DWORD dwBufferSize, DWORD nSampleRate, int nChannels, LPCSTR pDevName) = 0;
virtual HRESULT Release() = 0;

virtual HRESULT SetCurrentPosition(DWORD dwNewPosition) = 0;
virtual HRESULT GetCurrentPosition(LPDWORD lpdwCurrentPlayCursor, LPDWORD lpdwCurrentWriteCursor) = 0;

virtual HRESULT Lock(DWORD dwWriteCursor, DWORD dwWriteBytes, LPVOID* lplpvAudioPtr1, DWORD* lpdwAudioBytes1, LPVOID* lplpvAudioPtr2, DWORD* lpdwAudioBytes2, DWORD dwFlags) = 0;
virtual HRESULT Unlock(LPVOID lpvAudioPtr1, DWORD dwAudioBytes1, LPVOID lpvAudioPtr2, DWORD dwAudioBytes2) = 0;

virtual HRESULT Stop() = 0;
virtual HRESULT Play(DWORD dwReserved1, DWORD dwReserved2, DWORD dwFlags) = 0;

virtual HRESULT SetVolume(LONG lVolume) = 0;
virtual HRESULT GetVolume(LONG* lplVolume) = 0;

virtual HRESULT GetStatus(LPDWORD lpdwStatus) = 0;
virtual HRESULT Restore() = 0;
};
Loading