projects::hatari

summary

NOTE: This project is not run, sponsored, or endorsed by my employer or the Hatari developers. Please go here for the official Hatari project website.
 

Hatari is an Atari ST/STE/TT/Falcon emulator for a wide variety of platforms, including Linux, Windows, macOS, and even Android. It can run on virtually any platform that supports the SDL library.

I've been doing some changes in the past few weeks to enable Hatari to build for Windows 10 ARM64.

current binary releases

All releases are GPG-signed with my current public key (Key ID is 0x08B64D879E452650 or local copy)

source code

The source code is available in git, as a series of patches applied on top of the official Hatari sources.

building from source

First you need the code with changes to build on Microsoft Visual Studio 2019:

git clone -b vcf-2019 https://git.uplinklabs.net/steven/projects/hatari.git

You need to first build SDL and optionally capsimage (and other dependencies like libpng, depending on the features you want to have in your build of Hatari).

building sdl

SDL is the first dependency to take care of. Unzip the SDL 2.0.9 (or later) sources, and then do something like this:

mkdir SDL2-arm64
cd SDL2-arm64
cmake \
	-G "Visual Studio 16 2019" \
	-A arm64 \
	-DCMAKE_INSTALL_PREFIX="C:/SDK/SDL2/arm64" \
	..\SDL2-2.0.9
cmake --build . --target install --config Release

Currently the above will fail, with this:

     Creating library D:/dev/SDL2-arm64/Release/SDL2.lib and object D:/dev/SDL2-arm64/Release/SDL2.exp
SDL_string.obj : error LNK2019: unresolved external symbol memset referenced in function SDL_vsnprintf_REAL [D:\dev\SDL2-arm64\SDL2.vcxproj]
SDL_dinputjoystick.obj : error LNK2019: unresolved external symbol memcpy referenced in function EnumJoysticksCallback [D:\dev\SDL2-arm64\SDL2.vcxproj]
D:\dev\SDL2-arm64\Release\SDL2.dll : fatal error LNK1120: 2 unresolved externals [D:\dev\SDL2-arm64\SDL2.vcxproj]
  SDL2-static.vcxproj -> D:\dev\SDL2-arm64\Release\SDL2-static.lib
  SDL2main.vcxproj -> D:\dev\SDL2-arm64\Release\SDL2main.lib

The easiest fix is just to add vcruntime to the link list:

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 0128c7a..08e99a9 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1292,7 +1292,7 @@ elseif(WINDOWS)
   endif()

   # Libraries for Win32 native and MinGW
-  list(APPEND EXTRA_LIBS user32 gdi32 winmm imm32 ole32 oleaut32 version uuid advapi32 shell32)
+  list(APPEND EXTRA_LIBS vcruntime user32 gdi32 winmm imm32 ole32 oleaut32 version uuid advapi32 shell32)

   # TODO: in configure.in the check for timers is set on
   # cygwin | mingw32* - does this include mingw32CE?

Once you've fixed the library list, you can attempt the build again:

cmake --build . --target install --config Release

building hatari

Once you have the prerequisites built and installed for ARM64 Windows, you can configure Hatari with CMake:

mkdir hatari-arm64
cd hatari-arm64
cmake \
	-G "Visual Studio 16 2019" \
	-A arm64 \
	-DSDL2_LIBRARY="C:/SDK/SDL2/arm64/lib/SDL2.lib" \
	-DSDL2MAIN_LIBRARY="C:/SDK/SDL2/arm64/lib/SDL2main.lib" \
	-DSDL2_INCLUDE_DIR="C:/SDK/SDL2/arm64/include/SDL2" \
	..\hatari

If you are building on an ARM64 device directly, then you can just build the solution as it is:

cmake --build . --target hatari --config Release

cross compiling with a twist

However, building Hatari for Windows ARM64 is a bit tricky if your host cannot run ARM64 binaries, because Hatari builds and runs some tools from source code:

  build68k.vcxproj -> D:\dev\hatari-arm64\src\cpu\Release\build68k.exe
  Generating cpudefs.c
  This version of D:\dev\hatari-arm64\src\cpu\Release\build68k.exe is not compatible with the version of Windows you're
	running. Check your computer's system information and then contact the software publisher.
	C:\Program Files (x86)\Microsoft Visual
	Studio\2019\Professional\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets(209,5): error MSB6006: "cmd.exe" exit ed
	with code 216. [D:\dev\hatari-arm64\src\cpu\gencpu.vcxproj]

To get around this issue, you can build the tools for your host architecture (such as x86 or x64) and change the generated ARM64 projects to use those tools when required. The commands shown below will build the two tools we need to finish the ARM64 build. Note that the SDL2-related arguments for CMake here point to the wrong binaries (ARM64) for the host architecture (x64). Obviously this is wrong, and the build should fail, right? Well, no. We don't really care because we only need to build some tools which have no dependency on SDL to run -- we only pass in the SDL paths here to ensure that CMake configure doesn't error out complaining that SDL is missing. We don't need the x64 build of Hatari itself, or anything else in the project requiring SDL2.

mkdir hatari-x64
cmake \
	-G "Visual Studio 16 2019" \
	-A x64
	-DSDL2_LIBRARY="C:/SDK/SDL2/arm64/lib/SDL2.lib" \
	-DSDL2MAIN_LIBRARY="C:/SDK/SDL2/arm64/lib/SDL2main.lib" \
	-DSDL2_INCLUDE_DIR="C:/SDK/SDL2/arm64/include/SDL2" \
	..\hatari
cmake --build . --target gencpu --config Release

Now that the "gencpu.exe" and "build68k.exe" tools are built for your host architecture, you'll have to fix the paths in the ARM64-configured Hatari Visual Studio solution. Open up Hatari.sln in your Hatari-arm64 directory.

You can find the first one in the properties for "cpudefs.c.rule" in the "gencpu" project. Just change the path for build68k.exe to your x64 build here.

cpudefs.c.rule in the gencpu project
change the command line to the x64 build68k.exe path

 

The second one is in the "UaeCpu" project in the properties for the "cpustbl.c.rule" item:

cpustbl.c.rule in the UaeCpu project
change the command line to the x64 gencpu.exe path

 

Now just build the "Hatari" project with the "Release" configuration inside Visual Studio, and you'll have a hatari.exe file you can run on your Windows ARM64 device! Don't forget to copy any dependencies (e.g. SDL, libpng, capsimage) into the directory hatari.exe resides in.