mirror of
https://github.com/sehugg/8bitworkshop.git
synced 2025-05-19 05:38:13 +00:00
moved some types to workertypes.ts
This commit is contained in:
parent
1e7e7feae5
commit
82f01b3fcd
@ -248,6 +248,7 @@ function require(modname) {
|
|||||||
<script src="src/audio.js"></script>
|
<script src="src/audio.js"></script>
|
||||||
<script src="gen/util.js"></script>
|
<script src="gen/util.js"></script>
|
||||||
<script src="src/cpu/disasm6502.js"></script>
|
<script src="src/cpu/disasm6502.js"></script>
|
||||||
|
<script src="gen/workertypes.js"></script>
|
||||||
<script src="gen/project.js"></script>
|
<script src="gen/project.js"></script>
|
||||||
<script src="gen/windows.js"></script>
|
<script src="gen/windows.js"></script>
|
||||||
<script src="gen/views.js"></script>
|
<script src="gen/views.js"></script>
|
||||||
|
@ -1,84 +1,6 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
type FileData = string | Uint8Array;
|
import { FileData, Dependency, SourceLine, SourceFile, CodeListing, CodeListingMap, WorkerError, WorkerResult } from "./workertypes";
|
||||||
|
|
||||||
export interface SourceLine {
|
|
||||||
offset:number;
|
|
||||||
line:number;
|
|
||||||
insns?:string;
|
|
||||||
iscode?:boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface Dependency {
|
|
||||||
path:string,
|
|
||||||
filename:string,
|
|
||||||
data:FileData // TODO: or binary?
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface WorkerFileUpdate { path:string, data:FileData };
|
|
||||||
export interface WorkerBuildStep { path:string, platform:string, tool:string, mainfile?:boolean };
|
|
||||||
|
|
||||||
export interface WorkerMessage {
|
|
||||||
updates:WorkerFileUpdate[],
|
|
||||||
buildsteps:WorkerBuildStep[]
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface WorkerError {
|
|
||||||
line:number,
|
|
||||||
msg:string,
|
|
||||||
path?:string
|
|
||||||
//TODO
|
|
||||||
}
|
|
||||||
|
|
||||||
export class SourceFile {
|
|
||||||
lines: SourceLine[];
|
|
||||||
text: string;
|
|
||||||
offset2line: {[offset:number]:number};
|
|
||||||
line2offset: {[line:number]:number};
|
|
||||||
|
|
||||||
constructor(lines:SourceLine[], text?:string) {
|
|
||||||
lines = lines || [];
|
|
||||||
this.lines = lines;
|
|
||||||
this.text = text;
|
|
||||||
this.offset2line = {};
|
|
||||||
this.line2offset = {};
|
|
||||||
for (var info of lines) {
|
|
||||||
if (info.offset >= 0) {
|
|
||||||
this.offset2line[info.offset] = info.line;
|
|
||||||
this.line2offset[info.line] = info.offset;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
findLineForOffset(PC:number):number {
|
|
||||||
if (this.offset2line) {
|
|
||||||
for (var i=0; i<16; i++) {
|
|
||||||
var line = this.offset2line[PC];
|
|
||||||
if (line >= 0) {
|
|
||||||
return line;
|
|
||||||
}
|
|
||||||
PC--;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
lineCount():number { return this.lines.length; }
|
|
||||||
}
|
|
||||||
|
|
||||||
interface CodeListing {
|
|
||||||
lines:SourceLine[],
|
|
||||||
asmlines:SourceLine[],
|
|
||||||
text:string,
|
|
||||||
sourcefile:SourceFile,
|
|
||||||
assemblyfile:SourceFile
|
|
||||||
}
|
|
||||||
|
|
||||||
type CodeListingMap = {[path:string]:CodeListing};
|
|
||||||
|
|
||||||
interface WorkerResult {
|
|
||||||
output:Uint8Array, //TODO
|
|
||||||
errors:WorkerError[],
|
|
||||||
listings:CodeListingMap,
|
|
||||||
}
|
|
||||||
|
|
||||||
type BuildResultCallback = (result:WorkerResult) => void;
|
type BuildResultCallback = (result:WorkerResult) => void;
|
||||||
type BuildStatusCallback = (busy:boolean) => void;
|
type BuildStatusCallback = (busy:boolean) => void;
|
||||||
|
39
src/ui.ts
39
src/ui.ts
@ -4,7 +4,8 @@
|
|||||||
|
|
||||||
import $ = require("jquery");
|
import $ = require("jquery");
|
||||||
import * as bootstrap from "bootstrap";
|
import * as bootstrap from "bootstrap";
|
||||||
import { SourceFile, CodeProject } from "./project";
|
import { CodeProject } from "./project";
|
||||||
|
import { WorkerResult, SourceFile } from "./workertypes";
|
||||||
import { ProjectWindows } from "./windows";
|
import { ProjectWindows } from "./windows";
|
||||||
import { Platform, Preset } from "./baseplatform";
|
import { Platform, Preset } from "./baseplatform";
|
||||||
import * as Views from "./views";
|
import * as Views from "./views";
|
||||||
@ -43,7 +44,7 @@ var TOOL_TO_SOURCE_STYLE = {
|
|||||||
'jsasm': 'z80'
|
'jsasm': 'z80'
|
||||||
}
|
}
|
||||||
|
|
||||||
function newWorker() {
|
function newWorker() : Worker {
|
||||||
return new Worker("./src/worker/workermain.js");
|
return new Worker("./src/worker/workermain.js");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,21 +61,21 @@ var store; // persistent store
|
|||||||
var lastDebugInfo; // last debug info (CPU text)
|
var lastDebugInfo; // last debug info (CPU text)
|
||||||
var lastDebugState; // last debug state (object)
|
var lastDebugState; // last debug state (object)
|
||||||
|
|
||||||
function inspectVariable(ed, name) {
|
function inspectVariable(ed, name) { // TODO: ed?
|
||||||
var val;
|
var val;
|
||||||
if (platform.inspect) {
|
if (platform.inspect) {
|
||||||
platform.inspect(name);
|
platform.inspect(name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getCurrentPresetTitle() {
|
function getCurrentPresetTitle() : string {
|
||||||
if (!current_preset_entry)
|
if (!current_preset_entry)
|
||||||
return "ROM";
|
return "ROM";
|
||||||
else
|
else
|
||||||
return current_preset_entry.title || current_preset_entry.name || "ROM";
|
return current_preset_entry.title || current_preset_entry.name || "ROM";
|
||||||
}
|
}
|
||||||
|
|
||||||
function setLastPreset(id) {
|
function setLastPreset(id:string) {
|
||||||
if (platform_id != 'base_z80') { // TODO
|
if (platform_id != 'base_z80') { // TODO
|
||||||
localStorage.setItem("__lastplatform", platform_id);
|
localStorage.setItem("__lastplatform", platform_id);
|
||||||
localStorage.setItem("__lastid_"+platform_id, id);
|
localStorage.setItem("__lastid_"+platform_id, id);
|
||||||
@ -125,7 +126,7 @@ function refreshWindowList() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadEditor(path) {
|
function loadEditor(path:string) {
|
||||||
var tool = platform.getToolForFilename(path);
|
var tool = platform.getToolForFilename(path);
|
||||||
var mode = tool && TOOL_TO_SOURCE_STYLE[tool];
|
var mode = tool && TOOL_TO_SOURCE_STYLE[tool];
|
||||||
return new Views.SourceEditor(path, mode);
|
return new Views.SourceEditor(path, mode);
|
||||||
@ -170,7 +171,7 @@ function refreshWindowList() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// can pass integer or string id
|
// can pass integer or string id
|
||||||
function loadProject(preset_id) {
|
function loadProject(preset_id:string) {
|
||||||
var index = parseInt(preset_id+""); // might fail -1
|
var index = parseInt(preset_id+""); // might fail -1
|
||||||
for (var i=0; i<PRESETS.length; i++)
|
for (var i=0; i<PRESETS.length; i++)
|
||||||
if (PRESETS[i].id == preset_id)
|
if (PRESETS[i].id == preset_id)
|
||||||
@ -198,13 +199,13 @@ function loadProject(preset_id) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function reloadPresetNamed(id) {
|
function reloadPresetNamed(id:string) {
|
||||||
qs['platform'] = platform_id;
|
qs['platform'] = platform_id;
|
||||||
qs['file'] = id;
|
qs['file'] = id;
|
||||||
gotoNewLocation();
|
gotoNewLocation();
|
||||||
}
|
}
|
||||||
|
|
||||||
function getSkeletonFile(fileid, callback) {
|
function getSkeletonFile(fileid:string, callback) {
|
||||||
var ext = platform.getToolForFilename(fileid);
|
var ext = platform.getToolForFilename(fileid);
|
||||||
$.get( "presets/"+platform_id+"/skeleton."+ext, function( text ) {
|
$.get( "presets/"+platform_id+"/skeleton."+ext, function( text ) {
|
||||||
callback(null, text);
|
callback(null, text);
|
||||||
@ -240,7 +241,7 @@ function _uploadNewFile(e) {
|
|||||||
$("#uploadFileElem").click();
|
$("#uploadFileElem").click();
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleFileUpload(files) {
|
function handleFileUpload(files: File[]) {
|
||||||
console.log(files);
|
console.log(files);
|
||||||
var index = 0;
|
var index = 0;
|
||||||
function uploadNextFile() {
|
function uploadNextFile() {
|
||||||
@ -270,7 +271,7 @@ function handleFileUpload(files) {
|
|||||||
if (files) uploadNextFile();
|
if (files) uploadNextFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
function getCurrentFilename() {
|
function getCurrentFilename() : string {
|
||||||
var toks = main_file_id.split("/");
|
var toks = main_file_id.split("/");
|
||||||
return toks[toks.length-1];
|
return toks[toks.length-1];
|
||||||
}
|
}
|
||||||
@ -373,7 +374,7 @@ function updateSelector() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function setCompileOutput(data) {
|
function setCompileOutput(data: WorkerResult) {
|
||||||
// errors? mark them in editor
|
// errors? mark them in editor
|
||||||
if (data.errors && data.errors.length > 0) {
|
if (data.errors && data.errors.length > 0) {
|
||||||
projectWindows.setErrors(data.errors);
|
projectWindows.setErrors(data.errors);
|
||||||
@ -387,7 +388,7 @@ function setCompileOutput(data) {
|
|||||||
compparams = data.params;
|
compparams = data.params;
|
||||||
// load ROM
|
// load ROM
|
||||||
var rom = data.output;
|
var rom = data.output;
|
||||||
if (rom) {
|
if (rom instanceof Uint8Array) {
|
||||||
try {
|
try {
|
||||||
//console.log("Loading ROM length", rom.length);
|
//console.log("Loading ROM length", rom.length);
|
||||||
platform.loadROM(getCurrentPresetTitle(), rom);
|
platform.loadROM(getCurrentPresetTitle(), rom);
|
||||||
@ -427,7 +428,7 @@ function showMemory(state?) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function setDebugButtonState(btnid, btnstate) {
|
function setDebugButtonState(btnid:string, btnstate:string) {
|
||||||
$("#debug_bar").find("button").removeClass("btn_active").removeClass("btn_stopped");
|
$("#debug_bar").find("button").removeClass("btn_active").removeClass("btn_stopped");
|
||||||
$("#dbg_"+btnid).addClass("btn_"+btnstate);
|
$("#dbg_"+btnid).addClass("btn_"+btnstate);
|
||||||
}
|
}
|
||||||
@ -483,7 +484,7 @@ function singleFrameStep() {
|
|||||||
platform.runToVsync();
|
platform.runToVsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
function getEditorPC() {
|
function getEditorPC() : number {
|
||||||
var wnd = projectWindows.getActive();
|
var wnd = projectWindows.getActive();
|
||||||
return wnd && wnd.getCursorPC && wnd.getCursorPC();
|
return wnd && wnd.getCursorPC && wnd.getCursorPC();
|
||||||
}
|
}
|
||||||
@ -545,7 +546,7 @@ function _breakExpression() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getSymbolAtAddress(a) {
|
function getSymbolAtAddress(a : number) {
|
||||||
if (addr2symbol[a]) return addr2symbol[a];
|
if (addr2symbol[a]) return addr2symbol[a];
|
||||||
var i=0;
|
var i=0;
|
||||||
while (--a >= 0) {
|
while (--a >= 0) {
|
||||||
@ -607,7 +608,7 @@ function _recordVideo() {
|
|||||||
f();
|
f();
|
||||||
}
|
}
|
||||||
|
|
||||||
function setFrameRateUI(fps) {
|
function setFrameRateUI(fps:number) {
|
||||||
platform.setFrameRate(fps);
|
platform.setFrameRate(fps);
|
||||||
if (fps > 0.01)
|
if (fps > 0.01)
|
||||||
$("#fps_label").text(fps.toFixed(2));
|
$("#fps_label").text(fps.toFixed(2));
|
||||||
@ -859,7 +860,7 @@ function startPlatform() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadSharedFile(sharekey) {
|
function loadSharedFile(sharekey : string) {
|
||||||
var github = new Octokat();
|
var github = new Octokat();
|
||||||
var gist = github.gists(sharekey);
|
var gist = github.gists(sharekey);
|
||||||
gist.fetch().done(function(val) {
|
gist.fetch().done(function(val) {
|
||||||
@ -881,7 +882,7 @@ function loadSharedFile(sharekey) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// start
|
// start
|
||||||
function startUI(loadplatform) {
|
function startUI(loadplatform : boolean) {
|
||||||
installErrorHandler();
|
installErrorHandler();
|
||||||
// add default platform?
|
// add default platform?
|
||||||
platform_id = qs['platform'] || localStorage.getItem("__lastplatform");
|
platform_id = qs['platform'] || localStorage.getItem("__lastplatform");
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
import $ = require("jquery");
|
import $ = require("jquery");
|
||||||
import { SourceFile, WorkerError, CodeProject } from "./project";
|
import { CodeProject } from "./project";
|
||||||
|
import { SourceFile, WorkerError } from "./workertypes";
|
||||||
import { Platform } from "./baseplatform";
|
import { Platform } from "./baseplatform";
|
||||||
|
|
||||||
export interface ProjectView {
|
export interface ProjectView {
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
import $ = require("jquery");
|
import $ = require("jquery");
|
||||||
import { WorkerError, CodeProject } from "./project";
|
import { CodeProject } from "./project";
|
||||||
|
import { WorkerError } from "./workertypes";
|
||||||
import { ProjectView } from "./views";
|
import { ProjectView } from "./views";
|
||||||
|
|
||||||
type WindowCreateFunction = (id:string) => ProjectView;
|
type WindowCreateFunction = (id:string) => ProjectView;
|
||||||
|
86
src/workertypes.ts
Normal file
86
src/workertypes.ts
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
|
||||||
|
export type FileData = string | Uint8Array;
|
||||||
|
|
||||||
|
export interface SourceLine {
|
||||||
|
offset:number;
|
||||||
|
line:number;
|
||||||
|
insns?:string;
|
||||||
|
iscode?:boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class SourceFile {
|
||||||
|
lines: SourceLine[];
|
||||||
|
text: string;
|
||||||
|
offset2line: {[offset:number]:number};
|
||||||
|
line2offset: {[line:number]:number};
|
||||||
|
|
||||||
|
constructor(lines:SourceLine[], text?:string) {
|
||||||
|
lines = lines || [];
|
||||||
|
this.lines = lines;
|
||||||
|
this.text = text;
|
||||||
|
this.offset2line = {};
|
||||||
|
this.line2offset = {};
|
||||||
|
for (var info of lines) {
|
||||||
|
if (info.offset >= 0) {
|
||||||
|
this.offset2line[info.offset] = info.line;
|
||||||
|
this.line2offset[info.line] = info.offset;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
findLineForOffset(PC:number):number {
|
||||||
|
if (this.offset2line) {
|
||||||
|
for (var i=0; i<16; i++) {
|
||||||
|
var line = this.offset2line[PC];
|
||||||
|
if (line >= 0) {
|
||||||
|
return line;
|
||||||
|
}
|
||||||
|
PC--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
lineCount():number { return this.lines.length; }
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Dependency {
|
||||||
|
path:string,
|
||||||
|
filename:string,
|
||||||
|
data:FileData // TODO: or binary?
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface WorkerFileUpdate { path:string, data:FileData };
|
||||||
|
export interface WorkerBuildStep { path:string, platform:string, tool:string, mainfile?:boolean };
|
||||||
|
|
||||||
|
export interface WorkerMessage {
|
||||||
|
updates:WorkerFileUpdate[],
|
||||||
|
buildsteps:WorkerBuildStep[]
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface WorkerError {
|
||||||
|
line:number,
|
||||||
|
msg:string,
|
||||||
|
path?:string
|
||||||
|
//TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface CodeListing {
|
||||||
|
lines:SourceLine[],
|
||||||
|
asmlines:SourceLine[],
|
||||||
|
text:string,
|
||||||
|
sourcefile?:SourceFile,
|
||||||
|
assemblyfile?:SourceFile
|
||||||
|
}
|
||||||
|
|
||||||
|
export type CodeListingMap = {[path:string]:CodeListing};
|
||||||
|
|
||||||
|
// TODO
|
||||||
|
export type WorkerOutput = Uint8Array |
|
||||||
|
{program_rom_variable:string, program_rom:Uint8Array, code:{}, name:string, ports:any[], signals:any[]};
|
||||||
|
|
||||||
|
export interface WorkerResult {
|
||||||
|
output:WorkerOutput,
|
||||||
|
errors:WorkerError[],
|
||||||
|
listings:CodeListingMap,
|
||||||
|
symbolmap:{[sym:string]:number},
|
||||||
|
params:{},
|
||||||
|
}
|
@ -48,6 +48,7 @@ includeInThisContext("localForage/dist/localforage.js");
|
|||||||
includeInThisContext("gen/util.js");
|
includeInThisContext("gen/util.js");
|
||||||
includeInThisContext("src/store.js");
|
includeInThisContext("src/store.js");
|
||||||
var prj = require("../../gen/project.js");
|
var prj = require("../../gen/project.js");
|
||||||
|
var prj = require("../../gen/workertypes.js");
|
||||||
|
|
||||||
var test_platform_id = "_TEST";
|
var test_platform_id = "_TEST";
|
||||||
|
|
||||||
|
@ -36,6 +36,7 @@ function doBuild(msgs, callback, outlen, nlines, nerrors) {
|
|||||||
} else {
|
} else {
|
||||||
assert.equal(nerrors||0, 0, "errors");
|
assert.equal(nerrors||0, 0, "errors");
|
||||||
assert.equal(msg.output.code?msg.output.code.length:msg.output.length, outlen, "output binary");
|
assert.equal(msg.output.code?msg.output.code.length:msg.output.length, outlen, "output binary");
|
||||||
|
assert.ok(msg.output.code || msg.output instanceof Uint8Array);
|
||||||
if (nlines) {
|
if (nlines) {
|
||||||
if (typeof nlines === 'number')
|
if (typeof nlines === 'number')
|
||||||
nlines = [nlines];
|
nlines = [nlines];
|
||||||
|
@ -9,7 +9,8 @@
|
|||||||
"dom"
|
"dom"
|
||||||
],
|
],
|
||||||
"noImplicitThis": false,
|
"noImplicitThis": false,
|
||||||
"noImplicitAny": false
|
"noImplicitAny": false,
|
||||||
|
"alwaysStrict": true
|
||||||
},
|
},
|
||||||
"include": [
|
"include": [
|
||||||
"./src/*.ts",
|
"./src/*.ts",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user