DELETED
Moderator: Moderators
I assume you've gleaned all you can from http://www.atarihq.com/danb/files/64doc.txt ?
- Kweepa
- Vic 20 Scientist
- Posts: 1315
- Joined: Fri Jan 04, 2008 5:11 pm
- Location: Austin, Texas
- Occupation: Game maker
Here's the code from JarVIC's MOS6502Core.java (unchanged from jac64).
Don't blame me for the formatting!
Don't blame me for the formatting!
Code: Select all
private final void opADCimp(int data) {
int tmp = data + acc + (carry ? 1 : 0);
zero = (tmp & 0xff) == 0; // not valid in decimal mode
if (decimal) {
tmp = (acc & 0xf) + (data & 0xf) + (carry ? 1 : 0);
if (tmp > 0x9)
tmp += 0x6;
if (tmp <= 0x0f)
tmp = (tmp & 0xf) + (acc & 0xf0) + (data & 0xf0);
else
tmp = (tmp & 0xf) + (acc & 0xf0) + (data & 0xf0) + 0x10;
overflow = (((acc ^ data) & 0x80) == 0) &&
(((acc ^ tmp) & 0x80) != 0);
sign = (tmp & 0x80) > 0;
if ((tmp & 0x1f0) > 0x90)
tmp += 0x60;
carry = tmp > 0x99;
} else {
overflow = (((acc ^ data) & 0x80) == 0) &&
(((acc ^ tmp) & 0x80) != 0);
carry = tmp > 0xff;
sign = (tmp & 0x80) > 0;
}
acc = tmp & 0xff;
}
private final void opSBCimp(int data) {
int tmp = acc - data - (carry ? 0 : 1);
boolean nxtcarry = (tmp >= 0);
tmp = tmp & 0x1ff; // Carry is set!
sign = (tmp & 0x80) == 0x80; // Invalid in decimal mode??
zero = ((tmp & 0xff) == 0);
overflow = (((acc ^ tmp) & 0x80) != 0) && (((acc ^ data) & 0x80) != 0);
if (decimal) {
tmp = (acc & 0xf) - (data & 0xf) - (carry ? 0 : 1);
if ((tmp & 0x10) > 0)
tmp = ((tmp - 6) & 0xf) |
((acc & 0xf0) - (data & 0xf0) - 0x10);
else
tmp = (tmp & 0xf) | ((acc & 0xf0) - (data & 0xf0));
if ((tmp & 0x100) > 0)
tmp -= 0x60;
}
acc = tmp & 0xff;
carry = nxtcarry;
}