mirror of
https://github.com/sehugg/8bitworkshop.git
synced 2025-03-02 19:29:29 +00:00
started mocha-phantomjs tests
This commit is contained in:
parent
9d3a1bb48b
commit
db4ea08933
@ -1,7 +1,7 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title>8bitworkshop ~ Atari 2600</title>
|
||||
<title>8bitworkshop</title>
|
||||
<style type="text/css" media="screen">
|
||||
body {
|
||||
overflow: hidden !important;
|
||||
@ -274,6 +274,10 @@ canvas {
|
||||
<script src="src/util.js"></script>
|
||||
<script src="src/disasm.js"></script>
|
||||
<script src="src/ui.js"></script>
|
||||
<script>
|
||||
showWelcomeMessage();
|
||||
startUI(true);
|
||||
</script>
|
||||
|
||||
</body>
|
||||
<script>
|
||||
|
@ -14,7 +14,9 @@
|
||||
"test": "tests"
|
||||
},
|
||||
"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": {
|
||||
"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');
|
||||
imageData = ctx.createImageData(width, height);
|
||||
var buf = new ArrayBuffer(imageData.data.length);
|
||||
buf8 = new Uint8ClampedArray(buf);
|
||||
buf8 = new Uint8Array(buf); // TODO: Uint8ClampedArray
|
||||
datau32 = new Uint32Array(buf);
|
||||
}
|
||||
|
||||
@ -235,8 +235,10 @@ var SampleAudio = function(clockfreq) {
|
||||
function createContext() {
|
||||
if ( typeof AudioContext !== 'undefined') {
|
||||
self.context = new AudioContext();
|
||||
} else {
|
||||
} else if (typeof webkitAudioContext !== 'undefined' ){
|
||||
self.context = new webkitAudioContext();
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
self.sr=self.context.sampleRate;
|
||||
self.bufferlen=(self.sr > 44100) ? 4096 : 2048;
|
||||
@ -514,15 +516,14 @@ var BaseZ80Platform = function() {
|
||||
debugCondition = debugCond;
|
||||
this.resume();
|
||||
}
|
||||
/*
|
||||
this.restartDebugState = function() {
|
||||
if (debugCondition && !debugBreakState) {
|
||||
debugTargetClock -= cpu.getTstates();
|
||||
cpu.setTstates(0);
|
||||
debugSavedState = this.saveState();
|
||||
debugTargetClock -= debugSavedState.tstates;
|
||||
debugSavedState.tstates = 0;
|
||||
this.loadState(debugSavedState);
|
||||
}
|
||||
}
|
||||
*/
|
||||
this.getDebugCallback = function() {
|
||||
return debugCondition;
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ var SpaceInvadersPlatform = function(mainElement) {
|
||||
this.__proto__ = new BaseZ80Platform();
|
||||
|
||||
var cpu, ram, membus, iobus, rom;
|
||||
var video, audio, timer, pixels;
|
||||
var video, audio, timer, pixels, displayPCs;
|
||||
var inputs = [0xe,0x8,0x0];
|
||||
var bitshift_offset = 0;
|
||||
var bitshift_register = 0;
|
||||
@ -54,6 +54,7 @@ var SpaceInvadersPlatform = function(mainElement) {
|
||||
|
||||
this.start = function() {
|
||||
ram = new RAM(0x2000);
|
||||
displayPCs = new Uint16Array(new ArrayBuffer(0x2000*2));
|
||||
membus = {
|
||||
read: function(address) {
|
||||
if (address < 0x2000) {
|
||||
@ -74,6 +75,7 @@ var SpaceInvadersPlatform = function(mainElement) {
|
||||
var ofs = (address - 0x400)*8;
|
||||
for (var i=0; i<8; i++)
|
||||
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() {
|
||||
if (!self.isRunning())
|
||||
return;
|
||||
cpu.setTstates(0);
|
||||
var debugCond = self.getDebugCallback();
|
||||
var targetTstates = cpu.getTstates();
|
||||
for (var sl=0; sl<224; sl++) {
|
||||
var targetTstates = cpu.getTstates() + cpuCyclesPerLine;
|
||||
targetTstates += cpuCyclesPerLine;
|
||||
if (debugCond) {
|
||||
while (cpu.getTstates() < targetTstates) {
|
||||
if (debugCond && debugCond()) { debugCond = null; }
|
||||
if (debugCond && debugCond()) {
|
||||
debugCond = null;
|
||||
break;
|
||||
}
|
||||
cpu.runFrame(cpu.getTstates() + 1);
|
||||
}
|
||||
if (!debugCond)
|
||||
break;
|
||||
} else {
|
||||
cpu.runFrame(targetTstates);
|
||||
}
|
||||
@ -159,7 +166,7 @@ var SpaceInvadersPlatform = function(mainElement) {
|
||||
console.log("WATCHDOG FIRED"); // TODO: alert on video
|
||||
self.reset();
|
||||
}
|
||||
//self.restartDebugState();
|
||||
self.restartDebugState();
|
||||
});
|
||||
}
|
||||
|
||||
|
99
src/ui.js
99
src/ui.js
@ -847,51 +847,60 @@ var qs = (function (a) {
|
||||
return b;
|
||||
})(window.location.search.substr(1).split('&'));
|
||||
|
||||
// start
|
||||
showWelcomeMessage();
|
||||
// parse query string
|
||||
// is this a share URL?
|
||||
if (qs['sharekey']) {
|
||||
var sharekey = qs['sharekey'];
|
||||
console.log("Loading shared file ", sharekey);
|
||||
$.getJSON( ".storage/" + sharekey, function( result ) {
|
||||
console.log(result);
|
||||
var newid = 'shared/' + result['filename'];
|
||||
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);
|
||||
function startPlatform() {
|
||||
platform = new PLATFORMS[platform_id]($("#emulator")[0]);
|
||||
store = new FileStore(localStorage, platform_id + '/');
|
||||
PRESETS = platform.getPresets();
|
||||
setupDebugControls();
|
||||
platform.start();
|
||||
if (qs['file']) {
|
||||
// load file
|
||||
loadPreset(qs['file']);
|
||||
updateSelector();
|
||||
} else {
|
||||
// add default platform?
|
||||
platform_id = qs['platform'] || localStorage.getItem("__lastplatform");
|
||||
if (!platform_id) {
|
||||
platform_id = qs['platform'] = "vcs";
|
||||
}
|
||||
// load and start platform object
|
||||
$.getScript('src/platform/' + platform_id + '.js', function() {
|
||||
platform = new PLATFORMS[platform_id]($("#emulator")[0]);
|
||||
console.log("loaded platform", platform_id);
|
||||
store = new FileStore(localStorage, platform_id + '/');
|
||||
PRESETS = platform.getPresets();
|
||||
setupDebugControls();
|
||||
platform.start();
|
||||
if (qs['file']) {
|
||||
// load file
|
||||
loadPreset(qs['file']);
|
||||
updateSelector();
|
||||
} else {
|
||||
// try to load last file
|
||||
var lastid = localStorage.getItem("__lastid_"+platform_id) || localStorage.getItem("__lastid");
|
||||
localStorage.removeItem("__lastid");
|
||||
gotoPresetNamed(lastid || PRESETS[0].id);
|
||||
}
|
||||
});
|
||||
// try to load last file
|
||||
var lastid = localStorage.getItem("__lastid_"+platform_id) || localStorage.getItem("__lastid");
|
||||
localStorage.removeItem("__lastid");
|
||||
gotoPresetNamed(lastid || PRESETS[0].id);
|
||||
}
|
||||
}
|
||||
|
||||
// start
|
||||
function startUI(loadplatform) {
|
||||
// parse query string
|
||||
// is this a share URL?
|
||||
if (qs['sharekey']) {
|
||||
var sharekey = qs['sharekey'];
|
||||
console.log("Loading shared file ", sharekey);
|
||||
$.getJSON( ".storage/" + sharekey, function( result ) {
|
||||
console.log(result);
|
||||
var newid = 'shared/' + result['filename'];
|
||||
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 {
|
||||
// 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>
|
||||
<!--
|
||||
test.html: Test harness for the JSSpeccy Z80 core
|
||||
|
||||
|
||||
Copyright (C) 2009 Matthew Westcott
|
||||
|
||||
|
||||
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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
Contact details: <matthew@west.co.tt>
|
||||
Matthew Westcott, 14 Daisy Hill Drive, Adlington, Chorley, Lancs PR6 9NE UNITED KINGDOM
|
||||
-->
|
||||
@ -24,7 +24,7 @@
|
||||
<head>
|
||||
<title>jsspeccy test</title>
|
||||
<script>var global = {}</script>
|
||||
<script src="../../src/cpu/z80.js"></script>
|
||||
<script src="../../../src/cpu/z80.js"></script>
|
||||
<script type="text/javascript">/* <![CDATA[ */
|
||||
var testInputLines;
|
||||
var currentLine;
|
@ -1,6 +1,6 @@
|
||||
"use strict";
|
||||
|
||||
require('../../src/cpu/z80.js');
|
||||
require('../../../src/cpu/z80.js');
|
||||
|
||||
var _global = window;
|
||||
|
||||
@ -196,8 +196,8 @@ function hexWord(num) {
|
||||
|
||||
var fs = require('fs');
|
||||
var assert = require('assert');
|
||||
var testsIn = fs.readFileSync('test/z80/tests.in', {encoding:'utf8'}).split('\n\n');
|
||||
var testsExpected = fs.readFileSync('test/z80/tests.expected', {encoding:'utf8'}).split('\n\n');
|
||||
var testsIn = fs.readFileSync('test/cli/z80/tests.in', {encoding:'utf8'}).split('\n\n');
|
||||
var testsExpected = fs.readFileSync('test/cli/z80/tests.expected', {encoding:'utf8'}).split('\n\n');
|
||||
assert(testsIn.length == testsExpected.length);
|
||||
|
||||
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