AxibugEmuOnline/References/VirtuaNESex_src_191105/DirectDraw.h

373 lines
10 KiB
C
Raw Permalink Normal View History

2024-08-05 17:58:53 +08:00
//
// DirectDraw class
//
#ifndef __DIRECTDRAW_INCLUDED__
#define __DIRECTDRAW_INCLUDED__
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <objbase.h>
#include <mmsystem.h>
#include <vector>
using namespace std;
#define DIRECTDRAW_VERSION 0x0700
#include <ddraw.h>
#include <stdio.h>
#include <stdlib.h>
#include "typedef.h"
#include "macro.h"
class CDirectDraw
{
public:
// <20>p<EFBFBD>u<EFBFBD><75><EFBFBD>b<EFBFBD>N<EFBFBD><4E><EFBFBD><EFBFBD><EFBFBD>o<EFBFBD>ϐ<EFBFBD>
typedef struct tagDISPLAYMODE {
DWORD dwWidth;
DWORD dwHeight;
DWORD dwDepth;
DWORD dwRate;
} DISPLAYMODE, *LPDISPLAYMODE;
typedef struct tagPALBUF {
BYTE r;
BYTE g;
BYTE b;
} PALBUF, *LPPALBUF;
// <20><><EFBFBD>p<EFBFBD>”\<5C>ȃf<C883>B<EFBFBD>X<EFBFBD>v<EFBFBD><76><EFBFBD>C<EFBFBD><43><EFBFBD>[<5B>h
enum { DD_DISPLAYMODEMAX = 256 };
INT m_DisplayModeNum; // <20>f<EFBFBD>B<EFBFBD>X<EFBFBD>v<EFBFBD><76><EFBFBD>C<EFBFBD><43><EFBFBD>[<5B>h<EFBFBD><68>
DISPLAYMODE m_DisplayModeBuf[DD_DISPLAYMODEMAX];
// Screen size
enum { SCREEN_WIDTH = 256, SCREEN_HEIGHT = 240 };
// Render screen size
enum { RENDER_WIDTH = SCREEN_WIDTH+16, RENDER_HEIGHT = SCREEN_HEIGHT };
// Delta screen size
enum { DELTA_WIDTH = SCREEN_WIDTH, DELTA_HEIGHT = SCREEN_HEIGHT+6 };
// Filter
enum { BLTFILTER_NONE = 0,
BLTFILTER_2XSAI,
BLTFILTER_SUPER2XSAI,
BLTFILTER_SUPEREAGLE,
BLTFILTER_SCALE2X,
};
// <20>p<EFBFBD>u<EFBFBD><75><EFBFBD>b<EFBFBD>N<EFBFBD><4E><EFBFBD><EFBFBD><EFBFBD>o<EFBFBD>֐<EFBFBD>
CDirectDraw();
virtual ~CDirectDraw();
BOOL InitialDDraw( HWND hWnd );
void ReleaseDDraw();
BOOL InitialSurface( BOOL bScreenMode );
BOOL ReleaseSurface();
BOOL RestoreSurface();
BOOL BeginDisplayChange();
BOOL EndDisplayChange();
BOOL OnChangeDisplayMode();
// Display<61><79><EFBFBD>[<5B>h
INT GetDisplayModeNum() { return m_DisplayModes.size(); }
void SetDisplayMode( DWORD dwWidth, DWORD dwHeight, DWORD dwDepth, DWORD dwRate );
void GetDisplayMode( DWORD& dwWidth, DWORD& dwHeight, DWORD& dwDepth, DWORD& dwRate );
BOOL GetDisplayMode( INT no, DWORD& dwWidth, DWORD& dwHeight, DWORD& dwDepth, DWORD& dwRate );
INT GetMatchDisplayMode( DWORD dwWidth, DWORD dwHeight, DWORD dwDepth, DWORD dwRate );
BOOL IsNowDisplayMode( DWORD dwWidth, DWORD dwHeight, DWORD dwDepth, DWORD dwRate );
BOOL CalcPaletteTable();
void SetPaletteTable( LPBYTE pal );
void SetPaletteTable( RGBQUAD* pal );
void GetPaletteTable( RGBQUAD* pal );
void SetPaletteFile( LPCTSTR fname );
BOOL SetFullScreenGDI( BOOL bMode );
void SetUseHEL( BOOL bUseHEL ) {
m_bUseHEL = bUseHEL;
m_bDeltaUpdate = TRUE;
}
void SetSystemMemory( BOOL bSystemMemory ) {
m_bSystemMemory = bSystemMemory;
m_bDeltaUpdate = TRUE;
}
void SetScreenMode( BOOL bScreenMode ) {
m_bScreenMode = bScreenMode;
m_bDeltaUpdate = TRUE;
}
void SetFlipMode( BOOL bFlip ) {
m_bFlip = bFlip;
}
void SetAspectMode( BOOL bAspect ) {
m_bAspect = bAspect;
}
void SetAllLineMode( BOOL bAllLine ) {
m_bAllLine = bAllLine;
}
void SetMaxZoom( BOOL bZoom ) {
m_bMaxZoom = bZoom;
}
void SetDoubleSize( BOOL bDoubleSize ) {
m_bDoubleSize = bDoubleSize;
m_bDeltaUpdate = TRUE;
}
void SetTVFrameMode( BOOL bTVFrame ) {
m_bTVFrameMode = bTVFrame;
}
void SetScanlineMode( BOOL bScanline ) {
m_bScanlineMode = bScanline;
m_bDeltaUpdate = TRUE;
}
void SetScanlineColor( INT nScanlineColor ) {
m_nScanlineColor = nScanlineColor;
}
void SetZapperMode( BOOL bZapper ) {
m_bZapper = bZapper;
}
void SetZapperDrawMode( BOOL bDraw ) {
m_bZapperDraw = bDraw;
}
void SetWindowVSyncMode( BOOL bVSync ) {
m_bWindowVSync = bVSync;
}
void SetGraphicsFilter( INT nFilter ) {
m_nBltFilter = nFilter;
m_bDeltaUpdate = TRUE;
}
BOOL GetUseHEL() { return m_bUseHEL; }
BOOL GetSystemMemory() { return m_bSystemMemory; }
BOOL GetScreenMode() { return m_bScreenMode; }
BOOL GetFlipMode() { return m_bFlip; }
BOOL GetAspectMode() { return m_bAspect; }
BOOL GetAllLineMode() { return m_bAllLine; }
BOOL GetMaxZoom() { return m_bMaxZoom; }
BOOL GetDoubleSize() { return m_bDoubleSize; }
BOOL GetTVFrameMode() { return m_bTVFrameMode; }
BOOL GetScanlineMode() { return m_bScanlineMode; }
INT GetScanlineColor() { return m_nScanlineColor; }
BOOL GetZapperMode() { return m_bZapper; }
BOOL GetZapperDrawMode() { return m_bZapperDraw; }
BOOL GetWindowVSyncMode() { return m_bWindowVSync; }
INT GetGraphicsFilter() { return m_nBltFilter; }
LPBYTE GetRenderScreen() { return m_lpRender; }
LPBYTE GetLineColormode() { return m_LineColormode; }
// For Zapper
BYTE GetZapperHit();
void GetZapperPos( LONG& x, LONG& y );
void SetZapperPos( LONG x, LONG y );
void SetInfoString( LPCSTR str );
void SetMessageString( LPCSTR str );
void RealizePalette();
void OnScreenDraw();
void SetPaletteMode( INT nMode, BOOL bMono );
void GetPaletteData( RGBQUAD* rgb );
void SetDiskAccessLamp( BOOL bAccess ) {
m_bDiskAccessLamp = bAccess;
}
void Blt();
void Flip();
// MMX
BOOL IsMMX() { return m_bMMX; }
unsigned char * font;
void ViewChars( unsigned char * lpRdr ); //<2F><>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD>
protected:
// <20>v<EFBFBD><76><EFBFBD>e<EFBFBD>N<EFBFBD>g<EFBFBD><67><EFBFBD><EFBFBD><EFBFBD>o<EFBFBD>ϐ<EFBFBD>
// General
HWND m_hWnd; // Window handle
BOOL m_bChangeMode; // Screen Mode changing flag
BOOL m_bDraw; // Drawing flag
BOOL m_bNoRestore;
BOOL m_bMessage; // Message display?
DWORD m_dwMessageTime; // Message display times
BOOL m_bMMX; // Existence of MMX technology.
// Options
BOOL m_bUseHEL; // HAL<41><4C><EFBFBD>g<EFBFBD>킸HEL<45><4C><EFBFBD>g<EFBFBD>p
BOOL m_bSystemMemory; // <20>T<EFBFBD>[<5B>t<EFBFBD>F<EFBFBD>X<EFBFBD>ɃV<C983>X<EFBFBD>e<EFBFBD><65><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>g<EFBFBD>p
BOOL m_bScreenMode; // FALSE:Window TRUE:Fullscreen
BOOL m_bFlip; // <20>t<EFBFBD><74><EFBFBD>b<EFBFBD>v<EFBFBD>g<EFBFBD>p
BOOL m_bGDI; // GDI
BOOL m_bAspect; // TV<54>A<EFBFBD>X<EFBFBD>y<EFBFBD>N<EFBFBD>g<EFBFBD>
BOOL m_bAllLine; // <20>S<EFBFBD><53><EFBFBD>C<EFBFBD><43><EFBFBD>\<5C><>
BOOL m_bMaxZoom; // <20><><EFBFBD>ʑS<CA91>̂܂Ŋg<C58A><67>
BOOL m_bDoubleSize; // <20>Q<EFBFBD>{<7B>T<EFBFBD>C<EFBFBD>Y<EFBFBD><59><EFBFBD><EFBFBD><EFBFBD>_<EFBFBD><5F><EFBFBD><EFBFBD><EFBFBD>O
BOOL m_bTVFrameMode; // TV<54>g<EFBFBD>\<5C><>
BOOL m_bScanlineMode; // <20>X<EFBFBD>L<EFBFBD><4C><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>C<EFBFBD><43><EFBFBD><EFBFBD><EFBFBD>[<5B>h
INT m_nScanlineColor; // <20>X<EFBFBD>L<EFBFBD><4C><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>C<EFBFBD><43><EFBFBD>J<EFBFBD><4A><EFBFBD>[
BOOL m_bZapper; // Zapper
BOOL m_bZapperDraw; // Zapper Sight drawing
BOOL m_bWindowVSync; // Wait for VSync(Window mode)
BOOL m_bForceWrite; // <20><><EFBFBD>ɏ㏑<C98F><E38F91><EFBFBD>`<60><>
INT m_nBltFilter; // Blit Filter
// <20><><EFBFBD>p<EFBFBD>”\<5C>ȃf<C883>B<EFBFBD>X<EFBFBD>v<EFBFBD><76><EFBFBD>C<EFBFBD><43><EFBFBD>[<5B>h
std::vector<DISPLAYMODE> m_DisplayModes;
// <20>t<EFBFBD><74><EFBFBD>X<EFBFBD>N<EFBFBD><4E><EFBFBD>[<5B><><EFBFBD>f<EFBFBD>B<EFBFBD>X<EFBFBD>v<EFBFBD><76><EFBFBD>C<EFBFBD><43><EFBFBD>[<5B>h
DWORD m_dwDisplayWidth;
DWORD m_dwDisplayHeight;
DWORD m_dwDisplayDepth;
DWORD m_dwDisplayRate;
// DLL dynamic load
HINSTANCE m_hDDraw; // DLL Instance handle
// DirectDraw object
LPDIRECTDRAW7 m_lpDD; // DirectDraw Object
LPDIRECTDRAWSURFACE7 m_lpDDPrimary; // PrimarySurface
LPDIRECTDRAWSURFACE7 m_lpDDBack; // BackSurface
LPDIRECTDRAWSURFACE7 m_lpDDRender; // RenderSurface
LPDIRECTDRAWSURFACE7 m_lpDDRender2; // RenderSurface2
LPDIRECTDRAWSURFACE7 m_lpDDAscii; // AsciiSurface
LPDIRECTDRAWSURFACE7 m_lpDDZapper; // ZapperSurface
LPDIRECTDRAWSURFACE7 m_lpDDTV; // TV<54>g(^^;
LPDIRECTDRAWCLIPPER m_lpDDClipper; // Clipper
LPDIRECTDRAWCLIPPER m_lpDDClipper2; // Render window Clipper
LPDIRECTDRAWPALETTE m_lpDDPalette; // DirectDraw Palette
LPBYTE m_lpRender;
LPBYTE m_lpRenderDelta;
BYTE m_LineColormode[RENDER_HEIGHT];
BOOL m_bDeltaUpdate;
// <20>p<EFBFBD><70><EFBFBD>b<EFBFBD>g
INT m_nPaletteMode;
BOOL m_bMonoMode;
BOOL m_bPaletteUpdate; // Palette Update?
static PALBUF m_PalDefault[64]; // <20>f<EFBFBD>t<EFBFBD>H<EFBFBD><48><EFBFBD>g<EFBFBD>p<EFBFBD><70><EFBFBD>b<EFBFBD>g
PALBUF m_PaletteBuf[64]; // <20>p<EFBFBD><70><EFBFBD>b<EFBFBD>g<EFBFBD>o<EFBFBD>b<EFBFBD>t<EFBFBD>@
typedef struct tagLOGPAL {
WORD palVersion;
WORD palNumEntries;
PALETTEENTRY pe[256];
} LOGPAL, *LPLOGPAL;
HPALETTE m_hPalette; // Windows GDI Palette handle
LOGPAL m_logPalette; // Windows GDI Palette
// 256<35>F<EFBFBD><46><EFBFBD>[<5B>h<EFBFBD>p
RGBQUAD m_cpPalette[8][64*2]; // Color
RGBQUAD m_mpPalette[8][64*2]; // Monochrome
// <20>s<EFBFBD>N<EFBFBD>Z<EFBFBD><5A><EFBFBD>t<EFBFBD>H<EFBFBD>[<5B>}<7D>b<EFBFBD>g<EFBFBD>ɕϊ<C995><CF8A><EFBFBD><EFBFBD><EFBFBD><EFBFBD>p<EFBFBD><70><EFBFBD>b<EFBFBD>g
DWORD m_cnPalette[8][256]; // Color
DWORD m_csPalette[8][256]; // Color/Scanline
DWORD m_mnPalette[8][256]; // Monochrome
DWORD m_msPalette[8][256]; // Monochrome/Scanline
// 2xSaI mmx<6D>p<EFBFBD><70>RGB555<35>p<EFBFBD><70><EFBFBD>b<EFBFBD>g
DWORD m_cfPalette[8][256]; // Color
DWORD m_mfPalette[8][256]; // Monochrome
// For Zapper
LONG m_ZapperPosX, m_ZapperPosY;
// For Infomation&Message
enum { INFOSTR_SIZE = 64 };
CHAR m_szInfo[INFOSTR_SIZE+1];
CHAR m_szMess[INFOSTR_SIZE+1];
// For DiskAccessLamp
BOOL m_bDiskAccessLamp;
// <20>v<EFBFBD><76><EFBFBD>e<EFBFBD>N<EFBFBD>g<EFBFBD><67><EFBFBD><EFBFBD><EFBFBD>o<EFBFBD>֐<EFBFBD>
static HRESULT WINAPI EnumModesCallback( LPDDSURFACEDESC2 lpDDSurfaceDesc, LPVOID lpContext );
void RenderString( INT x, INT y, LPCSTR str );
BOOL RestoreSurfaceSub( LPDIRECTDRAWSURFACE7 lpSurface );
void GetBitMask( DWORD val, int& shift, int& bits );
void SetLZSSChar( LPBYTE lpLZ, LPDIRECTDRAWSURFACE7 lpDDSurface );
// Blitters
typedef void (CDirectDraw::*BLTFUNC)(LPBYTE,LPBYTE,DDSURFACEDESC2&,BOOL);
static BLTFUNC NormalBltTable[];
static BLTFUNC ScanlineBltTable[];
static BLTFUNC DoubleBltTable[];
static BLTFUNC DoubleScanlineBltTable[];
static BLTFUNC nx2xSaIBltTable[];
static BLTFUNC nxSuper2xSaIBltTable[];
static BLTFUNC nxSuperEagleBltTable[];
static BLTFUNC nxScale2xBltTable[];
// <20><><EFBFBD>ʁc
void Render8bpp_Normal(LPBYTE,LPBYTE,DDSURFACEDESC2&,BOOL);
void Render16bpp_Normal(LPBYTE,LPBYTE,DDSURFACEDESC2&,BOOL);
void Render24bpp_Normal(LPBYTE,LPBYTE,DDSURFACEDESC2&,BOOL);
void Render32bpp_Normal(LPBYTE,LPBYTE,DDSURFACEDESC2&,BOOL);
void Render8bpp_Scanline(LPBYTE,LPBYTE,DDSURFACEDESC2&,BOOL);
void Render16bpp_Scanline(LPBYTE,LPBYTE,DDSURFACEDESC2&,BOOL);
void Render24bpp_Scanline(LPBYTE,LPBYTE,DDSURFACEDESC2&,BOOL);
void Render32bpp_Scanline(LPBYTE,LPBYTE,DDSURFACEDESC2&,BOOL);
void Render8bpp_Double(LPBYTE,LPBYTE,DDSURFACEDESC2&,BOOL);
void Render16bpp_Double(LPBYTE,LPBYTE,DDSURFACEDESC2&,BOOL);
void Render24bpp_Double(LPBYTE,LPBYTE,DDSURFACEDESC2&,BOOL);
void Render32bpp_Double(LPBYTE,LPBYTE,DDSURFACEDESC2&,BOOL);
void Render8bpp_DoubleScanline(LPBYTE,LPBYTE,DDSURFACEDESC2&,BOOL);
void Render16bpp_DoubleScanline(LPBYTE,LPBYTE,DDSURFACEDESC2&,BOOL);
void Render24bpp_DoubleScanline(LPBYTE,LPBYTE,DDSURFACEDESC2&,BOOL);
void Render32bpp_DoubleScanline(LPBYTE,LPBYTE,DDSURFACEDESC2&,BOOL);
// <20>v<EFBFBD><76><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>_<EFBFBD>p
void Render16bpp( LPBYTE lpSrc, LPBYTE lpDst );
void Render16bppPrefilter( LPBYTE lpSrc, LPBYTE lpDst );
void Render32bpp( LPBYTE lpSrc, LPBYTE lpDst );
// Effects
void nx_2xSaI_16bpp(LPBYTE,LPBYTE,DDSURFACEDESC2&,BOOL);
void nx_2xSaI_32bpp(LPBYTE,LPBYTE,DDSURFACEDESC2&,BOOL);
void nx_Super2xSaI_16bpp(LPBYTE,LPBYTE,DDSURFACEDESC2&,BOOL);
void nx_Super2xSaI_32bpp(LPBYTE,LPBYTE,DDSURFACEDESC2&,BOOL);
void nx_SuperEagle_16bpp(LPBYTE,LPBYTE,DDSURFACEDESC2&,BOOL);
void nx_SuperEagle_32bpp(LPBYTE,LPBYTE,DDSURFACEDESC2&,BOOL);
void nx_Scale2x_16bpp(LPBYTE,LPBYTE,DDSURFACEDESC2&,BOOL);
void nx_Scale2x_32bpp(LPBYTE,LPBYTE,DDSURFACEDESC2&,BOOL);
private:
// <20>v<EFBFBD><76><EFBFBD>C<EFBFBD>x<EFBFBD>[<5B>g<EFBFBD><67><EFBFBD><EFBFBD><EFBFBD>o<EFBFBD>ϐ<EFBFBD>
// <20>v<EFBFBD><76><EFBFBD>C<EFBFBD>x<EFBFBD>[<5B>g<EFBFBD><67><EFBFBD><EFBFBD><EFBFBD>o<EFBFBD>֐<EFBFBD>
};
extern CDirectDraw DirectDraw;
#endif // !__DIRECTDRAW_INCLUDED__