@henols/c64-re-tools 2.0.0-rc.9 → 2.0.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.
Files changed (118) hide show
  1. package/README.md +97 -116
  2. package/package.json +1 -1
  3. package/skills/c64-assembler/SKILL.md +22 -6
  4. package/skills/c64-assembler/scripts/assemble.ts +42 -14
  5. package/skills/c64-assembler/scripts/lib/compare.ts +48 -0
  6. package/skills/c64-basic/SKILL.md +10 -1
  7. package/skills/c64-basic/scripts/basic.ts +3 -3
  8. package/skills/c64-disk/SKILL.md +13 -4
  9. package/skills/c64-disk/scripts/disk.ts +7 -7
  10. package/skills/c64-disk/scripts/{containers.ts → lib/containers.ts} +2 -2
  11. package/skills/c64-docs/SKILL.md +138 -0
  12. package/skills/c64-docs/references/page-types.md +141 -0
  13. package/skills/c64-docs/references/style.md +43 -0
  14. package/skills/c64-docs/scripts/generate.ts +109 -0
  15. package/skills/c64-docs/scripts/lib/links.ts +167 -0
  16. package/skills/c64-docs/scripts/lib/markdown.ts +79 -0
  17. package/skills/c64-docs/scripts/lib/reference.ts +406 -0
  18. package/skills/c64-docs/scripts/lib/source-map.ts +81 -0
  19. package/skills/c64-docs/scripts/link.ts +239 -0
  20. package/skills/c64-emulator/SKILL.md +16 -5
  21. package/skills/c64-knowledge/SKILL.md +140 -18
  22. package/skills/c64-knowledge/scripts/knowledge.ts +737 -112
  23. package/skills/c64-knowledge/scripts/lib/listing.ts +162 -0
  24. package/skills/c64-memory-map/SKILL.md +11 -2
  25. package/skills/c64-memory-map/scripts/memmap.ts +2 -2
  26. package/skills/c64-provenance/SKILL.md +66 -11
  27. package/skills/c64-provenance/scripts/{compare.ts → lib/compare.ts} +3 -3
  28. package/skills/c64-provenance/scripts/lib/library.ts +584 -0
  29. package/skills/c64-provenance/scripts/{runtime.ts → lib/runtime.ts} +2 -2
  30. package/skills/c64-provenance/scripts/{separate.ts → lib/separate.ts} +3 -3
  31. package/skills/c64-provenance/scripts/provenance.ts +242 -40
  32. package/skills/c64-reverse-engineering/SKILL.md +51 -26
  33. package/skills/c64-source/SKILL.md +76 -28
  34. package/skills/c64-source/scripts/generate.ts +425 -127
  35. package/skills/c64-source/scripts/{loader.ts → lib/loader.ts} +84 -25
  36. package/skills/c64-source/scripts/lib/source.ts +1121 -0
  37. package/skills/c64-static-analysis/SKILL.md +35 -18
  38. package/skills/c64-static-analysis/scripts/analyze.ts +184 -55
  39. package/skills/c64-static-analysis/scripts/{coverage.ts → lib/coverage.ts} +19 -25
  40. package/skills/c64-static-analysis/scripts/{findings.ts → lib/findings.ts} +6 -2
  41. package/skills/c64-static-analysis/scripts/{idioms.ts → lib/idioms.ts} +21 -12
  42. package/skills/c64-static-analysis/scripts/{instructions.ts → lib/instructions.ts} +1 -1
  43. package/skills/c64-static-analysis/scripts/lib/macros.ts +233 -0
  44. package/skills/c64-static-analysis/scripts/lib/pitfalls.ts +68 -0
  45. package/skills/c64-static-analysis/scripts/lib/pointers.ts +108 -0
  46. package/skills/c64-testing/SKILL.md +36 -7
  47. package/skills/c64-testing/references/scenario-format.md +12 -8
  48. package/skills/c64-testing/scripts/checklist.ts +3 -3
  49. package/skills/c64-testing/scripts/diff.ts +167 -0
  50. package/skills/c64-testing/scripts/lib/diff.ts +70 -0
  51. package/skills/c64-testing/scripts/{scenario.ts → lib/scenario.ts} +45 -34
  52. package/skills/c64-testing/scripts/run.ts +73 -21
  53. package/skills/c64-testing/scripts/test.ts +5 -5
  54. package/skills/c64-unpacker/SKILL.md +23 -9
  55. package/skills/c64-unpacker/scripts/{evidence.ts → lib/evidence.ts} +1 -1
  56. package/skills/c64-unpacker/scripts/{loads.ts → lib/loads.ts} +4 -4
  57. package/skills/c64-unpacker/scripts/{machine.ts → lib/machine.ts} +4 -4
  58. package/skills/c64-unpacker/scripts/{stages.ts → lib/stages.ts} +17 -5
  59. package/skills/c64-unpacker/scripts/unpack.ts +41 -24
  60. package/src/c64.ts +103 -5
  61. package/src/cli/cleanup.ts +1 -1
  62. package/src/cli/main.ts +14 -5
  63. package/src/cli/status.ts +70 -3
  64. package/src/graphics.ts +158 -0
  65. package/src/host/main.ts +25 -5
  66. package/src/host/server.ts +10 -3
  67. package/src/host/tools/petcat.ts +1 -1
  68. package/src/host/tools/status.ts +1 -1
  69. package/src/host/vice/adapter.ts +4 -3
  70. package/src/host/vice/process.ts +2 -2
  71. package/src/host/vice/screen.ts +1 -42
  72. package/src/host/vice/session.ts +196 -23
  73. package/src/host-client/autostart.ts +1 -1
  74. package/src/host-client/connect.ts +1 -1
  75. package/src/host-client/coverage.ts +2 -29
  76. package/src/host-client/image.ts +66 -0
  77. package/src/host-client/steps.ts +9 -4
  78. package/src/host-client/tools.ts +1 -0
  79. package/src/host-client/transfer.ts +39 -11
  80. package/src/host-client/vice-session.ts +33 -16
  81. package/src/knowledge/conflicts.ts +161 -0
  82. package/src/knowledge/database.ts +150 -38
  83. package/src/knowledge/expression.ts +209 -0
  84. package/src/knowledge/graph.ts +104 -0
  85. package/src/knowledge/history.ts +70 -22
  86. package/src/knowledge/import.ts +64 -55
  87. package/src/knowledge/join.ts +211 -0
  88. package/src/knowledge/program.ts +266 -0
  89. package/src/knowledge/read.ts +258 -27
  90. package/src/knowledge/schema.ts +199 -75
  91. package/src/knowledge/text.ts +415 -0
  92. package/src/knowledge/write.ts +740 -57
  93. package/src/mcp/main.ts +8 -2
  94. package/src/mcp/output.ts +15 -8
  95. package/src/mcp/server.ts +3 -1
  96. package/src/mcp/tools/debug.ts +97 -16
  97. package/src/mcp/tools/execution.ts +38 -5
  98. package/src/mcp/tools/machine.ts +11 -2
  99. package/src/mcp/tools/media.ts +18 -13
  100. package/src/mcp/tools/memory.ts +17 -8
  101. package/src/mcp/tools/video.ts +9 -9
  102. package/src/native/discover.ts +2 -2
  103. package/src/native/ghidra/analyze.ts +2 -2
  104. package/src/native/ghidra/index.ts +1 -1
  105. package/src/native/ghidra/language/c64rt_6510.slaspec +4 -1
  106. package/src/native/ghidra/scripts/C64Export.java +1 -1
  107. package/src/native/ghidra/scripts/C64Prepare.java +7 -1
  108. package/src/native/types.ts +14 -8
  109. package/{skills/c64-source/scripts → src}/opcodes.ts +75 -3
  110. package/src/package.ts +13 -3
  111. package/src/platform.ts +70 -7
  112. package/src/project.ts +180 -3
  113. package/src/protocol/messages.ts +1 -1
  114. package/src/protocol/tools.ts +2 -16
  115. package/src/protocol/vice.ts +124 -15
  116. package/src/script.ts +46 -7
  117. package/skills/c64-assembler/scripts/compare.ts +0 -84
  118. package/skills/c64-source/scripts/source.ts +0 -595
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  name: c64-knowledge
3
- description: Use this skill to read, write, correct and review the durable knowledge of a C64 project in .c64-re-tools/knowledge.db. It gives the knowledge at an address, and it names symbols, classifies memory regions, sets comments and records references. It also shows the history of each change, and it can revert to an earlier revision. Do not use it for live emulator state or for static analysis.
3
+ description: Use this skill to read, write, correct and review the durable knowledge of a C64 project in .c64-re-tools/knowledge/. The knowledge holds the program, its entry state and the coverage of the runs. It gives the knowledge at an address, and it names symbols, classifies memory regions, sets comments and records references. It records patches and macros for the generated source. It also shows the history of each change, and it can revert to an earlier revision. Do not use it for live emulator state or for static analysis.
4
4
  ---
