-
Notifications
You must be signed in to change notification settings - Fork 0
/
Emulate.c
6158 lines (4898 loc) · 108 KB
/
Emulate.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
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
/*
* Lower level 803 instruction emulation.
* \author Peter Onion
* (C) 1990-2019 P.J.Onion
*/
#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>
#include <stdbool.h>
#include <stdlib.h>
#include "E803-types.h"
#include "E803ops.h"
#include "Emulate.h"
#include "wg-definitions.h"
#include "Wiring.h"
//#include "Sound.h"
//#define FILM 0
extern void addSamplesFromCPU(int16_t first,int16_t remainder);
// Defined in Cpu.c
extern unsigned int WG_ControlButtons; // State of the buttons like Reset etc
//extern unsigned int WG_ControlButtonPresses;
//extern unsigned int WG_ControlButtonReleases;
extern bool WG_operate_pressed;
/* Various 803 registers */
E803word ACC; // The Accumulator
E803word AR; // Auxillary register used in double length working
E803word MREG; // Multipler
E803word STORE_CHAIN; // Data read from and written back into store
E803word WG; // value on the Word Generator buttons
E803word QACC,QAR; // Q register for double length multiply
E803word MANTREG; // Mantissa and Exponents in fp maths
int T; // Number of places to shift in Gp 5
int EXPREG;
/* Short values */
int32_t BREG; // For B modification
int32_t IR; // Instruction register
int32_t SCR; // Sequence Control Register
int32_t STORE_MS; // Top half on store chain
int32_t STORE_LS; // Bottom half on store chain
/* Some 803 constants */
E803word E803_ONE = 1;
E803word E803_ZERO = 0;
E803word E803_AR_MSB= 02000000000000; // Rounding bit for Fn 53
/* Various 803 internal sisnals */
bool S;
bool SS25;
bool WI; // Something to do with manual data
bool SS2,SS3; // Timing for operate to clear busy on Fn70
bool R; // Beat counter (R=Fetch,!R=Execute)
bool FPO; // Gp6 / floating point overflow
bool OFLOW; // Integer overflow flag
bool PARITY;
bool L; // Long function, prolongs R-bar (execute) phase
bool LW; // Last word time in some long functions */
bool B; // Busy
bool M; // B Modifier flag
bool N; // Read Button
bool ALWAYS = true; /* used for conditional jump decoding */
bool NEGA,Z;
bool GPFOUR; // surpresses execute phase for jumps
bool TC; // Transfer Contol for jumps
bool J; // Interrrupt request (unused)
bool *Conditions[] = {&ALWAYS,&NEGA,&Z,&OFLOW};
/* Emulation variables */
int32_t IR_saved;
int CPU_word_time_count = 0;
/* working space */
E803word tmp;
bool *DM160s_bits[] = {&PARITY,&L,&B,&FPO,&S,&OFLOW};
int DM160s_bright[6];
bool CpuRunning = false;
int PTSBusyBright;
int16_t CPUVolume = 0x100;
/* The next two run since the emulator was started */
//unsigned int CPU_word_time_count = 0;
unsigned int CPU_word_time_stop = 1;
/* The next one refers to the current emulation cycle */
unsigned int word_times_done = 0;
E803word *CoreStore = NULL;
void fn00(void); void fn01(void); void fn02(void); void fn03(void);
void fn04(void); void fn05(void); void fn06(void); void fn07(void);
void fn10(void); void fn11(void); void fn12(void); void fn13(void);
void fn14(void); void fn15(void); void fn16(void); void fn17(void);
void fn20(void); void fn21(void); void fn22(void); void fn23(void);
void fn24(void); void fn25(void); void fn26(void); void fn27(void);
void fn30(void); void fn31(void); void fn32(void); void fn33(void);
void fn34(void); void fn35(void); void fn36(void); void fn37(void);
void fn40(void); void fn41(void); void fn42(void); void fn43(void);
void fn44(void); void fn45(void); void fn46(void); void fn47(void);
void fn50(void); void fn51(void); void fn52(void); void fn53(void);
void fn54(void); void fn55(void); void fn56(void); void fn57(void);
void fn60(void); void fn61(void); void fn62(void); void fn63(void);
void fn64(void); void fn65(void); void fn66(void); void fn67(void);
void fn70(void); void fn71(void); void fn72(void); void fn73(void);
void fn74(void); void fn75(void); void fn76(void); void fn77(void);
/** Jump table for 803 op codes */
void (*functions[])(void) =
{ fn00,fn01,fn02,fn03,fn04,fn05,fn06,fn07,
fn10,fn11,fn12,fn13,fn14,fn15,fn16,fn17,
fn20,fn21,fn22,fn23,fn24,fn25,fn26,fn27,
fn30,fn31,fn32,fn33,fn34,fn35,fn36,fn37,
fn40,fn41,fn42,fn43,fn44,fn45,fn46,fn47,
fn50,fn51,fn52,fn53,fn54,fn55,fn56,fn57,
fn60,fn61,fn62,fn63,fn64,fn65,fn66,fn67,
fn70,fn71,fn72,fn73,fn74,fn75,fn76,fn77};
// New version 4/11/19
static void FetchStore(int32_t address,
int32_t *MSp,
int32_t *LSp,
E803word *STORE_READ)
{
E803word readWord;
address &= 8191;
readWord = CoreStore[address];
*STORE_READ = readWord;
*LSp = readWord & 0xFFFFF; /* Bottom 20 bits */
readWord >>= 20;
*MSp = readWord & 0xFFFFF; /* Top 20 bits */
}
#if 0
static void WriteStore(int address, E803word *datae)
{
address &= 8191;
CoreStore[address] = *datae;
}
#endif
void setCPUVolume(unsigned int level)
{
CPUVolume = (int16_t) (level * 0x40);
}
// Called before emulate to handle button presses etc.
void PreEmulate(bool updateFlag)
{
//printf("%s %s\n",__FUNCTION__,updateFlag?"TRUE":"FALSE");
// Check if the machine is on
if(CpuRunning)
{
if(WG_operate_pressed)
{
printf("Operate Bar pressed\n");
if(S) SS25 = true;
if(WI && !R) SS3 = true; /* 17/4/06 added !R */
}
if(SS25) PARITY = FPO = false;
}
if(updateFlag)
{
for(int n=0; n<6; n+=1)
{
DM160s_bright[n] = 0;
}
}
PTSBusyBright = 0;
word_times_done = 0;
}
void PostEmulate(bool updateFlag)
{
if(updateFlag)
{
wiring(UPDATE_DISPLAYS,0);
}
}
void Emulate(int wordTimesToEmulate)
{
static int ADDRESS,fn;
while(wordTimesToEmulate--)
{
CPU_word_time_count += 1;
if(CpuRunning)
{
/* This is the heart of the emulation. It fetches instructions and executes them. */
if (R)
{ /* fetch */
// 23/2/10 There may be moreto do when reset is pressed, but not reseting OFLOW was the
// visible clue to the bug!
if (WG_ControlButtons & WG_reset)
{
OFLOW = 0;
}
if (!S)
{ // Not stopped
if (WG_ControlButtons & WG_clear_store)
{
STORE_CHAIN = E803_ZERO;
STORE_LS = STORE_MS = 0;
M = 0;
if ((ADDRESS = IR & 8191) >= 4)
{
CoreStore[ADDRESS] = STORE_CHAIN;
}
}
else
{
FetchStore(IR, &STORE_MS, &STORE_LS, &STORE_CHAIN);
if (SCR & 1) /* H or D */
{ /* F2 N2 */
if (M == 0)
{ /* No B-mod */
IR = STORE_LS;
BREG = 0;
}
else
{ /* B-Mod */
IR = STORE_LS + BREG;
BREG = 0;
M = false;
}
}
else
{ /* F1 N1 */
IR = STORE_MS;
BREG = STORE_LS; /* Save for B-mod later */
M = (STORE_LS & 0x80000) ? true : false;
}
}
}
IR_saved = IR;
/* Need to check RON to see if S should be set */
S |= (WG_ControlButtons & (WG_read | WG_obey | WG_reset)) ? true
: false;
/* Selected stop */
if(WG_ControlButtons & WG_selected_stop)
{
//int n;
//n = (WG.bytes[0] & 0xFF) + ((WG.bytes[1] << 8) & 0xFF00);
//if( n == ((SCR >> 1) & 8191))
if((WG & 017777) == ((SCR >> 1) & 017777))
{
S = true;
}
}
if(SS25)
{
printf("SS25 UP %x\n",WG_ControlButtons );
}
/* Do a single instruction if operate been pressed */
if (SS25 && (WG_ControlButtons & (WG_normal |WG_obey)))
{
SS25 = S = false;
}
if (SS25 && (WG_ControlButtons & WG_read))
{
N = true;
M = false;
SS25 = false;
}
if (!S)
{
fn = (IR >> 13) & 077;
#if 0
if (traceChannel != NULL)
{
g_string_truncate(traceText,0);
g_string_printf(traceText,"\nSCR= %"PRId32"%c IR = %02o %4"PRId32" \nACC=",
(SCR>>1),SCR & 1 ? '+' : ' ', fn,IR & 8191);
traceText = dumpWord(traceText,&ACC);
g_string_append_printf(traceText,"\nAR =");
traceText = dumpWord(traceText,&AR);
g_string_append_printf(traceText,"\nSTR=");
traceText= dumpWord(traceText,&CoreStore[IR & 8191]);
//g_string_append_c(traceText,');
g_io_channel_write_chars(traceChannel,traceText->str,-1,NULL,NULL);
//printf("%s\n",traceText->str);
}
#endif
if ((fn & 070) == 040)
{
GPFOUR = true;
if (*Conditions[fn & 3]) /* if(TC) */
{
SCR = ((IR & 8191) << 1) + ((fn >> 2) & 1);
M = false;
if ((fn & 3) == 3)
OFLOW = 0;
TC = true; /* set TC */
}
else
{
TC = false;
SCR += 1;
SCR &= 16383;
}
IR = SCR >> 1;
}
else
{
GPFOUR = false;
R = !R;
}
if (fn & 040)
{
addSamplesFromCPU(0x0000, CPUVolume);
}
else
{
addSamplesFromCPU(0x0000,0x0000);
}
}
else
{ /* S == TRUE --> stopped */
if (N)
{
IR = (WG >> 20) & 0x7FFFF;
N = false;
}
addSamplesFromCPU(0x0000,0x0000);
}
TC = GPFOUR = false;
}
else
{ /* execute R-bar*/
if (fn & 040)
{
addSamplesFromCPU( CPUVolume, CPUVolume);
}
else
{
addSamplesFromCPU(0x0000,0x0000);
}
ADDRESS = IR & 8191;
if (ADDRESS >= 4)
{
STORE_CHAIN = CoreStore[ADDRESS];
}
else
{
STORE_CHAIN = E803_ZERO;
}
/* Call the handler for the current instruction */
(functions[fn])();
if (ADDRESS >= 4)
{
//hash(ADDRESS,STORE_CHAIN);
CoreStore[ADDRESS] = STORE_CHAIN;
}
//Z = (ACC.bytes[0] | ACC.bytes[1] | ACC.bytes[2] | ACC.bytes[3]
// | ACC.bytes[4]) ? FALSE : TRUE;
Z = (ACC & Bits39) ? false : true;
//NEGA = (ACC.bytes[4] & 0x40) ? TRUE : FALSE;
NEGA = (ACC & BitsSign) ? true : false;
/* Added PTSBusy to variables to set cleared by reset
Fri Aug 8 20:20:31 BST 1997*/
{
if (WG_ControlButtons & (WG_reset | WG_clear_store))
{
OFLOW = B = L = J = 0; /*= F77State*/
//reader1CharBufferWrite = reader1CharBufferRead = 0;
// FIX THIS
// if (WG_ControlButtons & WG_reset)
// doExternalDeviceFSM(STOP);
}
}
if ( !(L | B))
{
R = !R;
SCR += 1;
SCR &= 16383;
/* If M is set, don't replace previous address in IR with SCR */
if (!M)
{
IR = SCR >> 1;
}
}
}
for(int n=0;n<6;n++)
{
if(*DM160s_bits[n]) DM160s_bright[n]+=1;
}
}
else
{ // The computer is turned off, but there are still thing to do....
addSamplesFromCPU(0x0000,0x0000);
}
}
}
void fn00(void)
{
}
void fn01(void)
{
OFLOW |= E803_neg(&ACC,&ACC);
}
void fn02(void)
{
ACC = STORE_CHAIN;
OFLOW |= E803_add(&E803_ONE,&ACC);
}
void fn03(void)
{
E803_and(&STORE_CHAIN,&ACC);
}
void fn04(void)
{
OFLOW |= E803_add(&STORE_CHAIN,&ACC);
}
void fn05(void)
{
OFLOW |= E803_sub(&STORE_CHAIN,&ACC);
}
void fn06(void)
{
ACC = E803_ZERO;
}
void fn07(void)
{
OFLOW |= E803_neg_add(&STORE_CHAIN,&ACC);
}
void fn10(void)
{
tmp = ACC;
ACC = STORE_CHAIN;
STORE_CHAIN = tmp;
}
void fn11(void)
{
tmp = ACC;
OFLOW |= E803_neg(&STORE_CHAIN,&ACC);
STORE_CHAIN = tmp;
}
void fn12(void)
{
tmp = ACC;
ACC = STORE_CHAIN;
STORE_CHAIN = tmp;
OFLOW |= E803_add(&E803_ONE,&ACC);
}
void fn13(void)
{
tmp = ACC;
ACC = STORE_CHAIN;
STORE_CHAIN = tmp;
E803_and(&STORE_CHAIN,&ACC);
}
void fn14(void)
{
tmp = ACC;
ACC = STORE_CHAIN;
STORE_CHAIN = tmp;
OFLOW |= E803_add(&STORE_CHAIN,&ACC);
}
void fn15(void)
{
tmp = STORE_CHAIN;
STORE_CHAIN = ACC;
E803_sub(&tmp,&ACC);
}
void fn16(void)
{
STORE_CHAIN = ACC;
ACC = E803_ZERO;
}
void fn17(void)
{
tmp = STORE_CHAIN;;
STORE_CHAIN = ACC;
OFLOW |= E803_neg_add(&tmp,&ACC);
}
void fn20(void)
{
STORE_CHAIN = ACC;
}
void fn21(void)
{
OFLOW |= E803_neg(&ACC,&STORE_CHAIN);
}
void fn22(void)
{
OFLOW |= E803_add(&E803_ONE,&STORE_CHAIN);
}
void fn23(void)
{
E803_and(&ACC,&STORE_CHAIN);
}
void fn24(void)
{
OFLOW |= E803_add(&ACC,&STORE_CHAIN);
}
void fn25(void)
{
OFLOW |= E803_neg_add(&ACC,&STORE_CHAIN);
}
void fn26(void)
{
STORE_CHAIN = E803_ZERO;
}
void fn27(void)
{
OFLOW |= E803_sub(&ACC,&STORE_CHAIN);
}
void fn30(void)
{
ACC = STORE_CHAIN;
}
void fn31(void)
{
ACC = STORE_CHAIN;
OFLOW |= E803_neg(&STORE_CHAIN,&STORE_CHAIN);
}
void fn32(void)
{
ACC = STORE_CHAIN;
OFLOW |= E803_add(&E803_ONE,&STORE_CHAIN);
}
void fn33(void)
{
tmp = STORE_CHAIN;
E803_and(&ACC,&STORE_CHAIN);
ACC = tmp;
}
void fn34(void)
{
tmp = STORE_CHAIN;
OFLOW |= E803_add(&ACC,&STORE_CHAIN);
ACC = tmp;
}
void fn35(void)
{
tmp = STORE_CHAIN;
OFLOW |= E803_neg_add(&ACC,&STORE_CHAIN);
ACC = tmp;
}
void fn36(void)
{
ACC = STORE_CHAIN;
STORE_CHAIN = E803_ZERO;
}
void fn37(void)
{
tmp = STORE_CHAIN;
OFLOW |= E803_sub(&ACC,&STORE_CHAIN);
ACC = tmp;
}
void fn40(void)
{
}
void fn41(void)
{
}
void fn42(void)
{
}
void fn43(void)
{
}
void fn44(void)
{
}
void fn45(void)
{
}
void fn46(void)
{
}
void fn47(void)
{
}
void fn50(void)
{
if(!L)
{ /* First word */
L = true;
T = (IR & 127) - 1;
}
if(T--< 0)
{ /* Last Word */
L = false;
}
else
{
E803_signed_shift_right(&ACC,&AR);
}
}
void fn51(void)
{
if(!L)
{ /* First word */
L = true;
T = (IR & 127) - 1;
}
if(T--< 0)
{ /* Last Word */
L = false;
AR = E803_ZERO;
}
else
{
E803_unsigned_shift_right(&ACC);
}
}
void fn52(void)
{
int m,n,action;
if(!L)
{ /* First Word time */
L = true;
MREG = STORE_CHAIN;
E803_Double_M(&MREG); /* shift one bit left so that M.bytes[0] &
3 gives the action code */
E803_Acc_to_Q(&ACC,&QACC,&QAR);
ACC = AR = E803_ZERO;
return;
}
action = MREG & 3;
switch(action)
{
case 0: break;
case 1: /* Add */
OFLOW |= E803_dadd(&QACC,&QAR,&ACC,&AR);
break;
case 2: /* Subtract */
OFLOW |= E803_dsub(&QACC,&QAR,&ACC,&AR);
break;
case 3: break;
}
E803_shift_left(&QACC,&QAR);
n = E803_Shift_M_Right(&MREG);
m = (n >> 8) & 0xFF;
n = n & 0xFF;
if( (n == 0xFF) || (m == 0x00) )
{
L = false;
}
}
void fn53(void)
{
int m,n,action;
if(!L)
{ /* First Word time */
L = true;
MREG = STORE_CHAIN;
E803_Double_M(&MREG); /* shift one bit left so that M.bytes[0] &
3 gives the action code */
E803_Acc_to_Q(&ACC,&QACC,&QAR);
ACC = AR = E803_ZERO;
return;
}
if(LW)
{
L = LW = false;
OFLOW |= E803_dadd(&E803_ZERO,&E803_AR_MSB,&ACC,&AR);
AR = E803_ZERO;
}
else
{
action = MREG & 3;
switch(action)
{
case 0: break;
case 1: /* Add */
OFLOW |= E803_dadd(&QACC,&QAR,&ACC,&AR);
break;
case 2: /* Subtract */
OFLOW |= E803_dsub(&QACC,&QAR,&ACC,&AR);
break;
case 3: break;
}
E803_shift_left(&QACC,&QAR);
n = E803_Shift_M_Right(&MREG);
m = (n >> 8) & 0xFF;
n = n & 0xFF;
if( (n == 0xFF) || (m == 0x00) )
{
LW = true;
}
}
}
void fn54(void)
{
if(!L)
{ /* First word */
L = true;
T = (IR & 127) - 1;
}
/* Note first and last words can be the same word for 0 bit shift */
if(T-- < 0)
{ /* Last Word */
L = false;
}
else
{
OFLOW |= E803_shift_left(&ACC,&AR);
}
}
void fn55(void)
{
if(!L)
{ /* First word */
L = true;
T = (IR & 127) - 1;
AR = E803_ZERO; /* This is not quite what happens on a real 803.
The AR should be cleared during LW, but clearing
it here allows the use of the normal double
length left shift function */
}
/* Note first and last words can be the same word for 0 bit shift */
if(T-- < 0)
{ /* Last Word */
L = false;
AR = E803_ZERO;
}
else
{
OFLOW |= E803_shift_left(&ACC,&AR);
}
}
void fn56(void)
{
static E803word M_sign;
E803word ACC_sign;
if(!L)
{ /* First Word time */
uint64_t *m,mm,n;
L = true;
MREG = STORE_CHAIN;
/* Bug fixed 11/4/2010 The remainder needs an extra bit so
MREG and ACC/AR are sign extended to 40 bits and special
versions of add and subtract are used.
Oddly the listings of the DOS version from 1992 have
code to shift these values one place right.
*/
m = &MREG;
mm = n = *m;
n &= 0x4000000000LL; // Sign bit
mm &= 0x7FFFFFFFFFLL; // 39 bits
n *= 6; // Two duplicate sign bits
*m =mm | n;
m = &ACC;
mm = n = *m;
n &= 0x4000000000LL; // Sign bit
mm &= 0x7FFFFFFFFFLL; // 39 bits
n *= 6; // Two duplicate sign bits
*m =mm | n;
M_sign = MREG;
T = 40; /* ? */
QAR = QACC = E803_ZERO; /* Clear QAR so I can use the double
length left shift on QACC */
/*printf(" ");
dumpACCAR();
printf("\n");
*/
return;
}
ACC_sign = 0;
if(T--)
{
#if 0
if(traceChannel != NULL)
{
g_string_truncate(traceText,0);
g_string_printf(traceText,"\n%s T=%d\nMREG=",__FUNCTION__,T);
dumpWord(traceText,&MREG);
g_string_append_printf(traceText,"\nACC =");
dumpWord(traceText,&ACC);
g_string_append_printf(traceText,"\nAR =");
dumpWord(traceText,&AR);
g_string_append_printf(traceText,"\nQACC=");
dumpWord(traceText,&QACC);
}
#endif
if(T == 39)
{ /* Second word */
ACC_sign = ACC;
}
E803_shift_left(&QACC,&QAR);
if((ACC ^ M_sign) & 0x8000000000)
{ /* Signs different , so add */
E803_add56(&MREG,&ACC);
}
else
{ /* Signs same, so subtract */
E803_sub56(&MREG,&ACC);
if(T != 39) QACC |= 1;
}
#if 0
if(traceChannel != NULL)
{
g_string_append_printf(traceText,"\nACC2=");
dumpWord(traceText,&ACC);
g_string_append_printf(traceText,"\nAR2 =");