Basic copy and paste.

This commit is contained in:
Will Scullin 2020-09-03 22:39:16 -07:00
parent 1e56b0af63
commit ffe8a76c86
No known key found for this signature in database
GPG Key ID: 9092A5C0A673416B
3 changed files with 57 additions and 26 deletions

View File

@ -103,32 +103,6 @@
<div class="inset">
<div style="margin: 0 10px">
<div id="keyboard"></div>
<div id="textarea" style="display: none">
<button onclick="Apple2.io.keyDown(0x1b)">
ESC
</button>
<button onclick="Apple2.reset()" style="float: right; margin-left: 10px">
Reset
</button>
<button onclick="Apple2.io.keyDown(0x15)" style="float: right">
&rarr;
</button>
<button onclick="Apple2.io.keyDown(0x08)" style="float: right">
&larr;
</button>
<label for="text_input">Text Input</label>
<textarea rows="10" style="width: 99%" id="text_input"></textarea>
<br />
<button onclick="Apple2.io.setKeyBuffer(document.querySelector('#text_input').value)">
Send
</button>
<input type="checkbox" id="buffering" />
<label for="buffering">Buffer</label>
<button style="float: right"
onclick="document.querySelector('#keyboard').style.display = 'block'; document.querySelector('#textarea').style.display = 'none'">
Keyboard
</button>
</div>
</div>
</div>
</div>

View File

@ -456,6 +456,47 @@ export function LoresPage(page, charset, e, context)
_buffer[1] = base64_decode(state.buffer[1]);
this.refresh();
},
getText() {
function rowToBase(row) {
var ab = (row >> 3) & 3;
var cd = (row >> 1) & 0x3;
var e = row & 1;
return (cd << 8) | (e << 7) | (ab << 5) | (ab << 3);
}
function mapCharCode(charCode) {
charCode &= 0x7F;
if (charCode < 0x20) {
charCode += 0x40;
}
if (!e && (charCode >= 0x60)) {
charCode -= 0x40;
}
return charCode;
}
var buffer = '', line, charCode;
var row, col, base;
for (row = 0; row < 24; row++) {
base = rowToBase(row);
line = '';
if (e && _80colMode) {
for (col = 0; col < 80; col++) {
charCode = mapCharCode(_buffer[1 - col % 2][base + Math.floor(col / 2)]);
line += String.fromCharCode(charCode);
}
} else {
for (col = 0; col < 40; col++) {
charCode = mapCharCode(_buffer[0][base + col]);
line += String.fromCharCode(charCode);
}
}
line = line.trimRight();
buffer += line + '\n';
}
return buffer;
}
};
}
@ -1107,6 +1148,9 @@ export function VideoModes(gr, hgr, gr2, hgr2, e) {
_grs[1].mono(on);
_hgrs[0].mono(on);
_hgrs[1].mono(on);
},
getText() {
return _grs[pageMode - 1].getText();
}
};
}

View File

@ -587,6 +587,7 @@ function processHash(hash) {
}
}
/*
* Keyboard/Gamepad routines
*/
@ -797,6 +798,18 @@ export function initUI(apple2, disk2, cffa, e) {
}
window.addEventListener('mousedown', audio.autoStart);
window.addEventListener('paste', (event) => {
var paste = (event.clipboardData || window.clipboardData).getData('text');
io.setKeyBuffer(paste);
event.preventDefault();
});
window.addEventListener('copy', (event) => {
event.clipboardData.setData('text/plain', vm.getText());
event.preventDefault();
});
document.querySelectorAll('canvas').forEach(function(canvas) {
canvas.addEventListener('mousedown', function(evt) {
if (!gamepad) {