summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Pavone <pavone@retrodev.com>2019-01-28 21:15:27 -0800
committerMichael Pavone <pavone@retrodev.com>2019-01-28 21:15:27 -0800
commit8e5cb9d205e58ed143f058e0305748f363d440db (patch)
treef99b03b7da3453d36607e6de2e8dfbdf7e470a47
parentbe5da8b8183d25dda735deca880c0bcee028aa52 (diff)
Initial stab at overflow flag implementation in CPU DSL. Probably broken for subtraction
-rwxr-xr-xcpu_dsl.py9
-rw-r--r--ztestrun.c2
2 files changed, 6 insertions, 5 deletions
diff --git a/cpu_dsl.py b/cpu_dsl.py
index 6401827..e836e08 100755
--- a/cpu_dsl.py
+++ b/cpu_dsl.py
@@ -304,7 +304,7 @@ def _updateFlagsCImpl(prog, params, rawParams):
else:
lastDst = prog.resolveParam(prog.lastDst, None, {})
storage = prog.flags.getStorage(flag)
- if calc == 'bit' or calc == 'sign' or calc == 'carry' or calc == 'half':
+ if calc == 'bit' or calc == 'sign' or calc == 'carry' or calc == 'half' or calc == 'overflow':
myRes = lastDst
if calc == 'sign':
resultBit = prog.paramSize(prog.lastDst) - 1
@@ -313,6 +313,9 @@ def _updateFlagsCImpl(prog, params, rawParams):
elif calc == 'half':
resultBit = 4
myRes = '({a} ^ {b} ^ {res})'.format(a = prog.lastA, b = prog.lastB, res = lastDst)
+ elif calc == 'overflow':
+ resultBit = prog.paramSize(prog.lastDst) - 1
+ myRes = '((~({a} ^ {b})) & ({a} ^ {res}))'.format(a = prog.lastA, b = prog.lastB, res = lastDst)
else:
resultBit = int(resultBit)
if type(storage) is tuple:
@@ -347,9 +350,7 @@ def _updateFlagsCImpl(prog, params, rawParams):
reg = prog.resolveParam(storage, None, {})
output.append('\n\t{reg} = {res} == 0;'.format(
reg = reg, res = lastDst
- ))
- elif calc == 'overflow':
- pass
+ ))
elif calc == 'parity':
pass
else:
diff --git a/ztestrun.c b/ztestrun.c
index 4a59534..42c934f 100644
--- a/ztestrun.c
+++ b/ztestrun.c
@@ -116,7 +116,7 @@ int main(int argc, char ** argv)
printf("Flags: SZYHXVNC\n"
" %d%d%d%d%d%d%d%d\n",
context->last_flag_result >> 7, context->zflag != 0, context->last_flag_result >> 5 & 1, context->chflags >> 3 & 1,
- context->last_flag_result >> 3 & 1, context->pvflag != 0, context->nflag, context->chflags >> 7 & 1
+ context->last_flag_result >> 3 & 1, context->pvflag != 0, context->nflag != 0, context->chflags >> 7 & 1
);
puts("--Alternate Regs--");
printf("A: %X\nB: %X\nC: %X\nD: %X\nE: %X\nHL: %X\n",