BAM File Format
This is the file format originally used by OHRRPGCE. It is meant to be played back on a OPL2 sound chip, in melodic mode only (percussion mode isn't supported). You can use bamtovgm in order to convert it into VGM format.
The file starts with the ASCII letters "CBMF" and is then followed by a sequence of commands. Note there are 16 channels, although only channel 0 to 8 are usable on a single OPL2 chip; the others will be ignored.
- 0: Stop the song. If the end of file is reached, that also means stop song.
- 1-15: Reserved.
- 16-31: Note on. One byte is a parameter 0 to 127 specifying what MIDI note number to use (the player must convert it into a frequency).
- 32-47: Note off. No parameter.
- 48-63: Define voice. The parameter is 11 bytes long and is stored in SBI format.
- 64-79: Reserved.
- 80-95: Set label. There is no parameter. This label is remembered for future goto commands.
- 96-111: Goto label. This command is ignored if the label is previously undefined, except that label 0 means start of file if not yet defined. If the parameter is 1 to 253 it is repeat count; after that many times the goto is ignored and the repeat count is reset. If the parameter is 254 then it is just a normal goto (an infinite loop). If the parameter is 255 then it is a subroutine call; command 112 returns to the point after this subroutine call.
- 112: Return from subroutine. Subroutines cannot be nested. If not in a subroutine, this command does nothing.
- 113-127: Reserved. However, some files contain command 127 anyways (even though it is not supposed to be allowed); it should be treated as a zero-length delay.
- 128-255: Delay. No parameter. Subtract 127 to figure out delay amount in frames; one frame is 50 milliseconds.
Note that the low 4-bits of the command number are usually the channel number or label number.