@henols/c64-re-tools 2.5.1-rc.2 → 2.6.0-rc.10
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 +2 -2
- package/skills/c64-assembler/SKILL.md +26 -12
- package/skills/c64-assembler/scripts/assembler.ts +25 -13
- package/skills/c64-development/SKILL.md +2 -2
- package/skills/c64-docs/SKILL.md +4 -4
- package/skills/c64-docs/scripts/docs.ts +7 -7
- package/skills/c64-docs/scripts/lib/reference.ts +3 -3
- package/skills/c64-docs/scripts/lib/source-map.ts +9 -4
- package/skills/c64-knowledge/SKILL.md +29 -20
- package/skills/c64-knowledge/scripts/knowledge.ts +33 -39
- package/skills/c64-knowledge/scripts/lib/listing.ts +18 -3
- package/skills/c64-packer/SKILL.md +1 -1
- package/skills/c64-provenance/SKILL.md +11 -10
- package/skills/c64-provenance/scripts/lib/library.ts +16 -16
- package/skills/c64-provenance/scripts/provenance.ts +33 -23
- package/skills/c64-reverse-engineering/SKILL.md +16 -10
- package/skills/c64-source/SKILL.md +60 -42
- package/skills/c64-source/scripts/lib/export.ts +76 -32
- package/skills/c64-source/scripts/lib/loader.ts +26 -7
- package/skills/c64-source/scripts/lib/source.ts +21 -24
- package/skills/c64-source/scripts/lib/stage.ts +6 -5
- package/skills/c64-source/scripts/source.ts +213 -106
- package/skills/c64-static-analysis/SKILL.md +7 -5
- package/skills/c64-static-analysis/scripts/lib/coverage.ts +2 -25
- package/skills/c64-static-analysis/scripts/lib/instructions.ts +22 -20
- package/skills/c64-static-analysis/scripts/static-analysis.ts +36 -43
- package/skills/c64-testing/SKILL.md +5 -2
- package/skills/c64-testing/references/recording-format.md +18 -3
- package/skills/c64-testing/references/scenario-format.md +7 -6
- package/skills/c64-testing/scripts/lib/diff-files.ts +4 -18
- package/skills/c64-testing/scripts/lib/play.ts +39 -41
- package/skills/c64-testing/scripts/lib/recording.ts +46 -37
- package/skills/c64-testing/scripts/lib/replay.ts +1 -1
- package/skills/c64-testing/scripts/lib/runs.ts +2 -2
- package/skills/c64-testing/scripts/lib/scenario.ts +17 -10
- package/skills/c64-unpacker/SKILL.md +4 -1
- package/skills/c64-unpacker/scripts/lib/loads.ts +34 -13
- package/skills/c64-unpacker/scripts/unpacker.ts +5 -3
- package/skills/emulator/SKILL.md +7 -12
- package/src/build-name.ts +50 -0
- package/src/c64-keys.ts +98 -0
- package/src/c64.ts +20 -0
- package/src/cli/main.ts +3 -29
- package/src/host/main.ts +1 -1
- package/src/host/tools/index.ts +1 -6
- package/src/host/vice/session.ts +88 -9
- package/src/host-client/steps.ts +17 -17
- package/src/host-client/tools.ts +2 -7
- package/src/host-client/vice-session.ts +7 -1
- package/src/knowledge/program.ts +44 -1
- package/src/knowledge/read.ts +28 -8
- package/src/knowledge/schema.ts +33 -9
- package/src/knowledge/start-screen.ts +4 -0
- package/src/knowledge/text.ts +4 -2
- package/src/knowledge/write.ts +59 -25
- package/src/mcp/inputs.ts +12 -0
- package/src/mcp/server.ts +1 -1
- package/src/mcp/tools/input.ts +38 -5
- package/src/mcp/tools/machine.ts +3 -42
- package/src/mcp/tools/media.ts +1 -1
- package/src/native/acme.ts +1 -1
- package/src/native/c64run.ts +1 -1
- package/src/native/discover.ts +3 -3
- package/src/native/dxa.ts +12 -1
- package/src/native/ghidra/analyze.ts +74 -63
- package/src/native/ghidra/c64rt-wasm.ts +4 -0
- package/src/native/ghidra/language/c64rt_6510.sla +0 -0
- package/src/native/ghidra/pcode.ts +222 -0
- package/src/native/ghidra/walk.ts +205 -0
- package/src/native/ghidra/wasm.ts +98 -0
- package/src/native/processes.ts +4 -4
- package/src/native/types.ts +2 -2
- package/src/platform.ts +30 -1
- package/src/project.ts +17 -4
- package/src/protocol/tools.ts +1 -45
- package/src/protocol/vice.ts +47 -0
- package/src/script.ts +1 -1
- package/src/vsf.ts +98 -0
- package/tools/c64run.c +9 -12
- package/tools/install-container.sh +1 -2
- package/src/cli/status.ts +0 -127
- package/src/host/tools/status.ts +0 -47
- package/src/native/ghidra/index.ts +0 -170
- package/src/native/ghidra/scripts/C64Export.java +0 -274
- package/src/native/ghidra/scripts/C64Prepare.java +0 -66
- package/src/native/status.ts +0 -135
- package/tools/install-ghidra.sh +0 -40
|
@@ -27,7 +27,7 @@ Do the specialist work of each task as that task tells. Do not do it in another
|
|
|
27
27
|
- One repository can hold several programs, with one project folder for each program. Work on one project at a time.
|
|
28
28
|
- Write all files in the project folder. Do not write files at the root of the repository.
|
|
29
29
|
- A subagent can have no emulator tools. Give it its experiments as test run files. Many test runs can go at the same time. The emulator tools are for the main session only.
|
|
30
|
-
- To name a large program with more agents at the same time, give each agent one range of addresses. Each agent writes a batch of knowledge changes with its owner range. Then join the batches of the agents, and
|
|
30
|
+
- To name a large program with more agents at the same time, give each agent one range of addresses. Each agent writes a batch of knowledge changes with its owner range. Then join the batches of the agents, and write them to the project knowledge as one revision.
|
|
31
31
|
- Do not write a build script or a merge script. The generation of the source writes and assembles the loader. The project knowledge joins the batches.
|
|
32
32
|
- Do not write a script that makes a deliverable again, for example a capture, copy or replay script. Commit the deliverable.
|
|
33
33
|
|
|
@@ -85,30 +85,36 @@ Do the stages in this sequence. Go to the next stage only when its exit check is
|
|
|
85
85
|
|
|
86
86
|
| Stage | Work | Exit check |
|
|
87
87
|
|---|---|---|
|
|
88
|
-
| 1. Acceptance | Ask the user for the criteria of the rebuild. Offer these criteria:
|
|
88
|
+
| 1. Acceptance | Ask the user for the criteria of the rebuild. Offer these criteria: a base release that is identical to the original, and a passed replay of the default build. Also offer a replay of each recording, test scenarios and a list of the code that no run executed. Also offer documentation of the flows, tables, formats and graphics. | The user gave the criteria. |
|
|
89
89
|
| 2. Get | List the disk image. Extract the start file into `original/`. | The start file is in the project. |
|
|
90
90
|
| 3. Start | Find the SYS address of the BASIC start. | You have the entry address. |
|
|
91
91
|
| 4. Unpack | Examine the program for a packer. Trace it and find its stages. Capture a packed program into `.c64-re-tools/local/`. When a segment is the data of a cracktro and the program does not read it, capture again and exclude that range. Put the capture, or the PRG of a program without a packer, into the project knowledge. | The program in the project knowledge has the segments and the entry. |
|
|
92
92
|
| 5. Run | First, record. Ask the user to play each part that the scope names, in a recording session. Tell the user which parts. Record a part yourself only when the sessions of the user do not have it. Put the recordings in `tests/recordings/`. Then run the parts that a recording cannot have, in the emulator or as test runs. Write a coverage map for each part into `.c64-re-tools/local/`. Add the maps and the `coverage.bin` of each recording to the project knowledge. | The program in the project knowledge has a coverage map for each part that the scope names. |
|
|
93
93
|
| 6. Analyze | Analyze the program statically. The analysis reads the program and the coverage from the project knowledge. | No coverage conflict is open. |
|
|
94
|
-
| 7. Name | If the workspace has a routine library, match the program against it.
|
|
95
|
-
| 8. Releases and switches |
|
|
96
|
-
| 9. Generate | Generate the source from the project knowledge into `src`. For an unpacked program, also generate the loader. | The result of the generation is PASS.
|
|
97
|
-
| 10. Build and test | Build the base release into `build/`, and compare it with the original. Build the default build.
|
|
94
|
+
| 7. Name | If the workspace has a routine library, match the program against it. Write the names of the matches to the project knowledge. Then name each routine in the scope and give it a comment. Find the platform addresses in the memory map of the C64. Record the modules. Put the modules of one part of the program in one folder, for example `music/`, `irq/` or `graphics/`. When the scope has hundreds of routines, ask the user which routines to name. The source gives the other routines an `l_xxxx` label. | Each routine that the user selected has a name and a comment. |
|
|
95
|
+
| 8. Releases and switches | Record the original file, or the capture of it, as the base release in the project knowledge. The project knowledge keeps the bytes of each release. Record each other release. Compare the releases. Find the leftovers. Record a switch for each copy protection, trainer, cheat, crack change and correction. Record a patch for each range of a switch. Record each leftover as a region with a comment. | The project knowledge lists each switch. Each difference between the releases is in a patch, or the answer gives it as an exception. |
|
|
96
|
+
| 9. Generate | Generate the source from the project knowledge into `src`. For an unpacked program, also generate the loader. | The result of the generation is PASS. A release whose code is at other addresses is a version with a project of its own, or an exception in the answer. See "Versions of one program". |
|
|
97
|
+
| 10. Build and test | Build the base release into `build/`, and compare it with the original. Build the default build. Replay one recording on the default build. For each replay, give the checkpoint routine, the state and the random state with the names of stage 7. Then do only the tests that the next paragraph gives. | The criteria of stage 1 are true. |
|
|
98
98
|
| 11. Document | When the criteria ask for documentation, generate it into `README.md` and `docs/`. For versions in a group folder, also write the shared pages of the group folder. Then link the pages. | The link check of the documentation gives PASS. |
|
|
99
99
|
| 12. Hand over | Find each file that you made outside `.c64-re-tools/local/` and that is not a deliverable. Move it into `.c64-re-tools/local/`. Then give the answer (below). | Each file that you made outside `.c64-re-tools/local/` is a deliverable. |
|
|
100
100
|
|
|
101
101
|
In stage 5, make the recordings before you change the program. A recording needs no names, and its coverage gives the analysis of stage 6 more code. If you cannot get to a part of the program, ask the user how to get to it. Do stages 7 to 9 again until the source is clear. Each generation writes the source again.
|
|
102
102
|
|
|
103
|
+
In stage 10, a base release that is identical to the original proves the source. Do not test the base release more. The default build is different from the base release only in its patches, its leftovers and its loader. Thus test only these differences:
|
|
104
|
+
|
|
105
|
+
- When a patch of the default build changes code that a run executed, replay each recording of the part that has that code. A copy protection check is an example.
|
|
106
|
+
- Write a test scenario only for a test that a replay cannot do. Examples are a program that loads more files from a disk, and a criterion of the user.
|
|
107
|
+
- Do the other tests of stage 1 only when the user selected them.
|
|
108
|
+
|
|
103
109
|
After stage 7, save each routine that other programs can have to the routine library of the workspace. Examples are a music driver, a decruncher and a loader. Ask the user before you make a library.
|
|
104
110
|
|
|
105
111
|
### Deliverables of a full rebuild
|
|
106
112
|
|
|
107
113
|
- `.c64-re-tools/knowledge/` with the program, its entry state, the coverage, the names, the regions, the comments, the modules, the releases, the switches and the patches
|
|
108
|
-
- the
|
|
114
|
+
- the files of the program in `original/`, as the user gave them
|
|
109
115
|
- the generated source
|
|
110
116
|
- the built program and the loader
|
|
111
|
-
- the test scenarios
|
|
117
|
+
- the test scenarios, if you wrote them
|
|
112
118
|
- the recordings in `tests/recordings/`
|
|
113
119
|
- the documentation in `README.md` and `docs/`, when the criteria ask for it
|
|
114
120
|
- the runs in `runs/` that the knowledge gives as evidence
|
|
@@ -121,7 +127,7 @@ All other files that you made are not deliverables. Keep them in `.c64-re-tools/
|
|
|
121
127
|
Give the user a short answer at the end. Do not write a report file. Write a report file only when the user asks for it. The knowledge, `docs/` and the scenarios keep the durable results. The answer has:
|
|
122
128
|
|
|
123
129
|
1. Each criterion of stage 1 and its result, and each exception that the user accepted.
|
|
124
|
-
2. The count of the code ranges that no run executed. The ranges are in
|
|
130
|
+
2. The count of the code ranges that no run executed. The ranges are in `.c64-re-tools/local/generated/src/not_executed.json` for the source in `src/`.
|
|
125
131
|
3. The switches: the name, the kind and the default of each, and the releases that have it on. Also a copy protection that a crack removed and that no release has.
|
|
126
132
|
4. Open questions: what the evidence does not explain.
|
|
127
133
|
|
|
@@ -142,7 +148,7 @@ tools/ scripts for the formats of this program only
|
|
|
142
148
|
README.md the entry page of the documentation
|
|
143
149
|
```
|
|
144
150
|
|
|
145
|
-
Commit each folder of the layout other than `build/`, and `.c64-re-tools/knowledge/`. The knowledge holds the program, the entry state and the coverage, so the project needs no other folder for them. Put all other files that you make in `.c64-re-tools/local/`, also the captures and the coverage maps after you put them into the knowledge. Do not let git ignore a folder of the layout other than `build/`. Do not change the `.gitignore` files of the project.
|
|
151
|
+
Commit each folder of the layout other than `build/`, and `.c64-re-tools/knowledge/`. The knowledge holds the program, the entry state, the bytes of each release and the coverage, so the project needs no other folder for them. Put all other files that you make in `.c64-re-tools/local/`, also the captures and the coverage maps after you put them into the knowledge. Do not let git ignore a folder of the layout other than `build/`. Do not change the `.gitignore` files of the project.
|
|
146
152
|
|
|
147
153
|
If the project has a layout, use that layout.
|
|
148
154
|
|
|
@@ -72,10 +72,10 @@ Each flag applies only to the commands in the table. On another command, the scr
|
|
|
72
72
|
|
|
73
73
|
| Flag | Command | Effect |
|
|
74
74
|
|---|---|---|
|
|
75
|
-
| `--out <dir>` | `generate` | The folder for the source files. It is necessary. The script writes over the files of an earlier run. It removes a generated `.asm` file that this run does not write. A run without `--loader` keeps `loader.asm`,
|
|
75
|
+
| `--out <dir>` | `generate` | The folder for the source files. It is necessary. The script writes over the files of an earlier run. It removes a generated `.asm` file that this run does not write, also in a folder of `--out`. A folder with a generated `main.asm` is the source of another space, and it stays. A run without `--loader` keeps `loader.asm`, the loader program, `start_screen.asm` and `start_screen_stage.asm` of an earlier run. `staleLoader` tells when they are of another knowledge revision. |
|
|
76
76
|
| `--entry <address>` | `generate` | An address where code starts. Give the flag again for more addresses. There is no default. |
|
|
77
77
|
| `--space <space>` | `generate` | The knowledge space: `c64`, `drive8`, `loading`, or `bank0` to `bank255`. The default is `c64`. `--loader` and the platform names apply only to `c64`. The coverage is the coverage of the space. |
|
|
78
|
-
| `--loader` | `generate` | Also write `loader.asm` and
|
|
78
|
+
| `--loader` | `generate` | Also write `loader.asm` and the loader program, and `start_screen.asm` when the knowledge has a start screen. A start screen of a captured stage also gives `start_screen_stage.asm`. The script writes the loader program only after the check of the new loader ran. Else the loader program of an earlier run stays. It needs a capture in the knowledge. The default is no loader. |
|
|
79
79
|
| `--analyzer-names` | `generate` | Name an address without a name of the user or the LLM, and without a platform name, with its analyzer name, for example `FUN_17e2`. Without the flag, the source makes its own name, for example `l_17e2`. |
|
|
80
80
|
| `--to <folder>` | `export` | The folder of the new project. It is necessary. The script also writes `<folder>.zip` beside the folder. |
|
|
81
81
|
| `--name <name>` | `export` | The name of `baseline/<name>.prg` and `build/<name>.prg`. The default is the name of the folder. |
|
|
@@ -89,7 +89,8 @@ Each flag applies only to the commands in the table. On another command, the scr
|
|
|
89
89
|
|
|
90
90
|
### `generate --out <dir>`
|
|
91
91
|
|
|
92
|
-
The command writes the source files
|
|
92
|
+
The command writes the source files in `--out`. Then it checks them.
|
|
93
|
+
The folder `--out` gets only source files. The command writes `source-map.json` and `not_executed.json` in `.c64-re-tools/local/generated/<dir>/`. Git ignores this folder.
|
|
93
94
|
The same knowledge always gives the same source.
|
|
94
95
|
Do not edit the generated files. The next run writes over them. The values in `config.asm` are the one exception.
|
|
95
96
|
To make the source better, change the project knowledge. Then generate again.
|
|
@@ -97,7 +98,7 @@ To make the source better, change the project knowledge. Then generate again.
|
|
|
97
98
|
`body` holds these fields:
|
|
98
99
|
|
|
99
100
|
- `result`: `PASS` when every check passes, else `FAIL`.
|
|
100
|
-
- `files`: the files
|
|
101
|
+
- `files`: the files that the command wrote, each with `out`, `bytes` and `sha256`. `sourceMap` names `source-map.json`.
|
|
101
102
|
- `removed`: the files of an earlier run that the script removed.
|
|
102
103
|
- `instructions`, `dataBytes` and `undecodedBytes`.
|
|
103
104
|
- `labels`: `named` labels from the knowledge, and `generated` labels `l_xxxx`.
|
|
@@ -110,7 +111,7 @@ To make the source better, change the project knowledge. Then generate again.
|
|
|
110
111
|
- `asBytes`: the instructions that the source has as bytes.
|
|
111
112
|
- `notExecuted`: with coverage, the count of instructions that no run executed, and their ranges. `rest` names `not_executed.json`, which has all the ranges. Each range there has its source `file` and the `routine` before it.
|
|
112
113
|
- `unusedModules`: modules whose start is in no segment of the program. Often the program does not hold the code that the knowledge describes.
|
|
113
|
-
- `leftovers`: the bytes that nothing uses, with `bytes` and each range with its `file`. See "The leftovers". `noCoverage` tells that the knowledge has no coverage, so no range is a leftover.
|
|
114
|
+
- `leftovers`: the bytes that nothing uses, with `bytes` and each range with its `file`. See "The leftovers". `noCoverage` tells that the knowledge has no coverage, so no range is a leftover. `changed` gives the ranges that are `added` to the leftovers and `removed` from them since the earlier run in `--out`.
|
|
114
115
|
- `operandExpressions`: the count of instructions with an operand expression.
|
|
115
116
|
- `operandsAsNumbers`: each operand expression that the source has as a number, with its `address`, `expression` and `reason`.
|
|
116
117
|
- `macroUses`: the count of macro uses in the source.
|
|
@@ -118,7 +119,7 @@ To make the source better, change the project knowledge. Then generate again.
|
|
|
118
119
|
- `patchesNotWritten`: each patch that the source does not have, with its range, `switch` and `reason`.
|
|
119
120
|
- `switches`, `default`, `releases`: the checks of the switches. See "Switches and releases".
|
|
120
121
|
- `loader`: the check of the loader. See "The loader".
|
|
121
|
-
- `staleLoader`: a run without `--loader` kept `loader.asm` and
|
|
122
|
+
- `staleLoader`: a run without `--loader` kept `loader.asm` and the loader program of another knowledge revision. `files` gives the files. `revision` gives the revision of `loader.asm`. Without `revision`, `loader.asm` does not give one. `noEntryState: true` tells that the knowledge has no entry state for a new loader. A change in a space that the loader does not hold does not make the loader stale. The loader holds space `c64` and the space of the stage of the start screen.
|
|
122
123
|
|
|
123
124
|
`result` is `FAIL` for each of these:
|
|
124
125
|
|
|
@@ -126,7 +127,7 @@ To make the source better, change the project knowledge. Then generate again.
|
|
|
126
127
|
- The entry is in no segment of the program.
|
|
127
128
|
- A patch is in `patchesNotWritten`.
|
|
128
129
|
- A switch or the default build does not fit.
|
|
129
|
-
- A release does not give its
|
|
130
|
+
- A release does not give its bytes.
|
|
130
131
|
- The loader is not verified.
|
|
131
132
|
|
|
132
133
|
`hint` gives the action for each finding. When a change of the project knowledge corrects a finding, `nextAction` is the same `generate` command. Run it after the change. A `PASS` without findings gives a `hint` and no `nextAction`.
|
|
@@ -151,7 +152,7 @@ Do these actions for the findings:
|
|
|
151
152
|
#### The source files
|
|
152
153
|
|
|
153
154
|
- `main.asm` sets the address of each segment. It includes the files in address order.
|
|
154
|
-
- Each module in the knowledge is one file. A module starts at its address. It stops at the next module or at the end of its segment. Without modules, each segment is one file, `segment_xxxx.asm`.
|
|
155
|
+
- Each module in the knowledge is one file. A module starts at its address. It stops at the next module or at the end of its segment. The file of a module can be in a folder, for example `music/driver.asm`. Without modules, each segment is one file, `segments/segment_xxxx.asm`.
|
|
155
156
|
- `constants.asm` holds the names of addresses outside the program, for example `EXTCOL = $d020`. It also holds the register names in the program, for example `RASTER = $d012`. The names are in groups by memory area, in address order. Drive code and banks have one group only.
|
|
156
157
|
- The side comment of a constant is the knowledge comment of the address. Without a comment, it is the platform meaning. When the knowledge name is not the platform name, the platform name comes first. For an I/O mirror without a meaning, the comment gives the register that the mirror repeats.
|
|
157
158
|
- After the side comment, `Used:` counts how the source uses the name. The kinds are `read`, `written`, `modified`, `called`, `jumped to`, `jumped through`, `branched to`, `pointer`, `address`, `table` and `macro argument`. `address` is an immediate operand expression. `table` is an entry in a table of addresses.
|
|
@@ -160,7 +161,7 @@ Do these actions for the findings:
|
|
|
160
161
|
- When the knowledge has a start screen, `config.asm` also has `START_SCREEN = 1`. Set it to 0 to start the program at once. Then assemble `loader.asm` again.
|
|
161
162
|
- `start_screen.asm` is the code that shows the start screen and waits. It is the same for each program. `loader.asm` gives it the values of the start screen.
|
|
162
163
|
- `switches.asm` holds each release of the knowledge. `main.asm` and `loader.asm` include it first. The script writes it only when the knowledge has switches or releases, or when the source has leftovers. For each release, a block `!ifdef RELEASE_<label>` gives each switch the value of that release.
|
|
163
|
-
- `leftover_xxxx.asm` holds a range of leftovers. See "The leftovers".
|
|
164
|
+
- `leftovers/leftover_xxxx.asm` holds a range of leftovers. See "The leftovers".
|
|
164
165
|
- `macros.asm` holds the macros of the knowledge. `main.asm` and `loader.asm` include it.
|
|
165
166
|
|
|
166
167
|
#### Names in the source
|
|
@@ -194,15 +195,16 @@ Do these actions for the findings:
|
|
|
194
195
|
|
|
195
196
|
#### The leftovers
|
|
196
197
|
|
|
197
|
-
A leftover is a range of the program that nothing uses: unused code, old copies and old data. The script finds the leftovers from the coverage, as the export finds its free ranges (see "The free ranges"). The start screen, the patches
|
|
198
|
+
A leftover is a range of the program that nothing uses: unused code, old copies and old data. The script finds the leftovers from the coverage, as the export finds its free ranges (see "The free ranges"). The start screen, the patches and the addresses that the code of a patch names are never leftovers. A macro use in code that nothing uses is in the leftover with that code. A leftover never cuts a macro use in two.
|
|
198
199
|
|
|
199
|
-
- Each range of leftovers is a file `leftover_xxxx.asm`. When a range cuts a module, the module continues after the range in `<module>_xxxx.asm
|
|
200
|
+
- Each range of leftovers is a file `leftovers/leftover_xxxx.asm`. When a range cuts a module, the module continues after the range in `<module>_xxxx.asm`, in the folder of the module. The module in the knowledge does not change.
|
|
200
201
|
- `main.asm` builds a leftover file only when `LEFTOVERS` is 1. When it is 0, the build skips the bytes. Thus the addresses after the range do not change.
|
|
201
202
|
- `config.asm` has `LEFTOVERS = 0`. Thus the default build is the clean program, without the leftovers.
|
|
202
|
-
- Each release has `LEFTOVERS = 1`. Thus the build of a release gives the bytes of
|
|
203
|
-
-
|
|
203
|
+
- Each release has `LEFTOVERS = 1`. Thus the build of a release gives the bytes of the release.
|
|
204
|
+
- The loader program never has the leftovers. The loader does not copy them, and the memory there keeps the bytes that were in it before.
|
|
204
205
|
- Without coverage, no range is a leftover. Put the coverage of the runs into the project knowledge. Then generate again.
|
|
205
|
-
-
|
|
206
|
+
- When `leftovers.changed` has ranges, the default build and the loader program now leave out other bytes. A test that observes the `added` bytes on the loader program gets other values there. Fill the `added` ranges in the test of the leftovers. In a test that compares them, exclude them with the reason that they are leftovers.
|
|
207
|
+
- A leftover can be wrong when the coverage does not show a use. For example, the VIC-II reads a range, or the program reads a range before it writes it. Then a test of the loader program fails. Record the region in the project knowledge, or put the coverage of more runs into it. Do not change the source.
|
|
206
208
|
|
|
207
209
|
#### Switches and releases
|
|
208
210
|
|
|
@@ -213,7 +215,7 @@ The command does these checks. They use the defaults and the values of the knowl
|
|
|
213
215
|
1. `check`: the build of the base release must give the program byte by byte. In this build, each switch has its base value, and `LEFTOVERS` is 1.
|
|
214
216
|
2. `switches`: each switch alone at its other value. The build must have the same length as the base release. It can change bytes only in the patches of the switch.
|
|
215
217
|
3. `default`: the default build. It must have the same length. It can change bytes only in the patches of the switches in `default.in` and in the leftovers.
|
|
216
|
-
4. `releases`: each release, built with `RELEASE_<label>=1`, against the
|
|
218
|
+
4. `releases`: each release, built with `RELEASE_<label>=1`, against the bytes of the release in the project knowledge.
|
|
217
219
|
|
|
218
220
|
Each item of `switches` has `name`, `kind`, `default`, `base`, `define` and the patches.
|
|
219
221
|
|
|
@@ -225,13 +227,12 @@ Each item of `switches` has `name`, `kind`, `default`, `base`, `define` and the
|
|
|
225
227
|
|
|
226
228
|
`default` has `in`, `result` and `changedBytes`, as in `switches`. When `default` has `overflow` and the message `turn on one of them`, two alternatives are in the default build. Give one of the switches the default of the base release.
|
|
227
229
|
|
|
228
|
-
Each item of `releases` has `label`, `base`, `
|
|
230
|
+
Each item of `releases` has `label`, `base`, `define` and `result`. The check compares the build with each segment of the release. The build compare of the assembler does the same.
|
|
229
231
|
|
|
230
|
-
- `identical`: the build gives the bytes of the
|
|
232
|
+
- `identical`: the build gives the bytes of each segment of the release.
|
|
231
233
|
- `different`: the release has bytes that no patch gives. Compare the release with the program. Then record a switch and a patch for each difference.
|
|
232
|
-
- `layout differs`: the release has other segments than the program. Patches cannot move code. This result does not fail the run.
|
|
233
|
-
- `file changed`: the file is not the file that the knowledge recorded. Put back the file, or record the release again in the project knowledge.
|
|
234
234
|
- `does not assemble`: read the ACME diagnostics.
|
|
235
|
+
- `notInRelease`: the ranges of the program that the release does not have. The check does not compare them.
|
|
235
236
|
|
|
236
237
|
The script writes a patch only when its range is complete items of one file. A patch cannot cut an instruction. Its switch name cannot be a name of the source.
|
|
237
238
|
The script writes a macro use only when the use gives the bytes of the program. A label inside the range of a use also keeps the instructions. The macro line has no place for the label.
|
|
@@ -244,7 +245,14 @@ Build the program from the source in these ways:
|
|
|
244
245
|
|
|
245
246
|
#### The loader
|
|
246
247
|
|
|
247
|
-
`--loader` writes `loader.asm`
|
|
248
|
+
`--loader` writes `loader.asm` in `--out`. It assembles `loader.asm` to the loader program in `build/`. Git ignores `build/`. The name of the loader program tells its build:
|
|
249
|
+
|
|
250
|
+
- `clean_loader.prg`: each value of `config.asm` is its default. This is the clean program.
|
|
251
|
+
- `custom_<switches>_loader.prg`: the names of the switches that are not at their default. A switch that is off has `no_` before its name, for example `custom_no_start_screen_loader.prg`.
|
|
252
|
+
|
|
253
|
+
The symbols of the loader program are in `build/symbols/<name>.json`, for example `build/symbols/clean_loader.json`. They hold the labels of `loader.asm`, `main.asm` and `start_screen_stage.asm`. Give this file to a test of the loader program as its symbols. When the name changes, the script removes the loader program of the earlier run and its symbols.
|
|
254
|
+
|
|
255
|
+
The loader does these steps:
|
|
248
256
|
|
|
249
257
|
1. `10 SYS 2061` starts it.
|
|
250
258
|
2. It stops the interrupts and makes all RAM visible. It moves its copier to two free pages.
|
|
@@ -258,26 +266,26 @@ The copy table, the copier and the jump use labels, not numbers. `loader_from_xx
|
|
|
258
266
|
|
|
259
267
|
The loader changes the free stack byte below the stack pointer (`stackByte`). It does not set the SID, the time of day of the CIAs, the CIA interrupt flags or the interrupt registers of the VIC-II. A program that reads SID voice 3 for random numbers can thus give a different result. A start screen writes the colour RAM, and the loader does not set it again. When you compare the original and the rebuild, observe after the program sets its own random numbers.
|
|
260
268
|
|
|
261
|
-
The script builds and checks
|
|
269
|
+
The script builds and checks the loader program with the values of `config.asm`. With the defaults, the loader program is the clean program: no copy protection, all corrections and no leftovers. The entry state is the state of the base release. For a loader of a release, build `loader.asm` with the build option `--release <label>`. That loader also does not have the leftovers.
|
|
262
270
|
|
|
263
271
|
The start screen:
|
|
264
272
|
|
|
265
273
|
- The start screen needs the VIC-II values of the entry state. Its screen, bitmap, charset and colours must be in a segment of the program, or in a captured stage. See "The start screen of a captured stage".
|
|
266
274
|
- With a start screen, the copier uses three pages, not two.
|
|
267
|
-
- The start screen is part of the clean build only.
|
|
275
|
+
- The start screen is part of the clean build only. The loader program always shows it. A release build has no start screen, and `LEFTOVERS = 1` also turns it off.
|
|
268
276
|
- To start the program at once, set `START_SCREEN = 0` in `config.asm`, and assemble `loader.asm`. Do not define `START_SCREEN` on the command line of the build: `config.asm` sets it.
|
|
269
|
-
- A test that runs
|
|
277
|
+
- A test that runs the loader program stops at the start screen, because the start screen waits for a key. Run until `loader_start_screen_wait`. Then set the PC to `loader_start_screen_continue`.
|
|
270
278
|
|
|
271
279
|
`loader` holds these fields:
|
|
272
280
|
|
|
273
281
|
- `program`, the `copies` in their order, `copier` and `stackByte`.
|
|
274
|
-
- `verified: true`: the check ran
|
|
282
|
+
- `verified: true`: the check ran the loader program to its jump to the entry. There, the memory, $00/$01, the registers and the VIC-II are equal to the entry state. The raster line and the CIA values are also equal. An interrupt can run right at the entry, as in the original program.
|
|
275
283
|
- `limits`: each CIA value that the loader cannot set as it was at the entry. An old capture has no CIA values. Then capture the program again at its entry point.
|
|
276
284
|
- `startScreen`: with a start screen, `shown: true` when the VIC-II had the values of the start screen, and `waits: true` when the start screen waited without a key. `wait` and `continue` are the addresses of the wait and of the code after it. The check sets the PC to `continue`, and then runs the loader to its jump.
|
|
277
|
-
- `packed`: `packedBytes` and `unpackedBytes` of the packed form. With a start screen of a captured stage, this is the packed program in
|
|
278
|
-
- `stage`: the show stage of a start screen of a captured stage. It has the `space` of the stage and the address of the show `code`. It also has the `bytes` of the stage in
|
|
279
|
-
- When the check of
|
|
280
|
-
- `kept`: when the result has no new
|
|
285
|
+
- `packed`: `packedBytes` and `unpackedBytes` of the packed form. With a start screen of a captured stage, this is the packed program in the loader program.
|
|
286
|
+
- `stage`: the show stage of a start screen of a captured stage. It has the `space` of the stage and the address of the show `code`. It also has the `bytes` of the stage in the loader program, the `stash` copies, `packedBytes` and `unpackedBytes`. `startScreen.stage` names the space.
|
|
287
|
+
- When the check of the loader program cannot run, the script does not write a loader program. The loader program of an earlier run stays as it was. `loader.asm` is new. `reason` tells why the check did not run.
|
|
288
|
+
- `kept`: when the result has no new loader program, the paths of the loader programs of an earlier run. They are not of this source.
|
|
281
289
|
|
|
282
290
|
Do these actions when `verified` is `false`:
|
|
283
291
|
|
|
@@ -287,8 +295,8 @@ Do these actions when `verified` is `false`:
|
|
|
287
295
|
| `reason` about the packed form | If a tool is missing, stop the task and give the message to the user. If the free ranges are too small, write the loader by hand. If the check of the unpack fails, give the reason to the user. |
|
|
288
296
|
| `reason` that the source does not assemble | Correct the source first. The loader includes the source. |
|
|
289
297
|
| `reason` about the start screen | Correct the start screen in the project knowledge, or capture the program again with the start screen in memory. If the start screen is not necessary, remove it from the project knowledge. |
|
|
290
|
-
| `reason` about the show stage | If the reason names the coverage of the stage, run the stage with coverage. Put the map into the project knowledge in the space of the stage. If the memory is too small, capture the stage again with less memory. If a tool is missing, stop the task and give the message to the user. |
|
|
291
|
-
| `reason` that the check of
|
|
298
|
+
| `reason` about the show stage | If the reason names the coverage of the stage, run the stage with coverage. Put the map into the project knowledge in the space of the stage. If the memory is too small, capture the stage again with less memory. If a tool is missing, stop the task and give the message to the user. If `start_screen_stage.asm` does not assemble, stop the task and give the reason to the user. The reason names the file in `.c64-re-tools/local/` with the source that failed. |
|
|
299
|
+
| `reason` that the check of the loader program did not run | Stop the task and give the reason to the user. When the user tells you that the emulator is available, run the same command again. |
|
|
292
300
|
| `differences` | The loader ran. The list gives the bytes and the registers that are not equal. |
|
|
293
301
|
| `stop` | The loader did not get to its copier or its jump. `stop` gives the address and `port`, the value of $01. `history` gives the last 16 instructions. `cause` gives the first byte of the copier or of a copy that is not correct. |
|
|
294
302
|
|
|
@@ -299,8 +307,8 @@ Often the loading stage of a program shows a picture that is not in memory at th
|
|
|
299
307
|
The loader then always has the packed form, and the start screen is a program of its own in front of it:
|
|
300
308
|
|
|
301
309
|
1. Exomizer packs the program with the copier. This is the packed loader.
|
|
302
|
-
2. Exomizer packs the packed loader, the bytes of the stage and the show code into
|
|
303
|
-
3. When
|
|
310
|
+
2. Exomizer packs the packed loader, the bytes of the stage and the show code into the loader program.
|
|
311
|
+
3. When the loader program starts, Exomizer unpacks these parts. The program stays packed. The bytes of the packed loader under the stage go to a stash in free memory.
|
|
304
312
|
4. The show code shows the start screen with `start_screen.asm`. With a call, it sets $01 to $37, starts the interrupts and calls the routine.
|
|
305
313
|
5. It waits for a key or a fire button, as the start screen in the program does.
|
|
306
314
|
6. It stops the interrupts and the sound, and it stops the screen. It sets the CIA timers as RUN leaves them.
|
|
@@ -309,26 +317,26 @@ The loader then always has the packed form, and the start screen is a program of
|
|
|
309
317
|
The program is packed while the screen shows. Thus the picture and the tune have more free memory.
|
|
310
318
|
|
|
311
319
|
- The script puts everything in memory. It does not matter where the stage keeps its bytes, if the memory has enough room.
|
|
312
|
-
-
|
|
320
|
+
- The loader program has only the bytes of the stage that the start screen uses. These are the screen, the bitmap and the charset. With a call, they are also each byte of the stage that is not free from the call, as in "The free ranges". A call thus needs the coverage of the stage.
|
|
313
321
|
- With colours from the colour RAM of the capture, the show code holds the 1000 colours. It copies them to the colour RAM.
|
|
314
322
|
- The patches of the stage are in at the defaults of their switches. Thus a patch under a switch can remove the text of a crack from the picture.
|
|
315
|
-
- `start_screen_stage.asm` holds the show code and the bytes of the stage. Do not edit it. To make
|
|
323
|
+
- `start_screen_stage.asm` holds the show code and the bytes of the stage. Do not edit it. To make the loader program again, run `generate --loader`.
|
|
316
324
|
- The show stage needs Exomizer. The show code needs free memory in $0400-$9fff or $c000-$cfff. When the memory is too small, the reason gives the largest free ranges.
|
|
317
|
-
- The check runs
|
|
325
|
+
- The check runs the loader program to `loader_start_screen_wait` of the show stage. There, it compares the VIC-II with the start screen, the screen bytes in memory with the stage, and the colour RAM with the capture. Then it sets the PC to `loader_start_screen_continue`, and it checks the loader as usual.
|
|
318
326
|
|
|
319
327
|
#### The packed loader
|
|
320
328
|
|
|
321
329
|
A loader file that loads into $d000 or higher writes the I/O area. When the program is too large for one loader file, `loader.asm` has the packed form:
|
|
322
330
|
|
|
323
331
|
- `loader.asm` holds only the copier and the bytes below $0400. The segments at $0400 and higher are not in `loader.asm`. Between its free ranges, `loader.asm` holds the bytes of the program.
|
|
324
|
-
-
|
|
332
|
+
- The loader program is the build of `main.asm` from $0400 and the build of `loader.asm`, packed into one file. Where the two builds overlap, the loader program has the bytes of `loader.asm`.
|
|
325
333
|
- The jump to the entry uses the address of the entry, not its label.
|
|
326
334
|
|
|
327
335
|
To make the packed loader for other switch values, do these steps:
|
|
328
336
|
|
|
329
|
-
1. Assemble `main.asm`
|
|
330
|
-
2. Assemble `loader.asm` to `build/
|
|
331
|
-
3. Pack the two files into `build/
|
|
337
|
+
1. Assemble `main.asm` without an output path. The build name of the program tells the switch values, for example `build/custom_trainer.prg`. The leftovers are $00 in this build.
|
|
338
|
+
2. Assemble `loader.asm` without an output path, for example to `build/custom_trainer_loader.prg`. This is the copier.
|
|
339
|
+
3. Pack the two files into `build/custom_trainer_packed.prg`. The start address is the copier address in the comment at the start of `loader.asm`. The memory configuration at the exit is `$34`.
|
|
332
340
|
|
|
333
341
|
These steps do not work when a segment starts below $0400. They also do not work when a patch is between the free ranges of `loader.asm`. In these cases, use `generate --loader` for the base release.
|
|
334
342
|
|
|
@@ -387,6 +395,16 @@ A block of code stops after RTS, RTI, JMP, BRK or a JAM, and before a gap. A blo
|
|
|
387
395
|
- No run of the coverage executed it.
|
|
388
396
|
- No path gets to it from the entry, the hardware vectors or the code that stays. A path is a call, a jump, a branch, a reference of the knowledge or an operand expression. An entry of a table, and two immediate operands that give its address, are paths too.
|
|
389
397
|
|
|
398
|
+
Two immediate operands give an address only in these cases:
|
|
399
|
+
|
|
400
|
+
- The code stores the low byte and the high byte to two adjacent addresses outside $d000-$dfff.
|
|
401
|
+
- The code calls a routine with the low byte and the high byte in two registers.
|
|
402
|
+
- The code pushes the high byte and then the low byte onto the stack.
|
|
403
|
+
|
|
404
|
+
An operand expression of the knowledge at an immediate operand replaces these cases for that operand. Thus an operand expression with a constant stops a wrong address.
|
|
405
|
+
|
|
406
|
+
A call or a jump to ROM is not a path. The coverage shows where the CPU sees ROM. Without coverage, $01 of the entry state shows it. Known code of the knowledge is never ROM.
|
|
407
|
+
|
|
390
408
|
Code that a run executed always stays. `unreachableExecuted` lists the executed code that the entry and the vectors do not get to. An example is a copy check whose call the export removed. Give its `drop` value to `export` to make it free.
|
|
391
409
|
|
|
392
410
|
Data becomes free only when all of these are true:
|
|
@@ -394,7 +412,7 @@ Data becomes free only when all of these are true:
|
|
|
394
412
|
- Its region type is `bytes`, `words`, a table of addresses, `petscii`, `workspace` or `unused`.
|
|
395
413
|
- No run read, wrote or executed a byte of it.
|
|
396
414
|
- No code that stays reads it or names it. No table that stays has an entry in it.
|
|
397
|
-
- It is not
|
|
415
|
+
- It is not in the BASIC line that starts the program, and not at $fffa-$ffff.
|
|
398
416
|
|
|
399
417
|
The coverage does not show the reads of the VIC-II. Thus `charset`, `sprite`, `bitmap` and `screen` data stay, unless `--drop` names them. The bytes of the start screen always stay. Bytes without a region also stay.
|
|
400
418
|
|
|
@@ -404,7 +422,7 @@ The entry is the entry of the knowledge. Without it, the entry is the address of
|
|
|
404
422
|
|
|
405
423
|
```text
|
|
406
424
|
README.md the steps to build and test, the free ranges and the origin
|
|
407
|
-
src/ main.asm, constants.asm, macros.asm, the modules and loader.asm
|
|
425
|
+
src/ main.asm, constants.asm, macros.asm, the modules in their folders and loader.asm
|
|
408
426
|
baseline/<name>.prg the exported program, and baseline/<name>.json with its symbols
|
|
409
427
|
tests/ the tests of the project, changed for the new program
|
|
410
428
|
.c64-re-tools/knowledge/ the knowledge of the new program
|
|
@@ -429,7 +447,7 @@ tests/ the tests of the project, changed for the new program
|
|
|
429
447
|
5. Record names, comments, regions and modules in the project knowledge.
|
|
430
448
|
6. Run `generate` again. Do steps 4 to 6 again until the source is clear.
|
|
431
449
|
7. Assemble `main.asm` to a program. This is the default build. For a release, give the build option `--release <label>`.
|
|
432
|
-
8. For an unpacked program, run `generate` with `--loader` at the end. Compare
|
|
450
|
+
8. For an unpacked program, run `generate` with `--loader` at the end. Compare the loader program with the original program in a test.
|
|
433
451
|
9. To start a new program from the rebuild, run `export`.
|
|
434
452
|
|
|
435
453
|
---
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
// tells what stays. Without coverage nothing becomes free by itself.
|
|
11
11
|
|
|
12
12
|
import { type AddressRange, COVERAGE, formatC64Address, pointerTableEntries, POINTER_TABLE_TYPES, type PointerTableType } from "#src/c64.ts";
|
|
13
|
+
import { symbolsPath } from "#src/build-name.ts";
|
|
13
14
|
import { Refusal } from "#src/errors.ts";
|
|
14
15
|
import { NO_FALL_THROUGH, type Root, separate } from "#src/knowledge/separate.ts";
|
|
15
16
|
import type { RegionType } from "#src/knowledge/schema.ts";
|
|
@@ -28,8 +29,19 @@ const CODE_TYPES: readonly RegionType[] = ["code", "jumps", "dual-use"];
|
|
|
28
29
|
/** The hardware vectors $fffa-$ffff: they stay when the image holds them. */
|
|
29
30
|
const VECTORS: AddressRange = { start: 0xfffa, end: 0xffff };
|
|
30
31
|
|
|
31
|
-
/**
|
|
32
|
-
const
|
|
32
|
+
/** The I/O area: two immediates stored there are chip values, such as a timer latch, not an address. */
|
|
33
|
+
const IO_AREA: AddressRange = { start: 0xd000, end: 0xdfff };
|
|
34
|
+
|
|
35
|
+
/** The registers that each instruction changes, other than by a load of an immediate or a transfer. */
|
|
36
|
+
const WRITES_A = new Set(["lda", "adc", "sbc", "and", "ora", "eor", "pla", "lax", "anc", "asr", "arr", "ane", "lxa", "las", "slo", "rla", "sre", "rra", "isc"]);
|
|
37
|
+
const WRITES_X = new Set(["ldx", "inx", "dex", "tsx", "lax", "sbx", "lxa", "las"]);
|
|
38
|
+
const WRITES_Y = new Set(["ldy", "iny", "dey"]);
|
|
39
|
+
/** The registers that a JSR gets an address in, low byte first, as the KERNAL and BASIC routines get a pointer. */
|
|
40
|
+
const CALL_PAIRS = [
|
|
41
|
+
["x", "y"],
|
|
42
|
+
["a", "y"],
|
|
43
|
+
["a", "x"],
|
|
44
|
+
] as const;
|
|
33
45
|
|
|
34
46
|
export interface DropInput {
|
|
35
47
|
segments: readonly AddressRange[];
|
|
@@ -41,8 +53,12 @@ export interface DropInput {
|
|
|
41
53
|
coverage?: Uint8Array;
|
|
42
54
|
regions: ReadonlyArray<{ start: number; end: number; type: RegionType }>;
|
|
43
55
|
references: ReadonlyArray<{ from: number; to: number; kind: string }>;
|
|
44
|
-
/** The addresses that the operand expression of an instruction names, by the address of
|
|
56
|
+
/** The addresses that the operand expression of an instruction names, by the address of each instruction with an operand expression; none for a constant. */
|
|
45
57
|
operandTargets: ReadonlyMap<number, readonly number[]>;
|
|
58
|
+
/** The ranges where the CPU sees ROM and not the RAM of the image: code does not go there, and no address points there. */
|
|
59
|
+
rom?: readonly AddressRange[];
|
|
60
|
+
/** The BASIC line that starts the program: RUN reads it, which no coverage from the entry shows. */
|
|
61
|
+
basic?: AddressRange;
|
|
46
62
|
/** The patch ranges whose bytes the export changed. */
|
|
47
63
|
changed: readonly AddressRange[];
|
|
48
64
|
keep: readonly AddressRange[];
|
|
@@ -115,42 +131,72 @@ function flowsOf(input: DropInput, inImage: (address: number) => boolean, indexe
|
|
|
115
131
|
const reads: DataReference[] = [];
|
|
116
132
|
const { memory } = input;
|
|
117
133
|
const word = (at: number) => memory[at]! | (memory[(at + 1) & 0xffff]! << 8);
|
|
118
|
-
const
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
});
|
|
131
|
-
|
|
134
|
+
const rom = (address: number) => inside(address, input.rom ?? []);
|
|
135
|
+
// The address of a vector, a table or an RTS target in two immediates of one block: the low byte and the high byte
|
|
136
|
+
// go into a pointer (two stores to N and N+1), into the registers of a JSR, or onto the stack (PHA high, PHA low).
|
|
137
|
+
type Immediate = { at: number; value: number } | undefined;
|
|
138
|
+
const registers: { a: Immediate; x: Immediate; y: Immediate } = { a: undefined, x: undefined, y: undefined };
|
|
139
|
+
const stores = new Map<number, NonNullable<Immediate>>();
|
|
140
|
+
const pushes: Immediate[] = [];
|
|
141
|
+
const pair = (low: Immediate, high: Immediate) => {
|
|
142
|
+
if (low === undefined || high === undefined) return;
|
|
143
|
+
const target = low.value | (high.value << 8);
|
|
144
|
+
if (!inImage(target) || rom(target)) return;
|
|
145
|
+
flows.push({ from: low.at, to: target }, { from: low.at, to: (target + 1) & 0xffff });
|
|
146
|
+
reads.push({ from: low.at, start: target, end: target });
|
|
147
|
+
};
|
|
148
|
+
const endBlock = () => {
|
|
149
|
+
registers.a = registers.x = registers.y = undefined;
|
|
150
|
+
stores.clear();
|
|
151
|
+
pushes.length = 0;
|
|
132
152
|
};
|
|
153
|
+
let previousEnd = -2;
|
|
133
154
|
for (const at of [...input.instructions.keys()].sort((a, b) => a - b)) {
|
|
134
155
|
const opcode = memory[at]!;
|
|
135
|
-
const { mode } = OPCODES[opcode]!;
|
|
136
|
-
if (at > previousEnd + 1)
|
|
156
|
+
const { mnemonic, mode } = OPCODES[opcode]!;
|
|
157
|
+
if (at > previousEnd + 1) endBlock();
|
|
137
158
|
previousEnd = at + input.instructions.get(at)! - 1;
|
|
138
159
|
const operand = input.instructions.get(at) === 3 ? word(at + 1) : memory[at + 1]!;
|
|
160
|
+
// The registers: a load of an immediate that no operand expression explains, a transfer, a store, a push, a call.
|
|
161
|
+
const loaded = mode === "imm" && !input.operandTargets.has(at) ? { at, value: operand } : undefined;
|
|
162
|
+
if (WRITES_A.has(mnemonic) || (mode === "imp" && ["asl", "lsr", "rol", "ror"].includes(mnemonic))) registers.a = mnemonic === "lda" ? loaded : undefined;
|
|
163
|
+
if (WRITES_X.has(mnemonic)) registers.x = mnemonic === "ldx" ? loaded : undefined;
|
|
164
|
+
if (WRITES_Y.has(mnemonic)) registers.y = mnemonic === "ldy" ? loaded : undefined;
|
|
165
|
+
if (mnemonic === "tax") registers.x = registers.a;
|
|
166
|
+
if (mnemonic === "tay") registers.y = registers.a;
|
|
167
|
+
if (mnemonic === "txa") registers.a = registers.x;
|
|
168
|
+
if (mnemonic === "tya") registers.a = registers.y;
|
|
169
|
+
const stored = { sta: registers.a, stx: registers.x, sty: registers.y }[mnemonic];
|
|
170
|
+
if ((mode === "zp" || mode === "abs") && ["sta", "stx", "sty"].includes(mnemonic) && !inside(operand, [IO_AREA])) {
|
|
171
|
+
stores.delete(operand);
|
|
172
|
+
if (stored !== undefined) {
|
|
173
|
+
stores.set(operand, stored);
|
|
174
|
+
pair(stored, stores.get((operand + 1) & 0xffff));
|
|
175
|
+
pair(stores.get((operand - 1) & 0xffff), stored);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
if (mnemonic === "pha") {
|
|
179
|
+
pushes.push(registers.a);
|
|
180
|
+
if (pushes.length >= 2) pair(pushes.at(-1), pushes.at(-2));
|
|
181
|
+
}
|
|
182
|
+
if (mnemonic === "pla") pushes.pop();
|
|
183
|
+
if (mnemonic === "jsr") {
|
|
184
|
+
for (const [low, high] of CALL_PAIRS) pair(registers[low], registers[high]);
|
|
185
|
+
registers.a = registers.x = registers.y = undefined;
|
|
186
|
+
}
|
|
139
187
|
switch (mode) {
|
|
140
188
|
case "rel":
|
|
141
189
|
flows.push({ from: at, to: (at + 2 + (operand < 0x80 ? operand : operand - 0x100)) & 0xffff });
|
|
142
190
|
break;
|
|
143
|
-
case "imm":
|
|
144
|
-
immediates.push({ at, value: operand });
|
|
145
|
-
break;
|
|
146
191
|
case "ind":
|
|
147
192
|
reads.push({ from: at, start: operand, end: (operand + 1) & 0xffff });
|
|
148
193
|
if (inImage(operand) && inImage((operand + 1) & 0xffff)) flows.push({ from: at, to: word(operand) });
|
|
149
194
|
break;
|
|
150
195
|
case "abs":
|
|
151
196
|
case "zp":
|
|
152
|
-
if (opcode === 0x20 || opcode === 0x4c)
|
|
153
|
-
|
|
197
|
+
if (opcode === 0x20 || opcode === 0x4c) {
|
|
198
|
+
if (!rom(operand)) flows.push({ from: at, to: operand });
|
|
199
|
+
} else reads.push({ from: at, start: operand, end: operand });
|
|
154
200
|
break;
|
|
155
201
|
case "abx":
|
|
156
202
|
case "aby":
|
|
@@ -165,9 +211,8 @@ function flowsOf(input: DropInput, inImage: (address: number) => boolean, indexe
|
|
|
165
211
|
default:
|
|
166
212
|
break;
|
|
167
213
|
}
|
|
168
|
-
if (NO_FALL_THROUGH.has(opcode))
|
|
214
|
+
if (NO_FALL_THROUGH.has(opcode)) endBlock();
|
|
169
215
|
}
|
|
170
|
-
pairs();
|
|
171
216
|
for (const reference of input.references) {
|
|
172
217
|
if (inside(reference.from, input.changed)) continue;
|
|
173
218
|
if (reference.kind === "call" || reference.kind === "jump" || reference.kind === "pointer") flows.push({ from: reference.from, to: reference.to });
|
|
@@ -275,11 +320,10 @@ export function planDrops(input: DropInput): DropPlan {
|
|
|
275
320
|
|
|
276
321
|
// Data: a region of a droppable type that no run touched and that nothing that stays names.
|
|
277
322
|
const gone = [...input.drop, ...droppedCode];
|
|
278
|
-
const imageStart = Math.min(...input.segments.map((segment) => segment.start));
|
|
279
323
|
const units = automatic
|
|
280
324
|
? regions.filter((region) => {
|
|
281
325
|
if (!DROPPABLE_DATA.includes(region.type) || gone.some((range) => overlaps(range, region))) return false;
|
|
282
|
-
if ([...input.keep, ...input.changed, VECTORS].some((range) => overlaps(range, region))
|
|
326
|
+
if ([...input.keep, ...input.changed, VECTORS, ...(input.basic === undefined ? [] : [input.basic])].some((range) => overlaps(range, region))) return false;
|
|
283
327
|
for (let address = region.start; address <= region.end; address++) if (touched(address)) return false;
|
|
284
328
|
return true;
|
|
285
329
|
})
|
|
@@ -377,7 +421,7 @@ export function rewriteTest(text: string, name: string, symbols: ReadonlyMap<str
|
|
|
377
421
|
if (inside(address, free)) return { reason: `it names ${location}, which is in a free range` };
|
|
378
422
|
} else if (!symbols.has(location)) return { reason: `it names ${location}, which the exported program does not have` };
|
|
379
423
|
}
|
|
380
|
-
const side = (program: string) => ({ program: `${program}.prg`, symbols: `${program}.
|
|
424
|
+
const side = (program: string) => ({ program: `${program}.prg`, symbols: symbolsPath(`${program}.prg`) });
|
|
381
425
|
if (scenario) {
|
|
382
426
|
// Both sides are the exported program now: a step of the original alone (for example a key for its intro) goes, and a step of the rebuild alone runs on both sides.
|
|
383
427
|
const { original: _original, rebuild: _rebuild, steps, ...rest } = test;
|
|
@@ -389,7 +433,7 @@ export function rewriteTest(text: string, name: string, symbols: ReadonlyMap<str
|
|
|
389
433
|
return { kind: "scenario", text: `${JSON.stringify({ ...rest, original: side(`baseline/${name}`), rebuild: side(`build/${name}`), steps: both }, null, 2)}\n` };
|
|
390
434
|
}
|
|
391
435
|
const start = test.start as Record<string, unknown>;
|
|
392
|
-
const symbolsFile = test.symbols === undefined || test.symbols === "none" ? {} : { symbols: `build/${name}.
|
|
436
|
+
const symbolsFile = test.symbols === undefined || test.symbols === "none" ? {} : { symbols: symbolsPath(`build/${name}.prg`) };
|
|
393
437
|
return { kind: "run", text: `${JSON.stringify({ ...test, start: { ...start, program: `build/${name}.prg` }, ...symbolsFile }, null, 2)}\n` };
|
|
394
438
|
}
|
|
395
439
|
|
|
@@ -417,7 +461,7 @@ export function readmeText(input: ReadmeInput): string {
|
|
|
417
461
|
"",
|
|
418
462
|
"## Build",
|
|
419
463
|
"",
|
|
420
|
-
`Assemble \`src/${input.entryFile}\` to \`build/${name}.prg\`, with its symbols in
|
|
464
|
+
`Assemble \`src/${input.entryFile}\` to \`build/${name}.prg\`, with its symbols in \`${symbolsPath(`build/${name}.prg`)}\`.`,
|
|
421
465
|
input.entryFile === "main.asm"
|
|
422
466
|
? "Compare the build with the program in the project knowledge: the source must give that program."
|
|
423
467
|
: "Assemble `src/main.asm` to `.c64-re-tools/local/program.prg`, and compare it with the program in the project knowledge: the source must give that program.",
|
|
@@ -449,7 +493,7 @@ export function readmeText(input: ReadmeInput): string {
|
|
|
449
493
|
"## Files",
|
|
450
494
|
"",
|
|
451
495
|
`- \`src/\`: the source. You own it now: change it as you like.`,
|
|
452
|
-
`- \`baseline/${name}.prg\` and
|
|
496
|
+
`- \`baseline/${name}.prg\` and \`${symbolsPath(`baseline/${name}.prg`)}\`: the exported program and its symbols, the reference of the scenarios.`,
|
|
453
497
|
"- `tests/`: the tests.",
|
|
454
498
|
"- `.c64-re-tools/knowledge/`: the names, comments and memory map of the exported program. They do not follow your changes to the source.",
|
|
455
499
|
"",
|