From 4a9456f83fd512503d7d0d3edad8dcea95b415c0 Mon Sep 17 00:00:00 2001 From: Preston Skupinski Date: Mon, 11 Jul 2011 19:04:51 -0400 Subject: [PATCH] added a reset function --- cpu.js | 17 ++++++++++++++++- index.html | 2 +- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/cpu.js b/cpu.js index e7fef77..012069b 100644 --- a/cpu.js +++ b/cpu.js @@ -251,7 +251,8 @@ function CPU_65816() { this.execute = function(raw_hex, has_header) { this.mmu.load_rom(raw_hex); this.r.pc = 0x8000; - + + // Skip the header(the first 512 bytes) if there is one present for now. if(has_header) { this.r.pc += 4096; } @@ -366,6 +367,15 @@ function CPU_65816() { executing = false; } }; + + this.reset = function() { + this.waiting = false; + this.stopped = false; + this.interrupt = this.INTERRUPT.NO_INTERRUPT; + this.r = { a:0, b:0, x:0, y:0, d:0, s:0xff, pc:0, dbr:0, k:0 }; + this.p = { e:1, c:0, z:0, i:0, d:0, x:0, m:0, v:0, n:0 }; + this.mmu.reset(); + }; } var MMU = { @@ -373,6 +383,11 @@ var MMU = { memory: { 0: {} }, memory_mapped_io_devices: {}, + reset: function() { + this.memory ={ 0: {} }; + this.memory_mapped_io_devices = {}; + }, + add_memory_mapped_io_device: function(write_callback, read_callback, bank, location) { if(typeof this.memory_mapped_io_devices[bank] === 'undefined') { diff --git a/index.html b/index.html index a1a661d..74341bb 100644 --- a/index.html +++ b/index.html @@ -13,7 +13,7 @@ $(document).ready(function() { updateFields(); }); $("#reset").click(function() { - cpu = new CPU_65816(); + cpu.reset(); $("#hex").val(""); updateFields(); });