@henols/c64-re-tools 2.6.0-rc.3 → 2.6.0-rc.5

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 (37) hide show
  1. package/package.json +1 -1
  2. package/skills/c64-assembler/SKILL.md +26 -12
  3. package/skills/c64-assembler/scripts/assembler.ts +25 -13
  4. package/skills/c64-development/SKILL.md +1 -1
  5. package/skills/c64-docs/SKILL.md +4 -4
  6. package/skills/c64-docs/scripts/docs.ts +3 -3
  7. package/skills/c64-docs/scripts/lib/reference.ts +3 -3
  8. package/skills/c64-docs/scripts/lib/source-map.ts +9 -4
  9. package/skills/c64-knowledge/SKILL.md +25 -16
  10. package/skills/c64-knowledge/scripts/knowledge.ts +26 -41
  11. package/skills/c64-packer/SKILL.md +1 -1
  12. package/skills/c64-provenance/SKILL.md +11 -10
  13. package/skills/c64-provenance/scripts/lib/library.ts +16 -16
  14. package/skills/c64-provenance/scripts/provenance.ts +33 -23
  15. package/skills/c64-reverse-engineering/SKILL.md +6 -6
  16. package/skills/c64-source/SKILL.md +46 -39
  17. package/skills/c64-source/scripts/lib/export.ts +5 -4
  18. package/skills/c64-source/scripts/lib/loader.ts +6 -6
  19. package/skills/c64-source/scripts/lib/source.ts +11 -24
  20. package/skills/c64-source/scripts/lib/stage.ts +2 -2
  21. package/skills/c64-source/scripts/source.ts +135 -68
  22. package/skills/c64-static-analysis/SKILL.md +4 -4
  23. package/skills/c64-static-analysis/scripts/static-analysis.ts +26 -33
  24. package/skills/c64-testing/SKILL.md +1 -1
  25. package/skills/c64-testing/references/scenario-format.md +1 -1
  26. package/skills/c64-unpacker/SKILL.md +2 -0
  27. package/skills/c64-unpacker/scripts/lib/loads.ts +33 -12
  28. package/skills/c64-unpacker/scripts/unpacker.ts +5 -3
  29. package/src/build-name.ts +50 -0
  30. package/src/host/vice/session.ts +6 -1
  31. package/src/knowledge/program.ts +44 -1
  32. package/src/knowledge/read.ts +3 -7
  33. package/src/knowledge/schema.ts +27 -8
  34. package/src/knowledge/text.ts +4 -2
  35. package/src/knowledge/write.ts +47 -14
  36. package/src/native/acme.ts +1 -1
  37. package/src/project.ts +13 -1
@@ -72,10 +72,10 @@ Each flag applies only to the commands in the table. On another command, the scr
72
72
 
73
73
  | Flag | Command | Effect |
74
74
  |---|---|---|
75
- | `--out <dir>` | `generate` | The folder for the source files. It is necessary. The script writes over the files of an earlier run. It removes a generated `.asm` file that this run does not write. A run without `--loader` keeps `loader.asm`, `loader.prg`, `start_screen.asm` and `start_screen_stage.asm` of an earlier run. `staleLoader` tells when they are of another knowledge revision. |
75
+ | `--out <dir>` | `generate` | The folder for the source files. It is necessary. The script writes over the files of an earlier run. It removes a generated `.asm` file that this run does not write. A run without `--loader` keeps `loader.asm`, the loader program, `start_screen.asm` and `start_screen_stage.asm` of an earlier run. `staleLoader` tells when they are of another knowledge revision. |
76
76
  | `--entry <address>` | `generate` | An address where code starts. Give the flag again for more addresses. There is no default. |
77
77
  | `--space <space>` | `generate` | The knowledge space: `c64`, `drive8`, `loading`, or `bank0` to `bank255`. The default is `c64`. `--loader` and the platform names apply only to `c64`. The coverage is the coverage of the space. |
78
- | `--loader` | `generate` | Also write `loader.asm` and `loader.prg`, and `start_screen.asm` when the knowledge has a start screen. A start screen of a captured stage also gives `start_screen_stage.asm`. The script writes `loader.prg` only after the check of the new loader ran. Else the `loader.prg` of an earlier run stays. It needs a capture in the knowledge. The default is no loader. |
78
+ | `--loader` | `generate` | Also write `loader.asm` and the loader program, and `start_screen.asm` when the knowledge has a start screen. A start screen of a captured stage also gives `start_screen_stage.asm`. The script writes the loader program only after the check of the new loader ran. Else the loader program of an earlier run stays. It needs a capture in the knowledge. The default is no loader. |
79
79
  | `--analyzer-names` | `generate` | Name an address without a name of the user or the LLM, and without a platform name, with its analyzer name, for example `FUN_17e2`. Without the flag, the source makes its own name, for example `l_17e2`. |
