@henols/c64-re-tools 2.5.0 → 2.5.1-rc.1

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@henols/c64-re-tools",
3
- "version": "2.5.0",
3
+ "version": "2.5.1-rc.1",
4
4
  "description": "Agent-friendly Commodore 64 engineering toolkit for reverse engineering, debugging, development and testing.",
5
5
  "license": "MIT",
6
6
  "author": "Henrik Olsson",
@@ -53,6 +53,7 @@ The knowledge is text in `.c64-re-tools/knowledge/` of the project. Commit that
53
53
  | Write the code of a switch for a range | `patch '$100e-$1010' PROTECTION --code-file no-check.asm` |
54
54
  | List the releases, switches and patches | `switches` |
55
55
  | Record the start screen of the program | `start-screen --mode multicolour --screen '$5c00' --bitmap '$6000' --colours '$8328' --border 0 --background 0` |
56
+ | Record the start screen of a captured stage, and its tune | `start-screen --stage bank1 --call '$9000'` |
56
57
  | Remove the start screen | `unstart-screen` |
57
58
  | Write a macro | `macro inc16 --params dst --body-file inc16.asm` |
58
59
  | Write instructions as one use of a macro | `use '$1005-$100a' inc16 --args ptr` |
@@ -71,7 +72,7 @@ The knowledge is text in `.c64-re-tools/knowledge/` of the project. Commit that
71
72
  - An analyzer name is a second name from DXA, Ghidra or an idiom search, for example `FUN_17e2`. Each analyzer keeps its own name at an address. Get them from `at`, `search` or `symbols --analyzer`.
72
73
  - The generated source uses only the symbols. To use an analyzer name in the source, give the address that name with `rename`.
73
74
  - A symbol name is a label for ACME: a letter or an underscore, then letters, digits or underscores. The knowledge refuses the name of a 6502 instruction, for example `lda`, in upper or lower case.
74
- - A space is `c64` (the default), `drive8` for code in the 1541 drive, or `bank0` to `bank255` for cartridge banks. Drive code and banks use the same addresses as the C64. Thus each space has its own knowledge. A name is unique in one space.
75
+ - A space is `c64` (the default), `drive8` for code in the 1541 drive, or `bank0` to `bank255` for cartridge banks and for a captured stage of the loading. Drive code, banks and stages use the same addresses as the C64. Thus each space has its own knowledge. A name is unique in one space.
75
76
  - A revision id has the form `20261015T214501.123-k3f9qz`. It starts with the date and the time. Give the full id, or a start of the id that only one revision has. Get the ids from `revisions`, or from the `revision` field of a result. The revision `0` is the knowledge before the first revision.
76
77
  - A file of a capture is the `image.json` that the capture of a packed program wrote. Keep the other files of the capture next to it.
77
78
 
@@ -141,14 +142,16 @@ Each flag applies only to the commands in the table. On another command, the scr
141
142
  | `--body <text>` | `macro` | The body of the macro. |
142
143
  | `--body-file <file>` | `macro` | A project file with the body of the macro. |
143
144
  | `--args <x, y>` | `use` | One expression for each param of the macro, as a comma list. |
144
- | `--mode <mode>` | `start-screen` | Necessary. The mode of the VIC-II: `text`, `hires` or `multicolour`. |
145
- | `--screen <address>` | `start-screen` | Necessary. The address of the screen memory: 1000 bytes. |
145
+ | `--mode <mode>` | `start-screen` | The mode of the VIC-II: `text`, `hires` or `multicolour`. Necessary without `--stage`. |
146
+ | `--screen <address>` | `start-screen` | The address of the screen memory: 1000 bytes. Necessary without `--stage`. |
146
147
  | `--bitmap <address>` | `start-screen` | The address of the bitmap: 8000 bytes. `hires` and `multicolour` need it. |
147
148
  | `--charset <address>` | `start-screen` | The address of the charset: 2048 bytes. `text` needs it. |
148
149
  | `--colours <address>` | `start-screen` | The address of the 1000 bytes that the loader copies to the colour RAM. |
149
150
  | `--colour <0-15>` | `start-screen` | One colour for all of the colour RAM, in place of `--colours`. |
150
- | `--border <0-15>` | `start-screen` | Necessary. The border colour. |
151
- | `--background <0-15>` | `start-screen` | Necessary. The background colour. |
151
+ | `--border <0-15>` | `start-screen` | The border colour. Necessary without `--stage`. |
152
+ | `--background <0-15>` | `start-screen` | The background colour. Necessary without `--stage`. |
153
+ | `--stage <space>` | `start-screen` | The space of a captured stage that shows the screen, for example `bank1`. The script takes the mode, the addresses and the colours from the capture. Without it, the bytes are in the program at the entry. |
154
+ | `--call <address>` | `start-screen` | A routine of the stage that the start screen calls before it waits, for example the start of the loading tune. It must return with RTS. It needs `--stage`. |
152
155
 
153
156
  ---
154
157
 
@@ -380,7 +383,9 @@ An operand expression tells the generated source how to write the operand of one
380
383
 
381
384
  ### `release <label>`
382
385
 
383
- A rebuild keeps all of the program: unused bytes, dead code, old copies and leftovers of the development. It keeps a copy protection, a trainer and a cheat in the source. A switch puts each of them in or out of the build. A start screen of the program stays too: record it with `start-screen`. Only a cracktro and the other screens of a crack are not in the rebuild.
386
+ A rebuild keeps all of the program in the source: unused bytes, dead code, old copies and leftovers of the development. The default build and the loader do not have the leftovers. The build of a release has them. It keeps a copy protection, a trainer and a cheat in the source. A switch puts each of them in or out of the build. A start screen of the program stays too: record it with `start-screen`. Only a cracktro and the other screens of a crack are not in the rebuild.
387
+
388
+ Do not write a file of the rebuild by hand, for example a boot file, a packed picture or a script that changes bytes. Record each change in the knowledge, and generate the source.
384
389
 
