Vexos BASIC commands

Vexos basic is a BASIC language compiler for the Vectrex arcade system.
This basic variant is specifically targeted for the Vectrex system, and therefore has additional functionality that allows you to draw vectors, play music, etc.

Here you will a quick overview of the different commands available in Vexos basic.


Things you should know before you begin
Code style
Vexos basic is pretty flexible with its codestyle:

- You can tab out/space out your code as you like.
- You can use lowercase of capitals for your code. Everything is converted to uppercase upon compilation.
- No linenumbers are used/needed.


Notes
- Calculations are ALWAYS done from left to right (no hooks supported)
- SIN/COS/RND handled only as first part of calculation (will reset calculation)
- No freaky code or calculations!


Declaring variables
- A maximum number of 240 user-defined variables can be declared.
- An array takes up the same number of variables as its array size.
- Each variable can hold 1 byte of information (value 0..255, or -128..127)
- The variables will be inited with a value of 0.

- Arrays can be declared as such: DIM varname[numelements].
For example: DIM mylist[10] , will declare an array called mylist, with 10 elements.
Individual elements can be accessed like so: mylist[0]=123 , or mylist[index]=10

There are 16 predefined system variables that you can use as well:

JOYSTICK1_X - X-position of joystick1
JOYSTICK1_Y - Y-position of joystick1
JOYSTICK1_BUTTON1 - Set to 1 when Button 1 of joystick1 is pressed.
JOYSTICK1_BUTTON2 - Set to 1 when Button 2 of joystick1 is pressed.
JOYSTICK1_BUTTON3 - Set to 1 when Button 3 of joystick1 is pressed.
JOYSTICK1_BUTTON4 - Set to 1 when Button 4 of joystick1 is pressed.

JOYSTICK2_X - X-position of joystick2
JOYSTICK2_Y - Y-position of joystick2
JOYSTICK2_BUTTON1 - Set to 1 when Button 1 of joystick2 is pressed.
JOYSTICK2_BUTTON2 - Set to 1 when Button 2 of joystick2 is pressed.
JOYSTICK2_BUTTON3 - Set to 1 when Button 3 of joystick2 is pressed.
JOYSTICK2_BUTTON4 - Set to 1 when Button 4 of joystick2 is pressed.

COLLISIONFLAG - This variable is set to 1 by the CHECKCOLLISION routine upon collision.
The temporary system variables can be used whenever you run out of variables.
But be careful how you use them as these variables can be overwritten by the system.



The Vectrex display
Please remember that all drawing is done relative to the last position and that the vectrex screen has its 0,0 point in the center with the y-axis upwards.



If you would like to reposition your object, please reset the beam using the RESETBEAM command and then use the MOVETO command.


General commands
REM (short for remark)
You can use this to add comments to your code to clean up your code.
You can use as many of these as you like, as the basic compiler will ignore these.


DIM variabel
Declares a variable. The variable will be inited with a value of 0.
A maximum number of 240 variables can be declared. An array takes up the same number of variables as its array size.


IF condition THEN / ELSE / ENDIF
The IF-THEN construction is used whenever a decission is being made.
Therefore this is one of the most important commands, as it defines a large part of your game logic.
Each IF statement requires a closing ENDIF or ELSE statement.


FOR variable=startvalue TO endvalue DO / NEXT
The FOR-NEXT loop is used whenever you like to repeat something an n-number of times.
Each FOR statement requires a closing NEXT statement.


CHECKCOLLISION x1,y1,w1,h1, x2,y2,w2,h2
This command will check a collision between 2 area's defined by x1,y1,w1,h1 and x2,y2,w2,h2.
Upon collision, the COLLISIONFLAG will be set to 1.


Calculations
Standard Calculations
All calculations are handled from left to right. No brackets are supported.

The following standard calculations are supported:

+, -, * , / , SHL, SHR, AND , OR, XOR, INC, DEC


RND(value)
Returns a random value between 0 and .
For example: x=RND(255) - Assigns a random value between 0 and 255 to x.


SIN(angle)
Returns a sinus value for with an amplitude of 127. Angles range from 0 to 255.
For example: x=SIN(64) - Assigns the sinus value for angle 64 (90 degrees) to x.


COS(angle)
Returns a cosinus value for with an amplitude of 127. Angles range from 0 to 255.
For example: x=COS(64) - Assigns the cosinus value for angle 64 (90 degrees) to x.


Display commands
WAITSYNC
This routine provides a display timing for your program.
During the execution of this routine, the joystick input will also be checked.
Therefore this routine is pretty much required in any main loop.


INTENSITY brightness (0..120)
This command sets the beam intensity/brightness.


SETSCALE scale (0..255)
This command sets the scaling factor for the drawing routines.
The standard scale for movement/placement of objects using the moveto command is usually set at 128.


RESETBEAM
This command resets the beam to the center of the screen.


MOVETO x,y
This command moves the beam to position x,y.


DRAWDOTHERE
This command draws a single dot at the current beam position.


PSET x,y
This command draws a single dot at position x,y.


LINE dx,dy
This command draws a single line from the current beam position to position beamx+dx,beamy+dy.
Please note that all movement and line drawing is done relative its last position.


RECT x,y,width,height
This command draws a rectangle from position x,y with dimensions width,height.


CIRCLE x,y,r
This command draws a circle from position x,y with a radius of r.


DRAWSHAPE x,y,shapedata
This command draws a predefined shape at position x,y.
Shapes can be created and exported using the Vectorpaint tool by Revival Studios.


PRINT string/variabel
This command prints a string or variable at the current beam position.


*) These commands are not implemented yet
Sound commands
PLAYMUSIC musicdata
This command will play a piece of music from your own musicdata, or from one of the existing pieces of music data.
The following labels can be used to play exisiting music:

MUSIC_BERZERK - Plays the music from Berzerk
MUSIC_CRAZYCOASTER - Plays the power-onmusic from Crazy coaster/Narrow Escape
MUSIC_MELODYMASTER - Plays the music from Melody Master
MUSIC_SCRAMBLE - Plays the music from Scramble
MUSIC_SOLARQUEST - Plays the music from Solar Quest
MUSIC_ROMMUSIC1 - Plays rommusic 1
MUSIC_ROMMUSIC2 - Plays rommusic 2
MUSIC_ROMMUSIC3 - Plays rommusic 3
MUSIC_ROMMUSIC4 - Plays rommusic 4
MUSIC_ROMMUSIC5 - Plays rommusic 5
MUSIC_ROMMUSIC6 - Plays rommusic 6
MUSIC_ROMMUSIC7 - Plays rommusic 7
MUSIC_ROMMUSIC8 - Plays rommusic 8


PLAY note,duration
This command allows you to play single notes.


VOXSPEAK string
This command will use the Vecvox/Vecvoxx device to provide speech/voices for your game/program.
The string parameter will be analysed and converted to vecvox speech.
A Vecvoxx is required to hear the actual voices.


Troubleshooting
Compilation errors
Let me start off by saying that compiler-checking in the vexos basic compiler is very limited at the moment. It will however check for missing labels/subroutines and variabel names. In this case you will get an error like so:
(LINENO: 100) ERROR: Variable myvar not found! - Whenever an undeclared variable is used.
(LINENO: 123) ERROR: Label myfunction not found! - Whenever an undeclared label or function is used.

You should also get an error when you declare more than 240 variables.


My lines/movements are messed up!
Please remember that all drawing is done relative to the last position and that the vectrex screen has its 0,0 point in the center with the y-axis upwards. For more information see the section about the vectrex screen.


Input doesn't work
Did you forget to add a WAITRECAL command in the main loop???


Common mistakes
- Did you declare all the variables that you are using in your code?
- Did you close all IF statements with an ENDIF ?
- Did you close all FOR loops with a NEXT statement?
- Did you use the same counter value for you FOR and NEXT statement?
- Are you calculations peformed left to right? (no brackets supported)
- Are you sure you only access array-elements within their range?
- Are you sure you didn't make any typo's ?


F&*K you, your Basic compiler sucks!
Indeed it does!
Vexos Basic is far from a complete Basic compiler, but it does its job when handled with care.