show raster x/y crosshair when stopped (getRasterCanvasPosition)

This commit is contained in:
Steven Hugg 2023-11-10 10:38:30 -06:00
parent c6345ec728
commit de6250b0cd
11 changed files with 254 additions and 160 deletions

@ -1 +1 @@
Subproject commit 9d124f087e1f0c7f74f9244b9679cc62e71fa524
Subproject commit 113cd5741e5c414bbbe47ef8be7a896652d48f64

View File

@ -1,5 +1,5 @@
import { RasterVideo, dumpRAM, AnimationTimer, ControllerPoller } from "./emu";
import { RasterVideo, dumpRAM, AnimationTimer, ControllerPoller, drawCrosshair } from "./emu";
import { hex, printFlags, invertMap, byteToASCII } from "./util";
import { CodeAnalyzer } from "./analysis";
import { Segment, FileData } from "./workertypes";
@ -873,11 +873,26 @@ export abstract class BaseMachinePlatform<T extends Machine> extends BaseDebugPl
advance(novideo:boolean) {
let trap = this.getDebugCallback();
var steps = this.machine.advanceFrame(trap);
if (!novideo && this.video) this.video.updateFrame();
if (!novideo && this.serialVisualizer) this.serialVisualizer.refresh();
if (!novideo && this.video) {
this.video.updateFrame();
this.updateVideoDebugger();
}
if (!novideo && this.serialVisualizer) {
this.serialVisualizer.refresh();
}
return steps;
}
updateVideoDebugger() {
if (!this.isRunning() && isRaster(this.machine) && this.machine.getRasterCanvasPosition) {
const {x,y} = this.machine.getRasterCanvasPosition();
if (x >= 0 || y >= 0) {
const ctx = this.video.getContext();
drawCrosshair(ctx, x, y, 1);
}
}
}
advanceFrameClock(trap, step) {
if (!(step > 0)) return;
if (this.machine instanceof BaseWASMMachine) {
@ -915,7 +930,10 @@ export abstract class BaseMachinePlatform<T extends Machine> extends BaseDebugPl
// TODO: reset target clock counter
getRasterScanline() {
return isRaster(this.machine) && this.machine.getRasterY();
return isRaster(this.machine) && this.machine.getRasterY ? this.machine.getRasterY() : -1;
}
getRasterLineClock() {
return isRaster(this.machine) && this.machine.getRasterX ? this.machine.getRasterX() : -1;
}
readAddress(addr : number) : number {

View File

@ -32,6 +32,7 @@ export interface VideoSource {
export interface RasterFrameBased extends FrameBased, VideoSource {
getRasterY(): number;
getRasterX(): number;
getRasterCanvasPosition?(): { x: number, y: number };
}
export interface VideoParams {
@ -341,11 +342,13 @@ export abstract class BasicMachine extends BasicHeadlessMachine implements Sampl
this.audio = audio;
}
getVideoParams(): VideoParams {
return {width:this.canvasWidth,
return {
width: this.canvasWidth,
height: this.numVisibleScanlines,
aspect: this.aspectRatio,
overscan: this.overscan,
rotate:this.rotate};
rotate: this.rotate
};
}
connectVideo(pixels: Uint32Array): void {
this.pixels = pixels;

View File

@ -215,6 +215,21 @@ export class VectorVideo extends RasterVideo {
}
}
export function drawCrosshair(ctx:CanvasRenderingContext2D, x:number, y:number, width:number) {
ctx.fillStyle = 'rgba(0,0,0,0.25)';
ctx.fillRect(x-2, 0, 5, 32767);
ctx.fillRect(0, y-2, 32767, 5);
ctx.lineWidth = width;
ctx.strokeStyle = 'rgba(255,255,255,0.75)';
ctx.setLineDash([width*2,width*2]);
ctx.beginPath();
ctx.moveTo(x, 0);
ctx.lineTo(x, 32767);
ctx.moveTo(0, y);
ctx.lineTo(32767, y);
ctx.stroke();
}
export class RAM {
mem : Uint8Array;
constructor(size:number) {

View File

@ -556,6 +556,7 @@ export class BallyAstrocade extends BasicScanlineMachine implements AcceptsPaddl
case 'Astro': return this.m.toLongString(state);
}
}
getRasterCanvasPosition() { return { x: this.getRasterX(), y: this.getRasterY() }; }
}

View File

@ -516,6 +516,7 @@ export class Atari7800 extends BasicMachine implements RasterFrameBased {
var mc = 0;
var fc = 0;
var steps = 0;
this.lastFrameCycles = -1;
this.probe.logNewFrame();
//console.log(hex(this.cpu.getPC()), hex(this.maria.dll));
// visible lines
@ -530,6 +531,7 @@ export class Atari7800 extends BasicMachine implements RasterFrameBased {
if (trap && trap()) {
trap = null;
sl = 999;
this.lastFrameCycles = mc;
break; // TODO?
}
mc += this.advanceCPU() << 2;
@ -567,6 +569,7 @@ export class Atari7800 extends BasicMachine implements RasterFrameBased {
if (trap && trap()) {
trap = null;
sl = 999;
this.lastFrameCycles = mc;
break;
}
mc += this.advanceCPU() << 2;
@ -583,13 +586,18 @@ export class Atari7800 extends BasicMachine implements RasterFrameBased {
// TODO let bkcol = this.maria.regs[0x0];
// TODO $(this.video.canvas).css('background-color', COLORS_WEB[bkcol]);
*/
this.lastFrameCycles = fc;
return steps;
}
getRasterX() { return this.lastFrameCycles % colorClocksPerLine; }
// TODO: doesn't work when breakpoint
getRasterX() { return (this.lastFrameCycles + colorClocksPerLine) % colorClocksPerLine; }
getRasterY() { return this.scanline; }
getRasterCanvasPosition() {
return { x: this.getRasterX(), y: this.getRasterY() };
}
loadROM(data) {
if (data.length == 0xc080) data = data.slice(0x80); // strip header
this.rom = padBytes(data, this.defaultROMSize, true);

View File

@ -267,12 +267,18 @@ export class Atari800 extends BasicScanlineMachine implements AcceptsPaddleInput
keycode: this.keycode,
};
}
getRasterScanline() {
getRasterY() {
return this.antic.v;
}
getRasterLineClock() {
getRasterX() {
return this.antic.h;
}
getRasterCanvasPosition() {
return {
x: this.antic.h * 4 - this.firstVisibleClock,
y: this.antic.v - this.firstVisibleScanline,
}
}
getDebugCategories() {
return ['CPU', 'Stack', 'ANTIC', 'GTIA', 'POKEY'];
}

View File

@ -200,9 +200,18 @@ export class C64_WASMMachine extends BaseWASMMachine
}
this.exports.c64_joystick(this.sys, this.joymask0, this.joymask1);
}
getRasterX() {
return this.statearr[0xf4];
}
getRasterY() {
return this.exports.machine_get_raster_line(this.sys);
}
getRasterCanvasPosition() {
return {
x: this.getRasterX() * 392/63,
y: this.getRasterY() - 14,
}
}
getDebugStateOffset(index: number) {
var p = this.exports.machine_get_debug_pointer(this.sys, index);
return p - this.sys;

View File

@ -69,6 +69,12 @@ export class CPC_WASMMachine extends BaseWASMMachine implements Machine {
getRasterY() {
return this.exports.machine_get_raster_line(this.sys);
}
getRasterCanvasPosition() {
return {
x: -1, // TODO?
y: this.getRasterY() - 14,
}
}
/*
z80_tick_t tick_cb; // 0
uint64_t bc_de_hl_fa; // 8

View File

@ -93,6 +93,12 @@ export class VIC20_WASMMachine extends BaseWASMMachine implements Machine, Probe
getRasterY() {
return this.exports.machine_get_raster_line(this.sys);
}
getRasterCanvasPosition() {
return {
x: -1, // TODO?
y: this.getRasterY() - 14,
}
}
getCPUState() {
this.exports.machine_save_cpu_state(this.sys, this.cpustateptr);
var s = this.cpustatearr;

View File

@ -1,6 +1,6 @@
import { Platform, BasePlatform, cpuStateToLongString_6502, dumpStackToString, DisasmLine, CpuState, getToolForFilename_6502 } from "../common/baseplatform";
import { PLATFORMS, dumpRAM, EmuHalt, RasterVideo, __createCanvas } from "../common/emu";
import { PLATFORMS, dumpRAM, EmuHalt, RasterVideo, __createCanvas, drawCrosshair } from "../common/emu";
import { hex, loadScript, lpad, tobin } from "../common/util";
import { CodeAnalyzer_vcs } from "../common/analysis";
import { disassemble6502 } from "../common/cpu/disasm6502";
@ -72,6 +72,7 @@ function getToolForFilename_vcs(fn: string) {
class VCSPlatform extends BasePlatform {
lastBreakState; // last breakpoint state
canvas : HTMLCanvasElement;
// TODO: super hack for ProbeBitmap view
machine = {
@ -92,10 +93,10 @@ class VCSPlatform extends BasePlatform {
// show console div and start
$("#javatari-div").show();
Javatari.start();
var console = Javatari.room.console;
var jaconsole = Javatari.room.console;
// intercept clockPulse function
console.oldClockPulse = console.clockPulse;
console.clockPulse = function() {
jaconsole.oldClockPulse = jaconsole.clockPulse;
jaconsole.clockPulse = function() {
self.updateRecorder();
self.probe.logNewFrame();
this.oldClockPulse();
@ -106,18 +107,19 @@ class VCSPlatform extends BasePlatform {
}
}
// intercept TIA end of line
var videoSignal = console.tia.getVideoOutput();
var videoSignal = jaconsole.tia.getVideoOutput();
videoSignal.oldNextLine = videoSignal.nextLine;
videoSignal.nextLine = function(pixels, vsync) {
self.probe.logNewScanline();
return this.oldNextLine(pixels, vsync);
}
// resize after added to dom tree
var jacanvas = $("#javatari-screen").find("canvas");
var jacanvas = $("#javatari-screen").find("canvas")[0];
const resizeObserver = new ResizeObserver(entries => {
this.resize();
});
resizeObserver.observe(jacanvas[0]);
resizeObserver.observe(jacanvas);
this.canvas = jacanvas;
}
loadROM(title, data) {
@ -148,6 +150,16 @@ class VCSPlatform extends BasePlatform {
getRasterLineClock() : number {
return this.getRasterPosition().x;
}
getRasterCanvasPosition() : {x:number,y:number} {
let p = Javatari.room.console.tia.getVideoOutput().monitor.getDisplayParameters();
let {x,y} = this.getRasterPosition();
let canvasPos = {
x: (x - p.displayOriginX) * p.displayWidth * p.displayScaleX / (p.signalWidth - p.displayOriginX),
y: (y - p.displayOriginY) * p.displayHeight * p.displayScaleY / p.displayHeight
};
console.log(x,y,canvasPos,p);
return canvasPos;
}
// TODO: Clock changes this on event, so it may not be current
isRunning() {
@ -194,6 +206,8 @@ class VCSPlatform extends BasePlatform {
Javatari.room.speaker.mute();
this.lastBreakState = state;
callback(state);
// TODO: we have to delay because javatari timer is still running
setTimeout(() => this.updateVideoDebugger(), 100);
}
Javatari.room.speaker.mute();
}
@ -248,6 +262,7 @@ class VCSPlatform extends BasePlatform {
}
readAddress(addr) {
// TODO: shouldn't have to do this when debugging
// TODO: don't read bank switch addresses
if (this.lastBreakState && addr >= 0x80 && addr < 0x100)
return this.getRAMForState(this.lastBreakState)[addr & 0x7f];
else if ((addr & 0x1280) === 0x280)
@ -419,6 +434,13 @@ class VCSPlatform extends BasePlatform {
var xt = (1 - scale) * 50;
$('#javatari-div').css('transform', `translateX(-${xt}%) translateY(-${xt}%) scale(${scale})`);
}
updateVideoDebugger() {
const {x,y} = this.getRasterCanvasPosition();
if (x >= 0 || y >= 0) {
const ctx = this.canvas.getContext('2d');
drawCrosshair(ctx, x, y, 2);
}
}
};
// TODO: mixin for Base6502Platform?