COMMODORE PET BASIC QUICK REFERENCE CARD --------- --- ----- ----- --------- ---- (adapted from Commodore 64 Programmer's Reference Guide from Project 64) Link: Project 64 Page SIMPLE VARIABLES Type Name Range Real XY +/- 1.70141183E+38 +/- 2.93873588E-39 Integer XY% +/- 32767 String XY$ 0 to 255 characters X is a letter (A-Z), Y is a letter or number (0-9). Variable names can be more than 2 characters, but only the first two are recognized. ARRAY VARIABLES Type Name Single Dimension XY(5) Two-Dimension XY(5,5) Three-Dimension XY(5,5,5) Arrays of up to eleven elements (subscripts 0-10) can be used where needed. Arrays with more than eleven elements need to be DIMensioned first. SYSTEM VARIABLES Time TI Display the system clock in jiffy ticks TI$ Display/Set the system time in 24 hour clock format i.e. TI$="030012" ("HHMMSS") I/O Status ST Tape/File access status number. Pi (¼, Pi symbol) Value of Pi. 4.0 BASIC Disk Status DS Reads Current Disk Error Condition from dev 8 DS$ Reads Complete Error Condition to string "##, ERR TXT, Track, Sect" ALGEBRAIC OPERATORS RELATIONAL AND LOGICAL OPERATORS = Assigns value to variable = Equal - Negation < > Not Equal To ^ Exponentiation < Less Than * Multiplication > Greater Than / Division <= Less Than or Equal To + Addition >= Greater Than or Equal To - Substraction NOT Logical "Not" AND Logical "And" OR Logical "Or" Expression equals 1 if true, 0 if false SYSTEM COMMANDS LOAD"NAME" Loads a program from tape SAVE"NAME" Saves a program on tape LOAD"NAME",8 Loads a program from disk SAVE"NAME",8 Saves a program to disk VERIFY"NAME" Verifies that program was SAVEd without errors RUN Executes a program RUN xxx Executes program starting at line xxx STOP Halts execution END Ends execution CONT Continues program execution from line where program was halted PEEK(X) Returns contents of memory location X POKE X,Y Changes contents of location X to value Y SYS xxxxx Jumps to execute a machine language program, starting at xxxxx WAIT X,Y,Z Program waits until contents of location X, when EORed with Z and ANDed with Y, is nonzero. USR(X) Passes value of X to a machine language subroutine can also return value from m/l subroutine (is used like a function i.e. Y=USR(X)) EDITING AND FORMATTING COMMANDS LIST Lists entire program LIST A-B Lists from line A to line B REM Message Comment message can be listed but is ignored during program execution TAB(X) Used in PRINT statement. Spaces X positions on screen SPC(X) PRINTs X blanks on line POS(X) Returns current cursor position EDITING AND FORMATTING KEYS CLR/HOME Positions cursor to left corner of screen SHIFT+CLR/HOME Clears screen and places cursor in "Home" position SHIFT+INST/DEL Inserts space at current cursor position INST/DEL Deletes character at current cursor position CTRL When used with numeric color key, selects text color. May be used in PRINT statement. CRSR keys Moves cursor up, down, left, right on screen SHIFT Access Graphics characters in upper case/graphics mode and upper case characters in upper/lower case mode. ARRAYS AND STRINGS DIM A(X,Y,Z) Sets maximum subscripts for A; reserves space for (X+1)*(Y+1)*(Z+1) elements starting at A(0,0,0) LEN(X$) Returns number of characters in X$ STR$(X) Returns numeric value of X, converted to a string VAL(X$) Returns numeric value of X$, up to first non-numeric character CHR$(X) Returns ASCII character whose code is X ASC(X$) Returns ASCII code for first character of X$ LEFT$(A$,X) Returns leftmost X characters of A$ RIGHT$(A$,X) Returns rightmost X characters of A$ MID$(A$,X,Y) Returns Y characters of A$ starting at character X INPUT/OUTPUT COMMANDS INPUT A$ or A PRINTs "?" on screen and waits for user to enter a string or value INPUT "ABC";A PRINTs message and waits for user to enter value. Can also INPUT A$ GET A$ or A Waits for user to type one-character value; no RETURN needed DATA A,"B",C Initializes a set of values that can be used by READ statement READ A$ or A Assigns next DATA value to A$ or A RESTORE Resets data pointer to start READing the DATA list again PRINT"A= ";A PRINTs string "A=" and value of A ";" suppresses spaces - "," tabs data to next field PROGRAM FLOW GOTO X Branches to line X IF A=1 TO 10 IF assertion is true THEN execute following part of statement. IF false, execute next line number FOR A=1 TO 10 STEP 2 Executes all statements between FOR and corresponding NEXT, with A going from 1 to 10 by 2. Step size is 1 unless specified NEXT A Defines end of loop. A is optional GOSUB 2000 Branches to subtoutine starting at line 2000 RETURN Marks end of subroutine. Returns to statement following most recent GOSUB ON X GOTO A,B Branches to Xth line number on list. If X=1 branches to A, etc. ON X GOSUB A,B Branches to subroutine at Xth line number in list