Vous êtes sur la page 1sur 13

td_win32asm_070.

asm
;==============================================================================
;
Test Departments WINDOWS 32 BIT x86 ASSEMBLY examples
070
;==============================================================================
;==============================================================================
; ==> how to work with joysticks, (update !!!)
;-----------------------------------------------------------------------------; High, waiting for your man ?
;
; Here I am,
; a lot of people don't know how to work with joysticks.
; Because it could be quite simple, I think the main problem is that windows
; doesn't provide y/x client or screen coordinates ...
; If you only need a hint if a joystick is moved up/down/left or right this
; source is for you.
;
;
; Thank you.
;
;
; TD
td@crahkob.com
;
;
; This is an update because the joycaps structure was wrong (size=404 Bytes).
;==============================================================================
; Assembler directives
;-----------------------------------------------------------------------------.386
; specifies the processor our program want run on
.Model Flat ,StdCall
; always the same for Win95 (32 Bit)
option casemap:none
; case sensitive !!!
;==============================================================================
; Include all files where API functins resist you want use, set correct path
;-----------------------------------------------------------------------------includelib kernel32.lib
includelib user32.lib
includelib gdi32.lib
includelib winmm.lib
;==============================================================================
; Declaration of used API functions,take a look into WIN32.HLP and *.inc files
;-----------------------------------------------------------------------------GetModuleHandleA
PROTO :DWORD
LoadIconA
PROTO :DWORD,:DWORD
LoadCursorA
PROTO :DWORD,:DWORD
LoadImageA
PROTO :DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD
RegisterClassExA
PROTO :DWORD
CreateSolidBrush
PROTO :DWORD
CreateWindowExA
PROTO :DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD,
:DWORD,:DWORD,:DWORD,:DWORD,:DWORD
ShowWindow
PROTO :DWORD,:DWORD
UpdateWindow
PROTO :DWORD
Page 1

InvalidateRect
MoveWindow

td_win32asm_070.asm
PROTO :DWORD,:DWORD,:DWORD
PROTO :DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD

GetMessageA
TranslateMessage
DispatchMessageA
PostQuitMessage

PROTO
PROTO
PROTO
PROTO

DefWindowProcA
ExitProcess

PROTO :DWORD,:DWORD,:DWORD,:DWORD
PROTO :DWORD

MessageBoxA
SendMessageA

PROTO :DWORD,:DWORD,:DWORD,:DWORD
PROTO :DWORD,:DWORD,:DWORD,:DWORD

LoadBitmapA
DeleteObject

PROTO :DWORD,:DWORD
PROTO :DWORD

CreateRectRgn
CombineRgn
SetWindowRgn

PROTO :DWORD,:DWORD,:DWORD,:DWORD
PROTO :DWORD,:DWORD,:DWORD,:DWORD
PROTO :DWORD,:DWORD,:DWORD

timeGetDevCaps
timeSetEvent
timeKillEvent

PROTO :DWORD,:DWORD
PROTO :DWORD,:DWORD,:DWORD,:DWORD,:DWORD
PROTO :DWORD

joyGetNumDevs
joyGetDevCapsA
joyGetPos
joyGetPosEx
joyReleaseCapture
joySetCapture
joySetThreshold

PROTO
PROTO
PROTO
PROTO
PROTO
PROTO
PROTO

:DWORD,:DWORD,:DWORD,:DWORD
:DWORD
:DWORD
:DWORD

:DWORD,:DWORD,:DWORD
:DWORD,:DWORD
:DWORD,:DWORD
:DWORD
:DWORD,:DWORD,:DWORD,:DWORD
:DWORD,:DWORD

;==============================================================================
.const
;defined and fixed
;-----------------------------------------------------------------------------; - Parameter MAIN WINDOW CallBack Procedure ( API=RegisterClassExA ) WP1_CallBack
equ [ebp+4]
;return address
WP1_hWnd
equ [ebp+8]
;handle of window who receives message
WP1_uMsg
equ [ebp+12]
;the message number
WP1_wParam
equ [ebp+16]
;extra info about the message
WP1_lParam
equ [ebp+20]
;extra info about the message
;==============================================================================
.Data
;defined but not fixed
;-----------------------------------------------------------------------------CN
db "TD_joystick",0
WN
db "Joystick example - Done by Test Department",0
URL_TD
db "http://www.crahkob.com/td",0
StaticClassName
db "STATIC",0
;predefined class
MBx_Title
db "Error",0
MB0_Title
db "Attention please",0
MB0_Text
db "Please center and release joystick 1",0
Page 2

