LBAs are track relative

This commit is contained in:
Jaby
2022-10-19 20:42:58 +02:00
committed by Jaby
parent 7f06cb1226
commit 9d26770ea7
7 changed files with 41 additions and 35 deletions

View File

@@ -20,6 +20,16 @@ impl Sector {
}
}
pub fn get_header_mut(&mut self) -> Option<&mut Header> {
match self {
Sector::Audio(_) => None,
Sector::Empty(sec) => Some(&mut sec.header),
Sector::CDData(sec) => Some(&mut sec.header),
Sector::CDXAData(sec) => Some(&mut sec.header),
Sector::CDXAAudio(sec) => Some(&mut sec.header),
}
}
pub fn get_sub_header(&self) -> Option<&SubHeader> {
match self {
Sector::CDXAData(sec) => Some(&sec.sub_header),

View File

@@ -5,6 +5,10 @@ pub struct BCDValue {
}
impl BCDValue {
pub const fn new(value: u8) -> BCDValue {
BCDValue{value: (((value/10) << 4) | (value%10))}
}
pub fn get_decimal(&self) -> u8 {
((self.value >> 4)*10) + (self.value & 0b1111)
}
@@ -12,7 +16,7 @@ impl BCDValue {
impl std::convert::From<u8> for BCDValue {
fn from(value: u8) -> Self {
BCDValue{value: (((value/10) << 4) | (value%10))}
BCDValue::new(value)
}
}

View File

@@ -13,15 +13,15 @@ impl Time {
pub const MAX_SECONDS:usize = 60;
pub const MAX_MINUTES:usize = 74;
pub fn cue_start() -> Time {
pub const fn cue_start() -> Time {
Time{minute: 0, second: 0, sector: 0}
}
pub fn cd_start() -> Time {
pub const fn cd_start() -> Time {
Time{minute: 0, second: 2, sector: 0}
}
pub fn cd_pregap() -> Time {
pub const fn cd_pregap() -> Time {
Time{minute: 0, second: 2, sector: 0}
}
@@ -60,7 +60,7 @@ impl Time {
(BCDValue::from(self.minute), BCDValue::from(self.second), BCDValue::from(self.sector))
}
pub fn to_lba(&self) -> usize {
pub const fn to_lba(&self) -> usize {
self.sector as usize + (self.second as usize*Self::MAX_SECTORS) + (self.minute as usize*Self::MAX_SECONDS*Self::MAX_SECTORS)
}