From 0ca9f43098549596cb43080ccf6fa18155df4716 Mon Sep 17 00:00:00 2001 From: Steven Hugg Date: Mon, 13 Nov 2017 00:24:19 -0500 Subject: [PATCH] verilog: multiple modules, sound, tables, reset, module_top detect --- src/audio.js | 16 ++++++---- src/emu.js | 6 ++-- src/platform/verilog.js | 62 +++++++++++++++++++++++++++++--------- src/ui.js | 4 ++- src/worker/verilator2js.js | 18 +++++++---- src/worker/workermain.js | 21 ++++++++----- 6 files changed, 90 insertions(+), 37 deletions(-) diff --git a/src/audio.js b/src/audio.js index fa39c7cc..c04c793d 100644 --- a/src/audio.js +++ b/src/audio.js @@ -395,19 +395,23 @@ var SampleAudio = function(clockfreq) { } } + this.addSingleSample = function(value) { + buffer[bufpos++] = value; + if (bufpos >= buffer.length) { + bufpos = 0; + bufferlist[0] = bufferlist[1]; + bufferlist[1] = buffer; + } + } + this.feedSample = function(value, count) { while (count-- > 0) { accum += value; sfrac += sinc; if (sfrac >= 1) { - buffer[bufpos++] = accum / sfrac; sfrac -= 1; accum = 0; - if (bufpos >= buffer.length) { - bufpos = 0; - bufferlist[0] = bufferlist[1]; - bufferlist[1] = buffer; - } + this.feedSingleSample(accum / sfrac); } } } diff --git a/src/emu.js b/src/emu.js index c12dbbc6..0f3b13b9 100644 --- a/src/emu.js +++ b/src/emu.js @@ -207,8 +207,7 @@ var AnimationTimer = function(frequencyHz, callback) { var running; var lastts = 0; var useReqAnimFrame = window.requestAnimationFrame ? true : false; - var nframes = 0; - var startts = 0; + var nframes, startts; // for FPS calc function scheduleFrame() { if (useReqAnimFrame) @@ -222,8 +221,8 @@ var AnimationTimer = function(frequencyHz, callback) { lastts += intervalMsec; } else { lastts = ts; - startts = ts; } + if (nframes == 0) startts = ts; if (nframes++ == 300) { console.log("Avg framerate: " + nframes*1000/(ts-startts) + " fps"); } @@ -240,6 +239,7 @@ var AnimationTimer = function(frequencyHz, callback) { if (!running) { running = true; lastts = 0; + nframes = 0; scheduleFrame(); } } diff --git a/src/platform/verilog.js b/src/platform/verilog.js index 7f5cf35e..677783b5 100644 --- a/src/platform/verilog.js +++ b/src/platform/verilog.js @@ -2,14 +2,30 @@ var VERILOG_PRESETS = [ {id:'hvsync.v', name:'Hello Verilog'}, + {id:'pong.v', name:'Pong'}, ]; function VerilatorBase() { this.VL_RAND_RESET_I = function(bits) { return Math.floor(Math.random() * (1< 100) vl_fatal(__FILE__,__LINE__,__FILE__,"Verilated model didn't converge"); + if (++__VclockLoop > 100) { vl_fatal("Verilated model didn't converge"); } } if (__VclockLoop > maxVclockLoop) { maxVclockLoop = __VclockLoop; @@ -47,26 +63,44 @@ function VerilatorBase() { this._eval_settle(vlSymsp); this._eval(vlSymsp); __Vchange = this._change_request(vlSymsp); - if (++__VclockLoop > 100) vl_fatal(__FILE__,__LINE__,__FILE__,"Verilated model didn't DC converge"); + if (++__VclockLoop > 100) { vl_fatal("Verilated model didn't DC converge"); } } } } var VerilogPlatform = function(mainElement, options) { var self = this; - var video; + var video, audio; var videoWidth=288; var videoHeight=248; var idata, timer; var gen; var frameRate = 60; + var AUDIO_FREQ = 15700; this.getPresets = function() { return VERILOG_PRESETS; } + function tick2() { + gen.tick2(); + audio.addSingleSample(0+gen.audio); // TODO: sync with audio freq + } + + var RGBLOOKUP = [ + 0xff111111, + 0xff1111ff, + 0xff11ff11, + 0xff11ffff, + 0xffff1111, + 0xffff11ff, + 0xffffff11, + 0xffffffff, + ]; + this.start = function() { // TODO video = new RasterVideo(mainElement,videoWidth,videoHeight); video.create(); + audio = new SampleAudio(AUDIO_FREQ); idata = video.getFrameData(); // TODO: 15.7 kHz? timer = new AnimationTimer(frameRate, function() { @@ -75,17 +109,16 @@ var VerilogPlatform = function(mainElement, options) { var i=0; for (var y=0; y