Wolf Team MF Format
===================

This format was first seen in use by Wolf Team games, which used it for MT-32 MIDI music.
Wolf Team had PC-9801 and X68000 drivers that play back MF files.

However the format and driver has also been used by a few other developers as well:
- Melody / PANDA HOUSE used it in their games as "MFD.COM" (with an additional command FC and an improper fix to E0/E1)
- Studio Twinkle used it in the game "Twilight" (with commands F8..FB, but not FC and a proper E0/E1 fix)


Main Header
-----------
2 bytes - "MF"
1 bytes - number of songs (usually 01)
1 byte  - unused (always 00)
4 bytes - total file size

This is followed by all songs concatenated.

Song Header
-----------
2 bytes - song size (includes this value)
2 bytes - unknown (always 0000)
1 byte  - unknown (always 00)
1 bytes - flags (always 28h or 29h)
	Bit 0 (01): Endianess (0 - Little Endian, 1 - Big Endian)
	Note: The PC-98 driver requires the flags to be 28h and refuses to play the song else. The X68000 requires them to be 29h.
1 bytes - song tempo in BPM (Beats Per Minute, with 48 ticks per beat)
1 byte  - track count tc

Note: The "Endianess" flag affects all 2-byte values in the file.

[repeat tc times]
2 bytes - track measure offset list (relative to Song Header)
1 byte  - MIDI channel (00..0F - MIDI channel 1..16, 80..8F - MIDI channel 1..16 in drum mode, FF - disabled)
1 byte  - unused (always 00)
[repeat end]


Track Measure List
------------------
series of 2-byte offsets (relative to Song Header) that point to the measure's sequence data to play
Offsets < 0010h are special:
0000 - track end
0001 - loop start
0002 - loop end
0003..000F - invalid, same effect as track end


Commands
--------
00..7F ll - note, length ll (modified by Dx commands)
00..7F 00 ll - note, absolute length ll, followed by another note at the same tick
80..87 mm - Modulation (MIDI CC 1)
88..8F vv - Main Volume (MIDI CC 7)
90..97 pp - Panpot (MIDI CC 10)
98..9F ee - Expression (MIDI CC 11)
A0..A7 ii - instrument
A8..AF cc dd - Control Change cc, data dd
B0..BF xx - Pitch Bend (8-bit)
	E0 ll mm is calculated as follows:
	pb = 0x2000 + xx
	ll = pb & 0x7F
	mm = (pb >> 7) & 0x7F
C0..CF xx xx - Pitch Bend (16-bit)
	E0 ll mm is calculated as follows:
	pb = 0x2000 + xxxx
	ll = pb & 0x7F
	mm = (pb >> 7) & 0x7F
	Note: The byte order of xxxx depends on the Endianess flag in the file header.
D0..DF - affects note length (D8 - stop after aobut 50%, D2 - stop shortly before actual end)
	-> might be "stop note XX ticks earlier than actual end)
	default: no early stop
	D6 with a note of length 6 means "duration: 1 tick"
	-> according to disasm: D0 = off, D1 = 0 ticks, D2 = 1 tick, etc.
E0..E1 aa bb - Tempo Modifier (E1 = command with delay)
	aa = tempo scale (2.6 fixed point, 40h = 100%, 20h = 50%, 10h = 25%)
	bb = ignored (intended to be RCP-style tempo fade?)
	Notes:
	- The command is buggy in the PC-9801 and X68000 versions of Wolf Team's driver and doesn't have any effect there.
	- MFD.COM (by PANDA HOUSE) uses an incorrect formula: finalTempo = songTempo + (aa - 0x40)
	- The sound driver in "Twilight" (by Studio Twinkle) implements the proper RCP formula: finalTempo = songTempo * aa / 0x40
E2..E3 - set MIDI channel (E3 = command with delay)
E4..E5 aa - Channel Aftertouch (E5 = command with delay)
E6..E7 aa bb - Note Aftertouch (E7 = command with delay)
E8..EB - ignored
EC..EF - Pan (EC = 64/centre, ED = 0/right, EE = 127/left, EF = 64/centre)
	Bug: The X68000 Wolf Team driver sends MIDI CC 0x10 instead of 10, causing it to not work properly.
	      The bug doesn't exist in its PC-9801 version.
F0 dd - delay dd
F1 vv - set note velocity
F2..F7 - ignored
F8..FB - ignored [Wolf Team and MFD drivers]
F8 dd ii bb - set GS instrument [Twilight driver only]
	dd - delay
	ii - instrument
	bb - bank
	The driver will send "Bank MSB = dd", "Bank LSB = 0", "Instrument = ii" in that order.
F9 dd p1 p2 - set Roland Base Address [Twilight driver only]
	same as RCP command DD (see "raw RCP command")
FA dd p1 p2 - set Roland Parameter + send SysEx [Twilight driver only]
	same as RCP command DE (see "raw RCP command")
FB dd p1 p2 - set Roland Device [Twilight driver only]
	same as RCP command DF (see "raw RCP command")
FC cc dd p1 p2 - raw RCP command
	cc - RCP command
	dd - delay
	p1/p2 - parameter 1/2
	MFD driver: Implements RCP commands DD/DE/DF as described below. The files also seem to use RCP command F6/F7 for song comments.
		DD - set Roland Base Address
			p1 = address high "raH"
			p2 = mid "raM"
		DE - set Roland Parameter + send SysEx
			p1 = address low "raL"
			p2 = parameter "rPar"
			-> the driver sends: F0 41 rDev rMod 12 raH raM raL rPar [checksum] F7
		DF - set Roland Device
			p1 = Device ID "rDev"
			p2 = Model ID "rMod"
	Wolf Team driver: Only bb is used as delay. All other parameters are ignored.
	Twilight driver: The command is ignored and treated as it would have no parameters.
FD - increment Measure Counter
FE - Measure End (reads next measure pointer)
FF - Next Measure (combines FD and FE)
	Note: The actual value of the Measure Counter is ignored. FE and FF always just read the next measure pointer.

How the command ranges work:
cc+00 - command, no delay
cc+01 - command, delay of 1 tick
cc+02 - command, delay of 2 ticks
...
cc+(n-2) - command, delay of (n-2) ticks
cc+(n-1) xx - command, delay xx ticks (additional delay parameter right after command byte)
