nba-emu / NanoBoyAdvance

A cycle-accurate Nintendo Game Boy Advance emulator.
GNU General Public License v3.0
955 stars 53 forks source link

"zombie mode" does exist on the gba #364

Open ITotalJustice opened 4 months ago

ITotalJustice commented 4 months ago

APU: remove "Zombie" mode emulation (does not appear to exist on GBA) I don't have a test rom for this, however i know of at least 1 game that relies on zombie mode, that game being Prehistorik Man (which is pretty much a test rom :p).

during the intro (both of them), both square channels will have a volume of 15, along with left/right volume of 8 (7 + 1). the game then writes to envelope which causes the volume to be incremented, so volume is now 16, which gets masked down to 0.

i have tested this on my gba sp, the square channels are silenced as they overflow to 0. not sure the exact way this works, but according to the wiki, this behaviour is true across all systems:

fun env_write() {
  if (channel enabled) {
    if (old_period == 0 && !old_mode) {
      volume++;
    }
    volume &= 0xF;
  }
}

i am not sure the exact way in which zombie mode works. implementing it how the wiki describes (which is for dmg) breaks metroid zero intro when the ship lands.

ITotalJustice commented 4 months ago

here's metroid zero mission with the bug i described when using the code above:

how it should sound:

https://github.com/nba-emu/NanoBoyAdvance/assets/47043333/f3afcff2-cf6c-4118-b785-035f096b45c6

how it sounds with zombie mode:

https://github.com/nba-emu/NanoBoyAdvance/assets/47043333/045cc5c1-eff0-419f-bb1c-ffd79db1f0ff

so while it does exist, it's not exactly as it's implemented above (or on the wiki) for the gba...

fleroviux commented 4 months ago

So, as I understand this only proves that "Zombie" mode exists in GBC mode on GBA (SP), right? It is very possible that GBA mode doesn't actually use the same set of PSGs as CGB mode but rather a reimplementation.

fleroviux commented 4 months ago

To be clear: this is the issue that prompted my removal of "Zombie" mode emulation: https://github.com/nba-emu/NanoBoyAdvance/issues/335

But I haven't done any dedicated/extra testing to figure out if it actually exists in any capacity.

ITotalJustice commented 4 months ago

i managed to get zombie mode to happen on my gba in gba mode. sadly i can't make sense of the audio output as it's not consistent. It does play in a loop of sorts, it repeats every 8(?) seconds, with the last 5-8 seconds being the same output (volume = 15).

i've tried a few other methods of triggering zombie mode, but i've only been successful in changing the mode to trigger it

/*
test: write to env with period = 0, mode alternating
hw: volume changes!
*/

#include <tonc.h>

enum {
    ENVELOPE_SUB = 0 << 11,
    ENVELOPE_ADD = 1 << 11,
};

int main(void) {
    irq_init(NULL);
    irq_enable(II_VBLANK);

    REG_SNDSTAT = SSTAT_ENABLE;
    REG_SNDDSCNT = SDS_DMG100;
    REG_SNDDMGCNT = SDMG_LVOL(7) | SDMG_RVOL(7) | SDMG_LSQR1 | SDMG_RSQR1;

    int mode = ENVELOPE_ADD;
    REG_SND1CNT = (15 << 12) | mode | (0 << 8);
    REG_SND1FREQ = SFREQ_RESET | SFREQ_RATE(416);

    int wait = 60;
    while (1) {
        if (--wait == 0) {
            mode = mode == ENVELOPE_ADD ? ENVELOPE_SUB : ENVELOPE_ADD;
            REG_SND1CNT = (15 << 12) | mode | (0 << 8);
            wait = 60;
        }
        VBlankIntrWait();
    }
}

beep_overflow.zip