Your coding teacher here is called BASin?
Many programmers call it a “development tool” – it is a program that makes it easy to make other programs. In the 1980s, when the ZX Spectrum was the king of home computers, people would use BASIC to program it. The Spectrum had some very odd quirks when it came to doing this. Each key produced an entire codeword, and when a key was pressed at the same time as other keys it produced even more codewords! Programming on a Spectrum was very confusing to a beginner.
BASin removes that confusion. We have proper keyboards on all of our computers nowadays, so why not use them? BASin also gives you a much larger amount of screen area to show your program code, which you will find much more comfortable to use than the small screen area that the Spectrum provided.
You can also use BASin’s extra tools to “debug” (find mistakes) in your program. This means that you can watch your program run line by line; you can watch things change slowly, step by step; or you can stop the program and examine it in your own time to see exactly how it works. And you shouldalways remember that BASin is ready to help you if you need it – every screen and every window in BASin has a “HELP” menu for you to use.
So BASin gives you a lot of nice features, but it is still a ZX Spectrum inside. Any program you code using BASin will run on a real ZX Spectrum computer or on the new ZX Vega, exactly as it does in BASin on your PC.
BASin makes it fun to learn to code your programs, and will help you get started in the wonderful world of computer programming.
BASin was designed and programmed by Paul Dunn.
Paul Dunn is a 42 year old geek with a passion for Sinclair BASIC. He is the author of BASin, the BASIC development environment and co-author of the acclaimed ZXSpin emulator for PCs. He has also developed an implementation of Sinclair BASIC for PCs, known as SpecBAS. Paul has been coding in various languages since the days of the original Sinclair machines. He considers the biggest loss to the BASIC language to be the lack of line numbers. Does not consider GO TO “harmful”.
Click on link above and follow simple steps below to start using this tool
As you learn how to code you will want to get practice at writing your own programs, typing them into the computer, running them to see how they work, and saving them so you can run them and change them later.
Entering a program into BASin is easy. You just typeon the keyboard of your PC. BASin makes your programs appear in separate lines, and it moves the line numbers of your program to the left side of the window.
To begin entering a line of your program, you must first type in a line number. Number 10 is a good one to start with – it means that you can put lower numbers in if you need to. You will notice that the numbers as you type them move into the side of the window, until you press the space bar ready for your first command. After that, any letters you type will move to the right like normal.
BASin makes a soft “click” sound when you press a key, to tell you that it has done what you asked it to. When you have finished entering a line, press the ENTER key on your keyboard – BASin will give you a high, bright “beep” sound if there are no mistakes. If the coding teacher finds a problem with what you have typed, it will make a low “boop” sound, and the “cursor” (the flashing white/blue box) will turn red and move to where the mistake might be.
Program lines are stored in order, based on their line numbers. If you already have lines 10 and 20, and you enter line 15, then that new line will appear between 10 and 20. When you RUN the program, the computer will work on each line starting from the lowest line number, up to the highest.
If you enter a line with a number less than the last one you entered, the coding teacher will move it into its proper place in the list. If you enter a line with a number the same as another line, you will hear the “boop” sound and the cursor will turn green to let you know that you cannot have two lines with the same number. If you press ENTER a second time, BASin will understand that you want to overwrite the old line and will accept the new one – but beware, the other line that has that same line number will disappear and be lost!
To make a new line, just press ENTER anywhere in your program. BASin will make room with an empty space for you to start typing.
You can move around the line you are editing with the cursor keys on your keyboard: ( ← and →, ↑ and↓) left and right, up and down. If you try to move up or down off the line which you are editing and into another one, BASin will act as though you pressed ENTER and will store that line with the rest of the program.
If you enter more than one statement on a line you must separate them with the “:” symbol. This will cause BASin to split your line into what looks on the screen like another line. Don’t worry – it’s all the same line of your program, but BASin makes it easier to read by putting each statement on a line by itself. You might notice that only the first statement in a program line has a line number.
You can use the DELETE and BACKSPACE keys to make changes if you need to. You can even delete the line number at the start of the first statement on a program line, but BASin will think that your first statement is a direct command and try to run it instead of storing it for later!
You can use the SHIFT key together with the cursor keys to highlight letters. (You might already know how to do this with a word processor, when you want to cut, copy and paste.) But you can only do this for one program line (and its statements) at a time.
If your program grows so big that it won’t all fit on the screen at the same time, BASin will give you some scrollbars to the right of the program listing, which you can use to move around. You can also use your computer’s mouse to “scroll” through the program, or you can use the UP/DOWN cursor keys to move to the top or bottom. BASin will not let your cursor run off the bottom of the listing.
While you are learning to code you will probably find it useful to remind yourself what some or all of your lines of program code are doing. You can do this by putting remarks or reminders (sometimes called “comments”) in your program. In BASIC you do this by adding “REM statements” to your program.
REM statements all start with REM, which you can put either at the beginning of a line or as the last statement in a line. Everything on a line that comes after a REM is ignored by the computer.
After typing REM you can put whatever reminder message you like, up to the end of that line of code. If you want to put a remark which is too long to fit on one line you may continue the remark onto more lines by putting REM at the start of each line of the remark.
An example of a short remark is this:
80 CLS REM This is to clear the screen
Here you have reminded yourself what the CLS codeword does (you will learn about CLS in Lesson 1) – it clears the screen.
An example of a longer remark is this:
80 BORDER 1
81 REM This puts a blue border
82 REM around the edge of the screen.
83 REM Blue is my brother’s favourite colour
To start your program, you must use the codeword “RUN”. If you type RUN on an empty line, and press ENTER, the computer will then start doing what your program tells it to do, starting at the smallest line number and then carrying out the commands in each line from the top of your program down to the bottom.
If you want your program to start again when it has finished, you can do this by adding a RUN command at the end of your program. This might be useful if you want it to do something over and over again, for example playing a tune which you have coded into a program.
RUN is a special command. When you type RUN and press ENTER, the computer gets rid of all the numbers in its memory and clears the screen before it starts running your program. But if you want to keep the screen as it is, and keep any numbers that might be in the computer’s memory, then there’s a way you can do this and still run your program – using a GO TO command. GO TO needs a line number to start at, so you should add that to the command, for example:
GO TO 10
will start your program running at line 10, and move on from there.
You do not have to add a line number to a RUN command, but if you do so remember that will still clear the memory and screen before it starts.
If you have SAVEd your program with a LINE codeword then it will, when loaded, start immediately and you won’t have to use RUN. If you didn’t save with a LINE codeword then you will need to use RUN to get it to start. Saving without the LINE codeword is useful if you want to add more lines to your program or change anything – BASin will wait for your commands or changes after loading.
It is useful to know that if you save your program for loading later on the ZX Spectrum or ZX Vega, then it will be saved with the LINE codeword, so that it starts straightaway.
A “listing” of a program is all the lines of your program, or part of it, as you have written them.
You might want to take a look at your program so that you can remind yourself exactly what you have written. You can tell the computer to display the whole of your program on the screen by simply putting LIST in a program line, like this:
This tells the computer to display the whole of your program.
But if the program is too big to fit on the screen all at once, the first page of the program will be displayed, and you will also see the message “Scroll?”, which means the computer is asking you if you want it to display the next page of the program. (We call this “scrolling down” the screen.)
If you do want the computer to scroll down a page you can do so by touching almost any key on your keyboard, but not N, or the space bar, or BREAK.
If instead of seeing the whole o your program displayed on the screen, you only want the computer to display the program from somewhere after the start, you can use LIST followed by a line number. For example:
91 LIST 45
which would tell the computer to start the display of the program at line 45.
This section will cover the 50 most important BASIC codewords that you need to know.
There are four different types of codeword in BASIC: commands, functions, logical operations and PRINT items. Here is what we mean by each type.
A “command” is an instruction to the computer – it is always the first word that follows the line number on a program line, or after a statement separator “:”. A command is a “doing” word – it tells the computer to do something. Most commands need to be told what to use in order to do their job – for example, PRINT needs to be told what words or numbers to draw on the screen, BORDER needs to know what colour you want the screen border to be. This information is called an argument.
A “function” is like a command, but can appear anywhere inside an argument to a codeword. A function, like a command, tells the computer to do something, but also sends some information back. For example, the function “PI” will send back the number 3.141592654 (a wonderful number and soon to be one of your best friends!) and that number can then be used for another job. Some functions need a parameter, which is information that it needs to do its job, just like the arguments that a command needs. Some functions need more than one parameter, but we’ll get to that later.
A “logical operator” is a way of comparing one thing to another. These are symbols like ones you already know about (+ and -) and they work the same way, but instead of doing sums with them, you get to know if what you asked is true or false (right or wrong). If you ask the computer to PRINT 1=2 then it will show a zero (0) on the screen, meaning false, because 1 is not equal to 2. if you then ask for 1
When you PRINT something, you send some letters or numbers to the screen. You can change the way these letters and numbers look by using a PRINT item – for example:
PRINT INK 1;”Hello”
Will show the word “Hello” in blue writing because 1 is the number for choosing the colour blue. You can also use PRINT items to move your writing around the screen and even make it flash in funny colours.
Each line in a BASIC program is made up of a line number and then a statement. You can have more statements if you like, and they are separated by a colon (:) symbol. Any arguments that come after a codeword are part of its statement.
BASIC does the tasks it is given in each line, one after another. As we shall see later with the IF codeword, having more than one statement in a line can sometimes be very powerful.
In a lesson lasting just a few minutes you can learn how to create very simple computer programs.
There are ten lessons to get you started. But coding in BASIC is so easy to learn that you will be able to write your first programs immediately after the first lesson.
In each lesson you are shown five BASIC codewords and what they mean.
Lesson 1 PAPER, INK, BORDER, CLS, PRINT
Lesson 2 AT, BRIGHT, PLOT, CIRCLE, DRAW
Lesson 3 FOR, NEXT, TO, STEP, LET
Lesson 4 INPUT, INKEY$, FLASH, BEEP, INVERSE
Lesson 5 IF, THEN, AND, OR, GOTO
Lesson 6 DATA, READ, GO SUB, RETURN, NOT
Lesson 7 SQR, SGN, PI, ABS, INT
Lesson 8 SIN, COS, TAN, EXP, LN
Lesson 9 ASN, ACS, ATN, TAB, LEN
Lesson 10 PAUSE, RND, RANDOMIZE, STOP, CONTINUE
In each lesson there is an example program to show you how the five codewords for that lesson can be used, to create a very simple program. The example program will use the five codewords from that lesson, possibly with some of the other codewords you already know.
At the end of each lesson, after you have seen how the example program works, you should try and create your own programs by using just these five codewords plus some of the ones you learned earlier.
Then you go on to the next lesson and learn another five BASIC codewords, and so on. Pretty soon you’ll know 50 BASIC codewords, and you will be able to create lots of your own programs.
When that you have learned some BASIC codewords and can see what they mean, you can start to create your own programs. The coding teacher will keep an eye on you to check that you aren’t using any of the BASIC codewords in the wrong way. If you do something wrong you will create what we call a “bug” in your program, and we don’t like bugs in our programs because a bug stops a program from working properly.
When you make a mistake the coding teacher will put an ERROR message on the screen for you, if it wants to tell you that your mistake is in the way you tried to use a BASIC codeword.
Here are a few ERROR messages and what they mean.
Error messages start with a number or letter, which the computer uses to identify which error message it is. This number or letter is followed by a message which explains what is wrong. The two numbers that follow the message are the line number and the statement number where the problem happened.
If you did not make any coding mistakes in your program you will see this message:
0 Ok – your program has finished, and there were no mistakes. Note that this does not mean that everything went well, just that the computer has done what you told it to do!
Some of the error messages you might see are:
All of these errors have been coding errors. They use codewords in the wrong way, because they break the rules of coding in the BASIC language.
Sometimes a program has all of its codewords used exactly according to the rules of BASIC, but the plan for the program − which we call the “logic” of the program − is wrong in some way. So the computer understands what you want it to do because you have written your program according to the rules of BASIC, but because your program plan has an error you are asking the computer to do something which is impossible for some reason. Here is an example of a coding plan that goes wrong:
60 LET A = 5 (means that the value of A is set to be 5)
70 LET B = 0 (means that the value of B is set to be 0)
80 LET C = A/B (means that C is set to the value of A divided by B)
But you probably know from your arithmetic classes that it’s impossible to divide anything by 0. So although each of the lines in this program is written in correct BASIC, and so each line of the program code is correct when we think of it by itself, what happens when the computer tries to carry out all of the codeword instructions is that it gets stuck on line 80 when it tries to divide A by B, because B is 0.
This problem is called a “RUN TIME ERROR”, because we don’t find out the error until the computer tries to run the program.
So you’ve written a program, and BASin has given you an error message instead of running your program. What do we do now?
Well, if your program isn’t doing what it should do then we have what’s called a “bug” and we need to make it right so that the program can run. There are a few things you can do, and the first is to look at the error message and see what it says. If you can’t see the error, then you can use the “View” menu and choose the “Last Error” option to get it back on the screen again.
The error message will give you some idea of what went wrong, and if it’s a clear message (like a “Variable not found” error, or a “Number too big” error) then you can start fixing it right away. If it’s not as simple as that, then you can look at the line number in the error message and go to that line to start looking at your program. This is often the best way to fix a bug.
Let’s start by looking for spelling mistakes. If you can’t see any mistakes in your spelling and it looks right to you, but your program won’t run, then we need to get a bit more technical. We’re going to use a breakpoint. This is a special marker in your program that will stop it before it gets to the error. You can set a breakpoint by moving the cursor to the line where you want the breakpoint and double-clicking that line, and then type RUN.
When BASin gets to the line you marked, it will stop. Now, you can’t make any changes to the program just yet because it has in fact just stopped for a little while. You can now move on, one line at a time – this is called “Single Stepping” and you do that with the button on the toolbar that looks like footprints (This: ) Each time you click that button, the next statement in your program will run – and then BASin will stop again. This makes it easy for you to follow what your program is doing, and hopefully you will be able to find your bug.
Something else you might want to do is to check some of the variables your program uses. You can see them on your computer screen listed to the right, under the Spectrum screen. Quite often, if your program has a bug, one of the variables will not hold the value that you thought it should hold, and that will give you a better clue as to what is going wrong.
Getting bugs out of your program (“debugging”) is probably the most useful skill you will learn, and the more practice you get at it the easier you will find it to do.