<commit_before>//
//  DiskController.hpp
//  Clock Signal
//
//  Created by <NAME> on 14/01/2020.
//  Copyright © 2020 <NAME>. All rights reserved.
//

#ifndef DiskController_h
#define DiskController_h

namespace Oric {

class DiskController: public WD::WD1770 {
	public:
		DiskController(WD::WD1770::Personality personality, int clock_rate) :
			WD::WD1770(personality), clock_rate_(clock_rate) {}

		void set_disk(std::shared_ptr<Storage::Disk::Disk> disk, int d) {
			const size_t drive = size_t(d);
			if(!drives_[drive]) {
				drives_[drive] = std::make_unique<Storage::Disk::Drive>(clock_rate_, 300, 2);
				if(drive == selected_drive_) set_drive(drives_[drive]);
			}
			drives_[drive]->set_disk(disk);
		}

		enum class PagedItem {
			DiskROM,
			BASIC,
			RAM
		};

		struct Delegate: public WD1770::Delegate {
			virtual void disk_controller_did_change_paged_item(DiskController *controller) = 0;
		};
		inline void set_delegate(Delegate *delegate)	{
			delegate_ = delegate;
			WD1770::set_delegate(delegate);
			if(delegate) delegate->disk_controller_did_change_paged_item(this);
		}
		inline PagedItem get_paged_item() {
			return paged_item_;
		}

	protected:
		std::array<std::shared_ptr<Storage::Disk::Drive>, 4> drives_;
		size_t selected_drive_;
		void select_drive(size_t drive) {
			if(drive != selected_drive_) {
				selected_drive_ = drive;
				set_drive(drives_[selected_drive_]);
			}
		}
		Delegate *delegate_ = nullptr;

		bool enable_overlay_ram_ = false;
		bool disable_basic_rom_ = false;
		void select_paged_item() {
			PagedItem item = PagedItem::RAM;
			if(!enable_overlay_ram_) {
				item = disable_basic_rom_ ? PagedItem::DiskROM : PagedItem::BASIC;
			}
			set_paged_item(item);
		}

	private:
		PagedItem paged_item_ = PagedItem::DiskROM;
		int clock_rate_;

		inline void set_paged_item(PagedItem item) {
			if(paged_item_ == item) return;<commit_msg>Ensures a safe default-selected drive.<commit_after>//
//  DiskController.hpp
//  Clock Signal
//
//  Created by <NAME> on 14/01/2020.
//  Copyright © 2020 <NAME>. All rights reserved.
//

#ifndef DiskController_h
#define DiskController_h

namespace Oric {

class DiskController: public WD::WD1770 {
	public:
		DiskController(WD::WD1770::Personality personality, int clock_rate) :
			WD::WD1770(personality), clock_rate_(clock_rate) {}

		void set_disk(std::shared_ptr<Storage::Disk::Disk> disk, int d) {
			const size_t drive = size_t(d);
			if(!drives_[drive]) {
				drives_[drive] = std::make_unique<Storage::Disk::Drive>(clock_rate_, 300, 2);
				if(drive == selected_drive_) set_drive(drives_[drive]);
			}
			drives_[drive]->set_disk(disk);
		}

		enum class PagedItem {
			DiskROM,
			BASIC,
			RAM
		};

		struct Delegate: public WD1770::Delegate {
			virtual void disk_controller_did_change_paged_item(DiskController *controller) = 0;
		};
		inline void set_delegate(Delegate *delegate)	{
			delegate_ = delegate;
			WD1770::set_delegate(delegate);
			if(delegate) delegate->disk_controller_did_change_paged_item(this);
		}
		inline PagedItem get_paged_item() {
			return paged_item_;
		}

	protected:
		std::array<std::shared_ptr<Storage::Disk::Drive>, 4> drives_;
		size_t selected_drive_ = 0;
		void select_drive(size_t drive) {
			if(drive != selected_drive_) {
				selected_drive_ = drive;
				set_drive(drives_[selected_drive_]);
			}
		}
		Delegate *delegate_ = nullptr;

		bool enable_overlay_ram_ = false;
		bool disable_basic_rom_ = false;
		void select_paged_item() {
			PagedItem item = PagedItem::RAM;
			if(!enable_overlay_ram_) {
				item = disable_basic_rom_ ? PagedItem::DiskROM : PagedItem::BASIC;
			}
			set_paged_item(item);
		}

	private:
		PagedItem paged_item_ = PagedItem::DiskROM;
		int clock_rate_;

		inline void set_paged_item(PagedItem item) {
			if(paged_item_ == item) return;
{'fraction_non_alphanumeric': 0.12010512483574244, 'fraction_numerical': 0.0202365308804205, 'mean_word_length': 4.556204379562044, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2953371', 'n_tokens_mistral': 1583, 'n_tokens_neox': 1318, 'n_words': 258}