Struct spectrusty_formats::tap::Header
source · pub struct Header {
pub length: u16,
pub block_type: BlockType,
pub name: [u8; 10],
pub par1: [u8; 2],
pub par2: [u8; 2],
}
Expand description
Represents the TAP header block.
Fields§
§length: u16
Length of the data block excluding a block flag and checksum byte.
block_type: BlockType
The type of the file this header represents.
name: [u8; 10]
A name of the file.
par1: [u8; 2]
Additional header data.
par2: [u8; 2]
Additional header data.
Implementations§
source§impl Header
impl Header
sourcepub fn new_code(length: u16) -> Self
pub fn new_code(length: u16) -> Self
Creates a Code
header.
Examples found in repository?
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)
}
}
}
sourcepub fn new_program(length: u16) -> Self
pub fn new_program(length: u16) -> Self
Creates a Program
header.
Examples found in repository?
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)
}
}
}
sourcepub fn new_number_array(length: u16) -> Self
pub fn new_number_array(length: u16) -> Self
Creates a NumberArray
header.
Examples found in repository?
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)
}
}
}
sourcepub fn new_char_array(length: u16) -> Self
pub fn new_char_array(length: u16) -> Self
Creates a CharArray
header.
Examples found in repository?
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)
}
}
}
sourcepub fn with_start(self, start: u16) -> Self
pub fn with_start(self, start: u16) -> Self
Examples found in repository?
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)
}
}
}
sourcepub fn with_vars(self, vars: u16) -> Self
pub fn with_vars(self, vars: u16) -> Self
Changes vars
, builder style.
Panics
Panics if self is not a Program
header or if given vars
exceeds length
.
Examples found in repository?
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)
}
}
}
sourcepub fn with_array_name(self, n: char) -> Self
pub fn with_array_name(self, n: char) -> Self
Changes array name, builder style.
Panics
Panics if self is not an array header or if given character is not ASCII alphabetic.
Examples found in repository?
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)
}
}
}
sourcepub fn name_str(&self) -> Cow<'_, str>
pub fn name_str(&self) -> Cow<'_, str>
Returns a header name as a string.
Examples found in repository?
373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
TapChunkInfo::Head(header) => {
write!(f, "{}: \"{}\"", header.block_type, header.name_str().trim_end())?;
match header.block_type {
BlockType::Program => {
if header.start() < 10000 {
write!(f, " LINE {}", header.start())?;
}
if header.vars() != header.length {
write!(f, " PROG {} VARS {}",
header.vars(), header.length - header.vars())?;
}
Ok(())
}
BlockType::NumberArray => {
write!(f, " DATA {}()", header.array_name())
}
BlockType::CharArray => {
write!(f, " DATA {}$()", header.array_name())
}
BlockType::Code => {
write!(f, " CODE {},{}", header.start(), header.length)
}
}
}
TapChunkInfo::Data {length, ..} => {
write!(f, "(data {})", length)
}
TapChunkInfo::Unknown {size, ..} => {
write!(f, "(unkown {})", size)
}
TapChunkInfo::Empty => {
write!(f, "(empty)")
}
}
}
sourcepub fn start(&self) -> u16
pub fn start(&self) -> u16
Returns a starting address. Depending of the type of this header it may be either a starting address of BlockType::Code or starting line of BlockType::Program.
Examples found in repository?
373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
TapChunkInfo::Head(header) => {
write!(f, "{}: \"{}\"", header.block_type, header.name_str().trim_end())?;
match header.block_type {
BlockType::Program => {
if header.start() < 10000 {
write!(f, " LINE {}", header.start())?;
}
if header.vars() != header.length {
write!(f, " PROG {} VARS {}",
header.vars(), header.length - header.vars())?;
}
Ok(())
}
BlockType::NumberArray => {
write!(f, " DATA {}()", header.array_name())
}
BlockType::CharArray => {
write!(f, " DATA {}$()", header.array_name())
}
BlockType::Code => {
write!(f, " CODE {},{}", header.start(), header.length)
}
}
}
TapChunkInfo::Data {length, ..} => {
write!(f, "(data {})", length)
}
TapChunkInfo::Unknown {size, ..} => {
write!(f, "(unkown {})", size)
}
TapChunkInfo::Empty => {
write!(f, "(empty)")
}
}
}
sourcepub fn vars(&self) -> u16
pub fn vars(&self) -> u16
Returns an offset to VARS
. Only valid for headers with BlockType::Program.
Examples found in repository?
373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
TapChunkInfo::Head(header) => {
write!(f, "{}: \"{}\"", header.block_type, header.name_str().trim_end())?;
match header.block_type {
BlockType::Program => {
if header.start() < 10000 {
write!(f, " LINE {}", header.start())?;
}
if header.vars() != header.length {
write!(f, " PROG {} VARS {}",
header.vars(), header.length - header.vars())?;
}
Ok(())
}
BlockType::NumberArray => {
write!(f, " DATA {}()", header.array_name())
}
BlockType::CharArray => {
write!(f, " DATA {}$()", header.array_name())
}
BlockType::Code => {
write!(f, " CODE {},{}", header.start(), header.length)
}
}
}
TapChunkInfo::Data {length, ..} => {
write!(f, "(data {})", length)
}
TapChunkInfo::Unknown {size, ..} => {
write!(f, "(unkown {})", size)
}
TapChunkInfo::Empty => {
write!(f, "(empty)")
}
}
}
sourcepub fn array_name(&self) -> char
pub fn array_name(&self) -> char
Returns an array variable name.
Only valid for headers with BlockType::CharArray or BlockType::NumberArray.
Examples found in repository?
373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
TapChunkInfo::Head(header) => {
write!(f, "{}: \"{}\"", header.block_type, header.name_str().trim_end())?;
match header.block_type {
BlockType::Program => {
if header.start() < 10000 {
write!(f, " LINE {}", header.start())?;
}
if header.vars() != header.length {
write!(f, " PROG {} VARS {}",
header.vars(), header.length - header.vars())?;
}
Ok(())
}
BlockType::NumberArray => {
write!(f, " DATA {}()", header.array_name())
}
BlockType::CharArray => {
write!(f, " DATA {}$()", header.array_name())
}
BlockType::Code => {
write!(f, " CODE {},{}", header.start(), header.length)
}
}
}
TapChunkInfo::Data {length, ..} => {
write!(f, "(data {})", length)
}
TapChunkInfo::Unknown {size, ..} => {
write!(f, "(unkown {})", size)
}
TapChunkInfo::Empty => {
write!(f, "(empty)")
}
}
}
sourcepub fn to_tap_chunk(&self) -> TapChunk<[u8; 19]>
pub fn to_tap_chunk(&self) -> TapChunk<[u8; 19]>
Returns a tap chunk created from self.
Trait Implementations§
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
impl Copy for Header
impl Eq for Header
impl StructuralEq for Header
impl StructuralPartialEq for Header
Auto Trait Implementations§
impl RefUnwindSafe for Header
impl Send for Header
impl Sync for Header
impl Unpin for Header
impl UnwindSafe for Header
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,
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,
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,
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
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,
§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,
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,
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,
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,
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,
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,
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,
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,
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,
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
.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
.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,
.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,
.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,
.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,
.tap_ref_mut()
only in debug builds, and is erased in release
builds. Read more