forked from tingox/nd100em
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcpu.c
4043 lines (3736 loc) · 119 KB
/
cpu.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
/*
* nd100em - ND100 Virtual Machine
*
* Copyright (c) 2006 Per-Olof Astrom
* Copyright (c) 2006-2008 Roger Abrahamsson
* Copyright (c) 2008 Zdravko
*
* This file is originated from the nd100em project.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program (in the main directory of the nd100em
* distribution in the file COPYING); if not, see <http://www.gnu.org/licenses/>.
*/
#include <termios.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <errno.h>
#include <pthread.h>
#include <semaphore.h>
#include <signal.h>
#include <unistd.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <limits.h>
#include <math.h>
#include <string.h>
#include "nd100.h"
#include "cpu.h"
#define BUFSTRSIZE 24
struct termios savetty;
/* Interrupt thread synchronization */
sem_t sem_int;
/* mopc synchronization */
sem_t sem_mopc;
/* running cpu synchronization */
sem_t sem_run;
/* stopping cpu synchronization */
sem_t sem_stop;
/* Performance stuff */
double instr_counter;
float usertime,systemtime,totaltime;
struct rusage *used;
/* temporary string for misc data, basically a junk variable */
/* used by different trace stuff before sending off to tracing */
char trace_temp_str[256];
/* OpToStr
* IN: pointer to string ,raw operand
* OUT: Sets the string with the dissassembled operand and values
*/
void OpToStr(char *opstr, ushort operand) {
ushort instr;
char numstr[BUFSTRSIZE];
char deltastr[BUFSTRSIZE];
unsigned char nibble;
char offset,delta;
unsigned char relmode;
bool isneg;
offset = operand & 0x00ff;
nibble = operand & 0x000f;
relmode = (operand & 0x0700)>> 8;
delta = (operand & 070);
/* put offset into a string variable in octal with +/- sign for easy reading */
((int)offset <0) ? (void)snprintf(numstr,BUFSTRSIZE,"-%o",-(int)offset) : (void)snprintf(numstr,BUFSTRSIZE,"%o",offset);
/* ND110 delta offset for some instructions */
(void)snprintf(deltastr,sizeof(deltastr),"%o",delta);
instr=extract_opcode(operand);
switch(instr) {
case 0000000: /* STZ */
(void)snprintf(opstr,BUFSTRSIZE,"STZ %s%s",relmode_str[relmode],numstr);
break;
case 0004000: /* STA */
(void)snprintf(opstr,BUFSTRSIZE,"STA %s%s",relmode_str[relmode],numstr);
break;
case 0010000: /* STT */
(void)snprintf(opstr,BUFSTRSIZE,"STT %s%s",relmode_str[relmode],numstr);
break;
case 0014000: /* STX */
(void)snprintf(opstr,BUFSTRSIZE,"STX %s%s",relmode_str[relmode],numstr);
break;
case 0020000: /* STD */
(void)snprintf(opstr,BUFSTRSIZE,"STD %s%s",relmode_str[relmode],numstr);
break;
case 0024000: /* LDD */
(void)snprintf(opstr,BUFSTRSIZE,"LDD %s%s",relmode_str[relmode],numstr);
break;
case 0030000: /* STF */
(void)snprintf(opstr,BUFSTRSIZE,"STF %s%s",relmode_str[relmode],numstr);
break;
case 0034000: /* LDF */
(void)snprintf(opstr,BUFSTRSIZE,"LDF %s%s",relmode_str[relmode],numstr);
break;
case 0040000: /* MIN */
(void)snprintf(opstr,BUFSTRSIZE,"MIN %s%s",relmode_str[relmode],numstr);
break;
case 0044000: /* LDA */
(void)snprintf(opstr,BUFSTRSIZE,"LDA %s%s",relmode_str[relmode],numstr);
break;
case 0050000: /* LDT */
(void)snprintf(opstr,BUFSTRSIZE,"LDT %s%s",relmode_str[relmode],numstr);
break;
case 0054000: /* LDX */
(void)snprintf(opstr,BUFSTRSIZE,"LDX %s%s",relmode_str[relmode],numstr);
break;
case 0060000: /* ADD */
(void)snprintf(opstr,BUFSTRSIZE,"ADD %s%s",relmode_str[relmode],numstr);
break;
case 0064000: /* SUB */
(void)snprintf(opstr,BUFSTRSIZE,"SUB %s%s",relmode_str[relmode],numstr);
break;
case 0070000: /* AND */
(void)snprintf(opstr,BUFSTRSIZE,"AND %s%s",relmode_str[relmode],numstr);
break;
case 0074000: /* ORA */
(void)snprintf(opstr,BUFSTRSIZE,"ORA %s%s",relmode_str[relmode],numstr);
break;
case 0100000: /* FAD */
(void)snprintf(opstr,BUFSTRSIZE,"FAD %s%s",relmode_str[relmode],numstr);
break;
case 0104000: /* FSB */
(void)snprintf(opstr,BUFSTRSIZE,"FSB %s%s",relmode_str[relmode],numstr);
break;
case 0110000: /* FMU */
(void)snprintf(opstr,BUFSTRSIZE,"FMU %s%s",relmode_str[relmode],numstr);
break;
case 0114000: /* FDV */
(void)snprintf(opstr,BUFSTRSIZE,"FDV %s%s",relmode_str[relmode],numstr);
break;
case 0120000: /* MPY */
(void)snprintf(opstr,BUFSTRSIZE,"MPY %s%s",relmode_str[relmode],numstr);
break;
case 0124000: /* JMP */
(void)snprintf(opstr,BUFSTRSIZE,"JMP %s%s",relmode_str[relmode],numstr);
break;
case 0130000: /* JAP */
(void)snprintf(opstr,BUFSTRSIZE,"JAP %s",numstr);
break;
case 0130400: /* JAN */
(void)snprintf(opstr,BUFSTRSIZE,"JAN %s",numstr);
break;
case 0131000: /* JAZ */
(void)snprintf(opstr,BUFSTRSIZE,"JAZ %s",numstr);
break;
case 0131400: /* JAF */
(void)snprintf(opstr,BUFSTRSIZE,"JAF %s",numstr);
break;
case 0132000: /* JPC */
(void)snprintf(opstr,BUFSTRSIZE,"JPC %s",numstr);
break;
case 0132400: /* JNC */
(void)snprintf(opstr,BUFSTRSIZE,"JNC %s",numstr);
break;
case 0133000: /* JXZ */
(void)snprintf(opstr,BUFSTRSIZE,"JXZ %s",numstr);
break;
case 0133400: /* JXN */
(void)snprintf(opstr,BUFSTRSIZE,"JXN %s",numstr);
break;
case 0134000: /* JPL */
(void)snprintf(opstr,BUFSTRSIZE,"JPL %s%s",relmode_str[relmode],numstr);
break;
case 0140000: /* SKP */
(void)snprintf(opstr,BUFSTRSIZE,"SKP IF %s %s %s",skipregn_dst[(operand & 0x0007)],skiptype_str[((operand & 0x0700) >> 8)],skipregn_src[((operand & 0x0038) >> 3)]);
break;
case 0140120: /* ADDD */
(void)snprintf(opstr,BUFSTRSIZE,"ADDD");
break;
case 0140121: /* SUBD */
(void)snprintf(opstr,BUFSTRSIZE,"SUBD");
break;
case 0140122: /* COMD */
(void)snprintf(opstr,BUFSTRSIZE,"COMD");
break;
case 0140123: /* TSET */
(void)snprintf(opstr,BUFSTRSIZE,"TSET");
break;
case 0140124: /* PACK */
(void)snprintf(opstr,BUFSTRSIZE,"PACK");
break;
case 0140125: /* UPACK */
(void)snprintf(opstr,BUFSTRSIZE,"UPACK");
break;
case 0140126: /* SHDE */
(void)snprintf(opstr,BUFSTRSIZE,"SHDE");
break;
case 0140127: /* RDUS */
(void)snprintf(opstr,BUFSTRSIZE,"RDUS");
break;
case 0140130: /* BFILL */
(void)snprintf(opstr,BUFSTRSIZE,"BFILL");
break;
case 0140131: /* MOVB */
(void)snprintf(opstr,BUFSTRSIZE,"MOVB");
break;
case 0140132: /* MOVBF */
(void)snprintf(opstr,BUFSTRSIZE,"MOVBF");
break;
case 0140133: /* VERSN - ND110 specific */
if ((CurrentCPUType = ND100) || (CurrentCPUType = ND100CE) || (CurrentCPUType = ND100CX)) /* We are ND100 */
break;
else /* We are a ND110, print instruction */
(void)snprintf(opstr,BUFSTRSIZE,"VERSN");
case 0140134: /* INIT */
(void)snprintf(opstr,BUFSTRSIZE,"INIT");
break;
case 0140135: /* ENTR */
(void)snprintf(opstr,BUFSTRSIZE,"ENTR");
break;
case 0140136: /* LEAVE */
(void)snprintf(opstr,BUFSTRSIZE,"LEAVE");
break;
case 0140137: /* ELEAV */
(void)snprintf(opstr,BUFSTRSIZE,"ELEAV");
break;
case 0140300: /* SETPT */
(void)snprintf(opstr,BUFSTRSIZE,"SETPT");
break;
case 0140301: /* CLEPT */
(void)snprintf(opstr,BUFSTRSIZE,"CLEPT");
break;
case 0140302: /* CLNREENT */
(void)snprintf(opstr,BUFSTRSIZE,"CLNREENT");
break;
case 0140303: /* CHREENT-PAGES */
(void)snprintf(opstr,BUFSTRSIZE,"CHREENT-PAGES");
break;
case 0140304: /* CLEPU */
(void)snprintf(opstr,BUFSTRSIZE,"CLEPU");
break;
case 0140200: /* USER0 */
(void)snprintf(opstr,BUFSTRSIZE,"USER0");
break;
case 0140500: /* USER1 or ND110 instruction WGLOB */
if ((CurrentCPUType = ND100) || (CurrentCPUType = ND100CE) || (CurrentCPUType = ND100CX)) /* We are ND100 */
(void)snprintf(opstr,BUFSTRSIZE,"USER1");
else
(void)snprintf(opstr,BUFSTRSIZE,"WGLOB"); /* We are ND110 */
break;
case 0140501: /* RGLOB - ND110 Specific */
(void)snprintf(opstr,BUFSTRSIZE,"RGLOB");
break;
case 0140502: /* INSPL - ND110 Specific */
(void)snprintf(opstr,BUFSTRSIZE,"INSPL");
break;
case 0140503: /* REMPL - ND110 Specific */
(void)snprintf(opstr,BUFSTRSIZE,"REMPL");
break;
case 0140504: /* CNREK - ND110 Specific */
(void)snprintf(opstr,BUFSTRSIZE,"CNREK");
break;
case 0140505: /* CLPT - ND110 Specific */
(void)snprintf(opstr,BUFSTRSIZE,"CLPT");
break;
case 0140506: /* ENPT - ND110 Specific */
(void)snprintf(opstr,BUFSTRSIZE,"ENPT");
break;
case 0140507: /* REPT - ND110 Specific */
(void)snprintf(opstr,BUFSTRSIZE,"REPT");
break;
case 0140510: /* LBIT - ND110 Specific */
(void)snprintf(opstr,BUFSTRSIZE,"LBIT");
break;
case 0140513: /* SBITP - ND110 Specific */
(void)snprintf(opstr,BUFSTRSIZE,"SBITP");
break;
case 0140514: /* LBYTP - ND110 Specific */
(void)snprintf(opstr,BUFSTRSIZE,"LBYTP");
break;
case 0140515: /* SBYTP - ND110 Specific */
(void)snprintf(opstr,BUFSTRSIZE,"SBYTP");
break;
case 0140516: /* TSETP - ND110 Specific */
(void)snprintf(opstr,BUFSTRSIZE,"TSETP");
break;
case 0140517: /* RDUSP - ND110 Specific */
(void)snprintf(opstr,BUFSTRSIZE,"RDUSP");
break;
case 0140600: /* EXR */
(void)snprintf(opstr,BUFSTRSIZE,"EXR %s",skipregn_src[((operand & 0x0038) >> 3)]);
break;
case 0140700: /* USER2 */
if ((CurrentCPUType = ND100) || (CurrentCPUType = ND100CE) || (CurrentCPUType = ND100CX)) /* We are ND100 */
(void)snprintf(opstr,BUFSTRSIZE,"USER2");
else
(void)snprintf(opstr,BUFSTRSIZE,"LASB %s",deltastr); /* We are ND110 */
break;
case 0140701: /* SASB - ND110 Specific */
(void)snprintf(opstr,BUFSTRSIZE,"SASB %s",deltastr);
break;
case 0140702: /* LACB - ND110 Specific */
(void)snprintf(opstr,BUFSTRSIZE,"LACB %s",deltastr);
break;
case 0140703: /* SASB - ND110 Specific */
(void)snprintf(opstr,BUFSTRSIZE,"SASB %s",deltastr);
break;
case 0140704: /* LXSB - ND110 Specific */
(void)snprintf(opstr,BUFSTRSIZE,"LXSB %s",deltastr);
break;
case 0140705: /* LXCB - ND110 Specific */
(void)snprintf(opstr,BUFSTRSIZE,"LXCB %s",deltastr);
break;
case 0140706: /* SZSB - ND110 Specific */
(void)snprintf(opstr,BUFSTRSIZE,"SZSB %s",deltastr);
break;
case 0140707: /* SZCB - ND110 Specific */
(void)snprintf(opstr,BUFSTRSIZE,"SZCB %s",deltastr);
break;
case 0141100: /* USER3 */
(void)snprintf(opstr,BUFSTRSIZE,"USER3");
break;
case 0141200: /* RMPY */
(void)snprintf(opstr,BUFSTRSIZE,"RMPY %s %s",skipregn_src[((operand & 0x0038) >> 3)],skipregn_dst[(operand & 0x0007)]);
break;
case 0141300: /* USER4 */
(void)snprintf(opstr,BUFSTRSIZE,"USER4");
break;
case 0141500: /* USER5 */
(void)snprintf(opstr,BUFSTRSIZE,"USER5");
break;
case 0141600: /* RDIV */
(void)snprintf(opstr,BUFSTRSIZE,"RDIV %s",skipregn_src[((operand & 0x0038) >> 3)]);
break;
case 0141700: /* USER6 */
(void)snprintf(opstr,BUFSTRSIZE,"USER6");
break;
case 0142100: /* USER7 */
(void)snprintf(opstr,BUFSTRSIZE,"USER7");
break;
case 0142200: /* LBYT */
/* NOTE : moved from old parsing, SKP part, might have introduced P++ probs here */
(void)snprintf(opstr,BUFSTRSIZE,"LBYT");
break;
case 0142300: /* USER8 */
(void)snprintf(opstr,BUFSTRSIZE,"USER8");
break;
case 0142500: /* USER9 */
(void)snprintf(opstr,BUFSTRSIZE,"USER9");
break;
case 0142600: /* SBYT */
/* NOTE : moved from old parsing, SKP part, might have introduced P++ probs here */
(void)snprintf(opstr,BUFSTRSIZE,"SBYT");
break;
case 0142700: /* GECO - Undocumented instruction */
(void)snprintf(opstr,BUFSTRSIZE,"GECO");
break;
case 0143100: /* MOVEW */
(void)snprintf(opstr,BUFSTRSIZE,"MOVEW");
break;
case 0143200: /* MIX3 */
(void)snprintf(opstr,BUFSTRSIZE,"MIX3");
break;
case 0143300: /* LDATX */
(void)snprintf(opstr,BUFSTRSIZE,"LDATX");
break;
case 0143301: /* LDXTX */
(void)snprintf(opstr,BUFSTRSIZE,"LDXTX");
break;
case 0143302: /* LDDTX */
(void)snprintf(opstr,BUFSTRSIZE,"LDDTX");
break;
case 0143303: /* LDBTX */
(void)snprintf(opstr,BUFSTRSIZE,"LDBTX");
break;
case 0143304: /* STATX */
(void)snprintf(opstr,BUFSTRSIZE,"STATX");
break;
case 0143305: /* STZTX */
(void)snprintf(opstr,BUFSTRSIZE,"STZTX");
break;
case 0143306: /* STDTX */
(void)snprintf(opstr,BUFSTRSIZE,"STDTX");
break;
case 0143500: /* LWCS */
(void)snprintf(opstr,BUFSTRSIZE,"LWCS");
break;
case 0143604: /* IDENT PL10 */
(void)snprintf(opstr,BUFSTRSIZE,"IDENT PL10");
break;
case 0143611: /* IDENT PL11 */
(void)snprintf(opstr,BUFSTRSIZE,"IDENT PL11");
break;
case 0143622: /* IDENT PL12 */
(void)snprintf(opstr,BUFSTRSIZE,"IDENT PL12");
break;
case 0143643: /* IDENT PL13 */
(void)snprintf(opstr,BUFSTRSIZE,"IDENT PL13");
break;
case 0144000: /* SWAP */
(void)snprintf(opstr,BUFSTRSIZE,"SWAP %s %s",skipregn_src[((operand & 0x0038) >> 3)],skipregn_dst[(operand & 0x0007)]);
break;
case 0144100: /* SWAP CLD */
(void)snprintf(opstr,BUFSTRSIZE,"SWAP CLD %s %s",skipregn_src[((operand & 0x0038) >> 3)],skipregn_dst[(operand & 0x0007)]);
break;
case 0144200: /* SWAP CM1 */
(void)snprintf(opstr,BUFSTRSIZE,"SWAP CM1 %s %s",skipregn_src[((operand & 0x0038) >> 3)],skipregn_dst[(operand & 0x0007)]);
break;
case 0144300: /* SWAP CM1 CLD */
(void)snprintf(opstr,BUFSTRSIZE,"SWAP CM1 CLD %s %s",skipregn_src[((operand & 0x0038) >> 3)],skipregn_dst[(operand & 0x0007)]);
break;
case 0144400: /* RAND */
(void)snprintf(opstr,BUFSTRSIZE,"RAND %s %s",skipregn_src[((operand & 0x0038) >> 3)],skipregn_dst[(operand & 0x0007)]);
break;
case 0144500: /* RAND CLD */
(void)snprintf(opstr,BUFSTRSIZE,"RAND CLD %s %s",skipregn_src[((operand & 0x0038) >> 3)],skipregn_dst[(operand & 0x0007)]);
break;
case 0144600: /* RAND CM1 */
(void)snprintf(opstr,BUFSTRSIZE,"RAND CM1 %s %s",skipregn_src[((operand & 0x0038) >> 3)],skipregn_dst[(operand & 0x0007)]);
break;
case 0144700: /* RAND CM1 CLD */
(void)snprintf(opstr,BUFSTRSIZE,"RAND CM1 CLD %s %s",skipregn_src[((operand & 0x0038) >> 3)],skipregn_dst[(operand & 0x0007)]);
break;
case 0145000: /* REXO */
(void)snprintf(opstr,BUFSTRSIZE,"REXO %s %s",skipregn_src[((operand & 0x0038) >> 3)],skipregn_dst[(operand & 0x0007)]);
break;
case 0145100: /* REXO CLD */
(void)snprintf(opstr,BUFSTRSIZE,"REXO CLD %s %s",skipregn_src[((operand & 0x0038) >> 3)],skipregn_dst[(operand & 0x0007)]);
break;
case 0145200: /* REXO CM1 */
(void)snprintf(opstr,BUFSTRSIZE,"REXO CM1 %s %s",skipregn_src[((operand & 0x0038) >> 3)],skipregn_dst[(operand & 0x0007)]);
break;
case 0145300: /* REXO CM1 CLD */
(void)snprintf(opstr,BUFSTRSIZE,"REXO CM1 CLD %s %s",skipregn_src[((operand & 0x0038) >> 3)],skipregn_dst[(operand & 0x0007)]);
break;
case 0145400: /* RORA */
(void)snprintf(opstr,BUFSTRSIZE,"RORA %s %s",skipregn_src[((operand & 0x0038) >> 3)],skipregn_dst[(operand & 0x0007)]);
break;
case 0145500: /* RORA CLD */
(void)snprintf(opstr,BUFSTRSIZE,"RORA CLD %s %s",skipregn_src[((operand & 0x0038) >> 3)],skipregn_dst[(operand & 0x0007)]);
break;
case 0145600: /* RORA CM1 */
(void)snprintf(opstr,BUFSTRSIZE,"RORA CM1 %s %s",skipregn_src[((operand & 0x0038) >> 3)],skipregn_dst[(operand & 0x0007)]);
break;
case 0145700: /* RORA CM1 CLD */
(void)snprintf(opstr,BUFSTRSIZE,"RORA CM1 CLD %s %s",skipregn_src[((operand & 0x0038) >> 3)],skipregn_dst[(operand & 0x0007)]);
break;
case 0146000: /* RADD */
(void)snprintf(opstr,BUFSTRSIZE,"RADD %s %s",skipregn_src[((operand & 0x0038) >> 3)],skipregn_dst[(operand & 0x0007)]);
break;
case 0146100: /* RADD CLD */
(void)snprintf(opstr,BUFSTRSIZE,"RADD CLD %s %s",skipregn_src[((operand & 0x0038) >> 3)],skipregn_dst[(operand & 0x0007)]);
break;
case 0146200: /* RADD CM1 */
(void)snprintf(opstr,BUFSTRSIZE,"RADD CM1 %s %s",skipregn_src[((operand & 0x0038) >> 3)],skipregn_dst[(operand & 0x0007)]);
break;
case 0146300: /* RADD CM1 CLD */
(void)snprintf(opstr,BUFSTRSIZE,"RADD CM1 CLD %s %s",skipregn_src[((operand & 0x0038) >> 3)],skipregn_dst[(operand & 0x0007)]);
break;
case 0146400: /* RADD AD1 */
(void)snprintf(opstr,BUFSTRSIZE,"RADD AD1 %s %s",skipregn_src[((operand & 0x0038) >> 3)],skipregn_dst[(operand & 0x0007)]);
break;
case 0146500: /* RADD AD1 CLD */
(void)snprintf(opstr,BUFSTRSIZE,"RADD AD1 CLD %s %s",skipregn_src[((operand & 0x0038) >> 3)],skipregn_dst[(operand & 0x0007)]);
break;
case 0146600: /* RADD AD1 CM1 */
(void)snprintf(opstr,BUFSTRSIZE,"RADD AD1 CM1 %s %s",skipregn_src[((operand & 0x0038) >> 3)],skipregn_dst[(operand & 0x0007)]);
break;
case 0146700: /* RADD AD1 CM1 CLD */
(void)snprintf(opstr,BUFSTRSIZE,"RADD AD1 CM1 CLD %s %s",skipregn_src[((operand & 0x0038) >> 3)],skipregn_dst[(operand & 0x0007)]);
break;
case 0147000: /* RADD ADC */
(void)snprintf(opstr,BUFSTRSIZE,"RADD ADC %s %s",skipregn_src[((operand & 0x0038) >> 3)],skipregn_dst[(operand & 0x0007)]);
break;
case 0147100: /* RADD ADC CLD */
(void)snprintf(opstr,BUFSTRSIZE,"RADD ADC CLD %s %s",skipregn_src[((operand & 0x0038) >> 3)],skipregn_dst[(operand & 0x0007)]);
break;
case 0147200: /* RADD ADC CM1 */
(void)snprintf(opstr,BUFSTRSIZE,"RADD ADC CM1 %s %s",skipregn_src[((operand & 0x0038) >> 3)],skipregn_dst[(operand & 0x0007)]);
break;
case 0147300: /* RADD ADC CM1 CLD */
(void)snprintf(opstr,BUFSTRSIZE,"RADD ADC CM1 CLD %s %s",skipregn_src[((operand & 0x0038) >> 3)],skipregn_dst[(operand & 0x0007)]);
break;
case 0147400: /* NOOP */
case 0147500: /* NOOP */
case 0147600: /* NOOP */
case 0147700: /* NOOP */
(void)snprintf(opstr,BUFSTRSIZE,"ROP NOOP");
break;
case 0150000: /* TRA */
(void)snprintf(opstr,BUFSTRSIZE,"TRA %s", intregn_r[nibble]);
break;
case 0150100: /* TRR */
(void)snprintf(opstr,BUFSTRSIZE,"TRR %s", intregn_w[nibble]);
break;
case 0150200: /* MCL */
(void)snprintf(opstr,BUFSTRSIZE,"MCL %s", intregn_w[nibble]);
break;
case 0150300: /* MST */
(void)snprintf(opstr,BUFSTRSIZE,"MST %s", intregn_w[nibble]);
break;
case 0150400: /* OPCOM */
(void)snprintf(opstr,BUFSTRSIZE,"OPCOM");
break;
case 0150401: /* IOF */
(void)snprintf(opstr,BUFSTRSIZE,"IOF");
break;
case 0150402: /* ION */
(void)snprintf(opstr,BUFSTRSIZE,"ION");
break;
case 0150404: /* POF */
(void)snprintf(opstr,BUFSTRSIZE,"POF");
break;
case 0150405: /* PIOF */
(void)snprintf(opstr,BUFSTRSIZE,"PIOF");
break;
case 0150406: /* SEX */
(void)snprintf(opstr,BUFSTRSIZE,"SEX");
break;
case 0150407: /* REX */
(void)snprintf(opstr,BUFSTRSIZE,"REX");
break;
case 0150410: /* PON */
(void)snprintf(opstr,BUFSTRSIZE,"PON");
break;
case 0150412: /* PION */
(void)snprintf(opstr,BUFSTRSIZE,"PION");
break;
case 0150415: /* IOXT */
(void)snprintf(opstr,BUFSTRSIZE,"IOXT");
break;
case 0150416: /* EXAM */
(void)snprintf(opstr,BUFSTRSIZE,"EXAM");
break;
case 0150417: /* DEPO */
(void)snprintf(opstr,BUFSTRSIZE,"DEPO");
break;
case 0151000: /* WAIT */
(void)snprintf(opstr,BUFSTRSIZE,"WAIT"); /* TODO:: number??*/
break;
case 0151400: /* NLZ*/
(void)snprintf(opstr,BUFSTRSIZE,"NLZ %s",numstr);
break;
case 0152000: /* DNZ*/
(void)snprintf(opstr,BUFSTRSIZE,"DNZ %s",numstr);
break;
case 0152400: /* SRB */ /* NOTE: These two seems to have bit req on 0-2 as well */
(void)snprintf(opstr,BUFSTRSIZE,"SRB %o",(operand & 0x0078));
break;
case 0152600: /* LRB */ /* NOTE: These two seems to have bit req on 0-2 as well */
(void)snprintf(opstr,BUFSTRSIZE,"LRB %o",(operand & 0x0078) >> 3);
break;
case 0153000: /* MON */
(void)snprintf(opstr,BUFSTRSIZE,"MON %o",(operand & 0x00ff));
break;
case 0153400: /* IRW */
(void)snprintf(opstr,BUFSTRSIZE,"IRW %o %s",(operand & 0x0078), regn_w[(operand & 0x0007)]);
break;
case 0153600: /* IRR */
(void)snprintf(opstr,BUFSTRSIZE,"IRR %o %s",(operand & 0x0078), regn_w[(operand & 0x0007)]);
break;
case 0154000: /* SHT */
/* negative value -> shift right else shift left*/
isneg = ((operand & 0x0020)>>5) ? 1:0;
// offset = ((operand & 0x0020)>>5) ? (char)((operand & 0x003F) | 0x00C0) : (operand & 0x003F);
offset = (isneg) ? (~((operand & 0x003F) | 0xFFC0)+1) : (operand & 0x003F);
(isneg) ? (void)snprintf(numstr,BUFSTRSIZE,"SHR %o",offset) : (void)snprintf(numstr,BUFSTRSIZE,"%o",offset);
(void)snprintf(opstr,BUFSTRSIZE,"SHT %s%s",shtype_str[((operand & 0x0600) >> 9)],numstr);
break;
case 0154200: /* SHD */
/* negative value -> shift right else shift left*/
isneg = ((operand & 0x0020)>>5) ? 1:0;
offset = (isneg) ? (~((operand & 0x003F) | 0xFFC0)+1) : (operand & 0x003F);
(isneg) ? (void)snprintf(numstr,BUFSTRSIZE,"SHR %o",offset) : (void)snprintf(numstr,BUFSTRSIZE,"%o",offset);
// offset = ((operand & 0x0020)>>5) ? (char)((operand & 0x003F) | 0x00C0) : (operand & 0x003F);
// ((int)offset <0) ? (void)snprintf(numstr,BUFSTRSIZE,"SHR %o",-(int)offset) : (void)snprintf(numstr,BUFSTRSIZE,"%o",offset);
(void)snprintf(opstr,BUFSTRSIZE,"SHD %s%s",shtype_str[((operand & 0x0600) >> 9)],numstr);
break;
case 0154400: /* SHA */
/* negative value -> shift right else shift left*/
isneg = ((operand & 0x0020)>>5) ? 1:0;
offset = (isneg) ? (~((operand & 0x003F) | 0xFFC0)+1) : (operand & 0x003F);
(isneg) ? (void)snprintf(numstr,BUFSTRSIZE,"SHR %o",offset) : (void)snprintf(numstr,BUFSTRSIZE,"%o",offset);
// offset = ((operand & 0x0020)>>5) ? (char)((operand & 0x003F) | 0x00C0) : (operand & 0x003F);
// ((int)offset <0) ? (void)snprintf(numstr,BUFSTRSIZE,"SHR %o",-(int)offset) : (void)snprintf(numstr,BUFSTRSIZE,"%o",offset);
(void)snprintf(opstr,BUFSTRSIZE,"SHA %s%s",shtype_str[((operand & 0x0600) >> 9)],numstr);
break;
case 0154600: /* SAD */
/* negative value -> shift right else shift left*/
isneg = ((operand & 0x0020)>>5) ? 1:0;
offset = (isneg) ? (~((operand & 0x003F) | 0xFFC0)+1) : (operand & 0x003F);
(isneg) ? (void)snprintf(numstr,BUFSTRSIZE,"SHR %o",offset) : (void)snprintf(numstr,BUFSTRSIZE,"%o",offset);
// offset = ((operand & 0x0020)>>5) ? (char)((operand & 0x003F) | 0x00C0) : (operand & 0x003F);
// ((int)offset <0) ? (void)snprintf(numstr,BUFSTRSIZE,"SHR %o",-(int)offset) : (void)snprintf(numstr,BUFSTRSIZE,"%o",offset);
(void)snprintf(opstr,BUFSTRSIZE,"SAD %s%s",shtype_str[((operand & 0x0600) >> 9)],numstr);
break;
case 0160000: /* IOT */
(void)snprintf(opstr,BUFSTRSIZE,"IOT %o",(operand & 0x07ff));
break;
case 0164000: /* IOX */
(void)snprintf(opstr,BUFSTRSIZE,"IOX %o",(operand & 0x07ff));
break;
case 0170000: /* SAB */
(void)snprintf(opstr,BUFSTRSIZE,"SAB %s",numstr);
break;
case 0170400: /* SAA */
(void)snprintf(opstr,BUFSTRSIZE,"SAA %s",numstr);
break;
case 0171000: /* SAT */
(void)snprintf(opstr,BUFSTRSIZE,"SAT %s",numstr);
break;
case 0171400: /* SAX */
(void)snprintf(opstr,BUFSTRSIZE,"SAX %s",numstr);
break;
case 0172000: /* AAB */
(void)snprintf(opstr,BUFSTRSIZE,"AAB %s",numstr);
break;
case 0172400: /* AAA */
(void)snprintf(opstr,BUFSTRSIZE,"AAA %s",numstr);
break;
case 0173000: /* AAT */
(void)snprintf(opstr,BUFSTRSIZE,"AAT %s",numstr);
break;
case 0173400: /* AAX */
(void)snprintf(opstr,BUFSTRSIZE,"AAX %s",numstr);
break;
case 0174000: /* BSET ZRO */
case 0174200: /* BSET ONE */
case 0174400: /* BSET BCM */
case 0174600: /* BSET BAC */
case 0175000: /* BSKP ZRO */
case 0175200: /* BSKP ONE */
case 0175400: /* BSKP BCM */
case 0175600: /* BSKP BAC */
case 0176000: /* BSTC */
case 0176200: /* BSTA */
case 0176400: /* BLDC */
case 0176600: /* BLDA */
case 0177000: /* BANC */
case 0177200: /* BAND */
case 0177400: /* BORC */
case 0177600: /* BORA */
if (!(operand & 0x0007)) /* STS reg bits handling FIXME:: what if it is bit >7 & STS??*/
(void)snprintf(opstr,BUFSTRSIZE,"%s %s",bop_str[((operand & 0x0780) >> 7)],bopstsbit_str[((operand & 0x0078) >> 3)]);
else
(void)snprintf(opstr,BUFSTRSIZE,"%s %o D%s",bop_str[((operand & 0x0780) >> 7)],(int)(operand & 0x0078), regn[(operand & 0x0007)]);
break;
default: /* UNDEF */ /* Some ND instruction codes is undefined unfortunately. */
(void)snprintf(opstr,BUFSTRSIZE,"UNDEF");
break;
}
}
/* STZ
*/
void ndfunc_stz(ushort operand){
bool UseAPT;
ushort eff_addr;
eff_addr = New_GetEffectiveAddr(operand,&UseAPT);
MemoryWrite(0,eff_addr,UseAPT,2);
gPC++;
}
/* STA
*/
void ndfunc_sta(ushort operand){
bool UseAPT;
ushort eff_addr;
eff_addr = New_GetEffectiveAddr(operand,&UseAPT);
trace_step(1,"(%06o)<=A",(int)eff_addr);
MemoryWrite(gA,eff_addr,UseAPT,2);
gPC++;
}
/* STT
*/
void ndfunc_stt(ushort operand){
bool UseAPT;
ushort eff_addr;
eff_addr = New_GetEffectiveAddr(operand,&UseAPT);
MemoryWrite(gT,eff_addr,UseAPT,2);
gPC++;
}
/* STX
*/
void ndfunc_stx(ushort operand){
bool UseAPT;
ushort eff_addr;
eff_addr = New_GetEffectiveAddr(operand,&UseAPT);
MemoryWrite(gX,eff_addr,UseAPT,2);
gPC++;
}
/* STD
*/
void ndfunc_std(ushort operand){
bool UseAPT;
ushort eff_addr;
eff_addr = New_GetEffectiveAddr(operand,&UseAPT);
MemoryWrite(gA,eff_addr + 0,UseAPT,2);
MemoryWrite(gD,eff_addr + 1,UseAPT,2);
gPC++;
}
/* STF
*/
void ndfunc_stf(ushort operand){
bool UseAPT;
ushort eff_addr;
eff_addr = New_GetEffectiveAddr(operand,&UseAPT);
MemoryWrite(gT,eff_addr + 0,UseAPT,2);
MemoryWrite(gA,eff_addr + 1,UseAPT,2);
MemoryWrite(gD,eff_addr + 2,UseAPT,2);
gPC++;
}
/* STZTX
*/
void ndfunc_stztx(ushort operand){
ushort temp;
unsigned int fulladdress;
temp = (operand & 0x0038)>>3;
fulladdress = (((unsigned int)gT) <<16) | (ushort)(gX + temp);
PhysMemWrite(0,fulladdress);
/* TODO:: privilege check... */
gPC++;
}
/* STATX
*/
void ndfunc_statx(ushort operand){
ushort temp;
unsigned int fulladdress;
temp = (operand & 0x0038)>>3;
fulladdress = (((unsigned int)gT) <<16) | (ushort)(gX + temp);
PhysMemWrite(gA,fulladdress);
/* TODO:: privilege check... */
gPC++;
}
/* STDTX
*/
void ndfunc_stdtx(ushort operand){
ushort temp;
unsigned int fulladdress;
temp = (operand & 0x0038)>>3;
fulladdress = (((unsigned int)gT) <<16) | (ushort)(gX + temp);
PhysMemWrite(gA,fulladdress);
fulladdress++;
PhysMemWrite(gD,fulladdress);
/* TODO:: privilege check... */
gPC++;
}
/* LDA
*/
void ndfunc_lda(ushort operand){
if (trace) trace_pre(1,"A",(int)gA);
bool UseAPT;
ushort eff_addr;
eff_addr = New_GetEffectiveAddr(operand,&UseAPT);
gA = MemoryRead(eff_addr,UseAPT);
if (DISASM)
disasm_set_isdata(eff_addr);
trace_step(1,"A<=(%06o)",(int)eff_addr);
gPC++;
if (trace) trace_post(1,"A",(int)gA);
}
/* LDT
*/
void ndfunc_ldt(ushort operand){
if (trace) trace_pre(1,"T",(int)gT);
bool UseAPT;
ushort eff_addr;
eff_addr = New_GetEffectiveAddr(operand,&UseAPT);
gT = MemoryRead(eff_addr,UseAPT);
if (DISASM)
disasm_set_isdata(eff_addr);
gPC++;
if (trace) trace_post(1,"T",(int)gT);
}
/* LDX
*/
void ndfunc_ldx(ushort operand){
if (trace) trace_pre(1,"X",(int)gX);
bool UseAPT;
ushort eff_addr;
eff_addr = New_GetEffectiveAddr(operand,&UseAPT);
gX = MemoryRead(eff_addr,UseAPT);
if (DISASM)
disasm_set_isdata(eff_addr);
gPC++;
if (trace) trace_post(1,"X",(int)gX);
}
/* LDD
*/
void ndfunc_ldd(ushort operand){
if (trace) trace_pre(2,"A",(int)gA,"D",(int)gD);
bool UseAPT;
ushort eff_addr;
eff_addr = New_GetEffectiveAddr(operand,&UseAPT);
gA = MemoryRead(eff_addr + 0,UseAPT);
gD = MemoryRead(eff_addr + 1,UseAPT);
if (DISASM){
disasm_set_isdata(eff_addr+0);
disasm_set_isdata(eff_addr+1);
}
if (trace) trace_post(2,"A",(int)gA,"D",(int)gD);
gPC++;
}
/* LDF
*/
void ndfunc_ldf(ushort operand){
if (trace) trace_pre(3,"T",(int)gT,"A",(int)gA,"D",(int)gD);
bool UseAPT;
ushort eff_addr;
eff_addr = New_GetEffectiveAddr(operand,&UseAPT);
gT = MemoryRead(eff_addr + 0,UseAPT);
gA = MemoryRead(eff_addr + 1,UseAPT);
gD = MemoryRead(eff_addr + 2,UseAPT);
if (trace) trace_post(3,"T",(int)gT,"A",(int)gA,"D",(int)gD);
gPC++;
}
/* LDATX
*/
void ndfunc_ldatx(ushort operand){
ushort temp;
unsigned int fulladdress;
temp = (operand & 0x0038)>>3;
fulladdress = (((unsigned int)gT) <<16) | (ushort)(gX + temp);
gA = PhysMemRead(fulladdress);
/* TODO:: privilege check... */
gPC++;
}
/* LDXTX
*/
void ndfunc_ldxtx(ushort operand){
ushort temp;
unsigned int fulladdress;
temp = (operand & 0x0038)>>3;
fulladdress = (((unsigned int)gT) <<16) | (ushort)(gX + temp);
gX = PhysMemRead(fulladdress);
/* TODO:: privilege check... */
gPC++;
}
/* LDDTX
*/
void ndfunc_lddtx(ushort operand){
ushort temp;
unsigned int fulladdress;
temp = (operand & 0x0038)>>3;
fulladdress = (((unsigned int)gT) <<16) | (ushort)(gX + temp);
gA = PhysMemRead(fulladdress);
fulladdress++;
gD = PhysMemRead(fulladdress);
/* TODO:: privilege check... */
gPC++;
}
/* LDBTX
*/
void ndfunc_ldbtx(ushort operand){
ushort temp;
unsigned int fulladdress;
unsigned int result;
/* Bit odd instruction. See ND-06.014 section 3.3.10 */
/* "B: = 177000 ? ((EL) + (EL)) (? = inclusive OR)" */
temp = (operand & 0x0038)>>3;
fulladdress = (((unsigned int)gT) <<16) | (ushort)(gX + temp);
/* Ok, lets get all accesses now into temp variable */
temp = PhysMemRead(fulladdress);
result = temp + temp;
temp = PhysMemRead(result);
gB = 0177000 | temp;
/* TODO:: privilege check... */
gPC++;
}
/* MIN
*/
void ndfunc_min(ushort operand){
bool UseAPT;
ushort temp;
ushort eff_addr;
eff_addr = New_GetEffectiveAddr(operand,&UseAPT);
temp = MemoryRead(eff_addr,UseAPT);
temp++;
MemoryWrite(temp,eff_addr + 0,UseAPT,2);
if(0 == temp)
gPC ++; /* Next instruction is skipped */
gPC++;
}
/* ADD
*/
void ndfunc_add(ushort operand){
bool UseAPT;
ushort eff_word;
ushort eff_addr;
eff_addr = New_GetEffectiveAddr(operand,&UseAPT);
eff_word = MemoryRead(eff_addr,UseAPT);
gA = do_add(gA,eff_word,0);
gPC++;
}
/* SUB
*/
void ndfunc_sub(ushort operand){
bool UseAPT;
ushort eff_word;
ushort eff_addr;
eff_addr = New_GetEffectiveAddr(operand,&UseAPT);
eff_word = MemoryRead(eff_addr,UseAPT);
gA = do_add(gA,~eff_word,1);
gPC++;
}
/* AND
*/
void ndfunc_and(ushort operand){
bool UseAPT;
ushort eff_addr;
eff_addr = New_GetEffectiveAddr(operand,&UseAPT);
gA = gA & MemoryRead(eff_addr,UseAPT);
gPC++;
}
/* ORA
*/
void ndfunc_ora(ushort operand){
bool UseAPT;
ushort eff_addr;
eff_addr = New_GetEffectiveAddr(operand,&UseAPT);
gA = gA | MemoryRead(eff_addr,UseAPT);
gPC++;
}
/* FAD
*/
void ndfunc_fad(ushort operand){
bool UseAPT;
ushort eff_addr;
ushort a[3], b[3], r[3];
int res;
eff_addr = New_GetEffectiveAddr(operand,&UseAPT);
a[0] = gT;
a[1] = gA;
a[2] = gD;
b[0] = MemoryRead(eff_addr + 0,UseAPT);
b[1] = MemoryRead(eff_addr + 1,UseAPT);
b[2] = MemoryRead(eff_addr + 2,UseAPT);
if (trace) trace_pre(3,"T",(int)gT,"A",(int)gA,"D",(int)gD);
if (trace) trace_pre(3,"a+0",(int)b[0],"a+1",(int)b[1],"a+2",(int)b[2]);
res=NDFloat_Add(a,b,r);
gT = r[0];
gA = r[1];
gD = r[2];
if (res == -1)
setbit(_STS,_TG,1);
if (trace) trace_post(3,"T",(int)gT,"A",(int)gA,"D",(int)gD);
gPC++;
}
/* FSB
*/
void ndfunc_fsb(ushort operand){
bool UseAPT;
ushort eff_addr;
ushort a[3], b[3], r[3];
eff_addr = New_GetEffectiveAddr(operand,&UseAPT);
b[0] = gT;
a[0] = gT;
a[1] = gA;
a[2] = gD;
b[0] = MemoryRead(eff_addr + 0,UseAPT);