I also posted this new in the SpriteMinds forum (devoted to 16 bits sega programming) and Sega-16 forum but i think it can be interesting to post it as well so here it is !

I released a new version of SGDK, a sort of SDK for the Sega Megadrive that you can find here :

The big addition of this version is the new sound driver : the XGM driver.

Here is what this driver supports :
- 5 FM + 4 PSG + 4 PCM @14 Khz playback
- 16 priority levels for SFX play through PCM.
- support music pause / resume command.
- automatic DAC enabled handling when PCM are played.
- no size limit for XGM music data and PCM data.
- PCM must have their size and address aligned to 256 bytes.
- 100% running on Z80
- protection against DMA contention to preserve good PCM playback quality (not 100% guaranteed depending the driver load).

The XGM format is similar to VGM in the way it uses chip writes logging but is optimized for the Sega Megadrive where VGM support various systems. Because of that the XGM file size is usually about 30% smaller than VGM file (of course i am speaking about optimized VGM).
The advantage of using that type of format is that SGDK enable VGM playback directly through the XGM driver !
I developed a new tool (xgmtool) which convert a VGM file into a XGM file, it was a pain in the ass to convert my java tool in C but it's working now smile Actually xgmtool can do a lot more than that, it is a powerful tool to optimize the Megadrive VGM file (require 1.5 vgm file at least) ! I was really disappointed with the current available VGM utilities... not able to find a working VGM optimizer, or maybe i used them incorrectly but i tried hardly at least... so i had to develop my own tool :-/
There are restrictions in the VGM optimization and the XGM convertion: the XGM format uses frame based timing so if a VGM file use sub frame timing then the conversion may fails...

Currently there is unfortunately no tracker taking advantages of the XGM 4 PCM channels and that is a reason why i decided to post the new here smile Of course basically the Sega Genesis has hardware support for 5FM + 4PSG + 1PCM (or 6FM + 4 PSG) so it's normal to find this configuration in dedicated Sega Megadrive tracker software. With this new driver, the number of PCM channel can be increased to 4 and i believe it could be nice to have a tracker supporting this feature (in which case only XGM export is available).

For those who are interested, here are the XGM format specifications: … in/xgm.txt

Note that the Z80 XGM driver does not directly play the XGM file, it requires a compiled XGM file (thanks to xgmtool) which is very similar to the XGM format with some slight changes to make file parsing a bit easier for the Z80 smile

You can find an example in the usual sound sample:
source and binary

Last edited by Stef (Aug 25, 2015 2:39 pm)

Brooklyn, NY

Welcome Stef!

Can't wait to try this out.


Thanks smile and sorry i forgot to introduce myself !
I guess there is a section for that wink


Paging CountSymphonic. I know this goes beyond Genesis hardware, but I'm interested to know how this could possibly fit in with Prodigy (though it'd likely be a pain to rehash sound drivers).

Last edited by Jansaw (Nov 26, 2014 4:55 pm)


Yup, Stef and I already had a talk about this. Using the sound driver itself for tracking probably won't happen. But adding certain features like the multiple channel PCM playback and .XGM import and export will be something I'll be looking into at a later stage.

Very nice work Stef, way to push the console to it's limits! If you like I can test it on hardware as well and help you identify possible causes for bugs. The Genesis/Megadrive's sound chips and I.. well we understand each other. wink

Last edited by CountSymphoniC (Nov 26, 2014 6:38 pm)


Yeah, it would be awesome to have support for XGM in the Prodigy tracker smile I think there is no way of using the driver itself to play through Prodigy, and there is no point in doing it i believe as the 68k is handling FM & PSG chip itself so it has more control.
A solution could be using the Z80 for 4 PCM playback while the 68k is handling FM & PSG, i think that is a viable solution.
I know there is some bug in the xgmtool and that was expected tongue  Many possible bugs in the VGM to XGM conversion process wink
About the hardware itself, there is still the pause command which does not work on real hardware... i have to investigate it as i got it to work at some point. What i'm doing now is to put RR to max for each operator then keying off every channel. It should work (and work on emulator) but it does not on real hardware where some notes continue to play :-/

Last edited by Stef (Nov 27, 2014 10:00 am)

Buenos Aires, Argentina

Great tool!

Stef wrote:

There is a bug in my xgmtool which may not convert correctly VGM file from deflemask into XGM (samples are not correctly preserved from what users reported me). I will fix that asap

DefleMask uses 1.60 VGM files, the samples are stored in the header and you call them by ID after. This is always better than rewriting the sample data each time you want to play it. I don't know if you tool supports 1.60 VGM specs, bu you definitely should. smile

