diff options
author | Michael Pavone <pavone@retrodev.com> | 2019-01-28 22:49:02 -0800 |
---|---|---|
committer | Michael Pavone <pavone@retrodev.com> | 2019-01-28 22:49:02 -0800 |
commit | 90e1a8d54d506bc932b43c721016b1f20fc8a0b6 (patch) | |
tree | d509b2954eb8fd0af788b7b4af7ce1feba79a1d5 /cpu_dsl.py | |
parent | 4c0f1c402fee72a4b57cfb0dde9870265eab622a (diff) |
Implementation of carry/overflow flags for adc instructions in CPU DSL
Diffstat (limited to 'cpu_dsl.py')
-rwxr-xr-x | cpu_dsl.py | 30 |
1 files changed, 26 insertions, 4 deletions
@@ -420,10 +420,32 @@ def _getCarryCheck(prog): else: return prog.resolveReg(carryStorage, None, (), False) -def _adcCImpl(prog, params, rawParams): - - return '\n\t{dst} = {a} + {b} + ({check} ? 1 : 0);'.format(dst = params[2], - a = params[0], b = params[1], check=_getCarryCheck(prog) +def _adcCImpl(prog, params, rawParams, flagUpdates): + needsCarry = needsOflow = needsHalf = False + if flagUpdates: + for flag in flagUpdates: + calc = prog.flags.flagCalc[flag] + if calc == 'carry': + needsCarry = True + elif calc == 'half-carry': + needsHalf = True + elif calc == 'overflow': + needsOflow = True + decl = '' + carryCheck = _getCarryCheck(prog) + if needsCarry or needsOflow or needsHalf: + size = prog.paramSize(rawParams[2]) + if needsCarry: + size *= 2 + decl,name = prog.getTemp(size) + dst = prog.carryFlowDst = name + prog.lastA = params[0] + prog.lastB = '({b} ^ ({check} ? 1 : 0))'.format(b = params[1], check = carryCheck) + prog.lastBFlow = prog.lastB + else: + dst = params[2] + return decl + '\n\t{dst} = {a} + {b} + ({check} ? 1 : 0);'.format(dst = dst, + a = params[0], b = params[1], check = carryCheck ) def _sbcCImpl(prog, params, rawParams): |