- USB CDC 경로 복원: #define Serial Serial1 우회 제거 - rp2040js/avr8js/codemirror/xterm/monaco-editor vendor화 - /vendor 정적 라우팅 추가 (Express 5 catch-all 우회) - 부팅 완료 타임아웃 감지 (Serial 출력 없어도 8초 후 RAF 전환) - 리셋 시 Simulator 재생성으로 주변 장치 상태 초기화 - 시리얼 패널의 내부 메시지를 console.log로 이동
42 lines
1.3 KiB
JavaScript
42 lines
1.3 KiB
JavaScript
import { SimulationClock } from './clock/simulation-clock.js';
|
|
import { RP2040 } from './rp2040.js';
|
|
export class Simulator {
|
|
constructor(clock = new SimulationClock()) {
|
|
this.clock = clock;
|
|
this.executeTimer = null;
|
|
this.stopped = true;
|
|
this.rp2040 = new RP2040(clock);
|
|
this.rp2040.onBreak = () => this.stop();
|
|
}
|
|
execute() {
|
|
const { rp2040, clock } = this;
|
|
this.executeTimer = null;
|
|
this.stopped = false;
|
|
const cycleNanos = 1e9 / 125000000; // 125 MHz
|
|
for (let i = 0; i < 1000000 && !this.stopped; i++) {
|
|
if (rp2040.core.waiting) {
|
|
const { nanosToNextAlarm } = clock;
|
|
clock.tick(nanosToNextAlarm);
|
|
i += nanosToNextAlarm / cycleNanos;
|
|
}
|
|
else {
|
|
const cycles = rp2040.core.executeInstruction();
|
|
clock.tick(cycles * cycleNanos);
|
|
}
|
|
}
|
|
if (!this.stopped) {
|
|
this.executeTimer = setTimeout(() => this.execute(), 0);
|
|
}
|
|
}
|
|
stop() {
|
|
this.stopped = true;
|
|
if (this.executeTimer != null) {
|
|
clearTimeout(this.executeTimer);
|
|
this.executeTimer = null;
|
|
}
|
|
}
|
|
get executing() {
|
|
return !this.stopped;
|
|
}
|
|
}
|