verilog: ctrl-click to pause on scanline

This commit is contained in:
Steven Hugg 2019-05-01 22:07:17 -04:00
parent efb49f7fc8
commit 8152a14a2b
3 changed files with 46 additions and 15 deletions

View File

@ -84,7 +84,7 @@ export class RasterVideo {
arraybuf;
buf8;
datau32;
vcanvas;
vcanvas : JQuery;
paddle_x = 255;
paddle_y = 255;
@ -132,17 +132,15 @@ export class RasterVideo {
this.ctx.putImageData(this.imageData, 0, 0);
}
setupMouseEvents(el? : HTMLElement) {
setupMouseEvents(el? : HTMLCanvasElement) {
if (!el) el = this.canvas;
$(el).mousemove( (e) => {
// TODO: get coords right
var x = e.pageX - this.vcanvas.offset().left;
var y = e.pageY - this.vcanvas.offset().top;
var new_x = Math.floor(x * 255 / this.vcanvas.width() - 20);
var new_y = Math.floor(y * 255 / this.vcanvas.height() - 20);
this.paddle_x = clamp(0, 255, new_x);
this.paddle_y = clamp(0, 255, new_y);
});
$(el).mousemove( (e) => {
var pos = getMousePos(el, e);
var new_x = Math.floor(pos.x * 255 / this.canvas.width);
var new_y = Math.floor(pos.y * 255 / this.canvas.height);
this.paddle_x = clamp(0, 255, new_x);
this.paddle_y = clamp(0, 255, new_y);
});
};
}
@ -548,3 +546,15 @@ export class Toolbar {
}
// https://stackoverflow.com/questions/17130395/real-mouse-position-in-canvas
export function getMousePos(canvas : HTMLCanvasElement, evt) {
var rect = canvas.getBoundingClientRect(), // abs. size of element
scaleX = canvas.width / rect.width, // relationship bitmap vs. element for X
scaleY = canvas.height / rect.height; // relationship bitmap vs. element for Y
return {
x: (evt.clientX - rect.left) * scaleX, // scale mouse coordinates after they have
y: (evt.clientY - rect.top) * scaleY // been adjusted to be relative to element
}
}

View File

@ -1,10 +1,11 @@
"use strict";
import { Platform, BasePlatform } from "../baseplatform";
import { PLATFORMS, setKeyboardFromMap, AnimationTimer, RasterVideo, Keys, makeKeycodeMap } from "../emu";
import { PLATFORMS, setKeyboardFromMap, AnimationTimer, RasterVideo, Keys, makeKeycodeMap, getMousePos } from "../emu";
import { SampleAudio } from "../audio";
import { safe_extend, clamp } from "../util";
import { WaveformView, WaveformProvider, WaveformMeta } from "../waveform";
import { setFrameRateUI } from "../ui";
declare var Split;
@ -352,6 +353,23 @@ var VerilogPlatform = function(mainElement, options) {
});
// setup mouse events
video.setupMouseEvents();
// setup mouse click
video.vcanvas.click( (e) => {
if (!gen) return; // must have created emulator
if (!e.ctrlKey) {
setFrameRateUI(60);
return; // ctrl key must be down
}
setFrameRateUI(1.0/2048);
var pos = getMousePos(video.canvas, e);
var new_y = Math.floor(pos.y);
var clock = 0;
while (framey != new_y || clock++ > 200000) {
this.setGenInputs();
this.updateVideoFrameCycles(1, true, false);
gen.__unreset();
}
});
}
resize() {
@ -371,15 +389,18 @@ var VerilogPlatform = function(mainElement, options) {
this.setGenInputs();
var fps = this.getFrameRate();
// darken the previous frame?
if (fps < 45) {
var sync = fps > 45;
if (!sync) {
var mask = fps > 5 ? 0xe7ffffff : 0x7fdddddd;
for (var i=0; i<idata.length; i++)
idata[i] &= mask;
}
// paint into frame, synched with vsync if full speed
var sync = fps > 45;
var trace = this.isScopeVisible();
this.updateVideoFrameCycles(cyclesPerFrame * fps/60 + 1, sync, trace);
if (fps < 0.25) {
idata[frameidx] = -1;
}
//this.restartDebugState();
gen.__unreset();
this.refreshVideoFrame();

View File

@ -951,7 +951,7 @@ function _recordVideo() {
//TODO? return true;
}
function setFrameRateUI(fps:number) {
export function setFrameRateUI(fps:number) {
platform.setFrameRate(fps);
if (fps > 0.01)
$("#fps_label").text(fps.toFixed(2));