It is currently Sun Dec 10, 2017 11:03 pm

All times are UTC - 7 hours





Post new topic Reply to topic  [ 12 posts ] 
Author Message
 Post subject: Gameboy Sound Question
PostPosted: Mon Feb 10, 2014 11:15 am 
Offline

Joined: Mon Feb 10, 2014 10:37 am
Posts: 5
Hi Everybody,

I talk too much so to just see my questions skip down past the context description...

To put my questions in context {
I've already learned a lot from reading through everyone's posts here, as well as from all of the links shared. However, I am new to developing and interfacing with older systems, as most of the programming I've done is with higher level languages like C#, PHP, etc for web development, but I am dying to figure out how to get into making hardware prototypes for things.

I have been using Arduino boards to control MIDI enabled devices, and I more or less understand how that environment functions. I have a sequencer prototype that will output MIDI to MIDI devices, but I could just as easily send out messages other than MIDI from my hardware's button pushes and knob turns (ie binary commands to Gameboy's CPU.) I don't understand exactly how this works for the Gameboy (or NES.)

Most of the information I have found for Programming audio uses a cartridge to hold the values to be read into the CPU to be used to tell it what sound to make. I have seen Nanoloop, mGB, and LSDJ where this is the flow, but when looking into how to flash cartridges and the hardware to put compiled code onto the cartridge, I found that most of the equipment to do this is either homemade or super rare and expensive.}

Questions {
So I have found a lot of documentation for the register values the Gameboy uses to tell the CPU to make a noise. Can I just put these values into the system memory using the cartridge connector pins connected to my Arduino and have them read from there?

If yes, where exactly do these commands need to go in the Gameboy?

If not, do I then need to simulate a rom somehow? The orginal ChipMaestro project was using doing something similar for the NES I think.

Forgive my ignorance, I am still learning, but feel free to point out where I am misunderstanding how these systems work.

Thanks!


Top
 Profile  
 
PostPosted: Mon Feb 10, 2014 11:46 am 
Offline

Joined: Sun Apr 13, 2008 11:12 am
Posts: 6503
Location: Seattle
MoZI wrote:
Can I just put these values into the system memory using the cartridge connector pins connected to my Arduino and have them read from there?
No, you'll have to write GBZ80 code. SDCC does support writing C for the Gameboy, so this isn't too much of a barrier.
Quote:
If not, do I then need to simulate a rom somehow? The orginal ChipMaestro project was using doing something similar for the NES I think.
You'll either need a ROM or the ability to fake one by providing data to the CPU at the right time. The timing of the GBZ80 is tighter (wait states are briefer) so this is likely harder than for the NES. A general-purpose ROM emulator was commercially released for the Atari 2600 (the "harmony cart"): it uses a 70MHz ARM to emulate a 32KiB ROM. But the 2600 is 2/3 the speed of the NES.
There are techniques that would allow a non-general purpose ROM emulator with lower demands, but I would strongly encourage doing something simpler (i.e. an actual ROM) before attempting them. Similarly, I'm pretty certain the ChipMaestro is significantly more complicated (both routing difficulty and code complexity) than the equivalent functionality implemented using just 6502 code.


Top
 Profile  
 
PostPosted: Mon Feb 10, 2014 1:10 pm 
Offline

Joined: Mon Feb 10, 2014 10:37 am
Posts: 5
Thanks for the fast reply. :)

I absolutely agree that I should start simple. At this point, I am still trying to learn enough about how these systems work to know what will be simple. The reason I thought something like what I am describing is possible is because of a few projects that use Arduinos to somehow trigger notes.

The first is SonikTech's early NES experiments.... http://www.soniktech.com/tsundere/ (this is what I was talking about when I said early ChipMaestro prototype)

Then, on Shiftmore's blog he uses SonikTech's work to translate it to an Arduino Uno .... http://shiftmore.blogspot.com/2012/11/a ... art-i.html

I don't understand a lot about how they are doing this stuff, but it was my jumping off point since I am already using the Arduino Uno to send and recieve MIDI messages and I have digital pinouts available on the board. I also don't really know how closely the Gameboy's audio system resembles the NES even though, as far I understand it, they seem similar. I really only decided to look into the Gameboy because I could mount it's guts inside my controller and power it with batteries, but if the NES is easier to figure I could go with it to make noise, I would just need to build a bigger enclosure.

Am I completely misunderstanding what they are doing?


Top
 Profile  
 
PostPosted: Mon Feb 10, 2014 2:31 pm 
Offline

Joined: Mon Feb 10, 2014 10:37 am
Posts: 5
Looking at the GameBoy CPU Manual, it seems like the first thing I don't think I can overcome without the cartridge is the startup check the GameBoy requires before it switches to the cartridge rom, but then after that initial check, can I run a loop that checks the cartridge RAM for values I write to it from the Arduino? The ArduinoBoy sends MIDI over the side input on the side input on the GameBoy. Is it just a matter of writing notes to the cartridge RAM and letting them play at that point?


Top
 Profile  
 
