From e98a0f5f7e79b82c79ababb2b3eaa59d0b437eed Mon Sep 17 00:00:00 2001 From: michaelangel007 Date: Fri, 2 Jan 2015 17:56:16 -0800 Subject: [PATCH] Optimize rendering so it doesn't hog the CPU --- source/CPU/cpu6502.h | 5 +---- source/CPU/cpu65C02.h | 5 +---- source/CPU/cpu65d02.h | 5 +---- source/NTSC.cpp | 32 +++++++++++++++++--------------- source/NTSC.h | 4 ++-- source/Video.cpp | 6 +++--- 6 files changed, 25 insertions(+), 32 deletions(-) diff --git a/source/CPU/cpu6502.h b/source/CPU/cpu6502.h index 947334e5..3645242e 100644 --- a/source/CPU/cpu6502.h +++ b/source/CPU/cpu6502.h @@ -322,10 +322,7 @@ static DWORD Cpu6502 (DWORD uTotalCycles) // NTSC_BEGIN uElapsedCycles = uExecutedCycles - uPreviousCycles; - if( g_bFullSpeed ) - NTSC_VideoUpdateCycles( uElapsedCycles ); - else - g_pFunc_NTSCVideoUpdateGraphics( uElapsedCycles ); + NTSC_VideoUpdateCycles( uElapsedCycles ); // NTSC_END CheckInterruptSources(uExecutedCycles); diff --git a/source/CPU/cpu65C02.h b/source/CPU/cpu65C02.h index 545f44ab..a85e3c04 100644 --- a/source/CPU/cpu65C02.h +++ b/source/CPU/cpu65C02.h @@ -326,10 +326,7 @@ static DWORD Cpu65C02 (DWORD uTotalCycles) // NTSC_BEGIN uElapsedCycles = uExecutedCycles - uPreviousCycles; - if( g_bFullSpeed ) - NTSC_VideoUpdateCycles( uElapsedCycles ); - else - g_pFunc_NTSCVideoUpdateGraphics( uElapsedCycles ); + NTSC_VideoUpdateCycles( uElapsedCycles ); // NTSC_END CheckInterruptSources(uExecutedCycles); diff --git a/source/CPU/cpu65d02.h b/source/CPU/cpu65d02.h index c082a6c1..bd55a933 100644 --- a/source/CPU/cpu65d02.h +++ b/source/CPU/cpu65d02.h @@ -655,10 +655,7 @@ static DWORD Cpu65D02 (DWORD uTotalCycles) // NTSC_BEGIN uElapsedCycles = uExecutedCycles - uPreviousCycles; - if( g_bFullSpeed ) - NTSC_VideoUpdateCycles( uElapsedCycles ); - else - g_pFunc_NTSCVideoUpdateGraphics( uElapsedCycles ); + NTSC_VideoUpdateCycles( uElapsedCycles ); // NTSC_END CheckInterruptSources(uExecutedCycles); diff --git a/source/NTSC.cpp b/source/NTSC.cpp index b81debfc..6c8a05c1 100644 --- a/source/NTSC.cpp +++ b/source/NTSC.cpp @@ -132,6 +132,17 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA bgra_t *g_pVideoAddress; bgra_t *g_aNTSC_Lines[VIDEO_SCANNER_Y_DISPLAY*2]; // To maintain the 280x192 aspect ratio for 560px width, we double every scan line -> 560x384 + static unsigned (*g_pHorzClockOffset)[VIDEO_SCANNER_MAX_HORZ] = 0; + + typedef void (*Func_t)(long); + static Func_t g_apFuncVideoUpdateScanline[VIDEO_SCANNER_Y_DISPLAY]; + + static void (* g_pFunc_NTSCVideoUpdateText )(long) = 0; // NTSC_UpdateVideoText40; + void (* g_pFunc_NTSCVideoUpdateGraphics)(long) = 0; // NTSC_UpdateVideoText40; + + static void (*g_pFunc_ntscMonoPixel )(int) = 0; //ntscMonoSinglePixel ; + static void (*g_pFunc_ntscColorPixel)(int) = 0; //ntscColorSinglePixel; + static unsigned g_nTextFlashCounter = 0; static uint16_t g_nTextFlashMask = 0; @@ -368,17 +379,6 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA }; - static unsigned (*g_pHorzClockOffset)[VIDEO_SCANNER_MAX_HORZ] = 0; - - static void (* g_pFunc_NTSCVideoUpdateText )(long) = 0; // NTSC_UpdateVideoText40; - void (* g_pFunc_NTSCVideoUpdateGraphics)(long) = 0; // NTSC_UpdateVideoText40; - - static void (*g_pFunc_ntscMonoPixel )(int) = 0; //ntscMonoSinglePixel ; - static void (*g_pFunc_ntscColorPixel)(int) = 0; //ntscColorSinglePixel; - - typedef void (*Func_t)(long); - static Func_t g_apFuncVideoUpdateScanline[VIDEO_SCANNER_Y_DISPLAY]; - // Prototypes // prototype from CPU.h //unsigned char CpuRead(unsigned short addr, unsigned long uExecutedCycles); @@ -1479,11 +1479,15 @@ int NTSC_VideoIsVbl () //=========================================================================== void NTSC_VideoUpdateCycles( long cycles6502 ) { - bool bRedraw = false; + bool bRedraw = cycles6502 >= VIDEO_SCANNER_6502_CYCLES; -// if( !g_bFullSpeed ) +// if( g_bFullSpeed ) // g_pFunc_NTSCVideoUpdateGraphics( cycles6502 ); // else + + while( cycles6502 > VIDEO_SCANNER_6502_CYCLES ) + /* */ cycles6502 -= VIDEO_SCANNER_6502_CYCLES ; + for( ; cycles6502 > 0; cycles6502-- ) { if (VIDEO_SCANNER_MAX_HORZ == ++g_nVideoClockHorz) @@ -1515,9 +1519,7 @@ void NTSC_VideoUpdateCycles( long cycles6502 ) if( bRedraw ) // Force full refresh { for( int y = 0; y < VIDEO_SCANNER_Y_DISPLAY; y++ ) - { g_apFuncVideoUpdateScanline[ y ]( VIDEO_SCANNER_MAX_HORZ ); - } int nCyclesVBlank = (VIDEO_SCANNER_MAX_VERT - VIDEO_SCANNER_Y_DISPLAY) * VIDEO_SCANNER_MAX_HORZ; g_pFunc_NTSCVideoUpdateGraphics( nCyclesVBlank ); diff --git a/source/NTSC.h b/source/NTSC.h index 2cd30486..f693d2cc 100644 --- a/source/NTSC.h +++ b/source/NTSC.h @@ -1,9 +1,9 @@ -#define VIDEO_SCANNER_6502_CYCLES 17030 +// Constants + const int VIDEO_SCANNER_6502_CYCLES = 17030; // Globals (Public) extern uint16_t g_nVideoClockVert; extern uint16_t g_nVideoClockHorz; - extern void (* g_pFunc_NTSCVideoUpdateGraphics)(long); // Prototypes (Public) ________________________________________________ extern void NTSC_SetVideoTextMode( int cols ); diff --git a/source/Video.cpp b/source/Video.cpp index 33271c26..e7bb4b3d 100644 --- a/source/Video.cpp +++ b/source/Video.cpp @@ -1266,7 +1266,7 @@ void VideoRefreshScreen ( int bVideoModeFlags ) if( bVideoModeFlags ) { NTSC_SetVideoMode( bVideoModeFlags ); - g_pFunc_NTSCVideoUpdateGraphics( VIDEO_SCANNER_6502_CYCLES ); + NTSC_VideoUpdateCycles( VIDEO_SCANNER_6502_CYCLES ); } // NTSC_BEGIN: wsVideoRefresh() @@ -1341,7 +1341,7 @@ BYTE VideoSetMode (WORD, WORD address, BYTE write, BYTE, ULONG uExecutedCycles) // NTSC_BEGIN NTSC_SetVideoMode( g_uVideoMode ); // NTSC_END - +#if 0 // NTSC_CLEANUP: Is this still needed?? if (SW_80STORE) g_uVideoMode &= ~VF_PAGE2; @@ -1364,7 +1364,7 @@ BYTE VideoSetMode (WORD, WORD address, BYTE write, BYTE, ULONG uExecutedCycles) g_bVideoUpdatedThisFrame = true; } } - +#endif // NTSC_CLEANUP return MemReadFloatingBus(uExecutedCycles); }