From 96a889920432cbc2f3c51d302a901d427b6ce040 Mon Sep 17 00:00:00 2001 From: Preston Skupinski Date: Sun, 1 May 2011 16:52:48 -0400 Subject: [PATCH] added LDA direct page indirect (0xb2) --- cpu.js | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/cpu.js b/cpu.js index 4f52524..9593aae 100644 --- a/cpu.js +++ b/cpu.js @@ -48,7 +48,9 @@ function CPU_65816() { 0x58 : CLI, 0xc2 : REP, 0xe2 : SEP, 0xa9 : LDA_const, 0xad : LDA_absolute, 0xa5 : LDA_direct_page, 0xbd : LDA_absolute_indexed_x, - 0xb9 : LDA_absolute_indexed_y, 0xa2 : LDX_const, + 0xb9 : LDA_absolute_indexed_y, + 0xb2 : LDA_direct_page_indirect, + 0xa2 : LDX_const, 0xae : LDX_absolute, 0xa6 : LDX_direct_page, 0xa0 : LDY_const, 0xbc : LDY_absolute_indexed_x, 0xb4 : LDY_direct_page_indexed_x, @@ -306,6 +308,31 @@ var STZ_direct_page_indexed_x = { } }; +var LDA_direct_page_indirect = { + bytes_required:function() { + return 2; + }, + execute:function(cpu, bytes) { + var location = bytes[0] + cpu.r.d; + if(cpu.p.m===1) { + var low_byte_loc = cpu.mmu.read_byte(location); + var high_byte_loc = cpu.mmu.read_byte(location+1); + cpu.r.a = cpu.mmu.read_byte(high_byte_loc | low_byte_loc); + } else { + 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; + var low_byte = cpu.mmu.read_byte(absolute_location); + var high_byte = cpu.mmu.read_byte(absolute_location+1); + cpu.r.a = high_byte | low_byte; + } + if(cpu.r.a===0) { + cpu.p.z = 1; + } + // TODO: set the n bit of the p status register + } +}; + var LDA_direct_page_indexed_x = { bytes_required:function() { return 2;