Advertisement
Guest User

nes.js

a guest
Nov 21st, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import Bus from './nes/bus.js';
  2. import RP2C02 from './nes/2c02.js';
  3. import RP2A03 from './nes/2a03.js';
  4. import MCS6502 from './6502.js';
  5.  
  6. export default (rom, {Hz}) => {
  7.   const ram = [/* TODO */];
  8.   const bus = Bus(rom, ram);
  9.   const [
  10.     processor,
  11.     graphics,
  12.     sound
  13.   ] = [
  14.     MCS6502(bus),
  15.      RP2C02(bus),
  16.      RP2A03(bus),
  17.   ];
  18.  
  19.   return {
  20.     data: {
  21.       cpu: processor.data,
  22.       ppu: graphics.data,
  23.       apu: sound.data
  24.     },
  25.    
  26.     emulate: (state, ms) => {
  27.       const length = 1 + ms*Hz/1000;
  28.       const frames = Array.from({length});
  29.       const {
  30.         cpu: [cpu],
  31.         ppu: [ppu, frame],
  32.         apu: [apu]
  33.       } = frames.reduce(a => ({
  34.         cpu: processor.emulate(a.cpu, 0),
  35.         ppu: graphics.emulate(a.ppu),
  36.         apu: sound.emulate(a.apu)
  37.       }), state);
  38.  
  39.       return {
  40.         frame,
  41.         //cc,
  42.         state: {
  43.           cpu,
  44.           ppu,
  45.           apu
  46.         },
  47.         ms: frames.reduce(T => T - 1000/Hz, ms)
  48.       };
  49.     }
  50.   };
  51. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement