User Tools

Site Tools


sd-8516_user_s_guide

This is an old revision of the document!


SD-8516 User's Guide

CHAPTER 3: BEGINNING STELLAR BASIC PROGRAMMING

CHAPTER 3: BEGINNING STELLAR BASIC PROGRAMMING

Welcome to Stellar BASIC on your SD-8516! This is where the real fun begins. Stellar BASIC lets you talk directly to your machine and make it do exactly what you want. The thrill of typing in your first program and hitting RUN – the magic of watching the the screen come alive – using PETSCII graphics to play golf – the mystery of YOHO – and so much more – it's all right here, for you to discover!

Stellar BASIC is a lean, fast descendant of the famous Tiny BASIC from 1975 (the one that fit in under 4K and inspired so many early microcomputers). It's designed as a powerful yet easy to learn programming language for the everyman. There are no fancy tricks, just a straightforward list of commands. It is perfect for games, math, and little adventures, yet powerful enough to help you do taxes!

PRINT

Getting Started – The PRINT Command

The easiest way to make your SD-8516 say hello is with PRINT. You can also use the ? key as shorthand.

Type this right now (press ENTER after the line):

  ? "HELLO WORLD"

The computer should immediately display:

  HELLO WORLD

Now try:

  ? 42 + 8

It prints 50. You can do math right away, no program needed. This is called direct mode, directly entering commands on the terminal.

GOTO

Your First Program – The Never-Ending Message

Let's write a real program. Type NEW and press ENTER to clear any old stuff.

Now carefully type these lines (press ENTER after each one):

  10 ? "HELLO WORLD"
  20 GOTO 10

Type RUN and press ENTER.

Watch the screen fill up with “HELLO WORLD” scrolling forever! To stop the program, press the BREAK or STOP key (ESC on modern keyboards).

PROGRAMS

Line Numbers and How Programs Work

Every line in a program starts with a line number (any whole number from 1 to around 65000). The computer runs lines in order of those numbers, smallest to largest.

You don't have to type lines in order, the computer will sort them for you automatically. Try this:

  20 ? "LINE 20 COMES FIRST ANYWAY!"
  10 ? "BUT LINE 10 RUNS FIRST"

RUN

LIST

To see your program again, type LIST.

To erase just one line, type its number and press ENTER (e.g., 20 [ENTER] deletes line 20).

If you type NEW it will delete the current program. Make sure you SAVE “NAME” your program first.

LET (VARIABLES)

Variables – Remembering Things

Variables are like little memory boxes. In Stellar BASIC we use single letters only: A, B, Z, etc. (Version 1 does not support strings or floating point numbers).

Try this in direct mode:

  LET A = 25
  
  ? A

It prints 25.

Now a tiny counting program:

  10 LET A = 1
  20 ? A
  30 LET A = A + 1
  40 IF A <= 10 THEN GOTO 20
  50 ? "BLAST OFF!"

RUN

This program counts from 1 to 10. Can you make it count

INPUT

The INPUT Command – Asking Questions

Now let's make the computer ask questions.

Type NEW, then:

10 PRINT "WHAT IS YOUR GUESS (1-100)";
20 INPUT E
30 PRINT "YOU ENTERED: "; E

RUN

Type a number and press ENTER. Notice the semicolon (;) keeps things on the same line—no extra ? prompt needed.

IF-THEN

Making Decisions with IF…THEN

The real power comes from decisions.

Add these lines to make a simple checker:

  40 IF E = 42 THEN GOTO 70
  50 IF E <> 42 THEN ? "TRY AGAIN!"
  60 GOTO 10
  70 PRINT "YOU FOUND THE ANSWER!"

