c64bridge 0.9.2 → 0.9.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.
package/AGENTS.md CHANGED
@@ -115,12 +115,17 @@ Tools and parameters are listed dynamically via ListTools.
115
115
  Use ListResources to discover built-in knowledge, then read specific URIs to enrich context before coding:
116
116
 
117
117
  - `c64://basic/spec` — BASIC v2 tokens, syntax, device I/O
118
+ - `c64://basic/rom-routines` — BASIC ROM routines, parser/evaluator helpers, numeric/string machinery
118
119
  - `c64://assembly/6510-spec` — 6510 opcodes, addressing, zero-page strategy
119
120
  - `c64://graphics/vic/spec` — raster timing, sprites, colour RAM, bitmap modes
120
121
  - `c64://sound/sid/spec` — SID registers, waveforms, ADSR
121
122
  - `c64://memory/map` — full 64 KB address map
123
+ - `c64://memory/zero-page-and-workspace` — zero page, stack, page-2 buffers, page-3 vectors
122
124
  - `c64://vice/binary-monitor-spec` — mandatory reference when targeting VICE; covers Binary Monitor transport, command framing, and debugger side effects
123
125
  - `c64://basic/pitfalls` — quoting, line length, token pitfalls
126
+ - `c64://kernal/rom-routines` — KERNAL ROM routines, jump table, vectors, serial/tape/screen services
127
+ - `c64://io/spec` — memory-mapped VIC-II, SID, CIA, colour RAM, and expansion I/O registers
128
+ - `c64://io/cia/spec` — CIA timers, keyboard matrix, serial bus, TOD, IRQ/NMI details
124
129
  - `c64://graphics/petscii/style-guide` — readable PETSCII, colour/dither guidance
125
130
 
126
131
  Pull RAG snippets via `c64_rag` (ops `basic`/`asm`) for targeted examples.
