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

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? 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

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲丝袜自拍清纯另类| 99r国产精品| 精品少妇一区二区三区视频免付费 | 五月综合激情网| 777午夜精品视频在线播放| 日韩中文字幕亚洲一区二区va在线| 欧美日韩中文字幕一区二区| 亚洲chinese男男1069| 欧美一级在线视频| 国产原创一区二区三区| 欧美国产禁国产网站cc| 99精品黄色片免费大全| 亚州成人在线电影| www国产精品av| 96av麻豆蜜桃一区二区| 亚洲制服丝袜av| 日韩一卡二卡三卡四卡| 成人性生交大片免费看中文| ㊣最新国产の精品bt伙计久久| 欧美亚洲国产一区二区三区va| 男人的j进女人的j一区| 国产精品美女一区二区三区| 91国偷自产一区二区使用方法| 日韩精品亚洲专区| 久久精品视频在线看| 日本高清成人免费播放| 麻豆成人久久精品二区三区红| 久久精品夜夜夜夜久久| 欧美视频三区在线播放| 狠狠色综合播放一区二区| 亚洲三级在线免费观看| 欧美成人r级一区二区三区| jlzzjlzz亚洲日本少妇| 人人狠狠综合久久亚洲| 国产精品久久久久影院亚瑟| 91麻豆精品91久久久久同性| 成人精品gif动图一区| 天堂va蜜桃一区二区三区漫画版| 久久精品视频免费观看| 欧美三级日韩三级国产三级| 国产成人啪午夜精品网站男同| 亚洲动漫第一页| 国产精品私人自拍| 日韩欧美亚洲国产精品字幕久久久 | 国产精品嫩草99a| 日韩欧美黄色影院| 在线观看免费亚洲| 福利91精品一区二区三区| 青草国产精品久久久久久| 一区在线中文字幕| 久久久不卡网国产精品一区| 久久在线免费观看| 精品1区2区3区| 不卡的av电影| 韩国在线一区二区| 日韩高清在线电影| 一区二区三区美女视频| 国产精品久久久久久久久动漫 | 久久影院视频免费| 337p亚洲精品色噜噜狠狠| 在线免费不卡视频| 99久久综合狠狠综合久久| 国产精品一区二区在线观看不卡 | 最新中文字幕一区二区三区| 精品国免费一区二区三区| 欧美一级视频精品观看| 欧美日韩精品电影| 色999日韩国产欧美一区二区| 粉嫩aⅴ一区二区三区四区五区| 狠狠色伊人亚洲综合成人| 日韩电影一区二区三区四区| 亚洲小说春色综合另类电影| 一区二区三区视频在线观看| 亚洲欧洲制服丝袜| 亚洲丝袜美腿综合| 中文字幕欧美一| 国产精品―色哟哟| 国产亚洲欧美一区在线观看| 在线亚洲免费视频| 一本到不卡免费一区二区| 大胆亚洲人体视频| 波多野结衣视频一区| 国产精品小仙女| 国模冰冰炮一区二区| 久久se这里有精品| 蜜臀av一区二区在线观看 | 国产午夜精品理论片a级大结局| 日韩西西人体444www| 欧美日韩一区二区电影| 欧美丝袜丝nylons| 欧亚一区二区三区| 欧洲精品在线观看| 欧美图区在线视频| 欧美撒尿777hd撒尿| 一本大道av一区二区在线播放| 在线亚洲一区观看| 91福利精品视频| 欧美视频在线播放| 欧美性受极品xxxx喷水| 欧美日韩另类国产亚洲欧美一级| 欧美图区在线视频| 欧美在线不卡一区| 日韩一级片在线观看| 欧美成人精精品一区二区频| 欧美videos大乳护士334| 精品国产乱码久久久久久免费| 精品国产电影一区二区| 久久久久久久久一| 椎名由奈av一区二区三区| 午夜欧美视频在线观看| 首页亚洲欧美制服丝腿| 日韩av不卡在线观看| 国产精品白丝av| 欧美一区二区日韩| 26uuu色噜噜精品一区二区| 欧美高清精品3d| 日韩欧美一区二区免费| 国产女人18毛片水真多成人如厕| 中文字幕中文在线不卡住| 亚洲影视在线播放| 久久激情五月婷婷| zzijzzij亚洲日本少妇熟睡| 欧美自拍偷拍一区| 欧美xxxx在线观看| 国产精品福利在线播放| 图片区日韩欧美亚洲| 国产成人亚洲综合a∨婷婷 | 国产一区二区免费在线| 91小视频在线| 欧美电影一区二区| 亚洲精品视频免费观看| 日本欧美大码aⅴ在线播放| 91色综合久久久久婷婷| 制服丝袜亚洲色图| 亚洲欧美日韩国产另类专区| 亚洲成av人在线观看| 国产99久久久国产精品| 国产麻豆精品久久一二三| 在线视频一区二区免费| 欧美日韩aaa| 中文字幕中文字幕在线一区| 日本午夜一本久久久综合| 不卡欧美aaaaa| 欧美哺乳videos| 亚洲一区视频在线| 成人影视亚洲图片在线| 在线91免费看| 亚洲精品第1页| 国产精品66部| 91精品国产乱码久久蜜臀| 精品国产一区二区三区久久久蜜月 | 成人涩涩免费视频| 在线看不卡av| 亚洲免费观看高清| 成人一区二区三区视频在线观看| 69久久夜色精品国产69蝌蚪网| 久久网站热最新地址| 免费看黄色91| 欧美日韩亚州综合| 中文字幕人成不卡一区| 男男视频亚洲欧美| 欧美三级三级三级| 亚洲精品久久7777| 99视频在线观看一区三区| 风流少妇一区二区| 中文成人av在线| 日韩国产成人精品| 国产性做久久久久久| 蜜桃av一区二区| 欧美一区二区日韩| 天天色天天操综合| 欧美日韩一区二区三区免费看| 欧美激情一区二区三区蜜桃视频| 久久不见久久见免费视频7| 91精品国产品国语在线不卡| 亚洲444eee在线观看| 国产乱人伦偷精品视频免下载 | 欧美在线一二三| 亚洲视频一二三| www.66久久| 综合在线观看色| 欧美日韩成人一区二区| 亚洲va韩国va欧美va| 欧美午夜在线一二页| 国产日韩视频一区二区三区| 国产一区二区剧情av在线| 欧美日韩免费观看一区三区| 亚洲自拍欧美精品| 欧美在线色视频| 亚洲第一综合色| 欧美精品久久一区| 免费成人美女在线观看| 91麻豆精品国产| 开心九九激情九九欧美日韩精美视频电影| 欧美一区二区三区婷婷月色| 奇米影视在线99精品| 欧美一区二区三区白人| 激情文学综合插| 国产精品福利一区| 成人黄色在线视频|