RUN and try a guess until you hit 42. (42 is a reference to the Hitchhiker's Guide – a great book).

Your First Game

A Classic: Number Guessing Game

Here's a complete small game you can type in; it's the first program ever written in Stellar BASIC.

It uses everything we've covered: PRINT/?, variables, INPUT, IF-THEN, GOTO, and introducing a new function: RAND() for random numbers.

After typingNEW, then enter this program:

10 ? ""
20 ? "NUMBER GUESSING GAME"
30 ? "GUESS MY NUMBER 1-100!"
40 LET A = 1 
50 LET B = 100

FIXME
UNDER CONSTRUCTION

60 D = RAND( B - A + 1 ) + A - 1   : REM SECRET NUMBER!
70 F=0
80 F=F+1
90 ? ""
100 ? "ROUND";F
110 ? "LOW:";A;" HIGH:";B
120 INPUT "YOUR GUESS:"; E
130 IF E>B THEN ? "TOO LARGE!":GOTO 90
140 IF E<A THEN ? "TOO SMALL!":GOTO 90
150 IF E<D THEN ? "HIGHER!":A=E:GOTO 80
160 IF E>D THEN ? "LOWER!":B=E:GOTO 80
170 ? "YOU GOT IT!"
180 ? "SCORE:";101-F
190 ? "PLAY AGAIN? (Y/N)"
200 INPUT G$
210 IF G$="Y" THEN GOTO 50
220 ? "BYE FOR NOW!"

RUN and play! (Note: RAND(N) gives 0 to N-1, so we adjust +A-1 to get the range.)

This is the spirit of 8-bit BASIC—type it in, play it, tweak it, make it yours. Just like the old days when you'd stay up late copying listings from magazines.

What's Next?

You've got the basics: PRINT/?, variables, math (+ - * /), GOTO, IF-THEN, INPUT, and RAND(). For more power, check the SD-8516 Programmer's Reference Guide—it covers GOSUB/RETURN (coming soon), FOR-NEXT loops, PEEK/POKE for memory fun, and future plans like strings (A$), sound, and even graphics commands.

Experiment! Change the messages, make the range bigger, add more hints. That's how so many great games started back in the day.

Happy programming, space cadet—your SD-8516 is ready for adventure!

GOSUB

Welcome back to Stellar BASIC on your SD-8516! We're building on the classic Tiny BASIC spirit from 1975; small, fast, and full of that pure home-computer magic. Type in a few lines, hit RUN, and watch your creation come to life!

Stellar BASIC keeps things simple: integer math only, single-letter variables (A–Z), line-numbered programs, PRINT, INPUT, and IF.

Here are some BASIC commands you can try right when you turn on your computer:

PRINT “HELLO WORLD!”

  LET A = -5            ( This sets A to 5 )
  PRINT A               ( This will print 5 )
  PRINT A*2             ( Prints 10 )

Here is an example program:

  10 LET A = 5  
  20 PRINT A  
  30 LET A = A - 1  
  40 IF A > 0 THEN GOTO 20  
  50 PRINT "GOAL!"

Next, type RUN. You will see a countdowns to 1, then “GOAL!”

GOSUB and RETURN

A useful feature of BASIC is GOSUB and RETURN. Think of a subroutine as a little helper routine you can call from anywhere. GOSUB jumps to it (and remembers where you came from), and RETURN sends you right back to the next line.

This saves tons of typing—perfect when you want the same message or calculation in multiple spots.

Here is an example of a GOSUB helper function:

  10 REM GOSUB SQUARE DEMO
  20 LET A = 2
  30 GOSUB 1000
  40 LET A = 3
  50 GOSUB 1000
  60 LET A = 4
  70 GOSUB 1000
  80 LET A = 5
  90 GOSUB 1000
  100 GOTO 9000
  9000 REM END
  1000 REM THIS HELPER FUNCTION WILL PRINT THE SQUARE OF A
  1010 PRINT A * A
  1020 RETURN

After you enter this program and type RUN, you will see the result 4, 9, 16, 25. As you can see, every time the program calls GOSUB 1000,* it runs the code at LINE NO 1000 and then RETURNs to continue in the main program.

You can nest up to 8 GOSUB calls in one program.

Improved Number Guessing Game with GOSUB

Let's level up the guessing game. Now we use GOSUB for separate “display instructions” and “show result” routines—cleaner code, easier to tweak.

NEW then type:

10 ? “” 20 GOSUB 900 : REM SHOW INSTRUCTIONS 30 A=1 : B=100 40 D=RAND(B-A+1)+A : REM SECRET NUMBER (1-100) 50 F=0

60 F=F+1 70 ? “” 80 ? “ROUND”;F 90 ? “LOW:”;A;“ HIGH:”;B 100 INPUT “YOUR GUESS:”; E 110 IF E>B THEN GOSUB 800:GOTO 70 120 IF E<A THEN GOSUB 700:GOTO 70 130 IF E<D THEN GOSUB 600:A=E:GOTO 60 140 IF E>D THEN GOSUB 500:B=E:GOTO 60

150 GOSUB 400 160 ? “SCORE:”;101-F 170 ? “PLAY AGAIN? (Y/N)” 180 INPUT G$ 190 IF G$=“Y” OR G$=“y” THEN GOTO 30 200 ? “THANKS FOR PLAYING!” 210 END

400 ? “YOU GOT IT IN”;F;“ GUESSES!” 410 RETURN

500 ? “LOWER!” 510 RETURN

600 ? “HIGHER!” 610 RETURN

700 ? “TOO SMALL!” 710 RETURN

800 ? “TOO LARGE!” 810 RETURN

900 ? “NUMBER GUESSING GAME V1.1” 910 ? “BY APPLEDOG (C) 2026” 920 ? “GUESS THE NUMBER BETWEEN 1 AND 100.” 930 ? “I'LL TELL YOU HIGHER OR LOWER.” 940 RETURN

RUN — Play a few rounds! The subroutines make it modular—if you want fancier win/lose messages later, just edit those GOSUB lines.

Negative Numbers in Action

Since negatives are fully supported, try tweaking the game or make a countdown timer:

10 ? “COUNTDOWN FROM ZERO…” 20 A=0 30 ? A 40 A=A-1 50 IF A>=-10 THEN GOTO 30 60 ? “BLAST OFF INTO NEGATIVE SPACE!”

What's Next?

You've now got the core toolkit: PRINT, LET variables, INPUT, IF-THEN, GOTO, RAND(), and GOSUB/RETURN for structured programs. Experiment wildly, change freely– add more subroutines, make the range -50 to 50 for negative guesses, introduce more features!

Check the SD-8516 Programmer's Reference Guide for deeper details: upcoming FOR-NEXT loops, PEEK/POKE for peeking at memory (classic retro fun), string variables (A$), sound commands, and more. The roadmap is alive—your ideas help shape it.

You are in the cockpit now, space cadet! Make the SD-8516 shine!

sd-8516_user_s_guide.1771620666.txt.gz · Last modified: by appledog

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki