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

This is an archive of a topic from NESdev BBS, taken in mid-October 2019 before a server upgrade.
View original topic
Concept for actually making VIN useful - "MBC-5B"
by on (#198540)
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.
Re: Concept for actually making VIN useful - "MBC-5B"
by on (#198545)
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...

Quote:
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.

Quote:
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 gnd→74HC138./G2[A,B], +5V→74HC138.+G1, A[15,14,13]→74HC138.S[2,1,0], 74HC138./Y3→YMZ./CS, A12→YMZ A0, DMG/WR→YMZ /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.

Quote:
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...)
Re: Concept for actually making VIN useful - "MBC-5B"
by on (#198549)
Quote:
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.

Quote:
(Try gnd→74HC138./G2[A,B], +5V→74HC138.+G1, A[15,14,13]→74HC138.S[2,1,0], 74HC138./Y3→YMZ./CS, A12→YMZ A0, DMG/WR→YMZ /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.
Re: Concept for actually making VIN useful - "MBC-5B"
by on (#198557)
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)
Re: Concept for actually making VIN useful - "MBC-5B"
by on (#198559)
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.
Re: Concept for actually making VIN useful - "MBC-5B"
by on (#198622)
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.
Re: Concept for actually making VIN useful - "MBC-5B"
by on (#198661)
If CR1 is a resonator, you're grounding out one pin. It won't work that way.
Re: Concept for actually making VIN useful - "MBC-5B"
by on (#198662)
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.
Re: Concept for actually making VIN useful - "MBC-5B"
by on (#198670)
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.
Re: Concept for actually making VIN useful - "MBC-5B"
by on (#198675)
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.
Attachment:
osc-4part-pierce.png
osc-4part-pierce.png [ 390 Bytes | Viewed 3309 times ]
Attachment:
osc-4part-colpitts.png
osc-4part-colpitts.png [ 412 Bytes | Viewed 3309 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)
Re: Concept for actually making VIN useful - "MBC-5B"
by on (#198679)
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.
Re: Concept for actually making VIN useful - "MBC-5B"
by on (#198682)
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.
Re: Concept for actually making VIN useful - "MBC-5B"
by on (#198687)
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.
Re: Concept for actually making VIN useful - "MBC-5B"
by on (#198689)
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.
Re: Concept for actually making VIN useful - "MBC-5B"
by on (#198713)
[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.
Re: Concept for actually making VIN useful - "MBC-5B"
by on (#198735)
ImATrackMan wrote:
[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.


Yep after, just like that. looks a lot better. Make sure pin 1 of that oscillator isn't an enable input or anything. if it's NC I suggest connecting it to VCC because it's a positive output enable on a lot of models, but check the data sheets to be sure.
Re: Concept for actually making VIN useful - "MBC-5B"
by on (#198759)
kevtris wrote:
Yep after, just like that. looks a lot better. Make sure pin 1 of that oscillator isn't an enable input or anything. if it's NC I suggest connecting it to VCC because it's a positive output enable on a lot of models, but check the data sheets to be sure.


Okie dokie. I'll make the minor change of hooking it up to VCC, though the datasheet says it doesn't really need it because of an internal pullup. I made a major change to the design to remap the YMZ to $4400 and $4401 at the request of nitro2k01. A0 is now actually A0, and the 138's been wired from A10 to A15 so I hope that's right. I also made the minor addition of two spots to wire up some pots for bias/gain control, again at the request of nitro2k01. If everything's all clear, I'll order all the parts and boards when I'm next free.
Image
EDIT: And I just realized I connected Y0 to /CS instead of Y1. I keep forgetting the first pin is VCC and not an output pin.
Re: Concept for actually making VIN useful - "MBC-5B"
by on (#198762)
... But if you put the registers at $4400-$47FF, that'll overlap with the MBC register at $4000-$5FFF...
Re: Concept for actually making VIN useful - "MBC-5B"
by on (#198765)
lidnariq wrote:
... But if you put the registers at $4400-$47FF, that'll overlap with the MBC register at $4000-$5FFF...

According to Nitro:

Quote:
Writes to areas like 6000 could conflict with for example EMS's multi ROM functionality. I might personally put it in a MBC register space which has a well defined use, but where writing to it doesn't produce negative results. For example SRAM bank.

For example... 5-6 address bits would be enough to put it in the $48xx area. This would make writes to the sound chip safe (would only change the SRAM bank
which doesn't really matter) whereas actual SRAM bank select writes could be done to $4000

Me: [but] what sort of problems would this cause on the EMS multirom? If anything it seems like you'll just be sending the YMZ garbage
which would immediately stop as soon as you choose a game.
Quote:
The problem is the reverse. If you're trying to to write to the YMZ, the EMS might think it's a multi ROM request and map out the currently running ROM. Boom crash!


He then told me how to wire the 138 for $4400, I just followed the advice of someone much more experienced than I am.
Re: Concept for actually making VIN useful - "MBC-5B"
by on (#198770)
ImATrackMan wrote:
EDIT: And I just realized I connected Y0 to /CS instead of Y1. I keep forgetting the first pin is VCC and not an output pin.


If you are, ignore this comment. But if you're not using schematic capture to wire everything up first, I strongly recommend doing that on future projects. It'll help prevent silly mistakes.
Re: Concept for actually making VIN useful - "MBC-5B"
by on (#198875)
lidnariq wrote:
... But if you put the registers at $4400-$47FF, that'll overlap with the MBC register at $4000-$5FFF...

That is intentional. The point is to avoid for example $6000-$7FFF which may have different functionality on different flashcarts precisely because it's mostly unused otherwise. $4000-$4FFF on the other hand has a behavior that's both predictable between various cart hardware and mostly non-destructive. Yes, the SRAM bank register will be changed by writing to $4400, but this can easily be restored by writing the desired bank value to $4000 which will also not affect the sound chip.
Re: Concept for actually making VIN useful - "MBC-5B"
by on (#198890)
Doesn't the SRAM bank register also affect the ROM bank on some MBCs?
Re: Concept for actually making VIN useful - "MBC-5B"
by on (#198900)
tepples wrote:
Doesn't the SRAM bank register also affect the ROM bank on some MBCs?

It does, on MBC1. But again, this is still predictable behavior that can be easily recovered.
Re: Concept for actually making VIN useful - "MBC-5B"
by on (#198974)
I went ahead and got 10 boards and ordered the parts for five. If they work 100%, or reasonably well, I'll buy the parts to populate the other five boards and send them out to whoever wants to write something or just play around with them.