verilog: support $readmemb/h("file", array)

This commit is contained in:
Steven Hugg 2019-05-01 23:33:49 -04:00
parent 8152a14a2b
commit 2aa818e320
5 changed files with 37 additions and 11 deletions

View File

@ -54,8 +54,7 @@ TODO:
- C/asm formatter
- fix WebAudio (https://news.ycombinator.com/item?id=18066474)
- allow download of JSASM output
- update bootstrap
- $readmemb/h
- update bootstrap to 4.0
- batariBasic: proper line numbers, debugging
- granular control over time scrubbing, show CPU state
- error showing replay div before rom starts
@ -75,7 +74,6 @@ TODO:
- markdown, verilog: can't share
- https://www.crowdsupply.com/tinyfpga/tinyfpga-bx
- HTTPS warning
- recording video indicator
- stego shareable images (http://pico-8.wikia.com/wiki/P8PNGFileFormat)
- https://makecode.com/language?
- open ROM from URL?
@ -115,15 +113,15 @@ TODO:
- https://remotestoragejs.readthedocs.io/en/latest/getting-started/how-to-add.html ?
- Verilog
- larger scope range, better scrolling
- make scope data wrap around range
- remove FPS and play controls when Verilog scope paused
- when paused scope doesn't work
- Safari: scope doesn't show while CRT in use
- Safari: scope doesn't show while CRT in use (sometimes Firefox too)
- verilog debugging/reloading makes it slow
- why loadState() on verilog kill perf?
- quantify verilog "graph iterations"
- toolbar overlaps scope
- toolbar overlaps scope
- CPU debugging
- disassemble more code around breakpoint
- single-stepping vector games makes screen fade
- break on stack overflow, bad op, bad access, etc
- PPU/TIA register write visualization

View File

@ -120,7 +120,11 @@ export function vl_stop(filename,lineno,hier) {
export function VL_RAND_RESET_I(bits) { return 0 | Math.floor(Math.random() * (1<<bits)); }
export function VL_RANDOM_I(bits) { return 0 | Math.floor(Math.random() * (1<<bits)); }
//export function VL_READMEM_Q(hex,width,depth,array_lsb,fnwords,filename,memp,start,end) {
//console.log(hex,width,depth,array_lsb,fnwords,filename,memp,start,end);
//}
// SIMULATOR BASE
abstract class VerilatorBase {

View File

@ -87,9 +87,9 @@ export class CodeProject {
this.pushAllFiles(files, m[2]+".json");
}
// include $readmem[bh] (TODO)
let re3 = /\b\$readmem[bh]\("(.+?)"/gmi;
let re3 = /\$readmem[bh]\("(.+?)"/gmi;
while (m = re3.exec(text)) {
this.pushAllFiles(files, m[2]);
this.pushAllFiles(files, m[1]);
}
} else {
// for .asm -- [.]include "file"

View File

@ -1530,6 +1530,28 @@ function compileInlineASM(code:string, platform, options, errors, asmlines) {
return code;
}
// convert $readmem(bh) to array assigns
function compileReadmemStmts(code, errors) {
var re3 = /\$readmem([bh])\("(.+?)",\s*(\w+)\)/gmi;
return code.replace(re3, function(_s,type,path,mem,index) {
var datafile = getWorkFileAsString(path);
if (datafile) {
var lines = datafile.split('\n');
var out = '';
for (var i=0; i<lines.length; i++) {
var line = lines[i].trim();
if (line !== '') {
out += 'mem[' + i + ']=\'' + type + line + ';'
}
}
return out;
} else {
errors.push({line:0, msg:"Could not load $readmem file '"+path+'"'});
return "";
}
});
}
function compileVerilator(step:BuildStep) {
loadNative("verilator_bin");
loadGen("worker/verilator2js");
@ -1554,7 +1576,9 @@ function compileVerilator(step:BuildStep) {
populateFiles(step, FS, {
mainFilePath:step.path,
processFn:(code) => {
return compileInlineASM(code, platform, step, errors, asmlines);
code = compileReadmemStmts(code, errors);
code = compileInlineASM(code, platform, step, errors, asmlines);
return code;
}
});
starttime();

View File

@ -120,6 +120,6 @@ describe('string functions', function() {
assert.ok(util.isProbablyBinary('test.bin'));
assert.ok(util.isProbablyBinary('test.chr'));
assert.ok(!util.isProbablyBinary('test.txt'));
assert.ok(!util.isProbablyBinary('test.dat'));
assert.ok(util.isProbablyBinary('test.dat'));
});
});