Heya..
Still having problems with DirectInput..
heres my DI code.. see anything wrong here? I'm getting nothing :(


KEYDOWN MACRO chaz
lea esi,KeyboardState
add esi,chaz
mov al,byte ptr
and eax,80h
shr eax,7
ENDM

.data
m_rRotate REAL4 0.0f
fphalf REAL4 0.500f
fp20 REAL4 20.0f
fpdummy REAL4 0.0f
m_rScale REAL4 0.0f
.code

InitializeDI PROC hWnd:HWND
mov esi,hWnd
push esi
invoke DirectInput8Create,hInstance,DIRECTINPUT_VERSION,offset IID_IDirectInput8A,offset lpDI,NULL
.if eax!=DI_OK
pop esi
invoke MessageBox,0,CTXT("Failed to create IDirectInput8A - KeyBoard"),CTXT("ERROR"),MB_OK+MB_ICONERROR
return FALSE
.endif
mcall ,IDirectInput8A_CreateDevice,offset GUID_SysKeyboard,offset lpDIDkboard,NULL
.if eax!=DI_OK
pop esi
invoke MessageBox,0,CTXT("Failed to create IDirectInputDevice8A- KeyBoard"),CTXT("ERROR"),MB_OK+MB_ICONERROR
return FALSE
.endif
mcall ,IDirectInputDevice8A_SetDataFormat,offset c_dfDIKeyboard
.if eax!=DI_OK
pop esi
invoke MessageBox,0,CTXT("Failed to SetDataFormat- KeyBoard"),CTXT("ERROR"),MB_OK+MB_ICONERROR
return FALSE
.endif
pop esi
mcall ,IDirectInputDevice8A_SetCooperativeLevel,esi,DISCL_NONEXCLUSIVE OR DISCL_FOREGROUND
.if eax!=DI_OK
.if eax==DIERR_INVALIDPARAM
invoke MessageBox,0,CTXT("Failed to SetCoopLevel- Invalid Param"),CTXT("ERROR"),MB_OK+MB_ICONERROR
; .elseif eax==DIERR_NOTINITIALIZED
; invoke MessageBox,0,CTXT("Failed to SetCoopLevel- Not Initialized"),CTXT("ERROR"),MB_OK+MB_ICONERROR
.elseif eax==E_HANDLE
invoke MessageBox,0,CTXT("Failed to SetCoopLevel- Invalid TopLevelHandle"),CTXT("ERROR"),MB_OK+MB_ICONERROR
.else
invoke MessageBox,0,CTXT("Failed to SetCoopLevel- Undefined"),CTXT("ERROR"),MB_OK+MB_ICONERROR
.endif
return FALSE
.endif
mcall ,IDirectInputDevice8A_Acquire
return TRUE
InitializeDI ENDP

DestroyDI PROC
mcall ,IDirectInputDevice8A_Unacquire
mcall ,IDirectInputDevice8A_Release
mcall ,IDirectInput8A_Release
ret
DestroyDI ENDP


.data?
KeyboardState db 256 dup (?)
.code

ProcessKeyboard PROC
invoke RtlZeroMemory,addr KeyboardState,256
mcall ,IDirectInputDevice8A_GetDeviceState,256,addr KeyboardState
.if eax==E_FAIL
invoke MessageBox,0,CTXT("Failed to read keyboard"),CTXT("ERROR"),MB_OK+MB_ICONERROR
ret
.endif

lea esi,KeyboardState
mov ecx,31h
.REPEAT
push ecx
mov al,byte ptr
and eax,80h
shr eax,7
.if eax==1
invoke MessageBox,0,CTXT("Ettert"),CTXT("DFfdt"),MB_OK
.endif
pop ecx
inc ecx
.UNTIL ecx==39h
KEYDOWN DIK_ESCAPE
.if eax==TRUE
; //Escape key pressed. Quit game.
; m_fQuit = true;
.endif

; ***Rotation Keys***
KEYDOWN DIK_NUMPAD9
.if eax==TRUE
fld m_rRotate
fsub fphalf
fstp m_rRotate
.endif
KEYDOWN DIK_NUMPAD7
.if eax==TRUE
fld m_rRotate
fadd fphalf
fstp m_rRotate
.endif

