fcdev 0.0.0-stage → 0.2.0

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 (294) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +82 -2
  3. package/bin/fcdev.mjs +17 -0
  4. package/package.json +38 -4
  5. package/src/api/header-parser.mjs +78 -0
  6. package/src/api/index.mjs +128 -0
  7. package/src/build/bank-link-config.mjs +74 -0
  8. package/src/build/build-plan.mjs +92 -0
  9. package/src/build/dependency-file.mjs +24 -0
  10. package/src/build/disk-builder.mjs +36 -0
  11. package/src/build/index.mjs +32 -0
  12. package/src/build/program-builder.mjs +212 -0
  13. package/src/build/source-collector.mjs +54 -0
  14. package/src/build/tool-arguments.mjs +83 -0
  15. package/src/cli/args-parser.mjs +84 -0
  16. package/src/cli/commands/api-command.mjs +62 -0
  17. package/src/cli/commands/build-command.mjs +34 -0
  18. package/src/cli/commands/debug-command.mjs +70 -0
  19. package/src/cli/commands/disasm-command.mjs +65 -0
  20. package/src/cli/commands/disk-command.mjs +34 -0
  21. package/src/cli/commands/info-command.mjs +33 -0
  22. package/src/cli/commands/project-info.mjs +57 -0
  23. package/src/cli/commands/run-command.mjs +68 -0
  24. package/src/cli/commands/sync-command.mjs +85 -0
  25. package/src/cli/index.mjs +103 -0
  26. package/src/config/config-loader.mjs +132 -0
  27. package/src/config/index.mjs +9 -0
  28. package/src/disasm/analysis.mjs +97 -0
  29. package/src/disasm/cdl.mjs +35 -0
  30. package/src/disasm/disassembler.mjs +114 -0
  31. package/src/disasm/index.mjs +16 -0
  32. package/src/disasm/info-writer.mjs +72 -0
  33. package/src/disasm/loaders.mjs +69 -0
  34. package/src/disasm/opcode-table.mjs +268 -0
  35. package/src/disasm/roundtrip.mjs +69 -0
  36. package/src/disasm/symbols.mjs +30 -0
  37. package/src/disasm/trace.mjs +25 -0
  38. package/src/emulator/debug-client.mjs +125 -0
  39. package/src/emulator/emulator-launcher.mjs +80 -0
  40. package/src/emulator/emulator-locator.mjs +62 -0
  41. package/src/emulator/index.mjs +11 -0
  42. package/src/packagers/fat-floppy.mjs +22 -0
  43. package/src/packagers/fat12-image.mjs +245 -0
  44. package/src/packagers/flat-binary.mjs +53 -0
  45. package/src/packagers/index.mjs +54 -0
  46. package/src/packagers/ines.mjs +38 -0
  47. package/src/shared/errors.mjs +25 -0
  48. package/src/shared/fs-utils.mjs +66 -0
  49. package/src/shared/index.mjs +11 -0
  50. package/src/shared/process.mjs +50 -0
  51. package/src/targets/index.mjs +17 -0
  52. package/src/targets/name-rules.mjs +33 -0
  53. package/src/targets/target-registry.mjs +225 -0
  54. package/src/toolchain/index.mjs +16 -0
  55. package/src/toolchain/toolchain-locator.mjs +104 -0
  56. package/targets/nes/asminc/fcnes.inc +16 -0
  57. package/targets/nes/chr/ascii-8x8.chr +0 -0
  58. package/targets/nes/chr/font8x8_basic.h +152 -0
  59. package/targets/nes/include/fcnes.h +45 -0
  60. package/targets/nes/lib/fcnes.lib +0 -0
  61. package/targets/nes/lib/nes-font.o +0 -0
  62. package/targets/nes/lib-build.json +9 -0
  63. package/targets/nes/src/fcnes.s +91 -0
  64. package/targets/nes/src/nes-font.s +12 -0
  65. package/targets/nes/target.json +27 -0
  66. package/targets/sb2000/api-reference.md +3295 -0
  67. package/targets/sb2000/api-unwrapped.json +36 -0
  68. package/targets/sb2000/asminc/sb2000.inc +418 -0
  69. package/targets/sb2000/include/sb2000-bank.h +74 -0
  70. package/targets/sb2000/include/sb2000-clock.h +68 -0
  71. package/targets/sb2000/include/sb2000-disk.h +141 -0
  72. package/targets/sb2000/include/sb2000-display.h +352 -0
  73. package/targets/sb2000/include/sb2000-file.h +273 -0
  74. package/targets/sb2000/include/sb2000-ime.h +158 -0
  75. package/targets/sb2000/include/sb2000-input.h +192 -0
  76. package/targets/sb2000/include/sb2000-math.h +228 -0
  77. package/targets/sb2000/include/sb2000-memory.h +115 -0
  78. package/targets/sb2000/include/sb2000-printer.h +116 -0
  79. package/targets/sb2000/include/sb2000-sound.h +134 -0
  80. package/targets/sb2000/include/sb2000-symbols.h +776 -0
  81. package/targets/sb2000/include/sb2000-system.h +219 -0
  82. package/targets/sb2000/include/sb2000-text.h +99 -0
  83. package/targets/sb2000/include/sb2000.h +45 -0
  84. package/targets/sb2000/lib/crt0.o +0 -0
  85. package/targets/sb2000/lib/sb2000.lib +0 -0
  86. package/targets/sb2000/lib-build.json +8 -0
  87. package/targets/sb2000/link-banked.cfg +42 -0
  88. package/targets/sb2000/link.cfg +35 -0
  89. package/targets/sb2000/src/crt0.s +122 -0
  90. package/targets/sb2000/src/lib/bank/sb-bank-current.c +18 -0
  91. package/targets/sb2000/src/lib/bank/sb-bank-select.c +21 -0
  92. package/targets/sb2000/src/lib/bank/sbi-bank-trampoline.s +46 -0
  93. package/targets/sb2000/src/lib/clock/sb-clock-get-date.c +17 -0
  94. package/targets/sb2000/src/lib/clock/sb-clock-get-time.c +17 -0
  95. package/targets/sb2000/src/lib/clock/sb-clock-set-date.c +21 -0
  96. package/targets/sb2000/src/lib/clock/sb-clock-set-time.c +17 -0
  97. package/targets/sb2000/src/lib/clock/sbi-date-from-fat.c +20 -0
  98. package/targets/sb2000/src/lib/clock/sbi-date-to-fat.c +24 -0
  99. package/targets/sb2000/src/lib/clock/sbi-time-from-fat.c +20 -0
  100. package/targets/sb2000/src/lib/clock/sbi-time-to-fat.c +19 -0
  101. package/targets/sb2000/src/lib/disk/sb-disk-format-track.c +18 -0
  102. package/targets/sb2000/src/lib/disk/sb-disk-free-bytes.c +38 -0
  103. package/targets/sb2000/src/lib/disk/sb-disk-init.c +16 -0
  104. package/targets/sb2000/src/lib/disk/sb-disk-read-sector.c +24 -0
  105. package/targets/sb2000/src/lib/disk/sb-disk-read-sectors.c +17 -0
  106. package/targets/sb2000/src/lib/disk/sb-disk-scan-track.c +27 -0
  107. package/targets/sb2000/src/lib/disk/sb-disk-start.c +16 -0
  108. package/targets/sb2000/src/lib/disk/sb-disk-stop.c +16 -0
  109. package/targets/sb2000/src/lib/disk/sb-disk-write-sector.c +19 -0
  110. package/targets/sb2000/src/lib/disk/sb-disk-write-sectors.c +17 -0
  111. package/targets/sb2000/src/lib/disk/sbi-disk-batch.c +23 -0
  112. package/targets/sb2000/src/lib/disk/sbi-disk-call.c +17 -0
  113. package/targets/sb2000/src/lib/disk/sbi-disk-set-position.c +18 -0
  114. package/targets/sb2000/src/lib/display/sb-cell-address.c +20 -0
  115. package/targets/sb2000/src/lib/display/sb-cells-copy.c +27 -0
  116. package/targets/sb2000/src/lib/display/sb-cells-fill.c +25 -0
  117. package/targets/sb2000/src/lib/display/sb-cells-rect.c +20 -0
  118. package/targets/sb2000/src/lib/display/sb-display-mode.c +16 -0
  119. package/targets/sb2000/src/lib/display/sb-glyph-address.c +28 -0
  120. package/targets/sb2000/src/lib/display/sb-image-fill-rect.c +26 -0
  121. package/targets/sb2000/src/lib/display/sb-image-load-raw.c +22 -0
  122. package/targets/sb2000/src/lib/display/sb-image-show-full.c +20 -0
  123. package/targets/sb2000/src/lib/display/sb-image-show.c +25 -0
  124. package/targets/sb2000/src/lib/display/sb-image-unpack-map.c +28 -0
  125. package/targets/sb2000/src/lib/display/sb-image-unpack-tiles.c +20 -0
  126. package/targets/sb2000/src/lib/display/sb-image-unpack-to-memory.c +22 -0
  127. package/targets/sb2000/src/lib/display/sb-palette-write.c +20 -0
  128. package/targets/sb2000/src/lib/display/sb-screen-clear.c +19 -0
  129. package/targets/sb2000/src/lib/display/sb-screen-flush.c +16 -0
  130. package/targets/sb2000/src/lib/display/sb-text-draw.c +22 -0
  131. package/targets/sb2000/src/lib/display/sb-text-field-ascii.c +25 -0
  132. package/targets/sb2000/src/lib/display/sb-text-field.c +25 -0
  133. package/targets/sb2000/src/lib/display/sb-text-to-memory.c +27 -0
  134. package/targets/sb2000/src/lib/display/sb-vram-bank.c +17 -0
  135. package/targets/sb2000/src/lib/display/sb-vram-fill.c +21 -0
  136. package/targets/sb2000/src/lib/display/sb-vram-load.c +21 -0
  137. package/targets/sb2000/src/lib/display/sb-window-compact.c +16 -0
  138. package/targets/sb2000/src/lib/display/sb-window-init.c +16 -0
  139. package/targets/sb2000/src/lib/display/sb-window-restore.c +17 -0
  140. package/targets/sb2000/src/lib/display/sb-window-save.c +21 -0
  141. package/targets/sb2000/src/lib/file/sb-dir-change.c +21 -0
  142. package/targets/sb2000/src/lib/file/sb-dir-current.c +27 -0
  143. package/targets/sb2000/src/lib/file/sb-dir-make.c +21 -0
  144. package/targets/sb2000/src/lib/file/sb-dir-open.c +61 -0
  145. package/targets/sb2000/src/lib/file/sb-dir-read.c +87 -0
  146. package/targets/sb2000/src/lib/file/sb-dir-remove.c +21 -0
  147. package/targets/sb2000/src/lib/file/sb-file-close.c +21 -0
  148. package/targets/sb2000/src/lib/file/sb-file-delete.c +21 -0
  149. package/targets/sb2000/src/lib/file/sb-file-get-attr.c +25 -0
  150. package/targets/sb2000/src/lib/file/sb-file-get-date.c +25 -0
  151. package/targets/sb2000/src/lib/file/sb-file-get-time.c +25 -0
  152. package/targets/sb2000/src/lib/file/sb-file-load.c +50 -0
  153. package/targets/sb2000/src/lib/file/sb-file-open.c +26 -0
  154. package/targets/sb2000/src/lib/file/sb-file-read.c +52 -0
  155. package/targets/sb2000/src/lib/file/sb-file-rename.c +30 -0
  156. package/targets/sb2000/src/lib/file/sb-file-save.c +31 -0
  157. package/targets/sb2000/src/lib/file/sb-file-set-attr.c +22 -0
  158. package/targets/sb2000/src/lib/file/sb-file-set-date.c +25 -0
  159. package/targets/sb2000/src/lib/file/sb-file-set-time.c +22 -0
  160. package/targets/sb2000/src/lib/file/sb-file-size.c +27 -0
  161. package/targets/sb2000/src/lib/file/sb-file-write-all.c +32 -0
  162. package/targets/sb2000/src/lib/file/sb-file-write.c +60 -0
  163. package/targets/sb2000/src/lib/file/sbi-dir-state.c +15 -0
  164. package/targets/sb2000/src/lib/file/sbi-dos-call.c +17 -0
  165. package/targets/sb2000/src/lib/file/sbi-load-sector.c +18 -0
  166. package/targets/sb2000/src/lib/file/sbi-select-handle.c +20 -0
  167. package/targets/sb2000/src/lib/file/sbi-set-path.c +26 -0
  168. package/targets/sb2000/src/lib/ime/sb-ime-get-method.c +17 -0
  169. package/targets/sb2000/src/lib/ime/sb-ime-get-state.c +18 -0
  170. package/targets/sb2000/src/lib/ime/sb-ime-hex.c +20 -0
  171. package/targets/sb2000/src/lib/ime/sb-ime-init.c +26 -0
  172. package/targets/sb2000/src/lib/ime/sb-ime-key-wait.c +19 -0
  173. package/targets/sb2000/src/lib/ime/sb-ime-key.c +19 -0
  174. package/targets/sb2000/src/lib/ime/sb-ime-parse.c +23 -0
  175. package/targets/sb2000/src/lib/ime/sb-ime-resume.c +16 -0
  176. package/targets/sb2000/src/lib/ime/sb-ime-select.c +19 -0
  177. package/targets/sb2000/src/lib/ime/sb-ime-set-state.c +18 -0
  178. package/targets/sb2000/src/lib/ime/sb-ime-set-width.c +16 -0
  179. package/targets/sb2000/src/lib/ime/sb-ime-suspend.c +16 -0
  180. package/targets/sb2000/src/lib/input/sb-break-disable.c +16 -0
  181. package/targets/sb2000/src/lib/input/sb-break-enable.c +16 -0
  182. package/targets/sb2000/src/lib/input/sb-key-count.c +17 -0
  183. package/targets/sb2000/src/lib/input/sb-key-flush.c +16 -0
  184. package/targets/sb2000/src/lib/input/sb-key-init.c +16 -0
  185. package/targets/sb2000/src/lib/input/sb-key-modifiers.c +16 -0
  186. package/targets/sb2000/src/lib/input/sb-key-poll.c +17 -0
  187. package/targets/sb2000/src/lib/input/sb-key-wait.c +17 -0
  188. package/targets/sb2000/src/lib/input/sb-keyboard-reset.c +17 -0
  189. package/targets/sb2000/src/lib/input/sb-mouse-buttons.c +21 -0
  190. package/targets/sb2000/src/lib/input/sb-mouse-position.c +18 -0
  191. package/targets/sb2000/src/lib/input/sb-mouse-reset.c +17 -0
  192. package/targets/sb2000/src/lib/input/sb-mouse-set-double-click.c +17 -0
  193. package/targets/sb2000/src/lib/input/sb-mouse-set-limits.c +26 -0
  194. package/targets/sb2000/src/lib/input/sb-mouse-set-position.c +18 -0
  195. package/targets/sb2000/src/lib/input/sb-pad-init.c +17 -0
  196. package/targets/sb2000/src/lib/input/sb-pad-poll.c +17 -0
  197. package/targets/sb2000/src/lib/input/sb-pad-state.c +16 -0
  198. package/targets/sb2000/src/lib/input/sb-pad-wait.c +17 -0
  199. package/targets/sb2000/src/lib/math/sb-float-add.c +19 -0
  200. package/targets/sb2000/src/lib/math/sb-float-div.c +19 -0
  201. package/targets/sb2000/src/lib/math/sb-float-from-text.c +18 -0
  202. package/targets/sb2000/src/lib/math/sb-float-mul.c +19 -0
  203. package/targets/sb2000/src/lib/math/sb-float-sub.c +19 -0
  204. package/targets/sb2000/src/lib/math/sb-float-to-text.c +19 -0
  205. package/targets/sb2000/src/lib/math/sb-int24-add.c +21 -0
  206. package/targets/sb2000/src/lib/math/sb-int24-div.c +26 -0
  207. package/targets/sb2000/src/lib/math/sb-int24-mul.c +20 -0
  208. package/targets/sb2000/src/lib/math/sb-int24-sub.c +21 -0
  209. package/targets/sb2000/src/lib/math/sb-int40-from-text.c +19 -0
  210. package/targets/sb2000/src/lib/math/sb-int40-to-text.c +27 -0
  211. package/targets/sb2000/src/lib/math/sb-line-step.c +21 -0
  212. package/targets/sb2000/src/lib/math/sb-math-div16.c +27 -0
  213. package/targets/sb2000/src/lib/math/sb-math-time-text.c +21 -0
  214. package/targets/sb2000/src/lib/math/sb-random-next.c +20 -0
  215. package/targets/sb2000/src/lib/math/sb-random-seed.c +19 -0
  216. package/targets/sb2000/src/lib/math/sb-random-warm-up.c +16 -0
  217. package/targets/sb2000/src/lib/math/sbi-peek.c +20 -0
  218. package/targets/sb2000/src/lib/math/sbi-poke.c +20 -0
  219. package/targets/sb2000/src/lib/memory/sb-address-to-far.c +20 -0
  220. package/targets/sb2000/src/lib/memory/sb-far-read-byte.c +17 -0
  221. package/targets/sb2000/src/lib/memory/sb-far-read.c +36 -0
  222. package/targets/sb2000/src/lib/memory/sb-far-write-byte.c +17 -0
  223. package/targets/sb2000/src/lib/memory/sb-far-write.c +36 -0
  224. package/targets/sb2000/src/lib/memory/sb-page-alloc.c +19 -0
  225. package/targets/sb2000/src/lib/memory/sb-page-free.c +19 -0
  226. package/targets/sb2000/src/lib/memory/sb-page-largest-free.c +17 -0
  227. package/targets/sb2000/src/lib/memory/sb-window-map-group.c +17 -0
  228. package/targets/sb2000/src/lib/memory/sb-window-map.c +18 -0
  229. package/targets/sb2000/src/lib/memory/sbi-far-copy-in.s +17 -0
  230. package/targets/sb2000/src/lib/memory/sbi-far-copy-out.s +17 -0
  231. package/targets/sb2000/src/lib/memory/sbi-far-read-byte.s +19 -0
  232. package/targets/sb2000/src/lib/memory/sbi-far-write-byte.s +17 -0
  233. package/targets/sb2000/src/lib/printer/sb-printer-carriage-return.c +16 -0
  234. package/targets/sb2000/src/lib/printer/sb-printer-feed.c +17 -0
  235. package/targets/sb2000/src/lib/printer/sb-printer-graphics-mode.c +16 -0
  236. package/targets/sb2000/src/lib/printer/sb-printer-home.c +16 -0
  237. package/targets/sb2000/src/lib/printer/sb-printer-init-port.c +16 -0
  238. package/targets/sb2000/src/lib/printer/sb-printer-page-left.c +16 -0
  239. package/targets/sb2000/src/lib/printer/sb-printer-page-length.c +17 -0
  240. package/targets/sb2000/src/lib/printer/sb-printer-position.c +18 -0
  241. package/targets/sb2000/src/lib/printer/sb-printer-reset.c +16 -0
  242. package/targets/sb2000/src/lib/printer/sb-printer-send-byte.c +18 -0
  243. package/targets/sb2000/src/lib/printer/sb-printer-text.c +29 -0
  244. package/targets/sb2000/src/lib/sb-internal.h +111 -0
  245. package/targets/sb2000/src/lib/sound/sb-sound-effect-from.c +19 -0
  246. package/targets/sb2000/src/lib/sound/sb-sound-play-from.c +18 -0
  247. package/targets/sb2000/src/lib/sound/sb-sound-play-wav-from.c +18 -0
  248. package/targets/sb2000/src/lib/sound/sb-sound-play-wav.c +16 -0
  249. package/targets/sb2000/src/lib/sound/sb-sound-repeat-wav-from.c +19 -0
  250. package/targets/sb2000/src/lib/sound/sb-sound-status.c +17 -0
  251. package/targets/sb2000/src/lib/sound/sb-sound-stop.c +16 -0
  252. package/targets/sb2000/src/lib/sound/sb-sound-tempo.c +17 -0
  253. package/targets/sb2000/src/lib/sound/sb-sound-transpose.c +17 -0
  254. package/targets/sb2000/src/lib/sound/sb-speech-off.c +16 -0
  255. package/targets/sb2000/src/lib/sound/sb-speech-send-entry-from.c +21 -0
  256. package/targets/sb2000/src/lib/sound/sb-speech-send-from.c +19 -0
  257. package/targets/sb2000/src/lib/sound/sb-speech-send.c +16 -0
  258. package/targets/sb2000/src/lib/system/sb-call-banked.c +19 -0
  259. package/targets/sb2000/src/lib/system/sb-context-restore.c +16 -0
  260. package/targets/sb2000/src/lib/system/sb-context-save.c +19 -0
  261. package/targets/sb2000/src/lib/system/sb-display-off.c +16 -0
  262. package/targets/sb2000/src/lib/system/sb-display-on.c +16 -0
  263. package/targets/sb2000/src/lib/system/sb-display-option.c +18 -0
  264. package/targets/sb2000/src/lib/system/sb-exec.c +22 -0
  265. package/targets/sb2000/src/lib/system/sb-irq-enable.c +19 -0
  266. package/targets/sb2000/src/lib/system/sb-irq-hook-reset.c +20 -0
  267. package/targets/sb2000/src/lib/system/sb-irq-hook-set.c +39 -0
  268. package/targets/sb2000/src/lib/system/sb-irq-mask.c +19 -0
  269. package/targets/sb2000/src/lib/system/sb-jump-banked.s +25 -0
  270. package/targets/sb2000/src/lib/system/sb-nmi-disable.c +16 -0
  271. package/targets/sb2000/src/lib/system/sb-nmi-enable.c +16 -0
  272. package/targets/sb2000/src/lib/system/sb-nmi-hook-reset.c +20 -0
  273. package/targets/sb2000/src/lib/system/sb-nmi-hook-set.c +33 -0
  274. package/targets/sb2000/src/lib/system/sb-nmi-service.c +19 -0
  275. package/targets/sb2000/src/lib/system/sb-stack-pointer.s +18 -0
  276. package/targets/sb2000/src/lib/system/sb-system-init.c +16 -0
  277. package/targets/sb2000/src/lib/system/sb-system-state.c +20 -0
  278. package/targets/sb2000/src/lib/system/sb-wait-frames.s +19 -0
  279. package/targets/sb2000/src/lib/system/sbi-exec-run.s +43 -0
  280. package/targets/sb2000/src/lib/system/sbi-interrupts-off.s +19 -0
  281. package/targets/sb2000/src/lib/system/sbi-interrupts-restore.s +17 -0
  282. package/targets/sb2000/src/lib/text/sb-beep.c +16 -0
  283. package/targets/sb2000/src/lib/text/sb-cursor-column.c +16 -0
  284. package/targets/sb2000/src/lib/text/sb-cursor-left.c +16 -0
  285. package/targets/sb2000/src/lib/text/sb-cursor-right.c +16 -0
  286. package/targets/sb2000/src/lib/text/sb-cursor-row.c +16 -0
  287. package/targets/sb2000/src/lib/text/sb-cursor-set-column.c +18 -0
  288. package/targets/sb2000/src/lib/text/sb-cursor-up.c +16 -0
  289. package/targets/sb2000/src/lib/text/sb-print-hex.c +22 -0
  290. package/targets/sb2000/src/lib/text/sb-print-uint.c +25 -0
  291. package/targets/sb2000/src/lib/text/sb-print.c +35 -0
  292. package/targets/sb2000/src/lib/text/sb-putc.c +26 -0
  293. package/targets/sb2000/src/sb2000.s +64 -0
  294. package/targets/sb2000/target.json +42 -0
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,83 @@
1
- # Temporary Holding Version
1
+ # fcdev
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ 6502 兼容机(NES、小霸王学习机等)的开发工具:用 cc65 把 C 或 ca65 汇编构建成机型对应的程序,带调试用模拟器,并能把已有程序反汇编回 ca65 源码。首批支持 NES 与小霸王学习机 SB2000,更多机型按“目标”扩展。
4
+
5
+ 通常不需要手动安装:用 `npm create fcdev@latest` 创建项目时会自动装好。
6
+
7
+ ## 安装
8
+
9
+ ```bash
10
+ npm install --save-dev fcdev
11
+ ```
12
+
13
+ 要求 Node.js 22 及以上。cc65 编译器与模拟器是分平台的依赖包,npm 会按系统自动安装;目前 cc65 只提供 Windows x64 的包,其他系统可用环境变量 `FCDEV_CC65_HOME` 指向自备的 cc65 目录。模拟器只提供 Windows x64 的包,其他系统可用环境变量 `FCDEV_EMULATOR` 指向自备的模拟器,但调试命令需要该模拟器支持同样的调试服务。
14
+
15
+ ## 使用
16
+
17
+ ```bash
18
+ fcdev build # 构建当前目录;目录里的全部 .c、.s、.asm 链接成一个程序
19
+ fcdev build src # 构建目录 src
20
+ fcdev build src/a.c # 只构建这个文件,它自己是一个程序
21
+ fcdev run src # 构建后在模拟器里运行
22
+ fcdev disk src # 构建后把程序放进磁盘镜像(只有声明了磁盘能力的目标)
23
+ fcdev disasm game.nes # 反汇编成 ca65 源码,并回读校验
24
+ fcdev sync # 生成 IDE 的 C/C++ 配置
25
+ fcdev info --json # 显示目标、工具链与头文件目录
26
+ fcdev api sb_file_open # 查询目标的 C 接口文档(函数名、模块名、$功能号或关键词;不带词列出全部模块)
27
+ ```
28
+
29
+ 入口是 `main`(汇编程序写 `.export _main`)。产物放在项目根的 `build/<目标>/`,中间文件在 `build/obj/`。
30
+
31
+ ### 调试
32
+
33
+ ```bash
34
+ fcdev run --debug --port 5688 src # 以调试模式启动模拟器,只在收到 run 命令时运行
35
+ FCDEV_DEBUG_PORT=5688 fcdev debug run 60
36
+ FCDEV_DEBUG_PORT=5688 fcdev debug shot screen.png
37
+ ```
38
+
39
+ `debug` 把命令原样转发给模拟器的调试服务,命令表见模拟器的说明文档。调试端口默认 5699。
40
+
41
+ ### 反汇编
42
+
43
+ ```bash
44
+ fcdev disasm game.nes # NES(NROM),入口取自中断向量
45
+ fcdev disasm prog.bin --base 8000 --entry 8008 # 平铺二进制:加载地址与入口
46
+ fcdev disasm game.nes --cdl game.cdl --symbols sym.txt # 加 CDL 与符号文件
47
+ ```
48
+
49
+ 用 `da65` 生成源码,再用 `ca65`、`ld65` 重新汇编,与原映像逐字节比较,不一致就报错。只追得到的代码才会按指令输出,其余按数据输出;用 `--cdl`(FCEUX、Mesen 格式)或 `--trace`(模拟器 `trace` 命令的日志)补充运行时才执行到的代码。
50
+
51
+ ## 配置
52
+
53
+ 项目根的 `fcdev.json`,未知的配置项会报错:
54
+
55
+ | 项 | 默认值 | 说明 |
56
+ | --- | --- | --- |
57
+ | `target` | 无,必填 | 目标名:`nes` 或 `sb2000` |
58
+ | `name` | 目录名 | 目录构建时的程序名;SB2000 要符合 DOS 8.3 规则 |
59
+ | `out` | `build` | 输出目录 |
60
+ | `optimize` | `true` | 给 cc65 加优化选项 |
61
+ | `define` | 空 | 预定义宏,值为字符串或数字 |
62
+ | `include` | 空 | 额外的头文件目录 |
63
+ | `toolchain` | 空 | 自备 cc65 的根目录,优先于平台包 |
64
+ | `firmware` | 无 | 固件(BIOS)文件;SB2000 运行时必填,fcdev 不提供任何 BIOS 或 ROM |
65
+ | `emulator` | 空 | 自备模拟器的路径,优先于平台包 |
66
+ | `targetOptions` | 空 | 目标专用选项,如 NES 的 `font`(是否链接 ASCII 字库,默认 `true`)、SB2000 的 `banks`(大程序的库页个数,默认 0) |
67
+
68
+ ## 目标
69
+
70
+ | 目标 | 产物 | 头文件 | 说明 |
71
+ | --- | --- | --- | --- |
72
+ | `nes` | `.nes` | `nes.h`(cc65)、`fcnes.h` | NROM,16K PRG 加 8K CHR;`fcnes.h` 提供调色板、文字显示与等待垂直消隐 |
73
+ | `sb2000` | `.EXE` | `sb2000.h` | 程序从 `$8000` 起装入,默认最大 16K,设 `targetOptions.banks` 后可换页做到约 468K;C 栈在窗口顶端;运行库把 DOS 的系统调用封装成 180 多个 C 函数(文字、键盘手柄鼠标、文件目录、软驱、显示、声音、数学、打印机、输入法等),用 `fcdev api` 查询,整本文档见 `targets/sb2000/api-reference.md` |
74
+
75
+ ## 限制
76
+
77
+ - 反汇编目前只支持 NROM 与平铺二进制;静态追踪追不到 RTS 跳转表等间接调用的代码,这部分按数据输出,回读仍然一致。
78
+ - SB2000 程序的退出码被忽略,`main` 返回后总是回到 DOS。
79
+ - `run` 在非调试模式下沿用模拟器的单实例规则:已有普通的模拟器窗口时,会把程序交给它打开。
80
+
81
+ ## 许可证
82
+
83
+ Apache-2.0。cc65 部分为 zlib 许可,模拟器为 GPL-3.0,各自随平台包附带许可文件。
package/bin/fcdev.mjs ADDED
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env node
2
+ // ------------------------------------------------------------------------
3
+ // 名称:fcdev.mjs
4
+ // 说明:fcdev 命令入口:把终端环境交给 cli,并以其返回值作为退出码。
5
+ // 作者:sungbin
6
+ // 邮箱:sungbin@3578.cn
7
+ // 日期:2026-11-10
8
+ // 备注:只经 src/cli/index.mjs 进入,不直接引用其他目录。
9
+ // ------------------------------------------------------------------------
10
+ import { runCli } from '../src/cli/index.mjs';
11
+
12
+ process.exitCode = await runCli(process.argv.slice(2), {
13
+ cwd: process.cwd(),
14
+ env: process.env,
15
+ stdout: process.stdout,
16
+ stderr: process.stderr,
17
+ });
package/package.json CHANGED
@@ -1,6 +1,40 @@
1
1
  {
2
2
  "name": "fcdev",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.2.0",
4
+ "description": "6502 兼容机(NES、学习机等)的开发工具:用 cc65 构建 C 与汇编程序",
5
+ "license": "Apache-2.0",
6
+ "author": "sungbin <sungbin@3578.cn>",
7
+ "keywords": [
8
+ "6502",
9
+ "nes",
10
+ "famicom",
11
+ "cc65",
12
+ "ca65",
13
+ "sb2000",
14
+ "disassembler"
15
+ ],
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "https://gitee.com/sungbin/fcdev.git",
19
+ "directory": "packages/fcdev"
20
+ },
21
+ "type": "module",
22
+ "engines": {
23
+ "node": ">=22"
24
+ },
25
+ "bin": {
26
+ "fcdev": "bin/fcdev.mjs"
27
+ },
28
+ "scripts": {
29
+ "prepack": "node ../../tools/build-libs.mjs"
30
+ },
31
+ "files": [
32
+ "bin",
33
+ "src",
34
+ "targets"
35
+ ],
36
+ "optionalDependencies": {
37
+ "@rujianjs/fcdev-cc65-win32-x64": "0.2.0",
38
+ "@rujianjs/fcdev-emulator-win32-x64": "0.2.0"
39
+ }
40
+ }
@@ -0,0 +1,78 @@
1
+ // ------------------------------------------------------------------------
2
+ // 名称:header-parser.mjs
3
+ // 说明:解析目标头文件里带文档注释的函数声明:说明、@param、@return、@syscall。
4
+ // 作者:sungbin
5
+ // 邮箱:sungbin@3578.cn
6
+ // 日期:2026-11-11
7
+ // 备注:头文件的文档注释是 C 接口文档的唯一来源,fcdev api 命令、API 参考文档的生成与接口检查都用这个解析器。
8
+ // 注释写法见 targets/sb2000/include/sb2000-file.h:首段是函数说明,@syscall 写对应的系统调用,@param 每个参数一行,@return 写返回值。
9
+ // ------------------------------------------------------------------------
10
+
11
+ /**
12
+ * @typedef {object} ApiFunction
13
+ * @property {string} name 函数名
14
+ * @property {string} header 所在头文件
15
+ * @property {string} signature 声明(不含分号,已压成一行)
16
+ * @property {string} returnType 返回类型文本
17
+ * @property {string[]} params 参数名
18
+ * @property {string} summary 说明首行
19
+ * @property {string} description 说明全文(@ 标签之前的部分,段落用换行连接)
20
+ * @property {string[]} paramDocs 文档里 @param 的参数名
21
+ * @property {Record<string, string>} paramText 每个 @param 的说明
22
+ * @property {boolean} hasReturnDoc 文档里有 @return
23
+ * @property {string} returnText @return 的说明
24
+ * @property {string[]} syscalls 文档里 @syscall 标签的内容
25
+ */
26
+
27
+ /**
28
+ * 解析头文件里带文档注释的函数声明。
29
+ * @param {string} text 头文件内容
30
+ * @param {string} header 头文件名
31
+ * @returns {ApiFunction[]} 函数列表
32
+ */
33
+ export function parseHeaderFunctions(text, header) {
34
+ const pattern = /\/\*\*((?:(?!\*\/)[\s\S])*)\*\/\s*((?:(?!\/\*)[^;{}#])*?\b(sb_\w+)\s*\(([^)]*)\))\s*;/g;
35
+ const functions = [];
36
+ for (const match of text.matchAll(pattern)) {
37
+ const [, rawDoc, declaration, name, rawParams] = match;
38
+ const docLines = rawDoc.split('\n').map((line) => line.replace(/^\s*\*?\s?/, '').trimEnd());
39
+ const params = rawParams.trim() === '' || rawParams.trim() === 'void'
40
+ ? []
41
+ : rawParams.split(',').map((part) => /(\w+)\s*(?:\[[^\]]*\])?\s*$/.exec(part.trim())?.[1] ?? part.trim());
42
+ const firstTag = docLines.findIndex((line) => line.startsWith('@'));
43
+ const descriptionLines = (firstTag < 0 ? docLines : docLines.slice(0, firstTag)).join('\n').trim();
44
+ const paramText = {};
45
+ let returnText = '';
46
+ let current = null;
47
+ for (const line of docLines.slice(Math.max(firstTag, 0))) {
48
+ const paramMatch = /^@param\s+(\w+)\s*(.*)$/.exec(line);
49
+ if (paramMatch) {
50
+ paramText[paramMatch[1]] = paramMatch[2];
51
+ current = { kind: 'param', name: paramMatch[1] };
52
+ } else if (line.startsWith('@return')) {
53
+ returnText = line.slice('@return'.length).trim();
54
+ current = { kind: 'return' };
55
+ } else if (line.startsWith('@')) {
56
+ current = null;
57
+ } else if (current && line.trim() !== '') {
58
+ if (current.kind === 'param') paramText[current.name] += ` ${line.trim()}`;
59
+ else returnText += ` ${line.trim()}`;
60
+ }
61
+ }
62
+ functions.push({
63
+ name,
64
+ header,
65
+ signature: declaration.replace(/\s+/g, ' ').trim(),
66
+ returnType: declaration.slice(0, declaration.indexOf(name)).replace(/__fastcall__/g, '').trim(),
67
+ params,
68
+ summary: docLines.find((line) => line !== '' && !line.startsWith('@')) ?? '',
69
+ description: descriptionLines,
70
+ paramDocs: docLines.filter((line) => line.startsWith('@param ')).map((line) => line.split(/\s+/)[1]),
71
+ paramText,
72
+ hasReturnDoc: docLines.some((line) => line.startsWith('@return')),
73
+ returnText,
74
+ syscalls: docLines.filter((line) => line.startsWith('@syscall ')).map((line) => line.slice('@syscall '.length).trim()),
75
+ });
76
+ }
77
+ return functions;
78
+ }
@@ -0,0 +1,128 @@
1
+ // ------------------------------------------------------------------------
2
+ // 名称:index.mjs
3
+ // 说明:目标的 C 接口文档:从头文件读出函数列表,按名称、模块、系统调用号查询,格式化成文字。
4
+ // 作者:sungbin
5
+ // 邮箱:sungbin@3578.cn
6
+ // 日期:2026-11-11
7
+ // 备注:fcdev api 命令的实现;没有 include 目录或头文件里没有带文档注释的函数的目标,视为没有 API 文档。
8
+ // ------------------------------------------------------------------------
9
+ import { readdirSync, readFileSync } from 'node:fs';
10
+ import path from 'node:path';
11
+ import { parseHeaderFunctions } from './header-parser.mjs';
12
+
13
+ export { parseHeaderFunctions };
14
+
15
+ /**
16
+ * 读出目标全部带文档注释的函数。
17
+ * @param {{dir: string, include: string[]}} target 目标(loadTarget 的结果)
18
+ * @returns {import('./header-parser.mjs').ApiFunction[]} 函数列表,按头文件名与声明顺序
19
+ */
20
+ export function loadTargetApi(target) {
21
+ const functions = [];
22
+ for (const includeDir of target.include) {
23
+ const dir = path.join(target.dir, includeDir);
24
+ let names;
25
+ try {
26
+ names = readdirSync(dir).filter((name) => name.endsWith('.h')).sort();
27
+ } catch {
28
+ continue;
29
+ }
30
+ for (const name of names) {
31
+ functions.push(...parseHeaderFunctions(readFileSync(path.join(dir, name), 'utf8').replace(/\r\n/g, '\n'), name));
32
+ }
33
+ }
34
+ return functions;
35
+ }
36
+
37
+ /**
38
+ * 头文件名对应的模块名:sb2000-file.h 的模块是 file。
39
+ * @param {string} header 头文件名
40
+ * @returns {string} 模块名
41
+ */
42
+ export function moduleOf(header) {
43
+ return header.replace(/^[a-z0-9]+-/, '').replace(/\.h$/, '');
44
+ }
45
+
46
+ /**
47
+ * 按模块分组。
48
+ * @param {import('./header-parser.mjs').ApiFunction[]} functions 函数列表
49
+ * @returns {Map<string, import('./header-parser.mjs').ApiFunction[]>} 模块名到函数列表,保持头文件顺序
50
+ */
51
+ export function groupByModule(functions) {
52
+ const groups = new Map();
53
+ for (const fn of functions) {
54
+ const key = moduleOf(fn.header);
55
+ groups.set(key, [...(groups.get(key) ?? []), fn]);
56
+ }
57
+ return groups;
58
+ }
59
+
60
+ /**
61
+ * 查询函数。依次尝试:函数名完全相同;模块名(file 或 sb2000-file.h);系统调用号(如 $7B、$7B/$09,不分大小写);名称、说明里包含该词。
62
+ * @param {import('./header-parser.mjs').ApiFunction[]} functions 函数列表
63
+ * @param {string} query 查询词
64
+ * @returns {{kind: 'function'|'module'|'syscall'|'text'|'none', matches: import('./header-parser.mjs').ApiFunction[]}} 查询结果
65
+ */
66
+ export function queryApi(functions, query) {
67
+ const word = query.trim();
68
+ const exact = functions.filter((fn) => fn.name === word);
69
+ if (exact.length > 0) return { kind: 'function', matches: exact };
70
+ const moduleName = moduleOf(word.includes('.h') ? word : `x-${word}.h`);
71
+ const byModule = functions.filter((fn) => moduleOf(fn.header) === moduleName);
72
+ if (byModule.length > 0) return { kind: 'module', matches: byModule };
73
+ const lower = word.toLowerCase();
74
+ if (/^\$?[0-9a-f]{2}(\/\$?[0-9a-f]{2})?$/.test(lower)) {
75
+ const [number, sub] = lower.replace(/\$/g, '').split('/');
76
+ const bySyscall = functions.filter((fn) => fn.syscalls.some((tag) => syscallMatches(tag, number, sub)));
77
+ if (bySyscall.length > 0) return { kind: 'syscall', matches: bySyscall };
78
+ }
79
+ const byText = functions.filter((fn) => fn.name.includes(lower) || fn.summary.toLowerCase().includes(lower));
80
+ return { kind: byText.length > 0 ? 'text' : 'none', matches: byText };
81
+ }
82
+
83
+ /**
84
+ * 一个 @syscall 标签是否涉及指定的功能号(与子功能)。标签可以是“$7B/$09”“$30/$04-$07”“$3C、$3D”“$7B/$01、$7B/$06”这样的写法。
85
+ * @param {string} tag 标签内容
86
+ * @param {string} number 功能号,两位十六进制小写
87
+ * @param {string} [sub] 子功能号,两位十六进制小写;省略时只比功能号
88
+ * @returns {boolean} 是否涉及
89
+ */
90
+ export function syscallMatches(tag, number, sub) {
91
+ for (const part of tag.split('、')) {
92
+ const match = /\$([0-9A-Fa-f]{2})(?![0-9A-Fa-f])(?:\/\$([0-9A-Fa-f]{2})(?:-\$([0-9A-Fa-f]{2}))?)?/.exec(part);
93
+ if (!match || match[1].toLowerCase() !== number) continue;
94
+ if (sub === undefined || match[2] === undefined) return true;
95
+ const low = parseInt(match[2], 16);
96
+ const high = match[3] === undefined ? low : parseInt(match[3], 16);
97
+ const wanted = parseInt(sub, 16);
98
+ if (wanted >= low && wanted <= high) return true;
99
+ }
100
+ return false;
101
+ }
102
+
103
+ /**
104
+ * 格式化一个函数的完整文档。
105
+ * @param {import('./header-parser.mjs').ApiFunction} fn 函数
106
+ * @returns {string} 多行文字
107
+ */
108
+ export function formatFunction(fn) {
109
+ const lines = [`${fn.signature};`, ` 所在:${fn.header}`];
110
+ if (fn.syscalls.length > 0) lines.push(` 系统调用:${fn.syscalls.join(';')}`);
111
+ lines.push('', ...fn.description.split('\n').map((line) => ` ${line}`.trimEnd()));
112
+ if (fn.params.length > 0) {
113
+ lines.push('', ' 参数:');
114
+ for (const param of fn.params) lines.push(` ${param} ${fn.paramText[param] ?? ''}`.trimEnd());
115
+ }
116
+ if (fn.hasReturnDoc) lines.push('', ` 返回:${fn.returnText}`);
117
+ return lines.join('\n');
118
+ }
119
+
120
+ /**
121
+ * 格式化函数的一行摘要。
122
+ * @param {import('./header-parser.mjs').ApiFunction} fn 函数
123
+ * @param {number} width 名称列宽
124
+ * @returns {string} 一行文字
125
+ */
126
+ export function formatSummary(fn, width) {
127
+ return ` ${fn.name.padEnd(width)} ${fn.summary}`;
128
+ }
@@ -0,0 +1,74 @@
1
+ // ------------------------------------------------------------------------
2
+ // 名称:bank-link-config.mjs
3
+ // 说明:多页(换页)程序的链接配置:按库页个数把目标的链接配置模板展开成完整的链接配置,并给出这种程序用的打包选项。
4
+ // 作者:sungbin
5
+ // 邮箱:sungbin@3578.cn
6
+ // 日期:2026-11-11
7
+ // 备注:模板里写固定的部分与库页 generatedFrom 之前的库页,%BANK_MEMORY% 与 %BANK_SEGMENTS% 两行分别展开成
8
+ // 库页 generatedFrom 到 N 的内存区与段;定义见 docs/03-目标规范.md 第 2 节的 banked。
9
+ // ------------------------------------------------------------------------
10
+ import { readFileSync, writeFileSync } from 'node:fs';
11
+ import path from 'node:path';
12
+ import { FcdevError } from '../shared/index.mjs';
13
+ import { resolveTargetPath } from '../targets/index.mjs';
14
+
15
+ /** 模板里内存区的展开位置 */
16
+ const MEMORY_MARKER = '%BANK_MEMORY%';
17
+
18
+ /** 模板里段的展开位置 */
19
+ const SEGMENT_MARKER = '%BANK_SEGMENTS%';
20
+
21
+ /**
22
+ * 取程序的库页个数。
23
+ * @param {import('./build-plan.mjs').BuildPlan} plan 构建计划
24
+ * @returns {number} 库页个数;目标不支持多页或选项为 0 时为 0
25
+ */
26
+ export function getBankCount(plan) {
27
+ const { banked } = plan.target;
28
+ return banked ? plan.targetOptions[banked.option] : 0;
29
+ }
30
+
31
+ /**
32
+ * 把模板展开成完整的链接配置。
33
+ * @param {string} template 链接配置模板
34
+ * @param {import('../targets/index.mjs').BankedSpec} banked 目标的多页定义
35
+ * @param {number} count 库页个数
36
+ * @returns {string} 链接配置
37
+ * @throws {FcdevError} 模板里缺少展开位置
38
+ */
39
+ export function expandBankedLinkConfig(template, banked, count) {
40
+ const lines = template.split(/\r?\n/);
41
+ const generate = (pattern) => {
42
+ const generated = [];
43
+ for (let bank = banked.generatedFrom; bank <= count; bank += 1) generated.push(` ${pattern.replaceAll('{n}', String(bank))}`);
44
+ return generated;
45
+ };
46
+ const expand = (marker, pattern) => {
47
+ const index = lines.findIndex((line) => line.trim() === marker);
48
+ if (index < 0) throw new FcdevError(`链接配置模板里缺少 ${marker} 一行`, { code: 'TARGET_INVALID' });
49
+ lines.splice(index, 1, ...generate(pattern));
50
+ };
51
+ expand(MEMORY_MARKER, banked.memory);
52
+ expand(SEGMENT_MARKER, banked.segment);
53
+ return lines.join('\n');
54
+ }
55
+
56
+ /**
57
+ * 确定链接用的配置文件与打包选项:多页程序展开模板并写到中间文件目录,普通程序直接用目标的链接配置。
58
+ * @param {import('./build-plan.mjs').BuildPlan} plan 构建计划
59
+ * @param {string} toolchainHome 工具链根目录
60
+ * @returns {{linkConfig: string, packagerOptions: Record<string, unknown>}} 链接配置的路径与打包选项
61
+ */
62
+ export function resolveLinkSetup(plan, toolchainHome) {
63
+ const { target } = plan;
64
+ const count = getBankCount(plan);
65
+ if (count === 0) {
66
+ return { linkConfig: resolveTargetPath(target, target.linkConfig, toolchainHome), packagerOptions: target.packagerOptions };
67
+ }
68
+ const template = readFileSync(resolveTargetPath(target, target.banked.linkConfig, toolchainHome), 'utf8');
69
+ const linkConfig = path.join(plan.objectDir, `${plan.programName}.cfg`);
70
+ writeFileSync(linkConfig, expandBankedLinkConfig(template, target.banked, count));
71
+ // 多页程序的大小由库页个数决定,不再用单页程序的大小上限检查
72
+ const { maxSize: _unused, ...packagerOptions } = target.packagerOptions;
73
+ return { linkConfig, packagerOptions };
74
+ }