use crate::disk_base;
use crate::disk525;
const BLOCK_SIZE: usize = 512;
const MAX_BLOCKS: usize = 65535;
const MIN_BLOCKS: usize = 280;
pub struct DO {
tracks: u16,
sectors: u16,
data: Vec<u8>
}
impl disk_base::DiskImage for DO {
fn from_bytes(data: &Vec<u8>) -> Option<Self> {
if data.len()%BLOCK_SIZE > 0 || data.len()/BLOCK_SIZE > MAX_BLOCKS || data.len()/BLOCK_SIZE < MIN_BLOCKS {
return None;
}
if (data.len()/BLOCK_SIZE)%8 >0 {
return None;
}
Some(Self {
tracks: (data.len()/BLOCK_SIZE/8) as u16,
sectors: 16,
data: data.clone()
})
}
fn is_do_or_po(&self) -> bool {
true
}
fn update_from_do(&mut self,dsk: &Vec<u8>) -> Result<(),Box<dyn std::error::Error>> {
if self.data.len()!=dsk.len() {
return Err(Box::new(disk_base::CommandError::UnknownFormat));
}
self.data = dsk.clone();
return Ok(());
}
fn update_from_po(&mut self,dsk: &Vec<u8>) -> Result<(),Box<dyn std::error::Error>> {
if self.data.len()!=dsk.len() {
return Err(Box::new(disk_base::CommandError::UnknownFormat));
}
return self.update_from_do(&disk525::reorder_po_to_do(dsk, self.sectors as usize));
}
fn to_do(&self) -> Result<Vec<u8>,Box<dyn std::error::Error>> {
return Ok(self.data.clone());
}
fn to_po(&self) -> Result<Vec<u8>,Box<dyn std::error::Error>> {
return Ok(disk525::reorder_do_to_po(&self.data, self.sectors as usize));
}
fn to_bytes(&self) -> Vec<u8> {
return self.data.clone();
}
fn get_track_buf(&self,track: &str) -> Result<(u16,Vec<u8>),Box<dyn std::error::Error>> {
return Err(Box::new(disk_base::CommandError::UnsupportedFormat));
}
fn get_track_bytes(&self,track: &str) -> Result<(u16,Vec<u8>),Box<dyn std::error::Error>> {
return Err(Box::new(disk_base::CommandError::UnsupportedFormat));
}
}