Constants, variables, arrays, and default settings
Constants
Variables
Arrays
Default settings
Constants

General

A constant can be a character string or a numerical value. The contents of a constant does not vary. A program uses a constant as defined. There are numerical constants and string constants to differentiate.

Numerical constants

A numerical constant is a numeric value which can have up to 8 significant digits and the value is either positive ( "+"signed and optional ) or negative ( "-"signed ).

A numerical constant cannot be greater than 1.7014118E+38 and cannot be lower than 1.548437E-38. "E" is the exponent of the base 10. The valid range of the exponent starts from -38 and ends at +38.

Examples of valid numerical constants:
-123.4
0.789
3748.0
3.7E+12 =3.7 x 1012
7.65E-9 =7.65 x 10-9
14.8E9 =14.8 x 109

The S-BASIC commands LIMIT, POKE, PEEK, and USR are able to use a hexadecimal constant. A hexadecimal constant is characterized by a \$-sign in its first position of the constant and can have up to 4 hexadecimal digits.

Examples of valid hexadecimal constants:
LIMIT \$BFFF
USR (\$C000, X\$) Note, X\$ is a string variable.

String constants

The contents of a string constant can contain one or more letters, numbers or any other characters. A string constant is to code between quotation marks. You cannot use a quotation mark directly within a string constant. A string constant can contain up to 255 characters.

String constants can be used for example, in a PRINT command to output it on the screen or a printer. "4+9" is a string constant, it is no numerical constant and can't be used by this for computations within an arithmetical function.

Examples of valid string constants:
"ABCDEFG"
"12345678910"
DATA ABCDEFG A string constant of a DATA command must not be quoted, but it can be quoted.

Variables

General

A variable is part of the work area of a program. It is used to process data with a non constant ( variable ) contents.

Each variable has a symbolic name which relates to its location ( address ) in the storage.

A variable contains numeric data, system data, or string data.

Numeric variables

Numeric data can be stored into a numeric variable only.

It contains the value 0 until it is first used by the program.

The values allowed are as defined at numeric constants.

The syntax of the symbolic name must be as follows:

1. The length of the name is optional. The S-BASIC identifies a variable by the first two characters only. For example, the interpreter uses A1 and A1A without distinction.

2. The first character of the name must be an alpha but not the next characters.

3. The names of a BASIC command, variable, and function are "Reserved words". This means, the use of those names are not allowed to use for the symbolic name of a variable. A list of "Reserved words" by the BASIC interpreter will follow later, but this time see the names here. All names you'll find there are reserved.

Examples of valid names of numeric variables:
ABC, XYZ, ABCD, A12345 ( ABC and ABCD will be interpreted as the same variable )

Examples of invalid names of numeric variables:
PRINT ( PRINT is a BASIC command )
C@ ( no special characters allowed, alpha and / or numbers only )

Example of the usage:
10 A=5 ( store the value of 5 into A )
20 PRINT A ( display the contents of A on screen )

String variables

A string variable contains string data.

The valid syntax of a name of a string variable is as described for numeric variables.

The interpreter determines a string variable by a suffixed "\$"-sign of the symbolic name.

A string variable can contain up to 255 characters.

It contains "null" until it will be initiated by the first usage of the program, whereby the length of it is 0.

The assigned string data to a string variable must be included by quotation marks and its length determines the length of the variable.

Strings can be concatenated by the "+"-sign.

Examples:
10 A\$="MZ-700" ( assigns "MZ-700" to the string variable named A\$ )
20 B\$="SHARP " ( assigns "SHARP" to the string variable named B\$ )
30 C\$=B\$+A\$ ( assigns the contents of A\$ and of B\$ to C\$, the result is "SHARP MZ-700" )
40 PRINT C\$ ( the contents of C\$ will be displayed on screen, that is "SHARP MZ-700" )

System variables

A system variable is established by the interpreter itself.

System variables of the S-BASIC interpreter are TI\$ and SIZE.

