1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-11-30 04:50:08 +00:00

About face! There should be no delay on serialisation, but a delay on interpretation-affecting soft switches.

This commit is contained in:
Thomas Harte 2018-08-22 21:56:45 -04:00
parent e802f6ecc2
commit 61e46399dc
2 changed files with 156 additions and 94 deletions

View File

@ -24,7 +24,7 @@ VideoBase::VideoBase(bool is_iie) :
// Show only the centre 75% of the TV frame. // Show only the centre 75% of the TV frame.
crt_->set_video_signal(Outputs::CRT::VideoSignal::Composite); crt_->set_video_signal(Outputs::CRT::VideoSignal::Composite);
crt_->set_visible_area(Outputs::CRT::Rect(0.115f + 0.030769230769231f, 0.122f, 0.77f, 0.77f)); crt_->set_visible_area(Outputs::CRT::Rect(0.115f, 0.122f, 0.77f, 0.77f));
crt_->set_immediate_default_phase(0.0f); crt_->set_immediate_default_phase(0.0f);
} }
@ -36,67 +36,85 @@ Outputs::CRT::CRT *VideoBase::get_crt() {
Rote setters and getters. Rote setters and getters.
*/ */
void VideoBase::set_alternative_character_set(bool alternative_character_set) { void VideoBase::set_alternative_character_set(bool alternative_character_set) {
set_alternative_character_set_ = alternative_character_set;
defer(2, [=] {
alternative_character_set_ = alternative_character_set; alternative_character_set_ = alternative_character_set;
});
} }
bool VideoBase::get_alternative_character_set() { bool VideoBase::get_alternative_character_set() {
return alternative_character_set_; return set_alternative_character_set_;
} }
void VideoBase::set_80_columns(bool columns_80) { void VideoBase::set_80_columns(bool columns_80) {
set_columns_80_ = columns_80;
defer(2, [=] {
columns_80_ = columns_80; columns_80_ = columns_80;
});
} }
bool VideoBase::get_80_columns() { bool VideoBase::get_80_columns() {
return columns_80_; return set_columns_80_;
} }
void VideoBase::set_80_store(bool store_80) { void VideoBase::set_80_store(bool store_80) {
store_80_ = store_80; set_store_80_ = store_80_ = store_80;
} }
bool VideoBase::get_80_store() { bool VideoBase::get_80_store() {
return store_80_; return set_store_80_;
} }
void VideoBase::set_page2(bool page2) { void VideoBase::set_page2(bool page2) {
page2_ = page2; set_page2_ = page2_ = page2;
} }
bool VideoBase::get_page2() { bool VideoBase::get_page2() {
return page2_; return set_page2_;
} }
void VideoBase::set_text(bool text) { void VideoBase::set_text(bool text) {
set_text_ = text;
defer(2, [=] {
text_ = text; text_ = text;
});
} }
bool VideoBase::get_text() { bool VideoBase::get_text() {
return text_; return set_text_;
} }
void VideoBase::set_mixed(bool mixed) { void VideoBase::set_mixed(bool mixed) {
set_mixed_ = mixed;
defer(2, [=] {
mixed_ = mixed; mixed_ = mixed;
});
} }
bool VideoBase::get_mixed() { bool VideoBase::get_mixed() {
return mixed_; return set_mixed_;
} }
void VideoBase::set_high_resolution(bool high_resolution) { void VideoBase::set_high_resolution(bool high_resolution) {
set_high_resolution_ = high_resolution;
defer(2, [=] {
high_resolution_ = high_resolution; high_resolution_ = high_resolution;
});
} }
bool VideoBase::get_high_resolution() { bool VideoBase::get_high_resolution() {
return high_resolution_; return set_high_resolution_;
} }
void VideoBase::set_double_high_resolution(bool double_high_resolution) { void VideoBase::set_double_high_resolution(bool double_high_resolution) {
set_double_high_resolution_ = double_high_resolution;
defer(2, [=] {
double_high_resolution_ = double_high_resolution; double_high_resolution_ = double_high_resolution;
});
} }
bool VideoBase::get_double_high_resolution() { bool VideoBase::get_double_high_resolution() {
return double_high_resolution_; return set_double_high_resolution_;
} }
void VideoBase::set_character_rom(const std::vector<uint8_t> &character_rom) { void VideoBase::set_character_rom(const std::vector<uint8_t> &character_rom) {
@ -283,3 +301,7 @@ void VideoBase::output_double_high_resolution(uint8_t *target, uint8_t *source,
target += 14; target += 14;
} }
} }
void VideoBase::defer(int delay, const std::function<void(void)> &action) {
pending_actions_.emplace_back(delay, action);
}

