asm 调用 d3d例子(一)

整理资源时发现的,大约3年多前,正好有段时间比较空,于是用asm调用d3d,实现了directx9.x的sdk附带的几个例子,使用masm32编译。

第一个例子,空项目。
源代码:
EmptyProject.Asm:

.386
.model flat,stdcall
 option casemap:none
WIN32_LEAN_AND_MEAN     equ 1
WINDOW_WIDTH        EQU 640
WINDOW_HEIGHT       EQU 480
S_OK			     EQU  0L
DXUTCACHE_LOCATION_FILE EQU 0
DXUTCACHE_LOCATION_RESOURCE EQU DXUTCACHE_LOCATION_FILE+1
include windows.inc
include d3d9.inc
include d3d9types.inc
include d3d9caps.inc
include dxerr9.inc
include d3dx9.inc
include ./DxUTmisc.inc
include ./DXUT.inc
include ./DXUTenum.inc

includelib kernel32.lib
includelib advapi32.lib
includelib gdi32.lib
includelib user32.lib
includelib msvcrt.lib

includelib d3d9.lib
includelib dxerr9.lib
includelib d3dx9.lib

LPCD3DEnumeration typedef ptr CD3DEnumeration

DXUTCALLBACKTIMER typedef proto FAR PASCAL idEvent:UINT, pUserContext:PVOID
LPDXUTCALLBACKTIMER typedef ptr DXUTCALLBACKTIMER

CGrowableArray DXUTCache_Texture
CGrowableArray DXUTCache_Effect
CGrowableArray DXUTCache_Font
CGrowableArray DXUT_TIMER
LPDXUTDeviceSettings typedef ptr DXUTDeviceSettings
DXUTCALLBACKISDEVICEACCEPTABLE typedef proto FAR PASCAL pCaps:ptr D3DCAPS9,\
	 AdapterFormat:D3DFORMAT, BackBufferFormat:D3DFORMAT, bWindowed:BOOL, pUserContext:PVOID
LPDXUTCALLBACKISDEVICEACCEPTABLE typedef ptr LPDXUTCALLBACKISDEVICEACCEPTABLE

DXUTCALLBACKMODIFYDEVICESETTINGS typedef proto FAR PASCAL pDeviceSettings:ptr DXUTDeviceSettings, 
	pCaps:D3DCAPS9, pUserContext:PVOID
LPDXUTCALLBACKMODIFYDEVICESETTINGS typedef ptr DXUTCALLBACKMODIFYDEVICESETTINGS

DXUTCALLBACKDEVICECREATED typedef proto FAR PASCAL pd3dDevice:IDirect3DDevice9, \
	pBackBufferSurfaceDesc:D3DSURFACE_DESC, pUserContext:PVOID
LPDXUTCALLBACKDEVICECREATED typedef ptr DXUTCALLBACKDEVICECREATED

DXUTCALLBACKDEVICERESET typedef proto FAR PASCAL pd3dDevice:ptr IDirect3DDevice9, \
	pBackBufferSurfaceDesc:D3DSURFACE_DESC, pUserContext:PVOID
LPDXUTCALLBACKDEVICERESET typedef ptr DXUTCALLBACKDEVICERESET

DXUTCALLBACKDEVICELOST typedef proto FAR PASCAL pUserContext:PVOID
LPDXUTCALLBACKDEVICELOST typedef ptr DXUTCALLBACKDEVICELOST

DXUTCALLBACKDEVICEDESTROYED typedef proto FAR PASCAL pUserContext:PVOID
LPDXUTCALLBACKDEVICEDESTROYED typedef ptr DXUTCALLBACKDEVICEDESTROYED

DXUTCALLBACKFRAMEMOVE typedef proto FAR PASCAL pd3dDevice:ptr IDirect3DDevice9, fTime:REAL8,\
	 fElapsedTime:REAL4, pUserContext:PVOID
LPDXUTCALLBACKFRAMEMOVE typedef ptr DXUTCALLBACKFRAMEMOVE

DXUTCALLBACKFRAMERENDER typedef proto FAR PASCAL pd3dDevice:ptr IDirect3DDevice9, fTime:REAL8, fElapsedTime:REAL4, \
	pUserContext:PVOID
LPDXUTCALLBACKFRAMERENDER typedef ptr DXUTCALLBACKFRAMERENDER

DXUTCALLBACKKEYBOARD typedef proto FAR PASCAL nChar:UINT, bKeyDown:BOOL, bAltDown:BOOL, pUserContext:PVOID
LPDXUTCALLBACKKEYBOARD typedef ptr DXUTCALLBACKKEYBOARD

