Subversion Repositories Kolibri OS

Rev

Rev 2745 | Rev 4935 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2745 Rev 3625
Line 14... Line 14...
14
;;   Calc 1.31
14
;;   Calc 1.31
15
;;           1)optimised program
15
;;           1) optimised program
16
;;           2)new type of window (you need kernel 114 revision or higher)
16
;;           2) new type of window (you need kernel 114 revision or higher)
17
;;   Calc 1.32
17
;;   Calc 1.32
18
;;           1)fixed arccos
18
;;           1) fixed arccos
-
 
19
;;   Calc 1.33
-
 
20
;;           1) align button captions in proper way, finally!
Line 19... Line -...
19
 
-
 
20
 
-
 
21
appname equ 'Calc '
-
 
22
version    equ '1.32'
21
 
23
 
22
 
24
use32
23
use32
25
               org    0x0
24
        org     0x0
26
               db    'MENUET01'            ; 8 byte id
25
        db      'MENUET01'      ; 8 byte id
27
               dd     0x01                      ; header version
26
        dd      0x01            ; header version
28
               dd     START                    ; start of code
27
        dd      START           ; start of code
29
               dd     I_END                    ; size of image
28
        dd      I_END           ; size of image
30
               dd     0x1000                  ; memory for app
29
        dd      E_END           ; memory for app
Line 31... Line 30...
31
               dd     0x1000                  ; esp
30
        dd      E_END           ; esp
Line 32... Line 31...
32
               dd     0x0,0x0                 ; I_Param , I_Icon
31
        dd      0x0,0x0         ; I_Param , I_Icon
33
 
-
 
34
include '..\..\..\macros.inc'
32
 
35
 
33
include '../../../macros.inc'
36
START:
-
 
37
 
34
 
38
 red:
-
 
39
    call draw_window
-
 
40
 
35
START:
Line 41... Line 36...
41
 still:  
36
red:
42
    push 10 
37
        call    draw_window
43
    pop eax 
38
still:  
44
    mcall
39
        mcall   10
Line 45... Line 40...
45
 
40
 
46
    dec eax
41
        dec     eax
47
    jz red
-
 
48
    dec eax 
42
        jz      red
49
    jz key 
43
        dec     eax 
Line 50... Line 44...
50
 
44
        jz      key 
51
  button:
45
 
52
    mov  al,17      ; ¯®«ãç¨âì ¨¤¥­â¨ä¨ª â®à ­ ¦ â®© ª­®¯ª¨
-
 
53
    mcall
46
button:
54
    shr  eax,8
47
        mcall   17      ; get button id
55
    jmp  testbut
48
        shr     eax, 8
56
 
49
        jmp     testbut
57
  key:         
50
 
58
    mov  al,2       ; ¯®«ãç¨âì ASCII-ª®¤ ­ ¦ â®© ª« ¢¨è¨
51
key:
59
    mcall
52
        mcall   2       ; get ASCII key code
Line 68... Line 61...
68
    mov  esi,butid
61
        mov     esi, butid
69
    add  esi,edi
62
        add     esi, edi
70
    lodsb
63
        lodsb
Line 71... Line 64...
71
     
64
 
72
  testbut:
65
testbut:
73
    cmp  eax,1      ; ª­®¯ª  1 - § ªàë⨥ ¯à®£à ¬¬ë
66
        cmp     eax, 1  ; button 1 -- exit
74
    jne  noclose
67
        jne     noexit
75
    or   eax,-1
-
 
Line 76... Line 68...
76
    mcall 
68
        mcall   -1
77
 
69
 
78
  noclose:
70
noexit:
79
    cmp  eax,2
71
        cmp     eax, 2
80
    jne  no_reset
72
        jne     no_reset
Line 81... Line 73...
81
    call clear_all
73
        call    clear_all
82
    jmp  still
74
        jmp     still
83
  
75
 
84
  no_reset:
76
no_reset:
85
    finit
77
        finit
86
    mov  ebx,muuta1  ; ¥à¥¢®¤ ¢ ä®à¬ â FPU
78
        mov     ebx, muuta1     ; convert to FPU format
87
    mov  esi,18
79
        mov     esi, 18
88
    call atof
80
        call    atof
Line 347... Line 339...
347
    cmp  eax,[entry_multiplier]
339
        cmp     eax, [entry_multiplier]
348
    jge  no_entry
340
        jge     no_entry
349
    cmp  [id],1
341
        cmp     [id], 1
350
    je   decimal_entry
