Concept for actually making VIN useful - "MBC-5B"

Discussion of programming and development for the original Game Boy and Game Boy Color.
User avatar
ImATrackMan
Posts: 37
Joined: Thu Mar 26, 2015 6:34 pm
Contact:

Concept for actually making VIN useful - "MBC-5B"

Post by ImATrackMan »

After some extremely crude fun messing around with LSDJ and enabling VIN to play Famicom expansion chips behind LSDJ tracks, I got to talking with B00daW and others to see about making an MBC5-compatible cart with an on-board sound chip that people could actually use. I don't have any hardware prototypes out and probably won't for a bit, mainly because I want to know if it's possible and need help getting it out of my head.

When I first mentioned it in a Discord server, someone mentioned possibly making a special version of their sound driver that was compatible with the new sound chip, the only thing they needed was for it to show up in a predictable memory location. Looking at these wiki'd Pan Docs pages, the area from $6000-7FFF isn't mentioned, so assuming it's not mirrored from $4000-5FFF (I honestly don't know), it could be used. Me being a massive Sunsoft 5B fanboy, I elected to try using the YMZ284 since it's bigger brothers are extremely well-known and documented (also where the tentative "MBC-5B" name comes from. I'm not aware of an actual B-revision of the MBC5 so it's perfect!). Taking from this, I looked at the 5B Audio page on the NESDev Wiki and saw that the 5B uses a space twice as large for its control on the Famicom, namely $C000-DFFF and $E000-FFFF. This is where my problem is.

