summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Pavone <pavone@retrodev.com>2019-02-06 08:54:09 -0800
committerMichael Pavone <pavone@retrodev.com>2019-02-06 08:54:09 -0800
commitdfec2468ff106556e035c8e702edf5a7d0e50e68 (patch)
tree7a1d0f1d7c7d5f8c010bbd5ff5ceb52ba462fb7e
parent961bdbea9dbbabff23624ef18280218eae452a3a (diff)
Fixes to DAA, SCF and CCF to pass ZEXALL in new Z80 core
-rwxr-xr-xcpu_dsl.py9
-rw-r--r--z80.cpu17
2 files changed, 19 insertions, 7 deletions
diff --git a/cpu_dsl.py b/cpu_dsl.py
index 928681b..070efbe 100755
--- a/cpu_dsl.py
+++ b/cpu_dsl.py
@@ -468,10 +468,11 @@ def _cmpCImpl(prog, params, rawParams, flagUpdates):
if needsCarry:
size *= 2
tmpvar = 'cmp_tmp{sz}__'.format(sz=size)
- prog.carryFlowDst = tmpvar
- prog.lastA = params[1]
- prog.lastB = params[0]
- prog.lastBFlow = params[0]
+ if flagUpdates:
+ prog.carryFlowDst = tmpvar
+ prog.lastA = params[1]
+ prog.lastB = params[0]
+ prog.lastBFlow = params[0]
scope = prog.getRootScope()
if not scope.resolveLocal(tmpvar):
scope.addLocal(tmpvar, size)
diff --git a/z80.cpu b/z80.cpu
index e31be38..db19837 100644
--- a/z80.cpu
+++ b/z80.cpu
@@ -1439,6 +1439,9 @@ ed 01DDD100 neg
00111111 ccf
local tmp 8
+ and 0x80 last_flag_result last_flag_result
+ and 0x7F a tmp
+ or tmp last_flag_result last_flag_result
and 0x80 chflags chflags
lsr chflags 4 tmp
or tmp chflags chflags
@@ -1446,6 +1449,10 @@ ed 01DDD100 neg
update_flags N0
00110111 scf
+ local tmp 8
+ and 0x80 last_flag_result last_flag_result
+ and 0x7F a tmp
+ or tmp last_flag_result last_flag_result
update_flags H0N0C1
00000000 nop
@@ -2217,24 +2224,28 @@ ed 10111001 cpdr
if tmp
or 0x60 diff diff
+ update_flags C1
else
- cmp 0xA0 a
+ cmp 0x9A a
if >=U
or 0x60 diff diff
+ update_flags C1
+ else
+ update_flags C0
end
end
if nflag
sub diff a a
- update_flags SZYHPXC
+ update_flags SZYHPX
else
add diff a a
- update_flags SZYHPXC
+ update_flags SZYHPX
end