Cheesecake BASIC v2 Documentation



Users Guide


Contents:

 

Starting Cheesecake BASIC.

From the windows console:

At the console prompt (e.g. C> ) type the following:
CCBASIC
And press the enter key.

Note that the file ccbasic.exe must be in the current directory or in a directory specified in the PATH environment variable.

From a link icon:

Click the icon for the Cheesecake BASIC interpreter.

After Cheesecake BASIC initializes, it will display the following prompt:

READY

That means Cheesecake BASIC is ready to take your commands.

 

Summary of interpreter commands.

BRK line

Sets a breakpoint at the specified line number

BYE

Exits the interpreter.

CBRK [line]

Clears the specified breakpoint. If no line number is specified, all breakpoints in the program are cleared.

CONT

Resumes a program after a STOP statement is executed or a breakpoint is hit.

LIST [line [-line]]

Lists the program.

LOAD "path"

Loads a program.

NEW

Re-initializes the interpreter.

RENUM [increment]

Renumbers the program lines. If no increment is specified, the default is 10.

RUN

Runs the program.

SAVE "path"

Saves the program under the given name

TRACE {ON | OFF}

Sets trace mode on or off.

 

 

Loading and saving programs.

Loading a program

Programs are loaded into Cheesecake BASIC with the LOAD command. The syntax of the LOAD command is:

LOAD "name-of-program"

The name of the program must include any extensions (e.g. .BAS) and must be inside double quotes.  The program must be an ASCII file containing BASIC program lines, BASIC statements, or interpreter commands.

Saving a program

The current program can be saved to a file using the SAVE command. The syntax of the SAVE command is:

SAVE "name-of-program"

The name of the program must include any extensions (e.g. .BAS) - Cheesecake BASIC will not add any default extension - and it must be inside double quotes. Files are saved in text (ASCII) form.

 

 

Editing programs.

Cheesecake BASIC has a line-based editor similar to other BASIC interpreters.

Using the Cheesecake BASIC editor

The Cheesecake BASIC editor is a line-based editor. All lines must begin with a line number. The line number determines the position of the line within the file.

To add a line

Enter the line number followed by the BASIC line.

e.g: 50 PRINT "Hello world"

 

To replace a line

Enter the line number followed by the BASIC line. If there is a line with the same line number, it will be replaced. If there is no line with the same line number, it will be added (see above).

e.g. 50 PRINT "Good bye"

 

To delete a line

Enter a line number. If there is a line with the same line number, it will be deleted. If there is no line with the same line number, no action will be taken.

e.g. 50

 

To list lines

Use the LIST command to list line ranges. E.g.

LIST 10-80
will display all program lines from 10 to 80 (both inclusive).

LIST 80-
will display all program lines starting with line 80

LIST
will display all program lines.

 

To renumber lines

Use the RENUM command. The syntax of the RENUM command is:
RENUM [increment]
This will renumber all lines using the increment given. The default increment is 10. All line number references (e.g. GOTO, GOSUB etc) are fixed to match the new line numbers.

 

Running programs.

The current program can be executed with the RUN command. The syntax of the RUN command is:

RUN

This will run the program until the program executes an END or STOP statement, an unhandled error is encountered, or a breakpoint it hit.

 

Debugging.

Cheesecake BASIC provides the following debugging support:

TRACE

When executing in trace mode, the interpreter displays each source line before the line statements are executed. Trace mode is turned on or off using the TRACE statement, with the following syntax:

TRACE {ON | OFF}

After a TRACE ON statement, each source line is displayed before being executed. This continues until the program terminates or until a TRACE OFF statement is executed. If you want to trace the entire program, you can execute a TRACE ON before running the program. If you want  to trace only a portion of a program, you can enclose the program portion between TRACE ON and TRACE OFF statements.

STOP

STOP statements can be placed in the program at places where you want the interpreter to stop program execution. When a STOP statement is executed, the interpreter stops executing the program. The user can then display the value of variables (using PRINT statements), change the value of variables (using LET statements) etc. To resume a stopped program, use the CONT command.

Breakpoints

Breakpoints can be used to stop execution of a program at a specific line without needing to add STOP statements to the program. When execution reaches that line, the interpreter stops executing the program. The user can then use immediate BASIC statements to display the value of variables, change variables etc. The program can resume execution using the CONT command.

