not sure if a union of an int and an std::opional is guaranteed to work

This commit is contained in:
folkert van heusden 2023-03-24 21:23:11 +01:00
parent ba5916f750
commit 3dddae94c3
Signed by untrusted user who does not match committer: folkert
GPG key ID: 6B6455EDFEED3BD1
2 changed files with 4 additions and 6 deletions

View file

@ -149,7 +149,7 @@ void cpu::setRegisterLowByte(const int nr, const bool word_mode, const uint16_t
bool cpu::put_result(const gam_rc_t & g, const uint16_t value) bool cpu::put_result(const gam_rc_t & g, const uint16_t value)
{ {
if (g.addr.has_value() == false) { if (g.addr.has_value() == false) {
setRegisterLowByte(g.reg, g.word_mode, value); setRegisterLowByte(g.reg.value(), g.word_mode, value);
return true; return true;
} }
@ -397,7 +397,7 @@ bool cpu::putGAM(const gam_rc_t & g, const uint16_t value)
return g.addr.value() != ADDR_PSW; return g.addr.value() != ADDR_PSW;
} }
setRegister(g.reg, value, g.prev_mode); setRegister(g.reg.value(), value, g.prev_mode);
return true; return true;
} }

6
cpu.h
View file

@ -17,10 +17,8 @@ typedef struct {
bool prev_mode; bool prev_mode;
d_i_space_t space; d_i_space_t space;
union { std::optional<uint16_t> addr;
std::optional<uint16_t> addr; std::optional<int> reg;
int reg;
};
std::optional<uint16_t> value; std::optional<uint16_t> value;
} gam_rc_t; } gam_rc_t;