The MASM Forum

Projects => Game Development => Topic started by: felipe on June 27, 2019, 05:25:24 AM

Title: directx9 simple 64 bits program
Post by: felipe on June 27, 2019, 05:25:24 AM
Here it's my first program using directx9 in 64 bits. It's a simple window but it's a start, with some luck and time i will do more. Now a few notes:

1) The program works correctly under normal circumtances. Which means here that you have the d3d9.dll in your system directory, there are no problems with your graphic card or drivers, etc. Basically i want to say this because the program don't do any kind of verification for errors, so if there is an extraordinary problem with the program it would just crash. It's made like this because the intention of the post of this program it's just to show the basic program structure to work with directx9. In a bloatware production level you will include all the error checks you want (even if the registerclassex function didn't work as someones does...)
2) The attached files include the DX9Includes64, which is a 64 bits version of the includes made by siekmanski with some modifications made by me. But wait! I have only changed the d3d9.inc file until now! I have commented out other includes in that file because the types are not friendlies with win64.inc unfortunately. The other modification of this file are the pointers offsets which now are 8 bytes long and not 4. That's all, all the other includes are exactly the same as before (like in other post from me here in the game development subforum.)
3) I almost forget to tell you that to assemble correctly you need to put the includes files directory in the include64 directory of the masm32 64 bits version...

Source code, executable and includes are attached... :azn:
Title: Re: directx9 simple 64 bits program
Post by: felipe on June 27, 2019, 08:24:47 AM
Here it's the same program but will check if there were errors initializing direct3d and while creating the direct3d device. In any case the program will show an error message and will finish. I know there can be more errors in the program like LoadLibrary not returning succesfull and then will crash the program (probably) but as i said before the program it's a demo, not a full finished app ready for sale  :joking:  :toothy:
Title: Re: directx9 simple 64 bits program
Post by: felipe on June 27, 2019, 10:00:55 AM
And here it's the fullscreen version of the same program...  :azn: You should unzip the program before running it  :icon_idea: or it will crash. I think this is because of GetAsyncKeyState.  :icon_idea:
Title: Re: directx9 simple 64 bits program
Post by: felipe on June 27, 2019, 11:03:17 AM
One thing worth to note is how D3DPRESENT_PARAMETERS is implemented in 64 bits. Only 1 member of the structure (HWND) has changed to a qword instead of a dword. But this member most be aligned to a qword or it will not work (the call to CreateDevice will return an error of D3DERR_INVALIDCALL). So in the structure each member is aligned to it's natural size (dwords to dwords and qwords to qwords) as microsoft  says here: https://docs.microsoft.com/es-es/cpp/build/x64-software-conventions?view=vs-2019#types-and-storage (https://docs.microsoft.com/es-es/cpp/build/x64-software-conventions?view=vs-2019#types-and-storage). Please refer to the page in your language... :icon_idea:
Title: Re: directx9 simple 64 bits program
Post by: daydreamer on June 27, 2019, 06:46:06 PM
it works,but fullscreen is the same problem with old programs that uses old 4:3 monitor format resolutions without stretching on newer computer that is more widescreen,its a square on the middle of the screen with black on left and right sides
Title: Re: directx9 simple 64 bits program
Post by: felipe on June 27, 2019, 11:24:10 PM
Wow! i have no idea how to fix that... :undecided: Any idea? By the way, the program in fullscreen mode ends when pressing the esc key (i forgot to mention that).
Probably i have to detect your monitor screen size and then use some nice direct3d function?  :icon_idea:
Title: Re: directx9 simple 64 bits program
Post by: daydreamer on June 28, 2019, 01:03:30 AM
Quote from: felipe on June 27, 2019, 11:24:10 PM
Wow! i have no idea how to fix that... :undecided: Any idea? By the way, the program in fullscreen mode ends when pressing the esc key (i forgot to mention that).
Probably i have to detect your monitor screen size and then use some nice direct3d function?  :icon_idea:
maybe some dx caps call shows all kinds of info on the gpu and list of screen modes
go thru dx9 sdk tutorials,samples,docs you find it
3d labyrinth next?
Title: Re: directx9 simple 64 bits program
Post by: felipe on June 28, 2019, 02:24:20 AM
thanks. i prefer some game in 2d first, something like a character moving like in mario bros I  :bgrin:
Title: Re: directx9 simple 64 bits program
Post by: Siekmanski on June 28, 2019, 05:14:26 AM
Hi Felipe,

You could check the actual monitor resolution like this and then copy it to the presentation parameters:


.data?
d3ddm                   D3DDISPLAYMODE <?>
d3dpp                   D3DPRESENT_PARAMETERS <?>

.code
; Get monitor display info
    coinvoke    g_pD3D,IDirect3D9,GetAdapterDisplayMode,D3DADAPTER_DEFAULT,offset d3ddm

; Get default monitor full-screen resolution
    invoke   RtlZeroMemory,offset d3dpp,sizeof d3dpp

    mov      eax,d3ddm.dx_Width
    mov      d3dpp.BackBufferWidth,eax
    mov      eax,d3ddm.dx_Height
    mov      d3dpp.BackBufferHeight,eax
               
    mov      d3dpp.Windowed,FALSE
    mov      eax,hWnd
    mov      d3dpp.hDeviceWindow,eax
    mov      d3dpp.BackBufferCount,1
    mov      d3dpp.SwapEffect,D3DSWAPEFFECT_DISCARD
    mov      d3dpp.PresentationInterval,D3DPRESENT_INTERVAL_ONE


Title: Re: directx9 simple 64 bits program
Post by: felipe on June 29, 2019, 01:35:50 AM
That's great siekmanski, thanks a lot  :thumbsup:. I will incorporate that code to the direct3d programs that i do. You still are the master here in direct3d  :cool:  :thup:
Title: Re: directx9 simple 64 bits program
Post by: felipe on June 29, 2019, 05:10:00 AM
This is a windowed version with added control for errors: while loading d3d9.dll, getting the proc address (of direct3dcreate9), while creating the direct3d object and  while creating the direct3d device. Related with this error controls there is a "bug" fixed: the error messages show after some of this errors in the previous version where in a messagebox not owned by the main window. This was causing that closing the main window while showing the messagebox crashed the program  :hmmm:. Finally it's implemented a mutex to avoid running multiple instances of the same program. This can be easily bypassed by a RE but to my "software company" that's not an issue by now.  :toothy:
Title: Re: directx9 simple 64 bits program
Post by: daydreamer on June 29, 2019, 08:35:44 PM
Quote from: felipe on June 28, 2019, 02:24:20 AM
thanks. i prefer some game in 2d first, something like a character moving like in mario bros I  :bgrin:
isnt that a game with lots of pitfalls(its being a platform jumping game after all)  :bgrin:
doing great work Felipe
but with todays gpu,bruteforcing few cubes would be easy
Title: Re: directx9 simple 64 bits program
Post by: hutch-- on July 04, 2021, 08:50:59 PM
 :biggrin:

I did not know there was a New York in Ukraine.  :tongue: