@henols/c64-re-tools 2.1.3 → 2.1.5

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 (37) hide show
  1. package/README.md +3 -3
  2. package/package.json +2 -1
  3. package/skills/c64-assembler/SKILL.md +1 -1
  4. package/skills/c64-assembler/scripts/assembler.ts +2 -2
  5. package/skills/c64-docs/SKILL.md +1 -1
  6. package/skills/c64-docs/scripts/docs.ts +5 -3
  7. package/skills/c64-emulator/SKILL.md +2 -0
  8. package/skills/c64-knowledge/SKILL.md +1 -0
  9. package/skills/c64-memory-map/SKILL.md +1 -1
  10. package/skills/c64-memory-map/scripts/memory-map.ts +4 -2
  11. package/skills/c64-provenance/SKILL.md +1 -1
  12. package/skills/c64-provenance/scripts/lib/compare.ts +12 -0
  13. package/skills/c64-provenance/scripts/lib/library.ts +7 -2
  14. package/skills/c64-provenance/scripts/provenance.ts +13 -7
  15. package/skills/c64-source/SKILL.md +2 -1
  16. package/skills/c64-source/scripts/source.ts +31 -15
  17. package/skills/c64-static-analysis/scripts/lib/findings.ts +24 -2
  18. package/skills/c64-testing/references/scenario-format.md +2 -0
  19. package/skills/c64-testing/scripts/lib/runs.ts +1 -1
  20. package/skills/c64-testing/scripts/lib/scenario.ts +4 -3
  21. package/skills/c64-testing/scripts/testing.ts +1 -1
  22. package/skills/c64-unpacker/SKILL.md +3 -2
  23. package/skills/c64-unpacker/scripts/lib/loads.ts +5 -2
  24. package/src/host/vice/session.ts +22 -2
  25. package/src/host-client/vice-session.ts +3 -3
  26. package/src/knowledge/write.ts +46 -1
  27. package/src/mcp/tools/media.ts +3 -4
  28. package/src/media.ts +3 -0
  29. package/src/native/c64run.ts +1 -1
  30. package/src/native/discover.ts +2 -2
  31. package/src/project.ts +6 -2
  32. package/src/script.ts +9 -1
  33. package/tools/c64run.c +655 -0
  34. package/tools/install-chips.sh +66 -0
  35. package/tools/install-container.sh +61 -0
  36. package/tools/install-dxa.sh +336 -0
  37. package/tools/install-ghidra.sh +40 -0
