Firstly, I'm assuming that;
- For add/adc/sub/sbc/cp it represents overflow.
- For and/xor/or it represents parity.
- AND: P/V is reset if overflow; reset otherwise (huh?)
- OR: P/V is set if overflow; reset otherwise
- XOR: P/V is set if parity even; reset otherwise
That moves me on to the real issue; overflow.
I'm currently taking the first operand as an unsigned byte and casting to an int (signed). I then take the second operand (also unsigned byte) and also cast to a signed int. If it's an adc or sbc instruction and the carry flag is set, I increment the second operand. I then either add or subtract the two.
If result < -128 or result > 127, I set the overflow flag.
This is clearly not right. What is the correct behaviour? I'm assuming it's to do with the treatment of signed/unsigned values, and changing these around results in different CRCs (eg using a signed byte first) but they're all still incorrect.
@CoBB: I think I know what you're going to say, but I'd feel better if I understood what was going on here rather than copying and pasting another solution.