@henols/vice-mcp 0.2.2 → 0.2.3

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 (77) hide show
  1. package/README.md +2 -2
  2. package/THIRD-PARTY-NOTICES.md +422 -1
  3. package/anno-bank.ts +171 -0
  4. package/anno-cli.ts +1674 -99
  5. package/anno-enum-gen.ts +416 -30
  6. package/anno-export-asm.ts +1175 -89
  7. package/anno-graphics.ts +338 -0
  8. package/anno-hazard-report.ts +1367 -0
  9. package/anno-import.ts +495 -0
  10. package/anno-join.ts +480 -0
  11. package/anno-provenance-ledger.ts +472 -0
  12. package/anno-register.ts +159 -0
  13. package/anno-store-export.ts +661 -0
  14. package/anno-store.ts +518 -2
  15. package/anno-tools.ts +1169 -16
  16. package/anno-types.ts +275 -2
  17. package/backend-detect.mts +124 -312
  18. package/build.ts +3 -1
  19. package/capture-predicate.ts +597 -0
  20. package/channel-lock.ts +349 -0
  21. package/evid-ingest.ts +217 -0
  22. package/evid-reconcile.ts +316 -0
  23. package/host-tool-client.ts +430 -0
  24. package/incident-record.ts +23 -12
  25. package/install-resources.ts +29 -13
  26. package/memmap-lookup.ts +285 -0
  27. package/package.json +27 -8
  28. package/prg-image.ts +1 -2
  29. package/repo-root.ts +87 -3
  30. package/resources/backend-detect.mjs +98 -236
  31. package/resources/broker-control.mjs +189 -16
  32. package/resources/broker-epoch.mjs +1 -1
  33. package/resources/broker-kill.mjs +8 -2
  34. package/resources/broker-launch.mjs +365 -210
  35. package/resources/broker-state.mjs +64 -18
  36. package/resources/container-guard.mjs +1 -1
  37. package/resources/ghidra-project.mjs +790 -0
  38. package/resources/host-tool.mjs +2561 -0
  39. package/resources/vice-broker.mjs +330 -184
  40. package/resources/vice-launcher.sh +127 -9
  41. package/stock-address.ts +1 -1
  42. package/stock-condition.ts +1 -1
  43. package/stock-connect.ts +9 -5
  44. package/stock-derived.ts +29 -37
  45. package/stock-diagnose.ts +200 -36
  46. package/stock-dispatch.ts +179 -77
  47. package/stock-handler.ts +1 -1
  48. package/stock-paths.ts +18 -14
  49. package/stock-petscii.ts +1 -1
  50. package/stock-protocol.ts +1 -1
  51. package/stock-recycle.ts +83 -2
  52. package/stock-reproducible-run.ts +811 -0
  53. package/stock-run-until.ts +100 -1
  54. package/stock-symbols.ts +4 -4
  55. package/stock-timing.ts +1 -1
  56. package/stop-oracle.ts +167 -0
  57. package/text-capability-probe.ts +660 -0
  58. package/text-connect.ts +157 -0
  59. package/text-protocol.ts +810 -0
  60. package/text-tools.ts +778 -0
  61. package/textmon-backtrace.ts +385 -0
  62. package/textmon-cpuhistory.ts +335 -0
  63. package/textmon-memmap.ts +494 -0
  64. package/textmon-profile.ts +458 -0
  65. package/textmon-registers.ts +748 -0
  66. package/tools-manifest.stock.json +864 -3
  67. package/vice-broker-client.ts +189 -42
  68. package/vice-errors.ts +268 -0
  69. package/vice-proxy.ts +339 -2144
  70. package/vsf-slice.ts +640 -0
  71. package/anno-d64.ts +0 -310
  72. package/capability-registry.ts +0 -390
  73. package/refresh-manifest.ts +0 -124
  74. package/tools-manifest.json +0 -1223
  75. package/vice-probe.ts +0 -278
  76. package/vice-sync.ts +0 -336
  77. package/vice.ts +0 -772
package/README.md CHANGED
@@ -13,7 +13,7 @@ separately so it can be launched directly by an MCP client.
13
13
 
14
14
  ## Requirements
15
15
 
16
- - **Node.js ≥ 22.18** (or ≥ 23.6). The server ships as TypeScript and runs under
16
+ - **Node.js ≥ 24**. The server ships as TypeScript and runs under
17
17
  Node's native type-stripping — no build step, no flags. Older Node needs
18
18
  `--experimental-strip-types` and is unsupported.
19
19
  - A **host** with VICE (`x64sc`) available, reachable from wherever the MCP client
