@henols/c64-re-tools 2.7.0 → 2.8.0-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. package/package.json +1 -1
  2. package/skills/c64-assembler/SKILL.md +23 -38
  3. package/skills/c64-assembler/scripts/assembler.ts +114 -16
  4. package/skills/c64-basic/SKILL.md +11 -31
  5. package/skills/c64-basic/scripts/basic.ts +4 -1
  6. package/skills/c64-development/SKILL.md +2 -2
  7. package/skills/c64-disk/SKILL.md +11 -32
  8. package/skills/c64-docs/SKILL.md +27 -45
  9. package/skills/c64-docs/references/page-types.md +20 -18
  10. package/skills/c64-docs/references/style.md +10 -4
  11. package/skills/c64-docs/scripts/docs.ts +13 -2
  12. package/skills/c64-docs/scripts/lib/reference.ts +47 -5
  13. package/skills/c64-knowledge/SKILL.md +138 -267
  14. package/skills/c64-knowledge/references/batches.md +48 -0
  15. package/skills/c64-knowledge/references/coverage.md +29 -0
  16. package/skills/c64-knowledge/references/source-knowledge.md +72 -0
  17. package/skills/c64-knowledge/references/start-screen.md +44 -0
  18. package/skills/c64-knowledge/scripts/knowledge.ts +266 -61
  19. package/skills/c64-knowledge/scripts/lib/check.ts +133 -0
  20. package/skills/c64-knowledge/scripts/lib/listing.ts +72 -8
  21. package/skills/c64-memory-map/SKILL.md +11 -32
  22. package/skills/c64-packer/SKILL.md +11 -31
  23. package/skills/c64-provenance/SKILL.md +40 -62
  24. package/skills/c64-provenance/scripts/lib/leftovers.ts +8 -3
  25. package/skills/c64-provenance/scripts/provenance.ts +64 -55
  26. package/skills/c64-reverse-engineering/SKILL.md +20 -47
  27. package/skills/c64-reverse-engineering/references/comment-check.md +42 -0
  28. package/skills/c64-reverse-engineering/references/versions.md +47 -0
  29. package/skills/c64-source/SKILL.md +43 -235
  30. package/skills/c64-source/references/export.md +50 -0
  31. package/skills/c64-source/references/loader.md +78 -0
  32. package/skills/c64-source/references/source-format.md +46 -0
  33. package/skills/c64-source/scripts/lib/export.ts +20 -7
  34. package/skills/c64-source/scripts/lib/loader.ts +116 -104
  35. package/skills/c64-source/scripts/source.ts +62 -52
  36. package/skills/c64-static-analysis/SKILL.md +51 -52
  37. package/skills/c64-static-analysis/scripts/lib/coverage.ts +55 -2
  38. package/skills/c64-static-analysis/scripts/lib/idioms.ts +28 -9
  39. package/skills/c64-static-analysis/scripts/static-analysis.ts +69 -15
  40. package/skills/c64-testing/SKILL.md +77 -59
  41. package/skills/c64-testing/references/recording-format.md +5 -79
  42. package/skills/c64-testing/references/scenario-format.md +4 -12
  43. package/skills/c64-testing/scripts/lib/play.ts +16 -8
  44. package/skills/c64-testing/scripts/lib/recording.ts +76 -9
  45. package/skills/c64-testing/scripts/lib/replay.ts +14 -0
  46. package/skills/c64-testing/scripts/lib/runs.ts +112 -1
  47. package/skills/c64-testing/scripts/lib/scenario.ts +12 -6
  48. package/skills/c64-testing/scripts/lib/start-screen.ts +27 -0
  49. package/skills/c64-testing/scripts/testing.ts +37 -15
  50. package/skills/c64-unpacker/SKILL.md +10 -30
  51. package/skills/emulator/SKILL.md +7 -36
  52. package/src/build-name.ts +12 -1
  53. package/src/knowledge/history.ts +8 -0
  54. package/src/knowledge/program.ts +73 -1
  55. package/src/knowledge/read.ts +46 -2
  56. package/src/knowledge/recording-files.ts +32 -0
  57. package/src/knowledge/schema.ts +3 -1
  58. package/src/knowledge/separate.ts +90 -3
  59. package/src/knowledge/start-screen.ts +99 -17
  60. package/src/knowledge/text.ts +2 -1
  61. package/src/knowledge/write.ts +15 -8
  62. package/src/loader.ts +167 -0
  63. package/src/native/c64run.ts +11 -0
  64. package/src/native/decompiler/analyze.ts +7 -6
  65. package/src/native/decompiler/walk.ts +32 -2
  66. package/src/native/dxa.ts +4 -4
  67. package/src/native/types.ts +32 -4
  68. package/src/script.ts +87 -17
  69. package/skills/c64-export/SKILL.md +0 -63
@@ -0,0 +1,42 @@
1
+ # Check of the comments
2
+
3
+ You check comments that another agent wrote about a C64 program. You did not write them. Find each claim that the evidence does not support.
4
+
5
+ ## Inputs
6
+
7
+ - The seed of the check.
8
+ - The project knowledge of the program: the listing, the references and the coverage.
9
+
10
+ ## Procedure
11
+
12
+ 1. Get the comments of the check with its seed. Each comment has an address, a placement and a text. It has a name when the address has a symbol.
13
+ 2. For each comment, read the listing of the code that the comment explains. Start at the address and stop at the end of the routine.
14
+ 3. Read the references to the address. Read the access of each line in the coverage.
15
+ 4. Find each claim of the comment. Check each claim against the code, the references and the coverage. Also check the name.
16
+ 5. Record the verdict of the comment in the check.
17
+ 6. Get the result of the check. Make sure that each comment of the check has a verdict.
18
+
19
+ Do not change the project knowledge. Do not use other comments or the documentation as evidence. They can have the same errors.
20
+
21
+ ## Verdicts
22
+
23
+ - `correct`: each claim agrees with the evidence.
24
+ - `wrong`: one or more claims do not agree with the evidence. Record the class of the error, the evidence, and the correct text or the correct name.
25
+ - `unsure`: the code and the coverage do not show the claim. Record the run that can show it.
26
+
27
+ A comment that does not give a detail is not wrong. A comment that tells more than the evidence shows is wrong.
28
+
29
+ ## Error classes
30
+
31
+ | Class | Errors | Check |
32
+ |---|---|---|
33
+ | `callers` | "Only X calls it", "no code calls it", "each frame". | Read all references to the address: calls, jumps and the entries of address tables. For "each frame", find a path from the interrupt. |
34
+ | `bits` | A wrong bit number or mask. `AND #$7f` clears bit 7. Bit 0 is the lowest bit. | Write the mask in binary. |
35
+ | `registers` | A wrong register or flag, for example a result in X, not in A. | Follow each register and flag from the entry to each RTS. |
36
+ | `bounds` | A count or an end that is wrong by one. `LDX #$07`, `DEX`, `BPL` runs 8 times. | Count the loop. Find out if the end address is in the range. |
37
+ | `units` | Bytes and entries, frames and seconds, or pixels and characters in the wrong place. | Check the step of the index and the size of each element. |
38
+ | `paths` | A claim that is true on one path only. A branch with the wrong sense: `BCC` jumps when the carry is clear. | Read each branch to the end of the routine. |
39
+ | `tables` | A claim about all entries of a table that is true only for some entries. | Read all entries of the table in the listing. |
40
+ | `hardware` | A wrong meaning of a chip register, a ROM routine or a memory configuration. | Find the address in the memory map of the C64. |
41
+ | `place` | A comment that explains other code: the address is wrong, or the code changed. | Compare the comment with the code at its address. |
42
+ | `scope` | A claim of history, intent or a release that nobody examined. | Find the evidence of the claim. |
@@ -0,0 +1,47 @@
1
+ # Project layout and versions
2
+
3
+ The project layout, and the group folder for versions of one program. The section "The stages of a full rebuild" of `<skill>/SKILL.md` refers to them.
4
+
5
+ ## Project layout
6
+
7
+ If the project has no layout, use this one. No script checks it. Each script takes the paths that you give.
8
+
9
+ ```
10
+ releases/ the disk image or the program as you got it
11
+ src/ the generated source
12
+ build/ the built programs. Do not commit them: each build writes them again.
13
+ tests/ the test scenarios, and the recordings in tests/recordings/
14
+ runs/ the runs that the knowledge gives as evidence
15
+ docs/ the documentation, with the reference in docs/reference/
16
+ tools/ scripts for the formats of this program only
17
+ README.md the entry page of the documentation
18
+ ```
19
+
20
+ Commit each folder of the layout other than `build/`, and `.c64-re-tools/knowledge/`. The project knowledge holds the program, the entry state, the bytes of each release and the coverage. Thus the project needs no other folder for them. Put all other files that you make in `.c64-re-tools/local/`, also the captures and the coverage maps after you put them into the knowledge. Do not let git ignore a folder of the layout other than `build/`. Do not change the `.gitignore` files of the project.
21
+
22
+ If the project has a layout, use that layout.
23
+
24
+ A workspace with several projects keeps its routine library in `library/` beside the projects. The library is not a project folder.
25
+
26
+ ## Versions of one program
27
+
28
+ Some releases of a program have a different layout. Their code is at different addresses, so patches cannot hold the differences. Each of these releases is a version of the program. Give each version a project of its own in a group folder:
29
+
30
+ ```
31
+ <game>/ the group folder: not a project
32
+ README.md the shared entry page: the program, each version, and how the versions differ
33
+ docs/ the shared pages: the development, the changes between the versions, the releases, the disk layout
34
+ library/ the routine library of the versions
35
+ tools/ the scripts for the formats of the program, for all versions
36
+ v1/ the project of the first version, with the project layout
37
+ v2/ the project of the second version, with the project layout
38
+ ```
39
+
40
+ 1. Make the group folder in the git repository. Do not put `.c64-re-tools/` in it.
41
+ 2. Ask the user before you move a project folder. Then move the current project into `<game>/v1/`. The project knowledge stays valid after the move.
42
+ 3. Make a project folder for the new version, for example `<game>/v2/`. Start at stage 2 with the file of that release. From the group folder, give `--project v2`. In the empty folder `v2/`, give `--project .`. The first write makes the project.
43
+ 4. Keep the releases with the same layout in one version. Record them as releases with switches. For example, `v2` holds a base release and a second release from a different crack.
44
+ 5. Save the routines of `v1` to the routine library in `<game>/library/`. Give `--library ../library`, because `--library` is relative to the project folder. In stage 7 of `v2`, match the program against that library. Then `v2` gets the names of `v1` for the same routines.
45
+ 6. Use the same folders in each version, for example `src` and `docs/reference`.
46
+ 7. From the group folder, give `--project v1` or `--project v2` to each script. A script can read a file of another version, for example `../v1/releases/<file>`. Use this to compare the releases of two versions. Record each release only in the project of its version.
47
+ 8. Write the facts that the versions share one time, in the pages of the group folder. The pages of each version tell only how that version works.
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: c64-source
3
- description: Generates ACME source code for a C64 program from the project knowledge. 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 of a program. Use it when the source must show new names, comments, regions, modules, macros or patches of the knowledge. Use it to start a new program from a rebuild. It does not change the project knowledge. It does not build or test the program.
3
+ description: Generates ACME source code for a C64 program from the project knowledge. 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 of a program. Use it when the source must show new names, comments, regions, modules, macros or patches of the knowledge. Use it when the user asks to "export the project", "start a new game from this rebuild" or "make a clean package of the code". It does not change the project knowledge. It does not build or test the program.
4
4
  ---
5
5
 
6
6
  # Generate source
@@ -56,12 +56,11 @@ To get the command list, run the script with no arguments.
56
56
  - A range is `<start>-<end>`, for example `'$c000-$cfff'`. In a JSON file, a range is `start` and `end`.
57
57
  - Bytes in a JSON file are hex in a field `data`, for example `"data": "a900"`.
58
58
  - 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.
59
- - The script refuses an `--out` path in `.c64-re-tools/knowledge/` and the index of the knowledge. Change the project knowledge only with the commands that change it.
59
+ - The script refuses an `--out` path in `.c64-re-tools/knowledge/`. Change the project knowledge only with the commands that change it.
60
60
  - The script refuses a folder where the command writes a file. It refuses a file where the command writes a folder.
61
61
  - When a test or another file is the evidence for a finding in the project knowledge, move it out of `.c64-re-tools/local/` first. The project knowledge refuses that evidence in that folder.
62
- - A coverage map can stay in `.c64-re-tools/local/`. The project knowledge keeps its ranges and its SHA-256.
63
- - Do not move a coverage map after you put it into the project knowledge. The knowledge refers to the map by its path at that time.
64
- - Put a run that is evidence in `runs/<name>/`, with its run file, its results and its snapshot files. Change the paths in the run file to the new paths. Then git keeps them, and another person can do the run again.
62
+ - A coverage map can stay in `.c64-re-tools/local/`. Do not move a coverage map after you put it into the project knowledge.
63
+ - To keep a run as evidence, use the command that keeps a run. It copies the run, its results and its snapshot files into `runs/<name>/`, and it changes the paths in the copy. Then git keeps them, and another person can do the run again.
65
64
  - 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`.
66
65
 
67
66
  ---
@@ -90,15 +89,15 @@ Each flag applies only to the commands in the table. On another command, the scr
90
89
  ### `generate --out <dir>`
91
90
 
92
91
  The command writes the source files in `--out`. Then it checks them.
93
- The folder `--out` gets only source files. The command writes `source-map.json` and `not_executed.json` in `.c64-re-tools/local/generated/<dir>/`. Git ignores this folder.
94
- The same knowledge always gives the same source.
92
+ The folder `--out` gets only source files. The same knowledge always gives the same source.
95
93
  Do not edit the generated files. The next run writes over them. The values in `config.asm` are the one exception.
96
94
  To make the source better, change the project knowledge. Then generate again.
95
+ `<skill>/references/source-format.md` gives the files, the names and the lines of the source.
97
96
 
98
97
  `body` holds these fields:
99
98
 
100
99
  - `result`: `PASS` when every check passes, else `FAIL`.
101
- - `files`: the files that the command wrote, each with `out`, `bytes` and `sha256`. `sourceMap` names `source-map.json`.
100
+ - `files`: the files that the command wrote, each with `out`, `bytes` and `sha256`.
102
101
  - `removed`: the files of an earlier run that the script removed.
103
102
  - `instructions`, `dataBytes` and `undecodedBytes`.
104
103
  - `labels`: `named` labels from the knowledge, and `generated` labels `l_xxxx`.
@@ -109,16 +108,17 @@ To make the source better, change the project knowledge. Then generate again.
109
108
  - `dataOnly`: the knowledge has no entry, no routine, no code region and no executed address in the space.
110
109
  - `entriesInData`: each `--entry` in a data region, with the `region` and its `origin`.
111
110
  - `asBytes`: the instructions that the source has as bytes.
112
- - `notExecuted`: with coverage, the count of instructions that no run executed, and their ranges. `rest` names `not_executed.json`, which has all the ranges. Each range there has its source `file` and the `routine` before it.
111
+ - `notExecuted`: with coverage, the count of instructions that no run executed, and their ranges. Each range has its source `file` and the `routine` before it.
113
112
  - `unusedModules`: modules whose start is in no segment of the program. Often the program does not hold the code that the knowledge describes.
114
113
  - `leftovers`: the bytes that nothing uses, with `bytes` and each range with its `file`. See "The leftovers". `noCoverage` tells that the knowledge has no coverage, so no range is a leftover. `changed` gives the ranges that are `added` to the leftovers and `removed` from them since the earlier run in `--out`.
114
+ - `unknownCode`: code that nothing reaches and that no run executed, which is not a leftover. A flow in `unresolved` can go to it: a JMP through a vector that a run wrote, or a jump whose address a run wrote. Each flow has `at` and `kind`. The default build and the loader keep this code. Find the targets of each flow in the emulator. Record a jump reference from the flow to each target in the project knowledge. When the flow goes outside the program, for example a crash through the I/O area, record the reference to that address. Then generate again.
115
115
  - `operandExpressions`: the count of instructions with an operand expression.
116
116
  - `operandsAsNumbers`: each operand expression that the source has as a number, with its `address`, `expression` and `reason`.
117
117
  - `macroUses`: the count of macro uses in the source.
118
118
  - `macrosAsInstructions`: each macro use that the source has as instructions, with its `start`, `end`, `macro` and `reason`.
119
119
  - `patchesNotWritten`: each patch that the source does not have, with its range, `switch` and `reason`.
120
120
  - `switches`, `default`, `releases`: the checks of the switches. See "Switches and releases".
121
- - `loader`: the check of the loader. See "The loader".
121
+ - `loader`: the loader program and its check. `<skill>/references/loader.md` gives its fields and the action for each result.
122
122
  - `staleLoader`: a run without `--loader` kept `loader.asm` and the loader program of another knowledge revision, or of another version of the toolkit. `files` gives the files. `revision` gives the revision of `loader.asm`, and `version` its toolkit version. Without `revision`, `loader.asm` does not give one. `noEntryState: true` tells that the knowledge has no entry state for a new loader. A change in a space that the loader does not hold does not make the loader stale. The loader holds space `c64` and the space of the stage of the start screen.
123
123
  - `staleReference`: each reference folder of the project that has pages of this source from an earlier knowledge revision. Each item has the `folder` and the `revision` of its pages.
124
124
 
@@ -147,63 +147,20 @@ Do these actions for the findings:
147
147
  | `entriesInData` | An analyzer region of data hides the code at the entry. If the entry is code, record a code region at the entry in the project knowledge. A region of the user or the LLM replaces the analyzer region. |
148
148
  | `invalid-input` that names a symbol or a module | Change that symbol or module in the project knowledge. |
149
149
  | `conflict` | The knowledge has conflicts from a git merge. Merge the open changes of the project knowledge. Then run the command again. |
150
- | A list with `rest` | Give a larger `--max-listed`. For `notExecuted`, read the file in `rest`. |
150
+ | A list with `rest` | Give a larger `--max-listed`. |
151
+ | `loader.verified: false` | Do the action of `<skill>/references/loader.md` for the `reason`. |
151
152
  | `staleLoader` | The loader can copy bytes that are not the bytes of the source. Run `nextAction`, which generates with `--loader`. With `noEntryState: true`, remove the files when the build does not use them. |
152
153
  | `staleReference` | The reference pages do not agree with the new source. When you do not change the knowledge again, generate the reference pages again from this source into each `folder`. |
153
154
 
154
- #### The source files
155
-
156
- - `main.asm` sets the address of each segment. It includes the files in address order.
157
- - Each module in the knowledge is one file. A module starts at its address. It stops at the next module or at the end of its segment. The file of a module can be in a folder, for example `music/driver.asm`. Without modules, each segment is one file, `segments/segment_xxxx.asm`.
158
- - `constants.asm` holds the names of addresses outside the program, for example `EXTCOL = $d020`. It also holds the register names in the program, for example `RASTER = $d012`. The names are in groups by memory area, in address order. Drive code and banks have one group only.
159
- - The side comment of a constant is the knowledge comment of the address. Without a comment, it is the platform meaning. When the knowledge name is not the platform name, the platform name comes first. For an I/O mirror without a meaning, the comment gives the register that the mirror repeats.
160
- - After the side comment, `Used:` counts how the source uses the name. The kinds are `read`, `written`, `modified`, `called`, `jumped to`, `jumped through`, `branched to`, `pointer`, `address`, `table` and `macro argument`. `address` is an immediate operand expression. `table` is an entry in a table of addresses. A macro line counts one `macro argument` for each name in its args. The other bytes that the macro reads or writes, for example the high byte of a 16-bit value, count for no name.
161
- - `config.asm` holds the value of each switch, for example `PROTECTION = 0`. The switches are in groups by kind. The side comment gives the releases that have the switch on, the ranges of its patches and the comment of the switch.
162
- - You can change a value in `config.asm` to 0 or 1. The next run keeps the values of the file. It adds a new switch with its default. It removes a switch that the knowledge does not have.
163
- - When the knowledge has a start screen, `config.asm` also has `START_SCREEN = 1`. Set it to 0 to start the program at once. Then assemble `loader.asm` again.
164
- - `start_screen.asm` is the code that shows the start screen and waits. It is the same for each program. `loader.asm` gives it the values of the start screen.
165
- - `switches.asm` holds each release of the knowledge. `main.asm` and `loader.asm` include it first. The script writes it only when the knowledge has switches or releases, or when the source has leftovers. For each release, a block `!ifdef RELEASE_<label>` gives each switch the value of that release.
166
- - `leftovers/leftover_xxxx.asm` holds a range of leftovers. See "The leftovers".
167
- - `macros.asm` holds the macros of the knowledge. `main.asm` and `loader.asm` include it.
168
-
169
- #### Names in the source
170
-
171
- - A label or a constant gets the name of the address in the knowledge.
172
- - Without a knowledge name, it gets the platform name, for example `EXTCOL` or `CHROUT`. A platform name wins over an analyzer name (`dxa`, `decompiler` or `heuristic`), for example `EXTCOL` over `ld020`. A `user` or `llm` name wins over a platform name.
173
- - An address in the program without a name gets `l_xxxx`.
174
- - A read or a write in the I/O area `$d000-$dfff` uses the register, also when the program has RAM there. For example, `lda $dd0e` is `lda CI2CRA` and `sta $d012` is `sta RASTER`. `constants.asm` has these names. An address without a platform name stays a number, for example `sta $d800,x`. The data label of the RAM stays at its data. A `user` or `llm` name of the address wins over the register.
175
- - A platform name in an operand expression of the knowledge stays in the source. When the program has the address, `constants.asm` has the name, and the RAM there keeps its label.
176
- - The source uses the names of a ROM only when the program uses that ROM. With coverage, the program uses a ROM 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.
177
- - When the program uses no ROM, the zero page and pages 2 and 3 get no system names. An operand expression or a macro use with such a name gets that reason.
178
-
179
- #### Lines in the source
180
-
181
- - `sta $d011 ; $d011: yScroll 3, rows 25, displayEnabled` is a store of an immediate to a register with a known meaning. The side comment gives the decoded value. A side comment in the knowledge replaces it.
182
- - Code regions, and the decoded instructions outside of data regions, become instructions.
183
- - Data regions become data by their type: `!byte`, `!word`, `!pet`, `!scr`, `!fill`, tables of labels, and sprite bytes in binary.
184
- - `lda+2 $0012` is an absolute operand below $0100. `+1` is a zero-page operand with a label.
185
- - `sta NMINV+1` is an address inside a platform entry of more than one byte, for example the high byte of a vector.
186
- - `lda room_colours+5` is an address inside a data region with a named start. The address has no name of its own.
187
- - `name = * + 1` is a label inside an instruction, for example for code that changes its own operand.
188
- - `lda #<irq_handler` and `lda bar_colours-1,x` are operand expressions of the knowledge. An expression in a non-immediate mode that starts with a bracket gets `0+` before it. ACME reads `(...)` as indirect.
189
- - `; = <irq_handler` at the end of an instruction with a number: the source cannot use this operand expression. `operandsAsNumbers` gives the reason.
190
- - `!byte` with an instruction as its comment: ACME writes this instruction with a different opcode. The bytes keep the source identical.
191
- - `not decoded` marks bytes in a code region that the script did not decode.
192
- - `; not executed $xxxx-$yyyy` starts code that no run of the coverage executed. The range is the same as in `not_executed.json`.
193
- - `+inc16 ptr` is a use of a macro of the knowledge. The comments inside a use go to its side comment.
194
- - `!zone patch_PROTECTION_100e` starts a patch. The condition is the switch state that the program does not have. It is `!if TRAINER` when the base release has the switch off. It is `!if PROTECTION = 0` when the base release has it on.
195
- - A patch block has the code of the patch and NOP to the end of the range. `else` has the code of the base release. The labels inside the range come before the zone as `name = * + n`.
196
- - Alternatives are patches of two or more switches at one range. They follow as `} else { !if FIX_B {`. A line before them stops the build with `!error` when two of them are in.
197
-
198
155
  #### The leftovers
