Subversion Repositories Kolibri OS

Rev

Rev 109 | Rev 175 | 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]
107 heavyiron 90
    cmp  eax,33
31 halyavin 91
    jne  no_sign
92
    cmp  [dsign],byte '-'
93
    jne  no_m
94
    mov  [dsign],byte '+'
95
    call print_display
96
    jmp  still
107 heavyiron 97
 
31 halyavin 98
  no_m:
99
    mov  [dsign],byte '-'
100
    call print_display
101
    jmp  still
107 heavyiron 102
 
31 halyavin 103
  no_sign:
104
    cmp  eax,3
105
    jne  no_display_change
106
    inc  [display_type]
107
    cmp  [display_type],2
108
    jbe  display_continue
109
    mov  [display_type],0
107 heavyiron 110
 
31 halyavin 111
  display_continue:
112
    mov  eax,[display_type]
113
    mov  eax,[multipl+eax*4]
114
    mov  [entry_multiplier],eax
115
    call print_display
116
    jmp  still
153 heavyiron 117
  multipl:  dd 10,16,2
31 halyavin 118
 
119
  no_display_change:
120
    cmp  eax,6
153 heavyiron 121
    jb   no_a_f
31 halyavin 122
    cmp  eax,11
153 heavyiron 123
    jg   no_a_f
31 halyavin 124
    add  eax,4
125
    call number_entry
126
    jmp  still
107 heavyiron 127
 
128
   no_a_f:
31 halyavin 129
    cmp  eax,12
153 heavyiron 130
    jb   no_13
31 halyavin 131
    cmp  eax,14
153 heavyiron 132
    jg   no_13
31 halyavin 133
    sub  eax,11
134
    call number_entry
135
    jmp  still
107 heavyiron 136
 
31 halyavin 137
   no_13:
107 heavyiron 138
    cmp  eax,19
153 heavyiron 139
    jb   no_46
107 heavyiron 140
    cmp  eax,21
153 heavyiron 141
    jg   no_46
107 heavyiron 142
    sub  eax,15
31 halyavin 143
    call number_entry
144
    jmp  still
107 heavyiron 145
 
31 halyavin 146
   no_46:
107 heavyiron 147
    cmp  eax,26
153 heavyiron 148
    jb   no_79
107 heavyiron 149
    cmp  eax,28
153 heavyiron 150
    jg   no_79
107 heavyiron 151
    sub  eax,19
31 halyavin 152
    call number_entry
153
    jmp  still
107 heavyiron 154
 
31 halyavin 155
   no_79:
107 heavyiron 156
    cmp  eax,34
31 halyavin 157
    jne  no_0
153 heavyiron 158
    xor  eax,eax
31 halyavin 159
    call number_entry
160
    jmp  still
107 heavyiron 161
 
162
   no_0:
163
    cmp  eax,35
31 halyavin 164
    jne  no_id
165
    inc  [id]
166
    and  [id],1
167
    mov  [new_dec],100000
168
    jmp  still
107 heavyiron 169
 
31 halyavin 170
  no_id:
107 heavyiron 171
    cmp  eax,17
31 halyavin 172
    jne  no_sin
173
    fld  [trans1]
174
    fsin
175
    jmp  show_result
107 heavyiron 176
 
31 halyavin 177
  no_sin:
107 heavyiron 178
    cmp  eax,18
179
    jne  no_asin
180
    fld  [trans1]
181
    fld  st0
182
    fmul st,st1
183
    fld1
184
    fsubrp  st1,st0
185
    fsqrt
186
    fpatan
187
    jmp  show_result
188
 
189
  no_asin:
190
    cmp  eax,16
31 halyavin 191
    jne  no_int
192
    fld  [trans1]
193
    frndint
194
    jmp  show_result
107 heavyiron 195
 
31 halyavin 196
  no_int:
107 heavyiron 197
    cmp  eax,23
198
    jne  no_1x
199
    fld  [trans1]
200
    fld1
201
    fdiv st,st1
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]
107 heavyiron 350
    test ebx,0xc0000000
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:
473
    fistp  [integer]
474
    fld    [tmp2]
475
    fisub  [integer]
476
    fldcw  [controlWord]
153 heavyiron 477
    cmp    byte [sign], 0     ; change fraction to positive
478
    je     no_neg2
31 halyavin 479
    fchs
107 heavyiron 480
 
31 halyavin 481
  no_neg2:
153 heavyiron 482
    mov    [res],0     ; convert 6 decimal numbers
31 halyavin 483
    mov    edi,6
484
 
485
   newd:
486
    fimul  [kymppi]
487
    fist   [decimal]
