Merge branch 'master' into c64book

This commit is contained in:
Steven Hugg 2022-08-02 17:24:21 -05:00
commit fa815fc9b7
5 changed files with 68 additions and 32 deletions

View File

@ -89,6 +89,7 @@ if (window.location.host.endsWith('8bitworkshop.com')) {
<li><a class="dropdown-item" href="#" id="item_download_rom">Download ROM Image</a></li>
<li><a class="dropdown-item" href="#" id="item_download_zip">Download Project as ZIP</a></li>
<li><a class="dropdown-item" href="#" id="item_download_allzip">Download All Changes as ZIP</a></li>
<li><a class="dropdown-item" href="#" id="item_download_sym">Download Debug Symbols</a></li>
</ul>
</li>
<li class="dropdown dropdown-submenu">

View File

@ -151,6 +151,7 @@ export interface Platform {
sourceFileFetch?: (path:string) => FileData;
getDownloadFile?() : {extension:string, blob:Blob};
getDebugSymbolFile?() : {extension:string, blob:Blob};
}
export interface Preset {

View File

@ -1141,6 +1141,16 @@ async function _downloadProjectZipFile(e) {
});
}
function _downloadSymFile(e) {
let symfile = platform.getDebugSymbolFile && platform.getDebugSymbolFile();
if (!symfile) {
alertError("This project does not have debug information.");
return;
}
var prefix = getFilenamePrefix(getCurrentMainFilename());
saveAs(symfile.blob, prefix + symfile.extension, {autoBom:false});
}
async function _downloadAllFilesZipFile(e) {
var zip = await newJSZip();
var keys = await store.keys();
@ -1907,6 +1917,7 @@ function setupDebugControls() {
$("#item_download_rom").click(_downloadROMImage);
$("#item_download_file").click(_downloadSourceFile);
$("#item_download_zip").click(_downloadProjectZipFile);
$("#item_download_sym").click(_downloadSymFile);
$("#item_download_allzip").click(_downloadAllFilesZipFile);
$("#item_record_video").click(_recordVideo);
if (platform_id.startsWith('apple2') || platform_id.startsWith('vcs')) // TODO: look for function

View File

@ -486,6 +486,37 @@ class JSNESPlatform extends Base6502Platform implements Platform, Probeable {
showHelp(tool:string, ident:string) {
window.open("https://8bitworkshop.com/docs/platforms/nes/", "_help"); // TODO
}
getDebugSymbolFile() {
var sym = this.debugSymbols.addr2symbol;
var text = "";
$.each(sym, function(k, v) {
let symType;
if (k < 0x2000) {
k = k % 0x800;
symType = "R";
} else if (k < 0x6000) symType = "G";
else if (k < 0x8000) {
k = k - 0x6000;
symType = "S";
} else {
k = k - 0x8000;
symType = "P";
}
let addr = Number(k).toString(16).padStart(4, '0').toUpperCase();
// Mesen doesn't allow lables to start with digits
if (v[0] >= '0' && v[0] <= '9') {
v = "L" + v;
}
// nor does it allow dots
v = (v as any).replaceAll('.', '_');
text += `${symType}:${addr}:${v}\n`;
});
return {
extension:".mlb",
blob: new Blob([text], {type:"text/plain"})
};
}
}
/// MAME support
@ -522,6 +553,7 @@ class NESMAMEPlatform extends BaseMAME6502Platform implements Platform {
getToolForFilename = getToolForFilename_6502;
getOpcodeMetadata = getOpcodeMetadata_6502;
getDefaultExtension() { return ".c"; };
}
///

View File

@ -18,7 +18,7 @@ import { EmscriptenModule } from "../workermain"
00B726 1 xx xx IBSECSZ: .res 2
00BA2F 1 2A 2B E8 2C HEX "2A2BE82C2D2E2F303132F0F133343536"
*/
function parseCA65Listing(code: string, symbols, params, dbg: boolean, listings?: CodeListingMap) {
function parseCA65Listing(code: string, symbols, segments, params, dbg: boolean, listings?: CodeListingMap) {
var segofs = 0;
var offset = 0;
var dbgLineMatch = /^([0-9A-F]+)([r]?)\s+(\d+)\s+[.]dbg\s+(\w+), "([^"]+)", (.+)/;
@ -62,17 +62,14 @@ function parseCA65Listing(code: string, symbols, params, dbg: boolean, listings?
insns: null
});
}
linenum++;
var linem = insnLineMatch.exec(line);
var topfile = linem && linem[3] == '1';
if (topfile) linenum++;
if (topfile && linem[1]) {
var offset = parseInt(linem[1], 16);
var insns = linem[4].trim();
if (insns.length) {
// take back one to honor the long .byte line
if (linem[5].length == 0) {
linenum--;
} else if (!dbg) {
if (!dbg) {
lines.push({
path: curpath,
line: linenum,
@ -83,14 +80,7 @@ function parseCA65Listing(code: string, symbols, params, dbg: boolean, listings?
}
} else {
var sym = linem[5];
var segm = sym && segMatch.exec(sym);
if (segm && segm[1]) {
var symofs = symbols['__' + segm[1] + '_RUN__'];
if (typeof symofs === 'number') {
segofs = symofs;
//console.log(sym, segofs, symofs, '-', offset);
}
} else if (sym.endsWith(':') && !sym.startsWith('@')) {
if (sym.endsWith(':') && !sym.startsWith('@')) {
var symofs = symbols[sym.substring(0, sym.length - 1)];
if (typeof symofs === 'number') {
segofs = symofs - offset;
@ -175,7 +165,8 @@ export function linkLD65(step: BuildStep): BuildStepResult {
'-C', cfgfile,
'-Ln', 'main.vice',
//'--dbgfile', 'main.dbg', // TODO: get proper line numbers
'-o', 'main', '-m', 'main.map'].concat(step.args, libargs);
'-o', 'main',
'-m', 'main.map'].concat(step.args, libargs);
//console.log(args);
execMain(step, LD65, args);
if (errors.length)
@ -202,27 +193,27 @@ export function linkLD65(step: BuildStep): BuildStepResult {
}
}
}
// build segment map
var seg_re = /^__(\w+)_SIZE__$/;
// TODO: move to Platform class
var segments = [];
segments.push({ name: 'CPU Stack', start: 0x100, size: 0x100, type: 'ram' });
segments.push({ name: 'CPU Vectors', start: 0xfffa, size: 0x6, type: 'rom' });
// TODO: CHR, banks, etc
for (let ident in symbolmap) {
let m = seg_re.exec(ident);
if (m) {
let re_seglist = /(\w+)\s+([0-9A-F]+)\s+([0-9A-F]+)\s+([0-9A-F]+)\s+([0-9A-F]+)/;
let parseseglist = false;
let m;
for (let s of mapout.split('\n')) {
if (parseseglist && (m = re_seglist.exec(s))) {
let seg = m[1];
let segstart = symbolmap['__' + seg + '_RUN__'] || symbolmap['__' + seg + '_START__'];
let segsize = symbolmap['__' + seg + '_SIZE__'];
let seglast = symbolmap['__' + seg + '_LAST__'];
if (segstart >= 0 && segsize > 0 && !seg.startsWith('PRG') && seg != 'RAM') { // TODO
var type = null;
if (seg.startsWith('CODE') || seg == 'STARTUP' || seg == 'RODATA' || seg.endsWith('ROM')) type = 'rom';
else if (seg == 'ZP' || seg == 'DATA' || seg == 'BSS' || seg.endsWith('RAM')) type = 'ram';
segments.push({ name: seg, start: segstart, size: segsize, last: seglast, type: type });
}
let start = parseInt(m[2], 16);
let size = parseInt(m[4], 16);
let type = '';
// TODO: better id of ram/rom
if (seg.startsWith('CODE') || seg == 'STARTUP' || seg == 'RODATA' || seg.endsWith('ROM')) type = 'rom';
else if (seg == 'ZP' || seg == 'DATA' || seg == 'BSS' || seg.endsWith('RAM')) type = 'ram';
segments.push({ name: seg, start, size, type });
}
if (s == 'Segment list:') parseseglist = true;
if (s == '') parseseglist = false;
}
// build listings
var listings: CodeListingMap = {};
@ -235,14 +226,14 @@ export function linkLD65(step: BuildStep): BuildStepResult {
let isECS = step.debuginfo?.entities != null; // TODO
if (isECS) {
var asmlines = [];
var srclines = parseCA65Listing(lstout, symbolmap, params, true, listings);
var srclines = parseCA65Listing(lstout, symbolmap, segments, params, true, listings);
listings[fn] = {
lines: [],
text: lstout
}
} else {
var asmlines = parseCA65Listing(lstout, symbolmap, params, false);
var srclines = parseCA65Listing(lstout, symbolmap, params, true); // TODO: listings param for ecs
var asmlines = parseCA65Listing(lstout, symbolmap, segments, params, false);
var srclines = parseCA65Listing(lstout, symbolmap, segments, params, true); // TODO: listings param for ecs
listings[fn] = {
asmlines: srclines.length ? asmlines : null,
lines: srclines.length ? srclines : asmlines,