|
|
|
Here is a short summary of the commands for the built in Commodore 64 BASIC V2. Note that this is not intended to be a tutorial, but just a quick reference to refresh long unused brain cells.
If you are looking for a BASIC tutorial, take a look at the original C64 manual. It is available as etext at: http://project64.c64.org
In C64 BASIC V2 there are only few types of variables:
Only the first TWO (!) characters of a variable name are significant. Thus 'CO', 'COCOS' and 'COLLOSEUM' (but not 'C' and 'CA') are equivalent names for a single variable. On the other hand the type identifier is used to distinguish variables. Therefore 'CO', 'CO%' and 'CO$' are three different variables.
FOR...TO...STEP...NEXT
- The only real loop construct in BASICFOR <Var> = <Start> TO <End> [STEP <Size>]
<Loop Code>
NEXT [<Var>]
FOR I=1 TO 5: PRINT I;: NEXT -> 1 2 3 4 5
FOR I=1 TO 5 STEP 2: PRINT I;: NEXT -> 1 3 5
FOR I=5 TO 1 STEP -2: PRINT I;: NEXT I -> 5 3 1
FOR I=3 TO 1: PRINT I;: NEXT -> 3 (!)
IF...THEN
- Conditional Program ExecutionELSE
or ENDIF
.IF <Condition> THEN <Statements>
orIF <Condition> GOTO <LineNr>
orIF <Condition> THEN <LineNr>
100 IF A < B THEN MN = A: GOTO 120
110 MN = B
120 ....
GOTO
or GO TO
- Unconditional JumpGOTO <LineNr>
orGO TO <LineNr>
GOSUB
- Unconditional Jump to SubroutineGOSUB <LineNr>
10 PRINT "Main Program"
20 GOSUB 100
30 PRINT "Back To Main"
40 GOSUB 100
50 PRINT "Once again Main"
60 END
100 PRINT "This is the Subroutine"
110 RETURN
RETURN
- Return from SubroutineRETURN
GOSUB
ON...GOTO
or ON...GOSUB
- Multiway branch ON <IntegerExpr> GOTO <LineNr1>, <LineNr2>
...ON <IntegerExpr> GOSUB <LineNr1>, <LineNr2>
...
ON X GOTO 100, 200, 300
IF X = 1 THEN GOTO 100
IF X = 2 THEN GOTO 200
IF X = 3 THEN GOTO 300
DEF FN
- Define a BASIC Function/SubroutineDEF FN <Name>(<Param>) = <Single Line Expression>
DEF FN SI(X) = SIN(X)/X
FN SI(π/3) -> 0.816993343
GET
- Read One Character from Standard Input without waitingGET <VarName>
100 GET A$: IF A$ = "" THEN GOTO 100
-> Wait for any Key
INPUT
- Get Data from Standard Input (usually Keyboard)INPUT
[<Prompt>;] <VarName> [, <VarName> ...]
INPUT "LOGIN:"; LG$
INPUT "Please Enter A, B and C"; A, B, C
INPUT A
PRINT
- Write to Standard Output (usually Screen)PRINT <Data>
or? <Data>
PRINT "Hello World"
PRINT "Here", "are", "Tabs" -> Note the ','
PRINT "First Line"; -> Note the ';'
PRINT "Still the same line"
PRINT "Power"; 2*32
SPC
- Advance the Cursor by a specific Number of StepsSPC(<Cnt>)
SPC(6)
TAB
- Advance the Cursor to a Specific PositionTAB(<Place>)
TAB(6)
POS
- Current Cursor PositionPOS(<Dummy>)
LOAD
- Load a Program from Disk or TapeLOAD <FileName> [, <Device> [, <SecondDev>]]
LOAD "SuperGame", 8, 1 -> Absolute Load from Disk #8
LOAD "*", 9 -> Load the first program from Disk #9
LOAD "", 1 -> Load the first program from Tape (#1)
SAVE
- Save a Program to Disk or TapeSAVE <FileName> [, <Device> [, <SecondDev>]]
SAVE "SuperGame", 8 -> Save to Disk #8
@
'
SAVE "@SuperGame",8 -> Save to Disk #8, overwriting an old file
VERIFY
- Check if the Program in Memory and a Program on Disk or Tape are equal. Do not modify anything.VERIFY <FileName> [, <Device> [, <SecondDev>]]
VERIFY "SuperGame", 8 -> Check SuperGame from Disk #8
VERIFY "*", 9 -> Check the first program from Disk #9
VERIFY "", 1 -> Check the first program from Tape #1
OPEN
- Open a FileOPEN <FileID>, <Device> [, <SecondDev> [, <FNameMode>]]
<SecondDev>
is an optional integer in the range 0-15 with the following meaning:
0..Used for LOAD,
1..Used for SAVE,
2-14..Freely usable for User File Access,
15..Command/Error Channel.<FNameMode>
uses the format: "<FileName> [,<FileType> [,<AccessMode>]]"
where <FileType>
is one of P
(Program), S
(Sequential), L
(Relative) or U
(User) and <AccessMode>
is one of R
(Read), W
(Write), A
(Append) or the number of Bytes/Record for Relative Files.
OPEN 1, 4 -> Open a Output File to the Printer #4
OPEN 1, 8, 2, "My File,P,R" -> Open a Program for Reading
OPEN 1, 8, 2, "My File,S,W" -> Open a Sequential File for Writing
OPEN 1, 8, 2, "My File,L,"+CHR$(40) -> Open a Relative File with 40 Bytes/Record
OPEN 1, 8, 15 -> Open the Disk Command/Error Channel
CLOSE
- Close a FileCLOSE <FileID>
CLOSE 1
GET#
- Read One Character from a FileGET# <FileID>, <VarName>
GET#1, A$
GET
' and '#
'.
INPUT#
- Get Data from a FileINPUT# <FileID>, <VarName> [, <VarName>...]
INPUT#1, EN$, ER$, TR$, SC$
INPUT
' and '#
'.
PRINT#
PRINT# <FileID>, <Data>
PRINT#1, "Power64"
PRINT
' and '#
'. Note also that ?#
is not PRINT#
also they look the same in a listing.
CMD
- Redirect Standard Output (Input is not affected) and writes a Message to itCMD <FileID> [, <Message>]
OPEN 1, 4 ; Open a File#1 on Printer#4
CMD 1 ; Make it the standard Output
PRINT "Whatever Output you want"
PRINT "More Output"
PRINT#1 ; Undo CMD 1
CLOSE 1
ST
- Device Status (Built-In Variable)READ
- Read Static Data from DATA Statements in the ProgramREAD <Var> [, <Var>...]
10 RESTORE
20 READ X$
30 PRINT X$;
40 S = 0
50 FOR I=1 TO 3
60 READ X
70 S = S + X
80 NEXT I
90 PRINT S
100 DATA "Power", 12, 34, 18
RESTORE
- Set Pointer to Next DATA element to the first DATA statement in the program.RESTORE
READ
DATA
- Store Static DataDATA <Data> [, <Data>...]
READ
LET
- AssignmentLET <Variable> = <Value>
LET A = 6.25
LET
keyword is not necessary. <Variable> = <Value> is all that is needed. LET
only slows things down -> Don't use it!
DIM
- Array DeclarationDIM <Name>(<Size> [, <Size>...])
DIM A(7)
-> An array of 8(!) elements indexed [0..7]DIM B$(4,5)
-> An array of 30(!) stringsA(3) = 17 : B$(2,3) = "Power64"
+, -, *, /, ^
- Arithmetic Operators9 + 5 * (15 - 1) / 7 + 2^4 -> 35
<, <=, =, <>, >=, >
- Comparison Operators3 <> 6 -> -1 (TRUE)
3 > 4 -> 0 (FALSE)
SIN
- Sine (Argument in Radians)SIN(<Value>)
SIN(π/3) -> 0.866025404
COS
- Cosine (Argument in Radians)COS(<Value>)
COS(π/3) -> 0.5
TAN
- Tangent (Argument in Radians)TAN(<Value>)
TAN(π/3) -> 1.73205081
ATN
- Arcus Tangent (Result in [-π/2 .. π/2])ATN(<Value>)
ATN(1) -> 0.785398163 ( = π/4)
EXP
- Exponent (ex where e = 2.71828183...)EXP(<Value>)
EXP(6.25) -> 518.012825
LOG
- Natural LogarithmLOG(<Value>)
LOG(6.25) -> 1.83258146
SQR
- Square RootSQR(<Value>)
SQR(6.25) -> 2.5
ABS
- Absolute ValueABS(<Value>)
ABS(-6.25) -> 6.25
ABS(0) -> 0
ABS(6.25) -> 6.25
SGN
- Sign SGN(<Value>)
SGN(-6.25) -> -1
SGN(0) -> 0
SGN(6.25) -> 1
INT
- Integer (Truncate to greatest integer less or equal to Argument.)INT(<Value>)
INT(-6.25) -> -7 (!)
INT(-5) -> -5
INT(0) -> 0
INT(5) -> 5
INT(6.25) -> 6
RND
- Random Number in [0.0 .. 1.0]RND(<Seed>)
(<Seed> < 0)
the Random number generator is initialized
RND(-625) -> 3.85114436E-06
RND(0) -> 0.464844882
RND(0) -> 0.0156260729
Recall the encoding of Boolean Values:
FALSE <--> 0 (0x0000) and TRUE <--> -1 (0xFFFF)
or any non-zero value
AND
- Logical & Binary AND<Expr> AND <Expr>
A>5 AND X<=Y
12 AND 10 -> 8 (%1100 AND %1010 = %1000)
OR
- Logical & Binary OR<Expr> OR <Expr>
A>5 OR X<=Y
12 OR 10 -> 14 (%1100 OR %1010 = %1110)
NOT
- Logical & Binary NOTNOT <Expr>
NOT A>5
NOT 2 -> -3 (NOT $0002 = $FFFD)
+
- Concatenate Strings"Pow" + "er64" -> "Power64"
<, <=, =, <>, >=, >
- Comparison Operators"C64" < "Power64" -> -1 (TRUE)
"Alpha" > "Omega" -> 0 (FALSE)
LEN
- StringlengthLEN(<String>)
LEN("Power64") -> 7
LEFT$
- Left part of a stringLEFT$(<String>, <Len>)
LEFT$("Power64", 5) -> "Power"
RIGHT$
- Right part of a stringRIGHT$(<String>, <Len>)
RIGHT$("Power64", 5) -> "wer64"
MID$
- Middle part of a stringMID$(<String>, <Start>, <Len>)
MID$("Power64 for Macintosh", 13, 3) -> "Mac"
/* -- 123456789012345678901 -- */
STR$
- Convert a Number into a StringSTR$(<Value>)
STR$(6.25) -> " 6.25"
STR$(-6.25) -> "-6.25"
VAL
- Convert a String to a NumberVAL(<String>)
VAL("6.25") -> 6.25
VAL("6xx25") -> 6
VAL("x6x25") -> 0
ASC
- ASCII code of the first character of a stringASC(<String>)
ASC("P") -> 80
ASC("Power64") -> 80
CHR$
- Character with a specific ASCII codeCHR$(<Value>)
CHR$(80) -> "P"
PEEK
- Read Byte from MemoryPEEK(<Addr>)
PEEK(53280)
-> Current Frame Color
POKE
- Write Byte to MemoryPOKE <Addr>, <Value>
POKE 53280, 7
-> Yellow Frame
WAIT
- Wait until a Byte in Memory has a specific valueWAIT <Addr>, <Mask> [, <Invert>]
WAIT
will halt the program until ((PEEK(<Addr>) EXOR <Invert>) AND <Mask>) != 0
Invert
> is not specified it is assumed to be 0.
WAIT 198, 255
-> Wait for a key in the key buffer.
SYS
- System - Call a Assembler ProgramSYS <Addr> [, <Param> ...]
USR
- User CommandUSR
(<Param>)
SYS
but the <Addr
> is fixed to $0310
and the first and only <Param
> is already evaluated and stored in FloatAccu1 (FAC1
) when the Assembler Program is called. Less flexible than SYS and thus rarely used.
RUN
- Start the BASIC ProgramRUN [<Line>]
Line
> is given, the program is started on its first line.
RUN
STOP
- Stops program executionSTOP
STOP
is similar to END
, but prints the message BREAK IN <Line>
when executed.
END
- End program executionEND
CONT
- Continue program executionCONT
STOP
, END
or the Run/Stop key, the command CONT
can be used to resume execution.
REM
- RemarkREM <Text>
REM This line contains a comment
LIST
- Display the listing of the current BASIC program LIST [<Line> | <From>- | -<To> | <From>-<To>]
LIST
LIST -40
LIST 100-200
NEW
- Delete the current program and all variables from memoryNEW
NEW
command was accidentally issued, the deleted program can be recovered by using the NEW
Magician described in Section 7.2.
CLR
- Delete all variablesCLR
FRE
- Free MemoryFRE(<Dummy>)
FRE(0)
-> -26627 (immediately after Power-on)
π
- Pi = 3.14159265TI
- Timer Ticks since Power-On (1 Tick = 1/60 Second)TI$
- Timer since Power-On in Hour/Minute/Second FormatTI$
(but not TI) can be assigned a value!
Source: http://www.salto.at/Power64/Documentation/Power64-ReadMe/AA-C64_BASIC.html Power64 Homepage: http://www.infinite-loop.at and http://www.salto.at - EMail: © Roland Lieger, Goethegasse 39, A-2340 Mödling, Austria - Europe Last Changed: Feb. 29, 2008 |