Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;;
  3. ;;   Calculator for MenuetOS
  4. ;;
  5. ;;   Compile with FASM for Menuet
  6. ;;
  7.  
  8.  
  9. use32
  10.  
  11.                org    0x0
  12.  
  13.                db     'MENUET01'              ; 8 byte id
  14.                dd     0x01                    ; header version
  15.                dd     START                   ; start of code
  16.                dd     I_END                   ; size of image
  17.                dd     0x1000                  ; memory for app
  18.                dd     0x1000                  ; esp
  19.                dd     0x0 , 0x0               ; I_Param , I_Icon
  20.  
  21. include 'lang.inc'
  22. include 'macros.inc'
  23.  
  24. START:                          ; start of execution
  25.  
  26.      call draw_window
  27.  
  28. still:
  29.  
  30.     mov  eax,10                 ; wait here for event
  31.     int  0x40
  32.  
  33.     cmp  eax,1                  ; redraw request ?
  34.     je   red
  35.     cmp  eax,2                  ; key in buffer ?
  36.     je   key
  37.     cmp  eax,3                  ; button in buffer ?
  38.     je   button
  39.  
  40.     jmp  still
  41.  
  42.   red:                          ; redraw
  43.     call draw_window
  44.     jmp  still
  45.  
  46.   key:                          ; key
  47.     mov  eax,2
  48.     int  0x40
  49.     shr  eax,8
  50.     mov  edi,asci             ;translation & emulation
  51.     mov  ecx,35               ;of button ID's
  52.     cld
  53.     repne scasb
  54.     jne  still
  55.     sub  edi,asci
  56.     dec  edi
  57.     mov  esi,butid
  58.     add  esi,edi
  59.     lodsb
  60.     jmp  testbut
  61.  
  62.   button:                       ; button
  63.     mov  eax,17                 ; get id
  64.     int  0x40
  65.  
  66.     shr  eax,8
  67.   testbut:
  68.     cmp  eax,1                   ; button id=1 ?
  69.     jne  noclose
  70.     mov  eax,-1                  ; close this program
  71.     int  0x40
  72.   noclose:
  73.  
  74.     cmp  eax,2
  75.     jne  no_reset
  76.     call clear_all
  77.     jmp  still
  78.   no_reset:
  79.  
  80.     finit
  81.  
  82.     mov    ebx,muuta1    ; Transform to fpu format
  83.     mov    esi,18
  84.     call   atof
  85.     fstp   [trans1]
  86.  
  87.     mov    ebx,muuta2
  88.     mov    esi,18
  89.     call   atof
  90.     fstp   [trans2]
  91.  
  92.     fld    [trans2]
  93.  
  94.     cmp  eax,30
  95.     jne  no_sign
  96.     cmp  [dsign],byte '-'
  97.     jne  no_m
  98.     mov  [dsign],byte '+'
  99.     call print_display
  100.     jmp  still
  101.   no_m:
  102.     mov  [dsign],byte '-'
  103.     call print_display
  104.     jmp  still
  105.   no_sign:
  106.  
  107.     cmp  eax,3
  108.     jne  no_display_change
  109.     inc  [display_type]
  110.     cmp  [display_type],2
  111.     jbe  display_continue
  112.     mov  [display_type],0
  113.   display_continue:
  114.     mov  eax,[display_type]
  115.     mov  eax,[multipl+eax*4]
  116.     mov  [entry_multiplier],eax
  117.     call print_display
  118.     jmp  still
  119.   multipl:  dd  10,16,2
  120.  
  121.   no_display_change:
  122.  
  123.  
  124.     cmp  eax,6
  125.     jb   no_10_15
  126.     cmp  eax,11
  127.     jg   no_10_15
  128.     add  eax,4
  129.     call number_entry
  130.     jmp  still
  131.    no_10_15:
  132.  
  133.     cmp  eax,12
  134.     jb   no_13
  135.     cmp  eax,14
  136.     jg   no_13
  137.     sub  eax,11
  138.     call number_entry
  139.     jmp  still
  140.    no_13:
  141.  
  142.     cmp  eax,12+6
  143.     jb   no_46
  144.     cmp  eax,14+6
  145.     jg   no_46
  146.     sub  eax,11+3
  147.     call number_entry
  148.     jmp  still
  149.    no_46:
  150.  
  151.     cmp  eax,12+12
  152.     jb   no_79
  153.     cmp  eax,14+12
  154.     jg   no_79
  155.     sub  eax,11+6
  156.     call number_entry
  157.     jmp  still
  158.    no_79:
  159.  
  160.     cmp  eax,13+18
  161.     jne  no_0
  162.     mov  eax,0
  163.     call number_entry
  164.     jmp  still
  165.     no_0:
  166.  
  167.     cmp  eax,32
  168.     jne  no_id
  169.     inc  [id]
  170.     and  [id],1
  171.     mov  [new_dec],100000
  172.     jmp  still
  173.   no_id:
  174.  
  175.     cmp  eax,16
  176.     jne  no_sin
  177.     fld  [trans1]
  178.     fsin
  179.     jmp  show_result
  180.   no_sin:
  181.  
  182.     cmp  eax,17
  183.     jne  no_int
  184.     fld  [trans1]
  185.     frndint
  186.     jmp  show_result
  187.   no_int:
  188.  
  189.     cmp  eax,22
  190.     jne  no_cos
  191.     fld  [trans1]
  192.     fcos
  193.     jmp  show_result
  194.   no_cos:
  195.  
  196.     cmp  eax,23
  197.     jne  no_lg2
  198.     fldlg2
  199.     jmp  show_result
  200.   no_lg2:
  201.  
  202.     cmp  eax,28
  203.     jne  no_tan
  204.     fld  [trans1]
  205.     fcos
  206.     fstp [tmp2]
  207.     fld  [trans1]
  208.     fsin
  209.     fdiv [tmp2]
  210.     jmp  show_result
  211.   no_tan:
  212.  
  213.     cmp  eax,29
  214.     jne  no_pi
  215.     fldpi
  216.     jmp  show_result
  217.    no_pi:
  218.  
  219.     cmp  eax,34
  220.     jne  no_sqrt
  221.     fld  [trans1]
  222.     fsqrt
  223.     jmp  show_result
  224.   no_sqrt:
  225.  
  226.     cmp  eax,15
  227.     jne  no_add
  228.     call calculate
  229.     call print_display
  230.     call new_entry
  231.     mov  [calc],'+'
  232.     jmp  still
  233.   no_add:
  234.  
  235.     cmp  eax,21
  236.     jne  no_sub
  237.     call calculate
  238.     call print_display
  239.     call new_entry
  240.     mov  [calc],'-'
  241.     jmp  still
  242.   no_sub:
  243.  
  244.     cmp  eax,27
  245.     jne  no_div
  246.     call calculate
  247.     call print_display
  248.     call new_entry
  249.     mov  [calc],'/'
  250.     jmp  still
  251.   no_div:
  252.  
  253.     cmp  eax,33
  254.     jne  no_mul
  255.     call calculate
  256.     call print_display
  257.     mov  [calc],'*'
  258.     call new_entry
  259.     jmp  still
  260.   no_mul:
  261.  
  262.     cmp    eax,35
  263.     jne    no_calc
  264.     call   calculate
  265.     jmp    still
  266.   no_calc:
  267.  
  268.     jmp  still
  269.  
  270.   show_result:
  271.  
  272.     call   ftoa
  273.     call   print_display
  274.  
  275.     jmp    still
  276.  
  277. error:
  278.  
  279.     jmp  still
  280.  
  281.  
  282. calculate:
  283.  
  284.     pusha
  285.  
  286.     cmp  [calc],' '
  287.     je   no_calculation
  288.  
  289.     cmp  [calc],'/'
  290.     jne  no_cdiv
  291.     fdiv [trans1]
  292.   no_cdiv:
  293.  
  294.     cmp  [calc],'*'
  295.     jne  no_cmul
  296.     fmul [trans1]
  297.   no_cmul:
  298.  
  299.     cmp  [calc],'+'
  300.     jne  no_cadd
  301.     fadd [trans1]
  302.   no_cadd:
  303.  
  304.     cmp  [calc],'-'
  305.     jne  no_cdec
  306.     fsub [trans1]
  307.   no_cdec:
  308.  
  309.     call   ftoa
  310.     call   print_display
  311.  
  312.   no_calculation:
  313.  
  314.     popa
  315.  
  316.     ret
  317.  
  318.  
  319.  
  320. number_entry:
  321.  
  322.     pusha
  323.  
  324.     cmp  eax,[entry_multiplier]
  325.     jge  no_entry
  326.  
  327.     cmp  [id],1
  328.     je   decimal_entry
  329.  
  330.     mov  ebx,[integer]
  331.     test ebx,0xF0000000
  332.     jnz  no_entry
  333.  
  334.     mov  ebx,eax
  335.     mov  eax,[integer]
  336.     mov  ecx,[entry_multiplier]
  337.     mul  ecx
  338.     add  eax,ebx
  339.     mov  [integer],eax
  340.     call print_display
  341.  
  342.     call to_muuta
  343.  
  344.     popa
  345.     ret
  346.  
  347.   decimal_entry:
  348.  
  349.     imul eax,[new_dec]
  350.     add  [decimal],eax
  351.  
  352.     mov  eax,[new_dec]
  353.     xor  edx,edx
  354.     mov  ebx,[entry_multiplier]
  355.     div  ebx
  356.     mov  [new_dec],eax
  357.  
  358.     call print_display
  359.  
  360.     call to_muuta
  361.  
  362.     popa
  363.  
  364.     ret
  365.  
  366.   no_entry:
  367.  
  368.     call print_display
  369.  
  370.     call to_muuta
  371.  
  372.     popa
  373.     ret
  374.  
  375.  
  376. to_muuta:
  377.  
  378.     pusha
  379.  
  380.     mov  al,[dsign]
  381.  
  382.     mov  esi,muuta0
  383.     mov  edi,muuta1
  384.     mov  ecx,18
  385.     cld
  386.     rep  movsb
  387.  
  388.     mov  [muuta1],al
  389.  
  390.     mov  edi,muuta1+10      ; INTEGER
  391.     mov  eax,[integer]
  392.   new_to_muuta1:
  393.     mov  ebx,10
  394.     xor  edx,edx
  395.     div  ebx
  396.     mov  [edi],dl
  397.     add  [edi],byte 48
  398.     dec  edi
  399.     cmp  edi,muuta1+1
  400.     jge  new_to_muuta1
  401.  
  402.     mov  edi,muuta1+17      ; DECIMAL
  403.     mov  eax,[decimal]
  404.   new_to_muuta2:
  405.     mov  ebx,10
  406.     xor  edx,edx
  407.     div  ebx
  408.     mov  [edi],dl
  409.     add  [edi],byte 48
  410.     dec  edi
  411.     cmp  edi,muuta1+12
  412.     jge  new_to_muuta2
  413.  
  414.     call print_muuta
  415.  
  416.     popa
  417.     ret
  418.  
  419.  
  420.  
  421. print_muuta:
  422.  
  423.     pusha
  424.  
  425.     mov  eax,13
  426.     mov  ebx,25*65536+125
  427.     mov  ecx,200*65536+22
  428.     mov  edx,0xffffff
  429.     int  0x40
  430.  
  431.     mov  eax,4
  432.     mov  ebx,25*65536+200
  433.     mov  ecx,0x0
  434.     mov  edx,muuta1
  435.     mov  esi,18
  436.     int  0x40
  437.  
  438.     mov  eax,4
  439.     mov  ebx,25*65536+210
  440.     mov  ecx,0x0
  441.     mov  edx,muuta2
  442.     mov  esi,18
  443.     int  0x40
  444.  
  445.     popa
  446.     ret
  447.  
  448.  
  449.  
  450. new_entry:
  451.  
  452.     pusha
  453.  
  454.     mov  esi,muuta1
  455.     mov  edi,muuta2
  456.     mov  ecx,18
  457.     cld
  458.     rep  movsb
  459.  
  460.     mov  esi,muuta0
  461.     mov  edi,muuta1
  462.     mov  ecx,18
  463.     cld
  464.     rep  movsb
  465.  
  466.     mov  [integer],0
  467.     mov  [decimal],0
  468.     mov  [id],0
  469.     mov  [new_dec],100000
  470.     mov  [sign],byte '+'
  471.  
  472.     popa
  473.     ret
  474.  
  475. ten        dd    10.0,0
  476. tmp        dw       1,0
  477. sign       db       1,0
  478. tmp2       dq     0x0,0
  479. exp        dd     0x0,0
  480. new_dec    dd  100000,0
  481. id         db     0x0,0
  482.  
  483. k8         dd 10000000
  484. k8r        dq 0
  485.  
  486. res     dd   0
  487.  
  488. trans1  dq   0
  489. trans2  dq   0
  490.  
  491. controlWord dw 1
  492.  
  493.  
  494.  
  495.  
  496. ftoa:     ; fpu st0 -> [integer],[decimal]
  497.  
  498.     pusha
  499.  
  500.     fst    [tmp2]
  501.  
  502.     fstcw  [controlWord]      ; set truncate integer mode
  503.     mov    ax,[controlWord]
  504.     mov    [tmp], ax
  505.     or     [tmp], word 0x0C00
  506.     fldcw  [tmp]
  507.  
  508.     ftst                      ; test if st0 is negative
  509.     fstsw  ax
  510.     and    ax, 4500h
  511.     mov    [sign], 0
  512.     cmp    ax, 0100h
  513.     jne    no_neg
  514.     mov    [sign],1
  515.   no_neg:
  516.  
  517.     fld    [tmp2]
  518.     fistp  [integer]
  519.  
  520.     fld    [tmp2]
  521.     fisub  [integer]
  522.  
  523.     fldcw  [controlWord]
  524.  
  525.     cmp  byte [sign], 0     ; change fraction to positive
  526.     je   no_neg2
  527.     fchs
  528.   no_neg2:
  529.  
  530.     mov    [res],0          ; convert 6 decimal numbers
  531.     mov    edi,6
  532.  
  533.    newd:
  534.  
  535.     fimul  [kymppi]
  536.     fist   [decimal]
  537.  
  538.     mov    ebx,[res]
  539.     imul   ebx,10
  540.     mov    [res],ebx
  541.  
  542.     mov    eax,[decimal]
  543.     add    [res],eax
  544.  
  545.     fisub  [decimal]
  546.  
  547.     fst    [tmp2]
  548.  
  549.     ftst
  550.     fstsw  ax
  551.     test   ax,1
  552.     jnz    real_done
  553.  
  554.     fld    [tmp2]
  555.  
  556.     dec    edi
  557.     jz     real_done
  558.  
  559.     jmp    newd
  560.  
  561.   real_done:
  562.  
  563.     mov    eax,[res]
  564.     mov    [decimal],eax
  565.  
  566.     cmp    [integer],0x80000000      ; out of fpu limits
  567.     jne    no_error
  568.     mov    [integer],0
  569.     mov    [decimal],0
  570.     call   clear_all
  571.     mov    [calc],'E'
  572.   no_error:
  573.  
  574.     mov    [dsign],byte '+'
  575.     cmp    [sign],byte 0             ; convert negative result
  576.     je     no_negative
  577.     mov    eax,[integer]
  578.     not    eax
  579.     inc    eax
  580.     mov    [integer],eax
  581.     mov    [dsign],byte '-'
  582.   no_negative:
  583.  
  584.     call   to_muuta
  585.  
  586.     popa
  587.     ret
  588.  
  589.  
  590.  
  591. atof:
  592.  
  593.     push ax
  594.     push di
  595.  
  596.     fldz
  597.     mov di, 0
  598.     cmp si, 0
  599.     je .error           ; Jump if string has 0 length.
  600.  
  601.     mov byte [sign], 0
  602.  
  603.     cmp byte [bx], '+'   ; Take care of leading '+' or '-'.
  604.     jne .noPlus
  605.     inc di
  606.     jmp .noMinus
  607.   .noPlus:
  608.  
  609.     cmp byte [bx], '-'
  610.     jne .noMinus
  611.     mov byte [sign], 1       ; Number is negative.
  612.     inc di
  613.   .noMinus:
  614.  
  615.     cmp si, di
  616.     je .error
  617.  
  618.     call atof_convertWholePart
  619.     jc .error
  620.  
  621.     call atof_convertFractionalPart
  622.     jc .error
  623.  
  624.     cmp byte [sign], 0
  625.     je  .dontNegate
  626.     fchs           ; Negate value
  627.   .dontNegate:
  628.  
  629.     mov bh, 0      ; Set bh to indicate the string is a valid number.
  630.     jmp .exit
  631.  
  632.   .error:
  633.     mov bh, 1      ; Set error code.
  634.     fstp st0       ; Pop top of fpu stack.
  635.  
  636.   .exit:
  637.     pop di
  638.     pop ax
  639.  
  640.     ret
  641.  
  642.  
  643.  
  644. atof_convertWholePart:
  645.  
  646.     ; Convert the whole number part (the part preceding the decimal
  647.     ; point) by reading a digit at a time, multiplying the current
  648.     ; value by 10, and adding the digit.
  649.  
  650. .mainLoop:
  651.  
  652.     mov al, [bx + di]
  653.     cmp al, '.'
  654.     je .exit
  655.  
  656.     cmp al, '0'    ; Make sure character is a digit.
  657.     jb .error
  658.     cmp al, '9'
  659.     ja .error
  660.  
  661.     ; Convert single character to digit and save to memory for
  662.     ; transfer to the FPU.
  663.  
  664.     sub al, '0'
  665.     mov ah, 0
  666.     mov [tmp], ax
  667.  
  668.     ; Multiply current value by 10 and add in digit.
  669.  
  670.     fmul dword [ten]
  671.     fiadd word [tmp]
  672.  
  673.     inc di
  674.     cmp si, di     ; Jump if end of string has been reached.
  675.     je .exit
  676.     jmp .mainLoop
  677.  
  678.   .error:
  679.     stc            ; Set error (carry) flag.
  680.     ret
  681.  
  682.   .exit:
  683.     clc            ; Clear error (carry) flag.
  684.     ret
  685.  
  686.  
  687. atof_convertFractionalPart:
  688.  
  689.     fld1      ; Load 1 to TOS.  This will be the value of the decimal place.
  690.  
  691.   .mainLoop:
  692.  
  693.     cmp si, di     ; Jump if end of string has been reached.
  694.     je .exit
  695.  
  696.     inc di         ; Move past the decimal point.
  697.     cmp si, di     ; Jump if end of string has been reached.
  698.     je .exit
  699.     mov al, [bx + di]
  700.  
  701.     cmp al, '0'    ; Make sure character is a digit.
  702.     jb .error
  703.     cmp al, '9'
  704.     ja .error
  705.  
  706.     fdiv dword [ten]     ; Next decimal place
  707.  
  708.     sub al, '0'
  709.     mov ah, 0
  710.     mov [tmp], ax
  711.  
  712.     ; Load digit, multiply by value for appropriate decimal place,
  713.     ; and add to current total.
  714.  
  715.     fild  word [tmp]
  716.     fmul  st0, st1
  717.     faddp st2, st0
  718.  
  719.     jmp .mainLoop
  720.  
  721.   .error:
  722.  
  723.     stc            ; Set error (carry) flag.
  724.     fstp st0       ; Pop top of fpu stack.
  725.     ret
  726.  
  727.   .exit:
  728.  
  729.     clc            ; Clear error (carry) flag.
  730.     fstp st0       ; Pop top of fpu stack.
  731.     ret
  732.  
  733.  
  734.  
  735.  
  736. ;   *********************************************
  737. ;   *******  WINDOW DEFINITIONS AND DRAW ********
  738. ;   *********************************************
  739.  
  740.  
  741. draw_window:
  742.  
  743.  
  744.     mov  eax,12                    ; function 12:tell os about windowdraw
  745.     mov  ebx,1                     ; 1, start of draw
  746.     int  0x40
  747.  
  748.                                    ; DRAW WINDOW
  749.     mov  eax,0                     ; function 0 : define and draw window
  750.     mov  ebx,100*65536+230         ; [x start] *65536 + [x size]
  751.     mov  ecx,100*65536+185         ; [y start] *65536 + [y size]
  752.     mov  edx,0x02ffffff            ; color of work area RRGGBB,8->color gl
  753.     mov  esi,0x805977bb            ; color of grab bar  RRGGBB,8->color gl
  754.     mov  edi,0x005977bb            ; color of frames    RRGGBB
  755.     int  0x40
  756.                                    ; CLOSE BUTTON
  757.     mov  eax,8                     ; function 8 : define and draw button
  758.     mov  ebx,(230-18)*65536+12     ; [x start] *65536 + [x size]
  759.     mov  ecx,4*65536+12            ; [y start] *65536 + [y size]
  760.     mov  edx,1                     ; button id
  761.     mov  esi,0x335599              ; button color RRGGBB
  762.     int  0x40
  763.  
  764.                                    ; WINDOW LABEL
  765.     mov  eax,4                     ; function 4 : write text to window
  766.     mov  ebx,8*65536+8             ; [x start] *65536 + [y start]
  767.     mov  ecx,0x00ddeeff            ; color of text RRGGBB
  768.     mov  edx,labelt                ; pointer to text beginning
  769.     mov  esi,labellen-labelt       ; text length
  770.     int  0x40
  771.  
  772.     mov  ebx,24*65536+25+3
  773.     mov  ecx,70*65536+17
  774.     mov  edx,6
  775.     mov  esi,0x303090;cc2211
  776.     mov  edi,7
  777.   newbutton:
  778.     dec  edi
  779.     jnz  no_new_row
  780.     mov  edi,6
  781.     mov  ebx,24*65536+25+3
  782.     add  ecx,20*65536
  783.   no_new_row:
  784.     mov  eax,8
  785.     int  0x40
  786.     add  ebx,30*65536
  787.     inc  edx
  788.     cmp  edx,11+24
  789.     jbe  newbutton
  790.  
  791.     mov  eax,8                     ; CLEAR ALL
  792.     mov  ebx,25*65536+27
  793.     mov  ecx,41*65536+15
  794.     mov  edx,2
  795.     int  0x40
  796.  
  797.     mov  eax,8                     ; CHANGE DISPLAY TYPE
  798.     mov  ebx,203*65536+7
  799.     mov  ecx,28*65536+7
  800.     mov  edx,3
  801.     int  0x40
  802.  
  803.     mov  ebx,25*65536+35           ; draw info text with function 4
  804.     mov  ecx,0xffffff ; 224466
  805.     mov  edx,text
  806.     mov  esi,30
  807.   newline:
  808.     mov  eax,4
  809.     int  0x40
  810.     add  ebx,10
  811.     add  edx,30
  812.     cmp  [edx],byte 'x'
  813.     jne  newline
  814.  
  815.     call print_display
  816.  
  817.     mov  eax,12                    ; function 12:tell os about windowdraw
  818.     mov  ebx,2                     ; 2, end of draw
  819.     int  0x40
  820.  
  821.     ret
  822.  
  823.  
  824.  
  825. print_display:
  826.  
  827.     pusha
  828.  
  829.     mov  eax,13
  830.     mov  ebx,59*65536+143
  831.     mov  ecx,24*65536+44
  832.     mov  edx,0xffffff
  833.     int  0x40
  834.  
  835.     mov  eax,4
  836.     mov  ebx,120*65536+28
  837.     mov  ecx,0
  838.     mov  edx,calc
  839.     mov  esi,1
  840.     int  0x40
  841.  
  842.     mov  eax,4
  843.     mov  ebx,175*65536+28
  844.     mov  ecx,0
  845.     mov  edx,[display_type]
  846.     shl  edx,2
  847.     add  edx,display_type_text
  848.     mov  esi,3
  849.     int  0x40
  850.  
  851.     cmp  [display_type],0   ; display as desimal
  852.     jne  no_display_decimal
  853.  
  854.     mov  eax,47
  855.     mov  ebx,11*65536   ; 11 decimal digits for 32 bits
  856.     mov  ecx,[integer]
  857.     mov  edx,84*65536+44
  858.     mov  esi,0x0
  859.     int  0x40
  860.  
  861.     mov  eax,47
  862.     mov  ebx,6*65536
  863.     mov  ecx,[decimal]
  864.     mov  edx,156*65536+44
  865.     mov  esi,0x0
  866.     int  0x40
  867.  
  868.     mov  eax,4
  869.     mov  ebx,150*65536+44
  870.     mov  ecx,0x0
  871.     mov  edx,dot
  872.     mov  esi,1
  873.     int  0x40
  874.  
  875.     mov  eax,4
  876.     mov  ebx,77*65536+44
  877.     mov  ecx,0x0
  878.     mov  edx,dsign
  879.     mov  esi,1
  880.     int  0x40
  881.  
  882.   no_display_decimal:
  883.  
  884.     cmp  [display_type],1
  885.     jne  no_display_hexadecimal
  886.  
  887.     mov  eax,4
  888.     mov  ebx,138*65536+44
  889.     mov  ecx,0x0
  890.     mov  edx,dsign
  891.     mov  esi,1
  892.     int  0x40
  893.  
  894.     mov  eax,47
  895.     mov  ebx,1*256+8*65536   ; 8 hexadecimal digits for 32 bits
  896.     mov  ecx,[integer]
  897.     mov  edx,144*65536+44
  898.     mov  esi,0x0
  899.     int  0x40
  900.  
  901.   no_display_hexadecimal:
  902.  
  903.  
  904.     cmp  [display_type],2
  905.     jne  no_display_binary
  906.  
  907.     mov  eax,4
  908.     mov  ebx,96*65536+44
  909.     mov  ecx,0x0
  910.     mov  edx,dsign
  911.     mov  esi,1
  912.     int  0x40
  913.  
  914.     mov  eax,47
  915.     mov  ebx,2*256+15*65536   ; 16 binary digits for 32 bits
  916.     mov  ecx,[integer]
  917.     mov  edx,102*65536+44
  918.     mov  esi,0x0
  919.     int  0x40
  920.  
  921.   no_display_binary:
  922.  
  923.     popa
  924.     ret
  925.  
  926.  
  927. clear_all:
  928.  
  929.     pusha
  930.  
  931.     mov  [calc],' '
  932.     mov  [integer],0
  933.     mov  [decimal],0
  934.     mov  [id],0
  935.     mov  [dsign],byte '+'
  936.     mov  esi,muuta0
  937.     mov  edi,muuta1
  938.     mov  ecx,18
  939.     cld
  940.     rep  movsb
  941.     mov  esi,muuta0
  942.     mov  edi,muuta2
  943.     mov  ecx,18
  944.     cld
  945.     rep  movsb
  946.     call print_muuta
  947.     call print_display
  948.  
  949.     popa
  950.     ret
  951.  
  952.  
  953.  
  954. ; DATA AREA
  955.  
  956. display_type       dd   0   ; 0 = decimal, 1 = hexadecimal, 2= binary
  957. entry_multiplier   dd  10
  958.  
  959. display_start_y    dd  0x0
  960. display_type_text  db 'dec hex bin'
  961.  
  962. dot     db  '.'
  963.  
  964. calc    db  ' '
  965.  
  966. integer dd    0
  967. decimal dd    0
  968.  
  969. kymppi  dd   10
  970.  
  971. dsign:
  972. muuta1  db   '+0000000000.000000'
  973. muuta2  db   '+0000000000.000000'
  974. muuta0  db   '+0000000000.000000'
  975.  
  976.  
  977. text:
  978.     db '                              '
  979.     db '  C                           '
  980.     db '                              '
  981.     db '                              '
  982.     db '  A    B    C    D    E    F  '
  983.     db '                              '
  984.     db '  1    2    3    +   SIN  INT '
  985.     db '                              '
  986.     db '  4    5    6    -   COS  LG2 '
  987.     db '                              '
  988.     db '  7    8    9    /   TAN   P  '
  989.     db '                              '
  990.     db ' -/+   0    .    *   SQR   =  '
  991.     db '                              '
  992.     db 'x <- END MARKER, DONT DELETE  '
  993. asci:  db 49,50,51,52,53,54,55,56,57,48,43,61,45,42,47,44,46,52,13,97,98,99,100
  994.        db 101,102,65,66,67,68,69,70,112,80,27,182
  995. butid: db 12,13,14,18,19,20,24,25,26,31,15,35,21,33,27,32,32,33,35,6,7,8,9,10,11
  996.        db 6,7,8,9,10,11,29,29,2,2
  997.  
  998. labelt:
  999.       db   'FPU CALCULATOR'
  1000. labellen:
  1001.  
  1002. I_END:
  1003.  
  1004.  
  1005.  
  1006.  
  1007.  
  1008.