亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? gfx.cpp

?? nes游戲模擬器
?? CPP
?? 第 1 頁 / 共 3 頁
字號:
//------------------------------------------------------------------------------
// Name: Gfx.cpp
// Desc: Holds all the graphics related functions. This includes drawing
//       scanlines, directx stuff, etc.
//------------------------------------------------------------------------------

#include "Gfx.h"
#include "Palette.h"
#include "AttributeTable.h"

// Global array of colors.
BYTE abyColors[NUMBER_OF_COLORS][4];

// DirectDraw Surfaces used for the graphics engine.
LPDIRECTDRAW7        lpDD;
LPDIRECTDRAWSURFACE7 lpddsPrimary;
LPDIRECTDRAWSURFACE7 lpddsBack;
LPDIRECTDRAWSURFACE7 lpddsScreen;
LPDIRECTDRAWCLIPPER  lpClipper;
RECT                 rcScreen;

BYTE* pSurfaceMemory; // Pointer to our locked memory to draw our pixels on.
LONG  lBytesPerPixel; // Number of bytes per pixel.
LONG  FourMinusBPP;   // 4 - Number of bytes per pixel (to speed up putpixel loop).
LONG  lSurfacePitch;  // The pitch of the scanline use to move to the next line.

//------------------------------------------------------------------------------
// Name: CreateDirectDraw()
// Desc: Creates DirectDraw and all the surfaces and sets up the colors
//       array with the paletted nes colors.
//------------------------------------------------------------------------------
HRESULT CreateDirectDraw(HWND hwnd)
{
	DDSURFACEDESC2 ddsd;
	DDPIXELFORMAT DDpf;  // DirectDraw pixel format structure.
	HRESULT ddrval;
	RECT rcClient;
   
	// Create the main DirectDraw object.
	ddrval = DirectDrawCreateEx(NULL, (VOID**)&lpDD, IID_IDirectDraw7, NULL);
	if(ddrval != DD_OK)
		return FALSE;

	// Using DDSCL_NORMAL means we will coexist with GDI.
	ddrval = lpDD->SetCooperativeLevel(hwnd, DDSCL_NORMAL);
	if(ddrval != DD_OK)
	{
		lpDD->Release();
		return FALSE;
	}
	
	memset(&ddsd, 0, sizeof(ddsd));
	ddsd.dwSize = sizeof(ddsd);
	ddsd.dwFlags = DDSD_CAPS;
	ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;

	// The primary surface is not a page flipping surface.
	ddrval = lpDD->CreateSurface(&ddsd, &lpddsPrimary, NULL);
	if (ddrval != DD_OK)
	{
		lpDD->Release();
		return FALSE;
	}

	// Create a clipper to ensure that our drawing stays inside our window.
	ddrval = lpDD->CreateClipper(0, &lpClipper, NULL);
	if (ddrval != DD_OK)
	{
		lpddsPrimary->Release();
		lpDD->Release();
		return FALSE;
	}

	// Setting it to our hwnd gives the clipper the coordinates from our window.
	ddrval = lpClipper->SetHWnd(0, hwnd);
	if (ddrval != DD_OK)
	{
		lpClipper-> Release();
		lpddsPrimary->Release();
		lpDD->Release();
		return FALSE;
	}

	// Attach the clipper to the primary surface.
	ddrval = lpddsPrimary->SetClipper(lpClipper);
	if (ddrval != DD_OK)
	{
		lpClipper-> Release();
		lpddsPrimary->Release();
		lpDD->Release();
		return FALSE;
	}

	GetClientRect(hwnd, &rcClient);
	memset(&ddsd, 0, sizeof(ddsd));
	ddsd.dwSize = sizeof(ddsd);
	ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
	ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
	ddsd.dwWidth = rcClient.right - rcClient.left;
	ddsd.dwHeight = rcClient.bottom - rcClient.top;

	// Create the backbuffer separately.
	ddrval = lpDD->CreateSurface(&ddsd, &lpddsBack, NULL);
	if (ddrval != DD_OK)
	{
		lpClipper-> Release();
		lpddsPrimary->Release();
		lpDD->Release();
		return FALSE;
	}
	
	ddsd.dwWidth = SCREEN_WIDTH;
	ddsd.dwHeight = SCREEN_HEIGHT;

	// Create the offscreen surface for drawing our screen to.
	ddrval = lpDD->CreateSurface(&ddsd, &lpddsScreen, NULL);
	if (ddrval != DD_OK)
	{
		lpClipper-> Release();
		lpddsPrimary->Release();
		lpddsBack->Release();
		lpDD->Release();
		return FALSE;
	}

	// Fill the DDpf structure and get the number of bytes per pixel.
	ZeroMemory(&DDpf, sizeof(DDpf));
	DDpf.dwSize = sizeof(DDpf);
	lpddsScreen->GetPixelFormat(&DDpf);
	
	// Save the number of bytes per pixel and 4 - the number of bytes
	// per pixel to speed things up when drawing pixels.
	lBytesPerPixel = DDpf.dwRGBBitCount / 8;
	FourMinusBPP = 4 - lBytesPerPixel;

	// Compile all the pixels.
	for (int i = 0; i < NUMBER_OF_COLORS; i++)
		CompilePixel(lpddsScreen, i, abyNESPalette[(3*i)], abyNESPalette[(3*i)+1], abyNESPalette[(3*i)+2]);

	return TRUE;
} // end CreateDirectDraw()


