1 /** Z80: portable Z80 emulator *******************************/ 2 /** **/ 3 /** CodesXX.h **/ 4 /** **/ 5 /** This file contains implementation for FD/DD tables of **/ 6 /** Z80 commands. It is included from Z80.c. **/ 7 /** **/ 8 /** Copyright (C) Marat Fayzullin 1994,1995,1996,1997 **/ 9 /** You are not allowed to distribute this software **/ 10 /** commercially. Please, notify me, if you make any **/ 11 /** changes to this file. **/ 12 /*************************************************************/ 13 14 /* $Id: mz80opc5.h,v 1.2 1999/11/08 01:33:58 nyef Exp $ */ 15 16 case JR_NZ: if(R->AF.B.l&Z_FLAG) OpZ80_1(R); else { M_JR; } break; 17 case JR_NC: if(R->AF.B.l&C_FLAG) OpZ80_1(R); else { M_JR; } break; 18 case JR_Z: if(R->AF.B.l&Z_FLAG) { M_JR; } else OpZ80_1(R); break; 19 case JR_C: if(R->AF.B.l&C_FLAG) { M_JR; } else OpZ80_1(R); break; 20 21 case JP_NZ: if(R->AF.B.l&Z_FLAG) OpZ80_2(R); else { M_JP; } break; 22 case JP_NC: if(R->AF.B.l&C_FLAG) OpZ80_2(R); else { M_JP; } break; 23 case JP_PO: if(R->AF.B.l&P_FLAG) OpZ80_2(R); else { M_JP; } break; 24 case JP_P: if(R->AF.B.l&S_FLAG) OpZ80_2(R); else { M_JP; } break; 25 case JP_Z: if(R->AF.B.l&Z_FLAG) { M_JP; } else OpZ80_2(R); break; 26 case JP_C: if(R->AF.B.l&C_FLAG) { M_JP; } else OpZ80_2(R); break; 27 case JP_PE: if(R->AF.B.l&P_FLAG) { M_JP; } else OpZ80_2(R); break; 28 case JP_M: if(R->AF.B.l&S_FLAG) { M_JP; } else OpZ80_2(R); break; 29 30 case RET_NZ: if(!(R->AF.B.l&Z_FLAG)) { M_RET; } break; 31 case RET_NC: if(!(R->AF.B.l&C_FLAG)) { M_RET; } break; 32 case RET_PO: if(!(R->AF.B.l&P_FLAG)) { M_RET; } break; 33 case RET_P: if(!(R->AF.B.l&S_FLAG)) { M_RET; } break; 34 case RET_Z: if(R->AF.B.l&Z_FLAG) { M_RET; } break; 35 case RET_C: if(R->AF.B.l&C_FLAG) { M_RET; } break; 36 case RET_PE: if(R->AF.B.l&P_FLAG) { M_RET; } break; 37 case RET_M: if(R->AF.B.l&S_FLAG) { M_RET; } break; 38 39 case CALL_NZ: if(R->AF.B.l&Z_FLAG) OpZ80_2(R); else { M_CALL; } break; 40 case CALL_NC: if(R->AF.B.l&C_FLAG) OpZ80_2(R); else { M_CALL; } break; 41 case CALL_PO: if(R->AF.B.l&P_FLAG) OpZ80_2(R); else { M_CALL; } break; 42 case CALL_P: if(R->AF.B.l&S_FLAG) OpZ80_2(R); else { M_CALL; } break; 43 case CALL_Z: if(R->AF.B.l&Z_FLAG) { M_CALL; } else OpZ80_2(R); break; 44 case CALL_C: if(R->AF.B.l&C_FLAG) { M_CALL; } else OpZ80_2(R); break; 45 case CALL_PE: if(R->AF.B.l&P_FLAG) { M_CALL; } else OpZ80_2(R); break; 46 case CALL_M: if(R->AF.B.l&S_FLAG) { M_CALL; } else OpZ80_2(R); break; 47 48 case ADD_B: M_ADD(R->BC.B.h);break; 49 case ADD_C: M_ADD(R->BC.B.l);break; 50 case ADD_D: M_ADD(R->DE.B.h);break; 51 case ADD_E: M_ADD(R->DE.B.l);break; 52 case ADD_H: M_ADD(R->XX.B.h);break; 53 case ADD_L: M_ADD(R->XX.B.l);break; 54 case ADD_A: M_ADD(R->AF.B.h);break; 55 case ADD_xHL: I=RdZ80(R->XX.W+(offset)OpZ80(R)); 56 M_ADD(I);break; 57 case ADD_BYTE: I=OpZ80(R);M_ADD(I);break; 58 59 case SUB_B: M_SUB(R->BC.B.h);break; 60 case SUB_C: M_SUB(R->BC.B.l);break; 61 case SUB_D: M_SUB(R->DE.B.h);break; 62 case SUB_E: M_SUB(R->DE.B.l);break; 63 case SUB_H: M_SUB(R->XX.B.h);break; 64 case SUB_L: M_SUB(R->XX.B.l);break; 65 case SUB_A: R->AF.B.h=0;R->AF.B.l=N_FLAG|Z_FLAG;break; 66 case SUB_xHL: I=RdZ80(R->XX.W+(offset)OpZ80(R)); 67 M_SUB(I);break; 68 case SUB_BYTE: I=OpZ80(R);M_SUB(I);break; 69 70 case AND_B: M_AND(R->BC.B.h);break; 71 case AND_C: M_AND(R->BC.B.l);break; 72 case AND_D: M_AND(R->DE.B.h);break; 73 case AND_E: M_AND(R->DE.B.l);break; 74 case AND_H: M_AND(R->XX.B.h);break; 75 case AND_L: M_AND(R->XX.B.l);break; 76 case AND_A: M_AND(R->AF.B.h);break; 77 case AND_xHL: I=RdZ80(R->XX.W+(offset)OpZ80(R)); 78 M_AND(I);break; 79 case AND_BYTE: I=OpZ80(R);M_AND(I);break; 80 81 case OR_B: M_OR(R->BC.B.h);break; 82 case OR_C: M_OR(R->BC.B.l);break; 83 case OR_D: M_OR(R->DE.B.h);break; 84 case OR_E: M_OR(R->DE.B.l);break; 85 case OR_H: M_OR(R->XX.B.h);break; 86 case OR_L: M_OR(R->XX.B.l);break; 87 case OR_A: M_OR(R->AF.B.h);break; 88 case OR_xHL: I=RdZ80(R->XX.W+(offset)OpZ80(R)); 89 M_OR(I);break; 90 case OR_BYTE: I=OpZ80(R);M_OR(I);break; 91 92 case ADC_B: M_ADC(R->BC.B.h);break; 93 case ADC_C: M_ADC(R->BC.B.l);break; 94 case ADC_D: M_ADC(R->DE.B.h);break; 95 case ADC_E: M_ADC(R->DE.B.l);break; 96 case ADC_H: M_ADC(R->XX.B.h);break; 97 case ADC_L: M_ADC(R->XX.B.l);break; 98 case ADC_A: M_ADC(R->AF.B.h);break; 99 case ADC_xHL: I=RdZ80(R->XX.W+(offset)OpZ80(R)); 100 M_ADC(I);break; 101 case ADC_BYTE: I=OpZ80(R);M_ADC(I);break; 102 103 case SBC_B: M_SBC(R->BC.B.h);break; 104 case SBC_C: M_SBC(R->BC.B.l);break; 105 case SBC_D: M_SBC(R->DE.B.h);break; 106 case SBC_E: M_SBC(R->DE.B.l);break; 107 case SBC_H: M_SBC(R->XX.B.h);break; 108 case SBC_L: M_SBC(R->XX.B.l);break; 109 case SBC_A: M_SBC(R->AF.B.h);break; 110 case SBC_xHL: I=RdZ80(R->XX.W+(offset)OpZ80(R)); 111 M_SBC(I);break; 112 case SBC_BYTE: I=OpZ80(R);M_SBC(I);break; 113 114 case XOR_B: M_XOR(R->BC.B.h);break; 115 case XOR_C: M_XOR(R->BC.B.l);break; 116 case XOR_D: M_XOR(R->DE.B.h);break; 117 case XOR_E: M_XOR(R->DE.B.l);break; 118 case XOR_H: M_XOR(R->XX.B.h);break; 119 case XOR_L: M_XOR(R->XX.B.l);break; 120 case XOR_A: R->AF.B.h=0;R->AF.B.l=P_FLAG|Z_FLAG;break; 121 case XOR_xHL: I=RdZ80(R->XX.W+(offset)OpZ80(R)); 122 M_XOR(I);break; 123 case XOR_BYTE: I=OpZ80(R);M_XOR(I);break; 124 125 case CP_B: M_CP(R->BC.B.h);break; 126 case CP_C: M_CP(R->BC.B.l);break; 127 case CP_D: M_CP(R->DE.B.h);break; 128 case CP_E: M_CP(R->DE.B.l);break; 129 case CP_H: M_CP(R->XX.B.h);break; 130 case CP_L: M_CP(R->XX.B.l);break; 131 case CP_A: R->AF.B.l=N_FLAG|Z_FLAG;break; 132 case CP_xHL: I=RdZ80(R->XX.W+(offset)OpZ80(R)); 133 M_CP(I);break; 134 case CP_BYTE: I=OpZ80(R);M_CP(I);break; 135 136 case LD_BC_WORD: M_LDWORD(BC);break; 137 case LD_DE_WORD: M_LDWORD(DE);break; 138 case LD_HL_WORD: M_LDWORD(XX);break; 139 case LD_SP_WORD: M_LDWORD(SP);break; 140 141 case LD_PC_HL: R->PC.W=R->XX.W;mz80_cache_ip(R);break; 142 case LD_SP_HL: R->SP.W=R->XX.W;break; 143 case LD_A_xBC: R->AF.B.h=RdZ80(R->BC.W);break; 144 case LD_A_xDE: R->AF.B.h=RdZ80(R->DE.W);break; 145 146 case ADD_HL_BC: M_ADDW(XX,BC);break; 147 case ADD_HL_DE: M_ADDW(XX,DE);break; 148 case ADD_HL_HL: M_ADDW(XX,XX);break; 149 case ADD_HL_SP: M_ADDW(XX,SP);break; 150 151 case DEC_BC: R->BC.W--;break; 152 case DEC_DE: R->DE.W--;break; 153 case DEC_HL: R->XX.W--;break; 154 case DEC_SP: R->SP.W--;break; 155 156 case INC_BC: R->BC.W++;break; 157 case INC_DE: R->DE.W++;break; 158 case INC_HL: R->XX.W++;break; 159 case INC_SP: R->SP.W++;break; 160 161 case DEC_B: M_DEC(R->BC.B.h);break; 162 case DEC_C: M_DEC(R->BC.B.l);break; 163 case DEC_D: M_DEC(R->DE.B.h);break; 164 case DEC_E: M_DEC(R->DE.B.l);break; 165 case DEC_H: M_DEC(R->XX.B.h);break; 166 case DEC_L: M_DEC(R->XX.B.l);break; 167 case DEC_A: M_DEC(R->AF.B.h);break; 168 case DEC_xHL: J.B.l = OpZ80(R); 169 I=RdZ80(R->XX.W+(offset)J.B.l);M_DEC(I); 170 WrZ80(R->XX.W+(offset)J.B.l,I); 171 break; 172 173 case INC_B: M_INC(R->BC.B.h);break; 174 case INC_C: M_INC(R->BC.B.l);break; 175 case INC_D: M_INC(R->DE.B.h);break; 176 case INC_E: M_INC(R->DE.B.l);break; 177 case INC_H: M_INC(R->XX.B.h);break; 178 case INC_L: M_INC(R->XX.B.l);break; 179 case INC_A: M_INC(R->AF.B.h);break; 180 case INC_xHL: J.B.l = OpZ80(R); 181 I=RdZ80(R->XX.W+(offset)J.B.l);M_INC(I); 182 WrZ80(R->XX.W+(offset)J.B.l,I); 183 break; 184 185 case RLCA: 186 I=(R->AF.B.h&0x80? C_FLAG:0); 187 R->AF.B.h=(R->AF.B.h<<1)|I; 188 R->AF.B.l=(R->AF.B.l&~(C_FLAG|N_FLAG|H_FLAG))|I; 189 break; 190 case RLA: 191 I=(R->AF.B.h&0x80? C_FLAG:0); 192 R->AF.B.h=(R->AF.B.h<<1)|(R->AF.B.l&C_FLAG); 193 R->AF.B.l=(R->AF.B.l&~(C_FLAG|N_FLAG|H_FLAG))|I; 194 break; 195 case RRCA: 196 I=R->AF.B.h&0x01; 197 R->AF.B.h=(R->AF.B.h>>1)|(I? 0x80:0); 198 R->AF.B.l=(R->AF.B.l&~(C_FLAG|N_FLAG|H_FLAG))|I; 199 break; 200 case RRA: 201 I=R->AF.B.h&0x01; 202 R->AF.B.h=(R->AF.B.h>>1)|(R->AF.B.l&C_FLAG? 0x80:0); 203 R->AF.B.l=(R->AF.B.l&~(C_FLAG|N_FLAG|H_FLAG))|I; 204 break; 205 206 case RST00: M_RST(0x0000);break; 207 case RST08: M_RST(0x0008);break; 208 case RST10: M_RST(0x0010);break; 209 case RST18: M_RST(0x0018);break; 210 case RST20: M_RST(0x0020);break; 211 case RST28: M_RST(0x0028);break; 212 case RST30: M_RST(0x0030);break; 213 case RST38: M_RST(0x0038);break; 214 215 case PUSH_BC: M_PUSH(BC);break; 216 case PUSH_DE: M_PUSH(DE);break; 217 case PUSH_HL: M_PUSH(XX);break; 218 case PUSH_AF: M_PUSH(AF);break; 219 220 case POP_BC: M_POP(BC);break; 221 case POP_DE: M_POP(DE);break; 222 case POP_HL: M_POP(XX);break; 223 case POP_AF: M_POP(AF);break; 224 225 case DJNZ: if(--R->BC.B.h) { M_JR; } else OpZ80_1(R);break; 226 case JP: M_JP;break; 227 case JR: M_JR;break; 228 case CALL: M_CALL;break; 229 case RET: M_RET;break; 230 case SCF: S(C_FLAG);R(N_FLAG|H_FLAG);break; 231 case CPL: R->AF.B.h=~R->AF.B.h;S(N_FLAG|H_FLAG);break; 232 case NOP: break; 233 case OUTA: OutZ80(OpZ80(R),R->AF.B.h);break; 234 case INA: R->AF.B.h=InZ80(OpZ80(R));break; 235 236 case DI: 237 R->IFF&=0xFE; 238 break; 239 case EI: 240 R->IFF|=0x01; 241 if(R->IRequest!=INT_NONE) 242 { 243 R->IFF|=0x20; 244 R->IBackup=R->ICount; 245 R->ICount=1; 246 } 247 break; 248 249 case CCF: 250 R->AF.B.l^=C_FLAG;R(N_FLAG|H_FLAG); 251 R->AF.B.l|=R->AF.B.l&C_FLAG? 0:H_FLAG; 252 break; 253 254 case EXX: 255 J.W=R->BC.W;R->BC.W=R->BC1.W;R->BC1.W=J.W; 256 J.W=R->DE.W;R->DE.W=R->DE1.W;R->DE1.W=J.W; 257 J.W=R->HL.W;R->HL.W=R->HL1.W;R->HL1.W=J.W; 258 break; 259 260 case EX_DE_HL: J.W=R->DE.W;R->DE.W=R->HL.W;R->HL.W=J.W;break; 261 case EX_AF_AF: J.W=R->AF.W;R->AF.W=R->AF1.W;R->AF1.W=J.W;break; 262 263 case LD_B_B: R->BC.B.h=R->BC.B.h;break; 264 case LD_C_B: R->BC.B.l=R->BC.B.h;break; 265 case LD_D_B: R->DE.B.h=R->BC.B.h;break; 266 case LD_E_B: R->DE.B.l=R->BC.B.h;break; 267 case LD_H_B: R->XX.B.h=R->BC.B.h;break; 268 case LD_L_B: R->XX.B.l=R->BC.B.h;break; 269 case LD_A_B: R->AF.B.h=R->BC.B.h;break; 270 case LD_xHL_B: J.W=R->XX.W+(offset)OpZ80(R); 271 WrZ80(J.W,R->BC.B.h);break; 272 273 case LD_B_C: R->BC.B.h=R->BC.B.l;break; 274 case LD_C_C: R->BC.B.l=R->BC.B.l;break; 275 case LD_D_C: R->DE.B.h=R->BC.B.l;break; 276 case LD_E_C: R->DE.B.l=R->BC.B.l;break; 277 case LD_H_C: R->XX.B.h=R->BC.B.l;break; 278 case LD_L_C: R->XX.B.l=R->BC.B.l;break; 279 case LD_A_C: R->AF.B.h=R->BC.B.l;break; 280 case LD_xHL_C: J.W=R->XX.W+(offset)OpZ80(R); 281 WrZ80(J.W,R->BC.B.l);break; 282 283 case LD_B_D: R->BC.B.h=R->DE.B.h;break; 284 case LD_C_D: R->BC.B.l=R->DE.B.h;break; 285 case LD_D_D: R->DE.B.h=R->DE.B.h;break; 286 case LD_E_D: R->DE.B.l=R->DE.B.h;break; 287 case LD_H_D: R->XX.B.h=R->DE.B.h;break; 288 case LD_L_D: R->XX.B.l=R->DE.B.h;break; 289 case LD_A_D: R->AF.B.h=R->DE.B.h;break; 290 case LD_xHL_D: J.W=R->XX.W+(offset)OpZ80(R); 291 WrZ80(J.W,R->DE.B.h);break; 292 293 case LD_B_E: R->BC.B.h=R->DE.B.l;break; 294 case LD_C_E: R->BC.B.l=R->DE.B.l;break; 295 case LD_D_E: R->DE.B.h=R->DE.B.l;break; 296 case LD_E_E: R->DE.B.l=R->DE.B.l;break; 297 case LD_H_E: R->XX.B.h=R->DE.B.l;break; 298 case LD_L_E: R->XX.B.l=R->DE.B.l;break; 299 case LD_A_E: R->AF.B.h=R->DE.B.l;break; 300 case LD_xHL_E: J.W=R->XX.W+(offset)OpZ80(R); 301 WrZ80(J.W,R->DE.B.l);break; 302 303 case LD_B_H: R->BC.B.h=R->XX.B.h;break; 304 case LD_C_H: R->BC.B.l=R->XX.B.h;break; 305 case LD_D_H: R->DE.B.h=R->XX.B.h;break; 306 case LD_E_H: R->DE.B.l=R->XX.B.h;break; 307 case LD_H_H: R->XX.B.h=R->XX.B.h;break; 308 case LD_L_H: R->XX.B.l=R->XX.B.h;break; 309 case LD_A_H: R->AF.B.h=R->XX.B.h;break; 310 case LD_xHL_H: J.W=R->XX.W+(offset)OpZ80(R); 311 WrZ80(J.W,R->HL.B.h);break; 312 313 case LD_B_L: R->BC.B.h=R->XX.B.l;break; 314 case LD_C_L: R->BC.B.l=R->XX.B.l;break; 315 case LD_D_L: R->DE.B.h=R->XX.B.l;break; 316 case LD_E_L: R->DE.B.l=R->XX.B.l;break; 317 case LD_H_L: R->XX.B.h=R->XX.B.l;break; 318 case LD_L_L: R->XX.B.l=R->XX.B.l;break; 319 case LD_A_L: R->AF.B.h=R->XX.B.l;break; 320 case LD_xHL_L: J.W=R->XX.W+(offset)OpZ80(R); 321 WrZ80(J.W,R->HL.B.l);break; 322 323 case LD_B_A: R->BC.B.h=R->AF.B.h;break; 324 case LD_C_A: R->BC.B.l=R->AF.B.h;break; 325 case LD_D_A: R->DE.B.h=R->AF.B.h;break; 326 case LD_E_A: R->DE.B.l=R->AF.B.h;break; 327 case LD_H_A: R->XX.B.h=R->AF.B.h;break; 328 case LD_L_A: R->XX.B.l=R->AF.B.h;break; 329 case LD_A_A: R->AF.B.h=R->AF.B.h;break; 330 case LD_xHL_A: J.W=R->XX.W+(offset)OpZ80(R); 331 WrZ80(J.W,R->AF.B.h);break; 332 333 case LD_xBC_A: WrZ80(R->BC.W,R->AF.B.h);break; 334 case LD_xDE_A: WrZ80(R->DE.W,R->AF.B.h);break; 335 336 case LD_B_xHL: R->BC.B.h=RdZ80(R->XX.W+(offset)OpZ80(R));break; 337 case LD_C_xHL: R->BC.B.l=RdZ80(R->XX.W+(offset)OpZ80(R));break; 338 case LD_D_xHL: R->DE.B.h=RdZ80(R->XX.W+(offset)OpZ80(R));break; 339 case LD_E_xHL: R->DE.B.l=RdZ80(R->XX.W+(offset)OpZ80(R));break; 340 case LD_H_xHL: R->HL.B.h=RdZ80(R->XX.W+(offset)OpZ80(R));break; 341 case LD_L_xHL: R->HL.B.l=RdZ80(R->XX.W+(offset)OpZ80(R));break; 342 case LD_A_xHL: R->AF.B.h=RdZ80(R->XX.W+(offset)OpZ80(R));break; 343 344 case LD_B_BYTE: R->BC.B.h=OpZ80(R);break; 345 case LD_C_BYTE: R->BC.B.l=OpZ80(R);break; 346 case LD_D_BYTE: R->DE.B.h=OpZ80(R);break; 347 case LD_E_BYTE: R->DE.B.l=OpZ80(R);break; 348 case LD_H_BYTE: R->XX.B.h=OpZ80(R);break; 349 case LD_L_BYTE: R->XX.B.l=OpZ80(R);break; 350 case LD_A_BYTE: R->AF.B.h=OpZ80(R);break; 351 case LD_xHL_BYTE: J.W=R->XX.W+(offset)OpZ80(R); 352 WrZ80(J.W,OpZ80(R));break; 353 354 case LD_xWORD_HL: 355 J.B.l=OpZ80(R); 356 J.B.h=OpZ80(R); 357 WrZ80(J.W++,R->XX.B.l); 358 WrZ80(J.W,R->XX.B.h); 359 break; 360 361 case LD_HL_xWORD: 362 J.B.l=OpZ80(R); 363 J.B.h=OpZ80(R); 364 R->XX.B.l=RdZ80(J.W++); 365 R->XX.B.h=RdZ80(J.W); 366 break; 367 368 case LD_A_xWORD: 369 J.B.l=OpZ80(R); 370 J.B.h=OpZ80(R); 371 R->AF.B.h=RdZ80(J.W); 372 break; 373 374 case LD_xWORD_A: 375 J.B.l=OpZ80(R); 376 J.B.h=OpZ80(R); 377 WrZ80(J.W,R->AF.B.h); 378 break; 379 380 case EX_HL_xSP: 381 J.B.l=RdZ80(R->SP.W);WrZ80(R->SP.W++,R->XX.B.l); 382 J.B.h=RdZ80(R->SP.W);WrZ80(R->SP.W--,R->XX.B.h); 383 R->XX.W=J.W; 384 break; 385 386 case DAA: 387 J.W=R->AF.B.h; 388 if(R->AF.B.l&C_FLAG) J.W|=256; 389 if(R->AF.B.l&H_FLAG) J.W|=512; 390 if(R->AF.B.l&N_FLAG) J.W|=1024; 391 R->AF.W=DAATable[J.W]; 392 break; 393 394 /* 395 * $Log: mz80opc5.h,v $ 396 * Revision 1.2 1999/11/08 01:33:58 nyef 397 * added preliminary implementation of ranged mmu 398 * 399 * Revision 1.1 1999/01/03 02:29:05 nyef 400 * Initial revision 401 * 402 */ 403