BASIC on the Altair

A ticket desk of your own

Bring the ideas from this BASIC path together in a small program. Plan a ticket desk, check it against a set of examples, and change its price without changing how it asks questions or keeps a total.

View lesson source ↗

Continue your session, or load BASIC

If the terminal below already shows your earlier BASIC session, press the browser's RUN button to continue it. You do not need to load the tape again. This tab keeps the machine, program, terminal, and pending input as you move between BASIC lessons, visit All lessons, or refresh. Returning always pauses execution first. Other tabs work independently; a newly opened or duplicated tab may begin with a copy of this tab's saved session.

Begin a lesson's commands at OK. If your previous program is still asking a question at ?, finish that conversation first; the ticket loop finishes when you answer 0. The lesson's setup explains which stored lines to keep or replace. Typing NEW at OK clears the stored program and variables without reloading BASIC.

If this is a fresh machine, follow the loading steps below.

This is the original 4K BASIC 3.2 interpreter running on our Altair. An interpreter is a program that reads your commands and carries them out. Before it can understand PRINT, the Altair must load that interpreter into memory.

  1. Get the selected paper-tape file from the machine guide (opens in a new tab). Return here and choose it in Paper tape below. The file stays on your computer.
  2. Raise only switches A11 and A10. Leave PC at 0000: do not press EXAMINE. You may then close the front panel to bring the terminal closer.
  3. Press the browser's RUN button. Click Terminal keyboard and answer each question when it appears:
When you see Enter
MEMORY SIZE? Just Enter, to let BASIC find the available memory.
TERMINAL WIDTH? Just Enter, to keep the default.
WANT SIN? Y then Enter. We will not need this math function today.

When 727 BYTES FREE and OK appear, BASIC is ready. Leave the processor running for the lesson. Switching tabs pauses it; press the browser's RUN button when you return.

If you need to start loading again, use Start fresh, raise A11 and A10 again, then RUN. This discards the current BASIC program and uses the tape you already selected. Reset CPU + serial does not reload BASIC.

The saved session stays in this browser tab's temporary storage. It is not sent to the site. Copy your numbered lines somewhere to keep them beyond the browser session. If the browser cannot save or restore a session, a message beside the machine explains that; you can still use the current page.

A computer waiting for your instructions

From paper tape to BASIC.

Resume a saved session with RUN. To load BASIC for the first time, choose the 4K BASIC 3.2 tape (guide opens in a new tab), raise the loading switches, then RUN. Loading instructions

This tab can keep your BASIC session between lessons. Checking for a saved session…

The file stays on your computer. Selecting a verified tape prepares a fresh, stopped machine.

No tape selected.

Front panel · address, data, and sense switches

To load BASIC, raise only A11 and A10 and leave PC at 0000. Do not press EXAMINE after raising the loading switches. You can then close this panel to bring the terminal closer.

Operate the front panel

ALTAIR 8800

Memory and sense switches

Address lights PC · next instruction

0 decimal · 0000 hex

Data lights The byte at that location

0 decimal · 00 hex

A lit lamp is 1; a dark lamp is 0. The digits help you read the lights.

Data / address switches Up = 1 · Down = 0

15–8 · Address + sense

7–0 · Address or data

All switches as an address
0 decimal · 0000 hex
Lower eight as a byte
0 decimal · 00 hex

Setting the switches prepares a number. It does not read or write memory. The CPU can read the upper eight switches at port FF, even while running.

Select the address in the switches and read its byte.

Move to the next address and read its byte.

Write the lower eight switches to the selected address.

Move to the next address, then write the lower eight switches.

EXAMINE would select address 0. DEPOSIT would write 0 to the selected address, 0.

Last memory operation

Enable JavaScript to operate the panel.

EXAMINE and NEXT change PC. Only 0000–0FFF contain RAM; other addresses read FF and discard deposits. Lights show instruction boundaries, not individual bus cycles.

Stopped · 0 instructions

RUN lets the processor execute; STOP pauses it. At BASIC’s prompt, type RUN to run your BASIC program. Break sends Control-C to BASIC.


  
  

0 keyboard bytes queued

Use uppercase commands. Enter sends a line; Backspace sends BASIC’s erase character (_). Paste one line at a time. Only the machine’s echoes appear above.

Inspect the running machine

    

