@henols/c64-re-tools 2.6.0-rc.9 → 2.7.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-assembler/SKILL.md +7 -7
- package/skills/c64-assembler/scripts/assembler.ts +4 -3
- package/skills/c64-basic/SKILL.md +1 -1
- package/skills/c64-development/SKILL.md +7 -7
- package/skills/c64-disk/SKILL.md +13 -13
- package/skills/c64-docs/SKILL.md +25 -10
- package/skills/c64-docs/references/page-types.md +11 -11
- package/skills/c64-docs/references/style.md +21 -0
- package/skills/c64-docs/scripts/docs.ts +78 -18
- package/skills/c64-docs/scripts/lib/links.ts +1 -1
- package/skills/c64-docs/scripts/lib/reference.ts +117 -31
- package/skills/c64-docs/scripts/lib/source-map.ts +14 -0
- package/skills/c64-knowledge/SKILL.md +15 -14
- package/skills/c64-knowledge/scripts/knowledge.ts +17 -10
- package/skills/c64-memory-map/SKILL.md +1 -1
- package/skills/c64-packer/SKILL.md +1 -1
- package/skills/c64-provenance/SKILL.md +5 -4
- package/skills/c64-provenance/scripts/lib/compare.ts +1 -1
- package/skills/c64-reverse-engineering/SKILL.md +26 -11
- package/skills/c64-source/SKILL.md +18 -15
- package/skills/c64-source/scripts/lib/export.ts +20 -8
- package/skills/c64-source/scripts/lib/loader.ts +51 -28
- package/skills/c64-source/scripts/lib/source.ts +27 -20
- package/skills/c64-source/scripts/source.ts +68 -53
- package/skills/c64-static-analysis/SKILL.md +24 -22
- package/skills/c64-static-analysis/scripts/lib/findings.ts +11 -11
- package/skills/c64-static-analysis/scripts/lib/instructions.ts +4 -4
- package/skills/c64-static-analysis/scripts/lib/macros.ts +3 -1
- package/skills/c64-static-analysis/scripts/static-analysis.ts +36 -27
- package/skills/c64-testing/SKILL.md +32 -24
- package/skills/c64-testing/references/recording-format.md +15 -9
- package/skills/c64-testing/references/scenario-format.md +9 -7
- package/skills/c64-testing/scripts/lib/recording.ts +214 -49
- package/skills/c64-testing/scripts/lib/replay.ts +45 -19
- package/skills/c64-testing/scripts/lib/runs.ts +7 -2
- package/skills/c64-testing/scripts/lib/scenario.ts +31 -31
- package/skills/c64-testing/scripts/testing.ts +37 -16
- package/skills/c64-unpacker/SKILL.md +16 -14
- package/skills/c64-unpacker/scripts/lib/stages.ts +18 -3
- package/skills/c64-unpacker/scripts/unpacker.ts +38 -6
- package/src/build-name.ts +9 -4
- package/src/c64.ts +1 -1
- package/src/host/main.ts +2 -2
- package/src/host/server.ts +3 -1
- package/src/host/tools/index.ts +1 -1
- package/src/host/vice/process.ts +34 -17
- package/src/host/vice/session.ts +55 -27
- package/src/host-client/steps.ts +4 -1
- package/src/host-client/tools.ts +1 -1
- package/src/knowledge/evidence.ts +66 -0
- package/src/knowledge/history.ts +5 -5
- package/src/knowledge/import.ts +12 -5
- package/src/knowledge/program.ts +81 -33
- package/src/knowledge/read.ts +3 -3
- package/src/knowledge/schema.ts +7 -7
- package/src/knowledge/separate.ts +2 -2
- package/src/knowledge/start-screen.ts +2 -0
- package/src/knowledge/text.ts +28 -3
- package/src/knowledge/write.ts +7 -7
- package/src/mcp/tools/debug.ts +23 -21
- package/src/mcp/tools/memory.ts +12 -9
- package/src/native/c64run.ts +7 -4
- package/src/native/{ghidra → decompiler}/analyze.ts +17 -17
- package/src/native/{ghidra → decompiler}/language/c64rt_6510.slaspec +1 -1
- package/src/native/{ghidra → decompiler}/walk.ts +6 -6
- package/src/native/types.ts +25 -25
- package/src/opcodes.ts +1 -1
- package/src/project.ts +1 -1
- package/src/reference-pages.ts +64 -0
- package/src/script.ts +2 -2
- package/tools/c64run.c +151 -5
- /package/src/native/{ghidra → decompiler}/c64rt-wasm.ts +0 -0
- /package/src/native/{ghidra → decompiler}/language/c64rt_6510.cspec +0 -0
- /package/src/native/{ghidra → decompiler}/language/c64rt_6510.ldefs +0 -0
- /package/src/native/{ghidra → decompiler}/language/c64rt_6510.pspec +0 -0
- /package/src/native/{ghidra → decompiler}/language/c64rt_6510.sla +0 -0
- /package/src/native/{ghidra → decompiler}/pcode.ts +0 -0
- /package/src/native/{ghidra → decompiler}/wasm.ts +0 -0
|
@@ -17,7 +17,7 @@ import { operandText } from "#src/knowledge/expression.ts";
|
|
|
17
17
|
import { historyAt, historyNamed, historyOfMacro, historyOfSwitch, revision, revisionNote, revisions, type HistoryEntry } from "#src/knowledge/history.ts";
|
|
18
18
|
import { joinBatches, type Batch, type JoinChoice, type JoinClash } from "#src/knowledge/join.ts";
|
|
19
19
|
import { knowledgeNames } from "#src/knowledge/names.ts";
|
|
20
|
-
import { addCoverage, memoryRows, operandImages as programImages, programCoverage, programImage, requireProgram, setImage, type ImageRequest } from "#src/knowledge/program.ts";
|
|
20
|
+
import { addCoverage, coverageRangeCounts, memoryRows, operandImages as programImages, programCoverage, programImage, requireProgram, setImage, type ImageRequest } from "#src/knowledge/program.ts";
|
|
21
21
|
import { startScreenOfStage } from "#src/knowledge/start-screen.ts";
|
|
22
22
|
import {
|
|
23
23
|
analyzerNamesAt,
|
|
@@ -203,11 +203,11 @@ function suppression(row: SuppressionRow) {
|
|
|
203
203
|
return { ...spaceOf(row), suppresses: row.entity, ...place, origin: row.origin, revision: row.revision };
|
|
204
204
|
}
|
|
205
205
|
|
|
206
|
-
/** A row of the program in a revision: memory bytes, the entry, or a coverage
|
|
206
|
+
/** A row of the program in a revision: memory bytes, the entry, or the ranges of one kind of a coverage map. */
|
|
207
207
|
function programRow(entry: Extract<HistoryEntry, { entity: "memory" | "entry" | "coverage" }>) {
|
|
208
208
|
if (entry.entity === "memory") return { ...spaceOf(entry.row), start: formatC64Address(entry.row.address), end: formatC64Address(entry.row.address + entry.row.bytes - 1), bytes: entry.row.bytes, origin: entry.row.origin, revision: entry.row.revision };
|
|
209
209
|
if (entry.entity === "entry") return { ...spaceOf(entry.row), address: formatC64Address(entry.row.address), state: entry.row.state, stages: entry.row.stages, origin: entry.row.origin, revision: entry.row.revision };
|
|
210
|
-
return { ...spaceOf(entry.row),
|
|
210
|
+
return { ...spaceOf(entry.row), map: entry.row.map, kind: entry.row.kind, ranges: entry.row.ranges, origin: entry.row.origin, revision: entry.row.revision };
|
|
211
211
|
}
|
|
212
212
|
|
|
213
213
|
function historyEntry(entry: HistoryEntry) {
|
|
@@ -299,7 +299,7 @@ function listingSource(db: DatabaseSync | undefined, space: string): ListingSour
|
|
|
299
299
|
/** Every value of --origin, for the message of a wrong one. */
|
|
300
300
|
const ORIGIN_VALUES = `one of ${ORIGINS.join(", ")}, semantic or analyzer, or a comma list of them. semantic is ${SEMANTIC_ORIGINS.join(" and ")}. analyzer is ${ANALYZERS.slice(0, -1).join(", ")} and ${ANALYZERS.at(-1)}`;
|
|
301
301
|
|
|
302
|
-
/** --origin for reads: one origin, semantic (user and llm), analyzer (dxa,
|
|
302
|
+
/** --origin for reads: one origin, semantic (user and llm), analyzer (dxa, decompiler and heuristic), or a comma list. */
|
|
303
303
|
function originFilter(value: string): Origin[] {
|
|
304
304
|
const origins = new Set<Origin>();
|
|
305
305
|
for (const part of value.split(",")) {
|
|
@@ -558,7 +558,7 @@ const READ_COMMANDS: CommandSpec[] = [
|
|
|
558
558
|
},
|
|
559
559
|
),
|
|
560
560
|
readCommand(
|
|
561
|
-
{ name: "symbols", summary: "The symbols, or with --analyzer the second names that DXA,
|
|
561
|
+
{ name: "symbols", summary: "The symbols, or with --analyzer the second names that DXA, the decompiler and the idioms gave.", options: { ...FILTER, kind: SYMBOL_KIND, analyzer: { kind: "flag", help: "the analyzer names in place of the symbols" }, ...LIST } },
|
|
562
562
|
(db, call) => {
|
|
563
563
|
const kind = call.string("kind") as (typeof SYMBOL_KINDS)[number] | undefined;
|
|
564
564
|
if (call.flag("analyzer")) return { analyzerNames: list(call, listAnalyzerNames(db, rangeOf(call), kind, originsOf(call), call.space), symbol, RANGE_REST) };
|
|
@@ -598,7 +598,6 @@ const READ_COMMANDS: CommandSpec[] = [
|
|
|
598
598
|
readCommand({ name: "spaces", summary: "The address spaces that hold knowledge.", options: LIST }, (db, call) => ({ spaces: list(call, listSpaces(db), (space) => space, MORE) })),
|
|
599
599
|
readCommand({ name: "program", summary: "The program in the knowledge: its segments and entry, and the coverage maps that coverage imported, with the ranges." }, (db, call) => {
|
|
600
600
|
const image = programImage(db, call.space);
|
|
601
|
-
const ranges = db === undefined ? [] : (db.prepare("SELECT kind, count(*) AS count FROM current_coverage WHERE space = ? GROUP BY kind ORDER BY kind").all(call.space) as Array<{ kind: string; count: number }>);
|
|
602
601
|
return {
|
|
603
602
|
...(call.space === DEFAULT_SPACE ? {} : { space: call.space }),
|
|
604
603
|
image:
|
|
@@ -612,7 +611,7 @@ const READ_COMMANDS: CommandSpec[] = [
|
|
|
612
611
|
stages: image.stages?.length ?? 0,
|
|
613
612
|
},
|
|
614
613
|
...((row) => (row === undefined ? {} : { startScreen: startScreen(row) }))(currentStartScreen(db, call.space)),
|
|
615
|
-
coverage: { maps: [...new Set(coverageRuns(db).filter((run) => run.space === call.space).map((run) => run.name))], ranges:
|
|
614
|
+
coverage: { maps: [...new Set(coverageRuns(db).filter((run) => run.space === call.space).map((run) => run.name))], ranges: coverageRangeCounts(db, call.space) },
|
|
616
615
|
};
|
|
617
616
|
}),
|
|
618
617
|
readCommand(
|
|
@@ -892,7 +891,7 @@ const WRITE_COMMANDS: CommandSpec[] = [
|
|
|
892
891
|
{
|
|
893
892
|
name: "release",
|
|
894
893
|
summary: "Records a release of the program from its PRG or the image.json of its capture: the knowledge keeps the bytes of the release. The base release is the one whose bytes are the program of the knowledge.",
|
|
895
|
-
subjects: [{ name: "<label>", help: "the release label, for example
|
|
894
|
+
subjects: [{ name: "<label>", help: "the release label, for example FIRESTAR or V2" }],
|
|
896
895
|
options: {
|
|
897
896
|
file: { kind: "path", value: "<file>", help: "the PRG or image.json of the release. After the write, the knowledge does not need the file", required: true },
|
|
898
897
|
base: { kind: "flag", help: "this release is the program of the knowledge: its segments and bytes must be the same" },
|
|
@@ -1061,7 +1060,7 @@ const WRITE_COMMANDS: CommandSpec[] = [
|
|
|
1061
1060
|
writeCommand(
|
|
1062
1061
|
{
|
|
1063
1062
|
name: "coverage",
|
|
1064
|
-
summary: "
|
|
1063
|
+
summary: "Puts coverage maps of the emulator or of a run into the coverage of the knowledge. Each map is named by its path: a new map of a path replaces the earlier map of that path, and --evidence coverage:<path> cites it.",
|
|
1065
1064
|
subjects: [{ name: "<map>", help: "a 64 KiB coverage map", list: true }],
|
|
1066
1065
|
},
|
|
1067
1066
|
(call) => {
|
|
@@ -1069,7 +1068,15 @@ const WRITE_COMMANDS: CommandSpec[] = [
|
|
|
1069
1068
|
const maps = call.subjects.map((path) => ({ bytes: readProjectFile(path).bytes, name: knowledgePath(path, "<map>") }));
|
|
1070
1069
|
return (db) => {
|
|
1071
1070
|
const { revision, current } = addCoverage(db, context, { space: call.space, maps });
|
|
1072
|
-
|
|
1071
|
+
const body = { revision, ...spaceOf(current), imported: current.imported, replaced: current.replaced, known: current.known, added: current.added, removed: current.removed };
|
|
1072
|
+
// Only a range that the coverage gained or lost changes the source and the reference.
|
|
1073
|
+
const hint =
|
|
1074
|
+
revision === null
|
|
1075
|
+
? "The knowledge has each map already. Nothing changed."
|
|
1076
|
+
: current.added === 0 && current.removed === 0
|
|
1077
|
+
? "The coverage did not change. The knowledge keeps the maps as evidence. The source and the reference do not change."
|
|
1078
|
+
: `The coverage gained ${current.added} and lost ${current.removed} ranges of accesses. They can change the leftovers and the code that no run executed. Generate the source again, then the reference.`;
|
|
1079
|
+
return reply(body, { hint });
|
|
1073
1080
|
};
|
|
1074
1081
|
},
|
|
1075
1082
|
),
|
|
@@ -43,7 +43,7 @@ To get the command list, run the script with no arguments.
|
|
|
43
43
|
- Give each path relative to the project folder. The project folder is the nearest folder at or above the working directory that holds `.c64-re-tools/`.
|
|
44
44
|
- If the working directory is not in a project, give `--project <folder>` to each command. If the working directory has projects below it, the script refuses and lists them.
|
|
45
45
|
- In a group folder, each version of a program is a project. The script refuses the group folder and each folder in it that is not a project. Give `--project` with a project of the group, for example `--project v1`.
|
|
46
|
-
- A path that a command only reads can go into another project of the group, for example `../v1/
|
|
46
|
+
- A path that a command only reads can go into another project of the group, for example `../v1/releases/game.prg`. The command writes only in its own project.
|
|
47
47
|
- An address is `$` and 1 to 4 hex digits, for example `'$c000'` or `'$fb'`, or a name. A name is a symbol, else an analyzer name that only one analyzer gives. Put an address in single quotes in a shell.
|
|
48
48
|
- A range is `<start>-<end>`, for example `'$c000-$cfff'`. In a JSON file, a range is `start` and `end`.
|
|
49
49
|
- Bytes in a JSON file are hex in a field `data`, for example `"data": "a900"`.
|
|
@@ -42,7 +42,7 @@ To get the command list, run the script with no arguments.
|
|
|
42
42
|
- Give each path relative to the project folder. The project folder is the nearest folder at or above the working directory that holds `.c64-re-tools/`.
|
|
43
43
|
- If the working directory is not in a project, give `--project <folder>` to each command. If the working directory has projects below it, the script refuses and lists them.
|
|
44
44
|
- In a group folder, each version of a program is a project. The script refuses the group folder and each folder in it that is not a project. Give `--project` with a project of the group, for example `--project v1`.
|
|
45
|
-
- A path that a command only reads can go into another project of the group, for example `../v1/
|
|
45
|
+
- A path that a command only reads can go into another project of the group, for example `../v1/releases/game.prg`. The command writes only in its own project.
|
|
46
46
|
- An address is `$` and 1 to 4 hex digits, for example `'$c000'` or `'$fb'`, or a name. A name is a symbol, else an analyzer name that only one analyzer gives. Put an address in single quotes in a shell.
|
|
47
47
|
- A range is `<start>-<end>`, for example `'$c000-$cfff'`. In a JSON file, a range is `start` and `end`.
|
|
48
48
|
- Bytes in a JSON file are hex in a field `data`, for example `"data": "a900"`.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: c64-provenance
|
|
3
|
-
description: Compares two or more releases of a C64 program byte by byte and tells which releases agree at each difference. It can run each release and tell how the program uses each difference. It gives evidence for each range of the program in the project knowledge. It finds the leftovers in the program, for example texts, assembler source, BASIC lines, unused bytes, copies and dead code. It keeps a library of routines that several programs share, and finds these routines in a program. Use it to separate the
|
|
3
|
+
description: Compares two or more releases of a C64 program byte by byte and tells which releases agree at each difference. It can run each release and tell how the program uses each difference. It gives evidence for each range of the program in the project knowledge. It finds the leftovers in the program, for example texts, assembler source, BASIC lines, unused bytes, copies and dead code. It keeps a library of routines that several programs share, and finds these routines in a program. Use it to separate the program from the changes of a crack or of a release. The bytes that the releases share do not prove the bytes of the commercial original. Use it to find the history of a program in its leftovers. Use it to find known routines, for example a music driver, in a program. It does not disassemble or analyze the code, and it does not change the project knowledge.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
# C64 provenance
|
|
@@ -59,7 +59,7 @@ To get the command list, run the script with no arguments.
|
|
|
59
59
|
- Give each path relative to the project folder. The project folder is the nearest folder at or above the working directory that holds `.c64-re-tools/`.
|
|
60
60
|
- If the working directory is not in a project, give `--project <folder>` to each command. If the working directory has projects below it, the script refuses and lists them.
|
|
61
61
|
- In a group folder, each version of a program is a project. The script refuses the group folder and each folder in it that is not a project. Give `--project` with a project of the group, for example `--project v1`.
|
|
62
|
-
- A path that a command only reads can go into another project of the group, for example `../v1/
|
|
62
|
+
- A path that a command only reads can go into another project of the group, for example `../v1/releases/game.prg`. The command writes only in its own project.
|
|
63
63
|
- An address is `$` and 1 to 4 hex digits, for example `'$c000'` or `'$fb'`, or a name. A name is a symbol, else an analyzer name that only one analyzer gives. Put an address in single quotes in a shell.
|
|
64
64
|
- A range is `<start>-<end>`, for example `'$c000-$cfff'`. In a JSON file, a range is `start` and `end`.
|
|
65
65
|
- Bytes in a JSON file are hex in a field `data`, for example `"data": "a900"`.
|
|
@@ -303,9 +303,9 @@ Traps:
|
|
|
303
303
|
3. Read `differences`.
|
|
304
304
|
4. To find how the program uses the differences, run `compare` again with `--frames`. Give the frames and the steps that get the program to the part that you examine. Read `runtime` of each difference.
|
|
305
305
|
5. Examine each important difference. Disassemble or analyze the bytes of each release. Find what the change does, for example a trainer, a removed copy protection, or a changed text.
|
|
306
|
-
6. Decide which bytes are
|
|
306
|
+
6. Decide which bytes of each difference are the program, and which bytes are a change of a crack or of a release. Steps 7 and 8 use this decision. Use more than the byte comparison: the code, the text, and the history of the releases.
|
|
307
307
|
- Do not call releases independent when you do not know their relation. Two cracks can come from the same source.
|
|
308
|
-
- Do not call a byte original only because one release has it. A majority of releases is also not proof.
|
|
308
|
+
- Do not call a byte a byte of the commercial original only because one release has it. A majority of releases is also not proof.
|
|
309
309
|
7. Record each release in the project knowledge. The base release is the program in the project knowledge.
|
|
310
310
|
8. Record each difference in the project knowledge as a switch and a patch. Select the kind of the switch:
|
|
311
311
|
- `protection`: a copy protection, or the code that a crack changed to remove it.
|
|
@@ -324,6 +324,7 @@ Traps:
|
|
|
324
324
|
4. Run `leftovers`. When you have two or more releases, also run `compare`.
|
|
325
325
|
5. Read `text` first: names, dates, greetings and credits. Then read `copies`, `residue`, `basic` and `deadCode`.
|
|
326
326
|
6. Examine each important finding. Disassemble or analyze its bytes, or examine them in the emulator.
|
|
327
|
+
- Old code or old source text is evidence of the development. It does not prove the computer of the authors, the order of their work, or the path of a copy through the crackers.
|
|
327
328
|
7. Record each finding that you proved in the project knowledge. Do not record the full list of leftovers.
|
|
328
329
|
- Do not remove a leftover from the program. A rebuild keeps it. Only the data of a cracktro goes out: leave it out of the capture of the program.
|
|
329
330
|
- Classify a PETSCII text that you proved as a `petscii` region, and a screen code text as a `screen` region. Classify other text as `bytes`.
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
// covers the addresses where every release has bytes, and reports where the
|
|
5
5
|
// releases differ and which releases agree there. For two releases with
|
|
6
6
|
// moved code, align maps the bytes of one to the other in blocks of equal
|
|
7
|
-
// bytes. It never decides which bytes
|
|
7
|
+
// bytes. It never decides which bytes the publisher shipped: that needs evidence
|
|
8
8
|
// beyond one comparison.
|
|
9
9
|
|
|
10
10
|
import { type AddressRange, formatC64Address } from "#src/c64.ts";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: c64-reverse-engineering
|
|
3
|
-
description: Reverse engineers a C64 program or a part of it, from an unknown disk image or file to documented understanding or a rebuilt program. It selects the next unknown to examine and the task that examines it. Use it when the user asks what a program does, for example "what does this game do", "find the main loop" or "understand $2100". Use it to rebuild a program from
|
|
3
|
+
description: Reverse engineers a C64 program or a part of it, from an unknown disk image or file to documented understanding or a rebuilt program. It selects the next unknown to examine and the task that examines it. Use it when the user asks what a program does, for example "what does this game do", "find the main loop" or "understand $2100". Use it to rebuild a program from a named reference file or capture, for example "rebuild this program". It does not do the specialist work of each task itself, and it does not add a feature to a program.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
# C64 reverse engineering
|
|
@@ -22,6 +22,15 @@ Do the specialist work of each task as that task tells. Do not do it in another
|
|
|
22
22
|
- reverse engineer and rebuild the whole program
|
|
23
23
|
- The current project knowledge.
|
|
24
24
|
|
|
25
|
+
## Terms
|
|
26
|
+
|
|
27
|
+
- **Reference file**: the program file or the capture that you examined. A test compares the rebuild with it. It can be a crack, a snapshot, a memory dump, a disk image or a commercial release.
|
|
28
|
+
- **Base release**: the release whose bytes are the program of the project knowledge. Its label and its folder do not tell where the bytes came from.
|
|
29
|
+
- **Commercial original**: the release that the publisher sold. You can use this term also when nobody examined that release.
|
|
30
|
+
- **Authenticated original**: a commercial original with recorded evidence that it is genuine, for example the disk of the publisher.
|
|
31
|
+
- Write that a rebuild is identical to the commercial original only after a compare with an authenticated original. A PASS of a compare is true only for the bytes of its reference file, for example a crack.
|
|
32
|
+
- Bytes that several related copies share do not prove the bytes of the commercial original.
|
|
33
|
+
|
|
25
34
|
## Project rules
|
|
26
35
|
|
|
27
36
|
- One repository can hold several programs, with one project folder for each program. Work on one project at a time.
|
|
@@ -73,7 +82,7 @@ Select the path for the scope:
|
|
|
73
82
|
| A routine that another program of the workspace has, for example a music driver | Match the program against the routine library of the workspace. |
|
|
74
83
|
| Source code from the knowledge | Generate the source from the project knowledge. |
|
|
75
84
|
| Source code to build | Assemble the source. |
|
|
76
|
-
| Proof that a rebuild behaves as the
|
|
85
|
+
| Proof that a rebuild behaves as the reference file | Test the rebuild against the reference file. |
|
|
77
86
|
|
|
78
87
|
4. Interpret the result. Keep observed facts apart from your conclusions.
|
|
79
88
|
5. Record each conclusion that the evidence supports in the project knowledge: names of routines and variables, data classifications, comments.
|
|
@@ -85,30 +94,36 @@ Do the stages in this sequence. Go to the next stage only when its exit check is
|
|
|
85
94
|
|
|
86
95
|
| Stage | Work | Exit check |
|
|
87
96
|
|---|---|---|
|
|
88
|
-
| 1. Acceptance | Ask the user for the criteria of the rebuild. Offer
|
|
89
|
-
| 2. Get | List the disk image. Extract the start file into `
|
|
97
|
+
| 1. Acceptance | Ask the user for the criteria of the rebuild. Offer a build of the base release that is identical to its bytes in the project knowledge. Also offer a passed replay of each recording on the default build. Also offer test scenarios and a list of the code that no run executed. Also offer documentation of the flows, tables, formats and graphics. | The user gave the criteria. |
|
|
98
|
+
| 2. Get | List the disk image. Extract the start file into `releases/`. | The start file is in the project. |
|
|
90
99
|
| 3. Start | Find the SYS address of the BASIC start. | You have the entry address. |
|
|
91
100
|
| 4. Unpack | Examine the program for a packer. Trace it and find its stages. Capture a packed program into `.c64-re-tools/local/`. When a segment is the data of a cracktro and the program does not read it, capture again and exclude that range. Put the capture, or the PRG of a program without a packer, into the project knowledge. | The program in the project knowledge has the segments and the entry. |
|
|
92
101
|
| 5. Run | First, record. Ask the user to play each part that the scope names, in a recording session. Tell the user which parts. Record a part yourself only when the sessions of the user do not have it. Put the recordings in `tests/recordings/`. Then run the parts that a recording cannot have, in the emulator or as test runs. Write a coverage map for each part into `.c64-re-tools/local/`. Add the maps and the `coverage.bin` of each recording to the project knowledge. | The program in the project knowledge has a coverage map for each part that the scope names. |
|
|
93
102
|
| 6. Analyze | Analyze the program statically. The analysis reads the program and the coverage from the project knowledge. | No coverage conflict is open. |
|
|
94
103
|
| 7. Name | If the workspace has a routine library, match the program against it. Write the names of the matches to the project knowledge. Then name each routine in the scope and give it a comment. Find the platform addresses in the memory map of the C64. Record the modules. Put the modules of one part of the program in one folder, for example `music/`, `irq/` or `graphics/`. When the scope has hundreds of routines, ask the user which routines to name. The source gives the other routines an `l_xxxx` label. | Each routine that the user selected has a name and a comment. |
|
|
95
|
-
| 8. Releases and switches | Record the
|
|
104
|
+
| 8. Releases and switches | Record the examined reference file, or its capture, as the base release in the project knowledge. The project knowledge keeps the bytes of each release. Record each other release. Compare the releases. Find the leftovers. Record a switch for each copy protection, trainer, cheat, crack change and correction. Record a patch for each range of a switch. Record each leftover as a region with a comment. | The project knowledge lists each switch. Each difference between the releases is in a patch, or the answer gives it as an exception. |
|
|
96
105
|
| 9. Generate | Generate the source from the project knowledge into `src`. For an unpacked program, also generate the loader. | The result of the generation is PASS. A release whose code is at other addresses is a version with a project of its own, or an exception in the answer. See "Versions of one program". |
|
|
97
|
-
| 10. Build and test | Build the base release into `build/`, and compare it with the
|
|
98
|
-
| 11. Document | When the criteria ask for documentation, generate it into `README.md` and `docs/`. For versions in a group folder, also write the shared pages of the group folder. Then link the pages. | The link check of the documentation gives PASS. |
|
|
106
|
+
| 10. Build and test | Build the base release into `build/`, and compare it with the base release in the project knowledge. The compare includes each segment of the base release. Build the default build. For a generated source with a loader, the default build is `build/clean_loader.prg`. Else it is `build/clean.prg`. Replay each recording on the default build. For each replay, give the checkpoint routine, the state and the random state with the names of stage 7. Then do only the tests that the next paragraph gives. | The criteria of stage 1 are true. |
|
|
107
|
+
| 11. Document | When the criteria ask for documentation, generate it into `README.md` and `docs/`. For versions in a group folder, also write the shared pages of the group folder. Write the reference files and the limits of the evidence in the first paragraph. Then link the pages. | The link check of the documentation gives PASS. Each claim stays in the limits of its evidence. |
|
|
99
108
|
| 12. Hand over | Find each file that you made outside `.c64-re-tools/local/` and that is not a deliverable. Move it into `.c64-re-tools/local/`. Then give the answer (below). | Each file that you made outside `.c64-re-tools/local/` is a deliverable. |
|
|
100
109
|
|
|
101
110
|
In stage 5, make the recordings before you change the program. A recording needs no names, and its coverage gives the analysis of stage 6 more code. If you cannot get to a part of the program, ask the user how to get to it. Do stages 7 to 9 again until the source is clear. Each generation writes the source again.
|
|
102
111
|
|
|
112
|
+
In stage 10, a build that is identical to the base release proves the source. It proves only the bytes of the base release. Do not test the base release more. The capture of stage 4 can leave out ranges, for example the data of a cracktro. Give each such range in the answer. The default build is different from the base release only in its patches, its leftovers and its loader. The replays on the default build test these differences:
|
|
113
|
+
|
|
114
|
+
- Replay only the default build: `build/clean_loader.prg` for a source with a loader, else `build/clean.prg`. Do not replay a release build or a build with a switch that is not at its default.
|
|
115
|
+
- Write a test scenario only for a test that a replay cannot do. Examples are a program that loads more files from a disk, and a criterion of the user.
|
|
116
|
+
- Do the other tests of stage 1 only when the user selected them.
|
|
117
|
+
|
|
103
118
|
After stage 7, save each routine that other programs can have to the routine library of the workspace. Examples are a music driver, a decruncher and a loader. Ask the user before you make a library.
|
|
104
119
|
|
|
105
120
|
### Deliverables of a full rebuild
|
|
106
121
|
|
|
107
122
|
- `.c64-re-tools/knowledge/` with the program, its entry state, the coverage, the names, the regions, the comments, the modules, the releases, the switches and the patches
|
|
108
|
-
- the files of the program in `
|
|
123
|
+
- the files of the program in `releases/`, as the user gave them
|
|
109
124
|
- the generated source
|
|
110
125
|
- the built program and the loader
|
|
111
|
-
- the test scenarios
|
|
126
|
+
- the test scenarios, if you wrote them
|
|
112
127
|
- the recordings in `tests/recordings/`
|
|
113
128
|
- the documentation in `README.md` and `docs/`, when the criteria ask for it
|
|
114
129
|
- the runs in `runs/` that the knowledge gives as evidence
|
|
@@ -132,7 +147,7 @@ Keep observed facts apart from your conclusions.
|
|
|
132
147
|
If the project has no layout, use this one. No script checks it. Each script takes the paths that you give.
|
|
133
148
|
|
|
134
149
|
```
|
|
135
|
-
|
|
150
|
+
releases/ the disk image or the program as you got it
|
|
136
151
|
src/ the generated source
|
|
137
152
|
build/ the built programs. Do not commit them: each build writes them again.
|
|
138
153
|
tests/ the test scenarios, and the recordings in tests/recordings/
|
|
@@ -168,7 +183,7 @@ Some releases of a program have a different layout. Their code is at different a
|
|
|
168
183
|
4. Keep the releases with the same layout in one version. Record them as releases with switches. For example, `v2` holds a base release and a second release from a different crack.
|
|
169
184
|
5. Save the routines of `v1` to the routine library in `<game>/library/`. Give `--library ../library`, because `--library` is relative to the project folder. In stage 7 of `v2`, match the program against that library. Then `v2` gets the names of `v1` for the same routines.
|
|
170
185
|
6. Use the same folders in each version, for example `src` and `docs/reference`.
|
|
171
|
-
7. From the group folder, give `--project v1` or `--project v2` to each script. A script can read a file of another version, for example `../v1/
|
|
186
|
+
7. From the group folder, give `--project v1` or `--project v2` to each script. A script can read a file of another version, for example `../v1/releases/<file>`. Use this to compare the releases of two versions. Record each release only in the project of its version.
|
|
172
187
|
8. Write the facts that the versions share one time, in the pages of the group folder. The pages of each version tell only how that version works.
|
|
173
188
|
|
|
174
189
|
## Knowledge
|
|
@@ -51,7 +51,7 @@ To get the command list, run the script with no arguments.
|
|
|
51
51
|
- Give each path relative to the project folder. The project folder is the nearest folder at or above the working directory that holds `.c64-re-tools/`.
|
|
52
52
|
- If the working directory is not in a project, give `--project <folder>` to each command. If the working directory has projects below it, the script refuses and lists them.
|
|
53
53
|
- In a group folder, each version of a program is a project. The script refuses the group folder and each folder in it that is not a project. Give `--project` with a project of the group, for example `--project v1`.
|
|
54
|
-
- A path that a command only reads can go into another project of the group, for example `../v1/
|
|
54
|
+
- A path that a command only reads can go into another project of the group, for example `../v1/releases/game.prg`. The command writes only in its own project.
|
|
55
55
|
- An address is `$` and 1 to 4 hex digits, for example `'$c000'` or `'$fb'`, or a name. A name is a symbol, else an analyzer name that only one analyzer gives. Put an address in single quotes in a shell.
|
|
56
56
|
- A range is `<start>-<end>`, for example `'$c000-$cfff'`. In a JSON file, a range is `start` and `end`.
|
|
57
57
|
- Bytes in a JSON file are hex in a field `data`, for example `"data": "a900"`.
|
|
@@ -119,7 +119,8 @@ To make the source better, change the project knowledge. Then generate again.
|
|
|
119
119
|
- `patchesNotWritten`: each patch that the source does not have, with its range, `switch` and `reason`.
|
|
120
120
|
- `switches`, `default`, `releases`: the checks of the switches. See "Switches and releases".
|
|
121
121
|
- `loader`: the check of the loader. See "The loader".
|
|
122
|
-
- `staleLoader`: a run without `--loader` kept `loader.asm` and the loader program of another knowledge revision. `files` gives the files. `revision` gives the revision of `loader.asm
|
|
122
|
+
- `staleLoader`: a run without `--loader` kept `loader.asm` and the loader program of another knowledge revision, or of another version of the toolkit. `files` gives the files. `revision` gives the revision of `loader.asm`, and `version` its toolkit version. Without `revision`, `loader.asm` does not give one. `noEntryState: true` tells that the knowledge has no entry state for a new loader. A change in a space that the loader does not hold does not make the loader stale. The loader holds space `c64` and the space of the stage of the start screen.
|
|
123
|
+
- `staleReference`: each reference folder of the project that has pages of this source from an earlier knowledge revision. Each item has the `folder` and the `revision` of its pages.
|
|
123
124
|
|
|
124
125
|
`result` is `FAIL` for each of these:
|
|
125
126
|
|
|
@@ -148,6 +149,7 @@ Do these actions for the findings:
|
|
|
148
149
|
| `conflict` | The knowledge has conflicts from a git merge. Merge the open changes of the project knowledge. Then run the command again. |
|
|
149
150
|
| A list with `rest` | Give a larger `--max-listed`. For `notExecuted`, read the file in `rest`. |
|
|
150
151
|
| `staleLoader` | The loader can copy bytes that are not the bytes of the source. Run `nextAction`, which generates with `--loader`. With `noEntryState: true`, remove the files when the build does not use them. |
|
|
152
|
+
| `staleReference` | The reference pages do not agree with the new source. When you do not change the knowledge again, generate the reference pages again from this source into each `folder`. |
|
|
151
153
|
|
|
152
154
|
#### The source files
|
|
153
155
|
|
|
@@ -155,7 +157,7 @@ Do these actions for the findings:
|
|
|
155
157
|
- Each module in the knowledge is one file. A module starts at its address. It stops at the next module or at the end of its segment. The file of a module can be in a folder, for example `music/driver.asm`. Without modules, each segment is one file, `segments/segment_xxxx.asm`.
|
|
156
158
|
- `constants.asm` holds the names of addresses outside the program, for example `EXTCOL = $d020`. It also holds the register names in the program, for example `RASTER = $d012`. The names are in groups by memory area, in address order. Drive code and banks have one group only.
|
|
157
159
|
- The side comment of a constant is the knowledge comment of the address. Without a comment, it is the platform meaning. When the knowledge name is not the platform name, the platform name comes first. For an I/O mirror without a meaning, the comment gives the register that the mirror repeats.
|
|
158
|
-
- After the side comment, `Used:` counts how the source uses the name. The kinds are `read`, `written`, `modified`, `called`, `jumped to`, `jumped through`, `branched to`, `pointer`, `address`, `table` and `macro argument`. `address` is an immediate operand expression. `table` is an entry in a table of addresses.
|
|
160
|
+
- After the side comment, `Used:` counts how the source uses the name. The kinds are `read`, `written`, `modified`, `called`, `jumped to`, `jumped through`, `branched to`, `pointer`, `address`, `table` and `macro argument`. `address` is an immediate operand expression. `table` is an entry in a table of addresses. A macro line counts one `macro argument` for each name in its args. The other bytes that the macro reads or writes, for example the high byte of a 16-bit value, count for no name.
|
|
159
161
|
- `config.asm` holds the value of each switch, for example `PROTECTION = 0`. The switches are in groups by kind. The side comment gives the releases that have the switch on, the ranges of its patches and the comment of the switch.
|
|
160
162
|
- You can change a value in `config.asm` to 0 or 1. The next run keeps the values of the file. It adds a new switch with its default. It removes a switch that the knowledge does not have.
|
|
161
163
|
- When the knowledge has a start screen, `config.asm` also has `START_SCREEN = 1`. Set it to 0 to start the program at once. Then assemble `loader.asm` again.
|
|
@@ -167,7 +169,7 @@ Do these actions for the findings:
|
|
|
167
169
|
#### Names in the source
|
|
168
170
|
|
|
169
171
|
- A label or a constant gets the name of the address in the knowledge.
|
|
170
|
-
- Without a knowledge name, it gets the platform name, for example `EXTCOL` or `CHROUT`. A platform name wins over an analyzer name (`dxa`, `
|
|
172
|
+
- Without a knowledge name, it gets the platform name, for example `EXTCOL` or `CHROUT`. A platform name wins over an analyzer name (`dxa`, `decompiler` or `heuristic`), for example `EXTCOL` over `ld020`. A `user` or `llm` name wins over a platform name.
|
|
171
173
|
- An address in the program without a name gets `l_xxxx`.
|
|
172
174
|
- A read or a write in the I/O area `$d000-$dfff` uses the register, also when the program has RAM there. For example, `lda $dd0e` is `lda CI2CRA` and `sta $d012` is `sta RASTER`. `constants.asm` has these names. An address without a platform name stays a number, for example `sta $d800,x`. The data label of the RAM stays at its data. A `user` or `llm` name of the address wins over the register.
|
|
173
175
|
- A platform name in an operand expression of the knowledge stays in the source. When the program has the address, `constants.asm` has the name, and the RAM there keeps its label.
|
|
@@ -190,7 +192,7 @@ Do these actions for the findings:
|
|
|
190
192
|
- `; not executed $xxxx-$yyyy` starts code that no run of the coverage executed. The range is the same as in `not_executed.json`.
|
|
191
193
|
- `+inc16 ptr` is a use of a macro of the knowledge. The comments inside a use go to its side comment.
|
|
192
194
|
- `!zone patch_PROTECTION_100e` starts a patch. The condition is the switch state that the program does not have. It is `!if TRAINER` when the base release has the switch off. It is `!if PROTECTION = 0` when the base release has it on.
|
|
193
|
-
- A patch block has the code of the patch and NOP to the end of the range. `else` has the
|
|
195
|
+
- A patch block has the code of the patch and NOP to the end of the range. `else` has the code of the base release. The labels inside the range come before the zone as `name = * + n`.
|
|
194
196
|
- Alternatives are patches of two or more switches at one range. They follow as `} else { !if FIX_B {`. A line before them stops the build with `!error` when two of them are in.
|
|
195
197
|
|
|
196
198
|
#### The leftovers
|
|
@@ -201,7 +203,7 @@ A leftover is a range of the program that nothing uses: unused code, old copies
|
|
|
201
203
|
- `main.asm` builds a leftover file only when `LEFTOVERS` is 1. When it is 0, the build skips the bytes. Thus the addresses after the range do not change.
|
|
202
204
|
- `config.asm` has `LEFTOVERS = 0`. Thus the default build is the clean program, without the leftovers.
|
|
203
205
|
- Each release has `LEFTOVERS = 1`. Thus the build of a release gives the bytes of the release.
|
|
204
|
-
- The loader program never has the leftovers. The
|
|
206
|
+
- The loader program never has the leftovers. The plain form does not copy them, and the memory there keeps the bytes that were in it before. The packed form unpacks the build of `main.asm` in one piece, so the leftovers in it are $00. A leftover after the last byte of that build is not in it: the memory there keeps the bytes that were in it before.
|
|
205
207
|
- Without coverage, no range is a leftover. Put the coverage of the runs into the project knowledge. Then generate again.
|
|
206
208
|
- When `leftovers.changed` has ranges, the default build and the loader program now leave out other bytes. A test that observes the `added` bytes on the loader program gets other values there. Fill the `added` ranges in the test of the leftovers. In a test that compares them, exclude them with the reason that they are leftovers.
|
|
207
209
|
- A leftover can be wrong when the coverage does not show a use. For example, the VIC-II reads a range, or the program reads a range before it writes it. Then a test of the loader program fails. Record the region in the project knowledge, or put the coverage of more runs into it. Do not change the source.
|
|
@@ -240,7 +242,7 @@ The script writes a macro use only when the use gives the bytes of the program.
|
|
|
240
242
|
Build the program from the source in these ways:
|
|
241
243
|
|
|
242
244
|
- The build of `config.asm`: no option. With the defaults, this is the default build, without the leftovers.
|
|
243
|
-
- A release: the build option `--release
|
|
245
|
+
- A release: the build option `--release FIRESTAR`.
|
|
244
246
|
- One switch: set its value in `config.asm`, for example `TRAINER = 1`. Do not define a switch on the command line of the build. ACME stops with `Symbol already defined`, because `config.asm` also sets the switch.
|
|
245
247
|
|
|
246
248
|
#### The loader
|
|
@@ -264,7 +266,7 @@ The loader does these steps:
|
|
|
264
266
|
|
|
265
267
|
The copy table, the copier and the jump use labels, not numbers. `loader_from_xxxx` and `loader_end_xxxx` are around each packed segment. `loader_to_xxxx` is its first address in place. Thus a segment can change its length, and the loader still works.
|
|
266
268
|
|
|
267
|
-
The loader changes the free stack byte below the stack pointer (`stackByte`). It does not set the SID, the time of day of the CIAs, the CIA interrupt flags or the interrupt registers of the VIC-II. A program that reads SID voice 3 for random numbers can thus give a different result. A start screen writes the colour RAM, and the loader does not set it again. When you compare the
|
|
269
|
+
The loader changes the free stack byte below the stack pointer (`stackByte`). It does not set the SID, the time of day of the CIAs, the CIA interrupt flags or the interrupt registers of the VIC-II. A program that reads SID voice 3 for random numbers can thus give a different result. A start screen writes the colour RAM, and the loader does not set it again. When you compare the reference and the rebuild, observe after the program sets its own random numbers.
|
|
268
270
|
|
|
269
271
|
The script builds and checks the loader program with the values of `config.asm`. With the defaults, the loader program is the clean program: no copy protection, all corrections and no leftovers. The entry state is the state of the base release. For a loader of a release, build `loader.asm` with the build option `--release <label>`. That loader also does not have the leftovers.
|
|
270
272
|
|
|
@@ -279,7 +281,7 @@ The start screen:
|
|
|
279
281
|
`loader` holds these fields:
|
|
280
282
|
|
|
281
283
|
- `program`, the `copies` in their order, `copier` and `stackByte`.
|
|
282
|
-
- `verified: true`: the check ran the loader program to its jump to the entry. There, the memory, $00/$01, the registers and the VIC-II are equal to the entry state. The raster line and the CIA values are also equal. An interrupt can run right at the entry, as in the
|
|
284
|
+
- `verified: true`: the check ran the loader program to its jump to the entry. There, the memory, $00/$01, the registers and the VIC-II are equal to the entry state. The raster line and the CIA values are also equal. An interrupt can run right at the entry, as in the program of the base release.
|
|
283
285
|
- `limits`: each CIA value that the loader cannot set as it was at the entry. An old capture has no CIA values. Then capture the program again at its entry point.
|
|
284
286
|
- `startScreen`: with a start screen, `shown: true` when the VIC-II had the values of the start screen, and `waits: true` when the start screen waited without a key. `wait` and `continue` are the addresses of the wait and of the code after it. The check sets the PC to `continue`, and then runs the loader to its jump.
|
|
285
287
|
- `packed`: `packedBytes` and `unpackedBytes` of the packed form. With a start screen of a captured stage, this is the packed program in the loader program.
|
|
@@ -320,7 +322,7 @@ The program is packed while the screen shows. Thus the picture and the tune have
|
|
|
320
322
|
- The loader program has only the bytes of the stage that the start screen uses. These are the screen, the bitmap and the charset. With a call, they are also each byte of the stage that is not free from the call, as in "The free ranges". A call thus needs the coverage of the stage.
|
|
321
323
|
- With colours from the colour RAM of the capture, the show code holds the 1000 colours. It copies them to the colour RAM.
|
|
322
324
|
- The patches of the stage are in at the defaults of their switches. Thus a patch under a switch can remove the text of a crack from the picture.
|
|
323
|
-
- `start_screen_stage.asm` holds the show code and the bytes of the stage. Do not edit it. To make the loader program again, run `generate --loader`.
|
|
325
|
+
- `start_screen_stage.asm` holds the show code and the bytes of the stage. Do not edit it. To make the loader program again, run `generate --out <dir> --loader`.
|
|
324
326
|
- The show stage needs Exomizer. The show code needs free memory in $0400-$9fff or $c000-$cfff. When the memory is too small, the reason gives the largest free ranges.
|
|
325
327
|
- The check runs the loader program to `loader_start_screen_wait` of the show stage. There, it compares the VIC-II with the start screen, the screen bytes in memory with the stage, and the colour RAM with the capture. Then it sets the PC to `loader_start_screen_continue`, and it checks the loader as usual.
|
|
326
328
|
|
|
@@ -335,10 +337,10 @@ A loader file that loads into $d000 or higher writes the I/O area. When the prog
|
|
|
335
337
|
To make the packed loader for other switch values, do these steps:
|
|
336
338
|
|
|
337
339
|
1. Assemble `main.asm` without an output path. The build name of the program tells the switch values, for example `build/custom_trainer.prg`. The leftovers are $00 in this build.
|
|
338
|
-
2. Assemble `loader.asm` without an output path, for example to `build/
|
|
340
|
+
2. Assemble `loader.asm` without an output path, for example to `build/custom_trainer_copier.prg`. This is the copier. The build name has `copier` in place of `loader`, so the build does not write over the loader program.
|
|
339
341
|
3. Pack the two files into `build/custom_trainer_packed.prg`. The start address is the copier address in the comment at the start of `loader.asm`. The memory configuration at the exit is `$34`.
|
|
340
342
|
|
|
341
|
-
These steps do not work when a segment starts below $0400. They also do not work when a patch is between the free ranges of `loader.asm`. In these cases, use `generate --loader` for the base release.
|
|
343
|
+
These steps do not work when a segment starts below $0400. They also do not work when a patch is between the free ranges of `loader.asm`. In these cases, use `generate --out <dir> --loader` for the base release.
|
|
342
344
|
|
|
343
345
|
---
|
|
344
346
|
|
|
@@ -377,7 +379,7 @@ On `FAIL`, `hint` gives the action for the stage:
|
|
|
377
379
|
|
|
378
380
|
| `stage` | Action |
|
|
379
381
|
|---|---|
|
|
380
|
-
| `
|
|
382
|
+
| `base` | The source of the knowledge does not pass. Run `generate`, and correct the project knowledge until `generate` gives `PASS`. Then export again. |
|
|
381
383
|
| `switches` | The build with the export values changes bytes outside the patches, or a patch does not fit. Read `build`. Run `generate`, and correct the patches. |
|
|
382
384
|
| `export` | This is a defect of the script. Give the result to the user. |
|
|
383
385
|
| `loader` | Read `reason`, and give it to the user. The export does not make the packed form of the loader. |
|
|
@@ -413,6 +415,7 @@ Data becomes free only when all of these are true:
|
|
|
413
415
|
- No run read, wrote or executed a byte of it.
|
|
414
416
|
- No code that stays reads it or names it. No table that stays has an entry in it.
|
|
415
417
|
- It is not in the BASIC line that starts the program, and not at $fffa-$ffff.
|
|
418
|
+
- No `charset`, `sprite`, `bitmap` or `screen` region has a byte of it. For example, `unused` bytes in a bitmap stay.
|
|
416
419
|
|
|
417
420
|
The coverage does not show the reads of the VIC-II. Thus `charset`, `sprite`, `bitmap` and `screen` data stay, unless `--drop` names them. The bytes of the start screen always stay. Bytes without a region also stay.
|
|
418
421
|
|
|
@@ -430,7 +433,7 @@ tests/ the tests of the project, changed for the new program
|
|
|
430
433
|
|
|
431
434
|
- The source has no mark line, no `switches.asm` or `config.asm`, no patch zones and no `; not executed` lines. A start screen stays in the loader. Build with `-DSTART_SCREEN=0` to start the program at once. It keeps the names, the comments, the operand expressions and the macros. A line comment at each changed patch gives the switch, its kind, its value and the comments.
|
|
432
435
|
- The knowledge has one revision `export`. It holds the program, the entry and its state, the names, the comments, the regions, the modules and the start screen. It has no history, analyzer names, references, operand expressions, macros, patches, switches, releases or coverage.
|
|
433
|
-
- A scenario of `tests/` compares the build of the new project with the baseline. Both sides are the same program. Thus a step of the
|
|
436
|
+
- A scenario of `tests/` compares the build of the new project with the baseline. Both sides are the same program. Thus a step of the reference side alone goes. A step of the rebuild side alone runs on both sides.
|
|
434
437
|
- A run file of `tests/` runs the build of the new project. Scenarios and run files take the names from the symbol files.
|
|
435
438
|
- The export leaves out a test that restores a snapshot. It also leaves out a test with a name that the new program does not have, or with an address in a free range.
|
|
436
439
|
- The export does not copy recordings, record files or `runs/`.
|
|
@@ -447,7 +450,7 @@ tests/ the tests of the project, changed for the new program
|
|
|
447
450
|
5. Record names, comments, regions and modules in the project knowledge.
|
|
448
451
|
6. Run `generate` again. Do steps 4 to 6 again until the source is clear.
|
|
449
452
|
7. Assemble `main.asm` to a program. This is the default build. For a release, give the build option `--release <label>`.
|
|
450
|
-
8. For an unpacked program, run `generate
|
|
453
|
+
8. For an unpacked program, run `generate --out <dir> --loader` at the end. Compare the loader program with the program of the base release in a test.
|
|
451
454
|
9. To start a new program from the rebuild, run `export`.
|
|
452
455
|
|
|
453
456
|
---
|
|
@@ -23,12 +23,22 @@ import { OPCODES } from "#src/opcodes.ts";
|
|
|
23
23
|
*/
|
|
24
24
|
export const DROPPABLE_DATA: readonly RegionType[] = ["bytes", "words", ...POINTER_TABLE_TYPES, "petscii", "workspace", "unused"];
|
|
25
25
|
|
|
26
|
+
/** The data that the VIC-II reads: a region of another type that overlaps it stays too, for example unused bytes in a bitmap. */
|
|
27
|
+
const VIC_DATA: readonly RegionType[] = ["charset", "sprite", "bitmap", "screen"];
|
|
28
|
+
|
|
26
29
|
/** Regions of code: their bytes are the blocks of the decoded instructions. */
|
|
27
30
|
const CODE_TYPES: readonly RegionType[] = ["code", "jumps", "dual-use"];
|
|
28
31
|
|
|
29
32
|
/** The hardware vectors $fffa-$ffff: they stay when the image holds them. */
|
|
30
33
|
const VECTORS: AddressRange = { start: 0xfffa, end: 0xffff };
|
|
31
34
|
|
|
35
|
+
/**
|
|
36
|
+
* The coverage flags that can be a use of the RAM byte: a read or a run of the
|
|
37
|
+
* ROM uses the ROM, not the RAM under it, so a JSR into the KERNAL keeps no byte
|
|
38
|
+
* of the image. The I/O flags stay, as VICE gives each access at $d000-$dfff as I/O.
|
|
39
|
+
*/
|
|
40
|
+
const RAM_ACCESS = 0xff & ~(COVERAGE.romRead | COVERAGE.romExecute);
|
|
41
|
+
|
|
32
42
|
/** The I/O area: two immediates stored there are chip values, such as a timer latch, not an address. */
|
|
33
43
|
const IO_AREA: AddressRange = { start: 0xd000, end: 0xdfff };
|
|
34
44
|
|
|
@@ -241,10 +251,10 @@ const isTable = (type: RegionType) => type === "jumps" || (POINTER_TABLE_TYPES a
|
|
|
241
251
|
*/
|
|
242
252
|
export function planDrops(input: DropInput): DropPlan {
|
|
243
253
|
const inImage = (address: number) => inside(address, input.segments);
|
|
244
|
-
const touched = (address: number) => input.coverage !== undefined && input.coverage[address] !== 0;
|
|
254
|
+
const touched = (address: number) => input.coverage !== undefined && (input.coverage[address]! & RAM_ACCESS) !== 0;
|
|
245
255
|
const executed = (address: number) => input.coverage !== undefined && (input.coverage[address]! & COVERAGE.ramExecute) !== 0;
|
|
246
256
|
const regions = input.regions.flatMap((region) => input.segments.filter((segment) => overlaps(region, segment)).map((segment) => ({ start: Math.max(region.start, segment.start), end: Math.min(region.end, segment.end), type: region.type })));
|
|
247
|
-
// The source writes a data region as data, also where
|
|
257
|
+
// The source writes a data region as data, also where the decompiler decoded instructions in it: those are no code.
|
|
248
258
|
const instructions = new Map([...input.instructions].filter(([start, length]) => !regions.some((region) => !CODE_TYPES.includes(region.type) && start <= region.end && region.start <= start + length - 1)));
|
|
249
259
|
const blocks = blocksOf(instructions, input.memory);
|
|
250
260
|
// An indexed operand reads in the region that holds it, and in the next region when it is the last byte (table-1,x).
|
|
@@ -323,6 +333,7 @@ export function planDrops(input: DropInput): DropPlan {
|
|
|
323
333
|
const units = automatic
|
|
324
334
|
? regions.filter((region) => {
|
|
325
335
|
if (!DROPPABLE_DATA.includes(region.type) || gone.some((range) => overlaps(range, region))) return false;
|
|
336
|
+
if (regions.some((other) => VIC_DATA.includes(other.type) && overlaps(other, region))) return false;
|
|
326
337
|
if ([...input.keep, ...input.changed, VECTORS, ...(input.basic === undefined ? [] : [input.basic])].some((range) => overlaps(range, region))) return false;
|
|
327
338
|
for (let address = region.start; address <= region.end; address++) if (touched(address)) return false;
|
|
328
339
|
return true;
|
|
@@ -397,7 +408,7 @@ const hasSnapshot = (value: unknown): boolean =>
|
|
|
397
408
|
/**
|
|
398
409
|
* A scenario or a run file of the project for the new project. A scenario
|
|
399
410
|
* compares the baseline (the exported program) with the build of the new
|
|
400
|
-
* project: a step of the
|
|
411
|
+
* project: a step of the reference side alone goes, and a step of the rebuild
|
|
401
412
|
* side alone runs on both sides. A run file runs the build. A test is left out when it restores a
|
|
402
413
|
* snapshot (a state of the old program), names something that the exported
|
|
403
414
|
* program does not have, or names an address in a free range.
|
|
@@ -411,8 +422,9 @@ export function rewriteTest(text: string, name: string, symbols: ReadonlyMap<str
|
|
|
411
422
|
} catch {
|
|
412
423
|
return { reason: "it is not JSON" };
|
|
413
424
|
}
|
|
414
|
-
const scenario = typeof test.
|
|
425
|
+
const scenario = typeof test.reference === "object" && typeof test.rebuild === "object" && Array.isArray(test.steps);
|
|
415
426
|
const run = typeof test.start === "object" && test.start !== null && Array.isArray(test.steps);
|
|
427
|
+
if (!scenario && typeof test.rebuild === "object" && Array.isArray(test.steps)) return { reason: "it is a scenario without a reference side. A scenario has reference, rebuild and steps" };
|
|
416
428
|
if (!scenario && !run) return { reason: "it is not a scenario or a run file" };
|
|
417
429
|
if (hasSnapshot(test)) return { reason: "it restores a snapshot, which is a state of the old program" };
|
|
418
430
|
for (const location of locationsOf(test.steps)) {
|
|
@@ -423,14 +435,14 @@ export function rewriteTest(text: string, name: string, symbols: ReadonlyMap<str
|
|
|
423
435
|
}
|
|
424
436
|
const side = (program: string) => ({ program: `${program}.prg`, symbols: symbolsPath(`${program}.prg`) });
|
|
425
437
|
if (scenario) {
|
|
426
|
-
// Both sides are the exported program now: a step of the
|
|
427
|
-
const {
|
|
438
|
+
// Both sides are the exported program now: a step of the reference alone (for example a key for its intro) goes, and a step of the rebuild alone runs on both sides.
|
|
439
|
+
const { reference: _reference, rebuild: _rebuild, steps, ...rest } = test;
|
|
428
440
|
const both = (steps as unknown[]).flatMap((step) => {
|
|
429
441
|
if (step === null || typeof step !== "object" || !("side" in step)) return [step];
|
|
430
442
|
const { side: only, ...action } = step as Record<string, unknown>;
|
|
431
|
-
return only === "
|
|
443
|
+
return only === "reference" ? [] : [action];
|
|
432
444
|
});
|
|
433
|
-
return { kind: "scenario", text: `${JSON.stringify({ ...rest,
|
|
445
|
+
return { kind: "scenario", text: `${JSON.stringify({ ...rest, reference: side(`baseline/${name}`), rebuild: side(`build/${name}`), steps: both }, null, 2)}\n` };
|
|
434
446
|
}
|
|
435
447
|
const start = test.start as Record<string, unknown>;
|
|
436
448
|
const symbolsFile = test.symbols === undefined || test.symbols === "none" ? {} : { symbols: symbolsPath(`build/${name}.prg`) };
|