Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various fixes #19

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ To add additional disk images, use
then

```sh
./bin/index`
./bin/index
```

## Updates
Expand Down
19 changes: 19 additions & 0 deletions bin/index
Original file line number Diff line number Diff line change
Expand Up @@ -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)};`
Expand Down
4 changes: 2 additions & 2 deletions js/cards/disk2.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand All @@ -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));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion js/formats/format_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
}
Expand Down
14 changes: 9 additions & 5 deletions js/ui/apple2.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ function doLoadLocalDisk(drive, file) {
if (_disk2.setBinary(drive, name, ext, this.result)) {
driveLights.label(drive, name);
MicroModal.close('loading-modal');
focused = false;
initGamepad();
}
};
Expand Down Expand Up @@ -399,7 +400,7 @@ function updateLocalStorage() {
document.querySelector('#manage-modal-content').innerHTML =
'<span class="local_save">' +
name +
' <a href="#" onclick="doDelete(\'' +
' <a href="#" onclick="Apple2.doDelete(\'' +
name +
'\')">Delete</a><br /></span>';
});
Expand Down Expand Up @@ -549,15 +550,17 @@ 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
keyboard.commandKey(true);
} else if (evt.keyCode == 18) { // Alt
if (evt.location == 1) {
keyboard.commandKey(true);
} else {
keyboard.optionKey(true);
} else {
keyboard.commandKey(true);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This configuration was selected to allow keyboards with only Alt keys (in this case a Chromebook) to be able to use the apple keys and match the layout. I'm not sure this change matches the correct behavior, since now neither right side option or command activates closed apple.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change was so my Mac keyboard would do both open- and closed- apple on option and command keys. Apologies if it breaks other keyboards/OSs.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The way it currently works is both command/open-apple keys generate open-apple, and left option/alt generates open-apple and right alt generates closed-apple, which I think is the standard Mac keyboard. The problem is probably more of a doc issue. Someday I will write some docs.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry. My previous comment was wrong. The change was because the left option key on the Mac keyboard was triggering the right (closed-apple) key on the virtual keyboard, and the right option key on the Mac keyboard was triggering the left (open-apple) key on the virtual keyboard. With the change above, the side of the Mac keyboard key matched the virtual keyboard. I also have my Mac option and command keys swapped, so for me it was the command keys in each case. However, it is not a big issue. Let me know if you want any more help with this.

}
}
}
Expand All @@ -574,9 +577,9 @@ function _keyup(evt) {
keyboard.commandKey(false);
} else if (evt.keyCode == 18) { // Alt
if (evt.location == 1) {
keyboard.commandKey(false);
} else {
keyboard.optionKey(false);
} else {
keyboard.commandKey(false);
}
}
}
Expand Down Expand Up @@ -715,6 +718,7 @@ export function initUI(apple2, disk2, 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; });
});

Expand Down
32 changes: 27 additions & 5 deletions js/ui/keyboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -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], // , - <
Expand Down Expand Up @@ -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;

Expand All @@ -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));
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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':
Expand Down