1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-11-26 08:49:37 +00:00

Factors proceed_to_symbol upwards.

This commit is contained in:
Thomas Harte 2021-03-07 20:48:51 -05:00
parent 40516c9cec
commit ab5e4ca9c7
3 changed files with 13 additions and 19 deletions

View File

@ -136,7 +136,7 @@ std::unique_ptr<Data> Parser::get_next_data_body(const std::shared_ptr<Storage::
// accumulate until the next non-word marker is hit
while(!tape->is_at_end()) {
SymbolType start_symbol = get_next_symbol(tape);
const SymbolType start_symbol = get_next_symbol(tape);
if(start_symbol != SymbolType::Word) break;
data->data.push_back(get_next_byte_contents(tape));
}
@ -171,17 +171,6 @@ void Parser::proceed_to_landing_zone(const std::shared_ptr<Storage::Tape::Tape>
}
}
/*!
Swallows symbols until it reaches the first instance of the required symbol, swallows that
and returns.
*/
void Parser::proceed_to_symbol(const std::shared_ptr<Storage::Tape::Tape> &tape, SymbolType required_symbol) {
while(!tape->is_at_end()) {
const SymbolType symbol = get_next_symbol(tape);
if(symbol == required_symbol) return;
}
}
/*!
Swallows the next byte; sets the error flag if it is not equal to @c value.
*/
@ -211,7 +200,7 @@ uint8_t Parser::get_next_byte_contents(const std::shared_ptr<Storage::Tape::Tape
int byte_plus_parity = 0;
int c = 9;
while(c--) {
SymbolType next_symbol = get_next_symbol(tape);
const SymbolType next_symbol = get_next_symbol(tape);
if((next_symbol != SymbolType::One) && (next_symbol != SymbolType::Zero)) set_error_flag();
byte_plus_parity = (byte_plus_parity >> 1) | (((next_symbol == SymbolType::One) ? 1 : 0) << 8);
}

View File

@ -88,12 +88,6 @@ class Parser: public Storage::Tape::PulseClassificationParser<WaveType, SymbolTy
*/
void proceed_to_landing_zone(const std::shared_ptr<Storage::Tape::Tape> &tape, bool is_original);
/*!
Swallows symbols until it reaches the first instance of the required symbol, swallows that
and returns.
*/
void proceed_to_symbol(const std::shared_ptr<Storage::Tape::Tape> &tape, SymbolType required_symbol);
/*!
Swallows the next byte; sets the error flag if it is not equal to @c value.
*/

View File

@ -56,6 +56,17 @@ template <typename SymbolType> class Parser {
return tape->is_at_end() && !has_next_symbol_;
}
/*!
Swallows symbols until it reaches the first instance of the required symbol, swallows that
and returns.
*/
void proceed_to_symbol(const std::shared_ptr<Storage::Tape::Tape> &tape, SymbolType required_symbol) {
while(!is_at_end(tape)) {
const SymbolType symbol = get_next_symbol(tape);
if(symbol == required_symbol) return;
}
}
protected:
/*!
Should be implemented by subclasses. Consumes @c pulse.