struct Flags { union { uint8_t b = 0; BitField n; BitField v; BitField m; BitField x; BitField d; BitField i; BitField z; BitField c; }; inline operator uint() const { return b; } inline auto operator =(uint value) -> uint { return b = value; } inline auto operator&=(uint value) -> uint { return b &= value; } inline auto operator|=(uint value) -> uint { return b |= value; } }; struct Reg16 { union { uint16_t w = 0; BitField l; BitField h; }; inline operator uint() const { return w; } inline auto operator =(uint value) -> uint { return w = value; } inline auto operator |=(uint value) -> uint { return w |= value; } inline auto operator ^=(uint value) -> uint { return w ^= value; } inline auto operator &=(uint value) -> uint { return w &= value; } inline auto operator<<=(uint value) -> uint { return w <<= value; } inline auto operator>>=(uint value) -> uint { return w >>= value; } inline auto operator +=(uint value) -> uint { return w += value; } inline auto operator -=(uint value) -> uint { return w -= value; } inline auto operator *=(uint value) -> uint { return w *= value; } inline auto operator /=(uint value) -> uint { return w /= value; } inline auto operator %=(uint value) -> uint { return w %= value; } }; struct Reg24 { union { uint32_t d = 0; BitField l; BitField h; BitField b; BitField w; }; inline operator uint() const { return d; } inline auto operator =(uint value) -> uint { return d = uint24( value); } inline auto operator |=(uint value) -> uint { return d = uint24(d | value); } inline auto operator ^=(uint value) -> uint { return d = uint24(d ^ value); } inline auto operator &=(uint value) -> uint { return d = uint24(d & value); } inline auto operator<<=(uint value) -> uint { return d = uint24(d << value); } inline auto operator>>=(uint value) -> uint { return d = uint24(d >> value); } inline auto operator +=(uint value) -> uint { return d = uint24(d + value); } inline auto operator -=(uint value) -> uint { return d = uint24(d - value); } inline auto operator *=(uint value) -> uint { return d = uint24(d * value); } inline auto operator /=(uint value) -> uint { return d = uint24(d / value); } inline auto operator %=(uint value) -> uint { return d = uint24(d % value); } }; struct Registers { Reg24 pc; Reg16 a; Reg16 x; Reg16 y; Reg16 z; //pseudo-register (zero register) Reg16 s; Reg16 d; Flags p; uint8 db = 0; bool e = false; bool irq = false; //IRQ pin (0 = low, 1 = trigger) bool wai = false; //raised during wai, cleared after interrupt triggered uint8 mdr = 0; //memory data register uint16 vector = 0; //interrupt vector address };