It is currently Mon Oct 20, 2014 4:48 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 28 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: Thu Mar 13, 2008 1:23 am 
Offline
User avatar
 WWW  Profile

Joined: Wed Jan 09, 2008 10:23 am
Posts: 359
Location: Glasgow, Scotland
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.


Top
 
PostPosted: Mon Mar 17, 2008 2:18 pm 
Offline
Site Admin
User avatar
 Profile

Joined: Wed Dec 19, 2007 10:46 pm
Posts: 779
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:

  • B Brackets
  • C Program line concatenation
  • L LET statement removal
  • R REM statement removal
  • S Space removal
  • T THEN statement removal
  • V Variable name contractions
  • : Colons and null line removal

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
>


Top
 
PostPosted: Mon Mar 17, 2008 7:45 pm 
Offline
User avatar
 WWW  Profile

Joined: Wed Jan 09, 2008 10:23 am
Posts: 359
Location: Glasgow, Scotland
Ooh, nice! 8-)

That one certainly looks more powerful that the one I had seen. I'll definitely need to give it a try.

Kind regards,

Francis.


Top
 
PostPosted: Tue Mar 18, 2008 2:36 am 
Offline
User avatar
 WWW  Profile

Joined: Wed Jan 09, 2008 10:23 am
Posts: 359
Location: Glasgow, Scotland
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.


Top
 
PostPosted: Tue Mar 18, 2008 11:07 am 
Offline
Site Admin
User avatar
 Profile

Joined: Wed Dec 19, 2007 10:46 pm
Posts: 779
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.


Top
 
PostPosted: Sat Apr 05, 2008 11:46 am 
Offline
User avatar
 Profile

Joined: Tue Mar 25, 2008 4:22 pm
Posts: 129
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?


Top
 
PostPosted: Sat Apr 05, 2008 11:59 am 
Offline
User avatar
 WWW  Profile

Joined: Wed Jan 09, 2008 10:23 am
Posts: 359
Location: Glasgow, Scotland
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.


Top
 
PostPosted: Sat Apr 05, 2008 12:08 pm 
Offline
User avatar
 Profile

Joined: Tue Mar 25, 2008 4:22 pm
Posts: 129
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?


Top
 
PostPosted: Sat Apr 05, 2008 1:30 pm 
Offline
User avatar
 WWW  Profile

Joined: Wed Jan 09, 2008 10:23 am
Posts: 359
Location: Glasgow, Scotland
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.


Top
 
PostPosted: Sat Apr 05, 2008 2:14 pm 
Offline
Site Admin
User avatar
 Profile

Joined: Wed Dec 19, 2007 10:46 pm
Posts: 779
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.


Top
 
PostPosted: Sat Apr 05, 2008 3:53 pm 
Offline
User avatar
 Profile

Joined: Wed Jan 09, 2008 7:30 am
Posts: 406
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.


Top
 
PostPosted: Sat Apr 05, 2008 10:08 pm 
Offline
User avatar
 WWW  Profile

Joined: Thu Apr 03, 2008 2:49 pm
Posts: 277
Location: Antarctica
Haha he's unstoppable!

Keep up the good work Steve :)


Top
 
PostPosted: Sat Apr 05, 2008 10:21 pm 
Offline
User avatar
 Profile

Joined: Wed Jan 09, 2008 7:30 am
Posts: 406
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


Top
 
PostPosted: Sat Apr 05, 2008 10:34 pm 
Offline
Site Admin
User avatar
 Profile

Joined: Wed Dec 19, 2007 10:46 pm
Posts: 779
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.


Top
 
PostPosted: Sun Apr 06, 2008 1:16 am 
Offline
User avatar
 Profile

Joined: Tue Mar 25, 2008 4:22 pm
Posts: 129
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.


Top
 
PostPosted: Sun Apr 06, 2008 7:14 am 
Offline
User avatar
 Profile

Joined: Wed Jan 09, 2008 7:30 am
Posts: 406
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 ;) , just trying to steer you away from the dark side and to the light :) Besides they can slow you code up noticeably compared to Procs, they are the devils statements sent to tempt you !


Top
 
PostPosted: Sun Apr 06, 2008 9:47 am 
Offline
User avatar
 Profile

Joined: Wed Jan 09, 2008 7:30 am
Posts: 406
DaveF wrote:
Haha he's unstoppable!

Keep up the good work Steve :)

Heh heh, I do seem to have been busy lately !


Top
 
PostPosted: Sun Apr 06, 2008 6:36 pm 
Offline
User avatar
 Profile

Joined: Tue Mar 25, 2008 4:22 pm
Posts: 129
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.


Top
 
PostPosted: Sun Apr 06, 2008 7:32 pm 
Offline
User avatar
 Profile

Joined: Tue Mar 25, 2008 4:22 pm
Posts: 129
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.


Top
 
PostPosted: Sun Apr 06, 2008 7:35 pm 
Offline
Site Admin
User avatar
 Profile

Joined: Wed Dec 19, 2007 10:46 pm
Posts: 779
You read the manual extract for *CRUNCH? That sounds like expected output. You specify the parameter to *omit* that function.

Sam.


Top
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 28 posts ]  Go to page 1, 2  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron