Fixed bug in emulation of ADC opcode while in decimal/BCD mode. Thanks

to Thomas Jentzsch for advice on this.


git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@1403 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
stephena 2008-02-23 16:26:29 +00:00
parent e3ee622633
commit 0c15f5daeb
3 changed files with 78 additions and 78 deletions

View File

@ -13,14 +13,14 @@
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: M6502.m4,v 1.4 2005-06-16 01:11:28 stephena Exp $
// $Id: M6502.m4,v 1.5 2008-02-23 16:26:29 stephena Exp $
//============================================================================
/**
Code and cases to emulate each of the 6502 instruction
@author Bradford W. Mott
@version $Id: M6502.m4,v 1.4 2005-06-16 01:11:28 stephena Exp $
@version $Id: M6502.m4,v 1.5 2008-02-23 16:26:29 stephena Exp $
*/
#ifndef NOTSAMEPAGE
@ -29,15 +29,15 @@
define(M6502_ADC, `{
uInt8 oldA = A;
Int16 nonBCDSum = (Int16)A + (Int16)operand + (C ? 1 : 0);
if(!D)
{
Int16 sum = (Int16)((Int8)A) + (Int16)((Int8)operand) + (C ? 1 : 0);
V = ((sum > 127) || (sum < -128));
sum = (Int16)A + (Int16)operand + (C ? 1 : 0);
A = sum;
C = (sum > 0xff);
A = nonBCDSum;
C = (nonBCDSum > 0xff);
notZ = A;
N = A & 0x80;
}
@ -45,9 +45,9 @@ define(M6502_ADC, `{
{
Int16 sum = ourBCDTable[0][A] + ourBCDTable[0][operand] + (C ? 1 : 0);
notZ = nonBCDSum & 0xff; // Z flag calculation ignores D flag
C = (sum > 99);
A = ourBCDTable[1][sum & 0xff];
notZ = A;
N = A & 0x80;
V = ((oldA ^ A) & 0x80) && ((A ^ operand) & 0x80);
}

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: M6502Hi.ins,v 1.2 2005-06-16 01:11:28 stephena Exp $
// $Id: M6502Hi.ins,v 1.3 2008-02-23 16:26:29 stephena Exp $
//============================================================================
/**
@ -21,7 +21,7 @@
high compatibility emulation
@author Bradford W. Mott
@version $Id: M6502Hi.ins,v 1.2 2005-06-16 01:11:28 stephena Exp $
@version $Id: M6502Hi.ins,v 1.3 2008-02-23 16:26:29 stephena Exp $
*/
#ifndef NOTSAMEPAGE
@ -114,14 +114,14 @@
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: M6502Hi.ins,v 1.2 2005-06-16 01:11:28 stephena Exp $
// $Id: M6502Hi.ins,v 1.3 2008-02-23 16:26:29 stephena Exp $
//============================================================================
/**
Code and cases to emulate each of the 6502 instruction
@author Bradford W. Mott
@version $Id: M6502Hi.ins,v 1.2 2005-06-16 01:11:28 stephena Exp $
@version $Id: M6502Hi.ins,v 1.3 2008-02-23 16:26:29 stephena Exp $
*/
#ifndef NOTSAMEPAGE
@ -278,15 +278,15 @@ case 0x69:
}
{
uInt8 oldA = A;
Int16 nonBCDSum = (Int16)A + (Int16)operand + (C ? 1 : 0);
if(!D)
{
Int16 sum = (Int16)((Int8)A) + (Int16)((Int8)operand) + (C ? 1 : 0);
V = ((sum > 127) || (sum < -128));
sum = (Int16)A + (Int16)operand + (C ? 1 : 0);
A = sum;
C = (sum > 0xff);
A = nonBCDSum;
C = (nonBCDSum > 0xff);
notZ = A;
N = A & 0x80;
}
@ -294,9 +294,9 @@ case 0x69:
{
Int16 sum = ourBCDTable[0][A] + ourBCDTable[0][operand] + (C ? 1 : 0);
notZ = nonBCDSum & 0xff; // Z flag calculation ignores D flag
C = (sum > 99);
A = ourBCDTable[1][sum & 0xff];
notZ = A;
N = A & 0x80;
V = ((oldA ^ A) & 0x80) && ((A ^ operand) & 0x80);
}
@ -309,15 +309,15 @@ case 0x65:
}
{
uInt8 oldA = A;
Int16 nonBCDSum = (Int16)A + (Int16)operand + (C ? 1 : 0);
if(!D)
{
Int16 sum = (Int16)((Int8)A) + (Int16)((Int8)operand) + (C ? 1 : 0);
V = ((sum > 127) || (sum < -128));
sum = (Int16)A + (Int16)operand + (C ? 1 : 0);
A = sum;
C = (sum > 0xff);
A = nonBCDSum;
C = (nonBCDSum > 0xff);
notZ = A;
N = A & 0x80;
}
@ -325,9 +325,9 @@ case 0x65:
{
Int16 sum = ourBCDTable[0][A] + ourBCDTable[0][operand] + (C ? 1 : 0);
notZ = nonBCDSum & 0xff; // Z flag calculation ignores D flag
C = (sum > 99);
A = ourBCDTable[1][sum & 0xff];
notZ = A;
N = A & 0x80;
V = ((oldA ^ A) & 0x80) && ((A ^ operand) & 0x80);
}
@ -343,15 +343,15 @@ case 0x75:
}
{
uInt8 oldA = A;
Int16 nonBCDSum = (Int16)A + (Int16)operand + (C ? 1 : 0);
if(!D)
{
Int16 sum = (Int16)((Int8)A) + (Int16)((Int8)operand) + (C ? 1 : 0);
V = ((sum > 127) || (sum < -128));
sum = (Int16)A + (Int16)operand + (C ? 1 : 0);
A = sum;
C = (sum > 0xff);
A = nonBCDSum;
C = (nonBCDSum > 0xff);
notZ = A;
N = A & 0x80;
}
@ -359,9 +359,9 @@ case 0x75:
{
Int16 sum = ourBCDTable[0][A] + ourBCDTable[0][operand] + (C ? 1 : 0);
notZ = nonBCDSum & 0xff; // Z flag calculation ignores D flag
C = (sum > 99);
A = ourBCDTable[1][sum & 0xff];
notZ = A;
N = A & 0x80;
V = ((oldA ^ A) & 0x80) && ((A ^ operand) & 0x80);
}
@ -376,15 +376,15 @@ case 0x6d:
}
{
uInt8 oldA = A;
Int16 nonBCDSum = (Int16)A + (Int16)operand + (C ? 1 : 0);
if(!D)
{
Int16 sum = (Int16)((Int8)A) + (Int16)((Int8)operand) + (C ? 1 : 0);
V = ((sum > 127) || (sum < -128));
sum = (Int16)A + (Int16)operand + (C ? 1 : 0);
A = sum;
C = (sum > 0xff);
A = nonBCDSum;
C = (nonBCDSum > 0xff);
notZ = A;
N = A & 0x80;
}
@ -392,9 +392,9 @@ case 0x6d:
{
Int16 sum = ourBCDTable[0][A] + ourBCDTable[0][operand] + (C ? 1 : 0);
notZ = nonBCDSum & 0xff; // Z flag calculation ignores D flag
C = (sum > 99);
A = ourBCDTable[1][sum & 0xff];
notZ = A;
N = A & 0x80;
V = ((oldA ^ A) & 0x80) && ((A ^ operand) & 0x80);
}
@ -411,15 +411,15 @@ case 0x7d:
}
{
uInt8 oldA = A;
Int16 nonBCDSum = (Int16)A + (Int16)operand + (C ? 1 : 0);
if(!D)
{
Int16 sum = (Int16)((Int8)A) + (Int16)((Int8)operand) + (C ? 1 : 0);
V = ((sum > 127) || (sum < -128));
sum = (Int16)A + (Int16)operand + (C ? 1 : 0);
A = sum;
C = (sum > 0xff);
A = nonBCDSum;
C = (nonBCDSum > 0xff);
notZ = A;
N = A & 0x80;
}
@ -427,9 +427,9 @@ case 0x7d:
{
Int16 sum = ourBCDTable[0][A] + ourBCDTable[0][operand] + (C ? 1 : 0);
notZ = nonBCDSum & 0xff; // Z flag calculation ignores D flag
C = (sum > 99);
A = ourBCDTable[1][sum & 0xff];
notZ = A;
N = A & 0x80;
V = ((oldA ^ A) & 0x80) && ((A ^ operand) & 0x80);
}
@ -446,15 +446,15 @@ case 0x79:
}
{
uInt8 oldA = A;
Int16 nonBCDSum = (Int16)A + (Int16)operand + (C ? 1 : 0);
if(!D)
{
Int16 sum = (Int16)((Int8)A) + (Int16)((Int8)operand) + (C ? 1 : 0);
V = ((sum > 127) || (sum < -128));
sum = (Int16)A + (Int16)operand + (C ? 1 : 0);
A = sum;
C = (sum > 0xff);
A = nonBCDSum;
C = (nonBCDSum > 0xff);
notZ = A;
N = A & 0x80;
}
@ -462,9 +462,9 @@ case 0x79:
{
Int16 sum = ourBCDTable[0][A] + ourBCDTable[0][operand] + (C ? 1 : 0);
notZ = nonBCDSum & 0xff; // Z flag calculation ignores D flag
C = (sum > 99);
A = ourBCDTable[1][sum & 0xff];
notZ = A;
N = A & 0x80;
V = ((oldA ^ A) & 0x80) && ((A ^ operand) & 0x80);
}
@ -482,15 +482,15 @@ case 0x61:
}
{
uInt8 oldA = A;
Int16 nonBCDSum = (Int16)A + (Int16)operand + (C ? 1 : 0);
if(!D)
{
Int16 sum = (Int16)((Int8)A) + (Int16)((Int8)operand) + (C ? 1 : 0);
V = ((sum > 127) || (sum < -128));
sum = (Int16)A + (Int16)operand + (C ? 1 : 0);
A = sum;
C = (sum > 0xff);
A = nonBCDSum;
C = (nonBCDSum > 0xff);
notZ = A;
N = A & 0x80;
}
@ -498,9 +498,9 @@ case 0x61:
{
Int16 sum = ourBCDTable[0][A] + ourBCDTable[0][operand] + (C ? 1 : 0);
notZ = nonBCDSum & 0xff; // Z flag calculation ignores D flag
C = (sum > 99);
A = ourBCDTable[1][sum & 0xff];
notZ = A;
N = A & 0x80;
V = ((oldA ^ A) & 0x80) && ((A ^ operand) & 0x80);
}
@ -518,15 +518,15 @@ case 0x71:
}
{
uInt8 oldA = A;
Int16 nonBCDSum = (Int16)A + (Int16)operand + (C ? 1 : 0);
if(!D)
{
Int16 sum = (Int16)((Int8)A) + (Int16)((Int8)operand) + (C ? 1 : 0);
V = ((sum > 127) || (sum < -128));
sum = (Int16)A + (Int16)operand + (C ? 1 : 0);
A = sum;
C = (sum > 0xff);
A = nonBCDSum;
C = (nonBCDSum > 0xff);
notZ = A;
N = A & 0x80;
}
@ -534,9 +534,9 @@ case 0x71:
{
Int16 sum = ourBCDTable[0][A] + ourBCDTable[0][operand] + (C ? 1 : 0);
notZ = nonBCDSum & 0xff; // Z flag calculation ignores D flag
C = (sum > 99);
A = ourBCDTable[1][sum & 0xff];
notZ = A;
N = A & 0x80;
V = ((oldA ^ A) & 0x80) && ((A ^ operand) & 0x80);
}

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: M6502Low.ins,v 1.4 2006-02-05 02:49:47 stephena Exp $
// $Id: M6502Low.ins,v 1.5 2008-02-23 16:26:29 stephena Exp $
//============================================================================
/**
@ -21,7 +21,7 @@
low compatibility emulation
@author Bradford W. Mott
@version $Id: M6502Low.ins,v 1.4 2006-02-05 02:49:47 stephena Exp $
@version $Id: M6502Low.ins,v 1.5 2008-02-23 16:26:29 stephena Exp $
*/
#ifndef NOTSAMEPAGE
@ -115,14 +115,14 @@
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: M6502Low.ins,v 1.4 2006-02-05 02:49:47 stephena Exp $
// $Id: M6502Low.ins,v 1.5 2008-02-23 16:26:29 stephena Exp $
//============================================================================
/**
Code and cases to emulate each of the 6502 instruction
@author Bradford W. Mott
@version $Id: M6502Low.ins,v 1.4 2006-02-05 02:49:47 stephena Exp $
@version $Id: M6502Low.ins,v 1.5 2008-02-23 16:26:29 stephena Exp $
*/
#ifndef NOTSAMEPAGE
@ -280,15 +280,15 @@ case 0x69:
}
{
uInt8 oldA = A;
Int16 nonBCDSum = (Int16)A + (Int16)operand + (C ? 1 : 0);
if(!D)
{
Int16 sum = (Int16)((Int8)A) + (Int16)((Int8)operand) + (C ? 1 : 0);
V = ((sum > 127) || (sum < -128));
sum = (Int16)A + (Int16)operand + (C ? 1 : 0);
A = sum;
C = (sum > 0xff);
A = nonBCDSum;
C = (nonBCDSum > 0xff);
notZ = A;
N = A & 0x80;
}
@ -296,9 +296,9 @@ case 0x69:
{
Int16 sum = ourBCDTable[0][A] + ourBCDTable[0][operand] + (C ? 1 : 0);
notZ = nonBCDSum & 0xff; // Z flag calculation ignores D flag
C = (sum > 99);
A = ourBCDTable[1][sum & 0xff];
notZ = A;
N = A & 0x80;
V = ((oldA ^ A) & 0x80) && ((A ^ operand) & 0x80);
}
@ -312,15 +312,15 @@ case 0x65:
}
{
uInt8 oldA = A;
Int16 nonBCDSum = (Int16)A + (Int16)operand + (C ? 1 : 0);
if(!D)
{
Int16 sum = (Int16)((Int8)A) + (Int16)((Int8)operand) + (C ? 1 : 0);
V = ((sum > 127) || (sum < -128));
sum = (Int16)A + (Int16)operand + (C ? 1 : 0);
A = sum;
C = (sum > 0xff);
A = nonBCDSum;
C = (nonBCDSum > 0xff);
notZ = A;
N = A & 0x80;
}
@ -328,9 +328,9 @@ case 0x65:
{
Int16 sum = ourBCDTable[0][A] + ourBCDTable[0][operand] + (C ? 1 : 0);
notZ = nonBCDSum & 0xff; // Z flag calculation ignores D flag
C = (sum > 99);
A = ourBCDTable[1][sum & 0xff];
notZ = A;
N = A & 0x80;
V = ((oldA ^ A) & 0x80) && ((A ^ operand) & 0x80);
}
@ -344,15 +344,15 @@ case 0x75:
}
{
uInt8 oldA = A;
Int16 nonBCDSum = (Int16)A + (Int16)operand + (C ? 1 : 0);
if(!D)
{
Int16 sum = (Int16)((Int8)A) + (Int16)((Int8)operand) + (C ? 1 : 0);
V = ((sum > 127) || (sum < -128));
sum = (Int16)A + (Int16)operand + (C ? 1 : 0);
A = sum;
C = (sum > 0xff);
A = nonBCDSum;
C = (nonBCDSum > 0xff);
notZ = A;
N = A & 0x80;
}
@ -360,9 +360,9 @@ case 0x75:
{
Int16 sum = ourBCDTable[0][A] + ourBCDTable[0][operand] + (C ? 1 : 0);
notZ = nonBCDSum & 0xff; // Z flag calculation ignores D flag
C = (sum > 99);
A = ourBCDTable[1][sum & 0xff];
notZ = A;
N = A & 0x80;
V = ((oldA ^ A) & 0x80) && ((A ^ operand) & 0x80);
}
@ -377,15 +377,15 @@ case 0x6d:
}
{
uInt8 oldA = A;
Int16 nonBCDSum = (Int16)A + (Int16)operand + (C ? 1 : 0);
if(!D)
{
Int16 sum = (Int16)((Int8)A) + (Int16)((Int8)operand) + (C ? 1 : 0);
V = ((sum > 127) || (sum < -128));
sum = (Int16)A + (Int16)operand + (C ? 1 : 0);
A = sum;
C = (sum > 0xff);
A = nonBCDSum;
C = (nonBCDSum > 0xff);
notZ = A;
N = A & 0x80;
}
@ -393,9 +393,9 @@ case 0x6d:
{
Int16 sum = ourBCDTable[0][A] + ourBCDTable[0][operand] + (C ? 1 : 0);
notZ = nonBCDSum & 0xff; // Z flag calculation ignores D flag
C = (sum > 99);
A = ourBCDTable[1][sum & 0xff];
notZ = A;
N = A & 0x80;
V = ((oldA ^ A) & 0x80) && ((A ^ operand) & 0x80);
}
@ -418,15 +418,15 @@ case 0x7d:
}
{
uInt8 oldA = A;
Int16 nonBCDSum = (Int16)A + (Int16)operand + (C ? 1 : 0);
if(!D)
{
Int16 sum = (Int16)((Int8)A) + (Int16)((Int8)operand) + (C ? 1 : 0);
V = ((sum > 127) || (sum < -128));
sum = (Int16)A + (Int16)operand + (C ? 1 : 0);
A = sum;
C = (sum > 0xff);
A = nonBCDSum;
C = (nonBCDSum > 0xff);
notZ = A;
N = A & 0x80;
}
@ -434,9 +434,9 @@ case 0x7d:
{
Int16 sum = ourBCDTable[0][A] + ourBCDTable[0][operand] + (C ? 1 : 0);
notZ = nonBCDSum & 0xff; // Z flag calculation ignores D flag
C = (sum > 99);
A = ourBCDTable[1][sum & 0xff];
notZ = A;
N = A & 0x80;
V = ((oldA ^ A) & 0x80) && ((A ^ operand) & 0x80);
}
@ -459,15 +459,15 @@ case 0x79:
}
{
uInt8 oldA = A;
Int16 nonBCDSum = (Int16)A + (Int16)operand + (C ? 1 : 0);
if(!D)
{
Int16 sum = (Int16)((Int8)A) + (Int16)((Int8)operand) + (C ? 1 : 0);
V = ((sum > 127) || (sum < -128));
sum = (Int16)A + (Int16)operand + (C ? 1 : 0);
A = sum;
C = (sum > 0xff);
A = nonBCDSum;
C = (nonBCDSum > 0xff);
notZ = A;
N = A & 0x80;
}
@ -475,9 +475,9 @@ case 0x79:
{
Int16 sum = ourBCDTable[0][A] + ourBCDTable[0][operand] + (C ? 1 : 0);
notZ = nonBCDSum & 0xff; // Z flag calculation ignores D flag
C = (sum > 99);
A = ourBCDTable[1][sum & 0xff];
notZ = A;
N = A & 0x80;
V = ((oldA ^ A) & 0x80) && ((A ^ operand) & 0x80);
}
@ -492,15 +492,15 @@ case 0x61:
}
{
uInt8 oldA = A;
Int16 nonBCDSum = (Int16)A + (Int16)operand + (C ? 1 : 0);
if(!D)
{
Int16 sum = (Int16)((Int8)A) + (Int16)((Int8)operand) + (C ? 1 : 0);
V = ((sum > 127) || (sum < -128));
sum = (Int16)A + (Int16)operand + (C ? 1 : 0);
A = sum;
C = (sum > 0xff);
A = nonBCDSum;
C = (nonBCDSum > 0xff);
notZ = A;
N = A & 0x80;
}
@ -508,9 +508,9 @@ case 0x61:
{
Int16 sum = ourBCDTable[0][A] + ourBCDTable[0][operand] + (C ? 1 : 0);
notZ = nonBCDSum & 0xff; // Z flag calculation ignores D flag
C = (sum > 99);
A = ourBCDTable[1][sum & 0xff];
notZ = A;
N = A & 0x80;
V = ((oldA ^ A) & 0x80) && ((A ^ operand) & 0x80);
}
@ -532,15 +532,15 @@ case 0x71:
}
{
uInt8 oldA = A;
Int16 nonBCDSum = (Int16)A + (Int16)operand + (C ? 1 : 0);
if(!D)
{
Int16 sum = (Int16)((Int8)A) + (Int16)((Int8)operand) + (C ? 1 : 0);
V = ((sum > 127) || (sum < -128));
sum = (Int16)A + (Int16)operand + (C ? 1 : 0);
A = sum;
C = (sum > 0xff);
A = nonBCDSum;
C = (nonBCDSum > 0xff);
notZ = A;
N = A & 0x80;
}
@ -548,9 +548,9 @@ case 0x71:
{
Int16 sum = ourBCDTable[0][A] + ourBCDTable[0][operand] + (C ? 1 : 0);
notZ = nonBCDSum & 0xff; // Z flag calculation ignores D flag
C = (sum > 99);
A = ourBCDTable[1][sum & 0xff];
notZ = A;
N = A & 0x80;
V = ((oldA ^ A) & 0x80) && ((A ^ operand) & 0x80);
}