From c8542ddb61fd9738a87a1af49b03583cfd1b420e Mon Sep 17 00:00:00 2001 From: Jaby Date: Mon, 10 Oct 2022 22:06:11 +0200 Subject: [PATCH] Prepare for calculating LBAs --- src/Tools/psxcdgen_ex/src/main.rs | 10 ++++++---- src/Tools/psxcdgen_ex/src/types/lba_calculator.rs | 13 +++++++++++++ src/Tools/psxcdgen_ex/src/types/mod.rs | 13 +++++++++++++ 3 files changed, 32 insertions(+), 4 deletions(-) create mode 100644 src/Tools/psxcdgen_ex/src/types/lba_calculator.rs diff --git a/src/Tools/psxcdgen_ex/src/main.rs b/src/Tools/psxcdgen_ex/src/main.rs index ec51784e..d9a38722 100644 --- a/src/Tools/psxcdgen_ex/src/main.rs +++ b/src/Tools/psxcdgen_ex/src/main.rs @@ -23,6 +23,8 @@ fn populate() -> Result { desc.root.add_dir(folder); desc.root.add_file(file); desc.root.add_file(file2); + + desc.calculate_lbas(); Ok(desc) } @@ -31,10 +33,10 @@ fn run_main() -> Result<(), Error> { for element in desc.get_memory_layout().iter() { match element { - Layout::SystemArea(_) => println!("SystemArea:"), - Layout::PVD(_) => println!("PVD:"), - Layout::Directory{name, properties: _} => println!("Dir: {}", name), - Layout::File(file) => println!("File: {}", file), + Layout::SystemArea(_) => println!("SystemArea:"), + Layout::PVD(_) => println!("PVD:"), + Layout::Directory{name, properties} => println!("Dir: {} @{}", name, properties.lba.unwrap_or(0)), + Layout::File(file) => println!("File: {} @{}", file, file.get_lba().unwrap_or(0)), } } Ok(()) diff --git a/src/Tools/psxcdgen_ex/src/types/lba_calculator.rs b/src/Tools/psxcdgen_ex/src/types/lba_calculator.rs new file mode 100644 index 00000000..65520fae --- /dev/null +++ b/src/Tools/psxcdgen_ex/src/types/lba_calculator.rs @@ -0,0 +1,13 @@ +use super::layout::MemoryLayoutMut; + +pub fn calculate(layout: MemoryLayoutMut, start_lba: usize) -> usize { + let lba = start_lba; + + for element in layout.into_iter() { + match element { + _ => println!("LBA calculation not implemented yet") + } + } + + lba +} \ No newline at end of file diff --git a/src/Tools/psxcdgen_ex/src/types/mod.rs b/src/Tools/psxcdgen_ex/src/types/mod.rs index a591796a..6bb2a3e7 100644 --- a/src/Tools/psxcdgen_ex/src/types/mod.rs +++ b/src/Tools/psxcdgen_ex/src/types/mod.rs @@ -1,4 +1,5 @@ pub mod layout; +mod lba_calculator; use cdtypes::types::cdstring::DString; use tool_helper::Error; @@ -17,6 +18,10 @@ impl CDDesc { } } + pub fn calculate_lbas(&mut self) { + lba_calculator::calculate(self.get_memory_layout_mut(), 0); + } + pub fn get_memory_layout(&self) -> layout::MemoryLayout { layout::DefaultLayout::new(self) } @@ -63,6 +68,10 @@ impl Directory { pub fn add_file(&mut self, file: File) { self.files.push(file); } + + pub fn get_lba(&self) -> Option { + self.properties.lba + } } impl std::fmt::Display for Directory { @@ -80,6 +89,10 @@ impl File { pub fn new(file_name: &str) -> Result { Ok(File{name: FileName::from_str(file_name)?, properties: Properties::default()}) } + + pub fn get_lba(&self) -> Option { + self.properties.lba + } } impl std::fmt::Display for File {