/* * 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 Psuedo-Random Number Generator object. function prng() { // --- Private variables. // Memory location for PRNG value. var MEMORY = null; var MEMORY_START = 0; var PRNG_ADDRESS = 0; // --- Public methods. // Attach PRNG to DOM. this.attach = function(newMemory, newStartPosition) { MEMORY = newMemory; MEMORY_START = newStartPosition; PRNG_ADDRESS = MEMORY_START; MEMORY.addReadCallback(PRNG_ADDRESS, PRNG_ADDRESS, null, function(address, value, data){ // On read, change the random value. MEMORY.writeByte(address, Math.floor(Math.random() * 256)); }); }; }