From 191cf4829bb0518605e33ae774a1df8d69367f49 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Fri, 20 Jan 2023 22:29:49 -0500 Subject: [PATCH] Attempt real blank reporting. --- Components/9918/Implementation/9918.cpp | 34 +++++++++++++++------ Components/9918/Implementation/9918Base.hpp | 6 +++- 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/Components/9918/Implementation/9918.cpp b/Components/9918/Implementation/9918.cpp index a7eae4314..65a4ea339 100644 --- a/Components/9918/Implementation/9918.cpp +++ b/Components/9918/Implementation/9918.cpp @@ -292,7 +292,7 @@ void TMS9918::run_for(const HalfCycles cycles) { if( (this->screen_mode_ == ScreenMode::Blank) || - (this->fetch_pointer_.row >= this->mode_timing_.pixel_lines && this->fetch_pointer_.row != this->mode_timing_.total_lines-1)) + this->is_vertical_blank()) next_line_buffer.line_mode = LineMode::Refresh; } } @@ -521,7 +521,7 @@ void Base::output_border(int cycles, [[maybe_unused]] uint32_t cram // MARK: - External interface. template -int Base::masked_address(int address) { +int Base::masked_address(int address) const { if constexpr (is_yamaha_vdp(personality)) { return address & 3; } else { @@ -728,9 +728,9 @@ uint8_t Base::read_register() { // b1 = display field odd/even // b0 = command ongoing return - queued_access_ == MemoryAccess::None ? 0x80 : 0x00 | - 0x40 | - 0x20; + (queued_access_ == MemoryAccess::None ? 0x80 : 0x00) | + (is_vertical_blank() ? 0x40 : 0x00) | + (is_horizontal_blank() ? 0x20 : 0x00); break; } @@ -772,13 +772,29 @@ uint8_t TMS9918::read(int address) { // MARK: - Ephemeral state. template -uint8_t TMS9918::get_current_line() const { - // Determine the row to return. - constexpr int row_change_position = 63; // This is the proper Master System value; substitute if any other VDPs turn out to have this functionality. - int source_row = +int Base::fetch_line() const { + // This is the proper Master System value; TODO: what's correct for Yamaha, etc? + constexpr int row_change_position = 63; + + return (this->fetch_pointer_.column < row_change_position) ? (this->fetch_pointer_.row + this->mode_timing_.total_lines - 1) % this->mode_timing_.total_lines : this->fetch_pointer_.row; +} + +template +bool Base::is_vertical_blank() const { + return fetch_pointer_.row >= mode_timing_.pixel_lines && fetch_pointer_.row != mode_timing_.total_lines - 1; +} + +template +bool Base::is_horizontal_blank() const { + return fetch_pointer_.column < StandardTiming::FirstPixelCycle; +} + +template +uint8_t TMS9918::get_current_line() const { + int source_row = this->fetch_line(); if(this->tv_standard_ == TVStandard::NTSC) { if(this->mode_timing_.pixel_lines == 240) { diff --git a/Components/9918/Implementation/9918Base.hpp b/Components/9918/Implementation/9918Base.hpp index 32f296ab1..261106dea 100644 --- a/Components/9918/Implementation/9918Base.hpp +++ b/Components/9918/Implementation/9918Base.hpp @@ -302,7 +302,11 @@ template struct Base: public Storage { // with the beginning of writing the next, hence the two separate line buffers. LineBufferPointer output_pointer_, fetch_pointer_; - int masked_address(int address); + int fetch_line() const; + bool is_vertical_blank() const; + bool is_horizontal_blank() const; + + int masked_address(int address) const; void write_vram(uint8_t); void write_register(uint8_t); void write_palette(uint8_t);