//------------------------------------------------------------------------------
// Name: DestroyDirectDraw()
// Desc: Cleans up everything that was initialized for DirectDdraw.
//------------------------------------------------------------------------------
HRESULT DestroyDirectDraw()
{
	if(lpDD != NULL)
	{
		if (lpddsPrimary != NULL)
		{
			lpddsPrimary->Release();
			lpddsPrimary = NULL;
		}
		if (lpddsBack != NULL)
		{
			lpddsBack->Release();
			lpddsBack = NULL;
		}
		if (lpddsScreen != NULL)
		{
			lpddsScreen->Release();
			lpddsScreen = NULL;
		}
		if (lpClipper != NULL)
		{
			lpClipper->Release();
			lpClipper = NULL;
		}

		lpDD->Release();
		lpDD = NULL;
	}

	return DD_OK;
} // end DestroyDirectDraw()


//------------------------------------------------------------------------------
// Name: Flip()
// Desc: Blts the nes screen surface to the back surface and then flips
//       the back surface and the primary if in full screen mode. If in
//       windowed mode, it blts the back surface to the primary surface
//       instead of fliping them.
//------------------------------------------------------------------------------
VOID Flip()
{
	//lpddsBack->Blt(NULL, lpddsScreen, NULL, DDBLT_WAIT, NULL);
	//lpddsPrimary->Blt(NULL, lpddsBack, NULL, DDBLT_WAIT, NULL);
	lpddsPrimary->Blt(&rcScreen, lpddsScreen, NULL, DDBLT_WAIT, NULL);
} // end Flip()


//------------------------------------------------------------------------------
// Name: BeginDrawing()
// Desc: Clears the surface to the background color, locks the surface and
//       sets up the pointer to the video memory.
//------------------------------------------------------------------------------
HRESULT BeginDrawing()
{
	HRESULT ddrval;
	DDSURFACEDESC2 ddsdLockedSurf; // Surface description to lock our surface.

	// Clear to the background color which is located in bits 7-5 in reg $2001
	// when bit 0 is set, otherwise is the first entry in the background palette.
	//BYTE byColorIndex = ((CPU.Memory[0x2001] & 0xE0) >> 5) * 3;
	//ClearScreen(RGB(abyNESPalette[byColorIndex], 0, 0));
	ClearScreen(RGB(0, 0, 0));
	
	// Lock the surface.
	ddsdLockedSurf.dwSize = sizeof(DDSURFACEDESC2);
	ddrval = lpddsScreen->Lock(NULL, &ddsdLockedSurf, DDLOCK_WAIT | DDLOCK_NOSYSLOCK, NULL);
	if (ddrval == DD_OK)
	{
		// Initialize the pointer to surface memory to point to the
		// beginning of our scanline.
		pSurfaceMemory = (BYTE*)ddsdLockedSurf.lpSurface;

		// Save the pitch of the surface for later use in other functions.
		lSurfacePitch = ddsdLockedSurf.lPitch;
	}

	return ddrval;
} // end BeginDrawing()


//------------------------------------------------------------------------------
// Name: EndDrawing()
// Desc: Unlocks the drawing surface and flips the surfaces.
//------------------------------------------------------------------------------
VOID EndDrawing()
{
	// Unlock the drawing surface.
	lpddsScreen->Unlock(NULL);

	// Flip the surfaces to display what we've drawn.
	Flip();
} // end EndDrawing()


//------------------------------------------------------------------------------
// Name: DrawScanline()
// Desc: The main routine for drawing a scanline. Locks and unlocks the
//       surface and calls the scanline drawing routing for the type
//       of mirroring.
//------------------------------------------------------------------------------
VOID DrawScanline()
{
	// Save the pointer to video memory so we don't permanently modify it.
	BYTE* pTemp = pSurfaceMemory;
	// Now move the pointer to surface memory to the correct scanline.
	pSurfaceMemory += (lSurfacePitch * wScanline);

	// Draw our scanline if its enabled.
	if (CPU.Memory[0x2001] & 0x08)
		DrawScanlineH();

	// Draw all the sprites that are on the scanline if they are enabled.
	//if (CPU.Memory[0x2001] & 0x10)
	//	DrawScanlineSprites();

	// Restore our pointer to memory.
	pSurfaceMemory = pTemp;
} // end DrawScanline()


