Shortening BASIC-programs

Basic and Machine Language

Moderator: Moderators

Post Reply
User avatar
tokra
Vic 20 Scientist
Posts: 1123
Joined: Tue Apr 27, 2010 5:32 pm
Location: Scheessel, Germany

Shortening BASIC-programs

Post by tokra »

Browsing old german '64er' magazines I found this little program called

BASIC PACKER

which not only removes REM and Spaces, but also uses 255 byte in each BASIC-line and uses some other tricks as well (it does 4 passes over each program).

The resulting program is still BASIC but no more editable. The program is for the C64 but I managed to load a VIC-program into the C64 VICE, compact it, and save it again to be reloaded on the VIC. I tried the game-file of "The Great Adventure" and it shortened that one by nearly 3 KB.

I'm sure BASIC-wizards like Jeff might find this useful to squeeze a few more bytes out of programs without having to resort to machine language (which you should learn anyway ;-)).
User avatar
RobertBe
Vic 20 Elite
Posts: 2312
Joined: Sat Jul 14, 2007 2:48 pm

Re: Shortening BASIC-programs

Post by RobertBe »

tokra wrote:BASIC PACKER

which not only removes REM and Spaces, but also uses 255 byte in each BASIC-line and uses some other tricks as well (it does 4 passes over each program).
I have a similar C64 program from Ahoy magazine. It is called, "Compactor". I've even used it with some success on Basic 7/Basic 8 programs for the C128.

Truly,
Robert Bernardo
Fresno Commodore User Group
http://videocam.net.au/fcug
The Other Group of Amigoids
http://www.calweb.com/~rabel1/
Southern California Commodore & Amiga Network
http://www.sccaners.org
Last edited by RobertBe on Thu Sep 23, 2010 10:30 pm, edited 1 time in total.
User avatar
Jeff-20
Denial Founder
Posts: 5759
Joined: Wed Dec 31, 1969 6:00 pm

Post by Jeff-20 »

I feel like I'm pretty good at crunching, but this is really interesting. I wonder if it can intelligently handle GOTOs and GOSUBs. I also use a lot of ON statements.
High Scores, Links, and Jeff's Basic Games page.
wimoos
Vic 20 Afficionado
Posts: 346
Joined: Tue Apr 14, 2009 8:15 am
Website: http://wimbasic.webs.com
Location: Netherlands
Occupation: farmer

Post by wimoos »

no more editable..
This also means you can't MERGE the program anymore using Programmers Aid or Exbasic/Wimbasic.
VICE; selfwritten 65asmgen; tasm; maintainer of WimBasic
User avatar
GreyGhost
Vic 20 Nerd
Posts: 525
Joined: Wed Oct 05, 2005 11:10 pm

Post by GreyGhost »

If you guys want a Vic 20 version, look in compute's Gazettes archive for a program called Crunch. There is a Vic and 64 version, though the Vic version is shortened a bit.
Rob
User avatar
RobertBe
Vic 20 Elite
Posts: 2312
Joined: Sat Jul 14, 2007 2:48 pm

Post by RobertBe »

GreyGhost wrote:If you guys want a Vic 20 version, look in compute's Gazettes archive for a program called Crunch.
I've used Crunch (which I call Cruncher), and sometimes it's unsuccessful in compressing Basic. That's when I turn to Compactor from Ahoy.

One or the other,
Robert Bernardo
Fresno Commodore User Group
http://videocam.net.au/fcug
The Other Group of Amigoids
http://www.calweb.com/~rabel1/
Southern California Commodore & Amiga Network
http://www.sccaners.org
CurtisP
Vic 20 Dabbler
Posts: 99
Joined: Tue Mar 08, 2005 8:24 pm

Post by CurtisP »

Jeff-20 wrote:I feel like I'm pretty good at crunching, but this is really interesting. I wonder if it can intelligently handle GOTOs and GOSUBs. I also use a lot of ON statements.
One of my tricks is to simulate a REPEAT loop using FOR NEXT

Code: Select all

FORZ=0TO1:GETZ$:Z=LEN(Z):NEXT:REM do more stuff
User avatar
Jeff-20
Denial Founder
Posts: 5759
Joined: Wed Dec 31, 1969 6:00 pm

Post by Jeff-20 »

Haven't seen you in a while, Curtis. Good tip! But will the stack eventually overflow? Is it actually faster?
High Scores, Links, and Jeff's Basic Games page.
wimoos
Vic 20 Afficionado
Posts: 346
Joined: Tue Apr 14, 2009 8:15 am
Website: http://wimbasic.webs.com
Location: Netherlands
Occupation: farmer

Post by wimoos »

This trick is maybe a wee bit faster than its GOTO equivalent (for the example shown it is irrelevant, but other purposes may benefit).

The stack will not overflow, the FOR/NEXT is taken from the stack after a key has been pressed. No new FOR/NEXT is built up per iteration.

The trick is actually an example of improper programming: you're not supposed to modify the loop counter other than through the NEXT statement.

How about this variant in WimBasic:

Code: Select all

10 GETX$:IFX$="".
Ceci n'est pas un typo.
VICE; selfwritten 65asmgen; tasm; maintainer of WimBasic
Post Reply