104 lines
4.2 KiB
JavaScript
104 lines
4.2 KiB
JavaScript
/*
|
|
* 6502 Based Virtual Computer
|
|
* Copyright (C) 2011 Scott C. Duensing <scott@jaegertech.com>
|
|
*
|
|
* 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.
|
|
*/
|
|
|
|
// Try it out!
|
|
|
|
// Declare components of our computer.
|
|
console.log("Creating components.");
|
|
var computer = {
|
|
memory: new ram(64 * 1024),
|
|
cpu: new cpu6502(),
|
|
monitor: new textDisplayCanvas(),
|
|
keys: new keyboard(),
|
|
random: new prng(),
|
|
timer: new clock()
|
|
};
|
|
console.log("Creating components - success!");
|
|
|
|
|
|
// Memory Map (64k):
|
|
var MM_IRQ_VECTOR = 0xfffe;
|
|
var MM_RESET_VECTOR = 0xfffc;
|
|
var MM_NMI_VECTOR = 0xfffa;
|
|
var MM_CLOCK = 0xfff9;
|
|
var MM_PRNG = 0xfff8;
|
|
var MM_KEYBOARD_META = 0xfff7;
|
|
var MM_KEYBOARD_CHARACTER = 0xfff6;
|
|
var MM_DISPLAY_COMMAND = 0xffa1;
|
|
var MM_DISPLAY_DATA = 0xffa0;
|
|
var MM_DISPLAY_ADAPTER = 0xf000;
|
|
var MM_HEAP_END = 0xefff;
|
|
var MM_HEAP_START = 0x0200;
|
|
var MM_STACK = 0x0100;
|
|
var MM_ZERO_PAGE = 0x0000;
|
|
|
|
|
|
console.log("MM_IRQ_VECTOR = 0x" + MM_IRQ_VECTOR.toString(16));
|
|
console.log("MM_RESET_VECTOR = 0x" + MM_RESET_VECTOR.toString(16));
|
|
console.log("MM_NMI_VECTOR = 0x" + MM_NMI_VECTOR.toString(16));
|
|
console.log("MM_CLOCK = 0x" + MM_CLOCK.toString(16));
|
|
console.log("MM_PRNG = 0x" + MM_PRNG.toString(16));
|
|
console.log("MM_KEYBOARD_META = 0x" + MM_KEYBOARD_META.toString(16));
|
|
console.log("MM_KEYBOARD_CHARACTER = 0x" + MM_KEYBOARD_CHARACTER.toString(16));
|
|
console.log("MM_DISPLAY_COMMAND = 0x" + MM_DISPLAY_COMMAND.toString(16));
|
|
console.log("MM_DISPLAY_DATA = 0x" + MM_DISPLAY_DATA.toString(16));
|
|
console.log("MM_DISPLAY_ADAPTER = 0x" + MM_DISPLAY_ADAPTER.toString(16));
|
|
console.log("MM_HEAP_END = 0x" + MM_HEAP_END.toString(16));
|
|
console.log("MM_HEAP_START = 0x" + MM_HEAP_START.toString(16));
|
|
console.log("MM_STACK = 0x" + MM_STACK.toString(16));
|
|
console.log("MM_ZERO_PAGE = 0x" + MM_ZERO_PAGE.toString(16));
|
|
|
|
// Configure components & connect them together.
|
|
computer.memory.attach("memory");
|
|
computer.cpu.attach(computer.memory, function(event){
|
|
// We don't care about events just yet.
|
|
var message = "Event " + event + " @ 0x" + computer.cpu.getPC().toString(16) + " = " + computer.memory.readByte(computer.cpu.getPC()).toString(16);
|
|
console.log(message);
|
|
//alert(message);
|
|
});
|
|
computer.monitor.attach(computer.memory, MM_DISPLAY_ADAPTER, "display");
|
|
computer.keys.attach(computer.memory, MM_KEYBOARD_CHARACTER);
|
|
computer.random.attach(computer.memory, MM_PRNG);
|
|
computer.timer.attach(computer.memory, MM_CLOCK, 0x100);
|
|
|
|
// Power on!
|
|
computer.memory.reset();
|
|
|
|
/*
|
|
// Make it do something!
|
|
var HELLO_WORLD = [0xA2, 0x00, 0xBD, 0x14, 0x02, 0xF0, 0x0B, 0x8D, 0xA0, 0xFF, 0xA9, 0x07,
|
|
0x8D, 0xA1, 0xFF, 0xE8, 0xD0, 0xF0, 0x00, 0x00, 0x48, 0x65, 0x6C,
|
|
0x6C, 0x6F, 0x2C, 0x20, 0x77, 0x6F, 0x72, 0x6C, 0x64, 0x21, 0x00];
|
|
|
|
for (var x=0; x<HELLO_WORLD.length; x++) memory.writeByte(MM_HEAP_START + x, HELLO_WORLD[x]);
|
|
memory.writeByte(MM_RESET_VECTOR, MM_HEAP_START & 0x00FF);
|
|
memory.writeByte(MM_RESET_VECTOR + 1, (MM_HEAP_START & 0xFF00) >> 8);
|
|
*/
|
|
|
|
// Load test into RAM. Set PC to 0x1000 to run.
|
|
//for (var x=0; x<PROGRAM.length; x++) memory.writeByte(x + 0xa, PROGRAM[x]);
|
|
|
|
// Load EhBASIC into RAM.
|
|
for (var x=0; x<PROGRAM.length; x++) computer.memory.writeByte(x, PROGRAM[x]);
|
|
|
|
console.log("Code loaded.");
|
|
|
|
computer.cpu.reset();
|
|
//cpu.setPC(0x1000);
|
|
computer.cpu.run();
|