Page 1 of 2

Basic "crunching" question.

Posted: Sun Nov 25, 2012 7:12 pm
by JohnnyRockets
Page 79 of the PRG says that crunching a program is a good way to save memory.

It says by abbreviating keywords, memory can be saved.

But it also implies that if the program is "listed" before saving it the abbreviated commands will be "inflated" to their normal length and all memory savings would be gone.

The method is to use abbreviations and then save the program before doing any kind of listing.

Does that sound right?

Also by adding multiple command to one line, where are the savings derived? From the fact that you do not need to have a new line number, spaces, etc?

Posted: Sun Nov 25, 2012 7:35 pm
by Jeff-20
You can fit more commands per line by using abbreviations and removing unnecessary spaces (exceeding the 88 character limit for a program line). The fewer lines you have, the smaller the program. Remember that each line takes a chunk of memory just to index it.

I try to make my programs as compact as possible while editing and "crunch" when I am finally done. So that I can maximize savings. Another trick is to make the best use of variables so that you're not repeating commonly used numbers, etc.

Posted: Sun Nov 25, 2012 7:44 pm
by JohnnyRockets
Jeff-20 wrote:You can fit more commands per line by using abbreviations and removing unnecessary spaces (exceeding the 88 character limit for a program line). The fewer lines you have, the smaller the program. Remember that each line takes a chunk of memory just to index it.

I try to make my programs as compact as possible while editing and "crunch" when I am finally done. So that I can maximize savings. Another trick is to make the best use of variables so that you're not repeating commonly used numbers, etc.
Thanks Jeff!

When you "crunch" at the end, do you do like a "find and replace" type of search like in Notepad?

Posted: Sun Nov 25, 2012 8:04 pm
by Jeff-20
I do all of my programming on a real vic.

Posted: Sun Nov 25, 2012 8:27 pm
by buzbard
BASIC is tokenized when you type in the line, so each BASIC command and function only uses 1 byte of RAM.

If you type in a line such as:

Code: Select all

10 INPUT"ENTER YOUR NAME";N$
The "INPUT" keyword will be tokenized, and if you were to type "I shift-N" for the shortcut of INPUT you'll still get the same token. Typing LIST will not un-crunch the line, it still only takes 1 byte in RAM. The LIST command interprets the (1 byte) token that it finds in RAM and displays it as the full keyword, but it still only uses 1 byte.

Posted: Sun Nov 25, 2012 8:52 pm
by JohnnyRockets
buzbard wrote:BASIC is tokenized when you type in the line, so each BASIC command and function only uses 1 byte of RAM.

If you type in a line such as:

Code: Select all

10 INPUT"ENTER YOUR NAME";N$
The "INPUT" keyword will be tokenized, and if you were to type "I shift-N" for the shortcut of INPUT you'll still get the same token. Typing LIST will not un-crunch the line, it still only takes 1 byte in RAM. The LIST command interprets the (1 byte) token that it finds in RAM and displays it as the full keyword, but it still only uses 1 byte.
Buzbard,

Thanks for your explanation! But it sure seems like they are insinuating something different on page 79 of the Programmer's Reference Guide, under "Abbreviating Keywords". Almost like a "crunching" of some kind can take place with abbreviations and save memory...?

Posted: Sun Nov 25, 2012 9:13 pm
by buzbard
Well, you could type in the line above then type PRINT FRE(0), note how much RAM is free.

Then power cycle the VIC to clear all the RAM then type it in again using the shortcut then type PRINT FRE(0) again to see if you get a smaller number.

I'll bet you get the same number though.

Posted: Sun Nov 25, 2012 9:17 pm
by JohnnyRockets
buzbard wrote:Well, you could type in the line above then type PRINT FRE(0), note how much RAM is free.

Then power cycle the VIC to clear all the RAM then type it in again using the shortcut then type PRINT FRE(0) again to see if you get a smaller number.

I'll bet you get the same number though.
Excellent! I will do this and report back my results! Cool!

Posted: Sun Nov 25, 2012 9:19 pm
by JohnnyRockets
Jeff-20 wrote:I do all of my programming on a real vic.
Do you use the Programmer's Aid Cartridge?

Posted: Mon Nov 26, 2012 10:45 am
by Leeeeee
Also by adding multiple command to one line, where are the savings derived? From the fact that you do not need to have a new line number, spaces, etc?
Yes, four bytes are saved by not having another line number and line link.
It says by abbreviating keywords, memory can be saved.
Only where it allows you to enter a line that will be longer than one logical screen line when listed.
But it also implies that if the program is "listed" before saving it the abbreviated commands will be "inflated" to their normal length and all memory savings would be gone.
No, the problem with lines that are longer than one logical screen line is that they can't be edited with the screen editor. When the line is listed it gets broken into screen line length chunks and each chunk is treated as an individual part by the screen editor.

For example the line ..

Code: Select all

10?:?:?:?:?:?:?:?:?:?:
?:?:?:?:?:?:?:?:?:?:?:
?:?:?:?:?:?:?:?:?:?:?
Is a valid, though not very usefull, line that is much longer than one logical screen line. When you list it it looks like this.

Code: Select all

10 PRINT:PRINT:PRINT:P
RINT:PRINT:PRINT:PRINT
:PRINT:PRINT:PRINT:PRI
NT:PRINT:PRINT:PRINT:P
RINT:PRINT:PRINT:PRINT
:PRINT:PRINT:PRINT:PRI
NT:PRINT:PRINT:PRINT:P
RINT:PRINT:PRINT:PRINT
:PRINT:PRINT:PRINT
This is fine though, you can at this point run and list the code as much as you wish and it performs as expected.

However, if you try to use the screen editor on the code, even if no changes are made, you either get a truncated line, a syntax error or three blank lines printed depending on where the cursor is when you hit return.
The method is to use abbreviations and then save the program before doing any kind of listing.

Does that sound right?
Sort of. Once the program is listed it is all too easy to invoke the screen editor and end up with a truncated long line. If this happens the only way to fix the truncated line is to retype it in its abbreviated keyword entirety.

Lee.

Posted: Mon Nov 26, 2012 11:20 am
by JohnnyRockets
Hi Leeeeee!

Thanks for a great explanation.

I'm sorry to sound so green, but what is the screen editor you are talking about?

Whenever I have had to "edit" a line, it was usually done by just retyping it.

Is there a better way? :oops:

Posted: Mon Nov 26, 2012 11:54 am
by buzbard
JohnnyRockets wrote:...what is the screen editor you are talking about?
If you list a progam then use the cursor key to move to a line and change what is there, that's the screen editor. You don't have to retype a line from scratch.

Posted: Mon Nov 26, 2012 12:18 pm
by Kweepa
Note: you have to press RETURN for the line to be updated.

Posted: Mon Nov 26, 2012 12:19 pm
by JohnnyRockets
buzbard wrote:
JohnnyRockets wrote:...what is the screen editor you are talking about?
If you list a progam then use the cursor key to move to a line and change what is there, that's the screen editor. You don't have to retype a line from scratch.
Ahem... Yes, of course you can! I knew that! 8)

Actually, I didn't know that! And it is awesome!

Be kind everyone, please keep all laughter and jokes to yourselves... :oops:

Posted: Mon Nov 26, 2012 12:57 pm
by Jeff-20
Above I tried to write everything Lee wrote, but it got lost in translation. He did it much better. :lol: I use abbreviations all the time to get more info into a basic line.

My favorites are the undocumented abbreviations one can put between quotes. If you look at Commodore game tape listings, they put some kind of line break trick to squeeze full title screens of text into single lines. I still haven't figured that out. I think Blue Meanies was a good example.