RADIO SHACK–STYLE WEB REFERENCE

TRS-80
MODEL 4
BASIC

PROGRAMMER'S REFERENCE MANUAL
Web Emulator Expanded Edition • Arrays • ASCII Load/Save • Interruptible BREAK
Detailed Command, Function, Math, String, Operator, and Programming Reference
RETURN TO MAIN

Table of Contents

01Welcome to Model 4 BASIC02How to Use This Manual03Starting the Emulator04The READY Prompt05Entering and Editing Program Lines06Direct Mode and Program Mode07RUN08BREAK Program Interrupt09LIST10NEW11CLEAR12CLS13HELP, MEM, DIR, CATALOG, BASIC, SYSTEM14Loading ASCII BASIC Programs15Saving ASCII BASIC Programs16ASCII File Format17PRINT18PRINT with Semicolons19PRINT with Commas20TAB(N)21PRINT @ Position22INPUT23LET and Assignment24REM Comments25END26Multiple Statements with Colon27GOTO28IF...THEN29Comparison Operators30GOSUB and RETURN31FOR...NEXT32STEP33Nested Loops34PAUSE35DATA36READ37RESTORE38Numeric Variables39String Variables40DIM Overview41One-Dimensional Arrays42Multidimensional Arrays43String Arrays44Array Subscripts45Array Errors46Arithmetic Operators47Logical Operators48ABS, INT, FIX, ROUND, SGN49SQR, EXP, LOG50SIN, COS, TAN51ASN, ACS, ATN52MIN and MAX53Factorial54RND and RANDINT55PI, E, TRUE, FALSE56LEN, ASC, VAL57CHR$ and STR$58LEFT$, RIGHT$, MID$59UPPER$, LOWER$, TRIM$60INKEY$61Operator Precedence62Screen Geometry63Character Graphics64Animation65Debugging with PRINT66Debugging GOTO Programs67Debugging Arrays68Avoiding Infinite Loops69Program Structure70Performance and Browser Pacing71Compatibility Notes72Error: ?SN ERROR73Runtime Error Reference74Program: Horizontal Counter75Program: Dice Roller76Program: Guessing Game77Program: Multiplication Table78Program: Prime Number Test79Program: Array Squares80Program: Matrix Fill81Program: String Array Menu82Program: Moving Star83Program: Random Histogram84Program: Data Reader85Program: Subroutine Demonstration86Program: One-Dimensional Life87Adapting Historical Listings88Backing Up Your Programs89Using Notepad++90Mobile and iPad Use91Keyboard Shortcuts92Quick Command Summary93Quick Function Summary94Alphabetical Index A–G95Alphabetical Index H–P96Alphabetical Index Q–Z97Final Notes
Expanded edition: Command, function, array, operator, mathematical, string, screen, file, and execution entries now include purpose, syntax, parameters, detailed behavior, guidance, errors, related entries, and the original runnable examples.
Compatibility notice: this manual describes the web emulator. It is inspired by the TRS-80 Model 4 but is not an archival reproduction of a copyrighted historical manual.
TRS-80 MODEL 4 BASICPAGE 1

Welcome to Model 4 BASIC

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"
Contents1 / 97
TRS-80 MODEL 4 BASICPAGE 2

How to Use This Manual

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.

Contents2 / 97
TRS-80 MODEL 4 BASICPAGE 3

Starting the Emulator

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
RUN
Contents3 / 97
TRS-80 MODEL 4 BASICPAGE 4

The READY Prompt

The 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)
Contents4 / 97
TRS-80 MODEL 4 BASICPAGE 5

Entering and Editing Program Lines

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
20
Contents5 / 97
TRS-80 MODEL 4 BASICPAGE 6

Direct Mode and Program Mode

Direct 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)
Contents6 / 97
TRS-80 MODEL 4 BASICPAGE 7

RUN

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.

Purpose

Starts execution of the numbered BASIC program currently stored in emulator memory.

Syntax

RUN

Parameters and Elements

ElementDescription
RUNDirect command; it does not take a line-number argument in this emulator.

Detailed Description

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.

Programming Guidance

  • Use LIST before RUN after loading or editing a program.
  • Save important changes before experimenting with NEW or reloading another file.
  • Use PAUSE in animation loops so output remains readable and the browser stays responsive.

Common Errors and Limitations

  • RUN reports that no program is in memory when there are no numbered lines.
  • A runtime syntax, array, branch, arithmetic, or DATA error stops execution and displays an error message.

Related Entries

Examples

The original runnable examples are retained below.

10 PRINT "RUNNING"
20 GOTO 10
RUN
Contents7 / 97
TRS-80 MODEL 4 BASICPAGE 8

BREAK Program Interrupt

BREAK 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.

Purpose

Stops a running program without erasing its numbered lines.

Syntax

BREAK PROGRAM buttonVirtual keyboard: BREAKKeyboard: EscKeyboard: Ctrl+C

Parameters and Elements

ElementDescription
BREAK requestAn interrupt flag checked between statements, during paced loops, during PAUSE, and while INPUT is waiting.

Detailed Description

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.

Programming Guidance

  • Use BREAK rather than refreshing the browser, because refreshing can discard an unsaved program.
  • After a break, use LIST and add temporary PRINT statements to locate the loop or branch responsible.
  • A very large single mathematical calculation may not stop until that calculation returns; normal BASIC loops are interruptible.

Common Errors and Limitations

  • BREAK is not an error and does not remove the program.
  • Pressing BREAK while no program is running simply clears the current input line in some interface contexts.

Related Entries

Examples

The original runnable examples are retained below.

10 PRINT "PRESS BREAK"
20 GOTO 10
RUN
Contents8 / 97
TRS-80 MODEL 4 BASICPAGE 9

LIST

LIST 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.

Purpose

Displays every stored numbered program line in ascending numeric order.

Syntax

LIST

Detailed Description

LIST 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.

Programming Guidance

  • Verify branch targets and quotation marks after importing a program.
  • Use line-number gaps such as 10, 20, and 30 to make later insertion easier.

Common Errors and Limitations

  • LIST displays a no-program message when memory contains no numbered lines.

Related Entries

