mirror of
https://github.com/sehugg/8bitworkshop.git
synced 2024-11-22 14:33:51 +00:00
verilog: monitor sync
This commit is contained in:
parent
bc13614b6a
commit
ac55082863
@ -376,6 +376,7 @@ var VerilogPlatform = function(mainElement, options) {
|
|||||||
this.updateRecorder();
|
this.updateRecorder();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (!sync) scanlineCycles = 0;
|
||||||
// use slow update method
|
// use slow update method
|
||||||
var trace0 = trace_index;
|
var trace0 = trace_index;
|
||||||
while (ncycles--) {
|
while (ncycles--) {
|
||||||
@ -393,17 +394,15 @@ var VerilogPlatform = function(mainElement, options) {
|
|||||||
idata[frameidx] = rgb & 0x80000000 ? rgb : RGBLOOKUP[rgb & 15];
|
idata[frameidx] = rgb & 0x80000000 ? rgb : RGBLOOKUP[rgb & 15];
|
||||||
frameidx++;
|
frameidx++;
|
||||||
}
|
}
|
||||||
scanlineCycles++;
|
|
||||||
} else if (!framehsync && top.state.hsync) {
|
} else if (!framehsync && top.state.hsync) {
|
||||||
framehsync = true;
|
framehsync = true;
|
||||||
scanlineCycles++;
|
|
||||||
} else if ((framehsync && !top.state.hsync) || framex > videoWidth*2) {
|
} else if ((framehsync && !top.state.hsync) || framex > videoWidth*2) {
|
||||||
framehsync = false;
|
framehsync = false;
|
||||||
|
if (sync) scanlineCycles = framex;
|
||||||
framex = 0;
|
framex = 0;
|
||||||
framey++;
|
framey++;
|
||||||
top.state.hpaddle = framey > video.paddle_x ? 1 : 0;
|
top.state.hpaddle = framey > video.paddle_x ? 1 : 0;
|
||||||
top.state.vpaddle = framey > video.paddle_y ? 1 : 0;
|
top.state.vpaddle = framey > video.paddle_y ? 1 : 0;
|
||||||
scanlineCycles = 0;
|
|
||||||
}
|
}
|
||||||
if (framey > maxVideoLines || top.state.vsync) {
|
if (framey > maxVideoLines || top.state.vsync) {
|
||||||
framevsync = true;
|
framevsync = true;
|
||||||
@ -426,8 +425,7 @@ var VerilogPlatform = function(mainElement, options) {
|
|||||||
// use trace buffer to update video
|
// use trace buffer to update video
|
||||||
updateVideoFrameFast(tmod: HDLModuleTrace) {
|
updateVideoFrameFast(tmod: HDLModuleTrace) {
|
||||||
var maxLineCycles = 1009; // prime number so we eventually sync up
|
var maxLineCycles = 1009; // prime number so we eventually sync up
|
||||||
if (!scanlineCycles) scanlineCycles = maxLineCycles;
|
var nextlineCycles = scanlineCycles;
|
||||||
var nextlineCycles = scanlineCycles + 1;
|
|
||||||
// TODO: we can go faster if no paddle/sound
|
// TODO: we can go faster if no paddle/sound
|
||||||
frameidx = 0;
|
frameidx = 0;
|
||||||
var wasvsync = false;
|
var wasvsync = false;
|
||||||
@ -435,7 +433,7 @@ var VerilogPlatform = function(mainElement, options) {
|
|||||||
function spkr() { if (useAudio) audio.feedSample(tmod.trace.spkr, 1); }
|
function spkr() { if (useAudio) audio.feedSample(tmod.trace.spkr, 1); }
|
||||||
// iterate through a frame of scanlines + room for vsync
|
// iterate through a frame of scanlines + room for vsync
|
||||||
for (framey=0; framey<videoHeight*2; framey++) {
|
for (framey=0; framey<videoHeight*2; framey++) {
|
||||||
if (usePaddles) {
|
if (usePaddles && framey < videoHeight) {
|
||||||
top.state.hpaddle = framey > video.paddle_x ? 1 : 0;
|
top.state.hpaddle = framey > video.paddle_x ? 1 : 0;
|
||||||
top.state.vpaddle = framey > video.paddle_y ? 1 : 0;
|
top.state.vpaddle = framey > video.paddle_y ? 1 : 0;
|
||||||
}
|
}
|
||||||
@ -445,9 +443,11 @@ var VerilogPlatform = function(mainElement, options) {
|
|||||||
resetKbdStrobe();
|
resetKbdStrobe();
|
||||||
// convert trace buffer to video/audio
|
// convert trace buffer to video/audio
|
||||||
var n = 0;
|
var n = 0;
|
||||||
|
// draw scanline visible pixels
|
||||||
if (framey < videoHeight) {
|
if (framey < videoHeight) {
|
||||||
for (framex=0; framex<videoWidth; framex++) {
|
for (framex=0; framex<videoWidth; framex++) {
|
||||||
var rgb = tmod.trace.rgb;
|
var rgb = tmod.trace.rgb;
|
||||||
|
//if (tmod.trace.hsync) rgb ^= Math.random() * 15;
|
||||||
idata[frameidx++] = rgb & 0x80000000 ? rgb : RGBLOOKUP[rgb & 15];
|
idata[frameidx++] = rgb & 0x80000000 ? rgb : RGBLOOKUP[rgb & 15];
|
||||||
spkr();
|
spkr();
|
||||||
tmod.nextTrace();
|
tmod.nextTrace();
|
||||||
@ -455,18 +455,26 @@ var VerilogPlatform = function(mainElement, options) {
|
|||||||
n += videoWidth;
|
n += videoWidth;
|
||||||
}
|
}
|
||||||
// find hsync
|
// find hsync
|
||||||
while (n < nextlineCycles && !tmod.trace.hsync) { spkr(); tmod.nextTrace(); n++; }
|
var hsyncStart=0, hsyncEnd=0;
|
||||||
while (n < nextlineCycles && tmod.trace.hsync) { spkr(); tmod.nextTrace(); n++; }
|
while (n < nextlineCycles) {
|
||||||
// see if our scanline cycle count is stable
|
if (tmod.trace.hsync) {
|
||||||
if (n == scanlineCycles + 1) {
|
if (!hsyncStart) hsyncStart = n;
|
||||||
// scanline cycle count licked in, reset buffer to improve cache locality
|
hsyncEnd = n;
|
||||||
nextlineCycles = n;
|
} else if (hsyncEnd)
|
||||||
|
break;
|
||||||
|
spkr();
|
||||||
|
tmod.nextTrace();
|
||||||
|
n++;
|
||||||
|
}
|
||||||
|
// see if our scanline cycle count is stable (can't read tmod.trace after end of line)
|
||||||
|
if (hsyncStart < hsyncEnd && hsyncEnd == scanlineCycles-1) {
|
||||||
|
// scanline cycle count locked in, reset buffer to improve cache locality
|
||||||
|
nextlineCycles = scanlineCycles;
|
||||||
tmod.resetTrace();
|
tmod.resetTrace();
|
||||||
} else {
|
} else {
|
||||||
// not in sync, don't reset buffer (TODO: take some of the cycles back)
|
// not in sync, don't reset buffer (TODO: take some of the cycles back)
|
||||||
//console.log('scanline', scanlineCycles, nextlineCycles, n);
|
//console.log('scanline', framey, scanlineCycles, nextlineCycles, n, hsyncStart, hsyncEnd);
|
||||||
scanlineCycles = n;
|
nextlineCycles = maxLineCycles;
|
||||||
nextlineCycles = n;
|
|
||||||
}
|
}
|
||||||
// exit when vsync starts and then stops
|
// exit when vsync starts and then stops
|
||||||
if (tmod.trace.vsync) {
|
if (tmod.trace.vsync) {
|
||||||
|
Loading…
Reference in New Issue
Block a user