Sprite mode words are 32 bit values used to describe the format of the sprite data, i.e. the screen mode the sprite was created in. There are three basic formats supported by different versions of RISC OS:
Mode numbers are the only supported mode word format in versions of RISC OS prior to RISC OS 3.5.
If the mode number is one of an extension mode (i.e. a mode defined by a third-party module) then some operations on the sprite will only perform correctly if that mode (or a very similar one) is present on the host system.
Note that it is illegal to use a mode number between 128 and 255 in a sprite mode word (i.e. a mode number with the shadow bit set).
RISC OS 3.5 extended the mode word format to the following:
wttt tyyy yyyy yyyy yyxx xxxx xxxx xxx1
Field | Contents |
---|---|
w (bit 31) | Wide mask flag |
t (bits 27-30) | Sprite type |
y (bits 14-26) | Vertical DPI |
x (bits 1-13) | Horizontal DPI |
Bit 0 must always contain the value ‘1’.
Note that many OS APIs will only accept a sprite mode word if the horizontal and vertical DPI fields contain DPI values that can be expressed as eigen values; i.e. 180 DPI (eigen value 0), 90 DPI (eigen value 1), 45 DPI (eigen value 2) or 22 or 23 DPI (eigen value 3).
Starting with RISC OS 5.21 a new sprite mode word format is supported, allowing for a much larger number of sprite types, at the cost of less DPI combinations.
w111 1ttt tttt 0000 ffff ffff yyxx 0001
Field | Contents |
---|---|
w (bit 31) | Wide mask flag |
t (bits 20-26) | Sprite type |
f (bits 8-15) | Contains bits 8-15 of the Mode Flags |
y (bits 6-7) | Y eigen value (0=180 DPI, 1=90 DPI, etc.) |
x (bits 4-5) | X eigen value |
Bits 27-30, 16-19 and 0-3 must always contain the fixed pattern &78000001.
The above rules are essentially just an expanded form of the set of rules presented for decoding mode specifiers, as many APIs which accept mode words actually accept all types of mode specifier. However it’s important to remember that pointers to mode selector blocks are not valid sprite mode words, as there is no way the pointer or the block can be saved out to a sprite file. Therefore if you are writing a public API which only accepts sprite mode words, you may want to implement a check for mode selectors and throw an error if one is passed in by accident.
Some APIs may also accept pointers to sprite areas – these can be distinguished from pointers to mode selector blocks by the fact that bit 0 of the first word of a sprite area will always be zero, whereas bit 0 of the first word of a mode selector block will always be one.
Also note that even if it looks like a RISC OS 3.5 or RISC OS 5 sprite mode word, other factors may mean that it’s a completely invalid mode word (e.g. DPI values of zero in a RISC OS 3.5 mode word, or the fixed bits of a RISC OS 5 mode word containing an invalid pattern).
Type | Description | NColour value | ModeFlags value | Log2BPP value |
---|---|---|---|---|
0 | Invalid (used to identify mode numbers) | - | - | - |
1 | 1bpp palletised | 1 | 0 | 0 |
2 | 2bpp palletised | 3 | 0 | 1 |
3 | 4bpp palletised | 15 | 0 | 2 |
4 | 8bpp palletised | 63 | 0 | 3 |
5 | 16bpp 1:5:5:5 TBGR | 65535 | 0 | 4 |
6 | 32bpp 8:8:8:8 TBGR | -1 | 0 | 5 |
7 | 32bpp CMYK | -1 | &1000 | 5 |
8 | 24bpp | 16777215 | 0 | 6 |
9 | JPEG data | - | - | - |
10 | 16bpp 5:6:5 TBGR | 65535 | &80 | 4 |
11-14 | Reserved | - | - | - |
15 | Invalid (used to identify RISC OS 5 sprite mode words) | - | - | - |
Note that for sprite type 4, the values returned by the kernel are for a sprite with a 64 entry palette instead of a full 256 entry palette.
RISC OS 5 sprite mode words support the same list of sprite type numbers as are supported by RISC OS 3.5 sprite mode words. However, instead of using fixed values for bits 8-15 of the mode flags, arbitrary values can be used, introducing a number of extra sub-formats (e.g. sprite type 6 with ARGB pixel format). See Valid Mode Variable Combinations for a summary of formats which are supported by the OS.
The following sprite type numbers are exclusive to RISC OS 5 sprite mode words:
Type | Description | NColour value | Log2BPP value |
---|---|---|---|
16 | 16bpp 4:4:4:4 | 4095 | 4 |
17 | 4:2:0 YCbCr | 420 | 7 |
18 | 4:2:2 YCbCr | 422 | 7 |
19-127 | Reserved | - | - |
On RISC OS 3.5 and above, attempting to use OS_ReadModeVariable to read the details of an unknown or unsupported sprite type will generally result in the kernel acting as if it was given a type 6 (i.e. 32bpp) sprite mode word. By comparing the values returned by the kernel against the expected values for a given mode word, this can be used as a method of determining if the kernel/OS supports that sprite type.
See Format Of Sprite for details of how the sprite mode word affects the format of the sprite mask.