byuu's message board

For discussion of projects related to www.byuu.org/


1, 2  Next
AY-compatible PSG shield for Arduino 
Author Message
Board Admin
User avatar

Joined: Fri 10 Apr 2009, 23:48:17

Posts: 1690
Location: 囧国
Post AY-compatible PSG shield for Arduino
We've managed our first release at the Hardchord project, a six-channel PSG shield for Arduino-compatible devices using two YMZ284 PSG state machines (AY-3-8910 compatible).

The AY-3-8910 and compatible chips were used in a lot of early computing hardware such as the Atari ST, ZX Spectrum, MSX1 (some models) and many arcade games. It's very similar to the SN76489, but is not register compatible (though I expect I can get SN76489 states converted to AY registers).

It is being released as open hardware. The schematics and board stencils can be found at the YMZ Shield project page, and the code is released under the BSD license at GitHub.

Image

Our 12 beta boards were produced with the help of DFRobot.

I'm generally very pleased with how it turned out except for two minor problems. Capacitors C3 and C6 should be 10μF, not 47μF. Also, resistors R1 and R4 should be 1KΩ and not 10KΩ. These two mistakes were causing the waves to be severely malformed when connected to better audio hardware (miraculously, it all worked fine through cheap headphones).

Sample code is available in the library and shows how to do some simple sound effects like going up/down staircases in Dragon Warrior and some basic machine gun effects. There are also 3-channel music demos for Pacman and Duck Hunt, and some massive 6-channel demos that reproduce the FF7 battle theme and Ryu's stage from SF2.

Suggestions on how I can improve the code are welcome. It uses very specific type assignments and has ifdef sections that allow it to use faster AVR style PORT access instead of Arduino-style digitalWrite(). I'm hoping to improve the AVR with more versions to support Arduino Mega and some other boards with non-standard PORT mapping.

The next revision of the board will probably be mapped to the SPI pins for stackability. We may also move the write and bus access lines to a second shifter to keep Arduino pins 0-9 free.

Currently working on a program that would convert SN76489 audio logs to AY-compatible format so we could use this as a hardware player for Sega Master System/Game Gear music, as well as all the AY-3-8910-based formats out there.

https://github.com/sobodash/hardchord/b ... Shield.cpp
https://github.com/sobodash/hardchord/b ... mzShield.h

_________________
web :: deviantArt :: 微博 :: Last.fm :: Twitter

Tue 19 Feb 2013, 15:43:00

Joined: Wed 06 May 2009, 04:13:19

Posts: 4543
Post Re: AY-compatible PSG shield for Arduino
That's a beautiful little piece of hardware.
And a delightful stereo implementation, too! Not enough stereo PSG setups in the world.

BTW, two game consoles used the AY-3-8910 as well. My beloved Vectrex, and the much better-known Intellivision.

_________________
This post best viewed at 800x600
;write ! ! !

Wed 20 Feb 2013, 09:31:42

Joined: Thu 19 Nov 2009, 16:18:55

Posts: 1586
Post Re: AY-compatible PSG shield for Arduino
That's really awesome, D--. Congratulations on getting it out the door. It looks like a sweet little board.

_________________
My Emulator Repo for Debian/Ubuntu/Mint/etc (includes bsnes, Retroarch, libretro, VBA, Nestopia, Dolphin)

Wed 20 Feb 2013, 15:06:04
Board Admin
User avatar

Joined: Fri 10 Apr 2009, 23:48:17

Posts: 1690
Location: 囧国
Post Re: AY-compatible PSG shield for Arduino
Thanks guys. Really appreciate the support. There's a lot of people who keep asking questions like "What's the point?" It's great to see people who get it :)

CaptainJistuce wrote:
BTW, two game consoles used the AY-3-8910 as well. My beloved Vectrex, and the much better-known Intellivision.


Good catch, I forgot about thouse. Should add it to the Wiki. Are there any VGM rips for these systems? I could look into porting them over.

Edit: Uploaded a few rough demos to YouTube:

http://www.youtube.com/watch?v=-wcmNZf33b0
http://www.youtube.com/watch?v=i5qTc73Rb4c
http://www.youtube.com/watch?v=JtzRx7VrKDg

_________________
web :: deviantArt :: 微博 :: Last.fm :: Twitter

Wed 20 Feb 2013, 15:41:07

Joined: Wed 06 May 2009, 04:13:19

Posts: 4543
Post Re: AY-compatible PSG shield for Arduino
D-- wrote:
Thanks guys. Really appreciate the support. There's a lot of people who keep asking questions like "What's the point?" It's great to see people who get it :)

