From 5f90941e4e9ab136e862c3955ff7ca6a22a75463 Mon Sep 17 00:00:00 2001
From: Thomas Harte <thomas.harte@gmail.com>
Date: Wed, 28 Nov 2018 18:16:13 -0800
Subject: [PATCH] Starts nudging the Oric back to functionality under the new
 regime.

i.e. one where it can't invent internal pixel formats.
---
 Machines/Oric/Oric.cpp  | 18 +++++++-----------
 Machines/Oric/Video.cpp | 42 +++++++++++++++++++++--------------------
 Machines/Oric/Video.hpp |  8 +++++---
 3 files changed, 34 insertions(+), 34 deletions(-)

diff --git a/Machines/Oric/Oric.cpp b/Machines/Oric/Oric.cpp
index dc8d0c011..9cf344462 100644
--- a/Machines/Oric/Oric.cpp
+++ b/Machines/Oric/Oric.cpp
@@ -212,6 +212,7 @@ template <Analyser::Static::Oric::Target::DiskInterface disk_interface> class Co
 	public:
 		ConcreteMachine(const Analyser::Static::Oric::Target &target, const ROMMachine::ROMFetcher &rom_fetcher) :
 				m6502_(*this),
+				video_output_(ram_),
 				ay8910_(audio_queue_),
 				speaker_(ay8910_),
 				via_port_handler_(audio_queue_, ay8910_, speaker_, tape_player_, keyboard_),
@@ -246,7 +247,7 @@ template <Analyser::Static::Oric::Target::DiskInterface disk_interface> class Co
 				}
 			}
 
-			colour_rom_ = std::move(*roms[0]);
+			video_output_.set_colour_rom(*roms[0]);
 			rom_ = std::move(*roms[1]);
 
 			switch(disk_interface) {
@@ -267,7 +268,6 @@ template <Analyser::Static::Oric::Target::DiskInterface disk_interface> class Co
 				} break;
 			}
 
-			colour_rom_.resize(128);
 			rom_.resize(16384);
 			paged_rom_ = rom_.data();
 
