asdf more trial and error, getting closer... trying to treat WAVE_FREQ as write-only

This commit is contained in:
lif 2024-01-21 00:55:52 -08:00
parent 36c1e52e29
commit 0cc0f52463
4 changed files with 63689 additions and 50605 deletions

View file

@ -31,9 +31,8 @@ fn main() {
.collect(); .collect();
// gba psg has inverted wave channel polarity // gba psg has inverted wave channel polarity
for sample_pair in &mut bytes[0..*song_positions.iter().min().unwrap()] { for sample_pair in &mut bytes[0..*song_positions.iter().min().unwrap()] {
let upper = *sample_pair & 0xF0; // don't worry about carries, both nybbles are NYBBLE_MAX
let lower = *sample_pair & 0x0F; *sample_pair = 0xFF - *sample_pair;
*sample_pair = (0xF0 - upper) | (0x0F - lower);
} }
consts.add_array("LSDPACK_DATA", "u8", &bytes); consts.add_array("LSDPACK_DATA", "u8", &bytes);
consts.add_array("LSDPACK_SONG_POSITIONS", "usize", &song_positions); consts.add_array("LSDPACK_SONG_POSITIONS", "usize", &song_positions);

114175
lsdpack.s

File diff suppressed because it is too large Load diff

View file

@ -1,4 +1,7 @@
use core::{fmt::Write, ops::Add}; use core::{
fmt::Write,
ops::{Add, BitXorAssign},
};
use gba::prelude::*; use gba::prelude::*;
use voladdress::{Safe, VolAddress}; use voladdress::{Safe, VolAddress};
@ -104,6 +107,7 @@ pub struct Lsdpack {
repeat_cmd: Option<(LsdpackCmd, bool)>, repeat_cmd: Option<(LsdpackCmd, bool)>,
repeat_cmd_counter: usize, repeat_cmd_counter: usize,
sample_pitch: u16, sample_pitch: u16,
wave_bank_switch: bool,
stopped: bool, stopped: bool,
} }
@ -118,6 +122,7 @@ impl Lsdpack {
repeat_cmd_counter: 0, repeat_cmd_counter: 0,
sample_pitch: 0, sample_pitch: 0,
stopped: false, stopped: false,
wave_bank_switch: false,
} }
} }
@ -147,17 +152,28 @@ impl Lsdpack {
//let lrvol = LEFT_RIGHT_VOLUME.read(); //let lrvol = LEFT_RIGHT_VOLUME.read();
//LEFT_RIGHT_VOLUME.write(lrvol.with_wave_left(false).with_wave_right(false)); //LEFT_RIGHT_VOLUME.write(lrvol.with_wave_left(false).with_wave_right(false));
let wb = WAVE_BANK.read(); //let wb = WAVE_BANK.read();
//WAVE_BANK.write(WaveBank::new().with_enabled(false)); //WAVE_BANK.write(WaveBank::new().with_enabled(false));
/*
WAVE_BANK.write(
WaveBank::new()
.with_enabled(true)
.with_two_banks(false)
.with_bank1(wb.bank1()),
);
*/
/*
let wave_ram_ptr = (WAVE_RAM.as_mut_ptr() as *mut u8); let wave_ram_ptr = (WAVE_RAM.as_mut_ptr() as *mut u8);
for i in 0..16 { for i in 0..16 {
unsafe { unsafe {
wave_ram_ptr.add(i).write_volatile(self.data[ptr + i]); wave_ram_ptr.add(i).write_volatile(self.data[ptr + i]);
} }
} }
// */
/* //*
WAVE_RAM.index(0).write(u32::from_le_bytes( WAVE_RAM.index(0).write(u32::from_le_bytes(
TryFrom::try_from(&self.data[ptr..ptr + 4]).unwrap(), TryFrom::try_from(&self.data[ptr..ptr + 4]).unwrap(),
)); ));
@ -170,20 +186,26 @@ impl Lsdpack {
WAVE_RAM.index(3).write(u32::from_le_bytes( WAVE_RAM.index(3).write(u32::from_le_bytes(
TryFrom::try_from(&self.data[ptr + 12..ptr + 16]).unwrap(), TryFrom::try_from(&self.data[ptr + 12..ptr + 16]).unwrap(),
)); ));
*/ // */
self.wave_bank_switch ^= true;
//WAVE_BANK.write(WaveBank::new().with_enabled(true));
WAVE_BANK.write( WAVE_BANK.write(
WaveBank::new() WaveBank::new()
.with_enabled(true) .with_enabled(true)
.with_two_banks(false) .with_two_banks(false)
.with_bank1(!wb.bank1()), .with_bank1(self.wave_bank_switch),
); );
//WAVE_BANK.write(WaveBank::new().with_enabled(true));
// SOUND_ENABLED.write(sound_enabled); // SOUND_ENABLED.write(sound_enabled);
//LEFT_RIGHT_VOLUME.write(lrvol); //LEFT_RIGHT_VOLUME.write(lrvol);
unsafe { WAVE_FREQ.cast() }.write(self.sample_pitch); WAVE_FREQ.write(
WaveFrequency::new()
.with_enabled(true)
.with_length(self.sample_pitch & 0x7ff),
);
//unsafe { WAVE_FREQ.cast() }.write(self.sample_pitch);
//WAVE_FREQ.write(WaveFrequency::new().with_enabled(true).with_length(0x7e0));
} }
#[link_section = ".iwram"] #[link_section = ".iwram"]
@ -258,8 +280,16 @@ impl Lsdpack {
fn write_lsb<T>(&mut self, voladdr: VolAddress<T, Safe, Safe>) { fn write_lsb<T>(&mut self, voladdr: VolAddress<T, Safe, Safe>) {
let voladdr = unsafe { voladdr.cast::<u16>() }; let voladdr = unsafe { voladdr.cast::<u16>() };
//voladdr.write((voladdr.read() & 0xFF00) | (self.next_byte() as u16)); //voladdr.write((voladdr.read() & 0xFF00) | (self.next_byte() as u16));
let val = self.next_byte();
/*
if let Ok(mut logger) =
gba::mgba::MgbaBufferedLogger::try_new(gba::mgba::MgbaMessageLevel::Info)
{
writeln!(logger, "lsb: {}", val);
}
// */
unsafe { unsafe {
(voladdr.as_mut_ptr() as *mut u8).write_volatile(self.next_byte()); (voladdr.as_mut_ptr() as *mut u8).write_volatile(val);
} }
} }
@ -267,10 +297,16 @@ impl Lsdpack {
fn write_msb<T>(&mut self, voladdr: VolAddress<T, Safe, Safe>) { fn write_msb<T>(&mut self, voladdr: VolAddress<T, Safe, Safe>) {
let voladdr = unsafe { voladdr.cast::<u16>() }; let voladdr = unsafe { voladdr.cast::<u16>() };
//voladdr.write((voladdr.read() & 0xFF) | ((self.next_byte() as u16) << 8)); //voladdr.write((voladdr.read() & 0xFF) | ((self.next_byte() as u16) << 8));
let val = self.next_byte();
/*
if let Ok(mut logger) =
gba::mgba::MgbaBufferedLogger::try_new(gba::mgba::MgbaMessageLevel::Info)
{
writeln!(logger, "msb: {}", val);
}
// */
unsafe { unsafe {
(voladdr.as_mut_ptr() as *mut u8) (voladdr.as_mut_ptr() as *mut u8).add(1).write_volatile(val);
.add(1)
.write_volatile(self.next_byte());
} }
} }
@ -278,6 +314,13 @@ impl Lsdpack {
fn write_u16le<T>(&mut self, voladdr: VolAddress<T, Safe, Safe>) { fn write_u16le<T>(&mut self, voladdr: VolAddress<T, Safe, Safe>) {
let voladdr = unsafe { voladdr.cast::<u16>() }; let voladdr = unsafe { voladdr.cast::<u16>() };
let halfword = u16::from_le_bytes([self.next_byte(), self.next_byte()]); let halfword = u16::from_le_bytes([self.next_byte(), self.next_byte()]);
/*
if let Ok(mut logger) =
gba::mgba::MgbaBufferedLogger::try_new(gba::mgba::MgbaMessageLevel::Info)
{
writeln!(logger, "u16le: {}", halfword);
}
// */
voladdr.write(halfword); voladdr.write(halfword);
} }
@ -372,7 +415,10 @@ impl Lsdpack {
} }
PitchPu0 => self.write_u16le(TONE1_FREQUENCY), PitchPu0 => self.write_u16le(TONE1_FREQUENCY),
PitchPu1 => self.write_u16le(TONE2_FREQUENCY), PitchPu1 => self.write_u16le(TONE2_FREQUENCY),
PitchWav => self.write_u16le(WAVE_FREQ), PitchWav => {
self.sample_pitch = u16::from_le_bytes([self.next_byte(), self.next_byte()]);
unsafe { WAVE_FREQ.cast() }.write(self.sample_pitch);
}
SampleNext => self.write_next_samples(), SampleNext => self.write_next_samples(),
// general register writes: // general register writes:
@ -389,15 +435,41 @@ impl Lsdpack {
} //self.write_msb(TONE2_PATTERN), } //self.write_msb(TONE2_PATTERN),
Pu1PitchLsb => self.write_lsb(TONE2_FREQUENCY), Pu1PitchLsb => self.write_lsb(TONE2_FREQUENCY),
Pu1PitchMsb => self.write_msb(TONE2_FREQUENCY), Pu1PitchMsb => self.write_msb(TONE2_FREQUENCY),
//WavOnOff => unsafe { WAVE_BANK.cast() }.write(self.next_byte()), WavOnOff => {
WavOnOff => WAVE_BANK.write( let val = self.next_byte();
WaveBank::new().with_enabled(self.next_byte() != 0), //.with_two_banks(true) self.wave_bank_switch = val & 0x40 != 0;
//.with_bank1(false), unsafe { WAVE_BANK.cast() }.write(val);
), }
/*
WavOnOff => {
let val = self.next_byte();
if val == 0 {
WAVE_LEN_VOLUME.write(WaveLenVolume::new().with_volume(0))
} else {
panic!("perish")
}
/*
WAVE_BANK.write(
WaveBank::new()
.with_enabled(self.next_byte() != 0)
.with_two_banks(true)
.with_bank1(false),
);
*/
}
*/
WavLength => self.write_lsb(WAVE_LEN_VOLUME), WavLength => self.write_lsb(WAVE_LEN_VOLUME),
WavEnv => self.write_msb(WAVE_LEN_VOLUME), WavEnv => self.write_msb(WAVE_LEN_VOLUME),
WavPitchLsb => self.write_lsb(WAVE_FREQ), WavPitchLsb => {
WavPitchMsb => self.write_msb(WAVE_FREQ), self.sample_pitch &= 0xff00;
self.sample_pitch |= self.next_byte() as u16;
unsafe { WAVE_FREQ.cast() }.write(self.sample_pitch);
}
WavPitchMsb => {
self.sample_pitch &= 0xff;
self.sample_pitch |= (self.next_byte() as u16) << 8;
unsafe { WAVE_FREQ.cast() }.write(self.sample_pitch);
}
NoiLength => self.write_lsb(NOISE_LEN_ENV), NoiLength => self.write_lsb(NOISE_LEN_ENV),
NoiEnv => { NoiEnv => {
self.next_byte(); self.next_byte();

View file

@ -86,7 +86,7 @@ extern "C" fn main() -> ! {
IME.write(true); IME.write(true);
//TIMER0_RELOAD.write((((16777216 / 1) / 360) as u16).wrapping_neg()); //TIMER0_RELOAD.write((((16777216 / 1) / 360) as u16).wrapping_neg());
TIMER0_RELOAD.write((((280896 / 1) / 6) as u16).wrapping_neg()); TIMER0_RELOAD.write((((280896 / 1) / 12) as u16).wrapping_neg());
TIMER0_CONTROL.write( TIMER0_CONTROL.write(
TimerControl::new() TimerControl::new()
.with_overflow_irq(true) .with_overflow_irq(true)