Setting breakpoints:

To set a breakpoint, use the BRK command, with the following syntax:

BRK <Line number>

Clearing breakpoints:

To clear a breakpoint, use the CBRK command, with the following syntax:

CBRK [Line number]

If no line number is specified, CBRK will clear ALL the breakpoints in the program.

To continue execution of a program after a breakpoint is hit or a STOP statement is executed:

To continue execution of a program, use the CONT command, with the following syntax:

CONT

The CONT command can also be used after the program executes a STOP statement.

 

Executing immediate commands.

BASIC statements that are not part of a program line (i.e. a line starting with a line number) are executed immediately by the interpreter.

E.g.

READY
DIM A$(2)
READY
A$(2) = "Hello world!"
READY
PRINT A$(2)
Hello world!
READY

 

Exiting the interpreter.

To exit the interpreter use the BYE command. The syntax of the BYE command is:

BYE

 

 

Language Reference


Contents:

 

Data types

Cheesecake BASIC supports the following data types:

INTEGER

16-bit signed integer
Suffix: %

SINGLE

32-bit floating point
Suffix: !

STRING

String.
Suffix: $

If an identifier does not include a type-specifier suffix, the default type is SINGLE.

You can control the default data type of variables and arrays based on the first character of their identifier, by using the DEFINT, DEFSNG, or DEFSTR statements.

 

Program Lines

All lines in a Cheesecake BASIC Program must be numbered. Line numbers must be between 1 and 32767.

 

Statements

Cheesecake BASIC allows statements to be separated by colons. E.g.:

10 BEEP : PRINT : PRINT "Hello World" : PRINT : END

Note the following exception:

DATA statements must be the ONLY statement in their line. In the following example, line 10 is a valid Cheesecake BASIC line, but lines 20 and 30 are not:

10 DATA a, b, c
20 PRINT : DATA a, b, c
30 DATA a, b, c ' This is the data

Following is the list of Cheesecake BASIC statements:

BEEP

CHDIR "path"

CLOSE [#]filenumber

CLS

COLOR fg [,bg]

DATA constant [,constant]*

DEF name(args) = expression

DEFINT letter range [. letter range]*

DEFSNG letter range [. letter range]*

DEFSTR letter range [. letter range]*

DIM arrayname(size [,size]*) [, arrayname(size [,size]*)]*

Note: Arrays that are not explicitly dimensioned in a DIM statement are by default created as a one-dimensional array of 10 elements.

END

ERROR errornumber

EXIT [FOR | WHILE]

FIELD #filenumber, integer as fieldname [,integer as fieldname]*

FOR id=firstvalue TO lastvalue [STEP increment]

GET #filenumber

GOSUB linenumber

GOTO linenumber

IF exp THEN statements [ELSE statements]

INPUT [#filenumber,] [prompt {,|;}] var [,var]*

KEY(keynumber) {ON | OFF | STOP}

KILL "path"

[LET | LSET | RSET] var = exp

LINE INPUT [#filenumber,] [prompt {,|;}] var [,var]*

LOCATE x, y

NEXT [id]

ON ERROR GOTO linenumber

ON exp GOSUB linenumber [,linenumber]*

ON exp GOTO linenumber [,linenumber]*

ON KEY(keynumber) GOSUB linenumber

ON TIMER(seconds) GOSUB linenumber

OPEN filename [FOR {INPUT|OUTPUT|APPEND|RANDOM}] as #filenumber [LEN=length]

PRINT [#filenumber,] print-list

PUT #filenumber

RANDOMIZE [exp]

READ var [,var]*

REM (or apostrophe) [comments]

RESTORE [linenumber]

RESUME [NEXT | linenumber]

RETURN [linenumber]

SEEK #filenumber, recordnumber

SHELL "command"

SLEEP seconds

STOP

TIMER {ON | OFF | STOP}

WEND

WHILE exp

Cheesecake BASIC for DOS also supports the following statements:

CIRCLE [STEP] (x,y), radius [, color [,start, end [,aspect]]]

DEF SEG[=value]

DRAW string-expression

LINE [STEP] [(x,y)] - [STEP] (x,y) [, [color][,B[F]]]

OUT port-no, value

PLAY string-expression

POKE address, value

PRESET [STEP] (x,y) [,color]

PSET [STEP] (x,y) [,color]

SCREEN [mode] [, [color] [, [apage] [, [vpage]]]]

SOUND freq, duration

VIEW [SCREEN] (x,y) - (x,y) [. [color [, [boundary]]]

WINDOW [SCREEN] (x,y) - (x,y)

 

Functions

ABS

Returns the absolute value of a numeric expression.
ABS( numeric expression )

ASC

Returns the ASCII code of the first character in a string.
ASC( string expression )

ATN

Returns the arctangent of a numeric expression.
ATN( numeric expression )

CHR$

Converts an ASCII code into a one-character string.
CHR$( numeric expression )

CINT

Converts a numeric expression into an integer by rounding the fractional part of the expression.
CINT( numeric expression )

COS

Returns the cosine of a numeric expression.
COS( numeric expression )

CURSORX

Returns the horizontal position of the cursor.
CURSORX

CURSORY

Returns the vertical position of the cursor.
CURSORY

CVI

Converts a string containing an integer into an INTEGER.
CVI( 2-byte string )

CVS

Converts a string containing an single into an SINGLE.
CVS( 4-byte string )

DATE$

Retrieves the system date.
DATE$

EOF

Returns non-zero if the end of the file has been reached, zero otherwise.
EOF( file number )

ERL

Returns the error line of the last error.
ERL

ERR

Returns the error code of the last error.
ERR

ERT$

Returns the error text of the last error.
ERT

EXP

Returns the base e (2.7182..) raised to a power.
EXP( numeric expression )

FIX

Truncates a number to an INTEGER.
FIX( numeric expression )

INKEY$

Reads a character from the keyboard.
INKEY$

INSTR

Returns the position of a substring within a string.
INSTR( main-string, substring )

INT

Returns the largest integer less than or equal to a numeric expression.
INT( numeric expression )

LCASE$

Lowercases a string.
LCASE$( string expression )

LEFT$

Returns the leftmost n characters of a string.
LEFT$( string expression, numeric expression )

LEN

Returns the length of a string.
LEN( string expression )

LOC

Returns the current position within a file.
LOC( file number )

LOF

Returns the length of a file.
LOF( file number )

LOG

Returns the natural (base e) logarithm of a number.
LOG( numeric expression )

LTRIM$

Returns a string with leading spaces removed.
LTRIM$( string expression )

MID$

Returns a portion of a string.
MID$( string expression, start [, length ] )

MKI$

Converts an integer to a 2-byte string.
MKI$( numeric expression )

MKS$

Converts a single to a 4-byte string.
MKS$( numeric expression )

RIGHT$

Returns the rightmost n characters of a string.
RIGHT$( string expression, numeric expression )

RND

Return a random number between 0 and 1.
RND

RTRIM$

Returns a string with traling spaces removed.
RTRIM$( string expression )

SEEK

Returns the current position within a file.
SEEK( file number )

SGN

Returns the sign of a number.
SEEK( numeric expression )

SIN

Returns the sine of a numeric expression.
SIN( numeric expression )

SPACE$

Returns a string consisting of n spaces.
SPACE$( numeric expression )

SQR

Returns the square root of a number.
SQR( numeric expression )

STR$

Returns the string representation of a number.
STR$( numeric expression )

STRING$

Returns a string consisting of multiple copies of a character.
STRING$( numeric expression, string expression )

TAB

Used only in PRINT statements, moves the print head to the specified column.
TAB( numeric expression )

TAN

Returns the tangent of a numeric expression.
TAN( numeric expression )

TIME$

Retrieves the system time.
TIME$

TIMER

Returns the number of seconds since midnight.
TIMER

UCASE$

Uppercases a string.
UCASE$( string expression )

VAL

Converts a string to a number.
VAL( string expression )

Cheesecake BASIC for DOS also supports the following functions:

INP

Reads a byte from an I/O Port.
INP( numeric expression )

PEEK

Returns the byte at the specified memory address.
Peek( numeric expression )

POINT

Returns the color of a screen pixel.
POINT( x, y )

SCREEN

Returns the ASCII code of the character at the specified screen location.
SCREEN( row, column )