MADE FOR THE NES. READY FOR YOUR IDEAS. NO ACCOUNT NEEDED.
NESBASICBY NDB SOFTWARE

14 THE COMMAND REFERENCE

Find the right word.

All 59 shipped keyword tokens, directly from the bundled guide. THEN, TO, and STEP are syntax fragments.

59 commands and syntax fragments

ABS

Syntax: ABS(N)

Parameters: N: signed integer.

Result: integer.

Example fragment: PRINT ABS(-5)

Absolute value; -32768 has no positive signed 16-bit representation.

Errors: OVERFLOW (9); TYPE MISMATCH (25).

ASC

Syntax: ASC(S$)

Parameters: S$: nonempty string.

Result: integer.

Example fragment: PRINT ASC("A")

First unsigned byte,0–255; does not inspect arbitrary device scan codes.

Errors: BAD ARGUMENT (11) for empty; TYPE MISMATCH (25).

BEEP

Syntax: BEEP

Parameters: No arguments.

Result: statement; no value.

Example fragment: BEEP

Starts/replaces pulse 1 note 69 for 12 emulated frames. Other voices remain.

Errors: SYNTAX ERROR (1) for arguments.

CAT

Syntax: CAT

Parameters: No arguments; direct command.

Result: statement; no value.

Example fragment: CAT

Alias for FILES. Lists six project slots; does not LOAD a project.

Errors: SYNTAX ERROR (1); DIRECT COMMAND ONLY (6).

CHR$

Syntax: CHR$(N)

Parameters: N: integer 0–255.

Result: string.

Example fragment: A$=CHR$(72)+CHR$(73)

Creates exactly one byte, including NUL. A supported byte need not be a printable glyph.

Errors: BAD ARGUMENT (11); TYPE MISMATCH (25); STRING SPACE FULL (26).

CLEAR

Syntax: CLEAR

Parameters: No arguments.

Result: statement; no value.

Example fragment: CLEAR

Resets numeric/string values, control frames and random seed; stops sound/hides sprites. Keeps source and kept artwork.

Errors: SYNTAX ERROR (1).

CLS

Syntax: CLS

Parameters: No arguments.

Result: statement; no value.

Example fragment: CLS

Clears terminal in text mode, canvas in graphics. Does not remove saved source or all hardware sprites.

Errors: SYNTAX ERROR (1).

COLOR

Syntax: COLOR foreground,background

Parameters: Two numeric NES palette indices 0–63, excluding 13/29/45/61.

Result: statement; no value.

Example fragment: COLOR 42,15

One shared foreground/background pair. Text may also use it; sprite palette remains fixed.

Errors: BAD ARGUMENT (11); TYPE MISMATCH (25).

DEMOS

Syntax: DEMOS

Parameters: No arguments; direct command.

Result: statement; no value.

Example fragment: DEMOS

Lists six editable built-in examples. Does not use saved-file slots.

Errors: SYNTAX ERROR (1); DIRECT COMMAND ONLY (6).

EDITSPR

Syntax: EDITSPR art

Parameters: Numeric art ID 8–39; whole direct command.

Result: statement; no value.

Example fragment: EDITSPR 8

32 native 8×8 two-bit patterns. Keep/discard/cancel; KEEP is session-only until project SAVE. No colon continuation.

Errors: BAD ARGUMENT (11); DIRECT COMMAND ONLY (6); SYNTAX ERROR (1).

END

Syntax: END

Parameters: No arguments.

Result: statement; no value.

Example fragment: 30 END

Finishes execution, clears pending control frames and stops sound. Keeps source and final scene.

Errors: SYNTAX ERROR (1).

ERASE

Syntax: ERASE ["NAME" | slot]

Parameters: Direct command; name rules match SAVE, slot 1–6.

Result: statement; no value.

Example fragment: ERASE "DEMO"

Confirmed deletion, alias of KILL; cancel retains the file. Without a name uses PROGRAM.

Errors: FILE NOT FOUND (22); BAD ARGUMENT (11); DIRECT COMMAND ONLY (6).

FILES

Syntax: FILES

Parameters: No arguments; direct command.

Result: statement; no value.

Example fragment: FILES

Lists the six-slot directory, including available/damaged entries. Does not clear working code.

Errors: SYNTAX ERROR (1); DIRECT COMMAND ONLY (6).

FILL

Syntax: FILL x,y[,ink]

Parameters: Numeric seed in local canvas coordinates; ink 0/1, default 1.

Result: statement; no value.

Example fragment: FILL 20,20

SCREEN 1 required. Four-connected bounded flood fill; clipped/already-matching seed is a no-op.

Errors: FILL TOO COMPLEX (21); GRAPHICS MODE REQUIRED (20); BAD ARGUMENT (11); TYPE MISMATCH (25).

FOR

Syntax: FOR A=start TO limit [STEP step]

Parameters: Numeric single-letter variable; numeric expressions; nonzero step, default 1.

Result: statement; no value.

Example fragment: 10 FOR I=1 TO 5

Program loop, inclusive limit; negative/zero-trip loops supported. Shares eight-frame stack with GOSUB.

Errors: BAD ARGUMENT (11) for zero step; CONTROL STACK FULL (18); LOOP VARIABLE IN USE (19); PROGRAM ONLY (16).

GOSUB

Syntax: GOSUB line

Parameters: Literal existing line 1–65535; program statement.

Result: statement; no value.

Example fragment: 10 GOSUB 100

Saves current source location for RETURN, including a colon continuation. Shares eight control frames.

Errors: UNDEFINED LINE (12); CONTROL STACK FULL (18); PROGRAM ONLY (16); BAD LINE NUMBER (3).

GOTO

Syntax: GOTO line

Parameters: Literal existing line 1–65535; program statement.

Result: statement; no value.

Example fragment: 20 GOTO 10

Jumps without saving a return location. A variable/expression is not a line-target substitute.

Errors: UNDEFINED LINE (12); PROGRAM ONLY (16); BAD LINE NUMBER (3).

HELP

Syntax: HELP [page]

Parameters: Direct command; literal page 1–9; omitted means 1.

Result: statement; no value.

Example fragment: HELP 8

Native text reference: strings/input 7, input codes 8, functions/editing 9. It does not open this host PDF.

Errors: BAD ARGUMENT (11); DIRECT COMMAND ONLY (6); SYNTAX ERROR (1).

HIDE

Syntax: HIDE slot

Parameters: Numeric sprite slot 0–63.

Result: statement; no value.

Example fragment: HIDE 0

Safe for an already-hidden slot; permitted in either text or graphics mode.

Errors: BAD ARGUMENT (11); TYPE MISMATCH (25).

IF

Syntax: IF condition THEN line-or-statement

Parameters: Numeric condition; string comparisons produce numeric truth. Program statement.

Result: statement; no value.

Example fragment: 10 IF N$="" THEN PRINT "EMPTY"

Nonzero is true. A false condition skips the rest of its whole line. Inline THEN and literal targets supported; no ELSE.

Errors: PROGRAM ONLY (16); UNDEFINED LINE (12); TYPE MISMATCH (25); syntax/range errors in expressions.

INKEY$

Syntax: INKEY$

Parameters: No arguments or parentheses.

Result: string.

Example fragment: K$=INKEY$

Nonblocking one queued event byte or empty string. In RUN, reserved button edge codes 128–135. Eight-event ring; drop newest on overflow.

Errors: STRING SPACE FULL (26) on temporary exhaustion. Empty is normal; ASC(empty) is not.

INPUT

Syntax: INPUT [prompt;]A or INPUT [prompt;]A$

Parameters: Optional string prompt; one numeric/string variable.

Result: statement; no value.

Example fragment: INPUT "NAME";N$

Uses 95-character line editor. Empty strings valid; numeric empty/invalid retries. String limit 63/shared pool applies.

Errors: BAD INPUT (17); STRING TOO LONG (27); STRING SPACE FULL (26); BREAK (8); TYPE MISMATCH (25).

INT

Syntax: INT(N)

Parameters: N: integer.

Result: integer.

Example fragment: PRINT INT(-7)

Identity in an integer-only language; does not enable fractional literals or floating point.

Errors: TYPE MISMATCH (25); expression syntax/range errors.

JOY

Syntax: JOY(port)

Parameters: Numeric port 1 or 2.

Result: integer.

Example fragment: J=JOY(1)

Held-button sum:1/2/4/8/16/32/64/128. Port 2 returns 0 after optional external-keyboard handshake, until reset.

Errors: BAD ARGUMENT (11); TYPE MISMATCH (25).

KILL

Syntax: KILL ["NAME" | slot]

Parameters: Direct command; name rules match SAVE, slot 1–6.

