Английская Википедия:Acorn System BASIC

Материал из Онлайн справочника
Перейти к навигацииПерейти к поиску

Шаблон:Short description Шаблон:Infobox programming language Acorn System BASIC and Atom BASIC are two closely related dialects of the BASIC programming language developed by Acorn Computers for their early microcomputers like the Acorn System 3 and Acorn Atom. Developed in-house, they have a number of significant idiosyncrasies compared to most BASIC dialects of the home computer era.

In particular, the language lacked statements for many of the machine's internal functions and provided this using direct access and manipulation of memory locations using indirection operators instead of PEEK and POKE. Both also lacked floating-point support, although this could be added with an optional ROM which introduced further idiosyncrasies. System and Atom BASIC differ primarily in that Atom used the same indirection system to provide rudimentary string manipulation, which Standard lacked, and added a small number of new statements for computer graphics.

Most of these oddities were removed when the underlying system was greatly expanded to produce BBC BASIC on the Atom's successor, the BBC Micro. BBC BASIC ROMs were later offered to Atom users.

History

Файл:Hermann Hauser using Acorn Atom 2012.jpg
Hermann Hauser uses Atom BASIC at the BBC Micro 30th anniversary.

Acorn Computers formed in 1978 and got its start making a series of kit-built and Eurocard-based systems starting with the Acorn System 1 in 1979. They developed Acorn System BASIC for these machines,Шаблон:Sfn an integer-only dialect that required only 4 KB of memory in total.Шаблон:Sfn The language had a number of implementation details that made it "highly non-standard."Шаблон:Sfn

The Atom, introduced in 1980, was built from parts of the System 3 packaged onto a single board. Systems shipped standard with 2 KB of RAM and 8 KB of ROM, which included BASIC and a number of device drivers. Atom BASIC had only a few changes from the System version, adding support for string manipulation and a small number of graphics commands. The Atom was upgradable, with up to 12 KB of RAM in total and an additional 4 KB of ROM that added floating-point support. This used separate functions and operations that worked on them, indicated by the % symbol.Шаблон:Sfn This choice of symbol was unfortunate, as Microsoft BASIC used the percent sign to indicate integers, not floating point.Шаблон:Sfn

The Atom was on the market for only a short period before Acorn began development of its successor, the Proton. This was initially to be a two-processor unit. The design was still in its earliest stages when a series of events led to it being selected as the basis of the single-CPU BBC Micro.Шаблон:Sfn At the time, there were comments that it should definitely not use Acorn's variety of BASIC, which "virtually no other microcomputer can understand" and that "If the new language were based on the Atom's form of BASIC, it would be a disaster."Шаблон:Sfn

Ultimately, the BBC system did use an Acorn-written BASIC, but heavily modified. The resulting BBC BASIC was much more similar to Microsoft BASIC and was later offered as an upgrade to the Atom.Шаблон:Sfn

Description

As the two dialects are very similar, the following will refer to Atom BASIC primarily and point out differences where they exist.

Program editing

Like most BASICs of the era, Atom BASIC used a line-oriented editor with direct (immediate) and indirect modes. Typing in a statement without a line number performed the operation immediately. Adding a line number instead placed those statements in the stored program. One idiosyncrasy was that while it allowed multiple statements on a single line, the separator between statements was the semicolonШаблон:Sfn instead of the commonly used colon, thus requiring the user to convert that character when typing in programs for other computers.

Intended for use with computer terminals, Acorn BASIC did not support a full-screen editing mode. For contrast, in Commodore BASIC (and many other microcomputer dialects), one can use the cursor keys to move upward into a program listing, make changes on-screen, and then press Шаблон:Key to enter those changes. On the Atom, one could move upward into a listing using the cursor keys, but to edit that text, the Шаблон:Key key was pressed to copy it to the input area where it could be edited.Шаблон:Sfn

Another difference on the Atom was the Шаблон:Key key, which performed a system reset, potentially clearing out the program from memory. To reset this if the key was pressed by mistake, Atom BASIC added the Шаблон:Code command, which could also be used to reset an accidental Шаблон:Code. A more minor change was that Шаблон:Code used comma-separated to and from line numbers instead of the minus sign, Шаблон:Code prints out lines 20 to 40.Шаблон:Sfn

