///////////////////////////////////////////////////////////////////////////////
///
///         Space Codesign System Inc. - (https://www.spacecodesign.com)
///         (c) All Rights Reserved. 2018
///
///         No authorization to modify or use this file for
///         commercial purposes without prior written consent
///         of its author(s)
///
///////////////////////////////////////////////////////////////////////////////
#ifndef BASIC_VGA_CONTROLLER_H_
#define BASIC_VGA_CONTROLLER_H_

#include <chrono>
#include <memory>
#include <thread>
#include <list>

typedef struct {
	unsigned char alpha;
	unsigned char blue;
	unsigned char green;
	unsigned char red;
} rgba;

class basic_vga_controller {
public:

	basic_vga_controller(unsigned int width, unsigned int height, unsigned int refresh_rate);
	~basic_vga_controller();

	void save_bitmap(rgba** frame, int index);
	void request_display_frame(rgba** frame);
	void synchronize();
	inline bool can_continue() { return !m_exit_requested; }
	inline void terminate() { m_exit_requested = true; }

private:

	std::unique_ptr<std::thread> m_main_thread;
	unsigned int m_width;
	unsigned int m_height;
	unsigned int m_refresh_rate;
	bool m_exit_requested;
	unsigned int* m_frame;
	unsigned int m_frame_count;

	void vga_emulation();
};

#endif