385
390
  - A release is a PRG or the `image.json` of a capture, in a folder that git keeps, for example `original/`. The script refuses a file in `.c64-re-tools/local/`.
386
391
  - A label is upper case, for example `ORIGINAL`, `FIRESTAR` or `V2`.
@@ -398,15 +403,40 @@ A rebuild keeps all of the program: unused bytes, dead code, old copies and left
398
403
  A start screen is a loading screen, a title screen or a presentation screen of the program itself. The loader of the generated source shows it before the program starts. Then the loader waits for a key, or for a fire button on joystick port 1 or 2.
399
404
 
400
405
  - Record only a screen of the program itself. Do not record a screen of a crack, for example a picture, an intro or a credit screen of a crack group.
401
- - The bytes of the screen must be in the program of the knowledge at the entry. Thus capture the program while the bytes of the screen are in memory.
406
+ - If a release changed the screen of the program, stop and ask the user how to deal with it. An example is a picture with the text of a crack in it. Do not decide alone. Give the user these options:
407
+ 1. Record patches under a switch that take out the change.
408
+ 2. Use the screen as it is.
409
+ 3. Do not record a start screen.
410
+ - The bytes of the screen must be in the program of the knowledge at the entry, or in a captured stage.
411
+
412
+ #### A start screen of a captured stage
413
+
414
+ Use this when a stage of the loading shows the screen, and the program at the entry does not have it. Do these steps:
415
+
416
+ 1. Capture the stage while it shows the screen. Do not exclude the memory of the screen.
417
+ 2. Put the capture into the knowledge in a space of its own, for example `image stage/image.json --space bank1`.
418
+ 3. If the stage plays a tune or does other work during the screen, find the routine that starts it. Run the stage with coverage while that routine runs. Put the map into the knowledge with `coverage <map> --space bank1`.
419
+ 4. Record the start screen with `start-screen --stage bank1`, and with `--call` for the routine.
420
+
421
+ - The script takes the mode, the screen, the bitmap or the charset, the colours and the colour RAM from the capture. Do not find the addresses or the colours yourself.
422
+ - The generated source puts the screen in memory. It does not matter where the stage keeps its bytes, if the memory has enough room.
423
+ - A flag that you give replaces the value of the capture. Give a flag only to correct a value.
424
+ - A capture of an older version has no colour RAM. Then capture the stage again.
425
+
426
+ #### A start screen in the program
427
+
428
+ - Capture the program while the bytes of the screen are in memory.
402
429
  - Get the mode, the addresses and the colours from the VIC-II while the original program shows the screen.
403
- - The colour RAM is not in the capture. Find the 1000 colour bytes in the program: compare them with the colour RAM at $d800 while the original shows the screen. Give their address with `--colours`. If the program does not have them, give one colour with `--colour`.
430
+ - Find the 1000 colour bytes in the program: compare them with the colour RAM at $d800 while the original shows the screen. Give their address with `--colours`. If the program does not have them, give one colour with `--colour`.
431
+
432
+ #### The rules of the VIC-II
433
+
404
434
  - `text` needs `--charset`. `hires` and `multicolour` need `--bitmap`. `text` and `multicolour` need `--colours` or `--colour`. `hires` uses neither.
405
435
  - The screen is at a step of $0400, the bitmap at a step of $2000 and the charset at a step of $0800. They must be in one VIC bank of 16 KB.
406
436
  - In VIC bank 0 and 2, the VIC-II reads the character ROM at $1000-$1fff of the bank. A screen or a bitmap cannot be there. A charset at $1000 or $1800 of the bank is the character ROM.
407
437
  - No part can be in $0000-$03ff. The colours cannot be in $d000-$dfff.
408
438
  - A space has one start screen, and only the space `c64` has one. A write replaces the start screen of the knowledge.
409
- - The generated source has the switch `START_SCREEN`. Thus no symbol and no switch can have that name.
439
+ - The generated source has the switches `START_SCREEN` and `LEFTOVERS`. Thus no symbol and no switch can have these names.
410
440
  - `body.startScreen` gives the start screen after the write.
411
441
 
412
442
  ### `unstart-screen`
@@ -18,6 +18,7 @@ import { historyAt, historyNamed, historyOfMacro, historyOfSwitch, revision, rev
18
18
  import { joinBatches, type Batch, type JoinChoice, type JoinClash } from "#src/knowledge/join.ts";
19
19
  import { knowledgeNames } from "#src/knowledge/names.ts";
20
20
  import { addCoverage, programCoverage, programImage, requireProgram, setImage, type ImageRequest } from "#src/knowledge/program.ts";
21
+ import { startScreenOfStage } from "#src/knowledge/start-screen.ts";
21
22
  import {
22
23
  analyzerNamesAt,
23
24
  at,
@@ -175,6 +176,9 @@ const startScreen = (row: StartScreenRow) => ({
175
176
  ...(row.colour === undefined ? {} : { colour: row.colour }),
176
177
  border: row.border,
177
178
  background: row.background,
179
+ ...(row.stage === undefined ? {} : { stage: row.stage }),
180
+ ...(row.call === undefined ? {} : { call: formatC64Address(row.call) }),
181
+ ...(row.colourRam === true ? { colourRam: true } : {}),
178
182
  ...(row.comment === undefined ? {} : { comment: row.comment }),
179
183
  origin: row.origin,
180
184
  revision: row.revision,
@@ -935,38 +939,64 @@ const WRITE_COMMANDS: CommandSpec[] = [
935
939
  writeCommand(
936
940
  {
937
941
  name: "start-screen",
938
- summary: "Records the start screen of the program: a loading, title or presentation screen of the program itself that is still in memory at the entry. The loader of the generated source shows it and waits for a key or a fire button before the entry.",
942
+ summary: "Records the start screen of the program: a loading, title or presentation screen of the program itself, in memory at the entry or in a captured stage of the loading. The loader of the generated source shows it and waits for a key or a fire button before the entry.",
939
943
  options: {
940
- mode: { kind: "choice", value: "<mode>", choices: START_SCREEN_MODES, help: `one of ${START_SCREEN_MODES.join(", ")}`, required: true },
941
- screen: { kind: "address", value: "<address>", help: "the screen: the 1000 characters of a text screen, or the 1000 colour bytes of a bitmap", required: true },
944
+ mode: { kind: "choice", value: "<mode>", choices: START_SCREEN_MODES, help: `one of ${START_SCREEN_MODES.join(", ")}. Necessary without --stage` },
945
+ screen: { kind: "address", value: "<address>", help: "the screen: the 1000 characters of a text screen, or the 1000 colour bytes of a bitmap. Necessary without --stage" },
942
946
  bitmap: { kind: "address", value: "<address>", help: "the 8000 bytes of the bitmap. hires and multicolour need it" },
943
947
  charset: { kind: "address", value: "<address>", help: "the 2048 bytes of the charset, or '$1000' or '$1800' for the character ROM in VIC bank 0. text needs it" },
944
948
  colours: { kind: "address", value: "<address>", help: "the 1000 bytes that the loader copies to the colour RAM" },
945
949
  colour: { kind: "count", value: "<0-15>", min: 0, max: 15, help: "one colour for all of the colour RAM, in place of --colours" },
946
- border: { kind: "count", value: "<0-15>", min: 0, max: 15, help: "the border colour", required: true },
947
- background: { kind: "count", value: "<0-15>", min: 0, max: 15, help: "the background colour", required: true },
950
+ border: { kind: "count", value: "<0-15>", min: 0, max: 15, help: "the border colour. Necessary without --stage" },
951
+ background: { kind: "count", value: "<0-15>", min: 0, max: 15, help: "the background colour. Necessary without --stage" },
952
+ stage: { kind: "text", value: "<space>", help: "the space of a captured stage that shows the screen, for example bank1. The script takes the mode, the addresses and the colours from the capture of the stage. Without it, the bytes are in the program at the entry" },
953
+ call: { kind: "address", value: "<address>", help: "a routine of the stage that the start screen calls before it waits, for example the routine that starts the loading tune. It must return with RTS. Needs --stage" },
948
954
  comment: { kind: "text", value: "<text>", help: "what the screen is" },
949
955
  },
950
- notes: "Record only a screen of the program itself, never a screen of a crack. text and multicolour need --colours or --colour; hires uses neither. A write replaces the start screen of the knowledge.",
956
+ notes: "Record only a screen of the program itself, never a screen of a crack. If a release changed the screen, for example with the text of a crack, stop and ask the user how to deal with it. text and multicolour need --colours or --colour; hires uses neither. With --stage, the script takes the screen from the capture of the stage: give only --stage, and --call for a tune. A flag that you give too replaces the value of the capture. A write replaces the start screen of the knowledge.",
951
957
  },
952
958
  (call) => {
953
959
  const context = contextOf(call);
954
960
  const commentText = call.string("comment");
955
- const optional = (key: "bitmap" | "charset" | "colours") => ((value) => (value === undefined ? {} : { [key]: value }))(call.address(key));
956
- const colour = call.count("colour");
957
- const request = {
961
+ // The values that the call gives. With --stage, the capture of the stage gives the others.
962
+ const given: { mode?: StartScreenMode; screen?: number; bitmap?: number; charset?: number; colours?: number; colour?: number; border?: number; background?: number } = {};
963
+ const mode = call.string("mode") as StartScreenMode | undefined;
964
+ if (mode !== undefined) given.mode = mode;
965
+ for (const key of ["screen", "bitmap", "charset", "colours"] as const) {
966
+ const value = call.address(key);
967
+ if (value !== undefined) given[key] = value;
968
+ }
969
+ for (const key of ["colour", "border", "background"] as const) {
970
+ const value = call.count(key);
971
+ if (value !== undefined) given[key] = value;
972
+ }
973
+ const stage = call.string("stage");
974
+ const routine = call.address("call");
975
+ const extra = {
958
976
  space: call.space,
959
- mode: call.string("mode") as StartScreenMode,
960
- screen: call.address("screen")!,
961
- ...optional("bitmap"),
962
- ...optional("charset"),
963
- ...optional("colours"),
964
- ...(colour === undefined ? {} : { colour }),
965
- border: call.count("border")!,
966
- background: call.count("background")!,
977
+ ...(stage === undefined ? {} : { stage }),
978
+ ...(routine === undefined ? {} : { call: routine }),
967
979
  ...(commentText === undefined ? {} : { comment: commentText }),
968
980
  };
969
- return (db) => shown(setStartScreen(db, context, request), "startScreen", startScreen);
981
+ const complete = (values: typeof given & { colourRam?: true }, remedy: string) => {
982
+ const missing = (["mode", "screen", "border", "background"] as const).filter((key) => values[key] === undefined);
983
+ if (missing.length > 0) throw new UsageError(`Give ${missing.map((key) => `--${key}`).join(", ")}, ${remedy}`);
984
+ return { ...values, mode: values.mode!, screen: values.screen!, border: values.border!, background: values.background!, ...extra };
985
+ };
986
+ if (stage === undefined) {
987
+ const request = complete(given, "or give --stage with the space of a captured stage that shows the screen.");
988
+ return (db) => shown(setStartScreen(db, context, request), "startScreen", startScreen);
989
+ }
990
+ return (db) => {
991
+ // The capture of the stage gives the screen. A flag of the call replaces a value of the capture, and --colours or --colour replaces the colour RAM.
992
+ const image = programImage(db, stage);
993
+ if (image === undefined) throw new Refusal("not-found", `The knowledge has no program in ${stage}. Capture the stage while it shows the start screen, and put the capture into the project knowledge with image --space ${stage}. Then record the start screen again.`);
994
+ const captured = mode === undefined ? startScreenOfStage(image.state, stage) : undefined;
995
+ const { colourRam, ...fromCapture } = captured ?? { colourRam: undefined };
996
+ const ownColours = given.colours !== undefined || given.colour !== undefined;
997
+ const request = complete({ ...fromCapture, ...(colourRam === true && !ownColours ? { colourRam } : {}), ...given }, "or give --stage alone to take the screen from the capture.");
998
+ return shown(setStartScreen(db, context, request), "startScreen", startScreen);
999
+ };
970
1000
  },
971
1001
  ),
972
1002
  writeCommand({ name: "unstart-screen", summary: "Removes the start screen. The loader of the generated source then starts the program at once." }, (call) => {
@@ -37,7 +37,10 @@ These rules apply to each rebuild:
37
37
 
38
38
  - Do not keep a cracktro. A capture of a packed program starts at the last stage, so the code of a cracktro is not in the program. When the capture has data of a cracktro that the program does not read, capture again and exclude that range.
39
39
  - Keep the start screen of the program, for example the loading picture of the publisher. Keep its bytes in the capture, and record the start screen in the project knowledge. The loader of the rebuild then shows it and waits for a key or a fire button. Do not keep a screen of a crack, for example a picture, an intro or a credit screen of a crack group.
40
- - Keep all other bytes: unused bytes, dead code, old copies, texts and leftovers of the development. Record each one as a region with a comment. Do not remove them.
40
+ - When the start screen is only in a stage of the loading, capture that stage while it shows the screen. Put the capture into the project knowledge in a space of its own. Then record the start screen of that stage. Keep its tune: record the routine that starts the tune as the call of the start screen.
41
+ - A release can change the start screen, for example with the text of a crack. Then stop and ask the user how to deal with it. Do not decide alone.
42
+ - Keep all other bytes: unused bytes, dead code, old copies, texts and leftovers of the development. Record each one as a region with a comment. Do not remove them. The source keeps them, and the build of each release has them. The default build and the loader do not have them.
43
+ - Do not write a file of the rebuild by hand, for example a boot file, a packed picture or a script that changes bytes. Record each change in the project knowledge, and generate the source.
41
44
  - Keep a copy protection in the source, off by default. Record a `protection` switch and its patches.
42
45
  - Keep a trainer and a cheat in the source, off by default. Record a `trainer` or `cheat` switch and its patches.
43
46
  - When two or more releases have different corrections, record each release and one `fix` switch for each correction. The switch names the releases that have the correction. The default build has all corrections.
@@ -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`, `loader.prg` and `start_screen.asm` of an earlier run. `staleLoader` tells when they are of another knowledge revision. |
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`, `loader.prg`, `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
- | `--space <space>` | `generate` | The knowledge space: `c64`, `drive8`, or `bank0` to `bank255`. The default is `c64`. The coverage, `--loader` and the platform names apply only to `c64`. |
78
- | `--loader` | `generate` | Also write `loader.asm` and `loader.prg`, and `start_screen.asm` when the knowledge has a start screen. The script writes `loader.prg` only after the check of the new loader ran. Else the `loader.prg` of an earlier run stays. It needs a capture in the knowledge. The default is no loader. |
77
+ | `--space <space>` | `generate` | The knowledge space: `c64`, `drive8`, 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 `loader.prg`, 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 `loader.prg` only after the check of the new loader ran. Else the `loader.prg` 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. |
@@ -110,6 +110,7 @@ To make the source better, change the project knowledge. Then generate again.
110
110
  - `asBytes`: the instructions that the source has as bytes.
111
111
  - `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
112
  - `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.
113
114
  - `operandExpressions`: the count of instructions with an operand expression.
114
115
  - `operandsAsNumbers`: each operand expression that the source has as a number, with its `address`, `expression` and `reason`.
115
116
  - `macroUses`: the count of macro uses in the source.
@@ -158,7 +159,8 @@ Do these actions for the findings:
158
159
  - You can change a value in `config.asm` to 0 or 1. The next run keeps the values of the file. It adds a new switch with its default. It removes a switch that the knowledge does not have.
159
160
  - 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.
160
161
  - `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.
161
- - `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. For each release, a block `!ifdef RELEASE_<label>` gives each switch the value of that release.
162
+ - `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".
162
164
  - `macros.asm` holds the macros of the knowledge. `main.asm` and `loader.asm` include it.
163
165
 
164
166
  #### Names in the source
@@ -190,15 +192,27 @@ Do these actions for the findings:
190
192
  - A patch block has the code of the patch and NOP to the end of the range. `else` has the original code. The labels inside the range come before the zone as `name = * + n`.
191
193
  - Alternatives are patches of two or more switches at one range. They follow as `} else { !if FIX_B {`. A line before them stops the build with `!error` when two of them are in.
192
194
 
195
+ #### The leftovers
196
+
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, the macro uses and the addresses that the code of a patch names are never leftovers.
198
+
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`. The module in the knowledge does not change.
200
+ - `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
+ - `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 its file.
203
+ - `loader.prg` never has the leftovers. The loader does not copy them, and the memory there keeps the bytes that were in it before.
204
+ - Without coverage, no range is a leftover. Put the coverage of the runs into the project knowledge. Then generate again.
205
+ - 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 `loader.prg` fails. Record the region in the project knowledge, or put the coverage of more runs into it. Do not change the source.
206
+
193
207
  #### Switches and releases
194
208
 
195
209
  The program of the knowledge is the base release. The default build is the clean program: no copy protection, no trainer, no cheat, no crack change, and all corrections. Thus the default build can be different from the program.
196
210
 
197
211
  The command does these checks. They use the defaults and the values of the knowledge, not the values in `config.asm`.
198
212
 
199
- 1. `check`: the build of the base release must give the program byte by byte. In this build, each switch has its base value.
213
+ 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.
200
214
  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.
201
- 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`.
215
+ 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.
202
216
  4. `releases`: each release, built with `RELEASE_<label>=1`, against the file of the release.
203
217
 
204
218
  Each item of `switches` has `name`, `kind`, `default`, `base`, `define` and the patches.
@@ -224,7 +238,7 @@ The script writes a macro use only when the use gives the bytes of the program.
224
238
 
225
239
  Build the program from the source in these ways:
226
240
 
227
- - The build of `config.asm`: no option. With the defaults, this is the default build.
241
+ - The build of `config.asm`: no option. With the defaults, this is the default build, without the leftovers.
228
242
  - A release: the build option `--release ORIGINAL`.
229
243
  - One switch: set its value in `config.asm`, for example `TRAINER = 1`. Do not define a switch on the command line of the build. ACME stops with `Symbol already defined`, because `config.asm` also sets the switch.
230
244
 
@@ -234,7 +248,7 @@ Build the program from the source in these ways:
234
248
 
235
249
  1. `10 SYS 2061` starts it.
236
250
  2. It stops the interrupts and makes all RAM visible. It moves its copier to two free pages.
237
- 3. It copies each segment and the pages $0002-$03ff of the entry state into place. No copy writes over the packed bytes of a copy that has not run yet.
251
+ 3. It copies each segment without the leftovers, and the pages $0002-$03ff of the entry state, into place. No copy writes over the packed bytes of a copy that has not run yet.
238
252
  4. When the knowledge has a start screen and `START_SCREEN` is 1, it shows the start screen. It waits until the user releases all keys and fire buttons. Then it waits for a key, or for a fire button on joystick port 1 or 2, and for its release. A move of a joystick is not a key.
239
253
  5. It sets the screen registers of the VIC-II and the VIC bank from the entry state. Then it waits for the raster line of the entry.
240
254
  6. It sets the CIA timers, their latches and the interrupt masks from the entry state. A running timer gets the value that counts down to the timer value at the entry.
@@ -244,11 +258,11 @@ The copy table, the copier and the jump use labels, not numbers. `loader_from_xx
244
258
 
245
259
  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.
246
260
 
247
- The entry state is the state of the base release. Thus the script builds and checks `loader.prg` with the switch values of the base release. For a loader of the default build, build `loader.asm` with no option.
261
+ The script builds and checks `loader.prg` with the values of `config.asm`. With the defaults, `loader.prg` 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.
248
262
 
249
263
  The start screen:
250
264
 
251
- - 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.
265
+ - 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".
252
266
  - With a start screen, the copier uses three pages, not two.
253
267
  - `loader.prg` always shows the start screen. 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. The build of a release does not read `config.asm`, so it shows the start screen.
254
268
  - A test that runs `loader.prg` stops at the start screen, because the emulator cannot press a key of the keyboard matrix. Run until `loader_start_screen_wait`. Then set the PC to `loader_start_screen_continue`.
@@ -259,7 +273,8 @@ The start screen:
259
273
  - `verified: true`: the check ran `loader.prg` 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.
260
274
  - `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.
261
275
  - `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.
262
- - `packed`: `packedBytes` and `unpackedBytes` of the packed form.
276
+ - `packed`: `packedBytes` and `unpackedBytes` of the packed form. With a start screen of a captured stage, this is the packed program in `loader.prg`.
277
+ - `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 `loader.prg`, the `stash` copies, `packedBytes` and `unpackedBytes`. `startScreen.stage` names the space.
263
278
  - When the check of `loader.prg` cannot run, the script does not write `loader.prg`. The `loader.prg` of an earlier run stays as it was. `loader.asm` is new. `reason` tells why the check did not run.
264
279
  - `kept`: when the result has no new `loader.prg`, the path of the `loader.prg` of an earlier run. That file is not of this source.
265
280
 
@@ -271,10 +286,35 @@ Do these actions when `verified` is `false`:
271
286
  | `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. |
272
287
  | `reason` that the source does not assemble | Correct the source first. The loader includes the source. |
273
288
  | `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. |
289
+ | `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. |
274
290
  | `reason` that the check of `loader.prg` 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. |
275
291
  | `differences` | The loader ran. The list gives the bytes and the registers that are not equal. |
276
292
  | `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. |
277
293
 
294
+ #### The start screen of a captured stage
295
+
296
+ Often the loading stage of a program shows a picture that is not in memory at the entry. Then the knowledge has the picture in a captured stage: a space such as `bank1`. `--stage` of the start screen names that space. `--call` names a routine of the stage, for example the routine that starts the loading tune.
297
+
298
+ The loader then always has the packed form, and the start screen is a program of its own in front of it:
299
+
300
+ 1. Exomizer packs the program with the copier. This is the packed loader.
301
+ 2. Exomizer packs the packed loader, the bytes of the stage and the show code into `loader.prg`.
302
+ 3. When `loader.prg` 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.
303
+ 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.
304
+ 5. It waits for a key or a fire button, as the start screen in the program does.
305
+ 6. It stops the interrupts and the sound, and it stops the screen. It sets the CIA timers as RUN leaves them.
306
+ 7. It copies the stash back to the packed loader. Then it starts the packed loader, which unpacks the program over the start screen.
307
+
308
+ The program is packed while the screen shows. Thus the picture and the tune have more free memory.
309
+
310
+ - The script puts everything in memory. It does not matter where the stage keeps its bytes, if the memory has enough room.
311
+ - `loader.prg` 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.
312
+ - With colours from the colour RAM of the capture, the show code holds the 1000 colours. It copies them to the colour RAM.
313
+ - 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.
314
+ - `start_screen_stage.asm` holds the show code and the bytes of the stage. Do not edit it. To make `loader.prg` again, run `generate --loader`.
315
+ - 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.
316
+ - The check runs `loader.prg` 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.
317
+
278
318
  #### The packed loader
279
319
 
280
320
  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:
@@ -285,7 +325,7 @@ A loader file that loads into $d000 or higher writes the I/O area. When the prog
285
325
 
286
326
  To make the packed loader for other switch values, do these steps:
287
327
 
288
- 1. Assemble `main.asm` to `build/main.prg`.
328
+ 1. Assemble `main.asm` to `build/main.prg`. The leftovers are $00 in this build.
289
329
  2. Assemble `loader.asm` to `build/copier.prg`.
290
330
  3. Pack the two files into `build/loader.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`.
291
331
 
@@ -321,6 +361,7 @@ The build with these values can change bytes only in the patches. Then the comma
321
361
  - `loader`: the copies, the copier, `stackByte` and `simulated: true`. The export does not run the loader.
322
362
  - `noCoverage` or `unrooted`: why nothing became free without `--drop`.
323
363
  - `spacesLeftOut`: the spaces that the export does not have. The export has only the space `c64`.
364
+ - `startScreenLeftOut`: the start screen is of a captured stage. The export does not have it, because the export has only the space `c64`.
324
365
 
325
366
  On `PASS`, `hint` tells you to build and test the new project as its `README.md` tells. When the knowledge has no coverage, or `unreachableExecuted` has items, `hint` also tells how to make more ranges free.
326
367
  On `FAIL`, `hint` gives the action for the stage:
@@ -10,6 +10,8 @@
10
10
  // copier, and the copier writes only pages $0002-$03ff. With a start
11
11
  // screen in the knowledge, the copier shows it after the copies and waits for
12
12
  // a key or a fire button: the code is start-screen.asm, the same for each program.
13
+ // The loader loads the segments without the leftovers: the ranges of the
14
+ // source that nothing uses are not in loader.prg.
13
15
 
14
16
  import { readFileSync } from "node:fs";
15
17
  import { fileURLToPath } from "node:url";
@@ -105,6 +107,8 @@ export interface PackedBlock {
105
107
  }
106
108
 
107
109
  export interface LoaderPlan {
110
+ /** The ranges that the loader puts in place: the segments without the leftovers. */
111
+ loaded: AddressRange[];
108
112
  blocks: PackedBlock[];
109
113
  copies: Copy[];
110
114
  /** The first of the two free pages where the copier runs. */
@@ -168,12 +172,12 @@ export function startScreenPlan(row: StartScreenRow): StartScreenPlan {
168
172
  bank,
169
173
  border: row.border,
170
174
  background: row.background,
171
- colourMode: row.colours !== undefined ? 2 : row.colour !== undefined ? 1 : 0,
175
+ colourMode: row.colours !== undefined || row.colourRam === true ? 2 : row.colour !== undefined ? 1 : 0,
172
176
  };
173
177
  }
174
178
 
175
179
  /** The lines of loader.asm that give the start screen code its values. */
176
- function startScreenValues(row: StartScreenRow, plan: StartScreenPlan): string[] {
180
+ export function startScreenValues(row: StartScreenRow, plan: StartScreenPlan): string[] {
177
181
  const value = (name: string, number: number, comment?: string) => `c64_source_ss_${name} = ${formatC64Byte(number)}${comment === undefined ? "" : ` ; ${comment}`}`;
178
182
  const font = row.charset !== undefined && isRomFont(row.charset) ? " (the character ROM)" : "";
179
183
  const what = [`screen ${formatC64Address(row.screen)}`, ...(row.bitmap === undefined ? [] : [`bitmap ${formatC64Address(row.bitmap)}`]), ...(row.charset === undefined ? [] : [`charset ${formatC64Address(row.charset)}${font}`])];
@@ -187,7 +191,8 @@ function startScreenValues(row: StartScreenRow, plan: StartScreenPlan): string[]
187
191
  value("background", plan.background),
188
192
  value("colour_mode", plan.colourMode),
189
193
  value("colour", row.colour ?? 0),
190
- `c64_source_ss_colours = ${formatC64Address(row.colours ?? 0)}`,
194
+ // The colour RAM of a captured stage is in the show code: STAGE_COLOURS in stage.ts.
195
+ `c64_source_ss_colours = ${row.colourRam === true ? "c64_source_stage_colours" : formatC64Address(row.colours ?? 0)}`,
191
196
  ];
192
197
  }
193
198
 
@@ -223,7 +228,7 @@ const overlaps = (a: AddressRange, b: AddressRange) => a.start <= b.end && b.sta
223
228
  const show = (range: AddressRange) => `${formatC64Address(range.start)}-${formatC64Address(range.end)}`;
224
229
 
225
230
  /** Parts of `range` that no range in `holes` covers. */
226
- function subtract(range: AddressRange, holes: AddressRange[]): AddressRange[] {
231
+ export function subtract(range: AddressRange, holes: AddressRange[]): AddressRange[] {
227
232
  let pieces = [range];
228
233
  for (const hole of holes) {
229
234
  pieces = pieces.flatMap((piece) => {
@@ -445,7 +450,7 @@ export function ciaSection(state: EntryState): { ops: Op[]; plan: CiaPlan } | un
445
450
  }
446
451
 
447
452
  export interface LoaderInput {
448
- /** The segments with the files that hold them, in address order. */
453
+ /** The ranges to load, each with the files that hold it, in address order: the segments without the leftovers. */
449
454
  segments: Array<AddressRange & { files: string[] }>;
450
455
  byteAt: (address: number) => number;
451
456
  state: EntryState;
@@ -461,6 +466,8 @@ export interface LoaderInput {
461
466
  config?: boolean;
462
467
  /** The start screen of the knowledge: the copier shows it after the copies. */
463
468
  startScreen?: StartScreenRow;
469
+ /** Always the packed form: the show stage of a start screen from a captured stage holds the packed program while it shows the screen. */
470
+ packed?: boolean;
464
471
  }
465
472
 
466
473
  /** The checks of a start screen against the program and the entry state. Refuses by name. */
@@ -545,11 +552,12 @@ export function planLoader(input: LoaderInput): LoaderPlan {
545
552
  const codeSize = COPIER_CODE_SIZE + (state.vic === undefined ? 0 : VIC_SIZE) + ciaSize + (screen === undefined ? 0 : START_SCREEN_SIZES[screen.colourMode]);
546
553
  const copierImage = at;
547
554
  const end = copierImage + codeSize + COPY_ENTRY * plain.length + 2 - 1;
555
+ if (input.packed === true) return planPacked(input, blocks, cia, codeSize, screen, "The start screen of a captured stage shows while the program is still packed.");
548
556
  // The end can be past $ffff, which is no address.
549
557
  if (end > LOAD_LIMIT) return planPacked(input, blocks, cia, codeSize, screen, `The plain loader would end ${end > 0xffff ? "past $ffff" : `at ${formatC64Address(end)}`}, after ${formatC64Address(LOAD_LIMIT)}: loading it would write the I/O area.`);
550
558
  // The CIA part and the start screen take room from the copy table in the copier's pages.
551
559
  const maxCopies = Math.max(0, Math.min(TABLE_COPIES, Math.floor((copierBytes - codeSize - 2) / COPY_ENTRY)));
552
- if (plain.length > maxCopies) throw new WireFailure("invalid-input", `The loader needs ${plain.length} copies; it can do at most ${maxCopies}. Capture the program again with fewer segments, or write the loader by hand.`);
560
+ if (plain.length > maxCopies) return planPacked(input, blocks, cia, codeSize, screen, `The plain loader needs ${plain.length} copies, and its copier can do at most ${maxCopies}.`);
553
561
 
554
562
  const order = copyOrder(plain);
555
563
  if (order === undefined) {
@@ -621,6 +629,7 @@ export function planLoader(input: LoaderInput): LoaderPlan {
621
629
  lines.push(" !word 0", "}", "}");
622
630
 
623
631
  return {
632
+ loaded: input.segments.map(({ start, end }) => ({ start, end })),
624
633
  blocks: blocks.map((block, index) => ({ what: block.what, range: block.range, packedAt: packedAt[index]!, bytes: block.bytes })),
625
634
  copies,
626
635
  copier,
@@ -719,6 +728,7 @@ function planPacked(input: LoaderInput, blocks: Block[], cia: ReturnType<typeof
719
728
  parts.sort((a, b) => a.range.start - b.range.start);
720
729
  for (const part of parts) lines.push("", ...part.text);
721
730
  return {
731
+ loaded: input.segments.map(({ start, end }) => ({ start, end })),
722
732
  blocks: pieces.map((piece) => ({ what: piece.what, range: piece.target, packedAt: piece.at, bytes: piece.bytes })),
723
733
  copies,
724
734
  copier,
@@ -735,7 +745,7 @@ function planPacked(input: LoaderInput, blocks: Block[], cia: ReturnType<typeof
735
745
  const MAX_PACKED_COPIES = Math.floor((256 - 2) / COPY_ENTRY);
736
746
 
737
747
  /** A piece of pages 0-3 in the packed form: its target and where the copier reads it. */
738
- interface Piece {
748
+ export interface Piece {
739
749
  what: string;
740
750
  target: AddressRange;
741
751
  at: number;
@@ -748,7 +758,7 @@ interface Piece {
748
758
  * A part that does not fit in one range is split, and each piece is a copy.
749
759
  * Undefined when the ranges are too small.
750
760
  */
751
- function placePieces(ranges: AddressRange[], low: ReadonlyArray<{ what: string; range: AddressRange; bytes: (address: number) => number }>, distance: (range: AddressRange) => number): Piece[] | undefined {
761
+ export function placePieces(ranges: AddressRange[], low: ReadonlyArray<{ what: string; range: AddressRange; bytes: (address: number) => number }>, distance: (range: AddressRange) => number): Piece[] | undefined {
752
762
  const left = ranges.map((range) => ({ ...range }));
753
763
  const pieces: Piece[] = [];
754
764
  let rest = low.reduce((sum, block) => sum + block.range.end - block.range.start + 1, 0);
@@ -815,24 +825,43 @@ export interface PackedLoader {
815
825
  }
816
826
 
817
827
  /**
818
- * Packs the build of main.asm from $0400 and the build of loader.asm (the
819
- * copier wins where they overlap) with the entry at the copier and $01 = $34,
820
- * and checks the unpack in the emulator of Exomizer: every byte of the two
821
- * builds, and the jump to the copier. Refuses by name when it does not hold.
828
+ * Packs the loaded ranges of the build of main.asm from $0400 and the build of
829
+ * loader.asm (the copier wins where they overlap) with the entry at the copier
830
+ * and $01 = $34, and checks the unpack in the emulator of Exomizer: every byte
831
+ * of the two builds, and the jump to the copier. Refuses by name when it does
832
+ * not hold.
822
833
  */
823
834
  export async function packLoader(main: Uint8Array, copier: Uint8Array, plan: LoaderPlan, context: ToolContext): Promise<PackedLoader> {
824
- // The unpacker uses pages 0-3; the copier writes them.
835
+ return packParts(packedParts(main, copier, plan), plan.copier, 0x34, "main.asm and loader.asm", "the copier", context);
836
+ }
837
+
838
+ /** What Exomizer packs in the packed form: the loaded ranges of the build of main.asm from $0400, and the build of loader.asm. */
839
+ function packedParts(main: Uint8Array, copier: Uint8Array, plan: Pick<LoaderPlan, "loaded">): Array<{ start: number; body: Uint8Array }> {
840
+ // The unpacker uses pages 0-3; the copier writes them. The leftovers between the loaded ranges are not packed.
825
841
  const program = prgRange(main);
826
- const skip = Math.max(0, 0x0400 - program.start);
827
- const parts = [...(skip < program.body.length ? [{ start: program.start + skip, body: program.body.subarray(skip) }] : []), prgRange(copier)];
842
+ const ranges = plan.loaded.flatMap((range) => {
843
+ const start = Math.max(range.start, 0x0400, program.start);
844
+ const end = Math.min(range.end, program.start + program.body.length - 1);
845
+ return start <= end ? [{ start, body: program.body.subarray(start - program.start, end - program.start + 1) }] : [];
846
+ });
847
+ return [...ranges, prgRange(copier)];
848
+ }
849
+
850
+ /**
851
+ * Packs parts (a later one wins where they overlap) into one program that
852
+ * unpacks itself, starts at `entry` with $01 = `exitMemory`, and checks the
853
+ * unpack in the emulator of Exomizer: every byte of the parts, and the jump
854
+ * to the entry. Refuses by name when it does not hold.
855
+ */
856
+ export async function packParts(parts: ReadonlyArray<{ start: number; body: Uint8Array }>, entry: number, exitMemory: number, what: string, entryName: string, context: ToolContext): Promise<PackedLoader> {
828
857
  const prg = (part: { start: number; body: Uint8Array }) => Buffer.concat([Buffer.from([part.start & 0xff, part.start >> 8]), part.body]);
829
- const packed = await pack({ programs: parts.map(prg), entry: plan.copier, exitMemory: 0x34 }, context);
830
- if (packed.entry !== plan.copier) throw new WireFailure("operation-failed", `The unpack in the emulator of Exomizer jumps to ${formatC64Address(packed.entry)}, not to the copier at ${formatC64Address(plan.copier)}.`);
858
+ const packed = await pack({ programs: parts.map(prg), entry, exitMemory }, context);
859
+ if (packed.entry !== entry) throw new WireFailure("operation-failed", `The unpack in the emulator of Exomizer jumps to ${formatC64Address(packed.entry)}, not to ${entryName} at ${formatC64Address(entry)}.`);
831
860
  const reference = mergedPrograms(parts);
832
861
  const wrong = compareBuild(packed.unpacked, reference).segments.find((segment) => segment.result !== "identical");
833
862
  if (wrong !== undefined) {
834
863
  const first = wrong.firstDifference === undefined ? "" : `: the first is ${wrong.firstDifference.address}, ${wrong.firstDifference.built} and not ${wrong.firstDifference.reference}`;
835
- throw new WireFailure("operation-failed", `The unpack in the emulator of Exomizer does not give ${wrong.start}-${wrong.end} of main.asm and loader.asm (${wrong.result}${first}).`);
864
+ throw new WireFailure("operation-failed", `The unpack in the emulator of Exomizer does not give ${wrong.start}-${wrong.end} of ${what} (${wrong.result}${first}).`);
836
865
  }
837
866
  const unpackedBytes = reference.segments.reduce((sum, segment) => sum + segment.end - segment.start + 1, 0);
838
867
  return { program: packed.program, packedBytes: packed.program.length, unpackedBytes, ...(packed.cycles === undefined ? {} : { cycles: packed.cycles }) };