1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-11-02 16:04:59 +00:00
CLK/Machines/AppleII/Video.cpp
Thomas Harte 5f1c210746 Simplifies and corrects low-resolution colour generation.
Possibly disproving the premise for this whole experiment, all colours seem immediately to work correctly. Hmmm.
2018-04-18 21:41:11 -04:00

118 lines
3.3 KiB
C++

//
// Video.cpp
// Clock Signal
//
// Created by Thomas Harte on 14/04/2018.
// Copyright © 2018 Thomas Harte. All rights reserved.
//
#include "Video.hpp"
using namespace AppleII::Video;
namespace {
struct ScaledByteFiller {
ScaledByteFiller() {
VideoBase::setup_tables();
}
} throwaway;
}
VideoBase::VideoBase() :
crt_(new Outputs::CRT::CRT(455, 1, Outputs::CRT::DisplayType::NTSC60, 1)) {
// Set a composite sampling function that assumes 1bpp input, and uses just 7 bits per byte.
crt_->set_composite_sampling_function(
"float composite_sample(usampler2D sampler, vec2 coordinate, vec2 icoordinate, float phase, float amplitude)"
"{"
"uint texValue = texture(sampler, coordinate).r;"
"texValue <<= int(icoordinate.x) % 7;"
"return float(texValue & 64u);"
"}");
crt_->set_integer_coordinate_multiplier(7.0f);
// Show only the centre 75% of the TV frame.
crt_->set_video_signal(Outputs::CRT::VideoSignal::Composite);
crt_->set_visible_area(Outputs::CRT::Rect(0.115f, 0.117f, 0.77f, 0.77f));
}
Outputs::CRT::CRT *VideoBase::get_crt() {
return crt_.get();
}
uint16_t VideoBase::scaled_byte[256];
uint16_t VideoBase::low_resolution_patterns[2][16];
void VideoBase::setup_tables() {
for(int c = 0; c < 128; ++c) {
const uint16_t value =
((c & 0x01) ? 0x0003 : 0x0000) |
((c & 0x02) ? 0x000c : 0x0000) |
((c & 0x04) ? 0x0030 : 0x0000) |
((c & 0x08) ? 0x0140 : 0x0000) |
((c & 0x10) ? 0x0600 : 0x0000) |
((c & 0x20) ? 0x1800 : 0x0000) |
((c & 0x40) ? 0x6000 : 0x0000);
uint8_t *const table_entry = reinterpret_cast<uint8_t *>(&scaled_byte[c]);
table_entry[0] = static_cast<uint8_t>(value >> 8);
table_entry[1] = static_cast<uint8_t>(value & 0xff);
}
for(int c = 128; c < 256; ++c) {
uint8_t *const source_table_entry = reinterpret_cast<uint8_t *>(&scaled_byte[c & 0x7f]);
uint8_t *const destination_table_entry = reinterpret_cast<uint8_t *>(&scaled_byte[c]);
destination_table_entry[0] = static_cast<uint8_t>(source_table_entry[0] >> 1);
destination_table_entry[1] = static_cast<uint8_t>((source_table_entry[1] >> 1) | ((source_table_entry[0]&1) << 6));
}
for(int c = 0; c < 16; ++c) {
// Produce the whole 28-bit pattern that would cover two bytes.
int pattern = 0;
for(int l = 0; l < 7; ++l) {
pattern <<= 4;
pattern |= c;
}
// Pack that 28-bit pattern into the appropriate look-up tables.
uint8_t *const left_entry = reinterpret_cast<uint8_t *>(&low_resolution_patterns[0][c]);
uint8_t *const right_entry = reinterpret_cast<uint8_t *>(&low_resolution_patterns[1][c]);
left_entry[0] = static_cast<uint8_t>(pattern >> 21);
left_entry[1] = static_cast<uint8_t>(pattern >> 14);
right_entry[0] = static_cast<uint8_t>(pattern >> 7);
right_entry[1] = static_cast<uint8_t>(pattern);
}
printf("");
}
void VideoBase::set_graphics_mode() {
use_graphics_mode_ = true;
}
void VideoBase::set_text_mode() {
use_graphics_mode_ = false;
}
void VideoBase::set_mixed_mode(bool mixed_mode) {
mixed_mode_ = mixed_mode;
}
void VideoBase::set_video_page(int page) {
video_page_ = page;
}
void VideoBase::set_low_resolution() {
graphics_mode_ = GraphicsMode::LowRes;
}
void VideoBase::set_high_resolution() {
graphics_mode_ = GraphicsMode::HighRes;
}
void VideoBase::set_character_rom(const std::vector<uint8_t> &character_rom) {
character_rom_ = character_rom;
}