@henols/c64-re-tools 2.3.0-rc.5 → 2.3.0-rc.6
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 +149 -78
- package/skills/c64-assembler/scripts/assembler.ts +18 -11
- package/skills/c64-basic/SKILL.md +90 -52
- package/skills/c64-basic/scripts/basic.ts +15 -6
- package/skills/c64-development/SKILL.md +46 -73
- package/skills/c64-disk/SKILL.md +145 -73
- package/skills/c64-disk/scripts/disk.ts +11 -6
- package/skills/c64-docs/SKILL.md +199 -118
- package/skills/c64-docs/references/page-types.md +3 -3
- package/skills/c64-docs/references/style.md +9 -13
- package/skills/c64-docs/scripts/docs.ts +39 -15
- package/skills/c64-docs/scripts/lib/links.ts +1 -1
- package/skills/c64-docs/scripts/lib/reference.ts +2 -2
- package/skills/c64-docs/scripts/lib/source-map.ts +2 -2
- package/skills/c64-export/SKILL.md +21 -45
- package/skills/c64-knowledge/SKILL.md +489 -233
- package/skills/c64-knowledge/scripts/knowledge.ts +31 -26
- package/skills/c64-memory-map/SKILL.md +131 -65
- package/skills/c64-memory-map/scripts/memory-map.ts +19 -11
- package/skills/c64-packer/SKILL.md +120 -72
- package/skills/c64-packer/scripts/packer.ts +10 -3
- package/skills/c64-provenance/SKILL.md +301 -173
- package/skills/c64-provenance/scripts/lib/library.ts +6 -6
- package/skills/c64-provenance/scripts/provenance.ts +85 -36
- package/skills/c64-reverse-engineering/SKILL.md +55 -72
- package/skills/c64-source/SKILL.md +316 -224
- package/skills/c64-source/scripts/lib/export.ts +9 -14
- package/skills/c64-source/scripts/lib/loader.ts +5 -5
- package/skills/c64-source/scripts/lib/source.ts +5 -5
- package/skills/c64-source/scripts/source.ts +106 -21
- package/skills/c64-static-analysis/SKILL.md +188 -112
- package/skills/c64-static-analysis/scripts/static-analysis.ts +29 -9
- package/skills/c64-testing/SKILL.md +272 -166
- package/skills/c64-testing/references/recording-format.md +11 -12
- package/skills/c64-testing/references/scenario-format.md +20 -5
- package/skills/c64-testing/scripts/lib/diff-files.ts +8 -8
- package/skills/c64-testing/scripts/lib/recording.ts +7 -7
- package/skills/c64-testing/scripts/lib/replay.ts +7 -7
- package/skills/c64-testing/scripts/lib/runs.ts +6 -7
- package/skills/c64-testing/scripts/lib/scenario.ts +12 -6
- package/skills/c64-testing/scripts/testing.ts +35 -15
- package/skills/c64-unpacker/SKILL.md +273 -127
- package/skills/c64-unpacker/scripts/lib/loads.ts +3 -3
- package/skills/c64-unpacker/scripts/unpacker.ts +70 -11
- package/skills/emulator/SKILL.md +12 -12
- package/src/errors.ts +22 -2
- package/src/host/vice/session.ts +1 -1
- package/src/host-client/entry-state.ts +1 -1
- package/src/host-client/image.ts +3 -3
- package/src/host-client/steps.ts +1 -1
- package/src/knowledge/expression.ts +1 -1
- package/src/knowledge/names.ts +2 -3
- package/src/knowledge/program.ts +2 -3
- package/src/knowledge/write.ts +2 -2
- package/src/mcp/inputs.ts +1 -1
- package/src/mcp/tools/input.ts +1 -1
- package/src/mcp/tools/media.ts +1 -1
- package/src/native/exomizer.ts +2 -2
- package/src/project.ts +2 -2
- package/src/script.ts +164 -75
|
@@ -1,255 +1,387 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: c64-knowledge
|
|
3
|
-
description:
|
|
3
|
+
description: Reads and changes the durable knowledge of a C64 project in .c64-re-tools/knowledge/. The knowledge holds the program and the coverage of the runs. It holds the names, regions, comments and references, and the releases, switches, patches and macros of the source. It keeps the history of each change. Use it to find the knowledge at an address or a name. Use it to record a name, a region, a comment or a reference after you interpret the evidence. Use it to put a program or the coverage of runs into the project. Use it to record the releases, switches, patches and macros of the generated source. Use it to read the history, to revert to an earlier revision, or to decide the conflicts of a git merge. It does not run the program, analyze the machine code or generate the source.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
#
|
|
6
|
+
# C64 knowledge
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
Use this script to read and change the knowledge of a C64 project.
|
|
9
|
+
Use only the commands of the script. Do not read or change the project knowledge in another way.
|
|
9
10
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
## Inputs
|
|
15
|
-
|
|
16
|
-
One of these:
|
|
11
|
+
```bash
|
|
12
|
+
node <skill>/scripts/knowledge.ts <command>
|
|
13
|
+
```
|
|
17
14
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
- a request to see the history or a revision.
|
|
15
|
+
`<skill>` is the base directory of this skill. Run the script with `node`. You can run it from any directory.
|
|
16
|
+
Each command in this skill, for example `at '$2100'`, goes in the place of `<command>`.
|
|
17
|
+
Each command prints one JSON envelope on stdout. See the section "JSON output".
|
|
18
|
+
To get the command list, run the script with no arguments.
|
|
23
19
|
|
|
24
|
-
|
|
20
|
+
The knowledge is text in `.c64-re-tools/knowledge/` of the project. Commit that folder with git. Do not edit its files yourself. The script checks each change.
|
|
25
21
|
|
|
26
|
-
|
|
27
|
-
node <skill>/scripts/knowledge.ts <command> [subjects] [options]
|
|
28
|
-
```
|
|
22
|
+
---
|
|
29
23
|
|
|
30
|
-
|
|
24
|
+
## Select the command
|
|
31
25
|
|
|
32
|
-
|
|
|
26
|
+
| Goal | Command |
|
|
33
27
|
|---|---|
|
|
34
|
-
|
|
|
28
|
+
| Find all knowledge at one address | `at '$2100'` |
|
|
35
29
|
| Find names and comment text | `search player` |
|
|
36
|
-
|
|
|
37
|
-
|
|
|
38
|
-
|
|
|
39
|
-
|
|
|
40
|
-
|
|
|
41
|
-
|
|
|
42
|
-
|
|
|
43
|
-
|
|
|
44
|
-
|
|
|
45
|
-
|
|
|
30
|
+
| List the symbols in a range | `symbols --range '$2000-$2fff'` |
|
|
31
|
+
| List the names that the analyzers gave | `symbols --analyzer` |
|
|
32
|
+
| List only the facts of the user and the LLM | `symbols --origin semantic` |
|
|
33
|
+
| List the regions, comments or references in a range | `regions --range '$2000-$2fff'` |
|
|
34
|
+
| Show the code of a range with names, comments, access and references | `listing '$0400-$04ff'` |
|
|
35
|
+
| Write all knowledge to one file | `export --out .c64-re-tools/local/knowledge.json` |
|
|
36
|
+
| Find what the knowledge holds of the program | `program` |
|
|
37
|
+
| Put a captured program into the knowledge | `image .c64-re-tools/local/capture/image.json` |
|
|
38
|
+
| Put a PRG into the knowledge | `image original/game.prg` |
|
|
39
|
+
| Put drive code into the knowledge | `image drive.prg --space drive8` |
|
|
40
|
+
| Add the coverage of runs | `coverage .c64-re-tools/local/runs/rooms/room0.bin` |
|
|
41
|
+
| Name the symbol at an address | `rename '$2100' update_player --kind routine --reason 'reads joystick 2'` |
|
|
46
42
|
| Remove a symbol | `remove-symbol '$2100'` |
|
|
47
43
|
| Classify memory | `classify '$3000-$303f' sprite` |
|
|
48
44
|
| Classify a table of records | `classify '$3000-$303b' bytes --element 6` |
|
|
49
|
-
| Many writes as one revision | `apply -` with the JSON on standard input, or `apply <file>` |
|
|
50
|
-
| One batch from the batches of parallel agents | `join a.json b.json --out .c64-re-tools/local/joined.json` |
|
|
51
45
|
| Make memory unknown, and keep the analyzers out of it | `unclassify '$3000-$303f'` |
|
|
52
|
-
|
|
|
53
|
-
| Add
|
|
54
|
-
|
|
|
55
|
-
| Start a file of generated source | `module '$2000' player.asm --title 'Player movement'`
|
|
56
|
-
| Write the operand of an instruction as an expression | `operand '$8079' --lo irq_handler`
|
|
57
|
-
|
|
|
58
|
-
|
|
|
59
|
-
| Write
|
|
60
|
-
|
|
|
61
|
-
|
|
|
62
|
-
| Write a macro | `
|
|
63
|
-
|
|
|
64
|
-
|
|
|
65
|
-
|
|
|
66
|
-
|
|
|
67
|
-
|
|
|
68
|
-
| Go back to an earlier state | `revert 20261015T2145` for all spaces, or `revert 20261015T2145 --space bank3` for one space |
|
|
46
|
+
| Write a comment | `comment '$2100' line Reads joystick 2.` |
|
|
47
|
+
| Add a reference | `reference '$2000' '$2100' call` |
|
|
48
|
+
| Find the places that a removal blocks | `suppressions --range '$2000-$2fff'` |
|
|
49
|
+
| Start a file of the generated source | `module '$2000' player.asm --title 'Player movement'` |
|
|
50
|
+
| Write the operand of an instruction as an expression | `operand '$8079' --lo irq_handler` |
|
|
51
|
+
| Record a release of the program | `release ORIGINAL --file original/game.prg --base` |
|
|
52
|
+
| Write a switch | `switch PROTECTION --kind protection --releases ORIGINAL` |
|
|
53
|
+
| Write the code of a switch for a range | `patch '$100e-$1010' PROTECTION --code-file no-check.asm` |
|
|
54
|
+
| List the releases, switches and patches | `switches` |
|
|
55
|
+
| Write a macro | `macro inc16 --params dst --body-file inc16.asm` |
|
|
56
|
+
| Write instructions as one use of a macro | `use '$1005-$100a' inc16 --args ptr` |
|
|
57
|
+
| Do many writes as one revision | `apply .c64-re-tools/local/batch.json` |
|
|
58
|
+
| Make one batch from the batches of parallel agents | `join a.json b.json --out .c64-re-tools/local/joined.json` |
|
|
59
|
+
| Read the history of an address or a name | `history '$2100'` |
|
|
60
|
+
| Read the last revisions | `revisions` |
|
|
61
|
+
| Go back to an earlier state | `revert 20261015T2145` |
|
|
69
62
|
| Decide the conflicts after a git merge | `merge --reason 'merge of two computers'` |
|
|
70
63
|
|
|
71
|
-
|
|
64
|
+
---
|
|
72
65
|
|
|
73
|
-
|
|
66
|
+
## Addresses, names and spaces
|
|
74
67
|
|
|
75
|
-
|
|
68
|
+
- A symbol is the name of an address from the user or the LLM. Get it from `at`, `search` or `symbols`.
|
|
69
|
+
- An analyzer name is a second name from DXA, Ghidra or an idiom search, for example `FUN_17e2`. Each analyzer keeps its own name at an address. Get them from `at`, `search` or `symbols --analyzer`.
|
|
70
|
+
- The generated source uses only the symbols. To use an analyzer name in the source, give the address that name with `rename`.
|
|
71
|
+
- A symbol name is a label for ACME: a letter or an underscore, then letters, digits or underscores. The knowledge refuses the name of a 6502 instruction, for example `lda`, in upper or lower case.
|
|
72
|
+
- A space is `c64` (the default), `drive8` for code in the 1541 drive, or `bank0` to `bank255` for cartridge banks. Drive code and banks use the same addresses as the C64. Thus each space has its own knowledge. A name is unique in one space.
|
|
73
|
+
- A revision id has the form `20261015T214501.123-k3f9qz`. It starts with the date and the time. Give the full id, or a start of the id that only one revision has. Get the ids from `revisions`, or from the `revision` field of a result. The revision `0` is the knowledge before the first revision.
|
|
74
|
+
- A file of a capture is the `image.json` that the capture of a packed program wrote. Keep the other files of the capture next to it.
|
|
76
75
|
|
|
77
|
-
|
|
76
|
+
### Paths and the project folder
|
|
78
77
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
78
|
+
- 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/`.
|
|
79
|
+
- 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.
|
|
80
|
+
- 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.
|
|
81
|
+
- A range is `<start>-<end>`, for example `'$c000-$cfff'`. In a JSON file, a range is `start` and `end`.
|
|
82
|
+
- Bytes in a JSON file are hex in a field `data`, for example `"data": "a900"`.
|
|
83
|
+
- Write each file that you make for your work in `.c64-re-tools/local/` of the project. Git ignores that folder. Examples are results, batches, step files, runs, snapshots and memory dumps.
|
|
84
|
+
- The script refuses an `--out` path in `.c64-re-tools/knowledge/` and the index of the knowledge. Change the project knowledge only with the commands that change it.
|
|
85
|
+
- The script refuses a folder where the command writes a file. It refuses a file where the command writes a folder.
|
|
86
|
+
- When a file is the evidence for a finding in the project knowledge, move it out of `.c64-re-tools/local/` first. The project knowledge refuses evidence in that folder.
|
|
87
|
+
- Do not move a coverage map after you put it into the project knowledge. The knowledge refers to the map by its path at that time.
|
|
88
|
+
- Put a run that is evidence in `runs/<name>/`, with its run file, its results and its snapshot files. Change the paths in the run file to the new paths. Then git keeps them, and another person can do the run again.
|
|
89
|
+
- A shell redirect (`>`) is relative to the working directory, not to the project folder. From the folder above the project, write `<folder>/.c64-re-tools/local/result.json`.
|
|
90
90
|
|
|
91
|
-
|
|
91
|
+
---
|
|
92
92
|
|
|
93
|
-
|
|
93
|
+
## Flags
|
|
94
94
|
|
|
95
|
-
|
|
96
|
-
- `<script>.ts --help` lists the commands. `<script>.ts <command> --help` gives the subjects and the options of one command. The help is JSON: `{"text": "..."}`.
|
|
97
|
-
- 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. Quote an address in a shell.
|
|
98
|
-
- A range is `<start>-<end>`, for example `'$c000-$cfff'`. In a JSON file, a range is `start` and `end`.
|
|
99
|
-
- Bytes in a JSON file are hex in a field `data`, for example `"data": "a900"`.
|
|
100
|
-
- The script examines each `--out` path before it starts work. It refuses a path in `.c64-re-tools/knowledge/` and the index of the knowledge, because only c64-knowledge writes them. It refuses a folder where the command writes a file, and a file where the command writes a folder.
|
|
101
|
-
- The result is one JSON object on one line. A file that the script writes shows as `{"out", "bytes", "sha256"}`. A list shows as `{"count", "listed"}`, and `rest` tells where to get the rest of a long list.
|
|
102
|
-
- An error is `{"error": {"code": "...", "message": "..."}}`. The message tells what is wrong and what to do.
|
|
103
|
-
- The exit status is 0 for done or PASS, 1 for FAIL, 2 for an error and 3 for INCONCLUSIVE.
|
|
95
|
+
Each flag applies only to the commands in the table. On another command, the script refuses the flag.
|
|
104
96
|
|
|
105
|
-
|
|
97
|
+
| Flag | Command | Effect |
|
|
98
|
+
|---|---|---|
|
|
99
|
+
| `--space <space>` | All commands | The space of the command: `c64`, `drive8`, or `bank0` to `bank255`. The default is `c64`. Without `--space`, `revert` reverts all spaces. |
|
|
100
|
+
| `--by <user\|llm>` | All commands in "Change the knowledge" | Who decided the change. The default is `llm`. Give `user` only when the user decided the change. |
|
|
101
|
+
| `--reason <text>` | All commands in "Change the knowledge" | Why you make the change. The revision keeps it, and `history` shows it. |
|
|
102
|
+
| `--evidence <kind:ref>` | All commands in "Change the knowledge" | One thing that the change rests on: `coverage:<map>`, `test:<file>`, `file:<file>` or `note:<text>`. You can give it more than one time. |
|
|
103
|
+
| `--expect-revision <revision>` | All commands in "Change the knowledge" | Refuse the change when the knowledge changed after this revision. Give the `revision` of your last read. |
|
|
104
|
+
| `--range <start>-<end>` | `symbols`, `regions`, `comments`, `references`, `suppressions`, `modules`, `operands`, `patches`, `uses`, `export` | Only the rows in this range. The default is all addresses. |
|
|
105
|
+
| `--origin <origin>` | `search`, `symbols`, `regions`, `comments`, `references`, `modules`, `operands`, `patches`, `macros`, `uses`, `export` | Only the rows of these origins: `user`, `llm`, `dxa`, `ghidra`, `heuristic`, `semantic` (user and llm), `analyzer` (dxa, ghidra and heuristic), or a comma list. The default is all origins. |
|
|
106
|
+
| `--max-listed <n>` | `search`, `symbols`, `regions`, `comments`, `references`, `suppressions`, `modules`, `operands`, `patches`, `switches`, `releases`, `macros`, `uses`, `spaces`, `history`, `revisions`, `revision`, `listing` | The most items in each list of the body. The default is 50. The counts are always complete. |
|
|
107
|
+
| `--kind <kind>` | `symbols`, `rename` | The symbol kind: `label`, `routine`, `variable`, `data` or `vector`. A read gives all kinds by default. A new symbol without `--kind` is a `label`. A `rename` without `--kind` keeps the kind of the symbol. |
|
|
108
|
+
| `--kind <kind>` | `references` | Only references of this kind: `call`, `jump`, `read`, `write`, `reference` or `pointer`. |
|
|
109
|
+
| `--kind <kind>` | `switch` | Necessary. The switch kind: `protection`, `trainer`, `cheat`, `crack`, `fix` or `change`. |
|
|
110
|
+
| `--analyzer` | `symbols` | List the analyzer names in place of the symbols. |
|
|
111
|
+
| `--type <type>` | `regions` | Only regions of this type. |
|
|
112
|
+
| `--switch <switch>` | `patches`, `unpatch` | Only the patches of this switch. For `unpatch`, the switch of the patch to remove. |
|
|
113
|
+
| `--switch <name>` | `history` | The history of a switch and its patches in place of an address. |
|
|
114
|
+
| `--macro <name>` | `uses` | Only the uses of this macro. |
|
|
115
|
+
| `--macro <name>` | `history` | The history of a macro in place of an address. |
|
|
116
|
+
| `--name <name>` | `history` | The history of a name in place of an address. |
|
|
117
|
+
| `--before <revision>` | `revisions` | Only the revisions before this one. |
|
|
118
|
+
| `--out <file>` | `export`, `join` | Necessary. The JSON file to write. |
|
|
119
|
+
| `--out <file>` | `listing` | Write the listing as text to this file in place of the lines in the body. |
|
|
120
|
+
| `--element <n>` | `classify` | The bytes of one element of a table. The length of the range must be a multiple of it. |
|
|
121
|
+
| `--title <text>` | `module` | The title of the file. A `module` write without a title keeps the title that the module has. |
|
|
122
|
+
| `--lo <symbol>` | `operand` | The operand is the low byte of the symbol plus the offset. |
|
|
123
|
+
| `--hi <symbol>` | `operand` | The operand is the high byte of the symbol plus the offset. |
|
|
124
|
+
| `--value <symbol>` | `operand` | The operand is the symbol plus the offset. |
|
|
125
|
+
| `--expr <text>` | `operand` | The operand is this ACME expression. |
|
|
126
|
+
| `--offset <n>` | `operand` | With `--lo`, `--hi` or `--value`: a whole number to add, for example `1` or `'$1000'`. Write a negative offset as `--offset=-1`. The default is 0. |
|
|
127
|
+
| `--code <text>` | `patch` | The ACME code of the patch. |
|
|
128
|
+
| `--code-file <file>` | `patch` | A project file with the ACME code of the patch. |
|
|
129
|
+
| `--nop` | `patch` | The patch is NOP only. |
|
|
130
|
+
| `--comment <text>` | `patch`, `switch`, `release`, `macro` | A comment for the row. A `patch`, `switch` or `macro` write without `--comment` keeps the comment that the row has. |
|
|
131
|
+
| `--default <0\|1>` | `switch` | The value in the default build. See the section of `switch`. |
|
|
132
|
+
| `--releases <A,B>` | `switch` | The labels of the releases that have the switch on, as a comma list. A write without it keeps the releases that the switch has. |
|
|
133
|
+
| `--file <file>` | `release` | Necessary. The PRG or `image.json` of the release, in a folder that git keeps. |
|
|
134
|
+
| `--base` | `release` | This release is the program of the knowledge. |
|
|
135
|
+
| `--params <a,b>` | `macro` | The params of the macro, as a comma list without a dot. The default is no params. |
|
|
136
|
+
| `--body <text>` | `macro` | The body of the macro. |
|
|
137
|
+
| `--body-file <file>` | `macro` | A project file with the body of the macro. |
|
|
138
|
+
| `--args <x, y>` | `use` | One expression for each param of the macro, as a comma list. |
|
|
106
139
|
|
|
107
|
-
|
|
108
|
-
- If the working directory is not in a project and has projects below it, the script refuses and lists them. Then give `--project <folder>` to each script.
|
|
109
|
-
- Write each file that you make for your work in `.c64-re-tools/local/` of the project. Git ignores that folder. Examples are results, batches, step files, runs, snapshots and memory dumps.
|
|
110
|
-
- Move a file out of `.c64-re-tools/local/` only when it is the evidence for a finding. Move it before you give it to `--evidence test:<file>` or `--evidence file:<file>` of c64-knowledge. These two refuse a file in `.c64-re-tools/local/`.
|
|
111
|
-
- Do not move a coverage map after `coverage` of c64-knowledge imported it. `--evidence coverage:<map>` names the map by its path at the import. The knowledge keeps the coverage and the SHA-256 of the map, so the evidence stays valid.
|
|
112
|
-
- Put a run that is evidence in `runs/<name>/`, with its run file, its results and the snapshot files that it uses. Change the paths in the run file to the new paths. Then git keeps them, and another person can do the run again.
|
|
113
|
-
- A shell redirect (`>`) is relative to the working directory, not to the project folder. From the folder above the project, write `<folder>/.c64-re-tools/local/result.json`.
|
|
140
|
+
---
|
|
114
141
|
|
|
115
|
-
##
|
|
142
|
+
## Read the knowledge
|
|
116
143
|
|
|
117
|
-
|
|
144
|
+
A read writes nothing. A project without knowledge gives empty lists and the revision `0`.
|
|
118
145
|
|
|
119
|
-
|
|
120
|
-
2. Use `history` when the current knowledge is surprising or disputed. Each row gives the `reason` and the `evidence` of the revision that wrote it.
|
|
146
|
+
Each row in a body has `origin` and `revision`. A row of a space other than `c64` also has `space`.
|
|
121
147
|
|
|
122
|
-
|
|
148
|
+
When a git merge left conflicts in the knowledge, each read body also has `conflicts`. Each item gives the `conflict` and its `rows`. The `hint` tells you to decide the conflicts, and `nextAction` is the `merge` command. Each write stops until you run `merge`.
|
|
123
149
|
|
|
124
|
-
|
|
125
|
-
2. Decide the change. Keep observed facts apart from your conclusions.
|
|
126
|
-
3. Write it with `--reason` and `--expect-revision` set to the revision you read. Add `--evidence` for each thing that the change rests on: `coverage:<map>`, `test:<file>`, `file:<file>` or `note:<text>`.
|
|
127
|
-
- `coverage:<map>` names a map by its path at the import. The script uses the last import of that map into the space of the write.
|
|
128
|
-
- `test:<file>` and `file:<file>` name a file outside `.c64-re-tools/local/`. Move the file before the write.
|
|
129
|
-
- The script keeps the SHA-256 of each file and map.
|
|
130
|
-
4. Read the result. A `revision` of `null` means that nothing changed.
|
|
150
|
+
### `at <address>`
|
|
131
151
|
|
|
132
|
-
|
|
152
|
+
- `body` holds `address`, `comments`, `referencesFrom`, `referencesTo` and `revision`. When the knowledge has them, it also holds `symbol`, `analyzerNames`, `region`, `operand`, `patch`, `macroUse` and `suppressions`.
|
|
153
|
+
- `revision` is the current revision of the knowledge. Give it to `--expect-revision` of your next write.
|
|
154
|
+
- Use `at` for the addresses of the question before other work.
|
|
133
155
|
|
|
134
|
-
|
|
156
|
+
### `search <text>`
|
|
135
157
|
|
|
136
|
-
|
|
158
|
+
- `body` holds the lists `symbols`, `analyzerNames` and `comments` with the text in their names or comment text.
|
|
159
|
+
- If a list is long, give a longer text.
|
|
137
160
|
|
|
138
|
-
|
|
161
|
+
### `symbols`
|
|
139
162
|
|
|
140
|
-
|
|
163
|
+
- `body.symbols` lists the symbols, each with `address`, `name` and `kind`.
|
|
164
|
+
- With `--analyzer`, `body.analyzerNames` lists the analyzer names in place of the symbols.
|
|
141
165
|
|
|
142
|
-
|
|
143
|
-
2. For a program without a packer, drive code or a cartridge bank, put the PRG in with `image <file.prg>`. Give `--space drive8` or `--space bank0` for drive code or a bank. A PRG has the extension `.prg` or no extension. The script refuses a file with another extension.
|
|
144
|
-
3. Write each coverage map of a run into `.c64-re-tools/local/`. Then add it with `coverage <map.bin> ...`.
|
|
145
|
-
4. Read what the knowledge holds with `program`: the segments, the entry, and the coverage maps that it has.
|
|
166
|
+
### `regions`
|
|
146
167
|
|
|
147
|
-
- `
|
|
148
|
-
- `coverage` joins the maps. It keeps each address that a run executed, read or wrote. It also keeps each address that one run wrote and executed: self-modified code. `coverage` puts each map into the space of `--space`. You can add the same map to each space. A map that the space has is not added again.
|
|
149
|
-
- The capture and the maps are not necessary after the import. Keep them in `.c64-re-tools/local/`.
|
|
150
|
-
- A `revert` also gives back the coverage maps of that revision. A `revert` to a revision before an import removes the map and its ranges. Then you can import the map again, and `--evidence coverage:<map>` refuses it until you do.
|
|
168
|
+
- `body.regions` lists the regions, each with `start`, `end` and `type`. A table also has `element` and `count`.
|
|
151
169
|
|
|
152
|
-
|
|
170
|
+
### `comments`
|
|
153
171
|
|
|
154
|
-
|
|
155
|
-
[
|
|
156
|
-
{ "op": "rename", "address": "$2100", "name": "update_player", "kind": "routine" },
|
|
157
|
-
{ "op": "classify", "start": "$3000", "end": "$303b", "type": "bytes", "element": 6 },
|
|
158
|
-
{ "op": "comment", "address": "$2100", "placement": "line", "text": "Reads joystick 2." }
|
|
159
|
-
]
|
|
160
|
-
```
|
|
172
|
+
- `body.comments` lists the comments, each with `address`, `placement` and `text`.
|
|
161
173
|
|
|
162
|
-
|
|
174
|
+
### `references`
|
|
163
175
|
|
|
164
|
-
|
|
176
|
+
- `body.references` lists the references, each with `from`, `to` and `kind`.
|
|
177
|
+
|
|
178
|
+
### `suppressions`
|
|
179
|
+
|
|
180
|
+
- `body.suppressions` lists the places that a removal blocks. Each item has `suppresses` (`symbol`, `region` or `reference`), the place, and the `reason` of the removal.
|
|
181
|
+
- `unclassify` and `unreference` block the place for DXA and Ghidra. A later analysis does not add a region in that range or that reference again. This is also true for a fact from the LLM.
|
|
182
|
+
- `remove-symbol` does not block the address, because an analyzer name never becomes a symbol.
|
|
183
|
+
- A `rename`, `classify` or `reference` at a blocked place ends the block there. A `revert` to a revision before the removal also ends the block.
|
|
184
|
+
- `at` and `history` also show the blocks.
|
|
185
|
+
|
|
186
|
+
### `modules`
|
|
187
|
+
|
|
188
|
+
- `body.modules` lists the modules, each with `start`, `file` and `title`.
|
|
189
|
+
|
|
190
|
+
### `operands`
|
|
191
|
+
|
|
192
|
+
- `body.operands` lists the operand expressions, each with `address`, `select` and `text`. `text` is the operand as the source writes it.
|
|
193
|
+
|
|
194
|
+
### `patches`
|
|
195
|
+
|
|
196
|
+
- `body.patches` lists the patches, each with `start`, `end`, `bytes`, `switch`, `code` and `comment`.
|
|
197
|
+
|
|
198
|
+
### `switches`
|
|
199
|
+
|
|
200
|
+
- `body.switches` lists the switches. Each item has `name`, `kind`, `default`, `base`, `releases`, `comment` and the ranges of its `patches`.
|
|
201
|
+
- `base` is the value of the switch in the program of the knowledge.
|
|
202
|
+
|
|
203
|
+
### `releases`
|
|
204
|
+
|
|
205
|
+
- `body.releases` lists the releases, the base release first. Each item has `label`, `file`, `sha256`, `base` and `define`.
|
|
206
|
+
- `define` is the assembler define that builds the release.
|
|
207
|
+
|
|
208
|
+
### `macros`
|
|
209
|
+
|
|
210
|
+
- `body.macros` lists the macros, each with `name`, `params`, `body` and `comment`.
|
|
211
|
+
|
|
212
|
+
### `uses`
|
|
213
|
+
|
|
214
|
+
- `body.uses` lists the macro uses, each with `start`, `end`, `macro`, `args` and `text`. `text` is the line of the source, for example `+inc16 ptr`.
|
|
215
|
+
|
|
216
|
+
### `spaces`
|
|
217
|
+
|
|
218
|
+
- `body.spaces` lists the spaces that hold knowledge.
|
|
219
|
+
|
|
220
|
+
### `program`
|
|
221
|
+
|
|
222
|
+
- `body.image` is `null` when the knowledge has no program in the space. Then put the program in with `image`.
|
|
223
|
+
- Else `body.image` has `segments`, `bytes`, `entry`, `state` and `stages`. `state` is `true` when the knowledge has the entry state of a capture. `stages` is the number of unpacker stages.
|
|
224
|
+
- `body.coverage.maps` lists the coverage maps of the space. `body.coverage.ranges` gives the number of ranges of each access kind.
|
|
225
|
+
|
|
226
|
+
### `listing <range>`
|
|
227
|
+
|
|
228
|
+
- `body.lines` lists one line for each instruction of a code region, and one `!byte` line for other bytes.
|
|
229
|
+
- Each line has `address`, `bytes`, `text`, `referencesIn` and `referencesOut`. It can also have `label`, `analyzerNames` and `comment`.
|
|
230
|
+
- `text` is the instruction with the names of its target. An operand expression of the knowledge replaces the operand.
|
|
231
|
+
- When the knowledge has coverage, `access` tells if a run executed (`x`), read (`r`) or wrote (`w`) the bytes of the line, or `-` for none.
|
|
232
|
+
- With `--out`, the body has `lines` as a number, and `out`, `bytes` and `sha256` of the text file.
|
|
233
|
+
- If the knowledge has no program in the space, the script refuses. Put the program in with `image` first.
|
|
234
|
+
- Use `listing` in place of your own disassembler.
|
|
235
|
+
|
|
236
|
+
### `export`
|
|
237
|
+
|
|
238
|
+
- `body` holds `counts`, `revision`, `out`, `bytes` and `sha256`. `counts` gives the number of rows of each kind in the file.
|
|
239
|
+
- The file has all current knowledge of the space in the range, with the analyzer names and the source knowledge.
|
|
240
|
+
|
|
241
|
+
---
|
|
242
|
+
|
|
243
|
+
## Read the history
|
|
244
|
+
|
|
245
|
+
### `history [<address>]`
|
|
246
|
+
|
|
247
|
+
- Give exactly one of `<address>`, `--name`, `--macro` and `--switch`.
|
|
248
|
+
- `body.history` lists the rows of all revisions. Each item has `entity`, the fields of the row, `fromRevision`, and `toRevision` when a later revision closed the row. It also has the `reason` and the `evidence` of the revision that wrote it.
|
|
249
|
+
- Use `history` when the current knowledge is surprising or disputed.
|
|
250
|
+
|
|
251
|
+
### `revisions`
|
|
252
|
+
|
|
253
|
+
- `body.revisions` lists the revisions, newest first. Each item has `id`, `operation`, `description`, `createdAt`, `origin` and `evidence`.
|
|
254
|
+
- To get older revisions, give `--before` with the oldest `id` in `listed`.
|
|
255
|
+
|
|
256
|
+
### `revision <revision>`
|
|
257
|
+
|
|
258
|
+
- `body.revision` gives the revision. `body.added` and `body.closed` list the rows that it added and closed.
|
|
259
|
+
- The rows include the memory, entry and coverage rows of the program.
|
|
260
|
+
|
|
261
|
+
---
|
|
262
|
+
|
|
263
|
+
## Change the knowledge
|
|
264
|
+
|
|
265
|
+
Each command in this group writes one revision. The first accepted write makes `.c64-re-tools/knowledge/`. A refused write writes nothing.
|
|
266
|
+
|
|
267
|
+
- `body.revision` is the new revision. A `revision` of `null` tells that nothing changed.
|
|
268
|
+
- When the write replaced a row of a different origin, `body.previous` gives that row as it was before. For example, an `llm` write over a `user` name gives `previous`. Read `previous` and tell the user about the change.
|
|
269
|
+
- A write can give the same fact that an analyzer gave. Then the fact gets the origin of the write, and the next analysis does not remove it.
|
|
270
|
+
- A `--by user` write over the same fact of `llm` changes the origin to `user`. A `--by llm` write over the same fact of `user` changes nothing.
|
|
271
|
+
- A comment, a module and an operand expression are at the start of an instruction. In a code region, the script refuses an address that is an operand byte of an instruction. The `hint` gives the start of that instruction. In data, each address is correct.
|
|
272
|
+
|
|
273
|
+
Errors of this group:
|
|
274
|
+
|
|
275
|
+
- `conflict`: the change contradicts the current knowledge. For example, the name belongs to another address. Read that address and its history. Then decide.
|
|
276
|
+
- `conflict` with "from a git merge": git joined the knowledge of two computers, and two rows are current where the knowledge permits one row. Run `merge`. Then write again.
|
|
277
|
+
- `stale-revision`: the knowledge changed after the revision of `--expect-revision`. Read the knowledge again. Then decide again.
|
|
278
|
+
- `not-found`: there is nothing to remove, no such revision, or no such file.
|
|
279
|
+
- `invalid-database` or `unsupported-schema`: give `error` and `hint` to the user. Do not edit the knowledge files.
|
|
280
|
+
|
|
281
|
+
### `rename <address> <name>`
|
|
282
|
+
|
|
283
|
+
- `body.symbol` gives the symbol after the write.
|
|
284
|
+
- A `rename` changes the name in each operand expression and in each argument of a macro use.
|
|
285
|
+
|
|
286
|
+
### `remove-symbol <address>`
|
|
287
|
+
|
|
288
|
+
- The knowledge refuses the removal while an operand expression or a macro use names the symbol. Remove the expression with `unoperand`, or the use with `unuse`, first.
|
|
289
|
+
|
|
290
|
+
### `classify <range> <type>`
|
|
291
|
+
|
|
292
|
+
- `body.regions` gives the regions after the write. A classification inside a region splits that region. Thus regions never overlap.
|
|
293
|
+
- With `--element`, each region item also has `element` and `count`.
|
|
294
|
+
|
|
295
|
+
| Type | Meaning |
|
|
165
296
|
|---|---|
|
|
166
|
-
| `
|
|
167
|
-
| `
|
|
168
|
-
| `
|
|
169
|
-
| `
|
|
170
|
-
| `
|
|
171
|
-
| `
|
|
172
|
-
| `
|
|
173
|
-
| `
|
|
174
|
-
| `
|
|
175
|
-
| `operand` | `address`, `select` (`lo`, `hi`, `value` or `expr`), `symbol` and `offset` (optional), or `expression` for `expr` |
|
|
176
|
-
| `unoperand` | `address` |
|
|
177
|
-
| `patch` | `start`, `end`, `switch`, `code` (empty for NOP only), `comment` (optional) |
|
|
178
|
-
| `unpatch` | `start`, `switch` (optional) |
|
|
179
|
-
| `unuse` | `start` |
|
|
180
|
-
| `macro` | `name`, `params` (a list or a comma list), `body`, `comment` (optional) |
|
|
181
|
-
| `unmacro` | `name` |
|
|
182
|
-
| `use` | `start`, `end`, `macro`, `args` (a list or a comma list) |
|
|
297
|
+
| `code` | Instructions. |
|
|
298
|
+
| `bytes`, `words`, `petscii`, `screen`, `bitmap`, `sprite` | Data of that form. |
|
|
299
|
+
| `charset` | Characters of a character set, 8 bytes for each character. |
|
|
300
|
+
| `addresses`, `addresses-split` | A table of addresses: one table of 16-bit values, or a low-byte table and then a high-byte table. |
|
|
301
|
+
| `rts-addresses`, `rts-addresses-split` | The same, with each value the target minus 1, for a PHA, PHA, RTS dispatch. |
|
|
302
|
+
| `jumps` | A table of `JMP abs` instructions. Each 3-byte entry is an entry point. It is code. |
|
|
303
|
+
| `workspace` | RAM that the program writes at run time. Its bytes in the image do not matter. |
|
|
304
|
+
| `unused` | Bytes that nothing executes or reads. |
|
|
305
|
+
| `dual-use` | Code at one time, and data or a vector at another time. No analyzer finding conflicts with it. |
|
|
183
306
|
|
|
184
|
-
|
|
307
|
+
### `unclassify <range>`
|
|
185
308
|
|
|
186
|
-
|
|
309
|
+
- The range becomes unknown. The analyzers do not classify it again. See the section of `suppressions`.
|
|
187
310
|
|
|
188
|
-
|
|
311
|
+
### `comment <address> <placement> <text>...`
|
|
189
312
|
|
|
190
|
-
`
|
|
313
|
+
- `<placement>` is `line` or `side`. A `line` comment is a line of its own above the address. A `side` comment is at the end of the line of the address.
|
|
314
|
+
- `body.comment` gives the comment after the write.
|
|
191
315
|
|
|
192
|
-
|
|
316
|
+
### `uncomment <address> <placement>`
|
|
193
317
|
|
|
194
|
-
|
|
318
|
+
- Removes the comment of that placement.
|
|
195
319
|
|
|
196
|
-
|
|
320
|
+
### `reference <from> <to> <kind>`
|
|
197
321
|
|
|
198
|
-
`
|
|
322
|
+
- `<kind>` is `call`, `jump`, `read`, `write` or `reference`. Only an operand expression writes a `pointer` reference.
|
|
323
|
+
- `body.reference` gives the reference after the write.
|
|
199
324
|
|
|
200
|
-
|
|
201
|
-
- A batch can give an address a name that `join` replaces. Then `join` also replaces that name in the operand expressions and macro args of that batch.
|
|
202
|
-
- The regions of the owner come after the regions of the other batches. Thus the regions of the owner stay where they overlap.
|
|
203
|
-
- A name from a batch stays when another batch removes the symbol at that address.
|
|
204
|
-
- `choices` lists each place where the batches gave different values, with the value that stays.
|
|
205
|
-
- When one name or one module file is at two addresses, `join` writes nothing and gives the error `conflict`. The message names the addresses and the batches. Correct the batches, then do `join` again.
|
|
325
|
+
### `unreference <from> <to> <kind>`
|
|
206
326
|
|
|
207
|
-
|
|
327
|
+
- The analyzers do not add this reference again. See the section of `suppressions`.
|
|
208
328
|
|
|
209
|
-
|
|
329
|
+
### `module <start> <file.asm>`
|
|
210
330
|
|
|
211
|
-
A module tells
|
|
331
|
+
- A module tells where a file of the generated source starts. The file runs to the next module or to the end of its segment.
|
|
332
|
+
- Each address has one module, and each file name has one module.
|
|
333
|
+
- A file name has letters, digits, underscores or hyphens, and ends in `.asm`. It has no folder.
|
|
334
|
+
- The generated source has the files `main.asm`, `loader.asm`, `switches.asm`, `config.asm`, `constants.asm` and `macros.asm` already. Thus a module cannot have one of these names, in upper or lower case.
|
|
335
|
+
- The title becomes the first line of the file.
|
|
336
|
+
- `body.module` gives the module after the write.
|
|
212
337
|
|
|
213
|
-
|
|
338
|
+
### `unmodule <start>`
|
|
214
339
|
|
|
215
|
-
|
|
340
|
+
- Removes the module that starts at the address.
|
|
216
341
|
|
|
217
|
-
|
|
342
|
+
### `operand <address>`
|
|
218
343
|
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
|
222
|
-
|
|
223
|
-
| `--
|
|
224
|
-
| `--
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
-
|
|
344
|
+
An operand expression tells the generated source how to write the operand of one instruction. The source then has a name, not a number. When code or data changes its length, the operand follows the address that moved.
|
|
345
|
+
|
|
346
|
+
| Flag | Source |
|
|
347
|
+
|---|---|
|
|
348
|
+
| `--lo irq_handler` | `lda #<irq_handler` |
|
|
349
|
+
| `--hi sprite_bank --offset '$1000'` | `lda #>(sprite_bank+$1000)` |
|
|
350
|
+
| `--value bar_colours --offset=-1` | `lda bar_colours-1,x` |
|
|
351
|
+
| `--expr '(sprite_bank + 5*64) / 64'` | `lda #(sprite_bank + 5*64) / 64` |
|
|
352
|
+
|
|
353
|
+
- Give exactly one of `--lo`, `--hi`, `--value` and `--expr`.
|
|
354
|
+
- The knowledge must have the program of the space. Else the script refuses. Put the program in with `image` first.
|
|
355
|
+
- The address is the start of an instruction in a code region, as `listing` shows it. The script refuses an address in no code region. Classify the code first.
|
|
356
|
+
- A name is a symbol of the knowledge or a platform name of the C64 memory map.
|
|
229
357
|
- `--expr` takes `$`, `%` and decimal numbers, names, brackets, the operators `+ - * / % << >> >>> & | XOR`, and `<`, `>`, `-` and `!` before an operand.
|
|
230
|
-
- The script compares the value of the expression with the operand in the program
|
|
358
|
+
- The script compares the value of the expression with the operand in the program. If they are not equal, the script refuses the write. The `error` gives both values.
|
|
231
359
|
- Each name in the expression gets a `pointer` reference from the instruction. Thus `at` on the named address shows the code that uses the address.
|
|
232
|
-
-
|
|
233
|
-
|
|
234
|
-
Write an operand expression for each immediate that is a byte of an address. Also write one for each table read through the byte before the table. The pointer candidates of the c64-static-analysis skill show many of these places.
|
|
360
|
+
- `body.operand` gives the expression after the write, with its `text`.
|
|
361
|
+
- Write an operand expression for each immediate that is a byte of an address. Also write one for each table read through the byte before the table. The pointer candidates of a static analysis show many of these places.
|
|
235
362
|
|
|
236
|
-
|
|
363
|
+
### `unoperand <address>`
|
|
237
364
|
|
|
238
|
-
|
|
365
|
+
- Removes the operand expression at the address.
|
|
239
366
|
|
|
240
|
-
###
|
|
367
|
+
### `release <label>`
|
|
241
368
|
|
|
242
|
-
A
|
|
369
|
+
A rebuild keeps all of the program: unused bytes, dead code, old copies and leftovers of the development. It keeps a copy protection, a trainer and a cheat in the source. A switch puts each of them in or out of the build. Only a cracktro is not in the rebuild.
|
|
243
370
|
|
|
371
|
+
- A release is a PRG or the `image.json` of a capture, in a folder that git keeps, for example `original/`. The script refuses a file in `.c64-re-tools/local/`.
|
|
372
|
+
- A label is upper case, for example `ORIGINAL`, `FIRESTAR` or `V2`.
|
|
244
373
|
- The base release is the release whose bytes are the program of the knowledge. Record it with `--base`. The script refuses `--base` when the segments or the bytes of the file are not the program.
|
|
245
374
|
- A space has one base release. Record the base release before the first switch.
|
|
246
|
-
- The build of a release
|
|
247
|
-
-
|
|
248
|
-
|
|
375
|
+
- The build of a release gives each switch the value of that release. The check of the generated source compares that build with the bytes of the file.
|
|
376
|
+
- `body.release` gives the release, with its `sha256` and its `define`.
|
|
377
|
+
|
|
378
|
+
### `unrelease <label>`
|
|
379
|
+
|
|
380
|
+
- The knowledge refuses a release that a switch names. It also refuses the base release while the knowledge has switches.
|
|
249
381
|
|
|
250
|
-
###
|
|
382
|
+
### `switch <name>`
|
|
251
383
|
|
|
252
|
-
|
|
384
|
+
A switch has a kind, a default, and the releases that have it on. The generated source writes all switches with their defaults.
|
|
253
385
|
|
|
254
386
|
| Kind | What it changes | Default |
|
|
255
387
|
|---|---|---|
|
|
@@ -257,107 +389,231 @@ All switches are in `switches.jsonl` of the knowledge, and the c64-source skill
|
|
|
257
389
|
| `trainer` | A trainer, for example infinite lives | 0 (off) |
|
|
258
390
|
| `cheat` | A cheat | 0 (off) |
|
|
259
391
|
| `crack` | A change that a cracker made in the program, for example a credit text | 0 (off) |
|
|
260
|
-
| `fix` | A correction that one or more releases have | 1 (on). Give `--default 0` only for an alternative (
|
|
261
|
-
| `change` | Another difference between releases | Give `--default 0` or `--default 1
|
|
392
|
+
| `fix` | A correction that one or more releases have | 1 (on). Give `--default 0` only for an alternative (see `patch`). |
|
|
393
|
+
| `change` | Another difference between releases | Give `--default 0` or `--default 1`. |
|
|
262
394
|
|
|
263
|
-
- The default build is the clean program. It has no copy protection, trainer, cheat or crack change, and it has all corrections.
|
|
264
|
-
-
|
|
395
|
+
- The default build is the clean program. It has no copy protection, trainer, cheat or crack change, and it has all corrections. Thus the script refuses `--default 1` for `protection`, `trainer`, `cheat` and `crack`.
|
|
396
|
+
- A switch that no release has on, for example a trainer of your own, has no `--releases`.
|
|
265
397
|
- The base value of a switch is 1 when the base release has it on, else 0. The program of the knowledge has the base value of each switch.
|
|
266
398
|
- A switch name is upper case, for example `PROTECTION`, `TRAINER` or `FIX_LIVES`. It cannot start with `RELEASE_`. It cannot be the name of a symbol or a platform name.
|
|
267
|
-
- A `switch` write without `--releases` or `--comment` keeps the releases and the comment that the switch has.
|
|
268
399
|
- The script refuses a change of the base value while the switch has patches. Remove the patches first, because they hold the other state.
|
|
269
|
-
-
|
|
270
|
-
- `
|
|
400
|
+
- The script refuses defaults that put in two alternatives.
|
|
401
|
+
- `body.switch` gives the switch after the write, with its `base`.
|
|
271
402
|
|
|
272
|
-
###
|
|
403
|
+
### `unswitch <name>`
|
|
404
|
+
|
|
405
|
+
- The knowledge refuses a switch that has patches. Remove the patches with `unpatch` first.
|
|
406
|
+
|
|
407
|
+
### `patch <range> <switch>`
|
|
273
408
|
|
|
274
409
|
A patch is ACME code for a range of the program. The code is the bytes of the switch in the state that the base release does not have. Examples:
|
|
275
410
|
|
|
276
411
|
- The base release has a copy protection. The switch `PROTECTION` names the base release. The code is the program without the protection, for example NOP in place of the `JSR` to the check.
|
|
277
|
-
- The base release has the protection already removed, and another release has it
|
|
278
|
-
- A correction is only in release `V2
|
|
412
|
+
- The base release has the protection already removed, and another release has it. The code is the bytes of the protection from that release. When no release has these bytes, write in a comment that the crack removed the protection.
|
|
413
|
+
- A correction is only in release `V2`. The switch `FIX_LIVES` names `V2`, and the code is the bytes of `V2`.
|
|
279
414
|
- A correction is in the base release and not in `V1`. The switch names the base release, and the code is the bytes of `V1`.
|
|
280
415
|
|
|
281
416
|
Rules:
|
|
282
417
|
|
|
418
|
+
- Give exactly one of `--code`, `--code-file` and `--nop`.
|
|
283
419
|
- Write the switch first. `patch` refuses a switch that the knowledge does not have.
|
|
284
420
|
- Many patches can have the same switch.
|
|
285
|
-
- The code must fit in the range. NOP (
|
|
286
|
-
- `patch` refuses code that is longer than the range when each line is a 6510 instruction, `!byte`, `!word`, `!fill` or a comment.
|
|
287
|
-
-
|
|
288
|
-
- The braces in the code must be pairs
|
|
289
|
-
- Patches of different switches can have the same range. They are alternatives, for example two releases with two different corrections of one bug. The default build can put in only one of them.
|
|
421
|
+
- The code must fit in the range. NOP (`$EA`) fills the bytes after the code.
|
|
422
|
+
- `patch` refuses code that is longer than the range when each line is a 6510 instruction, `!byte`, `!word`, `!fill` or a comment. It does not check the length of other code, for example code with a label or a macro. The check of the generated source finds these errors.
|
|
423
|
+
- The code can use the labels and the macros of the source, and local labels with a dot, for example `.skip`.
|
|
424
|
+
- The braces in the code must be pairs.
|
|
425
|
+
- Patches of different switches can have the same range. They are alternatives, for example two releases with two different corrections of one bug. The default build can put in only one of them.
|
|
290
426
|
- The knowledge refuses all other overlaps of patches. A patch cannot overlap a macro use.
|
|
291
427
|
- A patch with the same start and the same switch replaces the patch.
|
|
292
|
-
- When patches of two switches start at one address, give `unpatch` the switch with `--switch`.
|
|
293
428
|
- Each byte of the range must be in the program of the knowledge.
|
|
294
|
-
-
|
|
429
|
+
- `body.patch` gives the patch after the write.
|
|
295
430
|
|
|
296
|
-
|
|
431
|
+
### `unpatch <start>`
|
|
297
432
|
|
|
298
|
-
-
|
|
299
|
-
- A release: `--release ORIGINAL`. A release build does not read `config.asm`.
|
|
300
|
-
- One switch: set its value in `config.asm` of the source, for example `TRAINER = 1`.
|
|
433
|
+
- When patches of two switches start at the address, give the switch with `--switch`.
|
|
301
434
|
|
|
302
|
-
|
|
435
|
+
### `macro <name>`
|
|
303
436
|
|
|
304
437
|
A macro writes a run of instructions as one line of the source, for example `+inc16 ptr`. Use macros to make the source shorter and easier to read.
|
|
305
438
|
|
|
306
|
-
-
|
|
307
|
-
-
|
|
308
|
-
-
|
|
309
|
-
|
|
310
|
-
|
|
439
|
+
- Give `--body` or `--body-file`. The body uses each param with a dot, for example `.dst`.
|
|
440
|
+
- The knowledge refuses a change of the number of params while the macro has uses.
|
|
441
|
+
- `body.macro` gives the macro after the write.
|
|
442
|
+
|
|
443
|
+
### `unmacro <name>`
|
|
444
|
+
|
|
445
|
+
- The knowledge refuses a macro that has uses. Remove the uses with `unuse` first.
|
|
446
|
+
|
|
447
|
+
### `use <range> <macro>`
|
|
448
|
+
|
|
449
|
+
- The range is complete instructions of the program of the knowledge.
|
|
450
|
+
- Each name in an argument is a symbol of the knowledge or a platform name.
|
|
311
451
|
- A use cannot overlap a patch or another use.
|
|
452
|
+
- The generated source writes a use only when the use gives the bytes of the program. Else it writes the instructions and gives the reason.
|
|
453
|
+
- `body.use` gives the use after the write.
|
|
312
454
|
|
|
313
|
-
|
|
455
|
+
### `unuse <start>`
|
|
314
456
|
|
|
315
|
-
|
|
457
|
+
- Removes the macro use that starts at the address.
|
|
316
458
|
|
|
317
|
-
|
|
459
|
+
### `image <file>`
|
|
318
460
|
|
|
319
|
-
- `
|
|
320
|
-
-
|
|
321
|
-
-
|
|
461
|
+
- `<file>` is the `image.json` of a capture, or a PRG. A PRG has the extension `.prg` or no extension. The script refuses a file with another extension.
|
|
462
|
+
- For drive code or a cartridge bank, give `--space drive8` or `--space bank0`.
|
|
463
|
+
- `body` holds `revision`, `bytes`, `rowsAdded`, `rowsClosed` and `entryChanged`.
|
|
464
|
+
- `image` writes only the bytes that changed. The same image again writes nothing. A new image replaces the program of the space. The history keeps the old bytes.
|
|
465
|
+
- After the import, you do not need the file of the capture. Keep it in `.c64-re-tools/local/`.
|
|
322
466
|
|
|
323
|
-
|
|
467
|
+
### `coverage <map>...`
|
|
324
468
|
|
|
325
|
-
Write
|
|
469
|
+
- `<map>` is a 64 KiB coverage map of a run. Write each map in `.c64-re-tools/local/`.
|
|
470
|
+
- `body` holds `revision`, `imported`, `known` and `ranges`. `imported` lists the new maps. `known` lists the maps that the space has already.
|
|
471
|
+
- `coverage` joins the maps. It keeps each address that a run executed, read or wrote. It also keeps each address that one run wrote and executed: self-modified code.
|
|
472
|
+
- `coverage` puts each map into the space of `--space`. You can add the same map to each space.
|
|
473
|
+
- `--evidence coverage:<map>` names a map by its path at the import. It refers to the last import of that map into the space of the write.
|
|
474
|
+
|
|
475
|
+
### `apply <file>`
|
|
476
|
+
|
|
477
|
+
- `<file>` is a JSON list of writes. Give `-` to read the list from standard input.
|
|
478
|
+
- `body` holds `revision`, `writes` and `replaced`. Each item of `replaced` has the number of the `write`, its `op` and its `previous`.
|
|
479
|
+
- All writes become one revision. If the knowledge refuses one write, the script writes nothing, and the `error` names the write.
|
|
480
|
+
- Each write has `op` and the fields of the command with the same name. Each write can also have `space`. For example:
|
|
481
|
+
|
|
482
|
+
```json
|
|
483
|
+
[
|
|
484
|
+
{ "op": "rename", "address": "$2100", "name": "update_player", "kind": "routine" },
|
|
485
|
+
{ "op": "classify", "start": "$3000", "end": "$303b", "type": "bytes", "element": 6 },
|
|
486
|
+
{ "op": "comment", "address": "$2100", "placement": "line", "text": "Reads joystick 2." }
|
|
487
|
+
]
|
|
488
|
+
```
|
|
489
|
+
|
|
490
|
+
| op | Fields |
|
|
491
|
+
|---|---|
|
|
492
|
+
| `rename` | `address`, `name`, `kind` (optional) |
|
|
493
|
+
| `remove-symbol` | `address` |
|
|
494
|
+
| `classify` | `start`, `end`, `type`, `element` (optional) |
|
|
495
|
+
| `unclassify` | `start`, `end` |
|
|
496
|
+
| `comment` | `address`, `placement` (`line` or `side`), `text` |
|
|
497
|
+
| `uncomment` | `address`, `placement` |
|
|
498
|
+
| `reference`, `unreference` | `from`, `to`, `kind` |
|
|
499
|
+
| `module` | `start`, `file`, `title` (optional) |
|
|
500
|
+
| `unmodule` | `start` |
|
|
501
|
+
| `operand` | `address`, `select` (`lo`, `hi`, `value` or `expr`), `symbol` and `offset` (optional), or `expression` for `expr` |
|
|
502
|
+
| `unoperand` | `address` |
|
|
503
|
+
| `patch` | `start`, `end`, `switch`, `code` (empty for NOP only), `comment` (optional) |
|
|
504
|
+
| `unpatch` | `start`, `switch` (optional) |
|
|
505
|
+
| `macro` | `name`, `params` (a list or a comma list), `body`, `comment` (optional) |
|
|
506
|
+
| `unmacro` | `name` |
|
|
507
|
+
| `use` | `start`, `end`, `macro`, `args` (a list or a comma list) |
|
|
508
|
+
| `unuse` | `start` |
|
|
509
|
+
|
|
510
|
+
- The script checks an `operand`, `patch` or `use` write against the program of its space.
|
|
511
|
+
- Apply a batch from a library match or an idiom search in the same way. Read the notes of the result that wrote the batch first.
|
|
512
|
+
|
|
513
|
+
### `revert <revision>`
|
|
514
|
+
|
|
515
|
+
- Makes the knowledge the same as at the revision. Without `--space`, all spaces revert. With `--space`, only that space reverts.
|
|
516
|
+
- `body` holds `revision`, `restores`, and `spaces: "all"` or `space`.
|
|
517
|
+
- A revert is a new revision. The history stays complete.
|
|
518
|
+
- A revert also gives back the coverage maps of that revision. A revert to a revision before an import removes the map and its ranges. Then `--evidence coverage:<map>` refuses the map until you import it again.
|
|
519
|
+
|
|
520
|
+
### `merge`
|
|
521
|
+
|
|
522
|
+
- Decides each conflict that a git merge left. Of the rows of one conflict, the newest row stays. All choices become one revision.
|
|
523
|
+
- `body.choices` lists each choice, with the `conflict`, the row that is `kept` and the rows that are `closed`. Tell the user the choices.
|
|
524
|
+
|
|
525
|
+
---
|
|
526
|
+
|
|
527
|
+
## Batches of parallel agents
|
|
528
|
+
|
|
529
|
+
When more agents name the program at the same time, give each agent one range of addresses. Each agent writes one batch file and does not apply it. A batch has the form `{"owner": {"start": "$1000", "end": "$1fff"}, "ops": [...]}`. `ops` holds the writes, as for `apply`. The owner ranges must not overlap.
|
|
530
|
+
|
|
531
|
+
### `join <batch>...`
|
|
532
|
+
|
|
533
|
+
- `join` makes one batch from two or more batch files. It writes no knowledge.
|
|
534
|
+
- `body` holds `writes`, `repeated`, `choices`, `out`, `bytes` and `sha256`.
|
|
535
|
+
- `choices` lists each place where the batches gave different values, with the value that stays.
|
|
536
|
+
- At an address in the owner range of a batch, the name, the comment, the operand and the module of that batch stay. At an address that no batch owns, the first batch in the command stays.
|
|
537
|
+
- A batch can give an address a name that `join` replaces. Then `join` also replaces that name in the operand expressions and macro arguments of that batch.
|
|
538
|
+
- The regions of the owner come after the regions of the other batches. Thus the regions of the owner stay where they overlap.
|
|
539
|
+
- A name from a batch stays when another batch removes the symbol at that address.
|
|
540
|
+
- When one name or one module file is at two addresses, `join` writes nothing and gives the error `conflict`. The `error` names the addresses and the batches. Correct the batches. Then do `join` again.
|
|
541
|
+
- The `hint` tells you to examine `choices`. `nextAction` is the `apply` command for the joined batch. Run it when the choices agree with your task.
|
|
542
|
+
|
|
543
|
+
---
|
|
544
|
+
|
|
545
|
+
## Workflow
|
|
546
|
+
|
|
547
|
+
Read:
|
|
548
|
+
|
|
549
|
+
1. Run `at` for the addresses of the question.
|
|
550
|
+
2. Run `history` when the current knowledge is surprising or disputed. Each row gives the `reason` and the `evidence` of the revision that wrote it.
|
|
551
|
+
|
|
552
|
+
Write:
|
|
553
|
+
|
|
554
|
+
1. Read the current value with `at`. Keep the `revision` of the body.
|
|
555
|
+
2. Decide the change. Keep observed facts apart from your conclusions.
|
|
556
|
+
3. Write the change with `--reason`, and with `--expect-revision` set to the revision that you read. Give `--evidence` for each thing that the change rests on.
|
|
557
|
+
4. Read the body. If it has `previous`, tell the user.
|
|
558
|
+
|
|
559
|
+
Put the program into the knowledge:
|
|
560
|
+
|
|
561
|
+
1. For a packed program, capture the unpacked program into `.c64-re-tools/local/`. Then run `image` with its `image.json`.
|
|
562
|
+
2. For a program without a packer, drive code or a cartridge bank, run `image` with the PRG.
|
|
563
|
+
3. Write the coverage map of each run into `.c64-re-tools/local/`. Then run `coverage` with the maps.
|
|
564
|
+
4. Run `program` to see the segments, the entry and the coverage maps.
|
|
565
|
+
|
|
566
|
+
Write knowledge only after interpretation:
|
|
326
567
|
|
|
327
568
|
- a symbol name that tells what a routine or a variable does
|
|
328
569
|
- a region type that the evidence supports
|
|
329
570
|
- a comment that explains behavior that a name cannot show
|
|
330
571
|
- a reference that the evidence supports.
|
|
331
572
|
|
|
332
|
-
Do not
|
|
573
|
+
Do not write:
|
|
333
574
|
|
|
334
575
|
- temporary investigation state
|
|
335
576
|
- a guess, only because a routine needs a temporary name
|
|
336
577
|
- confidence or status words in comment text.
|
|
337
578
|
|
|
338
|
-
|
|
579
|
+
For runtime evidence, examine the program in the emulator. For static evidence, analyze the machine code. To make the source from the knowledge, generate the source. To name the routines that other programs share, match the program against a routine library.
|
|
580
|
+
|
|
581
|
+
## JSON output
|
|
582
|
+
|
|
583
|
+
Each command prints one JSON envelope on one line on stdout. Notes go to stderr.
|
|
339
584
|
|
|
340
|
-
|
|
585
|
+
On success, the exit code is 0:
|
|
341
586
|
|
|
342
|
-
|
|
587
|
+
```json
|
|
588
|
+
{"ok": true, "command": "<command>", "body": {}, "hint": "...", "nextAction": "..."}
|
|
589
|
+
```
|
|
343
590
|
|
|
344
|
-
|
|
591
|
+
On failure, the exit code is 2:
|
|
345
592
|
|
|
346
|
-
|
|
593
|
+
```json
|
|
594
|
+
{"ok": false, "command": "<command>", "code": "<code>", "error": "...", "hint": "...", "nextAction": "..."}
|
|
595
|
+
```
|
|
347
596
|
|
|
348
|
-
|
|
597
|
+
- `body` holds the result. The section of each command gives the fields of its body.
|
|
598
|
+
- A check gives its verdict in `body.result`: `PASS`, `FAIL` or `INCONCLUSIVE`. The exit code is 0 for each verdict. Thus read `body.result`, not the exit code.
|
|
599
|
+
- `error` is one sentence. It tells what is wrong.
|
|
600
|
+
- `hint` tells what to do or what to examine. Read it before your next step. Some envelopes have no `hint`.
|
|
601
|
+
- `nextAction` is a full command line. It runs from any directory. Run it when it agrees with your task. Some envelopes have no `nextAction`.
|
|
602
|
+
- `code` does not change between versions. Do the action for the code:
|
|
349
603
|
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
- `
|
|
353
|
-
- `
|
|
354
|
-
|
|
604
|
+
| `code` | Action |
|
|
605
|
+
|---|---|
|
|
606
|
+
| `installation-incomplete`, `machine-unavailable` | Stop the task. Give `error` and `hint` to the user and wait for the user. Do not install, start or change a tool. Do not make a replacement for the tool, for example your own disk parser, disassembler or emulator script. |
|
|
607
|
+
| `invalid-input`, `not-found` | Correct the call as `hint` tells. Then run the command again. |
|
|
608
|
+
| `operation-failed` | Give `error` and `hint` to the user. |
|
|
609
|
+
| Another code | Do as `hint` tells. |
|
|
355
610
|
|
|
356
|
-
|
|
611
|
+
These fields have the same meaning in each body:
|
|
357
612
|
|
|
358
|
-
|
|
613
|
+
| Field | Meaning |
|
|
614
|
+
|---|---|
|
|
615
|
+
| `out`, `bytes`, `sha256` | A file that the command wrote: its path, its size and its SHA-256. |
|
|
616
|
+
| `count`, `listed`, `rest` | A list. `count` is the number of items. `listed` holds the first items, at most `--max-listed`. `rest` tells how to get the other items. |
|
|
359
617
|
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
- Source from the knowledge → c64-source
|
|
363
|
-
- Names of routines that other programs share → c64-provenance
|
|
618
|
+
To get the command list, run the script with no arguments. The envelope has `command: "help"`, and `body.commands` gives the name, the summary and the synopsis of each command.
|
|
619
|
+
To get the subjects and the flags of one command, run `<command> --help`. Then `body.subjects` and `body.options` give them.
|