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