
That is the course. You have a finished game, written by you, running on an Einstein without Turbo Pascal behind it. This last section looks back at what that took, points at what was left out, lifts the lid one final time - and says where to go next.
You can write a program, keep it, and change it - in Turbo's own editor, saved to the disc, compiled to memory or to a .COM that stands on its own.
You can make the machine decide and repeat - if and case, for, while and repeat, and a loop that waits for a key.
You can give your data a shape - types of your own, sets, arrays, records, and pointers that build a list as the program runs.
You can keep things on the disc - files of records, read and written in any order, and text files.
You can build a program bigger than one idea - Warehouse is over 500 lines, in procedures and functions that each do one job, one of them calling itself.
You can read somebody else's program - 1,261 lines of Borland's - and change it to suit your machine.
Warehouse has six levels, undo, a best score for each level, a map of where you can reach, and an editor. It is also plainly a first game, and the exercises are a list of what it could have next: redo, a count of pushes, crates that know they are stuck, a title screen with the scores on it.
Take them or leave them. The more useful move is to start something of your own, because the second program is where you find out which parts you understood and which you copied. A board as an array of an enumerated type, a key loop, a list for undo, a file of records - they are the same in anything you write next. A minesweeper, a game of Battleships against the computer, a maze: each is a weekend's work now.
Deliberately, and worth knowing so you can go and find it. The Turbo Pascal manual has a section on each - and the manual is a guide, not the last word, so try each one on the machine.
BlockRead and BlockWrite, for moving whole blocks of a file at a time.New takes.Sin, Cos, ArcTan, Exp, Ln and the rest. MicroCalc uses them; this course never needed them.S26 reached into the machine's memory and its chips with Mem and Port. One step further, and you are writing the machine's own language inside a Pascal program. inline puts bytes straight into the compiled code, and the Z80 runs them as instructions:
program Lid;
var
X: Integer;
begin
X := 5;
inline($21/X/$34);
Writeln('X is ', X);
end.
X is 6
Two instructions' worth of bytes, and no Pascal in between:
| Bytes | Meaning |
|---|---|
$21, then X | Point at the variable X. Where a variable's name appears in inline, Turbo puts its address. |
$34 | Add one to the byte pointed at. |
Nothing printed the 6 but Pascal's Writeln; nothing changed X but the Z80 following those bytes. Change the $34 to $35 and it takes one away instead.
That is machine code, and it is how programs of the time did what a compiler could not do fast enough, or at all. The Z80 assembly course on this site writes those same bytes as LD HL,X and INC (HL), which is easier to read than numbers, and builds a complete game out of them from the beginning. You already know most of its ideas from the comfortable side: a loop that runs once a pass, a character of your own, a list in memory. Compiled Pascal is already fast - about 39,000 turns of an empty loop a second, where the Xtal BASIC course measured about 850 - but machine code is the fastest the Einstein can go.
$34 to $35. What is X now?inline line inline($21/X/$34/$34);. What does the second $34 do?39.1 Put the inline line inside a for loop that runs five times. What is printed?
39.2 Pick one item from "What This Course Left Alone", read its section in the manual, and find out by experiment whether the manual is right.
39.3 Write a second game - a small one - of your own.
Worked solutions are in Appendix II.
The sections are a path, and you walk them once. The appendices are for coming back to:
Three things, please - they matter more now, at the end, than they would have at the start.
If something here is wrong, say so - a wrong sentence nobody reports stays wrong for everyone who reads it next. If something was unclear, that is a fault in the writing; the person who already knows the answer is the worst judge of whether an explanation works. And if you think you could improve it - a clearer explanation, a missing section, a note on what the real machine does differently - please do.
The contact form is at tatungbytes.co.uk/contact.
Every listing in this course was compiled and run on the machine before it was printed, and every result you were told to expect was read off a screen rather than off a manual. That mattered more than it should have. Borland's manual is the best guide there is to this Turbo Pascal, and it is still wrong in places: it lists IOresult as a Boolean, which on the machine is an Integer, and its table of editor commands is not quite the table the editor follows.
That is not a complaint about the book. It is the reason the course is shaped the way it is, and it is worth carrying with you: the machine is the authority. When something you read disagrees with what the Einstein does in front of you, the Einstein is right.
Go and find out what it does.