# Applicability

This document applies to the tip-of-trunk version of the PiDP-8/I software. If you are still running the last stable release, v2017.12.22, you'll need to either [upgrade](/#updating) or switch to the [last version of this document as of the time of that stable


# The Situation

In February 2016, Norman Davie released a program he called [Deeper after an earlier program by Steve Gibson called [Deep The most important difference between these two programs for our purposes here is that instead of running as PDP-8 code within the simulator, as Gibson's program does, Davie's Deeper Thought runs as a native program on the Raspberry Pi, using a version of Oscar Vermeulen's original `gpio.c` module to manipulate the LEDs on the PiDP-8/I's front panel and read its switches.

Davie's program has been [forked several but this mode of operation remains in all of the versions I've tried.

When Ian Schofield created the [incandescent lamp simulator](/wiki?name=Incandescent+Lamp+Simulator) (ILS) for the PiDP-8/I, he changed the external interface in a couple of ways which prevented it from being used with any of these versions of Deeper Thought.

When I rewrote the ILS, one of the things I did was add a compatibility interface for programs like Deeper Thought which remain dependent on the old `gpio.c` module interface. This article describes the steps you must take to build a version of Deeper Thought against our new ILS.

If you are running a single-core Pi (e.g. Zero, original A+, original B+...) there is little point to following this guide. Just stop the PiDP-8/I simulator and run your chosen version of Deeper Thought directly, as its GPIO method will work the same as our single-core GPIO method, which we call NLS to distinguish it from ILS mode.


# Modifying `deeper.c`

The first thing you have to do to build any version of Deeper Thought against the current version of the PiDP-8/I software is copy its `deeper.c` file into the PiDP-8/I software's `src/misc` subdirectory:

    $ cd ~/pidp8i                  ⇠ or wherever the PiDP-8/I source code is
    $ cp src/misc

Use your favorite Linux text editor to make a few adjustments to to get it to build:

1. Add the following lines between the big block comment at the top of the file and the `#include` lines following it, at line 156 or so:

        #define _XOPEN_SOURCE 500
        #include "gpio-common.h"

2. Remove these lines, found up among the `#include` lines:

        extern void *blink(void *ptr); the real-time multiplexing process to start up
        extern uint32 ledstatus[8];     bitfields: 8 ledrows of up to 12 LEDs
        extern uint32 switchstatus[3];  bitfields: 3 rows of up to 12 switches

3. Replace the block of code beginning with the `pthread_create()` call and ending with `sleep( 2 )` — inclusive — with the following:

        pidp8i_simple_gpio_mode = 1;
        if (start_pidp8i_gpio_thread ("Deeper Thought 2") != 0) {
          fprintf( stderr, "Failed to start GPIO thread.  PiDP-8/I panel attached?\n" );
          exit (EXIT_FAILURE);
        }

With that done, you must reconfigure the software to get it to recognize that `deeper.c` has been added to the `src` subdirectory. If you're happy with your current PiDP-8/I software configuration, this will do the trick:

    $ make reconfig

Otherwise, re-read `README.md` and run `configure` manually:

    $ ./configure --with-your-new-option-set

Either way, among the lines in the `configure` script output should be this one:

    Found Deeper Thought; building it against ILS GPIO module

If you reconfigure it on a multi-core Pi such as the Pi 2 or Pi 3, it will build against the ILS; otherwise, it will build against the NLS, which may look slightly different from the appearance you get from the old `gpio.c` module, but it probably isn't worth continuing unless you're simply curious.

Now you can try saying `make`. If the software builds, you can now run it as `sudo bin/deeper`.

If you want to install it, I recommend that you build and install Deeper Thought in the normal way, then copy the `bin/deeper` executable you built above over the top of the normal one. This lets you leverage the rest of the installation process shipped with Deeper Thought, such as installing the `deeper` system service.


# Disabling the PiDP-8/I Simulator

If you want Deeper Thought to run by default instead of the PiDP-8/I simulator, say:

    $ sudo systemctl stop pidp8i
    $ sudo systemctl disable pidp8i

The Deeper Thought installer script will mark its service to start by default. If you don't give those two commands, Deeper Thought will crash on boot because it can't grab control over the GPIO lines going to the PiDP-8/I front panel while the PiDP-8/I simulator is running.


# Reverting to Boot with the PiDP-8/I Simulator

To revert the changes made in the previous section and mark Deeper Thought to not start on boot, say:

    $ sudo systemctl stop deeper
    $ sudo systemctl disable deeper
    $ sudo systemctl enable pidp8i
    $ sudo systemctl start pidp8i


# Why Not Make This Easy?

You might be wondering why I describe how to modify `deeper.c` to build against the PiDP-8/I software instead of just integrating it and shipping it along with it. It's because this software is not licensed under any open source license, and attempts to get the authors to so license it have been ignored. Therefore, I cannot re-distribute this software, even though it is freely-available on the Internet.


## License

Copyright © 2017-2019 by Warren Young. This document is licensed under the terms of [the SIMH license][sl].

[sl]: