Rev 5486 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 5486 | Rev 8014 | ||
---|---|---|---|
1 | ; Files *.asc routines by Maciej Guba |
1 | ; Files *.asc routines by Maciej Guba |
2 | ; Thanks to Reverend for integer/float/ascii conversion examples |
2 | ; Thanks to Reverend for integer/float/ascii conversion examples |
3 | read_asc: |
3 | read_asc: |
4 | mov eax,[fptr] |
4 | mov eax,[fptr] |
5 | .find_vert: |
5 | .find_vert: |
6 | cmp dword[eax],'Vert' |
6 | cmp dword[eax],'Vert' |
7 | je @f |
7 | je @f |
8 | inc eax |
8 | inc eax |
9 | jmp .find_vert |
9 | jmp .find_vert |
10 | @@: |
10 | @@: |
11 | add eax,4 |
11 | add eax,4 |
12 | cmp dword[eax],'ices' |
12 | cmp dword[eax],'ices' |
13 | jne .find_vert |
13 | jne .find_vert |
14 | add eax,3 |
14 | add eax,3 |
15 | @@: |
15 | @@: |
16 | inc eax |
16 | inc eax |
17 | cmp byte[eax],'0' ; search end of ascii number of vertices string |
17 | cmp byte[eax],'0' ; search end of ascii number of vertices string |
18 | jb @b |
18 | jb @b |
19 | cmp byte[eax],'9' |
19 | cmp byte[eax],'9' |
20 | ja @b |
20 | ja @b |
21 | ; eax - start ascii number |
21 | ; eax - start ascii number |
22 | @@: |
22 | @@: |
23 | inc eax |
23 | inc eax |
24 | cmp byte[eax],'0' |
24 | cmp byte[eax],'0' |
25 | jb .convert1 |
25 | jb .convert1 |
26 | cmp byte[eax],'9' |
26 | cmp byte[eax],'9' |
27 | ja .convert1 |
27 | ja .convert1 |
28 | jmp @b |
28 | jmp @b |
29 | .convert1: |
29 | .convert1: |
30 | dec eax |
30 | dec eax |
31 | mov ebx,eax |
31 | mov ebx,eax |
32 | push eax |
32 | push eax |
33 | call ascii_to_integer |
33 | call ascii_to_integer |
34 | mov [points_count_var],dx |
34 | mov [points_count_var],edx |
35 | pop eax |
35 | pop eax |
36 | 36 | ||
37 | @@: |
37 | @@: |
38 | inc eax |
38 | inc eax |
39 | cmp dword[eax],'Face' |
39 | cmp dword[eax],'Face' |
40 | jne @b |
40 | jne @b |
41 | add eax,3 |
41 | add eax,3 |
42 | @@: |
42 | @@: |
43 | inc eax |
43 | inc eax |
44 | cmp byte[eax],'0' |
44 | cmp byte[eax],'0' |
45 | jb @b |
45 | jb @b |
46 | cmp byte[eax],'9' |
46 | cmp byte[eax],'9' |
47 | ja @b |
47 | ja @b |
48 | ; eax - start ascii number |
48 | ; eax - start ascii number |
49 | @@: |
49 | @@: |
50 | inc eax |
50 | inc eax |
51 | cmp byte[eax],'0' |
51 | cmp byte[eax],'0' |
52 | jb .convert2 |
52 | jb .convert2 |
53 | cmp byte[eax],'9' |
53 | cmp byte[eax],'9' |
54 | ja .convert2 |
54 | ja .convert2 |
55 | jmp @b |
55 | jmp @b |
56 | ; eax - end ascii number |
56 | ; eax - end ascii number |
57 | .convert2: |
57 | .convert2: |
58 | dec eax |
58 | dec eax |
59 | mov ebx,eax |
59 | mov ebx,eax |
60 | push eax |
60 | push eax |
61 | call ascii_to_integer |
61 | call ascii_to_integer |
62 | mov [triangles_count_var],dx |
62 | mov [triangles_count_var],edx |
63 | pop eax |
63 | pop eax |
64 | 64 | ||
65 | @@: |
65 | @@: |
66 | inc eax |
66 | inc eax |
67 | cmp dword[eax],'Vert' |
67 | cmp dword[eax],'Vert' |
68 | jnz @b |
68 | jnz @b |
69 | inc eax |
69 | inc eax |
70 | 70 | ||
71 | mov edi,[points_ptr] |
71 | mov edi,[points_ptr] |
72 | xor ebx,ebx |
72 | xor ebx,ebx |
73 | .decode_vertices: |
73 | .decode_vertices: |
74 | push ebx |
74 | push ebx |
75 | @@: |
75 | @@: |
76 | inc eax |
76 | inc eax |
77 | cmp dword[eax],'Vert' |
77 | cmp dword[eax],'Vert' |
78 | jne @b |
78 | jne @b |
79 | xor ecx,ecx |
79 | xor ecx,ecx |
80 | 80 | ||
81 | .decode_coord: |
81 | .decode_coord: |
82 | push ecx |
82 | push ecx |
83 | @@: |
83 | @@: |
84 | inc eax |
84 | inc eax |
85 | mov dl,byte[eax] |
85 | mov dl,byte[eax] |
86 | cmp dl,byte[XYZpartices+ecx] |
86 | cmp dl,byte[XYZpartices+ecx] |
87 | jne @b |
87 | jne @b |
88 | @@: |
88 | @@: |
89 | inc eax |
89 | inc eax |
90 | cmp byte[eax],'.' |
90 | cmp byte[eax],'.' |
91 | je .readF |
91 | je .readF |
92 | cmp byte[eax],'-' |
92 | cmp byte[eax],'-' |
93 | je .readF |
93 | je .readF |
94 | cmp byte[eax],'0' |
94 | cmp byte[eax],'0' |
95 | jb @b |
95 | jb @b |
96 | cmp byte[eax],'9' |
96 | cmp byte[eax],'9' |
97 | ja @b |
97 | ja @b |
98 | .readF: ; read float |
98 | .readF: ; read float |
99 | mov esi,eax |
99 | mov esi,eax |
100 | push eax |
100 | push eax |
101 | push ecx |
101 | push ecx |
102 | 102 | ||
103 | call atof ; st0 - desired dword float |
103 | call atof ; st0 - desired dword float |
104 | 104 | ||
105 | pop ecx |
105 | pop ecx |
106 | pop eax |
106 | pop eax |
107 | 107 | ||
108 | fstp dword[edi] |
108 | fstp dword[edi] |
109 | add edi,4 |
109 | add edi,4 |
110 | 110 | ||
111 | pop ecx |
111 | pop ecx |
112 | inc ecx |
112 | inc ecx |
113 | cmp ecx,3 |
113 | cmp ecx,3 |
114 | jne .decode_coord |
114 | jne .decode_coord |
115 | pop ebx |
115 | pop ebx |
116 | inc ebx |
116 | inc ebx |
117 | cmp bx,[points_count_var] |
117 | cmp ebx,[points_count_var] |
118 | jne .decode_vertices |
118 | jne .decode_vertices |
119 | mov dword[edi],-1 |
119 | mov dword[edi],-1 |
120 | 120 | ||
121 | 121 | ||
122 | 122 | ||
123 | mov esi,eax |
123 | mov esi,eax |
124 | @@: |
124 | @@: |
125 | inc esi |
125 | inc esi |
126 | cmp dword[esi],'Face' |
126 | cmp dword[esi],'Face' |
127 | jne @b |
127 | jne @b |
128 | xor edx,edx |
128 | xor edx,edx |
129 | mov edi,[triangles_ptr] |
129 | mov edi,[triangles_ptr] |
130 | cld |
130 | cld |
131 | .decode_face: |
131 | .decode_face: |
132 | 132 | ||
133 | push edx |
133 | push edx |
134 | @@: |
134 | @@: |
135 | inc esi |
135 | inc esi |
136 | cmp dword[esi],'Face' |
136 | cmp dword[esi],'Face' |
137 | jne @b |
137 | jne @b |
138 | @@: |
138 | @@: |
139 | inc esi |
139 | inc esi |
140 | cmp byte[esi],'0' ; face number start |
140 | cmp byte[esi],'0' ; face number start |
141 | jb @b |
141 | jb @b |
142 | cmp byte[esi],'9' |
142 | cmp byte[esi],'9' |
143 | ja @b |
143 | ja @b |
144 | @@: |
144 | @@: |
145 | inc esi |
145 | inc esi |
146 | cmp byte[esi],'0' |
146 | cmp byte[esi],'0' |
147 | jb @f |
147 | jb @f |
148 | cmp byte[esi],'9' ; face number end |
148 | cmp byte[esi],'9' ; face number end |
149 | ja @f |
149 | ja @f |
150 | jmp @b |
150 | jmp @b |
151 | @@: |
151 | @@: |
152 | xor ecx,ecx |
152 | xor ecx,ecx |
153 | .next_vertex_number: |
153 | .next_vertex_number: |
154 | 154 | ||
155 | push ecx |
155 | push ecx |
156 | @@: |
156 | @@: |
157 | inc esi |
157 | inc esi |
158 | cmp byte[esi],'0' |
158 | cmp byte[esi],'0' |
159 | jb @b |
159 | jb @b |
160 | cmp byte[esi],'9' |
160 | cmp byte[esi],'9' |
161 | ja @b |
161 | ja @b |
162 | ; eax - start ascii number |
162 | ; eax - start ascii number |
163 | @@: |
163 | @@: |
164 | inc esi |
164 | inc esi |
165 | cmp byte[esi],'0' |
165 | cmp byte[esi],'0' |
166 | jb @f |
166 | jb @f |
167 | cmp byte[esi],'9' |
167 | cmp byte[esi],'9' |
168 | ja @f |
168 | ja @f |
169 | jmp @b |
169 | jmp @b |
170 | ; eax - end ascii number |
170 | ; eax - end ascii number |
171 | @@: |
171 | @@: |
172 | dec esi |
172 | dec esi |
173 | mov ebx,esi |
173 | mov ebx,esi |
174 | push esi |
174 | push esi |
175 | call ascii_to_integer |
175 | call ascii_to_integer |
176 | mov eax,edx |
176 | mov eax,edx |
177 | 177 | ||
178 | stosw |
178 | stosd |
179 | pop esi |
179 | pop esi |
180 | add esi,2 |
180 | add esi,4 |
181 | 181 | ||
182 | pop ecx |
182 | pop ecx |
183 | inc ecx |
183 | inc ecx |
184 | cmp ecx,3 |
184 | cmp ecx,3 |
185 | jne .next_vertex_number |
185 | jne .next_vertex_number |
186 | pop edx |
186 | pop edx |
187 | inc edx |
187 | inc edx |
188 | cmp dx,[triangles_count_var] |
188 | cmp edx,[triangles_count_var] |
189 | jne .decode_face |
189 | jne .decode_face |
190 | mov dword[edi],-1 ;dword[triangles+ebx+2],-1 ; end mark |
190 | mov dword[edi],-1 ;dword[triangles+ebx+2],-1 ; end mark |
191 | mov eax,1 ;-> mark if ok |
191 | mov eax,1 ;-> mark if ok |
192 | ret |
192 | ret |
193 | 193 | ||
194 | ascii_to_integer: |
194 | ascii_to_integer: |
195 | ; in --- [ebx] -> end of ascii string |
195 | ; in --- [ebx] -> end of ascii string |
196 | ; out -- edx -> desired number |
196 | ; out -- edx -> desired number |
197 | xor edx,edx |
197 | xor edx,edx |
198 | xor ecx,ecx |
198 | xor ecx,ecx |
199 | .again: |
199 | .again: |
200 | movzx eax,byte[ebx] |
200 | movzx eax,byte[ebx] |
201 | sub al,'0' |
201 | sub al,'0' |
202 | cwde |
202 | cwde |
203 | push edx |
203 | push edx |
204 | mul dword[convert_muler+ecx] |
204 | mul dword[convert_muler+ecx] |
205 | pop edx |
205 | pop edx |
206 | add edx,eax |
206 | add edx,eax |
207 | dec ebx |
207 | dec ebx |
208 | cmp byte[ebx],'0' |
208 | cmp byte[ebx],'0' |
209 | jb .end |
209 | jb .end |
210 | cmp byte[ebx],'9' |
210 | cmp byte[ebx],'9' |
211 | ja .end |
211 | ja .end |
212 | add ecx,4 |
212 | add ecx,4 |
213 | jmp .again |
213 | jmp .again |
214 | @@: |
214 | @@: |
215 | 215 | ||
216 | .end: |
216 | .end: |
217 | ret |
217 | ret |
218 | 218 | ||
219 | ;=============================================================================== |
219 | ;=============================================================================== |
220 | ; ASCII to float conversion procedure |
220 | ; ASCII to float conversion procedure |
221 | ; |
221 | ; |
222 | ; input: |
222 | ; input: |
223 | ; esi - pointer to string |
223 | ; esi - pointer to string |
224 | ; |
224 | ; |
225 | ; output: |
225 | ; output: |
226 | ; st0 - number changed into float |
226 | ; st0 - number changed into float |
227 | ; |
227 | ; |
228 | ;=============================================================================== |
228 | ;=============================================================================== |
229 | 229 | ||
230 | atof: |
230 | atof: |
231 | .string equ ebp-4 |
231 | .string equ ebp-4 |
232 | 232 | ||
233 | push ebp |
233 | push ebp |
234 | mov ebp,esp |
234 | mov ebp,esp |
235 | sub esp,32 |
235 | sub esp,32 |
236 | push eax ecx esi |
236 | push eax ecx esi |
237 | mov [.string],esi |
237 | mov [.string],esi |
238 | fninit |
238 | fninit |
239 | fldz |
239 | fldz |
240 | fldz |
240 | fldz |
241 | 241 | ||
242 | cld |
242 | cld |
243 | cmp byte [esi], '-' |
243 | cmp byte [esi], '-' |
244 | jnz @F |
244 | jnz @F |
245 | inc esi |
245 | inc esi |
246 | @@: |
246 | @@: |
247 | xor eax, eax |
247 | xor eax, eax |
248 | align 4 |
248 | align 4 |
249 | .loop.integer_part: |
249 | .loop.integer_part: |
250 | lodsb |
250 | lodsb |
251 | cmp al, '.' |
251 | cmp al, '.' |
252 | jz .mantisa |
252 | jz .mantisa |
253 | cmp al,'0' |
253 | cmp al,'0' |
254 | jb .exit |
254 | jb .exit |
255 | cmp al,'9' |
255 | cmp al,'9' |
256 | ja .exit |
256 | ja .exit |
257 | fimul [i10] |
257 | fimul [i10] |
258 | sub al, '0' |
258 | sub al, '0' |
259 | push eax |
259 | push eax |
260 | fiadd dword [esp] |
260 | fiadd dword [esp] |
261 | add esp, 4 |
261 | add esp, 4 |
262 | jmp .loop.integer_part |
262 | jmp .loop.integer_part |
263 | 263 | ||
264 | .mantisa: |
264 | .mantisa: |
265 | xor ecx, ecx |
265 | xor ecx, ecx |
266 | xor eax, eax |
266 | xor eax, eax |
267 | cld |
267 | cld |
268 | fxch st1 |
268 | fxch st1 |
269 | @@: |
269 | @@: |
270 | 270 | ||
271 | lodsb |
271 | lodsb |
272 | cmp al,'0' |
272 | cmp al,'0' |
273 | jb .exit |
273 | jb .exit |
274 | cmp al,'9' |
274 | cmp al,'9' |
275 | ja .exit |
275 | ja .exit |
276 | cmp ecx,7*4 |
276 | cmp ecx,7*4 |
277 | je .exit ; max 7 digits in mantisa |
277 | je .exit ; max 7 digits in mantisa |
278 | sub al,'0' |
278 | sub al,'0' |
279 | push eax |
279 | push eax |
280 | fild dword[esp] |
280 | fild dword[esp] |
281 | fidiv dword[convert_muler+4+ecx] |
281 | fidiv dword[convert_muler+4+ecx] |
282 | faddp |
282 | faddp |
283 | add esp,4 |
283 | add esp,4 |
284 | add ecx,4 |
284 | add ecx,4 |
285 | jmp @b |
285 | jmp @b |
286 | .exit: |
286 | .exit: |
287 | faddp |
287 | faddp |
288 | 288 | ||
289 | mov eax, [.string] |
289 | mov eax, [.string] |
290 | cmp byte [eax], '-' |
290 | cmp byte [eax], '-' |
291 | jnz @F |
291 | jnz @F |
292 | fchs |
292 | fchs |
293 | @@: |
293 | @@: |
294 | cld |
294 | cld |
295 | stc ; always returns no error |
295 | stc ; always returns no error |
296 | pop esi ecx eax |
296 | pop esi ecx eax |
297 | mov esp,ebp |
297 | mov esp,ebp |
298 | pop ebp |
298 | pop ebp |
299 | ret |
299 | ret |
300 | 300 | ||
301 | 301 | ||
302 | itoa: ; unsigned dword integer to ascii procedure |
302 | itoa: ; unsigned dword integer to ascii procedure |
303 | ; in eax - variable |
303 | ; in eax - variable |
304 | ; esi - Pointer to ascii string |
304 | ; esi - Pointer to ascii string |
305 | ; out esi - desired ascii string |
305 | ; out esi - desired ascii string |
306 | ; edi - end of ascii string - ptr to memory |
306 | ; edi - end of ascii string - ptr to memory |
307 | .temp_string equ dword[ebp-36] |
307 | .temp_string equ dword[ebp-36] |
308 | .ptr equ dword[ebp-40] |
308 | .ptr equ dword[ebp-40] |
309 | .var equ dword[ebp-44] |
309 | .var equ dword[ebp-44] |
310 | push ecx |
310 | push ecx |
311 | push ebp |
311 | push ebp |
312 | mov ebp,esp |
312 | mov ebp,esp |
313 | sub esp,64 |
313 | sub esp,64 |
314 | mov .var,eax |
314 | mov .var,eax |
315 | mov eax,-1 |
315 | mov eax,-1 |
316 | lea edi,.temp_string |
316 | lea edi,.temp_string |
317 | cld |
317 | cld |
318 | mov ecx,9 |
318 | mov ecx,9 |
319 | rep stosd ; make floor |
319 | rep stosd ; make floor |
320 | 320 | ||
321 | 321 | ||
322 | mov .ptr,esi |
322 | mov .ptr,esi |
323 | lea edi,.temp_string |
323 | lea edi,.temp_string |
324 | add edi,34 |
324 | add edi,34 |
325 | std |
325 | std |
326 | xor eax,eax |
326 | xor eax,eax |
327 | stosb ; mark begin |
327 | stosb ; mark begin |
328 | mov eax,.var |
328 | mov eax,.var |
329 | mov esi,10 |
329 | mov esi,10 |
330 | @@: |
330 | @@: |
331 | xor edx,edx |
331 | xor edx,edx |
332 | div esi |
332 | div esi |
333 | xchg eax,edx |
333 | xchg eax,edx |
334 | add al,'0' |
334 | add al,'0' |
335 | stosb |
335 | stosb |
336 | xchg eax,edx |
336 | xchg eax,edx |
337 | or eax,eax |
337 | or eax,eax |
338 | jnz @b |
338 | jnz @b |
339 | stosb ; mark end |
339 | stosb ; mark end |
340 | 340 | ||
341 | lea esi,.temp_string |
341 | lea esi,.temp_string |
342 | cld |
342 | cld |
343 | @@: |
343 | @@: |
344 | lodsb |
344 | lodsb |
345 | or al,al |
345 | or al,al |
346 | jnz @b |
346 | jnz @b |
347 | 347 | ||
348 | mov edi,.ptr |
348 | mov edi,.ptr |
349 | @@: |
349 | @@: |
350 | lodsb |
350 | lodsb |
351 | stosb |
351 | stosb |
352 | or al,al |
352 | or al,al |
353 | jnz @b |
353 | jnz @b |
354 | 354 | ||
355 | mov esp,ebp |
355 | mov esp,ebp |
356 | pop ebp |
356 | pop ebp |
357 | pop ecx |
357 | pop ecx |
358 | ret |
358 | ret |
359 | if 1 |
359 | if 1 |
360 | ftoa_mac: |
360 | ftoa_mac: |
361 | ; in : esi - pointer to dword float |
361 | ; in : esi - pointer to dword float |
362 | ; edi - pointer to ascii string |
362 | ; edi - pointer to ascii string |
363 | .ptr_f equ dword[ebp-4] |
363 | .ptr_f equ dword[ebp-4] |
364 | .sign equ dword[ebp-8] ; 0 -> less than zero, 1 - otherwise |
364 | .sign equ dword[ebp-8] ; 0 -> less than zero, 1 - otherwise |
365 | .ptr_ascii equ dword[ebp-12] |
365 | .ptr_ascii equ dword[ebp-12] |
366 | .integer equ dword[ebp-20] |
366 | .integer equ dword[ebp-20] |
367 | .fraction equ dword[ebp-28] |
367 | .fraction equ dword[ebp-28] |
368 | .status_orginal equ word[ebp-32] |
368 | .status_orginal equ word[ebp-32] |
369 | .status_changed equ word[ebp-34] |
369 | .status_changed equ word[ebp-34] |
370 | push ecx |
370 | push ecx |
371 | push ebp |
371 | push ebp |
372 | mov ebp,esp |
372 | mov ebp,esp |
373 | sub esp,64 |
373 | sub esp,64 |
374 | fninit |
374 | fninit |
375 | fnstcw .status_orginal |
375 | fnstcw .status_orginal |
376 | mov ax, .status_orginal |
376 | mov ax, .status_orginal |
377 | or ax, 0000110000000000b |
377 | or ax, 0000110000000000b |
378 | mov .status_changed, ax |
378 | mov .status_changed, ax |
379 | fldcw .status_changed |
379 | fldcw .status_changed |
380 | ; -------------------------------- |
380 | ; -------------------------------- |
381 | ; check if signed |
381 | ; check if signed |
382 | xor eax, eax |
382 | xor eax, eax |
383 | fld dword[esi] |
383 | fld dword[esi] |
384 | fst .sign |
384 | fst .sign |
385 | test .sign, 80000000h |
385 | test .sign, 80000000h |
386 | setz al |
386 | setz al |
387 | mov .sign, eax |
387 | mov .sign, eax |
388 | 388 | ||
389 | mov .ptr_f,esi |
389 | mov .ptr_f,esi |
390 | mov .ptr_ascii,edi |
390 | mov .ptr_ascii,edi |
391 | fabs |
391 | fabs |
392 | fld st0 |
392 | fld st0 |
393 | frndint |
393 | frndint |
394 | fist .integer |
394 | fist .integer |
395 | fsubp st1, st0 |
395 | fsubp st1, st0 |
396 | 396 | ||
397 | mov eax,.integer |
397 | mov eax,.integer |
398 | mov esi,.ptr_ascii |
398 | mov esi,.ptr_ascii |
399 | call itoa |
399 | call itoa |
400 | ; edi -> ptr to end of ascii string |
400 | ; edi -> ptr to end of ascii string |
401 | dec edi |
401 | dec edi |
402 | mov al,'.' |
402 | mov al,'.' |
403 | stosb |
403 | stosb |
404 | 404 | ||
405 | mov ecx, 6 ; max 6 digits in fraction part |
405 | mov ecx, 6 ; max 6 digits in fraction part |
406 | .loop: |
406 | .loop: |
407 | fimul [i10] |
407 | fimul [i10] |
408 | fld st0 |
408 | fld st0 |
409 | frndint |
409 | frndint |
410 | fist .fraction |
410 | fist .fraction |
411 | fsubp st1, st0 |
411 | fsubp st1, st0 |
412 | mov esi,edi |
412 | mov esi,edi |
413 | mov eax,.fraction |
413 | mov eax,.fraction |
414 | add al,'0' |
414 | add al,'0' |
415 | stosb |
415 | stosb |
416 | ftst |
416 | ftst |
417 | fnstsw ax |
417 | fnstsw ax |
418 | test ax, 0100000000000000b |
418 | test ax, 0100000000000000b |
419 | jz @F |
419 | jz @F |
420 | test ax, 0000010100000000b |
420 | test ax, 0000010100000000b |
421 | jz .finish |
421 | jz .finish |
422 | @@: |
422 | @@: |
423 | loop .loop |
423 | loop .loop |
424 | if 0 |
424 | if 0 |
425 | fldcw .status_orginal |
425 | fldcw .status_orginal |
426 | fimul [i10] |
426 | fimul [i10] |
427 | fist .fraction |
427 | fist .fraction |
428 | ; mov esi,edi |
428 | ; mov esi,edi |
429 | mov eax,.fraction |
429 | mov eax,.fraction |
430 | add al,'0' |
430 | add al,'0' |
431 | stosb |
431 | stosb |
432 | ; call itoa |
432 | ; call itoa |
433 | ; -------------------------------- |
433 | ; -------------------------------- |
434 | ; restore previous values |
434 | ; restore previous values |
435 | .finish: |
435 | .finish: |
436 | ; fstp st0 |
436 | ; fstp st0 |
437 | ffree st |
437 | ffree st |
438 | mov eax,.fraction |
438 | mov eax,.fraction |
439 | mov esi,edi |
439 | mov esi,edi |
440 | ; call itoa |
440 | ; call itoa |
441 | 441 | ||
442 | add al,'0' |
442 | add al,'0' |
443 | stosb |
443 | stosb |
444 | end if |
444 | end if |
445 | .finish: |
445 | .finish: |
446 | ffree st |
446 | ffree st |
447 | cmp .sign,0 |
447 | cmp .sign,0 |
448 | jnz @f |
448 | jnz @f |
449 | mov esi,.ptr_ascii |
449 | mov esi,.ptr_ascii |
450 | dec esi |
450 | dec esi |
451 | mov byte[esi],'-' |
451 | mov byte[esi],'-' |
452 | @@: |
452 | @@: |
453 | mov esp,ebp |
453 | mov esp,ebp |
454 | pop ebp |
454 | pop ebp |
455 | pop ecx |
455 | pop ecx |
456 | 456 | ||
457 | ret |
457 | ret |
458 | end if |
458 | end if |
459 | if 0 |
459 | if 0 |
460 | ;=============================================================================== |
460 | ;=============================================================================== |
461 | ; float to ASCII conversion procedure |
461 | ; float to ASCII conversion procedure |
462 | ; |
462 | ; |
463 | ; input: |
463 | ; input: |
464 | ; buffer - pointer to memory where output will be saved |
464 | ; buffer - pointer to memory where output will be saved |
465 | ; precision - number of digits after dot |
465 | ; precision - number of digits after dot |
466 | ; |
466 | ; |
467 | ; output: |
467 | ; output: |
468 | ; no immediate output |
468 | ; no immediate output |
469 | ; |
469 | ; |
470 | ; notes: |
470 | ; notes: |
471 | ; separate integer and mantisa part with dot '.' |
471 | ; separate integer and mantisa part with dot '.' |
472 | ; so GOOD 123.456 |
472 | ; so GOOD 123.456 |
473 | ; WRONG 123,456 |
473 | ; WRONG 123,456 |
474 | ; |
474 | ; |
475 | ; coded by Reverend // HTB + RAG |
475 | ; coded by Reverend // HTB + RAG |
476 | ;=============================================================================== |
476 | ;=============================================================================== |
477 | proc ftoa buffer, precision |
477 | proc ftoa buffer, precision |
478 | locals |
478 | locals |
479 | status_original dw ? |
479 | status_original dw ? |
480 | status_changed dw ? |
480 | status_changed dw ? |
481 | integer dd ? |
481 | integer dd ? |
482 | mantisa dd ? |
482 | mantisa dd ? |
483 | signed dd ? |
483 | signed dd ? |
484 | endl |
484 | endl |
485 | push eax ecx;edi ecx |
485 | push eax ecx;edi ecx |
486 | ; -------------------------------- |
486 | ; -------------------------------- |
487 | ; set correct precision |
487 | ; set correct precision |
488 | mov eax, [precision] |
488 | mov eax, [precision] |
489 | cmp eax, 51 |
489 | cmp eax, 51 |
490 | jb @F |
490 | jb @F |
491 | mov eax, 51 |
491 | mov eax, 51 |
492 | @@: |
492 | @@: |
493 | mov [precision], eax |
493 | mov [precision], eax |
494 | ; -------------------------------- |
494 | ; -------------------------------- |
495 | ; change control wortd of fpu to prevent rounding |
495 | ; change control wortd of fpu to prevent rounding |
496 | fnstcw [status_original] |
496 | fnstcw [status_original] |
497 | mov ax, [status_original] |
497 | mov ax, [status_original] |
498 | or ax, 0000110000000000b |
498 | or ax, 0000110000000000b |
499 | mov [status_changed], ax |
499 | mov [status_changed], ax |
500 | fldcw [status_changed] |
500 | fldcw [status_changed] |
501 | ; -------------------------------- |
501 | ; -------------------------------- |
502 | ; check if signed |
502 | ; check if signed |
503 | xor eax, eax |
503 | xor eax, eax |
504 | fst [signed] |
504 | fst [signed] |
505 | test [signed], 80000000h |
505 | test [signed], 80000000h |
506 | setnz al |
506 | setnz al |
507 | mov [signed], eax |
507 | mov [signed], eax |
508 | ; -------------------------------- |
508 | ; -------------------------------- |
509 | ; cut integer and mantisa separately |
509 | ; cut integer and mantisa separately |
510 | fld st0 |
510 | fld st0 |
511 | fld st0 ; st0 = x, st1 = x |
511 | fld st0 ; st0 = x, st1 = x |
512 | frndint |
512 | frndint |
513 | fist [integer] ; st0 = x, st1 = x |
513 | fist [integer] ; st0 = x, st1 = x |
514 | fabs |
514 | fabs |
515 | fsubp st1, st0 ; st0 = mantisa(x) |
515 | fsubp st1, st0 ; st0 = mantisa(x) |
516 | ; -------------------------------- |
516 | ; -------------------------------- |
517 | ; save integer part in buffer |
517 | ; save integer part in buffer |
518 | ; mov edi, [buffer] |
518 | ; mov edi, [buffer] |
519 | mov esi,[buffer] |
519 | mov esi,[buffer] |
520 | ; push [signed] |
520 | ; push [signed] |
521 | ; push edi |
521 | ; push edi |
522 | ; push 10 |
522 | ; push 10 |
523 | ; push [integer] |
523 | ; push [integer] |
524 | mov eax,[integer] |
524 | mov eax,[integer] |
525 | call itoa |
525 | call itoa |
526 | ; add edi, eax |
526 | ; add edi, eax |
527 | mov al, '.' |
527 | mov al, '.' |
528 | stosb |
528 | stosb |
529 | mov esi,edi |
529 | mov esi,edi |
530 | ; -------------------------------- |
530 | ; -------------------------------- |
531 | ; save mantisa part in buffer |
531 | ; save mantisa part in buffer |
532 | mov ecx, [precision] |
532 | mov ecx, [precision] |
533 | dec ecx |
533 | dec ecx |
534 | .loop: |
534 | .loop: |
535 | fimul [i10] |
535 | fimul [i10] |
536 | fld st0 |
536 | fld st0 |
537 | frndint |
537 | frndint |
538 | fist [mantisa] |
538 | fist [mantisa] |
539 | fsubp st1, st0 |
539 | fsubp st1, st0 |
540 | ; push 0 |
540 | ; push 0 |
541 | ; push edi |
541 | ; push edi |
542 | ; push 10 |
542 | ; push 10 |
543 | ; push [mantisa] |
543 | ; push [mantisa] |
544 | mov esi,edi |
544 | mov esi,edi |
545 | mov eax,[mantisa] |
545 | mov eax,[mantisa] |
546 | call itoa |
546 | call itoa |
547 | ; add edi, eax |
547 | ; add edi, eax |
548 | ftst |
548 | ftst |
549 | fnstsw ax |
549 | fnstsw ax |
550 | test ax, 0100000000000000b |
550 | test ax, 0100000000000000b |
551 | jz @F |
551 | jz @F |
552 | test ax, 0000010100000000b |
552 | test ax, 0000010100000000b |
553 | jz .finish |
553 | jz .finish |
554 | @@: |
554 | @@: |
555 | loop .loop |
555 | loop .loop |
556 | fldcw [status_original] |
556 | fldcw [status_original] |
557 | fimul [i10] |
557 | fimul [i10] |
558 | fist [mantisa] |
558 | fist [mantisa] |
559 | ; push 0 |
559 | ; push 0 |
560 | ; push edi |
560 | ; push edi |
561 | ; push 10 |
561 | ; push 10 |
562 | ; push [mantisa] |
562 | ; push [mantisa] |
563 | mov esi,edi |
563 | mov esi,edi |
564 | mov eax,[mantisa] |
564 | mov eax,[mantisa] |
565 | call itoa |
565 | call itoa |
566 | ; -------------------------------- |
566 | ; -------------------------------- |
567 | ; restore previous values |
567 | ; restore previous values |
568 | .finish: |
568 | .finish: |
569 | fstp st0 |
569 | fstp st0 |
570 | cmp [signed],1 |
570 | cmp [signed],1 |
571 | jnz @f |
571 | jnz @f |
572 | mov byte[buffer],'-' |
572 | mov byte[buffer],'-' |
573 | @@: |
573 | @@: |
574 | stc |
574 | stc |
575 | pop ecx eax ;edi eax |
575 | pop ecx eax ;edi eax |
576 | ret |
576 | ret |
577 | endp |
577 | endp |
578 | end if |
578 | end if |
579 | if 0 |
579 | if 0 |
580 | write_asc: |
580 | write_asc: |
581 | .counter equ dword[ebp-4] |
581 | .counter equ dword[ebp-4] |
582 | push ebp |
582 | push ebp |
583 | mov ebp,esp |
583 | mov ebp,esp |
584 | sub esp,64 |
584 | sub esp,64 |
585 | fninit |
585 | fninit |
586 | mov edi,asc_file_buffer |
586 | mov edi,asc_file_buffer |
587 | mov esi,asc_main_header |
587 | mov esi,asc_main_header |
588 | cld |
588 | cld |
589 | @@: |
589 | @@: |
590 | lodsb |
590 | lodsb |
591 | cmp al,1 |
591 | cmp al,1 |
592 | jz @f |
592 | jz @f |
593 | stosb |
593 | stosb |
594 | jmp @b |
594 | jmp @b |
595 | @@: |
595 | @@: |
596 | 596 | ||
597 | mov esi,asc_info_header |
597 | mov esi,asc_info_header |
598 | @@: |
598 | @@: |
599 | lodsb |
599 | lodsb |
600 | cmp al,1 |
600 | cmp al,1 |
601 | jz @f |
601 | jz @f |
602 | stosb |
602 | stosb |
603 | jmp @b |
603 | jmp @b |
604 | @@: |
604 | @@: |
605 | push esi ; -> position in header info |
605 | push esi ; -> position in header info |
606 | movzx eax,[points_count_var] |
606 | movzx eax,[points_count_var] |
607 | mov esi,edi |
607 | mov esi,edi |
608 | call itoa ; unsigned dword integer to ascii procedure |
608 | call itoa ; unsigned dword integer to ascii procedure |
609 | pop esi |
609 | pop esi |
610 | inc esi |
610 | inc esi |
611 | @@: |
611 | @@: |
612 | lodsb |
612 | lodsb |
613 | cmp al,1 |
613 | cmp al,1 |
614 | jz @f |
614 | jz @f |
615 | stosb |
615 | stosb |
616 | jmp @b |
616 | jmp @b |
617 | @@: |
617 | @@: |
618 | push esi |
618 | push esi |
619 | movzx eax,[triangles_count_var] |
619 | movzx eax,[triangles_count_var] |
620 | mov esi,edi |
620 | mov esi,edi |
621 | call itoa |
621 | call itoa |
622 | pop esi |
622 | pop esi |
623 | inc esi |
623 | inc esi |
624 | @@: |
624 | @@: |
625 | lodsb |
625 | lodsb |
626 | cmp al,1 |
626 | cmp al,1 |
627 | jz @f |
627 | jz @f |
628 | stosb |
628 | stosb |
629 | jmp @b |
629 | jmp @b |
630 | @@: |
630 | @@: |
631 | ;============================================================= |
631 | ;============================================================= |
632 | ;================vertex list parser=========================== |
632 | ;================vertex list parser=========================== |
633 | ;============================================================= |
633 | ;============================================================= |
634 | 634 | ||
635 | xor ecx,ecx |
635 | xor ecx,ecx |
636 | .again_vertex: |
636 | .again_vertex: |
637 | push ecx |
637 | push ecx |
638 | mov esi,asc_one_vertex_formula |
638 | mov esi,asc_one_vertex_formula |
639 | @@: |
639 | @@: |
640 | lodsb |
640 | lodsb |
641 | cmp al,1 |
641 | cmp al,1 |
642 | jz @f |
642 | jz @f |
643 | stosb |
643 | stosb |
644 | jmp @b |
644 | jmp @b |
645 | @@: |
645 | @@: |
646 | mov eax,ecx |
646 | mov eax,ecx |
647 | ; push ecx |
647 | ; push ecx |
648 | push esi |
648 | push esi |
649 | mov esi,edi |
649 | mov esi,edi |
650 | call itoa |
650 | call itoa |
651 | pop esi |
651 | pop esi |
652 | ; pop ecx |
652 | ; pop ecx |
653 | inc esi |
653 | inc esi |
654 | xor ebx,ebx |
654 | xor ebx,ebx |
655 | .next_vertex_coef: |
655 | .next_vertex_coef: |
656 | push ebx |
656 | push ebx |
657 | @@: |
657 | @@: |
658 | lodsb |
658 | lodsb |
659 | cmp al,1 |
659 | cmp al,1 |
660 | jz @f |
660 | jz @f |
661 | stosb |
661 | stosb |
662 | jmp @b |
662 | jmp @b |
663 | @@: |
663 | @@: |
664 | ; int3 |
664 | ; int3 |
665 | push esi |
665 | push esi |
666 | lea esi,[ecx*3] |
666 | lea esi,[ecx*3] |
667 | shl esi,2 |
667 | shl esi,2 |
668 | add esi,points_r |
668 | add esi,points_r |
669 | add esi,ebx |
669 | add esi,ebx |
670 | ; int3 |
670 | ; int3 |
671 | call ftoa_mac |
671 | call ftoa_mac |
672 | ; std |
672 | ; std |
673 | ; fld dword[esi] |
673 | ; fld dword[esi] |
674 | 674 | ||
675 | 675 | ||
676 | ; pushad |
676 | ; pushad |
677 | ; stdcall ftoa, edi, 30 |
677 | ; stdcall ftoa, edi, 30 |
678 | ; popad |
678 | ; popad |
679 | ; add edi,20 |
679 | ; add edi,20 |
680 | 680 | ||
681 | 681 | ||
682 | pop esi |
682 | pop esi |
683 | pop ebx |
683 | pop ebx |
684 | add ebx,4 |
684 | add ebx,4 |
685 | cmp ebx,12 |
685 | cmp ebx,12 |
686 | jnz .next_vertex_coef |
686 | jnz .next_vertex_coef |
687 | @@: |
687 | @@: |
688 | lodsb |
688 | lodsb |
689 | cmp al,1 |
689 | cmp al,1 |
690 | jz @f |
690 | jz @f |
691 | stosb |
691 | stosb |
692 | jmp @b |
692 | jmp @b |
693 | @@: |
693 | @@: |
694 | pop ecx |
694 | pop ecx |
695 | inc ecx |
695 | inc ecx |
696 | cmp cx,[points_count_var] |
696 | cmp cx,[points_count_var] |
697 | jnz .again_vertex |
697 | jnz .again_vertex |
698 | 698 | ||
699 | 699 | ||
700 | ; mov edi,[temp_edi] |
700 | ; mov edi,[temp_edi] |
701 | 701 | ||
702 | 702 | ||
703 | mov esi,asc_face_list_header |
703 | mov esi,asc_face_list_header |
704 | @@: |
704 | @@: |
705 | lodsb |
705 | lodsb |
706 | cmp al,1 ; all face header |
706 | cmp al,1 ; all face header |
707 | jz @f |
707 | jz @f |
708 | stosb |
708 | stosb |
709 | jmp @b |
709 | jmp @b |
710 | @@: |
710 | @@: |
711 | ;===================================== |
711 | ;===================================== |
712 | ; ==============face list parser====== |
712 | ; ==============face list parser====== |
713 | ;===================================== |
713 | ;===================================== |
714 | xor ecx,ecx |
714 | xor ecx,ecx |
715 | .again_face: |
715 | .again_face: |
716 | push ecx |
716 | push ecx |
717 | mov .counter,ecx |
717 | mov .counter,ecx |
718 | mov esi,asc_one_face_formula |
718 | mov esi,asc_one_face_formula |
719 | @@: |
719 | @@: |
720 | lodsb |
720 | lodsb |
721 | cmp al,1 |
721 | cmp al,1 |
722 | jz @f |
722 | jz @f |
723 | stosb |
723 | stosb |
724 | jmp @b |
724 | jmp @b |
725 | @@: |
725 | @@: |
726 | mov eax,ecx |
726 | mov eax,ecx |
727 | push esi |
727 | push esi |
728 | mov esi,edi |
728 | mov esi,edi |
729 | call itoa |
729 | call itoa |
730 | pop esi |
730 | pop esi |
731 | inc esi |
731 | inc esi |
732 | @@: |
732 | @@: |
733 | lodsb |
733 | lodsb |
734 | cmp al,1 |
734 | cmp al,1 |
735 | jz @f |
735 | jz @f |
736 | stosb |
736 | stosb |
737 | jmp @b |
737 | jmp @b |
738 | @@: |
738 | @@: |
739 | 739 | ||
740 | xor ebx,ebx |
740 | xor ebx,ebx |
741 | .next_face_index: |
741 | .next_face_index: |
742 | push ebx |
742 | push ebx |
743 | mov ecx,.counter |
743 | mov ecx,.counter |
744 | lea ecx,[ecx*3] |
744 | lea ecx,[ecx*3] |
745 | add ecx,ecx |
745 | add ecx,ecx |
746 | movzx eax,word[triangles+ecx+ebx] |
746 | movzx eax,word[triangles+ecx+ebx] |
747 | push esi |
747 | push esi |
748 | mov esi,edi |
748 | mov esi,edi |
749 | call itoa |
749 | call itoa |
750 | pop esi |
750 | pop esi |
751 | @@: |
751 | @@: |
752 | lodsb |
752 | lodsb |
753 | cmp al,1 |
753 | cmp al,1 |
754 | jz @f |
754 | jz @f |
755 | stosb |
755 | stosb |
756 | jmp @b |
756 | jmp @b |
757 | @@: |
757 | @@: |
758 | pop ebx |
758 | pop ebx |
759 | add ebx,2 |
759 | add ebx,2 |
760 | cmp ebx,6 |
760 | cmp ebx,6 |
761 | jnz .next_face_index |
761 | jnz .next_face_index |
762 | 762 | ||
763 | ; push esi |
763 | ; push esi |
764 | mov esi,asc_material |
764 | mov esi,asc_material |
765 | @@: |
765 | @@: |
766 | lodsb |
766 | lodsb |
767 | cmp al,1 |
767 | cmp al,1 |
768 | jz @f |
768 | jz @f |
769 | stosb |
769 | stosb |
770 | jmp @b |
770 | jmp @b |
771 | @@: |
771 | @@: |
772 | ; pop esi |
772 | ; pop esi |
773 | 773 | ||
774 | pop ecx |
774 | pop ecx |
775 | inc ecx |
775 | inc ecx |
776 | cmp cx,[triangles_count_var] |
776 | cmp cx,[triangles_count_var] |
777 | jnz .again_face |
777 | jnz .again_face |
778 | 778 | ||
779 | ; write file |
779 | ; write file |
780 | sub edi,asc_file_buffer |
780 | sub edi,asc_file_buffer |
781 | ; mov [file_buffer+2],edi |
781 | ; mov [file_buffer+2],edi |
782 | mov [FileSize],edi |
782 | mov [FileSize],edi |
783 | 783 | ||
784 | invoke CreateFile,asc_file_name, GENERIC_WRITE, 0, 0,CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0 |
784 | invoke CreateFile,asc_file_name, GENERIC_WRITE, 0, 0,CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0 |
785 | mov [hfile],eax |
785 | mov [hfile],eax |
786 | invoke WriteFile,eax,asc_file_buffer,[FileSize], byteswritten, 0 |
786 | invoke WriteFile,eax,asc_file_buffer,[FileSize], byteswritten, 0 |
787 | invoke CloseHandle,[hfile] |
787 | invoke CloseHandle,[hfile] |
788 | 788 | ||
789 | mov esp,ebp |
789 | mov esp,ebp |
790 | pop ebp |
790 | pop ebp |
791 | ret |
791 | ret |
792 | end if |
792 | end if |
793 | if 0 |
793 | if 0 |
794 | asc_file_buffer: |
794 | asc_file_buffer: |
795 | rd 65536 |
795 | rd 65536 |
796 | ascii_string rb 50 |
796 | ascii_string rb 50 |
797 | ftoa_muler dd 1000000000 |
797 | ftoa_muler dd 1000000000 |
798 | file_size dd ? |
798 | file_size dd ? |
799 | file_handle dd ? |
799 | file_handle dd ? |
800 | end if |
800 | end if |
801 | 801 | ||
802 | if 0 |
802 | if 0 |
803 | convert_muler: |
803 | convert_muler: |
804 | dd 1, 10, 100, 1000, 10000 |
804 | dd 1, 10, 100, 1000, 10000 |
805 | XYZpartices: |
805 | XYZpartices: |
806 | db 'X','Y','Z' |
806 | db 'X','Y','Z' |
807 | i10 dw 10 |
807 | i10 dw 10 |
808 | points_count_var dd ? |
808 | points_count_var dd ? |
809 | triangles_count_var dd ? |
809 | triangles_count_var dd ? |
810 | points rb 100 |
810 | points rb 100 |
811 | triangles rb 100 |
811 | triangles rb 100 |
812 | asc_file: |
812 | asc_file: |
813 | 813 | ||
814 | file "2TORUS.ASC" |
814 | file "2TORUS.ASC" |
815 | end if |
815 | end if |