10.02.2013 Views

a E i - Commodore Is Awesome

a E i - Commodore Is Awesome

a E i - Commodore Is Awesome

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

So if your screen is blank and<br />

nothing is happening what should you<br />

do?<br />

On a Cl28 you could fi rst try<br />

typing SLOW just in case the computer<br />

has been put into fast mode. On<br />

other computers, and the Cl28 if the<br />

above fails, try changing the ink colour<br />

to see if the cursor re-appears.<br />

CONTROL and a number will do this.<br />

If the cursor does re-appear then you<br />

know that your program has finished<br />

and printed some sort of message on<br />

the screen, Find out where the colour<br />

of the ink is changed to that of the<br />

background within the program,<br />

change it to something else and re-run<br />

the program. You will now see the<br />

message when the program stops.<br />

Illegal What?<br />

Quite often programs will be<br />

published that contain a lot of DATA<br />

statements, Somewhere within the<br />

program this DATA will be READ<br />

and the value then POKEd into<br />

memory. Your <strong>Commodore</strong> uses this<br />

type of program quite a lot as a way of<br />

getting machine code into memory,<br />

One of the most common problems<br />

that people get with these is that, when<br />

the program is RUN, the computer<br />

responds with an ILLEGAL<br />

QUANTITY ERROR in a certain line.<br />

If you enter the following example I<br />

will show you, as I promised, that the<br />

computer is not always right:<br />

10 FOR COUNT=0 TO 7<br />

20 READ NUM<br />

30 SUM = SUM + NUM<br />

40 POKE 49152 + COUNT NUM<br />

50 NEXT COUNT<br />

60 READ CHECK<br />

70 IF SUMCHECK THEN PRINT<br />

"ERROR" STOP<br />

80 PRINT "FINISHED"<br />

100 DATA 102,101,103,104,105,106,<br />

107,732<br />

This sort of loader is used in Your<br />

<strong>Commodore</strong> every month. Every line<br />

has a checksum on the end, the total of<br />

the number's that have been read being<br />

worked out in line 30. This is then<br />

compared with the checksum, READ<br />

in line 60 and compared with SUM in<br />

line 70, If they aren't the same then the<br />

computer reports the error and<br />

STOPs.<br />

Let's RUN this program and see<br />

what happens. You should get an error<br />

message 'ILLEGAL QUANTITY<br />

ERROR IN LINE 40', Your immedi-<br />

PROGRAMMING<br />

ate reaction is to check line 40. But<br />

there's nothing wrong with this so<br />

what is the problem?<br />

An ILLEGAL QUANTITY<br />

ERROR means that a number has<br />

been used that is too large. So let's<br />

have a look at line 40. In this line was<br />

POKE 49152 + COUNT with the<br />

number that has been READ from the<br />

data statement. The maximum value<br />

that 49152 + COUNT can reach is<br />

49152 + 7 (see the For Next loop in the<br />

first line) which is 49159. There is<br />

nothing wrong with this so what about<br />

the number that has been read? You<br />

can only POKE a number up to 255<br />

into memory'. What must have<br />

happened is that you are trying to<br />

POKE a number greater than 255 into<br />

the computer's memory. If we tell the<br />

computer to print this number out<br />

when it stops with an error message<br />

our fears will be confirmed, RUN the<br />

program again and then type the<br />

following line when the program stops:<br />

PRINT NUM<br />

The computer should respond with<br />

732. Hence our illegal quantity error.<br />

Yu can only POKE a number up to 255<br />

into memory, remember? So what has<br />

gone wrong? Let's follow the program<br />

through.<br />

Line 10 is a loop that repeats eight<br />

times count going through<br />

0,1,2,3,4,5,6 and 7.<br />

Line 20 READS the next number from<br />

the data statements.<br />

Line 30 adds this number to the<br />

current value of sum.<br />

Line 40 POK Es the value that has been<br />

read into memeory,<br />

line 50 goes back round the loop eight<br />

times,<br />

Line 60 the checksum is read.<br />

Line 70 the sum is compared with the<br />

checksum and the program stops if<br />

they are not the same.<br />

Line 80 is the end of the program.<br />

So what is our problem? Eight pieces<br />

of DATA are read, the sum is then<br />

read and the program should end. If<br />

you take a close look at line 100 you<br />

will see that there are only seven pieces<br />

of data and the check sum. This means<br />

that instead of the last number being<br />

read and POK Ed into memory the<br />

program READS the checks= and<br />

tries to POKE this into memory giving<br />

you your illegal quantity error. The<br />

number 108 is missing from line MO. In<br />

this ease the fact that a number was<br />

missing from line 100 was easy to spot.<br />

YOUR COMMODORE january 1987<br />

110<br />

After all we only have one line of<br />

DATA in the program. How would<br />

you cope if there were 600. 700 or more<br />

lines of DATA? How could you find<br />

the line where the DATA was missing?<br />

System Variables<br />

The designers of the <strong>Commodore</strong><br />

series of computers use certain areas of<br />

the computers memory to hold<br />

information about certain things in the<br />

computer. The following memory<br />

locations hold the line number of the<br />

last DATA statement;<br />

63 & 64 on the C64, C16 and Plus/4<br />

65 & 66 on the C128<br />

The line number of the last DATA<br />

statement can be found by entering the<br />

following line:<br />

PRINT PEEK (63) + 256* PEEK(64)<br />

or<br />

PRINT PEEK (65) + 256* PEEK (66)<br />

on the C128<br />

Re-Run the above program, when the<br />

computer stops with the error<br />

message try the PEEK and you will<br />

find that the number 100 is printed -<br />

the line where the error is. So now you<br />

can fi nd where in your program the<br />

computer is READing DATA from<br />

even if there are hundreds of lines.<br />

Correct Version?<br />

Let's correct the above program and<br />

see if it works. Re-enter line 100 to<br />

read:<br />

100 DATA 102,101.103,104,105,106.<br />

107,108,732<br />

RUN the program again and all is well.<br />

or is it? The computer comes up with<br />

FINISHED and no error messages are<br />

printed so everything shoudl be OK.<br />

Well I'm afraid that it isn't.<br />

Adding Up<br />

The main failing of this type of<br />

program is that the check on each line<br />

is simply a sum of all of the numbers.<br />

Therefore 3+2+1 would give you a<br />

checksum of six. However 2+3+1<br />

would also give you six even though<br />

the numbers are not in the correct<br />

order. If these numbers were part of a<br />

machine code program, the fact that<br />

they could be in the incorrect order<br />

may cause the program not to work<br />

correctly or even crash, The golden

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!