@@ -0,0 +1,66 @@
1
+ #!/usr/bin/env bash
2
+ # Builds c64run, the replay core of c64-testing: floooh/chips c64.h at a pinned
3
+ # commit with the line-command harness c64run.c next to this script. Installs
4
+ # $PREFIX/bin/c64run and the three C64 ROMs that it loads to
5
+ # $PREFIX/share/c64-re-tools/roms (PREFIX: /usr/local). Debian, Ubuntu, macOS.
6
+
7
+ set -Eeuo pipefail
8
+
9
+ CHIPS_COMMIT="9e88298ce56319953ac7a43213a1120359f7a3a6"
10
+ CHIPS_URL="https://codeload.github.com/floooh/chips/tar.gz/${CHIPS_COMMIT}"
11
+ CHIPS_SHA256="fcae39995f61bfe461175047b11f16d147be0e7353c8a247ac503b5fd3a09b8d"
12
+ # The C64 ROMs from the Commodore firmware archive on zimmers.net, installed
13
+ # under the names that VICE uses (the bytes are the same as VICE's).
14
+ ROM_URL="https://www.zimmers.net/anonftp/pub/cbm/firmware/computers/c64"
15
+ ROMS=(
16
+ "kernal.901227-03.bin kernal-901227-03.bin 83c60d47047d7beab8e5b7bf6f67f80daa088b7a6a27de0d7e016f6484042721"
17
+ "basic.901226-01.bin basic-901226-01.bin 89878cea0a268734696de11c4bae593eaaa506465d2029d619c0e0cbccdfa62d"
18
+ "characters.901225-01.bin chargen-901225-01.bin fd0d53b8480e86163ac98998976c72cc58d5dd8eb824ed7b829774e74213b420"
19
+ )
20
+ PREFIX="${PREFIX:-/usr/local}"
21
+ HERE="$(cd "$(dirname "$0")" && pwd)"
22
+
23
+ fail() {
24
+ printf 'c64run: %s\n' "$*" >&2
25
+ exit 1
26
+ }
27
+
28
+ if [[ "$(id -u)" -eq 0 || -w "${PREFIX}" ]]; then SUDO=""; else SUDO="sudo"; fi
29
+
30
+ CC="${CC:-$(command -v gcc || command -v cc || true)}"
31
+ if [[ -z "${CC}" ]] || ! command -v curl >/dev/null 2>&1; then
32
+ command -v apt-get >/dev/null 2>&1 || fail "a C compiler and curl are needed."
33
+ ${SUDO} apt-get update
34
+ ${SUDO} apt-get install -y --no-install-recommends build-essential ca-certificates curl
35
+ CC=gcc
36
+ fi
37
+
38
+ check() {
39
+ local sum
40
+ if command -v sha256sum >/dev/null 2>&1; then sum="$(sha256sum "$2" | cut -d' ' -f1)"; else sum="$(shasum -a 256 "$2" | cut -d' ' -f1)"; fi
41
+ [[ "${sum}" == "$1" ]]
42
+ }
43
+
44
+ BUILD_DIR="$(mktemp -d -t c64run-build-XXXXXXXX)"
45
+ trap 'rm -rf "${BUILD_DIR}"' EXIT
46
+
47
+ curl -fsSL --retry 3 -o "${BUILD_DIR}/chips.tgz" "${CHIPS_URL}"
48
+ check "${CHIPS_SHA256}" "${BUILD_DIR}/chips.tgz" || fail "the chips archive has the wrong checksum. Refusing to compile it."
49
+ tar -xzf "${BUILD_DIR}/chips.tgz" -C "${BUILD_DIR}"
50
+
51
+ mkdir -p "${BUILD_DIR}/roms"
52
+ for rom in "${ROMS[@]}"; do
53
+ read -r source name sha <<< "${rom}"
54
+ curl -fsSL --retry 3 -o "${BUILD_DIR}/roms/${name}" "${ROM_URL}/${source}"
55
+ check "${sha}" "${BUILD_DIR}/roms/${name}" || fail "the ROM ${name} has the wrong checksum."
56
+ done
57
+
58
+ "${CC}" -O2 -Wall -Wno-unused-function -DCHIPS_COMMIT="\"${CHIPS_COMMIT:0:12}\"" \
59
+ -I "${BUILD_DIR}/chips-${CHIPS_COMMIT}" -o "${BUILD_DIR}/c64run" "${HERE}/c64run.c"
60
+ started="$(printf 'init %s\nquit\n' "${BUILD_DIR}/roms" | "${BUILD_DIR}/c64run")"
61
+ [[ "${started}" == ok*pc=fce2* ]] || fail "the compiled c64run does not reach the reset vector: ${started}"
62
+
63
+ ${SUDO} install -d -m 0755 "${PREFIX}/bin" "${PREFIX}/share/c64-re-tools/roms"
64
+ ${SUDO} install -m 0755 "${BUILD_DIR}/c64run" "${PREFIX}/bin/c64run"
65
+ ${SUDO} install -m 0644 "${BUILD_DIR}"/roms/*.bin "${PREFIX}/share/c64-re-tools/roms/"
66
+ echo "c64run (chips ${CHIPS_COMMIT:0:12}) is installed in ${PREFIX}/bin/c64run, its ROMs in ${PREFIX}/share/c64-re-tools/roms."
@@ -0,0 +1,61 @@
1
+ #!/usr/bin/env bash
2
+ # The native tools of the skill scripts in a Debian or Ubuntu dev container,
3
+ # as root: ACME, dxa, c64run with its C64 ROMs, and Ghidra. The dev container
4
+ # Feature runs the copy of this script that comes with the toolkit version it
5
+ # installs, so the tools and the skills are always of the same version.
6
+ # A tool is installed again only when its install files changed: a stamp in
7
+ # $STAMPS keeps the SHA-256 of the files that installed it.
8
+
9
+ set -Eeuo pipefail
10
+
11
+ HERE="$(cd "$(dirname "$0")" && pwd)"
12
+ STAMPS="/usr/local/share/c64-re-tools/stamps"
13
+
14
+ fail() {
15
+ printf 'c64-re-tools tools: %s\n' "$*" >&2
16
+ exit 1
17
+ }
18
+
19
+ [[ "$(id -u)" -eq 0 ]] || fail "run as root."
20
+ # shellcheck disable=SC1091
21
+ . /etc/os-release
22
+ [[ "${ID:-}" == debian || "${ID:-}" == ubuntu || "${ID_LIKE:-}" == *debian* ]] || fail "only Debian and Ubuntu are supported, not ${ID:-an unknown system}."
23
+
24
+ export DEBIAN_FRONTEND=noninteractive
25
+ APT_UPDATED=""
26
+
27
+ # Installs the packages that are not installed yet.
28
+ packages() {
29
+ local missing=() package
30
+ for package in "$@"; do
31
+ dpkg -s "${package}" > /dev/null 2>&1 || missing+=("${package}")
32
+ done
33
+ [[ ${#missing[@]} -eq 0 ]] && return
34
+ if [[ -z "${APT_UPDATED}" ]]; then
35
+ apt-get update
36
+ APT_UPDATED=1
37
+ fi
38
+ apt-get install -y --no-install-recommends "${missing[@]}"
39
+ }
40
+
41
+ # tool <name> <script> [<file>...]: runs the script when the stamp of the tool
42
+ # is not the SHA-256 of the script and its files.
43
+ tool() {
44
+ local name="$1" sum
45
+ shift
46
+ sum="$(cd "${HERE}" && cat "$@" | sha256sum | cut -d' ' -f1)"
47
+ if [[ "$(cat "${STAMPS}/${name}" 2>/dev/null || true)" == "${sum}" ]]; then
48
+ echo "c64-re-tools tools: ${name} is up to date."
49
+ return
50
+ fi
51
+ bash "${HERE}/$1"
52
+ mkdir -p "${STAMPS}"
53
+ echo "${sum}" > "${STAMPS}/${name}"
54
+ }
55
+
56
+ packages acme unzip curl ca-certificates build-essential
57
+ tool dxa install-dxa.sh
58
+ tool c64run install-chips.sh c64run.c
59
+ tool ghidra install-ghidra.sh
60
+
61
+ [[ -z "${APT_UPDATED}" ]] || rm -rf /var/lib/apt/lists/*
@@ -0,0 +1,336 @@
1
+ #!/usr/bin/env bash
2
+
3
+ set -Eeuo pipefail
4
+
5
+ # ------------------------------------------------------------
6
+ # dxa installer for Debian / Ubuntu
7
+ #
8
+ # Installs:
9
+ # /usr/local/bin/dxa
10
+ # /usr/local/share/man/man1/dxa.1 (if supplied by source)
11
+ #
12
+ # Does NOT install:
13
+ # xa
14
+ # xa65
15
+ #
16
+ # dxa version:
17
+ # 0.1.5
18
+ # ------------------------------------------------------------
19
+
20
+ DXA_VERSION="0.1.5"
21
+
22
+ DXA_ARCHIVE="dxa-${DXA_VERSION}.tar.gz"
23
+
24
+ # The source archive. The upstream site (floodgap.com) is gone; Void Linux keeps the same archive.
25
+ DXA_URL="https://sources.voidlinux.org/dxa-${DXA_VERSION}/${DXA_ARCHIVE}"
26
+
27
+ # Published MD5 from SlackBuilds.
28
+ DXA_MD5="6d69ae1772ed58de97b0180e480dfe0c"
29
+
30
+ PREFIX="/usr/local"
31
+ BIN_DIR="${PREFIX}/bin"
32
+ MAN_DIR="${PREFIX}/share/man/man1"
33
+
34
+ BUILD_DIR=""
35
+
36
+ # ------------------------------------------------------------
37
+ # Helpers
38
+ # ------------------------------------------------------------
39
+
40
+ info()
41
+ {
42
+ printf '\n==> %s\n' "$*"
43
+ }
44
+
45
+ error()
46
+ {
47
+ printf '\nERROR: %s\n' "$*" >&2
48
+ exit 1
49
+ }
50
+
51
+ cleanup()
52
+ {
53
+ if [[ -n "${BUILD_DIR}" && -d "${BUILD_DIR}" ]]; then
54
+ rm -rf "${BUILD_DIR}"
55
+ fi
56
+ }
57
+
58
+ trap cleanup EXIT
59
+
60
+
61
+ # ------------------------------------------------------------
62
+ # Check platform
63
+ # ------------------------------------------------------------
64
+
65
+ if [[ ! -f /etc/os-release ]]; then
66
+ error "This script is intended for Debian/Ubuntu-style Linux systems."
67
+ fi
68
+
69
+ # shellcheck disable=SC1091
70
+ source /etc/os-release
71
+
72
+ case "${ID:-}" in
73
+ debian|ubuntu)
74
+ ;;
75
+ *)
76
+ if [[ "${ID_LIKE:-}" != *debian* ]]; then
77
+ error "Unsupported distribution: ${ID:-unknown}. This script expects Debian or Ubuntu."
78
+ fi
79
+ ;;
80
+ esac
81
+
82
+
83
+ # ------------------------------------------------------------
84
+ # Determine sudo command
85
+ # ------------------------------------------------------------
86
+
87
+ if [[ "$(id -u)" -eq 0 ]]; then
88
+ SUDO=""
89
+ else
90
+ command -v sudo >/dev/null 2>&1 ||
91
+ error "sudo is required when the script is not run as root."
92
+
93
+ SUDO="sudo"
94
+ fi
95
+
96
+
97
+ # ------------------------------------------------------------
98
+ # Show what we're doing
99
+ # ------------------------------------------------------------
100
+
101
+ cat <<EOF
102
+
103
+ dxa installer
104
+ -------------
105
+
106
+ Version: ${DXA_VERSION}
107
+ Install to: ${BIN_DIR}/dxa
108
+
109
+ This script installs dxa only.
110
+ It will NOT install xa or xa65.
111
+
112
+ EOF
113
+
114
+
115
+ # ------------------------------------------------------------
116
+ # Install build requirements
117
+ # ------------------------------------------------------------
118
+
119
+ info "Installing build requirements"
120
+
121
+ ${SUDO} apt-get update
122
+
123
+ ${SUDO} apt-get install -y --no-install-recommends \
124
+ build-essential \
125
+ ca-certificates \
126
+ curl
127
+
128
+
129
+ # ------------------------------------------------------------
130
+ # Create temporary build directory
131
+ # ------------------------------------------------------------
132
+
133
+ BUILD_DIR="$(mktemp -d -t dxa-build-XXXXXXXX)"
134
+
135
+ info "Using temporary build directory: ${BUILD_DIR}"
136
+
137
+ cd "${BUILD_DIR}"
138
+
139
+
140
+ # ------------------------------------------------------------
141
+ # Download dxa
142
+ # ------------------------------------------------------------
143
+
144
+ info "Downloading dxa ${DXA_VERSION}"
145
+
146
+ curl \
147
+ --fail \
148
+ --location \
149
+ --show-error \
150
+ --silent \
151
+ --retry 3 \
152
+ --output "${DXA_ARCHIVE}" \
153
+ "${DXA_URL}"
154
+
155
+
156
+ # ------------------------------------------------------------
157
+ # Verify archive
158
+ # ------------------------------------------------------------
159
+
160
+ info "Verifying downloaded archive"
161
+
162
+ ACTUAL_MD5="$(md5sum "${DXA_ARCHIVE}" | awk '{print $1}')"
163
+
164
+ if [[ "${ACTUAL_MD5}" != "${DXA_MD5}" ]]; then
165
+ echo
166
+ echo "Expected MD5:"
167
+ echo " ${DXA_MD5}"
168
+ echo
169
+ echo "Downloaded MD5:"
170
+ echo " ${ACTUAL_MD5}"
171
+ echo
172
+
173
+ error "Checksum mismatch. Refusing to compile the archive."
174
+ fi
175
+
176
+ echo "Checksum OK."
177
+
178
+
179
+ # ------------------------------------------------------------
180
+ # Extract
181
+ # ------------------------------------------------------------
182
+
183
+ info "Extracting source"
184
+
185
+ tar -xzf "${DXA_ARCHIVE}"
186
+
187
+ SOURCE_DIR="${BUILD_DIR}/dxa-${DXA_VERSION}"
188
+
189
+ if [[ ! -d "${SOURCE_DIR}" ]]; then
190
+ error "Expected source directory not found: ${SOURCE_DIR}"
191
+ fi
192
+
193
+ cd "${SOURCE_DIR}"
194
+
195
+
196
+ # ------------------------------------------------------------
197
+ # Build
198
+ # ------------------------------------------------------------
199
+
200
+ info "Compiling dxa with GCC"
201
+
202
+ make clean >/dev/null 2>&1 || true
203
+
204
+ make CC=gcc
205
+
206
+
207
+ # ------------------------------------------------------------
208
+ # Locate resulting binary
209
+ # ------------------------------------------------------------
210
+
211
+ info "Locating compiled dxa executable"
212
+
213
+ DXA_BINARY=""
214
+
215
+ if [[ -x "${SOURCE_DIR}/dxa" ]]; then
216
+ DXA_BINARY="${SOURCE_DIR}/dxa"
217
+ else
218
+ DXA_BINARY="$(
219
+ find "${SOURCE_DIR}" \
220
+ -maxdepth 3 \
221
+ -type f \
222
+ -name dxa \
223
+ -perm -111 \
224
+ -print \
225
+ -quit
226
+ )"
227
+ fi
228
+
229
+ if [[ -z "${DXA_BINARY}" ]]; then
230
+ error "Compilation completed, but the dxa executable could not be found."
231
+ fi
232
+
233
+ echo "Found:"
234
+ echo " ${DXA_BINARY}"
235
+
236
+
237
+ # ------------------------------------------------------------
238
+ # Basic executable check
239
+ # ------------------------------------------------------------
240
+
241
+ info "Checking compiled binary"
242
+
243
+ if [[ ! -x "${DXA_BINARY}" ]]; then
244
+ error "Compiled dxa binary is not executable."
245
+ fi
246
+
247
+ # dxa -h exits non-zero; its output names the version.
248
+ DXA_HELP="$("${DXA_BINARY}" -h 2>&1 || true)"
249
+
250
+ if [[ "${DXA_HELP}" != *"v${DXA_VERSION} -- symbolic"* ]]; then
251
+ error "The compiled dxa does not run or is not version ${DXA_VERSION}."
252
+ fi
253
+
254
+ echo "Compiled dxa binary runs."
255
+
256
+
257
+ # ------------------------------------------------------------
258
+ # Install binary
259
+ # ------------------------------------------------------------
260
+
261
+ info "Installing dxa"
262
+
263
+ ${SUDO} install -d -m 0755 "${BIN_DIR}"
264
+
265
+ ${SUDO} install \
266
+ -m 0755 \
267
+ "${DXA_BINARY}" \
268
+ "${BIN_DIR}/dxa"
269
+
270
+
271
+ # ------------------------------------------------------------
272
+ # Install man page if supplied
273
+ # ------------------------------------------------------------
274
+
275
+ DXA_MANPAGE="$(
276
+ find "${SOURCE_DIR}" \
277
+ -type f \
278
+ -name 'dxa.1' \
279
+ -print \
280
+ -quit
281
+ )"
282
+
283
+ if [[ -n "${DXA_MANPAGE}" ]]; then
284
+
285
+ info "Installing dxa manual page"
286
+
287
+ ${SUDO} install -d -m 0755 "${MAN_DIR}"
288
+
289
+ ${SUDO} install \
290
+ -m 0644 \
291
+ "${DXA_MANPAGE}" \
292
+ "${MAN_DIR}/dxa.1"
293
+
294
+ if command -v mandb >/dev/null 2>&1; then
295
+ ${SUDO} mandb -q || true
296
+ fi
297
+ else
298
+ echo
299
+ echo "No dxa.1 man page found in the source archive."
300
+ echo "Skipping manual-page installation."
301
+ fi
302
+
303
+
304
+ # ------------------------------------------------------------
305
+ # Verify installation
306
+ # ------------------------------------------------------------
307
+
308
+ info "Verifying installation"
309
+
310
+ if [[ ! -x "${BIN_DIR}/dxa" ]]; then
311
+ error "dxa was not installed correctly."
312
+ fi
313
+
314
+ echo
315
+ echo "Executable:"
316
+ command -v dxa || true
317
+
318
+
319
+ echo
320
+ echo "Installed path:"
321
+ echo " ${BIN_DIR}/dxa"
322
+
323
+
324
+ # ------------------------------------------------------------
325
+ # Check that xa wasn't installed by us
326
+ # ------------------------------------------------------------
327
+
328
+ echo
329
+ echo "------------------------------------------------------------"
330
+ echo "Installation complete"
331
+ echo "------------------------------------------------------------"
332
+ echo
333
+ echo "dxa ${DXA_VERSION} is installed:"
334
+ echo
335
+ echo " ${BIN_DIR}/dxa"
336
+ echo
@@ -0,0 +1,40 @@
1
+ #!/usr/bin/env bash
2
+ # Installs Ghidra in $DEST/ghidra_<version>_PUBLIC (DEST: /opt) and points
3
+ # $DEST/ghidra at it, so that C64RT_GHIDRA=$DEST/ghidra stays the same when
4
+ # the version changes. Removes the Ghidra versions that it installed before.
5
+ # Ghidra needs Java 21. Debian and Ubuntu.
6
+
7
+ set -Eeuo pipefail
8
+
9
+ GHIDRA_VERSION="12.1.3"
10
+ GHIDRA_ZIP="ghidra_${GHIDRA_VERSION}_PUBLIC_20260817.zip"
11
+ GHIDRA_URL="https://github.com/NationalSecurityAgency/ghidra/releases/download/Ghidra_${GHIDRA_VERSION}_build/${GHIDRA_ZIP}"
12
+ GHIDRA_SHA256="93a5d11a9ad510622acaaf908c556a7b9b764d338e78a7567f3689bf5081fd54"
13
+ DEST="${DEST:-/opt}"
14
+ GHIDRA_DIR="${DEST}/ghidra_${GHIDRA_VERSION}_PUBLIC"
15
+
16
+ fail() {
17
+ printf 'Ghidra: %s\n' "$*" >&2
18
+ exit 1
19
+ }
20
+
21
+ [[ "$(id -u)" -eq 0 || -w "${DEST}" ]] || fail "run as root, or set DEST to a folder that you can write."
22
+
23
+ if [[ ! -d "${GHIDRA_DIR}" ]]; then
24
+ BUILD_DIR="$(mktemp -d -t ghidra-XXXXXXXX)"
25
+ trap 'rm -rf "${BUILD_DIR}"' EXIT
26
+ curl -fsSL --retry 3 -o "${BUILD_DIR}/${GHIDRA_ZIP}" "${GHIDRA_URL}"
27
+ echo "${GHIDRA_SHA256} ${BUILD_DIR}/${GHIDRA_ZIP}" | sha256sum -c - > /dev/null || fail "the archive has the wrong checksum."
28
+ unzip -q "${BUILD_DIR}/${GHIDRA_ZIP}" -d "${BUILD_DIR}/unpacked"
29
+ # Ghidra ships its decompiler only for x86-64; on arm64 its own Gradle wrapper builds it.
30
+ if [[ "$(uname -m)" == aarch64 || "$(uname -m)" == arm64 ]]; then
31
+ (cd "${BUILD_DIR}/unpacked/ghidra_${GHIDRA_VERSION}_PUBLIC/support/gradle" && GRADLE_USER_HOME="${BUILD_DIR}/gradle" ./gradlew --no-daemon buildNatives)
32
+ fi
33
+ mv "${BUILD_DIR}/unpacked/ghidra_${GHIDRA_VERSION}_PUBLIC" "${GHIDRA_DIR}"
34
+ fi
35
+
36
+ ln -sfn "${GHIDRA_DIR}" "${DEST}/ghidra"
37
+ for old in "${DEST}"/ghidra_*_PUBLIC; do
38
+ [[ "${old}" == "${GHIDRA_DIR}" || ! -d "${old}" ]] || rm -rf "${old}"
39
+ done
40
+ echo "Ghidra ${GHIDRA_VERSION} is installed in ${GHIDRA_DIR}, and ${DEST}/ghidra points at it."