2016-12-03 17:18:08 +00:00
|
|
|
//
|
|
|
|
// Tape.cpp
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 03/12/2016.
|
2018-05-13 19:19:52 +00:00
|
|
|
// Copyright 2016 Thomas Harte. All rights reserved.
|
2016-12-03 17:18:08 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
#include "Tape.hpp"
|
|
|
|
|
|
|
|
using namespace Electron;
|
|
|
|
|
2017-09-01 02:29:24 +00:00
|
|
|
Tape::Tape() : TapePlayer(2000000) {
|
2017-07-16 23:24:01 +00:00
|
|
|
shifter_.set_delegate(this);
|
|
|
|
}
|
2017-03-26 18:34:47 +00:00
|
|
|
|
|
|
|
void Tape::push_tape_bit(uint16_t bit) {
|
2017-10-22 01:50:53 +00:00
|
|
|
data_register_ = static_cast<uint16_t>((data_register_ >> 1) | (bit << 10));
|
2016-12-03 17:18:08 +00:00
|
|
|
|
|
|
|
if(input_.minimum_bits_until_full) input_.minimum_bits_until_full--;
|
|
|
|
if(input_.minimum_bits_until_full == 8) interrupt_status_ &= ~Interrupt::ReceiveDataFull;
|
2017-03-26 18:34:47 +00:00
|
|
|
if(!input_.minimum_bits_until_full) {
|
|
|
|
if((data_register_&0x3) == 0x1) {
|
2016-12-03 17:18:08 +00:00
|
|
|
interrupt_status_ |= Interrupt::ReceiveDataFull;
|
|
|
|
if(is_in_input_mode_) input_.minimum_bits_until_full = 9;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(output_.bits_remaining_until_empty) output_.bits_remaining_until_empty--;
|
|
|
|
if(!output_.bits_remaining_until_empty) interrupt_status_ |= Interrupt::TransmitDataEmpty;
|
|
|
|
|
|
|
|
if(data_register_ == 0x3ff) interrupt_status_ |= Interrupt::HighToneDetect;
|
|
|
|
else interrupt_status_ &= ~Interrupt::HighToneDetect;
|
|
|
|
|
|
|
|
evaluate_interrupts();
|
|
|
|
}
|
|
|
|
|
2017-03-26 18:34:47 +00:00
|
|
|
void Tape::evaluate_interrupts() {
|
|
|
|
if(last_posted_interrupt_status_ != interrupt_status_) {
|
2016-12-03 17:18:08 +00:00
|
|
|
last_posted_interrupt_status_ = interrupt_status_;
|
|
|
|
if(delegate_) delegate_->tape_did_change_interrupt_status(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-26 18:34:47 +00:00
|
|
|
void Tape::clear_interrupts(uint8_t interrupts) {
|
2016-12-03 17:18:08 +00:00
|
|
|
interrupt_status_ &= ~interrupts;
|
|
|
|
evaluate_interrupts();
|
|
|
|
}
|
|
|
|
|
2017-03-26 18:34:47 +00:00
|
|
|
void Tape::set_is_in_input_mode(bool is_in_input_mode) {
|
2016-12-03 17:18:08 +00:00
|
|
|
is_in_input_mode_ = is_in_input_mode;
|
|
|
|
}
|
|
|
|
|
2017-03-26 18:34:47 +00:00
|
|
|
void Tape::set_counter(uint8_t value) {
|
2016-12-03 17:18:08 +00:00
|
|
|
output_.cycles_into_pulse = 0;
|
|
|
|
output_.bits_remaining_until_empty = 0;
|
|
|
|
}
|
|
|
|
|
2017-03-26 18:34:47 +00:00
|
|
|
void Tape::set_data_register(uint8_t value) {
|
2017-10-22 01:50:53 +00:00
|
|
|
data_register_ = static_cast<uint16_t>((value << 2) | 1);
|
2016-12-03 17:18:08 +00:00
|
|
|
output_.bits_remaining_until_empty = 9;
|
|
|
|
}
|
|
|
|
|
2017-03-26 18:34:47 +00:00
|
|
|
uint8_t Tape::get_data_register() {
|
2017-10-22 01:50:53 +00:00
|
|
|
return static_cast<uint8_t>(data_register_ >> 2);
|
2016-12-03 17:18:08 +00:00
|
|
|
}
|
|
|
|
|
2017-07-16 23:49:31 +00:00
|
|
|
void Tape::process_input_pulse(const Storage::Tape::Tape::Pulse &pulse) {
|
2017-07-16 23:24:01 +00:00
|
|
|
shifter_.process_pulse(pulse);
|
|
|
|
}
|
2016-12-03 17:18:08 +00:00
|
|
|
|
2017-07-16 23:24:01 +00:00
|
|
|
void Tape::acorn_shifter_output_bit(int value) {
|
2017-10-22 01:50:53 +00:00
|
|
|
push_tape_bit(static_cast<uint16_t>(value));
|
2016-12-03 17:18:08 +00:00
|
|
|
}
|
|
|
|
|
2017-07-28 02:05:29 +00:00
|
|
|
void Tape::run_for(const Cycles cycles) {
|
2017-03-26 18:34:47 +00:00
|
|
|
if(is_enabled_) {
|
|
|
|
if(is_in_input_mode_) {
|
|
|
|
if(is_running_) {
|
2017-07-25 01:36:30 +00:00
|
|
|
TapePlayer::run_for(cycles);
|
2016-12-03 17:18:08 +00:00
|
|
|
}
|
2017-03-26 18:34:47 +00:00
|
|
|
} else {
|
2017-10-21 23:49:04 +00:00
|
|
|
output_.cycles_into_pulse += static_cast<unsigned int>(cycles.as_int());
|
2017-03-26 18:34:47 +00:00
|
|
|
while(output_.cycles_into_pulse > 1664) { // 1664 = the closest you can get to 1200 baud if you're looking for something
|
|
|
|
output_.cycles_into_pulse -= 1664; // that divides the 125,000Hz clock that the sound divider runs off.
|
2016-12-03 17:18:08 +00:00
|
|
|
push_tape_bit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|