Change file addresses to u64.

This commit is contained in:
Pedro de Oliveira 2023-04-23 01:18:19 +01:00
parent cb93ab20ee
commit 189afa26ba
2 changed files with 26 additions and 26 deletions

View File

@ -35,12 +35,12 @@ pub trait Block: fmt::Debug {
pub struct BlockInfo {
pub block_type: BlockType,
pub start_address: u32,
pub end_address: u32,
pub start_address: u64,
pub end_address: u64,
}
impl BlockInfo {
pub fn get_size(&self) -> u32 {
pub fn get_size(&self) -> u64 {
self.end_address - self.start_address
}
}
@ -60,7 +60,7 @@ impl 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 {
info: Some(BlockInfo {
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];
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 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] {
0 => Codec::Pcm8BitUnsigned,
1 => Codec::Adpcm4to8,
@ -127,9 +127,9 @@ impl SoundData {
_ => 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];
drop(fp.read(&mut data));
file.read_exact(&mut data).unwrap();
Self {
info: Some(BlockInfo {
@ -194,10 +194,10 @@ impl SoundDataContinuation {
data,
}
}
pub fn from_stream(fp: &mut File, start_address: u32, end_address: u32) -> Self {
let address = fp.stream_position().unwrap() as u32;
pub fn from_stream(file: &mut File, start_address: u64, end_address: u64) -> Self {
let address = file.stream_position().unwrap();
let mut data: Vec<u8> = vec![0; (end_address - address) as usize];
drop(fp.read(&mut data));
file.read_exact(&mut data).unwrap();
Self {
info: Some(BlockInfo {
@ -255,13 +255,13 @@ impl Silence {
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];
drop(fp.read(&mut length_buffer));
file.read_exact(&mut length_buffer).unwrap();
let length = u16::from_le_bytes(length_buffer) + 1;
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);
Self {
@ -325,9 +325,9 @@ impl Marker {
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];
drop(fp.read(&mut value_buffer));
file.read_exact(&mut value_buffer).unwrap();
let value = u16::from_le_bytes(value_buffer);
Self {
@ -387,10 +387,10 @@ impl Text {
data,
}
}
pub fn from_stream(fp: &mut File, start_address: u32, end_address: u32) -> Self {
let address = fp.stream_position().unwrap() as u32;
pub fn from_stream(file: &mut File, start_address: u64, end_address: u64) -> Self {
let address = file.stream_position().unwrap();
let mut data: Vec<u8> = vec![0; (end_address - address) as usize];
drop(fp.read(&mut data));
file.read_exact(&mut data).unwrap();
Self {
info: Some(BlockInfo {
@ -448,9 +448,9 @@ impl RepeatStart {
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];
drop(fp.read(&mut count_buffer));
file.read_exact(&mut count_buffer).unwrap();
let count = u16::from_le_bytes(count_buffer) + 1;
Self {
@ -509,7 +509,7 @@ impl 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 {
info: Some(BlockInfo {
block_type: BlockType::RepeatEnd,

View File

@ -64,7 +64,7 @@ impl VocFile {
};
loop {
let block_start_address = file.stream_position().unwrap() as u32;
let block_start_address = file.stream_position().unwrap();
// Block Type
let mut block_type_buffer: [u8; 1] = [0];
@ -95,8 +95,8 @@ impl VocFile {
}
};
let current_address = file.stream_position().unwrap() as u32;
let block_end_address = current_address + block_size;
let current_address = file.stream_position().unwrap();
let block_end_address = current_address + block_size as u64;
let block: Box<dyn Block> = match block_type {
BlockType::Terminator => Box::new(Terminator::from_stream(