Difference between revisions of "SMPS/Headers"

From Sega Retro

m (Black Squirrel moved page SCHG:SMPS Hacking/Variants and Headers to SCHG:SMPS/Headers without leaving a redirect)
m (Black Squirrel moved page SCHG:SMPS/Headers to SMPS/Headers without leaving a redirect)
(No difference)

Revision as of 13:36, 23 January 2019

Template:SMPSHackingNav

Cleanup.svg
This article needs cleanup.
This article needs to be edited to conform to a higher standard of article quality. After the article has been cleaned up, you may remove this message. For help, see the How to Edit a Page article.

Further information: this needs merging with SMPS, although the technical details may need sub-pages.

Because SMPS is a multiplatform format and each platform has a different sound setup, each format has a header which, while sharing a common setup, have different usage for different fields. Furthermore, the different formats are handled by different types of CPUs, so the semantics of pointers — locations in the song — are different. This page explains them all; after these, differences between versions are noted on the other pages.

Mega Drive SMPS

SMPS on the Sega Mega Drive allows use of the system's two sound chips, the YM2612 and the SN76489 (also called the PSG). SMPS almost fully supports the YM2612, allowing the songwriter to use as many FM synthesis channels (the chip has six), as well as allowing him to trade one channel away for DAC sample playback. However, SMPS's support for the SN76489 is slightly restricted: the songwriter can either use up to three square wave tone channels or up to two square wave tone channels and a noise channel.

SMPS on the Sega Mega Drive is not a singular technology, as nearly every game has made modifications to the format ranging from slight data layout changes (this is almost guaranteed for DAC samples) to complete changes in coordination flags. However, each of these variants fall under two categories: SMPS-68000 and SMPS-Z80, depending on which of the Mega Drive's CPUs most of the sound driver runs on.

All the formats (except SMPS-Ristar below) share a common header format:

Offset Size Description
$00 Word FM voice array pointer. This points to a list of all the FM voices in the song; PSG voices and DAC samples (if any) are hardcoded in the sound driver.
$02 Byte Number of FM channels.
$03 Byte Number of PSG channels.
$04 Word Tempo modifier. First byte is the dividing timing, and the second is the main tempo modifier. Change the second byte to make the music faster or slower, and change the first byte to determine the range of tempo values you can achieve. The higher the divider, the slower the tempo can be.
$06 Variable*8 bytes Entries for all FM channels, then entries for all PSG channels. Each entry is 4 bytes long.
FM Channel Entry
$00 Word Pointer to FM channel n's song data. For the first FM channel (offset $06), if the word following this (offset $08) is zero, this channel is to be used as DAC sample playback.
$02 Byte If not DAC (see above), is the initial channel n key displacement (signed).
$03 Byte If not DAC (see above), sets the initial volume of FM channel n. 0 is maximum volume, with incrementing volumes going down.
PSG Channel Entry
$00 Word Pointer to PSG channel n's song data.
$02 Byte Unknown, possibly unused.
$03 Byte PSG channel n initial voice number.

SMPS-68000

The 68000 performs all sound processing except DAC sample playback, which is relegated to the Z80 with a specialized playback engine. All pointers in SMPS are signed big-endian words relative to a particular offset: for headers, it's the beginning of the song; for coordination flags, it's the address immediately after the coordination flag including parameters, though some games will use offsets from the beginning of the song.

SMPS-Ristar

Ristar has a modified SMPS-68000 engine capable of mixing two DAC samples from the song. Therefore, its header is slightly different and you will have to either pick and choose or build a new channel if you wish to port songs over.

SMPS-Treasure

Treasure-developed games use a modified SMPS-68000 that merely adds a few coordination flags that the songs use, so you will have to watch for these and attempt to simulate their effects (or actually port the code over) when porting.

SMPS-Z80

In SMPS-Z80, the Z80 performs all sound processing parallel to the 68000, which merely issues it commands telling it what to do. All pointers are unsigned little-endian words which are absolute addresses in Z80 memory space. Consequently, most SMPS-Z80 games store music and sound effects in ROM banks, switching between ROM banks when needing to get to different data. Sonic the Hedgehog 2 and Mega Man: The Wily Wars, however, have the 68000 copy song data to a location in Z80 RAM ($1380 and $1002, respectively) and accessed from there; otherwise, they behave identically. It is unknown whether or not other games follow this pattern.

32X SMPS (SMPS-32X)

Most Sega 32X games that use SMPS use one of the Mega Drive variants and have custom engines for 32X-side sound (if any). Knuckles' Chaotix and Tempo, however, use modified SMPS-Z80s that allow the 32X's PWM channels to play up to four simultaneous samples with the songs, relegating mixing to the slave SH-2 (using the 68000 as a communication intermediary, as the Z80 cannot directly communicate with the SH-2s) since the bare PWM hardware only has two stereo channels. In these cases, there is an extra chunk appended to the end of the song header (the rest remains untouched) that gives instructions for setting up the PWM:

Offset from end of normal header Size Description
$00, $04, $08, $0C Word PWM channel n pointer.
$02, $06, $0A, $0E Byte Likely PWM channel n key displacement; just like with FM channels.
$03, $07, $0B, $0F Byte PWM channel n volume modifier; the higher the value, the louder the volume.

Unlike with other channel types, you must specify all four PWM channels.

Master System/Game Gear SMPS

The Sega Master System and Sega Game Gear both have only a SN76489, however unlike with Mega Drive SMPS, the SMS/GG SMPS can use all four of the chip's channels (three square wave channels and one white noise channel). Because the SMS/GG use a Z80, the pointers are the same as with SMPS-Z80: unsigned little-endian addresses into the Z80 memory space, and the systems's banking capabilities are used.

However, there are slight differences between the sound capabilities of the two platforms:

  • The Master System as distributed in Japan also includes a YM2413 which allows for FM channels to be mixed; it is unknown whether or not any Master System games that use SMPS support this.
  • The Game Gear allows individual channels to be panned left or right on the speaker. SMPS on the Game Gear supports this.
Offset Size Description
$00 Word Unknown - pointer to PSG envelope data?
$02 Byte Number of PSG channels. In order to use noise, all four channels must be used, and the fourth channel is noise.
$03 Byte Unknown. If it turns out that no SMPS games use the YM2413, this will definitely be zero.
$04 Word Tempo modifier; same as with Mega Drive SMPS.
$06+(4*n) Word PSG channel n pointer.
$08+(4*n) Byte Unknown, possibly unused.
$09+(4*n) Byte PSG channel n initial voice number.

Sega CD SMPS (SMPS-PCM)

SMPS-PCM is a modification of SMPS-68000 that runs on the Sega CD's 68000. Consequently, it can only access the Sega CD's PCM chip, the RF5C164, which hooks into a global sample bank (for each SMPS program on disc), to play DAC samples at different frequencies, effectively turning it into wavetable synthesis. Like SMPS-68000, the header pointers are relative to the beginning of the file and the coordination flag pointers are relative to the byte after the full coordination flag (including parameters). The header is different:

Offset Size Description
$00 Word 0 - as SMPS grabs sample data from its own bank
$02 Byte Number of PCM channels. Usually 8 or 9 (it is unknown why some songs use 9; however the extra channel will always do nothing).
$03 Byte 0 - only one sound source is used.
$04 Word Tempo modifier; same with other SMPSs.
$06+(4*n) Word PCM channel n pointer
$08+(4*n) Byte Initial PCM channel n key displacement (signed).
$09+(4*n) Byte Unknown (possibly channel pan modifier; L/R outputs have additional individual volumes)

Both music and sound effects can be played with SMPS-PCM, just like with other SMPS variants; however because of the PCM-only limitation, some games, like Sonic CD, will also have a custom driver for accessing the Mega Drive's/32X's sound chips.