home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
TCE Demo 2
/
TCE_DEMO_CD2.iso
/
demo_cd_.2
/
mags
/
stosser
/
stoser05.arj
/
stoser05.msa
/
A
/
7.PNE
< prev
next >
Wrap
Text File
|
1987-04-22
|
7KB
|
304 lines
STOS BITS 'N PIECES
by
Martin Cubitt July 1993
The PACK command explained.
The PACK and UNPACK commands must be
two of the most commonly used commands
from any extension. Issues 5 and 6 of
the STOS Newsletter featured an article
by Francois Lionet explaining how they
work.
This article extracts most of the
information from that article. No copy-
right is expressed. Besides, Francois
would probably like you to know how
clever (and suprisingly simple) the com-
paction method is.
How many parameter does the PACK com-
mand have?
How many of you said two? Well, yes but
that is not the whole story.
You may use two parameters (for the
source and destination banks) or nine
parameters!
The STOS compactor accessory uses all
nine to get the best results of compact-
ion.
The full syntax of the pack command is:
pic_length=PACK source, destination,
resolution, flags, height of block,
start in x, start in y, size of x, size
of y
Wow!
So what do they all do?
SOURCE is the address of the screen to
be packed, as per normal.
DESTINATION is the bank or address
where the compacted data should be
stored.
RESOLUTION tells STOS the mode the pic-
ture has been created in. Obviously this
should be what ever MODE you are in.
This can be retrieved by M=mode.
FLAGS set up information about the
colour palette.
Bit 0: If on, the entire palette will
be set to zero before the picture is
unpacked. If the bit is clear the pal-
ette will not be altered, ideal when un-
packing to a bank. Ideally this flag
would have been given in the UNPACK com-
mand so you can decode this at UNPACK
time. It is possible to change the flag
of a compacted picture, details later.
Bit 1: If on, the palette will change
to that of the screen to be unpacked. If
the bit is clear then the palette will
be unaltered.
The default for both of these bits is 1
(on).
HEIGHT OF BLOCK is covered later, it
sets the packing block size in Y lines.
START IN X states the top left x co-
ordinate from where the picture will be
packed. The value given is the number of
words (2 bytes), so for low resolution 0
would be far left, 10 the middle and 19
the far right.
START IN Y states the top y co-ordinate
of the picture.
SIZE OF X indicates how many words (2
bytes) across from the start x will be
packed, ie. the width.
SIZE OF Y states the number of packing
squares in Y to process. The full length
of the picture area to pack is therefore
square_size * size_in_y.
When using the more detailed version of
the command you must set ALL nine param-
eters, not just the ones you want.
Otherwise the command will be in error.
The compaction method used by STOS is
reasonably simple. I will not go in at
length about some of the more technical
details of how, but give you a basic
idea. I will try to keep it to a level
where most of us get the picture (no pun
intended).
For each byte of the screen (32,000 of
them) we have a single corresponding bit
in an index table. Therefore the index
table will be 32,000 bits long. That
works out to be 4,000 bytes. Another
table is required to store the bytes.
The compaction routine starts off by
examining the bytes from the original
picture systematically. If the current
byte is different from the previous one,
or it is the first byte, it sets the
corresponding bit within the index table
to 1 and stores the current byte into
the bytes table. If however the current
byte is equal to the previously examined
byte then the compactor sets the bit in
the index to 0. Okay so far?
So for the following bytes...
10
10
12
12
12
13
12
10
10
The bits table would be
101001110
and the bytes table
10
12
13
12
10
Okay. So how is this unpacked?
It firsts read the current bit from the
index. If set to 1 then the next byte is
pulled off the bytes table, in my exam-
ple this would be 10. If the bit is not
set, then the previous value is used.
The retrieved byte is poked into the
picture and the loop continues until the
last bit is reached.
If the screen was blank then the bit
table would start with a 1 and then have
31,999 0's.
The byte table would have 0 and that is
all.
So the compacted picture would be 4,000
+ 1 = 4,001 bytes.
That is not so good. An empty picture
should not pack into 4K!
So Francois' routine cleverly packs the
index! This is not packed at bit level
but at byte level. So the new bit index
table will be 4,000 / 8 = 500 bytes. So
the blank picture will be 500 bytes plus
2 bytes for the second bytes tables ($80
and $00) and one byte for the original
bytes table, giving 503 bytes. A lot
better than 4,000 bytes.
Francois did try packing the second
index table but there was generally no
saving. Besides, the process was slowed
down.
So the unpacker actually has to first
rebuild the first index table using the
second index table! Then the first one
can be unpacked.
This principle can be used for non-
screen banks. It is probably the most
simple (without being rubbish) compact-
ion methods around. For this reason it
is fast.
As you may know, the ST's screen is
divided into what is called bit planes.
In low resolution there are four bit
planes. The combination of all four
gives a four bit value which represents
the colour of the pixel at that position
So if
plane 0 - 0
plane 1 - 0
plane 2 - 1
plane 3 - 0
the colour is %0100 = 4
The compactor explores memory plane by
plane. Therefore it loops four times in
low resolution (2 in medium and 1 in
high).
The compactor accessory tries the block
sizes 1,2,4,8,16 and 32. The height of
the block contains the size in Y of
blocks (1 being line by line).
A packed bank creates a header as
follows:
Offset Size Value Description
0 L $06071963 ID (Francois' DOB)
4 W 0/1/2 Resolution
6 W X start (in words)
8 W Y start (in lines)
10 W X size (in words)
12 W No. blocks
14 W - Unused -
16 W Y size of squares
(line)
18 W Flags
20 L Offset to bytes(2)
table
24 L Offset to index(2)
table
28 W W W... palette
70 start of bytes(1)
table
start of index(2)
table
start of bytes(2)
table
So you could actually doke (not poke as
it is as double byte value) the flags to
change them. So to change bit 0 to 1 you
may do
doke start(bank)+18,
deek(start(bank)+18) or
%01
and to set bit 1 to 1 use
doke start(bank)+18,
deek(start(bank)+18) or
%10
To set off bit 0 use
a=deek(start(bank)+18)
a=bclr(a,0)
doke start(bank)+18,a
and to set off bit 1 use
a=deek(start(bank)+18)
a=bclr(a,1)
doke start(bank)+18,a
That's about it. A little confusing but
the main thing is that it works and
works well!
CUBITTM/STOS0005/190793