From 5ed8b76902e9418c952ded5f428ba36c4eba1c61 Mon Sep 17 00:00:00 2001 From: jaby Date: Sun, 25 Feb 2024 15:38:30 -0500 Subject: [PATCH] Fix CD image for PKG files --- examples/PoolBox/iso/Config.xml | 3 ++- examples/PoolBox/iso/System.cnf | 2 +- src/Library/src/BootLoader/start_boot.cpp | 1 + src/Tools/psxcdgen_ex/src/encoder/psx.rs | 10 +++++++++- src/Tools/psxcdgen_ex/src/lib.rs | 7 +++++-- src/Tools/psxcdgen_ex/src/main.rs | 18 +++++++++++++---- src/Tools/psxcdgen_ex/src/types/mod.rs | 24 +++++++++++++++++------ 7 files changed, 50 insertions(+), 15 deletions(-) diff --git a/examples/PoolBox/iso/Config.xml b/examples/PoolBox/iso/Config.xml index cdac6c8e..e7cf921e 100644 --- a/examples/PoolBox/iso/Config.xml +++ b/examples/PoolBox/iso/Config.xml @@ -5,7 +5,8 @@ System.cnf -
../application/bin/%TV_FORMAT%/PSX-release/PoolBox.psexe
+ +
../application/bin/%TV_FORMAT%/PSX-release/PoolBox.psexe
../application/bin/%TV_FORMAT%/PSX-release/Overlay.controller_tests ../application/bin/%TV_FORMAT%/PSX-release/Overlay.gpu_tests ../application/bin/%TV_FORMAT%/PSX-release/Overlay.gte_tests diff --git a/examples/PoolBox/iso/System.cnf b/examples/PoolBox/iso/System.cnf index bf22c6f7..e097006d 100644 --- a/examples/PoolBox/iso/System.cnf +++ b/examples/PoolBox/iso/System.cnf @@ -1,4 +1,4 @@ -BOOT=cdrom:\XXXX_AAA.AA;1 +BOOT=cdrom:\SLES_000.25;1 TCB=4 EVENT=10 STACK=801FFFF0 \ No newline at end of file diff --git a/src/Library/src/BootLoader/start_boot.cpp b/src/Library/src/BootLoader/start_boot.cpp index 55cc12d5..266e1ce0 100644 --- a/src/Library/src/BootLoader/start_boot.cpp +++ b/src/Library/src/BootLoader/start_boot.cpp @@ -121,6 +121,7 @@ namespace JabyEngine { __debug_boot_color_at(::JabyEngine::GPU::Color24::Red(), DebugX, DebugY, DebugScale); SPU::stop_voices(); + // TODO: v Might be the PS3 crash __debug_boot_color_at(::JabyEngine::GPU::Color24::Green(), DebugX, DebugY, DebugScale); CD::setup(); __debug_boot_color_at(::JabyEngine::GPU::Color24::Blue(), DebugX, DebugY, DebugScale); diff --git a/src/Tools/psxcdgen_ex/src/encoder/psx.rs b/src/Tools/psxcdgen_ex/src/encoder/psx.rs index a1422263..7eb7982c 100644 --- a/src/Tools/psxcdgen_ex/src/encoder/psx.rs +++ b/src/Tools/psxcdgen_ex/src/encoder/psx.rs @@ -108,7 +108,7 @@ pub fn encode_psx_image(cd_desc: &CDDesc, sec_writer: &mut dyn SectorWriter) -> } } - Ok(()) + process_end_dummy_section(cd_desc.end_dummy_padding, sec_writer) } fn process_system_area(system_area: &SystemArea, sec_writer: &mut dyn SectorWriter) -> Result<(), Error> { @@ -353,6 +353,14 @@ fn process_file(file: &File, sec_writer: &mut dyn SectorWriter) -> Result<(), Er Ok(()) } +fn process_end_dummy_section(padding: usize, sec_writer: &mut dyn SectorWriter) -> Result<(), Error> { + for _ in 0..sector_count_mode2_form1(padding) { + sec_writer.write_cd_xa_data(builder::create_xa_data_zero())?; + } + + Ok(()) +} + fn validate_path_table(path_table: &PathTable) -> Result<(), Error> { if path_table.size_bytes > Mode2Form1::DATA_SIZE { Err(Error::from_text(format!("Path Tables are not allowed to be bigger then {} bytes - Path Table has {} bytes", Mode2Form1::DATA_SIZE, path_table.size_bytes))) diff --git a/src/Tools/psxcdgen_ex/src/lib.rs b/src/Tools/psxcdgen_ex/src/lib.rs index 2525acd4..49aff663 100644 --- a/src/Tools/psxcdgen_ex/src/lib.rs +++ b/src/Tools/psxcdgen_ex/src/lib.rs @@ -29,7 +29,9 @@ pub fn process(config: config_reader::Configuration, calculate_lba: LbaCalculato Ok((cd_desc, lba_embedded_files)) } -pub fn process_files(file_map: FileSystemMap, lba_embedded_files: LBAEmbeddedFiles, length_func: LengthCalculatorFunction) -> Result<(), Error> { +pub fn process_files(file_map: FileSystemMap, lba_embedded_files: LBAEmbeddedFiles, length_func: LengthCalculatorFunction) -> Result { + let mut size_bytes = 0; + for lba_embedded_file_raw in lba_embedded_files { let new_content_info = { let mut lba_embedded_file = lba_embedded_file_raw.borrow_mut(); @@ -59,9 +61,10 @@ pub fn process_files(file_map: FileSystemMap, lba_embedded_files: LBAEmbeddedFil } } } + size_bytes += lba_embedded_file_raw.borrow().get_extended_size(); } - Ok(()) + Ok(size_bytes) } pub fn dump_content(cd_desc: &CDDesc, mut out: Output) -> Result<(), Error> { diff --git a/src/Tools/psxcdgen_ex/src/main.rs b/src/Tools/psxcdgen_ex/src/main.rs index 2acab8f8..b7a5a8bd 100644 --- a/src/Tools/psxcdgen_ex/src/main.rs +++ b/src/Tools/psxcdgen_ex/src/main.rs @@ -36,11 +36,21 @@ impl SystemType { } fn run_main(cmd_line: CommandLine) -> Result<(), Error> { - let encoding_functions = cmd_line.system_type.get_encoding_functions(); - let (desc, lba_embedded_files) = psxcdgen_ex::process(config_reader::parse_xml(read_file_to_string(&cmd_line.input_file)?)?, encoding_functions.lba_calculator)?; - let file_map = desc.create_file_map(); + const PKG_MINIMUM_CONTENT_SIZE:usize = 512*1024; - psxcdgen_ex::process_files(file_map, lba_embedded_files, encoding_functions.length_calculator)?; + let encoding_functions = cmd_line.system_type.get_encoding_functions(); + let (mut desc, lba_embedded_files) = psxcdgen_ex::process(config_reader::parse_xml(read_file_to_string(&cmd_line.input_file)?)?, encoding_functions.lba_calculator)?; + let file_map = desc.create_file_map(); + + let content_size = psxcdgen_ex::process_files(file_map, lba_embedded_files, encoding_functions.length_calculator)?; + if content_size < PKG_MINIMUM_CONTENT_SIZE { + let missing_size = PKG_MINIMUM_CONTENT_SIZE - content_size; + + desc.set_end_padding(missing_size); + tool_helper::print_warning(format!("Content size {}b smaller then {}b.\nCD will be padded with {}b to work as a .pkg", content_size, PKG_MINIMUM_CONTENT_SIZE, missing_size)); + + } + write_image(&desc, encoding_functions.encoder, cmd_line.output_type, cmd_line.output_file)?; if let Some(list_content_option) = cmd_line.list_content { diff --git a/src/Tools/psxcdgen_ex/src/types/mod.rs b/src/Tools/psxcdgen_ex/src/types/mod.rs index cad43dd0..72a16700 100644 --- a/src/Tools/psxcdgen_ex/src/types/mod.rs +++ b/src/Tools/psxcdgen_ex/src/types/mod.rs @@ -15,17 +15,25 @@ pub fn new_shared_ptr(value: T) -> SharedPtr { } pub struct CDDesc { - pub(super) system_area: SharedPtr, - pub(super) path_table: SharedPtr, - pub(super) pvd: SharedPtr, - pub(super) root: SharedPtr, - pub(super) vol_sector_count: usize, + pub(super) system_area: SharedPtr, + pub(super) path_table: SharedPtr, + pub(super) pvd: SharedPtr, + pub(super) root: SharedPtr, + pub(super) vol_sector_count: usize, + pub(super) end_dummy_padding: usize } impl CDDesc { pub fn new() -> CDDesc { match Directory::new("\x00") { - Ok(root) => CDDesc{system_area: new_shared_ptr(SystemArea::new()), path_table: new_shared_ptr(PathTable::new()), pvd: new_shared_ptr(PrimaryVolumeDescriptor::new()), root: new_shared_ptr(root), vol_sector_count: 0}, + Ok(root) => CDDesc{ + system_area: new_shared_ptr(SystemArea::new()), + path_table: new_shared_ptr(PathTable::new()), + pvd: new_shared_ptr(PrimaryVolumeDescriptor::new()), + root: new_shared_ptr(root), + vol_sector_count: 0, + end_dummy_padding: 0 + }, Err(error) => panic!("Creating root directory failed with: {}", error) } } @@ -42,6 +50,10 @@ impl CDDesc { self.root.borrow_mut().add_file(file); } + pub fn set_end_padding(&mut self, padding: usize) { + self.end_dummy_padding = padding + } + pub fn create_file_map(&self) -> FileSystemMap { file_map::new_file_map(&self.root.borrow()) }