199
156
 
200
- A leftover is a range of the program that nothing uses: unused code, old copies and old data. The script finds the leftovers from the coverage, as the export finds its free ranges (see "The free ranges"). The start screen, the patches and the addresses that the code of a patch names are never leftovers. A macro use in code that nothing uses is in the leftover with that code. A leftover never cuts a macro use in two.
157
+ A leftover is a range of the program that nothing uses: unused code, old copies and old data. The start screen, the patches and the addresses that the code of a patch names are never leftovers. A macro use in code that nothing uses is in the leftover with that code. A leftover never cuts a macro use in two.
201
158
 
202
159
  - Each range of leftovers is a file `leftovers/leftover_xxxx.asm`. When a range cuts a module, the module continues after the range in `<module>_xxxx.asm`, in the folder of the module. The module in the knowledge does not change.
203
160
  - `main.asm` builds a leftover file only when `LEFTOVERS` is 1. When it is 0, the build skips the bytes. Thus the addresses after the range do not change.
204
161
  - `config.asm` has `LEFTOVERS = 0`. Thus the default build is the clean program, without the leftovers.
205
162
  - Each release has `LEFTOVERS = 1`. Thus the build of a release gives the bytes of the release.
206
- - The loader program never has the leftovers. The plain form does not copy them, and the memory there keeps the bytes that were in it before. The packed form unpacks the build of `main.asm` in one piece, so the leftovers in it are $00. A leftover after the last byte of that build is not in it: the memory there keeps the bytes that were in it before.
163
+ - The loader program never has the leftovers. The memory of a leftover range does not hold the bytes of the program.
207
164
  - Without coverage, no range is a leftover. Put the coverage of the runs into the project knowledge. Then generate again.
208
165
  - When `leftovers.changed` has ranges, the default build and the loader program now leave out other bytes. A test that observes the `added` bytes on the loader program gets other values there. Fill the `added` ranges in the test of the leftovers. In a test that compares them, exclude them with the reason that they are leftovers.
209
166
  - A leftover can be wrong when the coverage does not show a use. For example, the VIC-II reads a range, or the program reads a range before it writes it. Then a test of the loader program fails. Record the region in the project knowledge, or put the coverage of more runs into it. Do not change the source.
@@ -229,118 +186,18 @@ Each item of `switches` has `name`, `kind`, `default`, `base`, `define` and the
229
186
 
230
187
  `default` has `in`, `result` and `changedBytes`, as in `switches`. When `default` has `overflow` and the message `turn on one of them`, two alternatives are in the default build. Give one of the switches the default of the base release.
231
188
 
232
- Each item of `releases` has `label`, `base`, `define` and `result`. The check compares the build with each segment of the release. The build compare of the assembler does the same.
189
+ Each item of `releases` has `label`, `base`, `define` and `result`. The check compares the build with each segment of the release.
233
190
 
234
191
  - `identical`: the build gives the bytes of each segment of the release.
235
192
  - `different`: the release has bytes that no patch gives. Compare the release with the program. Then record a switch and a patch for each difference.
236
193
  - `does not assemble`: read the ACME diagnostics.
237
194
  - `notInRelease`: the ranges of the program that the release does not have. The check does not compare them.
238
195
 
239
- The script writes a patch only when its range is complete items of one file. A patch cannot cut an instruction. Its switch name cannot be a name of the source.
240
- The script writes a macro use only when the use gives the bytes of the program. A label inside the range of a use also keeps the instructions. The macro line has no place for the label.
241
-
242
196
  Build the program from the source in these ways:
243
197
 
244
198
  - The build of `config.asm`: no option. With the defaults, this is the default build, without the leftovers.
245
199
  - A release: the build option `--release FIRESTAR`.
246
- - One switch: set its value in `config.asm`, for example `TRAINER = 1`. Do not define a switch on the command line of the build. ACME stops with `Symbol already defined`, because `config.asm` also sets the switch.
247
-
248
- #### The loader
249
-
250
- `--loader` writes `loader.asm` in `--out`. It assembles `loader.asm` to the loader program in `build/`. Git ignores `build/`. The name of the loader program tells its build:
251
-
252
- - `clean_loader.prg`: each value of `config.asm` is its default. This is the clean program.
253
- - `custom_<switches>_loader.prg`: the names of the switches that are not at their default. A switch that is off has `no_` before its name, for example `custom_no_start_screen_loader.prg`.
254
-
255
- The symbols of the loader program are in `build/symbols/<name>.json`, for example `build/symbols/clean_loader.json`. They hold the labels of `loader.asm`, `main.asm` and `start_screen_stage.asm`. Give this file to a test of the loader program as its symbols. When the name changes, the script removes the loader program of the earlier run and its symbols.
256
-
257
- The loader does these steps:
258
-
259
- 1. `10 SYS 2061` starts it.
260
- 2. It stops the interrupts and makes all RAM visible. It moves its copier to two free pages.
261
- 3. It copies each segment without the leftovers, and the pages $0002-$03ff of the entry state, into place. No copy writes over the packed bytes of a copy that has not run yet.
262
- 4. When the knowledge has a start screen and `START_SCREEN` is 1, it shows the start screen. It waits until the user releases all keys and fire buttons. Then it waits for a key, or for a fire button on joystick port 1 or 2, and for its release. A move of a joystick is not a key.
263
- 5. It sets the screen registers of the VIC-II and the VIC bank from the entry state. Then it waits for the raster line of the entry.
264
- 6. It sets the CIA timers, their latches and the interrupt masks from the entry state. A running timer gets the value that counts down to the timer value at the entry.
265
- 7. It sets $00/$01, the stack pointer, A, X, Y and the flags. Then it jumps to the entry.
266
-
267
- The copy table, the copier and the jump use labels, not numbers. `loader_from_xxxx` and `loader_end_xxxx` are around each packed segment. `loader_to_xxxx` is its first address in place. Thus a segment can change its length, and the loader still works.
268
-
269
- The loader changes the free stack byte below the stack pointer (`stackByte`). It does not set the SID, the time of day of the CIAs, the CIA interrupt flags or the interrupt registers of the VIC-II. A program that reads SID voice 3 for random numbers can thus give a different result. A start screen writes the colour RAM, and the loader does not set it again. When you compare the reference and the rebuild, observe after the program sets its own random numbers.
270
-
271
- The script builds and checks the loader program with the values of `config.asm`. With the defaults, the loader program is the clean program: no copy protection, all corrections and no leftovers. The entry state is the state of the base release. For a loader of a release, build `loader.asm` with the build option `--release <label>`. That loader also does not have the leftovers.
272
-
273
- The start screen:
274
-
275
- - The start screen needs the VIC-II values of the entry state. Its screen, bitmap, charset and colours must be in a segment of the program, or in a captured stage. See "The start screen of a captured stage".
276
- - With a start screen, the copier uses three pages, not two.
277
- - The start screen is part of the clean build only. The loader program always shows it. A release build has no start screen, and `LEFTOVERS = 1` also turns it off.
278
- - To start the program at once, set `START_SCREEN = 0` in `config.asm`, and assemble `loader.asm`. Do not define `START_SCREEN` on the command line of the build: `config.asm` sets it.
279
- - A test that runs the loader program stops at the start screen, because the start screen waits for a key. Run until `loader_start_screen_wait`. Then set the PC to `loader_start_screen_continue`.
280
-
281
- `loader` holds these fields:
282
-
283
- - `program`, the `copies` in their order, `copier` and `stackByte`.
284
- - `verified: true`: the check ran the loader program to its jump to the entry. There, the memory, $00/$01, the registers and the VIC-II are equal to the entry state. The raster line and the CIA values are also equal. An interrupt can run right at the entry, as in the program of the base release.
285
- - `limits`: each CIA value that the loader cannot set as it was at the entry. An old capture has no CIA values. Then capture the program again at its entry point.
286
- - `startScreen`: with a start screen, `shown: true` when the VIC-II had the values of the start screen, and `waits: true` when the start screen waited without a key. `wait` and `continue` are the addresses of the wait and of the code after it. The check sets the PC to `continue`, and then runs the loader to its jump.
287
- - `packed`: `packedBytes` and `unpackedBytes` of the packed form. With a start screen of a captured stage, this is the packed program in the loader program.
288
- - `stage`: the show stage of a start screen of a captured stage. It has the `space` of the stage and the address of the show `code`. It also has the `bytes` of the stage in the loader program, the `stash` copies, `packedBytes` and `unpackedBytes`. `startScreen.stage` names the space.
289
- - When the check of the loader program cannot run, the script does not write a loader program. The loader program of an earlier run stays as it was. `loader.asm` is new. `reason` tells why the check did not run.
290
- - `kept`: when the result has no new loader program, the paths of the loader programs of an earlier run. They are not of this source.
291
-
292
- Do these actions when `verified` is `false`:
293
-
294
- | Field | Action |
295
- |---|---|
296
- | `reason` about the copy order, the free pages or the count of copies | The reason gives the ranges. Capture the program again with fewer segments, or write the loader by hand. |
297
- | `reason` about the packed form | If a tool is missing, stop the task and give the message to the user. If the free ranges are too small, write the loader by hand. If the check of the unpack fails, give the reason to the user. |
298
- | `reason` that the source does not assemble | Correct the source first. The loader includes the source. |
299
- | `reason` about the start screen | Correct the start screen in the project knowledge, or capture the program again with the start screen in memory. If the start screen is not necessary, remove it from the project knowledge. |
300
- | `reason` about the show stage | If the reason names the coverage of the stage, run the stage with coverage. Put the map into the project knowledge in the space of the stage. If the memory is too small, capture the stage again with less memory. If a tool is missing, stop the task and give the message to the user. If `start_screen_stage.asm` does not assemble, stop the task and give the reason to the user. The reason names the file in `.c64-re-tools/local/` with the source that failed. |
301
- | `reason` that the check of the loader program did not run | Stop the task and give the reason to the user. When the user tells you that the emulator is available, run the same command again. |
302
- | `differences` | The loader ran. The list gives the bytes and the registers that are not equal. |
303
- | `stop` | The loader did not get to its copier or its jump. `stop` gives the address and `port`, the value of $01. `history` gives the last 16 instructions. `cause` gives the first byte of the copier or of a copy that is not correct. |
304
-
305
- #### The start screen of a captured stage
306
-
307
- Often the loading stage of a program shows a picture that is not in memory at the entry. Then the knowledge has the picture in the captured stage of the space `loading`. `--stage` of the start screen names that space. `--call` names a routine of the stage, for example the routine that starts the loading tune.
308
-
309
- The loader then always has the packed form, and the start screen is a program of its own in front of it:
310
-
311
- 1. Exomizer packs the program with the copier. This is the packed loader.
312
- 2. Exomizer packs the packed loader, the bytes of the stage and the show code into the loader program.
313
- 3. When the loader program starts, Exomizer unpacks these parts. The program stays packed. The bytes of the packed loader under the stage go to a stash in free memory.
314
- 4. The show code shows the start screen with `start_screen.asm`. With a call, it sets $01 to $37, starts the interrupts and calls the routine.
315
- 5. It waits for a key or a fire button, as the start screen in the program does.
316
- 6. It stops the interrupts and the sound, and it stops the screen. It sets the CIA timers as RUN leaves them.
317
- 7. It copies the stash back to the packed loader. Then it starts the packed loader, which unpacks the program over the start screen.
318
-
319
- The program is packed while the screen shows. Thus the picture and the tune have more free memory.
320
-
321
- - The script puts everything in memory. It does not matter where the stage keeps its bytes, if the memory has enough room.
322
- - The loader program has only the bytes of the stage that the start screen uses. These are the screen, the bitmap and the charset. With a call, they are also each byte of the stage that is not free from the call, as in "The free ranges". A call thus needs the coverage of the stage.
323
- - With colours from the colour RAM of the capture, the show code holds the 1000 colours. It copies them to the colour RAM.
324
- - The patches of the stage are in at the defaults of their switches. Thus a patch under a switch can remove the text of a crack from the picture.
325
- - `start_screen_stage.asm` holds the show code and the bytes of the stage. Do not edit it. To make the loader program again, run `generate --out <dir> --loader`.
326
- - The show stage needs Exomizer. The show code needs free memory in $0400-$9fff or $c000-$cfff. When the memory is too small, the reason gives the largest free ranges.
327
- - The check runs the loader program to `loader_start_screen_wait` of the show stage. There, it compares the VIC-II with the start screen, the screen bytes in memory with the stage, and the colour RAM with the capture. Then it sets the PC to `loader_start_screen_continue`, and it checks the loader as usual.
328
-
329
- #### The packed loader
330
-
331
- A loader file that loads into $d000 or higher writes the I/O area. When the program is too large for one loader file, `loader.asm` has the packed form:
332
-
333
- - `loader.asm` holds only the copier and the bytes below $0400. The segments at $0400 and higher are not in `loader.asm`. Between its free ranges, `loader.asm` holds the bytes of the program.
334
- - The loader program is the build of `main.asm` from $0400 and the build of `loader.asm`, packed into one file. Where the two builds overlap, the loader program has the bytes of `loader.asm`.
335
- - The jump to the entry uses the address of the entry, not its label.
336
-
337
- To make the packed loader for other switch values, do these steps:
338
-
339
- 1. Assemble `main.asm` without an output path. The build name of the program tells the switch values, for example `build/custom_trainer.prg`. The leftovers are $00 in this build.
340
- 2. Assemble `loader.asm` without an output path, for example to `build/custom_trainer_copier.prg`. This is the copier. The build name has `copier` in place of `loader`, so the build does not write over the loader program.
341
- 3. Pack the two files into `build/custom_trainer_packed.prg`. The start address is the copier address in the comment at the start of `loader.asm`. The memory configuration at the exit is `$34`.
342
-
343
- These steps do not work when a segment starts below $0400. They also do not work when a patch is between the free ranges of `loader.asm`. In these cases, use `generate --out <dir> --loader` for the base release.
200
+ - Other switch values: the build option `--switch TRAINER=1`, one time for each switch. `config.asm` does not change. With a loader, this build also gives the loader program of these switch values. See "The loader of other switch values".
344
201
 
