Mercurial > repos > blastem
comparison z80inst.c @ 201:2d2fa345e1fc
Add support for bit instructions to decoder
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Mon, 21 Jan 2013 21:17:52 -0800 |
parents | d3066ceb29d1 |
children | 693ad04b965e |
comparison
equal
deleted
inserted
replaced
200:d3066ceb29d1 | 201:2d2fa345e1fc |
---|---|
416 NOP, | 416 NOP, |
417 NOP, | 417 NOP, |
418 NOP | 418 NOP |
419 }; | 419 }; |
420 | 420 |
421 #define SHIFT_BLOCK(op) \ | |
422 {op, Z80_B, Z80_UNUSED, Z80_UNUSED, 0},\ | |
423 {op, Z80_C, Z80_UNUSED, Z80_UNUSED, 0},\ | |
424 {op, Z80_D, Z80_UNUSED, Z80_UNUSED, 0},\ | |
425 {op, Z80_E, Z80_UNUSED, Z80_UNUSED, 0},\ | |
426 {op, Z80_H, Z80_UNUSED, Z80_UNUSED, 0},\ | |
427 {op, Z80_L, Z80_UNUSED, Z80_UNUSED, 0},\ | |
428 {op, Z80_UNUSED, Z80_REG_INDIRECT, Z80_HL, 0},\ | |
429 {op, Z80_A, Z80_UNUSED, Z80_UNUSED, 0} | |
430 | |
431 #define BIT_BLOCK(op, bit) \ | |
432 {op, Z80_USE_IMMED, Z80_REG, Z80_B, bit},\ | |
433 {op, Z80_USE_IMMED, Z80_REG, Z80_C, bit},\ | |
434 {op, Z80_USE_IMMED, Z80_REG, Z80_D, bit},\ | |
435 {op, Z80_USE_IMMED, Z80_REG, Z80_E, bit},\ | |
436 {op, Z80_USE_IMMED, Z80_REG, Z80_H, bit},\ | |
437 {op, Z80_USE_IMMED, Z80_REG, Z80_L, bit},\ | |
438 {op, Z80_USE_IMMED, Z80_REG_INDIRECT, Z80_HL, bit},\ | |
439 {op, Z80_USE_IMMED, Z80_REG, Z80_A, bit} | |
440 | |
441 z80inst z80_tbl_bit[256] = { | |
442 //0 | |
443 SHIFT_BLOCK(Z80_RLC), | |
444 SHIFT_BLOCK(Z80_RRC), | |
445 //1 | |
446 SHIFT_BLOCK(Z80_RL), | |
447 SHIFT_BLOCK(Z80_RR), | |
448 //2 | |
449 SHIFT_BLOCK(Z80_SLA), | |
450 SHIFT_BLOCK(Z80_SRA), | |
451 //3 | |
452 SHIFT_BLOCK(Z80_SLL), | |
453 SHIFT_BLOCK(Z80_SRL), | |
454 //4 | |
455 BIT_BLOCK(Z80_BIT, 0), | |
456 BIT_BLOCK(Z80_BIT, 1), | |
457 //5 | |
458 BIT_BLOCK(Z80_BIT, 2), | |
459 BIT_BLOCK(Z80_BIT, 3), | |
460 //6 | |
461 BIT_BLOCK(Z80_BIT, 4), | |
462 BIT_BLOCK(Z80_BIT, 5), | |
463 //7 | |
464 BIT_BLOCK(Z80_BIT, 6), | |
465 BIT_BLOCK(Z80_BIT, 7), | |
466 //8 | |
467 BIT_BLOCK(Z80_RES, 0), | |
468 BIT_BLOCK(Z80_RES, 1), | |
469 //9 | |
470 BIT_BLOCK(Z80_RES, 2), | |
471 BIT_BLOCK(Z80_RES, 3), | |
472 //A | |
473 BIT_BLOCK(Z80_RES, 4), | |
474 BIT_BLOCK(Z80_RES, 5), | |
475 //B | |
476 BIT_BLOCK(Z80_RES, 6), | |
477 BIT_BLOCK(Z80_RES, 7), | |
478 //C | |
479 BIT_BLOCK(Z80_SET, 0), | |
480 BIT_BLOCK(Z80_SET, 1), | |
481 //D | |
482 BIT_BLOCK(Z80_SET, 2), | |
483 BIT_BLOCK(Z80_SET, 3), | |
484 //E | |
485 BIT_BLOCK(Z80_SET, 4), | |
486 BIT_BLOCK(Z80_SET, 5), | |
487 //F | |
488 BIT_BLOCK(Z80_SET, 6), | |
489 BIT_BLOCK(Z80_SET, 7) | |
490 }; | |
491 | |
421 uint8_t * z80_decode(uint8_t * istream, z80inst * decoded) | 492 uint8_t * z80_decode(uint8_t * istream, z80inst * decoded) |
422 { | 493 { |
423 if (*istream == 0xCB) { | 494 if (*istream == 0xCB) { |
495 istream++; | |
496 memcpy(decoded, z80_tbl_bit + *istream, sizeof(z80inst)); | |
424 } else if (*istream == 0xDD) { | 497 } else if (*istream == 0xDD) { |
425 } else if (*istream == 0xED) { | 498 } else if (*istream == 0xED) { |
426 istream++; | 499 istream++; |
427 if (*istream < 0x40 || *istream >= 0xC0) { | 500 if (*istream < 0x40 || *istream >= 0xC0) { |
428 memcpy(decoded, z80_tbl_extd + 0xBF, sizeof(z80inst)); | 501 memcpy(decoded, z80_tbl_extd + 0xBF, sizeof(z80inst)); |
444 } else if ((decoded->addr_mode & 0xF) == Z80_IMMED_INDIRECT) { | 517 } else if ((decoded->addr_mode & 0xF) == Z80_IMMED_INDIRECT) { |
445 decoded->immed = *(++istream); | 518 decoded->immed = *(++istream); |
446 if (decoded->op != Z80_OUT && decoded->op != Z80_IN) { | 519 if (decoded->op != Z80_OUT && decoded->op != Z80_IN) { |
447 decoded->immed |= *(++istream) << 8; | 520 decoded->immed |= *(++istream) << 8; |
448 } | 521 } |
449 } else if (decoded->reg == Z80_USE_IMMED) { | 522 } else if (decoded->reg == Z80_USE_IMMED && decoded->op != Z80_BIT && decoded->op != Z80_RES && decoded->op != Z80_SET) { |
450 decoded->immed = *(++istream); | 523 decoded->immed = *(++istream); |
451 } | 524 } |
452 return istream+1; | 525 return istream+1; |
453 } | 526 } |
454 | 527 |
488 "im", | 561 "im", |
489 "rlc", | 562 "rlc", |
490 "rl", | 563 "rl", |
491 "rrc", | 564 "rrc", |
492 "rr", | 565 "rr", |
493 "sl", | 566 "sla", |
567 "sra", | |
568 "sll", | |
569 "srl", | |
494 "rld", | 570 "rld", |
495 "rrd", | 571 "rrd", |
496 "bit", | 572 "bit", |
497 "set", | 573 "set", |
498 "res", | 574 "res", |
566 break; | 642 break; |
567 case Z80_IMMED_INDIRECT: | 643 case Z80_IMMED_INDIRECT: |
568 len += sprintf(dst+len, " (%d)", decoded->immed); | 644 len += sprintf(dst+len, " (%d)", decoded->immed); |
569 break; | 645 break; |
570 } | 646 } |
571 if (decoded->reg != Z80_UNUSED) { | 647 if (decoded->reg == Z80_USE_IMMED) { |
648 len += sprintf(dst+len, " %d", decoded->immed); | |
649 } else if (decoded->reg != Z80_UNUSED) { | |
572 if (decoded->op == Z80_JRCC || decoded->op == Z80_JPCC || decoded->op == Z80_CALLCC || decoded->op == Z80_RETCC) { | 650 if (decoded->op == Z80_JRCC || decoded->op == Z80_JPCC || decoded->op == Z80_CALLCC || decoded->op == Z80_RETCC) { |
573 len += sprintf(dst+len, "%s %s", decoded->reg == Z80_UNUSED ? "" : "," , z80_conditions[decoded->reg]); | 651 len += sprintf(dst+len, "%s %s", decoded->reg == Z80_UNUSED ? "" : "," , z80_conditions[decoded->reg]); |
574 } else { | 652 } else { |
575 len += sprintf(dst+len, "%s %s", decoded->reg == Z80_UNUSED ? "" : "," , z80_regs[decoded->reg]); | 653 len += sprintf(dst+len, "%s %s", decoded->reg == Z80_UNUSED ? "" : "," , z80_regs[decoded->reg]); |
576 } | 654 } |
577 } | 655 } |
578 } else { | 656 } else { |
579 if (decoded->reg != Z80_UNUSED) { | 657 if (decoded->reg == Z80_USE_IMMED) { |
658 len += sprintf(dst+len, " %d", decoded->immed); | |
659 } else if (decoded->reg != Z80_UNUSED) { | |
580 if (decoded->op == Z80_JRCC || decoded->op == Z80_JPCC || decoded->op == Z80_CALLCC || decoded->op == Z80_RETCC) { | 660 if (decoded->op == Z80_JRCC || decoded->op == Z80_JPCC || decoded->op == Z80_CALLCC || decoded->op == Z80_RETCC) { |
581 len += sprintf(dst+len, " %s", z80_conditions[decoded->reg]); | 661 len += sprintf(dst+len, " %s", z80_conditions[decoded->reg]); |
582 } else { | 662 } else { |
583 len += sprintf(dst+len, " %s", z80_regs[decoded->reg]); | 663 len += sprintf(dst+len, " %s", z80_regs[decoded->reg]); |
584 } | 664 } |