KEYDOWN DIK_NUMPAD6
.if eax==TRUE
fld eye_vector.x
fadd fphalf
fstp eye_vector.x
.endif
KEYDOWN DIK_NUMPAD4
.if eax==TRUE
fld eye_vector.x
fsub fphalf
fstp eye_vector.x
.endif
KEYDOWN DIK_NUMPAD1
.if eax==TRUE
fld eye_vector.y
fsub fphalf
fstp eye_vector.y
.endif
KEYDOWN DIK_NUMPAD3
.if eax==TRUE
fld eye_vector.y
fadd fphalf
fstp eye_vector.y
.endif
KEYDOWN DIK_NUMPAD8
.if eax==TRUE
fld eye_vector.z
fadd fphalf
fstp eye_vector.z
.endif
KEYDOWN DIK_NUMPAD2
.if eax==TRUE
fld eye_vector.z
fsub fphalf
fstp eye_vector.z
.endif

; ; //Set an upper and lower limit for the rotation factor
; fld fp20 ;is rotation less than -20?
; fchs
; fcom m_rRotate
; jge @F
; fstp m_rRotate
; jmp kk1
; @@:
; fstp fpdummy
; kk1:
; fld fp20
; fcom m_rRotate
; jle @F
; fld fp20
; fstp m_rRotate
; jmp kk2
; @@:
; fstp fpdummy
; kk2:

; //Scale Earth
KEYDOWN DIK_UP
.if eax==TRUE
fld m_rScale
fadd fphalf
fstp m_rScale
.endif
KEYDOWN DIK_DOWN
.if eax==TRUE
fld m_rScale
fsub fphalf
fstp m_rScale
.endif

; //Set an upper and lower limit for the scale factor
fld1
fcom m_rScale
jge @F
fstp m_rScale
jmp kk3
@@:
fstp fpdummy
kk3:
fld fp20
fcom m_rScale
jle @F
fstp m_rScale
jmp kk4
@@:
fstp fpdummy
kk4:
ret
ProcessKeyboard ENDP
Posted on 2003-05-05 11:07:41 by Homer
Please please oh please oh please help me get DI working !!
To this end, here's my "Scrontified" version of the DI include...
Posted on 2003-05-08 02:18:57 by Homer
Bogdan, I'm calling the GetDeviceState function from ProcessKeyboard, in turn called from my Render procedure, so it should be polling at the current framerate :(
Posted on 2003-05-08 02:28:22 by Homer
Ok

I will check it out in more detail when i will get a little free time (like tonight)
Posted on 2003-05-08 03:07:28 by BogdanOntanu
Heya.. anything obvious? woe is me :(
Posted on 2003-05-10 02:14:39 by Homer
Please excuse, i just forgot to check this out ...

On first fast look

KEYDOWN MACRO chaz
lea esi,KeyboardState
add esi,chaz
mov al,byte ptr
and eax,80h
shr eax,7
ENDM



You can not do keydown like this: It is a KEYDOWN event ONLY if oldstate was KEYUP and now is KEYDOWN

What exactly is the thing that is not working?

:stupid:
Posted on 2003-05-12 04:14:46 by BogdanOntanu
Bogdan, it initializes ok , no errors.
It just never senses any keypresses - ever.
That code I posted I'd modified to sense for number keys,
just while screwing around trying to figure out what was wrong.

I call my polling function from my Render procedure, but it never senses any keypresses.

Why can't I poll for keydown like that, by the way?
afaik if bit seven is on, the key is down, and thats as complicated as it gets !!
I don't keep the state of my keyboard array, its a local.
I assumed that the polling function would just read 256 bytes into it and overwrite its contents, rather than mask them properly.
Should I keep state like a regular keyboardarray?
Posted on 2003-05-13 11:10:52 by Homer
groans:mad:
Posted on 2003-05-20 03:54:24 by Homer
well it must be some initialization, or bad GUID for system keyboard issue...

I use to read the keyboard prety well in HE using same DirectInput man

I do have a full old 256 keys state saved in HE because i want to detect just when a key went down and not to do it again on next game loop... but i guess that it is Ok not to keep such states IF you do not need it

However i would not use LOCAL storage buffers for DirectInput as those are alocated on your procedure stack and i do not know IF Directinput that is somehow event and thread based will be able to properly acces those local buffers... have you tryied with global buffers ?
Posted on 2003-05-23 13:50:49 by BogdanOntanu
Now what you said there makes a lot of sense - but I've actually had more trouble with dynamic memory and dx (application heap via GlobalAlloc) than I have with locals and dx (Thread Stack)
Both are supposedly mapped into the process's memory space, and yet under xp I get the occasional acces violation while doing something innocuous like copying data from a dx buffer to a dynamically allocated one (which threw no errors when it was allocated). More often than not they are generated not by my code as such but within DX itself, and further proof is that when run under a debugger, these exceptions are often handled transparently by the debugger's exception handler - in other words, the one provided by default when you compile under masm is not up to scratch?
Methinks this is not my doing !! I have a macro I use for debugging - its job is to place canary values on the stack before calling a suspect proc, and then check the stack afterwards, it alerts to corruption of the stack, and if possible will correct the stack and tell you how much it was out by and in what direction.
I'm not a bad coder - my stack is good - why this intermittent exception in d3d8.dll? Seen anything like it? Could I have an ecclectic mix of DX8 and 8.1 includes causing an issue or would that be safe? Worst thing that could happen is a stack misalignment due to incorrect #parms, right? (which my macro would detect...)
I don't think the GUIDs changed ...
Posted on 2003-05-25 12:05:11 by Homer
Maybe this is not much help, but anyhow, I compared the code of yours you've posted to my c++ class for directinput ( I have never used asm for directx yet, but it's still not hard to compare ) in my game I'm doing, some weeks ago, when you first posted it.
It is almost exactly the same as far as I can see, I tried change the few places in my code that didn't match yours so it would be the same, and it still worked good.

