-
Notifications
You must be signed in to change notification settings - Fork 2
/
x87.bas
1117 lines (1067 loc) · 45.7 KB
/
x87.bas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
Static shared As ULong x87_pc_off
static shared As ULong x87_op_off
static shared As UShort x87_pc_seg
static shared As UShort x87_op_seg
Declare Sub x87_d8()
Declare Sub x87_d9()
Declare Sub x87_da()
Declare Sub x87_db()
Declare Sub x87_dc()
Declare Sub x87_dd()
Declare Sub x87_de()
Declare Sub x87_df()
static shared As Double STD(0 To 7)
static shared As UShort npxs,npxc,tag
static shared As integer TOP
#Define ST(x) (STD((TOP+(x)) And 7))
Const C0 =(1 Shl 8)
Const C1 =(1 Shl 9)
Const C2 =(1 Shl 10)
Const C3 =(1 Shl 14)
Const BIAS80 =16383
Const BIAS64 =1023
'rutinas en 386A.C necesarias aqui
Declare Sub seteab(v As Ubyte)
Declare Sub seteaw(v As UShort)
Declare Sub seteal(v As ULong)
Declare Function geteab() As UByte
Declare Function geteaw() As UShort
Declare Function geteal() As uLong
' esta rutina requiere la matematica MATH.BI para las dos funciones FLOOR y CEIL (y POW al parecer)
' FLOOR
' devuelve el entero anterior al valor indicado
' ejemplos: 2.5=2, -2.3=-3
'
' CEIL:
' devuelve el entero posterior al valor indicado
' ejemplos: 2.5=3, -2.3=-2
#Include "crt\math.bi"
Function x87_fround(b As Double ) As LongInt
Select Case As Const ((npxc Shr 10) And 3)
Case 0 'Nearest
' este falla en BASIC, lo redondea para arriba, y deberia ser para abajo
' por eso, como truco, lo hago entero (FIX) y asi, redondea para abajo
' sin est truco, falla mi "D.EXE"
return CLngInt(Fix(b)+0.5)
Case 1 'Down
Return CLngInt(floor(b)) 'floor=double
Case 2 'Up
Return CLngInt(ceil(b)) ' ceil=double
Case 3 'Chop
' este falla en el WOLFSTEIN3D si NO es INT!!!!
' pero a su vez, falla el TEST387 si ES INT!!!! Que hago?
' parece que FIX soluciona el tema!!
return clngint(fix(b))
End Select
End Function
' no funciona bien, la anulo por ahora.
const STATUS_ZERODIVIDE=4
Function x87_div(ByRef dst As double, src1 As double, src2 As Double) As Integer
'Do
'If src2 = 0.0 Then
' npxs = npxs Or STATUS_ZERODIVIDE
'if npxc and STATUS_ZERODIVIDE Then
' dst = src1 / src2
'else
' picint(1 Shl 13)
'End if
' Return 1 ' si sale con "1", en la rutina que lo ha llamado se hace un RETURN (salida de sub)
'Else
' no funciona bien esta zona, por eso, dejo solo la parte divisora "normal"
' se nota que falla en el test 287demo, en el CAD SHUTTLE, zona del motor.
dst = src1 / src2
'End If
'Loop while 0
Return 0
End Function
Sub x87_push(i As double )
TOP=(TOP-1) And 7
STD(TOP)=i
tag = tag And inv(3 Shl ((TOP And 7) Shl 1))
if (i=0.0) Then tag = tag Or (1 Shl ((TOP And 7) Shl 1))
End Sub
Function x87_pop() As Double
Dim As Double t=STD(TOP)
tag = tag Or (3 Shl ((TOP And 7) Shl 1))
TOP=(TOP+1) And 7
return t
End Function
Function x87_ld80() As Double
Type test0
As Short begin
Union
As Double eind_d
As ULongInt eind_ll
End Union
End Type
Dim test As test0
test.eind_ll = readmeml_386(easeg,eaaddr)
test.eind_ll = test.eind_ll Or (CULngInt(readmeml_386(easeg,eaaddr+4)) Shl 32)
test.begin = readmemw_386(easeg,eaaddr+8)
Dim As LongInt exp64 = (((test.begin And &h7fff) - BIAS80))
Dim As LongInt blah = IIf((exp64>0),exp64,-exp64) And &h3ff
Dim As LongInt exp64final = iif((exp64>0),blah,-blah) +BIAS64
Dim As LongInt mant64 = (test.eind_ll Shr 11) And &hfffffffffffff
Dim As LongInt sign = IIf((test.begin And &h8000),1,0)
If (test.begin And &h7fff) = &h7fff Then exp64final = &h7ff ' nuevo en la 9.1
If (test.begin And &h7fff) = 0 Then exp64final = 0 ' nuevo en la 9.1
If test.eind_ll And &h400 Then mant64+=1
test.eind_ll = (sign Shl 63) Or (exp64final Shl 52) Or mant64
return test.eind_d
End Function
Sub x87_st80(d As Double )
Type test0
As Short begin
Union
As Double eind_d
As ULongInt eind_ll
End Union
End Type
Dim test As test0
test.eind_d=d
Dim As LongInt sign80 = IIf((test.eind_ll And &h8000000000000000),1,0)
Dim As LongInt exp80 = test.eind_ll And &h7ff0000000000000
Dim As LongInt exp80final = (exp80 Shr 52)
Dim As LongInt mant80 = test.eind_ll And &h000fffffffffffff
Dim As LongInt mant80final = (mant80 Shl 11)
if exp80final = &h7ff Then ' Infinity/Nan
exp80final = &h7fff
mant80final Or= &h8000000000000000
ElseIf d <> 0 Then
' Elvira wants the 8 and tcalc doesnt
mant80final = mant80final Or &h8000000000000000
' Ca-cyber doesnt like this when result is zero.
exp80final += (BIAS80 - BIAS64)
EndIf
test.begin = (CShort(sign80) Shl 15) Or CShort(exp80final)
test.eind_ll = mant80final
writememl_386(easeg,eaaddr,test.eind_ll And &Hffffffff)
writememl_386(easeg,eaaddr+4,test.eind_ll Shr 32)
writememw_386(easeg,eaaddr+8,test.begin)
End Sub
Sub x87_d8()
Union ts0
As single s
As ULong i
End Union
Dim ts As ts0
'Print #5,"D8:";modo,reg,Hex(rmdat32 And &hFF,2)
if (modo=3) Then
Select Case As Const (rmdat32 And &hFF)
Case &hC0, &hC1, &hC2, &hC3 ,&hC4, &hC5, &hC6, &hC7 'FADD
ST(0)=ST(0)+ST(rmdat32 And 7)
cycles-=8
return
case &hC8, &hC9, &hCA, &hCB ,&hCC, &hCD, &hCE, &hCF 'FMUL
ST(0)=ST(0)*ST(rmdat32 And 7)
cycles-=16
return
case &hD0, &hD1, &hD2, &hD3 ,&hD4, &hD5, &hD6, &hD7 'FCOM
npxs = npxs And inv(C0 Or C2 Or C3)
if ST(0)=ST(rmdat32 And 7) Then
npxs = npxs Or C3
elseif ST(0)<ST(rmdat32 And 7) Then
npxs = npxs Or C0
EndIf
cycles-=4
return
case &hD8, &hD9, &hDA, &hDB ,&hDC, &hDD, &hDE, &hDF 'FCOMP
npxs = npxs And inv(C0 Or C2 Or C3)
if ST(0)=ST(rmdat32 And 7) Then
npxs = npxs Or C3
elseif ST(0)<ST(rmdat32 And 7) Then
npxs = npxs Or C0
EndIf
x87_pop()
cycles-=4
return
case &hE0, &hE1, &hE2, &hE3 ,&hE4, &hE5, &hE6, &hE7 'FSUB
ST(0)=ST(0)-ST(rmdat32 And 7)
cycles-=8
return
case &hE8, &hE9, &hEA, &hEB ,&hEC, &hED, &hEE, &hEF 'FSUBR
ST(0)=ST(rmdat32 And 7)-ST(0)
cycles-=8
return
case &hF0, &hF1, &hF2, &hF3 ,&hF4, &hF5, &hF6, &hF7 'FDIV
'ST(0)=ST(0)/ST(rmdat32 And 7)
If x87_div(ST(0),ST(0),ST(rmdat32 And 7)) Then Return ' version 9
cycles-=73
return
case &hF8, &hF9, &hFA, &hFB ,&hFC, &hFD, &hFE, &hFF 'FDIVR
'ST(0)=ST(rmdat32 And 7)/ST(0)
If x87_div(ST(0),ST(rmdat32 And 7),ST(0)) Then Return ' version 9
cycles-=73
return
End Select
else
ts.i=geteal(): if abrt Then return
Select Case As Const (reg)
case 0 'FADD short
ST(0)+=ts.s
cycles-=8
return
case 1 'FMUL short
ST(0)*=ts.s
cycles-=11
return
case 2 'FCOM short
npxs = npxs And inv(C0 Or C2 Or C3)
if ST(0)=ts.s Then
npxs = npxs Or C3
ElseIf ST(0)<ts.s Then
npxs = npxs Or C0
EndIf
cycles-=4
return
case 3 'FCOMP short
npxs = npxs And inv(C0 Or C2 Or C3)
if ST(0)=ts.s Then
npxs = npxs Or C3
ElseIf ST(0)<ts.s Then
npxs = npxs Or C0
EndIf
cycles-=4
x87_pop()
return
case 4 'FSUB short
ST(0)-=ts.s
cycles-=8
return
case 5 'FSUBR short
ST(0)=ts.s-ST(0)
cycles-=8
return
case 6 'FDIV short
'ST(0)=ST(0)/ts.s
If x87_div(ST(0),ST(0),ts.s) Then Return ' version 9
cycles-=73
return
case 7 'FDIVR short
'ST(0)=ts.s/ST(0)
If x87_div(ST(0),ts.s,ST(0)) Then return ' version 9
cycles-=73
return
End Select
EndIf
x86illegal()
End Sub
Sub x87_d9()
Union ts0
As single s
As ULong i
End Union
Dim ts As ts0
'Print #5,"D9:";modo,reg,Hex(rmdat32 And &hFF,2)
Dim As Double td
Dim As LongInt temp64
Dim As UShort tempw
Dim As integer temp
if (modo=3) Then
Select Case As Const (rmdat32 And &hFF)
Case &hC0, &hC1, &hC2, &hC3 ,&hC4, &hC5, &hC6, &hC7 'FLD
x87_push(ST(rmdat32 And 7))
cycles-=4
return
case &hC8, &hC9, &hCA, &hCB ,&hCC, &hCD, &hCE, &hCF 'FXCH
td=ST(0)
ST(0)=ST(rmdat32 And 7)
ST(rmdat32 And 7)=td
cycles-=4
return
case &hD0 'FNOP
cycles-=3
return
case &hD8, &hD9, &hDA, &hDB, &hDC, &hDD, &hDE, &hDF 'Invalid, but apparently not illega
ST(rmdat32 And 7) = ST(0)
temp = (tag Shr ((TOP And 7) Shl 1)) And 3
tag = tag And inv(3 shl (((TOP + rmdat32) And 7) Shl 1))
tag = tag Or (temp Shl (((TOP + rmdat32) And 7) Shl 1))
x87_pop()
cycles-=3
Return
case &hE0 'FCHS
ST(0)=-ST(0)
cycles-=6
return
case &hE1 'FABS
ST(0)=fabs(ST(0))
cycles-=3
return
case &hE4 'FTST
npxs = npxs And inv(C0 Or C2 Or C3)
If ST(0)=0.0 Then
npxs = npxs Or C3
ElseIf ST(0)<0.0 Then
npxs = npxs Or C0
EndIf
cycles-=4
return
case &hE5 'FXAM
npxs = npxs And inv(C0 Or C2 Or C3)
if ((tag Shr ((TOP And 7) Shl 1)) And 3)=3 Then
npxs = npxs Or (C0 Or C3)
ElseIf ST(0)=0.0 Then
npxs = npxs Or C3
else
npxs = npxs Or C2
EndIf
if ST(0)<0.0 Then npxs = npxs Or C1
cycles-=8
return
case &hE8 'FLD1
x87_push(1.0)
cycles-=4
return
case &hE9 'FLDL2T
x87_push(3.3219280948873623)
cycles-=8
return
case &hEA 'FLDL2E
x87_push(1.4426950408889634)
cycles-=8
return
case &hEB 'FLDPI
x87_push(3.141592653589793)
cycles-=8
return
case &hEC 'FLDEG2
x87_push(0.3010299956639812)
cycles-=8
return
case &hED 'FLDLN2
x87_push(0.693147180559945)
cycles-=8
return
case &hEE 'FLDZ
x87_push(0.0)
tag = tag Or (1 Shl ((TOP And 7) Shl 1))
cycles-=4
return
case &hF0 'F2XM1
ST(0)=pow(2.0,ST(0))-1.0
cycles-=200
return
case &hF1 'FYL2X
ST(1)=ST(1)*(Log_(ST(0))/Log_(2.0))
x87_pop()
cycles-=250
return
case &hF2 'FPTAN
ST(0)=tan_(ST(0))
x87_push(1.0)
npxs = npxs And inv(C2)
cycles-=235
return
case &hF3 'FPATAN
ST(1)=atan2_(ST(1),ST(0))
x87_pop()
cycles-=250
return
case &hF6 'FDECSTP
TOP=(TOP-1) And 7
return
case &hF7 'FINCSTP
TOP=(TOP+1) And 7
return
case &hF8 'FPREM
temp64=CLngInt(ST(0)/ST(1))
ST(0)=ST(0) - ( ST(1)* CDbl(temp64) )
npxs = npxs And inv(C0 Or C1 Or C2 Or C3)
if (temp64 And 4) Then npxs = npxs Or C0
if (temp64 And 2) Then npxs = npxs Or C3
if (temp64 And 1) Then npxs = npxs Or C1
cycles-=100
return
case &hFA 'FSQRT
ST(0)=sqrt(ST(0))
cycles-=83
return
case &hFB 'FSINCOS
td=ST(0)
ST(0)=Sin_(td)
x87_push(cos_(td))
npxs = npxs And inv( C2 )
cycles-=330
return
case &hFC 'FRNDINT
ST(0)=CDbl( x87_fround(ST(0)) ) ' en la 8.1 es "double"
cycles-=21
return
case &hFD 'FSCALE
temp64=CLngInt(ST(1))
ST(0)=ST(0)*pow(2.0,CDbl(temp64))
cycles-=30
return
case &hFE 'FSIN
ST(0)=Sin_(ST(0))
npxs = npxs And inv( C2 )
cycles-=300
return
case &hFF 'FCOS
ST(0)=cos_(ST(0))
npxs = npxs And inv( C2 )
cycles-=300
return
End Select
else
Select Case As Const (reg)
Case 0 'FLD single-precision
ts.i=geteal(): if abrt Then return
x87_push(CDbl(ts.s))
cycles-=3
return
case 2 'FST single-precision
ts.s=CSng(ST(0))
seteal(ts.i)
cycles-=7
return
case 3 'FSTP single-precision
ts.s=CSng(ST(0))
seteal(ts.i): if abrt Then return
x87_pop()
cycles-=7
return
case 4 'FLDENV
Select Case As Const ((cr0 And 1) Or (op32 And &h100))
Case &h000 , _ '16-bit real mode
&h001 '16-bit protected mode
npxc=readmemw_386(easeg,eaaddr)
npxs=readmemw_386(easeg,eaaddr+2)
tag =readmemw_386(easeg,eaaddr+4)
TOP =(npxs Shr 11) And 7
case &h100 , _ '32-bit real mode
&h101 '32-bit protected mode
npxc=readmemw_386(easeg,eaaddr)
npxs=readmemw_386(easeg,eaaddr+4)
tag =readmemw_386(easeg,eaaddr+8)
TOP =(npxs Shr 11) And 7
End Select
cycles-=IIf((cr0 And 1),34,44)
return
case 5 'FLDCW
tempw=geteaw() : if abrt Then return
npxc=tempw
cycles-=4
return
case 6 'FSTENV
Select Case As Const ((cr0 And 1) Or (op32 And &h100))
Case &h000 '16-bit real mode
writememw_386(easeg,eaaddr,npxc)
writememw_386(easeg,eaaddr+2,npxs)
writememw_386(easeg,eaaddr+4,tag)
writememw_386(easeg,eaaddr+6,x87_pc_off)
writememw_386(easeg,eaaddr+10,x87_op_off)
exit Select
case &h001 '16-bit protected mode
writememw_386(easeg,eaaddr,npxc)
writememw_386(easeg,eaaddr+2,npxs)
writememw_386(easeg,eaaddr+4,tag)
writememw_386(easeg,eaaddr+6,x87_pc_off)
writememw_386(easeg,eaaddr+8,x87_pc_seg)
writememw_386(easeg,eaaddr+10,x87_op_off)
writememw_386(easeg,eaaddr+12,x87_op_seg)
exit Select
case &h100 '32-bit real mode
writememw_386(easeg,eaaddr,npxc)
writememw_386(easeg,eaaddr+4,npxs)
writememw_386(easeg,eaaddr+8,tag)
writememw_386(easeg,eaaddr+12,x87_pc_off)
writememw_386(easeg,eaaddr+20,x87_op_off)
writememl_386(easeg,eaaddr+24,(x87_op_off Shr 16) Shl 12)
exit Select
case &h101 '32-bit protected mode
writememw_386(easeg,eaaddr,npxc)
writememw_386(easeg,eaaddr+4,npxs)
writememw_386(easeg,eaaddr+8,tag)
writememl_386(easeg,eaaddr+12,x87_pc_off)
writememl_386(easeg,eaaddr+16,x87_pc_seg)
writememl_386(easeg,eaaddr+20,x87_op_off)
writememl_386(easeg,eaaddr+24,x87_op_seg)
exit Select
End Select
If abrt Then Return
cycles-=IIf((cr0 And 1),56,67 )
return
case 7 'FSTCW
seteaw(npxc):If abrt Then Return
cycles-=3
return
End Select
EndIf
x86illegal()
End Sub
Sub x87_da()
Dim As long templ
'Print #5,"DA:";modo,reg,Hex(rmdat32 And &hFF,2)
if (modo=3) Then
Select Case As Const (rmdat32 And &hFF)
Case &hE9 'FUCOMPP
npxs = npxs And inv(C0 Or C2 Or C3)
if ST(0)=ST(1) Then
npxs = npxs Or C3
ElseIf ST(0)<ST(1) Then
npxs = npxs Or C0
EndIf
x87_pop()
x87_pop()
cycles-=5
return
End Select
else
templ=geteal(): if abrt Then return
Select Case As Const (reg)
Case 0 'FIADD
ST(0)=ST(0)+CDbl(templ)
cycles-=20
return
case 1 'FIMUL
ST(0)=ST(0)*CDbl(templ)
cycles-=22
return
case 2 'FICOM
npxs = npxs And inv(C0 Or C2 Or C3)
if ST(0)=CDbl(templ) Then
npxs = npxs Or C3
ElseIf ST(0)<CDbl(templ) Then
npxs = npxs Or C0
EndIf
cycles-=15
return
case 3 'FICOMP
npxs = npxs And inv(C0 Or C2 Or C3)
if ST(0)=CDbl(templ) Then
npxs = npxs Or C3
ElseIf ST(0)<CDbl(templ) Then
npxs = npxs Or C0
EndIf
x87_pop()
cycles-=15
return
case 4 'FISUB
ST(0)=ST(0) - CDbl(templ)
cycles-=20
return
case 5 'FISUBR
ST(0)=CDbl(templ) - ST(0)
cycles-=19
return
case 6 'FIDIV
'ST(0)=ST(0) / CDbl(templ)
If x87_div(ST(0),ST(0),CDbl(templ)) Then return ' version 9
cycles-=84
return
case 7 'FIDIVR
'ST(0)=CDbl(templ) / ST(0)
If x87_div(ST(0),CDbl(templ),ST(0)) Then Return ' version 9
cycles-=84
return
End Select
EndIf
x86illegal()
End Sub
Sub x87_db()
Dim As Double t
Dim As Long templ
Dim As LongInt temp64 ' este es nuevo en la 8.1
'Print #5,"DB:";modo,reg,Hex(rmdat32 And &hFF,2)
if (modo=3) Then
Select Case As Const (reg)
Case 4
Select Case As Const (rmdat32 And &hFF)
case &hE1
return
case &hE2 'FCLEX
npxs = npxs And &hFF00
return
case &hE3 'FINIT
npxc=&h37F
npxs=0
tag=&hFFFF
TOP=0
cycles-=17
return
case &hE4
return
End Select
exit Select
End Select
else
Select Case As Const (reg)
Case 0 'FILD short
templ=geteal(): if abrt Then return
x87_push( CDbl(templ) )
cycles-=9
return
case 2 'FIST Short
temp64=x87_fround(ST(0)) ' nuevo en la 8.1
seteal( CLng(temp64) )
cycles-=28
return
case 3 'FISTP Short
temp64=x87_fround(ST(0)) ' nuevo en la 8.1
seteal( CLng(temp64) ): if abrt Then return
x87_pop()
cycles-=28
return
case 5 'FLD extended
t=x87_ld80(): if abrt Then return
x87_push(t)
cycles-=6
return
case 7 'FSTP extended
x87_st80(ST(0)): if abrt Then return
x87_pop()
cycles-=6
return
End Select
EndIf
x86illegal()
End Sub
Sub x87_dc()
Union ts1
As Double d
As ULongInt i
End Union
Dim t As ts1
'Print #5,"DC:";modo,reg,Hex(rmdat32 And &hFF,2)
if (modo=3) Then
Select Case As Const (rmdat32 And &hFF)
Case &hC0, &hC1, &hC2, &hC3 ,&hC4, &hC5, &hC6, &hC7 'FADD
ST(rmdat32 And 7)=ST(rmdat32 And 7) + ST(0)
cycles-=8
return
case &hC8, &hC9, &hCA, &hCB ,&hCC, &hCD, &hCE, &hCF 'FMUL
ST(rmdat32 And 7)=ST(rmdat32 And 7) * ST(0)
cycles-=16
return
case &hE0, &hE1, &hE2, &hE3 ,&hE4, &hE5, &hE6, &hE7 'FSUBR
ST(rmdat32 And 7)=ST(0) - ST(rmdat32 And 7)
cycles-=8
return
case &hE8, &hE9, &hEA, &hEB ,&hEC, &hED, &hEE, &hEF 'FSUB
ST(rmdat32 And 7)=ST(rmdat32 And 7) - ST(0)
cycles-=8
return
case &hF0, &hF1, &hF2, &hF3 ,&hF4, &hF5, &hF6, &hF7 'FDIVR
'ST(rmdat32 And 7)=(ST(0) /ST(rmdat32 And 7))
If x87_div(ST(rmdat32 And 7),ST(0),ST(rmdat32 And 7)) Then Return ' version 9
cycles-=73
return
case &hF8, &hF9, &hFA, &hFB ,&hFC, &hFD, &hFE, &hFF 'FDIV
'ST(rmdat32 And 7)=(ST(rmdat32 And 7) /ST(0))
If x87_div(ST(rmdat32 And 7),ST(rmdat32 And 7),ST(0)) Then return ' version 9
cycles-=73
return
End Select
Else
t.i = readmeml_386(easeg,eaaddr)
t.i = t.i Or (CULngInt(readmeml_386(easeg,eaaddr+4)) Shl 32)
if abrt Then return
Select Case As Const (reg)
case 0 'FADD Double
ST(0)+=t.d
cycles-=8
return
case 1 'FMUL Double
ST(0)*=t.d
cycles-=14
return
case 2 'FCOM Double
npxs = npxs And inv(C0 Or C2 Or C3)
if ST(0)=t.d Then
npxs = npxs Or C3
ElseIf ST(0)<t.d Then
npxs = npxs Or C0
EndIf
cycles-=4
return
case 3 'FCOMP Double
npxs = npxs And inv(C0 Or C2 Or C3)
if ST(0)=t.d Then
npxs = npxs Or C3
ElseIf ST(0)<t.d Then
npxs = npxs Or C0
EndIf
cycles-=4
x87_pop()
return
case 4 'FSUB Double
ST(0)=ST(0) - t.d
cycles-=8
return
case 5 'FSUBR Double
ST(0)=t.d - ST(0)
cycles-=8
return
case 6 'FDIV Double
'ST(0)=ST(0)/t.d
If x87_div(ST(0),ST(0),t.d) Then Return ' version 9
cycles-=73
return
case 7 'FDIVR Double
'ST(0)=t.d/ST(0)
If x87_div(ST(0),t.d,ST(0)) Then Return ' version 9
cycles-=73
return
End Select
EndIf
x86illegal()
End Sub
Sub x87_dd()
Union ts1
As Double d
As ULongint i
End Union
Dim t As ts1
'Print #5,"DD:";modo,reg,Hex(rmdat32 And &hFF,2)
Dim As integer temp
if (modo=3) Then
Select Case As Const (reg)
Case 0 'FFREE
tag = tag Or (3 Shl (((TOP+rmdat32) And 7) Shl 1))
cycles-=3
return
case 2 'FST
ST(rmdat32 And 7)=ST(0)
temp=(tag Shr ((TOP And 7) Shl 1)) And 3
tag = tag And inv(3 Shl (((TOP+rmdat32) And 7) Shl 1))
tag = tag Or (temp Shl (((TOP+rmdat32) And 7) Shl 1))
cycles-=3
return
case 3 'FSTP
ST(rmdat32 And 7)=ST(0)
temp=(tag Shr ((TOP And 7) Shl 1)) And 3
tag = tag And inv(3 Shl (((TOP+rmdat32) And 7) Shl 1))
tag = tag Or (temp Shl (((TOP+rmdat32) And 7) Shl 1))
x87_pop()
cycles-=3
return
case 4 'FUCOM
npxs = npxs And inv(C0 Or C2 Or C3)
if ST(0)=ST(rmdat32 And 7) Then
npxs = npxs Or C3
ElseIf ST(0)<ST(rmdat32 And 7) Then
npxs = npxs Or C0
EndIf
cycles-=4
return
case 5 'FUCOMP
npxs = npxs And inv(C0 Or C2 Or C3)
if ST(0)=ST(rmdat32 And 7) Then
npxs = npxs Or C3
ElseIf ST(0)<ST(rmdat32 And 7) Then
npxs = npxs Or C0
EndIf
x87_pop()
cycles-=4
return
End Select
else
Select Case As Const (reg)
Case 0 'FLD double-precision
t.i=readmeml_386(easeg,eaaddr)
t.i = t.i Or (CULngInt(readmeml_386(easeg,eaaddr+4)) Shl 32): if abrt Then return
x87_push(t.d)
cycles-=3
return
case 2 'FST double-precision
t.d=ST(0)
writememl_386(easeg,eaaddr,t.i And &hffffffff)
writememl_386(easeg,eaaddr+4,(t.i Shr 32))
cycles-=8
return
case 3 'FSTP double-precision
t.d=ST(0)
writememl_386(easeg,eaaddr,t.i And &hffffffff)
writememl_386(easeg,eaaddr+4,(t.i Shr 32)): if abrt Then return
x87_pop()
cycles-=8
return
case 4 'FRSTOR
Select Case As Const ((cr0 And 1) Or (op32 And &h100))
case &h000, _ '16-bit real mode
&h001 '16-bit protected mode
npxc=readmemw_386(easeg,eaaddr)
npxs=readmemw_386(easeg,eaaddr+2)
tag =readmemw_386(easeg,eaaddr+4)
TOP =(npxs Shr 11) And 7
eaaddr+=14
exit Select
case &h100, _ '32-bit real mode
&h101 '32-bit protected mode
npxc=readmemw_386(easeg,eaaddr)
npxs=readmemw_386(easeg,eaaddr+4)
tag =readmemw_386(easeg,eaaddr+8)
TOP =(npxs Shr 11) And 7
eaaddr+=28
exit Select
End Select
ST(0)=x87_ld80(): eaaddr+=10
ST(1)=x87_ld80(): eaaddr+=10
ST(2)=x87_ld80(): eaaddr+=10
ST(3)=x87_ld80(): eaaddr+=10
ST(4)=x87_ld80(): eaaddr+=10
ST(5)=x87_ld80(): eaaddr+=10
ST(6)=x87_ld80(): eaaddr+=10
ST(7)=x87_ld80()
cycles-=IIf((cr0 And 1),34,44)
return
case 6 'FSAVE
npxs = (npxs And inv(7 shl 11)) or (TOP shl 11) ' de la 9.1
Select Case As Const ((cr0 And 1) Or (op32 And &h100))
Case &h000 '16-bit real mode
writememw_386(easeg,eaaddr,npxc)
writememw_386(easeg,eaaddr+2,npxs)
writememw_386(easeg,eaaddr+4,tag)
writememw_386(easeg,eaaddr+6,x87_pc_off)
writememw_386(easeg,eaaddr+10,x87_op_off)
eaaddr+=14
x87_st80(ST(0)): eaaddr+=10
x87_st80(ST(1)): eaaddr+=10
x87_st80(ST(2)): eaaddr+=10
x87_st80(ST(3)): eaaddr+=10
x87_st80(ST(4)): eaaddr+=10
x87_st80(ST(5)): eaaddr+=10
x87_st80(ST(6)): eaaddr+=10
x87_st80(ST(7))
exit Select
case &h001 '16-bit protected mode
writememw_386(easeg,eaaddr,npxc)
writememw_386(easeg,eaaddr+2,npxs)
writememw_386(easeg,eaaddr+4,tag)
writememw_386(easeg,eaaddr+6,x87_pc_off)
writememw_386(easeg,eaaddr+8,x87_pc_seg)
writememw_386(easeg,eaaddr+10,x87_op_off)
writememw_386(easeg,eaaddr+12,x87_op_seg)
eaaddr+=14
x87_st80(ST(0)): eaaddr+=10
x87_st80(ST(1)): eaaddr+=10
x87_st80(ST(2)): eaaddr+=10
x87_st80(ST(3)): eaaddr+=10
x87_st80(ST(4)): eaaddr+=10
x87_st80(ST(5)): eaaddr+=10
x87_st80(ST(6)): eaaddr+=10
x87_st80(ST(7))
exit Select
case &h100 '32-bit real mode
writememw_386(easeg,eaaddr,npxc)
writememw_386(easeg,eaaddr+4,npxs)
writememw_386(easeg,eaaddr+8,tag)
writememw_386(easeg,eaaddr+12,x87_pc_off)
writememw_386(easeg,eaaddr+20,x87_op_off)
writememl_386(easeg,eaaddr+24,(x87_op_off Shr 16) Shl 12)
eaaddr+=28
x87_st80(ST(0)): eaaddr+=10
x87_st80(ST(1)): eaaddr+=10
x87_st80(ST(2)): eaaddr+=10
x87_st80(ST(3)): eaaddr+=10
x87_st80(ST(4)): eaaddr+=10
x87_st80(ST(5)): eaaddr+=10
x87_st80(ST(6)): eaaddr+=10
x87_st80(ST(7))
exit select
case &h101 '32-bit protected mode
writememw_386(easeg,eaaddr,npxc)
writememw_386(easeg,eaaddr+4,npxs)
writememw_386(easeg,eaaddr+8,tag)
writememl_386(easeg,eaaddr+12,x87_pc_off)
writememl_386(easeg,eaaddr+16,x87_pc_seg)
writememl_386(easeg,eaaddr+20,x87_op_off)
writememl_386(easeg,eaaddr+24,x87_op_seg)
eaaddr+=28
x87_st80(ST(0)): eaaddr+=10
x87_st80(ST(1)): eaaddr+=10
x87_st80(ST(2)): eaaddr+=10
x87_st80(ST(3)): eaaddr+=10
x87_st80(ST(4)): eaaddr+=10
x87_st80(ST(5)): eaaddr+=10
x87_st80(ST(6)): eaaddr+=10
x87_st80(ST(7))
exit Select
End Select
cycles-=IIf((cr0 And 1),56,67 )
return
case 7 'FSTSW
seteaw((npxs And &hC7FF) Or (TOP Shl 11))
cycles-=3
return
End Select
EndIf
x86illegal()
End Sub
Sub x87_de()
'Print #5,"DE:";modo,reg,Hex(rmdat32 And &hFF,2)
Dim As Long templ
if (modo=3) Then
Select Case As Const (rmdat32 And &hFF)
case &hC0, &hC1, &hC2, &hC3 ,&hC4, &hC5, &hC6, &hC7 'FADDP
ST(rmdat32 And 7)=ST(rmdat32 And 7)+ST(0) ' version 8.1 'STD(TOP)
x87_pop()
cycles-=8
return
case &hC8, &hC9, &hCA, &hCB ,&hCC, &hCD, &hCE, &hCF 'FMULP
ST(rmdat32 And 7)=ST(rmdat32 And 7)*ST(0) ' version 8.1 'STD(TOP)
x87_pop()
cycles-=16
return
Case &hD9 'FCOMPP
npxs = npxs And inv(C0 Or C2 Or C3)
' esto de la 9.1 no se si usarlo, es un lio, y ... tiene utilidad?
'If (CULngInt(ST(0))=(1 Shl 63)) And (CULngInt(ST(1))=0) Then
' npxs = npxs Or C0 ' Nasty hack to fix 80387 detection
'ElseIf (ST(0)=ST(1)) Then ' este sustituye al que sigue de la 7.0
If ST(0)=ST(1) Then ' este seria el viejo de la 7.0
npxs = npxs Or C3
ElseIf ST(0)<ST(1) Then
npxs = npxs Or C0
EndIf
x87_pop()
x87_pop()
cycles-=5
return
case &hE0, &hE1, &hE2, &hE3 ,&hE4, &hE5, &hE6, &hE7 'FSUBRP
ST(rmdat32 And 7)=ST(0)-ST(rmdat32 And 7)
x87_pop()
cycles-=8
return
case &hE8, &hE9, &hEA, &hEB ,&hEC, &hED, &hEE, &hEF 'FSUBP
ST(rmdat32 And 7)=ST(rmdat32 And 7)-ST(0) ' version 8.1 'STD(TOP)
x87_pop()
cycles-=8
return
case &hF0, &hF1, &hF2, &hF3 ,&hF4, &hF5, &hF6, &hF7 'FDIVRP
'ST(rmdat32 And 7)=ST(0)/ST(rmdat32 And 7)
If x87_div(ST(rmdat32 And 7),ST(0),ST(rmdat32 And 7)) Then Return ' version 9
x87_pop()
cycles-=73
return
case &hF8, &hF9, &hFA, &hFB ,&hFC, &hFD, &hFE, &hFF 'FDIVP
'ST(rmdat32 And 7)=ST(rmdat32 And 7)/ST(0) ' version 8.1 'STD(TOP)
If x87_div(ST(rmdat32 And 7),ST(rmdat32 And 7),ST(0)) Then Return ' version 9
x87_pop()
cycles-=73
return
End Select
else
templ=CLng(CShort(geteaw())): if abrt Then return
Select Case As Const (reg)
Case 0 'FIADD
ST(0)=ST(0)+CDbl(templ)
cycles-=20