The YMZ284 is a very straightforward chip to wire up, but for me not being SUPER into hardware, the addressing is a bit tricky. All the data lines are obvious, GB /WR can go to YMZ /WR (reads don't work on the YMZ anyway), /IC to RESET, and all that's left are Vcc/Vdd, OUT, /CS, and A0, the YMZ's sole addressing pin. These last two are my issue.

Image

1. Can the area from $6000-7FFF be used for this with the MBC5?
2. If it can, can the YMZ be controlled with $6000 (SN5B equivalent $C000) for Address Select, and $7000 for Address Write (SN5B equivalent $E000)?
3. How would the wiring for such a scheme be?

In my opinion, VIN is the last "well-known" Cool ThingTM about the GB that I don't think's been taken advantage of enough, or at all really. Implemented and used, yes, but not taken advantage of. Nanoloop 1.5's phase square and Mono's drum synth are cool and all, but not very practical or "useful" in my mind as 1.5's implementation is a simple extension of ONE hardware channel, Mono doesn't let you use the internal sound, and neither one can be used for anything other than their namesake program's purpose, simple 16-step loops. I hope this concept can reach a stage where people can use it to its full potential. Since the aim is to be MBC5-compatible (first by using a real MBC5), it can be used as-is, but if someone wants to make a homebrew program to take advantage of 3 new channels, the option will be there too. Thank you in advance for any help.
lidnariq
Posts: 11429
Joined: Sun Apr 13, 2008 11:12 am

Re: Concept for actually making VIN useful - "MBC-5B"

Post by lidnariq »

ImATrackMan wrote:1. Can the area from $6000-7FFF be used for this with the MBC5?
Don't know. Certainly what documentation we have insinuates writes to that region has no effect...
2. If it can, can the YMZ be controlled with $6000 (SN5B equivalent $C000) for Address Select, and $7000 for Address Write (SN5B equivalent $E000)?
Sure? Connect YMZ A0 to DMG A12, in that case.
3. How would the wiring for such a scheme be?
You need to decode when /WR is low, and A15,14,13 are '011'. The YMZ284/294 has two separate enables that both have to be low; other parts (e.g. AY-3-8910) do something else.

Regardless, you could use a 74'138 or 74'139 to generate the signals needed for any of these parts.

https://wiki.nesdev.com/w/index.php/74138
(Try gnd74HC138./G2[A,B], +5V74HC138.+G1, A[15,14,13]74HC138.S[2,1,0], 74HC138./Y3YMZ./CS, A12YMZ A0, DMG/WRYMZ /WR. You'll want something different if you're starting with a AY-3-8910.)

You might need extra analog hardware before the VIN pin.
In my opinion, VIN is the last "well-known" Cool ThingTM about the GB that I don't think's been taken advantage of enough, or at all really. Implemented and used, yes, but not taken advantage of.
I was under the impression that there was significant model-to-model behavior differences on the VIN pin. I guess there's what he reported himself on the Nanoloop mono. But ... I guess you can still technically get audio out of it, regardless.

(On a wild tangent: I kinda want to know how the Nanoloop Mono's analog synth works, but...)
User avatar
ImATrackMan
Posts: 37
Joined: Thu Mar 26, 2015 6:34 pm
Contact:

Re: Concept for actually making VIN useful - "MBC-5B"

Post by ImATrackMan »

The YMZ284/294 has two separate enables that both have to be low; other parts (e.g. AY-3-8910) do something else.
The other enables are /WR and /CS, both have to remain low. A0 being high selects the register, while it being low writes the data.
(Try gnd74HC138./G2[A,B], +5V74HC138.+G1, A[15,14,13]74HC138.S[2,1,0], 74HC138./Y3YMZ./CS, A12YMZ A0, DMG/WRYMZ /WR. You'll want something different if you're starting with a AY-3-8910.)
Will do. AY isn't my starting point, I have 2 294s already. Thank you so much.
User avatar
za909
Posts: 248
Joined: Fri Jan 24, 2014 9:05 am
Location: Mijn hart woont al in Nederland

Re: Concept for actually making VIN useful - "MBC-5B"

Post by za909 »

If you want easy wiring the SN76489 could also be useful, you only need one register for it (some bits of the data written determine which channel receives the lower bits and whether it's a volume or period register write)
lidnariq
Posts: 11429
Joined: Sun Apr 13, 2008 11:12 am

Re: Concept for actually making VIN useful - "MBC-5B"

Post by lidnariq »

The SN76494 theoretically requires its inputs be stable for up to 32 cycles (of the 4MHz master clock). Not hard, but it does require an extra latch.
User avatar
ImATrackMan
Posts: 37
Joined: Thu Mar 26, 2015 6:34 pm
Contact:

Re: Concept for actually making VIN useful - "MBC-5B"

Post by ImATrackMan »

Image

Well, here goes the first proto. This is meant to plug in between the GB itself and a flash cartridge. I don't know if splitting the lines like this and making them this much longer than they need to be will cause any issues.

Also, I have no idea if this will work at all! No way to know what's wrong if the test ROM doesn't do anything.
User avatar
Jeroen
Posts: 1048
Joined: Tue Jul 03, 2007 1:49 pm

Re: Concept for actually making VIN useful - "MBC-5B"

Post by Jeroen »

If CR1 is a resonator, you're grounding out one pin. It won't work that way.
User avatar
kevtris
Posts: 504
Joined: Sat Oct 29, 2005 2:09 am
Location: Indianapolis
Contact:

Re: Concept for actually making VIN useful - "MBC-5B"

Post by kevtris »

ImATrackMan wrote:Image

Well, here goes the first proto. This is meant to plug in between the GB itself and a flash cartridge. I don't know if splitting the lines like this and making them this much longer than they need to be will cause any issues.

Also, I have no idea if this will work at all! No way to know what's wrong if the test ROM doesn't do anything.

Not to pop your bubble but you need to make some changes to that to make it work. The chip requires a clock to run. It can probably use the GB's own clock or you can provide an oscillator. The way it's wired now to what I assume is a 3 terminal resonator will not work. The middle terminal is ground, and the outside 2 terminals need to be connected to some kind of amplifier (usually an inverter inside a chip). The sound chip you are using however cannot run that resonator.

A 4 pin crystal oscillator will work, but I suggest using the GB's clock which eliminates the need. It will run a bit slower, around 1MHzish but it will still work. Just run CLK to pin 7. The schematic I saw shows 2MHz, so the GB clock should be fine; this will give you more low end range anyways.

Also, you need bypass capacitors, 0.1uf caps across each chip (though a single one is probably OK).

As for routing, it'd probably be a lot simpler if you ran all the "passthrough" signals on the bottom layer, straight from the cart edge to the socket, then did all the other routing on the top only (or minimal bottom use for vertical connections). It should be relatively easy to do this.

Might wanna bump the size of the power/ground routes up too. Say 20-25 mils for those. Signals can be 6-8 mils depending on the board fab you're using.

The audio might be another issue too. It appears you need a 4.7K resistor to ground to load the audio output, otherwise it will probably be silent or at least very very quiet. A coupling capacitor is needed too. I suggest a 1uf between the output and the GB input for starters.

Hope that helps.
/* this is a comment */
User avatar
ImATrackMan
Posts: 37
Joined: Thu Mar 26, 2015 6:34 pm
Contact:

Re: Concept for actually making VIN useful - "MBC-5B"

Post by ImATrackMan »

kevtris wrote:
Not to pop your bubble but you need to make some changes to that to make it work.
Absolutely not popping any bubbles, that's the whole reason for me posting that screenshot, and people popping in and offering their input, you especially, is even more motivation to get this done. I'll make some of those changes tonight when I get home.
kevtris wrote:
A 4 pin crystal oscillator will work, but I suggest using the GB's clock which eliminates the need. It will run a bit slower, around 1MHzish but it will still work. Just run CLK to pin 7. The schematic I saw shows 2MHz, so the GB clock should be fine; this will give you more low end range anyways.
Rationale for the external clock is that the YMZ, like the 5B inspiring this, also has a permanent 1/2 clock divider. Connecting it to CLK would certainly give me more low end, but I think .5 mHz is a little too much. That plus the fact that AY/YM at 1.79 mHz is already familiar to people makes it a good choice in my opinion.
lidnariq
Posts: 11429
Joined: Sun Apr 13, 2008 11:12 am

Re: Concept for actually making VIN useful - "MBC-5B"

Post by lidnariq »

Here's two quick-and-dirty crystal drivers I've used. You'll almost certainly get more reliable results from using one of the 4 pin oscillator-in-a-cans, though.
osc-4part-pierce.png
osc-4part-pierce.png (390 Bytes) Viewed 7334 times
osc-4part-colpitts.png
osc-4part-colpitts.png (412 Bytes) Viewed 7334 times
A much sillier option would be to take advantage that the clock on the gameboy's clock edge is a square wave. Then you could use a resonant highpass filter (e.g. inductory and capacitor or crystal and resistor) to extract the 3x harmonic. (Set 1/(2·π·sqrt(L·C)) = 3.072MHz)


In a ridiculous way, I've wanted to add a user-programmable prescaler to the clock input of these old sound ICs. It'd be nice to be able to switch between having a high enough clock frequency to actually use envelope bass ... and then to switch back such that you could get useful bass notes out of the ordinary square wave channels. (Obviously not at the same time)
User avatar
mikejmoffitt
Posts: 1353
Joined: Sun May 27, 2012 8:43 pm

Re: Concept for actually making VIN useful - "MBC-5B"

Post by mikejmoffitt »

ImATrackMan wrote:
kevtris wrote:
Not to pop your bubble but you need to make some changes to that to make it work.
Absolutely not popping any bubbles, that's the whole reason for me posting that screenshot, and people popping in and offering their input, you especially, is even more motivation to get this done. I'll make some of those changes tonight when I get home.
kevtris wrote:
A 4 pin crystal oscillator will work, but I suggest using the GB's clock which eliminates the need. It will run a bit slower, around 1MHzish but it will still work. Just run CLK to pin 7. The schematic I saw shows 2MHz, so the GB clock should be fine; this will give you more low end range anyways.
Rationale for the external clock is that the YMZ, like the 5B inspiring this, also has a permanent 1/2 clock divider. Connecting it to CLK would certainly give me more low end, but I think .5 mHz is a little too much. That plus the fact that AY/YM at 1.79 mHz is already familiar to people makes it a good choice in my opinion.
The clock being "Familiar" to people is a poor justification IMO. Keeping it in the same clock domain as the GB will make it simpler to program as well, since all these square wave-based sound chips are just period counters.
lidnariq
Posts: 11429
Joined: Sun Apr 13, 2008 11:12 am

Re: Concept for actually making VIN useful - "MBC-5B"

Post by lidnariq »

mikejmoffitt wrote:The clock being "Familiar" to people is a poor justification IMO. Keeping it in the same clock domain as the GB will make it simpler to program as well, since all these square wave-based sound chips are just period counters.
To rephrase, on the off chance that it's insufficiently clear, using the same clock (or a power of two multiple) means that you can use the same pitch table for the YMZ as well as the built-in channels.
User avatar
ImATrackMan
Posts: 37
Joined: Thu Mar 26, 2015 6:34 pm
Contact:

Re: Concept for actually making VIN useful - "MBC-5B"

Post by ImATrackMan »

A casual reminder that the YMZ will further divide CLK by two, resulting in it running at 1/8th of the internal clock. That, and as far as I'm aware, the GB has 11-bit pitch where the YMZ has 12-bit, so to get it where the pitch tables line up exactly, I have to clock it at half of the gameboy speed, which equates to using the full gameboy clock. For that, I could use the donor crystal from an actual GB, or an increasingly complicated multiplier circuit to make CLK 4 times as fast as it is. In any case, this is really just to see if it works at all, so at this stage, clock speed doesn't matter at all as long as it makes noise.

Edit:The ultimate goal is to put this into a flash cartridge. I'm going for as few parts as possible while maintaining a decent clock speed. Sure a flat 4.00000 is an option but then it'll be too "close enough" while still bring out of tune with the internal GB channels. I honestly think 3.58/1.79 is a good speed, especially when the frequency table is available in the source for arguably the most popular PC chiptune creation software there is, Famitracker, which is, incidentally, where the person who programmed the test ROM got it from.
lidnariq
Posts: 11429
Joined: Sun Apr 13, 2008 11:12 am

Re: Concept for actually making VIN useful - "MBC-5B"

Post by lidnariq »

ImATrackMan wrote:A casual reminder that the YMZ will further divide CLK by two, resulting in it running at 1/8th of the internal clock. That, and as far as I'm aware, the GB has 11-bit pitch where the YMZ has 12-bit, so to get it where the pitch tables line up exactly,
Musically, they don't need to. The reason I mentioned "any power of two" is because musically, each power of two is an octave and easy to compensate for. (After all, the NES's pulse and triangle channels differ by one octave.) Although being off by three octaves is a bit silly, it still gives some remaining headroom.

Admittedly, when the fastest divisor yields 16KiHz and any integer quotient of same, that is pretty cramped.

Ultimately, you can easily get 4 MiHz crystals or osillators, not just exact 4.000MHz ones.
User avatar
ImATrackMan
Posts: 37
Joined: Thu Mar 26, 2015 6:34 pm
Contact:

Re: Concept for actually making VIN useful - "MBC-5B"

Post by ImATrackMan »

[OLDER IMAGE]
Did some of the changes, namely went to an OSC, added the decoupling cap, and the resistor from VIN to ground. I also did a little rewiring but I don't think it made much difference. The width of the power traces was fine since I used .5mm (19.86 mils)
kevtris wrote:I suggest a 1uf between the output and the GB input for starters.
I forgot to ask if that was before or after the resistor. I assume after.
lidnariq wrote:Ultimately, you can easily get 4 MiHz crystals or osillators, not just exact 4.000MHz ones.
I found a nice one on Mouser in both 3.58 AND exactly 4.194304. They're non-stock though, so I'll have to wait a bit longer for them.

EDIT: I went ahead and added the cap. I also went and added some jumpers to the top area of the adapter near the cart slot.


Image

Image


Some flash carts use VIN as a /WR signal for the flash rom, and it seems that EMS cartridges are among those. As a result, they pull VIN to 5V, so these are there to accommodate any flash cart someone might be using to play around with this.
Post Reply