From a3a0b13c6f9fa47bd2f2ac1bdbbd8cbd3d03054d Mon Sep 17 00:00:00 2001 From: Curtis F Kaylor Date: Sun, 27 Sep 2020 13:54:02 -0400 Subject: [PATCH] Fixed setting of carry flag by ADC in decimal mode --- lib6502/lib6502.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib6502/lib6502.c b/lib6502/lib6502.c index 5709825..8eb614b 100644 --- a/lib6502/lib6502.c +++ b/lib6502/lib6502.c @@ -192,12 +192,12 @@ enum { /* inelegant & slow, but consistent with the hw for illegal digits */ \ l= (A & 0x0F) + (B & 0x0F) + getC(); \ h= (A & 0xF0) + (B & 0xF0); \ - if (l >= 0x0A) { l -= 0x0A; h += 0x10; } \ - if (h >= 0xA0) { h -= 0xA0; } \ + if (l >= 0x0A) { l += 0x06; h += 0x10; } \ + if (h >= 0xA0) { h += 0x60; } \ fetch(); \ - s= h | (l & 0x0F); \ + s= (h & 0xF0) | (l & 0x0F); \ /* only C is valid on NMOS 6502 */ \ - setNVZC(s & 0x80, !(((A ^ B) & 0x80) && ((A ^ s) & 0x80)), !s, !!(h & 0x80)); \ + setNVZC(s & 0x80, !(((A ^ B) & 0x80) && ((A ^ s) & 0x80)), (s==0), ((h & 0x100) > 0)); \ A= s; \ tick(1); \ next(); \