# ReDMCSB toolchains

This document describes the ReDMCSB toolchains and their preparation.

## Apple Macintosh

### Overview

- This toolchain builds executables for:
  - Apple IIgs: with Apple MPW IIgs cross-development tools
  - Atari ST (utility disk only), Amiga, X68000: with the THINK C 4.0.5 and 5.0.2 compilers that generate Macintosh executables that are then converted to a custom executable format developed by FTL Games, named 'FTL' because this is the file name extension used for most of them. On the platforms where these executables are used, a small loader program is compiled using a native compiler (Megamax C on Atari ST, Aztec C on Amiga, XC on X68000 - see corresponding toolchains) and all other programs are in the 'FTL' format. Note that some executables use a library that was part of THINK C 3.0.2 even though that version was not used to build any of the released executables.
    One assembly file is assembled with the native MPW Assembler for Macintosh and then converted to a THINK C project for use in an Atari ST executable (ANIMATE.FTL).
- Automation: MPW script and OneClick scripts. MPW scripts are used to automate all the build process. THINK C does not have any built-in feature allowing automation. To work around this limitation, the Oneclick software is used to simulate mouse clicks and key presses in the THINK C user interface. This mechanism is fragile because you can interfere and break the build process if you click mouse buttons or press keys while the scripts are running.
- Operating system: Although FTL Games developed at least some of the original executables on System 6 because System 7 was not yet released, the toolchain uses System 7.5.3 because OneClick requires at least Macintosh System 7 to run. THINK C must be updated to 4.0.5 for System 7 support.
- File transfer between Windows host and emulator: a hard disk image is required to work with the emulator. HFSUtils commands are used to import the necessary files in the disk image before starting emulation, and to export files from the disk image after the build process is complete.
  Macintosh files that use both a data fork and a resource fork are transferred using the BinHex format and the UUDeview command line tool is used to decode such files.
  Screenshots of errors are captured in case of build errors in THINK C. These screenshots are converted from the Macintosh PICT format to Windows BMP with the PictView command line tool.
  CiderPress allows easy manipulation of Macintosh disk images. Although not required to run the ReDMCSB build process, it is used to prepare the hard disk image.

### Preparation

1. Download the following files:
   - Macintosh emulator MinivMac: Use the Advanced Variations Service to build MinivMac using source code branch 36 for Windows 64 bit to emulate a Macintosh II with these options: 'Sound' disabled, 'Initial speed' set to 'All out' and 'Run in Background' enabled. Copy the text line below, paste it in the first text box on the form, click the 'Make custom variation' button and download the compiled executable.
     `-br 36 -t wx64 -m II -sound 0 -speed a -bg 1`
   - Macintosh II ROM: 9779D2C4 - MacII (800k v2).ROM
   - System Software 7.5.3 Revision 2: MacOS_7.5.3.zip
   - MPW 3.5: MPW-GM.img.bin
   - MPW IIgs Tools prerelease version (no known online source, use files supplied with ReDMCSB)
   - MPW IIgs Assembler and MPW IIgs C: APDA_Apple_II_Software_Library.zip (requires registration before downloading)
   - Think C 3.0.2: Thinks LightspeedC 3.0.2 (1988) (3.5-800k).7z
   - Think C 4.0: Symantec THINK C 4.0 for Macintosh (3.5-800k).7z
   - Think C 4.0.5 Update: THINK_C_4.0.5_Update.sea.bin
   - Think C 5.0.2: Symantec THINK C 5.0.2 for Macintosh (3.5-800k).7z
   - OneClick 1.4: OneClick_v1.4.sit
   - Custom OneClick palette for ReDMCSB to automate Macintosh programs (use the file supplied with ReDMCSB)
   - StuffIt Expander 5.5: stuffit_expander_5.5.img
   - HFSUtils: hfsuw31a.zip
   - RSXNT.DLL (required for HFSUtils) from rsxrt150.zip (no known online source, use the file supplied with ReDMCSB)
   - UUDeview: uudeview-win32.zip
   - PictView 1.14 command-line converter: pvw32con.zip
   - CiderPress: CiderPress404.zip
2. Expand these archives with 7-zip:
   - m201115_130141_147.bin.zip
   - MacOS_7.5.3.zip
   - Thinks LightspeedC 3.0.2 (1988) (3.5-800k).7z
   - Symantec THINK C 4.0 for Macintosh (3.5-800k).7z
   - Symantec THINK C 5.0.2 for Macintosh (3.5-800k).7z
   - hfsuw31a.zip
3. Extract the file 'RSXNT.DLL' from rsxrt150.zip and place it in the same folder as HFSUtils executables
4. Rename the ROM file from '9779D2C4 - MacII (800k v2).ROM' to 'MacII.ROM' and place this file in the same folder as 'Mini vMac.exe'
5. Open APDA Apple II Software Library.iso in 7-zip and extract the following folders from the ISO image:
   - MPW IIgs\MPW IIgs Assembler
   - MPW IIgs\MPW IIgs C
6. Run the following PowerShell commands to create two empty disk images of 50MB and 150MB (the second one is used only temporarily to expand Macintosh archives).
   `[IO.File]::WriteAllBytes("D:\ReDMCSB.dsk", (New-Object -TypeName Byte[] -ArgumentList (50*1024*1024)))
   [IO.File]::WriteAllBytes("D:\Temp.dsk", (New-Object -TypeName Byte[] -ArgumentList (150*1024*1024)))`
7. Drag and drop '009-4454(Inst-1).dsk' (System 7.5.3 installation disk 1) on 'Mini vMac.exe' and wait for the system to load
8. Drag and drop 'ReDMCSB.dsk' on the Mini vMac window, initialize the disk with name 'REDMCSB'
9. Install the System on the disk using the Custom Install option and select only System Software / Minimal System Software for this Macintosh. Each time the setup asks for a floppy disk, drag and drop the corresponding file on the Mini vMac window.
10. Shut down the system (menu Special / Shut Down) and close the emulator
11. Duplicate disk image 'ReDMCSB.dsk' to 'ReDMCSB_Extract.dsk'. The first one is kept clean for later use, and the copy is used to extract temporary files
12. Drag and drop 'ReDMCSB_Extract.dsk' on 'Mini vMac.exe' and let the system start
13. Drag and drop 'Temp.dsk' on the Mini vMac window and initialize the disk with name 'Temp'
14. Drag and drop 'stuffit_expander_5.5.img' on the Mini vMac window. Install StuffIt Expander
15. Shut down the system (menu Special / Shut Down)
16. Install CiderPress application to manage Apple IIgs and Macintosh disk images
17. Open 'Temp.dsk' with CiderPress. Add files 'MPW-GM.img.bin', 'OneClick_v1.4.sit' and 'THINK_C_4.0.5_Update.sea.bin' into the disk image. Also add file AUTOMATION.TXT that contains a OneClick script
18. Drag and drop 'ReDMCSB_Extract.dsk' on 'Mini vMac.exe' and let the system start
19. Drag and drop 'Temp.dsk' on the Mini vMac window
20. Open the 'Temp' disk. Drag and drop files 'MPW-GM.img.bin', 'OneClick_v1.4.sit' and 'THINK_C_4.0.5_Update.sea.bin' on the StuffIt Expander icon on the desktop to expand all three archives
21. Drag and drop file 'MPW-GM.img' on the StuffIt Expander icon on the desktop to mount the disk image
22. Open the 'MPW-GM' disk and copy the 'MPW-GM' folder to the 'Temp' disk
23. Open the 'THINK C 4.0.5 Update.sea' self-extracting archive file to extract its content on the 'Temp' disk
24. Create a 'TC5' folder on the 'Temp' disk. Drag and drop disk 2 of THINK C 5.0.2 on the Mini vMac window. Open 'THINK C 2' on the desktop, open 'Headers and Libs.sea' and extract its content on the 'Temp' disk in the 'TC5' folder
25. Shut down the system (menu Special / Shut Down)
26. Open disk ReDMCSB.dsk in CiderPress. Open another instance of CiderPress to open various disk images to copy content to ReDMCSB.dsk using CiderPress:
27. Create folders:
    - 'REDMCSB:MPW'
    - 'REDMCSB:MPW:Interfaces'
    - 'REDMCSB:MPW:Interfaces:CIIgsIncludes'
    - 'REDMCSB:MPW:Libraries'
    - 'REDMCSB:MPW:Libraries:CIIgsLibraries'
    - 'REDMCSB:MPW:Tools'