342
        je      decimal_entry
351
    mov  ebx,[integer]
343
        mov     ebx, [integer]
352
    test ebx,0xF0000000
344
        test    ebx, 0xf0000000
353
    jnz  no_entry
345
        jnz     no_entry
354
    mov  ebx,eax
346
        mov     ebx, eax
355
    mov  eax,[integer]
347
        mov     eax, [integer]
356
    mov  ecx,[entry_multiplier]
348
        mov     ecx, [entry_multiplier]
357
    mul  ecx
349
        mul     ecx
Line 391... Line 383...
391
    mov  edi,muuta1
383
        mov     edi, muuta1
392
    mov  ecx,18
384
        mov     ecx, 18
393
    cld
385
        cld
394
    rep  movsb
386
        rep     movsb
395
    mov  [muuta1],al
387
        mov     [muuta1], al
396
    mov  edi,muuta1+10     ; 楫®¥
388
        mov     edi, muuta1+10     ; []
397
    mov  eax,[integer]
389
        mov     eax, [integer]
Line 398... Line 390...
398
  
390
 
Line 399... Line 391...
399
  new_to_muuta1:
391
new_to_muuta1:
Line 404... Line 396...
404
    mov  [edi],dl
396
        mov     [edi], dl
405
    add  [edi],byte 48
397
        add     [edi], byte 48
406
    dec  edi
398
        dec     edi
407
    cmp  edi,muuta1+1
399
        cmp     edi, muuta1+1
408
    jge  new_to_muuta1
400
        jge     new_to_muuta1
409
    mov  edi,muuta1+17     ; ¤à®¡­®¥
401
        mov     edi, muuta1+17     ; {}
410
    mov  eax,[decimal]
402
        mov     eax, [decimal]
Line 411... Line 403...
411
  
403
 
Line 412... Line 404...
412
  new_to_muuta2:
404
new_to_muuta2:
Line 640... Line 632...
640
;   *********************************************
632
;   *********************************************
641
;   ******* WINDOW DEFINITIONS AND DRAW *********
633
;   ******* WINDOW DEFINITIONS AND DRAW *********
642
;   *********************************************
634
;   *********************************************
Line 643... Line 635...
643
 
635
 
-
 
636
draw_window:
Line 644... Line 637...
644
draw_window:
637
        mcall   12, 1
645
    
-
 
646
    mov  eax,12
-
 
Line 647... Line -...
647
    mov  ebx,1
-
 
648
    mcall
-
 
649
                                   
638
 
650
    mov  eax,48
-
 
651
    mov  ebx,3
-
 
Line 652... Line -...
652
    mov  ecx,sc
-
 
653
    mov  edx,sizeof.system_colors
-
 
654
    mcall
-
 
655
 
639
        mcall   48, 3, sc, sizeof.system_colors
656
    mov  eax,48
640
 
657
    mov  ebx,4
641
        mcall   48, 4
658
    int  0x40
642
 
659
    mov  ecx, eax
643
        mov     ecx, eax
Line 682... Line 666...
682
    add  ebx,30 shl 16
666
        add     ebx, 30 shl 16
683
    inc  edx
667
        inc     edx
684
    cmp  edx,39
668
        cmp     edx, 39
685
    jbe  newbutton
669
        jbe     newbutton
Line 686... Line 670...
686
  
670
 
687
    mcall  ,199 shl 16+28,49 shl 16+18,2               ; 'C'
671
        mcall   , <199, 28>, <49, 18>, 2        ; 'C'
-
 
672
        mcall   , <220,  8>, < 7,  8>, 3        ; 'dec-bin-hex'
Line 688... Line -...
688
    mcall  ,220 shl 16+8,7 shl 16+8,3                     ; 'dec-bin-hex'
-
 
689
 
-
 
690
    mov  eax,4
673
 
691
    mov  ebx,27 shl 16+55
674
 
692
    mov  ecx,[sc.work_button_text]
675
        mov     ecx, [sc.work_button_text]
693
    mov  edx,text
676
        mov     edx, text
-
 
677
        mov     edi, 55 - 20
-
 
678
next_line:
-
 
679
        inc     edx
-
 
680
        and     edi, 0x0000ffff
-
 
681
        add     edi, 20 SHL 16 + 20
-
 
682
next_button:
-
 
683
        movzx   esi, byte[edx - 1]
-
 
684
        imul    eax, esi, 6
-
 
685
        neg     eax
-
 
686
        add     eax, 29
-
 
687
        shr     eax, 1
-
 
688
        shl     eax, 16
694
    mov  esi,33
689
        mov     ebx, edi
695
  newline:
690
        add     ebx, eax
696
    mcall
691
        mcall   4
-
 
692
        add     edx, esi
-
 
693
        inc     edx
-
 
694
        add     edi, 30 SHL 16
697
    add  ebx,20
695
        cmp     [edx - 1], byte 0
698
    add  edx,33
696
        jne     next_button
Line 699... Line 697...
699
    cmp  [edx],byte 'x'
697
        cmp     [edx], byte 'x'
Line 700... Line 698...
700
    jne  newline
698
        jne     next_line
701
    
-
 
702
    call print_display
-
 
703
    
-
 
704
    mov  eax,12
699
 
Line 705... Line 700...
705
    mov  ebx,2
700
        call    print_display
706
    mcall
701
 
707
 
702
        mcall   12, 2
Line 708... Line 703...
708
    ret
703
        ret
709
 
704
 
710
print_display:
705
print_display:
711
    pusha
706
        pusha
Line 728... Line 723...
728
    mov  edi,[sc.work]
723
        mov     edi, [sc.work]
729
    mcall
724
        mcall
Line 730... Line 725...
730
   
725
 
731
    cmp  [dsign],byte '+'
726
        cmp     [dsign], byte '+'
732
    je   positive
727
        je      positive
733
    mov  ebx,23 shl 16+22
-
 
734
    mov  ecx,0x0
-
 
735
    mov  edx,dsign
-
 
736
    mov  esi,1
-
 
Line 737... Line 728...
737
    mcall  
728
        mcall   , <23, 22>, 0, dsign, 1
738
 
729
 
739
positive:  
730
positive:  
740
    cmp  [display_type],0
731
        cmp     [display_type], 0
741
    jne  no_display_decimal
732
        jne     no_display_decimal
Line 742... Line 733...
742
    cmp  [decimal],0
733
        cmp     [decimal], 0
743
    je   whole
-
 
744
 
-
 
745
    mov  ebx,180 shl 16+22
-
 
746
    mov  ecx,0x0
-
 
747
    mov  edx,dot
-
 
748
    mov  esi,1
-
 
749
    mcall
-
 
750
    
734
        je      whole
751
    mov  eax,47
-
 
752
    mov  ebx,10 shl 16
-
 
753
    mov  ecx,[integer]
-
 
754
    mov  edx,120 shl 16+22
-
 
755
    mov  esi,0x0
-
 
756
    mcall     
735
 
757
    
-
 
758
    mov  ebx,6 shl 16
-
 
759
    mov  ecx,[decimal]
-
 
Line 760... Line 736...
760
    mov  edx,187 shl 16+22     
736
        mcall   , <180, 22>, 0, dot, 1
761
    mov  esi,0x0
737
        mcall   47, <10, 0>, [integer], <120, 22>, 0
Line 762... Line 738...
762
    mcall 
738
        mcall   , <6, 0>, [decimal], <187, 22>, 0
763
 
739
 
764
    popa
-
 
765
    ret
-
 
766
    
-
 
767
whole:
-
 
Line 768... Line 740...
768
    mov  ebx,220 shl 16+22
740
        popa
769
    mov  ecx,0x0
741
        ret
770
    mov  edx,dot
-
 
771
    mov  esi,1
-
 
772
    mcall
-
 
773
 
-
 
774
    cmp  [integer],0
742
 
775
    je  null
-
 
776
 
-
 
777
    mov  eax,47
-
 
778
    mov  ebx,10 shl 16
743
whole:
779
    mov  ecx,[integer]
744
        mcall   , <220, 22>, 0, dot, 1
Line 780... Line 745...
780
    mov  edx,160 shl 16+22
745
 
781
    mov  esi,0x0
746
        cmp     [integer], 0
782
    mcall
747
        je      null
783
 
748
        mcall   47, <10, 0>, [integer], <160, 22>, 0
784
    popa
749
        popa
785
    ret
-
 
786
              
-
 
787
  no_display_decimal:
-
 
788
    cmp  [display_type],1
750
        ret
789
    jne  no_display_hexadecimal
-
 
790
    cmp  [integer],0
-
 
791
    je  null
-
 
792
    
-
 
793
    mov  eax,47
751
 
794
    mov  ebx,256+8 shl 16
752
no_display_decimal:
Line 795... Line 753...
795
    mov  ecx,[integer]
753
        cmp     [display_type], 1
796
    mov  edx,173 shl 16+22
