diff --git a/src/index.ts b/src/index.ts index 3e159a4..8c0ba7d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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; } diff --git a/src/protocol/client.ts b/src/protocol/client.ts index 9f71b86..d77409b 100644 --- a/src/protocol/client.ts +++ b/src/protocol/client.ts @@ -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> { - 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)]...