Program listings on the T/S computer are available on command. With either LIST or LLIST, the program in the machine is displayed for you, to study or change. But not everything in the machine’s program file is displayed!
There are three elements of the file that are censored from the LISTings you see; I’ll get to them in a moment. But ignorance is bliss, you say. To an extent, you’re right. For most programming chores, understanding the structure of the T/S’s program file is unnecessary. There are times, however, when you may want to work with the program file itself – line renumbering, or when trying to save space for example – and these times, knowledge of the structure is important.
Computer Structure
This paper is a tool for holding information. The shapes written on it (letters) mean different things as they are combined (words, and sentences). The computer is also a tool for holding information; but it is built in a different way. There are two main differences: 1. it holds binary numbers only, and 2. it is linear, like a string of beads, rather than two dimensional, as this paper is. For the convenience of the human users, both of these attributes have been “covered up.” You can communicate with the machine using letters and decimal numbers, and recieve its replies in the same way, but the machine is doing a lot of extra work to accomodate you. When we look at the structure of the computer, though, we must keep those differences in mind.
Mechanics
The computer stores numbers in a long string. Each number, in reality, is a collection of 32 transistors, formed into eight switches, or bits. These eight bits together are called a byte. As it happens, eight switches can be arranged in 256 different ways, from 00000000, 00000001, 00000010,… to 11111111. We can think of each arrangement as a number, between 0 and 255. Each of these eight bit numbers has a fixed position in the string of numbers; these positions are called addresses. Not all addresses have switches presently attached – it’s a little like a new Levittown, with empty streets stretching off into the distance. In the basic T/S 1000, only the addresses from 0 to 8192, and from 16384 to 18432 are used, while the machine could work with addresses up to 65536! The sample program we will look at today will be stored between 16509 and 16607.
Here’s the program:
10 REM SAMPLE PROGRAM, NO. 1
20 FOR N=16509 TO 16608
30 SCROLL
40 LPRINT N;" ";PEEK N;TAB 10;CHR$ PEEK N
50 NEXT N
You may want to change LPRINT to PRINT after you have RUN it once. Otherwise type it in exactly as written – the success of your future pokes depends on it. This program uses two features of BASIC to help us examine the machine’s memory: PEEK and CHR$. PEEK, followed by an address, will give us the decimal value of the number at that address. There is a companion command to PEEK, that lets us change the value stored in RAM; that is POKE. We’ll use it in this tutorial as well. The machine can interperet that number in several ways (as text, as a binary number, or as machine code) and we can use CHR$ to command the machine to translate the number into text. &
Tokens
Run the program. “Wait!” you say, “each address is supposed to hold one number, and some seem to hold whole words.” What you’re seeing are tokens. When the machine translates it’s memory into text, some numbers are assigned whole words, rather than individual characters. You can see a list of all the tokens in the character list in the back of your User’s Manual.
The Powerful 118
The next thing you notice is that the nice, neat program lines are gone; the numbers run along without an apparent break. There are two kinds of breaks there though, one of which you haven’t even known about. 118 is the end of line marker; note how each line of the program has a 118 to conclude it (each line of the screen display has one also, but that’s a subject for another month). When the LIST routine is drawing the program to the screen, it uses the 118 markers to signal the end of a line. We can have some fun with that – enter POKE 16520,118 and ENTER. The LIST routine now thinks that the REM is in two parts! The program will still run; the machine uses a different method of keeping things straight as it RUNs. Now try POKE 16521,118 and ENTER. List the program – where did it go? It’s still there; try RUN to prove it. The LIST routine interperets two 118’s together as the end of the program file. If you want to see the rest of the program again, POKE 16520,0 and 16521,0.
The Silent 126
The machine has another flag hidden in the listing. RUN the program again, and watch the LISTing of line 20 (addresses 16536 to 16566). The number 16509 appears, starting at 16543. There are the character codes for 1, 6, 5, 0, and 9 – but then there are six bytes of garbage before you get to the “to”. The 126 tells the computer that a five byte binary number follows. This number is inserted after each decimal number you include in your program line, as the line is copied from the bottom of the screen into the program area. When you press EDIT, these numbers are stripped out. Try POKE 16520,126. LIST now thinks that the letters “PROGR” are a binary number, and hides them from you. They’re still there – RUN the program again to prove it. Now LIST it again, and pull line 10 down with EDIT. It looks the same as in the listing, but “PROGR” has been deleted now. Press ENTER to replace it, and RUN to prove it. This will happen to machine code, if it happens to contain a 126 (which, unfortunately, is a very important command) and is pulled down with EDIT.
Try POKE 16548,0 and LIST. This will remove the 126 from behind the decimal number 16509, and LIST will provide the CHR$ for the five following bytes, rather than skipping them as it normally does. Sometimes, a bad load will change a 126 to something else, and the program will not operate correctly. The symptom, of course, is six characters of garbage following a good number in the LISTing. If you like, you can then add a program such as the one given here, and identify the address of the missing 126, then replace it with a POKE.

More Anatomy
Line numbers…
There are two more “structures” that help the machine navigate through the program file. The first is the Line number. This is stored in an almost logical way. Remember that the largest number that an address can hold is 255. How would it hold a line number larger than that? Let’s see. EDIT line 50, and change its line number to 300, and RUN. The line number for that line is held at addresses 16601 and 16602. The computer has taken the line number(300), and seen how many 256’s would go in (one), then put the remainder in the next address. Try POKEing 16601,10, and LIST. The first number now represents 2560, and the remainder from before is added in, making 2604.
And Line length.
There are two more bytes to account for. These are extremely important for the machine, as they tell the computer how long the present line is, and thus, how many addresses to move to get to the next line. RUN, and look at line 10. Address 16511 holds 23. Now start at the first byte of the text of the line (16513), and count down 23 – there’s the 118 at the end! Many computers only allow lines of less than 256 characters (can you guess why?), but the T/S machines support lines of essentially any length. If the length is greater than 255, the same operation as the line number is performed, with one byte getting the number of 256’s in th length, and the other getting the remainder. One catch – the two bytes are in reverse order, to speed the Z80’s handling of the numbers.
Now you have seen part of the machine’s structure that was hidden before. Like a sleek car, it sometimes pays to lift the hood, and appreciate the effort that went into the works under there, as well.
Good Luck !
Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.