From 020a04006e7c0f54862434d5f685ed1669eb6f07 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Thu, 18 Mar 2021 23:07:51 -0400 Subject: [PATCH] Adds flashing, randomises initial RAM contents. --- Machines/Sinclair/ZXSpectrum/Video.hpp | 13 ++++++++++++- Machines/Sinclair/ZXSpectrum/ZXSpectrum.cpp | 3 +++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/Machines/Sinclair/ZXSpectrum/Video.hpp b/Machines/Sinclair/ZXSpectrum/Video.hpp index 72c46e914..e24aed551 100644 --- a/Machines/Sinclair/ZXSpectrum/Video.hpp +++ b/Machines/Sinclair/ZXSpectrum/Video.hpp @@ -89,6 +89,12 @@ template class Video { const int cycles_this_line = std::min(cycles_remaining, timings.cycles_per_line - offset); const int end_offset = offset + cycles_this_line; + if(!line && !offset) { + ++flash_counter_; + flash_mask_ = uint8_t(flash_counter_ >> 4); + flash_counter_ &= 31; + } + if(line < 3) { // Output sync line. crt_.output_sync(cycles_this_line); @@ -127,9 +133,11 @@ template class Video { const int start_column = offset >> 3; const int end_column = (offset + pixel_duration) >> 3; for(int column = start_column; column < end_column; column++) { - const uint8_t pixels = memory_[pixel_address_]; const uint8_t attributes = memory_[attribute_address_]; + constexpr uint8_t masks[] = {0, 0xff}; + const uint8_t pixels = memory_[pixel_address_] ^ masks[flash_mask_ & (attributes >> 7)]; + const uint8_t colours[2] = { palette[((attributes & 0x40) >> 3) | (attributes & 0x07)], palette[(attributes & 0x78) >> 3], @@ -255,6 +263,9 @@ template class Video { int attribute_address_ = 0; int pixel_address_ = 0; + uint8_t flash_mask_ = 0; + int flash_counter_ = 0; + #define RGB(r, g, b) (r << 4) | (g << 2) | b static constexpr uint8_t palette[] = { RGB(0, 0, 0), RGB(0, 0, 2), RGB(2, 0, 0), RGB(2, 0, 2), diff --git a/Machines/Sinclair/ZXSpectrum/ZXSpectrum.cpp b/Machines/Sinclair/ZXSpectrum/ZXSpectrum.cpp index 638565e57..ce649eaa9 100644 --- a/Machines/Sinclair/ZXSpectrum/ZXSpectrum.cpp +++ b/Machines/Sinclair/ZXSpectrum/ZXSpectrum.cpp @@ -26,6 +26,8 @@ #include "../../../Analyser/Static/ZXSpectrum/Target.hpp" +#include "../../Utility/MemoryFuzzer.hpp" + #include "../../../ClockReceiver/JustInTime.hpp" #include @@ -60,6 +62,7 @@ template class ConcreteMachine: // Set up initial memory map. update_memory_map(); + Memory::Fuzz(ram_); // TODO: insert media. (void)target;