• entries
    146
  • comments
    436
  • views
    197169

When Boredom Strikes

Sign in to follow this  
Washu

1712 views

Washu does crazy things. In this case I wrote this up...


.586
.model flat, stdcall
option casemap :none

@ArgRev MACRO arglist:REQ
LOCAL txt, arg
txt TEXTEQU <>
% FOR arg,
txt CATSTR , <,>, txt
ENDM

txt SUBSTR txt, 1, @SizeStr( %txt ) - 1
txt CATSTR , txt, >
EXITM txt
ENDM

INVOKEC MACRO comObject, methodNumber, args:VARARG
LOCAL txt
IFNB
% FOR arg, @ArgRev( )
push arg
ENDM
ENDIF
mov ecx, dword ptr [comObject]
push ecx
mov eax, [ecx]
mov edx, dword ptr [eax + methodNumber];
call edx
ENDM

RELEASE MACRO comObject
LOCAL skip
cmp comObject, 0
jz skip
INVOKEC comObject, IUnknown_Release
skip:
ENDM

DEFINEGUID MACRO name, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11
name DD _1
DW _2
DW _3
DB _4
DB _5
DB _6
DB _7
DB _8
DB _9
DB _10
DB _11
ENDM

ExitProcess PROTO stdcall :DWORD
MessageBoxA PROTO stdcall :DWORD, :DWORD, :DWORD, :DWORD
RegisterClassExA PROTO stdcall :DWORD
GetModuleHandleA PROTO stdcall :DWORD
DefWindowProcA PROTO stdcall :DWORD, :DWORD, :DWORD, :DWORD
CreateWindowExA PROTO stdcall :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD
PostQuitMessage PROTO stdcall :DWORD
ShowWindow PROTO stdcall :DWORD, :DWORD
UpdateWindow PROTO stdcall :DWORD
PeekMessageA PROTO stdcall :DWORD, :DWORD, :DWORD, :DWORD, :DWORD
TranslateMessage PROTO stdcall :DWORD
DispatchMessageA PROTO stdcall :DWORD
D3D11CreateDeviceAndSwapChain PROTO stdcall :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD

POINT STRUC 4
x DWORD ?
y DWORD ?
POINT ENDS

MSG STRUC 4
hwnd DWORD ?
message DWORD ?
wparam WORD ?
lparam DWORD ?
time DWORD ?
point POINT <>
MSG ENDS

WNDCLASSEX STRUC 4
cbSize DWORD SIZEOF(WNDCLASSEX)
style DWORD CW_VREDRAW OR CW_HREDRAW OR CW_OWNDC
lpfnWndProc DWORD WndProc
cbClsExtra DWORD 0
cbWndExtra DWORD 0
hInstance DWORD ?
hIcon DWORD 0
hCursor DWORD 0
hbrBackground DWORD COLOR_BACKGROUND
lpszMenuName DWORD 0
lpszClassName DWORD className
hIconSm DWORD 0
WNDCLASSEX ENDS

DXGI_RATIONAL STRUC 4
numerator DWORD ?
denominator DWORD ?
DXGI_RATIONAL ENDS

DXGI_MODE_DESC STRUC 4
w DWORD 800
h DWORD 600
refreshRate DXGI_RATIONAL <1, 60>
format DWORD DXGI_FORMAT_R8G8B8A8_UNORM
scanLineOrder DWORD 0
scaling DWORD 0
DXGI_MODE_DESC ENDS

DXGI_SWAP_CHAIN_DESC STRUC 4
bufferDesc DXGI_MODE_DESC <>
sampleDesc DXGI_RATIONAL <1, 0>
usage DWORD 20h OR 40h
bufferCount DWORD 2
window DWORD ?
windowed DWORD 1
swapEffect DWORD 0
flags DWORD 0
DXGI_SWAP_CHAIN_DESC ENDS

MB_OK EQU 0
SW_SHOW EQU 5
CW_VREDRAW EQU 1
CW_HREDRAW EQU 2
CW_OWNDC EQU 20h
COLOR_BACKGROUND EQU 1
WS_OVERLAPPED EQU 00000000h
WS_MINIMIZEBOX EQU 00020000h
WS_MAXIMIZEBOX EQU 00020000h
WS_SYSMENU EQU 00080000h
WS_THICKFRAME EQU 00040000h
WS_CAPTION EQU 00C00000h
WS_OVERLAPPEDWINDOW EQU WS_OVERLAPPED OR WS_MINIMIZEBOX OR WS_MAXIMIZEBOX OR WS_SYSMENU OR WS_THICKFRAME OR WS_CAPTION
WM_QUIT EQU 0012h

D3D_DRIVER_TYPE_UNKNOWN EQU 0
D3D_DRIVER_TYPE_HARDWARE EQU ( D3D_DRIVER_TYPE_UNKNOWN + 1 )
D3D11_CREATE_DEVICE_SINGLETHREADED EQU 1
D3D_FEATURE_LEVEL_11_0 EQU 0b000h
DXGI_FORMAT_R8G8B8A8_UNORM EQU 28

