@henols/c64-re-tools 2.4.0-rc.5 → 2.5.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/skills/c64-docs/references/page-types.md +3 -3
- package/skills/c64-docs/references/style.md +3 -1
- package/skills/c64-knowledge/SKILL.md +34 -3
- package/skills/c64-knowledge/scripts/knowledge.ts +64 -1
- package/skills/c64-reverse-engineering/SKILL.md +1 -0
- package/skills/c64-source/SKILL.md +21 -9
- package/skills/c64-source/scripts/lib/export.ts +3 -0
- package/skills/c64-source/scripts/lib/loader.ts +140 -20
- package/skills/c64-source/scripts/lib/source.ts +15 -4
- package/skills/c64-source/scripts/lib/start-screen.asm +139 -0
- package/skills/c64-source/scripts/source.ts +99 -17
- package/skills/c64-unpacker/SKILL.md +3 -2
- package/src/knowledge/conflicts.ts +4 -0
- package/src/knowledge/history.ts +5 -0
- package/src/knowledge/read.ts +55 -2
- package/src/knowledge/schema.ts +32 -2
- package/src/knowledge/text.ts +19 -0
- package/src/knowledge/write.ts +122 -1
package/src/knowledge/write.ts
CHANGED
|
@@ -39,6 +39,9 @@ import {
|
|
|
39
39
|
RELEASE_COLUMNS,
|
|
40
40
|
releaseLabeled,
|
|
41
41
|
SWITCH_COLUMNS,
|
|
42
|
+
START_SCREEN_COLUMNS,
|
|
43
|
+
currentStartScreen,
|
|
44
|
+
startScreenRanges,
|
|
42
45
|
switchNamed,
|
|
43
46
|
coverageRuns,
|
|
44
47
|
resolveRevision,
|
|
@@ -58,6 +61,7 @@ import {
|
|
|
58
61
|
toRelease,
|
|
59
62
|
toSuppression,
|
|
60
63
|
toSwitch,
|
|
64
|
+
toStartScreen,
|
|
61
65
|
toSymbol,
|
|
62
66
|
type CommentRow,
|
|
63
67
|
type CoverageRun,
|
|
@@ -70,10 +74,11 @@ import {
|
|
|
70
74
|
type RegionRow,
|
|
71
75
|
type ReleaseRow,
|
|
72
76
|
type SuppressionRow,
|
|
77
|
+
type StartScreenRow,
|
|
73
78
|
type SwitchRow,
|
|
74
79
|
type SymbolRow,
|
|
75
80
|
} from "./read.ts";
|
|
76
|
-
import { CODE_REGION_TYPES, COMMENT_PLACEMENTS, EVIDENCE_KINDS, MAX_ELEMENT, MODULE_FILE, DEFAULT_SPACE, GENERATED_FILES, isGeneratedFile, isSemantic, MACRO_NAME, MACRO_PARAM, OFF_KINDS, RELEASE_DEFINE, RELEASE_LABEL, SWITCH_KINDS, SWITCH_NAME, NO_ELEMENT_TYPES, OPERAND_SELECTS, POINTER_KIND, REFERENCE_KINDS, REGION_TYPES, SYMBOL_KINDS, type CommentPlacement, type EvidenceKind, type OperandSelect, type Origin, type ReferenceKind, type RegionType, type Space, type SwitchKind, type SymbolKind } from "./schema.ts";
|
|
81
|
+
import { CODE_REGION_TYPES, COMMENT_PLACEMENTS, EVIDENCE_KINDS, MAX_ELEMENT, MODULE_FILE, DEFAULT_SPACE, GENERATED_FILES, isGeneratedFile, isSemantic, MACRO_NAME, MACRO_PARAM, OFF_KINDS, RELEASE_DEFINE, RELEASE_LABEL, START_SCREEN_MODES, START_SCREEN_SWITCH, SWITCH_KINDS, SWITCH_NAME, NO_ELEMENT_TYPES, OPERAND_SELECTS, POINTER_KIND, REFERENCE_KINDS, REGION_TYPES, SYMBOL_KINDS, type CommentPlacement, type EvidenceKind, type OperandSelect, type Origin, type ReferenceKind, type RegionType, type Space, type StartScreenMode, type SwitchKind, type SymbolKind } from "./schema.ts";
|
|
77
82
|
import { newRevisionId, rowId, sqlName } from "./text.ts";
|
|
78
83
|
|
|
79
84
|
/** What a change rests on: a coverage run, a test or another project file with its SHA-256, or a note. */
|
|
@@ -280,6 +285,12 @@ export class Change {
|
|
|
280
285
|
.run(this.#rowId(), row.space, row.label, row.file, row.sha256, row.base ? 1 : 0, row.comment ?? null, row.origin, this.id());
|
|
281
286
|
}
|
|
282
287
|
|
|
288
|
+
insertStartScreen(row: Omit<StartScreenRow, "revision">): void {
|
|
289
|
+
this.#db
|
|
290
|
+
.prepare("INSERT INTO start_screens (id, space, mode, screen, bitmap, charset, colours, colour, border, background, comment, origin, valid_from_revision) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")
|
|
291
|
+
.run(this.#rowId(), row.space, row.mode, row.screen, row.bitmap ?? null, row.charset ?? null, row.colours ?? null, row.colour ?? null, row.border, row.background, row.comment ?? null, row.origin, this.id());
|
|
292
|
+
}
|
|
293
|
+
|
|
283
294
|
insertMacro(row: Omit<MacroRow, "revision">): void {
|
|
284
295
|
this.#db
|
|
285
296
|
.prepare("INSERT INTO macros (id, space, name, params, body, comment, origin, valid_from_revision) VALUES (?, ?, ?, ?, ?, ?, ?, ?)")
|
|
@@ -323,6 +334,7 @@ function describe(conflict: Conflict): string {
|
|
|
323
334
|
const place = (entry: ConflictRow) => {
|
|
324
335
|
if (entry.entity === "macro" || entry.entity === "switch") return entry.row.name;
|
|
325
336
|
if (entry.entity === "release") return entry.row.label;
|
|
337
|
+
if (entry.entity === "start-screen") return formatC64Address(entry.row.screen);
|
|
326
338
|
const row = entry.row as { address?: number; start?: number; end?: number; from?: number };
|
|
327
339
|
if (row.address !== undefined) return formatC64Address(row.address);
|
|
328
340
|
if (row.from !== undefined && entry.entity === "reference") return formatC64Address(row.from);
|
|
@@ -432,6 +444,7 @@ function renameStep(db: DatabaseSync, change: Change, origin: Origin, request: S
|
|
|
432
444
|
throw new Refusal("conflict", `The name ${request.name} already belongs to ${formatC64Address(owner.address)}. Rename or remove that symbol first.`);
|
|
433
445
|
}
|
|
434
446
|
if (switchNamed(db, request.name, space) !== undefined) throw new Refusal("conflict", `${request.name} is the name of a switch. Give the symbol another name.`);
|
|
447
|
+
if (request.name === START_SCREEN_SWITCH) throw new Refusal("conflict", `${START_SCREEN_SWITCH} is the switch of the start screen in the generated source. Give the symbol another name.`);
|
|
435
448
|
const release = request.name.startsWith(RELEASE_DEFINE) ? releaseLabeled(db, request.name.slice(RELEASE_DEFINE.length), space) : undefined;
|
|
436
449
|
if (release !== undefined) throw new Refusal("conflict", `${request.name} builds the release ${release.label}. Give the symbol another name.`);
|
|
437
450
|
if (existing !== undefined) change.close("symbols", "space = ? AND address = ?", space, request.address);
|
|
@@ -945,6 +958,7 @@ function checkSwitch(request: SwitchRequest): void {
|
|
|
945
958
|
checkSpace(request);
|
|
946
959
|
checkSwitchName(request.name);
|
|
947
960
|
if (request.name.startsWith(RELEASE_DEFINE)) throw new Refusal("invalid-input", `A switch name does not start with ${RELEASE_DEFINE}: the build of a release defines ${RELEASE_DEFINE}<label>.`);
|
|
961
|
+
if (request.name === START_SCREEN_SWITCH) throw new Refusal("invalid-input", `${START_SCREEN_SWITCH} is the switch of the start screen in the generated source. Give the switch another name.`);
|
|
948
962
|
checkOneOf(SWITCH_KINDS, request.kind, "kind");
|
|
949
963
|
if (request.default !== undefined && request.default !== 0 && request.default !== 1) throw new Refusal("invalid-input", "default must be 0 or 1.");
|
|
950
964
|
if (OFF_KINDS.includes(request.kind) && request.default === 1) {
|
|
@@ -1050,6 +1064,92 @@ function unreleaseStep(db: DatabaseSync, change: Change, _origin: Origin, reques
|
|
|
1050
1064
|
return { current: null };
|
|
1051
1065
|
}
|
|
1052
1066
|
|
|
1067
|
+
type StartScreenRequest = InSpace & { mode: StartScreenMode; screen: number; bitmap?: number; charset?: number; colours?: number; colour?: number; border: number; background: number; comment?: string };
|
|
1068
|
+
|
|
1069
|
+
/**
|
|
1070
|
+
* The rules of the VIC-II for a start screen: the screen at a 1K step, the
|
|
1071
|
+
* bitmap at an 8K step and the charset at a 2K step, all in one 16K VIC bank,
|
|
1072
|
+
* and no part where the VIC-II reads the character ROM. The colours are RAM
|
|
1073
|
+
* that the loader reads with the I/O area in, so not in $d000-$dfff. Nothing is
|
|
1074
|
+
* in pages 0-3, because the loader writes the entry state there.
|
|
1075
|
+
*/
|
|
1076
|
+
function checkStartScreen(request: StartScreenRequest): void {
|
|
1077
|
+
checkSpace(request);
|
|
1078
|
+
if (spaceOf(request) !== DEFAULT_SPACE) throw new Refusal("invalid-input", "A start screen is only in the space c64.");
|
|
1079
|
+
checkOneOf(START_SCREEN_MODES, request.mode, "mode");
|
|
1080
|
+
checkAddress(request.screen, "screen");
|
|
1081
|
+
for (const key of ["bitmap", "charset", "colours"] as const) if (request[key] !== undefined) checkAddress(request[key], key);
|
|
1082
|
+
for (const key of ["border", "background", "colour"] as const) {
|
|
1083
|
+
const value = request[key];
|
|
1084
|
+
if (value !== undefined && (!Number.isInteger(value) || value < 0 || value > 15)) throw new Refusal("invalid-input", `${key} must be a colour from 0 to 15.`);
|
|
1085
|
+
}
|
|
1086
|
+
if (request.mode === "text") {
|
|
1087
|
+
if (request.charset === undefined || request.bitmap !== undefined) throw new Refusal("invalid-input", "A text start screen has a charset and no bitmap. Give --charset, for example '$1000' for the character ROM in VIC bank 0.");
|
|
1088
|
+
} else if (request.bitmap === undefined || request.charset !== undefined) {
|
|
1089
|
+
throw new Refusal("invalid-input", `A ${request.mode} start screen has a bitmap and no charset. Give --bitmap.`);
|
|
1090
|
+
}
|
|
1091
|
+
if (request.colours !== undefined && request.colour !== undefined) throw new Refusal("invalid-input", "Give the colour RAM as --colours or as --colour, not both.");
|
|
1092
|
+
const colourRam = request.colours !== undefined || request.colour !== undefined;
|
|
1093
|
+
if (request.mode === "hires" && colourRam) throw new Refusal("invalid-input", "A hires bitmap does not use the colour RAM. Remove --colours and --colour.");
|
|
1094
|
+
if (request.mode !== "hires" && !colourRam) throw new Refusal("invalid-input", `A ${request.mode} start screen uses the colour RAM. Give --colours with the address of its 1000 bytes, or --colour with one colour.`);
|
|
1095
|
+
const step = (value: number, size: number, what: string) => {
|
|
1096
|
+
if (value % size !== 0) throw new Refusal("invalid-input", `The VIC-II reads the ${what} only at a step of $${size.toString(16)}: ${formatC64Address(value)} is not at one.`);
|
|
1097
|
+
};
|
|
1098
|
+
step(request.screen, 0x400, "screen");
|
|
1099
|
+
if (request.bitmap !== undefined) step(request.bitmap, 0x2000, "bitmap");
|
|
1100
|
+
if (request.charset !== undefined) step(request.charset, 0x800, "charset");
|
|
1101
|
+
const bank = request.screen >> 14;
|
|
1102
|
+
for (const [what, value] of [["bitmap", request.bitmap], ["charset", request.charset]] as const) {
|
|
1103
|
+
if (value !== undefined && value >> 14 !== bank) throw new Refusal("invalid-input", `The ${what} at ${formatC64Address(value)} is not in the VIC bank of the screen (${formatC64Address(bank << 14)}-${formatC64Address((bank << 14) + 0x3fff)}).`);
|
|
1104
|
+
}
|
|
1105
|
+
for (const { what, range } of startScreenRanges(request)) {
|
|
1106
|
+
if (range.end > 0xffff) throw new Refusal("invalid-input", `The ${what} at ${formatC64Address(range.start)} goes past $ffff.`);
|
|
1107
|
+
if (range.start < 0x0400) throw new Refusal("invalid-input", `The ${what} at ${formatC64Address(range.start)} is in pages 0-3, where the loader writes the entry state.`);
|
|
1108
|
+
if (what === "colours") {
|
|
1109
|
+
if (range.start <= 0xdfff && range.end >= 0xd000) throw new Refusal("invalid-input", `The colours at ${formatC64Address(range.start)} are in $d000-$dfff, where the loader sees the I/O area. Give the RAM address of the 1000 colour bytes.`);
|
|
1110
|
+
continue;
|
|
1111
|
+
}
|
|
1112
|
+
// In VIC banks 0 and 2 the VIC-II reads the character ROM at $1000-$1fff of the bank.
|
|
1113
|
+
const relative = range.start & 0x3fff;
|
|
1114
|
+
if ((bank & 1) === 0 && relative <= 0x1fff && relative + (range.end - range.start) >= 0x1000) {
|
|
1115
|
+
throw new Refusal("invalid-input", `The ${what} at ${formatC64Address(range.start)} is where the VIC-II reads the character ROM ($1000-$1fff of VIC bank ${bank}). Only a text charset at $1000 or $1800 of the bank uses the ROM font.`);
|
|
1116
|
+
}
|
|
1117
|
+
}
|
|
1118
|
+
checkCommentText(request.comment, "A start screen comment");
|
|
1119
|
+
}
|
|
1120
|
+
|
|
1121
|
+
function startScreenStep(db: DatabaseSync, change: Change, origin: Origin, request: StartScreenRequest): Step<StartScreenRow, StartScreenRow> {
|
|
1122
|
+
const space = spaceOf(request);
|
|
1123
|
+
const existing = currentStartScreen(db, space);
|
|
1124
|
+
const comment = request.comment === undefined ? existing?.comment : request.comment.trim();
|
|
1125
|
+
const row: Omit<StartScreenRow, "revision"> = {
|
|
1126
|
+
space,
|
|
1127
|
+
mode: request.mode,
|
|
1128
|
+
screen: request.screen,
|
|
1129
|
+
...(request.bitmap === undefined ? {} : { bitmap: request.bitmap }),
|
|
1130
|
+
...(request.charset === undefined ? {} : { charset: request.charset }),
|
|
1131
|
+
...(request.colours === undefined ? {} : { colours: request.colours }),
|
|
1132
|
+
...(request.colour === undefined ? {} : { colour: request.colour }),
|
|
1133
|
+
border: request.border,
|
|
1134
|
+
background: request.background,
|
|
1135
|
+
...(comment === undefined ? {} : { comment }),
|
|
1136
|
+
origin: origin as StartScreenRow["origin"],
|
|
1137
|
+
};
|
|
1138
|
+
const same = existing !== undefined && KEYS.start_screens.key(existing) === KEYS.start_screens.key({ ...row, origin: existing.origin, revision: "" });
|
|
1139
|
+
if (same && !confirms(existing.origin, origin)) return { current: existing };
|
|
1140
|
+
if (existing !== undefined) change.close("start_screens", "space = ?", space);
|
|
1141
|
+
change.insertStartScreen(row);
|
|
1142
|
+
const current = currentStartScreen(db, space)!;
|
|
1143
|
+
return existing !== undefined && existing.origin !== origin ? { current, previous: existing } : { current };
|
|
1144
|
+
}
|
|
1145
|
+
|
|
1146
|
+
function unstartScreenStep(db: DatabaseSync, change: Change, _origin: Origin, request: InSpace): Step<null> {
|
|
1147
|
+
const space = spaceOf(request);
|
|
1148
|
+
if (currentStartScreen(db, space) === undefined) throw new Refusal("not-found", "The knowledge has no start screen.");
|
|
1149
|
+
change.close("start_screens", "space = ?", space);
|
|
1150
|
+
return { current: null };
|
|
1151
|
+
}
|
|
1152
|
+
|
|
1053
1153
|
type MacroRequest = InSpace & { name: string; params?: string[]; body: string; comment?: string };
|
|
1054
1154
|
|
|
1055
1155
|
function checkMacroName(name: unknown, what = "A macro name"): void {
|
|
@@ -1290,6 +1390,17 @@ export function removeRelease(db: DatabaseSync, context: WriteContext, request:
|
|
|
1290
1390
|
return result(write(db, context, "remove-release", (change) => unreleaseStep(db, change, context.origin, request)));
|
|
1291
1391
|
}
|
|
1292
1392
|
|
|
1393
|
+
/** Writes the start screen of the program: the loader of the generated source shows it before the entry. */
|
|
1394
|
+
export function setStartScreen(db: DatabaseSync, context: WriteContext, request: StartScreenRequest): WriteResult<StartScreenRow, StartScreenRow> {
|
|
1395
|
+
checkStartScreen(request);
|
|
1396
|
+
return result(write(db, context, "set-start-screen", (change) => startScreenStep(db, change, context.origin, request)));
|
|
1397
|
+
}
|
|
1398
|
+
|
|
1399
|
+
export function removeStartScreen(db: DatabaseSync, context: WriteContext, request: InSpace): WriteResult<null> {
|
|
1400
|
+
checkSpace(request);
|
|
1401
|
+
return result(write(db, context, "remove-start-screen", (change) => unstartScreenStep(db, change, context.origin, request)));
|
|
1402
|
+
}
|
|
1403
|
+
|
|
1293
1404
|
/** Writes a macro of the generated source. */
|
|
1294
1405
|
export function setMacro(db: DatabaseSync, context: WriteContext, request: MacroRequest): WriteResult<MacroRow, MacroRow> {
|
|
1295
1406
|
checkMacro(request);
|
|
@@ -1490,6 +1601,12 @@ const KEYS = {
|
|
|
1490
1601
|
map: toRelease,
|
|
1491
1602
|
key: (row: ReleaseRow) => `${row.space}|${row.label}|${row.file}|${row.sha256}|${row.base}|${row.comment ?? ""}|${row.origin}`,
|
|
1492
1603
|
},
|
|
1604
|
+
start_screens: {
|
|
1605
|
+
columns: START_SCREEN_COLUMNS,
|
|
1606
|
+
map: toStartScreen,
|
|
1607
|
+
key: (row: StartScreenRow) =>
|
|
1608
|
+
`${row.space}|${row.mode}|${row.screen}|${row.bitmap ?? ""}|${row.charset ?? ""}|${row.colours ?? ""}|${row.colour ?? ""}|${row.border}|${row.background}|${row.comment ?? ""}|${row.origin}`,
|
|
1609
|
+
},
|
|
1493
1610
|
macros: { columns: MACRO_COLUMNS, map: toMacro, key: (row: MacroRow) => `${row.space}|${row.name}|${listText(row.params)}|${row.body}|${row.comment ?? ""}|${row.origin}` },
|
|
1494
1611
|
macro_uses: { columns: MACRO_USE_COLUMNS, map: toMacroUse, key: (row: MacroUseRow) => `${row.space}|${row.start}|${row.end}|${row.macro}|${listText(row.args)}|${row.origin}` },
|
|
1495
1612
|
suppressions: {
|
|
@@ -1555,6 +1672,10 @@ export function revert(db: DatabaseSync, context: WriteContext, request: { revis
|
|
|
1555
1672
|
change.insertRelease(spec.map(row as never) as ReleaseRow);
|
|
1556
1673
|
continue;
|
|
1557
1674
|
}
|
|
1675
|
+
if (table === "start_screens") {
|
|
1676
|
+
change.insertStartScreen(spec.map(row as never) as StartScreenRow);
|
|
1677
|
+
continue;
|
|
1678
|
+
}
|
|
1558
1679
|
if (table === "macro_uses") {
|
|
1559
1680
|
change.insertMacroUse(spec.map(row as never) as MacroUseRow);
|
|
1560
1681
|
continue;
|