June 19, 2018

The MAGIC-1 homebrew computer


http://www.homebrewcpu.com/overview.htm is a website about an amateur CPU project, called MAGIC-1. It is not the first attempt to build a computer from scratch, but it is one of the most interesting. Not because of the hardware part (it is made by TTL chips and some RAM) but because of the software stack.
The inventor describes this as very demanding:
“Although the hardware design and construction of Magic-1 usually gets the most attention, the largest part of the project (by far) has been developing/porting the software.“
That means, developing the CPU itself, wiring the cables and make the current flow was easy going. Only the part of programming an operating system is really difficult. And the inventor is right. The main problem with homebrew computers is not the electronics part of the project. The most man hours gets usually invested in the software stack.
The MAGIC-1 project is interesting, because it is not using CP/M but a Forth system, better known as MINIX. Minix is a stackbased operating system which can be reprogrammed and has a built-in TCP/IP stack.
But why is developing the hardware for a computer an easy task and programming the software a hard one? Let us reduce the situation to a synthetic game. At first we are building the computer itself. We are not taking real transistors but programming a Brainfuck interpreter. Such an interpreter can be realized in under 100 lines of code, and it can be done without any problems. https://github.com/kgabis/brainfuck-c/blob/master/brainfuck.c If we are starting the interpreter we get a fully functional computer. It has a memory and can execute commands. This is equal to build a computer in hardware. That means, after switching the device on, it is ready and can execute any program.
Now comes the difficult part. We want to program our Brainfuck interpreter. The surprise is, that even if we had invented the brainfuck interpreter ourself and know every detail of it, we are not able to program on the machine. For example, if the task is to program a simple operating system, or a string search algorithm, we need many weeks until the software will be ready. And this situation is not only true for the Brainfuck soft-emulator but is the normal case for any homebrew CPU project. The computer itself (no matter if is an emulator or real hardware) can be realized in a short amount of time and is described in the literature in detail. But programming a game on the computer, an operating system or something else is very hard.