# TurboPascal on Mac
**Note: probably 99% of this tutorial (excluding installation and folder structure) is DOSBox- and not Mac-specific.
As long as your computer can run DOSBox you should be able to convert the steps to work on Windows.**

## 1. Downloading & Installing DOSBox
DOS apps don't run natively on OS X, so we use DOSBox to emulate
DOS for us.

### 1a. Downloading DOSBox
Navigate to [the official DOSBox download page](http://www.dosbox.com/download.php?main=1)
and select the latest Mac OS X version (at the time of writing this is for DOSBox 0.74).
It will kick you over to SourceForge where your download will
start after a couple of seconds.

### 1b. Installing DOSBox
Go to where you saved the DOSBox disk image to (for me it's the
Downloads directory) and double click it to mount it.

![I didn't think people would look at alt text :P](http://i.imgur.com/7wtkYUM.png)

Finder should automatically reveal the contained filesystem, however
if it doesn't just double click the appropriate icon in the Finder
sidebar.

![Contents of DOSBox disk image](http://i.imgur.com/WJXNA52.png)

If you want more details on how DOSBox works,
feel free to open the ReadMe.txt file, but for now just drag the
DOSBox.app into your `/Applications` directory. If you are having trouble
finding this, just click the Finder icon in your Dock, hit ⌘⇧G,
enter `/Applications` in the modal that appears and then press ⏎ (Return).

## 2. Downloading & Installing TurboPascal
Without TurboPascal we'd just have a DOS terminal. Such fun.

### 2a. Downloading TurboPascal
Because TurboPascal is so old, it was actually quite difficult finding the
binaries for it. [These](http://borlandc.org/wp-content/uploads/2013/04/pascal.zip) from borlandc.org
work for me but if you have different binaries that you'd prefer using then go right ahead.

### 2b. Installing TurboPascal
To use TurboPascal we need to "install" it. You could use any location on your filesystem
for TurboPascal but I tend to place these things in my home directory so I can find them easily.

But first, extract the pascal.zip that you downloaded from borlandc.org.
The resulting directory should be called `TP`.
I renamed it to `TurboPascal` because that way it's easier to know what it is.
On UNIX-like systems the home directory is where everything specific
to you goes. The path varies from Mac to Mac, depending on your setup
(my home directory is on a separate hard drive), so if you don't know
where your home directory is: move the focus to Finder (by selecting
Finder in the Dock) and press ⌘⇧G. In the resulting modal, just
enter `~` and press ⏎ (Return).

Copy or cut your `TurboPascal` over to your home directory, such that
the resulting path is `~/TurboPascal`. This'll be important later.

## 3. Setting up DOSBox with TurboPascal
### 3a. Mounting and setting up a filesystem
Now that TurboPascal is installed, it's time to fire up DOSBox.
![DOSBox startup](http://imgur.com/b1SxCYj.png)

You'll have to "mount" your current Mac filesystem by assigning it
to a drive letter.

First we'll mount TurboPascal. I chose A as the drive letter, but you could choose anything.
*for any of the following, type only what is after the `>` sign*
```shell
Z:\>mount A ~/TurboPascal/BIN
```

Next we'll mount the rest of our home directory so that we can open and save a
file within TurboPascal. You can also mount a specific directory if
you'd prefer not navigating a large file tree.

```shell
Z:\>mount C ~
Z:\>C:
```
The first of these commands mounts your home directory (`~`) as the C drive. The second changes the
current drive to your home directory. We'll change the working directory
of TurboPascal so that navigating the file structure isn't such a pain
and so that all files TurboPascal generates for your project stay in
one location.
Alternatively you could also `mount C /`, but this is not recommended (you don't want to give
an ancient operating system permission to potentially overwrite OS X).

![What it looks like now](http://imgur.com/pN0Vosk.png)

Where you place your projects is up to you. I ran these commands to
create a directory within my home directory dedicated to Pascal projects:

```shell
C:\>mkdir PASPRO
C:\>cd PASPRO
```

### 3b. Running TurboPascal
**This tutorial assumes your current directory is `C:\PASPRO`.**

You have several choices now. You can either use the "blue window" TurboPascal that we use at
College or you can use an external editor. I'll cover both.

#### 3b-i. Using "blue window" TurboPascal

To start "blue window" TurboPascal, run the following:
```shell
C:\PASPRO>A:\TPX.EXE
```

Ta da!

![Ta da](http://imgur.com/9jxfDGZ.png)

Actually we're not *quite* done yet: you may notice that you can't move your mouse cursor. I've found that
double clicking the blue area of the window makes DOSBox capture your mouse cursor, but if it does not you
may need to press CTRL+F10 (CTRL+Fn+F10 if F10 mutes your Mac). Performing this shortcut again
releases the mouse as well.

Now you can write code :D

![Now you can write code](http://imgur.com/k858wcW.png)

You'll also find all your code and .exe files in `~/PASPRO`. Neat.

#### 3b-ii. Using an external editor
If you'd prefer using an external editor such as [GitHub Atom](https://atom.io/) or
[Sublime Text (use 3, it supports Pascal highlighting)](http://www.sublimetext.com/) then… follow along.

Make changes to your `.PAS` files with your editor of choice. When it comes to running, you will have to
invoke the compiler manually.

```shell
C:\PASPRO>A:\TPC.EXE HIWORLD
```
In this case HIWORLD refers to your code file, `HIWORLD.PAS` (or whatever it may be). The compiler is smart
enough to know that they end in `.PAS` and will compile it to a `.EXE` file called `HIWORLD.EXE`.

If it compiles successfully you'll see something like this:

![Success](http://imgur.com/ViavUFU.png)

If it doesn't, the output will usually tell you the error and the line it ocurred on.

Assuming you have compiled your program in a similar matter, you can run your application without adding
.EXE to the end.
```shell
C:\PASPRO>HIWORLD
```

##### Extra bits and bobs
I actually tend to create small batch files that compile the program and then run it. One of these may be
called CR.BAT (CR = Compile Run) and look like this.

```shell
A:\TPC.EXE HIWORLD
HIWORLD
```

If you have this kind of setup you can edit your code and compile+run it by just running `CR`.

## 4. Automating your setup
Of course you don't want to type all these things every time you start DOSBox. If you want your DOSBox to
launch just like it does at College you'll have to add the commands you wish to run to the DOSBox
configuration file.

The file we'll be editing is `~/Library/Preferences/DOSBox 0.74 Preferences` you can either directly edit
it by opening a terminal and typing
```shell
open -e ~/Library/Preferences/DOSBox\ 0.74\ Preferences
```

or you can click Finder in the dock, press ⌘⇧G, enter `~/Library/Preferences`, press ⏎ (Return), and double click the file
entitled `DOSBox 0.74 Preferences`.

---
Once you've opened the DOSBox configuration file, scroll to the bottom to find `[autoexec]` and add your startup
lines below this.

If you've followed the tutorial fully, something like this will make DOSBox mount the correct directories,
change directory to our project directory (`PASPRO`), and finally execute `TPX`, the TurboPascal Integrated
Development Environment (IDE).

```
mount A ~/TurboPascal/BIN
mount C ~
C:
cd PASPRO
A:\TPX.EXE
```

## 5. That's it. Write some programs.
Thanks for reading. Hopefully it helped those who couldn't get TurboPascal running on their Mac
(or on Windows).

© 2014 Niklas Vangerow