ECHO +====================================================================+
ECHO + Build ReDMCSB executable files for Atari ST                        +
ECHO +====================================================================+

PATH \MEGAMAX

CD \SOURCE

ECHO OFF
ECHO ----------------------------------------------------------------------
ECHO - Replace C loader in Megamax C library SYSLIB
ECHO ----------------------------------------------------------------------
ECHO ON
REM Replace C loader object code in the system library used by the Megamax linker
REM with original version supplied with Megamax C but not processed through the
REM code improver (which leaves a ble instead of a ble.s in the default one)
REM It is used for the utility disk START.PRG, MKBIN.PRG and for DMPACK.TOS
MKSSINIT.BAT \MEGAMAX \OBJECT\SU1E\START.PRG INIT

ECHO OFF
IF NOT EXISTS \SOURCE\EXEID106.TXT GOTO EXEID124
ECHO ----------------------------------------------------------------------
ECHO - Build executable S10EA\BOOTSECT.BIN
ECHO ----------------------------------------------------------------------
ECHO ON
MKSSBIN.BAT \SOURCE\BOOTSECT.C S10EA BOOTSECT.BIN -DEXEID=106
IF EXISTS ERRORS.OUT COPY ERRORS.OUT \OBJECT\S10EA\BOOTSECT.BIN\BOOTSECT.ERR

:EXEID124
ECHO OFF
IF NOT EXISTS \SOURCE\EXEID124.TXT GOTO EXEID112
ECHO ----------------------------------------------------------------------
ECHO - Build executable SU1E\BOOTSECT.BIN
ECHO ----------------------------------------------------------------------
ECHO ON
MKSSBIN.BAT \SOURCE\BOOTSECT.C SU1E BOOTSECT.BIN -DEXEID=124
IF EXISTS ERRORS.OUT COPY ERRORS.OUT \OBJECT\SU1E\BOOTSECT.BIN\BOOTSECT.ERR

:EXEID112
ECHO OFF
IF NOT EXISTS \SOURCE\EXEID112.TXT GOTO EXEID107
ECHO ----------------------------------------------------------------------
ECHO - Build executable S10EA\SWOOSH.IMG
ECHO ----------------------------------------------------------------------
ECHO ON
MKSSBIN.BAT \SOURCE\SWSH.C S10EA SWOOSH.IMG -DEXEID=112
IF EXISTS ERRORS.OUT COPY ERRORS.OUT \OBJECT\S10EA\SWOOSH.IMG\SWSH.ERR

:EXEID107
ECHO OFF
IF NOT EXISTS \SOURCE\EXEID107.TXT GOTO EXEID119
ECHO ----------------------------------------------------------------------
ECHO - Build executable S10EA\GRAPH21.BIN
ECHO ----------------------------------------------------------------------
ECHO ON
MKSSBIN.BAT \SOURCE\GRAPH21.C S10EA GRAPH21.BIN -DEXEID=107
IF EXISTS ERRORS.OUT COPY ERRORS.OUT \OBJECT\S10EA\GRAPH21.BIN\GRAPH21.ERR

:EXEID119
ECHO OFF
IF NOT EXISTS \SOURCE\EXEID119.TXT GOTO EXEID108
ECHO ----------------------------------------------------------------------
ECHO - Build executable S20E\GRAPH21.BIN
ECHO ----------------------------------------------------------------------
ECHO ON
MKSSBIN.BAT \SOURCE\GRAPH21.C S20E GRAPH21.BIN -DEXEID=119
IF EXISTS ERRORS.OUT COPY ERRORS.OUT \OBJECT\S20E\GRAPH21.BIN\GRAPH21.ERR

:EXEID108
ECHO OFF
IF NOT EXISTS \SOURCE\EXEID108.TXT GOTO EXEID109
ECHO ----------------------------------------------------------------------
ECHO - Build executable S10EA\GRAPH538.BIN
ECHO ----------------------------------------------------------------------
ECHO ON
MKSSBIN.BAT \SOURCE\GRAPH538.C S10EA GRAPH538.BIN -DEXEID=108
IF EXISTS ERRORS.OUT COPY ERRORS.OUT \OBJECT\S10EA\GRAPH538.BIN\GRAPH538.ERR

