Files
kurogedelic 5684e187b0 Felucca 0.8-beta source
Firmware, update loader, build tools, assets, web installer and editor,
host tests. Four tracks (three synth parts and a drum track), user presets
with live editor sync (protocol v2), editor protocol v3 (tracks), the
command-line installer tools/fm1_install.py.
2026-10-03 16:06:39 +09:00

27 lines
1000 B
JavaScript

// SPDX-License-Identifier: GPL-3.0-only
// Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments
//
// FM-1 .fwsc packages in the browser: the package identity and the image the
// device reads during an update.
const BLOCKS = 20, BLK = 0x30, KEEP = 0x2F;
// the package identity ("FM-1_904"): one marker byte after each of the first 20 blocks
export function productOf(fwsc) {
if (fwsc.length < BLOCKS * BLK) throw new Error("not an FM-1 package (too short)");
let s = "";
for (let i = 0; i < BLOCKS; i++) {
const m = fwsc[i * BLK + KEEP];
if (m !== 0x7D) s += String.fromCharCode((m - i - 1) & 0xFF);
}
return s;
}
// the image the device addresses during an update: the .fwsc without the 20 marker bytes
export function logicalImage(fwsc) {
const out = new Uint8Array(fwsc.length - BLOCKS);
for (let i = 0; i < BLOCKS; i++) out.set(fwsc.subarray(i * BLK, i * BLK + KEEP), i * KEEP);
out.set(fwsc.subarray(BLOCKS * BLK), BLOCKS * KEEP);
return out;
}