@henols/c64-re-tools 2.5.1-rc.2 → 2.6.0-rc.10
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 +2 -2
- package/skills/c64-assembler/SKILL.md +26 -12
- package/skills/c64-assembler/scripts/assembler.ts +25 -13
- package/skills/c64-development/SKILL.md +2 -2
- package/skills/c64-docs/SKILL.md +4 -4
- package/skills/c64-docs/scripts/docs.ts +7 -7
- package/skills/c64-docs/scripts/lib/reference.ts +3 -3
- package/skills/c64-docs/scripts/lib/source-map.ts +9 -4
- package/skills/c64-knowledge/SKILL.md +29 -20
- package/skills/c64-knowledge/scripts/knowledge.ts +33 -39
- package/skills/c64-knowledge/scripts/lib/listing.ts +18 -3
- package/skills/c64-packer/SKILL.md +1 -1
- package/skills/c64-provenance/SKILL.md +11 -10
- package/skills/c64-provenance/scripts/lib/library.ts +16 -16
- package/skills/c64-provenance/scripts/provenance.ts +33 -23
- package/skills/c64-reverse-engineering/SKILL.md +16 -10
- package/skills/c64-source/SKILL.md +60 -42
- package/skills/c64-source/scripts/lib/export.ts +76 -32
- package/skills/c64-source/scripts/lib/loader.ts +26 -7
- package/skills/c64-source/scripts/lib/source.ts +21 -24
- package/skills/c64-source/scripts/lib/stage.ts +6 -5
- package/skills/c64-source/scripts/source.ts +213 -106
- package/skills/c64-static-analysis/SKILL.md +7 -5
- package/skills/c64-static-analysis/scripts/lib/coverage.ts +2 -25
- package/skills/c64-static-analysis/scripts/lib/instructions.ts +22 -20
- package/skills/c64-static-analysis/scripts/static-analysis.ts +36 -43
- package/skills/c64-testing/SKILL.md +5 -2
- package/skills/c64-testing/references/recording-format.md +18 -3
- package/skills/c64-testing/references/scenario-format.md +7 -6
- package/skills/c64-testing/scripts/lib/diff-files.ts +4 -18
- package/skills/c64-testing/scripts/lib/play.ts +39 -41
- package/skills/c64-testing/scripts/lib/recording.ts +46 -37
- package/skills/c64-testing/scripts/lib/replay.ts +1 -1
- package/skills/c64-testing/scripts/lib/runs.ts +2 -2
- package/skills/c64-testing/scripts/lib/scenario.ts +17 -10
- package/skills/c64-unpacker/SKILL.md +4 -1
- package/skills/c64-unpacker/scripts/lib/loads.ts +34 -13
- package/skills/c64-unpacker/scripts/unpacker.ts +5 -3
- package/skills/emulator/SKILL.md +7 -12
- package/src/build-name.ts +50 -0
- package/src/c64-keys.ts +98 -0
- package/src/c64.ts +20 -0
- package/src/cli/main.ts +3 -29
- package/src/host/main.ts +1 -1
- package/src/host/tools/index.ts +1 -6
- package/src/host/vice/session.ts +88 -9
- package/src/host-client/steps.ts +17 -17
- package/src/host-client/tools.ts +2 -7
- package/src/host-client/vice-session.ts +7 -1
- package/src/knowledge/program.ts +44 -1
- package/src/knowledge/read.ts +28 -8
- package/src/knowledge/schema.ts +33 -9
- package/src/knowledge/start-screen.ts +4 -0
- package/src/knowledge/text.ts +4 -2
- package/src/knowledge/write.ts +59 -25
- package/src/mcp/inputs.ts +12 -0
- package/src/mcp/server.ts +1 -1
- package/src/mcp/tools/input.ts +38 -5
- package/src/mcp/tools/machine.ts +3 -42
- package/src/mcp/tools/media.ts +1 -1
- package/src/native/acme.ts +1 -1
- package/src/native/c64run.ts +1 -1
- package/src/native/discover.ts +3 -3
- package/src/native/dxa.ts +12 -1
- package/src/native/ghidra/analyze.ts +74 -63
- package/src/native/ghidra/c64rt-wasm.ts +4 -0
- package/src/native/ghidra/language/c64rt_6510.sla +0 -0
- package/src/native/ghidra/pcode.ts +222 -0
- package/src/native/ghidra/walk.ts +205 -0
- package/src/native/ghidra/wasm.ts +98 -0
- package/src/native/processes.ts +4 -4
- package/src/native/types.ts +2 -2
- package/src/platform.ts +30 -1
- package/src/project.ts +17 -4
- package/src/protocol/tools.ts +1 -45
- package/src/protocol/vice.ts +47 -0
- package/src/script.ts +1 -1
- package/src/vsf.ts +98 -0
- package/tools/c64run.c +9 -12
- package/tools/install-container.sh +1 -2
- package/src/cli/status.ts +0 -127
- package/src/host/tools/status.ts +0 -47
- package/src/native/ghidra/index.ts +0 -170
- package/src/native/ghidra/scripts/C64Export.java +0 -274
- package/src/native/ghidra/scripts/C64Prepare.java +0 -66
- package/src/native/status.ts +0 -135
- package/tools/install-ghidra.sh +0 -40
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
// one VICE. Exposes C64-domain operations only.
|
|
3
3
|
|
|
4
4
|
import { ProtocolError, WireFailure, type VideoStandard } from "../protocol/messages.ts";
|
|
5
|
-
import { MAX_MEMORY_READ, traceHitsFromAttachment, validateViceResult, type TraceResult, type Breakpoint, type BreakpointParams, type PointRemoved, type Watchpoint, type WatchpointParams, type ExecutionParams, type ExecutionResult, type JoystickState, type MachineStatus, type MemmapRange, type MemoryWriteParams, type ProfileEntry, type RegisterValues, type ResetMode, type RunState, type RunTarget, type RunUntilResult, type MemoryReadParams, type MemoryReadResult, type Registers, type Space, type ViceOperation, type ViceOperations } from "../protocol/vice.ts";
|
|
5
|
+
import { MAX_MEMORY_READ, traceHitsFromAttachment, validateViceResult, type TraceResult, type Breakpoint, type BreakpointParams, type PointRemoved, type Watchpoint, type WatchpointParams, type ExecutionParams, type ExecutionResult, type JoystickState, type MachineStatus, type PressResult, type MemmapRange, type MemoryWriteParams, type ProfileEntry, type RegisterValues, type ResetMode, type RunState, type RunTarget, type RunUntilResult, type MemoryReadParams, type MemoryReadResult, type Registers, type Space, type ViceOperation, type ViceOperations } from "../protocol/vice.ts";
|
|
6
|
+
import type { KeyTap } from "../c64-keys.ts";
|
|
6
7
|
import { HostConnection } from "./connect.ts";
|
|
7
8
|
import { readProjectFile } from "./transfer.ts";
|
|
8
9
|
|
|
@@ -158,6 +159,11 @@ export class ViceSessionClient {
|
|
|
158
159
|
return this.#request("joystick", state);
|
|
159
160
|
}
|
|
160
161
|
|
|
162
|
+
/** Presses keys of the keyboard matrix and RESTORE: each tap holds its keys `frames` frames, then waits `frames` frames with all keys up. */
|
|
163
|
+
press(taps: KeyTap[], frames: number): Promise<PressResult> {
|
|
164
|
+
return this.#request("press", { taps, frames });
|
|
165
|
+
}
|
|
166
|
+
|
|
161
167
|
/** Action list gives all breakpoints, remove gives `{removed, id}`; add, enable and disable give the one breakpoint. */
|
|
162
168
|
breakpoint(params: Extract<BreakpointParams, { action: "list" }>): Promise<{ breakpoints: Breakpoint[] }>;
|
|
163
169
|
breakpoint(params: Extract<BreakpointParams, { action: "remove" }>): Promise<PointRemoved>;
|
package/src/knowledge/program.ts
CHANGED
|
@@ -11,7 +11,7 @@ import { type AddressRange, COVERAGE, formatC64Address } from "../c64.ts";
|
|
|
11
11
|
|
|
12
12
|
import { COVERAGE_KINDS, DEFAULT_SPACE, MEMORY_ROW, type CoverageKind, type Space } from "./schema.ts";
|
|
13
13
|
import { coverageRuns } from "./read.ts";
|
|
14
|
-
import { checkSpace, write, type Evidence, type WriteContext } from "./write.ts";
|
|
14
|
+
import { checkSpace, write, type Evidence, type OperandImage, type WriteContext } from "./write.ts";
|
|
15
15
|
|
|
16
16
|
/** The 64 KiB of one space: offset n is address n. */
|
|
17
17
|
const SIZE = 0x10000;
|
|
@@ -278,3 +278,46 @@ export function programCoverage(db: DatabaseSync | undefined, space: Space = DEF
|
|
|
278
278
|
}
|
|
279
279
|
return { map, selfModified };
|
|
280
280
|
}
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* The program of each space in the knowledge that operand, patch and macro
|
|
284
|
+
* use writes in that space are checked against, with the platform names. A
|
|
285
|
+
* byte outside the segments of the program is not in it. Each program is
|
|
286
|
+
* read once, when a write in its space needs it.
|
|
287
|
+
*/
|
|
288
|
+
export function operandImages(db: DatabaseSync, platform: ReadonlyMap<string, number>): (space: string) => OperandImage {
|
|
289
|
+
const images = new Map<string, OperandImage>();
|
|
290
|
+
return (space) => {
|
|
291
|
+
const known = images.get(space);
|
|
292
|
+
if (known !== undefined) return known;
|
|
293
|
+
const image = requireProgram(db, space);
|
|
294
|
+
const inside = (at: number) => image.segments.some((segment) => at >= segment.start && at <= segment.end);
|
|
295
|
+
const made: OperandImage = { byteAt: (at) => (inside(at) ? image.byteAt(at) : undefined), platform };
|
|
296
|
+
images.set(space, made);
|
|
297
|
+
return made;
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
* The bytes of a release: the program for the base release, else the bytes
|
|
303
|
+
* that the knowledge keeps for the release. Undefined when the space has no
|
|
304
|
+
* release with this label.
|
|
305
|
+
*/
|
|
306
|
+
export function releaseImage(db: DatabaseSync | undefined, label: string, space: Space = DEFAULT_SPACE): Pick<ProgramImage, "segments" | "byteAt"> | undefined {
|
|
307
|
+
if (db === undefined) return undefined;
|
|
308
|
+
const release = db.prepare("SELECT base FROM current_releases WHERE space = ? AND label = ?").get(space, label) as { base: number } | undefined;
|
|
309
|
+
if (release === undefined) return undefined;
|
|
310
|
+
if (release.base === 1) return programImage(db, space);
|
|
311
|
+
const rows = db.prepare("SELECT address, bytes FROM current_release_memory WHERE space = ? AND label = ? ORDER BY address").all(space, label) as Array<{ address: number; bytes: string }>;
|
|
312
|
+
const memory = new Uint8Array(SIZE);
|
|
313
|
+
const segments: AddressRange[] = [];
|
|
314
|
+
for (const row of rows) {
|
|
315
|
+
const bytes = Buffer.from(row.bytes, "hex");
|
|
316
|
+
memory.set(bytes, row.address);
|
|
317
|
+
const end = row.address + bytes.length - 1;
|
|
318
|
+
const last = segments.at(-1);
|
|
319
|
+
if (last !== undefined && last.end + 1 === row.address) last.end = end;
|
|
320
|
+
else segments.push({ start: row.address, end });
|
|
321
|
+
}
|
|
322
|
+
return { segments, byteAt: (address) => memory[address]! };
|
|
323
|
+
}
|
package/src/knowledge/read.ts
CHANGED
|
@@ -7,7 +7,7 @@ import type { DatabaseSync } from "node:sqlite";
|
|
|
7
7
|
import type { AddressRange } from "../c64.ts";
|
|
8
8
|
import { Refusal } from "../errors.ts";
|
|
9
9
|
import { DEFAULT_SPACE, type CommentPlacement, type OperandSelect, type Origin, type ReferenceKind, type RegionType, type Space, type StartScreenMode, type SuppressionEntity, type SwitchKind, type SymbolKind } from "./schema.ts";
|
|
10
|
-
import { NO_REVISION } from "./text.ts";
|
|
10
|
+
import { compareText, NO_REVISION, sqlName, TABLES } from "./text.ts";
|
|
11
11
|
|
|
12
12
|
export interface SymbolRow {
|
|
13
13
|
space: Space;
|
|
@@ -114,12 +114,10 @@ export interface SwitchRow {
|
|
|
114
114
|
revision: string;
|
|
115
115
|
}
|
|
116
116
|
|
|
117
|
-
/** A release of the program
|
|
117
|
+
/** A release of the program, and whether its bytes are the program of the knowledge. The bytes of another release are in release_memory. */
|
|
118
118
|
export interface ReleaseRow {
|
|
119
119
|
space: Space;
|
|
120
120
|
label: string;
|
|
121
|
-
file: string;
|
|
122
|
-
sha256: string;
|
|
123
121
|
base: boolean;
|
|
124
122
|
comment?: string;
|
|
125
123
|
origin: Extract<Origin, "user" | "llm">;
|
|
@@ -201,7 +199,7 @@ export const MODULE_COLUMNS = "space, start_address, file, title, origin, valid_
|
|
|
201
199
|
export const OPERAND_COLUMNS = "space, address, selector, symbol, offset, expression, origin, valid_from_revision";
|
|
202
200
|
export const PATCH_COLUMNS = "space, start_address, end_address, switch_name, code, comment, origin, valid_from_revision";
|
|
203
201
|
export const SWITCH_COLUMNS = "space, name, kind, default_value, releases, comment, origin, valid_from_revision";
|
|
204
|
-
export const RELEASE_COLUMNS = "space, label,
|
|
202
|
+
export const RELEASE_COLUMNS = "space, label, base, comment, origin, valid_from_revision";
|
|
205
203
|
export const MACRO_COLUMNS = "space, name, params, body, comment, origin, valid_from_revision";
|
|
206
204
|
export const MACRO_USE_COLUMNS = "space, start_address, end_address, macro, args, origin, valid_from_revision";
|
|
207
205
|
export const START_SCREEN_COLUMNS = "space, mode, screen, bitmap, charset, colours, colour, border, background, stage, call_address, colour_ram, comment, origin, valid_from_revision";
|
|
@@ -304,8 +302,6 @@ export function toRelease(row: Raw): ReleaseRow {
|
|
|
304
302
|
const release: ReleaseRow = {
|
|
305
303
|
space: row.space as Space,
|
|
306
304
|
label: row.label as string,
|
|
307
|
-
file: row.file as string,
|
|
308
|
-
sha256: row.sha256 as string,
|
|
309
305
|
base: row.base === 1,
|
|
310
306
|
origin: row.origin as ReleaseRow["origin"],
|
|
311
307
|
revision: row.valid_from_revision as string,
|
|
@@ -356,6 +352,30 @@ export function currentRevision(db: DatabaseSync | undefined): string {
|
|
|
356
352
|
return (db.prepare("SELECT max(id) AS id FROM revisions").get() as { id: string | null }).id ?? "0";
|
|
357
353
|
}
|
|
358
354
|
|
|
355
|
+
/**
|
|
356
|
+
* The newest revision that changed a row in one of `spaces`, or the revision
|
|
357
|
+
* of no knowledge when none did. A change in another space does not change it.
|
|
358
|
+
*/
|
|
359
|
+
export function spacesRevision(db: DatabaseSync | undefined, spaces: readonly Space[]): string {
|
|
360
|
+
if (db === undefined || spaces.length === 0) return NO_REVISION;
|
|
361
|
+
const marks = spaces.map(() => "?").join(", ");
|
|
362
|
+
let newest = NO_REVISION;
|
|
363
|
+
for (const spec of TABLES) {
|
|
364
|
+
const row = db.prepare(`SELECT max(valid_from_revision) AS added, max(valid_to_revision) AS closed FROM ${sqlName(spec.table)} WHERE space IN (${marks})`).get(...spaces) as { added: string | null; closed: string | null };
|
|
365
|
+
for (const id of [row.added, row.closed]) if (id !== null && compareText(id, newest) > 0) newest = id;
|
|
366
|
+
}
|
|
367
|
+
return newest;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
/**
|
|
371
|
+
* The revision of the source of a space: the newest revision of that space and
|
|
372
|
+
* of the stage of its start screen. A change in another space does not change it.
|
|
373
|
+
*/
|
|
374
|
+
export function sourceRevision(db: DatabaseSync | undefined, space: Space = DEFAULT_SPACE): string {
|
|
375
|
+
const stage = space === DEFAULT_SPACE ? currentStartScreen(db, space)?.stage : undefined;
|
|
376
|
+
return spacesRevision(db, [space, ...(stage === undefined ? [] : [stage])]);
|
|
377
|
+
}
|
|
378
|
+
|
|
359
379
|
/** One import of a coverage map: its project path, its SHA-256, the space it went into and the revision. */
|
|
360
380
|
export interface CoverageRun {
|
|
361
381
|
name: string;
|
|
@@ -523,7 +543,7 @@ export function moduleAt(db: DatabaseSync | undefined, start: number, space: Spa
|
|
|
523
543
|
}
|
|
524
544
|
|
|
525
545
|
export function moduleWithFile(db: DatabaseSync | undefined, file: string, space: Space = DEFAULT_SPACE): ModuleRow | undefined {
|
|
526
|
-
const row = db?.prepare(`SELECT ${MODULE_COLUMNS} FROM current_modules WHERE space = ? AND file =
|
|
546
|
+
const row = db?.prepare(`SELECT ${MODULE_COLUMNS} FROM current_modules WHERE space = ? AND file = ? COLLATE NOCASE`).get(space, file) as Raw | undefined;
|
|
527
547
|
return row === undefined ? undefined : toModule(row);
|
|
528
548
|
}
|
|
529
549
|
|
package/src/knowledge/schema.ts
CHANGED
|
@@ -56,8 +56,12 @@ export { OPERAND_SELECTS, type OperandSelect } from "./expression.ts";
|
|
|
56
56
|
export const SUPPRESSION_ENTITIES = ["symbol", "region", "reference"] as const;
|
|
57
57
|
export type SuppressionEntity = (typeof SUPPRESSION_ENTITIES)[number];
|
|
58
58
|
|
|
59
|
-
/**
|
|
60
|
-
|
|
59
|
+
/**
|
|
60
|
+
* A module file of the generated source: a name that ends in .asm, in the
|
|
61
|
+
* source folder or in one folder of it, for example music/driver.asm. A folder
|
|
62
|
+
* name is lower case, so two modules cannot differ only in its letter case.
|
|
63
|
+
*/
|
|
64
|
+
export const MODULE_FILE = /^(?:[a-z0-9_][a-z0-9_-]{0,29}\/)?[A-Za-z0-9_][A-Za-z0-9_-]{0,59}\.asm$/;
|
|
61
65
|
/** A switch of the generated source: upper case, so it reads as a build option and not as a label. */
|
|
62
66
|
export const SWITCH_NAME = /^[A-Z][A-Z0-9_]{1,31}$/;
|
|
63
67
|
/** A release label: the switch-name form. The build of a release defines RELEASE_<label>. */
|
|
@@ -100,12 +104,22 @@ export const MEMORY_ROW = 64;
|
|
|
100
104
|
/** Files that c64-source writes itself: no module can have these names. */
|
|
101
105
|
export const GENERATED_FILES = ["main.asm", "loader.asm", "switches.asm", "config.asm", "constants.asm", "macros.asm", "start_screen.asm"] as const;
|
|
102
106
|
|
|
103
|
-
/** The
|
|
104
|
-
export const
|
|
107
|
+
/** The folder of the leftovers in the generated source: leftovers/leftover_xxxx.asm. */
|
|
108
|
+
export const LEFTOVER_FOLDER = "leftovers";
|
|
109
|
+
/** The folder of the parts of segments that no module holds: segments/segment_xxxx.asm. */
|
|
110
|
+
export const SEGMENT_FOLDER = "segments";
|
|
111
|
+
/** The folders that c64-source writes itself: no module file is in them. */
|
|
112
|
+
export const GENERATED_FOLDERS = [LEFTOVER_FOLDER, SEGMENT_FOLDER] as const;
|
|
105
113
|
|
|
106
|
-
/**
|
|
114
|
+
/**
|
|
115
|
+
* True for a generated file name in any letter case (the file systems of macOS
|
|
116
|
+
* and Windows ignore case), also in a folder: a folder with a generated
|
|
117
|
+
* main.asm is the source of another space, not a folder of modules.
|
|
118
|
+
*/
|
|
107
119
|
export function isGeneratedFile(file: string): boolean {
|
|
108
|
-
|
|
120
|
+
const lower = file.toLowerCase();
|
|
121
|
+
const name = lower.slice(lower.lastIndexOf("/") + 1);
|
|
122
|
+
return (GENERATED_FILES as readonly string[]).includes(name) || GENERATED_FOLDERS.some((folder) => lower.startsWith(`${folder}/`));
|
|
109
123
|
}
|
|
110
124
|
|
|
111
125
|
/**
|
|
@@ -287,8 +301,6 @@ function createSchema(db: DatabaseSync): void {
|
|
|
287
301
|
id TEXT PRIMARY KEY,
|
|
288
302
|
space TEXT NOT NULL DEFAULT 'c64' CHECK (${SPACE_CHECK}),
|
|
289
303
|
label TEXT NOT NULL CHECK (length(label) > 0),
|
|
290
|
-
file TEXT NOT NULL CHECK (length(file) > 0),
|
|
291
|
-
sha256 TEXT NOT NULL CHECK (length(sha256) = 64),
|
|
292
304
|
base INTEGER NOT NULL CHECK (base IN (0, 1)),
|
|
293
305
|
comment TEXT CHECK (comment IS NULL OR length(comment) > 0),
|
|
294
306
|
origin TEXT NOT NULL CHECK (origin IN ('user', 'llm')),
|
|
@@ -356,6 +368,17 @@ function createSchema(db: DatabaseSync): void {
|
|
|
356
368
|
valid_to_revision TEXT REFERENCES revisions (id)
|
|
357
369
|
);
|
|
358
370
|
CREATE INDEX memory_current ON memory (space, address) WHERE valid_to_revision IS NULL;
|
|
371
|
+
CREATE TABLE release_memory (
|
|
372
|
+
id TEXT PRIMARY KEY,
|
|
373
|
+
space TEXT NOT NULL DEFAULT 'c64' CHECK (${SPACE_CHECK}),
|
|
374
|
+
label TEXT NOT NULL CHECK (length(label) > 0),
|
|
375
|
+
address INTEGER NOT NULL CHECK (address BETWEEN 0 AND 65535),
|
|
376
|
+
bytes TEXT NOT NULL CHECK (length(bytes) BETWEEN 2 AND ${MEMORY_ROW * 2} AND length(bytes) % 2 = 0 AND address + length(bytes) / 2 <= 65536),
|
|
377
|
+
origin TEXT NOT NULL CHECK (origin IN ('user', 'llm')),
|
|
378
|
+
valid_from_revision TEXT NOT NULL REFERENCES revisions (id),
|
|
379
|
+
valid_to_revision TEXT REFERENCES revisions (id)
|
|
380
|
+
);
|
|
381
|
+
CREATE INDEX release_memory_current ON release_memory (space, label, address) WHERE valid_to_revision IS NULL;
|
|
359
382
|
CREATE TABLE entries (
|
|
360
383
|
id TEXT PRIMARY KEY,
|
|
361
384
|
space TEXT NOT NULL DEFAULT 'c64' CHECK (${SPACE_CHECK}),
|
|
@@ -379,6 +402,7 @@ function createSchema(db: DatabaseSync): void {
|
|
|
379
402
|
);
|
|
380
403
|
CREATE INDEX coverage_current ON coverage (space, kind) WHERE valid_to_revision IS NULL;
|
|
381
404
|
CREATE VIEW current_memory AS SELECT * FROM memory WHERE valid_to_revision IS NULL;
|
|
405
|
+
CREATE VIEW current_release_memory AS SELECT * FROM release_memory WHERE valid_to_revision IS NULL;
|
|
382
406
|
CREATE VIEW current_entries AS SELECT * FROM entries WHERE valid_to_revision IS NULL;
|
|
383
407
|
CREATE VIEW current_coverage AS SELECT * FROM coverage WHERE valid_to_revision IS NULL;
|
|
384
408
|
CREATE VIEW current_symbols AS SELECT * FROM symbols WHERE valid_to_revision IS NULL;
|
|
@@ -399,7 +423,7 @@ function createSchema(db: DatabaseSync): void {
|
|
|
399
423
|
}
|
|
400
424
|
|
|
401
425
|
/** The version of the index this build makes. An index with another version is emptied and made again. */
|
|
402
|
-
export const INDEX_VERSION =
|
|
426
|
+
export const INDEX_VERSION = 14;
|
|
403
427
|
|
|
404
428
|
function indexVersion(db: DatabaseSync): number | undefined {
|
|
405
429
|
const hasMeta = db.prepare("SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = 'meta'").get();
|
|
@@ -6,6 +6,10 @@
|
|
|
6
6
|
import { Refusal } from "../errors.ts";
|
|
7
7
|
import type { StartScreenMode } from "./schema.ts";
|
|
8
8
|
|
|
9
|
+
/** The labels of the start screen in a generated loader: its wait for a key or a fire button, and the code after the wait. */
|
|
10
|
+
export const START_SCREEN_WAIT = "loader_start_screen_wait";
|
|
11
|
+
export const START_SCREEN_CONTINUE = "loader_start_screen_continue";
|
|
12
|
+
|
|
9
13
|
/** The fields of a start screen that the capture of a stage gives. */
|
|
10
14
|
export interface StageScreen {
|
|
11
15
|
mode: StartScreenMode;
|
package/src/knowledge/text.ts
CHANGED
|
@@ -166,12 +166,12 @@ export const TABLES: readonly TableSpec[] = [
|
|
|
166
166
|
origin,
|
|
167
167
|
],
|
|
168
168
|
},
|
|
169
|
-
// The releases of the program
|
|
169
|
+
// The releases of the program, and the one whose bytes are the program. The bytes of the other releases are in release_memory.jsonl.
|
|
170
170
|
{
|
|
171
171
|
table: "releases",
|
|
172
172
|
file: "releases.jsonl",
|
|
173
173
|
sort: "label",
|
|
174
|
-
fields: [space, field("label", "label", "text"), field("
|
|
174
|
+
fields: [space, field("label", "label", "text"), field("base", "base", "integer"), field("comment", "comment", "text", true), origin],
|
|
175
175
|
},
|
|
176
176
|
{
|
|
177
177
|
table: "macros",
|
|
@@ -209,6 +209,8 @@ export const TABLES: readonly TableSpec[] = [
|
|
|
209
209
|
},
|
|
210
210
|
// The program itself: its bytes, at most 64 to a row, so a changed byte changes one line.
|
|
211
211
|
{ table: "memory", file: "memory.jsonl", sort: "address", fields: [space, field("at", "address", "address"), field("bytes", "bytes", "hex"), origin] },
|
|
212
|
+
// The bytes of each release other than the base release, as the bytes of the program.
|
|
213
|
+
{ table: "release_memory", file: "release_memory.jsonl", sort: "address", fields: [space, field("label", "label", "text"), field("at", "address", "address"), field("bytes", "bytes", "hex"), origin] },
|
|
212
214
|
// Where the program starts, the machine state there, and the stages of its unpacker.
|
|
213
215
|
{
|
|
214
216
|
table: "entries",
|
package/src/knowledge/write.ts
CHANGED
|
@@ -78,7 +78,7 @@ import {
|
|
|
78
78
|
type SwitchRow,
|
|
79
79
|
type SymbolRow,
|
|
80
80
|
} from "./read.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, LEFTOVERS_SWITCH, 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";
|
|
81
|
+
import { CODE_REGION_TYPES, COMMENT_PLACEMENTS, EVIDENCE_KINDS, MAX_ELEMENT, MEMORY_ROW, MODULE_FILE, DEFAULT_SPACE, GENERATED_FILES, GENERATED_FOLDERS, isGeneratedFile, isSemantic, MACRO_NAME, MACRO_PARAM, OFF_KINDS, RELEASE_DEFINE, RELEASE_LABEL, LEFTOVERS_SWITCH, 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";
|
|
82
82
|
import { newRevisionId, rowId, sqlName } from "./text.ts";
|
|
83
83
|
|
|
84
84
|
/** What a change rests on: a coverage run, a test or another project file with its SHA-256, or a note. */
|
|
@@ -99,8 +99,8 @@ export interface WriteContext {
|
|
|
99
99
|
expectedRevision?: string;
|
|
100
100
|
/** Kept with the revision when the write changes something. */
|
|
101
101
|
evidence?: Evidence[];
|
|
102
|
-
/** The image that an operand, patch or macro use write is checked against. */
|
|
103
|
-
image?: OperandImage;
|
|
102
|
+
/** The image of a space that an operand, patch or macro use write in that space is checked against. */
|
|
103
|
+
image?: (space: Space) => OperandImage;
|
|
104
104
|
}
|
|
105
105
|
|
|
106
106
|
/** The bytes of the image and the platform names (C64 space only) that operand expressions, patches and macro uses are checked against. */
|
|
@@ -281,8 +281,15 @@ export class Change {
|
|
|
281
281
|
|
|
282
282
|
insertRelease(row: Omit<ReleaseRow, "revision">): void {
|
|
283
283
|
this.#db
|
|
284
|
-
.prepare("INSERT INTO releases (id, space, label,
|
|
285
|
-
.run(this.#rowId(), row.space, row.label, row.
|
|
284
|
+
.prepare("INSERT INTO releases (id, space, label, base, comment, origin, valid_from_revision) VALUES (?, ?, ?, ?, ?, ?, ?)")
|
|
285
|
+
.run(this.#rowId(), row.space, row.label, row.base ? 1 : 0, row.comment ?? null, row.origin, this.id());
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
/** Bytes of a release other than the base release, as a memory row of the program holds them. */
|
|
289
|
+
insertReleaseMemory(row: { space: Space; label: string; address: number; bytes: string; origin: Origin }): void {
|
|
290
|
+
this.#db
|
|
291
|
+
.prepare("INSERT INTO release_memory (id, space, label, address, bytes, origin, valid_from_revision) VALUES (?, ?, ?, ?, ?, ?, ?)")
|
|
292
|
+
.run(this.#rowId(), row.space, row.label, row.address, row.bytes, row.origin, this.id());
|
|
286
293
|
}
|
|
287
294
|
|
|
288
295
|
insertStartScreen(row: Omit<StartScreenRow, "revision">): void {
|
|
@@ -713,13 +720,13 @@ function checkOperandValue(db: DatabaseSync, space: Space, image: OperandImage,
|
|
|
713
720
|
return identifiers(text).map((name) => resolve(name)!);
|
|
714
721
|
}
|
|
715
722
|
|
|
716
|
-
function operandStep(db: DatabaseSync, change: Change, context: ChangeContext & { image?: OperandImage }, request: OperandRequest): Step<OperandRow, OperandRow> {
|
|
723
|
+
function operandStep(db: DatabaseSync, change: Change, context: ChangeContext & { image?: (space: Space) => OperandImage }, request: OperandRequest): Step<OperandRow, OperandRow> {
|
|
717
724
|
const space = spaceOf(request);
|
|
718
725
|
if (context.image === undefined) throw new Refusal("invalid-input", "An operand expression is checked against the image, and no image was given.");
|
|
719
726
|
const wanted: Omit<OperandRow, "space" | "address" | "origin" | "revision"> = { select: request.select, offset: request.offset ?? 0 };
|
|
720
727
|
if (request.symbol !== undefined) wanted.symbol = request.symbol;
|
|
721
728
|
if (request.expression !== undefined) wanted.expression = request.expression.trim();
|
|
722
|
-
const targets = new Set(checkOperandValue(db, space, context.image, request, operandText(wanted)));
|
|
729
|
+
const targets = new Set(checkOperandValue(db, space, context.image(space), request, operandText(wanted)));
|
|
723
730
|
const existing = operandAt(db, request.address, space);
|
|
724
731
|
const origin = context.origin as OperandRow["origin"];
|
|
725
732
|
if (existing !== undefined && existing.select === wanted.select && existing.symbol === wanted.symbol && existing.offset === wanted.offset && existing.expression === wanted.expression && !confirms(existing.origin, origin)) {
|
|
@@ -751,9 +758,11 @@ type ModuleRequest = InSpace & { start: number; file: string; title?: string };
|
|
|
751
758
|
function checkModule(request: ModuleRequest): void {
|
|
752
759
|
checkSpace(request);
|
|
753
760
|
checkAddress(request.start, "start");
|
|
754
|
-
if (!MODULE_FILE.test(request.file))
|
|
761
|
+
if (!MODULE_FILE.test(request.file)) {
|
|
762
|
+
throw new Refusal("invalid-input", "A module file is a name of letters, digits, underscores or hyphens (at most 60) that ends in .asm. It can have one folder of lower-case letters, digits, underscores or hyphens (at most 30), for example music/driver.asm.");
|
|
763
|
+
}
|
|
755
764
|
if (isGeneratedFile(request.file)) {
|
|
756
|
-
throw new Refusal("invalid-input", `A module cannot have the file ${request.file}, because the generated source writes ${GENERATED_FILES.join(", ")} itself, in any letter case. Give the module another file.`);
|
|
765
|
+
throw new Refusal("invalid-input", `A module cannot have the file ${request.file}, because the generated source writes ${GENERATED_FILES.join(", ")} in any folder, and the folders ${GENERATED_FOLDERS.map((folder) => `${folder}/`).join(", ")} itself, in any letter case. Give the module another file.`);
|
|
757
766
|
}
|
|
758
767
|
if (request.title !== undefined && (request.title.trim().length === 0 || request.title.length > MAX_COMMENT)) throw new Refusal("invalid-input", `A module title has 1 to ${MAX_COMMENT} characters.`);
|
|
759
768
|
}
|
|
@@ -874,11 +883,12 @@ export function leastPatchBytes(code: string): number | undefined {
|
|
|
874
883
|
return bytes;
|
|
875
884
|
}
|
|
876
885
|
|
|
877
|
-
function patchStep(db: DatabaseSync, change: Change, context: ChangeContext & { image?: OperandImage }, request: PatchRequest): Step<PatchRow, PatchRow> {
|
|
886
|
+
function patchStep(db: DatabaseSync, change: Change, context: ChangeContext & { image?: (space: Space) => OperandImage }, request: PatchRequest): Step<PatchRow, PatchRow> {
|
|
878
887
|
const space = spaceOf(request);
|
|
879
888
|
const range = `${formatC64Address(request.start)}-${formatC64Address(request.end)}`;
|
|
880
889
|
if (context.image === undefined) throw new Refusal("invalid-input", "A patch is checked against the image, and no image was given.");
|
|
881
|
-
|
|
890
|
+
const image = context.image(space);
|
|
891
|
+
checkInImage(image, request.start, request.end, "a patch");
|
|
882
892
|
const least = leastPatchBytes(request.code);
|
|
883
893
|
const length = request.end - request.start + 1;
|
|
884
894
|
if (least !== undefined && least > length) {
|
|
@@ -979,7 +989,7 @@ function defaultOf(request: SwitchRequest, existing: SwitchRow | undefined): 0 |
|
|
|
979
989
|
throw new Refusal("invalid-input", `A ${request.kind} switch needs a default: give --default 0 or --default 1.`);
|
|
980
990
|
}
|
|
981
991
|
|
|
982
|
-
function switchStep(db: DatabaseSync, change: Change, context: ChangeContext & { image?: OperandImage }, request: SwitchRequest): Step<SwitchRow, SwitchRow> {
|
|
992
|
+
function switchStep(db: DatabaseSync, change: Change, context: ChangeContext & { image?: (space: Space) => OperandImage }, request: SwitchRequest): Step<SwitchRow, SwitchRow> {
|
|
983
993
|
const space = spaceOf(request);
|
|
984
994
|
const base = baseLabel(db, space);
|
|
985
995
|
if (base === undefined) throw new Refusal("not-found", "The knowledge has no base release. Record the release whose bytes are the program first (release <label> --file <file> --base).");
|
|
@@ -992,7 +1002,7 @@ function switchStep(db: DatabaseSync, change: Change, context: ChangeContext & {
|
|
|
992
1002
|
if (existing !== undefined && existing.kind === request.kind && existing.default === value && listText(existing.releases) === listText(releases) && existing.comment === comment && !confirms(existing.origin, origin)) return { current: existing };
|
|
993
1003
|
const symbol = symbolNamed(db, request.name, space);
|
|
994
1004
|
if (symbol !== undefined) throw new Refusal("conflict", `The switch name ${request.name} is the name of the symbol at ${formatC64Address(symbol.address)}. Give the switch another name.`);
|
|
995
|
-
if (space === DEFAULT_SPACE && context.image?.platform.has(request.name)) throw new Refusal("conflict", `The switch name ${request.name} is a C64 platform name. Give the switch another name.`);
|
|
1005
|
+
if (space === DEFAULT_SPACE && context.image?.(space).platform.has(request.name)) throw new Refusal("conflict", `The switch name ${request.name} is a C64 platform name. Give the switch another name.`);
|
|
996
1006
|
// The patches hold the code of the value that the base release does not have: that value cannot change under them.
|
|
997
1007
|
if (existing !== undefined && baseValue(existing, base) !== baseValue({ releases }, base)) {
|
|
998
1008
|
const patches = listPatches(db, undefined, request.name, undefined, space);
|
|
@@ -1019,16 +1029,23 @@ function unswitchStep(db: DatabaseSync, change: Change, _origin: Origin, request
|
|
|
1019
1029
|
return { current: null };
|
|
1020
1030
|
}
|
|
1021
1031
|
|
|
1022
|
-
/**
|
|
1023
|
-
|
|
1032
|
+
/**
|
|
1033
|
+
* A release. `rows` are the bytes of a release other than the base release,
|
|
1034
|
+
* as memoryRows gives them: the address of each row and its bytes as hex. The
|
|
1035
|
+
* base release has no bytes of its own: its bytes are the program.
|
|
1036
|
+
*/
|
|
1037
|
+
type ReleaseRequest = InSpace & { label: string; base?: boolean; comment?: string; rows?: ReadonlyMap<number, string> };
|
|
1024
1038
|
|
|
1025
1039
|
function checkRelease(request: ReleaseRequest): void {
|
|
1026
1040
|
checkSpace(request);
|
|
1027
1041
|
if (typeof request.label !== "string" || !RELEASE_LABEL.test(request.label)) {
|
|
1028
1042
|
throw new Refusal("invalid-input", "A release label is an upper-case letter, then 1 to 31 upper-case letters, digits or underscores, for example ORIGINAL or FIRESTAR.");
|
|
1029
1043
|
}
|
|
1030
|
-
|
|
1031
|
-
|
|
1044
|
+
for (const [address, bytes] of request.rows ?? []) {
|
|
1045
|
+
if (!Number.isInteger(address) || address < 0 || address > 0xffff || !/^(?:[0-9a-f]{2})+$/.test(bytes) || bytes.length > MEMORY_ROW * 2 || address + bytes.length / 2 > 0x10000) {
|
|
1046
|
+
throw new Refusal("invalid-input", `The bytes of a release at ${formatC64Address(address & 0xffff)} are not a memory row.`);
|
|
1047
|
+
}
|
|
1048
|
+
}
|
|
1032
1049
|
checkCommentText(request.comment, "A release comment");
|
|
1033
1050
|
}
|
|
1034
1051
|
|
|
@@ -1037,7 +1054,12 @@ function releaseStep(db: DatabaseSync, change: Change, origin: Origin, request:
|
|
|
1037
1054
|
const existing = releaseLabeled(db, request.label, space);
|
|
1038
1055
|
const base = request.base ?? existing?.base ?? false;
|
|
1039
1056
|
const comment = request.comment === undefined ? existing?.comment : request.comment.trim();
|
|
1040
|
-
|
|
1057
|
+
const held = db.prepare("SELECT id, address, bytes FROM current_release_memory WHERE space = ? AND label = ?").all(space, request.label) as Array<{ id: string; address: number; bytes: string }>;
|
|
1058
|
+
// A release without new bytes keeps its bytes. The base release has none: its bytes are the program.
|
|
1059
|
+
const wanted = base ? new Map<number, string>() : (request.rows ?? new Map(held.map((row) => [row.address, row.bytes])));
|
|
1060
|
+
if (!base && wanted.size === 0) throw new Refusal("invalid-input", `The release ${request.label} has no bytes. Give the file of the release.`);
|
|
1061
|
+
const sameBytes = held.length === wanted.size && held.every((row) => wanted.get(row.address) === row.bytes);
|
|
1062
|
+
if (existing !== undefined && existing.base === base && existing.comment === comment && sameBytes && !confirms(existing.origin, origin)) return { current: existing };
|
|
1041
1063
|
const other = baseLabel(db, space);
|
|
1042
1064
|
if (base && other !== undefined && other !== request.label) throw new Refusal("conflict", `The release ${other} is the base release. A space has one base release.`);
|
|
1043
1065
|
// Every switch takes its base value from the base release: it cannot change under them.
|
|
@@ -1047,8 +1069,17 @@ function releaseStep(db: DatabaseSync, change: Change, origin: Origin, request:
|
|
|
1047
1069
|
}
|
|
1048
1070
|
const symbol = symbolNamed(db, `${RELEASE_DEFINE}${request.label}`, space);
|
|
1049
1071
|
if (symbol !== undefined) throw new Refusal("conflict", `The build of the release defines ${RELEASE_DEFINE}${request.label}, and that is the name of the symbol at ${formatC64Address(symbol.address)}. Give the release another label.`);
|
|
1050
|
-
if (existing
|
|
1051
|
-
|
|
1072
|
+
if (existing === undefined || existing.base !== base || existing.comment !== comment || confirms(existing.origin, origin)) {
|
|
1073
|
+
if (existing !== undefined) change.close("releases", "space = ? AND label = ?", space, request.label);
|
|
1074
|
+
change.insertRelease({ space, label: request.label, base, ...(comment === undefined ? {} : { comment }), origin: origin as ReleaseRow["origin"] });
|
|
1075
|
+
}
|
|
1076
|
+
// Only the rows that changed: a changed byte changes one short line of the text.
|
|
1077
|
+
const kept = new Set<number>();
|
|
1078
|
+
for (const row of held) {
|
|
1079
|
+
if (wanted.get(row.address) === row.bytes) kept.add(row.address);
|
|
1080
|
+
else change.close("release_memory", "id = ?", row.id);
|
|
1081
|
+
}
|
|
1082
|
+
for (const [address, bytes] of [...wanted].sort(([a], [b]) => a - b)) if (!kept.has(address)) change.insertReleaseMemory({ space, label: request.label, address, bytes, origin });
|
|
1052
1083
|
const current = releaseLabeled(db, request.label, space)!;
|
|
1053
1084
|
return existing !== undefined && existing.origin !== origin ? { current, previous: existing } : { current };
|
|
1054
1085
|
}
|
|
@@ -1063,6 +1094,7 @@ function unreleaseStep(db: DatabaseSync, change: Change, _origin: Origin, reques
|
|
|
1063
1094
|
throw new Refusal("conflict", `The release ${request.label} ${why} the switches ${switches.map((row) => row.name).join(", ")}. Change or remove them first (switch, unswitch).`);
|
|
1064
1095
|
}
|
|
1065
1096
|
change.close("releases", "space = ? AND label = ?", space, request.label);
|
|
1097
|
+
change.close("release_memory", "space = ? AND label = ?", space, request.label);
|
|
1066
1098
|
return { current: null };
|
|
1067
1099
|
}
|
|
1068
1100
|
|
|
@@ -1264,11 +1296,11 @@ function renameInUses(db: DatabaseSync, change: Change, space: Space, from: stri
|
|
|
1264
1296
|
}
|
|
1265
1297
|
}
|
|
1266
1298
|
|
|
1267
|
-
function useStep(db: DatabaseSync, change: Change, context: ChangeContext & { image?: OperandImage }, request: MacroUseRequest): Step<MacroUseRow, MacroUseRow> {
|
|
1299
|
+
function useStep(db: DatabaseSync, change: Change, context: ChangeContext & { image?: (space: Space) => OperandImage }, request: MacroUseRequest): Step<MacroUseRow, MacroUseRow> {
|
|
1268
1300
|
const space = spaceOf(request);
|
|
1269
|
-
const image = context.image;
|
|
1270
1301
|
const range = `${formatC64Address(request.start)}-${formatC64Address(request.end)}`;
|
|
1271
|
-
if (image === undefined) throw new Refusal("invalid-input", "A macro use is checked against the image, and no image was given.");
|
|
1302
|
+
if (context.image === undefined) throw new Refusal("invalid-input", "A macro use is checked against the image, and no image was given.");
|
|
1303
|
+
const image = context.image(space);
|
|
1272
1304
|
const macro = macroNamed(db, request.macro, space);
|
|
1273
1305
|
if (macro === undefined) throw new Refusal("not-found", `There is no macro ${request.macro}. Write it first (macro).`);
|
|
1274
1306
|
const args = (request.args ?? []).map((arg) => arg.trim());
|
|
@@ -1414,7 +1446,7 @@ export function removeSwitch(db: DatabaseSync, context: WriteContext, request: I
|
|
|
1414
1446
|
return result(write(db, context, "remove-switch", (change) => unswitchStep(db, change, context.origin, request)));
|
|
1415
1447
|
}
|
|
1416
1448
|
|
|
1417
|
-
/** Writes a release of the program
|
|
1449
|
+
/** Writes a release of the program and its bytes. The caller reads the bytes from the file of the release, and checks the file of the base release. */
|
|
1418
1450
|
export function setRelease(db: DatabaseSync, context: WriteContext, request: ReleaseRequest): WriteResult<ReleaseRow, ReleaseRow> {
|
|
1419
1451
|
checkRelease(request);
|
|
1420
1452
|
return result(write(db, context, "set-release", (change) => releaseStep(db, change, context.origin, request)));
|
|
@@ -1605,6 +1637,7 @@ export function applyBatch(db: DatabaseSync, context: WriteContext, operations:
|
|
|
1605
1637
|
/** The tables of the program and the columns that make a row. */
|
|
1606
1638
|
const PROGRAM_TABLES = [
|
|
1607
1639
|
["memory", "space, address, bytes, origin"],
|
|
1640
|
+
["release_memory", "space, label, address, bytes, origin"],
|
|
1608
1641
|
["entries", "space, address, state, stages, origin"],
|
|
1609
1642
|
["coverage", "space, kind, start_address, end_address, origin"],
|
|
1610
1643
|
] as const;
|
|
@@ -1634,7 +1667,7 @@ const KEYS = {
|
|
|
1634
1667
|
releases: {
|
|
1635
1668
|
columns: RELEASE_COLUMNS,
|
|
1636
1669
|
map: toRelease,
|
|
1637
|
-
key: (row: ReleaseRow) => `${row.space}|${row.label}|${row.
|
|
1670
|
+
key: (row: ReleaseRow) => `${row.space}|${row.label}|${row.base}|${row.comment ?? ""}|${row.origin}`,
|
|
1638
1671
|
},
|
|
1639
1672
|
start_screens: {
|
|
1640
1673
|
columns: START_SCREEN_COLUMNS,
|
|
@@ -1735,6 +1768,7 @@ export function revert(db: DatabaseSync, context: WriteContext, request: { revis
|
|
|
1735
1768
|
if (nowKeys.has(key(row))) continue;
|
|
1736
1769
|
const values = row as never;
|
|
1737
1770
|
if (table === "memory") change.insertMemory(values);
|
|
1771
|
+
else if (table === "release_memory") change.insertReleaseMemory(values);
|
|
1738
1772
|
else if (table === "entries") change.insertEntry(values);
|
|
1739
1773
|
else change.insertCoverage({ ...(values as { space: Space; kind: string; origin: Origin }), start: row.start_address as number, end: row.end_address as number });
|
|
1740
1774
|
}
|
package/src/mcp/inputs.ts
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
import { z } from "zod";
|
|
7
7
|
|
|
8
8
|
import { c64AddressOf } from "../c64.ts";
|
|
9
|
+
import { keyTaps, MAX_PRESS_FRAMES, PRESS_FRAMES } from "../c64-keys.ts";
|
|
9
10
|
import { DEFAULT_TIMEOUT_FRAMES, keyboardBytes, MAX_RASTER_LINE } from "../host-client/steps.ts";
|
|
10
11
|
import { COMPARISONS, CONDITION_REGISTERS, JOYSTICK_DIRECTIONS, MAX_KEYBOARD_BYTES, MAX_MEMORY_WRITE, MAX_TIMEOUT_FRAMES, MEMORY_VIEWS, SPACES } from "../protocol/vice.ts";
|
|
11
12
|
|
|
@@ -91,6 +92,17 @@ export const TOOL_INPUTS = {
|
|
|
91
92
|
})
|
|
92
93
|
.strict(),
|
|
93
94
|
|
|
95
|
+
press: z
|
|
96
|
+
.object({
|
|
97
|
+
keys: z.string().min(1).describe("the keys: each character is one tap, a name in braces is one key, for example {F1}, and + in braces holds keys together, for example {LSHIFT+CBM}"),
|
|
98
|
+
frames: z.number().int().min(1).max(MAX_PRESS_FRAMES).default(PRESS_FRAMES).describe("the frames that each tap holds its keys, and then waits with all keys up"),
|
|
99
|
+
})
|
|
100
|
+
.strict()
|
|
101
|
+
.superRefine((value, context) => {
|
|
102
|
+
const taps = keyTaps(value.keys);
|
|
103
|
+
if (typeof taps === "string") context.addIssue({ code: "custom", message: taps, path: ["keys"] });
|
|
104
|
+
}),
|
|
105
|
+
|
|
94
106
|
keyboard: z
|
|
95
107
|
.object({
|
|
96
108
|
mode: z.enum(["text", "petscii"]),
|
package/src/mcp/server.ts
CHANGED
|
@@ -19,7 +19,6 @@ import { elapsedMs, trace, type TraceFields } from "../trace.ts";
|
|
|
19
19
|
/** The session operations tools may call. */
|
|
20
20
|
export type ViceSessionApi = Pick<
|
|
21
21
|
ViceSessionClient,
|
|
22
|
-
| "status"
|
|
23
22
|
| "memoryRead"
|
|
24
23
|
| "registersGet"
|
|
25
24
|
| "memoryWrite"
|
|
@@ -36,6 +35,7 @@ export type ViceSessionApi = Pick<
|
|
|
36
35
|
| "diskAttach"
|
|
37
36
|
| "keyboard"
|
|
38
37
|
| "joystick"
|
|
38
|
+
| "press"
|
|
39
39
|
| "screenCapture"
|
|
40
40
|
| "screenCompare"
|
|
41
41
|
| "screenBaselines"
|
package/src/mcp/tools/input.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
// Input tools: c64_keyboard and c64_joystick.
|
|
1
|
+
// Input tools: c64_keyboard, c64_press and c64_joystick.
|
|
2
2
|
|
|
3
3
|
import { z } from "zod";
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { formatC64Address } from "../../c64.ts";
|
|
6
|
+
import { keyTaps, MAX_PRESS_TAPS, MAX_TAP_KEYS, PRESS_FRAMES, type KeyTap } from "../../c64-keys.ts";
|
|
7
|
+
import { JOYSTICK_DIRECTIONS, MAX_KEYBOARD_BYTES, POINT_STOP_REASONS, RUN_STATES, SPACES } from "../../protocol/vice.ts";
|
|
6
8
|
import { keyboardBytes } from "../../host-client/steps.ts";
|
|
7
9
|
import { TOOL_INPUTS } from "../inputs.ts";
|
|
8
|
-
import { defineTool } from "../server.ts";
|
|
10
|
+
import { AddressOutput, defineTool } from "../server.ts";
|
|
9
11
|
|
|
10
12
|
|
|
11
13
|
export const c64Keyboard = defineTool({
|
|
@@ -14,7 +16,7 @@ export const c64Keyboard = defineTool({
|
|
|
14
16
|
description:
|
|
15
17
|
`Type up to ${MAX_KEYBOARD_BYTES} keys into the C64 keyboard queue. The C64 reads them while it runs. ` +
|
|
16
18
|
"Only a program that reads keys through the KERNAL sees them. A program that reads the keyboard hardware directly does not see them. Many games do that. " +
|
|
17
|
-
"
|
|
19
|
+
"For keys that a program reads from the keyboard hardware, use c64_press. " +
|
|
18
20
|
'Mode text types text, for example "RUN\\n". Letters of either case type the normal (unshifted) key. A line break types RETURN. ' +
|
|
19
21
|
"Mode petscii types PETSCII codes 1 to 255 in bytes, for example [147] to clear the screen. " +
|
|
20
22
|
"While c64_autostart loads a program, this tool refuses keys: see c64_autostart. " +
|
|
@@ -29,6 +31,37 @@ export const c64Keyboard = defineTool({
|
|
|
29
31
|
},
|
|
30
32
|
});
|
|
31
33
|
|
|
34
|
+
export const c64Press = defineTool({
|
|
35
|
+
name: "c64_press",
|
|
36
|
+
title: "Press keys of the C64 keyboard",
|
|
37
|
+
description:
|
|
38
|
+
"Press keys of the C64 keyboard matrix, and RESTORE. A program that reads the keyboard hardware directly sees these keys. Many games do that. " +
|
|
39
|
+
"Each character of keys is one tap: the key goes down, then up. Letters of either case press the same key. A line break presses RETURN. " +
|
|
40
|
+
"A key without a character has its name in braces: {F1} to {F8}, {RETURN}, {SPACE}, {DEL}, {INST}, {HOME}, {CLR}, {STOP}, {RUN} and {RESTORE}. " +
|
|
41
|
+
"The other names are {CTRL}, {CBM}, {LSHIFT}, {RSHIFT}, {UP}, {DOWN}, {LEFT}, {RIGHT}, {POUND}, {UPARROW} and {LEFTARROW}. " +
|
|
42
|
+
"{F2}, {RUN}, {CLR}, {INST}, {UP} and {LEFT} also press the left SHIFT. " +
|
|
43
|
+
`Join keys with + in braces to hold them together in one tap, for example {LSHIFT+CBM}, {CTRL+3} or {STOP+RESTORE}. One tap holds at most ${MAX_TAP_KEYS} keys, RESTORE included. One call has at most ${MAX_PRESS_TAPS} taps. ` +
|
|
44
|
+
`Each tap holds its keys for frames frames (default ${PRESS_FRAMES}). Then all keys are up for frames frames. The machine runs during the taps, and it runs again after them when it ran before. ` +
|
|
45
|
+
"A breakpoint, watchpoint or JAM stops the taps early. Then stopReason tells why, taps tells how many taps were complete, and the machine stays stopped. All keys are up at the end. " +
|
|
46
|
+
"The CPU history starts again at each tap. " +
|
|
47
|
+
"To type text through the KERNAL keyboard queue, use c64_keyboard.",
|
|
48
|
+
inputSchema: TOOL_INPUTS.press,
|
|
49
|
+
outputSchema: z.object({
|
|
50
|
+
taps: z.number().int().min(0).max(MAX_PRESS_TAPS).describe("the taps that were complete"),
|
|
51
|
+
state: z.enum(RUN_STATES),
|
|
52
|
+
stopReason: z.enum(POINT_STOP_REASONS).optional().describe("why the taps stopped early"),
|
|
53
|
+
pc: AddressOutput.optional(),
|
|
54
|
+
pointId: z.number().int().min(1).optional().describe("the id of the breakpoint or watchpoint that stopped the taps"),
|
|
55
|
+
space: z.enum(SPACES).optional().describe("the CPU that stopped, c64 or drive8. pc is the address in that space"),
|
|
56
|
+
}),
|
|
57
|
+
readOnly: false,
|
|
58
|
+
async run(input, session) {
|
|
59
|
+
// The schema checked the keys: keyTaps gives taps here.
|
|
60
|
+
const { pc, ...result } = await session.press(keyTaps(input.keys) as KeyTap[], input.frames);
|
|
61
|
+
return { ...result, ...(pc === undefined ? {} : { pc: formatC64Address(pc) }) };
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
|
|
32
65
|
export const c64Joystick = defineTool({
|
|
33
66
|
name: "c64_joystick",
|
|
34
67
|
title: "Move a joystick",
|
|
@@ -44,4 +77,4 @@ export const c64Joystick = defineTool({
|
|
|
44
77
|
},
|
|
45
78
|
});
|
|
46
79
|
|
|
47
|
-
export const inputTools = [c64Keyboard, c64Joystick];
|
|
80
|
+
export const inputTools = [c64Keyboard, c64Press, c64Joystick];
|