Commodore Basic V2

from Wikipedia, the free encyclopedia
Screenshot of the Commodore BASIC V2 on the C64

Commodore BASIC V2 is the BASIC dialectprimarily usedon the Commodore 64 (C64) and the Commodore VC 20 (VC20). With the C64, a BASIC V2 interpreter is permanently contained in the ROM and also serves as a user interface . This user interface is provided by a line-oriented editor also contained in the ROM. As input, the editor accepts the specification of a program line with a preceding line number (which it accepts without comment) or the specification of a command or system command that is executed directly (for example RUN , LOAD , SYS , PRINT ).

BASIC V2 is based on Microsoft BASIC and has been adapted for the C64.

Language elements

BASIC V2 works line-number-oriented, i.e. each line must be preceded by a number which also serves as a parameter for jump instructions and as a reference for error messages. Line numbers once assigned can no longer be changed directly. A line can be deleted without a query by entering the corresponding line number and pressing the return key. There is no system command for automatically renumbering the lines, so it is common to assign line numbers 10 (or more) apart. If lines are to be inserted later, the remaining numbers between two line numbers can be used. Any number of commands can be in each line, separated by colons. In principle, however, a program line must not be longer than 255 characters; In practice, the editor limits the length to two lines on the screen (80 characters). The interpreter does not need any spaces or other formatting characters and accepts short codes instead of the usual keywords, which are then automatically spelled out in the program. Structuring for better readability is only possible with spaces between keywords, but the lines can only be indented by inserting a colon at the beginning of the line.

In addition to the usual input and output commands ( PRINT , INPUT ), GET can be used to read out the value of a single keystroke.

For branching within a program, BASIC V2 supports the jump instructions GOTO , GOSUB / RETURN and the conditional jump instruction ON GOTO . In addition, SYS can be used to jump directly into a machine language program. The USR (x) function calls a machine language program as a function and receives a return value from it. The only language elements available for structured programming are counting loops ( FOR NEXT ).

Also not included are commands for the comfortable creation of sound, graphics and sprites . The POKE command and the PEEK (x) function are provided for direct access to the hardware , especially the memory .

Simple variables do not have to be declared before they can be used, the variable type is defined via their suffix ("$" for strings, "%" for integers, without a suffix for floating point numbers). For indexed variables , however, dimensioning with DIM is necessary if more than 10 elements per parameter (maximum three) are to be used. More complex variable types are not implemented.

Special variants of the input and output commands are available for the transmission of data from and to peripheral devices ( PRINT # , INPUT # , GET # ). In addition, there are OPEN , CLOSE and CMD for controlling printers, datasets and floppies .

Code sample

 10 input "Geben Sie bitte Ihren Namen ein"; a$
 20 print "Guten Tag "; a$
 30 input "Wie viele Sterne möchten Sie?"; s
 40 for i = 1 to s
 50 s$ = s$ + "*"
 55 next i
 60 print s$
 70 input "Möchten Sie noch mehr Sterne?"; q$
 80 if len(q$) = 0 goto 70
 90 l$ = left$(q$, 1)
 100 if (l$ = "J") or (l$ = "j") then goto 30
 110 print "Auf Wiedersehen";
 120 for i = 1 to 200
 130 print a$; " ";
 140 next i
 150 print

Web links