diff --git a/cpu.js b/cpu.js index d0715e7..e17b1c0 100755 --- a/cpu.js +++ b/cpu.js @@ -109,6 +109,31 @@ var cpu_lib = { } }; }, + Direct_page_indirect_long: function(instruction) { + this.bytes_required = function() { + return 2; + }; + + this.execute = function(cpu, bytes) { + cpu.cycle_count+=4; + + if((cpu.r.d&0xff)!==0) + cpu.cycle_count++; + + var memory_location = bytes[0] + cpu.r.d, + bank_byte = cpu.mmu.read_byte(memory_location+2), + absolute_location = cpu.mmu.read_word(memory_location); + if(cpu.p.e||cpu.p.m) { + instruction.execute(cpu, [cpu.mmu.read_byte_long(absolute_location, + bank_byte)]); + } else { + instruction.execute(cpu, [cpu.mmu.read_byte_long(absolute_location, + bank_byte), + cpu.mmu.read_byte_long(absolute_location+1, + bank_byte)]); + } + }; + }, Absolute: function(instruction) { this.bytes_required = function() { return 3; @@ -1440,29 +1465,8 @@ var EOR_direct_page_indirect_long_indexed_y = { } }; -var EOR_direct_page_indirect_long = { - bytes_required:function() { - return 2; - }, - execute:function(cpu, bytes) { - cpu.cycle_count+=4; - - if((cpu.r.d&0xff)!==0) - cpu.cycle_count++; - - var memory_location = bytes[0] + cpu.r.d, - bank_byte = cpu.mmu.read_byte(memory_location+2), - absolute_location = cpu.mmu.read_word(memory_location); - if(cpu.p.e||cpu.p.m) { - EOR_const.execute(cpu, [cpu.mmu.read_byte_long(absolute_location, - bank_byte)]); - } else { - var low_byte = cpu.mmu.read_byte_long(absolute_location, bank_byte), - high_byte = cpu.mmu.read_byte_long(absolute_location+1, bank_byte); - EOR_const.execute(cpu, [low_byte, high_byte]); - } - } -}; +var EOR_direct_page_indirect_long = + new cpu_lib.addressing.Direct_page_indirect_long(EOR_const); var EOR_direct_page_indirect_indexed_y = { bytes_required:function() { @@ -1545,29 +1549,8 @@ var ORA_direct_page_indirect = var ORA_direct_page_indexed_x_indirect = new cpu_lib.addressing.Direct_page_indexed_x_indirect(ORA_const); -var ORA_direct_page_indirect_long = { - bytes_required:function() { - return 2; - }, - execute:function(cpu, bytes) { - cpu.cycle_count+=4; - - if((cpu.r.d&0xff)!==0) - cpu.cycle_count++; - - var memory_location = bytes[0] + cpu.r.d, - bank_byte = cpu.mmu.read_byte(memory_location+2), - absolute_location = cpu.mmu.read_word(memory_location); - if(cpu.p.e||cpu.p.m) { - ORA_const.execute(cpu, [cpu.mmu.read_byte_long(absolute_location, - bank_byte)]); - } else { - var low_byte = cpu.mmu.read_byte_long(absolute_location, bank_byte), - high_byte = cpu.mmu.read_byte_long(absolute_location+1, bank_byte); - ORA_const.execute(cpu, [low_byte, high_byte]); - } - } -}; +var ORA_direct_page_indirect_long = + new cpu_lib.addressing.Direct_page_indirect_long(ORA_const); var ORA_direct_page_indirect_long_indexed_y = { bytes_required:function() { @@ -1682,29 +1665,8 @@ var AND_direct_page_indirect = var AND_direct_page_indexed_x_indirect = new cpu_lib.addressing.Direct_page_indexed_x_indirect(AND_const); -var AND_direct_page_indirect_long = { - bytes_required:function() { - return 2; - }, - execute:function(cpu, bytes) { - cpu.cycle_count+=4; - - if((cpu.r.d&0xff)!==0) - cpu.cycle_count++; - - var memory_location = bytes[0] + cpu.r.d, - bank_byte = cpu.mmu.read_byte(memory_location+2), - absolute_location = cpu.mmu.read_word(memory_location); - if(cpu.p.e||cpu.p.m) { - AND_const.execute(cpu, [cpu.mmu.read_byte_long(absolute_location, - bank_byte)]); - } else { - var low_byte = cpu.mmu.read_byte_long(absolute_location, bank_byte); - var high_byte = cpu.mmu.read_byte_long(absolute_location+1, bank_byte); - AND_const.execute(cpu, [low_byte, high_byte]); - } - } -}; +var AND_direct_page_indirect_long = + new cpu_lib.addressing.Direct_page_indirect_long(AND_const); var AND_direct_page_indirect_long_indexed_y = { bytes_required:function() { @@ -1912,29 +1874,8 @@ var CMP_direct_page_indirect = var CMP_direct_page_indexed_x_indirect = new cpu_lib.addressing.Direct_page_indexed_x_indirect(CMP_const); -var CMP_direct_page_indirect_long = { - bytes_required:function() { - return 2; - }, - execute:function(cpu, bytes) { - cpu.cycle_count+=4; - - if((cpu.r.d&0xff)!==0) - cpu.cycle_count++; - - var memory_location = bytes[0] + cpu.r.d, - bank_byte = cpu.mmu.read_byte(memory_location+2), - absolute_location = cpu.mmu.read_word(memory_location); - if(cpu.p.e||cpu.p.m) { - CMP_const.execute(cpu, [cpu.mmu.read_byte_long(absolute_location, - bank_byte)]); - } else { - var low_byte = cpu.mmu.read_byte_long(absolute_location, bank_byte), - high_byte = cpu.mmu.read_byte_long(absolute_location+1, bank_byte); - CMP_const.execute(cpu, [low_byte, high_byte]); - } - } -}; +var CMP_direct_page_indirect_long = + new cpu_lib.addressing.Direct_page_indirect_long(CMP_const); var CMP_direct_page_indirect_long_indexed_y = { bytes_required:function() { @@ -2148,29 +2089,8 @@ var SBC_absolute_long_indexed_x = var SBC_direct_page_indexed_x_indirect = new cpu_lib.addressing.Direct_page_indexed_x_indirect(SBC_const); -var SBC_direct_page_indirect_long = { - bytes_required:function() { - return 2; - }, - execute:function(cpu, bytes) { - cpu.cycle_count+=4; - - if((cpu.r.d&0xff)!==0) - cpu.cycle_count++; - - var memory_location = bytes[0] + cpu.r.d, - bank_byte = cpu.mmu.read_byte(memory_location+2), - absolute_location = cpu.mmu.read_word(memory_location); - if(cpu.p.e||cpu.p.m) { - SBC_const.execute(cpu, [cpu.mmu.read_byte_long(absolute_location, - bank_byte)]); - } else { - var low_byte = cpu.mmu.read_byte_long(absolute_location, bank_byte), - high_byte = cpu.mmu.read_byte_long(absolute_location+1, bank_byte); - SBC_const.execute(cpu, [low_byte, high_byte]); - } - } -}; +var SBC_direct_page_indirect_long = + new cpu_lib.addressing.Direct_page_indirect_long(SBC_const); var SBC_direct_page_indirect_long_indexed_y = { bytes_required:function() { @@ -2407,29 +2327,8 @@ var ADC_direct_page_indirect_long_indexed_y = { } }; -var ADC_direct_page_indirect_long = { - bytes_required:function() { - return 2; - }, - execute:function(cpu, bytes) { - if((cpu.r.d&0x00ff)!==0) - cpu.cycle_count+=5; - else - cpu.cycle_count+=4; - - var memory_location = bytes[0] + cpu.r.d, - bank_byte = cpu.mmu.read_byte(memory_location+2), - absolute_location = cpu.mmu.read_word(memory_location); - if(cpu.p.e||cpu.p.m) { - ADC_const.execute(cpu, [cpu.mmu.read_byte_long(absolute_location, - bank_byte)]); - } else { - var low_byte = cpu.mmu.read_byte_long(absolute_location, bank_byte), - high_byte = cpu.mmu.read_byte_long(absolute_location+1, bank_byte); - ADC_const.execute(cpu, [low_byte, high_byte]); - } - } -}; +var ADC_direct_page_indirect_long = + new cpu_lib.addressing.Direct_page_indirect_long(ADC_const); var ADC_direct_page_indirect_indexed_y = { bytes_required:function() { @@ -3304,33 +3203,8 @@ var STA_stack_relative_indirect_indexed_y = { var LDA_direct_page_indexed_x_indirect = new cpu_lib.addressing.Direct_page_indexed_x_indirect(LDA_const); -var LDA_direct_page_indirect_long = { - bytes_required:function() { - return 2; - }, - execute:function(cpu, bytes) { - cpu.cycle_count+=6; - - if((cpu.r.d&0xff)!==0) - cpu.cycle_count++; - - var memory_location = bytes[0] + cpu.r.d, - bank_byte = cpu.mmu.read_byte(memory_location+2), - absolute_location = cpu.mmu.read_word(memory_location); - - if(cpu.p.e||cpu.p.m) { - cpu.r.a = cpu.mmu.read_byte_long(absolute_location, - bank_byte); - cpu.p.n = cpu.r.a >> 7; - } else { - cpu.cycle_count++; - - cpu.r.a = cpu.mmu.read_word_long(absolute_location, bank_byte); - cpu.p.n = cpu.r.a >> 15; - } - cpu_lib.r.p.check_z(cpu, cpu.r.a); - } -}; +var LDA_direct_page_indirect_long = + new cpu_lib.addressing.Direct_page_indirect_long(LDA_const); var LDA_direct_page_indirect_long_indexed_y = { bytes_required:function() {