08 NES BASIC PROGRAMMING GUIDE
Functions you can rely on
ABS(N) returns absolute value; ABS(-32768) overflows. INT(N) returns the same integer. SGN(N) returns -1, 0 or 1. RND(N) requires N from 1 to 32767 and returns 0 through N-1. The ROM's deterministic 16-bit generator starts from seed ACE1 when values reset. RUN repeats that initial sequence; there is no host-random number dependency or RANDOMIZE statement. Use RND(6)+1 for values 1–6.
ASC(S$) returns the first byte of a nonempty string. ASC("A") is 65, ASC("0") is 48 and ASC(" ") is 32. ASC("") raises BAD ARGUMENT. CHR$(N) creates one byte for N=0–255, including zero. Every value in that domain round-trips through ASC(CHR$(N)). A valid byte is not necessarily a visible glyph; reserved button bytes and control bytes are data, not printable ASCII. CHR$ does not discover hardware key codes.
LEN counts string bytes, including embedded NUL. LEFT$/RIGHT$ take a nonnegative count and clamp it to available bytes. MID$ uses a positive one-based start and optional nonnegative count; omitted count means the rest. A start past the end returns empty. Negative counts or start zero raise BAD ARGUMENT.
STR$ produces ordinary signed decimal without a leading space for positive numbers. VAL accepts a whole signed decimal with optional surrounding spaces. VAL("12X"), VAL("") and embedded NUL are invalid; out-of-range values overflow. These are not floating-point conversion routines. Function arguments retain their types; LEN(42), for example, raises TYPE MISMATCH.
INKEY$ has no parentheses. It returns one queued byte or an empty string immediately. It reads events while a program runs; a direct idle read normally returns empty. The controller-event table and focus rules are in Chapter 11. JOY(port) returns held-state masks and SPRCOL(a,b) returns a box-collision result; those numeric functions are described with sprites below and in the reference.