5
5
 
6
6
  # c64-knowledge
7
7
 
8
8
  ## Purpose
9
9
 
10
- Read, write, correct and review the durable understanding of a C64 project. The knowledge is in `.c64-re-tools/knowledge.db` in the project directory. Git can version that file.
10
+ Read, write, correct and review the durable understanding of a C64 project. The knowledge also holds the program: its bytes, its entry state and the stages of its unpacker. It holds the coverage of the runs too. The other skills read the program and the coverage from the knowledge. The knowledge is text in `.c64-re-tools/knowledge/` in the project folder: one JSON line for each row. Commit that folder with git. The script keeps an index of the text in `.c64-re-tools/local/knowledge.db` and makes the index again when the text changes. Do not commit the index.
11
11
 
12
- This skill is the only write path for conclusions of the user and the LLM. It does not run an emulator or an analyzer.
12
+ This skill is the only write path for conclusions of the user and the LLM. It does not run an emulator or an analyzer. Write the knowledge only with the script. The script checks each write. Do not write or edit the files in `.c64-re-tools/knowledge/` or the index yourself.
13
13
 
14
14
  ## Inputs
15
15
 
@@ -18,43 +18,60 @@ One of these:
18
18
  - an address, a range or a symbol name to look up
19
19
  - text to search for
