Subversion Repositories Kolibri OS

Rev

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

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