Blassic Reference Documentation



For Blassic v0.5.x by Julian Albo (ninsesabe@arrakis.es)

Documentation last updated by Andrew L. Ayers (andrewa at phoenixgarage.NOSPAM.org) on January 27, 2003

Please note that Blassic is constantly being updated and revised, and that some of the definitions for the keywords used in Blassic may not be completely valid. I have tried my best to create useful documentation for Blassic, I can only hope that the community for Blassic continues to update and improve this documentation in the future.




Definitions used in this document and in Blassic:

Blassic makes use of a variety of variable types. Each type has an associated character suffix, which may be added to the end of the variable to help identify what the variable represents. These types are string ($), integer (%), long-integer (&), single-precision (!), and double-precision (?).

In Blassic, TRUE is defined to be "-1", whereas FALSE is defined to be "0".

Blassic's only size limitations are available memory and hard disk space. Other than that, "the sky is the limit"!

Blassic Keywords
Blassic System Variables
Blassic Error Codes


Blassic Keywords

Please note:
Keywords preceeded by an asterisk (*) are undocumented at this time, either because the keyword is a part of another version of Blassic, or the keyword is not yet implemented, or the function of the keyword is not known or clear to the author of this document.

Blassic utilizes three distinct types of keywords: Commands, Functions, and Statements. Commands are those keywords which are typically used only in the Blassic editor/debugger (ie, when Blassic is not started with a filename). Functions are those keywords which may or may not take arguments, but which always return a value to the Blassic program. Statements are keywords which are used to execute a specified action within Blassic, and may or may not take arguments, but do not return a value back to the Blassic program.



A b c d e f g h i j k l m n o p q r s t u v w x y z
ABS (n)

Function. Returns the absolute value of the number "n".
PRINT ABS (-1)

ACOS (n)

Function. Returns the arc-cosine value of the number "n".
PRINT ACOS (.01)

AND

Logical Operation. Returns the bitwise-AND value computed between two numbers.
A = 5 AND 3: PRINT A

ASC (char$)

Function. Returns the ascii value of the character "char$".
A$ = "A": PRINT ASC (A$)

ASIN (n)

Function. Returns the arc-sine value of the number "n".
PRINT ASIN (.01)

ATAN (n)

Function. Returns the arc-tangent value of the number "n".
PRINT ATAN (.01)

AUTO [n] [, i]

Command. Enters the auto numbering mode. "n" is the initial number to start at, and "i" is the increment. The default values are set as 10 and 10.
AUTO 10, 5.
a B c d e f g h i j k l m n o p q r s t u v w x y z
BIN$ (n)

Function. Returns the binary value as a string, of the number "n".
BV$ = BIN$ (24): PRINT "The binary value of 24 is ";BV$
a b C d e f g h i j k l m n o p q r s t u v w x y z
CHAIN program$

Statement. Stops execution of currently running Blassic program, then loads and begins execution of another Blassic program defined as "program$". Defined variables and values are preserved between the CHAIN.
PROG$ = "program.bas": CHAIN PROG$

CHDIR path$

Statement. Changes the current directory for subsequent FILES command usage (see FILES) to "path$".
CHDIR ".\temp\"

CHR$ (n)

Function. Returns the ascii character as a string, of the number "n".
A = 65: PRINT CHR$ (A)

CINT (n)

Function. Returns the integer value of the decimal number "n" (rounded up to the nearest integer).
PRINT CINT (1.5)

CIRCLE (x, y), r [,c [,sa, ea]]

Statement. Draws a circle in a graphics mode (see MODE), at the coordinates indicated by "x" and "y", with a radius of "r" pixels, in the current color (see COLOR). If "c" is specified, then the circle is drawn with the color indicated by "c" (see COLOR for table of values). If "sa" and "ea" (start and end angles) are specified, then an arc (part of a circle) is drawn. The angles must indicate a range between 0 and 2π (see PI). Zero angle is at the "3 o'clock" position on the circle (ie, 1,0 on the unit circle), and proceeds counterclockwise around the circle.
CIRCLE (160, 100), 50, 4
CIRCLE (160, 100), 50, 4, PI/2, PI

CLEAR

Statement. Clears all variables, including array variables (see DIM and ERASE).
CLEAR

