From be8530bc3d440ba626a13c6fa0a81f6e7435e857 Mon Sep 17 00:00:00 2001 From: rogerman Date: Tue, 28 Feb 2017 22:04:36 -0800 Subject: [PATCH] GPU: Fix graphical issue in Billiards Action when running at custom framebuffer sizes. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Fixes custom VRAM reads for OBJ bitmap reads when the read location doesn’t start at line 0. This behavior is now consistent with how BG extended layers do it. --- desmume/src/GPU.cpp | 21 ++++++++++++++++++--- desmume/src/GPU.h | 1 + 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/desmume/src/GPU.cpp b/desmume/src/GPU.cpp index 5cdb0a0e5..1a71a6880 100644 --- a/desmume/src/GPU.cpp +++ b/desmume/src/GPU.cpp @@ -470,6 +470,7 @@ void GPUEngineBase::_Reset_Base() this->_needUpdateWINH[1] = true; this->vramBlockOBJIndex = VRAM_NO_3D_USAGE; + this->vramBlockOBJAddress = this->_sprMem; this->nativeLineRenderCount = GPU_FRAMEBUFFER_NATIVE_HEIGHT; this->nativeLineOutputCount = GPU_FRAMEBUFFER_NATIVE_HEIGHT; @@ -3927,13 +3928,25 @@ void GPUEngineBase::_RenderLine_SetupSprites(GPUEngineCompositorInfo &compInfo) template void GPUEngineBase::_RenderLine_LayerOBJ(GPUEngineCompositorInfo &compInfo, itemsForPriority_t *__restrict item) { + bool useCustomVRAM = false; + size_t vramLine = compInfo.line.indexNative; + if (this->vramBlockOBJIndex != VRAM_NO_3D_USAGE) { - GPU->GetEngineMain()->VerifyVRAMLineDidChange(this->vramBlockOBJIndex, compInfo.line.indexNative); + const size_t vramPixel = (size_t)((u8 *)MMU_gpu_map(this->vramBlockOBJAddress) - MMU.ARM9_LCD) / sizeof(u16); + + if (vramPixel < (GPU_FRAMEBUFFER_NATIVE_WIDTH * GPU_VRAM_BLOCK_LINES * 4)) + { + const size_t blockID = vramPixel / (GPU_FRAMEBUFFER_NATIVE_WIDTH * GPU_VRAM_BLOCK_LINES); + const size_t blockPixel = vramPixel % (GPU_FRAMEBUFFER_NATIVE_WIDTH * GPU_VRAM_BLOCK_LINES); + const size_t blockLine = blockPixel / GPU_FRAMEBUFFER_NATIVE_WIDTH; + + vramLine += blockLine; + GPU->GetEngineMain()->VerifyVRAMLineDidChange(blockID, vramLine); + useCustomVRAM = !GPU->GetEngineMain()->isLineCaptureNative[blockID][vramLine]; + } } - const bool useCustomVRAM = (this->vramBlockOBJIndex != VRAM_NO_3D_USAGE) && !GPU->GetEngineMain()->isLineCaptureNative[this->vramBlockOBJIndex][compInfo.line.indexNative]; - const u16 *__restrict srcLine = (useCustomVRAM) ? GPU->GetEngineMain()->GetCustomVRAMBlockPtr(this->vramBlockOBJIndex) + compInfo.line.blockOffsetCustom : NULL; if (this->isLineRenderNative[compInfo.line.indexNative] && useCustomVRAM) { switch (OUTPUTFORMAT) @@ -3976,6 +3989,7 @@ void GPUEngineBase::_RenderLine_LayerOBJ(GPUEngineCompositorInfo &compInfo, item } else { + const u16 *__restrict srcLine = (useCustomVRAM) ? GPU->GetCustomVRAMAddressUsingMappedAddress(this->vramBlockOBJAddress) + compInfo.line.blockOffsetCustom : NULL; void *__restrict dstColorPtr = compInfo.target.lineColorHead; u8 *__restrict dstLayerIDPtr = compInfo.target.lineLayerIDHead; @@ -4475,6 +4489,7 @@ void GPUEngineBase::UpdateVRAM3DUsageProperties_OBJLayer(const size_t bankIndex) if( (vramAddress == (DISPCAPCNT.VRAMWriteOffset * ADDRESS_STEP_32KB)) && (sprSize.width == 64) && (sprSize.height == 64) ) { this->vramBlockOBJIndex = bankIndex; + this->vramBlockOBJAddress = this->_sprMem + (((spriteInfo.TileIndex & 0x3E0) * 64 + (spriteInfo.TileIndex & 0x1F) * 8) << 1); return; } } diff --git a/desmume/src/GPU.h b/desmume/src/GPU.h index 3e2adf272..ba081435a 100644 --- a/desmume/src/GPU.h +++ b/desmume/src/GPU.h @@ -1453,6 +1453,7 @@ public: void LastLineProcess(); u8 vramBlockOBJIndex; + u32 vramBlockOBJAddress; size_t nativeLineRenderCount; size_t nativeLineOutputCount;