Sprite graphics format

From NeoGeo Development Wiki
Revision as of 19:22, 1 January 2016 by Furrtek (talk | contribs)
Jump to navigation Jump to search
File:Spritegfx.png

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.

  • On cart 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 pattern.

"Consolegfx"-style definition

  • Color indexes per tile: 0~15
  • Space used: 4 bits per pixel. 128 bytes for each tile.

This is a tiled, planar bitmap format. Each pair represents one byte.

C1/3/5/7

  [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]

C2/4/6/8

  [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 Tileline = 0 To (Width\16)-1
        For Tilerow = 0 To (Height\16)-1
            For Quarter = 0 To 3
                Select Case Quarter
                    Case 0: xOfs = 8: yOfs = 0
                    Case 1: xOfs = 8: yOfs = 8
                    Case 2: xOfs = 0: yOfs = 0
                    Case 3: xOfs = 0: yOfs = 8
                End Select
                For QuarterLine = 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 = (Tilerow * 16) + Pixels + xOfs
                        yPos = (Tileline * 16) + QuarterLine + yOfs
                        for Bitplanes = 0 to 3
                            ColorIndex .= GetBit(Bin(BitPlane(3-Bitplanes)),7-Pixels)
                        next Bitplanes
                        PixelSet (xPos, yPos), Palette[BinToDec(ColorIndex)]
                    Next Pixels
                Next QuarterLine
            Next Quarter
        Next Tilerow
    Next Tileline

Coding