From 6fb3849e73b797d4610a2b782127f927dec0c9c9 Mon Sep 17 00:00:00 2001 From: Alejandro Soto Date: Mon, 14 Nov 2022 21:10:40 -0600 Subject: Implement VGA simulation --- tb/vga.hpp | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 tb/vga.hpp (limited to 'tb/vga.hpp') diff --git a/tb/vga.hpp b/tb/vga.hpp new file mode 100644 index 0000000..92446ca --- /dev/null +++ b/tb/vga.hpp @@ -0,0 +1,72 @@ +#ifndef LIBTALLER_VGA_HPP +#define LIBTALLER_VGA_HPP + +#include +#include +#include + +#include +#include + +namespace taller::vga +{ + struct timings + { + unsigned active; + unsigned front_porch; + unsigned sync; + unsigned back_porch; + }; + + struct video_mode + { + std::uint32_t pixel_clk; + timings h; + timings v; + }; + + template + class display + { + public: + display(Crtc &crtc, std::uint32_t clock_hz) noexcept; + + ~display() noexcept; + + void tick(bool clk) noexcept; + + inline bool key(std::size_t index) + { + return keys.at(index); + } + + private: + Crtc& crtc; + SDL_Window *window = nullptr; + const video_mode *mode = nullptr; + unsigned row = 0; + unsigned col = 0; + unsigned hsync_lo = 0; + unsigned hsync_hi = 0; + unsigned vsync_hi = 0; + unsigned vsync_lo = 0; + bool last_hsync = false; + bool last_vsync = false; + bool found_line = false; + const std::uint32_t clock_hz; + + std::array keys = {}; + + void move_pos() noexcept; + void scan_syncs() noexcept; + void scan_vsync() noexcept; + void put_pixel() noexcept; + void guess_mode() noexcept; + void signal_lost() noexcept; + void update_window() noexcept; + }; +} + +#include "vga.impl.hpp" + +#endif -- cgit v1.2.3