changeset 1719:fb5ae8c20b85

Fix cp instruction in new Z80 core and implement its DD/FD prefixes
author Michael Pavone <pavone@retrodev.com>
date Wed, 30 Jan 2019 21:47:35 -0800
parents c7d18b8ec29a
children 1648c685083a
files cpu_dsl.py z80.cpu
diffstat 2 files changed, 56 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/cpu_dsl.py	Wed Jan 30 18:55:58 2019 -0800
+++ b/cpu_dsl.py	Wed Jan 30 21:47:35 2019 -0800
@@ -379,7 +379,8 @@
 		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 @@
 			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):
--- a/z80.cpu	Wed Jan 30 18:55:58 2019 -0800
+++ b/z80.cpu	Wed Jan 30 21:47:35 2019 -0800
@@ -879,18 +879,53 @@
 	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