Examples

The original runnable examples are retained below.

Contents9 / 97
TRS-80 MODEL 4 BASICPAGE 10

NEW

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.

Purpose

Deletes all numbered BASIC lines from emulator memory so a new program can be entered.

Syntax

NEW

Detailed Description

NEW 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.

Programming Guidance

  • Use SAVE ASCII BASIC before NEW when the listing has value.
  • Use CLEAR instead when only variables and runtime state need to be reset.

Common Errors and Limitations

  • There is no undo command after NEW.

Related Entries

Examples

The original runnable examples are retained below.

Contents10 / 97
TRS-80 MODEL 4 BASICPAGE 11

CLEAR

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.

Purpose

Resets variables, arrays, DATA position, and active runtime stacks while preserving program text.

Syntax

CLEAR

Detailed Description

CLEAR 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.

Programming Guidance

  • Use CLEAR during direct-mode testing when previous values may affect results.
  • Do not use CLEAR inside a program after DIM unless you intend to remove the arrays.

Common Errors and Limitations

  • Array references made after CLEAR require DIM again.

Related Entries

Examples

The original runnable examples are retained below.

Contents11 / 97
TRS-80 MODEL 4 BASICPAGE 12

CLS

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.

Purpose

Clears the simulated terminal or screen display.

Syntax

CLS10 CLS

Detailed Description

In 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.

Programming Guidance

  • Place CLS near the beginning of display-oriented programs.
  • Frequent CLS in a fast loop may flicker; PRINT @ can update selected positions more smoothly.

Related Entries

Examples

The original runnable examples are retained below.

10 CLS
20 PRINT @ 128,"MODEL 4 BASIC"
Contents12 / 97
TRS-80 MODEL 4 BASICPAGE 13

HELP, MEM, DIR, CATALOG, BASIC, SYSTEM

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.

Purpose

Provides emulator help and period-style simulated system information.

Syntax

HELPMEMDIRCATALOGBASICSYSTEM

Parameters and Elements

ElementDescription
HELPDisplays supported commands, functions, arrays, file controls, and interrupt keys.
MEMReports simulated free memory; the figure is decorative rather than a live JavaScript heap measurement.
DIR / CATALOGDisplays a simulated drive directory.
BASIC / SYSTEMDisplays Model 4 BASIC or TRSDOS-style ready messages.

Detailed Description

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.

Common Errors and Limitations

  • DIR and CATALOG do not enumerate files in the user's iPad, PC, or server directory.
  • MEM should not be used to estimate actual browser memory consumption.

Related Entries

Examples

The original runnable examples are retained below.

Contents13 / 97
TRS-80 MODEL 4 BASICPAGE 14

Loading ASCII BASIC Programs

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.

Purpose

Imports a plain-text BASIC listing from the local device into emulator program memory.

Syntax

Select LOAD ASCII BASICChoose a plain-text file containing numbered BASIC lines

Parameters and Elements

ElementDescription
.BAS / .TXT / other text fileThe filename extension is not part of the BASIC language; the file contents must be readable text.
Numbered lineA line beginning with a decimal line number is stored in the program.

Detailed Description

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.

Programming Guidance

  • After loading, issue LIST before RUN.
  • Use straight ASCII quotation marks rather than typographic quotes.
  • Keep a copy of the original file before adapting a historical listing.

Common Errors and Limitations

  • Unnumbered lines are not stored as program lines.
  • Rich-text documents, word-processing files, and binary tokenized BASIC files are not plain ASCII listings.

Related Entries

Examples

The original runnable examples are retained below.

10 PRINT "LOADED FROM LOCAL PC"
20 END
Contents14 / 97
TRS-80 MODEL 4 BASICPAGE 15

Saving ASCII BASIC Programs

Select 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.

Purpose

Downloads the current numbered listing as a portable plain-text BASIC file.

Syntax

Select SAVE ASCII BASIC

Detailed Description

The 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.

Programming Guidance

  • Use meaningful filenames after the browser download completes.
  • Store master copies in Files, iCloud Drive, OneDrive, or another backed-up location.
  • Plain ASCII files can be edited using Notepad++, VS Code, Textastic, or similar editors.

Common Errors and Limitations

  • An empty program cannot produce a useful listing.
  • Some mobile browsers choose their own download location or filename behavior.

Related Entries

Examples

The original runnable examples are retained below.

Contents15 / 97
TRS-80 MODEL 4 BASICPAGE 16

ASCII File Format

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.

Purpose

Defines the portable, human-readable format used for loading and saving emulator programs.

Syntax

10 PRINT "HELLO"20 END

Parameters and Elements

ElementDescription
Line numberDecimal number at the beginning of each stored program line.
Statement textOne or more BASIC statements following the line number.
EncodingUTF-8 or ordinary ASCII-compatible plain text.

Detailed Description

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.

Programming Guidance

  • Use straight quotes, ordinary spaces, and standard line endings.
  • Avoid editors that silently replace quotes or insert formatting characters.

Common Errors and Limitations

  • A genuine tokenized TRS-80 .BAS disk image may require conversion before this emulator can read it.

Related Entries

Examples

The original runnable examples are retained below.

Contents16 / 97
TRS-80 MODEL 4 BASICPAGE 17

PRINT

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.

Purpose

Writes text, numbers, variables, array elements, or expression results to the emulator display.

Syntax

PRINT "TEXT"PRINT expressionPRINT item1;item2PRINT item1,item2PRINT

Parameters and Elements

ElementDescription
itemA 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 PRINTProduces a blank line or terminates a line previously held open.

Detailed Description

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.

Programming Guidance

  • Use labels such as PRINT "I=";I when debugging.
  • Use PRINT @ for random-access character placement and TAB for column alignment.

Common Errors and Limitations

  • Unbalanced quotation marks or parentheses produce a syntax or expression error.
  • A reference to an undimensioned array causes an array error.

Related Entries

Examples

The original runnable examples are retained below.

PRINT "TOTAL=";A
PRINT X(I)
PRINT
Contents17 / 97
TRS-80 MODEL 4 BASICPAGE 18

PRINT with Semicolons

A 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.

Purpose

Controls horizontal output by placing values directly next to one another and optionally suppressing the newline.

Syntax

PRINT "A";"B"PRINT I;" ";PRINT

Detailed Description

Semicolons 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.

Programming Guidance

  • Add explicit spaces inside quoted strings when separation is desired.
  • Remember that numeric formatting may already include spacing depending on the emulator's formatter.

Common Errors and Limitations

  • Forgetting the final bare PRINT can cause later output to continue on the same line.

Related Entries

Examples

The original runnable examples are retained below.

10 FOR I=1 TO 10
20 PRINT I;" ";
30 NEXT I
40 PRINT
Contents18 / 97
TRS-80 MODEL 4 BASICPAGE 19

PRINT with Commas

A 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.

Purpose

Formats output in fixed-width print zones similar to classic BASIC report columns.

Syntax

PRINT "NAME","SCORE"PRINT A,B,C

Detailed Description

The 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.

Programming Guidance

  • Use TAB(N) for explicit column targets.
  • Test long headings and negative numbers because they may cross a zone boundary.

Related Entries

Examples

The original runnable examples are retained below.

PRINT "NAME","SCORE"
PRINT "RICH",100
Contents19 / 97
TRS-80 MODEL 4 BASICPAGE 20

TAB(N)

TAB(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.

Purpose

Inserts spaces until output reaches a requested character column.

Syntax

PRINT TAB(N);"TEXT"

Parameters and Elements

ElementDescription
NNumeric expression representing the target column.

Detailed Description

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.

Programming Guidance

  • Use modest column values that fit the visible width.
  • Use PRINT @ when a row and column position must be specified independently.

Common Errors and Limitations

  • Negative or nonsensical targets are effectively limited by the generated spacing behavior.

Related Entries

Examples

The original runnable examples are retained below.

PRINT TAB(20);"CENTER AREA"
Contents20 / 97
TRS-80 MODEL 4 BASICPAGE 21

PRINT @ Position

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.

Purpose

Writes text at a specific location in the simulated 64-by-16 character screen memory.

Syntax

PRINT @ position,"TEXT"PRINT @ expression;value

Parameters and Elements

ElementDescription
positionNumeric expression from 0 through 1023; values are wrapped into the screen area.
rowComputed as INT(position/64).
columnComputed as position MOD 64.

Detailed Description

PRINT @ allows menus, scoreboards, and animation without producing a scrolling line for every update. Text overwrites existing characters beginning at the selected position.

Programming Guidance

  • Calculate positions as row*64+column.
  • Erase a moving object by printing spaces at its previous position.

Common Errors and Limitations

  • Very long text can extend beyond the intended row in the emulator's line representation.
  • PRINT @ is an emulator screen feature, not a general browser pixel-graphics command.

Related Entries

Examples

The original runnable examples are retained below.

10 CLS
20 PRINT @ 0,"TOP LEFT"
30 PRINT @ 128,"ROW 2"
Contents21 / 97
TRS-80 MODEL 4 BASICPAGE 22

INPUT

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.

Purpose

Pauses a program and obtains a numeric or string value from the user.

Syntax

INPUT AINPUT A$

Parameters and Elements

ElementDescription
ASingle-letter numeric variable.
A$Single-letter string variable.

Detailed Description

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.

Programming Guidance

  • Print a descriptive prompt immediately before INPUT.
  • Validate ranges after numeric input and branch back when necessary.

Common Errors and Limitations

  • This version accepts one scalar variable per INPUT statement.
  • Array elements and comma-separated input lists are not documented as supported.

Related Entries

Examples

The original runnable examples are retained below.

10 INPUT A
20 PRINT "YOU ENTERED ";A
Contents22 / 97
TRS-80 MODEL 4 BASICPAGE 23

LET and Assignment

LET 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.

Purpose

Stores the result of an expression in a scalar variable or array element.

Syntax

LET A=expressionA=expressionA$="text"X(I)=expressionN$(I)=string-expression

Parameters and Elements

ElementDescription
LETOptional keyword retained for traditional BASIC readability.
destinationNumeric variable, string variable, numeric array element, or string array element.
expressionValue evaluated before storage.

Detailed Description

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.

Programming Guidance

  • Use LET in instructional listings when it makes assignment clearer.
  • Do not confuse equality testing inside IF with assignment at the beginning of a statement.

Common Errors and Limitations

  • Using an array before DIM, using the wrong number of subscripts, or exceeding a bound produces an array error.

Related Entries

Examples

The original runnable examples are retained below.

LET A=10
B=A*2
LET X(I)=B
N$="TRS-80"
Contents23 / 97
TRS-80 MODEL 4 BASICPAGE 24

REM Comments

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.

Purpose

Adds explanatory text to a program without executing it.

Syntax

REM comment text100 REM INITIALIZE ARRAYS

Detailed Description

The 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.

Programming Guidance

  • Explain why code exists rather than merely repeating what the statement visibly does.
  • Use line-numbered comments as section headings in long listings.

Related Entries

Examples

The original runnable examples are retained below.

10 REM INITIALIZE SCREEN
20 CLS
Contents24 / 97
TRS-80 MODEL 4 BASICPAGE 25

END

END 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.

Purpose

Terminates program execution normally.

Syntax

END

Detailed Description

END 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.

Programming Guidance

  • Place END before a block of subroutines when the main path must not fall through into them.

Related Entries

Examples

The original runnable examples are retained below.

100 END
500 REM SUBROUTINES MAY FOLLOW
Contents25 / 97
TRS-80 MODEL 4 BASICPAGE 26

Multiple Statements with Colon

A 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.

Purpose

Places more than one BASIC statement on the same numbered line.

Syntax

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

Detailed Description

The 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.

Programming Guidance

  • Use colons sparingly; one statement per line is easier to debug and document.
  • Do not assume a GOTO target can enter the middle of a multi-statement line; targets select the line's first statement.

Common Errors and Limitations

  • A colon inside an unterminated string may be parsed incorrectly because the quotation itself is invalid.

Related Entries

Examples

The original runnable examples are retained below.

10 A=1: B=2: PRINT A+B
Contents26 / 97
TRS-80 MODEL 4 BASICPAGE 27

GOTO

GOTO 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.

Purpose

Transfers execution unconditionally to a numbered program line.

Syntax

GOTO line-number

Parameters and Elements

ElementDescription
line-numberExisting numbered line that becomes the next execution point.

Detailed Description

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.

Programming Guidance

  • Reserve line-number ranges for major program sections.
  • Use GOSUB for reusable routines that must return.
  • Use BREAK to recover from an accidental endless GOTO loop.

Common Errors and Limitations

  • A nonexistent target produces NO SUCH LINE.
  • Excessive unstructured jumps make maintenance difficult.

Related Entries

Examples

The original runnable examples are retained below.

10 PRINT "AGAIN"
20 GOTO 10
Contents27 / 97
TRS-80 MODEL 4 BASICPAGE 28

IF...THEN

IF 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.

Purpose

Tests a condition and branches to a line number when the condition is true.

Syntax

IF condition THEN line-number

Parameters and Elements

ElementDescription
conditionNumeric expression; zero is false and any nonzero value is true.
line-numberTarget executed only when the condition is true.

Detailed Description

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.

Programming Guidance

  • Use parentheses in compound conditions.
  • Design the fall-through path to be easy to understand.

Common Errors and Limitations

  • This emulator documents THEN followed by a line number, not an arbitrary inline statement.

Related Entries

Examples

The original runnable examples are retained below.

10 IF A>5 THEN 100
20 PRINT "A IS 5 OR LESS"
Contents28 / 97
TRS-80 MODEL 4 BASICPAGE 29

Comparison Operators

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.

Purpose

Compares numeric values and returns 1 for true or 0 for false.

Syntax

A=BA<>BAA<=BA>BA>=B

Parameters and Elements

ElementDescription
=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)
Contents29 / 97
TRS-80 MODEL 4 BASICPAGE 30

GOSUB and RETURN

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.

Purpose

Calls a reusable subroutine and later resumes execution after the call.

Syntax

GOSUB line-numberRETURN

Parameters and Elements

ElementDescription
line-numberFirst line of the subroutine.
RETURNUses the most recently saved return point.

Detailed Description

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.

Programming Guidance

  • Place subroutines after END and give each a REM heading.
  • Ensure every normal subroutine path reaches RETURN.

Common Errors and Limitations

  • RETURN WITHOUT GOSUB occurs when the return stack is empty.
  • A GOSUB target that does not exist produces NO SUCH LINE.

Related Entries

Examples

The original runnable examples are retained below.

10 GOSUB 100
20 END
100 PRINT "SUBROUTINE"
110 RETURN
Contents30 / 97
TRS-80 MODEL 4 BASICPAGE 31

FOR...NEXT

FOR 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.

Purpose

Repeats a block of statements while advancing a numeric control variable.

Syntax

FOR I=start TO finishFOR I=start TO finish STEP incrementNEXT I

Parameters and Elements

ElementDescription
ISingle-letter numeric loop variable.
startInitial numeric value.
finishInclusive ending value.
incrementAmount added each repetition; defaults to 1.

Detailed Description

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.

Programming Guidance

  • Do not modify the loop variable inside the loop unless the altered control behavior is intentional.
  • Use different variables for nested loops.

Common Errors and Limitations

  • NEXT WITHOUT FOR and NEXT VARIABLE MISMATCH indicate a damaged loop structure.
  • A zero STEP can create an endless loop; use BREAK to stop it.

Related Entries

Examples

The original runnable examples are retained below.

10 FOR I=1 TO 10
20 PRINT I
30 NEXT I
Contents31 / 97
TRS-80 MODEL 4 BASICPAGE 32

STEP

STEP 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.

Purpose

Specifies the amount and direction by which a FOR loop variable changes.

Syntax

FOR I=1 TO 10 STEP 2FOR I=10 TO 1 STEP -1

Detailed Description

Positive STEP values count upward; negative values count downward. The finish value remains inclusive. Fractional steps are accepted because variables use floating-point numbers.

Programming Guidance

  • Choose a step sign that moves toward the ending value.
  • Avoid relying on exact equality after many fractional increments.

Common Errors and Limitations

  • A step of zero never moves toward completion and can create an infinite loop.

Related Entries

Examples

The original runnable examples are retained below.

FOR I=10 TO 0 STEP -2
PRINT I
NEXT I
Contents32 / 97
TRS-80 MODEL 4 BASICPAGE 33

Nested Loops

Loops 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.

Purpose

Uses one FOR/NEXT loop inside another to process rows, columns, combinations, or multidimensional arrays.

Syntax

FOR R=0 TO 5 FOR C=0 TO 5 A(R,C)=R*C NEXT CNEXT R

Detailed Description

The 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.

Programming Guidance

  • Use R and C for row and column where that improves readability.
  • Keep NEXT statements visually aligned in files edited outside the emulator.

Common Errors and Limitations

  • Crossing loop structures or closing them in the wrong order produces mismatch errors.

Related Entries

Examples

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 R
Contents33 / 97
TRS-80 MODEL 4 BASICPAGE 34

PAUSE

PAUSE 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.

Purpose

Delays program execution for approximately a specified number of milliseconds while keeping the browser responsive.

Syntax

PAUSE milliseconds

Parameters and Elements

ElementDescription
millisecondsNumeric expression converted to a nonnegative integer delay.

Detailed Description

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.

Programming Guidance

  • Use PAUSE 50 to PAUSE 500 for visible animation, depending on the effect.
  • Do not use PAUSE as a precision timer.

Common Errors and Limitations

  • Browser scheduling, background tabs, and power-saving modes can make the actual delay longer.

Related Entries

Examples

The original runnable examples are retained below.

10 PRINT "TICK"
20 PAUSE 500
30 GOTO 10
Contents34 / 97
TRS-80 MODEL 4 BASICPAGE 35

DATA

DATA 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.

Purpose

Stores constant numeric and string values inside the program for sequential retrieval by READ.

Syntax

DATA 10,20,30DATA "RED","GREEN","BLUE"

Detailed Description

DATA statements are scanned before RUN and placed into a shared data pool. Reaching a DATA line during ordinary execution performs no visible action.

