请输入您要查询的百科知识:

 

词条 Draft:TRS-80 Level II BASIC
释义

  1. Background

  2. Program editing

  3. Variables

  4. Program control

  5. Mathematical functions

  6. Input/Output

  7. Graphics

  8. Disk BASIC

  9. Model III modifications

  10. Model IV BASIC

  11. References

{{AFC submission|t||ts=20181018061207|u=Kalunk|ns=118|demo=}}{{about|the standard BASIC for the TRS-80 Model I/III/IV|TRS-80 Color Computer BASIC|Color BASIC}}{{Infobox software
| name = TRS-80 Level II BASIC
| logo =
| developer = Microsoft, Tandy
| author =
| released = {{Start date and age|1978}}
| latest release version = Level IV
| latest release date = {{Start date and age|1983}}
| platform = TRS-80
| genre = BASIC
| license = Commercial proprietary software
}}

TRS-80 Level II BASIC is an interpreter for the BASIC programming language that shipped with the TRS-80 family of Z80-based home computers.

The language was included in the ROM of the Model I and occupied 12kb. On the Model III, it was increased to 16kb in size. On the Model IV, BASIC was entirely disk-based and RAM-resident, occupying about 17kb.

Background

When Radio Shack initially developed the Model I in 1977, they licensed Li-Chen Wang's Tiny BASIC as the built-in operating environment for the computer, but it was only intended as an interim until Microsoft's BASIC-80 could be ported. The first Radio Shack brochure for the Model I in January 1978 mentioned that Level II BASIC would be "available soon".[1]

At the time, Microsoft offered several versions of BASIC for the Z80 microprocessor, an 8kb, an extended, and a disk version. The extended BASIC included several enhancements such as double precision floating point capability and descriptive error messages. It was 12kb in size, however since it was necessary to also include statements from Level I BASIC, in particular the commands for setting graphics blocks, the resulting interpreter would be too big to fit into the computer's 12kb ROM space. Microsoft produced a BASIC port that was roughly halfway between 8kb and Extended BASIC, including some but not all of the latter's features. The port took four weeks of work. Radio Shack began offering Level II BASIC in June 1978, along with the introduction of floppy disk drives and the TRS-80 Expansion Interface.

Users with disk drives had access to TRS-80 Disk BASIC, which added most of the remaining Extended BASIC features and was around 16kb in size.

Program editing

Level II BASIC uses a line editor like most home computer BASICs. The BASIC command prompt is a > character and Radio Shack changed the Ok prompt in Microsoft's original source code to "Ready".

The EDIT statement is used to modify program lines; it has several options such as I for Insert and D for Delete. Cassette Level II BASIC does not display descriptive error messages, instead a two letter error code is shown. If Disk BASIC is used, full descriptive errors are printed. Program lines can be as long as 255 characters, not counting the line number. The user may "crunch" program lines by omitting spaces; since the tokenizer does not remove these automatically, they will use extra memory if included in a program line. Line numbers have a maximum value of 65520. The INPUT statement cannot be executed in direct mode since the buffer used to hold direct mode commands is also used by INPUT and CONT cannot be executed within a program, otherwise all BASIC statements, functions, and commands work in either direct or program mode.

Three abbreviations are permitted in Level II BASIC: ? can be used as shorthand for the PRINT statement (it will be displayed as PRINT when the program is LISTed), ' can be used in place of REM, and . is used to duplicate the last program line typed.[2]

Variables

Level II BASIC recognizes four variable types. These are integer, string, single, and double precision. Integer variables occupy two bytes of memory and have a range of -32767 to 32768. Single precision variables are four bytes in length, three being the exponent and one being the mantissa. Double precision variables are eight bytes in length; seven exponent and one mantissa. String variables hold a character string or an array of strings; each string has a maximum length of 255 characters.

Arrays may be created which consist of a "block" of variables, thus if an integer array of six elements is created via the statement DIM A%(6), this will create six integer constants which are referenced by the index number, the lowest element in the array being 0. String array elements refer to discreet strings whose space is allocated dynamically, the same 255 character limit applying to each string in the array. Arrays may consist of up to three subscripts, thus DIM A%(3,6,4) will create a total of 13 integer constants, occupying 26 bytes of memory. Generally, it is necessary to dimension arrays prior to use with a DIM statement, if this is not done, BASIC automatically sets an array to ten elements.

Variable names can only contain alphanumeric characters and may not be a reserved word. The first character must be a letter. Variable names have no limit to their length, but only the first two characters are significant, thus the variable names FOOTBALL, FOOD, and FOUR all reference the same variable.

The % symbol is used to designate a variable as integer, ! indicates single precision, # double precision, and $ string. If no variable designation is used, the default type used is single precision. The user may also use the DEFx statement to designate a range of variables as a specific type. Double precision variables may not be used as the index of a FOR...NEXT loop, nor as the argument of mathematical functions such as ATN or COS.

