handle the carry bit properly when in decimal mode for adc
This commit is contained in:
parent
7cee0a3cd1
commit
b505f7a50d
8
cpu.js
8
cpu.js
|
@ -3620,11 +3620,13 @@ var ADC_const = {
|
|||
ones = bytes[0] & 0x0f;
|
||||
tens = bytes[0] >>4;
|
||||
var dec_arg = (tens*10)+ones;
|
||||
var result = dec_a + dec_arg;
|
||||
var result = dec_a + dec_arg + cpu.p.c;
|
||||
// Check for decimal overflow.
|
||||
if(result>99) {
|
||||
result -= 99;
|
||||
cpu.p.c = 1;
|
||||
} else {
|
||||
cpu.p.c = 0;
|
||||
}
|
||||
var digits = result.toString(10).split("");
|
||||
var i = 0;
|
||||
|
@ -3667,11 +3669,13 @@ var ADC_const = {
|
|||
hundreds = (argument >> 8) & 0xf;
|
||||
thousands = (argument >> 12) & 0xf;
|
||||
var dec_arg = (thousands*1000)+(hundreds*100)+(tens*10)+ones;
|
||||
var result = dec_a + dec_arg;
|
||||
var result = dec_a + dec_arg + cpu.p.c;
|
||||
// Check for decimal overflow.
|
||||
if(result>9999) {
|
||||
result -= 9999;
|
||||
cpu.p.c = 1;
|
||||
} else {
|
||||
cpu.p.c = 0;
|
||||
}
|
||||
var digits = result.toString(10).split("");
|
||||
var i = 0;
|
||||
|
|
|
@ -648,6 +648,23 @@ function test_adc() {
|
|||
equals(cpu.p.e, 0, "The hidden e flag of the p status register should "+
|
||||
"be 0 for native mode.");
|
||||
});
|
||||
test("Test that ADC handles decimal mode with legal BCD numbers in 8-bit "+
|
||||
"memory/accumulator mode with double digit numbers with the carry "+
|
||||
"bit set", function() {
|
||||
var cpu = new CPU_65816();
|
||||
cpu.execute("18fb38f8a9156926");
|
||||
equals(cpu.r.a, 0x42, "0x15 + 0x26 should result in 0x42 with decimal "+
|
||||
"mode on and with 8-bit memory/accumulator mode "+
|
||||
"and the carry bit set.");
|
||||
equals(cpu.p.c, 0, "The carry flag of the p status register should be "+
|
||||
"clear after no decimal overflow.");
|
||||
equals(cpu.p.d, 1, "Decimal mode should be set to 1 in the p status "+
|
||||
"register.");
|
||||
equals(cpu.p.m, 1, "The m flag of the p status register should be 1 for "+
|
||||
"8-bit memory/accumulator mode.");
|
||||
equals(cpu.p.e, 0, "The hidden e flag of the p status register should "+
|
||||
"be 0 for native mode.");
|
||||
});
|
||||
test("Test that ADC handles decimal mode with legal BCD numbers in 8-bit "+
|
||||
"memory/accumulator mode when adding two numbers that cause an "+
|
||||
"overflow.", function() {
|
||||
|
@ -715,6 +732,23 @@ function test_adc() {
|
|||
equals(cpu.p.e, 0, "The hidden e flag of the p status register should "+
|
||||
"be 0 for native mode.");
|
||||
});
|
||||
test("Test that ADC handles decimal mode with legal BCD numbers in 16-bit "+
|
||||
"memory/accumulator mode when adding two four digit numbers with the "+
|
||||
"carry bit set.", function() {
|
||||
var cpu = new CPU_65816();
|
||||
cpu.execute("18fb38f8c220a90110699939");
|
||||
equals(cpu.r.a, 0x5001, "0x1001 + 0x3999 should result in 0x5001 with "+
|
||||
"decimal mode on and with 16-bit "+
|
||||
"memory/accumulator mode and the carry flag set.");
|
||||
equals(cpu.p.c, 0, "The carry flag of the p status register should be "+
|
||||
"clear after no decimal overflow.");
|
||||
equals(cpu.p.d, 1, "Decimal mode should be set to 1 in the p status "+
|
||||
"register.");
|
||||
equals(cpu.p.m, 0, "The m flag of the p status register should be 0 for "+
|
||||
"16-bit memory/accumulator mode.");
|
||||
equals(cpu.p.e, 0, "The hidden e flag of the p status register should "+
|
||||
"be 0 for native mode.");
|
||||
});
|
||||
}
|
||||
|
||||
function test_branching() {
|
||||
|
|
Loading…
Reference in New Issue