removed bus::is_psw special case from add/sub

This commit is contained in:
Folkert van Heusden 2025-04-02 23:35:19 +02:00
parent f1bcefe433
commit 5c9a46aec7
Signed by untrusted user who does not match committer: folkert
GPG key ID: 6B6455EDFEED3BD1
4 changed files with 9 additions and 36 deletions

13
bus.cpp
View file

@ -531,19 +531,6 @@ uint16_t bus::read(const uint16_t addr_in, const word_mode_t word_mode, const rm
return temp; return temp;
} }
bool bus::is_psw(const uint16_t addr, const int run_mode, const d_i_space_t space) const
{
auto meta = mmu_->calculate_physical_address(run_mode, addr);
if (space == d_space && meta.physical_data_is_psw)
return true;
if (space == i_space && meta.physical_instruction_is_psw)
return true;
return false;
}
bool bus::write(const uint16_t addr_in, const word_mode_t word_mode, uint16_t value, const rm_selection_t mode_selection, const d_i_space_t space) bool bus::write(const uint16_t addr_in, const word_mode_t word_mode, uint16_t value, const rm_selection_t mode_selection, const d_i_space_t space)
{ {
int run_mode = mode_selection == rm_cur ? c->getPSW_runmode() : c->getPSW_prev_runmode(); int run_mode = mode_selection == rm_cur ? c->getPSW_runmode() : c->getPSW_prev_runmode();

2
bus.h
View file

@ -136,6 +136,4 @@ public:
void write_word(const uint16_t a, const uint16_t value, const d_i_space_t s); void write_word(const uint16_t a, const uint16_t value, const d_i_space_t s);
void write_word(const uint16_t a, const uint16_t value) override { write_word(a, value, i_space); } void write_word(const uint16_t a, const uint16_t value) override { write_word(a, value, i_space); }
void write_physical(const uint32_t a, const uint16_t value); void write_physical(const uint32_t a, const uint16_t value);
bool is_psw(const uint16_t addr, const int run_mode, const d_i_space_t space) const;
}; };

29
cpu.cpp
View file

@ -547,7 +547,6 @@ bool cpu::putGAM(const gam_rc_t & g, const uint16_t value)
if (g.addr.has_value()) { if (g.addr.has_value()) {
auto rc = b->write(g.addr.value(), g.word_mode, value, g.mode_selection, g.space); auto rc = b->write(g.addr.value(), g.word_mode, value, g.mode_selection, g.space);
return rc == false; return rc == false;
} }
@ -709,37 +708,27 @@ bool cpu::double_operand_instructions(const uint16_t instr)
int16_t result = 0; int16_t result = 0;
bool set_flags = true; if (instr & 0x8000) // SUB
result = g_dst.value.value() - g_ssrc.value.value();
else // ADD
result = g_dst.value.value() + g_ssrc.value.value();
if (g_dst.addr.has_value()) bool set_flags = putGAM(g_dst, result);
set_flags = !b->is_psw(g_dst.addr.value(), g_dst.mode_selection, g_dst.space);
if (instr & 0x8000) { // SUB if (set_flags) {
result = (g_dst.value.value() - g_ssrc.value.value()) & 0xffff; if (instr & 0x8000) { // SUB
if (set_flags) {
setPSW_v(SIGN((g_dst.value.value() ^ g_ssrc.value.value()) & (~g_ssrc.value.value() ^ result), wm_word)); setPSW_v(SIGN((g_dst.value.value() ^ g_ssrc.value.value()) & (~g_ssrc.value.value() ^ result), wm_word));
setPSW_c(uint16_t(g_dst.value.value()) < uint16_t(g_ssrc.value.value())); setPSW_c(uint16_t(g_dst.value.value()) < uint16_t(g_ssrc.value.value()));
} }
} else {
else { // ADD setPSW_v(SIGN((~g_ssrc.value.value() ^ g_dst.value.value()) & (g_ssrc.value.value() ^ (result & 0xffff)), wm_word));
uint32_t temp = g_dst.value.value() + g_ssrc.value.value();
result = temp;
if (set_flags) {
setPSW_v(SIGN((~g_ssrc.value.value() ^ g_dst.value.value()) & (g_ssrc.value.value() ^ (temp & 0xffff)), wm_word));
setPSW_c(uint16_t(result) < uint16_t(g_ssrc.value.value())); setPSW_c(uint16_t(result) < uint16_t(g_ssrc.value.value()));
} }
}
if (set_flags) {
setPSW_n(result < 0); setPSW_n(result < 0);
setPSW_z(result == 0); setPSW_z(result == 0);
} }
(void)putGAM(g_dst, result);
return true; return true;
} }

View file

@ -710,7 +710,6 @@ int main(int argc, char *argv[])
*running = false; *running = false;
uint32_t stop_event = event.exchange(EVENT_NONE); uint32_t stop_event = event.exchange(EVENT_NONE);
if (stop_event == EVENT_HALT || stop_event == EVENT_INTERRUPT || stop_event == EVENT_TERMINATE) if (stop_event == EVENT_HALT || stop_event == EVENT_INTERRUPT || stop_event == EVENT_TERMINATE)
break; break;
} }