Subversion Repositories Kolibri OS

Rev

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