DXUTCALLBACKMOUSE typedef proto FAR PASCAL bLeftButtonDown:BOOL, bRightButtonDown:BOOL,\
	bMiddleButtonDown:BOOL, bSideButton1Down:BOOL, bSideButton2Down:BOOL, \
	nMouseWheelDelta:DWORD, xPos:DWORD, yPos:DWORD, pUserContext:PVOID
LPDXUTCALLBACKMOUSE typedef ptr DXUTCALLBACKMOUSE

DXUTCALLBACKMSGPROC typedef proto FAR PASCAL hWnd:HWND, uMsg:UINT, wParam:WPARAM, \
	lParam:LPARAM, pbNoFurtherProcessing:ptr BOOL, pUserContext:PVOID
LPDXUTCALLBACKMSGPROC typedef ptr DXUTCALLBACKMSGPROC
CGrowableArray D3DFORMAT
CGrowableArray D3DMULTISAMPLE_TYPE
CGrowableArray UINT
CGrowableArray LPCD3DEnumAdapterInfo


CD3DEnumeration struct
	m_pD3D LPDIRECT3D9 ?
	m_IsDeviceAcceptableFunc LPDXUTCALLBACKISDEVICEACCEPTABLE ?
	m_pIsDeviceAcceptableFuncUserContext LPVOID ?
	m_bRequirePostPixelShaderBlending BOOL ?
	CGrowableArray_D D3DFORMAT, m_DepthStecilPossibleList
;	m_DepthStecilPossibleList CGrowableArray ?
	CGrowableArray_D D3DMULTISAMPLE_TYPE, m_MultiSampleTypeList
;	m_MultiSampleTypeList CGrowableArray ?
	CGrowableArray_D UINT, m_PresentIntervalList
;	m_PresentIntervalList CGrowableArray ?
	m_bSoftwareVP BOOL ?
	m_bHardwareVP BOOL ?
	m_bPureHarewareVP BOOL ?
	m_bMixedVP BOOL ?
	m_nMinWidth UINT ?
	m_nMaxWidth UINT ?
	m_nMinHeight UINT ?
	m_nMaxHeight UINT ?
	m_nRefreshMin UINT ?
	m_nRefreshMax UINT ?
	m_nMultisampleQualityMax UINT ?
	CGrowableArray_D LPCD3DEnumAdapterInfo,m_AdapterInfoList
;	m_AdapterInfoList CGrowableArray< ptr CD3DEnumAdapterInfo> ?
CD3DEnumeration ends

DXUT_TIMER struct
	pCallbackTimer LPDXUTCALLBACKTIMER ?
	pCallbackUserContext PVOID ?
	fTimeoutInSecs REAL4 ?
	fCountdown REAL4 ?
	bEnabled BOOL ?
	nID UINT ?
DXUT_TIMER ends

DXUTDeviceSettings struct
	AdapterOrdinal UINT ?
	DeviceType D3DDEVTYPE <>
	AdapterFormat D3DFORMAT <>
	BehaviorFlags DWORD ?
	pp D3DPRESENT_PARAMETERS <>
DXUTDeviceSettings ends

STATE struct
		m_D3D LPDIRECT3D9 ?
		m_D3DDevice LPDIRECT3DDEVICE9 ?
		m_D3DEnumeration LPCD3DEnumeration ?
;		m_D3DEnumeration ptr CD3DEnumeration ?
		m_CurrentDeviceSettings LPDXUTDeviceSettings ?
