Difference between revisions of "Andlabs/Time Trax"
From Sega Retro
Line 27: | Line 27: | ||
==Song Format== | ==Song Format== | ||
− | *$00 byte - xxxxxxxxxxx; loaded to byte $01 of the in-RAM channel data structure, if $FF, | + | The first thing in each song is a list of n channel headers; their form is: |
+ | *$00 byte - xxxxxxxxxxx; loaded to byte $01 of the in-RAM channel data structure, if $FF, end the list (and thus stop loading the sound, as there is nothing left to do) | ||
+ | *$01 byte - channel number: | ||
+ | **$00..$05 - FM1..FM6 | ||
+ | **$06 - PSG1 | ||
+ | **$07 - PSG2 | ||
==Z80 RAM Channel Data Structure== | ==Z80 RAM Channel Data Structure== |
Revision as of 21:08, 14 July 2013
Contents
There are only two sound banks.
- $F0000 - PCM samples
- $F8000 - music and SFX
everything fits neatly into its bank
Commands
Commands are two bytes each, the first byte being the argument and the second byte being the command itself. There are $20 bytes granted for commands (so up to $10 commands at once), and another byte in RAM used to determine where the command write pointer is. (Another byte stores where it used to be; this is used to tell if we have new commands.)
Commands, where $xx indicates argument:
- $00 - play sound $xx ($00..$05 music, $06..$nn SFX)
- $01 - ??
- $02 - ??
- $03 - ??
- $04 - ??
- $05 - ??
- $06 - ??
Sound Bank
The beginning of this bank consists of the following:
- $0 byte - ???
- $1 big-endian word - bank pointer to list of songs
- ...
The list of songs consists of just a flat list of big-endian bank pointers.
Song Format
The first thing in each song is a list of n channel headers; their form is:
- $00 byte - xxxxxxxxxxx; loaded to byte $01 of the in-RAM channel data structure, if $FF, end the list (and thus stop loading the sound, as there is nothing left to do)
- $01 byte - channel number:
- $00..$05 - FM1..FM6
- $06 - PSG1
- $07 - PSG2
Z80 RAM Channel Data Structure
- $00 byte: xxxxx
- $01 byte: xxxxx; loaded from byte $00 of the song
PCM Sample Bank
The top of this bank contains pointer-length pairs for PCM samples. Pointers are relative to the Z80 memory map (so they are bank pointers). Pointers and lengths are big endian (this is NOT how things usually are done!)
Or in other words
- $0 word - first sample pointer BIG ENDIAN
- $2 word - first sample length BIG ENDIAN
- $4 word - second sample pointer BIG ENDIAN
- $6 word - second sample length BIG ENDIAN
- $8 word - third sample pointer BIG ENDIAN
- $A word - third sample length BIG ENDIAN
and so on until the first PCM data byte
PCM Sample Playback
PCM samples are played back through a buffer: the game reads $80 bytes of sample data, then plays back one byte of ample data every so often. Buffer filling is done all at once and in groups of 8 bytes, with another PCM data write after each group of 8 bytes.
Though the sample buffer is $80 bytes long, the game has two consecutive buffers, switching after one has been played through. Why he doesn't just use one $100-byte-long buffer is beyond me; maybe he wanted it to load to the second buffer while playing back from the first?
pcm-bug
There appears to be a bug in the buffer loading code:
ROM:0B18 ld hl, (PCMSampleLength) ROM:0B1B ld bc, 80h ; 'Ç' ROM:0B1E sbc hl, bc ROM:0B20 jp m, loc_C67 ; stops sample playback ROM:0B23 ld (PCMSampleLength), hl
if I am reading this correctly, the game will stop playing samples if it cannot fill a buffer completely, leaving the tail end of samples unplayed:
00f0000: 8024 166e 9692 048d 9b1f 0a70 a58f 0869 .$.n.......p...i 00f0010: adf8 156f c367 0975 ccdc 0579 d255 2080 ...o.g.u...y.U . 00f0020: f2d5 093b ____ ____ ____ ____ ____ ____ ...;____________
notice how none of those lengths (except one) are aligned