From c196213441d76b45c4af4de28e56a8c601040b32 Mon Sep 17 00:00:00 2001 From: Jaby Date: Wed, 12 Oct 2022 20:26:26 +0200 Subject: [PATCH] Start calculating LBAs --- src/Tools/psxcdgen_ex/src/types/mod.rs | 43 ++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/src/Tools/psxcdgen_ex/src/types/mod.rs b/src/Tools/psxcdgen_ex/src/types/mod.rs index 33165665..fe3ff7a8 100644 --- a/src/Tools/psxcdgen_ex/src/types/mod.rs +++ b/src/Tools/psxcdgen_ex/src/types/mod.rs @@ -1,7 +1,8 @@ mod helper; pub mod layout; -use cdtypes::types::{cdstring::DString, dir_record::DirectoryRecord}; +use cdtypes::types::{cdstring::DString, dir_record::DirectoryRecord, helper::sector_count_mode2_form1, sector::*}; +use layout::LayoutMut; use tool_helper::Error; pub struct CDDesc { @@ -11,6 +12,8 @@ pub struct CDDesc { } impl CDDesc { + const DEFAULT_DATA_SIZE_FOR_NOW:usize = Mode2Form1::DATA_SIZE; + pub fn new() -> CDDesc { match Directory::new("root") { Ok(root) => CDDesc{system_area: SystemArea::new(), pvd: PrimaryVolumeDescriptor::new(), root}, @@ -27,9 +30,24 @@ impl CDDesc { } pub fn calculate_lbas(&mut self) { + let mut cur_lba = 0; + Self::for_each_dir_mut(&mut self.root, &|dir| {dir.update_content_size();}); // Now layout iterate? + for element in self.get_memory_layout_mut() { + match element { + LayoutMut::SystemArea(system_area) => { + let system_area_props = &mut system_area.properties; + + system_area_props.lba = cur_lba; + cur_lba += system_area_props.sector_count_xa_data(Self::DEFAULT_DATA_SIZE_FOR_NOW); + }, + _ => () + } + + println!("cur_lba: {}", cur_lba); + } } fn for_each_dir_mut(dir: &mut Directory, function: &T) { @@ -41,11 +59,14 @@ impl CDDesc { } pub struct SystemArea { + pub properties: Properties } impl SystemArea { + const DEFAULT_SIZE:usize = (16*Mode2Form1::DATA_SIZE); + pub fn new() -> SystemArea { - SystemArea{} + SystemArea{properties: Properties{lba: 0, overwrite_size_bytes: Some(Self::DEFAULT_SIZE), is_hidden: false}} } } @@ -87,7 +108,7 @@ impl Directory { } self.properties.overwrite_size_bytes = Some(size_bytes); - } + } fn _update_content(&mut self) { let dir_member = helper::collect_directory_record_member(&self.files, &self.dirs); @@ -196,6 +217,22 @@ pub struct Properties { pub is_hidden: bool } +impl Properties { + pub fn sector_count_xa_data(&self, content_size: usize) -> usize { + let size_bytes = { + if let Some(forced_bytes) = self.overwrite_size_bytes { + forced_bytes + } + + else { + content_size + } + }; + + sector_count_mode2_form1(size_bytes) + } +} + impl Default for Properties { fn default() -> Self { Properties{lba: 0, overwrite_size_bytes: None, is_hidden: false}