I felt like making a thread covering stripe image format, since I believe none have been made before that explained it completely.
First of all:
This is a pretty useful Wiki page explaining it.
But just to try to make it simpler, I wanted to make a tutorial, so there. OK, let's get to the point.
1. What is stripe image format?
Basically all it is, are tiles on the screen loaded on layers 1-4, in SMW those very tiles are 8x8 and they can be loaded on layers 1-3.
Stripe image is found in other games too, such as Super Mario All-Stars. It's basically a tile-uploading technique, accessed with DMA.
2. Then, how does it work?
Stripe image tiles should be put in a table. One image made out of this format can consist out of many seperate 'lines', 'stripes'. Such a line basically consists out of two things:
1. A header
2. The tile data
The header is always 4 bytes, the tile data can vary.
Taken from the Wiki:
As mentioned earlier, the header consists out of 4 bytes.
Byte 1:
E bit:
The 7th bit of this byte is the end of data bit. If this bit is set, the tile upload stops right there, so nothing after it will be uploaded anymore (in the stripe image routine, it returns when this bit is set).
Almost always, to specify that the end of data bit is set, value #$FF is used.
#$FF is an easy-to-recognize value and therefore, it's often used, even though any value between #$80 and #$FF should work.
So if you end a table, do not forget the #$FF behind it!
HHH bits:
This seems to determine on which layer the image is being uploaded.
If bit 5 is set and bits 4 and 6 are clear, tiles are uploaded on layer 1.
If bit bits 4 and 5 are set and bit 6 is clear, tiles are uploaded on layer 2.
If bits 4 and 6 are set and bit 5 is clear, tiles are uploaded on layer 3.
Y bit:
High bit of Y location of tiles being uploaded.
If it's set, the tile is loaded 256 pixels (1 screen) lower.
X bit:
High bit of X location of tiles being uploaded.
If it's set, the tile is loaded 256 pixels (1 screen) to the right.
yy:
Y location of tile, first two low bits.
Byte 2:
yyy:
Y location, other three low bits.
xxxxx:
X location, low bits. Mind that a line can contain 1F 8x8 tiles horizontally ; that's why there are 5 low bits.
Byte 3:
D:
Which direction the bytes should be uploaded to ; horizontal or vertical.
If this D bit is clear, tiles are uploaded like this:
If it's set:
Note: Horizontally, it goes to the right, and vertically, it sinks down. It cannot go left, or rise up.
Mind that the X and Y position system still works the same when you use vertical direction, however, the X bits will now become Y bits and the Y bits will become X bits.
R:
RLE bit. If it's set, this repeats the tiles an X number of times, determined by the Length bits. A line should look like this then:
This is basically a byte-saver. You're never forced to use it, but it comes in handy sometimes.
llllll:
Length of data bits (these are often unused). See byte 4 for more detail.
They form the upper bits of the bits used in byte 4, so that one can upload data for 100 (hex) bytes or more, in one single line.
Byte 4:
LLLLLLLL:
Length of data bits. The whole fourth byte is made of these bits. So, how does this work?
Each 8x8 tile needs 2 bytes of data, as can be seen under 'Tile data'.
Byte 4 basically tells the game what size the tile data is, so the correct amount of tiles can be uploaded.
If this byte doesn't match with the size of the tile data, there's a 99% chance some tiles will either not be uploaded, or, worse and much more common, everything glitches up.
So how do you know what this byte should contain?
Well, perhaps there are tricks to come around this with a good assembler, but basically you have to count how many bytes the tiles you want to upload take up. Then you subtract that by one, because:
Fourth byte of the header = size of tile data in bytes, - 1.
A good code would be this:
Bad code:
Make sure they match!
This should be pretty simple. Each tile consists out of two bytes ; the tile-to-use byte, and the properties byte.
Byte 1:
Specifies which 8x8 graphic to use for the tile. Often it's easier to view if the GFX are uncompressed. When hacking SMW, AllGFX.bin is often a good choice for this. Note : Does not specify the graphics page, this is what the properties byte does.
Byte 2:
The properties byte. For any game this is in YXPCCCTT format.
Y:
Flipping the tile vertically wise.
X:
Flipping the tile horizontally wise.
P:
Priority bit. If set, it might go in front of more layers and/or sprites, than it did before. Layers only have one, as opposed to sprites.
CCC:
Palette to use.
For SMW, layers 1 and 2 can only uses palettes 0-7, 16 colours per palette.
Layer 3 is a story on its own: It also uses 8 palettes, but these have only 4 colours each. It shares palettes 0 and 1 with layers 1 and 2.
If CCC is:
The same goes for layer 3, but mind that you don't add 16 colours up per palette, but only 4. So palette 1 for layer 3 would be colours 4-7 from palette 0. Also note that for each palette, the first colour is always transparent. Yes, for layer 3 too.
TT:
Graphic page to use. Layers have 2 of these bits, as opposed to sprites, which only have 1, which means layers could use many GFX at the same time. However, SMW leaves bit 1 (the upper T bit) unused :[.
This could be called the high bit of the graphic-to-use-for-the-tile bits, located in the first byte of the tile data.
Okay, so we covered that up.
More examples
Here's a handful of example codes that are valid.
One simple line:
Two lines:
Using RLE:
--------> Don't follow "Find Roy's Dignity", my hack. Because it's pretty outdated. <--------
First of all:
This is a pretty useful Wiki page explaining it.
But just to try to make it simpler, I wanted to make a tutorial, so there. OK, let's get to the point.
1. What is stripe image format?
Basically all it is, are tiles on the screen loaded on layers 1-4, in SMW those very tiles are 8x8 and they can be loaded on layers 1-3.
Stripe image is found in other games too, such as Super Mario All-Stars. It's basically a tile-uploading technique, accessed with DMA.
2. Then, how does it work?
Stripe image tiles should be put in a table. One image made out of this format can consist out of many seperate 'lines', 'stripes'. Such a line basically consists out of two things:
1. A header
2. The tile data
The header is always 4 bytes, the tile data can vary.
Header.
Taken from the Wiki:
Quote
|Byte 1| |Byte 2| |Byte 3| |Byte 4|
EHHHYXyy yyyxxxxx DRllllll LLLLLLLL
E = End of data
HHH = Data destination (VRAM address, see below)
Xxxxxx = X coordinate
Yyyyyy = Y coordinate
D = Direction (0 = Horizontal, 1 = Vertical)
R = RLE (see below)
llllllLLLLLLLL = Length (amount of bytes to upload - 1)
EHHHYXyy yyyxxxxx DRllllll LLLLLLLL
E = End of data
HHH = Data destination (VRAM address, see below)
Xxxxxx = X coordinate
Yyyyyy = Y coordinate
D = Direction (0 = Horizontal, 1 = Vertical)
R = RLE (see below)
llllllLLLLLLLL = Length (amount of bytes to upload - 1)
As mentioned earlier, the header consists out of 4 bytes.
Byte 1:
E bit:
The 7th bit of this byte is the end of data bit. If this bit is set, the tile upload stops right there, so nothing after it will be uploaded anymore (in the stripe image routine, it returns when this bit is set).
Almost always, to specify that the end of data bit is set, value #$FF is used.
#$FF is an easy-to-recognize value and therefore, it's often used, even though any value between #$80 and #$FF should work.
So if you end a table, do not forget the #$FF behind it!
HHH bits:
This seems to determine on which layer the image is being uploaded.
If bit 5 is set and bits 4 and 6 are clear, tiles are uploaded on layer 1.
If bit bits 4 and 5 are set and bit 6 is clear, tiles are uploaded on layer 2.
If bits 4 and 6 are set and bit 5 is clear, tiles are uploaded on layer 3.
Y bit:
High bit of Y location of tiles being uploaded.
If it's set, the tile is loaded 256 pixels (1 screen) lower.
X bit:
High bit of X location of tiles being uploaded.
If it's set, the tile is loaded 256 pixels (1 screen) to the right.
yy:
Y location of tile, first two low bits.
Byte 2:
yyy:
Y location, other three low bits.
xxxxx:
X location, low bits. Mind that a line can contain 1F 8x8 tiles horizontally ; that's why there are 5 low bits.
Byte 3:
D:
Which direction the bytes should be uploaded to ; horizontal or vertical.
If this D bit is clear, tiles are uploaded like this:
Quote
[t][t]
If it's set:
Quote
[t]
[t]
[t]
Note: Horizontally, it goes to the right, and vertically, it sinks down. It cannot go left, or rise up.
Mind that the X and Y position system still works the same when you use vertical direction, however, the X bits will now become Y bits and the Y bits will become X bits.
R:
RLE bit. If it's set, this repeats the tiles an X number of times, determined by the Length bits. A line should look like this then:
Quote
db $58,$20,$40,$06 ; Header of line, three tiles are uploaded.
db $A0,$15 ; However, since RLE is set, you only need to specify one tile. This tile will be uploaded three times.
db $A0,$15 ; However, since RLE is set, you only need to specify one tile. This tile will be uploaded three times.
This is basically a byte-saver. You're never forced to use it, but it comes in handy sometimes.
llllll:
Length of data bits (these are often unused). See byte 4 for more detail.
They form the upper bits of the bits used in byte 4, so that one can upload data for 100 (hex) bytes or more, in one single line.
Byte 4:
LLLLLLLL:
Length of data bits. The whole fourth byte is made of these bits. So, how does this work?
Each 8x8 tile needs 2 bytes of data, as can be seen under 'Tile data'.
Byte 4 basically tells the game what size the tile data is, so the correct amount of tiles can be uploaded.
If this byte doesn't match with the size of the tile data, there's a 99% chance some tiles will either not be uploaded, or, worse and much more common, everything glitches up.
So how do you know what this byte should contain?
Well, perhaps there are tricks to come around this with a good assembler, but basically you have to count how many bytes the tiles you want to upload take up. Then you subtract that by one, because:
Fourth byte of the header = size of tile data in bytes, - 1.
The -1 does not apply for RLE.
A good code would be this:
Quote
db $58,$20,$00,$03
db $50,$14
db $50,$54
db $50,$14
db $50,$54
Bad code:
Quote
db $58,$20,$00,$01
db $50,$14
db $50,$54
db $50,$14
db $50,$54
Make sure they match!
Tile data:
This should be pretty simple. Each tile consists out of two bytes ; the tile-to-use byte, and the properties byte.
Byte 1:
Specifies which 8x8 graphic to use for the tile. Often it's easier to view if the GFX are uncompressed. When hacking SMW, AllGFX.bin is often a good choice for this. Note : Does not specify the graphics page, this is what the properties byte does.
Byte 2:
The properties byte. For any game this is in YXPCCCTT format.
NOTE: DO NOT CONFUSE WITH YXPPCCCT!! This is used for sprites, not layers.
Y:
Flipping the tile vertically wise.
X:
Flipping the tile horizontally wise.
P:
Priority bit. If set, it might go in front of more layers and/or sprites, than it did before. Layers only have one, as opposed to sprites.
CCC:
Palette to use.
For SMW, layers 1 and 2 can only uses palettes 0-7, 16 colours per palette.
Layer 3 is a story on its own: It also uses 8 palettes, but these have only 4 colours each. It shares palettes 0 and 1 with layers 1 and 2.
If CCC is:
Quote
000 = Palette 0
001 = Palette 1
010 = Palette 2
011 = Palette 3
100 = Palette 4
101 = Palette 5
110 = Palette 6
111 = Palette 7
001 = Palette 1
010 = Palette 2
011 = Palette 3
100 = Palette 4
101 = Palette 5
110 = Palette 6
111 = Palette 7
The same goes for layer 3, but mind that you don't add 16 colours up per palette, but only 4. So palette 1 for layer 3 would be colours 4-7 from palette 0. Also note that for each palette, the first colour is always transparent. Yes, for layer 3 too.
TT:
Graphic page to use. Layers have 2 of these bits, as opposed to sprites, which only have 1, which means layers could use many GFX at the same time. However, SMW leaves bit 1 (the upper T bit) unused :[.
This could be called the high bit of the graphic-to-use-for-the-tile bits, located in the first byte of the tile data.
Okay, so we covered that up.
More examples
Here's a handful of example codes that are valid.
One simple line:
Quote
db $53,$A0,$00,$03 ; Layer 3, no RLE, 2 tiles.
db $A0,$04 ; Tile A0, palette 1 (layer 3, so colours 4-7, palette 0)
db $A0,$44 ; Tile A0, palette 1, X-flipped (layer 3, so colours 4-7, palette 0)
db $FF ; End table.
db $A0,$04 ; Tile A0, palette 1 (layer 3, so colours 4-7, palette 0)
db $A0,$44 ; Tile A0, palette 1, X-flipped (layer 3, so colours 4-7, palette 0)
db $FF ; End table.
Two lines:
Quote
db $55,$83,$00,$07 ; Layer 3, no RLE, 4 tiles
db $B8,$18 ; Tile B8, palette 6
db $B9,$18 ; Tile B9, palette 6
db $B9,$58 ; Tile B9, palette 6, X flip
db $B8,$58 ; Tile B8, palette 6, X flip
db $55,$A3,$00,$07 ; Layer 3, no RLE, 4 tiles (one line lower than before)
db $B8,$98 ; Tile B8, palette 6, Y flip
db $B9,$98 ; Tile B9, palette 6, Y flip
db $B9,$D8 ; Tile B9, palette 6, X and Y flip
db $B8,$D8 ; Tile B8, palette 6, X and Y flip
db $FF
db $B8,$18 ; Tile B8, palette 6
db $B9,$18 ; Tile B9, palette 6
db $B9,$58 ; Tile B9, palette 6, X flip
db $B8,$58 ; Tile B8, palette 6, X flip
db $55,$A3,$00,$07 ; Layer 3, no RLE, 4 tiles (one line lower than before)
db $B8,$98 ; Tile B8, palette 6, Y flip
db $B9,$98 ; Tile B9, palette 6, Y flip
db $B9,$D8 ; Tile B9, palette 6, X and Y flip
db $B8,$D8 ; Tile B8, palette 6, X and Y flip
db $FF
Using RLE:
Quote
db $58,$20,$40,$08 ; Layer 3, RLE, 4 tiles
db $30,$10 ; Tile 30, palette 4. Repeat 4 times because of RLE.
db $FF
db $30,$10 ; Tile 30, palette 4. Repeat 4 times because of RLE.
db $FF
--------> Don't follow "Find Roy's Dignity", my hack. Because it's pretty outdated. <--------