View File

@ -165,14 +165,14 @@ class VideoBase {
bool is_double_mode(GraphicsMode m) { return !!(static_cast<int>(m)&1); } bool is_double_mode(GraphicsMode m) { return !!(static_cast<int>(m)&1); }
// Various soft-switch values. // Various soft-switch values.
bool alternative_character_set_ = false; bool alternative_character_set_ = false, set_alternative_character_set_ = false;
bool columns_80_ = false; bool columns_80_ = false, set_columns_80_ = false;
bool store_80_ = false; bool store_80_ = false, set_store_80_ = false;
bool page2_ = false; bool page2_ = false, set_page2_ = false;
bool text_ = true; bool text_ = true, set_text_ = true;
bool mixed_ = false; bool mixed_ = false, set_mixed_ = false;
bool high_resolution_ = false; bool high_resolution_ = false, set_high_resolution_ = false;
bool double_high_resolution_ = false; bool double_high_resolution_ = false, set_double_high_resolution_ = false;
// Graphics carry is the final level output in a fetch window; // Graphics carry is the final level output in a fetch window;
// it carries on into the next if it's high resolution with // it carries on into the next if it's high resolution with
@ -223,6 +223,18 @@ class VideoBase {
Outputs 80-column double-high-resolution graphics to @c target, drawing @c length columns from @c source. Outputs 80-column double-high-resolution graphics to @c target, drawing @c length columns from @c source.
*/ */
void output_double_high_resolution(uint8_t *target, uint8_t *source, uint8_t *auxiliary_source, size_t length) const; void output_double_high_resolution(uint8_t *target, uint8_t *source, uint8_t *auxiliary_source, size_t length) const;
/// Schedule @c action to occur in @c delay cycles.
void defer(int delay, const std::function<void(void)> &action);
// The list of deferred actions.
struct DeferredAction {
int delay;
std::function<void(void)> action;
DeferredAction(int delay, const std::function<void(void)> &action) : delay(delay), action(std::move(action)) {}
};
std::vector<DeferredAction> pending_actions_;
}; };
template <class BusHandler, bool is_iie> class Video: public VideoBase { template <class BusHandler, bool is_iie> class Video: public VideoBase {
@ -237,7 +249,94 @@ template <class BusHandler, bool is_iie> class Video: public VideoBase {
Implicitly adds an extra half a colour clock at the end of every Implicitly adds an extra half a colour clock at the end of every
line. line.
*/ */
void run_for(const Cycles cycles) { void run_for(Cycles cycles) {
// If there are no pending actions, just run for the entire length.
// This should be the normal branch.
if(pending_actions_.empty()) {
advance(cycles.as_int());
return;
}
// Divide the time to run according to the pending actions.
int cycles_remaining = cycles.as_int();
while(cycles_remaining) {
int next_period = pending_actions_.empty() ? cycles_remaining : std::min(cycles_remaining, pending_actions_[0].delay);
advance(next_period);
cycles_remaining -= next_period;
off_t performances = 0;
for(auto &action: pending_actions_) {
action.delay -= next_period;
if(!action.delay) {
action.action();
++performances;
}
}
if(performances) {
pending_actions_.erase(pending_actions_.begin(), pending_actions_.begin() + performances);
}
}
}
/*!
Obtains the last value the video read prior to time now+offset.
*/
uint8_t get_last_read_value(Cycles offset) {
// Rules of generation:
// (1) a complete sixty-five-cycle scan line consists of sixty-five consecutive bytes of
// display buffer memory that starts twenty-five bytes prior to the actual data to be displayed.
// (2) During VBL the data acts just as if it were starting a whole new frame from the beginning, but
// it never finishes this pseudo-frame. After getting one third of the way through the frame (to
// scan line $3F), it suddenly repeats the previous six scan lines ($3A through $3F) before aborting
// to begin the next true frame.
//
// Source: Have an Apple Split by Bob Bishop; http://rich12345.tripod.com/aiivideo/softalk.html
// Determine column at offset.
int mapped_column = column_ + offset.as_int();
// Map that backwards from the internal pixels-at-start generation to pixels-at-end
// (so what was column 0 is now column 25).
mapped_column += 25;
// Apply carry into the row counter.
int mapped_row = row_ + (mapped_column / 65);
mapped_column %= 65;
mapped_row %= 262;
// Apple out-of-bounds row logic.
if(mapped_row >= 256) {
mapped_row = 0x3a + (mapped_row&255);
} else {
mapped_row %= 192;
}
// Calculate the address and return the value.
uint16_t read_address = static_cast<uint16_t>(get_row_address(mapped_row) + mapped_column - 25);
uint8_t value, aux_value;
bus_handler_.perform_read(read_address, 1, &value, &aux_value);
return value;
}
/*!
@returns @c true if the display will be within vertical blank at now + @c offset; @c false otherwise.
*/
bool get_is_vertical_blank(Cycles offset) {
// Map that backwards from the internal pixels-at-start generation to pixels-at-end
// (so what was column 0 is now column 25).
int mapped_column = column_ + offset.as_int();
// Map that backwards from the internal pixels-at-start generation to pixels-at-end
// (so what was column 0 is now column 25).
mapped_column += 25;
// Apply carry into the row counter and test it for location.
int mapped_row = row_ + (mapped_column / 65);
return (mapped_row % 262) >= 192;
}
private:
void advance(Cycles cycles) {
/* /*
Addressing scheme used throughout is that column 0 is the first column with pixels in it; Addressing scheme used throughout is that column 0 is the first column with pixels in it;
row 0 is the first row with pixels in it. row 0 is the first row with pixels in it.
@ -305,19 +404,18 @@ template <class BusHandler, bool is_iie> class Video: public VideoBase {
} }
if(row_ < 192) { if(row_ < 192) {
// Output an initial 1.5 columns of blank. The pixel area will be the next 40.5 // The pixel area is the first 40.5 columns; base contents
// columns; base contents remain where they would naturally be but auxiliary // remain where they would naturally be but auxiliary
// graphics appear to the left of that. // graphics appear to the left of that.
if(!column_) { if(!column_) {
crt_->output_blank(14 + 7);
pixel_pointer_ = crt_->allocate_write_area(568); pixel_pointer_ = crt_->allocate_write_area(568);
graphics_carry_ = 0; graphics_carry_ = 0;
was_double_ = true; was_double_ = true;
} }
if(column_ < 42 && ending_column > 2) { if(column_ < 40) {
const int pixel_start = std::max(2, column_) - 2; const int pixel_start = std::max(0, column_);
const int pixel_end = std::min(42, ending_column) - 2; const int pixel_end = std::min(40, ending_column);
const int pixel_row = row_ & 7; const int pixel_row = row_ & 7;
const bool is_double = Video::is_double_mode(line_mode); const bool is_double = Video::is_double_mode(line_mode);
@ -406,8 +504,8 @@ template <class BusHandler, bool is_iie> class Video: public VideoBase {
} }
} }
} else { } else {
if(column_ < 42 && ending_column >= 42) { if(column_ < 40 && ending_column >= 40) {
crt_->output_blank(589); crt_->output_blank(568);
} }
} }
@ -417,7 +515,7 @@ template <class BusHandler, bool is_iie> class Video: public VideoBase {
*/ */
if(column_ < first_sync_column && ending_column >= first_sync_column) { if(column_ < first_sync_column && ending_column >= first_sync_column) {
crt_->output_blank((first_sync_column - 42)*14 - 1); crt_->output_blank((first_sync_column - 41)*14 - 1);
} }
if(column_ < (first_sync_column + sync_length) && ending_column >= (first_sync_column + sync_length)) { if(column_ < (first_sync_column + sync_length) && ending_column >= (first_sync_column + sync_length)) {
@ -429,7 +527,7 @@ template <class BusHandler, bool is_iie> class Video: public VideoBase {
const int colour_burst_start = std::max(first_sync_column + sync_length + 1, column_); const int colour_burst_start = std::max(first_sync_column + sync_length + 1, column_);
const int colour_burst_end = std::min(first_sync_column + sync_length + 4, ending_column); const int colour_burst_end = std::min(first_sync_column + sync_length + 4, ending_column);
if(colour_burst_end > colour_burst_start) { if(colour_burst_end > colour_burst_start) {
crt_->output_colour_burst(static_cast<unsigned int>(colour_burst_end - colour_burst_start) * 14, 128); crt_->output_colour_burst(static_cast<unsigned int>(colour_burst_end - colour_burst_start) * 14, 192);
} }
second_blank_start = std::max(first_sync_column + sync_length + 3, column_); second_blank_start = std::max(first_sync_column + sync_length + 3, column_);
@ -455,64 +553,6 @@ template <class BusHandler, bool is_iie> class Video: public VideoBase {
} }
} }
/*!
Obtains the last value the video read prior to time now+offset.
*/
uint8_t get_last_read_value(Cycles offset) {
// Rules of generation:
// (1) a complete sixty-five-cycle scan line consists of sixty-five consecutive bytes of
// display buffer memory that starts twenty-five bytes prior to the actual data to be displayed.
// (2) During VBL the data acts just as if it were starting a whole new frame from the beginning, but
// it never finishes this pseudo-frame. After getting one third of the way through the frame (to
// scan line $3F), it suddenly repeats the previous six scan lines ($3A through $3F) before aborting
// to begin the next true frame.
//
// Source: Have an Apple Split by Bob Bishop; http://rich12345.tripod.com/aiivideo/softalk.html
// Determine column at offset.
int mapped_column = column_ + offset.as_int();
// Map that backwards from the internal pixels-at-start generation to pixels-at-end
// (so what was column 0 is now column 25).
mapped_column += 25;
// Apply carry into the row counter.
int mapped_row = row_ + (mapped_column / 65);
mapped_column %= 65;
mapped_row %= 262;
// Apple out-of-bounds row logic.
if(mapped_row >= 256) {
mapped_row = 0x3a + (mapped_row&255);
} else {
mapped_row %= 192;
}
// Calculate the address and return the value.
uint16_t read_address = static_cast<uint16_t>(get_row_address(mapped_row) + mapped_column - 25);
uint8_t value, aux_value;
bus_handler_.perform_read(read_address, 1, &value, &aux_value);
return value;
}
/*!
@returns @c true if the display will be within vertical blank at now + @c offset; @c false otherwise.
*/
bool get_is_vertical_blank(Cycles offset) {
// Map that backwards from the internal pixels-at-start generation to pixels-at-end
// (so what was column 0 is now column 25).
int mapped_column = column_ + offset.as_int();
// Map that backwards from the internal pixels-at-start generation to pixels-at-end
// (so what was column 0 is now column 25).
mapped_column += 25;
// Apply carry into the row counter and test it for location.
int mapped_row = row_ + (mapped_column / 65);
return (mapped_row % 262) >= 192;
}
private:
GraphicsMode graphics_mode(int row) { GraphicsMode graphics_mode(int row) {
if(text_) return columns_80_ ? GraphicsMode::DoubleText : GraphicsMode::Text; if(text_) return columns_80_ ? GraphicsMode::DoubleText : GraphicsMode::Text;
if(mixed_ && row >= 160 && row < 192) { if(mixed_ && row >= 160 && row < 192) {