diff --git a/css/ui.css b/css/ui.css index ee1bdab7..6426f5d1 100644 --- a/css/ui.css +++ b/css/ui.css @@ -431,3 +431,20 @@ div.markdown th { height:100%; overflow-y:auto; } +div.profiler { + background-color: #333; + color: #ddd; + white-space: pre; + margin-top: 20px auto 0; + font-family: "Andale Mono", "Menlo", "Lucida Console", monospace; + font-size: 10pt; +} +span.profiler-lineno { + color: #fff; +} +span.profiler-local { + color: #999; +} +span.profiler-cident { + color: #99ffff; +} diff --git a/index.html b/index.html index 67cfcacc..c7167cda 100644 --- a/index.html +++ b/index.html @@ -82,8 +82,9 @@ if (window.location.host.endsWith('8bitworkshop.com')) { @@ -178,7 +179,7 @@ if (window.location.host.endsWith('8bitworkshop.com')) { - +   @@ -292,6 +293,31 @@ if (window.location.host.endsWith('8bitworkshop.com')) { + diff --git a/presets/nes/bcd.c b/presets/nes/bcd.c index 80bfd79f..1156361d 100644 --- a/presets/nes/bcd.c +++ b/presets/nes/bcd.c @@ -9,7 +9,7 @@ word bcd_add(word a, word b) { byte d = (a & 0xf) + (b & 0xf) + c; c = 0; while (d >= 10) { - c++; + ++c; d -= 10; } result |= d << shift; diff --git a/presets/nes/vrambuf.c b/presets/nes/vrambuf.c index 12d3fa0c..78d1eee6 100644 --- a/presets/nes/vrambuf.c +++ b/presets/nes/vrambuf.c @@ -2,9 +2,15 @@ #include "neslib.h" #include "vrambuf.h" +#pragma bss-name(push,"ZEROPAGE") +#pragma data-name(push,"ZEROPAGE") + // index to end of buffer byte updptr = 0; +#pragma bss-name(pop) +#pragma data-name(pop) + // add EOF marker to buffer void cendbuf(void) { updbuf[updptr] = NT_UPD_EOF; @@ -30,11 +36,12 @@ void cflushnow(void) { // using horizontal increment void putbytes(word addr, const char* str, byte len) { if (updptr >= VBUFSIZE-4-len) cflushnow(); - updbuf[updptr++] = (addr >> 8) ^ NT_UPD_HORZ; - updbuf[updptr++] = addr & 0xff; - updbuf[updptr++] = len; + updbuf[updptr] = (addr >> 8) ^ NT_UPD_HORZ; + updbuf[++updptr] = addr & 0xff; + updbuf[++updptr] = len; while (len--) { - updbuf[updptr++] = *str++; + updbuf[++updptr] = *str++; } + ++updptr; cendbuf(); } diff --git a/src/baseplatform.ts b/src/baseplatform.ts index 6afd51e1..ea61c79a 100644 --- a/src/baseplatform.ts +++ b/src/baseplatform.ts @@ -157,6 +157,31 @@ export abstract class BasePlatform { this.recorder.recordFrame(this.saveState()); } } + startProfiling() : ProfilerOutput { + var frame = null; + var output = {frame:null}; + var i = 0; + var lastsl = 9999; + var start = 0; + (this as any).runEval((c:CpuState) => { + var sl = (this as any).getRasterScanline(); + if (sl != lastsl) { + if (frame) { + frame.lines.push({start:start,end:i-1}); + } + if (sl < lastsl) { + output.frame = frame; + frame = {iptab:new Uint32Array(0x8000), lines:[]}; // TODO: const + i = 0; + } + start = i; + lastsl = sl; + } + frame.iptab[i++] = c.EPC || c.PC; + return false; // profile forever + }); + return output; + } } export abstract class BaseDebugPlatform extends BasePlatform { @@ -208,29 +233,6 @@ export abstract class BaseDebugPlatform extends BasePlatform { this.advance(novideo); this.postFrame(); } - startProfiling() : ProfilerOutput { - var frame = null; - var output = {frame:null}; - var i = 0; - var lastsl = 9999; - var start = 0; - (this as any).runEval((c:CpuState) => { - var sl = (this as any).getRasterScanline(); - if (sl != lastsl) { - if (frame) frame.lines.push({start:start,end:i}); - if (sl < lastsl) { - output.frame = frame; - frame = {iptab:new Uint32Array(14672), lines:[]}; - i = 0; - } - start = i+1; - lastsl = sl; - } - frame.iptab[i++] = c.EPC || c.PC; - return false; // profile forever - }); - return output; - } } ////// 6502 @@ -1028,6 +1030,7 @@ export abstract class BasicZ80ScanlinePlatform extends BaseZ80Platform { abstract getKeyboardMap(); abstract startScanline(sl : number); abstract drawScanline(sl : number); + getRasterScanline() { return this.currentScanline; } constructor(mainElement : HTMLElement) { super(); diff --git a/src/platform/nes.ts b/src/platform/nes.ts index 03fc7681..3714e4a6 100644 --- a/src/platform/nes.ts +++ b/src/platform/nes.ts @@ -231,30 +231,6 @@ const _JSNESPlatform = function(mainElement) { getRasterScanline() : number { return nes.ppu.scanline; } - startProfiling() : ProfilerOutput { - var frame0 = frameindex; - var frame = null; - var output = {frame:null}; - var i = 0; - var lastsl = 9999; - var start = 0; - this.runEval((c) => { - var sl = this.getRasterScanline(); - if (sl != lastsl) { - if (frame) frame.lines.push({start:start,end:i}); - if (sl < lastsl) { - output.frame = frame; - frame = {iptab:new Uint32Array(14672), lines:[]}; - i = 0; - } - start = i+1; - lastsl = sl; - } - frame.iptab[i++] = c.EPC || c.PC; - return false; //frameindex>frame0; // TODO - }); - return output; - } getCPUState() { var c = nes.cpu.toJSON(); diff --git a/src/platform/vcs.ts b/src/platform/vcs.ts index bcac76cd..ff5e1f33 100644 --- a/src/platform/vcs.ts +++ b/src/platform/vcs.ts @@ -153,6 +153,7 @@ class VCSPlatform extends BasePlatform { Javatari.room.speaker.mute(); } isDebugging() : boolean { + // TODO: always true return Javatari.room.console.onBreakpointHit != null; } clearDebug() { diff --git a/src/ui.ts b/src/ui.ts index 68cb2a9d..1e2c4348 100644 --- a/src/ui.ts +++ b/src/ui.ts @@ -354,28 +354,24 @@ function getCurrentEditorFilename() : string { } function _shareFileAsGist(e) { - loadScript("octokat.js/dist/octokat.js", () => { - if (current_output == null) { // TODO - alert("Please fix errors before sharing."); - return true; - } - var text = projectWindows.getCurrentText(); - if (!text) return false; - var github = new exports['Octokat'](); - var files = {}; - files[getCurrentEditorFilename()] = {"content": text}; - var gistdata = { - "description": '8bitworkshop.com {"platform":"' + platform_id + '"}', - "public": true, - "files": files - }; - var gist = github.gists.create(gistdata).done(function(val) { - var url = "http://8bitworkshop.com/?gistkey=" + val.id; - window.prompt("Copy link to clipboard (Ctrl+C, Enter)", url); - }).fail(function(err) { - alert("Error sharing file: " + err.message); + var gisturl_ta = $("#embedGistURL"); + var shareurl_ta = $("#embedGistShareURL"); + loadClipboardLibrary(); + gisturl_ta.change(() => { + var gisturl = gisturl_ta.val() + ''; + var pos = gisturl.lastIndexOf('/'); + if (pos >= 0) { + var gistkey = gisturl.substring(pos+1); + var embed = { + platform: platform_id, + gistkey: gistkey + }; + var linkqs = $.param(embed); + var fulllink = get8bitworkshopLink(linkqs, 'redir.html'); + shareurl_ta.val(fulllink); + } }); - }); + $("#embedGistModal").modal('show'); } function _shareEmbedLink(e) { @@ -387,10 +383,7 @@ function _shareEmbedLink(e) { 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"); - }); + loadClipboardLibrary(); loadScript('lib/liblzg.js', () => { // TODO: Module is bad var name (conflicts with MAME) var lzgrom = compressLZG( window['Module'], Array.from(current_output) ); @@ -402,11 +395,7 @@ function _shareEmbedLink(e) { r: lzgb64 }; var linkqs = $.param(embed); - console.log(linkqs); - var loc = window.location; - var prefix = loc.pathname.replace('index.html',''); - var protocol = (loc.host == '8bitworkshop.com') ? 'https:' : loc.protocol; - var fulllink = protocol+'//'+loc.host+prefix+'embed.html?' + linkqs; + var fulllink = get8bitworkshopLink(linkqs, 'embed.html'); var iframelink = '