CaptainJistuce wrote:
BTW, two game consoles used the AY-3-8910 as well. My beloved Vectrex, and the much better-known Intellivision.


Good catch, I forgot about thouse. Should add it to the Wiki. Are there any VGM rips for these systems? I could look into porting them over.


I don't think there's any rips. Music's pretty rare in that era anyways.
Most INTV games don't have any, and most Vectrex games only have a single ditty of a few seconds for the title screen, which the built-in MineStorm would replay at the start of every level.

_________________
This post best viewed at 800x600
;write ! ! !

Thu 21 Feb 2013, 04:01:41
Board Admin
User avatar

Joined: Fri 10 Apr 2009, 23:48:17

Posts: 1690
Location: 囧国
Post Re: AY-compatible PSG shield for Arduino
CaptainJistuce wrote:
I don't think there's any rips. Music's pretty rare in that era anyways.
Most INTV games don't have any, and most Vectrex games only have a single ditty of a few seconds for the title screen, which the built-in MineStorm would replay at the start of every level.


You would be surprised. Recent revisions of the format support the chip family. There are a bunch of rips for other systems using the sound chips at:

http://vgm.mdscene.net/forum/viewforum. ... 83b4744f3a
http://vgm.mdscene.net/forum/viewforum. ... 83b4744f3a

_________________
web :: deviantArt :: 微博 :: Last.fm :: Twitter

Thu 21 Feb 2013, 07:17:05

Joined: Wed 06 May 2009, 04:13:19

Posts: 4543
Post Re: AY-compatible PSG shield for Arduino
D-- wrote:
CaptainJistuce wrote:
I don't think there's any rips. Music's pretty rare in that era anyways.
Most INTV games don't have any, and most Vectrex games only have a single ditty of a few seconds for the title screen, which the built-in MineStorm would replay at the start of every level.


You would be surprised. Recent revisions of the format support the chip family. There are a bunch of rips for other systems using the sound chips at:

http://vgm.mdscene.net/forum/viewforum. ... 83b4744f3a
http://vgm.mdscene.net/forum/viewforum. ... 83b4744f3a

Oh, wow... they DO have some Vectrex rips.

"Tracks: 1
Play time: 0:03"

That's why I assumed it hadn't been ripped. Niche system, VERY limited music.

http://vgm.mdscene.net/forum/viewtopic.php?t=491

And there it is. The greatest piece of video game music ever composed.

_________________
This post best viewed at 800x600
;write ! ! !

Thu 21 Feb 2013, 09:06:21
Board Admin
User avatar

Joined: Fri 10 Apr 2009, 23:48:17

Posts: 1690
Location: 囧国
Post Re: AY-compatible PSG shield for Arduino
CaptainJistuce wrote:
That's why I assumed it hadn't been ripped. Niche system, VERY limited music.

http://vgm.mdscene.net/forum/viewtopic.php?t=491

And there it is. The greatest piece of video game music ever composed.


:D

I really like VGM format. It's such an interesting idea: save the clock speed of the sound processor, then tap the actual bus lines and log reads and writes as the occur relative to an external clock.

Unfortunately, the information in the spec is kind of confusing. I'll probably have to study the Audacity code to figure out how exactly its delay bits work. The file spec says:

Code:
  0x61 nn nn : Wait n samples, n can range from 0 to 65535 (approx 1.49
               seconds). Longer pauses than this are represented by multiple
               wait commands.
  0x62       : wait 735 samples (60th of a second), a shortcut for
               0x61 0xdf 0x02
  0x63       : wait 882 samples (50th of a second), a shortcut for
               0x61 0x72 0x03


I tries setting 0x62 as a delay of 16 milliseconds and 0x63 as 20 milliseconds, but it's really just far too short of a delay for the audio. There's probably something else I'm missing ... I need to check my code at home, in retrospect I may have been parsing the nn bytes of 0x61 as MSB instead of LSB.

_________________
web :: deviantArt :: 微博 :: Last.fm :: Twitter

Thu 21 Feb 2013, 11:54:33
User avatar

Joined: Fri 10 Apr 2009, 20:54:19

Posts: 2679
Post Re: AY-compatible PSG shield for Arduino
You could take a look at an actual VGM player, like Game_Music_Emu, or VGMPlay.

Most VGM logs will be interleaving register write commands with delay commands. Most VGM files don't use 0x62 or 0x63 these days, except with a more recent extension that allows the file to reprogram the preset delays for those two commands. Most stuff will usually just use 0x61 to delay for N samples (little endian), or use the newer 0x7x short delay command (delay for low nibble plus one samples). Some things dependent on YM2612 PCM will use the data block system to spare log space, and then use 0x8x pcm delay command (emit one byte from the current position in the PCM buffer to the YM2612 DAC port, then delay for low nibble plus one samples).

And maybe you can also comment on how you feel with regard to the format only being sample accurate to 44100Hz, and not cycle accurate. I think both blargg and I tried unsuccessfully to argue in favor of a cycle accurate format. Cycle accuracy need not imply that the logs will grow to unmanageable sizes.

_________________
blag

Thu 21 Feb 2013, 21:24:00
Board Admin
User avatar

Joined: Fri 10 Apr 2009, 23:48:17

Posts: 1690
Location: 囧国
Post Re: AY-compatible PSG shield for Arduino
kode54 wrote:
Most VGM logs will be interleaving register write commands with delay commands. Most VGM files don't use 0x62 or 0x63 these days, except with a more recent extension that allows the file to reprogram the preset delays for those two commands. Most stuff will usually just use 0x61 to delay for N samples (little endian), or use the newer 0x7x short delay command (delay for low nibble plus one samples). Some things dependent on YM2612 PCM will use the data block system to spare log space, and then use 0x8x pcm delay command (emit one byte from the current position in the PCM buffer to the YM2612 DAC port, then delay for low nibble plus one samples).

While this is true, the overwhelming number of Sega Master System and Game Gear dumps were made in version 1.1 of the file spec. 0x62 and 0x63 are used extensively there, and 0x7x did not exist yet. Since I'm translating between PSG formats, I'm less concerned about newer revisions at this moment.

This will probably change with our next OPN+DAC board, where I will be wanting to ports OPN2+PSG to OPN.

kode54 wrote:
And maybe you can also comment on how you feel with regard to the format only being sample accurate to 44100Hz, and not cycle accurate. I think both blargg and I tried unsuccessfully to argue in favor of a cycle accurate format. Cycle accuracy need not imply that the logs will grow to unmanageable sizes.

Honestly, I don't know how I feel about this. Since my main goal is to port it from one hardware PSG to another, there will always be some degree of accuracy problems. I'm mostly just happy that the information is even available in such a useful format.

Also, cycle accurate to what? The bus timing of the sound chip (datasheet says YMZs data pins update at 10ns, which is like 100MHz) or the timing of the CPU or shifter controlling its register writes (3.57MHz, but there will be a lot of those cycles wasted on actually turning on/off the right pins and pushing out data)?

44100Hz is pretty fast, and will probably be "good enough" for most use cases.

Honestly, I'm not sure how they even make VGM logs. Are they using an emulator? That would already have accuracy problems. The most accurate way would probably be to directly solder wires onto the bus pins of the PSG/FM synth and rapidly poll the state of the pins with another hardware device.

You could probably do it with a 16MHz Arduino. Write a program that loops endlessly with all the pins of PORTD soldered onto the data pins of the sound chip. Every time through the loop, you would simply push the state of PORTD into a flash memory chip over SPI.

This would be fucking huge, and would generate logs of well over 128GB per song I am guessing (have not done the math).

On the PC end, write a tool that parses the logs to find where patterns repeat, and also to collapse the bus log into duration + state: 4,000 cycles observed at 0xd, or whatever. Counting the number of cycles for the SPI transfer would tell you exactly how long the Arduino spent between each data bus poll, giving you exceptionally accurate timing.

But then we're talking about creating a new format... And also requiring all audio rippers to own both the original machine and the original game card.

Honestly, this will always be an imperfect science. The stuff coming out the audio ports, sometimes even off the pins, will never match the perfect square waves or saw envelopes of the data sheets. There are lots of components in there leaking radiation that will pollute whatever analog comes off the DAC (internal or external).

_________________
web :: deviantArt :: 微博 :: Last.fm :: Twitter

Fri 22 Feb 2013, 02:16:23
User avatar

Joined: Fri 10 Apr 2009, 20:54:19

Posts: 2679
Post Re: AY-compatible PSG shield for Arduino
It need not poll constantly. Is there not some way to detect when a fresh bus write is targeting the FM/PSG? Buffer that, log it when it happens.

And yeah, existing VGM dumps are made using emulators, so far as I know.

_________________
blag

Sat 23 Feb 2013, 16:11:00

Joined: Mon 06 Sep 2010, 07:50:15

Posts: 576
Post Re: AY-compatible PSG shield for Arduino
First off, OH SNAP FINALLY SOMEONE ELSE HERE OTHER THAN KODE54 OR MYSELF TALKIN' 'BOUT VGMS! Second, your project looks pretty awesome and if I was more inclined to learn Arduino programming I'd probably pass out from its awesomeness (yes, I'm repeating 'awesome').

Now to your VGM-related issue:

D-- wrote:
Unfortunately, the information in the spec is kind of confusing. I'll probably have to study the Audacity code to figure out how exactly its delay bits work. The file spec says:

Code:
  0x61 nn nn : Wait n samples, n can range from 0 to 65535 (approx 1.49
               seconds). Longer pauses than this are represented by multiple
               wait commands.
  0x62       : wait 735 samples (60th of a second), a shortcut for
               0x61 0xdf 0x02
  0x63       : wait 882 samples (50th of a second), a shortcut for
               0x61 0x72 0x03


I tries setting 0x62 as a delay of 16 milliseconds and 0x63 as 20 milliseconds, but it's really just far too short of a delay for the audio. There's probably something else I'm missing ... I need to check my code at home, in retrospect I may have been parsing the nn bytes of 0x61 as MSB instead of LSB.


The VGM functionality to change the values of 0x62 and 0x63 is too recent to be of any use to older VGM players, so for now I'd recommend using 0x61. Second, as Kode54 said all values are indeed stored and read back as little-endian, so 0x61 0xDF 0x02 becomes 0x61 0x02DF. Pretty much every VGM player I've seen the source for has byte-ordering code to account for ARM and PPC devices running the software.

VGM dumps are currently made using emulators (most of them modded by ValleyBell himself to add the VGM dumping code) and his modded version of M1 for arcade games. Chips are added to the spec depending on if he can find the source for a certain system's emulator and if the audio playback has decent accuracy (it's why PCEngine VGMs use the Ootake core for playback).

Regarding switching VGM from sample accuracy to cycle accuracy, I'd wager it'd probably result in a format similar to PSF where the program (reduced to only the audio code) and data itself is stored in a file and playback is done via a stripped-down emulator. When VGM was being developed there was discussion about the trade-off in file size vs. accuracy and since it went from PSG+YM2413 to YM2612 to YM2151 in v1.50 (the version before I became involved) the original developers tended towards file size. I could go either way, but if that's the case might as well extend PSF to a "VSF" variant or something.

I look forward to seeing OPN/OPN2+DAC on Arduino!

Sat 23 Feb 2013, 23:03:56
Board Admin
User avatar

Joined: Fri 10 Apr 2009, 23:48:17

Posts: 1690
Location: 囧国
Post Re: AY-compatible PSG shield for Arduino
Edit: Major changes have caused everything that was in this post to be out of date.

We're now preparing for our second revision of the board, which will switch to the surface-mount YMZ284-M chips instead of the through-hole YMZ284-D. We have a few sources for these chips which should make the boards much cheaper to produce.

New revision will add a speaker to the board so you will get sound output wen you don't have headphones or a line jack connected.

Working on cleaning up some voltage spikes since the code's timing is already as tight as it can be.

The underlying library is almost completely ported over to AVR now with code for every Arduino board yet released, the new Leonardo, and fallback code that uses the slower Arduino library methods.

We've also rewired the 74HC595 to use the hardware SPI bus for much faster transfers so we can avoid bit banging. The idea is that with the new Hardchord Music block format, it will be possible to run your music inside an interrupt to let you play effects while the rest of your program continues.

_________________
web :: deviantArt :: 微博 :: Last.fm :: Twitter

Tue 26 Feb 2013, 19:47:48
Board Admin
User avatar

Joined: Fri 10 Apr 2009, 23:48:17

Posts: 1690
Location: 囧国
Post Re: AY-compatible PSG shield for Arduino
Image

Say hello to the YM2612+YMZ284 version.

_________________
web :: deviantArt :: 微博 :: Last.fm :: Twitter

Thu 06 Feb 2014, 13:27:32

Joined: Mon 06 Sep 2010, 07:50:15

Posts: 576
Post Re: AY-compatible PSG shield for Arduino
D-- wrote:
Say hello to the YM2612+YMZ284 version.


*o* :shock:

ME WANT.

Thu 06 Feb 2014, 23:17:07
1, 2  Next

Who is online

Users browsing this forum: No registered users and 0 guests

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum