@henols/c64-re-tools 2.3.0-rc.2 → 2.3.0-rc.4

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@henols/c64-re-tools",
3
- "version": "2.3.0-rc.2",
3
+ "version": "2.3.0-rc.4",
4
4
  "description": "Agent-friendly Commodore 64 engineering toolkit for reverse engineering, debugging, development and testing.",
5
5
  "license": "MIT",
6
6
  "author": "Henrik Olsson",
@@ -26,8 +26,7 @@
26
26
  "tools/",
27
27
  "distribution/package.ts",
28
28
  "distribution/plugin.ts",
29
- "LICENSE",
30
- "README.md"
29
+ "LICENSE"
31
30
  ],
32
31
  "engines": {
33
32
  "node": ">=24.0.0"
@@ -18,9 +18,7 @@ This skill does not run the program and does not change project knowledge.
18
18
  - The output path: where to write the PRG, relative to the project folder.
19
19
  - Optional include directories, symbol definitions and a start address.
20
20
 
21
- ## Tools / execution path
22
-
23
- The script runs ACME on this machine. It copies the source root to a temporary directory, assembles it there and writes the program into the project. The host runtime is not necessary.
21
+ ## Tools
24
22
 
25
23
  ```
26
24
  node <skill>/scripts/assembler.ts build src main.a --out build/game.prg
@@ -38,7 +36,7 @@ node <skill>/scripts/assembler.ts build src main.a --out build/game.prg
38
36
  | `--max-listed 200` | Show at most 200 symbols in the result. The default is 50. `symbols.count` gives the count of all symbols. |
39
37
  | `--out-symbols build/game.json` | Write the symbols to this file as `{"symbols": [...]}`. Without `--all-symbols`, the file does not have the constants that the source does not use. Give this file to the c64-testing skill as the symbols of the rebuild. |
40
38
 
41
- The script copies the full source root. Put all files that the program includes under it. Version control directories stay out.
39
+ Put all files that the program includes under the source root.
42
40
 
43
41
  The target CPU is the 6510. The output is a C64 PRG, or the bytes only with `--plain`.
44
42
 
@@ -103,7 +101,7 @@ With `--compare`, `compare` gives `identical` and `segments`: one check for each
103
101
 
104
102
  - `FAIL` with `assembled: false`: the source has errors. Correct the source.
105
103
  - `FAIL` with `assembled: true`: the build is not identical to the program in the knowledge. Read `compare.segments`.
106
- - `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.
104
+ - `installation-incomplete` or `machine-unavailable`: stop the task. Give the message to the user and wait for the user. Do not install, start or change a tool yourself. Do not make a replacement for the tool, for example your own disk parser, disassembler or emulator script.
107
105
  - `invalid-input`: an option or a path is wrong. Read the message and correct the call.
108
106
  - `not-found`: the source root has no main source file with that name, or no folder with files for an `--include`. Give a path relative to the source root.
109
107
 
@@ -112,4 +110,4 @@ With `--compare`, `compare` gives `identical` and `segments`: one check for each
112
110
  - Run or debug the program → emulator
113
111
  - Compare the rebuild with the original → c64-testing
114
112
  - Pack the program into one small PRG that unpacks itself → c64-packer
115
- - Write a new program, or add a feature or a fix → c64-development
113
+ - Write a new program, or add a feature or a correction → c64-development
@@ -15,9 +15,7 @@ This skill does not run the program and does not change project knowledge.
15
15
 
16
16
  - The program: a PRG file, relative to the project folder.
17
17
 
18
- ## Tools / execution path
19
-
20
- The script sends the program to the host runtime. The host decodes it with petcat and finds the handoffs.
18
+ ## Tools
21
19
 
22
20
  ```
23
21
  node <skill>/scripts/basic.ts list extracted/game.prg
@@ -74,7 +72,7 @@ The listing and the handoff addresses.
74
72
 
75
73
  - `invalid-input` with "is no BASIC program": the file is not a BASIC program. Usually the file is machine code. Give it to the c64-static-analysis skill. A memory dump also gives this error: its first two bytes are not a load address, and its bytes go past `$ffff`.
76
74
  - An empty `handoffs` list: the BASIC does not start machine code with SYS or USR. Do not make up a handoff. Look for a POKE into a vector or a LOAD of another file in the listing.
77
- - `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.
75
+ - `installation-incomplete` or `machine-unavailable`: stop the task. Give the message to the user and wait for the user. Do not install, start or change a tool yourself. Do not make a replacement for the tool, for example your own disk parser, disassembler or emulator script.
78
76
  - `not-found` or another `invalid-input`: the path or an argument is wrong. Read the message and correct the call.
79
77
 
80
78
  ## Handoffs
@@ -17,9 +17,9 @@ This skill does not do the specialist work itself.
17
17
  - The acceptance checks: what the user must see or what memory must hold when the work is complete.
18
18
  - The project: its source, its tests and its knowledge.
19
19
 
20
- ## Tools / execution path
20
+ ## Tools
21
21
 
22
- This skill uses the other skills. It does not use the host runtime or the emulator directly.
22
+ This skill uses the other skills. It does not use the emulator tools directly.
23
23
 
24
24
  | Work | Skill |
25
25
  |---|---|
@@ -159,7 +159,7 @@ A program that builds, with a run file in `tests/` for each acceptance check, an
159
159
 
160
160
  ## Failure and conflicts
161
161
 
162
- - A skill reports `installation-incomplete`, or `machine-unavailable` with a message that the host runtime does not run: stop the whole task. Give the message to the user and wait for the user. Do not continue with other skills. Do not make a replacement for the tool or the host runtime, for example your own assembler or emulator script.
162
+ - A skill reports `installation-incomplete` or `machine-unavailable`: stop the whole task. Give the message to the user and wait for the user. Do not continue with other skills. Do not install, start or change a tool yourself. Do not make a replacement for the tool, for example your own assembler or emulator script.
163
163
  - A tool gives a wrong result: tell the user the defect and the evidence, and wait for the user. Do not make a workaround.
164
164
  - A test gives FAIL: change the program until the test gives PASS. Do not change the expected value to make the test pass. Change an expected value only when the user changes the acceptance check.
165
165
  - A run gives FAIL because a `runUntil` did not get to its target: the program did not get to that state. Find why with the emulator skill.
@@ -18,9 +18,7 @@ This skill does not change the disk image and does not change project knowledge.
18
18
  - To extract a file: the output path, relative to the project folder.
19
19
  - A T64 tape file or a CRT cartridge file, relative to the project folder.
20
20
 
21
- ## Tools / execution path
22
-
23
- The script sends a disk image to the host runtime. The host runs c1541 and sends the result back. The script writes an extracted file into the project. It reads T64 and CRT files itself.
21
+ ## Tools
24
22
 
25
23
  ```
26
24
  node <skill>/scripts/disk.ts <command> <image> [name] [--out <file>]
@@ -82,8 +80,6 @@ A downstream skill records the meaning of the extracted content.
82
80
 
83
81
  ## Tapes and cartridges
84
82
 
85
- The script reads T64 and CRT files itself. The host runtime is not necessary for them.
86
-
87
83
  - T64: `directory` and `read`. Many T64 files have a wrong end address. Then the entry has `fixedSize: true`, and the size comes from the position of the next file.
88
84
  - CRT: `directory` and `crt`. The script reads hardware types 0 (normal 8K, 16K or Ultimax), 5 (Ocean), 19 (Magic Desk) and 32 (EasyFlash). It refuses other types by name. `crt` writes `crt.json` and one PRG for each CHIP packet, for example `bank3-8000.prg`.
89
85
  - A cartridge bank uses the same addresses as other banks. Analyze each bank PRG with c64-static-analysis and `--space bank3`, and record its knowledge in space `bank3`.
@@ -99,8 +95,8 @@ The directory, the BAM, an entry or a sector chain as JSON.
99
95
 
100
96
  - `not-found`: the image file is missing, or the image has no file with that name. Read the directory again and compare the names.
101
97
  - `media-error`: the image, the T64 file or the CRT file has a defect, or its content is not of its type. A CRT with a hardware type that the script does not read also gives `media-error`. The message tells the problem, for example a sector chain that loops. Tell the user. Do not change the file.
102
- - `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.
103
- - `invalid-input`: an argument or a path is wrong. A file with an extension that the command does not take is also wrong. The message gives each type that the command takes. Read the message and correct the call.
98
+ - `installation-incomplete` or `machine-unavailable`: stop the task. Give the message to the user and wait for the user. Do not install, start or change a tool yourself. Do not make a replacement for the tool, for example your own disk parser, disassembler or emulator script.
99
+ - `invalid-input`: an argument or a path is wrong. A file with an extension that the command does not take is also wrong. The message gives each type that the command takes. Read the message and change the call.
104
100
 
105
101
  A file that is not `closed` was not written fully. Its data can be incomplete.
106
102
 
@@ -22,9 +22,7 @@ This skill does not change the knowledge.
22
22
  - The program in the knowledge. Put it in with `image` of the c64-knowledge skill. The reference decodes the tables and shows the graphics from it.
23
23
  - The entry page `README.md` and the directory of the other pages, for example `docs`. The reference goes into a directory of its own, for example `docs/reference`.
24
24
 
25
- ## Tools / execution path
26
-
27
- The script runs on this machine. It does not use the emulator or the host runtime.
25
+ ## Tools
28
26
 
29
27
  ```
30
28
  node <skill>/scripts/docs.ts generate src --out docs/reference
@@ -107,7 +105,7 @@ node <skill>/scripts/docs.ts link README.md docs --source src --check
107
105
 
108
106
  - The reference draws each sprite, bitmap and charset region, and it decodes each table. To get the image of a graphic or the entries of a table, classify its region with c64-knowledge. Do not write a script that draws or decodes them.
109
107
  - A script of the project decodes only a format of the program, for example a packed map or a music stream. Put the script in `tools/` of the project. Its output files are the assets, for example in `assets/rooms/`.
110
- - When the code of the program makes the data, run that code in VICE with a run of c64-testing. Observe the memory, or capture the screen. Do not write a 6502 emulator in the script.
108
+ - When the code of the program makes the data, run that code with a run of c64-testing. Observe the memory, or capture the screen. Do not write a 6502 emulator in the script.
111
109
 
112
110
  In the call graph, a solid arrow is a call, a thick arrow is a table entry, and a dotted arrow is a jump. A table entry goes from each routine that reads the table to each target in code. A table of data addresses gives no arrow.
113
111
 
@@ -17,9 +17,9 @@ This skill does not change the rebuilt project or its knowledge.
17
17
  - The folder of the new project. It must be new or empty, and no project can hold it. Use a folder beside the project, for example `../game-new`.
18
18
  - Optional: the coverage of the runs in the knowledge. Without coverage, nothing becomes free by itself.
19
19
 
20
- ## Tools / execution path
20
+ ## Tools
21
21
 
22
- This skill uses the other skills. It does not use the host runtime directly.
22
+ This skill uses the other skills.
23
23
 
24
24
  | Work | Skill |
25
25
  |---|---|
@@ -75,7 +75,7 @@ A new project folder and a zip file of it. Its build is identical to its baselin
75
75
  - `export` gives FAIL with `stage`: read `reason`. The c64-source skill tells what to do for each stage.
76
76
  - `export` refuses the folder: give a new or empty folder outside every project. Remove a folder or a zip file of an earlier export only when this task made it.
77
77
  - A test of the new project gives FAIL: the export dropped a range that the program uses. Remove the folder and the zip file. Run `export` again with `--keep` for the range, then test again.
78
- - A skill reports `installation-incomplete`, or `machine-unavailable` with a message that the host runtime does not run: stop the whole task. Give the message to the user and wait for the user. Do not make a replacement for the tool or the host runtime.
78
+ - A skill reports `installation-incomplete` or `machine-unavailable`: stop the whole task. Give the message to the user and wait for the user. Do not continue with other skills. Do not install, start or change a tool yourself. Do not make a replacement for the tool.
79
79
 
80
80
  ## Handoffs
81
81
 
@@ -84,4 +84,4 @@ A new project folder and a zip file of it. Its build is identical to its baselin
84
84
  - Switches and the code at an address → c64-knowledge
85
85
  - The build of the new project → c64-assembler
86
86
  - The tests of the new project → c64-testing
87
- - A new feature or a fix in the new project → c64-development
87
+ - A new feature or a correction in the new project → c64-development
@@ -7,7 +7,7 @@ description: Use this skill to read, write, correct and review the durable knowl
7
7
 
8
8
  ## Purpose
9
9
 
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.
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 index of the text is `.c64-re-tools/local/knowledge.db`. Do not commit the index.
11
11
 
12
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
 
@@ -21,7 +21,7 @@ One of these:
21
21
  - a capture of the c64-unpacker skill, a PRG, or coverage maps to put into the knowledge
22
22
  - a request to see the history or a revision.
23
23
 
24
- ## Tools / execution path
24
+ ## Tools
25
25
 
26
26
  ```
27
27
  node <skill>/scripts/knowledge.ts <command> [subjects] [options]
@@ -223,7 +223,7 @@ Give one selector:
223
223
  | `--value <symbol>` | The symbol plus the offset | `lda bar_colours-1,x` |
224
224
  | `--expr <text>` | ACME expression text with names and numbers | `lda #(sprite_bank + 5*64) / 64` |
225
225
 
226
- - The address is the start of an instruction in a code region. The script decodes the instructions from the start of the region, as `listing` does. It refuses an address in no code region and an operand byte of an instruction. Classify the code first.
226
+ - 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 and an operand byte of an instruction. Classify the code first.
227
227
  - `--offset` adds a whole number to the symbol. Write a negative offset as `--offset=-1`.
228
228
  - A name is a symbol of the knowledge or a platform name of the c64-memory-map skill.
229
229
  - `--expr` takes `$`, `%` and decimal numbers, names, brackets, the operators `+ - * / % << >> >>> & | XOR`, and `<`, `>`, `-` and `!` before an operand.
@@ -16,9 +16,7 @@ This skill does not read the emulator and does not change project knowledge.
16
16
  - One or more addresses.
17
17
  - Or a register and a value to decode.
18
18
 
19
- ## Tools / execution path
20
-
21
- The script looks up local reference data. It does not use the host runtime.
19
+ ## Tools
22
20
 
23
21
  ```
24
22
  node <skill>/scripts/memory-map.ts at '$d020' '$0314' '$ffd2'
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: c64-packer
3
- description: Use this skill to pack and crunch a C64 program with Exomizer into one PRG that unpacks itself and starts with RUN. It can merge more PRG files into one program. It unpacks the result in an emulator and checks each byte and the entry before it writes the PRG. Use it to make a small release file of a rebuilt or new program. Do not use it to unpack a packed program. Use the c64-unpacker skill for that.
3
+ description: Use this skill to pack and crunch a C64 program with Exomizer into one PRG that unpacks itself and starts with RUN. It can merge more PRG files into one program. It checks each byte and the entry of the result before it writes the PRG. Use it to make a small release file of a rebuilt or new program. Do not use it to unpack a packed program. Use the c64-unpacker skill for that.
4
4
  ---
5
5
 
6
6
  # c64-packer
@@ -9,7 +9,7 @@ description: Use this skill to pack and crunch a C64 program with Exomizer into
9
9
 
10
10
  Pack and crunch PRG files of the project with Exomizer into one PRG. The PRG loads at $0801, starts with RUN, unpacks the program and jumps to its entry. Check the result before you use it.
11
11
 
12
- This skill does not assemble the program, does not run it in VICE and does not change project knowledge.
12
+ This skill does not assemble the program, does not run it in the emulator and does not change project knowledge.
13
13
 
14
14
  ## Inputs
15
15
 
@@ -18,9 +18,7 @@ This skill does not assemble the program, does not run it in VICE and does not c
18
18
  - The entry: the address where the program starts after the unpack. If the first PRG is a BASIC program at $0801 with `SYS` and a number, the script uses that address.
19
19
  - Optional: the value of $01 when the program starts.
20
20
 
21
- ## Tools / execution path
22
-
23
- The script runs Exomizer on this machine. Exomizer packs the files with `sfx`. Then the script unpacks the result with `desfx` in the 6502 emulator of Exomizer. It compares the unpacked bytes with the bytes of the inputs, and the jump address with the entry. The host runtime is not necessary.
21
+ ## Tools
24
22
 
25
23
  ```
26
24
  node <skill>/scripts/packer.ts pack build/game.prg --out build/game-packed.prg
@@ -29,7 +27,7 @@ node <skill>/scripts/packer.ts pack build/loader.prg build/main.prg --entry '$04
29
27
 
30
28
  | Option | Meaning |
31
29
  |---|---|
32
- | `--entry '$0400'` | The address where the program starts after the unpack. It must be `$0400` or higher. A name of the knowledge is also correct. Without it, the script uses the `SYS` address of the BASIC line of the first input. |
30
+ | `--entry '$0400'` | The address where the program starts after the unpack. It must be `$0400` or higher. It can also be a name of the knowledge. Without it, the script uses the `SYS` address of the BASIC line of the first input. |
33
31
  | `--exit-memory '$35'` | The value of $01 when the program starts, `$34` to `$37`. Without it, the value is `$37`: BASIC, KERNAL and I/O. With it, the program starts with interrupts off. |
34
32
 
35
33
  ### Calling the script
@@ -66,7 +64,7 @@ node <skill>/scripts/packer.ts pack build/loader.prg build/main.prg --entry '$04
66
64
 
67
65
  The packed program starts the unpacker with `SYS 2061`, at $080d. A BASIC program at $0801 often has its entry at $080d too. Then the CPU gets to $080d two times: first before the unpack, then at the start of the program. To examine the program at its entry in the emulator, stop at $080d, run one frame, and stop at $080d again.
68
66
 
69
- The unpacker uses $0334 to $03ff and the zero page while it runs. A program that loads into these addresses can fail. Then Exomizer stops with an error, or the check gives `FAIL`.
67
+ The unpacker uses $0334 to $03ff and the zero page while it runs. A program that loads into these addresses can fail. Then the script gives `operation-failed`, or the check gives `FAIL`.
70
68
 
71
69
  ## Knowledge
72
70
 
@@ -83,11 +81,11 @@ Do not store:
83
81
 
84
82
  - `PASS`: the packed program unpacks to the bytes of all inputs and jumps to the entry. The PRG is at `out`.
85
83
  - `FAIL`: the packed program unpacks to different bytes, or jumps to a different address. The script did not write a file.
86
- - `INCONCLUSIVE`: the emulator of Exomizer keeps only the largest range that the unpacker wrote. Bytes of the inputs outside that range have no check. This occurs when the inputs have gaps between them. The PRG is at `out`.
84
+ - `INCONCLUSIVE`: the check has only the largest range that the unpacker wrote. Bytes of the inputs outside that range have no check. This occurs when the inputs have gaps between them. The PRG is at `out`.
87
85
 
88
86
  Other fields:
89
87
  - `packedBytes` and `unpackedBytes`: the size of the packed PRG and of the bytes of the inputs. `percent` is the packed size as a percentage of the unpacked size.
90
- - `unpackSeconds`: the time of the unpack in the emulator of Exomizer, in seconds at the PAL clock. A real C64 can need more time.
88
+ - `unpackSeconds`: the time of the unpack, in seconds at the PAL clock. A real C64 can need more time.
91
89
  - `inputs`: each input with its `loadRange` and its `bytes`.
92
90
  - `check.entry`: the address where the unpacker jumped.
93
91
  - `check.segments`: one check for each segment of the merged inputs. The `result` of a segment is `identical`, `different` with `firstDifference`, or `not covered`. `firstDifference` gives the `address`, the unpacked byte (`built`) and the input byte (`reference`).
@@ -97,8 +95,8 @@ Other fields:
97
95
  - `FAIL`: do not use the packed program. Read `check`. Give the call and the result to the user.
98
96
  - `invalid-input` with `Give --entry`: the first input has no BASIC line with `SYS` and a number. Give `--entry`.
99
97
  - `invalid-input` for the entry: the entry is below $0400. The unpacker runs there. A program with an entry below $0400 needs a different packer.
100
- - `operation-failed` with `Exomizer could not pack the program`: read the last output of Exomizer in the message. Correct the inputs, or give the message to the user.
101
- - `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.
98
+ - `operation-failed` with `Exomizer could not pack the program`: read the last output of Exomizer in the message. Change the inputs, or give the message to the user.
99
+ - `installation-incomplete` or `machine-unavailable`: stop the task. Give the message to the user and wait for the user. Do not install, start or change a tool yourself. Do not make a replacement for the tool, for example your own disk parser, disassembler or emulator script.
102
100
  - `not-found`: there is no file at an input path. Give a path relative to the project folder.
103
101
 
104
102
  ## Handoffs
@@ -25,9 +25,7 @@ This skill does not change project knowledge.
25
25
  - For one release: the program, the coverage and the other knowledge of the project. Put the program and the coverage in with `image` and `coverage` of the c64-knowledge skill.
26
26
  - For the library: the program and the other knowledge of its project, and the library folder.
27
27
 
28
- ## Tools / execution path
29
-
30
- The script compares the releases locally. Only `--frames` uses the host runtime: each release runs in its own emulator.
28
+ ## Tools
31
29
 
32
30
  ```
33
31
  node <skill>/scripts/provenance.ts compare releases/a.prg releases/b.prg releases/c.prg
@@ -60,7 +58,7 @@ Use `--align` for two releases with added code and moved data. One shift does no
60
58
  - `alignedShare`: the share of the bytes of the two releases that a block holds, with 3 decimals.
61
59
  - Each list shows at most 64 items. `moreBlocks`, `moreOnlyInA` and `moreOnlyInB` give the number of the items that the list does not show. Use `--range` to see them.
62
60
 
63
- With `--frames`, a PRG starts with autostart and RUN. An image starts from its bytes: the script writes the segments and the entry state from `entry_state.json` into the emulator, and starts at the entry. Watchpoints on each difference stop the run at its first access.
61
+ With `--frames`, a PRG starts with autostart and RUN. An image starts at its entry, with the entry state from `entry_state.json`. The run records the first access to each difference.
64
62
 
65
63
  ### Calling the script
66
64
 
@@ -226,7 +224,7 @@ The runtime evidence and the leftovers are evidence only. The script does not de
226
224
  - Do not call a byte original only because one release has it. A majority of releases is also not proof.
227
225
  - `common` is empty: the releases do not cover the same addresses. Use `--shift`, or compare a range that all releases cover.
228
226
  - `run.releases` shows `started: false`: a PRG without a BASIC start, or an image without `entry_state.json`. The reason tells which. The other releases still give evidence.
229
- - `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 emulator script.
227
+ - `installation-incomplete` or `machine-unavailable`: stop the task. Give the message to the user and wait for the user. Do not install, start or change a tool yourself. Do not make a replacement for the tool, for example your own emulator script.
230
228
  - `moreDifferences: true`: the script shows only the first differences. Use `--range` to see the others.
231
229
  - `not-found`: the project has no file at that path.
232
230
  - `not-found` from `match`: the library folder does not exist, or it has no routine files. Save a routine with `routine` first.
@@ -22,9 +22,9 @@ This skill does not do the specialist work itself.
22
22
  - reverse engineer and rebuild the whole program
23
23
  - The current project knowledge.
24
24
 
25
- ## Tools / execution path
25
+ ## Tools
26
26
 
27
- This skill uses the other skills. It does not use the host runtime or the emulator directly.
27
+ This skill uses the other skills. It does not use the emulator tools directly.
28
28
 
29
29
  ### Project folder
30
30
 
@@ -175,7 +175,7 @@ A clear answer for the scope, with the durable conclusions in the project knowle
175
175
 
176
176
  ## Failure and conflicts
177
177
 
178
- - A skill reports `installation-incomplete`, or `machine-unavailable` with a message that the host runtime does not run: stop the whole task. Give the message to the user and wait for the user. Do not continue with other skills. Do not make a replacement for the tool or the host runtime, for example your own disk parser, disassembler or emulator script.
178
+ - A skill reports `installation-incomplete` or `machine-unavailable`: stop the whole task. Give the message to the user and wait for the user. Do not continue with other skills. Do not install, start or change a tool yourself. Do not make a replacement for the tool, for example your own disk parser, disassembler or emulator script.
179
179
  - A tool gives a wrong result, and the exit check of a stage cannot be true. Tell the user the defect and the evidence, and wait for the user. Do not make a workaround, for example a change to a generated file. When the user accepts an exception, give the defect and the exception in the answer of stage 12.
180
180
  - If the evidence does not support a conclusion, keep the unknown and get more evidence. Do not make up a meaning.
181
181
  - Before you replace current knowledge from the user or the LLM, read its history and the evidence for it.
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: c64-source
3
- description: Use this skill to generate ACME source code for a C64 program from the project knowledge. The knowledge holds the program, its entry state, the coverage and the names. The script runs Ghidra for the instructions and writes the source files. It checks with ACME that the source assembles to the same bytes as the program. It can also write a loader that sets the entry state of an unpacked program. It can also export the program as the start of a new program. The export is a new project with one value for each switch and without unused code. Use it to make a rebuild. Do not edit the generated files. Change the knowledge and generate again.
3
+ description: Use this skill to generate ACME source code for a C64 program from the project knowledge. The knowledge holds the program, its entry state, the coverage and the names. The script writes the source files. It checks that the source assembles to the same bytes as the program. It can also write a loader that sets the entry state of an unpacked program. It can also export the program as the start of a new program. The export is a new project with one value for each switch and without unused code. Use it to make a rebuild. Do not edit the generated files. Change the knowledge and generate again.
4
4
  ---
5
5
 
6
6
  # c64-source
@@ -15,13 +15,11 @@ This skill does not change the knowledge.
15
15
 
16
16
  - The program in the knowledge. Put it in with `image` of the c64-knowledge skill: a capture of the c64-unpacker skill, or a PRG.
17
17
  - The output directory for the source files, relative to the project folder.
18
- - Optional entry points for Ghidra.
18
+ - Optional entry points of code.
19
19
  - Optional: the coverage in the knowledge. Add it with `coverage` of the c64-knowledge skill.
20
20
  - For the loader: the entry state of a capture in the knowledge.
21
21
 
22
- ## Tools / execution path
23
-
24
- The script runs Ghidra and ACME on this machine. With `--loader`, it also runs the loader in the emulator through the host runtime.
22
+ ## Tools
25
23
 
26
24
  ```
27
25
  node <skill>/scripts/source.ts generate --out src
@@ -32,13 +30,13 @@ node <skill>/scripts/source.ts generate --out src --loader
32
30
  | Option | Meaning |
33
31
  |---|---|
34
32
  | `--out src` | The directory for the source files. The script writes over the files that it generated before. It removes a generated `.asm` file that this run does not write. A run without `--loader` keeps `loader.asm` and `loader.prg` of an earlier run. |
35
- | `--entry '$080d'` | An entry point for Ghidra. Use it again for more entry points. The entry of the program, the routines and the code regions in the knowledge are entry points too. |
33
+ | `--entry '$080d'` | An address where code starts. Use it again for more entry points. The entry of the program, the routines and the code regions in the knowledge are entry points too. |
36
34
  | `--analyzer-names` | Name an address that has no symbol and no platform name with its analyzer name, for example `FUN_17e2`. The order is heuristic, Ghidra, then DXA. Without it, the source makes its own names, for example `l_17e2`. |
37
35
  | `--space drive8` | Generate the source of drive code or a cartridge bank from the knowledge of that space. The coverage, `--loader` and the platform names are only for `c64`. |
38
36
  | `--loader` | Also write `loader.asm` and `loader.prg`. This needs a capture in the knowledge, with its entry and its entry state. |
39
37
  | `--max-listed 20` | List at most this number of items in each list. The default is 50. The counts are always in the result. |
40
38
 
41
- When the knowledge has coverage, code that no run executed gets the line `; not executed` with its range. `notExecuted` lists it. The executed code is also a seed for Ghidra. Thus the source has the code after a JSR to a routine that Ghidra thinks does not return.
39
+ When the knowledge has coverage, code that no run executed gets the line `; not executed` with its range. `notExecuted` lists it. The executed code is always instructions in the source.
42
40
 
43
41
  ### Calling the script
44
42
 
@@ -83,7 +81,7 @@ When the knowledge has coverage, code that no run executed gets the line `; not
83
81
  - A label or a constant gets the name of the address in the knowledge. Without a knowledge name, it gets the platform name of the c64-memory-map skill, for example `EXTCOL` or `CHROUT`. A platform name wins over a name from an analyzer (`dxa`, `ghidra` or `heuristic`), for example `EXTCOL` over `ld020`. A `user` or `llm` name wins over a platform name. An address in the program without a name gets `l_xxxx`.
84
82
  - The source uses the names of a ROM only when the program uses that ROM. When the knowledge has coverage, a ROM is in use when a run executed code of it. A read of ROM bytes as data does not count. Without coverage, `$01` of the entry state tells which ROMs are in. When the program uses neither ROM, the zero page and pages 2 and 3 get no system names. `romNamesLeftOut` gives the ROMs that the source did not name, and the evidence. An operand expression or a macro use with such a name gets that reason.
85
83
  - `sta $d011 ; $d011: yScroll 3, rows 25, displayEnabled` is a store of an immediate to a register that the c64-memory-map skill decodes. The side comment gives the decoded value. A side comment in the knowledge replaces it.
86
- - Code regions, and the instructions that Ghidra decodes outside of data regions, become instructions.
84
+ - Code regions, and the decoded instructions outside of data regions, become instructions.
87
85
  - Data regions become data by their type: `!byte`, `!word`, `!pet`, `!scr`, `!fill`, tables of labels, and sprite bytes in binary.
88
86
  - `lda+2 $0012` is an absolute operand below $0100. `+1` is a zero-page operand with a label.
89
87
  - `sta NMINV+1` is an address inside a platform entry of more than one byte, for example the high byte of a vector.
@@ -92,7 +90,7 @@ When the knowledge has coverage, code that no run executed gets the line `; not
92
90
  - `lda #<irq_handler` and `lda bar_colours-1,x` are operand expressions of the knowledge. The script writes each name of an expression with the name of its address in the source. An operand expression in a non-immediate mode that starts with a bracket gets `0+` before it, because ACME reads `(...)` as indirect.
93
91
  - `; = <irq_handler` at the end of an instruction with a number: the source cannot use this operand expression. `operandsAsNumbers` gives the reason.
94
92
  - `!byte` with an instruction as its comment: ACME writes this instruction with a different opcode. The bytes keep the source identical.
95
- - `not decoded` marks bytes in a code region that Ghidra did not decode.
93
+ - `not decoded` marks bytes in a code region that the script did not decode.
96
94
  - `; not executed $xxxx-$yyyy` starts code that no run of the coverage executed. The range is the same as in `not_executed.json`.
97
95
  - `+inc16 ptr` is a use of a macro of the knowledge. `macros.asm` holds the macros. `main.asm` and `loader.asm` include it. The comments inside a use go to its side comment.
98
96
  - `!zone patch_PROTECTION_100e` starts a patch of the knowledge. The condition is the state that the program does not have. It is `!if TRAINER` when the base release has the switch off. It is `!if PROTECTION = 0` when the base release has it on. The block has the code of the patch and NOP to the end of the range. `else` has the original code. The labels inside the range come before the zone as `name = * + n`. Thus all builds have them.
@@ -136,21 +134,21 @@ The copy table, the copier and the jump to the entry use labels, not numbers. `l
136
134
 
137
135
  The flags go through the free stack byte below the stack pointer (`stackByte`). The loader changes this byte. The loader does not set the SID, the time of day of the CIAs, the CIA interrupt flags or the interrupt registers of the VIC-II. `loader.limits` names each CIA value that the loader cannot set as it was at the entry. A program that reads the SID voice 3 for random numbers can still differ in a scenario. A raster sync does not change a timer or the SID. Then observe after the program sets up its own random numbers. To sync the original and the rebuild in a test, see the sync rules of the c64-testing skill.
138
136
 
139
- The script simulates the copies first. Then it runs `loader.prg` in the emulator to its jump to the entry. It compares the memory, $00/$01, the registers, the screen registers of the VIC-II, the VIC bank and the raster line with the entry state there. It also compares the CIA timers, latches and interrupt masks. `loader.verified: true` tells that all of them are equal. An interrupt can run right at the entry, as in the original program.
137
+ The script runs `loader.prg` to its jump to the entry. It compares the memory, $00/$01, the registers, the screen registers of the VIC-II, the VIC bank and the raster line with the entry state there. It also compares the CIA timers, latches and interrupt masks. `loader.verified: true` tells that all of them are equal. An interrupt can run right at the entry, as in the original program.
140
138
 
141
139
  The entry state is the state of the base release. Thus the script builds and checks `loader.prg` with the switch values of the base release. For a loader of the default build, build `loader.asm` with the c64-assembler skill and no option.
142
140
 
143
141
  ### The packed loader
144
142
 
145
- A loader file that loads into $d000 or higher writes the I/O area. When the image is too large for one loader file, `loader.asm` has the packed form. The packed form needs Exomizer. It has these differences:
143
+ A loader file that loads into $d000 or higher writes the I/O area. When the image is too large for one loader file, `loader.asm` has the packed form. It has these differences:
146
144
 
147
145
  - `loader.asm` holds only the copier and the bytes below $0400: pages $0002-$03ff of the entry state and the parts of segments there. The copier is in one free range, at `loader.copier`. The bytes below $0400 go into free ranges. When one range is too small, they go into more ranges, and each piece is a copy. Between these ranges, `loader.asm` holds the bytes of the image. The segments at $0400 and higher are not in `loader.asm`.
148
- - The script packs the build of `main.asm` from $0400 and the build of `loader.asm` into `loader.prg` with Exomizer. Where the two builds overlap, the bytes of `loader.asm` are in `loader.prg`.
146
+ - The script packs the build of `main.asm` from $0400 and the build of `loader.asm` into `loader.prg`. Where the two builds overlap, the bytes of `loader.asm` are in `loader.prg`.
149
147
  - `10 SYS` starts the unpacker. The unpacker writes all bytes, also at $d000-$dfff. Then it jumps to the copier with all RAM visible ($01 = $34).
150
148
  - The unpacker uses the zero page and $0334-$03ff. Thus the copier writes pages $0002-$03ff after the unpack. Then it does steps 4 to 6.
151
149
  - The jump to the entry uses the address of the entry, not its label. The build of `loader.asm` does not include `main.asm`.
152
150
 
153
- The script checks the unpack in the emulator of Exomizer. All bytes of the two builds must be correct, and the unpacker must jump to the copier. Then the script runs `loader.prg` in the emulator, as for the plain loader. `loader.packed` gives `packedBytes` and `unpackedBytes`.
151
+ The script checks the unpack. All bytes of the two builds must be correct, and the unpacker must jump to the copier. Then the script checks `loader.prg` as for the plain loader. `loader.packed` gives `packedBytes` and `unpackedBytes`.
154
152
 
155
153
  To make the packed loader for other switch values, do these steps:
156
154
 
@@ -186,7 +184,7 @@ The script does these steps. It writes nothing until all the checks pass.
186
184
  - `change`: its default.
187
185
  3. It builds the program with these values. This build can change bytes only in the patches.
188
186
  4. It finds the free ranges. Each free range gets the bytes $00 and the label `free_xxxx`. No address moves.
189
- 5. It makes the source of the new program. ACME must assemble the source to the new program byte by byte. For a capture with an entry state, the script also makes `loader.asm` and simulates its copies. It does not run the loader in the emulator.
187
+ 5. It makes the source of the new program. The source must assemble to the new program byte by byte. For a capture with an entry state, the script also makes `loader.asm` and checks its copies. It does not run the loader.
190
188
  6. It writes the new project and the zip file.
191
189
 
192
190
  ### The free ranges
@@ -260,13 +258,13 @@ Do not store:
260
258
  - `removed`: the files of an earlier run that the script removed from `--out` and did not write again.
261
259
  - `instructions`, `dataBytes` and `undecodedBytes`.
262
260
  - `labels`: `named` labels from the knowledge and `generated` labels `l_xxxx`.
263
- - `entriesInData`: each `--entry` in a data region of the knowledge, with the `region` and its `origin`. Ghidra does not decode an entry in a data region.
261
+ - `entriesInData`: each `--entry` in a data region of the knowledge, with the `region` and its `origin`. The script does not decode an entry in a data region.
264
262
  - `asBytes`: the instructions that the source has as bytes.
265
263
  - `operandExpressions`: the count of instructions that the source has with an operand expression.
266
- - `operandsAsNumbers`: the operand expressions that the source has as a number with a side comment, each with its `address`, `expression` and `reason`. An expression becomes a number when no instruction with an operand value is at the address, or when a name has no address. An expression that ACME refuses or does not assemble to the program also becomes a number. Then the script assembles the source again, at most six times.
264
+ - `operandsAsNumbers`: the operand expressions that the source has as a number with a side comment, each with its `address`, `expression` and `reason`. An expression becomes a number when no instruction with an operand value is at the address, or when a name has no address. An expression that does not assemble to the program also becomes a number.
267
265
  - `unusedModules`: modules in the knowledge whose start is in no segment of the program. Often this tells that the program does not hold code that the knowledge describes.
268
266
  - `entryOutside`: the entry is in no segment of the program in the knowledge, with a `reason`. The capture does not hold the program.
269
- - `dataOnly`: the knowledge has no entry, no routine, no code region and no executed address in the space. Thus the source has only data, and Ghidra does not run. A table or a key page in a cartridge bank is an example.
267
+ - `dataOnly`: the knowledge has no entry, no routine, no code region and no executed address in the space. Thus the source has only data. A table or a key page in a cartridge bank is an example.
270
268
  - `notExecuted`: when the knowledge has coverage, the count of instructions that no run executed, the count of their ranges, and the first ranges. `rest` names the file `not_executed.json` in `--out` when the list is not complete. This file has all of the ranges. Each range has its source `file` and the `routine` before it. `files` counts the ranges in each file.
271
269
  - `macroUses`: the count of macro uses that the source has.
272
270
  - `macrosAsInstructions`: the macro uses that the source has as instructions, each with its `start`, `end`, `macro` and `reason`.
@@ -277,7 +275,7 @@ Do not store:
277
275
  - `releases`: the build of each release. Each item has `label`, `base`, `file`, the `define` and the `result`. `identical` tells that the build gives the bytes of the file. `different` gives the segments that differ. `layout differs` tells that the release has other segments than the program: patches cannot move code, so this result does not fail the run. `file changed` tells that the file is not the file that the knowledge recorded. `does not assemble` gives the diagnostics of ACME.
278
276
  - `loader`: the program, the copies in their order, the copier page, `stackByte`, `verified` and `differences`. A packed loader also has `packed` with `packedBytes` and `unpackedBytes`. `limits` lists the CIA values that the loader cannot set. An entry state from an old capture has no CIA values. Then `limits` tells you to capture the program again. When the script cannot make the loader, `loader` has `verified: false` and a `reason`. The loader includes the source. Thus a source that does not assemble to the program also stops the loader.
279
277
 
280
- `result` is `PASS` when the source is identical and the emulator check of the loader passes. `result` is `FAIL` for a failed check and for an entry in no segment. These also give `FAIL`:
278
+ `result` is `PASS` when the source is identical and the check of the loader passes. `result` is `FAIL` for a failed check and for an entry in no segment. These also give `FAIL`:
281
279
 
282
280
  - a patch that the source does not have
283
281
  - a switch or a default build that does not fit
@@ -302,14 +300,14 @@ Do not store:
302
300
  - `dataOnly`: this is not a failure. If the space has code, give `--entry` or classify the code with the c64-knowledge skill. Then generate again.
303
301
  - `entriesInData`: an analyzer region of data hides the code at the entry. If the entry is code, record a code region at the entry with the c64-knowledge skill, for example `classify '$0500-$05ff' code`. A region of the user or the LLM replaces the analyzer region. Then generate again.
304
302
  - `loader.verified: false` with a `reason`: the script did not make the loader. The script still writes and checks the source. When no copy order or no free pages exist, or the loader needs too many copies, the reason gives the ranges. Capture the program again with fewer segments, or write the loader by hand.
305
- - `loader.verified: false` with a `reason` about the packed form: the image is too large for one loader file. If the reason tells that Exomizer is not installed, stop the task. Give the message to the user. If the free ranges are too small for the copier and the bytes below $0400, the reason gives the largest free ranges. Write the loader by hand. If the unpack check of Exomizer fails, give the reason to the user.
303
+ - `loader.verified: false` with a `reason` about the packed form: the image is too large for one loader file. If the reason tells that a tool is missing, stop the task. Give the message to the user. If the free ranges are too small for the copier and the bytes below $0400, the reason gives the largest free ranges. Write the loader by hand. If the unpack check fails, give the reason to the user.
306
304
  - `loader.verified: false` with `differences`: the loader ran, and `differences` gives the bytes and registers that are not equal.
307
305
  - `loader.verified: false` with `stop`: the loader did not get to its copier or to its jump. `stop` gives the address where it stopped and `port`, the value of $01. `history` gives the last 16 instructions. `cause` gives the first byte of the copier that is not equal to its byte in the loader file. For a packed loader, `cause` gives the first byte of the copier that the unpack did not write. If the copier ran, `cause` can also give the first byte that a copy did not write correctly.
308
306
  - `export` with `stage: "original"`: the source of the knowledge does not pass. Run `generate`, and correct the knowledge until `generate` gives PASS.
309
307
  - `export` with `stage: "switches"`: the build with the export values changes bytes outside the patches, or a patch does not fit. Read `build`. Correct the patches.
310
308
  - `export` refuses two switches that change one range: the export puts both alternatives in. Give all but one of them the kind `change` and the default of the base release with `switch` of the c64-knowledge skill.
311
309
  - `export` refuses `--drop`: read the message. It names the code that stays and goes to the range or reads it, or the code or region that the range cuts.
312
- - `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 disassembler or emulator script.
310
+ - `installation-incomplete` or `machine-unavailable`: stop the task. Give the message to the user and wait for the user. Do not install, start or change a tool yourself. Do not make a replacement for the tool, for example your own disassembler or emulator script.
313
311
 
314
312
  ## Handoffs
315
313
 
@@ -16,9 +16,9 @@ Find the static structure of a C64 program. Record the structure in the project
16
16
  - Entry points: addresses where code starts, for example the SYS address from the c64-basic skill. Routine symbols in the knowledge are entry points too. Ghidra needs at least one. DXA finds the SYS of a BASIC start by itself.
17
17
  - Optional: routines to decompile (Ghidra), or a file for the listing (DXA).
18
18
 
19
- ## Tools / execution path
19
+ ## Tools
20
20
 
21
- The script reads the program, the coverage and the current knowledge, and runs DXA or Ghidra on this machine. The host runtime is not necessary. The script records the result in the project knowledge, `.c64-re-tools/knowledge/`.
21
+ The script reads the program, the coverage and the current knowledge. It records the result in the project knowledge, `.c64-re-tools/knowledge/`.
22
22
 
23
23
  ```
24
24
  node <skill>/scripts/static-analysis.ts analyze --analyzer dxa --out-listing .c64-re-tools/local/game.lst
@@ -112,7 +112,7 @@ The script never replaces a name or a region from the user or the LLM. DXA and G
112
112
 
113
113
  A `heuristic` region replaces the part of a DXA or Ghidra region where it lies, because an idiom is specific evidence about those bytes. DXA and Ghidra never replace a `heuristic` region. If they find code there, the result shows a conflict. A heuristic table can be too long or too short, because the script cannot know its length. Correct it with the c64-knowledge skill. Your region replaces it, and a removal holds.
114
114
 
115
- A new analysis replaces the earlier facts of the same analyzer in the analyzed range, also its analyzer names. The history keeps the earlier facts. Knowledge from an older version can have analyzer names as symbols. A new analysis moves the names of that analyzer to its analyzer names.
115
+ A new analysis replaces the earlier facts of the same analyzer in the analyzed range, also its analyzer names. The history keeps the earlier facts.
116
116
 
117
117
  A fact that the user or the LLM removes does not come back. The next analysis does not write a fact at that place, and counts it as `suppressed`. To remove a wrong fact, use the c64-knowledge skill.
118
118
 
@@ -138,8 +138,8 @@ The exit status is 0, also with conflicts.
138
138
  - `invalid-input` with a message about an entry point: no entry point is inside the program for Ghidra. Give one with `--entry`.
139
139
  - `stale-revision`: the knowledge changed during the analysis. The script recorded nothing. Run the analysis again.
140
140
  - `operation-failed` with a message about an incomplete result or listing: the analyzer did not give a complete result. The script recorded nothing. Tell the user.
141
- - `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.
142
- - `notDecompiled`: Ghidra did not decompile these routines. Each entry has the reason. If the reason says that the decompiler did not start, tell the user the remedy in the reason. On macOS, Ghidra has no native decompiler until the user builds it: `./gradlew buildNatives` in the `support/gradle` directory of Ghidra.
141
+ - `installation-incomplete` or `machine-unavailable`: stop the task. Give the message to the user and wait for the user. Do not install, start or change a tool yourself. Do not make a replacement for the tool, for example your own disk parser, disassembler or emulator script.
142
+ - `notDecompiled`: Ghidra did not decompile these routines. Each entry has the reason. If the reason says that the decompiler did not start, tell the user the remedy in the reason.
143
143
 
144
144
  ## Handoffs
145
145