Neo Geo Pocket Color YM player

Discussion of development of software for any "obsolete" computer or video game system. See the WSdev wiki and ObscureDev wiki for more information on certain platforms.
mic_
Posts: 922
Joined: Thu Oct 05, 2006 6:29 am

Neo Geo Pocket Color YM player

Post by mic_ »

Lately I've been writing an YM player for the Neo Geo Pocket Color. In case you don't know, .YM files are register logs (16 bytes per frame) for the YM2149 chip and its clones (like the AY-3-8910). These chips were used in the Atari ST, ZX Spectrum, Amstrad CPC, and probably a lot of other '80s home computers and arcade machines.

While the sound chip in the NGPC is quite similar to the one found in the SEGA Master System, which in turn is relatively similar in capabilities to the YM/AY chips, there were differences that made me not choose to emulate the YM/AY using the NGPC's PSG (for example, it can't generate low-enough frequencies).

So what I do instead is to generate PCM data and output it to the NGPC's 8-bit audio DACs. This is of course a lot more CPU-intensive, so I had to settle for very low sample rates. Currently the maximum output sample rate I've been able to use is 8 kHz. The NGPC's main CPU (a TLCS-900/H) runs at 6.144 MHz, with every two cycles making up one CPU state. At an 8 kHz sample rate this gives me 3072000/8000 = 384 states per sample. The fastest instructions take 2 states to complete, but most take more.

Here's a video of the first version which used a 6 kHz sample rate.

And here's a video of an optimized version using an 8 kHz sample rate. I've also made the ROM available for this version, which you can run on your NGPC if you happen to own a flash cart (I'm unsure if there are any emulators available that will run it correctly).
Shiru
Posts: 1161
Joined: Sat Jan 23, 2010 11:41 pm

Re: Neo Geo Pocket Color YM player

Post by Shiru »

Nice experiment. Sadly, it is known from earlier attempts on the software AY emulation on Z80 at 10 MHz fully dedicated to it is not enough to complete emulation of the chip, with the noise and envelope (the best part of the chip) generators with nice quality. I guess TLCS-900 at 3 MHz processing power is close to Z80 at 10 MHz.

By the way, in fact AY is the original, YM is a clone.
mic_
Posts: 922
Joined: Thu Oct 05, 2006 6:29 am

Re: Neo Geo Pocket Color YM player

Post by mic_ »

Well, I can probably get it up to 9.6 kHz with some more work. But I believe 16 kHz would be the lower limit for where it would start sounding half-decent.
I've been considering various ways of moving parts of the emulation to the sound co-processor (a 3.072 MHz Z80) - for example the envelope generation, which is the most expensive part. But I haven't yet come up with a cheap way that would keep the two processors in sync.
mic_
Posts: 922
Joined: Thu Oct 05, 2006 6:29 am

Re: Neo Geo Pocket Color YM player

Post by mic_ »

Do I feel silly. I had been hunting cycles everywhere I could find them in my playback code, and it still didn't add up. I'd counted the best-case and worst-case cycles manually but for some reason the code seemed to perform worse than it should when I actually ran it on my NGPC.

It wasn't until yesterday that I (accidentally) realized that I had put an absolute jump at the end of my playback loop, instead of a long relative jump. My code runs from RAM (which is faster because of the wider bus), but because of this error, every sample except the first one of each buffer would be generated and mixed by code running from ROM.
At least this had made me look harder for ways of optimizing the code compared to what I otherwise might have.

And with that I give you some videos of YM files being played back at 16000 Hz on my NGPC:

Saboteur 2
Pablo and the gold of Montezuma
DOC Zak 1

Here's a zip file with the corresponding ROMs.
mic_
Posts: 922
Joined: Thu Oct 05, 2006 6:29 am

Re: Neo Geo Pocket Color YM player

Post by mic_ »

I've improved the envelope generator emulation a bit, so a lot of songs now sound better. And I also drew some graphics instead of just using the system font on a plain background.

Image

Videos:
Epic Tune 19
Oblaka

ROM download. There's a tool included (for Windows) that allows you to easily generate new ROMs with different YM files. The source code of the player is also included.
zzo38
Posts: 1096
Joined: Mon Feb 07, 2011 12:46 pm

Re: Neo Geo Pocket Color YM player

Post by zzo38 »

VGM format can also log the register writes of AY-3-8910 and of various other sound chips. Can it be used with VGM too? Furthermore, Sunsoft 5B audio in NSF is also a clone of AY-3-8910, too (and I suppose it might be logged to VGM). What programs are there to write musics for this chips other than ppMCK and VGMCK and Vortex Tracker? (There is also AY8930, which VGM format supports and VGMCK can be used to write music for it, but VGMPlay does not yet support. Is your program compatible with AY8930?)
(Free Hero Mesh - FOSS puzzle game engine)
mic_
Posts: 922
Joined: Thu Oct 05, 2006 6:29 am

Re: Neo Geo Pocket Color YM player

Post by mic_ »

Can it be used with VGM too?
That might be difficult, but it would depend on how the VGM had been generated. If the whole file looked like write-reg0 write-reg1 ... write-reg13 wait-frame it would probably be doable, otherwise it might not be.
What programs are there to write musics for this chips other than ppMCK and VGMCK and Vortex Tracker?
maxYMizer comes to mind. There are probably a lot of other ones. I'm not all that familiar with the Atari ST or Spectrum scene.
Is your program compatible with AY8930?
If you only use its AY-3-8910 compatibility mode, then yes. But it won't play anything that uses the extra registers.
mic_
Posts: 922
Joined: Thu Oct 05, 2006 6:29 am

Re: Neo Geo Pocket Color YM player

Post by mic_ »

I've posted a short write-up that goes into some detail on the YM/AY chip and the NGPC hardware, and then describes how the player works.
zzo38
Posts: 1096
Joined: Mon Feb 07, 2011 12:46 pm

Re: Neo Geo Pocket Color YM player

Post by zzo38 »

mic_ wrote:
Can it be used with VGM too?
That might be difficult, but it would depend on how the VGM had been generated. If the whole file looked like write-reg0 write-reg1 ... write-reg13 wait-frame it would probably be doable, otherwise it might not be.
Maybe it is possible to convert other features into write-reg0 write-reg1 etc and then convert to .YM format, possibly
Is your program compatible with AY8930?
If you only use its AY-3-8910 compatibility mode, then yes. But it won't play anything that uses the extra registers.
Same as VGMPlay; it doesn't currently support the extra registers either. Do you know of a program that does support it? (preferable open-source, and that might be made to work with VGMPlay; otherwise, it still may be possible to convert .VGM into another format supported by other program, so that you can use VGMCK to write music of AY8930 and convert it to play in the other program)

You say if 7-Zip is installed you can right-click the file; I have the command-line program installed and just typing in "7z x" and the filename will extract it. (Note: Don't download the "command-line only" version, which omits many features; download the full version, it includes the full-featured command-line program. However, if you don't want the GUI you can delete that and the command-line still works.)
(Free Hero Mesh - FOSS puzzle game engine)
mic_
Posts: 922
Joined: Thu Oct 05, 2006 6:29 am

Re: Neo Geo Pocket Color YM player

Post by mic_ »

Maybe it is possible to convert other features into write-reg0 write-reg1 etc and then convert to .YM format, possibly
If they use short delays to write to the chip multiple times per frame my player wouldn't support it. If the VGM file only contains YM/AY register write commands and "wait one frame"-commands it will practically be the same as an .YM file and then it would be easy to support it.
Do you know of a program that does support [the AY8930]?
No.
I have the command-line program installed and just typing in "7z x" and the filename will extract it.
Oh, ok. That's nice. I only ever use the GUI version for Windows and Ubuntu.
psycopathicteen
Posts: 3140
Joined: Wed May 19, 2010 6:12 pm

Re: Neo Geo Pocket Color YM player

Post by psycopathicteen »

So what I do instead is to generate PCM data and output it to the NGPC's 8-bit audio DACs. This is of course a lot more CPU-intensive, so I had to settle for very low sample rates. Currently the maximum output sample rate I've been able to use is 8 kHz. The NGPC's main CPU (a TLCS-900/H) runs at 6.144 MHz, with every two cycles making up one CPU state. At an 8 kHz sample rate this gives me 3072000/8000 = 384 states per sample. The fastest instructions take 2 states to complete, but most take more.
Does that mean the 6 Mhz TLCS-900/H in the NGPC is roughly the same speed as the 12 Mhz 68000 in the "full sized" Neo Geo?
tepples
Posts: 22708
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: Neo Geo Pocket Color YM player

Post by tepples »

A 68000 has four cycles per state, but I seem to remember that the fastest instructions finish in one state. Correct me if I'm wrong though.
psycopathicteen
Posts: 3140
Joined: Wed May 19, 2010 6:12 pm

Re: Neo Geo Pocket Color YM player

Post by psycopathicteen »

I misread 2 states as 2 cycles.
User avatar
TmEE
Posts: 960
Joined: Wed Feb 13, 2008 9:10 am
Location: Norway (50 and 60Hz compatible :P)
Contact:

Re: Neo Geo Pocket Color YM player

Post by TmEE »

Most instructions that operate on registers alone take 4 cycles. Most common instructions go from 4 to 20 in steps of 2 cycles, all comes down to the addressing modes used and whether or not you deal with byre/word or longs. Every byte/word access is 4 cycles, longs take 8 cycles. Register operations don't normally add extra cycles, arithmetic adds in steps of 2, depending on operation. Address register increment comes for free, and arranging your data for sequential access makes things lovely.
psycopathicteen
Posts: 3140
Joined: Wed May 19, 2010 6:12 pm

Re: Neo Geo Pocket Color YM player

Post by psycopathicteen »

So basically the 68000 and TLCS-900/H are about the same performance wise?
Post Reply