View Single Post
Old Mar 3rd, 2008, 3:21 PM   #2
Klarre
Game engine designer
 
Klarre's Avatar
 
Join Date: May 2005
Location: Sweden
Posts: 291
Rep Power: 4 Klarre is on a distinguished road
Re: [MASM32] Working with arrays

After finding the "Memory" debug window in Visual Studio, it was pretty simply to solve the bug. The functions is now looking like this and seems to work fine.

; ------------------------------------------------------------------------------
input_create proc
	invoke crt_malloc, 256	; Allocate 256 Bytes for the key array
	mov g_keys, eax	; Store the key array pointer

	invoke crt_memset, g_keys, 0, 256	; Make sure no buttons are pressed

	ret
input_create endp

; ------------------------------------------------------------------------------
input_is_key_pressed proc key:dword
	mov eax, g_keys	; Get the key array address
	add eax, key	; Offset to the correct position in the array
	mov ah, [eax]	; Read the value on the position in the array

	.if(ah)
		mov eax, 1
	.else
		mov eax, 0
	.endif

	ret
input_is_key_pressed endp
__________________
http://www.klarre.se
Klarre is online now   Reply With Quote