754
        jne     no_display_hexadecimal
797
    mov  esi,0x0
755
        cmp     [integer], 0
798
    mcall
-
 
799
 
-
 
800
    popa
756
        je      null
801
    ret
-
 
802
 
-
 
803
  no_display_hexadecimal:
-
 
804
    cmp  [integer],0
-
 
805
    je  null
-
 
806
 
757
        mcall   47, <8, 256>, [integer], <173, 22>, 0
807
    mov  eax,47
758
        popa
Line 808... Line 759...
808
    mov  ebx,2*256+32 shl 16
759
        ret
809
    mov  ecx,[integer]
-
 
810
    mov  edx,32 shl 16+22
-
 
811
    mov  esi,0x0
-
 
812
    mcall
760
 
813
 
-
 
814
    popa
-
 
815
    ret
-
 
816
  
761
no_display_hexadecimal:
817
  null:
762
        cmp     [integer], 0
Line 818... Line 763...
818
    mov  eax,47
763
        je      null
819
    mov  ebx,1 shl 16
764
        mcall   47, <32, 2*256>, [integer], <32, 22>, 0
Line 847... Line 792...
847
    ret
792
        ret
Line 848... Line 793...
848
 
793
 
Line 849... Line 794...
849
 
794
 
Line 850... Line 795...
850
;data
795
;data
851
 
796
 
852
title db appname,version,0
797
title   db 'Calc 1.33', 0
Line 861... Line 806...
861
decimal       dd  0
806
decimal         dd  0
862
kymppi        dd  10
807
kymppi          dd  10
863
ten           dd  10.0,0
808
ten             dd  10.0, 0
864
tmp           dw  1,0
809
tmp             dw  1, 0
865
sign          db  1,0
810
sign            db  1, 0
866
tmp2          dq  0x0,0
811
tmp2            dq  0, 0
867
exp           dd  0x0,0
812
exp             dd  0, 0
868
new_dec       dd  100000,0
813
new_dec         dd  100000, 0
869
id            db  0x0,0
814
id              db  0, 0
870
res           dd  0
815
res             dd  0
871
trans1        dq  0
816
trans1          dq  0
872
trans2        dq  0
817
trans2          dq  0
873
controlWord   dw  1
818
controlWord     dw  1
874
smallValueForRounding dq 0.0000005 ; 1/2 from last significant digit
819
smallValueForRounding dq        0.0000005 ; 1/2 from last significant digit
875
multipl:      dd  10,16,2
820
multipl         dd  10,16,2
Line 876... Line 821...
876
 
821
 
877
dsign:
822
dsign:
878
muuta1        db  '+0000000000.000000'
823
muuta1          db  '+0000000000.000000'
879
muuta2        db  '+0000000000.000000'
824
muuta2          db  '+0000000000.000000'
Line 880... Line 825...
880
muuta0        db  '+0000000000.000000'
825
muuta0          db  '+0000000000.000000'
881
 
826
 
882
text:
827
text:
883
    db ' A    B    C    D    E    F    C '
828
        db 1,'A',   1,'B', 1,'C', 1,'D', 1,'E',   1,'F',   3,'CLR', 0
884
    db ' 1    2    3    +   Int  Sin Asin'
829
        db 1,'1',   1,'2', 1,'3', 1,'+', 3,'Int', 3,'Sin', 4,'Asin', 0
885
    db ' 4    5    6    -   1/x  Cos Acos'
830
        db 1,'4',   1,'5', 1,'6', 1,'-', 3,'1/x', 3,'Cos', 4,'Acos', 0
886
    db ' 7    8    9    /   x^2  Tan Atan'
831
        db 1,'7',   1,'8', 1,'9', 1,'/', 3,'x^2', 3,'Tan', 4,'Atan', 0
Line 887... Line 832...
887
    db '+/-   0    .    *   Sqr  Pi    = '
832
        db 3,'+/-', 1,'0', 1,'.', 1,'*', 3,'Sqr', 2,'Pi',  1,'=', 0
888
    db 'x'
833
        db 'x'
Line 889... Line 834...
889
 
834
 
Line 890... Line 835...
890
asci:  db 49,50,51,52,53,54,55,56,57,48,43,61,45,42,47,44,46,27
835
asci:   db 49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 43, 61, 45, 42, 47, 44, 46, 27
-
 
836
butid:  db 12, 13, 14, 19, 20, 21, 26, 27, 28, 34, 15, 39, 22, 36, 29, 35, 35, 1
-
 
837