DMG-CPU-Inside icon indicating copy to clipboard operation
DMG-CPU-Inside copied to clipboard

APU CH1 and CH2 volume envelope only work when AOI_MUX_2 cells have output inverted

Open msinger opened this issue 2 years ago • 2 comments

I can't get the volume envelope function of APU channels 1&2 working without somehow inverting the clock that goes into the COUNT cells HEVO...HAFO (CH1) and FENA...FENO (CH2). They are counting in the wrong direction. I checked the schematic with the die shot and can't find any wrong connections that could cause that. So I think one of the following things must be the case:

  • AOI_MUX_2 has an inverter, changing it to AO_MUX_2 so to speak
  • COUNT has its outputs switched
  • COUNT triggers on opposite clock edge

When I modify the behavior of the COUNT cells in any way (or multiple ways at once), they are causing the APU to break everywhere else they are used. This is why I can only think of the AOI_MUX_2 cells being the culprit here. I haven't simulated everything yet, so I can't say if changing them to "AO without I" will break anything else.

It is also possible that silly me has a totally wrong understanding of the COUNT cells. I see them as flip-flops that toggle on a falling clock edge and can be asynchronously set to D whenever LOAD is high. At least this is how they work for me correctly in other places. Here's a truth table:

CLK     D   LOAD  |  COUT
--------------------------
 x      D    H    |   D     (async. load)
H->L    x    L    |  !COUT  (toggle)
L->H    x    L    |  COUT   (keep)
_
Q is always the inverse of COUT.

Please let me know if I misunderstood their function.

msinger avatar Nov 22 '21 21:11 msinger

Same goes for the volume envelope of CH4. It needs AO_MUX_2 cells instead of AOI_MUX_2 for FOLE...ELAF.

The two AOI_MUX_4 cells on the same page (page 20) also need to be AO_MUX_4 for the noise generator to work. I'll explain why. Please see #79 first, so you don't get confused about the labels. I tested channel 4 on a real DMG CPU B Gameboy and in a simulation with Icarus using the following register configuration and compared the sound that came out of it: FF26 <= 0x80 FF20 <= 0x00 FF21 <= 0xF3 FF25 <= 0xFF FF24 <= 0x77 FF22 <= 0x13 FF23 <= 0x80 (I wrote the registers in the given order.) This gives a nice white-ish sounding noise if you play that on a real Gameboy. If I play that in my simulation with ELYX and DARY being AOI cells, I can only hear a very subtle clicking, which is caused by a constant 1 showing up on the net CH4_BIT which gets decreased in volume over time by the envelope function. (The subtle clickings are the volume steps that are actually audible if there is nothing else playing.) The constant 1 on CH4_BIT is caused by ELYX not having any of its B inputs set when bits [6:4] in FF22 are set to 001. The same result happens when FF22 is set to something else, like 0x53 for example. In that case it is DARY that never gets a B input set and therefore always outputs a 1. So, CH4_BIT is always 1 when bit 7 of FF22 is not set, which blocks CH4 from generating any noise sound. If I change ELYX and DARY to be AO cells, then they are not blocking each other anymore and CH4_BIT can "randomly" flip between 0 and 1. The AOI_MUX_6 cell ETYR also doesn't work like it should. Though it has no partner that would block it, it produces wrong sounds compared to the original Gameboy when I implement it as an AOI cell. I set FF22 to 0xD8 to test that. With that setting only the subtle clickings of the volume envelope can be heard in the simulation output. If I change it to AO instead, I hear the same low frequency blubbering that I hear on a real Gameboy with these register settings.

Because of these tests I strongly believe that all the AOI_MUX_n cells are actually AO_MUX_n, becuase they all look the same. They have two rows between the last input and their output at the bottom. This could be enough space for the inverter which would make them AO.

msinger avatar Nov 24 '21 00:11 msinger

Also on page 20, the AOI_MUX_2 KAVU gives a different sound when changed to AO without I. I tested it with FF22 = 0x83. When KAVU is an AO it sounds much more like the original Gameboy.

msinger avatar Nov 24 '21 01:11 msinger