Back to MrGibson.com
C64 BASIC V2 only.
COMMODORE KEY
The Commodore key performs a number of functions. First, it allows you to move
between the text and graphic display modes.
When the computer is first turned on, it is in the Upper Case/Graphic mode, that
is, everything you type is in upper case letters. As was mentioned, using the key
in this mode will display the graphic on the right side of the keys.
If you hold down the key and key, the display will change to upper and
lower case. Now, if you hold down the key and any other key with a graphic
symbol, the graphic shown on the left side of the key will be displayed.
To get back into the upper case/graphic mode hold down the key and key again.
The second function of the key is to allow you access to a second set of eight
text colors. By holding down the key and any of the number keys, any text now
typed will be in the alternate color available from the key you depressed.
ABS(numeric-experssion)
Returns absolute value. Always a non negative number.
Examples:
100 PRINT ABS(42.3)
100 VV=ABS(-6.124)
AND
The AND command performs two different functions: boolean expressions and
bitwise operations.
Examples:
100 PRINT 3>2 AND 5<6
this example would print -1, meaning "true"
100 PRINT 2=2 AND 3<2
this example would print 0, meaning "false"
ASC (char)
Returns numeric value of a single character.
ATN (number)
The numerical function ATN is a mathematical function that returns the arc
tangent of a numeric value (the inverse function of TAN).
Example:
100 PRINT ATN(1)
CHR$ (number)
CHR$ can be used to convert a number between 0 and 255 into an ASCII character
Note - The following BASIC line:
100 PRINT CHR$(147)
will clear the screen
CLOSE file-device-number
The CLOSE command is used for closing currently opened files or drive number.
Example:
100 CLOSE 4
CLR
CLR deletes all variables, arrays, data read position from DATA lines
CMD
CMD changes the data output from the screen to another peripheral device like
datasette, modem, printer or disk drive.
CMD can be used directly or in programs.
CONT
The CONT command is used to resume execution of a BASIC program, which either
ended in with an END or a STOP command.
COS
COS is a mathematical function which evaluates to the cosine for a given angle,
a number considered to be in radians.
DATA
The DATA command is used to store constant information in the program code, and
is used with the BASIC command READ.
Example:
100 DATA 156,243,311,22,99,500,111,132,101,909,33,35
110 FOR X=0 TO 11
120 READ A
130 PRINT A
140 NEXT
DEF
The DEF commands defines a function with exactly one single numeric argument
which can be executed with FN afterwards.
Example:
100 DEF FN LOG10(X) = LOG(X)/LOG(10)
110 Y = 10
120 Y = Y * 10 : PRINT FN LOG10(Y); " ";
130 IF Y<1E38 THEN 120
DIM
The DIM command allocates space in array memory for a new array.
Example:
100 DIM T(8,1,5)
Example creates a three-dimensional array.
END
Stops the execution of code.
Example:
100 IF X>200 END
EXP (number)
EXP is a mathematical function that evaluates the inverse natural LOG of the
argument.
FN function-name (value)
Executes a function from the DEF
Example:
100 DEF FN LOG10(X) = LOG(X)/LOG(10)
110 Y = 10
120 Y = Y * 10 : PRINT FN LOG10(Y); " ";
130 IF Y<1E38 THEN 120
FOR
The FOR...NEXT loop commands are executed until counter variable equals the
value in the TO clause
Example:
100 FOR X=1 TO 5
110 PRINT X". OUTPUT OF THIS LINE"
120 NEXT X
FRE(number)
FRE accepts any numerical argument within the limits of the floating point
format or any string argument, and returns the number of unused bytes of BASIC
RAM.
GET
GET#
The GET command reads one or more chars from the keyboard cache into a variable.
GET# reads single characters from the specified device or the opened file.
Examples:
100 GET A$
200 IF A$ = "" THEN 100
100 GET#1
200 CLOSE 1
GOSUB line-number
The GOSUB command jumps to a subroutine at the indicated line number. The
subroutine finalizes using a RETURN command.
Example:
100 GOSUB 200
GOTO line-number
The GOTO command makes the BASIC interpreter branch to the indicated line
Example:
100 GOTO 200
IF
The IF command is used to test a "condition". If the condition produces a
non-zero value, the statements after the THEN or GOTO are performed. When the
condition is false then the BASIC interpreter will ignore the rest of the BASIC
commands in the line.
For the condition the following relational operators are useful:
= equal
<> unequal
< less than
> greater
<= less-equal
>= greater-equal
Furthermore, logical operators like AND, OR or NOT can be used to combine several
conditions, and parentheses () to override precedence order.
When the command is GOTO, GOSUB or THEN , the system will perform a branch.
The performance of branches gets progressively worse as the program size grows.
This can be addressed to some degree by understanding the line-lookup process.
Example:
100 IF A$="" OR B$="" THEN 200
In this example, if string A$ OR string B$ is empty, got line 200
INPUT
INPUT#
The INPUT statement allows the program to get data from the user, assigning
that data to a variable. The program will stop, print a question mark (?) on
the screen, and wait for the user to type in the answer and hit RETURN.
INPUT is followed by a variable name, or a list of variable names, separated
by commas. A message may be placed within quote marks, before the list of
variable names to be INPUT. If more than one variable is to be INPUT, they must
be separated by commas when typed.
Example:
100 INPUT "PLEASE ENTER YOUR FIRST NAME ";A$
120 PRINT "ENTER YOUR CODE NUMBER"; : INPUT B
INPUT#
INPUT# is similar to INPUT, but takes data from a previously OPENed file or device.
Example:
100 INPUT# 1 , A
INT (float-number)
INT is used to round numbers, whereas rounding is different from its common
mathematical definition. By positive numbers the fractional part will be cut,
while by neagtive numbers the next lower integer value is returned.
Example:
100 PRINT INT(1.55)
The example will display 1
LET variable = value
LET is hardly ever used in programs, since it is optional, but the statement
is the heart of all BASIC programs. The variable name which is to be assigned
the result of a calculation is on the left side of the equal sign, and the formula on the right.
Example:
100 LET A = 5
120 LET D$ = "HELLO"
MID$ (string,integer,integer)
MID$ is used for cutting strings into component parts inside strings beginning
by the start character (1st integer number) until to the indicated length number
(2nd integer number) from the left side to the right side.
Example:
100 A$="SATURDAY MORNING"
110 B$=MID$(A$,6,3)
120 PRINT B$
In this example, just the word "DAY" is cut and printed
NEW
NEW clears memory of program code.
The command NEW should be used before writing a new BASIC program, because old
program code can conflict with the new BASIC code.
NEXT |variable|
The NEXT command is used with the FOR command to create a loop. The FOR...NEXT
loop commands are executed until counter variable equals the value in the TO
clause
Example:
100 FOR X=1 TO 5
110 PRINT X". OUTPUT OF THIS LINE"
120 NEXT X
NOT
The NOT command will reverse the boolean "true" into "false".
This can be used in IF/THEN construct.
ON
The ON command is part of a structure which jumps to a specific line in the
given list of BASIC.
Example:
100 INPUT "Write an integer number, please "; A
120 PRINT: ON A GOTO 1000,2000,3000
500 END
1000 PRINT "1. jump"
1001 A=A+1: GOTO 120
2000 PRINT "2. jump"
2001 A=A+1: GOTO 120
3000 PRINT "3. jump"
3001 A=A+1: GOTO 120
OPEN
The OPEN command is used for opening a external peripheral device, like a printer,
datassette or disk drive, and for data input and output operations from external
devices.
PEEK(integer)
The PEEK command returns the memory contents of the specified address
Note #1
PEEK(197) can be used to get pressed key on keyboard
Example:
100 A = PEEK(197): IF A=64 THEN 100
110 PRINT "THE PUSHED KEY HAS GOT THE VALUE: "; A
120 IF A=46 THEN END
130 IF A<>0 THEN 100
Note #2:
PEEK can be used to gather joystick information
56321 (Control Port 1) and 56320 (Control Port 2)
Example:
100 joy1=peek(56321)
110 joy2=peek(56320)
POKE address, integer-value
Examples:
100 POKE 53280,1
The example will change the screen frame color to white
100 POKE 53281,1
The example will change the screen background color to white
100 POKE 646,0
The example will change the text color to black
Note:
POKE values can be used to play sound
Voice# /Freq POKE C C# D D# E F F# G G# A A# B C C#
VOICE 1/HIGH 54273 34 36 38 40 43 45 48 51 54 57 61 64 68 72
VOICE 1/L0W 54272 75 85 126 200 52 198 127 97 111 172 126 188 149 169
VOICE 2/HIGH 54280 34 36 38 40 43 45 48 51 54 57 61 64 68 72
VOICE 2/L0W 54279 75 85 126 200 52 198 127 97 111 172 126 188 149 169
VOICE 3/HIGH 54287 34 36 38 40 43 45 48 51 54 57 61 64 68 72
VOICE 3/L0W 54286 75 85 126 200 52 198 127 97 111 172 126 188 149 169
Example:
100 POKE 54273,34:POKE 54272,75
Example plays C note in voice 1
By POKEing the value for a character in the appropriate screen memory location,
that character will be displayed in the proper position.
Example (bouncing ball):
100 REM CLEAR SCREEN
110 PRINT "{CLR/HOME}"
120 REM BG L-GREEN AND YELLOW BORDER
130 POKE 53280,7
135 POKE 53281,13
140 X = 1
145 Y = 1
150 DX = 1
155 DY = 1
160 REM DISPLAY BALL
170 POKE 1024 + X + 40*Y,81
180 LINE 190 SLOW CODE DOWN
190 FOR T = 1 TO 30
195 NEXT
200 POKE 1024 + X + 40*Y,32
210 X = X + DX
220 IF X <= 0 OR X >= 39 THEN DX = -DX
230 Y = Y + DY
240 IF Y <= 0 OR Y >= 24 THEN DY = -DY
250 GOTO 160
POS(dummy value)
The POS function determines the actual position of the cursor between
0 (first, leftmost column) and 79 (last, rightmost column in the second line)
of the logical line on screen. The dummy argument is mandatory, but it does not
have any effect on the result. Usually POS(0) will be used.
PRINT | PRINT# |
The PRINT command is used to print data to the current output device, normally
the screen.
Examples:
100 PRINT "HELLO!"
100 PRINT COS(2)+SQR(2)
100 PRINT "{CONTROL+2}" : REM PRESSING CTL AND 2 ON KEYBOARD
READ variable
The READ command is used to store values into a variable from the DATA command
Example:
100 DATA 156,243,311,22,99,500,111,132,101,909,33,35
110 FOR X=0 TO 11
120 READ A
130 PRINT A
140 NEXT
REM
Program documentation. Documentation can be entered after the statement without
effecting the program.
Example:
100 REM THIS LINE DOES NOTHING
RESTORE
The RESTORE command is used to clear the pointer of the next data value.
The next read data value will be the first data value.
Example:
100 FOR X=0 TO 10
110 READ A(X)
120 PRINT A(X),;
130 NEXT
140 RESTORE
RETURN
Return from branch - see GOSUB
RIGHT$
RIGHT$ is used for cutting strings into component parts beginning at the right
side moving left until the indicated integer number of characters has been
reached.
Example:
100 A$="SATURDAY MORNING"
120 REM CUT OUT MORNING
130 B$=RIGHT$(A$,7)
140 PRINT B$
SQR (numeric-expression)
Returns the square root.
WAIT
The WAIT command waits for a given memory location to match specific bit
constellations.
Example 1:
100 POKE 162,0
200 WAIT 162,64
Example waits for a little over a second.
Example 2:
100 POKE 162,0
110 WAIT 162,32
120 WAIT 162,16
130 WAIT 162,8
140 WAIT 162,4
The example will wait exactly one second because it will first wait 32/60ths,
then 16, 8 and 4 = 60/60ths.