488
    mov    ebx,[res]
489
    imul   ebx,10
490
    mov    [res],ebx
491
    mov    eax,[decimal]
492
    add    [res],eax
493
    fisub  [decimal]
494
    ftst
495
    fstsw  ax
107 heavyiron 496
 
31 halyavin 497
    dec    edi
153 heavyiron 498
    jz     real_done
31 halyavin 499
    jmp    newd
500
 
501
  real_done:
502
    mov    eax,[res]
503
    mov    [decimal],eax
107 heavyiron 504
    cmp    [integer],0x80000000
31 halyavin 505
    jne    no_error
506
    call   clear_all
507
    mov    [calc],'E'
107 heavyiron 508
 
31 halyavin 509
  no_error:
510
    mov    [dsign],byte '+'
153 heavyiron 511
    cmp    [sign],byte 0      ; convert negative result
512
    je     no_negative
31 halyavin 513
    mov    eax,[integer]
514
    not    eax
515
    inc    eax
516
    mov    [integer],eax
517
    mov    [dsign],byte '-'
107 heavyiron 518
 
31 halyavin 519
  no_negative:
520
    call   to_muuta
521
    popa
522
    ret
523
 
524
 
525
atof:
526
    push ax
527
    push di
528
    fldz
529
    mov di, 0
530
    cmp si, 0
153 heavyiron 531
    je .error            ; Jump if string has 0 length.
31 halyavin 532
    mov byte [sign], 0
153 heavyiron 533
    cmp byte [bx], '+'   ; Take care of leading '+' or '-'.
31 halyavin 534
    jne .noPlus
535
    inc di
536
    jmp .noMinus
107 heavyiron 537
 
31 halyavin 538
  .noPlus:
539
    cmp byte [bx], '-'
540
    jne .noMinus
153 heavyiron 541
    mov byte [sign], 1   ; Number is negative.
31 halyavin 542
    inc di
107 heavyiron 543
 
31 halyavin 544
  .noMinus:
545
    cmp si, di
546
    je .error
547
    call atof_convertWholePart
548
    jc .error
549
    call atof_convertFractionalPart
550
    jc .error
551
    cmp byte [sign], 0
153 heavyiron 552
    je .dontNegate
553
    fchs    ; Negate value
107 heavyiron 554
 
31 halyavin 555
  .dontNegate:
153 heavyiron 556
    mov bh, 0    ; Set bh to indicate the string is a valid number.
31 halyavin 557
    jmp .exit
558
 
559
  .error:
153 heavyiron 560
    mov bh, 1    ; Set error code.
561
    fstp st0    ; Pop top of fpu stack.
31 halyavin 562
 
563
  .exit:
564
    pop di
565
    pop ax
566
    ret
567
 
568
atof_convertWholePart:
569
 
570
    ; Convert the whole number part (the part preceding the decimal
571
    ; point) by reading a digit at a time, multiplying the current
572
    ; value by 10, and adding the digit.
573
 
574
.mainLoop:
575
    mov al, [bx + di]
576
    cmp al, '.'
577
    je .exit
153 heavyiron 578
    cmp al, '0'       ; Make sure character is a digit.
31 halyavin 579
    jb .error
580
    cmp al, '9'
581
    ja .error
582
 
583
    ; Convert single character to digit and save to memory for
584
    ; transfer to the FPU.
585
 
586
    sub al, '0'
587
    mov ah, 0
588
    mov [tmp], ax
589
 
590
    ; Multiply current value by 10 and add in digit.
591
 
592
    fmul dword [ten]
593
    fiadd word [tmp]
594
    inc di
153 heavyiron 595
    cmp si, di         ; Jump if end of string has been reached.
31 halyavin 596
    je .exit
597
    jmp .mainLoop
598
 
599
  .error:
153 heavyiron 600
    stc                ; Set error (carry) flag.
31 halyavin 601
    ret
602
 
603
  .exit:
153 heavyiron 604
    clc                ; Clear error (carry) flag.
31 halyavin 605
    ret
606
 
607
 
608
atof_convertFractionalPart:
153 heavyiron 609
    fld1               ; Load 1 to TOS.  This will be the value of the decimal place.
31 halyavin 610
 
611
  .mainLoop:
153 heavyiron 612
    cmp si, di         ; Jump if end of string has been reached.
31 halyavin 613
    je .exit
153 heavyiron 614
    inc di             ; Move past the decimal point.
615
    cmp si, di         ; Jump if end of string has been reached.
31 halyavin 616
    je .exit
617
    mov al, [bx + di]
153 heavyiron 618
    cmp al, '0'        ; Make sure character is a digit.
