Subversion Repositories Kolibri OS

Rev

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