From 21ca1ef86bde581cb45135ee5f733e45e2e9a5f3 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sat, 12 Mar 2016 23:19:10 -0500 Subject: [PATCH] Started attempting to clarify instance variable usage. --- Storage/Tape/Formats/TapeUEF.cpp | 36 +++++++++++++++++++++----------- Storage/Tape/Formats/TapeUEF.hpp | 12 +++++++++++ 2 files changed, 36 insertions(+), 12 deletions(-) diff --git a/Storage/Tape/Formats/TapeUEF.cpp b/Storage/Tape/Formats/TapeUEF.cpp index 387bb0bf5..7ed0d8818 100644 --- a/Storage/Tape/Formats/TapeUEF.cpp +++ b/Storage/Tape/Formats/TapeUEF.cpp @@ -176,7 +176,12 @@ void Storage::UEF::find_next_tape_chunk() switch(_chunk_id) { - case 0x0100: case 0x0102: // implicit and explicit bit patterns + case 0x0100: // implicit bit pattern + _implicit_data_chunk.position = 0; + return; + + case 0x0102: // explicit bit patterns + _explicit_data_chunk.position = 0; return; case 0x0112: // integer gap @@ -233,8 +238,8 @@ bool Storage::UEF::chunk_is_finished() { switch(_chunk_id) { - case 0x0100: return (_chunk_position / 10) == _chunk_length; - case 0x0102: return (_chunk_position / 8) == _chunk_length; + case 0x0100: return (_implicit_data_chunk.position / 10) == _chunk_length; + case 0x0102: return (_explicit_data_chunk.position / 8) == _chunk_length; case 0x0114: case 0x0110: return _chunk_position == _chunk_duration.length; @@ -251,16 +256,24 @@ bool Storage::UEF::get_next_bit() { case 0x0100: { - uint32_t bit_position = _chunk_position%10; - _chunk_position++; - if(!bit_position) - { - _current_byte = (uint8_t)gzgetc(_file); - } + uint32_t bit_position = _implicit_data_chunk.position%10; + _implicit_data_chunk.position++; + if(!bit_position) _implicit_data_chunk.current_byte = (uint8_t)gzgetc(_file); if(bit_position == 0) return false; if(bit_position == 9) return true; - bool result = (_current_byte&1) ? true : false; - _current_byte >>= 1; + bool result = (_implicit_data_chunk.current_byte&1) ? true : false; + _implicit_data_chunk.current_byte >>= 1; + return result; + } + break; + + case 0x0102: + { + uint32_t bit_position = _explicit_data_chunk.position%8; + _explicit_data_chunk.position++; + if(!bit_position) _explicit_data_chunk.current_byte = (uint8_t)gzgetc(_file); + bool result = (_explicit_data_chunk.current_byte&1) ? true : false; + _explicit_data_chunk.current_byte >>= 1; return result; } break; @@ -268,7 +281,6 @@ bool Storage::UEF::get_next_bit() // TODO: 0x0104, 0x0111 case 0x0114: - case 0x0102: { uint32_t bit_position = _chunk_position%8; _chunk_position++; diff --git a/Storage/Tape/Formats/TapeUEF.hpp b/Storage/Tape/Formats/TapeUEF.hpp index fe86ecaef..bb7676e41 100644 --- a/Storage/Tape/Formats/TapeUEF.hpp +++ b/Storage/Tape/Formats/TapeUEF.hpp @@ -35,6 +35,18 @@ class UEF : public Tape { uint16_t _chunk_id; uint32_t _chunk_length; + union { + struct { + uint8_t current_byte; + uint32_t position; + } _implicit_data_chunk; + + struct { + uint8_t current_byte; + uint32_t position; + } _explicit_data_chunk; + }; + uint8_t _current_byte; uint32_t _chunk_position;