28. Copy files:
    - 'REDMCSB:MPW:MPW Shell' from MPW-GM folder on 'Temp' disk
    - 'REDMCSB:MPW:SysErrs.err' from MPW-GM folder on 'Temp' disk
    - 'REDMCSB:MPW:Tools:Asm' from MPW-GM folder on 'Temp' disk
    - 'REDMCSB:MPW:Tools:LinkIIgs' from MPW IIgs Tools disk image
    - 'REDMCSB:MPW:Tools:MakeBinIIgs' from MPW IIgs Tools disk image
    - 'REDMCSB:MPW:Tools:MakeLibIIgs' from MPW IIgs Tools disk image
    - 'REDMCSB:MPW:Tools:AsmIIgs' from MPW IIgs Assembler disk image
    - 'REDMCSB:MPW:Interfaces:CIIgsIncludes:String.h' from MPW IIgs C disk image
    - 'REDMCSB:MPW:Libraries:CIIgsLibraries:Stack1K.obj' from MPW IIgs C disk image
    - 'REDMCSB:MPW:Libraries:CIIgsLibraries:Stack8K.obj' from MPW IIgs C disk image
    - 'REDMCSB:MPW:Libraries:CIIgsLibraries:Start.obj' from MPW IIgs C disk image
    - 'REDMCSB:MPW:Tools:CIIgs' from MPW IIgs C disk image
    - 'REDMCSB:MPW:Libraries:CIIgsLibraries:CLib' from MPW IIgs Tools disk image
29. Create folders:
    - 'REDMCSB:Think C 3.0.2'
    - 'REDMCSB:Think C 3.0.2:Libraries'
30. Copy file:
    - 'REDMCSB:Think C 3.0.2:Libraries:setjmp.Lib' from Think C 3.0.2 Disk 2
31. Create folders
    - 'REDMCSB:Think C 4.0.5'
    - 'REDMCSB:Think C 4.0.5:C Libraries'
    - 'REDMCSB:Think C 4.0.5:C Libraries:headers'
    - 'REDMCSB:Think C 4.0.5:Utilities'
32. Copy files:
    - 'REDMCSB:Think C 4.0.5:THINK C' from Think C 4.0.5 disk 1
    - 'REDMCSB:Think C 4.0.5:C Libraries:ANSI' from Think C 4.0.5 disk 2
    - 'REDMCSB:Think C 4.0.5:C Libraries:headers:stdarg.h' from Think C 4.0.5 disk 2
    - 'REDMCSB:Think C 4.0.5:C Libraries:headers:stdio.h' from Think C 4.0.5 disk 2
    - 'REDMCSB:Think C 4.0.5:Utilities:oConv' from Think C 4.0.5 disk 4
33. Create folders:
    - 'REDMCSB:Think C 5.0.2'
    - 'REDMCSB:Think C 5.0.2:THINK C 5.0 Folder'
    - 'REDMCSB:Think C 5.0.2:THINK C 5.0 Folder:C Libraries'
    - 'REDMCSB:Think C 5.0.2:THINK C 5.0 Folder:C Libraries:headers'
34. Copy files:
    - 'REDMCSB:Think C 5.0.2:THINK C 5.0' from Think C 5.0.2 disk 1
    - 'REDMCSB:Think C 5.0.2:THINK C 5.0 Folder:C Libraries:headers:stdarg.h' from disk 'Temp' in 'TC5:THINK C 5.0 Folder:C Libraries:headers:stdarg.h'
35. Drag and drop 'ReDMCSB.dsk' on 'Mini vMac.exe' and let the system start
36. Drag and drop 'Temp.dsk' on the Mini vMac window
37. Install Think C 4.0.5 Update from the 'Temp' disk. Select the file to patch: 'REDMCSB:Think C 4.0.5:THINK C'
38. Install OneClick 1.4 from the 'Temp' disk
39. Shut down the system
40. Drag and drop 'ReDMCSB.dsk' on 'Mini vMac.exe' and let the system start
41. Click the 'Demo' button of OneClick
42. In Finder, select file 'REDMCSB:Think C 4.0.5:THINK C'. Open File menu, Get Info. Set memory to 2560 KB (required to avoid "out of memory" error when compiling large source code files). Repeat the same configuration on file 'REDMCSB:Think C 5.0.2:THINK C 5.0'
43. In Finder, select file 'REDMCSB:MPW:MPW Shell'. Open File menu, Get Info. Set memory to 3072 KB
44. Open File menu, Make alias. Move alias file into 'REDMCSB:System Folder:Startup Items' so that MPW Shell will automatically start when the system starts
45. Use OneClick to create a generic ReDMCSB palette with a single button:
    1. Drag and drop 'Temp.dsk' on the Mini vMac window
    2. Open 'MPW Shell', open the file AUTOMATION.TXT from the 'Temp' disk. Edit/Select all, then Edit/Copy
    3. Open OneClick Editor
    4. In 'Palette' tab, click 'New Palette' button and select 'New Application Palette'. Name: "ReDMCSB". Dimensions 60x15. Coordinates 579,20. Uncheck 'Title Bar'
    5. In 'Button' tab, click 'New Button' button. Name: 'Load and run automation script'. Style: None. Button Text: none. Dimensions 60x15. Coordinates 0,0
    6. Go back to 'Palette' tab, reset Dimensions to 60x15
    7. In 'Script' tab, paste the script with Command-v (Alt v in Mini vMac)
    8. Do not close the OneClick Editor, instead quit 'MPW Shell'. This causes OneClick to save the palette while preventing execution of the 'Startup' handler
    9. Close emulator and extract the Palette file from REDMCSB:System Folder:Preferences:OneClick Folder:Button Palettes:MPW Shell Palette
46. Duplicate palette file with the name of other applications to automate:
    - REDMCSB:System Folder:Preferences:OneClick Folder:Button Palettes:THINK C Palette
    - REDMCSB:System Folder:Preferences:OneClick Folder:Button Palettes:THINK C 5.0 Palette
    - REDMCSB:System Folder:Preferences:OneClick Folder:Button Palettes:oConv Palette
47. Delete 'ReDMCSB_Extract.dsk' and 'Temp.dsk'
48. Compress 'ReDMCSB.dsk' to 'ReDMCSB.zip'

## Atari ST

### Overview

- This toolchain builds executables for:
  - Atari ST: with the Megamax C compiler
- Automation: batch file using the PCOMMAND shell (similar to DOS)
- File transfer between Windows host and emulator: a folder on the host in mounted as a hard drive in the emulator using native Hatari feature.

### Preparation

1. Download the following files:
   - Atari ST emulator Hatari v2.2.1: hatari-2.2.1_windows64.zip
   - Megamax C compiler v1.1 (no known online source, use the files supplied with ReDMCSB)
   - Shell PCOMMAND.PRG: pcommand.arc
   - DC Xtract 2.1 (to expand ARC archives): dcx220c.lzh
   - SHUTDOWN.PRG: custom program (supplied source code to be compiled with Megamax C)
2. Expand these archives with 7-zip:
   - hatari-2.2.1_windows64.zip
   - dcx220c.lzh
3. Run DC Xtract 2.1 in the Hatari emulator to extract archive pcommand.arc
4. Run SHUTDOWN.BAT to build SHUTDOWN.PRG with Megamax C. This program causes the emulator to exit

## Commodore Amiga

### Overview

- This toolchain builds executables for:
  - Amiga: with the Aztec C compiler
- Automation: script file using the native Amiga shell
- File transfer between Windows host and emulator: a folder on the host in mounted as a hard drive in the emulator using native WinUAE feature.

### Preparation

1. Download the following files:
   - Amiga emulator WinUAE v3.5.0: WinUAE3500.zip
   - Kickstart v3.0 ROM: Kickstart v3.0 r39.106 (1992)(Commodore)(A1200)[!].zip
   - Workbench v3.0: Workbench v3.0 rev 39.29 (1992)(Commodore)(A1200-A4000)(M10)(Disk 2 of 6)(Workbench)[!].zip
   - Aztec C v3.6a: Aztec C v3.6a (1987-12)(Aztec)(Disk 1 of 4).zip, Aztec C v3.6a (1987-12)(Aztec)(Disk 2 of 4).zip, Aztec C v3.6a (1987-12)(Aztec)(Disk 3 of 4)[b corrupt files].zip and Aztec C v3.6a (1987-12)(Aztec)(Disk 4 of 4).zip
   - UAEUNP command line tool: uaeunp-0.8.zip
2. Expand all archives
3. Extract all files from ADF disk images using UAEUNP command lines: `uaeunp.exe -x <Filename.adf> **`

## Common

### Overview

- This toolchain contains ReDMCSB main source code and scripts as well as some tools used for analyzing executables.

### Preparation

1. Download the following files:
   - OMFUtils: omfutils source code and required libomf source code (click on the 'Code' button then 'Download ZIP'.
   - UNLZEXE: t.unlzexe_v.0.81_win_32-bit.gerstrong.2010-07-04.zip
   - WinMerge: winmerge-2.16.8-x64-exe.zip
   - Java SE Development Kit is required to compile OMFUtils. JRE is enough to run OMFUtils: Java SE Downloads
2. Extract both omfutils and libomf in the same folder
3. Install the JDK
4. Open cmd.exe and run these command lines to compile the programs (you may need to adjust paths):
   `cd <path to the omfutils folder>
   javac.exe ByteReader.java dumpobj.java GetOpt.java lseg.java makedirect.java makeobj.java omf\OMF.java omf\OMF_Align.java omf\OMF_CInterseg.java omf\OMF_Const.java omf\OMF_CReloc.java omf\OMF_DS.java omf\OMF_Entry.java omf\OMF_Eof.java omf\OMF_Equ.java omf\OMF_Expr.java omf\OMF_Expression.java omf\OMF_Interseg.java omf\OMF_Label.java omf\OMF_LConst.java omf\OMF_Local.java omf\OMF_Mem.java omf\OMF_Number.java omf\OMF_Opcode.java omf\OMF_Org.java omf\OMF_RelExpr.java omf\OMF_Reloc.java omf\OMF_Relocation.java omf\OMF_Segment.java omf\OMF_Strong.java omf\OMF_Super.java omf\OMF_Using.java omf\io\OMF_DataInput.java omf\io\OMF_DataOutput.java omf\io\OMF_InputStream.java omf\io\OMF_NullOutputStream.java omf\io\OMF_OutputStream.java omf\io\OMF_OutputStream2.java omf\io\__OMF_Reader.java omf\io\__OMF_Writer.java`

## Fujitsu FM-Towns

### Overview

- This toolchain builds executables for:
  - FM-Towns: these executables are built using High C
- Automation: batch file using the native DOS shell
- File transfer between Windows host and emulator: a hard disk image is required to work with the emulator. MTOOLS commands are used to import the necessary files in the disk image before starting emulation, and to export files from the disk image after the build process is complete.
  DiskExplorer allows easy manipulation of the hard disk images. Although not required to run the ReDMCSB build process, it is used to prepare the hard disk image.

### Preparation

1. Download the following files:
   - FM-Towns emulator UNZ v0.5 L30: unz0530.zip
   - FM-Towns ROM files FMT_DIC.ROM, FMT_DOS.ROM, FMT_F20.ROM, FMT_FNT.ROM and FMT_SYS.ROM: townsbios.zip
   - MS-DOS v3.1 L36: ms-dos31l36.zip
   - High C Compiler Multimedia Development Kit v1.7 L13: High C Compiler Multimedia Development Kit v1.7 L13 [CD].7z
   - MTOOLS: mtools-4.0.18-win32.7z
   - DiskExplorer v1.69 English: editd169e.zip
2. Expand all archives with 7-zip.
3. Place ROM files in the same folder as UNZ.
4. Create hard disk image
5. Format hard disk image
6. Copy files

## IBM PC

### Overview

- This toolchain builds executables for:
  - PC: with Turbo C++ and Turbo Assembler
  - PC-9801: with Turbo C, Turbo C++ and Turbo Assembler
  - FM-Towns: with Turbo Assembler. Only a few assembly source code files are assembled to object files and libraries (no full executables). This is a workaround because no assembler is present in the FM-Towns toolchain.
- Automation: batch file using the emulated DOS shell
- File transfer between Windows host and emulator: a folder on the host in mounted as a hard drive in the emulator using native DOSBox feature.

### Preparation

1. Download the following files:
   - IBM PC emulator DOSBox: dosbox-0.74-3.tar.gz
   - Turbo C 2.01: Borland Turbo C 2.01 (3.5)
   - Turbo C 2.0c for PC-9801: TURBO C 2.0C.zip
   - Turbo C++ 1.01: Borland Turbo C++ 1.01 (3.5)
   - Turbo Assembler 1.01: Borland Turbo Assembler 1.01 (5.25-360k)
   - Turbo Assembler 2.01: Borland Turbo Assembler 2.01 (5.25)
   - Turbo Assembler 4.0: Borland Turbo Assembler 4.0 (3.5-1.44mb)
   - LZEXE91: lzexe91.zip
   - Virtual Floppy Image Converter 0.73: vf011010.zip
2. Expand all archives with 7-zip.
3. Use 7-zip to extract files from .IMG disk images.
4. Use Virtual Floppy Image Converter to extract files from the .D88 disk images of Turbo C for PC-9801: Select the export folder and choose the format 'File Extract' then drag and drop each disk image.
5. Perform installation of Turbo Assembler 4.0 inside DOSBox.

## Sharp X68000

### Overview

- This toolchain builds executables for:
  - X68000: with the XC C Compiler 1.01
- Automation: batch file using the native Human68k shell (similar to DOS)
- File transfer between Windows host and emulator: a folder on the host in mounted as a hard drive in the emulator using the WindrvXM device driver.

### Preparation

1. Download the following files:
   - X68000 emulator X68k_TypeG: xm6_typeg_331L15_20190720.zip
   - IPL ROM: Sharp X68000 Boot ROM (1987)(Sharp).zip
   - CG ROM: Sharp X68000 CG ROM (1987)(Sharp).zip
   - Human68k 3.02 System Disk: Human 68k v3.02 (1993)(Sharp - Hudson).zip
   - WindrvXM 0.27: WindrvXM027.zip
   - XC C compiler v1.01: ZZZ-UNK-C Compiler Pro 68k v2.0 (1990)(Sharp)(Disk 5 of 5).zip
   - Virtual Floppy Image Converter 0.73: vf011010.zip
   - DiskExplorer v1.69 English: editd169e.zip
2. Expand all archives with 7-zip.
3. Use Virtual Floppy Image Converter to extract files from 'ZZZ-UNK-C Compiler Pro 68k v2.0 (1990)(Sharp)(Disk 5 of 5).dim': Select the export folder and choose the format 'File Extract' then drag and drop the disk image.
4. Extract the x64 version of the emulator
5. Rename 'Sharp X68000 CG ROM (1987)(Sharp).bin' to 'cgrom.dat' and place it in the same folder as the emulator
6. Rename 'Sharp X68000 Boot ROM (1987)(Sharp).bin' to 'iplrom.dat' and place it in the same folder as the emulator
7. Build custom boot disk:
   1. Start the emulator. Click on menu Tools / Image / Make a new floppy disk. Enter file name REDMCSB.XDF and select Save as type '1.25 MB Disk Image Files (XDF;HDM;2HD;DUP;IMG)'. Click OK in the next dialog box.
   2. In the Media menu, Insert 'Human68k 3.02 System Disk' in Floppy Drive #0. The computer will start booting from that floppy disk.
   3. In the Media menu, Insert REDMCSB.XDF in Floppy Drive #1
   4. Format the floppy disk in drive B: and make it bootable with this command: `format b: /s` (note that you may need to customize keyboard input options to type ':' in Tools / Options / Keyboard tab)
   5. Format displays a first message, press 'Return'. Wait while the disk is formatted, then a second message is displayed, press 'N'.
   6. Copy required files with these commands:
      `copy a:command.x b:
      cd a:sys
      copy a:float2.x b:`
   7. Exit the emulator
   8. Create a text file named CONFIG.SYS with this content:
      `DEVICE=FLOAT2.X
      DEVICE=WINDRVXM.SYS`
   9. Create a text file named AUTOEXEC.BAT with this content:
      `ECHO OFF
      PATH A:\;
      C:
      \SOURCE\REDMCSB.BAT`
   10. Open REDMCSB.XDF with Disk Explorer ('plain disk' format).
   11. Add these files into the disk image: WindrvXM.SYS (from the downloaded archive), AUTOEXEC.BAT and CONFIG.SYS.
8. Use the emulator configuration file 'XM6g.ini' supplied with ReDMCSB.