:EXEID109
ECHO OFF
IF NOT EXISTS \SOURCE\EXEID109.TXT GOTO EXEID122
ECHO ----------------------------------------------------------------------
ECHO - Build executable S10EA\GRAPH548.BIN
ECHO ----------------------------------------------------------------------
ECHO ON
MKSSBIN.BAT \SOURCE\GRAPH548.C S10EA GRAPH548.BIN -DEXEID=109
IF EXISTS ERRORS.OUT COPY ERRORS.OUT \OBJECT\S10EA\GRAPH548.BIN\GRAPH548.ERR

:EXEID122
ECHO OFF
IF NOT EXISTS \SOURCE\EXEID122.TXT GOTO EXEID128
ECHO ----------------------------------------------------------------------
ECHO - Build executable SDMP\DMPACK.TOS
ECHO ----------------------------------------------------------------------
ECHO ON
REM Compile source code file to object file
MMCC.TTP DMPACK.C -DEXEID=122
IF EXISTS ERRORS.OUT COPY ERRORS.OUT \OBJECT\SDMP\DMPACK.TOS\DMPACK.ERR
COPY DMPACK.O \OBJECT\SDMP\DMPACK.TOS\DMPACK.O
DEL \SOURCE\DMPACK.O
REM Do not improve DMPACK.O with code improver MMIMP.TTP
REM Disassemble object file to assembly file
IF EXISTS \SOURCE\ASSEMBLY.TXT MMDIS.TTP \OBJECT\SDMP\DMPACK.TOS\DMPACK.O -o \OBJECT\SDMP\DMPACK.TOS\DMPACK.S
REM Link object file to executable file
MMLINK.TTP \OBJECT\SDMP\DMPACK.TOS\DMPACK.O -o \BUILD\SDMP\DMPACK.TOS -M \BUILD\SDMP\DMPACK.MAP

:EXEID128
ECHO OFF
IF NOT EXISTS \SOURCE\EXEID128.TXT GOTO EXEID111
ECHO ----------------------------------------------------------------------
ECHO - Build executable SU1E\START.PRG
ECHO ----------------------------------------------------------------------
ECHO ON
REM Compile source code file to object file
MMCC.TTP PRIM1.C -DEXEID=128
IF EXISTS ERRORS.OUT COPY ERRORS.OUT \OBJECT\SU1E\START.PRG\PRIM1.ERR
COPY PRIM1.O \OBJECT\SU1E\START.PRG\PRIM1.O
DEL \SOURCE\PRIM1.O
REM Do not improve PRIM1.O with code improver MMIMP.TTP
REM Disassemble object file to assembly file
IF EXISTS \SOURCE\ASSEMBLY.TXT MMDIS.TTP \OBJECT\SU1E\START.PRG\PRIM1.O -o \OBJECT\SU1E\START.PRG\PRIM1.S
REM Link object file to executable file
MMLINK.TTP \OBJECT\SU1E\START.PRG\PRIM1.O -o \BUILD\SU1E\START.PRG -M \BUILD\SU1E\START.MAP

:EXEID111
ECHO OFF
IF NOT EXISTS \SOURCE\EXEID111.TXT GOTO EXEID120
ECHO ----------------------------------------------------------------------
ECHO - Build executable S10EA\START.PRG
ECHO ----------------------------------------------------------------------
ECHO ON
REM Replace C loader object code in the system library used by the Megamax linker
REM with a custom version for START.PRG by FTL (based on original Megamax C loader)
MKSSINIT.BAT \SOURCE \OBJECT\S10EA\START.PRG INITSTRT -DEXEID=111
REM Compile source code file to object file
MMCC.TTP STARTGD.C -DEXEID=111
IF EXISTS ERRORS.OUT COPY ERRORS.OUT \OBJECT\S10EA\START.PRG\STARTGD.ERR
COPY STARTGD.O \OBJECT\S10EA\START.PRG\STARTGD.O
DEL \SOURCE\STARTGD.O
REM Do not improve STARTGD.O with code improver MMIMP.TTP
REM Disassemble object file to assembly file
IF EXISTS \SOURCE\ASSEMBLY.TXT MMDIS.TTP \OBJECT\S10EA\START.PRG\STARTGD.O -o \OBJECT\S10EA\START.PRG\STARTGD.S
REM Link object file to executable file
MMLINK.TTP \OBJECT\S10EA\START.PRG\STARTGD.O -o \BUILD\S10EA\START.PRG -M \BUILD\S10EA\START.MAP

