Skip to content

Commit

Permalink
fix: only enable sound for sm83 consoles
Browse files Browse the repository at this point in the history
  • Loading branch information
Dabolus committed Dec 14, 2022
1 parent edcb135 commit 36ab9ec
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/helpers/sound.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <gbdk/platform.h>

void sound_init() {
#ifdef NINTENDO
// NOTE: these registers must be in this specific order!
// 1000 0000 in binary: turns on sound
NR52_REG = 0x80;
Expand All @@ -15,51 +16,64 @@ void sound_init() {
// (1 bit for L and 1 for R), so we are telling the GB to
// enable every channel on both L and R
NR51_REG = 0xFF;
#endif
}

void sound_start() {
#ifdef NINTENDO
NR10_REG = 0x00;
NR11_REG = 0xC2;
NR12_REG = 0xF4;
NR13_REG = 0xB0;
NR14_REG = 0x86;
#endif
}

void sound_enter() {
#ifdef NINTENDO
NR10_REG = 0x00;
NR11_REG = 0x80;
NR12_REG = 0x63;
NR13_REG = 0x73;
NR14_REG = 0x86;
#endif
}

void sound_switch() {
#ifdef NINTENDO
NR41_REG = 0x00;
NR42_REG = 0x37;
NR43_REG = 0x70;
NR44_REG = 0x80;
#endif
}

void sound_scroll(uint8_t len) {
#ifdef NINTENDO
NR41_REG = 0x00;
NR42_REG = 0x60 | len;
NR43_REG = 0x10;
NR44_REG = 0x80;
#endif
}

void sound_bounce() {
#ifdef NINTENDO
NR10_REG = 0x77;
NR11_REG = 0xC0;
NR12_REG = 0x83;
NR13_REG = 0x66;
NR14_REG = 0x86;
#endif
}

void sound_back() {
#ifdef NINTENDO
NR41_REG = 0x1F;
NR42_REG = 0xF1;
NR43_REG = 0x30;
NR44_REG = 0xC0;
#endif
}

#endif

0 comments on commit 36ab9ec

Please sign in to comment.