;		m_CurrentDeviceSettings ptr DXUTDeviceSettings ?
		m_BackBufferSurfaceDesc D3DSURFACE_DESC <>
		m_Caps D3DCAPS9 <>
		m_HWNDFocus HWND ?
		m_HWNDDeviceFullScreen HWND ?
		m_HWNDDeviceWindowed HWND ?
		m_AdapterMonitor HMONITOR ?
		m_Menu HMENU ?
		m_FullScreenBackBufferWidthAtModeChange UINT ?
		m_FullScreenBackBufferHeightAtModeChange UINT ?
		m_WindowBackBufferWidthAtModeChange UINT ?
		m_WindowBackBufferHeightAtModeChange UINT ?
		m_WindowedStyleAtModeChange DWORD ?
		m_WindowedPlacement WINDOWPLACEMENT <>
		m_TopmostWhileWindowed BOOL ?
		m_Minimized BOOL ?
		m_Maximized BOOL ?
		m_MinimizedWhileFullscreen BOOL ?
		m_IgnoreSizeChange BOOL ?
		m_Time REAL8 ?
		m_AbsoluteTime REAL8 ?
		m_ElapsedTime REAL4 ?
		m_HInstance HINSTANCE ?
		m_LastStatsUpdateTime REAL8 ?
		m_LastStatsUpdateFrames DWORD ?
		m_FPS REAL4 ?
		m_CurrentFrameNumber DWORD ?
		m_KeyboardHook HHOOK ?
		m_AllowShortcutKeysWhenFullscreen BOOL ?
		m_AllowShortcutKeysWhenWindowed BOOL ?
		m_AllowShortcutKeys BOOL ?
		m_CallDefWindowProc BOOL ?
		m_StartupStickyKeys STICKYKEYS <>
		m_StartupToggleKeys TOGGLEKEYS <>
		m_StartupFilterKeys FILTERKEYS <>
		m_HandleDefaultHotkeys BOOL ?
		m_HandleAltEnter BOOL ?
		m_ShowMsgBoxOnError BOOL ?
		m_NoStats BOOL ?
		m_ClipCursorWhenFullScreen BOOL ?
		m_ShowCursorWhenFullScreen BOOL ?
		m_ConstantFrameTime BOOL ?
		m_TimePerFrame REAL4 ?
		m_WireframeMode BOOL ?
		m_AutoChangeAdapter BOOL ?
		m_WindowCreatedWithDefaultPositions BOOL ?
		m_ExitCode DWORD ?
		m_DXUTInited BOOL ?
		m_WindowCreated BOOL ?
		m_DeviceCreated BOOL ?
		m_DXUTInitCalled BOOL ?
		m_WindowCreateCalled BOOL ?
		m_DeviceCreateCalled BOOL ?
		m_DeviceObjectsCreated BOOL ?
		m_DeviceObjectsReset BOOL ?
		m_InsideDeviceCallback BOOL ?
		m_InsideMainloop BOOL ?
		m_Active BOOL ?
		m_TimePaused BOOL ?
		m_RenderingPaused BOOL ?
		m_PauseRenderingCount DWORD ?
		m_PauseTimeCount DWORD ?
		m_DeviceLost BOOL ?
		m_NotifyOnMouseMove BOOL ?
		m_Automation BOOL ?
		m_InSizeMove BOOL ?
		m_TimerLastID UINT ?
		m_OverrideAdapterOrdinal DWORD ?
		m_OverrideWindowed BOOL ?
		m_OverrideFullScreen BOOL ?
		m_OverrideStartX DWORD ?
		m_OverrideStartY DWORD ?
		m_OverrideWidth DWORD ?
		m_OverrideHeight DWORD ?
		m_OverrideForceHAL BOOL ?
		m_OverrideForceREF BOOL ?
		m_OverrideForcePureHWVP BOOL ?
		m_OverrideForceHWVP BOOL ?
		m_OverrideForceSWVP BOOL ?
		m_OverrideConstantFrameTime BOOL ?
		m_OverrideConstantTimePerFrame REAL4 ?
		m_OverrideQuitAfterFrame DWORD ?
		m_OverrideForceVsync DWORD ?
		m_OverrideRelaunchMCE BOOL ?
		m_IsDeviceAcceptableFunc LPDXUTCALLBACKISDEVICEACCEPTABLE ?
		m_ModifyDeviceSettingsFunc LPDXUTCALLBACKMODIFYDEVICESETTINGS ?
		m_DeviceCreatedFunc LPDXUTCALLBACKDEVICECREATED ?
		m_DeviceResetFunc LPDXUTCALLBACKDEVICERESET ?
		m_DeviceLostFunc LPDXUTCALLBACKDEVICELOST ?
		m_DeviceDestroyedFunc LPDXUTCALLBACKDEVICEDESTROYED ?
		m_FrameMoveFunc LPDXUTCALLBACKFRAMEMOVE ?
		m_FrameRenderFunc LPDXUTCALLBACKFRAMERENDER ?
		m_KeyboardFunc LPDXUTCALLBACKKEYBOARD ?
		m_MouseFunc LPDXUTCALLBACKMOUSE ?
		m_WindowMsgFunc LPDXUTCALLBACKMSGPROC ?
		m_IsDeviceAcceptableFuncUserContext LPVOID ?
		m_ModifyDeviceSettingsFuncUserContext LPVOID ?
		m_DeviceCreatedUserContext LPVOID ?
		m_DeviceCreatedFuncUserContext LPVOID ?
		m_DeviceResetFuncUserContext LPVOID ?
		m_DeviceLostFuncUserContext LPVOID ?
		m_DeviceDestroyedFuncUserContext LPVOID ?
		m_FrameMoveFuncUserContext LPVOID ?
		m_FrameRenderFuncUserContext LPVOID ?
		m_KeyboardFuncUserContext LPVOID ?
		m_MouseFuncUserContext LPVOID ?
		m_WindowMsgFuncUserContext LPVOID ?
		m_Keys BOOL 256  dup( ? )
		m_MouseButtons BOOL 5 dup( ? )
		CGrowableArray_D DXUT_TIMER, m_TimerList
	;	CGrowableArray DXUT_TIMER
		;, m_TimerList
