diff --git a/src/ui.ts b/src/ui.ts index afba7ad2..0b8d39f4 100644 --- a/src/ui.ts +++ b/src/ui.ts @@ -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(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([(current_output).code], {type: "text/plain"}); + saveAs(blob, getCurrentMainFilename()+".js"); } } diff --git a/src/worker/workermain.ts b/src/worker/workermain.ts index 44e41475..948495b5 100644 --- a/src/worker/workermain.ts +++ b/src/worker/workermain.ts @@ -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"]; diff --git a/src/workertypes.ts b/src/workertypes.ts index 8fb8f113..06a6d771 100644 --- a/src/workertypes.ts +++ b/src/workertypes.ts @@ -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,