mirror of
https://github.com/TomHarte/CLK.git
synced 2024-09-08 03:54:27 +00:00
Merge pull request #165 from TomHarte/HalfCycleTyper
Brings `Typer` into the new `run_for` orthodoxy
This commit is contained in:
commit
1fb158b297
@ -98,6 +98,8 @@ template <class T> class WrappedInt {
|
|||||||
inline T operator +(const T &rhs) const { return T(length_ + rhs.length_); }
|
inline T operator +(const T &rhs) const { return T(length_ + rhs.length_); }
|
||||||
inline T operator -(const T &rhs) const { return T(length_ - rhs.length_); }
|
inline T operator -(const T &rhs) const { return T(length_ - rhs.length_); }
|
||||||
|
|
||||||
|
inline T operator -() const { return T(- length_); }
|
||||||
|
|
||||||
inline bool operator <(const T &rhs) const { return length_ < rhs.length_; }
|
inline bool operator <(const T &rhs) const { return length_ < rhs.length_; }
|
||||||
inline bool operator >(const T &rhs) const { return length_ > rhs.length_; }
|
inline bool operator >(const T &rhs) const { return length_ > rhs.length_; }
|
||||||
inline bool operator <=(const T &rhs) const { return length_ <= rhs.length_; }
|
inline bool operator <=(const T &rhs) const { return length_ <= rhs.length_; }
|
||||||
|
@ -327,7 +327,7 @@ Cycles Machine::perform_bus_operation(CPU::MOS6502::BusOperation operation, uint
|
|||||||
queue_next_display_interrupt();
|
queue_next_display_interrupt();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(typer_) typer_->update((int)cycles);
|
if(typer_) typer_->run_for(Cycles((int)cycles));
|
||||||
if(plus3_) plus3_->run_for(Cycles(4*(int)cycles));
|
if(plus3_) plus3_->run_for(Cycles(4*(int)cycles));
|
||||||
if(shift_restart_counter_) {
|
if(shift_restart_counter_) {
|
||||||
shift_restart_counter_ -= cycles;
|
shift_restart_counter_ -= cycles;
|
||||||
|
@ -101,8 +101,8 @@ class Machine:
|
|||||||
virtual void tape_did_change_interrupt_status(Tape *tape);
|
virtual void tape_did_change_interrupt_status(Tape *tape);
|
||||||
|
|
||||||
// for Utility::TypeRecipient
|
// for Utility::TypeRecipient
|
||||||
virtual int get_typer_delay();
|
virtual HalfCycles get_typer_delay();
|
||||||
virtual int get_typer_frequency();
|
virtual HalfCycles get_typer_frequency();
|
||||||
uint16_t *sequence_for_character(Utility::Typer *typer, char character);
|
uint16_t *sequence_for_character(Utility::Typer *typer, char character);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -8,12 +8,12 @@
|
|||||||
|
|
||||||
#include "Electron.hpp"
|
#include "Electron.hpp"
|
||||||
|
|
||||||
int Electron::Machine::get_typer_delay() {
|
HalfCycles Electron::Machine::get_typer_delay() {
|
||||||
return get_is_resetting() ? 625*25*128 : 0; // wait one second if resetting
|
return get_is_resetting() ? Cycles(625*25*128) : Cycles(0); // wait one second if resetting
|
||||||
}
|
}
|
||||||
|
|
||||||
int Electron::Machine::get_typer_frequency() {
|
HalfCycles Electron::Machine::get_typer_frequency() {
|
||||||
return 625*128*2; // accept a new character every two frames
|
return Cycles(625*128*2); // accept a new character every two frames
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t *Electron::Machine::sequence_for_character(Utility::Typer *typer, char character) {
|
uint16_t *Electron::Machine::sequence_for_character(Utility::Typer *typer, char character) {
|
||||||
|
@ -11,14 +11,14 @@
|
|||||||
|
|
||||||
using namespace Utility;
|
using namespace Utility;
|
||||||
|
|
||||||
Typer::Typer(const char *string, int delay, int frequency, Delegate *delegate) :
|
Typer::Typer(const char *string, HalfCycles delay, HalfCycles frequency, Delegate *delegate) :
|
||||||
counter_(-delay), frequency_(frequency), string_pointer_(0), delegate_(delegate), phase_(0) {
|
counter_(-delay), frequency_(frequency), string_pointer_(0), delegate_(delegate), phase_(0) {
|
||||||
size_t string_size = strlen(string) + 3;
|
size_t string_size = strlen(string) + 3;
|
||||||
string_ = (char *)malloc(string_size);
|
string_ = (char *)malloc(string_size);
|
||||||
snprintf(string_, string_size, "%c%s%c", Typer::BeginString, string, Typer::EndString);
|
snprintf(string_, string_size, "%c%s%c", Typer::BeginString, string, Typer::EndString);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Typer::update(int duration) {
|
void Typer::run_for(HalfCycles duration) {
|
||||||
if(string_) {
|
if(string_) {
|
||||||
if(counter_ < 0 && counter_ + duration >= 0) {
|
if(counter_ < 0 && counter_ + duration >= 0) {
|
||||||
if(!type_next_character()) {
|
if(!type_next_character()) {
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include "KeyboardMachine.hpp"
|
#include "KeyboardMachine.hpp"
|
||||||
|
#include "../ClockReceiver/ClockReceiver.hpp"
|
||||||
|
|
||||||
namespace Utility {
|
namespace Utility {
|
||||||
|
|
||||||
@ -30,9 +31,9 @@ class Typer {
|
|||||||
const uint16_t NotMapped = 0xfffe;
|
const uint16_t NotMapped = 0xfffe;
|
||||||
};
|
};
|
||||||
|
|
||||||
Typer(const char *string, int delay, int frequency, Delegate *delegate);
|
Typer(const char *string, HalfCycles delay, HalfCycles frequency, Delegate *delegate);
|
||||||
~Typer();
|
~Typer();
|
||||||
void update(int duration);
|
void run_for(HalfCycles duration);
|
||||||
bool type_next_character();
|
bool type_next_character();
|
||||||
|
|
||||||
const char BeginString = 0x02; // i.e. ASCII start of text
|
const char BeginString = 0x02; // i.e. ASCII start of text
|
||||||
@ -40,8 +41,8 @@ class Typer {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
char *string_;
|
char *string_;
|
||||||
int frequency_;
|
HalfCycles frequency_;
|
||||||
int counter_;
|
HalfCycles counter_;
|
||||||
int phase_;
|
int phase_;
|
||||||
Delegate *delegate_;
|
Delegate *delegate_;
|
||||||
size_t string_pointer_;
|
size_t string_pointer_;
|
||||||
@ -58,8 +59,8 @@ class TypeRecipient: public Typer::Delegate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual int get_typer_delay() { return 0; }
|
virtual HalfCycles get_typer_delay() { return HalfCycles(0); }
|
||||||
virtual int get_typer_frequency() { return 0; }
|
virtual HalfCycles get_typer_frequency() { return HalfCycles(0); }
|
||||||
std::unique_ptr<Typer> typer_;
|
std::unique_ptr<Typer> typer_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -183,8 +183,7 @@ HalfCycles Machine::perform_machine_cycle(const CPU::Z80::PartialMachineCycle &c
|
|||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// This will lose some precision; TODO: bring inside the [Half]ClockReceiver domain.
|
if(typer_) typer_->run_for(cycle.length);
|
||||||
if(typer_) typer_->update(cycle.length.as_int() / 2);
|
|
||||||
|
|
||||||
return HalfCycles(0);
|
return HalfCycles(0);
|
||||||
}
|
}
|
||||||
|
@ -75,8 +75,8 @@ class Machine:
|
|||||||
|
|
||||||
// for Utility::TypeRecipient::Delegate
|
// for Utility::TypeRecipient::Delegate
|
||||||
uint16_t *sequence_for_character(Utility::Typer *typer, char character);
|
uint16_t *sequence_for_character(Utility::Typer *typer, char character);
|
||||||
int get_typer_delay() { return 7000000; }
|
HalfCycles get_typer_delay() { return Cycles(7000000); }
|
||||||
int get_typer_frequency() { return 390000; }
|
HalfCycles get_typer_frequency() { return Cycles(390000); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<Video> video_;
|
std::shared_ptr<Video> video_;
|
||||||
|
Loading…
Reference in New Issue
Block a user