mirror of
https://github.com/sehugg/8bitworkshop.git
synced 2025-03-03 10:30:17 +00:00
started mocha-phantomjs tests
This commit is contained in:
parent
9d3a1bb48b
commit
db4ea08933
@ -1,7 +1,7 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<title>8bitworkshop ~ Atari 2600</title>
|
<title>8bitworkshop</title>
|
||||||
<style type="text/css" media="screen">
|
<style type="text/css" media="screen">
|
||||||
body {
|
body {
|
||||||
overflow: hidden !important;
|
overflow: hidden !important;
|
||||||
@ -274,6 +274,10 @@ canvas {
|
|||||||
<script src="src/util.js"></script>
|
<script src="src/util.js"></script>
|
||||||
<script src="src/disasm.js"></script>
|
<script src="src/disasm.js"></script>
|
||||||
<script src="src/ui.js"></script>
|
<script src="src/ui.js"></script>
|
||||||
|
<script>
|
||||||
|
showWelcomeMessage();
|
||||||
|
startUI(true);
|
||||||
|
</script>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
<script>
|
<script>
|
||||||
|
@ -14,7 +14,9 @@
|
|||||||
"test": "tests"
|
"test": "tests"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "mocha --recursive"
|
"test": "npm run test-node && npm run test-browser",
|
||||||
|
"test-node": "mocha --recursive test/cli",
|
||||||
|
"test-browser": "mocha-phantomjs ./testemu.html"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
13
src/emu.js
13
src/emu.js
@ -47,7 +47,7 @@ var RasterVideo = function(mainElement, width, height, options) {
|
|||||||
ctx = canvas.getContext('2d');
|
ctx = canvas.getContext('2d');
|
||||||
imageData = ctx.createImageData(width, height);
|
imageData = ctx.createImageData(width, height);
|
||||||
var buf = new ArrayBuffer(imageData.data.length);
|
var buf = new ArrayBuffer(imageData.data.length);
|
||||||
buf8 = new Uint8ClampedArray(buf);
|
buf8 = new Uint8Array(buf); // TODO: Uint8ClampedArray
|
||||||
datau32 = new Uint32Array(buf);
|
datau32 = new Uint32Array(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -235,8 +235,10 @@ var SampleAudio = function(clockfreq) {
|
|||||||
function createContext() {
|
function createContext() {
|
||||||
if ( typeof AudioContext !== 'undefined') {
|
if ( typeof AudioContext !== 'undefined') {
|
||||||
self.context = new AudioContext();
|
self.context = new AudioContext();
|
||||||
} else {
|
} else if (typeof webkitAudioContext !== 'undefined' ){
|
||||||
self.context = new webkitAudioContext();
|
self.context = new webkitAudioContext();
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
self.sr=self.context.sampleRate;
|
self.sr=self.context.sampleRate;
|
||||||
self.bufferlen=(self.sr > 44100) ? 4096 : 2048;
|
self.bufferlen=(self.sr > 44100) ? 4096 : 2048;
|
||||||
@ -514,15 +516,14 @@ var BaseZ80Platform = function() {
|
|||||||
debugCondition = debugCond;
|
debugCondition = debugCond;
|
||||||
this.resume();
|
this.resume();
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
this.restartDebugState = function() {
|
this.restartDebugState = function() {
|
||||||
if (debugCondition && !debugBreakState) {
|
if (debugCondition && !debugBreakState) {
|
||||||
debugTargetClock -= cpu.getTstates();
|
|
||||||
cpu.setTstates(0);
|
|
||||||
debugSavedState = this.saveState();
|
debugSavedState = this.saveState();
|
||||||
|
debugTargetClock -= debugSavedState.tstates;
|
||||||
|
debugSavedState.tstates = 0;
|
||||||
|
this.loadState(debugSavedState);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
this.getDebugCallback = function() {
|
this.getDebugCallback = function() {
|
||||||
return debugCondition;
|
return debugCondition;
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@ var SpaceInvadersPlatform = function(mainElement) {
|
|||||||
this.__proto__ = new BaseZ80Platform();
|
this.__proto__ = new BaseZ80Platform();
|
||||||
|
|
||||||
var cpu, ram, membus, iobus, rom;
|
var cpu, ram, membus, iobus, rom;
|
||||||
var video, audio, timer, pixels;
|
var video, audio, timer, pixels, displayPCs;
|
||||||
var inputs = [0xe,0x8,0x0];
|
var inputs = [0xe,0x8,0x0];
|
||||||
var bitshift_offset = 0;
|
var bitshift_offset = 0;
|
||||||
var bitshift_register = 0;
|
var bitshift_register = 0;
|
||||||
@ -54,6 +54,7 @@ var SpaceInvadersPlatform = function(mainElement) {
|
|||||||
|
|
||||||
this.start = function() {
|
this.start = function() {
|
||||||
ram = new RAM(0x2000);
|
ram = new RAM(0x2000);
|
||||||
|
displayPCs = new Uint16Array(new ArrayBuffer(0x2000*2));
|
||||||
membus = {
|
membus = {
|
||||||
read: function(address) {
|
read: function(address) {
|
||||||
if (address < 0x2000) {
|
if (address < 0x2000) {
|
||||||
@ -74,6 +75,7 @@ var SpaceInvadersPlatform = function(mainElement) {
|
|||||||
var ofs = (address - 0x400)*8;
|
var ofs = (address - 0x400)*8;
|
||||||
for (var i=0; i<8; i++)
|
for (var i=0; i<8; i++)
|
||||||
pixels[ofs+i] = (value & (1<<i)) ? PIXEL_ON : PIXEL_OFF;
|
pixels[ofs+i] = (value & (1<<i)) ? PIXEL_ON : PIXEL_OFF;
|
||||||
|
displayPCs[address] = cpu.getPC(); // save program counter
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -137,15 +139,20 @@ var SpaceInvadersPlatform = function(mainElement) {
|
|||||||
timer = new AnimationTimer(60, function() {
|
timer = new AnimationTimer(60, function() {
|
||||||
if (!self.isRunning())
|
if (!self.isRunning())
|
||||||
return;
|
return;
|
||||||
cpu.setTstates(0);
|
|
||||||
var debugCond = self.getDebugCallback();
|
var debugCond = self.getDebugCallback();
|
||||||
|
var targetTstates = cpu.getTstates();
|
||||||
for (var sl=0; sl<224; sl++) {
|
for (var sl=0; sl<224; sl++) {
|
||||||
var targetTstates = cpu.getTstates() + cpuCyclesPerLine;
|
targetTstates += cpuCyclesPerLine;
|
||||||
if (debugCond) {
|
if (debugCond) {
|
||||||
while (cpu.getTstates() < targetTstates) {
|
while (cpu.getTstates() < targetTstates) {
|
||||||
if (debugCond && debugCond()) { debugCond = null; }
|
if (debugCond && debugCond()) {
|
||||||
|
debugCond = null;
|
||||||
|
break;
|
||||||
|
}
|
||||||
cpu.runFrame(cpu.getTstates() + 1);
|
cpu.runFrame(cpu.getTstates() + 1);
|
||||||
}
|
}
|
||||||
|
if (!debugCond)
|
||||||
|
break;
|
||||||
} else {
|
} else {
|
||||||
cpu.runFrame(targetTstates);
|
cpu.runFrame(targetTstates);
|
||||||
}
|
}
|
||||||
@ -159,7 +166,7 @@ var SpaceInvadersPlatform = function(mainElement) {
|
|||||||
console.log("WATCHDOG FIRED"); // TODO: alert on video
|
console.log("WATCHDOG FIRED"); // TODO: alert on video
|
||||||
self.reset();
|
self.reset();
|
||||||
}
|
}
|
||||||
//self.restartDebugState();
|
self.restartDebugState();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
99
src/ui.js
99
src/ui.js
@ -847,51 +847,60 @@ var qs = (function (a) {
|
|||||||
return b;
|
return b;
|
||||||
})(window.location.search.substr(1).split('&'));
|
})(window.location.search.substr(1).split('&'));
|
||||||
|
|
||||||
// start
|
function startPlatform() {
|
||||||
showWelcomeMessage();
|
platform = new PLATFORMS[platform_id]($("#emulator")[0]);
|
||||||
// parse query string
|
store = new FileStore(localStorage, platform_id + '/');
|
||||||
// is this a share URL?
|
PRESETS = platform.getPresets();
|
||||||
if (qs['sharekey']) {
|
setupDebugControls();
|
||||||
var sharekey = qs['sharekey'];
|
platform.start();
|
||||||
console.log("Loading shared file ", sharekey);
|
if (qs['file']) {
|
||||||
$.getJSON( ".storage/" + sharekey, function( result ) {
|
// load file
|
||||||
console.log(result);
|
loadPreset(qs['file']);
|
||||||
var newid = 'shared/' + result['filename'];
|
updateSelector();
|
||||||
updatePreset(newid, result['text']);
|
|
||||||
qs['file'] = newid;
|
|
||||||
delete qs['sharekey'];
|
|
||||||
window.location = "?" + $.param(qs);
|
|
||||||
}, 'text');
|
|
||||||
} else {
|
|
||||||
// reset file?
|
|
||||||
if (qs['file'] && qs['reset']) {
|
|
||||||
store.deleteFile(qs['file']);
|
|
||||||
qs['reset'] = '';
|
|
||||||
window.location = "?" + $.param(qs);
|
|
||||||
} else {
|
} else {
|
||||||
// add default platform?
|
// try to load last file
|
||||||
platform_id = qs['platform'] || localStorage.getItem("__lastplatform");
|
var lastid = localStorage.getItem("__lastid_"+platform_id) || localStorage.getItem("__lastid");
|
||||||
if (!platform_id) {
|
localStorage.removeItem("__lastid");
|
||||||
platform_id = qs['platform'] = "vcs";
|
gotoPresetNamed(lastid || PRESETS[0].id);
|
||||||
}
|
}
|
||||||
// load and start platform object
|
}
|
||||||
$.getScript('src/platform/' + platform_id + '.js', function() {
|
|
||||||
platform = new PLATFORMS[platform_id]($("#emulator")[0]);
|
// start
|
||||||
console.log("loaded platform", platform_id);
|
function startUI(loadplatform) {
|
||||||
store = new FileStore(localStorage, platform_id + '/');
|
// parse query string
|
||||||
PRESETS = platform.getPresets();
|
// is this a share URL?
|
||||||
setupDebugControls();
|
if (qs['sharekey']) {
|
||||||
platform.start();
|
var sharekey = qs['sharekey'];
|
||||||
if (qs['file']) {
|
console.log("Loading shared file ", sharekey);
|
||||||
// load file
|
$.getJSON( ".storage/" + sharekey, function( result ) {
|
||||||
loadPreset(qs['file']);
|
console.log(result);
|
||||||
updateSelector();
|
var newid = 'shared/' + result['filename'];
|
||||||
} else {
|
updatePreset(newid, result['text']);
|
||||||
// try to load last file
|
qs['file'] = newid;
|
||||||
var lastid = localStorage.getItem("__lastid_"+platform_id) || localStorage.getItem("__lastid");
|
delete qs['sharekey'];
|
||||||
localStorage.removeItem("__lastid");
|
window.location = "?" + $.param(qs);
|
||||||
gotoPresetNamed(lastid || PRESETS[0].id);
|
}, 'text');
|
||||||
}
|
} else {
|
||||||
});
|
// reset file?
|
||||||
|
if (qs['file'] && qs['reset']) {
|
||||||
|
store.deleteFile(qs['file']);
|
||||||
|
qs['reset'] = '';
|
||||||
|
window.location = "?" + $.param(qs);
|
||||||
|
} else {
|
||||||
|
// add default platform?
|
||||||
|
platform_id = qs['platform'] || localStorage.getItem("__lastplatform");
|
||||||
|
if (!platform_id) {
|
||||||
|
platform_id = qs['platform'] = "vcs";
|
||||||
|
}
|
||||||
|
// load and start platform object
|
||||||
|
if (loadplatform) {
|
||||||
|
$.getScript('src/platform/' + platform_id + '.js', function() {
|
||||||
|
console.log("loaded platform", platform_id);
|
||||||
|
startPlatform();
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
startPlatform();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,22 +1,22 @@
|
|||||||
<!DOCTYPE HTML>
|
<!DOCTYPE HTML>
|
||||||
<!--
|
<!--
|
||||||
test.html: Test harness for the JSSpeccy Z80 core
|
test.html: Test harness for the JSSpeccy Z80 core
|
||||||
|
|
||||||
Copyright (C) 2009 Matthew Westcott
|
Copyright (C) 2009 Matthew Westcott
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
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
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
Contact details: <matthew@west.co.tt>
|
Contact details: <matthew@west.co.tt>
|
||||||
Matthew Westcott, 14 Daisy Hill Drive, Adlington, Chorley, Lancs PR6 9NE UNITED KINGDOM
|
Matthew Westcott, 14 Daisy Hill Drive, Adlington, Chorley, Lancs PR6 9NE UNITED KINGDOM
|
||||||
-->
|
-->
|
||||||
@ -24,7 +24,7 @@
|
|||||||
<head>
|
<head>
|
||||||
<title>jsspeccy test</title>
|
<title>jsspeccy test</title>
|
||||||
<script>var global = {}</script>
|
<script>var global = {}</script>
|
||||||
<script src="../../src/cpu/z80.js"></script>
|
<script src="../../../src/cpu/z80.js"></script>
|
||||||
<script type="text/javascript">/* <![CDATA[ */
|
<script type="text/javascript">/* <![CDATA[ */
|
||||||
var testInputLines;
|
var testInputLines;
|
||||||
var currentLine;
|
var currentLine;
|
@ -1,6 +1,6 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
require('../../src/cpu/z80.js');
|
require('../../../src/cpu/z80.js');
|
||||||
|
|
||||||
var _global = window;
|
var _global = window;
|
||||||
|
|
||||||
@ -196,8 +196,8 @@ function hexWord(num) {
|
|||||||
|
|
||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
var assert = require('assert');
|
var assert = require('assert');
|
||||||
var testsIn = fs.readFileSync('test/z80/tests.in', {encoding:'utf8'}).split('\n\n');
|
var testsIn = fs.readFileSync('test/cli/z80/tests.in', {encoding:'utf8'}).split('\n\n');
|
||||||
var testsExpected = fs.readFileSync('test/z80/tests.expected', {encoding:'utf8'}).split('\n\n');
|
var testsExpected = fs.readFileSync('test/cli/z80/tests.expected', {encoding:'utf8'}).split('\n\n');
|
||||||
assert(testsIn.length == testsExpected.length);
|
assert(testsIn.length == testsExpected.length);
|
||||||
|
|
||||||
describe('Z80 CPU', function() {
|
describe('Z80 CPU', function() {
|
26
test/ui/testemus.js
Normal file
26
test/ui/testemus.js
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
|
||||||
|
function assert(b, msg) {
|
||||||
|
if (!b) { throw new Error(msg); }
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('Test VCS emulator', function() {
|
||||||
|
var platform = new VCSPlatform();
|
||||||
|
it('Should start', function(done) {
|
||||||
|
platform.start();
|
||||||
|
assert(!platform.isRunning());
|
||||||
|
// TODO: more testing
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Test Space Invaders emulator', function() {
|
||||||
|
var platform = new SpaceInvadersPlatform($('#emulator')[0]);
|
||||||
|
it('Should start', function(done) {
|
||||||
|
platform.start();
|
||||||
|
assert(!platform.isRunning());
|
||||||
|
platform.resume();
|
||||||
|
assert(platform.isRunning());
|
||||||
|
// TODO: more testing
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
46
testemu.html
Normal file
46
testemu.html
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<!-- encoding must be set for mocha's special characters to render properly -->
|
||||||
|
<link rel="stylesheet" href="node_modules/mocha/mocha.css" />
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="mocha"></div>
|
||||||
|
<div id="notebook">
|
||||||
|
<div id="editor_window">
|
||||||
|
<div id="disassembly" class="editor">
|
||||||
|
</div>
|
||||||
|
<div id="editor" class="editor">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="emulator" id="emulator">
|
||||||
|
<div id="javatari-screen" style="margin: 0 auto; box-shadow: 2px 2px 10px rgb(60, 60, 60);"></div>
|
||||||
|
<div id="javatari-console-panel" style="margin: 0 auto; box-shadow: 2px 2px 10px rgb(60, 60, 60);"></div>
|
||||||
|
<div id="mem_info" class="mem_info" style="display:none">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<script src="node_modules/mocha/mocha.js"></script>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
mocha.ui('bdd')
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<script src="jquery/jquery-2.2.3.min.js"></script>
|
||||||
|
|
||||||
|
<script src="javatari.js/release/javatari/javatari.js"></script>
|
||||||
|
<script src="src/cpu/z80.js"></script>
|
||||||
|
<script src="src/emu.js"></script>
|
||||||
|
<script src="src/util.js"></script>
|
||||||
|
<script src="src/disasm.js"></script>
|
||||||
|
<script src="src/platform/vcs.js"></script>
|
||||||
|
<script src="src/platform/spaceinv.js"></script>
|
||||||
|
|
||||||
|
<script src="test/ui/testemus.js"></script>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
mocha.run()
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
x
Reference in New Issue
Block a user