-
Notifications
You must be signed in to change notification settings - Fork 0
/
am9511.c
906 lines (768 loc) · 18.7 KB
/
am9511.c
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
/* am9511.c
*
* First cut am9511 emulation. This version is NOT cycle accurate,
* or even algorithm accurate. It should be a somewhat reasonable
* stand-in, which should allow us to run base-line comparisions with
* the real device.
*/
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include "am9511.h"
#include "floatcnv.h"
#include "ova.h"
#include "types.h"
/* Define fp_na() -- fp to native and
* na_fp() -- native to fp
*/
#ifdef z80
#define fp_na(x,y) fp_hi(x,y)
#define na_fp(x,y) hi_fp(x,y)
#else
#define fp_na(x,y) fp_ie(x,y)
#define na_fp(x,y) ie_fp(x,y)
#endif
/* Stack is 16 bytes long. sp is the stack pointer.
* Points to next location to use.
*
* AM9511 status and operator latch
*/
struct am_context {
unsigned char stack[16];
int sp;
void *fptmp;
unsigned char status;
unsigned char op_latch;
#ifndef NDEBUG
unsigned char last_latch;
#endif
};
#define AM_OP 0x1f
/* Add to sp
*/
#define sp_add(n) ((ctx->sp + (n)) & 0xf)
/* Return pointer into stack
*/
#define stpos(offset) (ctx->stack + sp_add(offset))
/* Increment stack pointer
*/
#define inc_sp(n) ctx->sp = sp_add(n)
/* Decrement stack pointer
*/
#define dec_sp(n) ctx->sp = sp_add(-(n))
/* Push byte to am9511 stack
*/
void am_push(void *amp, unsigned char v) {
struct am_context *ctx = (struct am_context *)amp;
*stpos(0) = v;
inc_sp(1);
}
/* Pop byte from am9511 stack
*/
unsigned char am_pop(void *amp) {
struct am_context *ctx = (struct am_context *)amp;
dec_sp(1);
return *stpos(0);
}
/* Return status of am9511
*/
unsigned char am_status(void *amp) {
struct am_context *ctx = (struct am_context *)amp;
return ctx->status;
}
#define IS_SINGLE ((ctx->op_latch & AM_SINGLE) == AM_SINGLE)
#define IS_FIXED (ctx->op_latch & AM_FIXED)
/* Set SIGN and ZERO according to op type and top of stack.
* Zero detect for integer is or'ing together all the bytes.
* Zero detect for float is testing bit 23 for 0.
* The sign bit for all types is the top-most bit. If 1 then
* negative.
*/
static void sz(struct am_context *ctx) {
if (IS_SINGLE) {
if ((*stpos(-1) | *stpos(-2)) == 0)
ctx->status |= AM_ZERO;
} else if (IS_FIXED) {
if ((*stpos(-1) | *stpos(-2) | *stpos(-3) | *stpos(-4)) == 0)
ctx->status |= AM_ZERO;
} else {
if ((*stpos(-2) & 0x80) == 0)
ctx->status |= AM_ZERO;
}
if (*stpos(-1) & 0x80)
ctx->status |= AM_SIGN;
}
/* PUPI
*/
static void pupi(struct am_context *ctx) {
am_push(ctx, 0xda); /* little end to big end */
am_push(ctx, 0x0f);
am_push(ctx, 0xc9);
am_push(ctx, 0x02);
sz(ctx);
}
/* PTOS PTOD PTOF
*
* This relies on the stack data not moving during a push.
*/
static void pto(struct am_context *ctx) {
unsigned char *s;
if (IS_SINGLE) {
s = stpos(-2);
am_push(ctx, *s++);
am_push(ctx, *s);
} else {
s = stpos(-4);
am_push(ctx, *s++);
am_push(ctx, *s++);
am_push(ctx, *s++);
am_push(ctx, *s);
}
sz(ctx);
}
/* POPS POPD POPF
*
* Note that the SIGN and ZERO flags are set from the element that
* is next on stack. But... it may be wrong! We do not know what the
* new tos element really is! (in terms of type)
* The guide states and SIGN and ZERO are affected, but no more than that.
*/
static void pop(struct am_context *ctx) {
if (IS_SINGLE)
dec_sp(2);
else
dec_sp(4);
sz(ctx);
}
/* XCHS XCHD XCHF
*/
static void xch(struct am_context *ctx) {
unsigned char *s, *t, v;
if (IS_SINGLE) {
s = stpos(-2);
t = stpos(-4);
v = *t; *t++ = *s; *s++ = v;
v = *t; *t = *s; *s = v;
} else {
s = stpos(-4);
t = stpos(-8);
v = *t; *t++ = *s; *s++ = v;
v = *t; *t++ = *s; *s++ = v;
v = *t; *t++ = *s; *s++ = v;
v = *t; *t = *s; *s = v;
}
sz(ctx);
}
/* CHSF
*/
static void chsf(struct am_context *ctx) {
/* Floating point sign change - only flip sign
* (if not zero). And, as with the AM9511 chip, CHSF
* is even faster than CHSS.
*/
if (*stpos(-2) & 0x80)
*stpos(-1) ^= 0x80;
sz(ctx);
}
/* CHSS CHSD
*/
static void chs(struct am_context *ctx) {
if (IS_SINGLE) {
if (cm16(stpos(-2), stpos(-2)))
ctx->status |= AM_ERR_OVF;
} else {
if (cm32(stpos(-4), stpos(-4)))
ctx->status |= AM_ERR_OVF;
}
sz(ctx);
}
/* Push float to stack, set SIGN and ZERO
*/
static void push_float(struct am_context *ctx, float x) {
unsigned char v[4];
na_fp(&x, ctx->fptmp);
fp_am(ctx->fptmp, v);
am_push(ctx, v[0]);
am_push(ctx, v[1]);
am_push(ctx, v[2]);
am_push(ctx, v[3]);
ctx->op_latch = AM_FLOAT;
sz(ctx);
}
/* FLTS
*/
static void flts(struct am_context *ctx) {
int16 n;
float x;
n = am_pop(ctx);
n = (n << 8) | am_pop(ctx);
x = n;
push_float(ctx, x);
}
/* FLTD
*/
static void fltd(struct am_context *ctx) {
int32 n;
float x;
int b;
/* HI-TECH C long shift bug
*/
b = am_pop(ctx);
n = b;
n = n << 8;
b = am_pop(ctx);
n = n | b;
n = n << 8;
b = am_pop(ctx);
n = n | b;
n = n << 8;
b = am_pop(ctx);
n = n | b;
x = n;
push_float(ctx, x);
}
/* FIXS
*/
static void fixs(struct am_context *ctx) {
float x;
unsigned char *s;
int n;
s = stpos(-4);
am_fp(s, ctx->fptmp);
fp_na(ctx->fptmp, &x);
if ((x < -32768.0) || (x > 32767.0)) {
ctx->status |= AM_ERR_OVF;
sz(ctx);
return;
}
dec_sp(4);
n = (int)x;
am_push(ctx, n);
am_push(ctx, n >> 8);
ctx->op_latch = AM_SINGLE;
sz(ctx);
}
/* FIXD
*/
static void fixd(struct am_context *ctx) {
float x;
unsigned char *s;
int32 n;
float xl, xh;
s = stpos(-4);
am_fp(s, ctx->fptmp);
fp_na(ctx->fptmp, &x);
n = -2147483648;
xl = (float)n;
n = 2147483647;
xh = (float)n;
if ((x < xl) || (x > xh)) {
ctx->status |= AM_ERR_OVF;
sz(ctx);
return;
}
dec_sp(4);
n = (int32)x;
am_push(ctx, n);
am_push(ctx, n >> 8);
am_push(ctx, n >> 16);
am_push(ctx, n >> 24);
ctx->op_latch = AM_DOUBLE;
sz(ctx);
}
/* SADD DADD
*/
static void add(struct am_context *ctx) {
int carry;
int overflow;
if (IS_SINGLE) {
carry = add16( stpos(-4), stpos(-2), stpos(-4));
overflow = oadd16(stpos(-4), stpos(-2), stpos(-4));
dec_sp(2);
} else {
carry = add32( stpos(-8), stpos(-4), stpos(-8));
overflow = oadd32(stpos(-8), stpos(-4), stpos(-8));
dec_sp(4);
}
if (carry)
ctx->status |= AM_CARRY;
if (overflow)
ctx->status |= AM_ERR_OVF;
sz(ctx);
}
/* SSUB DSUB
*/
static void sub(struct am_context *ctx) {
int carry;
int overflow;
if (IS_SINGLE) {
carry = sub16( stpos(-4), stpos(-2), stpos(-4));
overflow = osub16(stpos(-4), stpos(-2), stpos(-4));
dec_sp(2);
} else {
carry = sub32( stpos(-8), stpos(-4), stpos(-8));
overflow = osub32(stpos(-8), stpos(-4), stpos(-8));
dec_sp(4);
}
if (carry)
ctx->status |= AM_CARRY;
if (overflow)
ctx->status |= AM_ERR_OVF;
sz(ctx);
}
/* MUL
*/
static void mul(struct am_context *ctx) {
int overflow;
if (IS_SINGLE) {
overflow = mull16(stpos(-4), stpos(-2), stpos(-4));
dec_sp(2);
} else {
overflow = mull32(stpos(-8), stpos(-4), stpos(-8));
dec_sp(4);
}
if (overflow)
ctx->status |= AM_ERR_OVF;
sz(ctx);
}
/* MUU
*/
static void muu(struct am_context *ctx) {
int overflow;
if (IS_SINGLE) {
overflow = mulu16(stpos(-4), stpos(-2), stpos(-4));
dec_sp(2);
} else {
overflow = mulu32(stpos(-8), stpos(-4), stpos(-8));
dec_sp(4);
}
if (overflow)
ctx->status |= AM_ERR_OVF;
sz(ctx);
}
/* DIV
*/
static void divi(struct am_context *ctx) {
int div0;
if (IS_SINGLE) {
div0 = div16(stpos(-4), stpos(-2), stpos(-4));
dec_sp(2);
} else {
div0 = div32(stpos(-8), stpos(-4), stpos(-8));
dec_sp(4);
}
if (div0)
ctx->status |= AM_ERR_DIV0;
sz(ctx);
}
/* Detect and report float overflow/underflow
*/
static int fov(struct am_context *ctx, double r) {
int e;
frexp(r, &e);
if (e > 63) {
ctx->status |= AM_ERR_OVF;
return 1;
} else if (e < -64) {
ctx->status |= AM_ERR_UND;
return 1;
}
return 0;
}
/* basicf - basic FADD/FSUB/FMUL/FDIV
*
* The guide says that overflow and underflow are detected on the
* exponent. The mantissa is maintained, and the exponent is offset
* by 128. So... that is what we do. Note that frexp() and ldexp()
* should be implemented via bit operations, not arithmetic.
*/
static void basicf(struct am_context *ctx) {
unsigned char *ap, *bp;
float a, b, r;
double m;
int e;
ap = stpos(-4);
am_fp(ap, ctx->fptmp);
fp_na(ctx->fptmp, &a);
bp = stpos(-8);
am_fp(bp, ctx->fptmp);
fp_na(ctx->fptmp, &b);
switch (ctx->op_latch & AM_OP) {
case AM_FADD:
r = a + b;
break;
case AM_FSUB:
r = b - a;
break;
case AM_FMUL:
r = a * b;
break;
case AM_FDIV:
if (a == 0.0) {
r = b;
ctx->status |= AM_ERR_DIV0;
} else
r = b / a;
break;
}
/* We do not use fov() because we want to bias exponent by 128
* on OVF/UND per the guide.
*/
m = frexp(r, &e);
if (e > 63) {
ctx->status |= AM_ERR_OVF;
e -= 128;
r = ldexp(m, e);
} else if (e < -64) {
ctx->status |= AM_ERR_UND;
e += 128;
r = ldexp(m, e);
}
na_fp(&r, ctx->fptmp);
fp_am(ctx->fptmp, bp);
dec_sp(4);
ctx->op_latch = AM_FLOAT;
sz(ctx);
}
/* SQRT EXP SIN COS TAN LN LOG etc (functions with single arg)
*
* Note that we use the -lm math library with GCC, and the -LF library
* with HI-TECH C. This means we are limited to only using functions
* that are in both. This explains the strange shenanigans with double
* here.
*/
static void ffunc(struct am_context *ctx) {
unsigned char *ap;
float a;
double x;
ap = stpos(-4);
am_fp(ap, ctx->fptmp);
fp_na(ctx->fptmp, &a);
x = a;
switch (ctx->op_latch & AM_OP) {
case AM_SQRT:
if (a < 0.0) {
ctx->status |= AM_ERR_NEG;
goto err;
}
x = sqrt(x);
break;
case AM_EXP:
/* -1.0 x 2^5 .. 1.0 x 2^5 */
if ((a < -32.0) || (a > 32.0)) {
ctx->status |= AM_ERR_ARG;
goto err;
}
x = exp(x);
break;
case AM_SIN:
x = sin(x);
break;
case AM_COS:
x = cos(x);
break;
case AM_TAN:
/* less than 2^-12 : return A as tan(A) */
if (a >= (1.0 / 4096.0))
x = tan(x);
break;
case AM_LN:
if (a < 0.0) {
ctx->status |= AM_ERR_NEG;
goto err;
}
x = log(x);
break;
case AM_LOG:
if (a < 0.0) {
ctx->status |= AM_ERR_NEG;
goto err;
}
x = log10(x);
break;
case AM_ASIN:
if ((a < -1.0) || (a > 1.0)) {
ctx->status |= AM_ERR_ARG;
goto err;
}
x = asin(x);
break;
case AM_ACOS:
if ((a < -1.0) || (a > 1.0)) {
ctx->status |= AM_ERR_ARG;
goto err;
}
x = acos(x);
break;
case AM_ATAN:
x = atan(x);
break;
}
if (fov(ctx, x))
goto err;
a = x;
na_fp(&a, ctx->fptmp);
fp_am(ctx->fptmp, ap);
err:
ctx->op_latch = AM_FLOAT;
sz(ctx);
}
/* PWR
*
* B^A = EXP( A * LN(B) )
*/
static void pwr(struct am_context *ctx) {
/* B^A = EXP( A * LN(B) ) */
unsigned char *ap, *bp;
float a, b;
double x;
/* A */
ap = stpos(-4);
am_fp(ap, ctx->fptmp);
fp_na(ctx->fptmp, &a);
/* B */
bp = stpos(-8);
am_fp(bp, ctx->fptmp);
fp_na(ctx->fptmp, &b);
/* LN(B) */
if (b < 0.0) {
ctx->status |= AM_ERR_NEG;
goto err;
}
x = b;
x = log(x);
/* A * LN(B) */
x = (double)a * x;
/* EXP( A * LN(B) ) */
if ((x < -32.0) || (x > 32.0)) {
ctx->status |= AM_ERR_ARG;
goto err;
}
x = exp(x);
if (fov(ctx, x))
goto err;
/* replace B with result */
b = x;
na_fp(&b, ctx->fptmp);
fp_am(ctx->fptmp, bp);
/* roll stack */
dec_sp(4);
err:
sz(ctx);
}
/* Issue am9511 command. Does not return until command
* is complete.
*/
void am_command(void *amp, unsigned char op) {
struct am_context *ctx = (struct am_context *)amp;
ctx->op_latch = op;
#ifndef NDEBUG
ctx->last_latch = op;
#endif
ctx->status = AM_BUSY;
switch (ctx->op_latch & AM_OP) {
case AM_NOP: /* no operation */
ctx->status = 0;
break;
case AM_PUPI: /* push pi */
pupi(ctx);
break;
case AM_CHS: /* change sign */
chs(ctx);
break;
case AM_CHSF: /* float change sign */
chsf(ctx); /* per Wayne Hortensius */
break;
case AM_POP: /* pop */
pop(ctx);
break;
case AM_PTO: /* push tos (copy) */
pto(ctx);
break;
case AM_XCH: /* exchange tos and nos */
xch(ctx);
break;
case AM_FLTD: /* 32 bit to float */
fltd(ctx);
break;
case AM_FLTS: /* 16 bit to float */
flts(ctx);
break;
case AM_FIXD: /* float to 32 bit */
fixd(ctx);
break;
case AM_FIXS: /* float to 16 bit */
fixs(ctx);
break;
case AM_ADD: /* add */
add(ctx);
break;
case AM_SUB: /* subtract nos-tos */
sub(ctx);
break;
case AM_MUL: /* multiply, lower half */
mul(ctx);
break;
case AM_MUU: /* multiply, upper half */
muu(ctx);
break;
case AM_DIV: /* divide nos/tos */
divi(ctx);
break;
case AM_FADD: /* floating add */
case AM_FSUB: /* floating subtract */
case AM_FMUL: /* floating multiply */
case AM_FDIV: /* floating divide */
basicf(ctx);
break;
case AM_SQRT: /* square root */
case AM_EXP: /* exponential (e^x) */
case AM_SIN: /* sine */
case AM_COS: /* cosine */
case AM_TAN: /* tangent */
case AM_LOG: /* common logarithm (base 10) */
case AM_LN: /* natural logarthm (base e) */
case AM_ASIN: /* inverse sine */
case AM_ACOS: /* inverse cosine */
case AM_ATAN: /* inverse tangent */
ffunc(ctx);
break;
case AM_PWR: /* power nos^tos */
pwr(ctx);
break;
default:
break;
}
ctx->status &= ~AM_BUSY;
}
/* Reset the am9511 emulator
*/
void am_reset(void *amp) {
struct am_context *ctx = (struct am_context *)amp;
int i;
ctx->sp = 0;
ctx->status = 0;
ctx->op_latch = 0;
ctx->last_latch = 0;
for (i = 0; i < 16; ++i)
ctx->stack[i] = 0;
}
/* Create chip.
*/
void *am_create(int status, int data) {
struct am_context *p;
void *fpp;
fpp = malloc(fp_size());
if (fpp == NULL)
return NULL;
p = malloc(sizeof (struct am_context));
if (p == NULL) {
free(fpp);
return NULL;
}
p->fptmp = fpp;
am_reset(p);
return (void *)p;
}
/* Dump stack A..H or A..D, format depends on arg (AM_SINGLE,
* AM_DOUBLE, AM_FLOAT). Dump status and last op_latch.
*/
void am_dump(void *amp, unsigned char op) {
struct am_context *ctx = (struct am_context *)amp;
int i;
int16 n;
int32 nl;
float x;
unsigned char t = ctx->status;
int b;
static char *opnames[] = {
"NOP", "SQRT", "SIN", "COS",
"TAN", "ASIN", "ACOS", "ATAN",
"LOG", "LN", "EXP", "PWR",
"ADD", "SUB", "MUL", "DIV",
"FADD", "FSUB", "FMUL", "FDIV",
"CHS", "CHSF", "MUU", "PTO",
"POP", "XCH", "PUPI", "",
"FLTD", "FLTS", "FIXD", "FIXS"
};
printf("AM9511 STATUS: %02x ", ctx->status);
if (t & AM_BUSY) printf("BUSY ");
if (t & AM_SIGN) printf("SIGN ");
if (t & AM_ZERO) printf("ZERO ");
if (t & AM_CARRY) printf("CARRY ");
printf("ERROR: ");
t &= AM_ERR_MASK;
if (t == AM_ERR_NONE) printf("NONE");
if (t & AM_ERR_DIV0) printf("DIV0");
if (t & AM_ERR_NEG) printf("NEG");
if (t & AM_ERR_ARG) printf("ARG");
if (t & AM_ERR_ARG) printf("ARG");
if (t & AM_ERR_UND) printf("UND");
if (t & AM_ERR_OVF) printf("OVF");
printf("\n");
t = ctx->last_latch;
printf("LAST COMMAND: ");
if (t & AM_SR) printf("SR ");
if ((t & AM_SINGLE) == AM_SINGLE) printf("SINGLE ");
else if (t & AM_FIXED) printf("DOUBLE ");
else printf("FLOAT ");
printf("%s\n", opnames[t & AM_OP]);
t = ctx->op_latch;
ctx->op_latch = op;
printf("AM9511 STACK ");
if (IS_SINGLE) {
printf("(SINGLE)\n");
for (i = 0; i < 8; ++i) {
n = *stpos(-(i * 2) - 1);
n = (n << 8) | *stpos(-(i * 2) - 2);
printf("%c: %02x %02x %d\n", 'A' + i,
*stpos(-(i * 2) - 1),
*stpos(-(i * 2) - 2),
n);
}
} else {
if (IS_FIXED)
printf("(DOUBLE)\n");
else
printf("(FLOAT)\n");
for (i = 0; i < 4; ++i) {
printf("%c: %02x %02x %02x %02x ", 'A' + i,
*stpos(-(i * 4) - 1),
*stpos(-(i * 4) - 2),
*stpos(-(i * 4) - 3),
*stpos(-(i * 4) - 4));
if (IS_FIXED) {
#if 0
/* Borked -- HI-TECH C bug
*
* We have seen this before -- use a "fix" (work-around)
*/
nl = *stpos(-(i * 4) - 1);
nl = (nl << 8) | *stpos(-(i * 4) - 2);
nl = (nl << 8) | *stpos(-(i * 4) - 3);
nl = (nl << 8) | *stpos(-(i * 4) - 4);
#else
/* We use the following instead, which seems to work
*/
b = *stpos(-(i * 4) - 1);
nl = b;
nl = nl << 8;
b = *stpos(-(i * 4) - 2);
nl = nl | b;
nl = nl << 8;
b = *stpos(-(i * 4) - 3);
nl = nl | b;
nl = nl << 8;
b = *stpos(-(i * 4) - 4);
nl = nl | b;
#endif
printf("%ld\n", (long)nl);
} else {
am_fp(stpos(-(i * 4) - 4), ctx->fptmp);
fp_na(ctx->fptmp, &x);
printf("%g\n", x);
}
}
}
ctx->op_latch = t;
}