From 492743608c4e13e911015e77c5d2e6537955145f Mon Sep 17 00:00:00 2001 From: ghidorahrex Date: Thu, 22 Jun 2023 18:32:31 +0000 Subject: [PATCH] GP-2881: Fixed up several instructions --- .../Processors/Z80/data/languages/z80.slaspec | 1050 ++++++++++------- 1 file changed, 629 insertions(+), 421 deletions(-) diff --git a/Ghidra/Processors/Z80/data/languages/z80.slaspec b/Ghidra/Processors/Z80/data/languages/z80.slaspec index 41141036da..12a590ba7f 100644 --- a/Ghidra/Processors/Z80/data/languages/z80.slaspec +++ b/Ghidra/Processors/Z80/data/languages/z80.slaspec @@ -20,7 +20,7 @@ define register offset=0x00 size=2 [ AF BC DE HL ]; define register offset=0x20 size=1 [ F_ A_ C_ B_ E_ D_ L_ H_ ]; # Alternate registers define register offset=0x20 size=2 [ AF_ BC_ DE_ HL_ ]; # Alternate registers define register offset=0x40 size=2 [ _ PC SP IX IY ]; - +define register offset=0x46 size=1 [ IXL IXH IYL IYH ]; # Undocumented registers define register offset=0x50 size=1 [ rCBAR rCBR rBBR ]; # Fake Registers used for pcode control @@ -451,16 +451,18 @@ cc2: "C" is bits3_3=0x7 { c:1 = $(C_flag); export c; } } :LD A,I is op0_8=0xed & A & I; op0_8=0x57 { - A = I; - setResultFlags(I); + local val = I; + A = val; + setResultFlags(val); $(H_flag) = 0; # $(PV_flag) = IFF2; $(N_flag) = 0; } :LD A,R is op0_8=0xed & A & R; op0_8=0x5f { - A = R; - setResultFlags(R); + local val = R; + A = val; + setResultFlags(val); $(H_flag) = 0; # $(PV_flag) = IFF2; $(N_flag) = 0; @@ -591,49 +593,73 @@ cc2: "C" is bits3_3=0x7 { c:1 = $(C_flag); export c; } swap(IY); } -# ?? Instruction manual contradicts itself - not sure what to do here ?? :LDI is op0_8=0xed; op0_8=0xa0 { val:1 = 0; - MemRead(val,HL); - MemStore(DE,val); - DE = DE + 1; - HL = HL + 1; - BC = BC - 1; + local inloc = HL; + local outloc = DE; + MemRead(val,inloc); + MemStore(outloc,val); + + DE = outloc + 1; + HL = inloc + 1; + local test = BC - 1; + BC = test; + $(H_flag) = 0; - $(PV_flag) = (BC != 0); + $(PV_flag) = (test != 0); $(N_flag) = 0; } :LDIR is op0_8=0xed; op0_8=0xb0 { - tmp:1 = 0; - MemRead(tmp,HL); - MemStore(DE,tmp); - DE = DE + 1; - HL = HL + 1; - BC = BC - 1; - if (BC != 0) goto inst_start; + val:1 = 0; + local inloc = HL; + local outloc = DE; + MemRead(val,inloc); + MemStore(outloc,val); + + DE = outloc + 1; + HL = inloc + 1; + local test = BC - 1; + BC = test; + + if (test != 0) goto inst_start; + $(H_flag) = 0; - $(PV_flag) = (BC != 0); + $(PV_flag) = 0; $(N_flag) = 0; } :LDD is op0_8=0xed; op0_8=0xa8 { - DE = DE - 1; - HL = HL - 1; - BC = BC - 1; + val:1 = 0; + local inloc = HL; + local outloc = DE; + MemRead(val,inloc); + MemStore(outloc,val); + + DE = outloc - 1; + HL = inloc - 1; + local test = BC - 1; + BC = test; + $(H_flag) = 0; - $(PV_flag) = (BC != 0); + $(PV_flag) = (test != 0); $(N_flag) = 0; } :LDDR is op0_8=0xed; op0_8=0xb8 { - tmp:1 = 0; - MemRead(tmp,HL); - MemStore(DE,tmp); - DE = DE - 1; - HL = HL - 1; - BC = BC - 1; - if (BC != 0) goto inst_start; + val:1 = 0; + local inloc = HL; + local outloc = DE; + MemRead(val,inloc); + MemStore(outloc,val); + + DE = outloc - 1; + HL = inloc - 1; + local test = BC - 1; + BC = test; + + if (test != 0) goto inst_start; + $(H_flag) = 0; $(PV_flag) = 0; $(N_flag) = 0; @@ -641,395 +667,498 @@ cc2: "C" is bits3_3=0x7 { c:1 = $(C_flag); export c; } :CPI is op0_8=0xed; op0_8=0xa1 { val:1 = 0; - MemRead(val,HL); - cmp:1 = A - val; + local loc = HL; + MemRead(val,loc); + local a_temp = A; + + cmp:1 = a_temp - val; setResultFlags(cmp); - HL = HL + 1; - BC = BC - 1; + HL = loc + 1; + local test = BC - 1; + BC = test; - carries:1 = (~A & val) | (val & cmp) | (cmp & ~A); + carries:1 = (~a_temp & val) | (val & cmp) | (cmp & ~a_temp); $(H_flag) = (carries & 0b00001000) != 0; - $(PV_flag) = (BC != 0); + $(PV_flag) = (test != 0); $(N_flag) = 1; } :CPIR is op0_8=0xed; op0_8=0xb1 { val:1 = 0; - MemRead(val,HL); - cmp:1 = A - val; - setResultFlags(cmp); - HL = HL + 1; - BC = BC - 1; + local loc = HL; + MemRead(val,loc); + local a_temp = A; - if (cmp != 0 || BC != 0) goto inst_start; + cmp:1 = a_temp - val; + setResultFlags(cmp); + HL = loc + 1; + local test = BC - 1; + BC = test; + + if (cmp != 0 || test != 0) goto inst_start; - carries:1 = (~A & val) | (val & cmp) | (cmp & ~A); + carries:1 = (~a_temp & val) | (val & cmp) | (cmp & ~a_temp); $(H_flag) = (carries & 0b00001000) != 0; - $(PV_flag) = (BC != 0); + $(PV_flag) = (test != 0); $(N_flag) = 1; } :CPD is op0_8=0xed; op0_8=0xa9 { val:1 = 0; - MemRead(val,HL); - cmp:1 = A - val; - setResultFlags(cmp); - HL = HL - 1; - BC = BC - 1; + local loc = HL; + MemRead(val,loc); + local a_temp = A; - carries:1 = (~A & val) | (val & cmp) | (cmp & ~A); + cmp:1 = a_temp - val; + setResultFlags(cmp); + HL = loc - 1; + local test = BC - 1; + BC = test; + + carries:1 = (~a_temp & val) | (val & cmp) | (cmp & ~a_temp); $(H_flag) = (carries & 0b00001000) != 0; - $(PV_flag) = (BC != 0); + $(PV_flag) = (test != 0); $(N_flag) = 1; } :CPDR is op0_8=0xed; op0_8=0xb9 { val:1 = 0; - MemRead(val,HL); - cmp:1 = A - val; + local loc = HL; + MemRead(val,loc); + local a_temp = A; + + cmp:1 = a_temp - val; setResultFlags(cmp); - HL = HL - 1; - BC = BC - 1; + HL = loc - 1; + local test = BC - 1; + BC = test; - if (cmp != 0 || BC != 0) goto inst_start; - - carries:1 = (~A & val) | (val & cmp) | (cmp & ~A); + if (cmp != 0 || test != 0) goto inst_start; + + carries:1 = (~a_temp & val) | (val & cmp) | (cmp & ~a_temp); $(H_flag) = (carries & 0b00001000) != 0; - $(PV_flag) = (BC != 0); + $(PV_flag) = (test != 0); $(N_flag) = 1; } :ADD A, reg0_3 is op6_2=0x2 & bits3_3=0x0 & reg0_3 & A { - local A_temp = A; + local a_temp = A; local reg_temp = reg0_3; - - A = A + reg0_3; - setResultFlags(A); - additionFlags(A_temp, reg_temp); + + additionFlags(a_temp, reg_temp); + a_temp= a_temp + reg0_3; + setResultFlags(a_temp); + A = a_temp; } :ADD A, imm8 is op0_8=0xc6; imm8 & A { - local A_temp = A; - - A = A + imm8; - setResultFlags(A); - additionFlags(A_temp, imm8); + local a_temp = A; + + additionFlags(a_temp, imm8); + a_temp = a_temp + imm8; + setResultFlags(a_temp); + A = a_temp; } :ADD A, (HL) is op0_8=0x86 & HL & A { val:1 = 0; MemRead(val,HL); - local A_temp = A; - - A = A + val; - setResultFlags(A); - additionFlags(A_temp, val); + local a_temp = A; + + additionFlags(a_temp, val); + a_temp = a_temp + val; + setResultFlags(a_temp); + A = a_temp; } :ADD A, ixMem8 is op0_8=0xdd; op0_8=0x86; ixMem8 & A { val:1 = ixMem8; - local A_temp = A; - - A = A + val; - setResultFlags(A); - additionFlags(A_temp, val); + local a_temp = A; + + additionFlags(a_temp, val); + a_temp = a_temp + val; + setResultFlags(a_temp); + A = a_temp; } :ADD A, iyMem8 is op0_8=0xfd; op0_8=0x86; iyMem8 & A { val:1 = iyMem8; - local A_temp = A; - - A = A + val; - setResultFlags(A); - additionFlags(A_temp, val); + local a_temp = A; + + additionFlags(a_temp, val); + a_temp = a_temp + val; + setResultFlags(a_temp); + A = a_temp; } :ADC A, reg0_3 is op6_2=0x2 & bits3_3=0x1 & reg0_3 & A { - additionWithCarry(A, reg0_3, A); - setResultFlags(A); + local a_temp = A; + local r_temp = reg0_3; + + additionWithCarry(a_temp, r_temp, a_temp); + setResultFlags(a_temp); + A = a_temp; } :ADC A, imm8 is op0_8=0xce; imm8 & A { - additionWithCarry(A, imm8, A); - setResultFlags(A); + val:1 = imm8; + local a_temp = A; + + additionWithCarry(a_temp, val, a_temp); + setResultFlags(a_temp); + A = a_temp; } :ADC A, (HL) is op0_8=0x8e & HL & A { val:1 = 0; MemRead(val,HL); - additionWithCarry(A, val, A); - setResultFlags(A); + local a_temp = A; + + additionWithCarry(a_temp, val, a_temp); + setResultFlags(a_temp); + A = a_temp; } :ADC A, ixMem8 is op0_8=0xdd; op0_8=0x8e; ixMem8 & A{ val:1 = ixMem8; - additionWithCarry(A, val, A); - setResultFlags(A); + MemRead(val,HL); + local a_temp = A; + + additionWithCarry(a_temp, val, a_temp); + setResultFlags(a_temp); + A = a_temp; } :ADC A, iyMem8 is op0_8=0xfd; op0_8=0x8e; iyMem8 & A { + val:1 = iyMem8; - additionWithCarry(A, val, A); - setResultFlags(A); + MemRead(val,HL); + local a_temp = A; + + additionWithCarry(a_temp, val, a_temp); + setResultFlags(a_temp); + A = a_temp; } :SUB reg0_3 is op6_2=0x2 & bits3_3=0x2 & reg0_3 { - local A_temp = A; - - A = A - reg0_3; - subtractionFlags(A_temp, reg0_3); - setResultFlags(A); + local a_temp = A; + local r_temp = reg0_3; + + subtractionFlags(a_temp, r_temp); + a_temp = a_temp - r_temp; + setResultFlags(a_temp); + a_temp = A; } :SUB imm8 is op0_8=0xd6; imm8 { - local A_temp = A; - - A = A - imm8; - subtractionFlags(A_temp, imm8); - setResultFlags(A); + local a_temp = A; + + subtractionFlags(a_temp, imm8); + a_temp = a_temp - imm8; + setResultFlags(a_temp); + A = a_temp; } :SUB (HL) is op0_8=0x96 & HL { val:1 = 0; MemRead(val,HL); - local A_temp = A; - - A = A - val; - subtractionFlags(A_temp, val); - setResultFlags(A); + local a_temp = A; + + subtractionFlags(a_temp, val); + a_temp = a_temp - val; + setResultFlags(a_temp); + A = a_temp; } :SUB ixMem8 is op0_8=0xdd; op0_8=0x96; ixMem8 { val:1 = ixMem8; - local A_temp = A; - - A = A - val; - subtractionFlags(A_temp, val); - setResultFlags(A); + local a_temp = A; + + subtractionFlags(a_temp, val); + a_temp = a_temp - val; + setResultFlags(a_temp); + A = a_temp; } :SUB iyMem8 is op0_8=0xfd; op0_8=0x96; iyMem8 { val:1 = iyMem8; - local A_temp = A; - - A = A - val; - subtractionFlags(A_temp, val); - setResultFlags(A); + local a_temp = A; + + subtractionFlags(a_temp, val); + a_temp = a_temp - val; + setResultFlags(a_temp); + A = a_temp; } :SBC A, reg0_3 is op6_2=0x2 & bits3_3=0x3 & reg0_3 & A { - subtractionWithCarry(A, reg0_3, A); - setResultFlags(A); + local a_temp = A; + local r_temp = reg0_3; + + subtractionWithCarry(a_temp, r_temp, a_temp); + setResultFlags(a_temp); + A = a_temp; } :SBC A, imm8 is op0_8=0xde; imm8 & A { - subtractionWithCarry(A, imm8, A); - setResultFlags(A); + local a_temp = A; + + subtractionWithCarry(a_temp, imm8, a_temp); + setResultFlags(a_temp); + A = a_temp; } :SBC A, (HL) is op0_8=0x9e & HL & A { val:1 = 0; MemRead(val,HL); - subtractionWithCarry(A, val, A); - setResultFlags(A); + local a_temp = A; + + subtractionWithCarry(a_temp, val, a_temp); + setResultFlags(a_temp); + A = a_temp; } :SBC A, ixMem8 is op0_8=0xdd; op0_8=0x9e; ixMem8 & A { val:1 = ixMem8; - subtractionWithCarry(A, val, A); - setResultFlags(A); + local a_temp = A; + + subtractionWithCarry(a_temp, val, a_temp); + setResultFlags(a_temp); + A = a_temp; } :SBC A, iyMem8 is op0_8=0xfd; op0_8=0x9e; iyMem8 & A { val:1 = iyMem8; - subtractionWithCarry(A, val, A); - setResultFlags(A); + local a_temp = A; + + subtractionWithCarry(a_temp, val, a_temp); + setResultFlags(a_temp); + A = a_temp; } :AND reg0_3 is op6_2=0x2 & bits3_3=0x4 & reg0_3 { + local a_temp = A; $(H_flag) = 1; $(C_flag) = 0; $(N_flag) = 0; - A = A & reg0_3; - setResultFlags(A); - setParity(A); + a_temp = a_temp & reg0_3; + setResultFlags(a_temp); + setParity(a_temp); + A = a_temp; } :AND imm8 is op0_8=0xe6; imm8 { + local a_temp = A; $(H_flag) = 1; $(C_flag) = 0; $(N_flag) = 0; - A = A & imm8; - setResultFlags(A); - setParity(A); + a_temp = a_temp & imm8; + setResultFlags(a_temp); + setParity(a_temp); + A = a_temp; } :AND (HL) is op0_8=0xa6 & HL { + val:1 = 0; + MemRead(val,HL); + local a_temp = A; $(H_flag) = 1; $(C_flag) = 0; $(N_flag) = 0; - tmp:1 = 0; - MemRead(tmp,HL); - A = A & tmp; - setResultFlags(A); - setParity(A); + + a_temp = a_temp & val; + setResultFlags(a_temp); + setParity(a_temp); + A = a_temp; } :AND ixMem8 is op0_8=0xdd; op0_8=0xa6; ixMem8 { + local a_temp = A; $(H_flag) = 1; $(C_flag) = 0; $(N_flag) = 0; - A = A & ixMem8; - setResultFlags(A); - setParity(A); + a_temp = a_temp & ixMem8; + setResultFlags(a_temp); + setParity(a_temp); + A = a_temp; } :AND iyMem8 is op0_8=0xfd; op0_8=0xa6; iyMem8 { + local a_temp = A; $(H_flag) = 1; $(C_flag) = 0; $(N_flag) = 0; - A = A & iyMem8; - setResultFlags(A); - setParity(A); + a_temp = a_temp & iyMem8; + setResultFlags(a_temp); + setParity(a_temp); + A = a_temp; } :OR reg0_3 is op6_2=0x2 & bits3_3=0x6 & reg0_3 { + local a_temp = A; $(H_flag) = 0; $(C_flag) = 0; $(N_flag) = 0; - A = A | reg0_3; - setResultFlags(A); - setParity(A); + a_temp = a_temp | reg0_3; + setResultFlags(a_temp); + setParity(a_temp); + A = a_temp; } :OR imm8 is op0_8=0xf6; imm8 { + local a_temp = A; $(H_flag) = 0; $(C_flag) = 0; $(N_flag) = 0; - A = A | imm8; - setResultFlags(A); - setParity(A); + a_temp = a_temp | imm8; + setResultFlags(a_temp); + setParity(a_temp); + A = a_temp; } :OR (HL) is op0_8=0xb6 & HL { + val:1 = 0; + MemRead(val,HL); + local a_temp = A; + $(H_flag) = 0; $(C_flag) = 0; $(N_flag) = 0; - val:1 = 0; - MemRead(val,HL); - A = A | val; - setResultFlags(A); - setParity(A); + a_temp = a_temp | val; + setResultFlags(a_temp); + setParity(a_temp); + A = a_temp; } :OR ixMem8 is op0_8=0xdd; op0_8=0xb6; ixMem8 { + local a_temp = A; $(H_flag) = 0; $(C_flag) = 0; $(N_flag) = 0; - A = A | ixMem8; - setResultFlags(A); - setParity(A); + a_temp = a_temp | ixMem8; + setResultFlags(a_temp); + setParity(a_temp); + A = a_temp; } :OR iyMem8 is op0_8=0xfd; op0_8=0xb6; iyMem8 { + local a_temp = A; $(H_flag) = 0; $(C_flag) = 0; $(N_flag) = 0; - A = A | iyMem8; - setResultFlags(A); - setParity(A); + a_temp = a_temp | iyMem8; + setResultFlags(a_temp); + setParity(a_temp); + A = a_temp; } :XOR reg0_3 is op6_2=0x2 & bits3_3=0x5 & reg0_3 { + local a_temp = A; $(H_flag) = 0; $(C_flag) = 0; $(N_flag) = 0; - A = A ^ reg0_3; - setResultFlags(A); - setParity(A); + a_temp = a_temp ^ reg0_3; + setResultFlags(a_temp); + setParity(a_temp); + A = a_temp; } :XOR imm8 is op0_8=0xee; imm8 { + local a_temp = A; $(H_flag) = 0; $(C_flag) = 0; $(N_flag) = 0; - A = A ^ imm8; - setResultFlags(A); - setParity(A); + a_temp = a_temp ^ imm8; + setResultFlags(a_temp); + setParity(a_temp); + A = a_temp; } :XOR (HL) is op0_8=0xae & HL { + val:1 = 0; + MemRead(val,HL); + local a_temp = A; + $(H_flag) = 0; $(C_flag) = 0; $(N_flag) = 0; - val:1 = 0; - MemRead(val,HL); - A = A ^ val; - setResultFlags(A); - setParity(A); + + a_temp = a_temp ^ val; + setResultFlags(a_temp); + setParity(a_temp); + A = a_temp; } :XOR ixMem8 is op0_8=0xdd; op0_8=0xae; ixMem8 { + local a_temp = A; $(H_flag) = 0; $(C_flag) = 0; $(N_flag) = 0; - A = A ^ ixMem8; - setResultFlags(A); - setParity(A); + a_temp = a_temp ^ ixMem8; + setResultFlags(a_temp); + setParity(a_temp); + A = a_temp; } :XOR iyMem8 is op0_8=0xfd; op0_8=0xae; iyMem8 { + local a_temp = A; $(H_flag) = 0; $(C_flag) = 0; $(N_flag) = 0; - A = A ^ iyMem8; - setResultFlags(A); - setParity(A); + a_temp = a_temp ^ iyMem8; + setResultFlags(a_temp); + setParity(a_temp); + A = a_temp; } :CP reg0_3 is op6_2=0x2 & bits3_3=0x7 & reg0_3 { - cmp:1 = A - reg0_3; - subtractionFlags(A, reg0_3); + local a_temp = A; + local r_temp = reg0_3; + cmp:1 = a_temp - r_temp; + subtractionFlags(a_temp, r_temp); setResultFlags(cmp); } :CP imm8 is op0_8=0xfe; imm8 { - cmp:1 = A - imm8; - subtractionFlags(A, imm8); + local a_temp = A; + cmp:1 = a_temp - imm8; + subtractionFlags(a_temp, imm8); setResultFlags(cmp); } :CP (HL) is op0_8=0xbe & HL { val:1 = 0; MemRead(val,HL); + local a_temp = A; - cmp:1 = A - val; - subtractionFlags(A, val); + cmp:1 = a_temp - val; + subtractionFlags(a_temp, val); setResultFlags(cmp); } :CP ixMem8 is op0_8=0xdd; op0_8=0xbe; ixMem8 { val:1 = ixMem8; - - cmp:1 = A - val; - subtractionFlags(A, val); + local a_temp = A; + + cmp:1 = a_temp - val; + subtractionFlags(a_temp, val); setResultFlags(cmp); } :CP iyMem8 is op0_8=0xfd; op0_8=0xbe; iyMem8 { val:1 = iyMem8; - - cmp:1 = A - val; - subtractionFlags(A, val); +local a_temp = A; + + cmp:1 = a_temp - val; + subtractionFlags(a_temp, val); setResultFlags(cmp); } :INC reg3_3 is op6_2=0x0 & reg3_3 & bits0_3=0x4 { local r_temp = reg3_3; - - reg3_3 = reg3_3 + 1; - setResultFlags(reg3_3); - additionFlagsNoC(r_temp, 1); + additionFlags(r_temp, 1); + r_temp = r_temp + 1; + reg3_3 = r_temp; + setResultFlags(r_temp); } :INC (HL) is op0_8=0x34 & HL { @@ -1065,10 +1194,10 @@ cc2: "C" is bits3_3=0x7 { c:1 = $(C_flag); export c; } :DEC reg3_3 is op6_2=0x0 & reg3_3 & bits0_3=0x5 { local r_temp = reg3_3; - - reg3_3 = reg3_3 - 1; subtractionFlagsNoC(r_temp, 1); - setResultFlags(reg3_3); + r_temp = r_temp - 1; + reg3_3 = r_temp; + setResultFlags(r_temp); } :DEC (HL) is op0_8=0x35 & HL { @@ -1103,10 +1232,11 @@ cc2: "C" is bits3_3=0x7 { c:1 = $(C_flag); export c; } } :DAA is op0_8=0x27 { + local a_temp = A; if (DECOMPILE_MODE) goto ; - HN:1 = A >> 4; # high nibble - LN:1 = A & 0xF; # low nibbble + HN:1 = a_temp >> 4; # high nibble + LN:1 = a_temp & 0xF; # low nibbble # # If (C and H are both 0, and both nibbles are in range[0,9] no # adjustment is needed. @@ -1130,31 +1260,31 @@ if (DECOMPILE_MODE) goto ; # # Isn't used - A = A + 0x06; + a_temp = a_temp + 0x06; goto ; - A = A + 0x06; + a_temp = a_temp + 0x06; goto ; - A = A + 0x60; + a_temp = a_temp + 0x60; $(C_flag) = 1; goto ; - A = A + 0x66; + a_temp = a_temp + 0x66; $(C_flag) = 1; goto ; - A = A + 0x66; + a_temp = a_temp + 0x66; $(C_flag) = 1; goto ; - A = A + 0x60; + a_temp = a_temp + 0x60; goto ; - A = A + 0x66; + a_temp = a_temp + 0x66; goto ; - A = A + 0x66; + a_temp = a_temp + 0x66; goto ; @@ -1168,30 +1298,32 @@ if (DECOMPILE_MODE) goto ; # # Isn't used - A = A + 0xFA; + a_temp = a_temp + 0xFA; goto ; - A = A + 0xA0; + a_temp = a_temp + 0xA0; goto ; - A = A + 0x9A; + a_temp = a_temp + 0x9A; - setResultFlags(A); - setParity(A); + setResultFlags(a_temp); + setParity(a_temp); + A = a_temp; goto ; - A_temp:1 = A; + - A = BCDadjust(A_temp, $(C_flag), $(H_flag)); - $(C_flag) = BCDadjustCarry(A_temp, $(C_flag), $(H_flag)); + a_temp = BCDadjust(a_temp, $(C_flag), $(H_flag)); + $(C_flag) = BCDadjustCarry(a_temp, $(C_flag), $(H_flag)); - setResultFlags(A); - $(PV_flag) = hasEvenParity(A); + setResultFlags(a_temp); + $(PV_flag) = hasEvenParity(a_temp); + A = a_temp; } @@ -1203,11 +1335,11 @@ if (DECOMPILE_MODE) goto ; } :NEG is op0_8=0xed; op0_8=0x44 { - A_temp:1 = A; - - A = -A; - subtractionFlags(0, A_temp); - setResultFlags(A); + local a_temp = A; + subtractionFlags(0, a_temp); + a_temp = -a_temp; + A = a_temp; + setResultFlags(a_temp); } :CCF is op0_8=0x3f { @@ -1256,38 +1388,43 @@ if (DECOMPILE_MODE) goto ; local HL_temp = HL; local Reg_temp = sRegPair4_2; - HL = HL + sRegPair4_2; additionFlagsNoPV(HL_temp, Reg_temp); + HL = HL_temp + Reg_temp; } :ADC HL,sRegPair4_2 is op0_8=0xed & HL; op6_2=0x1 & sRegPair4_2 & bits0_4=0xa { local HL_temp = HL; local Reg_temp = sRegPair4_2; - HL = HL + sRegPair4_2 + zext($(C_flag)); - setResultFlags(HL); additionFlagsNoPV(HL_temp, Reg_temp); + HL_temp = HL_temp + Reg_temp + zext($(C_flag)); + setResultFlags(HL_temp); + HL = HL_temp; } :SBC HL,sRegPair4_2 is op0_8=0xed & HL; op6_2=0x1 & sRegPair4_2 & bits0_4=0x2 { - subtractionWithCarry(HL, sRegPair4_2, HL); - setResultFlags(HL); + local HL_temp = HL; + local Reg_temp = sRegPair4_2; + + subtractionWithCarry(HL_temp, sRegPair4_2, HL_temp); + setResultFlags(HL_temp); + HL = HL_temp; } :ADD IX,pRegPair4_2 is op0_8=0xdd & IX; op6_2=0x0 & pRegPair4_2 & bits0_4=0x9 { local IX_temp = IX; local Reg_temp = pRegPair4_2; - IX = IX + pRegPair4_2; additionFlagsNoPV(IX_temp, Reg_temp); + IX = IX_temp + pRegPair4_2; } :ADD IY,pRegPair4_2 is op0_8=0xfd & IY; op6_2=0x0 & pRegPair4_2 & bits0_4=0x9 { local IY_temp = IY; local Reg_temp = pRegPair4_2; - IY = IY + pRegPair4_2; additionFlagsNoPV(IY_temp, Reg_temp); + IY = IY_temp + Reg_temp; } :INC sRegPair4_2 is op6_2=0x0 & sRegPair4_2 & bits0_4=0x3 { @@ -1315,41 +1452,47 @@ if (DECOMPILE_MODE) goto ; } :RLCA is op0_8=0x07 { - $(C_flag) = (A >> 7); - A = (A << 1) | $(C_flag); + local a_temp = A; + $(C_flag) = (a_temp >> 7); + A = (a_temp << 1) | $(C_flag); $(H_flag) = 0; $(N_flag) = 0; } :RLA is op0_8=0x17 { - nextC:1 = (A >> 7); - A = (A << 1) | $(C_flag); + local a_temp = A; + nextC:1 = (a_temp >> 7); + A = (a_temp << 1) | $(C_flag); $(C_flag) = nextC; $(H_flag) = 0; $(N_flag) = 0; } :RRCA is op0_8=0x0f { - $(C_flag) = (A & 1); - A = (A >> 1) | ($(C_flag) << 7); + local a_temp = A; + $(C_flag) = (a_temp & 1); + A = (a_temp >> 1) | ($(C_flag) << 7); $(H_flag) = 0; $(N_flag) = 0; } :RRA is op0_8=0x1f { - nextC:1 = (A & 1); - A = (A >> 1) | ($(C_flag) << 7); + local a_temp = A; + nextC:1 = (a_temp & 1); + A = (a_temp >> 1) | ($(C_flag) << 7); $(C_flag) = nextC; $(H_flag) = 0; $(N_flag) = 0; } :RLC reg0_3 is op0_8=0x0cb; op6_2=0x0 & bits3_3=0x0 & reg0_3 { - $(C_flag) = (reg0_3 >> 7); - reg0_3 = (reg0_3 << 1) | $(C_flag); - setResultFlags(reg0_3); + local val = reg0_3; + $(C_flag) = (val >> 7); + val = (val << 1) | $(C_flag); + reg0_3 = val; + setResultFlags(val); $(H_flag) = 0; - setParity(reg0_3); + setParity(val); $(N_flag) = 0; } @@ -1387,12 +1530,14 @@ if (DECOMPILE_MODE) goto ; } :RL reg0_3 is op0_8=0x0cb; op6_2=0x0 & bits3_3=0x2 & reg0_3 { - nextC:1 = (reg0_3 >> 7); - reg0_3 = (reg0_3 << 1) | $(C_flag); + local r_temp = reg0_3; + nextC:1 = (r_temp >> 7); + r_temp = (r_temp << 1) | $(C_flag); + reg0_3 = r_temp; $(C_flag) = nextC; - setResultFlags(reg0_3); + setResultFlags(r_temp); $(H_flag) = 0; - setParity(reg0_3); + setParity(r_temp); $(N_flag) = 0; } @@ -1434,11 +1579,13 @@ if (DECOMPILE_MODE) goto ; } :RRC reg0_3 is op0_8=0x0cb; op6_2=0x0 & bits3_3=0x1 & reg0_3 { - $(C_flag) = (reg0_3 & 1); - reg0_3 = (reg0_3 >> 1) | ($(C_flag) << 7); - setResultFlags(reg0_3); + local r_temp = reg0_3; + $(C_flag) = (r_temp & 1); + r_temp = (r_temp >> 1) | ($(C_flag) << 7); + reg0_3 = r_temp; + setResultFlags(r_temp); $(H_flag) = 0; - setParity(reg0_3); + setParity(r_temp); $(N_flag) = 0; } @@ -1477,12 +1624,14 @@ if (DECOMPILE_MODE) goto ; } :RR reg0_3 is op0_8=0x0cb; op6_2=0x0 & bits3_3=0x3 & reg0_3 { - nextC:1 = (reg0_3 & 1); - reg0_3 = (reg0_3 >> 1) | ($(C_flag) << 7); + local r_temp = reg0_3; + nextC:1 = (r_temp & 1); + r_temp = (r_temp >> 1) | ($(C_flag) << 7); + reg0_3 = r_temp; $(C_flag) = nextC; - setResultFlags(reg0_3); + setResultFlags(r_temp); $(H_flag) = 0; - setParity(reg0_3); + setParity(r_temp); $(N_flag) = 0; } @@ -1524,11 +1673,13 @@ if (DECOMPILE_MODE) goto ; } :SLA reg0_3 is op0_8=0x0cb; op6_2=0x0 & bits3_3=0x4 & reg0_3 { - $(C_flag) = (reg0_3 >> 7); - reg0_3 = reg0_3 << 1; - setResultFlags(reg0_3); + local r_temp = reg0_3; + $(C_flag) = (r_temp >> 7); + r_temp = r_temp << 1; + reg0_3 = r_temp; + setResultFlags(r_temp); $(H_flag) = 0; - setParity(reg0_3); + setParity(r_temp); $(N_flag) = 0; } @@ -1567,11 +1718,13 @@ if (DECOMPILE_MODE) goto ; } :SRA reg0_3 is op0_8=0x0cb; op6_2=0x0 & bits3_3=0x5 & reg0_3 { - $(C_flag) = (reg0_3 & 1); - reg0_3 = reg0_3 s>> 1; - setResultFlags(reg0_3); + local _val = reg0_3; + $(C_flag) = (_val & 1); + _val = _val s>> 1; + reg0_3 = _val; + setResultFlags(_val); $(H_flag) = 0; - setParity(reg0_3); + setParity(_val); $(N_flag) = 0; } @@ -1610,11 +1763,13 @@ if (DECOMPILE_MODE) goto ; } :SRL reg0_3 is op0_8=0x0cb; op6_2=0x0 & bits3_3=0x7 & reg0_3 { - $(C_flag) = (reg0_3 & 1); - reg0_3 = reg0_3 >> 1; - setResultFlags(reg0_3); + local val = reg0_3; + $(C_flag) = (val & 1); + val = val >> 1; + reg0_3 = val; + setResultFlags(val); $(H_flag) = 0; - setParity(reg0_3); + setParity(val); $(N_flag) = 0; } @@ -1654,37 +1809,41 @@ if (DECOMPILE_MODE) goto ; :RLD is op0_8=0xed; op0_8=0x6f { val:1 = 0; + local a_temp = A; MemRead(val,HL); - nibA:1 = A & 0x0f; + nibA:1 = a_temp & 0x0f; nibM:1 = val >> 4; val = (val << 4) | nibA; - A = (A & 0xf0) | nibM; + a_temp = (a_temp & 0xf0) | nibM; + A = a_temp; MemStore(HL,val); @if defined(Z180) setResultFlags(val); @else - setResultFlags(A); + setResultFlags(a_temp); @endif $(H_flag) = 0; - setParity(A); + setParity(a_temp); $(N_flag) = 0; } :RRD is op0_8=0xed; op0_8=0x67 { val:1 = 0; MemRead(val,HL); - nibA:1 = A & 0x0f; + local a_temp = A; + nibA:1 = a_temp & 0x0f; nibM:1 = val & 0x0f; val = (val >> 4) | (nibA << 4); - A = (A & 0xf0) | nibM; + a_temp = (a_temp & 0xf0) | nibM; + A = a_temp; MemStore(HL,val); @if defined(Z180) setResultFlags(val); @else - setResultFlags(A); + setResultFlags(a_temp); @endif $(H_flag) = 0; - setParity(A); + setParity(a_temp); $(N_flag) = 0; } @@ -1855,10 +2014,12 @@ if (DECOMPILE_MODE) goto ; } :IN reg3_3,IOAddrC is op0_8=0xed & IOAddrC; op6_2=0x1 & reg3_3 & bits0_3=0x0 { - ioRead(IOAddrC, reg3_3); - setResultFlags(reg3_3); + val:1 = 0; + ioRead(IOAddrC, val); + reg3_3 = val; + setResultFlags(val); $(H_flag) = 0; - setParity(reg3_3); + setParity(val); $(N_flag) = 0; } @@ -1913,59 +2074,70 @@ if (DECOMPILE_MODE) goto ; } :OUTI is op0_8=0xed & IOAddrC; op0_8=0xa3 { + local test = B - 1; + B = test; val:1 = 0; MemRead(val,HL); + ioWrite(IOAddrC, val); - B = B - 1; HL = HL + 1; - $(Z_flag) = (B == 0); - $(N_flag) = (B s< 0); + $(Z_flag) = (test == 0); + $(N_flag) = (test s< 0); } :OTIR is op0_8=0xed & IOAddrC; op0_8=0xb3 { B = B - 1; val:1 = 0; MemRead(val,HL); + ioWrite(IOAddrC, val); HL = HL + 1; + if (B != 0) goto inst_start; + $(Z_flag) = 1; $(N_flag) = 1; } :OUTD is op0_8=0xed & IOAddrC; op0_8=0xab { - B = B - 1; + local test = B - 1; + B = test; val:1 = 0; MemRead(val,HL); + ioWrite(IOAddrC, val); HL = HL - 1; - $(Z_flag) = (B == 0); - $(N_flag) = (B s< 0); + $(Z_flag) = (test == 0); + $(N_flag) = (test s< 0); } :OTDR is op0_8=0xed & IOAddrC; op0_8=0xbb { B = B - 1; val:1 = 0; MemRead(val,HL); + ioWrite(IOAddrC, val); HL = HL - 1; + if (B != 0) goto inst_start; + $(Z_flag) = 1; $(N_flag) = 1; } @if defined(Z180) :MLT qRegPair4_2 is op0_8=0xed; op6_2=0x1 & qRegPair4_2 & bits0_4=0xc { - hi:2 = qRegPair4_2 >> 8; - lo:2 = qRegPair4_2 & 0xff; + local pair = qRegPair4_2; + hi:2 = pair >> 8; + lo:2 = pair & 0xff; qRegPair4_2 = hi * lo; } :TST reg3_3 is op0_8=0xed; op6_2=0x0 & reg3_3 & bits0_3=0x4 { - r:1 = reg3_3 & A; - setResultFlags(r); + local result = reg3_3 & A; + setResultFlags(result); $(H_flag)=1; - setParity(r); + setParity(result); $(N_flag)=0; $(C_flag)=0; } @@ -1973,37 +2145,40 @@ if (DECOMPILE_MODE) goto ; :TST hlMem8 is op0_8=0xed; op0_8=0x34 & hlMem8 { val:1 = 0; MemRead(val,HL); - r:1 = val & A; - setResultFlags(r); + + local result = val & A; + setResultFlags(result); $(H_flag)=1; - setParity(r); + setParity(result); $(N_flag)=0; $(C_flag)=0; } :TST imm8 is op0_8=0xed; op0_8=0x64; imm8 { - r:1 = imm8 & A; - setResultFlags(r); + val:1 = imm8 & A; + setResultFlags(val); $(H_flag)=1; - setParity(r); + setParity(val); $(N_flag)=0; $(C_flag)=0; } :IN0 Flag,IOAddr8 is op0_8=0xed; op6_2=0x0 & bits3_3=0x6 & Flag & bits0_3=0x0; IOAddr8 { - r:1 = 0; - ioRead(IOAddr8,r); # read input location - setResultFlags(r); + val:1 = 0; + ioRead(IOAddr8,val); # read input location + setResultFlags(val); $(H_flag)=0; - setParity(r); + setParity(val); $(N_flag)=0; } :IN0 reg3_3,IOAddr8 is op0_8=0xed; op6_2=0x0 & reg3_3 & bits0_3=0x0; IOAddr8 { - ioRead(IOAddr8,reg3_3); # read input location - setResultFlags(reg3_3); + local r_temp = reg3_3; + ioRead(IOAddr8,r_temp); # read input location + reg3_3 = r_temp; + setResultFlags(r_temp); $(H_flag)=0; - setParity(reg3_3); + setParity(r_temp); $(N_flag)=0; } @@ -2012,37 +2187,42 @@ if (DECOMPILE_MODE) goto ; } :OTDM is op0_8=0xed; op0_8=0x8b & hlMem8 & IOAddrC { - r:1 = hlMem8; - ioWrite(IOAddrC, r); + val:1 = hlMem8; + ioWrite(IOAddrC, val); HL = HL - 1; C = C - 1; - setSubtractFlags(B,1); # ?? sets $(C_flag) based upon B-1 ?? - B = B - 1; - setResultFlags(B); + local test = B; + setSubtractFlags(test,1); # ?? sets $(C_flag) based upon B-1 ?? + test = test - 1; + B = test; + setResultFlags(test); # P_flag = parity(r); - $(PV_flag) = (r s< 0); + $(PV_flag) = (val s< 0); } :OTDMR is op0_8=0xed; op0_8=0x9b & hlMem8 & IOAddrC { - r:1 = hlMem8; - ioWrite(IOAddrC, r); + local test = B - 1; + B = test; + val:1 = hlMem8; + ioWrite(IOAddrC, val); HL = HL - 1; C = C - 1; - B = B - 1; - if (B != 0) goto inst_start; + + if (test != 0) goto inst_start; + $(S_flag)=0; $(Z_flag)=1; $(H_flag) = 0; # $(PV_flag)=1; - $(PV_flag) = (r s< 0); # based upon last output byte + $(PV_flag) = (val s< 0); # based upon last output byte $(C_flag)=0; } :TSTIO IOAddr8 is op0_8=0xed; op0_8=0x74; IOAddr8 { - v:1 = 0; - ioRead(IOAddr8,v); - r:1 = A & v; - setResultFlags(r); + val:1 = 0; + ioRead(IOAddr8,val); + local result = A & val; + setResultFlags(result); $(H_flag) = 1; # P_flag = parity(v); $(N_flag) = 0; @@ -2050,32 +2230,37 @@ if (DECOMPILE_MODE) goto ; } :OTIM is op0_8=0xed; op0_8=0x83 & hlMem8 & IOAddrC { - r:1 = hlMem8; - ioWrite(IOAddrC, r); + val:1 = hlMem8; + ioWrite(IOAddrC, val); HL = HL + 1; C = C + 1; - setSubtractFlags(B,1); # ?? sets $(C_flag) based upon B-1 ?? - B = B - 1; - setResultFlags(B); + local test = B; + setSubtractFlags(test,1); # ?? sets $(C_flag) based upon B-1 ?? + test = test - 1; + B = test; + setResultFlags(test); $(H_flag) = 1; # P_flag = parity(r); - $(PV_flag) = (r s< 0); + $(PV_flag) = (val s< 0); $(N_flag) = 0; $(C_flag)=0; } :OTIMR is op0_8=0xed; op0_8=0x93 & hlMem8 & IOAddrC { - r:1 = hlMem8; - ioWrite(IOAddrC, r); + val:1 = hlMem8; + local test = B - 1; + B = test; + ioWrite(IOAddrC, val); HL = HL - 1; C = C + 1; - B = B - 1; - if (B != 0) goto inst_start; + + if (test != 0) goto inst_start; + $(S_flag)=0; $(Z_flag)=1; $(H_flag) = 0; # $(PV_flag)=1; - $(PV_flag) = (r s< 0); # based upon last output byte + $(PV_flag) = (val s< 0); # based upon last output byte $(C_flag)=0; } @@ -2088,25 +2273,10 @@ if (DECOMPILE_MODE) goto ; # Undocumented instructions # information taken from https://clrhome.org/table -@if defined(Z180) +@ifndef Z180 # Bad support on Z180 -@else - -define token opbyte_ex (8) - bits2 = (2,2) -; - -define register offset=0x46 size=1 [ IXL IXH IYL IYH ]; # Undocumented registers - -#:NEG is op0_8=0xed; (op0_8=0x4c)|(op0_8=0x5c) { -# A_temp:1 = A; -# -# A = -A; -# subtractionFlags(0, A_temp); -# setResultFlags(A); -#} :IM 0 is op0_8=0xed; op0_8=0x4e { setInterruptMode(0:1); @@ -2120,11 +2290,13 @@ define register offset=0x46 size=1 [ IXL IXH IYL IYH ]; # Undocumented registers # CB range :SLL reg0_3 is op0_8=0x0cb; op6_2=0x0 & bits3_3=0x6 & reg0_3 { - $(C_flag) = (reg0_3 >> 7); - reg0_3 = ((reg0_3 << 1) | 0x01) & 0xff; - setResultFlags(reg0_3); + local r_temp = reg0_3; + $(C_flag) = (r_temp >> 7); + r_temp = (r_temp << 1) | 0x01; + reg0_3 = r_temp; + setResultFlags(r_temp); $(H_flag) = 0; - setParity(reg0_3); + setParity(r_temp); $(N_flag) = 0; } @@ -2132,7 +2304,7 @@ define register offset=0x46 size=1 [ IXL IXH IYL IYH ]; # Undocumented registers val:1 = 0; MemRead(val,HL); $(C_flag) = (val >> 7); - val = (val << 1 | 0x01) & 0xff; + val = val << 1 | 0x01; setResultFlags(val); MemStore(HL,val); $(H_flag) = 0; @@ -2148,35 +2320,35 @@ ixl_iyl: IXL is op0_8=0xdd & IXL { export IXL; } ixl_iyl: IYL is op0_8=0xfd & IYL { export IYL; } :INC ixh_iyh is ixh_iyh; op0_8=0x24 { - local r_temp = ixh_iyh; - - ixh_iyh = r_temp + 1; - setResultFlags(ixh_iyh); - additionFlags(r_temp, 1); + local val = ixh_iyh; + additionFlags(val, 1); + val = val + 1; + ixh_iyh = val; + setResultFlags(val); } :DEC ixh_iyh is ixh_iyh; op0_8=0x25 { - local r_temp = ixh_iyh; - - ixh_iyh = r_temp - 1; - setResultFlags(ixh_iyh); - additionFlags(r_temp, 1); + local val = ixh_iyh; + subtractionFlagsNoC(val, 1); + val = val - 1; + ixh_iyh = val ; + setResultFlags(val); } :INC ixl_iyl is ixl_iyl; op0_8=0x2c { - local r_temp = ixl_iyl; - - ixl_iyl = r_temp + 1; - setResultFlags(ixl_iyl); - additionFlags(r_temp, 1); + local val = ixl_iyl; + additionFlags(val, 1); + val = val + 1; + ixl_iyl = val; + setResultFlags(val); } :DEC ixl_iyl is ixl_iyl; op0_8=0x2d { - local r_temp = ixl_iyl; - - ixl_iyl = r_temp - 1; - setResultFlags(ixl_iyl); - additionFlags(r_temp, 1); + local val = ixl_iyl; + subtractionFlagsNoC(val, 1); + val = val - 1; + ixl_iyl = val; + setResultFlags(val); } :LD ixh_iyh,imm8 is ixh_iyh; op0_8=0x26; imm8 { @@ -2252,122 +2424,158 @@ ixl_iyl: IYL is op0_8=0xfd & IYL { export IYL; } } :ADD A, ixh_iyh is ixh_iyh; op0_8=0x84 & A { - local A_temp = A; - local reg_temp = ixh_iyh; - - A = A + ixh_iyh; - setResultFlags(A); - additionFlags(A_temp, reg_temp); + local a_temp = A; + local val = ixh_iyh; + + additionFlags(a_temp, val); + a_temp = a_temp + val; + setResultFlags(a_temp); + A = a_temp; } :ADD A, ixl_iyl is ixl_iyl; op0_8=0x85 & A { - local A_temp = A; - local reg_temp = ixl_iyl; - - A = A + ixl_iyl; - setResultFlags(A); - additionFlags(A_temp, reg_temp); + local a_temp = A; + local val = ixl_iyl; + + additionFlags(a_temp, val); + a_temp = a_temp + val; + setResultFlags(a_temp); + A = a_temp; } :ADC A, ixh_iyh is ixh_iyh; op0_8=0x8c & A { - additionWithCarry(A, ixh_iyh, A); - setResultFlags(A); + local a_temp = A; + local val = ixh_iyh; + + additionWithCarry(a_temp, val, a_temp); + setResultFlags(a_temp); + A = a_temp; } :ADC A, ixl_iyl is ixl_iyl; op0_8=0x8d & A { - additionWithCarry(A, ixl_iyl, A); - setResultFlags(A); + local a_temp = A; + local val = ixl_iyl; + + additionWithCarry(a_temp, val, a_temp); + setResultFlags(a_temp); + A = a_temp; } :SUB ixh_iyh is ixh_iyh; op0_8=0x94 { - local A_temp = A; - - A = A - ixh_iyh; - subtractionFlags(A_temp, ixh_iyh); - setResultFlags(A); + local a_temp = A; + local val = ixh_iyh; + + subtractionFlags(a_temp, val); + a_temp = a_temp - val; + setResultFlags(a_temp); + A = a_temp; } :SUB ixl_iyl is ixl_iyl; op0_8=0x95 { - local A_temp = A; - - A = A - ixl_iyl; - subtractionFlags(A_temp, ixl_iyl); - setResultFlags(A); + local a_temp = A; + local val = ixl_iyl; + + subtractionFlags(a_temp, val); + a_temp = a_temp - val; + setResultFlags(a_temp); + A = a_temp; } :SBC A, ixh_iyh is ixh_iyh; op0_8=0x9c & A { - subtractionWithCarry(A, ixh_iyh, A); + local a_temp = A; + subtractionWithCarry(a_temp, ixh_iyh, a_temp); setResultFlags(A); + A = a_temp; } :SBC A, ixl_iyl is ixl_iyl; op0_8=0x9d & A { - subtractionWithCarry(A, ixl_iyl, A); - setResultFlags(A); + local a_temp = A; + subtractionWithCarry(a_temp, ixl_iyl, a_temp); + setResultFlags(a_temp); + A = a_temp; } :AND ixh_iyh is ixh_iyh; op0_8=0xa4 { + local a_temp = A; $(H_flag) = 1; $(C_flag) = 0; $(N_flag) = 0; - A = A & ixh_iyh; - setResultFlags(A); - setParity(A); + a_temp = a_temp & ixh_iyh; + setResultFlags(a_temp); + setParity(a_temp); + A = a_temp; } :AND ixl_iyl is ixl_iyl; op0_8=0xa5 { + local a_temp = A; $(H_flag) = 1; $(C_flag) = 0; $(N_flag) = 0; - A = A & ixl_iyl; - setResultFlags(A); - setParity(A); + a_temp = a_temp & ixl_iyl; + setResultFlags(a_temp); + setParity(a_temp); + A = a_temp; } :XOR ixh_iyh is ixh_iyh; op0_8=0xac { + local a_temp = A; $(H_flag) = 0; $(C_flag) = 0; $(N_flag) = 0; - A = A ^ ixh_iyh; - setResultFlags(A); - setParity(A); + a_temp = a_temp ^ ixh_iyh; + setResultFlags(a_temp); + setParity(a_temp); + A = a_temp; } :XOR ixl_iyl is ixl_iyl; op0_8=0xad { + local a_temp = A; $(H_flag) = 0; $(C_flag) = 0; $(N_flag) = 0; - A = A ^ ixl_iyl; - setResultFlags(A); - setParity(A); + a_temp = a_temp ^ ixl_iyl; + setResultFlags(a_temp); + setParity(a_temp); + A = a_temp; } :OR ixh_iyh is ixh_iyh; op0_8=0xb4 { + local a_temp = A; $(H_flag) = 0; $(C_flag) = 0; $(N_flag) = 0; - A = A | ixh_iyh; - setResultFlags(A); - setParity(A); + a_temp = a_temp | ixh_iyh; + setResultFlags(a_temp); + setParity(a_temp); + A = a_temp; } :OR ixl_iyl is ixl_iyl; op0_8=0xb5 { + local a_temp = A; $(H_flag) = 0; $(C_flag) = 0; $(N_flag) = 0; - A = A | ixl_iyl; - setResultFlags(A); - setParity(A); + a_temp = a_temp | ixl_iyl; + setResultFlags(a_temp); + setParity(a_temp); + A = a_temp; } :CP ixh_iyh is ixh_iyh; op0_8=0xbc { - cmp:1 = A - ixh_iyh; - subtractionFlags(A, ixh_iyh); + local a_temp = A; + local r_temp = ixh_iyh; + + cmp:1 = a_temp - r_temp; + subtractionFlags(a_temp, r_temp); setResultFlags(cmp); } :CP ixl_iyl is ixl_iyl; op0_8=0xbd { - cmp:1 = A - ixl_iyl; - subtractionFlags(A, ixl_iyl); + local a_temp = A; + local r_temp = ixl_iyl; + + cmp:1 = a_temp - r_temp; + subtractionFlags(a_temp, r_temp); setResultFlags(cmp); }