From 9f8b7f4ebe32c81f7cffb2c07e803dcc815e1e00 Mon Sep 17 00:00:00 2001 From: jaby Date: Thu, 20 Oct 2022 22:12:46 +0200 Subject: [PATCH] Prepare filling in PVD --- src/Tools/cdtypes/src/types/pvd.rs | 2 +- .../src/iso_writer/psx/encoder/mod.rs | 2 +- src/Tools/psxcdgen_ex/planschi.bin | Bin 37632 -> 42336 bytes src/Tools/psxcdgen_ex/src/encoder/builder.rs | 36 ++++++++++++++++-- src/Tools/psxcdgen_ex/src/encoder/psx.rs | 18 ++++++++- src/Tools/psxcdgen_ex/src/types/mod.rs | 6 +-- 6 files changed, 54 insertions(+), 10 deletions(-) diff --git a/src/Tools/cdtypes/src/types/pvd.rs b/src/Tools/cdtypes/src/types/pvd.rs index 17731a4e..803033f8 100644 --- a/src/Tools/cdtypes/src/types/pvd.rs +++ b/src/Tools/cdtypes/src/types/pvd.rs @@ -54,7 +54,7 @@ pub struct VolumeDescriptorTerminator { } impl PrimaryVolumeDescriptor { - pub fn new() -> PrimaryVolumeDescriptor { + pub fn psx_default() -> PrimaryVolumeDescriptor { PrimaryVolumeDescriptor{ volume_type: [1], std_id: ['C' as u8, 'D' as u8, '0' as u8, '0' as u8, '1' as u8], diff --git a/src/Tools/psxcdgen/src/iso_writer/psx/encoder/mod.rs b/src/Tools/psxcdgen/src/iso_writer/psx/encoder/mod.rs index 51155f24..d6182563 100644 --- a/src/Tools/psxcdgen/src/iso_writer/psx/encoder/mod.rs +++ b/src/Tools/psxcdgen/src/iso_writer/psx/encoder/mod.rs @@ -123,7 +123,7 @@ pub fn write_pvd(mut desc: PVDDesc, sectors: &mut Vec, conte let sectors_size = sectors.len(); let now_date = Date::now(); - let mut raw_pvd = PrimaryVolumeDescriptor::new(); + let mut raw_pvd = PrimaryVolumeDescriptor::psx_default(); raw_pvd.system_id = AString::from_str("PLAYSTATION")?; if desc.volume_identifier.len() > 8 { diff --git a/src/Tools/psxcdgen_ex/planschi.bin b/src/Tools/psxcdgen_ex/planschi.bin index c2ef3956c01a09296d9949bbf361051bf17e5906..baf0845d234a51eec449276f904eca3883a84d66 100644 GIT binary patch literal 42336 zcmeI!TS!z<6vpv2qn0McWM-m;qeIYx<~U`9MOUF4QQ?KDUPdF-f|BSm6a*1s4p!vl zK?=#rhYUfAz@#V;?D7&BQUo=GQIOO;R8Umf)@dJfh=XB-aQ;gU>s;pS+5VQuCqqVw z*wv53O88KXLI42-5I_I{O9{lEI?)jRg}AH_J;=G1Q0*~0SgL{m-Nuh@=`2$Ni)$AKmY**5U`*Cc}Wl5 zEHA~8moyU{0R#|0009dMkeBq(&GM3iyrh}v2q1s}0ti@8fV`xKZkCs3l9x0S9RUOo zKmY*?3Xqrd(9QBv0(nU@(GfrZ0R#}Rpa6ME58W&;%_1*pCOQHLAba>7kqD zr9|?QW}+j200IagU_k-$k{-HQUYbo_(oA#&5I_I{1S}{(UeZH1%S%ZrFU6@3#))lh zzT2H+6Xyg=f9rU=O~f{QNNntQU-`r5Cb(%{N8oP++z}-a*Y0uLP=EB3sn+Iac~`6d z0F!A?>;(Y?{*SG^g~c}#9{XJ>2c`Imc6?(lSU1p*s348PM<_V#Q-pRYJI^Ym?7 zMfTl+eK`-J4#|*FBKA2dFV(1l)X329y!3yj!?z%S00IagfWTxBnBV2TAKpidYBADQ z<99myzD#gy`=4$t3@=fuTCEg4TJCVX`8>f@H&*!S$1bt8F#c!9wE>l8!WA!>`EA>> uGiEG$74485DbNo_bzlAQS$79o_Uc=M^7UMIV@)9CVf(rZaz|c_Jop7eFAdiK delta 8 PcmaEGim724(}KwW6N>~0 diff --git a/src/Tools/psxcdgen_ex/src/encoder/builder.rs b/src/Tools/psxcdgen_ex/src/encoder/builder.rs index c7662db2..9425d871 100644 --- a/src/Tools/psxcdgen_ex/src/encoder/builder.rs +++ b/src/Tools/psxcdgen_ex/src/encoder/builder.rs @@ -1,13 +1,43 @@ use cdtypes::types::sector::*; -pub fn create_xa_data_for_data(data: &[u8; Mode2Form1::DATA_SIZE]) -> Mode2Form1 { +pub struct SubModeBuilder { + sub_mode: SubMode +} + +impl SubModeBuilder { + pub fn new_mode1() -> Self { + SubModeBuilder{sub_mode: SubMode::default_form1()} + } + + pub fn set_eor(mut self) -> Self { + self.sub_mode.set_eor(); + self + } + + pub fn set_eof(mut self) -> Self { + self.sub_mode.set_eof(); + self + } + + pub fn create(self) -> SubMode { + self.sub_mode + } +} + +pub fn create_xa_data_for_raw(mut sub_mode: SubMode, data: &[u8; Mode2Form1::DATA_SIZE]) -> Mode2Form1 { let mut sector = Mode2Form1::new(); - sector.sub_header.sub_mode.set_data(); + sub_mode.set_data(); + + sector.sub_header.sub_mode = sub_mode; sector.data = *data; sector } +pub fn create_xa_data_for(sub_mode: SubMode, data: &T) -> Mode2Form1 { + create_xa_data_for_raw(sub_mode, unsafe {std::mem::transmute::<&T, &[u8; Mode2Form1::DATA_SIZE]>(data)}) +} + pub fn create_xa_data_zero() -> Mode2Form1 { - create_xa_data_for_data(&[0u8; Mode2Form1::DATA_SIZE]) + create_xa_data_for_raw(SubMode::default_form1(), &[0u8; Mode2Form1::DATA_SIZE]) } \ No newline at end of file diff --git a/src/Tools/psxcdgen_ex/src/encoder/psx.rs b/src/Tools/psxcdgen_ex/src/encoder/psx.rs index 2012533a..652b8cbc 100644 --- a/src/Tools/psxcdgen_ex/src/encoder/psx.rs +++ b/src/Tools/psxcdgen_ex/src/encoder/psx.rs @@ -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, 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(()) } diff --git a/src/Tools/psxcdgen_ex/src/types/mod.rs b/src/Tools/psxcdgen_ex/src/types/mod.rs index 3dade461..61759810 100644 --- a/src/Tools/psxcdgen_ex/src/types/mod.rs +++ b/src/Tools/psxcdgen_ex/src/types/mod.rs @@ -14,9 +14,9 @@ pub fn new_shared_ptr(value: T) -> SharedPtr { } pub struct CDDesc { - system_area: SharedPtr, - path_table: SharedPtr, - pvd: SharedPtr, + pub(super) system_area: SharedPtr, + pub(super) path_table: SharedPtr, + pub(super) pvd: SharedPtr, pub(super) root: SharedPtr }