Subversion Repositories Kolibri OS

Rev

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