summaryrefslogtreecommitdiffstatshomepage
path: root/src/lib/formats/hti_tape.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/formats/hti_tape.cpp')
-rw-r--r--src/lib/formats/hti_tape.cpp34
1 files changed, 19 insertions, 15 deletions
diff --git a/src/lib/formats/hti_tape.cpp b/src/lib/formats/hti_tape.cpp
index 29bab6cd51c..7f77e3f99df 100644
--- a/src/lib/formats/hti_tape.cpp
+++ b/src/lib/formats/hti_tape.cpp
@@ -12,7 +12,8 @@
static constexpr uint32_t OLD_FILE_MAGIC = 0x5441434f; // Magic value at start of old-format image file: "TACO"
-static constexpr uint32_t FILE_MAGIC = 0x48544930; // Magic value at start of image file: "HTI0"
+static constexpr uint32_t FILE_MAGIC_DELTA = 0x48544930; // Magic value at start of delta-modulation image file: "HTI0"
+static constexpr uint32_t FILE_MAGIC_MANCHESTER = 0x48544931; // Magic value at start of manchester-modulation image file: "HTI1"
// *** Position of tape holes ***
// At beginning of tape:
@@ -41,7 +42,7 @@ static const hti_format_t::tape_pos_t tape_holes[] = {
};
hti_format_t::hti_format_t()
- : m_bits_per_word(16)
+ : m_img_format(HTI_DELTA_MOD_16_BITS)
{
clear_tape();
}
@@ -52,13 +53,15 @@ bool hti_format_t::load_tape(io_generic *io)
io_generic_read(io, tmp, 0, 4);
auto magic = pick_integer_be(tmp , 0 , 4);
- if (magic != FILE_MAGIC && magic != OLD_FILE_MAGIC) {
+ if (((m_img_format == HTI_DELTA_MOD_16_BITS || m_img_format == HTI_DELTA_MOD_17_BITS) && magic != FILE_MAGIC_DELTA && magic != OLD_FILE_MAGIC) ||
+ (m_img_format == HTI_MANCHESTER_MOD && magic != FILE_MAGIC_MANCHESTER)) {
return false;
}
uint64_t offset = 4;
- for (tape_track_t& track : m_tracks) {
+ for (unsigned i = 0; i < no_of_tracks(); i++) {
+ tape_track_t& track = m_tracks[ i ];
if (!load_track(io , offset , track , magic == OLD_FILE_MAGIC)) {
clear_tape();
return false;
@@ -72,12 +75,13 @@ void hti_format_t::save_tape(io_generic *io)
{
uint8_t tmp[ 4 ];
- place_integer_be(tmp, 0, 4, FILE_MAGIC);
+ place_integer_be(tmp, 0, 4, m_img_format == HTI_MANCHESTER_MOD ? FILE_MAGIC_MANCHESTER : FILE_MAGIC_DELTA);
io_generic_write(io, tmp, 0, 4);
uint64_t offset = 4;
- for (const tape_track_t& track : m_tracks) {
+ for (unsigned i = 0; i < no_of_tracks(); i++) {
+ const tape_track_t& track = m_tracks[ i ];
tape_pos_t next_pos = (tape_pos_t)-1;
unsigned n_words = 0;
tape_track_t::const_iterator it_start;
@@ -105,7 +109,7 @@ void hti_format_t::clear_tape()
}
}
-hti_format_t::tape_pos_t hti_format_t::word_length(tape_word_t w)
+hti_format_t::tape_pos_t hti_format_t::word_length(tape_word_t w) const
{
unsigned zeros , ones;
@@ -117,10 +121,10 @@ hti_format_t::tape_pos_t hti_format_t::word_length(tape_word_t w)
zeros = 16 - ones;
- return zeros * ZERO_BIT_LEN + ones * ONE_BIT_LEN;
+ return zeros * bit_length(false) + ones * bit_length(true);
}
-hti_format_t::tape_pos_t hti_format_t::farthest_end(const track_iterator_t& it , bool forward)
+hti_format_t::tape_pos_t hti_format_t::farthest_end(const track_iterator_t& it , bool forward) const
{
if (forward) {
return word_end_pos(it);
@@ -190,7 +194,7 @@ void hti_format_t::write_word(unsigned track_no , tape_pos_t start , tape_word_t
// as the record expands & contracts when re-written with different content.
// Without this fix, a gap could form in the slack big enough to cause
// false gap detections.
- if (forward && it_high != track.end() && (it_high->first - end_pos) >= (ZERO_BIT_LEN * 16)) {
+ if (forward && it_high != track.end() && (it_high->first - end_pos) >= (bit_length(false) * 16)) {
track.insert(it_high, std::make_pair(end_pos, 0));
it_high--;
}
@@ -414,7 +418,7 @@ bool hti_format_t::load_track(io_generic *io , uint64_t& offset , tape_track_t&
if (!old_format) {
track.insert(std::make_pair(pos , tmp16));
pos += word_length(tmp16);
- } else if (m_bits_per_word == 16) {
+ } else if (m_img_format == HTI_DELTA_MOD_16_BITS) {
// Convert HP9845 & HP85 old format
// Basically, in old format each word had 17 bits (an implicit 1
// was added at the end). In new format we just keep the 16 bits
@@ -429,7 +433,7 @@ bool hti_format_t::load_track(io_generic *io , uint64_t& offset , tape_track_t&
track.insert(std::make_pair(pos, tmp16));
pos += word_length(tmp16);
last_word_end = pos;
- delta_pos -= ONE_BIT_LEN;
+ delta_pos -= DELTA_ONE_BIT_LEN;
} else {
// Convert HP9825 old format
// In moving from old to new format we make the 17th bit at the
@@ -458,7 +462,7 @@ bool hti_format_t::load_track(io_generic *io , uint64_t& offset , tape_track_t&
}
if (bits_in_accum) {
track.insert(std::make_pair(pos, word_accum));
- tape_pos_t shift = (tape_pos_t)(16 - bits_in_accum) * ZERO_BIT_LEN;
+ tape_pos_t shift = (tape_pos_t)(16 - bits_in_accum) * DELTA_ZERO_BIT_LEN;
delta_pos += shift;
last_word_end = pos + word_length(word_accum);
}
@@ -483,12 +487,12 @@ void hti_format_t::dump_sequence(io_generic *io , uint64_t& offset , tape_track_
}
}
-hti_format_t::tape_pos_t hti_format_t::word_end_pos(const track_iterator_t& it)
+hti_format_t::tape_pos_t hti_format_t::word_end_pos(const track_iterator_t& it) const
{
return it->first + word_length(it->second);
}
-void hti_format_t::adjust_it(tape_track_t& track , track_iterator_t& it , tape_pos_t pos)
+void hti_format_t::adjust_it(tape_track_t& track , track_iterator_t& it , tape_pos_t pos) const
{
if (it != track.begin()) {
--it;