Mercurial > repos > blastem
comparison cpu_dsl.py @ 1710:2344b3650b38
Fix sbc and implement carry/overflow flags for it in CPU DSL
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Mon, 28 Jan 2019 22:56:43 -0800 |
parents | 9c058ea77b7a |
children | 87d4f0b4bf1d |
comparison
equal
deleted
inserted
replaced
1709:9c058ea77b7a | 1710:2344b3650b38 |
---|---|
446 dst = params[2] | 446 dst = params[2] |
447 return decl + '\n\t{dst} = {a} + {b} + ({check} ? 1 : 0);'.format(dst = dst, | 447 return decl + '\n\t{dst} = {a} + {b} + ({check} ? 1 : 0);'.format(dst = dst, |
448 a = params[0], b = params[1], check = carryCheck | 448 a = params[0], b = params[1], check = carryCheck |
449 ) | 449 ) |
450 | 450 |
451 def _sbcCImpl(prog, params, rawParams): | 451 def _sbcCImpl(prog, params, rawParams, flagUpdates): |
452 return '\n\t{dst} = {a} - {b} - ({check} ? 1 : 0);'.format(dst = params[2], | 452 needsCarry = needsOflow = needsHalf = False |
453 if flagUpdates: | |
454 for flag in flagUpdates: | |
455 calc = prog.flags.flagCalc[flag] | |
456 if calc == 'carry': | |
457 needsCarry = True | |
458 elif calc == 'half-carry': | |
459 needsHalf = True | |
460 elif calc == 'overflow': | |
461 needsOflow = True | |
462 decl = '' | |
463 carryCheck = _getCarryCheck(prog) | |
464 if needsCarry or needsOflow or needsHalf: | |
465 size = prog.paramSize(rawParams[2]) | |
466 if needsCarry: | |
467 size *= 2 | |
468 decl,name = prog.getTemp(size) | |
469 dst = prog.carryFlowDst = name | |
470 prog.lastA = params[1] | |
471 prog.lastB = '({b} ^ ({check} ? 1 : 0))'.format(b = params[0], check = carryCheck) | |
472 prog.lastBFlow = '((-{b}) ^ ({check} ? -1 : 0))'.format(b = params[0], check = carryCheck) | |
473 else: | |
474 dst = params[2] | |
475 return decl + '\n\t{dst} = {b} - {a} - ({check} ? 1 : 0);'.format(dst = dst, | |
453 a = params[0], b = params[1], check=_getCarryCheck(prog) | 476 a = params[0], b = params[1], check=_getCarryCheck(prog) |
454 ) | 477 ) |
455 | 478 |
456 _opMap = { | 479 _opMap = { |
457 'mov': Op(lambda val: val).cUnaryOperator(''), | 480 'mov': Op(lambda val: val).cUnaryOperator(''), |