From 758d336563ab64a8667f58cd39f933da894f3c05 Mon Sep 17 00:00:00 2001 From: Preston Skupinski Date: Wed, 11 May 2011 20:31:12 -0400 Subject: [PATCH] added emulation mode page one swap wrapping --- cpu.js | 15 +++++++++++++-- test/tests.js | 15 +++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/cpu.js b/cpu.js index 0aab334..73c7794 100644 --- a/cpu.js +++ b/cpu.js @@ -175,11 +175,22 @@ var MMU = { memory: { 0: {} }, pull_byte: function() { - return this.memory[this.cpu.r.dbr][++this.cpu.r.s]; + if(this.cpu.p.e&&(this.cpu.r.s===0x1ff)) { + this.cpu.r.s = 0x100; + return this.memory[this.cpu.r.dbr][this.cpu.r.s]; + } else { + return this.memory[this.cpu.r.dbr][++this.cpu.r.s]; + } }, push_byte: function(b) { - this.memory[this.cpu.r.dbr][this.cpu.r.s--] = b; + if(this.cpu.p.e&&(this.cpu.r.s===0x100)) { + var result = this.memory[this.cpu.r.dbr][this.cpu.r.s]; + this.cpu.r.s = 0x1ff; + return result; + } else { + this.memory[this.cpu.r.dbr][this.cpu.r.s--] = b; + } }, read_byte: function(location) { diff --git a/test/tests.js b/test/tests.js index b997061..97fbe39 100644 --- a/test/tests.js +++ b/test/tests.js @@ -23,9 +23,24 @@ function run_tests() { test_cmp(); test_subroutines(); test_mvn_and_mvp(); + test_emulation_mode(); +} + +function test_emulation_mode() { + module("Emulation Mode"); + test("Make sure pulling from the stack when the stack register is at 0x1ff"+ + "causes the stack register to pull from 0x100.", function() { + var cpu = new CPU_65816(); + cpu.execute("a9fe8d0001a90068"); + equals(cpu.r.s, 0x100, "The stack register should be 0x100 after the "+ + "pull operation."); + equals(cpu.r.a, 0xfe, "The accumulator should be 0xfe after the pull "+ + "operation."); + }); } function test_mvn_and_mvp() { + module("MVN and MVP"); test("Test a short example program for MVP", function() { var cpu = new CPU_65816(); cpu.execute("18fbe230a9ab8dff0fa9cd8d0010c230a90100a20010a00020440000");