From c42e1f28d679d9764f24cddeae755c8c036f1c4d Mon Sep 17 00:00:00 2001 From: joevt Date: Wed, 28 Feb 2024 16:08:32 -0800 Subject: [PATCH] atimach64gx: Fix fb_pitch calculation. Also, move the calculation to crtc_update where we calculate everything else (including bits per pixel which is needed for the fb_pitch calculation. --- devices/video/atimach64gx.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/devices/video/atimach64gx.cpp b/devices/video/atimach64gx.cpp index a4ec6f4..310ed05 100644 --- a/devices/video/atimach64gx.cpp +++ b/devices/video/atimach64gx.cpp @@ -378,8 +378,7 @@ void AtiMach64Gx::write_reg(uint32_t reg_offset, uint32_t value, uint32_t size) break; case ATI_CRTC_OFF_PITCH: new_value = value; - this->fb_pitch = extract_bits(new_value, ATI_CRTC_PITCH, ATI_CRTC_PITCH_size) * 8; - this->fb_ptr = &this->vram_ptr[extract_bits(new_value, ATI_CRTC_OFFSET, ATI_CRTC_OFFSET_size) * 8]; + this->crtc_update(); return; case ATI_CRTC_INT_CNTL: { @@ -609,6 +608,19 @@ void AtiMach64Gx::crtc_update() need_recalc = true; } + static uint8_t bits_per_pixel[8] = {0, 0, 4, 8, 16, 24, 32, 0}; + + int new_fb_pitch = extract_bits(this->regs[ATI_CRTC_OFF_PITCH], ATI_CRTC_PITCH, ATI_CRTC_PITCH_size) * bits_per_pixel[this->pixel_format]; + if (new_fb_pitch != this->fb_pitch) { + this->fb_pitch = new_fb_pitch; + need_recalc = true; + } + uint8_t* new_fb_ptr = &this->vram_ptr[extract_bits(this->regs[ATI_CRTC_OFF_PITCH], ATI_CRTC_OFFSET, ATI_CRTC_OFFSET_size) * 8]; + if (new_fb_ptr != this->fb_ptr) { + this->fb_ptr = new_fb_ptr; + need_recalc = true; + } + // pixel clock = source_freq / post_div int m = 8 >> (this->dac_regs[Rgb514::F0_M0] >> 6); int vco_div = (this->dac_regs[Rgb514::F0_M0] & 0x3F) + 65;