
How to compile TTDPatch
-----------------------

Why is it so difficult?

The difficulties that arise come from the fact that TTDPatch must be a
16bit DOS program, but incorporate 32bit protected mode code.  This
means it must use some pretty special constructs to be compiled.  In
particular, the 32bit code must not have any relocations, and it must
be linked in to a special segment in a special location.

In addition, the source is used for both the Windows and DOS versions 
use the same code for the most part (except for a few special functions), 
that makes it necessary to do a fair bit if #if WINTTDX testing.


What are the compilation defines?

The following defines are used by both the assembler and C sources:

DEBUG		If 0, this is a beta or release version.  If 1 it
		is alpha, and contains some help for debugging.
		By default it is 1.  See notes below under "running it".
WINTTDX		If 0, compile for the DOS version.  If 1, compile
		for the Windows version.  There are no other allowed 
		values for this define.

These defines are always defined, but have different values.  Therefore, 
don't test the with #ifdef DEBUG which will always be true, but use 
#if DEBUG or #if !DEBUG to test the #define value.


What software you need
======================

To compile TTDPatch using the provided makefile and batch files, you need
the following software:

- The Cygwin distribution, from http://www.cygwin.com/
  In particular, you need GNU Make, gcc, the binutils, the fileutils,
  grep, gawk, the nasm sources (look in the nasm/ directory too!),
  Perl 5.8.0 or higher (currently experimental), unzip, and perhaps some 
  other Cygwin packages.  Of course you also need the prerequisites for
  each of the above packages.  Let me know if you find you need another 
  package that I haven't listed.
- Borland C++ for DOS 3.1 or higher to compile the DOS version
  OR OpenWatcom for DOS (set compiler with USEBCC in Makefile)
- Texinfo to compile the documentation
- The most recent UPX EXE packer to compress ttdpatch.exe

You can install Perl 5.6.1 if you don't need to update the language files.
The language files need Perl 5.8.0 or higher because of its superior Unicode
processing capabilities.

The files in bin/ assume that you're using the Far Commander as shell.  If 
you prefer a different shell just edit bin/t2.bat whichever way you want.

Make sure that after installing, you edit bin/setall.bat to tell
the programs where everything is.  Also make sure that setall.bat is 
actually called before you try to run make!  If you have the Far Commander
you just need to run t.bat and everything should be fine.

The PATH environment variable should contain these dirs in the following order:
(CYGWIN)\BIN
(TTDPATCHSRC)\BIN
(BORLANDC3.1)\BIN
(TASM5.0)\BIN
(BORLANDC5.5)\BIN


How to compile it
=================

Assuming that you have all the above software, in all the above paths
and so on, and have started Far Commander from the t2.bat file in BIN, or
otherwise entered your favourite shell, you can run the following commands 
to start the compilation:

make
make all
make dos	any of the above will compile the DOS version of TTDPatch

make allw
make win	any of the above will compile the Windows version of TTDPatch

make clean	to delete all compiled files
make cleantemp	to delete only temporary files
make remake	force recompilation (use this when you change between 
		DEBUG=0 and DEBUG=1 for example)

There are a few other pseudo-targets but these are the most important
ones.  Study the makefile for enlightenment.

Running it
==========

By default, TTDPatch is compiled with DEBUG=1, which puts a few INT3 debug
breakpoints in the code.  For the DOS version, these are usually harmless.
The Windows version however crashes if these instructions are executed and
there is no debugger to handle them.

This means that if you compile TTDPatch for Windows with DEBUG=1, you must
load a debugger that traps these instructions.  Alternatively, you can
compile the patch with DEBUG=0, or simply comment out the INT3 in proc
winloader in loader.ah.  The other INT3 instructions are only executed 
when there is some problem that can't be handled otherwise, just to draw your
attention.

Alternatively, uncomment the NASMDEF += -dNOINT3 line in the Makefile to
remove the INT3 instructions even for debugging versions.
