gr-sim: fix carry flag in SBC

This commit is contained in:
Vince Weaver 2018-02-14 14:09:54 -05:00
parent ecc4a5bb1c
commit 3b7529991e
2 changed files with 8 additions and 4 deletions

View File

@ -68,9 +68,11 @@ void sbc(int value) {
int temp_value;
temp_a=a&0xff;
temp_value=value&0xff;
temp_value=(~value)&0xff;
result=temp_a-temp_value-(!c);
result=temp_a+temp_value+c;
// printf("SBC: %x - %x (%x) = %x\n",a,value,c,result);
c=(result&0x100)>>8;
n=(result&0x80)>>7;
@ -79,6 +81,8 @@ void sbc(int value) {
a=result&0xff;
z=(a==0);
}
void cmp(int value) {

View File

@ -54,7 +54,7 @@ static void test_sbc(void) {
if (a!=((i-j-0)&0xff)) {
printf("SBC: Error! %d-%d should be %d, not %d\n",i,j,i-j-0,a);
}
if (c!=(((i-j-0)>>8)&0x1)) {
if (c==(((i-j-0)>>8)&0x1)) {
printf("SBC: Error! Carry should be %d, not %d\n",((i-j-0)>>8)&0x1,c);
}
if ((a==0) && (z!=1)) printf("SBC error, zflag wrong\n");
@ -71,7 +71,7 @@ static void test_sbc(void) {
if (a!=((i-j-1)&0xff)) {
printf("SBC: Error! %d-%d should be %d, not %d\n",i,j,i-j-1,a);
}
if (c!=(((i-j-1)>>8)&0x1)) {
if (c==(((i-j-1)>>8)&0x1)) {
printf("SBC: Error! Carry should be %d, not %d\n",((i-j-1)>>8)&0x1,c);
}
if ((a==0) && (z!=1)) printf("SBC error, zflag wrong\n");