Change file addresses to u64.
This commit is contained in:
parent
cb93ab20ee
commit
189afa26ba
|
@ -35,12 +35,12 @@ pub trait Block: fmt::Debug {
|
||||||
|
|
||||||
pub struct BlockInfo {
|
pub struct BlockInfo {
|
||||||
pub block_type: BlockType,
|
pub block_type: BlockType,
|
||||||
pub start_address: u32,
|
pub start_address: u64,
|
||||||
pub end_address: u32,
|
pub end_address: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BlockInfo {
|
impl BlockInfo {
|
||||||
pub fn get_size(&self) -> u32 {
|
pub fn get_size(&self) -> u64 {
|
||||||
self.end_address - self.start_address
|
self.end_address - self.start_address
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -60,7 +60,7 @@ impl Terminator {
|
||||||
block_type: BlockType::Terminator,
|
block_type: BlockType::Terminator,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn from_stream(_fp: &mut File, start_address: u32, end_address: u32) -> Self {
|
pub fn from_stream(_file: &mut File, start_address: u64, end_address: u64) -> Self {
|
||||||
Self {
|
Self {
|
||||||
info: Some(BlockInfo {
|
info: Some(BlockInfo {
|
||||||
block_type: BlockType::Terminator,
|
block_type: BlockType::Terminator,
|
||||||
|
@ -108,13 +108,13 @@ impl SoundData {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_stream(fp: &mut File, start_address: u32, end_address: u32) -> Self {
|
pub fn from_stream(file: &mut File, start_address: u64, end_address: u64) -> Self {
|
||||||
let mut frequency_divisor_buffer: [u8; 1] = [0];
|
let mut frequency_divisor_buffer: [u8; 1] = [0];
|
||||||
drop(fp.read(&mut frequency_divisor_buffer));
|
file.read_exact(&mut frequency_divisor_buffer).unwrap();
|
||||||
let sample_rate: u32 = 1000000u32 / (256u32 - frequency_divisor_buffer[0] as u32);
|
let sample_rate: u32 = 1000000u32 / (256u32 - frequency_divisor_buffer[0] as u32);
|
||||||
|
|
||||||
let mut codec_buffer: [u8; 1] = [0];
|
let mut codec_buffer: [u8; 1] = [0];
|
||||||
drop(fp.read(&mut codec_buffer));
|
file.read_exact(&mut codec_buffer).unwrap();
|
||||||
let codec = match codec_buffer[0] {
|
let codec = match codec_buffer[0] {
|
||||||
0 => Codec::Pcm8BitUnsigned,
|
0 => Codec::Pcm8BitUnsigned,
|
||||||
1 => Codec::Adpcm4to8,
|
1 => Codec::Adpcm4to8,
|
||||||
|
@ -127,9 +127,9 @@ impl SoundData {
|
||||||
_ => panic!("Bad Sound format. Got {}", codec_buffer[0]),
|
_ => panic!("Bad Sound format. Got {}", codec_buffer[0]),
|
||||||
};
|
};
|
||||||
|
|
||||||
let address = fp.stream_position().unwrap() as u32;
|
let address = file.stream_position().unwrap();
|
||||||
let mut data: Vec<u8> = vec![0; (end_address - address) as usize];
|
let mut data: Vec<u8> = vec![0; (end_address - address) as usize];
|
||||||
drop(fp.read(&mut data));
|
file.read_exact(&mut data).unwrap();
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
info: Some(BlockInfo {
|
info: Some(BlockInfo {
|
||||||
|
@ -194,10 +194,10 @@ impl SoundDataContinuation {
|
||||||
data,
|
data,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn from_stream(fp: &mut File, start_address: u32, end_address: u32) -> Self {
|
pub fn from_stream(file: &mut File, start_address: u64, end_address: u64) -> Self {
|
||||||
let address = fp.stream_position().unwrap() as u32;
|
let address = file.stream_position().unwrap();
|
||||||
let mut data: Vec<u8> = vec![0; (end_address - address) as usize];
|
let mut data: Vec<u8> = vec![0; (end_address - address) as usize];
|
||||||
drop(fp.read(&mut data));
|
file.read_exact(&mut data).unwrap();
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
info: Some(BlockInfo {
|
info: Some(BlockInfo {
|
||||||
|
@ -255,13 +255,13 @@ impl Silence {
|
||||||
sample_rate,
|
sample_rate,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn from_stream(fp: &mut File, start_address: u32, end_address: u32) -> Self {
|
pub fn from_stream(file: &mut File, start_address: u64, end_address: u64) -> Self {
|
||||||
let mut length_buffer: [u8; 2] = [0; 2];
|
let mut length_buffer: [u8; 2] = [0; 2];
|
||||||
drop(fp.read(&mut length_buffer));
|
file.read_exact(&mut length_buffer).unwrap();
|
||||||
let length = u16::from_le_bytes(length_buffer) + 1;
|
let length = u16::from_le_bytes(length_buffer) + 1;
|
||||||
|
|
||||||
let mut frequency_divisor_buffer: [u8; 1] = [0];
|
let mut frequency_divisor_buffer: [u8; 1] = [0];
|
||||||
drop(fp.read(&mut frequency_divisor_buffer));
|
file.read_exact(&mut frequency_divisor_buffer).unwrap();
|
||||||
let sample_rate: u32 = 1000000u32 / (256u32 - frequency_divisor_buffer[0] as u32);
|
let sample_rate: u32 = 1000000u32 / (256u32 - frequency_divisor_buffer[0] as u32);
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
|
@ -325,9 +325,9 @@ impl Marker {
|
||||||
value,
|
value,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn from_stream(fp: &mut File, start_address: u32, end_address: u32) -> Self {
|
pub fn from_stream(file: &mut File, start_address: u64, end_address: u64) -> Self {
|
||||||
let mut value_buffer: [u8; 2] = [0; 2];
|
let mut value_buffer: [u8; 2] = [0; 2];
|
||||||
drop(fp.read(&mut value_buffer));
|
file.read_exact(&mut value_buffer).unwrap();
|
||||||
let value = u16::from_le_bytes(value_buffer);
|
let value = u16::from_le_bytes(value_buffer);
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
|
@ -387,10 +387,10 @@ impl Text {
|
||||||
data,
|
data,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn from_stream(fp: &mut File, start_address: u32, end_address: u32) -> Self {
|
pub fn from_stream(file: &mut File, start_address: u64, end_address: u64) -> Self {
|
||||||
let address = fp.stream_position().unwrap() as u32;
|
let address = file.stream_position().unwrap();
|
||||||
let mut data: Vec<u8> = vec![0; (end_address - address) as usize];
|
let mut data: Vec<u8> = vec![0; (end_address - address) as usize];
|
||||||
drop(fp.read(&mut data));
|
file.read_exact(&mut data).unwrap();
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
info: Some(BlockInfo {
|
info: Some(BlockInfo {
|
||||||
|
@ -448,9 +448,9 @@ impl RepeatStart {
|
||||||
count,
|
count,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn from_stream(fp: &mut File, start_address: u32, end_address: u32) -> Self {
|
pub fn from_stream(file: &mut File, start_address: u64, end_address: u64) -> Self {
|
||||||
let mut count_buffer: [u8; 2] = [0; 2];
|
let mut count_buffer: [u8; 2] = [0; 2];
|
||||||
drop(fp.read(&mut count_buffer));
|
file.read_exact(&mut count_buffer).unwrap();
|
||||||
let count = u16::from_le_bytes(count_buffer) + 1;
|
let count = u16::from_le_bytes(count_buffer) + 1;
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
|
@ -509,7 +509,7 @@ impl RepeatEnd {
|
||||||
block_type: BlockType::RepeatEnd,
|
block_type: BlockType::RepeatEnd,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn from_stream(_fp: &mut File, start_address: u32, end_address: u32) -> Self {
|
pub fn from_stream(_file: &mut File, start_address: u64, end_address: u64) -> Self {
|
||||||
Self {
|
Self {
|
||||||
info: Some(BlockInfo {
|
info: Some(BlockInfo {
|
||||||
block_type: BlockType::RepeatEnd,
|
block_type: BlockType::RepeatEnd,
|
||||||
|
|
|
@ -64,7 +64,7 @@ impl VocFile {
|
||||||
};
|
};
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
let block_start_address = file.stream_position().unwrap() as u32;
|
let block_start_address = file.stream_position().unwrap();
|
||||||
|
|
||||||
// Block Type
|
// Block Type
|
||||||
let mut block_type_buffer: [u8; 1] = [0];
|
let mut block_type_buffer: [u8; 1] = [0];
|
||||||
|
@ -95,8 +95,8 @@ impl VocFile {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let current_address = file.stream_position().unwrap() as u32;
|
let current_address = file.stream_position().unwrap();
|
||||||
let block_end_address = current_address + block_size;
|
let block_end_address = current_address + block_size as u64;
|
||||||
|
|
||||||
let block: Box<dyn Block> = match block_type {
|
let block: Box<dyn Block> = match block_type {
|
||||||
BlockType::Terminator => Box::new(Terminator::from_stream(
|
BlockType::Terminator => Box::new(Terminator::from_stream(
|
||||||
|
|
Loading…
Reference in New Issue