mirror of
https://github.com/sehugg/8bitworkshop.git
synced 2025-01-22 05:31:33 +00:00
more modules to typescript
This commit is contained in:
parent
65210b39b8
commit
a8c1ead244
@ -242,12 +242,12 @@ function require(modname) {
|
||||
<script src="tss/js/tss/AudioLooper.js"></script>
|
||||
<script src="tss/js/Log.js"></script>
|
||||
|
||||
<script src="src/store.js"></script>
|
||||
<script src="gen/store.js"></script>
|
||||
<script src="src/vlist.js"></script>
|
||||
<script src="src/emu.js"></script>
|
||||
<script src="src/audio.js"></script>
|
||||
<script src="gen/emu.js"></script>
|
||||
<script src="gen/audio.js"></script>
|
||||
<script src="gen/util.js"></script>
|
||||
<script src="src/cpu/disasm6502.js"></script>
|
||||
<script src="gen/cpu/disasm6502.js"></script>
|
||||
<script src="gen/workertypes.js"></script>
|
||||
<script src="gen/project.js"></script>
|
||||
<script src="gen/windows.js"></script>
|
||||
|
@ -36,7 +36,7 @@ body {
|
||||
<script src="bootstrap/js/bootstrap.min.js"></script>
|
||||
<script src="FileSaver.js/FileSaver.min.js"></script>
|
||||
<script src="gen/util.js"></script>
|
||||
<script src="src/pixed/pixeleditor.js"></script>
|
||||
<script src="gen/pixed/pixeleditor.js"></script>
|
||||
|
||||
<script>
|
||||
|
||||
|
@ -1,5 +1,7 @@
|
||||
"use strict";
|
||||
|
||||
declare var MasterChannel, AudioLooper, PsgDeviceChannel;
|
||||
|
||||
var MasterAudio = function() {
|
||||
this.master = new MasterChannel();
|
||||
this.looper = new AudioLooper(512);
|
||||
@ -83,14 +85,14 @@ var POKEYDeviceChannel = function() {
|
||||
var FREQ_17_APPROX = 1787520.0 /* approximate 1.79 MHz clock freq */
|
||||
|
||||
// LFSR sequences
|
||||
var bit1 = [ 0,1 ];
|
||||
var bit4 = [ 1,1,0,1,1,1,0,0,0,0,1,0,1,0,0 ];
|
||||
var bit5 = [ 0,0,1,1,0,0,0,1,1,1,1,0,0,1,0,1,0,1,1,0,1,1,1,0,1,0,0,0,0,0,1 ];
|
||||
var bit1 = new Uint8Array( [ 0,1 ] );
|
||||
var bit4 = new Uint8Array( [ 1,1,0,1,1,1,0,0,0,0,1,0,1,0,0 ] );
|
||||
var bit5 = new Uint8Array( [ 0,0,1,1,0,0,0,1,1,1,1,0,0,1,0,1,0,1,1,0,1,1,1,0,1,0,0,0,0,0,1 ] );
|
||||
var bit17 = new Uint8Array(1<<17);
|
||||
var bit17_5 = new Uint8Array(1<<17);
|
||||
var bit5_4 = new Uint8Array(1<<17);
|
||||
for (var i=0; i<bit17.length; i++) {
|
||||
bit17[i] = Math.random() > 0.5;
|
||||
bit17[i] = Math.random() > 0.5 ? 1 : 0;
|
||||
bit17_5[i] = bit17[i] & bit5[i % bit5.length];
|
||||
bit5_4[i] = bit5[i % bit5.length] & bit4[i % bit4.length];
|
||||
}
|
||||
@ -207,50 +209,6 @@ var POKEYDeviceChannel = function() {
|
||||
}
|
||||
}
|
||||
|
||||
////// CPU sound (unused)
|
||||
|
||||
var CPUSoundChannel = function(cpu, clockRate) {
|
||||
var sampleRate;
|
||||
var buffer;
|
||||
var lastbufpos=0;
|
||||
var curSample=0;
|
||||
var clocksPerSample;
|
||||
|
||||
this.setBufferLength = function (length) {
|
||||
buffer = new Int32Array(length);
|
||||
};
|
||||
|
||||
this.getBuffer = function () {
|
||||
return buffer;
|
||||
};
|
||||
|
||||
this.setSampleRate = function (rate) {
|
||||
sampleRate = rate;
|
||||
};
|
||||
|
||||
this.getSetDACFunction = function() {
|
||||
return function(a,v) {
|
||||
var bufpos = Math.floor(cpu.getTstates() / clocksPerSample);
|
||||
while (lastbufpos < bufpos)
|
||||
buffer[lastbufpos++] = curSample;
|
||||
lastbufpos = bufpos;
|
||||
curSample = v;
|
||||
};
|
||||
};
|
||||
|
||||
this.generate = function (length) {
|
||||
clocksPerSample = clockRate * 1.0 / sampleRate;
|
||||
var clocks = Math.round(length * clocksPerSample);
|
||||
if (cpu.getTstates && cpu.runFrame) {
|
||||
cpu.setTstates(0);
|
||||
lastbufpos = 0;
|
||||
cpu.runFrame(cpu.getTstates() + totalClocks);
|
||||
while (lastbufpos < length)
|
||||
buffer[lastbufpos++] = curSample;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
////// Worker sound
|
||||
|
||||
var WorkerSoundChannel = function(worker) {
|
||||
@ -334,7 +292,7 @@ var SampleAudio = function(clockfreq) {
|
||||
}
|
||||
|
||||
function createContext() {
|
||||
var AudioContext = window.AudioContext || window.webkitAudioContext || window.mozAudioContext;
|
||||
var AudioContext = window['AudioContext'] || window['webkitAudioContext'] || window['mozAudioContext'];
|
||||
if (! AudioContext) {
|
||||
console.log("no web audio context");
|
||||
return;
|
@ -258,7 +258,7 @@ var OPS_6502 = [
|
||||
{mn:"ISB",am:"AAAA,x",nb:3,il:1,c1:7,c2:1}, // FF
|
||||
];
|
||||
|
||||
function disassemble6502(pc, b0, b1, b2) {
|
||||
function disassemble6502(pc:number, b0:number, b1:number, b2:number) : {line:string, nbytes:number} {
|
||||
|
||||
function formatHex(number, len) {
|
||||
if (typeof number === "undefined" || number === null || isNaN(number)) {
|
@ -1,16 +1,19 @@
|
||||
"use strict";
|
||||
|
||||
// external modules
|
||||
declare var jt, Javatari, Z80_fast, CPU6809;
|
||||
|
||||
// Emulator classes
|
||||
|
||||
var PLATFORMS = {};
|
||||
|
||||
var frameUpdateFunction = null;
|
||||
var frameUpdateFunction : (Canvas) => void = null;
|
||||
|
||||
function noise() {
|
||||
return (Math.random() * 256) & 0xff;
|
||||
}
|
||||
|
||||
function __createCanvas(mainElement, width, height) {
|
||||
function __createCanvas(mainElement:HTMLElement, width:number, height:number) {
|
||||
// TODO
|
||||
var fsElement = document.createElement('div');
|
||||
fsElement.classList.add("emubevel");
|
||||
@ -19,14 +22,14 @@ function __createCanvas(mainElement, width, height) {
|
||||
canvas.width = width;
|
||||
canvas.height = height;
|
||||
canvas.classList.add("emuvideo");
|
||||
canvas.tabIndex = "-1"; // Make it focusable
|
||||
canvas.tabIndex = -1; // Make it focusable
|
||||
|
||||
fsElement.appendChild(canvas);
|
||||
mainElement.appendChild(fsElement);
|
||||
return canvas;
|
||||
}
|
||||
|
||||
var RasterVideo = function(mainElement, width, height, options) {
|
||||
var RasterVideo = function(mainElement:HTMLElement, width:number, height:number, options?) {
|
||||
var self = this;
|
||||
var canvas, ctx;
|
||||
var imageData, arraybuf, buf8, datau32;
|
||||
@ -131,7 +134,7 @@ mainElement.appendChild(borderElement);
|
||||
*/
|
||||
}
|
||||
|
||||
var VectorVideo = function(mainElement, width, height) {
|
||||
var VectorVideo = function(mainElement:HTMLElement, width:number, height:number) {
|
||||
var self = this;
|
||||
var canvas, ctx;
|
||||
var persistenceAlpha = 0.5;
|
||||
@ -204,12 +207,12 @@ var VectorVideo = function(mainElement, width, height) {
|
||||
}
|
||||
}
|
||||
|
||||
var RAM = function(size) {
|
||||
var RAM = function(size:number) {
|
||||
var memArray = new ArrayBuffer(size);
|
||||
this.mem = new Uint8Array(memArray);
|
||||
}
|
||||
|
||||
var AnimationTimer = function(frequencyHz, callback) {
|
||||
var AnimationTimer = function(frequencyHz:number, callback:() => void) {
|
||||
var intervalMsec = 1000.0 / frequencyHz;
|
||||
var running;
|
||||
var lastts = 0;
|
||||
@ -265,8 +268,8 @@ var AnimationTimer = function(frequencyHz, callback) {
|
||||
|
||||
//
|
||||
|
||||
function cpuStateToLongString_6502(c) {
|
||||
function decodeFlags(c, flags) {
|
||||
function cpuStateToLongString_6502(c) : string {
|
||||
function decodeFlags(c) {
|
||||
var s = "";
|
||||
s += c.N ? " N" : " -";
|
||||
s += c.V ? " V" : " -";
|
||||
@ -893,7 +896,10 @@ var BusProbe = function(bus) {
|
||||
|
||||
/// MAME SUPPORT
|
||||
|
||||
declare var FS, ENV, Module; // mame emscripten
|
||||
|
||||
var BaseMAMEPlatform = function() {
|
||||
|
||||
var self = this;
|
||||
|
||||
var loaded = false;
|
||||
@ -903,7 +909,7 @@ var BaseMAMEPlatform = function() {
|
||||
var video;
|
||||
var preload_files;
|
||||
var running = false;
|
||||
var console_vars = {};
|
||||
var console_vars : {[varname:string]:string[]} = {};
|
||||
var console_varname;
|
||||
var initluavars = false;
|
||||
var luadebugscript;
|
||||
@ -978,11 +984,11 @@ var BaseMAMEPlatform = function() {
|
||||
'-debug',
|
||||
'-debugger', 'none',
|
||||
'-verbose', '-window', '-nokeepaspect',
|
||||
'-resolution', canvas.width+'x'+canvas.height
|
||||
'-resolution', video.canvas.width+'x'+video.canvas.height
|
||||
];
|
||||
if (romfn) modargs.push('-cart', romfn);
|
||||
window.JSMESS = {};
|
||||
window.Module = {
|
||||
window['JSMESS'] = {};
|
||||
window['Module'] = {
|
||||
arguments: modargs,
|
||||
screenIsReadOnly: true,
|
||||
print: bufferConsoleOutput,
|
||||
@ -1039,7 +1045,7 @@ var BaseMAMEPlatform = function() {
|
||||
oReq1.responseType = "arraybuffer";
|
||||
oReq1.onload = function(oEvent) {
|
||||
opts.biosdata = new Uint8Array(oReq1.response);
|
||||
console.log("loaded " + opts.biosfile + " (" + oEvent.total + " bytes)");
|
||||
console.log("loaded " + opts.biosfile); // + " (" + oEvent.total + " bytes)");
|
||||
fetch_bios.resolve();
|
||||
};
|
||||
oReq1.send();
|
||||
@ -1058,7 +1064,7 @@ var BaseMAMEPlatform = function() {
|
||||
oReq2.responseType = "arraybuffer";
|
||||
oReq2.onload = function(oEvent) {
|
||||
console.log("loaded WASM file");
|
||||
window.Module.wasmBinary = new Uint8Array(oReq2.response);
|
||||
window['Module'].wasmBinary = new Uint8Array(oReq2.response);
|
||||
fetch_wasm.resolve();
|
||||
};
|
||||
oReq2.send();
|
@ -1,11 +1,11 @@
|
||||
"use strict";
|
||||
|
||||
function PixelEditor(parentDiv, fmt, palette, initialData, thumbnails) {
|
||||
function PixelEditor(parentDiv:HTMLElement, fmt, palette, initialData, thumbnails?) {
|
||||
var self = this;
|
||||
var width = fmt.w;
|
||||
var height = fmt.h;
|
||||
|
||||
function createCanvas(parent) {
|
||||
function createCanvas() {
|
||||
var c = document.createElement('canvas');
|
||||
c.width = width;
|
||||
c.height = height;
|
||||
@ -142,7 +142,7 @@ function PixelEditor(parentDiv, fmt, palette, initialData, thumbnails) {
|
||||
dragcol = getPixel(pos.x, pos.y) == curpalcol ? 0 : curpalcol;
|
||||
setPixel(pos.x, pos.y, curpalcol);
|
||||
dragging = true;
|
||||
pixcanvas.setCapture();
|
||||
// TODO: pixcanvas.setCapture();
|
||||
})
|
||||
.mousemove(function(e) {
|
||||
var pos = getPositionFromEvent(e);
|
||||
@ -155,7 +155,7 @@ function PixelEditor(parentDiv, fmt, palette, initialData, thumbnails) {
|
||||
setPixel(pos.x, pos.y, dragcol);
|
||||
dragging = false;
|
||||
commit();
|
||||
pixcanvas.releaseCapture();
|
||||
// TODO: pixcanvas.releaseCapture();
|
||||
});
|
||||
}
|
||||
|
||||
@ -453,14 +453,14 @@ function pixelEditorReceiveMessage(e) {
|
||||
|
||||
function createThumbnailForImage(parentdiv, i) {
|
||||
var span = $('<span class="thumb">');
|
||||
var thumb = new PixelEditor(span, currentFormat, palette, allimages[i]);
|
||||
var thumb = new PixelEditor(span[0], currentFormat, palette, allimages[i]);
|
||||
parentdiv.append(span);
|
||||
span.click(function() { createEditorForImage(i) });
|
||||
return thumb;
|
||||
}
|
||||
|
||||
function createEditorForImage(i) {
|
||||
currentPixelEditor = new PixelEditor(maineditor, currentFormat, palette, allimages[i], [allthumbs[i]]);
|
||||
currentPixelEditor = new PixelEditor(document.getElementById('maineditor'), currentFormat, palette, allimages[i], [allthumbs[i]]);
|
||||
currentPixelEditor.resize();
|
||||
currentPixelEditor.makeEditable();
|
||||
currentPixelEditor.createPaletteButtons();
|
@ -1,8 +1,10 @@
|
||||
"use strict";
|
||||
|
||||
// TODO: use modules; export type for LocalForageDbMethods
|
||||
//import * as localforage from "localforage";
|
||||
declare var localforage;
|
||||
|
||||
var OldFileStore = function(storage, prefix) {
|
||||
var OldFileStore = function(storage, prefix:string) {
|
||||
var self = this;
|
||||
this.saveFile = function(name, text) {
|
||||
storage.setItem(prefix + name, text);
|
||||
@ -66,7 +68,7 @@ localforage.defineDriver(OldFileStoreDriver);
|
||||
*/
|
||||
|
||||
// copy localStorage to new driver
|
||||
function copyFromOldStorageFormat(platformid, newstore, callback) {
|
||||
function copyFromOldStorageFormat(platformid:string, newstore, callback:()=>void) {
|
||||
var alreadyMigratedKey = "__migrated_" + platformid;
|
||||
//localStorage.removeItem(alreadyMigratedKey);
|
||||
if (localStorage.getItem(alreadyMigratedKey))
|
||||
@ -108,7 +110,7 @@ function copyFromOldStorageFormat(platformid, newstore, callback) {
|
||||
migrateNext(); // start the conversion
|
||||
}
|
||||
|
||||
function createNewPersistentStore(platformid, callback) {
|
||||
function createNewPersistentStore(platformid:string, callback:()=>void) {
|
||||
var store = localforage.createInstance({
|
||||
name: platformid,
|
||||
version: 2.0
|
@ -7,7 +7,7 @@ var ENVIRONMENT_IS_WORKER = typeof importScripts === 'function';
|
||||
// WebAssembly module cache
|
||||
// TODO: leaks memory even when disabled...
|
||||
var _WASM_module_cache = {};
|
||||
var CACHE_WASM_MODULES = ENVIRONMENT_IS_WORKER;
|
||||
var CACHE_WASM_MODULES = true;
|
||||
function getWASMModule(module_id) {
|
||||
var module = _WASM_module_cache[module_id];
|
||||
if (!module) {
|
||||
|
@ -7,7 +7,7 @@ var includeInThisContext = function(path) {
|
||||
vm.runInThisContext(code, path);
|
||||
};
|
||||
|
||||
includeInThisContext("src/cpu/disasm6502.js");
|
||||
includeInThisContext("gen/cpu/disasm6502.js");
|
||||
|
||||
describe('6502 disassembler', function() {
|
||||
it('Should work', function() {
|
||||
|
@ -6,7 +6,7 @@ var includeInThisContext = function(path) {
|
||||
vm.runInThisContext(code, path);
|
||||
};
|
||||
|
||||
includeInThisContext("src/emu.js");
|
||||
includeInThisContext("gen/emu.js");
|
||||
|
||||
function assert(b, msg) {
|
||||
if (!b) { throw new Error(msg); }
|
||||
|
@ -8,7 +8,7 @@ var includeInThisContext = function(path) {
|
||||
};
|
||||
|
||||
includeInThisContext("gen/util.js");
|
||||
includeInThisContext("src/pixed/pixeleditor.js");
|
||||
includeInThisContext("gen/pixed/pixeleditor.js");
|
||||
|
||||
describe('Pixel editor', function() {
|
||||
it('Should decode', function() {
|
||||
|
@ -46,7 +46,8 @@ global.localStorage = {
|
||||
|
||||
includeInThisContext("localForage/dist/localforage.js");
|
||||
includeInThisContext("gen/util.js");
|
||||
includeInThisContext("src/store.js");
|
||||
includeInThisContext("gen/store.js");
|
||||
//var sto = require("../../gen/store.js");
|
||||
//var wtypes = require("../../gen/workertypes.js");
|
||||
var prj = require("../../gen/project.js");
|
||||
|
||||
|
@ -3,7 +3,7 @@ var assert = require('assert');
|
||||
var fs = require('fs');
|
||||
var wtu = require('./workertestutils.js');
|
||||
|
||||
includeInThisContext('src/emu.js');
|
||||
includeInThisContext('gen/emu.js');
|
||||
includeInThisContext('src/platform/verilog.js');
|
||||
|
||||
function loadPlatform(msg) {
|
||||
|
@ -3,6 +3,9 @@ var assert = require('assert');
|
||||
var fs = require('fs');
|
||||
var wtu = require('./workertestutils.js');
|
||||
|
||||
// TODO: why memory leak?
|
||||
CACHE_WASM_MODULES = false;
|
||||
|
||||
global.onmessage({data:{preload:'cc65', platform:'nes'}});
|
||||
global.onmessage({data:{preload:'ca65', platform:'nes'}});
|
||||
global.onmessage({data:{preload:'sdcc'}});
|
||||
|
Loading…
x
Reference in New Issue
Block a user