1 // license:BSD-3-Clause 2 // copyright-holders:Juergen Buchmueller 3 /* tmp1 value for ini/inir/outi/otir for [C.1-0][io.1-0] */ 4 static const uint8_t irep_tmp1[4][4] = { 5 {0,0,1,0},{0,1,0,1},{1,0,1,1},{0,1,1,0} 6 }; 7 8 /* tmp1 value for ind/indr/outd/otdr for [C.1-0][io.1-0] */ 9 static const uint8_t drep_tmp1[4][4] = { 10 {0,1,0,0},{1,0,0,1},{0,0,1,0},{0,1,0,1} 11 }; 12 13 /* tmp2 value for all in/out repeated opcodes for B.7-0 */ 14 static const uint8_t breg_tmp2[256] = { 15 0,0,1,1,0,1,0,0,1,1,0,0,1,0,1,1, 16 0,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0, 17 1,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0, 18 1,0,1,1,0,1,0,0,1,1,0,0,1,0,1,1, 19 0,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0, 20 1,0,1,1,0,1,0,0,1,1,0,0,1,0,1,1, 21 0,0,1,1,0,1,0,0,1,1,0,0,1,0,1,1, 22 0,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0, 23 1,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0, 24 1,0,1,1,0,1,0,0,1,1,0,0,1,0,1,1, 25 0,0,1,1,0,1,0,0,1,1,0,0,1,0,1,1, 26 0,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0, 27 1,0,1,1,0,1,0,0,1,1,0,0,1,0,1,1, 28 0,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0, 29 1,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0, 30 1,0,1,1,0,1,0,0,1,1,0,0,1,0,1,1 31 }; 32 33 static const uint8_t cc_op[0x100] = { 34 /*-0 -1 -2 -3 -4 -5 -6 -7 -8 -9 -a -b -c -d -e -f */ 35 3, 9, 7, 4, 4, 4, 6, 3, 4, 7, 6, 4, 4, 4, 6, 3, 36 7, 9, 7, 4, 4, 4, 6, 3, 8, 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6, 6, 6, 6, 6, 9, 6, 6, 6, 6, 6, 6, 6, 9, 6, 61 6, 6, 6, 6, 6, 6, 9, 6, 6, 6, 6, 6, 6, 6, 9, 6, 62 6, 6, 6, 6, 6, 6, 9, 6, 6, 6, 6, 6, 6, 6, 9, 6, 63 7, 7, 7, 7, 7, 7,13, 7, 7, 7, 7, 7, 7, 7,13, 7, 64 7, 7, 7, 7, 7, 7,13, 7, 7, 7, 7, 7, 7, 7,13, 7, 65 7, 7, 7, 7, 7, 7,13, 7, 7, 7, 7, 7, 7, 7,13, 7, 66 7, 7, 7, 7, 7, 7,13, 7, 7, 7, 7, 7, 7, 7,13, 7, 67 7, 7, 7, 7, 7, 7,13, 7, 7, 7, 7, 7, 7, 7,13, 7, 68 7, 7, 7, 7, 7, 7,13, 7, 7, 7, 7, 7, 7, 7,13, 7, 69 7, 7, 7, 7, 7, 7,13, 7, 7, 7, 7, 7, 7, 7,13, 7, 70 7, 7, 7, 7, 7, 7,13, 7, 7, 7, 7, 7, 7, 7,13, 7 71 }; 72 73 static const uint8_t cc_ed[0x100] = { 74 /*-0 -1 -2 -3 -4 -5 -6 -7 -8 -9 -a -b -c -d -e -f */ 75 12,13, 6, 6, 9, 6, 6, 6,12,13, 6, 6, 9, 6, 6, 6, 76 12,13, 6, 6, 9, 6, 6, 6,12,13, 6, 6, 9, 6, 6, 6, 77 12,13, 6, 6, 9, 6, 6, 6,12,13, 6, 6,10, 6, 6, 6, 78 12,13, 6, 6, 9, 6, 6, 6,12,13, 6, 6, 9, 6, 6, 6, 79 9,10,10,19, 6,12, 6, 6, 9,10,10,18,17,12, 6, 6, 80 9,10,10,19, 6,12, 6, 6, 9,10,10,18,17,12, 6, 6, 81 9,10,10,19, 6,12, 6,16, 9,10,10,18,17,12, 6,16, 82 9,10,10,19,12,12, 8, 6, 9,10,10,18,17,12, 6, 6, 83 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 84 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 85 12,12,12,12, 6, 6, 6, 6,12,12,12,12, 6, 6, 6, 6, 86 12,12,12,12, 6, 6, 6, 6,12,12,12,12, 6, 6, 6, 6, 87 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 88 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 89 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 90 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6 91 }; 92 93 static const uint8_t cc_xy[0x100] = { 94 /*-0 -1 -2 -3 -4 -5 -6 -7 -8 -9 -a -b -c -d -e -f */ 95 4, 4, 4, 4, 4, 4, 4, 4, 4,10, 4, 4, 4, 4, 4, 4, 96 4, 4, 4, 4, 4, 4, 4, 4, 4,10, 4, 4, 4, 4, 4, 4, 97 4,12,19, 7, 9, 9,15, 4, 4,10,18, 7, 9, 9, 9, 4, 98 4, 4, 4, 4,18,18,15, 4, 4,10, 4, 4, 4, 4, 4, 4, 99 4, 4, 4, 4, 9, 9,14, 4, 4, 4, 4, 4, 9, 9,14, 4, 100 4, 4, 4, 4, 9, 9,14, 4, 4, 4, 4, 4, 9, 9,14, 4, 101 9, 9, 9, 9, 9, 9,14, 9, 9, 9, 9, 9, 9, 9,14, 9, 102 15,15,15,15,15,15, 4,15, 4, 4, 4, 4, 9, 9,14, 4, 103 4, 4, 4, 4, 9, 9,14, 4, 4, 4, 4, 4, 9, 9,14, 4, 104 4, 4, 4, 4, 9, 9,14, 4, 4, 4, 4, 4, 9, 9,14, 4, 105 4, 4, 4, 4, 9, 9,14, 4, 4, 4, 4, 4, 9, 9,14, 4, 106 4, 4, 4, 4, 9, 9,14, 4, 4, 4, 4, 4, 9, 9,14, 4, 107 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 0, 4, 4, 4, 4, 108 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 109 4,12, 4,19, 4,14, 4, 4, 4, 6, 4, 4, 4, 4, 4, 4, 110 4, 4, 4, 4, 4, 4, 4, 4, 4, 7, 4, 4, 4, 4, 4, 4 111 }; 112 113 static const uint8_t cc_xycb[0x100] = { 114 /*-0 -1 -2 -3 -4 -5 -6 -7 -8 -9 -a -b -c -d -e -f */ 115 19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19, 116 19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19, 117 19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19, 118 19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19, 119 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15, 120 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15, 121 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15, 122 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15, 123 19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19, 124 19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19, 125 19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19, 126 19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19, 127 19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19, 128 19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19, 129 19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19, 130 19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19 131 }; 132 133 /* extra cycles if jr/jp/call taken and 'interrupt latency' on rst 0-7 */ 134 static const uint8_t cc_ex[0x100] = { 135 /*-0 -1 -2 -3 -4 -5 -6 -7 -8 -9 -a -b -c -d -e -f */ 136 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 137 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* DJNZ */ 138 2, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, /* JR NZ/JR Z */ 139 2, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, /* JR NC/JR C */ 140 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,10, 0, 0, 141 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,10, 0, 0, 142 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,10, 0, 0, 143 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,10, 0, 0, 144 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 145 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 146 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 147 4, 4, 4, 4, 0, 0, 0, 0, 4, 4, 4, 4, 0, 0, 0, 0, /* LDIR/CPIR/INIR/OTIR LDDR/CPDR/INDR/OTDR */ 148 5, 0, 3, 0,10, 0, 0, 2, 5, 0, 3, 0,10, 0, 0, 2, 149 5, 0, 3, 0,10, 0, 0, 2, 5, 0, 3, 0,10, 0, 0, 2, 150 5, 0, 3, 0,10, 0, 0, 2, 5, 0, 3, 0,10, 0, 0, 2, 151 5, 0, 3, 0,10, 0, 0, 2, 5, 0, 3, 0,10, 0, 0, 2 152 }; 153 154 static const uint8_t *const cc_default[6] = { cc_op, cc_cb, cc_ed, cc_xy, cc_xycb, cc_ex }; 155 156 #define Z180_TABLE_dd Z180_TABLE_xy 157 #define Z180_TABLE_fd Z180_TABLE_xy 158 159 160 #define TABLE(prefix) {\ 161 &z180_device::prefix##_00,&z180_device::prefix##_01,&z180_device::prefix##_02,&z180_device::prefix##_03,&z180_device::prefix##_04,&z180_device::prefix##_05,&z180_device::prefix##_06,&z180_device::prefix##_07, \ 162 &z180_device::prefix##_08,&z180_device::prefix##_09,&z180_device::prefix##_0a,&z180_device::prefix##_0b,&z180_device::prefix##_0c,&z180_device::prefix##_0d,&z180_device::prefix##_0e,&z180_device::prefix##_0f, \ 163 &z180_device::prefix##_10,&z180_device::prefix##_11,&z180_device::prefix##_12,&z180_device::prefix##_13,&z180_device::prefix##_14,&z180_device::prefix##_15,&z180_device::prefix##_16,&z180_device::prefix##_17, \ 164 &z180_device::prefix##_18,&z180_device::prefix##_19,&z180_device::prefix##_1a,&z180_device::prefix##_1b,&z180_device::prefix##_1c,&z180_device::prefix##_1d,&z180_device::prefix##_1e,&z180_device::prefix##_1f, \ 165 &z180_device::prefix##_20,&z180_device::prefix##_21,&z180_device::prefix##_22,&z180_device::prefix##_23,&z180_device::prefix##_24,&z180_device::prefix##_25,&z180_device::prefix##_26,&z180_device::prefix##_27, \ 166 &z180_device::prefix##_28,&z180_device::prefix##_29,&z180_device::prefix##_2a,&z180_device::prefix##_2b,&z180_device::prefix##_2c,&z180_device::prefix##_2d,&z180_device::prefix##_2e,&z180_device::prefix##_2f, \ 167 &z180_device::prefix##_30,&z180_device::prefix##_31,&z180_device::prefix##_32,&z180_device::prefix##_33,&z180_device::prefix##_34,&z180_device::prefix##_35,&z180_device::prefix##_36,&z180_device::prefix##_37, \ 168 &z180_device::prefix##_38,&z180_device::prefix##_39,&z180_device::prefix##_3a,&z180_device::prefix##_3b,&z180_device::prefix##_3c,&z180_device::prefix##_3d,&z180_device::prefix##_3e,&z180_device::prefix##_3f, \ 169 &z180_device::prefix##_40,&z180_device::prefix##_41,&z180_device::prefix##_42,&z180_device::prefix##_43,&z180_device::prefix##_44,&z180_device::prefix##_45,&z180_device::prefix##_46,&z180_device::prefix##_47, \ 170 &z180_device::prefix##_48,&z180_device::prefix##_49,&z180_device::prefix##_4a,&z180_device::prefix##_4b,&z180_device::prefix##_4c,&z180_device::prefix##_4d,&z180_device::prefix##_4e,&z180_device::prefix##_4f, \ 171 &z180_device::prefix##_50,&z180_device::prefix##_51,&z180_device::prefix##_52,&z180_device::prefix##_53,&z180_device::prefix##_54,&z180_device::prefix##_55,&z180_device::prefix##_56,&z180_device::prefix##_57, \ 172 &z180_device::prefix##_58,&z180_device::prefix##_59,&z180_device::prefix##_5a,&z180_device::prefix##_5b,&z180_device::prefix##_5c,&z180_device::prefix##_5d,&z180_device::prefix##_5e,&z180_device::prefix##_5f, \ 173 &z180_device::prefix##_60,&z180_device::prefix##_61,&z180_device::prefix##_62,&z180_device::prefix##_63,&z180_device::prefix##_64,&z180_device::prefix##_65,&z180_device::prefix##_66,&z180_device::prefix##_67, \ 174 &z180_device::prefix##_68,&z180_device::prefix##_69,&z180_device::prefix##_6a,&z180_device::prefix##_6b,&z180_device::prefix##_6c,&z180_device::prefix##_6d,&z180_device::prefix##_6e,&z180_device::prefix##_6f, \ 175 &z180_device::prefix##_70,&z180_device::prefix##_71,&z180_device::prefix##_72,&z180_device::prefix##_73,&z180_device::prefix##_74,&z180_device::prefix##_75,&z180_device::prefix##_76,&z180_device::prefix##_77, \ 176 &z180_device::prefix##_78,&z180_device::prefix##_79,&z180_device::prefix##_7a,&z180_device::prefix##_7b,&z180_device::prefix##_7c,&z180_device::prefix##_7d,&z180_device::prefix##_7e,&z180_device::prefix##_7f, \ 177 &z180_device::prefix##_80,&z180_device::prefix##_81,&z180_device::prefix##_82,&z180_device::prefix##_83,&z180_device::prefix##_84,&z180_device::prefix##_85,&z180_device::prefix##_86,&z180_device::prefix##_87, \ 178 &z180_device::prefix##_88,&z180_device::prefix##_89,&z180_device::prefix##_8a,&z180_device::prefix##_8b,&z180_device::prefix##_8c,&z180_device::prefix##_8d,&z180_device::prefix##_8e,&z180_device::prefix##_8f, \ 179 &z180_device::prefix##_90,&z180_device::prefix##_91,&z180_device::prefix##_92,&z180_device::prefix##_93,&z180_device::prefix##_94,&z180_device::prefix##_95,&z180_device::prefix##_96,&z180_device::prefix##_97, \ 180 &z180_device::prefix##_98,&z180_device::prefix##_99,&z180_device::prefix##_9a,&z180_device::prefix##_9b,&z180_device::prefix##_9c,&z180_device::prefix##_9d,&z180_device::prefix##_9e,&z180_device::prefix##_9f, \ 181 &z180_device::prefix##_a0,&z180_device::prefix##_a1,&z180_device::prefix##_a2,&z180_device::prefix##_a3,&z180_device::prefix##_a4,&z180_device::prefix##_a5,&z180_device::prefix##_a6,&z180_device::prefix##_a7, \ 182 &z180_device::prefix##_a8,&z180_device::prefix##_a9,&z180_device::prefix##_aa,&z180_device::prefix##_ab,&z180_device::prefix##_ac,&z180_device::prefix##_ad,&z180_device::prefix##_ae,&z180_device::prefix##_af, \ 183 &z180_device::prefix##_b0,&z180_device::prefix##_b1,&z180_device::prefix##_b2,&z180_device::prefix##_b3,&z180_device::prefix##_b4,&z180_device::prefix##_b5,&z180_device::prefix##_b6,&z180_device::prefix##_b7, \ 184 &z180_device::prefix##_b8,&z180_device::prefix##_b9,&z180_device::prefix##_ba,&z180_device::prefix##_bb,&z180_device::prefix##_bc,&z180_device::prefix##_bd,&z180_device::prefix##_be,&z180_device::prefix##_bf, \ 185 &z180_device::prefix##_c0,&z180_device::prefix##_c1,&z180_device::prefix##_c2,&z180_device::prefix##_c3,&z180_device::prefix##_c4,&z180_device::prefix##_c5,&z180_device::prefix##_c6,&z180_device::prefix##_c7, \ 186 &z180_device::prefix##_c8,&z180_device::prefix##_c9,&z180_device::prefix##_ca,&z180_device::prefix##_cb,&z180_device::prefix##_cc,&z180_device::prefix##_cd,&z180_device::prefix##_ce,&z180_device::prefix##_cf, \ 187 &z180_device::prefix##_d0,&z180_device::prefix##_d1,&z180_device::prefix##_d2,&z180_device::prefix##_d3,&z180_device::prefix##_d4,&z180_device::prefix##_d5,&z180_device::prefix##_d6,&z180_device::prefix##_d7, \ 188 &z180_device::prefix##_d8,&z180_device::prefix##_d9,&z180_device::prefix##_da,&z180_device::prefix##_db,&z180_device::prefix##_dc,&z180_device::prefix##_dd,&z180_device::prefix##_de,&z180_device::prefix##_df, \ 189 &z180_device::prefix##_e0,&z180_device::prefix##_e1,&z180_device::prefix##_e2,&z180_device::prefix##_e3,&z180_device::prefix##_e4,&z180_device::prefix##_e5,&z180_device::prefix##_e6,&z180_device::prefix##_e7, \ 190 &z180_device::prefix##_e8,&z180_device::prefix##_e9,&z180_device::prefix##_ea,&z180_device::prefix##_eb,&z180_device::prefix##_ec,&z180_device::prefix##_ed,&z180_device::prefix##_ee,&z180_device::prefix##_ef, \ 191 &z180_device::prefix##_f0,&z180_device::prefix##_f1,&z180_device::prefix##_f2,&z180_device::prefix##_f3,&z180_device::prefix##_f4,&z180_device::prefix##_f5,&z180_device::prefix##_f6,&z180_device::prefix##_f7, \ 192 &z180_device::prefix##_f8,&z180_device::prefix##_f9,&z180_device::prefix##_fa,&z180_device::prefix##_fb,&z180_device::prefix##_fc,&z180_device::prefix##_fd,&z180_device::prefix##_fe,&z180_device::prefix##_ff \ 193 } 194 195 196 const z180_device::opcode_func z180_device::s_z180ops[Z180_PREFIX_COUNT][0x100] = 197 { 198 TABLE(op), 199 TABLE(cb), 200 TABLE(dd), 201 TABLE(ed), 202 TABLE(fd), 203 TABLE(xycb) 204 }; 205 206 /*************************************************************** 207 * define an opcode function 208 ***************************************************************/ 209 #define OP(prefix,opcode) void z180_device::prefix##_##opcode() 210 211 /*************************************************************** 212 * adjust cycle count by n T-states 213 ***************************************************************/ 214 #define CC(prefix,opcode) m_extra_cycles += m_cc[Z180_TABLE_##prefix][opcode] 215 216 /*************************************************************** 217 * execute an opcode 218 ***************************************************************/ 219 220 #define EXEC_PROTOTYPE(prefix) \ 221 int z180_device::exec##_##prefix(const uint8_t opcode) \ 222 { \ 223 (this->*s_z180ops[Z180_PREFIX_##prefix][opcode])(); \ 224 return m_cc[Z180_TABLE_##prefix][opcode]; \ 225 } 226 227 EXEC_PROTOTYPE(op) 228 EXEC_PROTOTYPE(cb) 229 EXEC_PROTOTYPE(dd) 230 EXEC_PROTOTYPE(ed) 231 EXEC_PROTOTYPE(fd) 232 EXEC_PROTOTYPE(xycb) 233