Write sectors
This commit is contained in:
parent
1d0482d74c
commit
7a0ceee9c9
|
@ -135,4 +135,14 @@ impl Sector {
|
|||
Sector::CDXAAudio(sector) => sector.finalize(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn as_raw(&self) -> &[u8] {
|
||||
match self {
|
||||
Sector::Audio(sector) => unsafe {std::mem::transmute::<&Audio, &[u8; SECTOR_SIZE]>(sector)},
|
||||
Sector::Empty(sector) => unsafe {std::mem::transmute::<&Mode0, &[u8; SECTOR_SIZE]>(sector)},
|
||||
Sector::CDData(sector) => unsafe {std::mem::transmute::<&Mode1, &[u8; SECTOR_SIZE]>(sector)},
|
||||
Sector::CDXAData(sector) => unsafe {std::mem::transmute::<&Mode2Form1, &[u8; SECTOR_SIZE]>(sector)},
|
||||
Sector::CDXAAudio(sector) => unsafe {std::mem::transmute::<&Mode2Form2, &[u8; SECTOR_SIZE]>(sector)},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,10 +9,12 @@ pub fn encode_psx_image(cd_desc: CDDesc, sec_writer: &mut dyn SectorWriter) -> R
|
|||
}
|
||||
}
|
||||
|
||||
Err(Error::not_implemented("encode_psx_image"))
|
||||
//Err(Error::not_implemented("encode_psx_image"))
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn process_system_area(_: &SystemArea, sec_writer: &mut dyn SectorWriter) -> Result<(), Error> {
|
||||
|
||||
sec_writer.write(Sector::CDXAData(builder::create_xa_data_zero()))
|
||||
sec_writer.write(Sector::CDXAData(builder::create_xa_data_zero()))?;
|
||||
Ok(())
|
||||
}
|
|
@ -3,13 +3,13 @@ use cdtypes::types::time::Time;
|
|||
use std::io::Write;
|
||||
|
||||
pub struct BinCueWriter {
|
||||
_bin_out: std::boxed::Box<dyn Write>,
|
||||
bin_out: std::boxed::Box<dyn Write>,
|
||||
cd_time: Time,
|
||||
}
|
||||
|
||||
impl BinCueWriter {
|
||||
pub fn new<T: Write + 'static>(writer: T) -> BinCueWriter {
|
||||
BinCueWriter{_bin_out: std::boxed::Box::new(writer), cd_time: Time::cd_start()}
|
||||
BinCueWriter{bin_out: std::boxed::Box::new(writer), cd_time: Time::cd_start()}
|
||||
}
|
||||
|
||||
fn finalize(&mut self, sector: &mut Sector) -> Result<(), Error> {
|
||||
|
@ -25,15 +25,9 @@ impl BinCueWriter {
|
|||
}
|
||||
|
||||
impl SectorWriter for BinCueWriter {
|
||||
fn write(&mut self, mut sector: Sector) -> Result<(), Error> {
|
||||
fn write(&mut self, mut sector: Sector) -> Result<usize, Error> {
|
||||
self.finalize(&mut sector)?;
|
||||
|
||||
match sector {
|
||||
Sector::Empty(_) => Err(Error::not_implemented("Empty sector encoding")),
|
||||
Sector::Audio(_) => Err(Error::not_implemented("Audio sector encoding")),
|
||||
Sector::CDData(_) => Err(Error::not_implemented("CD Data sector encoding")),
|
||||
Sector::CDXAData(_) => Err(Error::not_implemented("CD XA Data sector encoding")),
|
||||
Sector::CDXAAudio(_) => Err(Error::not_implemented("CD XA Audio sector encoding"))
|
||||
}
|
||||
Ok(self.bin_out.write(sector.as_raw())?)
|
||||
}
|
||||
}
|
|
@ -12,7 +12,7 @@ pub enum ImageType {
|
|||
}
|
||||
|
||||
pub trait SectorWriter {
|
||||
fn write(&mut self, sector: Sector) -> Result<(), Error>;
|
||||
fn write(&mut self, sector: Sector) -> Result<usize, Error>;
|
||||
}
|
||||
|
||||
pub fn write_image(cd_desc: CDDesc, encoder: EncoderFunction, image_type: ImageType, output_path: PathBuf) -> Result<(), Error> {
|
||||
|
|
Loading…
Reference in New Issue