From 652cc4f2c94570ea35c2c686e6ce453c7813b31a Mon Sep 17 00:00:00 2001 From: Matthew Budd Date: Tue, 6 Oct 2020 20:08:17 -0400 Subject: [PATCH] Added logic to protect against PPU and NT view windows from crash when being opened with no game loaded. --- src/drivers/Qt/NameTableViewer.cpp | 25 ++++++++++--------------- src/drivers/Qt/ppuViewer.cpp | 17 +++++++++++++---- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/src/drivers/Qt/NameTableViewer.cpp b/src/drivers/Qt/NameTableViewer.cpp index aa70168f..485dbd85 100644 --- a/src/drivers/Qt/NameTableViewer.cpp +++ b/src/drivers/Qt/NameTableViewer.cpp @@ -572,15 +572,8 @@ static void DrawNameTable(int scanline, int ntnum, bool invalidateCache) //obviously this whole scheme of nt cache doesnt work if an mmc5 game is playing tricks with the attribute table } - //pbitmap += (8*3); } - //pbitmap += 7*((NTWIDTH*3)); } - - //this copies the attribute tables to the cache if needed. but we arent using it now because - //if(redrawtables){ - // memcpy(tablecache+0x3c0,table+0x3c0,0x40); - //} } //---------------------------------------------------- void FCEUD_UpdateNTView(int scanline, bool drawall) @@ -594,12 +587,8 @@ void FCEUD_UpdateNTView(int scanline, bool drawall) return; } - //uint8 *pbitmap = ppuv_palette; - //if (!hNTView) return; - ppu_getScroll(xpos,ypos); - if (NTViewSkip < NTViewRefresh) { NTViewSkip++; @@ -618,13 +607,19 @@ void FCEUD_UpdateNTView(int scanline, bool drawall) memcpy(palcache,PALRAM,32); drawall = 1; //palette has changed, so redraw all } + + if ( vnapage[0] == NULL ) + { + return; + } ntmirroring = NT_NONE; - if(vnapage[0] == vnapage[1])ntmirroring = NT_HORIZONTAL; - if(vnapage[0] == vnapage[2])ntmirroring = NT_VERTICAL; - if((vnapage[0] != vnapage[1]) && (vnapage[0] != vnapage[2]))ntmirroring = NT_FOUR_SCREEN; + if (vnapage[0] == vnapage[1])ntmirroring = NT_HORIZONTAL; + if (vnapage[0] == vnapage[2])ntmirroring = NT_VERTICAL; + if ((vnapage[0] != vnapage[1]) && (vnapage[0] != vnapage[2]))ntmirroring = NT_FOUR_SCREEN; - if((vnapage[0] == vnapage[1]) && (vnapage[1] == vnapage[2]) && (vnapage[2] == vnapage[3])){ + if ((vnapage[0] == vnapage[1]) && (vnapage[1] == vnapage[2]) && (vnapage[2] == vnapage[3])) + { if(vnapage[0] == &NTARAM[0x000])ntmirroring = NT_SINGLE_SCREEN_TABLE_0; if(vnapage[0] == &NTARAM[0x400])ntmirroring = NT_SINGLE_SCREEN_TABLE_1; if(vnapage[0] == ExtraNTARAM)ntmirroring = NT_SINGLE_SCREEN_TABLE_2; diff --git a/src/drivers/Qt/ppuViewer.cpp b/src/drivers/Qt/ppuViewer.cpp index a48be32c..ba334f3d 100644 --- a/src/drivers/Qt/ppuViewer.cpp +++ b/src/drivers/Qt/ppuViewer.cpp @@ -510,19 +510,28 @@ void FCEUD_UpdatePPUView(int scanline, int refreshchr) if (refreshchr) { + int i10, x10; for (i = 0, x=0x1000; i < 0x1000; i++, x++) { - chrcache0[i] = VPage[i>>10][i]; - chrcache1[i] = VPage[x>>10][x]; + i10 = i>>10; + x10 = x>>10; + + if ( VPage[i10] == NULL ) + { + continue; + } + chrcache0[i] = VPage[i10][i]; + chrcache1[i] = VPage[x10][x]; + if (debug_loggingCD) { if (cdloggerVideoDataSize) { int addr; - addr = &VPage[i >> 10][i] - CHRptr[0]; + addr = &VPage[i10][i] - CHRptr[0]; if ((addr >= 0) && (addr < (int)cdloggerVideoDataSize)) logcache0[i] = cdloggervdata[addr]; - addr = &VPage[x >> 10][x] - CHRptr[0]; + addr = &VPage[x10][x] - CHRptr[0]; if ((addr >= 0) && (addr < (int)cdloggerVideoDataSize)) logcache1[i] = cdloggervdata[addr]; }