Breakout, the game the course builds in HiSoft C, running on the Tatung Einstein: coloured brick rows, the bat and the ball on a black court
← Back to Courses
module
1

What You're Going To Make

Introduction

Every program in the other courses on this site was either read out a line at a time by an interpreter, or written in the Z80's own instructions, or typed into a compiler that lived in the same program as its editor. This course is none of those. You write C in an editor, hand the file to a compiler, and run what comes out - and each of those is a command at the disc operating system's prompt, and the compiler takes most of a minute.

That is how software was written on small computers in 1985, and this course does not hide it. It teaches C on the Einstein the way it was done, and it builds towards one thing: Breakout, a real-time game in which you keep a ball in play with a bat and knock out a wall of bricks.

What C Actually Is

C was designed in the early 1970s at Bell Laboratories by Dennis Ritchie, to write an operating system in - Unix - and it shows. It is a small language that stays close to the machine: it has the numbers the processor has, it lets you hold the address of anything and do arithmetic on it, and it does very little for you that you did not ask for. Where Pascal was designed to teach programming properly, C was designed to get systems programming done, and it went on to be the language most other languages are written in.

HiSoft C was a British C compiler for Z80 computers, sold from 1985 by HiSoft of Dunstable - the same firm whose Pascal and assembler are on this site - and it was sold for the Einstein: its manual lists the machine on the title page and came with a library of Einstein functions for the screen, the keyboard and the graphics. It is a compiler and an editor, run one at a time from the prompt, like this:

0:HC HELLO.C
HiSoft-C Compiler V1.35 Copyright (C) 1985
Line File
MEMORY MAP    Start  End
Runtimes      0100  11FF
Code          1200  1320
Initialisers  1321  1324
Fixed Data    EBE3  EC00
Smallest #data 0x134B
0:HELLO
Hello, Einstein
0:

Two commands. HC turns your program into a program the Einstein can run, and prints a map of where in memory it will live; the second is the program itself. HC takes about half a minute, because it is read from the disc before it starts and reads its library from the disc as it goes. You will get used to it. People did.

The Version This Course Covers

When the compiler starts it says what it is:

HiSoft-C Compiler V1.35 Copyright (C) 1985

This course covers HiSoft C version 1.35, and only that - the one on the course disc. HiSoft sold other versions, for the Spectrum and the Amstrad and for CP/M machines in general, and there were other C compilers for CP/M, and a great deal is written about C in general. Almost all of it is about some other compiler, and in C that matters more than it sounds: C was not standardised until 1989, and a compiler from 1985 is one company's reading of a 1978 book. This course tells you what this compiler does, having tried it.

If you already know C, be careful in a different way. Most of what you know will work - HiSoft's manual says the compiler was "designed to be very close" to the book, and it is. The places where it differs are exactly the places you will not think to check - a char that is never negative, a cast spelt with a word, a call with the wrong number of arguments that stops the machine - and this course points them out as it goes.

HiSoft's own manual, if you can find a copy, is a good one: a tutorial, a language reference that follows the book's chapter numbers and says where it departs, the whole library, and every error message. This course does not replace it. It walks the same ground on the Einstein, with every step tried.

The Machine

The Tatung Einstein is a British computer, built around the Zilog Z80 processor and sold from 1984. It came with a disc drive built in at a time when most home computers loaded from cassette, and it runs a disc operating system that can run CP/M programs - which is what HiSoft C is.