The language also had the ability to use line labels instead of numbers for branching. Labels consisted of a single lower-case letter typed immediately after the line number. For instance:Шаблон:Sfn

10s PRINT "*"
20 GOTO s

The advantage of this method is that the memory address of the statement is stored in s, meaning that the branch, a GOTO, can move directly to that line without having to search through every line in the program looking for the matching line number.Шаблон:Sfn Acorn also allowed any expression to be used to produce the line number for branch targets, like Шаблон:Code.Шаблон:Sfn

Statements

Acorn's primitives were similar to other BASICs of the era, and supported most of the elementary statements like Шаблон:Mono.Шаблон:Sfn There are a number of common statements that are missing, notably Шаблон:Mono used to store data in a program, Шаблон:Mono computed branches, and Шаблон:Mono for user-defined functions.Шаблон:Efn

To these basics, Acorn added Шаблон:Code for the construction of bottom-tested, expression-based loops. FOR loops are highly optimized by using a direct comparison between their index variable and a constant value that is set only once upon entry into the loop. Another optimization is that the address of the FOR is stored, not the line number, so when the matching NEXT is encountered the program can immediately branch back to the FOR. While FOR is suitable for many loops, when more control is needed, for instance when comparing against a more complex criterion, the IF statement may be used:

500 A=A+1
510 REM additional statements here
600 IF A>10 AND B>100 THEN 500

The downside to this style of loop is that the branch requires the program to be searched through for line 500, which, in a loop, normally happens many times. In large programs, this can introduce significant overhead. Using a DO for this purpose offers higher performance:

500 DO A=A+1
510 REM additional statements here
600 UNTIL A>10 AND B>100

In this case, like the FOR loop, the address of the DO is stored when the loop is entered, allowing the UNTIL to return to the top of the loop immediately without having to scan through the program.Шаблон:Sfn Note the special case that the DO can be followed directly by another statement without the semicolon separator being required - the Шаблон:Code is not part of the Шаблон:Code, it is a separate statement.Шаблон:Sfn

Among the more minor additions is the Шаблон:Code statement, which paused execution until the next clock tick, every Шаблон:Frac of a second. This does not wait for one entire tick, just until the next tick, which may happen immediately.Шаблон:Sfn Шаблон:Code calls a machine language routine,Шаблон:Sfn the analog of Шаблон:Code or Шаблон:Code in most dialects.Шаблон:Sfn

Math, operators and functions

Acorn used 32-bit signed integers for all math,Шаблон:Sfn with no standard floating-point support. To handle division, which often returns a fractional part, they added the Шаблон:Code operator to return the remainder. For instance, Шаблон:Code will return 2, while Шаблон:Code will return 1.Шаблон:Sfn

Variable names can consist only of a single letter, A to Z.Шаблон:Sfn All double-letter combinations are reserved as arrays, so E was a single value, while EE was an array. All arrays required a DIM statement,Шаблон:Sfn it did not assume a dimension of 10 like Microsoft BASICs. At runtime, the only check performed on an array was that the index being passed in was a positive value, so one could read off into memory by passing in values larger than the dimension.Шаблон:Sfn It did not support multi-dimensional arrays.Шаблон:Sfn

Basic math operations included Шаблон:Mono. It also supported bitwise logic operators, with Шаблон:Mono used for AND, OR and XOR, respectively. These operators perform comparisons, so Шаблон:Code returns 0. The use of the colon for ORШаблон:Efn is why the statement separator had to use the semicolon.Шаблон:Sfn Note that these are separate from the logical connections found in IF statements, like Шаблон:Code, which are also supported.Шаблон:Sfn

There were only two math functions, Шаблон:Mono and Шаблон:Mono. ABS works as in other BASICs, returning the absolute value of a given input. RND does not, it returns a value between the -ve and +ve maximum integer values. To use this in the conventional form to return a value between 0 and a given positive value, between 0 and 10 for example, one used Шаблон:Code.Шаблон:Sfn

Vectors