SIZE contains the actual byte size of the free storage.

TI\$ contains the 6 digits of the system time ( 24 hours counting ) and can be established by your program to set the clock.

Further system variables are ERN and ERL. If an error occurs while the interpreter is interpreting a BASIC line of your program, ERL will contain the number of the line in error and ERN will contain the internal BASIC error number which describes the error.

Examples:
10 TI\$="153100" ( the system clock will be set to 15:31:00 )
20 PRINT TI\$ ( displays the clock, the format is hhmmss - hh hours, mm minutes, ss seconds )
PRINT SIZE ( displays the byte size of the free storage )

Arrays

An array is a group or a table of values which can be referred to by the same name. Each value of the array is an element. The elements of an array definition are variables and can be used by any BASIC command or function. The max. numbers of elements that can be defined is depending on the available storage in most cases.

The definition, the type, and the setting of the numbers of elements with its order of an array is called defining or dimensioning an array. It is done by the BASIC command DIM.

Here is an example:

10 DIM C\$(5)

An array having one dimension only will be created by the interpreter. The array C\$ has 6 elements (element #0 to element #5) and no data is assigned to these 6 elements now. Each element of these 6 elements is a string variable:

 C\$(0) C\$(1) C\$(2) C\$(3) C\$(4) C\$(5)

The first string variable is the first element in the array and it is called C\$(0).

This is another example:

20 DIM D(2,3)

An array having two dimensions will be created. All elements are initiated with the value 0. Each element of an array can be referred to by the name of the array and is indicated by a number of numeric values, the index values. The number of indexes equals to the number of dimensions.

The index determines the position of an element within an array. 0 is the lowest position and the max. position equals to the number given by the DIM command ( i.e. 2 and 3 ).

The array D(2,3) in the example above can be imagined like a table with rows and columns:

 columns rows D(0,0) D(0,1) D(0,2) D(0,3) D(1,0) D(1,1) D(1,2) D(1,3) D(2,0) D(2,1) D(2,2) D(2,3)

The element of the second row and the 4th column is called D(1,3).

More examples of declaring an array having one dimension:
10 DIM A(5) ( numeric array A has 6 elements )
20 DIM X\$(8) ( string array X\$ has 9 elements )
10 DIM A(5), X\$(8) ( same as line 10 and line 20, but defined in one line only )

More examples of declaring an array having two dimensions:
10 DIM B(5,5) ( numeric array has 6 rows and each row has 6 columns )
20 DIM Y\$(5,8) ( string array has 6 rows and each row has 9 columns )
10 DIM B(5,5), Y\$(5,8), A(5), X\$(8) ( declaring two string arrays and two numeric arrays )

Example of declaring an array having three dimensions:
10 DIM C(5,5,5) ( numeric array with 6 x 6 x 6 elements )

DIM A(5), A(6) is not valid, the names of the arrays must be different.

Try a tiny program:

10 DIM A(2),B\$(2)
20 A(0)=26
30 A(1)=9
40 A(2)= -100
50 B\$(0)="ABC"
60 B\$(1)=""XYZ"
70 B\$(2)=""MZ-700"
80 PRINT A(1)
90 PRINT B\$(2)
100 PRINT A(2)
110 PRINT B\$(0)+B\$(1)
120 PRINT A(0)

A variable within an array is called an element. Numeric constants, numeric variables, and numeric arrays are called numeric expressions whereas string constants, string variables, and string arrays are called string expressions.

Default settings

General

The following default settings are available after the start of the S-BASIC interpreter.

Keyboard

Operation mode: alphanumeric
Re-definable function keys:

 key function key function F1 "RUN"+CHR\$(13) SHIFT+F1 "CHR\$(" F2 "LIST" SHIFT+F2 "DEF KEY(" F3 "AUTO" SHIFT+F3 "CONT" F4 "RENUM" SHIFT+F4 "SAVE" F5 "COLOR" SHIFT+F5 "LOAD"

The function key F1 automatically invokes the enter key by the definition of +CHR\$(13).

Each function key can be defined for your own purposes. For example, to redefine key 8, that is F3+SHIFT, you code:

DEF KEY(8) = "KEY LIST"+CHR\$(13) and the string "CONT" is replaced with the new command which can have max. 15 characters. CHR\$(13) invokes the enter key CR automatically. The command KEY LIST will list a table which contains the commands of all function keys.

The key table is defined at location \$1322 in the S-Basic. Each 1st byte of the 10 table entries contains the length of the containig command string. The first entry is associated to the first function key, the 2nd entry is associated to the 2nd function key and so on, up to 10 entries / function keys. Each entry is 16 bytes in length.

System clock

TI\$ will be initiated with "000000".

Music

The tempo for the PLAY command is set to 4 ( moderato, middle ) and the time is set to 5 ( 1/4 note ).

Control characters and control key functions

If you press the CTRL key coincidentally with one of the keys described in the following table, a special function will be performed as described. These keys are control keys.

The associated ASCII character to the functions are also shown. These ASCII characters can be used by a PRINT command if an asterisk is suffixed to the ASCII value shown in the table and they perform the same function like pressing the associated control keys do.

The addresses shown in the table are used by the S-BASIC interpreter to perform its associated subroutines. You can modify them for own purposes. Several control keys are unused (marked as NOACT in the table), but you can expand it to own functions if you want. The location address shown in the table contains the address of the interpreter's subroutine. If this address is \$00E9 no function is performed, because at location \$00E9 is a RET command. 16 control keys are unused and wait for your own usage.

 CTRL+ ASCII location address points to subroutine at address function - \$00 \$0067 \$00E9 NOACT A \$01 \$0069 \$00E9 NOACT B \$02 \$006B \$00E9 NOACT C \$03 \$006D \$00E9 NOACT D \$04 \$006F \$00E9 NOACT E \$05 \$0071 \$07FE keyboard is set to lowercase F \$06 \$0073 \$07F8 keyboard is set to uppercase G \$07 \$0075 \$00E9 NOACT H \$08 \$0077 \$00E9 NOACT I \$09 \$0079 \$00E9 NOACT J \$0A \$007B \$00E9 NOACT K \$0B \$007D \$00E9 NOACT L \$0C \$007F \$00E9 NOACT M \$0D \$0081 \$078D CR key function N \$0E \$0083 \$00E9 NOACT O \$0F \$0085 \$00E9 NOACT P \$10* \$0087 \$0804 DEL key function Q \$11* \$0089 \$07B1 cursor down key function R \$12* \$008B \$07D6 cursor up key function S \$13* \$008D \$07B7 cursor left key function T \$14* \$008F \$07D8 cursor right key function U \$15* \$0091 \$06F9 HOME key function V \$16* \$0093 \$071E CLR key function W \$17* \$0095 \$07FB GRAPH key function X \$18* \$0097 \$08A6 INS key function Y \$19* \$0099 \$07F8 ALPHA key function Z \$1A \$009B \$00E9 NOACT [ or SHIFT+BREAK only \$1B \$009D \$078D NOACT? \ \$1C \$009F \$00E9 NOACT ] \$1D \$00A1 \$00E9 NOACT \$1E \$00A3 \$00E9 NOACT / \$1F \$00A5 \$00E9 NOACT

If you use the CTRL key coincidentally with a key not shown in the table above, the last character typed in will be repeated and print on the screen.

An example to activate an inactive entry:
Normally CHR\$(7) invokes in BASICs the BEEP function, S-BASIC can't do. To this replace the two bytes at location \$0075 by \$120A. If you code now PRINT CHR\$(7) or use CTRL+G the BEEP function will be invoked. The subroutine at \$0A12 is performed and invokes the BEEP function.

Other default settings

The boundary of the BASIC text area ( for BASIC programs ) is set to \$FEFF ( LIMIT MAX ).

last updated September 18, 2002
sharpmz@sharpmz.org