If strings are used extensively in a program, it will be necessary to reserve string space with the CLEAR statement. BASIC defaults to either 50 or 100 bytes of string space (depending om the ROM revision) if CLEAR is not used to reserve it. The CLEAR statement with no parameters will delete all variables and arrays by resetting their pointers, freeing the memory space they occupy, and beginning program execution with RUN will also clear them.[3]

The FRE function cleans up string space garbage when executed, due to an inefficient method of garbage collection, this process can be extremely slow, sometimes an hour or more if many large strings are present.

Program control

The FOR...NEXT loop is used to perform a code loop according to the number of times specified, the counter variable is increased or decreased by one (the STEP clause may be used to specify other increments) with each iteration of the loop until it reaches the ending value, whereby the loop terminates. NEXT is usually followed by the index variable, however it may be omitted for slightly faster program execution. Nested FOR...NEXT loops may also be used.

IF...THEN is used for conditional actions via a Boolean expression. If the expression is false, execution continues on the next program line. If it is true, all statements on the program line following THEN are executed. Level II BASIC also supports ELSE clauses, which are not present in all BASIC implementations. Although conditional jumps are usually done via a statement such as IF A=1 THEN 50, BASIC will also accept GOTO in place of THEN (thus IF A=1 GOTO 50) which will execute slightly faster. This cannot be done with GOSUB statements and it is necessary to type IF...THEN GOSUB.

The GOTO statement performs a jump to the specified line number. GOSUB operates similarly to GOTO, but it saves the line number on the stack and goes to the statement following the GOSUB if a RETURN statement is encountered. Care must be taken with GOTO statements to avoid "spaghetti" code which is difficult to trace and debug and with GOSUB to avoid having too many nested subroutines which may cause BASIC to run out of stack space.

Mathematical functions

Level II BASIC contains a full set of commands for trigonometric calculations and handling numeric data. These include ATN, COS, EXP, SQR, COS, and SIN. The RND statement is used to generate a random number. It has two forms. The first is RND(0) which generates a fractional number between 0 and 1, and the second is RND(1) which generates an integer between 1 and 32768. Random number generation is in practice pseudo-random since the numbers are produced via a hash stored at $40AA. The RANDOM statement refreshes the hash via the CPU's Refresh register. As mentioned above, mathematical functions do not accept double precision numbers or variables as arguments, they will be truncated down to single precision.

Input/Output

Level II BASIC has an extensive series of commands for I/O and file handling. PEEK and POKE display and modify the contents of memory locations, INP and OUTP display and modify the Z80 CPU's I/O ports, and OPEN, CLOSE, and other commands are used to manipulate disk and tape files.

BASIC has the so-called Monitor Mode for loading machine language programs off of cassette, this is invoked by typing SYSTEM, which brings up the monitor prompt. Typing a filename will attempt to load a program from cassette and / (followed by an optional address) will execute the program.

If Disk BASIC is running, typing CMD "S" will exit out of BASIC to the DOS command prompt. Any BASIC program in memory will be lost.

Graphics

The TRS-80 lacks a true graphics mode the way computers such as the Apple II do and instead has pseudo-graphics via graphics characters. The command SET turns on a graphics block and RESET turns it off. CLS clears the screen.

The cursor is moved around the screen via the PRINT @ statement, which is used to specific an absolute coordinate on the screen rather than a row and column position as in many other BASICs.

Disk BASIC

Level II Disk BASIC, aside from providing support to manipulate disk files and save and load BASIC programs to disk, added several other features including full description error messages and user defined functions.

Model III modifications

Cassette BASIC on the Model III incorporated the functions from Disk BASIC not directly related to disk I/O, this included user defined functions and increased the total size of BASIC to 16kb.

Model IV BASIC

In 1983, Radio Shack replaced the Model III with the Model IV, which could either run in Model III mode or its own native move. The Model IV's BASIC was RAM-resident and differed significantly from the older Level II BASIC. It was based on the newer Microsoft BASIC-80 version 5.x and included a number of enhancements such as WHILE...WEND loops for structured programming, 40 character variable names, and integer division. Program statement crunching was no longer allowed and the user had to type spaces in program lines. It was also possible to save BASIC programs in ASCII instead of tokenized format. The CLS and PRINT @ statements were carried over from Level II BASIC, however the SET and RESET commands were removed. Level IV BASIC also removed cassette support.

References

1. ^{{cite web | url=http://www.trs-80.com/wordpress/catalogs-radio-shack/ | title=TRS-80 Catalogs: Radio Shack Catalogs | Ira Goldklang's TRS-80 Revived Site}}
2. ^{{cite web | url=http://www.trs-80.com/wordpress/info-level-2-basic-language/ | title=TRS-80 Model I Level 2 BASIC Language Reference | Ira Goldklang's TRS-80 Revived Site}}
3. ^"Level II BASIC Reference Manual", (C) 1978 Radio Shack
随便看

 

开放百科全书收录14589846条英语、德语、日语等多语种百科知识,基本涵盖了大多数领域的百科知识,是一部内容自由、开放的电子版国际百科全书。

 

Copyright © 2023 OENC.NET All Rights Reserved
京ICP备2021023879号 更新时间:2024/11/12 2:14:50