2018-04-14 23:46:15 +00:00
|
|
|
//
|
|
|
|
// Video.cpp
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 14/04/2018.
|
2018-05-13 19:19:52 +00:00
|
|
|
// Copyright 2018 Thomas Harte. All rights reserved.
|
2018-04-14 23:46:15 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
#include "Video.hpp"
|
|
|
|
|
2018-04-15 23:35:08 +00:00
|
|
|
using namespace AppleII::Video;
|
2018-04-14 23:46:15 +00:00
|
|
|
|
2018-08-25 00:04:26 +00:00
|
|
|
VideoBase::VideoBase(bool is_iie, std::function<void(Cycles)> &&target) :
|
2018-11-15 03:04:57 +00:00
|
|
|
crt_(910, 1, Outputs::Display::Type::NTSC60, Outputs::Display::InputDataType::Luminance1),
|
2018-08-25 00:04:26 +00:00
|
|
|
is_iie_(is_iie),
|
|
|
|
deferrer_(std::move(target)) {
|
2018-04-18 02:04:02 +00:00
|
|
|
|
|
|
|
// Show only the centre 75% of the TV frame.
|
2018-11-29 01:53:33 +00:00
|
|
|
crt_.set_display_type(Outputs::Display::DisplayType::CompositeColour);
|
2018-11-15 03:04:57 +00:00
|
|
|
crt_.set_visible_area(Outputs::Display::Rect(0.118f, 0.122f, 0.77f, 0.77f));
|
|
|
|
crt_.set_immediate_default_phase(0.0f);
|
2018-09-05 14:26:08 +00:00
|
|
|
|
|
|
|
character_zones[0].xor_mask = 0;
|
|
|
|
character_zones[0].address_mask = 0x3f;
|
|
|
|
character_zones[1].xor_mask = 0;
|
|
|
|
character_zones[1].address_mask = 0x3f;
|
|
|
|
character_zones[2].xor_mask = 0;
|
|
|
|
character_zones[2].address_mask = 0x3f;
|
|
|
|
character_zones[3].xor_mask = 0;
|
|
|
|
character_zones[3].address_mask = 0x3f;
|
|
|
|
|
|
|
|
if(is_iie) {
|
|
|
|
character_zones[0].xor_mask =
|
|
|
|
character_zones[2].xor_mask =
|
|
|
|
character_zones[3].xor_mask = 0xff;
|
|
|
|
character_zones[2].address_mask =
|
|
|
|
character_zones[3].address_mask = 0xff;
|
|
|
|
}
|
2018-04-18 02:04:02 +00:00
|
|
|
}
|
|
|
|
|
2018-11-15 03:04:57 +00:00
|
|
|
void VideoBase::set_scan_target(Outputs::Display::ScanTarget *scan_target) {
|
|
|
|
crt_.set_scan_target(scan_target);
|
2018-04-18 02:04:02 +00:00
|
|
|
}
|
|
|
|
|
2018-07-25 02:15:42 +00:00
|
|
|
/*
|
|
|
|
Rote setters and getters.
|
|
|
|
*/
|
|
|
|
void VideoBase::set_alternative_character_set(bool alternative_character_set) {
|
2018-08-23 01:56:45 +00:00
|
|
|
set_alternative_character_set_ = alternative_character_set;
|
2018-08-25 00:04:26 +00:00
|
|
|
deferrer_.defer(Cycles(2), [=] {
|
2018-08-23 01:56:45 +00:00
|
|
|
alternative_character_set_ = alternative_character_set;
|
2018-09-05 14:26:08 +00:00
|
|
|
if(alternative_character_set) {
|
|
|
|
character_zones[1].address_mask = 0xff;
|
|
|
|
character_zones[1].xor_mask = 0;
|
|
|
|
} else {
|
|
|
|
character_zones[1].address_mask = 0x3f;
|
|
|
|
character_zones[1].xor_mask = flash_mask();
|
|
|
|
}
|
2018-08-23 01:56:45 +00:00
|
|
|
});
|
2018-04-18 02:04:02 +00:00
|
|
|
}
|
|
|
|
|
2018-07-25 02:15:42 +00:00
|
|
|
bool VideoBase::get_alternative_character_set() {
|
2018-08-23 01:56:45 +00:00
|
|
|
return set_alternative_character_set_;
|
2018-04-18 02:04:02 +00:00
|
|
|
}
|
|
|
|
|
2018-07-25 02:15:42 +00:00
|
|
|
void VideoBase::set_80_columns(bool columns_80) {
|
2018-08-23 01:56:45 +00:00
|
|
|
set_columns_80_ = columns_80;
|
2018-08-25 00:04:26 +00:00
|
|
|
deferrer_.defer(Cycles(2), [=] {
|
2018-08-23 01:56:45 +00:00
|
|
|
columns_80_ = columns_80;
|
|
|
|
});
|
2018-04-18 02:04:02 +00:00
|
|
|
}
|
|
|
|
|
2018-07-25 02:15:42 +00:00
|
|
|
bool VideoBase::get_80_columns() {
|
2018-08-23 01:56:45 +00:00
|
|
|
return set_columns_80_;
|
2018-04-18 02:04:02 +00:00
|
|
|
}
|
|
|
|
|
2018-07-25 02:15:42 +00:00
|
|
|
void VideoBase::set_80_store(bool store_80) {
|
2018-08-23 01:56:45 +00:00
|
|
|
set_store_80_ = store_80_ = store_80;
|
2018-04-18 02:04:02 +00:00
|
|
|
}
|
|
|
|
|
2018-07-25 02:15:42 +00:00
|
|
|
bool VideoBase::get_80_store() {
|
2018-08-23 01:56:45 +00:00
|
|
|
return set_store_80_;
|
2018-07-25 02:15:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void VideoBase::set_page2(bool page2) {
|
2018-08-23 01:56:45 +00:00
|
|
|
set_page2_ = page2_ = page2;
|
2018-07-25 02:15:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool VideoBase::get_page2() {
|
2018-08-23 01:56:45 +00:00
|
|
|
return set_page2_;
|
2018-07-25 02:15:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void VideoBase::set_text(bool text) {
|
2018-08-23 01:56:45 +00:00
|
|
|
set_text_ = text;
|
2018-08-25 00:04:26 +00:00
|
|
|
deferrer_.defer(Cycles(2), [=] {
|
2018-08-23 01:56:45 +00:00
|
|
|
text_ = text;
|
|
|
|
});
|
2018-07-25 02:15:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool VideoBase::get_text() {
|
2018-08-23 01:56:45 +00:00
|
|
|
return set_text_;
|
2018-07-25 02:15:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void VideoBase::set_mixed(bool mixed) {
|
2018-08-23 01:56:45 +00:00
|
|
|
set_mixed_ = mixed;
|
2018-08-25 00:04:26 +00:00
|
|
|
deferrer_.defer(Cycles(2), [=] {
|
2018-08-23 01:56:45 +00:00
|
|
|
mixed_ = mixed;
|
|
|
|
});
|
2018-07-25 02:15:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool VideoBase::get_mixed() {
|
2018-08-23 01:56:45 +00:00
|
|
|
return set_mixed_;
|
2018-07-25 02:15:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void VideoBase::set_high_resolution(bool high_resolution) {
|
2018-08-23 01:56:45 +00:00
|
|
|
set_high_resolution_ = high_resolution;
|
2018-08-25 00:04:26 +00:00
|
|
|
deferrer_.defer(Cycles(2), [=] {
|
2018-08-23 01:56:45 +00:00
|
|
|
high_resolution_ = high_resolution;
|
|
|
|
});
|
2018-07-25 02:15:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool VideoBase::get_high_resolution() {
|
2018-08-23 01:56:45 +00:00
|
|
|
return set_high_resolution_;
|
2018-07-25 02:15:42 +00:00
|
|
|
}
|
|
|
|
|
2018-09-07 03:23:19 +00:00
|
|
|
void VideoBase::set_annunciator_3(bool annunciator_3) {
|
|
|
|
set_annunciator_3_ = annunciator_3;
|
2018-08-25 00:04:26 +00:00
|
|
|
deferrer_.defer(Cycles(2), [=] {
|
2018-09-07 03:23:19 +00:00
|
|
|
annunciator_3_ = annunciator_3;
|
|
|
|
high_resolution_mask_ = annunciator_3_ ? 0x7f : 0xff;
|
2018-08-23 01:56:45 +00:00
|
|
|
});
|
2018-07-25 02:15:42 +00:00
|
|
|
}
|
|
|
|
|
2018-09-07 03:23:19 +00:00
|
|
|
bool VideoBase::get_annunciator_3() {
|
|
|
|
return set_annunciator_3_;
|
2018-04-18 02:04:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void VideoBase::set_character_rom(const std::vector<uint8_t> &character_rom) {
|
|
|
|
character_rom_ = character_rom;
|
2018-08-04 20:52:29 +00:00
|
|
|
|
|
|
|
// Flip all character contents based on the second line of the $ graphic.
|
|
|
|
if(character_rom_[0x121] == 0x3c || character_rom_[0x122] == 0x3c) {
|
|
|
|
for(auto &graphic : character_rom_) {
|
|
|
|
graphic =
|
|
|
|
((graphic & 0x01) ? 0x40 : 0x00) |
|
|
|
|
((graphic & 0x02) ? 0x20 : 0x00) |
|
|
|
|
((graphic & 0x04) ? 0x10 : 0x00) |
|
|
|
|
((graphic & 0x08) ? 0x08 : 0x00) |
|
|
|
|
((graphic & 0x10) ? 0x04 : 0x00) |
|
|
|
|
((graphic & 0x20) ? 0x02 : 0x00) |
|
|
|
|
((graphic & 0x40) ? 0x01 : 0x00);
|
|
|
|
}
|
|
|
|
}
|
2018-04-18 02:04:02 +00:00
|
|
|
}
|
2018-08-18 22:44:31 +00:00
|
|
|
|
2018-09-05 15:36:40 +00:00
|
|
|
void VideoBase::output_text(uint8_t *target, const uint8_t *const source, size_t length, size_t pixel_row) const {
|
2018-08-18 22:44:31 +00:00
|
|
|
for(size_t c = 0; c < length; ++c) {
|
2018-09-05 14:26:08 +00:00
|
|
|
const int character = source[c] & character_zones[source[c] >> 6].address_mask;
|
|
|
|
const uint8_t xor_mask = character_zones[source[c] >> 6].xor_mask;
|
2018-08-18 22:44:31 +00:00
|
|
|
const std::size_t character_address = static_cast<std::size_t>(character << 3) + pixel_row;
|
|
|
|
const uint8_t character_pattern = character_rom_[character_address] ^ xor_mask;
|
|
|
|
|
|
|
|
// The character ROM is output MSB to LSB rather than LSB to MSB.
|
2018-08-20 02:31:04 +00:00
|
|
|
target[0] = target[1] = character_pattern & 0x40;
|
|
|
|
target[2] = target[3] = character_pattern & 0x20;
|
|
|
|
target[4] = target[5] = character_pattern & 0x10;
|
|
|
|
target[6] = target[7] = character_pattern & 0x08;
|
|
|
|
target[8] = target[9] = character_pattern & 0x04;
|
|
|
|
target[10] = target[11] = character_pattern & 0x02;
|
|
|
|
target[12] = target[13] = character_pattern & 0x01;
|
2018-08-18 22:44:31 +00:00
|
|
|
graphics_carry_ = character_pattern & 0x01;
|
2018-08-20 02:31:04 +00:00
|
|
|
target += 14;
|
2018-08-18 22:44:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-05 15:36:40 +00:00
|
|
|
void VideoBase::output_double_text(uint8_t *target, const uint8_t *const source, const uint8_t *const auxiliary_source, size_t length, size_t pixel_row) const {
|
2018-08-18 22:44:31 +00:00
|
|
|
for(size_t c = 0; c < length; ++c) {
|
|
|
|
const std::size_t character_addresses[2] = {
|
|
|
|
static_cast<std::size_t>(
|
2018-09-05 14:26:08 +00:00
|
|
|
(auxiliary_source[c] & character_zones[auxiliary_source[c] >> 6].address_mask) << 3
|
2018-08-18 22:44:31 +00:00
|
|
|
) + pixel_row,
|
|
|
|
static_cast<std::size_t>(
|
2018-09-05 14:26:08 +00:00
|
|
|
(source[c] & character_zones[source[c] >> 6].address_mask) << 3
|
|
|
|
) + pixel_row
|
2018-08-18 22:44:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const uint8_t character_patterns[2] = {
|
2018-09-05 14:26:08 +00:00
|
|
|
static_cast<uint8_t>(
|
|
|
|
character_rom_[character_addresses[0]] ^ character_zones[auxiliary_source[c] >> 6].xor_mask
|
|
|
|
),
|
|
|
|
static_cast<uint8_t>(
|
|
|
|
character_rom_[character_addresses[1]] ^ character_zones[source[c] >> 6].xor_mask
|
|
|
|
)
|
2018-08-18 22:44:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// The character ROM is output MSB to LSB rather than LSB to MSB.
|
|
|
|
target[0] = character_patterns[0] & 0x40;
|
|
|
|
target[1] = character_patterns[0] & 0x20;
|
|
|
|
target[2] = character_patterns[0] & 0x10;
|
|
|
|
target[3] = character_patterns[0] & 0x08;
|
|
|
|
target[4] = character_patterns[0] & 0x04;
|
|
|
|
target[5] = character_patterns[0] & 0x02;
|
|
|
|
target[6] = character_patterns[0] & 0x01;
|
|
|
|
target[7] = character_patterns[1] & 0x40;
|
|
|
|
target[8] = character_patterns[1] & 0x20;
|
|
|
|
target[9] = character_patterns[1] & 0x10;
|
|
|
|
target[10] = character_patterns[1] & 0x08;
|
|
|
|
target[11] = character_patterns[1] & 0x04;
|
|
|
|
target[12] = character_patterns[1] & 0x02;
|
|
|
|
target[13] = character_patterns[1] & 0x01;
|
|
|
|
graphics_carry_ = character_patterns[1] & 0x01;
|
|
|
|
target += 14;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-05 15:36:40 +00:00
|
|
|
void VideoBase::output_low_resolution(uint8_t *target, const uint8_t *const source, size_t length, int column, int row) const {
|
2018-08-18 22:44:31 +00:00
|
|
|
const int row_shift = row&4;
|
|
|
|
for(size_t c = 0; c < length; ++c) {
|
|
|
|
// Low-resolution graphics mode shifts the colour code on a loop, but has to account for whether this
|
|
|
|
// 14-sample output window is starting at the beginning of a colour cycle or halfway through.
|
2018-08-20 02:31:04 +00:00
|
|
|
if((column + static_cast<int>(c))&1) {
|
2018-08-18 22:44:31 +00:00
|
|
|
target[0] = target[4] = target[8] = target[12] = (source[c] >> row_shift) & 4;
|
|
|
|
target[1] = target[5] = target[9] = target[13] = (source[c] >> row_shift) & 8;
|
|
|
|
target[2] = target[6] = target[10] = (source[c] >> row_shift) & 1;
|
|
|
|
target[3] = target[7] = target[11] = (source[c] >> row_shift) & 2;
|
|
|
|
graphics_carry_ = (source[c] >> row_shift) & 8;
|
|
|
|
} else {
|
|
|
|
target[0] = target[4] = target[8] = target[12] = (source[c] >> row_shift) & 1;
|
|
|
|
target[1] = target[5] = target[9] = target[13] = (source[c] >> row_shift) & 2;
|
|
|
|
target[2] = target[6] = target[10] = (source[c] >> row_shift) & 4;
|
|
|
|
target[3] = target[7] = target[11] = (source[c] >> row_shift) & 8;
|
|
|
|
graphics_carry_ = (source[c] >> row_shift) & 2;
|
|
|
|
}
|
|
|
|
target += 14;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-09 00:51:15 +00:00
|
|
|
void VideoBase::output_fat_low_resolution(uint8_t *target, const uint8_t *const source, size_t length, int column, int row) const {
|
|
|
|
const int row_shift = row&4;
|
|
|
|
for(size_t c = 0; c < length; ++c) {
|
2018-09-09 14:06:21 +00:00
|
|
|
// Fat low-resolution mode appears not to do anything to try to make odd and
|
|
|
|
// even columns compatible.
|
|
|
|
target[0] = target[1] = target[8] = target[9] = (source[c] >> row_shift) & 1;
|
|
|
|
target[2] = target[3] = target[10] = target[11] = (source[c] >> row_shift) & 2;
|
|
|
|
target[4] = target[5] = target[12] = target[13] = (source[c] >> row_shift) & 4;
|
|
|
|
target[6] = target[7] = (source[c] >> row_shift) & 8;
|
|
|
|
graphics_carry_ = (source[c] >> row_shift) & 4;
|
2018-09-09 00:51:15 +00:00
|
|
|
target += 14;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-05 15:36:40 +00:00
|
|
|
void VideoBase::output_double_low_resolution(uint8_t *target, const uint8_t *const source, const uint8_t *const auxiliary_source, size_t length, int column, int row) const {
|
2018-08-18 22:44:31 +00:00
|
|
|
const int row_shift = row&4;
|
|
|
|
for(size_t c = 0; c < length; ++c) {
|
2018-08-20 02:31:04 +00:00
|
|
|
if((column + static_cast<int>(c))&1) {
|
2018-08-18 22:44:31 +00:00
|
|
|
target[0] = target[4] = (auxiliary_source[c] >> row_shift) & 2;
|
|
|
|
target[1] = target[5] = (auxiliary_source[c] >> row_shift) & 4;
|
|
|
|
target[2] = target[6] = (auxiliary_source[c] >> row_shift) & 8;
|
|
|
|
target[3] = (auxiliary_source[c] >> row_shift) & 1;
|
|
|
|
|
|
|
|
target[8] = target[12] = (source[c] >> row_shift) & 4;
|
|
|
|
target[9] = target[13] = (source[c] >> row_shift) & 8;
|
|
|
|
target[10] = (source[c] >> row_shift) & 1;
|
|
|
|
target[7] = target[11] = (source[c] >> row_shift) & 2;
|
|
|
|
graphics_carry_ = (source[c] >> row_shift) & 8;
|
|
|
|
} else {
|
|
|
|
target[0] = target[4] = (auxiliary_source[c] >> row_shift) & 8;
|
|
|
|
target[1] = target[5] = (auxiliary_source[c] >> row_shift) & 1;
|
|
|
|
target[2] = target[6] = (auxiliary_source[c] >> row_shift) & 2;
|
|
|
|
target[3] = (auxiliary_source[c] >> row_shift) & 4;
|
|
|
|
|
|
|
|
target[8] = target[12] = (source[c] >> row_shift) & 1;
|
|
|
|
target[9] = target[13] = (source[c] >> row_shift) & 2;
|
|
|
|
target[10] = (source[c] >> row_shift) & 4;
|
|
|
|
target[7] = target[11] = (source[c] >> row_shift) & 8;
|
|
|
|
graphics_carry_ = (source[c] >> row_shift) & 2;
|
|
|
|
}
|
|
|
|
target += 14;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-05 15:36:40 +00:00
|
|
|
void VideoBase::output_high_resolution(uint8_t *target, const uint8_t *const source, size_t length) const {
|
2018-08-18 22:44:31 +00:00
|
|
|
for(size_t c = 0; c < length; ++c) {
|
|
|
|
// High resolution graphics shift out LSB to MSB, optionally with a delay of half a pixel.
|
|
|
|
// If there is a delay, the previous output level is held to bridge the gap.
|
2018-09-07 03:23:19 +00:00
|
|
|
// Delays may be ignored on a IIe if Annunciator 3 is set; that's the state that
|
|
|
|
// high_resolution_mask_ models.
|
|
|
|
if(source[c] & high_resolution_mask_ & 0x80) {
|
2018-08-18 22:44:31 +00:00
|
|
|
target[0] = graphics_carry_;
|
|
|
|
target[1] = target[2] = source[c] & 0x01;
|
|
|
|
target[3] = target[4] = source[c] & 0x02;
|
|
|
|
target[5] = target[6] = source[c] & 0x04;
|
|
|
|
target[7] = target[8] = source[c] & 0x08;
|
|
|
|
target[9] = target[10] = source[c] & 0x10;
|
|
|
|
target[11] = target[12] = source[c] & 0x20;
|
|
|
|
target[13] = source[c] & 0x40;
|
|
|
|
} else {
|
|
|
|
target[0] = target[1] = source[c] & 0x01;
|
|
|
|
target[2] = target[3] = source[c] & 0x02;
|
|
|
|
target[4] = target[5] = source[c] & 0x04;
|
|
|
|
target[6] = target[7] = source[c] & 0x08;
|
|
|
|
target[8] = target[9] = source[c] & 0x10;
|
|
|
|
target[10] = target[11] = source[c] & 0x20;
|
|
|
|
target[12] = target[13] = source[c] & 0x40;
|
|
|
|
}
|
|
|
|
graphics_carry_ = source[c] & 0x40;
|
|
|
|
target += 14;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-05 15:36:40 +00:00
|
|
|
void VideoBase::output_double_high_resolution(uint8_t *target, const uint8_t *const source, const uint8_t *const auxiliary_source, size_t length) const {
|
2018-08-18 22:44:31 +00:00
|
|
|
for(size_t c = 0; c < length; ++c) {
|
2018-08-20 02:31:04 +00:00
|
|
|
target[0] = auxiliary_source[c] & 0x01;
|
|
|
|
target[1] = auxiliary_source[c] & 0x02;
|
|
|
|
target[2] = auxiliary_source[c] & 0x04;
|
|
|
|
target[3] = auxiliary_source[c] & 0x08;
|
|
|
|
target[4] = auxiliary_source[c] & 0x10;
|
|
|
|
target[5] = auxiliary_source[c] & 0x20;
|
|
|
|
target[6] = auxiliary_source[c] & 0x40;
|
|
|
|
target[7] = source[c] & 0x01;
|
|
|
|
target[8] = source[c] & 0x02;
|
|
|
|
target[9] = source[c] & 0x04;
|
|
|
|
target[10] = source[c] & 0x08;
|
|
|
|
target[11] = source[c] & 0x10;
|
|
|
|
target[12] = source[c] & 0x20;
|
|
|
|
target[13] = source[c] & 0x40;
|
|
|
|
|
2018-08-18 22:44:31 +00:00
|
|
|
graphics_carry_ = auxiliary_source[c] & 0x40;
|
2018-08-19 01:36:48 +00:00
|
|
|
target += 14;
|
2018-08-18 22:44:31 +00:00
|
|
|
}
|
|
|
|
}
|