VOLUME B -- BASIC QUICK REFERENCE
SC-3000 BASIC Level III-B — part of the SE3K documentation library, also readable inside the emulator.
============================================================================ SC-3000 BASIC LEVEL III-B VOLUME B -- BASIC QUICK REFERENCE ============================================================================ Usage : dictionary -- alphabetical syntax, no examples Level : all References : Vol. A1 (guide with examples) * Vol. D (ML interface) TABLE OF CONTENTS ---------------------------------------------------------------------------- Variable names (naming rules, 2-char limit) ........................... B-1 Commands -- direct mode (alphabetical) .................................. B-2 Commands -- program statements (alphabetical) .......................... B-5 Built-in functions (alphabetical) ..................................... B-14 Operators and precedences ............................................. B-20 System limitations .................................................... B-21 SOUND frequency table ................................................. B-22 Token table (internal codes) .......................................... B-23 SC-3000 ASCII codes ................................................... B-25
VARIABLE NAMES
VARIABLE NAMES ============================================================================ Numeric variable letter followed by zero or more letters/digits X CR NR K4 W1 String variable numeric name followed by $ A$ NAME$ (NAME$ and NA$ are the same: NA$) Array variable name with parenthesised subscript(s) A(n) M(r, c) T(i, j, k) max 3 dimensions +---------------------------------------------------------------------+ | CRITICAL: only the FIRST 2 CHARACTERS of a name are significant. | | All longer names are silently truncated -- no error is reported. | | | | SPEED and SPRITE -> both become SP -> one overwrites the other | | DIM FRR(11) and DIM FRC(11) -> both become DIM FR(11) | | NAME$ and NADDR$ -> both become NA$ | +---------------------------------------------------------------------+ A scalar and an array with the same 2-char prefix can coexist: A = 99 : DIM A(5) -- scalar A and array A(n) are distinct All names are case-insensitive: SCORE = Score = score. See Vol. A1 ch. 2 for naming conventions and conflict-avoidance rules.
COMMANDS -- DIRECT MODE
COMMANDS -- DIRECT MODE ============================================================================ LIST LIST [m][-[n]] -- m=first line, n=last line Display program. SPACE pauses, BREAK stops. LLIST LLIST [m][-[n]] -- Same as LIST but to serial printer. AUTO AUTO [m][, n] -- m=start line (def 10), n=step (def 10) Auto line-number generation. DELETE DELETE m[-n] -- Remove program lines m through n. RUN RUN [m] -- m=start line (default=first). Start execution. CONT CONT -- Resume after STOP or BREAK. LOAD LOAD ["filename"] -- Load program from cassette. SAVE SAVE "filename" -- Save program to cassette (name <= 16 chars). VERIFY VERIFY ["filename"] -- Compare tape file with program in memory. NEW NEW -- Clear program and variables. RENUM RENUM [m1][, m2][, m3] -- m1=new start(def 10), m2=from line(def 1st), m3=step(def 10) Renumber program lines.
COMMANDS -- PROGRAM STATEMENTS
COMMANDS -- PROGRAM STATEMENTS
============================================================================
REM
REM -- Comment; rest of line ignored.
STOP
STOP -- Stop execution; resume with CONT.
END
END -- Terminate program.
LET
LET d=s -- Assign expression s to variable d (LET optional).
PRINT
PRINT [s1{,|;}s2...] -- Display values.
, = tab to next zone; ; = no space; : at end = no newline.
Special: CHR$(&H10)=8x8 font, CHR$(&H11)=16x8 font.
LPRINT
LPRINT [s1{,|;}s2...] -- Same as PRINT but to serial printer.
INPUT
INPUT [d$;]d1[, d2...] -- d$=optional prompt. Read keyboard -> variables.
READ
READ d1[, d2...] -- Read next DATA item(s) into variables.
DATA
DATA c1[, c2...] -- Store constants for READ.
RESTORE
RESTORE [m] -- Reset READ pointer.
DIM
DIM d(n1[, n2, n3])[,...] -- Declare array up to 3 dimensions.
Without DIM, max index=10.
ERASE
ERASE [d1, d2...] -- Invalidate array declarations (all if omitted).
DEF
DEF FN d(x)=z -- Define user function d, argument x, body z.
Up to 8 user functions.
GOTO
GOTO m -- Jump to line number m.
GOSUB
GOSUB m -- Call subroutine at line m.
RETURN
RETURN -- Return from GOSUB. Stack depth <= 15.
ON
ON s GOTO/GOSUB m1[, m2...] -- s=1 -> m1, s=2 -> m2 ...
FOR
FOR m=n1 TO n2 [STEP n3] -- Loop. n3 default=1. Nesting <= 8.
NEXT
NEXT [m1[, m2...]] -- End of FOR loop.
IF
IF r THEN s -- Execute s if r is true (non-zero).
GOTO can be omitted: IF r THEN line#
CONSOLE
CONSOLE [v][, l][, c][, s] -- v=scroll upper (0-22), l=scroll lower (2-24),
c=click sound(1/0), s=small-caps(1/0).
CLS
CLS -- Clear screen.
SCREEN
SCREEN n[, m] -- n=write screen(1=text,2=gfx), m=display screen.
COLOR
COLOR n[, m,(x1, y1)-(x2, y2), b] -- n=colour of bit 1(0-15), m=bit 0,
coords=range for bg colour, b=backdrop colour.
Text mode: only n and m are used.
PATTERN
PATTERN mn, d -- m=C#(text,32-255) or S#(sprite,0-255); n=char code; d=hex string.
16 bytes per char (2 bytes x 8 rows). Odd-byte "*" = repeat.
VRAM $1800-$1FFF (swapped with RAM $8B36-$9335).
CURSOR
CURSOR x, y -- Set cursor position. Text: x=0-37, y=0-24. Gfx: x=0-255, y=0-192.
POSITION
POSITION (x, y), a, b -- Set graphics origin. a=x-dir(0=right,1=left), b=y-dir(0=down,1=up).
PSET
PSET (x, y), c -- Draw pixel at (x, y) colour c(0-15).
PRESET
PRESET (x, y) -- Erase pixel at (x, y).
LINE
LINE [(x1, y1)]-(x2, y2), c[, f] -- Draw line; f=B (box) or BF (filled box).
Omit start to continue from last point.
BLINE
BLINE [(x1, y1)]-(x2, y2)[, c[, f]] -- Erase line/box (colour ignored).
CIRCLE
CIRCLE (x, y), r[, c, l, m, n, o] -- Draw circle/ellipse.
l=aspect ratio, m=start angle(0-1), n=end angle(0-1), o=B/BF.
BCIRCLE
BCIRCLE (x, y), r[, c, l, m, n, o] -- Erase circle (colour ignored).
PAINT
PAINT (x, y), c -- Flood fill enclosed area at (x, y) with colour c.
SPRITE
SPRITE n,(x, y), p, c -- Display sprite n at (x, y), pattern p, colour c(0-15).
MAG
MAG m -- Sprite size: 0=8x8, 1=16x16, 2=8x8 magnified, 3=16x16 magnified.
SOUND
SOUND c, f, v -- PSG output. c=channel(0=mute,1-3=tone,4=white noise,5=periodic noise),
f=frequency (see table), v=volume(0-15).
BEEP
BEEP [m] -- m=0 stop, 1=continuous, 2=single. Omit=single beep.
HCOPY
HCOPY -- Print screen text to serial printer.
Can print: digits, Latin letters (upper+lower), ASCII symbols.
Cannot print: SC-3000 tile/graphic characters, Dieresis chars.
CALL
CALL a -- Call machine code at address a (-32767 to 32767).
POKE
POKE a, d -- Write byte d(0-255) to address a. ROM $0000-$7FFF ignored.
OUT
OUT p, d -- Write byte d(0-255) to I/O port p(0-255).
VPOKE
VPOKE a, d -- Write byte d(0-255) to VRAM address a(0-16383).
MOTOR
MOTOR n -- n=0 CMT motor off, n<>0 on, omit=toggle.
TTL relay-control signal on PPI Port C bit 3 (I/O $DE); the
console emits it on the cassette connector's motor-remote pin.
BUILT-IN FUNCTIONS
BUILT-IN FUNCTIONS ============================================================================ ABS ABS(x) -- Absolute value of x. RND RND(f) -- f=0 init seed, f=1 next random (0 <= r < 1), f=-1 swap seed. SIN SIN(x) -- Sine (x in radians). COS COS(x) -- Cosine (x in radians). TAN TAN(x) -- Tangent (x in radians). ASN ASN(x) -- Arcsine; x in [-1,1]; result in radians. ACS ACS(x) -- Arccosine; x in [-1,1]. ATN ATN(x) -- Arctangent; result in (-pi/2, pi/2). LOG LOG(x) -- Natural logarithm (base e). LGT LGT(x) -- Common logarithm (base 10). LTW LTW(x) -- Binary logarithm (base 2). EXP EXP(x) -- e^x. RAD RAD(x) -- Degrees to radians. DEG DEG(x) -- Radians to degrees. PI PI -- pi = 3.1415926536. SQR SQR(x) -- Square root of x. INT INT(x) -- Largest integer <= x. SGN SGN(x) -- Sign: +1, 0, or -1. ASC ASC(s) -- ASCII code of first character of string s. LEN LEN(s) -- String length. VAL VAL(s) -- Convert numeric string to number. PEEK PEEK(a) -- Read byte from address a (-32768 to 32767). INP INP(p) -- Read byte from I/O port p (0-255). FRE FRE -- Free RAM bytes available. VPEEK VPEEK(a) -- Read byte from VRAM address a (0-16383). STICK STICK(f) -- Joystick f(1=P1,2=P2): 0=none,1=up,2=upR,3=R,4=dnR,5=dn,6=dnL,7=L,8=upL. STRIG STRIG(f) -- Trigger buttons f(1=P1,2=P2): 0=none,1=T1,2=T2,3=both. CHR$ CHR$(x) -- Character for ASCII code x (0-255). HEX$ HEX$(x) -- Convert x (-32768..32767) to hexadecimal string. INKEY$ INKEY$ -- Current key as string, or null string if none pressed. LEFT$ LEFT$(s, x) -- First x characters of string s. RIGHT$ RIGHT$(s, x) -- Last x characters of string s. MID$ MID$(s, x[, y]) -- y chars from position x of s (default: to end). STR$ STR$(x) -- Number x to string. TIME$ TIME$ -- Read/write timer as string "hh:mm:ss". SPC SPC(n) -- Insert n spaces at current print position (PRINT only). Characters in the skipped positions are overwritten. TAB TAB(n) -- Advance print cursor to column n (PRINT only). No effect if cursor already past column n; does not erase.
OPERATORS AND PRECEDENCES
OPERATORS AND PRECEDENCES ============================================================================ Priority Symbol Numeric String Meaning -------- ------ ------- ------ ------------------------------- 1 ^ o x Exponentiation (0^0 = 1) 2 + / - o x Unary sign 3 * / o x Multiply / Divide 4 MOD o x Integer remainder 5 + o o Add / String concatenation 5 - o x Subtract 6 = < > <= >= <> o o Comparison (true=-1, false=0) 7 NOT o x Logical NOT 8 AND o x Logical AND 8 OR o x Logical OR 8 XOR o x Logical XOR
SYSTEM LIMITATIONS
SYSTEM LIMITATIONS ============================================================================ String length (max) 255 characters String workspace area 300 characters Screen input buffer 256 characters Line buffer (tokenised) 256 characters Operator precedence levels 32 levels FOR-NEXT nesting (max) 16 levels -- error [23] if exceeded GOSUB-RETURN nesting (max) 8 levels -- error [21] if exceeded Array dimensions (max) 3 (DIM A(x,y,z)) Numeric range +/-9.9999999999E-99 to +/-9.9999999999E+99 Integer form -32768 to 32767 (&HFFFF = -1 in BASIC) Hexadecimal literal &H0000 to &HFFFF (two's complement, 16-bit) Variable name any length; only first 2 characters significant Line number 1 to 65535 POKE/PEEK address &H8000 to &HFFFF (RAM); ROM &H0000-&H7FFF read-only VRAM address 0 to 16383 (&H0000-&H3FFF) I/O port 0 to 255 (&H00-&HFF) HEX$(x) argument -32768 to 32767 (two's complement hex output) CHR$(x) argument 0 to 255
SOUND FREQUENCY TABLE
SOUND FREQUENCY TABLE ============================================================================ Scale f1 f2 f3 f4 f5 f6 C 131 262 523 1047 2094 C+ 139 277 554 1109 2218 D 147 294 587 1175 2350 D+ 156 311 622 1245 2490 E 165 330 659 1319 2638 F 175 349 698 1397 2794 F+ 185 370 740 1480 2960 G 196 392 784 1568 3136 G+ 208 415 831 1661 3322 A 110 220 440 880 1760 3520 A+ 117 233 466 932 1864 B 123 247 494 988 1976 f1=octave 1 (32'), f2=octave 2 (16'), f3=octave 3 (8'), f4=octave 4 (4'), f5=octave 5 (2'), f6=octave 6 (1'). Frequencies in Hz.
TOKEN TABLE -- STATEMENT KEYWORDS ($17C0)
TOKEN TABLE -- STATEMENT KEYWORDS ($17C0) ============================================================================ ROM format: ASCII bytes + token byte. Range: $82-$E5. Character data $10C0-$17BF (before this table). $82 LIST $83 LLIST $84 AUTO $85 DELETE $86 RUN $87 CONT $88 LOAD $89 SAVE $8A VERIFY $8B NEW $8C RENUM ($8D-$8F: reserved/internal) $90 REM $91 PRINT $91 ? <- alias $92 LPRINT $92 L? <- alias $93 DATA $94 DEF $95 INPUT $96 READ $97 STOP $98 END $99 LET $9A DIM $9B FOR $9C NEXT $9D GOTO $9E GOSUB $9F GO $A0 ON $A1 RETURN $A2 ERASE $A3 CURSOR $A4 IF $A5 RESTORE $A6 SCREEN $A7 COLOR $A8 LINE $A9 SOUND $AA BEEP $AB CONSOLE $AC CLS $AD OUT $AE CALL $AF POKE $B0 PSET $B1 PRESET $B2 PAINT $B3 BLINE $B4 POSITION $B5 HCOPY $B6 SPRITE $B7 PATTERN $B8 CIRCLE $B9 BCIRCLE $BA MAG $BB VPOKE $BC MOTOR ($BD-$BF: reserved/internal) $C0 ^ $C1 * $C2 / $C3 MOD $C4 + $C5 - $C6 <> $C6 >< <- alias $C7 >= $C7 => <- alias $C8 <= $C8 =< <- alias $C9 > $CA < $CB = $CC NOT $CD AND $CE OR $CF XOR ($D0-$DF: reserved/internal) $E0 FN $E1 TO $E2 STEP $E3 THEN $E4 TAB $E5 SPC Unique tokens: 78 Total entries: 83
TOKEN TABLE -- FUNCTION KEYWORDS ($1960)
TOKEN TABLE -- FUNCTION KEYWORDS ($1960) ============================================================================ Stored in tokenised programs as: $80 (prefix) + sub-token. $80 ABS $81 RND $82 SIN $83 COS $84 TAN $85 ASN $86 ACS $87 ATN $88 LOG $89 LGT $8A LTW $8B EXP $8C RAD $8D DEG $8E PI $8F SQR $90 INT $91 SGN $92 ASC $93 LEN $94 VAL $95 PEEK $96 INP $97 FRE $98 VPEEK $99 STICK $9A STRIG ($9B-$9F: unassigned) $A0 CHR$ $A1 HEX$ $A2 INKEY$ $A3 LEFT$ $A4 RIGHT$ $A5 MID$ $A6 STR$ $A7 TIME$ Total: 35 function tokens
SC-3000 ASCII CODES
SC-3000 ASCII CODES ============================================================================ CHR$(x) prints the character with code x. ASC(s$) returns the code of the first character of s$.
A -- Control codes (0-31, &H00-&H1F)
A -- Control codes (0-31, &H00-&H1F) ---------------------------------------------------------------------------- Code Hex Name Effect on cursor / terminal ---- ---- ---- ------------------------------------------------------ 0 &H00 NUL ignored 7 &H07 BEL emits a short beep (same as BEEP) 8 &H08 BS backspace -- cursor left 1 9 &H09 HT tab -- cursor to next tab stop (every 8 columns) 10 &H0A LF line feed -- cursor down 1 row 11 &H0B VT cursor to home (col 0, row 0) 12 &H0C FF clear screen + cursor to home (= CLS) 13 &H0D CR beginning of current line (without advancing) 16 &H10 DLE switch to 8x8 pixel-per-character font 17 &H11 DC1 switch to 16x8 pixel-per-character font (wider) 28 &H1C FS cursor right 1 29 &H1D GS cursor left 1 (= BS) 30 &H1E RS cursor up 1 31 &H1F US cursor down 1 (= LF) Note: codes 1-6, 14-15, 18-27 produce no known visible effect.
B -- Printable ASCII (32-127, &H20-&H7F)
B -- Printable ASCII (32-127, &H20-&H7F)
----------------------------------------------------------------------------
Identical to the standard US-ASCII set. Grid with column/row offset:
_0 _1 _2 _3 _4 _5 _6 _7 _8 _9 _A _B _C _D _E _F
2_ SP ! " # $ % & ' ( ) * + , - . /
3_ 0 1 2 3 4 5 6 7 8 9 : ; < = > ?
4_ @ A B C D E F G H I J K L M N O
5_ P Q R S T U V W X Y Z [ \ ] ^ _
6_ ` a b c d e f g h i j k l m n o
7_ p q r s t u v w x y z { | } ~ DEL
Reading: row 2_ col _0 = code &H20 = 32 = space.
row 4_ col _1 = code &H41 = 65 = 'A'.
C -- Extended characters (128-255, &H80-&HFF)
C -- Extended characters (128-255, &H80-&HFF) ---------------------------------------------------------------------------- Codes 128-255 depend on the ROM revision and the active keyboard mode (KANA, GRAPH). &H80-&H9F (128-159) SC-3000 special graphic characters: block graphics symbols, extended punctuation, box-drawing characters. Accessible via the GRAPH key + letter. &HA0-&HDF (160-223) Half-width Katakana (Japanese version). Corresponds to the JIS X 0201 standard (Katakana subset). Accessible via the KANA key. &HA1 ヲ &HA2 ァ &HA3 ィ &HA4 ゥ &HA5 ェ &HA6 ォ &HA7 ャ &HA8 ュ &HA9 ョ &HAA ッ &HAB ー &HAC ア &HAD イ &HAE ウ &HAF エ &HB0 オ &HB1 カ &HB2 キ &HB3 ク &HB4 ケ &HB5 コ &HB6 サ &HB7 シ &HB8 ス &HB9 セ &HBA ソ &HBB タ &HBC チ &HBD ツ &HBE テ &HBF ト &HC0 ナ &HC1 ニ &HC2 ヌ &HC3 ネ &HC4 ノ &HC5 ハ &HC6 ヒ &HC7 フ &HC8 ヘ &HC9 ホ &HCA マ &HCB ミ &HCC ム &HCD メ &HCE モ &HCF ヤ &HD0 ユ &HD1 ヨ &HD2 ラ &HD3 リ &HD4 ル &HD5 レ &HD6 ロ &HD7 ワ &HD8 ン &HD9 ゙ &HDA ゚ &HDB-&HDF: reserved &HE0-&HFF (224-255) Additional graphic characters and special symbols. Exact content depends on the ROM revision.
D -- Keyboard -> ASCII code mapping
D -- Keyboard -> ASCII code mapping ---------------------------------------------------------------------------- The lookup tables used by BASIC to convert the keyboard matrix code to ASCII code are located in ROM at the following addresses: $3FA0 Normal characters (alphanumeric + symbols) $3FE0 SHIFT + key $4020 KANA (Katakana) $4060 SHIFT + KANA $40A0 GRAPH (graphic characters) $40E0 SHIFT + GRAPH $4120 CTRL + key (produces codes 1-31) $4160 FUNC function keys (ends at $4298) The KEYREAD routine ($4918) scans the matrix; BASIC then uses the lookup table corresponding to the active modifier combination. ============================================================================