IUnknown_QueryInterface EQU 0h
IUnknown_AddRef EQU 4h
IUnknown_Release EQU 8h

IDXGISwapChain_GetBuffer EQU 24h
IDXGISwapChain_Present EQU 20h

ID3D11Device_CreateRTView EQU 24h

ID3D11Context_ClearRTView EQU 0C8h

.data
msgTitle DB "Oh shit son!", 0
regFail DB "Failed to register window class.", 0
cwFail DB "Failed to create window.", 0
showFail DB "Failed to show window.", 0
updateFail DB "Failed to update window.", 0
d3d11Fail1 DB "Failed to create D3D11 device.", 0
d3d11Fail2 DB "Failed to get back buffer from swap chain.", 0
d3d11Fail3 DB "Failed to create render target.", 0

messageIdx DD regFail, cwFail, showFail, updateFail, d3d11Fail1, d3d11Fail2, d3d11Fail3

className DB "TestClass", 0
windowTitle DB "My Window", 0
wndClass WNDCLASSEX <>
swapDesc DXGI_SWAP_CHAIN_DESC <>
featureLvl DD D3D_FEATURE_LEVEL_11_0
swapChain DD 0
device DD 0
newFeatLvl DD 0
context DD 0

blackColor DD 0, 0, 0, 0
backBuffer DD 0
view DD 0
DEFINEGUID ID3D11Texture2D_GUID, 6f15aaf2h, 0d208h, 04e89h, 09ah, 0b4h, 048h, 095h, 035h, 0d3h, 04fh, 09Ch

.code
WndProc PROC stdcall hwnd:DWORD, msg:DWORD, wparam:WORD, lparam:DWORD
cmp msg, 2
jnz done
INVOKE PostQuitMessage, 0
xor eax, eax
ret
done:
INVOKE DefWindowProcA, hwnd, msg, wparam, lparam
ret;
WndProc ENDP

main PROC
LOCAL hwnd:DWORD
LOCAL hmodule:DWORD
LOCAL msg:MSG

INVOKE GetModuleHandleA, 0
mov hmodule, eax
mov wndClass.hInstance, eax

INVOKE RegisterClassExA, ADDR wndClass
cmp eax, 0
mov eax, 0
jz error

INVOKE CreateWindowExA, 0, ADDR className, ADDR windowTitle, WS_OVERLAPPEDWINDOW, 0, 0, 800, 600, 0, 0, hmodule, 0
mov hwnd, eax
cmp eax, 0
mov eax, 1
jz error

INVOKE ShowWindow, hwnd, SW_SHOW
INVOKE UpdateWindow, hwnd
cmp eax, 0
mov eax, 3
jz error

mov eax, hwnd
mov swapDesc.window, eax

INVOKE D3D11CreateDeviceAndSwapChain, 0, D3D_DRIVER_TYPE_HARDWARE, 0, 0, ADDR featureLvl, 1, 7, ADDR swapDesc, ADDR swapChain, ADDR device, ADDR newFeatLvl, ADDR context
cmp eax, 0
mov eax, 4
jnz error

lea eax, [backBuffer]
INVOKEC swapChain, IDXGISwapChain_GetBuffer, 0, OFFSET ID3D11Texture2D_GUID, eax
cmp eax, 0
mov eax, 5
jnz error

lea eax, [view]
INVOKEC device, ID3D11Device_CreateRTView, dword ptr [backBuffer], 0, eax
cmp eax, 0
mov eax, 6
jnz error

gameLoop:
msgLoop:
INVOKE PeekMessageA, ADDR msg, 0, 0, 0, 1
cmp eax, 0
jz gameNext
cmp msg.message, WM_QUIT
jz done
INVOKE TranslateMessage, ADDR msg
INVOKE DispatchMessageA, ADDR msg
jmp msgLoop
gameNext:
INVOKEC context, ID3D11Context_ClearRTView, view, OFFSET blackColor
INVOKEC swapChain, IDXGISwapChain_Present, 0, 0
jmp gameLoop

done:
RELEASE view
RELEASE backBuffer
RELEASE swapChain
RELEASE device
RELEASE context
INVOKE ExitProcess, eax
ret
error:
mov eax, messageIdx[eax*4]
INVOKE MessageBoxA, 0, eax, ADDR msgTitle, MB_OK
RELEASE view
RELEASE backBuffer
RELEASE swapChain
RELEASE device
RELEASE context
INVOKE ExitProcess, eax
main ENDP
END main


If you're asking yourself "Is that a Win32 application that creates a D3D11 device, clears the render target, and then presents it?" Then yes. It is.
Sign in to follow this  


5 Comments


Recommended Comments

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now