2019-03-13 04:11:00 +00:00
|
|
|
import MicroModal from 'micromodal';
|
|
|
|
|
2019-03-01 05:21:18 +00:00
|
|
|
import Apple2IO from './apple2io';
|
|
|
|
import ApplesoftDump from './applesoft/decompiler';
|
|
|
|
import { HiresPage, LoresPage, VideoModes } from './canvas';
|
|
|
|
import CPU6502 from './cpu6502';
|
|
|
|
import MMU from './mmu';
|
|
|
|
import Prefs from './prefs';
|
|
|
|
import { debug, gup, hup } from './util';
|
|
|
|
|
|
|
|
import Audio from './ui/audio';
|
2019-03-13 04:11:00 +00:00
|
|
|
import DriveLights from './ui/drive_lights';
|
2019-03-01 14:48:50 +00:00
|
|
|
import { gamepad, configGamepad, initGamepad, processGamepad } from './ui/gamepad';
|
2019-03-01 05:21:18 +00:00
|
|
|
import KeyBoard from './ui/keyboard';
|
|
|
|
import Printer from './ui/printer';
|
2019-03-13 04:11:00 +00:00
|
|
|
import Tape, { TAPE_TYPES } from './ui/tape';
|
2019-03-01 05:21:18 +00:00
|
|
|
|
2019-03-13 04:11:00 +00:00
|
|
|
import DiskII, { DISK_TYPES } from './cards/disk2';
|
2019-03-01 05:21:18 +00:00
|
|
|
import Parallel from './cards/parallel';
|
|
|
|
import RAMFactor from './cards/ramfactor';
|
|
|
|
import Thunderclock from './cards/thunderclock';
|
|
|
|
|
|
|
|
import apple2e_charset from './roms/apple2e_char';
|
|
|
|
import apple2enh_charset from './roms/apple2enh_char';
|
2019-03-01 18:15:17 +00:00
|
|
|
import rmfont_charset from './roms/rmfont_char';
|
2019-03-01 05:21:18 +00:00
|
|
|
|
|
|
|
import Apple2eROM from './roms/apple2e';
|
|
|
|
import Apple2eEnhancedROM from './roms/apple2enh';
|
|
|
|
|
|
|
|
import SYMBOLS from './symbols';
|
2016-11-22 05:17:34 +00:00
|
|
|
|
|
|
|
var kHz = 1023;
|
|
|
|
|
|
|
|
var focused = false;
|
|
|
|
var startTime = Date.now();
|
|
|
|
var lastCycles = 0;
|
|
|
|
var renderedFrames = 0, lastFrames = 0;
|
|
|
|
var paused = false;
|
|
|
|
|
|
|
|
var hashtag;
|
|
|
|
|
2016-11-28 01:28:49 +00:00
|
|
|
var DEBUG = false;
|
|
|
|
var TRACE = false;
|
|
|
|
var MAX_TRACE = 256;
|
|
|
|
var trace = [];
|
|
|
|
|
2016-11-22 05:17:34 +00:00
|
|
|
var disk_categories = {'Local Saves': []};
|
|
|
|
var disk_sets = {};
|
|
|
|
var disk_cur_name = [];
|
|
|
|
var disk_cur_cat = [];
|
|
|
|
|
2016-11-28 01:28:49 +00:00
|
|
|
var _currentDrive = 1;
|
2016-11-22 05:17:34 +00:00
|
|
|
|
2019-04-01 03:52:45 +00:00
|
|
|
export function openLoad(drive, event)
|
2016-11-22 05:17:34 +00:00
|
|
|
{
|
2016-11-28 01:28:49 +00:00
|
|
|
_currentDrive = parseInt(drive, 10);
|
2016-11-22 05:17:34 +00:00
|
|
|
if (event.metaKey) {
|
|
|
|
openLoadHTTP(drive);
|
|
|
|
} else {
|
|
|
|
if (disk_cur_cat[drive]) {
|
2019-03-13 04:11:00 +00:00
|
|
|
document.querySelector('#category_select').value = disk_cur_cat[drive];
|
2019-04-01 03:52:45 +00:00
|
|
|
selectCategory();
|
2016-11-22 05:17:34 +00:00
|
|
|
}
|
2019-03-13 04:11:00 +00:00
|
|
|
MicroModal.show('load-modal');
|
2016-11-22 05:17:34 +00:00
|
|
|
}
|
2019-04-01 03:52:45 +00:00
|
|
|
}
|
2016-11-22 05:17:34 +00:00
|
|
|
|
2019-04-01 03:52:45 +00:00
|
|
|
export function openSave(drive, event)
|
2016-11-22 05:17:34 +00:00
|
|
|
{
|
2016-11-28 01:28:49 +00:00
|
|
|
_currentDrive = parseInt(drive, 10);
|
|
|
|
|
|
|
|
var mimetype = 'application/octet-stream';
|
|
|
|
var data = disk2.getBinary(drive);
|
2019-03-13 04:11:00 +00:00
|
|
|
var a = document.querySelector('#local_save_link');
|
2016-11-28 01:28:49 +00:00
|
|
|
|
|
|
|
var blob = new Blob([data], { 'type': mimetype });
|
2019-03-13 04:11:00 +00:00
|
|
|
a.href = window.URL.createObjectURL(blob);
|
|
|
|
a.download = drivelights.label(drive) + '.dsk';
|
2016-11-28 01:28:49 +00:00
|
|
|
|
2016-11-22 05:17:34 +00:00
|
|
|
if (event.metaKey) {
|
|
|
|
dumpDisk(drive);
|
|
|
|
} else {
|
2019-03-13 04:11:00 +00:00
|
|
|
document.querySelector('#save_name').value = drivelights.label(drive);
|
|
|
|
MicroModal.show('save-modal');
|
2016-11-22 05:17:34 +00:00
|
|
|
}
|
2019-04-01 03:52:45 +00:00
|
|
|
}
|
2016-11-22 05:17:34 +00:00
|
|
|
|
2019-04-01 03:52:45 +00:00
|
|
|
export function handleDragOver(drive, event) {
|
2019-02-19 04:42:50 +00:00
|
|
|
event.preventDefault();
|
|
|
|
event.dataTransfer.dropEffect = 'copy';
|
2019-04-01 03:52:45 +00:00
|
|
|
}
|
2019-02-19 04:42:50 +00:00
|
|
|
|
2019-04-01 03:52:45 +00:00
|
|
|
export function handleDragEnd(drive, event) {
|
2019-02-19 04:42:50 +00:00
|
|
|
var dt = event.dataTransfer;
|
|
|
|
if (dt.items) {
|
|
|
|
for (var i = 0; i < dt.items.length; i++) {
|
|
|
|
dt.items.remove(i);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
event.dataTransfer.clearData();
|
|
|
|
}
|
2019-04-01 03:52:45 +00:00
|
|
|
}
|
2019-02-19 04:42:50 +00:00
|
|
|
|
2019-04-01 03:52:45 +00:00
|
|
|
export function handleDrop(drive, event) {
|
2019-02-19 04:42:50 +00:00
|
|
|
event.preventDefault();
|
|
|
|
event.stopPropagation();
|
|
|
|
|
|
|
|
if (drive < 1) {
|
|
|
|
if (!disk2.getMetadata(1)) {
|
|
|
|
drive = 1;
|
|
|
|
} else if (!disk2.getMetadata(2)) {
|
|
|
|
drive = 2;
|
|
|
|
} else {
|
|
|
|
drive = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var dt = event.dataTransfer;
|
|
|
|
if (dt.files.length == 1) {
|
|
|
|
doLoadLocal(drive, dt.files[0]);
|
|
|
|
} else if (dt.files.length == 2) {
|
|
|
|
doLoadLocal(1, dt.files[0]);
|
|
|
|
doLoadLocal(2, dt.files[1]);
|
2019-03-13 04:11:00 +00:00
|
|
|
} else {
|
|
|
|
for (var idx = 0; idx < dt.items.length; idx++) {
|
|
|
|
if (dt.items[idx].type === 'text/uri-list') {
|
|
|
|
dt.items[idx].getAsString(function(url) {
|
|
|
|
var parts = document.location.hash.split('|');
|
|
|
|
parts[drive - 1] = url;
|
|
|
|
document.location.hash = parts.join('|');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2019-02-19 04:42:50 +00:00
|
|
|
}
|
2019-04-01 03:52:45 +00:00
|
|
|
}
|
2019-02-19 04:42:50 +00:00
|
|
|
|
2016-11-22 05:17:34 +00:00
|
|
|
var loading = false;
|
|
|
|
|
2016-11-28 01:28:49 +00:00
|
|
|
function loadAjax(drive, url) {
|
2016-11-22 05:17:34 +00:00
|
|
|
loading = true;
|
2019-03-13 04:11:00 +00:00
|
|
|
MicroModal.show('loading-modal');
|
|
|
|
|
|
|
|
fetch(url).then(function(response) {
|
|
|
|
return response.json();
|
|
|
|
}).then(function(data) {
|
|
|
|
if (data.type == 'binary') {
|
|
|
|
loadBinary(drive, data);
|
2019-06-15 22:59:02 +00:00
|
|
|
} else if (DISK_TYPES.indexOf(data.type) > -1) {
|
2019-03-13 04:11:00 +00:00
|
|
|
loadDisk(drive, data);
|
2016-11-28 01:28:49 +00:00
|
|
|
}
|
2019-03-13 04:11:00 +00:00
|
|
|
initGamepad(data.gamepad);
|
|
|
|
MicroModal.close('loading-modal');
|
|
|
|
loading = false;
|
|
|
|
}).catch(function(error) {
|
|
|
|
window.alert(error || status);
|
|
|
|
MicroModal.close('loading-modal');
|
|
|
|
loading = false;
|
2016-11-28 01:28:49 +00:00
|
|
|
});
|
2016-11-22 05:17:34 +00:00
|
|
|
}
|
|
|
|
|
2019-04-01 03:52:45 +00:00
|
|
|
export function doLoad() {
|
2019-03-13 04:11:00 +00:00
|
|
|
MicroModal.close('load-modal');
|
|
|
|
var urls = document.querySelector('#disk_select').value, url;
|
2016-11-22 05:17:34 +00:00
|
|
|
if (urls && urls.length) {
|
|
|
|
if (typeof(urls) == 'string') {
|
|
|
|
url = urls;
|
|
|
|
} else {
|
|
|
|
url = urls[0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-13 04:11:00 +00:00
|
|
|
var files = document.querySelector('#local_file').files;
|
2016-11-22 05:17:34 +00:00
|
|
|
if (files.length == 1) {
|
2019-01-09 08:27:31 +00:00
|
|
|
doLoadLocal(_currentDrive, files[0]);
|
2016-11-22 05:17:34 +00:00
|
|
|
} else if (url) {
|
|
|
|
var filename;
|
2019-03-13 04:11:00 +00:00
|
|
|
MicroModal.close('load-modal');
|
2016-11-22 05:17:34 +00:00
|
|
|
if (url.substr(0,6) == 'local:') {
|
|
|
|
filename = url.substr(6);
|
|
|
|
if (filename == '__manage') {
|
|
|
|
openManage();
|
|
|
|
} else {
|
2016-11-28 01:28:49 +00:00
|
|
|
loadLocalStorage(_currentDrive, filename);
|
2016-11-22 05:17:34 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
var r1 = /json\/disks\/(.*).json$/.exec(url);
|
2016-11-28 01:28:49 +00:00
|
|
|
if (r1) {
|
2016-11-22 05:17:34 +00:00
|
|
|
filename = r1[1];
|
2016-11-28 01:28:49 +00:00
|
|
|
} else {
|
|
|
|
filename = url;
|
2016-11-22 05:17:34 +00:00
|
|
|
}
|
2016-11-28 01:28:49 +00:00
|
|
|
var parts = document.location.hash.split('|');
|
|
|
|
parts[_currentDrive - 1] = filename;
|
|
|
|
document.location.hash = parts.join('|');
|
2016-11-22 05:17:34 +00:00
|
|
|
}
|
|
|
|
}
|
2019-04-06 19:20:35 +00:00
|
|
|
}
|
2016-11-22 05:17:34 +00:00
|
|
|
|
2019-04-01 03:52:45 +00:00
|
|
|
export function doSave() {
|
2019-03-13 04:11:00 +00:00
|
|
|
var name = document.querySelector('#save_name').value;
|
2016-11-28 01:28:49 +00:00
|
|
|
saveLocalStorage(_currentDrive, name);
|
2019-03-13 04:11:00 +00:00
|
|
|
MicroModal.close('save-modal');
|
2019-04-06 19:20:35 +00:00
|
|
|
}
|
2016-11-22 05:17:34 +00:00
|
|
|
|
2019-04-01 03:52:45 +00:00
|
|
|
export function doDelete(name) {
|
2016-11-22 05:17:34 +00:00
|
|
|
if (window.confirm('Delete ' + name + '?')) {
|
|
|
|
deleteLocalStorage(name);
|
|
|
|
}
|
2019-04-01 03:52:45 +00:00
|
|
|
}
|
2016-11-22 05:17:34 +00:00
|
|
|
|
2019-01-09 08:27:31 +00:00
|
|
|
function doLoadLocal(drive, file) {
|
|
|
|
var parts = file.name.split('.');
|
|
|
|
var ext = parts[parts.length - 1].toLowerCase();
|
2019-06-15 22:59:02 +00:00
|
|
|
if (DISK_TYPES.indexOf(ext) > -1) {
|
2019-01-09 08:27:31 +00:00
|
|
|
doLoadLocalDisk(drive, file);
|
2019-06-15 22:59:02 +00:00
|
|
|
} else if (TAPE_TYPES.indexOf(ext) > -1) {
|
2019-04-06 19:20:35 +00:00
|
|
|
tape.doLoadLocalTape(file);
|
2019-01-09 08:27:31 +00:00
|
|
|
} else {
|
|
|
|
window.alert('Unknown file type: ' + ext);
|
2016-11-22 05:17:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-28 01:28:49 +00:00
|
|
|
function doLoadLocalDisk(drive, file) {
|
2016-11-22 05:17:34 +00:00
|
|
|
var fileReader = new FileReader();
|
|
|
|
fileReader.onload = function() {
|
|
|
|
var parts = file.name.split('.');
|
2019-01-09 08:27:31 +00:00
|
|
|
var ext = parts.pop().toLowerCase();
|
|
|
|
var name = parts.join('.');
|
2016-11-28 01:28:49 +00:00
|
|
|
if (disk2.setBinary(drive, name, ext, this.result)) {
|
|
|
|
drivelights.label(drive, name);
|
2016-11-22 05:17:34 +00:00
|
|
|
initGamepad();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
fileReader.readAsArrayBuffer(file);
|
|
|
|
}
|
|
|
|
|
2016-11-28 01:28:49 +00:00
|
|
|
function doLoadHTTP(drive, _url) {
|
2019-03-13 04:11:00 +00:00
|
|
|
var url = _url || document.querySelector('#http_url').value;
|
2016-11-22 05:17:34 +00:00
|
|
|
if (url) {
|
|
|
|
var req = new XMLHttpRequest();
|
|
|
|
req.open('GET', url, true);
|
|
|
|
req.responseType = 'arraybuffer';
|
|
|
|
|
|
|
|
req.onload = function() {
|
2019-01-09 08:27:31 +00:00
|
|
|
var urlParts = url.split('/');
|
|
|
|
var file = urlParts.pop();
|
|
|
|
var fileParts = file.split('.');
|
|
|
|
var ext = fileParts.pop().toLowerCase();
|
|
|
|
var name = decodeURIComponent(fileParts.join('.'));
|
|
|
|
if (disk2.setBinary(drive, name, ext, req.response)) {
|
|
|
|
drivelights.label(drive, name);
|
2019-03-13 04:11:00 +00:00
|
|
|
MicroModal.close('http-modal');
|
2019-01-09 08:27:31 +00:00
|
|
|
initGamepad();
|
2016-11-22 05:17:34 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
req.send(null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function openLoadHTTP(drive) {
|
2016-11-28 01:28:49 +00:00
|
|
|
_currentDrive = parseInt(drive, 10);
|
2019-03-13 04:11:00 +00:00
|
|
|
MicroModal.show('http-modal');
|
2016-11-22 05:17:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function openManage() {
|
2019-03-13 04:11:00 +00:00
|
|
|
MicroModal.show('manage-modal');
|
2016-11-22 05:17:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var prefs = new Prefs();
|
2017-09-23 04:42:57 +00:00
|
|
|
var romVersion = prefs.readPref('computer_type2e');
|
|
|
|
var enhanced = false;
|
2019-03-01 05:21:18 +00:00
|
|
|
var multiScreen = false;
|
2017-09-23 04:42:57 +00:00
|
|
|
var rom;
|
|
|
|
var char_rom = apple2e_charset;
|
|
|
|
switch (romVersion) {
|
|
|
|
case 'apple2e':
|
|
|
|
rom = new Apple2eROM();
|
|
|
|
break;
|
|
|
|
case 'apple2rm':
|
|
|
|
rom = new Apple2eEnhancedROM();
|
|
|
|
char_rom = rmfont_charset;
|
|
|
|
enhanced = true;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
rom = new Apple2eEnhancedROM();
|
|
|
|
char_rom =apple2enh_charset;
|
|
|
|
enhanced = true;
|
|
|
|
}
|
|
|
|
|
2016-11-22 05:17:34 +00:00
|
|
|
var runTimer = null;
|
|
|
|
var cpu = new CPU6502({'65C02': enhanced});
|
|
|
|
|
2017-09-23 04:42:57 +00:00
|
|
|
var context1, context2, context3, context4;
|
|
|
|
|
|
|
|
var canvas1 = document.getElementById('screen');
|
|
|
|
var canvas2 = document.getElementById('screen2');
|
|
|
|
var canvas3 = document.getElementById('screen3');
|
|
|
|
var canvas4 = document.getElementById('screen4');
|
|
|
|
|
|
|
|
context1 = canvas1.getContext('2d');
|
|
|
|
if (canvas4) {
|
|
|
|
multiScreen = true;
|
|
|
|
context2 = canvas2.getContext('2d');
|
|
|
|
context3 = canvas3.getContext('2d');
|
|
|
|
context4 = canvas4.getContext('2d');
|
|
|
|
} else if (canvas2) {
|
|
|
|
multiScreen = true;
|
|
|
|
context2 = context1;
|
|
|
|
context3 = canvas2.getContext('2d');
|
|
|
|
context4 = context3;
|
2016-11-22 05:17:34 +00:00
|
|
|
} else {
|
2017-09-23 04:42:57 +00:00
|
|
|
context2 = context1;
|
|
|
|
context3 = context1;
|
|
|
|
context4 = context1;
|
2016-11-22 05:17:34 +00:00
|
|
|
}
|
2016-11-28 01:28:49 +00:00
|
|
|
|
2017-09-24 14:06:57 +00:00
|
|
|
var gr = new LoresPage(1, char_rom, true, context1);
|
|
|
|
var gr2 = new LoresPage(2, char_rom, true, context2);
|
2017-09-23 04:42:57 +00:00
|
|
|
var hgr = new HiresPage(1, context3);
|
|
|
|
var hgr2 = new HiresPage(2, context4);
|
|
|
|
|
2017-09-24 14:06:57 +00:00
|
|
|
var vm = new VideoModes(gr, hgr, gr2, hgr2, true);
|
2019-03-01 05:21:18 +00:00
|
|
|
vm.enhanced(enhanced);
|
|
|
|
vm.multiScreen(multiScreen);
|
2016-11-28 01:28:49 +00:00
|
|
|
var dumper = new ApplesoftDump(cpu);
|
2016-11-22 05:17:34 +00:00
|
|
|
|
|
|
|
var drivelights = new DriveLights();
|
|
|
|
var io = new Apple2IO(cpu, vm);
|
2019-03-01 05:21:18 +00:00
|
|
|
var keyboard = new KeyBoard(cpu, io, true);
|
2017-12-03 04:45:02 +00:00
|
|
|
var audio = new Audio(io);
|
2019-01-09 08:27:31 +00:00
|
|
|
var tape = new Tape(io);
|
2019-03-13 04:11:00 +00:00
|
|
|
var printer = new Printer('#printer-modal .paper');
|
2016-11-22 05:17:34 +00:00
|
|
|
|
2017-08-20 17:46:10 +00:00
|
|
|
var mmu = new MMU(cpu, vm, gr, gr2, hgr, hgr2, io, rom);
|
2016-11-22 05:17:34 +00:00
|
|
|
|
2016-11-28 01:28:49 +00:00
|
|
|
cpu.addPageHandler(mmu);
|
2016-11-22 05:17:34 +00:00
|
|
|
|
2019-02-19 04:42:50 +00:00
|
|
|
var parallel = new Parallel(io, 1, printer);
|
2016-11-28 01:28:49 +00:00
|
|
|
var slinky = new RAMFactor(io, 2, 1024 * 1024);
|
|
|
|
var disk2 = new DiskII(io, 6, drivelights);
|
|
|
|
var clock = new Thunderclock(io, 7);
|
2016-11-22 05:17:34 +00:00
|
|
|
|
2016-12-06 05:16:21 +00:00
|
|
|
io.setSlot(1, parallel);
|
|
|
|
io.setSlot(2, slinky);
|
|
|
|
io.setSlot(6, disk2);
|
|
|
|
io.setSlot(7, clock);
|
2016-11-22 05:17:34 +00:00
|
|
|
|
2019-04-01 03:52:45 +00:00
|
|
|
var showFPS = false;
|
2016-11-22 05:17:34 +00:00
|
|
|
|
|
|
|
function updateKHz() {
|
|
|
|
var now = Date.now();
|
|
|
|
var ms = now - startTime;
|
|
|
|
var cycles = cpu.cycles();
|
|
|
|
var delta;
|
|
|
|
|
2019-04-01 03:52:45 +00:00
|
|
|
if (showFPS) {
|
2016-11-22 05:17:34 +00:00
|
|
|
delta = renderedFrames - lastFrames;
|
|
|
|
var fps = parseInt(delta/(ms/1000), 10);
|
2019-03-13 04:11:00 +00:00
|
|
|
document.querySelector('#khz').innerText = fps + 'fps';
|
2016-11-22 05:17:34 +00:00
|
|
|
} else {
|
|
|
|
delta = cycles - lastCycles;
|
|
|
|
var khz = parseInt(delta/ms);
|
2019-03-13 04:11:00 +00:00
|
|
|
document.querySelector('#khz').innerText = khz + 'KHz';
|
2016-11-22 05:17:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
startTime = now;
|
|
|
|
lastCycles = cycles;
|
|
|
|
lastFrames = renderedFrames;
|
|
|
|
}
|
|
|
|
|
2019-04-01 03:52:45 +00:00
|
|
|
export function toggleShowFPS() {
|
|
|
|
showFPS = !showFPS;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function updateSound() {
|
2019-03-13 04:11:00 +00:00
|
|
|
var on = document.querySelector('#enable_sound').checked;
|
|
|
|
var label = document.querySelector('#toggle-sound i');
|
2019-02-19 04:42:50 +00:00
|
|
|
audio.enable(on);
|
|
|
|
if (on) {
|
2019-03-13 04:11:00 +00:00
|
|
|
label.classList.remove('fa-volume-off');
|
|
|
|
label.classList.add('fa-volume-up');
|
2019-02-19 04:42:50 +00:00
|
|
|
} else {
|
2019-03-13 04:11:00 +00:00
|
|
|
label.classList.remove('fa-volume-up');
|
|
|
|
label.classList.add('fa-volume-off');
|
2019-02-19 04:42:50 +00:00
|
|
|
}
|
2019-04-06 19:20:35 +00:00
|
|
|
}
|
2016-11-22 05:17:34 +00:00
|
|
|
|
|
|
|
function dumpDisk(drive) {
|
|
|
|
var wind = window.open('', '_blank');
|
|
|
|
wind.document.title = drivelights.label(drive);
|
|
|
|
wind.document.write('<pre>');
|
|
|
|
wind.document.write(disk2.getJSON(drive, true));
|
|
|
|
wind.document.write('</pre>');
|
|
|
|
wind.document.close();
|
|
|
|
}
|
|
|
|
|
2019-04-01 03:52:45 +00:00
|
|
|
export function dumpProgram() {
|
2016-11-22 05:17:34 +00:00
|
|
|
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();
|
2019-04-01 03:52:45 +00:00
|
|
|
}
|
2016-11-22 05:17:34 +00:00
|
|
|
|
2019-04-01 03:52:45 +00:00
|
|
|
export function step()
|
2016-11-22 05:17:34 +00:00
|
|
|
{
|
|
|
|
if (runTimer) {
|
|
|
|
clearInterval(runTimer);
|
|
|
|
}
|
|
|
|
runTimer = null;
|
|
|
|
|
|
|
|
cpu.step(function() {
|
|
|
|
debug(cpu.dumpRegisters());
|
|
|
|
debug(cpu.dumpPC());
|
|
|
|
});
|
2019-04-01 03:52:45 +00:00
|
|
|
}
|
2016-11-22 05:17:34 +00:00
|
|
|
|
|
|
|
var accelerated = false;
|
|
|
|
|
2019-04-01 03:52:45 +00:00
|
|
|
export function updateCPU()
|
2016-11-22 05:17:34 +00:00
|
|
|
{
|
2019-03-13 04:11:00 +00:00
|
|
|
accelerated = document.querySelector('#accelerator_toggle').checked;
|
2016-11-22 05:17:34 +00:00
|
|
|
kHz = accelerated ? 4092 : 1023;
|
|
|
|
io.updateHz(kHz * 1000);
|
|
|
|
if (runTimer) {
|
|
|
|
run();
|
|
|
|
}
|
2019-04-06 19:20:35 +00:00
|
|
|
}
|
2016-11-22 05:17:34 +00:00
|
|
|
|
|
|
|
var _requestAnimationFrame =
|
|
|
|
window.requestAnimationFrame ||
|
|
|
|
window.mozRequestAnimationFrame ||
|
|
|
|
window.webkitRequestAnimationFrame ||
|
|
|
|
window.msRequestAnimationFrame;
|
|
|
|
|
|
|
|
function run(pc) {
|
|
|
|
if (runTimer) {
|
|
|
|
clearInterval(runTimer);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pc) {
|
|
|
|
cpu.setPC(pc);
|
|
|
|
}
|
|
|
|
|
|
|
|
var ival = 30;
|
2016-11-28 01:28:49 +00:00
|
|
|
|
2016-11-22 05:17:34 +00:00
|
|
|
var now, last = Date.now();
|
|
|
|
var runFn = function() {
|
|
|
|
now = Date.now();
|
|
|
|
|
|
|
|
var step = (now - last) * kHz, stepMax = kHz * ival;
|
|
|
|
last = now;
|
|
|
|
if (step > stepMax) {
|
|
|
|
step = stepMax;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (document.location.hash != hashtag) {
|
|
|
|
hashtag = document.location.hash;
|
|
|
|
var hash = hup();
|
|
|
|
if (hash) {
|
|
|
|
processHash(hash);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!loading) {
|
|
|
|
mmu.resetVB();
|
2016-11-28 01:28:49 +00:00
|
|
|
if (DEBUG) {
|
|
|
|
cpu.stepCyclesDebug(TRACE ? 1 : step, function() {
|
|
|
|
var line = cpu.dumpRegisters() + ' ' +
|
|
|
|
cpu.dumpPC(undefined, SYMBOLS);
|
|
|
|
if (TRACE) {
|
|
|
|
debug(line);
|
|
|
|
} else {
|
|
|
|
trace.push(line);
|
|
|
|
if (trace.length > MAX_TRACE) {
|
|
|
|
trace.shift();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
cpu.stepCycles(step);
|
|
|
|
}
|
2019-03-22 03:39:48 +00:00
|
|
|
if (vm.blit()) {
|
|
|
|
renderedFrames++;
|
|
|
|
}
|
2019-02-19 04:42:50 +00:00
|
|
|
io.tick();
|
2016-11-22 05:17:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
processGamepad(io);
|
|
|
|
|
|
|
|
if (!paused && _requestAnimationFrame) {
|
|
|
|
_requestAnimationFrame(runFn);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
if (_requestAnimationFrame) {
|
|
|
|
_requestAnimationFrame(runFn);
|
|
|
|
} else {
|
|
|
|
runTimer = setInterval(runFn, ival);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function stop() {
|
|
|
|
if (runTimer) {
|
|
|
|
clearInterval(runTimer);
|
|
|
|
}
|
|
|
|
runTimer = null;
|
|
|
|
}
|
|
|
|
|
2019-04-01 03:52:45 +00:00
|
|
|
export function reset()
|
2016-11-22 05:17:34 +00:00
|
|
|
{
|
|
|
|
cpu.reset();
|
|
|
|
}
|
|
|
|
|
2016-11-28 01:28:49 +00:00
|
|
|
var state = null;
|
|
|
|
|
|
|
|
function storeStateLocal() {
|
|
|
|
window.localStorage['apple2.state'] = JSON.stringify(state);
|
|
|
|
}
|
|
|
|
|
|
|
|
function restoreStateLocal() {
|
|
|
|
var data = window.localStorage['apple2.state'];
|
|
|
|
if (data) {
|
|
|
|
state = JSON.parse(data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function saveState() {
|
|
|
|
if (state && !window.confirm('Overwrite Saved State?')) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
state = {
|
|
|
|
cpu: cpu.getState(),
|
|
|
|
io: io.getState(),
|
|
|
|
mmu: mmu.getState(),
|
|
|
|
vm: vm.getState(),
|
|
|
|
disk2: disk2.getState(),
|
|
|
|
drivelights: drivelights.getState()
|
|
|
|
};
|
|
|
|
if (slinky) {
|
|
|
|
state.slinky = slinky.getState();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (window.localStorage) {
|
|
|
|
storeStateLocal();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function restoreState() {
|
|
|
|
if (window.localStorage) {
|
|
|
|
restoreStateLocal();
|
|
|
|
}
|
|
|
|
if (!state) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
cpu.setState(state.cpu);
|
|
|
|
io.setState(state.io);
|
|
|
|
mmu.setState(state.mmu);
|
|
|
|
vm.setState(state.vm);
|
|
|
|
disk2.setState(state.disk2);
|
|
|
|
drivelights.setState(state.drivelights);
|
|
|
|
if (slinky && state.slinky) {
|
|
|
|
slinky.setState(state.slinky);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-22 05:17:34 +00:00
|
|
|
function loadBinary(bin) {
|
|
|
|
stop();
|
|
|
|
for (var idx = 0; idx < bin.length; idx++) {
|
|
|
|
var pos = bin.start + idx;
|
|
|
|
cpu.write(pos >> 8, pos & 0xff, bin.data[idx]);
|
|
|
|
}
|
|
|
|
run(bin.start);
|
|
|
|
}
|
|
|
|
|
2019-04-01 03:52:45 +00:00
|
|
|
export function selectCategory() {
|
2019-03-13 04:11:00 +00:00
|
|
|
document.querySelector('#disk_select').innerHTML = '';
|
|
|
|
var cat = disk_categories[document.querySelector('#category_select').value];
|
2016-11-22 05:17:34 +00:00
|
|
|
if (cat) {
|
|
|
|
for (var idx = 0; idx < cat.length; idx++) {
|
|
|
|
var file = cat[idx], name = file.name;
|
|
|
|
if (file.disk) {
|
|
|
|
name += ' - ' + file.disk;
|
|
|
|
}
|
2019-03-13 04:11:00 +00:00
|
|
|
var option = document.createElement('option');
|
|
|
|
option.value = file.filename;
|
|
|
|
option.innerText = name;
|
|
|
|
document.querySelector('#disk_select').append(option);
|
2016-11-28 01:28:49 +00:00
|
|
|
if (disk_cur_name[_currentDrive] == name) {
|
2019-03-13 04:11:00 +00:00
|
|
|
option.selected = true;
|
2016-11-22 05:17:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-04-01 03:52:45 +00:00
|
|
|
}
|
2016-11-22 05:17:34 +00:00
|
|
|
|
2019-04-01 03:52:45 +00:00
|
|
|
export function selectDisk() {
|
2019-03-13 04:11:00 +00:00
|
|
|
document.querySelector('#local_file').value = '';
|
2019-04-01 03:52:45 +00:00
|
|
|
}
|
2016-11-22 05:17:34 +00:00
|
|
|
|
2019-04-01 03:52:45 +00:00
|
|
|
export function clickDisk() {
|
|
|
|
doLoad();
|
|
|
|
}
|
2016-11-22 05:17:34 +00:00
|
|
|
|
2016-11-28 01:28:49 +00:00
|
|
|
function loadDisk(drive, disk) {
|
2016-11-22 05:17:34 +00:00
|
|
|
var name = disk.name;
|
|
|
|
var category = disk.category;
|
|
|
|
|
|
|
|
if (disk.disk) {
|
|
|
|
name += ' - ' + disk.disk;
|
|
|
|
}
|
|
|
|
|
2016-11-28 01:28:49 +00:00
|
|
|
disk_cur_cat[drive] = category;
|
|
|
|
disk_cur_name[drive] = name;
|
2016-11-22 05:17:34 +00:00
|
|
|
|
2016-11-28 01:28:49 +00:00
|
|
|
drivelights.label(drive, name);
|
|
|
|
disk2.setDisk(drive, disk);
|
2016-11-22 05:17:34 +00:00
|
|
|
initGamepad(disk.gamepad);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* LocalStorage Disk Storage
|
|
|
|
*/
|
|
|
|
|
|
|
|
function updateLocalStorage() {
|
|
|
|
var diskIndex = JSON.parse(window.localStorage.diskIndex || '{}');
|
|
|
|
var names = [], name, cat;
|
|
|
|
|
|
|
|
for (name in diskIndex) {
|
|
|
|
if (diskIndex.hasOwnProperty(name)) {
|
|
|
|
names.push(name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cat = disk_categories['Local Saves'] = [];
|
2019-03-13 04:11:00 +00:00
|
|
|
document.querySelector('#manage-modal-content').innerHTML = '';
|
2016-11-22 05:17:34 +00:00
|
|
|
|
|
|
|
names.forEach(function(name) {
|
2017-08-20 17:46:10 +00:00
|
|
|
cat.push({
|
|
|
|
'category': 'Local Saves',
|
|
|
|
'name': name,
|
|
|
|
'filename': 'local:' + name
|
|
|
|
});
|
2019-03-13 04:11:00 +00:00
|
|
|
document.querySelector('#manage-modal-content').innerHTML =
|
2017-08-20 17:46:10 +00:00
|
|
|
'<span class="local_save">' +
|
|
|
|
name +
|
|
|
|
' <a href="#" onclick="doDelete(\'' +
|
|
|
|
name +
|
2019-03-13 04:11:00 +00:00
|
|
|
'\')">Delete</a><br /></span>';
|
2017-08-20 17:46:10 +00:00
|
|
|
});
|
|
|
|
cat.push({
|
|
|
|
'category': 'Local Saves',
|
|
|
|
'name': 'Manage Saves...',
|
|
|
|
'filename': 'local:__manage'
|
2016-11-22 05:17:34 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function saveLocalStorage(drive, name) {
|
|
|
|
var diskIndex = JSON.parse(window.localStorage.diskIndex || '{}');
|
|
|
|
|
|
|
|
var json = disk2.getJSON(drive);
|
|
|
|
diskIndex[name] = json;
|
|
|
|
|
|
|
|
window.localStorage.diskIndex = JSON.stringify(diskIndex);
|
|
|
|
|
|
|
|
window.alert('Saved');
|
|
|
|
|
|
|
|
drivelights.label(drive, name);
|
|
|
|
drivelights.dirty(drive, false);
|
|
|
|
updateLocalStorage();
|
|
|
|
}
|
|
|
|
|
|
|
|
function deleteLocalStorage(name) {
|
|
|
|
var diskIndex = JSON.parse(window.localStorage.diskIndex || '{}');
|
|
|
|
if (diskIndex[name]) {
|
|
|
|
delete diskIndex[name];
|
|
|
|
window.alert('Deleted');
|
|
|
|
}
|
|
|
|
window.localStorage.diskIndex = JSON.stringify(diskIndex);
|
|
|
|
updateLocalStorage();
|
|
|
|
}
|
|
|
|
|
|
|
|
function loadLocalStorage(drive, name) {
|
|
|
|
var diskIndex = JSON.parse(window.localStorage.diskIndex || '{}');
|
|
|
|
if (diskIndex[name]) {
|
|
|
|
disk2.setJSON(drive, diskIndex[name]);
|
|
|
|
drivelights.label(drive, name);
|
|
|
|
drivelights.dirty(drive, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function processHash(hash) {
|
2016-11-28 01:28:49 +00:00
|
|
|
var files = hash.split('|');
|
|
|
|
for (var idx = 0; idx < files.length; idx++) {
|
|
|
|
var file = files[idx];
|
|
|
|
if (file.indexOf('://') > 0) {
|
|
|
|
var parts = file.split('.');
|
|
|
|
var ext = parts[parts.length - 1].toLowerCase();
|
|
|
|
if (ext == 'json') {
|
|
|
|
loadAjax(idx + 1, file);
|
|
|
|
} else {
|
|
|
|
doLoadHTTP(idx + 1, file);
|
|
|
|
}
|
2016-11-22 05:17:34 +00:00
|
|
|
} else {
|
2016-11-28 01:28:49 +00:00
|
|
|
loadAjax(idx + 1, 'json/disks/' + file + '.json');
|
2016-11-22 05:17:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Keyboard/Gamepad routines
|
|
|
|
*/
|
|
|
|
|
|
|
|
function _keydown(evt) {
|
2019-03-13 04:11:00 +00:00
|
|
|
if (!focused && (!evt.metaKey || evt.ctrlKey)) {
|
2016-11-22 05:17:34 +00:00
|
|
|
evt.preventDefault();
|
|
|
|
|
|
|
|
var key = keyboard.mapKeyEvent(evt);
|
|
|
|
if (key != 0xff) {
|
2017-10-01 18:17:30 +00:00
|
|
|
io.keyDown(key);
|
2016-11-22 05:17:34 +00:00
|
|
|
}
|
|
|
|
}
|
2016-11-28 01:28:49 +00:00
|
|
|
if (evt.keyCode === 112) { // F1 - Reset
|
2016-11-22 05:17:34 +00:00
|
|
|
cpu.reset();
|
2019-01-03 23:28:58 +00:00
|
|
|
evt.preventDefault(); // prevent launching help
|
2016-11-22 05:17:34 +00:00
|
|
|
} else if (evt.keyCode === 113) { // F2 - Full Screen
|
|
|
|
var elem = document.getElementById('screen');
|
2019-01-03 23:37:19 +00:00
|
|
|
if (evt.shiftKey) { // Full window, but not full screen
|
2019-03-13 04:11:00 +00:00
|
|
|
document.querySelector('#display').classList.toggle('zoomwindow');
|
2019-03-22 03:39:48 +00:00
|
|
|
document.querySelector('#display > div').classList.toggle('overscan');
|
|
|
|
document.querySelector('#display > div').classList.toggle('flexbox-centering');
|
2019-03-13 04:11:00 +00:00
|
|
|
document.querySelector('#screen').classList.toggle('maxhw');
|
|
|
|
document.querySelector('#header').classList.toggle('hidden');
|
2019-06-15 16:16:11 +00:00
|
|
|
document.querySelectorAll('.inset').forEach(function(el) { el.classList.toggle('hidden'); });
|
2019-03-13 04:11:00 +00:00
|
|
|
document.querySelector('#reset').classList.toggle('hidden');
|
2019-01-03 23:37:19 +00:00
|
|
|
} else if (document.webkitCancelFullScreen) {
|
2016-11-22 05:17:34 +00:00
|
|
|
if (document.webkitIsFullScreen) {
|
|
|
|
document.webkitCancelFullScreen();
|
|
|
|
} else {
|
|
|
|
if (Element.ALLOW_KEYBOARD_INPUT) {
|
|
|
|
elem.webkitRequestFullScreen(Element.ALLOW_KEYBOARD_INPUT);
|
|
|
|
} else {
|
|
|
|
elem.webkitRequestFullScreen();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (document.mozCancelFullScreen) {
|
|
|
|
if (document.mozIsFullScreen) {
|
|
|
|
document.mozCancelFullScreen();
|
|
|
|
} else {
|
|
|
|
elem.mozRequestFullScreen();
|
|
|
|
}
|
|
|
|
}
|
2016-11-28 01:28:49 +00:00
|
|
|
} else if (evt.keyCode === 114) { // F3
|
2016-11-22 05:17:34 +00:00
|
|
|
io.keyDown(0x1b);
|
2017-12-03 04:45:02 +00:00
|
|
|
} else if (evt.keyCode === 117) { // F6 Quick Save
|
|
|
|
saveState();
|
|
|
|
} else if (evt.keyCode === 120) { // F9 Quick Restore
|
|
|
|
restoreState();
|
2016-11-22 05:17:34 +00:00
|
|
|
} else if (evt.keyCode == 16) { // Shift
|
|
|
|
keyboard.shiftKey(true);
|
|
|
|
} 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
|
2019-03-14 02:27:55 +00:00
|
|
|
if (evt.location == 1) {
|
2019-01-03 23:32:56 +00:00
|
|
|
keyboard.commandKey(true);
|
|
|
|
} else {
|
|
|
|
keyboard.optionKey(true);
|
|
|
|
}
|
2016-11-22 05:17:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function _keyup(evt) {
|
|
|
|
if (!focused)
|
|
|
|
io.keyUp();
|
|
|
|
|
|
|
|
if (evt.keyCode == 16) { // Shift
|
|
|
|
keyboard.shiftKey(false);
|
|
|
|
} else if (evt.keyCode == 17) { // Control
|
|
|
|
keyboard.controlKey(false);
|
|
|
|
} else if (evt.keyCode == 91 || evt.keyCode == 93) { // Command
|
|
|
|
keyboard.commandKey(false);
|
|
|
|
} else if (evt.keyCode == 18) { // Alt
|
2019-03-14 02:27:55 +00:00
|
|
|
if (evt.location == 1) {
|
2019-01-03 23:32:56 +00:00
|
|
|
keyboard.commandKey(false);
|
|
|
|
} else {
|
|
|
|
keyboard.optionKey(false);
|
|
|
|
}
|
2016-11-22 05:17:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-01 03:52:45 +00:00
|
|
|
export function updateScreen() {
|
2019-03-13 04:11:00 +00:00
|
|
|
var green = document.querySelector('#green_screen').checked;
|
|
|
|
var scanlines = document.querySelector('#show_scanlines').checked;
|
2016-11-22 05:17:34 +00:00
|
|
|
|
|
|
|
vm.green(green);
|
2016-12-06 05:16:21 +00:00
|
|
|
vm.scanlines(scanlines);
|
2019-04-06 19:20:35 +00:00
|
|
|
}
|
2016-11-22 05:17:34 +00:00
|
|
|
|
|
|
|
var disableMouseJoystick = false;
|
|
|
|
var flipX = false;
|
|
|
|
var flipY = false;
|
|
|
|
var swapXY = false;
|
|
|
|
|
2019-04-01 03:52:45 +00:00
|
|
|
export function updateJoystick() {
|
2019-03-13 04:11:00 +00:00
|
|
|
disableMouseJoystick = document.querySelector('#disable_mouse').checked;
|
|
|
|
flipX = document.querySelector('#flip_x').checked;
|
|
|
|
flipY = document.querySelector('#flip_y').checked;
|
|
|
|
swapXY = document.querySelector('#swap_x_y').checked;
|
2019-03-01 14:48:50 +00:00
|
|
|
configGamepad(flipX, flipY);
|
2016-11-22 05:17:34 +00:00
|
|
|
|
|
|
|
if (disableMouseJoystick) {
|
|
|
|
io.paddle(0, 0.5);
|
|
|
|
io.paddle(1, 0.5);
|
|
|
|
return;
|
|
|
|
}
|
2019-04-01 03:52:45 +00:00
|
|
|
}
|
2016-11-22 05:17:34 +00:00
|
|
|
|
|
|
|
function _mousemove(evt) {
|
|
|
|
if (gamepad || disableMouseJoystick) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-03-13 04:11:00 +00:00
|
|
|
var s = document.querySelector('#screen');
|
2019-07-27 22:57:40 +00:00
|
|
|
var offset = s.getBoundingClientRect();
|
2019-03-13 04:11:00 +00:00
|
|
|
var x = (evt.pageX - offset.left) / s.clientWidth,
|
|
|
|
y = (evt.pageY - offset.top) / s.clientHeight,
|
2016-11-22 05:17:34 +00:00
|
|
|
z = x;
|
|
|
|
|
|
|
|
if (swapXY) {
|
|
|
|
x = y;
|
|
|
|
y = z;
|
|
|
|
}
|
|
|
|
|
|
|
|
io.paddle(0, flipX ? 1 - x : x);
|
|
|
|
io.paddle(1, flipY ? 1 - y : y);
|
|
|
|
}
|
|
|
|
|
2019-04-01 03:52:45 +00:00
|
|
|
export function pauseRun() {
|
2019-03-13 04:11:00 +00:00
|
|
|
var label = document.querySelector('#pause-run i');
|
2016-11-22 05:17:34 +00:00
|
|
|
if (paused) {
|
|
|
|
run();
|
2019-03-13 04:11:00 +00:00
|
|
|
label.classList.remove('fa-play');
|
|
|
|
label.classList.add('fa-pause');
|
2016-11-22 05:17:34 +00:00
|
|
|
} else {
|
|
|
|
stop();
|
2019-03-13 04:11:00 +00:00
|
|
|
label.classList.remove('fa-pause');
|
|
|
|
label.classList.add('fa-play');
|
2016-11-22 05:17:34 +00:00
|
|
|
}
|
|
|
|
paused = !paused;
|
2019-04-01 03:52:45 +00:00
|
|
|
}
|
2016-11-22 05:17:34 +00:00
|
|
|
|
2019-04-01 03:52:45 +00:00
|
|
|
export function toggleSound() {
|
2019-03-13 04:11:00 +00:00
|
|
|
var enableSound = document.querySelector('#enable_sound');
|
|
|
|
enableSound.checked = !enableSound.checked;
|
2019-04-01 03:52:45 +00:00
|
|
|
updateSound();
|
|
|
|
}
|
2019-02-19 04:42:50 +00:00
|
|
|
|
2019-04-01 03:52:45 +00:00
|
|
|
export function openOptions() {
|
2019-03-13 04:11:00 +00:00
|
|
|
MicroModal.show('options-modal');
|
2019-04-06 19:20:35 +00:00
|
|
|
}
|
2016-11-22 05:17:34 +00:00
|
|
|
|
2019-04-01 03:52:45 +00:00
|
|
|
export function openPrinterModal() {
|
2019-03-13 04:11:00 +00:00
|
|
|
MicroModal.show('printer-modal');
|
2019-04-06 19:20:35 +00:00
|
|
|
}
|
2019-03-13 04:11:00 +00:00
|
|
|
|
|
|
|
MicroModal.init();
|
|
|
|
|
|
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
|
|
hashtag = document.location.hash;
|
2016-11-22 05:17:34 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Input Handling
|
|
|
|
*/
|
|
|
|
|
2019-03-13 04:11:00 +00:00
|
|
|
window.addEventListener('keydown', _keydown);
|
|
|
|
window.addEventListener('keyup', _keyup);
|
|
|
|
window.addEventListener('mousedown', function() { audio.autoStart(); });
|
2016-11-22 05:17:34 +00:00
|
|
|
|
2019-03-13 04:11:00 +00:00
|
|
|
document.querySelectorAll('canvas').forEach(function(canvas) {
|
|
|
|
canvas.addEventListener('mousedown', function(evt) {
|
2019-02-19 04:42:50 +00:00
|
|
|
if (!gamepad) {
|
|
|
|
io.buttonDown(evt.which == 1 ? 0 : 1);
|
|
|
|
}
|
|
|
|
evt.preventDefault();
|
2019-03-13 04:11:00 +00:00
|
|
|
});
|
|
|
|
canvas.addEventListener('mouseup', function(evt) {
|
2017-09-24 14:06:57 +00:00
|
|
|
if (!gamepad) {
|
|
|
|
io.buttonUp(evt.which == 1 ? 0 : 1);
|
|
|
|
}
|
2019-03-13 04:11:00 +00:00
|
|
|
});
|
|
|
|
});
|
2016-11-22 05:17:34 +00:00
|
|
|
|
2019-03-13 04:11:00 +00:00
|
|
|
document.body.addEventListener('mousemove', _mousemove);
|
2016-11-22 05:17:34 +00:00
|
|
|
|
2019-03-13 04:11:00 +00:00
|
|
|
document.querySelectorAll('input,textarea').forEach(function(input) {
|
|
|
|
input.addEventListener('input', function() { focused = true; });
|
|
|
|
input.addEventListener('blur', function() { focused = false; });
|
|
|
|
});
|
2016-11-22 05:17:34 +00:00
|
|
|
|
2019-02-19 04:42:50 +00:00
|
|
|
keyboard.create('#keyboard');
|
2016-11-22 05:17:34 +00:00
|
|
|
|
|
|
|
if (prefs.havePrefs()) {
|
2019-03-13 04:11:00 +00:00
|
|
|
document.querySelectorAll('#options-modal input[type=checkbox]').forEach(function(el) {
|
|
|
|
var val = prefs.readPref(el.id);
|
|
|
|
if (val) {
|
|
|
|
el.checked = JSON.parse(val);
|
|
|
|
}
|
|
|
|
el.addEventListener('change', function() {
|
|
|
|
prefs.writePref(el.id, JSON.stringify(el.checked));
|
|
|
|
});
|
2016-11-22 05:17:34 +00:00
|
|
|
});
|
2019-03-13 04:11:00 +00:00
|
|
|
document.querySelectorAll('#options-modal select').forEach(function(el) {
|
|
|
|
var val = prefs.readPref(el.id);
|
|
|
|
if (val) {
|
|
|
|
el.value = val;
|
|
|
|
}
|
|
|
|
el.addEventListener('change', function() {
|
|
|
|
prefs.writePref(el.id, el.value);
|
|
|
|
});
|
2016-11-28 01:28:49 +00:00
|
|
|
});
|
2016-11-22 05:17:34 +00:00
|
|
|
}
|
|
|
|
|
2019-04-01 03:52:45 +00:00
|
|
|
cpu.reset();
|
2016-11-22 05:17:34 +00:00
|
|
|
setInterval(updateKHz, 1000);
|
2019-04-01 03:52:45 +00:00
|
|
|
updateSound();
|
|
|
|
updateScreen();
|
|
|
|
updateCPU();
|
2016-11-22 05:17:34 +00:00
|
|
|
|
|
|
|
if (window.localStorage !== undefined) {
|
2019-03-13 04:11:00 +00:00
|
|
|
document.querySelectorAll('.disksave').forEach(function (el) { el.style.display = 'inline-block';});
|
2016-11-22 05:17:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var oldcat = '';
|
2019-03-13 04:11:00 +00:00
|
|
|
var option;
|
2019-03-01 05:21:18 +00:00
|
|
|
for (var idx = 0; idx < window.disk_index.length; idx++) {
|
|
|
|
var file = window.disk_index[idx];
|
2016-11-22 05:17:34 +00:00
|
|
|
var cat = file.category;
|
|
|
|
var name = file.name, disk = file.disk;
|
|
|
|
if (cat != oldcat) {
|
2019-03-13 04:11:00 +00:00
|
|
|
option = document.createElement('option');
|
|
|
|
option.value = cat;
|
|
|
|
option.innerText = cat;
|
|
|
|
document.querySelector('#category_select').append(option);
|
|
|
|
|
2016-11-22 05:17:34 +00:00
|
|
|
disk_categories[cat] = [];
|
|
|
|
oldcat = cat;
|
|
|
|
}
|
|
|
|
disk_categories[cat].push(file);
|
|
|
|
if (disk) {
|
|
|
|
if (!disk_sets[name]) {
|
|
|
|
disk_sets[name] = [];
|
|
|
|
}
|
|
|
|
disk_sets[name].push(file);
|
|
|
|
}
|
|
|
|
}
|
2019-03-13 04:11:00 +00:00
|
|
|
option = document.createElement('option');
|
|
|
|
option.innerText = 'Local Saves';
|
|
|
|
document.querySelector('#category_select').append(option);
|
2016-11-22 05:17:34 +00:00
|
|
|
|
|
|
|
updateLocalStorage();
|
|
|
|
initGamepad();
|
|
|
|
|
|
|
|
// Check for disks in hashtag
|
|
|
|
|
|
|
|
var hash = gup('disk') || hup();
|
|
|
|
if (hash) {
|
|
|
|
processHash(hash);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (navigator.standalone) {
|
2019-03-13 04:11:00 +00:00
|
|
|
document.body.classList.add('standalone');
|
2016-11-22 05:17:34 +00:00
|
|
|
}
|
|
|
|
|
2019-02-19 04:42:50 +00:00
|
|
|
run();
|
2016-11-22 05:17:34 +00:00
|
|
|
});
|