/* * 6502 Based Virtual Computer * Copyright (C) 2011 Scott C. Duensing * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ // Our Clock object. function clock() { // --- Private variables. // Memory location for PRNG value. var MEMORY = null; var MEMORY_START = 0; var CLOCK_ADDRESS = 0; // Clock values. var MILLISECONDS = 0; var CLOCK = 0; // --- Private methods. var clockTick = function() { MEMORY.writeByte(CLOCK_ADDRESS, CLOCK++); if (CLOCK > 255) CLOCK = 0; setTimeout(function(){ clockTick(); }, MILLISECONDS); }; // --- Public methods. // Attach clock to DOM. this.attach = function(newMemory, newStartPosition, newMilliseconds) { MEMORY = newMemory; MEMORY_START = newStartPosition; CLOCK_ADDRESS = MEMORY_START; MILLISECONDS = newMilliseconds; clockTick(); }; }