80
80
  | `--to <folder>` | `export` | The folder of the new project. It is necessary. The script also writes `<folder>.zip` beside the folder. |
81
81
  | `--name <name>` | `export` | The name of `baseline/<name>.prg` and `build/<name>.prg`. The default is the name of the folder. |
@@ -89,7 +89,8 @@ Each flag applies only to the commands in the table. On another command, the scr
89
89
 
90
90
  ### `generate --out <dir>`
91
91
 
92
- The command writes the source files, `source-map.json` and `not_executed.json` in `--out`. Then it checks them.
92
+ 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.
93
94
  The same knowledge always gives the same source.
94
95
  Do not edit the generated files. The next run writes over them. The values in `config.asm` are the one exception.
95
96
  To make the source better, change the project knowledge. Then generate again.
@@ -97,7 +98,7 @@ To make the source better, change the project knowledge. Then generate again.
97
98
  `body` holds these fields:
98
99
 
99
100
  - `result`: `PASS` when every check passes, else `FAIL`.
100
- - `files`: the files in `--out`, each with `out`, `bytes` and `sha256`. `sourceMap` names `source-map.json`.
101
+ - `files`: the files that the command wrote, each with `out`, `bytes` and `sha256`. `sourceMap` names `source-map.json`.
101
102
  - `removed`: the files of an earlier run that the script removed.
102
103
  - `instructions`, `dataBytes` and `undecodedBytes`.
103
104
  - `labels`: `named` labels from the knowledge, and `generated` labels `l_xxxx`.
@@ -110,7 +111,7 @@ To make the source better, change the project knowledge. Then generate again.
110
111
  - `asBytes`: the instructions that the source has as bytes.
111
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.
112
113
  - `unusedModules`: modules whose start is in no segment of the program. Often the program does not hold the code that the knowledge describes.
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.
114
+ - `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
115
  - `operandExpressions`: the count of instructions with an operand expression.
115
116
  - `operandsAsNumbers`: each operand expression that the source has as a number, with its `address`, `expression` and `reason`.
116
117
  - `macroUses`: the count of macro uses in the source.
@@ -118,7 +119,7 @@ To make the source better, change the project knowledge. Then generate again.
118
119
  - `patchesNotWritten`: each patch that the source does not have, with its range, `switch` and `reason`.
119
120
  - `switches`, `default`, `releases`: the checks of the switches. See "Switches and releases".
120
121
  - `loader`: the check of the loader. See "The loader".
121
- - `staleLoader`: a run without `--loader` kept `loader.asm` and `loader.prg` of another knowledge revision. `files` gives the files. `revision` gives the revision of `loader.asm`. Without `revision`, `loader.asm` does not give one. `noEntryState: true` tells that the knowledge has no entry state for a new loader.
122
+ - `staleLoader`: a run without `--loader` kept `loader.asm` and the loader program of another knowledge revision. `files` gives the files. `revision` gives the revision of `loader.asm`. Without `revision`, `loader.asm` does not give one. `noEntryState: true` tells that the knowledge has no entry state for a new loader.
122
123
 
123
124
  `result` is `FAIL` for each of these:
124
125
 
@@ -126,7 +127,7 @@ To make the source better, change the project knowledge. Then generate again.
126
127
  - The entry is in no segment of the program.
127
128
  - A patch is in `patchesNotWritten`.
128
129
  - A switch or the default build does not fit.
129
- - A release does not give its file. A release with `layout differs` does not give `FAIL`. But the base release must be `identical`.
130
+ - A release does not give its bytes. A release with `layout differs` does not give `FAIL`. But the base release must be `identical`.
130
131
  - The loader is not verified.
131
132
 
132
133
  `hint` gives the action for each finding. When a change of the project knowledge corrects a finding, `nextAction` is the same `generate` command. Run it after the change. A `PASS` without findings gives a `hint` and no `nextAction`.
@@ -151,7 +152,7 @@ Do these actions for the findings:
151
152
  #### The source files
152
153
 
153
154
  - `main.asm` sets the address of each segment. It includes the files in address order.
154
- - 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. Without modules, each segment is one file, `segment_xxxx.asm`.
155
+ - 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`.
155
156
  - `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.
156
157
  - 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.
157
158
  - 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.
@@ -160,7 +161,7 @@ Do these actions for the findings:
160
161
  - 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.
161
162
  - `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.
