@henols/c64-re-tools 1.1.0 → 2.0.0-rc.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (159) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +154 -37
  3. package/distribution/package.ts +21 -0
  4. package/distribution/plugin.ts +122 -0
  5. package/package.json +34 -40
  6. package/skills/c64-assembler/SKILL.md +76 -0
  7. package/skills/c64-assembler/scripts/assemble.ts +110 -0
  8. package/skills/c64-assembler/scripts/compare.ts +84 -0
  9. package/skills/c64-basic/SKILL.md +66 -0
  10. package/skills/c64-basic/scripts/basic.ts +46 -0
  11. package/skills/c64-disk/SKILL.md +93 -0
  12. package/skills/c64-disk/scripts/containers.ts +124 -0
  13. package/skills/c64-disk/scripts/disk.ts +120 -0
  14. package/skills/c64-emulator/SKILL.md +134 -0
  15. package/skills/c64-knowledge/SKILL.md +166 -0
  16. package/skills/c64-knowledge/scripts/knowledge.ts +492 -0
  17. package/skills/c64-memory-map/SKILL.md +79 -0
  18. package/skills/c64-memory-map/scripts/memmap.ts +92 -0
  19. package/skills/c64-provenance/SKILL.md +110 -0
  20. package/skills/c64-provenance/scripts/compare.ts +152 -0
  21. package/skills/c64-provenance/scripts/provenance.ts +334 -0
  22. package/skills/c64-provenance/scripts/runtime.ts +191 -0
  23. package/skills/c64-provenance/scripts/separate.ts +140 -0
  24. package/skills/c64-reverse-engineering/SKILL.md +144 -0
  25. package/skills/c64-source/SKILL.md +126 -0
  26. package/skills/c64-source/scripts/generate.ts +490 -0
  27. package/skills/c64-source/scripts/loader.ts +571 -0
  28. package/skills/c64-source/scripts/opcodes.ts +61 -0
  29. package/skills/c64-source/scripts/source.ts +595 -0
  30. package/skills/c64-static-analysis/SKILL.md +119 -0
  31. package/skills/c64-static-analysis/scripts/analyze.ts +275 -0
  32. package/skills/c64-static-analysis/scripts/coverage.ts +78 -0
  33. package/skills/c64-static-analysis/scripts/findings.ts +75 -0
  34. package/skills/c64-static-analysis/scripts/idioms.ts +149 -0
  35. package/skills/c64-static-analysis/scripts/instructions.ts +105 -0
  36. package/skills/c64-testing/SKILL.md +103 -0
  37. package/skills/c64-testing/references/scenario-format.md +116 -0
  38. package/skills/c64-testing/scripts/checklist.ts +51 -0
  39. package/skills/c64-testing/scripts/run.ts +189 -0
  40. package/skills/c64-testing/scripts/scenario.ts +493 -0
  41. package/skills/c64-testing/scripts/test.ts +65 -0
  42. package/skills/c64-unpacker/SKILL.md +135 -0
  43. package/skills/c64-unpacker/scripts/evidence.ts +207 -0
  44. package/skills/c64-unpacker/scripts/loads.ts +209 -0
  45. package/skills/c64-unpacker/scripts/machine.ts +80 -0
  46. package/skills/c64-unpacker/scripts/stages.ts +130 -0
  47. package/skills/c64-unpacker/scripts/unpack.ts +683 -0
  48. package/src/c64.ts +411 -0
  49. package/src/cli/ap-sdk.ts +44 -0
  50. package/src/cli/cleanup.ts +194 -0
  51. package/src/cli/main.ts +125 -0
  52. package/src/cli/status.ts +61 -0
  53. package/src/host/main.ts +134 -0
  54. package/src/host/server.ts +392 -0
  55. package/src/host/tools/c1541.ts +284 -0
  56. package/src/host/tools/index.ts +35 -0
  57. package/src/host/tools/petcat.ts +77 -0
  58. package/src/host/tools/status.ts +47 -0
  59. package/src/host/tools/version.ts +41 -0
  60. package/src/host/vice/adapter.ts +804 -0
  61. package/src/host/vice/binary-monitor.ts +389 -0
  62. package/src/host/vice/chips.ts +118 -0
  63. package/src/host/vice/connect.ts +34 -0
  64. package/src/host/vice/process.ts +413 -0
  65. package/src/host/vice/screen.ts +184 -0
  66. package/src/host/vice/session.ts +1426 -0
  67. package/src/host/vice/text-monitor.ts +223 -0
  68. package/src/host-client/autostart.ts +55 -0
  69. package/src/host-client/connect.ts +241 -0
  70. package/src/host-client/coverage.ts +63 -0
  71. package/src/host-client/steps.ts +170 -0
  72. package/src/host-client/tools.ts +89 -0
  73. package/src/host-client/transfer.ts +126 -0
  74. package/src/host-client/vice-session.ts +316 -0
  75. package/src/knowledge/database.ts +132 -0
  76. package/src/knowledge/history.ts +163 -0
  77. package/src/knowledge/import.ts +391 -0
  78. package/src/knowledge/read.ts +342 -0
  79. package/src/knowledge/schema.ts +229 -0
  80. package/src/knowledge/write.ts +663 -0
  81. package/src/mcp/main.ts +134 -0
  82. package/src/mcp/output.ts +32 -0
  83. package/src/mcp/server.ts +316 -0
  84. package/src/mcp/tools/debug.ts +327 -0
  85. package/src/mcp/tools/execution.ts +117 -0
  86. package/src/mcp/tools/input.ts +72 -0
  87. package/src/mcp/tools/machine.ts +100 -0
  88. package/src/mcp/tools/media.ts +129 -0
  89. package/src/mcp/tools/memory.ts +250 -0
  90. package/src/mcp/tools/video.ts +271 -0
  91. package/src/native/acme.ts +116 -0
  92. package/src/native/discover.ts +179 -0
  93. package/src/native/dxa.ts +166 -0
  94. package/src/native/ghidra/analyze.ts +86 -0
  95. package/src/native/ghidra/index.ts +173 -0
  96. package/src/native/ghidra/language/c64rt_6510.cspec +34 -0
  97. package/src/native/ghidra/language/c64rt_6510.ldefs +15 -0
  98. package/src/native/ghidra/language/c64rt_6510.pspec +15 -0
  99. package/src/native/ghidra/language/c64rt_6510.slaspec +596 -0
  100. package/src/native/ghidra/scripts/C64Export.java +274 -0
  101. package/src/native/ghidra/scripts/C64Prepare.java +60 -0
  102. package/src/native/local.ts +34 -0
  103. package/src/native/processes.ts +350 -0
  104. package/src/native/run.ts +172 -0
  105. package/src/native/staging.ts +83 -0
  106. package/src/native/status.ts +113 -0
  107. package/src/native/types.ts +257 -0
  108. package/src/native/watchdog.ts +78 -0
  109. package/src/package.ts +21 -0
  110. package/src/platform.ts +441 -0
  111. package/src/project.ts +39 -0
  112. package/src/protocol/framing.ts +132 -0
  113. package/src/protocol/messages.ts +259 -0
  114. package/src/protocol/tools.ts +266 -0
  115. package/src/protocol/vice.ts +1348 -0
  116. package/src/script.ts +60 -0
  117. package/src/time.ts +15 -0
  118. package/src/trace.ts +194 -0
  119. package/THIRD-PARTY-NOTICES.md +0 -26
  120. package/bin/cli.mjs +0 -283
  121. package/skills/acme-build/SKILL.md +0 -260
  122. package/skills/acme-build/scripts/acme.mjs +0 -341
  123. package/skills/acme-build/template.a +0 -53
  124. package/skills/c64-disk-access/SKILL.md +0 -159
  125. package/skills/c64-disk-access/scripts/c1541.mjs +0 -569
  126. package/skills/c64-memory-mapping/SKILL.md +0 -631
  127. package/skills/c64-memory-mapping/memmap.json +0 -8800
  128. package/skills/c64-memory-mapping/scripts/driver.mjs +0 -553
  129. package/skills/c64-petcat/SKILL.md +0 -87
  130. package/skills/c64-petcat/scripts/petcat.mjs +0 -221
  131. package/skills/c64-program-recon/SKILL.md +0 -706
  132. package/skills/c64-program-recon/references/control-flow.md +0 -180
  133. package/skills/c64-program-recon/references/graphics.md +0 -79
  134. package/skills/c64-program-recon/references/observation-hazards.md +0 -143
  135. package/skills/c64-program-recon/references/reconstruction.md +0 -133
  136. package/skills/c64-program-recon/references/sound-and-input.md +0 -74
  137. package/skills/c64-program-recon/references/tool-selection.md +0 -78
  138. package/skills/c64-program-recon/scripts/derive.mjs +0 -364
  139. package/skills/c64-program-recon/scripts/packer-finding.mjs +0 -709
  140. package/skills/c64-program-recon/templates/memory-map.template.md +0 -101
  141. package/skills/c64-provenance-diff/SKILL.md +0 -292
  142. package/skills/c64-provenance-diff/scripts/diff-images.mjs +0 -984
  143. package/skills/c64-provenance-diff/scripts/recovery-schema.mjs +0 -395
  144. package/skills/c64-ram-capture/RELEASES.json.example +0 -17
  145. package/skills/c64-ram-capture/SKILL.md +0 -474
  146. package/skills/c64-ram-capture/scripts/compare-cross-binary.mjs +0 -525
  147. package/skills/c64-ram-capture/scripts/compare.mjs +0 -258
  148. package/skills/c64-ram-capture/scripts/derive-transients.mjs +0 -575
  149. package/skills/c64-ram-capture/scripts/dump-artifacts.mjs +0 -317
  150. package/skills/c64-ram-capture/scripts/mcp-module.mjs +0 -174
  151. package/skills/c64-ram-capture/scripts/project-paths.mjs +0 -81
  152. package/skills/c64-ram-capture/scripts/releases.mjs +0 -109
  153. package/skills/c64-ram-capture/scripts/vsf-slice.mjs +0 -147
  154. package/skills/c64-ram-capture/scripts/watch-loads.mjs +0 -581
  155. package/skills/c64-ram-capture/templates/capture-record.template.md +0 -99
  156. package/skills/c64-ram-capture/transients/README.md +0 -137
  157. package/skills/routine-queue-walker/SKILL.md +0 -394
  158. package/skills/routine-queue-walker/scripts/completeness-report.mjs +0 -465
  159. package/skills/vice-wedge-triage/SKILL.md +0 -269
