2018-08-21 22:32:07 +00:00
|
|
|
|
|
|
|
var assert = require('assert');
|
|
|
|
var fs = require('fs');
|
|
|
|
var wtu = require('./workertestutils.js');
|
|
|
|
global.includeInThisContext('src/cpu/z80fast.js');
|
|
|
|
|
|
|
|
const jsdom = require('jsdom');
|
|
|
|
const { JSDOM } = jsdom;
|
|
|
|
const { window } = new JSDOM();
|
|
|
|
|
2018-08-23 22:27:07 +00:00
|
|
|
const dom = new JSDOM(`<!DOCTYPE html><div id="emulator"><div id="javatari-screen"></div></div>`);
|
2018-08-23 20:02:13 +00:00
|
|
|
global.window = dom.window;
|
|
|
|
global.document = dom.window.document;
|
2018-08-21 22:32:07 +00:00
|
|
|
dom.window.Audio = null;
|
2018-08-23 20:02:13 +00:00
|
|
|
global.Image = function() { }
|
2018-08-23 22:27:07 +00:00
|
|
|
global.btoa = require('btoa');
|
|
|
|
global.atob = require('atob');
|
|
|
|
global['$'] = require("jquery/jquery-2.2.3.min.js");
|
2018-08-23 20:02:13 +00:00
|
|
|
includeInThisContext("javatari.js/release/javatari/javatari.js");
|
|
|
|
Javatari.AUTO_START = false;
|
2018-08-21 22:32:07 +00:00
|
|
|
includeInThisContext('src/cpu/z80fast.js');
|
|
|
|
//includeInThisContext('tss/js/Log.js');
|
2018-08-23 20:02:13 +00:00
|
|
|
global.Log = require('tss/js/Log.js').Log;
|
2018-08-21 22:32:07 +00:00
|
|
|
includeInThisContext('tss/js/tss/PsgDeviceChannel.js');
|
|
|
|
includeInThisContext('tss/js/tss/MasterChannel.js');
|
|
|
|
includeInThisContext('tss/js/tss/AudioLooper.js');
|
|
|
|
|
|
|
|
var jsnes = require("jsnes/jsnes.min.js");
|
|
|
|
|
|
|
|
var emu = require('gen/emu.js');
|
|
|
|
var audio = require('gen/audio.js');
|
2018-08-23 20:02:13 +00:00
|
|
|
var recorder = require('gen/recorder.js');
|
2018-08-23 22:27:07 +00:00
|
|
|
var _vicdual = require('gen/platform/vicdual.js');
|
|
|
|
var _apple2 = require('gen/platform/apple2.js');
|
|
|
|
var _vcs = require('gen/platform/vcs.js');
|
2018-08-21 22:32:07 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
|
2018-08-23 22:27:07 +00:00
|
|
|
dom.window.HTMLCanvasElement.prototype.getContext = function() {
|
|
|
|
return {
|
|
|
|
getImageData: function(x,y,w,h) { return {data: new Uint32Array(w*h) }; },
|
|
|
|
fillRect: function(x,y,w,h) { },
|
|
|
|
drawImage: function(img,x,y,w,h) { },
|
|
|
|
putImageData: function(data,w,h) { }
|
|
|
|
};
|
|
|
|
}
|
|
|
|
global.navigator = {};
|
|
|
|
|
|
|
|
var keycallback;
|
|
|
|
|
2018-08-21 22:32:07 +00:00
|
|
|
emu.RasterVideo = function(mainElement, width, height, options) {
|
|
|
|
var datau32;
|
|
|
|
this.create = function() {
|
|
|
|
datau32 = new Uint32Array(width*height);
|
|
|
|
}
|
|
|
|
this.setKeyboardEvents = function(callback) {
|
2018-08-23 22:27:07 +00:00
|
|
|
keycallback = callback;
|
2018-08-21 22:32:07 +00:00
|
|
|
}
|
|
|
|
this.getFrameData = function() { return datau32; }
|
2018-08-23 20:02:13 +00:00
|
|
|
this.updateFrame = function() { }
|
2018-08-21 22:32:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
|
2018-08-23 20:02:13 +00:00
|
|
|
function testPlatform(platid, romname, maxframes, callback) {
|
2018-08-21 22:32:07 +00:00
|
|
|
var emudiv = document.getElementById('emulator');
|
|
|
|
var platform = new emu.PLATFORMS[platid](emudiv);
|
2018-08-23 20:02:13 +00:00
|
|
|
var rec = new recorder.StateRecorderImpl(platform);
|
2018-08-21 22:32:07 +00:00
|
|
|
platform.start();
|
2018-08-23 20:02:13 +00:00
|
|
|
var rom = fs.readFileSync('./test/roms/' + platid + '/' + romname);
|
|
|
|
rom = new Uint8Array(rom);
|
2018-08-23 22:27:07 +00:00
|
|
|
platform.loadROM("ROM", rom);
|
2018-08-23 20:02:13 +00:00
|
|
|
platform.resume(); // so that recorder works
|
|
|
|
platform.setRecorder(rec);
|
|
|
|
for (var i=0; i<maxframes; i++) {
|
|
|
|
if (callback) callback(platform, i);
|
|
|
|
platform.nextFrame();
|
|
|
|
}
|
|
|
|
platform.pause();
|
|
|
|
assert.equal(maxframes, rec.numFrames());
|
|
|
|
var state1 = platform.saveState();
|
|
|
|
assert.equal(1, rec.loadFrame(1));
|
|
|
|
assert.equal(maxframes, rec.loadFrame(maxframes));
|
|
|
|
var state2 = platform.saveState();
|
|
|
|
assert.deepEqual(state1, state2);
|
|
|
|
return platform;
|
2018-08-21 22:32:07 +00:00
|
|
|
}
|
|
|
|
|
2018-08-23 20:02:13 +00:00
|
|
|
describe('Platform Replay', () => {
|
2018-08-23 22:27:07 +00:00
|
|
|
|
2018-08-23 20:02:13 +00:00
|
|
|
it('Should run apple2', () => {
|
|
|
|
var platform = testPlatform('apple2', 'cosmic.c.rom', 70, (platform, frameno) => {
|
2018-08-23 22:27:07 +00:00
|
|
|
if (frameno == 60) {
|
|
|
|
keycallback(32, 32, 1); // space bar
|
|
|
|
}
|
|
|
|
});
|
|
|
|
assert.equal(platform.saveState().kbd, 0x20); // strobe cleared
|
|
|
|
});
|
|
|
|
|
|
|
|
it('Should run vcs', () => {
|
|
|
|
var platform = testPlatform('vcs', 'brickgame.rom', 70, (platform, frameno) => {
|
2018-08-23 20:02:13 +00:00
|
|
|
if (frameno == 60) {
|
|
|
|
var cstate = platform.saveControlsState();
|
2018-08-23 22:27:07 +00:00
|
|
|
cstate.SA = 0xff ^ 0x40; // stick left
|
2018-08-23 20:02:13 +00:00
|
|
|
platform.loadControlsState(cstate);
|
|
|
|
}
|
|
|
|
});
|
2018-08-23 22:27:07 +00:00
|
|
|
assert.equal(platform.saveState().p.SA, 0xff ^ 0x40);
|
2018-08-23 20:02:13 +00:00
|
|
|
});
|
2018-08-23 22:27:07 +00:00
|
|
|
|
2018-08-21 22:32:07 +00:00
|
|
|
});
|
2018-08-23 22:27:07 +00:00
|
|
|
|