Subversion Repositories Kolibri OS

Rev

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

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