Rev 967 | Rev 3625 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
382 | heavyiron | 1 | ;; Calculator for MenuetOS (c) Ville Turjanmaa |
2 | ;; |
||
485 | heavyiron | 3 | ;; Compile with FASM |
153 | heavyiron | 4 | ;; |
485 | heavyiron | 5 | ;; Pavel Rymovski (Heavyiron) - version for KolibriOS |
6 | ;; |
||
382 | heavyiron | 7 | ;; What's new: |
153 | heavyiron | 8 | ;; Calc 1.1 |
382 | heavyiron | 9 | ;; 1) changed design |
10 | ;; 2) new procedure of draw window (10 decimal digits, 23 binary, "+" not displayed now) |
||
11 | ;; 3) window with skin |
||
153 | heavyiron | 12 | ;; Calc 1.2 |
107 | heavyiron | 13 | ;; 1)added some useful functions, such as arcsin, arccos, arctg, 1/x, x^2 |
153 | heavyiron | 14 | ;; Calc 1.31 |
107 | heavyiron | 15 | ;; 1)optimised program |
153 | heavyiron | 16 | ;; 2)new type of window (you need kernel 114 revision or higher) |
382 | heavyiron | 17 | ;; Calc 1.32 |
18 | ;; 1)fixed arccos |
||
31 | halyavin | 19 | |
382 | heavyiron | 20 | |
153 | heavyiron | 21 | appname equ 'Calc ' |
382 | heavyiron | 22 | version equ '1.32' |
153 | heavyiron | 23 | |
31 | halyavin | 24 | use32 |
153 | heavyiron | 25 | org 0x0 |
382 | heavyiron | 26 | db 'MENUET01' ; 8 byte id |
27 | dd 0x01 ; header version |
||
28 | dd START ; start of code |
||
29 | dd I_END ; size of image |
||
31 | halyavin | 30 | dd 0x1000 ; memory for app |
31 | dd 0x1000 ; esp |
||
153 | heavyiron | 32 | dd 0x0,0x0 ; I_Param , I_Icon |
31 | halyavin | 33 | |
485 | heavyiron | 34 | include '..\..\..\macros.inc' |
31 | halyavin | 35 | |
107 | heavyiron | 36 | START: |
31 | halyavin | 37 | |
485 | heavyiron | 38 | red: |
107 | heavyiron | 39 | call draw_window |
31 | halyavin | 40 | |
485 | heavyiron | 41 | still: |
107 | heavyiron | 42 | push 10 |
43 | pop eax |
||
485 | heavyiron | 44 | mcall |
45 | |||
46 | dec eax |
||
107 | heavyiron | 47 | jz red |
48 | dec eax |
||
49 | jz key |
||
153 | heavyiron | 50 | |
485 | heavyiron | 51 | button: |
153 | heavyiron | 52 | mov al,17 ; получить идентификатор нажатой кнопки |
485 | heavyiron | 53 | mcall |
31 | halyavin | 54 | shr eax,8 |
107 | heavyiron | 55 | jmp testbut |
153 | heavyiron | 56 | |
485 | heavyiron | 57 | key: |
153 | heavyiron | 58 | mov al,2 ; получить ASCII-код нажатой клавиши |
485 | heavyiron | 59 | mcall |
107 | heavyiron | 60 | shr eax,8 |
153 | heavyiron | 61 | mov edi,asci ; перевод ASCII в идентификатор кнопки |
107 | heavyiron | 62 | mov ecx,18 |
31 | halyavin | 63 | cld |
64 | repne scasb |
||
65 | jne still |
||
66 | sub edi,asci |
||
67 | dec edi |
||
68 | mov esi,butid |
||
69 | add esi,edi |
||
70 | lodsb |
||
107 | heavyiron | 71 | |
31 | halyavin | 72 | testbut: |
153 | heavyiron | 73 | cmp eax,1 ; кнопка 1 - закрытие программы |
31 | halyavin | 74 | jne noclose |
153 | heavyiron | 75 | or eax,-1 |
485 | heavyiron | 76 | mcall |
107 | heavyiron | 77 | |
31 | halyavin | 78 | noclose: |
79 | cmp eax,2 |
||
80 | jne no_reset |
||
81 | call clear_all |
||
82 | jmp still |
||
107 | heavyiron | 83 | |
31 | halyavin | 84 | no_reset: |
85 | finit |
||
153 | heavyiron | 86 | mov ebx,muuta1 ; Перевод в формат FPU |
87 | mov esi,18 |
||
88 | call atof |
||
89 | fstp [trans1] |
||
90 | mov ebx,muuta2 |
||
91 | mov esi,18 |
||
92 | call atof |
||
93 | fst [trans2] |
||
205 | heavyiron | 94 | |
107 | heavyiron | 95 | cmp eax,33 |
31 | halyavin | 96 | jne no_sign |
97 | cmp [dsign],byte '-' |
||
98 | jne no_m |
||
99 | mov [dsign],byte '+' |
||
100 | call print_display |
||
101 | jmp still |
||
107 | heavyiron | 102 | |
31 | halyavin | 103 | no_m: |
104 | mov [dsign],byte '-' |
||
105 | call print_display |
||
106 | jmp still |
||
107 | heavyiron | 107 | |
31 | halyavin | 108 | no_sign: |
109 | cmp eax,3 |
||
110 | jne no_display_change |
||
111 | inc [display_type] |
||
112 | cmp [display_type],2 |
||
113 | jbe display_continue |
||
114 | mov [display_type],0 |
||
107 | heavyiron | 115 | |
31 | halyavin | 116 | display_continue: |
117 | mov eax,[display_type] |
||
118 | mov eax,[multipl+eax*4] |
||
119 | mov [entry_multiplier],eax |
||
120 | call print_display |
||
121 | jmp still |
||
122 | |||
123 | no_display_change: |
||
124 | cmp eax,6 |
||
153 | heavyiron | 125 | jb no_a_f |
31 | halyavin | 126 | cmp eax,11 |
153 | heavyiron | 127 | jg no_a_f |
31 | halyavin | 128 | add eax,4 |
129 | call number_entry |
||
130 | jmp still |
||
107 | heavyiron | 131 | |
132 | no_a_f: |
||
31 | halyavin | 133 | cmp eax,12 |
153 | heavyiron | 134 | jb no_13 |
31 | halyavin | 135 | cmp eax,14 |
153 | heavyiron | 136 | jg no_13 |
31 | halyavin | 137 | sub eax,11 |
138 | call number_entry |
||
139 | jmp still |
||
107 | heavyiron | 140 | |
31 | halyavin | 141 | no_13: |
107 | heavyiron | 142 | cmp eax,19 |
153 | heavyiron | 143 | jb no_46 |
107 | heavyiron | 144 | cmp eax,21 |
153 | heavyiron | 145 | jg no_46 |
107 | heavyiron | 146 | sub eax,15 |
31 | halyavin | 147 | call number_entry |
148 | jmp still |
||
107 | heavyiron | 149 | |
31 | halyavin | 150 | no_46: |
107 | heavyiron | 151 | cmp eax,26 |
153 | heavyiron | 152 | jb no_79 |
107 | heavyiron | 153 | cmp eax,28 |
153 | heavyiron | 154 | jg no_79 |
107 | heavyiron | 155 | sub eax,19 |
31 | halyavin | 156 | call number_entry |
157 | jmp still |
||
107 | heavyiron | 158 | |
31 | halyavin | 159 | no_79: |
107 | heavyiron | 160 | cmp eax,34 |
31 | halyavin | 161 | jne no_0 |
153 | heavyiron | 162 | xor eax,eax |
31 | halyavin | 163 | call number_entry |
164 | jmp still |
||
107 | heavyiron | 165 | |
166 | no_0: |
||
167 | cmp eax,35 |
||
31 | halyavin | 168 | jne no_id |
169 | inc [id] |
||
170 | and [id],1 |
||
171 | mov [new_dec],100000 |
||
172 | jmp still |
||
107 | heavyiron | 173 | |
31 | halyavin | 174 | no_id: |
107 | heavyiron | 175 | cmp eax,17 |
31 | halyavin | 176 | jne no_sin |
177 | fld [trans1] |
||
178 | fsin |
||
179 | jmp show_result |
||
107 | heavyiron | 180 | |
31 | halyavin | 181 | no_sin: |
107 | heavyiron | 182 | cmp eax,18 |
183 | jne no_asin |
||
184 | fld [trans1] |
||
185 | fld st0 |
||
186 | fmul st,st1 |
||
187 | fld1 |
||
188 | fsubrp st1,st0 |
||
189 | fsqrt |
||
190 | fpatan |
||
191 | jmp show_result |
||
192 | |||
193 | no_asin: |
||
194 | cmp eax,16 |
||
31 | halyavin | 195 | jne no_int |
196 | fld [trans1] |
||
197 | frndint |
||
198 | jmp show_result |
||
107 | heavyiron | 199 | |
31 | halyavin | 200 | no_int: |
107 | heavyiron | 201 | cmp eax,23 |
202 | jne no_1x |
||
203 | fld1 |
||
175 | heavyiron | 204 | fdiv [trans1] |
107 | heavyiron | 205 | jmp show_result |
206 | |||
207 | no_1x: |
||
208 | cmp eax,24 |
||
31 | halyavin | 209 | jne no_cos |
210 | fld [trans1] |
||
211 | fcos |
||
212 | jmp show_result |
||
107 | heavyiron | 213 | |
31 | halyavin | 214 | no_cos: |
107 | heavyiron | 215 | cmp eax,25 |
216 | jne no_acos |
||
217 | fld [trans1] |
||
382 | heavyiron | 218 | fld st0 |
219 | fmul st,st1 |
||
107 | heavyiron | 220 | fld1 |
382 | heavyiron | 221 | fsubrp st1,st0 |
107 | heavyiron | 222 | fsqrt |
382 | heavyiron | 223 | fxch st1 |
107 | heavyiron | 224 | fpatan |
31 | halyavin | 225 | jmp show_result |
107 | heavyiron | 226 | |
227 | no_acos: |
||
228 | cmp eax,30 |
||
229 | jne no_x2 |
||
230 | fld [trans1] |
||
231 | fmul st,st0 |
||
232 | jmp show_result |
||
233 | |||
234 | no_x2: |
||
235 | cmp eax,31 |
||
31 | halyavin | 236 | jne no_tan |
237 | fld [trans1] |
||
107 | heavyiron | 238 | fptan |
239 | fstp st2 |
||
240 | jmp show_result |
||
241 | |||
242 | no_tan: |
||
243 | cmp eax,32 |
||
244 | jne no_atan |
||
31 | halyavin | 245 | fld [trans1] |
107 | heavyiron | 246 | fld1 |
247 | fpatan |
||
31 | halyavin | 248 | jmp show_result |
107 | heavyiron | 249 | |
250 | no_atan: |
||
251 | cmp eax,38 |
||
31 | halyavin | 252 | jne no_pi |
253 | fldpi |
||
254 | jmp show_result |
||
107 | heavyiron | 255 | |
31 | halyavin | 256 | no_pi: |
107 | heavyiron | 257 | cmp eax,37 |
31 | halyavin | 258 | jne no_sqrt |
259 | fld [trans1] |
||
260 | fsqrt |
||
261 | jmp show_result |
||
107 | heavyiron | 262 | |
31 | halyavin | 263 | no_sqrt: |
264 | cmp eax,15 |
||
265 | jne no_add |
||
266 | call calculate |
||
267 | call new_entry |
||
268 | mov [calc],'+' |
||
269 | jmp still |
||
107 | heavyiron | 270 | |
31 | halyavin | 271 | no_add: |
107 | heavyiron | 272 | cmp eax,22 |
31 | halyavin | 273 | jne no_sub |
274 | call calculate |
||
275 | call new_entry |
||
276 | mov [calc],'-' |
||
277 | jmp still |
||
107 | heavyiron | 278 | |
31 | halyavin | 279 | no_sub: |
107 | heavyiron | 280 | cmp eax,29 |
31 | halyavin | 281 | jne no_div |
282 | call calculate |
||
283 | call new_entry |
||
284 | mov [calc],'/' |
||
285 | jmp still |
||
107 | heavyiron | 286 | |
31 | halyavin | 287 | no_div: |
107 | heavyiron | 288 | cmp eax,36 |
31 | halyavin | 289 | jne no_mul |
290 | call calculate |
||
291 | mov [calc],'*' |
||
292 | call new_entry |
||
293 | jmp still |
||
107 | heavyiron | 294 | |
31 | halyavin | 295 | no_mul: |
107 | heavyiron | 296 | cmp eax,39 |
31 | halyavin | 297 | jne no_calc |
298 | call calculate |
||
299 | jmp still |
||
107 | heavyiron | 300 | |
31 | halyavin | 301 | no_calc: |
302 | jmp still |
||
303 | |||
304 | show_result: |
||
305 | call ftoa |
||
306 | call print_display |
||
307 | jmp still |
||
308 | |||
309 | error: |
||
310 | jmp still |
||
311 | |||
312 | calculate: |
||
313 | pusha |
||
314 | cmp [calc],' ' |
||
153 | heavyiron | 315 | je no_calculation |
31 | halyavin | 316 | cmp [calc],'/' |
317 | jne no_cdiv |
||
318 | fdiv [trans1] |
||
107 | heavyiron | 319 | |
31 | halyavin | 320 | no_cdiv: |
321 | cmp [calc],'*' |
||
322 | jne no_cmul |
||
323 | fmul [trans1] |
||
107 | heavyiron | 324 | |
31 | halyavin | 325 | no_cmul: |
326 | cmp [calc],'+' |
||
327 | jne no_cadd |
||
328 | fadd [trans1] |
||
107 | heavyiron | 329 | |
31 | halyavin | 330 | no_cadd: |
331 | cmp [calc],'-' |
||
332 | jne no_cdec |
||
333 | fsub [trans1] |
||
107 | heavyiron | 334 | |
31 | halyavin | 335 | no_cdec: |
336 | call ftoa |
||
107 | heavyiron | 337 | |
338 | no_calculation: |
||
31 | halyavin | 339 | call print_display |
340 | popa |
||
341 | ret |
||
342 | |||
343 | number_entry: |
||
344 | |||
345 | pusha |
||
346 | |||
347 | cmp eax,[entry_multiplier] |
||
348 | jge no_entry |
||
349 | cmp [id],1 |
||
153 | heavyiron | 350 | je decimal_entry |
31 | halyavin | 351 | mov ebx,[integer] |
175 | heavyiron | 352 | test ebx,0xF0000000 |
31 | halyavin | 353 | jnz no_entry |
354 | mov ebx,eax |
||
355 | mov eax,[integer] |
||
356 | mov ecx,[entry_multiplier] |
||
357 | mul ecx |
||
358 | add eax,ebx |
||
359 | mov [integer],eax |
||
360 | call print_display |
||
361 | call to_muuta |
||
362 | popa |
||
363 | ret |
||
364 | |||
365 | decimal_entry: |
||
366 | |||
367 | imul eax,[new_dec] |
||
368 | add [decimal],eax |
||
369 | mov eax,[new_dec] |
||
370 | xor edx,edx |
||
371 | mov ebx,[entry_multiplier] |
||
372 | div ebx |
||
373 | mov [new_dec],eax |
||
374 | call print_display |
||
375 | call to_muuta |
||
376 | popa |
||
377 | ret |
||
378 | |||
379 | no_entry: |
||
380 | |||
381 | call print_display |
||
382 | call to_muuta |
||
383 | popa |
||
384 | ret |
||
107 | heavyiron | 385 | |
386 | to_muuta: |
||
31 | halyavin | 387 | |
388 | pusha |
||
389 | mov al,[dsign] |
||
390 | mov esi,muuta0 |
||
391 | mov edi,muuta1 |
||
392 | mov ecx,18 |
||
393 | cld |
||
394 | rep movsb |
||
395 | mov [muuta1],al |
||
153 | heavyiron | 396 | mov edi,muuta1+10 ; целое |
31 | halyavin | 397 | mov eax,[integer] |
107 | heavyiron | 398 | |
31 | halyavin | 399 | new_to_muuta1: |
107 | heavyiron | 400 | |
31 | halyavin | 401 | mov ebx,10 |
402 | xor edx,edx |
||
403 | div ebx |
||
404 | mov [edi],dl |
||
405 | add [edi],byte 48 |
||
406 | dec edi |
||
407 | cmp edi,muuta1+1 |
||
408 | jge new_to_muuta1 |
||
153 | heavyiron | 409 | mov edi,muuta1+17 ; дробное |
31 | halyavin | 410 | mov eax,[decimal] |
107 | heavyiron | 411 | |
31 | halyavin | 412 | new_to_muuta2: |
107 | heavyiron | 413 | |
31 | halyavin | 414 | mov ebx,10 |
415 | xor edx,edx |
||
416 | div ebx |
||
417 | mov [edi],dl |
||
418 | add [edi],byte 48 |
||
419 | dec edi |
||
420 | cmp edi,muuta1+12 |
||
421 | jge new_to_muuta2 |
||
422 | popa |
||
423 | ret |
||
424 | |||
425 | new_entry: |
||
426 | |||
427 | pusha |
||
428 | mov esi,muuta1 |
||
429 | mov edi,muuta2 |
||
430 | mov ecx,18 |
||
431 | cld |
||
432 | rep movsb |
||
433 | mov esi,muuta0 |
||
434 | mov edi,muuta1 |
||
435 | mov ecx,18 |
||
436 | cld |
||
437 | rep movsb |
||
438 | mov [integer],0 |
||
439 | mov [decimal],0 |
||
440 | mov [id],0 |
||
441 | mov [new_dec],100000 |
||
442 | mov [sign],byte '+' |
||
443 | popa |
||
444 | ret |
||
445 | |||
446 | |||
107 | heavyiron | 447 | ftoa: ; fpu st0 -> [integer],[decimal] |
31 | halyavin | 448 | pusha |
449 | fst [tmp2] |
||
450 | fstcw [controlWord] ; set truncate integer mode |
||
451 | mov ax,[controlWord] |
||
452 | mov [tmp], ax |
||
153 | heavyiron | 453 | or [tmp], word 0x0c00 |
31 | halyavin | 454 | fldcw [tmp] |
455 | ftst ; test if st0 is negative |
||
456 | fstsw ax |
||
107 | heavyiron | 457 | and ax, 0x4500 |
31 | halyavin | 458 | mov [sign], 0 |
107 | heavyiron | 459 | cmp ax, 0x0100 |
31 | halyavin | 460 | jne no_neg |
461 | mov [sign],1 |
||
107 | heavyiron | 462 | |
31 | halyavin | 463 | no_neg: |
175 | heavyiron | 464 | fld [tmp2] |
153 | heavyiron | 465 | cmp byte [sign], 0 ; change fraction to positive |
466 | je no_neg2 |
||
31 | halyavin | 467 | fchs |
107 | heavyiron | 468 | |
31 | halyavin | 469 | no_neg2: |
822 | diamond | 470 | fadd [smallValueForRounding] |
471 | fist [integer] |
||
472 | fisub [integer] |
||
153 | heavyiron | 473 | mov [res],0 ; convert 6 decimal numbers |
31 | halyavin | 474 | mov edi,6 |
475 | |||
476 | newd: |
||
477 | fimul [kymppi] |
||
478 | fist [decimal] |
||
479 | mov ebx,[res] |
||
480 | imul ebx,10 |
||
481 | mov [res],ebx |
||
482 | mov eax,[decimal] |
||
483 | add [res],eax |
||
484 | fisub [decimal] |
||
175 | heavyiron | 485 | fst [tmp2] |
31 | halyavin | 486 | ftst |
487 | fstsw ax |
||
175 | heavyiron | 488 | test ax,1 |
489 | jnz real_done |
||
490 | fld [tmp2] |
||
31 | halyavin | 491 | dec edi |
175 | heavyiron | 492 | jz real_done |
31 | halyavin | 493 | jmp newd |
494 | |||
495 | real_done: |
||
822 | diamond | 496 | fldcw [controlWord] |
31 | halyavin | 497 | mov eax,[res] |
498 | mov [decimal],eax |
||
107 | heavyiron | 499 | cmp [integer],0x80000000 |
31 | halyavin | 500 | jne no_error |
501 | call clear_all |
||
502 | mov [calc],'E' |
||
107 | heavyiron | 503 | |
31 | halyavin | 504 | no_error: |
505 | mov [dsign],byte '+' |
||
153 | heavyiron | 506 | cmp [sign],byte 0 ; convert negative result |
507 | je no_negative |
||
822 | diamond | 508 | ; mov eax,[integer] |
509 | ; not eax |
||
510 | ; inc eax |
||
511 | ; mov [integer],eax |
||
31 | halyavin | 512 | mov [dsign],byte '-' |
107 | heavyiron | 513 | |
31 | halyavin | 514 | no_negative: |
515 | call to_muuta |
||
516 | popa |
||
517 | ret |
||
518 | |||
519 | |||
520 | atof: |
||
521 | push ax |
||
522 | push di |
||
523 | fldz |
||
524 | mov di, 0 |
||
525 | cmp si, 0 |
||
153 | heavyiron | 526 | je .error ; Jump if string has 0 length. |
31 | halyavin | 527 | mov byte [sign], 0 |
153 | heavyiron | 528 | cmp byte [bx], '+' ; Take care of leading '+' or '-'. |
31 | halyavin | 529 | jne .noPlus |
530 | inc di |
||
531 | jmp .noMinus |
||
107 | heavyiron | 532 | |
31 | halyavin | 533 | .noPlus: |
534 | cmp byte [bx], '-' |
||
535 | jne .noMinus |
||
153 | heavyiron | 536 | mov byte [sign], 1 ; Number is negative. |
31 | halyavin | 537 | inc di |
107 | heavyiron | 538 | |
31 | halyavin | 539 | .noMinus: |
540 | cmp si, di |
||
541 | je .error |
||
542 | call atof_convertWholePart |
||
543 | jc .error |
||
544 | call atof_convertFractionalPart |
||
545 | jc .error |
||
546 | cmp byte [sign], 0 |
||
153 | heavyiron | 547 | je .dontNegate |
548 | fchs ; Negate value |
||
107 | heavyiron | 549 | |
31 | halyavin | 550 | .dontNegate: |
153 | heavyiron | 551 | mov bh, 0 ; Set bh to indicate the string is a valid number. |
31 | halyavin | 552 | jmp .exit |
553 | |||
554 | .error: |
||
153 | heavyiron | 555 | mov bh, 1 ; Set error code. |
382 | heavyiron | 556 | ; fstp st0 ; Pop top of fpu stack. |
31 | halyavin | 557 | |
558 | .exit: |
||
559 | pop di |
||
560 | pop ax |
||
561 | ret |
||
562 | |||
563 | atof_convertWholePart: |
||
564 | |||
565 | ; Convert the whole number part (the part preceding the decimal |
||
566 | ; point) by reading a digit at a time, multiplying the current |
||
567 | ; value by 10, and adding the digit. |
||
568 | |||
569 | .mainLoop: |
||
570 | mov al, [bx + di] |
||
571 | cmp al, '.' |
||
572 | je .exit |
||
153 | heavyiron | 573 | cmp al, '0' ; Make sure character is a digit. |
31 | halyavin | 574 | jb .error |
575 | cmp al, '9' |
||
576 | ja .error |
||
577 | |||
578 | ; Convert single character to digit and save to memory for |
||
579 | ; transfer to the FPU. |
||
580 | |||
581 | sub al, '0' |
||
582 | mov ah, 0 |
||
583 | mov [tmp], ax |
||
584 | |||
585 | ; Multiply current value by 10 and add in digit. |
||
586 | |||
587 | fmul dword [ten] |
||
588 | fiadd word [tmp] |
||
589 | inc di |
||
153 | heavyiron | 590 | cmp si, di ; Jump if end of string has been reached. |
31 | halyavin | 591 | je .exit |
592 | jmp .mainLoop |
||
593 | |||
594 | .error: |
||
153 | heavyiron | 595 | stc ; Set error (carry) flag. |
31 | halyavin | 596 | ret |
597 | |||
598 | .exit: |
||
153 | heavyiron | 599 | clc ; Clear error (carry) flag. |
31 | halyavin | 600 | ret |
601 | |||
602 | |||
603 | atof_convertFractionalPart: |
||
153 | heavyiron | 604 | fld1 ; Load 1 to TOS. This will be the value of the decimal place. |
31 | halyavin | 605 | |
606 | .mainLoop: |
||
153 | heavyiron | 607 | cmp si, di ; Jump if end of string has been reached. |
31 | halyavin | 608 | je .exit |
153 | heavyiron | 609 | inc di ; Move past the decimal point. |
610 | cmp si, di ; Jump if end of string has been reached. |
||
31 | halyavin | 611 | je .exit |
612 | mov al, [bx + di] |
||
153 | heavyiron | 613 | cmp al, '0' ; Make sure character is a digit. |
31 | halyavin | 614 | jb .error |
615 | cmp al, '9' |
||
616 | ja .error |
||
153 | heavyiron | 617 | fdiv dword [ten] ; Next decimal place |
31 | halyavin | 618 | sub al, '0' |
619 | mov ah, 0 |
||
620 | mov [tmp], ax |
||
621 | |||
622 | ; Load digit, multiply by value for appropriate decimal place, |
||
623 | ; and add to current total. |
||
624 | |||
625 | fild word [tmp] |
||
626 | fmul st0, st1 |
||
627 | faddp st2, st0 |
||
628 | jmp .mainLoop |
||
629 | |||
630 | .error: |
||
153 | heavyiron | 631 | stc ; Set error (carry) flag. |
632 | fstp st0 ; Pop top of fpu stack. |
||
31 | halyavin | 633 | ret |
634 | |||
635 | .exit: |
||
153 | heavyiron | 636 | clc ; Clear error (carry) flag. |
637 | fstp st0 ; Pop top of fpu stack. |
||
31 | halyavin | 638 | ret |
639 | |||
640 | ; ********************************************* |
||
153 | heavyiron | 641 | ; ******* WINDOW DEFINITIONS AND DRAW ********* |
31 | halyavin | 642 | ; ********************************************* |
643 | |||
644 | draw_window: |
||
153 | heavyiron | 645 | |
646 | mov eax,12 |
||
647 | mov ebx,1 |
||
485 | heavyiron | 648 | mcall |
153 | heavyiron | 649 | |
967 | leency | 650 | mov eax,48 |
651 | mov ebx,3 |
||
652 | mov ecx,sc |
||
653 | mov edx,sizeof.system_colors |
||
654 | mcall |
||
655 | |||
175 | heavyiron | 656 | xor eax,eax |
195 | heavyiron | 657 | mov ebx,200 shl 16+255 |
658 | mov ecx,200 shl 16+180 |
||
153 | heavyiron | 659 | mov edx,[sc.work] |
551 | spraid | 660 | or edx,0x34000000 |
485 | heavyiron | 661 | mov edi,title |
662 | mcall |
||
31 | halyavin | 663 | |
153 | heavyiron | 664 | mov eax,8 |
195 | heavyiron | 665 | mov ebx,19 shl 16+28 |
666 | mov ecx,49 shl 16+18 |
||
31 | halyavin | 667 | mov edx,6 |
153 | heavyiron | 668 | mov esi,[sc.work_button] |
31 | halyavin | 669 | mov edi,7 |
670 | newbutton: |
||
671 | dec edi |
||
672 | jnz no_new_row |
||
107 | heavyiron | 673 | mov edi,7 |
195 | heavyiron | 674 | mov ebx,19 shl 16+28 |
675 | add ecx,20 shl 16 |
||
31 | halyavin | 676 | no_new_row: |
485 | heavyiron | 677 | mcall |
195 | heavyiron | 678 | add ebx,30 shl 16 |
31 | halyavin | 679 | inc edx |
107 | heavyiron | 680 | cmp edx,39 |
31 | halyavin | 681 | jbe newbutton |
153 | heavyiron | 682 | |
382 | heavyiron | 683 | mcall ,199 shl 16+28,49 shl 16+18,2 ; 'C' |
195 | heavyiron | 684 | mcall ,220 shl 16+8,7 shl 16+8,3 ; 'dec-bin-hex' |
153 | heavyiron | 685 | |
686 | mov eax,4 |
||
195 | heavyiron | 687 | mov ebx,27 shl 16+54 |
153 | heavyiron | 688 | mov ecx,[sc.work_button_text] |
31 | halyavin | 689 | mov edx,text |
153 | heavyiron | 690 | mov esi,33 |
31 | halyavin | 691 | newline: |
485 | heavyiron | 692 | mcall |
107 | heavyiron | 693 | add ebx,20 |
153 | heavyiron | 694 | add edx,33 |
31 | halyavin | 695 | cmp [edx],byte 'x' |
696 | jne newline |
||
153 | heavyiron | 697 | |
31 | halyavin | 698 | call print_display |
153 | heavyiron | 699 | |
700 | mov eax,12 |
||
701 | mov ebx,2 |
||
485 | heavyiron | 702 | mcall |
153 | heavyiron | 703 | |
31 | halyavin | 704 | ret |
705 | |||
706 | print_display: |
||
707 | pusha |
||
195 | heavyiron | 708 | mcall 13,18 shl 16+210,19 shl 16+13,0xffffff |
153 | heavyiron | 709 | |
31 | halyavin | 710 | mov eax,4 |
195 | heavyiron | 711 | mov ebx,135 shl 16+7 |
153 | heavyiron | 712 | mov ecx,[sc.work_text] |
713 | or ecx,0x40000000 |
||
714 | mov edx,calc |
||
715 | mov esi,1 |
||
716 | mov edi,[sc.work] |
||
485 | heavyiron | 717 | mcall |
153 | heavyiron | 718 | |
195 | heavyiron | 719 | mov ebx,198 shl 16+8 |
31 | halyavin | 720 | mov edx,[display_type] |
721 | shl edx,2 |
||
722 | add edx,display_type_text |
||
723 | mov esi,3 |
||
153 | heavyiron | 724 | mov edi,[sc.work] |
485 | heavyiron | 725 | mcall |
153 | heavyiron | 726 | |
107 | heavyiron | 727 | cmp [dsign],byte '+' |
153 | heavyiron | 728 | je positive |
195 | heavyiron | 729 | mov ebx,23 shl 16+22 |
153 | heavyiron | 730 | mov ecx,0x0 |
731 | mov edx,dsign |
||
732 | mov esi,1 |
||
485 | heavyiron | 733 | mcall |
153 | heavyiron | 734 | |
735 | positive: |
||
736 | cmp [display_type],0 |
||
31 | halyavin | 737 | jne no_display_decimal |
107 | heavyiron | 738 | cmp [decimal],0 |
739 | je whole |
||
153 | heavyiron | 740 | |
195 | heavyiron | 741 | mov ebx,180 shl 16+22 |
153 | heavyiron | 742 | mov ecx,0x0 |
743 | mov edx,dot |
||
744 | mov esi,1 |
||
485 | heavyiron | 745 | mcall |
153 | heavyiron | 746 | |
747 | mov eax,47 |
||
195 | heavyiron | 748 | mov ebx,10 shl 16 |
153 | heavyiron | 749 | mov ecx,[integer] |
195 | heavyiron | 750 | mov edx,120 shl 16+22 |
153 | heavyiron | 751 | mov esi,0x0 |
485 | heavyiron | 752 | mcall |
153 | heavyiron | 753 | |
195 | heavyiron | 754 | mov ebx,6 shl 16 |
153 | heavyiron | 755 | mov ecx,[decimal] |
195 | heavyiron | 756 | mov edx,187 shl 16+22 |
153 | heavyiron | 757 | mov esi,0x0 |
485 | heavyiron | 758 | mcall |
153 | heavyiron | 759 | |
107 | heavyiron | 760 | popa |
761 | ret |
||
762 | |||
763 | whole: |
||
195 | heavyiron | 764 | mov ebx,220 shl 16+22 |
153 | heavyiron | 765 | mov ecx,0x0 |
766 | mov edx,dot |
||
767 | mov esi,1 |
||
485 | heavyiron | 768 | mcall |
153 | heavyiron | 769 | |
107 | heavyiron | 770 | cmp [integer],0 |
771 | je null |
||
153 | heavyiron | 772 | |
773 | mov eax,47 |
||
195 | heavyiron | 774 | mov ebx,10 shl 16 |
153 | heavyiron | 775 | mov ecx,[integer] |
195 | heavyiron | 776 | mov edx,160 shl 16+22 |
153 | heavyiron | 777 | mov esi,0x0 |
485 | heavyiron | 778 | mcall |
153 | heavyiron | 779 | |
107 | heavyiron | 780 | popa |
781 | ret |
||
153 | heavyiron | 782 | |
31 | halyavin | 783 | no_display_decimal: |
153 | heavyiron | 784 | cmp [display_type],1 |
785 | jne no_display_hexadecimal |
||
107 | heavyiron | 786 | cmp [integer],0 |
787 | je null |
||
153 | heavyiron | 788 | |
789 | mov eax,47 |
||
195 | heavyiron | 790 | mov ebx,256+8 shl 16 |
153 | heavyiron | 791 | mov ecx,[integer] |
195 | heavyiron | 792 | mov edx,173 shl 16+22 |
153 | heavyiron | 793 | mov esi,0x0 |
485 | heavyiron | 794 | mcall |
153 | heavyiron | 795 | |
107 | heavyiron | 796 | popa |
797 | ret |
||
798 | |||
31 | halyavin | 799 | no_display_hexadecimal: |
107 | heavyiron | 800 | cmp [integer],0 |
801 | je null |
||
153 | heavyiron | 802 | |
803 | mov eax,47 |
||
195 | heavyiron | 804 | mov ebx,2*256+32 shl 16 |
153 | heavyiron | 805 | mov ecx,[integer] |
195 | heavyiron | 806 | mov edx,32 shl 16+22 |
153 | heavyiron | 807 | mov esi,0x0 |
485 | heavyiron | 808 | mcall |
153 | heavyiron | 809 | |
31 | halyavin | 810 | popa |
811 | ret |
||
107 | heavyiron | 812 | |
813 | null: |
||
153 | heavyiron | 814 | mov eax,47 |
195 | heavyiron | 815 | mov ebx,1 shl 16 |
153 | heavyiron | 816 | mov ecx,0 |
195 | heavyiron | 817 | mov edx,214 shl 16+22 |
153 | heavyiron | 818 | mov esi,0x0 |
485 | heavyiron | 819 | mcall |
153 | heavyiron | 820 | |
107 | heavyiron | 821 | popa |
822 | ret |
||
31 | halyavin | 823 | |
824 | clear_all: |
||
825 | pusha |
||
826 | mov [calc],' ' |
||
827 | mov [integer],0 |
||
828 | mov [decimal],0 |
||
829 | mov [id],0 |
||
830 | mov [dsign],byte '+' |
||
831 | mov esi,muuta0 |
||
832 | mov edi,muuta1 |
||
833 | mov ecx,18 |
||
834 | cld |
||
835 | rep movsb |
||
836 | mov esi,muuta0 |
||
837 | mov edi,muuta2 |
||
838 | mov ecx,18 |
||
839 | cld |
||
840 | rep movsb |
||
841 | call print_display |
||
842 | popa |
||
843 | ret |
||
844 | |||
845 | |||
153 | heavyiron | 846 | ;data |
31 | halyavin | 847 | |
485 | heavyiron | 848 | title db appname,version,0 |
153 | heavyiron | 849 | |
107 | heavyiron | 850 | display_type dd 0 ; 0 = decimal, 1 = hexadecimal, 2= binary |
31 | halyavin | 851 | entry_multiplier dd 10 |
107 | heavyiron | 852 | display_type_text db 'dec hex bin' |
31 | halyavin | 853 | |
382 | heavyiron | 854 | dot db '.' |
485 | heavyiron | 855 | calc db ' ' |
856 | integer dd 0 |
||
857 | decimal dd 0 |
||
858 | kymppi dd 10 |
||
382 | heavyiron | 859 | ten dd 10.0,0 |
485 | heavyiron | 860 | tmp dw 1,0 |
861 | sign db 1,0 |
||
862 | tmp2 dq 0x0,0 |
||
863 | exp dd 0x0,0 |
||
864 | new_dec dd 100000,0 |
||
865 | id db 0x0,0 |
||
382 | heavyiron | 866 | res dd 0 |
485 | heavyiron | 867 | trans1 dq 0 |
868 | trans2 dq 0 |
||
869 | controlWord dw 1 |
||
822 | diamond | 870 | smallValueForRounding dq 0.0000005 ; 1/2 from last significant digit |
485 | heavyiron | 871 | multipl: dd 10,16,2 |
31 | halyavin | 872 | |
873 | dsign: |
||
485 | heavyiron | 874 | muuta1 db '+0000000000.000000' |
875 | muuta2 db '+0000000000.000000' |
||
876 | muuta0 db '+0000000000.000000' |
||
31 | halyavin | 877 | |
878 | text: |
||
153 | heavyiron | 879 | db ' A B C D E F C ' |
880 | db ' 1 2 3 + Int Sin Asin' |
||
881 | db ' 4 5 6 - 1/x Cos Acos' |
||
882 | db ' 7 8 9 / x^2 Tan Atan' |
||
883 | db '+/- 0 . * Sqr Pi = ' |
||
107 | heavyiron | 884 | db 'x' |
31 | halyavin | 885 | |
107 | heavyiron | 886 | asci: db 49,50,51,52,53,54,55,56,57,48,43,61,45,42,47,44,46,27 |
887 | butid: db 12,13,14,19,20,21,26,27,28,34,15,39,22,36,29,35,35,1 |
||
153 | heavyiron | 888 | |
889 | I_END: |
||
890 | |||
967 | leency | 891 | sc system_colors |