Better linting, tests, fix text buffer, ROR.

This commit is contained in:
Will Scullin 2019-10-16 20:18:53 -07:00
parent e2c615f20b
commit 37a6efc661
No known key found for this signature in database
GPG Key ID: 9092A5C0A673416B
10 changed files with 72 additions and 37 deletions

View File

@ -15,6 +15,10 @@
"semi": [ "semi": [
2, 2,
"always" "always"
],
"no-use-before-define": [
2,
{ "functions": false }
] ]
}, },
"env": { "env": {
@ -38,11 +42,15 @@
"browser": false "browser": false
} }
}, { }, {
"files": [ "test/*"], "files": [ "test/**/*"],
"env": { "env": {
"jest": true, "jest": true,
"node": true "node": true
},
"rules": {
"no-console": 0
} }
}, { }, {
"files": [ "js/entry2.js", "js/entry2e.js"], "files": [ "js/entry2.js", "js/entry2e.js"],
"env": { "env": {

View File

@ -121,7 +121,7 @@
<label for="text_input">Text Input</label> <label for="text_input">Text Input</label>
<textarea rows="10" style="width: 99%" id="text_input"></textarea> <textarea rows="10" style="width: 99%" id="text_input"></textarea>
<br /> <br />
<button onclick="Apple2.io.setKeyBuffer(document.querySelector('#text_input').innerText)"> <button onclick="Apple2.io.setKeyBuffer(document.querySelector('#text_input').value)">
Send Send
</button> </button>
<input type="checkbox" id="buffering" /> <input type="checkbox" id="buffering" />

View File

@ -636,7 +636,7 @@ export default function CPU6502(options)
function ror(readAddrFn) { function ror(readAddrFn) {
var addr = readAddrFn({rwm: true}); var addr = readAddrFn({rwm: true});
var oldVal = readByte(addr); var oldVal = readByte(addr);
writeByte(addr, val); writeByte(addr, oldVal);
var val = rotateRight(oldVal); var val = rotateRight(oldVal);
writeByte(addr, val); writeByte(addr, val);
} }

View File

@ -286,7 +286,7 @@ export function explodeSector13(volume, track, sector, data) {
} }
export function readSector(drive, track, sector) { export function readSector(drive, track, sector) {
var _sector = cur.fmt == 'po' ? _PO[sector] : _DO[sector]; var _sector = drive.fmt == 'po' ? _PO[sector] : _DO[sector];
var val, state = 0; var val, state = 0;
var idx = 0; var idx = 0;
var retry = 0; var retry = 0;

View File

@ -54,6 +54,9 @@ var disk_sets = {};
var disk_cur_name = []; var disk_cur_name = [];
var disk_cur_cat = []; var disk_cur_cat = [];
var tape;
var disk2;
var driveLights;
var _currentDrive = 1; var _currentDrive = 1;
export function openLoad(drive, event) export function openLoad(drive, event)
@ -252,7 +255,9 @@ function doLoadHTTP(drive, _url) {
var name = decodeURIComponent(fileParts.join('.')); var name = decodeURIComponent(fileParts.join('.'));
if (disk2.setBinary(drive, name, ext, req.response)) { if (disk2.setBinary(drive, name, ext, req.response)) {
driveLights.label(drive, name); driveLights.label(drive, name);
MicroModal.close('http-modal'); if (!_url) {
MicroModal.close('http-modal');
}
initGamepad(); initGamepad();
} }
}; };
@ -338,18 +343,18 @@ var vm = new VideoModes(gr, hgr, gr2, hgr2, false);
vm.multiScreen(multiScreen); vm.multiScreen(multiScreen);
var dumper = new ApplesoftDump(cpu); var dumper = new ApplesoftDump(cpu);
var driveLights = new DriveLights(); driveLights = new DriveLights();
var io = new Apple2IO(cpu, vm); export var io = new Apple2IO(cpu, vm);
var keyboard = new KeyBoard(cpu, io); var keyboard = new KeyBoard(cpu, io);
var audio = new Audio(io); var audio = new Audio(io);
var tape = new Tape(io); tape = new Tape(io);
var printer = new Printer('#printer-modal .paper'); var printer = new Printer('#printer-modal .paper');
var lc = new LanguageCard(io, 0, rom); var lc = new LanguageCard(io, 0, rom);
var parallel = new Parallel(io, 1, printer); var parallel = new Parallel(io, 1, printer);
var slinky = new RAMFactor(io, 2, 1024 * 1024); var slinky = new RAMFactor(io, 2, 1024 * 1024);
var videoterm = new Videoterm(io, 3, context1); var videoterm = new Videoterm(io, 3, context1);
var disk2 = new DiskII(io, 6, driveLights); disk2 = new DiskII(io, 6, driveLights);
var clock = new Thunderclock(io, 7); var clock = new Thunderclock(io, 7);
cpu.addPageHandler(ram1); cpu.addPageHandler(ram1);
@ -538,6 +543,11 @@ function stop() {
runTimer = null; runTimer = null;
} }
export function reset()
{
cpu.reset();
}
var state = null; var state = null;
function storeStateLocal() { function storeStateLocal() {
@ -910,8 +920,12 @@ document.addEventListener('DOMContentLoaded', function() {
document.body.addEventListener('mousemove', _mousemove); document.body.addEventListener('mousemove', _mousemove);
document.querySelectorAll('input,textarea').forEach(function(input) { document.querySelectorAll('input,textarea').forEach(function(input) {
input.addEventListener('input', function() { focused = true; }); input.addEventListener('focus', function() {
input.addEventListener('blur', function() { focused = false; }); focused = true;
});
input.addEventListener('blur', function() {
focused = false;
});
}); });
keyboard.create('#keyboard'); keyboard.create('#keyboard');
@ -995,7 +1009,7 @@ document.addEventListener('DOMContentLoaded', function() {
reptKey.addEventListener('click', function() { reptKey.addEventListener('click', function() {
document.querySelector('#keyboard').style.display = 'none'; document.querySelector('#keyboard').style.display = 'none';
document.querySelector('#textarea').style.display = 'block'; document.querySelector('#textarea').style.display = 'block';
document.querySelector.focus(); document.querySelector('#textarea').focus();
}); });
document.querySelector('#text_input').addEventListener('keydown', function() { document.querySelector('#text_input').addEventListener('keydown', function() {
focused = document.querySelector('#buffering').checked; focused = document.querySelector('#buffering').checked;

View File

@ -39,7 +39,7 @@ var paused = false;
var hashtag; var hashtag;
var DEBUG = false; var DEBUG = true;
var TRACE = false; var TRACE = false;
var MAX_TRACE = 256; var MAX_TRACE = 256;
var trace = []; var trace = [];
@ -49,8 +49,20 @@ var disk_sets = {};
var disk_cur_name = []; var disk_cur_name = [];
var disk_cur_cat = []; var disk_cur_cat = [];
var tape;
var disk2;
var driveLights;
var _currentDrive = 1; var _currentDrive = 1;
export function setTrace(debug, trace) {
DEBUG = debug;
TRACE = trace;
}
export function getTrace() {
return trace;
}
export function openLoad(drive, event) export function openLoad(drive, event)
{ {
_currentDrive = parseInt(drive, 10); _currentDrive = parseInt(drive, 10);
@ -241,6 +253,9 @@ function doLoadHTTP(drive, _url) {
req.responseType = 'arraybuffer'; req.responseType = 'arraybuffer';
req.onload = function() { req.onload = function() {
if (req.status !== 200) {
return window.alert('Unable to load "' + url + '"');
}
var urlParts = url.split('/'); var urlParts = url.split('/');
var file = urlParts.pop(); var file = urlParts.pop();
var fileParts = file.split('.'); var fileParts = file.split('.');
@ -248,7 +263,9 @@ function doLoadHTTP(drive, _url) {
var name = decodeURIComponent(fileParts.join('.')); var name = decodeURIComponent(fileParts.join('.'));
if (disk2.setBinary(drive, name, ext, req.response)) { if (disk2.setBinary(drive, name, ext, req.response)) {
driveLights.label(drive, name); driveLights.label(drive, name);
MicroModal.close('http-modal'); if (!_url) {
MicroModal.close('http-modal');
}
initGamepad(); initGamepad();
} }
}; };
@ -323,11 +340,11 @@ vm.enhanced(enhanced);
vm.multiScreen(multiScreen); vm.multiScreen(multiScreen);
var dumper = new ApplesoftDump(cpu); var dumper = new ApplesoftDump(cpu);
var driveLights = new DriveLights(); driveLights = new DriveLights();
var io = new Apple2IO(cpu, vm); var io = new Apple2IO(cpu, vm);
var keyboard = new KeyBoard(cpu, io, true); var keyboard = new KeyBoard(cpu, io, true);
var audio = new Audio(io); var audio = new Audio(io);
var tape = new Tape(io); tape = new Tape(io);
var printer = new Printer('#printer-modal .paper'); var printer = new Printer('#printer-modal .paper');
var mmu = new MMU(cpu, vm, gr, gr2, hgr, hgr2, io, rom); var mmu = new MMU(cpu, vm, gr, gr2, hgr, hgr2, io, rom);
@ -336,7 +353,7 @@ cpu.addPageHandler(mmu);
var parallel = new Parallel(io, 1, printer); var parallel = new Parallel(io, 1, printer);
var slinky = new RAMFactor(io, 2, 1024 * 1024); var slinky = new RAMFactor(io, 2, 1024 * 1024);
var disk2 = new DiskII(io, 6, driveLights); disk2 = new DiskII(io, 6, driveLights);
var clock = new Thunderclock(io, 7); var clock = new Thunderclock(io, 7);
io.setSlot(1, parallel); io.setSlot(1, parallel);

View File

@ -1,7 +1,7 @@
import CPU6502 from '../js/cpu6502'; import CPU6502 from '../js/cpu6502';
import Test6502 from '../js/roms/6502test'; import Test6502 from './roms/6502test';
import Test65C02 from '../js/roms/65C02test'; import Test65C02 from './roms/65C02test';
import { toHex } from '../js/util'; import { toHex } from '../js/util';

View File

@ -1,5 +1,10 @@
import CPU6502 from '../js/cpu6502'; import CPU6502 from '../js/cpu6502';
function assertByte(b) {
expect(b <= 0xFF).toEqual(true);
expect(b >= 0x00).toEqual(true);
}
function Memory(size) { function Memory(size) {
var data = Buffer.alloc(size << 8); var data = Buffer.alloc(size << 8);
@ -13,10 +18,17 @@ function Memory(size) {
}, },
read: function(page, off) { read: function(page, off) {
assertByte(page);
assertByte(off);
return data[(page << 8) | off]; return data[(page << 8) | off];
}, },
write: function(page, off, val) { write: function(page, off, val) {
assertByte(page);
assertByte(off);
assertByte(val);
data[(page << 8) | off] = val; data[(page << 8) | off] = val;
}, },
@ -38,6 +50,8 @@ function Program(page, code) {
}, },
read: function(page, off) { read: function(page, off) {
assertByte(page);
assertByte(off);
return data[off]; return data[off];
} }
}; };

View File

@ -1,9 +1,5 @@
// From https://github.com/Klaus2m5/6502_65C02_functional_tests // From https://github.com/Klaus2m5/6502_65C02_functional_tests
import { toHex } from '../util';
var LOG = false;
export default function Test6502() { export default function Test6502() {
var data = [ var data = [
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
@ -8211,12 +8207,7 @@ export default function Test6502() {
return data[page * 0x100 + off]; return data[page * 0x100 + off];
}, },
write: function(page, off, val) { write: function(page, off, val) {
/*eslint no-console: 0 */
data[page * 0x100 + off] = val; data[page * 0x100 + off] = val;
if (LOG) {
console.log(toHex(page * 0x100 + off, 4) + ' = ' + toHex(val) +
' ('+ String.fromCharCode(val) + ')');
}
} }
}; };
} }

View File

@ -1,9 +1,5 @@
// From https://github.com/Klaus2m5/6502_65C02_functional_tests // From https://github.com/Klaus2m5/6502_65C02_functional_tests
import { toHex } from '../util';
var LOG = false;
export default function Test65C02() { export default function Test65C02() {
var data = [ var data = [
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
@ -8211,12 +8207,7 @@ export default function Test65C02() {
return data[page * 0x100 + off]; return data[page * 0x100 + off];
}, },
write: function(page, off, val) { write: function(page, off, val) {
/*eslint no-console: 0 */
data[page * 0x100 + off] = val; data[page * 0x100 + off] = val;
if (LOG) {
console.log(toHex(page * 0x100 + off, 4) + ' = ' + toHex(val) +
' ('+ String.fromCharCode(val) + ')');
}
} }
}; };
} }