//------------------------------------------------------------------------------
// Name: DrawScanlineH()
// Desc: Draws a scanline using horizontal mirroring.
//------------------------------------------------------------------------------
VOID DrawScanlineH()
{
	BYTE*  pabyNameTables;
	BYTE*  pbyNameTableTile;
	BYTE*  pbyAttributeTable;
	BYTE*  pbyCurPatternTableAddr;
	BYTE   byCounter = 8;
	BYTE   byUpperColor = 0;
	WORD   wTileNum = 0;
	WORD   wBegTileNum = 0;
	WORD   relx = byHScroll[0];
	WORD   x = 0;
	DWORD  byScanlineMOD8 = wScanline % 8;

	__asm
	{
		// Save the registers
		pushad
	
		// The pointer to the current nametable tile will always
		// start with the first name table.
		
		// Get the bits that determine what nametable to use.
		xor ebx, ebx
		mov bl, [CPU.Memory+02000h]
		and bl, 03
		
		// Get the address of the name table and save it for later.
		lea eax, [PPU.apbyNameTables+ebx*4]
		mov pabyNameTables, eax

		// Get the pointer to the current name table and store
		// it in the variables for later. Also, store the
		// the attribute table.
		mov eax, [eax]
		mov pbyNameTableTile, eax
		mov pbyAttributeTable, eax
		add eax, 03C0h
		mov pbyAttributeTable, eax

		// Get the address of the background pattern table
		xor ebx, ebx
		mov bl, BYTE PTR [CPU.Memory+02000h]   // Address of the PPU control register #1
		and bl, PATTERN_TABLE_ADDRESS
		shr bx, 2                              // Which pattern table (0,1)
		mov ebx, [PPU.apbyPatternTables+ebx]   // Move the address of the pattern table array into ebx
		mov pbyCurPatternTableAddr, ebx        // Save the address of the pattern table for later

		//--------------------------------------------------------
		// Get the address of the tile number in the ppu memory
		// by (TILENUM * 16) + PATTERNTABLE (Yoshi)
		//--------------------------------------------------------

		and eax, 000000FFh
		mov ax, wScanline
		mov cx, relx

		// TILENUM = ((Scanline / 8) * 32) + (HScroll / 8)
		shr ax, 3        // Scanline / 8
		shl ax, 5        // Multiply by 32

		// Save the beginning tile number so we don't have
		// to recalculate it when we change name tables.
		mov wBegTileNum, ax

		shr cx, 3        // HScroll / 8
		add ax, cx       // ax=TILENUM
		
		// Save the tile number so we can increment it.
		mov wTileNum, ax

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲精品日韩专区silk| 色婷婷综合久久久久中文 | 亚洲久草在线视频| 国产精品视频九色porn| 国产日韩欧美不卡在线| 欧美成人一区二区三区片免费| 欧美日韩一卡二卡| 在线播放国产精品二区一二区四区| 日本韩国欧美三级| 欧美少妇xxx| 日韩欧美电影一二三| 日韩三级av在线播放| 精品久久久久久久人人人人传媒| 欧美刺激午夜性久久久久久久| 欧美xxx久久| 国产精品视频一区二区三区不卡| 中文字幕av一区二区三区高 | 亚洲另类春色国产| 一区二区三区四区在线播放| 亚洲大片免费看| 日本不卡一区二区三区高清视频| 日韩高清不卡在线| 国产乱理伦片在线观看夜一区| 国产精品一区二区在线观看不卡| av福利精品导航| 在线亚洲欧美专区二区| 日韩一级片在线观看| 中文字幕不卡在线观看| 亚洲一区二区三区小说| 蜜桃av一区二区三区电影| 另类小说图片综合网| 成人自拍视频在线| 欧美日韩一区二区三区高清| 精品国产91亚洲一区二区三区婷婷| 中文字幕第一区二区| 天堂影院一区二区| 不卡电影免费在线播放一区| 欧美在线影院一区二区| 精品国产3级a| 亚洲国产日日夜夜| 粉嫩av一区二区三区在线播放 | 精品在线免费观看| 91视频.com| 久久久久久免费| 亚洲精品videosex极品| 国模冰冰炮一区二区| 在线视频国内自拍亚洲视频| 日韩欧美中文字幕制服| 一区二区三区四区av| 激情久久五月天| 精品1区2区3区| 国产精品久久久久久一区二区三区| 日日夜夜免费精品| 一本色道久久综合亚洲aⅴ蜜桃| 欧美成人精品1314www| 亚洲午夜视频在线观看| 99re热视频这里只精品| 亚洲国产视频一区二区| 99久久99久久精品国产片果冻 | 成人免费在线观看入口| 久久国产精品99精品国产| 欧美综合亚洲图片综合区| 日本一区二区成人在线| 国产精品一二三四五| 欧美成人女星排名| 人禽交欧美网站| 欧美日本韩国一区二区三区视频| 亚洲精品中文字幕乱码三区| 成人永久aaa| 国产女人18水真多18精品一级做 | 亚洲少妇30p| 从欧美一区二区三区| 国产午夜亚洲精品羞羞网站| 加勒比av一区二区| 欧美videos中文字幕| 蜜臀精品久久久久久蜜臀| 日韩一级片在线观看| 美国精品在线观看| 日韩精品一区二区三区视频播放| 免费高清视频精品| 欧美变态tickle挠乳网站| 久久精品国产999大香线蕉| 日韩天堂在线观看| 加勒比av一区二区| 国产亲近乱来精品视频| www.av精品| 亚洲精品免费视频| 欧美伊人久久久久久午夜久久久久| 亚洲女爱视频在线| 欧美成人猛片aaaaaaa| 国内一区二区视频| 国产欧美日韩在线| 91婷婷韩国欧美一区二区| 亚洲伊人伊色伊影伊综合网| 欧美日韩国产精品自在自线| 麻豆精品国产传媒mv男同| 久久久夜色精品亚洲| 99综合影院在线| 亚洲国产成人tv| 精品久久久久久久人人人人传媒 | 亚洲免费视频成人| 欧美日韩视频在线第一区| 婷婷六月综合亚洲| 欧美精品一区二区三区一线天视频| 国产精品夜夜爽| 亚洲欧美激情小说另类| 欧美一区二区视频免费观看| 国产精品一区二区在线观看网站| 综合欧美亚洲日本| 欧美一区二区三区四区五区 | 国产精品视频第一区| 日本精品视频一区二区| 蜜桃视频在线观看一区二区| 国产三级一区二区| 色综合久久综合网欧美综合网| 国产成人亚洲精品青草天美| 亚洲精品欧美激情| 久久久久久97三级| 色哟哟亚洲精品| 九九国产精品视频| 国产精品不卡一区二区三区| 91.com视频| 色久综合一二码| 捆绑调教美女网站视频一区| 中文字幕精品一区| 欧美一级二级三级蜜桃| 91麻豆国产在线观看| 国产精品2024| 蜜臀久久久久久久| 亚洲综合激情网| 国产精品久久网站| 久久五月婷婷丁香社区| 欧美日韩国产中文| 97se亚洲国产综合自在线不卡| 日韩国产欧美在线播放| 亚洲欧洲精品一区二区三区不卡| 欧美精品久久99| 色婷婷一区二区| 处破女av一区二区| 久久99这里只有精品| 国产精品国产精品国产专区不片| 欧美一区二区三区在线电影| 色哟哟一区二区在线观看| 国产91精品入口| 国产一区二区三区蝌蚪| 久久精品国产一区二区三区免费看 | 中文字幕av一区二区三区免费看 | 丝袜诱惑亚洲看片 | 日韩免费电影网站| 欧美性videosxxxxx| 91婷婷韩国欧美一区二区| 成人久久久精品乱码一区二区三区| 国产一区二区三区免费播放| 国产综合成人久久大片91| 国产真实乱对白精彩久久| 韩国一区二区在线观看| 免费观看成人鲁鲁鲁鲁鲁视频| 免费日韩伦理电影| 蜜臀99久久精品久久久久久软件| 日韩国产一二三区| 狠狠色狠狠色综合| 国产成人精品免费视频网站| 国产精品18久久久久| 国产ts人妖一区二区| av一区二区三区黑人| 色综合久久久久久久久久久| 91久久一区二区| 91.成人天堂一区| 久久久综合激的五月天| 国产色综合久久| 亚洲欧美日韩中文播放 | 99精品偷自拍| 欧美日韩精品专区| 亚洲成人免费视频| 久久综合九色欧美综合狠狠| 日韩视频免费观看高清完整版在线观看 | 国产成人精品免费一区二区| 日韩一区二区三区精品视频| 成人性生交大合| 国产精品资源网| 97久久超碰国产精品| 欧美日韩亚洲另类| 欧美v日韩v国产v| 最新成人av在线| 蜜臀a∨国产成人精品| 国产+成+人+亚洲欧洲自线| 91久久香蕉国产日韩欧美9色| 69久久99精品久久久久婷婷| 久久精品男人天堂av| 亚洲一区二区三区三| 免费观看一级欧美片| av一区二区三区在线| 欧美一区日本一区韩国一区| 亚洲美女精品一区| 久久精品国产精品青草| 91成人网在线| 国产三级精品视频| 首页欧美精品中文字幕| 成人网在线播放| 日韩一区二区精品葵司在线 |