Subversion Repositories Kolibri OS

Rev

Rev 195 | Rev 382 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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