From 37a6efc66101471c8025055723af9820764c2014 Mon Sep 17 00:00:00 2001 From: Will Scullin Date: Wed, 16 Oct 2019 20:18:53 -0700 Subject: [PATCH] Better linting, tests, fix text buffer, ROR. --- .eslintrc.json | 10 +++++++++- apple2js.html | 2 +- js/cpu6502.js | 2 +- js/formats/format_utils.js | 2 +- js/main2.js | 30 ++++++++++++++++++++++-------- js/main2e.js | 27 ++++++++++++++++++++++----- test/cpu.spec.js | 4 ++-- test/cpu6502.spec.js | 14 ++++++++++++++ {js => test}/roms/6502test.js | 9 --------- {js => test}/roms/65C02test.js | 9 --------- 10 files changed, 72 insertions(+), 37 deletions(-) rename {js => test}/roms/6502test.js (99%) rename {js => test}/roms/65C02test.js (99%) diff --git a/.eslintrc.json b/.eslintrc.json index 9edc9b7..9d51f88 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -15,6 +15,10 @@ "semi": [ 2, "always" + ], + "no-use-before-define": [ + 2, + { "functions": false } ] }, "env": { @@ -38,11 +42,15 @@ "browser": false } }, { - "files": [ "test/*"], + "files": [ "test/**/*"], "env": { "jest": true, "node": true + }, + "rules": { + "no-console": 0 } + }, { "files": [ "js/entry2.js", "js/entry2e.js"], "env": { diff --git a/apple2js.html b/apple2js.html index 7ab66cc..bb7e0cc 100644 --- a/apple2js.html +++ b/apple2js.html @@ -121,7 +121,7 @@
- diff --git a/js/cpu6502.js b/js/cpu6502.js index c752222..67ac350 100644 --- a/js/cpu6502.js +++ b/js/cpu6502.js @@ -636,7 +636,7 @@ export default function CPU6502(options) function ror(readAddrFn) { var addr = readAddrFn({rwm: true}); var oldVal = readByte(addr); - writeByte(addr, val); + writeByte(addr, oldVal); var val = rotateRight(oldVal); writeByte(addr, val); } diff --git a/js/formats/format_utils.js b/js/formats/format_utils.js index 0b1de62..aea4496 100644 --- a/js/formats/format_utils.js +++ b/js/formats/format_utils.js @@ -286,7 +286,7 @@ export function explodeSector13(volume, track, sector, data) { } 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 idx = 0; var retry = 0; diff --git a/js/main2.js b/js/main2.js index 86b29c9..bdfcf7a 100644 --- a/js/main2.js +++ b/js/main2.js @@ -54,6 +54,9 @@ var disk_sets = {}; var disk_cur_name = []; var disk_cur_cat = []; +var tape; +var disk2; +var driveLights; var _currentDrive = 1; export function openLoad(drive, event) @@ -252,7 +255,9 @@ function doLoadHTTP(drive, _url) { var name = decodeURIComponent(fileParts.join('.')); if (disk2.setBinary(drive, name, ext, req.response)) { driveLights.label(drive, name); - MicroModal.close('http-modal'); + if (!_url) { + MicroModal.close('http-modal'); + } initGamepad(); } }; @@ -338,18 +343,18 @@ var vm = new VideoModes(gr, hgr, gr2, hgr2, false); vm.multiScreen(multiScreen); var dumper = new ApplesoftDump(cpu); -var driveLights = new DriveLights(); -var io = new Apple2IO(cpu, vm); +driveLights = new DriveLights(); +export var io = new Apple2IO(cpu, vm); var keyboard = new KeyBoard(cpu, io); var audio = new Audio(io); -var tape = new Tape(io); +tape = new Tape(io); var printer = new Printer('#printer-modal .paper'); var lc = new LanguageCard(io, 0, rom); var parallel = new Parallel(io, 1, printer); var slinky = new RAMFactor(io, 2, 1024 * 1024); 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); cpu.addPageHandler(ram1); @@ -538,6 +543,11 @@ function stop() { runTimer = null; } +export function reset() +{ + cpu.reset(); +} + var state = null; function storeStateLocal() { @@ -910,8 +920,12 @@ document.addEventListener('DOMContentLoaded', function() { document.body.addEventListener('mousemove', _mousemove); document.querySelectorAll('input,textarea').forEach(function(input) { - input.addEventListener('input', function() { focused = true; }); - input.addEventListener('blur', function() { focused = false; }); + input.addEventListener('focus', function() { + focused = true; + }); + input.addEventListener('blur', function() { + focused = false; + }); }); keyboard.create('#keyboard'); @@ -995,7 +1009,7 @@ document.addEventListener('DOMContentLoaded', function() { reptKey.addEventListener('click', function() { document.querySelector('#keyboard').style.display = 'none'; document.querySelector('#textarea').style.display = 'block'; - document.querySelector.focus(); + document.querySelector('#textarea').focus(); }); document.querySelector('#text_input').addEventListener('keydown', function() { focused = document.querySelector('#buffering').checked; diff --git a/js/main2e.js b/js/main2e.js index a029ecd..f35811c 100644 --- a/js/main2e.js +++ b/js/main2e.js @@ -39,7 +39,7 @@ var paused = false; var hashtag; -var DEBUG = false; +var DEBUG = true; var TRACE = false; var MAX_TRACE = 256; var trace = []; @@ -49,8 +49,20 @@ var disk_sets = {}; var disk_cur_name = []; var disk_cur_cat = []; +var tape; +var disk2; +var driveLights; var _currentDrive = 1; +export function setTrace(debug, trace) { + DEBUG = debug; + TRACE = trace; +} + +export function getTrace() { + return trace; +} + export function openLoad(drive, event) { _currentDrive = parseInt(drive, 10); @@ -241,6 +253,9 @@ function doLoadHTTP(drive, _url) { req.responseType = 'arraybuffer'; req.onload = function() { + if (req.status !== 200) { + return window.alert('Unable to load "' + url + '"'); + } var urlParts = url.split('/'); var file = urlParts.pop(); var fileParts = file.split('.'); @@ -248,7 +263,9 @@ function doLoadHTTP(drive, _url) { var name = decodeURIComponent(fileParts.join('.')); if (disk2.setBinary(drive, name, ext, req.response)) { driveLights.label(drive, name); - MicroModal.close('http-modal'); + if (!_url) { + MicroModal.close('http-modal'); + } initGamepad(); } }; @@ -323,11 +340,11 @@ vm.enhanced(enhanced); vm.multiScreen(multiScreen); var dumper = new ApplesoftDump(cpu); -var driveLights = new DriveLights(); +driveLights = new DriveLights(); var io = new Apple2IO(cpu, vm); var keyboard = new KeyBoard(cpu, io, true); var audio = new Audio(io); -var tape = new Tape(io); +tape = new Tape(io); var printer = new Printer('#printer-modal .paper'); 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 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); io.setSlot(1, parallel); diff --git a/test/cpu.spec.js b/test/cpu.spec.js index 15d82c3..ac1afd2 100644 --- a/test/cpu.spec.js +++ b/test/cpu.spec.js @@ -1,7 +1,7 @@ import CPU6502 from '../js/cpu6502'; -import Test6502 from '../js/roms/6502test'; -import Test65C02 from '../js/roms/65C02test'; +import Test6502 from './roms/6502test'; +import Test65C02 from './roms/65C02test'; import { toHex } from '../js/util'; diff --git a/test/cpu6502.spec.js b/test/cpu6502.spec.js index 3851786..a910481 100644 --- a/test/cpu6502.spec.js +++ b/test/cpu6502.spec.js @@ -1,5 +1,10 @@ import CPU6502 from '../js/cpu6502'; +function assertByte(b) { + expect(b <= 0xFF).toEqual(true); + expect(b >= 0x00).toEqual(true); +} + function Memory(size) { var data = Buffer.alloc(size << 8); @@ -13,10 +18,17 @@ function Memory(size) { }, read: function(page, off) { + assertByte(page); + assertByte(off); + return data[(page << 8) | off]; }, write: function(page, off, val) { + assertByte(page); + assertByte(off); + assertByte(val); + data[(page << 8) | off] = val; }, @@ -38,6 +50,8 @@ function Program(page, code) { }, read: function(page, off) { + assertByte(page); + assertByte(off); return data[off]; } }; diff --git a/js/roms/6502test.js b/test/roms/6502test.js similarity index 99% rename from js/roms/6502test.js rename to test/roms/6502test.js index 11686a6..0cf15fb 100644 --- a/js/roms/6502test.js +++ b/test/roms/6502test.js @@ -1,9 +1,5 @@ // From https://github.com/Klaus2m5/6502_65C02_functional_tests -import { toHex } from '../util'; - -var LOG = false; - export default function Test6502() { var data = [ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, @@ -8211,12 +8207,7 @@ export default function Test6502() { return data[page * 0x100 + off]; }, write: function(page, off, val) { - /*eslint no-console: 0 */ data[page * 0x100 + off] = val; - if (LOG) { - console.log(toHex(page * 0x100 + off, 4) + ' = ' + toHex(val) + - ' ('+ String.fromCharCode(val) + ')'); - } } }; } diff --git a/js/roms/65C02test.js b/test/roms/65C02test.js similarity index 99% rename from js/roms/65C02test.js rename to test/roms/65C02test.js index f4eba0f..d56ab50 100644 --- a/js/roms/65C02test.js +++ b/test/roms/65C02test.js @@ -1,9 +1,5 @@ // From https://github.com/Klaus2m5/6502_65C02_functional_tests -import { toHex } from '../util'; - -var LOG = false; - export default function Test65C02() { var data = [ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, @@ -8211,12 +8207,7 @@ export default function Test65C02() { return data[page * 0x100 + off]; }, write: function(page, off, val) { - /*eslint no-console: 0 */ data[page * 0x100 + off] = val; - if (LOG) { - console.log(toHex(page * 0x100 + off, 4) + ' = ' + toHex(val) + - ' ('+ String.fromCharCode(val) + ')'); - } } }; }