Last edited by Delek (Nov 27, 2014 11:00 am)


Yeah of course i support VGM 1.6 wink xgmtool is able to take a VGM 1.5 and optimize it in VGM 1.6, actually that is a part of the VGM to XGM conversion wink I fixed the bug and i believe there is no more issue with DefleMask VGM file now  :

Last edited by Stef (Nov 27, 2014 12:45 pm)


Hmm so basically just include the z80 code for 4 PCM. I'll have to dig through the source and see for myself how all this works. I'll have to implement it soon.

Is the 4 PCM support suitable for chromatic sampled instruments? I'm curious what one would have to do in code to control the pitch of the samples. I see using percussive samples would be simple, but things like Piano or Strings is what I'm curious about. Also, isn't it the case that 1 PCM channel is done with the YM2612 and the other 3 are done with the PSG tone channels 1-3 or are all 4 done in one YM2612 channel?

This could very well turn the Sega Genesis/Mega Drive into the perfect sample/synth tracking console. Very exciting!

Also, as for your pause bug... I would think that the Key off and RR maxed out would have done the trick. Try maxing the TL also, it should silence everything.

Last edited by CountSymphoniC (Nov 27, 2014 6:23 pm)


I would say "almost". The 4 PCM driver is feeding the DAC register in continue so when you do YM writes from the 68000 you need to :
- interrupt Z80 to take its bus
- write the YM chips (register index and value)
- restore register index to 0x2A for YM port 0 (so Z80 will write the DAC register again)
- release Z80

Also you should have a look in the SGDK sound.c source file to see how i load and control the 4 PCM driver (SND_xxx_4PCM(..) functions).
And unfortunately these 4 channels PCM drivers does not support pitch adjustment, all samples are played at a fixed 16 Khz (and 14 Khz in case the XGM driver) so there are useful only for drum and beat. There is a 4 PCM driver which does support envelop (16 levels per channel) but as the XGM driver does not support it you don't require it. In SGDK all multiple PCM drivers are done by software mixing so it only uses the FM5 in DAC mode smile

Thanks for the tip with TL, i think that is what i did initially when it was working but i wanted to have faster pause command and so only use the RR but it looks like that is not enough on real hardware :-/

Last edited by Stef (Nov 27, 2014 11:47 pm)


Just to post some news, all the firsts issues with the XGM driver were resolved quickly and i just uploaded a new version of SGDK which fix a minor issue (PCM playback could be delayed in some case in some case). I think now the XGM driver is already pretty stable and can be used safely in ambitious project (as Antarex) smile

Stef wrote:

Just to post some news, all the firsts issues with the XGM driver were resolved quickly and i just uploaded a new version of SGDK which fix a minor issue (PCM playback could be delayed in some case in some case). I think now the XGM driver is already pretty stable and can be used safely in ambitious project (as Antarex) smile

How are things coming along with this?

Is it possible to use this in conjunction with mml?

Last edited by marcb0t (Apr 23, 2016 4:10 am)


I will soon post a new version of my dev kit including an updated version of the driver.
It should support variable tempo so you won't require anymore to use 2 different tracks for NTSC and PAL systems, it also improves the DMA contention to preserve the PCM quality.
XGM has nothing to do with MML actually, MML is about editing / composing music so more related to music editor as Deflemask or VGMMaker (if we are speaking about the Megadrive) where XGM is just a driver playing the music coming from chips command logs. The advantage is that it can take .VGM as input (almost every tools can do .VGM export) and convert it to XGM, the disadvantage is that format is heavier in size than a real music format (as MML). XGM size is pretty acceptable though (smaller than optimized VGM).


is anyone live here? i have a questions about it. we are try to attach new songs into RRR game. that original driver have some problem - first is size, second is samples and song at same time. now when Larry says some - song is paused.

both that problem was solved, but into two different thread smile it can be played samples and song at same time, but limit of song is 3 kb. it can be played up to 32kb song, but when will play samples - song will paused. and next problem is - deflemask 2 rrr converter. i have some problem will effects. my note bend is going to some wrong place... and i am stuck with it.

so idea is to change driver. so choice is GEMS or this one. with GEMS no have size limit, no have samples and song at same time problem. but slides... that deflemask's effects is killing me. how to recount all that effects into RRR drivers, or into GEMS - no idea. with XGM, as i heard - with that effects is no problem. but our technical's expert says it will be problem with a samples quality. what is that problem? it need to play 8bit 8000 PCM mono samples. at same time as melody plays. it is some narrator phrases.

can some one i little explain? remember - explain like for a child. i am not very technical expert smile just by simple words.