Skip to content

Commit

Permalink
Intercept APU Reads instead of Writes
Browse files Browse the repository at this point in the history
Dunno why this didn't occur to me sooner
  • Loading branch information
GhostSonic21 committed Nov 9, 2018
1 parent b5f6287 commit 55b7303
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 18 deletions.
18 changes: 4 additions & 14 deletions MusicSilencer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ uint8 volumeFilter(uint8 data, uint16 addr) {

// Vanilla
if (musicStatus.engine == SMW_Vanilla && addr == 0x57) {
// Save volume
musicStatus.currentVolume = data;
if (musicStatus.disabled) {
// Find song and see if it's fine
uint8 songRead = S9xAPUGetByte(0x0006);
Expand All @@ -48,8 +46,6 @@ uint8 volumeFilter(uint8 data, uint16 addr) {
}
// MusicK
else if (musicStatus.engine == SMW_Musik && addr == 0x57) {
// Save volume
musicStatus.currentVolume = data;
// Find song and see if it's fine
if (musicStatus.disabled) {
uint8 songRead = S9xGetByteFree(0x1dfb);
Expand All @@ -71,26 +67,20 @@ void setMusicEngine(MusicEngine engine) {
}

bool toggleMusicDisable() {
musicStatus.disabled = !musicStatus.disabled;
// Turn off immediatley
if (musicStatus.engine != Disabled) {
musicStatus.disabled = !musicStatus.disabled;
if (musicStatus.disabled) {
// Resave the volume just in case
musicStatus.currentVolume = S9xAPUGetByte(0x57);
// Turn it off if applicable
S9xAPUSetByte(volumeFilter(musicStatus.currentVolume,0x57), 0x57);
// Message
S9xMessage(S9X_INFO, 0, "Music Disabled.");
S9xMessage(S9X_INFO, 0, "Music Disabled");
}
// Turn on immediatley
else {
S9xAPUSetByte(musicStatus.currentVolume, 0x57);
// Message
S9xMessage(S9X_INFO, 0, "Music Enabled.");
S9xMessage(S9X_INFO, 0, "Music Enabled");
}
}
else {
S9xMessage(S9X_INFO, 0, "Set The Music Engine First.");
S9xMessage(S9X_INFO, 0, "Set the Music Engine First");
}
return musicStatus.disabled;
}
Expand Down
1 change: 0 additions & 1 deletion MusicSilencer.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ enum MusicEngine {
struct MusicStatus {
MusicEngine engine = Disabled;
bool disabled = false;
uint8 currentVolume = 0;
};

void setMusicEngine(MusicEngine);
Expand Down
6 changes: 3 additions & 3 deletions apu/bapu/smp/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ uint8 SMP::op_read(uint16 addr) {
#endif
if((addr & 0xfff0) == 0x00f0) return mmio_read(addr);
if(addr >= 0xffc0 && status.iplrom_enable) return iplrom[addr & 0x3f];
// Filters out volume reads
if (volumeCallback != NULL)
return (*volumeCallback)(apuram[addr], addr);
return apuram[addr];
}

Expand All @@ -46,9 +49,6 @@ void SMP::op_write(uint16 addr, uint8 data) {
tick();
#endif
if((addr & 0xfff0) == 0x00f0) mmio_write(addr, data);
else if (addr < 0x00F0 && volumeCallback != NULL) {
data = (*volumeCallback)(data,addr);
}
apuram[addr] = data; //all writes go to RAM, even MMIO writes
}

Expand Down

0 comments on commit 55b7303

Please sign in to comment.