td_win32asm_070.asm
MB1_Text
db "while getting the number of joysticks your system supports.",0
MB2_Text
db "on joystick 1 while determine its capabilities.",0
MB3_Text
db "on joystick 1, unplugged.",0
;-----------------------------------------------------------------------------align 4
;align on a 4 byte boundary
;-----------------------------------------------------------------------------timer_ms
dd 05
;timer event value on startup
Xpos_main
Ypos_main
Xorg_main
Yorg_main
Xmax_main
Ymax_main

dd
dd
dd
dd
dd
dd

200
200
000
000
400
300

;X orgin point main window


;Y orgin point main window
;X position main window
;Y position main window
;max. width main window
;max. height main window

Xpos_image
Ypos_image
Xmax_image
Ymax_image

dd
dd
dd
dd

180
140
020
020

;x
;y
;x
;y

Ymin_joy
Xmin_joy
Ymax_joy
Xmax_joy
YXpos_joy

dd
dd
dd
dd
dd

0
0
0
0
0

;this value indicates a


;this value indicates a
;this value indicates a
;this value indicates a
;joystick position from

position image
position image
max. width image
max. height image
joystick movement UP
joystick movement LEFT
joystick movement DOWN
joystick movement RIGHT
MM_JOY1MOVE (value=3A0h) message

; - region datas, generated with Test Departments Region Creator/Tester reg_image_max


dd 0017
i00_0000000000 dd 0007,0001,0014,0002,0005,0002,0016,0003,0004,0003,0017,0004,0003,0004,0018,0005
i00_0000000004 dd 0003,0005,0018,0006,0002,0006,0019,0007,0002,0007,0019,0008,0002,0008,0019,0009
i00_0000000008 dd 0002,0009,0019,0010,0002,0010,0019,0011,0002,0011,0019,0012,0002,0012,0019,0013
i00_0000000012 dd 0003,0013,0018,0014,0003,0014,0018,0015,0004,0015,0017,0016,0005,0016,0016,0017
i00_0000000016 dd 0007,0017,0014,0018
;==============================================================================
.Data?
;not defined and not fixed
;-----------------------------------------------------------------------------align 4
;align on a 4 byte boundary
hEvt_effect
hWnd_image
hImg_image
hRgn_image

dd
dd
dd
dd

?
?
?
?

;handle
;handle
;handle
;handle

