-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkb11.cpp
935 lines (881 loc) · 24.6 KB
/
kb11.cpp
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
#include <cstdlib>
//#include <sched.h>
#include <setjmp.h>
#include <stdint.h>
#include <stdio.h>
//#include <unistd.h>
#include <Arduino.h>
#include "bootrom.h"
#include "kb11.h"
/*
***** Update 1/3/2023 ISS *****
* This update resolves a fundamental design flaw which placed the
* CPU registers at an arbirary and umappped location in the IOPAGE.
* Due to the fact that any instruction can reference either a register directly eg INC R0
* or, using a register as an address (with optional indirection) eg INC (R0), with only 16 bits of address
* being passed to the read/write routines, a method of determining if the operand is a register
* or an address is required. The minimal implmentation of this is the use of rflag to indicate
* if an operand is a register or a memory address. This is set if the destination is a register and cleared if not.
* The flag is cleared at the beginning of each CPU step and set in DA(...).
*/
void disasm(uint32_t ia);
void fp11(int32 IR);
void KB11::reset(uint16_t start,int bootdev) {
unibus.reset();
for (auto i = 0; i < 29; i++) {
unibus.write16(02000 + (i * 2), bootrom[i]);
}
if (bootdev)
unibus.rl11.loadboot(); // Overlay RK05 boot
R[7] = start;
stacklimit = 0xff;
switchregister = 0173030;
switchregister = 0;
wtstate = false;
}
inline uint16_t KB11::read16(const uint16_t va) {
uint32_t tm;
auto a = tm = mmu.decode<false>(va, currentmode());
if (!(mmu.SR[3] & 020))
a |= 017000000;
if ((a & 017777760) == 017777700)
return R[(a & 017) >> 1];
switch (a) {
case 017777776:
return PSW;
case 017777774:
return stacklimit;
case 017777570:
return switchregister;
default:
return unibus.read16(tm);
}
}
inline void KB11::write16(const uint16_t va, const uint16_t v) {
uint32_t tm;
auto a = tm = mmu.decode<true>(va, currentmode());
if (!(mmu.SR[3] & 020))
a |= 017000000;
if ((a & 017777760) == 017777700)
{
R[(a & 017) >> 1] = v;
return;
}
switch (a) {
case 017777776:
stackpointer[currentmode()] = R[6];
writePSW(v & ~020);
R[6] = stackpointer[currentmode()];
break;
case 017777774:
stacklimit = v;
break;
case 017777570:
displayregister = v;
break;
default:
unibus.write16(tm, v);
}
}
// ADD 06SSDD
void KB11::ADD(const uint16_t instr) {
const auto src = SS<2>(instr);
const auto da = DA<2>(instr);
const auto dst = read<2>(da);
const auto sum = src + dst;
write<2>(da, sum);
PSW &= 0xFFF0;
setNZ<2>(sum);
if (((~src ^ dst) & (src ^ sum)) & 0x8000) {
PSW |= FLAGV;
}
if ((int32_t(src) + int32_t(dst)) > 0xFFFF) {
PSW |= FLAGC;
}
}
// SUB 16SSDD
void KB11::SUB(const uint16_t instr) {
const auto val1 = SS<2>(instr);
const auto da = DA<2>(instr);
const auto val2 = read<2>(da);
const auto uval = (val2 - val1) & 0xFFFF;
PSW &= 0xFFF0;
write<2>(da, uval);
setNZ<2>(uval);
if (((val1 ^ val2) & (~val1 ^ uval)) & 0x8000) {
PSW |= FLAGV;
}
if (val1 > val2) {
PSW |= FLAGC;
}
}
// MUL 070RSS
void KB11::MUL(const uint16_t instr) {
const auto reg = (instr >> 6) & 7;
int32_t val1 = R[reg];
if (val1 & 0x8000) {
val1 = -((0xFFFF ^ val1) + 1);
}
int32_t val2 = read<2>(DA<2>(instr));
if (val2 & 0x8000) {
val2 = -((0xFFFF ^ val2) + 1);
}
int sval = val1 * val2;
R[reg] = sval >> 16;
R[reg | 1] = sval & 0xFFFF;
PSW &= 0xFFF0;
if (sval < 0) {
PSW |= FLAGN;
}
if (sval == 0) {
PSW |= FLAGZ;
}
if ((sval < -(1 << 15)) || (sval >= ((1L << 15) - 1))) {
PSW |= FLAGC;
}
}
void KB11::DIV(const uint16_t instr) {
const auto reg = (instr >> 6) & 7;
const int32_t val1 = (R[reg] << 16) | (R[reg | 1]);
int32_t val2 = read<2>(DA<2>(instr));
PSW &= 0xFFF0;
if (val2 > 32767)
val2 |= 0xffff0000;
if (val2 == 0) {
PSW |= FLAGC | FLAGV;
return;
}
if ((val1 / val2) >= 0x10000) {
PSW |= FLAGV;
return;
}
R[reg] = (val1 / val2) & 0xFFFF;
R[reg | 1] = (val1 % val2) & 0xFFFF;
if (R[reg] == 0) {
PSW |= FLAGZ;
}
if (R[reg] & 0100000) {
PSW |= FLAGN;
}
}
void KB11::ASH(const uint16_t instr) {
const auto reg = (instr >> 6) & 7;
const auto val1 = R[reg];
auto val2 = read<2>(DA<2>(instr)) & 077;
PSW &= 0xFFF0;
int32_t sval = val1;
if (val2 & 040) {
val2 = 0100 - val2;
if (sval & 0100000)
sval |= 0xffff0000;
sval = sval << 1;
sval = sval >> val2;
if (sval & 1)
PSW |= FLAGC;
sval = sval >> 1;
}
else {
uint32_t msk = 0xffff << val2;
sval = sval << val2;
if (sval & 0xffff0000)
if ((sval & 0xffff0000) != (msk & 0xffff0000))
PSW |= FLAGV;
if ((sval & 0x8000) != (val1 & 0x8000))
PSW |= FLAGV;
if (sval & 0200000)
PSW |= FLAGC;
}
sval &= 0xffff;
R[reg & 7] = sval;
setZ(sval == 0);
if (sval & 0100000) {
PSW |= FLAGN;
}
}
void KB11::ASHC(const uint16_t instr) {
const auto reg = (instr >> 6) & 7;
const auto val1 = ((uint32_t)(R[reg]) << 16) | (uint32_t)R[reg | 1];
auto val2 = read<2>(DA<2>(instr)) & 077;
PSW &= 0xFFF0;
uint64_t msk;
int64_t sval = (int)val1;
if (val2 == 0) {
setZ((sval & 0xffffffff) == 0);
if (sval & 0x80000000)
PSW |= FLAGN;
return;
}
if (val2 & 040)
{
val2 = 0100 - val2;
msk = ((uint64_t)1 << (val2 - 1));
sval = sval >> val2;
if ((val1 & msk) && val2)
PSW |= FLAGC;
}
else
{
sval = sval << val2;
msk = 0x100000000 >> val2;
if ((val1 & msk) && val2)
PSW |= FLAGC;
}
if ((sval & 0x80000000) != (val1 & 0x80000000))
PSW |= FLAGV;
R[reg & 7] = (sval >> 16) & 0xFFFF;
R[(reg & 7) | 1] = sval & 0xFFFF;
setZ((sval & 0xffffffff) == 0);
if (sval & 0x80000000)
PSW |= FLAGN;
}
// XOR 064RDD
void KB11::XOR(const uint16_t instr) {
const auto reg = R[(instr >> 6) & 7];
const auto da = DA<2>(instr);
const auto dst = reg ^ read<2>(da);
write<2>(da, dst);
setNZ<2>(dst);
}
// SOB 077RNN
void KB11::SOB(const uint16_t instr) {
const auto reg = (instr >> 6) & 7;
R[reg]--;
if (R[reg]) {
R[7] -= (instr & 077) << 1;
}
}
void KB11::FIS(const uint16_t instr)
{
union fltint {
uint32_t xint;
float xflt;
};
uint32_t arg1, arg2;
fltint bfr;
uint16_t adr = R[instr & 7]; // Base address from specfied reg
float op1, op2;
arg1 = bfr.xint = read<2>(adr + 6) | (read<2>(adr + 4) << 16);
op1 = bfr.xflt;
arg2 = bfr.xint = read<2>(adr + 2) | (read<2>(adr) << 16);
op2 = bfr.xflt;
PSW &= ~(FLAGN | FLAGV | FLAGZ | FLAGC);
switch (instr & 070) {
case 0: // FADD
bfr.xflt = op1 + op2;
break;
case 010:
bfr.xflt = op1 - op2;
break;
case 020:
bfr.xflt = (op1 * op2) / 4.0f;
break;
case 030:
if (op2 == 0.0) {
PSW |= (FLAGN | FLAGV | FLAGC);
trap(INTFIS);
}
bfr.xflt = (op1 / op2) * 4.0f;
break;
}
R[instr & 7] += 4;
if (bfr.xflt == 0.0)
PSW |= FLAGZ;
if (bfr.xflt < 0.0)
PSW |= FLAGN;
write<2>(adr + 4, bfr.xint >> 16);
write<2>(adr + 6, bfr.xint);
}
// MTPS
void KB11::MTPS(const uint16_t instr)
{
const auto da = DA<1>(instr);
auto src = read<1>(da);
PSW = (PSW & 0177400) | src & 0357;
}
// MFPS
void KB11::MFPS(const uint16_t instr)
{
const auto da = DA<1>(instr);
auto dst = PSW & 0357;
if (PSW & msb<1>() && ((instr & 030) == 0)) {
dst |= 0177400;
write<2>(da, dst);
}
else
write<1>(da, dst);
setNZ<1>(PSW & 0377);
}
// JSR 004RDD
void KB11::JSR(const uint16_t instr) {
if (((instr >> 3) & 7) == 0) {
trap(INTBUS);
}
const auto dst = DA<2>(instr);
const auto reg = (instr >> 6) & 7;
push(R[reg]);
R[reg] = R[7];
R[7] = dst;
}
// JMP 0001DD
void KB11::JMP(const uint16_t instr) {
if (((instr >> 3) & 7) == 0) {
// Registers don't have a virtual address so trap!
//Serial.printf("JMP called on register\n");
//printstate();
trap(INTBUS);
//std::abort();
} else
R[7] = DA<2>(instr);
}
// MARK 0064NN
void KB11::MARK(const uint16_t instr) {
R[6] = R[7] + ((instr & 077) << 1);
R[7] = R[5];
R[5] = pop();
}
// MFPI 0065SS
void KB11::MFPI(const uint16_t instr) {
uint16_t uval;
if (!(instr & 0x38)) {
const auto reg = instr & 7;
if ((reg != 6) || (currentmode() == previousmode())) {
uval = R[reg];
}
else {
uval = stackpointer[previousmode()];
}
}
else {
const auto da = DA<2>(instr);
uval = unibus.read16(mmu.decode<false>(da, previousmode()));
}
push(uval);
setNZ<2>(uval);
}
// MTPI 0066DD
void KB11::MTPI(const uint16_t instr) {
const auto uval = pop();
if (!(instr & 0x38)) {
const auto reg = instr & 7;
if ((reg != 6) || (currentmode() == previousmode())) {
R[reg] = uval;
} else {
stackpointer[previousmode()] = uval;
}
} else {
const auto da = DA<2>(instr);
unibus.write16(mmu.decode<true>(da, previousmode()), uval);
}
setNZ<2>(uval);
}
// RTS 00020R
void KB11::RTS(const uint16_t instr) {
const auto reg = instr & 7;
R[7] = R[reg];
R[reg] = pop();
}
// MFPT 000007
void KB11::MFPT() {
trap(010); // not a PDP11/44
}
// RTI 000004, RTT 000006
void KB11::RTT() {
R[7] = pop();
auto psw = pop();
psw &= 0xf8ff;
if (currentmode()) { // user / super restrictions
// keep SPL and allow lower only for modes and register set
//psw = (PSW & 0xf81f) | (psw & 0xf8e0);
psw = (PSW & 0177760) | (psw & 017);
}
writePSW(psw);
if (R[7] == 0)
R[7] = R[7];
}
void KB11::WAIT() {
if (currentmode())
return;
wtstate = true;
}
void KB11::RESET() {
if (currentmode()) {
// RESET is ignored outside of kernel mode
return;
}
unibus.reset();
}
// SWAB 0003DD
void KB11::SWAB(const uint16_t instr) {
const auto da = DA<2>(instr);
auto dst = read<2>(da);
dst = (dst << 8) | (dst >> 8);
write<2>(da, dst);
PSW &= 0xFFF0;
if ((dst & 0xff) == 0) {
PSW |= FLAGZ;
}
if (dst & 0x80) {
PSW |= FLAGN;
}
}
// SXT 0067DD
void KB11::SXT(const uint16_t instr) {
if (N()) {
write<2>(DA<2>(instr), 0xffff);
PSW &= ~FLAGZ;
} else {
write<2>(DA<2>(instr), 0);
PSW |= FLAGZ;
}
PSW &= ~FLAGV;
}
void KB11::step() {
PC = R[7];
rflag = 0;
if (print)
printstate();
const auto instr = fetch16();
if (!(mmu.SR[0] & 0160000)) {
mmu.SR[2] = PC;
mmu.SR[0] |= 0200;
}
switch (instr >> 12) { // xxSSDD Mostly double operand instructions
case 0: // 00xxxx mixed group
switch (instr >> 8) { // 00xxxx 8 bit instructions first (branch & JSR)
case 0: // 000xXX Misc zero group
switch (instr >> 6) { // 000xDD group (4 case full decode)
case 0: // 0000xx group
switch (instr) {
case 0: // HALT 000000
if (currentmode()) {
trap(010);
}
Serial.printf("HALT: DR: %06o\r\n", displayregister);
printstate();
ESP.restart();
return;
case 1: // WAIT 000001
WAIT();
return;
case 3: // BPT 000003
trap(014); // Trap 14 - BPT
return;
case 4: // IOT 000004
trap(020);
return;
case 5: // RESET 000005
RESET();
return;
case 2: // RTI 000002
case 6: // RTT 000006
RTT();
return;
case 7: // MFPT
MFPT();
return;
default: // We don't know this 0000xx instruction
Serial.printf("unknown 0000xx instruction\n");
printstate();
trap(INTINVAL);
return;
}
case 1: // JMP 0001DD
JMP(instr);
return;
case 2: // 00002xR single register group
switch ((instr >> 3) & 7) { // 00002xR register or CC
case 0: // RTS 00020R
RTS(instr);
return;
case 3: // SPL 00023N
if (currentmode())
trap(010);
PSW = ((PSW & 0xf81f) | ((instr & 7) << 5));
return;
case 4: // CLR CC 00024C Part 1 without N
case 5: // CLR CC 00025C Part 2 with N
PSW = (PSW & ~(instr & 017));
return;
case 6: // SET CC 00026C Part 1 without N
case 7: // SET CC 00027C Part 2 with N
PSW = (PSW | (instr & 017));
return;
default: // We don't know this 00002xR instruction
Serial.printf("unknown 0002xR instruction\n");
printstate();
trap(INTINVAL);
return;
}
case 3: // SWAB 0003DD
SWAB(instr);
return;
default:
Serial.printf("unknown 000xDD instruction\n");
printstate();
trapat(INTINVAL);
return;
}
case 1: // BR 0004 offset
branch(instr);
return;
case 2: // BNE 0010 offset
if (!Z()) {
branch(instr);
}
return;
case 3: // BEQ 0014 offset
if (Z()) {
branch(instr);
}
return;
case 4: // BGE 0020 offset
if (!(N() xor V())) {
branch(instr);
}
return;
case 5: // BLT 0024 offset
if (N() xor V()) {
branch(instr);
}
return;
case 6: // BGT 0030 offset
if ((!(N() xor V())) && (!Z())) {
branch(instr);
}
return;
case 7: // BLE 0034 offset
if ((N() xor V()) || Z()) {
branch(instr);
}
return;
case 8: // JSR 004RDD In two parts
case 9: // JSR 004RDD continued (9 bit instruction so use 2 x 8 bit
JSR(instr);
return;
default: // Remaining 0o00xxxx instructions where xxxx >= 05000
switch (instr >> 6) { // 00xxDD
case 050: // CLR 0050DD
CLR<2>(instr);
return;
case 051: // COM 0051DD
COM<2>(instr);
return;
case 052: // INC 0052DD
INC<2>(instr);
return;
case 053: // DEC 0053DD
_DEC<2>(instr);
return;
case 054: // NEG 0054DD
NEG<2>(instr);
return;
case 055: // ADC 0055DD
_ADC<2>(instr);
return;
case 056: // SBC 0056DD
SBC<2>(instr);
return;
case 057: // TST 0057DD
TST<2>(instr);
return;
case 060: // ROR 0060DD
ROR<2>(instr);
return;
case 061: // ROL 0061DD
ROL<2>(instr);
return;
case 062: // ASR 0062DD
ASR<2>(instr);
return;
case 063: // ASL 0063DD
ASL<2>(instr);
return;
case 064: // MARK 0064nn
MARK(instr);
return;
case 065: // MFPI 0065SS
MFPI(instr);
return;
case 066: // MTPI 0066DD
MTPI(instr);
return;
case 067: // SXT 0067DD
SXT(instr);
return;
default: // We don't know this 0o00xxDD instruction
Serial.printf("unknown 00xxDD instruction\n");
printstate();
trapat(INTINVAL);
return;
}
}
case 1: // MOV 01SSDD
MOV<2>(instr);
return;
case 2: // CMP 02SSDD
CMP<2>(instr);
return;
case 3: // BIT 03SSDD
SBIT<2>(instr);
return;
case 4: // BIC 04SSDD
BIC<2>(instr);
return;
case 5: // BIS 05SSDD
BIS<2>(instr);
return;
case 6: // ADD 06SSDD
ADD(instr);
return;
case 7: // 07xRSS instructions
switch ((instr >> 9) & 7) { // 07xRSS
case 0: // MUL 070RSS
MUL(instr);
return;
case 1: // DIV 071RSS
DIV(instr);
return;
case 2: // ASH 072RSS
ASH(instr);
return;
case 3: // ASHC 073RSS
ASHC(instr);
return;
case 4: // XOR 074RSS
XOR(instr);
return;
case 5: // FIS
FIS(instr);
return;
case 6:
//Serial.printf("Invalid instruction:%06o\r\n",instr);
trap(INTINVAL);
case 7: // SOB 077Rnn
SOB(instr);
return;
default: // We don't know this 07xRSS instruction
Serial.printf("unknown 07xRSS instruction\n");
printstate();
trapat(INTINVAL);
return;
}
case 8: // 10xxxx instructions
switch ((instr >> 8) & 0xf) { // 10xxxx 8 bit instructions first
case 0: // BPL 1000 offset
if (!N()) {
branch(instr);
}
return;
case 1: // BMI 1004 offset
if (N()) {
branch(instr);
}
return;
case 2: // BHI 1010 offset
if ((!C()) && (!Z())) {
branch(instr);
}
return;
case 3: // BLOS 1014 offset
if (C() || Z()) {
branch(instr);
}
return;
case 4: // BVC 1020 offset
if (!V()) {
branch(instr);
}
return;
case 5: // BVS 1024 offset
if (V()) {
branch(instr);
}
return;
case 6: // BCC 1030 offset
if (!C()) {
branch(instr);
}
return;
case 7: // BCS 1034 offset
if (C()) {
branch(instr);
}
return;
case 8: // EMT 1040 operand
trap(030); // Trap 30 - EMT instruction
case 9: // TRAP 1044 operand
trap(034); // Trap 34 - TRAP instruction
default: // Remaining 10xxxx instructions where xxxx >= 05000
switch ((instr >> 6) & 077) { // 10xxDD group
case 050: // CLRB 1050DD
CLR<1>(instr);
return;
case 051: // COMB 1051DD
COM<1>(instr);
return;
case 052: // INCB 1052DD
INC<1>(instr);
return;
case 053: // DECB 1053DD
_DEC<1>(instr);
return;
case 054: // NEGB 1054DD
NEG<1>(instr);
return;
case 055: // ADCB 01055DD
_ADC<1>(instr);
return;
case 056: // SBCB 01056DD
SBC<1>(instr);
return;
case 057: // TSTB 1057DD
TST<1>(instr);
return;
case 060: // RORB 1060DD
ROR<1>(instr);
return;
case 061: // ROLB 1061DD
ROL<1>(instr);
return;
case 062: // ASRB 1062DD
ASR<1>(instr);
return;
case 063: // ASLB 1063DD
ASL<1>(instr);
return;
case 064: // MTPS 1064SS
MTPS(instr);
return;
case 067: // MFPS 106700
MFPS(instr);
return;
case 065:
MFPI(instr);
return;
case 066:
MTPI(instr);
return;
// case 0o65: // MFPD 1065DD
// case 0o66: // MTPD 1066DD
// case 0o67: // MTFS 1064SS
default: // We don't know this 0o10xxDD instruction
Serial.printf("unknown 0o10xxDD instruction\n");
printstate();
trapat(INTINVAL);
return;
}
}
case 9: // MOVB 11SSDD
MOV<1>(instr);
return;
case 10: // CMPB 12SSDD
CMP<1>(instr);
return;
case 11: // BITB 13SSDD
SBIT<1>(instr);
return;
case 12: // BICB 14SSDD
BIC<1>(instr);
return;
case 13: // BISB 15SSDD
BIS<1>(instr);
return;
case 14: // SUB 16SSDD
SUB(instr);
return;
case 15:
fp11(instr);
return;
Serial.printf("invalid 17xxxx FPP instruction\n");
printstate();
trap(INTINVAL);
break;
[[fallthrough]];
default: // 15 17xxxx FPP instructions
//Serial.printf("invalid 17xxxx FPP instruction\n");
//return;
//printstate();
trap(INTINVAL);
}
}
void KB11::interrupt(uint8_t vec, uint8_t pri) {
if (vec & 1) {
printf("Thou darst calling interrupt() with an odd vector number?\n");
std::abort();
}
wtstate = false;
// fast path
if (itab[0].vec == 0) {
itab[0].vec = vec;
itab[0].pri = pri;
return;
}
uint8_t i = 0;
for (i = 0; i < itab.size(); i++)
if (itab[1].vec == vec && itab[i].pri == pri)
return;
i = 0;
while (itab[i].pri > pri)
i++;
for (uint8_t j = itab.size() - 1; j > i; j--) {
itab[j] = itab[j - 1];
}
itab[i].vec = vec;
itab[i].pri = pri;
if (i >= itab.size()) {
printf("interrupt table full:%d\n", i);
for (i = 0; i < itab.size(); i++)
printf("%o %d:%d\r\n", itab[i].vec, i, itab.size());
std::abort();
}
}
// pop the top interrupt off the itab.
void KB11::popirq() {
for (uint8_t i = 0; i < itab.size() - 1; i++) {
itab[i] = itab[i + 1];
}
itab[itab.size() - 1].vec = 0;
itab[itab.size() - 1].pri = 0;
wtstate = false;
}
void KB11::trapat(uint16_t vec) {
if (vec & 1) {
Serial.printf("Thou darst calling trapat() with an odd vector number?\n");
std::abort();
}
//Serial.printf("trap: vec: %03o pc:%06o\r\n", vec, R[7]);
auto opsw = PSW;
auto npsw = unibus.read16(mmu.decode<false>(vec, 0) + 2);
writePSW(npsw | (currentmode() << 12));
push(opsw);
push(R[7]);
R[7] = unibus.read16(mmu.decode<false>(vec, 0)); // Get from K-apace
wtstate = false;
}
void KB11::printstate() {
ptstate();
return;
Serial.printf("R0 %06o R1 %06o R2 %06o R3 %06o R4 %06o R5 %06o R6 %06o R7 "
"%06o\r\n",
R[0], R[1], R[2], R[3], R[4], R[5], R[6], R[7]);
Serial.printf("[%s%s%s%s%s%s", previousmode() ? "u" : "k",
currentmode() ? "U" : "K", N() ? "N" : " ", Z() ? "Z" : " ",
V() ? "V" : " ", C() ? "C" : " ");
Serial.printf("] instr %06o: %06o\t ", PC, read16(PC));
disasm(PC);
Serial.printf(" PSW:%06o\r\n",PSW);
}
void KB11::ptstate() {
Serial.printf("R0 %06o R1 %06o R2 %06o R3 %06o R4 %06o R5 %06o R6 %06o R7 %06o\r\n",
uint16_t(R[0]), uint16_t(R[1]), uint16_t(R[2]), uint16_t(R[3]), uint16_t(R[4]), uint16_t(R[5]), uint16_t(R[6]), uint16_t(R[7]));
Serial.printf("[%s%s%s%s%s%s",
PSW & 0140000 ? "U" : "K",
PSW & 0030000 ? "U" : "K",
N() ? "N" : " ",
Z() ? "Z" : " ",
V() ? "V" : " ",
C() ? "C" : " ");
Serial.printf("] instr %06o: %06o\t ", PC, read16(PC));
disasm(PC);
Serial.printf(" PS:%o\r\n", PSW);
}