1 /* z80_ddfd.c Z80 {DD,FD}xx opcodes 2 Copyright (c) 1999-2003 Philip Kendall 3 4 This program is free software; you can redistribute it and/or modify 5 it under the terms of the GNU General Public License as published by 6 the Free Software Foundation; either version 2 of the License, or 7 (at your option) any later version. 8 9 This program is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 GNU General Public License for more details. 13 14 You should have received a copy of the GNU General Public License along 15 with this program; if not, write to the Free Software Foundation, Inc., 16 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 18 Author contact information: 19 20 E-mail: philip-fuse@shadowmagic.org.uk 21 22 */ 23 24 /* NB: this file is autogenerated by '../../z80/z80.pl' from 'opcodes_ddfd.dat', 25 and included in 'z80_ops.c' */ 26 27 case 0x09: /* ADD REGISTER,BC */ 28 contend_read_no_mreq( IR, 1 ); 29 contend_read_no_mreq( IR, 1 ); 30 contend_read_no_mreq( IR, 1 ); 31 contend_read_no_mreq( IR, 1 ); 32 contend_read_no_mreq( IR, 1 ); 33 contend_read_no_mreq( IR, 1 ); 34 contend_read_no_mreq( IR, 1 ); 35 ADD16(REGISTER,BC); 36 break; 37 case 0x19: /* ADD REGISTER,DE */ 38 contend_read_no_mreq( IR, 1 ); 39 contend_read_no_mreq( IR, 1 ); 40 contend_read_no_mreq( IR, 1 ); 41 contend_read_no_mreq( IR, 1 ); 42 contend_read_no_mreq( IR, 1 ); 43 contend_read_no_mreq( IR, 1 ); 44 contend_read_no_mreq( IR, 1 ); 45 ADD16(REGISTER,DE); 46 break; 47 case 0x21: /* LD REGISTER,nnnn */ 48 REGISTERL=readbyte(PC++); 49 REGISTERH=readbyte(PC++); 50 break; 51 case 0x22: /* LD (nnnn),REGISTER */ 52 LD16_NNRR(REGISTERL,REGISTERH); 53 break; 54 case 0x23: /* INC REGISTER */ 55 contend_read_no_mreq( IR, 1 ); 56 contend_read_no_mreq( IR, 1 ); 57 REGISTER++; 58 break; 59 case 0x24: /* INC REGISTERH */ 60 INC(REGISTERH); 61 break; 62 case 0x25: /* DEC REGISTERH */ 63 DEC(REGISTERH); 64 break; 65 case 0x26: /* LD REGISTERH,nn */ 66 REGISTERH = readbyte( PC++ ); 67 break; 68 case 0x29: /* ADD REGISTER,REGISTER */ 69 contend_read_no_mreq( IR, 1 ); 70 contend_read_no_mreq( IR, 1 ); 71 contend_read_no_mreq( IR, 1 ); 72 contend_read_no_mreq( IR, 1 ); 73 contend_read_no_mreq( IR, 1 ); 74 contend_read_no_mreq( IR, 1 ); 75 contend_read_no_mreq( IR, 1 ); 76 ADD16(REGISTER,REGISTER); 77 break; 78 case 0x2a: /* LD REGISTER,(nnnn) */ 79 LD16_RRNN(REGISTERL,REGISTERH); 80 break; 81 case 0x2b: /* DEC REGISTER */ 82 contend_read_no_mreq( IR, 1 ); 83 contend_read_no_mreq( IR, 1 ); 84 REGISTER--; 85 break; 86 case 0x2c: /* INC REGISTERL */ 87 INC(REGISTERL); 88 break; 89 case 0x2d: /* DEC REGISTERL */ 90 DEC(REGISTERL); 91 break; 92 case 0x2e: /* LD REGISTERL,nn */ 93 REGISTERL = readbyte( PC++ ); 94 break; 95 case 0x34: /* INC (REGISTER+dd) */ 96 { 97 libspectrum_byte offset, bytetemp; 98 libspectrum_word wordtemp; 99 offset = readbyte( PC ); 100 contend_read_no_mreq( PC, 1 ); contend_read_no_mreq( PC, 1 ); 101 contend_read_no_mreq( PC, 1 ); contend_read_no_mreq( PC, 1 ); 102 contend_read_no_mreq( PC, 1 ); PC++; 103 wordtemp = REGISTER + (libspectrum_signed_byte)offset; 104 bytetemp = readbyte( wordtemp ); 105 contend_read_no_mreq( wordtemp, 1 ); 106 INC(bytetemp); 107 writebyte(wordtemp,bytetemp); 108 } 109 break; 110 case 0x35: /* DEC (REGISTER+dd) */ 111 { 112 libspectrum_byte offset, bytetemp; 113 libspectrum_word wordtemp; 114 offset = readbyte( PC ); 115 contend_read_no_mreq( PC, 1 ); contend_read_no_mreq( PC, 1 ); 116 contend_read_no_mreq( PC, 1 ); contend_read_no_mreq( PC, 1 ); 117 contend_read_no_mreq( PC, 1 ); PC++; 118 wordtemp = REGISTER + (libspectrum_signed_byte)offset; 119 bytetemp = readbyte( wordtemp ); 120 contend_read_no_mreq( wordtemp, 1 ); 121 DEC(bytetemp); 122 writebyte(wordtemp,bytetemp); 123 } 124 break; 125 case 0x36: /* LD (REGISTER+dd),nn */ 126 { 127 libspectrum_byte offset, value; 128 offset = readbyte( PC++ ); 129 value = readbyte( PC ); 130 contend_read_no_mreq( PC, 1 ); contend_read_no_mreq( PC, 1 ); PC++; 131 writebyte( REGISTER + (libspectrum_signed_byte)offset, value ); 132 } 133 break; 134 case 0x39: /* ADD REGISTER,SP */ 135 contend_read_no_mreq( IR, 1 ); 136 contend_read_no_mreq( IR, 1 ); 137 contend_read_no_mreq( IR, 1 ); 138 contend_read_no_mreq( IR, 1 ); 139 contend_read_no_mreq( IR, 1 ); 140 contend_read_no_mreq( IR, 1 ); 141 contend_read_no_mreq( IR, 1 ); 142 ADD16(REGISTER,SP); 143 break; 144 case 0x44: /* LD B,REGISTERH */ 145 B=REGISTERH; 146 break; 147 case 0x45: /* LD B,REGISTERL */ 148 B=REGISTERL; 149 break; 150 case 0x46: /* LD B,(REGISTER+dd) */ 151 { 152 libspectrum_byte offset; 153 offset = readbyte( PC ); 154 contend_read_no_mreq( PC, 1 ); contend_read_no_mreq( PC, 1 ); 155 contend_read_no_mreq( PC, 1 ); contend_read_no_mreq( PC, 1 ); 156 contend_read_no_mreq( PC, 1 ); PC++; 157 B = readbyte( REGISTER + (libspectrum_signed_byte)offset ); 158 } 159 break; 160 case 0x4c: /* LD C,REGISTERH */ 161 C=REGISTERH; 162 break; 163 case 0x4d: /* LD C,REGISTERL */ 164 C=REGISTERL; 165 break; 166 case 0x4e: /* LD C,(REGISTER+dd) */ 167 { 168 libspectrum_byte offset; 169 offset = readbyte( PC ); 170 contend_read_no_mreq( PC, 1 ); contend_read_no_mreq( PC, 1 ); 171 contend_read_no_mreq( PC, 1 ); contend_read_no_mreq( PC, 1 ); 172 contend_read_no_mreq( PC, 1 ); PC++; 173 C = readbyte( REGISTER + (libspectrum_signed_byte)offset ); 174 } 175 break; 176 case 0x54: /* LD D,REGISTERH */ 177 D=REGISTERH; 178 break; 179 case 0x55: /* LD D,REGISTERL */ 180 D=REGISTERL; 181 break; 182 case 0x56: /* LD D,(REGISTER+dd) */ 183 { 184 libspectrum_byte offset; 185 offset = readbyte( PC ); 186 contend_read_no_mreq( PC, 1 ); contend_read_no_mreq( PC, 1 ); 187 contend_read_no_mreq( PC, 1 ); contend_read_no_mreq( PC, 1 ); 188 contend_read_no_mreq( PC, 1 ); PC++; 189 D = readbyte( REGISTER + (libspectrum_signed_byte)offset ); 190 } 191 break; 192 case 0x5c: /* LD E,REGISTERH */ 193 E=REGISTERH; 194 break; 195 case 0x5d: /* LD E,REGISTERL */ 196 E=REGISTERL; 197 break; 198 case 0x5e: /* LD E,(REGISTER+dd) */ 199 { 200 libspectrum_byte offset; 201 offset = readbyte( PC ); 202 contend_read_no_mreq( PC, 1 ); contend_read_no_mreq( PC, 1 ); 203 contend_read_no_mreq( PC, 1 ); contend_read_no_mreq( PC, 1 ); 204 contend_read_no_mreq( PC, 1 ); PC++; 205 E = readbyte( REGISTER + (libspectrum_signed_byte)offset ); 206 } 207 break; 208 case 0x60: /* LD REGISTERH,B */ 209 REGISTERH=B; 210 break; 211 case 0x61: /* LD REGISTERH,C */ 212 REGISTERH=C; 213 break; 214 case 0x62: /* LD REGISTERH,D */ 215 REGISTERH=D; 216 break; 217 case 0x63: /* LD REGISTERH,E */ 218 REGISTERH=E; 219 break; 220 case 0x64: /* LD REGISTERH,REGISTERH */ 221 break; 222 case 0x65: /* LD REGISTERH,REGISTERL */ 223 REGISTERH=REGISTERL; 224 break; 225 case 0x66: /* LD H,(REGISTER+dd) */ 226 { 227 libspectrum_byte offset; 228 offset = readbyte( PC ); 229 contend_read_no_mreq( PC, 1 ); contend_read_no_mreq( PC, 1 ); 230 contend_read_no_mreq( PC, 1 ); contend_read_no_mreq( PC, 1 ); 231 contend_read_no_mreq( PC, 1 ); PC++; 232 H = readbyte( REGISTER + (libspectrum_signed_byte)offset ); 233 } 234 break; 235 case 0x67: /* LD REGISTERH,A */ 236 REGISTERH=A; 237 break; 238 case 0x68: /* LD REGISTERL,B */ 239 REGISTERL=B; 240 break; 241 case 0x69: /* LD REGISTERL,C */ 242 REGISTERL=C; 243 break; 244 case 0x6a: /* LD REGISTERL,D */ 245 REGISTERL=D; 246 break; 247 case 0x6b: /* LD REGISTERL,E */ 248 REGISTERL=E; 249 break; 250 case 0x6c: /* LD REGISTERL,REGISTERH */ 251 REGISTERL=REGISTERH; 252 break; 253 case 0x6d: /* LD REGISTERL,REGISTERL */ 254 break; 255 case 0x6e: /* LD L,(REGISTER+dd) */ 256 { 257 libspectrum_byte offset; 258 offset = readbyte( PC ); 259 contend_read_no_mreq( PC, 1 ); contend_read_no_mreq( PC, 1 ); 260 contend_read_no_mreq( PC, 1 ); contend_read_no_mreq( PC, 1 ); 261 contend_read_no_mreq( PC, 1 ); PC++; 262 L = readbyte( REGISTER + (libspectrum_signed_byte)offset ); 263 } 264 break; 265 case 0x6f: /* LD REGISTERL,A */ 266 REGISTERL=A; 267 break; 268 case 0x70: /* LD (REGISTER+dd),B */ 269 { 270 libspectrum_byte offset; 271 offset = readbyte( PC ); 272 contend_read_no_mreq( PC, 1 ); contend_read_no_mreq( PC, 1 ); 273 contend_read_no_mreq( PC, 1 ); contend_read_no_mreq( PC, 1 ); 274 contend_read_no_mreq( PC, 1 ); PC++; 275 writebyte( REGISTER + (libspectrum_signed_byte)offset, B ); 276 } 277 break; 278 case 0x71: /* LD (REGISTER+dd),C */ 279 { 280 libspectrum_byte offset; 281 offset = readbyte( PC ); 282 contend_read_no_mreq( PC, 1 ); contend_read_no_mreq( PC, 1 ); 283 contend_read_no_mreq( PC, 1 ); contend_read_no_mreq( PC, 1 ); 284 contend_read_no_mreq( PC, 1 ); PC++; 285 writebyte( REGISTER + (libspectrum_signed_byte)offset, C ); 286 } 287 break; 288 case 0x72: /* LD (REGISTER+dd),D */ 289 { 290 libspectrum_byte offset; 291 offset = readbyte( PC ); 292 contend_read_no_mreq( PC, 1 ); contend_read_no_mreq( PC, 1 ); 293 contend_read_no_mreq( PC, 1 ); contend_read_no_mreq( PC, 1 ); 294 contend_read_no_mreq( PC, 1 ); PC++; 295 writebyte( REGISTER + (libspectrum_signed_byte)offset, D ); 296 } 297 break; 298 case 0x73: /* LD (REGISTER+dd),E */ 299 { 300 libspectrum_byte offset; 301 offset = readbyte( PC ); 302 contend_read_no_mreq( PC, 1 ); contend_read_no_mreq( PC, 1 ); 303 contend_read_no_mreq( PC, 1 ); contend_read_no_mreq( PC, 1 ); 304 contend_read_no_mreq( PC, 1 ); PC++; 305 writebyte( REGISTER + (libspectrum_signed_byte)offset, E ); 306 } 307 break; 308 case 0x74: /* LD (REGISTER+dd),H */ 309 { 310 libspectrum_byte offset; 311 offset = readbyte( PC ); 312 contend_read_no_mreq( PC, 1 ); contend_read_no_mreq( PC, 1 ); 313 contend_read_no_mreq( PC, 1 ); contend_read_no_mreq( PC, 1 ); 314 contend_read_no_mreq( PC, 1 ); PC++; 315 writebyte( REGISTER + (libspectrum_signed_byte)offset, H ); 316 } 317 break; 318 case 0x75: /* LD (REGISTER+dd),L */ 319 { 320 libspectrum_byte offset; 321 offset = readbyte( PC ); 322 contend_read_no_mreq( PC, 1 ); contend_read_no_mreq( PC, 1 ); 323 contend_read_no_mreq( PC, 1 ); contend_read_no_mreq( PC, 1 ); 324 contend_read_no_mreq( PC, 1 ); PC++; 325 writebyte( REGISTER + (libspectrum_signed_byte)offset, L ); 326 } 327 break; 328 case 0x77: /* LD (REGISTER+dd),A */ 329 { 330 libspectrum_byte offset; 331 offset = readbyte( PC ); 332 contend_read_no_mreq( PC, 1 ); contend_read_no_mreq( PC, 1 ); 333 contend_read_no_mreq( PC, 1 ); contend_read_no_mreq( PC, 1 ); 334 contend_read_no_mreq( PC, 1 ); PC++; 335 writebyte( REGISTER + (libspectrum_signed_byte)offset, A ); 336 } 337 break; 338 case 0x7c: /* LD A,REGISTERH */ 339 A=REGISTERH; 340 break; 341 case 0x7d: /* LD A,REGISTERL */ 342 A=REGISTERL; 343 break; 344 case 0x7e: /* LD A,(REGISTER+dd) */ 345 { 346 libspectrum_byte offset; 347 offset = readbyte( PC ); 348 contend_read_no_mreq( PC, 1 ); contend_read_no_mreq( PC, 1 ); 349 contend_read_no_mreq( PC, 1 ); contend_read_no_mreq( PC, 1 ); 350 contend_read_no_mreq( PC, 1 ); PC++; 351 A = readbyte( REGISTER + (libspectrum_signed_byte)offset ); 352 } 353 break; 354 case 0x84: /* ADD A,REGISTERH */ 355 ADD(REGISTERH); 356 break; 357 case 0x85: /* ADD A,REGISTERL */ 358 ADD(REGISTERL); 359 break; 360 case 0x86: /* ADD A,(REGISTER+dd) */ 361 { 362 libspectrum_byte offset, bytetemp; 363 offset = readbyte( PC ); 364 contend_read_no_mreq( PC, 1 ); contend_read_no_mreq( PC, 1 ); 365 contend_read_no_mreq( PC, 1 ); contend_read_no_mreq( PC, 1 ); 366 contend_read_no_mreq( PC, 1 ); PC++; 367 bytetemp = readbyte( REGISTER + (libspectrum_signed_byte)offset ); 368 ADD(bytetemp); 369 } 370 break; 371 case 0x8c: /* ADC A,REGISTERH */ 372 ADC(REGISTERH); 373 break; 374 case 0x8d: /* ADC A,REGISTERL */ 375 ADC(REGISTERL); 376 break; 377 case 0x8e: /* ADC A,(REGISTER+dd) */ 378 { 379 libspectrum_byte offset, bytetemp; 380 offset = readbyte( PC ); 381 contend_read_no_mreq( PC, 1 ); contend_read_no_mreq( PC, 1 ); 382 contend_read_no_mreq( PC, 1 ); contend_read_no_mreq( PC, 1 ); 383 contend_read_no_mreq( PC, 1 ); PC++; 384 bytetemp = readbyte( REGISTER + (libspectrum_signed_byte)offset ); 385 ADC(bytetemp); 386 } 387 break; 388 case 0x94: /* SUB A,REGISTERH */ 389 SUB(REGISTERH); 390 break; 391 case 0x95: /* SUB A,REGISTERL */ 392 SUB(REGISTERL); 393 break; 394 case 0x96: /* SUB A,(REGISTER+dd) */ 395 { 396 libspectrum_byte offset, bytetemp; 397 offset = readbyte( PC ); 398 contend_read_no_mreq( PC, 1 ); contend_read_no_mreq( PC, 1 ); 399 contend_read_no_mreq( PC, 1 ); contend_read_no_mreq( PC, 1 ); 400 contend_read_no_mreq( PC, 1 ); PC++; 401 bytetemp = readbyte( REGISTER + (libspectrum_signed_byte)offset ); 402 SUB(bytetemp); 403 } 404 break; 405 case 0x9c: /* SBC A,REGISTERH */ 406 SBC(REGISTERH); 407 break; 408 case 0x9d: /* SBC A,REGISTERL */ 409 SBC(REGISTERL); 410 break; 411 case 0x9e: /* SBC A,(REGISTER+dd) */ 412 { 413 libspectrum_byte offset, bytetemp; 414 offset = readbyte( PC ); 415 contend_read_no_mreq( PC, 1 ); contend_read_no_mreq( PC, 1 ); 416 contend_read_no_mreq( PC, 1 ); contend_read_no_mreq( PC, 1 ); 417 contend_read_no_mreq( PC, 1 ); PC++; 418 bytetemp = readbyte( REGISTER + (libspectrum_signed_byte)offset ); 419 SBC(bytetemp); 420 } 421 break; 422 case 0xa4: /* AND A,REGISTERH */ 423 AND(REGISTERH); 424 break; 425 case 0xa5: /* AND A,REGISTERL */ 426 AND(REGISTERL); 427 break; 428 case 0xa6: /* AND A,(REGISTER+dd) */ 429 { 430 libspectrum_byte offset, bytetemp; 431 offset = readbyte( PC ); 432 contend_read_no_mreq( PC, 1 ); contend_read_no_mreq( PC, 1 ); 433 contend_read_no_mreq( PC, 1 ); contend_read_no_mreq( PC, 1 ); 434 contend_read_no_mreq( PC, 1 ); PC++; 435 bytetemp = readbyte( REGISTER + (libspectrum_signed_byte)offset ); 436 AND(bytetemp); 437 } 438 break; 439 case 0xac: /* XOR A,REGISTERH */ 440 XOR(REGISTERH); 441 break; 442 case 0xad: /* XOR A,REGISTERL */ 443 XOR(REGISTERL); 444 break; 445 case 0xae: /* XOR A,(REGISTER+dd) */ 446 { 447 libspectrum_byte offset, bytetemp; 448 offset = readbyte( PC ); 449 contend_read_no_mreq( PC, 1 ); contend_read_no_mreq( PC, 1 ); 450 contend_read_no_mreq( PC, 1 ); contend_read_no_mreq( PC, 1 ); 451 contend_read_no_mreq( PC, 1 ); PC++; 452 bytetemp = readbyte( REGISTER + (libspectrum_signed_byte)offset ); 453 XOR(bytetemp); 454 } 455 break; 456 case 0xb4: /* OR A,REGISTERH */ 457 OR(REGISTERH); 458 break; 459 case 0xb5: /* OR A,REGISTERL */ 460 OR(REGISTERL); 461 break; 462 case 0xb6: /* OR A,(REGISTER+dd) */ 463 { 464 libspectrum_byte offset, bytetemp; 465 offset = readbyte( PC ); 466 contend_read_no_mreq( PC, 1 ); contend_read_no_mreq( PC, 1 ); 467 contend_read_no_mreq( PC, 1 ); contend_read_no_mreq( PC, 1 ); 468 contend_read_no_mreq( PC, 1 ); PC++; 469 bytetemp = readbyte( REGISTER + (libspectrum_signed_byte)offset ); 470 OR(bytetemp); 471 } 472 break; 473 case 0xbc: /* CP A,REGISTERH */ 474 CP(REGISTERH); 475 break; 476 case 0xbd: /* CP A,REGISTERL */ 477 CP(REGISTERL); 478 break; 479 case 0xbe: /* CP A,(REGISTER+dd) */ 480 { 481 libspectrum_byte offset, bytetemp; 482 offset = readbyte( PC ); 483 contend_read_no_mreq( PC, 1 ); contend_read_no_mreq( PC, 1 ); 484 contend_read_no_mreq( PC, 1 ); contend_read_no_mreq( PC, 1 ); 485 contend_read_no_mreq( PC, 1 ); PC++; 486 bytetemp = readbyte( REGISTER + (libspectrum_signed_byte)offset ); 487 CP(bytetemp); 488 } 489 break; 490 case 0xcb: /* shift DDFDCB */ 491 { 492 libspectrum_word tempaddr; libspectrum_byte opcode3; 493 contend_read( PC, 3 ); 494 tempaddr = 495 REGISTER + (libspectrum_signed_byte)readbyte_internal( PC ); 496 PC++; contend_read( PC, 3 ); 497 opcode3 = readbyte_internal( PC ); 498 contend_read_no_mreq( PC, 1 ); contend_read_no_mreq( PC, 1 ); PC++; 499 #ifdef HAVE_ENOUGH_MEMORY 500 switch(opcode3) { 501 #include "z80_ddfdcb.c" 502 } 503 #else /* #ifdef HAVE_ENOUGH_MEMORY */ 504 z80_ddfdcbxx(opcode3,tempaddr); 505 #endif /* #ifdef HAVE_ENOUGH_MEMORY */ 506 } 507 break; 508 case 0xe1: /* POP REGISTER */ 509 POP16(REGISTERL,REGISTERH); 510 break; 511 case 0xe3: /* EX (SP),REGISTER */ 512 { 513 libspectrum_byte bytetempl, bytetemph; 514 bytetempl = readbyte( SP ); 515 bytetemph = readbyte( SP + 1 ); contend_read_no_mreq( SP + 1, 1 ); 516 writebyte( SP + 1, REGISTERH ); 517 writebyte( SP, REGISTERL ); 518 contend_write_no_mreq( SP, 1 ); contend_write_no_mreq( SP, 1 ); 519 REGISTERL=bytetempl; REGISTERH=bytetemph; 520 } 521 break; 522 case 0xe5: /* PUSH REGISTER */ 523 contend_read_no_mreq( IR, 1 ); 524 PUSH16(REGISTERL,REGISTERH); 525 break; 526 case 0xe9: /* JP REGISTER */ 527 PC=REGISTER; /* NB: NOT INDIRECT! */ 528 break; 529 case 0xf9: /* LD SP,REGISTER */ 530 contend_read_no_mreq( IR, 1 ); 531 contend_read_no_mreq( IR, 1 ); 532 SP = REGISTER; 533 break; 534 default: /* Instruction did not involve H or L, so backtrack 535 one instruction and parse again */ 536 PC--; 537 R--; 538 opcode = opcode2; 539 #ifdef HAVE_ENOUGH_MEMORY 540 goto end_opcode; 541 #else /* #ifdef HAVE_ENOUGH_MEMORY */ 542 return 1; 543 #endif /* #ifdef HAVE_ENOUGH_MEMORY */ 544