multimedia timerevent 2
image window
image itself
image region (I don't like squares)

; - WndClassEx Structure ( API=RegisterClassExA ) cbSize


dd ?
style
dd ?
lpfnWndProc
dd ?
cbclsExtra
dd ?
cbWndExtra
dd ?
hInstance
dd ?
hIcon
dd ?
hcursor
dd ?
Page 3

td_win32asm_070.asm
hbrBackground
lpszMenuName
lpszClassName
hIconSm

dd
dd
dd
dd

?
?
?
?

; - Msg Structure ( API=GetMessageA ) - member POINT = POINT structure


hWnd
dd ?
message
dd ?
wParam
dd ?
lParam
dd ?
time
dd ?
xpt
dd ?
ypt
dd ?
; - TIMECAPS structure wPeriodMin
dd ?
wPeriodMax
dd ?
; - JOYCAPS structure joycaps_wMid
dw ?
joycaps_wPid
dw ?
joycaps_szPname
db 32 dup (?)
joycaps_wXmin
dd ?
joycaps_wXmax
dd ?
joycaps_wYmin
dd ?
joycaps_wYmax
dd ?
joycaps_wZmin
dd ?
joycaps_wZmax
dd ?
joycaps_wNumButtons
dd ?
joycaps_wPeriodMin
dd ?
joycaps_wPeriodMax
dd ?
joycaps_wRmin
dd ?
joycaps_wRmax
dd ?
joycaps_wUmin
dd ?
joycaps_wUmax
dd ?
joycaps_wVmin
dd ?
joycaps_wVmax
dd ?
joycaps_wCaps
dd ?
joycaps_wMaxAxes
dd ?
joycaps_wNumAxes
dd ?
joycaps_wMaxButtons
dd ?
joycaps_szRegKey
db 32 dup (?)
joycaps_szOEMVxD
db 260 dup (?)
; - JOYINFOEX structure
joyinfoex_dwSize
joyinfoex_dwFlags
joyinfoex_dwXpos
joyinfoex_dwYpos
joyinfoex_dwZpos
joyinfoex_dwRpos
joyinfoex_dwUpos
joyinfoex_dwVpos

dd
dd
dd
dd
dd
dd
dd
dd

;[MAXPNAMELEN]

;[MAXPNAMELEN]
;[MAX_JOYSTICKOEMVXDNAME]

?
?
?
?
?
?
?
?
Page 4

td_win32asm_070.asm
joyinfoex_dwButtons
dd ?
joyinfoex_dwButtonNumber dd ?
joyinfoex_dwPOV
dd ?
joyinfoex_dwReserved1
dd ?
joyinfoex_dwReserved2
dd ?
;==============================================================================
.CODE
;our code area, Main=label of our program code
;-----------------------------------------------------------------------------Main:
;==============================================================================
GetProgramInstance:
;do it first
;-----------------------------------------------------------------------------push
0h
;lpModuleHandle, 0=get program handle
call
GetModuleHandleA
;- API Function mov
hInstance,eax
;return value in eax=handle of program
;==============================================================================
RegisterWindowClass:
;asign brush, icon, cursor and window procedure
;-----------------------------------------------------------------------------mov
cbSize,30h
;size in bytes of WNDCLASSEX structure
mov
style,3h
;window style
mov
lpfnWndProc,OFFSET WP1 ;address of user lpfnWndProc function
mov
cbclsExtra,0h
;extra bytes to allocate set to 0
mov
cbWndExtra,0h
;class directive in rc file
push
00000000h
;crColor, brush color value RGB
call
CreateSolidBrush
;- API Function mov
hbrBackground,eax
;handle brush, background color
mov
lpszMenuName,0h
;menu name in resource file,0=no menu
mov
lpszClassName,OFFSET CN ;name of windows Class Name
mov
hIconSm,0h
;iconhandle 0=search in rc file
push
1000
;icon-string or icon resource id
push
hInstance
;our program handle
call
LoadIconA
;- API Function mov
hIcon,eax
;handle of newly loaded icon
push
32512
;lpCursorName,default value in dezimal
push
0h
;hInstance, 0=default system cursor
call
LoadCursorA
;- API Function mov
hcursor,eax
;handle of the cursor
push
OFFSET cbSize
;pointer to WNDCLASSEX structure
call
RegisterClassExA
;- API Function ;==============================================================================
CreateMainWindow:
;create, show and update main window
;-----------------------------------------------------------------------------push
0h
;lpParam, extra pointer data 0=no data
push
hInstance
;hInstance, handle of our program
push
0h
;hMenu, handle window menu 0=class menu
push
0h
;hWndParent, handle parent window 0=no
push
Ymax_main
;intnHeight, window height pixel
push
Xmax_main
;intnWidth, window width pixel
push
Ypos_main
;inty, vertical position window
push
Xpos_main
;intx, horizontal position window
push
02CA0000h
;dwStyle, WS_POPUP, WS_SYSMENU
push
OFFSET WN
;lpWindowName, pointer to window name
Page 5

td_win32asm_070.asm
push
OFFSET CN
;lpClassName, pointer to class name
push
0h
;dwExStyle, WS_EX_TOPMOST=8h
call
CreateWindowExA
;- API Function - WS_EX_TOOLWINDOW=80h
mov
hWnd,eax
;hwnd,return value=handle of window
push
1h
;nCmdShow, show state 1=SW_SHOWNORMAL
push
hWnd
;hwnd, handle of window
call
ShowWindow
;- API Function push
hWnd
;hwnd, handle of window
call
UpdateWindow
;- API Function ;==============================================================================
LoopGetMessage:
;retrieve, translate, dispatch messages
;-----------------------------------------------------------------------------push
0h
;wMsgFilterMax, highest message value
push
0h
;wMsgFilterMin, lowest message value
push
0h
;hWnd, handle of window who gets msg.
push
OFFSET hWnd
;lpMsg, pointer to MSG structure
call
GetMessageA
;- API Function cmp
eax,0h
;check if return value=0 (exit)
je
ExitPrg
;if return value is 0 goto LABEL
push
OFFSET hWnd
;lpMSG, pointer to msg structure
call
TranslateMessage
;- API Function - keyboard code
push
OFFSET hWnd
;lpMSG, pointer to msg structure
call
DispatchMessageA
;- API Function jmp
LoopGetMessage
;check for message again, goto LABEL
;==============================================================================
ExitPrg:
;terminate our program
;-----------------------------------------------------------------------------push
hInstance
;push our programm handle to exit
call
ExitProcess
;- API Function ;##############################################################################
; The Window Procedure (API=RegisterClassExA) for this registered window.
;-----------------------------------------------------------------------------WP1:
push
ebp
;create stack frame
mov
ebp,esp
;
pushad
;push all register to the stack
mov
eax,WP1_uMsg
;move the message number to eax
;==============================================================================
WP1_uMsg_01h:
;WM_CREATE (value=01h) message received ?
;-----------------------------------------------------------------------------cmp
eax,1h
;check if WM_CREATE message recieved
jne
WP1_uMsg_02h
;if not goto LABEL
call
My_StartMsg
;- SubRoutine call
My_CheckJoystick
;- SubRoutine call
My_CreateImage
;- SubRoutine call
My_timeSetEvent
;- SubRoutine jmp
WP1_return
;==============================================================================
WP1_uMsg_02h:
;WM_DESTROY (value=02h)
;-----------------------------------------------------------------------------Page 6

td_win32asm_070.asm
cmp
eax,2h
;check if value=2h (WM_DESTROY)
jne
WP1_uMsg_0Fh
;if not 2h go to LABEL
call
My_CleanSystem
;- SubRoutine ;-----------------------------------------------------------------------------; API "PostQuitMessage" indicates to Windows a request to terminate
;-----------------------------------------------------------------------------push
0h
;nExitCode, exit code=wParam
call
PostQuitMessage
;- API Function popad
;pop all register back from stack
xor
eax,eax
;set eax to 0 to exit our program
mov
esp,ebp
;delete stack frame
pop
ebp
;
ret
10h
;return and clear stack
;==============================================================================
WP1_uMsg_0Fh:
;WM_PAINT (value=0Fh)
;-----------------------------------------------------------------------------cmp
eax,0Fh
;check if WM_PAINT message recieved
jne
WP1_uMsg_7Eh
;if not goto label
jmp

WP1_return

;==============================================================================
WP1_uMsg_7Eh:
;WM_DISPLAYCHANGE (value=7Eh)
;-----------------------------------------------------------------------------cmp
eax,7Eh
;check if WM_DISPLAYCHANGE message recieved
jne
WP1_uMsg_111h
;if not goto label
call
My_InvalidateMain
;- SubRoutine jmp

WP1_return

;==============================================================================
WP1_uMsg_111h:
;WM_COMMAND (value=111h)
;-----------------------------------------------------------------------------cmp
eax,111h
;check if WM_COMMAND message recieved
jne
WP1_uMsg_112h
;if not goto label
jmp

WP1_return

;==============================================================================
WP1_uMsg_112h:
;WM_SYSCOMMAND (value=112h)
;-----------------------------------------------------------------------------cmp
eax,112h
;check if WM_COMMAND message recieved
jne
WP1_uMsg_3A0h
;if not goto label
mov
eax,WP1_wParam
;extra info about the message
cmp
eax,0F060h
;SC_CLOSE=0F060h received ?
jne
WP1_return
call
My_CleanSystem
;- SubRoutine jmp
WP1_return
;==============================================================================
WP1_uMsg_3A0h:
;MM_JOY1MOVE (value=3A0h)
;-----------------------------------------------------------------------------Page 7

cmp
jne
mov
mov
jmp

eax,3A0h
WP1_return
eax,WP1_lParam
YXpos_joy,eax
WP1_return

td_win32asm_070.asm
;check if MM_JOY1MOVE message recieved
;if not goto label
;
;store it, analyze it in the Thread !

;==============================================================================
WP1_return:
;default message processing
;-----------------------------------------------------------------------------popad
;pop all register from stack
push
WP1_lParam
;extra info about the message
push
WP1_wParam
;extra info about the message
push
WP1_uMsg
;the message number
push
WP1_hWnd
;handle of window who receives message
call
DefWindowProcA
;- API Function mov
esp,ebp
;delete stack frame
pop
ebp
ret
10h
;return and clear stack
;==============================================================================
WP1_return_0:
;leaving, returning FALSE (0) in EAX.
;-----------------------------------------------------------------------------popad
;pop all register from stack
mov
eax,0h
;set EAX to FALSE (0)
mov
esp,ebp
;delete stack frame
pop
ebp
ret
10h
;return and clear stack
;-----------------------------------------------------------------------------WP1_return_1:
;leaving, returning TRUE (1) in EAX.
;-----------------------------------------------------------------------------popad
;pop all register from stack
mov
eax,1h
;set EAX to TRUE (1)
mov
esp,ebp
;delete stack frame
pop
ebp
ret
10h
;return and clear stack
;##############################################################################
;##############################################################################
; HIGH RESOLUTION TIMER THREAD (Mmedia.hlp), USE EXTRA STRUCTURES AND VAR's !
;-----------------------------------------------------------------------------TP1:
push
ebp
;create stack frame
mov
ebp,esp
;
pushad
;push all register to the stack
;-----------------------------------------------------------------------------Joystick1:
; check joystick
;-----------------------------------------------------------------------------mov
eax,YXpos_joy
;obtained from main window proc via MM_JoyXMove
mov
ebx,eax
;copy, yPos=HIWORD(lParam), xPos=LOWORD(lParam)
shr
eax,16
;move high word into low word, high word=0, get Ypos
and
ebx,0FFFFh
;mask high word out (set to 0) and get Xpos
JoyUp:
cmp
eax,Ymin_joy
;test if joystick moves up
Page 8

td_win32asm_070.asm
jae
JoyDown
cmp
Ypos_image,4
;limit top
jbe
TP1_return
dec
Ypos_image
;y=y-1
jmp
Image_Move
JoyDown:
cmp
eax,Ymax_joy
;test if joystick moves down
jbe
JoyLeft
cmp
Ypos_image,252
;limit bottom
jae
TP1_return
inc
Ypos_image
;y=y+1
jmp
Image_Move
JoyLeft:
cmp
ebx,Xmin_joy
;test if joystick moves left
jae
JoyRight
cmp
Xpos_image,4
;limit left
jbe
TP1_return
dec
Xpos_image
;x=x-1
jmp
Image_Move
JoyRight:
cmp
ebx,Xmax_joy
;test if jostick moves right
jbe
TP1_return
;notting happened, notting to do !
cmp
Xpos_image,372
;limit right
jae
TP1_return
inc
Xpos_image
;x=x+1
jmp
Image_Move
;-----------------------------------------------------------------------------Image_Move:
; ==> move image to new position
;-----------------------------------------------------------------------------push
01h
;bRepaint, repaint flag
push
Ymax_image
;nHeight, height
push
Xmax_image
;nWidth, width
push
Ypos_image
;Y, vertical position
push
Xpos_image
;X, horizontal position
push
hWnd_image
;hWnd, handle of window
call
MoveWindow
;- API Function ;-----------------------------------------------------------------------------TP1_return:
; ==> say ciao
;-----------------------------------------------------------------------------popad
;pop all register back from stack
mov
esp,ebp
;delete stack frame
pop
ebp
;
ret
14h
;return and clear stack (14h !!!)
;##############################################################################
;******************************************************************************
; My subroutine(s) for a compacter code resist here ...
;-----------------------------------------------------------------------------My_CreateImage:
;create window and region
;-----------------------------------------------------------------------------push
0h
;lpParam, extra pointer data 0=no data
push
hInstance
;hInstance, handle of our program
push
800
;hMenu, the child-window ID
Page 9

td_win32asm_070.asm
push
WP1_hWnd
;hWndParent, handle parent window 0=no
push
Ymax_image
;intnHeight, window height pixel
push
Xmax_image
;intnWidth, window width pixel
push
Ypos_image
;inty, vertical position window
push
Xpos_image
;intx, horizontal position window
push
5400000Eh
;dwStyle, SS_BITMAP = 0Eh
push
0h
;lpWindowName, pointer to window name
push
OFFSET StaticClassName ;lpClassName, pointer to class name
push
0h
;dwExStyle
call
CreateWindowExA
;- API Function mov
hWnd_image,eax
;hwnd, store handle of window
push
1800
;lpBitmapName, bitmap resource ID
push
hInstance
;hInstance, handle of modul instance
call
LoadBitmapA
;- API Function mov
hImg_image,eax
;hObject, handle of graphic object
push
hImg_image
;push handle of the bitmap
push
0h
;wParam, fImageType, IMAGE_BITMAP=0h
push
172h
;uMsg, STM_SETIMAGE=172h
push
hWnd_image
;hwnd, handle of destination window
call
SendMessageA
;- API Function cmp
reg_image_max,0h
;create the region
je
My_CreateImgRgn_return
mov
esi,0h
mov
ebx,OFFSET i00_0000000000
push
[ebx+12]
push
[ebx+08]
push
[ebx+04]
push
[ebx+00]
call
CreateRectRgn
mov
edi,eax
inc
esi
cmp
reg_image_max,1h
je
My_CreateImgRgn_set
My_CreateImgRgn_combine:
add
ebx,16
push
[ebx+12]
push
[ebx+08]
push
[ebx+04]
push
[ebx+00]
call
CreateRectRgn
push
eax
push
2h
push
eax
push
edi
push
edi
call
CombineRgn
call
DeleteObject
inc
esi
cmp
esi,reg_image_max
jb
My_CreateImgRgn_combine
My_CreateImgRgn_set:
mov
hRgn_image,edi
push
1h
Page 10

td_win32asm_070.asm
push
edi
push
hWnd_image
call
SetWindowRgn
My_CreateImgRgn_return:
ret
;-----------------------------------------------------------------------------My_timeSetEvent:
;set multimedia timer
;-----------------------------------------------------------------------------push
8h
;cbtc, size in bytes TIMECAPS structure
push
OFFSET wPeriodMin
;ptc, address of a TIMECAPS structure
call
timeGetDevCaps
;- API Function push
1h
;fuEvent, timer type, TIME_PERIODIC=1h
push
0h
;dwUser, user-supplied callback data
push
OFFSET TP1
;lpTimeProc, address callback function
push
wPeriodMin
;uResolution, resolution in ms
push
timer_ms
;uDelay, event delay in milliseconds
call
timeSetEvent
;- API Function mov
hEvt_effect,eax
;handle timerevent
ret
;-----------------------------------------------------------------------------My_InvalidateMain:
;performs WM_PAINT msg. if update area not empty
;-----------------------------------------------------------------------------push
0h
;bErase, erase-background flag
push
0h
;lpRect, rect structure, 0h=client area
push
WP1_hWnd
;hWnd, handle window update region
call
InvalidateRect
;- API Function ret
;-----------------------------------------------------------------------------My_CleanSystem:
;clean up the system !!!
;-----------------------------------------------------------------------------push
hEvt_effect
;uTimerID, timer event to cancel
call
timeKillEvent
;- API Function push
hRgn_image
;hObject, handle object
call
DeleteObject
;- API Function push
hImg_image
;hObject, handle object
call
DeleteObject
;- API Function ret
;-----------------------------------------------------------------------------My_CheckJoystick:
;get the number of supported joysticks
;-----------------------------------------------------------------------------call
joyGetNumDevs
;- API Function cmp
eax,0h
;if 0 no joystick avaible
je
My_ErrorBox1
;
;-----------------------------------------------------------------------------; API "joyGetDevCaps" queries a joystick to determine its capabilities.
;-----------------------------------------------------------------------------push
404
;cbjc, size in bytes of the JOYCAPS structure
push
OFFSET joycaps_wMid
;pjc, pointer to JOYCAPS structure
push
0h
;uJoyID, id joystick to be queried, JOYSTICKID1
Page 11

td_win32asm_070.asm
call
joyGetDevCapsA
;- API Function cmp
eax,0h
;0=JOYERR_NOERROR
jne
My_ErrorBox2
;on error
;-----------------------------------------------------------------------------; API "joyGetPosEx" queries a joystick for its position and button status
;-----------------------------------------------------------------------------mov
joyinfoex_dwSize,52
;size of structure
mov
joyinfoex_dwFlags,3h
;JOY_RETURNX=1h,JOY_RETURNY=2h
push
OFFSET joyinfoex_dwSize ;pji, pointer to a JOYINFO structure
push
0h
;uJoyID, id joystick (JOYSTICKID1/JOYSTICKID2)
call
joyGetPosEx
;- API Function cmp
eax,0A7h
;167=JOYERR_UNPLUGGED
je
My_ErrorBox3
;joystick unplugged
;-----------------------------------------------------------------------------; We know the center values, so we calculate the values that indicates moving !
;-----------------------------------------------------------------------------mov
eax,joyinfoex_dwXpos
;Xpos while joystick centered !
sub
eax,2500
mov
Xmin_joy,eax
;value to check for if joystick moves left
add
eax,5000
mov
Xmax_joy,eax
;value to check for if joystick moves right
mov
eax,joyinfoex_dwYpos
;Ypos while joystick centered !
sub
eax,2500
mov
Ymin_joy,eax
;value to check for if joystick moves up
add
eax,5000
mov
Ymax_joy,eax
;value to check for if joystick moves down
;-----------------------------------------------------------------------------; API "joyReleaseCapture" releases the specified captured joystick
;-----------------------------------------------------------------------------push
0h
;uJoyID, id joystick to released JOYSTICKID1=0
call
joyReleaseCapture
;- API Function ;-----------------------------------------------------------------------------; API "joySetCapture" sents the spec. joystick messages to the specified window
;-----------------------------------------------------------------------------push
0h
;fChanged, 0h=use uPeriod, 1h=use treshold
push
timer_ms
;uPeriod, polling frequency in milliseconds
push
0h
;uJoyID, id joystick, JOYSTICKID1=0
push
WP1_hWnd
;hwnd, handle window to receive joystick messages
call
joySetCapture
;- API Function ;-----------------------------------------------------------------------------; API "joySetThreshold" sets the movement threshold of a joystick, NOT USED !!!
;-----------------------------------------------------------------------------push
2
;uTreshold, new movement threshold
push
0h
;uJoyID, id joystick, JOYSTICKID1=0
call
joySetThreshold
;- API Function ret
;-----------------------------------------------------------------------------My_StartMsg:
;-----------------------------------------------------------------------------push
30h
;uType, 30h=MB_ICONEXCLAMATION
push
OFFSET MB0_Title
;lpCaption,pointer to title text
push
OFFSET MB0_Text
;lpText,pointer to text message box
Page 12

push
call
ret

WP1_hWnd
MessageBoxA

td_win32asm_070.asm
;handle of owner window 0=no owner
;- API Function -

;-----------------------------------------------------------------------------My_ErrorBox1:
;-----------------------------------------------------------------------------push
10h
;uType, 10h=MB_ICONERROR
push
OFFSET MBx_Title
;lpCaption,pointer to title text
push
OFFSET MB1_Text
;lpText,pointer to text message box
push
WP1_hWnd
;handle of owner window 0=no owner
call
MessageBoxA
;- API Function ret
;-----------------------------------------------------------------------------My_ErrorBox2:
;-----------------------------------------------------------------------------push
10h
;uType, 10h=MB_ICONERROR
push
OFFSET MBx_Title
;lpCaption,pointer to title text
push
OFFSET MB2_Text
;lpText,pointer to text message box
push
WP1_hWnd
;handle of owner window 0=no owner
call
MessageBoxA
;- API Function ret
;-----------------------------------------------------------------------------My_ErrorBox3:
;-----------------------------------------------------------------------------push
10h
;uType, 10h=MB_ICONERROR
push
OFFSET MBx_Title
;lpCaption,pointer to title text
push
OFFSET MB3_Text
;lpText,pointer to text message box
push
WP1_hWnd
;handle of owner window 0=no owner
call
MessageBoxA
;- API Function ret
;******************************************************************************
;==============================================================================
; end Main = end of our program code
;-----------------------------------------------------------------------------end Main
;end of our program code, entry point
;==============================================================================
; To create the exe file use this commands with your Microsoft Assembler/Linker
;-----------------------------------------------------------------------------; ml.exe /c /coff td_win32asm_070.asm
;asm command
; rc.exe /v rsrc.rc
;rc command
; cvtres.exe /machine:ix86 rsrc.res
; link.exe /subsystem:windows td_win32asm_070.obj rsrc.obj
;link command
;==============================================================================

Page 13

Vous aimerez peut-être aussi