@@ -39,7 +39,7 @@ Add it to your MCP client configuration and let the client launch it:
39
39
  ```
40
40
 
41
41
  The bin (`vice-mcp`) speaks the MCP stdio protocol. `initialize` and `tools/list`
42
- are answered locally (from `tools-manifest.json`); `tools/call` forwards to the host
42
+ are answered locally (from `tools-manifest.stock.json`); `tools/call` forwards to the host
43
43
  VICE MCP server.
44
44
 
45
45
  ## Environment
@@ -4,7 +4,7 @@ This package is MIT-licensed (see `LICENSE` at the repository root, copyright
4
4
  Henrik Olsson). This file lists third-party material incorporated into, or
5
5
  relied on by, `@henols/vice-mcp`, with a provenance line per source.
6
6
 
7
- **No GPL-licensed material is incorporated into this package: no GPL-licensed material appears anywhere in `@henols/vice-mcp`'s source or its published tarball.** Every source named below is either zlib-licensed (incorporated), reference-only (nothing copied), or a build/test-time subprocess whose licence therefore never attaches to anything shipped.
7
+ **GPL-2.0-or-later source IS incorporated into this repository, under `src/mcp/vice/vendor/dxa/` (Phase 35, DXA-01).** That source is build-time-only input — vendored to be compiled by `vendor/dxa/build.bash` into a host-side binary this project's host-tool execution seam spawns as a subprocess, never imported by, linked into, or shipped inside the published `@henols/vice-mcp` tarball (A-06: `src/mcp/vice/package.json`'s `files[]` deliberately omits `vendor/dxa/` and the `dxa-*` modules that consume it). Every OTHER source named below is either zlib-licensed (incorporated), reference-only (nothing copied), or a build/test-time subprocess whose licence therefore never attaches to anything shipped.
8
8
 
9
9
  ## Incorporated material — cc65 (zlib)
10
10
 
@@ -51,6 +51,427 @@ freely, subject to the following restrictions:
51
51
  3. This notice may not be removed or altered from any source distribution.
52
52
  ```
53
53
 
54
+ ## Incorporated material — dxa (GPL-2.0-or-later)
55
+
56
+ `src/mcp/vice/vendor/dxa/` vendors the upstream-unmodified, GPL-licensed
57
+ source of [dxa](https://www.floodgap.com/retrotech/xa/dists/dxa-0.1.5.tar.gz)
58
+ 0.1.5 (37,987 bytes, 25 Mar 2022), the symbolic 65xx disassembler this
59
+ project's byte-level code/data discovery engine builds and spawns
60
+ (`DXA-01`). The tarball is pinned by `dxa-0.1.5.tar.gz.sha256`
61
+ (`8e40ed77816581f9ad95acac2ed69a2fb2ac7850e433d19cd684193a45826799`), written
62
+ to this repository BEFORE the tarball was ever fetched, and re-verified
63
+ byte-for-byte against that pin by `vendor/dxa/build.bash` on every run.
64
+
65
+ The tarball ships **no `LICENSE` and no `COPYING` file** — the GPL grant
66
+ lives only in a header comment repeated (with per-file variance, below) at
67
+ the top of every vendored `.c`/`.h` file. This project therefore supplies the
68
+ full GPL licence text itself, reproduced in full further down this section.
69
+
70
+ `main.c`'s header, quoted verbatim from `src/mcp/vice/vendor/dxa/main.c`:
71
+
72
+ ```
73
+ /*\
74
+ * dxa -- symbolic 65xx disassembler
75
+ *
76
+ * Based on d65 Copyright (C) 1993, 1994 Marko M\"akel\"a
77
+ * Changes for dxa (C) 2005-2019 Cameron Kaiser
78
+ *
79
+ * This program is free software; you can redistribute it and/or modify
80
+ * it under the terms of the GNU General Public License as published by
81
+ * the Free Software Foundation; either version 2 of the License, or
82
+ * (at your option) any later version.
83
+ *
84
+ * This program is distributed in the hope that it will be useful,
85
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
86
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
87
+ * GNU General Public License for more details.
88
+ *
89
+ * You should have received a copy of the GNU General Public License
90
+ * along with this program; if not, write to the Free Software
91
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
92
+ *
93
+ * Marko does not maintain dxa, so questions specific to dxa should be
94
+ * sent to me at ckaiser@floodgap.com.
95
+ *
96
+ \*/
97
+ ```
98
+
99
+ **Per-file copyright variance — recorded rather than flattened.** Every
100
+ vendored `.c` file carries the `dxa -- symbolic 65xx disassembler` /
101
+ `GNU General Public License` (GPL) header block, but the copyright line
102
+ itself differs by file, reflecting dxa's own history as a fork of Marko
103
+ Mäkelä's `d65`:
104
+
105
+ - `table.c` and `vector.c` carry only the original `Copyright (C) 1993, 1994
106
+ Marko M\"akel\"a` line (their header still identifies as `dxa v0.1.1`,
107
+ an earlier version string than the tarball's own 0.1.5) — no Cameron
108
+ Kaiser line at all.
109
+ - `scan.c` and `label.c` carry `Copyright (C) 1993, 1994 Marko M\"akel\"a`
110
+ followed by a separate `Copyright (C) 2019 Cameron Kaiser` line.
111
+ - `dump.c` carries `Copyright (C) 1993, 1994 Marko M\"akel\"a` followed by
112
+ `Changes for dxa (C) 2004-2019 Cameron Kaiser` (note: 2004, one year
113
+ earlier than `main.c`'s own 2005-2019 span for the same "Changes for dxa"
114
+ wording).
115
+ - `main.c` (quoted above) carries `Based on d65 Copyright (C) 1993, 1994
116
+ Marko M\"akel\"a` followed by `Changes for dxa (C) 2005-2019 Cameron
117
+ Kaiser`.
118
+
119
+ Every one of `ChangeLog`, `dump.c`, `dxa.1`, `INSTALL`, `label.c`, `main.c`,
120
+ `Makefile`, `opcodes.h`, `options.h`, `proto.h`, `scan.c`, `structures.h`,
121
+ `table.c`, `tests/Makefile`, `tests/test01.t`, `tests/test02.t`, `vector.c`
122
+ is upstream-unmodified and every `.c` file's header names the same GPL
123
+ grant — nothing added, nothing removed, nothing patched
124
+ (`vendor/dxa/build.bash`'s `verify` step asserts this byte-for-byte on every
125
+ run, not merely at vendoring time).
126
+
127
+ `vendor/dxa/build.bash` — never a package manager, never `$PATH` — is the
128
+ only supported way to obtain a built `dxa` binary; the built binary and every
129
+ `.o` intermediate are gitignored, never committed (host-architecture-specific
130
+ artifacts a digest gate could not otherwise defend). Full text of the GPL
131
+ licence dxa is offered under — the GNU General Public License, Version 2,
132
+ June 1991 — reproduced below because the upstream tarball ships none:
133
+
134
+ ```
135
+ GNU GENERAL PUBLIC LICENSE
136
+ Version 2, June 1991
137
+
138
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
139
+ <https://fsf.org/>
140
+ Everyone is permitted to copy and distribute verbatim copies
141
+ of this license document, but changing it is not allowed.
142
+
143
+ Preamble
144
+
145
+ The licenses for most software are designed to take away your
146
+ freedom to share and change it. By contrast, the GNU General Public
147
+ License is intended to guarantee your freedom to share and change free
148
+ software--to make sure the software is free for all its users. This
149
+ General Public License applies to most of the Free Software
150
+ Foundation's software and to any other program whose authors commit to
151
+ using it. (Some other Free Software Foundation software is covered by
152
+ the GNU Lesser General Public License instead.) You can apply it to
153
+ your programs, too.
154
+
155
+ When we speak of free software, we are referring to freedom, not
156
+ price. Our General Public Licenses are designed to make sure that you
157
+ have the freedom to distribute copies of free software (and charge for
158
+ this service if you wish), that you receive source code or can get it
159
+ if you want it, that you can change the software or use pieces of it
160
+ in new free programs; and that you know you can do these things.
161
+
162
+ To protect your rights, we need to make restrictions that forbid
163
+ anyone to deny you these rights or to ask you to surrender the rights.
164
+ These restrictions translate to certain responsibilities for you if you
165
+ distribute copies of the software, or if you modify it.
166
+
167
+ For example, if you distribute copies of such a program, whether
168
+ gratis or for a fee, you must give the recipients all the rights that
169
+ you have. You must make sure that they, too, receive or can get the
170
+ source code. And you must show them these terms so they know their
171
+ rights.
172
+
173
+ We protect your rights with two steps: (1) copyright the software, and
174
+ (2) offer you this license which gives you legal permission to copy,
175
+ distribute and/or modify the software.
176
+
177
+ Also, for each author's protection and ours, we want to make certain
178
+ that everyone understands that there is no warranty for this free
179
+ software. If the software is modified by someone else and passed on, we
180
+ want its recipients to know that what they have is not the original, so
181
+ that any problems introduced by others will not reflect on the original
182
+ authors' reputations.
183
+
184
+ Finally, any free program is threatened constantly by software
185
+ patents. We wish to avoid the danger that redistributors of a free
186
+ program will individually obtain patent licenses, in effect making the
187
+ program proprietary. To prevent this, we have made it clear that any
188
+ patent must be licensed for everyone's free use or not licensed at all.
189
+
190
+ The precise terms and conditions for copying, distribution and
191
+ modification follow.
192
+
193
+ GNU GENERAL PUBLIC LICENSE
194
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
195
+
196
+ 0. This License applies to any program or other work which contains
197
+ a notice placed by the copyright holder saying it may be distributed
198
+ under the terms of this General Public License. The "Program", below,
199
+ refers to any such program or work, and a "work based on the Program"
200
+ means either the Program or any derivative work under copyright law:
201
+ that is to say, a work containing the Program or a portion of it,
202
+ either verbatim or with modifications and/or translated into another
203
+ language. (Hereinafter, translation is included without limitation in
204
+ the term "modification".) Each licensee is addressed as "you".
205
+
206
+ Activities other than copying, distribution and modification are not
207
+ covered by this License; they are outside its scope. The act of
208
+ running the Program is not restricted, and the output from the Program
209
+ is covered only if its contents constitute a work based on the
210
+ Program (independent of having been made by running the Program).
211
+ Whether that is true depends on what the Program does.
212
+
213
+ 1. You may copy and distribute verbatim copies of the Program's
214
+ source code as you receive it, in any medium, provided that you
215
+ conspicuously and appropriately publish on each copy an appropriate
216
+ copyright notice and disclaimer of warranty; keep intact all the
217
+ notices that refer to this License and to the absence of any warranty;
218
+ and give any other recipients of the Program a copy of this License
219
+ along with the Program.
220
+
221
+ You may charge a fee for the physical act of transferring a copy, and
222
+ you may at your option offer warranty protection in exchange for a fee.
223
+
224
+ 2. You may modify your copy or copies of the Program or any portion
225
+ of it, thus forming a work based on the Program, and copy and
226
+ distribute such modifications or work under the terms of Section 1
227
+ above, provided that you also meet all of these conditions:
228
+
229
+ a) You must cause the modified files to carry prominent notices
230
+ stating that you changed the files and the date of any change.
231
+
232
+ b) You must cause any work that you distribute or publish, that in
233
+ whole or in part contains or is derived from the Program or any
234
+ part thereof, to be licensed as a whole at no charge to all third
235
+ parties under the terms of this License.
236
+
237
+ c) If the modified program normally reads commands interactively
238
+ when run, you must cause it, when started running for such
239
+ interactive use in the most ordinary way, to print or display an
240
+ announcement including an appropriate copyright notice and a
241
+ notice that there is no warranty (or else, saying that you provide
242
+ a warranty) and that users may redistribute the program under
243
+ these conditions, and telling the user how to view a copy of this
244
+ License. (Exception: if the Program itself is interactive but
245
+ does not normally print such an announcement, your work based on
246
+ the Program is not required to print an announcement.)
247
+
248
+ These requirements apply to the modified work as a whole. If
249
+ identifiable sections of that work are not derived from the Program,
250
+ and can be reasonably considered independent and separate works in
251
+ themselves, then this License, and its terms, do not apply to those
252
+ sections when you distribute them as separate works. But when you
253
+ distribute the same sections as part of a whole which is a work based
254
+ on the Program, the distribution of the whole must be on the terms of
255
+ this License, whose permissions for other licensees extend to the
256
+ entire whole, and thus to each and every part regardless of who wrote it.
257
+
258
+ Thus, it is not the intent of this section to claim rights or contest
259
+ your rights to work written entirely by you; rather, the intent is to
260
+ exercise the right to control the distribution of derivative or
261
+ collective works based on the Program.
262
+
263
+ In addition, mere aggregation of another work not based on the Program
264
+ with the Program (or with a work based on the Program) on a volume of
265
+ a storage or distribution medium does not bring the other work under
266
+ the scope of this License.
267
+
268
+ 3. You may copy and distribute the Program (or a work based on it,
269
+ under Section 2) in object code or executable form under the terms of
270
+ Sections 1 and 2 above provided that you also do one of the following:
271
+
272
+ a) Accompany it with the complete corresponding machine-readable
273
+ source code, which must be distributed under the terms of Sections
274
+ 1 and 2 above on a medium customarily used for software interchange; or,
275
+
276
+ b) Accompany it with a written offer, valid for at least three
277
+ years, to give any third party, for a charge no more than your
278
+ cost of physically performing source distribution, a complete
279
+ machine-readable copy of the corresponding source code, to be
280
+ distributed under the terms of Sections 1 and 2 above on a medium
281
+ customarily used for software interchange; or,
282
+
283
+ c) Accompany it with the information you received as to the offer
284
+ to distribute corresponding source code. (This alternative is
285
+ allowed only for noncommercial distribution and only if you
286
+ received the program in object code or executable form with such
287
+ an offer, in accord with Subsection b above.)
288
+
289
+ The source code for a work means the preferred form of the work for
290
+ making modifications to it. For an executable work, complete source
291
+ code means all the source code for all modules it contains, plus any
292
+ associated interface definition files, plus the scripts used to
293
+ control compilation and installation of the executable. However, as a
294
+ special exception, the source code distributed need not include
295
+ anything that is normally distributed (in either source or binary
296
+ form) with the major components (compiler, kernel, and so on) of the
297
+ operating system on which the executable runs, unless that component
298
+ itself accompanies the executable.
299
+
300
+ If distribution of executable or object code is made by offering
301
+ access to copy from a designated place, then offering equivalent
302
+ access to copy the source code from the same place counts as
303
+ distribution of the source code, even though third parties are not
304
+ compelled to copy the source along with the object code.
305
+
306
+ 4. You may not copy, modify, sublicense, or distribute the Program
307
+ except as expressly provided under this License. Any attempt
308
+ otherwise to copy, modify, sublicense or distribute the Program is
309
+ void, and will automatically terminate your rights under this License.
310
+ However, parties who have received copies, or rights, from you under
311
+ this License will not have their licenses terminated so long as such
312
+ parties remain in full compliance.
313
+
314
+ 5. You are not required to accept this License, since you have not
315
+ signed it. However, nothing else grants you permission to modify or
316
+ distribute the Program or its derivative works. These actions are
317
+ prohibited by law if you do not accept this License. Therefore, by
318
+ modifying or distributing the Program (or any work based on the
319
+ Program), you indicate your acceptance of this License to do so, and
320
+ all its terms and conditions for copying, distributing or modifying
321
+ the Program or works based on it.
322
+
323
+ 6. Each time you redistribute the Program (or any work based on the
324
+ Program), the recipient automatically receives a license from the
325
+ original licensor to copy, distribute or modify the Program subject to
326
+ these terms and conditions. You may not impose any further
327
+ restrictions on the recipients' exercise of the rights granted herein.
328
+ You are not responsible for enforcing compliance by third parties to
329
+ this License.
330
+
331
+ 7. If, as a consequence of a court judgment or allegation of patent
332
+ infringement or for any other reason (not limited to patent issues),
333
+ conditions are imposed on you (whether by court order, agreement or
334
+ otherwise) that contradict the conditions of this License, they do not
335
+ excuse you from the conditions of this License. If you cannot
336
+ distribute so as to satisfy simultaneously your obligations under this
337
+ License and any other pertinent obligations, then as a consequence you
338
+ may not distribute the Program at all. For example, if a patent
339
+ license would not permit royalty-free redistribution of the Program by
340
+ all those who receive copies directly or indirectly through you, then
341
+ the only way you could satisfy both it and this License would be to
342
+ refrain entirely from distribution of the Program.
343
+
344
+ If any portion of this section is held invalid or unenforceable under
345
+ any particular circumstance, the balance of the section is intended to
346
+ apply and the section as a whole is intended to apply in other
347
+ circumstances.
348
+
349
+ It is not the purpose of this section to induce you to infringe any
350
+ patents or other property right claims or to contest validity of any
351
+ such claims; this section has the sole purpose of protecting the
352
+ integrity of the free software distribution system, which is
353
+ implemented by public license practices. Many people have made
354
+ generous contributions to the wide range of software distributed
355
+ through that system in reliance on consistent application of that
356
+ system; it is up to the author/donor to decide if he or she is willing
357
+ to distribute software through any other system and a licensee cannot
358
+ impose that choice.
359
+
360
+ This section is intended to make thoroughly clear what is believed to
361
+ be a consequence of the rest of this License.
362
+
363
+ 8. If the distribution and/or use of the Program is restricted in
364
+ certain countries either by patents or by copyrighted interfaces, the
365
+ original copyright holder who places the Program under this License
366
+ may add an explicit geographical distribution limitation excluding
367
+ those countries, so that distribution is permitted only in or among
368
+ countries not thus excluded. In such case, this License incorporates
369
+ the limitation as if written in the body of this License.
370
+
371
+ 9. The Free Software Foundation may publish revised and/or new versions
372
+ of the General Public License from time to time. Such new versions will
373
+ be similar in spirit to the present version, but may differ in detail to
374
+ address new problems or concerns.
375
+
376
+ Each version is given a distinguishing version number. If the Program
377
+ specifies a version number of this License which applies to it and "any
378
+ later version", you have the option of following the terms and conditions
379
+ either of that version or of any later version published by the Free
380
+ Software Foundation. If the Program does not specify a version number of
381
+ this License, you may choose any version ever published by the Free Software
382
+ Foundation.
383
+
384
+ 10. If you wish to incorporate parts of the Program into other free
385
+ programs whose distribution conditions are different, write to the author
386
+ to ask for permission. For software which is copyrighted by the Free
387
+ Software Foundation, write to the Free Software Foundation; we sometimes
388
+ make exceptions for this. Our decision will be guided by the two goals
389
+ of preserving the free status of all derivatives of our free software and
390
+ of promoting the sharing and reuse of software generally.
391
+
392
+ NO WARRANTY
393
+
394
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
395
+ FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
396
+ OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
397
+ PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
398
+ OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
399
+ MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
400
+ TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
401
+ PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
402
+ REPAIR OR CORRECTION.
403
+
404
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
405
+ WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
406
+ REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
407
+ INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
408
+ OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
409
+ TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
410
+ YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
411
+ PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
412
+ POSSIBILITY OF SUCH DAMAGES.
413
+
414
+ END OF TERMS AND CONDITIONS
415
+
416
+ How to Apply These Terms to Your New Programs
417
+
418
+ If you develop a new program, and you want it to be of the greatest
419
+ possible use to the public, the best way to achieve this is to make it
420
+ free software which everyone can redistribute and change under these terms.
421
+
422
+ To do so, attach the following notices to the program. It is safest
423
+ to attach them to the start of each source file to most effectively
424
+ convey the exclusion of warranty; and each file should have at least
425
+ the "copyright" line and a pointer to where the full notice is found.
426
+
427
+ <one line to give the program's name and a brief idea of what it does.>
428
+ Copyright (C) <year> <name of author>
429
+
430
+ This program is free software; you can redistribute it and/or modify
431
+ it under the terms of the GNU General Public License as published by
432
+ the Free Software Foundation; either version 2 of the License, or
433
+ (at your option) any later version.
434
+
435
+ This program is distributed in the hope that it will be useful,
436
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
437
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
438
+ GNU General Public License for more details.
439
+
440
+ You should have received a copy of the GNU General Public License along
441
+ with this program; if not, see <https://www.gnu.org/licenses/>.
442
+
443
+ Also add information on how to contact you by electronic and paper mail.
444
+
445
+ If the program is interactive, make it output a short notice like this
446
+ when it starts in an interactive mode:
447
+
448
+ Gnomovision version 69, Copyright (C) year name of author
449
+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
450
+ This is free software, and you are welcome to redistribute it
451
+ under certain conditions; type `show c' for details.
452
+
453
+ The hypothetical commands `show w' and `show c' should show the appropriate
454
+ parts of the General Public License. Of course, the commands you use may
455
+ be called something other than `show w' and `show c'; they could even be
456
+ mouse-clicks or menu items--whatever suits your program.
457
+
458
+ You should also get your employer (if you work as a programmer) or your
459
+ school, if any, to sign a "copyright disclaimer" for the program, if
460
+ necessary. Here is a sample; alter the names:
461
+
462
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the program
463
+ `Gnomovision' (which makes passes at compilers) written by James Hacker.
464
+
465
+ <signature of Moe Ghoul>, 1 April 1989
466
+ Moe Ghoul, President of Vice
467
+
468
+ This General Public License does not permit incorporating your program into
469
+ proprietary programs. If your program is a subroutine library, you may
470
+ consider it more useful to permit linking proprietary applications with the
471
+ library. If this is what you want to do, use the GNU Lesser General
472
+ Public License instead of this License.
473
+ ```
474
+
54
475
  ## Reference-only cross-checks (no code or data taken)
55
476
 
56
477
  masswerk.at's 6502 instruction-set reference
package/anno-bank.ts ADDED
@@ -0,0 +1,171 @@
1
+ #!/usr/bin/env node
2
+ // anno-bank.ts
3
+ //
4
+ // Phase 37, plan 37-06 (AUTO-04/AUTO-05): the processor-port bit decode, the
5
+ // per-range banked-region resolution, and the region-to-map-entry
6
+ // consistency table `anno-join.ts`'s candidate-constraint step calls BEFORE
7
+ // `selectMemmapEntry()` ever runs. This is the phase's highest-risk
8
+ // requirement pair -- both are recorded UNVALIDATED, not narrowed, and a
9
+ // measured survey found no prior art to copy (SVD-Loader, radare2's
10
+ // device-description import, IDA's device definitions all annotate
11
+ // unconditionally, because their domain has no path-dependent address
12
+ // meaning). Resolve bank state BEFORE the address; decline with a reason
13
+ // where the program itself does not determine one.
14
+ //
15
+ // THIS MODULE NEVER NAMES THE PERSISTENCE DEPENDENCY, NEVER OPENS THE STORE,
16
+ // and NEVER IMPORTS `hostpath.ts`/`containerpath.ts` -- the same posture
17
+ // `memmap-lookup.ts` takes. It takes plain data (a raw `$01` value, a
18
+ // `MemmapEntry`) and returns plain data.
19
+ //
20
+ // WHAT THIS IS THE ONE AUTHORITATIVE PLACE FOR: D-37-21's bit arithmetic
21
+ // (`decodeBankState`), the not-applicable-outside-the-three-ranges rule
22
+ // (`resolveBankedRegion`), the address-is-bank-conditional-at-all membership
23
+ // test (`isBankConditionalAddress`), and the region-to-map-entry consistency
24
+ // table (`regionAdmitsEntry`) `anno-join.ts`'s candidate constraint uses.
25
+ //
26
+ // The REACHING-VALUES SET computation -- which recovered processor-port
27
+ // value(s) reach a given program point, over the recovered const-write facts
28
+ // and the stored cross-reference graph (D-37-24) -- lives in `anno-join.ts`
29
+ // itself, not here. This module only ever decodes a SINGLE already-resolved
30
+ // value; it has no notion of "which value(s) reach this address" and never
31
+ // will (that is the join's own responsibility, since it alone holds the
32
+ // store handle and the cross-reference graph).
33
+ //
34
+ // WHAT NOT TO DO:
35
+ // - Never derive "is this region io/basic/kernal/character-rom" from
36
+ // memmap.json's `desc` field by regex (37-RESEARCH.md Pitfall 2 /
37
+ // `BANK_CONDITIONAL_RANGES`'s own header comment in `memmap-lookup.ts`).
38
+ // `regionAdmitsEntry()` below matches against the STRUCTURED `section`
39
+ // field (plus one whole-word "RAM" label fallback, since no committed
40
+ // section names RAM specifically within any of the three ranges) --
41
+ // never `desc`.
42
+ // - Never default an unresolved region to RAM (the power-on state). The
43
+ // caller (`anno-join.ts`) declines instead; this module only ever
44
+ // returns a decoded/resolved answer or the explicit "not applicable"
45
+ // member -- it never invents a fallback of its own.
46
+ // - Never write the store's reserved `bank` column (D-37-25). This module
47
+ // does not touch the store at all, so that prohibition is satisfied by
48
+ // construction here -- restated because this is the plan that would be
49
+ // tempted.
50
+
51
+ import { BANK_CONDITIONAL_RANGES } from "./memmap-lookup.ts";
52
+ import type { MemmapEntry } from "./memmap-lookup.ts";
53
+
54
+ /**
55
+ * D-37-21: what a bank-conditional range currently contains. `not_applicable`
56
+ * exists so a caller can tell "this address is outside all three
57
+ * bank-conditional ranges" from "the constraint resolved to RAM" -- collapsing
58
+ * the two would make an out-of-range address silently RAM-constrained, which
59
+ * is exactly the confident-wrong-comment failure `AUTO-04` exists to prevent.
60
+ */
61
+ export type BankedRegion = "io_area" | "character_rom" | "ram" | "basic_rom" | "kernal_rom" | "not_applicable";
62
+
63
+ /** The decoded triple, plus the raw value it was decoded from. Each field
64
+ * answers "what does THIS ONE range currently hold", independent of whether
65
+ * the address a caller cares about actually falls inside it -- that mapping
66
+ * is `resolveBankedRegion()`'s job. */
67
+ export interface BankState {
68
+ raw: number;
69
+ ioRange: BankedRegion;
70
+ basicRange: BankedRegion;
71
+ kernalRange: BankedRegion;
72
+ }
73
+
74
+ /**
75
+ * D-37-21's bit arithmetic, stated as bit tests rather than left for a reader
76
+ * to re-derive from `bank.a`'s own inline comment -- which mislabels the
77
+ * all-RAM value's own bit 2 as clear (it is SET; the RAM outcome it states is
78
+ * right anyway, because the RAM case never depends on bit 2). Masks to bits
79
+ * 2-0 FIRST, so two values differing only above bit 2 decode identically --
80
+ * asserted as its own test case rather than merely trusted.
81
+ *
82
+ * - `$D000-$DFFF` (the I/O range): when bits #1-#0 are both clear, the
83
+ * region is RAM regardless of bit #2. Otherwise, bit #2 clear is
84
+ * Character ROM; bit #2 set is the I/O area.
85
+ * - `$A000-$BFFF` (the BASIC range): BASIC ROM only when BOTH bits #1 and
86
+ * #0 are set; otherwise RAM.
87
+ * - `$E000-$FFFF` (the KERNAL range): KERNAL ROM when bit #1 is set;
88
+ * otherwise RAM.
89
+ */
90
+ export function decodeBankState(value: number): BankState {
91
+ const raw = value;
92
+ const b = value & 0x07; // bits #2-#0: CHAREN(2) HIRAM(1) LORAM(0)
93
+ const bits10 = b & 0x03;
94
+ const bit2Set = (b & 0x04) !== 0;
95
+
96
+ const ioRange: BankedRegion = bits10 === 0 ? "ram" : bit2Set ? "io_area" : "character_rom";
97
+ const basicRange: BankedRegion = bits10 === 0x03 ? "basic_rom" : "ram";
98
+ const kernalRange: BankedRegion = (b & 0x02) !== 0 ? "kernal_rom" : "ram";
99
+
100
+ return { raw, ioRange, basicRange, kernalRange };
101
+ }
102
+
103
+ /** Does `address` fall inside ANY of the three bank-conditional ranges,
104
+ * regardless of the current `$01` value? The join uses this to decide
105
+ * whether the whole reaching-values/decline machinery applies to an address
106
+ * at all -- outside these three ranges, bank state is irrelevant and the
107
+ * candidate set stays unconstrained (D-37-22). */
108
+ export function isBankConditionalAddress(address: number): boolean {
109
+ for (const range of BANK_CONDITIONAL_RANGES) {
110
+ if (address >= range.start && address <= range.end) return true;
111
+ }
112
+ return false;
113
+ }
114
+
115
+ /**
116
+ * D-37-22: resolves a single address against an already-decoded `state`,
117
+ * returning the NOT-APPLICABLE member for any address outside all three
118
+ * `BANK_CONDITIONAL_RANGES` -- never RAM. The three ranges are disjoint by
119
+ * construction (each a fixed, hand-maintained, non-overlapping span), so the
120
+ * first (and only) match determines the answer.
121
+ */
122
+ export function resolveBankedRegion(address: number, state: BankState): BankedRegion {
123
+ for (const range of BANK_CONDITIONAL_RANGES) {
124
+ if (address < range.start || address > range.end) continue;
125
+ if (range.start === 0xd000) return state.ioRange;
126
+ if (range.start === 0xa000) return state.basicRange;
127
+ if (range.start === 0xe000) return state.kernalRange;
128
+ }
129
+ return "not_applicable";
130
+ }
131
+
132
+ /**
133
+ * The region-to-map-entry consistency table (D-37-22's candidate constraint,
134
+ * T-37-29's mitigation). Matches the STRUCTURED `section` field, never
135
+ * `desc` (Pitfall 2) -- a small, explicit, hand-maintained keyword set per
136
+ * region, cross-checked against the real committed `memmap.json`'s own
137
+ * section vocabulary (37-RESEARCH.md §C; MEASURED this plan against the
138
+ * real file's `$D000-$DFFF` overlap).
139
+ *
140
+ * RAM has NO dedicated `section` anywhere in the three bank-conditional
141
+ * ranges -- there is nothing chip-specific to document about plain program
142
+ * RAM sitting underneath a ROM/IO window -- so it is matched instead against
143
+ * the entry's own LABEL for a whole-word "RAM" token, which is exactly how
144
+ * the map's own "depends on the processor port" entries describe the RAM
145
+ * alternative (e.g. "I/O Area (memory mapped chip registers), Character ROM
146
+ * or RAM area"; "KERNAL ROM or RAM area"; "BASIC ROM or RAM area").
147
+ */
148
+ const SECTION_MARKERS: Readonly<Record<Exclude<BankedRegion, "ram" | "not_applicable">, readonly string[]>> = Object.freeze({
149
+ io_area: Object.freeze(["I/O Area", "VIC", "SID", "CIA", "Color RAM"]),
150
+ character_rom: Object.freeze(["Character ROM"]),
151
+ basic_rom: Object.freeze(["BASIC ROM"]),
152
+ kernal_rom: Object.freeze(["KERNAL ROM"]),
153
+ });
154
+
155
+ /** Whole-word "RAM" -- deliberately NOT a bare substring match, so a label
156
+ * like "PROGRAM" or "RAMPAGE" (neither of which exists in the committed map
157
+ * today, but the rule should not depend on that) never false-matches. */
158
+ const RAM_LABEL_WORD = /\bRAM\b/;
159
+
160
+ /**
161
+ * Does `entry` represent `region`? `not_applicable` never reaches here -- the
162
+ * join only calls this once a real bank-conditional region has been
163
+ * resolved for a specific address. An entry matching NO region member
164
+ * returns `false`, so the caller's candidate-narrowing EXCLUDES it rather
165
+ * than silently admitting it (D-37-22's own prohibition).
166
+ */
167
+ export function regionAdmitsEntry(entry: MemmapEntry, region: Exclude<BankedRegion, "not_applicable">): boolean {
168
+ if (region === "ram") return RAM_LABEL_WORD.test(entry.label);
169
+ const markers = SECTION_MARKERS[region];
170
+ return typeof entry.section === "string" && markers.some((marker) => entry.section.includes(marker));
171
+ }