EBasic Language Reference

General Commands

NEW

Clears current program and variables from memory.

LIST

Lists the contents of the program in memory.

RUN

This will make the computer begin running the program that has been entered into memory. (Executing as another word for running).

HELP

This returns debug information, including the values of all defined variables in the current program. Also prints the firmware version of the computer.


Jumps

GOTO <line number>

Jump to the specified line number

GOSUB <line number>

Just to the specified line number and return to the line following the GOSUB then the RETURN command is encountered.

RETURN

Return to the line following the last GOSUB that was executed.


Input Output

Print <expr>

Output the evaluation of the expression to the screen.
Adding the optional semicolon to the expression will stop the cursor moving to the next line.

The example below will print "EXACTLY"

10 PRINT "EXACT";
20 PRINT "LY"

While the example below will print "EXACT" and "LY" on separate lines.

10 PRINT "EXACT"
20 PRINT "LY"

Input "Input message",variable1 |,variable2..

Take input from the keyboard after first printing the "Input Message"
More than one variable can be included. Input will read lines from the keyboard until each variable is assigned.

BEEP <duration>,<pitch>

Play a sound in milliseconds and hz.

INKEY(<duration>)

Waits for a single key to be pressed on the keyboard for the duration specified (in hundredths of seconds) If no key is pressed in that time, an empty string is returned.


Time and delays

WAIT <duration>

Wait for the specified number of milliseconds

The example below will wait for one second

WAIT 1000

TIME()

This returns the current of milliseconds since the computer was last restarted.

It can be used for simple interval calculations

PRINT TIME()

Loops

FOR <variable> = <start> TO <end> STEP <step>

Execute the code between the FOR line and the enclosing NEXT command until the declared variable is equal or greater than the <end> value. The control variable will be incremented by <step> which is optional. If <step> is omitted, a default value of 1 will be used.

NEXT

Jump back to the nearest FOR loop unless the control variable has reached the end point.

REPEAT

Repeats all of the code statements between REPEAT and the matching UNTIL statement, until the expression in the UNTIL is true.

UNTIL <expr>

If <expr> is not true, control jumps back to the nearest REPEAT statement.


Flow Control

IF <expr> THEN <statement1> ELSE <statement2>

Evaluate the expression. If the result is true then execute the statement (or statements separated by :) If not true, execute the statements after the ELSE.

IF <expr> THEN <statement1> ELSE IF <expr2> THEN <statement2> ELSE <statement3>

Evaluate the expression. If the result is true then execute the statement (or statements separated by :) If not true test the expression following ELSE IF. If this expression evaluates to true then execute statement2. If the expression evaluated to false then execute statement3.


Variable assignment

LET <variable> = <expr>

Assign the value of expr to the variable.

<variable> = <expr>

Assign the value of expr to the variable.

Data storage

DATA

This command allows a comma separated list of data items to be stored on a single line.
It is used in conjunction with RESTORE and READ.

RESTORE

This command prepares the the line number containing a DATA statement for reading.

READ <variable>

This command reads the current value on the DATA line into the specified variable.

The example below will read 6 string values from a data time and print them

5 RESTORE 100
10 FOR X=1 TO 6
20 READ char
30 PRINT char
40 NEXT
50 END
100 DATA "James","Sarah","Luke","Fred","Jim","Sheila"

Arrays

Arrays are a convenient way to store multiple values of a variable in memory. The DIM command is used to dimension an array.

Once the array is dimensioned, it can be read and written to. An array dimensioned with x elements can be read from 0 to n-1.

The following example writes numbers to a single dimension array of 10 elements, set them all to 1 in a loop and then read them back.

10 DIM a(10)
30 FOR x=0 TO 9
40 a(x)=1
50 NEXT
60 FOR x=0 TO 9
70 PRINT a(x)
80 NEXT

In the following example, a two-dimensional array is created with 5x5 elements. A value is written diagonally through it, finally the program prints out the entire contents of the array.

