Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 | 3x 3x 3x 3x 3x 3x 3x 3x 194x 194x 60x 60x 60x 1080x 1080x 60x 60x 60x 960x 60x 60x 60x 60x 60x 60x 60x 60x 60x 60x 60x 60x | // Shared helpers for snapshot importers (bem-snapshot.js, uef-snapshot.js): the jsbeeb state each
// chip's import ends in, and the common snapshot envelope that wraps per-format parsed state.
import { EVERYTHINGENABLED, Video } from "./video.js";
const DefaultAcia = {
sr: 0x02,
cr: 0x00,
dr: 0x00,
rs423Selected: false,
motorOn: false,
tapeCarrierCount: 0,
tapeDcdLineLevel: false,
hadDcdHigh: false,
serialReceiveRate: 19200,
serialTransmitRate: 19200,
txCompleteTaskOffset: null,
runTapeTaskOffset: null,
runRs423TaskOffset: null,
};
const DefaultAdc = { status: 0x40, low: 0x00, high: 0x00, taskOffset: null };
const CrtcImportedRegisters = 18;
const CrtcAddress = 0;
const CrtcData = 1;
const UlaControl = 0;
const UlaPalette = 1;
const MaxDisplayEnableSkew = 2;
/**
* A jsbeeb VIA state from an imported VIA's registers and lines.
* @param {{ora: number, orb: number, ira: number, irb: number, ddra: number, ddrb: number, sr: number, acr: number,
* pcr: number, ifr: number, ier: number, t1l: number, t2l: number, t1c: number, t2c: number,
* t1hit: number|boolean, t2hit: number|boolean, ca1: number|boolean, ca2: number|boolean, cb2?: boolean}} via
* timers in jsbeeb's units, twice the 1MHz count
* @param {number|undefined} ic32 the system VIA's addressable latch; undefined for the user VIA
*/
export function importedViaState(via, ic32) {
const state = {
ora: via.ora,
orb: via.orb,
ira: via.ira,
irb: via.irb,
ddra: via.ddra,
ddrb: via.ddrb,
sr: via.sr,
acr: via.acr,
pcr: via.pcr,
ifr: via.ifr,
ier: via.ier,
t1l: via.t1l,
t2l: via.t2l,
t1c: via.t1c,
t2c: via.t2c,
// A free-running timer 1 that has already hit would never interrupt again, the 100Hz tick among them.
t1hit: via.acr & 0x40 ? false : !!via.t1hit,
t2hit: !!via.t2hit,
portapins: 0xff,
portbpins: 0xff,
ca1: !!via.ca1,
ca2: !!via.ca2,
cb1: false,
cb2: !!via.cb2,
justhit: 0,
t1_pb7: (via.orb >> 7) & 1,
lastPolltime: 0,
taskOffset: 1,
};
return ic32 === undefined ? state : { ...state, IC32: ic32 };
}
/**
* A jsbeeb sound chip state from an imported chip's channels, in SN76489 order with noise last.
* @param {{registers: Uint16Array, counter: Float32Array, outputBit: boolean[], volume: Float32Array}} channels
* @param {number} lfsr the noise shift register
*/
export function importedSoundState({ registers, counter, outputBit, volume }, lfsr) {
return {
registers,
counter,
outputBit,
volume,
lfsr,
latchedRegister: 0,
residual: 0,
sineOn: false,
sineStep: 0,
sineTime: 0,
};
}
/**
* Build jsbeeb video state from parsed CRTC, ULA and palette data, by writing them to a Video as the
* guest would have.
* @param {number} ulaControl - VideoULA control register
* @param {Uint8Array} ulaPalette - 16-entry raw ULA palette register values (lower nibble of &FE21 writes)
* @param {Uint8Array} crtcRegs - CRTC registers (at least 18 bytes)
* @param {number} ic32 - the system VIA's addressable latch, whose screen size bits set the hardware wrap
* @param {Int32Array|null} [nulaCollook] - NULA colour lookup (16 ABGR entries), or null for default BBC palette
* @param {object|null} [crtcCounters] - CRTC counter state {hc, vc, sc, ma, maback}, or null for defaults
*/
export function buildVideoState(ulaControl, ulaPalette, crtcRegs, ic32, nulaCollook, crtcCounters) {
const video = new Video(false, 0, () => {}, { hasVideoNula: true, drainKind: "js" });
for (let reg = 0; reg < CrtcImportedRegisters; reg++) {
video.crtc.write(CrtcAddress, reg);
video.crtc.write(CrtcData, crtcRegs[reg]);
}
video.crtc.write(CrtcAddress, 0);
if (nulaCollook) video.ula.collook.set(nulaCollook);
video.ula.write(UlaControl, ulaControl);
for (let i = 0; i < 16; i++) video.ula.write(UlaPalette, (i << 4) | (ulaPalette[i] & 0x0f));
video.setScreenHwScroll((ic32 >> 4) & 3);
const startAddr = (video.regs[13] | (video.regs[12] << 8)) & 0x3fff;
video.horizCounter = crtcCounters ? crtcCounters.hc : 0;
video.vertCounter = crtcCounters ? crtcCounters.vc : 0;
video.scanlineCounter = crtcCounters ? crtcCounters.sc : 0;
video.addr = crtcCounters ? crtcCounters.ma : startAddr;
video.lineStartAddr = crtcCounters ? crtcCounters.maback : startAddr;
video.nextLineStartAddr = video.lineStartAddr;
video.dispEnabled = EVERYTHINGENABLED;
// The CRTC leaves a skew of 3 (display off) unset; the import has always shown it as 2.
video.displayEnableSkew = Math.min((video.regs[8] & 0x30) >>> 4, MaxDisplayEnableSkew);
return video.snapshotState();
}
/**
* Build a jsbeeb snapshot envelope from parsed emulator components.
* @param {string} importedFrom - source identifier (e.g. "b-em", "beebem-uef")
* @param {string} modelName - jsbeeb model name/synonym
* @param {object} cpuState - parsed CPU state {a, x, y, flags, s, pc, nmi, fe30, fe34}
* @param {Uint8Array} ram - 64KB RAM array
* @param {Uint8Array|null} roms - 256KB sideways ROM/RAM array, or null
* @param {object} sysvia - jsbeeb sys VIA state
* @param {object} uservia - jsbeeb user VIA state
* @param {object} video - jsbeeb video state (from buildVideoState)
* @param {object} soundChip - jsbeeb sound chip state
* @param {object|null} [tube] - jsbeeb tube state, or null if no co-processor was fitted
*/
export function buildSnapshot(
importedFrom,
modelName,
cpuState,
ram,
roms,
sysvia,
uservia,
video,
soundChip,
tube = null,
) {
return {
format: "jsbeeb-snapshot",
version: 3,
model: modelName,
coProcessor: !!tube,
timestamp: new Date().toISOString(),
importedFrom,
state: {
a: cpuState.a,
x: cpuState.x,
y: cpuState.y,
s: cpuState.s,
pc: cpuState.pc,
p: cpuState.flags | 0x30,
nmiLevel: !!cpuState.nmi,
nmiEdge: false,
halted: false,
takeInt: false,
romsel: cpuState.fe30 ?? 0,
acccon: cpuState.fe34 ?? 0,
videoDisplayPage: 0,
currentCycles: 0,
targetCycles: 0,
cycleSeconds: 0,
peripheralCycles: 0,
videoCycles: 0,
music5000PageSel: 0,
ram,
...(roms instanceof Uint8Array ? { roms } : {}),
scheduler: { epoch: 0 },
sysvia,
uservia,
video,
soundChip,
acia: { ...DefaultAcia },
adc: { ...DefaultAdc },
...(tube ? { tube } : {}),
},
};
}
|