package/README.md CHANGED
@@ -40,6 +40,8 @@ C64 Bridge is listed in the [Official MCP Registry](https://registry.modelcontex
40
40
  - [Configuration Merge Rules](#configuration-merge-rules)
41
41
  - [Backend Configuration: C64 Ultimate](#backend-configuration-c64-ultimate)
42
42
  - [Backend Configuration: VICE](#backend-configuration-vice)
43
+ - [VICE Window Modes](#vice-window-modes)
44
+ - [Recommended VICE Configurations](#recommended-vice-configurations)
43
45
  - [Runtime Backend Switching](#runtime-backend-switching)
44
46
  - [VS Code MCP Setup](#vs-code-mcp-setup)
45
47
  - [Enable the C64 Agent](#enable-the-c64-agent)
@@ -242,7 +244,7 @@ Use this for a C64 Ultimate or Ultimate 64:
242
244
 
243
245
  ### Backend Configuration: VICE
244
246
 
245
- Use this for managed VICE launches:
247
+ C64 Bridge can either connect to an already running VICE Binary Monitor or manage a local VICE process for you. The usual managed setup only needs the emulator binary and, when auto-detection cannot find it, the VICE resource directory:
246
248
 
247
249
  ```json
248
250
  {
@@ -253,9 +255,69 @@ Use this for managed VICE launches:
253
255
  }
254
256
  ```
255
257
 
258
+ - `exe` is optional when `x64sc` or `x64` is on `PATH`. If no explicit binary is configured, the runtime prefers `/usr/local/bin/x64sc` when present, then falls back to `x64sc` or `x64` on `PATH`.
256
259
  - `directory` is optional. When omitted, C64 Bridge auto-detects a VICE resource directory by looking for the standard C64 ROM set near the emulator binary and in common system locations.
257
- - `VICE_BINARY`, `VICE_DIRECTORY`, `VICE_HOST`, `VICE_PORT`, `VICE_VISIBLE`, `VICE_WARP`, and `VICE_ARGS` override managed VICE startup without editing config files.
258
- - If no explicit binary is configured, the runtime prefers `/usr/local/bin/x64sc` when present, then falls back to `x64sc` or `x64` on `PATH` so the same setup remains portable across operating systems.
260
+ - `host` and `port` are optional and default to `127.0.0.1:6502`, the Binary Monitor endpoint C64 Bridge starts for managed local sessions. On local endpoints, C64 Bridge first tries to reuse an already running monitor before starting its own process.
261
+ - `visible`, `warp`, and `args` are optional runtime controls. They can live in JSON config, but most users set their environment-variable equivalents from the MCP client because they are per-session preferences.
262
+ - By default, VICE is started lazily on first access. When setting the environment variable `VICE_PREWARM=1`, C64 Bridge starts or connects VICE in the background during MCP startup.
263
+ - `VICE_BINARY`, `VICE_DIRECTORY`, `VICE_HOST`, `VICE_PORT`, `VICE_VISIBLE`, `VICE_WARP`, `VICE_ARGS`, and `VICE_PREWARM` override the JSON values without editing config files.
264
+
265
+ #### VICE Window Modes
266
+
267
+ Choose the window mode based on where the MCP server runs:
268
+
269
+ | Mode | Configuration | What happens | Use when |
270
+ | --- | --- | --- | --- |
271
+ | Visible | `VICE_VISIBLE=true` | VICE opens a normal desktop window. Warp defaults to off. | You are developing locally and want to watch or interact with the emulator. |
272
+ | Minimized | `VICE_VISIBLE=true`, `VICE_ARGS="-minimized"` | VICE still runs as a normal desktop app, but its window starts iconified. Binary Monitor operations, screen reads, frame capture, and keyboard input continue to work. | You are using an agent locally and do not want the emulator stealing focus, but still want the option to restore the window. |
273
+ | Headless/Xvfb | `VICE_VISIBLE=false` | C64 Bridge launches VICE without a user-facing desktop window, using Xvfb unless disabled. Warp defaults to on. | CI, unattended tests, servers, or any session where no one needs to inspect the emulator window. |
274
+
275
+ Minimized and headless are not the same thing. Minimized is still a visible desktop session with a real VICE window; it is simply hidden by the window manager at startup. Headless/Xvfb has no user-facing window, so it is better for automation but less convenient when you need to debug by looking at the emulator.
276
+
277
+ For normal local MCP use, prefer minimized VICE. It avoids focus stealing while preserving the ability to restore the window for visual inspection. Prefer headless/Xvfb for CI and remote or display-less environments.
278
+
279
+ `FORCE_XVFB=1` forces the Xvfb path even if a graphical session is available. `DISABLE_XVFB=1` disables that fallback and uses the current display, which is mainly useful for troubleshooting display detection.
280
+
281
+ #### Recommended VICE Configurations
282
+
283
+ Local agent session, VICE starts minimized:
284
+
285
+ ```json
286
+ {
287
+ "servers": {
288
+ "c64bridge": {
289
+ "command": "npx",
290
+ "args": ["-y", "c64bridge@latest"],
291
+ "env": {
292
+ "C64_MODE": "vice",
293
+ "VICE_VISIBLE": "true",
294
+ "VICE_ARGS": "-minimized",
295
+ "VICE_WARP": "false"
296
+ }
297
+ }
298
+ }
299
+ }
300
+ ```
301
+
302
+ Headless automation, VICE runs without a visible desktop window:
303
+
304
+ ```json
305
+ {
306
+ "servers": {
307
+ "c64bridge": {
308
+ "command": "npx",
309
+ "args": ["-y", "c64bridge@latest"],
310
+ "env": {
311
+ "C64_MODE": "vice",
312
+ "VICE_VISIBLE": "false",
313
+ "VICE_WARP": "true"
314
+ }
315
+ }
316
+ }
317
+ }
318
+ ```
319
+
320
+ If VICE is installed outside the usual search paths, add `VICE_BINARY` and, if ROM/resource auto-detection fails, `VICE_DIRECTORY` to either example.
259
321
 
260
322
  > [!NOTE]
261
323
  > VICE supports only the operations marked with a VICE checkmark in the [MCP API Reference](#mcp-api-reference). Unsupported operations return `unsupported_platform`.
@@ -356,6 +418,8 @@ You can add `env` entries in `.vscode/mcp.json` to select a config file, overrid
356
418
  - `C64_MODE` forces the initial backend to `c64u` or `vice`
357
419
  - `LOG_LEVEL=debug` enables verbose logging
358
420
 
421
+ For VICE-specific overrides such as `VICE_ARGS=-minimized`, `VICE_VISIBLE=false`, or custom VICE paths, use the patterns in [Backend Configuration: VICE](#backend-configuration-vice).
422
+
359
423
  ### Environment Variables in MCP Client Configs
360
424
 
361
425
  Every runtime environment variable documented in the root [mcp.json](./mcp.json) can be supplied by your MCP client configuration, including `.vscode/mcp.json` under `servers.c64bridge.env`.
@@ -373,7 +437,7 @@ When an environment variable has no JSON config equivalent, the order is:
373
437
 
374
438
  That rule applies uniformly across the documented runtime environment variables below.
375
439
 
376
- Example: visible VICE with a specific ROM or resource directory, plus a hardware fallback that can still be selected instantly at runtime:
440
+ Example: start on minimized VICE with a specific ROM or resource directory, plus a hardware fallback that can still be selected instantly at runtime:
377
441
 
378
442
  ```json
379
443
  {
@@ -389,6 +453,7 @@ Example: visible VICE with a specific ROM or resource directory, plus a hardware
389
453
  "VICE_BINARY": "/usr/local/bin/x64sc",
390
454
  "VICE_DIRECTORY": "/usr/local/share/vice",
391
455
  "VICE_VISIBLE": "true",
456
+ "VICE_ARGS": "-minimized",
392
457
  "VICE_WARP": "false"
393
458
  }
394
459
  }
@@ -451,13 +516,14 @@ Every runtime environment variable documented in `mcp.json` can be set in your M
451
516
  | Variable | Default | JSON Config Key | Description |
452
517
  | --- | --- | --- | --- |
453
518
  | `DISABLE_XVFB` | 0 | — | Set to 1 to disable Xvfb fallback and use the current display only |
454
- | `FORCE_XVFB` | 0 | — | Set to 1 to force managed VICE launches to run under Xvfb |
455
- | `VICE_ARGS` | | vice.args | Extra command-line arguments forwarded to managed VICE launches |
519
+ | `FORCE_XVFB` | 0 | — | Set to 1 to force managed VICE launches to use Xvfb even when a graphical session is detected |
520
+ | `VICE_ARGS` | | vice.args | Extra command-line arguments forwarded to managed VICE launches, such as -minimized for a visible window that starts iconified |
456
521
  | `VICE_BINARY` | x64sc | vice.exe | VICE binary to launch for managed emulator sessions and audio capture; automatic search is used only when this override is missing or invalid |
457
522
  | `VICE_DIRECTORY` | auto-detect | vice.directory | Override the VICE resource directory used for ROM and UI asset discovery; automatic search is used only when this override is missing or invalid |
458
523
  | `VICE_HOST` | 127.0.0.1 | vice.host | Override the VICE Binary Monitor host |
459
524
  | `VICE_PORT` | 6502 | vice.port | Override the VICE Binary Monitor port |
460
- | `VICE_VISIBLE` | true | vice.visible | Launch VICE visibly on the desktop instead of headless/Xvfb when possible |
525
+ | `VICE_PREWARM` | 0 | vice.prewarm | Set to 1 to start/connect VICE in the background during MCP startup; disabled by default so VICE starts lazily on first use |
526
+ | `VICE_VISIBLE` | true | vice.visible | Launch VICE as a desktop window when true; use headless/Xvfb managed launch when false |
461
527
  | `VICE_WARP` | false when visible, true when headless | vice.warp | Enable warp mode for managed VICE sessions |
462
528
  | `VICE_XVFB_DISPLAY` | :99 | — | Display number to use when managed VICE launches under Xvfb |
463
529
 
@@ -578,10 +644,11 @@ The [`./build`](./build) script at the project root wraps all development tasks
578
644
 
579
645
  ## Documentation
580
646
 
581
- - [doc/developer.md](doc/developer.md) — development workflow and RAG details
582
- - [data/context/bootstrap.md](data/context/bootstrap.md) — primer injected ahead of prompts
583
- - [doc/c64u/c64-openapi.yaml](doc/c64u/c64-openapi.yaml) — REST surface (OpenAPI 3.1)
584
- - [AGENTS.md](AGENTS.md) — LLM-facing quick setup, usage, and personas
647
+ - [DeepWiki](https://deepwiki.com/chrisgleissner/c64bridge) - architecture and implementation overview
648
+ - [doc/developer.md](doc/developer.md) - development workflow and RAG details
649
+ - [data/context/bootstrap.md](data/context/bootstrap.md) - primer injected ahead of prompts
650
+ - [doc/c64u/c64-openapi.yaml](doc/c64u/c64-openapi.yaml) - REST surface (OpenAPI 3.1)
651
+ - [AGENTS.md](AGENTS.md) - LLM-facing quick setup, usage, and personas
585
652
 
586
653
  ## Static MCP Interface
587
654
 
@@ -593,7 +660,7 @@ This allows agents to inspect the available tools, resources, prompts, and schem
593
660
 
594
661
  <!-- AUTO-GENERATED:MCP-DOCS-START -->
595
662
 
596
- This MCP server exposes **17 tools**, **26 resources**, and **10 prompts** for controlling your Commodore 64.
663
+ This MCP server exposes **17 tools**, **27 resources**, and **10 prompts** for controlling your Commodore 64.
597
664
 
598
665
  ### Tools
599
666
 
@@ -846,7 +913,8 @@ Grouped entry point for reading and updating selected VICE resources.
846
913
  | `c64://graphics/sprite-charset/best-practices` | Documents sprite and charset workflows, memory layout, VIC-II configuration, common pitfalls, and proven techniques for hardware-accelerated graphics. |
847
914
  | `c64://memory/map` | Page-by-page breakdown of the 64 KB address space with hardware, ROM, and RAM regions. |
848
915
  | `c64://memory/zero-page-and-workspace` | Documents zero-page variables, BASIC pointers, and KERNAL workspace addresses. |
849
- | `c64://kernal/rom-routines` | Lists KERNAL ROM vectors and service routines for OS-level functionality. |
916
+ | `c64://basic/rom-routines` | Maps BASIC ROM landmarks, reusable interpreter routines, numeric helpers, string helpers, and C64-specific BASIC continuation entries. |
917
+ | `c64://kernal/rom-routines` | Maps KERNAL ROM vectors, jump table entries, internal routines, serial/tape/screen services, and reset handlers. |
850
918
  | `c64://io/spec` | Covers VIC-II, SID, CIA, and system control registers with address ranges and usage notes. |
851
919
  | `c64://io/cia/spec` | Details CIA 1/2 registers, timers, interrupts, and keyboard matrix layout. |
852
920
  | `c64://printer/spec` | Covers device setup, control codes, and Ultimate 64 integration for printers. |
@@ -0,0 +1,269 @@
1
+ # C64 BASIC ROM Routines Memory Map — Compact ($A000-$BFFF, $E000-$E4D2)
2
+
3
+ > Purpose: Token-efficient reference for Commodore 64 BASIC V2 ROM routines, tables, parser/evaluator helpers, numeric/string machinery, statement/function dispatch, and C64-specific BASIC continuation code.
4
+ > Format: Address-first tables; **bold** names indicate the most reusable entry points for machine-language or MCP tooling.
5
+ > Conventions: A=Accumulator, X,Y=Index, C=Carry; “—” = not applicable.
6
+ > Related memory maps: `../memory/memory-map.md`, `../memory/low-memory-map.md`, `../kernal/rom-routines.md`, `../io/io-spec.md`.
7
+
8
+ ## Legend
9
+
10
+ Class: A=safe helper, B=usable with guardrails, C=interpreter-coupled, D=non-returning/control-flow, data=table/constant.
11
+
12
+ ## Direct-Use Rules
13
+
14
+ - BASIC ROM must be banked in (`$0001` LORAM+HIRAM set). KERNAL ROM must also be visible for I/O and error reporting.
15
+ - Many failures jump to `$A437` (`ERROR`) rather than returning a status code.
16
+ - Prefer KERNAL APIs for files/devices and dynamic keyboard or tokenized program install for statements.
17
+ - Best reusable BASIC targets: `FRMEVL`, `FRMNUM`, `GETBYT`, `GETADR`, `PTRGET`, `FOUT`, `MOVFM`, `MOVMF`, `LNKPRG`, `CLR`.
18
+ - Avoid direct statement entries unless a wrapper controls `TXTPTR`, stack, BASIC vectors, error recovery, and runtime pointers.
19
+
20
+ ## Essential BASIC State
21
+
22
+ | Address | Decimal | Name | Function | Notes |
23
+ |:--|:--|:--|:--|:--|
24
+ | `$000C` | 12 | DIMFLG | Array allocation/reference flag | Used by `PTRGET`. |
25
+ | `$000D` | 13 | VALTYP | Current type | `$00` numeric, `$FF` string. |
26
+ | `$000E` | 14 | INTFLG | Numeric subtype | `$00` float, `$80` integer. |
27
+ | `$0014–$0015` | 20–21 | LINNUM | Line/address/number temp | Used by `PEEK`, `POKE`, `WAIT`, `SYS`. |
28
+ | `$0016–$0021` | 22–33 | TEMPPT/TEMPST | Temporary string descriptor stack | Three 3-byte descriptors. |
29
+ | `$002B–$002C` | 43–44 | **TXTTAB** | BASIC program start | Normally `$0801`. |
30
+ | `$002D–$002E` | 45–46 | **VARTAB** | Scalar variable table start | Updated after program changes. |
31
+ | `$002F–$0030` | 47–48 | **ARYTAB** | Array table start | Follows scalars. |
32
+ | `$0031–$0032` | 49–50 | **STREND** | End of arrays / free RAM start | Moves upward. |
33
+ | `$0033–$0034` | 51–52 | **FREETOP** | Bottom of string heap | Strings grow downward. |
34
+ | `$0037–$0038` | 55–56 | **MEMSIZ** | BASIC memory top | Lower then `CLR` to reserve RAM. |
35
+ | `$0039–$003A` | 57–58 | CURLIN | Current BASIC line | High byte `$FF` = direct mode. |
36
+ | `$0041–$0042` | 65–66 | DATPTR | Current DATA item pointer | Reset by `RESTORE`. |
37
+ | `$0045–$0048` | 69–72 | VARNAM/VARPNT | Current variable name/value pointer | Set by `PTRGET`. |
38
+ | `$0050–$0052` | 80–82 | DSCPNT | String descriptor pointer/temp | String functions. |
39
+ | `$0061–$0066` | 97–102 | **FAC1** | Primary floating-point accumulator | Exponent, mantissa, sign. |
40
+ | `$0069–$006E` | 105–110 | FAC2/ARG | Secondary FP accumulator | Arithmetic argument. |
41
+ | `$0070` | 112 | FACOV | FP rounding byte | Used by `ROUND`. |
42
+ | `$0073–$008A` | 115–138 | **CHRGET/CHRGOT** | BASIC scanner in zero page | `CHRGOT` entry at `$0079`. |
43
+ | `$007A–$007B` | 122–123 | **TXTPTR** | BASIC text pointer | Parser/evaluator input. |
44
+ | `$008B–$008F` | 139–143 | RNDX | RND seed | Five-byte FP seed. |
45
+ | `$0300–$030B` | 768–779 | BASIC vectors | Error, warm start, tokenize, LIST, execute, evaluate | Copied from `$E447`. |
46
+ | `$030C–$030F` | 780–783 | SYS save | A, X, Y, status for BASIC `SYS` | Restored after SYS returns. |
47
+ | `$0310–$0311` | 784–785 | USR vector | Target for `USR()` | Default illegal quantity. |
48
+
49
+ ## ROM Landmarks
50
+
51
+ | Address | Decimal | Name | Function | Class | Notes |
52
+ |:--|:--|:--|:--|:--|:--|
53
+ | `$A000` | 40960 | Cold vector | Points to `$E394` | data | Do not execute as code. |
54
+ | `$A002` | 40962 | Warm vector | Points to `$E37B` | data | BASIC warm start. |
55
+ | `$A004` | 40964 | CBMBASIC | ROM signature | data | Identification text. |
56
+ | `$A00C` | 40972 | Command table | 35 statement addresses minus 1 | data | Token `$80–$A2`. |
57
+ | `$A052` | 41042 | Function table | 23 function addresses minus 1 | data | Token `$B4–$CA`. |
58
+ | `$A080` | 41088 | Operator table | Precedence + address minus 1 | data | Arithmetic, compare, logical. |
59
+ | `$A09E` | 41118 | Keyword table | Statement keywords | data | High bit marks final char. |
60
+ | `$A129` | 41257 | Reserved-word table | `TAB(`, `TO`, `SPC(`, etc. | data | Tokenizer metadata. |
61
+ | `$A140` | 41280 | Operator keyword table | `+ - * / ^ AND OR > = <` | data | Tokenizer metadata. |
62
+ | `$A14D` | 41293 | Function keyword table | `SGN` through `MID$` | data | Tokenizer metadata. |
63
+ | `$A19E` | 41374 | Error text | BASIC error message strings | data | Indexed by `$A328`. |
64
+ | `$A328` | 41768 | Error pointers | Pointers to error text | data | X = error index. |
65
+ | `$A364` | 41828 | Interpreter text | `OK`, `ERROR IN`, `READY`, `BREAK` | data | Screen messages. |
66
+ | `$BFED` | 49133 | EXP | EXP function body | A/B | Continues at `$E000`. |
67
+ | `$E000–$E4D2` | 57344–58578 | BASIC continuation | EXP/RND/trig, I/O wrappers, init, BASIC vectors | mixed | Located in ROM area often grouped with KERNAL. |
68
+
69
+ ## Core Reusable Entries
70
+
71
+ | Address | Decimal | Name | Function | Args/Input | Output | Class | Notes |
72
+ |:--|:--|:--|:--|:--|:--|:--|:--|
73
+ | `$A533` | 42291 | **LNKPRG** | Relink tokenized BASIC program | Program at `TXTTAB` | Forward links rebuilt | B | Use after raw program writes. |
74
+ | `$A57C` | 42364 | CRUNCH | Tokenize input line | BASIC input-buffer state | Tokenized line | B/C | Easier: use keyboard injection. |
75
+ | `$A613` | 42515 | FNDLIN | Find BASIC line | `LINNUM` target | C set if found | B | Program table must be valid. |
76
+ | `$A65E` | 42590 | **CLR** | Clear variables/runtime/string heap | BASIC pointers valid | Runtime reset | B/C | Use after program/memory-bound changes. |
77
+ | `$A68E` | 42638 | STXTPT | Set text pointer to program start | `TXTTAB` valid | `TXTPTR=TXTTAB-1` | B/C | Prepares interpreter scan. |
78
+ | `$A717` | 42775 | LIST helper | Detokenize through output channel | Program text/current channel | Output text | C | Output-channel dependent. |
79
+ | `$AB1E` | 43806 | **STROUT** | Output zero/quote-terminated string | A/Y pointer | Characters output | B | Current output channel used. |
80
+ | `$AB47` | 43847 | CHR output wrapper | Output PETSCII char | A=byte | Character output | B/C | Prefer KERNAL `CHROUT`. |
81
+ | `$AD8A` | 44426 | **FRMNUM** | Evaluate numeric expression | `TXTPTR` at first char | FAC1 numeric | B | String result -> type error. |
82
+ | `$AD8D` | 44429 | **CHKNUM** | Require numeric result | `VALTYP` | Return or error | A | Type mismatch jumps to error. |
83
+ | `$AD8F` | 44431 | CHKSTR | Require string result | `VALTYP` | Return or error | A | Type mismatch jumps to error. |
84
+ | `$AD90` | 44432 | CHKVAL | Type check by carry | C clear=numeric, set=string | Return or error | A | Helper under `CHKNUM/CHKSTR`. |
85
+ | `$AD9E` | 44446 | **FRMEVL** | Evaluate any expression | `TXTPTR` at first char | FAC1 or string result; `VALTYP` | B | Most useful parser entry. |
86
+ | `$AEF7` | 44791 | CHKCLS | Require `)` | Scanner state | Advances or error | B | Syntax helper. |
87
+ | `$AEFA` | 44794 | CHKOPN | Require `(` | Scanner state | Advances or error | B | Syntax helper. |
88
+ | `$AEFD` | 44797 | CHKCOM | Require `,` | Scanner state | Advances or error | B | Syntax helper. |
89
+ | `$AEFF` | 44799 | SYNCHR | Require char in A | A=required char | Advances or error | B | Syntax helper. |
90
+ | `$B08B` | 45195 | **PTRGET** | Find/create variable | `TXTPTR` at var name | `VARPNT`, Y/A value address | B | May allocate or evaluate subscripts. |
91
+ | `$B1AA` | 45482 | FAC→int | Convert FAC1 to signed 16-bit | FAC1 | A=lo,Y=hi | A/B | Range-sensitive. |
92
+ | `$B391` | 45969 | **GIVAYF** | Signed int to FAC1 | A=hi,Y=lo | FAC1 | A | Values >32767 become negative. |
93
+ | `$B3A2` | 45986 | SNGFLT | Byte to FAC1 | Y=byte | FAC1 | A | Sets numeric result. |
94
+ | `$B487` | 46215 | STRLIT | Create string descriptor from literal | A/Y pointer | Temp string descriptor | B | String heap/temps apply. |
95
+ | `$B4F4` | 46324 | GETSPA | Allocate string space | A=bytes | X/Y pointer | B/C | May garbage collect or error. |
96
+ | `$B526` | 46374 | GARBA2 | Garbage collect string heap | BASIC string state | Compacted strings | C | Avoid unless runtime owned. |
97
+ | `$B6DB` | 46811 | FRETMS | Release temp string | A/Y descriptor | Temp stack updated | B/C | Descriptor discipline matters. |
98
+ | `$B79E` | 47006 | **GETBYT** | Parse byte expression | `TXTPTR` expression | X=`0..255` | B | Illegal quantity on range error. |
99
+ | `$B7EB` | 47083 | **GETNUM** | Parse `addr,byte` | `TXTPTR` expression | `$14/$15`, X=byte | B | Useful for POKE-style syntax. |
100
+ | `$B7F1` | 47089 | COMBYT | Parse comma then byte | Current char comma | X=byte | B | Calls comma check. |
101
+ | `$B7F7` | 47095 | **GETADR** | FAC1 to unsigned address | FAC1 | `$14/$15`, A/Y | A/B | `0..65535`. |
102
+ | `$BBA2` | 48034 | **MOVFM** | Load packed float to FAC1 | A/Y pointer | FAC1 | A/B | Read numeric variable/constant. |
103
+ | `$BBD4` | 48084 | **MOVMF** | Store FAC1 as packed float | X/Y destination, FAC1 | 5 bytes written | A/B | Floating scalar vars. |
104
+ | `$BC1B` | 48155 | ROUND | Round FAC1 | FAC1/FACOV | FAC1 | A | Numeric helper. |
105
+ | `$BC2B` | 48171 | SIGN | Sign of FAC1 | FAC1 | A=`0`,`1`,`$FF` | A | Zero/positive/negative. |
106
+ | `$BDDD` | 48605 | **FOUT** | FAC1 to ASCII | FAC1 | A/Y temp string pointer | A/B | Copy text immediately. |
107
+
108
+ ## Math Helpers
109
+
110
+ | Address | Decimal | Name | Input | Output | Class | Notes |
111
+ |:--|:--|:--|:--|:--|:--|:--|
112
+ | `$BC39` | 48185 | SGN | FAC1 | FAC1 = -1/0/1 | A | Function token `$B4`. |
113
+ | `$BC58` | 48216 | ABS | FAC1 | FAC1 | A | Clears sign. |
114
+ | `$BCCC` | 48332 | INT | FAC1 | FAC1 | A | BASIC floor semantics. |
115
+ | `$B9EA` | 47594 | LOG | FAC1 > 0 | FAC1 | A/B | Domain errors jump to `ERROR`. |
116
+ | `$BF71` | 49009 | SQR | FAC1 >= 0 | FAC1 | A/B | Uses LOG/EXP path. |
117
+ | `$BFB4` | 49076 | NEGOP | FAC1 | -FAC1 | A | Unary negation. |
118
+ | `$BFED` | 49133 | EXP | FAC1 | FAC1 | A/B | Continues at `$E000`; overflow possible. |
119
+ | `$E097` | 57495 | RND | FAC1 argument | FAC1 | A/B | Positive advances, negative seeds, zero mixes time. |
120
+ | `$E264` | 57956 | COS | FAC1 radians | FAC1 | A/B | Adds PI/2, uses SIN. |
121
+ | `$E26B` | 57963 | SIN | FAC1 radians | FAC1 | A/B | Dispatch entry. |
122
+ | `$E2B4` | 58036 | TAN | FAC1 radians | FAC1 | A/B | SIN/COS division. |
123
+ | `$E30E` | 58126 | ATN | FAC1 | FAC1 radians | A/B | Polynomial approximation. |
124
+
125
+ ## Statement Dispatch Entries
126
+
127
+ Statement entries assume live interpreter context unless noted. Prefer text/tokenized program execution over direct calls.
128
+
129
+ | Token | Command | Entry | Class | Direct-use note |
130
+ |:--|:--|:--|:--|:--|
131
+ | `$80` | END | `$A831` | D | Program termination. |
132
+ | `$81` | FOR | `$A742` | C | Requires FOR stack frame. |
133
+ | `$82` | NEXT | `$AD1E` | C | Requires matching FOR frame. |
134
+ | `$83` | DATA | `$A8F8` | C | Statement skipper. |
135
+ | `$84` | INPUT# | `$ABA5` | C | Prefer KERNAL channel I/O. |
136
+ | `$85` | INPUT | `$ABBF` | C | Editor/string context. |
137
+ | `$86` | DIM | `$B081` | C | Allocates arrays. |
138
+ | `$87` | READ | `$AC06` | C | Depends on `DATPTR`. |
139
+ | `$88` | LET | `$A9A5` | C | Prefer `FRMEVL` + `PTRGET` + store helper. |
140
+ | `$89` | GOTO | `$A8A0` | D | Interpreter flow. |
141
+ | `$8A` | RUN | `$A871` | D | Non-local flow. |
142
+ | `$8B` | IF | `$A928` | C | Interpreter-only. |
143
+ | `$8C` | RESTORE | `$A81D` | C | Resets DATA state. |
144
+ | `$8D` | GOSUB | `$A883` | C | Requires BASIC return frame. |
145
+ | `$8E` | RETURN | `$A8D2` | C | Requires GOSUB frame. |
146
+ | `$8F` | REM | `$A93B` | C | Statement skipper. |
147
+ | `$90` | STOP | `$A82F` | D | STOP/BREAK path. |
148
+ | `$91` | ON | `$A94B` | C | Interpreter-only. |
149
+ | `$92` | WAIT | `$B82D` | C | Can hang; avoid for MCP. |
150
+ | `$93` | LOAD | `$E168` | C | Prefer KERNAL `LOAD`. |
151
+ | `$94` | SAVE | `$E156` | C | Prefer KERNAL `SAVE`. |
152
+ | `$95` | VERIFY | `$E165` | C | Prefer KERNAL load/verify. |
153
+ | `$96` | DEF | `$B3B3` | C | DEF FN machinery. |
154
+ | `$97` | POKE | `$B824` | C | Prefer memory write or `GETNUM`. |
155
+ | `$98` | PRINT# | `$AA80` | C | Prefer KERNAL channel output. |
156
+ | `$99` | PRINT | `$AAA0` | C | Output context required. |
157
+ | `$9A` | CONT | `$A857` | D | Requires continuation state. |
158
+ | `$9B` | LIST | `$A69C` | C | Output-channel dependent. |
159
+ | `$9C` | CLR | `$A65E` | B/C | Useful after memory/program edits. |
160
+ | `$9D` | CMD | `$AA86` | C | Prefer KERNAL channel control. |
161
+ | `$9E` | SYS | `$E12A` | C | Parses BASIC `SYS`; direct ML should `JSR/JMP`. |
162
+ | `$9F` | OPEN | `$E1BE` | C | Prefer KERNAL `OPEN`. |
163
+ | `$A0` | CLOSE | `$E1C7` | C | Prefer KERNAL `CLOSE`. |
164
+ | `$A1` | GET | `$AB7B` | C | Assignment/string path. |
165
+ | `$A2` | NEW | `$A642` | D | Destructive. |
166
+
167
+ ## Function Dispatch Entries
168
+
169
+ Function entries are normally called by the evaluator. Direct use is safest for simple FAC1 numeric helpers.
170
+
171
+ | Token | Function | Entry | Class | Direct-use note |
172
+ |:--|:--|:--|:--|:--|
173
+ | `$B4` | SGN | `$BC39` | A | FAC1 in/out. |
174
+ | `$B5` | INT | `$BCCC` | A | FAC1 in/out. |
175
+ | `$B6` | ABS | `$BC58` | A | FAC1 in/out. |
176
+ | `$B7` | USR | `$0310` | C | RAM vector. |
177
+ | `$B8` | FRE | `$B37D` | C | Can trigger GC. |
178
+ | `$B9` | POS | `$B39E` | C | Reads cursor/channel state. |
179
+ | `$BA` | SQR | `$BF71` | A/B | FAC1 non-negative. |
180
+ | `$BB` | RND | `$E097` | A/B | FAC1 argument. |
181
+ | `$BC` | LOG | `$B9EA` | A/B | FAC1 positive. |
182
+ | `$BD` | EXP | `$BFED` | A/B | Overflow possible. |
183
+ | `$BE` | COS | `$E264` | A/B | FAC1 radians. |
184
+ | `$BF` | SIN | `$E26B` | A/B | FAC1 radians. |
185
+ | `$C0` | TAN | `$E2B4` | A/B | FAC1 radians. |
186
+ | `$C1` | ATN | `$E30E` | A/B | FAC1 in/out. |
187
+ | `$C2` | PEEK | `$B80D` | C | Parser convention; ML should `LDA`. |
188
+ | `$C3` | LEN | `$B77C` | C | String argument convention. |
189
+ | `$C4` | STR$ | `$B465` | C | String descriptor result. |
190
+ | `$C5` | VAL | `$B7AD` | C | String parser state. |
191
+ | `$C6` | ASC | `$B78B` | C | Errors on empty string. |
192
+ | `$C7` | CHR$ | `$B6EC` | C | String descriptor result. |
193
+ | `$C8` | LEFT$ | `$B700` | C | String function convention. |
194
+ | `$C9` | RIGHT$ | `$B72C` | C | String function convention. |
195
+ | `$CA` | MID$ | `$B737` | C | String function convention. |
196
+
197
+ ## Operator Dispatch Entries
198
+
199
+ | Operator | Entry | Precedence | Direct-use note |
200
+ |:--|:--|:--|:--|
201
+ | `+` | `$B86A` | `$79` | Prefer `FRMEVL`. |
202
+ | `-` | `$B853` | `$79` | Prefer `FRMEVL`. |
203
+ | `*` | `$BA2B` | `$7B` | Prefer `FRMEVL`. |
204
+ | `/` | `$BB12` | `$7B` | Prefer `FRMEVL`. |
205
+ | `^` | `$BF7B` | `$7D` | Prefer `FRMEVL`. |
206
+ | `AND` | `$AFE9` | low | Evaluator convention. |
207
+ | `OR` | `$AFE6` | low | Evaluator convention. |
208
+ | comparison | `$B016` | compare | Evaluator convention. |
209
+ | unary `-` | `$BFB4` | unary | FAC1 negation is reasonable. |
210
+ | `NOT` | `$AF0D` | unary | Evaluator convention. |
211
+
212
+ ## C64-Specific BASIC Continuation (`$E000–$E4D2`)
213
+
214
+ | Address | Decimal | Name | Function | Class | Notes |
215
+ |:--|:--|:--|:--|:--|:--|
216
+ | `$E000` | 57344 | EXP continuation | Completes EXP from `$BFED` | A/B | Cross-ROM BASIC code. |
217
+ | `$E043` | 57411 | POLY1 | FP polynomial helper | B | FAC1/coefficient state. |
218
+ | `$E059` | 57433 | POLY2 | FP polynomial helper | B | Used by math functions. |
219
+ | `$E08D` | 57485 | RMULC | RND multiply constant | data | Five-byte FP. |
220
+ | `$E092` | 57490 | RADDC | RND add constant | data | Five-byte FP. |
221
+ | `$E097` | 57495 | RND | Random number function | A/B | FAC1 argument. |
222
+ | `$E0F9` | 57593 | BASIC/KERNAL I/O bridge | Checked CHKIN/CHKOUT/CHRIN/CHROUT/GETIN | C/D | May enter BASIC error path. |
223
+ | `$E12A` | 57642 | SYS | BASIC `SYS` parser/executor | C | Uses `$030C–$030F`. |
224
+ | `$E156` | 57686 | SAVE wrapper | BASIC `SAVE` statement | C | Prefer KERNAL API. |
225
+ | `$E165` | 57701 | VERIFY wrapper | BASIC `VERIFY` statement | C | Falls into LOAD path. |
226
+ | `$E168` | 57704 | LOAD wrapper | BASIC `LOAD` statement | C | May relink BASIC program. |
227
+ | `$E1BE` | 57790 | OPEN wrapper | BASIC `OPEN` statement | C | Prefer KERNAL API. |
228
+ | `$E1C7` | 57799 | CLOSE wrapper | BASIC `CLOSE` statement | C | Prefer KERNAL API. |
229
+ | `$E1D4` | 57812 | L/V/S parameter setup | Parse filename/LFN/dev/SA | C | For LOAD/SAVE/VERIFY. |
230
+ | `$E200` | 57856 | Get int to X | Parse comma + integer byte | B/C | Parser helper. |
231
+ | `$E206` | 57862 | Fetch/endline helper | Parser control-flow helper | D | Can unwind caller. |
232
+ | `$E20E` | 57870 | Check comma | Require comma | B/C | Parser helper. |
233
+ | `$E219` | 57881 | O/C parameter setup | Parse OPEN/CLOSE params | C | Sets KERNAL file state. |
234
+ | `$E264` | 57956 | COS | Cosine | A/B | FAC1 radians. |
235
+ | `$E26B` | 57963 | SIN | Sine | A/B | FAC1 radians. |
236
+ | `$E2B4` | 58036 | TAN | Tangent | A/B | FAC1 radians. |
237
+ | `$E30E` | 58126 | ATN | Arctangent | A/B | FAC1 in/out. |
238
+ | `$E37B` | 58235 | Warm BASIC | READY/warm-start path | D | Jump target, not subroutine. |
239
+ | `$E38B` | 58251 | Error message path | Print BASIC error and READY | D | X=error index. |
240
+ | `$E394` | 58260 | Cold BASIC | Power-on BASIC init | D | Reset/init path. |
241
+ | `$E3A2` | 58274 | CHRGET image | Source copied to `$0073` | data | Scanner code image. |
242
+ | `$E3BF` | 58303 | INIT | BASIC zero-page init | C/D | Copies `CHRGET`. |
243
+ | `$E422` | 58402 | Startup messages | Banner and bytes-free output | D | Boot path. |
244
+ | `$E447` | 58439 | BASIC vector table | Defaults for `$0300–$030B` | data | Error, warm, crunch, list, execute, evaluate. |
245
+ | `$E453` | 58451 | Copy BASIC vectors | Restore BASIC RAM vectors | B/C | Mostly init/recovery. |
246
+ | `$E460` | 58464 | Text constants | Startup/message text | data | Constants. |
247
+
248
+ ## Compact Workflows
249
+
250
+ | Need | Preferred mechanism | Minimal sequence |
251
+ |:--|:--|:--|
252
+ | Evaluate expression | `FRMNUM`/`FRMEVL` | Set `TXTPTR` to first char, `JSR $AD8A` or `JSR $AD9E`, handle BASIC errors. |
253
+ | Numeric result as text | `FOUT` | FAC1 ready, `JSR $BDDD`, copy A/Y string immediately. |
254
+ | Parse byte/address syntax | `GETBYT`/`GETADR`/`GETNUM` | Use BASIC-compatible expression text and controlled `TXTPTR`. |
255
+ | Read/write numeric scalar | `PTRGET` + `MOVFM`/`MOVMF` | Set `TXTPTR` to var name; use returned `VARPNT`. |
256
+ | Install tokenized program | Raw write + `LNKPRG` + `CLR` | Write at `TXTTAB`, final next pointer `$0000`, `JSR $A533`, `JSR $A65E`. |
257
+ | Execute BASIC statement | Dynamic keyboard or normal interpreter | Avoid direct statement entries unless runtime/error context is controlled. |
258
+ | Reserve high RAM | Lower `MEMSIZ`, then `CLR` | Update `$37/$38`, `JSR $A65E`; keep ML/sprites above new top. |
259
+
260
+ ## Avoid as General MCP APIs
261
+
262
+ | Entry | Reason |
263
+ |:--|:--|
264
+ | `$A437` | BASIC error path; non-returning for normal callers. |
265
+ | `$A7AE` | Main interpreter loop; full runtime context required. |
266
+ | `$A7ED` | Command dispatcher; token/stack conventions required. |
267
+ | `$E206` | May skip a return address at end-of-statement. |
268
+ | `$E37B`, `$E394` | Warm/cold BASIC entry paths, not subroutines. |
269
+ | Direct string allocation/GC | Safe only when descriptor stack and movable string heap are controlled. |
@@ -33,7 +33,7 @@ Do not assume the current backend is correct without checking
33
33
 
34
34
  ## Memory Map (default RAM layout)
35
35
 
36
- For Full details see `../memory/memory-map.md` with focus on low-memory (pages 0-3) in `../memory/low-memory-map.md` and KERNAL memory in `../memory/kernal-memory-map.md`.
36
+ For full details see `../memory/memory-map.md`. Use `../memory/low-memory-map.md` for zero page/pages 0-3, `../basic/rom-routines.md` for BASIC ROM routines, `../kernal/rom-routines.md` for KERNAL ROM routines, and `../io/io-spec.md` or `../io/cia-spec.md` for hardware registers.
37
37
 
38
38
  - $0000–$00FF: Zero page
39
39
  - $0100–$01FF: Stack
@@ -105,11 +105,11 @@ User‑port mapping for CIA2 PRB and PRA b2 is defined in `io-spec.md` (pin lett
105
105
 
106
106
  - **System I/O (IEC, tape, user/expansion ports, keyboard algorithm):** `io-spec.md`
107
107
  - **Printers:** `data/printer/printer-spec.md`
108
- - **KERNAL vector/entry points:** `data/memory/kernal-api-spec.md`
108
+ - **KERNAL vector/entry points:** `../kernal/rom-routines.md`
109
109
 
110
110
  ---
111
111
 
112
112
  **Provenance:**
113
113
 
114
114
  - [C64 Programmer’s Reference Guide](https://www.zimmers.net/cbmpics/cbm/c64/c64prg.txt)
115
- - [Mapping the C64](https://www.zimmers.net/anonftp/pub/cbm/c64/manuals/mapping-c64_txt)
115
+ - [Mapping the C64](https://www.zimmers.net/anonftp/pub/cbm/c64/manuals/mapping-c64_txt)
@@ -1,8 +1,9 @@
1
- # C64 KERNAL Memory Map — Complete ($E000–$FFFF)
1
+ # C64 KERNAL ROM Routines Memory Map — Complete ($E000–$FFFF)
2
2
 
3
3
  > Purpose: Exhaustive sequential map of KERNAL ROM: callable routines, internal subroutines, constants, tables, IRQ/NMI handlers, and vectors.
4
4
  > Format: One table row per symbol; **bold** names indicate callable/public API (also present in `data/api/kernal-api-spec.md`).
5
5
  > Conventions: A=Accumulator, X,Y=Index, C=Carry; “—” not applicable.
6
+ > Related memory maps: `../memory/memory-map.md`, `../memory/low-memory-map.md`, `../basic/rom-routines.md`, `../io/io-spec.md`.
6
7
 
7
8
  | Address | Decimal | Name | Function | Args | Input | Output | Notes |
8
9
  |:--------|:--------|:-----|:---------|:-----|:------|:-------|:------|
@@ -37,7 +38,7 @@
37
38
  | `$E38B` | 58251 | Error msg | BASIC error/READY printing | X=index | Vector `$0302` next | — | — |
38
39
  | `$E394` | 58260 | Cold BASIC | Power‑on BASIC init | — | — | — | Copies vectors to RAM |
39
40
  | `$E3A2` | 58274 | INITAT | CHRGET text (to $0073) | — | — | — | Moved to ZP |
40
- | `$E3BA` | 59298 | RND seed | Initial RND seed (5‑byte) | — | — | — | Constant |
41
+ | `$E3BA` | 58298 | RND seed | Initial RND seed (5‑byte) | — | — | — | Constant |
41
42
  | `$E3BF` | 58303 | INIT | BASIC ZP init; copy CHRGET | — | — | — | — |
42
43
  | `$E422` | 58402 | Startup msgs | Print banner & BYTES FREE | — | — | — | — |
43
44
  | `$E447` | 58439 | BASIC vec tbl | ROM vector table (→RAM $0300) | — | — | — | — |
@@ -5,6 +5,7 @@
5
5
  > Style: Same compact table schema used in your KERNAL/BASIC specs. **Hex + decimal** addresses. **Bold** = key/callable vectors.
6
6
 
7
7
  > Hints: Zero page gives **1‑byte addressing** → faster code; keep ML temporaries in $FB–$FE. If **tape is unused**, the **cassette buffer $033C–$03FB (828–1019)** is ideal for **small ML helpers** or even **sprite/char data** (e.g., sprite blocks 13 @ $0340–$037F, 14 @ $0380–$03BF). Keyboard buffering enables **“dynamic keyboard”** input injection. Adjust **LORAM/HIRAM/CHAREN** via $0001 for ROM/RAM banking.
8
+ > Related memory maps: `memory-map.md`, `../basic/rom-routines.md`, `../kernal/rom-routines.md`, `../io/io-spec.md`.
8
9
 
9
10
  ## Legend
10
11
 
@@ -2,6 +2,19 @@
2
2
 
3
3
  All addresses are shown as `hex` / `dec`. Group related entries to minimise token usage while keeping lookup simple.
4
4
 
5
+ ## Memory Map Reference Routing
6
+
7
+ Use this quick map to select the narrowest reference before coding or patching memory.
8
+
9
+ | Need | MCP resource | File |
10
+ | --- | --- | --- |
11
+ | Whole 64 KB layout, RAM/ROM/I/O banks, VIC/SID/CIA ranges | `c64://memory/map` | `data/memory/memory-map.md` |
12
+ | Zero page, stack, page-2 buffers, page-3 vectors, cassette buffer | `c64://memory/zero-page-and-workspace` | `data/memory/low-memory-map.md` |
13
+ | BASIC ROM routines, parser/evaluator helpers, variables, strings, token dispatch | `c64://basic/rom-routines` | `data/basic/rom-routines.md` |
14
+ | KERNAL ROM routines, jump table, vectors, serial/tape/screen services | `c64://kernal/rom-routines` | `data/kernal/rom-routines.md` |
15
+ | Hardware register map for VIC-II, SID, CIA, colour RAM, expansion I/O | `c64://io/spec` | `data/io/io-spec.md` |
16
+ | CIA timer, keyboard, serial, TOD, IRQ/NMI register details | `c64://io/cia/spec` | `data/io/cia-spec.md` |
17
+
5
18
  ## Zero Page ($0000-$00FF)
6
19
 
7
20
  | Label | Address | Purpose |