| Posted By
Dunric on 2005-10-18 21:57:00
| Commodore equations
Today while cleaning out areas of my room, I stumbled upon an old United Church of Christ Southwest Conference - "Youth Ministries" - Song Book.
On the back of this song book was written the following information:
Before Mods: 5710 After: 7470 More Mods: 7670 more mods: 7877
Up above that was a simple math equation:
7877 - 5710 -------- 2167 bytes saved
Every time I sat down to program, either on the C64 or C128, I used to calculate the number of bytes used by a program and the required blocks free on disk before I performed a save operation.
I took the number of bytes used, divided it by 254, and came to the number of blocks used. For example:
52399 bytes used divided by 254 = 206 Blocks required on disk
50639 bytes used divided by 254 = 199 Blocks required on disk
50439 bytes used divided by 254 = 198 Blocks required on disk
50232 bytes used divided by 254 = 197 Blocks required on disk
In order to find out the number of bytes a program on disk will take up in RAM, use this equation:
Blocks Used / 4 = Bytes Used
So 206 divided by 4 will equal approximately 51.5 kilobytes used.
(51.5 * 4 = 206)
According to my calculations, a C-64 BASIC 2.0 program cannot exceed 154 blocks on disk. In fact, I would advise against creating a C-64 BASIC 2.0 program in excess of 140 blocksused. Most C-64 programs require variables and strings, so anything above 140 blocks might run into ?OUT OF MEMORY ERRORS. The largest BASIC 2.0 program I have ever seen left a mere 996 bytes free (149 blocks used).
Likewise, a C-128 BASIC 7.0 program cannot exceed 229 blocks used. However, the C-128 stores variable data in a separate memory bank (instead of tacking it onto the end of the program like the C-64, VIC-20 and Plus 4/C-16 do). The largest BASIC 7.0 program I have ever seen left a mere 8 bytes free (229 blocks used).
To summarize, calculating the number of blocks used by a program can be accomplished as follows:
# of bytes used / 254 = # of blocks used on disk
Calculating how many bytes a program on disk takes up in memory is done this way:
# of blocks used on disk * 4 = # of bytes used in memory
Very handy equations to use when programming.
Paul
|
|
Posted By
JamesC on 2005-10-18 23:19:39
| Re: Commodore equations
It is posts like these that I wish I had moderator operations...... I'd kill the **** post so that other wouldn't be subject to the same drivel that I had just read.
Point 1) The majority of us have been using Commodore machines at one time or another for the last 20+ years, and know how to calculate blocks required. It's in the disk drive manual!
Point 2) "In order to find out the number of bytes a program on disk will take up in RAM, use this equation: Blocks Used / 4 = Bytes Used" is not a guaranteed exact calculation. The very last block will most likely not be completely filled with data, but instead contain a few bytes of the actual program (or data file); the remainder will contain whatever was previously in that particular disk drive buffer for the previous disk drive operation. One must look at the track/sector link to find out for sure how many valid program or data bytes are contained in this last sector.
Point 3) Your post has very little to do with the Plus/4 or C16 or C116. The C64 is designed to point back inside the program when strings are defined, whereas the Plus/4 (and its' siblings) and the 128 will copy the string to upper memory. It is only when a string is changed (added to, shortened, or otherwise modified without the new string residing within the program code) that the 64 will move the string's definition to variable memory.
Point 4) Still off the subject of this site, but a 128 program CAN use more than 229 blocks of disk space and still fit within the 128's RAM. If it is a strictly machine code program that is coded to swap between banks 0 and 1 of RAM, or stores code in the optional RAM expansion, then it can easily exceed the 12****+ bytes allowed for BASIC programs. Or, it can be coded to load "modules" as needed..... GEOS is a perfect example of this.
|
|
Posted By
Dunric on 2005-10-19 18:26:58
| Re: Commodore equations
I was posting this because I didn't think many people knew of it. The original equation was published in a 1984 issue of Compute!'s Gazette, which is old. I assumed that most people didn't know the "/254" equation.
Paul
|
|
| |
Copyright © Plus/4 World Team, 2001-2024. Support Plus/4 World on Patreon |