345
202
  ---
346
203
 
@@ -350,6 +207,7 @@ These steps do not work when a segment starts below $0400. They also do not work
350
207
 
351
208
  The command writes the program of the knowledge as the start of a new program: a new project folder and a zip file of it. A person changes the source of the new project directly.
352
209
  First, make sure that `generate` gives `PASS`. The command writes nothing until all its checks pass.
210
+ `<skill>/references/export.md` gives the free ranges and the files of the new project.
353
211
 
354
212
  The command sets each switch to its export value:
355
213
 
@@ -367,6 +225,7 @@ The build with these values can change bytes only in the patches. Then the comma
367
225
  - `switches`: each switch with `kind`, `base` and the export `value`.
368
226
  - `free`: the count of free bytes, and each free range with `bytes`, `what` and `label`.
369
227
  - `unreachableExecuted`: each range of executed code that the entry does not get to, with the `routine` before it and its `drop` value.
228
+ - `unknownCode`: code that nothing reaches and that no run executed, which stays because a flow in `unresolved` can go to it. Record the targets of each flow as for `generate`. Then export again.
370
229
  - `knowledge`: the counts of the rows of the new knowledge.
371
230
  - `tests`: the `written` tests, and the `leftOut` tests with the reason.
372
231
  - `loader`: the copies, the copier, `stackByte` and `simulated: true`. The export does not run the loader.
@@ -384,60 +243,21 @@ On `FAIL`, `hint` gives the action for the stage:
384
243
  | `export` | This is a defect of the script. Give the result to the user. |
385
244
  | `loader` | Read `reason`, and give it to the user. The export does not make the packed form of the loader. |
386
245
 
387
- Traps of the command:
388
-
389
- - The command refuses a folder that is not empty, and a zip file that exists. Remove the folder and the zip file of an earlier export, or give another folder.
390
- - The command refuses two switches that change one range. The export puts both alternatives in. In the project knowledge, give all but one of them the kind `change`, with the default of the base release.
391
- - The command refuses a `--drop` range that code which stays goes to or reads. The message names that code. It also refuses a range that cuts code or a region.
392
-
393
- #### The free ranges
394
-
395
- A block of code stops after RTS, RTI, JMP, BRK or a JAM, and before a gap. A block of code becomes free only when both of these are true:
396
-
397
- - No run of the coverage executed it.
398
- - No path gets to it from the entry, the hardware vectors or the code that stays. A path is a call, a jump, a branch, a reference of the knowledge or an operand expression. An entry of a table, and two immediate operands that give its address, are paths too.
399
-
400
- Two immediate operands give an address only in these cases:
401
-
402
- - The code stores the low byte and the high byte to two adjacent addresses outside $d000-$dfff.
403
- - The code calls a routine with the low byte and the high byte in two registers.
404
- - The code pushes the high byte and then the low byte onto the stack.
405
-
406
- An operand expression of the knowledge at an immediate operand replaces these cases for that operand. Thus an operand expression with a constant stops a wrong address.
407
-
408
- A call or a jump to ROM is not a path. The coverage shows where the CPU sees ROM. Without coverage, $01 of the entry state shows it. Known code of the knowledge is never ROM.
409
-
410
- Code that a run executed always stays. `unreachableExecuted` lists the executed code that the entry and the vectors do not get to. An example is a copy check whose call the export removed. Give its `drop` value to `export` to make it free.
411
-
412
- Data becomes free only when all of these are true:
413
-
414
- - Its region type is `bytes`, `words`, a table of addresses, `petscii`, `workspace` or `unused`.
415
- - No run read, wrote or executed a byte of it.
416
- - No code that stays reads it or names it. No table that stays has an entry in it.
417
- - It is not in the BASIC line that starts the program, and not at $fffa-$ffff.
418
- - No `charset`, `sprite`, `bitmap` or `screen` region has a byte of it. For example, `unused` bytes in a bitmap stay.
246
+ Each range of `unreachableExecuted` is code that a run executed and that the entry does not get to now. Find the code that calls the range in the project knowledge:
419
247
 
420
- The coverage does not show the reads of the VIC-II. Thus `charset`, `sprite`, `bitmap` and `screen` data stay, unless `--drop` names them. The bytes of the start screen always stay. Bytes without a region also stay.
421
-
422
- The entry is the entry of the knowledge. Without it, the entry is the address of the first SYS in the BASIC line of the program. Without coverage, nothing becomes free without `--drop`. Without an entry and without the hardware vectors in the program, no code is unreachable.
248
+ | Caller | Action |
249
+ |---|---|
250
+ | Only code that the export removed, for example a copy check | Drop the range. |
251
+ | Code that the knowledge does not show, for example a call through a pointer | Keep the range. |
252
+ | You are not sure | Ask the user. |
423
253
 
424
- #### The new project
254
+ To drop a range, remove the folder and the zip file of the export. Then export again, and give `--drop` with each range. When a test of the new project gives `FAIL`, the export dropped a range that the program uses. Remove the folder and the zip file. Export again without that range in `--drop`.
425
255
 
426
- ```text
427
- README.md the steps to build and test, the free ranges and the origin
428
- src/ main.asm, constants.asm, macros.asm, the modules in their folders and loader.asm
429
- baseline/<name>.prg the exported program, and baseline/<name>.json with its symbols
430
- tests/ the tests of the project, changed for the new program
431
- .c64-re-tools/knowledge/ the knowledge of the new program
432
- ```
256
+ Traps of the command:
433
257
 
434
- - The source has no mark line, no `switches.asm` or `config.asm`, no patch zones and no `; not executed` lines. A start screen stays in the loader. Build with `-DSTART_SCREEN=0` to start the program at once. It keeps the names, the comments, the operand expressions and the macros. A line comment at each changed patch gives the switch, its kind, its value and the comments.
435
- - The knowledge has one revision `export`. It holds the program, the entry and its state, the names, the comments, the regions, the modules and the start screen. It has no history, analyzer names, references, operand expressions, macros, patches, switches, releases or coverage.
436
- - A scenario of `tests/` compares the build of the new project with the baseline. Both sides are the same program. Thus a step of the reference side alone goes. A step of the rebuild side alone runs on both sides.
437
- - A run file of `tests/` runs the build of the new project. Scenarios and run files take the names from the symbol files.
438
- - The export leaves out a test that restores a snapshot. It also leaves out a test with a name that the new program does not have, or with an address in a free range.
439
- - The export does not copy recordings, record files or `runs/`.
440
- - The zip file holds the folder without `.c64-re-tools/local/`.
258
+ - The command refuses a folder that is not empty, and a zip file that exists. Remove the folder and the zip file of an earlier export, or give another folder. Remove only the folder and the zip file that this task made.
259
+ - The command refuses two switches that change one range. The export puts both alternatives in. In the project knowledge, give all but one of them the kind `change`, with the default of the base release.
260
+ - The command refuses a `--drop` range that code which stays goes to or reads. The message names that code. It also refuses a range that cuts code or a region.
441
261
 
442
262
  ---
443
263
 
@@ -450,8 +270,9 @@ tests/ the tests of the project, changed for the new program
450
270
  5. Record names, comments, regions and modules in the project knowledge.
451
271
  6. Run `generate` again. Do steps 4 to 6 again until the source is clear.
452
272
  7. Assemble `main.asm` to a program. This is the default build. For a release, give the build option `--release <label>`.
453
- 8. For an unpacked program, run `generate --out <dir> --loader` at the end. Compare the loader program with the program of the base release in a test.
454
- 9. To start a new program from the rebuild, run `export`.
273
+ 8. For an unpacked program, run `generate --out <dir> --loader` at the end. Compare the loader program with the program of the base release in a test. The loader program is in `loader.program`, and its symbols file is in `loader.symbols`.
274
+ 9. To start a new program from the rebuild, tell the user the export value of each switch. If the user wants another value, change the kind or the default of the switch in the project knowledge. Then run `export`, and build and test the new project as its `README.md` tells.
275
+ 10. Give the user the folder and the zip file, the value of each switch, the free ranges, and each test with its result.
455
276
 
456
277
  ---
457
278
 
@@ -459,24 +280,15 @@ tests/ the tests of the project, changed for the new program
459
280
 
460
281
  Each command prints one JSON envelope on one line on stdout. Notes go to stderr.
461
282
 