31 halyavin 619
    jb .error
620
    cmp al, '9'
621
    ja .error
153 heavyiron 622
    fdiv dword [ten]   ; Next decimal place
31 halyavin 623
    sub al, '0'
624
    mov ah, 0
625
    mov [tmp], ax
626
 
627
    ; Load digit, multiply by value for appropriate decimal place,
628
    ; and add to current total.
629
 
630
    fild  word [tmp]
631
    fmul  st0, st1
632
    faddp st2, st0
633
    jmp .mainLoop
634
 
635
  .error:
153 heavyiron 636
    stc           ; Set error (carry) flag.
637
    fstp st0    ; Pop top of fpu stack.
31 halyavin 638
    ret
639
 
640
  .exit:
153 heavyiron 641
    clc              ; Clear error (carry) flag.
642
    fstp st0    ; Pop top of fpu stack.
31 halyavin 643
    ret
644
 
645
;   *********************************************
153 heavyiron 646
;   ******* WINDOW DEFINITIONS AND DRAW *********
31 halyavin 647
;   *********************************************
648
 
649
draw_window:
153 heavyiron 650
 
651
    mov  eax,48
652
    mov  ebx,3
653
    mov  ecx,sc
654
    mov  edx,sizeof.system_colors
655
    int  0x40
31 halyavin 656
 
153 heavyiron 657
    mov  eax,12
658
    mov  ebx,1
659
    int  0x40
660
 
661
    mov  eax,0
662
    mov  ebx,200*65536+255
663
    mov  ecx,200*65536+180
664
    mov  edx,[sc.work]
665
    or   edx,0x33000000
666
    mov  edi,header
667
    int  0x40
31 halyavin 668
 
153 heavyiron 669
    mov  eax,8
670
    mov  ebx,19*65536+28
671
    mov  ecx,49*65536+18
31 halyavin 672
    mov  edx,6
153 heavyiron 673
    mov  esi,[sc.work_button]
31 halyavin 674
    mov  edi,7
675
  newbutton:
676
    dec  edi
677
    jnz  no_new_row
107 heavyiron 678
    mov  edi,7
153 heavyiron 679
    mov  ebx,19*65536+28
31 halyavin 680
    add  ecx,20*65536
681
  no_new_row:
153 heavyiron 682
    int  0x40
31 halyavin 683
    add  ebx,30*65536
684
    inc  edx
107 heavyiron 685
    cmp  edx,39
31 halyavin 686
    jbe  newbutton
153 heavyiron 687
 
688
    mcall  ,199*65536+28,49*65536+18,2                  ; 'C'
689
    mcall  ,220*65536+8,7*65536+8,3                     ; 'dec-bin-hex'
690
 
691
    mov  eax,4
692
    mov  ebx,27*65536+54
693
    mov  ecx,[sc.work_button_text]
31 halyavin 694
    mov  edx,text
153 heavyiron 695
    mov  esi,33
31 halyavin 696
  newline:
153 heavyiron 697
    int  0x40
107 heavyiron 698
    add  ebx,20
153 heavyiron 699
    add  edx,33
31 halyavin 700
    cmp  [edx],byte 'x'
701
    jne  newline
153 heavyiron 702
 
31 halyavin 703
    call print_display
153 heavyiron 704
 
705
    mov  eax,12
706
    mov  ebx,2
707
    int  0x40
708
 
31 halyavin 709
    ret
710
 
711
print_display:
712
    pusha
153 heavyiron 713
    mcall 13,18*65536+210,19*65536+13,0xffffff
714
 
31 halyavin 715
    mov  eax,4
153 heavyiron 716
    mov  ebx,135*65536+7
717
    mov  ecx,[sc.work_text]
718
    or   ecx,0x40000000
719
    mov  edx,calc
720
    mov  esi,1
721
    mov  edi,[sc.work]
722
    int  0x40
723
 
724
    mov  ebx,198*65536+8
31 halyavin 725
    mov  edx,[display_type]
726
    shl  edx,2
727
    add  edx,display_type_text
728
    mov  esi,3
153 heavyiron 729
    mov  edi,[sc.work]
31 halyavin 730
    int  0x40
153 heavyiron 731
 
107 heavyiron 732
    cmp  [dsign],byte '+'
153 heavyiron 733
    je   positive
734
    mov  ebx,23*65536+22
735
    mov  ecx,0x0
736
    mov  edx,dsign
737
    mov  esi,1
738
    int  0x40
739
 
740
positive:
741
    cmp  [display_type],0
31 halyavin 742
    jne  no_display_decimal
107 heavyiron 743
    cmp  [decimal],0
744
    je   whole
