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