@henols/c64-re-tools 2.6.0-rc.1 → 2.6.0-rc.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/skills/c64-assembler/SKILL.md +27 -13
- package/skills/c64-assembler/scripts/assembler.ts +26 -14
- package/skills/c64-development/SKILL.md +2 -2
- package/skills/c64-docs/SKILL.md +4 -4
- package/skills/c64-docs/scripts/docs.ts +7 -7
- package/skills/c64-docs/scripts/lib/reference.ts +13 -5
- package/skills/c64-docs/scripts/lib/source-map.ts +9 -4
- package/skills/c64-knowledge/SKILL.md +60 -36
- package/skills/c64-knowledge/scripts/knowledge.ts +75 -59
- package/skills/c64-knowledge/scripts/lib/listing.ts +18 -3
- package/skills/c64-packer/SKILL.md +1 -1
- package/skills/c64-provenance/SKILL.md +11 -10
- package/skills/c64-provenance/scripts/lib/library.ts +16 -16
- package/skills/c64-provenance/scripts/provenance.ts +33 -23
- package/skills/c64-reverse-engineering/SKILL.md +17 -11
- package/skills/c64-source/SKILL.md +74 -49
- package/skills/c64-source/scripts/lib/export.ts +76 -32
- package/skills/c64-source/scripts/lib/loader.ts +33 -10
- package/skills/c64-source/scripts/lib/source.ts +14 -25
- package/skills/c64-source/scripts/lib/stage.ts +11 -5
- package/skills/c64-source/scripts/lib/start-screen.asm +4 -2
- package/skills/c64-source/scripts/source.ts +257 -134
- package/skills/c64-static-analysis/SKILL.md +8 -6
- package/skills/c64-static-analysis/scripts/lib/coverage.ts +2 -25
- package/skills/c64-static-analysis/scripts/lib/instructions.ts +22 -20
- package/skills/c64-static-analysis/scripts/lib/macros.ts +3 -1
- package/skills/c64-static-analysis/scripts/static-analysis.ts +36 -43
- package/skills/c64-testing/SKILL.md +5 -2
- package/skills/c64-testing/references/recording-format.md +18 -3
- package/skills/c64-testing/references/scenario-format.md +7 -6
- package/skills/c64-testing/scripts/lib/diff-files.ts +4 -18
- package/skills/c64-testing/scripts/lib/play.ts +39 -41
- package/skills/c64-testing/scripts/lib/recording.ts +46 -37
- package/skills/c64-testing/scripts/lib/replay.ts +1 -1
- package/skills/c64-testing/scripts/lib/runs.ts +2 -2
- package/skills/c64-testing/scripts/lib/scenario.ts +17 -10
- package/skills/c64-testing/scripts/testing.ts +6 -1
- package/skills/c64-unpacker/SKILL.md +6 -3
- package/skills/c64-unpacker/scripts/lib/loads.ts +34 -13
- package/skills/c64-unpacker/scripts/lib/machine.ts +7 -3
- package/skills/c64-unpacker/scripts/unpacker.ts +5 -3
- package/skills/emulator/SKILL.md +7 -12
- package/src/build-name.ts +50 -0
- package/src/c64-keys.ts +98 -0
- package/src/c64.ts +21 -1
- package/src/cli/main.ts +3 -29
- package/src/host/main.ts +1 -1
- package/src/host/tools/index.ts +1 -6
- package/src/host/vice/session.ts +88 -9
- package/src/host-client/steps.ts +17 -17
- package/src/host-client/tools.ts +2 -7
- package/src/host-client/vice-session.ts +7 -1
- package/src/knowledge/program.ts +44 -1
- package/src/knowledge/read.ts +33 -10
- package/src/knowledge/schema.ts +37 -11
- package/src/knowledge/start-screen.ts +68 -0
- package/src/knowledge/text.ts +5 -2
- package/src/knowledge/write.ts +69 -30
- package/src/mcp/inputs.ts +12 -0
- package/src/mcp/server.ts +1 -1
- package/src/mcp/tools/input.ts +38 -5
- package/src/mcp/tools/machine.ts +3 -42
- package/src/mcp/tools/media.ts +1 -1
- package/src/native/acme.ts +1 -1
- package/src/native/c64run.ts +1 -1
- package/src/native/discover.ts +3 -3
- package/src/native/dxa.ts +12 -1
- package/src/native/ghidra/analyze.ts +74 -63
- package/src/native/ghidra/c64rt-wasm.ts +4 -0
- package/src/native/ghidra/language/c64rt_6510.sla +0 -0
- package/src/native/ghidra/pcode.ts +222 -0
- package/src/native/ghidra/walk.ts +205 -0
- package/src/native/ghidra/wasm.ts +98 -0
- package/src/native/processes.ts +4 -4
- package/src/native/types.ts +2 -2
- package/src/platform.ts +30 -1
- package/src/project.ts +17 -4
- package/src/protocol/tools.ts +1 -45
- package/src/protocol/vice.ts +47 -0
- package/src/script.ts +3 -3
- package/src/vsf.ts +98 -0
- package/tools/c64run.c +9 -12
- package/tools/install-container.sh +1 -2
- package/src/cli/status.ts +0 -127
- package/src/host/tools/status.ts +0 -47
- package/src/native/ghidra/index.ts +0 -170
- package/src/native/ghidra/scripts/C64Export.java +0 -274
- package/src/native/ghidra/scripts/C64Prepare.java +0 -66
- package/src/native/status.ts +0 -135
- package/tools/install-ghidra.sh +0 -40
|
@@ -46,19 +46,20 @@ The knowledge is text in `.c64-re-tools/knowledge/` of the project. Commit that
|
|
|
46
46
|
| Write a comment | `comment '$2100' line Reads joystick 2.` |
|
|
47
47
|
| Add a reference | `reference '$2000' '$2100' call` |
|
|
48
48
|
| Find the places that a removal blocks | `suppressions --range '$2000-$2fff'` |
|
|
49
|
-
| Start a file of the generated source | `module '$2000' player.asm --title 'Player movement'` |
|
|
49
|
+
| Start a file of the generated source | `module '$2000' game/player.asm --title 'Player movement'` |
|
|
50
50
|
| Write the operand of an instruction as an expression | `operand '$8079' --lo irq_handler` |
|
|
51
51
|
| Record a release of the program | `release ORIGINAL --file original/game.prg --base` |
|
|
52
52
|
| Write a switch | `switch PROTECTION --kind protection --releases ORIGINAL` |
|
|
53
53
|
| Write the code of a switch for a range | `patch '$100e-$1010' PROTECTION --code-file no-check.asm` |
|
|
54
54
|
| List the releases, switches and patches | `switches` |
|
|
55
55
|
| Record the start screen of the program | `start-screen --mode multicolour --screen '$5c00' --bitmap '$6000' --colours '$8328' --border 0 --background 0` |
|
|
56
|
-
| Record the start screen of a captured stage, and its tune | `start-screen --
|
|
56
|
+
| Record the start screen of a captured stage, and its tune | `start-screen --stage loading --call '$9000'` |
|
|
57
57
|
| Remove the start screen | `unstart-screen` |
|
|
58
58
|
| Write a macro | `macro inc16 --params dst --body-file inc16.asm` |
|
|
59
59
|
| Write instructions as one use of a macro | `use '$1005-$100a' inc16 --args ptr` |
|
|
60
60
|
| Do many writes as one revision | `apply .c64-re-tools/local/batch.json` |
|
|
61
|
-
|
|
|
61
|
+
| Show the batches of parallel agents as one list of writes | `join a.json b.json` |
|
|
62
|
+
| Write the batches of parallel agents as one revision | `join a.json b.json --apply` |
|
|
62
63
|
| Read the history of an address or a name | `history '$2100'` |
|
|
63
64
|
| Read the last revisions | `revisions` |
|
|
64
65
|
| Go back to an earlier state | `revert 20261015T2145` |
|
|
@@ -72,9 +73,9 @@ The knowledge is text in `.c64-re-tools/knowledge/` of the project. Commit that
|
|
|
72
73
|
- An analyzer name is a second name from DXA, Ghidra or an idiom search, for example `FUN_17e2`. Each analyzer keeps its own name at an address. Get them from `at`, `search` or `symbols --analyzer`.
|
|
73
74
|
- The generated source uses only the symbols. To use an analyzer name in the source, give the address that name with `rename`.
|
|
74
75
|
- A symbol name is a label for ACME: a letter or an underscore, then letters, digits or underscores. The knowledge refuses the name of a 6502 instruction, for example `lda`, in upper or lower case.
|
|
75
|
-
- A space is `c64` (the default), `drive8` for code in the 1541 drive, or `bank0` to `bank255`
|
|
76
|
+
- A space is `c64` (the default), `drive8` for code in the 1541 drive, `loading` or `bank0` to `bank255`. `loading` is the captured stage of the loading that shows the start screen. `bank0` to `bank255` are cartridge banks, or other memory images of the program, for example a file that the program loads later. Drive code, the stage and banks use the same addresses as the C64. Thus each space has its own knowledge. A name is unique in one space.
|
|
76
77
|
- A revision id has the form `20261015T214501.123-k3f9qz`. It starts with the date and the time. Give the full id, or a start of the id that only one revision has. Get the ids from `revisions`, or from the `revision` field of a result. The revision `0` is the knowledge before the first revision.
|
|
77
|
-
- A file of a capture is the `image.json` that the capture of a packed program wrote.
|
|
78
|
+
- A file of a capture is the `image.json` that the capture of a packed program wrote. The other files of the capture must be next to it.
|
|
78
79
|
|
|
79
80
|
### Paths and the project folder
|
|
80
81
|
|
|
@@ -102,14 +103,18 @@ Each flag applies only to the commands in the table. On another command, the scr
|
|
|
102
103
|
|
|
103
104
|
| Flag | Command | Effect |
|
|
104
105
|
|---|---|---|
|
|
105
|
-
| `--space <space>` | All commands | The space of the command: `c64`, `drive8`, or `bank0` to `bank255`. The default is `c64`. Without `--space`, `revert` reverts all spaces. |
|
|
106
|
+
| `--space <space>` | All commands | The space of the command: `c64`, `drive8`, `loading`, or `bank0` to `bank255`. The default is `c64`. Without `--space`, `revert` reverts all spaces. |
|
|
106
107
|
| `--by <user\|llm>` | All commands in "Change the knowledge" | Who decided the change. The default is `llm`. Give `user` only when the user decided the change. |
|
|
107
108
|
| `--reason <text>` | All commands in "Change the knowledge" | Why you make the change. The revision keeps it, and `history` shows it. |
|
|
108
109
|
| `--evidence <kind:ref>` | All commands in "Change the knowledge" | One thing that the change rests on: `coverage:<map>`, `test:<file>`, `file:<file>` or `note:<text>`. You can give it more than one time. |
|
|
109
110
|
| `--expect-revision <revision>` | All commands in "Change the knowledge" | Refuse the change when the knowledge changed after this revision. Give the `revision` of your last read. |
|
|
111
|
+
| `--by <user\|llm>` | `join` | With `--apply`: the same as for the commands in "Change the knowledge". |
|
|
112
|
+
| `--reason <text>` | `join` | With `--apply`: the same as for the commands in "Change the knowledge". |
|
|
113
|
+
| `--evidence <kind:ref>` | `join` | With `--apply`: the same as for the commands in "Change the knowledge". |
|
|
114
|
+
| `--expect-revision <revision>` | `join` | With `--apply`: the same as for the commands in "Change the knowledge". |
|
|
110
115
|
| `--range <start>-<end>` | `symbols`, `regions`, `comments`, `references`, `suppressions`, `modules`, `operands`, `patches`, `uses`, `export` | Only the rows in this range. The default is all addresses. |
|
|
111
116
|
| `--origin <origin>` | `search`, `symbols`, `regions`, `comments`, `references`, `modules`, `operands`, `patches`, `macros`, `uses`, `export` | Only the rows of these origins: `user`, `llm`, `dxa`, `ghidra`, `heuristic`, `semantic` (user and llm), `analyzer` (dxa, ghidra and heuristic), or a comma list. The default is all origins. |
|
|
112
|
-
| `--max-listed <n>` | `search`, `symbols`, `regions`, `comments`, `references`, `suppressions`, `modules`, `operands`, `patches`, `switches`, `releases`, `macros`, `uses`, `spaces`, `history`, `revisions`, `revision`, `listing` | The most items in each list of the body. The default is 50. The counts are always complete. |
|
|
117
|
+
| `--max-listed <n>` | `search`, `symbols`, `regions`, `comments`, `references`, `suppressions`, `modules`, `operands`, `patches`, `switches`, `releases`, `macros`, `uses`, `spaces`, `history`, `revisions`, `revision`, `listing`, `join` | The most items in each list of the body. The default is 50. The counts are always complete. |
|
|
113
118
|
| `--kind <kind>` | `symbols`, `rename` | The symbol kind: `label`, `routine`, `variable`, `data` or `vector`. A read gives all kinds by default. A new symbol without `--kind` is a `label`. A `rename` without `--kind` keeps the kind of the symbol. |
|
|
114
119
|
| `--kind <kind>` | `references` | Only references of this kind: `call`, `jump`, `read`, `write`, `reference` or `pointer`. |
|
|
115
120
|
| `--kind <kind>` | `switch` | Necessary. The switch kind: `protection`, `trainer`, `cheat`, `crack`, `fix` or `change`. |
|
|
@@ -121,7 +126,8 @@ Each flag applies only to the commands in the table. On another command, the scr
|
|
|
121
126
|
| `--macro <name>` | `history` | The history of a macro in place of an address. |
|
|
122
127
|
| `--name <name>` | `history` | The history of a name in place of an address. |
|
|
123
128
|
| `--before <revision>` | `revisions` | Only the revisions before this one. |
|
|
124
|
-
| `--out <file>` | `export
|
|
129
|
+
| `--out <file>` | `export` | Necessary. The JSON file to write. |
|
|
130
|
+
| `--apply` | `join` | Write the joined writes to the project knowledge as one revision. Without it, `join` writes nothing. |
|
|
125
131
|
| `--out <file>` | `listing` | Write the listing as text to this file in place of the lines in the body. |
|
|
126
132
|
| `--element <n>` | `classify` | The bytes of one element of a table. The length of the range must be a multiple of it. |
|
|
127
133
|
| `--title <text>` | `module` | The title of the file. A `module` write without a title keeps the title that the module has. |
|
|
@@ -142,15 +148,15 @@ Each flag applies only to the commands in the table. On another command, the scr
|
|
|
142
148
|
| `--body <text>` | `macro` | The body of the macro. |
|
|
143
149
|
| `--body-file <file>` | `macro` | A project file with the body of the macro. |
|
|
144
150
|
| `--args <x, y>` | `use` | One expression for each param of the macro, as a comma list. |
|
|
145
|
-
| `--mode <mode>` | `start-screen` |
|
|
146
|
-
| `--screen <address>` | `start-screen` |
|
|
151
|
+
| `--mode <mode>` | `start-screen` | The mode of the VIC-II: `text`, `hires` or `multicolour`. Necessary without `--stage`. |
|
|
152
|
+
| `--screen <address>` | `start-screen` | The address of the screen memory: 1000 bytes. Necessary without `--stage`. |
|
|
147
153
|
| `--bitmap <address>` | `start-screen` | The address of the bitmap: 8000 bytes. `hires` and `multicolour` need it. |
|
|
148
154
|
| `--charset <address>` | `start-screen` | The address of the charset: 2048 bytes. `text` needs it. |
|
|
149
155
|
| `--colours <address>` | `start-screen` | The address of the 1000 bytes that the loader copies to the colour RAM. |
|
|
150
156
|
| `--colour <0-15>` | `start-screen` | One colour for all of the colour RAM, in place of `--colours`. |
|
|
151
|
-
| `--border <0-15>` | `start-screen` |
|
|
152
|
-
| `--background <0-15>` | `start-screen` |
|
|
153
|
-
| `--stage <space>` | `start-screen` | The space of
|
|
157
|
+
| `--border <0-15>` | `start-screen` | The border colour. Necessary without `--stage`. |
|
|
158
|
+
| `--background <0-15>` | `start-screen` | The background colour. Necessary without `--stage`. |
|
|
159
|
+
| `--stage <space>` | `start-screen` | The space of the captured stage that shows the screen: `loading`. The script takes the mode, the addresses and the colours from the capture. Without it, the bytes are in the program at the entry. |
|
|
154
160
|
| `--call <address>` | `start-screen` | A routine of the stage that the start screen calls before it waits, for example the start of the loading tune. It must return with RTS. It needs `--stage`. |
|
|
155
161
|
|
|
156
162
|
---
|
|
@@ -218,7 +224,7 @@ When a git merge left conflicts in the knowledge, each read body also has `confl
|
|
|
218
224
|
|
|
219
225
|
### `releases`
|
|
220
226
|
|
|
221
|
-
- `body.releases` lists the releases, the base release first. Each item has `label`, `
|
|
227
|
+
- `body.releases` lists the releases, the base release first. Each item has `label`, `base` and `define`.
|
|
222
228
|
- `define` is the assembler define that builds the release.
|
|
223
229
|
|
|
224
230
|
### `macros`
|
|
@@ -242,10 +248,10 @@ When a git merge left conflicts in the knowledge, each read body also has `confl
|
|
|
242
248
|
|
|
243
249
|
### `listing <range>`
|
|
244
250
|
|
|
245
|
-
- `body.lines`
|
|
246
|
-
- Each line has `address`, `bytes`, `text`, `referencesIn` and `referencesOut`. It can also have `label`, `analyzerNames` and `comment`.
|
|
251
|
+
- `body.lines` has `count` and `listed`. `listed` holds one line for each instruction of a code region, and one `!byte` line for other bytes.
|
|
252
|
+
- Each line has `address`, `bytes`, `text`, `referencesIn` and `referencesOut`. It can also have `label`, `analyzerNames`, `lineComments` and `comment`. `lineComments` are the line comments before the line. `comment` is the side comment.
|
|
247
253
|
- `text` is the instruction with the names of its target. An operand expression of the knowledge replaces the operand.
|
|
248
|
-
- When the knowledge has coverage, `access` tells if a run executed (`x`), read (`r`) or wrote (`w`) the bytes of the line, or `-` for none.
|
|
254
|
+
- When the knowledge has coverage, `access` tells if a run executed (`x`), read (`r`) or wrote (`w`) the bytes of the line, or `-` for none. An `r` on code can come from a read of the 6502 that the program does not do, for example the byte after an RTS or the opcode at the PC when an interrupt starts.
|
|
249
255
|
- With `--out`, the body has `lines` as a number, and `out`, `bytes` and `sha256` of the text file.
|
|
250
256
|
- If the knowledge has no program in the space, the script refuses. Put the program in with `image` first.
|
|
251
257
|
- Use `listing` in place of your own disassembler.
|
|
@@ -347,8 +353,10 @@ Errors of this group:
|
|
|
347
353
|
|
|
348
354
|
- A module tells where a file of the generated source starts. The file runs to the next module or to the end of its segment.
|
|
349
355
|
- Each address has one module, and each file name has one module.
|
|
350
|
-
- A file name has letters, digits, underscores or hyphens, and ends in `.asm`. It
|
|
351
|
-
-
|
|
356
|
+
- A file name has letters, digits, underscores or hyphens, and ends in `.asm`. It can have one folder, for example `music/driver.asm`. A folder name has lower-case letters, digits, underscores or hyphens.
|
|
357
|
+
- Put the modules of one part of the program in one folder, for example `music/`, `irq/` or `graphics/`.
|
|
358
|
+
- The generated source has the files `main.asm`, `loader.asm`, `switches.asm`, `config.asm`, `constants.asm`, `macros.asm` and `start_screen.asm` already. It also has the folders `leftovers/` and `segments/`. Thus a module cannot have one of these files, also in a folder, or one of these folders, in upper or lower case.
|
|
359
|
+
- Two modules cannot have file names that are different only in upper or lower case.
|
|
352
360
|
- The title becomes the first line of the file.
|
|
353
361
|
- `body.module` gives the module after the write.
|
|
354
362
|
|
|
@@ -387,12 +395,13 @@ A rebuild keeps all of the program in the source: unused bytes, dead code, old c
|
|
|
387
395
|
|
|
388
396
|
Do not write a file of the rebuild by hand, for example a boot file, a packed picture or a script that changes bytes. Record each change in the knowledge, and generate the source.
|
|
389
397
|
|
|
390
|
-
-
|
|
398
|
+
- `--file` is a PRG or the `image.json` of a capture. The project knowledge keeps the bytes of the release. After the write, the project does not need the file. A capture can stay in `.c64-re-tools/local/`.
|
|
391
399
|
- A label is upper case, for example `ORIGINAL`, `FIRESTAR` or `V2`.
|
|
392
400
|
- The base release is the release whose bytes are the program of the knowledge. Record it with `--base`. The script refuses `--base` when the segments or the bytes of the file are not the program.
|
|
393
401
|
- A space has one base release. Record the base release before the first switch.
|
|
394
|
-
- The build of a release gives each switch the value of that release. The check of the generated source compares that build with the bytes of the
|
|
395
|
-
-
|
|
402
|
+
- The build of a release gives each switch the value of that release. The check of the generated source compares that build with the bytes of the release in the project knowledge.
|
|
403
|
+
- To change the bytes of a release, record the release again with its new file.
|
|
404
|
+
- `body.release` gives the release, with its `define`. `body.bytes` gives the number of bytes of the file.
|
|
396
405
|
|
|
397
406
|
### `unrelease <label>`
|
|
398
407
|
|
|
@@ -407,15 +416,30 @@ A start screen is a loading screen, a title screen or a presentation screen of t
|
|
|
407
416
|
1. Record patches under a switch that take out the change.
|
|
408
417
|
2. Use the screen as it is.
|
|
409
418
|
3. Do not record a start screen.
|
|
410
|
-
- The bytes of the screen must be in the program of the knowledge at the entry, or in a captured stage.
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
419
|
+
- The bytes of the screen must be in the program of the knowledge at the entry, or in a captured stage.
|
|
420
|
+
|
|
421
|
+
#### A start screen of a captured stage
|
|
422
|
+
|
|
423
|
+
Use this when a stage of the loading shows the screen, and the program at the entry does not have it. Do these steps:
|
|
424
|
+
|
|
425
|
+
1. Capture the stage while it shows the screen. Do not exclude the memory of the screen.
|
|
426
|
+
2. Put the capture into the knowledge in the space `loading`: `image stage/image.json --space loading`. Do not use another space for it.
|
|
427
|
+
3. If the stage plays a tune or does other work during the screen, find the routine that starts it. Run the stage with coverage while that routine runs. Put the map into the knowledge with `coverage <map> --space loading`.
|
|
428
|
+
4. Record the start screen with `start-screen --stage loading`, and with `--call` for the routine.
|
|
429
|
+
|
|
430
|
+
- The script takes the mode, the screen, the bitmap or the charset, the colours and the colour RAM from the capture. Do not find the addresses or the colours yourself.
|
|
431
|
+
- The generated source puts the screen in memory. It does not matter where the stage keeps its bytes, if the memory has enough room.
|
|
432
|
+
- A flag that you give replaces the value of the capture. Give a flag only to correct a value.
|
|
433
|
+
- A capture of an older version has no colour RAM. Then capture the stage again.
|
|
434
|
+
|
|
435
|
+
#### A start screen in the program
|
|
436
|
+
|
|
437
|
+
- Capture the program while the bytes of the screen are in memory.
|
|
417
438
|
- Get the mode, the addresses and the colours from the VIC-II while the original program shows the screen.
|
|
418
|
-
-
|
|
439
|
+
- Find the 1000 colour bytes in the program: compare them with the colour RAM at $d800 while the original shows the screen. Give their address with `--colours`. If the program does not have them, give one colour with `--colour`.
|
|
440
|
+
|
|
441
|
+
#### The rules of the VIC-II
|
|
442
|
+
|
|
419
443
|
- `text` needs `--charset`. `hires` and `multicolour` need `--bitmap`. `text` and `multicolour` need `--colours` or `--colour`. `hires` uses neither.
|
|
420
444
|
- The screen is at a step of $0400, the bitmap at a step of $2000 and the charset at a step of $0800. They must be in one VIC bank of 16 KB.
|
|
421
445
|
- In VIC bank 0 and 2, the VIC-II reads the character ROM at $1000-$1fff of the bank. A screen or a bitmap cannot be there. A charset at $1000 or $1800 of the bank is the character ROM.
|
|
@@ -524,7 +548,7 @@ A macro writes a run of instructions as one line of the source, for example `+in
|
|
|
524
548
|
### `apply <file>`
|
|
525
549
|
|
|
526
550
|
- `<file>` is a JSON list of writes. Give `-` to read the list from standard input.
|
|
527
|
-
- `body` holds `revision`, `writes` and `replaced`.
|
|
551
|
+
- `body` holds `revision`, `writes` and `replaced`. `replaced` lists each write that replaced a row of a different origin, for example an `llm` write over a `user` row. Each item has the number of the `write`, its `op` and its `previous`. A write over a row of the same origin is not in `replaced`.
|
|
528
552
|
- All writes become one revision. If the knowledge refuses one write, the script writes nothing, and the `error` names the write.
|
|
529
553
|
- Each write has `op` and the fields of the command with the same name. Each write can also have `space`. For example:
|
|
530
554
|
|
|
@@ -557,7 +581,6 @@ A macro writes a run of instructions as one line of the source, for example `+in
|
|
|
557
581
|
| `unuse` | `start` |
|
|
558
582
|
|
|
559
583
|
- The script checks an `operand`, `patch` or `use` write against the program of its space.
|
|
560
|
-
- Apply a batch from a library match or an idiom search in the same way. Read the notes of the result that wrote the batch first.
|
|
561
584
|
|
|
562
585
|
### `revert <revision>`
|
|
563
586
|
|
|
@@ -575,19 +598,20 @@ A macro writes a run of instructions as one line of the source, for example `+in
|
|
|
575
598
|
|
|
576
599
|
## Batches of parallel agents
|
|
577
600
|
|
|
578
|
-
When more agents name the program at the same time, give each agent one range of addresses. Each agent writes one batch file and does not apply it. A batch has the form `{"owner": {"start": "$1000", "end": "$1fff"}, "ops": [...]}`. `ops` holds the writes, as for `apply`. The owner ranges must not overlap.
|
|
601
|
+
When more agents name the program at the same time, give each agent one range of addresses. Each agent writes one batch file in `.c64-re-tools/local/` and does not apply it. A batch has the form `{"owner": {"start": "$1000", "end": "$1fff"}, "ops": [...]}`. `ops` holds the writes, as for `apply`. The owner ranges must not overlap.
|
|
579
602
|
|
|
580
603
|
### `join <batch>...`
|
|
581
604
|
|
|
582
|
-
- `join` makes one
|
|
583
|
-
- `body` holds `writes`, `repeated
|
|
605
|
+
- `join` makes one list of writes from two or more batch files. Without `--apply`, it writes no knowledge.
|
|
606
|
+
- Without `--apply`, `body` holds `writes`, `repeated` and `choices`. `writes` lists the joined writes.
|
|
607
|
+
- With `--apply`, `join` writes the joined writes as one revision, or nothing when the knowledge refuses one write. Then `body` holds `revision`, `writes`, `replaced`, `repeated` and `choices`, as for `apply`.
|
|
584
608
|
- `choices` lists each place where the batches gave different values, with the value that stays.
|
|
585
609
|
- At an address in the owner range of a batch, the name, the comment, the operand and the module of that batch stay. At an address that no batch owns, the first batch in the command stays.
|
|
586
610
|
- A batch can give an address a name that `join` replaces. Then `join` also replaces that name in the operand expressions and macro arguments of that batch.
|
|
587
611
|
- The regions of the owner come after the regions of the other batches. Thus the regions of the owner stay where they overlap.
|
|
588
612
|
- A name from a batch stays when another batch removes the symbol at that address.
|
|
589
613
|
- When one name or one module file is at two addresses, `join` writes nothing and gives the error `conflict`. The `error` names the addresses and the batches. Correct the batches. Then do `join` again.
|
|
590
|
-
-
|
|
614
|
+
- Without `--apply`, the `hint` tells you to examine `choices` and `writes`. `nextAction` is the same `join` with `--apply`. Run it when the choices agree with your task.
|
|
591
615
|
|
|
592
616
|
---
|
|
593
617
|
|
|
@@ -17,7 +17,8 @@ import { operandText } from "#src/knowledge/expression.ts";
|
|
|
17
17
|
import { historyAt, historyNamed, historyOfMacro, historyOfSwitch, revision, revisionNote, revisions, type HistoryEntry } from "#src/knowledge/history.ts";
|
|
18
18
|
import { joinBatches, type Batch, type JoinChoice, type JoinClash } from "#src/knowledge/join.ts";
|
|
19
19
|
import { knowledgeNames } from "#src/knowledge/names.ts";
|
|
20
|
-
import { addCoverage, programCoverage, programImage, requireProgram, setImage, type ImageRequest } from "#src/knowledge/program.ts";
|
|
20
|
+
import { addCoverage, memoryRows, operandImages as programImages, programCoverage, programImage, requireProgram, setImage, type ImageRequest } from "#src/knowledge/program.ts";
|
|
21
|
+
import { startScreenOfStage } from "#src/knowledge/start-screen.ts";
|
|
21
22
|
import {
|
|
22
23
|
analyzerNamesAt,
|
|
23
24
|
at,
|
|
@@ -158,8 +159,6 @@ const switchRow = (row: SwitchRow, base?: string, patches?: readonly PatchRow[])
|
|
|
158
159
|
const release = (row: ReleaseRow) => ({
|
|
159
160
|
...spaceOf(row),
|
|
160
161
|
label: row.label,
|
|
161
|
-
file: row.file,
|
|
162
|
-
sha256: row.sha256,
|
|
163
162
|
base: row.base,
|
|
164
163
|
define: `--define ${RELEASE_DEFINE}${row.label}=1`,
|
|
165
164
|
...(row.comment === undefined ? {} : { comment: row.comment }),
|
|
@@ -177,6 +176,7 @@ const startScreen = (row: StartScreenRow) => ({
|
|
|
177
176
|
background: row.background,
|
|
178
177
|
...(row.stage === undefined ? {} : { stage: row.stage }),
|
|
179
178
|
...(row.call === undefined ? {} : { call: formatC64Address(row.call) }),
|
|
179
|
+
...(row.colourRam === true ? { colourRam: true } : {}),
|
|
180
180
|
...(row.comment === undefined ? {} : { comment: row.comment }),
|
|
181
181
|
origin: row.origin,
|
|
182
182
|
revision: row.revision,
|
|
@@ -271,8 +271,10 @@ function listingSource(db: DatabaseSync | undefined, space: string): ListingSour
|
|
|
271
271
|
const coverage = programCoverage(db, space)?.map;
|
|
272
272
|
const inside = (at: number) => image.segments.some((segment) => at >= segment.start && at <= segment.end);
|
|
273
273
|
const platform = new Map(space === DEFAULT_SPACE ? platformNames().map((entry) => [entry.address, entry.name]) : []);
|
|
274
|
+
const entries = space === DEFAULT_SPACE ? platformNames().filter((entry) => entry.end > entry.address) : [];
|
|
274
275
|
return {
|
|
275
276
|
byteAt: (at) => (inside(at) ? image.byteAt(at) : undefined),
|
|
277
|
+
entryStart: (at) => (inside(at) ? undefined : entries.find((entry) => at > entry.address && at <= entry.end)?.address),
|
|
276
278
|
// A user or LLM name, else the platform name; an analyzer name in symbols (knowledge from an older version) gives way to it.
|
|
277
279
|
nameOf: (at) => {
|
|
278
280
|
const own = symbolAt(db, at, space);
|
|
@@ -359,15 +361,9 @@ function imageRequest(path: string, space: string): ImageRequest {
|
|
|
359
361
|
return request;
|
|
360
362
|
}
|
|
361
363
|
|
|
362
|
-
/**
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
* the segments of the program is not in it.
|
|
366
|
-
*/
|
|
367
|
-
function operandImage(db: DatabaseSync, space: string): OperandImage {
|
|
368
|
-
const image = requireProgram(db, space);
|
|
369
|
-
const inside = (at: number) => image.segments.some((segment) => at >= segment.start && at <= segment.end);
|
|
370
|
-
return { byteAt: (at) => (inside(at) ? image.byteAt(at) : undefined), platform: new Map(platformNames().map((entry) => [entry.name, entry.address])) };
|
|
364
|
+
/** The programs that operand, patch and macro use writes are checked against, with the platform names. */
|
|
365
|
+
function operandImages(db: DatabaseSync): (space: string) => OperandImage {
|
|
366
|
+
return programImages(db, new Map(platformNames().map((entry) => [entry.name, entry.address])));
|
|
371
367
|
}
|
|
372
368
|
|
|
373
369
|
/** An offset: a whole number in decimal or $ hex, with an optional minus sign. */
|
|
@@ -810,7 +806,7 @@ const WRITE_COMMANDS: CommandSpec[] = [
|
|
|
810
806
|
request.symbol = call.string(select)!;
|
|
811
807
|
if (offset !== undefined) request.offset = offsetOf(offset, "--offset");
|
|
812
808
|
}
|
|
813
|
-
return (db) => shown(setOperand(db, { ...context, image:
|
|
809
|
+
return (db) => shown(setOperand(db, { ...context, image: operandImages(db) }, request), "operand", operand);
|
|
814
810
|
},
|
|
815
811
|
),
|
|
816
812
|
writeCommand({ name: "unoperand", summary: "Removes the operand expression at an address.", subjects: [ADDRESS] }, (call) => {
|
|
@@ -837,7 +833,7 @@ const WRITE_COMMANDS: CommandSpec[] = [
|
|
|
837
833
|
if ((code === undefined) === !call.flag("nop")) throw new UsageError("patch needs exactly one of --code, --code-file or --nop.");
|
|
838
834
|
const commentText = call.string("comment");
|
|
839
835
|
const request = { space: call.space, ...call.parseRange(call.subject(0), "<range>"), switch: call.subject(1), code: code ?? "", ...(commentText === undefined ? {} : { comment: commentText }) };
|
|
840
|
-
return (db) => shown(setPatch(db, { ...context, image:
|
|
836
|
+
return (db) => shown(setPatch(db, { ...context, image: operandImages(db) }, request), "patch", patch);
|
|
841
837
|
},
|
|
842
838
|
),
|
|
843
839
|
writeCommand(
|
|
@@ -881,7 +877,7 @@ const WRITE_COMMANDS: CommandSpec[] = [
|
|
|
881
877
|
...(commentText === undefined ? {} : { comment: commentText }),
|
|
882
878
|
};
|
|
883
879
|
return (db) => {
|
|
884
|
-
const result = setSwitch(db, { ...context, image:
|
|
880
|
+
const result = setSwitch(db, { ...context, image: operandImages(db) }, request);
|
|
885
881
|
const base = listReleases(db, undefined, call.space).find((row) => row.base)?.label;
|
|
886
882
|
return shown(result, "switch", (row: SwitchRow) => switchRow(row, base));
|
|
887
883
|
};
|
|
@@ -895,27 +891,23 @@ const WRITE_COMMANDS: CommandSpec[] = [
|
|
|
895
891
|
writeCommand(
|
|
896
892
|
{
|
|
897
893
|
name: "release",
|
|
898
|
-
summary: "Records a release of the program
|
|
894
|
+
summary: "Records a release of the program from its PRG or the image.json of its capture: the knowledge keeps the bytes of the release. The base release is the one whose bytes are the program of the knowledge.",
|
|
899
895
|
subjects: [{ name: "<label>", help: "the release label, for example ORIGINAL or FIRESTAR" }],
|
|
900
896
|
options: {
|
|
901
|
-
file: { kind: "path", value: "<file>", help: "the PRG or image.json of the release,
|
|
897
|
+
file: { kind: "path", value: "<file>", help: "the PRG or image.json of the release. After the write, the knowledge does not need the file", required: true },
|
|
902
898
|
base: { kind: "flag", help: "this release is the program of the knowledge: its segments and bytes must be the same" },
|
|
903
899
|
comment: { kind: "text", value: "<text>", help: "what the release is, for example the group and the date" },
|
|
904
900
|
},
|
|
905
|
-
notes: "The build of a release defines RELEASE_<label>=1: each switch then has the value of that release. The check of the generated source builds each release and compares it with the bytes of
|
|
901
|
+
notes: "The build of a release defines RELEASE_<label>=1: each switch then has the value of that release. The check of the generated source builds each release and compares it with the bytes of the release in the knowledge.",
|
|
906
902
|
},
|
|
907
903
|
(call) => {
|
|
908
904
|
const context = contextOf(call);
|
|
909
905
|
const file = knowledgePath(call.string("file")!, "--file");
|
|
910
|
-
const root = projectRoot();
|
|
911
|
-
if (isInside(join(root, PROJECT_DIRECTORY, LOCAL_DIRECTORY), resolveProjectPath(file, root))) {
|
|
912
|
-
throw new UsageError(`--file ${file} is in ${PROJECT_DIRECTORY}/${LOCAL_DIRECTORY}/, which git ignores. Move the release to a folder that git keeps, for example original/.`);
|
|
913
|
-
}
|
|
914
906
|
const image = readImage(file);
|
|
915
|
-
const sha256 = createHash("sha256").update(readProjectFile(file).bytes).digest("hex");
|
|
916
907
|
const commentText = call.string("comment");
|
|
917
908
|
const base = call.flag("base");
|
|
918
|
-
|
|
909
|
+
// The base release has no bytes of its own: its bytes are the program.
|
|
910
|
+
const request = { space: call.space, label: call.subject(0), ...(base ? { base } : { rows: memoryRows(image.segments, image.byteAt) }), ...(commentText === undefined ? {} : { comment: commentText }) };
|
|
919
911
|
return (db) => {
|
|
920
912
|
if (base) {
|
|
921
913
|
const program = requireProgram(db, call.space);
|
|
@@ -925,7 +917,8 @@ const WRITE_COMMANDS: CommandSpec[] = [
|
|
|
925
917
|
});
|
|
926
918
|
if (!same) throw new Refusal("invalid-input", `The bytes of ${file} are not the program of the knowledge. Give --base only to the release whose file image put into the knowledge.`);
|
|
927
919
|
}
|
|
928
|
-
|
|
920
|
+
const bytes = image.segments.reduce((sum, segment) => sum + segment.end - segment.start + 1, 0);
|
|
921
|
+
return { ...shown(setRelease(db, context, request), "release", release), bytes };
|
|
929
922
|
};
|
|
930
923
|
},
|
|
931
924
|
),
|
|
@@ -939,42 +932,62 @@ const WRITE_COMMANDS: CommandSpec[] = [
|
|
|
939
932
|
name: "start-screen",
|
|
940
933
|
summary: "Records the start screen of the program: a loading, title or presentation screen of the program itself, in memory at the entry or in a captured stage of the loading. The loader of the generated source shows it and waits for a key or a fire button before the entry.",
|
|
941
934
|
options: {
|
|
942
|
-
mode: { kind: "choice", value: "<mode>", choices: START_SCREEN_MODES, help: `one of ${START_SCREEN_MODES.join(", ")}
|
|
943
|
-
screen: { kind: "address", value: "<address>", help: "the screen: the 1000 characters of a text screen, or the 1000 colour bytes of a bitmap
|
|
935
|
+
mode: { kind: "choice", value: "<mode>", choices: START_SCREEN_MODES, help: `one of ${START_SCREEN_MODES.join(", ")}. Necessary without --stage` },
|
|
936
|
+
screen: { kind: "address", value: "<address>", help: "the screen: the 1000 characters of a text screen, or the 1000 colour bytes of a bitmap. Necessary without --stage" },
|
|
944
937
|
bitmap: { kind: "address", value: "<address>", help: "the 8000 bytes of the bitmap. hires and multicolour need it" },
|
|
945
938
|
charset: { kind: "address", value: "<address>", help: "the 2048 bytes of the charset, or '$1000' or '$1800' for the character ROM in VIC bank 0. text needs it" },
|
|
946
939
|
colours: { kind: "address", value: "<address>", help: "the 1000 bytes that the loader copies to the colour RAM" },
|
|
947
940
|
colour: { kind: "count", value: "<0-15>", min: 0, max: 15, help: "one colour for all of the colour RAM, in place of --colours" },
|
|
948
|
-
border: { kind: "count", value: "<0-15>", min: 0, max: 15, help: "the border colour
|
|
949
|
-
background: { kind: "count", value: "<0-15>", min: 0, max: 15, help: "the background colour
|
|
950
|
-
stage: { kind: "text", value: "<space>", help: "the space of
|
|
941
|
+
border: { kind: "count", value: "<0-15>", min: 0, max: 15, help: "the border colour. Necessary without --stage" },
|
|
942
|
+
background: { kind: "count", value: "<0-15>", min: 0, max: 15, help: "the background colour. Necessary without --stage" },
|
|
943
|
+
stage: { kind: "text", value: "<space>", help: "the space of the captured stage that shows the screen: loading. The script takes the mode, the addresses and the colours from the capture of the stage. Without it, the bytes are in the program at the entry" },
|
|
951
944
|
call: { kind: "address", value: "<address>", help: "a routine of the stage that the start screen calls before it waits, for example the routine that starts the loading tune. It must return with RTS. Needs --stage" },
|
|
952
945
|
comment: { kind: "text", value: "<text>", help: "what the screen is" },
|
|
953
946
|
},
|
|
954
|
-
notes: "Record only a screen of the program itself, never a screen of a crack. If a release changed the screen, for example with the text of a crack, stop and ask the user how to deal with it. text and multicolour need --colours or --colour; hires uses neither. With --stage, the
|
|
947
|
+
notes: "Record only a screen of the program itself, never a screen of a crack. If a release changed the screen, for example with the text of a crack, stop and ask the user how to deal with it. text and multicolour need --colours or --colour; hires uses neither. With --stage, the script takes the screen from the capture of the stage: give only --stage, and --call for a tune. A flag that you give too replaces the value of the capture. A write replaces the start screen of the knowledge.",
|
|
955
948
|
},
|
|
956
949
|
(call) => {
|
|
957
950
|
const context = contextOf(call);
|
|
958
951
|
const commentText = call.string("comment");
|
|
959
|
-
|
|
960
|
-
const colour =
|
|
952
|
+
// The values that the call gives. With --stage, the capture of the stage gives the others.
|
|
953
|
+
const given: { mode?: StartScreenMode; screen?: number; bitmap?: number; charset?: number; colours?: number; colour?: number; border?: number; background?: number } = {};
|
|
954
|
+
const mode = call.string("mode") as StartScreenMode | undefined;
|
|
955
|
+
if (mode !== undefined) given.mode = mode;
|
|
956
|
+
for (const key of ["screen", "bitmap", "charset", "colours"] as const) {
|
|
957
|
+
const value = call.address(key);
|
|
958
|
+
if (value !== undefined) given[key] = value;
|
|
959
|
+
}
|
|
960
|
+
for (const key of ["colour", "border", "background"] as const) {
|
|
961
|
+
const value = call.count(key);
|
|
962
|
+
if (value !== undefined) given[key] = value;
|
|
963
|
+
}
|
|
961
964
|
const stage = call.string("stage");
|
|
962
965
|
const routine = call.address("call");
|
|
963
|
-
const
|
|
966
|
+
const extra = {
|
|
964
967
|
space: call.space,
|
|
965
|
-
mode: call.string("mode") as StartScreenMode,
|
|
966
|
-
screen: call.address("screen")!,
|
|
967
|
-
...optional("bitmap"),
|
|
968
|
-
...optional("charset"),
|
|
969
|
-
...optional("colours"),
|
|
970
|
-
...(colour === undefined ? {} : { colour }),
|
|
971
|
-
border: call.count("border")!,
|
|
972
|
-
background: call.count("background")!,
|
|
973
968
|
...(stage === undefined ? {} : { stage }),
|
|
974
969
|
...(routine === undefined ? {} : { call: routine }),
|
|
975
970
|
...(commentText === undefined ? {} : { comment: commentText }),
|
|
976
971
|
};
|
|
977
|
-
|
|
972
|
+
const complete = (values: typeof given & { colourRam?: true }, remedy: string) => {
|
|
973
|
+
const missing = (["mode", "screen", "border", "background"] as const).filter((key) => values[key] === undefined);
|
|
974
|
+
if (missing.length > 0) throw new UsageError(`Give ${missing.map((key) => `--${key}`).join(", ")}, ${remedy}`);
|
|
975
|
+
return { ...values, mode: values.mode!, screen: values.screen!, border: values.border!, background: values.background!, ...extra };
|
|
976
|
+
};
|
|
977
|
+
if (stage === undefined) {
|
|
978
|
+
const request = complete(given, "or give --stage with the space of a captured stage that shows the screen.");
|
|
979
|
+
return (db) => shown(setStartScreen(db, context, request), "startScreen", startScreen);
|
|
980
|
+
}
|
|
981
|
+
return (db) => {
|
|
982
|
+
// The capture of the stage gives the screen. A flag of the call replaces a value of the capture, and --colours or --colour replaces the colour RAM.
|
|
983
|
+
const image = programImage(db, stage);
|
|
984
|
+
if (image === undefined) throw new Refusal("not-found", `The knowledge has no program in ${stage}. Capture the stage while it shows the start screen, and put the capture into the project knowledge with image --space ${stage}. Then record the start screen again.`);
|
|
985
|
+
const captured = mode === undefined ? startScreenOfStage(image.state, stage) : undefined;
|
|
986
|
+
const { colourRam, ...fromCapture } = captured ?? { colourRam: undefined };
|
|
987
|
+
const ownColours = given.colours !== undefined || given.colour !== undefined;
|
|
988
|
+
const request = complete({ ...fromCapture, ...(colourRam === true && !ownColours ? { colourRam } : {}), ...given }, "or give --stage alone to take the screen from the capture.");
|
|
989
|
+
return shown(setStartScreen(db, context, request), "startScreen", startScreen);
|
|
990
|
+
};
|
|
978
991
|
},
|
|
979
992
|
),
|
|
980
993
|
writeCommand({ name: "unstart-screen", summary: "Removes the start screen. The loader of the generated source then starts the program at once." }, (call) => {
|
|
@@ -1020,7 +1033,7 @@ const WRITE_COMMANDS: CommandSpec[] = [
|
|
|
1020
1033
|
const context = contextOf(call);
|
|
1021
1034
|
const request = { space: call.space, ...call.parseRange(call.subject(0), "<range>"), macro: call.subject(1), args: commaList(call.string("args") ?? "") };
|
|
1022
1035
|
return (db) => {
|
|
1023
|
-
const result = setMacroUse(db, { ...context, image:
|
|
1036
|
+
const result = setMacroUse(db, { ...context, image: operandImages(db) }, request);
|
|
1024
1037
|
return { revision: result.revision, use: macroUse(result.current), ...(result.previous === undefined ? {} : { previous: macroUse(result.previous) }) };
|
|
1025
1038
|
};
|
|
1026
1039
|
},
|
|
@@ -1065,7 +1078,7 @@ const WRITE_COMMANDS: CommandSpec[] = [
|
|
|
1065
1078
|
name: "revert",
|
|
1066
1079
|
summary: "Makes the knowledge the same as at one revision: all spaces, or with --space only that space. The revert is a new revision: the history stays complete.",
|
|
1067
1080
|
subjects: [REVISION],
|
|
1068
|
-
options: { space: { kind: "space", value: "<space>", help: "revert only this space: c64, drive8, or bank0 to bank255. The other spaces do not change. Without --space, every space reverts" } },
|
|
1081
|
+
options: { space: { kind: "space", value: "<space>", help: "revert only this space: c64, drive8, loading, or bank0 to bank255. The other spaces do not change. Without --space, every space reverts" } },
|
|
1069
1082
|
},
|
|
1070
1083
|
(call) => {
|
|
1071
1084
|
const context = contextOf(call);
|
|
@@ -1104,23 +1117,25 @@ const WRITE_COMMANDS: CommandSpec[] = [
|
|
|
1104
1117
|
}
|
|
1105
1118
|
if (!Array.isArray(parsed)) throw new Refusal("invalid-input", `The batch ${path} is not a JSON list of writes. Give a list such as [{"op": "rename", "address": "$2100", "name": "update_player"}].`);
|
|
1106
1119
|
const operations = parsed.map((item, index) => batchOperation(call, item, `write ${index + 1}`));
|
|
1107
|
-
|
|
1108
|
-
return (db) => {
|
|
1109
|
-
const applied = applyBatch(db, checked ? { ...context, image: operandImage(db, call.space) } : context, operations);
|
|
1110
|
-
// replaced: each write that replaced a row of another origin, with that row as previous gives it for one write.
|
|
1111
|
-
const replaced = applied.steps.flatMap((step, index) => (step.previous === undefined ? [] : [{ write: index + 1, op: operations[index]!.op, previous: shownPrevious(step.previous) }]));
|
|
1112
|
-
return { revision: applied.revision, writes: applied.steps.length, replaced };
|
|
1113
|
-
};
|
|
1120
|
+
return (db) => applied(db, context, operations);
|
|
1114
1121
|
},
|
|
1115
1122
|
),
|
|
1116
1123
|
];
|
|
1117
1124
|
|
|
1118
|
-
/**
|
|
1125
|
+
/** Applies the writes of a batch as one revision, and gives the revision, the count and each row of another origin that a write replaced. */
|
|
1126
|
+
function applied(db: DatabaseSync, context: WriteContext, operations: BatchOperation[]) {
|
|
1127
|
+
const result = applyBatch(db, { ...context, image: operandImages(db) }, operations);
|
|
1128
|
+
// replaced: each write that replaced a row of another origin, with that row as previous gives it for one write.
|
|
1129
|
+
const replaced = result.steps.flatMap((step, index) => (step.previous === undefined ? [] : [{ write: index + 1, op: operations[index]!.op, previous: shownPrevious(step.previous) }]));
|
|
1130
|
+
return { revision: result.revision, writes: result.steps.length, replaced };
|
|
1131
|
+
}
|
|
1132
|
+
|
|
1133
|
+
/** join: the batches of agents that worked in parallel, as one list of writes. With --apply, it writes them as one revision. */
|
|
1119
1134
|
const JOIN: CommandSpec = {
|
|
1120
1135
|
name: "join",
|
|
1121
|
-
summary: "Joins the batches of agents that worked in parallel into one
|
|
1136
|
+
summary: "Joins the batches of agents that worked in parallel into one list of writes, and shows it. With --apply, it writes the list as one revision, or nothing when one write is refused.",
|
|
1122
1137
|
subjects: [{ name: "<batch>", help: 'a batch: a list of writes, or {"owner": {"start": "$1000", "end": "$1fff"}, "ops": [...]}', list: true }],
|
|
1123
|
-
options: { ...
|
|
1138
|
+
options: { ...WRITE, apply: { kind: "flag", help: "write the joined writes to the project knowledge as one revision. Without it, the result only shows them" }, ...LIST },
|
|
1124
1139
|
notes: "At an address in the owner range of a batch, its name, comment, operand and module win, and its regions come last. One name or one module file at two addresses writes nothing.",
|
|
1125
1140
|
run: (call) => {
|
|
1126
1141
|
if (call.subjects.length < 2) throw new UsageError("join needs two or more batch files.");
|
|
@@ -1157,9 +1172,10 @@ const JOIN: CommandSpec = {
|
|
|
1157
1172
|
const clash = (item: JoinClash) => `${item.what} ${item.value} at ${item.places.map((place) => `${formatC64Address(place.address)} (${place.file})`).join(" and ")}${item.space === DEFAULT_SPACE ? "" : ` in ${item.space}`}`;
|
|
1158
1173
|
throw new Refusal("conflict", `The batches give one ${joined.clashes.map(clash).join(", one ")}. Nothing was written. Give each name and each module file one address in the batches, then join again.`);
|
|
1159
1174
|
}
|
|
1160
|
-
const
|
|
1161
|
-
|
|
1162
|
-
|
|
1175
|
+
const shown = { repeated: joined.repeated, choices: joined.choices.map(choice) };
|
|
1176
|
+
if (call.flag("apply")) return { ...withWrite((db) => applied(db, contextOf(call), joined.ops)), ...shown };
|
|
1177
|
+
const body = { writes: listed(joined.ops.map(batchJson), call.count("max-listed")!, (write) => write, MORE), ...shown };
|
|
1178
|
+
return reply(body, { hint: "Examine each item of choices and writes. Then nextAction writes them to the project knowledge as one revision.", nextAction: call.next("join", ...call.subjects, "--apply") });
|
|
1163
1179
|
},
|
|
1164
1180
|
};
|
|
1165
1181
|
|
|
@@ -1243,7 +1259,7 @@ function batchFields(fields: Record<string, unknown>, at: string, address: (text
|
|
|
1243
1259
|
|
|
1244
1260
|
await runScript({
|
|
1245
1261
|
name: "knowledge",
|
|
1246
|
-
summary: "Reads and writes the knowledge of the project: names, regions, comments, references, the program and its coverage, and the source knowledge. A read needs no knowledge folder. Every command takes --space: c64 (the default), drive8 for 1541 drive code, or bank0 to bank255 for cartridge banks. revert without --space reverts all spaces.",
|
|
1262
|
+
summary: "Reads and writes the knowledge of the project: names, regions, comments, references, the program and its coverage, and the source knowledge. A read needs no knowledge folder. Every command takes --space: c64 (the default), drive8 for 1541 drive code, loading for a captured stage of the loading, or bank0 to bank255 for cartridge banks. revert without --space reverts all spaces.",
|
|
1247
1263
|
names: knowledgeNames,
|
|
1248
1264
|
commands: [...READ_COMMANDS, ...WRITE_COMMANDS, JOIN],
|
|
1249
1265
|
});
|
|
@@ -11,6 +11,8 @@ export interface ListingSource {
|
|
|
11
11
|
byteAt: (address: number) => number | undefined;
|
|
12
12
|
/** The name of an address: a symbol, else a platform name. */
|
|
13
13
|
nameOf: (address: number) => string | undefined;
|
|
14
|
+
/** The start of the platform entry of more bytes that holds an address outside the image (NMINV for its high byte), or undefined. */
|
|
15
|
+
entryStart?: (address: number) => number | undefined;
|
|
14
16
|
/** The analyzer names of an address, for reference. */
|
|
15
17
|
secondNames: (address: number) => string[];
|
|
16
18
|
/** The knowledge regions, in address order. */
|
|
@@ -52,9 +54,22 @@ function accessOf(coverage: Uint8Array | undefined, start: number, length: numbe
|
|
|
52
54
|
return text === "" ? "-" : text;
|
|
53
55
|
}
|
|
54
56
|
|
|
57
|
+
/**
|
|
58
|
+
* The name of an operand target, as c64-source writes it: its own name, else
|
|
59
|
+
* name+offset inside a named data region, or inside a platform entry of more bytes.
|
|
60
|
+
*/
|
|
61
|
+
function targetName(target: number, source: ListingSource): string | undefined {
|
|
62
|
+
const own = source.nameOf(target);
|
|
63
|
+
if (own !== undefined) return own;
|
|
64
|
+
const region = source.regions.find((row) => target > row.start && target <= row.end && !CODE.has(row.type) && row.type !== "dual-use");
|
|
65
|
+
const start = region?.start ?? source.entryStart?.(target);
|
|
66
|
+
const name = start === undefined ? undefined : source.nameOf(start);
|
|
67
|
+
return name === undefined ? undefined : `${name}+${target - start!}`;
|
|
68
|
+
}
|
|
69
|
+
|
|
55
70
|
/** The operand value of an instruction as an expression: the name of its target where one exists, else the number. Empty for no operand. */
|
|
56
|
-
function operandOf(mode: Mode, address: number, low: number, high: number,
|
|
57
|
-
const named = (target: number, digits: 2 | 4) =>
|
|
71
|
+
function operandOf(mode: Mode, address: number, low: number, high: number, source: ListingSource): string {
|
|
72
|
+
const named = (target: number, digits: 2 | 4) => targetName(target, source) ?? (digits === 2 ? formatC64Byte(target) : formatC64Address(target));
|
|
58
73
|
if (mode === "imp") return "";
|
|
59
74
|
if (mode === "imm") return formatC64Byte(low);
|
|
60
75
|
if (mode === "rel") return named((address + 2 + (low < 0x80 ? low : low - 0x100)) & 0xffff, 4);
|
|
@@ -108,7 +123,7 @@ export function listing(source: ListingSource, start: number, end: number): List
|
|
|
108
123
|
const bytes = Array.from({ length: length - 1 }, (_, offset) => source.byteAt(address + 1 + offset));
|
|
109
124
|
if (address + length - 1 <= region.end && bytes.every((value) => value !== undefined)) {
|
|
110
125
|
// The operand expression of the knowledge in the syntax of the addressing mode, as c64-source writes it.
|
|
111
|
-
const operand = source.operand(address) ?? operandOf(opcode.mode, address, bytes[0] ?? 0, bytes[1] ?? 0, source
|
|
126
|
+
const operand = source.operand(address) ?? operandOf(opcode.mode, address, bytes[0] ?? 0, bytes[1] ?? 0, source);
|
|
112
127
|
if (address >= start) lines.push(line(address, length, instructionWith(byte, operand)));
|
|
113
128
|
address += length;
|
|
114
129
|
continue;
|
|
@@ -25,7 +25,7 @@ To get the command list, run the script with no arguments.
|
|
|
25
25
|
|---|---|
|
|
26
26
|
| Pack a BASIC program at `$0801` that starts with `SYS` | `pack build/game.prg --out build/game-packed.prg` |
|
|
27
27
|
| Pack a program that starts at a known address | `pack build/main.prg --entry '$0400' --out build/release.prg` |
|
|
28
|
-
| Merge more PRG files into one packed program | `pack build/
|
|
28
|
+
| Merge more PRG files into one packed program | `pack build/clean_loader.prg build/clean.prg --entry '$0400' --out build/clean_packed.prg` |
|
|
29
29
|
| Start the program with RAM in place of the BASIC and KERNAL ROMs | `pack build/game.prg --exit-memory '$35' --out build/game-packed.prg` |
|
|
30
30
|
|
|
31
31
|
---
|