1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-11-19 23:32:28 +00:00

Microtweak: simplify Macintosh pixel serialisation.

This commit is contained in:
Thomas Harte 2022-06-06 08:34:58 -04:00
parent d4c1e92b1c
commit 5495f30329
2 changed files with 18 additions and 22 deletions

View File

@ -12,6 +12,16 @@
using namespace Apple::Macintosh; using namespace Apple::Macintosh;
namespace {
#if TARGET_RT_BIG_ENDIAN
constexpr uint64_t PixelMask = 0x8040201008040201;
#else
constexpr uint64_t PixelMask = 0x0102040810204080;
#endif
}
// Re: CRT timings, see the Apple Guide to the Macintosh Hardware Family, // Re: CRT timings, see the Apple Guide to the Macintosh Hardware Family,
// bottom of page 400: // bottom of page 400:
// //
@ -86,34 +96,20 @@ void Video::run_for(HalfCycles duration) {
const int final_pixel_word = std::min(final_word, 32); const int final_pixel_word = std::min(final_word, 32);
if(!first_word) { if(!first_word) {
pixel_buffer_ = crt_.begin_data(512); pixel_buffer_ = reinterpret_cast<uint64_t *>(crt_.begin_data(512, 8));
} }
if(pixel_buffer_) { if(pixel_buffer_) {
for(int c = first_word; c < final_pixel_word; ++c) { for(int c = first_word; c < final_pixel_word; ++c) {
uint16_t pixels = ram_[video_base + video_address_] ^ 0xffff; const uint16_t pixels = ram_[video_base + video_address_] ^ 0xffff;
++video_address_; ++video_address_;
pixel_buffer_[15] = pixels & 0x01; const uint64_t low_pixels = (pixels & 0xff) * 0x0101010101010101;
pixel_buffer_[14] = pixels & 0x02; const uint64_t high_pixels = (pixels >> 8) * 0x0101010101010101;
pixel_buffer_[13] = pixels & 0x04;
pixel_buffer_[12] = pixels & 0x08;
pixel_buffer_[11] = pixels & 0x10;
pixel_buffer_[10] = pixels & 0x20;
pixel_buffer_[9] = pixels & 0x40;
pixel_buffer_[8] = pixels & 0x80;
pixels >>= 8; pixel_buffer_[0] = high_pixels & PixelMask;
pixel_buffer_[7] = pixels & 0x01; pixel_buffer_[1] = low_pixels & PixelMask;
pixel_buffer_[6] = pixels & 0x02; pixel_buffer_ += 2;
pixel_buffer_[5] = pixels & 0x04;
pixel_buffer_[4] = pixels & 0x08;
pixel_buffer_[3] = pixels & 0x10;
pixel_buffer_[2] = pixels & 0x20;
pixel_buffer_[1] = pixels & 0x40;
pixel_buffer_[0] = pixels & 0x80;
pixel_buffer_ += 16;
} }
} else { } else {
video_address_ += size_t(final_pixel_word - first_word); video_address_ += size_t(final_pixel_word - first_word);

View File

@ -96,7 +96,7 @@ class Video {
size_t video_address_ = 0; size_t video_address_ = 0;
size_t audio_address_ = 0; size_t audio_address_ = 0;
uint8_t *pixel_buffer_ = nullptr; uint64_t *pixel_buffer_ = nullptr;
bool use_alternate_screen_buffer_ = false; bool use_alternate_screen_buffer_ = false;
bool use_alternate_audio_buffer_ = false; bool use_alternate_audio_buffer_ = false;