CLOSE [#channel]

Statement. Closes all open file channels. Passing the optional input/output channel "channel" will close only that open channel number (see OPEN).
CLOSE #1

CLS

Statement. Clears the window to the currently selected PAPER color (see PAPER).
PAPER 1: CLS

COLOR n

Statement. Changes the currently selected foreground text color to the color represented by the number "n". All subsequent printed text and graphics will be drawn using this color.
Possible color values are:

NumberDescriptionNumberDescription
0Black8Dk Grey
1Dk Blue9Lt Blue
2Dk Green10Lt Green
3Dk Cyan11Lt Cyan
4Red12Lt Red
5Purple13lt Purple
6Brown14Yellow
7Lt Grey15White

COLOR 5: REM Change to purple

CONT

CONT. Command. Continue with execution of the code after a CTRL-C break.
CONT

COS (n)

Function. Returns the cosine value of the number "n".
PRINT COS (.01)

CVD (str$)

Function. Converts a passed in string "str$" to a double-precision number. The passed string must be eight (8) bytes or longer. If less than 8 bytes long, an error is generated. If more than 8 bytes long, only the first 8 bytes are used.
PRINT CVD ("abcdefgh")

CVI (str$)

Function. Converts a passed in string "str$" to an integer number. The passed string must be two (2) bytes or longer. If less than 2 bytes long, an error is generated. If more than 2 bytes long, only the first 2 bytes are used.
PRINT CVI ("ab")

CVL (str$)

Function. Converts a passed in string "str$" to a long-integer number. The passed string must be four (4) bytes or longer. If less than 4 bytes long, an error is generated. If more than 4 bytes long, only the first 4 bytes are used.
PRINT CVL ("abcd")

CVS (str$)

Function. Converts a passed in string "str$" to a single-precision number. The passed string must be four (4) bytes or longer. If less than 4 bytes long, an error is generated. If more than 4 bytes long, only the first 4 bytes are used.
PRINT CVS ("abcd")
a b c D e f g h i j k l m n o p q r s t u v w x y z
DATA n1 [,n2 ,n3, etc]

Statement. Defines a list of constants "n1, n2, n3, etc", of numeric and/or string type, which may be intermixed, to be parsed by a READ statement. Note that the variable type (numeric or string) defined in the READ statement must match with the constant type in the DATA statement (see READ and RESTORE).
DATA 1, "This is number one", 2, "This is number two"

DATE$

Function. Returns a string containing the current date in the format "mm-dd-yyyy".
A$ = DATE$: PRINT "Today's date is ";A$

DEF FN functiondef (arguments)

Statement. Defines a named function for later use in the program. Functions may be defined on a single line, or may span multiple lines, ending with the statment FN END (see FN END).
DEF FN concat$ (a$, b$) = a$ + b$: PRINT FN concat$ ("here", "there")
DEF FN addone (x) = x + 1: PRINT FN addone (5)

DEF [INT|REAL|STR] list

Statement. Defines a particular variable or range of variables, as defined in "list" as being of integer, real, or string data types. Attempting to set a variables defined as one type to a value of another type will result in an error at runtime.
DEF INT A
DEF INT A-Z
DEF INT A-Z, a-z
DEF REAL L-N
DEF STR A-B, NAME

DELETE [n1 [- n2]]

Command. If neither "n1" or "n2" are passed, deletes the program currently in memory. If "n1" is a line number, deletes that line. If "n1" and "n2" are both line numbers spanning a range of lines, those lines in the range are deleted.
DELETE 10-50

DELIMITER #channel, char$

Statement. Sets the delimeter to the character "char$", used by the open sequential input/output channel "channel", to separate data fields within each data line parsed.
DELIMITER #1, "-": INPUT #1, A$, B$, C$

DIM listvar(n1) [, var(n2), etc]

Statement. Dimensions and allocates memory for an array or list of arrays in "list". Memory allocated may be reclaimed by using CLEAR. The array may also be cleared by using ERASE.
DIM A$(20)
DIM A$(20), B$(5), CC(12)

DRAW str$

Statement. Draws the object described by a string "str$" of graphics language commands in the current graphics mode (see MODE). The following table details the graphics command language:

CommandDescription
BCauses the cursor to not DRAW on the next motion command
C nChanges the current drawing color to value "n" (see
COLOR for table of valid color values for "n")
U nMoves up "n" pixels from the current position
D nMoves down "n" pixels from the current position
L nMoves left "n" pixels from the current position
R nMoves right "n" pixels from the current position
E nMoves diagonally up and right "n" pixels from the current position
F nMoves diagonally down and right "n" pixels from the current position
G nMoves diagonally down and left "n" pixels from the current position
H nMoves diagonally up and left "n" pixels from the current position
M x, yMoves to the coordinate specified by "x" and "y". Motion is
absolute unless "x" and/or "y" are prefixed with either "+" or "-", in which
case the move will be relative to the current position.

DRAW "BM100,100;R20;D20;L20;U20": REM DRAW A SQUARE
DRAW "BM100,100;E20;F20;L40": REM DRAW A TRIANGLE
DRAW "BM100,100;R20;M+10,-20;U20;L40"

DRAW x, y
DRAWR x, y

Statement. Draws a line to the position "x, y" in the current COLOR from a position specified by the MOVE statement (see COLOR and MOVE). DRAWR draws a line relative to the current position.
COLOR 1: MOVE 50,50: DRAW 100,100
a b c d E f g h i j k l m n o p q r s t u v w x y z
EDIT n

Command. Edit a line number "n" in the program currently in memory.
EDIT 25

END

Statement. Ends the execution of the currently running Blassic program.
END

ENVIRON var$

Statement. Creates an environment variable for the environment the Blassic program is currently running in, as defined by the variable "var$".
V$ = "TEST=test env variable": ENVIRON V$: SHELL "env | more"

ENVIRON$ (var$)

Function. Returns a string containing the value of the requested environment variable "var$".
PATH$ = ENVIRON$ ("PATH"): PRINT "The path is "; PATH$

EOF (n)

Function. Returns TRUE (-1) if the end of file has been reached on the current open input/output channel number "n" (see OPEN).
IF EOF (1) THEN CLOSE #1

ERASE list

Statement. Clears individual array variables defined in "list" (see DIM and CLEAR).
DIM A(10), TT(5): ERASE A, TT

ERL

Function. Returns the program line where the last error was generated. Normally used inside an ON ERROR GOTO routine.
PRINT "Error occurred on line "; ERL

ERR

Function. Returns the code of the last error generated. Normally used inside an ON ERROR GOTO routine.
PRINT "Error code "; ERR

ERROR n

Statement. Forces the error number "n", stopping the program or jumping to the position established by a previous ON ERROR GOTO statement. For a list of the error numbers used by Blassic, please refer to the error.h file in the Blassic sources.
ERROR 1

EXIT [n]

Statement. Quit the currently running program in memory, returning to the operating system. If then number "n" is specified, it will be used as the return value of the Blassic comment, otherwise Blassic will return "0" (the ERRORLEVEL value in Windows).
EXIT 1

EXP (n)

Function. Returns the mathematical number e raised to the number "n"th power, where e is the base for natural logarithms (e = ~2.7182818).
PRINT EXP (1): REM RETURN e, WHICH EQUALS ~2.7182818
a b c d e F g h i j k l m n o p q r s t u v w x y z
FIELD #channel, n1 AS var1$ [, n2 AS var2$...]

Statement. Allocates space and position of variables in a random input/output buffer (see OPEN), where "channel" is the number of the open input/output channel, "n1" is the number of characters allocated to the field, and "var1$" is a string variable that will be used to access the field. FIELD does not actually insert or retrieve any data from the open input/output channel. It only designates how the data will be inserted by the PUT statement, and retrieved by the GET statement.
FIELD #1, 25 AS NAME$, 8 AS DOB$, 3 AS AGE$

FILES [str$]

Statement. List files in current directory (see CHDIR). If optional file mask "str$" is used, the returned list will contain files in the current directory that matches the mask. Please note that the wildcards allowed are operating system dependent.
FILES
FILES "*.TXT": REM Return all files ending in ".TXT"

FIX (n)

Function. Truncates the decimal portion of the number "n" and returns the whole number part.
PRINT FIX (1.5): REM Prints "1"

FN END

Statement. Terminates the end of a multi-line function declaration (see DEF FN).
DEF FN addtwice (x)
  x = x + 5
  x = x + 10
  addtwice = x
FN END

FOR var = n1 TO n2 [STEP i]

Statement. Initializes and executes a loop, which sets the variable "var" to each value in the loop, with a beginning value of "n1" and an ending value of "n2", incremented by the STEP increment value "i". Values "n1", "n2" and "i" may all be negative. STEP is optional and is assumed to be "1" if not specified (see NEXT).
FOR cc = 1 TO 5: PRINT cc: NEXT cc
FOR cc = 1 TO 10 STEP 2: PRINT cc: NEXT cc
FOR cc = 5 TO -5 STEP -1: PRINT cc: NEXT cc
a b c d e f G h i j k l m n o p q r s t u v w x y z
GET var$
GET #channel [, n]

Statement. In the first case, GET is used to retrieve a character typed on the keyboard, and place it in variable "var$". The program execution is suspended until a key is pressed on the keyboard, after which the execution resumes with the next line of code. In the second case, GET is used to retrieve a specified record number "n" from the open random access input/output channel "channel". If "n" is not defined, then the next record is retrieved (see OPEN).
GET K$: PRINT "The key pressed was "; K$
GET #1

GOSUB label

Statement. Branches to a subroutine defined by "label", where "label" is a label name or line number to branch to. GOSUB causes execution to branch to the subroutine, execute the lines contained within that subroutine, and then via a RETURN statement, continue execution of code after the GOSUB (see RETURN).
GOSUB GetUserInput
GOSUB 1110

GOTO label

Statement. Branches to "label", where "label" is a label name or line number, continuing the execution of statements at that point.
GOTO EndOfProgram

GRAPHICS [CLS|PAPER|PEN]

Statement. Enables the use of the CLS, PAPER, and PEN statements in the graphics modes (see MODE).
COLOR ,0: GRAPHICS CLS
a b c d e f g H i j k l m n o p q r s t u v w x y z
HEX$ (n)

Function. Returns a string representing the hexdecimal value of the number "n", which may be positive or negative.
PRINT HEX$ (10);" is the hexdecimal value = 10."
a b c d e f g h I j k l m n o p q r s t u v w x y z
IF exp1 THEN exp2 [ELSE exp3]

Statement. The IF-THEN-ELSE construct is used to form logic based interactive branching. "exp1" is either a logic or arithmetic expression test, which if it evaluates to TRUE (-1), causes the execution of the THEN expression "exp2". Otherwise execution continues with the next line, or if the ELSE expression "exp3" is defined, then it is executed instead. Expressions "exp2" and "exp3" may be other statements or functional expressions.
IF A$ = "K" THEN GOTO 40
IF N = 10 THEN V$ = HEX$(N) ELSE GOSUB NewItem
IF y >= 15 THEN Y = 15

INKEY$

Function. Returns the first value from the keyboard buffer as a single character string. Does not pause for input.
K$ = INKEY$: IF K$ = "Q" THEN GOTO EndOfProgram

INPUT #channel, var1 [, var2...]

Statement. Gets a value or string from the open sequential input/output channel "channel" and assigns the value to the variable var1 (, var2, etc). The variables may be any number of string or numeric variables. If the data being read does not match up with the variable types used, an error will occur.
INPUT #1, NAM$, AGE, DOB$
PRINT " NAME : "; NAM$
PRINT " AGE : "; AGE
PRINT "DATE OF BIRTH : "; DOB$

INPUT ["prompt";] var1 [, var2...]

Statement. Pauses program execution to get input from the keyboard. If used, "prompt" is a quoted string that replaces the standard INPUT prompt character "?", with the string defined by "prompt". The variables "var1", "var2", etc are used to store the resulting keyboard input, which is terminated by a carriage return. These variables may be of string or numeric type. The data input by the user must match the types of the variables, otherwise an error will occur. Should multiple variables need to be entered, the user must separate the data entered by commas.
INPUT K$
INPUT "Your name : "; NAM$
INPUT "Please enter your name and age (name, age) : "; NAM$, AGE

INPUT$ (n)

Function. Pauses and waits for keyboard input, until the number of characters input equals the number "n". INPUT$ then returns those characters as a string, and continues with the execution of the Blassic program. INPUT$ does not display a prompt.
K$ = INPUT$ (3): PRINT "Characters : "; K$

INSTR ([n,] str1$, str2$)

Function. Returns a numeric value indicating the position of the first instance string "str2$" is found within string "str1$", where "n" is a numeric value indicating the starting position within "str1$" where the search is to begin. If "n" is ommitted, then the searching begins with the first character of "str1$". If "str1$" is null, then INSTR returns "0". If "str2$" is null, then INSTR returns the "1".
PRINT INSTR ("HELLO", "L")
L$ = "HELLO": P = INSTR (3, L$, "O"): PRINT "Position = "; P

INT (n)

Function. Returns the integer value of the decimal number "n".
AGE = INT (20.75): PRINT AGE
a b c d e f g h i j K l m n o p q r s t u v w x y z
KILL path$

Statement. Deletes the file specified by "path$". If "path$" does not specify an explicit or relative path to the file, then the current defined path is used (see CHDIR).
KILL "..\test.txt"
a b c d e f g h i j k L m n o p q r s t u v w x y z
LABEL str$

Defines a label "str$" in the program. For statements that normally use a line number as parameter, such as GOTO, a defined label name can be substituted for the line number. LABEL must be the first instruction in the line, otherwise it is ignored.
LABEL EndOfProgram

LEFT$ (str$, n)

Function. Returns the left-most number "n" of characters of string "str$" as a string.
K$ = "HELLO": PRINT LEFT$ (K$, 3)

LEN (str$)

Function. Returns the length of string "str$", as a numeric value.
A$ = "HELLO": PRINT "The string "; A$; " contains "; LEN (A$); " characters."

LET var = n

Statement. Assigns the value "n" to the variable "var". This statement is mainly included for compatibility reasons, as in most versions of BASIC (including Blassic) the equals (=) sign is sufficient to make the assignment.
LET A$ = "TEST"
LET X = 10

LINE INPUT [#channel,] str$

Statement. If the open input/output channel "channel" is defined, then LINE INPUT retrieves a line of string data "str$" from the input/output channel, in which the line of data can contain any character, including commas (or other defined delimiters). If "channel" is omitted or undefined, then LINE INPUT pauses the program execution to get a line of input data "str$" from the keyboard, which can contain any character, including commas.
LINE INPUT #1, L$
PRINT "Data : ";: LINE INPUT L$

LIST [n1][-][n2]

Command. List the currently loaded program in memory. If neither "n1" or "n2" are defined, then the entire program is listed. If "n1" is defined, and proceeded with a "-", then all lines from line "n1" to the end of the program are listed. If "n2" is defined, and preceeded with a "-", then all lines from the beginning of the program to "n2" are listed. If both "n1" and "n2" are defined in such a way as to present a range of line numbers, then all lines between those lines are listed.
LIST
LIST 20-
LIST -50
LIST 20-50

LOAD file$
LOAD file$, var$
LOAD file$, address [, size]

Command. Loads a Blassic program "file$". If the program is not found, then "file$" with ".blc" and ".bas" concatenated onto "file$" are tried. If string var$ is used, then the program is loaded into the string variable. If address and/or size are defined, then the file is loaded in the address of memory specified. If size is used, only that many bytes are loaded, otherwise the entire file is loaded.
LOAD "test"
LOAD "test.bas", V$
LOAD "test.bas", 100, 1000

LOCAL var

Statement. Defines a variable "var" as being "local" to the subroutine or function in which it is defined. When this is done, the variable acts independently of other instances defined outside of the subroutine or function, such that any changes made to the variable are not reflected by other outside instances of that variable.
10 B = 5: PRINT B
20 GOSUB 50: PRINT B
30 END
40 REM START OF SUBROUTINE
50 LOCAL B
60 B = 200
70 PRINT B
80 RETURN

LOCATE v, h

Statement. Moves the text cursor to the location specified by the values "v" and "h" to denote the vertical and horizontal positions accordingly.
CLS: LOCATE 5, 10: PRINT "Here!"

LOG (n)

Function. Returns the natural logarithm (base e) of "n", where "n" is any number greater than zero (0). If "n" is defined as zero, then LOG returns "-inf" (infinity).
PRINT "The log of 2 is "; LOG(2)

LOG10 (n)

Function. Returns the base 10 logarithm of "n", where "n" is any number greater than zero (0). If "n" is defined as zero, then LOG10 returns "-inf" (infinity).
PRINT "The log10 of 2 is "; LOG10(2)

LOWER$ (str$)

Function. Returns the lowercase converted version of the string "str$".
A$ = "HELLO": PRINT LOWER$ (A$)

LSET var1$ = var2$

Statement. Moves data into a random-access file buffer, where "var1$" is the name of a string variable defined with a FIELD statement, and "var2$" is a string variable to be placed into that field. The data placed in the field is left-justified according to the space in the field. If "var2$" is larger than the field, then the data is truncated on the right. Please note that this statement works on strings only. Numeric data needs to be converted into a string using the functions MKD$, MKI$, MKL$, or MKS$.
B$ = "TEST": LSET F$ = B$

LTRIM$ (str$)

Function. Removes leading left-hand spaces from the string "str$", and returns the modified string.
PRINT LTRIM$ (" HELLO "); "GOODBYE"
a b c d e f g h i j k l M n o p q r s t u v w x y z
MASK [n1 [,n2]]

Statement. Sets the graphics bitmask mode. If "n1" is set, the mode affects all graphics operations. If "n2" is set, the mode only affects the first used graphics statement. The modes are as follows:

ModeDescription
0Copy
1XOR
2AND
3OR
4Invert

MASK 1, 0

MAX (var1, var2 [,...])

Function. Returns the value which is highest in the list of numeric variables passed to MAX.
PRINT "The maximum is "; MAX (10, 20, 30)

MID$ (str$, n1, n2)

Function. Returns a string of characters from the string "var$", beginning at position number "n1" of the string, for a length of "n2".
K$ = "HELLO": PRINT MID$ (K$, 3, 2)

MIN (var1, var2 [,...])

Function. Returns the value which is lowest in the list of numeric variables passed to MIN.
PRINT "The minimum is "; MIN (10, 20, 30)

MKD$ (n)

Function. Converts the double-precision number "n" into an 8-byte string so it can later be retrieved from a random-access file as a numeric value.
V$ = MKD$ (12.5)

MKDIR path$

Statement. Creates a sub-directory "path$" in the current directory (see CHDIR).
MKDIR "temp"

MKI$ (n)

Function. Converts the integer number "n" into an 2-byte string so it can later be retrieved from a random-access file as a numeric value.
V$ = MKI$ (12)

MKL$ (n)

Function. Converts the long-integer number "n" into an 4-byte string so it can later be retrieved from a random-access file as a numeric value.
V$ = MKL$ (1234)

MKS$ (n)

Function. Converts the single-precision number "n" into an 4-byte string so it can later be retrieved from a random-access file as a numeric value.
V$ = MKS$ (12.5)

MOD

Mathematical Operation. Returns the modulo (remainder) value computed between two numbers.
A = 5 MOD 3: PRINT A

MODE n
MODE h, w
MODE h, w, d

Statement. Initializes and creates a graphics mode window of size type "n". When using the second notation, MODE allows the user to create a graphics mode window of arbitrary height ("h") and width ("w"). When using the third notation, setting "d" to "1" causes the y coordinates to be reveresed (ie, coordinates decrease going down). Omitting "d" or setting it to "0" returns it to normal operation. Valid values for "n" include:

NumberDescription
0Text Mode
1320 x 200
2640 x 200
5320 x 200
10640 x 480
11800 x 600

MODE 1: REM Change to 320x200 mode
MODE 1024, 768

MODE str$

Statement. Initializes and creates a graphics mode based on the mode description string "str$". The following modes are available for use:

ModeDescriptionInverted Y Axis?
spectrum256 x 176Yes
cpc2640 x 400Yes

MODE "cpc2"

MOVE x, y
MOVER x, y

Statement. Moves the position of the virtual graphics cursor to the absolute position "x, y", for subsequent graphics operations such as DRAW (see DRAW). MOVER moves the graphics cursor relative to the current position.
COLOR 1: MOVE 50,50: DRAW 100,100

a b c d e f g h i j k l m N o p q r s t u v w x y z
NAME file1$ AS file2$

Statement. Renames a file in the current directory from filename "file1$" to filename "file2$".
NAME "TEST.BAS" AS "NEWTEST.BAS"

NEW

Statement. Clears program from memory.
NEW

NEXT var

Statement. Terminates a FOR-NEXT loop, where "var" is the numeric loop variable. Program execution continues either with the statement following the FOR, or the with the next statement after the NEXT, depending on the value of the counter specified in the FOR (see FOR).
FOR T = 1 TO 10: NEXT T

NOT

Logical Operation. Returns the bitwise-NOT value computed between two numbers.
A = 5 NOT 3: PRINT A
a b c d e f g h i j k l m n O p q r s t u v w x y z
OCT$ (n)

Function. Returns the octal value (in string form) of the number "n".
OV$ = OCT$ (24): PRINT "The octal value of 24 is ";OV$

ON BREAK CONT
ON BREAK GOSUB label
ON BREAK STOP

Statement. ON BREAK takes three forms, each form defining a different method of handling what happens if the user of the Blassic program presses CTRL-C. The first form cancels the effect of CTRL-C stopping the program. The second form causes the program to jump to the subroutine specified "label" (which may be a label name or line number - see GOSUB and LABEL). The third form disables the effects of any prior ON BREAK CONT and ON BREAK GOSUB usage, and allows the normal action of CTRL-C to interrupt the running program.
ON BREAK CONT
ON BREAK GOSUB BRK_HANDLER
ON BREAK STOP

ON ERROR GOTO label

Statement. ON ERROR GOTO causes the running Blassic program to jump to the specified "label" (which may be a label name or line number - see GOTO and LABEL) Also see RESUME, ERR, and ERL.
ON ERROR GOTO ERR_HANDLER

ON n [GOTO|GOSUB] label1, ..., labelX

Statement. Causes the running Blassic program to jump to a "label" in the program or a "label" of a subroutine (see GOTO, GOSUB, and LABEL), depending on the numeric value "n". For example, if "n" equals "2", then the second label would be jumped to.
T = 3: ON T GOTO 100, 200, 300
FOR T = 1 TO 3: ON T GOSUB 100, 200, 300: NEXT T

OPEN file$ FOR mode AS #channel

Statement. Opens a file "file$", where "file$" is the name of a file and/or path to a file for processing. The file is opened for a particular "mode", which may be INPUT, OUTPUT, APPEND, or RANDOM, and is assigned an available input/output channel "channel", for subsequent file operations.
OPEN "test.txt" FOR INPUT AS #1

OR

Logical Operation. Returns the bitwise-OR value computed between two numbers.
A = 5 OR 3: PRINT A

OSFAMILY$

Function. Returns a string representing the type of Operating System Family the OS that the Blassic program is running on.
PRINT "The OS Family is "; OSFAMILY$

OSNAME$

Function. Returns a string representing the name of the Operating System that the Blassic program is running on.
PRINT "The OS Name is "; OSNAME$
a b c d e f g h i j k l m n o P q r s t u v w x y z
PAPER n

Statement. Sets the color of the current background to color number "n".

Possible color numbers are:

NumberDescriptionNumberDescription
0Black8Dk Grey *
1Dk Blue9Lt Blue *
2Dk Green10Lt Green *
3Dk Cyan11Lt Cyan *
4Red12Lt Red *
5Purple13lt Purple *
6Brown14Yellow *
7Lt Grey15White *

* NOTE: These color values are only valid in the graphics modes (see MODE).
PAPER 5: REM Change to purple

PAUSE n

Statement. Pauses the running Blassic program for "n" number of milliseconds. Execution then continues with the next line after the PAUSE.
PAUSE 1000: REM WAIT ONE SECOND

PEEK (n)
PEEK16 (n)
PEEK32 (n)

Function. PEEK returns a single-byte value of data located at the address number "n" (see SYSVARPTR). The variants of this command, PEEK16 and PEEK32, return 2-byte (integer) and 4-byte (long integer) values respectively.
V = PEEK (SYSVARPTR)

PEN n1 [,n2 [, n3]]

Statement. In the simplest form, PEN allows the program to change the current forground color of printed text to color number "n".
Possible color numbers are:

NumberDescriptionNumberDescription
0Black8Dk Grey
1Dk Blue9Lt Blue
2Dk Green10Lt Green
3Dk Cyan11Lt Cyan
4Red12Lt Red
5Purple13lt Purple
6Brown14Yellow
7Lt Grey15White

In this usage, PEN performs much the same as the COLOR statement. PEN does, however, have more advanced modes, which allow for a much greater control of the way text output is displayed in the graphics modes (the advanced modes of PEN only work in the graphic modes, and will cause an error in the text mode). These modes work in the following manner:

PEN n1, n2 [, n3]

Parameter "n2" sets the background draw mode. When "n2" is set to "0", PEN operates in "normal" mode, in which the background is considered "opaque", and any character printed at the location replaces the character currently at that location (see LOCATE). When "n2" is set to "1", PEN operates in "transparent" mode, in which the background is considered transparent, and any character printed at the location will "blend" together (which can allow for multiple effects - play with it!).

Parameter "n3" sets the write mode. The write modes are as follows:

ModeDescription
0Copy
1XOR
2AND
3OR
4Invert

The exact behavior is dependent on the graphics mode used (see MODE). Using the XOR mode with PEN 15 (ie, PEN 15,,1), as used in the sample program "graph.bas", is the most useful form, for the moment.
PEN 1
PEN 1, 1
PEN 15, 1, 1

PI

Function. Returns a single-precision number which represents of PI (π).
PRINT "The value of PI is "; PI

PLEASE

Statement. A debugging tool which causes the currently running Blassic program to print the statement "Programmer is too polite in X", where "X" is the line number of the PLEASE statement. When a key is pressed, then execution continues with the next line (ok, I know that explanation is pretty contrived, but what the heck other use can you think for it?)...
PLEASE

PLOT x, y
PLOTR x, y

Statement. Plots a pixel in the current PEN color at the absolute position "x, y". The variant PLOTR plots the pixel relative to the current position.
COLOR 2: PLOT 50, 50

POKE address, n
POKE16 address, n
POKE32 address, n

Statement. POKE places the single-byte value "n" (0-255) into the address location "address". The variants of this command, POKE16 and POKE32, places return 2-byte (integer) and 4-byte (long integer) values at the address location "address" respectively. See SYSVARPTR.
POKE X, 15

POP

Statement. Causes the most recent return address from a prior GOSUB to be deleted from the top of the return-address stack, to modify program branch. While useful in some extreme cases, this practice is considered poor programming and should be avoided when possible (see GOSUB and RETURN).
POP

POPEN str$ FOR mode AS #channel

Statement. Opens a piped command line "str$", where "str$" is a command string you want to pipe data through, processing the data prior to input or output to the open input/output channel "channel". The pipe is opened for a particular "mode", which may be INPUT, OUTPUT, APPEND, or RANDOM.
POPEN "grep ""test"" > test.txt" FOR OUTPUT AS #1

PRINT [#channel,] var

Statement. Prints the variable "var" to the current graphics or text window. If the open input/output channel "channel" is defined (and opened for OUTPUT or APPEND - see OPEN), then the variable "var" is written to the file.
PRINT "Hello there..."
INPUT NM$: PRINT "Hello, "; NM$
PRINT #1, A$

PRINT AT x, y, var

Statement. Prints the variable "var" to the current graphics or text window, at the position indicated by "x" and "y" (see LOCATE).
PRINT AT 10, 5, "Hello there..."

PRINT USING [#channel,] f$; var

Statement. Prints the variable "var" to the current graphics or text window, formatted using the special formatting string "f$". If the open sequential input/output channel "channel" is defined (and opened for OUTPUT or APPEND - see OPEN), then the variable "var" is written to the file after being formatted.
PRINT USING "This is number ## of ##..."; x; y
PRINT USING #1, "Code ##"; CD

PROGRAMARG$ (n)

Function. PROGRAMARG$ returns the command line parameter value at position number "n", excluding the Blassic command and the program name. If there are insufficient parameters, an empty ("") string is returned. Parameters are passed to a Blassic program when the program is run with the Blassic command, as follows:

> blassic program.bas arg1 arg2 [etc]

PRINT "The first argument is "; PROGRAMARG$(0)

PROGRAMARG$ arg1$ [, arg2$...]

Command. Establishes the return values of the PROGRAMARG$ function to the args specified. Useful when debugging.
PROGRAMARG$ test, 5

PROGRAMPTR

Function. Returns the address of the program memory area, or "0" if there is no program loaded. See the autoview.bas and automod.bas sample programs.
V = PROGRAMPTR

PUT #channel [,n]

Statement. Writes a record from a random access buffer to a file, where "channel" is an open random access input/output channel, and "n" is the record number to be written to. If "n" is not defined, then the record goes into the next available record (see OPEN).
PUT #1, 5
a b c d e f g h i j k l m n o p q R s t u v w x y z
RANDOMIZE n

Statement. Reseeds the random number generator with a number "n".
RANDOMIZE TIME

READ [#channel,] var1 [, var2...]

Statement. Reads a value or values (var1, etc.) from a defined DATA statement (see DATA). If input/output channel "channel" is defined, then READ reads a data element from the open input/output channel "channel" (see OPEN).
DATA JOHN DOE, 23: READ NAM$, AGE
READ #1, NAM$, AGE: REM READ THE NAME AND AGE

REM comments

Statement. Defines a comment in the code. Characters after the REM statement are ignored by the Blassic interpreter.
REM This is a comment...

RENUM sline [, snum [, inc]]

Command. Renumbers the lines of the currently loaded program in the Blassic environment, starting with line "sline", with the renumbering beginning with the line number "snum", and incrementing by "inc" lines. If no parameters are passed to RENUM, then the default is "10, 10, 10".
RENUM 10, 100, 5

REPEAT

Statement. Begins a REPEAT-UNTIL loop structure (see UNTIL).
REPEAT
   K$ = INKEY$
UNTIL K$ = "Q"

RESTORE [label]

Statement. Restores the DATA read pointer (see DATA and READ) to the point represented by the label "label", where "label" is a line number or label name (see LABEL). If "label" is not defined, then the read pointer is moved to the beginning of the first DATA statement.
RESTORE 100

RESUME [NEXT | label]

In an ON ERROR GOTO routine, returns to the statement that produced the error, to the next statement, or to the position specified by the label "label", which can be a line number or label name.
RESUME NEXT

RETURN

Statement. Returns and continues execution at the line after the last GOSUB statement (see GOSUB).
RETURN

RIGHT$ (var$, n)

Function. Returns the right-most number of "n" characters of string "var$" as a string.
K$ = "HELLO": PRINT RIGHT$ (K$, 3)

RMDIR path$

Statement. Removes the sub-directory named "path$" in the current directory (see CHDIR and MKDIR).
RMDIR "temp"

RND
Function. Returns a random single-precision value between 0 and 1.
PRINT "Random roll from 1 to 6 : "; INT (RND * 6) + 1

RSET var$ = str$

Statement. Moves data into a random-access file buffer, where "var$" is the name of a string variable defined with a FIELD statement, and "str$" is a string variable to be placed into that field. The data placed in the field is right-justified according to the space in the field. If "str$" is larger than the field, then the date is truncated on the left. Please note that this statement works on strings only. Numeric data needs to be converted into a string using MKD$, MKI$, MKL$, or MKS$.
B$ = "TEST": RSET F$ = B$

RTRIM$ (str$)

Function. Removes trailing right-hand spaces from the string "str$", and returns the modified string.
PRINT RTRIM$ (" HELLO "); "GOODBYE"

RUN

Command. Runs the currently loaded Blassic program.
RUN
a b c d e f g h i j k l m n o p q r S t u v w x y z
SAVE file$
SAVE file$, A

Command. The first defined style of the command saves a loaded Blassic program as "file$" in the current directory in the Blassic binary format. The second style of the command saves the program in text format. Filename extensions are not added, but it is reccommended that ".blc" is used for the Blassic binary format, and ".bas" for text format.
SAVE "test.blc"
SAVE "test.bas", A

SAVE file$, B, var$
SAVE file$, B, address, size

Statement. The first style of the statement allows the saving of content of the string "var$" in the filename "file$". The second style allows saving bytes into the filename "file$", starting at the "address", for a length of "size".
SAVE "test.txt", B, NM$
SAVE "test.txt", B, 100, 1000

SGN (n)

Function. Returns back a -1 if the number "n" is negative, 0 if the number is equal to 0, and 1 is the number is positive.
S = SGN (-50): IF S = -1 THEN PRINT "Negative"

SHELL str$

Statement. Shells out to the operating system and executes the command line "str$".
SHELL "ls -als" (for *nix)
SHELL "dir *.txt"

SIN (n)

Function. Returns the sine value of the number "n".
PRINT SIN (.01)

SOCKET host$, port AS #channel

Statement. Opens a socket and connects it to the "host$" specified using the tcp "port" number, and associates it to an input/output channel "channel".
SOCKET "192.28.45.100", 8080 AS #1

SPC (n)

Statement. Used to insert a number of "n" spaces into a PRINT statement (see PRINT).
PRINT SPC (10); "Indented 10 spaces..."

SPACE$ (n)

Function. Returns a number of "n" spaces as a string.
SP$ = SPACE$ (10): PRINT SP$; "Indented 10 spaces..."

SQR (n)

Function. Returns the square root value of the number "n".
PRINT "The square root of four is : "; SQR (4)

STOP

Statement. Causes the currently running Blassic program to stop execution.
STOP
STR$ (n)

Function. Returns back the string representation of the number "n".
N = 50: PRINT STR$ (N)

STRING$ (n, char$)

Function. Returns back a string composed of the single character string value "char$", repeated "n" number of times.
PRINT STRING (10, "X")

SWAP var1, var2

Statement. Swaps the values of the variables "var1" and "var2", which may be string or numeric. The variables must have matching types, or an error will occur.
A = 1: B = 2: SWAP A, B: PRINT A, B

SYMBOL n, byte0, byte1, ..., byte7

Statement. Allows for the redefining of a graphics mode ASCII character symbol. Eight bytes are passed to SYMBOL to redefine the character number "n". The bits that make up each byte determine how the symbol will appear when printed.
SYMBOL 250, 128, 192, 224, 240, 248, 252, 254, 255: REM Redefine symbol 250 to be a triangle shape

SYNCHRONIZE [n]

Statement. When using a graphics mode, Blassic writes any changes to the window to both the graphics window as well as into a bitmap of the same size as the window. This is so that the system can redraw the window as it needs to (such as when a window is overlayed, then uncovered). SYNCHRONIZE allows the program to determine when to write to the bitmap, and when to update the graphics window as needed by the program, rather than by the system. When a "1" is passed to SYNCHRONIZE, any graphics commands only update the bitmap, and not the actual window. Then, when the SYNCHRONIZE statement is used without a parameter, the bitmap is copied into the window, making the changes visible. This process can be repeated as necessary, allowing for fluid motion with little flicker. Passing a "0" to SYNCHRONIZE will return the behavior to normal, copying changes to both the window and the off-screen bitmap buffer.

Here is an example of this method:

x = 160: y=100: dx = 5
Mode 1
While Inkey$ = ""
   x = x + dx
   If x < 0 or x > 320 Then dx = -dx
   Synchronize 1
   Move x-20, y-20
   Pen 4: Draw x+20, y-20: Draw x+20, y+20: Draw x-20, y+20: Draw x-20, y-20
   Pause 1
   Synchronize
   Pen 15: Draw x+20, y-20: Draw x+20, y+20: Draw x-20, y+20: Draw x-20, y-20
Wend
Synchronize: Mode 0

SYSTEM

Statement. Quits the running Blassic program and returns to the operating system.
SYSTEM

SYSVARPTR

Function. Returns the address of the system variable memory area. For information on the system variables refer to the sysvar.h file in the Blassic sources.
AD = SYSVARPTR
a b c d e f g h i j k l m n o p q r s T u v w x y z
TAB (n)

Statement. Used to tab "n" number of spaces over in a PRINT statement (see PRINT).
PRINT TAB (10); "Tabbed over 10 spaces..."

TAN (n)

Function. Returns the tangent value of the number "n".
PRINT TAN (.01)

TIME

Function. Returns a long integer value representing the current time.
T = TIME: PRINT "TIME = "; T

TIME$

Function. Returns a string containing the current time in the format "hh:mm:ss" (24-hour format).
T$ = TIME$: PRINT "The current time is "; T$

TRIM$ (str$)

Function. Removes leading and trailing spaces from the string "str$", and returns the modified string.
PRINT TRIM$ (" HELLO "); "GOODBYE"

TROFF

Command. Turns off the trace utility (see TRON).
TROFF

TRON

Command. Turns on the trace utility, which causes the line number to be printed at the current cursor position, inside a pair of brackets, as the Blassic program runs (see TROFF).
TRON
a b c d e f g h i j k l m n o p q r s t U v w x y z
UNTIL exp

Statement. Finishes a REPEAT-UNTIL loop structure, where "exp" is the code to evaluate, which if it evaluates to TRUE (-1), the loop exits and continues with the next statement after the UNTIL (see REPEAT).
REPEAT
   K$ = INKEY$
UNTIL K$ = "Q"

UPPER$ (str$)

Function. Returns the uppercase representation of the string "str$" as a string.
A$ = "hello": PRINT UPPER$ (A$)

USR (lib$, func$ [, param$])

Function. Calls the external function "func$" in the defined library "lib$", returning the return value from the function. Optionally, a parameter "param$" may be passed to the function as well.
N = USR ("./testdl.so", "testfunc", VARPTR ("test"))
a b c d e f g h i j k l m n o p q r s t u V w x y z
VAL (var$)

Function. Returns the numeric value of the string "var$". The string must start with a number, otherwise VAL returns "0".
PRINT VAL ("10")

VARPTR (var)

Function. Returns the address pointer of the first byte of data associated with variable "var", which may be any string or numeric variable.
AP = VARPTR("This is a test")
a b c d e f g h i j k l m n o p q r s t u v W x y z
WEND

Statement. Ends a WHILE-WEND looping structure (see WHILE).
WHILE INKEY$ <> "Q"
   PRINT "PRESS Q TO QUIT..."
WEND

WHILE exp

Statement. Begins a WHILE-WEND looping structure (see WEND), where "exp" is the code to evaluate which will continue the execution of the loop so long as the evaluation is TRUE (-1).
WHILE INKEY$ <> "Q"
   PRINT "PRESS Q TO QUIT..."
WEND

* WINDOW #channel, x1, y1, x2, y2 (Blassic v0.5)

Not documented yet.

WRITE #channel, var1 [, var2...]

Statement. Writes a value or values (var1, etc.) to the defined open input/output channel "channel" (see OPEN).
WRITE #1, NAM$, AGE: REM WRITE THE NAME AND AGE
a b c d e f g h i j k l m n o p q r s t u v w X y z
XMOUSE

Function. Returns the x coordinate of the mouse position (only in graphics mode).
X = XMOUSE

XPOS

Function. Returns the x coordinate of the graphics cursor.
X = XPOS

XOR

Logical Operation. Returns the bitwise-XOR value computed between two numbers.
A = 5 XOR 3: PRINT A
a b c d e f g h i j k l m n o p q r s t u v w x Y z
YMOUSE

Function. Returns the y coordinate of the mouse position (only in graphics mode).
Y = YMOUSE

YPOS

Function. Returns the y coordinate of the graphics cursor.
Y = YPOS
a b c d e f g h i j k l m n o p q r s t u v w x y Z
* ZONE

Not documented yet - unimplemented.


Blassic System Variables

The system variables area begins at the position returned by the function SYSVARPTR, and can be accessed with PEEK and POKE.

The values of the multibyte variables are stored in Intel format, even if the actual architecture use a different format, to maximize portability.

The name given in the table is simply for reference, it will not be recognized if used within a Blassic program.

If the value of the "Writable" column is "Yes", then if the value in that location is modified, then the behaviour of Blassic will change. If the value is "No", this indicates that any value written will not alter the behavior of Blassic, but can alter future readings.

Name Position Length Writable Description
GraphicsWidth 0 2 No Width of the window in graphics mode.
GraphicsHeight 2 2 No Height of the window in graphics mode.
NumArgs 4 2 No Numbers of args passed to the program from the command line (program name excluded).
VersionMajor 6 2 No First chunk of version number.
VersionMinor 8 2 No Second chunk of version number.
VersionRelease 10 2 No Last chunk of version number.
AutoInit 12 4 Yes Starting number of line used by AUTO by default and when loading text programs without line numbers.
AutoInc 16 4 Yes Increment of line number used by AUTO by default and when loading text programs without line numbers.
CharGen 20 4 No Location in memory of the character generator used in graphics mode.
ShellResult 24 1 No Return value of the last command invoked by the SHELL instruction.
TypeOfVal 25 1 Yes Type of VAL function: 0 for only numbers, 1 for expressions evaluation.
TypeOfNextCheck 26 1 Yes Type of NEXT check: 0, all FOR has to be nested; 1, check relaxed.
TypeOfDimCheck 27 1 Yes Type of DIM check: 0, DIM an array already dimensioned is an error; 1, is accepted.


Blassic Error Codes

Blassic error codes may be retrieved in a Blassic program by using the ERR function (the line number the error occurred in may also be retrieved using the ERL function). The following are descriptions for these error codes:

Error NumberError Description
0No Error
1Syntax
2Type Mismatch
3Gosub Without Return
4Return Without Gosub
5Next Without For
6Not Implemented
7Divide By Zero
8Data Exhausted
9Invalid Command
10Polite
11Bad Subscript
12Out Of Memory
13Already Dimensioned
14No Continue
15File Number
16File Mode
17File Already Open
18File Read
19File Write
20Until Without Repeat
21Wend Without While
22While Without Wend
23Blassic Internal Error
24No Dynamic Library
25No Dynamic Symbol
26Cannot Resume
27No Label
28Misplaced Local
29Field Overflow
30File Not Found
31Line Exhausted
32Function Not Defined
33Incomplete Def
34Invalid Direct
35Bad Record
36Function Call
37Socket
38Rename File
39Operating System
40Input Past EOF