Fix register parsing (VICE binary protocol v2 format), getDisplay ensureStopped race, getPalette missing VC body

This commit is contained in:
Mattias Hansson 2026-07-19 22:54:38 +02:00
parent d06d2ef71d
commit 1bea1deba9
2 changed files with 19 additions and 17 deletions

View file

@ -378,17 +378,19 @@ Related tools: setRegister, step, continue, status`,
};
for (let i = 0; i < count && offset < response.body.length; i++) {
const itemSize = response.body[offset];
offset += 1;
const id = response.body[offset];
const size = response.body[offset + 1];
offset += 2;
offset += 1;
const valueSize = itemSize - 1;
let value = 0;
if (size === 1) {
if (valueSize === 1) {
value = response.body[offset];
} else if (size === 2) {
} else if (valueSize === 2) {
value = response.body.readUInt16LE(offset);
}
offset += size;
offset += valueSize;
const name = regNames[id] || `R${id}`;
registers[name] = value;
@ -500,14 +502,15 @@ Related tools: getRegisters, continue, setBreakpoint, status`,
let pc = 0;
for (let i = 0; i < count && offset < regResponse.body.length; i++) {
const itemSize = regResponse.body[offset];
offset += 1;
const id = regResponse.body[offset];
const size = regResponse.body[offset + 1];
offset += 2;
if (id === 3 && size === 2) {
offset += 1;
if (id === 3) {
// PC
pc = regResponse.body.readUInt16LE(offset);
}
offset += size;
offset += itemSize - 1;
}
return formatResponse({
@ -880,14 +883,15 @@ Related tools: readMemory, getRegisters, step`,
const count = regResponse.body.readUInt16LE(0);
let offset = 2;
for (let i = 0; i < count && offset < regResponse.body.length; i++) {
const itemSize = regResponse.body[offset];
offset += 1;
const id = regResponse.body[offset];
const size = regResponse.body[offset + 1];
offset += 2;
if (id === 3 && size === 2) {
offset += 1;
if (id === 3) {
startAddress = regResponse.body.readUInt16LE(offset);
break;
}
offset += size;
offset += itemSize - 1;
}
startAddress = startAddress ?? 0;
}

View file

@ -730,9 +730,6 @@ export class ViceClient {
innerHeight: number;
pixels: Buffer;
}> {
// Ensure VICE is stopped before display capture
await this.ensureStopped();
// Body: useVicii(1) + format(1)
// Format: 0 = indexed 8-bit
const body = Buffer.alloc(2);
@ -770,7 +767,8 @@ export class ViceClient {
// Get palette (color table)
async getPalette(): Promise<Array<{ r: number; g: number; b: number }>> {
const response = await this.sendCommand(Command.PaletteGet);
// VICE 3.6+ expects 1-byte body (useVIC flag), not empty
const response = await this.sendCommand(Command.PaletteGet, Buffer.from([1]));
// Parse response
// Response: count(2) + [r(1) + g(1) + b(1)]...