20
20
  - a change to a symbol, a region, a comment or a reference, with a short reason
21
+ - a capture of the c64-unpacker skill, a PRG, or coverage maps to put into the knowledge
21
22
  - a request to see the history or a revision.
22
23
 
23
24
  ## Tools / execution path
24
25
 
25
- Run the script in the project directory. The project directory is the directory that the harness started in.
26
-
27
26
  ```
28
27
  node <skill>/scripts/knowledge.ts <command> [arguments] [options]
29
28
  ```
30
29
 
31
- The script prints one JSON object. An error prints `{"error": {"code": ..., "message": ...}}`. Addresses are `$` and four hex digits. Quote them in a shell, for example `'$2100'`.
30
+ The script prints one JSON object. An error prints `{"error": {"code": ..., "message": ...}}`. Addresses are `$` and four hex digits. Quote them in a shell, for example `'$2100'`. A name also gives an address, for example `at update_player`. The script tries the symbols first and then the analyzer names.
31
+
32
+ A symbol is the name of an address from the user or the LLM. An analyzer name is a second name from DXA, Ghidra or an idiom, for example `FUN_17e2`. Each analyzer keeps its own name at an address. `at`, `search` and `export` show the analyzer names. The generated source uses only the symbols, unless c64-source gets `--analyzer-names`. To use an analyzer name in the source, `rename` the address with it.
32
33
 
33
34
  | Need | Command |
34
35
  |---|---|
35
36
  | Everything known at one address | `at '$2100'` |
36
37
  | Find names and comment text | `search player` |
37
38
  | Lists in a range | `symbols`, `regions`, `comments`, `references` with `--start` and `--end` |
39
+ | The names that DXA, Ghidra and the idioms gave | `symbols --analyzer` |
38
40
  | Only some origins | add `--origin semantic`, `--origin analyzer` (dxa, ghidra and heuristic), or `--origin user,llm` |
39
- | All knowledge in one file | `export --out exports/knowledge.json` |
41
+ | All knowledge in one file | `export --out .c64-re-tools/local/knowledge.json` |
42
+ | Put the program into the knowledge | `image .c64-re-tools/local/capture/image.json` or `image original/game.prg` |
43
+ | Add the coverage of runs | `coverage .c64-re-tools/local/runs/rooms/room0.bin ...` |
44
+ | What the knowledge holds of the program | `program` |
45
+ | The code of a range with names, comments, access and references | `listing '$0400' '$04ff'` |
40
46
  | Name the symbol at an address | `rename '$2100' update_player --kind routine` |
41
47
  | Remove a symbol | `remove-symbol '$2100'` |
42
48
  | Classify memory | `classify '$3000' '$303f' sprite` |
43
49
  | Classify a table of records | `classify '$3000' '$303b' bytes --element 6` |
44
- | Many writes as one revision | `apply batch.json`, or `apply -` with the JSON on standard input |
50
+ | Many writes as one revision | `apply -` with the JSON on standard input, or `apply <file>` |
51
+ | One batch from the batches of parallel agents | `join a.json b.json --out .c64-re-tools/local/joined.json` |
45
52
  | Make memory unknown, and keep the analyzers out of it | `unclassify '$3000' '$303f'` |
46
53
  | Set or remove a comment | `comment '$2100' line Reads joystick 2.` / `uncomment '$2100' line` |
47
54
  | Add or remove a reference | `reference '$2000' '$2100' call` / `unreference ...` |
48
55
  | Places that a removal blocks | `suppressions` with `--start` and `--end` |
49
56
  | Start a file of generated source | `module '$2000' player.asm --title 'Player movement'` / `unmodule '$2000'` |
57
+ | Write the operand of an instruction as an expression | `operand '$8079' --lo irq_handler` / `unoperand '$8079'` |
58
+ | Operand expressions | `operands` with `--start` and `--end` |
59
+ | Replace a range with code when a switch is on | `patch '$100e' '$1010' CRACK --code-file crack.asm` / `unpatch '$100e'` |
60
+ | Patches and switches | `patches` with `--switch`, and `switches` |
61
+ | Write a macro | `macro inc16 --params dst --body-file inc16.asm` / `unmacro inc16` |
62
+ | Write instructions as one use of a macro | `use '$1005' '$100a' inc16 --args ptr` / `unuse '$1005'` |
63
+ | Macros and their uses | `macros`, and `uses` with `--start`, `--end` and `--macro` |
50
64
  | Files of generated source | `modules` |
51
65
  | The address spaces that hold knowledge | `spaces` |
52
- | History | `history '$2100'`, `history --name update_player`, `revisions`, `revision 12` |
53
- | Go back to an earlier state | `revert 12` |
66
+ | History | `history '$2100'`, `history --name update_player`, `history --macro inc16`, `revisions`, `revision 20261015T2145` |
67
+ | Go back to an earlier state | `revert 20261015T2145` |
68
+ | Decide the conflicts after a git merge | `merge --reason 'merge of two computers'` |
69
+
70
+ A revision has an id such as `20261015T214501.123-k3f9qz`. The id starts with the date and time. A command takes the full id, or a start of the id that only one revision has. The revision `0` is the knowledge before the first revision.
54
71
 
55
72
  Every command takes `--space`: `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, so each space has its own knowledge. A name is unique inside one space. In a batch, a write can name its own `space`.
56
73
 
57
- Symbol kinds are `label`, `routine`, `variable`, `data` and `vector`. Reference kinds are `call`, `jump`, `read`, `write` and `reference`.
74
+ Symbol kinds are `label`, `routine`, `variable`, `data` and `vector`. Reference kinds are `call`, `jump`, `read`, `write`, `reference` and `pointer`. Only an operand expression writes a `pointer` reference.
58
75
 
59
76
  Region types:
60
77
 
@@ -62,6 +79,7 @@ Region types:
62
79
  |---|---|
63
80
  | `code` | Instructions. |
64
81
  | `bytes`, `words`, `petscii`, `screen`, `bitmap`, `sprite` | Data of that form. |
82
+ | `charset` | Characters of a character set, 8 bytes for each character. |
65
83
  | `addresses`, `addresses-split` | A table of addresses: one table of 16-bit values, or a low-byte table and then a high-byte table. |
66
84
  | `rts-addresses`, `rts-addresses-split` | The same, with each value the target minus 1, for a PHA, PHA, RTS dispatch. |
67
85
  | `jumps` | A table of `JMP abs` instructions. Each 3-byte entry is an entry point. It is code. |
@@ -71,6 +89,15 @@ Region types:
71
89
 
72
90
  `--element` gives the bytes of one element of a table. The length of the region must be a multiple of it. The result shows `element` and `count`.
73
91
 
92
+ ### Project folder
93
+
94
+ - Paths are relative to the project folder. The project folder is the nearest folder at or above the working directory that holds `.c64-re-tools/`.
95
+ - 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.
96
+ - 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.
97
+ - 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` of c64-knowledge. `--evidence` refuses a file in `.c64-re-tools/local/`.
98
+ - 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.
99
+ - 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`.
100
+
74
101
  ## Workflow
75
102
 
76
103
  Read:
@@ -82,12 +109,25 @@ Write:
82
109
 
83
110
  1. Read the current value with `at`. Note the `revision` in the result.
84
111
  2. Decide the change. Keep observed facts apart from your conclusions.
85
- 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:<file>`, `test:<file>`, `file:<file>` or `note:<text>`. The script keeps the SHA-256 of each file.
112
+ 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>`. `<map>` is a coverage map that `coverage` put into the knowledge, by its path at that time. The script uses the last import of the map into the space of the write. The script keeps the SHA-256 of each file and map.
86
113
  4. Read the result. A `revision` of `null` means that nothing changed.
87
114
 
88
115
  Each write is one revision. A classification inside a region splits that region, so regions never overlap.
89
116
 
90
- For more than a few writes, put them in one JSON file and use `apply`. The file is a list of writes. Each write has `op` and the arguments of the command with the same name, for example:
117
+ ## The program and the coverage
118
+
119
+ The knowledge holds the program, so a project needs no image or coverage files. The other skills read them from the knowledge and take no path to them.
120
+
121
+ 1. Capture a packed program with the c64-unpacker skill into `.c64-re-tools/local/`. Then put it in with `image .c64-re-tools/local/capture/image.json`. The script reads `image.bin`, `entry_state.json` and the stages next to it.
122
+ 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.
123
+ 3. Write each coverage map of a run into `.c64-re-tools/local/`. Then add it with `coverage <map.bin> ...`.
124
+ 4. Read what the knowledge holds with `program`: the segments, the entry, and the coverage maps that it has.
125
+
126
+ - `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.
127
+ - `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.
128
+ - The capture and the maps are not necessary after the import. Keep them in `.c64-re-tools/local/`.
129
+
130
+ For more than a few writes, use `apply -` and give the writes on standard input as one JSON list. Each write has `op` and the arguments of the command with the same name, for example:
91
131
 
92
132
  ```json
93
133
  [
@@ -110,16 +150,96 @@ The ops and their fields:
110
150
  | `reference`, `unreference` | `from`, `to`, `kind` |
111
151
  | `module` | `start`, `file`, `title` (optional) |
112
152
  | `unmodule` | `start` |
153
+ | `operand` | `address`, `select` (`lo`, `hi`, `value` or `expr`), `symbol` and `offset` (optional), or `expression` for `expr` |
154
+ | `unoperand` | `address` |
155
+ | `patch` | `start`, `end`, `switch`, `code` (empty for NOP only), `comment` (optional) |
156
+ | `unpatch`, `unuse` | `start` |
157
+ | `macro` | `name`, `params` (a list or a comma list), `body`, `comment` (optional) |
158
+ | `unmacro` | `name` |
159
+ | `use` | `start`, `end`, `macro`, `args` (a list or a comma list) |
160
+
161
+ 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. The script checks an `operand`, `patch` or `use` write against the program of the knowledge in the space of `--space`. All writes become one revision. If the knowledge refuses one write, the script writes nothing, and the error names the write.
162
+
163
+ The c64-provenance skill writes a batch with `match --out`. The batch holds the names of library routines at their addresses in this program. Read the `batch.leftOut` of its result first. Then apply the batch with the command in its `apply`.
164
+
165
+ ## Listing
166
+
167
+ `listing` reads the program and the other knowledge, and writes no knowledge. Use it in place of your own disassembler.
168
+
169
+ - `listing` gives one line for each instruction of a code region, and one `!byte` line for other bytes. A line has the name of the address, the instruction with the names of its target, and the comments. An operand expression of the knowledge replaces the operand. `analyzerNames` gives the second names. `referencesIn` and `referencesOut` count the references. 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. `--out` writes the listing as text to a project file.
170
+
171
+ ## Batches of parallel agents
172
+
173
+ 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 of an agent has the form `{"owner": "$1000-$1fff", "ops": [...]}`. `ops` holds the writes, as for `apply`. The owner ranges must not overlap.
113
174
 
114
- 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. All writes become one revision. If the knowledge refuses one write, the script writes nothing, and the error names the write.
175
+ `join` makes one batch from the batch files. It writes no knowledge.
176
+
177
+ - 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.
178
+ - 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.
179
+ - The regions of the owner come after the regions of the other batches. Thus the regions of the owner stay where they overlap.
180
+ - A name from a batch stays when another batch removes the symbol at that address.
181
+ - `choices` lists each place where the batches gave different values, with the value that stays.
182
+ - When one name or one module file is at two addresses, `join` writes nothing. `clashes` lists the addresses and the batches. Correct the batches, then do `join` again.
183
+
184
+ Then apply the joined batch with the command in `apply`.
115
185
 
116
186
  ## Modules
117
187
 
118
- A module tells the c64-source skill where a file of the generated source starts. The file runs to the next module or to the end of its segment. Each address has one module, and each file name has one module. A file name has letters, digits, underscores or hyphens, and ends in `.asm`. The c64-source skill writes `main.asm`, `loader.asm` and `constants.asm` itself. Thus a module cannot have one of these names, in upper or lower case. The title becomes the first line of the file. A `module` write without a title keeps the title that the module has. Modules have a history, and `revert` restores them.
188
+ A module tells the c64-source skill where a file of the generated source starts. The file runs to the next module or to the end of its segment. Each address has one module, and each file name has one module. A file name has letters, digits, underscores or hyphens, and ends in `.asm`. The c64-source skill writes `main.asm`, `loader.asm`, `constants.asm` and `macros.asm` itself. Thus a module cannot have one of these names, in upper or lower case. The title becomes the first line of the file. A `module` write without a title keeps the title that the module has. Modules have a history, and `revert` restores them.
189
+
190
+ ## Operand expressions
191
+
192
+ An operand expression tells the c64-source skill 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.
193
+
194
+ Give one selector:
195
+
196
+ | Option | Operand | Source |
197
+ |---|---|---|
198
+ | `--lo <symbol>` | The low byte of the symbol plus the offset | `lda #<irq_handler` |
199
+ | `--hi <symbol>` | The high byte of the symbol plus the offset | `lda #>(sprite_bank+$1000)` |
200
+ | `--value <symbol>` | The symbol plus the offset | `lda bar_colours-1,x` |
201
+ | `--expr <text>` | ACME expression text with names and numbers | `lda #(sprite_bank + 5*64) / 64` |
202
+
203
+ - `--offset` adds a whole number to the symbol. Write a negative offset as `--offset=-1`.
204
+ - A name is a symbol of the knowledge or a platform name of the c64-memory-map skill.
205
+ - `--expr` takes `$`, `%` and decimal numbers, names, brackets, the operators `+ - * / % << >> >>> & | XOR`, and `<`, `>`, `-` and `!` before an operand.
206
+ - The script compares the value of the expression with the operand in the program of the knowledge. If they are not equal, the script refuses the write.
207
+ - 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.
208
+ - A `rename` of a symbol changes the name in each expression. The knowledge refuses `remove-symbol` while an expression uses the symbol. Use `unoperand` first.
209
+
210
+ 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.
211
+
212
+ ## Code switches
213
+
214
+ A patch is ACME code that replaces a range of the program when the build defines its switch as 1. Use patches to change the program, for example for a crack, a trainer or a debug hook. The default build does not define the switch. Thus the c64-source skill still makes a source that is identical to the program.
215
+
216
+ - A switch name is upper case, for example `CRACK` or `TRAINER`. It cannot be the name of a symbol or a platform name.
217
+ - Many patches can have the same switch. The c64-source skill builds each switch on its own. It does not build two switches together.
218
+ - The code must fit in the range. NOP ($EA) fills the bytes after the code. `--nop` gives a range of NOP only.
219
+ - `--code` gives the code as text. `--code-file` reads the code from a project file. The code can use the labels and the macros of the source, and local labels with a dot, for example `.skip`.
220
+ - The braces in the code must be pairs, because the source puts the code inside `{ }`.
221
+ - A patch cannot overlap another patch or a macro use.
222
+ - Each byte of the range must be in the program of the knowledge.
223
+ - A `patch` write without `--comment` keeps the comment that the patch has.
224
+
225
+ Build the program with a switch on with the c64-assembler skill: `--define CRACK=1`.
226
+
227
+ ## Macros
228
+
229
+ 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.
230
+
231
+ - `macro` writes the ACME macro: its name, its params and its body. `--params` gives the params as a comma list, without a dot. The body uses each param with a dot, for example `.dst`.
232
+ - `use` writes the instructions from the start to the end as one use of a macro. `--args` gives one expression for each param, as a comma list. Each name in an arg is a symbol of the knowledge or a platform name.
233
+ - The range of a use is complete instructions of the program of the knowledge.
234
+ - A `rename` of a symbol changes the name in each arg. The knowledge refuses `remove-symbol` while an arg uses the symbol.
235
+ - The knowledge refuses `unmacro` while the macro has uses. It also refuses a change of the number of params while the macro has uses.
236
+ - A use cannot overlap a patch or another use.
237
+
238
+ The c64-source skill writes a use only when the use gives the bytes of the program. If not, it writes the instructions and gives the reason. The c64-static-analysis skill finds uses of known 6502 idioms and writes them to a batch with `--macro-batch`.
119
239
 
120
240
  ## Removals
121
241
 
122
- `remove-symbol`, `unclassify` and `unreference` block the place for DXA and Ghidra. An analysis does not add a symbol at that address, a region in that range or that reference again. This applies to every removed fact, also to a fact from the LLM.
242
+ `unclassify` and `unreference` block the place for DXA and Ghidra. An analysis does not add a region in that range or that reference again. This applies to every removed fact, also to a fact from the LLM. `remove-symbol` does not block the address, because an analyzer name never becomes a symbol.
123
243
 
124
244
  - `suppressions` lists the blocked places with the reason of each removal. `at` and `history` also show them.
125
245
  - A `rename`, `classify` or `reference` at a blocked place ends the block there, because your own fact is at the place then.
@@ -146,7 +266,7 @@ The script records the origin `llm`. Use `--origin user` only when the user deci
146
266
 
147
267
  For a read: the current or historical knowledge in compact JSON.
148
268
 
149
- For a write: the new revision and the current value after the write. If the write replaces a symbol or a region of a different origin, `previous` gives that row as it was before the write. For example, an `llm` write over a `user` name gives `previous`. Read `previous` and tell the user about the change. For `apply`, `replaced` lists each write that replaced a row. Each item has the number of the write, its `op` and its `previous`.
269
+ For a write: the new revision and the current value after the write. If the write replaces a symbol, a region or an operand expression of a different origin, `previous` gives that row as it was before the write. For example, an `llm` write over a `user` name gives `previous`. Read `previous` and tell the user about the change. For `apply`, `replaced` lists each write that replaced a row. Each item has the number of the write, its `op` and its `previous`.
150
270
 
151
271
  The exit status is 0 for a result. The exit status is 1 for an error from the knowledge, for example `conflict`. The exit status is 2 for a wrong argument.
152
272
 
@@ -155,7 +275,8 @@ The exit status is 0 for a result. The exit status is 1 for an error from the kn
155
275
  - `conflict`: the change contradicts current knowledge. For example, the name belongs to another address. Read that address and its history, then decide.
156
276
  - `stale-revision`: the knowledge changed after you read it. Read it again, then decide again.
157
277
  - `not-found`: there is nothing to remove or no such revision.
158
- - `invalid-database` or `unsupported-schema`: tell the user the message. Do not edit the file.
278
+ - `conflict` with "from a git merge": git joined the knowledge of two computers, and two rows are current where the knowledge permits one row. For example, two names are at one address. Every read shows these rows in `conflicts`. Writes stop until you run `merge`. The `merge` command keeps the newest row of each conflict and closes the other rows, in one revision. Its result lists each choice. Tell the user the choices.
279
+ - `invalid-database` or `unsupported-schema`: tell the user the message. Do not edit the knowledge files.
159
280
 
160
281
  A revert makes a new revision. The history stays complete.
161
282
 
@@ -164,3 +285,4 @@ A revert makes a new revision. The history stays complete.
164
285
  - Runtime evidence → c64-emulator
165
286
  - Static evidence → c64-static-analysis
166
287
  - Source from the knowledge → c64-source
288
+ - Names of routines that other programs share → c64-provenance