1
0
mirror of https://github.com/sehugg/8bitworkshop.git synced 2024-11-25 18:33:11 +00:00

made WorkerOutput/VerilogOutput type more specific; FILE__filename_ext define for mcpp

This commit is contained in:
Steven Hugg 2018-11-22 12:28:50 -05:00
parent 43e33f143c
commit 6e50cbb20e
3 changed files with 21 additions and 10 deletions

View File

@ -5,7 +5,7 @@
import $ = require("jquery");
import * as bootstrap from "bootstrap";
import { CodeProject } from "./project";
import { WorkerResult, SourceFile, WorkerError } from "./workertypes";
import { WorkerResult, WorkerOutput, VerilogOutput, SourceFile, WorkerError } from "./workertypes";
import { ProjectWindows } from "./windows";
import { Platform, Preset, DebugSymbols } from "./baseplatform";
import { PLATFORMS } from "./emu";
@ -57,7 +57,7 @@ function newWorker() : Worker {
var userPaused : boolean; // did user explicitly pause?
var current_output; // current ROM
var current_output : WorkerOutput; // current ROM
var current_preset_entry : Preset; // current preset object (if selected)
var main_file_id : string; // main file ID
var store; // persistent store
@ -324,13 +324,17 @@ function _shareEmbedLink(e) {
alert("Please fix errors before sharing.");
return true;
}
if (!(current_output instanceof Uint8Array)) {
alert("Can't share a Verilog executable yet. (It's not actually a ROM...)");
return true;
}
loadScript('lib/clipboard.min.js', () => {
var ClipboardJS = exports['ClipboardJS'];
new ClipboardJS(".btn");
});
loadScript('lib/liblzg.js', () => {
// TODO: Module is bad var name (conflicts with MAME)
var lzgrom = compressLZG( window['Module'], current_output );
var lzgrom = compressLZG( window['Module'], Array.from(<Uint8Array>current_output) );
window['Module'] = null; // so we load it again next time
var lzgb64 = btoa(byteArrayToString(lzgrom));
var embed = {
@ -415,12 +419,12 @@ function _downloadROMImage(e) {
alert("Please finish compiling with no errors before downloading ROM.");
return true;
}
if (current_output.code) { // TODO
var blob = new Blob([current_output.code], {type: "text/plain"});
saveAs(blob, getCurrentMainFilename()+".js");
} else {
if (current_output instanceof Uint8Array) {
var blob = new Blob([current_output], {type: "application/octet-stream"});
saveAs(blob, getCurrentMainFilename()+".rom");
} else {
var blob = new Blob([(<VerilogOutput>current_output).code], {type: "text/plain"});
saveAs(blob, getCurrentMainFilename()+".js");
}
}

View File

@ -1162,6 +1162,10 @@ function compileSDCC(step:BuildStep) {
};
}
function makeCPPSafe(s:string) : string {
return s.replace(/[^A-Za-z0-9_]/g,'_');
}
function preprocessMCPP(step:BuildStep) {
load("mcpp");
var platform = step.platform;
@ -1182,8 +1186,9 @@ function preprocessMCPP(step:BuildStep) {
// TODO: make configurable by other compilers
var args = [
"-D", "__8BITWORKSHOP__",
"-D", platform.toUpperCase().replace(/[-.]/g,'_'),
"-D", "__SDCC_z80",
"-D", makeCPPSafe(platform.toUpperCase()),
"-D", "FILE__" + makeCPPSafe(step.path+""),
"-I", "/share/include",
"-Q",
step.path, "main.i"];

View File

@ -83,8 +83,10 @@ export interface CodeListing {
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 type VerilogOutput =
{program_rom_variable:string, program_rom:Uint8Array, code:string, name:string, ports:any[], signals:any[]};
export type WorkerOutput = Uint8Array | VerilogOutput;
export interface WorkerResult {
output:WorkerOutput,