Subversion Repositories Kolibri OS

Rev

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

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