added ADC direct page indirect

This commit is contained in:
Preston Skupinski 2011-05-07 14:37:29 -04:00
parent 1f127547e1
commit 47766a6b0d
2 changed files with 58 additions and 7 deletions

29
cpu.js
View File

@ -81,7 +81,7 @@ function CPU_65816() {
0xf0 : BEQ, 0xd0 : BNE, 0x90 : BCC, 0xb0 : BCS,
0x50 : BVC, 0x70 : BVS, 0x10 : BPL, 0x30 : BMI,
0x69 : ADC_const, 0x6d : ADC_absolute,
0x65 : ADC_direct_page };
0x65 : ADC_direct_page, 0x72 : ADC_direct_page_indirect };
}
var MMU = {
@ -130,7 +130,6 @@ var ADC_const = {
}
},
execute:function(cpu, bytes) {
// TODO: Signed overflow checking.
if(cpu.p.m) {
var old_a = cpu.r.a;
cpu.r.a += bytes[0] + cpu.p.c;
@ -201,16 +200,36 @@ var ADC_direct_page = {
return 2;
},
execute:function(cpu, bytes) {
var location = bytes[0] + cpu.r.d;
if(cpu.p.m) {
ADC_const.execute(cpu, [cpu.mmu.read_byte(bytes[0])]);
ADC_const.execute(cpu, [cpu.mmu.read_byte(location)]);
} else {
var low_byte = cpu.mmu.read_byte(bytes[0]);
var high_byte = cpu.mmu.read_byte(bytes[0]+1);
var low_byte = cpu.mmu.read_byte(location);
var high_byte = cpu.mmu.read_byte(location+1);
ADC_const.execute(cpu, [low_byte, high_byte]);
}
}
};
var ADC_direct_page_indirect = {
bytes_required:function() {
return 2;
},
execute:function(cpu, bytes) {
var location = bytes[0] + cpu.r.d;
var low_byte_loc = cpu.mmu.read_byte(location);
var high_byte_loc = cpu.mmu.read_byte(location+1);
var absolute_location = high_byte_loc | low_byte_loc;
if(cpu.p.m) {
ADC_const.execute(cpu, [cpu.mmu.read_byte(absolute_location)]);
} else {
var low_byte = cpu.mmu.read_byte(absolute_location);
var high_byte = cpu.mmu.read_byte(absolute_location+1);
ADC_const.execute(cpu, [low_byte, high_byte]);
}
}
};
var BMI = {
bytes_required:function() {
return 2;

View File

@ -132,7 +132,7 @@ function test_adc() {
test("Test ADC direct page with 16-bit numbers (m bit is 0)", function() {
var cpu = new CPU_65816();
cpu.execute("18fb18c230a9010085ffa9ff7f65ff")
cpu.execute("18fb18c230a9010085fea9ff7f65fe");
equals(cpu.r.a, 0x8000, "0x7fff + 0x0001 should result in 0x8000 when "+
"using ADC");
equals(cpu.p.v, 1, "0x7fff + 0x0001 should set the overflow(v) bit when "+
@ -162,7 +162,7 @@ function test_adc() {
test("Test ADC absolute with 16-bit numbers (m bit is 0)", function() {
var cpu = new CPU_65816();
cpu.execute("18fb18c230a901008dffffa9ff7f6dffff")
cpu.execute("18fb18c230a901008dffffa9ff7f6dffff");
equals(cpu.r.a, 0x8000, "0x7fff + 0x0001 should result in 0x8000 when "+
"using ADC");
equals(cpu.p.v, 1, "0x7fff + 0x0001 should set the overflow(v) bit when "+
@ -174,6 +174,38 @@ function test_adc() {
equals(cpu.p.n, 1, "0x7fff + 0x0001 should set the negative(n) bit when "+
"using ADC");
});
test("Test ADC direct page indirect with 8-bit numbers (m bit is 1)",
function() {
var cpu = new CPU_65816();
cpu.execute("18fb18e230a90185ffa9ff85fd64fea97f72fd");
equals(cpu.r.a, 0x80, "0x7f + 0x01 should result in 0x80 when "+
"using ADC");
equals(cpu.p.v, 1, "0x7f + 0x01 should set the overflow(v) bit when "+
"using ADC");
equals(cpu.p.c, 0, "0x7f + 0x01 should not set the carry(c) bit when "+
"using ADC");
equals(cpu.p.z, 0, "0x7f + 0x01 should not set the zero(z) bit when "+
"using ADC");
equals(cpu.p.n, 1, "0x7f + 0x01 should set the negative(n) bit when "+
"using ADC");
});
test("Test ADC direct page indirect with 16-bit numbers (m bit is 0)",
function() {
var cpu = new CPU_65816();
cpu.execute("18fb18c230a901008500a9000085bba9ff7f72bb");
equals(cpu.r.a, 0x8000, "0x7fff + 0x0001 should result in 0x8000 when "+
"using ADC");
equals(cpu.p.v, 1, "0x7fff + 0x0001 should set the overflow(v) bit when "+
"using ADC");
equals(cpu.p.c, 0, "0x7fff + 0x0001 should not set the carry(c) bit when "+
"using ADC");
equals(cpu.p.z, 0, "0x7fff + 0x0001 should not set the zero(z) bit when "+
"using ADC");
equals(cpu.p.n, 1, "0x7fff + 0x0001 should set the negative(n) bit when "+
"using ADC");
});
}
function test_branching() {