********* Welcome to Project 64! The goal of Project 64 is to preserve Commodore 64 related documents in electronic text format that might otherwise cease to exist with the rapid advancement of computer technology and declining interest in 8- bit computers on the part of the general population. If you would like to help by converting C64 related hardcopy documents to electronic texts please contact the manager of Project 64, Cris Berneburg, at 74171.2136@compuserve.com. Extensive efforts were made to preserve the contents of the original document. However, certain portions, such as diagrams, program listings, and indexes may have been either altered or sacrificed due to the limitations of plain vanilla text. Diagrams may have been eliminated where ASCII-art was not feasible. Program listings may be missing display codes where substitutions were not possible. Tables of contents and indexes may have been changed from page number references to section number references. Please accept our apologies for these limitations, alterations, and possible omissions. Document names are limited to the 8.3 file convention of DOS. The first characters of the file name are an abbreviation of the original document name. The version number of the etext follows next. After that a letter may appear to indicate the particular source of the document. Finally, the document is given a .TXT extension. The author(s) of the original document and members of Project 64 make no representations about the accuracy or suitability of this material for any purpose. This etext is provided "as-is". Please refer to the warantee of the original document, if any, that may included in this etext. No other warantees, express or implied, are made to you as to the etext or any medium it may be on. Neither the author(s) nor the members of Project 64 will assume liability for damages either from the direct or indirect use of this etext or from the distribution of or modification to this etext. ********* The Project 64 etext for Commodore BASIC articles #1, converted by anonymous. This etext was created by concatenating several documents into one. All of the included documents were retrieved from the Headgap BBS, sysop Bob Nunn, telnet://bbs.headgap.com:1474, login: guest, password: guest. Basic Language (11 - Basic Language). Introductory Basic Lesson (13 - Begin Basic 1). Basic (14 - Begin Basic 2). BASIC110.TXT, July 1996, etext #63. ********* The Project 64 etext of Basic Language (11 - Basic Language). ********* BASIC LANGUAGE AUTHOR: UNKNOWN FROM: CLARKSVILLE COMMODORE USERS GROUP BASIC (Beginners All-purpose Symbolic Instructional Code) was developed in 1963 by John G. Kemeny and Thomas E. Kurtz at Dartmouth University for use with a time-sharing computer system developed by General Electric. BASIC is the most used computer language. At one time BASIC was the first Computer language taught in Computer Science classes because of its relative simplicity and similarity to plain English. BASIC is a High Level computer language, that is, it is a language that is people oriented rather than a machine oriented language (i.e. Machine Language). BASIC as used on the C-64 is an Interpreted language, each Command in BASIC calls upon one or more built in Machine Language routines during execution. Interpreted languages are much slower in execution than Machine language because of this. BASIC can be Compiled using a special program called a Compiler. A Compiler scans the BASIC language program, converts it to Machine Code and re-writes the program back to the mass storage device in compiled form. A Compiled Program can RUN on the order of 100 times faster than the Interpreted version. The original BASIC Program is called the Source Code and the Compiled version is the Object Code. Now-a-days BASIC has fallen from favor with Colleges and PASCAL is generally taught as the first Computer language. PASCAL is a highly structured language, that is, the structure of the program is very rigid. EXAMPLE: All Variable names and Variable types that are going to be used in the program must be declared at the beginning of the program: VAR EMPLNO: INTEGER; HOURS,RATE: REAL; P,Q: BOOLEAN; C: CHAR; other parts of the PASCAL program are equally rigid in structure. One of the reasons to teach PASCAL rather than BASIC is because computer programming is a highly logical occupation and rigidly structured languages force the programmer to think through the problem carefully before writing the program. Also the structure of the program makes it self-documenting. Microsoft BASIC (Version 2.0) the language used by the C-64 contains over 70 different Commands. The possible number of ways of combining these Commands is so large that my computer cannot calculate it. One of the things to take into account when writing a computer program is whether to make it transportable or not. Consider the simple task of clearing the screen, you can clear it by typing: 10 PRINT "Reverse Video Heart" If you use this method and later want to make your program RUN on a different manufacturers computer it will have to be changed. You can also Clear the Screen by typing: 10 PRINT CHR$(147) If you use this method this line will run on any manufacturers computer. To make your programs more transportable use the ASCII CHAR$ for control functions where possible and avoid using PEEKS and POKES (because the addresses are different on different machines). ********* End of Basic Language (11 - Basic Language). ********* The Project 64 etext of an Introductory Basic Lesson (13 - Begin Basic 1). ********* Introductory Basic Lesson Commands vs. Statements: BASIC makes a distinction between what are know as commands and statements. The PRINT statement tells the computer to display information in the screen for us to look at. So what's a command? We use commands to tell BASIC directly that we want it to do so mething for us. Normally, commands are typed in directly, although it is possible for them to be used in programs. We just type in the command and BASIC goes and executes it. We dont use line numbers, as we would for statements in a program. Here are some of the most important commands that you will need to know to effectively write programs in BASIC: LIST RUN SAVE LOAD NEW LIST: When we want to look at a program that we have typed in, especially a large one, we use the LIST command. By typing LIST, we are telling BASIC that we want to see our program, to have it LISTed for us. BASIC responds by displaying the whole program on the screen, starting with the lowest line number and displaying lines in ascending order until the end of the program is reached If the program is large, it may scroll off the top of the screen as it is being listed. Type in this short program, which we will use to demonstrate how commands work. 10 PRINT "THIS PROGRAM WILL BE USED" 20 PRINT "TO DEMONSTRATE BASIC COMMANDS" 30 PRINT "IMPORTANT BASIC COMMANDS ARE" 40 PRINT "LIST" 50 PRINT "RUN" 60 PRINT "SAVE" 70 PRINT "LOAD" 80 PRINT "NEW" 90 END Be sure to hit the return key after each line that you enter. Now type LIST. The program that you just typed in is displayed on the screen. You can LIST an entire program, or only part of it. You can list individual lines, if you want. Try LIST 20. Line 20 will be LISTED. You can also LIST a range of lines by using the hyphen (-). Try this: LIST 20-60. Line 20-60 will be LISTED. You can LIST a program up to a certain point from the beginning. Try LIST -70. The program, up to line 70, is displayed. Finally, you can LIST a program from a certain point to the end. Try LIST 30-. What happens? Do you see how LIST helps you look at all or part of your program? RUN: RUN is the command that you give BASIC when you want your program to be translated into action by the computer, or to be EXECUTED. When BASIC executes your pr ogram, it starts with the lowest line number, and carries out the instuctions it finds on each line, in ascending order, until it reaches the END statement. What do you think the program you typed in will do when you type RUN? Type RUN ,and see if you were right. The program should have printed the following on the screen. THIS PROGRAM WILL BE USED TO DEMONSTRATE BASIC COMMANDS IMPORTANT BASIC COMMANDS ARE: LIST RUN SAVE LOAD NEW SAVE: After we have typed in a program we usually would like to save our work; otherwise, we'd have to type in the program in again every time we wanted to use it. Fortunately, there are magnetic disks that we have to save pro grams on. When you save a program, you have to give it a name so that you can refer to it later if you want to use it. The name, or FILENAME, can be almost any combination of letters and characters, but it's a good idea to use a name that makes sense to you so you can more easily remember what the program is used for. You would use the SAVE statement like this: SAVE "filename",8. You substitute, where it says 'filename', the name for the prog ram that you have chosen. The name must appear in double quotes , as indicated. The comma and the 8 are used to tell BASIC t hat you want to save this program to disk (BASIC associates the DEVICE NUMBER 8 with your disk drive). For example, if you choose DEMO for a name, you would SAVE the program like this: SAVE "DEMO",8 Make sure that you have a formatted disk in your disk drive and the program will be saved. LOAD: LOAD is the exact opposite of SAVE. When we want to work on a program that we have previously saved to disk, we have to LOAD it into the computer. The comm and looks like this: LOAD "filename",8. To load the program that we just saved, assuming that it was named DEMO, we would type: LOAD "DEMO",8. The program will be loaded into memory for us to RUN, LIST, or edit. You have to use the exact name to load a program that you used to save it or else the the computer will not know what file you are looking for and respond with FILE NOT FOUND ERROR. NEW: What if you're done with a program and want to start working on a new one. This is where the NEW command comes in. It tells BASIC that you want to start work on a new program and to clear things out so you can start from scratch. Make sure that you have saved the example program, and now type NEW. Now try to LIST the program. What happens? Try RUNning it? What happens now? As you can see, BASIC has thrown out your program and doesn't know anything about it anymore. You can now start working on a new program, or you can bring back the old one, by LOADing it. Be sure to be very careful with the NEW command, or you might lose some work after working on it for a long time! Line Numbers: You may have wondered how you would get rid of a program line that you didn't want in the program anymore. With BASIC, deleting lines is very easy. All you have to do is type the line number that you want to delete and hit the RETURN key. The requested line will be deleted. If you have the sample progam saved, type 20 and hit RETURN. Now try listing the program. Line 20 should have been deleted from the program. That will wrap up this lesson. Try practicing these commands until you are confortable with them. ********* End of an Introductory Basic Lesson (13 - Begin Basic 1). ********* The Project 64 etext of Basic (14 - Begin Basic 2). ********* BASIC BASIC is an high level language that can be used to solve a problem or perform some function on a computer. We can think of a program that we write in BASIC as a set of instructions for the computer to follow to perform some task Usually, a program will require some sort of data to operate on. It will then process the data as we have specified, and finally it will provide us with the result of that processing. The data that we give to a BASIC program is called INPUT. The answer that that we get back is called OUTPUT. As the program executes, the computer uses memory to store and retrieve data. In any high level language, there must be some convenient means for the program to retrieve, store, and process data easily. NUMBERS AND LITERALS: We've seen how the PRINT statement works, and how we can use our computer like a calculator: PRINT 5 PRINT 43 + 12 PRINT "HELLO THERE" Numbers, like 5, 43, 12, and literals, like "HELLO THERE", are what are known as CONSTANTS. Their value never changes. VARIABLES: A variable is a symbol used to represent a number or a character string. As the name implies, a variable can be changed by the programmer at any time. A variable is given a name, and through this name, we refer to some number or character string stored in memory. ASSIGNMENT STATEMENTS: A variable is assigned a value through what is know as an assignment statement. The LET statement lets us accomplish this: 10 LET X=1 20 PRINT X 30 END In this program, the variable X is given the value 1, and is then printed. The value of a variable can be changed at will: 10 LET X=1:LET X=2 20 PRINT X 30 END In this program, the variable X is fi rst assigned the value 1, and then is reassigned the value 2. When the program is RUN, the value 2 will be printed. The Statement LET is optional, and X=1, and LET X=1 do exactly the same thing: 10 X=1 20 PRINTX 30 END VARIABLE NAMES: You must follow these rules when giving names to variables: 1) The first character must be a letter. 2) The second character is optional, a letter or a number. 3) Only the first 2 characters in the variable name are significant. Names can be longer than 2 characters, but BASIC' sees' only the first 2 Characters. The names RATE RAT RA are all seen by BASIC as the variable RA. 4) The third character may be % if the variable is to be used to take on integer (whole number) values, or $, if the variable is to be used for character string val ues, like "OUR HOUSE", or "COMMODORE", EXAMPLES: A=5.3 numeric variable A%=5 integer variable A$="HELLO THERE" character variable Here are some examples of valid variable names: A X1 B4 CC J$ K% K3 NN$ Variables may be used in mathematical expressions or character string manipulations. Let's write a short program to add 2 numbers and print out the answer: 10 A=7 20 B=3.5 30 C=A+B 40 PRINT C 50 END THE INPUT STATEMENT: How do we get data to our program to process? This is accomplished by using the INPUT statement. When a program encounters this statement, it stops, and waits for the user to enter some input data. The user will be prompted with a ? symbol, and may then enter the data, terminated by pressing the RETURN key. Here's a simple example of a program to take a number from the user and print it out. 10 INPUT A 20 PRINT "YOU ENTERED THE NUMBER ";A 30 END The program should always prompt the user for the kind of input required. This can be done with a PRINT statement or the INPUT statement itself. 10 PRINT "ENTER A NUMBER" 20 INPUT A 30 PRINT "YOU ENTERED THE NUMBER ";A 40 END or: 10 INPUT "ENTER A NUMBER";A 20 PRINT "YOU ENTERED THE NUMBER ";A 30 END Let's write a program to take 2 number from the user, add them together, and print out the answer. 10 PRINT "ENTER THE FIRST NUMBER" 20 INPUT A 30 PRINT "ENTER THE SECOND NUMBER" 40 INPUT B 50 C=A+B 60 PRINT "THE SUM IS ";C 70 END INPUT can be used to enter more than one value at a time. 10 PRINT "ENTER THE 2 NUMBERS SEPARATED BY A COMMA" 20 INPUT A,B 30 C=A+B 40 PRINT C 50 END Try experimenting with variables, and the INPUT statement. Have Fun! ********* End of Basic (14 - Begin Basic 2). ********* The end of the Project 64 etext for Commodore BASIC #1. *********