162
163
  - `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.
163
- - `leftover_xxxx.asm` holds a range of leftovers. See "The leftovers".
164
+ - `leftovers/leftover_xxxx.asm` holds a range of leftovers. See "The leftovers".
164
165
  - `macros.asm` holds the macros of the knowledge. `main.asm` and `loader.asm` include it.
165
166
 
166
167
  #### Names in the source
@@ -196,13 +197,14 @@ Do these actions for the findings:
196
197
 
197
198
  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, the macro uses and the addresses that the code of a patch names are never leftovers.
198
199
 
199
- - Each range of leftovers is a file `leftover_xxxx.asm`. When a range cuts a module, the module continues after the range in `<module>_xxxx.asm`. The module in the knowledge does not change.
200
+ - 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.
200
201
  - `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.
201
202
  - `config.asm` has `LEFTOVERS = 0`. Thus the default build is the clean program, without the leftovers.
202
- - Each release has `LEFTOVERS = 1`. Thus the build of a release gives the bytes of its file.
203
- - `loader.prg` never has the leftovers. The loader does not copy them, and the memory there keeps the bytes that were in it before.
203
+ - Each release has `LEFTOVERS = 1`. Thus the build of a release gives the bytes of the release.
204
+ - The loader program never has the leftovers. The loader does not copy them, and the memory there keeps the bytes that were in it before.
204
205
  - Without coverage, no range is a leftover. Put the coverage of the runs into the project knowledge. Then generate again.
205
- - 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 `loader.prg` fails. Record the region in the project knowledge, or put the coverage of more runs into it. Do not change the source.
206
+ - 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.
207
+ - 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.
206
208
 
207
209
  #### Switches and releases
208
210
 
@@ -213,7 +215,7 @@ The command does these checks. They use the defaults and the values of the knowl
213
215
  1. `check`: the build of the base release must give the program byte by byte. In this build, each switch has its base value, and `LEFTOVERS` is 1.
214
216
  2. `switches`: each switch alone at its other value. The build must have the same length as the base release. It can change bytes only in the patches of the switch.
215
217
  3. `default`: the default build. It must have the same length. It can change bytes only in the patches of the switches in `default.in` and in the leftovers.
216
- 4. `releases`: each release, built with `RELEASE_<label>=1`, against the file of the release.
218
+ 4. `releases`: each release, built with `RELEASE_<label>=1`, against the bytes of the release in the project knowledge.
217
219
 
218
220
  Each item of `switches` has `name`, `kind`, `default`, `base`, `define` and the patches.
219
221
 
@@ -225,12 +227,11 @@ Each item of `switches` has `name`, `kind`, `default`, `base`, `define` and the
225
227
 
226
228
  `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.
227
229
 
228
- Each item of `releases` has `label`, `base`, `file`, `define` and `result`:
230
+ Each item of `releases` has `label`, `base`, `define` and `result`:
229
231
 
230
- - `identical`: the build gives the bytes of the file.
232
+ - `identical`: the build gives the bytes of the release.
231
233
  - `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.
232
234
  - `layout differs`: the release has other segments than the program. Patches cannot move code. This result does not fail the run.
233
- - `file changed`: the file is not the file that the knowledge recorded. Put back the file, or record the release again in the project knowledge.
234
235
  - `does not assemble`: read the ACME diagnostics.
235
236
 
236
237
  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.
@@ -244,7 +245,14 @@ Build the program from the source in these ways:
244
245
 
245
246
  #### The loader
246
247
 
247
- `--loader` writes `loader.asm` and assembles it to `loader.prg`. The loader does these steps:
248
+ `--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:
249
+
250
+ - `clean_loader.prg`: each value of `config.asm` is its default. This is the clean program.
251
+ - `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`.
252
+
253
+ 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.
254
+
255
+ The loader does these steps:
248
256
 
249
257
  1. `10 SYS 2061` starts it.
250
258
  2. It stops the interrupts and makes all RAM visible. It moves its copier to two free pages.
@@ -258,27 +266,26 @@ The copy table, the copier and the jump use labels, not numbers. `loader_from_xx
258
266
 
259
267
  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 original and the rebuild, observe after the program sets its own random numbers.
260
268
 
261
- The script builds and checks `loader.prg` with the values of `config.asm`. With the defaults, `loader.prg` 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.
269
+ 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.
262
270
 
263
271
  The start screen:
264
272
 
265
273
  - 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".
266
274
  - With a start screen, the copier uses three pages, not two.
267
- - The start screen is part of the clean build only. `loader.prg` always shows it. A release build has no start screen, and `LEFTOVERS = 1` also turns it off.
275
+ - 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.
268
276
  - 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.
