z80 vgm player

For anything related to sound (YM2612, PSG, Z80, PCM...)

Moderator: BigEvilCorporation

sigflup
Very interested
Posts: 111
Joined: Mon Sep 06, 2010 12:05 pm
Contact:

z80 vgm player

Post by sigflup » Sat Aug 04, 2012 11:18 pm

This is my vgm player for the z80. Works on real hardware. This assumes that the vgm starts at 0x8000 in the rom. Doesn't play samples as of yet. You have to pre-process the vgm with vgm2zgm in the tarball. This compiles with a slightly modified sdcc. prog.c tells you what's modified. I'll also supply the firmware, here you go

source code is here

Chilly Willy
Very interested
Posts: 2854
Joined: Fri Aug 17, 2007 9:33 pm

Post by Chilly Willy » Sat Aug 04, 2012 11:47 pm

Nice work! You've been busy. :D

kubilus1
Very interested
Posts: 237
Joined: Thu Aug 16, 2012 2:25 am
Contact:

Post by kubilus1 » Fri Aug 17, 2012 4:06 pm

Wow, that seems to be what I am looking for. Now I just have to figure out how to incorporate it into a running example. BTW, what is bin2head? Google only seems to show window EXE, is there something more *nix friendly?

sigflup
Very interested
Posts: 111
Joined: Mon Sep 06, 2010 12:05 pm
Contact:

Post by sigflup » Fri Aug 17, 2012 4:49 pm

kubilus1 wrote:Wow, that seems to be what I am looking for. Now I just have to figure out how to incorporate it into a running example. BTW, what is bin2head? Google only seems to show window EXE, is there something more *nix friendly?
bin2head coverts a binary onto a c header file. basically I #include the firware into my code

djcouchycouch
Very interested
Posts: 696
Joined: Sat Feb 18, 2012 2:44 am

Post by djcouchycouch » Fri Aug 17, 2012 6:56 pm

Hi,

Can this be made to work with the SGDK?

What does the vgm2zgm tool do the vgm file?

Other than not playing samples, are there any other current limitations?

Thanks!
DJCC

sigflup
Very interested
Posts: 111
Joined: Mon Sep 06, 2010 12:05 pm
Contact:

Post by sigflup » Sat Aug 18, 2012 6:42 pm

I've never used sgdk so I don't know. as far as I know sgdk is just a gcc library so yeah. you could #include it or .incbin it. vgm2zgm just makes all the vgm instructions the same size. that's to promise the same number of z80 clocks per instruction. aside from samples it should work on any sega genesis vgm

djcouchycouch
Very interested
Posts: 696
Joined: Sat Feb 18, 2012 2:44 am

Post by djcouchycouch » Sun Aug 19, 2012 1:35 am

Can it play music and sound effects together?

sigflup
Very interested
Posts: 111
Joined: Mon Sep 06, 2010 12:05 pm
Contact:

Post by sigflup » Sun Aug 19, 2012 2:09 am

don't see why not. You'd have to play the sound effects with the 68k though

kubilus1
Very interested
Posts: 237
Joined: Thu Aug 16, 2012 2:25 am
Contact:

Updated the Driver

Post by kubilus1 » Wed Aug 29, 2012 4:03 am

Okay I spent some time revamping this driver and making it a bit more of an API. Now the songs can be located anywhere in the memory and the driver will take care of banking, finding the offset within the bank, etc.

The sdcc stack space at 0x1fff still applies, but I went ahead and precompiled the z80 driver and bin2c'd it to a .h file so it won't be necessary to deal with this.

This is in three parts:

* The z80 stuff: vgm_drv.c (The source) vgm_drv.h (The compiled driver) Makefile
* The 68k interface: vgm_client.c (The main lib) vgm_client.h (The api to this) Makefile.client (yeah two makefiles, crappy I know!)
* A sample use case: test.c (Just threw this into Makefile.client because I'm lazy)

Test.c should show how this is used and now should be very straightforward. Deflemask > vgm > vgm2zgm > bin2c. Then just point the driver at the start of your song and tell it to go. I'm sure there are some bugs, which I'll work on when I get time.

I also threw in a couple crappy songs I did in deflemask with the vgm export, just to show that it can be done. I apologize for any injured ears. Prebuilt this as z80vgm.bin.

Also, thanks to Sigflup, ChillyWilly, and others whose bits and pieces of code from the forum found there way into this.

Here's the download: http://dl.dropbox.com/u/101302896/z80_sound_drvr.tgz

sigflup
Very interested
Posts: 111
Joined: Mon Sep 06, 2010 12:05 pm
Contact:

Post by sigflup » Thu Aug 30, 2012 7:51 pm

wow! this is awesome! thank you

kubilus1
Very interested
Posts: 237
Joined: Thu Aug 16, 2012 2:25 am
Contact:

Post by kubilus1 » Thu Aug 30, 2012 8:40 pm

Glad you like it. I kind of cheated with the IO between the z80 and 68k. It seems sdcc will not do staticly located variables, at least not on the z80. This should be fine unless the variables are moved around, then you would have to reference the .map file. I thought about making some sort of parser for this and spitting out a header, perhaps later.

Otherwise, sdcc is really neat!

Now onto, making some graphics, sprites and stuff. Will look at mega-happy-sprite. It's great there are other *Nix developers doing genesis development, I was starting to worry that this was a Windows only club.

Chilly Willy
Very interested
Posts: 2854
Joined: Fri Aug 17, 2007 9:33 pm

Post by Chilly Willy » Fri Aug 31, 2012 12:40 am

Damn! That's pretty nifty! I'd have never though to do a z80 sound driver in C. :lol:

That's probably plenty fine for anything but pcm. For that you'd need to redo the player to 100% assembly.

You're right about sdcc not doing static entry points in banks... so what we did for the SMS Myth menu was mic made a little tool to convert sdcc map files into h and inc files with the values needed. If you're interested, look at the map2h.cpp file in the sms tools branch of the neomythmenu project at google code.

http://code.google.com/p/neo-myth-menu/

Note - there's also a vgm player in the sms myth menu, but it's for playing SMS VGMs. It could be altered to play MD VGMs, I imagine.

bastien
Very interested
Posts: 208
Joined: Mon Jun 25, 2007 7:19 pm
Location: Besançon,France
Contact:

Re: Updated the Driver

Post by bastien » Sat Oct 20, 2012 9:21 am

kubilus1 wrote:

Test.c should show how this is used and now should be very straightforward. Deflemask > vgm > vgm2zgm > bin2c. Then just point the driver at the start of your song and tell it to go. I'm sure there are some bugs, which I'll work on when I get time.
How did u use vgm2zgm i have builded the .c and use the syntaxe vgm2zgm test.vgm but don't works.
Thanks for help

kubilus1
Very interested
Posts: 237
Joined: Thu Aug 16, 2012 2:25 am
Contact:

Post by kubilus1 » Mon Oct 22, 2012 4:02 pm

I believe like this:

$ cat test.vgm | vgm2zgm > test.zgm


PS: I'm working on an update to this driver that will no longer require vgm2zgm and will support PCM, along with other improvements.

kubilus1
Very interested
Posts: 237
Joined: Thu Aug 16, 2012 2:25 am
Contact:

Updated Sound Driver.

Post by kubilus1 » Thu Oct 25, 2012 3:32 pm

Updated the z80 VGM player:

* vgm2zgm no longer required. Just turn a regular vgm into a header file with bin2c or something similar. Have tried with a number of different VGM versions.

* PCM support. This works with PCM from files exported from Deflemask. 8khz samples only.

* Banking switching, looping, etc. This should work correctly with files split across banks, that loop across banks, PCM split across banks, etc. Reading header and determining loop location and other relevant info.

* Examples for both sgdk and non-sgdk usage.

* Pausing works.


Get it here: http://dl.dropbox.com/u/101302896/sound ... _25_12.zip


----------------------------

Note, it's unlikely I'll try for anything above 8khz samples since this would be impractical in C, unless I re-write this in straight assembly. However, I would rather work on something else, such as, I don't know, creating a game of sorts! :)

Post Reply