10 DIM a(5,5)
30 FOR x=0 TO 4
40 a(x,x)=1
50 NEXT
60 FOR ry=0 TO 4
70 FOR rx=0 TO 4
80 PRINT a(rx,ry);
90 NEXT
100 PRINT;
110 NEXT
This output of this program is shown below:-
10000
01000
00100
00010
00001

Logic Operators

<A> AND <B>

Performs the bitwise AND of the values A and B

<A> OR <B>

Performs the bitwise OR of the values A and B

<A> XOR <B>

Performs the bitwise exlcusive OR of the values A and B

NOT <A>

Returns the logical negation of A

Functions

ASC(<character>)

Returns the ASCII code for the specified character

ABS(<expr>)

Returns the absolute value of the specified number. I.e. fractional part removed.

SIN(<expr>)

Returns the sinusoid of the input value specified in radians.

COS(<expr>)

Returns the cosine of the input value specified in radians.

TAN(<expr>)

Returns the tangential value of the input value specified in radians.

RAD(<expr>)

Returns the radians value of the input value specified in degrees.

DEG(<expr>)

Returns the degrees value of the input value specified in radians.

PI

Returns the value of PI 3.141 etc etc

LOG(<expr>)

Returns the log to the base 10 of the input value.

LN(<expr>)

Returns the log natural of the specified value.

EXP(<expr>)

Returns the exponent of the specified value. (10 to the power of <expr>)

LEFT$(<string>, <numchars>)

Returns a string containing the number of characters specified from the input string starting from the left.

RIGHT$(<string>, <numchars>)

Returns a string containing the number of characters specified from the input string starting from the right.

MID$(<string>, <start>,<numchars>)

Returns a string made up from the characters of the specified string starting from the <start> character, and including the number of characters specified by <numchars>.


Drawing commands

On a system with the LCD screen fitted, the following commands can be used to draw graphics on the screen.

CLS

This clears the LCD screen ready for drawing

MOVE

This command sets the start point of any line to be drawn

MOVE 10,10

DRAW

This command will draw a line from the last position to the new postion set by the x and y coordinates of the command.
The example below would draw a horizontal line starting from the 10th pixel to the 100th pixel along the x-axis.
The line would be 10 pixels from the top of the screen

MOVE 10,10
DRAW 100,10

REFRESH

This command forces frame buffer mode of LCD screen updating, which is ideal for animation.
The first time it is called, the mode is set, and any drawing updates are done off screen.
When the command is subsequently called, the drawing buffer is instantly displayed on the screen.

By only calling REFRESH at the end of re-drawing the game scene, flicker free animation is possible

The example below will animate an asterisk across the screen without flicker

10 FOR x=1 TO 110
20 CLS
30 PRINTAT x,30,"*"
40 WAIT (10)
50 REFRESH
60 NEXT

User functions

The language now supports the definition of functions to enable better modularity.

A function is defined as:-

FUNCTION myFunction(param1, param2, param3 .. etc)

code...

RETURN value

The function can define any number of parameters, or if no parameters are required, defined as:-

FUNCTION myNoArgFunction()

code...

RETURN value

A function does not have to return a value. If a return value is not required, just return nothing:-

FUNCTION myNoRetValFunction()

code...

RETURN

Calling user functions

A function can be called in two ways, the first is the same as the built in functions, used in an expression. like:-

10 myValue=myFunction() * 2
20 PRINT myValue
10 PRINT myfunction()
10 INPUT a 
20 INPUT b
30 PRINT myCalulator(a,b)

Another way to call a function is where the function doesn't return a value, or it's not required. Just specify the function on a line as one would a command

10 drawScreen()
10 drawSquare(30,30)

System Commands

There are a number of SYS commands that provide access to parts of the computer that are not already provided for in the ebasic language.

Click Here for the Operating system reference


(c) 2017 PicoCreate

Terms and conditions apply, click here for further details