This manual documents the web-based TRS-80 Model 4 TinyBASIC Fully Loaded emulator. It is written in the style of an early-1980s computer reference, but it accurately describes the features implemented by this browser emulator. The system accepts numbered BASIC program lines, direct commands, numeric and string expressions, arrays, DATA statements, subroutines, loops, screen-positioned output, and ASCII program files. Use the emulator as a programming laboratory: type a line, list it, run it, interrupt it, modify it, and save it back to your local computer.
PRINT "RADIO SHACK TRS-80 MODEL 4"
PRINT "READY"The manual is organized as a tutorial, command reference, programming guide, troubleshooting handbook, and collection of runnable examples. Use the search box at the top to locate a statement such as DIM, PRINT, BREAK, RND, or GOSUB. The table of contents links to each page. Printed output is formatted as a multi-page reference manual. Features marked as emulator extensions are convenient browser features and are not claimed to be exact copies of every historical Model 4 BASIC implementation.
Open the emulator page and allow the simulated boot sequence to complete. Click or tap the green display before typing. The READY prompt indicates that the command processor is waiting. A line that begins with a number is stored in program memory. A line without a number is executed immediately as a direct command. RESET / BOOT clears the display and restarts the simulated system; it does not represent a physical power cycle.
10 PRINT "HELLO"
20 END
RUNThe greater-than prompt is the input point. Direct statements are useful for calculations and experiments. Numbered lines build a program. LIST displays the stored program. RUN begins execution at the lowest numbered line. NEW removes all program lines. CLEAR resets variables and runtime stacks but leaves the program text intact.
PRINT 2+2
A=25
PRINT SQR(A)Type a line number followed by a BASIC statement. Re-entering the same number replaces the old line. Entering a number by itself deletes that line. Program lines are sorted numerically, so you may enter them in any order. Leave gaps such as 10, 20, 30 so additional lines can be inserted later.
10 PRINT "FIRST"
30 PRINT "THIRD"
20 PRINT "SECOND"
LIST
20Direct mode executes an unnumbered statement immediately. Program mode stores numbered lines for later execution. Most statements work in either mode, although GOTO and GOSUB require a stored program target. Direct mode is especially useful for testing expressions, checking functions, and inspecting variables.
PRINT FACT(6)
PRINT SIN(PI/2)
PRINT RANDINT(1,6)RUN resets runtime variables and arrays, scans DATA statements, clears FOR/NEXT and GOSUB stacks, and begins execution at the first stored line. When the program reaches END or passes the final statement, READY is displayed. A running program can be stopped with BREAK PROGRAM, the on-screen BREAK key, Esc, or Ctrl+C.
Starts execution of the numbered BASIC program currently stored in emulator memory.
RUN| Element | Description |
|---|---|
RUN | Direct command; it does not take a line-number argument in this emulator. |
RUN prepares a fresh execution environment, clears scalar variables and arrays, resets DATA, FOR/NEXT, and GOSUB state, scans DATA statements, and begins with the lowest numbered program line. Program text remains unchanged. Execution ends normally after END or after the final statement, and it can be interrupted by BREAK.
The original runnable examples are retained below.
10 PRINT "RUNNING"
20 GOTO 10
RUNBREAK is the emergency stop for a running BASIC program. The large BREAK PROGRAM button, the virtual BREAK key, Esc, and Ctrl+C all request an interrupt. The interpreter checks for the interrupt between statements and while pacing long loops or PAUSE delays. BREAK also cancels a program waiting at INPUT. The display reports *** BREAK *** followed by READY. BREAK does not erase the stored program.
Stops a running program without erasing its numbered lines.
BREAK PROGRAM buttonVirtual keyboard: BREAKKeyboard: EscKeyboard: Ctrl+C| Element | Description |
|---|---|
BREAK request | An interrupt flag checked between statements, during paced loops, during PAUSE, and while INPUT is waiting. |
BREAK is the emergency recovery mechanism for an accidental infinite loop or a program that is producing excessive output. It clears active runtime stacks and cancels pending input. The stored listing stays available for inspection, correction, and another RUN.
The original runnable examples are retained below.
10 PRINT "PRESS BREAK"
20 GOTO 10
RUNLIST displays every stored line in ascending numeric order. The listing is plain ASCII text and corresponds to what SAVE ASCII BASIC writes to disk. LIST does not run the program or alter variables. Use it often while debugging to verify line numbers, punctuation, array subscripts, and branch targets.
Displays every stored numbered program line in ascending numeric order.
LISTLIST is the principal program-inspection command. It shows exactly the text that will be written by SAVE ASCII BASIC. Listing does not execute statements, change variables, or reset arrays.
The original runnable examples are retained below.
NEW removes all numbered program lines. It is intended for starting a new program. Save any program you wish to keep before issuing NEW. NEW does not delete files from the local computer; it only clears the emulator program memory.
Deletes all numbered BASIC lines from emulator memory so a new program can be entered.
NEWNEW affects the in-memory program only. It does not delete a previously saved .BAS file. Because browsers do not provide automatic recovery of unsaved BASIC listings, NEW should be used only after the current program has been saved or is no longer needed.
The original runnable examples are retained below.
CLEAR resets numeric variables, string variables, numeric arrays, string arrays, the DATA pointer, FOR/NEXT stack, and GOSUB stack. The numbered program remains in memory. RUN performs its own runtime reset before execution, so CLEAR is most useful while experimenting in direct mode.
Resets variables, arrays, DATA position, and active runtime stacks while preserving program text.
CLEARCLEAR initializes A through Z to zero, A$ through Z$ to empty strings, removes array definitions and values, resets the DATA pointer, and empties FOR/NEXT and GOSUB stacks. RUN performs a comparable runtime reset automatically.
The original runnable examples are retained below.
CLS clears the emulated display. Used as a program statement, it creates a clean screen before menus, games, tables, or animation. Used as a direct command, it clears the terminal and restores the prompt.
Clears the simulated terminal or screen display.
CLS10 CLSIn direct mode, CLS clears the terminal and restores the command prompt. In program mode, it clears output so menus, positioned text, or animation can begin with a clean display. CLS does not modify program lines or variables.
The original runnable examples are retained below.
10 CLS
20 PRINT @ 128,"MODEL 4 BASIC"HELP prints a compact list of implemented statements, operators, functions, arrays, file controls, and BREAK methods. MEM reports simulated free memory. DIR and CATALOG display a simulated disk directory. BASIC and SYSTEM display period-style ready messages. These commands are decorative system conveniences rather than a full TRSDOS implementation.
Provides emulator help and period-style simulated system information.
HELPMEMDIRCATALOGBASICSYSTEM| Element | Description |
|---|---|
HELP | Displays supported commands, functions, arrays, file controls, and interrupt keys. |
MEM | Reports simulated free memory; the figure is decorative rather than a live JavaScript heap measurement. |
DIR / CATALOG | Displays a simulated drive directory. |
BASIC / SYSTEM | Displays Model 4 BASIC or TRSDOS-style ready messages. |
These commands support the atmosphere and usability of the emulator. They do not implement a complete TRSDOS file system, disk allocation map, or machine-language command environment.
The original runnable examples are retained below.
Select LOAD ASCII BASIC and choose a local .BAS or .TXT file. The browser reads the file as text, normalizes line endings, and imports numbered BASIC lines into program memory. The file never needs to be uploaded to a server. After loading, use LIST to inspect it and RUN to execute it. A valid ASCII program should contain one numbered BASIC line per text line.
Imports a plain-text BASIC listing from the local device into emulator program memory.
Select LOAD ASCII BASICChoose a plain-text file containing numbered BASIC lines| Element | Description |
|---|---|
.BAS / .TXT / other text file | The filename extension is not part of the BASIC language; the file contents must be readable text. |
Numbered line | A line beginning with a decimal line number is stored in the program. |
The browser File API reads the selected file locally; the program is not uploaded to a remote server. Line endings are normalized and numbered lines are inserted into memory. On iPadOS, custom .BAS extensions may be greyed out if the file input restricts recognized types; an unrestricted file picker or a temporary .TXT filename avoids that problem.
The original runnable examples are retained below.
10 PRINT "LOADED FROM LOCAL PC"
20 ENDSelect SAVE ASCII BASIC to download the current program as a plain-text .BAS file. Lines are saved in ascending order with their line numbers. The file can be edited with Notepad, Notepad++, VS Code, or another text editor, then loaded back into the emulator. Saving does not include current variable values, screen contents, or execution state.
Downloads the current numbered listing as a portable plain-text BASIC file.
Select SAVE ASCII BASICThe emulator sorts program lines numerically, joins them with text line endings, and asks the browser to download the result. Only source code is saved. Variables, arrays, screen output, current DATA position, and execution state are not included.
The original runnable examples are retained below.
The portable program format uses ordinary printable characters and line endings. Avoid rich-text editors that may insert formatting or typographic quotation marks. Use straight double quotes around BASIC strings. A line without a leading number is not stored as part of a loaded program. Keep a backup before making large edits.
Defines the portable, human-readable format used for loading and saving emulator programs.
10 PRINT "HELLO"20 END| Element | Description |
|---|---|
Line number | Decimal number at the beginning of each stored program line. |
Statement text | One or more BASIC statements following the line number. |
Encoding | UTF-8 or ordinary ASCII-compatible plain text. |
The format is source text, not the tokenized binary representation used by some historical BASIC systems. Each physical text line should contain one numbered BASIC line. Colons may combine multiple statements within that line.
The original runnable examples are retained below.
PRINT displays strings, numeric expressions, variables, array elements, and function results. A bare PRINT outputs a blank line. Items can be separated by semicolons or commas. Numbers are formatted without unnecessary trailing zeros. Strings are printed exactly as evaluated.
Writes text, numbers, variables, array elements, or expression results to the emulator display.
PRINT "TEXT"PRINT expressionPRINT item1;item2PRINT item1,item2PRINT| Element | Description |
|---|---|
item | A string expression, numeric expression, variable, array element, or supported function. |
; | Joins output without ordinary tab-zone spacing; a trailing semicolon suppresses the newline. |
, | Advances output toward the next print zone. |
bare PRINT | Produces a blank line or terminates a line previously held open. |
PRINT evaluates each item from left to right and converts numeric results to readable text. String literals appear without quotation marks. Array references and functions are evaluated exactly as they would be in assignments or conditions.
The original runnable examples are retained below.
PRINT "TOTAL=";A
PRINT X(I)
PRINTA semicolon joins output without automatically advancing to the next display line. It is useful for constructing tables, progress indicators, and rows of symbols. In this emulator, PRINT statements ending with a semicolon preserve the current output line for the next PRINT.
Controls horizontal output by placing values directly next to one another and optionally suppressing the newline.
PRINT "A";"B"PRINT I;" ";PRINTSemicolons are useful for rows, prompts, progress displays, and character graphics. A trailing semicolon leaves the current output line open. A later bare PRINT advances to the next line.
The original runnable examples are retained below.
10 FOR I=1 TO 10
20 PRINT I;" ";
30 NEXT I
40 PRINTA comma advances output toward the next tab zone. This resembles classic BASIC column formatting and is useful for aligned reports. Exact spacing depends on the current column and the emulator tab-zone width.
Formats output in fixed-width print zones similar to classic BASIC report columns.
PRINT "NAME","SCORE"PRINT A,B,CThe emulator advances to the next 16-column zone based on the current output position. Commas are convenient for rough tables but do not guarantee alignment for values longer than a zone.
The original runnable examples are retained below.
PRINT "NAME","SCORE"
PRINT "RICH",100TAB(N) inserts spaces until the output reaches column N. If the current column has already passed N, no reverse movement occurs. TAB is intended for formatted reports and headings rather than random-access screen placement.
Inserts spaces until output reaches a requested character column.
PRINT TAB(N);"TEXT"| Element | Description |
|---|---|
N | Numeric expression representing the target column. |
TAB only moves forward. If output has already passed the requested column, no backward cursor movement occurs. TAB is evaluated during PRINT processing and is most useful for headings and reports.
The original runnable examples are retained below.
PRINT TAB(20);"CENTER AREA"PRINT @ places text at a simulated screen-memory position on a 64-column by 16-row display. Position zero is the upper-left character. The row is position divided by 64; the column is the remainder. Positions wrap within the 1024-character screen area. This feature is well suited to menus, scoreboards, and character animation.
Writes text at a specific location in the simulated 64-by-16 character screen memory.
PRINT @ position,"TEXT"PRINT @ expression;value| Element | Description |
|---|---|
position | Numeric expression from 0 through 1023; values are wrapped into the screen area. |
row | Computed as INT(position/64). |
column | Computed as position MOD 64. |
PRINT @ allows menus, scoreboards, and animation without producing a scrolling line for every update. Text overwrites existing characters beginning at the selected position.
The original runnable examples are retained below.
10 CLS
20 PRINT @ 0,"TOP LEFT"
30 PRINT @ 128,"ROW 2"INPUT pauses the program, displays a question prompt, and waits for a value. INPUT A stores a numeric value; INPUT A$ stores text. Press Enter to submit. BREAK, Esc, or Ctrl+C cancels a waiting INPUT and interrupts the program. Numeric input that cannot be parsed becomes zero in this emulator.
Pauses a program and obtains a numeric or string value from the user.
INPUT AINPUT A$| Element | Description |
|---|---|
A | Single-letter numeric variable. |
A$ | Single-letter string variable. |
INPUT displays a question prompt and waits for Enter. Numeric input is converted with browser number parsing; invalid numeric text becomes zero in this implementation. BREAK, Esc, or Ctrl+C cancels the wait and interrupts the program.
The original runnable examples are retained below.
10 INPUT A
20 PRINT "YOU ENTERED ";ALET assigns a value to a variable or array element. LET is optional. Numeric expressions are stored in numeric variables; string expressions are stored in names ending with a dollar sign. Array elements must have been dimensioned before assignment.
Stores the result of an expression in a scalar variable or array element.
LET A=expressionA=expressionA$="text"X(I)=expressionN$(I)=string-expression| Element | Description |
|---|---|
LET | Optional keyword retained for traditional BASIC readability. |
destination | Numeric variable, string variable, numeric array element, or string array element. |
expression | Value evaluated before storage. |
The destination type determines whether the expression is interpreted as numeric or string. Array elements require a preceding DIM declaration. String assignments are limited to the emulator's configured maximum length.
The original runnable examples are retained below.
LET A=10
B=A*2
LET X(I)=B
N$="TRS-80"REM marks a comment. The interpreter ignores the remainder of that statement. Comments should explain purpose, assumptions, data formats, and non-obvious calculations. Clear comments are especially valuable in programs that use many GOTO targets.
Adds explanatory text to a program without executing it.
REM comment text100 REM INITIALIZE ARRAYSThe interpreter ignores the remainder of the REM statement. Comments can identify sections, explain formulas, describe variable use, or record compatibility changes made to an imported historical listing.
The original runnable examples are retained below.
10 REM INITIALIZE SCREEN
20 CLSEND terminates program execution normally. It is optional at the physical end of a program, but including it makes the intended stopping point clear and prevents accidental entry into subroutines placed later in the listing.
Terminates program execution normally.
ENDEND prevents execution from continuing into later lines, especially subroutines placed after the main program. Reaching the physical end of the listing also stops execution, but an explicit END documents intent.
The original runnable examples are retained below.
100 END
500 REM SUBROUTINES MAY FOLLOWA colon separates multiple statements on one numbered line. Colons inside quoted strings are not separators. Compact lines save listing space, but excessive chaining makes programs harder to debug. GOTO and loop behavior operate on the flattened statement sequence.
Places more than one BASIC statement on the same numbered line.
10 A=1:B=2:PRINT A+BThe interpreter divides a line at top-level colons while preserving colons inside quoted strings. Statements then execute in their written order. Branches operate on the flattened statement sequence.
The original runnable examples are retained below.
10 A=1: B=2: PRINT A+BGOTO transfers execution to the first statement on the specified line. The target line must exist. Unstructured jumps are historically common in BASIC, but reserve line-number ranges for major sections and document important targets.
Transfers execution unconditionally to a numbered program line.
GOTO line-number| Element | Description |
|---|---|
line-number | Existing numbered line that becomes the next execution point. |
GOTO is useful for main loops, retries, state transitions, and exits from conditional sections. The emulator jumps to the first statement on the target line.
The original runnable examples are retained below.
10 PRINT "AGAIN"
20 GOTO 10IF evaluates a numeric condition. Zero is false; any nonzero value is true. In this emulator, THEN is followed by a line number. When true, execution jumps to that line. When false, execution continues with the next statement.
Tests a condition and branches to a line number when the condition is true.
IF condition THEN line-number| Element | Description |
|---|---|
condition | Numeric expression; zero is false and any nonzero value is true. |
line-number | Target executed only when the condition is true. |
Comparisons return numeric 1 or 0 and can be combined with AND, OR, and NOT. When the condition is false, execution continues with the next statement.
The original runnable examples are retained below.
10 IF A>5 THEN 100
20 PRINT "A IS 5 OR LESS"Comparisons return 1 for true and 0 for false. Supported operators are =, <>, <, <=, >, and >=. Comparisons may be combined with AND, OR, and NOT. Parentheses make intent clear and reduce precedence mistakes.
Compares numeric values and returns 1 for true or 0 for false.
A=BA<>BAA<=BA>BA>=BParameters and Elements
Element Description =Equal <>Not equal <Less than <=Less than or equal >Greater than >=Greater than or equal
Detailed Description
Comparison results are ordinary numeric values. They may be printed, assigned, or used as IF conditions. Floating-point calculations can contain tiny rounding differences, so exact equality after complex decimal arithmetic should be used carefully.
Programming Guidance
- Use a tolerance test such as ABS(A-B)<0.0001 for approximate decimal equality.
- Parenthesize comparisons before combining them with AND or OR.
Related Entries
Examples
The original runnable examples are retained below.
PRINT 5=5
PRINT 5<>4
PRINT (A>=1) AND (A<=10)GOSUB transfers control to a subroutine and stores the return point. RETURN resumes after the calling GOSUB. Subroutines are useful for repeated printing, calculations, input validation, and screen setup. RETURN without a matching GOSUB causes an error.
Calls a reusable subroutine and later resumes execution after the call.
GOSUB line-numberRETURN| Element | Description |
|---|---|
line-number | First line of the subroutine. |
RETURN | Uses the most recently saved return point. |
GOSUB pushes the current execution position onto a stack and branches. RETURN pops that position and continues after the GOSUB. Nested subroutine calls are permitted as stack space allows.
The original runnable examples are retained below.
10 GOSUB 100
20 END
100 PRINT "SUBROUTINE"
110 RETURNFOR initializes a single-letter numeric variable, records an ending value and step, and begins a loop. NEXT increments the variable and either repeats or exits. The default step is 1. Negative steps count downward. The NEXT variable must match the active FOR frame.
Repeats a block of statements while advancing a numeric control variable.
FOR I=start TO finishFOR I=start TO finish STEP incrementNEXT I| Element | Description |
|---|---|
I | Single-letter numeric loop variable. |
start | Initial numeric value. |
finish | Inclusive ending value. |
increment | Amount added each repetition; defaults to 1. |
FOR assigns the start value and records the loop frame. NEXT increments the variable and repeats when it has not passed the ending value. Positive and negative steps are supported.
The original runnable examples are retained below.
10 FOR I=1 TO 10
20 PRINT I
30 NEXT ISTEP changes the increment used by FOR. Fractional and negative steps are accepted. A positive step continues while the variable is less than or equal to the ending value. A negative step continues while it is greater than or equal to the ending value.
Specifies the amount and direction by which a FOR loop variable changes.
FOR I=1 TO 10 STEP 2FOR I=10 TO 1 STEP -1Positive STEP values count upward; negative values count downward. The finish value remains inclusive. Fractional steps are accepted because variables use floating-point numbers.
The original runnable examples are retained below.
FOR I=10 TO 0 STEP -2
PRINT I
NEXT ILoops may be nested. Each NEXT must close the most recent matching FOR. Nested loops are useful for tables, grids, array initialization, and cellular automata. Keep loop variables distinct and indent the source in an external editor when possible.
Uses one FOR/NEXT loop inside another to process rows, columns, combinations, or multidimensional arrays.
FOR R=0 TO 5 FOR C=0 TO 5 A(R,C)=R*C NEXT CNEXT RThe innermost active loop completes for each iteration of the outer loop. The emulator tracks loop frames in stack order, so NEXT must match the active structure.
The original runnable examples are retained below.
10 FOR R=1 TO 5
20 FOR C=1 TO 10
30 PRINT "*";
40 NEXT C
50 PRINT
60 NEXT RPAUSE milliseconds delays execution for approximately the requested number of milliseconds. Unlike a busy-wait BASIC loop, PAUSE yields to the browser and remains interruptible. Use PAUSE for animation pacing and demonstrations. Browser timing is not suitable for precision measurement.
Delays program execution for approximately a specified number of milliseconds while keeping the browser responsive.
PAUSE milliseconds| Element | Description |
|---|---|
milliseconds | Numeric expression converted to a nonnegative integer delay. |
PAUSE uses asynchronous browser timing rather than a busy loop. The interpreter continues checking for BREAK during the delay, making it suitable for animation and demonstrations.
The original runnable examples are retained below.
10 PRINT "TICK"
20 PAUSE 500
30 GOTO 10DATA stores constant values inside the program. Items are separated by commas and may be numeric or quoted strings. DATA statements do nothing when reached during normal execution; they are scanned before RUN to construct the data pool.
Stores constant numeric and string values inside the program for sequential retrieval by READ.
DATA 10,20,30DATA "RED","GREEN","BLUE"DATA statements are scanned before RUN and placed into a shared data pool. Reaching a DATA line during ordinary execution performs no visible action.
The original runnable examples are retained below.
10 DATA 10,20,30,"DONE"READ obtains the next item from the DATA pool and places it into a numeric or string variable. READ past the final item causes an error. This emulator currently documents READ into scalar variables; use assignment afterward to place values into arrays.
Retrieves the next value from the program's DATA pool.
READ AREAD A$| Element | Description |
|---|---|
A | Numeric scalar destination. |
A$ | String scalar destination. |
Each READ advances the shared DATA pointer. Values are converted to the destination type. To place a value into an array, READ it into a scalar and then assign the scalar to the array element.
The original runnable examples are retained below.
10 DATA 5,10,15
20 READ A
30 PRINT ARESTORE resets the DATA pointer to the first DATA item. It permits the same data list to be read again. This implementation restores to the beginning rather than to a particular line number.
Moves the DATA pointer back to the first DATA item.
RESTOREAfter RESTORE, the next READ returns the first data value again. This implementation does not document RESTORE with a line-number argument.
The original runnable examples are retained below.
10 DATA 1,2
20 READ A
30 RESTORE
40 READ BNumeric variable names are the single letters A through Z. Values use JavaScript floating-point numbers internally. Integer-looking results are displayed as integers; other results are rounded for readable output. Programs that require exact decimal financial arithmetic should account for binary floating-point behavior.
Stores numeric values used in calculations, loops, comparisons, and array subscripts.
A=10R=PI/2PRINT AScalar numeric names are A through Z. Values are JavaScript double-precision floating-point numbers internally. This offers a large range but includes the usual binary floating-point rounding behavior.
The original runnable examples are retained below.
String variable names are A$ through Z$. Strings can be assigned from literals, string variables, string functions, or concatenations. Stored strings are limited to 255 characters by assignment in this emulator.
Stores text values for messages, names, menus, and input.
A$="MODEL 4"PRINT A$Scalar string names are A$ through Z$. String expressions can combine literals, variables, and supported string functions. Assignment truncates strings to the emulator's configured maximum length.
The original runnable examples are retained below.
A$="MODEL "+"4"
PRINT A$DIM creates numeric or string arrays. Array names use a single letter, optionally followed by $. Dimensions are inclusive, so DIM X(68) permits subscripts 0 through 68. Arrays are reset when RUN begins or CLEAR is issued. DIM may contain expressions such as DIM X(M) if M has already been assigned.
Declares numeric or string arrays and establishes their valid subscript ranges.
DIM X(68)DIM X (M)DIM A(10,10)DIM N$(20)| Element | Description |
|---|---|
array name | Single letter, optionally followed by $ for strings. |
dimension | Inclusive upper bound; DIM X(68) creates elements X(0) through X(68). |
multiple dimensions | Comma-separated upper bounds for tables or grids. |
DIM must execute before an array is read or written. Dimension expressions are evaluated at runtime, so a variable such as M may determine the size if it has already been assigned. New elements initially read as zero or an empty string.
The original runnable examples are retained below.
5 LET M=68
10 DIM X(M)
20 DIM Y(M)A one-dimensional array is a numbered list of elements. Use it for scores, samples, character states, lookup tables, and histories. Every element initially contains zero, or an empty string for string arrays. Subscripts are truncated to integers.
Stores an indexed sequence of related values under one array name.
DIM X(100)X(I)=valuePRINT X(I)One-dimensional arrays model lists, time series, scores, counters, and cellular states. The lower bound is zero and the declared number is the inclusive upper bound.
The original runnable examples are retained below.
10 DIM X(10)
20 FOR I=0 TO 10
30 X(I)=I*I
40 NEXT IMultiple dimensions create tables or higher-dimensional grids. DIM A(10,10) permits row and column subscripts from 0 through 10. The number of subscripts used later must match the declaration. Values are stored sparsely in the emulator, so untouched elements consume minimal entry storage.
Stores table, matrix, grid, or higher-dimensional data addressed by more than one subscript.
DIM A(10,10)A(R,C)=valuePRINT A(R,C)Each dimension has an inclusive zero-based range. The number of subscripts in every later reference must equal the number declared by DIM. The emulator stores values using a sparse key representation, so untouched elements remain at their default value.
The original runnable examples are retained below.
10 DIM A(5,5)
20 A(2,3)=99
30 PRINT A(2,3)A string array is dimensioned with a dollar-sign name. Each unassigned element reads as an empty string. String arrays are useful for menus, names, messages, and text maps.
Stores multiple text values that can be selected by a numeric subscript.
DIM N$(20)N$(0)="FIRST"PRINT N$(I)String arrays are useful for menu labels, names, map rows, messages, and lookup tables. Unassigned elements return an empty string.
The original runnable examples are retained below.
10 DIM N$(3)
20 N$(0)="ZERO"
30 PRINT N$(0)Subscripts may be constants, variables, arithmetic expressions, or function results. They are evaluated when the element is read or written and truncated to integers. Negative subscripts and subscripts greater than the declared upper bound cause SUBSCRIPT OUT OF RANGE.
Selects a particular element from an array.
X(5)X(I)X(I+1)A(R,C)| Element | Description |
|---|---|
subscript expression | Numeric expression evaluated and truncated to an integer. |
valid range | Zero through the corresponding declared upper bound. |
Subscripts can contain variables, arithmetic, and supported numeric functions. They are checked every time an element is read or written.
The original runnable examples are retained below.
X(I+1)=X(I)*2
PRINT A(R,C)ARRAY NOT DIMENSIONED means an element was used before DIM. WRONG NUMBER OF SUBSCRIPTS means the reference does not match the declared rank. SUBSCRIPT OUT OF RANGE means an index is below zero or above its upper bound. NEGATIVE ARRAY DIMENSION and BAD DIM STATEMENT report invalid declarations.
Explains runtime failures caused by invalid declarations or references.
ARRAY NOT DIMENSIONEDWRONG NUMBER OF SUBSCRIPTSSUBSCRIPT OUT OF RANGEBAD DIM STATEMENTArray checking protects the program from silently reading or writing an unintended element. The error usually identifies a missing DIM, an incorrect loop limit, a neighbor calculation at an edge, or a mismatch between one- and two-dimensional use.
The original runnable examples are retained below.
The arithmetic operators are +, -, *, /, ^, MOD, and postfix factorial !. Parentheses control evaluation order. Division or modulus by zero causes an error. Exponentiation uses JavaScript Math.pow behavior.
Performs numeric calculations.
A+BA-BA*BA/BA^BA MOD BN!| Element | Description |
|---|---|
+ | Addition |
- | Subtraction or unary negation |
* | Multiplication |
/ | Division |
^ | Exponentiation |
MOD | Remainder |
! | Postfix factorial |
Arithmetic expressions may contain constants, variables, array elements, functions, and parentheses. Normal precedence applies, but parentheses are strongly recommended in mixed expressions.
The original runnable examples are retained below.
PRINT (2+3)*4
PRINT 2^8
PRINT 10 MOD 3
PRINT 5!AND is true when both operands are nonzero. OR is true when either operand is nonzero. NOT converts zero to 1 and nonzero to 0. Logical results are numeric and can be printed, assigned, or used in IF.
Combines or reverses truth values represented numerically.
condition1 AND condition2condition1 OR condition2NOT condition| Element | Description |
|---|---|
AND | Returns 1 only when both operands are nonzero. |
OR | Returns 1 when either operand is nonzero. |
NOT | Returns 1 for zero and 0 for nonzero. |
Logical operations are most commonly used inside IF, but their numeric results can also be assigned or printed.
The original runnable examples are retained below.
PRINT (A>0) AND (A<10)
PRINT NOT 0ABS returns magnitude. INT rounds downward. FIX truncates toward zero. ROUND returns the nearest integer using JavaScript rounding behavior. SGN returns -1, 0, or 1. These functions are helpful for numeric formatting, loop bounds, and simulations.
Provides common value-normalization and integer-conversion operations.
ABS(X)INT(X)FIX(X)ROUND(X)SGN(X)| Element | Description |
|---|---|
ABS | Magnitude without sign. |
INT | Greatest integer less than or equal to X. |
FIX | Truncates toward zero. |
ROUND | Rounds to the nearest integer using browser behavior. |
SGN | Returns -1, 0, or 1. |
INT and FIX differ for negative values: INT(-3.1) is -4, while FIX(-3.1) is -3. SGN is useful for direction and comparison logic.
The original runnable examples are retained below.
PRINT ABS(-25)
PRINT INT(-3.1)
PRINT FIX(-3.9)
PRINT SGN(-8)SQR returns the square root and rejects negative input. EXP raises e to a power. LOG returns the natural logarithm. Very large or invalid mathematical results follow browser numeric behavior where not explicitly trapped.
Calculates square roots, exponential values, and natural logarithms.
SQR(X)EXP(X)LOG(X)| Element | Description |
|---|---|
SQR(X) | Square root; X must be nonnegative. |
EXP(X) | e raised to X. |
LOG(X) | Natural logarithm; mathematically requires X greater than zero. |
These functions use the browser's standard mathematical library. They are useful in geometry, growth and decay, statistics, and scientific calculations.
The original runnable examples are retained below.
PRINT SQR(144)
PRINT EXP(1)
PRINT LOG(E)Trigonometric functions use radians. Convert degrees to radians by multiplying by PI/180. TAN becomes very large near odd multiples of PI/2 because of floating-point approximation.
Evaluates the principal trigonometric functions using radians.
SIN(X)COS(X)TAN(X)| Element | Description |
|---|---|
X | Angle measured in radians. |
Convert degrees with radians=degrees*PI/180. These functions support geometry, oscillation, circular movement, and waveform calculations.
The original runnable examples are retained below.
R=45*PI/180
PRINT SIN(R),COS(R),TAN(R)Inverse trigonometric functions return radians. ASN and ACS expect values in the mathematical domain -1 through 1. ATN accepts any finite numeric value.
Returns inverse trigonometric angles in radians.
ASN(X)ACS(X)ATN(X)| Element | Description |
|---|---|
ASN | Arcsine; X normally lies from -1 to 1. |
ACS | Arccosine; X normally lies from -1 to 1. |
ATN | Arctangent; accepts any finite X. |
Multiply the returned radians by 180/PI to obtain degrees. Inverse functions are useful when deriving an angle from a ratio or coordinate relationship.
The original runnable examples are retained below.
PRINT ATN(1)*180/PIMIN and MAX accept multiple comma-separated numeric expressions. They return the smallest or largest result. Use them to clamp ranges, analyze data, or compare candidates.
Selects the smallest or largest value from a list of numeric expressions.
MIN(A,B,...)MAX(A,B,...)Every argument is evaluated before the result is selected. These functions are useful for limits, range analysis, clipping, and comparisons among several candidates.
The original runnable examples are retained below.
PRINT MIN(10,20,5)
PRINT MAX(10,20,5)The postfix ! operator and FACT(X) calculate factorial after truncating X to an integer. Negative values are rejected. Values above 170 are rejected because they exceed useful finite JavaScript number range.
Calculates the product of all positive integers from 1 through a nonnegative integer.
N!FACT(N)The argument is truncated to an integer. Both syntaxes use the same implementation. Factorials are used in combinations, permutations, probability, and series expansions.
The original runnable examples are retained below.
PRINT 6!
PRINT FACT(6)RND or RND() returns a pseudo-random value from zero up to but not including one. RND(X) returns that value multiplied by X. RANDINT(A,B) returns an integer from A through B inclusive. Random sequences are supplied by the browser and are not cryptographically secure.
Generates pseudo-random values for games, simulations, sampling, and randomized initialization.
RNDRND()RND(X)RANDINT(A,B)| Element | Description |
|---|---|
RND / RND() | Value from 0 inclusive to 1 exclusive. |
RND(X) | Random fraction multiplied by X. |
RANDINT(A,B) | Integer from A through B inclusive. |
The emulator uses the browser's pseudo-random generator. RND(1) therefore behaves like RND()*1, which is useful for compatibility with listings that include a dummy argument.
The original runnable examples are retained below.
R=RND(1)*10
D=RANDINT(1,6)PI and E provide common mathematical constants. TRUE equals 1 and FALSE equals 0. These names can be used wherever a numeric expression is accepted.
Provides named numeric constants.
PIETRUEFALSE| Element | Description |
|---|---|
PI | Approximately 3.141592653589793. |
E | Approximately 2.718281828459045. |
TRUE | Numeric 1. |
FALSE | Numeric 0. |
Named constants make mathematical and logical expressions clearer than embedding approximate decimal values.
The original runnable examples are retained below.
LEN returns string length. ASC returns the character code of the first character, or zero for an empty string. VAL converts the beginning of a numeric-looking string to a number; invalid text becomes zero.
Inspects or converts string data.
LEN(A$)ASC(A$)VAL(A$)| Element | Description |
|---|---|
LEN | Number of characters. |
ASC | Character code of the first character; zero for an empty string. |
VAL | Numeric conversion of text; invalid text becomes zero. |
These functions help validate input, decode characters, and convert text fields into numbers.
The original runnable examples are retained below.
PRINT LEN("MODEL 4")
PRINT ASC("A")
PRINT VAL("123")+7CHR$(N) returns the character whose 8-bit code is N. STR$(N) converts a numeric value to text. These functions bridge numeric and string processing.
Converts between character codes, numbers, and strings.
CHR$(N)STR$(N)| Element | Description |
|---|---|
CHR$(N) | Character corresponding to the low 8 bits of N. |
STR$(N) | Text representation of a numeric expression. |
CHR$ is useful for generated characters and simple text protocols. STR$ allows numeric results to participate in string concatenation.
The original runnable examples are retained below.
PRINT CHR$(65)
A$=STR$(123)LEFT$ returns characters from the beginning, RIGHT$ from the end, and MID$ from a one-based starting position. MID$ may include an optional length. Out-of-range slicing follows safe browser string behavior and returns available text.
Extracts a substring from the beginning, end, or middle of a string.
LEFT$(A$,N)RIGHT$(A$,N)MID$(A$,START)MID$(A$,START,LENGTH)| Element | Description |
|---|---|
A$ | Source string expression. |
N / LENGTH | Number of characters. |
START | One-based starting position. |
LEFT$ and RIGHT$ select from the ends. MID$ subtracts one from START to map traditional BASIC indexing to browser string indexing. Requests beyond available text return the portion that exists.
The original runnable examples are retained below.
A$="RADIO SHACK"
PRINT LEFT$(A$,5)
PRINT RIGHT$(A$,5)
PRINT MID$(A$,7,5)UPPER$ and LOWER$ change letter case. TRIM$ removes leading and trailing whitespace. They are emulator conveniences useful when comparing input and preparing reports.
Normalizes the case and surrounding whitespace of strings.
UPPER$(A$)LOWER$(A$)TRIM$(A$)These emulator extensions simplify menu input and text processing. UPPER$ and LOWER$ change letter case; TRIM$ removes whitespace at both ends.
The original runnable examples are retained below.
INKEY$ returns the last ordinary key pressed and then clears the stored key. It does not wait. Programs can poll INKEY$ in a loop for simple interactive control, but should include PAUSE or other pacing to avoid excessive CPU use.
Returns the most recently pressed ordinary key without pausing the program.
A$=INKEY$INKEY$ is nonblocking. After it returns the stored key, the stored value is cleared, so a later call returns an empty string until another key is pressed.
The original runnable examples are retained below.
10 A$=INKEY$
20 IF A$="" THEN 10
30 PRINT A$Use parentheses whenever an expression mixes arithmetic, comparison, and logical operations. The evaluator handles unary signs, exponentiation, multiplication and division, addition and subtraction, comparisons, NOT, AND, and OR. Parentheses are the clearest way to communicate intended order.
Determines the order in which parts of a mixed expression are evaluated.
(parentheses)unary sign / NOT^ and !* / MOD+-comparisonsANDORThe parser implements precedence rules, but complex expressions are easier to read and safer to port when parentheses explicitly state the desired order.
The original runnable examples are retained below.
The simulated character display is modeled as 64 columns by 16 rows for PRINT @ addressing. Normal terminal output can scroll beyond those dimensions. PRINT @ updates the screen-memory region and keeps it visible near the top.
Text characters can act as graphics. Asterisks, spaces, plus signs, slashes, and letters can form charts, mazes, vehicles, or cellular automata. PRINT @ is useful for placing individual objects, while semicolon PRINT is useful for building rows.
Animation usually follows four steps: erase or clear the previous image, update state variables, draw the new image, and PAUSE. Use BREAK to stop an animation. Avoid extremely short GOTO loops without pacing, because they can flood the terminal with output.
Temporary PRINT statements reveal variable values, branch choices, and array contents. Include labels so the output is meaningful. Remove or comment debug lines after the program works.
PRINT "I=";I;" C=";C;" X(I)=";X(I)Create a line-number map before writing a large program. Typical ranges might reserve 10-99 for initialization, 100-499 for the main loop, 500-799 for subroutines, and 800-999 for error handling. LIST verifies that every target exists.
Check DIM upper bounds, loop start and end values, and every calculated subscript. Remember that DIM X(68) includes both X(0) and X(68). A loop from 0 TO M is therefore valid when the array was dimensioned with M.
Every intentional loop should have an exit condition or be designed to run until BREAK. During development, add a counter or PAUSE. The new interrupt system lets you recover from GOTO loops, long FOR loops, pauses, and waiting input without reloading the page.
Begin with initialization, then enter a main loop, then place subroutines after END. Use comments and consistent line-number ranges. Keep calculations in small sections and avoid changing a FOR control variable inside its loop unless the effect is deliberate.
The interpreter periodically yields to the browser so the screen remains responsive and BREAK can be detected. A JavaScript implementation does not execute at the same speed as a physical 1980s computer. Timing loops therefore should not be used as clocks; use PAUSE for visible pacing.
This is a TinyBASIC-style web interpreter inspired by the TRS-80 Model 4. It is not a byte-for-byte Microsoft BASIC, Level II BASIC, Model III BASIC, or TRSDOS BASIC clone. Programs that depend on PEEK, POKE, machine language, disk channels, graphics hardware, SOUND syntax, ON GOTO, or other undocumented features may require adaptation.
?SN ERROR indicates that a statement did not match the implemented grammar. Check spelling, required keywords, parentheses, commas, line numbers, and quotation marks. Unsupported historical BASIC statements also produce this error.
Important runtime messages include DIVISION BY ZERO, MOD BY ZERO, NO SUCH LINE, NEXT WITHOUT FOR, NEXT VARIABLE MISMATCH, RETURN WITHOUT GOSUB, READ PAST END OF DATA, NEGATIVE FACTORIAL, FACTORIAL TOO LARGE, ARRAY NOT DIMENSIONED, WRONG NUMBER OF SUBSCRIPTS, and SUBSCRIPT OUT OF RANGE.
This introductory program demonstrates FOR, NEXT, semicolon output, and a final blank PRINT.
10 CLS
20 FOR I=1 TO 20
30 PRINT I;" ";
40 NEXT I
50 PRINT
60 ENDRANDINT produces an integer from one through six. Re-run the program for another roll.
10 CLS
20 PRINT "DICE ROLL: ";RANDINT(1,6)
30 ENDThis simple game selects a target and branches according to the player input.
10 A=RANDINT(1,10)
20 PRINT "GUESS 1 TO 10"
30 INPUT G
40 IF G=A THEN 100
50 PRINT "TRY AGAIN"
60 GOTO 30
100 PRINT "CORRECT"
110 ENDNested loops and formatted PRINT create a compact multiplication table.
10 FOR R=1 TO 10
20 FOR C=1 TO 10
30 PRINT R*C,
40 NEXT C
50 PRINT
60 NEXT RThe program counts exact divisors. It uses MOD and a loop.
10 INPUT N
20 C=0
30 FOR I=1 TO N
40 IF N MOD I=0 THEN 60
50 GOTO 70
60 C=C+1
70 NEXT I
80 IF C=2 THEN 110
90 PRINT "NOT PRIME"
100 END
110 PRINT "PRIME"This program dimension an array, fills it, and prints it.
10 DIM X(20)
20 FOR I=0 TO 20
30 X(I)=I*I
40 NEXT I
50 FOR I=0 TO 20
60 PRINT I;" ";X(I)
70 NEXT IA two-dimensional array stores products by row and column.
10 DIM A(5,5)
20 FOR R=0 TO 5
30 FOR C=0 TO 5
40 A(R,C)=R*C
50 NEXT C
60 NEXT R
70 PRINT A(4,5)A string array stores labels that can be printed in a loop.
10 DIM M$(3)
20 M$(0)="RUN"
30 M$(1)="LIST"
40 M$(2)="SAVE"
50 M$(3)="BREAK"
60 FOR I=0 TO 3
70 PRINT I;" ";M$(I)
80 NEXT IPRINT @ and PAUSE create a simple moving character. Press BREAK to stop or allow it to finish.
10 CLS
20 FOR P=0 TO 63
30 PRINT @ P,"*"
40 PAUSE 50
50 PRINT @ P," "
60 NEXT PThe array counts 100 simulated die rolls and prints totals.
10 DIM C(6)
20 FOR I=1 TO 100
30 D=RANDINT(1,6)
40 C(D)=C(D)+1
50 NEXT I
60 FOR D=1 TO 6
70 PRINT D;" ";C(D)
80 NEXT DDATA, READ, and RESTORE provide an embedded table.
10 DATA 10,20,30,40
20 FOR I=1 TO 4
30 READ A
40 PRINT A
50 NEXT I
60 RESTOREA reusable heading routine is called twice.
10 GOSUB 100
20 PRINT "FIRST SECTION"
30 GOSUB 100
40 PRINT "SECOND SECTION"
50 END
100 PRINT "----------------"
110 RETURNThis cellular-automaton program demonstrates DIM, two arrays, random initialization, nested loops, array references in conditions, array assignments, GOTO, and repeated generations. It runs continuously because line 350 returns to initialization; use BREAK PROGRAM, the virtual BREAK key, Esc, or Ctrl+C to stop it.
5 LET M = 68
10 DIM X (M)
20 DIM Y (M)
30 FOR I = 0 TO M
40 LET R = RND(1) * 10
50 IF R > 5 THEN 80
60 LET X(I) = 1
70 GOTO 90
80 LET X(I) = 0
90 NEXT I
100 FOR I = 2 TO M-2
110 IF X(I) = 1 THEN 140
120 PRINT " ";
130 GOTO 150
140 PRINT "*";
150 NEXT I
160 PRINT
170 GOTO 200
200 FOR T = 0 TO 25
210 FOR I = 2 TO M-2
220 GOTO 500
230 NEXT I
260 FOR I = 0 TO M
270 LET X(I) = Y(I)
280 IF X(I) = 0 THEN 310
290 PRINT "*";
300 GOTO 320
310 PRINT " ";
320 NEXT I
330 PRINT
340 NEXT T
350 GOTO 30
500 LET C = 0
510 FOR Z = (I-2) TO (I+2)
520 IF Z = I THEN 550
530 IF X(Z) = 0 THEN 550
540 LET C = C + 1
550 NEXT Z
560 IF X(I) = 0 THEN 800
700 LET Y(I) = 0
710 IF C = 2 THEN 750
720 IF C = 4 THEN 750
730 GOTO 230
750 LET Y(I) = 1
760 GOTO 230
800 LET Y(I) = 0
810 IF C = 2 THEN 850
820 IF C = 3 THEN 850
830 GOTO 230
850 LET Y(I) = 1
860 GOTO 230Old magazine and manual listings may use syntax not implemented here. First preserve the original file, then replace unsupported commands one at a time. PEEK/POKE graphics can often be rewritten with PRINT @. Timing loops can become PAUSE. Disk file operations can be replaced by browser ASCII LOAD and SAVE for whole-program storage.
Save frequently under versioned filenames such as LIFE01.BAS, LIFE02.BAS, and LIFE03.BAS. Plain ASCII files are small and easy to archive. Keep a known-working copy before changing loops, branch targets, or array dimensions.
Set the document to plain text and use a monospaced font. Keep line endings consistent. BASIC keywords may be uppercase for a period appearance, although the emulator matches keywords case-insensitively. Do not let smart-quote substitution change straight quotation marks.
Tap the green screen to focus the hidden input control. The on-screen keyboard can enter common keys and function shortcuts. Local file loading and downloading depend on browser file-picker behavior. For long programs, editing on a desktop text editor and transferring the .BAS file is usually more comfortable.
F1 types LIST, F2 RUN, F3 NEW, F4 CLS, F5 PRINT, F6 GOTO, F7 INPUT, and F8 HELP on the on-screen keyboard. BKSP deletes the last input character. ENTER submits. BREAK interrupts execution. Esc interrupts a running program or clears a non-running input line. Ctrl+C interrupts execution.
Core commands: RUN, LIST, NEW, CLEAR, CLS, HELP, MEM, DIR, CATALOG, BASIC, and SYSTEM. Core statements: PRINT, INPUT, LET, DIM, REM, END, GOTO, IF...THEN, GOSUB, RETURN, FOR, NEXT, DATA, READ, RESTORE, and PAUSE. Browser controls add ASCII LOAD, ASCII SAVE, RESET / BOOT, and BREAK PROGRAM.
Numeric functions: ABS, ASN, ACS, ATN, COS, EXP, FACT, FIX, INT, LOG, MAX, MIN, RANDINT, RND, ROUND, SGN, SIN, SQR, and TAN. String-related functions: LEN, ASC, VAL, CHR$, STR$, LEFT$, RIGHT$, MID$, UPPER$, LOWER$, and TRIM$. INKEY$ reports the last key.
ABS, ACS, AND, arrays, ASC, ASN, assignment, BASIC, BREAK, CATALOG, CHR$, CLEAR, CLS, comparisons, COS, DATA, DIM, DIR, E, END, EXP, FACT, factorial, FALSE, FIX, FOR, GOSUB, GOTO.
HELP, IF, INKEY$, INPUT, INT, LEFT$, LEN, LET, LIST, LOG, LOWER$, MAX, MEM, MID$, MIN, MOD, NEW, NEXT, NOT, numeric variables, OR, PAUSE, PI, PRINT, PRINT @.
RANDINT, READ, REM, RESTORE, RETURN, RIGHT$, RND, ROUND, RUN, SAVE ASCII BASIC, SGN, SIN, SQR, STEP, string arrays, string variables, STR$, SYSTEM, TAB, TAN, THEN, TRIM$, TRUE, UPPER$, VAL.
The best way to learn BASIC is to modify working programs. Change constants, add output, place values in arrays, create a subroutine, and intentionally trigger an error so you recognize it later. Save each successful stage. The emulator is designed to make experimentation safe: the BREAK control stops runaway programs, and ASCII files make your work portable.