sd-8516_user_s_guide
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| sd-8516_user_s_guide [2026/02/20 21:00] – appledog | sd-8516_user_s_guide [2026/02/21 10:20] (current) – appledog | ||
|---|---|---|---|
| Line 15: | Line 15: | ||
| Type this right now (press ENTER after the line): | Type this right now (press ENTER after the line): | ||
| - | | + | <codify BASIC> |
| + | ? "HELLO WORLD" | ||
| + | </ | ||
| The computer should immediately display: | The computer should immediately display: | ||
| Line 23: | Line 25: | ||
| Now try: | Now try: | ||
| - | | + | <codify BASIC> |
| + | ? 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. | It prints 50. You can do math right away, no program needed. This is called **direct mode,** directly entering commands on the terminal. | ||
| Line 34: | Line 38: | ||
| Now carefully type these lines (press ENTER after each one): | Now carefully type these lines (press ENTER after each one): | ||
| - | | + | <codify BASIC> |
| - | 20 GOTO 10 | + | 10 PRINT "HELLO WORLD" |
| + | 20 GOTO 10 | ||
| + | </ | ||
| Type **RUN** and press ENTER. | Type **RUN** and press ENTER. | ||
| Line 48: | Line 54: | ||
| You don't have to type lines in order, the computer will sort them for you automatically. Try this: | You don't have to type lines in order, the computer will sort them for you automatically. Try this: | ||
| - | | + | <codify BASIC> |
| - | 10 ? "BUT LINE 10 RUNS FIRST" | + | 20 ? "LINE 20 COMES FIRST ANYWAY!" |
| + | 10 ? "BUT LINE 10 RUNS FIRST" | ||
| + | </ | ||
| **RUN** | **RUN** | ||
| Line 67: | Line 75: | ||
| Try this in direct mode: | Try this in direct mode: | ||
| - | | + | <codify BASIC> |
| - | + | LET A = 25 | |
| - | ? A | + | |
| + | ? A | ||
| + | </ | ||
| It prints 25. | It prints 25. | ||
| Line 75: | Line 85: | ||
| Now a tiny counting program: | Now a tiny counting program: | ||
| - | | + | <codify BASIC> |
| - | 20 ? A | + | 10 LET A = 1 |
| - | 30 LET A = A + 1 | + | 20 ? A |
| - | 40 IF A <= 10 THEN GOTO 20 | + | 30 LET A = A + 1 |
| - | 50 ? "BLAST OFF!" | + | 40 IF A <= 10 THEN GOTO 20 |
| + | 50 ? "BLAST OFF!" | ||
| + | </ | ||
| **RUN** | **RUN** | ||
| Line 110: | Line 122: | ||
| Add these lines to make a simple checker: | Add these lines to make a simple checker: | ||
| - | | + | <codify BASIC> |
| - | 50 IF E <> 42 THEN ? "TRY AGAIN!" | + | 40 IF E = 42 THEN GOTO 70 |
| - | 60 GOTO 10 | + | 50 IF E <> 42 THEN ? "TRY AGAIN!" |
| - | 70 PRINT "YOU FOUND THE ANSWER!" | + | 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' | **RUN** and try a guess until you hit 42. (42 is a reference to the Hitchhiker' | ||
| Line 158: | Line 172: | ||
| Here is an example program: | Here is an example program: | ||
| - | | + | <codify BASIC> |
| - | 20 PRINT A | + | 10 LET A = 5 |
| - | 30 LET A = A - 1 | + | 20 PRINT A |
| - | 40 IF A > 0 THEN GOTO 20 | + | 30 LET A = A - 1 |
| - | 50 PRINT " | + | 40 IF A > 0 THEN GOTO 20 |
| + | 50 PRINT " | ||
| + | </ | ||
| Next, type **RUN.** You will see a countdowns to 1, then " | Next, type **RUN.** You will see a countdowns to 1, then " | ||
| Line 173: | Line 189: | ||
| Here is an example of a GOSUB helper function: | Here is an example of a GOSUB helper function: | ||
| - | | + | <codify BASIC> |
| - | 20 LET A = 2 | + | 10 REM GOSUB SQUARE DEMO |
| - | 30 GOSUB 1000 | + | 20 LET A = 2 |
| - | 40 LET A = 3 | + | 30 GOSUB 1000 |
| - | 50 GOSUB 1000 | + | 40 LET A = 3 |
| - | 60 LET A = 4 | + | 50 GOSUB 1000 |
| - | 70 GOSUB 1000 | + | 60 LET A = 4 |
| - | 80 LET A = 5 | + | 70 GOSUB 1000 |
| - | 90 GOSUB 1000 | + | 80 LET A = 5 |
| - | 100 GOTO 9000 | + | 90 GOSUB 1000 |
| - | 9000 REM END | + | 100 GOTO 9000 |
| + | 9000 REM END | ||
| - | | + | 1000 REM THIS HELPER FUNCTION WILL PRINT THE SQUARE OF A |
| - | 1010 PRINT A * A | + | 1010 PRINT A * A |
| - | 1020 RETURN | + | 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 **RETURN**s to continue in the main program. | 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 **RETURN**s to continue in the main program. | ||
| Line 199: | Line 217: | ||
| **NEW** then type: | **NEW** then type: | ||
| - | 10 ? "" | + | <codify BASIC> |
| + | 10 PRINT "" | ||
| 20 GOSUB 900 : REM SHOW INSTRUCTIONS | 20 GOSUB 900 : REM SHOW INSTRUCTIONS | ||
| 30 A=1 : B=100 | 30 A=1 : B=100 | ||
| Line 244: | Line 263: | ||
| 940 RETURN | 940 RETURN | ||
| 5000 REM END | 5000 REM END | ||
| + | </ | ||
| - | Ty to **RUN** this program and play a few rounds! The subroutines make it modular. If you want fancier win/lose messages later, just edit those GOSUB lines. | + | Try to **RUN** this program and 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** | **Negative Numbers in Action** | ||
| Line 251: | Line 271: | ||
| Since negatives are fully supported, try tweaking the game or make a countdown timer: | Since negatives are fully supported, try tweaking the game or make a countdown timer: | ||
| + | <codify BASIC> | ||
| 10 PRINT " | 10 PRINT " | ||
| 20 LET A = 0 | 20 LET A = 0 | ||
| Line 257: | Line 278: | ||
| 50 IF A >= - 10 THEN GOTO 30 | 50 IF A >= - 10 THEN GOTO 30 | ||
| 60 PRINT "BLAST OFF INTO NEGATIVE SPACE!" | 60 PRINT "BLAST OFF INTO NEGATIVE SPACE!" | ||
| + | </ | ||
| + | |||
| + | === WHILE, DO-WHILE, and FOR-NEXT Part I | ||
| + | Stellar BASIC V1 keeps things simple and fast; no built-in FOR-NEXT or WHILE (yet! --they' | ||
| + | |||
| + | The key tricks: | ||
| + | |||
| + | * WHILE -- A while loop checks the condition first, so place the IF check before the loop body. | ||
| + | * DO-WHILE -- A do loop runs at least once, so place the IF check at the end of the loop body. | ||
| + | * FOR-NEXT -- A for-next is essentially a WHILE loop (see below). | ||
| + | |||
| + | Let's see these in action with short examples you can type in right now. | ||
| + | |||
| + | ==== WHILE | ||
| + | WHILE is short for WHILE-DO. The loop check is at the front of the do-loop (so it may skip the loop entirely). This is like "while something is true, keep doing the body." | ||
| + | |||
| + | Example: Print numbers from 1 to 5, checking first. | ||
| + | |||
| + | <codify BASIC> | ||
| + | 10 LET I = 1 | ||
| + | 20 IF I > 5 THEN GOTO 60 | ||
| + | 30 ? I | ||
| + | 40 LET I = I + 1 | ||
| + | 50 GOTO 20 | ||
| + | 60 ? " | ||
| + | </ | ||
| + | |||
| + | This prints 1 through 5. If you change line 10 to LET I=10, it skips the printing entirely, since the condition was false when we checked the loop condition (at the front of the loop body). | ||
| + | |||
| + | ==== DO-WHILE | ||
| + | In this style the do-loop is executed and then if the condition (the while) passes, it executes the loop again. This style of loop always runs at least once. | ||
| + | |||
| + | Example: Keep asking for a positive number until you get one. | ||
| + | |||
| + | <codify BASIC> | ||
| + | 10 INPUT "ENTER A POSITIVE NUMBER ", N | ||
| + | 20 IF N > 0 THEN GOTO 40 | ||
| + | 30 PRINT "TRY AGAIN – MUST BE POSITIVE!" | ||
| + | 40 IF N <= 0 THEN GOTO 10 | ||
| + | 50 PRINT " | ||
| + | </ | ||
| + | |||
| + | This program runs the INPUT at least once. If you enter -5, it complains and loops back. If positive, it exits. The check is at the bottom; no skip on first pass. | ||
| + | |||
| + | ==== FOR-NEXT | ||
| + | Here, the FOR idea is to iterate over a range, and the NEXT check usually occurrs at the front of the loop (but may also occurr at the end of the loop). | ||
| + | |||
| + | Example: Countdown from 10 to 0, check at top. | ||
| + | |||
| + | <codify BASIC> | ||
| + | 10 LET C = 10 | ||
| + | 20 IF C >= 0 THEN GOTO 40 | ||
| + | 30 GOTO 70 | ||
| + | 40 PRINT C | ||
| + | 50 LET C = C - 1 | ||
| + | 60 GOTO 20 | ||
| + | 70 PRINT " | ||
| + | </ | ||
| + | |||
| + | Observe that sometimes flipping the logic of the test makes the code cleaner (no extra check): | ||
| + | |||
| + | <codify BASIC> | ||
| + | 10 LET C = 10 | ||
| + | 20 IF C < 0 THEN GOTO 60 | ||
| + | 40 PRINT C | ||
| + | 50 LET C = C - 1 | ||
| + | 60 GOTO 20 | ||
| + | 70 PRINT " | ||
| + | </ | ||
| + | |||
| + | In this second case, inverting the logic falls-through to the do-loop. This is more efficient, even though the idea is "if C is greater than or equal to zero". Know your logic operators! | ||
| + | |||
| + | ==== FOR-NEXT part II | ||
| + | Here is another example of a similar loop, that amounts to a FOR-NEXT loop. | ||
| + | |||
| + | Example: Print even numbers 2 to 20 (step +2). | ||
| + | |||
| + | <codify BASIC> | ||
| + | 10 LET X = 2 | ||
| + | 20 IF X > 20 THEN GOTO 60 | ||
| + | 30 PRINT X | ||
| + | 40 LET X = X + 2 | ||
| + | 50 GOTO 20 | ||
| + | 60 PRINT "EVEN NUMBERS DONE!" | ||
| + | </ | ||
| + | |||
| + | Or, to simulate STEP -1 (countdown), | ||
| + | |||
| + | <codify BASIC> | ||
| + | 10 LET Y = 20 | ||
| + | 20 IF Y < 1 THEN GOTO 60 | ||
| + | 30 PRINT Y | ||
| + | 40 LET Y = Y - 1 | ||
| + | 50 GOTO 20 | ||
| + | 60 PRINT "BLAST OFF!" | ||
| + | </ | ||
| + | |||
| + | These methods of program flow control are from old-school TinyBASIC programming. This was the norm -- inventive uses of code. There is a LOT you can do with TinyBASIC. It's understandable, | ||
| + | |||
| + | === An Exercise for the Reader | ||
| + | |||
| + | You can practice your BASIC skills with these exercises: | ||
| + | |||
| + | * Make the WHILE example count backwards. | ||
| + | * Turn the guessing game's round counter into a DO-style loop (run at least one round?). | ||
| + | * Add a "Play again?" | ||
| + | |||
| + | When FOR-NEXT arrives in a future update, you'll appreciate how these hand-built loops taught you control flow. Until then, don't forget to "think differently!" | ||
| == NEXT STEPS | == NEXT STEPS | ||
| Line 266: | Line 395: | ||
| //Check the **SD-8516 Programmer' | //Check the **SD-8516 Programmer' | ||
| - | |||
sd-8516_user_s_guide.1771621229.txt.gz · Last modified: by appledog
