Template:Short description Template:Infobox programming language
Vilnius BASIC, sometimes known as BK BASIC, is a dialect of the BASIC programming language running on the Elektronika BK-0010-01/BK-0011M and UKNC computers. It was developed at Vilnius University, located in Lithuania which was a republic of the Soviet Union at the time.
In contrast to most microcomputer dialects of BASIC of the era, which were interpreters, Vilnius BASIC was a compile and go language that compiled the source when the user entered the RUN
command. It was otherwise similar to GW-BASIC and MSX BASIC in style and most features, although it lacked some of the multimedia commands found in MSX. One oddity was that it did not allow more than one statement on a single line, a feature normally implemented using the colon. It also lacked the ability to open more than one data file at a time.
Only the UKNC version had a full-screen editor, versions of the 0010 series machines used a line editor. Machine-dependent features, like graphics operators, parameters, and PEEK/POKE
addresses were also different among the machines.
DescriptionEdit
Program editingEdit
In contrast to most BASIC dialects of the era, Vilnius BASIC was a compile and go system, not an interpreter. When the user types <syntaxhighlight lang="text" class="" style="" inline="1">RUN</syntaxhighlight>, the compiler reads the code and produces a threaded code executable that it then ran. Nevertheless, this detail was largely invisible to the user, as the system still allowed statements to be typed in without a line number for direct (immediate) mode, or with a number for indirect mode in which case the new line was added to the program or replaced the same-numbered line if it already existed.
By the late 1970s, most microcomputer dialects offered a full-screen editor, in which the user can use the cursor keys to move around the program and type changes into any visible line of code. The Electronica systems were emulating an PDP-11, machines that had been built in the era before cursor-addressable computer terminals were widely available and thus retain the older line editor style. In these systems, a prompt is displayed that allows the user to type in one line of code, or recall a previously typed line and then edit it in-place.
Commands and statementsEdit
The list of keywords supported in Vilnius can be separated into two groups, those that can only be used in direct mode, and those that can be direct or indirect.
The former, known as commands, included the common <syntaxhighlight lang="text" class="" style="" inline="1">CONT, LIST, NEW, RUN</syntaxhighlight>. <syntaxhighlight lang="text" class="" style="" inline="1">CLOAD and CSAVE</syntaxhighlight> load and save programs to cassette tape. <syntaxhighlight lang="text" class="" style="" inline="1">AUTO</syntaxhighlight> turned on automatic line number entry, <syntaxhighlight lang="text" class="" style="" inline="1">RENUM</syntaxhighlight> renumbered the lines in the current program, and <syntaxhighlight lang="text" class="" style="" inline="1">DELETE</syntaxhighlight> deleted ranges of lines using the same "to" format as LIST, for instance, <syntaxhighlight lang="text" class="" style="" inline="1">DELETE -200</syntaxhighlight> would delete everything from the start of the program up to an including line 200.
Vilnius' primitives were similar to other BASICs of the era, and supported most of the elementary statements like Template:Mono. In contrast to most dialects, Vilnius did not allow more than one statement per line.
Numeric variables, operators and functionsEdit
As with most dialects, variable names had to start with a letter and could be followed by more letters or digits. Variable names could be any length, but only the first two characters were stored or matched, meaning that typing <syntaxhighlight lang="text" class="" style="" inline="1">PRT001=1</syntaxhighlight> followed <syntaxhighlight lang="text" class="" style="" inline="1">PR=5</syntaxhighlight> would result in a single variable in memory known as PR with the value 5.
Vilnius BASIC had four basic data types, strings, single and double-precision floating point numbers, and integers. Unless otherwise denoted, variables were assumed to be double-precision, stored in eight bytes and providing about 17 digits of precision. For comparison, most MS dialects used a 5-byte format for floating point. If <syntaxhighlight lang="text" class="" style="" inline="1">!</syntaxhighlight> was suffixed to the variable name, the value was stored in single-precision using four bytes with about 7 digits of precision. <syntaxhighlight lang="text" class="" style="" inline="1">%</syntaxhighlight> specified an integer, using a single 16-bit word to store values between -32768 and +32767. If a value with more precision was assigned to a variable with less, any excess was simply discarded; <syntaxhighlight lang="text" class="" style="" inline="1">A%=1.5</syntaxhighlight> will result in A% having the value 1.
Numeric constants in the source code could also be specified as a particular type using the same indicators; <syntaxhighlight lang="text" class="" style="" inline="1">50%</syntaxhighlight> would store the constant as an integer, <syntaxhighlight lang="text" class="" style="" inline="1">0.05!</syntaxhighlight> or <syntaxhighlight lang="text" class="" style="" inline="1">5E-02</syntaxhighlight> stores a single-precision value 0.05, and <syntaxhighlight lang="text" class="" style="" inline="1">0.05</syntaxhighlight> or <syntaxhighlight lang="text" class="" style="" inline="1">5D-02</syntaxhighlight> stores the same value in the default double-precision format. Vilnius also had the additional ability to allow numeric constants to be typed in as strings of binary, octal or hexadecimal characters, by prefixing the string with Template:Mono and a single letter indicating the type, B, O, H. For instance, <syntaxhighlight lang="text" class="" style="" inline="1">A=&H9A8B</syntaxhighlight> would convert the hexadecimal string H9A8B to the equivalent decimal value 39563 and store that in A.
Operators for numerical values included <syntaxhighlight lang="text" class="" style="" inline="1">+, -, *, /, ^</syntaxhighlight> adding <syntaxhighlight lang="text" class="" style="" inline="1">\</syntaxhighlight> for integer division and <syntaxhighlight lang="text" class="" style="" inline="1">MOD</syntaxhighlight> for the remainder. Thus <syntaxhighlight lang="text" class="" style="" inline="1">5\2</syntaxhighlight> returns 2, while <syntaxhighlight lang="text" class="" style="" inline="1">5 MOD 2</syntaxhighlight> returns 1. Numeric functions include the standard <syntaxhighlight lang="text" class="" style="" inline="1">ABS, ATN, COS, EXP, INT, LOG, RND, SGN, SIN, SQR, TAN</syntaxhighlight>. It also included the <syntaxhighlight lang="text" class="" style="" inline="1">FIX</syntaxhighlight> operator, which is similar to <syntaxhighlight lang="text" class="" style="" inline="1">INT</syntaxhighlight> but always truncates toward zero so that <syntaxhighlight lang="text" class="" style="" inline="1">FIX(-1.5)</syntaxhighlight> returns -1 instead of -2 like INT.
In addition to PEEK and POKE, which returned 16-bit values, the system also offered <syntaxhighlight lang="text" class="" style="" inline="1">OUT and INP</syntaxhighlight>, which were similar but applied a bit mask to the values to allow individual bits to be set or cleared.Template:Sfn <syntaxhighlight lang="text" class="" style="" inline="1">CLS</syntaxhighlight> cleared the screen. System functions include <syntaxhighlight lang="text" class="" style="" inline="1">FRE</syntaxhighlight> which returned the amount of free memory, and <syntaxhighlight lang="text" class="" style="" inline="1">TAB</syntaxhighlight> which moved to the given column. <syntaxhighlight lang="text" class="" style="" inline="1">AT (x,y)</syntaxhighlight> worked in a similar fashion to TAB, but moved the cursor to the given X,Y location.
StringsEdit
Suffixing a variable with <syntaxhighlight lang="text" class="" style="" inline="1">$</syntaxhighlight> indicated it was a string. String functions include the common <syntaxhighlight lang="text" class="" style="" inline="1">ASC, CHR$, LEN, STR$, VAL</syntaxhighlight>. The <syntaxhighlight lang="text" class="" style="" inline="1">STRING$</syntaxhighlight> function makes copies of a given pattern string so that <syntaxhighlight lang="text" class="" style="" inline="1">A$=STRING$(17, "X")</syntaxhighlight> will produce a string of 17 X's.Template:Sfn Only one manipulation function is included, <syntaxhighlight lang="text" class="" style="" inline="1">MID$</syntaxhighlight>, which works as in MS, but can also be used to replace characters in an existing string, <syntaxhighlight lang="text" class="" style="" inline="1">MID$(A$,1,1)="Y"</syntaxhighlight> will replace the first letter of A$ with Y. <syntaxhighlight lang="text" class="" style="" inline="1">INKEY$</syntaxhighlight> returns the current key pressed on the keyboard, if any.Template:Sfn <syntaxhighlight lang="text" class="" style="" inline="1">+</syntaxhighlight> was used for string concatenation, as in most dialects.
The <syntaxhighlight lang="text" class="" style="" inline="1">HEX$, OCT$ and BIN$</syntaxhighlight> functions returned a string encoding the value passed in. For instance <syntaxhighlight lang="text" class="" style="" inline="1">PRINT HEX$(255)</syntaxhighlight> produces FF, while <syntaxhighlight lang="text" class="" style="" inline="1">PRINT BIN$(255)</syntaxhighlight> produces 0000000011111111.
Graphics additionsEdit
The Electronica systems included computer graphics support, and Vilnius BASIC included a number of statements to work with graphics. One interesting feature of this system was that X,Y coordinates were written in parens. The system remembered the last specified point, and new locations could be indicated with the <syntaxhighlight lang="text" class="" style="" inline="1">@</syntaxhighlight>, for instance, if the last draw command was at (100,100), one could turn the pixel at (105,105) to color 3 with <syntaxhighlight lang="text" class="" style="" inline="1">PSET @(5,5),3</syntaxhighlight>. There were five color values, 0 through 3.
In addition to <syntaxhighlight lang="text" class="" style="" inline="1">PSET</syntaxhighlight>, one could draw lines from-to using a pair of coordinates separated by a minus sign, similar to the LIST command, for instance <syntaxhighlight lang="text" class="" style="" inline="1">LINE (100,100)-(120,120),3</syntaxhighlight>. In its simplest form, <syntaxhighlight lang="text" class="" style="" inline="1">CIRCLE</syntaxhighlight> took an X,Y pair for the center, a radius, and a color, <syntaxhighlight lang="text" class="" style="" inline="1">CIRCLE (120,120),30,1</syntaxhighlight>. It could also plot arcs from given start and end angles in radians, <syntaxhighlight lang="text" class="" style="" inline="1">CIRCLE (120,120),30,1,0,1.5</syntaxhighlight>, and could "compress" the vertical axis to produce an ellipse, <syntaxhighlight lang="text" class="" style="" inline="1">CIRCLE (100,100),20,1,,,0.4</syntaxhighlight>. <syntaxhighlight lang="text" class="" style="" inline="1">PAINT (100,100),3,1</syntaxhighlight> performed a flood fill starting at (100,100), filling with color 3 and moving outward until it saw color 1.
Finally, there was the multi-purpose <syntaxhighlight lang="text" class="" style="" inline="1">DRAW</syntaxhighlight> command. This took a string which encoded a series of drawing steps that could produce a complex shape in a single line of code. The four cardinal directions were indicated with U, D, L and R (up, down, left, right). The 45-degree angles were, moving clockwise, E (up-right), F, G and H (up-left). For instance, <syntaxhighlight lang="text" class="" style="" inline="1">DRAW "R20D20L20U20"</syntaxhighlight> would produce a square with sides 20 pixels long starting at the last drawn position. In addition to directions, the M command could be used to specify explicit coordinates, like "M100,120", which did not require the parens. C changes the color, B moves without drawing a line, and N resets the coordinates to what they were before the DRAW command.
There is a single graphics function, <syntaxhighlight lang="text" class="" style="" inline="1">POINT(x,y)</syntaxhighlight>, which returns the number of the color of that location on the screen.
Example programEdit
1 CLS 2 FOR X%=30% TO 1% STEP -2% 3 ? AT(X%,1%);"*" 4 ? AT(X%,20%);"*" 5 NEXT X%
This program clears the screen, creates a loop based on integer values, and then uses the <syntaxhighlight lang="text" class="" style="" inline="1">AT</syntaxhighlight> command to move the cursor alternately between Y values 1 and 20, printing (using the short form for PRINT, ?) an asterix at both locations. The result is a series of 30 asterixes in two horizontal lines.
See alsoEdit
ReferencesEdit
CitationsEdit
BibliographyEdit
- Template:Cite book
- {{#invoke:citation/CS1|citation
|CitationClass=web }}