Struct spectrusty_formats::mdr::MdrFileHeader
source · #[repr(C, packed)]pub struct MdrFileHeader {
pub block_type: BlockType,
pub length: [u8; 2],
pub start: [u8; 2],
pub prog_length: [u8; 2],
pub line: [u8; 2],
}
Expand description
Binary (SAVE *
) file’s header.
Occupies the first 9 bytes of a first data block.
This is the equivalent of an audio tape header.
Fields§
§block_type: BlockType
The type of the file this header represents.
length: [u8; 2]
Length of data.
start: [u8; 2]
Start of data.
prog_length: [u8; 2]
Program length.
line: [u8; 2]
Program’s starting line number.
Implementations§
source§impl MdrFileHeader
impl MdrFileHeader
sourcepub fn array_name(&self) -> char
pub fn array_name(&self) -> char
Examples found in repository?
src/mdr.rs (line 388)
379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398
fn from(fbh: &MdrFileHeader) -> Self {
let length = u16::from_le_bytes(fbh.length);
match fbh.block_type {
BlockType::Program => {
let vars = u16::from_le_bytes(fbh.prog_length);
let line = u16::from_le_bytes(fbh.line);
Header::new_program(length).with_start(line).with_vars(vars)
}
BlockType::NumberArray => {
Header::new_number_array(length).with_array_name(fbh.array_name())
}
BlockType::CharArray => {
Header::new_char_array(length).with_array_name(fbh.array_name())
}
BlockType::Code => {
let start = u16::from_le_bytes(fbh.start);
Header::new_code(length).with_start(start)
}
}
}
pub fn length(&self) -> u16
pub fn start(&self) -> u16
pub fn prog_length(&self) -> u16
pub fn line(&self) -> u16
sourcepub fn into_array(self) -> [u8; 9]
pub fn into_array(self) -> [u8; 9]
Examples found in repository?
src/mdr.rs (line 808)
785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820
fn file_from_tap_reader<R: Read + Seek>(&mut self, rd: &mut TapChunkReader<R>) -> io::Result<u8> {
if rd.chunk_limit() == 0 {
rd.next_chunk()?;
}
let header = if let TapChunkInfo::Head(header) = TapChunkInfo::try_from(rd.get_mut())? {
header
}
else {
return Err(io::Error::new(io::ErrorKind::InvalidData, "not a TAP header"))
};
if let Some(chunk_size) = rd.next_chunk()? {
if chunk_size < 2 || header.length != chunk_size - 2 {
return Err(io::Error::new(io::ErrorKind::InvalidData, "not a TAP block"))
}
let mut flag = 0u8;
rd.read_exact(slice::from_mut(&mut flag))?;
if flag != DATA_BLOCK_FLAG {
return Err(io::Error::new(io::ErrorKind::InvalidData, "invalid TAP block flag"))
}
}
else {
return Err(io::Error::new(io::ErrorKind::InvalidData, "missing TAP chunk"))
}
let fbheader = MdrFileHeader::from(&header).into_array();
let hdrd = io::Cursor::new(fbheader).chain(rd.take(header.length as u64));
let res = self.store_file(header.name, true, hdrd)?;
{
let mut checksum = 0u8;
let res = rd.read_exact(slice::from_mut(&mut checksum));
if res.is_err() || rd.checksum != 0 {
self.erase_file(header.name);
return Err(io::Error::new(io::ErrorKind::InvalidData, "TAP block checksum error"))
}
}
Ok(res)
}
Trait Implementations§
source§impl Clone for MdrFileHeader
impl Clone for MdrFileHeader
source§fn clone(&self) -> MdrFileHeader
fn clone(&self) -> MdrFileHeader
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl Debug for MdrFileHeader
impl Debug for MdrFileHeader
source§impl Default for MdrFileHeader
impl Default for MdrFileHeader
source§fn default() -> MdrFileHeader
fn default() -> MdrFileHeader
Returns the “default value” for a type. Read more
source§impl From<&Header> for MdrFileHeader
impl From<&Header> for MdrFileHeader
source§impl From<&MdrFileHeader> for Header
impl From<&MdrFileHeader> for Header
source§fn from(fbh: &MdrFileHeader) -> Self
fn from(fbh: &MdrFileHeader) -> Self
Converts to this type from the input type.
source§impl PartialEq<MdrFileHeader> for MdrFileHeader
impl PartialEq<MdrFileHeader> for MdrFileHeader
source§fn eq(&self, other: &MdrFileHeader) -> bool
fn eq(&self, other: &MdrFileHeader) -> bool
source§impl TryFrom<&[u8]> for &MdrFileHeader
impl TryFrom<&[u8]> for &MdrFileHeader
impl Copy for MdrFileHeader
impl Eq for MdrFileHeader
impl StructuralEq for MdrFileHeader
impl StructuralPartialEq for MdrFileHeader
Auto Trait Implementations§
impl RefUnwindSafe for MdrFileHeader
impl Send for MdrFileHeader
impl Sync for MdrFileHeader
impl Unpin for MdrFileHeader
impl UnwindSafe for MdrFileHeader
Blanket Implementations§
§impl<T> Conv for T
impl<T> Conv for T
§impl<T> FmtForward for T
impl<T> FmtForward for T
§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
Causes
self
to use its Binary
implementation when Debug
-formatted.§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
Causes
self
to use its Octal
implementation when Debug
-formatted.§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
§fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
Formats each item in a sequence. Read more
source§impl<S, T> IntoSample<S> for Twhere
S: FromSample<T>,
impl<S, T> IntoSample<S> for Twhere
S: FromSample<T>,
source§fn into_sample(self) -> S
fn into_sample(self) -> S
Convert to
S
a sample type from self
.§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Pipes by value. This is generally the method you want to use. Read more
§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
Borrows
self
and passes that borrow into the pipe function. Read more§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
Mutably borrows
self
and passes that borrow into the pipe function. Read more§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> Rwhere
Self: Borrow<B>,
B: 'a + ?Sized,
R: 'a,
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> Rwhere
Self: Borrow<B>,
B: 'a + ?Sized,
R: 'a,
§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R
) -> Rwhere
Self: BorrowMut<B>,
B: 'a + ?Sized,
R: 'a,
fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R
) -> Rwhere
Self: BorrowMut<B>,
B: 'a + ?Sized,
R: 'a,
§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> Rwhere
Self: AsRef<U>,
U: 'a + ?Sized,
R: 'a,
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> Rwhere
Self: AsRef<U>,
U: 'a + ?Sized,
R: 'a,
Borrows
self
, then passes self.as_ref()
into the pipe function.§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> Rwhere
Self: AsMut<U>,
U: 'a + ?Sized,
R: 'a,
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> Rwhere
Self: AsMut<U>,
U: 'a + ?Sized,
R: 'a,
§impl<T> Tap for T
impl<T> Tap for T
§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Selfwhere
Self: Borrow<B>,
B: ?Sized,
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Selfwhere
Self: Borrow<B>,
B: ?Sized,
Immutable access to the
Borrow<B>
of a value. Read more§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Selfwhere
Self: BorrowMut<B>,
B: ?Sized,
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Selfwhere
Self: BorrowMut<B>,
B: ?Sized,
Mutable access to the
BorrowMut<B>
of a value. Read more§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Selfwhere
Self: AsRef<R>,
R: ?Sized,
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Selfwhere
Self: AsRef<R>,
R: ?Sized,
Immutable access to the
AsRef<R>
view of a value. Read more§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Selfwhere
Self: AsMut<R>,
R: ?Sized,
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Selfwhere
Self: AsMut<R>,
R: ?Sized,
Mutable access to the
AsMut<R>
view of a value. Read more§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Selfwhere
Self: Deref<Target = T>,
T: ?Sized,
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Selfwhere
Self: Deref<Target = T>,
T: ?Sized,
Immutable access to the
Deref::Target
of a value. Read more§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Selfwhere
Self: DerefMut<Target = T> + Deref,
T: ?Sized,
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Selfwhere
Self: DerefMut<Target = T> + Deref,
T: ?Sized,
Mutable access to the
Deref::Target
of a value. Read more§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
Calls
.tap()
only in debug builds, and is erased in release builds.§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
Calls
.tap_mut()
only in debug builds, and is erased in release
builds. Read more§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Selfwhere
Self: Borrow<B>,
B: ?Sized,
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Selfwhere
Self: Borrow<B>,
B: ?Sized,
Calls
.tap_borrow()
only in debug builds, and is erased in release
builds. Read more§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Selfwhere
Self: BorrowMut<B>,
B: ?Sized,
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Selfwhere
Self: BorrowMut<B>,
B: ?Sized,
Calls
.tap_borrow_mut()
only in debug builds, and is erased in release
builds. Read more§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Selfwhere
Self: AsRef<R>,
R: ?Sized,
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Selfwhere
Self: AsRef<R>,
R: ?Sized,
Calls
.tap_ref()
only in debug builds, and is erased in release
builds. Read more§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Selfwhere
Self: AsMut<R>,
R: ?Sized,
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Selfwhere
Self: AsMut<R>,
R: ?Sized,
Calls
.tap_ref_mut()
only in debug builds, and is erased in release
builds. Read more