Date : Mon, 22 Nov 2010 16:07:06 +0000
From : jgh@... (J.G.Harston)
Subject: Extracting / Encoding sprites
James McGill wrote:
> Does anyone know of a clever way of extracting sprites from a ROM?
It all depends on how the code in the ROM has decided to encode them.
There are three standard methods of encoding a two-colour sprites:
four 8x8pix characters TL,TR,BL,BR or TL,BL,TR,BR:
byte 0 byte 8 or byte 0 byte 16
.. .. .. ..
byte 7 byte 15 byte 7 byte 23
byte 16 byte 24 byte 8 byte 24
.. .. .. ..
byte 23 byte 31 byte 15 byte 31
32 16pix pixel rows top to bottom:
byte 0 byte 1 or byte 1 byte 0
... ... ... ...
byte 14 byte 15 byte 15 byte 14
byte 16 byte 17 byte 17 byte 16
.. .. .. ...
byte 30 byte 31 byte 31 byte 30
Type 1 is used by AMX Desktop, type 4 is used by Jet Set Willy.
DefIcon here: http://mdfs.net/Apps/Font can display all of them,
you could try loading bits of the ROM image in and stepping through
the icon types to see if anything looks recognisable. I tend to use
code of the following for 2-colour sprites:
FOR A%=0 TO 3
VDU 23,128+A%
FOR B%=0 TO 7:VDU sprite%?(B%+8*A%)
NEXT:NEXT
VDU 128,129,8,8,10,130,131,11
4-colour and 16-colour sprites on the BBC tend to be encoded in the
same way as the screen layout to make writing to the screen memory
simple. The GXR sprites are encoded like this.
A 16-colour (MODE 2) 16x16px sprite would be encoded as:
byte 0 byte 8 byte 16 byte 24 byte 32 byte 40 byte 48 byte 56
.. .. .. .. .. .. .. ..
byte 7 byte 15 byte 23 byte 31 byte 39 byte 47 byte 55 byte 63
byte 64 byte 72 byte 80 byte 88 byte 96 byte 104 byte 112 byte 120
.. .. .. .. .. .. .. ..
byte 71 byte 79 byte 87 byte 95 byte 103 byte 111 byte 119 byte 127
Each byte containing: :l3:r3:l2:r2:l1:r1:l0:r0:
Where l3:l2:l1:l0 is the colour of the lefthand pixel, and
r3:r2:r1:r0 is the colour of the righthand pixel.
The following BASIC code will copy such a sprite to (nonshadow) screen:
sprite%=&2000 :REM Location of sprite
screen%=&3000 :REM Destination in screen
FOR A%=0 TO 63 STEP 4:screen%!A%=sprite%!A%:NEXT
FOR A%=0 TO 63 STEP 4:screen%!(A%+640)=sprite%!(A%+64):NEXT
Just to round it off, 4-colour (MODE 1) sprites would be encoded as:
byte 0 byte 8 byte 16 byte 24
.. .. .. ..
byte 7 byte 15 byte 23 byte 31
byte 32 byte 40 byte 48 byte 56
.. .. .. ..
byte 39 byte 47 byte 55 byte 64
Each byte containing: :a1:b1:c1:d1:a0:b0:c0:d0:
Where a1:a0, b1:b0, c1:c0, d1:d0 are the colours of the pixels, left
to right.
The following BASIC code will copy such a sprite to (nonshadow) screen:
sprite%=&2000 :REM Location of sprite
screen%=&3000 :REM Destination in screen
FOR A%=0 TO 31 STEP 4:screen%!A%=sprite%!A%:NEXT
FOR A%=0 TO 31 STEP 4:screen%!(A%+640)=sprite%!(A%+32):NEXT
--
J.G.Harston - jgh@...