@henols/c64-re-tools 2.6.0-rc.2 → 2.6.0-rc.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/skills/c64-assembler/SKILL.md +26 -12
- package/skills/c64-assembler/scripts/assembler.ts +24 -11
- package/skills/c64-knowledge/SKILL.md +31 -16
- package/skills/c64-knowledge/scripts/knowledge.ts +62 -33
- package/skills/c64-packer/SKILL.md +1 -1
- package/skills/c64-reverse-engineering/SKILL.md +1 -1
- package/skills/c64-source/SKILL.md +51 -30
- package/skills/c64-source/scripts/lib/export.ts +76 -32
- package/skills/c64-source/scripts/lib/loader.ts +29 -9
- package/skills/c64-source/scripts/lib/source.ts +5 -16
- package/skills/c64-source/scripts/lib/stage.ts +11 -5
- package/skills/c64-source/scripts/lib/start-screen.asm +4 -2
- package/skills/c64-source/scripts/source.ts +145 -46
- package/skills/c64-static-analysis/scripts/lib/coverage.ts +2 -25
- package/skills/c64-testing/SKILL.md +3 -1
- package/skills/c64-testing/references/recording-format.md +1 -0
- package/skills/c64-testing/references/scenario-format.md +5 -3
- package/skills/c64-testing/scripts/lib/recording.ts +25 -8
- package/skills/c64-testing/scripts/lib/replay.ts +1 -1
- package/skills/c64-testing/scripts/lib/scenario.ts +14 -5
- package/skills/c64-unpacker/SKILL.md +4 -2
- package/skills/c64-unpacker/scripts/lib/loads.ts +33 -12
- package/skills/c64-unpacker/scripts/lib/machine.ts +7 -3
- package/skills/c64-unpacker/scripts/unpacker.ts +5 -3
- package/src/build-name.ts +47 -0
- package/src/c64.ts +21 -1
- package/src/host/vice/session.ts +6 -1
- package/src/knowledge/read.ts +5 -2
- package/src/knowledge/schema.ts +5 -3
- package/src/knowledge/start-screen.ts +68 -0
- package/src/knowledge/text.ts +1 -0
- package/src/knowledge/write.ts +22 -16
- package/src/native/acme.ts +1 -1
- package/src/platform.ts +30 -1
- package/src/script.ts +3 -3
|
@@ -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. 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
|
-
| `--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
|
|
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 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. |
|
|
@@ -110,7 +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
|
+
- `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
114
|
- `operandExpressions`: the count of instructions with an operand expression.
|
|
115
115
|
- `operandsAsNumbers`: each operand expression that the source has as a number, with its `address`, `expression` and `reason`.
|
|
116
116
|
- `macroUses`: the count of macro uses in the source.
|
|
@@ -118,7 +118,7 @@ To make the source better, change the project knowledge. Then generate again.
|
|
|
118
118
|
- `patchesNotWritten`: each patch that the source does not have, with its range, `switch` and `reason`.
|
|
119
119
|
- `switches`, `default`, `releases`: the checks of the switches. See "Switches and releases".
|
|
120
120
|
- `loader`: the check of the loader. See "The loader".
|
|
121
|
-
- `staleLoader`: a run without `--loader` kept `loader.asm` and
|
|
121
|
+
- `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.
|
|
122
122
|
|
|
123
123
|
`result` is `FAIL` for each of these:
|
|
124
124
|
|
|
@@ -200,9 +200,10 @@ A leftover is a range of the program that nothing uses: unused code, old copies
|
|
|
200
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
201
|
- `config.asm` has `LEFTOVERS = 0`. Thus the default build is the clean program, without the leftovers.
|
|
202
202
|
- Each release has `LEFTOVERS = 1`. Thus the build of a release gives the bytes of its file.
|
|
203
|
-
-
|
|
203
|
+
- 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
204
|
- Without coverage, no range is a leftover. Put the coverage of the runs into the project knowledge. Then generate again.
|
|
205
|
-
-
|
|
205
|
+
- 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.
|
|
206
|
+
- 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
207
|
|
|
207
208
|
#### Switches and releases
|
|
208
209
|
|
|
@@ -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` and assembles it to
|
|
248
|
+
`--loader` writes `loader.asm` and assembles it to the loader program. 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 `symbols/<name>.json`, for example `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,25 +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
|
-
-
|
|
268
|
-
-
|
|
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.
|
|
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.
|
|
277
|
+
- A test that runs the loader program 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`.
|
|
269
278
|
|
|
270
279
|
`loader` holds these fields:
|
|
271
280
|
|
|
272
281
|
- `program`, the `copies` in their order, `copier` and `stackByte`.
|
|
273
|
-
- `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.
|
|
274
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.
|
|
275
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.
|
|
276
|
-
- `packed`: `packedBytes` and `unpackedBytes` of the packed form. With a start screen of a captured stage, this is the packed program in
|
|
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
|
|
278
|
-
- When the check of
|
|
279
|
-
- `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.
|
|
280
289
|
|
|
281
290
|
Do these actions when `verified` is `false`:
|
|
282
291
|
|
|
@@ -286,20 +295,20 @@ Do these actions when `verified` is `false`:
|
|
|
286
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. |
|
|
287
296
|
| `reason` that the source does not assemble | Correct the source first. The loader includes the source. |
|
|
288
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. |
|
|
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. |
|
|
290
|
-
| `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. |
|
|
291
300
|
| `differences` | The loader ran. The list gives the bytes and the registers that are not equal. |
|
|
292
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. |
|
|
293
302
|
|
|
294
303
|
#### The start screen of a captured stage
|
|
295
304
|
|
|
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
|
|
305
|
+
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 the captured stage of the space `loading`. `--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
306
|
|
|
298
307
|
The loader then always has the packed form, and the start screen is a program of its own in front of it:
|
|
299
308
|
|
|
300
309
|
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
|
|
302
|
-
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.
|
|
303
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.
|
|
304
313
|
5. It waits for a key or a fire button, as the start screen in the program does.
|
|
305
314
|
6. It stops the interrupts and the sound, and it stops the screen. It sets the CIA timers as RUN leaves them.
|
|
@@ -307,25 +316,27 @@ The loader then always has the packed form, and the start screen is a program of
|
|
|
307
316
|
|
|
308
317
|
The program is packed while the screen shows. Thus the picture and the tune have more free memory.
|
|
309
318
|
|
|
310
|
-
-
|
|
319
|
+
- The script puts everything in memory. It does not matter where the stage keeps its bytes, if the memory has enough room.
|
|
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.
|
|
321
|
+
- With colours from the colour RAM of the capture, the show code holds the 1000 colours. It copies them to the colour RAM.
|
|
311
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.
|
|
312
|
-
- `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`.
|
|
313
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.
|
|
314
|
-
- 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.
|
|
315
326
|
|
|
316
327
|
#### The packed loader
|
|
317
328
|
|
|
318
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:
|
|
319
330
|
|
|
320
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.
|
|
321
|
-
-
|
|
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`.
|
|
322
333
|
- The jump to the entry uses the address of the entry, not its label.
|
|
323
334
|
|
|
324
335
|
To make the packed loader for other switch values, do these steps:
|
|
325
336
|
|
|
326
|
-
1. Assemble `main.asm`
|
|
327
|
-
2. Assemble `loader.asm` to `build/
|
|
328
|
-
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`.
|
|
329
340
|
|
|
330
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.
|
|
331
342
|
|
|
@@ -384,6 +395,16 @@ A block of code stops after RTS, RTI, JMP, BRK or a JAM, and before a gap. A blo
|
|
|
384
395
|
- No run of the coverage executed it.
|
|
385
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.
|
|
386
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
|
+
|
|
387
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.
|
|
388
409
|
|
|
389
410
|
Data becomes free only when all of these are true:
|
|
@@ -391,7 +412,7 @@ Data becomes free only when all of these are true:
|
|
|
391
412
|
- Its region type is `bytes`, `words`, a table of addresses, `petscii`, `workspace` or `unused`.
|
|
392
413
|
- No run read, wrote or executed a byte of it.
|
|
393
414
|
- No code that stays reads it or names it. No table that stays has an entry in it.
|
|
394
|
-
- It is not
|
|
415
|
+
- It is not in the BASIC line that starts the program, and not at $fffa-$ffff.
|
|
395
416
|
|
|
396
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.
|
|
397
418
|
|
|
@@ -426,7 +447,7 @@ tests/ the tests of the project, changed for the new program
|
|
|
426
447
|
5. Record names, comments, regions and modules in the project knowledge.
|
|
427
448
|
6. Run `generate` again. Do steps 4 to 6 again until the source is clear.
|
|
428
449
|
7. Assemble `main.asm` to a program. This is the default build. For a release, give the build option `--release <label>`.
|
|
429
|
-
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.
|
|
430
451
|
9. To start a new program from the rebuild, run `export`.
|
|
431
452
|
|
|
432
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
|
"",
|
|
@@ -11,7 +11,7 @@
|
|
|
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
13
|
// The loader loads the segments without the leftovers: the ranges of the
|
|
14
|
-
// source that nothing uses are not in loader.
|
|
14
|
+
// source that nothing uses are not in the loader program.
|
|
15
15
|
|
|
16
16
|
import { readFileSync } from "node:fs";
|
|
17
17
|
import { fileURLToPath } from "node:url";
|
|
@@ -24,6 +24,7 @@ import { isRomFont, startScreenRanges, type StartScreenRow } from "#src/knowledg
|
|
|
24
24
|
import { WireFailure } from "#src/host-client/tools.ts";
|
|
25
25
|
import { pack } from "#src/native/exomizer.ts";
|
|
26
26
|
import type { ToolContext } from "#src/native/run.ts";
|
|
27
|
+
import type { AssembledSymbol } from "#src/native/types.ts";
|
|
27
28
|
|
|
28
29
|
export interface EntryState {
|
|
29
30
|
pc: number;
|
|
@@ -138,9 +139,7 @@ export function loaderLimits(plan: { cia?: CiaPlan }): string[] {
|
|
|
138
139
|
|
|
139
140
|
/** The label of the loader's jump to the entry, in ACME's symbol list. */
|
|
140
141
|
export const LOADER_JUMP = "c64_source_loader_jump";
|
|
141
|
-
|
|
142
|
-
export const START_SCREEN_WAIT = "loader_start_screen_wait";
|
|
143
|
-
export const START_SCREEN_CONTINUE = "loader_start_screen_continue";
|
|
142
|
+
export { START_SCREEN_CONTINUE, START_SCREEN_WAIT } from "#src/knowledge/start-screen.ts";
|
|
144
143
|
/** The file of the start screen in the generated source. */
|
|
145
144
|
export const START_SCREEN_FILE = "start_screen.asm";
|
|
146
145
|
/** The code of the start screen: the same for each program. loader.asm sets its values. */
|
|
@@ -172,7 +171,7 @@ export function startScreenPlan(row: StartScreenRow): StartScreenPlan {
|
|
|
172
171
|
bank,
|
|
173
172
|
border: row.border,
|
|
174
173
|
background: row.background,
|
|
175
|
-
colourMode: row.colours !== undefined ? 2 : row.colour !== undefined ? 1 : 0,
|
|
174
|
+
colourMode: row.colours !== undefined || row.colourRam === true ? 2 : row.colour !== undefined ? 1 : 0,
|
|
176
175
|
};
|
|
177
176
|
}
|
|
178
177
|
|
|
@@ -191,7 +190,8 @@ export function startScreenValues(row: StartScreenRow, plan: StartScreenPlan): s
|
|
|
191
190
|
value("background", plan.background),
|
|
192
191
|
value("colour_mode", plan.colourMode),
|
|
193
192
|
value("colour", row.colour ?? 0),
|
|
194
|
-
|
|
193
|
+
// The colour RAM of a captured stage is in the show code: STAGE_COLOURS in stage.ts.
|
|
194
|
+
`c64_source_ss_colours = ${row.colourRam === true ? "c64_source_stage_colours" : formatC64Address(row.colours ?? 0)}`,
|
|
195
195
|
];
|
|
196
196
|
}
|
|
197
197
|
|
|
@@ -651,7 +651,7 @@ const SHOWN_FREE = 8;
|
|
|
651
651
|
/**
|
|
652
652
|
* The packed form of the loader, for an image too large for one loader file:
|
|
653
653
|
* Exomizer packs the build of main.asm (from $0400) and the build of
|
|
654
|
-
* loader.asm into loader
|
|
654
|
+
* loader.asm into the loader program, which starts at the copier with all RAM
|
|
655
655
|
* visible ($01 = $34). loader.asm holds only the copier, in one free range,
|
|
656
656
|
* and the bytes of pages $0002-$03ff, in pieces in the free ranges: the
|
|
657
657
|
* unpacker of Exomizer uses the zero page and $0334-$03ff, so the copier
|
|
@@ -689,7 +689,7 @@ function planPacked(input: LoaderInput, blocks: Block[], cia: ReturnType<typeof
|
|
|
689
689
|
const lines: string[] = [
|
|
690
690
|
...input.header.map((line) => `; ${line}`),
|
|
691
691
|
"; The image is too large for one loader file, so this is the packed form. Exomizer packs the",
|
|
692
|
-
`; build of main.asm and the build of this file into loader
|
|
692
|
+
`; build of main.asm and the build of this file into the loader program, with --entry '${formatC64Address(copier)}' and --exit-memory '$34'.`,
|
|
693
693
|
"; The unpacker of Exomizer uses the zero page and $0334-$03ff, so the copier writes pages $0002-$03ff after the unpack.",
|
|
694
694
|
"",
|
|
695
695
|
"!cpu 6510",
|
|
@@ -815,7 +815,7 @@ function placePacked(free: AddressRange[], low: Parameters<typeof placePieces>[1
|
|
|
815
815
|
|
|
816
816
|
/** What Exomizer makes of a packed loader. */
|
|
817
817
|
export interface PackedLoader {
|
|
818
|
-
/** loader
|
|
818
|
+
/** The loader program: it loads at $0801 and starts with RUN. */
|
|
819
819
|
program: Buffer;
|
|
820
820
|
packedBytes: number;
|
|
821
821
|
unpackedBytes: number;
|
|
@@ -991,3 +991,23 @@ function vicLines(state: EntryState, earlier: number): string[] {
|
|
|
991
991
|
" bne .raster",
|
|
992
992
|
];
|
|
993
993
|
}
|
|
994
|
+
|
|
995
|
+
/**
|
|
996
|
+
* The symbols of the loader program: the labels of the build of loader.asm, which
|
|
997
|
+
* includes main.asm, and of start_screen_stage.asm when the loader has a show
|
|
998
|
+
* stage. A test takes one symbols file. Refuses a name with two values.
|
|
999
|
+
*/
|
|
1000
|
+
export function loaderSymbols(...builds: ReadonlyArray<readonly AssembledSymbol[]>): AssembledSymbol[] {
|
|
1001
|
+
const valueOf = (symbol: AssembledSymbol) => (symbol.kind === "address" ? symbol.address : symbol.value);
|
|
1002
|
+
const byName = new Map<string, AssembledSymbol>();
|
|
1003
|
+
for (const symbol of builds.flat()) {
|
|
1004
|
+
const known = byName.get(symbol.name);
|
|
1005
|
+
if (known !== undefined && valueOf(known) !== valueOf(symbol)) {
|
|
1006
|
+
throw new WireFailure("operation-failed", `The builds of the loader program give ${symbol.name} two values, ${valueOf(known)} and ${valueOf(symbol)}. This is a defect of the script.`);
|
|
1007
|
+
}
|
|
1008
|
+
// An address in one build can be outside the load range of the other build, where it is a constant.
|
|
1009
|
+
const kept = known === undefined || (known.kind === "constant" && symbol.kind === "address") ? symbol : known;
|
|
1010
|
+
byName.set(symbol.name, { ...kept, used: symbol.used || (known?.used ?? false) });
|
|
1011
|
+
}
|
|
1012
|
+
return [...byName.values()].sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0));
|
|
1013
|
+
}
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
// each release has it, the default build does not, and the loader never
|
|
15
15
|
// loads it.
|
|
16
16
|
|
|
17
|
+
import { CONFIG_FILE, configValues } from "#src/build-name.ts";
|
|
17
18
|
import { type AddressRange, COVERAGE, formatC64Address, formatC64Byte, POINTER_TABLE_TYPES, pointerTableEntries, type PointerTableType } from "#src/c64.ts";
|
|
18
19
|
import { WireFailure } from "#src/host-client/tools.ts";
|
|
19
20
|
import { identifiers, operandText, replaceIdentifiers, type OperandExpression } from "#src/knowledge/expression.ts";
|
|
@@ -930,21 +931,7 @@ export const hasSwitchFile = (layout: Pick<Layout, "switches" | "releases" | "le
|
|
|
930
931
|
/** True when the source has config.asm: the knowledge has switches or a start screen, or the source has leftovers. */
|
|
931
932
|
export const hasConfigFile = (layout: Pick<Layout, "switches" | "startScreen" | "leftovers">) => layout.switches.length > 0 || layout.startScreen || layout.leftovers.length > 0;
|
|
932
933
|
|
|
933
|
-
|
|
934
|
-
export const CONFIG_FILE = "config.asm";
|
|
935
|
-
|
|
936
|
-
/** A value line of config.asm: NAME = 0 or NAME = 1. */
|
|
937
|
-
const CONFIG_VALUE = /^\s*([A-Z][A-Z0-9_]*)\s*=\s*([01])\s*(?:;.*)?$/;
|
|
938
|
-
|
|
939
|
-
/** The values of the switches in a config.asm text, by name. Lines that are not a value line are not read. */
|
|
940
|
-
export function configValues(text: string): Map<string, 0 | 1> {
|
|
941
|
-
const values = new Map<string, 0 | 1>();
|
|
942
|
-
for (const line of text.split(/\r?\n/)) {
|
|
943
|
-
const match = CONFIG_VALUE.exec(line);
|
|
944
|
-
if (match !== null) values.set(match[1]!, match[2] === "1" ? 1 : 0);
|
|
945
|
-
}
|
|
946
|
-
return values;
|
|
947
|
-
}
|
|
934
|
+
export { CONFIG_FILE, configValues };
|
|
948
935
|
|
|
949
936
|
/**
|
|
950
937
|
* config.asm: the value of each switch as a plain assignment, grouped by
|
|
@@ -977,7 +964,7 @@ export function configText(layout: Pick<Layout, "switches" | "patches" | "startS
|
|
|
977
964
|
}
|
|
978
965
|
}
|
|
979
966
|
if (layout.startScreen) {
|
|
980
|
-
out.push("", "; Start screen: on by default", `${START_SCREEN_SWITCH} = ${values.get(START_SCREEN_SWITCH) ?? 1} ; the loader shows the start screen and waits for a key or a fire button. 0 starts the program at once`);
|
|
967
|
+
out.push("", "; Start screen: on by default", `${START_SCREEN_SWITCH} = ${values.get(START_SCREEN_SWITCH) ?? 1} ; the loader shows the start screen and waits for a key or a fire button. 0 starts the program at once. Only the clean build has it: a release and LEFTOVERS = 1 have none`);
|
|
981
968
|
}
|
|
982
969
|
if (layout.leftovers.length > 0) {
|
|
983
970
|
const bytes = layout.leftovers.reduce((sum, range) => sum + range.end - range.start + 1, 0);
|
|
@@ -1006,6 +993,8 @@ function switchesText(layout: Layout): string {
|
|
|
1006
993
|
out.push(`!ifdef ${RELEASE_DEFINE}${release.label} {`);
|
|
1007
994
|
for (const row of layout.switches) out.push(`${INDENT}${row.name} = ${row.releases.includes(release.label) ? 1 : 0}`);
|
|
1008
995
|
if (layout.leftovers.length > 0) out.push(`${INDENT}${LEFTOVERS_SWITCH} = 1`);
|
|
996
|
+
// The start screen is part of the clean build only: the build of a release is the bytes of its file.
|
|
997
|
+
if (layout.startScreen) out.push(`${INDENT}${START_SCREEN_SWITCH} = 0`);
|
|
1009
998
|
out.push("}");
|
|
1010
999
|
}
|
|
1011
1000
|
if (hasConfigFile(layout)) {
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// the loader as it is in memory before it starts (the plain loader file, or
|
|
4
4
|
// the parts of the packed form), the bytes of the stage that the start screen
|
|
5
5
|
// uses at their own addresses, the bytes of the loader that those cover in a
|
|
6
|
-
// stash, and the show code into one loader.
|
|
6
|
+
// stash, and the show code into one loader program. The show code shows the
|
|
7
7
|
// screen with start-screen.asm, calls the routine of the stage, waits for a
|
|
8
8
|
// key or a fire button, stops the interrupts of the stage, sets the CIAs as
|
|
9
9
|
// RUN leaves them, copies the stash back and starts the loader.
|
|
@@ -27,6 +27,8 @@ export interface StageInput {
|
|
|
27
27
|
innerPort: number;
|
|
28
28
|
/** The bytes of the stage that the start screen uses, in address order, at $0400 or higher. */
|
|
29
29
|
stage: StagePart[];
|
|
30
|
+
/** The colour RAM of the capture of the stage, when the start screen takes its colours from it: the show code holds it. */
|
|
31
|
+
colourRam?: Uint8Array;
|
|
30
32
|
row: StartScreenRow;
|
|
31
33
|
plan: StartScreenPlan;
|
|
32
34
|
/** The lines that include switches.asm or config.asm, for START_SCREEN. */
|
|
@@ -41,7 +43,7 @@ export interface StagePlan {
|
|
|
41
43
|
code: number;
|
|
42
44
|
/** The parts of the loader under the bytes of the stage: where the show code copies them back from. */
|
|
43
45
|
stash: Array<{ target: AddressRange; at: number }>;
|
|
44
|
-
/** start_screen_stage.asm: the show code at `code`,
|
|
46
|
+
/** start_screen_stage.asm: the show code at `code`, and each part of the stage at its own address. */
|
|
45
47
|
text: string;
|
|
46
48
|
}
|
|
47
49
|
|
|
@@ -50,7 +52,9 @@ export const STAGE_FILE = "start_screen_stage.asm";
|
|
|
50
52
|
/** The labels of the show stage: its start and the end of the show code. */
|
|
51
53
|
export const STAGE_START = "c64_source_stage";
|
|
52
54
|
export const STAGE_CODE_END = "c64_source_stage_code_end";
|
|
53
|
-
/** The label of
|
|
55
|
+
/** The label of the colour RAM of the capture in the show code. */
|
|
56
|
+
export const STAGE_COLOURS = "c64_source_stage_colours";
|
|
57
|
+
/** The label of a part of the stage: its first byte and the byte after it. */
|
|
54
58
|
export const stageLabel = (start: number, part: "from" | "end") => `stage_${part}_${start.toString(16).padStart(4, "0")}`;
|
|
55
59
|
|
|
56
60
|
/** One copy of the stash: the length, where it is read and where it is written. */
|
|
@@ -139,7 +143,7 @@ export function stageText(input: StageInput, code: number, stash: StagePlan["sta
|
|
|
139
143
|
const { row } = input;
|
|
140
144
|
const lines = [
|
|
141
145
|
...input.header.map((line) => `; ${line}`),
|
|
142
|
-
`; The show stage of the start screen from ${row.stage}: Exomizer packs it with the loader into loader
|
|
146
|
+
`; The show stage of the start screen from ${row.stage}: Exomizer packs it with the loader into the loader program, with --entry '${formatC64Address(code)}'.`,
|
|
143
147
|
"; It shows the start screen, waits for a key or a fire button, copies back the bytes of the loader that the stage covers, and starts the loader.",
|
|
144
148
|
"",
|
|
145
149
|
"!cpu 6510",
|
|
@@ -244,10 +248,12 @@ export function stageText(input: StageInput, code: number, stash: StagePlan["sta
|
|
|
244
248
|
...stash.map((item) => ` !word ${item.target.end - item.target.start + 1}, ${formatC64Address(item.at)}, ${formatC64Address(item.target.start)} ; ${show(item.target)} of the loader`),
|
|
245
249
|
" !word 0",
|
|
246
250
|
"}",
|
|
251
|
+
...(input.colourRam === undefined ? [] : [`; The colour RAM of the capture of ${row.stage}.`, STAGE_COLOURS, ...byteLines({ start: 0, body: input.colourRam })]),
|
|
247
252
|
STAGE_CODE_END,
|
|
248
253
|
];
|
|
254
|
+
// Each part at its own address: the code is in a free range, so no part overlaps it, and the build never runs past $ffff.
|
|
249
255
|
for (const part of input.stage) {
|
|
250
|
-
lines.push("", `; ${row.stage} ${show(rangeOf(part))}`,
|
|
256
|
+
lines.push("", `; ${row.stage} ${show(rangeOf(part))}`, `* = ${formatC64Address(part.start)}`, stageLabel(part.start, "from"), ...byteLines(part), stageLabel(part.start, "end"));
|
|
251
257
|
}
|
|
252
258
|
return `${lines.join("\n")}\n`;
|
|
253
259
|
}
|