diff --git a/devices/video/videoctrl.cpp b/devices/video/videoctrl.cpp index 56b2acc..eaa91c0 100644 --- a/devices/video/videoctrl.cpp +++ b/devices/video/videoctrl.cpp @@ -155,15 +155,33 @@ void VideoCtrlBase::start_refresh_task() { this->refresh_task_id = TimerManager::get_instance()->add_cyclic_timer( refresh_interval, [this]() { + // assert VBL interrupt + if (this->int_ctrl) + this->int_ctrl->ack_int(this->irq_id, 1); this->update_screen(); } ); + + uint64_t vbl_duration = static_cast(1.0f / ((double)(this->pixel_clock) / + hori_total / vert_blank) * NS_PER_SEC + 0.5); + this->vbl_end_task_id = TimerManager::get_instance()->add_cyclic_timer( + refresh_interval, + refresh_interval + vbl_duration, + [this]() { + // deassert VBL interrupt + if (this->int_ctrl) + this->int_ctrl->ack_int(this->irq_id, 0); + } + ); } void VideoCtrlBase::stop_refresh_task() { if (this->refresh_task_id) { TimerManager::get_instance()->cancel_timer(this->refresh_task_id); } + if (this->vbl_end_task_id) { + TimerManager::get_instance()->cancel_timer(this->vbl_end_task_id); + } } void VideoCtrlBase::get_palette_colors(uint8_t index, uint8_t& r, uint8_t& g, diff --git a/devices/video/videoctrl.h b/devices/video/videoctrl.h index 14a3b79..6ccb51b 100644 --- a/devices/video/videoctrl.h +++ b/devices/video/videoctrl.h @@ -25,6 +25,7 @@ along with this program. If not, see . #define VIDEO_CTRL_H #include +#include #include #include @@ -66,6 +67,8 @@ protected: int active_height; // height of the visible display area int hori_total = 0; int vert_total = 0; + int hori_blank = 0; + int vert_blank = 0; int pixel_depth; float pixel_clock; float refresh_rate; @@ -76,6 +79,11 @@ protected: uint8_t* fb_ptr; int fb_pitch; uint32_t refresh_task_id = 0; + uint32_t vbl_end_task_id = 0; + + // interrupt suff + InterruptCtrl* int_ctrl = nullptr; + uint32_t irq_id = 0; std::function convert_fb_cb;