Building Atari800 for MS Windows
================================

There are several ways to build an Atari800 executable on Windows:

- using a Unix-like environment such as Cygwin, MinGW or MSYS2,
- using Microsoft 32-bit C/C++ Compiler.

Table of contents:

I) Building using Cygwin, MinGW, MinGW-w64, MSYS2 etc.
I.1) Building the DirectX version
I.2) Building the SDL version
I.3) Notes on building using Cygwin
I.4) Notes on building using MinGW
I.5) Notes on building using MSYS2
II) Building using Microsoft 32-bit C/C++ Compiler


I) Building using Cygwin, MinGW, MinGW-w64, MSYS2 etc.
------------------------------------------------------

All of these toolchains provide a Unix-like environment on Windows, so building
Atari800 with them is based on the same configure/make sequence as on other
platforms. The procedure is described in detail in DOC/INSTALL, section
"Building the Emulator on most platforms" - read it before continuing below.

There are several configure options applicable to the Windows platform:
1. Type "./configure --target=windx" to build a version that uses DirectX for
   display, sound and input.

2. Type "./configure --with-video=<choice> --with-sound=<choice>" to build other
   versions. The available options are:
   * --with-video:
     * sdl - uses SDL,
     * ncurses - uses the ncurses library,
     * no - pure console interface.
   * --with-sound:
     * win - uses WinMM,
     * sdl - uses SDL,
     * no - no sound.
   You can add other configure options if desired.

The recommended version is --with-video=sdl --with-audio=sdl, as it has the
largest set of features.


I.1) Building the DirectX version
---------------------------------

You will need the DirectX SDK release not newer than the one from August 2007,
as it is the last one to contain the now-deprecated DirectInput libraries.


I.2) Building the SDL version
-----------------------------

The procedure for building the SDL version is described in DOC/INSTALL, section
"Building the Emulator for SDL".


I.3) Notes on building using Cygwin
-----------------------------------

1. Get Cygwin at http://cygwin.com/
2. The executable requires the following DLLs: /bin/mgwz.dll and (for SDL)
   sdl.dll - copy them to the same directory as atari800.exe.


I.4) Notes on building using MinGW
----------------------------------

1. To build the SDL version with OpenGL support, get the OpenGL headers at
   http://www.libsdl.org/extras/win32/common/opengl-devel.tar.gz .
   See also http://www.libsdl.org/extras/win32/mingw32/README.txt
2. If the configure script does not find the SDL library, you might need to add
   "--with-sdl-prefix=/mingw" to the configure options.


I.5) Notes on building using MSYS2
----------------------------------

1. Install MSYS2 itself:
  - Based on:
    https://www.msys2.org/
    https://github.com/msys2/msys2/wiki/MSYS2-installation
  a) Get the MSYS2 installer package from https://www.msys2.org/ . Choose the
     one that matches your Windows architecture (i686 or x86_64). The
     instructions below is tailored towards MSYS2 release dated 20180531, which
     was the latest at the time of this writing.
  b) Run the installer to install the environment.
     - Note: MSYS2 provides 3 Start menu shortcuts to the MSYS shell:
     "MSYS2 MSYS" - use this and only this shell to install or remove packages.
     "MSYS2 MinGW 32-bit" - use this shell to build 32-bit programs.
     "MSYS2 MinGW 64-bit" - use this shell to build 64-bit programs.
  c) If not selected at the end of installer, run "MSYS2 MSYS" shell (from Start
     menu).
  d) Update the environment using pacman -Syuu. Run it multiple times until no
     more packages are left to update.
     Note: if after an update there appears a message to "exit pacman without
     returning to the MSYS shell", then close the MSYS shell window, and use
     Task Manager to kill the "pacman.exe" process that is left hanging. Then
     re-run "MSYS2 MSYS" to continue updating.

2. Install packages required by Atari800:
  - Note: to install a package, enter
    pacman -S <package_name1> <package_name2> ...
  a) Start the "MSYS2 MSYS" shell.
  b) If you want to regenerate the configure script, install the following
     packages:
     - autoconf
     - perl
  c) To build Atari800, install:
     - make
     To build the 32-bit binary, install:
     - mingw-w64-i686-gcc
     - mingw-w64-i686-SDL
     - mingw-w64-i686-readline
     - mingw-w64-i686-libpng
     To build the 64-bit binary, install:
     - mingw-w64-x86_64-gcc
     - mingw-w64-x86_64-SDL
     - mingw-w64-x86_64-readline
     - mingw-w64-x86_64-libpng

3. Build Atari800:
  a) Start the "MSYS2 MinGW 32-bit" shell to build the 32-bit binary, or the
     "MSYS2 MinGW 64-bit" shell to build the 64-bit binary.
  b) Follow the common build procedure as described in DOC/INSTALL, section
     "Building the Emulator for SDL".
  c) The executable requires the following DLLs - copy them from mingw32/bin or
     mingw64/bin (depending on which binary you have built) to the same
     directory as atari800.exe:
     - libpng16-16.dll
     - libreadline7.dll
     - libtermcap-0.dll
     - SDL.dll
     - zlib1.dll
     For the 32-bit binary also copy:
     - libgcc_s_dw2-1.dll
     - libwinpthread-1.dll


II) Building using Microsoft 32-bit C/C++ Compiler
--------------------------------------------------

Atari800 for Windows can be built using command-line tools
from Microsoft Visual C++ 2005.  Avoid older compilers such as VC++ 6
because they are buggy (even with service packs) and unsupported.
In addition to the compiler suite you need Windows Platform SDK (included
in Visual C++ 2008 or newer) and DirectX SDK (not newer than the August 2007
version, as it is the last one to contain the now-deprecated DirectInput
libraries.) Set "Path", "INCLUDE" and "LIB" environment variables to point to
the correct locations in VC++, PSDK and DXSDK.

1. Install the ZLIB library:
a. Download the source code from http://www.zlib.org
b. Remove -MD from CFLAGS in win32\Makefile.msc
c. Compile with "nmake /f win32\Makefile.msc zlib.lib".
d. Copy zlib.h and zconf.h to the Include directory of VC++.
e. Copy zlib.lib to the Lib directory of VC++.
2. Install the LIBPNG library:
a. Download the source code from http://www.libpng.org
b. Remove -MD from CFLAGS in scripts\makefile.vcwin32
c. Compile with "nmake /f scripts\makefile.vcwin32".
d. Copy png.h and pngconf.h to the Include directory of VC++.
e. Copy libpng.lib to the Lib directory of VC++.
OR
1&2. #undef HAVE_LIBPNG and HAVE_LIBZ in Atari800's src\win32\msc\config.h.
     The compiled emulator won't handle zlib-compressed disk images
     and state files and won't produce PNG screenshots.
3. Navigate to the src directory of Atari800 sources.
4. Type "nmake /f win32\msc\Makefile".
5. If you are getting linking errors saying something about MSVCRT
   then you probably ignored step 1b or 2b.
6. Copy atari800.exe to destination directory.
