Skip to content

Commit

Permalink
auto-loading of tapes
Browse files Browse the repository at this point in the history
  • Loading branch information
gasman committed Jul 13, 2012
1 parent d8b758c commit 8713eca
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 11 deletions.
7 changes: 6 additions & 1 deletion Makefile
Expand Up @@ -8,6 +8,10 @@ build/roms.js: bin2js.pl roms/*
mkdir -p build
perl bin2js.pl roms JSSpeccy.roms > build/roms.js

build/autoloaders.js: bin2js.pl autoloaders/*
mkdir -p build
perl bin2js.pl autoloaders JSSpeccy.autoloaders > build/autoloaders.js

build/z80.js: core/z80.coffee
mkdir -p build
coffee -c -o build/ core/z80.coffee
Expand All @@ -19,6 +23,7 @@ CORE_JS_FILES=\
core/keyboard.js \
core/memory.js \
build/roms.js \
build/autoloaders.js \
core/sna_file.js \
core/spectrum.js \
core/tap_file.js \
Expand All @@ -31,7 +36,7 @@ build/jsspeccy-core.min.js: $(CORE_JS_FILES)
mkdir -p build
java -jar compiler.jar \
--js=core/jsspeccy.js --js=core/display.js --js=core/io_bus.js --js=core/keyboard.js \
--js=core/memory.js --js=build/roms.js --js=core/sna_file.js --js=core/spectrum.js \
--js=core/memory.js --js=build/roms.js --js=build/autoloaders.js --js=core/sna_file.js --js=core/spectrum.js \
--js=core/tap_file.js --js=core/tzx_file.js --js=core/viewport.js --js=build/z80.js \
--js=core/z80_file.js \
--js_output_file=build/jsspeccy-core.min.js
Expand Down
Binary file added autoloaders/tape_128.z80
Binary file not shown.
Binary file added autoloaders/tape_48.z80
Binary file not shown.
25 changes: 18 additions & 7 deletions core/jsspeccy.js
Expand Up @@ -62,14 +62,14 @@ function JSSpeccy(container, opts) {
self.reset = function() {
spectrum.reset();
};
self.loadLocalFile = function(file) {
self.loadLocalFile = function(file, opts) {
var reader = new FileReader();
reader.onloadend = function() {
self.loadFile(file.name, this.result);
self.loadFile(file.name, this.result, opts);
};
reader.readAsArrayBuffer(file);
};
self.loadFromUrl = function(url) {
self.loadFromUrl = function(url, opts) {
var request = new XMLHttpRequest();

request.addEventListener('error', function(e) {
Expand All @@ -78,7 +78,7 @@ function JSSpeccy(container, opts) {

request.addEventListener('load', function(e) {
data = request.response;
self.loadFile(url, data);
self.loadFile(url, data, opts);
/* URL is not ideal for passing as the 'filename' argument - e.g. the file
may be served through a server-side script with a non-indicative file
extension - but it's better than nothing, and hopefully the heuristics
Expand All @@ -93,7 +93,9 @@ function JSSpeccy(container, opts) {
request.send();
};

self.loadFile = function(name, data) {
self.loadFile = function(name, data, opts) {
if (!opts) opts = {};

var fileType = 'unknown';
if (name && name.match(/\.sna(\.zip)?$/i)) {
fileType = 'sna';
Expand Down Expand Up @@ -123,10 +125,10 @@ function JSSpeccy(container, opts) {
loadSnapshot(JSSpeccy.Z80File(data));
break;
case 'tap':
self.currentTape = JSSpeccy.TapFile(data);
loadTape(JSSpeccy.TapFile(data), opts);
break;
case 'tzx':
self.currentTape = JSSpeccy.TzxFile(data);
loadTape(JSSpeccy.TzxFile(data), opts);
break;
}
};
Expand All @@ -139,6 +141,15 @@ function JSSpeccy(container, opts) {
e.g. paging is locked */
spectrum.loadSnapshot(snapshot);
}
function loadTape(tape, opts) {
if (!opts) opts = {};
self.currentTape = tape;
if (opts.autoload) {
var snapshotBuffer = JSSpeccy.autoloaders[currentModel.tapeAutoloader].buffer;
var snapshot = JSSpeccy.Z80File(snapshotBuffer);
loadSnapshot(snapshot);
}
}

self.isRunning = false;
self.currentTape = null;
Expand Down
2 changes: 2 additions & 0 deletions core/spectrum.js
Expand Up @@ -132,6 +132,7 @@ JSSpeccy.buildContentionTables = function(model) {
JSSpeccy.Spectrum.MODEL_48K = {
id: '48k',
name: 'Spectrum 48K',
tapeAutoloader: 'tape_48.z80',
tstatesUntilOrigin: 14336,
tstatesPerScanline: 224,
frameLength: 69888,
Expand All @@ -142,6 +143,7 @@ JSSpeccy.buildContentionTables(JSSpeccy.Spectrum.MODEL_48K);
JSSpeccy.Spectrum.MODEL_128K = {
id: '128k',
name: 'Spectrum 128K',
tapeAutoloader: 'tape_128.z80',
tstatesUntilOrigin: 14362,
tstatesPerScanline: 228,
frameLength: 70908,
Expand Down
9 changes: 6 additions & 3 deletions ui/ui.js
Expand Up @@ -96,15 +96,15 @@ JSSpeccy.UI = function(opts) {

var fileSelect = openFilePanel.find('input[type="file"]');
fileSelect.change(function() {
controller.loadLocalFile(this.files[0]);
controller.loadLocalFile(this.files[0], {'autoload': true});
hidePanels();
});

var urlField = openFilePanel.find('input[type="url"]');
openFilePanel.find('button.open-url').click(function() {
var url = urlField.val();
if (url !== '') {
controller.loadFromUrl(url);
controller.loadFromUrl(url, {'autoload': true});
hidePanels();
}
});
Expand Down Expand Up @@ -195,7 +195,10 @@ JSSpeccy.UI = function(opts) {
function loadSelectedFile() {
var url = wosDownloads.val();
if (url) {
controller.loadFromUrl(url.replace('ftp://ftp.worldofspectrum.org/pub/sinclair/', 'http://wosproxy.zxdemo.org/unzip/'));
controller.loadFromUrl(
url.replace('ftp://ftp.worldofspectrum.org/pub/sinclair/', 'http://wosproxy.zxdemo.org/unzip/'),
{'autoload': true}
);
hidePanels();
}
}
Expand Down

0 comments on commit 8713eca

Please sign in to comment.