From 180b515881f0d24167e19da8210f31288bec061e Mon Sep 17 00:00:00 2001 From: Andrew Ogle Date: Sun, 22 Aug 2021 09:52:45 -0700 Subject: [PATCH] fixed loading bug added reset method --- scripts/cpu.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/scripts/cpu.js b/scripts/cpu.js index 74280fb..60c9e37 100644 --- a/scripts/cpu.js +++ b/scripts/cpu.js @@ -57,11 +57,23 @@ class CPU { } } + reset(){ + this.memory = new Uint8Array(4096); + this.v = new Uint8Array(16); + this.delayTimer = 0; + this.soundTimer = 0; + this.i = 0; + this.pc = 0x200; + this.stack = new Array(); + } + loadProgramIntoMemory(program) { + this.reset() for (let loc = 0; loc < program.length; loc++) { this.memory[0x200 + loc] = program[loc]; } } + loadRom(romName) { var request = new XMLHttpRequest;