;		m_TimerList ptr CGrowableArray ?
		m_StaticFrameStats WCHAR 256 dup( ? )
		m_FPSStats WCHAR 64 dup( ? )
		m_FrameStats WCHAR 256 dup( ? )
		m_DeviceStats WCHAR 256 dup( ? )
		m_WindowTitle WCHAR 256 dup( ? )
		
	STATE ends
DXUTState struct
	
	m_state STATE <>
DXUTState ends
LPDXUTState typedef ptr DXUTState
DXUTCACHE_SOURCELOCATION typedef DWORD

DXUTCache_Texture struct
	Location DXUTCACHE_SOURCELOCATION <>
	wszSource WCHAR MAX_PATH dup(?)
	hSrcModule HMODULE ?
	iWidth UINT ?
	Height UINT ?
	Depth UINT ?
	MipLevels UINT ?
	Usage DWORD ?
	Format D3DFORMAT <>
	Pool D3DPOOL <>
	iType D3DRESOURCETYPE <>
	pTexture LPDIRECT3DBASETEXTURE9 ?
DXUTCache_Texture ends

DXUTCache_Effect struct
	Location DXUTCACHE_SOURCELOCATION <>
	wszSource WCHAR MAX_PATH dup(?)
	hSrcModule HMODULE ?
	dwFlags DWORD ?
	pEffect LPD3DXEFFECT ?
DXUTCache_Effect ends

DXUTCache_Font struct
	D3DXFONT_DESC <>
	pFont LPD3DXFONT ?
DXUTCache_Font ends

CDXUTResourceCache struct
	CGrowableArray_D  DXUTCache_Texture, m_TextureCache
	CGrowableArray_D  DXUTCache_Effect, m_EffectCache
	CGrowableArray_D  DXUTCache_Font, m_FontCache
CDXUTResourceCache ends

WinMain proto :HINSTANCE, :HINSTANCE, :LPSTR, :DWORD
OnCreateDevice proto pd3dDevice:ptr IDirect3DDevice9, pBackBufferSurfaceDesc:ptr D3DSURFACE_DESC,pUserContext:ptr VOID
DXUTSetCallbackDeviceCreated proto pCallbackDeviceCreated:LPDXUTCALLBACKDEVICECREATED,pUserContext:ptr void
GetDXUTState proto
DXUTGetGlobalResourceCache proto
DXUTAllowShortcutKeys proto bAllowKeys:BOOL
DXUTGetD3DObject proto 
DXUTReLaunchMediaCenter proto 
DXUTLock@DXUTLock proto 
@DXUTLock@DXUTLock proto
DXUTState@DXUTState proto  pDXUTState:ptr DXUTState
Create@DXUTState proto  pDXUTState:ptr DXUTState
Destroy@DXUTState proto pDXUTState:ptr DXUTState
DXUTShutdown@DXUTState proto pDXUTState:ptr DXUTState, nExitCode:DWORD
DXUTGetHWND proto
DXUTIsWindowed proto 
DXUTCleanup3DEnvironment proto bReleaseSettings:BOOL
DXUTGetD3DDevice proto

OnLostDevice@CDXUTResourceCache proto pCDXUTResourceCache: ptr CDXUTResourceCache
OnDestroyDevice@CDXUTResourceCache proto pCDXUTResourceCache: ptr CDXUTResourceCache
@DXUTDeviceSettings@DXUTDeviceSettings proto pDXUTDeviceSettings: ptr DXUTDeviceSettings

.data
ClassName db "SimpleWinClass",0
AppName  db "D3D9",0
g_bThreadSafe BOOL TRUE

.data?
; Windows stuff
hInstance HINSTANCE ?
CommandLine LPSTR ?
state DXUTState <>
cache CDXUTResourceCache <>
g_cs CRITICAL_SECTION <>
.code
start:

	invoke GetModuleHandle, NULL
	mov    hInstance,eax
	invoke GetCommandLine
	invoke DXUTState@DXUTState, addr state
	invoke WinMain, hInstance,NULL,CommandLine, SW_SHOWDEFAULT
	invoke Destroy@DXUTState, addr state
	invoke ExitProcess,eax
WinMain proc hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdLine:LPSTR,CmdShow:DWORD
    LOCAL wc:WNDCLASSEX
    LOCAL msg:MSG
    LOCAL hwnd:HWND
    invoke DXUTSetCallbackDeviceCreated, OnCreateDevice, NULL
    
    mov   wc.cbSize,SIZEOF WNDCLASSEX
    mov   wc.style, CS_HREDRAW or CS_VREDRAW
    mov   wc.lpfnWndProc, OFFSET WndProc
    mov   wc.cbClsExtra,NULL
    mov   wc.cbWndExtra,NULL
    push  hInst
    pop   wc.hInstance
    mov   wc.hbrBackground,BLACK_BRUSH
    mov   wc.lpszMenuName,NULL
    mov   wc.lpszClassName,OFFSET ClassName
    invoke LoadIcon,NULL, IDI_APPLICATION
    mov   wc.hIcon,eax
    mov   wc.hIconSm,0
    invoke LoadCursor,NULL, IDC_ARROW
    mov   wc.hCursor,eax
    invoke RegisterClassEx, addr wc
    
    INVOKE CreateWindowEx,NULL,ADDR ClassName,ADDR AppName,\
           WS_OVERLAPPEDWINDOW,100,\
           100,WINDOW_WIDTH,WINDOW_HEIGHT,NULL,NULL,\
           hInst,NULL
    mov   hwnd,eax
    
    INVOKE ShowWindow, hwnd,SW_SHOWNORMAL
    INVOKE UpdateWindow, hwnd
    .WHILE msg.message != WM_QUIT
                
        INVOKE PeekMessage, ADDR msg,NULL,0,0, PM_REMOVE
        .IF (eax)
            INVOKE TranslateMessage, ADDR msg
            INVOKE DispatchMessage, ADDR msg
        .ELSE
        
        .ENDIF
        
    .ENDW
    mov     eax,msg.wParam
    ret
WinMain endp
WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
        
    .IF uMsg==WM_CLOSE
        
        invoke PostQuitMessage,NULL
        
    .ELSEIF uMsg == WM_KEYDOWN
        
        .if wParam == VK_ESCAPE
            
            invoke PostQuitMessage, 0
            
        .endif
        
    .ELSE
        
        invoke DefWindowProc,hWnd,uMsg,wParam,lParam
        ret
        
    .ENDIF
    
    xor    eax,eax
    ret
    
WndProc endp
GET_SET_ACCESSOR pDXUTState, DWORD, ExitCode, DXUTState
GET_SET_ACCESSOR pDXUTState, HWND,HWNDDeviceWindowed, DXUTState
GET_SET_ACCESSOR pDXUTState, HWND,HWNDDeviceFullScreen, DXUTState
GET_SET_ACCESSOR pDXUTState, ptr DXUTDeviceSettings, CurrentDeviceSettings, DXUTState
GET_SET_ACCESSOR pDXUTState, BOOL, InsideDeviceCallback, DXUTState
GET_SET_ACCESSOR pDXUTState, BOOL, DeviceObjectsReset, DXUTState
GET_SET_ACCESSOR pDXUTState, LPDXUTCALLBACKDEVICELOST, DeviceLostFunc, DXUTState
GET_SET_ACCESSOR pDXUTState, ptr VOID, DeviceLostFuncUserContext, DXUTState
GET_SET_ACCESSOR pDXUTState, BOOL, DeviceObjectsCreated, DXUTState
GET_SET_ACCESSOR pDXUTState, LPDXUTCALLBACKDEVICEDESTROYED, DeviceDestroyedFunc, DXUTState
GET_SET_ACCESSOR pDXUTState, ptr VOID, DeviceDestroyedFuncUserContext, DXUTState
GET_SET_ACCESSOR pDXUTState, ptr IDirect3DDevice9, D3DDevice, DXUTState
GET_SET_ACCESSOR pDXUTState, BOOL, DeviceCreated, DXUTState
GET_SET_ACCESSOR pDXUTState, ptr CD3DEnumeration, D3DEnumeration, DXUTState
GET_SET_ACCESSOR pDXUTState, ptr IDirect3D9, D3D, DXUTState
GET_SET_ACCESSOR pDXUTState, BOOL,  OverrideRelaunchMCE, DXUTState
GETP_SETP_ACCESSOR pDXUTState, D3DSURFACE_DESC, BackBufferSurfaceDesc, DXUTState
GETP_SETP_ACCESSOR pDXUTState, D3DCAPS9, Caps, DXUTState



DXUTCleanup3DEnvironment proc bReleaseSettings:BOOL
	
	invoke DXUTGetD3DDevice
	assume eax:LPDIRECT3DDEVICE9 
	.if eax
		push eax
		invoke  GetDXUTState
		assume eax :ptr DXUTState
		push eax
		invoke SetInsideDeviceCallback@DXUTState, eax, TRUE
		pop eax
		push eax
		invoke GetDeviceObjectsReset@DXUTState, eax
		.if eax
			pop eax
			push eax
			invoke GetDeviceLostFunc@DXUTState, 	eax
			.if eax
				pop ebx
				mov ecx, eax
				push ebx
				push ecx
				invoke GetDeviceLostFuncUserContext@DXUTState, ebx
				pop ecx
				push eax
				call ecx
				;assume ecx: ptr DXUTCALLBACKDEVICELOST
				;invoke ecx, eax
			.endif
			pop eax
			push eax
			invoke SetDeviceObjectsReset@DXUTState, eax, FALSE
			invoke DXUTGetGlobalResourceCache
			assume eax: ptr CDXUTResourceCache
			invoke OnLostDevice@CDXUTResourceCache, eax
		.endif
		pop eax
		push eax
		invoke GetDeviceObjectsCreated@DXUTState, eax
		.if eax
			pop eax
			push eax
			invoke GetDeviceDestroyedFunc@DXUTState, eax
			.if eax
				pop ebx
				mov ecx, eax
				push ebx
				push ecx
				invoke GetDeviceDestroyedFuncUserContext@DXUTState, ebx
				pop ecx
				;assume ecx:LPDXUTCALLBACKDEVICEDESTROYED
				;invoke ecx, eax
				push eax
				call ecx
			.endif
			pop eax
			push eax
			invoke SetDeviceObjectsCreated@DXUTState, eax, FALSE
			invoke DXUTGetGlobalResourceCache
			assume eax: ptr CDXUTResourceCache
			invoke OnDestroyDevice@CDXUTResourceCache, eax
			pop eax
			push eax
		.endif
		pop eax
		push eax
		invoke SetInsideDeviceCallback@DXUTState, eax, FALSE
		pop eax
		pop ebx
		push eax
		invoke vf( ebx, IDirect3DDevice9, Release )
		.if eax > 0
			
		.endif
		pop eax
		push eax
		invoke SetD3DDevice@DXUTState, eax, NULL
		.if bReleaseSettings
			pop eax
			push eax
			invoke GetCurrentDeviceSettings@DXUTState, eax
			.if eax
;				invoke @DXUTDeviceSettings@DXUTDeviceSettings, eax
			.endif
			pop eax
			push eax
			invoke SetCurrentDeviceSettings@DXUTState, eax, NULL
		.endif
		pop eax
		push eax
		invoke GetBackBufferSurfaceDesc@DXUTState, eax
		invoke ZeroMemory, eax,sizeof D3DSURFACE_DESC
		pop eax
		push eax
		invoke GetCaps@DXUTState, eax
		invoke ZeroMemory, eax,sizeof D3DCAPS9
		pop eax
		invoke SetDeviceCreated@DXUTState, eax, FALSE
	.endif
	ret

DXUTCleanup3DEnvironment endp
OnCreateDevice proc pd3dDevice:ptr IDirect3DDevice9, pBackBufferSurfaceDesc:ptr D3DSURFACE_DESC,pUserContext:ptr VOID
	
	mov eax, S_OK
	ret

OnCreateDevice endp

DXUTSetCallbackDeviceCreated proc pCallbackDeviceCreated:LPDXUTCALLBACKDEVICECREATED,pUserContext:ptr void

	xor eax, eax
	ret
DXUTSetCallbackDeviceCreated endp

GetDXUTState proc
	
	mov eax, OFFSET state
	ret

GetDXUTState endp

DXUTGetGlobalResourceCache proc
	
	mov eax, OFFSET cache
	ret

DXUTGetGlobalResourceCache endp
DXUTState@DXUTState proc pDXUTState:ptr DXUTState
	
	invoke Create@DXUTState, pDXUTState
	ret

DXUTState@DXUTState endp

Create@DXUTState proc pDXUTState:ptr DXUTState
	pushad
	invoke DXUTGetGlobalResourceCache
	mov eax, pDXUTState
	assume eax : ptr DXUTState 
	lea eax, [eax].m_state
	assume eax :ptr STATE
	invoke ZeroMemory, eax, sizeof( STATE)
	mov g_bThreadSafe, TRUE
	invoke InitializeCriticalSection, addr g_cs
	mov eax, pDXUTState
	mov [eax].m_OverrideStartX, -1
	mov [eax].m_OverrideStartY, -1
	mov [eax].m_OverrideAdapterOrdinal, -1
	mov [eax].m_OverrideForceVsync, -1
	mov [eax].m_AutoChangeAdapter, TRUE
	mov [eax].m_ShowMsgBoxOnError, TRUE
	mov [eax].m_AllowShortcutKeysWhenWindowed, TRUE
	mov [eax].m_Active, TRUE
	mov [eax].m_CallDefWindowProc, TRUE
	popad
	ret
Create@DXUTState endp

Destroy@DXUTState proc pDXUTState:ptr DXUTState
	invoke DXUTShutdown@DXUTState, pDXUTState, 0
	invoke DeleteCriticalSection, addr g_cs
	ret
Destroy@DXUTState endp
DXUTShutdown@DXUTState proc pDXUTState:ptr DXUTState, nExitCode:DWORD
	LOCAL hWnd:HWND
	invoke DXUTGetHWND
	mov hWnd,eax
	.IF hWnd != NULL
		invoke SendMessage, hWnd, WM_CLOSE, 0, 0
	.endif
	invoke GetDXUTState
	assume eax : ptr DXUTState
	push eax
	invoke SetExitCode@DXUTState, eax, nExitCode
	invoke DXUTCleanup3DEnvironment, TRUE
	invoke DXUTAllowShortcutKeys, TRUE
	pop eax
	push eax
	invoke SetD3DEnumeration@DXUTState, eax, NULL
	invoke DXUTGetD3DObject
	.if eax
		invoke vf( eax, IDirect3D9, Release )
	.endif
	pop eax
	push eax
	invoke SetD3D@DXUTState, eax, NULL
	pop eax
	invoke GetOverrideRelaunchMCE@DXUTState, eax
	.if eax
		invoke DXUTReLaunchMediaCenter
	.endif
	
	ret
DXUTShutdown@DXUTState endp

DXUTLock@DXUTLock proc 
	
	.IF g_bThreadSafe
		invoke EnterCriticalSection, addr g_cs
	.ENDIF
	ret

DXUTLock@DXUTLock endp

@DXUTLock@DXUTLock proc 
	.IF g_bThreadSafe
		invoke LeaveCriticalSection, addr g_cs
	.ENDIF
	ret
@DXUTLock@DXUTLock endp



DXUTGetHWND proc
	invoke DXUTIsWindowed
	.if eax
		invoke GetDXUTState
		assume eax:ptr DXUTState
		invoke GetHWNDDeviceWindowed@DXUTState, eax
		ret
	.else
		invoke GetDXUTState
		assume eax:ptr DXUTState
		invoke GetHWNDDeviceFullScreen@DXUTState, eax
		ret
	.endif
	ret
DXUTGetHWND endp

DXUTIsWindowed proc
	
	invoke GetDXUTState
	assume eax: ptr DXUTState
	invoke GetCurrentDeviceSettings@DXUTState, eax
	.if eax
		assume eax : ptr DXUTDeviceSettings
		.if [eax].pp.Windowed
			mov eax, 1
		.else
			mov eax, 0
		.endif
	.else
		mov eax, 0
	.endif
	ret

DXUTIsWindowed endp

DXUTGetD3DDevice proc
	
	invoke GetDXUTState
	assume eax: ptr DXUTState
	invoke GetD3DDevice@DXUTState, eax
	ret

DXUTGetD3DDevice endp

OnLostDevice@CDXUTResourceCache proc pCDXUTResourceCache: ptr CDXUTResourceCache
;
;
;
	mov eax, S_OK
	ret

OnLostDevice@CDXUTResourceCache endp

OnDestroyDevice@CDXUTResourceCache proc pCDXUTResourceCache: ptr CDXUTResourceCache
	
;
;
;	
	ret

OnDestroyDevice@CDXUTResourceCache endp

DXUTAllowShortcutKeys proc bAllowKeys:BOOL
;
;
;
;
	ret

DXUTAllowShortcutKeys endp

DXUTGetD3DObject proc
	
	invoke GetDXUTState
	invoke GetD3D@DXUTState, eax
	ret

DXUTGetD3DObject endp

