comparison z80_to_x86.c @ 821:21a69dfb6ee7

Implement half carry for a couple of the trivial cases
author Michael Pavone <pavone@retrodev.com>
date Sat, 01 Aug 2015 17:05:51 -0700
parents ab017fb09e77
children 22c3c52b9871
comparison
equal deleted inserted replaced
820:cf6149b7c6e5 821:21a69dfb6ee7
404 mov_rdispr(code, src_op.base, src_op.disp, dst_op.base, size); 404 mov_rdispr(code, src_op.base, src_op.disp, dst_op.base, size);
405 } 405 }
406 } 406 }
407 if (inst->ea_reg == Z80_I && inst->addr_mode == Z80_REG) { 407 if (inst->ea_reg == Z80_I && inst->addr_mode == Z80_REG) {
408 //ld a, i sets some flags 408 //ld a, i sets some flags
409 //TODO: Implement half-carry flag
410 cmp_ir(code, 0, dst_op.base, SZ_B); 409 cmp_ir(code, 0, dst_op.base, SZ_B);
411 setcc_rdisp(code, CC_Z, opts->gen.context_reg, zf_off(ZF_Z)); 410 setcc_rdisp(code, CC_Z, opts->gen.context_reg, zf_off(ZF_Z));
412 setcc_rdisp(code, CC_S, opts->gen.context_reg, zf_off(ZF_S)); 411 setcc_rdisp(code, CC_S, opts->gen.context_reg, zf_off(ZF_S));
412 mov_irdisp(code, 0, opts->gen.context_reg, zf_off(ZF_H), SZ_B);;
413 mov_irdisp(code, 0, opts->gen.context_reg, zf_off(ZF_N), SZ_B);; 413 mov_irdisp(code, 0, opts->gen.context_reg, zf_off(ZF_N), SZ_B);;
414 mov_rdispr(code, opts->gen.context_reg, offsetof(z80_context, iff2), opts->gen.scratch1, SZ_B); 414 mov_rdispr(code, opts->gen.context_reg, offsetof(z80_context, iff2), opts->gen.scratch1, SZ_B);
415 mov_rrdisp(code, opts->gen.scratch1, opts->gen.context_reg, zf_off(ZF_PV), SZ_B); 415 mov_rrdisp(code, opts->gen.scratch1, opts->gen.context_reg, zf_off(ZF_PV), SZ_B);
416 } 416 }
417 z80_save_reg(inst, opts); 417 z80_save_reg(inst, opts);
578 if (opts->regs[Z80_BC] >= 0) { 578 if (opts->regs[Z80_BC] >= 0) {
579 sub_ir(code, 1, opts->regs[Z80_BC], SZ_W); 579 sub_ir(code, 1, opts->regs[Z80_BC], SZ_W);
580 } else { 580 } else {
581 sub_irdisp(code, 1, opts->gen.context_reg, zr_off(Z80_BC), SZ_W); 581 sub_irdisp(code, 1, opts->gen.context_reg, zr_off(Z80_BC), SZ_W);
582 } 582 }
583 //TODO: Implement half-carry 583 mov_irdisp(code, 0, opts->gen.context_reg, zf_off(ZF_H), SZ_B);
584 mov_irdisp(code, 0, opts->gen.context_reg, zf_off(ZF_N), SZ_B); 584 mov_irdisp(code, 0, opts->gen.context_reg, zf_off(ZF_N), SZ_B);
585 setcc_rdisp(code, CC_NZ, opts->gen.context_reg, zf_off(ZF_PV)); 585 setcc_rdisp(code, CC_NZ, opts->gen.context_reg, zf_off(ZF_PV));
586 break; 586 break;
587 } 587 }
588 case Z80_LDIR: { 588 case Z80_LDIR: {
612 //TODO: Figure out what the flag state should be here 612 //TODO: Figure out what the flag state should be here
613 //TODO: Figure out whether an interrupt can interrupt this 613 //TODO: Figure out whether an interrupt can interrupt this
614 jmp(code, start); 614 jmp(code, start);
615 *cont = code->cur - (cont + 1); 615 *cont = code->cur - (cont + 1);
616 cycles(&opts->gen, 2); 616 cycles(&opts->gen, 2);
617 //TODO: Implement half-carry 617 mov_irdisp(code, 0, opts->gen.context_reg, zf_off(ZF_H), SZ_B);
618 mov_irdisp(code, 0, opts->gen.context_reg, zf_off(ZF_N), SZ_B); 618 mov_irdisp(code, 0, opts->gen.context_reg, zf_off(ZF_N), SZ_B);
619 mov_irdisp(code, 0, opts->gen.context_reg, zf_off(ZF_PV), SZ_B); 619 mov_irdisp(code, 0, opts->gen.context_reg, zf_off(ZF_PV), SZ_B);
620 break; 620 break;
621 } 621 }
622 case Z80_LDD: { 622 case Z80_LDD: {
639 if (opts->regs[Z80_BC] >= 0) { 639 if (opts->regs[Z80_BC] >= 0) {
640 sub_ir(code, 1, opts->regs[Z80_BC], SZ_W); 640 sub_ir(code, 1, opts->regs[Z80_BC], SZ_W);
641 } else { 641 } else {
642 sub_irdisp(code, 1, opts->gen.context_reg, zr_off(Z80_BC), SZ_W); 642 sub_irdisp(code, 1, opts->gen.context_reg, zr_off(Z80_BC), SZ_W);
643 } 643 }
644 //TODO: Implement half-carry 644 mov_irdisp(code, 0, opts->gen.context_reg, zf_off(ZF_H), SZ_B);
645 mov_irdisp(code, 0, opts->gen.context_reg, zf_off(ZF_N), SZ_B); 645 mov_irdisp(code, 0, opts->gen.context_reg, zf_off(ZF_N), SZ_B);
646 setcc_rdisp(code, CC_NZ, opts->gen.context_reg, zf_off(ZF_PV)); 646 setcc_rdisp(code, CC_NZ, opts->gen.context_reg, zf_off(ZF_PV));
647 break; 647 break;
648 } 648 }
649 case Z80_LDDR: { 649 case Z80_LDDR: {
669 } 669 }
670 uint8_t * cont = code->cur+1; 670 uint8_t * cont = code->cur+1;
671 jcc(code, CC_Z, code->cur+2); 671 jcc(code, CC_Z, code->cur+2);
672 cycles(&opts->gen, 7); 672 cycles(&opts->gen, 7);
673 //TODO: Figure out what the flag state should be here 673 //TODO: Figure out what the flag state should be here
674 //TODO: Figure out whether an interrupt can interrupt this
675 jmp(code, start); 674 jmp(code, start);
676 *cont = code->cur - (cont + 1); 675 *cont = code->cur - (cont + 1);
677 cycles(&opts->gen, 2); 676 cycles(&opts->gen, 2);
678 //TODO: Implement half-carry 677 mov_irdisp(code, 0, opts->gen.context_reg, zf_off(ZF_H), SZ_B);
679 mov_irdisp(code, 0, opts->gen.context_reg, zf_off(ZF_N), SZ_B); 678 mov_irdisp(code, 0, opts->gen.context_reg, zf_off(ZF_N), SZ_B);
680 mov_irdisp(code, 0, opts->gen.context_reg, zf_off(ZF_PV), SZ_B); 679 mov_irdisp(code, 0, opts->gen.context_reg, zf_off(ZF_PV), SZ_B);
681 break; 680 break;
682 } 681 }
683 /*case Z80_CPI: 682 /*case Z80_CPI: