@henols/c64-re-tools 2.3.0-rc.5 → 2.3.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.
- package/package.json +1 -1
- package/skills/c64-assembler/SKILL.md +149 -78
- package/skills/c64-assembler/scripts/assembler.ts +18 -11
- package/skills/c64-basic/SKILL.md +90 -52
- package/skills/c64-basic/scripts/basic.ts +15 -6
- package/skills/c64-development/SKILL.md +46 -73
- package/skills/c64-disk/SKILL.md +145 -73
- package/skills/c64-disk/scripts/disk.ts +11 -6
- package/skills/c64-docs/SKILL.md +199 -118
- package/skills/c64-docs/references/page-types.md +3 -3
- package/skills/c64-docs/references/style.md +9 -13
- package/skills/c64-docs/scripts/docs.ts +39 -15
- package/skills/c64-docs/scripts/lib/links.ts +1 -1
- package/skills/c64-docs/scripts/lib/reference.ts +2 -2
- package/skills/c64-docs/scripts/lib/source-map.ts +2 -2
- package/skills/c64-export/SKILL.md +21 -45
- package/skills/c64-knowledge/SKILL.md +489 -233
- package/skills/c64-knowledge/scripts/knowledge.ts +31 -26
- package/skills/c64-memory-map/SKILL.md +131 -65
- package/skills/c64-memory-map/scripts/memory-map.ts +19 -11
- package/skills/c64-packer/SKILL.md +120 -72
- package/skills/c64-packer/scripts/packer.ts +10 -3
- package/skills/c64-provenance/SKILL.md +301 -173
- package/skills/c64-provenance/scripts/lib/library.ts +6 -6
- package/skills/c64-provenance/scripts/provenance.ts +85 -36
- package/skills/c64-reverse-engineering/SKILL.md +55 -72
- package/skills/c64-source/SKILL.md +316 -224
- package/skills/c64-source/scripts/lib/export.ts +9 -14
- package/skills/c64-source/scripts/lib/loader.ts +5 -5
- package/skills/c64-source/scripts/lib/source.ts +5 -5
- package/skills/c64-source/scripts/source.ts +106 -21
- package/skills/c64-static-analysis/SKILL.md +188 -112
- package/skills/c64-static-analysis/scripts/static-analysis.ts +29 -9
- package/skills/c64-testing/SKILL.md +272 -166
- package/skills/c64-testing/references/recording-format.md +11 -12
- package/skills/c64-testing/references/scenario-format.md +20 -5
- package/skills/c64-testing/scripts/lib/diff-files.ts +8 -8
- package/skills/c64-testing/scripts/lib/recording.ts +7 -7
- package/skills/c64-testing/scripts/lib/replay.ts +7 -7
- package/skills/c64-testing/scripts/lib/runs.ts +6 -7
- package/skills/c64-testing/scripts/lib/scenario.ts +12 -6
- package/skills/c64-testing/scripts/testing.ts +35 -15
- package/skills/c64-unpacker/SKILL.md +273 -127
- package/skills/c64-unpacker/scripts/lib/loads.ts +3 -3
- package/skills/c64-unpacker/scripts/unpacker.ts +70 -11
- package/skills/emulator/SKILL.md +12 -12
- package/src/errors.ts +22 -2
- package/src/host/vice/session.ts +1 -1
- package/src/host-client/entry-state.ts +1 -1
- package/src/host-client/image.ts +3 -3
- package/src/host-client/steps.ts +1 -1
- package/src/knowledge/expression.ts +1 -1
- package/src/knowledge/names.ts +2 -3
- package/src/knowledge/program.ts +2 -3
- package/src/knowledge/write.ts +2 -2
- package/src/mcp/inputs.ts +1 -1
- package/src/mcp/tools/input.ts +1 -1
- package/src/mcp/tools/media.ts +1 -1
- package/src/native/exomizer.ts +2 -2
- package/src/project.ts +2 -2
- package/src/script.ts +164 -75
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: c64-development
|
|
3
|
-
description:
|
|
3
|
+
description: Writes a new C64 program in 6510 assembly for ACME, or adds a feature or a fix to a program. It builds, runs, debugs and tests the program in small steps, with tests that give PASS or FAIL. It works on source that a person wrote, and on a rebuilt program with switches. Use it when the user asks for a new program, for example "write a game" or "make the border flash". Use it to add a feature or a fix, for example "add a high score" or "fix the sprite flicker". It does not find out what an unknown program does.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
#
|
|
6
|
+
# C64 development
|
|
7
7
|
|
|
8
8
|
## Purpose
|
|
9
9
|
|
|
10
10
|
Coordinate the development of a C64 program: a new program, a new feature or a fix. Make each change in small steps. Prove each step with a test that gives PASS.
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
Do the specialist work of each task as that task tells. Do not do it in another way.
|
|
13
13
|
|
|
14
14
|
## Inputs
|
|
15
15
|
|
|
@@ -17,38 +17,19 @@ This skill does not do the specialist work itself.
|
|
|
17
17
|
- The acceptance checks: what the user must see or what memory must hold when the work is complete.
|
|
18
18
|
- The project: its source, its tests and its knowledge.
|
|
19
19
|
|
|
20
|
-
##
|
|
20
|
+
## Project rules
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
| Work | Skill |
|
|
25
|
-
|---|---|
|
|
26
|
-
| Assemble the source to a PRG, with errors and symbols | c64-assembler |
|
|
27
|
-
| Run, look, debug and measure | emulator |
|
|
28
|
-
| Tests with expected values (`expect` steps in a run), and original against rebuild | c64-testing |
|
|
29
|
-
| The meaning of an address or a register, and an include of the platform names | c64-memory-map |
|
|
30
|
-
| Patches and switches of a rebuilt program, names and comments | c64-knowledge |
|
|
31
|
-
| The source of a rebuilt program | c64-source |
|
|
32
|
-
| Ranges that a rebuilt program does not use | c64-provenance |
|
|
33
|
-
| Documentation | c64-docs |
|
|
34
|
-
|
|
35
|
-
### Project folder
|
|
36
|
-
|
|
37
|
-
One repository can hold several programs, with one project folder for each program. A project folder holds `.c64-re-tools/`. Work on one project at a time:
|
|
38
|
-
|
|
39
|
-
- From the root of the repository, give `--project <folder>` to each skill script, and `project` to each emulator tool with a path.
|
|
22
|
+
- One repository can hold several programs, with one project folder for each program. Work on one project at a time.
|
|
40
23
|
- Write all files in the project folder. Do not write files at the root of the repository.
|
|
41
|
-
- Write each file that you make for your work in `.c64-re-tools/local/` of the project. Git ignores that folder. Examples are results, step files, snapshots and memory dumps.
|
|
42
24
|
- Keep the run files that are tests in `tests/`. Git keeps them.
|
|
43
|
-
- Write the knowledge only with the c64-knowledge script. Do not write or edit the files in `.c64-re-tools/knowledge/` yourself.
|
|
44
25
|
|
|
45
26
|
## Workflow
|
|
46
27
|
|
|
47
28
|
First select the path:
|
|
48
29
|
|
|
49
30
|
- The project has no program yet: path A.
|
|
50
|
-
- The program has source that a person wrote: path B. A project
|
|
51
|
-
- The source comes from
|
|
31
|
+
- The program has source that a person wrote: path B. A project that an export of a rebuilt program made also takes path B.
|
|
32
|
+
- The source comes from a generation from the project knowledge: path C. Such a source has `main.asm` and `source-map.json`. Do not edit this source. The next generation of the source writes over it.
|
|
52
33
|
|
|
53
34
|
### Acceptance checks
|
|
54
35
|
|
|
@@ -59,7 +40,7 @@ Before you write code, write the acceptance checks. If the request does not give
|
|
|
59
40
|
- the border color in a frame
|
|
60
41
|
- the address of the main loop.
|
|
61
42
|
|
|
62
|
-
|
|
43
|
+
Put a check that only a person can judge, for example smooth animation, into a test checklist.
|
|
63
44
|
|
|
64
45
|
### A. A new program
|
|
65
46
|
|
|
@@ -67,12 +48,12 @@ Use this layout. No script makes it.
|
|
|
67
48
|
|
|
68
49
|
```
|
|
69
50
|
src/ the source, with src/main.a as the entry
|
|
70
|
-
build/ programs and symbol files
|
|
51
|
+
build/ the built programs and their symbol files
|
|
71
52
|
tests/ run files with expect steps
|
|
72
53
|
docs/ the documentation, when the user asks for it
|
|
73
54
|
```
|
|
74
55
|
|
|
75
|
-
Start the program with a BASIC line
|
|
56
|
+
Start the program with a BASIC line. Then an autostart in the emulator and a test run can start it:
|
|
76
57
|
|
|
77
58
|
```
|
|
78
59
|
* = $0801
|
|
@@ -85,51 +66,51 @@ start ; $080d = 2061
|
|
|
85
66
|
|
|
86
67
|
Do these steps for each small part of the program:
|
|
87
68
|
|
|
88
|
-
1. Find the meaning of each register
|
|
69
|
+
1. Find the meaning of each register in the memory map of the C64. Export the platform names as an include file to `src/hw.a`. Include it with `!source`. Do not type the addresses of registers yourself.
|
|
89
70
|
2. Write the code for one part.
|
|
90
|
-
3.
|
|
91
|
-
4. Start
|
|
92
|
-
5. Write the `expect` steps of this part in a run file. Give `
|
|
93
|
-
6. Run all run files in `tests
|
|
71
|
+
3. Assemble `src/main.a` into `build/<name>.prg`, with the symbols in `build/<name>.json`. Change the source at the file and the line of each error.
|
|
72
|
+
4. Start the program in the emulator with an autostart. Look at the screen. Read the screen memory, not only the screen image.
|
|
73
|
+
5. Write the `expect` steps of this part in a run file. Give the symbol file `build/<name>.json` in the run file, so that a step can use the labels of the source.
|
|
74
|
+
6. Run all run files in `tests/`. Go to the next part only when each run gives PASS.
|
|
94
75
|
|
|
95
|
-
To find a defect,
|
|
76
|
+
To find a defect, debug the program in the emulator:
|
|
96
77
|
|
|
97
|
-
- Stop at the code with
|
|
98
|
-
-
|
|
99
|
-
- Measure an interrupt or a loop
|
|
100
|
-
- Save
|
|
78
|
+
- Stop at the code with a breakpoint, or at a write to a variable with a watchpoint.
|
|
79
|
+
- Run the emulator until the program gets to a state.
|
|
80
|
+
- Measure the cycles of an interrupt or a loop. Profile the program to find the routines that use the most cycles.
|
|
81
|
+
- Save a snapshot of the machine before a risky try.
|
|
101
82
|
|
|
102
83
|
Find the cause before you change the code. Do not change code at random until a test passes.
|
|
103
84
|
|
|
104
|
-
When the user must play or look at the program,
|
|
85
|
+
When the user must play or look at the program, open the emulator window for the user.
|
|
105
86
|
|
|
106
87
|
### B. A feature or a fix in source that a person wrote
|
|
107
88
|
|
|
108
89
|
1. Write a run file with an `expect` step that shows the defect or the missing feature.
|
|
109
|
-
2. Run it
|
|
110
|
-
3. For a defect, find the cause
|
|
111
|
-
4. Change the source.
|
|
90
|
+
2. Run it. Make sure that it gives FAIL. A test that gives PASS before the change does not test the change.
|
|
91
|
+
3. For a defect, find the cause in the emulator.
|
|
92
|
+
4. Change the source. Assemble it.
|
|
112
93
|
5. Run the new run file and all other run files in `tests/`. Each run must give PASS.
|
|
113
94
|
|
|
114
95
|
### C. A feature or a fix in a rebuilt program
|
|
115
96
|
|
|
116
|
-
A rebuilt program gets its source from the knowledge. A change is a switch and its patches in the knowledge. The build of the base release stays identical to the original.
|
|
97
|
+
A rebuilt program gets its source from the project knowledge. A change is a switch and its patches in the knowledge. The build of the base release stays identical to the original.
|
|
117
98
|
|
|
118
|
-
1. Read the releases and the switches
|
|
119
|
-
2. Give each feature and each fix its own switch. Then each one can be on or off alone.
|
|
99
|
+
1. Read the releases and the switches in the project knowledge. If the knowledge has no base release, record the original file as the base release first, for example `original/game.prg`.
|
|
100
|
+
2. Give each feature and each fix its own switch. Then each one can be on or off alone. Record the switch in the project knowledge. No release has your change, so do not give the switch a release. Select the kind of the switch:
|
|
120
101
|
- A fix: `fix`, for example `FIX_FLICKER`. The default build has it.
|
|
121
102
|
- A trainer or a cheat: `trainer` or `cheat`. The default build does not have it.
|
|
122
|
-
- Another feature: `change`, for example `HISCORE`. Ask the user if the default build must have it.
|
|
123
|
-
3. Find the code to change
|
|
124
|
-
4. Write the code in a file in `.c64-re-tools/local/`.
|
|
125
|
-
5. If the code does not fit, write a short patch with a `jsr` to the new code. Put the new code in a second patch of the same switch, in a range that the program does not use. The range must have evidence:
|
|
126
|
-
6.
|
|
127
|
-
7. Build
|
|
128
|
-
-
|
|
129
|
-
-
|
|
130
|
-
- When the default build does not have the switch
|
|
103
|
+
- Another feature: `change`, for example `HISCORE`. Ask the user if the default build must have it. Record the default as 1 or 0.
|
|
104
|
+
3. Find the code to change. Read the project knowledge at the addresses, and examine the code in the emulator.
|
|
105
|
+
4. Write the code in a file in `.c64-re-tools/local/`. Record a patch of the switch for the range, with the code from the file. The code must fit in the range.
|
|
106
|
+
5. If the code does not fit, write a short patch with a `jsr` to the new code. Put the new code in a second patch of the same switch, in a range that the program does not use. The range must have evidence: a leftover that you found in the program, or code that no run executed and that the program cannot reach. If no range has this evidence, stop and ask the user.
|
|
107
|
+
6. Generate the source from the project knowledge into `src`. Continue only when the result of the generation is PASS. A switch with the result `overflow` or `does not assemble` has a patch that you must change.
|
|
108
|
+
7. Build the program:
|
|
109
|
+
- Build the base release and compare it with the original. This build must be identical to the original.
|
|
110
|
+
- Build the default build.
|
|
111
|
+
- When the default build does not have the switch, set the switch to 1 in `src/config.asm`. Then build the default build. After the test, set the value back to the default if the user did not ask for the change.
|
|
131
112
|
8. Test the build that has the switch:
|
|
132
|
-
- Run the scenarios in `tests/`
|
|
113
|
+
- Run the test scenarios in `tests/` where the behavior must stay the same as the original.
|
|
133
114
|
- Run a run file with `expect` steps that show the feature or the fix.
|
|
134
115
|
|
|
135
116
|
### The answer
|
|
@@ -143,9 +124,9 @@ Give the user a short answer at the end:
|
|
|
143
124
|
|
|
144
125
|
## Knowledge
|
|
145
126
|
|
|
146
|
-
For a new program, the source is the truth. Record names and comments in the knowledge only when the user asks for the knowledge or for documentation. Then put the program
|
|
127
|
+
For a new program, the source is the truth. Record names and comments in the project knowledge only when the user asks for the knowledge or for documentation. Then put the built program into the project knowledge first.
|
|
147
128
|
|
|
148
|
-
For a rebuilt program,
|
|
129
|
+
For a rebuilt program, record each change as a switch and its patches in the project knowledge.
|
|
149
130
|
|
|
150
131
|
Do not store:
|
|
151
132
|
|
|
@@ -159,22 +140,14 @@ A program that builds, with a run file in `tests/` for each acceptance check, an
|
|
|
159
140
|
|
|
160
141
|
## Failure and conflicts
|
|
161
142
|
|
|
162
|
-
- A
|
|
143
|
+
- A task reports `installation-incomplete` or `machine-unavailable`: stop the whole task. Give the message to the user and wait for the user. Do not continue with other tasks.
|
|
163
144
|
- A tool gives a wrong result: tell the user the defect and the evidence, and wait for the user. Do not make a workaround.
|
|
164
145
|
- A test gives FAIL: change the program until the test gives PASS. Do not change the expected value to make the test pass. Change an expected value only when the user changes the acceptance check.
|
|
165
|
-
- A run gives FAIL because a `runUntil` did not get to its target: the program did not get to that state. Find
|
|
166
|
-
- The program reads the keyboard hardware, and a key does not arrive: read the description of
|
|
146
|
+
- A run gives FAIL because a `runUntil` step did not get to its target: the program did not get to that state. Find the cause in the emulator.
|
|
147
|
+
- The program reads the keyboard hardware, and a key does not arrive: read the description of the keyboard tool of the emulator. Do not change the program to make it accept a key.
|
|
167
148
|
- A patch does not fit, and no unused range has evidence: stop and ask the user.
|
|
168
149
|
|
|
169
|
-
##
|
|
170
|
-
|
|
171
|
-
-
|
|
172
|
-
-
|
|
173
|
-
- Tests with expected values, and original against rebuild → c64-testing
|
|
174
|
-
- The meaning of an address or a register → c64-memory-map
|
|
175
|
-
- Patches, names and comments → c64-knowledge
|
|
176
|
-
- The source of a rebuilt program → c64-source
|
|
177
|
-
- Unused ranges of a rebuilt program → c64-provenance
|
|
178
|
-
- Documentation → c64-docs
|
|
179
|
-
- Code that nobody understands yet → c64-reverse-engineering
|
|
180
|
-
- The start of a new program from a rebuilt program → c64-export
|
|
150
|
+
## Other tasks
|
|
151
|
+
|
|
152
|
+
- To find out what code does when nobody understands it yet, reverse engineer it.
|
|
153
|
+
- To start a new program from a rebuilt program, export the rebuilt program as a new project.
|
package/skills/c64-disk/SKILL.md
CHANGED
|
@@ -1,109 +1,181 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: c64-disk
|
|
3
|
-
description:
|
|
3
|
+
description: Examines a C64 disk image (D64, D71, D81 or G64), a T64 tape file or a CRT cartridge file. It extracts files from it into the project. It shows the directory, the BAM, the directory entry of a file and the sector chain of a file. It writes each bank of a cartridge as a PRG. Use it when a program comes as a disk image, a tape file or a cartridge file. Use it to find the sectors that a loader reads directly. It does not run the program, it does not decode BASIC, and it does not change the disk image.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
#
|
|
6
|
+
# C64 disk
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
Use this script to extract files from a C64 disk image, a T64 tape file or a CRT cartridge file, and to examine them.
|
|
9
|
+
Use only the commands of the script. Do not read disk images, tape files or cartridge files in another way.
|
|
9
10
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
```bash
|
|
12
|
+
node <skill>/scripts/disk.ts <command>
|
|
13
|
+
```
|
|
13
14
|
|
|
14
|
-
|
|
15
|
+
`<skill>` is the base directory of this skill. Run the script with `node`. You can run it from any directory.
|
|
16
|
+
Each command in this skill, for example `directory original/game.d64`, goes in the place of `<command>`.
|
|
17
|
+
Each command prints one JSON envelope on stdout. See the section "JSON output".
|
|
18
|
+
To get the command list, run the script with no arguments.
|
|
15
19
|
|
|
16
|
-
|
|
17
|
-
- For one file: the file name as the directory shows it.
|
|
18
|
-
- To extract a file: the output path, relative to the project folder.
|
|
19
|
-
- A T64 tape file or a CRT cartridge file, relative to the project folder.
|
|
20
|
+
---
|
|
20
21
|
|
|
21
|
-
##
|
|
22
|
+
## Select the command
|
|
22
23
|
|
|
23
|
-
|
|
24
|
-
node <skill>/scripts/disk.ts <command> <image> [name] [--out <file>]
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
| Need | Command |
|
|
24
|
+
| Goal | Command |
|
|
28
25
|
|---|---|
|
|
29
|
-
|
|
|
30
|
-
|
|
|
31
|
-
|
|
|
32
|
-
|
|
|
33
|
-
|
|
|
34
|
-
|
|
|
26
|
+
| Get the disk name, the free blocks and the files of a disk | `directory original/game.d64` |
|
|
27
|
+
| Extract one file of a disk | `read original/game.d64 GAME --out extracted/game.prg` |
|
|
28
|
+
| Get the type, the size and the first block of one file | `entry original/game.d64 GAME` |
|
|
29
|
+
| Get the track and the sector of each block of one file | `chain original/game.d64 GAME` |
|
|
30
|
+
| Find the used sectors that no file uses | `bam original/game.d64` |
|
|
31
|
+
| Get the files of a tape | `directory original/game.t64` |
|
|
35
32
|
| Extract one file of a tape | `read original/game.t64 GAME --out extracted/game.prg` |
|
|
36
|
-
|
|
|
33
|
+
| Get the banks of a cartridge | `directory original/game.crt` |
|
|
37
34
|
| Write each bank of a cartridge as a PRG | `crt original/game.crt --out cart` |
|
|
38
35
|
|
|
39
|
-
|
|
36
|
+
## Images and file names
|
|
40
37
|
|
|
41
|
-
|
|
38
|
+
- `<image>` is the file that the user gives. Each command takes only some types of file:
|
|
42
39
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
-
|
|
51
|
-
-
|
|
40
|
+
| Command | Types of file |
|
|
41
|
+
|---|---|
|
|
42
|
+
| `directory` | `.d64`, `.d71`, `.d81`, `.g64`, `.t64`, `.crt` |
|
|
43
|
+
| `read` | `.d64`, `.d71`, `.d81`, `.g64`, `.t64` |
|
|
44
|
+
| `bam`, `entry`, `chain` | `.d64`, `.d71`, `.d81`, `.g64` |
|
|
45
|
+
| `crt` | `.crt` |
|
|
46
|
+
|
|
47
|
+
- `<name>` is a file name from the result of `directory`. Write the name in the same form as the directory shows it. The letter case of a name is not important.
|
|
48
|
+
- A name shows the characters that the C64 shows in a directory list. A byte that has no character shows as `{$xx}`, for example `{$c1}`. Put the name in single quotes in a shell, for example `'GAME {$c1}'`.
|
|
49
|
+
- Put `--` before a name that starts with `-`. Put the `--` after all flags, for example `read d.d64 --out x.prg -- '-----'`.
|
|
50
|
+
- The script does not read a TAP file. A TAP file holds tape signals, and turbo loaders have their own formats. Start a TAP file in the emulator, or capture the parts of the program that it loads.
|
|
51
|
+
|
|
52
|
+
### Wrong files and names
|
|
52
53
|
|
|
53
|
-
|
|
54
|
+
- `not-found`: the image file is missing, or the image has no file with that name. Run `directory` again and compare the names.
|
|
55
|
+
- `media-error`: the file has a defect, or its content is not of its type. A cartridge of a hardware type that the script does not read also gives `media-error`. `error` tells the problem, for example a sector chain that loops. Give `error` to the user. Do not change the file.
|
|
56
|
+
- `invalid-input` with "is not a file that": the command does not take this type of file. `hint` gives each type that the command takes.
|
|
54
57
|
|
|
55
|
-
|
|
56
|
-
|
|
58
|
+
### Paths and the project folder
|
|
59
|
+
|
|
60
|
+
- Give each path relative to the project folder. The project folder is the nearest folder at or above the working directory that holds `.c64-re-tools/`.
|
|
61
|
+
- If the working directory is not in a project, give `--project <folder>` to each command. If the working directory has projects below it, the script refuses and lists them.
|
|
62
|
+
- An address is `$` and 1 to 4 hex digits, for example `'$c000'` or `'$fb'`, or a name. A name is a symbol, else an analyzer name that only one analyzer gives. Put an address in single quotes in a shell.
|
|
63
|
+
- A range is `<start>-<end>`, for example `'$c000-$cfff'`. In a JSON file, a range is `start` and `end`.
|
|
64
|
+
- Bytes in a JSON file are hex in a field `data`, for example `"data": "a900"`.
|
|
57
65
|
- Write each file that you make for your work in `.c64-re-tools/local/` of the project. Git ignores that folder. Examples are results, batches, step files, runs, snapshots and memory dumps.
|
|
58
|
-
-
|
|
59
|
-
-
|
|
60
|
-
-
|
|
66
|
+
- The script refuses an `--out` path in `.c64-re-tools/knowledge/` and the index of the knowledge. Change the project knowledge only with the commands that change it.
|
|
67
|
+
- The script refuses a folder where the command writes a file. It refuses a file where the command writes a folder.
|
|
68
|
+
- When a file is the evidence for a finding in the project knowledge, move it out of `.c64-re-tools/local/` first. The project knowledge refuses evidence in that folder.
|
|
69
|
+
- Do not move a coverage map after you put it into the project knowledge. The knowledge refers to the map by its path at that time.
|
|
70
|
+
- Put a run that is evidence in `runs/<name>/`, with its run file, its results and its snapshot files. Change the paths in the run file to the new paths. Then git keeps them, and another person can do the run again.
|
|
61
71
|
- A shell redirect (`>`) is relative to the working directory, not to the project folder. From the folder above the project, write `<folder>/.c64-re-tools/local/result.json`.
|
|
62
72
|
|
|
63
|
-
##
|
|
73
|
+
## Flags
|
|
74
|
+
|
|
75
|
+
Each flag applies only to the commands in the table. On another command, the script refuses the flag.
|
|
76
|
+
|
|
77
|
+
| Flag | Command | Effect |
|
|
78
|
+
|---|---|---|
|
|
79
|
+
| `--out <file>` | `read` | The file to write, relative to the project folder. Required. |
|
|
80
|
+
| `--out <dir>` | `crt` | The folder for the bank files and `crt.json`, relative to the project folder. Required. |
|
|
81
|
+
|
|
82
|
+
---
|
|
83
|
+
|
|
84
|
+
## Examine a file
|
|
85
|
+
|
|
86
|
+
### `directory <image>`
|
|
87
|
+
|
|
88
|
+
For a disk image, `body` holds `diskName`, `diskId`, `dosType`, `freeBlocks` and `entries`. Each entry has `name`, `type`, `blocks`, `closed` and `locked`.
|
|
89
|
+
|
|
90
|
+
For a tape file, `body` holds `name` and `entries`. Each entry has `name`, `start`, `end` and `bytes`. Many T64 files have a wrong end address. Then the entry has `fixedSize: true`, and the size comes from the position of the next file.
|
|
91
|
+
|
|
92
|
+
For a cartridge file, `body` holds the header and `chips`. The header is `name`, `type`, `typeName`, `exrom`, `game`, and `mode` for type 0. Each chip has `bank`, `address`, `size` and `space`.
|
|
93
|
+
|
|
94
|
+
When a file on a disk is not `closed`, `hint` names it. The data of that file can be incomplete.
|
|
95
|
+
|
|
96
|
+
Do not record the directory list in the project knowledge.
|
|
64
97
|
|
|
65
|
-
|
|
66
|
-
2. Run `read` with an output path to extract the file. A PRG file keeps its 2-byte load address at the start.
|
|
67
|
-
3. Run `entry` or `chain` only when the disk structure is important, for example for a loader that reads sectors directly.
|
|
68
|
-
4. Run `bam` only to find used sectors that no file uses. `unreferenced` lists them. The list does not include the header, the directory and the BAM blocks. These sectors can hold data that a loader reads directly.
|
|
98
|
+
### `bam <image>`
|
|
69
99
|
|
|
70
|
-
|
|
100
|
+
`body.tracks` gives the `freeSectors` and the `usedSectors` of each track. `body.unreferenced` lists the used sectors that no file uses. The list does not include the header, the directory and the BAM blocks. These sectors can hold data that a loader reads directly.
|
|
71
101
|
|
|
72
|
-
|
|
73
|
-
- none.
|
|
102
|
+
### `entry <image> <name>`
|
|
74
103
|
|
|
75
|
-
|
|
76
|
-
- the directory list
|
|
77
|
-
- sector chains.
|
|
104
|
+
`body` holds `found: true` and `entry`: the `name`, `type`, `blocks`, `closed`, `locked`, `startTrack` and `startSector` of the file. Use it when the disk structure is important, for example for a loader that reads sectors directly.
|
|
78
105
|
|
|
79
|
-
|
|
106
|
+
### `chain <image> <name>`
|
|
80
107
|
|
|
81
|
-
|
|
108
|
+
`body` holds `found: true` and `sectors`: the `track` and the `sector` of each block of the file, in sequence. Do not record the sector chain in the project knowledge.
|
|
82
109
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
110
|
+
---
|
|
111
|
+
|
|
112
|
+
## Extract files
|
|
113
|
+
|
|
114
|
+
### `read <image> <name>`
|
|
115
|
+
|
|
116
|
+
Writes the bytes of one file at `--out`. A PRG file keeps its 2-byte load address at the start. A file from a tape gets the start address of its tape entry as its load address.
|
|
117
|
+
|
|
118
|
+
`body` holds the `name` of the file and the written file as `out`, `bytes` and `sha256`.
|
|
119
|
+
|
|
120
|
+
For a cartridge file, the script refuses `read`. Use `crt`.
|
|
121
|
+
|
|
122
|
+
### `crt <file.crt>`
|
|
87
123
|
|
|
88
|
-
|
|
124
|
+
Writes one PRG for each CHIP packet of the cartridge, for example `bank3-8000.prg`. It also writes `crt.json` with the header and the packets. The script reads hardware types 0 (normal 8K, 16K or Ultimax), 5 (Ocean), 19 (Magic Desk) and 32 (EasyFlash).
|
|
89
125
|
|
|
90
|
-
|
|
126
|
+
`body` holds the header, `chips` and `files`. Each chip has `bank`, `address`, `size`, `space` and `file`. `files` has one item for each PRG and one item for `crt.json`.
|
|
91
127
|
|
|
92
|
-
|
|
128
|
+
All banks use the same addresses. Thus `hint` tells you to analyze each bank PRG in its own knowledge space. The field `space` of the chip gives that space, for example `bank3`. Record the knowledge of the bank in that space too.
|
|
93
129
|
|
|
94
|
-
|
|
130
|
+
---
|
|
131
|
+
|
|
132
|
+
## Workflow
|
|
133
|
+
|
|
134
|
+
1. Run `directory`. Find the file in `entries`.
|
|
135
|
+
2. Run `read` to extract the file. For a cartridge, run `crt`.
|
|
136
|
+
3. Run `entry` or `chain` only when the disk structure is important.
|
|
137
|
+
4. Run `bam` only to find the used sectors that no file uses.
|
|
138
|
+
5. Give the extracted file to the next task. Decode a BASIC program, unpack a packed program, or disassemble machine code.
|
|
139
|
+
|
|
140
|
+
---
|
|
95
141
|
|
|
96
|
-
|
|
97
|
-
- `media-error`: the image, the T64 file or the CRT file has a defect, or its content is not of its type. A CRT with a hardware type that the script does not read also gives `media-error`. The message tells the problem, for example a sector chain that loops. Tell the user. Do not change the file.
|
|
98
|
-
- `installation-incomplete` or `machine-unavailable`: stop the task. Give the message to the user and wait for the user. Do not install, start or change a tool yourself. Do not make a replacement for the tool, for example your own disk parser, disassembler or emulator script.
|
|
99
|
-
- `invalid-input`: an argument or a path is wrong. A file with an extension that the command does not take is also wrong. The message gives each type that the command takes. Read the message and change the call.
|
|
142
|
+
## JSON output
|
|
100
143
|
|
|
101
|
-
|
|
144
|
+
Each command prints one JSON envelope on one line on stdout. Notes go to stderr.
|
|
145
|
+
|
|
146
|
+
On success, the exit code is 0:
|
|
147
|
+
|
|
148
|
+
```json
|
|
149
|
+
{"ok": true, "command": "<command>", "body": {}, "hint": "...", "nextAction": "..."}
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
On failure, the exit code is 2:
|
|
153
|
+
|
|
154
|
+
```json
|
|
155
|
+
{"ok": false, "command": "<command>", "code": "<code>", "error": "...", "hint": "...", "nextAction": "..."}
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
- `body` holds the result. The section of each command gives the fields of its body.
|
|
159
|
+
- A check gives its verdict in `body.result`: `PASS`, `FAIL` or `INCONCLUSIVE`. The exit code is 0 for each verdict. Thus read `body.result`, not the exit code.
|
|
160
|
+
- `error` is one sentence. It tells what is wrong.
|
|
161
|
+
- `hint` tells what to do or what to examine. Read it before your next step. Some envelopes have no `hint`.
|
|
162
|
+
- `nextAction` is a full command line. It runs from any directory. Run it when it agrees with your task. Some envelopes have no `nextAction`.
|
|
163
|
+
- `code` does not change between versions. Do the action for the code:
|
|
164
|
+
|
|
165
|
+
| `code` | Action |
|
|
166
|
+
|---|---|
|
|
167
|
+
| `installation-incomplete`, `machine-unavailable` | Stop the task. Give `error` and `hint` to the user and wait for the user. Do not install, start or change a tool. Do not make a replacement for the tool, for example your own disk parser, disassembler or emulator script. |
|
|
168
|
+
| `invalid-input`, `not-found` | Correct the call as `hint` tells. Then run the command again. |
|
|
169
|
+
| `operation-failed` | Give `error` and `hint` to the user. |
|
|
170
|
+
| Another code | Do as `hint` tells. |
|
|
171
|
+
|
|
172
|
+
These fields have the same meaning in each body:
|
|
173
|
+
|
|
174
|
+
| Field | Meaning |
|
|
175
|
+
|---|---|
|
|
176
|
+
| `out`, `bytes`, `sha256` | A file that the command wrote: its path, its size and its SHA-256. |
|
|
177
|
+
| `count`, `listed`, `rest` | A list. `count` is the number of items. `listed` holds the first items, at most `--max-listed`. `rest` tells how to get the other items. |
|
|
102
178
|
|
|
103
|
-
|
|
179
|
+
To get the command list, run the script with no arguments. The envelope has `command: "help"`, and `body.commands` gives the name, the summary and the synopsis of each command.
|
|
180
|
+
To get the subjects and the flags of one command, run `<command> --help`. Then `body.subjects` and `body.options` give them.
|
|
104
181
|
|
|
105
|
-
- BASIC program → c64-basic
|
|
106
|
-
- Packed program → c64-unpacker
|
|
107
|
-
- Machine code, also a cartridge bank → c64-static-analysis
|
|
108
|
-
- A TAP file → c64-unpacker
|
|
109
|
-
- Run the program → emulator
|
|
@@ -6,7 +6,7 @@ import { formatC64Address } from "#src/c64.ts";
|
|
|
6
6
|
import { isRefusal, Refusal } from "#src/errors.ts";
|
|
7
7
|
import { DISK_IMAGE_TYPES, inspectDisk } from "#src/host-client/tools.ts";
|
|
8
8
|
import { readProjectFile, writeReported } from "#src/host-client/transfer.ts";
|
|
9
|
-
import { OPTIONS, runScript, type Call, type SubjectSpec } from "#src/script.ts";
|
|
9
|
+
import { OPTIONS, reply, runScript, type Call, type SubjectSpec } from "#src/script.ts";
|
|
10
10
|
import { parseCrt, parseT64, tapeFile } from "./lib/containers.ts";
|
|
11
11
|
|
|
12
12
|
const IMAGE: SubjectSpec = { name: "<image>", help: "a .d64, .d71, .d81 or .g64 disk image, relative to the project folder" };
|
|
@@ -31,16 +31,18 @@ function kindFor(command: string, image: string, takes: readonly Kind[]): Kind {
|
|
|
31
31
|
throw new Refusal("invalid-input", `${image} is not a file that ${command} takes. Give ${list}.`);
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
/** Runs `body` and names the file in a refusal of its content. */
|
|
34
|
+
/** Runs `body` and names the file in a refusal of its content. A CRT of a hardware type that CRT_TYPES does not hold is also a media-error. */
|
|
35
35
|
function about<T>(image: string, body: () => T): T {
|
|
36
36
|
try {
|
|
37
37
|
return body();
|
|
38
38
|
} catch (error) {
|
|
39
|
-
if (isRefusal(error) && error.code === "media-error") throw new Refusal(error.code, `${image}: ${error.message}
|
|
39
|
+
if (isRefusal(error) && error.code === "media-error") throw new Refusal(error.code, `${image}: ${error.message}.`, { hint: MEDIA_HINT });
|
|
40
40
|
throw error;
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
+
const MEDIA_HINT = "The file has a defect, or its content is not of its type. Give this message to the user. Do not change the file.";
|
|
45
|
+
|
|
44
46
|
/** A file that the image does not hold. */
|
|
45
47
|
const noFile = (image: string, name: string) => new Refusal("not-found", `${image} has no file ${name}. Give the name as directory shows it.`);
|
|
46
48
|
|
|
@@ -75,7 +77,7 @@ const diskOnly = (call: Call, action: string) => kindFor(action, call.subject(0)
|
|
|
75
77
|
|
|
76
78
|
await runScript({
|
|
77
79
|
name: "disk",
|
|
78
|
-
summary: "Inspects a disk image
|
|
80
|
+
summary: "Inspects a disk image and extracts files into the project. It also reads T64 tape files and CRT cartridge files. A CRT can have hardware type 0 (normal 8K, 16K or Ultimax), 5 (Ocean), 19 (Magic Desk) or 32 (EasyFlash).",
|
|
79
81
|
commands: [
|
|
80
82
|
{
|
|
81
83
|
name: "directory",
|
|
@@ -89,7 +91,10 @@ await runScript({
|
|
|
89
91
|
const { header, chips } = cartridge(image);
|
|
90
92
|
return { ...header, chips: chips.map(({ file: _file, ...chip }) => chip) };
|
|
91
93
|
}
|
|
92
|
-
|
|
94
|
+
const listing = (await inspect(call, "directory")) as { entries?: Array<{ name: string; closed?: boolean }> };
|
|
95
|
+
const open = (listing.entries ?? []).filter((entry) => entry.closed === false).map((entry) => entry.name);
|
|
96
|
+
if (open.length === 0) return listing;
|
|
97
|
+
return reply(listing, { hint: `The file ${open.join(", ")} is not closed. Its data can be incomplete.` });
|
|
93
98
|
},
|
|
94
99
|
},
|
|
95
100
|
{
|
|
@@ -153,7 +158,7 @@ await runScript({
|
|
|
153
158
|
const { crt, header, chips } = cartridge(image);
|
|
154
159
|
const files = crt.chips.map((chip, index) => writeReported(`${out}/${chips[index]!.file}`, Buffer.concat([Buffer.from([chip.address & 0xff, chip.address >> 8]), chip.data]), { what: "--out" }));
|
|
155
160
|
files.push(writeReported(`${out}/crt.json`, `${JSON.stringify({ ...header, chips }, null, 2)}\n`, { what: "--out" }));
|
|
156
|
-
return { ...header, chips, files };
|
|
161
|
+
return reply({ ...header, chips, files }, { hint: "All banks use the same addresses. Analyze each bank PRG in its own knowledge space: the field space of its chip gives the space." });
|
|
157
162
|
},
|
|
158
163
|
},
|
|
159
164
|
],
|