diff --git a/cpu.js b/cpu.js index 6f4d7bb..5b73de4 100644 --- a/cpu.js +++ b/cpu.js @@ -127,7 +127,7 @@ function CPU_65816() { 0xda : PHX, 0xfa : PLX, 0x08 : PHP, 0x28 : PLP, 0xf4 : PEA, 0xd4 : PEI, 0x8b : PHB, 0xab : PLB, 0x4b : PHK, 0x0b : PHD, 0x2b : PLD, 0x62 : PER, - 0x20 : JSR, 0x60 : RTS }; + 0x20 : JSR, 0x60 : RTS, 0x22 : JSL, 0x6b : RTL }; /** * Take a raw hex string representing the program and execute it. @@ -206,6 +206,34 @@ var MMU = { } }; +var JSL = { + bytes_required:function() { + return 4; + }, + execute:function(cpu, bytes) { + var location = cpu.r.pc - 1; + var low_byte = location & 0x00ff; + var high_byte = location >> 8; + cpu.mmu.store_byte(cpu.r.s--, cpu.r.pbr); + cpu.mmu.store_byte(cpu.r.s--, high_byte); + cpu.mmu.store_byte(cpu.r.s--, low_byte); + cpu.r.pbr = bytes[2]; + cpu.r.pc = (bytes[1]<<8)|bytes[0]; + } +}; + +var RTL = { + bytes_required:function() { + return 1; + }, + execute:function(cpu) { + var low_byte = cpu.mmu.read_byte(++cpu.r.s); + var high_byte = cpu.mmu.read_byte(++cpu.r.s); + cpu.r.pbr = cpu.mmu.read_byte(++cpu.r.s); + cpu.r.pc = ((high_byte<<8)|low_byte) + 1; + } +}; + var JSR = { bytes_required:function() { return 3;