Its screen is 40 characters wide and 24 lines deep, and it draws a few characters its own way. The curly brackets that C uses everywhere come out as ¼ and ¾, and the backslash as ½. You will see main() ¼ on the screen where you typed main() {, and the compiler will be perfectly happy, because what it reads is the code for {; only the picture is different. S3 says which keys make them.

You do not need to own an Einstein. The course runs on an emulator.

Where This Is Going

This course builds one program. Not from the first page - the first part is the workshop, and the second the language, in short programs you type and throw away - but from later on each section adds a piece to the game, and what you run at the end of a section is the game so far.

The game is Breakout. A court drawn on the screen with rows of bricks across the top; a ball that moves one square every tick whether you like it or not, bouncing off the walls; and you, sliding a bat along the bottom with the keys to keep it in play. Every brick the ball hits disappears and scores. Let the ball past the bat and you lose one of three lives; clear the bricks and you have won. That is the whole of the rules, and it suits C almost exactly: the bricks are a two-dimensional array, the ball and the bat are structures handed to functions by address, the keyboard has to be read without waiting, and the whole thing has to move every tick - which is where a compiled language earns its keep. A C program on this machine gets round an empty loop about ten thousand times a second, and the game will spend most of that waiting for you.

The pieces come in the order you need them. Part one is the workshop: the disc, the editor, the compiler, what each one leaves behind, and what the compiler says when something is wrong - including the trick it has of putting you back in the editor on the faulty line. Part two is the language: printing, numbers, names, choices, loops, functions, arrays, pointers, strings, structures, the preprocessor, files and memory. Part three is the machine: keys without waiting, the Einstein library that came with the compiler, the screen, reaching the hardware from C, and how fast and how big things are. Part four is the game, one piece a section. Then you read a real program that HiSoft wrote in 1985 - the CP/M library on the disc - and find you can follow it.

Who This Is For

  • Anyone who wants to see what programming a small computer in C was actually like, tools and all.
  • Retro computing hobbyists and collectors, and anyone with an Einstein in the loft.
  • Anyone who knows C from a modern machine and would like to meet its 1985 self, on a machine with 64K.
  • Anyone who has done the Turbo Pascal course and wondered what the same machine does when the compiler and the editor are separate programs.
  • Anyone who means to go on to the Z80 assembly course. HiSoft C lets you put machine code inside a C function, and a section of this course does.

What You Need To Know Already

Nothing.

You do not need to have programmed before. Everything is explained as it comes up, in the order you need it, and nothing is used before it has been explained.

If you have programmed before, the first sections will go quickly. Read them anyway: the Einstein's keyboard, the editor and the compiler's messages have their surprises, and they are all in the first seven sections.

What You Need

Three things, all free: the MAME emulator, the Einstein's ROM image, and the HiSoft C course disc from the Downloads page. S3 installs them, on macOS, Windows or Linux, and finishes with the compiler signing on in front of you.

The course disc carries the compiler, its four library files and their help, the editor, the finished game, and 72K of room for your own work.

If you have a real Einstein, you are very welcome to follow along. The course is written and checked against the emulator, so where the two differ you will be ahead of us, and we would like to hear about it. S3 begins with what is different for you.

How Each Section Is Laid Out

Every section has the same shape.

  • What it teaches, in one line at the top.
  • The explanation, one idea at a time.
  • The code - runnable as it stands. In the early parts, short programs to type in full; in the last, the new pieces of the game and exactly where each one goes.
  • What you should see, so you know whether it worked.
  • Change one thing - two or three small edits with a question attached. These are the part that does the teaching. Reading code that works produces a feeling of understanding that is hard to tell from the real thing until something breaks; changing one thing and guessing what will happen finds out cheaply. In C there are two ways to be wrong: the compiler refuses it, or it runs and does something you did not intend - and the second is the one to watch for.
  • Exercises, with worked solutions in Appendix II.
  • When it goes wrong - the failures we actually hit, and what they looked like on screen.

Found A Mistake? Stuck? Want To Help?

All three are worth a message, and the last one most of all. Nothing in this course has yet been tried on a real Einstein.

Next

S2, C On The Einstein, Honestly - where this compiler came from, how it reached the Einstein, what Einstein owners had to write C with, and what nobody knows.

Get the Newsletter

New guides, disk images and community finds, roughly once a quarter. No spam, we promise, this isn't Tatung's marketing department.
Your subscription could not be saved. Please try again.
Your subscription has been successful.

Newsletter

Subscribe to our newsletter and stay updated.