153 heavyiron 745
 
746
    mov  ebx,180*65536+22
747
    mov  ecx,0x0
748
    mov  edx,dot
749
    mov  esi,1
750
    int  0x40
751
 
752
    mov  eax,47
753
    mov  ebx,10*65536
754
    mov  ecx,[integer]
755
    mov  edx,120*65536+22
756
    mov  esi,0x0
757
    int  0x40
758
 
759
    mov  ebx,6*65536
760
    mov  ecx,[decimal]
761
    mov  edx,187*65536+22
762
    mov  esi,0x0
763
    int  0x40
764
 
107 heavyiron 765
    popa
766
    ret
767
 
768
whole:
153 heavyiron 769
    mov  ebx,220*65536+22
770
    mov  ecx,0x0
771
    mov  edx,dot
772
    mov  esi,1
773
    int  0x40
774
 
107 heavyiron 775
    cmp  [integer],0
776
    je  null
153 heavyiron 777
 
778
    mov  eax,47
779
    mov  ebx,10*65536
780
    mov  ecx,[integer]
781
    mov  edx,160*65536+22
782
    mov  esi,0x0
783
    int  0x40
784
 
107 heavyiron 785
    popa
786
    ret
153 heavyiron 787
 
31 halyavin 788
  no_display_decimal:
153 heavyiron 789
    cmp  [display_type],1
790
    jne  no_display_hexadecimal
107 heavyiron 791
    cmp  [integer],0
792
    je  null
153 heavyiron 793
 
794
    mov  eax,47
795
    mov  ebx,256+8*65536
796
    mov  ecx,[integer]
797
    mov  edx,173*65536+22
798
    mov  esi,0x0
799
    int  0x40
800
 
107 heavyiron 801
    popa
802
    ret
803
 
31 halyavin 804
  no_display_hexadecimal:
107 heavyiron 805
    cmp  [integer],0
806
    je  null
153 heavyiron 807
 
808
    mov  eax,47
809
    mov  ebx,2*256+32*65536
810
    mov  ecx,[integer]
811
    mov  edx,32*65536+22
812
    mov  esi,0x0
813
    int  0x40
814
 
31 halyavin 815
    popa
816
    ret
107 heavyiron 817
 
818
  null:
153 heavyiron 819
    mov  eax,47
820
    mov  ebx,1*65536
821
    mov  ecx,0
822
    mov  edx,214*65536+22
823
    mov  esi,0x0
824
    int  0x40
825
 
107 heavyiron 826
    popa
827
    ret
31 halyavin 828
 
829
clear_all:
830
    pusha
831
    mov  [calc],' '
832
    mov  [integer],0
833
    mov  [decimal],0
834
    mov  [id],0
835
    mov  [dsign],byte '+'
836
    mov  esi,muuta0
837
    mov  edi,muuta1
838
    mov  ecx,18
839
    cld
840
    rep  movsb
841
    mov  esi,muuta0
842
    mov  edi,muuta2
843
    mov  ecx,18
844
    cld
845
    rep  movsb
846
    call print_display
847
    popa
848
    ret
849
 
850
 
153 heavyiron 851
;data
31 halyavin 852
 
153 heavyiron 853
header db appname,version,0
854
 
107 heavyiron 855
display_type       dd  0    ; 0 = decimal, 1 = hexadecimal, 2= binary
31 halyavin 856
entry_multiplier   dd  10
107 heavyiron 857
display_type_text  db  'dec hex bin'
31 halyavin 858
 
153 heavyiron 859
dot     db  '.'
860
calc    db  ' '
31 halyavin 861
integer dd    0
862
decimal dd    0
863
kymppi  dd   10
864
 
865
dsign:
153 heavyiron 866
muuta1  db   '+0000000000.000000'
867
muuta2  db   '+0000000000.000000'
868
muuta0  db   '+0000000000.000000'
31 halyavin 869
 
870
text:
153 heavyiron 871
    db ' A    B    C    D    E    F    C '
872
    db ' 1    2    3    +   Int  Sin Asin'
873
    db ' 4    5    6    -   1/x  Cos Acos'
874
    db ' 7    8    9    /   x^2  Tan Atan'
875
    db '+/-   0    .    *   Sqr  Pi    = '
107 heavyiron 876
    db 'x'
31 halyavin 877
 
107 heavyiron 878
asci:  db 49,50,51,52,53,54,55,56,57,48,43,61,45,42,47,44,46,27
879
butid: db 12,13,14,19,20,21,26,27,28,34,15,39,22,36,29,35,35,1
153 heavyiron 880
 
881
I_END:
882
 
883
sc     system_colors