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