1
0
mirror of https://github.com/TomHarte/CLK.git synced 2025-02-16 18:30:32 +00:00

Merge pull request #1257 from TomHarte/CGABorderColour

Switch back to yellow for composite.
This commit is contained in:
Thomas Harte 2023-12-07 21:56:38 -05:00 committed by GitHub
commit ba91f461fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 55 additions and 42 deletions

View File

@ -15,41 +15,6 @@
namespace PCCompatible {
static constexpr uint8_t DarkCyan = 0b00'10'10;
static constexpr uint8_t DarkMagenta = 0b10'00'10;
static constexpr uint8_t DarkGrey = 0b10'10'10;
static constexpr uint8_t DarkGreen = 0b00'10'00;
static constexpr uint8_t DarkRed = 0b10'00'00;
static constexpr uint8_t DarkYellow = 0b10'10'00;
static constexpr uint8_t Brown = 0b10'01'00;
/// @returns @c Brown if @c source is @c DarkYellow; @c source otherwise.
constexpr uint8_t yellow_to_brown(uint8_t source) {
return (source == DarkYellow) ? Brown : source;
}
/// @returns The brightened (i.e. high intensity) version of @c source.
constexpr uint8_t bright(uint8_t source) {
return source | (source >> 1);
}
/// Maps the RGB TTL triplet @c source to an appropriate output colour.
constexpr uint8_t rgb(uint8_t source) {
return uint8_t(
((source & 0x01) << 1) |
((source & 0x02) << 2) |
((source & 0x04) << 3)
);
}
/// Maps the RGBI value in @c source to an appropriate output colour, including potential yellow-to-brown conversion.
constexpr uint8_t rgbi(uint8_t source) {
const uint8_t result = rgb(source);
return (source & 0x10) ? bright(result) : yellow_to_brown(result);
}
class CGA {
public:
CGA() : crtc_(Motorola::CRTC::Personality::HD6845S, outputter_) {}
@ -113,6 +78,7 @@ class CGA {
void set_display_type(Outputs::Display::DisplayType display_type) {
outputter_.crt.set_display_type(display_type);
outputter_.set_is_composite(Outputs::Display::is_composite(display_type));
}
Outputs::Display::DisplayType get_display_type() const {
return outputter_.crt.get_display_type();
@ -165,6 +131,11 @@ class CGA {
update_palette();
}
void set_is_composite(bool is_composite) {
is_composite_ = is_composite;
update_palette();
}
void set_colours(uint8_t value) {
colours_ = value;
update_palette();
@ -335,6 +306,9 @@ class CGA {
// Apply blink or background intensity.
if(control_ & 0x20) {
// Potentially remap dark yellow to brown.
colours[0] = yellow_to_brown(colours[0]);
if((attributes & 0x80) && (state.field_count & 16)) {
std::swap(colours[0], colours[1]);
}
@ -344,9 +318,6 @@ class CGA {
}
}
// Potentially remap dark yellow to brown.
colours[0] = yellow_to_brown(colours[0]);
// Draw according to ROM contents.
pixel_pointer[0] = (row & 0x80) ? colours[1] : colours[0];
pixel_pointer[1] = (row & 0x40) ? colours[1] : colours[0];
@ -384,6 +355,7 @@ class CGA {
int pixels_per_tick = 8;
uint8_t colours_ = 0;
uint8_t control_ = 0;
bool is_composite_ = false;
enum class Mode {
Pixels640, Pixels320, Text,
} mode_ = Mode::Text;
@ -425,10 +397,48 @@ class CGA {
border_colour = (mode_ != Mode::Pixels640) ? palette320[0] : 0;
}
//
// Named colours and mapping logic.
//
static constexpr uint8_t DarkCyan = 0b00'10'10;
static constexpr uint8_t DarkMagenta = 0b10'00'10;
static constexpr uint8_t DarkGrey = 0b10'10'10;
static constexpr uint8_t DarkGreen = 0b00'10'00;
static constexpr uint8_t DarkRed = 0b10'00'00;
static constexpr uint8_t DarkYellow = 0b10'10'00;
static constexpr uint8_t Brown = 0b10'01'00;
/// @returns @c Brown if @c source is @c DarkYellow and composite output is not enabled; @c source otherwise.
constexpr uint8_t yellow_to_brown(uint8_t source) {
return (source == DarkYellow && !is_composite_) ? Brown : source;
}
/// @returns The brightened (i.e. high intensity) version of @c source.
constexpr uint8_t bright(uint8_t source) {
return source | (source >> 1);
}
/// Maps the RGB TTL triplet @c source to an appropriate output colour.
constexpr uint8_t rgb(uint8_t source) {
return uint8_t(
((source & 0x01) << 1) |
((source & 0x02) << 2) |
((source & 0x04) << 3)
);
}
/// Maps the RGBI value in @c source to an appropriate output colour, including potential yellow-to-brown conversion.
constexpr uint8_t rgbi(uint8_t source) {
const uint8_t result = rgb(source);
return (source & 0x10) ? bright(result) : yellow_to_brown(result);
}
} outputter_;
Motorola::CRTC::CRTC6845<CRTCOutputter, Motorola::CRTC::CursorType::MDA> crtc_;
int full_clock_ = 0;
};
}

View File

@ -1109,10 +1109,9 @@ class ConcreteMachine:
void set_display_type(Outputs::Display::DisplayType display_type) override {
video_.set_display_type(display_type);
ppi_handler_.hint_is_composite(
(display_type == Outputs::Display::DisplayType::CompositeColour) ||
(display_type == Outputs::Display::DisplayType::CompositeMonochrome)
);
// Give the PPI a shout-out in case it isn't too late to switch to CGA40.
ppi_handler_.hint_is_composite(Outputs::Display::is_composite(display_type));
}
Outputs::Display::DisplayType get_display_type() const override {

View File

@ -51,6 +51,10 @@ enum class DisplayType {
CompositeMonochrome
};
constexpr bool is_composite(DisplayType type) {
return type == DisplayType::CompositeColour || type == DisplayType::CompositeMonochrome;
}
/*!
Enumerates the potential formats of input data.