| www.retrosoftware.co.uk http://www.retrosoftware.co.uk/forum/ |
|
| Compression of program code http://www.retrosoftware.co.uk/forum/viewtopic.php?f=73&t=42 |
Page 1 of 2 |
| Author: | FrancisL [ Thu Mar 13, 2008 1:23 am ] |
| Post subject: | Compression of program code |
Here's a useful utility I got from one of my books to compress your program code: Code: 10 page=&1900 20 basef=page:baset=page 30 pf=3:pt=3 40 quote=0:rem=0 50 !baset=!basef 60 IF basef?1>127 END 70 pt=pt+1 80 pf=pf+1 90 byte=basef?pf 100 IF byte=&0D baset?3=pt:basef=basef+pf:baset=baset+pt:GOTO 30 110 IF rem GOTO 80 120 IF byte=&22 quote=1-quote:GOTO 170 130 IF quote GOTO 170 140 IF byte=&8D baset!pt=basef!pf:pt=pt+3:pf=pf+3:GOTO 70 150 IF byte=&F4 rem=1:GOTO 170 160 IF byte=&20 GOTO 80 170 baset?pt=byte:GOTO 70 It works by stripping the REM statements and removing any space characters from your program. To use it load your program to be compressed as normal. Then set the PAGE to &900 and load the above program and run it. Line 10 should be set to the same page address as the program being compressed. I remember that there was a better utility available (I think it was a type-in from Acorn or Micro User) that also changed the names of variables from, say, MyVeryLongVariableName% to A%. If anyone has this one kicking about then I would certainly be interested in it. Kind regards, Francis. |
|
| Author: | Samwise [ Mon Mar 17, 2008 2:18 pm ] |
| Post subject: | Re: Compression of program code |
Francis, Have you seen BeebugSoft's Toolkit Plus [http://bbc.nvg.org/rom/Beebug/util/] (RTF Manual)? It has a command called *CRUNCH which I used to use in the past to great effect. Sam. CRUNCH Syntax: *CRUNCH <<B>> <<C>> <<L>> <<R>> <<S>> <<T>> <<V>> <<:>> Minimum abbreviation: *CR. Menu option: E Function: Compact a Basic program. This command invokes a powerful set of routines which remove from a Basic program all unnecessary spaces and REM statements, concatenate program lines, and substitute short variable names. All the various program-shortening functions will be performed if *CRUNCH is issued alone. Each of the functions may be prevented by following the command with one or more of the following parameters:
If substitution of shortened variable names is performed a list of the new, contracted variable names against the original variable names is displayed. For example: Code: >LIST
10 REM example 20 FOR count=0 TO 10 30 PRINT "Toolkit Plus" 40 NEXT count >*CRUNCH Variable crunching A — count Old Program Size = 72 Bytes Saved = 40 New Program Size = 32 >LIST 20FORA=0T010:PRINT"Toolkit Plus"NEXTA > |
|
| Author: | FrancisL [ Mon Mar 17, 2008 7:45 pm ] |
| Post subject: | Re: Compression of program code |
Ooh, nice! That one certainly looks more powerful that the one I had seen. I'll definitely need to give it a try. Kind regards, Francis. |
|
| Author: | FrancisL [ Tue Mar 18, 2008 2:36 am ] |
| Post subject: | Re: Compression of program code |
I must admit that I am quite impressed by Toolkit+. It reduces the current version of my game program by over 2 kB! Kind regards, Francis. |
|
| Author: | Samwise [ Tue Mar 18, 2008 11:07 am ] |
| Post subject: | Re: Compression of program code |
Yeah, it's awesome, isn't it? IIRC it was the only way I could get Grid Iron 2 from Alternative Software to actually run reliably in the correct MODE, without spewing an out of memory error. It was just a whopping BASIC program. Plus it has the added benefit of making programs much harder to read by the casual layman, which used to annoy a few of my schoolmates ... heh. Sam. |
|
| Author: | AndrewW [ Sat Apr 05, 2008 11:46 am ] |
| Post subject: | Re: Compression of program code |
Crunch seems okay for me as long as it's just limited to REM statements. Any more and you surely lose the understandability of your program? |
|
| Author: | FrancisL [ Sat Apr 05, 2008 11:59 am ] |
| Post subject: | Re: Compression of program code |
AndrewW wrote: Crunch seems okay for me as long as it's just limited to REM statements. Any more and you surely lose the understandability of your program? It's really intended more for a release version of a program to decrease memory consumption and possibly increase the execution speed as well. You shouldn't really use it on your original developmental version of your code otherwise, as you say, you just lose all understandability of it. Kind regards, Francis. |
|
| Author: | AndrewW [ Sat Apr 05, 2008 12:08 pm ] |
| Post subject: | Re: Compression of program code |
FrancisL wrote: Here's a useful utility I got from one of my books to compress your program code: Code: 10 page=&1900 20 basef=page:baset=page 30 pf=3:pt=3 40 quote=0:rem=0 50 !baset=!basef 60 IF basef?1>127 END 70 pt=pt+1 80 pf=pf+1 90 byte=basef?pf 100 IF byte=&0D baset?3=pt:basef=basef+pf:baset=baset+pt:GOTO 30 110 IF rem GOTO 80 120 IF byte=&22 quote=1-quote:GOTO 170 130 IF quote GOTO 170 140 IF byte=&8D baset!pt=basef!pf:pt=pt+3:pf=pf+3:GOTO 70 150 IF byte=&F4 rem=1:GOTO 170 160 IF byte=&20 GOTO 80 170 baset?pt=byte:GOTO 70 It works by stripping the REM statements and removing any space characters from your program. To use it load your program to be compressed as normal. Then set the PAGE to &900 and load the above program and run it. Line 10 should be set to the same page address as the program being compressed. I remember that there was a better utility available (I think it was a type-in from Acorn or Micro User) that also changed the names of variables from, say, MyVeryLongVariableName% to A%. If anyone has this one kicking about then I would certainly be interested in it. Kind regards, Francis. Loading the program between &900 and &1900 not interfere with DFS function I take it? |
|
| Author: | FrancisL [ Sat Apr 05, 2008 1:30 pm ] |
| Post subject: | Re: Compression of program code |
AndrewW wrote: Loading the program between &900 and &1900 not interfere with DFS function I take it? The compression program should be loaded at &900 and is small enough not to interfere with anything else. Your program to be compressed can be loaded anywhere in memory (within reason) as long as the page is set to the appropriate address in the first line of the compression program. The crunch program that Samwise mentions is far superior to the one I listed and I would recommend its use over this one. Kind regards, Francis. |
|
| Author: | Samwise [ Sat Apr 05, 2008 2:14 pm ] |
| Post subject: | Re: Compression of program code |
For the record, I included the usage description above. This shows how to restrict the various options with *CRUNCH so it can be restricted to only remove REM statements, for instance. It really is quite powerful and elegant. Sam. |
|
| Author: | SteveO [ Sat Apr 05, 2008 3:53 pm ] |
| Post subject: | Re: Compression of program code |
I'm just working on a new version of SWIFT that will allow you to enter basic programs and then transfer to BeebEM in the same was as machine code. This way you can write code with as many REMS as you wish and they will be stripped prior to sending to BeebEm, once there you can issue the CRUNCH to reduce size even more. Advantage of this is that you can have as many REMS as you wish, with CRUNCH you were still limited to what MODE 7 could fit in in total prior to crunching. So you'd keep all your source code in SWIFT and only transfer to the BEEB for the final version. This version will be out tonight if your interested with a quick vid to show you how to use the feature. |
|
| Author: | DaveF [ Sat Apr 05, 2008 10:08 pm ] |
| Post subject: | Re: Compression of program code |
Haha he's unstoppable! Keep up the good work Steve |
|
| Author: | SteveO [ Sat Apr 05, 2008 10:21 pm ] |
| Post subject: | Re: Compression of program code |
It's now up on the Swift page; http://www.retrosoftware.co.uk/swift with a supporting video, sorry no sound with this one due to the PC I was using. But I try and emphasize items by pointing with the mouse ! Basically there's a new project item type for text items. This was designed to allow easier creation of boot files and for keeping notes. However it can also be used to enter BASIC programs. The limitations are that the DFS name you give the file must be !BOOT, but the project name and project item name can be anything you wish. This is because it basically uses this file to "boot" your code into BeebEM. You can see that the BASIC program must also start with the AUTO command, this simply gets the Beeb to convert your BASIC code as text to an actual BASIC program. Once your program has been sent across to BeebEM just press escape and type *CRUNCH (if using the crunch utility) to finish off the compaction job. Then save this code for your commercial release. Have a look at the video and it will hopefully become more obvious ! Note you won't be able to use GOTOs or GOSUBs as you do not enter line numbers, but you shouldn't be using them anyway ! Again this is a Beta version, but version number moved to 3.1 |
|
| Author: | Samwise [ Sat Apr 05, 2008 10:34 pm ] |
| Post subject: | Re: Compression of program code |
Booo!! Don't listen to The Man! ... ain't nothing wrong with the occasional GOTO or GOSUB, if used appropriately. We don't need your rules, Man ... we're free, Man! Like the birds and the trees ... *sniffs* Sam. |
|
| Author: | AndrewW [ Sun Apr 06, 2008 1:16 am ] |
| Post subject: | Re: Compression of program code |
Samwise wrote: For the record, I included the usage description above. This shows how to restrict the various options with *CRUNCH so it can be restricted to only remove REM statements, for instance. It really is quite powerful and elegant. Sam. Yes thanks Samwise, it looks it. I'm just considering what would be more convenient during development using *crunch - or a program below DFS PAGE that removes REMs. Having to Load, crunch/remove, save then run again would require another program or script I think but might be well worth the effort. |
|
| Author: | SteveO [ Sun Apr 06, 2008 7:14 am ] |
| Post subject: | Re: Compression of program code |
Samwise wrote: Booo!! Don't listen to The Man! ... ain't nothing wrong with the occasional GOTO or GOSUB, if used appropriately. We don't need your rules, Man ... we're free, Man! Like the birds and the trees ... *sniffs* Sam. Well, it's hard to cage a free spirit like yours Sam |
|
| Author: | SteveO [ Sun Apr 06, 2008 9:47 am ] |
| Post subject: | Re: Compression of program code |
DaveF wrote: Haha he's unstoppable! Keep up the good work Steve Heh heh, I do seem to have been busy lately ! |
|
| Author: | AndrewW [ Sun Apr 06, 2008 6:36 pm ] |
| Post subject: | Re: Compression of program code |
Which version of Toolkit do you use? I tried 2.05 and with *crunch r it started to completely compact the program eventually saving 1.6K. However, I think those options are to /prevent/ various functions. |
|
| Author: | AndrewW [ Sun Apr 06, 2008 7:32 pm ] |
| Post subject: | Re: Compression of program code |
Here's the script file: BBC Script Machine BBC B OSCLI"BFS" LOAD"VICTORY" OSCLI"CRUNCH BCLSVT:":SAVE"VICTORY2": HMLOAD However, the REM statement (what few there are at the moment) are still there. |
|
| Author: | Samwise [ Sun Apr 06, 2008 7:35 pm ] |
| Post subject: | Re: Compression of program code |
You read the manual extract for *CRUNCH? That sounds like expected output. You specify the parameter to *omit* that function. Sam. |
|
| Page 1 of 2 | All times are UTC [ DST ] |
| Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |
|