Support Lead-out track

This commit is contained in:
jaby 2024-07-21 16:33:03 +02:00
parent 5624eb40f3
commit aaab604f61
10 changed files with 36 additions and 22 deletions

View File

@ -3,7 +3,7 @@
<Publisher>Jaby</Publisher> <Publisher>Jaby</Publisher>
<License>%PSX_LICENSE_PATH%/%PSX_LICENSE%.DAT</License> <License>%PSX_LICENSE_PATH%/%PSX_LICENSE%.DAT</License>
</Description> </Description>
<Track> <Track lead-out="0:2:0">
<!--TODO: JabyEngine should warn at runtime that I did not apply lba_source!--> <!--TODO: JabyEngine should warn at runtime that I did not apply lba_source!-->
<File name = "SYSTEM.CNF">System.cnf.subst</File> <File name = "SYSTEM.CNF">System.cnf.subst</File>
<Main name = "%PSX_BOOT_FILE%" lba_source = "../application/src/asset_mgr.cpp">../application/bin/%PSX_TV_FORMAT%/PSX-release/PoolBox.psexe</Main> <Main name = "%PSX_BOOT_FILE%" lba_source = "../application/src/asset_mgr.cpp">../application/bin/%PSX_TV_FORMAT%/PSX-release/PoolBox.psexe</Main>
@ -37,12 +37,5 @@
<Channel>../assets/bin/Evacuation.xa</Channel> <Channel>../assets/bin/Evacuation.xa</Channel>
</XA-Audio> </XA-Audio>
</Directory> </Directory>
<!-- TODO: Support lead out track of 2 seconds for PS3 -->
<Directory hidden = "true">
<File>../assets/bin/fox.xa</File>
<File>../assets/bin/fox.xa</File>
<File>../assets/bin/fox.xa</File>
<File>../assets/bin/fox.xa</File>
</Directory>
</Track> </Track>
</ISO_Project> </ISO_Project>

View File

@ -1,6 +1,6 @@
[package] [package]
name = "cdtypes" name = "cdtypes"
version = "0.7.0" version = "0.7.1"
edition = "2021" edition = "2021"
[profile.release] [profile.release]

View File

@ -332,10 +332,12 @@ impl Audio {
pub struct Mode0 { pub struct Mode0 {
pub sync: Sync, pub sync: Sync,
pub header: Header, pub header: Header,
pub zero: [u8;2336] pub zero: [u8;Mode0::DATA_SIZE]
} }
impl Mode0 { impl Mode0 {
pub const DATA_SIZE:usize = 2336;
pub fn new() -> Mode0 { pub fn new() -> Mode0 {
Mode0{sync: Sync::new(), header: Header::new(0), zero: [0; 2336]} Mode0{sync: Sync::new(), header: Header::new(0), zero: [0; 2336]}
} }

View File

@ -1,6 +1,6 @@
[package] [package]
name = "psxcdgen_ex" name = "psxcdgen_ex"
version = "0.5.0" version = "0.6.0"
edition = "2021" edition = "2021"
[profile.release] [profile.release]

View File

@ -41,7 +41,7 @@ fn parse_iso_project(iso_project: roxmltree::Node, config: &mut Configuration) -
} }
else { else {
print_warning("Found more than 1 track. Track will be ignored".to_owned()); print_warning("Found more than 1 track. Multi-Tracks are not supported yet. Track will be ignored".to_owned());
Ok(()) Ok(())
} }
}, },

View File

@ -165,6 +165,10 @@ pub fn create_xa_audio_for(data: &Vec<RawData>) -> Vec<InterleavedXASector> {
sectors sectors
} }
pub fn create_mode0_zero() -> Mode0 {
Mode0::new()
}
pub fn create_xa_data_zero() -> Mode2Form1 { pub fn create_xa_data_zero() -> Mode2Form1 {
create_xa_data_for_raw(SubMode::default_form1(), &[0u8; Mode2Form1::DATA_SIZE]) create_xa_data_for_raw(SubMode::default_form1(), &[0u8; Mode2Form1::DATA_SIZE])
} }

View File

@ -8,7 +8,7 @@ use std::io::{Read, Seek, SeekFrom};
const ROOT_DIR_NAME:&'static str = "\x00"; const ROOT_DIR_NAME:&'static str = "\x00";
pub mod length_of { pub mod length_of {
use cdtypes::types::helper::{sector_count_mode2_form1, sector_count_mode2_form2}; use cdtypes::types::{sector::Mode0, helper::{sector_count_mode2_form1, sector_count_mode2_form2}};
use crate::types::FileType; use crate::types::FileType;
use super::{Directory, File, LengthInfo, PathTable}; use super::{Directory, File, LengthInfo, PathTable};
@ -46,6 +46,10 @@ pub mod length_of {
LengthInfo{bytes: Some(fake_size), sectors: sector_count_mode2_form1(fake_size)} LengthInfo{bytes: Some(fake_size), sectors: sector_count_mode2_form1(fake_size)}
} }
} }
pub fn lead_out(sectors: usize) -> LengthInfo {
LengthInfo{bytes: Some(sectors*Mode0::DATA_SIZE), sectors}
}
} }
pub fn calculate_length_for(element: &Layout) -> LengthInfo { pub fn calculate_length_for(element: &Layout) -> LengthInfo {
@ -133,6 +137,7 @@ pub fn encode_image(cd_desc: &CDDesc, sec_writer: &mut dyn SectorWriter) -> Resu
} }
} }
process_lead_out(cd_desc.lead_out_sectors, sec_writer)?;
process_end_dummy_section(cd_desc.end_dummy_padding, sec_writer)?; process_end_dummy_section(cd_desc.end_dummy_padding, sec_writer)?;
process_cd_da(&cd_desc.cd_da_tracks, sec_writer) process_cd_da(&cd_desc.cd_da_tracks, sec_writer)
} }
@ -387,6 +392,13 @@ fn write_dummy(sec_writer: &mut dyn SectorWriter, sectors: usize) -> Result<(),
Ok(()) Ok(())
} }
fn process_lead_out(sectors: usize, sec_writer: &mut dyn SectorWriter) -> Result<(), Error> {
for _ in 0..sectors {
sec_writer.write_empty(builder::create_mode0_zero())?;
}
Ok(())
}
fn process_end_dummy_section(padding: usize, sec_writer: &mut dyn SectorWriter) -> Result<(), Error> { fn process_end_dummy_section(padding: usize, sec_writer: &mut dyn SectorWriter) -> Result<(), Error> {
write_dummy(sec_writer, sector_count_mode2_form1(padding)) write_dummy(sec_writer, sector_count_mode2_form1(padding))
} }

View File

@ -263,5 +263,7 @@ fn parse_configuration(config: config_reader::Configuration) -> Result<(CDDesc,
parse_dir(&mut cd_desc.root.borrow_mut(), config.root, &mut lba_embedded_files)?; parse_dir(&mut cd_desc.root.borrow_mut(), config.root, &mut lba_embedded_files)?;
parse_cd_da(&mut cd_desc.cd_da_tracks, config.cd_audio_files)?; parse_cd_da(&mut cd_desc.cd_da_tracks, config.cd_audio_files)?;
cd_desc.lead_out_sectors = config.lead_out_sectors.unwrap_or(0);
Ok((cd_desc, lba_embedded_files)) Ok((cd_desc, lba_embedded_files))
} }

View File

@ -29,10 +29,14 @@ fn run_main(cmd_line: CommandLine) -> Result<(), Error> {
let content_size = desc.get_content_size(); let content_size = desc.get_content_size();
if content_size < PKG_MINIMUM_CONTENT_SIZE { if content_size < PKG_MINIMUM_CONTENT_SIZE {
let missing_size = PKG_MINIMUM_CONTENT_SIZE - content_size; let missing_size = PKG_MINIMUM_CONTENT_SIZE - content_size;
desc.set_end_padding(missing_size); desc.end_dummy_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)); 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));
} }
if desc.lead_out_sectors == 0 {
tool_helper::print_warning(format!("Consider adding a 2 second lead-out to your track (Add attribute 'lead-out=\"0:2:0\"' to your Track) for supporting the PS3"));
}
write_image(&desc, cmd_line.output_type, cmd_line.output_file)?; write_image(&desc, cmd_line.output_type, cmd_line.output_file)?;
if let Some(list_content_option) = cmd_line.list_content { if let Some(list_content_option) = cmd_line.list_content {

View File

@ -9,7 +9,7 @@ use std::{cell::RefCell, path::PathBuf, rc::Rc};
pub use file_map::FileSystemMap; pub use file_map::FileSystemMap;
pub use tool_helper::Error; pub use tool_helper::Error;
use crate::types::helper::InterleavedXASizes; use crate::{encoder::cd, types::helper::InterleavedXASizes};
pub type SharedPtr<T> = Rc<RefCell<T>>; pub type SharedPtr<T> = Rc<RefCell<T>>;
pub type RawData = Vec<u8>; pub type RawData = Vec<u8>;
@ -24,8 +24,8 @@ pub struct CDDesc {
pub(super) root: SharedPtr<Directory>, pub(super) root: SharedPtr<Directory>,
pub(super) cd_da_tracks: Vec<Vec<AudioSample>>, pub(super) cd_da_tracks: Vec<Vec<AudioSample>>,
pub(super) vol_sector_count: usize, pub(super) vol_sector_count: usize,
pub(super) lead_out_sectors: Option<usize>, pub lead_out_sectors: usize,
pub(super) end_dummy_padding: usize pub end_dummy_padding: usize
} }
impl CDDesc { impl CDDesc {
@ -38,7 +38,7 @@ impl CDDesc {
root: new_shared_ptr(root), root: new_shared_ptr(root),
cd_da_tracks: Vec::new(), cd_da_tracks: Vec::new(),
vol_sector_count: 0, vol_sector_count: 0,
lead_out_sectors: None, lead_out_sectors: 0,
end_dummy_padding: 0 end_dummy_padding: 0
}, },
Err(error) => panic!("Creating root directory failed with: {}", error) Err(error) => panic!("Creating root directory failed with: {}", error)
@ -57,10 +57,6 @@ impl CDDesc {
self.root.borrow_mut().add_file(file); 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 { pub fn create_file_map(&self) -> FileSystemMap {
file_map::new_file_map(&self.root.borrow()) file_map::new_file_map(&self.root.borrow())
} }
@ -75,6 +71,7 @@ impl CDDesc {
} }
}); });
size += cd::length_of::lead_out(self.lead_out_sectors).bytes.unwrap_or(0);
size size
} }