summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xcpu_dsl.py23
-rw-r--r--z80.cpu41
2 files changed, 56 insertions, 8 deletions
diff --git a/cpu_dsl.py b/cpu_dsl.py
index 9254af5..f277962 100755
--- a/cpu_dsl.py
+++ b/cpu_dsl.py
@@ -379,7 +379,8 @@ def _updateFlagsCImpl(prog, params, rawParams):
else:
raise Exception('Unknown flag calc type: ' + calc)
if prog.carryFlowDst:
- output.append('\n\t{dst} = {tmpdst};'.format(dst = prog.resolveParam(prog.lastDst, None, {}), tmpdst = prog.carryFlowDst))
+ if prog.lastOp.op != 'cmp':
+ output.append('\n\t{dst} = {tmpdst};'.format(dst = prog.resolveParam(prog.lastDst, None, {}), tmpdst = prog.carryFlowDst))
prog.carryFlowDst = None
if parity:
if paritySize > 8:
@@ -417,14 +418,26 @@ def _updateFlagsCImpl(prog, params, rawParams):
output.append('\n\t{reg} = {val};'.format(reg=reg, val=explicit[flag]))
return ''.join(output)
-def _cmpCImpl(prog, params):
- size = prog.paramSize(params[1])
+def _cmpCImpl(prog, params, rawParams, flagUpdates):
+ size = prog.paramSize(rawParams[1])
+ needsCarry = False
+ if flagUpdates:
+ for flag in flagUpdates:
+ calc = prog.flags.flagCalc[flag]
+ if calc == 'carry':
+ needsCarry = True
+ break
+ if needsCarry:
+ size *= 2
tmpvar = 'cmp_tmp{sz}__'.format(sz=size)
- typename = ''
+ 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)
- prog.lastDst = tmpvar
+ prog.lastDst = rawParams[1]
return '\n\t{var} = {b} - {a};'.format(var = tmpvar, a = params[0], b = params[1])
def _asrCImpl(prog, params, rawParams):
diff --git a/z80.cpu b/z80.cpu
index 0969456..1c7945c 100644
--- a/z80.cpu
+++ b/z80.cpu
@@ -879,18 +879,53 @@ ed 01110010 sbc_hl_sp
update_flags SZYH0PXN0C0
10111RRR cp_reg
+ mov main.R last_flag_result
cmp main.R a
- update_flags SZYHVXN1C
+ update_flags SZHVN1C
+
+dd 10111100 cp_ixh
+ lsr ix 8 last_flag_result
+ cmp last_flag_result a
+ update_flags SZHVN1C
+
+dd 10111101 cp_ixl
+ mov ix last_flag_result
+ cmp last_flag_result a
+ update_flags SZHVN1C
+
+fd 10111100 cp_iyh
+ lsr iy 8 last_flag_result
+ cmp last_flag_result a
+ update_flags SZHVN1C
+
+fd 10111101 cp_iyl
+ mov iy last_flag_result
+ cmp last_flag_result a
+ update_flags SZHVN1C
10111110 cp_hl
z80_fetch_hl
+ mov scratch1 last_flag_result
cmp scratch1 a
- update_flags SZYHVXN1C
+ update_flags SZHVN1C
+
+dd 10111110 cp_ixd
+ z80_fetch_index ix
+ mov scratch1 last_flag_result
+ cmp scratch1 a
+ update_flags SZHVN1C
+
+fd 10111110 cp_iyd
+ z80_fetch_index iy
+ mov scratch1 last_flag_result
+ cmp scratch1 a
+ update_flags SZHVN1C
11111110 cp_immed
z80_fetch_immed
+ mov scratch1 last_flag_result
cmp scratch1 a
- update_flags SZYHVXN1C
+ update_flags SZHVN1C
00RRR100 inc_reg
add 1 main.R main.R