Result: statement; no value.

Example fragment: KILL 1

Confirmed deletion, alias of ERASE. Numbered slot can explicitly delete a damaged entry. No automatic reclamation.

Errors: FILE NOT FOUND (22); BAD ARGUMENT (11); DIRECT COMMAND ONLY (6).

LEFT$

Syntax: LEFT$(S$,N)

Parameters: String and nonnegative numeric count.

Result: string.

Example fragment: A$=LEFT$("HELLO",2)

Returns up to N bytes from the start. Zero is empty; oversized count clamps to string length.

Errors: BAD ARGUMENT (11); TYPE MISMATCH (25); destination/temporary string limits 26/27.

LEN

Syntax: LEN(S$)

Parameters: String expression.

Result: integer.

Example fragment: A=LEN("HELLO")

Counts bytes, including embedded NUL. Stored variables max 63, but a literal can use the line limit.

Errors: TYPE MISMATCH (25); expression errors.

LET

Syntax: LET variable=expression

Parameters: A–Z numeric or A$–Z$ string variable with matching typed expression.

Result: statement; no value.

Example fragment: LET A$="HELLO"

LET is optional. Independent numeric/string variables; no long identifiers, arrays or implicit conversion.

Errors: TYPE MISMATCH (25); STRING SPACE FULL (26); STRING TOO LONG (27); expression errors.

LINE

Syntax: LINE x1,y1,x2,y2[,ink]

Parameters: Signed numeric endpoints, optional ink 0/1 default 1.

Result: statement; no value.

Example fragment: LINE 0,0,127,63

SCREEN 1; inclusive integer Bresenham line, each point clips to 128×64 canvas. Very long segments can take many frames.

Errors: GRAPHICS MODE REQUIRED (20); BAD ARGUMENT (11); TYPE MISMATCH (25).

LIST

Syntax: LIST

Parameters: No arguments; direct command.

Result: statement; no value.

Example fragment: LIST

Displays tokenized source in numeric order. Long output pages: Start continues, Select cancels.

Errors: DIRECT COMMAND ONLY (6); BREAK (8); BAD PROGRAM (7) if source is invalid.

LOAD

Syntax: LOAD ["NAME"]

Parameters: Direct command; quoted 1–12-character name or default PROGRAM.

Result: statement; no value.

Example fragment: LOAD "HELLO"

Validates source/art before replacement; confirms dirty working data. Clears values, restores saved art. Read versions 2/3.

Errors: FILE NOT FOUND (22); BAD SAVED PROJECT (23); DIRECT COMMAND ONLY (6); BREAK (8).

LOADDEMO

Syntax: LOADDEMO number

Parameters: Literal built-in demo 1–6; direct command.

Result: statement; no value.

Example fragment: LOADDEMO 6

Replaces working source after confirmation if dirty. Retains kept artwork, uses no save slot. Demo 6 is input diagnostic.

Errors: BAD ARGUMENT (11); DIRECT COMMAND ONLY (6); BREAK (8).

LOCATE

Syntax: LOCATE column,row

Parameters: Numeric column 0–27, row 0–21.

Result: statement; no value.

Example fragment: LOCATE 4,3

Sets text output position. Restores text if currently in graphics; graphics surface is cleared in that transition.

Errors: BAD ARGUMENT (11); TYPE MISMATCH (25).

MID$

Syntax: MID$(S$,start[,count])

Parameters: String, numeric positive one-based start, optional nonnegative count.

Result: string.

Example fragment: A$=MID$("HELLO",2,3)

Count defaults to rest. Past end returns empty; count clamps to available bytes.

Errors: BAD ARGUMENT (11); TYPE MISMATCH (25); string destination/temporary limits 26/27.

MOVE

Syntax: MOVE slot,x,y

Parameters: Numeric visible slot 0–63, x 0–255, y 1–239.

Result: statement; no value.

Example fragment: MOVE 0,88,100

SCREEN 1 required; preserves slot artwork. A hidden slot is an invalid MOVE target.

Errors: BAD ARGUMENT (11); GRAPHICS MODE REQUIRED (20); TYPE MISMATCH (25).

NEW

Syntax: NEW

Parameters: No arguments; direct command.

Result: statement; no value.

Example fragment: NEW

Confirms nonempty dirty source; resets program/values, stops sound/hides sprites. Keeps kept artwork. Does not erase saved files.

