183#include <type_traits>
208 #define MAYBE_UNUSED_LABEL [[maybe_unused]]
210 #pragma warning(disable : 4102)
211 #define MAYBE_UNUSED_LABEL
217enum Reg8 :
int {
A,
F,
B,
C,
D,
E,
H,
L,
IXH,
IXL,
IYH,
IYL,
REG_I,
REG_R,
DUMMY };
221static constexpr byte S_FLAG = 0x80;
222static constexpr byte Z_FLAG = 0x40;
223static constexpr byte Y_FLAG = 0x20;
224static constexpr byte H_FLAG = 0x10;
225static constexpr byte X_FLAG = 0x08;
226static constexpr byte V_FLAG = 0x04;
227static constexpr byte P_FLAG = V_FLAG;
228static constexpr byte N_FLAG = 0x02;
229static constexpr byte C_FLAG = 0x01;
233 std::array<byte, 256>
ZS;
235 std::array<byte, 256>
ZSP;
240static constexpr byte ZS0 = Z_FLAG;
241static constexpr byte ZSXY0 = Z_FLAG;
242static constexpr byte ZSP0 = Z_FLAG | V_FLAG;
243static constexpr byte ZSPXY0 = Z_FLAG | V_FLAG;
244static constexpr byte ZS255 = S_FLAG;
245static constexpr byte ZSXY255 = S_FLAG | X_FLAG | Y_FLAG;
247static constexpr Table initTables()
251 for (
auto i_ :
xrange(256)) {
252 auto i = narrow_cast<byte>(i_);
253 byte zFlag = (i == 0) ? Z_FLAG : 0;
254 byte sFlag = i & S_FLAG;
255 byte xFlag = i & X_FLAG;
256 byte yFlag = i & Y_FLAG;
258 for (
int v = 128; v != 0; v >>= 1) {
259 if (i & v) vFlag ^= V_FLAG;
261 table.
ZS [i] = zFlag | sFlag;
262 table.
ZSXY [i] = zFlag | sFlag | xFlag | yFlag;
263 table.
ZSP [i] = zFlag | sFlag | vFlag;
264 table.
ZSPXY[i] = zFlag | sFlag | xFlag | yFlag | vFlag;
265 table.
ZSPH [i] = zFlag | sFlag | vFlag | H_FLAG;
267 assert(table.
ZS [ 0] == ZS0);
268 assert(table.
ZSXY [ 0] == ZSXY0);
269 assert(table.
ZSP [ 0] == ZSP0);
270 assert(table.
ZSPXY[ 0] == ZSPXY0);
271 assert(table.
ZS [255] == ZS255);
272 assert(table.
ZSXY [255] == ZSXY255);
277static constexpr Table table = initTables();
301 , T(time, motherboard_.getScheduler())
302 , motherboard(motherboard_)
303 , scheduler(motherboard.getScheduler())
304 , traceSetting(traceSetting_)
305 , diHaltCallback(diHaltCallback_)
306 , IRQStatus(motherboard.getDebugger(), name +
".pendingIRQ",
307 "Non-zero if there are pending IRQs (thus CPU would enter "
308 "interrupt routine in EI mode).",
310 , IRQAccept(motherboard.getDebugger(), name +
".acceptIRQ",
311 "This probe is only useful to set a breakpoint on (the value "
312 "return by read is meaningless). The breakpoint gets triggered "
313 "right after the CPU accepted an IRQ.")
315 motherboard.getCommandController(),
tmpStrCat(name,
"_freq_locked"),
316 "real (locked) or custom (unlocked) CPU frequency",
319 motherboard.getCommandController(),
tmpStrCat(name,
"_freq"),
320 "custom CPU frequency (only valid when unlocked)",
321 T::CLOCK_FREQ, 1000000, 1000000000)
322 , freq(T::CLOCK_FREQ)
323 , tracingEnabled(traceSetting.getBoolean())
324 , isCMOS(motherboard.hasToshibaEngine())
326 static_assert(!std::is_polymorphic_v<CPUCore<T>>,
327 "keep CPUCore non-virtual to keep PC at offset 0");
334 assert(T::getTimeFast() <= time);
367 T::setMemPtr(0xFFFF);
397 assert(NMIStatus == 0);
398 assert(IRQStatus == 0);
420 if (exitLoop) [[unlikely]] {
435template<
typename T>
void CPUCore<T>::setSlowInstructions()
437 slowInstructions = 2;
443 assert(IRQStatus >= 0);
444 if (IRQStatus == 0) {
445 setSlowInstructions();
447 IRQStatus = IRQStatus + 1;
452 IRQStatus = IRQStatus - 1;
453 assert(IRQStatus >= 0);
458 assert(NMIStatus >= 0);
459 if (NMIStatus == 0) {
461 setSlowInstructions();
469 assert(NMIStatus >= 0);
485 return address == getPC();
490 assert(time >= getCurrentTime());
491 scheduler.schedule(time);
492 T::advanceTime(time);
498 EmuTime time2 = T::calcTime(time, cycles);
501 scheduler.schedule(time2);
515 }
else if (&
setting == &freqValue) {
517 }
else if (&
setting == &traceSetting) {
518 tracingEnabled = traceSetting.getBoolean();
530 if (freqLocked.getBoolean()) {
535 T::setFreq(freqValue.getInt());
540template<
typename T>
inline byte CPUCore<T>::READ_PORT(
word port,
unsigned cc)
542 EmuTime time = T::getTimeFast(cc);
543 scheduler.schedule(time);
544 byte result = interface->readIO(port, time);
549template<
typename T>
inline void CPUCore<T>::WRITE_PORT(
word port,
byte value,
unsigned cc)
551 EmuTime time = T::getTimeFast(cc);
552 scheduler.schedule(time);
553 interface->writeIO(port, value, time);
557template<
typename T>
template<
bool PRE_PB,
bool POST_PB>
563 if (readCacheLine[high] ==
nullptr) {
566 if (
const byte* line = interface->getReadCacheLine(addrBase)) {
568 T::template PRE_MEM<PRE_PB, POST_PB>(address);
569 T::template POST_MEM< POST_PB>(address);
570 readCacheLine[high] = line - addrBase;
571 return readCacheLine[high][address];
575 readCacheLine[high] = std::bit_cast<const byte*>(uintptr_t(1));
576 T::template PRE_MEM<PRE_PB, POST_PB>(address);
577 EmuTime time = T::getTimeFast(cc);
578 scheduler.schedule(time);
579 byte result = interface->readMem(narrow_cast<word>(address), time);
580 T::template POST_MEM<POST_PB>(address);
583template<
typename T>
template<
bool PRE_PB,
bool POST_PB>
587 if (uintptr_t(line) > 1) [[likely]] {
589 T::template PRE_MEM<PRE_PB, POST_PB>(address);
590 T::template POST_MEM< POST_PB>(address);
591 return line[address];
593 return RDMEMslow<PRE_PB, POST_PB>(address, cc);
596template<
typename T>
template<
bool PRE_PB,
bool POST_PB>
599 constexpr bool PRE = T::template Normalize<PRE_PB >::value;
600 constexpr bool POST = T::template Normalize<POST_PB>::value;
601 return RDMEM_impl2<PRE, POST>(address, cc);
614 unsigned address = narrow_cast<word>(getPC() + PC_OFFSET);
615 return RDMEM_impl<false, false>(address, cc);
619 return RDMEM_impl<true, true>(address, cc);
622template<
typename T>
template<
bool PRE_PB,
bool POST_PB>
625 auto res =
word(RDMEM_impl<PRE_PB, false>(address, cc));
626 res |=
word(RDMEM_impl<false, POST_PB>(narrow_cast<word>(address + 1), cc + T::CC_RDMEM) << 8);
629template<
typename T>
template<
bool PRE_PB,
bool POST_PB>
635 T::template PRE_WORD<PRE_PB, POST_PB>(address);
636 T::template POST_WORD< POST_PB>(address);
640 return RD_WORD_slow<PRE_PB, POST_PB>(address, cc);
643template<
typename T>
template<
bool PRE_PB,
bool POST_PB>
646 constexpr bool PRE = T::template Normalize<PRE_PB >::value;
647 constexpr bool POST = T::template Normalize<POST_PB>::value;
648 return RD_WORD_impl2<PRE, POST>(address, cc);
652 unsigned addr = narrow_cast<word>(getPC() + PC_OFFSET);
653 return RD_WORD_impl<false, false>(addr, cc);
656 unsigned address,
unsigned cc)
658 return RD_WORD_impl<true, true>(address, cc);
661template<
typename T>
template<
bool PRE_PB,
bool POST_PB>
667 if (writeCacheLine[high] ==
nullptr) {
670 if (
byte* line = interface->getWriteCacheLine(addrBase)) {
672 T::template PRE_MEM<PRE_PB, POST_PB>(address);
673 T::template POST_MEM< POST_PB>(address);
674 writeCacheLine[high] = line - addrBase;
675 writeCacheLine[high][address] = value;
680 writeCacheLine[high] = std::bit_cast<byte*>(uintptr_t(1));
681 T::template PRE_MEM<PRE_PB, POST_PB>(address);
682 EmuTime time = T::getTimeFast(cc);
683 scheduler.schedule(time);
684 interface->writeMem(narrow_cast<word>(address), value, time);
685 T::template POST_MEM<POST_PB>(address);
687template<
typename T>
template<
bool PRE_PB,
bool POST_PB>
689 unsigned address,
byte value,
unsigned cc)
692 if (uintptr_t(line) > 1) [[likely]] {
694 T::template PRE_MEM<PRE_PB, POST_PB>(address);
695 T::template POST_MEM< POST_PB>(address);
696 line[address] = value;
698 WRMEMslow<PRE_PB, POST_PB>(address, value, cc);
701template<
typename T>
template<
bool PRE_PB,
bool POST_PB>
703 unsigned address,
byte value,
unsigned cc)
705 constexpr bool PRE = T::template Normalize<PRE_PB >::value;
706 constexpr bool POST = T::template Normalize<POST_PB>::value;
707 WRMEM_impl2<PRE, POST>(address, value, cc);
710 unsigned address,
byte value,
unsigned cc)
712 WRMEM_impl<true, true>(address, value, cc);
715template<
typename T>
NEVER_INLINE void CPUCore<T>::WR_WORD_slow(
716 unsigned address,
word value,
unsigned cc)
718 WRMEM_impl<true, false>( address,
byte(value & 255), cc);
719 WRMEM_impl<false, true>(narrow_cast<word>(address + 1),
byte(value >> 8), cc + T::CC_WRMEM);
722 unsigned address,
word value,
unsigned cc)
727 T::template PRE_WORD<true, true>(address);
728 T::template POST_WORD< true>(address);
732 WR_WORD_slow(address, value, cc);
737template<
typename T>
template<
bool PRE_PB,
bool POST_PB>
739 unsigned address,
word value,
unsigned cc)
741 WRMEM_impl<PRE_PB, false>(narrow_cast<word>(address + 1),
byte(value >> 8), cc);
742 WRMEM_impl<false, POST_PB>( address,
byte(value & 255), cc + T::CC_WRMEM);
744template<
typename T>
template<
bool PRE_PB,
bool POST_PB>
746 unsigned address,
word value,
unsigned cc)
751 T::template PRE_WORD<PRE_PB, POST_PB>(address);
752 T::template POST_WORD< POST_PB>(address);
756 WR_WORD_rev_slow<PRE_PB, POST_PB>(address, value, cc);
759template<
typename T>
template<
bool PRE_PB,
bool POST_PB>
761 unsigned address,
word value,
unsigned cc)
763 constexpr bool PRE = T::template Normalize<PRE_PB >::value;
764 constexpr bool POST = T::template Normalize<POST_PB>::value;
765 WR_WORD_rev2<PRE, POST>(address, value, cc);
775 PUSH<T::EE_NMI_1>(getPC());
781template<
typename T>
inline void CPUCore<T>::irq0()
785 assert(interface->readIRQVector() == 0xFF);
790 PUSH<T::EE_IRQ0_1>(getPC());
792 T::setMemPtr(getPC());
797template<
typename T>
inline void CPUCore<T>::irq1()
803 PUSH<T::EE_IRQ1_1>(getPC());
805 T::setMemPtr(getPC());
810template<
typename T>
inline void CPUCore<T>::irq2()
816 PUSH<T::EE_IRQ2_1>(getPC());
817 unsigned x = interface->readIRQVector() | (getI() << 8);
818 setPC(RD_WORD(x, T::CC_IRQ2_2));
819 T::setMemPtr(getPC());
824void CPUCore<T>::executeInstructions()
826 checkNoCurrentFlags();
827#ifdef USE_COMPUTED_GOTO
830 static std::array<void*, 256> opcodeTable = {
831 &&op00, &&op01, &&op02, &&op03, &&op04, &&op05, &&op06, &&op07,
832 &&op08, &&op09, &&op0A, &&op0B, &&op0C, &&op0D, &&op0E, &&op0F,
833 &&op10, &&op11, &&op12, &&op13, &&op14, &&op15, &&op16, &&op17,
834 &&op18, &&op19, &&op1A, &&op1B, &&op1C, &&op1D, &&op1E, &&op1F,
835 &&op20, &&op21, &&op22, &&op23, &&op24, &&op25, &&op26, &&op27,
836 &&op28, &&op29, &&op2A, &&op2B, &&op2C, &&op2D, &&op2E, &&op2F,
837 &&op30, &&op31, &&op32, &&op33, &&op34, &&op35, &&op36, &&op37,
838 &&op38, &&op39, &&op3A, &&op3B, &&op3C, &&op3D, &&op3E, &&op3F,
839 &&op00, &&op41, &&op42, &&op43, &&op44, &&op45, &&op46, &&op47,
840 &&op48, &&op00, &&op4A, &&op4B, &&op4C, &&op4D, &&op4E, &&op4F,
841 &&op50, &&op51, &&op00, &&op53, &&op54, &&op55, &&op56, &&op57,
842 &&op58, &&op59, &&op5A, &&op00, &&op5C, &&op5D, &&op5E, &&op5F,
843 &&op60, &&op61, &&op62, &&op63, &&op00, &&op65, &&op66, &&op67,
844 &&op68, &&op69, &&op6A, &&op6B, &&op6C, &&op00, &&op6E, &&op6F,
845 &&op70, &&op71, &&op72, &&op73, &&op74, &&op75, &&op76, &&op77,
846 &&op78, &&op79, &&op7A, &&op7B, &&op7C, &&op7D, &&op7E, &&op00,
847 &&op80, &&op81, &&op82, &&op83, &&op84, &&op85, &&op86, &&op87,
848 &&op88, &&op89, &&op8A, &&op8B, &&op8C, &&op8D, &&op8E, &&op8F,
849 &&op90, &&op91, &&op92, &&op93, &&op94, &&op95, &&op96, &&op97,
850 &&op98, &&op99, &&op9A, &&op9B, &&op9C, &&op9D, &&op9E, &&op9F,
851 &&opA0, &&opA1, &&opA2, &&opA3, &&opA4, &&opA5, &&opA6, &&opA7,
852 &&opA8, &&opA9, &&opAA, &&opAB, &&opAC, &&opAD, &&opAE, &&opAF,
853 &&opB0, &&opB1, &&opB2, &&opB3, &&opB4, &&opB5, &&opB6, &&opB7,
854 &&opB8, &&opB9, &&opBA, &&opBB, &&opBC, &&opBD, &&opBE, &&opBF,
855 &&opC0, &&opC1, &&opC2, &&opC3, &&opC4, &&opC5, &&opC6, &&opC7,
856 &&opC8, &&opC9, &&opCA, &&opCB, &&opCC, &&opCD, &&opCE, &&opCF,
857 &&opD0, &&opD1, &&opD2, &&opD3, &&opD4, &&opD5, &&opD6, &&opD7,
858 &&opD8, &&opD9, &&opDA, &&opDB, &&opDC, &&opDD, &&opDE, &&opDF,
859 &&opE0, &&opE1, &&opE2, &&opE3, &&opE4, &&opE5, &&opE6, &&opE7,
860 &&opE8, &&opE9, &&opEA, &&opEB, &&opEC, &&opED, &&opEE, &&opEF,
861 &&opF0, &&opF1, &&opF2, &&opF3, &&opF4, &&opF5, &&opF6, &&opF7,
862 &&opF8, &&opF9, &&opFA, &&opFB, &&opFC, &&opFD, &&opFE, &&opFF,
868 setPC(getPC() + ii.length); \
870 T::R800Refresh(*this); \
871 if (!T::limitReached()) [[likely]] { \
873 unsigned address = getPC(); \
874 const byte* line = readCacheLine[address >> CacheLine::BITS]; \
875 if (uintptr_t(line) > 1) [[likely]] { \
876 T::template PRE_MEM<false, false>(address); \
877 T::template POST_MEM< false>(address); \
878 byte op = line[address]; \
879 goto *(opcodeTable[op]); \
888 setPC(getPC() + ii.length); \
890 T::R800Refresh(*this); \
891 assert(T::limitReached()); \
895 setPC(getPC() + ii.length); \
898 assert(T::limitReached()); \
902#define CASE(X) op##X:
907 setPC(getPC() + ii.length); \
909 T::R800Refresh(*this); \
910 if (!T::limitReached()) [[likely]] { \
916 setPC(getPC() + ii.length); \
918 T::R800Refresh(*this); \
919 assert(T::limitReached()); \
923 setPC(getPC() + ii.length); \
926 assert(T::limitReached()); \
929#define CASE(X) case 0x##X:
933#ifndef USE_COMPUTED_GOTO
937 byte opcodeMain = RDMEM_OPCODE<0>(T::CC_MAIN);
939#ifdef USE_COMPUTED_GOTO
940 goto *(opcodeTable[opcodeMain]);
943 unsigned address = getPC();
944 byte opcodeSlow = RDMEMslow<false, false>(address, T::CC_MAIN);
945 goto *(opcodeTable[opcodeSlow]);
949#ifndef USE_COMPUTED_GOTO
951 switch (opcodeMain) {
965CASE(08) { II ii = ex_af_af();
NEXT; }
970CASE(20) { II ii = jr(CondNZ());
NEXT; }
971CASE(28) { II ii = jr(CondZ ());
NEXT; }
972CASE(30) { II ii = jr(CondNC());
NEXT; }
973CASE(38) { II ii = jr(CondC ());
NEXT; }
974CASE(18) { II ii = jr(CondTrue());
NEXT; }
976CASE(32) { II ii = ld_xbyte_a();
NEXT; }
978CASE(22) { II ii = ld_xword_SS<HL,0>();
NEXT; }
979CASE(2
A) { II ii = ld_SS_xword<HL,0>();
NEXT; }
980CASE(02) { II ii = ld_SS_a<BC>();
NEXT; }
981CASE(12) { II ii = ld_SS_a<DE>();
NEXT; }
984CASE(03) { II ii = inc_SS<BC,0>();
NEXT; }
985CASE(13) { II ii = inc_SS<DE,0>();
NEXT; }
986CASE(23) { II ii = inc_SS<HL,0>();
NEXT; }
987CASE(33) { II ii = inc_SS<SP,0>();
NEXT; }
988CASE(0
B) { II ii = dec_SS<BC,0>();
NEXT; }
989CASE(1
B) { II ii = dec_SS<DE,0>();
NEXT; }
990CASE(2
B) { II ii = dec_SS<HL,0>();
NEXT; }
991CASE(3
B) { II ii = dec_SS<SP,0>();
NEXT; }
992CASE(09) { II ii = add_SS_TT<HL,BC,0>();
NEXT; }
993CASE(19) { II ii = add_SS_TT<HL,DE,0>();
NEXT; }
994CASE(29) { II ii = add_SS_SS<HL ,0>();
NEXT; }
995CASE(39) { II ii = add_SS_TT<HL,SP,0>();
NEXT; }
996CASE(01) { II ii = ld_SS_word<BC,0>();
NEXT; }
997CASE(11) { II ii = ld_SS_word<DE,0>();
NEXT; }
998CASE(21) { II ii = ld_SS_word<HL,0>();
NEXT; }
999CASE(31) { II ii = ld_SS_word<SP,0>();
NEXT; }
1000CASE(04) { II ii = inc_R<B,0>();
NEXT; }
1002CASE(14) { II ii = inc_R<D,0>();
NEXT; }
1004CASE(24) { II ii = inc_R<H,0>();
NEXT; }
1007CASE(34) { II ii = inc_xhl();
NEXT; }
1008CASE(05) { II ii = dec_R<B,0>();
NEXT; }
1010CASE(15) { II ii = dec_R<D,0>();
NEXT; }
1012CASE(25) { II ii = dec_R<H,0>();
NEXT; }
1015CASE(35) { II ii = dec_xhl();
NEXT; }
1016CASE(06) { II ii = ld_R_byte<B,0>();
NEXT; }
1017CASE(0
E) { II ii = ld_R_byte<C,0>();
NEXT; }
1018CASE(16) { II ii = ld_R_byte<D,0>();
NEXT; }
1019CASE(1
E) { II ii = ld_R_byte<E,0>();
NEXT; }
1020CASE(26) { II ii = ld_R_byte<H,0>();
NEXT; }
1021CASE(2
E) { II ii = ld_R_byte<L,0>();
NEXT; }
1022CASE(3
E) { II ii = ld_R_byte<A,0>();
NEXT; }
1023CASE(36) { II ii = ld_xhl_byte();
NEXT; }
1025CASE(41) { II ii = ld_R_R<B,C,0>();
NEXT; }
1026CASE(42) { II ii = ld_R_R<B,D,0>();
NEXT; }
1027CASE(43) { II ii = ld_R_R<B,E,0>();
NEXT; }
1028CASE(44) { II ii = ld_R_R<B,H,0>();
NEXT; }
1029CASE(45) { II ii = ld_R_R<B,L,0>();
NEXT; }
1030CASE(47) { II ii = ld_R_R<B,A,0>();
NEXT; }
1031CASE(48) { II ii = ld_R_R<C,B,0>();
NEXT; }
1032CASE(4
A) { II ii = ld_R_R<C,D,0>();
NEXT; }
1033CASE(4
B) { II ii = ld_R_R<C,E,0>();
NEXT; }
1034CASE(4
C) { II ii = ld_R_R<C,H,0>();
NEXT; }
1035CASE(4
D) { II ii = ld_R_R<C,L,0>();
NEXT; }
1036CASE(4
F) { II ii = ld_R_R<C,A,0>();
NEXT; }
1037CASE(50) { II ii = ld_R_R<D,B,0>();
NEXT; }
1038CASE(51) { II ii = ld_R_R<D,C,0>();
NEXT; }
1039CASE(53) { II ii = ld_R_R<D,E,0>();
NEXT; }
1040CASE(54) { II ii = ld_R_R<D,H,0>();
NEXT; }
1041CASE(55) { II ii = ld_R_R<D,L,0>();
NEXT; }
1042CASE(57) { II ii = ld_R_R<D,A,0>();
NEXT; }
1043CASE(58) { II ii = ld_R_R<E,B,0>();
NEXT; }
1044CASE(59) { II ii = ld_R_R<E,C,0>();
NEXT; }
1045CASE(5
A) { II ii = ld_R_R<E,D,0>();
NEXT; }
1046CASE(5
C) { II ii = ld_R_R<E,H,0>();
NEXT; }
1047CASE(5
D) { II ii = ld_R_R<E,L,0>();
NEXT; }
1048CASE(5
F) { II ii = ld_R_R<E,A,0>();
NEXT; }
1049CASE(60) { II ii = ld_R_R<H,B,0>();
NEXT; }
1050CASE(61) { II ii = ld_R_R<H,C,0>();
NEXT; }
1051CASE(62) { II ii = ld_R_R<H,D,0>();
NEXT; }
1052CASE(63) { II ii = ld_R_R<H,E,0>();
NEXT; }
1053CASE(65) { II ii = ld_R_R<H,L,0>();
NEXT; }
1054CASE(67) { II ii = ld_R_R<H,A,0>();
NEXT; }
1055CASE(68) { II ii = ld_R_R<L,B,0>();
NEXT; }
1056CASE(69) { II ii = ld_R_R<L,C,0>();
NEXT; }
1057CASE(6
A) { II ii = ld_R_R<L,D,0>();
NEXT; }
1058CASE(6
B) { II ii = ld_R_R<L,E,0>();
NEXT; }
1059CASE(6
C) { II ii = ld_R_R<L,H,0>();
NEXT; }
1060CASE(6
F) { II ii = ld_R_R<L,A,0>();
NEXT; }
1061CASE(78) { II ii = ld_R_R<A,B,0>();
NEXT; }
1062CASE(79) { II ii = ld_R_R<A,C,0>();
NEXT; }
1063CASE(7
A) { II ii = ld_R_R<A,D,0>();
NEXT; }
1064CASE(7
B) { II ii = ld_R_R<A,E,0>();
NEXT; }
1065CASE(7
C) { II ii = ld_R_R<A,H,0>();
NEXT; }
1066CASE(7
D) { II ii = ld_R_R<A,L,0>();
NEXT; }
1067CASE(70) { II ii = ld_xhl_R<B>();
NEXT; }
1068CASE(71) { II ii = ld_xhl_R<C>();
NEXT; }
1069CASE(72) { II ii = ld_xhl_R<D>();
NEXT; }
1070CASE(73) { II ii = ld_xhl_R<E>();
NEXT; }
1071CASE(74) { II ii = ld_xhl_R<H>();
NEXT; }
1072CASE(75) { II ii = ld_xhl_R<L>();
NEXT; }
1073CASE(77) { II ii = ld_xhl_R<A>();
NEXT; }
1074CASE(46) { II ii = ld_R_xhl<B>();
NEXT; }
1075CASE(4
E) { II ii = ld_R_xhl<C>();
NEXT; }
1076CASE(56) { II ii = ld_R_xhl<D>();
NEXT; }
1077CASE(5
E) { II ii = ld_R_xhl<E>();
NEXT; }
1078CASE(66) { II ii = ld_R_xhl<H>();
NEXT; }
1079CASE(6
E) { II ii = ld_R_xhl<L>();
NEXT; }
1080CASE(7
E) { II ii = ld_R_xhl<A>();
NEXT; }
1083CASE(80) { II ii = add_a_R<B,0>();
NEXT; }
1084CASE(81) { II ii = add_a_R<C,0>();
NEXT; }
1085CASE(82) { II ii = add_a_R<D,0>();
NEXT; }
1086CASE(83) { II ii = add_a_R<E,0>();
NEXT; }
1087CASE(84) { II ii = add_a_R<H,0>();
NEXT; }
1088CASE(85) { II ii = add_a_R<L,0>();
NEXT; }
1089CASE(86) { II ii = add_a_xhl();
NEXT; }
1090CASE(87) { II ii = add_a_a();
NEXT; }
1091CASE(88) { II ii = adc_a_R<B,0>();
NEXT; }
1092CASE(89) { II ii = adc_a_R<C,0>();
NEXT; }
1093CASE(8
A) { II ii = adc_a_R<D,0>();
NEXT; }
1094CASE(8
B) { II ii = adc_a_R<E,0>();
NEXT; }
1095CASE(8
C) { II ii = adc_a_R<H,0>();
NEXT; }
1096CASE(8
D) { II ii = adc_a_R<L,0>();
NEXT; }
1099CASE(90) { II ii = sub_R<B,0>();
NEXT; }
1100CASE(91) { II ii = sub_R<C,0>();
NEXT; }
1101CASE(92) { II ii = sub_R<D,0>();
NEXT; }
1102CASE(93) { II ii = sub_R<E,0>();
NEXT; }
1103CASE(94) { II ii = sub_R<H,0>();
NEXT; }
1104CASE(95) { II ii = sub_R<L,0>();
NEXT; }
1105CASE(96) { II ii = sub_xhl();
NEXT; }
1107CASE(98) { II ii = sbc_a_R<B,0>();
NEXT; }
1108CASE(99) { II ii = sbc_a_R<C,0>();
NEXT; }
1109CASE(9
A) { II ii = sbc_a_R<D,0>();
NEXT; }
1110CASE(9
B) { II ii = sbc_a_R<E,0>();
NEXT; }
1111CASE(9
C) { II ii = sbc_a_R<H,0>();
NEXT; }
1112CASE(9
D) { II ii = sbc_a_R<L,0>();
NEXT; }
1115CASE(A0) { II ii = and_R<B,0>();
NEXT; }
1116CASE(A1) { II ii = and_R<C,0>();
NEXT; }
1118CASE(A3) { II ii = and_R<E,0>();
NEXT; }
1119CASE(A4) { II ii = and_R<H,0>();
NEXT; }
1120CASE(A5) { II ii = and_R<L,0>();
NEXT; }
1121CASE(A6) { II ii = and_xhl();
NEXT; }
1123CASE(A8) { II ii = xor_R<B,0>();
NEXT; }
1124CASE(A9) { II ii = xor_R<C,0>();
NEXT; }
1125CASE(AA) { II ii = xor_R<D,0>();
NEXT; }
1126CASE(AB) { II ii = xor_R<E,0>();
NEXT; }
1127CASE(AC) { II ii = xor_R<H,0>();
NEXT; }
1128CASE(AD) { II ii = xor_R<L,0>();
NEXT; }
1129CASE(AE) { II ii = xor_xhl();
NEXT; }
1139CASE(B8) { II ii = cp_R<B,0>();
NEXT; }
1140CASE(B9) { II ii = cp_R<C,0>();
NEXT; }
1141CASE(BA) { II ii = cp_R<D,0>();
NEXT; }
1142CASE(BB) { II ii = cp_R<E,0>();
NEXT; }
1144CASE(BD) { II ii = cp_R<L,0>();
NEXT; }
1145CASE(BE) { II ii = cp_xhl();
NEXT; }
1148CASE(D3) { II ii = out_byte_a();
NEXT; }
1149CASE(DB) { II ii = in_a_byte();
NEXT; }
1151CASE(E3) { II ii = ex_xsp_SS<HL,0>();
NEXT; }
1152CASE(EB) { II ii = ex_de_hl();
NEXT; }
1153CASE(E9) { II ii = jp_SS<HL,0>();
NEXT; }
1154CASE(F9) { II ii = ld_sp_SS<HL,0>();
NEXT; }
1157CASE(C6) { II ii = add_a_byte();
NEXT; }
1158CASE(CE) { II ii = adc_a_byte();
NEXT; }
1159CASE(D6) { II ii = sub_byte();
NEXT; }
1161CASE(E6) { II ii = and_byte();
NEXT; }
1162CASE(EE) { II ii = xor_byte();
NEXT; }
1163CASE(F6) { II ii = or_byte();
NEXT; }
1164CASE(FE) { II ii = cp_byte();
NEXT; }
1165CASE(C0) { II ii = ret(CondNZ());
NEXT; }
1166CASE(C8) { II ii = ret(CondZ ());
NEXT; }
1168CASE(D8) { II ii = ret(CondC ());
NEXT; }
1169CASE(E0) { II ii = ret(CondPO());
NEXT; }
1170CASE(E8) { II ii = ret(CondPE());
NEXT; }
1171CASE(F0) { II ii = ret(CondP ());
NEXT; }
1172CASE(F8) { II ii = ret(CondM ());
NEXT; }
1174CASE(C2) { II ii = jp(CondNZ());
NEXT; }
1175CASE(CA) { II ii = jp(CondZ ());
NEXT; }
1176CASE(D2) { II ii = jp(CondNC());
NEXT; }
1177CASE(DA) { II ii = jp(CondC ());
NEXT; }
1178CASE(E2) { II ii = jp(CondPO());
NEXT; }
1179CASE(EA) { II ii = jp(CondPE());
NEXT; }
1180CASE(F2) { II ii = jp(CondP ());
NEXT; }
1181CASE(FA) { II ii = jp(CondM ());
NEXT; }
1182CASE(C3) { II ii = jp(CondTrue());
NEXT; }
1183CASE(C4) { II ii = call(CondNZ());
NEXT; }
1184CASE(CC) { II ii = call(CondZ ());
NEXT; }
1185CASE(D4) { II ii = call(CondNC());
NEXT; }
1186CASE(DC) { II ii = call(CondC ());
NEXT; }
1187CASE(E4) { II ii = call(CondPO());
NEXT; }
1188CASE(EC) { II ii = call(CondPE());
NEXT; }
1189CASE(F4) { II ii = call(CondP ());
NEXT; }
1190CASE(FC) { II ii = call(CondM ());
NEXT; }
1191CASE(CD) { II ii = call(CondTrue());
NEXT; }
1192CASE(C1) { II ii = pop_SS <BC,0>();
NEXT; }
1194CASE(E1) { II ii = pop_SS <HL,0>();
NEXT; }
1195CASE(F1) { II ii = pop_SS <AF,0>();
NEXT; }
1196CASE(C5) { II ii = push_SS<BC,0>();
NEXT; }
1197CASE(D5) { II ii = push_SS<DE,0>();
NEXT; }
1198CASE(E5) { II ii = push_SS<HL,0>();
NEXT; }
1199CASE(F5) { II ii = push_SS<AF,0>();
NEXT; }
1200CASE(C7) { II ii = rst<0x00>();
NEXT; }
1201CASE(CF) { II ii = rst<0x08>();
NEXT; }
1202CASE(D7) { II ii = rst<0x10>();
NEXT; }
1203CASE(DF) { II ii = rst<0x18>();
NEXT; }
1204CASE(E7) { II ii = rst<0x20>();
NEXT; }
1205CASE(EF) { II ii = rst<0x28>();
NEXT; }
1206CASE(F7) { II ii = rst<0x30>();
NEXT; }
1207CASE(FF) { II ii = rst<0x38>();
NEXT; }
1210 byte cb_opcode = RDMEM_OPCODE<0>(T::CC_PREFIX);
1212 switch (cb_opcode) {
1213 case 0x00: { II ii = rlc_R<B>();
NEXT; }
1214 case 0x01: { II ii = rlc_R<C>();
NEXT; }
1215 case 0x02: { II ii = rlc_R<D>();
NEXT; }
1216 case 0x03: { II ii = rlc_R<E>();
NEXT; }
1217 case 0x04: { II ii = rlc_R<H>();
NEXT; }
1218 case 0x05: { II ii = rlc_R<L>();
NEXT; }
1219 case 0x07: { II ii = rlc_R<A>();
NEXT; }
1220 case 0x06: { II ii = rlc_xhl();
NEXT; }
1221 case 0x08: { II ii = rrc_R<B>();
NEXT; }
1222 case 0x09: { II ii = rrc_R<C>();
NEXT; }
1223 case 0x0a: { II ii = rrc_R<D>();
NEXT; }
1224 case 0x0b: { II ii = rrc_R<E>();
NEXT; }
1225 case 0x0c: { II ii = rrc_R<H>();
NEXT; }
1226 case 0x0d: { II ii = rrc_R<L>();
NEXT; }
1227 case 0x0f: { II ii = rrc_R<A>();
NEXT; }
1228 case 0x0e: { II ii = rrc_xhl();
NEXT; }
1229 case 0x10: { II ii = rl_R<B>();
NEXT; }
1230 case 0x11: { II ii = rl_R<C>();
NEXT; }
1231 case 0x12: { II ii = rl_R<D>();
NEXT; }
1232 case 0x13: { II ii = rl_R<E>();
NEXT; }
1233 case 0x14: { II ii = rl_R<H>();
NEXT; }
1234 case 0x15: { II ii = rl_R<L>();
NEXT; }
1235 case 0x17: { II ii = rl_R<A>();
NEXT; }
1236 case 0x16: { II ii = rl_xhl();
NEXT; }
1237 case 0x18: { II ii = rr_R<B>();
NEXT; }
1238 case 0x19: { II ii = rr_R<C>();
NEXT; }
1239 case 0x1a: { II ii = rr_R<D>();
NEXT; }
1240 case 0x1b: { II ii = rr_R<E>();
NEXT; }
1241 case 0x1c: { II ii = rr_R<H>();
NEXT; }
1242 case 0x1d: { II ii = rr_R<L>();
NEXT; }
1243 case 0x1f: { II ii = rr_R<A>();
NEXT; }
1244 case 0x1e: { II ii = rr_xhl();
NEXT; }
1245 case 0x20: { II ii = sla_R<B>();
NEXT; }
1246 case 0x21: { II ii = sla_R<C>();
NEXT; }
1247 case 0x22: { II ii = sla_R<D>();
NEXT; }
1248 case 0x23: { II ii = sla_R<E>();
NEXT; }
1249 case 0x24: { II ii = sla_R<H>();
NEXT; }
1250 case 0x25: { II ii = sla_R<L>();
NEXT; }
1251 case 0x27: { II ii = sla_R<A>();
NEXT; }
1252 case 0x26: { II ii = sla_xhl();
NEXT; }
1253 case 0x28: { II ii = sra_R<B>();
NEXT; }
1254 case 0x29: { II ii = sra_R<C>();
NEXT; }
1255 case 0x2a: { II ii = sra_R<D>();
NEXT; }
1256 case 0x2b: { II ii = sra_R<E>();
NEXT; }
1257 case 0x2c: { II ii = sra_R<H>();
NEXT; }
1258 case 0x2d: { II ii = sra_R<L>();
NEXT; }
1259 case 0x2f: { II ii = sra_R<A>();
NEXT; }
1260 case 0x2e: { II ii = sra_xhl();
NEXT; }
1261 case 0x30: { II ii = T::IS_R800 ? sla_R<B>() : sll_R<
B>();
NEXT; }
1262 case 0x31: { II ii = T::IS_R800 ? sla_R<C>() : sll_R<
C>();
NEXT; }
1263 case 0x32: { II ii = T::IS_R800 ? sla_R<D>() : sll_R<
D>();
NEXT; }
1264 case 0x33: { II ii = T::IS_R800 ? sla_R<E>() : sll_R<
E>();
NEXT; }
1265 case 0x34: { II ii = T::IS_R800 ? sla_R<H>() : sll_R<
H>();
NEXT; }
1266 case 0x35: { II ii = T::IS_R800 ? sla_R<L>() : sll_R<
L>();
NEXT; }
1267 case 0x37: { II ii = T::IS_R800 ? sla_R<A>() : sll_R<
A>();
NEXT; }
1268 case 0x36: { II ii = T::IS_R800 ? sla_xhl() : sll_xhl();
NEXT; }
1269 case 0x38: { II ii = srl_R<B>();
NEXT; }
1270 case 0x39: { II ii = srl_R<C>();
NEXT; }
1271 case 0x3a: { II ii = srl_R<D>();
NEXT; }
1272 case 0x3b: { II ii = srl_R<E>();
NEXT; }
1273 case 0x3c: { II ii = srl_R<H>();
NEXT; }
1274 case 0x3d: { II ii = srl_R<L>();
NEXT; }
1275 case 0x3f: { II ii = srl_R<A>();
NEXT; }
1276 case 0x3e: { II ii = srl_xhl();
NEXT; }
1278 case 0x40: { II ii = bit_N_R<0,B>();
NEXT; }
1279 case 0x41: { II ii = bit_N_R<0,C>();
NEXT; }
1280 case 0x42: { II ii = bit_N_R<0,D>();
NEXT; }
1281 case 0x43: { II ii = bit_N_R<0,E>();
NEXT; }
1282 case 0x44: { II ii = bit_N_R<0,H>();
NEXT; }
1283 case 0x45: { II ii = bit_N_R<0,L>();
NEXT; }
1284 case 0x47: { II ii = bit_N_R<0,A>();
NEXT; }
1285 case 0x48: { II ii = bit_N_R<1,B>();
NEXT; }
1286 case 0x49: { II ii = bit_N_R<1,C>();
NEXT; }
1287 case 0x4a: { II ii = bit_N_R<1,D>();
NEXT; }
1288 case 0x4b: { II ii = bit_N_R<1,E>();
NEXT; }
1289 case 0x4c: { II ii = bit_N_R<1,H>();
NEXT; }
1290 case 0x4d: { II ii = bit_N_R<1,L>();
NEXT; }
1291 case 0x4f: { II ii = bit_N_R<1,A>();
NEXT; }
1292 case 0x50: { II ii = bit_N_R<2,B>();
NEXT; }
1293 case 0x51: { II ii = bit_N_R<2,C>();
NEXT; }
1294 case 0x52: { II ii = bit_N_R<2,D>();
NEXT; }
1295 case 0x53: { II ii = bit_N_R<2,E>();
NEXT; }
1296 case 0x54: { II ii = bit_N_R<2,H>();
NEXT; }
1297 case 0x55: { II ii = bit_N_R<2,L>();
NEXT; }
1298 case 0x57: { II ii = bit_N_R<2,A>();
NEXT; }
1299 case 0x58: { II ii = bit_N_R<3,B>();
NEXT; }
1300 case 0x59: { II ii = bit_N_R<3,C>();
NEXT; }
1301 case 0x5a: { II ii = bit_N_R<3,D>();
NEXT; }
1302 case 0x5b: { II ii = bit_N_R<3,E>();
NEXT; }
1303 case 0x5c: { II ii = bit_N_R<3,H>();
NEXT; }
1304 case 0x5d: { II ii = bit_N_R<3,L>();
NEXT; }
1305 case 0x5f: { II ii = bit_N_R<3,A>();
NEXT; }
1306 case 0x60: { II ii = bit_N_R<4,B>();
NEXT; }
1307 case 0x61: { II ii = bit_N_R<4,C>();
NEXT; }
1308 case 0x62: { II ii = bit_N_R<4,D>();
NEXT; }
1309 case 0x63: { II ii = bit_N_R<4,E>();
NEXT; }
1310 case 0x64: { II ii = bit_N_R<4,H>();
NEXT; }
1311 case 0x65: { II ii = bit_N_R<4,L>();
NEXT; }
1312 case 0x67: { II ii = bit_N_R<4,A>();
NEXT; }
1313 case 0x68: { II ii = bit_N_R<5,B>();
NEXT; }
1314 case 0x69: { II ii = bit_N_R<5,C>();
NEXT; }
1315 case 0x6a: { II ii = bit_N_R<5,D>();
NEXT; }
1316 case 0x6b: { II ii = bit_N_R<5,E>();
NEXT; }
1317 case 0x6c: { II ii = bit_N_R<5,H>();
NEXT; }
1318 case 0x6d: { II ii = bit_N_R<5,L>();
NEXT; }
1319 case 0x6f: { II ii = bit_N_R<5,A>();
NEXT; }
1320 case 0x70: { II ii = bit_N_R<6,B>();
NEXT; }
1321 case 0x71: { II ii = bit_N_R<6,C>();
NEXT; }
1322 case 0x72: { II ii = bit_N_R<6,D>();
NEXT; }
1323 case 0x73: { II ii = bit_N_R<6,E>();
NEXT; }
1324 case 0x74: { II ii = bit_N_R<6,H>();
NEXT; }
1325 case 0x75: { II ii = bit_N_R<6,L>();
NEXT; }
1326 case 0x77: { II ii = bit_N_R<6,A>();
NEXT; }
1327 case 0x78: { II ii = bit_N_R<7,B>();
NEXT; }
1328 case 0x79: { II ii = bit_N_R<7,C>();
NEXT; }
1329 case 0x7a: { II ii = bit_N_R<7,D>();
NEXT; }
1330 case 0x7b: { II ii = bit_N_R<7,E>();
NEXT; }
1331 case 0x7c: { II ii = bit_N_R<7,H>();
NEXT; }
1332 case 0x7d: { II ii = bit_N_R<7,L>();
NEXT; }
1333 case 0x7f: { II ii = bit_N_R<7,A>();
NEXT; }
1334 case 0x46: { II ii = bit_N_xhl<0>();
NEXT; }
1335 case 0x4e: { II ii = bit_N_xhl<1>();
NEXT; }
1336 case 0x56: { II ii = bit_N_xhl<2>();
NEXT; }
1337 case 0x5e: { II ii = bit_N_xhl<3>();
NEXT; }
1338 case 0x66: { II ii = bit_N_xhl<4>();
NEXT; }
1339 case 0x6e: { II ii = bit_N_xhl<5>();
NEXT; }
1340 case 0x76: { II ii = bit_N_xhl<6>();
NEXT; }
1341 case 0x7e: { II ii = bit_N_xhl<7>();
NEXT; }
1343 case 0x80: { II ii = res_N_R<0,B>();
NEXT; }
1344 case 0x81: { II ii = res_N_R<0,C>();
NEXT; }
1345 case 0x82: { II ii = res_N_R<0,D>();
NEXT; }
1346 case 0x83: { II ii = res_N_R<0,E>();
NEXT; }
1347 case 0x84: { II ii = res_N_R<0,H>();
NEXT; }
1348 case 0x85: { II ii = res_N_R<0,L>();
NEXT; }
1349 case 0x87: { II ii = res_N_R<0,A>();
NEXT; }
1350 case 0x88: { II ii = res_N_R<1,B>();
NEXT; }
1351 case 0x89: { II ii = res_N_R<1,C>();
NEXT; }
1352 case 0x8a: { II ii = res_N_R<1,D>();
NEXT; }
1353 case 0x8b: { II ii = res_N_R<1,E>();
NEXT; }
1354 case 0x8c: { II ii = res_N_R<1,H>();
NEXT; }
1355 case 0x8d: { II ii = res_N_R<1,L>();
NEXT; }
1356 case 0x8f: { II ii = res_N_R<1,A>();
NEXT; }
1357 case 0x90: { II ii = res_N_R<2,B>();
NEXT; }
1358 case 0x91: { II ii = res_N_R<2,C>();
NEXT; }
1359 case 0x92: { II ii = res_N_R<2,D>();
NEXT; }
1360 case 0x93: { II ii = res_N_R<2,E>();
NEXT; }
1361 case 0x94: { II ii = res_N_R<2,H>();
NEXT; }
1362 case 0x95: { II ii = res_N_R<2,L>();
NEXT; }
1363 case 0x97: { II ii = res_N_R<2,A>();
NEXT; }
1364 case 0x98: { II ii = res_N_R<3,B>();
NEXT; }
1365 case 0x99: { II ii = res_N_R<3,C>();
NEXT; }
1366 case 0x9a: { II ii = res_N_R<3,D>();
NEXT; }
1367 case 0x9b: { II ii = res_N_R<3,E>();
NEXT; }
1368 case 0x9c: { II ii = res_N_R<3,H>();
NEXT; }
1369 case 0x9d: { II ii = res_N_R<3,L>();
NEXT; }
1370 case 0x9f: { II ii = res_N_R<3,A>();
NEXT; }
1371 case 0xa0: { II ii = res_N_R<4,B>();
NEXT; }
1372 case 0xa1: { II ii = res_N_R<4,C>();
NEXT; }
1373 case 0xa2: { II ii = res_N_R<4,D>();
NEXT; }
1374 case 0xa3: { II ii = res_N_R<4,E>();
NEXT; }
1375 case 0xa4: { II ii = res_N_R<4,H>();
NEXT; }
1376 case 0xa5: { II ii = res_N_R<4,L>();
NEXT; }
1377 case 0xa7: { II ii = res_N_R<4,A>();
NEXT; }
1378 case 0xa8: { II ii = res_N_R<5,B>();
NEXT; }
1379 case 0xa9: { II ii = res_N_R<5,C>();
NEXT; }
1380 case 0xaa: { II ii = res_N_R<5,D>();
NEXT; }
1381 case 0xab: { II ii = res_N_R<5,E>();
NEXT; }
1382 case 0xac: { II ii = res_N_R<5,H>();
NEXT; }
1383 case 0xad: { II ii = res_N_R<5,L>();
NEXT; }
1384 case 0xaf: { II ii = res_N_R<5,A>();
NEXT; }
1385 case 0xb0: { II ii = res_N_R<6,B>();
NEXT; }
1386 case 0xb1: { II ii = res_N_R<6,C>();
NEXT; }
1387 case 0xb2: { II ii = res_N_R<6,D>();
NEXT; }
1388 case 0xb3: { II ii = res_N_R<6,E>();
NEXT; }
1389 case 0xb4: { II ii = res_N_R<6,H>();
NEXT; }
1390 case 0xb5: { II ii = res_N_R<6,L>();
NEXT; }
1391 case 0xb7: { II ii = res_N_R<6,A>();
NEXT; }
1392 case 0xb8: { II ii = res_N_R<7,B>();
NEXT; }
1393 case 0xb9: { II ii = res_N_R<7,C>();
NEXT; }
1394 case 0xba: { II ii = res_N_R<7,D>();
NEXT; }
1395 case 0xbb: { II ii = res_N_R<7,E>();
NEXT; }
1396 case 0xbc: { II ii = res_N_R<7,H>();
NEXT; }
1397 case 0xbd: { II ii = res_N_R<7,L>();
NEXT; }
1398 case 0xbf: { II ii = res_N_R<7,A>();
NEXT; }
1399 case 0x86: { II ii = res_N_xhl<0>();
NEXT; }
1400 case 0x8e: { II ii = res_N_xhl<1>();
NEXT; }
1401 case 0x96: { II ii = res_N_xhl<2>();
NEXT; }
1402 case 0x9e: { II ii = res_N_xhl<3>();
NEXT; }
1403 case 0xa6: { II ii = res_N_xhl<4>();
NEXT; }
1404 case 0xae: { II ii = res_N_xhl<5>();
NEXT; }
1405 case 0xb6: { II ii = res_N_xhl<6>();
NEXT; }
1406 case 0xbe: { II ii = res_N_xhl<7>();
NEXT; }
1408 case 0xc0: { II ii = set_N_R<0,B>();
NEXT; }
1409 case 0xc1: { II ii = set_N_R<0,C>();
NEXT; }
1410 case 0xc2: { II ii = set_N_R<0,D>();
NEXT; }
1411 case 0xc3: { II ii = set_N_R<0,E>();
NEXT; }
1412 case 0xc4: { II ii = set_N_R<0,H>();
NEXT; }
1413 case 0xc5: { II ii = set_N_R<0,L>();
NEXT; }
1414 case 0xc7: { II ii = set_N_R<0,A>();
NEXT; }
1415 case 0xc8: { II ii = set_N_R<1,B>();
NEXT; }
1416 case 0xc9: { II ii = set_N_R<1,C>();
NEXT; }
1417 case 0xca: { II ii = set_N_R<1,D>();
NEXT; }
1418 case 0xcb: { II ii = set_N_R<1,E>();
NEXT; }
1419 case 0xcc: { II ii = set_N_R<1,H>();
NEXT; }
1420 case 0xcd: { II ii = set_N_R<1,L>();
NEXT; }
1421 case 0xcf: { II ii = set_N_R<1,A>();
NEXT; }
1422 case 0xd0: { II ii = set_N_R<2,B>();
NEXT; }
1423 case 0xd1: { II ii = set_N_R<2,C>();
NEXT; }
1424 case 0xd2: { II ii = set_N_R<2,D>();
NEXT; }
1425 case 0xd3: { II ii = set_N_R<2,E>();
NEXT; }
1426 case 0xd4: { II ii = set_N_R<2,H>();
NEXT; }
1427 case 0xd5: { II ii = set_N_R<2,L>();
NEXT; }
1428 case 0xd7: { II ii = set_N_R<2,A>();
NEXT; }
1429 case 0xd8: { II ii = set_N_R<3,B>();
NEXT; }
1430 case 0xd9: { II ii = set_N_R<3,C>();
NEXT; }
1431 case 0xda: { II ii = set_N_R<3,D>();
NEXT; }
1432 case 0xdb: { II ii = set_N_R<3,E>();
NEXT; }
1433 case 0xdc: { II ii = set_N_R<3,H>();
NEXT; }
1434 case 0xdd: { II ii = set_N_R<3,L>();
NEXT; }
1435 case 0xdf: { II ii = set_N_R<3,A>();
NEXT; }
1436 case 0xe0: { II ii = set_N_R<4,B>();
NEXT; }
1437 case 0xe1: { II ii = set_N_R<4,C>();
NEXT; }
1438 case 0xe2: { II ii = set_N_R<4,D>();
NEXT; }
1439 case 0xe3: { II ii = set_N_R<4,E>();
NEXT; }
1440 case 0xe4: { II ii = set_N_R<4,H>();
NEXT; }
1441 case 0xe5: { II ii = set_N_R<4,L>();
NEXT; }
1442 case 0xe7: { II ii = set_N_R<4,A>();
NEXT; }
1443 case 0xe8: { II ii = set_N_R<5,B>();
NEXT; }
1444 case 0xe9: { II ii = set_N_R<5,C>();
NEXT; }
1445 case 0xea: { II ii = set_N_R<5,D>();
NEXT; }
1446 case 0xeb: { II ii = set_N_R<5,E>();
NEXT; }
1447 case 0xec: { II ii = set_N_R<5,H>();
NEXT; }
1448 case 0xed: { II ii = set_N_R<5,L>();
NEXT; }
1449 case 0xef: { II ii = set_N_R<5,A>();
NEXT; }
1450 case 0xf0: { II ii = set_N_R<6,B>();
NEXT; }
1451 case 0xf1: { II ii = set_N_R<6,C>();
NEXT; }
1452 case 0xf2: { II ii = set_N_R<6,D>();
NEXT; }
1453 case 0xf3: { II ii = set_N_R<6,E>();
NEXT; }
1454 case 0xf4: { II ii = set_N_R<6,H>();
NEXT; }
1455 case 0xf5: { II ii = set_N_R<6,L>();
NEXT; }
1456 case 0xf7: { II ii = set_N_R<6,A>();
NEXT; }
1457 case 0xf8: { II ii = set_N_R<7,B>();
NEXT; }
1458 case 0xf9: { II ii = set_N_R<7,C>();
NEXT; }
1459 case 0xfa: { II ii = set_N_R<7,D>();
NEXT; }
1460 case 0xfb: { II ii = set_N_R<7,E>();
NEXT; }
1461 case 0xfc: { II ii = set_N_R<7,H>();
NEXT; }
1462 case 0xfd: { II ii = set_N_R<7,L>();
NEXT; }
1463 case 0xff: { II ii = set_N_R<7,A>();
NEXT; }
1464 case 0xc6: { II ii = set_N_xhl<0>();
NEXT; }
1465 case 0xce: { II ii = set_N_xhl<1>();
NEXT; }
1466 case 0xd6: { II ii = set_N_xhl<2>();
NEXT; }
1467 case 0xde: { II ii = set_N_xhl<3>();
NEXT; }
1468 case 0xe6: { II ii = set_N_xhl<4>();
NEXT; }
1469 case 0xee: { II ii = set_N_xhl<5>();
NEXT; }
1470 case 0xf6: { II ii = set_N_xhl<6>();
NEXT; }
1471 case 0xfe: { II ii = set_N_xhl<7>();
NEXT; }
1477 byte ed_opcode = RDMEM_OPCODE<0>(T::CC_PREFIX);
1479 switch (ed_opcode) {
1480 case 0x00:
case 0x01:
case 0x02:
case 0x03:
1481 case 0x04:
case 0x05:
case 0x06:
case 0x07:
1482 case 0x08:
case 0x09:
case 0x0a:
case 0x0b:
1483 case 0x0c:
case 0x0d:
case 0x0e:
case 0x0f:
1484 case 0x10:
case 0x11:
case 0x12:
case 0x13:
1485 case 0x14:
case 0x15:
case 0x16:
case 0x17:
1486 case 0x18:
case 0x19:
case 0x1a:
case 0x1b:
1487 case 0x1c:
case 0x1d:
case 0x1e:
case 0x1f:
1488 case 0x20:
case 0x21:
case 0x22:
case 0x23:
1489 case 0x24:
case 0x25:
case 0x26:
case 0x27:
1490 case 0x28:
case 0x29:
case 0x2a:
case 0x2b:
1491 case 0x2c:
case 0x2d:
case 0x2e:
case 0x2f:
1492 case 0x30:
case 0x31:
case 0x32:
case 0x33:
1493 case 0x34:
case 0x35:
case 0x36:
case 0x37:
1494 case 0x38:
case 0x39:
case 0x3a:
case 0x3b:
1495 case 0x3c:
case 0x3d:
case 0x3e:
case 0x3f:
1497 case 0x77:
case 0x7f:
1499 case 0x80:
case 0x81:
case 0x82:
case 0x83:
1500 case 0x84:
case 0x85:
case 0x86:
case 0x87:
1501 case 0x88:
case 0x89:
case 0x8a:
case 0x8b:
1502 case 0x8c:
case 0x8d:
case 0x8e:
case 0x8f:
1503 case 0x90:
case 0x91:
case 0x92:
case 0x93:
1504 case 0x94:
case 0x95:
case 0x96:
case 0x97:
1505 case 0x98:
case 0x99:
case 0x9a:
case 0x9b:
1506 case 0x9c:
case 0x9d:
case 0x9e:
case 0x9f:
1507 case 0xa4:
case 0xa5:
case 0xa6:
case 0xa7:
1508 case 0xac:
case 0xad:
case 0xae:
case 0xaf:
1509 case 0xb4:
case 0xb5:
case 0xb6:
case 0xb7:
1510 case 0xbc:
case 0xbd:
case 0xbe:
case 0xbf:
1512 case 0xc0:
case 0xc2:
1513 case 0xc4:
case 0xc5:
case 0xc6:
case 0xc7:
1514 case 0xc8:
case 0xca:
case 0xcb:
1515 case 0xcc:
case 0xcd:
case 0xce:
case 0xcf:
1516 case 0xd0:
case 0xd2:
case 0xd3:
1517 case 0xd4:
case 0xd5:
case 0xd6:
case 0xd7:
1518 case 0xd8:
case 0xda:
case 0xdb:
1519 case 0xdc:
case 0xdd:
case 0xde:
case 0xdf:
1520 case 0xe0:
case 0xe1:
case 0xe2:
case 0xe3:
1521 case 0xe4:
case 0xe5:
case 0xe6:
case 0xe7:
1522 case 0xe8:
case 0xe9:
case 0xea:
case 0xeb:
1523 case 0xec:
case 0xed:
case 0xee:
case 0xef:
1524 case 0xf0:
case 0xf1:
case 0xf2:
1525 case 0xf4:
case 0xf5:
case 0xf6:
case 0xf7:
1526 case 0xf8:
case 0xf9:
case 0xfa:
case 0xfb:
1527 case 0xfc:
case 0xfd:
case 0xfe:
case 0xff:
1528 { II ii = nop();
NEXT; }
1530 case 0x40: { II ii = in_R_c<B>();
NEXT; }
1531 case 0x48: { II ii = in_R_c<C>();
NEXT; }
1532 case 0x50: { II ii = in_R_c<D>();
NEXT; }
1533 case 0x58: { II ii = in_R_c<E>();
NEXT; }
1534 case 0x60: { II ii = in_R_c<H>();
NEXT; }
1535 case 0x68: { II ii = in_R_c<L>();
NEXT; }
1536 case 0x70: { II ii = in_R_c<DUMMY>();
NEXT; }
1537 case 0x78: { II ii = in_R_c<A>();
NEXT; }
1539 case 0x41: { II ii = out_c_R<B>();
NEXT; }
1540 case 0x49: { II ii = out_c_R<C>();
NEXT; }
1541 case 0x51: { II ii = out_c_R<D>();
NEXT; }
1542 case 0x59: { II ii = out_c_R<E>();
NEXT; }
1543 case 0x61: { II ii = out_c_R<H>();
NEXT; }
1544 case 0x69: { II ii = out_c_R<L>();
NEXT; }
1545 case 0x71: { II ii = out_c_0();
NEXT; }
1546 case 0x79: { II ii = out_c_R<A>();
NEXT; }
1548 case 0x42: { II ii = sbc_hl_SS<BC>();
NEXT; }
1549 case 0x52: { II ii = sbc_hl_SS<DE>();
NEXT; }
1550 case 0x62: { II ii = sbc_hl_hl ();
NEXT; }
1551 case 0x72: { II ii = sbc_hl_SS<SP>();
NEXT; }
1553 case 0x4a: { II ii = adc_hl_SS<BC>();
NEXT; }
1554 case 0x5a: { II ii = adc_hl_SS<DE>();
NEXT; }
1555 case 0x6a: { II ii = adc_hl_hl ();
NEXT; }
1556 case 0x7a: { II ii = adc_hl_SS<SP>();
NEXT; }
1558 case 0x43: { II ii = ld_xword_SS_ED<BC>();
NEXT; }
1559 case 0x53: { II ii = ld_xword_SS_ED<DE>();
NEXT; }
1560 case 0x63: { II ii = ld_xword_SS_ED<HL>();
NEXT; }
1561 case 0x73: { II ii = ld_xword_SS_ED<SP>();
NEXT; }
1563 case 0x4b: { II ii = ld_SS_xword_ED<BC>();
NEXT; }
1564 case 0x5b: { II ii = ld_SS_xword_ED<DE>();
NEXT; }
1565 case 0x6b: { II ii = ld_SS_xword_ED<HL>();
NEXT; }
1566 case 0x7b: { II ii = ld_SS_xword_ED<SP>();
NEXT; }
1568 case 0x47: { II ii = ld_i_a();
NEXT; }
1569 case 0x4f: { II ii = ld_r_a();
NEXT; }
1570 case 0x57: { II ii = ld_a_IR<REG_I>();
if (T::IS_R800) {
NEXT; }
else {
NEXT_STOP; }}
1571 case 0x5f: { II ii = ld_a_IR<REG_R>();
if (T::IS_R800) {
NEXT; }
else {
NEXT_STOP; }}
1573 case 0x67: { II ii = rrd();
NEXT; }
1574 case 0x6f: { II ii = rld();
NEXT; }
1576 case 0x45:
case 0x4d:
case 0x55:
case 0x5d:
1577 case 0x65:
case 0x6d:
case 0x75:
case 0x7d:
1579 case 0x46:
case 0x4e:
case 0x66:
case 0x6e:
1580 { II ii = im_N<0>();
NEXT; }
1581 case 0x56:
case 0x76:
1582 { II ii = im_N<1>();
NEXT; }
1583 case 0x5e:
case 0x7e:
1584 { II ii = im_N<2>();
NEXT; }
1585 case 0x44:
case 0x4c:
case 0x54:
case 0x5c:
1586 case 0x64:
case 0x6c:
case 0x74:
case 0x7c:
1587 { II ii = neg();
NEXT; }
1589 case 0xa0: { II ii = ldi();
NEXT; }
1590 case 0xa1: { II ii = cpi();
NEXT; }
1591 case 0xa2: { II ii = ini();
NEXT; }
1592 case 0xa3: { II ii = outi();
NEXT; }
1593 case 0xa8: { II ii = ldd();
NEXT; }
1594 case 0xa9: { II ii = cpd();
NEXT; }
1595 case 0xaa: { II ii = ind();
NEXT; }
1596 case 0xab: { II ii = outd();
NEXT; }
1597 case 0xb0: { II ii = ldir();
NEXT; }
1598 case 0xb1: { II ii = cpir();
NEXT; }
1599 case 0xb2: { II ii = inir();
NEXT; }
1600 case 0xb3: { II ii = otir();
NEXT; }
1601 case 0xb8: { II ii = lddr();
NEXT; }
1602 case 0xb9: { II ii = cpdr();
NEXT; }
1603 case 0xba: { II ii = indr();
NEXT; }
1604 case 0xbb: { II ii = otdr();
NEXT; }
1606 case 0xc1: { II ii = T::IS_R800 ? mulub_a_R<B>() : nop();
NEXT; }
1607 case 0xc9: { II ii = T::IS_R800 ? mulub_a_R<C>() : nop();
NEXT; }
1608 case 0xd1: { II ii = T::IS_R800 ? mulub_a_R<D>() : nop();
NEXT; }
1609 case 0xd9: { II ii = T::IS_R800 ? mulub_a_R<E>() : nop();
NEXT; }
1610 case 0xc3: { II ii = T::IS_R800 ? muluw_hl_SS<BC>() : nop();
NEXT; }
1611 case 0xf3: { II ii = T::IS_R800 ? muluw_hl_SS<SP>() : nop();
NEXT; }
1618 byte opcodeDD = RDMEM_OPCODE<0>(T::CC_DD + T::CC_MAIN);
1794 if constexpr (T::IS_R800) {
1795 II ii = nop<T::CC_DD>();
NEXT;
1798 #ifdef USE_COMPUTED_GOTO
1799 goto *(opcodeTable[opcodeDD]);
1801 opcodeMain = opcodeDD;
1806 case 0x09: { II ii = add_SS_TT<IX,BC,T::CC_DD>();
NEXT; }
1807 case 0x19: { II ii = add_SS_TT<IX,DE,T::CC_DD>();
NEXT; }
1808 case 0x29: { II ii = add_SS_SS<IX ,T::CC_DD>();
NEXT; }
1809 case 0x39: { II ii = add_SS_TT<IX,SP,T::CC_DD>();
NEXT; }
1810 case 0x21: { II ii = ld_SS_word<IX,T::CC_DD>();
NEXT; }
1811 case 0x22: { II ii = ld_xword_SS<IX,T::CC_DD>();
NEXT; }
1812 case 0x2a: { II ii = ld_SS_xword<IX,T::CC_DD>();
NEXT; }
1813 case 0x23: { II ii = inc_SS<IX,T::CC_DD>();
NEXT; }
1814 case 0x2b: { II ii = dec_SS<IX,T::CC_DD>();
NEXT; }
1815 case 0x24: { II ii = inc_R<IXH,T::CC_DD>();
NEXT; }
1816 case 0x2c: { II ii = inc_R<IXL,T::CC_DD>();
NEXT; }
1817 case 0x25: { II ii = dec_R<IXH,T::CC_DD>();
NEXT; }
1818 case 0x2d: { II ii = dec_R<IXL,T::CC_DD>();
NEXT; }
1819 case 0x26: { II ii = ld_R_byte<IXH,T::CC_DD>();
NEXT; }
1820 case 0x2e: { II ii = ld_R_byte<IXL,T::CC_DD>();
NEXT; }
1821 case 0x34: { II ii = inc_xix<IX>();
NEXT; }
1822 case 0x35: { II ii = dec_xix<IX>();
NEXT; }
1823 case 0x36: { II ii = ld_xix_byte<IX>();
NEXT; }
1825 case 0x44: { II ii = ld_R_R<B,IXH,T::CC_DD>();
NEXT; }
1826 case 0x45: { II ii = ld_R_R<B,IXL,T::CC_DD>();
NEXT; }
1827 case 0x4c: { II ii = ld_R_R<C,IXH,T::CC_DD>();
NEXT; }
1828 case 0x4d: { II ii = ld_R_R<C,IXL,T::CC_DD>();
NEXT; }
1829 case 0x54: { II ii = ld_R_R<D,IXH,T::CC_DD>();
NEXT; }
1830 case 0x55: { II ii = ld_R_R<D,IXL,T::CC_DD>();
NEXT; }
1831 case 0x5c: { II ii = ld_R_R<E,IXH,T::CC_DD>();
NEXT; }
1832 case 0x5d: { II ii = ld_R_R<E,IXL,T::CC_DD>();
NEXT; }
1833 case 0x7c: { II ii = ld_R_R<A,IXH,T::CC_DD>();
NEXT; }
1834 case 0x7d: { II ii = ld_R_R<A,IXL,T::CC_DD>();
NEXT; }
1835 case 0x60: { II ii = ld_R_R<IXH,B,T::CC_DD>();
NEXT; }
1836 case 0x61: { II ii = ld_R_R<IXH,C,T::CC_DD>();
NEXT; }
1837 case 0x62: { II ii = ld_R_R<IXH,D,T::CC_DD>();
NEXT; }
1838 case 0x63: { II ii = ld_R_R<IXH,E,T::CC_DD>();
NEXT; }
1839 case 0x65: { II ii = ld_R_R<IXH,IXL,T::CC_DD>();
NEXT; }
1840 case 0x67: { II ii = ld_R_R<IXH,A,T::CC_DD>();
NEXT; }
1841 case 0x68: { II ii = ld_R_R<IXL,B,T::CC_DD>();
NEXT; }
1842 case 0x69: { II ii = ld_R_R<IXL,C,T::CC_DD>();
NEXT; }
1843 case 0x6a: { II ii = ld_R_R<IXL,D,T::CC_DD>();
NEXT; }
1844 case 0x6b: { II ii = ld_R_R<IXL,E,T::CC_DD>();
NEXT; }
1845 case 0x6c: { II ii = ld_R_R<IXL,IXH,T::CC_DD>();
NEXT; }
1846 case 0x6f: { II ii = ld_R_R<IXL,A,T::CC_DD>();
NEXT; }
1847 case 0x70: { II ii = ld_xix_R<IX,B>();
NEXT; }
1848 case 0x71: { II ii = ld_xix_R<IX,C>();
NEXT; }
1849 case 0x72: { II ii = ld_xix_R<IX,D>();
NEXT; }
1850 case 0x73: { II ii = ld_xix_R<IX,E>();
NEXT; }
1851 case 0x74: { II ii = ld_xix_R<IX,H>();
NEXT; }
1852 case 0x75: { II ii = ld_xix_R<IX,L>();
NEXT; }
1853 case 0x77: { II ii = ld_xix_R<IX,A>();
NEXT; }
1854 case 0x46: { II ii = ld_R_xix<B,IX>();
NEXT; }
1855 case 0x4e: { II ii = ld_R_xix<C,IX>();
NEXT; }
1856 case 0x56: { II ii = ld_R_xix<D,IX>();
NEXT; }
1857 case 0x5e: { II ii = ld_R_xix<E,IX>();
NEXT; }
1858 case 0x66: { II ii = ld_R_xix<H,IX>();
NEXT; }
1859 case 0x6e: { II ii = ld_R_xix<L,IX>();
NEXT; }
1860 case 0x7e: { II ii = ld_R_xix<A,IX>();
NEXT; }
1862 case 0x84: { II ii = add_a_R<IXH,T::CC_DD>();
NEXT; }
1863 case 0x85: { II ii = add_a_R<IXL,T::CC_DD>();
NEXT; }
1864 case 0x86: { II ii = add_a_xix<IX>();
NEXT; }
1865 case 0x8c: { II ii = adc_a_R<IXH,T::CC_DD>();
NEXT; }
1866 case 0x8d: { II ii = adc_a_R<IXL,T::CC_DD>();
NEXT; }
1867 case 0x8e: { II ii = adc_a_xix<IX>();
NEXT; }
1868 case 0x94: { II ii = sub_R<IXH,T::CC_DD>();
NEXT; }
1869 case 0x95: { II ii = sub_R<IXL,T::CC_DD>();
NEXT; }
1870 case 0x96: { II ii = sub_xix<IX>();
NEXT; }
1871 case 0x9c: { II ii = sbc_a_R<IXH,T::CC_DD>();
NEXT; }
1872 case 0x9d: { II ii = sbc_a_R<IXL,T::CC_DD>();
NEXT; }
1873 case 0x9e: { II ii = sbc_a_xix<IX>();
NEXT; }
1874 case 0xa4: { II ii = and_R<IXH,T::CC_DD>();
NEXT; }
1875 case 0xa5: { II ii = and_R<IXL,T::CC_DD>();
NEXT; }
1876 case 0xa6: { II ii = and_xix<IX>();
NEXT; }
1877 case 0xac: { II ii = xor_R<IXH,T::CC_DD>();
NEXT; }
1878 case 0xad: { II ii = xor_R<IXL,T::CC_DD>();
NEXT; }
1879 case 0xae: { II ii = xor_xix<IX>();
NEXT; }
1880 case 0xb4: { II ii = or_R<IXH,T::CC_DD>();
NEXT; }
1881 case 0xb5: { II ii = or_R<IXL,T::CC_DD>();
NEXT; }
1882 case 0xb6: { II ii = or_xix<IX>();
NEXT; }
1883 case 0xbc: { II ii = cp_R<IXH,T::CC_DD>();
NEXT; }
1884 case 0xbd: { II ii = cp_R<IXL,T::CC_DD>();
NEXT; }
1885 case 0xbe: { II ii = cp_xix<IX>();
NEXT; }
1887 case 0xe1: { II ii = pop_SS <IX,T::CC_DD>();
NEXT; }
1888 case 0xe5: { II ii = push_SS<IX,T::CC_DD>();
NEXT; }
1889 case 0xe3: { II ii = ex_xsp_SS<IX,T::CC_DD>();
NEXT; }
1890 case 0xe9: { II ii = jp_SS<IX,T::CC_DD>();
NEXT; }
1891 case 0xf9: { II ii = ld_sp_SS<IX,T::CC_DD>();
NEXT; }
1892 case 0xcb: ixy = getIX();
goto xx_cb;
1894 if constexpr (T::IS_R800) {
1895 II ii = nop<T::CC_DD>();
NEXT;
1897 T::add(T::CC_DD);
goto opDD_2;
1900 if constexpr (T::IS_R800) {
1901 II ii = nop<T::CC_DD>();
NEXT;
1903 T::add(T::CC_DD);
goto opFD_2;
1911 byte opcodeFD = RDMEM_OPCODE<0>(T::CC_DD + T::CC_MAIN);
2087 if constexpr (T::IS_R800) {
2088 II ii = nop<T::CC_DD>();
NEXT;
2091 #ifdef USE_COMPUTED_GOTO
2092 goto *(opcodeTable[opcodeFD]);
2094 opcodeMain = opcodeFD;
2099 case 0x09: { II ii = add_SS_TT<IY,BC,T::CC_DD>();
NEXT; }
2100 case 0x19: { II ii = add_SS_TT<IY,DE,T::CC_DD>();
NEXT; }
2101 case 0x29: { II ii = add_SS_SS<IY ,T::CC_DD>();
NEXT; }
2102 case 0x39: { II ii = add_SS_TT<IY,SP,T::CC_DD>();
NEXT; }
2103 case 0x21: { II ii = ld_SS_word<IY,T::CC_DD>();
NEXT; }
2104 case 0x22: { II ii = ld_xword_SS<IY,T::CC_DD>();
NEXT; }
2105 case 0x2a: { II ii = ld_SS_xword<IY,T::CC_DD>();
NEXT; }
2106 case 0x23: { II ii = inc_SS<IY,T::CC_DD>();
NEXT; }
2107 case 0x2b: { II ii = dec_SS<IY,T::CC_DD>();
NEXT; }
2108 case 0x24: { II ii = inc_R<IYH,T::CC_DD>();
NEXT; }
2109 case 0x2c: { II ii = inc_R<IYL,T::CC_DD>();
NEXT; }
2110 case 0x25: { II ii = dec_R<IYH,T::CC_DD>();
NEXT; }
2111 case 0x2d: { II ii = dec_R<IYL,T::CC_DD>();
NEXT; }
2112 case 0x26: { II ii = ld_R_byte<IYH,T::CC_DD>();
NEXT; }
2113 case 0x2e: { II ii = ld_R_byte<IYL,T::CC_DD>();
NEXT; }
2114 case 0x34: { II ii = inc_xix<IY>();
NEXT; }
2115 case 0x35: { II ii = dec_xix<IY>();
NEXT; }
2116 case 0x36: { II ii = ld_xix_byte<IY>();
NEXT; }
2118 case 0x44: { II ii = ld_R_R<B,IYH,T::CC_DD>();
NEXT; }
2119 case 0x45: { II ii = ld_R_R<B,IYL,T::CC_DD>();
NEXT; }
2120 case 0x4c: { II ii = ld_R_R<C,IYH,T::CC_DD>();
NEXT; }
2121 case 0x4d: { II ii = ld_R_R<C,IYL,T::CC_DD>();
NEXT; }
2122 case 0x54: { II ii = ld_R_R<D,IYH,T::CC_DD>();
NEXT; }
2123 case 0x55: { II ii = ld_R_R<D,IYL,T::CC_DD>();
NEXT; }
2124 case 0x5c: { II ii = ld_R_R<E,IYH,T::CC_DD>();
NEXT; }
2125 case 0x5d: { II ii = ld_R_R<E,IYL,T::CC_DD>();
NEXT; }
2126 case 0x7c: { II ii = ld_R_R<A,IYH,T::CC_DD>();
NEXT; }
2127 case 0x7d: { II ii = ld_R_R<A,IYL,T::CC_DD>();
NEXT; }
2128 case 0x60: { II ii = ld_R_R<IYH,B,T::CC_DD>();
NEXT; }
2129 case 0x61: { II ii = ld_R_R<IYH,C,T::CC_DD>();
NEXT; }
2130 case 0x62: { II ii = ld_R_R<IYH,D,T::CC_DD>();
NEXT; }
2131 case 0x63: { II ii = ld_R_R<IYH,E,T::CC_DD>();
NEXT; }
2132 case 0x65: { II ii = ld_R_R<IYH,IYL,T::CC_DD>();
NEXT; }
2133 case 0x67: { II ii = ld_R_R<IYH,A,T::CC_DD>();
NEXT; }
2134 case 0x68: { II ii = ld_R_R<IYL,B,T::CC_DD>();
NEXT; }
2135 case 0x69: { II ii = ld_R_R<IYL,C,T::CC_DD>();
NEXT; }
2136 case 0x6a: { II ii = ld_R_R<IYL,D,T::CC_DD>();
NEXT; }
2137 case 0x6b: { II ii = ld_R_R<IYL,E,T::CC_DD>();
NEXT; }
2138 case 0x6c: { II ii = ld_R_R<IYL,IYH,T::CC_DD>();
NEXT; }
2139 case 0x6f: { II ii = ld_R_R<IYL,A,T::CC_DD>();
NEXT; }
2140 case 0x70: { II ii = ld_xix_R<IY,B>();
NEXT; }
2141 case 0x71: { II ii = ld_xix_R<IY,C>();
NEXT; }
2142 case 0x72: { II ii = ld_xix_R<IY,D>();
NEXT; }
2143 case 0x73: { II ii = ld_xix_R<IY,E>();
NEXT; }
2144 case 0x74: { II ii = ld_xix_R<IY,H>();
NEXT; }
2145 case 0x75: { II ii = ld_xix_R<IY,L>();
NEXT; }
2146 case 0x77: { II ii = ld_xix_R<IY,A>();
NEXT; }
2147 case 0x46: { II ii = ld_R_xix<B,IY>();
NEXT; }
2148 case 0x4e: { II ii = ld_R_xix<C,IY>();
NEXT; }
2149 case 0x56: { II ii = ld_R_xix<D,IY>();
NEXT; }
2150 case 0x5e: { II ii = ld_R_xix<E,IY>();
NEXT; }
2151 case 0x66: { II ii = ld_R_xix<H,IY>();
NEXT; }
2152 case 0x6e: { II ii = ld_R_xix<L,IY>();
NEXT; }
2153 case 0x7e: { II ii = ld_R_xix<A,IY>();
NEXT; }
2155 case 0x84: { II ii = add_a_R<IYH,T::CC_DD>();
NEXT; }
2156 case 0x85: { II ii = add_a_R<IYL,T::CC_DD>();
NEXT; }
2157 case 0x86: { II ii = add_a_xix<IY>();
NEXT; }
2158 case 0x8c: { II ii = adc_a_R<IYH,T::CC_DD>();
NEXT; }
2159 case 0x8d: { II ii = adc_a_R<IYL,T::CC_DD>();
NEXT; }
2160 case 0x8e: { II ii = adc_a_xix<IY>();
NEXT; }
2161 case 0x94: { II ii = sub_R<IYH,T::CC_DD>();
NEXT; }
2162 case 0x95: { II ii = sub_R<IYL,T::CC_DD>();
NEXT; }
2163 case 0x96: { II ii = sub_xix<IY>();
NEXT; }
2164 case 0x9c: { II ii = sbc_a_R<IYH,T::CC_DD>();
NEXT; }
2165 case 0x9d: { II ii = sbc_a_R<IYL,T::CC_DD>();
NEXT; }
2166 case 0x9e: { II ii = sbc_a_xix<IY>();
NEXT; }
2167 case 0xa4: { II ii = and_R<IYH,T::CC_DD>();
NEXT; }
2168 case 0xa5: { II ii = and_R<IYL,T::CC_DD>();
NEXT; }
2169 case 0xa6: { II ii = and_xix<IY>();
NEXT; }
2170 case 0xac: { II ii = xor_R<IYH,T::CC_DD>();
NEXT; }
2171 case 0xad: { II ii = xor_R<IYL,T::CC_DD>();
NEXT; }
2172 case 0xae: { II ii = xor_xix<IY>();
NEXT; }
2173 case 0xb4: { II ii = or_R<IYH,T::CC_DD>();
NEXT; }
2174 case 0xb5: { II ii = or_R<IYL,T::CC_DD>();
NEXT; }
2175 case 0xb6: { II ii = or_xix<IY>();
NEXT; }
2176 case 0xbc: { II ii = cp_R<IYH,T::CC_DD>();
NEXT; }
2177 case 0xbd: { II ii = cp_R<IYL,T::CC_DD>();
NEXT; }
2178 case 0xbe: { II ii = cp_xix<IY>();
NEXT; }
2180 case 0xe1: { II ii = pop_SS <IY,T::CC_DD>();
NEXT; }
2181 case 0xe5: { II ii = push_SS<IY,T::CC_DD>();
NEXT; }
2182 case 0xe3: { II ii = ex_xsp_SS<IY,T::CC_DD>();
NEXT; }
2183 case 0xe9: { II ii = jp_SS<IY,T::CC_DD>();
NEXT; }
2184 case 0xf9: { II ii = ld_sp_SS<IY,T::CC_DD>();
NEXT; }
2185 case 0xcb: ixy = getIY();
goto xx_cb;
2187 if constexpr (T::IS_R800) {
2188 II ii = nop<T::CC_DD>();
NEXT;
2190 T::add(T::CC_DD);
goto opDD_2;
2193 if constexpr (T::IS_R800) {
2194 II ii = nop<T::CC_DD>();
NEXT;
2196 T::add(T::CC_DD);
goto opFD_2;
2201#ifndef USE_COMPUTED_GOTO
2207 unsigned tmp = RD_WORD_PC<1>(T::CC_DD + T::CC_DD_CB);
2208 auto ofst = narrow_cast<int8_t>(tmp & 0xFF);
2209 unsigned addr = narrow_cast<word>(ixy + ofst);
2210 auto xxcb_opcode = narrow_cast<byte>(tmp >> 8);
2211 switch (xxcb_opcode) {
2212 case 0x00: { II ii = rlc_xix_R<B>(addr);
NEXT; }
2213 case 0x01: { II ii = rlc_xix_R<C>(addr);
NEXT; }
2214 case 0x02: { II ii = rlc_xix_R<D>(addr);
NEXT; }
2215 case 0x03: { II ii = rlc_xix_R<E>(addr);
NEXT; }
2216 case 0x04: { II ii = rlc_xix_R<H>(addr);
NEXT; }
2217 case 0x05: { II ii = rlc_xix_R<L>(addr);
NEXT; }
2218 case 0x06: { II ii = rlc_xix_R<DUMMY>(addr);
NEXT; }
2219 case 0x07: { II ii = rlc_xix_R<A>(addr);
NEXT; }
2220 case 0x08: { II ii = rrc_xix_R<B>(addr);
NEXT; }
2221 case 0x09: { II ii = rrc_xix_R<C>(addr);
NEXT; }
2222 case 0x0a: { II ii = rrc_xix_R<D>(addr);
NEXT; }
2223 case 0x0b: { II ii = rrc_xix_R<E>(addr);
NEXT; }
2224 case 0x0c: { II ii = rrc_xix_R<H>(addr);
NEXT; }
2225 case 0x0d: { II ii = rrc_xix_R<L>(addr);
NEXT; }
2226 case 0x0e: { II ii = rrc_xix_R<DUMMY>(addr);
NEXT; }
2227 case 0x0f: { II ii = rrc_xix_R<A>(addr);
NEXT; }
2228 case 0x10: { II ii = rl_xix_R<B>(addr);
NEXT; }
2229 case 0x11: { II ii = rl_xix_R<C>(addr);
NEXT; }
2230 case 0x12: { II ii = rl_xix_R<D>(addr);
NEXT; }
2231 case 0x13: { II ii = rl_xix_R<E>(addr);
NEXT; }
2232 case 0x14: { II ii = rl_xix_R<H>(addr);
NEXT; }
2233 case 0x15: { II ii = rl_xix_R<L>(addr);
NEXT; }
2234 case 0x16: { II ii = rl_xix_R<DUMMY>(addr);
NEXT; }
2235 case 0x17: { II ii = rl_xix_R<A>(addr);
NEXT; }
2236 case 0x18: { II ii = rr_xix_R<B>(addr);
NEXT; }
2237 case 0x19: { II ii = rr_xix_R<C>(addr);
NEXT; }
2238 case 0x1a: { II ii = rr_xix_R<D>(addr);
NEXT; }
2239 case 0x1b: { II ii = rr_xix_R<E>(addr);
NEXT; }
2240 case 0x1c: { II ii = rr_xix_R<H>(addr);
NEXT; }
2241 case 0x1d: { II ii = rr_xix_R<L>(addr);
NEXT; }
2242 case 0x1e: { II ii = rr_xix_R<DUMMY>(addr);
NEXT; }
2243 case 0x1f: { II ii = rr_xix_R<A>(addr);
NEXT; }
2244 case 0x20: { II ii = sla_xix_R<B>(addr);
NEXT; }
2245 case 0x21: { II ii = sla_xix_R<C>(addr);
NEXT; }
2246 case 0x22: { II ii = sla_xix_R<D>(addr);
NEXT; }
2247 case 0x23: { II ii = sla_xix_R<E>(addr);
NEXT; }
2248 case 0x24: { II ii = sla_xix_R<H>(addr);
NEXT; }
2249 case 0x25: { II ii = sla_xix_R<L>(addr);
NEXT; }
2250 case 0x26: { II ii = sla_xix_R<DUMMY>(addr);
NEXT; }
2251 case 0x27: { II ii = sla_xix_R<A>(addr);
NEXT; }
2252 case 0x28: { II ii = sra_xix_R<B>(addr);
NEXT; }
2253 case 0x29: { II ii = sra_xix_R<C>(addr);
NEXT; }
2254 case 0x2a: { II ii = sra_xix_R<D>(addr);
NEXT; }
2255 case 0x2b: { II ii = sra_xix_R<E>(addr);
NEXT; }
2256 case 0x2c: { II ii = sra_xix_R<H>(addr);
NEXT; }
2257 case 0x2d: { II ii = sra_xix_R<L>(addr);
NEXT; }
2258 case 0x2e: { II ii = sra_xix_R<DUMMY>(addr);
NEXT; }
2259 case 0x2f: { II ii = sra_xix_R<A>(addr);
NEXT; }
2260 case 0x30: { II ii = T::IS_R800 ? sll2() : sll_xix_R<
B>(addr);
NEXT; }
2261 case 0x31: { II ii = T::IS_R800 ? sll2() : sll_xix_R<
C>(addr);
NEXT; }
2262 case 0x32: { II ii = T::IS_R800 ? sll2() : sll_xix_R<
D>(addr);
NEXT; }
2263 case 0x33: { II ii = T::IS_R800 ? sll2() : sll_xix_R<
E>(addr);
NEXT; }
2264 case 0x34: { II ii = T::IS_R800 ? sll2() : sll_xix_R<
H>(addr);
NEXT; }
2265 case 0x35: { II ii = T::IS_R800 ? sll2() : sll_xix_R<
L>(addr);
NEXT; }
2266 case 0x36: { II ii = T::IS_R800 ? sll2() : sll_xix_R<
DUMMY>(addr);
NEXT; }
2267 case 0x37: { II ii = T::IS_R800 ? sll2() : sll_xix_R<
A>(addr);
NEXT; }
2268 case 0x38: { II ii = srl_xix_R<B>(addr);
NEXT; }
2269 case 0x39: { II ii = srl_xix_R<C>(addr);
NEXT; }
2270 case 0x3a: { II ii = srl_xix_R<D>(addr);
NEXT; }
2271 case 0x3b: { II ii = srl_xix_R<E>(addr);
NEXT; }
2272 case 0x3c: { II ii = srl_xix_R<H>(addr);
NEXT; }
2273 case 0x3d: { II ii = srl_xix_R<L>(addr);
NEXT; }
2274 case 0x3e: { II ii = srl_xix_R<DUMMY>(addr);
NEXT; }
2275 case 0x3f: { II ii = srl_xix_R<A>(addr);
NEXT; }
2277 case 0x40:
case 0x41:
case 0x42:
case 0x43:
2278 case 0x44:
case 0x45:
case 0x46:
case 0x47:
2279 { II ii = bit_N_xix<0>(addr);
NEXT; }
2280 case 0x48:
case 0x49:
case 0x4a:
case 0x4b:
2281 case 0x4c:
case 0x4d:
case 0x4e:
case 0x4f:
2282 { II ii = bit_N_xix<1>(addr);
NEXT; }
2283 case 0x50:
case 0x51:
case 0x52:
case 0x53:
2284 case 0x54:
case 0x55:
case 0x56:
case 0x57:
2285 { II ii = bit_N_xix<2>(addr);
NEXT; }
2286 case 0x58:
case 0x59:
case 0x5a:
case 0x5b:
2287 case 0x5c:
case 0x5d:
case 0x5e:
case 0x5f:
2288 { II ii = bit_N_xix<3>(addr);
NEXT; }
2289 case 0x60:
case 0x61:
case 0x62:
case 0x63:
2290 case 0x64:
case 0x65:
case 0x66:
case 0x67:
2291 { II ii = bit_N_xix<4>(addr);
NEXT; }
2292 case 0x68:
case 0x69:
case 0x6a:
case 0x6b:
2293 case 0x6c:
case 0x6d:
case 0x6e:
case 0x6f:
2294 { II ii = bit_N_xix<5>(addr);
NEXT; }
2295 case 0x70:
case 0x71:
case 0x72:
case 0x73:
2296 case 0x74:
case 0x75:
case 0x76:
case 0x77:
2297 { II ii = bit_N_xix<6>(addr);
NEXT; }
2298 case 0x78:
case 0x79:
case 0x7a:
case 0x7b:
2299 case 0x7c:
case 0x7d:
case 0x7e:
case 0x7f:
2300 { II ii = bit_N_xix<7>(addr);
NEXT; }
2302 case 0x80: { II ii = res_N_xix_R<0,B>(addr);
NEXT; }
2303 case 0x81: { II ii = res_N_xix_R<0,C>(addr);
NEXT; }
2304 case 0x82: { II ii = res_N_xix_R<0,D>(addr);
NEXT; }
2305 case 0x83: { II ii = res_N_xix_R<0,E>(addr);
NEXT; }
2306 case 0x84: { II ii = res_N_xix_R<0,H>(addr);
NEXT; }
2307 case 0x85: { II ii = res_N_xix_R<0,L>(addr);
NEXT; }
2308 case 0x87: { II ii = res_N_xix_R<0,A>(addr);
NEXT; }
2309 case 0x88: { II ii = res_N_xix_R<1,B>(addr);
NEXT; }
2310 case 0x89: { II ii = res_N_xix_R<1,C>(addr);
NEXT; }
2311 case 0x8a: { II ii = res_N_xix_R<1,D>(addr);
NEXT; }
2312 case 0x8b: { II ii = res_N_xix_R<1,E>(addr);
NEXT; }
2313 case 0x8c: { II ii = res_N_xix_R<1,H>(addr);
NEXT; }
2314 case 0x8d: { II ii = res_N_xix_R<1,L>(addr);
NEXT; }
2315 case 0x8f: { II ii = res_N_xix_R<1,A>(addr);
NEXT; }
2316 case 0x90: { II ii = res_N_xix_R<2,B>(addr);
NEXT; }
2317 case 0x91: { II ii = res_N_xix_R<2,C>(addr);
NEXT; }
2318 case 0x92: { II ii = res_N_xix_R<2,D>(addr);
NEXT; }
2319 case 0x93: { II ii = res_N_xix_R<2,E>(addr);
NEXT; }
2320 case 0x94: { II ii = res_N_xix_R<2,H>(addr);
NEXT; }
2321 case 0x95: { II ii = res_N_xix_R<2,L>(addr);
NEXT; }
2322 case 0x97: { II ii = res_N_xix_R<2,A>(addr);
NEXT; }
2323 case 0x98: { II ii = res_N_xix_R<3,B>(addr);
NEXT; }
2324 case 0x99: { II ii = res_N_xix_R<3,C>(addr);
NEXT; }
2325 case 0x9a: { II ii = res_N_xix_R<3,D>(addr);
NEXT; }
2326 case 0x9b: { II ii = res_N_xix_R<3,E>(addr);
NEXT; }
2327 case 0x9c: { II ii = res_N_xix_R<3,H>(addr);
NEXT; }
2328 case 0x9d: { II ii = res_N_xix_R<3,L>(addr);
NEXT; }
2329 case 0x9f: { II ii = res_N_xix_R<3,A>(addr);
NEXT; }
2330 case 0xa0: { II ii = res_N_xix_R<4,B>(addr);
NEXT; }
2331 case 0xa1: { II ii = res_N_xix_R<4,C>(addr);
NEXT; }
2332 case 0xa2: { II ii = res_N_xix_R<4,D>(addr);
NEXT; }
2333 case 0xa3: { II ii = res_N_xix_R<4,E>(addr);
NEXT; }
2334 case 0xa4: { II ii = res_N_xix_R<4,H>(addr);
NEXT; }
2335 case 0xa5: { II ii = res_N_xix_R<4,L>(addr);
NEXT; }
2336 case 0xa7: { II ii = res_N_xix_R<4,A>(addr);
NEXT; }
2337 case 0xa8: { II ii = res_N_xix_R<5,B>(addr);
NEXT; }
2338 case 0xa9: { II ii = res_N_xix_R<5,C>(addr);
NEXT; }
2339 case 0xaa: { II ii = res_N_xix_R<5,D>(addr);
NEXT; }
2340 case 0xab: { II ii = res_N_xix_R<5,E>(addr);
NEXT; }
2341 case 0xac: { II ii = res_N_xix_R<5,H>(addr);
NEXT; }
2342 case 0xad: { II ii = res_N_xix_R<5,L>(addr);
NEXT; }
2343 case 0xaf: { II ii = res_N_xix_R<5,A>(addr);
NEXT; }
2344 case 0xb0: { II ii = res_N_xix_R<6,B>(addr);
NEXT; }
2345 case 0xb1: { II ii = res_N_xix_R<6,C>(addr);
NEXT; }
2346 case 0xb2: { II ii = res_N_xix_R<6,D>(addr);
NEXT; }
2347 case 0xb3: { II ii = res_N_xix_R<6,E>(addr);
NEXT; }
2348 case 0xb4: { II ii = res_N_xix_R<6,H>(addr);
NEXT; }
2349 case 0xb5: { II ii = res_N_xix_R<6,L>(addr);
NEXT; }
2350 case 0xb7: { II ii = res_N_xix_R<6,A>(addr);
NEXT; }
2351 case 0xb8: { II ii = res_N_xix_R<7,B>(addr);
NEXT; }
2352 case 0xb9: { II ii = res_N_xix_R<7,C>(addr);
NEXT; }
2353 case 0xba: { II ii = res_N_xix_R<7,D>(addr);
NEXT; }
2354 case 0xbb: { II ii = res_N_xix_R<7,E>(addr);
NEXT; }
2355 case 0xbc: { II ii = res_N_xix_R<7,H>(addr);
NEXT; }
2356 case 0xbd: { II ii = res_N_xix_R<7,L>(addr);
NEXT; }
2357 case 0xbf: { II ii = res_N_xix_R<7,A>(addr);
NEXT; }
2358 case 0x86: { II ii = res_N_xix_R<0,DUMMY>(addr);
NEXT; }
2359 case 0x8e: { II ii = res_N_xix_R<1,DUMMY>(addr);
NEXT; }
2360 case 0x96: { II ii = res_N_xix_R<2,DUMMY>(addr);
NEXT; }
2361 case 0x9e: { II ii = res_N_xix_R<3,DUMMY>(addr);
NEXT; }
2362 case 0xa6: { II ii = res_N_xix_R<4,DUMMY>(addr);
NEXT; }
2363 case 0xae: { II ii = res_N_xix_R<5,DUMMY>(addr);
NEXT; }
2364 case 0xb6: { II ii = res_N_xix_R<6,DUMMY>(addr);
NEXT; }
2365 case 0xbe: { II ii = res_N_xix_R<7,DUMMY>(addr);
NEXT; }
2367 case 0xc0: { II ii = set_N_xix_R<0,B>(addr);
NEXT; }
2368 case 0xc1: { II ii = set_N_xix_R<0,C>(addr);
NEXT; }
2369 case 0xc2: { II ii = set_N_xix_R<0,D>(addr);
NEXT; }
2370 case 0xc3: { II ii = set_N_xix_R<0,E>(addr);
NEXT; }
2371 case 0xc4: { II ii = set_N_xix_R<0,H>(addr);
NEXT; }
2372 case 0xc5: { II ii = set_N_xix_R<0,L>(addr);
NEXT; }
2373 case 0xc7: { II ii = set_N_xix_R<0,A>(addr);
NEXT; }
2374 case 0xc8: { II ii = set_N_xix_R<1,B>(addr);
NEXT; }
2375 case 0xc9: { II ii = set_N_xix_R<1,C>(addr);
NEXT; }
2376 case 0xca: { II ii = set_N_xix_R<1,D>(addr);
NEXT; }
2377 case 0xcb: { II ii = set_N_xix_R<1,E>(addr);
NEXT; }
2378 case 0xcc: { II ii = set_N_xix_R<1,H>(addr);
NEXT; }
2379 case 0xcd: { II ii = set_N_xix_R<1,L>(addr);
NEXT; }
2380 case 0xcf: { II ii = set_N_xix_R<1,A>(addr);
NEXT; }
2381 case 0xd0: { II ii = set_N_xix_R<2,B>(addr);
NEXT; }
2382 case 0xd1: { II ii = set_N_xix_R<2,C>(addr);
NEXT; }
2383 case 0xd2: { II ii = set_N_xix_R<2,D>(addr);
NEXT; }
2384 case 0xd3: { II ii = set_N_xix_R<2,E>(addr);
NEXT; }
2385 case 0xd4: { II ii = set_N_xix_R<2,H>(addr);
NEXT; }
2386 case 0xd5: { II ii = set_N_xix_R<2,L>(addr);
NEXT; }
2387 case 0xd7: { II ii = set_N_xix_R<2,A>(addr);
NEXT; }
2388 case 0xd8: { II ii = set_N_xix_R<3,B>(addr);
NEXT; }
2389 case 0xd9: { II ii = set_N_xix_R<3,C>(addr);
NEXT; }
2390 case 0xda: { II ii = set_N_xix_R<3,D>(addr);
NEXT; }
2391 case 0xdb: { II ii = set_N_xix_R<3,E>(addr);
NEXT; }
2392 case 0xdc: { II ii = set_N_xix_R<3,H>(addr);
NEXT; }
2393 case 0xdd: { II ii = set_N_xix_R<3,L>(addr);
NEXT; }
2394 case 0xdf: { II ii = set_N_xix_R<3,A>(addr);
NEXT; }
2395 case 0xe0: { II ii = set_N_xix_R<4,B>(addr);
NEXT; }
2396 case 0xe1: { II ii = set_N_xix_R<4,C>(addr);
NEXT; }
2397 case 0xe2: { II ii = set_N_xix_R<4,D>(addr);
NEXT; }
2398 case 0xe3: { II ii = set_N_xix_R<4,E>(addr);
NEXT; }
2399 case 0xe4: { II ii = set_N_xix_R<4,H>(addr);
NEXT; }
2400 case 0xe5: { II ii = set_N_xix_R<4,L>(addr);
NEXT; }
2401 case 0xe7: { II ii = set_N_xix_R<4,A>(addr);
NEXT; }
2402 case 0xe8: { II ii = set_N_xix_R<5,B>(addr);
NEXT; }
2403 case 0xe9: { II ii = set_N_xix_R<5,C>(addr);
NEXT; }
2404 case 0xea: { II ii = set_N_xix_R<5,D>(addr);
NEXT; }
2405 case 0xeb: { II ii = set_N_xix_R<5,E>(addr);
NEXT; }
2406 case 0xec: { II ii = set_N_xix_R<5,H>(addr);
NEXT; }
2407 case 0xed: { II ii = set_N_xix_R<5,L>(addr);
NEXT; }
2408 case 0xef: { II ii = set_N_xix_R<5,A>(addr);
NEXT; }
2409 case 0xf0: { II ii = set_N_xix_R<6,B>(addr);
NEXT; }
2410 case 0xf1: { II ii = set_N_xix_R<6,C>(addr);
NEXT; }
2411 case 0xf2: { II ii = set_N_xix_R<6,D>(addr);
NEXT; }
2412 case 0xf3: { II ii = set_N_xix_R<6,E>(addr);
NEXT; }
2413 case 0xf4: { II ii = set_N_xix_R<6,H>(addr);
NEXT; }
2414 case 0xf5: { II ii = set_N_xix_R<6,L>(addr);
NEXT; }
2415 case 0xf7: { II ii = set_N_xix_R<6,A>(addr);
NEXT; }
2416 case 0xf8: { II ii = set_N_xix_R<7,B>(addr);
NEXT; }
2417 case 0xf9: { II ii = set_N_xix_R<7,C>(addr);
NEXT; }
2418 case 0xfa: { II ii = set_N_xix_R<7,D>(addr);
NEXT; }
2419 case 0xfb: { II ii = set_N_xix_R<7,E>(addr);
NEXT; }
2420 case 0xfc: { II ii = set_N_xix_R<7,H>(addr);
NEXT; }
2421 case 0xfd: { II ii = set_N_xix_R<7,L>(addr);
NEXT; }
2422 case 0xff: { II ii = set_N_xix_R<7,A>(addr);
NEXT; }
2423 case 0xc6: { II ii = set_N_xix_R<0,DUMMY>(addr);
NEXT; }
2424 case 0xce: { II ii = set_N_xix_R<1,DUMMY>(addr);
NEXT; }
2425 case 0xd6: { II ii = set_N_xix_R<2,DUMMY>(addr);
NEXT; }
2426 case 0xde: { II ii = set_N_xix_R<3,DUMMY>(addr);
NEXT; }
2427 case 0xe6: { II ii = set_N_xix_R<4,DUMMY>(addr);
NEXT; }
2428 case 0xee: { II ii = set_N_xix_R<5,DUMMY>(addr);
NEXT; }
2429 case 0xf6: { II ii = set_N_xix_R<6,DUMMY>(addr);
NEXT; }
2430 case 0xfe: { II ii = set_N_xix_R<7,DUMMY>(addr);
NEXT; }
2436template<
typename T>
inline void CPUCore<T>::cpuTracePre()
2440template<
typename T>
inline void CPUCore<T>::cpuTracePost()
2442 if (tracingEnabled) [[unlikely]] {
2443 cpuTracePost_slow();
2446template<
typename T>
void CPUCore<T>::cpuTracePost_slow()
2448 std::array<byte, 4> opBuf;
2449 std::string dasmOutput;
2450 dasm(*interface, start_pc, opBuf, dasmOutput, T::getTimeFast());
2451 dasmOutput.resize(19,
' ');
2452 std::cout << strCat(hex_string<4>(start_pc),
2454 " AF=", hex_string<4>(getAF()),
2455 " BC=", hex_string<4>(getBC()),
2456 " DE=", hex_string<4>(getDE()),
2457 " HL=", hex_string<4>(getHL()),
2458 " IX=", hex_string<4>(getIX()),
2459 " IY=", hex_string<4>(getIY()),
2460 " SP=", hex_string<4>(getSP()),
2465template<
typename T>
ExecIRQ CPUCore<T>::getExecIRQ()
const
2468 if (IRQStatus && getIFF1() && !prevWasEI()) [[unlikely]]
return ExecIRQ::IRQ;
2472template<
typename T>
void CPUCore<T>::executeSlow(
ExecIRQ execIRQ)
2479 if (prevWasLDAI()) [[unlikely]] {
2497 assert(getF() & V_FLAG);
2498 setF(getF() & ~V_FLAG);
2511 }
else if (getHALT()) [[unlikely]] {
2513 incR(narrow_cast<byte>(T::advanceHalt(T::HALT_STATES, scheduler.getNext())));
2514 setSlowInstructions();
2517 assert(T::limitReached());
2518 executeInstructions();
2521 if constexpr (T::IS_R800) {
2522 if ((prev2WasCall()) && (!prevWasPopRet())) [[unlikely]] {
2544 assert(fastForward || !interface->isBreaked());
2546 interface->setFastForward(
true);
2548 execute2(fastForward);
2549 interface->setFastForward(
false);
2558 scheduler.schedule(T::getTime());
2559 setSlowInstructions();
2565 (!interface->anyBreakPoints() && !tracingEnabled)) {
2568 if (slowInstructions) {
2570 executeSlow(getExecIRQ());
2571 scheduler.schedule(T::getTimeFast());
2573 while (slowInstructions == 0) {
2575 if (!T::limitReached()) [[likely]] {
2577 executeInstructions();
2582 scheduler.schedule(T::getTimeFast());
2583 if (needExitCPULoop())
return;
2586 }
while (!needExitCPULoop());
2589 if (slowInstructions == 0) {
2591 assert(T::limitReached());
2592 executeInstructions();
2597 executeSlow(getExecIRQ());
2602 scheduler.schedule(T::getTime());
2635 auto execIRQ = getExecIRQ();
2637 interface->checkBreakPoints(getPC())) {
2638 assert(interface->isBreaked());
2641 }
while (!needExitCPULoop());
2646 if constexpr (R8 ==
A) {
return getA(); }
2647 else if constexpr (R8 ==
F) {
return getF(); }
2648 else if constexpr (R8 ==
B) {
return getB(); }
2649 else if constexpr (R8 ==
C) {
return getC(); }
2650 else if constexpr (R8 ==
D) {
return getD(); }
2651 else if constexpr (R8 ==
E) {
return getE(); }
2652 else if constexpr (R8 ==
H) {
return getH(); }
2653 else if constexpr (R8 ==
L) {
return getL(); }
2654 else if constexpr (R8 ==
IXH) {
return getIXh(); }
2655 else if constexpr (R8 ==
IXL) {
return getIXl(); }
2656 else if constexpr (R8 ==
IYH) {
return getIYh(); }
2657 else if constexpr (R8 ==
IYL) {
return getIYl(); }
2658 else if constexpr (R8 ==
REG_I) {
return getI(); }
2659 else if constexpr (R8 ==
REG_R) {
return getR(); }
2660 else if constexpr (R8 ==
DUMMY) {
return 0; }
2664 if constexpr (R16 ==
AF) {
return getAF(); }
2665 else if constexpr (R16 ==
BC) {
return getBC(); }
2666 else if constexpr (R16 ==
DE) {
return getDE(); }
2667 else if constexpr (R16 ==
HL) {
return getHL(); }
2668 else if constexpr (R16 ==
IX) {
return getIX(); }
2669 else if constexpr (R16 ==
IY) {
return getIY(); }
2670 else if constexpr (R16 ==
SP) {
return getSP(); }
2674 if constexpr (R8 ==
A) { setA(x); }
2675 else if constexpr (R8 ==
F) { setF(x); }
2676 else if constexpr (R8 ==
B) { setB(x); }
2677 else if constexpr (R8 ==
C) { setC(x); }
2678 else if constexpr (R8 ==
D) { setD(x); }
2679 else if constexpr (R8 ==
E) { setE(x); }
2680 else if constexpr (R8 ==
H) { setH(x); }
2681 else if constexpr (R8 ==
L) { setL(x); }
2682 else if constexpr (R8 ==
IXH) { setIXh(x); }
2683 else if constexpr (R8 ==
IXL) { setIXl(x); }
2684 else if constexpr (R8 ==
IYH) { setIYh(x); }
2685 else if constexpr (R8 ==
IYL) { setIYl(x); }
2686 else if constexpr (R8 ==
REG_I) { setI(x); }
2687 else if constexpr (R8 ==
REG_R) { setR(x); }
2688 else if constexpr (R8 ==
DUMMY) { }
2692 if constexpr (R16 ==
AF) { setAF(x); }
2693 else if constexpr (R16 ==
BC) { setBC(x); }
2694 else if constexpr (R16 ==
DE) { setDE(x); }
2695 else if constexpr (R16 ==
HL) { setHL(x); }
2696 else if constexpr (R16 ==
IX) { setIX(x); }
2697 else if constexpr (R16 ==
IY) { setIY(x); }
2698 else if constexpr (R16 ==
SP) { setSP(x); }
2704 set8<DST>(get8<SRC>());
return {1, T::CC_LD_R_R + EE};
2708template<
typename T>
template<Reg16 REG,
int EE> II CPUCore<T>::ld_sp_SS() {
2709 setSP(get16<REG>());
return {1, T::CC_LD_SP_HL + EE};
2713template<
typename T>
template<Reg16 REG> II CPUCore<T>::ld_SS_a() {
2714 T::setMemPtr((getA() << 8) | ((get16<REG>() + 1) & 0xFF));
2715 WRMEM(get16<REG>(), getA(), T::CC_LD_SS_A_1);
2716 return {1, T::CC_LD_SS_A};
2720template<
typename T>
template<Reg8 SRC> II CPUCore<T>::ld_xhl_R() {
2721 WRMEM(getHL(), get8<SRC>(), T::CC_LD_HL_R_1);
2722 return {1, T::CC_LD_HL_R};
2726template<
typename T>
template<Reg16 IXY, Reg8 SRC> II CPUCore<T>::ld_xix_R() {
2727 int8_t ofst = RDMEM_OPCODE<1>(T::CC_DD + T::CC_LD_XIX_R_1);
2728 unsigned addr = narrow_cast<word>(get16<IXY>() + ofst);
2730 WRMEM(addr, get8<SRC>(), T::CC_DD + T::CC_LD_XIX_R_2);
2731 return {2, T::CC_DD + T::CC_LD_XIX_R};
2735template<
typename T> II CPUCore<T>::ld_xhl_byte() {
2736 byte val = RDMEM_OPCODE<1>(T::CC_LD_HL_N_1);
2737 WRMEM(getHL(), val, T::CC_LD_HL_N_2);
2738 return {2, T::CC_LD_HL_N};
2742template<
typename T>
template<Reg16 IXY> II CPUCore<T>::ld_xix_byte() {
2743 unsigned tmp = RD_WORD_PC<1>(T::CC_DD + T::CC_LD_XIX_N_1);
2744 auto ofst = narrow_cast<int8_t>(tmp & 0xFF);
2745 auto val = narrow_cast<byte>(tmp >> 8);
2746 unsigned addr = narrow_cast<word>(get16<IXY>() + ofst);
2748 WRMEM(addr, val, T::CC_DD + T::CC_LD_XIX_N_2);
2749 return {3, T::CC_DD + T::CC_LD_XIX_N};
2753template<
typename T> II CPUCore<T>::ld_xbyte_a() {
2754 unsigned x = RD_WORD_PC<1>(T::CC_LD_NN_A_1);
2755 T::setMemPtr((getA() << 8) | ((x + 1) & 0xFF));
2756 WRMEM(x, getA(), T::CC_LD_NN_A_2);
2757 return {3, T::CC_LD_NN_A};
2761template<
typename T>
template<
int EE>
inline II CPUCore<T>::WR_NN_Y(
word reg) {
2762 unsigned addr = RD_WORD_PC<1>(T::CC_LD_XX_HL_1 + EE);
2763 T::setMemPtr(addr + 1);
2764 WR_WORD(addr, reg, T::CC_LD_XX_HL_2 + EE);
2765 return {3, T::CC_LD_XX_HL + EE};
2767template<
typename T>
template<Reg16 REG,
int EE> II CPUCore<T>::ld_xword_SS() {
2768 return WR_NN_Y<EE >(get16<REG>());
2770template<
typename T>
template<Reg16 REG> II CPUCore<T>::ld_xword_SS_ED() {
2771 return WR_NN_Y<T::EE_ED>(get16<REG>());
2775template<
typename T>
template<Reg16 REG> II CPUCore<T>::ld_a_SS() {
2776 T::setMemPtr(get16<REG>() + 1);
2777 setA(RDMEM(get16<REG>(), T::CC_LD_A_SS_1));
2778 return {1, T::CC_LD_A_SS};
2782template<
typename T> II CPUCore<T>::ld_a_xbyte() {
2783 unsigned addr = RD_WORD_PC<1>(T::CC_LD_A_NN_1);
2784 T::setMemPtr(addr + 1);
2785 setA(RDMEM(addr, T::CC_LD_A_NN_2));
2786 return {3, T::CC_LD_A_NN};
2790template<
typename T>
template<Reg8 DST,
int EE> II CPUCore<T>::ld_R_byte() {
2791 set8<DST>(RDMEM_OPCODE<1>(T::CC_LD_R_N_1 + EE));
return {2, T::CC_LD_R_N + EE};
2795template<
typename T>
template<Reg8 DST> II CPUCore<T>::ld_R_xhl() {
2796 set8<DST>(RDMEM(getHL(), T::CC_LD_R_HL_1));
return {1, T::CC_LD_R_HL};
2800template<
typename T>
template<Reg8 DST, Reg16 IXY> II CPUCore<T>::ld_R_xix() {
2801 int8_t ofst = RDMEM_OPCODE<1>(T::CC_DD + T::CC_LD_R_XIX_1);
2802 unsigned addr = narrow_cast<word>(get16<IXY>() + ofst);
2804 set8<DST>(RDMEM(addr, T::CC_DD + T::CC_LD_R_XIX_2));
2805 return {2, T::CC_DD + T::CC_LD_R_XIX};
2809template<
typename T>
template<
int EE>
inline word CPUCore<T>::RD_P_XX() {
2810 unsigned addr = RD_WORD_PC<1>(T::CC_LD_HL_XX_1 + EE);
2811 T::setMemPtr(addr + 1);
2812 return RD_WORD(addr, T::CC_LD_HL_XX_2 + EE);
2814template<
typename T>
template<Reg16 REG,
int EE> II CPUCore<T>::ld_SS_xword() {
2815 set16<REG>(RD_P_XX<EE>());
return {3, T::CC_LD_HL_XX + EE};
2817template<
typename T>
template<Reg16 REG> II CPUCore<T>::ld_SS_xword_ED() {
2818 set16<REG>(RD_P_XX<T::EE_ED>());
return {3, T::CC_LD_HL_XX + T::EE_ED};
2822template<
typename T>
template<Reg16 REG,
int EE> II CPUCore<T>::ld_SS_word() {
2823 set16<REG>(RD_WORD_PC<1>(T::CC_LD_SS_NN_1 + EE));
return {3, T::CC_LD_SS_NN + EE};
2828template<
typename T>
inline void CPUCore<T>::ADC(
byte reg) {
2829 unsigned res = getA() + reg + ((getF() & C_FLAG) ? 1 : 0);
2830 byte f = ((res & 0x100) ? C_FLAG : 0) |
2831 ((getA() ^ res ^ reg) & H_FLAG) |
2832 (((getA() ^ res) & (reg ^ res) & 0x80) >> 5) |
2834 if constexpr (T::IS_R800) {
2835 f |= table.
ZS[res & 0xFF];
2836 f |=
byte(getF() & (X_FLAG | Y_FLAG));
2838 f |= table.
ZSXY[res & 0xFF];
2841 setA(narrow_cast<byte>(res));
2843template<
typename T>
inline II CPUCore<T>::adc_a_a() {
2844 unsigned res = 2 * getA() + ((getF() & C_FLAG) ? 1 : 0);
2845 byte f = ((res & 0x100) ? C_FLAG : 0) |
2847 (((getA() ^ res) & 0x80) >> 5) |
2849 if constexpr (T::IS_R800) {
2850 f |= table.
ZS[res & 0xFF];
2851 f |=
byte(getF() & (X_FLAG | Y_FLAG));
2853 f |= table.
ZSXY[res & 0xFF];
2856 setA(narrow_cast<byte>(res));
2857 return {1, T::CC_CP_R};
2859template<
typename T>
template<Reg8 SRC,
int EE> II CPUCore<T>::adc_a_R() {
2860 ADC(get8<SRC>());
return {1, T::CC_CP_R + EE};
2862template<
typename T> II CPUCore<T>::adc_a_byte() {
2863 ADC(RDMEM_OPCODE<1>(T::CC_CP_N_1));
return {2, T::CC_CP_N};
2865template<
typename T> II CPUCore<T>::adc_a_xhl() {
2866 ADC(RDMEM(getHL(), T::CC_CP_XHL_1));
return {1, T::CC_CP_XHL};
2868template<
typename T>
template<Reg16 IXY> II CPUCore<T>::adc_a_xix() {
2869 int8_t ofst = RDMEM_OPCODE<1>(T::CC_DD + T::CC_CP_XIX_1);
2870 unsigned addr = narrow_cast<word>(get16<IXY>() + ofst);
2872 ADC(RDMEM(addr, T::CC_DD + T::CC_CP_XIX_2));
2873 return {2, T::CC_DD + T::CC_CP_XIX};
2877template<
typename T>
inline void CPUCore<T>::ADD(
byte reg) {
2878 unsigned res = getA() + reg;
2879 byte f = ((res & 0x100) ? C_FLAG : 0) |
2880 ((getA() ^ res ^ reg) & H_FLAG) |
2881 (((getA() ^ res) & (reg ^ res) & 0x80) >> 5) |
2883 if constexpr (T::IS_R800) {
2884 f |= table.
ZS[res & 0xFF];
2885 f |=
byte(getF() & (X_FLAG | Y_FLAG));
2887 f |= table.
ZSXY[res & 0xFF];
2890 setA(narrow_cast<byte>(res));
2892template<
typename T>
inline II CPUCore<T>::add_a_a() {
2893 unsigned res = 2 * getA();
2894 byte f = ((res & 0x100) ? C_FLAG : 0) |
2896 (((getA() ^ res) & 0x80) >> 5) |
2898 if constexpr (T::IS_R800) {
2899 f |= table.
ZS[res & 0xFF];
2900 f |=
byte(getF() & (X_FLAG | Y_FLAG));
2902 f |= table.
ZSXY[res & 0xFF];
2905 setA(narrow_cast<byte>(res));
2906 return {1, T::CC_CP_R};
2908template<
typename T>
template<Reg8 SRC,
int EE> II CPUCore<T>::add_a_R() {
2909 ADD(get8<SRC>());
return {1, T::CC_CP_R + EE};
2911template<
typename T> II CPUCore<T>::add_a_byte() {
2912 ADD(RDMEM_OPCODE<1>(T::CC_CP_N_1));
return {2, T::CC_CP_N};
2914template<
typename T> II CPUCore<T>::add_a_xhl() {
2915 ADD(RDMEM(getHL(), T::CC_CP_XHL_1));
return {1, T::CC_CP_XHL};
2917template<
typename T>
template<Reg16 IXY> II CPUCore<T>::add_a_xix() {
2918 int8_t ofst = RDMEM_OPCODE<1>(T::CC_DD + T::CC_CP_XIX_1);
2919 unsigned addr = narrow_cast<word>(get16<IXY>() + ofst);
2921 ADD(RDMEM(addr, T::CC_DD + T::CC_CP_XIX_2));
2922 return {2, T::CC_DD + T::CC_CP_XIX};
2926template<
typename T>
inline void CPUCore<T>::AND(
byte reg) {
2929 if constexpr (T::IS_R800) {
2930 f |= table.
ZSPH[getA()];
2931 f |=
byte(getF() & (X_FLAG | Y_FLAG));
2933 f |= table.
ZSPXY[getA()];
2938template<
typename T> II CPUCore<T>::and_a() {
2940 if constexpr (T::IS_R800) {
2941 f |= table.
ZSPH[getA()];
2942 f |=
byte(getF() & (X_FLAG | Y_FLAG));
2944 f |= table.
ZSPXY[getA()];
2948 return {1, T::CC_CP_R};
2950template<
typename T>
template<Reg8 SRC,
int EE> II CPUCore<T>::and_R() {
2951 AND(get8<SRC>());
return {1, T::CC_CP_R + EE};
2953template<
typename T> II CPUCore<T>::and_byte() {
2954 AND(RDMEM_OPCODE<1>(T::CC_CP_N_1));
return {2, T::CC_CP_N};
2956template<
typename T> II CPUCore<T>::and_xhl() {
2957 AND(RDMEM(getHL(), T::CC_CP_XHL_1));
return {1, T::CC_CP_XHL};
2959template<
typename T>
template<Reg16 IXY> II CPUCore<T>::and_xix() {
2960 int8_t ofst = RDMEM_OPCODE<1>(T::CC_DD + T::CC_CP_XIX_1);
2961 unsigned addr = narrow_cast<word>(get16<IXY>() + ofst);
2963 AND(RDMEM(addr, T::CC_DD + T::CC_CP_XIX_2));
2964 return {2, T::CC_DD + T::CC_CP_XIX};
2968template<
typename T>
inline void CPUCore<T>::CP(
byte reg) {
2969 unsigned q = getA() - reg;
2970 byte f = table.
ZS[q & 0xFF] |
2971 ((q & 0x100) ? C_FLAG : 0) |
2973 ((getA() ^
byte(q) ^ reg) & H_FLAG) |
2974 (((reg ^ getA()) & (getA() ^
byte(q)) & 0x80) >> 5);
2975 if constexpr (T::IS_R800) {
2976 f |=
byte(getF() & (X_FLAG | Y_FLAG));
2978 f |=
byte(reg & (X_FLAG | Y_FLAG));
2982template<
typename T> II CPUCore<T>::cp_a() {
2983 byte f = ZS0 | N_FLAG;
2984 if constexpr (T::IS_R800) {
2985 f |=
byte(getF() & (X_FLAG | Y_FLAG));
2987 f |=
byte(getA() & (X_FLAG | Y_FLAG));
2990 return {1, T::CC_CP_R};
2992template<
typename T>
template<Reg8 SRC,
int EE> II CPUCore<T>::cp_R() {
2993 CP(get8<SRC>());
return {1, T::CC_CP_R + EE};
2995template<
typename T> II CPUCore<T>::cp_byte() {
2996 CP(RDMEM_OPCODE<1>(T::CC_CP_N_1));
return {2, T::CC_CP_N};
2998template<
typename T> II CPUCore<T>::cp_xhl() {
2999 CP(RDMEM(getHL(), T::CC_CP_XHL_1));
return {1, T::CC_CP_XHL};
3001template<
typename T>
template<Reg16 IXY> II CPUCore<T>::cp_xix() {
3002 int8_t ofst = RDMEM_OPCODE<1>(T::CC_DD + T::CC_CP_XIX_1);
3003 unsigned addr = narrow_cast<word>(get16<IXY>() + ofst);
3005 CP(RDMEM(addr, T::CC_DD + T::CC_CP_XIX_2));
3006 return {2, T::CC_DD + T::CC_CP_XIX};
3010template<
typename T>
inline void CPUCore<T>::OR(
byte reg) {
3013 if constexpr (T::IS_R800) {
3014 f |= table.
ZSP[getA()];
3015 f |=
byte(getF() & (X_FLAG | Y_FLAG));
3017 f |= table.
ZSPXY[getA()];
3021template<
typename T> II CPUCore<T>::or_a() {
3023 if constexpr (T::IS_R800) {
3024 f |= table.
ZSP[getA()];
3025 f |=
byte(getF() & (X_FLAG | Y_FLAG));
3027 f |= table.
ZSPXY[getA()];
3030 return {1, T::CC_CP_R};
3032template<
typename T>
template<Reg8 SRC,
int EE> II CPUCore<T>::or_R() {
3033 OR(get8<SRC>());
return {1, T::CC_CP_R + EE};
3035template<
typename T> II CPUCore<T>::or_byte() {
3036 OR(RDMEM_OPCODE<1>(T::CC_CP_N_1));
return {2, T::CC_CP_N};
3038template<
typename T> II CPUCore<T>::or_xhl() {
3039 OR(RDMEM(getHL(), T::CC_CP_XHL_1));
return {1, T::CC_CP_XHL};
3041template<
typename T>
template<Reg16 IXY> II CPUCore<T>::or_xix() {
3042 int8_t ofst = RDMEM_OPCODE<1>(T::CC_DD + T::CC_CP_XIX_1);
3043 unsigned addr = narrow_cast<word>(get16<IXY>() + ofst);
3045 OR(RDMEM(addr, T::CC_DD + T::CC_CP_XIX_2));
3046 return {2, T::CC_DD + T::CC_CP_XIX};
3050template<
typename T>
inline void CPUCore<T>::SBC(
byte reg) {
3051 unsigned res = getA() - reg - ((getF() & C_FLAG) ? 1 : 0);
3052 byte f = ((res & 0x100) ? C_FLAG : 0) |
3054 ((getA() ^ res ^ reg) & H_FLAG) |
3055 (((reg ^ getA()) & (getA() ^ res) & 0x80) >> 5);
3056 if constexpr (T::IS_R800) {
3057 f |= table.
ZS[res & 0xFF];
3058 f |=
byte(getF() & (X_FLAG | Y_FLAG));
3060 f |= table.
ZSXY[res & 0xFF];
3063 setA(narrow_cast<byte>(res));
3065template<
typename T> II CPUCore<T>::sbc_a_a() {
3066 if constexpr (T::IS_R800) {
3067 word t = (getF() & C_FLAG)
3068 ? (255 * 256 | ZS255 | C_FLAG | H_FLAG | N_FLAG)
3069 : ( 0 * 256 | ZS0 | N_FLAG);
3070 setAF(
t | (getF() & (X_FLAG | Y_FLAG)));
3072 setAF((getF() & C_FLAG) ?
3073 (255 * 256 | ZSXY255 | C_FLAG | H_FLAG | N_FLAG) :
3074 ( 0 * 256 | ZSXY0 | N_FLAG));
3076 return {1, T::CC_CP_R};
3078template<
typename T>
template<Reg8 SRC,
int EE> II CPUCore<T>::sbc_a_R() {
3079 SBC(get8<SRC>());
return {1, T::CC_CP_R + EE};
3081template<
typename T> II CPUCore<T>::sbc_a_byte() {
3082 SBC(RDMEM_OPCODE<1>(T::CC_CP_N_1));
return {2, T::CC_CP_N};
3084template<
typename T> II CPUCore<T>::sbc_a_xhl() {
3085 SBC(RDMEM(getHL(), T::CC_CP_XHL_1));
return {1, T::CC_CP_XHL};
3087template<
typename T>
template<Reg16 IXY> II CPUCore<T>::sbc_a_xix() {
3088 int8_t ofst = RDMEM_OPCODE<1>(T::CC_DD + T::CC_CP_XIX_1);
3089 unsigned addr = narrow_cast<word>(get16<IXY>() + ofst);
3091 SBC(RDMEM(addr, T::CC_DD + T::CC_CP_XIX_2));
3092 return {2, T::CC_DD + T::CC_CP_XIX};
3096template<
typename T>
inline void CPUCore<T>::SUB(
byte reg) {
3097 unsigned res = getA() - reg;
3098 byte f = ((res & 0x100) ? C_FLAG : 0) |
3100 ((getA() ^ res ^ reg) & H_FLAG) |
3101 (((reg ^ getA()) & (getA() ^ res) & 0x80) >> 5);
3102 if constexpr (T::IS_R800) {
3103 f |= table.
ZS[res & 0xFF];
3104 f |=
byte(getF() & (X_FLAG | Y_FLAG));
3106 f |= table.
ZSXY[res & 0xFF];
3109 setA(narrow_cast<byte>(res));
3111template<
typename T> II CPUCore<T>::sub_a() {
3112 if constexpr (T::IS_R800) {
3113 word t = 0 * 256 | ZS0 | N_FLAG;
3114 setAF(
t | (getF() & (X_FLAG | Y_FLAG)));
3116 setAF(0 * 256 | ZSXY0 | N_FLAG);
3118 return {1, T::CC_CP_R};
3120template<
typename T>
template<Reg8 SRC,
int EE> II CPUCore<T>::sub_R() {
3121 SUB(get8<SRC>());
return {1, T::CC_CP_R + EE};
3123template<
typename T> II CPUCore<T>::sub_byte() {
3124 SUB(RDMEM_OPCODE<1>(T::CC_CP_N_1));
return {2, T::CC_CP_N};
3126template<
typename T> II CPUCore<T>::sub_xhl() {
3127 SUB(RDMEM(getHL(), T::CC_CP_XHL_1));
return {1, T::CC_CP_XHL};
3129template<
typename T>
template<Reg16 IXY> II CPUCore<T>::sub_xix() {
3130 int8_t ofst = RDMEM_OPCODE<1>(T::CC_DD + T::CC_CP_XIX_1);
3131 unsigned addr = narrow_cast<word>(get16<IXY>() + ofst);
3133 SUB(RDMEM(addr, T::CC_DD + T::CC_CP_XIX_2));
3134 return {2, T::CC_DD + T::CC_CP_XIX};
3138template<
typename T>
inline void CPUCore<T>::XOR(
byte reg) {
3141 if constexpr (T::IS_R800) {
3142 f |= table.
ZSP[getA()];
3143 f |=
byte(getF() & (X_FLAG | Y_FLAG));
3145 f |= table.
ZSPXY[getA()];
3149template<
typename T> II CPUCore<T>::xor_a() {
3150 if constexpr (T::IS_R800) {
3151 word t = 0 * 256 + ZSP0;
3152 setAF(
t | (getF() & (X_FLAG | Y_FLAG)));
3154 setAF(0 * 256 + ZSPXY0);
3156 return {1, T::CC_CP_R};
3158template<
typename T>
template<Reg8 SRC,
int EE> II CPUCore<T>::xor_R() {
3159 XOR(get8<SRC>());
return {1, T::CC_CP_R + EE};
3161template<
typename T> II CPUCore<T>::xor_byte() {
3162 XOR(RDMEM_OPCODE<1>(T::CC_CP_N_1));
return {2, T::CC_CP_N};
3164template<
typename T> II CPUCore<T>::xor_xhl() {
3165 XOR(RDMEM(getHL(), T::CC_CP_XHL_1));
return {1, T::CC_CP_XHL};
3167template<
typename T>
template<Reg16 IXY> II CPUCore<T>::xor_xix() {
3168 int8_t ofst = RDMEM_OPCODE<1>(T::CC_DD + T::CC_CP_XIX_1);
3169 unsigned addr = narrow_cast<word>(get16<IXY>() + ofst);
3171 XOR(RDMEM(addr, T::CC_DD + T::CC_CP_XIX_2));
3172 return {2, T::CC_DD + T::CC_CP_XIX};
3177template<
typename T>
inline byte CPUCore<T>::DEC(
byte reg) {
3179 byte f = ((reg & ~res & 0x80) >> 5) |
3180 (((res & 0x0F) + 1) & H_FLAG) |
3182 if constexpr (T::IS_R800) {
3183 f |=
byte(getF() & (C_FLAG | X_FLAG | Y_FLAG));
3186 f |=
byte(getF() & C_FLAG);
3187 f |= table.
ZSXY[res];
3192template<
typename T>
template<Reg8 REG,
int EE> II CPUCore<T>::dec_R() {
3193 set8<REG>(DEC(get8<REG>()));
return {1, T::CC_INC_R + EE};
3195template<
typename T>
template<
int EE>
inline void CPUCore<T>::DEC_X(
unsigned x) {
3196 byte val = DEC(RDMEM(x, T::CC_INC_XHL_1 + EE));
3197 WRMEM(x, val, T::CC_INC_XHL_2 + EE);
3199template<
typename T> II CPUCore<T>::dec_xhl() {
3201 return {1, T::CC_INC_XHL};
3203template<
typename T>
template<Reg16 IXY> II CPUCore<T>::dec_xix() {
3204 int8_t ofst = RDMEM_OPCODE<1>(T::CC_DD + T::CC_INC_XIX_1);
3205 unsigned addr = narrow_cast<word>(get16<IXY>() + ofst);
3207 DEC_X<T::CC_DD + T::EE_INC_XIX>(addr);
3208 return {2, T::CC_INC_XHL + T::CC_DD + T::EE_INC_XIX};
3212template<
typename T>
inline byte CPUCore<T>::INC(
byte reg) {
3214 byte f = ((reg & -reg & 0x80) >> 5) |
3215 (((reg & 0x0F) - 1) & H_FLAG) |
3217 if constexpr (T::IS_R800) {
3218 f |=
byte(getF() & (C_FLAG | X_FLAG | Y_FLAG));
3221 f |=
byte(getF() & C_FLAG);
3222 f |= table.
ZSXY[reg];
3227template<
typename T>
template<Reg8 REG,
int EE> II CPUCore<T>::inc_R() {
3228 set8<REG>(INC(get8<REG>()));
return {1, T::CC_INC_R + EE};
3230template<
typename T>
template<
int EE>
inline void CPUCore<T>::INC_X(
unsigned x) {
3231 byte val = INC(RDMEM(x, T::CC_INC_XHL_1 + EE));
3232 WRMEM(x, val, T::CC_INC_XHL_2 + EE);
3234template<
typename T> II CPUCore<T>::inc_xhl() {
3236 return {1, T::CC_INC_XHL};
3238template<
typename T>
template<Reg16 IXY> II CPUCore<T>::inc_xix() {
3239 int8_t ofst = RDMEM_OPCODE<1>(T::CC_DD + T::CC_INC_XIX_1);
3240 unsigned addr = narrow_cast<word>(get16<IXY>() + ofst);
3242 INC_X<T::CC_DD + T::EE_INC_XIX>(addr);
3243 return {2, T::CC_INC_XHL + T::CC_DD + T::EE_INC_XIX};
3248template<
typename T>
template<Reg16 REG>
inline II CPUCore<T>::adc_hl_SS() {
3249 unsigned reg = get16<REG>();
3250 T::setMemPtr(getHL() + 1);
3251 unsigned res = getHL() + reg + ((getF() & C_FLAG) ? 1 : 0);
3252 byte f =
byte(res >> 16) |
3254 if constexpr (T::IS_R800) {
3255 f |=
byte(getF() & (X_FLAG | Y_FLAG));
3258 f |=
byte(((getHL() ^ res ^ reg) >> 8) & H_FLAG);
3260 f |=
byte(((getHL() ^ res) & (reg ^ res) & 0x8000) >> 13);
3261 if constexpr (T::IS_R800) {
3262 f |= (res >> 8) & S_FLAG;
3264 f |= (res >> 8) & (S_FLAG | X_FLAG | Y_FLAG);
3267 f |=
byte(((getHL() ^ reg) >> 8) & H_FLAG);
3269 f |=
byte((getHL() & reg & 0x8000) >> 13);
3273 setHL(narrow_cast<word>(res));
3274 return {1, T::CC_ADC_HL_SS};
3276template<
typename T> II CPUCore<T>::adc_hl_hl() {
3277 T::setMemPtr(getHL() + 1);
3278 unsigned res = 2 * getHL() + ((getF() & C_FLAG) ? 1 : 0);
3279 byte f =
byte(res >> 16) |
3281 if constexpr (T::IS_R800) {
3282 f |=
byte(getF() & (X_FLAG | Y_FLAG));
3286 f |=
byte(((getHL() ^ res) & 0x8000) >> 13);
3287 if constexpr (T::IS_R800) {
3288 f |=
byte((res >> 8) & (H_FLAG | S_FLAG));
3290 f |=
byte((res >> 8) & (H_FLAG | S_FLAG | X_FLAG | Y_FLAG));
3294 f |=
byte((getHL() & 0x8000) >> 13);
3298 setHL(narrow_cast<word>(res));
3299 return {1, T::CC_ADC_HL_SS};
3303template<
typename T>
template<Reg16 REG1, Reg16 REG2,
int EE> II CPUCore<T>::add_SS_TT() {
3304 unsigned reg1 = get16<REG1>();
3305 unsigned reg2 = get16<REG2>();
3306 T::setMemPtr(reg1 + 1);
3307 unsigned res = reg1 + reg2;
3308 byte f =
byte(((reg1 ^ res ^ reg2) >> 8) & H_FLAG) |
3311 if constexpr (T::IS_R800) {
3312 f |=
byte(getF() & (S_FLAG | Z_FLAG | V_FLAG | X_FLAG | Y_FLAG));
3314 f |=
byte(getF() & (S_FLAG | Z_FLAG | V_FLAG));
3315 f |=
byte((res >> 8) & (X_FLAG | Y_FLAG));
3318 set16<REG1>(narrow_cast<word>(res));
3319 return {1, T::CC_ADD_HL_SS + EE};
3321template<
typename T>
template<Reg16 REG,
int EE> II CPUCore<T>::add_SS_SS() {
3322 unsigned reg = get16<REG>();
3323 T::setMemPtr(reg + 1);
3324 unsigned res = 2 * reg;
3325 byte f =
byte(res >> 16) |
3327 if constexpr (T::IS_R800) {
3328 f |=
byte(getF() & (S_FLAG | Z_FLAG | V_FLAG | X_FLAG | Y_FLAG));
3329 f |=
byte((res >> 8) & H_FLAG);
3331 f |=
byte(getF() & (S_FLAG | Z_FLAG | V_FLAG));
3332 f |=
byte((res >> 8) & (H_FLAG | X_FLAG | Y_FLAG));
3335 set16<REG>(narrow_cast<word>(res));
3336 return {1, T::CC_ADD_HL_SS + EE};
3340template<
typename T>
template<Reg16 REG>
inline II CPUCore<T>::sbc_hl_SS() {
3341 unsigned reg = get16<REG>();
3342 T::setMemPtr(getHL() + 1);
3343 unsigned res = getHL() - reg - ((getF() & C_FLAG) ? 1 : 0);
3344 byte f = ((res & 0x10000) ? C_FLAG : 0) |
3346 if constexpr (T::IS_R800) {
3347 f |=
byte(getF() & (X_FLAG | Y_FLAG));
3350 f |=
byte(((getHL() ^ res ^ reg) >> 8) & H_FLAG);
3352 f |=
byte(((reg ^ getHL()) & (getHL() ^ res) & 0x8000) >> 13);
3353 if constexpr (T::IS_R800) {
3354 f |=
byte((res >> 8) & S_FLAG);
3356 f |=
byte((res >> 8) & (S_FLAG | X_FLAG | Y_FLAG));
3359 f |=
byte(((getHL() ^ reg) >> 8) & H_FLAG);
3361 f |=
byte(((reg ^ getHL()) & getHL() & 0x8000) >> 13);
3365 setHL(narrow_cast<word>(res));
3366 return {1, T::CC_ADC_HL_SS};
3368template<
typename T> II CPUCore<T>::sbc_hl_hl() {
3369 T::setMemPtr(getHL() + 1);
3370 byte f = T::IS_R800 ? (getF() & (X_FLAG | Y_FLAG)) : 0;
3371 if (getF() & C_FLAG) {
3372 f |= C_FLAG | H_FLAG | S_FLAG | N_FLAG;
3373 if constexpr (!T::IS_R800) {
3374 f |= X_FLAG | Y_FLAG;
3378 f |= Z_FLAG | N_FLAG;
3382 return {1, T::CC_ADC_HL_SS};
3386template<
typename T>
template<Reg16 REG,
int EE> II CPUCore<T>::dec_SS() {
3387 set16<REG>(narrow_cast<word>(get16<REG>() - 1));
return {1, T::CC_INC_SS + EE};
3391template<
typename T>
template<Reg16 REG,
int EE> II CPUCore<T>::inc_SS() {
3392 set16<REG>(narrow_cast<word>(get16<REG>() + 1));
return {1, T::CC_INC_SS + EE};
3397template<
typename T>
template<
unsigned N, Reg8 REG> II CPUCore<T>::bit_N_R() {
3398 byte reg = get8<REG>();
3400 if constexpr (T::IS_R800) {
3402 f |=
byte(getF() & (S_FLAG | V_FLAG | C_FLAG | X_FLAG | Y_FLAG));
3404 f |= (reg & (1 << N)) ? 0 : Z_FLAG;
3406 f |= table.
ZSPH[reg & (1 << N)];
3407 f |=
byte(getF() & C_FLAG);
3408 f |=
byte(reg & (X_FLAG | Y_FLAG));
3411 return {1, T::CC_BIT_R};
3413template<
typename T>
template<
unsigned N>
inline II CPUCore<T>::bit_N_xhl() {
3414 byte m = RDMEM(getHL(), T::CC_BIT_XHL_1) & (1 << N);
3416 if constexpr (T::IS_R800) {
3417 f |=
byte(getF() & (S_FLAG | V_FLAG | C_FLAG | X_FLAG | Y_FLAG));
3419 f |= m ? 0 : Z_FLAG;
3422 f |=
byte(getF() & C_FLAG);
3423 f |=
byte((T::getMemPtr() >> 8) & (X_FLAG | Y_FLAG));
3426 return {1, T::CC_BIT_XHL};
3428template<
typename T>
template<
unsigned N>
inline II CPUCore<T>::bit_N_xix(
unsigned addr) {
3430 byte m = RDMEM(addr, T::CC_DD + T::CC_BIT_XIX_1) & (1 << N);
3432 if constexpr (T::IS_R800) {
3433 f |=
byte(getF() & (S_FLAG | V_FLAG | C_FLAG | X_FLAG | Y_FLAG));
3435 f |= m ? 0 : Z_FLAG;
3438 f |=
byte(getF() & C_FLAG);
3439 f |=
byte((addr >> 8) & (X_FLAG | Y_FLAG));
3442 return {3, T::CC_DD + T::CC_BIT_XIX};
3446static constexpr byte RES(
unsigned b,
byte reg) {
3447 return reg &
byte(~(1 << b));
3449template<
typename T>
template<
unsigned N, Reg8 REG> II CPUCore<T>::res_N_R() {
3450 set8<REG>(RES(N, get8<REG>()));
return {1, T::CC_SET_R};
3452template<
typename T>
template<
int EE>
inline byte CPUCore<T>::RES_X(
unsigned bit,
unsigned addr) {
3453 byte res = RES(bit, RDMEM(addr, T::CC_SET_XHL_1 + EE));
3454 WRMEM(addr, res, T::CC_SET_XHL_2 + EE);
3457template<
typename T>
template<
unsigned N> II CPUCore<T>::res_N_xhl() {
3458 RES_X<0>(N, getHL());
return {1, T::CC_SET_XHL};
3460template<
typename T>
template<
unsigned N, Reg8 REG> II CPUCore<T>::res_N_xix_R(
unsigned a) {
3462 set8<REG>(RES_X<T::CC_DD + T::EE_SET_XIX>(N, a));
3463 return {3, T::CC_DD + T::CC_SET_XIX};
3467static constexpr byte SET(
unsigned b,
byte reg) {
3468 return reg |
byte(1 << b);
3470template<
typename T>
template<
unsigned N, Reg8 REG> II CPUCore<T>::set_N_R() {
3471 set8<REG>(SET(N, get8<REG>()));
return {1, T::CC_SET_R};
3473template<
typename T>
template<
int EE>
inline byte CPUCore<T>::SET_X(
unsigned bit,
unsigned addr) {
3474 byte res = SET(bit, RDMEM(addr, T::CC_SET_XHL_1 + EE));
3475 WRMEM(addr, res, T::CC_SET_XHL_2 + EE);
3478template<
typename T>
template<
unsigned N> II CPUCore<T>::set_N_xhl() {
3479 SET_X<0>(N, getHL());
return {1, T::CC_SET_XHL};
3481template<
typename T>
template<
unsigned N, Reg8 REG> II CPUCore<T>::set_N_xix_R(
unsigned a) {
3483 set8<REG>(SET_X<T::CC_DD + T::EE_SET_XIX>(N, a));
3484 return {3, T::CC_DD + T::CC_SET_XIX};
3488template<
typename T>
inline byte CPUCore<T>::RL(
byte reg) {
3490 reg = narrow_cast<byte>((reg << 1) | ((getF() & C_FLAG) ? 0x01 : 0));
3491 byte f = c ? C_FLAG : 0;
3492 if constexpr (T::IS_R800) {
3493 f |= table.
ZSP[reg];
3494 f |=
byte(getF() & (X_FLAG | Y_FLAG));
3496 f |= table.
ZSPXY[reg];
3501template<
typename T>
template<
int EE>
inline byte CPUCore<T>::RL_X(
unsigned x) {
3502 byte res = RL(RDMEM(x, T::CC_SET_XHL_1 + EE));
3503 WRMEM(x, res, T::CC_SET_XHL_2 + EE);
3506template<
typename T>
template<Reg8 REG> II CPUCore<T>::rl_R() {
3507 set8<REG>(RL(get8<REG>()));
return {1, T::CC_SET_R};
3509template<
typename T> II CPUCore<T>::rl_xhl() {
3510 RL_X<0>(getHL());
return {1, T::CC_SET_XHL};
3512template<
typename T>
template<Reg8 REG> II CPUCore<T>::rl_xix_R(
unsigned a) {
3514 set8<REG>(RL_X<T::CC_DD + T::EE_SET_XIX>(a));
3515 return {3, T::CC_DD + T::CC_SET_XIX};
3519template<
typename T>
inline byte CPUCore<T>::RLC(
byte reg) {
3521 reg = narrow_cast<byte>((reg << 1) | c);
3522 byte f = c ? C_FLAG : 0;
3523 if constexpr (T::IS_R800) {
3524 f |= table.
ZSP[reg];
3525 f |=
byte(getF() & (X_FLAG | Y_FLAG));
3527 f |= table.
ZSPXY[reg];
3532template<
typename T>
template<
int EE>
inline byte CPUCore<T>::RLC_X(
unsigned x) {
3533 byte res = RLC(RDMEM(x, T::CC_SET_XHL_1 + EE));
3534 WRMEM(x, res, T::CC_SET_XHL_2 + EE);
3537template<
typename T>
template<Reg8 REG> II CPUCore<T>::rlc_R() {
3538 set8<REG>(RLC(get8<REG>()));
return {1, T::CC_SET_R};
3540template<
typename T> II CPUCore<T>::rlc_xhl() {
3541 RLC_X<0>(getHL());
return {1, T::CC_SET_XHL};
3543template<
typename T>
template<Reg8 REG> II CPUCore<T>::rlc_xix_R(
unsigned a) {
3545 set8<REG>(RLC_X<T::CC_DD + T::EE_SET_XIX>(a));
3546 return {3, T::CC_DD + T::CC_SET_XIX};
3550template<
typename T>
inline byte CPUCore<T>::RR(
byte reg) {
3552 reg = narrow_cast<byte>((reg >> 1) | ((getF() & C_FLAG) << 7));
3553 byte f = c ? C_FLAG : 0;
3554 if constexpr (T::IS_R800) {
3555 f |= table.
ZSP[reg];
3556 f |=
byte(getF() & (X_FLAG | Y_FLAG));
3558 f |= table.
ZSPXY[reg];
3563template<
typename T>
template<
int EE>
inline byte CPUCore<T>::RR_X(
unsigned x) {
3564 byte res = RR(RDMEM(x, T::CC_SET_XHL_1 + EE));
3565 WRMEM(x, res, T::CC_SET_XHL_2 + EE);
3568template<
typename T>
template<Reg8 REG> II CPUCore<T>::rr_R() {
3569 set8<REG>(RR(get8<REG>()));
return {1, T::CC_SET_R};
3571template<
typename T> II CPUCore<T>::rr_xhl() {
3572 RR_X<0>(getHL());
return {1, T::CC_SET_XHL};
3574template<
typename T>
template<Reg8 REG> II CPUCore<T>::rr_xix_R(
unsigned a) {
3576 set8<REG>(RR_X<T::CC_DD + T::EE_SET_XIX>(a));
3577 return {3, T::CC_DD + T::CC_SET_XIX};
3581template<
typename T>
inline byte CPUCore<T>::RRC(
byte reg) {
3583 reg = narrow_cast<byte>((reg >> 1) | (c << 7));
3584 byte f = c ? C_FLAG : 0;
3585 if constexpr (T::IS_R800) {
3586 f |= table.
ZSP[reg];
3587 f |=
byte(getF() & (X_FLAG | Y_FLAG));
3589 f |= table.
ZSPXY[reg];
3594template<
typename T>
template<
int EE>
inline byte CPUCore<T>::RRC_X(
unsigned x) {
3595 byte res = RRC(RDMEM(x, T::CC_SET_XHL_1 + EE));
3596 WRMEM(x, res, T::CC_SET_XHL_2 + EE);
3599template<
typename T>
template<Reg8 REG> II CPUCore<T>::rrc_R() {
3600 set8<REG>(RRC(get8<REG>()));
return {1, T::CC_SET_R};
3602template<
typename T> II CPUCore<T>::rrc_xhl() {
3603 RRC_X<0>(getHL());
return {1, T::CC_SET_XHL};
3605template<
typename T>
template<Reg8 REG> II CPUCore<T>::rrc_xix_R(
unsigned a) {
3607 set8<REG>(RRC_X<T::CC_DD + T::EE_SET_XIX>(a));
3608 return {3, T::CC_DD + T::CC_SET_XIX};
3612template<
typename T>
inline byte CPUCore<T>::SLA(
byte reg) {
3615 byte f = c ? C_FLAG : 0;
3616 if constexpr (T::IS_R800) {
3617 f |= table.
ZSP[reg];
3618 f |=
byte(getF() & (X_FLAG | Y_FLAG));
3620 f |= table.
ZSPXY[reg];
3625template<
typename T>
template<
int EE>
inline byte CPUCore<T>::SLA_X(
unsigned x) {
3626 byte res = SLA(RDMEM(x, T::CC_SET_XHL_1 + EE));
3627 WRMEM(x, res, T::CC_SET_XHL_2 + EE);
3630template<
typename T>
template<Reg8 REG> II CPUCore<T>::sla_R() {
3631 set8<REG>(SLA(get8<REG>()));
return {1, T::CC_SET_R};
3633template<
typename T> II CPUCore<T>::sla_xhl() {
3634 SLA_X<0>(getHL());
return {1, T::CC_SET_XHL};
3636template<
typename T>
template<Reg8 REG> II CPUCore<T>::sla_xix_R(
unsigned a) {
3638 set8<REG>(SLA_X<T::CC_DD + T::EE_SET_XIX>(a));
3639 return {3, T::CC_DD + T::CC_SET_XIX};
3643template<
typename T>
inline byte CPUCore<T>::SLL(
byte reg) {
3644 assert(!T::IS_R800);
3646 reg = narrow_cast<byte>((reg << 1) | 1);
3647 byte f = c ? C_FLAG : 0;
3648 f |= table.
ZSPXY[reg];
3652template<
typename T>
template<
int EE>
inline byte CPUCore<T>::SLL_X(
unsigned x) {
3653 byte res = SLL(RDMEM(x, T::CC_SET_XHL_1 + EE));
3654 WRMEM(x, res, T::CC_SET_XHL_2 + EE);
3657template<
typename T>
template<Reg8 REG> II CPUCore<T>::sll_R() {
3658 set8<REG>(SLL(get8<REG>()));
return {1, T::CC_SET_R};
3660template<
typename T> II CPUCore<T>::sll_xhl() {
3661 SLL_X<0>(getHL());
return {1, T::CC_SET_XHL};
3663template<
typename T>
template<Reg8 REG> II CPUCore<T>::sll_xix_R(
unsigned a) {
3665 set8<REG>(SLL_X<T::CC_DD + T::EE_SET_XIX>(a));
3666 return {3, T::CC_DD + T::CC_SET_XIX};
3668template<
typename T> II CPUCore<T>::sll2() {
3670 byte f = (getF() & (X_FLAG | Y_FLAG)) |
3674 return {3, T::CC_DD + T::CC_SET_XIX};
3678template<
typename T>
inline byte CPUCore<T>::SRA(
byte reg) {
3680 reg = (reg >> 1) | (reg & 0x80);
3681 byte f = c ? C_FLAG : 0;
3682 if constexpr (T::IS_R800) {
3683 f |= table.
ZSP[reg];
3684 f |=
byte(getF() & (X_FLAG | Y_FLAG));
3686 f |= table.
ZSPXY[reg];
3691template<
typename T>
template<
int EE>
inline byte CPUCore<T>::SRA_X(
unsigned x) {
3692 byte res = SRA(RDMEM(x, T::CC_SET_XHL_1 + EE));
3693 WRMEM(x, res, T::CC_SET_XHL_2 + EE);
3696template<
typename T>
template<Reg8 REG> II CPUCore<T>::sra_R() {
3697 set8<REG>(SRA(get8<REG>()));
return {1, T::CC_SET_R};
3699template<
typename T> II CPUCore<T>::sra_xhl() {
3700 SRA_X<0>(getHL());
return {1, T::CC_SET_XHL};
3702template<
typename T>
template<Reg8 REG> II CPUCore<T>::sra_xix_R(
unsigned a) {
3704 set8<REG>(SRA_X<T::CC_DD + T::EE_SET_XIX>(a));
3705 return {3, T::CC_DD + T::CC_SET_XIX};
3709template<
typename T>
inline byte CPUCore<T>::SRL(
byte reg) {
3712 byte f = c ? C_FLAG : 0;
3713 if constexpr (T::IS_R800) {
3714 f |= table.
ZSP[reg];
3715 f |=
byte(getF() & (X_FLAG | Y_FLAG));
3717 f |= table.
ZSPXY[reg];
3722template<
typename T>
template<
int EE>
inline byte CPUCore<T>::SRL_X(
unsigned x) {
3723 byte res = SRL(RDMEM(x, T::CC_SET_XHL_1 + EE));
3724 WRMEM(x, res, T::CC_SET_XHL_2 + EE);
3727template<
typename T>
template<Reg8 REG> II CPUCore<T>::srl_R() {
3728 set8<REG>(SRL(get8<REG>()));
return {1, T::CC_SET_R};
3730template<
typename T> II CPUCore<T>::srl_xhl() {
3731 SRL_X<0>(getHL());
return {1, T::CC_SET_XHL};
3733template<
typename T>
template<Reg8 REG> II CPUCore<T>::srl_xix_R(
unsigned a) {
3735 set8<REG>(SRL_X<T::CC_DD + T::EE_SET_XIX>(a));
3736 return {3, T::CC_DD + T::CC_SET_XIX};
3740template<
typename T> II CPUCore<T>::rla() {
3741 byte c = getF() & C_FLAG;
3742 byte f = (getA() & 0x80) ? C_FLAG : 0;
3743 if constexpr (T::IS_R800) {
3744 f |=
byte(getF() & (S_FLAG | Z_FLAG | P_FLAG | X_FLAG | Y_FLAG));
3746 f |=
byte(getF() & (S_FLAG | Z_FLAG | P_FLAG));
3748 setA(narrow_cast<byte>((getA() << 1) | (c ? 1 : 0)));
3749 if constexpr (!T::IS_R800) {
3750 f |=
byte(getA() & (X_FLAG | Y_FLAG));
3753 return {1, T::CC_RLA};
3755template<
typename T> II CPUCore<T>::rlca() {
3756 setA(narrow_cast<byte>((getA() << 1) | (getA() >> 7)));
3758 if constexpr (T::IS_R800) {
3759 f |=
byte(getF() & (S_FLAG | Z_FLAG | P_FLAG | X_FLAG | Y_FLAG));
3760 f |=
byte(getA() & C_FLAG);
3762 f |=
byte(getF() & (S_FLAG | Z_FLAG | P_FLAG));
3763 f |=
byte(getA() & (Y_FLAG | X_FLAG | C_FLAG));
3766 return {1, T::CC_RLA};
3768template<
typename T> II CPUCore<T>::rra() {
3769 auto c =
byte((getF() & C_FLAG) << 7);
3770 byte f = (getA() & 0x01) ? C_FLAG : 0;
3771 if constexpr (T::IS_R800) {
3772 f |=
byte(getF() & (S_FLAG | Z_FLAG | P_FLAG | X_FLAG | Y_FLAG));
3774 f |=
byte(getF() & (S_FLAG | Z_FLAG | P_FLAG));
3776 setA((getA() >> 1) | c);
3777 if constexpr (!T::IS_R800) {
3778 f |=
byte(getA() & (X_FLAG | Y_FLAG));
3781 return {1, T::CC_RLA};
3783template<
typename T> II CPUCore<T>::rrca() {
3784 byte f = getA() & C_FLAG;
3785 if constexpr (T::IS_R800) {
3786 f |=
byte(getF() & (S_FLAG | Z_FLAG | P_FLAG | X_FLAG | Y_FLAG));
3788 f |=
byte(getF() & (S_FLAG | Z_FLAG | P_FLAG));
3790 setA(narrow_cast<byte>((getA() >> 1) | (getA() << 7)));
3791 if constexpr (!T::IS_R800) {
3792 f |=
byte(getA() & (X_FLAG | Y_FLAG));
3795 return {1, T::CC_RLA};
3800template<
typename T> II CPUCore<T>::rld() {
3801 byte val = RDMEM(getHL(), T::CC_RLD_1);
3802 T::setMemPtr(getHL() + 1);
3803 WRMEM(getHL(), narrow_cast<byte>((val << 4) | (getA() & 0x0F)), T::CC_RLD_2);
3804 setA((getA() & 0xF0) | (val >> 4));
3806 if constexpr (T::IS_R800) {
3807 f |=
byte(getF() & (C_FLAG | X_FLAG | Y_FLAG));
3808 f |= table.
ZSP[getA()];
3810 f |=
byte(getF() & C_FLAG);
3811 f |= table.
ZSPXY[getA()];
3814 return {1, T::CC_RLD};
3818template<
typename T> II CPUCore<T>::rrd() {
3819 byte val = RDMEM(getHL(), T::CC_RLD_1);
3820 T::setMemPtr(getHL() + 1);
3821 WRMEM(getHL(), narrow_cast<byte>((val >> 4) | (getA() << 4)), T::CC_RLD_2);
3822 setA((getA() & 0xF0) | (val & 0x0F));
3824 if constexpr (T::IS_R800) {
3825 f |=
byte(getF() & (C_FLAG | X_FLAG | Y_FLAG));
3826 f |= table.
ZSP[getA()];
3828 f |=
byte(getF() & C_FLAG);
3829 f |= table.
ZSPXY[getA()];
3832 return {1, T::CC_RLD};
3837template<
typename T>
template<
int EE>
inline void CPUCore<T>::PUSH(
word reg) {
3839 WR_WORD_rev<true, true>(getSP(), reg, T::CC_PUSH_1 + EE);
3841template<
typename T>
template<Reg16 REG,
int EE> II CPUCore<T>::push_SS() {
3842 PUSH<EE>(get16<REG>());
return {1, T::CC_PUSH + EE};
3846template<
typename T>
template<
int EE>
inline word CPUCore<T>::POP() {
3847 word addr = getSP();
3849 if constexpr (T::IS_R800) {
3851 if constexpr (EE == 0) {
3859 return RD_WORD(addr, T::CC_POP_1 + EE);
3861template<
typename T>
template<Reg16 REG,
int EE> II CPUCore<T>::pop_SS() {
3862 set16<REG>(POP<EE>());
return {1, T::CC_POP + EE};
3867template<
typename T>
template<
typename COND> II CPUCore<T>::call(COND cond) {
3868 word addr = RD_WORD_PC<1>(T::CC_CALL_1);
3871 PUSH<T::EE_CALL>(getPC() + 3);
3873 if constexpr (T::IS_R800) {
3875 setSlowInstructions();
3877 return {0, T::CC_CALL_A};
3879 return {3, T::CC_CALL_B};
3885template<
typename T>
template<
unsigned ADDR> II CPUCore<T>::rst() {
3886 PUSH<0>(getPC() + 1);
3889 if constexpr (T::IS_R800) {
3891 setSlowInstructions();
3893 return {0, T::CC_RST};
3898template<
typename T>
template<
int EE,
typename COND>
inline II CPUCore<T>::RET(COND cond) {
3900 auto addr = POP<EE>();
3903 return {0, T::CC_RET_A + EE};
3905 return {1, T::CC_RET_B + EE};
3908template<
typename T>
template<
typename COND> II CPUCore<T>::ret(COND cond) {
3909 return RET<T::EE_RET_C>(cond);
3911template<
typename T> II CPUCore<T>::ret() {
3912 return RET<0>(CondTrue());
3914template<
typename T> II CPUCore<T>::retn() {
3916 setSlowInstructions();
3917 return RET<T::EE_RETN>(CondTrue());
3922template<
typename T>
template<Reg16 REG,
int EE> II CPUCore<T>::jp_SS() {
3923 setPC(get16<REG>()); T::R800ForcePageBreak();
return {0, T::CC_JP_HL + EE};
3927template<
typename T>
template<
typename COND> II CPUCore<T>::jp(COND cond) {
3928 word addr = RD_WORD_PC<1>(T::CC_JP_1);
3932 T::R800ForcePageBreak();
3933 return {0, T::CC_JP_A};
3935 return {3, T::CC_JP_B};
3940template<
typename T>
template<
typename COND> II CPUCore<T>::jr(COND cond) {
3941 int8_t ofst = RDMEM_OPCODE<1>(T::CC_JR_1);
3943 if (((getPC() + 2) & 0xFF) == 0) {
3971 T::R800ForcePageBreak();
3973 setPC(narrow_cast<word>(getPC() + 2 + ofst));
3974 T::setMemPtr(getPC());
3975 return {0, T::CC_JR_A};
3977 return {2, T::CC_JR_B};
3982template<
typename T> II CPUCore<T>::djnz() {
3983 byte b = getB() - 1;
3985 int8_t ofst = RDMEM_OPCODE<1>(T::CC_JR_1 + T::EE_DJNZ);
3987 if (((getPC() + 2) & 0xFF) == 0) {
3989 T::R800ForcePageBreak();
3991 setPC(narrow_cast<word>(getPC() + 2 + ofst));
3992 T::setMemPtr(getPC());
3993 return {0, T::CC_JR_A + T::EE_DJNZ};
3995 return {2, T::CC_JR_B + T::EE_DJNZ};
4000template<
typename T>
template<Reg16 REG,
int EE> II CPUCore<T>::ex_xsp_SS() {
4001 word res = RD_WORD_impl<true, false>(getSP(), T::CC_EX_SP_HL_1 + EE);
4003 WR_WORD_rev<false, true>(getSP(), get16<REG>(), T::CC_EX_SP_HL_2 + EE);
4005 return {1, T::CC_EX_SP_HL + EE};
4009template<
typename T>
template<Reg8 REG> II CPUCore<T>::in_R_c() {
4010 if constexpr (T::IS_R800) T::waitForEvenCycle(T::CC_IN_R_C_1);
4011 T::setMemPtr(getBC() + 1);
4012 byte res = READ_PORT(getBC(), T::CC_IN_R_C_1);
4014 if constexpr (T::IS_R800) {
4015 f |=
byte(getF() & (C_FLAG | X_FLAG | Y_FLAG));
4016 f |= table.
ZSP[res];
4018 f |=
byte(getF() & C_FLAG);
4019 f |= table.
ZSPXY[res];
4023 return {1, T::CC_IN_R_C};
4027template<
typename T> II CPUCore<T>::in_a_byte() {
4028 unsigned y = RDMEM_OPCODE<1>(T::CC_IN_A_N_1) + 256 * getA();
4029 T::setMemPtr(y + 1);
4030 if constexpr (T::IS_R800) T::waitForEvenCycle(T::CC_IN_A_N_2);
4031 setA(READ_PORT(narrow_cast<word>(y), T::CC_IN_A_N_2));
4032 return {2, T::CC_IN_A_N};
4036template<
typename T>
template<Reg8 REG> II CPUCore<T>::out_c_R() {
4037 if constexpr (T::IS_R800) T::waitForEvenCycle(T::CC_OUT_C_R_1);
4038 T::setMemPtr(getBC() + 1);
4039 WRITE_PORT(getBC(), get8<REG>(), T::CC_OUT_C_R_1);
4040 return {1, T::CC_OUT_C_R};
4042template<
typename T> II CPUCore<T>::out_c_0() {
4044 if constexpr (T::IS_R800) T::waitForEvenCycle(T::CC_OUT_C_R_1);
4045 T::setMemPtr(getBC() + 1);
4046 byte out_c_x = isCMOS ? 255 : 0;
4047 WRITE_PORT(getBC(), out_c_x, T::CC_OUT_C_R_1);
4048 return {1, T::CC_OUT_C_R};
4052template<
typename T> II CPUCore<T>::out_byte_a() {
4053 byte port = RDMEM_OPCODE<1>(T::CC_OUT_N_A_1);
4054 auto y = narrow_cast<word>((getA() << 8) | port);
4055 T::setMemPtr((getA() << 8) | ((port + 1) & 255));
4056 if constexpr (T::IS_R800) T::waitForEvenCycle(T::CC_OUT_N_A_2);
4057 WRITE_PORT(y, getA(), T::CC_OUT_N_A_2);
4058 return {2, T::CC_OUT_N_A};
4063template<
typename T>
inline II CPUCore<T>::BLOCK_CP(
int increase,
bool repeat) {
4064 T::setMemPtr(T::getMemPtr() + increase);
4065 byte val = RDMEM(getHL(), T::CC_CPI_1);
4066 byte res = getA() - val;
4067 setHL(narrow_cast<word>(getHL() + increase));
4069 byte f = ((getA() ^ val ^ res) & H_FLAG) |
4072 (getBC() ? V_FLAG : 0);
4073 if constexpr (T::IS_R800) {
4074 f |=
byte(getF() & (C_FLAG | X_FLAG | Y_FLAG));
4076 f |=
byte(getF() & C_FLAG);
4077 unsigned k = res - ((f & H_FLAG) >> 4);
4078 f |= (k << 4) & Y_FLAG;
4082 if (
repeat && getBC() && res) {
4084 T::setMemPtr(getPC() + 1);
4085 return {
word(-1), T::CC_CPIR};
4087 return {1, T::CC_CPI};
4090template<
typename T> II CPUCore<T>::cpd() {
return BLOCK_CP(-1,
false); }
4091template<
typename T> II CPUCore<T>::cpi() {
return BLOCK_CP( 1,
false); }
4092template<
typename T> II CPUCore<T>::cpdr() {
return BLOCK_CP(-1,
true ); }
4093template<
typename T> II CPUCore<T>::cpir() {
return BLOCK_CP( 1,
true ); }
4097template<
typename T>
inline II CPUCore<T>::BLOCK_LD(
int increase,
bool repeat) {
4098 byte val = RDMEM(getHL(), T::CC_LDI_1);
4099 WRMEM(getDE(), val, T::CC_LDI_2);
4100 setHL(narrow_cast<word>(getHL() + increase));
4101 setDE(narrow_cast<word>(getDE() + increase));
4103 byte f = getBC() ? V_FLAG : 0;
4104 if constexpr (T::IS_R800) {
4105 f |=
byte(getF() & (S_FLAG | Z_FLAG | C_FLAG | X_FLAG | Y_FLAG));
4107 f |=
byte(getF() & (S_FLAG | Z_FLAG | C_FLAG));
4108 f |=
byte(((getA() + val) << 4) & Y_FLAG);
4109 f |=
byte((getA() + val) & X_FLAG);
4114 T::setMemPtr(getPC() + 1);
4115 return {
word(-1), T::CC_LDIR};
4117 return {1, T::CC_LDI};
4120template<
typename T> II CPUCore<T>::ldd() {
return BLOCK_LD(-1,
false); }
4121template<
typename T> II CPUCore<T>::ldi() {
return BLOCK_LD( 1,
false); }
4122template<
typename T> II CPUCore<T>::lddr() {
return BLOCK_LD(-1,
true ); }
4123template<
typename T> II CPUCore<T>::ldir() {
return BLOCK_LD( 1,
true ); }
4127template<
typename T>
inline II CPUCore<T>::BLOCK_IN(
int increase,
bool repeat) {
4128 if constexpr (T::IS_R800) T::waitForEvenCycle(T::CC_INI_1);
4129 T::setMemPtr(getBC() + increase);
4130 setBC(getBC() - 0x100);
4131 byte val = READ_PORT(getBC(), T::CC_INI_1);
4132 WRMEM(getHL(), val, T::CC_INI_2);
4133 setHL(narrow_cast<word>(getHL() + increase));
4134 unsigned k = val + ((getC() + increase) & 0xFF);
4136 if constexpr (T::IS_R800) {
4137 setF((getF() & ~Z_FLAG) | (b ? 0 : Z_FLAG) | N_FLAG);
4139 setF(((val & S_FLAG) >> 6) |
4140 ((k & 0x100) ? (H_FLAG | C_FLAG) : 0) |
4142 (table.ZSPXY[(k & 0x07) ^ b] & P_FLAG));
4146 return {
word(-1), T::CC_INIR};
4148 return {1, T::CC_INI};
4151template<
typename T> II CPUCore<T>::ind() {
return BLOCK_IN(-1,
false); }
4152template<
typename T> II CPUCore<T>::ini() {
return BLOCK_IN( 1,
false); }
4153template<
typename T> II CPUCore<T>::indr() {
return BLOCK_IN(-1,
true ); }
4154template<
typename T> II CPUCore<T>::inir() {
return BLOCK_IN( 1,
true ); }
4158template<
typename T>
inline II CPUCore<T>::BLOCK_OUT(
int increase,
bool repeat) {
4159 byte val = RDMEM(getHL(), T::CC_OUTI_1);
4160 setHL(narrow_cast<word>(getHL() + increase));
4161 if constexpr (T::IS_R800) T::waitForEvenCycle(T::CC_OUTI_2);
4162 WRITE_PORT(getBC(), val, T::CC_OUTI_2);
4163 setBC(getBC() - 0x100);
4164 T::setMemPtr(getBC() + increase);
4165 unsigned k = val + getL();
4167 if constexpr (T::IS_R800) {
4168 setF((getF() & ~Z_FLAG) | (b ? 0 : Z_FLAG) | N_FLAG);
4170 setF(((val & S_FLAG) >> 6) |
4171 ((k & 0x100) ? (H_FLAG | C_FLAG) : 0) |
4173 (table.ZSPXY[(k & 0x07) ^ b] & P_FLAG));
4177 return {
word(-1), T::CC_OTIR};
4179 return {1, T::CC_OUTI};
4182template<
typename T> II CPUCore<T>::outd() {
return BLOCK_OUT(-1,
false); }
4183template<
typename T> II CPUCore<T>::outi() {
return BLOCK_OUT( 1,
false); }
4184template<
typename T> II CPUCore<T>::otdr() {
return BLOCK_OUT(-1,
true ); }
4185template<
typename T> II CPUCore<T>::otir() {
return BLOCK_OUT( 1,
true ); }
4189template<
typename T>
template<
int EE> II CPUCore<T>::nop() {
return {1, T::CC_NOP + EE}; }
4190template<
typename T> II CPUCore<T>::ccf() {
4192 if constexpr (T::IS_R800) {
4194 f |=
byte(getF() & (S_FLAG | Z_FLAG | P_FLAG | C_FLAG | X_FLAG | Y_FLAG | H_FLAG));
4196 f |=
byte((getF() & C_FLAG) << 4);
4200 f |=
byte(getF() & (S_FLAG | Z_FLAG | P_FLAG | C_FLAG | Y_FLAG));
4201 f |=
byte((getF() | getA()) & X_FLAG);
4203 f |=
byte(getF() & (S_FLAG | Z_FLAG | P_FLAG | C_FLAG));
4204 f |=
byte((getF() | getA()) & (X_FLAG | Y_FLAG));
4209 return {1, T::CC_CCF};
4211template<
typename T> II CPUCore<T>::cpl() {
4212 setA(getA() ^ 0xFF);
4213 byte f = H_FLAG | N_FLAG;
4214 if constexpr (T::IS_R800) {
4217 f |=
byte(getF() & (S_FLAG | Z_FLAG | P_FLAG | C_FLAG));
4218 f |=
byte(getA() & (X_FLAG | Y_FLAG));
4221 return {1, T::CC_CPL};
4223template<
typename T> II CPUCore<T>::daa() {
4227 if ((f & H_FLAG) || ((getA() & 0xf) > 9)) adjust += 6;
4228 if ((f & C_FLAG) || (getA() > 0x99)) adjust += 0x60;
4229 if (f & N_FLAG) a -= adjust;
else a += adjust;
4230 if constexpr (T::IS_R800) {
4231 f &= C_FLAG | N_FLAG | X_FLAG | Y_FLAG;
4234 f &= C_FLAG | N_FLAG;
4235 f |= table.
ZSPXY[a];
4237 f |=
byte((getA() > 0x99) | ((getA() ^ a) & H_FLAG));
4240 return {1, T::CC_DAA};
4242template<
typename T> II CPUCore<T>::neg() {
4244 unsigned a = getA();
4245 unsigned res = -signed(a);
4246 byte f = ((res & 0x100) ? C_FLAG : 0) |
4248 ((res ^ a) & H_FLAG) |
4249 ((a & res & 0x80) >> 5);
4250 if constexpr (T::IS_R800) {
4251 f |= table.
ZS[res & 0xFF];
4252 f |=
byte(getF() & (X_FLAG | Y_FLAG));
4254 f |= table.
ZSXY[res & 0xFF];
4257 setA(narrow_cast<byte>(res));
4258 return {1, T::CC_NEG};
4260template<
typename T> II CPUCore<T>::scf() {
4262 if constexpr (T::IS_R800) {
4263 f |=
byte(getF() & (S_FLAG | Z_FLAG | P_FLAG | X_FLAG | Y_FLAG));
4268 f |=
byte(getF() & (S_FLAG | Z_FLAG | P_FLAG | Y_FLAG));
4269 f |=
byte((getF() | getA()) & X_FLAG);
4271 f |=
byte(getF() & (S_FLAG | Z_FLAG | P_FLAG));
4272 f |=
byte((getF() | getA()) & (X_FLAG | Y_FLAG));
4276 return {1, T::CC_SCF};
4279template<
typename T> II CPUCore<T>::ex_af_af() {
4280 auto t = getAF2(); setAF2(getAF()); setAF(
t);
4281 return {1, T::CC_EX};
4283template<
typename T> II CPUCore<T>::ex_de_hl() {
4284 auto t = getDE(); setDE(getHL()); setHL(
t);
4285 return {1, T::CC_EX};
4287template<
typename T> II CPUCore<T>::exx() {
4288 auto t1 = getBC2(); setBC2(getBC()); setBC(t1);
4289 auto t2 = getDE2(); setDE2(getDE()); setDE(t2);
4290 auto t3 = getHL2(); setHL2(getHL()); setHL(t3);
4291 return {1, T::CC_EX};
4294template<
typename T> II CPUCore<T>::di() {
4297 return {1, T::CC_DI};
4299template<
typename T> II CPUCore<T>::ei() {
4303 setSlowInstructions();
4304 return {1, T::CC_EI};
4306template<
typename T> II CPUCore<T>::halt() {
4308 setSlowInstructions();
4310 if (!(getIFF1() || getIFF2())) {
4311 diHaltCallback.execute();
4313 return {1, T::CC_HALT};
4315template<
typename T>
template<
unsigned N> II CPUCore<T>::im_N() {
4316 setIM(N);
return {1, T::CC_IM};
4320template<
typename T>
template<Reg8 REG> II CPUCore<T>::ld_a_IR() {
4322 byte f = getIFF2() ? V_FLAG : 0;
4323 if constexpr (T::IS_R800) {
4324 f |=
byte(getF() & (C_FLAG | X_FLAG | Y_FLAG));
4325 f |= table.
ZS[getA()];
4327 f |=
byte(getF() & C_FLAG);
4328 f |= table.
ZSXY[getA()];
4331 setSlowInstructions();
4334 return {1, T::CC_LD_A_I};
4338template<
typename T> II CPUCore<T>::ld_r_a() {
4347 if constexpr (T::IS_R800) val -= 1;
4349 return {1, T::CC_LD_A_I};
4351template<
typename T> II CPUCore<T>::ld_i_a() {
4353 return {1, T::CC_LD_A_I};
4357template<
typename T>
template<Reg8 REG> II CPUCore<T>::mulub_a_R() {
4364 setHL(
word(getA()) *
word(get8<REG>()));
4365 setF((getF() & (N_FLAG | H_FLAG | X_FLAG | Y_FLAG)) |
4367 (getHL() ? 0 : Z_FLAG) |
4368 ((getHL() & 0xFF00) ? C_FLAG : 0));
4369 return {1, T::CC_MULUB};
4373template<
typename T>
template<Reg16 REG> II CPUCore<T>::muluw_hl_SS() {
4380 uint32_t res = uint32_t(getHL()) * get16<REG>();
4381 setDE(narrow_cast<word>(res >> 16));
4382 setHL(narrow_cast<word>(res >> 0));
4383 setF((getF() & (N_FLAG | H_FLAG | X_FLAG | Y_FLAG)) |
4385 (res ? 0 : Z_FLAG) |
4386 ((res & 0xFFFF0000) ? C_FLAG : 0));
4387 return {1, T::CC_MULUW};
4397template<
typename T>
template<
typename Archive>
4400 T::serialize(ar, version);
4401 ar.serialize(
"regs",
static_cast<CPURegs&
>(*
this));
4402 if (ar.versionBelow(version, 2)) {
4404 ar.serialize(
"memptr", mPtr);
4408 if (ar.versionBelow(version, 5)) {
4417 ar.serialize(
"nmiEdge", nmiEdge);
4426 if constexpr (T::IS_R800) {
4427 if (ar.versionBelow(version, 4)) {
4428 motherboard.getMSXCliComm().printWarning(
4429 "Loading an old savestate: the timing of the R800 "
4430 "emulation has changed. This may cause synchronization "
4431 "problems in replay.");