@moonbase-machines/player 0.11.0 → 0.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -96,7 +96,7 @@ return {
96
96
  // A C64 game: on moonbase's own ROMs (@moonbase-machines/c64/rom.js), as the site has it everywhere, or on
97
97
  // Commodore's where the page gives them (`roms`) and asks for them; the machine autostarted
98
98
  // with LOAD"name",8,1, and RUN for a BASIC program, typed into the KERNAL's buffer, the frame on a canvas of
99
- // 384 by 272 doubled, the keys as the matrix and the arrows as the joystick.
99
+ // 384 by 272 doubled, the keys as the matrix, the arrows its cursor keys, and a gamepad the joystick.
100
100
  async function c64(g, { canvas, layer, speaker }) {
101
101
  const { game, saves, roms: makers, studies, status, printer } = g;
102
102
  const [{ C64 }, { keyboard, painter }, { SID }, { c64Roms, typed: startTyped }, { add }] = await Promise.all([
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moonbase-machines/player",
3
- "version": "0.11.0",
3
+ "version": "0.12.0",
4
4
  "description": "The player for Mark Wharton's titles of 1985 to 1995: the Original, a game's own disk on Moonbase's machines, and the Remake, its scenes on an engine; the player's own disk of saves in the browser.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -14,11 +14,11 @@
14
14
  "moonbase-play": "./bin/moonbase-play.mjs"
15
15
  },
16
16
  "dependencies": {
17
- "@moonbase-machines/apple2e": "0.11.0",
18
- "@moonbase-machines/c64": "0.11.0",
19
- "@moonbase-machines/charset": "0.11.0",
20
- "@moonbase-machines/mos6502": "0.11.0",
21
- "@moonbase-machines/vector": "0.11.0"
17
+ "@moonbase-machines/apple2e": "0.12.0",
18
+ "@moonbase-machines/c64": "0.12.0",
19
+ "@moonbase-machines/charset": "0.12.0",
20
+ "@moonbase-machines/mos6502": "0.12.0",
21
+ "@moonbase-machines/vector": "0.12.0"
22
22
  },
23
23
  "scripts": {
24
24
  "test": "node --test test/*.test.js",
@@ -0,0 +1,138 @@
1
+ # The remake engine
2
+
3
+ A remake is not a game written again in JavaScript. It is the title's own code, lifted from the original into scene
4
+ scripts, compiled to JavaScript and run on this engine. The engine stands in for the machine and for the routines the
5
+ title called. The logic is the original's, statement for statement, so the remake does what the original did, and the
6
+ pilots can hold the two side by side, event by event.
7
+
8
+ A title of its own engine is the exception: its `title.js` names a module in its folder as its `engine`, and that
9
+ module plays the game itself (below).
10
+
11
+ ## A title's folder
12
+
13
+ The page gives the player the title's folder (`../README.md` says what is in it). For a remake on this engine it holds:
14
+
15
+ - `title.js`: the engine, `'card'` or `'vector'`; the scripts and the one it starts with; the files that load as
16
+ scripts (`fileScripts`); the memory at the start; the entries other scripts jump into; and the `map`, the routines
17
+ the scenes call, by address, each with the name of its step.
18
+ - `<name>.scene`: the scripts, as lifted and as edited after. They are the source.
19
+ - `compiled/<name>.js`: each scene compiled by `moonbase-compile`, which the remake runs. These are always compiled
20
+ again from the scene and never edited.
21
+ - the title's own modules, where it has them: its problems (`modules`) and its view's drawing (`view`).
22
+
23
+ ## A scene script
24
+
25
+ A scene is a step or a statement to a line (`script.js`), each line with the address in the original it came from:
26
+
27
+ ```
28
+ L0813: a label
29
+ 0813 if a != 127 goto L0825 a branch on a compare, or on a flag: if zero goto L0825
30
+ 0817 call L08BF a call into the script's own code
31
+ 081C char 32 a step: one of the title's routines, with its inputs
32
+ 0825 x = 0 a statement on the registers a, x and y, the flags, the stack and memory
33
+ data $08D7 00 00 80 80 bytes of the original's tables, at their addresses
34
+ ; a comment
35
+ ```
36
+
37
+ A statement is the original's own instruction, written so it can be read. The engine runs it on three registers,
38
+ four flags, a stack and 64K of memory, as the 6502 did. A step is a call into one of the title's routines, which the
39
+ title's `map` names by address (`0x0800: 'char'`). The engine does the routine's work in JavaScript and emits an
40
+ event. Everything a scene does is an event: the view draws the events, and a pilot reads them as the transcript to
41
+ hold against the original's.
42
+
43
+ ### Code that rewrites itself
44
+
45
+ A scene is the code as text, lifted once, so it can't follow code that changes its own instructions. The 6502 does
46
+ follow it, because it reads each instruction's bytes from memory as it runs. A routine that keeps a pointer in the
47
+ address bytes of its own `LDA` and moves the pointer by incrementing them would be lifted as a read of one fixed
48
+ address. Microsoft's CHRGET in 6502 BASIC is the best-known case. Such a line needs either a step, the routine
49
+ answered in JavaScript, or a hand edit to read through the pointer instead (`a = [$007A]`, the byte at the address
50
+ held at `$7A` and `$7B`), with the reason beside it.
51
+
52
+ ## Compiled to JavaScript
53
+
54
+ `moonbase-compile <title folder>` writes each scene as an ES module in `compiled/` (`compile.js`). The module's
55
+ default export is `{ labels, data, steps, run }`:
56
+
57
+ - `labels`, each label's step;
58
+ - `data`, the bytes the script puts in memory;
59
+ - `steps`, each step's address, its line in the scene and its text;
60
+ - `run`, a function for each block of the script, by the step it starts at.
61
+
62
+ A run of statements that only computes is one function, a loop where it branches back to its own start, each line
63
+ with the scene's line beside it as a comment. Anything that can stop the run stays a step of its own, so the title
64
+ waits where it waited: a routine's step, and a read or write that may reach the I/O page. A jump, a call or a return
65
+ ends a function.
66
+
67
+ The player loads the compiled modules with `import()` (`load.js` `loadTitle`). There is no JSON in between. The JSON
68
+ beside the title, `<name>.json`, is the game's data: its disks' files, its kind and where it saves. `loadTitle` with
69
+ `scenes` reads the `.scene` files instead and runs them line by line, which gives the same results more slowly.
70
+
71
+ ## The two engines
72
+
73
+ The scripts are the same for every title. What differs is the routines their steps call, and there are two sets.
74
+
75
+ - **Card** (`card.js`, `cards.js`, `card-view.js`, `c64-view.js`): a title on the Apple IIe or the Commodore 64. A
76
+ toolkit's own code is lifted into scripts too, beside the scenes. What cannot be a script is JavaScript here: the
77
+ routines that take their data inline after the call (fill, copy, print), the Apple's ROM routines and ProDOS's
78
+ calls (`@moonbase-machines/apple2e`), the Commodore 64's KERNAL, I/O page, drive, printer and BASIC
79
+ (`@moonbase-machines/c64`), the keyboard and the soft switches. The screen is the machine's own, written byte for
80
+ byte as the original wrote it.
81
+ - **Vector** (`vector.js`, `layout.js`, `raster.js`, `problems.js`, `view.js`): a title on the vector engine. Its
82
+ routines (a text, a picture, a box, a wait, a key) are written again here by the original's rules for keys, random
83
+ numbers and waits. The view draws the pictures from their shapes as SVG (`@moonbase-machines/vector`), at any size.
84
+ A title's problems are its own module, rewritten in JavaScript as generators, run with the helpers in `problems.js`.
85
+
86
+ `load.js` makes the engine from the title and its scripts (`makeEngine`), with the routines of the title's `engine`.
87
+ `../engines/scenes.js` plays it on the page.
88
+
89
+ ## The original's time
90
+
91
+ A title's code sits in the remake's memory where it came from, so the engine counts the time the original took
92
+ (`Engine.time`). Each line costs its instruction's cycles, read from the opcode at its address, and a branch taken
93
+ costs one more. A click of the speaker is kept at its cycle and played as the emulator plays it (`../audio.js`), so
94
+ the remake runs at the original's speed and sounds as it did.
95
+
96
+ ## Bugs fixed
97
+
98
+ The remake plays the game as it was, bugs and all, because the pilots hold it against the original. A title can
99
+ also have a version with its bugs fixed, as a separate script beside the faithful one. Its `title.js` names each
100
+ script that version replaces:
101
+
102
+ ```js
103
+ fixed: { game: 'game-fixed' }
104
+ ```
105
+
106
+ The player's setting **Bugs fixed** (`play.js`, `fixed`) is offered only for a title that has one. With it on,
107
+ `loadTitle` runs `compiled/game-fixed.js` in place of `compiled/game.js`, and the page starts again when the
108
+ setting changes. Only compiled scripts are replaced: with `scenes`, `loadTitle` runs the faithful scenes.
109
+
110
+ Because every statement is the original's, with its address, a fix is an edit to a known line, not a guess at what
111
+ the game meant. Make the fixed script from the faithful one by edits that each check the line they change is the
112
+ one they expect. A changed line keeps its address, and a line that is new has none. That keeps the fixed version
113
+ the same game with only its bugs changed. When the faithful script is lifted again, the edits are made again, and
114
+ one whose line has changed stops instead of editing the wrong line.
115
+
116
+ Corrupted text can be fixed the same way where the text is in the code: a string a call takes inline after it, or a
117
+ scene's `data` line. Text the game reads from its disk at run time is the game's data, `<name>.json`, not a
118
+ script, and a fixed script does not change it.
119
+
120
+ ## A title of its own engine
121
+
122
+ When `title.js` names a module as its `engine`, the title has no scripts. `loadTitle` imports that module as
123
+ `title.own`, and the player hands it the game (`../play.js`). That engine is the original program's own, read from
124
+ its code and written again routine for routine, playing the game's data as the original read it.
125
+
126
+ ## The files
127
+
128
+ | File | What it is |
129
+ |---|---|
130
+ | `engine.js` | runs the scripts: the statements on the registers, flags, stack and memory, the steps through the routines, every step an event |
131
+ | `script.js` | reads a scene script, a step to a line |
132
+ | `compile.js` | compiles a scene script to JavaScript (`moonbase-compile`) |
133
+ | `load.js` | loads a title's folder, its compiled scripts or its scenes, and makes its engine |
134
+ | `events.js` | what each step is as an event, in the same words for the original and the remake |
135
+ | `lift.js` | the lifter: a file's 6502 walked from its entries into a scene script; the card engine uses it to lift code a title's scenes miss, as it runs |
136
+ | `card.js`, `cards.js` | the card engine's routines, and what it knows of every title it plays |
137
+ | `vector.js`, `layout.js`, `raster.js`, `problems.js` | the vector engine's routines; its text laid out as the engine laid it out; the original's screen dot for dot, for the scenes that read it back; its problems' helpers |
138
+ | `view.js`, `card-view.js`, `c64-view.js` | the views: a vector title's as SVG, an Apple's hi-res page, a Commodore 64's screen |