====== BASIC-11 under RT-11 ====== DEC BASIC-11 on the PDP-11/23: getting in and out, program commands, statements, and the dialect rules that break programs written for other BASICs. Verified on ''BASIC-11 V2'' under ''RT-11 V5.5''. **''BASIC.SAV'' lives on the games disk, ''DL1:''. The prompt is ''READY''. To leave, type ''BYE''.** ===== Quick Reference ===== ^ Task ^ Command ^ | Start BASIC | ''RUN DL1:BASIC'' | | Leave BASIC | ''BYE'' | | New program | ''NEW'' | | Load a saved program | ''OLD ELIZA'' | | Save the first time | ''SAVE'' | | Save over the old copy | ''REPLACE'' | | Run / list | ''RUN'' / ''LIST'' | | Delete lines | ''DEL 100-200'' | | Renumber | ''RESEQ'' | | Erase the program in memory | ''SCR'' | | Back in after Ctrl-C | ''REENTER'' at the RT-11 dot | ===== Getting in and out ===== **# Start BASIC from the games disk:** RUN DL1:BASIC Answer its start-up questions with RETURN for the defaults. **# Leave BASIC:** BYE **# Recover your program after a stray Ctrl-C:** REENTER Typed at the RT-11 dot. The program is still in memory. ===== Program commands ===== **# Start a new program — it asks for a name:** NEW **# Load a saved program:** OLD DL1:ELIZA **# Save as a new file:** SAVE **# Overwrite the saved copy:** REPLACE **# Merge a saved program into memory:** APPEND NAME **# Delete a saved program file:** UNSAVE NAME **# Run without the header line:** RUNNH **# List a range of lines:** LIST 100-200 **# Delete a range of lines:** DEL 100-200 Typing a line number on its own deletes that line. **# Renumber the program:** RESEQ **# Erase the program in memory:** SCR **# Clear variables, keep the program:** CLEAR **# Show memory used:** LENGTH **# Save a pre-translated copy that loads faster:** COMPILE ''SUB'' edits text inside one line — check the manual for its exact form. ==== Keys ==== ^ Keys ^ Action ^ | ''DELETE'' | Erase last character | | ''Ctrl-U'' | Erase the line | | ''Ctrl-C'' | Stop the program; twice drops to RT-11 | | ''Ctrl-S'' / ''Ctrl-Q'' | Pause / resume output | | ''Ctrl-O'' | Discard output | ===== Statements ===== ^ Statement ^ Does ^ | ''10 REM text'' | Comment — also ''10 ! text'' | | ''LET X=5'' | Assign — ''LET'' optional | | ''PRINT A;B'' | semicolon packs close, comma jumps to next column | | ''PRINT TAB(10);X'' | Print at a column | | ''INPUT "AGE";A'' | Prompt and read | | ''IF X>5 THEN 200'' | Jump if true | | ''GOTO 100'' | Jump | | ''GOSUB 500'' / ''RETURN'' | Subroutine | | ''ON N GOTO 10,20,30'' | Jump by value | | ''FOR I=1 TO 10 STEP 2'' / ''NEXT I'' | Loop | | ''DIM A(50)'' | Array — default size 10 | | ''DEF FNA(X)=X*X'' | One-line function | | ''READ A'' / ''DATA 1,2'' / ''RESTORE'' | Constants in the program | | ''RANDOMIZE'' | New random sequence each run | | ''CHAIN "PROG2"'' | Run another saved program | | ''STOP'' / ''END'' | Halt / last line | ===== Files ===== **# Create a file:** OPEN "DATA.DAT" FOR OUTPUT AS FILE #1 **# Open a file for reading:** OPEN "DATA.DAT" FOR INPUT AS FILE #1 **# Write and read through it:** PRINT #1,X INPUT #1,X **# Jump at end of file:** IF END #1 THEN 900 **# Close it:** CLOSE #1 **# Delete a file:** KILL "DATA.DAT" ===== Functions ===== ^ Function ^ Returns ^ | ''ABS'' ''INT'' ''SGN'' ''SQR'' | absolute, integer part, sign, square root | | ''SIN'' ''COS'' ''ATN'' ''PI'' | trig in radians, pi | | ''EXP'' ''LOG'' ''LOG10'' | e to the x, natural and base-10 log | | ''RND'' | 0 to 1 — ''INT(RND*6)+1'' rolls a die | | ''LEN(A$)'' ''POS(A$,B$,1)'' | length, position of B$ in A$ | | ''SEG$(A$,2,4)'' | characters 2 **through** 4 | | ''STR$(X)'' ''VAL(A$)'' | number to string, string to number | | ''CHR$(65)'' ''ASC("A")'' | character codes | | ''TRM$(A$)'' | strip trailing spaces | | ''DAT$'' ''CLK$'' | date, time of day ''HH:MM:SS'' | ===== Porting programs from other BASICs ===== **# 1. Variable names are one letter plus an optional digit.** ''A'', ''A1'', ''Z9'', ''T$'' are legal. ''CA'' and ''CB'' are not — rename to ''C'' and ''D''. **# 2. Output wraps at 72 columns.** A 79-character line breaks and scrambles any picture drawn with ''PRINT''. Keep lines under 72. **# 3. Use ''IF … THEN line''.** ''IF X>4 GOTO 200'' from other dialects becomes ''IF X>4 THEN 200''. For a statement after ''THEN'', jump around it instead. **# 4. Paste slowly.** BASIC drops characters from a fast paste. Paste a line at a time, or use the terminal program's line delay. **# 5. A one-letter typo can look like a logic bug.** The Mandelbrot below printed whole lines of characters or whole lines of spaces. Line 40 said ''Y'' where it meant ''X''. ''LIST 30-50'' before you debug anything else. ===== Mandelbrot benchmark ===== Draws the set in characters ''0''-''9'' and ''A''-''F'' and reports the elapsed time. Needs the QBone ''KW11'' enabled for ''CLK$'' to move. 10 REM MANDELBROT SET FOR BASIC-11 12 T$=CLK$ 14 S1=VAL(SEG$(T$,1,2))*3600+VAL(SEG$(T$,4,5))*60+VAL(SEG$(T$,7,8)) 20 FOR Y=-12 TO 12 30 FOR X=-35 TO 35 40 C=X*.0367-.65 50 D=Y*.0833 60 A=C 70 B=D 80 FOR I=0 TO 15 90 T=A*A-B*B+C 100 B=2*A*B+D 110 A=T 120 IF A*A+B*B>4 THEN 170 130 NEXT I 140 PRINT " "; 150 GOTO 200 170 IF I<10 THEN 190 180 I=I+7 190 PRINT CHR$(48+I); 200 NEXT X 210 PRINT 220 NEXT Y 230 PRINT 240 U$=CLK$ 250 S2=VAL(SEG$(U$,1,2))*3600+VAL(SEG$(U$,4,5))*60+VAL(SEG$(U$,7,8)) 260 E=S2-S1 270 IF E>=0 THEN 290 280 E=E+86400 290 PRINT "STARTED ";T$;" FINISHED ";U$ 300 PRINT "ELAPSED TIME:";INT(E/60);"MIN";E-60*INT(E/60);"SEC" 310 END Slow. The 11/23 has no floating-point hardware, so every multiply runs in software — **several minutes** for one picture. Points inside the set run all 16 iterations and print as spaces, so the middle rows crawl. That is normal. **# Save it once it runs:** SAVE ===== Programs on the games disk ===== ^ File ^ What ^ | ''ELIZA.BAS'' | The classic conversation program | | ''PRIMES.BAS'' | Prime numbers | | ''SIEVE.BAS'' | Sieve of Eratosthenes benchmark | | ''PI.BAS'' | Digits of pi | | ''DEMOB1.BAS'' | Demonstration program | **# Talk to ELIZA:** OLD DL1:ELIZA RUN //101 BASIC Computer Games// came largely out of DEC BASIC, so most listings run with little change. ===== Troubleshooting ===== ^ Symptom ^ Cause ^ Fix ^ | Can't find ''BASIC.SAV'' | not on the system disk | ''RUN DL1:BASIC'' | | Syntax error on ''CA=…'' | two-letter variable name | one letter + optional digit | | Picture lines break and scramble | 72-column output wrap | keep lines under 72 | | Whole lines all chars or all spaces | ''X'' not used where expected | ''LIST'' and check the loop maths | | Dropped to the dot prompt | Ctrl-C twice | ''REENTER'' | | ''CLK$'' never changes | no line clock | enable ''KW11'' before booting RT-11 | | Missing characters after a paste | paste too fast | paste a line at a time | | Old lines mixed into a new program | memory not cleared | ''SCR'' before typing | Rule of thumb: **''SAVE'' once, ''REPLACE'' every time after**. Related: [[pdp11:rt11|RT-11 commands]], [[pdp11:rt11_games_disk|games disk contents]].