comparison m68k_core_x86.c @ 1297:71b1a080b30c

Fix SBCD edge cases to pass Flamewing's test ROM. Could use some cleanup to produce better code for the SBCD case, but produces correct results now
author Michael Pavone <pavone@retrodev.com>
date Wed, 22 Mar 2017 22:16:39 -0700
parents 82838d4c84d9
children 208803173ebc
comparison
equal deleted inserted replaced
1296:4e2007c1d8ab 1297:71b1a080b30c
1470 if (inst->op == M68K_ABCD) { 1470 if (inst->op == M68K_ABCD) {
1471 adc_rr(code, other_reg + (AH-RAX), opts->gen.scratch1 + (AH-RAX), SZ_B); 1471 adc_rr(code, other_reg + (AH-RAX), opts->gen.scratch1 + (AH-RAX), SZ_B);
1472 } else { 1472 } else {
1473 sbb_rr(code, other_reg + (AH-RAX), opts->gen.scratch1 + (AH-RAX), SZ_B); 1473 sbb_rr(code, other_reg + (AH-RAX), opts->gen.scratch1 + (AH-RAX), SZ_B);
1474 } 1474 }
1475 cmp_ir(code, 0xA, opts->gen.scratch1 + (AH-RAX), SZ_B); 1475 cmp_ir(code, inst->op == M68K_SBCD ? 0x10 : 0xA, opts->gen.scratch1 + (AH-RAX), SZ_B);
1476 mov_ir(code, 0xA0, other_reg + (AH-RAX), SZ_B); 1476 mov_ir(code, 0xA0, other_reg + (AH-RAX), SZ_B);
1477 code_ptr no_adjust = code->cur+1; 1477 code_ptr no_adjust = code->cur+1;
1478 //add correction factor if necessary 1478 //add correction factor if necessary
1479 jcc(code, CC_B, no_adjust); 1479 jcc(code, CC_B, no_adjust);
1480 mov_ir(code, 6, opts->gen.scratch1 + (AH-RAX), SZ_B); 1480 mov_ir(code, 6, opts->gen.scratch1 + (AH-RAX), SZ_B);
1495 } 1495 }
1496 set_flag(opts, 0, FLAG_C); 1496 set_flag(opts, 0, FLAG_C);
1497 //determine if we need a correction on the upper nibble 1497 //determine if we need a correction on the upper nibble
1498 code_ptr def_adjust = code->cur+1; 1498 code_ptr def_adjust = code->cur+1;
1499 jcc(code, CC_C, def_adjust); 1499 jcc(code, CC_C, def_adjust);
1500 cmp_rr(code, other_reg + (AH-RAX), opts->gen.scratch1, SZ_B); 1500 if (inst->op == M68K_SBCD) {
1501 no_adjust = code->cur+1; 1501 no_adjust = code->cur+1;
1502 jcc(code, CC_B, no_adjust); 1502 jmp(code, no_adjust);
1503 } else {
1504 cmp_rr(code, other_reg + (AH-RAX), opts->gen.scratch1, SZ_B);
1505 no_adjust = code->cur+1;
1506 jcc(code, CC_B, no_adjust);
1507 }
1503 *def_adjust = code->cur - (def_adjust + 1); 1508 *def_adjust = code->cur - (def_adjust + 1);
1504 set_flag(opts, 1, FLAG_C); 1509 set_flag(opts, 1, FLAG_C);
1505 or_ir(code, 0x60, opts->gen.scratch1 + (AH-RAX), SZ_B); 1510 or_ir(code, 0x60, opts->gen.scratch1 + (AH-RAX), SZ_B);
1506 *no_adjust = code->cur - (no_adjust+1); 1511 *no_adjust = code->cur - (no_adjust+1);
1507 if (inst->op == M68K_ABCD) { 1512 if (inst->op == M68K_ABCD) {