1
0
mirror of https://github.com/sehugg/8bitworkshop.git synced 2024-12-22 12:30:01 +00:00

variable inspection, bitmaps for verilog, active high hsync/vsync, powerup vs reset

This commit is contained in:
Steven Hugg 2017-11-21 11:15:08 -05:00
parent 2525d6e585
commit 48baf73ecb
5 changed files with 112 additions and 35 deletions

View File

@ -8,7 +8,7 @@ module digits10_case(digit, yofs, bits);
wire [6:0] caseexpr = {digit,yofs}; wire [6:0] caseexpr = {digit,yofs};
always @(*) always @(*)
case (caseexpr) case (caseexpr)/*{w:5,h:5,count:10}*/
7'o00: bits = 5'b11111; 7'o00: bits = 5'b11111;
7'o01: bits = 5'b10001; 7'o01: bits = 5'b10001;
7'o02: bits = 5'b10001; 7'o02: bits = 5'b10001;
@ -81,11 +81,9 @@ module digits10_array(digit, yofs, bits);
reg [4:0] bitarray[10][5]; reg [4:0] bitarray[10][5];
always @(*) assign bits = bitarray[digit][yofs];
bits = bitarray[digit][yofs];
initial begin/*{w:5,h:5,count:10}*/
initial
begin
bitarray[0][0] = 5'b11111; bitarray[0][0] = 5'b11111;
bitarray[0][1] = 5'b10001; bitarray[0][1] = 5'b10001;
bitarray[0][2] = 5'b10001; bitarray[0][2] = 5'b10001;

View File

@ -43,11 +43,10 @@ module hvsync_generator(
else else
vpos <= 0; vpos <= 0;
reg vga_HS, vga_VS;
always @(posedge clk) always @(posedge clk)
begin begin
vga_HS <= (hpos>=START_H_RETRACE && hpos<=END_H_RETRACE); hsync <= (hpos>=START_H_RETRACE && hpos<=END_H_RETRACE);
vga_VS <= (vpos==START_V_RETRACE); vsync <= (vpos==START_V_RETRACE);
end end
always @(posedge clk) always @(posedge clk)
@ -55,9 +54,6 @@ module hvsync_generator(
display_on <= (hpos<H_DISPLAY) && (vpos<V_DISPLAY); display_on <= (hpos<H_DISPLAY) && (vpos<V_DISPLAY);
end end
assign hsync = ~vga_HS;
assign vsync = ~vga_VS;
endmodule endmodule
`endif `endif

View File

@ -187,14 +187,14 @@ function PixelEditor(parentDiv, fmt, palette, initialData, thumbnails) {
///////////////// /////////////////
var pixel_re = /([0#]?)([x$%])([0-9a-f]+)/gi; var pixel_re = /([0#]?)([x$%]|\d'b)([0-9a-f]+)/gi;
function parseHexBytes(s) { function parseHexBytes(s) {
var arr = []; var arr = [];
var m; var m;
while (m = pixel_re.exec(s)) { while (m = pixel_re.exec(s)) {
var n; var n;
if (m[2].startsWith('%')) if (m[2].startsWith('%') || m[2].endsWith("b"))
n = parseInt(m[3],2); n = parseInt(m[3],2);
else if (m[2].startsWith('x') || m[2].startsWith('$')) else if (m[2].startsWith('x') || m[2].startsWith('$'))
n = parseInt(m[3],16); n = parseInt(m[3],16);
@ -215,6 +215,8 @@ function replaceHexBytes(s, bytes) {
li = pixel_re.lastIndex; li = pixel_re.lastIndex;
if (m[2].startsWith('%')) if (m[2].startsWith('%'))
result += m[1] + "%" + bytes[i++].toString(2); result += m[1] + "%" + bytes[i++].toString(2);
else if (m[2].endsWith('b'))
result += m[1] + m[2] + bytes[i++].toString(2); // TODO
else if (m[2].startsWith('x')) else if (m[2].startsWith('x'))
result += m[1] + "x" + hex(bytes[i++]); result += m[1] + "x" + hex(bytes[i++]);
else if (m[2].startsWith('$')) else if (m[2].startsWith('$'))

View File

@ -139,17 +139,19 @@ var VerilogPlatform = function(mainElement, options) {
var paddle_x = 0; var paddle_x = 0;
var paddle_y = 0; var paddle_y = 0;
var switches = [0]; var switches = [0];
var inspect_obj, inspect_sym;
var inspect_data = new Uint32Array(videoWidth * videoHeight);
this.getPresets = function() { return VERILOG_PRESETS; } this.getPresets = function() { return VERILOG_PRESETS; }
var RGBLOOKUP = [ var RGBLOOKUP = [
0xff111111, 0xff222222,
0xff1111ff, 0xff2222ff,
0xff11ff11, 0xff22ff22,
0xff11ffff, 0xff22ffff,
0xffff1111, 0xffff2222,
0xffff11ff, 0xffff22ff,
0xffffff11, 0xffffff22,
0xffffffff, 0xffffffff,
]; ];
@ -158,23 +160,56 @@ var VerilogPlatform = function(mainElement, options) {
audio.addSingleSample(0+gen.spkr); // TODO: sync with audio freq audio.addSingleSample(0+gen.spkr); // TODO: sync with audio freq
} }
function updateInspectionFrame() {
if (inspect_obj && inspect_sym) {
var COLOR_BIT_OFF = 0xffff3333;
var COLOR_BIT_ON = 0xffffffff;
for (var y=0; y<videoHeight; y++) {
var val = inspect_data[y * videoWidth];
var i = y * videoWidth + 16;
do {
idata[i] = (val & 1) ? COLOR_BIT_ON : COLOR_BIT_OFF;
i -= 2;
val >>= 1;
} while (val != 0);
}
}
}
function updateInspectionPostFrame() {
if (inspect_obj && inspect_sym) {
var ctx = video.getContext();
var val = inspect_data[inspect_data.length-1];
ctx.fillStyle = "black";
ctx.fillRect(18, videoHeight-8, 30, 8);
ctx.fillStyle = "white";
ctx.fillText(val.toString(10), 20, videoHeight-1);
}
}
function updateVideoFrame() { function updateVideoFrame() {
var i=0; var i=4; // TODO, start @ 0?
var trace=inspect_obj && inspect_sym;
for (var y=0; y<videoHeight; y++) { for (var y=0; y<videoHeight; y++) {
gen.hpaddle = y > paddle_x ? 1 : 0; gen.hpaddle = y > paddle_x ? 1 : 0;
gen.vpaddle = y > paddle_y ? 1 : 0; gen.vpaddle = y > paddle_y ? 1 : 0;
for (var x=0; x<videoWidth; x++) { for (var x=0; x<videoWidth; x++) {
vidtick(); vidtick();
if (trace) {
inspect_data[i] = inspect_obj[inspect_sym];
}
idata[i++] = RGBLOOKUP[gen.rgb]; idata[i++] = RGBLOOKUP[gen.rgb];
} }
var z=0; var z=0;
while (gen.hsync && z++<videoWidth) vidtick();
while (!gen.hsync && z++<videoWidth) vidtick(); while (!gen.hsync && z++<videoWidth) vidtick();
while (gen.hsync && z++<videoWidth) vidtick();
} }
var z=0; var z=0;
while (gen.vsync && z++<videoWidth*80) vidtick();
while (!gen.vsync && z++<videoWidth*80) vidtick(); while (!gen.vsync && z++<videoWidth*80) vidtick();
while (gen.vsync && z++<videoWidth*80) vidtick();
updateInspectionFrame();
video.updateFrame(); video.updateFrame();
updateInspectionPostFrame();
} }
var yposlist = []; var yposlist = [];
@ -187,9 +222,9 @@ var VerilogPlatform = function(mainElement, options) {
if (idata[i]) if (idata[i])
idata[i] = 0; //<<= 1; idata[i] = 0; //<<= 1;
} }
var COLOR_SIGNAL = 0xff11ff11; var COLOR_SIGNAL = 0xff22ff22;
var COLOR_BORDER = 0xff661111; var COLOR_BORDER = 0xff662222;
var COLOR_TRANS_SIGNAL = 0xff116611; var COLOR_TRANS_SIGNAL = 0xff226622;
for (var x=0; x<videoWidth; x++) { for (var x=0; x<videoWidth; x++) {
gen.clk ^= 1; gen.clk ^= 1;
gen.eval(); gen.eval();
@ -221,11 +256,9 @@ var VerilogPlatform = function(mainElement, options) {
video.updateFrame(); video.updateFrame();
// draw labels // draw labels
var ctx = video.getContext(); var ctx = video.getContext();
ctx.font = "8px TinyFont";
ctx.fillStyle = "white";
for (var i=0; i<arr.length; i++) { for (var i=0; i<arr.length; i++) {
var v = arr[i]; var v = arr[i];
ctx.textAlign = 'left'; ctx.fillStyle = v.name == inspect_sym ? "yellow" : "white";
ctx.fillText(v.name, 1, yposlist[i]); ctx.fillText(v.name, 1, yposlist[i]);
//ctx.textAlign = 'right'; //ctx.textAlign = 'right';
//ctx.fillText(""+gen[v.name], videoWidth-1, yposlist[i]); //ctx.fillText(""+gen[v.name], videoWidth-1, yposlist[i]);
@ -240,6 +273,10 @@ var VerilogPlatform = function(mainElement, options) {
// TODO // TODO
video = new RasterVideo(mainElement,videoWidth,videoHeight); video = new RasterVideo(mainElement,videoWidth,videoHeight);
video.create(); video.create();
var ctx = video.getContext();
ctx.font = "8px TinyFont";
ctx.fillStyle = "white";
ctx.textAlign = "left";
setKeyboardFromMap(video, switches, VERILOG_KEYCODE_MAP); setKeyboardFromMap(video, switches, VERILOG_KEYCODE_MAP);
$(video.canvas).mousemove(function(e) { $(video.canvas).mousemove(function(e) {
paddle_x = clamp(8,240,Math.floor(e.offsetX * video.canvas.width / $(video.canvas).width() - 20)); paddle_x = clamp(8,240,Math.floor(e.offsetX * video.canvas.width / $(video.canvas).width() - 20));
@ -283,10 +320,8 @@ var VerilogPlatform = function(mainElement, options) {
var base = new VerilatorBase(); var base = new VerilatorBase();
gen = new mod(base); gen = new mod(base);
gen.__proto__ = base; gen.__proto__ = base;
output.code = null;
output.ports_signals = output.ports.concat(output.signals);
current_output = output; current_output = output;
this.reset(); this.poweron();
} }
this.isRunning = function() { this.isRunning = function() {
@ -301,14 +336,37 @@ var VerilogPlatform = function(mainElement, options) {
if (gen.spkr !== undefined) audio.start(); if (gen.spkr !== undefined) audio.start();
} }
this.reset = function() { this.poweron = function() {
gen._ctor_var_reset(); gen._ctor_var_reset();
this.reset();
}
this.reset = function() {
gen.reset2(); gen.reset2();
} }
this.getToolForFilename = function(fn) { this.getToolForFilename = function(fn) {
return "verilator"; return "verilator";
} }
this.getDefaultExtension = function() { return ".v"; }; this.getDefaultExtension = function() { return ".v"; };
this.inspect = function(name) {
if (!gen) return;
if (name && !name.match(/^\w+$/)) return;
var val = gen[name];
if (val === undefined && current_output.code) {
var re = new RegExp("(\\w+__DOT__" + name + ")\\b", "gm");
var m = re.exec(current_output.code);
if (m) {
name = m[1];
val = gen[name];
}
}
if (val !== undefined) {
inspect_obj = gen;
inspect_sym = name;
} else {
inspect_obj = inspect_sym = null;
}
}
}; };
function traceTiming() { function traceTiming() {

View File

@ -189,10 +189,27 @@ function newEditor(mode) {
setCode(editor.getValue()); setCode(editor.getValue());
}, 200); }, 200);
}); });
editor.on('cursorActivity', function(ed) {
var start = editor.getCursor(true);
var end = editor.getCursor(false);
if (start.line == end.line && start.ch < end.ch) {
var name = editor.getSelection();
inspectVariable(editor, name);
} else {
inspectVariable(editor);
}
});
scrollProfileView(editor); scrollProfileView(editor);
editor.setOption("mode", mode); editor.setOption("mode", mode);
} }
function inspectVariable(editor, name) {
var val;
if (platform.inspect) {
platform.inspect(name);
}
}
function getCurrentPresetTitle() { function getCurrentPresetTitle() {
if (current_preset_index < 0) if (current_preset_index < 0)
return "ROM"; return "ROM";
@ -1105,7 +1122,13 @@ function lookBackwardsForJSONComment(line, req) {
var pos0 = start.ch; var pos0 = start.ch;
line--; line--;
while (++line < editor.lineCount()) { while (++line < editor.lineCount()) {
if (editor.getLine(line).indexOf(';') >= pos0) { var l = editor.getLine(line);
var endsection;
if (platform_id == 'verilog')
endsection = l.indexOf('end') >= pos0;
else
endsection = l.indexOf(';') >= pos0;
if (endsection) {
var end = {line:line, ch:editor.getLine(line).length}; var end = {line:line, ch:editor.getLine(line).length};
return {obj:obj, start:start, end:end}; return {obj:obj, start:start, end:end};
} }