269
- - A test that runs `loader.prg` stops at the start screen, because the emulator cannot press a key of the keyboard matrix. Run until `loader_start_screen_wait`. Then set the PC to `loader_start_screen_continue`.
270
- - `loader.json` is the symbol file of `loader.prg`. It holds the labels of `loader.asm`, `main.asm` and `start_screen_stage.asm`. Give it to a test of `loader.prg` as its symbols.
277
+ - A test that runs the loader program stops at the start screen, because the emulator cannot press a key of the keyboard matrix. Run until `loader_start_screen_wait`. Then set the PC to `loader_start_screen_continue`.
271
278
 
272
279
  `loader` holds these fields:
273
280
 
274
281
  - `program`, the `copies` in their order, `copier` and `stackByte`.
275
- - `verified: true`: the check ran `loader.prg` 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 original program.
282
+ - `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 original program.
276
283
  - `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.
277
284
  - `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.
278
- - `packed`: `packedBytes` and `unpackedBytes` of the packed form. With a start screen of a captured stage, this is the packed program in `loader.prg`.
279
- - `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 `loader.prg`, the `stash` copies, `packedBytes` and `unpackedBytes`. `startScreen.stage` names the space.
280
- - When the check of `loader.prg` cannot run, the script does not write `loader.prg`. The `loader.prg` of an earlier run stays as it was. `loader.asm` is new. `reason` tells why the check did not run.
281
- - `kept`: when the result has no new `loader.prg`, the path of the `loader.prg` of an earlier run. That file is not of this source.
285
+ - `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.
286
+ - `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.
287
+ - 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.
288
+ - `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.
282
289
 
283
290
  Do these actions when `verified` is `false`:
284
291
 
@@ -289,7 +296,7 @@ Do these actions when `verified` is `false`:
289
296
  | `reason` that the source does not assemble | Correct the source first. The loader includes the source. |
290
297
  | `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. |
291
298
  | `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. |
292
- | `reason` that the check of `loader.prg` 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. |
299
+ | `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. |
293
300
  | `differences` | The loader ran. The list gives the bytes and the registers that are not equal. |
294
301
  | `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. |
295
302
 
@@ -300,8 +307,8 @@ Often the loading stage of a program shows a picture that is not in memory at th
300
307
  The loader then always has the packed form, and the start screen is a program of its own in front of it:
301
308
 
302
309
  1. Exomizer packs the program with the copier. This is the packed loader.
303
- 2. Exomizer packs the packed loader, the bytes of the stage and the show code into `loader.prg`.
304
- 3. When `loader.prg` 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.
310
+ 2. Exomizer packs the packed loader, the bytes of the stage and the show code into the loader program.
311
+ 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.
305
312
  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.
306
313
  5. It waits for a key or a fire button, as the start screen in the program does.
307
314
  6. It stops the interrupts and the sound, and it stops the screen. It sets the CIA timers as RUN leaves them.
@@ -310,26 +317,26 @@ The loader then always has the packed form, and the start screen is a program of
310
317
  The program is packed while the screen shows. Thus the picture and the tune have more free memory.
311
318
 
312
319
  - The script puts everything in memory. It does not matter where the stage keeps its bytes, if the memory has enough room.
313
- - `loader.prg` 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.
320
+ - 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.
314
321
  - With colours from the colour RAM of the capture, the show code holds the 1000 colours. It copies them to the colour RAM.
315
322
  - 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.
316
- - `start_screen_stage.asm` holds the show code and the bytes of the stage. Do not edit it. To make `loader.prg` again, run `generate --loader`.
323
+ - `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 --loader`.
317
324
  - 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.
318
- - The check runs `loader.prg` 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.
325
+ - 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.
319
326
 
320
327
  #### The packed loader
321
328
 
322
329
  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:
323
330
 
324
331
  - `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.
325
- - `loader.prg` is the build of `main.asm` from $0400 and the build of `loader.asm`, packed into one file. Where the two builds overlap, `loader.prg` has the bytes of `loader.asm`.
332
+ - 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`.
326
333
  - The jump to the entry uses the address of the entry, not its label.
327
334
 
328
335
  To make the packed loader for other switch values, do these steps:
329
336
 
330
- 1. Assemble `main.asm` to `build/main.prg`. The leftovers are $00 in this build.
331
- 2. Assemble `loader.asm` to `build/copier.prg`.
332
- 3. Pack the two files into `build/loader.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`.
337
+ 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.
338
+ 2. Assemble `loader.asm` without an output path, for example to `build/custom_trainer_loader.prg`. This is the copier.
339
+ 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`.
333
340
 
334
341
  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 --loader` for the base release.
335
342
 
@@ -415,7 +422,7 @@ The entry is the entry of the knowledge. Without it, the entry is the address of
415
422
 
416
423
  ```text
417
424
  README.md the steps to build and test, the free ranges and the origin
418
- src/ main.asm, constants.asm, macros.asm, the modules and loader.asm
425
+ src/ main.asm, constants.asm, macros.asm, the modules in their folders and loader.asm
419
426
  baseline/<name>.prg the exported program, and baseline/<name>.json with its symbols
420
427
  tests/ the tests of the project, changed for the new program
421
428
  .c64-re-tools/knowledge/ the knowledge of the new program
@@ -440,7 +447,7 @@ tests/ the tests of the project, changed for the new program
440
447
  5. Record names, comments, regions and modules in the project knowledge.
441
448
  6. Run `generate` again. Do steps 4 to 6 again until the source is clear.
442
449
  7. Assemble `main.asm` to a program. This is the default build. For a release, give the build option `--release <label>`.
443
- 8. For an unpacked program, run `generate` with `--loader` at the end. Compare `loader.prg` with the original program in a test.
450
+ 8. For an unpacked program, run `generate` with `--loader` at the end. Compare the loader program with the original program in a test.
444
451
  9. To start a new program from the rebuild, run `export`.
445
452
 
446
453
  ---
@@ -10,6 +10,7 @@
10
10
  // tells what stays. Without coverage nothing becomes free by itself.
11
11
 
12
12
  import { type AddressRange, COVERAGE, formatC64Address, pointerTableEntries, POINTER_TABLE_TYPES, type PointerTableType } from "#src/c64.ts";
13
+ import { symbolsPath } from "#src/build-name.ts";
13
14
  import { Refusal } from "#src/errors.ts";
14
15
  import { NO_FALL_THROUGH, type Root, separate } from "#src/knowledge/separate.ts";
15
16
  import type { RegionType } from "#src/knowledge/schema.ts";
@@ -420,7 +421,7 @@ export function rewriteTest(text: string, name: string, symbols: ReadonlyMap<str
420
421
  if (inside(address, free)) return { reason: `it names ${location}, which is in a free range` };
421
422
  } else if (!symbols.has(location)) return { reason: `it names ${location}, which the exported program does not have` };
422
423
  }
423
- const side = (program: string) => ({ program: `${program}.prg`, symbols: `${program}.json` });
424
+ const side = (program: string) => ({ program: `${program}.prg`, symbols: symbolsPath(`${program}.prg`) });
424
425
  if (scenario) {
425
426
  // Both sides are the exported program now: a step of the original alone (for example a key for its intro) goes, and a step of the rebuild alone runs on both sides.
426
427
  const { original: _original, rebuild: _rebuild, steps, ...rest } = test;
@@ -432,7 +433,7 @@ export function rewriteTest(text: string, name: string, symbols: ReadonlyMap<str
432
433
  return { kind: "scenario", text: `${JSON.stringify({ ...rest, original: side(`baseline/${name}`), rebuild: side(`build/${name}`), steps: both }, null, 2)}\n` };
433
434
  }
434
435
  const start = test.start as Record<string, unknown>;
435
- const symbolsFile = test.symbols === undefined || test.symbols === "none" ? {} : { symbols: `build/${name}.json` };
436
+ const symbolsFile = test.symbols === undefined || test.symbols === "none" ? {} : { symbols: symbolsPath(`build/${name}.prg`) };
436
437
  return { kind: "run", text: `${JSON.stringify({ ...test, start: { ...start, program: `build/${name}.prg` }, ...symbolsFile }, null, 2)}\n` };
437
438
  }
438
439
 
@@ -460,7 +461,7 @@ export function readmeText(input: ReadmeInput): string {
460
461
  "",
461
462
  "## Build",
462
463
  "",
463
- `Assemble \`src/${input.entryFile}\` to \`build/${name}.prg\`, with its symbols in \`build/${name}.json\`.`,
464
+ `Assemble \`src/${input.entryFile}\` to \`build/${name}.prg\`, with its symbols in \`${symbolsPath(`build/${name}.prg`)}\`.`,
464
465
  input.entryFile === "main.asm"
465
466
  ? "Compare the build with the program in the project knowledge: the source must give that program."
466
467
  : "Assemble `src/main.asm` to `.c64-re-tools/local/program.prg`, and compare it with the program in the project knowledge: the source must give that program.",
@@ -492,7 +493,7 @@ export function readmeText(input: ReadmeInput): string {
492
493
  "## Files",
493
494
  "",
494
495
  `- \`src/\`: the source. You own it now: change it as you like.`,
495
- `- \`baseline/${name}.prg\` and \`baseline/${name}.json\`: the exported program and its symbols, the reference of the scenarios.`,
496
+ `- \`baseline/${name}.prg\` and \`${symbolsPath(`baseline/${name}.prg`)}\`: the exported program and its symbols, the reference of the scenarios.`,
496
497
  "- `tests/`: the tests.",
497
498
  "- `.c64-re-tools/knowledge/`: the names, comments and memory map of the exported program. They do not follow your changes to the source.",
498
499
  "",
@@ -11,7 +11,7 @@
11
11
  // screen in the knowledge, the copier shows it after the copies and waits for
12
12
  // a key or a fire button: the code is start-screen.asm, the same for each program.
13
13
  // The loader loads the segments without the leftovers: the ranges of the
14
- // source that nothing uses are not in loader.prg.
14
+ // source that nothing uses are not in the loader program.
15
15
 
16
16
  import { readFileSync } from "node:fs";
17
17
  import { fileURLToPath } from "node:url";
@@ -651,7 +651,7 @@ const SHOWN_FREE = 8;
651
651
  /**
652
652
  * The packed form of the loader, for an image too large for one loader file:
653
653
  * Exomizer packs the build of main.asm (from $0400) and the build of
654
- * loader.asm into loader.prg, which starts at the copier with all RAM
654
+ * loader.asm into the loader program, which starts at the copier with all RAM
655
655
  * visible ($01 = $34). loader.asm holds only the copier, in one free range,
656
656
  * and the bytes of pages $0002-$03ff, in pieces in the free ranges: the
657
657
  * unpacker of Exomizer uses the zero page and $0334-$03ff, so the copier
@@ -689,7 +689,7 @@ function planPacked(input: LoaderInput, blocks: Block[], cia: ReturnType<typeof
689
689
  const lines: string[] = [
690
690
  ...input.header.map((line) => `; ${line}`),
691
691
  "; The image is too large for one loader file, so this is the packed form. Exomizer packs the",
692
- `; build of main.asm and the build of this file into loader.prg, with --entry '${formatC64Address(copier)}' and --exit-memory '$34'.`,
692
+ `; build of main.asm and the build of this file into the loader program, with --entry '${formatC64Address(copier)}' and --exit-memory '$34'.`,
693
693
  "; The unpacker of Exomizer uses the zero page and $0334-$03ff, so the copier writes pages $0002-$03ff after the unpack.",
694
694
  "",
695
695
  "!cpu 6510",
@@ -815,7 +815,7 @@ function placePacked(free: AddressRange[], low: Parameters<typeof placePieces>[1
815
815
 
816
816
  /** What Exomizer makes of a packed loader. */
817
817
  export interface PackedLoader {
818
- /** loader.prg: it loads at $0801 and starts with RUN. */
818
+ /** The loader program: it loads at $0801 and starts with RUN. */
819
819
  program: Buffer;
820
820
  packedBytes: number;
821
821
  unpackedBytes: number;
@@ -993,7 +993,7 @@ function vicLines(state: EntryState, earlier: number): string[] {
993
993
  }
994
994
 
995
995
  /**
996
- * The symbols of loader.prg: the labels of the build of loader.asm, which
996
+ * The symbols of the loader program: the labels of the build of loader.asm, which
997
997
  * includes main.asm, and of start_screen_stage.asm when the loader has a show
998
998
  * stage. A test takes one symbols file. Refuses a name with two values.
999
999
  */
@@ -1003,7 +1003,7 @@ export function loaderSymbols(...builds: ReadonlyArray<readonly AssembledSymbol[
1003
1003
  for (const symbol of builds.flat()) {
1004
1004
  const known = byName.get(symbol.name);
1005
1005
  if (known !== undefined && valueOf(known) !== valueOf(symbol)) {
1006
- throw new WireFailure("operation-failed", `The builds of loader.prg give ${symbol.name} two values, ${valueOf(known)} and ${valueOf(symbol)}. This is a defect of the script.`);
1006
+ throw new WireFailure("operation-failed", `The builds of the loader program give ${symbol.name} two values, ${valueOf(known)} and ${valueOf(symbol)}. This is a defect of the script.`);
1007
1007
  }
1008
1008
  // An address in one build can be outside the load range of the other build, where it is a constant.
1009
1009
  const kept = known === undefined || (known.kind === "constant" && symbol.kind === "address") ? symbol : known;
@@ -14,10 +14,11 @@
14
14
  // each release has it, the default build does not, and the loader never
15
15
  // loads it.
16
16
 
17
+ import { CONFIG_FILE, configValues } from "#src/build-name.ts";
17
18
  import { type AddressRange, COVERAGE, formatC64Address, formatC64Byte, POINTER_TABLE_TYPES, pointerTableEntries, type PointerTableType } from "#src/c64.ts";
18
19
  import { WireFailure } from "#src/host-client/tools.ts";
19
20
  import { identifiers, operandText, replaceIdentifiers, type OperandExpression } from "#src/knowledge/expression.ts";
20
- import { type CommentPlacement, isAnalyzer, isGeneratedFile, LEFTOVERS_SWITCH, RELEASE_DEFINE, START_SCREEN_SWITCH, type Origin, type RegionType, type SwitchKind } from "#src/knowledge/schema.ts";
21
+ import { type CommentPlacement, isAnalyzer, isGeneratedFile, LEFTOVER_FOLDER, LEFTOVERS_SWITCH, SEGMENT_FOLDER, RELEASE_DEFINE, START_SCREEN_SWITCH, type Origin, type RegionType, type SwitchKind } from "#src/knowledge/schema.ts";
21
22
  import type { Area } from "#src/platform.ts";
22
23
  import { hasZeroPageForm, instructionWith, labelProblem, MODE_LENGTH, OPCODES, takesAddress, USE_KINDS, useKind, type UseKind } from "#src/opcodes.ts";
23
24
 
@@ -95,7 +96,6 @@ export interface SourceSwitch {
95
96
  /** A release: the build with RELEASE_<label> gives each switch the value of this release. */
96
97
  export interface SourceRelease {
97
98
  label: string;
98
- file: string;
99
99
  base: boolean;
100
100
  comment?: string;
101
101
  }
@@ -330,23 +330,24 @@ export function layout(input: SourceInput): Layout {
330
330
  const end = bounds[index + 1]! - 1;
331
331
  const segmentTitle = `Segment ${formatC64Address(segment.start)}-${formatC64Address(segment.end)}`;
332
332
  if (leftovers.some((range) => range.start === start)) {
333
- pieces.push({ start, end, file: `leftover_${hex(start)}.asm`, title: `Leftovers ${formatC64Address(start)}-${formatC64Address(end)}: ${end - start + 1} bytes that nothing uses. Only LEFTOVERS = 1 builds them.`, segmentStart: index === 0, leftover: true, items: [] });
333
+ pieces.push({ start, end, file: `${LEFTOVER_FOLDER}/leftover_${hex(start)}.asm`, title: `Leftovers ${formatC64Address(start)}-${formatC64Address(end)}: ${end - start + 1} bytes that nothing uses. Only LEFTOVERS = 1 builds them.`, segmentStart: index === 0, leftover: true, items: [] });
334
334
  continue;
335
335
  }
336
- // A module that leftovers cut goes on in a file of its own after them: <module>_xxxx.asm.
336
+ // A module that leftovers cut goes on in a file of its own after them, in its folder: <module>_xxxx.asm.
337
337
  const module = modules.find((row) => row.start === start);
338
338
  const holder = module ?? modules.filter((row) => row.start >= segment.start && row.start < start).at(-1);
339
339
  const title = (text: string | undefined) => text?.replace(/\s*\r?\n\s*/g, " ");
340
- const file = module?.file ?? (holder === undefined ? `segment_${hex(start)}.asm` : `${holder.file.replace(/\.asm$/i, "")}_${hex(start)}.asm`);
340
+ const file = module?.file ?? (holder === undefined ? `${SEGMENT_FOLDER}/segment_${hex(start)}.asm` : `${holder.file.replace(/\.asm$/i, "")}_${hex(start)}.asm`);
341
341
  const named = module === undefined && holder !== undefined ? `${title(holder.title) ?? holder.file}, from ${formatC64Address(start)}` : title(module?.title);
342
342
  pieces.push({ start, end, file, title: named ?? segmentTitle, segmentStart: index === 0, leftover: false, items: [] });
343
343
  }
344
344
  }
345
+ // In any letter case: the file systems of macOS and Windows ignore it.
345
346
  const files = new Map<string, number>();
346
347
  for (const piece of pieces) {
347
- const other = files.get(piece.file);
348
+ const other = files.get(piece.file.toLowerCase());
348
349
  if (other !== undefined) throw new WireFailure("invalid-input", `The file ${piece.file} is used at ${formatC64Address(other)} and at ${formatC64Address(piece.start)}. Give the module another file.`);
349
- files.set(piece.file, piece.start);
350
+ files.set(piece.file.toLowerCase(), piece.start);
350
351
  }
351
352
 
352
353
  for (const piece of pieces) {
@@ -930,21 +931,7 @@ export const hasSwitchFile = (layout: Pick<Layout, "switches" | "releases" | "le
930
931
  /** True when the source has config.asm: the knowledge has switches or a start screen, or the source has leftovers. */
931
932
  export const hasConfigFile = (layout: Pick<Layout, "switches" | "startScreen" | "leftovers">) => layout.switches.length > 0 || layout.startScreen || layout.leftovers.length > 0;
932
933
 
933
- /** The file with the value of each switch. The user edits it, and generate keeps the values. */
934
- export const CONFIG_FILE = "config.asm";
935
-
936
- /** A value line of config.asm: NAME = 0 or NAME = 1. */
937
- const CONFIG_VALUE = /^\s*([A-Z][A-Z0-9_]*)\s*=\s*([01])\s*(?:;.*)?$/;
938
-
939
- /** The values of the switches in a config.asm text, by name. Lines that are not a value line are not read. */
940
- export function configValues(text: string): Map<string, 0 | 1> {
941
- const values = new Map<string, 0 | 1>();
942
- for (const line of text.split(/\r?\n/)) {
943
- const match = CONFIG_VALUE.exec(line);
944
- if (match !== null) values.set(match[1]!, match[2] === "1" ? 1 : 0);
945
- }
946
- return values;
947
- }
934
+ export { CONFIG_FILE, configValues };
948
935
 
949
936
  /**
950
937
  * config.asm: the value of each switch as a plain assignment, grouped by
@@ -984,7 +971,7 @@ export function configText(layout: Pick<Layout, "switches" | "patches" | "startS
984
971
  out.push(
985
972
  "",
986
973
  "; Leftovers: off by default",
987
- `${LEFTOVERS_SWITCH} = ${values.get(LEFTOVERS_SWITCH) ?? 0} ; ${bytes} bytes in ${layout.leftovers.length} leftover_xxxx.asm ${layout.leftovers.length === 1 ? "file" : "files"} that nothing uses. 1 builds them, so main.asm gives the bytes of the program. Each release has them. The loader never loads them`,
974
+ `${LEFTOVERS_SWITCH} = ${values.get(LEFTOVERS_SWITCH) ?? 0} ; ${bytes} bytes in ${layout.leftovers.length} ${layout.leftovers.length === 1 ? "file" : "files"} in ${LEFTOVER_FOLDER}/ that nothing uses. 1 builds them, so main.asm gives the bytes of the program. Each release has them. The loader never loads them`,
988
975
  );
989
976
  }
990
977
  return `${out.join("\n")}\n`;
@@ -1002,7 +989,7 @@ function switchesText(layout: Layout): string {
1002
989
  "; then each switch has the value of that release, and the build does not read config.asm.",
1003
990
  ];
1004
991
  for (const release of layout.releases) {
1005
- out.push("", `; ${release.label}${release.base ? " (the program of the knowledge)" : ""}: ${release.file}${release.comment === undefined ? "" : `. ${release.comment.replace(/\s*\r?\n\s*/g, " ")}`}`);
992
+ out.push("", `; ${release.label}${release.base ? " (the program of the knowledge)" : ""}${release.comment === undefined ? "" : `: ${release.comment.replace(/\s*\r?\n\s*/g, " ")}`}`);
1006
993
  out.push(`!ifdef ${RELEASE_DEFINE}${release.label} {`);
1007
994
  for (const row of layout.switches) out.push(`${INDENT}${row.name} = ${row.releases.includes(release.label) ? 1 : 0}`);
1008
995
  if (layout.leftovers.length > 0) out.push(`${INDENT}${LEFTOVERS_SWITCH} = 1`);
@@ -3,7 +3,7 @@
3
3
  // the loader as it is in memory before it starts (the plain loader file, or
4
4
  // the parts of the packed form), the bytes of the stage that the start screen
5
5
  // uses at their own addresses, the bytes of the loader that those cover in a
6
- // stash, and the show code into one loader.prg. The show code shows the
6
+ // stash, and the show code into one loader program. The show code shows the
7
7
  // screen with start-screen.asm, calls the routine of the stage, waits for a
8
8
  // key or a fire button, stops the interrupts of the stage, sets the CIAs as
9
9
  // RUN leaves them, copies the stash back and starts the loader.
@@ -143,7 +143,7 @@ export function stageText(input: StageInput, code: number, stash: StagePlan["sta
143
143
  const { row } = input;
144
144
  const lines = [
145
145
  ...input.header.map((line) => `; ${line}`),
146
- `; The show stage of the start screen from ${row.stage}: Exomizer packs it with the loader into loader.prg, with --entry '${formatC64Address(code)}'.`,
146
+ `; The show stage of the start screen from ${row.stage}: Exomizer packs it with the loader into the loader program, with --entry '${formatC64Address(code)}'.`,
147
147
  "; It shows the start screen, waits for a key or a fire button, copies back the bytes of the loader that the stage covers, and starts the loader.",
148
148
  "",
149
149
  "!cpu 6510",