:EXEID120
ECHO ON
REM Replace C loader object code in the system library used by the Megamax linker
REM with a custom version for the game by FTL (based on original Megamax C loader)
MKSSINIT.BAT \SOURCE \OBJECT\S10EA\START.PAK INITENG -DEXEID=110

REM Build game executable files and game executable files without the copy protection
ECHO OFF
IF NOT EXISTS \SOURCE\EXEID120.TXT GOTO EXEID110
MKSSGAME.BAT S20E  START      S20S21.LNK -DEXEID=120
REM MKSSGAME.BAT S20E  STARTNCP S20S21.LNK -DEXEID=120 -DNOCOPYPROTECTION=1
:EXEID110
IF NOT EXISTS \SOURCE\EXEID110.TXT GOTO EXEID113
MKSSGAME.BAT S10EA START      S10.LNK    -DEXEID=110
REM MKSSGAME.BAT S10EA STARTNCP S10.LNK    -DEXEID=110 -DNOCOPYPROTECTION=1
:EXEID113
IF NOT EXISTS \SOURCE\EXEID113.TXT GOTO EXEID114
MKSSGAME.BAT S10EB START      S10.LNK    -DEXEID=113
REM MKSSGAME.BAT S10EB STARTNCP S10.LNK    -DEXEID=113 -DNOCOPYPROTECTION=1
:EXEID114
IF NOT EXISTS \SOURCE\EXEID114.TXT GOTO EXEID115
MKSSGAME.BAT S11E  START      S11.LNK    -DEXEID=114
REM MKSSGAME.BAT S11E  STARTNCP S11.LNK    -DEXEID=114 -DNOCOPYPROTECTION=1
:EXEID115
IF NOT EXISTS \SOURCE\EXEID115.TXT GOTO EXEID116
MKSSGAME.BAT S12E  START      S12S13.LNK -DEXEID=115
REM MKSSGAME.BAT S12E  STARTNCP S12S13.LNK -DEXEID=115 -DNOCOPYPROTECTION=1
:EXEID116
IF NOT EXISTS \SOURCE\EXEID116.TXT GOTO EXEID117
MKSSGAME.BAT S12G  START      S12S13.LNK -DEXEID=116
REM MKSSGAME.BAT S12G  STARTNCP S12S13.LNK -DEXEID=116 -DNOCOPYPROTECTION=1
:EXEID117
IF NOT EXISTS \SOURCE\EXEID117.TXT GOTO EXEID118
MKSSGAME.BAT S13FA START      S12S13.LNK -DEXEID=117
REM MKSSGAME.BAT S13FA STARTNCP S12S13.LNK -DEXEID=117 -DNOCOPYPROTECTION=1
:EXEID118
IF NOT EXISTS \SOURCE\EXEID118.TXT GOTO EXEID121
MKSSGAME.BAT S13FB START      S12S13.LNK -DEXEID=118
REM MKSSGAME.BAT S13FB STARTNCP S12S13.LNK -DEXEID=118 -DNOCOPYPROTECTION=1
:EXEID121
IF NOT EXISTS \SOURCE\EXEID121.TXT GOTO END
MKSSGAME.BAT S21E  START      S20S21.LNK -DEXEID=121
REM MKSSGAME.BAT S21E  STARTNCP S20S21.LNK -DEXEID=121 -DNOCOPYPROTECTION=1

:END
CD ..

ECHO +====================================================================+
ECHO + Build complete                                                     +
ECHO +====================================================================+
