@henols/c64-re-tools 2.4.0-rc.2 → 2.4.0-rc.4

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 (50) hide show
  1. package/package.json +1 -1
  2. package/skills/c64-assembler/SKILL.md +8 -3
  3. package/skills/c64-assembler/scripts/assembler.ts +6 -16
  4. package/skills/c64-basic/SKILL.md +2 -0
  5. package/skills/c64-disk/SKILL.md +21 -4
  6. package/skills/c64-disk/scripts/disk.ts +43 -3
  7. package/skills/c64-docs/SKILL.md +2 -0
  8. package/skills/c64-docs/scripts/docs.ts +6 -6
  9. package/skills/c64-knowledge/SKILL.md +2 -0
  10. package/skills/c64-memory-map/SKILL.md +2 -0
  11. package/skills/c64-packer/SKILL.md +2 -0
  12. package/skills/c64-provenance/SKILL.md +11 -4
  13. package/skills/c64-provenance/scripts/lib/library.ts +99 -19
  14. package/skills/c64-provenance/scripts/provenance.ts +4 -3
  15. package/skills/c64-reverse-engineering/SKILL.md +3 -3
  16. package/skills/c64-source/SKILL.md +10 -2
  17. package/skills/c64-source/scripts/lib/export.ts +3 -3
  18. package/skills/c64-source/scripts/lib/source.ts +80 -24
  19. package/skills/c64-source/scripts/source.ts +49 -8
  20. package/skills/c64-static-analysis/SKILL.md +3 -1
  21. package/skills/c64-testing/SKILL.md +13 -1
  22. package/skills/c64-testing/references/recording-format.md +5 -1
  23. package/skills/c64-testing/references/scenario-format.md +5 -3
  24. package/skills/c64-testing/scripts/lib/recording.ts +32 -6
  25. package/skills/c64-testing/scripts/lib/runs.ts +13 -7
  26. package/skills/c64-testing/scripts/lib/scenario.ts +13 -6
  27. package/skills/c64-testing/scripts/testing.ts +6 -3
  28. package/skills/c64-unpacker/SKILL.md +2 -0
  29. package/src/host/server.ts +31 -6
  30. package/src/host/tools/c1541.ts +32 -8
  31. package/src/host/vice/binary-monitor.ts +19 -7
  32. package/src/host/vice/session.ts +6 -2
  33. package/src/host-client/connect.ts +12 -2
  34. package/src/host-client/tools.ts +9 -4
  35. package/src/host-client/transfer.ts +58 -4
  36. package/src/host-client/vice-session.ts +10 -3
  37. package/src/knowledge/import.ts +28 -5
  38. package/src/knowledge/write.ts +4 -0
  39. package/src/mcp/main.ts +4 -66
  40. package/src/mcp/session-source.ts +76 -0
  41. package/src/native/acme.ts +45 -12
  42. package/src/native/c64run.ts +1 -1
  43. package/src/native/types.ts +5 -2
  44. package/src/project.ts +58 -1
  45. package/src/protocol/framing.ts +15 -2
  46. package/src/protocol/messages.ts +77 -25
  47. package/src/protocol/tools.ts +33 -4
  48. package/src/protocol/vice.ts +40 -20
  49. package/src/script.ts +11 -6
  50. package/tools/c64run.c +48 -12
package/tools/c64run.c CHANGED
@@ -27,7 +27,7 @@
27
27
  #include "systems/c1541.h"
28
28
  #include "systems/c64.h"
29
29
 
30
- #define C64RUN_PROTOCOL 2
30
+ #define C64RUN_PROTOCOL 3
31
31
  // Keys that chips has no code for: each SHIFT alone, and the up arrow.
32
32
  #define C64RUN_KEY_LSHIFT 0x11
33
33
  #define C64RUN_KEY_RSHIFT 0x12
@@ -73,6 +73,7 @@ static int watch_hit;
73
73
 
74
74
  static int area(uint16_t addr);
75
75
  static int coverage_on, coverage_armed_input;
76
+ static void coverage_start(uint16_t pc);
76
77
 
77
78
  static site_t* site_for(uint16_t pc, uint16_t addr) {
78
79
  for (int i = 0; i < site_count; i++) if (sites[i].pc == pc && sites[i].addr == addr) return &sites[i];
@@ -106,7 +107,7 @@ static void input_read(uint16_t pc, uint16_t addr) {
106
107
  if (replaying) { M6502_SET_DATA(pins, idle_value(addr)); replay_unknown++; }
107
108
  return;
108
109
  }
109
- if (coverage_armed_input && !s->rom) { coverage_armed_input = 0; coverage_on = 1; }
110
+ if (coverage_armed_input && !s->rom) { coverage_armed_input = 0; coverage_start(pc); }
110
111
  const uint64_t index = s->count++;
111
112
  if (replaying) {
112
113
  if (s->nruns == 0) {
@@ -140,7 +141,25 @@ enum { COV_RAM_R = 1, COV_RAM_W = 2, COV_RAM_X = 4, COV_ROM_R = 8, COV_ROM_X = 1
140
141
  static uint8_t coverage[0x10000];
141
142
  // Set by "coverage on-checkpoint": the map starts at the first sample. coverage_armed_input,
142
143
  // set by "coverage on-input": the map starts at the first input read of code in RAM.
143
- static int coverage_armed;
144
+ // coverage_armed_pc, set by "coverage on-pc": the map starts at the first opcode fetch at coverage_pc.
145
+ static int coverage_armed, coverage_armed_pc;
146
+ static uint16_t coverage_pc;
147
+ // Where the map started: the tick and the pc of the instruction ("coverage status").
148
+ static int coverage_started;
149
+ static uint64_t coverage_from_tick;
150
+ static uint16_t coverage_from_pc;
151
+
152
+ static void coverage_start(uint16_t pc) {
153
+ coverage_on = coverage_started = 1;
154
+ coverage_from_tick = ticks;
155
+ coverage_from_pc = pc;
156
+ }
157
+
158
+ // Clears the map and every way that it can start.
159
+ static void coverage_reset(void) {
160
+ memset(coverage, 0, sizeof coverage);
161
+ coverage_on = coverage_armed = coverage_armed_input = coverage_armed_pc = coverage_started = 0;
162
+ }
144
163
 
145
164
  // 0: RAM, 1: ROM, 2: I/O, as the CPU sees the address now (the CPU port bits).
146
165
  static int area(uint16_t addr) {
@@ -205,7 +224,7 @@ static void sample(void) {
205
224
  }
206
225
  fputc('\n', sample_file);
207
226
  samples++;
208
- if (coverage_armed) { coverage_armed = 0; coverage_on = 1; }
227
+ if (coverage_armed) { coverage_armed = 0; coverage_start(sample_pc); }
209
228
  if (sample_stop && samples >= sample_stop) halted = 1;
210
229
  }
211
230
 
@@ -222,6 +241,7 @@ static void tick(void) {
222
241
  if (sync) {
223
242
  last_sync_pc = addr;
224
243
  if (sample_file && addr == sample_pc && decoded) sample();
244
+ if (coverage_armed_pc && addr == coverage_pc && decoded) { coverage_armed_pc = 0; coverage_start(addr); }
225
245
  }
226
246
  if (read && !sync && decoded && sys.io_mapped && (addr & 0xF000) == 0xD000 && input_addr[addr & 0x0FFF]) {
227
247
  input_read(last_sync_pc, addr);
@@ -420,11 +440,10 @@ int main(int argc, char** argv) {
420
440
  halted = 0;
421
441
  sample_stop = 0;
422
442
  maps = 0;
423
- coverage_on = coverage_armed = coverage_armed_input = 0;
443
+ coverage_reset();
424
444
  if (pin_file) { fclose(pin_file); pin_file = NULL; }
425
445
  if (record_file) { fclose(record_file); record_file = NULL; }
426
446
  if (sample_file) { fclose(sample_file); sample_file = NULL; }
427
- memset(coverage, 0, sizeof coverage);
428
447
  const char* problem = init(dir);
429
448
  if (problem) printf("err init: %s\n", problem); else status("ok");
430
449
  } else if (!strcmp(cmd, "quit")) {
@@ -468,6 +487,9 @@ int main(int argc, char** argv) {
468
487
  M6502_SET_DATA(pins, mem_rd(&sys.mem_cpu, pc));
469
488
  m6502_set_pc(&sys.cpu, pc);
470
489
  last_sync_pc = pc;
490
+ // The prefetch is the opcode fetch at pc: it does not pass through tick.
491
+ if (coverage_armed_pc && pc == coverage_pc) { coverage_armed_pc = 0; coverage_start(pc); }
492
+ if (coverage_on) cover(pc, 1, 1);
471
493
  status("ok");
472
494
  } else if (!strcmp(cmd, "run")) {
473
495
  // run <tick>: run to the absolute tick (a tick in the past does nothing)
@@ -617,12 +639,26 @@ int main(int argc, char** argv) {
617
639
  pin_file = fopen(a1, "r");
618
640
  if (pin_file) printf("ok ranges=%d\n", pin_ranges); else printf("err pin: cannot read %s\n", a1);
619
641
  } else if (!strcmp(cmd, "coverage")) {
620
- // coverage on | on-checkpoint | on-input | off | <file>: start now, at the next sample,
621
- // at the first input read of code in RAM; stop; or write the 65536-byte map
622
- if (!strcmp(a1, "on")) { memset(coverage, 0, sizeof coverage); coverage_on = 1; coverage_armed = coverage_armed_input = 0; printf("ok\n"); }
623
- else if (!strcmp(a1, "on-checkpoint")) { memset(coverage, 0, sizeof coverage); coverage_on = coverage_armed_input = 0; coverage_armed = 1; printf("ok\n"); }
624
- else if (!strcmp(a1, "on-input")) { memset(coverage, 0, sizeof coverage); coverage_on = coverage_armed = 0; coverage_armed_input = 1; printf("ok\n"); }
625
- else if (!strcmp(a1, "off")) { coverage_on = coverage_armed = coverage_armed_input = 0; printf("ok\n"); }
642
+ // coverage on | on-checkpoint | on-input | on-pc <pc hex> | off | status | <file>: start
643
+ // now, at the next sample, at the first input read of code in RAM, at the first opcode
644
+ // fetch at pc; stop; where the map started ("ok from tick=<n> pc=<hex>" or "ok
645
+ // not-started"); or write the 65536-byte map
646
+ unsigned pc;
647
+ if (!strcmp(a1, "on")) { coverage_reset(); coverage_start(last_sync_pc); printf("ok\n"); }
648
+ else if (!strcmp(a1, "on-checkpoint")) { coverage_reset(); coverage_armed = 1; printf("ok\n"); }
649
+ else if (!strcmp(a1, "on-input")) { coverage_reset(); coverage_armed_input = 1; printf("ok\n"); }
650
+ else if (!strcmp(a1, "on-pc")) {
651
+ if (sscanf(a2, "%x", &pc) != 1 || pc > 0xFFFF) { printf("err coverage: give on-pc and a pc\n"); continue; }
652
+ coverage_reset();
653
+ coverage_armed_pc = 1;
654
+ coverage_pc = (uint16_t)pc;
655
+ printf("ok\n");
656
+ }
657
+ else if (!strcmp(a1, "off")) { coverage_on = coverage_armed = coverage_armed_input = coverage_armed_pc = 0; printf("ok\n"); }
658
+ else if (!strcmp(a1, "status")) {
659
+ if (coverage_started) printf("ok from tick=%llu pc=%04x\n", (unsigned long long)coverage_from_tick, coverage_from_pc);
660
+ else printf("ok not-started\n");
661
+ }
626
662
  else printf(write_file(a1, coverage, sizeof coverage) ? "ok\n" : "err coverage: cannot write %s\n", a1);
627
663
  } else if (!strcmp(cmd, "palette")) {
628
664
  // palette: the 16 colours as RRGGBB