Most BASICs of the era used PEEK and POKE to access machine specific functionality that was not built into the language itself. Acorn did not have PEEK and POKE, and used new operators to provide this functionality in an easier-to-use system. The operators were Шаблон:Code and Шаблон:Code, the former setting or returning the byte at a given location, and the latter setting or returning a 4-byte "word".Шаблон:Sfn For instance, common examples of PEEK in most dialects, like Шаблон:Code, could be accomplished with Шаблон:Code.Шаблон:Sfn Most dialects lacked the equivalent of the !.Шаблон:Efn Moreover, the same syntax could be used to set the value in memory, like a POKE, for instance, Шаблон:Code.Шаблон:Sfn

To aid in accessing data arranged in a continual form in memory, like arrays of numbers, the operators could be applied to the right-hand side of a variable. When used in this way, like Шаблон:Code, the system accessed the memory at the variable's location in memory. Any number following the operator was applied as an offset, so for instance, Шаблон:Code would return the value of the byte 100 locations after the location of A in memory.Шаблон:Sfn

This was often used with another Acorn-only concept, the "vector". Confusingly, these were created using the same DIM commands as an array, but applied to single-letter variables. When the DIM was encountered the system would set aside that many locations at the top of memory, and then move the memory pointer up. This left a block of memory that could then be accessed with the indirection operators. For instance:Шаблон:Sfn

10 DIM A(100)
20 PRINT A?10

Which will print the byte value at the 11th location in A (all accesses are zero-indexed).Шаблон:Sfn Likewise, one could store values in memory using the same operator applied before the variable name:

!A=123456

This will convert the decimal value 123456 from ASCII into an integer and store it in the memory locations starting at the base location for A.Шаблон:Sfn

To aid operation with vectors, Acorn added the pseudo-variable Шаблон:Code. When the system first started up, it pointed to the first location past the end of the program. Any DIMs were then created at the current value of TOP, and TOP was then updated to the end of the new object. It was possible to create dynamic vectors by directly manipulating TOP.Шаблон:Sfn

Strings

Atom BASIC added string support but did not support string variables nor did it have the concept of a string as an atomic type. Instead, the vector system was used to manipulate string data in memory, as ASCII values.Шаблон:Sfn To aid this usage, the Шаблон:Code operator converted in-memory values to their ASCII values. This operator continued reading data from memory until it encountered a return, and when writing data to memory, always added a return at the end.Шаблон:Sfn So while Шаблон:Code would print the single value of the byte at A's location in memory as a number, Шаблон:Code would read the values starting at that location and print it as a string.Шаблон:Sfn For instance:

10 DIM A(12)
Шаблон:TypoA="HELLO, WORLD"
30 PRINT $A

This code may appear very similar to the use of strings in other dialects, although the location of the $ relative to the variable name changes. It is especially similar to those dialects that required a DIM on all strings, like HP Time-Shared BASIC or Atari BASIC. Internally, the operation is very different. In those dialects, A and A$ are two different variables and the $ is, in effect, part of the name. In Acorn, A and $A they are the same variable, and the $ is applying a unary operation to that variable. This also means one can use arrays for strings, like Шаблон:Code, which converts the value in AA(10) to a string.Шаблон:Sfn

This concept allows individual characters to be accessed using vector notation. For instance, Шаблон:Code would return the ASCII value of the 5th character, 79 for O in this case, while Шаблон:Code would output "O".Шаблон:Sfn There is no way to extract a substring in a single operation, one has to loop over the characters and move them one-by-one. Concatenation is possible by assigning one variable to the end of another, for instance, Шаблон:Code copies the string B to the end of A.Шаблон:Sfn

The language has only two string functions, Шаблон:Code which looks for the trailing return character and returned the length, and Шаблон:Code to return the ASCII value of a character. CH has an odd format with no parens, so Шаблон:Code would return 65.Шаблон:Sfn It is otherwise similar to the more common Шаблон:Code seen in other dialects.Шаблон:Sfn

Another new operator was Шаблон:Code, which converted a numeric value into a hexadecimal string. Like $, this could be used anywhere to perform the conversion. For instance, Шаблон:Code sets the value of A to the decimal value 16384, the location of the screen memory. This was often combined with the $ operator to allow strings to contain unprintable characters, like the "cursor up" character.Шаблон:Sfn

Floating point

