Export instead of attach to window, and make webpack like it.

This commit is contained in:
Will Scullin 2019-03-31 20:52:45 -07:00
parent 2963f116ce
commit 542786e87c
No known key found for this signature in database
GPG Key ID: 9092A5C0A673416B
11 changed files with 197 additions and 203 deletions

View File

@ -43,6 +43,11 @@
"env": {
"jest": true
}
}, {
"files": [ "js/entry2.js", "js/entry2e.js"],
"env": {
"commonjs": true
}
}
]
}

View File

@ -34,9 +34,9 @@
</head>
<body class="apple2"
ondragover="handleDragOver(0, event)"
ondrop="handleDrop(0, event)"
ondragend="handleDragEnd(0, event)">
ondragover="Apple2.handleDragOver(0, event)"
ondrop="Apple2.handleDrop(0, event)"
ondragend="Apple2.handleDragEnd(0, event)">
<div style="margin: auto; width: 614px">
<div id="header">
<a href="about.html" target="_blank">
@ -51,30 +51,30 @@
</div>
<div class="inset">
<div style="float: left; width: 50%"
ondragover="handleDragOver(1, event)"
ondrop="handleDrop(1, event)"
ondragend="handleDragEnd(1, event)">
ondragover="Apple2.handleDragOver(1, event)"
ondrop="Apple2.handleDrop(1, event)"
ondragend="Apple2.handleDragEnd(1, event)">
<button id="diskload1" class="diskload" title="Load Disk"
onclick="openLoad(1, event);">
onclick="Apple2.openLoad(1, event);">
<i class="fas fa-folder-open"></i>
</button>
<button id="disksave1" class="disksave" title="Save Disk"
onclick="openSave(1, event);">
onclick="Apple2.openSave(1, event);">
<i class="fas fa-save"></i>
</button>
<div class="disk" id="disk1">&nbsp;</div>
<span id="disklabel1" class="disklabel">Disk 1</span>
</div>
<div style="float: left; width: 50%"
ondragover="handleDragOver(2, event)"
ondrop="handleDrop(2, event)"
ondragend="handleDragEnd(2, event)">
ondragover="Apple2.handleDragOver(2, event)"
ondrop="Apple2.handleDrop(2, event)"
ondragend="Apple2.handleDragEnd(2, event)">
<button id="diskload2" class="diskload" title="Load Disk"
onclick="openLoad(2, event);">
onclick="Apple2.openLoad(2, event);">
<i class="fas fa-folder-open"></i>
</button>
<button id="disksave2" class="disksave" title="Save Disk"
onclick="openSave(2, event);">
onclick="Apple2.openSave(2, event);">
<i class="fas fa-save"></i>
</button>
<div class="disk" id="disk2">&nbsp;</div>
@ -83,21 +83,21 @@
<div style="clear: both"></div>
</div>
<div class="inset">
<div id="khz" onclick="showFPS = !showFPS">0KHz</div>
<button id="pause-run" onclick="pauseRun()" title="Pause/Run">
<div id="khz" onclick="Apple2.togglShowFPS()">0KHz</div>
<button id="pause-run" onclick="Apple2.pauseRun()" title="Pause/Run">
<i class="fas fa-pause"></i>
</button>
<button id="toggle-sound" onclick="toggleSound()" title="Toggle Sound">
<button id="toggle-sound" onclick="Apple2.toggleSound()" title="Toggle Sound">
<i class="fas fa-volume-off"></i>
</button>
<button id="toggle-printer" onclick="openPrinterModal()" title="Toggle Printer">
<button id="toggle-printer" onclick="Apple2.openPrinterModal()" title="Toggle Printer">
<i class="fas fa-print"></i>
</button>
<div style="float: right">
<button onclick="window.open('about.html', 'blank')" title="About">
<i class="fas fa-info"></i>
</button>
<button onclick="openOptions()" title="Options">
<button onclick="Apple2.openOptions()" title="Options">
<i class="fas fa-cog"></i>
</button>
</div>
@ -106,22 +106,22 @@
<div style="margin: 0 10px">
<div id="keyboard"></div>
<div id="textarea" style="display: none">
<button onclick="io.keyDown(0x1b)">
<button onclick="Apple2.io.keyDown(0x1b)">
ESC
</button>
<button onclick="reset()" style="float: right; margin-left: 10px">
<button onclick="Apple2.reset()" style="float: right; margin-left: 10px">
Reset
</button>
<button onclick="io.keyDown(0x15)" style="float: right">
<button onclick="Apple2.io.keyDown(0x15)" style="float: right">
&rarr;
</button>
<button onclick="io.keyDown(0x08)" style="float: right">
<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="io.setKeyBuffer(document.querySelector('#text_input').innerText)">
<button onclick="Apple2.io.setKeyBuffer(document.querySelector('#text_input').innerText)">
Send
</button>
<input type="checkbox" id="buffering" />
@ -161,7 +161,7 @@
<h3>Type</h3>
<ul>
<li>
<select id="computer_type2" value="apple2plus" onchange="updateCPU()">
<select id="computer_type2" value="apple2plus" onchange="Apple2.updateCPU()">
<option value="apple2plus">Apple ][+</option>
<option value="apple2">Autostart Apple ][</option>
<option value="original">Apple ][</option>
@ -177,7 +177,7 @@
<h3>CPU</h3>
<ul>
<li>
<input type="checkbox" id="accelerator_toggle" onclick="updateCPU()"/>
<input type="checkbox" id="accelerator_toggle" onclick="Apple2.updateCPU()"/>
<label for="accelerator_toggle">
Accelerated CPU
</label>
@ -187,28 +187,28 @@
<ul>
<li>
<input type="checkbox" id="disable_mouse"
onclick="updateJoystick()" />
onclick="Apple2.updateJoystick()" />
<label for="disable_mouse">
Disable Mouse Joystick
</label>
</li>
<li>
<input type="checkbox" id="flip_x"
onclick="updateJoystick()" />
onclick="Apple2.updateJoystick()" />
<label for="flip_x">
Flip X-Axis
</label>
</li>
<li>
<input type="checkbox" id="flip_y"
onclick="updateJoystick()" />
onclick="Apple2.updateJoystick()" />
<label for="flip_y">
Flip Y-Axis
</label>
</li>
<li>
<input type="checkbox" id="swap_x_y"
onclick="updateJoystick()" />
onclick="Apple2.updateJoystick()" />
<label for="swap_x_y">
Swap X-Y Axis
</label>
@ -218,14 +218,14 @@
<ul>
<li>
<input type="checkbox" id="green_screen"
onclick="updateScreen()" />
onclick="Apple2.updateScreen()" />
<label for="green_screen">
Green Screen
</label>
</li>
<li>
<input type="checkbox" id="show_scanlines"
onclick="updateScreen()" />
onclick="Apple2.updateScreen()" />
<label for="show_scanlines">
Show Scanlines
</label>
@ -235,7 +235,7 @@
<ul>
<li>
<input type="checkbox" id="enable_sound"
onclick="updateSound()" checked="checked" />
onclick="Apple2.updateSound()" checked="checked" />
<label for="enable_sound">
Enable
</label>
@ -272,7 +272,7 @@
</div>
</main>
<footer class="modal__footer">
<button class="modal__btn" onclick="doSave()" aria-label="Save disk locally">Save</button>
<button class="modal__btn" onclick="Apple2.doSave()" aria-label="Save disk locally">Save</button>
</footer>
</div>
</div>
@ -334,13 +334,13 @@
<tr>
<td>
<select id="category_select" multiple="multiple"
onchange="selectCategory(event)" >
onchange="Apple2.selectCategory(event)" >
</select>
</td>
<td>
<select id="disk_select" multiple="multiple"
onchange="selectDisk(event)"
ondblclick="clickDisk(event)">
onchange="Apple2.selectDisk(event)"
ondblclick="Apple2.clickDisk(event)">
</select>
</td>
</tr>
@ -351,7 +351,7 @@
</main>
<footer class="modal__footer">
<button class="modal__btn" data-micromodal-close aria-label="Close this dialog window">Cancel</button>
<button class="modal__btn" onclick="doLoad()" aria-label="Open the selected disk">Open</button>
<button class="modal__btn" onclick="Apple2.doLoad()" aria-label="Open the selected disk">Open</button>
</footer>
</div>
</div>

View File

@ -34,9 +34,9 @@
</head>
<body class="apple2e"
ondragover="handleDragOver(0, event)"
ondrop="handleDrop(0, event)"
ondragend="handleDragEnd(0, event)">
ondragover="Apple2.handleDragOver(0, event)"
ondrop="Apple2.handleDrop(0, event)"
ondragend="Apple2.handleDragEnd(0, event)">
<div class="outer">
<div id="header">
<a href="about.html" target="_blank">
@ -46,37 +46,37 @@
</div>
<div id="display">
<div class="overscan"
onkeydown="_keydown(event);"
onkeyup="_keyup(event);">
onkeydown="Apple2._keydown(event);"
onkeyup="Apple2._keyup(event);">
<canvas id="screen" width="560" height="384"></canvas>
</div>
</div>
<div class="inset">
<div style="float: left; width: 50%"
ondragover="handleDragOver(1, event)"
ondrop="handleDrop(1, event)"
ondragend="handleDragEnd(1, event)">
ondragover="Apple2.handleDragOver(1, event)"
ondrop="Apple2.handleDrop(1, event)"
ondragend="Apple2.handleDragEnd(1, event)">
<button id="diskload1" class="diskload" title="Load Disk"
onclick="openLoad(1, event);">
onclick="Apple2.openLoad(1, event);">
<i class="fas fa-folder-open"></i>
</button>
<button id="disksave1" class="disksave" title="Save Disk"
onclick="openSave(1, event);">
onclick="Apple2.openSave(1, event);">
<i class="fas fa-save"></i>
</button>
<div class="disk" id="disk1">&nbsp;</div>
<span id="disklabel1" class="disklabel">Disk 1</span>
</div>
<div style="float: left; width: 50%"
ondragover="handleDragOver(2, event)"
ondrop="handleDrop(2, event)"
ondragend="handleDragEnd(2, event)">
ondragover="Apple2.handleDragOver(2, event)"
ondrop="Apple2.handleDrop(2, event)"
ondragend="Apple2.handleDragEnd(2, event)">
<button id="diskload2" class="diskload" title="Load Disk"
onclick="openLoad(2, event);">
onclick="Apple2.openLoad(2, event);">
<i class="fas fa-folder-open"></i>
</button>
<button id="disksave2" class="disksave" title="Save Disk"
onclick="openSave(2, event);">
onclick="Apple2.openSave(2, event);">
<i class="fas fa-save"></i>
</button>
<div class="disk" id="disk2">&nbsp;</div>
@ -86,28 +86,28 @@
</div>
<div style="position: relative">
<div id="controls" class="inset">
<div id="khz" onclick="showFPS = !showFPS">0KHz</div>
<button id="pause-run" onclick="pauseRun()">
<div id="khz" onclick="Apple2.toggleShowFPS()">0KHz</div>
<button id="pause-run" onclick="Apple2.pauseRun()">
<i class="fas fa-pause"></i>
</button>
<button id="toggle-sound" onclick="toggleSound()">
<button id="toggle-sound" onclick="Apple2.toggleSound()">
<i class="fas fa-volume-off"></i>
</button>
<button id="toggle-printer" onclick="openPrinterModal()" title="Toggle Printer">
<button id="toggle-printer" onclick="Apple2.openPrinterModal()" title="Toggle Printer">
<i class="fas fa-print"></i>
</button>
<div style="float: right">
<button onclick="window.open('about.html', 'blank')" title="About">
<button onclick="Apple2.window.open('about.html', 'blank')" title="About">
<i class="fas fa-info"></i>
</button>
<button onclick="openOptions()">
<button onclick="Apple2.openOptions()">
<i class="fas fa-cog"></i>
</button>
</div>
</div>
<input id="reset" type="button" value="Reset"
onclick="reset(event)"
oncontextmenu="reset(event)" />
onclick="Apple2.reset(event)"
oncontextmenu="Apple2.reset(event)" />
</div>
<div class="inset">
<div id="keyboard"></div>
@ -140,7 +140,7 @@
<h3>Type</h3>
<ul>
<li>
<select id="computer_type2e" value="apple2enh" onchange="updateCPU()">
<select id="computer_type2e" value="apple2enh" onchange="Apple2.updateCPU()">
<option value="apple2enh">Enhanced Apple //e</option>
<option value="apple2e">Apple //e</option>
<option value="apple2rm">Enhanced Apple //e (Reactive Micro)</option>
@ -153,7 +153,7 @@
<h3>CPU</h3>
<ul>
<li>
<input type="checkbox" id="accelerator_toggle" onclick="updateCPU()"/>
<input type="checkbox" id="accelerator_toggle" onclick="Apple2.updateCPU()"/>
<label for="accelerator_toggle">
Accelerated CPU
</label>
@ -163,28 +163,28 @@
<ul>
<li>
<input type="checkbox" id="disable_mouse"
onclick="updateJoystick()" />
onclick="Apple2.updateJoystick()" />
<label for="disable_mouse">
Disable Mouse Joystick
</label>
</li>
<li>
<input type="checkbox" id="flip_x"
onclick="updateJoystick()" />
onclick="Apple2.updateJoystick()" />
<label for="flip_x">
Flip X-Axis
</label>
</li>
<li>
<input type="checkbox" id="flip_y"
onclick="updateJoystick()" />
onclick="Apple2.updateJoystick()" />
<label for="flip_y">
Flip Y-Axis
</label>
</li>
<li>
<input type="checkbox" id="swap_x_y"
onclick="updateJoystick()" />
onclick="Apple2.updateJoystick()" />
<label for="swap_x_y">
Swap X-Y Axis
</label>
@ -194,14 +194,14 @@
<ul>
<li>
<input type="checkbox" id="green_screen"
onclick="updateScreen()" />
onclick="Apple2.updateScreen()" />
<label for="green_screen">
Green Screen
</label>
</li>
<li>
<input type="checkbox" id="show_scanlines"
onclick="updateScreen()" />
onclick="Apple2.updateScreen()" />
<label for="show_scanlines">
Show Scanlines
</label>
@ -211,7 +211,7 @@
<ul>
<li>
<input type="checkbox" id="enable_sound"
onclick="updateSound()" checked="checked" />
onclick="Apple2.updateSound()" checked="checked" />
<label for="enable_sound">
Enable
</label>
@ -248,7 +248,7 @@
</div>
</main>
<footer class="modal__footer">
<button class="modal__btn" onclick="doSave()" aria-label="Save disk locally">Save</button>
<button class="modal__btn" onclick="Apple2.doSave()" aria-label="Save disk locally">Save</button>
</footer>
</div>
</div>
@ -310,13 +310,13 @@
<tr>
<td>
<select id="category_select" multiple="multiple"
onchange="selectCategory(event)" >
onchange="Apple2.selectCategory(event)" >
</select>
</td>
<td>
<select id="disk_select" multiple="multiple"
onchange="selectDisk(event)"
ondblclick="clickDisk(event)">
onchange="Apple2.selectDisk(event)"
ondblclick="Apple2.clickDisk(event)">
</select>
</td>
</tr>
@ -327,7 +327,7 @@
</main>
<footer class="modal__footer">
<button class="modal__btn" data-micromodal-close aria-label="Close this dialog window">Cancel</button>
<button class="modal__btn" onclick="doLoad()" aria-label="Open the selected disk">Open</button>
<button class="modal__btn" onclick="Apple2.doLoad()" aria-label="Open the selected disk">Open</button>
</footer>
</div>
</div>

View File

@ -1,11 +0,0 @@
/*!
* Copyright 2010-2019 Will Scullin <scullin@scullinsteel.com>
*
* Permission to use, copy, modify, distribute, and sell this software and its
* documentation for any purpose is hereby granted without fee, provided that
* the above copyright notice appear in all copies and that both that
* copyright notice and this permission notice appear in supporting
* documentation. No representations are made about the suitability of this
* software for any purpose. It is provided "as is" without express or
* implied warranty.
*/

3
js/entry2.js Normal file
View File

@ -0,0 +1,3 @@
const Apple2 = require('./main2');
module.exports = { Apple2 };

3
js/entry2e.js Normal file
View File

@ -0,0 +1,3 @@
const Apple2 = require('./main2e');
module.exports = { Apple2 };

View File

@ -56,7 +56,7 @@ var disk_cur_cat = [];
var _currentDrive = 1;
window.openLoad = function(drive, event)
export function openLoad(drive, event)
{
_currentDrive = parseInt(drive, 10);
if (event.metaKey) {
@ -64,13 +64,13 @@ window.openLoad = function(drive, event)
} else {
if (disk_cur_cat[drive]) {
document.querySelector('#category_select').value = disk_cur_cat[drive];
window.selectCategory();
selectCategory();
}
MicroModal.show('load-modal');
}
};
}
window.openSave = function(drive, event)
export function openSave(drive, event)
{
_currentDrive = parseInt(drive, 10);
@ -88,14 +88,14 @@ window.openSave = function(drive, event)
document.querySelector('#save_name').value = drivelights.label(drive);
MicroModal.show('save-modal');
}
};
}
window.handleDragOver = function(drive, event) {
export function handleDragOver(drive, event) {
event.preventDefault();
event.dataTransfer.dropEffect = 'copy';
};
}
window.handleDragEnd = function(drive, event) {
export function handleDragEnd(drive, event) {
var dt = event.dataTransfer;
if (dt.items) {
for (var i = 0; i < dt.items.length; i++) {
@ -104,9 +104,9 @@ window.handleDragEnd = function(drive, event) {
} else {
event.dataTransfer.clearData();
}
};
}
window.handleDrop = function(drive, event) {
export function handleDrop(drive, event) {
event.preventDefault();
event.stopPropagation();
@ -136,7 +136,7 @@ window.handleDrop = function(drive, event) {
}
}
}
};
}
var loading = false;
@ -162,7 +162,7 @@ function loadAjax(drive, url) {
});
}
window.doLoad = function doLoad() {
export function doLoad() {
MicroModal.close('load-modal');
var urls = document.querySelector('#disk_select').value, url;
if (urls && urls.length) {
@ -198,19 +198,19 @@ window.doLoad = function doLoad() {
document.location.hash = parts.join('|');
}
}
};
}
window.doSave = function doSave() {
export function doSave() {
var name = document.querySelector('#save_name').value;
saveLocalStorage(_currentDrive, name);
MicroModal.close('save-modal');
};
}
window.doDelete = function(name) {
export function doDelete(name) {
if (window.confirm('Delete ' + name + '?')) {
deleteLocalStorage(name);
}
};
}
function doLoadLocal(drive, file) {
var parts = file.name.split('.');
@ -374,7 +374,7 @@ io.setSlot(3, videoterm);
io.setSlot(6, disk2);
io.setSlot(7, clock);
window.showFPS = false;
var showFPS = false;
function updateKHz() {
var now = Date.now();
@ -382,7 +382,7 @@ function updateKHz() {
var cycles = cpu.cycles();
var delta;
if (window.showFPS) {
if (showFPS) {
delta = renderedFrames - lastFrames;
var fps = parseInt(delta/(ms/1000), 10);
document.querySelector('#khz').innerText = fps + 'fps';
@ -397,7 +397,11 @@ function updateKHz() {
lastFrames = renderedFrames;
}
window.updateSound = function updateSound() {
export function toggleShowFPS() {
showFPS = !showFPS;
}
export function updateSound() {
var on = document.querySelector('#enable_sound').checked;
var label = document.querySelector('#toggle-sound i');
audio.enable(on);
@ -419,16 +423,16 @@ function dumpDisk(drive) {
wind.document.close();
}
window.dumpProgram = function() {
export function dumpProgram() {
var wind = window.open('', '_blank');
wind.document.title = 'Program Listing';
wind.document.write('<pre>');
wind.document.write(dumper.toString());
wind.document.write('</pre>');
wind.document.close();
};
}
window.step = function()
export function step()
{
if (runTimer) {
clearInterval(runTimer);
@ -439,11 +443,11 @@ window.step = function()
debug(cpu.dumpRegisters());
debug(cpu.dumpPC());
});
};
}
var accelerated = false;
window.updateCPU = function updateCPU()
export function updateCPU()
{
accelerated = document.querySelector('#accelerator_toggle').checked;
kHz = accelerated ? 4092 : 1023;
@ -539,11 +543,6 @@ function stop() {
runTimer = null;
}
function reset()
{
cpu.reset();
}
var state = null;
function storeStateLocal() {
@ -612,7 +611,7 @@ function loadBinary(bin) {
run(bin.start);
}
window.selectCategory = function() {
export function selectCategory() {
document.querySelector('#disk_select').innerHTML = '';
var cat = disk_categories[document.querySelector('#category_select').value];
if (cat) {
@ -630,15 +629,15 @@ window.selectCategory = function() {
}
}
}
};
}
window.selectDisk = function() {
export function selectDisk() {
document.querySelector('#local_file').value = '';
};
}
window.clickDisk = function() {
window.doLoad();
};
export function clickDisk() {
doLoad();
}
function loadDisk(drive, disk) {
var name = disk.name;
@ -811,7 +810,7 @@ function _keyup(evt) {
}
}
window.updateScreen = function updateScreen() {
export function updateScreen() {
var green = document.querySelector('#green_screen').checked;
var scanlines = document.querySelector('#show_scanlines').checked;
@ -824,7 +823,7 @@ var flipX = false;
var flipY = false;
var swapXY = false;
window.updateJoystick = function() {
export function updateJoystick() {
disableMouseJoystick = document.querySelector('#disable_mouse').checked;
flipX = document.querySelector('#flip_x').checked;
flipY = document.querySelector('#flip_y').checked;
@ -836,7 +835,7 @@ window.updateJoystick = function() {
io.paddle(1, 0.5);
return;
}
};
}
function _mousemove(evt) {
if (gamepad || disableMouseJoystick) {
@ -858,7 +857,7 @@ function _mousemove(evt) {
io.paddle(1, flipY ? 1 - y : y);
}
window.pauseRun = function() {
export function pauseRun() {
var label = document.querySelector('#pause-run i');
if (paused) {
run();
@ -870,19 +869,19 @@ window.pauseRun = function() {
label.classList.add('fa-play');
}
paused = !paused;
};
}
window.toggleSound = function() {
export function toggleSound() {
var enableSound = document.querySelector('#enable_sound');
enableSound.checked = !enableSound.checked;
window.updateSound();
};
updateSound();
}
window.openOptions = function () {
export function openOptions() {
MicroModal.show('options-modal');
};
window.openPrinterModal = function () {
export function openPrinterModal() {
MicroModal.show('printer-modal');
};
@ -943,11 +942,11 @@ document.addEventListener('DOMContentLoaded', function() {
});
}
reset();
cpu.reset();
setInterval(updateKHz, 1000);
window.updateSound();
window.updateScreen();
window.updateCPU();
updateSound();
updateScreen();
updateCPU();
if (window.localStorage !== undefined) {
document.querySelectorAll('.disksave').forEach(function (el) { el.style.display = 'inline-block';});

View File

@ -51,7 +51,7 @@ var disk_cur_cat = [];
var _currentDrive = 1;
window.openLoad = function(drive, event)
export function openLoad(drive, event)
{
_currentDrive = parseInt(drive, 10);
if (event.metaKey) {
@ -59,13 +59,13 @@ window.openLoad = function(drive, event)
} else {
if (disk_cur_cat[drive]) {
document.querySelector('#category_select').value = disk_cur_cat[drive];
window.selectCategory();
selectCategory();
}
MicroModal.show('load-modal');
}
};
}
window.openSave = function(drive, event)
export function openSave(drive, event)
{
_currentDrive = parseInt(drive, 10);
@ -83,14 +83,14 @@ window.openSave = function(drive, event)
document.querySelector('#save_name').value = drivelights.label(drive);
MicroModal.show('save-modal');
}
};
}
window.handleDragOver = function(drive, event) {
export function handleDragOver(drive, event) {
event.preventDefault();
event.dataTransfer.dropEffect = 'copy';
};
}
window.handleDragEnd = function(drive, event) {
export function handleDragEnd(drive, event) {
var dt = event.dataTransfer;
if (dt.items) {
for (var i = 0; i < dt.items.length; i++) {
@ -99,9 +99,9 @@ window.handleDragEnd = function(drive, event) {
} else {
event.dataTransfer.clearData();
}
};
}
window.handleDrop = function(drive, event) {
export function handleDrop(drive, event) {
event.preventDefault();
event.stopPropagation();
@ -131,7 +131,7 @@ window.handleDrop = function(drive, event) {
}
}
}
};
}
var loading = false;
@ -157,7 +157,7 @@ function loadAjax(drive, url) {
});
}
window.doLoad = function doLoad() {
export function doLoad() {
MicroModal.close('load-modal');
var urls = document.querySelector('#disk_select').value, url;
if (urls && urls.length) {
@ -195,17 +195,17 @@ window.doLoad = function doLoad() {
}
};
window.doSave = function doSave() {
export function doSave() {
var name = document.querySelector('#save_name').value;
saveLocalStorage(_currentDrive, name);
MicroModal.close('save-modal');
};
window.doDelete = function(name) {
export function doDelete(name) {
if (window.confirm('Delete ' + name + '?')) {
deleteLocalStorage(name);
}
};
}
function doLoadLocal(drive, file) {
var parts = file.name.split('.');
@ -348,7 +348,7 @@ io.setSlot(2, slinky);
io.setSlot(6, disk2);
io.setSlot(7, clock);
window.showFPS = false;
var showFPS = false;
function updateKHz() {
var now = Date.now();
@ -356,7 +356,7 @@ function updateKHz() {
var cycles = cpu.cycles();
var delta;
if (window.showFPS) {
if (showFPS) {
delta = renderedFrames - lastFrames;
var fps = parseInt(delta/(ms/1000), 10);
document.querySelector('#khz').innerText = fps + 'fps';
@ -371,7 +371,11 @@ function updateKHz() {
lastFrames = renderedFrames;
}
window.updateSound = function updateSound() {
export function toggleShowFPS() {
showFPS = !showFPS;
}
export function updateSound() {
var on = document.querySelector('#enable_sound').checked;
var label = document.querySelector('#toggle-sound i');
audio.enable(on);
@ -393,16 +397,16 @@ function dumpDisk(drive) {
wind.document.close();
}
window.dumpProgram = function() {
export function dumpProgram() {
var wind = window.open('', '_blank');
wind.document.title = 'Program Listing';
wind.document.write('<pre>');
wind.document.write(dumper.toString());
wind.document.write('</pre>');
wind.document.close();
};
}
window.step = function()
export function step()
{
if (runTimer) {
clearInterval(runTimer);
@ -413,11 +417,11 @@ window.step = function()
debug(cpu.dumpRegisters());
debug(cpu.dumpPC());
});
};
}
var accelerated = false;
window.updateCPU = function updateCPU()
export function updateCPU()
{
accelerated = document.querySelector('#accelerator_toggle').checked;
kHz = accelerated ? 4092 : 1023;
@ -505,7 +509,7 @@ function stop() {
runTimer = null;
}
function reset()
export function reset()
{
cpu.reset();
}
@ -572,7 +576,7 @@ function loadBinary(bin) {
run(bin.start);
}
window.selectCategory = function() {
export function selectCategory() {
document.querySelector('#disk_select').innerHTML = '';
var cat = disk_categories[document.querySelector('#category_select').value];
if (cat) {
@ -590,15 +594,15 @@ window.selectCategory = function() {
}
}
}
};
}
window.selectDisk = function() {
export function selectDisk() {
document.querySelector('#local_file').value = '';
};
}
window.clickDisk = function() {
window.doLoad();
};
export function clickDisk() {
doLoad();
}
function loadDisk(drive, disk) {
var name = disk.name;
@ -709,8 +713,6 @@ function processHash(hash) {
* Keyboard/Gamepad routines
*/
window.reset = keyboard.reset;
function _keydown(evt) {
if (!focused && (!evt.metaKey || evt.ctrlKey)) {
evt.preventDefault();
@ -790,7 +792,7 @@ function _keyup(evt) {
}
}
window.updateScreen = function updateScreen() {
export function updateScreen() {
var green = document.querySelector('#green_screen').checked;
var scanlines = document.querySelector('#show_scanlines').checked;
@ -803,7 +805,7 @@ var flipX = false;
var flipY = false;
var swapXY = false;
window.updateJoystick = function() {
export function updateJoystick() {
disableMouseJoystick = document.querySelector('#disable_mouse').checked;
flipX = document.querySelector('#flip_x').checked;
flipY = document.querySelector('#flip_y').checked;
@ -815,7 +817,7 @@ window.updateJoystick = function() {
io.paddle(1, 0.5);
return;
}
};
}
function _mousemove(evt) {
if (gamepad || disableMouseJoystick) {
@ -837,7 +839,7 @@ function _mousemove(evt) {
io.paddle(1, flipY ? 1 - y : y);
}
window.pauseRun = function() {
export function pauseRun() {
var label = document.querySelector('#pause-run i');
if (paused) {
run();
@ -849,19 +851,19 @@ window.pauseRun = function() {
label.classList.add('fa-play');
}
paused = !paused;
};
}
window.toggleSound = function() {
export function toggleSound() {
var enableSound = document.querySelector('#enable_sound');
enableSound.checked = !enableSound.checked;
window.updateSound();
};
updateSound();
}
window.openOptions = function () {
export function openOptions() {
MicroModal.show('options-modal');
};
window.openPrinterModal = function () {
export function openPrinterModal() {
MicroModal.show('printer-modal');
};
@ -922,11 +924,11 @@ document.addEventListener('DOMContentLoaded', function() {
});
}
reset();
cpu.reset();
setInterval(updateKHz, 1000);
window.updateSound();
window.updateScreen();
window.updateCPU();
updateSound();
updateScreen();
updateCPU();
if (window.localStorage !== undefined) {
document.querySelectorAll('.disksave').forEach(function (el) { el.style.display = 'inline-block';});

View File

@ -11,18 +11,20 @@
export default function Prefs()
{
var havePrefs = typeof window.localStorage !== 'undefined';
return {
havePrefs: function() {
return typeof(localStorage) != 'undefined';
return havePrefs;
},
readPref: function(name) {
if (localStorage)
return localStorage.getItem(name);
if (havePrefs)
return window.localStorage.getItem(name);
return null;
},
writePref: function(name, value) {
if (localStorage)
localStorage.setItem(name, value);
if (havePrefs)
window.localStorage.setItem(name, value);
}
};
}

View File

@ -1,11 +0,0 @@
/*!
* Copyright 2010-2019 Will Scullin <scullin@scullinsteel.com>
*
* Permission to use, copy, modify, distribute, and sell this software and its
* documentation for any purpose is hereby granted without fee, provided that
* the above copyright notice appear in all copies and that both that
* copyright notice and this permission notice appear in supporting
* documentation. No representations are made about the suitability of this
* software for any purpose. It is provided "as is" without express or
* implied warranty.
*/

View File

@ -1,15 +1,17 @@
/*globals require module */
const path = require('path');
module.exports =
{
devtool: 'source-map',
entry: {
main2: path.resolve('js/main2.js'),
main2e: path.resolve('js/main2e.js')
main2: path.resolve('js/entry2.js'),
main2e: path.resolve('js/entry2e.js')
},
output: {
path: path.resolve('dist/')
path: path.resolve('dist/'),
library: 'Apple2',
libraryExport: 'Apple2',
libraryTarget: 'var'
},
devServer: {
compress: true,