DXUTReLaunchMediaCenter proc
;
;
;
;
	ret
DXUTReLaunchMediaCenter endp

end start

DXUTmisc.inc源文件:

CGrowableArray MACRO TYPE_VAR
;, VAR_NAME
	LP_&TYPE_VAR typedef ptr &TYPE_VAR
	CGrowableArray_&TYPE_VAR struct
		m_nSize DWORD ?
		m_nMaxSize DWORD ?
		m_pData LP_&TYPE_VAR ?
	CGrowableArray_&TYPE_VAR ends
;	&VAR_NAME CGrowableArray_&TYPE_VAR <>
ENDM



CGrowableArray_D MACRO TYPE_VAR, VAR_NAME
	&VAR_NAME CGrowableArray_&TYPE_VAR <>
ENDM

;CGrowableARRAY_F MACRO TYPE_VAR, a
;	&TYPE_VAR&@&TYPE_VAR&@CGrowableARRAY_F proc a: ptr &TYPE_VAR
;		mov eax, a
;		assume eax: ptrptr TYPE_VAR
;		
;	&TYPE_VAR&@&TYPE_VAR&@CGrowableARRAY_F endp
;ENDM

SET_ACCESSOR MACRO a, x, y,z
	Set&y&@&z proc &a:ptr &z, t:&x
		invoke DXUTLock@DXUTLock
		mov eax, &a
		assume eax: ptr &z
		lea eax, [eax].m_state
		assume eax: ptr STATE
		;push ebx
		;mov ebx, t
		;mov [eax].m_&y, ebx
		;pop ebx
		push ebx
		lea ebx, t
		mov ebx, dword ptr [ebx]
		lea eax, [eax].m_&y
		;push [ebx]
		;pop [eax]
		mov dword ptr[eax], ebx
		pop ebx
		;invoke CopyMemory, eax, addr t, sizeof &x
		invoke @DXUTLock@DXUTLock
		ret
	Set&y&@&z endp
ENDM

GET_ACCESSOR MACRO a, x, y,z
	Get&y&@&z proc &a:ptr &z
		;LOCAL t:&x
		invoke DXUTLock@DXUTLock
		mov eax, a
		assume eax: ptr &z
		lea eax,[eax].m_state
		assume eax:ptr STATE
		lea eax, [eax].m_&y
		mov eax, dword ptr [eax]
		push eax
		invoke @DXUTLock@DXUTLock
		
		pop eax
		ret
	Get&y&@&z endp
ENDM

GET_SET_ACCESSOR MACRO a, x, y,z
	SET_ACCESSOR a, x, y,z
	GET_ACCESSOR a, x, y,z
ENDM

SETP_ACCESSOR MACRO a, x, y, z
	Set&y&@z proc &a:ptr &z, t: ptr &x
		invoke DXUTLock@DXUTLock
		mov eax, a
		assume eax: ptr &z
		lea eax, [eax].m_state
		assume eax :ptr STATE
		push ebx
		mov ebx, t
		mov ebx, dword ptr [ebx]
		;mov [eax].m_&y, ebx
		lea eax, [eax].m_&y
		mov dword ptr [eax], ebx
		;push [ebx]
		;pop [eax]
		pop ebx
		invoke @DXUTLock@DXUTLock
		ret
	Set&y&@z endp	
ENDM

GETP_ACCESSOR MACRO a, x, y, z
	Get&y&@&z proc &a:ptr &z
		invoke DXUTLock@DXUTLock
		mov eax, a
		assume eax: ptr &z
		lea eax,[eax].m_state
		assume eax:ptr STATE
		lea eax, [eax].m_&y
		push eax
		invoke @DXUTLock@DXUTLock
		pop eax
		ret
	Get&y&@&z endp	
	
		
ENDM

GETP_SETP_ACCESSOR MACRO a, x, y, z
	SETP_ACCESSOR a, x, y, z
	GETP_ACCESSOR a, x, y, z
ENDM


其他文件都是空的。编译命令调用:

C:\RadASM\Masm32\Bin\ML.EXE /c /coff /Cp /nologo /I"C:\RadASM\Masm32\Include" "EmptyProject.asm"
C:\RadASM\Masm32\Bin\LINK.EXE /SUBSYSTEM:WINDOWS /RELEASE /VERSION:4.0 /LIBPATH:"C:\RadASM\Masm32\Lib" /OUT:"EmptyProject.exe" "EmptyProject.obj" "EmptyProject.res"

发布者

rix

如果连自己都不爱自己,哪还有谁来爱你