Prepare filling in PVD

This commit is contained in:
Jaby
2022-10-20 22:12:46 +02:00
committed by Jaby
parent 081baa5b51
commit a157a8e3c5
6 changed files with 54 additions and 10 deletions

View File

@@ -1,6 +1,7 @@
use super::{*, Sector, SectorWriter, {CDDesc, Error}};
use super::super::types::{layout::Layout, *};
use cdtypes::types::helper::sector_count_mode2_form1;
use builder::SubModeBuilder;
use cdtypes::types::{helper::sector_count_mode2_form1, pvd as cd_pvd};
const SYSTEM_AREA_SECTOR_COUNT:usize = 16;
const PVD_SECTOR_COUNT:usize = 2;
@@ -70,6 +71,7 @@ pub fn encode_psx_image(cd_desc: CDDesc, sec_writer: &mut dyn SectorWriter) -> R
for element in cd_desc.get_memory_layout() {
match element {
Layout::SystemArea(system_area) => process_system_area(&system_area.borrow(), sec_writer)?,
Layout::PVD(pvd) => process_pvd(&pvd.borrow(), cd_desc.path_table.clone(), sec_writer)?,
_ => ()
}
}
@@ -90,7 +92,19 @@ fn process_system_area(system_area: &SystemArea, sec_writer: &mut dyn SectorWrit
Ok(())
}
fn _process_pvd(_pvd: &PrimaryVolumeDescriptor, _sec_writer: &mut dyn SectorWriter) {
fn process_pvd(pvd: &PrimaryVolumeDescriptor, path_table: SharedPtr<PathTable>, sec_writer: &mut dyn SectorWriter) -> Result<(), Error> {
let path_table = path_table.borrow();
if pvd.track_rel_lba != 16 {
return Err(Error::from_text(format!("PVD required to start at sector 16 of Track - found LBA: {}", pvd.track_rel_lba)));
}
let mut cd_pvd = cd_pvd::PrimaryVolumeDescriptor::psx_default();
//Config pvd here
sec_writer.write(Sector::CDXAData(builder::create_xa_data_for(SubModeBuilder::new_mode1().set_eor().create(), &cd_pvd)))?;
sec_writer.write(Sector::CDXAData(builder::create_xa_data_for(SubModeBuilder::new_mode1().set_eor().set_eof().create(), &cd_pvd::VolumeDescriptorTerminator::new())))?;
Ok(())
}