Subversion Repositories Kolibri OS

Rev

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