Programming Guidance

  • Keep related data together and document its field order with REM.
  • Use quoted strings when commas or spaces belong to the data text.

Common Errors and Limitations

  • Expressions that depend on changing runtime variables should not be treated as portable DATA constants.

Related Entries

Examples

The original runnable examples are retained below.

10 DATA 10,20,30,"DONE"
Contents35 / 97
TRS-80 MODEL 4 BASICPAGE 36

READ

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.

Purpose

Retrieves the next value from the program's DATA pool.

Syntax

READ AREAD A$

Parameters and Elements

ElementDescription
ANumeric scalar destination.
A$String scalar destination.

Detailed Description

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.

Programming Guidance

  • Match the number and type order of READ statements to DATA items.
  • Use loops when reading repeated records.

Common Errors and Limitations

  • READ PAST END OF DATA occurs after the last available item.

Related Entries

Examples

The original runnable examples are retained below.

10 DATA 5,10,15
20 READ A
30 PRINT A
Contents36 / 97
TRS-80 MODEL 4 BASICPAGE 37

RESTORE

RESTORE 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.

Purpose

Moves the DATA pointer back to the first DATA item.

Syntax

RESTORE

Detailed Description

After RESTORE, the next READ returns the first data value again. This implementation does not document RESTORE with a line-number argument.

Programming Guidance

  • Use RESTORE when the same lookup data must be processed more than once.

Related Entries

Examples

The original runnable examples are retained below.

10 DATA 1,2
20 READ A
30 RESTORE
40 READ B
Contents37 / 97
TRS-80 MODEL 4 BASICPAGE 38

Numeric Variables

Numeric 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.

Purpose

Stores numeric values used in calculations, loops, comparisons, and array subscripts.

Syntax

A=10R=PI/2PRINT A

Detailed Description

Scalar 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.

Programming Guidance

  • Choose mnemonic single letters where possible, such as I for index, R for row or radius, and C for count or column.
  • Use INT or ROUND when an integer result is required.

Common Errors and Limitations

  • A single letter can hold only one scalar value at a time; use DIM when many related values are needed.

Related Entries

Examples

The original runnable examples are retained below.

Contents38 / 97
TRS-80 MODEL 4 BASICPAGE 39

String Variables

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.

Purpose

Stores text values for messages, names, menus, and input.

Syntax

A$="MODEL 4"PRINT A$

Detailed Description

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.

Programming Guidance

  • Use the dollar sign consistently; A and A$ are different variables.
  • Use TRIM$, UPPER$, or LOWER$ to normalize user input.

Common Errors and Limitations

  • Numeric and string expressions are not interchangeable except through VAL and STR$.

Related Entries

Examples

The original runnable examples are retained below.

A$="MODEL "+"4"
PRINT A$
Contents39 / 97
TRS-80 MODEL 4 BASICPAGE 40

DIM Overview

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.

Purpose

Declares numeric or string arrays and establishes their valid subscript ranges.

Syntax

DIM X(68)DIM X (M)DIM A(10,10)DIM N$(20)

Parameters and Elements

ElementDescription
array nameSingle letter, optionally followed by $ for strings.
dimensionInclusive upper bound; DIM X(68) creates elements X(0) through X(68).
multiple dimensionsComma-separated upper bounds for tables or grids.

Detailed Description

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.

Programming Guidance

  • Dimension arrays near the beginning of the program.
  • Match loop limits exactly to declared bounds.
  • Use two arrays when a generation must be calculated without overwriting the current state.

Common Errors and Limitations

  • Negative dimensions, missing bounds, repeated incompatible declarations, or invalid syntax cause DIM errors.

Related Entries

Examples

The original runnable examples are retained below.

5 LET M=68
10 DIM X(M)
20 DIM Y(M)
Contents40 / 97
TRS-80 MODEL 4 BASICPAGE 41

One-Dimensional Arrays

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.

Purpose

Stores an indexed sequence of related values under one array name.

Syntax

DIM X(100)X(I)=valuePRINT X(I)

Detailed Description

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.

Programming Guidance

  • Use FOR I=0 TO upper-bound to initialize every element.
  • Reserve boundary elements when an algorithm needs neighbor access.

Common Errors and Limitations

  • References outside 0 through the upper bound produce SUBSCRIPT OUT OF RANGE.

Related Entries

Examples

The original runnable examples are retained below.

10 DIM X(10)
20 FOR I=0 TO 10
30 X(I)=I*I
40 NEXT I
Contents41 / 97
TRS-80 MODEL 4 BASICPAGE 42

Multidimensional Arrays

Multiple 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.

Purpose

Stores table, matrix, grid, or higher-dimensional data addressed by more than one subscript.

Syntax

DIM A(10,10)A(R,C)=valuePRINT A(R,C)

Detailed Description

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.

Programming Guidance

  • Use nested loops to initialize or display grids.
  • Document which subscript represents rows, columns, layers, or other axes.

Common Errors and Limitations

  • Using too few or too many subscripts produces WRONG NUMBER OF SUBSCRIPTS.

Related Entries

Examples

The original runnable examples are retained below.

10 DIM A(5,5)
20 A(2,3)=99
30 PRINT A(2,3)
Contents42 / 97
TRS-80 MODEL 4 BASICPAGE 43

String Arrays

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.

Purpose

Stores multiple text values that can be selected by a numeric subscript.

Syntax

DIM N$(20)N$(0)="FIRST"PRINT N$(I)

Detailed Description

String arrays are useful for menu labels, names, map rows, messages, and lookup tables. Unassigned elements return an empty string.

Programming Guidance

  • Keep index meanings documented, especially when zero has a special role.
  • Use LEN or TRIM$ when validating stored text.

Common Errors and Limitations

  • The array name must include $ both in DIM and in every reference.

Related Entries

Examples

The original runnable examples are retained below.

10 DIM N$(3)
20 N$(0)="ZERO"
30 PRINT N$(0)
Contents43 / 97
TRS-80 MODEL 4 BASICPAGE 44

Array Subscripts

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.

Purpose

Selects a particular element from an array.

Syntax

X(5)X(I)X(I+1)A(R,C)

Parameters and Elements

ElementDescription
subscript expressionNumeric expression evaluated and truncated to an integer.
valid rangeZero through the corresponding declared upper bound.

Detailed Description

Subscripts can contain variables, arithmetic, and supported numeric functions. They are checked every time an element is read or written.

Programming Guidance

  • Check both ends of neighbor loops; X(I-2) requires I to start at least at 2.
  • Print subscript values during debugging when an out-of-range error is unexpected.

Common Errors and Limitations

  • Negative values and values above the bound produce SUBSCRIPT OUT OF RANGE.

Related Entries

Examples

The original runnable examples are retained below.

X(I+1)=X(I)*2
PRINT A(R,C)
Contents44 / 97
TRS-80 MODEL 4 BASICPAGE 45

Array Errors

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.

Purpose

Explains runtime failures caused by invalid declarations or references.

Syntax

ARRAY NOT DIMENSIONEDWRONG NUMBER OF SUBSCRIPTSSUBSCRIPT OUT OF RANGEBAD DIM STATEMENT

Detailed Description

Array 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.

Programming Guidance

  • Verify DIM executes before the failing line.
  • Print the current subscript and declared limit.
  • Examine loops using TO M versus TO M-1.

Related Entries

Examples

The original runnable examples are retained below.

Contents45 / 97
TRS-80 MODEL 4 BASICPAGE 46

Arithmetic Operators

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.

Purpose

Performs numeric calculations.

Syntax

A+BA-BA*BA/BA^BA MOD BN!

Parameters and Elements

ElementDescription
+Addition
-Subtraction or unary negation
*Multiplication
/Division
^Exponentiation
MODRemainder
!Postfix factorial

Detailed Description

Arithmetic expressions may contain constants, variables, array elements, functions, and parentheses. Normal precedence applies, but parentheses are strongly recommended in mixed expressions.

Programming Guidance

  • Use MOD for periodic behavior and divisibility tests.
  • Use ^ for powers and SQR for square roots.
  • Use factorial only for nonnegative integer-sized values.

Common Errors and Limitations

  • Division or MOD by zero produces a runtime error.
  • Large powers may overflow to browser infinity.

Related Entries

Examples

The original runnable examples are retained below.

PRINT (2+3)*4
PRINT 2^8
PRINT 10 MOD 3
PRINT 5!
Contents46 / 97
TRS-80 MODEL 4 BASICPAGE 47

Logical Operators

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.

Purpose

Combines or reverses truth values represented numerically.

Syntax

condition1 AND condition2condition1 OR condition2NOT condition

Parameters and Elements

ElementDescription
ANDReturns 1 only when both operands are nonzero.
ORReturns 1 when either operand is nonzero.
NOTReturns 1 for zero and 0 for nonzero.

Detailed Description

Logical operations are most commonly used inside IF, but their numeric results can also be assigned or printed.

Programming Guidance

  • Parenthesize each comparison before combining it.
  • Remember that any nonzero value counts as true.

Related Entries

Examples

The original runnable examples are retained below.

PRINT (A>0) AND (A<10)
PRINT NOT 0
Contents47 / 97
TRS-80 MODEL 4 BASICPAGE 48

ABS, INT, FIX, ROUND, SGN

ABS 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.

Purpose

Provides common value-normalization and integer-conversion operations.

Syntax

ABS(X)INT(X)FIX(X)ROUND(X)SGN(X)

Parameters and Elements

ElementDescription
ABSMagnitude without sign.
INTGreatest integer less than or equal to X.
FIXTruncates toward zero.
ROUNDRounds to the nearest integer using browser behavior.
SGNReturns -1, 0, or 1.

Detailed Description

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.

Programming Guidance

  • Use ABS(A-B) for tolerance comparisons.
  • Use INT(RND()*N) carefully; RANDINT is clearer for inclusive integer ranges.

Related Entries

Examples

The original runnable examples are retained below.

PRINT ABS(-25)
PRINT INT(-3.1)
PRINT FIX(-3.9)
PRINT SGN(-8)
Contents48 / 97
TRS-80 MODEL 4 BASICPAGE 49

SQR, EXP, LOG

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.

Purpose

Calculates square roots, exponential values, and natural logarithms.

Syntax

SQR(X)EXP(X)LOG(X)

Parameters and Elements

ElementDescription
SQR(X)Square root; X must be nonnegative.
EXP(X)e raised to X.
LOG(X)Natural logarithm; mathematically requires X greater than zero.

Detailed Description

These functions use the browser's standard mathematical library. They are useful in geometry, growth and decay, statistics, and scientific calculations.

Programming Guidance

  • Check domains before calling SQR or LOG.
  • Use LOG(X)/LOG(10) when a base-10 logarithm is needed.

Common Errors and Limitations

  • SQR of a negative value is explicitly rejected.
  • Invalid logarithm inputs may produce a non-finite browser numeric result.

Related Entries

Examples

The original runnable examples are retained below.

PRINT SQR(144)
PRINT EXP(1)
PRINT LOG(E)
Contents49 / 97
TRS-80 MODEL 4 BASICPAGE 50

SIN, COS, TAN

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.

Purpose

Evaluates the principal trigonometric functions using radians.

Syntax

SIN(X)COS(X)TAN(X)

Parameters and Elements

ElementDescription
XAngle measured in radians.

Detailed Description

Convert degrees with radians=degrees*PI/180. These functions support geometry, oscillation, circular movement, and waveform calculations.

Programming Guidance

  • Store the converted angle in a variable when several trig functions use it.
  • Expect rounding near values that are mathematically zero.

Common Errors and Limitations

  • TAN grows extremely large near odd multiples of PI/2.

Related Entries

Examples

The original runnable examples are retained below.

R=45*PI/180
PRINT SIN(R),COS(R),TAN(R)
Contents50 / 97
TRS-80 MODEL 4 BASICPAGE 51

ASN, ACS, ATN

Inverse trigonometric functions return radians. ASN and ACS expect values in the mathematical domain -1 through 1. ATN accepts any finite numeric value.

Purpose

Returns inverse trigonometric angles in radians.

Syntax

