Skip to content

Commit ae5b269

Browse files
getGAM is always called with rm_cur
1 parent ba67467 commit ae5b269

File tree

2 files changed

+58
-58
lines changed

2 files changed

+58
-58
lines changed

cpu.cpp

+57-57
Original file line numberDiff line numberDiff line change
@@ -477,9 +477,9 @@ void cpu::addToMMR1(const gam_rc_t & g)
477477
}
478478

479479
// GAM = general addressing modes
480-
gam_rc_t cpu::getGAM(const uint8_t mode, const uint8_t reg, const word_mode_t word_mode, const rm_selection_t mode_selection, const bool read_value)
480+
gam_rc_t cpu::getGAM(const uint8_t mode, const uint8_t reg, const word_mode_t word_mode, const bool read_value)
481481
{
482-
gam_rc_t g { word_mode, mode_selection, i_space, mode, { }, { }, { }, { } };
482+
gam_rc_t g { word_mode, rm_cur, i_space, mode, { }, { }, { }, { } };
483483

484484
d_i_space_t isR7_space = reg == 7 ? i_space : (b->getMMU()->get_use_data_space(getPSW_runmode()) ? d_space : i_space);
485485
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ always d_space here? TODO
@@ -491,60 +491,60 @@ gam_rc_t cpu::getGAM(const uint8_t mode, const uint8_t reg, const word_mode_t wo
491491
switch(mode) {
492492
case 0: // Rn
493493
g.reg = reg;
494-
g.value = getRegister(reg, mode_selection) & (word_mode == wm_byte ? 0xff : 0xffff);
494+
g.value = getRegister(reg, rm_cur) & (word_mode == wm_byte ? 0xff : 0xffff);
495495
break;
496496
case 1: // (Rn)
497-
g.addr = getRegister(reg, mode_selection);
497+
g.addr = getRegister(reg, rm_cur);
498498
if (read_value)
499-
g.value = b->read(g.addr.value(), word_mode, mode_selection, isR7_space);
499+
g.value = b->read(g.addr.value(), word_mode, rm_cur, isR7_space);
500500
break;
501501
case 2: // (Rn)+ / #n
502-
g.addr = getRegister(reg, mode_selection);
502+
g.addr = getRegister(reg, rm_cur);
503503
if (read_value)
504-
g.value = b->read(g.addr.value(), word_mode, mode_selection, isR7_space);
505-
addRegister(reg, mode_selection, word_mode == wm_word || reg == 7 || reg == 6 ? 2 : 1);
504+
g.value = b->read(g.addr.value(), word_mode, rm_cur, isR7_space);
505+
addRegister(reg, rm_cur, word_mode == wm_word || reg == 7 || reg == 6 ? 2 : 1);
506506
g.mmr1_update = { word_mode == wm_word || reg == 7 || reg == 6 ? 2 : 1, reg };
507507
break;
508508
case 3: // @(Rn)+ / @#a
509-
g.addr = b->read(getRegister(reg, mode_selection), wm_word, mode_selection, isR7_space);
509+
g.addr = b->read(getRegister(reg, rm_cur), wm_word, rm_cur, isR7_space);
510510
// might be wrong: the adds should happen when the read is really performed, because of traps
511-
addRegister(reg, mode_selection, 2);
511+
addRegister(reg, rm_cur, 2);
512512
g.mmr1_update = { 2, reg };
513513
g.space = d_space;
514514
if (read_value)
515-
g.value = b->read(g.addr.value(), word_mode, mode_selection, g.space);
515+
g.value = b->read(g.addr.value(), word_mode, rm_cur, g.space);
516516
break;
517517
case 4: // -(Rn)
518-
addRegister(reg, mode_selection, word_mode == wm_word || reg == 7 || reg == 6 ? -2 : -1);
518+
addRegister(reg, rm_cur, word_mode == wm_word || reg == 7 || reg == 6 ? -2 : -1);
519519
g.mmr1_update = { word_mode == wm_word || reg == 7 || reg == 6 ? -2 : -1, reg };
520520
g.space = d_space;
521-
g.addr = getRegister(reg, mode_selection);
521+
g.addr = getRegister(reg, rm_cur);
522522
if (read_value)
523-
g.value = b->read(g.addr.value(), word_mode, mode_selection, isR7_space);
523+
g.value = b->read(g.addr.value(), word_mode, rm_cur, isR7_space);
524524
break;
525525
case 5: // @-(Rn)
526-
addRegister(reg, mode_selection, -2);
526+
addRegister(reg, rm_cur, -2);
527527
g.mmr1_update = { -2, reg };
528-
g.addr = b->read(getRegister(reg, mode_selection), wm_word, mode_selection, isR7_space);
528+
g.addr = b->read(getRegister(reg, rm_cur), wm_word, rm_cur, isR7_space);
529529
g.space = d_space;
530530
if (read_value)
531-
g.value = b->read(g.addr.value(), word_mode, mode_selection, g.space);
531+
g.value = b->read(g.addr.value(), word_mode, rm_cur, g.space);
532532
break;
533533
case 6: // x(Rn) / a
534-
next_word = b->read(getPC(), wm_word, mode_selection, i_space);
535-
addRegister(7, mode_selection, + 2);
536-
g.addr = getRegister(reg, mode_selection) + next_word;
534+
next_word = b->read(getPC(), wm_word, rm_cur, i_space);
535+
addRegister(7, rm_cur, + 2);
536+
g.addr = getRegister(reg, rm_cur) + next_word;
537537
g.space = d_space;
538538
if (read_value)
539-
g.value = b->read(g.addr.value(), word_mode, mode_selection, g.space);
539+
g.value = b->read(g.addr.value(), word_mode, rm_cur, g.space);
540540
break;
541541
case 7: // @x(Rn) / @a
542-
next_word = b->read(getPC(), wm_word, mode_selection, i_space);
543-
addRegister(7, mode_selection, + 2);
544-
g.addr = b->read(getRegister(reg, mode_selection) + next_word, wm_word, mode_selection, d_space);
542+
next_word = b->read(getPC(), wm_word, rm_cur, i_space);
543+
addRegister(7, rm_cur, + 2);
544+
g.addr = b->read(getRegister(reg, rm_cur) + next_word, wm_word, rm_cur, d_space);
545545
g.space = d_space;
546546
if (read_value)
547-
g.value = b->read(g.addr.value(), word_mode, mode_selection, g.space);
547+
g.value = b->read(g.addr.value(), word_mode, rm_cur, g.space);
548548
break;
549549
}
550550

@@ -570,7 +570,7 @@ bool cpu::putGAM(const gam_rc_t & g, const uint16_t value)
570570

571571
gam_rc_t cpu::getGAMAddress(const uint8_t mode, const int reg, const word_mode_t word_mode)
572572
{
573-
return getGAM(mode, reg, word_mode, rm_cur, false);
573+
return getGAM(mode, reg, word_mode, false);
574574
}
575575

576576
bool cpu::double_operand_instructions(const uint16_t instr)
@@ -599,7 +599,7 @@ bool cpu::double_operand_instructions(const uint16_t instr)
599599

600600
switch(operation) {
601601
case 0b001: { // MOV/MOVB Move Word/Byte
602-
gam_rc_t g_src = getGAM(src_mode, src_reg, word_mode, rm_cur);
602+
gam_rc_t g_src = getGAM(src_mode, src_reg, word_mode);
603603

604604
bool set_flags = true;
605605

@@ -621,9 +621,9 @@ bool cpu::double_operand_instructions(const uint16_t instr)
621621
}
622622

623623
case 0b010: { // CMP/CMPB Compare Word/Byte
624-
gam_rc_t g_src = getGAM(src_mode, src_reg, word_mode, rm_cur);
624+
gam_rc_t g_src = getGAM(src_mode, src_reg, word_mode);
625625

626-
auto g_dst = getGAM(dst_mode, dst_reg, word_mode, rm_cur);
626+
auto g_dst = getGAM(dst_mode, dst_reg, word_mode);
627627

628628
addToMMR1(g_dst);
629629
addToMMR1(g_src);
@@ -639,9 +639,9 @@ bool cpu::double_operand_instructions(const uint16_t instr)
639639
}
640640

641641
case 0b011: { // BIT/BITB Bit Test Word/Byte
642-
gam_rc_t g_src = getGAM(src_mode, src_reg, word_mode, rm_cur);
642+
gam_rc_t g_src = getGAM(src_mode, src_reg, word_mode);
643643

644-
auto g_dst = getGAM(dst_mode, dst_reg, word_mode, rm_cur);
644+
auto g_dst = getGAM(dst_mode, dst_reg, word_mode);
645645

646646
addToMMR1(g_dst);
647647
addToMMR1(g_src);
@@ -654,7 +654,7 @@ bool cpu::double_operand_instructions(const uint16_t instr)
654654
}
655655

656656
case 0b100: { // BIC/BICB Bit Clear Word/Byte
657-
gam_rc_t g_src = getGAM(src_mode, src_reg, word_mode, rm_cur);
657+
gam_rc_t g_src = getGAM(src_mode, src_reg, word_mode);
658658

659659
if (dst_mode == 0) {
660660
addToMMR1(g_src); // keep here because of order of updates
@@ -667,7 +667,7 @@ bool cpu::double_operand_instructions(const uint16_t instr)
667667
setPSW_flags_nzv(result, word_mode);
668668
}
669669
else {
670-
auto g_dst = getGAM(dst_mode, dst_reg, word_mode, rm_cur);
670+
auto g_dst = getGAM(dst_mode, dst_reg, word_mode);
671671

672672
addToMMR1(g_dst);
673673
addToMMR1(g_src);
@@ -682,7 +682,7 @@ bool cpu::double_operand_instructions(const uint16_t instr)
682682
}
683683

684684
case 0b101: { // BIS/BISB Bit Set Word/Byte
685-
gam_rc_t g_src = getGAM(src_mode, src_reg, word_mode, rm_cur);
685+
gam_rc_t g_src = getGAM(src_mode, src_reg, word_mode);
686686

687687
if (dst_mode == 0) {
688688
addToMMR1(g_src); // keep here because of order of updates
@@ -697,7 +697,7 @@ bool cpu::double_operand_instructions(const uint16_t instr)
697697
setPSW_v(false);
698698
}
699699
else {
700-
auto g_dst = getGAM(dst_mode, dst_reg, word_mode, rm_cur);
700+
auto g_dst = getGAM(dst_mode, dst_reg, word_mode);
701701

702702
addToMMR1(g_dst);
703703
addToMMR1(g_src);
@@ -715,9 +715,9 @@ bool cpu::double_operand_instructions(const uint16_t instr)
715715
}
716716

717717
case 0b110: { // ADD/SUB Add/Subtract Word
718-
auto g_ssrc = getGAM(src_mode, src_reg, wm_word, rm_cur);
718+
auto g_ssrc = getGAM(src_mode, src_reg, wm_word);
719719

720-
auto g_dst = getGAM(dst_mode, dst_reg, wm_word, rm_cur);
720+
auto g_dst = getGAM(dst_mode, dst_reg, wm_word);
721721

722722
addToMMR1(g_dst);
723723
addToMMR1(g_ssrc);
@@ -776,7 +776,7 @@ bool cpu::additional_double_operand_instructions(const uint16_t instr)
776776
case 0: { // MUL
777777
int16_t R1 = getRegister(reg);
778778

779-
auto R2g = getGAM(dst_mode, dst_reg, wm_word, rm_cur);
779+
auto R2g = getGAM(dst_mode, dst_reg, wm_word);
780780
addToMMR1(R2g);
781781
int16_t R2 = R2g.value.value();
782782

@@ -793,7 +793,7 @@ bool cpu::additional_double_operand_instructions(const uint16_t instr)
793793
}
794794

795795
case 1: { // DIV
796-
auto R2g = getGAM(dst_mode, dst_reg, wm_word, rm_cur);
796+
auto R2g = getGAM(dst_mode, dst_reg, wm_word);
797797
addToMMR1(R2g);
798798
int16_t divider = R2g.value.value();
799799

@@ -840,7 +840,7 @@ bool cpu::additional_double_operand_instructions(const uint16_t instr)
840840
case 2: { // ASH
841841
uint32_t R = getRegister(reg), oldR = R;
842842

843-
auto g_dst = getGAM(dst_mode, dst_reg, wm_word, rm_cur);
843+
auto g_dst = getGAM(dst_mode, dst_reg, wm_word);
844844
addToMMR1(g_dst);
845845
uint16_t shift = g_dst.value.value() & 077;
846846

@@ -894,7 +894,7 @@ bool cpu::additional_double_operand_instructions(const uint16_t instr)
894894
case 3: { // ASHC
895895
uint32_t R0R1 = (uint32_t(getRegister(reg)) << 16) | getRegister(reg | 1);
896896

897-
auto g_dst = getGAM(dst_mode, dst_reg, wm_word, rm_cur);
897+
auto g_dst = getGAM(dst_mode, dst_reg, wm_word);
898898
addToMMR1(g_dst);
899899
uint16_t shift = g_dst.value.value() & 077;
900900

@@ -950,7 +950,7 @@ bool cpu::additional_double_operand_instructions(const uint16_t instr)
950950

951951
case 4: { // XOR (word only)
952952
uint16_t reg_v = getRegister(reg); // in case it is R7
953-
auto g_dst = getGAM(dst_mode, dst_reg, wm_word, rm_cur);
953+
auto g_dst = getGAM(dst_mode, dst_reg, wm_word);
954954
addToMMR1(g_dst);
955955
uint16_t vl = g_dst.value.value() ^ reg_v;
956956

@@ -989,7 +989,7 @@ bool cpu::single_operand_instructions(const uint16_t instr)
989989
if (word_mode == wm_byte) // handled elsewhere
990990
return false;
991991

992-
auto g_dst = getGAM(dst_mode, dst_reg, word_mode, rm_cur);
992+
auto g_dst = getGAM(dst_mode, dst_reg, word_mode);
993993
addToMMR1(g_dst);
994994

995995
uint16_t v = g_dst.value.value();
@@ -1045,7 +1045,7 @@ bool cpu::single_operand_instructions(const uint16_t instr)
10451045
set_flags = true;
10461046
}
10471047
else {
1048-
auto a = getGAM(dst_mode, dst_reg, word_mode, rm_cur);
1048+
auto a = getGAM(dst_mode, dst_reg, word_mode);
10491049
addToMMR1(a);
10501050
v = a.value.value();
10511051

@@ -1080,7 +1080,7 @@ bool cpu::single_operand_instructions(const uint16_t instr)
10801080
setRegister(dst_reg, v);
10811081
}
10821082
else {
1083-
auto a = getGAM(dst_mode, dst_reg, word_mode, rm_cur);
1083+
auto a = getGAM(dst_mode, dst_reg, word_mode);
10841084
addToMMR1(a);
10851085
int32_t vl = (a.value.value() + 1) & (word_mode == wm_byte ? 0xff : 0xffff);
10861086

@@ -1112,7 +1112,7 @@ bool cpu::single_operand_instructions(const uint16_t instr)
11121112
setRegister(dst_reg, v);
11131113
}
11141114
else {
1115-
auto a = getGAM(dst_mode, dst_reg, word_mode, rm_cur);
1115+
auto a = getGAM(dst_mode, dst_reg, word_mode);
11161116
addToMMR1(a);
11171117
int32_t vl = (a.value.value() - 1) & (word_mode == wm_byte ? 0xff : 0xffff);
11181118

@@ -1144,7 +1144,7 @@ bool cpu::single_operand_instructions(const uint16_t instr)
11441144
setRegister(dst_reg, v);
11451145
}
11461146
else {
1147-
auto a = getGAM(dst_mode, dst_reg, word_mode, rm_cur);
1147+
auto a = getGAM(dst_mode, dst_reg, word_mode);
11481148
addToMMR1(a);
11491149
uint16_t v = -a.value.value();
11501150

@@ -1179,7 +1179,7 @@ bool cpu::single_operand_instructions(const uint16_t instr)
11791179
setRegister(dst_reg, v);
11801180
}
11811181
else {
1182-
auto a = getGAM(dst_mode, dst_reg, word_mode, rm_cur);
1182+
auto a = getGAM(dst_mode, dst_reg, word_mode);
11831183
addToMMR1(a);
11841184
const uint16_t vo = a.value.value();
11851185
bool org_c = getPSW_c();
@@ -1216,7 +1216,7 @@ bool cpu::single_operand_instructions(const uint16_t instr)
12161216
setRegister(dst_reg, v);
12171217
}
12181218
else {
1219-
auto a = getGAM(dst_mode, dst_reg, word_mode, rm_cur);
1219+
auto a = getGAM(dst_mode, dst_reg, word_mode);
12201220
addToMMR1(a);
12211221
const uint16_t vo = a.value.value();
12221222
bool org_c = getPSW_c();
@@ -1235,7 +1235,7 @@ bool cpu::single_operand_instructions(const uint16_t instr)
12351235
}
12361236

12371237
case 0b000101111: { // TST/TSTB
1238-
auto g = getGAM(dst_mode, dst_reg, word_mode, rm_cur);
1238+
auto g = getGAM(dst_mode, dst_reg, word_mode);
12391239
uint16_t v = g.value.value();
12401240
addToMMR1(g);
12411241

@@ -1264,7 +1264,7 @@ bool cpu::single_operand_instructions(const uint16_t instr)
12641264
setPSW_v(getPSW_c() ^ getPSW_n());
12651265
}
12661266
else {
1267-
auto a = getGAM(dst_mode, dst_reg, word_mode, rm_cur);
1267+
auto a = getGAM(dst_mode, dst_reg, word_mode);
12681268
addToMMR1(a);
12691269
uint16_t t = a.value.value();
12701270
bool new_carry = t & 1;
@@ -1310,7 +1310,7 @@ bool cpu::single_operand_instructions(const uint16_t instr)
13101310
setPSW_v(getPSW_c() ^ getPSW_n());
13111311
}
13121312
else {
1313-
auto a = getGAM(dst_mode, dst_reg, word_mode, rm_cur);
1313+
auto a = getGAM(dst_mode, dst_reg, word_mode);
13141314
addToMMR1(a);
13151315
uint16_t t = a.value.value();
13161316
bool new_carry = false;
@@ -1357,7 +1357,7 @@ bool cpu::single_operand_instructions(const uint16_t instr)
13571357
setPSW_v(getPSW_n() ^ getPSW_c());
13581358
}
13591359
else {
1360-
auto a = getGAM(dst_mode, dst_reg, word_mode, rm_cur);
1360+
auto a = getGAM(dst_mode, dst_reg, word_mode);
13611361
addToMMR1(a);
13621362
uint16_t v = a.value.value();
13631363

@@ -1398,7 +1398,7 @@ bool cpu::single_operand_instructions(const uint16_t instr)
13981398
setRegister(dst_reg, v);
13991399
}
14001400
else {
1401-
auto a = getGAM(dst_mode, dst_reg, word_mode, rm_cur);
1401+
auto a = getGAM(dst_mode, dst_reg, word_mode);
14021402
addToMMR1(a);
14031403
uint16_t vl = a.value.value();
14041404
uint16_t v = (vl << 1) & (word_mode == wm_byte ? 0xff : 0xffff);
@@ -1467,7 +1467,7 @@ bool cpu::single_operand_instructions(const uint16_t instr)
14671467
if (word_mode == wm_byte) { // MTPS
14681468
#if 0 // not in the PDP-11/70
14691469
psw &= 0xff00; // only alter lower 8 bits
1470-
psw |= getGAM(dst_mode, dst_reg, word_mode, rm_cur).value.value() & 0xef; // can't change bit 4
1470+
psw |= getGAM(dst_mode, dst_reg, word_mode).value.value() & 0xef; // can't change bit 4
14711471
#else
14721472
trap(010);
14731473
#endif
@@ -1484,7 +1484,7 @@ bool cpu::single_operand_instructions(const uint16_t instr)
14841484
case 0b000110111: { // MFPS (get PSW to something) / SXT
14851485
if (word_mode == wm_byte) { // MFPS
14861486
#if 0 // not in the PDP-11/70
1487-
auto g_dst = getGAM(dst_mode, dst_reg, word_mode, rm_cur);
1487+
auto g_dst = getGAM(dst_mode, dst_reg, word_mode);
14881488

14891489
uint16_t temp = psw & 0xff;
14901490
bool extend_b7 = psw & 128;
@@ -1504,7 +1504,7 @@ bool cpu::single_operand_instructions(const uint16_t instr)
15041504
#endif
15051505
}
15061506
else { // SXT
1507-
auto g_dst = getGAM(dst_mode, dst_reg, word_mode, rm_cur);
1507+
auto g_dst = getGAM(dst_mode, dst_reg, word_mode);
15081508
addToMMR1(g_dst);
15091509

15101510
uint16_t vl = -getPSW_n();

cpu.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class cpu
8787

8888
void addToMMR1(const gam_rc_t & g);
8989

90-
gam_rc_t getGAM(const uint8_t mode, const uint8_t reg, const word_mode_t word_mode, const rm_selection_t mode_selection, const bool read_value = true);
90+
gam_rc_t getGAM(const uint8_t mode, const uint8_t reg, const word_mode_t word_mode, const bool read_value = true);
9191
gam_rc_t getGAMAddress(const uint8_t mode, const int reg, const word_mode_t word_mode);
9292
bool putGAM(const gam_rc_t & g, const uint16_t value); // returns false when flag registers should not be updated
9393

0 commit comments

Comments
 (0)