started on verilog scope, fixed code change, module top detect

This commit is contained in:
Steven Hugg 2017-11-14 09:33:15 -05:00
parent 0ca9f43098
commit b19ebe76df
7 changed files with 93 additions and 30 deletions

BIN
css/04B_03__.TTF Normal file

Binary file not shown.

View File

@ -222,3 +222,7 @@ canvas.pixelated {
#javatari-screen div {
box-sizing: content-box;
}
@font-face {
font-family: TinyFont;
src: url(04B_03__.TTF);
}

View File

@ -65,9 +65,9 @@ var RasterVideo = function(mainElement, width, height, options) {
};
};
this.getFrameData = function() {
return datau32;
}
this.getFrameData = function() { return datau32; }
this.getContext = function() { return ctx; }
this.updateFrame = function(sx, sy, dx, dy, width, height) {
//imageData.data.set(buf8); // TODO: slow w/ partial updates

View File

@ -77,6 +77,7 @@ var VerilogPlatform = function(mainElement, options) {
var gen;
var frameRate = 60;
var AUDIO_FREQ = 15700;
var current_output;
this.getPresets = function() { return VERILOG_PRESETS; }
@ -96,6 +97,65 @@ var VerilogPlatform = function(mainElement, options) {
0xffffffff,
];
function updateVideoFrame() {
var i=0;
for (var y=0; y<videoHeight; y++) {
for (var x=0; x<videoWidth; x++) {
tick2();
idata[i++] = RGBLOOKUP[gen.rgb];
}
var z=0;
while (gen.hsync && z++<videoWidth) tick2();
while (!gen.hsync && z++<videoWidth) tick2();
}
var z=0;
while (gen.vsync && z++<videoWidth*80) tick2();
while (!gen.vsync && z++<videoWidth*80) tick2();
video.updateFrame();
}
var yposlist = [];
function updateScopeFrame() {
var arr = current_output.ports;
if (!arr) return;
for (var i=0; i<idata.length; i++) {
if (idata[i])
idata[i] = 0; //<<= 1;
}
var COLOR_SIGNAL = 0xff11ff11;
var COLOR_BORDER = 0xff661111;
for (var x=0; x<videoWidth; x++) {
gen.clk ^= 1;
gen.eval();
var yb = 8;
var y1 = 0;
for (var i=0; i<arr.length; i++) {
var v = arr[i];
var lo = 0; // TODO? v.ofs?
var hi = v.len ? ((2 << v.len)-1) : 1;
var ys = hi>1 ? v.len*2+8 : 8;
var y2 = y1+ys;
var z = gen[v.name];
var y = y2 - ys*((z-lo)/hi);
yposlist[i] = y2;
//idata[x + y1*videoWidth] = COLOR_BORDER;
//idata[x + y2*videoWidth] = COLOR_BORDER;
idata[x + Math.round(y)*videoWidth] = COLOR_SIGNAL;
y1 += ys+yb;
}
}
video.updateFrame();
// draw labels
var ctx = video.getContext();
ctx.font = "8px TinyFont";
ctx.fillStyle = "white";
for (var i=0; i<arr.length; i++) {
var v = arr[i];
ctx.fillText(v.name, 1, yposlist[i]);
}
}
this.start = function() {
// TODO
video = new RasterVideo(mainElement,videoWidth,videoHeight);
@ -106,30 +166,21 @@ var VerilogPlatform = function(mainElement, options) {
timer = new AnimationTimer(frameRate, function() {
if (!self.isRunning())
return;
var i=0;
for (var y=0; y<videoHeight; y++) {
for (var x=0; x<videoWidth; x++) {
tick2();
idata[i++] = RGBLOOKUP[gen.rgb];
}
var z=0;
while (gen.hsync && z++<videoWidth) tick2();
while (!gen.hsync && z++<videoWidth) tick2();
}
var z=0;
while (gen.vsync && z++<videoWidth*80) tick2();
while (!gen.vsync && z++<videoWidth*80) tick2();
video.updateFrame();
if (gen.vsync !== undefined && gen.hsync !== undefined && gen.rgb !== undefined)
updateVideoFrame();
else
updateScopeFrame();
});
}
this.loadROM = function(title, modtext) {
//console.log(modtext);
var mod = new Function('base', modtext);
this.loadROM = function(title, output) {
var mod = new Function('base', output.code);
var base = new VerilatorBase();
gen = new mod(base);
gen.__proto__ = base;
console.log(gen);
output.code = null;
output.ports_signals = output.ports.concat(output.signals);
current_output = output;
this.reset();
}

View File

@ -457,7 +457,7 @@ function setCompileOutput(data) {
} else {
// load ROM
var rom = data.output;
var rom_changed = rom && !arrayCompare(rom, current_output);
var rom_changed = rom && !arrayCompare(rom.code||rom, current_output);
if (rom_changed) {
try {
//console.log("Loading ROM length", rom.length);

View File

@ -84,15 +84,17 @@ function translateVerilatorOutputToJS(htext, cpptext) {
}
return {
output:buildModule({
output:{
code:buildModule({
name:moduleName,
ports:ports,
signals:signals,
funcs:funcs,
}),
name:moduleName,
ports:ports,
signals:signals,
funcs:funcs,
}),
name:moduleName,
ports:ports,
signals:signals,
}
};
}

View File

@ -1031,6 +1031,11 @@ function assembleNAKEN(code, platform) {
}
}
function detectModuleName(code) {
var m = /\bmodule\s+(\w+_top)/.exec(code) || /\bmodule\s+(\w+)/.exec(code);
return m ? m[1] : null;
}
function compileVerilator(code, platform) {
loadWASM("verilator_bin");
load("verilator2js");
@ -1042,10 +1047,11 @@ function compileVerilator(code, platform) {
print:print_fn,
printErr:match_fn,
});
// detect module_top name
var topmod = "top";
var topmod = detectModuleName(code) || "top";
var m = /\bmodule\s+(\w+?_top)/.exec(code);
if (m && m[1]) topmod = m[1];
m = /\bmodule\s+(\w+?_top)/.exec(code);
if (m && m[1]) topmod = m[1];
var FS = verilator_mod['FS'];
//setupFS(FS);
FS.writeFile(topmod+".v", code);