BASIC

From DenialWIKI
Jump to: navigation, search
10 PRINT "HELLO MY NAME IS VIC"
20 GOTO 10

History

The VIC-20 computer shipped with a copy of Microsoft BASIC 2.0 in ROM. This was available when the computer was turned on.

The BASIC computer language was developed in 1963 at Dartmouth College in the USA. Microsoft (then called Micro-Soft) wrote a cut down version for personal computers in the mid 70's and sold it on to Commodore computers who placed it in their line of personal computers. The main benefit of this version is that it takes up very little space in the 8K ROM and programs are very small. The disadvantages are that it is very slow and somewhat inflexible, although when combined with the hardware of the VIC-20 and machine code it was very capable. Commodore did a deal with Micro-Soft granting them an unlimited licence for the usage of their BASIC as well as removal of the Micro-Soft name from the BASIC. Which is why it is called CBM BASIC not Micro-Soft BASIC.

Capabilities

Immediate versus Execute mode

When the VIC-20 is first started the user can type commands in what is called immediate mode. It is called this because the commands are executed after the return key is pressed.

PRINT "HELLO"
HELLO

READY.

Commands can be separated by the colon character :

FOR I = 1 TO 5 : PRINT I : NEXT I
 1
 2
 3
 4
 5
READY.

Immediate mode is useful for testing commands before placing them in a program. In Execution mode the VIC executes commands that have been typed in with line numbers before them. The VIC goes from the lowest line number to the highest unless otherwise directed. These BASIC lines are entered like immediate mode but they are not executed until a run command is called

10 FOR I = 1 TO 5
20 PRINT I
30 NEXT I

RUN
 1
 2
 3
 4
 5

READY.

The READY. prompt means that the VIC has finished executing commands and is ready to accept new immediate commands or to edit BASIC lines

Keywords

String functions
Maths functions
flow control Looping and branching
IO functions
Logic functions
Misc functions variables, memory, comments

Variables

Maths

Strings

Memory and Hardware access

Using the peek and poke commands BASIC can access the entire 64KByte address space of the VIC. This also enables BASIC programs to access most hardware since most of the hardware is memory mapped. The serial port devices like the Floppy Drive can be used via the built in BASIC DOS commands.

Example of changing a screen memory location using BASIC:

POKE 7680,65

Example of reading a joystick fire button from BASIC:

POKE 37154,255 : F = -((PEEK(37137)AND32)=0)

Example of a BASIC program reading a file from the Floppy Drive. It is assumed, that the drive has the device no. 8, and the file is stored as SEQ, containing sequential data:

10 INPUT "FILE NAME";N$
15 OPEN 2,8,2,N$+",S,R"
20 GET#2,A$
25 PRINT A$;
30 IF ST=0 THEN 20
35 CLOSE 2
40 END

Combining with Machine Code

BASIC can use the poke command to copy a machine code program into memory. The program is normally copied from data statements. Then it is executed via the sys command.

10 FOR I =  0 TO 5
20 READ D
30 POKE 7168 + I,D
40 NEXT I
50 SYS 7168
60 DATA 169,0,141,15,144,96
Assembly Source
lda #$00    169 0
sta $900F   141 15 144
rts         96

If you end the machine code program with RTS then it will return execution to the BASIC program otherwise the machine code will keep running.

The main problem is that if you are not careful your machine code can be clobbered by BASIC variables. The answer is to place it in memory that is known to be safe for certain times (like the tape buffer) or to change the end of the BASIC area with two pokes.

REM PROTECT MEMORY FROM 7168+
POKE 55,0 : POKE 56,28 : CLR

Another usage of machine code is to call the KERNAL directly. In order to do so you must first set up the A, X and Y registers. The following code shows this to set the position of the screen cursor via the KERNAL routine PLOT

5000 REM CURSOR GOTOXY
5010 POKE 781,Y
5020 POKE 782,X
5030 POKE 783,0
5040 SYS65520
5050 RETURN

Documentation

Examples

Bill made a mistake

?""+-0