@@ -461,11 +461,7 @@ template <Analyser::Static::Oric::Target::DiskInterface disk_interface> class Co
 
 		// to satisfy CRTMachine::Machine
 		void set_scan_target(Outputs::Display::ScanTarget *scan_target) override final {
-			speaker_.set_input_rate(1000000.0f);
-
-			video_output_.reset(new VideoOutput(ram_));
-			if(!colour_rom_.empty()) video_output_->set_colour_rom(colour_rom_);
-			set_display_type(Outputs::Display::DisplayType::RGB);
+			video_output_.set_scan_target(scan_target);
 		}
 
 		Outputs::Speaker::Speaker *get_speaker() override final {
@@ -534,7 +530,7 @@ template <Analyser::Static::Oric::Target::DiskInterface disk_interface> class Co
 		}
 
 		void set_display_type(Outputs::Display::DisplayType display_type) override {
-//			video_output_->set_video_signal(video_signal);
+			video_output_.set_display_type(display_type);
 		}
 
 		Configurable::SelectionSet get_accurate_selections() override {
@@ -574,11 +570,11 @@ template <Analyser::Static::Oric::Target::DiskInterface disk_interface> class Co
 		CPU::MOS6502::Processor<CPU::MOS6502::Personality::P6502, ConcreteMachine, false> m6502_;
 
 		// RAM and ROM
-		std::vector<uint8_t> rom_, microdisc_rom_, colour_rom_;
+		std::vector<uint8_t> rom_, microdisc_rom_;
 		uint8_t ram_[65536];
 		Cycles cycles_since_video_update_;
 		inline void update_video() {
-			video_output_->run_for(cycles_since_video_update_.flush());
+			video_output_.run_for(cycles_since_video_update_.flush());
 		}
 
 		// ROM bookkeeping
@@ -586,7 +582,7 @@ template <Analyser::Static::Oric::Target::DiskInterface disk_interface> class Co
 		int keyboard_read_count_ = 0;
 
 		// Outputs
-		std::unique_ptr<VideoOutput> video_output_;
+		VideoOutput video_output_;
 
 		Concurrency::DeferringAsyncTaskQueue audio_queue_;
 		GI::AY38910::AY38910 ay8910_;
diff --git a/Machines/Oric/Video.cpp b/Machines/Oric/Video.cpp
index 0df8a7534..394a9d01f 100644
--- a/Machines/Oric/Video.cpp
+++ b/Machines/Oric/Video.cpp
@@ -21,11 +21,7 @@ namespace {
 	const unsigned int PAL60Period = 262*64;
 }
 
-VideoOutput::VideoOutput(uint8_t *memory) :
-		ram_(memory),
-//		crt_(new Outputs::CRT::CRT(64*6, 6, Outputs::Display::Type::PAL50, 2)),
-		v_sync_start_position_(PAL50VSyncStartPosition), v_sync_end_position_(PAL50VSyncEndPosition),
-		counter_period_(PAL50Period) {
+
 //	crt_->set_rgb_sampling_function(
 //		"vec3 rgb_sample(usampler2D sampler, vec2 coordinate)"
 //		"{"
@@ -41,15 +37,25 @@ VideoOutput::VideoOutput(uint8_t *memory) :
 //			"return (float(texValue) - 4.0) / 20.0;"
 //		"}"
 //	);
-	crt_->set_composite_function_type(Outputs::CRT::CRT::CompositeSourceType::DiscreteFourSamplesPerCycle, 0.0f);
+
+VideoOutput::VideoOutput(uint8_t *memory) :
+		ram_(memory),
+		crt_(64*6, 1, Outputs::Display::Type::PAL50, Outputs::Display::InputDataType::Red1Green1Blue1),
+		v_sync_start_position_(PAL50VSyncStartPosition), v_sync_end_position_(PAL50VSyncEndPosition),
+		counter_period_(PAL50Period) {
+//	crt_->set_composite_function_type(Outputs::CRT::CRT::CompositeSourceType::DiscreteFourSamplesPerCycle, 0.0f);
 
 	set_display_type(Outputs::Display::DisplayType::CompositeColour);
-	crt_->set_visible_area(crt_->get_rect_for_area(54, 224, 16 * 6, 40 * 6, 4.0f / 3.0f));
+	crt_.set_visible_area(crt_.get_rect_for_area(54, 224, 16 * 6, 40 * 6, 4.0f / 3.0f));
 }
 
 void VideoOutput::set_display_type(Outputs::Display::DisplayType display_type) {
-//	video_signal_ = video_signal;
-//	crt_->set_video_signal(video_signal);
+	display_type_ = display_type;
+	crt_.set_display_type(display_type);
+}
+
+void VideoOutput::set_scan_target(Outputs::Display::ScanTarget *scan_target) {
+	crt_.set_scan_target(scan_target);
 }
 
 void VideoOutput::set_colour_rom(const std::vector<uint8_t> &rom) {
@@ -69,10 +75,6 @@ void VideoOutput::set_colour_rom(const std::vector<uint8_t> &rom) {
 	}
 }
 
-Outputs::CRT::CRT *VideoOutput::get_crt() {
-	return crt_.get();
-}
-
 void VideoOutput::run_for(const Cycles cycles) {
 	// Vertical: 0-39: pixels; otherwise blank; 48-53 sync, 54-56 colour burst
 	// Horizontal: 0-223: pixels; otherwise blank; 256-259 sync
@@ -88,7 +90,7 @@ void VideoOutput::run_for(const Cycles cycles) {
 		if(counter_ >= v_sync_start_position_ && counter_ < v_sync_end_position_) {
 			// this is a sync line
 			cycles_run_for = v_sync_end_position_ - counter_;
-			clamp(crt_->output_sync((v_sync_end_position_ - v_sync_start_position_) * 6));
+			clamp(crt_.output_sync((v_sync_end_position_ - v_sync_start_position_) * 6));
 		} else if(counter_ < 224*64 && h_counter < 40) {
 			// this is a pixel line
 			if(!h_counter) {
@@ -96,7 +98,7 @@ void VideoOutput::run_for(const Cycles cycles) {
 				paper_ = 0x0;
 				use_alternative_character_set_ = use_double_height_characters_ = blink_text_ = false;
 				set_character_set_base_address();
-				pixel_target_ = reinterpret_cast<uint16_t *>(crt_->begin_data(240));
+				pixel_target_ = reinterpret_cast<uint16_t *>(crt_.begin_data(240));
 
 				if(!counter_) {
 					frame_counter_++;
@@ -193,7 +195,7 @@ void VideoOutput::run_for(const Cycles cycles) {
 			}
 
 			if(h_counter == 40) {
-				crt_->output_data(40 * 6);
+				crt_.output_data(40 * 6);
 			}
 		} else {
 			// this is a blank line (or the equivalent part of a pixel line)
@@ -201,17 +203,17 @@ void VideoOutput::run_for(const Cycles cycles) {
 				cycles_run_for = 48 - h_counter;
 				clamp(
 					int period = (counter_ < 224*64) ? 8 : 48;
-					crt_->output_blank(period * 6);
+					crt_.output_blank(period * 6);
 				);
 			} else if(h_counter < 54) {
 				cycles_run_for = 54 - h_counter;
-				clamp(crt_->output_sync(6 * 6));
+				clamp(crt_.output_sync(6 * 6));
 			} else if(h_counter < 56) {
 				cycles_run_for = 56 - h_counter;
-				clamp(crt_->output_default_colour_burst(2 * 6));
+				clamp(crt_.output_default_colour_burst(2 * 6));
 			} else {
 				cycles_run_for = 64 - h_counter;
-				clamp(crt_->output_blank(8 * 6));
+				clamp(crt_.output_blank(8 * 6));
 			}
 		}
 
diff --git a/Machines/Oric/Video.hpp b/Machines/Oric/Video.hpp
index 2bf579a88..b96bc665e 100644
--- a/Machines/Oric/Video.hpp
+++ b/Machines/Oric/Video.hpp
@@ -21,14 +21,16 @@ namespace Oric {
 class VideoOutput {
 	public:
 		VideoOutput(uint8_t *memory);
-		Outputs::CRT::CRT *get_crt();
+		void set_colour_rom(const std::vector<uint8_t> &colour_rom);
+
 		void run_for(const Cycles cycles);
-		void set_colour_rom(const std::vector<uint8_t> &rom);
+
+		void set_scan_target(Outputs::Display::ScanTarget *scan_target);
 		void set_display_type(Outputs::Display::DisplayType display_type);
 
 	private:
 		uint8_t *ram_;
-		std::unique_ptr<Outputs::CRT::CRT> crt_;
+		Outputs::CRT::CRT crt_;
 
 		// Counters and limits
 		int counter_ = 0, frame_counter_ = 0;