Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions core/src/mmc/mapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,5 @@ pub trait Mapper: Send {
fn needs_bios(&self) -> bool {return false;}
fn load_bios(&mut self, _: Vec<u8>) {}
fn switch_disk(&mut self, _: usize) {}
fn vrc7_set_patches(&mut self, _patches: &[u8]) {}
}
4 changes: 4 additions & 0 deletions core/src/mmc/nsf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1402,4 +1402,8 @@ impl Mapper for NsfMapper {
fn audio_multiplexing(&mut self, emulate: bool) {
self.n163_expansion_audio_chip.emulate_multiplexing = emulate;
}

fn vrc7_set_patches(&mut self, patches: &[u8]) {
self.vrc7_audio.set_patches(patches);
}
}
25 changes: 19 additions & 6 deletions core/src/mmc/vrc7.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// https://www.nesdev.org/wiki/VRC7
// https://www.nesdev.org/wiki/VRC7_audio

use std::convert::TryInto;

use ines::INesCartridge;
use memoryblock::MemoryBlock;

Expand Down Expand Up @@ -295,6 +297,10 @@ impl Mapper for Vrc7 {
fn record_expansion_audio_output(&mut self, _nes_sample: f32) {
self.audio.record_output();
}

fn vrc7_set_patches(&mut self, patches: &[u8]) {
self.audio.set_patches(patches);
}
}

// TODO: explore and see if we can't somehow make these constant while keeping them
Expand Down Expand Up @@ -917,6 +923,7 @@ impl Vrc7AudioChannel {

pub struct Vrc7Audio {
pub custom_patch: [u8; 8],
pub patches: [u8; 8 * 15],
pub channel1: Vrc7AudioChannel,
pub channel2: Vrc7AudioChannel,
pub channel3: Vrc7AudioChannel,
Expand All @@ -931,6 +938,7 @@ impl Vrc7Audio {
pub fn new() -> Vrc7Audio {
let thing = Vrc7Audio {
custom_patch: [0u8; 8],
patches: DEFAULT_PATCH_TABLE,
channel1: Vrc7AudioChannel::new(1),
channel2: Vrc7AudioChannel::new(2),
channel3: Vrc7AudioChannel::new(3),
Expand Down Expand Up @@ -1070,7 +1078,7 @@ impl Vrc7Audio {
self.channel1.load_patch(&self.custom_patch);
} else {
let patch_index = ((self.channel1.instrument_index - 1) * 8) as usize;
self.channel1.load_patch(&DEFAULT_PATCH_TABLE[patch_index .. patch_index + 8]);
self.channel1.load_patch(&self.patches[patch_index .. patch_index + 8]);
}
},
0x31 => {
Expand All @@ -1080,7 +1088,7 @@ impl Vrc7Audio {
self.channel2.load_patch(&self.custom_patch);
} else {
let patch_index = ((self.channel2.instrument_index - 1) * 8) as usize;
self.channel2.load_patch(&DEFAULT_PATCH_TABLE[patch_index .. patch_index + 8]);
self.channel2.load_patch(&self.patches[patch_index .. patch_index + 8]);
}
},
0x32 => {
Expand All @@ -1090,7 +1098,7 @@ impl Vrc7Audio {
self.channel3.load_patch(&self.custom_patch);
} else {
let patch_index = ((self.channel3.instrument_index - 1) * 8) as usize;
self.channel3.load_patch(&DEFAULT_PATCH_TABLE[patch_index .. patch_index + 8]);
self.channel3.load_patch(&self.patches[patch_index .. patch_index + 8]);
}
},
0x33 => {
Expand All @@ -1100,7 +1108,7 @@ impl Vrc7Audio {
self.channel4.load_patch(&self.custom_patch);
} else {
let patch_index = ((self.channel4.instrument_index - 1) * 8) as usize;
self.channel4.load_patch(&DEFAULT_PATCH_TABLE[patch_index .. patch_index + 8]);
self.channel4.load_patch(&self.patches[patch_index .. patch_index + 8]);
}
},
0x34 => {
Expand All @@ -1110,7 +1118,7 @@ impl Vrc7Audio {
self.channel5.load_patch(&self.custom_patch);
} else {
let patch_index = ((self.channel5.instrument_index - 1) * 8) as usize;
self.channel5.load_patch(&DEFAULT_PATCH_TABLE[patch_index .. patch_index + 8]);
self.channel5.load_patch(&self.patches[patch_index .. patch_index + 8]);
}
},
0x35 => {
Expand All @@ -1120,7 +1128,7 @@ impl Vrc7Audio {
self.channel6.load_patch(&self.custom_patch);
} else {
let patch_index = ((self.channel6.instrument_index - 1) * 8) as usize;
self.channel6.load_patch(&DEFAULT_PATCH_TABLE[patch_index .. patch_index + 8]);
self.channel6.load_patch(&self.patches[patch_index .. patch_index + 8]);
}
},
_ => {}
Expand All @@ -1135,6 +1143,11 @@ impl Vrc7Audio {
self.channel5.record_current_output();
self.channel6.record_current_output();
}

pub fn set_patches(&mut self, patches: &[u8]) {
// This isn't going to be called during emulation, so no need to refresh.
self.patches = patches.try_into().unwrap_or(DEFAULT_PATCH_TABLE);
}
}

impl AudioChannelState for Vrc7AudioChannel {
Expand Down