From bb6e36f964b51bcb51a825a3a6cf5b0169686df5 Mon Sep 17 00:00:00 2001 From: Will Scullin Date: Thu, 23 Apr 2020 19:47:44 -0700 Subject: [PATCH] Various fixes (#23) * Sort disks in category order * Fix saving disk * Fix keyboard not working after modal * Make caps lock key on keyboard work, while keeping caps lock on virtual keyboard working too * Fix delete local storage * Fix minus key on Mac * Remove backtick * Credit. Co-authored-by: Matthew Hebley --- README.md | 5 ++++- bin/index | 19 +++++++++++++++++++ js/cards/disk2.js | 4 ++-- js/formats/format_utils.js | 2 +- js/ui/apple2.js | 7 ++++++- js/ui/keyboard.js | 32 +++++++++++++++++++++++++++----- 6 files changed, 59 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index c69828f..9e6e4d6 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ To add additional disk images, use then ```sh -./bin/index` +./bin/index ``` ## Updates @@ -170,3 +170,6 @@ then * [Gil Megidish](http://www.megidish.net/apple2js/), for the kick in the pants to finally post my version, once I realized there was, in fact, another apple2js in the world. * [AppleWin](https://github.com/AppleWin/AppleWin/), whose source code is a goldmine of useful references. * [Zellyn Hunter](https://github.com/zellyn/a2audit) and a2audit, for allowing me to get really nitpicky in my memory emulation. + +* Contributors + * [Snapperfish](http://github.com/Snapperfish) Various fixes diff --git a/bin/index b/bin/index index caf472f..44324f8 100755 --- a/bin/index +++ b/bin/index @@ -26,6 +26,25 @@ for (const fileName of dir.sort()) { } } +index.sort((x,y) => { + const xc = x.category.toLowerCase(); + const yc = y.category.toLowerCase(); + const xn = x.name.toLowerCase(); + const yn = y.name.toLowerCase(); + + if (xc < yc) { + return -1; + } else if (xc > yc) { + return 1; + } else if (xn < yn) { + return -1; + } else if (xn > yn) { + return 1; + } else { + return 0; + } +}); + fs.writeFileSync( path.resolve(diskPath, 'index.js'), `disk_index = ${JSON.stringify(index, null, 2)};` diff --git a/js/cards/disk2.js b/js/cards/disk2.js index 6cc5fef..c6f28e6 100644 --- a/js/cards/disk2.js +++ b/js/cards/disk2.js @@ -659,7 +659,7 @@ export default function DiskII(io, callbacks, sectors = 16) data[idx++] = cur.tracks[t]; } else { for (var s = 0; s < 0x10; s++) { - var sector = readSector(cur, t); + var sector = readSector(cur, t, s); for (var b = 0; b < 256; b++) { data[idx++] = sector[b]; } @@ -679,7 +679,7 @@ export default function DiskII(io, callbacks, sectors = 16) data += base64_encode(cur.tracks[t]); } else { for (var s = 0; s < 0x10; s++) { - data += base64_encode(readSector(cur, t)); + data += base64_encode(readSector(cur, t, s)); } } } diff --git a/js/formats/format_utils.js b/js/formats/format_utils.js index aea4496..9a745f9 100644 --- a/js/formats/format_utils.js +++ b/js/formats/format_utils.js @@ -390,7 +390,7 @@ export function jsonEncode(cur, pretty) { data[t] = base64_encode(cur.tracks[t]); } else { for (var s = 0; s < 0x10; s++) { - data[t][s] = base64_encode(readSector(cur, t)); + data[t][s] = base64_encode(readSector(cur, t, s)); } } } diff --git a/js/ui/apple2.js b/js/ui/apple2.js index 1b126bd..6db322f 100644 --- a/js/ui/apple2.js +++ b/js/ui/apple2.js @@ -262,11 +262,13 @@ function doLoadLocalDisk(drive, file) { if (this.result.byteLength >= 800 * 1024) { if (_cffa.setBinary(drive, name, ext, this.result)) { driveLights.label(drive, name); + focused = false; initGamepad(); } } else { if (_disk2.setBinary(drive, name, ext, this.result)) { driveLights.label(drive, name); + focused = false; initGamepad(); } } @@ -486,7 +488,7 @@ function updateLocalStorage() { document.querySelector('#manage-modal-content').innerHTML = '' + name + - ' Delete
'; }); @@ -630,6 +632,8 @@ function _keydown(evt) { _apple2.restoreState(); } else if (evt.keyCode == 16) { // Shift keyboard.shiftKey(true); + } else if (evt.keyCode == 20) { // Caps lock + keyboard.capslockKey(); } else if (evt.keyCode == 17) { // Control keyboard.controlKey(true); } else if (evt.keyCode == 91 || evt.keyCode == 93) { // Command @@ -814,6 +818,7 @@ export function initUI(apple2, disk2, cffa, e) { document.querySelectorAll('input,textarea').forEach(function(input) { input.addEventListener('input', function() { focused = true; }); + input.addEventListener('focus', function() { focused = true; }); input.addEventListener('blur', function() { focused = false; }); }); diff --git a/js/ui/keyboard.js b/js/ui/keyboard.js index 43995b5..b941694 100644 --- a/js/ui/keyboard.js +++ b/js/ui/keyboard.js @@ -138,6 +138,7 @@ export default function KeyBoard(cpu, io, e) { 0x6F: [0x2F, 0x2F, 0x39], // / // Stray keys + 0xAD: [0x2D, 0x2D, 0x5F], // - - _ 0xBA: [0x3B, 0x3B, 0x3A], // ; - : 0xBB: [0x3D, 0x3D, 0x2B], // = - + 0xBC: [0x2C, 0x2C, 0x3C], // , - < @@ -199,6 +200,9 @@ export default function KeyBoard(cpu, io, e) { var shifted = false; var controlled = false; var capslocked = true; + // Initially caps lock on physical keyboard is assumed to be off, + // but on emulated keyboard it is on. + var capslockKeyUsed = false; var optioned = false; var commanded = false; @@ -212,8 +216,14 @@ export default function KeyBoard(cpu, io, e) { key = uiKitMap[evt.key]; } else if (code in keymap) { key = keymap[code][evt.shiftKey ? 2 : (evt.ctrlKey ? 1 : 0)]; - if (capslocked && key >= 0x61 && key <= 0x7A) + + if (code != 20 && capslockKeyUsed) { + this.capslockKey(evt.getModifierState("CapsLock")); + } + + if (capslocked && key >= 0x61 && key <= 0x7A) { key -= 0x20; + } } else { debug('Unhandled key = ' + toHex(code)); } @@ -274,13 +284,25 @@ export default function KeyBoard(cpu, io, e) { capslockKey: function keyboard_caplockKey(down) { var capsLock = kb.querySelector('.key-LOCK'); - capslocked = down; - if (down) { + + if (arguments.length == 0) { + if (capslockKeyUsed) { + capslocked = !capslocked; + } else { + capslockKeyUsed = true; + } + } else if (down === undefined) { + capslocked = !capslocked; + capslockKeyUsed = false; + } else { + capslocked = down; + } + + if (capslocked) { capsLock.classList.add('active'); } else { capsLock.classList.remove('active'); } - }, reset: function keyboard_reset(event) { @@ -354,7 +376,7 @@ export default function KeyBoard(cpu, io, e) { break; case 'CAPS': case 'LOCK': - self.capslockKey(!capslocked); + self.capslockKey(undefined); break; case 'POW': case 'POWER':