Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

289 lines (253 sloc) 7.865 kb
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<title>DCPU-16</title>
<style type="text/css">
@font-face { font-family: Commodore; src: url('Commodore.ttf'); }
body {
background: #bbb;
font-family: Commodore;
}
#container {
padding: 6px;
z-index: 1000;
}
#container a {
color: #444;
}
button {
border: 4px solid #000;
background: #222;
color: #fff;
font-size: 24px;
font-family: Commodore;
}
button:active {
background: #aaf;
}
textarea {
background: #222;
color: #fff;
border: 8px solid #000;
font-family: Commodore;
font-size: 12px;
}
#consoleContainer {
-webkit-perspective: 2200;
-moz-perspective: 2200;
}
.perspective {
-webkit-transform: rotateY(32deg);
-moz-transform: rotateY(32deg);
}
canvas {
z-index: -1;
}
</style>
<script type="text/javascript" src="dcpu16.js"></script>
<script type="text/javascript">
var cpu = new DCPU16.CPU();
var display = (function() {
var screen = [];
screen.length = 32*12;
for (var i = 0, _len = screen.length; i < _len; ++i)
screen[i] = [0, 0];
var outputListeners = [];
return {
length: screen.length,
set: function(idx, val) {
screen[idx] = [val >> 8, val & 0xFF];
var string = '';
for (var i = 0, _len = screen.length; i < _len; ++i)
string += String.fromCharCode(screen[i][1]);
for (var i = 0, _len = outputListeners.length; i < _len; ++i)
outputListeners[i](screen, string);
},
onOutput: function(callback) {
outputListeners.push(callback);
},
};
})();
cpu.mapDevice(0x8000, display.length, display);
var input = (function() {
var buffer = "";
return {
get: function(idx) {
var result = buffer.charCodeAt(0) || 0x0000;
buffer = buffer.substr(1);
return result;
},
write: function(str) {
buffer += str;
}
};
})();
cpu.mapDevice(0x7FFF, 1, input);
function compile() {
var assembler = new DCPU16.Assembler(cpu);
try {
assembler.compile(assembler.clean(document.getElementById('editor').value));
document.getElementById('debug').value = cpu.getDump();
} catch(e) {
document.getElementById('debug').value = e;
}
}
function step() {
cpu.step();
document.getElementById('debug').value = cpu.getDump();
}
function run() {
cpu.run(function() {
if(document.getElementById('debugToggle').checked)
document.getElementById('debug').value = cpu.getDump();
});
if(!document.getElementById('debugToggle').checked) document.getElementById('debug').value = 'Executing...';
}
function stop() {
cpu.stop();
document.getElementById('debug').value = cpu.getDump();
}
function reset() {
cpu.clear();
document.getElementById('debug').value = cpu.getDump();
document.getElementById('console').value = '';
}
function sendInput() {
input.write(document.getElementById('input').value);
document.getElementById('input').value = '';
}
display.onOutput(function(screen, string) {
string.replace('\n', '');
document.getElementById('console').value = string;
});
cpu.onEnd(function() {
document.getElementById('debug').value = cpu.getDump();
});
</script>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-30599135-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
</head>
<body>
<div id="container">
<a href="http://github.com/mappum/DCPU-16"><h1>DCPU-16 Emulator</h1></a>
<h2>V0.7 - By Mappum</h2>
<textarea id="editor" cols="60" rows="40">
; Try some basic stuff
SET A, 0x30 ; 7c01 0030
SET [0x1000], 0x20 ; 7de1 1000 0020
SUB A, [0x1000] ; 7803 1000
IFN A, 0x10 ; c00d
SET PC, crash ; 7dc1 001a [*]
; Do a loopy thing
SET I, 10 ; a861
SET A, 0x2000 ; 7c01 2000
:loop SET [0x2000+I], [A] ; 2161 2000
SUB I, 1 ; 8463
IFN I, 0 ; 806d
SET PC, loop ; 7dc1 000d [*]
; Call a subroutine
SET X, 0x4 ; 9031
JSR testsub ; 7c10 0018 [*]
SET PC, print ; 7dc1 001a [*]
:testsub SHL X, 4 ; 9037
SET PC, POP ; 61c1
; "Hello, world!"
; Set 0x8000 - 0x8180 to an ASCII value to output to console
:print
SET [0x8000], 72
SET [0x8001], 101
SET [0x8002], 108
SET [0x8003], 108
SET [0x8004], 111
SET [0x8005], 44
SET [0x8006], 32
SET [0x8007], 119
SET [0x8008], 111
SET [0x8009], 114
SET [0x800a], 108
SET [0x800b], 100
SET [0x800c], 33
; BRK (break) is also non-standard
BRK
; Hang forever. X should now be 0x40 if everything went right.
:crash SET PC, crash ; 7dc1 001a [*]
</textarea>
<textarea id="debug" cols="45" rows="40" readonly="readonly"></textarea>
<div style="clear:both;">
<button onclick="compile()">Compile</button>
<button onclick="step()">Step</button>
<button onclick="run()">Run</button>
<button onclick="stop()">Stop</button>
<button onclick="reset();">Reset</button>
<label for="debugToggle">Debug:</label>
<input id="debugToggle" type="checkbox" checked="checked" />
</div>
<hr />
<div id="consoleContainer">
<h2>Console:</h2>
<textarea id="console" cols="30" rows="12" readonly="readonly" class="perspective"></textarea>
<br />
<input id="input" type="text" style="width:200px; height:32px; vertical-align: bottom" />
<button id="submit" style="width:68px" onclick="sendInput()">>></button>
</div>
</div>
<script type="text/javascript" src="lib/Three.js"></script>
<script type="text/javascript">
var scene, camera, renderer, cubes = [];
function init() {
scene = new THREE.Scene();
camera = new THREE.PerspectiveCamera(70, window.innerWidth / window.innerHeight, 1, 10000);
camera.position.y = 150;
camera.position.z = 500;
scene.add(camera);
for(var i = 0; i < 40; i++) {
var color = (Math.random() * 60) + 100;
color |= color << 8;
color |= (color & 0xff) << 16;
materials = new THREE.MeshBasicMaterial({color: color});
var geom = new THREE.CubeGeometry(Math.random() * 200 + 100,
Math.random() * 200 + 100, Math.random() * 200 + 100);
var cube = new THREE.Mesh(geom, materials);
cube.doubleSided = true;
cube.position.x = Math.random() * window.innerWidth - window.innerWidth / 2;
cube.position.y = Math.random() * window.innerWidth - window.innerWidth / 2;
cube.position.z = Math.random() * -600 - 200;
cube.rotation.x = Math.random() * 360;
cube.rotation.y = Math.random() * 360;
cube.rotation.z = Math.random() * 360;
scene.add(cube);
cubes.push(cube);
}
var light = new THREE.PointLight(0xffffff);
light.position.x = 500;
light.position.y = 550;
light.position.z = 500;
scene.add(light);
renderer = new THREE.CanvasRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
var el = renderer.domElement;
el.style.position = 'absolute';
el.style.left = 0;
el.style.top = 0;
el.style['z-index'] = -1;
document.body.appendChild(el);
}
if(navigator.platform.substr(0, 3) === 'Win'
|| navigator.platform === 'Mac'
|| navigator.platform === 'Linux') {
init();
renderer.render(scene, camera);
}
</script>
</body>
</html>
Jump to Line
Something went wrong with that request. Please try again.