Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; ========================================================================================
- align 16
- export D3D9_Startup:
- sub rsp, 48h
- ; ----- ENTER -----
- ; ----------------------------
- ; zero the interface ptrs
- ; ----------------------------
- xor eax, eax
- mov [pp_D3D], rax
- mov [pp_Device], rax
- mov [pp_Texture], rax
- ; -----------------------------------------------------------------
- ; HRESULT Direct3DCreate9Ex(UINT SDKVersion, IDirect3D9EX **ppD3D)
- ; -----------------------------------------------------------------
- mov ecx, D3D_SDK_VERSION ; p1: UINT SDKVersion
- lea rdx, pp_D3D ; p2: IDirect3D9EX **ppD3D
- call Direct3DCreate9Ex
- test eax, eax
- jnz >> .d3d9LError
- ; --------------------------------------
- ; zero D3DPRESENT_PARAMETERS structure
- ; --------------------------------------
- lea edx, d3dpp
- xor eax, eax ; fillvalue = 0
- mov ecx, sizeof(D3DPRESENT_PARAMETERS / 8) ; size /8 bytes per fill
- : mov [edx], rax
- add edx, 8
- dec ecx
- jnz <
- ; --------------------------------------
- ; fill D3DPRESENT_PARAMETERS structure
- ; --------------------------------------
- mov D[d3dpp.BackBufferWidth], SCREENWIDTH ; 1920
- mov D[d3dpp.BackBufferHeight], SCREENHEIGHT ; 1080
- mov D[d3dpp.BackBufferFormat], D3DFMT_X8R8G8B8 ; 22
- mov D[d3dpp.BackBufferCount], 1
- mov D[d3dpp.SwapEffect], D3DSWAPEFFECT_FLIPEX ; 5
- mov rax, [hWindow]
- mov [d3dpp.hDeviceWindow], rax
- mov D[d3dpp.Windowed], TRUE
- mov D[d3dpp.PresentationInterval], D3DPRESENT_INTERVAL_IMMEDIATE
- ; ------------------
- ; create the device
- ; ------------------
- ; HRESULT CreateDeviceEx(
- mov rcx, [pp_D3D] ; p1: *this
- xor edx, edx ; p2: UINT Adapter = 0
- mov r8d, D3DDEVTYPE_HAL ; p3: D3DDEVTYPE DeviceType (1)
- mov r9, [hWindow] ; p4: HWND hFocusWindow
- mov D[rsp+20h], D3DCREATE_HARDWARE_VERTEXPROCESSING ; p5: DWORD BehaviorFlags (40h)
- lea rax, d3dpp
- mov [rsp+28h], rax ; p6: D3DPRESENT_PARAMETERS *pPresentationParameters
- xor eax, eax
- mov [rsp+30h], rax ; p7: D3DDISPLAYMODEEX *pFullscreenDisplayMode
- lea rax, pp_Device
- mov [rsp+38h], rax ; p8: IDirect3DDevice9Ex **ppReturnedDeviceInterface
- mov rax, [rcx]
- add rax, IDirect3D9Ex_CreateDeviceEx
- call [rax]
- test eax, eax
- jnz >> .d3d9LError
- ; ------------------
- ; create the texture
- ; ------------------
- ; HRESULT CreateTexture
- mov rcx, [pp_Device] ; p1: *this
- mov edx, 1920 ; p2: UINT Width
- mov r8d, 1080 ; p3: UINT Height
- mov r9d, 1 ; p4: UINT Levels
- mov D[rsp+20h], D3DUSAGE_DYNAMIC ; p5: DWORD Usage
- mov D[rsp+28h], D3DFMT_X8R8G8B8 ; p6: D3DFORMAT Format
- mov D[rsp+30h], D3DPOOL_DEFAULT ; p7: D3DPOOL Pool
- lea rax, pp_Texture
- mov [rsp+38h], rax ; p8: IDirect3DTexture9 **ppTexture
- xor eax, eax
- mov [rsp+40h], rax ; p9: HANDLE *pSharedHandle
- mov rax, [rcx]
- add rax, IDirect3DDevice9Ex_CreateTexture
- call [rax]
- test eax, eax
- jnz >> .d3d9LError
- ; ----- EXIT -----
- mov eax, TRUE ; return 1 if successful
- jmp > .d3d9LExit
- .d3d9LError:
- xor rax, rax ; return 0 if error
- .d3d9LExit:
- add rsp, 48h
- ret
- ; ========================================================================================
- align 16
- export D3D9_Shutdown:
- sub rsp, 28h
- ; ----- Enter -----
- mov eax, [pp_D3D]
- or eax, eax
- jz >> .d3d9uExit
- ; release back buffer interface
- mov rcx, [pp_Texture]
- mov rax, [rcx]
- add eax, IDirect3DTexture9_Release
- call [rax]
- or eax, eax
- jnz >> .d3d9uExit
- ; release front buffer interface
- mov rcx, [pp_Device]
- mov rax, [rcx]
- add eax, IDirect3DDevice9Ex_Release
- call [rax]
- or eax, eax
- jnz >> .d3d9uExit
- ; release DirectDraw 7 interface
- mov rcx, [pp_D3D]
- mov rax, [rcx]
- add eax, IDirect3D9Ex_Release
- call [rax]
- or eax, eax
- jnz >> .d3d9uExit
- ; zero the DDraw interface ptrs
- xor eax, eax
- mov [pp_Texture], rax
- mov [pp_Device], rax
- mov [pp_D3D], rax
- ; ----- Exit -----
- .d3d9uExit:
- add rsp, 28h
- ret
- ; ========================================================================================
Advertisement