Home » Personal collection » Acorn hard disk » apps » web » !ChangeFSI/256sprites

!ChangeFSI/256sprites

This website contains an archive of files for the Acorn Electron, BBC Micro, Acorn Archimedes, Commodore 16 and Commodore 64 computers, which Dominic Ford has rescued from his private collection of floppy disks and cassettes.

Some of these files were originally commercial releases in the 1980s and 1990s, but they are now widely available online. I assume that copyright over them is no longer being asserted. If you own the copyright and would like files to be removed, please contact me.

Tape/disk: Home » Personal collection » Acorn hard disk » apps » web
Filename: !ChangeFSI/256sprites
Read OK:
File size: 122F bytes
Load address: 0000
Exec address: 0000
Duplicates

There are 3 duplicate copies of this file in the archive:

File contents
         256 entry palettes in the RISC OS sprite format
         ===============================================

Introduction
------------

The RISC OS sprite format provides for pictures with and without palettes in
1, 2 and 4 bits per pixel. For 8 bits per pixel a picture with no palette is
dealt with rationally, but a picture with a palette will end up with 64
(pairs of) palette entries. (The pairs of entries are for the possibly
flashing colours). The reader of the format must know how VIDC1's 16 entry
palette works in 8bit mode and apply the necessary bit reordering.

By stepping gingerly around the sprite operations and using ColourTrans
appropriately, sprites with 256 entry palettes can be created and
displayed on all RISC OS machines. Of course, this ability to create and
process a sprite with (say) 256 grey levels in it does not magically
endow the hardware with the ability to display 256 grey levels! The display
will be as close as possible i.e. 16 grey levels with standard hardware;
unless the machine has been hardware extended (e.g. the PCATS Graphics
Enhancer).

Format of a 256 entry palette sprite
------------------------------------

A 256 entry palette sprite is precisely like a 16 entry palette sprite, save
that there are 256 palette entries, each one consisting of a pair of
"palette entry" words of the form &BBGGRR00 as for ColourTrans. All bits of
the entry are significant.

Creating a 256 entry palette sprite
-----------------------------------

If you use OS_SpriteOp 15 to create a sprite with a palette, the OS will
create a 64 entry palette as before. The best thing to do is to create a
sprite with no palette and then to add 2048 to the following entries:

word 1: offset to next sprite
word 9: offset to sprite image
word 10: offset to sprite image/transparency mask

of the sprite and then to add 2048 to

word 4: offset to first free word

of the sprite area control block.

Then write the 256 double words of palette entries starting at word 12
of the sprite, keeping both items in a pair identical:

SYS"OS_SpriteOp",&10f,ram%,name$,0,X,Y,spritemode
sptr%=ram%+ram%!8
pal%=sptr%+11*4
!(sptr%+8*4)+=2048
!(sptr%+9*4)+=2048
!sptr%+=2048
!(ram%+12)+=2048
FORZ%=0TO255:B%=palette!(Z%<<2)ANDNOT&FF
 pal%!(Z%*8)=B%:pal%!(Z%*8+4)=B%
NEXT

Manipulating a 256 entry palette sprite
---------------------------------------

All sprite operations work on the 256 entry palette sprite. One can even
switch output to it and generate 256 grey level output into it (with
appropriate care over the GCOL and TINT values required by the OS). Sprite
areas containing 256 entry palette sprites may be loaded, saved etc.

Testing to see if a sprite is a 256 entry palette sprite
--------------------------------------------------------

After creation, the 256 entry palette sprite behaves just like all the
others, so its important to be able to distinguish it on the occasions when
it is needed (for example, when displaying it on the screen).

A 256 entry palette sprite will have the lowest of words 9 and 10 of the
sprite control block equal to 2048+44 (&82C). (If it is already known that
the sprite has no transparency mask, then one can test only word 9).

Displaying a 256 entry palette sprite
-------------------------------------

