2016-01-18 21:46:41 +00:00
|
|
|
//
|
|
|
|
// Tape.cpp
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 18/01/2016.
|
|
|
|
// Copyright © 2016 Thomas Harte. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#include "Tape.hpp"
|
2016-07-29 09:19:01 +00:00
|
|
|
#include "../../NumberTheory/Factors.hpp"
|
2016-01-18 21:46:41 +00:00
|
|
|
|
2016-08-27 21:18:12 +00:00
|
|
|
using namespace Storage::Tape;
|
2016-01-18 21:46:41 +00:00
|
|
|
|
2016-08-27 21:09:45 +00:00
|
|
|
void Storage::Tape::Tape::seek(Time seek_time)
|
2016-01-18 21:46:41 +00:00
|
|
|
{
|
|
|
|
// TODO: as best we can
|
|
|
|
}
|
2016-06-26 23:03:57 +00:00
|
|
|
|
|
|
|
TapePlayer::TapePlayer(unsigned int input_clock_rate) :
|
2016-07-29 11:15:46 +00:00
|
|
|
TimedEventLoop(input_clock_rate)
|
2016-06-26 23:03:57 +00:00
|
|
|
{}
|
|
|
|
|
2016-08-27 21:09:45 +00:00
|
|
|
void TapePlayer::set_tape(std::shared_ptr<Storage::Tape::Tape> tape)
|
2016-06-26 23:03:57 +00:00
|
|
|
{
|
|
|
|
_tape = tape;
|
2016-07-29 11:15:46 +00:00
|
|
|
reset_timer();
|
2016-06-26 23:03:57 +00:00
|
|
|
get_next_pulse();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TapePlayer::has_tape()
|
|
|
|
{
|
|
|
|
return (bool)_tape;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TapePlayer::get_next_pulse()
|
|
|
|
{
|
2016-07-29 09:19:01 +00:00
|
|
|
// get the new pulse
|
2016-06-26 23:03:57 +00:00
|
|
|
if(_tape)
|
2016-07-29 11:15:46 +00:00
|
|
|
_current_pulse = _tape->get_next_pulse();
|
2016-06-26 23:03:57 +00:00
|
|
|
else
|
|
|
|
{
|
2016-07-29 11:15:46 +00:00
|
|
|
_current_pulse.length.length = 1;
|
|
|
|
_current_pulse.length.clock_rate = 1;
|
2016-08-27 21:09:45 +00:00
|
|
|
_current_pulse.type = Tape::Pulse::Zero;
|
2016-06-26 23:03:57 +00:00
|
|
|
}
|
2016-07-29 09:19:01 +00:00
|
|
|
|
2016-07-29 11:15:46 +00:00
|
|
|
set_next_event_time_interval(_current_pulse.length);
|
2016-06-26 23:03:57 +00:00
|
|
|
}
|
|
|
|
|
2016-07-29 15:03:09 +00:00
|
|
|
void TapePlayer::run_for_cycles(int number_of_cycles)
|
2016-06-26 23:03:57 +00:00
|
|
|
{
|
|
|
|
if(has_tape())
|
|
|
|
{
|
2016-08-27 21:18:12 +00:00
|
|
|
TimedEventLoop::run_for_cycles(number_of_cycles);
|
2016-06-26 23:03:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TapePlayer::run_for_input_pulse()
|
|
|
|
{
|
2016-07-29 11:15:46 +00:00
|
|
|
jump_to_next_event();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TapePlayer::process_next_event()
|
|
|
|
{
|
|
|
|
process_input_pulse(_current_pulse);
|
2016-06-26 23:03:57 +00:00
|
|
|
get_next_pulse();
|
|
|
|
}
|