From 1f719b8879580586970338e7c96d65910dca02e8 Mon Sep 17 00:00:00 2001 From: Michael Pavone Date: Mon, 4 Feb 2019 23:46:35 -0800 Subject: Fixed CPI/CPD/CPIR/CPDR in new Z80 core --- cpu_dsl.py | 6 +++--- z80.cpu | 19 ++++++++++++++++++- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/cpu_dsl.py b/cpu_dsl.py index a5016b6..9893600 100755 --- a/cpu_dsl.py +++ b/cpu_dsl.py @@ -418,7 +418,7 @@ def _updateFlagsCImpl(prog, params, rawParams): raise Exception('Unknown flag calc type: ' + calc) if prog.carryFlowDst: if prog.lastOp.op != 'cmp': - output.append('\n\t{dst} = {tmpdst};'.format(dst = prog.resolveParam(prog.lastDst, None, {}), tmpdst = prog.carryFlowDst)) + output.append('\n\t{dst} = {tmpdst};'.format(dst = prog.resolveParam(prog.lastDst, prog.currentScope, {}), tmpdst = prog.carryFlowDst)) prog.carryFlowDst = None if parity: if paritySize > 8: @@ -1363,8 +1363,8 @@ class Program: def getTemp(self, size): if size in self.temp: return ('', self.temp[size]) - self.temp[size] = 'tmp{sz}'.format(sz=size); - return ('\n\tuint{sz}_t tmp{sz};'.format(sz=size), self.temp[size]) + self.temp[size] = 'gen_tmp{sz}__'.format(sz=size); + return ('\n\tuint{sz}_t gen_tmp{sz}__;'.format(sz=size), self.temp[size]) def resolveParam(self, param, parent, fieldVals, allowConstant=True, isdst=False): keepGoing = True diff --git a/z80.cpu b/z80.cpu index 8a69723..4742e4a 100644 --- a/z80.cpu +++ b/z80.cpu @@ -2127,11 +2127,18 @@ ed 10111000 lddr z80_cpd_cpi local tmp 16 local tmp8 8 + local hf 8 arg change 16 z80_fetch_mod_hl change sub scratch1 a tmp8 - update_flags SZHXN1 + update_flags SZHN1 + + lsr chflags 3 hf + and 1 hf hf + + sub hf tmp8 tmp8 + update_flags X and 0x2 tmp8 tmp8 lsl tmp8 4 tmp8 @@ -2159,21 +2166,31 @@ ed 10110001 cpir z80_cpd_cpi 1 if pvflag + if zflag + + else + add 1 pc wz sub 2 pc pc cycles 5 end + end ed 10111001 cpdr z80_cpd_cpi -1 if pvflag + if zflag + + else + add 1 pc wz sub 2 pc pc cycles 5 end + end 00100111 daa local diff 8 -- cgit v1.2.3