Maybe you could make a tiny test app with your dinput code, that just test for keypress and show the pressed key in a window, and upload, and let people test it...or is it stupid idea?
Posted on 2003-05-26 12:16:36 by david
I'll do that - I've been playing with FASM a little lately, but yes, its a good idea, and one I will follow up.
Posted on 2003-05-29 09:20:50 by Homer
BTW ...

You are using ::Aquire to catch the input ?
Posted on 2003-05-29 11:36:51 by BogdanOntanu
Bogdan, you disappoint me !!
Look up :eek:

...
mcall ,IDirectInputDevice8A_Acquire
return TRUE
InitializeDI ENDP
Posted on 2003-06-07 00:18:56 by Homer
Hehe :P

Well it was just a wild guess, but you know you will have to ::Aquire each time you read the keyboard do you ?
or at least each time you might loose "focus" , just to know because we had some problems with this in HE at the beginning

We are not using DI8 in HE -- i guess just DI3 or DI5 but besides that i can not find any problems in your code. I must be a very simple bug (so simple we overlook it) or a wrong constant

Well we are also using: DISCL_EXCLUSIVE OR DISCL_FOREGROUND and sometimes found others not to work ... so try this also
Posted on 2003-06-07 10:37:58 by BogdanOntanu
Ok, already tried the other modes too - tell me a little about how to detect when you have "lost focus" please - do we get any notification of this? Is it a matter of reacquiring it ?
Posted on 2003-06-09 09:31:20 by Homer
We just reaquire it every time :D bluntly but it works

besides i guess only WM_ACTIVATEAPP might help but i found it very unreliable
Posted on 2003-06-09 11:34:04 by BogdanOntanu
omg ur kidding?
So you're like calling Acquire from your polling code - and the COM object is looking at its internal reference counter and returning early if it doesnt have to reacquire?
What I'm saying is - have you measured the time you are losing by doing this?
It certainly sounds barbaric, but I'm sure it works wonderfully :)

I'll try it and let you know if that resolves the issue, but surely there's a cleaner way of doing it lol...
Posted on 2003-06-12 02:46:15 by Homer
Obviousely you have miss read the documentation...

now i know i am not an native english speaker but still :D
below is a portion of DX SDK info... i think they say MUST

LOL



....
Remarks
Before a device can be acquired,
a data format must be set by using the IDirectInputDevice::SetDataFormat method.

Devices must be acquired before calling the IDirectInputDevice::GetDeviceState
or IDirectInputDevice::GetDeviceData methods for that device.

Device acquisition does not use a reference count.
Therefore, if an application calls the IDirectInputDevice::Acquire method twice,
then calls the IDirectInputDevice::Unacquire method once, the device is unacquired.
....

Posted on 2003-06-12 11:20:53 by BogdanOntanu
Ok, so it has no ref counter - thats irrelevant - setting the data format is more relevant, or it would be if I was not already doing it.
I followed an m$ implementation (taken from Donuts3D actually) the source to which I have provided already. My code checks for all return values, excepting the return value from Acquire(). I've never seen any example source which called Acquire() more than once, but I see that it couldn't hurt. Thanks.
Posted on 2003-06-13 23:38:15 by Homer