papapbj0rn wrote:
You are right, it should be CLC, not SEC. I edited my first post.
I wrote the program in hex and translated to the wrong mnemonic for the forum post, sorry.
So, is ~C considered part of the result and thusly why Z:0, not just what is in register A?
There is a bug in the emulator you are using for that particular case, because Z should always match the 8-bit result. So in this case it should be Z:1.
Here's the emulator's SBC code:
Code:
function opSub(oper) {
var r=ac-oper-((flags&fCAR)?0:1),
rb=r&0xff;
if (flags&fDEC) {
var h, c=0,
l=(ac&15)-(oper&15)-((flags&fCAR)?0:1),
h1=(ac>>4)&15,
h2=(oper>>4)&15;
flags &= ~(fCAR|fZER|fOVF|fNEG);
if (l<0) {
l+=10;
c=1;
}
else if (l>9) {
l=(l+6)&15;
}
h=h1-h2-c;
if (h<0) {
h+=10;
flags|=fCAR;
}
else if (h>9) {
h=(h+6)&15;
}
r=(h<<4)|l;
if (r==0) {
flags|=fZER|fCAR;
}
else {
flags|=fCAR;
}
if (r&0x80) flags|=fNEG;
}
else {
flags &= ~(fCAR|fZER|fOVF|fNEG);
if (r==0) {
flags |=fZER|fCAR;
}
else if (r>0) {
flags |=fCAR;
}
flags|=r&0x80;
r=rb;
}
if ((ac^rb)&((0xff-oper)^rb)&0x80) flags|=fOVF;
ac=r;
}
Can you spot what the bug is?
I would not recommend using this emulator as a golden reference!