462
- On success, the exit code is 0:
463
-
464
- ```json
465
- {"ok": true, "command": "<command>", "body": {}, "hint": "...", "nextAction": "..."}
466
- ```
467
-
468
- On failure, the exit code is 2:
469
-
470
- ```json
471
- {"ok": false, "command": "<command>", "code": "<code>", "error": "...", "hint": "...", "nextAction": "..."}
472
- ```
473
-
283
+ - On success, the exit code is 0: `{"ok": true, "command": "<command>", "body": {}, "hint": "...", "nextAction": "..."}`
284
+ - On failure, the exit code is 2: `{"ok": false, "command": "<command>", "code": "<code>", "error": "...", "hint": "...", "nextAction": "..."}`
474
285
  - `body` holds the result. The section of each command gives the fields of its body.
475
286
  - A check gives its verdict in `body.result`: `PASS`, `FAIL` or `INCONCLUSIVE`. The exit code is 0 for each verdict. Thus read `body.result`, not the exit code.
476
- - `error` is one sentence. It tells what is wrong.
477
- - `hint` tells what to do or what to examine. Read it before your next step. Some envelopes have no `hint`.
478
- - `nextAction` is a full command line. It runs from any directory. Run it when it agrees with your task. Some envelopes have no `nextAction`.
479
- - `code` does not change between versions. Do the action for the code:
287
+ - `error` is one sentence. It tells what is wrong. `hint` tells what to do or what to examine. Read it before your next step.
288
+ - `nextAction` is a full command line. It runs from any directory. Run it when it agrees with your task.
289
+ - A list has `count`, `listed` and `rest`. `listed` holds at most `--max-listed` items. `rest` tells how to get the other items. A file that the command wrote has `out`, `bytes` and `sha256`.
290
+ - To get only some fields of `body`, give `--fields <path>,<path>`, for example `--fields count,listed.start`. A path through a list gives that field of each item. Do not write code to filter an envelope.
291
+ - To get the command list, run the script with no arguments. To get the subjects and the flags of one command, run `<command> --help`.
480
292
 
481
293
  | `code` | Action |
482
294
  |---|---|
@@ -485,12 +297,8 @@ On failure, the exit code is 2:
485
297
  | `operation-failed` | Give `error` and `hint` to the user. |
486
298
  | Another code | Do as `hint` tells. |
487
299
 
488
- These fields have the same meaning in each body:
489
-
490
- | Field | Meaning |
491
- |---|---|
492
- | `out`, `bytes`, `sha256` | A file that the command wrote: its path, its size and its SHA-256. |
493
- | `count`, `listed`, `rest` | A list. `count` is the number of items. `listed` holds the first items, at most `--max-listed`. `rest` tells how to get the other items. |
300
+ ## Reference
494
301
 
495
- To get the command list, run the script with no arguments. The envelope has `command: "help"`, and `body.commands` gives the name, the summary and the synopsis of each command.
496
- To get the subjects and the flags of one command, run `<command> --help`. Then `body.subjects` and `body.options` give them.
302
+ - `<skill>/references/source-format.md`: the files of the source, the names in the source and the lines in the source.
303
+ - `<skill>/references/loader.md`: the loader program, the start screen and the loader of other switch values. It also gives the fields of `loader`, and the action when the loader is not verified.
304
+ - `<skill>/references/export.md`: the free ranges of an export and the files of the new project.
@@ -0,0 +1,50 @@
1
+ # Export
2
+
3
+ This file gives the free ranges of an export and the files of the new project. For the command, see the section "Export a new program" of `SKILL.md`.
4
+
5
+ ## The free ranges
6
+
7
+ A block of code stops after RTS, RTI, JMP, BRK or a JAM, and before a gap. A block of code becomes free only when both of these are true:
8
+
9
+ - No run of the coverage executed it.
10
+ - No path gets to it from the entry, the hardware vectors or the code that stays. A path is a call, a jump, a branch, a reference of the knowledge or an operand expression. An entry of a table, and two immediate operands that give its address, are paths too.
11
+
12
+ Two immediate operands give an address only in these cases:
13
+
14
+ - The code stores the low byte and the high byte to two adjacent addresses outside $d000-$dfff.
15
+ - The code calls a routine with the low byte and the high byte in two registers.
16
+ - The code pushes the high byte and then the low byte onto the stack.
17
+
18
+ An operand expression of the knowledge at an immediate operand replaces these cases for that operand. Thus an operand expression with a constant stops a wrong address.
19
+
20
+ Code that a run executed always stays. `unreachableExecuted` lists the executed code that the entry and the vectors do not get to. An example is a copy check whose call the export removed. Give its `drop` value to `export` to make it free.
21
+
22
+ Data becomes free only when all of these are true:
23
+
24
+ - Its region type is `bytes`, `words`, a table of addresses, `petscii`, `workspace` or `unused`.
25
+ - No run read, wrote or executed a byte of it.
26
+ - No code that stays reads it or names it. No table that stays has an entry in it.
27
+ - It is not in the BASIC line that starts the program, and not at $fffa-$ffff.
28
+ - No `charset`, `sprite`, `bitmap` or `screen` region has a byte of it. For example, `unused` bytes in a bitmap stay.
29
+
30
+ The coverage does not show the reads of the VIC-II. Thus `charset`, `sprite`, `bitmap` and `screen` data stay, unless `--drop` names them. The bytes of the start screen always stay. Bytes without a region also stay.
31
+
32
+ The entry is the entry of the knowledge. Without it, the entry is the address of the first SYS in the BASIC line of the program. Without coverage, nothing becomes free without `--drop`. Without an entry and without the hardware vectors in the program, no code is unreachable.
33
+
34
+ ## The new project
35
+
36
+ ```text
37
+ README.md the steps to build and test, the free ranges and the origin
38
+ src/ main.asm, constants.asm, macros.asm, the modules in their folders and loader.asm
39
+ baseline/<name>.prg the exported program, and baseline/<name>.json with its symbols
40
+ tests/ the tests of the project, changed for the new program
41
+ .c64-re-tools/knowledge/ the knowledge of the new program
42
+ ```
43
+
44
+ - The source has no mark line, no `switches.asm` or `config.asm`, no patch zones and no `; not executed` lines. A start screen stays in the loader. Build with `-DSTART_SCREEN=0` to start the program at once. It keeps the names, the comments, the operand expressions and the macros. A line comment at each changed patch gives the switch, its kind, its value and the comments.
45
+ - The knowledge has one revision `export`. It holds the program, the entry and its state, the names, the comments, the regions, the modules and the start screen. It has no history, analyzer names, references, operand expressions, macros, patches, switches, releases or coverage.
46
+ - A scenario of `tests/` compares the build of the new project with the baseline. Both sides are the same program. Thus a step of the reference side alone goes. A step of the rebuild side alone runs on both sides.
47
+ - A run file of `tests/` runs the build of the new project. Scenarios and run files take the names from the symbol files.
48
+ - The export leaves out a test that restores a snapshot. It also leaves out a test with a name that the new program does not have, or with an address in a free range.
49
+ - The export does not copy recordings, record files or `runs/`.
50
+ - The zip file holds the folder without `.c64-re-tools/local/`.