From 3aa5750dcf2bae810c6e915c9ad73fd80858a9bc Mon Sep 17 00:00:00 2001 From: TomCh Date: Mon, 28 Dec 2020 16:25:29 +0000 Subject: [PATCH] Make Video.cpp and WinVideo.cpp into a dependent class hierarchy (PR #898) . class hierarchy: WinVideo IS_A Video (ie. WinVideo is a subclass of Video) . GetVideo() singleton instance of WinVideo in AppleWin.cpp, exposed via Interface.h --- source/CPU.cpp | 1 - source/CmdLine.cpp | 8 +- source/CmdLine.h | 1 - source/Configuration/Config.h | 4 +- source/Configuration/PageAdvanced.cpp | 3 +- source/Configuration/PageConfig.cpp | 37 +- source/Configuration/PageDisk.cpp | 3 +- source/Configuration/PageInput.cpp | 2 +- source/Configuration/PageSound.cpp | 2 +- source/Configuration/PropertySheetHelper.cpp | 5 +- source/Core.cpp | 8 +- source/Debugger/Debug.cpp | 21 +- source/Debugger/Debugger_Display.cpp | 19 +- source/Disk.cpp | 9 +- source/Harddisk.cpp | 2 - source/Interface.h | 9 +- source/Memory.cpp | 41 ++- source/MouseInterface.cpp | 1 - source/NTSC.cpp | 108 +++--- source/NTSC.h | 2 - source/NTSC_CharSet.cpp | 21 +- source/RGBMonitor.cpp | 30 +- source/SaveState.cpp | 11 +- source/Utilities.cpp | 11 +- source/Video.cpp | 360 ++++++++----------- source/Video.h | 352 +++++++++++------- source/Windows/AppleWin.cpp | 41 ++- source/Windows/WinFrame.cpp | 70 ++-- source/Windows/WinVideo.cpp | 154 +++----- source/Windows/WinVideo.h | 54 ++- 30 files changed, 691 insertions(+), 699 deletions(-) diff --git a/source/CPU.cpp b/source/CPU.cpp index a6b4f6e1..2be35bcf 100644 --- a/source/CPU.cpp +++ b/source/CPU.cpp @@ -96,7 +96,6 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #include "Speech.h" #endif #include "SynchronousEventManager.h" -#include "Video.h" #include "NTSC.h" #include "Log.h" diff --git a/source/CmdLine.cpp b/source/CmdLine.cpp index e57ff541..29dea833 100644 --- a/source/CmdLine.cpp +++ b/source/CmdLine.cpp @@ -306,7 +306,7 @@ bool ProcessCmdLine(LPSTR lpCmdLine) lpCmdLine = GetCurrArg(lpNextArg); lpNextArg = GetNextArg(lpNextArg); - if (!ReadVideoRomFile(lpCmdLine)) + if (!GetVideo().ReadVideoRomFile(lpCmdLine)) { std::string msg = "Failed to load video rom (not found or not exactly 2/4/8/16KiB)\n"; LogFileOutput("%s", msg.c_str()); @@ -314,12 +314,12 @@ bool ProcessCmdLine(LPSTR lpCmdLine) } else { - SetVideoRomRockerSwitch(true); // Use PAL char set + GetVideo().SetVideoRomRockerSwitch(true); // Use PAL char set } } else if (strcmp(lpCmdLine, "-printscreen") == 0) // Turn on display of the last filename print screen was saved to { - g_bDisplayPrintScreenFileName = true; + GetVideo().SetDisplayPrintScreenFileName(true); } else if (strcmp(lpCmdLine, "-no-printscreen-key") == 0) // Don't try to capture PrintScreen key GH#469 { @@ -327,7 +327,7 @@ bool ProcessCmdLine(LPSTR lpCmdLine) } else if (strcmp(lpCmdLine, "-no-printscreen-dlg") == 0) // Turn off the PrintScreen warning message dialog (if PrintScreen key can't be grabbed) { - g_bShowPrintScreenWarningDialog = false; + GetVideo().SetShowPrintScreenWarningDialog(false); } else if (strcmp(lpCmdLine, "-no-hook-system-key") == 0) // Don't hook the System keys (eg. Left-ALT+ESC/SPACE/TAB) GH#556 { diff --git a/source/CmdLine.h b/source/CmdLine.h index 9d2b387b..cce9b993 100644 --- a/source/CmdLine.h +++ b/source/CmdLine.h @@ -3,7 +3,6 @@ #include "RgbMonitor.h" #include "Harddisk.h" #include "Disk.h" -#include "Video.h" #include "Common.h" #include "Card.h" diff --git a/source/Configuration/Config.h b/source/Configuration/Config.h index 0369ed48..a2b52e10 100644 --- a/source/Configuration/Config.h +++ b/source/Configuration/Config.h @@ -5,7 +5,7 @@ #include "../CPU.h" #include "../DiskImage.h" // Disk_Status_e #include "../Harddisk.h" // HD_CardIsEnabled() -#include "../Video.h" // VideoRefreshRate_e, GetVideoRefreshRate() +#include "../Interface.h" // VideoRefreshRate_e, GetVideoRefreshRate() class CConfigNeedingRestart { @@ -14,7 +14,7 @@ public: m_Apple2Type( GetApple2Type() ), m_CpuType( GetMainCpu() ), m_uSaveLoadStateMsg(0), - m_videoRefreshRate( GetVideoRefreshRate() ) + m_videoRefreshRate( GetVideo().GetVideoRefreshRate() ) { m_bEnableHDD = HD_CardIsEnabled(); m_bEnableTheFreezesF8Rom = bEnableTheFreezesF8Rom; diff --git a/source/Configuration/PageAdvanced.cpp b/source/Configuration/PageAdvanced.cpp index f3b286f0..26e4e9e4 100644 --- a/source/Configuration/PageAdvanced.cpp +++ b/source/Configuration/PageAdvanced.cpp @@ -22,8 +22,9 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "StdAfx.h" + #include "PageAdvanced.h" -#include "PropertySheetHelper.h" +#include "PropertySheet.h" #include "../Common.h" #include "../ParallelPrinter.h" diff --git a/source/Configuration/PageConfig.cpp b/source/Configuration/PageConfig.cpp index f810f152..9cfb7447 100644 --- a/source/Configuration/PageConfig.cpp +++ b/source/Configuration/PageConfig.cpp @@ -24,9 +24,8 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #include "StdAfx.h" #include "PageConfig.h" -#include "PropertySheetHelper.h" +#include "PropertySheet.h" -#include "../Interface.h" #include "../Windows/AppleWin.h" #include "../Windows/WinFrame.h" #include "../Registry.h" @@ -117,7 +116,7 @@ BOOL CPageConfig::DlgProcInternal(HWND hWnd, UINT message, WPARAM wparam, LPARAM break; case IDC_MONOCOLOR: - VideoChooseMonochromeColor(); + GetVideo().ChooseMonochromeColor(); break; case IDC_CHECK_CONFIRM_REBOOT: @@ -201,12 +200,12 @@ BOOL CPageConfig::DlgProcInternal(HWND hWnd, UINT message, WPARAM wparam, LPARAM CheckDlgButton(hWnd, IDC_CHECK_CONFIRM_REBOOT, GetFrame().g_bConfirmReboot ? BST_CHECKED : BST_UNCHECKED ); - m_PropertySheetHelper.FillComboBox(hWnd,IDC_VIDEOTYPE, g_aVideoChoices, GetVideoType()); - CheckDlgButton(hWnd, IDC_CHECK_HALF_SCAN_LINES, IsVideoStyle(VS_HALF_SCANLINES) ? BST_CHECKED : BST_UNCHECKED); + m_PropertySheetHelper.FillComboBox(hWnd,IDC_VIDEOTYPE, GetVideo().GetVideoChoices(), GetVideo().GetVideoType()); + CheckDlgButton(hWnd, IDC_CHECK_HALF_SCAN_LINES, GetVideo().IsVideoStyle(VS_HALF_SCANLINES) ? BST_CHECKED : BST_UNCHECKED); CheckDlgButton(hWnd, IDC_CHECK_FS_SHOW_SUBUNIT_STATUS, GetFullScreenShowSubunitStatus() ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hWnd, IDC_CHECK_VERTICAL_BLEND, IsVideoStyle(VS_COLOR_VERTICAL_BLEND) ? BST_CHECKED : BST_UNCHECKED); - EnableWindow(GetDlgItem(hWnd, IDC_CHECK_VERTICAL_BLEND), (GetVideoType() == VT_COLOR_IDEALIZED) ? TRUE : FALSE); + CheckDlgButton(hWnd, IDC_CHECK_VERTICAL_BLEND, GetVideo().IsVideoStyle(VS_COLOR_VERTICAL_BLEND) ? BST_CHECKED : BST_UNCHECKED); + EnableWindow(GetDlgItem(hWnd, IDC_CHECK_VERTICAL_BLEND), (GetVideo().GetVideoType() == VT_COLOR_IDEALIZED) ? TRUE : FALSE); if (GetCardMgr().IsSSCInstalled()) { @@ -219,7 +218,7 @@ BOOL CPageConfig::DlgProcInternal(HWND hWnd, UINT message, WPARAM wparam, LPARAM EnableWindow(GetDlgItem(hWnd, IDC_SERIALPORT), FALSE); } - CheckDlgButton(hWnd, IDC_CHECK_50HZ_VIDEO, (GetVideoRefreshRate() == VR_50HZ) ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hWnd, IDC_CHECK_50HZ_VIDEO, (GetVideo().GetVideoRefreshRate() == VR_50HZ) ? BST_CHECKED : BST_UNCHECKED); SendDlgItemMessage(hWnd,IDC_SLIDER_CPU_SPEED,TBM_SETRANGE,1,MAKELONG(0,40)); SendDlgItemMessage(hWnd,IDC_SLIDER_CPU_SPEED,TBM_SETPAGESIZE,0,5); @@ -275,36 +274,36 @@ void CPageConfig::DlgOK(HWND hWnd) bool bVideoReinit = false; const VideoType_e newVideoType = (VideoType_e) SendDlgItemMessage(hWnd, IDC_VIDEOTYPE, CB_GETCURSEL, 0, 0); - if (GetVideoType() != newVideoType) + if (GetVideo().GetVideoType() != newVideoType) { - SetVideoType(newVideoType); + GetVideo().SetVideoType(newVideoType); bVideoReinit = true; } const bool newHalfScanLines = IsDlgButtonChecked(hWnd, IDC_CHECK_HALF_SCAN_LINES) != 0; - const bool currentHalfScanLines = IsVideoStyle(VS_HALF_SCANLINES); + const bool currentHalfScanLines = GetVideo().IsVideoStyle(VS_HALF_SCANLINES); if (currentHalfScanLines != newHalfScanLines) { if (newHalfScanLines) - SetVideoStyle( (VideoStyle_e) (GetVideoStyle() | VS_HALF_SCANLINES) ); + GetVideo().SetVideoStyle( (VideoStyle_e) (GetVideo().GetVideoStyle() | VS_HALF_SCANLINES) ); else - SetVideoStyle( (VideoStyle_e) (GetVideoStyle() & ~VS_HALF_SCANLINES) ); + GetVideo().SetVideoStyle( (VideoStyle_e) (GetVideo().GetVideoStyle() & ~VS_HALF_SCANLINES) ); bVideoReinit = true; } const bool newVerticalBlend = IsDlgButtonChecked(hWnd, IDC_CHECK_VERTICAL_BLEND) != 0; - const bool currentVerticalBlend = IsVideoStyle(VS_COLOR_VERTICAL_BLEND); + const bool currentVerticalBlend = GetVideo().IsVideoStyle(VS_COLOR_VERTICAL_BLEND); if (currentVerticalBlend != newVerticalBlend) { if (newVerticalBlend) - SetVideoStyle( (VideoStyle_e) (GetVideoStyle() | VS_COLOR_VERTICAL_BLEND) ); + GetVideo().SetVideoStyle( (VideoStyle_e) (GetVideo().GetVideoStyle() | VS_COLOR_VERTICAL_BLEND) ); else - SetVideoStyle( (VideoStyle_e) (GetVideoStyle() & ~VS_COLOR_VERTICAL_BLEND) ); + GetVideo().SetVideoStyle( (VideoStyle_e) (GetVideo().GetVideoStyle() & ~VS_COLOR_VERTICAL_BLEND) ); bVideoReinit = true; } const bool isNewVideoRate50Hz = IsDlgButtonChecked(hWnd, IDC_CHECK_50HZ_VIDEO) != 0; - const bool isCurrentVideoRate50Hz = GetVideoRefreshRate() == VR_50HZ; + const bool isCurrentVideoRate50Hz = GetVideo().GetVideoRefreshRate() == VR_50HZ; if (isCurrentVideoRate50Hz != isNewVideoRate50Hz) { m_PropertySheetHelper.GetConfigNew().m_videoRefreshRate = isNewVideoRate50Hz ? VR_50HZ : VR_60HZ; @@ -312,11 +311,11 @@ void CPageConfig::DlgOK(HWND hWnd) if (bVideoReinit) { - Config_Save_Video(); + GetVideo().Config_Save_Video(); GetFrame().FrameRefreshStatus(DRAW_TITLE, false); - VideoReinitialize(); + GetVideo().VideoReinitialize(); if ((g_nAppMode != MODE_LOGO) && (g_nAppMode != MODE_DEBUG)) { GetFrame().VideoRedrawScreen(); diff --git a/source/Configuration/PageDisk.cpp b/source/Configuration/PageDisk.cpp index 72634f16..71e57e9f 100644 --- a/source/Configuration/PageDisk.cpp +++ b/source/Configuration/PageDisk.cpp @@ -24,9 +24,8 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #include "StdAfx.h" #include "PageDisk.h" -#include "PropertySheetHelper.h" +#include "PropertySheet.h" -#include "../Interface.h" #include "../Windows/AppleWin.h" #include "../CardManager.h" #include "../Disk.h" // Drive_e, Disk_Status_e diff --git a/source/Configuration/PageInput.cpp b/source/Configuration/PageInput.cpp index db46f844..15545279 100644 --- a/source/Configuration/PageInput.cpp +++ b/source/Configuration/PageInput.cpp @@ -24,7 +24,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #include "StdAfx.h" #include "PageInput.h" -#include "PropertySheetHelper.h" +#include "PropertySheet.h" #include "../SaveState_Structs_common.h" #include "../Common.h" diff --git a/source/Configuration/PageSound.cpp b/source/Configuration/PageSound.cpp index a481600a..d236afdf 100644 --- a/source/Configuration/PageSound.cpp +++ b/source/Configuration/PageSound.cpp @@ -24,7 +24,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #include "StdAfx.h" #include "PageSound.h" -#include "PropertySheetHelper.h" +#include "PropertySheet.h" #include "../SaveState_Structs_common.h" #include "../Common.h" diff --git a/source/Configuration/PropertySheetHelper.cpp b/source/Configuration/PropertySheetHelper.cpp index 236bc980..f164b2d6 100644 --- a/source/Configuration/PropertySheetHelper.cpp +++ b/source/Configuration/PropertySheetHelper.cpp @@ -23,8 +23,8 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #include "StdAfx.h" +#include "PropertySheet.h" #include "PropertySheetHelper.h" -#include "IPropertySheet.h" #include "../Windows/AppleWin.h" // g_nAppMode, g_uScrollLockToggle, sg_PropertySheet #include "../CardManager.h" @@ -33,7 +33,6 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #include "../Log.h" #include "../Registry.h" #include "../SaveState.h" -#include "../Interface.h" /* Config causing AfterClose msgs: @@ -388,7 +387,7 @@ void CPropertySheetHelper::SaveCurrentConfig(void) m_ConfigOld.m_Slot[SLOT5] = GetCardMgr().QuerySlot(SLOT5); m_ConfigOld.m_bEnableHDD = HD_CardIsEnabled(); m_ConfigOld.m_bEnableTheFreezesF8Rom = GetPropertySheet().GetTheFreezesF8Rom(); - m_ConfigOld.m_videoRefreshRate = GetVideoRefreshRate(); + m_ConfigOld.m_videoRefreshRate = GetVideo().GetVideoRefreshRate(); // Reset flags each time: m_ConfigOld.m_uSaveLoadStateMsg = 0; diff --git a/source/Core.cpp b/source/Core.cpp index fe118b9e..aeeccce0 100644 --- a/source/Core.cpp +++ b/source/Core.cpp @@ -31,7 +31,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #include "Core.h" #include "CardManager.h" #include "CPU.h" -#include "Video.h" +#include "Interface.h" #include "Log.h" #include "Memory.h" #include "Mockingboard.h" @@ -194,7 +194,7 @@ CardManager& GetCardMgr(void) double Get6502BaseClock(void) { - return (GetVideoRefreshRate() == VR_50HZ) ? CLK_6502_PAL : CLK_6502_NTSC; + return (GetVideo().GetVideoRefreshRate() == VR_50HZ) ? CLK_6502_PAL : CLK_6502_NTSC; } void SetCurrentCLK6502(void) @@ -202,11 +202,11 @@ void SetCurrentCLK6502(void) static DWORD dwPrevSpeed = (DWORD) -1; static VideoRefreshRate_e prevVideoRefreshRate = VR_NONE; - if (dwPrevSpeed == g_dwSpeed && GetVideoRefreshRate() == prevVideoRefreshRate) + if (dwPrevSpeed == g_dwSpeed && GetVideo().GetVideoRefreshRate() == prevVideoRefreshRate) return; dwPrevSpeed = g_dwSpeed; - prevVideoRefreshRate = GetVideoRefreshRate(); + prevVideoRefreshRate = GetVideo().GetVideoRefreshRate(); // SPEED_MIN = 0 = 0.50 MHz // SPEED_NORMAL = 10 = 1.00 MHz diff --git a/source/Debugger/Debug.cpp b/source/Debugger/Debug.cpp index daa6da3b..88c61eea 100644 --- a/source/Debugger/Debug.cpp +++ b/source/Debugger/Debug.cpp @@ -46,7 +46,6 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #include "../SoundCore.h" // SoundCore_SetFade() #include "../Windows/WinVideo.h" #include "../Windows/WinFrame.h" -#include "../Video.h" // #define DEBUG_COMMAND_HELP 1 // #define DEBUG_ASM_HASH 1 @@ -4942,7 +4941,7 @@ size_t Util_GetTextScreen ( char* &pText_ ) g_nTextScreen = 0; memset( pBeg, 0, sizeof( g_aTextScreen ) ); - unsigned int uBank2 = VideoGetSWPAGE2() ? 1 : 0; + unsigned int uBank2 = GetVideo().VideoGetSWPAGE2() ? 1 : 0; LPBYTE g_pTextBank1 = MemGetAuxPtr (0x400 << uBank2); LPBYTE g_pTextBank0 = MemGetMainPtr(0x400 << uBank2); @@ -4955,7 +4954,7 @@ size_t Util_GetTextScreen ( char* &pText_ ) { char c; // TODO: FormatCharTxtCtrl() ? - if ( VideoGetSW80COL() ) + if ( GetVideo().VideoGetSW80COL() ) { // AUX c = g_pTextBank1[ nAddressStart ] & 0x7F; c = RemapChar(c); @@ -5432,7 +5431,7 @@ Update_t CmdNTSC (int nArgs) } }; - bool bColorTV = (g_eVideoType == VT_COLOR_TV); + bool bColorTV = (GetVideo().GetVideoType() == VT_COLOR_TV); uint32_t* pChromaTable = NTSC_VideoGetChromaTable( false, bColorTV ); char aStatusText[ CONSOLE_WIDTH*2 ] = "Loaded"; @@ -5467,7 +5466,7 @@ Update_t CmdNTSC (int nArgs) // Write BMP header WinBmpHeader_t bmp, *pBmp = &bmp; - Video_SetBitmapHeader( pBmp, 64, 256, 32 ); + GetVideo().Video_SetBitmapHeader( pBmp, 64, 256, 32 ); fwrite( pBmp, sizeof( WinBmpHeader_t ), 1, pFile ); } else @@ -5637,7 +5636,7 @@ int CmdTextSave (int nArgs) g_sMemoryLoadSaveFileName = g_aArgs[ 1 ].sArg; else { - if( VideoGetSW80COL() ) + if( GetVideo().VideoGetSW80COL() ) g_sMemoryLoadSaveFileName = "AppleWin_Text80.txt"; else g_sMemoryLoadSaveFileName = "AppleWin_Text40.txt"; @@ -6886,8 +6885,8 @@ Update_t _ViewOutput( ViewVideoPage_t iPage, int bVideoModeFlags ) switch( iPage ) { case VIEW_PAGE_X: - bVideoModeFlags |= !VideoGetSWPAGE2() ? 0 : VF_PAGE2; - bVideoModeFlags |= !VideoGetSWMIXED() ? 0 : VF_MIXED; + bVideoModeFlags |= !GetVideo().VideoGetSWPAGE2() ? 0 : VF_PAGE2; + bVideoModeFlags |= !GetVideo().VideoGetSWMIXED() ? 0 : VF_MIXED; break; // Page Current & current MIXED state case VIEW_PAGE_1: bVideoModeFlags |= 0; break; // Page 1 case VIEW_PAGE_2: bVideoModeFlags |= VF_PAGE2; break; // Page 2 @@ -6897,7 +6896,7 @@ Update_t _ViewOutput( ViewVideoPage_t iPage, int bVideoModeFlags ) } DebugVideoMode::Instance().Set(bVideoModeFlags); - VideoRefreshScreen( bVideoModeFlags, true ); + GetVideo().VideoRefreshScreen( bVideoModeFlags, true ); return UPDATE_NOTHING; // intentional } @@ -7450,7 +7449,7 @@ Update_t CmdWindowViewOutput (int nArgs) { GetFrame().VideoRedrawScreen(); - DebugVideoMode::Instance().Set(g_uVideoMode); + DebugVideoMode::Instance().Set( GetVideo().GetVideoMode() ); return UPDATE_NOTHING; // intentional } @@ -9584,7 +9583,7 @@ void DebugDisplay( BOOL bInitDisasm/*=FALSE*/ ) { uint32_t mode = 0; DebugVideoMode::Instance().Get(&mode); - VideoRefreshScreen(mode, true); + GetVideo().VideoRefreshScreen(mode, true); return; } diff --git a/source/Debugger/Debugger_Display.cpp b/source/Debugger/Debugger_Display.cpp index 46f26f69..915ba308 100644 --- a/source/Debugger/Debugger_Display.cpp +++ b/source/Debugger/Debugger_Display.cpp @@ -40,7 +40,6 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #include "../Memory.h" #include "../Mockingboard.h" #include "../NTSC.h" -#include "../Video.h" // NEW UI debugging - force display ALL meta-info (regs, stack, bp, watches, zp) for debugging purposes #define DEBUG_FORCE_DISPLAY 0 @@ -683,7 +682,7 @@ void StretchBltMemToFrameDC(void) wdest, hdest, // int nWidthDest, int nHeightDest, GetDebuggerMemDC(), // HDC hdcSrc, 0, 0, // int nXOriginSrc, int nYOriginSrc, - GetFrameBufferBorderlessWidth(), GetFrameBufferBorderlessHeight(), // int nWidthSrc, int nHeightSrc, + GetVideo().GetFrameBufferBorderlessWidth(), GetVideo().GetFrameBufferBorderlessHeight(), // int nWidthSrc, int nHeightSrc, SRCCOPY // DWORD dwRop ); } @@ -3124,25 +3123,25 @@ void DrawSoftSwitches( int iSoftSwitch ) bool bSet; // $C050 / $C051 = TEXTOFF/TEXTON = SW.TXTCLR/SW.TXTSET - bSet = !VideoGetSWTEXT(); + bSet = !GetVideo().VideoGetSWTEXT(); _DrawSoftSwitch( rect, 0xC050, bSet, NULL, "GR.", "TEXT" ); // $C052 / $C053 = MIXEDOFF/MIXEDON = SW.MIXCLR/SW.MIXSET // FULL/MIXED // MIX OFF/ON - bSet = !VideoGetSWMIXED(); + bSet = !GetVideo().VideoGetSWMIXED(); _DrawSoftSwitch( rect, 0xC052, bSet, NULL, "FULL", "MIX" ); // $C054 / $C055 = PAGE1/PAGE2 = PAGE2OFF/PAGE2ON = SW.LOWSCR/SW.HISCR // PAGE 1 / 2 - bSet = !VideoGetSWPAGE2(); + bSet = !GetVideo().VideoGetSWPAGE2(); _DrawSoftSwitch( rect, 0xC054, bSet, "PAGE ", "1", "2" ); // $C056 / $C057 LORES/HIRES = HIRESOFF/HIRESON = SW.LORES/SW.HIRES // LO / HIRES // LO / ----- // -- / HIRES - bSet = !VideoGetSWHIRES(); + bSet = !GetVideo().VideoGetSWHIRES(); _DrawSoftSwitch( rect, 0xC056, bSet, NULL, "LO", "HI", "RES" ); DebuggerSetColorBG( DebuggerGetColor( BG_INFO )); @@ -3150,7 +3149,7 @@ void DrawSoftSwitches( int iSoftSwitch ) // 280/560 HGR // C05E = ON, C05F = OFF - bSet = VideoGetSWDHIRES(); + bSet = GetVideo().VideoGetSWDHIRES(); _DrawSoftSwitch( rect, 0xC05E, bSet, NULL, "DHGR", "HGR" ); @@ -3158,18 +3157,18 @@ void DrawSoftSwitches( int iSoftSwitch ) int bgMemory = BG_DATA_2; // C000 = 80STOREOFF, C001 = 80STOREON - bSet = !VideoGetSW80STORE(); + bSet = !GetVideo().VideoGetSW80STORE(); _DrawSoftSwitch( rect, 0xC000, bSet, "80Sto", "0", "1", NULL, bgMemory ); // C002 .. C005 _DrawSoftSwitchMainAuxBanks( rect, bgMemory ); // C00C = off, C00D = on - bSet = !VideoGetSW80COL(); + bSet = !GetVideo().VideoGetSW80COL(); _DrawSoftSwitch( rect, 0xC00C, bSet, "Col", "40", "80", NULL, bgMemory ); // C00E = off, C00F = on - bSet = !VideoGetSWAltCharSet(); + bSet = !GetVideo().VideoGetSWAltCharSet(); _DrawSoftSwitch( rect, 0xC00E, bSet, NULL, "ASC", "MOUS", NULL, bgMemory ); // ASCII/MouseText #if SOFTSWITCH_LANGCARD diff --git a/source/Disk.cpp b/source/Disk.cpp index 7eac5512..250e8e27 100644 --- a/source/Disk.cpp +++ b/source/Disk.cpp @@ -42,7 +42,6 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #include "Memory.h" #include "Registry.h" #include "SaveState.h" -#include "Video.h" #include "YamlHelper.h" #include "../resource/resource.h" @@ -352,7 +351,7 @@ void Disk2InterfaceCard::EjectDisk(const int drive) Snapshot_UpdatePath(); SaveLastDiskImage(drive); - Video_ResetScreenshotCounter(""); + GetVideo().Video_ResetScreenshotCounter(""); } void Disk2InterfaceCard::UnplugDrive(const int drive) @@ -710,14 +709,14 @@ ImageError_e Disk2InterfaceCard::InsertDisk(const int drive, LPCTSTR pszImageFil GetImageTitle(pszImageFilename, pFloppy->m_imagename, pFloppy->m_fullname); Snapshot_UpdatePath(); - Video_ResetScreenshotCounter(pFloppy->m_imagename); + GetVideo().Video_ResetScreenshotCounter(pFloppy->m_imagename); if (g_nAppMode == MODE_LOGO) InitFirmware(GetCxRomPeripheral()); } else { - Video_ResetScreenshotCounter(""); + GetVideo().Video_ResetScreenshotCounter(""); } SaveLastDiskImage(drive); @@ -1577,8 +1576,6 @@ bool Disk2InterfaceCard::UserSelectNewDiskImage(const int drive, LPCSTR pszFilen RegLoadString(TEXT(REG_PREFS), TEXT(REGVALUE_PREF_START_DIR), 1, directory, MAX_PATH, TEXT("")); StringCbPrintf(title, 40, TEXT("Select Disk Image For Drive %d"), drive + 1); - _ASSERT(sizeof(OPENFILENAME) == sizeof(OPENFILENAME_NT4)); // Required for Win98/ME support (selected by _WIN32_WINNT=0x0400 in stdafx.h) - OPENFILENAME ofn; memset(&ofn, 0, sizeof(OPENFILENAME)); ofn.lStructSize = sizeof(OPENFILENAME); diff --git a/source/Harddisk.cpp b/source/Harddisk.cpp index 25c4fd77..6911fb61 100644 --- a/source/Harddisk.cpp +++ b/source/Harddisk.cpp @@ -460,8 +460,6 @@ static bool HD_SelectImage(const int drive, LPCSTR pszFilename) RegLoadString(TEXT(REG_PREFS), TEXT(REGVALUE_PREF_HDV_START_DIR), 1, directory, MAX_PATH, TEXT("")); StringCbPrintf(title, 40, TEXT("Select HDV Image For HDD %d"), drive + 1); - _ASSERT(sizeof(OPENFILENAME) == sizeof(OPENFILENAME_NT4)); // Required for Win98/ME support (selected by _WIN32_WINNT=0x0400 in stdafx.h) - OPENFILENAME ofn; memset(&ofn, 0, sizeof(OPENFILENAME)); ofn.lStructSize = sizeof(OPENFILENAME); diff --git a/source/Interface.h b/source/Interface.h index f2d0db47..119b39a7 100644 --- a/source/Interface.h +++ b/source/Interface.h @@ -1,6 +1,6 @@ #pragma once -// an AppleWin frontend must provide the implementation of these 2 methods +// an AppleWin frontend must provide the implementation of these methods // // once this is done, // the core emulator files (i.e. almost all the .cpp directly in Source) @@ -8,8 +8,11 @@ // this does not include the main event loop which is left in the arch specific area // nor the actual rendering of the video buffer to screen +#include "Video.h" +Video& GetVideo(void); + #include "Configuration/PropertySheet.h" -IPropertySheet& GetPropertySheet(); +IPropertySheet& GetPropertySheet(void); #include "FrameBase.h" -FrameBase& GetFrame(); +FrameBase& GetFrame(void); diff --git a/source/Memory.cpp b/source/Memory.cpp index 6640a844..f58596d2 100644 --- a/source/Memory.cpp +++ b/source/Memory.cpp @@ -43,7 +43,6 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #include "Log.h" #include "Mockingboard.h" #include "MouseInterface.h" -#include "Video.h" #include "NTSC.h" #include "NoSlotClock.h" #include "ParallelPrinter.h" @@ -419,7 +418,7 @@ static BYTE __stdcall IOWrite_C00x(WORD pc, WORD addr, BYTE bWrite, BYTE d, ULON if ((addr & 0xf) <= 0xB) return MemSetPaging(pc, addr, bWrite, d, nExecutedCycles); else - return VideoSetMode(pc, addr, bWrite, d, nExecutedCycles); + return GetVideo().VideoSetMode(pc, addr, bWrite, d, nExecutedCycles); } //------------------------------------- @@ -441,13 +440,13 @@ static BYTE __stdcall IORead_C01x(WORD pc, WORD addr, BYTE bWrite, BYTE d, ULONG case 0x6: res = SW_ALTZP ? true : false; break; case 0x7: res = SW_SLOTC3ROM ? true : false; break; case 0x8: res = SW_80STORE ? true : false; break; - case 0x9: res = VideoGetVblBar(nExecutedCycles); break; - case 0xA: res = VideoGetSWTEXT(); break; - case 0xB: res = VideoGetSWMIXED(); break; + case 0x9: res = GetVideo().VideoGetVblBar(nExecutedCycles); break; + case 0xA: res = GetVideo().VideoGetSWTEXT(); break; + case 0xB: res = GetVideo().VideoGetSWMIXED(); break; case 0xC: res = SW_PAGE2 ? true : false; break; - case 0xD: res = VideoGetSWHIRES(); break; - case 0xE: res = VideoGetSWAltCharSet(); break; - case 0xF: res = VideoGetSW80COL(); break; + case 0xD: res = GetVideo().VideoGetSWHIRES(); break; + case 0xE: res = GetVideo().VideoGetSWAltCharSet(); break; + case 0xF: res = GetVideo().VideoGetSW80COL(); break; } return KeybGetKeycode() | (res ? 0x80 : 0); @@ -500,10 +499,10 @@ static BYTE __stdcall IORead_C05x(WORD pc, WORD addr, BYTE bWrite, BYTE d, ULONG { switch (addr & 0xf) { - case 0x0: return VideoSetMode(pc, addr, bWrite, d, nExecutedCycles); - case 0x1: return VideoSetMode(pc, addr, bWrite, d, nExecutedCycles); - case 0x2: return VideoSetMode(pc, addr, bWrite, d, nExecutedCycles); - case 0x3: return VideoSetMode(pc, addr, bWrite, d, nExecutedCycles); + case 0x0: return GetVideo().VideoSetMode(pc, addr, bWrite, d, nExecutedCycles); + case 0x1: return GetVideo().VideoSetMode(pc, addr, bWrite, d, nExecutedCycles); + case 0x2: return GetVideo().VideoSetMode(pc, addr, bWrite, d, nExecutedCycles); + case 0x3: return GetVideo().VideoSetMode(pc, addr, bWrite, d, nExecutedCycles); case 0x4: return MemSetPaging(pc, addr, bWrite, d, nExecutedCycles); case 0x5: return MemSetPaging(pc, addr, bWrite, d, nExecutedCycles); case 0x6: return MemSetPaging(pc, addr, bWrite, d, nExecutedCycles); @@ -518,7 +517,7 @@ static BYTE __stdcall IORead_C05x(WORD pc, WORD addr, BYTE bWrite, BYTE d, ULONG case 0xF: if (IsApple2PlusOrClone(GetApple2Type())) IO_Annunciator(pc, addr, bWrite, d, nExecutedCycles); else - return (!SW_IOUDIS) ? VideoSetMode(pc, addr, bWrite, d, nExecutedCycles) + return (!SW_IOUDIS) ? GetVideo().VideoSetMode(pc, addr, bWrite, d, nExecutedCycles) : IO_Annunciator(pc, addr, bWrite, d, nExecutedCycles); } @@ -529,10 +528,10 @@ static BYTE __stdcall IOWrite_C05x(WORD pc, WORD addr, BYTE bWrite, BYTE d, ULON { switch (addr & 0xf) { - case 0x0: return VideoSetMode(pc, addr, bWrite, d, nExecutedCycles); - case 0x1: return VideoSetMode(pc, addr, bWrite, d, nExecutedCycles); - case 0x2: return VideoSetMode(pc, addr, bWrite, d, nExecutedCycles); - case 0x3: return VideoSetMode(pc, addr, bWrite, d, nExecutedCycles); + case 0x0: return GetVideo().VideoSetMode(pc, addr, bWrite, d, nExecutedCycles); + case 0x1: return GetVideo().VideoSetMode(pc, addr, bWrite, d, nExecutedCycles); + case 0x2: return GetVideo().VideoSetMode(pc, addr, bWrite, d, nExecutedCycles); + case 0x3: return GetVideo().VideoSetMode(pc, addr, bWrite, d, nExecutedCycles); case 0x4: return MemSetPaging(pc, addr, bWrite, d, nExecutedCycles); case 0x5: return MemSetPaging(pc, addr, bWrite, d, nExecutedCycles); case 0x6: return MemSetPaging(pc, addr, bWrite, d, nExecutedCycles); @@ -547,7 +546,7 @@ static BYTE __stdcall IOWrite_C05x(WORD pc, WORD addr, BYTE bWrite, BYTE d, ULON case 0xF: if (IsApple2PlusOrClone(GetApple2Type())) IO_Annunciator(pc, addr, bWrite, d, nExecutedCycles); else - return (!SW_IOUDIS) ? VideoSetMode(pc, addr, bWrite, d, nExecutedCycles) + return (!SW_IOUDIS) ? GetVideo().VideoSetMode(pc, addr, bWrite, d, nExecutedCycles) : IO_Annunciator(pc, addr, bWrite, d, nExecutedCycles); } @@ -615,7 +614,7 @@ static BYTE __stdcall IORead_C07x(WORD pc, WORD addr, BYTE bWrite, BYTE d, ULONG case 0xD: return IO_Null(pc, addr, bWrite, d, nExecutedCycles); case 0xE: return IS_APPLE2C() ? MemReadFloatingBus(SW_IOUDIS ? true : false, nExecutedCycles) // GH#636 : IO_Null(pc, addr, bWrite, d, nExecutedCycles); - case 0xF: return IsEnhancedIIEorIIC() ? MemReadFloatingBus(VideoGetSWDHIRES(), nExecutedCycles) // GH#636 + case 0xF: return IsEnhancedIIEorIIC() ? MemReadFloatingBus(GetVideo().VideoGetSWDHIRES(), nExecutedCycles) // GH#636 : IO_Null(pc, addr, bWrite, d, nExecutedCycles); } @@ -1354,7 +1353,7 @@ LPBYTE MemGetAuxPtr(const WORD offset) #ifdef RAMWORKS // Video scanner (for 14M video modes) always fetches from 1st 64K aux bank (UTAIIe ref?) - if (((SW_PAGE2 && SW_80STORE) || VideoGetSW80COL()) && + if (((SW_PAGE2 && SW_80STORE) || GetVideo().VideoGetSW80COL()) && ( ( ((offset & 0xFF00)>=0x0400) && ((offset & 0xFF00)<=0x0700) ) || ( SW_HIRES && ((offset & 0xFF00)>=0x2000) && ((offset & 0xFF00)<=0x3F00) ) @@ -2128,7 +2127,7 @@ BYTE __stdcall MemSetPaging(WORD programcounter, WORD address, BYTE write, BYTE // Replicate 80STORE, PAGE2 and HIRES to video sub-system if ((address <= 1) || ((address >= 0x54) && (address <= 0x57))) - return VideoSetMode(programcounter,address,write,value,nExecutedCycles); + return GetVideo().VideoSetMode(programcounter,address,write,value,nExecutedCycles); return write ? 0 : MemReadFloatingBus(nExecutedCycles); } diff --git a/source/MouseInterface.cpp b/source/MouseInterface.cpp index a5085523..de002df8 100644 --- a/source/MouseInterface.cpp +++ b/source/MouseInterface.cpp @@ -52,7 +52,6 @@ Etc. #include "Interface.h" // FrameSetCursorPosByMousePos() #include "Log.h" #include "Memory.h" -#include "Video.h" #include "NTSC.h" // NTSC_GetCyclesUntilVBlank() #include "YamlHelper.h" diff --git a/source/NTSC.cpp b/source/NTSC.cpp index 1fdc0f78..e4c7c55e 100644 --- a/source/NTSC.cpp +++ b/source/NTSC.cpp @@ -25,7 +25,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #include "Core.h" #include "CPU.h" // CpuGetCyclesThisVideoFrame() #include "Memory.h" // MemGetMainPtr(), MemGetAuxPtr(), MemGetAnnunciator() - #include "Video.h" // g_pFramebufferbits + #include "Interface.h" // GetFrameBuffer() #include "RGBMonitor.h" #include "NTSC_CharSet.h" @@ -104,7 +104,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA static bgra_t *g_pVideoAddress = 0; static bgra_t *g_pScanLines[VIDEO_SCANNER_Y_DISPLAY*2]; // To maintain the 280x192 aspect ratio for 560px width, we double every scan line -> 560x384 - static const UINT g_kFrameBufferWidth = GetFrameBufferWidth(); + static const UINT g_kFrameBufferWidth = GetVideo().GetFrameBufferWidth(); static unsigned short (*g_pHorzClockOffset)[VIDEO_SCANNER_MAX_HORZ] = 0; @@ -364,7 +364,7 @@ static void set_csbits() case A2TYPE_PRAVETS8M: csbits = &csbits_pravets8M[0]; g_nVideoCharSet = 0; break; // Apple ][ clone case A2TYPE_PRAVETS8A: csbits = &csbits_pravets8C[0]; break; // Apple //e clone case A2TYPE_TK30002E: csbits = &csbits_enhanced2e[0]; break; // Enhanced Apple //e clone - case A2TYPE_BASE64A: csbits = &csbits_base64a[GetVideoRomRockerSwitch() ? 0 : 1]; g_nVideoCharSet = 0; break; // Apple ][ clone + case A2TYPE_BASE64A: csbits = &csbits_base64a[GetVideo().GetVideoRomRockerSwitch() ? 0 : 1]; g_nVideoCharSet = 0; break; // Apple ][ clone default: _ASSERT(0); csbits = &csbits_enhanced2e[0]; break; } } @@ -715,14 +715,14 @@ inline void updateVideoScannerHorzEOL() //=========================================================================== inline void updateVideoScannerAddress() { - if (g_nVideoMixed && g_nVideoClockVert >= VIDEO_SCANNER_Y_MIXED && GetVideoRefreshRate() == VR_50HZ) // GH#763 + if (g_nVideoMixed && g_nVideoClockVert >= VIDEO_SCANNER_Y_MIXED && GetVideo().GetVideoRefreshRate() == VR_50HZ) // GH#763 g_nColorBurstPixels = 0; // instantaneously kill color-burst! g_pVideoAddress = g_nVideoClockVert < VIDEO_SCANNER_Y_DISPLAY ? g_pScanLines[2*g_nVideoClockVert] : g_pScanLines[0]; // Adjust, as these video styles have 2x 14M pixels of pre-render // NB. For VT_COLOR_MONITOR_NTSC, also check color-burst so that TEXT and MIXED(HGR+TEXT) render the TEXT at the same offset (GH#341) - if (g_eVideoType == VT_MONO_TV || g_eVideoType == VT_COLOR_TV || (g_eVideoType == VT_COLOR_MONITOR_NTSC && GetColorBurst())) + if (GetVideo().GetVideoType() == VT_MONO_TV || GetVideo().GetVideoType() == VT_COLOR_TV || (GetVideo().GetVideoType() == VT_COLOR_MONITOR_NTSC && GetColorBurst())) g_pVideoAddress -= 2; // GH#555: For the 14M video modes (DHGR,DGR,80COL), start rendering 1x 14M pixel early to account for these video modes being shifted right by 1 pixel @@ -735,7 +735,7 @@ inline void updateVideoScannerAddress() (g_pFuncUpdateGraphicsScreen == updateScreenText80) || (g_pFuncUpdateGraphicsScreen == updateScreenText80RGB) || (g_nVideoMixed && g_nVideoClockVert >= VIDEO_SCANNER_Y_MIXED && (g_pFuncUpdateTextScreen == updateScreenText80 || g_pFuncUpdateGraphicsScreen == updateScreenText80RGB))) - && (g_eVideoType != VT_COLOR_IDEALIZED) && (g_eVideoType != VT_COLOR_VIDEOCARD_RGB)) // Fix for "Ansi Story" (Turn the disk over) - Top row of TEXT80 is shifted by 1 pixel + && (GetVideo().GetVideoType() != VT_COLOR_IDEALIZED) && (GetVideo().GetVideoType() != VT_COLOR_VIDEOCARD_RGB)) // Fix for "Ansi Story" (Turn the disk over) - Top row of TEXT80 is shifted by 1 pixel { g_pVideoAddress -= 1; } @@ -1652,8 +1652,8 @@ void updateScreenText80 (long cycles6502) aux ^= g_nTextFlashMask; uint16_t bits = (main << 7) | (aux & 0x7f); - if ((g_eVideoType != VT_COLOR_IDEALIZED) // No extra 14M bit needed for VT_COLOR_IDEALIZED - && (g_eVideoType != VT_COLOR_VIDEOCARD_RGB)) + if ((GetVideo().GetVideoType() != VT_COLOR_IDEALIZED) // No extra 14M bit needed for VT_COLOR_IDEALIZED + && (GetVideo().GetVideoType() != VT_COLOR_VIDEOCARD_RGB)) bits = (bits << 1) | g_nLastColumnPixelNTSC; // GH#555: Align TEXT80 chars with DHGR updatePixels( bits ); @@ -1766,7 +1766,7 @@ uint16_t NTSC_VideoGetScannerAddress ( const ULONG uExecutedCycles ) } uint16_t addr; - bool bHires = (g_uVideoMode & VF_HIRES) && !(g_uVideoMode & VF_TEXT); // SW_HIRES && !SW_TEXT + bool bHires = (GetVideo().GetVideoMode() & VF_HIRES) && !(GetVideo().GetVideoMode() & VF_TEXT); // SW_HIRES && !SW_TEXT if( bHires ) addr = getVideoScannerAddressHGR(); else @@ -1787,7 +1787,7 @@ uint16_t NTSC_VideoGetScannerAddressForDebugger(void) //=========================================================================== void NTSC_SetVideoTextMode( int cols ) { - if (g_eVideoType == VT_COLOR_VIDEOCARD_RGB) + if (GetVideo().GetVideoType() == VT_COLOR_VIDEOCARD_RGB) { if (cols == 40) g_pFuncUpdateTextScreen = updateScreenText40RGB; @@ -1814,7 +1814,7 @@ void NTSC_SetVideoMode( uint32_t uVideoModeFlags, bool bDelay/*=false*/ ) g_nVideoMixed = uVideoModeFlags & VF_MIXED; - g_nVideoCharSet = VideoGetSWAltCharSet() ? 1 : 0; + g_nVideoCharSet = GetVideo().VideoGetSWAltCharSet() ? 1 : 0; RGB_DisableTextFB(); @@ -1831,14 +1831,14 @@ void NTSC_SetVideoMode( uint32_t uVideoModeFlags, bool bDelay/*=false*/ ) } } - if (GetVideoRefreshRate() == VR_50HZ && g_pVideoAddress) // GH#763 / NB. g_pVideoAddress==NULL when called via VideoResetState() + if (GetVideo().GetVideoRefreshRate() == VR_50HZ && g_pVideoAddress) // GH#763 / NB. g_pVideoAddress==NULL when called via VideoResetState() { if (uVideoModeFlags & VF_TEXT) { g_nColorBurstPixels = 0; // (For mid-line video mode change) Instantaneously kill color-burst! (not correct as TV's can take many lines) // Switching mid-line from graphics to TEXT - if (g_eVideoType == VT_COLOR_MONITOR_NTSC && + if (GetVideo().GetVideoType() == VT_COLOR_MONITOR_NTSC && g_pFuncUpdateGraphicsScreen != updateScreenText40 && g_pFuncUpdateGraphicsScreen != updateScreenText40RGB && g_pFuncUpdateGraphicsScreen != updateScreenText80 && g_pFuncUpdateGraphicsScreen != updateScreenText80RGB) { @@ -1852,7 +1852,7 @@ void NTSC_SetVideoMode( uint32_t uVideoModeFlags, bool bDelay/*=false*/ ) g_nColorBurstPixels = 1024; // (For mid-line video mode change) // Switching mid-line from TEXT to graphics - if (g_eVideoType == VT_COLOR_MONITOR_NTSC && + if (GetVideo().GetVideoType() == VT_COLOR_MONITOR_NTSC && (g_pFuncUpdateGraphicsScreen == updateScreenText40 || g_pFuncUpdateGraphicsScreen == updateScreenText40RGB || g_pFuncUpdateGraphicsScreen == updateScreenText80 || g_pFuncUpdateGraphicsScreen == updateScreenText80RGB)) { @@ -1862,7 +1862,7 @@ void NTSC_SetVideoMode( uint32_t uVideoModeFlags, bool bDelay/*=false*/ ) } // Video7_SL7 extra RGB modes handling - if (g_eVideoType == VT_COLOR_VIDEOCARD_RGB + if (GetVideo().GetVideoType() == VT_COLOR_VIDEOCARD_RGB && RGB_GetVideocard() == RGB_Videocard_e::Video7_SL7 // Exclude following modes (fallback through regular NTSC rendering with RGB text) // VF_DHIRES = 1 -> regular Apple IIe modes @@ -1917,12 +1917,12 @@ void NTSC_SetVideoMode( uint32_t uVideoModeFlags, bool bDelay/*=false*/ ) { if (uVideoModeFlags & VF_80COL) { - if (g_eVideoType == VT_COLOR_VIDEOCARD_RGB) + if (GetVideo().GetVideoType() == VT_COLOR_VIDEOCARD_RGB) g_pFuncUpdateGraphicsScreen = updateScreenText80RGB; else g_pFuncUpdateGraphicsScreen = updateScreenText80; } - else if (g_eVideoType == VT_COLOR_VIDEOCARD_RGB) + else if (GetVideo().GetVideoType() == VT_COLOR_VIDEOCARD_RGB) g_pFuncUpdateGraphicsScreen = updateScreenText40RGB; else g_pFuncUpdateGraphicsScreen = updateScreenText40; @@ -1933,18 +1933,18 @@ void NTSC_SetVideoMode( uint32_t uVideoModeFlags, bool bDelay/*=false*/ ) { if (uVideoModeFlags & VF_80COL) { - if (g_eVideoType == VT_COLOR_IDEALIZED) + if (GetVideo().GetVideoType() == VT_COLOR_IDEALIZED) g_pFuncUpdateGraphicsScreen = updateScreenDoubleHires80Simplified; - else if (g_eVideoType == VT_COLOR_VIDEOCARD_RGB) + else if (GetVideo().GetVideoType() == VT_COLOR_VIDEOCARD_RGB) g_pFuncUpdateGraphicsScreen = updateScreenDoubleHires80RGB; else g_pFuncUpdateGraphicsScreen = updateScreenDoubleHires80; } else { - if (g_eVideoType == VT_COLOR_IDEALIZED) + if (GetVideo().GetVideoType() == VT_COLOR_IDEALIZED) g_pFuncUpdateGraphicsScreen = updateScreenHires40Simplified; // handles both Single/Double Hires40 (EG. FT's DIGIDREAM demo) -// else if (g_eVideoType == VT_COLOR_VIDEOCARD_RGB) +// else if (GetVideo().GetVideoType() == VT_COLOR_VIDEOCARD_RGB) // // TODO else g_pFuncUpdateGraphicsScreen = updateScreenDoubleHires40; @@ -1952,9 +1952,9 @@ void NTSC_SetVideoMode( uint32_t uVideoModeFlags, bool bDelay/*=false*/ ) } else { - if (g_eVideoType == VT_COLOR_IDEALIZED) + if (GetVideo().GetVideoType() == VT_COLOR_IDEALIZED) g_pFuncUpdateGraphicsScreen = updateScreenHires40Simplified; - else if (g_eVideoType == VT_COLOR_VIDEOCARD_RGB) + else if (GetVideo().GetVideoType() == VT_COLOR_VIDEOCARD_RGB) g_pFuncUpdateGraphicsScreen = updateScreenSingleHires40RGB; else g_pFuncUpdateGraphicsScreen = updateScreenSingleHires40; @@ -1966,7 +1966,7 @@ void NTSC_SetVideoMode( uint32_t uVideoModeFlags, bool bDelay/*=false*/ ) { if (uVideoModeFlags & VF_80COL) { - if ((g_eVideoType == VT_COLOR_IDEALIZED) || (g_eVideoType == VT_COLOR_VIDEOCARD_RGB)) + if ((GetVideo().GetVideoType() == VT_COLOR_IDEALIZED) || (GetVideo().GetVideoType() == VT_COLOR_VIDEOCARD_RGB)) g_pFuncUpdateGraphicsScreen = updateScreenDoubleLores80Simplified; else g_pFuncUpdateGraphicsScreen = updateScreenDoubleLores80; @@ -1978,7 +1978,7 @@ void NTSC_SetVideoMode( uint32_t uVideoModeFlags, bool bDelay/*=false*/ ) } else { - if ((g_eVideoType == VT_COLOR_IDEALIZED) || (g_eVideoType == VT_COLOR_VIDEOCARD_RGB)) + if ((GetVideo().GetVideoType() == VT_COLOR_IDEALIZED) || (GetVideo().GetVideoType() == VT_COLOR_VIDEOCARD_RGB)) g_pFuncUpdateGraphicsScreen = updateScreenSingleLores40Simplified; else g_pFuncUpdateGraphicsScreen = updateScreenSingleLores40; @@ -1990,11 +1990,11 @@ void NTSC_SetVideoMode( uint32_t uVideoModeFlags, bool bDelay/*=false*/ ) void NTSC_SetVideoStyle(void) { - const bool half = IsVideoStyle(VS_HALF_SCANLINES); - const VideoRefreshRate_e refresh = GetVideoRefreshRate(); + const bool half = GetVideo().IsVideoStyle(VS_HALF_SCANLINES); + const VideoRefreshRate_e refresh = GetVideo().GetVideoRefreshRate(); uint8_t r, g, b; - switch ( g_eVideoType ) + switch ( GetVideo().GetVideoType() ) { case VT_COLOR_TV: r = 0xFF; @@ -2068,9 +2068,9 @@ void NTSC_SetVideoStyle(void) //#define GetRValue(rgb) (LOBYTE(rgb)) //#define GetGValue(rgb) (LOBYTE(((WORD)(rgb)) >> 8)) //#define GetBValue(rgb) (LOBYTE((rgb)>>16)) - r = (g_nMonochromeRGB >> 0) & 0xFF; - g = (g_nMonochromeRGB >> 8) & 0xFF; - b = (g_nMonochromeRGB >> 16) & 0xFF; + r = (GetVideo().GetMonochromeRGB() >> 0) & 0xFF; + g = (GetVideo().GetMonochromeRGB() >> 8) & 0xFF; + b = (GetVideo().GetMonochromeRGB() >> 16) & 0xFF; _mono: updateMonochromeTables( r, g, b ); // Custom Monochrome color if (half) @@ -2087,7 +2087,7 @@ static void GenerateBaseColors(baseColors_t pBaseNtscColors); void NTSC_Destroy(void) { - // After a VM restart, this will point to an old g_pFramebufferbits + // After a VM restart, this will point to an old FrameBuffer // - if it's now unmapped then this can cause a crash in NTSC_SetVideoMode()! g_pVideoAddress = 0; } @@ -2102,8 +2102,10 @@ void NTSC_VideoInit( uint8_t* pFramebuffer ) // wsVideoInit for (int y = 0; y < (VIDEO_SCANNER_Y_DISPLAY*2); y++) { - uint32_t offset = sizeof(bgra_t) * GetFrameBufferWidth() * ((GetFrameBufferHeight() - 1) - y - GetFrameBufferBorderHeight()) + (sizeof(bgra_t) * GetFrameBufferBorderWidth()); - g_pScanLines[y] = (bgra_t*) (g_pFramebufferbits + offset); + uint32_t offset = sizeof(bgra_t) * GetVideo().GetFrameBufferWidth() + * ((GetVideo().GetFrameBufferHeight() - 1) - y - GetVideo().GetFrameBufferBorderHeight()) + + (sizeof(bgra_t) * GetVideo().GetFrameBufferBorderWidth()); + g_pScanLines[y] = (bgra_t*) (GetVideo().GetFrameBuffer() + offset); } g_pVideoAddress = g_pScanLines[0]; @@ -2111,7 +2113,7 @@ void NTSC_VideoInit( uint8_t* pFramebuffer ) // wsVideoInit g_pFuncUpdateTextScreen = updateScreenText40; g_pFuncUpdateGraphicsScreen = updateScreenText40; - VideoReinitialize(); // Setup g_pFunc_ntsc*Pixel() + GetVideo().VideoReinitialize(); // Setup g_pFunc_ntsc*Pixel() bgra_t baseColors[kNumBaseColors]; GenerateBaseColors(&baseColors); @@ -2317,16 +2319,16 @@ static bool CheckVideoTables2( eApple2Type type, uint32_t mode ) SetApple2Type(type); NTSC_VideoInitAppleType(); - g_uVideoMode = mode; + GetVideo().SetVideoMode(mode); g_dwCyclesThisFrame = 0; g_nVideoClockHorz = g_nVideoClockVert = 0; for (DWORD cycles=0; cycles VBl at (0,192) diff --git a/source/NTSC.h b/source/NTSC.h index 05938b1a..fc629553 100644 --- a/source/NTSC.h +++ b/source/NTSC.h @@ -1,7 +1,5 @@ #pragma once -#include "Video.h" - // Globals (Public) extern uint16_t g_nVideoClockVert; extern uint16_t g_nVideoClockHorz; diff --git a/source/NTSC_CharSet.cpp b/source/NTSC_CharSet.cpp index a19da5fd..bd264740 100644 --- a/source/NTSC_CharSet.cpp +++ b/source/NTSC_CharSet.cpp @@ -24,7 +24,6 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #include "Interface.h" #include "Core.h" #include "../resource/resource.h" -#include "Video.h" unsigned char csbits_enhanced2e[2][256][8]; // Enhanced //e (2732 4K video ROM) @@ -162,11 +161,11 @@ static void userVideoRom4K(csbits_t csbits, const BYTE* pVideoRom) static void userVideoRomForIIe(void) { const BYTE* pVideoRom; - UINT size = GetVideoRom(pVideoRom); // 2K or 4K or 8K - if (size < kVideoRomSize4K) + UINT size = GetVideo().GetVideoRom(pVideoRom); // 2K or 4K or 8K + if (size < Video::kVideoRomSize4K) return; - if (size == kVideoRomSize4K) + if (size == Video::kVideoRomSize4K) { userVideoRom4K(&csbits_enhanced2e[0], pVideoRom); } @@ -241,8 +240,8 @@ static void userVideoRom2K(csbits_t csbits, const BYTE* pVideoRom, const eApple2 static void userVideoRomForIIPlus(void) { const BYTE* pVideoRom; - UINT size = GetVideoRom(pVideoRom); // 2K or 4K or 8K - if (size != kVideoRomSize2K) + UINT size = GetVideo().GetVideoRom(pVideoRom); // 2K or 4K or 8K + if (size != Video::kVideoRomSize2K) return; userVideoRom2K(&csbits_a2[0], pVideoRom); @@ -257,7 +256,7 @@ static void VideoRomForIIJPlus(void) return; DWORD dwResSize = SizeofResource(NULL, hResInfo); - if(dwResSize != kVideoRomSize2K) + if(dwResSize != Video::kVideoRomSize2K) return; HGLOBAL hResData = LoadResource(NULL, hResInfo); @@ -279,7 +278,7 @@ static void VideoRomForBase64A(void) return; DWORD dwResSize = SizeofResource(NULL, hResInfo); - if (dwResSize != kVideoRomSize4K) + if (dwResSize != Video::kVideoRomSize4K) return; HGLOBAL hResData = LoadResource(NULL, hResInfo); @@ -291,7 +290,7 @@ static void VideoRomForBase64A(void) return; userVideoRom2K(&csbits_base64a[0], pVideoRom, A2TYPE_BASE64A, 0); - userVideoRom2K(&csbits_base64a[1], pVideoRom + kVideoRomSize2K, A2TYPE_BASE64A, 0); + userVideoRom2K(&csbits_base64a[1], pVideoRom + Video::kVideoRomSize2K, A2TYPE_BASE64A, 0); } @@ -325,8 +324,8 @@ csbits_t Get2e_csbits(void) { const csbits_t videoRom4K = (GetApple2Type() == A2TYPE_APPLE2E) ? csbits_2e : csbits_enhanced2e; - if (IsVideoRom4K()) // 4K means US-only, so no secondary PAL video ROM + if (GetVideo().IsVideoRom4K()) // 4K means US-only, so no secondary PAL video ROM return videoRom4K; - return GetVideoRomRockerSwitch() == false ? videoRom4K : csbits_2e_pal; // NB. Same PAL video ROM for Original & Enhanced //e + return GetVideo().GetVideoRomRockerSwitch() == false ? videoRom4K : csbits_2e_pal; // NB. Same PAL video ROM for Original & Enhanced //e } diff --git a/source/RGBMonitor.cpp b/source/RGBMonitor.cpp index 34ceeaa2..a0037c66 100644 --- a/source/RGBMonitor.cpp +++ b/source/RGBMonitor.cpp @@ -4,7 +4,7 @@ #include "RGBMonitor.h" #include "Memory.h" // MemGetMainPtr() MemGetAuxPtr() -#include "Video.h" +#include "Interface.h" #include "Card.h" #include "YamlHelper.h" @@ -514,7 +514,7 @@ static void CopyMixedSource(int x, int y, int sx, int sy, bgra_t *pVideoAddress) const int matx = x*14; const int maty = HGR_MATRIX_YOFFSET + y; - const bool isSWMIXED = VideoGetSWMIXED(); + const bool isSWMIXED = GetVideo().VideoGetSWMIXED(); // transfer 14 pixels (i.e. the visible part of an apple hgr-byte) from row to pixelmatrix for (int nBytes=13; nBytes>=0; nBytes--) @@ -522,8 +522,8 @@ static void CopyMixedSource(int x, int y, int sx, int sy, bgra_t *pVideoAddress) hgrpixelmatrix[matx+nBytes][maty] = *(pSrc+nBytes); } - const bool bIsHalfScanLines = IsVideoStyle(VS_HALF_SCANLINES); - const UINT frameBufferWidth = GetFrameBufferWidth(); + const bool bIsHalfScanLines = GetVideo().IsVideoStyle(VS_HALF_SCANLINES); + const UINT frameBufferWidth = GetVideo().GetFrameBufferWidth(); for (int nBytes=13; nBytes>=0; nBytes--) { @@ -559,8 +559,8 @@ static void CopySource(int w, int h, int sx, int sy, bgra_t *pVideoAddress, cons UINT32* pDst = (UINT32*) pVideoAddress; const BYTE* const pSrc = g_aSourceStartofLine[ sy ] + sx; - const bool bIsHalfScanLines = IsVideoStyle(VS_HALF_SCANLINES); - const UINT frameBufferWidth = GetFrameBufferWidth(); + const bool bIsHalfScanLines = GetVideo().IsVideoStyle(VS_HALF_SCANLINES); + const UINT frameBufferWidth = GetVideo().GetFrameBufferWidth(); while (h--) { @@ -594,14 +594,14 @@ void UpdateHiResCell (int x, int y, uint16_t addr, bgra_t *pVideoAddress) BYTE byteval2 = *(pMain); BYTE byteval3 = (x < 39) ? *(pMain+1) : 0; - if (g_uVideoMode & VF_DHIRES) // ie. VF_DHIRES=1, VF_HIRES=1, VF_80COL=0 - NTSC.cpp refers to this as "DoubleHires40" + if (GetVideo().GetVideoMode() & VF_DHIRES) // ie. VF_DHIRES=1, VF_HIRES=1, VF_80COL=0 - NTSC.cpp refers to this as "DoubleHires40" { byteval1 &= 0x7f; byteval2 &= 0x7f; byteval3 &= 0x7f; } - if (IsVideoStyle(VS_COLOR_VERTICAL_BLEND)) + if (GetVideo().IsVideoStyle(VS_COLOR_VERTICAL_BLEND)) { CopyMixedSource(x, y, SRCOFFS_HIRES+HIRES_COLUMN_OFFSET+((x & 1)*HIRES_COLUMN_SUBUNIT_SIZE), (int)byteval2, pVideoAddress); } @@ -727,11 +727,11 @@ void UpdateHiResRGBCell(int x, int y, uint16_t addr, bgra_t* pVideoAddress) dwordval = dwordval >> 1; } - const bool bIsHalfScanLines = IsVideoStyle(VS_HALF_SCANLINES); + const bool bIsHalfScanLines = GetVideo().IsVideoStyle(VS_HALF_SCANLINES); // Second line UINT32* pSrc = (UINT32*)pVideoAddress; - pDst = pSrc - GetFrameBufferWidth(); + pDst = pSrc - GetVideo().GetFrameBufferWidth(); if (bIsHalfScanLines) { // Scanlines @@ -942,11 +942,11 @@ void UpdateDHiResCellRGB(int x, int y, uint16_t addr, bgra_t* pVideoAddress, boo } } - const bool bIsHalfScanLines = IsVideoStyle(VS_HALF_SCANLINES); + const bool bIsHalfScanLines = GetVideo().IsVideoStyle(VS_HALF_SCANLINES); // Second line UINT32* pSrc = (UINT32*)pVideoAddress ; - pDst = pSrc - GetFrameBufferWidth(); + pDst = pSrc - GetVideo().GetFrameBufferWidth(); if (bIsHalfScanLines) { // Scanlines @@ -1121,8 +1121,8 @@ void UpdateDuochromeCell(int h, int w, bgra_t* pVideoAddress, uint8_t bits, uint { UINT32* pDst = (UINT32*)pVideoAddress; - const bool bIsHalfScanLines = IsVideoStyle(VS_HALF_SCANLINES); - const UINT frameBufferWidth = GetFrameBufferWidth(); + const bool bIsHalfScanLines = GetVideo().IsVideoStyle(VS_HALF_SCANLINES); + const UINT frameBufferWidth = GetVideo().GetFrameBufferWidth(); RGBQUAD colors[2]; // use LoRes palette background += 12; @@ -1240,7 +1240,7 @@ void RGB_SetVideoMode(WORD address) if (address == 0x5F && g_rgbPrevAN3Addr == 0x5E) { g_rgbFlags = (g_rgbFlags << 1) & 3; - g_rgbFlags |= ((g_uVideoMode & VF_80COL) ? 0 : 1); // clock in !80COL + g_rgbFlags |= ((GetVideo().GetVideoMode() & VF_80COL) ? 0 : 1); // clock in !80COL g_rgbMode = g_rgbFlags; // latch F2,F1 } diff --git a/source/SaveState.cpp b/source/SaveState.cpp index 4b5179a7..9dcefd0a 100644 --- a/source/SaveState.cpp +++ b/source/SaveState.cpp @@ -47,7 +47,6 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #include "SerialComms.h" #include "Speaker.h" #include "Speech.h" -#include "Video.h" #include "z80emu.h" #include "Configuration/Config.h" @@ -284,11 +283,11 @@ static void ParseUnitApple2(YamlLoadHelper& yamlLoadHelper, UINT version) JoyLoadSnapshot(yamlLoadHelper); KeybLoadSnapshot(yamlLoadHelper, version); SpkrLoadSnapshot(yamlLoadHelper); - VideoLoadSnapshot(yamlLoadHelper, version); + GetVideo().VideoLoadSnapshot(yamlLoadHelper, version); MemLoadSnapshot(yamlLoadHelper, version); // g_Apple2Type may've changed: so redraw frame (title, buttons, leds, etc) - VideoReinitialize(); // g_CharsetType changed + GetVideo().VideoReinitialize(); // g_CharsetType changed GetFrame().FrameUpdateApple2Type(); // Calls VideoRedrawScreen() before the aux mem has been loaded (so if DHGR is enabled, then aux mem will be zeros at this stage) } @@ -491,8 +490,8 @@ static void Snapshot_LoadState_v2(void) HD_SetEnabled(false); KeybReset(); - VideoResetState(); - SetVideoRefreshRate(VR_60HZ); // Default to 60Hz as older save-states won't contain refresh rate + GetVideo().VideoResetState(); + GetVideo().SetVideoRefreshRate(VR_60HZ); // Default to 60Hz as older save-states won't contain refresh rate MB_InitializeForLoadingSnapshot(); // GH#609 #ifdef USE_SPEECH_API g_Speech.Reset(); @@ -584,7 +583,7 @@ void Snapshot_SaveState(void) JoySaveSnapshot(yamlSaveHelper); KeybSaveSnapshot(yamlSaveHelper); SpkrSaveSnapshot(yamlSaveHelper); - VideoSaveSnapshot(yamlSaveHelper); + GetVideo().VideoSaveSnapshot(yamlSaveHelper); MemSaveSnapshot(yamlSaveHelper); } diff --git a/source/Utilities.cpp b/source/Utilities.cpp index e9d56174..7bc3f1fa 100644 --- a/source/Utilities.cpp +++ b/source/Utilities.cpp @@ -31,7 +31,6 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #include "Core.h" #include "CardManager.h" #include "CPU.h" -#include "Video.h" #include "Joystick.h" #include "Log.h" #include "Mockingboard.h" @@ -196,7 +195,7 @@ void LoadConfiguration(void) } REGLOAD_DEFAULT(TEXT(REGVALUE_EMULATION_SPEED), &g_dwSpeed, SPEED_NORMAL); - Config_Load_Video(); + GetVideo().Config_Load_Video(); SetCurrentCLK6502(); // Pre: g_dwSpeed && Config_Load_Video()->SetVideoRefreshRate() DWORD dwEnhanceDisk; @@ -493,10 +492,10 @@ void GetAppleWindowTitle() g_pAppTitle += " - "; - if (IsVideoStyle(VS_HALF_SCANLINES)) + if (GetVideo().IsVideoStyle(VS_HALF_SCANLINES)) g_pAppTitle += " 50% "; - g_pAppTitle += VideoGetAppWindowTitle(); + g_pAppTitle += GetVideo().VideoGetAppWindowTitle(); if (GetCardMgr().GetDisk2CardMgr().IsAnyFirmware13Sector()) g_pAppTitle += " (S6-13) "; @@ -534,7 +533,7 @@ void ResetMachineState() PravetsReset(); if (GetCardMgr().QuerySlot(SLOT6) == CT_Disk2) dynamic_cast(GetCardMgr().GetRef(SLOT6)).Boot(); - VideoResetState(); + GetVideo().VideoResetState(); KeybReset(); if (GetCardMgr().IsSSCInstalled()) GetCardMgr().GetSSC()->CommReset(); @@ -569,7 +568,7 @@ void CtrlReset() MemResetPaging(); // For A][ & A][+, reset doesn't reset the video mode (UTAII:4-4) - VideoResetState(); // Switch Alternate char set off + GetVideo().VideoResetState(); // Switch Alternate char set off } if (IsAppleIIeOrAbove(GetApple2Type()) || IsCopamBase64A(GetApple2Type())) diff --git a/source/Video.cpp b/source/Video.cpp index d30d620a..10a33553 100644 --- a/source/Video.cpp +++ b/source/Video.cpp @@ -37,134 +37,97 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #include "Registry.h" #include "NTSC.h" #include "RGBMonitor.h" - #include "YamlHelper.h" - #define SW_80COL (g_uVideoMode & VF_80COL) - #define SW_DHIRES (g_uVideoMode & VF_DHIRES) - #define SW_HIRES (g_uVideoMode & VF_HIRES) - #define SW_80STORE (g_uVideoMode & VF_80STORE) - #define SW_MIXED (g_uVideoMode & VF_MIXED) - #define SW_PAGE2 (g_uVideoMode & VF_PAGE2) - #define SW_TEXT (g_uVideoMode & VF_TEXT) - -// Globals (Public) - - uint8_t *g_pFramebufferbits = NULL; // last drawn frame (initialized in WinVideoInitialize) - int g_nAltCharSetOffset = 0; // alternate character set - -// Globals (Private) - -// video scanner constants -int const kHBurstClock = 53; // clock when Color Burst starts -int const kHBurstClocks = 4; // clocks per Color Burst duration -int const kHClock0State = 0x18; // H[543210] = 011000 -int const kHClocks = 65; // clocks per horizontal scan (including HBL) -int const kHPEClock = 40; // clock when HPE (horizontal preset enable) goes low -int const kHPresetClock = 41; // clock when H state presets -int const kHSyncClock = 49; // clock when HSync starts -int const kHSyncClocks = 4; // clocks per HSync duration -int const kNTSCScanLines = 262; // total scan lines including VBL (NTSC) -int const kNTSCVSyncLine = 224; // line when VSync starts (NTSC) -int const kPALScanLines = 312; // total scan lines including VBL (PAL) -int const kPALVSyncLine = 264; // line when VSync starts (PAL) -int const kVLine0State = 0x100; // V[543210CBA] = 100000000 -int const kVPresetLine = 256; // line when V state presets -int const kVSyncLines = 4; // lines per VSync duration -int const kVDisplayableScanLines = 192; // max displayable scanlines - -COLORREF g_nMonochromeRGB = RGB(0xC0,0xC0,0xC0); - -uint32_t g_uVideoMode = VF_TEXT; // Current Video Mode (this is the last set one as it may change mid-scan line!) - -DWORD g_eVideoType = VT_DEFAULT; -static VideoStyle_e g_eVideoStyle = VS_HALF_SCANLINES; - -static bool g_bVideoScannerNTSC = true; // NTSC video scanning (or PAL) +#define SW_80COL (g_uVideoMode & VF_80COL) +#define SW_DHIRES (g_uVideoMode & VF_DHIRES) +#define SW_HIRES (g_uVideoMode & VF_HIRES) +#define SW_80STORE (g_uVideoMode & VF_80STORE) +#define SW_MIXED (g_uVideoMode & VF_MIXED) +#define SW_PAGE2 (g_uVideoMode & VF_PAGE2) +#define SW_TEXT (g_uVideoMode & VF_TEXT) //------------------------------------- - // NOTE: KEEP IN SYNC: VideoType_e g_aVideoChoices g_apVideoModeDesc - TCHAR g_aVideoChoices[] = - TEXT("Monochrome (Custom)\0") - TEXT("Color (Composite Idealized)\0") // newly added - TEXT("Color (RGB Card/Monitor)\0") // was "Color (RGB Monitor)" - TEXT("Color (Composite Monitor)\0") // was "Color (NTSC Monitor)" - TEXT("Color TV\0") - TEXT("B&W TV\0") - TEXT("Monochrome (Amber)\0") - TEXT("Monochrome (Green)\0") - TEXT("Monochrome (White)\0") - ; +// NOTE: KEEP IN SYNC: VideoType_e g_aVideoChoices g_apVideoModeDesc +const char Video::g_aVideoChoices[] = + "Monochrome (Custom)\0" + "Color (Composite Idealized)\0" + "Color (RGB Card/Monitor)\0" + "Color (Composite Monitor)\0" + "Color TV\0" + "B&W TV\0" + "Monochrome (Amber)\0" + "Monochrome (Green)\0" + "Monochrome (White)\0" + ; - // NOTE: KEEP IN SYNC: VideoType_e g_aVideoChoices g_apVideoModeDesc - // The window title will be set to this. - static const char *g_apVideoModeDesc[ NUM_VIDEO_MODES ] = - { - "Monochrome (Custom)" - , "Color (Composite Idealized)" - , "Color (RGB Card/Monitor)" - , "Color (Composite Monitor)" - , "Color TV" - , "B&W TV" - , "Monochrome (Amber)" - , "Monochrome (Green)" - , "Monochrome (White)" - }; +// NOTE: KEEP IN SYNC: VideoType_e g_aVideoChoices g_apVideoModeDesc +// The window title will be set to this. -// Prototypes (Private) _____________________________________________ +const char Video::m_szModeDesc0[] = "Monochrome (Custom)"; +const char Video::m_szModeDesc1[] = "Color (Composite Idealized)"; +const char Video::m_szModeDesc2[] = "Color (RGB Card/Monitor)"; +const char Video::m_szModeDesc3[] = "Color (Composite Monitor)"; +const char Video::m_szModeDesc4[] = "Color TV"; +const char Video::m_szModeDesc5[] = "B&W TV"; +const char Video::m_szModeDesc6[] = "Monochrome (Amber)"; +const char Video::m_szModeDesc7[] = "Monochrome (Green)"; +const char Video::m_szModeDesc8[] = "Monochrome (White)"; - bool g_bDisplayPrintScreenFileName = false; - bool g_bShowPrintScreenWarningDialog = true; - static void Util_MakeScreenShotFileName( TCHAR *pFinalFileName_, DWORD chars ); - static bool Util_TestScreenShotFileName( const TCHAR *pFileName ); - static void Video_MakeScreenShot( FILE *pFile, const VideoScreenShot_e ScreenShotType ); - static void videoCreateDIBSection(); +const char* const Video::g_apVideoModeDesc[NUM_VIDEO_MODES] = +{ + Video::m_szModeDesc0, + Video::m_szModeDesc1, + Video::m_szModeDesc2, + Video::m_szModeDesc3, + Video::m_szModeDesc4, + Video::m_szModeDesc5, + Video::m_szModeDesc6, + Video::m_szModeDesc7, + Video::m_szModeDesc8 +}; //=========================================================================== -// -// ----- ALL GLOBALLY ACCESSIBLE FUNCTIONS ARE BELOW THIS LINE ----- -// - -UINT GetFrameBufferBorderlessWidth(void) +UINT Video::GetFrameBufferBorderlessWidth(void) { static const UINT uFrameBufferBorderlessW = 560; // 560 = Double Hi-Res return uFrameBufferBorderlessW; } -UINT GetFrameBufferBorderlessHeight(void) +UINT Video::GetFrameBufferBorderlessHeight(void) { static const UINT uFrameBufferBorderlessH = 384; // 384 = Double Scan Line return uFrameBufferBorderlessH; } // NB. These border areas are not visible (... and these border areas are unrelated to the 3D border below) -UINT GetFrameBufferBorderWidth(void) +UINT Video::GetFrameBufferBorderWidth(void) { static const UINT uBorderW = 20; return uBorderW; } -UINT GetFrameBufferBorderHeight(void) +UINT Video::GetFrameBufferBorderHeight(void) { static const UINT uBorderH = 18; return uBorderH; } -UINT GetFrameBufferWidth(void) +UINT Video::GetFrameBufferWidth(void) { return GetFrameBufferBorderlessWidth() + 2 * GetFrameBufferBorderWidth(); } -UINT GetFrameBufferHeight(void) +UINT Video::GetFrameBufferHeight(void) { return GetFrameBufferBorderlessHeight() + 2 * GetFrameBufferBorderHeight(); } //=========================================================================== -void VideoReinitialize (bool bInitVideoScannerAddress /*= true*/) +void Video::VideoReinitialize(bool bInitVideoScannerAddress /*= true*/) { NTSC_VideoReinitialize( g_dwCyclesThisFrame, bInitVideoScannerAddress ); NTSC_VideoInitAppleType(); @@ -175,7 +138,8 @@ void VideoReinitialize (bool bInitVideoScannerAddress /*= true*/) } //=========================================================================== -void VideoResetState () + +void Video::VideoResetState(void) { g_nAltCharSetOffset = 0; g_uVideoMode = VF_TEXT; @@ -188,7 +152,7 @@ void VideoResetState () //=========================================================================== -BYTE VideoSetMode(WORD, WORD address, BYTE write, BYTE, ULONG uExecutedCycles) +BYTE Video::VideoSetMode(WORD, WORD address, BYTE write, BYTE, ULONG uExecutedCycles) { address &= 0xFF; @@ -229,42 +193,42 @@ BYTE VideoSetMode(WORD, WORD address, BYTE write, BYTE, ULONG uExecutedCycles) //=========================================================================== -bool VideoGetSW80COL(void) +bool Video::VideoGetSW80COL(void) { return SW_80COL ? true : false; } -bool VideoGetSWDHIRES(void) +bool Video::VideoGetSWDHIRES(void) { return SW_DHIRES ? true : false; } -bool VideoGetSWHIRES(void) +bool Video::VideoGetSWHIRES(void) { return SW_HIRES ? true : false; } -bool VideoGetSW80STORE(void) +bool Video::VideoGetSW80STORE(void) { return SW_80STORE ? true : false; } -bool VideoGetSWMIXED(void) +bool Video::VideoGetSWMIXED(void) { return SW_MIXED ? true : false; } -bool VideoGetSWPAGE2(void) +bool Video::VideoGetSWPAGE2(void) { return SW_PAGE2 ? true : false; } -bool VideoGetSWTEXT(void) +bool Video::VideoGetSWTEXT(void) { return SW_TEXT ? true : false; } -bool VideoGetSWAltCharSet(void) +bool Video::VideoGetSWAltCharSet(void) { return g_nAltCharSetOffset != 0; } @@ -276,13 +240,13 @@ bool VideoGetSWAltCharSet(void) #define SS_YAML_KEY_CYCLES_THIS_FRAME "Cycles This Frame" #define SS_YAML_KEY_VIDEO_REFRESH_RATE "Video Refresh Rate" -static std::string VideoGetSnapshotStructName(void) +std::string Video::VideoGetSnapshotStructName(void) { static const std::string name("Video"); return name; } -void VideoSaveSnapshot(YamlSaveHelper& yamlSaveHelper) +void Video::VideoSaveSnapshot(YamlSaveHelper& yamlSaveHelper) { YamlSaveHelper::Label state(yamlSaveHelper, "%s:\n", VideoGetSnapshotStructName().c_str()); yamlSaveHelper.SaveBool(SS_YAML_KEY_ALT_CHARSET, g_nAltCharSetOffset ? true : false); @@ -291,7 +255,7 @@ void VideoSaveSnapshot(YamlSaveHelper& yamlSaveHelper) yamlSaveHelper.SaveUint(SS_YAML_KEY_VIDEO_REFRESH_RATE, (UINT)GetVideoRefreshRate()); } -void VideoLoadSnapshot(YamlLoadHelper& yamlLoadHelper, UINT version) +void Video::VideoLoadSnapshot(YamlLoadHelper& yamlLoadHelper, UINT version) { if (!yamlLoadHelper.GetSubMap(VideoGetSnapshotStructName())) return; @@ -315,9 +279,25 @@ void VideoLoadSnapshot(YamlLoadHelper& yamlLoadHelper, UINT version) // References to Jim Sather's books are given as eg: // UTAIIe:5-7,P3 (Understanding the Apple IIe, chapter 5, page 7, Paragraph 3) // -WORD VideoGetScannerAddress(DWORD nCycles, VideoScanner_e videoScannerAddr /*= VS_FullAddr*/) +WORD Video::VideoGetScannerAddress(DWORD nCycles, VideoScanner_e videoScannerAddr /*= VS_FullAddr*/) { - // machine state switches + const int kHBurstClock = 53; // clock when Color Burst starts + const int kHBurstClocks = 4; // clocks per Color Burst duration + const int kHClock0State = 0x18; // H[543210] = 011000 + const int kHClocks = 65; // clocks per horizontal scan (including HBL) + const int kHPEClock = 40; // clock when HPE (horizontal preset enable) goes low + const int kHPresetClock = 41; // clock when H state presets + const int kHSyncClock = 49; // clock when HSync starts + const int kHSyncClocks = 4; // clocks per HSync duration + const int kNTSCScanLines = 262; // total scan lines including VBL (NTSC) + const int kNTSCVSyncLine = 224; // line when VSync starts (NTSC) + const int kPALScanLines = 312; // total scan lines including VBL (PAL) + const int kPALVSyncLine = 264; // line when VSync starts (PAL) + const int kVLine0State = 0x100; // V[543210CBA] = 100000000 + const int kVPresetLine = 256; // line when V state presets + const int kVSyncLines = 4; // lines per VSync duration + + // machine state switches // bool bHires = VideoGetSWHIRES() && !VideoGetSWTEXT(); bool bPage2 = VideoGetSWPAGE2(); @@ -432,7 +412,7 @@ WORD VideoGetScannerAddress(DWORD nCycles, VideoScanner_e videoScannerAddr /*= V //=========================================================================== // Called when *outside* of CpuExecute() -bool VideoGetVblBarEx(const DWORD dwCyclesThisFrame) +bool Video::VideoGetVblBarEx(const DWORD dwCyclesThisFrame) { if (g_bFullSpeed) { @@ -444,7 +424,7 @@ bool VideoGetVblBarEx(const DWORD dwCyclesThisFrame) } // Called when *inside* CpuExecute() -bool VideoGetVblBar(const DWORD uExecutedCycles) +bool Video::VideoGetVblBar(const DWORD uExecutedCycles) { if (g_bFullSpeed) { @@ -454,39 +434,25 @@ bool VideoGetVblBar(const DWORD uExecutedCycles) return g_nVideoClockVert < kVDisplayableScanLines; } -//=========================================================================== - -#define SCREENSHOT_BMP 1 -#define SCREENSHOT_TGA 0 - -static int g_nLastScreenShot = 0; -const int nMaxScreenShot = 999999999; -static std::string g_pLastDiskImageName; //=========================================================================== -void Video_ResetScreenshotCounter( const std::string & pImageName ) + +void Video::Video_ResetScreenshotCounter(const std::string& pImageName) { g_nLastScreenShot = 0; g_pLastDiskImageName = pImageName; } -//=========================================================================== -void Util_MakeScreenShotFileName( TCHAR *pFinalFileName_, DWORD chars ) +void Video::Util_MakeScreenShotFileName(TCHAR *pFinalFileName_, DWORD chars) { const std::string sPrefixScreenShotFileName = "AppleWin_ScreenShot"; // TODO: g_sScreenshotDir const std::string pPrefixFileName = !g_pLastDiskImageName.empty() ? g_pLastDiskImageName : sPrefixScreenShotFileName; -#if SCREENSHOT_BMP StringCbPrintf( pFinalFileName_, chars, TEXT("%s_%09d.bmp"), pPrefixFileName.c_str(), g_nLastScreenShot ); -#endif -#if SCREENSHOT_TGA - StringCbPrintf( pFinalFileName_, chars, TEXT("%s%09d.tga"), pPrefixFileName.c_str(), g_nLastScreenShot ); -#endif } // Returns TRUE if file exists, else FALSE -//=========================================================================== -bool Util_TestScreenShotFileName( const TCHAR *pFileName ) +bool Video::Util_TestScreenShotFileName(const TCHAR *pFileName) { bool bFileExists = false; FILE *pFile = fopen( pFileName, "rt" ); @@ -499,7 +465,8 @@ bool Util_TestScreenShotFileName( const TCHAR *pFileName ) } //=========================================================================== -void Video_TakeScreenShot( const VideoScreenShot_e ScreenShotType ) + +void Video::Video_TakeScreenShot(const VideoScreenShot_e ScreenShotType) { TCHAR sScreenShotFileName[ MAX_PATH ]; @@ -516,8 +483,8 @@ void Video_TakeScreenShot( const VideoScreenShot_e ScreenShotType ) return; } - Util_MakeScreenShotFileName( sScreenShotFileName, MAX_PATH ); - bExists = Util_TestScreenShotFileName( sScreenShotFileName ); + Util_MakeScreenShotFileName(sScreenShotFileName, MAX_PATH); + bExists = Util_TestScreenShotFileName(sScreenShotFileName); if( !bExists ) { break; @@ -525,45 +492,12 @@ void Video_TakeScreenShot( const VideoScreenShot_e ScreenShotType ) g_nLastScreenShot++; } - Video_SaveScreenShot( ScreenShotType, sScreenShotFileName ); + Video_SaveScreenShot(ScreenShotType, sScreenShotFileName); g_nLastScreenShot++; } -WinBmpHeader_t g_tBmpHeader; - -#if SCREENSHOT_TGA - enum TargaImageType_e - { - TARGA_RGB = 2 - }; - - struct TargaHeader_t - { // Addr Bytes - u8 nIdBytes ; // 00 01 size of ID field that follows 18 byte header (0 usually) - u8 bHasPalette ; // 01 01 - u8 iImageType ; // 02 01 type of image 0=none,1=indexed,2=rgb,3=grey,+8=rle packed - - s16 iPaletteFirstColor ; // 03 02 - s16 nPaletteColors ; // 05 02 - u8 nPaletteBitsPerEntry ; // 07 01 number of bits per palette entry 15,16,24,32 - - s16 nOriginX ; // 08 02 image x origin - s16 nOriginY ; // 0A 02 image y origin - s16 nWidthPixels ; // 0C 02 - s16 nHeightPixels ; // 0E 02 - u8 nBitsPerPixel ; // 10 01 image bits per pixel 8,16,24,32 - u8 iDescriptor ; // 11 01 image descriptor bits (vh flip bits) - - // pixel data... - u8 aPixelData[1] ; // rgb - }; - - TargaHeader_t g_tTargaHeader; -#endif // SCREENSHOT_TGA - -void Video_SetBitmapHeader( WinBmpHeader_t *pBmp, int nWidth, int nHeight, int nBitsPerPixel ) +void Video::Video_SetBitmapHeader(WinBmpHeader_t *pBmp, int nWidth, int nHeight, int nBitsPerPixel) { -#if SCREENSHOT_BMP pBmp->nCookie[ 0 ] = 'B'; // 0x42 pBmp->nCookie[ 1 ] = 'M'; // 0x4d pBmp->nSizeFile = 0; @@ -596,7 +530,8 @@ void Video_SetBitmapHeader( WinBmpHeader_t *pBmp, int nWidth, int nHeight, int n } //=========================================================================== -static void Video_MakeScreenShot(FILE *pFile, const VideoScreenShot_e ScreenShotType) + +void Video::Video_MakeScreenShot(FILE *pFile, const VideoScreenShot_e ScreenShotType) { WinBmpHeader_t *pBmp = &g_tBmpHeader; @@ -607,12 +542,6 @@ static void Video_MakeScreenShot(FILE *pFile, const VideoScreenShot_e ScreenShot 32 ); -// char sText[256]; -// sprintf( sText, "sizeof: BITMAPFILEHEADER = %d\n", sizeof(BITMAPFILEHEADER) ); // = 14 -// MessageBox( GetFrame().g_hFrameWindow, sText, "Info 1", MB_OK ); -// sprintf( sText, "sizeof: BITMAPINFOHEADER = %d\n", sizeof(BITMAPINFOHEADER) ); // = 40 -// MessageBox( GetFrame().g_hFrameWindow, sText, "Info 2", MB_OK ); - char sIfSizeZeroOrUnknown_BadWinBmpHeaderPackingSize54[ sizeof( WinBmpHeader_t ) == (14 + 40) ]; /**/ sIfSizeZeroOrUnknown_BadWinBmpHeaderPackingSize54[0]=0; @@ -670,22 +599,11 @@ static void Video_MakeScreenShot(FILE *pFile, const VideoScreenShot_e ScreenShot pSrc += GetFrameBufferWidth(); } } -#endif // SCREENSHOT_BMP - -#if SCREENSHOT_TGA - TargaHeader_t *pHeader = &g_tTargaHeader; - memset( (void*)pHeader, 0, sizeof( TargaHeader_t ) ); - - pHeader->iImageType = TARGA_RGB; - pHeader->nWidthPixels = FRAMEBUFFER_W; - pHeader->nHeightPixels = FRAMEBUFFER_H; - pHeader->nBitsPerPixel = 24; -#endif // SCREENSHOT_TGA - } //=========================================================================== -void Video_SaveScreenShot( const VideoScreenShot_e ScreenShotType, const TCHAR *pScreenShotFileName ) + +void Video::Video_SaveScreenShot(const VideoScreenShot_e ScreenShotType, const TCHAR *pScreenShotFileName) { FILE *pFile = fopen( pScreenShotFileName, "wb" ); if( pFile ) @@ -700,17 +618,9 @@ void Video_SaveScreenShot( const VideoScreenShot_e ScreenShotType, const TCHAR * } } - //=========================================================================== -static const UINT kVideoRomSize8K = kVideoRomSize4K*2; -static const UINT kVideoRomSize16K = kVideoRomSize8K*2; -static const UINT kVideoRomSizeMax = kVideoRomSize16K; -static BYTE g_videoRom[kVideoRomSizeMax]; -static UINT g_videoRomSize = 0; -static bool g_videoRomRockerSwitch = false; - -bool ReadVideoRomFile(const TCHAR* pRomFile) +bool Video::ReadVideoRomFile(const TCHAR* pRomFile) { g_videoRomSize = 0; @@ -738,43 +648,43 @@ bool ReadVideoRomFile(const TCHAR* pRomFile) return g_videoRomSize != 0; } -UINT GetVideoRom(const BYTE*& pVideoRom) +UINT Video::GetVideoRom(const BYTE*& pVideoRom) { pVideoRom = &g_videoRom[0]; return g_videoRomSize; } -bool GetVideoRomRockerSwitch(void) +bool Video::GetVideoRomRockerSwitch(void) { return g_videoRomRockerSwitch; } -void SetVideoRomRockerSwitch(bool state) +void Video::SetVideoRomRockerSwitch(bool state) { g_videoRomRockerSwitch = state; } -bool IsVideoRom4K(void) +bool Video::IsVideoRom4K(void) { return g_videoRomSize <= kVideoRomSize4K; } //=========================================================================== -enum VideoType127_e +void Video::Config_Load_Video() { - VT127_MONO_CUSTOM - , VT127_COLOR_MONITOR_NTSC - , VT127_MONO_TV - , VT127_COLOR_TV - , VT127_MONO_AMBER - , VT127_MONO_GREEN - , VT127_MONO_WHITE - , VT127_NUM_VIDEO_MODES -}; + enum VideoType127_e + { + VT127_MONO_CUSTOM + , VT127_COLOR_MONITOR_NTSC + , VT127_MONO_TV + , VT127_COLOR_TV + , VT127_MONO_AMBER + , VT127_MONO_GREEN + , VT127_MONO_WHITE + , VT127_NUM_VIDEO_MODES + }; -void Config_Load_Video() -{ DWORD dwTmp; REGLOAD_DEFAULT(TEXT(REGVALUE_VIDEO_MODE), &dwTmp, (DWORD)VT_DEFAULT); @@ -828,7 +738,7 @@ void Config_Load_Video() g_eVideoType = VT_DEFAULT; } -void Config_Save_Video() +void Video::Config_Save_Video() { REGSAVE(TEXT(REGVALUE_VIDEO_MODE) ,g_eVideoType); REGSAVE(TEXT(REGVALUE_VIDEO_STYLE) ,g_eVideoStyle); @@ -838,40 +748,64 @@ void Config_Save_Video() //=========================================================================== -VideoType_e GetVideoType(void) +uint32_t Video::GetVideoMode(void) +{ + return g_uVideoMode; +} + +void Video::SetVideoMode(uint32_t videoMode) +{ + g_uVideoMode = videoMode; +} + +VideoType_e Video::GetVideoType(void) { return (VideoType_e) g_eVideoType; } // TODO: Can only do this at start-up (mid-emulation requires a more heavy-weight video reinit) -void SetVideoType(VideoType_e newVideoType) +void Video::SetVideoType(VideoType_e newVideoType) { g_eVideoType = newVideoType; } -VideoStyle_e GetVideoStyle(void) +VideoStyle_e Video::GetVideoStyle(void) { return g_eVideoStyle; } -void SetVideoStyle(VideoStyle_e newVideoStyle) +void Video::IncVideoType(void) +{ + g_eVideoType++; + if (g_eVideoType >= NUM_VIDEO_MODES) + g_eVideoType = 0; +} + +void Video::DecVideoType(void) +{ + if (g_eVideoType <= 0) + g_eVideoType = NUM_VIDEO_MODES; + g_eVideoType--; +} + +void Video::SetVideoStyle(VideoStyle_e newVideoStyle) { g_eVideoStyle = newVideoStyle; } -bool IsVideoStyle(VideoStyle_e mask) +bool Video::IsVideoStyle(VideoStyle_e mask) { return (g_eVideoStyle & mask) != 0; } //=========================================================================== -VideoRefreshRate_e GetVideoRefreshRate(void) +VideoRefreshRate_e Video::GetVideoRefreshRate(void) { return (g_bVideoScannerNTSC == false) ? VR_50HZ : VR_60HZ; } -void SetVideoRefreshRate(VideoRefreshRate_e rate) +void Video::SetVideoRefreshRate(VideoRefreshRate_e rate) { if (rate != VR_50HZ) rate = VR_60HZ; @@ -882,7 +816,7 @@ void SetVideoRefreshRate(VideoRefreshRate_e rate) //=========================================================================== -const char* VideoGetAppWindowTitle(void) +const char* Video::VideoGetAppWindowTitle(void) { static const char *apVideoMonitorModeDesc[ 2 ] = { diff --git a/source/Video.h b/source/Video.h index f09fa528..699fb440 100644 --- a/source/Video.h +++ b/source/Video.h @@ -13,76 +13,76 @@ // Types ____________________________________________________________ - // NOTE: KEEP IN SYNC: VideoType_e g_aVideoChoices g_apVideoModeDesc - // NOTE: Used/Serialized by: g_eVideoType - enum VideoType_e - { - VT_MONO_CUSTOM - , VT_COLOR_IDEALIZED // Color rendering from AppleWin 1.25 (GH#357) - , VT_COLOR_VIDEOCARD_RGB // Real RGB card rendering - , VT_COLOR_MONITOR_NTSC // NTSC or PAL - , VT_COLOR_TV - , VT_MONO_TV - , VT_MONO_AMBER - , VT_MONO_GREEN - , VT_MONO_WHITE - , NUM_VIDEO_MODES - , VT_DEFAULT = VT_COLOR_TV - }; +// NOTE: KEEP IN SYNC: VideoType_e g_aVideoChoices g_apVideoModeDesc +// NOTE: Used/Serialized by: g_eVideoType +enum VideoType_e +{ + VT_MONO_CUSTOM + , VT_COLOR_IDEALIZED // Color rendering from AppleWin 1.25 (GH#357) + , VT_COLOR_VIDEOCARD_RGB // Real RGB card rendering + , VT_COLOR_MONITOR_NTSC // NTSC or PAL + , VT_COLOR_TV + , VT_MONO_TV + , VT_MONO_AMBER + , VT_MONO_GREEN + , VT_MONO_WHITE + , NUM_VIDEO_MODES + , VT_DEFAULT = VT_COLOR_TV +}; - extern TCHAR g_aVideoChoices[]; +extern TCHAR g_aVideoChoices[]; - enum VideoStyle_e - { - VS_NONE=0, - VS_HALF_SCANLINES=1, // drop 50% scan lines for a more authentic look - VS_COLOR_VERTICAL_BLEND=2, // Color "TV Emu" rendering from AppleWin 1.25 (GH#616) -// VS_TEXT_OPTIMIZED=4, - }; +enum VideoStyle_e +{ + VS_NONE=0, + VS_HALF_SCANLINES=1, // drop 50% scan lines for a more authentic look + VS_COLOR_VERTICAL_BLEND=2, // Color "TV Emu" rendering from AppleWin 1.25 (GH#616) +// VS_TEXT_OPTIMIZED=4, +}; - enum VideoRefreshRate_e - { - VR_NONE, - VR_50HZ, - VR_60HZ - }; +enum VideoRefreshRate_e +{ + VR_NONE, + VR_50HZ, + VR_60HZ +}; - enum VideoFlag_e - { - VF_80COL = 0x00000001, - VF_DHIRES = 0x00000002, - VF_HIRES = 0x00000004, - VF_80STORE= 0x00000008, - VF_MIXED = 0x00000010, - VF_PAGE2 = 0x00000020, - VF_TEXT = 0x00000040 - }; +enum VideoFlag_e +{ + VF_80COL = 0x00000001, + VF_DHIRES = 0x00000002, + VF_HIRES = 0x00000004, + VF_80STORE= 0x00000008, + VF_MIXED = 0x00000010, + VF_PAGE2 = 0x00000020, + VF_TEXT = 0x00000040 +}; - enum AppleFont_e - { - // 40-Column mode is 1x Zoom (default) - // 80-Column mode is ~0.75x Zoom (7 x 16) - // Tiny mode is 0.5 zoom (7x8) for debugger - APPLE_FONT_WIDTH = 14, // in pixels - APPLE_FONT_HEIGHT = 16, // in pixels +enum AppleFont_e +{ + // 40-Column mode is 1x Zoom (default) + // 80-Column mode is ~0.75x Zoom (7 x 16) + // Tiny mode is 0.5 zoom (7x8) for debugger + APPLE_FONT_WIDTH = 14, // in pixels + APPLE_FONT_HEIGHT = 16, // in pixels - // Each cell has a reserved aligned pixel area (grid spacing) - APPLE_FONT_CELL_WIDTH = 16, - APPLE_FONT_CELL_HEIGHT = 16, + // Each cell has a reserved aligned pixel area (grid spacing) + APPLE_FONT_CELL_WIDTH = 16, + APPLE_FONT_CELL_HEIGHT = 16, - // The bitmap contains 3 regions - // Each region is 256x256 pixels = 16x16 chars - APPLE_FONT_X_REGIONSIZE = 256, // in pixelx - APPLE_FONT_Y_REGIONSIZE = 256, // in pixels + // The bitmap contains 3 regions + // Each region is 256x256 pixels = 16x16 chars + APPLE_FONT_X_REGIONSIZE = 256, // in pixelx + APPLE_FONT_Y_REGIONSIZE = 256, // in pixels - // Starting Y offsets (pixels) for the regions - APPLE_FONT_Y_APPLE_2PLUS = 0, // ][+ - APPLE_FONT_Y_APPLE_80COL = 256, // //e (inc. Mouse Text) - APPLE_FONT_Y_APPLE_40COL = 512, // ][ - }; + // Starting Y offsets (pixels) for the regions + APPLE_FONT_Y_APPLE_2PLUS = 0, // ][+ + APPLE_FONT_Y_APPLE_80COL = 256, // //e (inc. Mouse Text) + APPLE_FONT_Y_APPLE_40COL = 512, // ][ +}; #ifdef _MSC_VER - /// turn of MSVC struct member padding + // turn of MSVC struct member padding #pragma pack(push,1) #define PACKED #else @@ -177,74 +177,170 @@ struct WinBmpHeader4_t #pragma pack(pop) #endif -// Globals __________________________________________________________ -extern COLORREF g_nMonochromeRGB; // saved to Registry -extern uint32_t g_uVideoMode; -extern DWORD g_eVideoType; // saved to Registry -extern uint8_t *g_pFramebufferbits; +// -// Prototypes _______________________________________________________ - -// size of the video buffer stored in g_pFramebufferbits -UINT GetFrameBufferBorderlessWidth(void); -UINT GetFrameBufferBorderlessHeight(void); -UINT GetFrameBufferBorderWidth(void); -UINT GetFrameBufferBorderHeight(void); -UINT GetFrameBufferWidth(void); -UINT GetFrameBufferHeight(void); - -void VideoReinitialize (bool bInitVideoScannerAddress = true); -void VideoResetState (); -enum VideoScanner_e {VS_FullAddr, VS_PartialAddrV, VS_PartialAddrH}; -WORD VideoGetScannerAddress(DWORD nCycles, VideoScanner_e videoScannerAddr = VS_FullAddr); -bool VideoGetVblBarEx(const DWORD dwCyclesThisFrame); -bool VideoGetVblBar(const DWORD uExecutedCycles); - -bool VideoGetSW80COL(void); -bool VideoGetSWDHIRES(void); -bool VideoGetSWHIRES(void); -bool VideoGetSW80STORE(void); -bool VideoGetSWMIXED(void); -bool VideoGetSWPAGE2(void); -bool VideoGetSWTEXT(void); -bool VideoGetSWAltCharSet(void); - -void VideoSaveSnapshot(class YamlSaveHelper& yamlSaveHelper); -void VideoLoadSnapshot(class YamlLoadHelper& yamlLoadHelper, UINT version); - -extern bool g_bDisplayPrintScreenFileName; -extern bool g_bShowPrintScreenWarningDialog; - -void Video_ResetScreenshotCounter( const std::string & pDiskImageFileName ); -enum VideoScreenShot_e +class Video { - SCREENSHOT_560x384 = 0, - SCREENSHOT_280x192 +public: + Video(void) + { + g_pFramebufferbits = NULL; // last drawn frame (initialized in WinVideoInitialize) + g_nAltCharSetOffset = 0; + g_uVideoMode = VF_TEXT; + g_eVideoType = VT_DEFAULT; + g_eVideoStyle = VS_HALF_SCANLINES; + g_bVideoScannerNTSC = true; + g_nMonochromeRGB = RGB(0xC0,0xC0,0xC0); + g_bDisplayPrintScreenFileName = false; + g_bShowPrintScreenWarningDialog = true; + g_nLastScreenShot = 0; + g_videoRomSize = 0; + g_videoRomRockerSwitch = false; + } + + virtual ~Video(void) + { + } + + virtual void Initialize(void) + { + } + + virtual void Destroy(void) + { + } + + virtual void VideoRedrawScreenDuringFullSpeed(DWORD dwCyclesThisFrame, bool bInit = false) = 0; + virtual void VideoRedrawScreenAfterFullSpeed(DWORD dwCyclesThisFrame) = 0; + virtual void VideoRefreshScreen(uint32_t uRedrawWholeScreenVideoMode = 0, bool bRedrawWholeScreen = false) = 0; + virtual void Video_RedrawAndTakeScreenShot(const char* pScreenshotFilename) = 0; + virtual void ChooseMonochromeColor(void) = 0; + virtual void Benchmark(void) = 0; + virtual void DisplayLogo(void) = 0; + + uint8_t* GetFrameBuffer(void) { return g_pFramebufferbits; } + void SetFrameBuffer(uint8_t* frameBuffer) { g_pFramebufferbits = frameBuffer; } + + // size of the video buffer stored in g_pFramebufferbits + UINT GetFrameBufferBorderlessWidth(void); + UINT GetFrameBufferBorderlessHeight(void); + UINT GetFrameBufferBorderWidth(void); + UINT GetFrameBufferBorderHeight(void); + UINT GetFrameBufferWidth(void); + UINT GetFrameBufferHeight(void); + + COLORREF GetMonochromeRGB(void) { return g_nMonochromeRGB; } + void SetMonochromeRGB(COLORREF colorRef) { g_nMonochromeRGB = colorRef; } + + void VideoReinitialize(bool bInitVideoScannerAddress = true); + void VideoResetState(void); + + enum VideoScanner_e {VS_FullAddr, VS_PartialAddrV, VS_PartialAddrH}; + WORD VideoGetScannerAddress(DWORD nCycles, VideoScanner_e videoScannerAddr = VS_FullAddr); + bool VideoGetVblBarEx(const DWORD dwCyclesThisFrame); + bool VideoGetVblBar(const DWORD uExecutedCycles); + + bool VideoGetSW80COL(void); + bool VideoGetSWDHIRES(void); + bool VideoGetSWHIRES(void); + bool VideoGetSW80STORE(void); + bool VideoGetSWMIXED(void); + bool VideoGetSWPAGE2(void); + bool VideoGetSWTEXT(void); + bool VideoGetSWAltCharSet(void); + + void VideoSaveSnapshot(class YamlSaveHelper& yamlSaveHelper); + void VideoLoadSnapshot(class YamlLoadHelper& yamlLoadHelper, UINT version); + + void Video_ResetScreenshotCounter(const std::string & pDiskImageFileName); + enum VideoScreenShot_e + { + SCREENSHOT_560x384 = 0, + SCREENSHOT_280x192 + }; + void Video_TakeScreenShot(VideoScreenShot_e ScreenShotType); + void Video_SetBitmapHeader(WinBmpHeader_t *pBmp, int nWidth, int nHeight, int nBitsPerPixel); + void Video_SaveScreenShot(const VideoScreenShot_e ScreenShotType, const TCHAR* pScreenShotFileName); + void SetDisplayPrintScreenFileName(bool state) { g_bDisplayPrintScreenFileName = state; } + + bool GetShowPrintScreenWarningDialog(void) { return g_bShowPrintScreenWarningDialog; } + void SetShowPrintScreenWarningDialog(bool state) { g_bShowPrintScreenWarningDialog = state; } + + BYTE VideoSetMode(WORD pc, WORD addr, BYTE bWrite, BYTE d, ULONG uExecutedCycles); + + bool ReadVideoRomFile(const char* pRomFile); + UINT GetVideoRom(const BYTE*& pVideoRom); + bool GetVideoRomRockerSwitch(void); + void SetVideoRomRockerSwitch(bool state); + bool IsVideoRom4K(void); + + void Config_Load_Video(void); + void Config_Save_Video(void); + + uint32_t GetVideoMode(void); + void SetVideoMode(uint32_t videoMode); + VideoType_e GetVideoType(void); + void SetVideoType(VideoType_e newVideoType); + void IncVideoType(void); + void DecVideoType(void); + VideoStyle_e GetVideoStyle(void); + void SetVideoStyle(VideoStyle_e newVideoStyle); + bool IsVideoStyle(VideoStyle_e mask); + + VideoRefreshRate_e GetVideoRefreshRate(void); + void SetVideoRefreshRate(VideoRefreshRate_e rate); + + const char* VideoGetAppWindowTitle(void); + const char* GetVideoChoices(void) { return g_aVideoChoices; } + + static const UINT kVideoRomSize2K = 1024*2; + static const UINT kVideoRomSize4K = kVideoRomSize2K*2; + +protected: + uint8_t *g_pFramebufferbits; + +private: + void Util_MakeScreenShotFileName(TCHAR *pFinalFileName_, DWORD chars); + bool Util_TestScreenShotFileName(const TCHAR *pFileName); + void Video_MakeScreenShot(FILE *pFile, const VideoScreenShot_e ScreenShotType); + + std::string VideoGetSnapshotStructName(void); + + int g_nAltCharSetOffset; + uint32_t g_uVideoMode; // Current Video Mode (this is the last set one as it may change mid-scan line!) + DWORD g_eVideoType; // saved to Registry + VideoStyle_e g_eVideoStyle; + bool g_bVideoScannerNTSC; // NTSC video scanning (or PAL) + COLORREF g_nMonochromeRGB; // saved to Registry + + WinBmpHeader_t g_tBmpHeader; + + bool g_bDisplayPrintScreenFileName; + bool g_bShowPrintScreenWarningDialog; + + int g_nLastScreenShot; + static const int nMaxScreenShot = 999999999; + std::string g_pLastDiskImageName; + + static const int kVDisplayableScanLines = 192; // max displayable scanlines + + static const UINT kVideoRomSize8K = kVideoRomSize4K*2; + static const UINT kVideoRomSize16K = kVideoRomSize8K*2; + static const UINT kVideoRomSizeMax = kVideoRomSize16K; + BYTE g_videoRom[kVideoRomSizeMax]; + UINT g_videoRomSize; + bool g_videoRomRockerSwitch; + + static const char g_aVideoChoices[]; + + static const char m_szModeDesc0[]; + static const char m_szModeDesc1[]; + static const char m_szModeDesc2[]; + static const char m_szModeDesc3[]; + static const char m_szModeDesc4[]; + static const char m_szModeDesc5[]; + static const char m_szModeDesc6[]; + static const char m_szModeDesc7[]; + static const char m_szModeDesc8[]; + static const char* const g_apVideoModeDesc[NUM_VIDEO_MODES]; }; -void Video_TakeScreenShot( VideoScreenShot_e ScreenShotType ); -void Video_SetBitmapHeader( WinBmpHeader_t *pBmp, int nWidth, int nHeight, int nBitsPerPixel ); -void Video_SaveScreenShot(const VideoScreenShot_e ScreenShotType, const TCHAR* pScreenShotFileName); - -BYTE VideoSetMode(WORD pc, WORD addr, BYTE bWrite, BYTE d, ULONG uExecutedCycles); - -const UINT kVideoRomSize2K = 1024*2; -const UINT kVideoRomSize4K = kVideoRomSize2K*2; -bool ReadVideoRomFile(const char* pRomFile); -UINT GetVideoRom(const BYTE*& pVideoRom); -bool GetVideoRomRockerSwitch(void); -void SetVideoRomRockerSwitch(bool state); -bool IsVideoRom4K(void); - -void Config_Load_Video(void); -void Config_Save_Video(void); - -VideoType_e GetVideoType(void); -void SetVideoType(VideoType_e newVideoType); -VideoStyle_e GetVideoStyle(void); -void SetVideoStyle(VideoStyle_e newVideoStyle); -bool IsVideoStyle(VideoStyle_e mask); - -VideoRefreshRate_e GetVideoRefreshRate(void); -void SetVideoRefreshRate(VideoRefreshRate_e rate); - -const char* VideoGetAppWindowTitle(void); diff --git a/source/Windows/AppleWin.cpp b/source/Windows/AppleWin.cpp index e83be2c2..33f879ee 100644 --- a/source/Windows/AppleWin.cpp +++ b/source/Windows/AppleWin.cpp @@ -172,7 +172,7 @@ static void ContinueExecution(void) if (g_bFullSpeed) { if (!bWasFullSpeed) - VideoRedrawScreenDuringFullSpeed(0, true); // Init for full-speed mode + GetVideo().VideoRedrawScreenDuringFullSpeed(0, true); // Init for full-speed mode // Don't call Spkr_Mute() - will get speaker clicks MB_Mute(); @@ -190,7 +190,7 @@ static void ContinueExecution(void) else { if (bWasFullSpeed) - VideoRedrawScreenAfterFullSpeed(g_dwCyclesThisFrame); + GetVideo().VideoRedrawScreenAfterFullSpeed(g_dwCyclesThisFrame); // Don't call Spkr_Demute() MB_Demute(); @@ -243,7 +243,7 @@ static void ContinueExecution(void) // const UINT dwClksPerFrame = NTSC_GetCyclesPerFrame(); - if (g_dwCyclesThisFrame >= dwClksPerFrame && !VideoGetVblBarEx(g_dwCyclesThisFrame)) + if (g_dwCyclesThisFrame >= dwClksPerFrame && !GetVideo().VideoGetVblBarEx(g_dwCyclesThisFrame)) { #ifdef LOG_PERF_TIMINGS PerfMarker perfMarkerVideoRefresh(g_timeVideoRefresh); @@ -251,9 +251,9 @@ static void ContinueExecution(void) g_dwCyclesThisFrame -= dwClksPerFrame; if (g_bFullSpeed) - VideoRedrawScreenDuringFullSpeed(g_dwCyclesThisFrame); + GetVideo().VideoRedrawScreenDuringFullSpeed(g_dwCyclesThisFrame); else - VideoRefreshScreen(); // Just copy the output of our Apple framebuffer to the system Back Buffer + GetVideo().VideoRefreshScreen(); // Just copy the output of our Apple framebuffer to the system Back Buffer } #ifdef LOG_PERF_TIMINGS @@ -482,7 +482,7 @@ static void RegisterHotKeys(void) if (!bStatus[2]) msg += "\n. Ctrl+PrintScreen"; - if (g_bShowPrintScreenWarningDialog) + if (GetVideo().GetShowPrintScreenWarningDialog()) SHMessageBoxCheck( GetFrame().g_hFrameWindow, msg.c_str(), "Warning", MB_ICONASTERISK | MB_OK, MB_OK, "AppleWin-75097740-8e59-444c-bc94-2d4915132599" ); msg += "\n"; @@ -741,7 +741,8 @@ static void OneTimeInitialization(HINSTANCE passinstance) #endif // Initialize COM - so we can use CoCreateInstance - // . NB. DSInit() & DIMouse::DirectInputInit are done when g_hFrameWindow is created (WM_CREATE) + // . DSInit() & DIMouse::DirectInputInit are done when g_hFrameWindow is created (WM_CREATE) + // . DDInit() is done in RepeatInitialization() by GetVideo().Initialize() HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED); LogFileOutput("Init: CoInitializeEx(), hr=0x%08X\n", hr); @@ -754,9 +755,6 @@ static void OneTimeInitialization(HINSTANCE passinstance) LogFileOutput("Init: SysClk_InitTimer(), res=%d\n", bSpeechOK ? 1:0); } #endif -#if 0 - DDInit(); // For WaitForVerticalBlank() -#endif GetFrame().g_hInstance = passinstance; GdiSetBatchLimit(512); @@ -793,14 +791,14 @@ static void RepeatInitialization(void) if (g_cmdLine.newVideoType >= 0) { - SetVideoType( (VideoType_e)g_cmdLine.newVideoType ); + GetVideo().SetVideoType( (VideoType_e)g_cmdLine.newVideoType ); g_cmdLine.newVideoType = -1; // Don't reapply after a restart } - SetVideoStyle( (VideoStyle_e) ((GetVideoStyle() | g_cmdLine.newVideoStyleEnableMask) & ~g_cmdLine.newVideoStyleDisableMask) ); + GetVideo().SetVideoStyle( (VideoStyle_e) ((GetVideo().GetVideoStyle() | g_cmdLine.newVideoStyleEnableMask) & ~g_cmdLine.newVideoStyleDisableMask) ); if (g_cmdLine.newVideoRefreshRate != VR_NONE) { - SetVideoRefreshRate(g_cmdLine.newVideoRefreshRate); + GetVideo().SetVideoRefreshRate(g_cmdLine.newVideoRefreshRate); g_cmdLine.newVideoRefreshRate = VR_NONE; // Don't reapply after a restart SetCurrentCLK6502(); } @@ -842,7 +840,7 @@ static void RepeatInitialization(void) JoyInitialize(); LogFileOutput("Main: JoyInitialize()\n"); - WinVideoInitialize(); // g_pFramebufferinfo been created now + GetVideo().Initialize(); // g_pFramebufferinfo been created now & COM init'ed LogFileOutput("Main: VideoInitialize()\n"); LogFileOutput("Main: FrameCreateWindow() - pre\n"); @@ -850,7 +848,7 @@ static void RepeatInitialization(void) LogFileOutput("Main: FrameCreateWindow() - post\n"); // Init palette color - VideoSwitchVideocardPalette(RGB_GetVideocard(), GetVideoType()); + VideoSwitchVideocardPalette(RGB_GetVideocard(), GetVideo().GetVideoType()); // Allow the 4 hardcoded slots to be configurated as empty // NB. this state is not persisted to the Registry/conf.ini (just as '-s7 empty' isn't) @@ -977,7 +975,7 @@ static void RepeatInitialization(void) if (g_cmdLine.szScreenshotFilename) { - Video_RedrawAndTakeScreenShot(g_cmdLine.szScreenshotFilename); + GetVideo().Video_RedrawAndTakeScreenShot(g_cmdLine.szScreenshotFilename); g_cmdLine.bShutdown = true; } @@ -1023,7 +1021,6 @@ static void Shutdown(void) ChangeDisplaySettings(NULL, 0); // restore default // Release COM - DDUninit(); SysClk_UninitTimer(); LogFileOutput("Exit: SysClk_UninitTimer()\n"); @@ -1047,14 +1044,20 @@ static void Shutdown(void) UnplugHardDiskControllerCard(); } -IPropertySheet& GetPropertySheet() +IPropertySheet& GetPropertySheet(void) { static CPropertySheet sg_PropertySheet; return sg_PropertySheet; } -FrameBase& GetFrame() +FrameBase& GetFrame(void) { static Win32Frame sg_Win32Frame; return sg_Win32Frame; } + +Video& GetVideo(void) +{ + static WinVideo video; + return video; +} diff --git a/source/Windows/WinFrame.cpp b/source/Windows/WinFrame.cpp index 81e80a20..6a49ff9a 100644 --- a/source/Windows/WinFrame.cpp +++ b/source/Windows/WinFrame.cpp @@ -62,8 +62,8 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #define VIEWPORTY 5 static const int kDEFAULT_VIEWPORT_SCALE = 2; - int g_nViewportCX = GetFrameBufferBorderlessWidth() * kDEFAULT_VIEWPORT_SCALE; - int g_nViewportCY = GetFrameBufferBorderlessHeight() * kDEFAULT_VIEWPORT_SCALE; + int g_nViewportCX = GetVideo().GetFrameBufferBorderlessWidth() * kDEFAULT_VIEWPORT_SCALE; + int g_nViewportCY = GetVideo().GetFrameBufferBorderlessHeight() * kDEFAULT_VIEWPORT_SCALE; static int g_nViewportScale = kDEFAULT_VIEWPORT_SCALE; // saved REGSAVE static int g_nMaxViewportScale = kDEFAULT_VIEWPORT_SCALE; // Max scale in Windowed mode with borders, buttons etc (full-screen may be +1) @@ -585,7 +585,7 @@ static void DrawFrameWindow (bool bPaintingWindow/*=false*/) // DRAW THE CONTENTS OF THE EMULATED SCREEN if (g_nAppMode == MODE_LOGO) - VideoDisplayLogo(); + GetVideo().DisplayLogo(); else if (g_nAppMode == MODE_DEBUG) DebugDisplay(); else @@ -1064,7 +1064,7 @@ LRESULT CALLBACK FrameWndProc ( CpuDestroy(); MemDestroy(); SpkrDestroy(); - WinVideoDestroy(); + GetVideo().Destroy(); MB_Destroy(); DeleteGdiObjects(); DIMouse::DirectInputUninit(window); // NB. do before window is destroyed @@ -1135,7 +1135,7 @@ LRESULT CALLBACK FrameWndProc ( } case WM_DISPLAYCHANGE: - VideoReinitialize(); + GetVideo().VideoReinitialize(); break; case WM_DROPFILES: @@ -1186,18 +1186,12 @@ LRESULT CALLBACK FrameWndProc ( // lparam = modifiers: shift, ctrl, alt, win if (wparam == VK_SNAPSHOT_560) { -#if _DEBUG -// MessageBox( GetFrame().g_hFrameWindow, "Double 580x384 size!", "PrintScreen", MB_OK ); -#endif - Video_TakeScreenShot( SCREENSHOT_560x384 ); + GetVideo().Video_TakeScreenShot( Video::SCREENSHOT_560x384 ); } else if (wparam == VK_SNAPSHOT_280) // ( lparam & MOD_SHIFT ) { -#if _DEBUG -// MessageBox( GetFrame().g_hFrameWindow, "Normal 280x192 size!", "PrintScreen", MB_OK ); -#endif - Video_TakeScreenShot( SCREENSHOT_280x192 ); + GetVideo().Video_TakeScreenShot( Video::SCREENSHOT_280x192 ); } else if (wparam == VK_SNAPSHOT_TEXT) // ( lparam & MOD_CONTROL ) @@ -1238,25 +1232,21 @@ LRESULT CALLBACK FrameWndProc ( if ( !KeybGetCtrlStatus() && !KeybGetShiftStatus() ) // F9 { - g_eVideoType++; - if (g_eVideoType >= NUM_VIDEO_MODES) - g_eVideoType = 0; + GetVideo().IncVideoType(); } else if ( !KeybGetCtrlStatus() && KeybGetShiftStatus() ) // SHIFT+F9 { - if (g_eVideoType <= 0) - g_eVideoType = NUM_VIDEO_MODES; - g_eVideoType--; + GetVideo().DecVideoType(); } else if ( KeybGetCtrlStatus() && KeybGetShiftStatus() ) // CTRL+SHIFT+F9 { - SetVideoStyle( (VideoStyle_e) (GetVideoStyle() ^ VS_HALF_SCANLINES) ); + GetVideo().SetVideoStyle( (VideoStyle_e) (GetVideo().GetVideoStyle() ^ VS_HALF_SCANLINES) ); } // TODO: Clean up code:FrameRefreshStatus(DRAW_TITLE) DrawStatusArea((HDC)0,DRAW_TITLE) DrawStatusArea( (HDC)0, DRAW_TITLE ); - VideoReinitialize(false); + GetVideo().VideoReinitialize(false); if (g_nAppMode != MODE_LOGO) { @@ -1264,23 +1254,23 @@ LRESULT CALLBACK FrameWndProc ( { UINT debugVideoMode; if ( DebugGetVideoMode(&debugVideoMode) ) - VideoRefreshScreen(debugVideoMode, true); + GetVideo().VideoRefreshScreen(debugVideoMode, true); else - VideoRefreshScreen(); + GetVideo().VideoRefreshScreen(); } else { - VideoRefreshScreen(); + GetVideo().VideoRefreshScreen(); } } - Config_Save_Video(); + GetVideo().Config_Save_Video(); } else if (wparam == VK_F10) { if (g_Apple2Type == A2TYPE_APPLE2E || g_Apple2Type == A2TYPE_APPLE2EENHANCED || g_Apple2Type == A2TYPE_BASE64A) { - SetVideoRomRockerSwitch( !GetVideoRomRockerSwitch() ); // F10: toggle rocker switch + GetVideo().SetVideoRomRockerSwitch( !GetVideo().GetVideoRomRockerSwitch() ); // F10: toggle rocker switch NTSC_VideoInitAppleType(); } else if (g_Apple2Type == A2TYPE_PRAVETS8A) @@ -1819,7 +1809,7 @@ LRESULT CALLBACK FrameWndProc ( DrawStatusArea((HDC)0,DRAW_TITLE); HCURSOR oldcursor = SetCursor(LoadCursor(0,IDC_WAIT)); g_nAppMode = MODE_BENCHMARK; - VideoBenchmark(); + GetVideo().Benchmark(); g_nAppMode = MODE_LOGO; ResetMachineState(); SetCursor(oldcursor); @@ -2258,12 +2248,12 @@ void SetFullScreenMode () width = (FULLSCREEN_SCALE_TYPE)(monitor_info.rcMonitor.right - monitor_info.rcMonitor.left); height = (FULLSCREEN_SCALE_TYPE)(monitor_info.rcMonitor.bottom - monitor_info.rcMonitor.top ); - scalex = width / GetFrameBufferBorderlessWidth(); - scaley = height / GetFrameBufferBorderlessHeight(); + scalex = width / GetVideo().GetFrameBufferBorderlessWidth(); + scaley = height / GetVideo().GetFrameBufferBorderlessHeight(); g_win_fullscreen_scale = (scalex <= scaley) ? scalex : scaley; - g_win_fullscreen_offsetx = ((int)width - (int)(g_win_fullscreen_scale * GetFrameBufferBorderlessWidth())) / 2; - g_win_fullscreen_offsety = ((int)height - (int)(g_win_fullscreen_scale * GetFrameBufferBorderlessHeight())) / 2; + g_win_fullscreen_offsetx = ((int)width - (int)(g_win_fullscreen_scale * GetVideo().GetFrameBufferBorderlessWidth())) / 2; + g_win_fullscreen_offsety = ((int)height - (int)(g_win_fullscreen_scale * GetVideo().GetFrameBufferBorderlessHeight())) / 2; SetWindowPos(GetFrame().g_hFrameWindow, NULL, left, top, (int)width, (int)height, SWP_NOZORDER | SWP_NOACTIVATE | SWP_FRAMECHANGED); g_bIsFullScreen = true; @@ -2351,8 +2341,8 @@ int Win32Frame::SetViewportScale(int nNewScale, bool bForce /*=false*/) nNewScale = g_nMaxViewportScale; g_nViewportScale = nNewScale; - g_nViewportCX = g_nViewportScale * GetFrameBufferBorderlessWidth(); - g_nViewportCY = g_nViewportScale * GetFrameBufferBorderlessHeight(); + g_nViewportCX = g_nViewportScale * GetVideo().GetFrameBufferBorderlessWidth(); + g_nViewportCY = g_nViewportScale * GetVideo().GetFrameBufferBorderlessHeight(); return nNewScale; } @@ -2468,8 +2458,8 @@ void FrameCreateWindow(void) int nOldViewportCX = g_nViewportCX; int nOldViewportCY = g_nViewportCY; - g_nViewportCX = GetFrameBufferBorderlessWidth() * 2; - g_nViewportCY = GetFrameBufferBorderlessHeight() * 2; + g_nViewportCX = GetVideo().GetFrameBufferBorderlessWidth() * 2; + g_nViewportCY = GetVideo().GetFrameBufferBorderlessHeight() * 2; GetWidthHeight(nWidth, nHeight); // Probe with 2x dimensions g_nViewportCX = nOldViewportCX; @@ -2844,8 +2834,8 @@ bool Win32Frame::GetBestDisplayResolutionForFullScreen(UINT& bestWidth, UINT& be { if (width > it->first) { - UINT scaleFactor = it->second / GetFrameBufferBorderlessHeight(); - if (it->first >= (GetFrameBufferBorderlessWidth() * scaleFactor)) + UINT scaleFactor = it->second / GetVideo().GetFrameBufferBorderlessHeight(); + if (it->first >= (GetVideo().GetFrameBufferBorderlessWidth() * scaleFactor)) { width = it->first; } @@ -2865,12 +2855,12 @@ bool Win32Frame::GetBestDisplayResolutionForFullScreen(UINT& bestWidth, UINT& be UINT tmpBestHeight = 0; for (VEC_PAIR::iterator it = vecDisplayResolutions.begin(); it!= vecDisplayResolutions.end(); ++it) { - if ((it->second % GetFrameBufferBorderlessHeight()) == 0) + if ((it->second % GetVideo().GetFrameBufferBorderlessHeight()) == 0) { if (it->second > tmpBestHeight) { - UINT scaleFactor = it->second / GetFrameBufferBorderlessHeight(); - if (it->first >= (GetFrameBufferBorderlessWidth() * scaleFactor)) + UINT scaleFactor = it->second / GetVideo().GetFrameBufferBorderlessHeight(); + if (it->first >= (GetVideo().GetFrameBufferBorderlessWidth() * scaleFactor)) { tmpBestWidth = it->first; tmpBestHeight = it->second; diff --git a/source/Windows/WinVideo.cpp b/source/Windows/WinVideo.cpp index 3615b66e..76650ab5 100644 --- a/source/Windows/WinVideo.cpp +++ b/source/Windows/WinVideo.cpp @@ -33,7 +33,6 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #include "Windows/WinFrame.h" #include "Windows/AppleWin.h" #include "Interface.h" -#include "Video.h" #include "Core.h" #include "CPU.h" #include "Joystick.h" @@ -44,13 +43,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #include "../resource/resource.h" -static COLORREF customcolors[256]; // MONOCHROME is last custom color -static HBITMAP g_hLogoBitmap; -static HBITMAP g_hDeviceBitmap; -static HDC g_hDeviceDC; -static LPBITMAPINFO g_pFramebufferinfo = NULL; - -static void videoCreateDIBSection() +void WinVideo::videoCreateDIBSection(void) { // CREATE THE DEVICE CONTEXT HWND window = GetDesktopWindow(); @@ -74,18 +67,16 @@ static void videoCreateDIBSection() SelectObject(g_hDeviceDC, g_hDeviceBitmap); // DRAW THE SOURCE IMAGE INTO THE SOURCE BIT BUFFER - memset(g_pFramebufferbits, 0, GetFrameBufferWidth() * GetFrameBufferHeight() * sizeof(bgra_t)); + memset(GetFrameBuffer(), 0, GetFrameBufferWidth() * GetFrameBufferHeight() * sizeof(bgra_t)); // CREATE THE OFFSET TABLE FOR EACH SCAN LINE IN THE FRAME BUFFER - NTSC_VideoInit(g_pFramebufferbits); + NTSC_VideoInit(GetFrameBuffer()); } -// -// ----- ALL GLOBALLY ACCESSIBLE FUNCTIONS ARE BELOW THIS LINE ----- -// - -void WinVideoInitialize() +void WinVideo::Initialize(void) { + Video::Initialize(); + // RESET THE VIDEO MODE SWITCHES AND THE CHARACTER SET OFFSET VideoResetState(); @@ -105,11 +96,14 @@ void WinVideoInitialize() g_pFramebufferinfo->bmiHeader.biClrUsed = 0; videoCreateDIBSection(); + +#if 0 + DDInit(); // For WaitForVerticalBlank() +#endif } -void WinVideoDestroy() +void WinVideo::Destroy(void) { - // DESTROY BUFFERS delete [] g_pFramebufferinfo; g_pFramebufferinfo = NULL; @@ -119,7 +113,7 @@ void WinVideoDestroy() DeleteObject(g_hDeviceBitmap); g_hDeviceDC = (HDC)0; g_hDeviceBitmap = (HBITMAP)0; - g_pFramebufferbits = NULL; + SetFrameBuffer(NULL); // DESTROY LOGO if (g_hLogoBitmap) { @@ -128,10 +122,15 @@ void WinVideoDestroy() } NTSC_Destroy(); + + DDUninit(); + + Video::Destroy(); } //=========================================================================== -void VideoBenchmark () { +void WinVideo::Benchmark(void) +{ _ASSERT(g_nAppMode == MODE_BENCHMARK); Sleep(500); @@ -151,7 +150,7 @@ void VideoBenchmark () { // SIMULATE THE ACTIVITY OF AN AVERAGE GAME DWORD totaltextfps = 0; - g_uVideoMode = VF_TEXT; + SetVideoMode(VF_TEXT); memset(mem+0x400,0x14,0x400); GetFrame().VideoRedrawScreen(); DWORD milliseconds = GetTickCount(); @@ -173,7 +172,7 @@ void VideoBenchmark () { // GOING ON, CHANGING HALF OF THE BYTES IN THE VIDEO BUFFER EACH FRAME TO // SIMULATE THE ACTIVITY OF AN AVERAGE GAME DWORD totalhiresfps = 0; - g_uVideoMode = VF_HIRES; + SetVideoMode(VF_HIRES); memset(mem+0x2000,0x14,0x2000); GetFrame().VideoRedrawScreen(); milliseconds = GetTickCount(); @@ -285,7 +284,7 @@ void VideoBenchmark () { } while (GetTickCount() - milliseconds < 1000); // DISPLAY THE RESULTS - VideoDisplayLogo(); + DisplayLogo(); TCHAR outstr[256]; wsprintf(outstr, TEXT("Pure Video FPS:\t%u hires, %u text\n") @@ -304,20 +303,21 @@ void VideoBenchmark () { MB_ICONINFORMATION | MB_SETFOREGROUND); } -// This is called from PageConfig //=========================================================================== -void VideoChooseMonochromeColor () + +// This is called from PageConfig +void WinVideo::ChooseMonochromeColor(void) { CHOOSECOLOR cc; memset(&cc, 0, sizeof(CHOOSECOLOR)); cc.lStructSize = sizeof(CHOOSECOLOR); cc.hwndOwner = GetFrame().g_hFrameWindow; - cc.rgbResult = g_nMonochromeRGB; + cc.rgbResult = GetMonochromeRGB(); cc.lpCustColors = customcolors + 1; cc.Flags = CC_RGBINIT | CC_SOLIDCOLOR; if (ChooseColor(&cc)) { - g_nMonochromeRGB = cc.rgbResult; + SetMonochromeRGB(cc.rgbResult); VideoReinitialize(); if ((g_nAppMode != MODE_LOGO) && (g_nAppMode != MODE_DEBUG)) { @@ -329,7 +329,7 @@ void VideoChooseMonochromeColor () //=========================================================================== -static void VideoDrawLogoBitmap(HDC hDstDC, int xoff, int yoff, int srcw, int srch, int scale) +void WinVideo::VideoDrawLogoBitmap(HDC hDstDC, int xoff, int yoff, int srcw, int srch, int scale) { HDC hSrcDC = CreateCompatibleDC( hDstDC ); SelectObject( hSrcDC, g_hLogoBitmap ); @@ -347,7 +347,8 @@ static void VideoDrawLogoBitmap(HDC hDstDC, int xoff, int yoff, int srcw, int sr } //=========================================================================== -void VideoDisplayLogo () + +void WinVideo::DisplayLogo(void) { int nLogoX = 0, nLogoY = 0; int scale = GetViewportScale(); @@ -420,15 +421,13 @@ void VideoDisplayLogo () //=========================================================================== -void VideoRedrawScreenDuringFullSpeed(DWORD dwCyclesThisFrame, bool bInit /*=false*/) +void WinVideo::VideoRedrawScreenDuringFullSpeed(DWORD dwCyclesThisFrame, bool bInit /*=false*/) { static DWORD dwFullSpeedStartTime = 0; -// static bool bValid = false; if (bInit) { // Just entered full-speed mode -// bValid = false; dwFullSpeedStartTime = GetTickCount(); return; } @@ -439,54 +438,12 @@ void VideoRedrawScreenDuringFullSpeed(DWORD dwCyclesThisFrame, bool bInit /*=fal dwFullSpeedStartTime += dwFullSpeedDuration; - // - -#if 0 - static BYTE text_main[1024*2] = {0}; // page1 & 2 - static BYTE text_aux[1024*2] = {0}; // page1 & 2 - static BYTE hgr_main[8192*2] = {0}; // page1 & 2 - static BYTE hgr_aux[8192*2] = {0}; // page1 & 2 - - bool bRedraw = true; // Always redraw for bValid==false (ie. just entered full-speed mode) - - if (bValid) - { - if ((g_uVideoMode&(VF_DHIRES|VF_HIRES|VF_TEXT|VF_MIXED)) == VF_HIRES) - { - // HIRES (not MIXED) - eg. AZTEC.DSK - if ((g_uVideoMode&VF_PAGE2) == 0) - bRedraw = memcmp(&hgr_main[0x0000], MemGetMainPtr(0x2000), 8192) != 0; - else - bRedraw = memcmp(&hgr_main[0x2000], MemGetMainPtr(0x4000), 8192) != 0; - } - else - { - bRedraw = - (memcmp(text_main, MemGetMainPtr(0x400), sizeof(text_main)) != 0) || - (memcmp(text_aux, MemGetAuxPtr(0x400), sizeof(text_aux)) != 0) || - (memcmp(hgr_main, MemGetMainPtr(0x2000), sizeof(hgr_main)) != 0) || - (memcmp(hgr_aux, MemGetAuxPtr(0x2000), sizeof(hgr_aux)) != 0); - } - } - - if (bRedraw) - VideoRedrawScreenAfterFullSpeed(dwCyclesThisFrame); - - // Copy all video memory (+ screen holes) - memcpy(text_main, MemGetMainPtr(0x400), sizeof(text_main)); - memcpy(text_aux, MemGetAuxPtr(0x400), sizeof(text_aux)); - memcpy(hgr_main, MemGetMainPtr(0x2000), sizeof(hgr_main)); - memcpy(hgr_aux, MemGetAuxPtr(0x2000), sizeof(hgr_aux)); - - bValid = true; -#else VideoRedrawScreenAfterFullSpeed(dwCyclesThisFrame); -#endif } //=========================================================================== -void VideoRedrawScreenAfterFullSpeed(DWORD dwCyclesThisFrame) +void WinVideo::VideoRedrawScreenAfterFullSpeed(DWORD dwCyclesThisFrame) { NTSC_VideoClockResync(dwCyclesThisFrame); GetFrame().VideoRedrawScreen(); // Better (no flicker) than using: NTSC_VideoReinitialize() or VideoReinitialize() @@ -494,15 +451,7 @@ void VideoRedrawScreenAfterFullSpeed(DWORD dwCyclesThisFrame) //=========================================================================== -void Win32Frame::VideoRedrawScreen (void) -{ - // NB. Can't rely on g_uVideoMode being non-zero (ie. so it can double up as a flag) since 'GR,PAGE1,non-mixed' mode == 0x00. - VideoRefreshScreen( g_uVideoMode, true ); -} - -//=========================================================================== - -void VideoRefreshScreen ( uint32_t uRedrawWholeScreenVideoMode /* =0*/, bool bRedrawWholeScreen /* =false*/ ) +void WinVideo::VideoRefreshScreen(uint32_t uRedrawWholeScreenVideoMode /* =0*/, bool bRedrawWholeScreen /* =false*/) { if (bRedrawWholeScreen || g_nAppMode == MODE_PAUSED) { @@ -552,36 +501,31 @@ void VideoRefreshScreen ( uint32_t uRedrawWholeScreenVideoMode /* =0*/, bool bRe //=========================================================================== -#define MAX_DRAW_DEVICES 10 - -static char *draw_devices[MAX_DRAW_DEVICES]; -static GUID draw_device_guid[MAX_DRAW_DEVICES]; -static int num_draw_devices = 0; -static LPDIRECTDRAW g_lpDD = NULL; - -static BOOL CALLBACK DDEnumProc(LPGUID lpGUID, LPCTSTR lpszDesc, LPCTSTR lpszDrvName, LPVOID lpContext) +BOOL CALLBACK WinVideo::DDEnumProc(LPGUID lpGUID, LPCTSTR lpszDesc, LPCTSTR lpszDrvName, LPVOID lpContext) { - int i = num_draw_devices; + WinVideo* obj = (WinVideo*)lpContext; + + int i = obj->num_draw_devices; if (i == MAX_DRAW_DEVICES) return TRUE; if (lpGUID != NULL) - memcpy(&draw_device_guid[i], lpGUID, sizeof (GUID)); - draw_devices[i] = _strdup(lpszDesc); + memcpy(&(obj->draw_device_guid[i]), lpGUID, sizeof (GUID)); + obj->draw_devices[i] = _strdup(lpszDesc); if (g_fh) fprintf(g_fh, "%d: %s - %s\n",i,lpszDesc,lpszDrvName); - num_draw_devices++; + (obj->num_draw_devices)++; return TRUE; } -bool DDInit(void) +bool WinVideo::DDInit(void) { #ifdef NO_DIRECT_X return false; #else - HRESULT hr = DirectDrawEnumerate((LPDDENUMCALLBACK)DDEnumProc, NULL); + HRESULT hr = DirectDrawEnumerate((LPDDENUMCALLBACK)DDEnumProc, this); if (FAILED(hr)) { LogFileOutput("DSEnumerate failed (%08X)\n", hr); @@ -617,7 +561,7 @@ bool DDInit(void) // From SoundCore.h #define SAFE_RELEASE(p) { if(p) { (p)->Release(); (p)=NULL; } } -void DDUninit(void) +void WinVideo::DDUninit(void) { SAFE_RELEASE(g_lpDD); } @@ -626,12 +570,22 @@ void DDUninit(void) //=========================================================================== -void Video_RedrawAndTakeScreenShot(const char* pScreenshotFilename) +void WinVideo::Video_RedrawAndTakeScreenShot(const char* pScreenshotFilename) { _ASSERT(pScreenshotFilename); if (!pScreenshotFilename) return; GetFrame().VideoRedrawScreen(); - Video_SaveScreenShot(SCREENSHOT_560x384, pScreenshotFilename); + Video_SaveScreenShot(Video::SCREENSHOT_560x384, pScreenshotFilename); +} + +//=========================================================================== +//=========================================================================== + +// NB. Win32Frame, not WinVideo +void Win32Frame::VideoRedrawScreen(void) +{ + // NB. Can't rely on g_uVideoMode being non-zero (ie. so it can double up as a flag) since 'GR,PAGE1,non-mixed' mode == 0x00. + GetVideo().VideoRefreshScreen( GetVideo().GetVideoMode(), true ); } diff --git a/source/Windows/WinVideo.h b/source/Windows/WinVideo.h index 1f6018e0..49d0c0bf 100644 --- a/source/Windows/WinVideo.h +++ b/source/Windows/WinVideo.h @@ -1,18 +1,48 @@ #pragma once -// Prototypes _______________________________________________________ +#include "Video.h" -void WinVideoInitialize(); -void WinVideoDestroy(); +class WinVideo : public Video +{ +public: + WinVideo() + { + g_pFramebufferinfo = NULL; + num_draw_devices = 0; + g_lpDD = NULL; + } -void VideoBenchmark (); -void VideoChooseMonochromeColor (); // FIXME: Should be moved to PageConfig and call VideoSetMonochromeColor() -void VideoDisplayLogo (); -void VideoRedrawScreenDuringFullSpeed(DWORD dwCyclesThisFrame, bool bInit = false); -void VideoRedrawScreenAfterFullSpeed(DWORD dwCyclesThisFrame); -void VideoRefreshScreen (uint32_t uRedrawWholeScreenVideoMode = 0, bool bRedrawWholeScreen = false); + virtual ~WinVideo() + { + } -void Video_RedrawAndTakeScreenShot(const char* pScreenshotFilename); + virtual void Initialize(void); + virtual void Destroy(void); -bool DDInit(void); -void DDUninit(void); + virtual void VideoRedrawScreenDuringFullSpeed(DWORD dwCyclesThisFrame, bool bInit = false); + virtual void VideoRedrawScreenAfterFullSpeed(DWORD dwCyclesThisFrame); + virtual void VideoRefreshScreen(uint32_t uRedrawWholeScreenVideoMode = 0, bool bRedrawWholeScreen = false); + virtual void Video_RedrawAndTakeScreenShot(const char* pScreenshotFilename); + virtual void ChooseMonochromeColor(void); + virtual void Benchmark(void); + virtual void DisplayLogo(void); + +private: + void videoCreateDIBSection(void); + void VideoDrawLogoBitmap(HDC hDstDC, int xoff, int yoff, int srcw, int srch, int scale); + static BOOL CALLBACK DDEnumProc(LPGUID lpGUID, LPCTSTR lpszDesc, LPCTSTR lpszDrvName, LPVOID lpContext); + bool DDInit(void); + void DDUninit(void); + + COLORREF customcolors[256]; // MONOCHROME is last custom color + HBITMAP g_hLogoBitmap; + HBITMAP g_hDeviceBitmap; + HDC g_hDeviceDC; + LPBITMAPINFO g_pFramebufferinfo; + + static const UINT MAX_DRAW_DEVICES = 10; + char *draw_devices[MAX_DRAW_DEVICES]; + GUID draw_device_guid[MAX_DRAW_DEVICES]; + int num_draw_devices; + LPDIRECTDRAW g_lpDD; +};