01.03.2014 Views

Section 2 - Commodore Computers

Section 2 - Commodore Computers

Section 2 - Commodore Computers

SHOW MORE
SHOW LESS

Create successful ePaper yourself

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

138 COMPUTEI COMPUTE! Mov. May, 1Q82.lssue 1982. Issue 24<br />

trying to debug a program.<br />

At this time, most VIC2D own ers probably do<br />

At this time, most VIC20 owners probably do<br />

not have the benefit of a printer, so there is no<br />

printed copy of the program on which to make<br />

printed copy of the program on which to make<br />

comments regarding the various routines used in a<br />

program. If youu are going to do any serious programming,<br />

a printer lTlakes makes the task much easier<br />

because you can follow the logic and flow of a<br />

program from beginning to end without having to<br />

enter multiple LIST statements. A disk drive provides<br />

a lot of speed and flexibility when you are<br />

using a program, but a printer is worth its weight<br />

using a program, but a printer is worth its weight<br />

in gold when you are tryingg to debug a program. If<br />

it is necessary to remove REMark statements from<br />

a program in order to conserve memory space, it is<br />

a program in order to conserve memory space, it is<br />

worthwhile keeping some handwritten notes concerning<br />

the program. At a minimum, you should<br />

write downn the BASIC line numbers of subroutines<br />

and majorr sections of the program so that you will<br />

at least have an idea of what area of the program to<br />

LIST when you want to look at or change an area<br />

of code.<br />

REMs And Blanks<br />

That brings us back to being confronted with the<br />

"OUT OFF MEMORY" message and the first technique<br />

for buyingg back k a few bytes of storage.<br />

REMark statements, as important as they are,<br />

require memory. They do not provide any function<br />

require memory. They do not provide any function<br />

in your program. A REMark statement on a line by<br />

itself will require a minimum of six bytes, even if<br />

there is no text associated with the REMark. If the<br />

REMark contains textual information (as it usually<br />

y<br />

does), add the length of the text to that six bytes.<br />

does), add the length of the text to that six bytes.<br />

The quickest way to obtain memory is simply<br />

The quickest way to obtain memory is simply<br />

to remove the REMark statements. Remember to<br />

write down a notation about the REMark so that<br />

the information is at least externally preserved for<br />

the in fo rmation is at least externally preserved fo r<br />

documentation purposes. One word of caution: if<br />

your program contains GOTO or GOSUBB statements<br />

whose object is a line number containing a<br />

REMark that youu removed, , you will receive an<br />

"UNDEFINEDNED STATEMENT" error message.<br />

Should you get an "UNDEFINED NED STATEMENT"<br />

"<br />

error message you will have to figure out from<br />

where the REMark was removed and change the<br />

GOTOO line number to be the line following the<br />

original REMark; ; this cann be a long and tedious<br />

tas laskk if your program contains many statements<br />

that GOTO a REMark statement. Try to avoid this<br />

situation when you are originally writing your<br />

program by not coding GOTOO or GOSUB statements<br />

which land onn a line number containing<br />

a REMark.<br />

Another way to buy back a feww bytes of memory<br />

at the expense of good "internal" documentation is<br />

to remove all all unnecessary blanks from the program.<br />

This makes the program a bit harder to read, , but<br />

every blank removed is a byte of usable memory.<br />

every blank removed is a byte of usable memory.<br />

That does not seem to be much, but if you add up<br />

the number of unnecessary blank spaces in your<br />

the number of unnecessary blank spaces in your<br />

program, youu will be surprised; ; besides, no one<br />

ever said that this was going to be easy!<br />

The VIC2D VIC20 makes it easy to remove the blanks<br />

with the use of the INST/DEL key, but remember<br />

not to remove any blanks from within quotes. Data<br />

between quote marks are called strings and, if you<br />

are displaying them on a television or printer, you<br />

undoubtedly need those blanks. For example, if<br />

you are displaying the message "PRESS X TTOO<br />

EXIT" you would not want that informationn displayed<br />

as "PRESSXTOEXIT".<br />

T he following routine was entered on the<br />

The following routine was entered on the<br />

VIC20: V I C2D:<br />

NEW<br />

100 PRINT "elr"<br />

"clr"<br />

200 A=2:B=3:C=4:D=5<br />

A = = = = 5<br />

300 IF A = BANDC B C = DTHEND D D = D + I 1: : GOTO<br />

400<br />

400 PRINT "FREE = ";FRE(X)<br />

T he results of running this program showed<br />

The results of running this program showed<br />

that there were 3465 bytes available; the program<br />

occupied 118 bytes (3583-3465 = 118). By simply<br />

occupied liS bytes (35S3 - 3465 = liS) . By simply<br />

removing the fifteen blanks in statement 3.0.0 300 it<br />

became less readable:<br />

300 IFA=BANDC=DTHEND=D+ I:GOT0 400<br />

300 IFA = BANDC = DTHEND = D + 1 :GOTO400<br />

but the results of that run showed 34SD 3480 bytes of<br />

free space; a 1.0.0% 100% return for each blank removed. .<br />

Finally, you might have observed that I did not<br />

remove the blank that separates the line number<br />

from the statement. I Itt does not really occupy any<br />

memory and is there only for readability; readability: in fact, if<br />

you remove that blank, you will find that BASIC<br />

will reinsert it when you LIST the statement.<br />

Multiple statements Statements And Short Variable Names<br />

Closely allied with removing blanks' and removing<br />

REMark statements is putting multiple statements<br />

on a line. Your VIC2D VIC20 cann onlyy display 22 characters<br />

on a line, but BASICC will actuallyy accept up to 8.0 80<br />

characters. It is possible to have your BASIC statements<br />

occupy about three and one half display<br />

lines. It is also possible to combine statements on<br />

one BASIC line by using the colon separator ch'aracter.<br />

Every line number in your program contains<br />

an overhead of fivee bytes (for technicians: that five<br />

bytes consists of two bytes for the line number, two<br />

bytes for r an internal pointer, and one byte for a<br />

delimiter at the end of each statement). You cann<br />

save four of these fivee bytes for every statement<br />

combined on a line (the colonn separator will use<br />

char<br />

one of the five bytes eliminated). For example,<br />

instead of coding:

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

Saved successfully!

Ooh no, something went wrong!