// Generates src/machine/chips/mc6847font.ts, the glyphs for the CoCo's video chip. // // The MC6847 has 64 built-in characters (ASCII $40-$5F, then $20-$3F), which is // the same order as the first 64 C64 "screen codes". We take them from the // open-roms character ROM that res/c64/c64.bios already ships (see // res/README.md for where that comes from), so no proprietary font is needed. // // node scripts/gen_mc6847_font.mjs import { readFileSync, writeFileSync } from 'fs'; const rom = readFileSync(new URL('../res/c64/c64.bios', import.meta.url)); // c64.bios = BASIC (8K) + character ROM (4K) + KERNAL (8K) const chargen = rom.subarray(0x2000, 0x2000 + 64 * 8); let out = `// GENERATED by scripts/gen_mc6847_font.mjs -- do not edit. // 64 glyphs x 8 rows, one byte per row, bit 7 = leftmost pixel. // Glyph order is the MC6847's: @ A-Z [ \\ ] ^ _ then space ! " # ... ? export const MC6847_FONT = new Uint8Array([ `; for (let c = 0; c < 64; c++) { const row = Array.from(chargen.subarray(c * 8, c * 8 + 8)).map(b => '0x' + b.toString(16).padStart(2, '0')); out += ' ' + row.join(', ') + ',\n'; } out += ']);\n'; writeFileSync(new URL('../src/machine/chips/mc6847font.ts', import.meta.url), out); console.log('wrote src/machine/chips/mc6847font.ts');