Errors: DIRECT COMMAND ONLY (6); SYNTAX ERROR (1).

NEXT

Syntax: NEXT A

Parameters: Numeric variable used by the active FOR.

Result: statement; no value.

Example fragment: 40 NEXT I

Advances by STEP and loops or finishes. Active frame must match; variable remains at its post-loop value.

Errors: UNMATCHED LOOP (14); OVERFLOW (9); PROGRAM ONLY (16); TYPE MISMATCH (25).

PRINT

Syntax: PRINT [expression[;|,expression]...]

Parameters: Numeric/string expressions; optional trailing separator.

Result: statement; no value.

Example fragment: PRINT "VALUE=";A

Semicolon joins, comma uses four-column tab stops. Default ends line; trailing separator preserves position. Restores text from graphics.

Errors: OUTPUT TOO LONG (5); TYPE MISMATCH (25); expression errors; BREAK (8) on canceled pages.

PSET

Syntax: PSET x,y[,ink]

Parameters: Signed numeric local coordinates, optional ink 0/1 default 1.

Result: statement; no value.

Example fragment: PSET 64,32

SCREEN 1; set/clear a point in 128×64 canvas. Out-of-canvas coordinates clip to no-op.

Errors: GRAPHICS MODE REQUIRED (20); BAD ARGUMENT (11); TYPE MISMATCH (25).

RECT

Syntax: RECT x1,y1,x2,y2[,ink]

Parameters: Numeric opposite corners, optional ink 0/1 default 1.

Result: statement; no value.

Example fragment: RECT 8,8,119,55

SCREEN 1; outline, not filled rectangle or x/y/width/height. Reversed and degenerate corners supported; clipping applies.

Errors: GRAPHICS MODE REQUIRED (20); BAD ARGUMENT (11); TYPE MISMATCH (25).

REM

Syntax: REM comment

Parameters: Remaining characters on the source line.

Result: statement; no value.

Example fragment: 10 REM A IS THE RUNNING TOTAL

Comment consumes the rest of the line, including colon/keywords. It is not an executable statement separator.

Errors: Physical/source memory bounds still apply.

RETURN

Syntax: RETURN

Parameters: No arguments; matching GOSUB frame.

Result: statement; no value.

Example fragment: 110 RETURN

Resumes the saved source/colon continuation. Natural source EOF with pending GOSUB also reports an invalid return.

Errors: INVALID RETURN (13); PROGRAM ONLY (16).

RIGHT$

Syntax: RIGHT$(S$,N)

Parameters: String and nonnegative numeric count.

Result: string.

Example fragment: A$=RIGHT$("HELLO",2)

Returns up to N bytes from end. Zero returns empty; oversized count clamps to available bytes.

Errors: BAD ARGUMENT (11); TYPE MISMATCH (25); string destination/temporary limits 26/27.

RND

Syntax: RND(N)

Parameters: Numeric N 1–32767.

Result: integer.

Example fragment: A=RND(6)+1

Returns 0 through N-1 using deterministic 16-bit LFSR. Variable reset seeds ACE 1; RUN repeats initial sequence. No RANDOMIZE.

Errors: BAD ARGUMENT (11); TYPE MISMATCH (25).

RUN

Syntax: RUN ["NAME"]

Parameters: Whole direct command; optional quoted saved name.

Result: statement; no value.

Example fragment: RUN "HELLO"

Starts from beginning with reset values. Named form validates/loads source/art and confirms dirty replacement. Does not SAVE.

Errors: FILE NOT FOUND (22); BAD SAVED PROJECT (23); DIRECT COMMAND ONLY (6); runtime errors from program.

SAVE

Syntax: SAVE ["NAME"]

Parameters: Whole direct command; optional quoted name, default PROGRAM.

Result: statement; no value.

Example fragment: SAVE "HELLO"

Six slots, names 1–12 uppercase letters/digits/_/./-. Source and kept art only. Confirm overwrite; wait for SAVED notice. Writes version 3.

Errors: SAVE DIRECTORY FULL (24); BAD PROGRAM (7); DIRECT COMMAND ONLY (6); BREAK (8).

SCREEN

Syntax: SCREEN mode

Parameters: Numeric 0=text,1=graphics.

Result: statement; no value.

Example fragment: SCREEN 1

Graphics start clears canvas/restores tile mapping/default colors. Return to text clears canvas. Hides sprites during screen transition.

Errors: BAD ARGUMENT (11); TYPE MISMATCH (25).

