-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutil.asm
195 lines (173 loc) · 4.8 KB
/
util.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
.386
.model flat, stdcall
option casemap:none
include util.inc
include windows.inc
.data
szOpenFile byte "r", 0
szFileGetLineFormat byte "%s", 0
szdPrintFormat byte "%d", 0dh, 0ah, 0
szdPrint2Format byte "%d %d", 0dh, 0ah, 0
szdPrint3Format byte "%d %d %d", 0dh, 0ah, 0
szdPrintFloatFormat byte "%f", 0dh, 0ah, 0
szdPrint2FloatFormat byte "(%f %f)", 0dh, 0ah, 0
PI REAL4 3.1415926
PIby2 REAL4 1.5707963
PIm2 REAL4 6.2831852
real0 REAL4 0.0
real1 REAL4 1.0
real2 REAL4 2.0
real1n REAL4 -1.0
real1of2 REAL4 0.5
real1of3 REAL4 0.33333
real2of3 REAL4 0.66666
real9of10 REAL4 0.9
real99of100 REAL4 0.99
real5 REAL4 5.0
real11 REAL4 11.0
real15 REAL4 15.0
real20 REAL4 20.0
real100 REAL4 100.0
MouseXi DWORD 0
MouseYi DWORD 0
MouseXf REAL4 0.0
MouseYf REAL4 0.0
.data?
fileBuffer BYTE 1024 DUP(?)
.code
dPrint proc data:DWORD
pushad
invoke printf, offset szdPrintFormat, data
popad
ret
dPrint ENDP
dPrint2 proc data0:DWORD, data1:DWORD
pushad
invoke printf, offset szdPrint2Format, data0, data1
popad
ret
dPrint2 ENDP
dPrint3 proc data0:DWORD, data1:DWORD, data2:DWORD
pushad
invoke printf, offset szdPrint3Format, data0, data1, data2
popad
ret
dPrint3 ENDP
dword2real4 PROC intValue: DWORD
local @result:DWORD
fild DWORD ptr intValue
fstp DWORD ptr @result
mov eax, @result
ret
dword2real4 ENDP
real42dword PROC realValue: REAL4
local @result:DWORD
fld DWORD ptr realValue
fistp DWORD ptr @result
mov eax, @result
ret
real42dword ENDP
dPrintFloat proc data:DWORD
local dbdata: QWORD
pushad
fld DWORD ptr data
fstp QWORD ptr dbdata
invoke printf, offset szdPrintFloatFormat, dbdata
popad
ret
dPrintFloat endp
dPrint2Float proc data0:DWORD, data1:DWORD
local dbdata0: QWORD, dbdata1:QWORD
pushad
fld DWORD ptr data0
fstp QWORD ptr dbdata0
fld DWORD ptr data1
fstp QWORD ptr dbdata1
invoke printf, offset szdPrint2FloatFormat, dbdata0, dbdata1
popad
ret
dPrint2Float endp
UpdateMousePos proc x:DWORD, y:DWORD
mov eax, x
mov MouseXi, eax
mov eax, y
mov MouseYi, eax
invoke dword2real4, MouseXi
mov MouseXf, eax
invoke dword2real4, MouseYi
mov MouseYf, eax
; invoke dPrint2, MouseXi, MouseYi
; invoke dPrint2Float, MouseXf, MouseYf
ret
UpdateMousePos endp
OpenTextFile PROC uses ebx edi esi szFileName:DWORD
invoke printf, szFileName
invoke fopen, szFileName, offset szOpenFile
ret
OpenTextFile ENDP
GetFileLine PROC uses ebx edi esi pFile:DWORD
invoke fscanf, pFile, offset szFileGetLineFormat, offset fileBuffer
mov eax, offset fileBuffer
ret
GetFileLine ENDP
CloseFile PROC uses ebx esi edi pFile:DWORD
invoke fclose, pFile
ret
CloseFile ENDP
Random PROC uses ebx esi edi
local @integer
invoke rand
and eax, 0000ffffh
; invoke dPrint, eax
mov @integer, eax
fild @integer
mov eax, 7fffh
mov @integer, eax
fidiv @integer
fstp @integer
mov eax, @integer
ret
Random ENDP
SetRect PROC uses ebx edi esi pRect:DWORD, dleft:DWORD, dtop:DWORD, dright:DWORD, dbottom:DWORD
mov edi, pRect
assume edi: PTR RECT
mov eax, dleft
mov [edi].left, eax
mov eax, dright
mov [edi].right, eax
mov eax, dtop
mov [edi].top, eax
mov eax, dbottom
mov [edi].bottom, eax
ret
SetRect ENDP
DwordToStr PROC uses ebx esi edi szStr:PTR BYTE , val:DWORD
mov esi, szStr
assume esi:PTR BYTR
mov ecx, val
.REPEAT
xor edx, edx
mov eax, ecx
mov ebx, 10
div ebx
add edx, 48
mov BYTE PTR [esi], dl
add esi, 1
mov ecx, eax
.UNTIL ecx == 0
mov BYTE PTR [esi], 0
mov eax, esi
sub eax, szStr
sub esi, 1
mov edi, szStr
.WHILE edi < esi
mov bl, [esi]
mov bh, [edi]
mov [esi], bh
mov [edi], bl
dec esi
inc edi
.ENDW
ret
DwordToStr ENDP
end