Latest twelve instructions on this page · PC before → after (hexadecimal)


  

Reset keeps RAM and the switches but resets the CPU and serial device. Start fresh discards the program, restores the bootstrap, rewinds the selected tape, and clears the terminal; raise the switches again before RUN.

Start with what the program should do

Load or resume BASIC using the instructions above, and begin at OK. This is the final project in our introductory BASIC path. It uses commands we have already met; the task is to decide how they fit together.

We want a ticket desk with these rules:

  1. Each ticket costs 2 pounds.
  2. Ask how many tickets someone wants, print that purchase's cost, and ask again for the next purchase.
  3. For a negative answer, explain the problem and ask again without changing the total.
  4. An answer of zero finishes the run and prints the total cost of all its purchases. Finishing before any purchase should give a total of zero.
  5. Another RUN starts a fresh total.

As in the earlier ticket programs, enter small whole numbers. Our negative check does not reject positive fractions; we are keeping the same limited input rules for this project.

Try making a plan before reading the solution. Which instructions run once at the start? Which ones repeat? Where does each of the three kinds of answer go? You can sketch those paths on paper before choosing line numbers.

The repeating question and running total lessons can help. We need an input loop here: we do not know how many purchases someone will make, so a FOR loop with a fixed number of trips would not fit these rules.

Give each value a job

Here is one plan. Choose separate names for the values we need:

Name Job When it changes
P Price of one ticket, in pounds. Set once at the start.
N Number of tickets in this purchase. Replaced by each INPUT.
C Cost of this purchase, in pounds. Calculated for each positive answer.
T Total cost of accepted purchases, in pounds. Starts at zero; add each new C.

Using P for the price means we can change it in one place. Calculating C=N*P once lets us both print C and add it to T. These are ordinary variables, just like N and T in the earlier lessons.

The plan is: set P and T, ask for N, then choose a path. A negative N gets an explanation and another question. Zero goes to the final total. A positive N gets a calculation, a printed cost, and an addition to T before the next question.

Build a reference version

You can try your own version first. The conversations below check this reference version; your wording and line numbers may differ, but the rules and calculated answers should agree.

At OK, type NEW to remove the previous lesson's program or your trial version. Then enter these lines one at a time, pressing Enter and waiting for each complete echo before the next:

Type, then Enter

NEW

BASIC replies

OK

Type one line at a time, then Enter

5 LET P=2
10 LET T=0
20 PRINT "HOW MANY TICKETS (0 TO FINISH)"
30 INPUT N
40 IF N<0 THEN 120
50 IF N=0 THEN 100
60 LET C=N*P
70 PRINT "COST POUNDS"
75 PRINT C
80 LET T=T+C
90 GOTO 20
100 PRINT "TOTAL POUNDS"
110 PRINT T
115 END
120 PRINT "PLEASE USE ZERO OR MORE"
130 GOTO 20

Check the stored program with LIST:

Type, then Enter

LIST

BASIC replies

5 LET P=2
10 LET T=0
20 PRINT "HOW MANY TICKETS (0 TO FINISH)"
30 INPUT N
40 IF N<0 THEN 120
50 IF N=0 THEN 100
60 LET C=N*P
70 PRINT "COST POUNDS"
75 PRINT C
80 LET T=T+C
90 GOTO 20
100 PRINT "TOTAL POUNDS"
110 PRINT T
115 END
120 PRINT "PLEASE USE ZERO OR MORE"
130 GOTO 20
OK

Follow the paths before RUN. Both GOTOs return to line 20, passing over the starting assignments. The negative and zero checks come before the calculation and addition. END on line 115 keeps the finished run from continuing into the negative-answer message.

Build the ticket desk ↑

Check the requirements

Work out the results independently before asking BASIC. At 2 pounds per ticket, these four runs should behave as follows:

Answers, in order Purchase costs Final total What this checks
3, 1, 0 6, then 2 8 Several purchases add together.
2, -1, 1, 0 4, then 2 6 Rejection preserves an earlier purchase.
0 None 0 Finishing immediately works.
2, 0 4 4 A later RUN has its own total.

Start with the first row. Type each answer only when ? appears:

Type, then Enter

RUN

BASIC replies

HOW MANY TICKETS (0 TO FINISH)
?

Type, then Enter

3

BASIC replies

COST POUNDS
 6
HOW MANY TICKETS (0 TO FINISH)
?

Type, then Enter

1

BASIC replies

COST POUNDS
 2
HOW MANY TICKETS (0 TO FINISH)
?

Type, then Enter

0

BASIC replies

TOTAL POUNDS
 8

OK

Now try a negative answer between two purchases. There should be no cost printed for -1, and it must not subtract from the total:

Type, then Enter

RUN

BASIC replies

HOW MANY TICKETS (0 TO FINISH)
?

Type, then Enter

2

BASIC replies

COST POUNDS
 4
HOW MANY TICKETS (0 TO FINISH)
?

Type, then Enter

-1

BASIC replies

PLEASE USE ZERO OR MORE
HOW MANY TICKETS (0 TO FINISH)
?

Type, then Enter

1

BASIC replies

COST POUNDS
 2
HOW MANY TICKETS (0 TO FINISH)
?

Type, then Enter

0

BASIC replies

TOTAL POUNDS
 6

OK

The first run ended with 8 pounds; this one ends with its own 6 pounds. Only its accepted purchases contributed to that total.

Check the last two rows as well:

Type, then Enter

RUN

BASIC replies

HOW MANY TICKETS (0 TO FINISH)
?

Type, then Enter

0

BASIC replies

TOTAL POUNDS
 0

OK

Type, then Enter

RUN

BASIC replies

HOW MANY TICKETS (0 TO FINISH)
?

Type, then Enter

2

BASIC replies

COST POUNDS
 4
HOW MANY TICKETS (0 TO FINISH)
?

Type, then Enter

0

BASIC replies

TOTAL POUNDS
 4

OK

Each zero answer reaches the total and END without another question. At OK, the stored program is still available for another RUN.

Check all four runs ↑

Change the price in one place

Suppose each ticket should now cost 3 pounds. Which stored line needs to change? Replace line 5:

Type, then Enter

5 LET P=3

The line number matters: this changes the assignment that RUN will execute. An immediate LET P=3 would not change the stored line, and the next RUN would still execute its old assignment of 2.

Repeat the first set of answers. Three tickets should now cost 9 pounds, one should cost 3 pounds, and the total should be 12 pounds:

Type, then Enter

RUN

BASIC replies

HOW MANY TICKETS (0 TO FINISH)
?

Type, then Enter

3

BASIC replies

COST POUNDS
 9
HOW MANY TICKETS (0 TO FINISH)
?

Type, then Enter

1

BASIC replies

COST POUNDS
 3
HOW MANY TICKETS (0 TO FINISH)
?

Type, then Enter

0

BASIC replies

TOTAL POUNDS
 12

OK

The calculation still reads C=N*P. It uses the new value of P, and both the printed cost and the total use the resulting C. There was no second copy of the ticket price to find and change.

Changing the price should not change the other rules. Check rejection and an empty total together:

Type, then Enter

RUN

BASIC replies

HOW MANY TICKETS (0 TO FINISH)
?

Type, then Enter

-1

BASIC replies

PLEASE USE ZERO OR MORE
HOW MANY TICKETS (0 TO FINISH)
?

Type, then Enter

0

BASIC replies

TOTAL POUNDS
 0

OK

Try the new price ↑

If your results differ

Use the method from the debugging lesson: pick one short failing conversation, predict the intermediate values, and use LIST and temporary PRINT lines to follow what happens.

For example, line 85 is a place to put a temporary PRINT T after each addition. Remove any diagnostic lines when you finish, then repeat the checks. Their extra output will not appear in the reference conversations.

Finish the introductory path

You can now turn a small set of rules into a stored program, predict its answers, change it, and investigate a mistake. Before moving on, explain:

Use the earlier lessons whenever one of those steps is unclear. You do not need to memorize the line numbers or every command to reason about a program.

This completes our first BASIC learning path. Your instructions ran inside the original interpreter, which itself ran as 8080 instructions on the emulated Altair.

You can keep experimenting in the terminal. This tab carries the BASIC machine and program between these lessons, including a visit to All lessons, and restores them paused after a refresh. Press the browser's RUN button to continue. Start fresh discards the program and reloads the retained tape. Copy your numbered lines somewhere for a lasting copy; browser session storage is temporary.

The machine guide (opens in a new tab) explains the hardware, loading process, and recovery controls. These lessons use that same machine and original interpreter.