|
||||
Chapter 1 : Making the Machine do somethingYou now have two ways of using the command line. Which one you use will depend on your personal preference and whether or not you need to read something on the screen at the same time. The simplest command of all is one to make the machine tell us which version of the operating system it contains. To do this, type: fx0 following the star, so that the whole line reads: *fx0 The machine doesn't take any notice of whether the letters in star commands are capitals or lower case. Note, though, that the '0' is the figure nought, not the letter O. After you have typed this in, press Return (or the 'Enter' key on the right of the numeric keypad). All commands and lines of programming are followed by a press of the Return key, unless we say otherwise. This tells the machine that the line is finished, and that it should execute it, that is, do what the instruction in the line tells it to. A line will appear on the screen saying: RISC OS 4.02 (10 Aug 1999) or something similar, followed by another star on the next line. If you get something different, it means you mistyped the command. You have given the machine your first command and it has, hopefully, done what you told it to. If you received some other kind of message, it probably means that you made a typing error, in which case, try again. Now type: Cat so that the entire line reads: *Cat From now on, we will always show star commands with the star at the beginning. Of course, if there is already a star on the screen, you won't need to type one in, though it doesn't matter if you do. When you press Return, your hard disc will run and a list of the files and subdirectories in its root directory will appear on the screen. The command you have just given is the one to Catalogue the disc. Getting Into BasicNow that you've got the hang of typing in simple commands, it's time to investigate Basic, the language we will use for programming.Type: *Basic The machine will reply with a message saying: ARM BBC BASIC V version 1.20 (C) Acorn 1989 Starting with 651516 bytes free > This message shows that Basic has now started up. The figure on the second line shows the amount of free memory that Basic can use. This depends on how much memory your machine has and how much of it the desktop was going to allocate to your next application. You will notice that there is no longer a star inviting you to enter a star command. This is because you are no longer using the command line - you are now in Basic. The '>' character is the Basic prompt, inviting you to type in a command that Basic will understand. Type a number of characters at random, then press Return. Almost certainly the result will be a message saying 'Mistake'. This is an error message, which means that the machine couldn't understand what you meant. Introducing KeywordsBasic understands certain words, known as Keywords. There are over 100 of these and you'll find a full list of them and what they do in Appendix 1. They always have to be in capitals, for a reason which we will find out shortly. Turn on the CapsLock key, then type:PRINT "HELLO" Take care to use the double-quote (") rather than the single-quote(') symbol. Because it is not on a letter key, you'll have to press Shift to get it, even though CapsLock is on. When you press Return, the word HELLO should appear on the next line and the following line will contain the Basic prompt. If you receive an error message instead, it probably means that you made a typing error, possibly leaving out one of the quotes. ... the word HELLO should appear on the next line ...
The command PRINT in Basic doesn't mean 'Send to the printer' but 'Put on the screen'. This is for historical reasons. Basic was invented before the microchip and at that time there were no visual display units for computers - all communication from the computer to its operator had to be via a printer. Today, the command PRINT means 'Display on the screen'. The command that you typed in tells Basic to print whatever is between the quotes, which is why the word HELLO appeared on the next line. Of course, if you put something else between the quotes, Basic will print that. Try it. Storing Up a ProgramWhen you have finished this little experiment, type in the following:10PRINT "HELLO" You will notice that this is the same command as before, only this time we put a number in front of it. Now when you press Return, nothing happens, except that the Basic prompt reappears. The machine hasn't ignored your command. Because it started with a number, it has stored it away to use later. Everything we typed in before our latest line was on Basic's command level, which means that Basic executes it immediately. If the command begins with a number, however, it is stored in the memory for later use. To prove it, type: LIST This tells Basic to show you what it has stored. You should find that it repeats your command back to you, including the number 10 at the beginning. This is the whole secret of the way computers can be made to do complicated things - the stored program. A program consists of a series of lines of instructions which tell the machine what to do and it follows them in succession. At the moment, our program only consists of one line, so let's add a second. Type in: 20PRINT "GOODBYE" If you now type LIST again, you should see the following: 10PRINT "HELLO" 20PRINT "GOODBYE" Basic has LISTed your program to show you what's in it. Now to make it do your bidding! Type: RUN You should find that the screen displays: HELLO GOODBYE > Basic has gone through your program, starting with the first line, which tells it to print HELLO, then the second, telling it to print GOODBYE. After it has done this, it finds there are no more lines to deal with, so it prints the Basic '>' prompt and returns control to you. Although we entered the lines in the order in which they were to be executed, we didn't necessarily have to do so. When you type in a line, Basic knows where to put it in the program by the number at the beginning, which is, of course, known as the line number. To prove it, type: 15PRINT "HELLO AGAIN" or put whatever you like between the quotes. If you type LIST again, you should see: 10PRINT "HELLO" 15PRINT "HELLO AGAIN" 20PRINT "GOODBYE" and if you type RUN, you should get: HELLO HELLO AGAIN GOODBYE You can see now why program lines are usually numbered in tens; it makes it much easier to insert extra lines into the program! Each line in this program contains just one instruction, frequently known as a statement. You can have more than one statement on one line if you wish, by separating them with a colon (:), for example: 10PRINT "HELLO":PRINT "HELLO AGAIN" If you want to change a line, simply type it in again, using the same line number. You can delete a line entirely, simply by typing its number and pressing Return. Try a few experiments and list the program each time to see the result. If you made a typing error, you will probably get an error message when you run the program. The message will tell you not only what kind of error it was, but on which line it was detected. Note by the way that this is not necessarily the line on which the error occurred, for reasons we will see later. By the way, PRINT on its own prints a blank line and a single quote (') in a PRINT statement sends the printing operation to the start of the next line. You could have written line 10 in the example above as: 10PRINT "HELLO"'"HELLO AGAIN" The Case of The Missing VariableIf you had an error saying 'Unknown or missing variable', it means that you missed out the quotes round the word, or words, that followed the PRINT command. We will find out what a variable is in the next section.If you're using the command line at the bottom of the screen, you may now be wondering how you can return to the desktop without a star prompt to press Return on. The answer is to type the Basic command: QUIT This will make Basic close down and you will get the star prompt back. Alternatively, you can type: *Quit from within Basic. This is a star command and you can use any star command when you're in Basic, provided you type the star first. This tells Basic that what follows is not for it to deal with; instead it is handed over to the main part of the operating system. Whichever you choose, you should now have the star prompt, with nothing following it. A further press of Return will take you back into the desktop. If you're using the task window, just close the window. You will get a prompt asking you to confirm that you wish to discard the task running in the window. We referred earlier to 'Read Only Memory' (ROM) and 'Random Access Memory' (RAM) so, before we go any further, let's just make sure we understand what these terms mean. Another history lesson here. When computers were in their infancy, there were no microchips. To construct a memory device capable of holding lots of numbers and producing them in any desired order would have required thousands of transistors (and before that even valves!). Such devices were very expensive and could only hold a small amount of data by modern standards. Larger amounts of storage would have been on magnetic discs or tapes, which could only be written to or read from in a fixed order. Random Access MemoryThe small quantity of memory which could store or produce numbers in any order would have been known as Random Access Memory, to distinguish it from the other, less flexible, type. Today, all memory chips that can be written to as well as read from are known by this name.Random access memory has one big disadvantage - it is volatile. This means that the numbers stored in it vanish if the power is switched off, even for a moment. If a computer contained only this type of memory, it couldn't work because its processor would not know what to do when it was switched on. It wouldn't even be able to load instructions from a disc! Read Only MemoryA computer needs an operating system to tell it what to do, at least when it's first switched on. So that the operating system is there all the time, it needs a different kind of chip, one whose contents are permanently fixed into it. Such a device is known as a Read Only Memory chip. Once the numbers have been 'blown' into it, they can't normally be changed (though some types can be erased and re-programmed), which is why it can be read from but not written to. On the other hand, it doesn't lose its contents when the power goes off!Using the term 'random access memory' to mean read/write memory is a bit of a misnomer because read only memory is random access as well. Both types of chip can produce their contents in any order. It's the convention in computing, though, that ROM means read only memory chips (of course) and RAM means volatile read/write memory chips. Some other types of computer, notably the IBM-compatible PC, have the bulk of their operation system stored on a disc with just enough of it in a ROM to be able to load the rest into the RAM. Although this makes it easier to upgrade to a newer version of the operating system, it means it has to be loaded every time you start up the machine as well as any time you reset it, possibly because the program has crashed. There is also a risk of the operating system itself being corrupted by a virus. Your RISC OS machine, on the other hand, has its entire operating system in a ROM. This means not only that it's there as soon as you turn on or reset the machine, requiring just a few seconds to set itself up, but that you have a large operating system which uses very little RAM. It's also much less susceptible to viruses! What is RAM Used For?Anything that you load into your computer goes into the RAM. This could be a Basic program, any kind of application software, whether written in Basic or machine code, sprites or data of any kind.The operating system uses part of the RAM to store the numbers that it works with, as does any program which is running. Some software makes use of relocatable modules, some of which are contained in the operating system ROM and some of which are loaded from a disc into a part of the RAM known as the Relocatable Module Area, or RMA. If you use a wordprocessor or desktop publishing package, you're using outline fonts. These use an area of RAM known as the font cache. Finally, everything on the screen has to be stored in a section of RAM which can also be read by the video controller chip that generates the picture on your monitor. How much RAM this uses depends on the resolution of your screen and the number of colours it can display. You can see how your RAM is being used by clicking the mouse on the icon in the bottom right-hand corner of the screen and looking at the Task Manager window. |
||||
|
||||
|