PostPosted: Mon Feb 10, 2014 3:15 pm 
Offline

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 19322
Location: NE Indiana, USA (NTSC)
The Game Boy needs to be running a program to receive the notes from the serial port at the side and play them through the speaker. On the original Game Boy and the Game Boy Color, this program must be on a Game Pak. The Game Boy Advance, on the other hand, can boot a small (<250K) program from its serial port, and homebrewers would routinely use this "MultiBoot" method to test code.


Top
 Profile  
 
PostPosted: Mon Feb 10, 2014 3:25 pm 
Offline

Joined: Sun Apr 13, 2008 11:12 am
Posts: 6503
Location: Seattle
I'm really not certain how to usefully integrate an external microcontroller here. The power-on licensing test requires either knowing the exact order the bootstrap code reads so that the micro can feed them, or else using a ROM. Once you're using a ROM instead of treating the GB as the world's most obnoxious-to-use knockoff of an AY-8910, it doesn't really make sense to ignore the CPU that's already part of the hardware.

The design that shiftmore uses the array of '245s and '138 to fake an 8-byte ROM that contains the five-byte sequence $A0 dd $8C aa $40 ob ob ob, which becomes be LDY #dd / STY $40aa/ RTI / RTI / RTI. On 2A03 power-up, it reads the reset vector from $FFFC ($40) and then $FFFD (open bus, so still $40), which effectively means it starts executing at $4040. Whenever it overflows and starts executing the RTIs, it pulls $40 from the stack all the time, and so returns to $4040. the value of open bus, which will be the same as the value written to the register. I have no idea how that doesn't crash all the time; certain values when interpreted as an instruction (e.g. 2) cause the 6502 to stop executing code until it's reset. That's ... astoundingly cleverly hacky, although I'd be more comfortable with it not explicitly depending on open bus behavior (It doesn't protect the user against stupidity: if the user enables APU interrupts, it could interrupt code mid-sequence and then crash. There are specific values of dd and aa which would cause a crash if an interrupt arrived at the right time, e.g. d=3 and a=2.


wild tangent: Something that I've wanted for a while for the GBA multiboot would be something that made it look like a USB hard drive, so that you'd just copy a 256KiB image onto it and the GBA would run it.

edit: back in the school of "how on earth did this ever work?"


Last edited by lidnariq on Tue Feb 11, 2014 1:16 pm, edited 1 time in total.

Top
 Profile  
 
PostPosted: Mon Feb 10, 2014 3:34 pm 
Offline

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 19322
Location: NE Indiana, USA (NTSC)
lidnariq: You'd like the GBA Movie Player. It runs mb.gba binaries from a CF card.


Top
 Profile  
 
PostPosted: Mon Feb 10, 2014 4:29 pm 
Offline

Joined: Sun Apr 13, 2008 11:12 am
Posts: 6503
Location: Seattle
The point was not needing to physically move anything: the GBA equivalent of blargg's rs232-to-NES cable.


Top
 Profile  
 
PostPosted: Mon Feb 10, 2014 4:59 pm 
Offline

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 19322
Location: NE Indiana, USA (NTSC)
That'd be either the MBV2 cable or this project by nocash.


Top
 Profile  
 
PostPosted: Mon Feb 10, 2014 10:29 pm 
Offline

Joined: Mon Feb 10, 2014 10:37 am
Posts: 5
lidnariq wrote:
the world's most obnoxious-to-use knockoff of an AY-8910

You guys know all things that are good. I actually found a really simple stripped down Arduino project that uses this processor instead.

lidnariq wrote:
it doesn't really make sense to ignore the CPU that's already part of the hardware.

Agreed. The project I was trying to incorporate the GameBoy into is a MIDI sequencer that sends MIDI to my hardware synthesizers. By itself, it doesn't make any sound, so I wanted a low power sound generator that I could embed in the sequencer that I could use to make noise when I'm not in the studio plugged into my other gear. This is more than I want to take on while I am still working on the sequencer.

Thanks for everyone's input!

...although, the GBA setup sounds interesting.


Top
 Profile  
 
PostPosted: Mon Feb 10, 2014 10:59 pm 
Offline

Joined: Sun Apr 13, 2008 11:12 am
Posts: 6503
Location: Seattle
MoZI wrote:
I actually found a really simple stripped down Arduino project that uses [an AY-8910] instead.
There are a large suite of other sound-making ICs, in case any of them are any easier to interface or program or more fun:
wikipedia links: various Yamaha parts, incomplete list of other sound ICs


Top
 Profile  
 
PostPosted: Tue Feb 11, 2014 8:07 am 
Offline

Joined: Mon Feb 10, 2014 10:37 am
Posts: 5
That's a great list. I had looked at a few of the other chips on there like the YMF282, which I still want to do, but it looked like it would have been too much to figure out. I had initially thought the GameBoy would be easier since it could only do a few things, but the AY-3-8910 seems like the one to start with. The manual is super nice. It's like "Hello friend. We're glad your here. You are really going to like using the AY38910. Here's how to do everything you want to do."


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ] 

All times are UTC - 7 hours


Who is online

Users browsing this forum: No registered users and 2 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
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group