@@ -0,0 +1,134 @@
1
+ ---
2
+ name: c64-emulator
3
+ description: Use this skill to operate and debug the live C64 emulator through the c64-re-tools MCP tools, whose names start with c64_. It loads programs and disks, controls and steps the CPU, and sets breakpoints and watchpoints. It reads and writes memory and registers, types keys, moves a joystick, advances frames and captures the screen. Do not use it for static analysis, project knowledge, assembly or disk inspection.
4
+ ---
5
+
6
+ # c64-emulator
7
+
8
+ ## Purpose
9
+
10
+ Operate and debug the one live C64 that belongs to this MCP session. Get runtime evidence and runtime state from it.
11
+
12
+ This skill does not analyse code statically. It does not write project knowledge. It does not assemble source code.
13
+
14
+ ## Inputs
15
+
16
+ - The machine action or the runtime question.
17
+ - The target address, state or condition, when the question needs one.
18
+ - The project path of the program or disk to load, when the question needs one.
19
+
20
+ Addresses are four hex digits after a dollar sign, for example `$c000`. Resolve a symbol name to its address before you use a tool. The c64-knowledge skill gives the address of a known symbol.
21
+
22
+ ## Tools / execution path
23
+
24
+ Use only the MCP tools. Each MCP session has its own C64. Nothing else can change that C64.
25
+
26
+ | Need | Tool |
27
+ |---|---|
28
+ | Run state, video standard, warp mode, window | `c64_status` |
29
+ | Reset, power cycle | `c64_reset` |
30
+ | Fast emulation | `c64_warp` |
31
+ | Show the C64 to the user in a window, hide it again | `c64_window` |
32
+ | Stop, start, step, step over, step out, exact frames | `c64_execution` |
33
+ | Run until an address, a memory value or a raster position | `c64_run_until` |
34
+ | Stop on an instruction address | `c64_breakpoint` |
35
+ | Stop on a memory read or write | `c64_watchpoint` |
36
+ | Memory | `c64_memory_read`, `c64_memory_write`, `c64_memory_search`, `c64_memory_compare` |
37
+ | CPU registers | `c64_registers` |
38
+ | Code as it is in memory now | `c64_disassemble` |
39
+ | Executed instructions, call chain | `c64_cpu_history`, `c64_backtrace` |
40
+ | Where the CPU spends cycles, which memory it uses | `c64_profile`, `c64_memmap` |
41
+ | Cycle count between two points | `c64_timing` |
42
+ | Video chip, sprites, CIAs, sound chip | `c64_vicii`, `c64_sprite`, `c64_cia`, `c64_sid` |
43
+ | Screen image, screen compare | `c64_screen` |
44
+ | Several of these from one moment | `c64_observe` |
45
+ | Keys, joystick | `c64_keyboard`, `c64_joystick` |
46
+ | Program and disk media | `c64_autostart`, `c64_program_load`, `c64_disk_attach` |
47
+ | Machine state to go back to, also in a later session | `c64_snapshot` (with `out` and `file`) |
48
+
49
+ Each memory and register tool has a `space`. Use `c64` for the computer. Use `drive8` for the CPU of the 1541 disk drive. The memory `view` is `cpu` or `ram`. With `cpu`, you see what the CPU sees now, with ROM and I/O where the memory configuration puts them. With `ram`, you see the RAM under them.
50
+
51
+ For a large result, give `out` with a path in the project. `c64_memory_read`, `c64_disassemble`, `c64_cpu_history` and `c64_screen` then write the result to that file. The answer gives only the file, the number of bytes and a SHA-256. Use it for a memory dump of more than a few hundred bytes, a long listing, or a screen that the user wants to keep.
52
+
53
+ `c64_memmap` keeps RAM, ROM and I/O apart. Use action `summary` to see which code ran. Use action `read` with `out` to keep a coverage run as a file, for example `coverage/attract.bin`. Clear the map before each run that you want to keep apart.
54
+
55
+ ## Workflow
56
+
57
+ 1. Read the project knowledge for the addresses in the question. Use the c64-knowledge skill.
58
+ 2. Get the machine state with `c64_status`.
59
+ 3. Load the subject if it is not loaded. Use `c64_autostart` to start it as a user does. Use `c64_program_load` to put a PRG in memory with no start.
60
+ 4. Set the stop condition. Use a breakpoint, a watchpoint or a `c64_run_until` target. Add a typed condition when the stop must occur only in one state. The `list` result shows the condition of each breakpoint and each watchpoint.
61
+ 5. Run, step or give input. Prefer `c64_run_until` and `advance-frames` to waits. They stop at the same emulated time on every run.
62
+ 6. Read only the state that answers the question. To read several things from one moment, use `c64_observe`.
63
+ 7. Interpret the evidence. Keep the observed facts apart from your conclusions.
64
+
65
+ Write operations need a stopped CPU. Stop the CPU with `c64_execution` action `pause` first.
66
+
67
+ `c64_reset` with `run` false stops the CPU at the first instruction of the reset routine. The result gives that address in `pc`. A reset and `c64_autostart` set `c64_timing` to zero.
68
+
69
+ A cartridge from `c64_autostart` stays in the C64 through every reset, as on a real C64. `c64_status` gives `cartridge: true` while the C64 has it, and `cartridge: false` when it does not. `c64_autostart` of a file that is not a cartridge removes the cartridge first. `c64_autostart` also sets both joysticks to the center first. `joysticksCentred` gives the ports that it changed.
70
+
71
+ Step, next and until-return work only in space `c64`. The emulator cannot stop the disk drive CPU after one instruction. To find when the drive executes an address, use `c64_run_until` with an address target in space `drive8`, or a breakpoint in space `drive8`. The drive can execute a few more instructions before it stops. The computer completes its current instruction. The `pc` in the result is the drive address where it stopped.
72
+
73
+ `c64_keyboard` puts keys in the keyboard queue of the KERNAL. A program that reads the keyboard hardware directly does not see them. Many games do this. The emulator has no command that presses one key of the keyboard matrix. For such a program:
74
+
75
+ - After `c64_window` or a snapshot restore, the profiler of VICE keeps the routines that ran before the restore. Then `c64_profile` can give the cycles of the program to such a routine, for example `$fd50`. Do not trust the routine addresses of `c64_profile` after a restore.
76
+ - VICE 3.10 and older have a known flaw: bits 5-7 of `$DC00` and `$DC01` are always 0. Then `emulatorFlaw` in the result of `c64_keyboard` and `c64_joystick` gives the flaw. With this flaw, a wait for any key that reads all keyboard columns at one time ends without a key. A wait for one specific key, or a compare of the full byte of a joystick port, never ends. Tell the user about the flaw. The next VICE release and the VICE nightly builds do not have it. Joystick port 1 uses the same lines as the keyboard.
77
+ - For one specific key, for example F1 or RUN/STOP, open the window and ask the user to press the key.
78
+ - Do not change the program to make it accept a key.
79
+
80
+ Before a risky experiment, save the state with `c64_snapshot`. Restore it to try again from the same point.
81
+
82
+ The emulator has no window. When the user must type, play or look at the C64, do these steps:
83
+
84
+ 1. Open the window with `c64_window` action `open`.
85
+ 2. Tell the user that the window is open and what to do in it.
86
+ 3. Wait until the user tells you that they finished.
87
+ 4. Close the window with `c64_window` action `close`.
88
+
89
+ The machine, the disk in drive 8, the breakpoints, the watchpoints, the joysticks, warp mode and `c64_timing` stay the same. The CPU stays running or stopped. The result field `notCarried` names the data that the move clears. A second `open` or `close` changes nothing.
90
+
91
+ A read does not change the run state. A running machine continues to run after a read.
92
+
93
+ ## Knowledge
94
+
95
+ Read:
96
+ - the current knowledge for each address and range that the question touches.
97
+
98
+ Automatic write:
99
+ - none.
100
+
101
+ Write after interpretation:
102
+ - a symbol, a region or a comment that the runtime evidence justifies. Record it with the c64-knowledge skill.
103
+
104
+ Do not store:
105
+ - breakpoints or watchpoints
106
+ - memory reads
107
+ - temporary machine state
108
+ - a screen capture, unless the user asks for it as an artifact
109
+
110
+ ## Result
111
+
112
+ The result is the runtime state or evidence that the question asks for.
113
+
114
+ If you cannot get the machine into the necessary state, say which state you could not get. Say what you tried.
115
+
116
+ ## Failure and conflicts
117
+
118
+ - `machine-state-lost` and the message says that the VICE window closed: the window closed before `c64_window` action `close`. The emulator has no window again. The machine state is the same as at the time when the window opened. The breakpoints and the watchpoints stay. Do not use results from the window time. Read the machine state again, then continue.
119
+ - `machine-unavailable` and the message says that the VICE window closed: the session starts the emulator again. Wait a few seconds. Then do the operation again.
120
+ - `machine-state-lost` with a different message: the connection to the host runtime was lost, and the machine state is gone. Do not continue with results from before. The next call starts a new machine when the host runtime runs. Load the program again, and set the breakpoints and the watchpoints again. If the next call gives `machine-unavailable` with a message that the host runtime does not run, obey the rule for that message.
121
+ - `machine-unavailable` and the message names a pause or a dialog in the emulator window: this occurs only while the window is open. Do not send more operations. Tell the user to resume the emulator (Pause, Alt+P) or to close the dialog in the VICE window. Then do the operation again. The machine state does not change.
122
+ - `machine-running`: stop the CPU first, then try again.
123
+ - `installation-incomplete`, or `machine-unavailable` with a message that the host runtime does not run: stop the task. Give the message to the user and wait for the user. The message gives the remedy. Do not make a replacement for the tool or the host runtime, for example your own disk parser, disassembler or emulator script. Do not try to repair the installation.
124
+ - `c64_run_until` with `stopReason` `timeout`: the target did not occur in the frame limit. This is evidence too. Report it.
125
+ - `c64_run_until` with `stopReason` `jam`: the CPU executed a JAM opcode and stopped. Report the address.
126
+
127
+ If the runtime evidence does not agree with the current knowledge, do not change the knowledge. Report the conflict and hand it to c64-knowledge.
128
+
129
+ ## Handoffs
130
+
131
+ - Static explanation of code → c64-static-analysis
132
+ - Durable conclusion or a knowledge conflict → c64-knowledge
133
+ - Comparison or assertion between runs → c64-testing
134
+ - Meaning of a C64 address or register → c64-memory-map
@@ -0,0 +1,166 @@
1
+ ---
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.
4
+ ---
5
+
6
+ # c64-knowledge
7
+
8
+ ## Purpose
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.
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.
13
+
14
+ ## Inputs
15
+
16
+ One of these:
17
+
18
+ - an address, a range or a symbol name to look up
19
+ - text to search for
20
+ - a change to a symbol, a region, a comment or a reference, with a short reason
21
+ - a request to see the history or a revision.
22
+
23
+ ## Tools / execution path
24
+
25
+ Run the script in the project directory. The project directory is the directory that the harness started in.
26
+
27
+ ```
28
+ node <skill>/scripts/knowledge.ts <command> [arguments] [options]
29
+ ```
30
+
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'`.
32
+
33
+ | Need | Command |
34
+ |---|---|
35
+ | Everything known at one address | `at '$2100'` |
36
+ | Find names and comment text | `search player` |
37
+ | Lists in a range | `symbols`, `regions`, `comments`, `references` with `--start` and `--end` |
38
+ | 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` |
40
+ | Name the symbol at an address | `rename '$2100' update_player --kind routine` |
41
+ | Remove a symbol | `remove-symbol '$2100'` |
42
+ | Classify memory | `classify '$3000' '$303f' sprite` |
43
+ | 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 |
45
+ | Make memory unknown, and keep the analyzers out of it | `unclassify '$3000' '$303f'` |
46
+ | Set or remove a comment | `comment '$2100' line Reads joystick 2.` / `uncomment '$2100' line` |
47
+ | Add or remove a reference | `reference '$2000' '$2100' call` / `unreference ...` |
48
+ | Places that a removal blocks | `suppressions` with `--start` and `--end` |
49
+ | Start a file of generated source | `module '$2000' player.asm --title 'Player movement'` / `unmodule '$2000'` |
50
+ | Files of generated source | `modules` |
51
+ | 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` |
54
+
55
+ 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
+
57
+ Symbol kinds are `label`, `routine`, `variable`, `data` and `vector`. Reference kinds are `call`, `jump`, `read`, `write` and `reference`.
58
+
59
+ Region types:
60
+
61
+ | Type | Meaning |
62
+ |---|---|
63
+ | `code` | Instructions. |
64
+ | `bytes`, `words`, `petscii`, `screen`, `bitmap`, `sprite` | Data of that form. |
65
+ | `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
+ | `rts-addresses`, `rts-addresses-split` | The same, with each value the target minus 1, for a PHA, PHA, RTS dispatch. |
67
+ | `jumps` | A table of `JMP abs` instructions. Each 3-byte entry is an entry point. It is code. |
68
+ | `workspace` | RAM that the program writes at run time. Its bytes in the image do not matter. |
69
+ | `unused` | Bytes that nothing executes or reads. |
70
+ | `dual-use` | Code at one time and data or a vector at another time. No analyzer finding conflicts with it. |
71
+
72
+ `--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
+
74
+ ## Workflow
75
+
76
+ Read:
77
+
78
+ 1. Use `at` for the addresses in the question before other work.
79
+ 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.
80
+
81
+ Write:
82
+
83
+ 1. Read the current value with `at`. Note the `revision` in the result.
84
+ 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.
86
+ 4. Read the result. A `revision` of `null` means that nothing changed.
87
+
88
+ Each write is one revision. A classification inside a region splits that region, so regions never overlap.
89
+
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:
91
+
92
+ ```json
93
+ [
94
+ { "op": "rename", "address": "$2100", "name": "update_player", "kind": "routine" },
95
+ { "op": "classify", "start": "$3000", "end": "$303b", "type": "bytes", "element": 6 },
96
+ { "op": "comment", "address": "$2100", "placement": "line", "text": "Reads joystick 2." }
97
+ ]
98
+ ```
99
+
100
+ The ops and their fields:
101
+
102
+ | op | Fields |
103
+ |---|---|
104
+ | `rename` | `address`, `name`, `kind` (optional) |
105
+ | `remove-symbol` | `address` |
106
+ | `classify` | `start`, `end`, `type`, `element` (optional) |
107
+ | `unclassify` | `start`, `end` |
108
+ | `comment` | `address`, `placement` (`line` or `side`), `text` |
109
+ | `uncomment` | `address`, `placement` |
110
+ | `reference`, `unreference` | `from`, `to`, `kind` |
111
+ | `module` | `start`, `file`, `title` (optional) |
112
+ | `unmodule` | `start` |
113
+
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.
115
+
116
+ ## Modules
117
+
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.
119
+
120
+ ## Removals
121
+
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.
123
+
124
+ - `suppressions` lists the blocked places with the reason of each removal. `at` and `history` also show them.
125
+ - A `rename`, `classify` or `reference` at a blocked place ends the block there, because your own fact is at the place then.
126
+ - A `revert` to a revision before the removal also ends the block.
127
+
128
+ ## Knowledge
129
+
130
+ Write after interpretation:
131
+
132
+ - a symbol name that tells what a routine or a variable does
133
+ - a region type that the evidence supports
134
+ - a comment that explains behavior that a name cannot show
135
+ - a reference that the evidence supports.
136
+
137
+ Do not store:
138
+
139
+ - temporary investigation state
140
+ - a guess, only because a routine needs a temporary name
141
+ - confidence or status words in comment text.
142
+
143
+ The script records the origin `llm`. Use `--origin user` only when the user decides the change.
144
+
145
+ ## Result
146
+
147
+ For a read: the current or historical knowledge in compact JSON.
148
+
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`.
150
+
151
+ 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
+
153
+ ## Failure and conflicts
154
+
155
+ - `conflict`: the change contradicts current knowledge. For example, the name belongs to another address. Read that address and its history, then decide.
156
+ - `stale-revision`: the knowledge changed after you read it. Read it again, then decide again.
157
+ - `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.
159
+
160
+ A revert makes a new revision. The history stays complete.
161
+
162
+ ## Handoffs
163
+
164
+ - Runtime evidence → c64-emulator
165
+ - Static evidence → c64-static-analysis
166
+ - Source from the knowledge → c64-source