@moonbase-machines/c64 0.12.0 → 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/browser.js CHANGED
@@ -1,15 +1,17 @@
1
1
  // A Commodore 64 (machine.js) in a browser page: each key one key of the C64's matrix and nothing else, the arrows its
2
2
  // cursor keys, Escape RUN/STOP, Control the Commodore key, Tab CTRL; the joystick a gamepad plugged in (an 8BitDo, or
3
3
  // any in the browser's standard mapping), never a key; the frame painted on a canvas doubled; and the machine run 50
4
- // frames a second, keeping up with the clock, two frames at most at a time.
4
+ // frames a second against the clock, a hitch caught up and a pause dropped (@moonbase-machines/mos6502/pace.js).
5
5
  //
6
6
  // const keys = keyboard(m, { ignore, onKey, log, listen }) ignore(e): a key the page keeps (a pane's); listen(type,
7
7
  // f), where its keys come from (the window's, unless a player gives
8
8
  // its own)
9
9
  // keys.press(column, row, frames) a key held for so many frames (RUN/STOP)
10
10
  // const draw = painter(canvas) draw(m.vic.frame)
11
- // pace(m, after) the frames run; after() each animation frame
11
+ // pace(m, after, each) the machine run at 50 frames a second: each(frames) after
12
+ // each frame, after(frames) each animation frame
12
13
  import { MATRIX, SHIFTED, WITH_SHIFT, CURSOR, MODIFIERS } from './keys.js';
14
+ import { pace as paced } from '@moonbase-machines/mos6502/pace.js';
13
15
  import { PALETTE, WIDTH, HEIGHT } from './vic.js';
14
16
 
15
17
  const PAD_DEAD = 0.4; // a stick pushed less far than this is at rest (the dead zone)
@@ -102,14 +104,4 @@ export function painter(canvas) {
102
104
 
103
105
  // the C64's 50 frames a second, kept up with the clock (two at most at a time, so a tab left in
104
106
  // the background does not run on and on when it comes back); each(frame) after each one run
105
- export function pace(m, after, each = () => {}) {
106
- let frames = 0;
107
- const started = performance.now();
108
- function tick() {
109
- const due = Math.min(2, Math.floor((performance.now() - started) / 20) - frames);
110
- for (let i = 0; i < due; i++) { m.runFrame(); frames++; each(frames); }
111
- after(frames);
112
- requestAnimationFrame(tick);
113
- }
114
- tick();
115
- }
107
+ export const pace = (m, after, each = () => {}) => paced(n => { m.runFrame(); each(n); }, 50, { after });