diff --git a/cpu.js b/cpu.js index 804d01a..ca114d3 100644 --- a/cpu.js +++ b/cpu.js @@ -80,7 +80,8 @@ function CPU_65816() { 0x6c : JMP_absolute_indirect, 0x80 : BRA, 0xf0 : BEQ, 0xd0 : BNE, 0x90 : BCC, 0xb0 : BCS, 0x50 : BVC, 0x70 : BVS, 0x10 : BPL, 0x30 : BMI, - 0x69 : ADC_const }; + 0x69 : ADC_const, 0x6d : ADC_absolute, + 0x65 : ADC_direct_page }; } var MMU = { @@ -179,6 +180,37 @@ var ADC_const = { } }; +var ADC_absolute = { + bytes_required:function() { + return 3; + }, + execute:function(cpu, bytes) { + var location = (bytes[1]<<8)|bytes[0]; + if(cpu.p.m) { + ADC_const.execute(cpu, [cpu.mmu.read_byte(location)]); + } else { + 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 = { + bytes_required:function() { + return 2; + }, + execute:function(cpu, bytes) { + if(cpu.p.m) { + ADC_const.execute(cpu, [cpu.mmu.read_byte(bytes[0])]); + } else { + var low_byte = cpu.mmu.read_byte(bytes[0]); + var high_byte = cpu.mmu.read_byte(bytes[0]+1); + ADC_const.execute(cpu, [low_byte, high_byte]); + } + } +}; + var BMI = { bytes_required:function() { return 2; diff --git a/test/tests.js b/test/tests.js index b5074b3..4a43b9a 100644 --- a/test/tests.js +++ b/test/tests.js @@ -114,6 +114,66 @@ function test_adc() { equals(cpu.p.n, 1, "0x7fff + 0x0001 should set the negative(n) bit when "+ "using ADC"); }); + + test("Test ADC direct page with 8-bit numbers (m bit is 1)", function() { + var cpu = new CPU_65816(); + cpu.execute("18fb18e230a90185ffa97f65ff"); + 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 with 16-bit numbers (m bit is 0)", function() { + var cpu = new CPU_65816(); + cpu.execute("18fb18c230a9010085ffa9ff7f65ff") + 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"); + }); + + test("Test ADC absolute with 8-bit numbers (m bit is 1)", function() { + var cpu = new CPU_65816(); + cpu.execute("18fb18e230a9018dffffa97f6dffff"); + 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 absolute with 16-bit numbers (m bit is 0)", function() { + var cpu = new CPU_65816(); + 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 "+ + "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() {