Sprite graphics format: Difference between revisions

From NeoGeo Development Wiki
Jump to navigation Jump to search
mNo edit summary
mNo edit summary
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
[[File:spritegfx.png|center]]
[[File:spritegfx2.png|center]]


The 16x16, 4bpp pixels sprite tiles are divided in 4 8x8 blocks. Each row of these 8x8 blocks are stored backwards in a 4bit planar organization.
The NeoGeo uses 16x16 pixels, 4bpp tiles for sprites.


*On cart systems, bitplanes 0 and 1 go in the odd [[C ROM]]s (C1, C3...), while bitplanes 2 and 3 go in the even ones (C2, C4...).
They are stored as 4, 8x8 pixels blocks. Each row of these 8x8 blocks is stored '''backwards''' in a 4bit planar organization.
*On CD systems, bitplanes follow a 1/0/3/2 pattern.
 
* On cartridge systems, bitplanes 0 and 1 go in the odd [[C ROM]]s (C1, C3...), while bitplanes 2 and 3 go in the even ones (C2, C4...).
* On [[CD systems]], bitplanes follow a 1/0/3/2 order.
 
=Size=
 
One tile is 16 * 16 pixels * 4 bits per pixel = 1024 bits = '''128 bytes'''.
 
=Addressing=
 
<pre>
Bit # ...543210
      ...nCLLLL
 
n: Tile number (multiple bits)
C: Block column, 0 = blocks 1 & 2, 1 = blocks 3 & 4
L: Block line # (0~15)
</pre>
 
{{Sig|CA4|CA4}} is "C".


="Consolegfx"-style definition=
="Consolegfx"-style definition=


* Color indexes per tile: 0~15
Each group represents one byte.
* Space used: 4 bits per pixel. 128 bytes for each tile.


This is a tiled, planar bitmap format. Each pair represents one byte.
* '''t''' is the 8x8 block number (1 to 4) as shown above.
* '''r''' is the row number in the block (0 to 7).
* '''bp''' is the bitplane number (0 to 3).


==C1/3/5/7==
==Odd C ROMs==
<pre>
<pre>
   [t1, r0, bp0], [t1, r0, bp1], [t1, r1, bp0], [t1, r1, bp1],
   [t1, r0, bp0], [t1, r0, bp1], [t1, r1, bp0], [t1, r1, bp1],
Line 36: Line 56:
</pre>
</pre>


==C2/4/6/8==
==Even C ROMs==
<pre>
<pre>
   [t1, r0, bp2], [t1, r0, bp3], [t1, r1, bp2], [t1, r1, bp3],
   [t1, r0, bp2], [t1, r0, bp3], [t1, r1, bp2], [t1, r1, bp3],
Line 63: Line 83:
Pseudocode:
Pseudocode:
<pre>
<pre>
    For Tileline = 0 To (Width\16)-1
for block = 0 to 3 {
        For Tilerow = 0 To (Height\16)-1
    select block {
            For Quarter = 0 To 3
        case 0: xOfs = 8: yOfs = 0
                Select Case Quarter
        case 1: xOfs = 8: yOfs = 8
                    Case 0: xOfs = 8: yOfs = 0
        case 2: xOfs = 0: yOfs = 0
                    Case 1: xOfs = 8: yOfs = 8
        case 3: xOfs = 0: yOfs = 8
                    Case 2: xOfs = 0: yOfs = 0
    }
                    Case 3: xOfs = 0: yOfs = 8
    for row = 0 to 7 {
                End Select
        BitPlane(0) = ReadByte(1)
                For QuarterLine = 0 To 7
        BitPlane(1) = ReadByte(1)
                    BitPlane(0) = ReadByte(1)
        BitPlane(2) = ReadByte(2)
                    BitPlane(1) = ReadByte(1)
        BitPlane(3) = ReadByte(2)
                    BitPlane(2) = ReadByte(2)
        for pixels = 0 to 7 {
                    BitPlane(3) = ReadByte(2)
            xPos = pixels + xOfs
                    For Pixels = 0 To 7
            yPos = row + yOfs
                        xPos = (Tilerow * 16) + Pixels + xOfs
            ColorIndex = 0
                        yPos = (Tileline * 16) + QuarterLine + yOfs
            for bitplanes = 0 to 3
                        for Bitplanes = 0 to 3
                ColorIndex .= GetBit(BitPlane(3 - bitplanes)), 7 - pixels)
                            ColorIndex .= GetBit(Bin(BitPlane(3-Bitplanes)),7-Pixels)
            PixelSet (xPos, yPos), Palette[ColorIndex]
                        next Bitplanes
         }
                        PixelSet (xPos, yPos), Palette[BinToDec(ColorIndex)]
     }
                    Next Pixels
}
                Next QuarterLine
            Next Quarter
         Next Tilerow
     Next Tileline
</pre>
</pre>



Latest revision as of 06:24, 10 July 2024

The NeoGeo uses 16x16 pixels, 4bpp tiles for sprites.

They are stored as 4, 8x8 pixels blocks. Each row of these 8x8 blocks is stored backwards in a 4bit planar organization.

  • On cartridge systems, bitplanes 0 and 1 go in the odd C ROMs (C1, C3...), while bitplanes 2 and 3 go in the even ones (C2, C4...).
  • On CD systems, bitplanes follow a 1/0/3/2 order.

Size

One tile is 16 * 16 pixels * 4 bits per pixel = 1024 bits = 128 bytes.

Addressing

Bit # ...543210
      ...nCLLLL

n: Tile number (multiple bits)
C: Block column, 0 = blocks 1 & 2, 1 = blocks 3 & 4
L: Block line # (0~15)

CA4 is "C".

"Consolegfx"-style definition

Each group represents one byte.

  • t is the 8x8 block number (1 to 4) as shown above.
  • r is the row number in the block (0 to 7).
  • bp is the bitplane number (0 to 3).

Odd C ROMs

  [t1, r0, bp0], [t1, r0, bp1], [t1, r1, bp0], [t1, r1, bp1],
  [t1, r2, bp0], [t1, r2, bp1], [t1, r3, bp0], [t1, r3, bp1],
  [t1, r4, bp0], [t1, r4, bp1], [t1, r5, bp0], [t1, r5, bp1],
  [t1, r6, bp0], [t1, r6, bp1], [t1, r7, bp0], [t1, r7, bp1],

  [t2, r0, bp0], [t2, r0, bp1], [t2, r1, bp0], [t2, r1, bp1],
  [t2, r2, bp0], [t2, r2, bp1], [t2, r3, bp0], [t2, r3, bp1],
  [t2, r4, bp0], [t2, r4, bp1], [t2, r5, bp0], [t2, r5, bp1],
  [t2, r6, bp0], [t2, r6, bp1], [t2, r7, bp0], [t2, r7, bp1]

  [t3, r0, bp0], [t3, r0, bp1], [t3, r1, bp0], [t3, r1, bp1],
  [t3, r2, bp0], [t3, r2, bp1], [t3, r3, bp0], [t3, r3, bp1],
  [t3, r4, bp0], [t3, r4, bp1], [t3, r5, bp0], [t3, r5, bp1],
  [t3, r6, bp0], [t3, r6, bp1], [t3, r7, bp0], [t3, r7, bp1]

  [t4, r0, bp0], [t4, r0, bp1], [t4, r1, bp0], [t4, r1, bp1],
  [t4, r2, bp0], [t4, r2, bp1], [t4, r3, bp0], [t4, r3, bp1],
  [t4, r4, bp0], [t4, r4, bp1], [t4, r5, bp0], [t4, r5, bp1],
  [t4, r6, bp0], [t4, r6, bp1], [t4, r7, bp0], [t4, r7, bp1]

Even C ROMs

  [t1, r0, bp2], [t1, r0, bp3], [t1, r1, bp2], [t1, r1, bp3],
  [t1, r2, bp2], [t1, r2, bp3], [t1, r3, bp2], [t1, r3, bp3],
  [t1, r4, bp2], [t1, r4, bp3], [t1, r5, bp2], [t1, r5, bp3],
  [t1, r6, bp2], [t1, r6, bp3], [t1, r7, bp2], [t1, r7, bp3],

  [t2, r0, bp2], [t2, r0, bp3], [t2, r1, bp2], [t2, r1, bp3],
  [t2, r2, bp2], [t2, r2, bp3], [t2, r3, bp2], [t2, r3, bp3],
  [t2, r4, bp2], [t2, r4, bp3], [t2, r5, bp2], [t2, r5, bp3],
  [t2, r6, bp2], [t2, r6, bp3], [t2, r7, bp2], [t2, r7, bp3]

  [t3, r0, bp2], [t3, r0, bp3], [t3, r1, bp2], [t3, r1, bp3],
  [t3, r2, bp2], [t3, r2, bp3], [t3, r3, bp2], [t3, r3, bp3],
  [t3, r4, bp2], [t3, r4, bp3], [t3, r5, bp2], [t3, r5, bp3],
  [t3, r6, bp2], [t3, r6, bp3], [t3, r7, bp2], [t3, r7, bp3]

  [t4, r0, bp2], [t4, r0, bp3], [t4, r1, bp2], [t4, r1, bp3],
  [t4, r2, bp2], [t4, r2, bp3], [t4, r3, bp2], [t4, r3, bp3],
  [t4, r4, bp2], [t4, r4, bp3], [t4, r5, bp2], [t4, r5, bp3],
  [t4, r6, bp2], [t4, r6, bp3], [t4, r7, bp2], [t4, r7, bp3]

Decoding

Pseudocode:

for block = 0 to 3 {
    select block {
        case 0: xOfs = 8: yOfs = 0
        case 1: xOfs = 8: yOfs = 8
        case 2: xOfs = 0: yOfs = 0
        case 3: xOfs = 0: yOfs = 8
    }
    for row = 0 to 7 {
        BitPlane(0) = ReadByte(1)
        BitPlane(1) = ReadByte(1)
        BitPlane(2) = ReadByte(2)
        BitPlane(3) = ReadByte(2)
        for pixels = 0 to 7 {
            xPos = pixels + xOfs
            yPos = row + yOfs
            ColorIndex = 0
            for bitplanes = 0 to 3
                ColorIndex .= GetBit(BitPlane(3 - bitplanes)), 7 - pixels)
            PixelSet (xPos, yPos), Palette[ColorIndex]
        }
    }
}

Coding