Subversion Repositories Kolibri OS

Rev

Rev 7786 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. ;;   Calculator for MenuetOS (c) Ville Turjanmaa
  2. ;;  
  3. ;;   Compile with FASM
  4. ;;  
  5. ;;   Pavel Rymovski (Heavyiron) - version for KolibriOS
  6. ;;
  7. ;; What's new:
  8. ;;   Calc 1.1
  9. ;;           1) changed design
  10. ;;           2) new procedure of draw window (10 decimal digits, 23 binary, "+" not displayed now)
  11. ;;           3) window with skin
  12. ;;   Calc 1.2
  13. ;;           1) added some useful functions, such as arcsin, arccos, arctg, 1/x, x^2
  14. ;;   Calc 1.31
  15. ;;           1) optimised program
  16. ;;           2) new type of window (you need kernel 114 revision or higher)
  17. ;;   Calc 1.32
  18. ;;           1) fixed arccos
  19. ;;   Calc 1.33
  20. ;;           1) align button captions in proper way, finally!
  21. ;;   Calc 1.4 - Leency
  22. ;;           1) better GUI, big fonts
  23.  
  24. use32
  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
  33.  
  34. include '../../../macros.inc'
  35. include '../../../gui_patterns.inc'
  36. include '../../../KOSfuncs.inc'
  37.  
  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.  
  44. START:
  45. red:
  46.         call    draw_window
  47. still:  
  48.         mcall   10
  49.  
  50.         dec     eax
  51.         jz      red
  52.         dec     eax
  53.         jz      key
  54.  
  55. button:
  56.         mcall   17      ; get button id
  57.         shr     eax, 8
  58.         jmp     testbut
  59.  
  60. key:
  61.         mcall   2       ; get ASCII key code
  62.                 and     eax, 0xffff ; supress scancodes
  63.         shr     eax, 8
  64.         mov     edi, asci       ; convert ASCII into button id
  65.         mov     ecx, hotkeys_count
  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
  74.  
  75. testbut:
  76.         cmp     eax, 1  ; button 1 -- exit
  77.         jne     noexit
  78.         mcall   -1
  79.  
  80. noexit:
  81.         cmp     eax, 2
  82.         jne     no_reset
  83.         call    clear_all
  84.         jmp     still
  85.  
  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], '+'
  271.                 call    print_display
  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], '-'
  280.                 call    print_display
  281.         jmp     still
  282.  
  283. no_sub:
  284.         cmp     eax, 29
  285.         jne     no_div
  286.         call    calculate
  287.         call    new_entry
  288.         mov     [calc], '/'
  289.                 call    print_display
  290.         jmp     still
  291.  
  292. no_div:
  293.         cmp     eax, 36
  294.         jne     no_mul
  295.         call    calculate
  296.         mov     [calc], '*'
  297.         call    new_entry
  298.                 call    print_display
  299.         jmp     still
  300.  
  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.  
  315. error:
  316.         jmp     still
  317.  
  318. calculate:
  319.         pusha
  320.         cmp     [calc], ' '
  321.         je      no_calculation
  322.         cmp     [calc], '/'
  323.         jne     no_cdiv
  324.         fdiv    [trans1]
  325.  
  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.  
  349. number_entry:
  350.  
  351.         pusha
  352.  
  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
  370.  
  371. decimal_entry:
  372.  
  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
  384.  
  385. no_entry:
  386.  
  387.         call    print_display
  388.         call    to_muuta
  389.         popa
  390.         ret
  391.  
  392. to_muuta:
  393.  
  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.  
  431. new_entry:
  432.  
  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
  451.  
  452.  
  453. ftoa:                         ; fpu st0 -> [integer],[decimal]
  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
  468.  
  469. no_neg:
  470.         fld     [tmp2]
  471.         cmp     byte [sign], 0     ; change fraction to positive
  472.         je      no_neg2
  473.         fchs
  474.  
  475. no_neg2:
  476.         fadd    [smallValueForRounding]
  477.         fist    [integer]
  478.         fisub   [integer]
  479.         mov     [res], 0     ; convert 6 decimal numbers
  480.         mov     edi, 6
  481.  
  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
  500.  
  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.  
  526. atof:
  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.  
  539.   .noPlus:
  540.         cmp     byte [bx], '-'
  541.         jne     .noMinus
  542.         mov     byte [sign], 1   ; Number is negative.
  543.         inc     di
  544.  
  545.   .noMinus:
  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.  
  556.   .dontNegate:
  557.         mov     bh, 0    ; Set bh to indicate the string is a valid number.
  558.         jmp     .exit
  559.  
  560.   .error:
  561.         mov     bh, 1    ; Set error code.
  562. ;       fstp    st0    ; Pop top of fpu stack.
  563.  
  564.   .exit:
  565.         pop     di
  566.         pop     ax
  567.         ret
  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.  
  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
  583.  
  584.     ; Convert single character to digit and save to memory for
  585.     ; transfer to the FPU.
  586.  
  587.         sub     al, '0'
  588.         mov     ah, 0
  589.         mov     [tmp], ax
  590.  
  591.     ; Multiply current value by 10 and add in digit.
  592.  
  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
  599.  
  600.   .error:
  601.         stc                ; Set error (carry) flag.
  602.         ret
  603.  
  604.   .exit:
  605.         clc                ; Clear error (carry) flag.
  606.         ret
  607.  
  608.  
  609. atof_convertFractionalPart:
  610.         fld1               ; Load 1 to TOS.  This will be the value of the decimal place.
  611.  
  612.   .mainLoop:
  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
  627.  
  628.     ; Load digit, multiply by value for appropriate decimal place,
  629.     ; and add to current total.
  630.  
  631.         fild    word [tmp]
  632.         fmul    st0, st1
  633.         faddp   st2, st0
  634.         jmp     .mainLoop
  635.  
  636.   .error:
  637.         stc           ; Set error (carry) flag.
  638.         fstp    st0    ; Pop top of fpu stack.
  639.         ret
  640.  
  641.   .exit:
  642.         clc              ; Clear error (carry) flag.
  643.         fstp    st0    ; Pop top of fpu stack.
  644.         ret
  645.  
  646. ;   *********************************************
  647. ;   ******* WINDOW DEFINITIONS AND DRAW *********
  648. ;   *********************************************
  649.  
  650. BTNSP_X equ 39
  651. DISPLAY_X equ 20
  652. DISPLAY_Y equ 18
  653. DISPLAY_W equ 208
  654. DISPLAY_H equ 26
  655.  
  656. draw_window:
  657.         mcall   12, 1
  658.  
  659.         mcall   48, 3, sc, sizeof.system_colors
  660.  
  661.                 mcall SF_STYLE_SETTINGS, SSF_GET_SKIN_HEIGHT
  662.  
  663.                 mov     ecx, 200 shl 16 + 210
  664.                 add     ecx, eax                ; add skin height to window height
  665.         mov     edx, [sc.work]
  666.         or      edx, 0x34000000
  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
  673.         mov     edx, 6
  674.         mov     esi, [sc.work_button]
  675.         mov     edi, 7
  676. newbutton:
  677.         dec     edi
  678.         jnz     no_new_row
  679.         mov     edi, 7
  680.         mov     ebx, 19 shl 16 + 36
  681.         add     ecx, 28 shl 16
  682. no_new_row:
  683.         mcall
  684.         add     ebx, BTNSP_X shl 16
  685.         inc     edx
  686.         cmp     edx, BTNSP_X
  687.         jbe     newbutton
  688.  
  689.         mcall   , <253, 36>, <55, 22>, 2, 0xF0969D  ; 'C'
  690.  
  691.  
  692.         mov     ecx, [sc.work_button_text]
  693.                 or      ecx, 0x10000000
  694.         mov     edx, text
  695.         mov     edi, 31
  696. next_line:
  697.         inc     edx
  698.         and     edi, 0x0000ffff
  699.         add     edi, 24 SHL 16 + 28
  700. next_button:
  701.         movzx   esi, byte[edx - 1]
  702.         imul    eax, esi, 8
  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
  712.         add     edi, BTNSP_X SHL 16
  713.         cmp     [edx - 1], byte 0
  714.                 jne     next_button
  715.         cmp     [edx], byte 'x'
  716.         jne     next_line
  717.  
  718.                 DrawRectangle3D DISPLAY_X-1,DISPLAY_Y-1,DISPLAY_W+2,DISPLAY_H+2, [sc.work_dark], [sc.work_light]
  719.                 DrawRectangle DISPLAY_X,DISPLAY_Y,DISPLAY_W,DISPLAY_H, [sc.work_graph]
  720.         mcall   38, < DISPLAY_X+1, DISPLAY_W+DISPLAY_X-1>, <DISPLAY_Y+1, DISPLAY_Y+1>, 0xE0E0E0 ; internal shadow
  721.                 mcall     , < DISPLAY_X+1,  DISPLAY_X+1>, <DISPLAY_Y+2, DISPLAY_Y+DISPLAY_H-1>,          ; internal shadow
  722.                
  723.         call    print_display
  724.  
  725.         mcall   12, 2
  726.         ret
  727.  
  728. print_display:
  729.         pusha
  730.                 mcall   13, < DISPLAY_X+2, DISPLAY_W-2>, <DISPLAY_Y+2, DISPLAY_H-2>, 0xFFFfff ; background
  731.                 mcall   8, <236,53>, <DISPLAY_Y,DISPLAY_H>, 3, [sc.work]        ; 'dec-bin-hex'
  732.                
  733.         mov     ecx, [sc.work_text]
  734.         or      ecx, 0x40000000
  735.         mcall   4, <135,6>,,calc,1,[sc.work]
  736.                
  737.         mov     edx, [display_type]
  738.         shl     edx, 2
  739.         add     edx, display_type_text
  740.         mov     esi, 3
  741.                 mov     ecx, [sc.work_text]
  742.                 or      ecx, 0x10000000
  743.         mcall   4,<250,DISPLAY_Y+(DISPLAY_H-14)/2>
  744.  
  745.         cmp     [dsign], byte '+'
  746.         je      positive
  747.         mcall   , <23, 26>, 0, dsign, 1
  748.  
  749. positive:  
  750.         cmp     [display_type], 0
  751.         jne     no_display_decimal
  752.         cmp     [decimal], 0
  753.         je      whole
  754.  
  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]
  758.  
  759.         popa
  760.         ret
  761.  
  762. whole:
  763.         mcall   , <214, 26>, [number_color], dot, 1
  764.  
  765.         cmp     [integer], 0
  766.         je      null
  767.         mcall   47, <10, 0>, [integer], <94, 26>, [number_color]
  768.         popa
  769.         ret
  770.  
  771. no_display_decimal:
  772.         cmp     [display_type], 1
  773.         jne     no_display_hexadecimal
  774.         cmp     [integer], 0
  775.         je      null
  776.         mcall   47, <8, 256>, [integer], <130, 26>, [number_color]
  777.         popa
  778.         ret
  779.  
  780. no_display_hexadecimal:
  781.         cmp     [integer], 0
  782.         je      null
  783.         mcall   47, <32, 2*256>, [integer], <32, 30>, 0
  784.         popa
  785.         ret
  786.  
  787. null:
  788.         mcall   47, <1, 0>, 0, <202, 26>, [number_color]
  789.         popa
  790.         ret
  791.  
  792. clear_all:
  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
  812.  
  813.  
  814. ;data
  815.  
  816. title   db 'Calc 1.45', 0
  817.  
  818. display_type            dd  0    ; 0 = decimal, 1 = hexadecimal, 2= binary
  819. entry_multiplier        dd  10
  820. display_type_text       db  'dec hex bin'
  821. number_color            dd 0x81333333
  822.  
  823. dot             db  '.',0
  824. calc            db  ' ',0
  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
  841.  
  842. dsign:
  843. muuta1          db  '+0000000000.000000'
  844. muuta2          db  '+0000000000.000000'
  845. muuta0          db  '+0000000000.000000'
  846.  
  847. text:
  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,'*', 4,'Sqrt',2,'Pi',  1,'=', 0
  853.         db 'x'
  854.  
  855. I_END:
  856.  
  857. sc      system_colors
  858. rb      0x200   ; stack
  859. E_END:
  860.