Floating-point support could be added with the additional 4 KB ROM expansion. This used an expanded 40-bit word size, 32 bits of signed mantissa followed by an 8-bit exponent.Шаблон:Sfn This meant the system needed some way to distinguish the data when reading and writing from memory, which was handled in a fashion similar to the string operator, using the Шаблон:Code prefix:Шаблон:Sfn

 %A=123.45

As the code was contained in a separate 4 KB ROM, it did not modify existing statements like PRINT. Instead, an entirely new set of statements was introduced, including Шаблон:Mono. This means, for instance, that one cannot Шаблон:Code if the values are floating point, one must instead Шаблон:Code. An integer value can be converted to float using the Шаблон:Code, and float to integer using the float operator, %.Шаблон:Sfn

The ROM also included a much larger variety of math functions, including Шаблон:Mono.Шаблон:Sfn Шаблон:Code converted a floating-point number into a string, as was the case for Шаблон:Code in other dialects, but in this case, the string was written to memory and the function returned the address where it was stored. As the string required storage long enough to hold it, this was often accomplished using TOP. For instance:

 STR PI, TOP
 PRINT $TOP
 TOP=TOP-LEN(TOP)

This converts the value of the pseudo-variable PI to a string starting at memory location TOP, prints the string using $TOP, and then abandons that memory.Шаблон:Sfn

Input/output

Шаблон:Code and Шаблон:Code mostly worked as in other dialects. One oddity came about because the colon and semicolon were already used for other purposes, leaving only the comma to separate fields. To print values with no spaces between them, the values were listed with a space character between them, like Шаблон:Code, a format that was also allowed on many other dialects although rarely used. This alone would not cause numbers to be printed in compact format, because they are normally printed with spaces on the right to make each one 8 characters wide This could be adjusted by changing the value in the Шаблон:Code pseudo-variable.Шаблон:Sfn A newline was printed with a single quote, Шаблон:Code.Шаблон:Sfn Шаблон:Code returns the cursor column, similar to Шаблон:Code in most dialects.Шаблон:Sfn

The default storage device for the Atom was a compact cassette system. Each file was stored as a series of blocks, each of which contained a header with the filename.Шаблон:Sfn Files saved with Шаблон:Code could be read back in with Шаблон:Code, whilst Шаблон:Code listed the names of the files on the cassette as it read past their headers.Шаблон:Sfn

Arbitrary data could be opened for reading using Шаблон:Code or writing with Шаблон:Code, both of which returned a numeric file handle. Files were closed with Шаблон:Code. Data was read or written in numeric format using Шаблон:Code, as single bytes with Шаблон:Code, and as strings using Шаблон:Code. The Шаблон:Code returned the length of the file, while Шаблон:Code returned or set the current pointer in the file, Шаблон:Sfn the number of bytes read or written so far.Шаблон:Sfn If the floating-point ROM was present, it added Шаблон:Code.Шаблон:Sfn

For instance:

A=FOUT"AFILE"
DO BPUT A,88; WAIT; WAIT; WAIT; WAIT; UNTIL 0

Will use the Шаблон:Code to write a series of bytes, 88s, until the user presses Шаблон:Keypress to stop the program. They can then be read back in (after manually rewinding the tape) using:Шаблон:Sfn

A=FIN"AFILE"
DO PRINT $BGET A; UNTIL 0

The dollar sign tells the system to convert the incoming binary data to string format, so in this case, the output will be a series of X's, not 88's.Шаблон:Sfn It might seem that SGET could be used instead of BGET, but this would attempt to continue reading from the file until it saw a return character, which in this example had not been written.Шаблон:Sfn

Graphics support

The Atom had rudimentary bitmap graphics and Atom BASIC added a number of commands to support it. Шаблон:Code cleared the screen, Шаблон:Code moved the graphical cursor to the given X,Y location, and Шаблон:Code drew a line from the current location to the provided X,Y.Шаблон:Sfn

The floating-point ROM also included support for colour graphics with the addition of the Шаблон:Code statement. Calling COLOUR with a parameter 0 through 3, sets the subsequent output to that colour. On a black-and-white display, the colours were shown as shades of grey.Шаблон:Sfn

Notes

Шаблон:Notelist

References

Citations

Шаблон:Reflist

Bibliography

Шаблон:BASIC