home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
No Fragments Archive 10: Diskmags
/
nf_archive_10.iso
/
MAGS
/
ST_USER
/
1990
/
USERJL90.MSA
/
TEXT_SCREENFL.DOC
< prev
next >
Wrap
Text File
|
1990-05-15
|
4KB
|
95 lines
Squeeze a quart into a pint pot
SCREENFULL is an exciting new challenge for programmers _ to write a program
that will fit on one standard 80 column by 22 row monitor or TV screen. The
program can be a game, utility, graphic designer, music and MIDI editor or even
a business program. You can use whatever programming language you feel most
comfotable with such as Basic, C, Pascal, STOS or 68000 machine code. The only
condition is that the whole of the source code must fit onto one screen.
The very small size limit on source code may sound quite restricting to ST
programmers who are used to producing large applications, but it is surprising
what can be squeezed into such a small space. Lateral thinking and ingenuity
are essential requirements.
To give you an idea of what can be achieved in Screenfull RLE.BSC and
RLD.BSC are two useful utility programs that will compact almost any file on
disk.
The first utility, a Fast Basic program called RLE.BSC, performs run length
encoding on a file to remove any continuous runs of identical bytes. First, the
file is scanned to see if any byte values in the range 0 to 255 are not used.
If one is found then it is used as a flag to indicate a run. For instance, if a
file contained the following sequence of bytes:
12 17 05 05 05 05 05 05 05 05 05 05 20 18
then a suitable flag would be 00 and the bytes would be conmpacted to:
12 17 00 05 10 20 18
The 00 indicates that a run follows, the byte is 05 and the length of the
run is 10. Notice that here we have a 50% reduction in file size. However, this
compaction method is dependent on there being an unused byte value and runs of
more than three identical bytes.
Text files contain very few runs of identical characters and therefore
aren't good candidates for this compaction method. Pictures, images, data files
and even some program files can usually be compacted to a certain extent.
The second utility, another Fast Basic program called RLD.BSC, takes a run
length encoded file and decompacts it. The run flag is always the first byte of
the file and the utility reads in byte, expands any runs and writes the
decompacted file to disk.
The source code for RLE.BSC and RLD.BSC has been stripped down to the bone
to fit the requirements of Screenfull. Fast Basic's file handling appears to be
quite slow so the code should be converted into a compiled language such as
HiSoft or GFA Basic if you intend to use the utilities seriously.
-----------------------------------------------------------------------------
A:\LISTINGS\RLE.BSC
-----------------------------------------------------------------------------
REM Run Length Encoding - by R.A.Waddilove - in Fast Basic
INPUT "File to compact:"i$
INPUT "Archive filename:"o$
PRINT:PRINT "Scanning file..."
DIM byte%(255)
F%=OPENIN i$
c%=0:REPEAT:byte%(BGET#F%)=1:c%=c%+1:UNTIL EOF#F%:CLOSE#F%
flag%=-1:FOR i%=0 TO 255:IF byte%(i%)=0 THEN flag%=i%
NEXT:IF flag%=-1 THEN PRINT "Can't compact!":END
PRINT "Encoding...":I%=OPENIN i$:O%=OPENOUT o$:BPUT#O%,flag%:b1%=BGET#I%
REPEAT:b2%=BGET#I%:IF b2%=b1% AND EOF#I%=0 THEN
b3%=BGET#I%:IF b3%=b2% AND EOF#I%=0 THEN
BPUT#O%,flag%:BPUT#O%,b1%:c%=2:REPEAT:b1%=BGET#I%:c%=c%+1
UNTIL b1%<>b2% OR c%=255 OR EOF#I%:IF EOF#I% THEN b1%=c%+1 ELSE BPUT#O%,c%
ELSE
BPUT#O%,b1%:BPUT#O%,b2%:b1%=b3%
ENDIF
ELSE
BPUT#O%,b1%:b1%=b2%
ENDIF
UNTIL EOF#I%:BPUT#O%,b1%:CLOSE#I%:CLOSE#O%
END
-----------------------------------------------------------------------------
A:\LISTINGS\RLD.BSC
-----------------------------------------------------------------------------
REM Run Length Decoding - by R.A.Waddilove - in Fast Basic
INPUT "File to decompact:"i$
INPUT "New filename:"o$
DELFILE o$ : \just a precaution
PRINT:PRINT "Decoding file..."
I%=OPENIN i$ : \open file to compact
flag%=BGET#I% : \get run length flag
O%=OPENOUT o$ : \open file to create
REPEAT
byte%=BGET#I%
IF byte%=flag% THEN
byte%=BGET#I% : count%=BGET#I%
FOR J%=1 TO count%
BPUT#O%,byte% : \ run of count%, bytes%
NEXT
ELSE
BPUT#O%,byte%
ENDIF
UNTIL EOF#I%
CLOSE#I%:CLOSE#O% : \close files
END
-----------------------------------------------------------------------------