Write PathTable infos, publisher name and more
This commit is contained in:
parent
21b6c6e1f6
commit
fa207165ba
Binary file not shown.
|
@ -1,7 +1,7 @@
|
||||||
use super::{*, Sector, SectorWriter, {CDDesc, Error}};
|
use super::{*, Sector, SectorWriter, {CDDesc, Error}};
|
||||||
use super::super::types::{layout::Layout, *};
|
use super::super::types::{layout::Layout, *};
|
||||||
use builder::SubModeBuilder;
|
use builder::SubModeBuilder;
|
||||||
use cdtypes::types::{cdstring::{AString, DString}, date::Date, helper::sector_count_mode2_form1, pvd as cd_pvd};
|
use cdtypes::types::{cdstring::{AString, DString}, date::Date, helper::sector_count_mode2_form1, pvd as cd_pvd, lsb_msb::*, sector::Mode2Form1};
|
||||||
|
|
||||||
const SYSTEM_AREA_SECTOR_COUNT:usize = 16;
|
const SYSTEM_AREA_SECTOR_COUNT:usize = 16;
|
||||||
const PVD_SECTOR_COUNT:usize = 2;
|
const PVD_SECTOR_COUNT:usize = 2;
|
||||||
|
@ -9,7 +9,8 @@ const PVD_SECTOR_COUNT:usize = 2;
|
||||||
pub fn calculate_psx_lbas(cd_desc: &mut CDDesc) {
|
pub fn calculate_psx_lbas(cd_desc: &mut CDDesc) {
|
||||||
let path_table_size = PathTable::calculate_size_for(cd_desc.root.clone());
|
let path_table_size = PathTable::calculate_size_for(cd_desc.root.clone());
|
||||||
let mut cur_lba = 0;
|
let mut cur_lba = 0;
|
||||||
|
|
||||||
|
cd_desc.vol_sector_count = 0;
|
||||||
CDDesc::for_each_dir_mut(cd_desc.root.clone(), &|dir| {dir.update_content_size();});
|
CDDesc::for_each_dir_mut(cd_desc.root.clone(), &|dir| {dir.update_content_size();});
|
||||||
|
|
||||||
for element in cd_desc.get_memory_layout() {
|
for element in cd_desc.get_memory_layout() {
|
||||||
|
@ -36,17 +37,18 @@ pub fn calculate_psx_lbas(cd_desc: &mut CDDesc) {
|
||||||
Layout::PathTables(path_table) => {
|
Layout::PathTables(path_table) => {
|
||||||
let mut path_table = path_table.borrow_mut();
|
let mut path_table = path_table.borrow_mut();
|
||||||
|
|
||||||
path_table.track_rel_lba = cur_lba;
|
path_table.track_rel_lba = cur_lba;
|
||||||
path_table.single_sector_size = sector_count_mode2_form1(path_table_size);
|
path_table.size_bytes = path_table_size;
|
||||||
|
|
||||||
cur_lba += path_table.single_sector_size*4;
|
cur_lba += sector_count_mode2_form1(path_table.size_bytes)*4;
|
||||||
},
|
},
|
||||||
|
|
||||||
Layout::Directory(dir) => {
|
Layout::Directory(dir) => {
|
||||||
let sector_count = sector_count_mode2_form1(dir.borrow().get_size());
|
let sector_count = sector_count_mode2_form1(dir.borrow().get_size());
|
||||||
let mut dir = dir.borrow_mut();
|
let mut dir = dir.borrow_mut();
|
||||||
|
|
||||||
cur_lba = update_lba(&mut dir.properties, cur_lba, sector_count)
|
cd_desc.vol_sector_count += sector_count;
|
||||||
|
cur_lba = update_lba(&mut dir.properties, cur_lba, sector_count);
|
||||||
},
|
},
|
||||||
|
|
||||||
Layout::File(file) => {
|
Layout::File(file) => {
|
||||||
|
@ -59,6 +61,7 @@ pub fn calculate_psx_lbas(cd_desc: &mut CDDesc) {
|
||||||
|
|
||||||
let mut file = file.borrow_mut();
|
let mut file = file.borrow_mut();
|
||||||
|
|
||||||
|
cd_desc.vol_sector_count += sector_count;
|
||||||
cur_lba = update_lba(&mut file.properties, cur_lba, sector_count);
|
cur_lba = update_lba(&mut file.properties, cur_lba, sector_count);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -68,10 +71,12 @@ pub fn calculate_psx_lbas(cd_desc: &mut CDDesc) {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn encode_psx_image(cd_desc: CDDesc, sec_writer: &mut dyn SectorWriter) -> Result<(), Error> {
|
pub fn encode_psx_image(cd_desc: CDDesc, sec_writer: &mut dyn SectorWriter) -> Result<(), Error> {
|
||||||
|
let vol_sector_count = cd_desc.vol_sector_count;
|
||||||
|
|
||||||
for element in cd_desc.get_memory_layout() {
|
for element in cd_desc.get_memory_layout() {
|
||||||
match element {
|
match element {
|
||||||
Layout::SystemArea(system_area) => process_system_area(&system_area.borrow(), sec_writer)?,
|
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)?,
|
Layout::PVD(pvd) => process_pvd(&pvd.borrow(), cd_desc.path_table.clone(), sec_writer, vol_sector_count)?,
|
||||||
_ => ()
|
_ => ()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -92,33 +97,36 @@ fn process_system_area(system_area: &SystemArea, sec_writer: &mut dyn SectorWrit
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn process_pvd(pvd: &PrimaryVolumeDescriptor, path_table: SharedPtr<PathTable>, sec_writer: &mut dyn SectorWriter) -> Result<(), Error> {
|
fn process_pvd(pvd: &PrimaryVolumeDescriptor, path_table: SharedPtr<PathTable>, sec_writer: &mut dyn SectorWriter, vol_sector_count: usize) -> Result<(), Error> {
|
||||||
const PLAYSATATION_STR:&'static str = "PLAYSTATION";
|
const PLAYSATATION_STR:&'static str = "PLAYSTATION";
|
||||||
let path_table = path_table.borrow();
|
|
||||||
|
let path_table = validate_path_table(&path_table)?;
|
||||||
|
let pvd_lba = pvd.track_rel_lba;
|
||||||
|
|
||||||
if pvd.track_rel_lba != 16 {
|
if pvd_lba != 16 {
|
||||||
return Err(Error::from_text(format!("PVD required to start at sector 16 of Track - found LBA: {}", pvd.track_rel_lba)));
|
return Err(Error::from_text(format!("PVD required to start at sector 16 of Track - found LBA: {}", pvd_lba)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
let mut cd_pvd = cd_pvd::PrimaryVolumeDescriptor::new();
|
let mut cd_pvd = cd_pvd::PrimaryVolumeDescriptor::new();
|
||||||
let now = Date::now();
|
let now = Date::now();
|
||||||
|
|
||||||
//Config pvd here
|
//Config pvd here
|
||||||
cd_pvd.system_id = AString::from_str(PLAYSATATION_STR)?;
|
cd_pvd.system_id = AString::from_str(PLAYSATATION_STR)?;
|
||||||
cd_pvd.volume_id = DString::from_str("PSX")?;
|
cd_pvd.volume_id = DString::from_str("PSX")?;
|
||||||
&cd_pvd.vol_space_size;
|
cd_pvd.vol_space_size.write(vol_sector_count as u32);
|
||||||
|
|
||||||
&cd_pvd.path_table_size;
|
cd_pvd.path_table_size.write(path_table.size_bytes as u32);
|
||||||
&cd_pvd.path_table_1;
|
cd_pvd.path_table_1.write(path_table.get_track_rel_lba_for(1, sector_count_mode2_form1) as u32);
|
||||||
&cd_pvd.path_table_2;
|
cd_pvd.path_table_2.write(path_table.get_track_rel_lba_for(2, sector_count_mode2_form1) as u32);
|
||||||
&cd_pvd.path_table_3;
|
cd_pvd.path_table_3.write(path_table.get_track_rel_lba_for(3, sector_count_mode2_form1) as u32);
|
||||||
&cd_pvd.path_table_4;
|
cd_pvd.path_table_4.write(path_table.get_track_rel_lba_for(4, sector_count_mode2_form1) as u32);
|
||||||
|
|
||||||
&cd_pvd.root_dir_record;
|
&cd_pvd.root_dir_record;
|
||||||
|
|
||||||
&cd_pvd.publisher_id; //< Company name
|
cd_pvd.publisher_id = AString::from_str(pvd.publisher.as_str())?;
|
||||||
&cd_pvd.data_preparer;
|
cd_pvd.data_preparer = AString::from_str("JABYENGINE PSXCDGEN_EX")?;
|
||||||
cd_pvd.app_id = AString::from_str(PLAYSATATION_STR)?;
|
cd_pvd.app_id = AString::from_str(PLAYSATATION_STR)?;
|
||||||
|
|
||||||
cd_pvd.vol_create_time = now;
|
cd_pvd.vol_create_time = now;
|
||||||
|
|
||||||
|
@ -129,3 +137,13 @@ fn process_pvd(pvd: &PrimaryVolumeDescriptor, path_table: SharedPtr<PathTable>,
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn validate_path_table(path_table: &SharedPtr<PathTable>) -> Result<std::cell::Ref<PathTable>, Error> {
|
||||||
|
let path_table = path_table.borrow();
|
||||||
|
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)))
|
||||||
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
|
Ok(path_table)
|
||||||
|
}
|
||||||
|
}
|
|
@ -14,16 +14,17 @@ pub fn new_shared_ptr<T>(value: T) -> SharedPtr<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct CDDesc {
|
pub struct CDDesc {
|
||||||
pub(super) system_area: SharedPtr<SystemArea>,
|
pub(super) system_area: SharedPtr<SystemArea>,
|
||||||
pub(super) path_table: SharedPtr<PathTable>,
|
pub(super) path_table: SharedPtr<PathTable>,
|
||||||
pub(super) pvd: SharedPtr<PrimaryVolumeDescriptor>,
|
pub(super) pvd: SharedPtr<PrimaryVolumeDescriptor>,
|
||||||
pub(super) root: SharedPtr<Directory>
|
pub(super) root: SharedPtr<Directory>,
|
||||||
|
pub(super) vol_sector_count: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CDDesc {
|
impl CDDesc {
|
||||||
pub fn new() -> CDDesc {
|
pub fn new() -> CDDesc {
|
||||||
match Directory::new("root") {
|
match Directory::new("root") {
|
||||||
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)},
|
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},
|
||||||
Err(error) => panic!("Creating root directory failed with: {}", error)
|
Err(error) => panic!("Creating root directory failed with: {}", error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -65,13 +66,13 @@ impl SystemArea {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct PathTable {
|
pub struct PathTable {
|
||||||
pub(super) track_rel_lba: usize,
|
pub(super) track_rel_lba: usize,
|
||||||
pub(super) single_sector_size: usize,
|
pub(super) size_bytes: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PathTable {
|
impl PathTable {
|
||||||
pub fn new() -> PathTable {
|
pub fn new() -> PathTable {
|
||||||
PathTable{track_rel_lba: 0, single_sector_size: 0}
|
PathTable{track_rel_lba: 0, size_bytes: 0}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn calculate_size_for(root: SharedPtr<Directory>) -> usize {
|
pub fn calculate_size_for(root: SharedPtr<Directory>) -> usize {
|
||||||
|
@ -84,15 +85,21 @@ impl PathTable {
|
||||||
|
|
||||||
size_bytes
|
size_bytes
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_track_rel_lba_for(&self, table_num: usize, sector_count_func: fn(data_size: usize) -> usize) -> usize {
|
||||||
|
let table_num = table_num - 1;
|
||||||
|
self.track_rel_lba + (table_num*sector_count_func(self.size_bytes))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct PrimaryVolumeDescriptor {
|
pub struct PrimaryVolumeDescriptor {
|
||||||
pub(in super) track_rel_lba: usize
|
pub(super) track_rel_lba: usize,
|
||||||
|
pub(super) publisher: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PrimaryVolumeDescriptor {
|
impl PrimaryVolumeDescriptor {
|
||||||
pub fn new() -> PrimaryVolumeDescriptor {
|
pub fn new() -> PrimaryVolumeDescriptor {
|
||||||
PrimaryVolumeDescriptor{track_rel_lba: 0}
|
PrimaryVolumeDescriptor{track_rel_lba: 0, publisher: String::new()}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue