Subversion Repositories Kolibri OS

Rev

Rev 967 | Rev 2745 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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