Wire up tests.

This commit is contained in:
Will Scullin 2019-03-01 20:38:04 -08:00
parent 58dbac1a78
commit 9bffd347cc
No known key found for this signature in database
GPG Key ID: 9092A5C0A673416B
3 changed files with 54 additions and 53 deletions

51
js/test.js Normal file
View File

@ -0,0 +1,51 @@
import CPU6502 from './cpu6502';
import Test6502 from './6502test';
import Test65C02 from './65C02test';
import { toHex } from './util';
var SYMBOLS = {};
var cpu;
var trace = [];
var lastPC = 0;
var done = false;
function traceCB() {
var pc = cpu.getPC();
done = lastPC == pc;
lastPC = pc;
var line = cpu.dumpRegisters() + ' ' + cpu.dumpPC(undefined, SYMBOLS);
trace.push(line);
if (trace.length > 1000) {
trace.shift();
}
}
window.test6502 = function test6502() {
cpu = new CPU6502();
var test = new Test6502();
cpu.addPageHandler(test);
cpu.setPC(0x400);
do {
cpu.stepCyclesDebug(1000, traceCB);
} while (!done);
if (lastPC == 0x3469) {
window.alert('6502 Success!');
} else {
window.alert('Failed! ' + toHex(lastPC));
}
};
window.test65C02 = function test65C02() {
cpu = new CPU6502({'65C02': true});
var test = new Test65C02();
cpu.addPageHandler(test);
cpu.setPC(0x400);
do {
cpu.stepCyclesDebug(1000, traceCB);
} while (!done);
if (lastPC == 0x24f1) {
window.alert('65C02 Success!');
} else {
window.alert('Failed! ' + toHex(lastPC));
}
};

View File

@ -4,58 +4,7 @@
<title>Test</title>
</head>
<body>
<script src="js/util.js"></script>
<script src="js/cpu6502.js"></script>
<script src="js/6502test.js"></script>
<script src="js/65C02test.js"></script>
<script>
var SYMBOLS = {};
var cpu;
var trace = [];
var lastPC = 0;
var done = false;
function traceCB() {
var pc = cpu.getPC()
done = lastPC == pc
lastPC = pc
var line = cpu.dumpRegisters() + ' ' + cpu.dumpPC(undefined, SYMBOLS);
trace.push(line);
if (trace.length > 1000) {
trace.shift();
}
}
function test6502() {
cpu = new CPU6502();
var test = new Test6502();
cpu.addPageHandler(test);
cpu.setPC(0x400);
do {
cpu.stepCyclesDebug(1000, traceCB);
} while (!done)
if (lastPC == 0x3469) {
window.alert("6502 Success!")
} else {
window.alert("Failed! " + toHex(lastPC))
}
}
function test65C02() {
cpu = new CPU6502({'65C02': true});
var test = new Test65C02();
cpu.addPageHandler(test);
cpu.setPC(0x400);
do {
cpu.stepCyclesDebug(1000, traceCB);
} while (!done)
if (lastPC == 0x24f1) {
window.alert("65C02 Success!")
} else {
window.alert("Failed! " + toHex(lastPC))
}
}
</script>
<script src="dist/test.js"></script>
<button onclick="test6502()">Test 6502</button>
<button onclick="test65C02()">Test 65C02</button>
</body>

View File

@ -7,9 +7,10 @@ module.exports =
entry: {
main2: path.resolve('js/main2.js'),
main2e: path.resolve('js/main2e.js'),
test: path.resolve('js/test.js')
},
output: {
path: path.resolve('dist/'),
path: path.resolve('dist/')
},
devServer: {
compress: true,