SGN

Syntax: SGN(N)

Parameters: Numeric expression.

Result: integer.

Example fragment: A=SGN(-42)

Returns -1 for negative,0 for zero,1 for positive. No floating-point conversion.

Errors: TYPE MISMATCH (25); expression errors.

SOUND

Syntax: SOUND channel,pitch,duration

Parameters: Numeric channel 1–4; tonal notes 33–96 for 1–3, noise index 0–15 for 4; duration 0–32767 frames.

Result: statement; no value.

Example fragment: SOUND 1,69,60

Asynchronous, replaces selected voice; duration 0 mutes it. Fixed levels; no DMC/samples. NTSC pitch target.

Errors: BAD ARGUMENT (11); TYPE MISMATCH (25).

SPRCOL

Syntax: SPRCOL(a,b)

Parameters: Numeric sprite slots 0–63.

Result: integer.

Example fragment: A=SPRCOL(0,1)

1 when both visible unclipped 8×8 boxes overlap,0 otherwise. Touching edges do not overlap; transparent pixels still count.

Errors: BAD ARGUMENT (11); TYPE MISMATCH (25).

SPRITE

Syntax: SPRITE slot,x,y,art

Parameters: Numeric slot 0–63, x 0–255, y 1–239, art 0–39.

Result: statement; no value.

Example fragment: SPRITE 0,80,100,0

SCREEN 1 required. Native 8×8 hardware sprite; art 0–7 predefined,8–39 kept editable. Eight per scanline.

Errors: BAD ARGUMENT (11); GRAPHICS MODE REQUIRED (20); TYPE MISMATCH (25).

STEP

Syntax: FOR A=start TO limit STEP step

Parameters: Numeric nonzero step in FOR syntax.

Result: grammar fragment.

Example fragment: 10 FOR I=5 TO 1 STEP -1

FOR grammar fragment, not a standalone command. Default step is 1; negative steps supported.

Errors: BAD ARGUMENT (11) for zero step; FOR/control errors.

STOP

Syntax: STOP

Parameters: No arguments.

Result: statement; no value.

Example fragment: 50 STOP

Intentional program termination with control-frame cleanup and sound stop, like END; no CONT command is supplied.

Errors: SYNTAX ERROR (1).

STR$

Syntax: STR$(N)

Parameters: Signed integer expression.

Result: string.

Example fragment: A$=STR$(-42)

Decimal text, minus sign for negatives, no positive leading space. Does not enable decimal fractions.

Errors: TYPE MISMATCH (25); STRING SPACE FULL (26); expression errors.

THEN

Syntax: IF condition THEN line-or-statement

Parameters: Part of IF grammar.

Result: grammar fragment.

Example fragment: 10 IF A=1 THEN PRINT "YES"

Not a standalone command. Literal target or inline statement; false skips whole remainder of line. No ELSE.

Errors: IF/program/target/expression errors.

TILE

Syntax: TILE column,row,id

Parameters: Numeric column 0–31, row 0–29, pattern 0–255.

Result: statement; no value.

Example fragment: TILE 0,0,65

SCREEN 1 native nametable placement, no palette argument. Patterns share; drawing changes referenced canvas patterns.

Errors: BAD ARGUMENT (11); GRAPHICS MODE REQUIRED (20); TYPE MISMATCH (25).

TO

Syntax: FOR A=start TO limit [STEP step]

Parameters: Numeric inclusive limit within FOR.

Result: grammar fragment.

Example fragment: 10 FOR I=1 TO 5

FOR grammar fragment, not a standalone command. Initial value past limit can yield zero trips.

Errors: FOR/program/expression errors.

VAL

Syntax: VAL(S$)

Parameters: String containing whole signed decimal with optional surrounding spaces.

Result: integer.

Example fragment: A=VAL(" -42 ")

Strict parse, not prefix conversion. Empty, trailing garbage and embedded NUL invalid; range -32768…32767.

Errors: BAD ARGUMENT (11); OVERFLOW (9); TYPE MISMATCH (25).

WAIT

Syntax: WAIT frames

Parameters: Numeric 0–32767 emulated frames.

Result: statement; no value.

Example fragment: WAIT 60

Yields interruptibly; zero adds no delay. Counts emulated time, freezes on app pause. Other statements add their own time.

Errors: BAD ARGUMENT (11); TYPE MISMATCH (25); BREAK (8).