The call "ColourTrans_SelectTable" takes a 64 entry palette sprite (and 2, 4
and 16) and returns a pixel translation table as needed for OS_SpriteOp 52.
For a 256 entry sprite, one needs to build a similar pixel translation
table directly. The following code will compute a pixel translation table
for any sprite (which hasn't a transparency mask):

IF sptr%!32=44 THEN
 palptr%=0
ELSE
 FOR grab%=0 TO 2048-8 STEP 8
  paltemp%!(grab%>>1)=sptr%!(grab%+44)
 NEXT
 palptr%=paltemp%
ENDIF
FORQ%=0TO255:pixtrans%?Q%=Q%:NEXT
IFsptr%!32=44+2048 THEN
 FORQ%=0TO255
  SYS"ColourTrans_ReturnColourNumber",palptr%!(Q%<<2) TO pixtrans%?Q%
 NEXT
ELSE
 SYS "ColourTrans_SelectTable",m,palptr%,-1,-1,pixtrans%
ENDIF
spx%=-1:FORQ%=0TO255:IFpixtrans%?Q%<>Q% spx%=pixtrans%
NEXT

spx% is either -1 (if no translation needs to be done - this speeds up
OS_SpriteOp 52 a lot!) or pixtrans%; it is passed to OS_SpriteOp 52 in
register 7.

Conclusion
----------

The ability to store, process and display 256 entry palette sprites
represents a small but useful gain for the RISC OS desktop. Common formats
can be converted to sprites without any loss of information and meaningfully
displayed. (Greater fidelity of display can be had with !ChangeFSI (which
can read and generate 256 entry palette sprites) or !Translator)

It is still a good idea to use the default desktop palette whenever possibl���
00000000  20 20 20 20 20 20 20 20  20 32 35 36 20 65 6e 74  |         256 ent|
00000010  72 79 20 70 61 6c 65 74  74 65 73 20 69 6e 20 74  |ry palettes in t|
00000020  68 65 20 52 49 53 43 20  4f 53 20 73 70 72 69 74  |he RISC OS sprit|
00000030  65 20 66 6f 72 6d 61 74  0a 20 20 20 20 20 20 20  |e format.       |
00000040  20 20 3d 3d 3d 3d 3d 3d  3d 3d 3d 3d 3d 3d 3d 3d  |  ==============|
00000050  3d 3d 3d 3d 3d 3d 3d 3d  3d 3d 3d 3d 3d 3d 3d 3d  |================|
*
00000070  3d 0a 0a 49 6e 74 72 6f  64 75 63 74 69 6f 6e 0a  |=..Introduction.|
00000080  2d 2d 2d 2d 2d 2d 2d 2d  2d 2d 2d 2d 0a 0a 54 68  |------------..Th|
00000090  65 20 52 49 53 43 20 4f  53 20 73 70 72 69 74 65  |e RISC OS sprite|
000000a0  20 66 6f 72 6d 61 74 20  70 72 6f 76 69 64 65 73  | format provides|
000000b0  20 66 6f 72 20 70 69 63  74 75 72 65 73 20 77 69  | for pictures wi|
000000c0  74 68 20 61 6e 64 20 77  69 74 68 6f 75 74 20 70  |th and without p|
000000d0  61 6c 65 74 74 65 73 20  69 6e 0a 31 2c 20 32 20  |alettes in.1, 2 |
000000e0  61 6e 64 20 34 20 62 69  74 73 20 70 65 72 20 70  |and 4 bits per p|
000000f0  69 78 65 6c 2e 20 46 6f  72 20 38 20 62 69 74 73  |ixel. For 8 bits|
00000100  20 70 65 72 20 70 69 78  65 6c 20 61 20 70 69 63  | per pixel a pic|
00000110  74 75 72 65 20 77 69 74  68 20 6e 6f 20 70 61 6c  |ture with no pal|
00000120  65 74 74 65 20 69 73 0a  64 65 61 6c 74 20 77 69  |ette is.dealt wi|
00000130  74 68 20 72 61 74 69 6f  6e 61 6c 6c 79 2c 20 62  |th rationally, b|
00000140  75 74 20 61 20 70 69 63  74 75 72 65 20 77 69 74  |ut a picture wit|
00000150  68 20 61 20 70 61 6c 65  74 74 65 20 77 69 6c 6c  |h a palette will|
00000160  20 65 6e 64 20 75 70 20  77 69 74 68 20 36 34 0a  | end up with 64.|
00000170  28 70 61 69 72 73 20 6f  66 29 20 70 61 6c 65 74  |(pairs of) palet|
00000180  74 65 20 65 6e 74 72 69  65 73 2e 20 28 54 68 65  |te entries. (The|
00000190  20 70 61 69 72 73 20 6f  66 20 65 6e 74 72 69 65  | pairs of entrie|
000001a0  73 20 61 72 65 20 66 6f  72 20 74 68 65 20 70 6f  |s are for the po|
000001b0  73 73 69 62 6c 79 0a 66  6c 61 73 68 69 6e 67 20  |ssibly.flashing |
000001c0  63 6f 6c 6f 75 72 73 29  2e 20 54 68 65 20 72 65  |colours). The re|
000001d0  61 64 65 72 20 6f 66 20  74 68 65 20 66 6f 72 6d  |ader of the form|
000001e0  61 74 20 6d 75 73 74 20  6b 6e 6f 77 20 68 6f 77  |at must know how|
000001f0  20 56 49 44 43 31 27 73  20 31 36 20 65 6e 74 72  | VIDC1's 16 entr|
00000200  79 0a 70 61 6c 65 74 74  65 20 77 6f 72 6b 73 20  |y.palette works |
00000210  69 6e 20 38 62 69 74 20  6d 6f 64 65 20 61 6e 64  |in 8bit mode and|
00000220  20 61 70 70 6c 79 20 74  68 65 20 6e 65 63 65 73  | apply the neces|
00000230  73 61 72 79 20 62 69 74  20 72 65 6f 72 64 65 72  |sary bit reorder|
00000240  69 6e 67 2e 0a 0a 42 79  20 73 74 65 70 70 69 6e  |ing...By steppin|
00000250  67 20 67 69 6e 67 65 72  6c 79 20 61 72 6f 75 6e  |g gingerly aroun|
00000260  64 20 74 68 65 20 73 70  72 69 74 65 20 6f 70 65  |d the sprite ope|
00000270  72 61 74 69 6f 6e 73 20  61 6e 64 20 75 73 69 6e  |rations and usin|
00000280  67 20 43 6f 6c 6f 75 72  54 72 61 6e 73 0a 61 70  |g ColourTrans.ap|
00000290  70 72 6f 70 72 69 61 74  65 6c 79 2c 20 73 70 72  |propriately, spr|
000002a0  69 74 65 73 20 77 69 74  68 20 32 35 36 20 65 6e  |ites with 256 en|
000002b0  74 72 79 20 70 61 6c 65  74 74 65 73 20 63 61 6e  |try palettes can|
000002c0  20 62 65 20 63 72 65 61  74 65 64 20 61 6e 64 0a  | be created and.|
000002d0  64 69 73 70 6c 61 79 65  64 20 6f 6e 20 61 6c 6c  |displayed on all|
000002e0  20 52 49 53 43 20 4f 53  20 6d 61 63 68 69 6e 65  | RISC OS machine|
000002f0  73 2e 20 4f 66 20 63 6f  75 72 73 65 2c 20 74 68  |s. Of course, th|
00000300  69 73 20 61 62 69 6c 69  74 79 20 74 6f 20 63 72  |is ability to cr|
00000310  65 61 74 65 20 61 6e 64  0a 70 72 6f 63 65 73 73  |eate and.process|
00000320  20 61 20 73 70 72 69 74  65 20 77 69 74 68 20 28  | a sprite with (|
00000330  73 61 79 29 20 32 35 36  20 67 72 65 79 20 6c 65  |say) 256 grey le|
00000340  76 65 6c 73 20 69 6e 20  69 74 20 64 6f 65 73 20  |vels in it does |
00000350  6e 6f 74 20 6d 61 67 69  63 61 6c 6c 79 0a 65 6e  |not magically.en|
00000360  64 6f 77 20 74 68 65 20  68 61 72 64 77 61 72 65  |dow the hardware|
00000370  20 77 69 74 68 20 74 68  65 20 61 62 69 6c 69 74  | with the abilit|
00000380  79 20 74 6f 20 64 69 73  70 6c 61 79 20 32 35 36  |y to display 256|
00000390  20 67 72 65 79 20 6c 65  76 65 6c 73 21 20 54 68  | grey levels! Th|
000003a0  65 20 64 69 73 70 6c 61  79 0a 77 69 6c 6c 20 62  |e display.will b|
000003b0  65 20 61 73 20 63 6c 6f  73 65 20 61 73 20 70 6f  |e as close as po|
000003c0  73 73 69 62 6c 65 20 69  2e 65 2e 20 31 36 20 67  |ssible i.e. 16 g|
000003d0  72 65 79 20 6c 65 76 65  6c 73 20 77 69 74 68 20  |rey levels with |
000003e0  73 74 61 6e 64 61 72 64  20 68 61 72 64 77 61 72  |standard hardwar|
000003f0  65 3b 0a 75 6e 6c 65 73  73 20 74 68 65 20 6d 61  |e;.unless the ma|
00000400  63 68 69 6e 65 20 68 61  73 20 62 65 65 6e 20 68  |chine has been h|
00000410  61 72 64 77 61 72 65 20  65 78 74 65 6e 64 65 64  |ardware extended|
00000420  20 28 65 2e 67 2e 20 74  68 65 20 50 43 41 54 53  | (e.g. the PCATS|
00000430  20 47 72 61 70 68 69 63  73 0a 45 6e 68 61 6e 63  | Graphics.Enhanc|
00000440  65 72 29 2e 0a 0a 46 6f  72 6d 61 74 20 6f 66 20  |er)...Format of |
00000450  61 20 32 35 36 20 65 6e  74 72 79 20 70 61 6c 65  |a 256 entry pale|
00000460  74 74 65 20 73 70 72 69  74 65 0a 2d 2d 2d 2d 2d  |tte sprite.-----|
00000470  2d 2d 2d 2d 2d 2d 2d 2d  2d 2d 2d 2d 2d 2d 2d 2d  |----------------|
00000480  2d 2d 2d 2d 2d 2d 2d 2d  2d 2d 2d 2d 2d 2d 2d 0a  |---------------.|
00000490  0a 41 20 32 35 36 20 65  6e 74 72 79 20 70 61 6c  |.A 256 entry pal|
000004a0  65 74 74 65 20 73 70 72  69 74 65 20 69 73 20 70  |ette sprite is p|
000004b0  72 65 63 69 73 65 6c 79  20 6c 69 6b 65 20 61 20  |recisely like a |
000004c0  31 36 20 65 6e 74 72 79  20 70 61 6c 65 74 74 65  |16 entry palette|
000004d0  20 73 70 72 69 74 65 2c  20 73 61 76 65 0a 74 68  | sprite, save.th|
000004e0  61 74 20 74 68 65 72 65  20 61 72 65 20 32 35 36  |at there are 256|
000004f0  20 70 61 6c 65 74 74 65  20 65 6e 74 72 69 65 73  | palette entries|
00000500  2c 20 65 61 63 68 20 6f  6e 65 20 63 6f 6e 73 69  |, each one consi|
00000510  73 74 69 6e 67 20 6f 66  20 61 20 70 61 69 72 20  |sting of a pair |
00000520  6f 66 0a 22 70 61 6c 65  74 74 65 20 65 6e 74 72  |of."palette entr|
00000530  79 22 20 77 6f 72 64 73  20 6f 66 20 74 68 65 20  |y" words of the |
00000540  66 6f 72 6d 20 26 42 42  47 47 52 52 30 30 20 61  |form &BBGGRR00 a|
00000550  73 20 66 6f 72 20 43 6f  6c 6f 75 72 54 72 61 6e  |s for ColourTran|
00000560  73 2e 20 41 6c 6c 20 62  69 74 73 20 6f 66 0a 74  |s. All bits of.t|
00000570  68 65 20 65 6e 74 72 79  20 61 72 65 20 73 69 67  |he entry are sig|
00000580  6e 69 66 69 63 61 6e 74  2e 0a 0a 43 72 65 61 74  |nificant...Creat|
00000590  69 6e 67 20 61 20 32 35  36 20 65 6e 74 72 79 20  |ing a 256 entry |
000005a0  70 61 6c 65 74 74 65 20  73 70 72 69 74 65 0a 2d  |palette sprite.-|
000005b0  2d 2d 2d 2d 2d 2d 2d 2d  2d 2d 2d 2d 2d 2d 2d 2d  |----------------|
*
000005d0  2d 2d 0a 0a 49 66 20 79  6f 75 20 75 73 65 20 4f  |--..If you use O|
000005e0  53 5f 53 70 72 69 74 65  4f 70 20 31 35 20 74 6f  |S_SpriteOp 15 to|
000005f0  20 63 72 65 61 74 65 20  61 20 73 70 72 69 74 65  | create a sprite|
00000600  20 77 69 74 68 20 61 20  70 61 6c 65 74 74 65 2c  | with a palette,|
00000610  20 74 68 65 20 4f 53 20  77 69 6c 6c 0a 63 72 65  | the OS will.cre|
00000620  61 74 65 20 61 20 36 34  20 65 6e 74 72 79 20 70  |ate a 64 entry p|
00000630  61 6c 65 74 74 65 20 61  73 20 62 65 66 6f 72 65  |alette as before|
00000640  2e 20 54 68 65 20 62 65  73 74 20 74 68 69 6e 67  |. The best thing|
00000650  20 74 6f 20 64 6f 20 69  73 20 74 6f 20 63 72 65  | to do is to cre|
00000660  61 74 65 20 61 0a 73 70  72 69 74 65 20 77 69 74  |ate a.sprite wit|
00000670  68 20 6e 6f 20 70 61 6c  65 74 74 65 20 61 6e 64  |h no palette and|
00000680  20 74 68 65 6e 20 74 6f  20 61 64 64 20 32 30 34  | then to add 204|
00000690  38 20 74 6f 20 74 68 65  20 66 6f 6c 6c 6f 77 69  |8 to the followi|
000006a0  6e 67 20 65 6e 74 72 69  65 73 3a 0a 0a 77 6f 72  |ng entries:..wor|
000006b0  64 20 31 3a 20 6f 66 66  73 65 74 20 74 6f 20 6e  |d 1: offset to n|
000006c0  65 78 74 20 73 70 72 69  74 65 0a 77 6f 72 64 20  |ext sprite.word |
000006d0  39 3a 20 6f 66 66 73 65  74 20 74 6f 20 73 70 72  |9: offset to spr|
000006e0  69 74 65 20 69 6d 61 67  65 0a 77 6f 72 64 20 31  |ite image.word 1|
000006f0  30 3a 20 6f 66 66 73 65  74 20 74 6f 20 73 70 72  |0: offset to spr|
00000700  69 74 65 20 69 6d 61 67  65 2f 74 72 61 6e 73 70  |ite image/transp|
00000710  61 72 65 6e 63 79 20 6d  61 73 6b 0a 0a 6f 66 20  |arency mask..of |
00000720  74 68 65 20 73 70 72 69  74 65 20 61 6e 64 20 74  |the sprite and t|
00000730  68 65 6e 20 74 6f 20 61  64 64 20 32 30 34 38 20  |hen to add 2048 |
00000740  74 6f 0a 0a 77 6f 72 64  20 34 3a 20 6f 66 66 73  |to..word 4: offs|
00000750  65 74 20 74 6f 20 66 69  72 73 74 20 66 72 65 65  |et to first free|
00000760  20 77 6f 72 64 0a 0a 6f  66 20 74 68 65 20 73 70  | word..of the sp|
00000770  72 69 74 65 20 61 72 65  61 20 63 6f 6e 74 72 6f  |rite area contro|
00000780  6c 20 62 6c 6f 63 6b 2e  0a 0a 54 68 65 6e 20 77  |l block...Then w|
00000790  72 69 74 65 20 74 68 65  20 32 35 36 20 64 6f 75  |rite the 256 dou|
000007a0  62 6c 65 20 77 6f 72 64  73 20 6f 66 20 70 61 6c  |ble words of pal|
000007b0  65 74 74 65 20 65 6e 74  72 69 65 73 20 73 74 61  |ette entries sta|
000007c0  72 74 69 6e 67 20 61 74  20 77 6f 72 64 20 31 32  |rting at word 12|
000007d0  0a 6f 66 20 74 68 65 20  73 70 72 69 74 65 2c 20  |.of the sprite, |
000007e0  6b 65 65 70 69 6e 67 20  62 6f 74 68 20 69 74 65  |keeping both ite|
000007f0  6d 73 20 69 6e 20 61 20  70 61 69 72 20 69 64 65  |ms in a pair ide|
00000800  6e 74 69 63 61 6c 3a 0a  0a 53 59 53 22 4f 53 5f  |ntical:..SYS"OS_|
00000810  53 70 72 69 74 65 4f 70  22 2c 26 31 30 66 2c 72  |SpriteOp",&10f,r|
00000820  61 6d 25 2c 6e 61 6d 65  24 2c 30 2c 58 2c 59 2c  |am%,name$,0,X,Y,|
00000830  73 70 72 69 74 65 6d 6f  64 65 0a 73 70 74 72 25  |spritemode.sptr%|
00000840  3d 72 61 6d 25 2b 72 61  6d 25 21 38 0a 70 61 6c  |=ram%+ram%!8.pal|
00000850  25 3d 73 70 74 72 25 2b  31 31 2a 34 0a 21 28 73  |%=sptr%+11*4.!(s|
00000860  70 74 72 25 2b 38 2a 34  29 2b 3d 32 30 34 38 0a  |ptr%+8*4)+=2048.|
00000870  21 28 73 70 74 72 25 2b  39 2a 34 29 2b 3d 32 30  |!(sptr%+9*4)+=20|
00000880  34 38 0a 21 73 70 74 72  25 2b 3d 32 30 34 38 0a  |48.!sptr%+=2048.|
00000890  21 28 72 61 6d 25 2b 31  32 29 2b 3d 32 30 34 38  |!(ram%+12)+=2048|
000008a0  0a 46 4f 52 5a 25 3d 30  54 4f 32 35 35 3a 42 25  |.FORZ%=0TO255:B%|
000008b0  3d 70 61 6c 65 74 74 65  21 28 5a 25 3c 3c 32 29  |=palette!(Z%<<2)|
000008c0  41 4e 44 4e 4f 54 26 46  46 0a 20 70 61 6c 25 21  |ANDNOT&FF. pal%!|
000008d0  28 5a 25 2a 38 29 3d 42  25 3a 70 61 6c 25 21 28  |(Z%*8)=B%:pal%!(|
000008e0  5a 25 2a 38 2b 34 29 3d  42 25 0a 4e 45 58 54 0a  |Z%*8+4)=B%.NEXT.|
000008f0  0a 4d 61 6e 69 70 75 6c  61 74 69 6e 67 20 61 20  |.Manipulating a |
00000900  32 35 36 20 65 6e 74 72  79 20 70 61 6c 65 74 74  |256 entry palett|
00000910  65 20 73 70 72 69 74 65  0a 2d 2d 2d 2d 2d 2d 2d  |e sprite.-------|
00000920  2d 2d 2d 2d 2d 2d 2d 2d  2d 2d 2d 2d 2d 2d 2d 2d  |----------------|
*
00000940  0a 0a 41 6c 6c 20 73 70  72 69 74 65 20 6f 70 65  |..All sprite ope|
00000950  72 61 74 69 6f 6e 73 20  77 6f 72 6b 20 6f 6e 20  |rations work on |
00000960  74 68 65 20 32 35 36 20  65 6e 74 72 79 20 70 61  |the 256 entry pa|
00000970  6c 65 74 74 65 20 73 70  72 69 74 65 2e 20 4f 6e  |lette sprite. On|
00000980  65 20 63 61 6e 20 65 76  65 6e 0a 73 77 69 74 63  |e can even.switc|
00000990  68 20 6f 75 74 70 75 74  20 74 6f 20 69 74 20 61  |h output to it a|
000009a0  6e 64 20 67 65 6e 65 72  61 74 65 20 32 35 36 20  |nd generate 256 |
000009b0  67 72 65 79 20 6c 65 76  65 6c 20 6f 75 74 70 75  |grey level outpu|
000009c0  74 20 69 6e 74 6f 20 69  74 20 28 77 69 74 68 0a  |t into it (with.|
000009d0  61 70 70 72 6f 70 72 69  61 74 65 20 63 61 72 65  |appropriate care|
000009e0  20 6f 76 65 72 20 74 68  65 20 47 43 4f 4c 20 61  | over the GCOL a|
000009f0  6e 64 20 54 49 4e 54 20  76 61 6c 75 65 73 20 72  |nd TINT values r|
00000a00  65 71 75 69 72 65 64 20  62 79 20 74 68 65 20 4f  |equired by the O|
00000a10  53 29 2e 20 53 70 72 69  74 65 0a 61 72 65 61 73  |S). Sprite.areas|
00000a20  20 63 6f 6e 74 61 69 6e  69 6e 67 20 32 35 36 20  | containing 256 |
00000a30  65 6e 74 72 79 20 70 61  6c 65 74 74 65 20 73 70  |entry palette sp|
00000a40  72 69 74 65 73 20 6d 61  79 20 62 65 20 6c 6f 61  |rites may be loa|
00000a50  64 65 64 2c 20 73 61 76  65 64 20 65 74 63 2e 0a  |ded, saved etc..|
00000a60  0a 54 65 73 74 69 6e 67  20 74 6f 20 73 65 65 20  |.Testing to see |
00000a70  69 66 20 61 20 73 70 72  69 74 65 20 69 73 20 61  |if a sprite is a|
00000a80  20 32 35 36 20 65 6e 74  72 79 20 70 61 6c 65 74  | 256 entry palet|
00000a90  74 65 20 73 70 72 69 74  65 0a 2d 2d 2d 2d 2d 2d  |te sprite.------|
00000aa0  2d 2d 2d 2d 2d 2d 2d 2d  2d 2d 2d 2d 2d 2d 2d 2d  |----------------|
*
00000ad0  2d 2d 0a 0a 41 66 74 65  72 20 63 72 65 61 74 69  |--..After creati|
00000ae0  6f 6e 2c 20 74 68 65 20  32 35 36 20 65 6e 74 72  |on, the 256 entr|
00000af0  79 20 70 61 6c 65 74 74  65 20 73 70 72 69 74 65  |y palette sprite|
00000b00  20 62 65 68 61 76 65 73  20 6a 75 73 74 20 6c 69  | behaves just li|
00000b10  6b 65 20 61 6c 6c 20 74  68 65 0a 6f 74 68 65 72  |ke all the.other|
00000b20  73 2c 20 73 6f 20 69 74  73 20 69 6d 70 6f 72 74  |s, so its import|
00000b30  61 6e 74 20 74 6f 20 62  65 20 61 62 6c 65 20 74  |ant to be able t|
00000b40  6f 20 64 69 73 74 69 6e  67 75 69 73 68 20 69 74  |o distinguish it|
00000b50  20 6f 6e 20 74 68 65 20  6f 63 63 61 73 69 6f 6e  | on the occasion|
00000b60  73 20 77 68 65 6e 0a 69  74 20 69 73 20 6e 65 65  |s when.it is nee|
00000b70  64 65 64 20 28 66 6f 72  20 65 78 61 6d 70 6c 65  |ded (for example|
00000b80  2c 20 77 68 65 6e 20 64  69 73 70 6c 61 79 69 6e  |, when displayin|
00000b90  67 20 69 74 20 6f 6e 20  74 68 65 20 73 63 72 65  |g it on the scre|
00000ba0  65 6e 29 2e 0a 0a 41 20  32 35 36 20 65 6e 74 72  |en)...A 256 entr|
00000bb0  79 20 70 61 6c 65 74 74  65 20 73 70 72 69 74 65  |y palette sprite|
00000bc0  20 77 69 6c 6c 20 68 61  76 65 20 74 68 65 20 6c  | will have the l|
00000bd0  6f 77 65 73 74 20 6f 66  20 77 6f 72 64 73 20 39  |owest of words 9|
00000be0  20 61 6e 64 20 31 30 20  6f 66 20 74 68 65 0a 73  | and 10 of the.s|
00000bf0  70 72 69 74 65 20 63 6f  6e 74 72 6f 6c 20 62 6c  |prite control bl|
00000c00  6f 63 6b 20 65 71 75 61  6c 20 74 6f 20 32 30 34  |ock equal to 204|
00000c10  38 2b 34 34 20 28 26 38  32 43 29 2e 20 28 49 66  |8+44 (&82C). (If|
00000c20  20 69 74 20 69 73 20 61  6c 72 65 61 64 79 20 6b  | it is already k|
00000c30  6e 6f 77 6e 20 74 68 61  74 0a 74 68 65 20 73 70  |nown that.the sp|
00000c40  72 69 74 65 20 68 61 73  20 6e 6f 20 74 72 61 6e  |rite has no tran|
00000c50  73 70 61 72 65 6e 63 79  20 6d 61 73 6b 2c 20 74  |sparency mask, t|
00000c60  68 65 6e 20 6f 6e 65 20  63 61 6e 20 74 65 73 74  |hen one can test|
00000c70  20 6f 6e 6c 79 20 77 6f  72 64 20 39 29 2e 0a 0a  | only word 9)...|
00000c80  44 69 73 70 6c 61 79 69  6e 67 20 61 20 32 35 36  |Displaying a 256|
00000c90  20 65 6e 74 72 79 20 70  61 6c 65 74 74 65 20 73  | entry palette s|
00000ca0  70 72 69 74 65 0a 2d 2d  2d 2d 2d 2d 2d 2d 2d 2d  |prite.----------|
00000cb0  2d 2d 2d 2d 2d 2d 2d 2d  2d 2d 2d 2d 2d 2d 2d 2d  |----------------|
00000cc0  2d 2d 2d 2d 2d 2d 2d 2d  2d 2d 2d 0a 0a 54 68 65  |-----------..The|
00000cd0  20 63 61 6c 6c 20 22 43  6f 6c 6f 75 72 54 72 61  | call "ColourTra|
00000ce0  6e 73 5f 53 65 6c 65 63  74 54 61 62 6c 65 22 20  |ns_SelectTable" |
00000cf0  74 61 6b 65 73 20 61 20  36 34 20 65 6e 74 72 79  |takes a 64 entry|
00000d00  20 70 61 6c 65 74 74 65  20 73 70 72 69 74 65 20  | palette sprite |
00000d10  28 61 6e 64 20 32 2c 20  34 0a 61 6e 64 20 31 36  |(and 2, 4.and 16|
00000d20  29 20 61 6e 64 20 72 65  74 75 72 6e 73 20 61 20  |) and returns a |
00000d30  70 69 78 65 6c 20 74 72  61 6e 73 6c 61 74 69 6f  |pixel translatio|
00000d40  6e 20 74 61 62 6c 65 20  61 73 20 6e 65 65 64 65  |n table as neede|
00000d50  64 20 66 6f 72 20 4f 53  5f 53 70 72 69 74 65 4f  |d for OS_SpriteO|
00000d60  70 20 35 32 2e 0a 46 6f  72 20 61 20 32 35 36 20  |p 52..For a 256 |
00000d70  65 6e 74 72 79 20 73 70  72 69 74 65 2c 20 6f 6e  |entry sprite, on|
00000d80  65 20 6e 65 65 64 73 20  74 6f 20 62 75 69 6c 64  |e needs to build|
00000d90  20 61 20 73 69 6d 69 6c  61 72 20 70 69 78 65 6c  | a similar pixel|
00000da0  20 74 72 61 6e 73 6c 61  74 69 6f 6e 0a 74 61 62  | translation.tab|
00000db0  6c 65 20 64 69 72 65 63  74 6c 79 2e 20 54 68 65  |le directly. The|
00000dc0  20 66 6f 6c 6c 6f 77 69  6e 67 20 63 6f 64 65 20  | following code |
00000dd0  77 69 6c 6c 20 63 6f 6d  70 75 74 65 20 61 20 70  |will compute a p|
00000de0  69 78 65 6c 20 74 72 61  6e 73 6c 61 74 69 6f 6e  |ixel translation|
00000df0  20 74 61 62 6c 65 0a 66  6f 72 20 61 6e 79 20 73  | table.for any s|
00000e00  70 72 69 74 65 20 28 77  68 69 63 68 20 68 61 73  |prite (which has|
00000e10  6e 27 74 20 61 20 74 72  61 6e 73 70 61 72 65 6e  |n't a transparen|
00000e20  63 79 20 6d 61 73 6b 29  3a 0a 0a 49 46 20 73 70  |cy mask):..IF sp|
00000e30  74 72 25 21 33 32 3d 34  34 20 54 48 45 4e 0a 20  |tr%!32=44 THEN. |
00000e40  70 61 6c 70 74 72 25 3d  30 0a 45 4c 53 45 0a 20  |palptr%=0.ELSE. |
00000e50  46 4f 52 20 67 72 61 62  25 3d 30 20 54 4f 20 32  |FOR grab%=0 TO 2|
00000e60  30 34 38 2d 38 20 53 54  45 50 20 38 0a 20 20 70  |048-8 STEP 8.  p|
00000e70  61 6c 74 65 6d 70 25 21  28 67 72 61 62 25 3e 3e  |altemp%!(grab%>>|
00000e80  31 29 3d 73 70 74 72 25  21 28 67 72 61 62 25 2b  |1)=sptr%!(grab%+|
00000e90  34 34 29 0a 20 4e 45 58  54 0a 20 70 61 6c 70 74  |44). NEXT. palpt|
00000ea0  72 25 3d 70 61 6c 74 65  6d 70 25 0a 45 4e 44 49  |r%=paltemp%.ENDI|
00000eb0  46 0a 46 4f 52 51 25 3d  30 54 4f 32 35 35 3a 70  |F.FORQ%=0TO255:p|
00000ec0  69 78 74 72 61 6e 73 25  3f 51 25 3d 51 25 3a 4e  |ixtrans%?Q%=Q%:N|
00000ed0  45 58 54 0a 49 46 73 70  74 72 25 21 33 32 3d 34  |EXT.IFsptr%!32=4|
00000ee0  34 2b 32 30 34 38 20 54  48 45 4e 0a 20 46 4f 52  |4+2048 THEN. FOR|
00000ef0  51 25 3d 30 54 4f 32 35  35 0a 20 20 53 59 53 22  |Q%=0TO255.  SYS"|
00000f00  43 6f 6c 6f 75 72 54 72  61 6e 73 5f 52 65 74 75  |ColourTrans_Retu|
00000f10  72 6e 43 6f 6c 6f 75 72  4e 75 6d 62 65 72 22 2c  |rnColourNumber",|
00000f20  70 61 6c 70 74 72 25 21  28 51 25 3c 3c 32 29 20  |palptr%!(Q%<<2) |
00000f30  54 4f 20 70 69 78 74 72  61 6e 73 25 3f 51 25 0a  |TO pixtrans%?Q%.|
00000f40  20 4e 45 58 54 0a 45 4c  53 45 0a 20 53 59 53 20  | NEXT.ELSE. SYS |
00000f50  22 43 6f 6c 6f 75 72 54  72 61 6e 73 5f 53 65 6c  |"ColourTrans_Sel|
00000f60  65 63 74 54 61 62 6c 65  22 2c 6d 2c 70 61 6c 70  |ectTable",m,palp|
00000f70  74 72 25 2c 2d 31 2c 2d  31 2c 70 69 78 74 72 61  |tr%,-1,-1,pixtra|
00000f80  6e 73 25 0a 45 4e 44 49  46 0a 73 70 78 25 3d 2d  |ns%.ENDIF.spx%=-|
00000f90  31 3a 46 4f 52 51 25 3d  30 54 4f 32 35 35 3a 49  |1:FORQ%=0TO255:I|
00000fa0  46 70 69 78 74 72 61 6e  73 25 3f 51 25 3c 3e 51  |Fpixtrans%?Q%<>Q|
00000fb0  25 20 73 70 78 25 3d 70  69 78 74 72 61 6e 73 25  |% spx%=pixtrans%|
00000fc0  0a 4e 45 58 54 0a 0a 73  70 78 25 20 69 73 20 65  |.NEXT..spx% is e|
00000fd0  69 74 68 65 72 20 2d 31  20 28 69 66 20 6e 6f 20  |ither -1 (if no |
00000fe0  74 72 61 6e 73 6c 61 74  69 6f 6e 20 6e 65 65 64  |translation need|
00000ff0  73 20 74 6f 20 62 65 20  64 6f 6e 65 20 2d 20 74  |s to be done - t|
00001000  68 69 73 20 73 70 65 65  64 73 20 75 70 0a 4f 53  |his speeds up.OS|
00001010  5f 53 70 72 69 74 65 4f  70 20 35 32 20 61 20 6c  |_SpriteOp 52 a l|
00001020  6f 74 21 29 20 6f 72 20  70 69 78 74 72 61 6e 73  |ot!) or pixtrans|
00001030  25 3b 20 69 74 20 69 73  20 70 61 73 73 65 64 20  |%; it is passed |
00001040  74 6f 20 4f 53 5f 53 70  72 69 74 65 4f 70 20 35  |to OS_SpriteOp 5|
00001050  32 20 69 6e 0a 72 65 67  69 73 74 65 72 20 37 2e  |2 in.register 7.|
00001060  0a 0a 43 6f 6e 63 6c 75  73 69 6f 6e 0a 2d 2d 2d  |..Conclusion.---|
00001070  2d 2d 2d 2d 2d 2d 2d 0a  0a 54 68 65 20 61 62 69  |-------..The abi|
00001080  6c 69 74 79 20 74 6f 20  73 74 6f 72 65 2c 20 70  |lity to store, p|
00001090  72 6f 63 65 73 73 20 61  6e 64 20 64 69 73 70 6c  |rocess and displ|
000010a0  61 79 20 32 35 36 20 65  6e 74 72 79 20 70 61 6c  |ay 256 entry pal|
000010b0  65 74 74 65 20 73 70 72  69 74 65 73 0a 72 65 70  |ette sprites.rep|
000010c0  72 65 73 65 6e 74 73 20  61 20 73 6d 61 6c 6c 20  |resents a small |
000010d0  62 75 74 20 75 73 65 66  75 6c 20 67 61 69 6e 20  |but useful gain |
000010e0  66 6f 72 20 74 68 65 20  52 49 53 43 20 4f 53 20  |for the RISC OS |
000010f0  64 65 73 6b 74 6f 70 2e  20 43 6f 6d 6d 6f 6e 20  |desktop. Common |
00001100  66 6f 72 6d 61 74 73 0a  63 61 6e 20 62 65 20 63  |formats.can be c|
00001110  6f 6e 76 65 72 74 65 64  20 74 6f 20 73 70 72 69  |onverted to spri|
00001120  74 65 73 20 77 69 74 68  6f 75 74 20 61 6e 79 20  |tes without any |
00001130  6c 6f 73 73 20 6f 66 20  69 6e 66 6f 72 6d 61 74  |loss of informat|
00001140  69 6f 6e 20 61 6e 64 20  6d 65 61 6e 69 6e 67 66  |ion and meaningf|
00001150  75 6c 6c 79 0a 64 69 73  70 6c 61 79 65 64 2e 20  |ully.displayed. |
00001160  28 47 72 65 61 74 65 72  20 66 69 64 65 6c 69 74  |(Greater fidelit|
00001170  79 20 6f 66 20 64 69 73  70 6c 61 79 20 63 61 6e  |y of display can|
00001180  20 62 65 20 68 61 64 20  77 69 74 68 20 21 43 68  | be had with !Ch|
00001190  61 6e 67 65 46 53 49 20  28 77 68 69 63 68 0a 63  |angeFSI (which.c|
000011a0  61 6e 20 72 65 61 64 20  61 6e 64 20 67 65 6e 65  |an read and gene|
000011b0  72 61 74 65 20 32 35 36  20 65 6e 74 72 79 20 70  |rate 256 entry p|
000011c0  61 6c 65 74 74 65 20 73  70 72 69 74 65 73 29 20  |alette sprites) |
000011d0  6f 72 20 21 54 72 61 6e  73 6c 61 74 6f 72 29 0a  |or !Translator).|
000011e0  0a 49 74 20 69 73 20 73  74 69 6c 6c 20 61 20 67  |.It is still a g|
000011f0  6f 6f 64 20 69 64 65 61  20 74 6f 20 75 73 65 20  |ood idea to use |
00001200  74 68 65 20 64 65 66 61  75 6c 74 20 64 65 73 6b  |the default desk|
00001210  74 6f 70 20 70 61 6c 65  74 74 65 20 77 68 65 6e  |top palette when|
00001220  65 76 65 72 20 70 6f 73  73 69 62 6c ff ff ff     |ever possibl...|
0000122f