SGA: Difference between revisions

From MultimediaWiki
Jump to navigation Jump to search
(some basic file format details)
No edit summary
Line 2: Line 2:
* Samples: [http://samples.mplayerhq.hu/game-formats/segacd/sga/ http://samples.mplayerhq.hu/game-formats/segacd/sga/]
* Samples: [http://samples.mplayerhq.hu/game-formats/segacd/sga/ http://samples.mplayerhq.hu/game-formats/segacd/sga/]


SGA is a rather common file format for games on the Sega CD console system. Little is known about the file format. It is likely to be some sort of vector quantizer due to the limited graphics capability of the Sega CD system.
SGA is a rather common file format for games on the Sega CD console system. Early version used uncompressed frames, newer version use a simple LZ compression scheme, whilst that last 32x version uses a yet to be determined compression method.


== File Format ==
== File Format ==
All multi-byte numbers in a SGA file are big endian.
All multi-byte numbers in a SGA file are big endian.  
Due to using CD storage each chunk is stored using 2048 byte sectors.
The data payload is the first 2046 bytes, with the last 2 being an integer specifying how much of the chunk is left. One item to be aware of is if the value is zero then to skip the next sector and check the next one. (I'm presuming this has something to do with padding the CD for faster loading?)


A SGA file is a headerless format that is comprised of a series of chunks. Each chunk can contain video or audio. The chunk layout is defined as:
A SGA doesnt contain a global header, but has headers for each chunk. Each chunk can contain video or audio.  
Chunk Header is 12-bytes


  byte 0    chunk type
  byte 0    chunk type
  byte 1    unknown
  byte 1    unknown (always 0)
  bytes 2-3  payload length
  bytes 2-3  payload length  
  bytes 4-5 unknown
  bytes 4-7 unknown (time indicator)
  bytes 6..  chunk payload
byte 8    column start (can be ignored since we are not drawing on a 320x224 screen)
byte 9    row start (again can be ignored)
byte 10    column size
byte 11    row size
  bytes 12..  chunk payload


Bytes 4-5 are presumed to be part of the chunk preamble since the payload length specifies the length of the chunk, minus 6 bytes.
Bytes 4-5 are presumed to be part of the chunk preamble since the payload length specifies the length of the chunk.


== Chunk Types ==
== Chunk Types ==
Some observed chunk types are:
Some observed chunk types are:


* 0x81: compressed video (night trap 32x uses this)
* 0xC1: uncompressed video (used in night trap)
* 0xC6: compressed video
* 0xCD: video, perhaps followed by audio
* 0xCD: video, perhaps followed by audio
* 0xCB: video, perhaps in files that are video only
* 0xCB: video, perhaps in files that are video only
* 0xA1: audio, sign/magnitude 8-bit PCM, apparently with a few header bytes in advance
* 0xA1: audio, sign/magnitude 8-bit PCM
 
== Uncompressed Video 0xC6 ==
Genesis Video uses 4-bit(16 color) pixels and upto 4 palettes
 
Video is made up of tiles. (column * 4 * row * 8) (each byte has 2 pixels)
Then palette data follows (if there is only 24 bytes then only one palette is used, otherwise there is 4 palettes)
A palette map follows for videos that use 4 palettes.
 
== Palette Data ==
Palettes are stored in an unusual format. As the genesis normally uses either an rgb or bgr stored in nibbles (even though only the top 3 bits are used).
 
bitmap={1,2,4}
 
For bit=0 to 2
    for color=0 to 15
        red[color]+=Top Most Bit of Data *bitmap[bit]
    next
next
 
Repeat for green and blue.
 
== Palette Map ==
Reading 2 bits for each tile, determines which of the 4 palettes to use.
 
For Row=0 to RowMax
    For Col=0 to ColMax
        PalMap[Row*ColMax+Col]=Top 2 Bits of data
    Next
Next
 
When Drawing the Tile you would select the palette based upon Map.       
 
== Compressed Video 0xC6 ==


== Games Using SGA ==
== Games Using SGA ==

Revision as of 19:52, 27 August 2007

SGA is a rather common file format for games on the Sega CD console system. Early version used uncompressed frames, newer version use a simple LZ compression scheme, whilst that last 32x version uses a yet to be determined compression method.

File Format

All multi-byte numbers in a SGA file are big endian. Due to using CD storage each chunk is stored using 2048 byte sectors. The data payload is the first 2046 bytes, with the last 2 being an integer specifying how much of the chunk is left. One item to be aware of is if the value is zero then to skip the next sector and check the next one. (I'm presuming this has something to do with padding the CD for faster loading?)

A SGA doesnt contain a global header, but has headers for each chunk. Each chunk can contain video or audio. Chunk Header is 12-bytes

byte 0     chunk type
byte 1     unknown (always 0)
bytes 2-3  payload length 
bytes 4-7  unknown (time indicator)
byte 8     column start (can be ignored since we are not drawing on a 320x224 screen) 
byte 9     row start (again can be ignored)
byte 10    column size
byte 11    row size
bytes 12..  chunk payload

Bytes 4-5 are presumed to be part of the chunk preamble since the payload length specifies the length of the chunk.

Chunk Types

Some observed chunk types are:

  • 0x81: compressed video (night trap 32x uses this)
  • 0xC1: uncompressed video (used in night trap)
  • 0xC6: compressed video
  • 0xCD: video, perhaps followed by audio
  • 0xCB: video, perhaps in files that are video only
  • 0xA1: audio, sign/magnitude 8-bit PCM

Uncompressed Video 0xC6

Genesis Video uses 4-bit(16 color) pixels and upto 4 palettes

Video is made up of tiles. (column * 4 * row * 8) (each byte has 2 pixels) Then palette data follows (if there is only 24 bytes then only one palette is used, otherwise there is 4 palettes) A palette map follows for videos that use 4 palettes.

Palette Data

Palettes are stored in an unusual format. As the genesis normally uses either an rgb or bgr stored in nibbles (even though only the top 3 bits are used).

bitmap={1,2,4}

For bit=0 to 2

   for color=0 to 15
       red[color]+=Top Most Bit of Data *bitmap[bit]
   next

next

Repeat for green and blue.

Palette Map

Reading 2 bits for each tile, determines which of the 4 palettes to use.

For Row=0 to RowMax

   For Col=0 to ColMax
       PalMap[Row*ColMax+Col]=Top 2 Bits of data
   Next

Next

When Drawing the Tile you would select the palette based upon Map.

Compressed Video 0xC6

Games Using SGA