Files
akbasic/docs/02-getting-started.md
Andrew Kesterson cdaefcc941
Some checks failed
akbasic CI Build / cmake_build (push) Successful in 3m0s
akbasic CI Build / sanitizers (push) Successful in 3m45s
akbasic CI Build / coverage (push) Failing after 3m22s
akbasic CI Build / akgl_build (push) Failing after 21s
akbasic CI Build / mutation_test (push) Successful in 11m26s
Write the usage guide as thirteen chapters in docs/
Organised the way the C128 Programmer's Reference Guide is: the language
first, then each hardware area, then the reference sections. One markdown
file per chapter.

The verb and function references are generated from the interpreter's own
dispatch table, with an assertion that every row is described, so they cannot
drift out of step with what the program accepts. 98 verbs and 30 functions.

Every example was run before it was written down, which caught three claims
that were wrong: a whole FOR loop on one line prints nothing rather than
looping once, MID and INSTR count from zero where a C128 counts from one, and
a multi-line DEF returns a value the caller has to assign away.

Chapter 13 is the list a BASIC 7.0 programmer needs -- roughly sixty
documented differences, including the two known FOR defects and the fact that
drawing does not survive a frame.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-07-31 21:50:50 -04:00

2.4 KiB

2. Getting started

The prompt

Run basic with no arguments and you get a prompt:

$ ./build/basic
READY

READY is printed whenever the interpreter is waiting for you, which is at startup and after a program stops.

Anything you type with a line number is stored as part of a program. Anything you type without one runs immediately:

PRINT 2 + 2
 4
READY

Your first program

10 PRINT "WHAT IS YOUR NAME"
20 INPUT "> " N$
30 PRINT "HELLO, " + N$
RUN

Type LIST to see it back, RUN to run it again, and NEW to throw it away.

Line numbers

Lines are stored under their numbers and run in numeric order, so the gaps are what let you insert later:

10 PRINT "FIRST"
30 PRINT "THIRD"
20 PRINT "SECOND"
LIST
10 PRINT "FIRST"
20 PRINT "SECOND"
30 PRINT "THIRD"

Typing a line number with nothing after it deletes that line. DELETE 20-40 removes a range, and RENUMBER tidies the whole program up — it rewrites every GOTO and GOSUB to match, so it will not break your branches.

AUTO 10 turns on automatic numbering so you do not have to type them; AUTO 0 turns it off again.

Several statements on one line

Statements are separated by colons:

10 A# = 1 : B# = 2 : PRINT A# + B#

There is one important limit: block structures do not work inside a single line.

10 FOR I# = 1 TO 3 : PRINT I# : NEXT I#

prints nothing at all. The loop body is skipped entirely, because the interpreter skips forward a line at a time looking for the NEXT and never finds one on the line it is already past. Write loops across several lines:

10 FOR I# = 1 TO 3
20 PRINT I#
30 NEXT I#

The same applies to DO/LOOP.

Running a file

$ ./build/basic program.bas

The file is read, stored, and run. It is exactly the same as typing the program in and saving yourself the trouble.

You can also pipe a program in:

$ echo '10 PRINT "HI"
RUN' | ./build/basic

Saving and loading

DSAVE "myprogram.bas"
DLOAD "myprogram.bas"

SAVE and LOAD are the same verbs under their other names. VERIFY "myprogram.bas" compares what is in memory against the file and prints OK if they match.

Stopping

QUIT ends the interpreter. STOP stops a program and returns you to the prompt, where CONT resumes it from where it stopped. END also stops the program, but does not arm CONT.

In the SDL build, closing the window stops the program too.