summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Pavone <pavone@retrodev.com>2019-01-28 22:56:43 -0800
committerMichael Pavone <pavone@retrodev.com>2019-01-28 22:56:43 -0800
commit14779958be0da1d37bd242f2be43f207fa5e5369 (patch)
tree8b7c7bd22d950c02d92fc8e270d0a7fa1cd7b19e
parent90e1a8d54d506bc932b43c721016b1f20fc8a0b6 (diff)
Fix sbc and implement carry/overflow flags for it in CPU DSL
-rwxr-xr-xcpu_dsl.py27
1 files changed, 25 insertions, 2 deletions
diff --git a/cpu_dsl.py b/cpu_dsl.py
index 34da6d0..76889b4 100755
--- a/cpu_dsl.py
+++ b/cpu_dsl.py
@@ -448,8 +448,31 @@ def _adcCImpl(prog, params, rawParams, flagUpdates):
a = params[0], b = params[1], check = carryCheck
)
-def _sbcCImpl(prog, params, rawParams):
- return '\n\t{dst} = {a} - {b} - ({check} ? 1 : 0);'.format(dst = params[2],
+def _sbcCImpl(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[1]
+ prog.lastB = '({b} ^ ({check} ? 1 : 0))'.format(b = params[0], check = carryCheck)
+ prog.lastBFlow = '((-{b}) ^ ({check} ? -1 : 0))'.format(b = params[0], check = carryCheck)
+ else:
+ dst = params[2]
+ return decl + '\n\t{dst} = {b} - {a} - ({check} ? 1 : 0);'.format(dst = dst,
a = params[0], b = params[1], check=_getCarryCheck(prog)
)