ASN(X)ACS(X)ATN(X)

Parameters and Elements

ElementDescription
ASNArcsine; X normally lies from -1 to 1.
ACSArccosine; X normally lies from -1 to 1.
ATNArctangent; accepts any finite X.

Detailed Description

Multiply the returned radians by 180/PI to obtain degrees. Inverse functions are useful when deriving an angle from a ratio or coordinate relationship.

Programming Guidance

  • Clamp computed ASN or ACS inputs to -1 through 1 when floating-point rounding may exceed the domain slightly.

Related Entries

Examples

The original runnable examples are retained below.

PRINT ATN(1)*180/PI
Contents51 / 97
TRS-80 MODEL 4 BASICPAGE 52

MIN and MAX

MIN 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.

Purpose

Selects the smallest or largest value from a list of numeric expressions.

Syntax

MIN(A,B,...)MAX(A,B,...)

Detailed Description

Every argument is evaluated before the result is selected. These functions are useful for limits, range analysis, clipping, and comparisons among several candidates.

Programming Guidance

  • Use MAX(lower,MIN(value,upper)) to clamp a value into a range.

Common Errors and Limitations

  • Provide at least one valid numeric argument.

Related Entries

Examples

The original runnable examples are retained below.

PRINT MIN(10,20,5)
PRINT MAX(10,20,5)
Contents52 / 97
TRS-80 MODEL 4 BASICPAGE 53

Factorial

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.

Purpose

Calculates the product of all positive integers from 1 through a nonnegative integer.

Syntax

N!FACT(N)

Detailed Description

The argument is truncated to an integer. Both syntaxes use the same implementation. Factorials are used in combinations, permutations, probability, and series expansions.

Programming Guidance

  • Use small values; factorial grows extremely rapidly.
  • 0! and 1! both equal 1.

Common Errors and Limitations

  • Negative values produce NEGATIVE FACTORIAL.
  • Values above 170 produce FACTORIAL TOO LARGE.

Related Entries

Examples

The original runnable examples are retained below.

PRINT 6!
PRINT FACT(6)
Contents53 / 97
TRS-80 MODEL 4 BASICPAGE 54

RND and RANDINT

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.

Purpose

Generates pseudo-random values for games, simulations, sampling, and randomized initialization.

Syntax

RNDRND()RND(X)RANDINT(A,B)

Parameters and Elements

ElementDescription
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.

Detailed Description

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.

Programming Guidance

  • Use RANDINT(1,6) for a die.
  • Use IF RND()<0.5 THEN line for a roughly even choice.
  • Do not use these functions for passwords, encryption, or security.

Related Entries

Examples

The original runnable examples are retained below.

R=RND(1)*10
D=RANDINT(1,6)
Contents54 / 97
TRS-80 MODEL 4 BASICPAGE 55

PI, E, TRUE, FALSE

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.

Purpose

Provides named numeric constants.

Syntax

PIETRUEFALSE

Parameters and Elements

ElementDescription
PIApproximately 3.141592653589793.
EApproximately 2.718281828459045.
TRUENumeric 1.
FALSENumeric 0.

Detailed Description

Named constants make mathematical and logical expressions clearer than embedding approximate decimal values.

Programming Guidance

  • Convert degrees using degrees*PI/180.
  • Use TRUE and FALSE when they improve readability, remembering that BASIC conditions accept any nonzero value as true.

Related Entries

Examples

The original runnable examples are retained below.

Contents55 / 97
TRS-80 MODEL 4 BASICPAGE 56

LEN, ASC, VAL

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.

Purpose

Inspects or converts string data.

Syntax

LEN(A$)ASC(A$)VAL(A$)

Parameters and Elements

ElementDescription
LENNumber of characters.
ASCCharacter code of the first character; zero for an empty string.
VALNumeric conversion of text; invalid text becomes zero.

Detailed Description

These functions help validate input, decode characters, and convert text fields into numbers.

Programming Guidance

  • Use TRIM$ before VAL when input may contain surrounding spaces.
  • Check LEN before relying on ASC of user input.

Related Entries

Examples

The original runnable examples are retained below.

PRINT LEN("MODEL 4")
PRINT ASC("A")
PRINT VAL("123")+7
Contents56 / 97
TRS-80 MODEL 4 BASICPAGE 57

CHR$ and STR$

CHR$(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.

Purpose

Converts between character codes, numbers, and strings.

Syntax

CHR$(N)STR$(N)

Parameters and Elements

ElementDescription
CHR$(N)Character corresponding to the low 8 bits of N.
STR$(N)Text representation of a numeric expression.

Detailed Description

CHR$ is useful for generated characters and simple text protocols. STR$ allows numeric results to participate in string concatenation.

Programming Guidance

  • Use ASC to reverse a CHR$ conversion for ordinary characters.
  • Be aware that browser character behavior is Unicode-based even though CHR$ masks to an 8-bit value.

Related Entries

Examples

The original runnable examples are retained below.

PRINT CHR$(65)
A$=STR$(123)
Contents57 / 97
TRS-80 MODEL 4 BASICPAGE 58

LEFT$, RIGHT$, MID$

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.

Purpose

Extracts a substring from the beginning, end, or middle of a string.

Syntax

LEFT$(A$,N)RIGHT$(A$,N)MID$(A$,START)MID$(A$,START,LENGTH)

Parameters and Elements

ElementDescription
A$Source string expression.
N / LENGTHNumber of characters.
STARTOne-based starting position.

Detailed Description

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.

Programming Guidance

  • Use LEN to determine safe positions.
  • Use MID$ in loops to examine one character at a time.

Related Entries

Examples

The original runnable examples are retained below.

A$="RADIO SHACK"
PRINT LEFT$(A$,5)
PRINT RIGHT$(A$,5)
PRINT MID$(A$,7,5)
Contents58 / 97
TRS-80 MODEL 4 BASICPAGE 59

UPPER$, LOWER$, TRIM$

UPPER$ and LOWER$ change letter case. TRIM$ removes leading and trailing whitespace. They are emulator conveniences useful when comparing input and preparing reports.

Purpose

Normalizes the case and surrounding whitespace of strings.

Syntax

UPPER$(A$)LOWER$(A$)TRIM$(A$)

Detailed Description

These emulator extensions simplify menu input and text processing. UPPER$ and LOWER$ change letter case; TRIM$ removes whitespace at both ends.

Programming Guidance

  • Normalize user input before comparing it with a command word.
  • TRIM$ does not remove spaces inside the string.

Related Entries

Examples

The original runnable examples are retained below.

Contents59 / 97
TRS-80 MODEL 4 BASICPAGE 60

INKEY$

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.

Purpose

Returns the most recently pressed ordinary key without pausing the program.

Syntax

A$=INKEY$

Detailed Description

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.

Programming Guidance

  • Poll INKEY$ inside a paced loop.
  • Use PAUSE to avoid consuming unnecessary CPU while waiting.

Common Errors and Limitations

  • Special browser shortcuts and modifier combinations may not appear as ordinary INKEY$ characters.

Related Entries

Examples

The original runnable examples are retained below.

10 A$=INKEY$
20 IF A$="" THEN 10
30 PRINT A$
Contents60 / 97
TRS-80 MODEL 4 BASICPAGE 61

Operator Precedence

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.

Purpose

Determines the order in which parts of a mixed expression are evaluated.

Syntax

(parentheses)unary sign / NOT^ and !* / MOD+-comparisonsANDOR

Detailed Description

The parser implements precedence rules, but complex expressions are easier to read and safer to port when parentheses explicitly state the desired order.

Programming Guidance

  • Write (A>0) AND (A<10), not A>0 AND A<10.
  • Break very long formulas into intermediate variables.

Common Errors and Limitations

  • Do not rely on precedence that belongs to another BASIC dialect without testing it in this emulator.

Related Entries

Examples

The original runnable examples are retained below.

Contents61 / 97
TRS-80 MODEL 4 BASICPAGE 62

Screen Geometry

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.

Contents62 / 97
TRS-80 MODEL 4 BASICPAGE 63

Character Graphics

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.

Contents63 / 97
TRS-80 MODEL 4 BASICPAGE 64

Animation

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.

Contents64 / 97
TRS-80 MODEL 4 BASICPAGE 65

Debugging with PRINT

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)
Contents65 / 97
TRS-80 MODEL 4 BASICPAGE 66

Debugging GOTO Programs

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.

Contents66 / 97
TRS-80 MODEL 4 BASICPAGE 67

Debugging Arrays

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.

Contents67 / 97
TRS-80 MODEL 4 BASICPAGE 68

Avoiding Infinite Loops

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.

Contents68 / 97
TRS-80 MODEL 4 BASICPAGE 69

Program Structure

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.

Contents69 / 97
TRS-80 MODEL 4 BASICPAGE 70

Performance and Browser Pacing

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.

Contents70 / 97
TRS-80 MODEL 4 BASICPAGE 71

Compatibility Notes

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.

Contents71 / 97
TRS-80 MODEL 4 BASICPAGE 72

Error: ?SN ERROR

?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.

Contents72 / 97
TRS-80 MODEL 4 BASICPAGE 73

Runtime Error Reference

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.

Contents73 / 97
TRS-80 MODEL 4 BASICPAGE 74

Program: Horizontal Counter

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 END
Contents74 / 97
TRS-80 MODEL 4 BASICPAGE 75

Program: Dice Roller

RANDINT produces an integer from one through six. Re-run the program for another roll.

10 CLS
20 PRINT "DICE ROLL: ";RANDINT(1,6)
30 END
Contents75 / 97
TRS-80 MODEL 4 BASICPAGE 76

Program: Guessing Game

This 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 END
Contents76 / 97
TRS-80 MODEL 4 BASICPAGE 77

Program: Multiplication Table

Nested 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 R
Contents77 / 97
TRS-80 MODEL 4 BASICPAGE 78

Program: Prime Number Test

The 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"
Contents78 / 97
TRS-80 MODEL 4 BASICPAGE 79

Program: Array Squares

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 I
Contents79 / 97
TRS-80 MODEL 4 BASICPAGE 80

Program: Matrix Fill

A 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)
Contents80 / 97
TRS-80 MODEL 4 BASICPAGE 81

Program: String Array Menu

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 I
Contents81 / 97
TRS-80 MODEL 4 BASICPAGE 82

Program: Moving Star

PRINT @ 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 P
Contents82 / 97
TRS-80 MODEL 4 BASICPAGE 83

Program: Random Histogram

The 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 D
Contents83 / 97
TRS-80 MODEL 4 BASICPAGE 84

Program: Data Reader

DATA, 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 RESTORE
Contents84 / 97
TRS-80 MODEL 4 BASICPAGE 85

Program: Subroutine Demonstration

A 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 RETURN
Contents85 / 97
TRS-80 MODEL 4 BASICPAGE 86

Program: One-Dimensional Life

This 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 230
Contents86 / 97
TRS-80 MODEL 4 BASICPAGE 87

Adapting Historical Listings

Old 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.

Contents87 / 97
TRS-80 MODEL 4 BASICPAGE 88

Backing Up Your Programs

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.

Contents88 / 97
TRS-80 MODEL 4 BASICPAGE 89

Using Notepad++

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.

Contents89 / 97
TRS-80 MODEL 4 BASICPAGE 90

Mobile and iPad Use

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.

Contents90 / 97
TRS-80 MODEL 4 BASICPAGE 91

Keyboard Shortcuts

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.

Contents91 / 97
TRS-80 MODEL 4 BASICPAGE 92

Quick Command Summary

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.

Contents92 / 97
TRS-80 MODEL 4 BASICPAGE 93

Quick Function Summary

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.

Contents93 / 97
TRS-80 MODEL 4 BASICPAGE 94

Alphabetical Index A–G

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.

Contents94 / 97
TRS-80 MODEL 4 BASICPAGE 95

Alphabetical Index H–P

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 @.

Contents95 / 97
TRS-80 MODEL 4 BASICPAGE 96

Alphabetical Index Q–Z

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.

Contents96 / 97
TRS-80 MODEL 4 BASICPAGE 97

Final Notes

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.

Contents97 / 97