Mercurial > repos > blastem
changeset 2594:1c493b8c513b
Fix some rotate instruction issues in new 68K core
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Sun, 09 Feb 2025 18:07:40 -0800 |
parents | b0a7b1f708cc |
children | eb4b37c14c93 |
files | cpu_dsl.py m68k_util.c |
diffstat | 2 files changed, 29 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- a/cpu_dsl.py Sun Feb 09 16:55:00 2025 -0800 +++ b/cpu_dsl.py Sun Feb 09 18:07:40 2025 -0800 @@ -1026,6 +1026,11 @@ mdecl,b = prog.getTemp(prog.paramSize(rawParams[1])) ret = f'\n\t{b} = {params[1]} & {rotMask};' prog.lastB = b + if prog.paramSize(rawParams[0]) > size: + mask = (1 << size) - 1 + a = f'({params[0]} & {mask})' + else: + a = params[0] prog.lastBUnmasked = params[1] if needsSizeAdjust: decl,name = prog.getTemp(size) @@ -1034,7 +1039,7 @@ else: dst = params[2] ret += '\n\t{dst} = {a} << {b} | {a} >> ({size} - {b});'.format(dst = dst, - a = params[0], b = b, size=size + a = a, b = b, size=size ) if needsSizeAdjust and not needsCarry: mask = (1 << size) - 1 @@ -1067,19 +1072,21 @@ else: size = destSize carryCheck = _getCarryCheck(prog) - size = prog.paramSize(rawParams[2]) + if prog.paramSize(rawParams[0]) > size: + mask = (1 << size) - 1 + a = f'({params[0]} & {mask})' + else: + a = params[0] if needsCarry or needsSizeAdjust: decl,name = prog.getTemp(size) dst = prog.carryFlowDst = name - prog.lastA = params[0] + prog.lastA = a prog.lastB = params[1] else: dst = params[2] - if size == 32 and (not type(params[1]) is int) or params[1] <= 1: + if size == 32 and ((not type(params[1]) is int) or params[1] <= 1): # we may need to shift by 32-bits which is too much for a normal int - a = f'((uint64_t){params[0]})' - else: - a = params[0] + a = f'((uint64_t){a})' ret = decl + '\n\t{dst} = {a} << {b} | {a} >> ({size} + 1 - {b}) | ({check} ? 1 : 0) << ({b} - 1);'.format(dst = dst, a = a, b = params[1], size=size, check=carryCheck ) @@ -1122,6 +1129,11 @@ ret = f'\n\t{b} = {params[1]} & {rotMask};' prog.lastB = b prog.lastBUnmasked = params[1] + if prog.paramSize(rawParams[0]) > size: + mask = (1 << size) - 1 + a = f'({params[0]} & {mask})' + else: + a = params[0] if needsSizeAdjust: decl,name = prog.getTemp(size) dst = prog.carryFlowDst = name @@ -1129,7 +1141,7 @@ else: dst = params[2] ret += '\n\t{dst} = {a} >> {b} | {a} << ({size} - {b});'.format(dst = dst, - a = params[0], b = b, size=size + a = a, b = b, size=size ) if needsSizeAdjust and not needsCarry: mask = (1 << size) - 1 @@ -1162,19 +1174,21 @@ else: size = destSize carryCheck = _getCarryCheck(prog) - size = prog.paramSize(rawParams[2]) + if prog.paramSize(rawParams[0]) > size: + mask = (1 << size) - 1 + a = f'({params[0]} & {mask})' + else: + a = params[0] if needsCarry or needsSizeAdjust: decl,name = prog.getTemp(size) dst = prog.carryFlowDst = name - prog.lastA = params[0] + prog.lastA = a prog.lastB = params[1] else: dst = params[2] - if size == 32 and (not type(params[1]) is int) or params[1] <= 1: + if size == 32 and ((not type(params[1]) is int) or params[1] <= 1): # we may need to shift by 32-bits which is too much for a normal int - a = f'((uint64_t){params[0]})' - else: - a = params[0] + a = f'((uint64_t){a})' ret = decl + '\n\t{dst} = {a} >> {b} | {a} << ({size} + 1 - {b}) | ({check} ? 1 : 0) << ({size}-{b});'.format(dst = dst, a = a, b = params[1], size=size, check=carryCheck )
--- a/m68k_util.c Sun Feb 09 16:55:00 2025 -0800 +++ b/m68k_util.c Sun Feb 09 18:07:40 2025 -0800 @@ -27,7 +27,7 @@ m68k_decode(debug_disasm_fetch, context, &inst, tmp); static char disasm_buf[256]; m68k_disasm(&inst, disasm_buf); - printf("Fetch %05X: %04X - %s, d2 = %X, d3 = %X, d4 = %X, d6 = %X, xflag = %d\n", tmp, context->scratch1, disasm_buf, context->dregs[2], context->dregs[3], context->dregs[4], context->dregs[6], context->xflag); + printf("Fetch %05X: %04X - %s, d0=%X, d2=%X, d3=%X, d4=%X, d6=%X, xflag=%d\n", tmp, context->scratch1, disasm_buf, context->dregs[0], context->dregs[2], context->dregs[3], context->dregs[4], context->dregs[6], context->xflag); } #endif }