예제 #1
0
        /**
         * Used to start execution of the CPU with the given ROM and optional emulator state.
         * The emulator's hardware loop will run on a spereate thread, and therefore, this method
         * is non-blocking.
         */
        public void Start(byte[] rom, EmulatorState state = null)
        {
            if (_thread != null)
            {
                throw new Exception("Emulator cannot be started because it was already running.");
            }

            _cyclesSinceLastInterrupt = 0;
            _nextInterrupt            = Interrupt.One;

            _cpu = new CPU(_cpuConfig);

            _cpu.OnDeviceRead  += CPU_OnDeviceRead;
            _cpu.OnDeviceWrite += CPU_OnDeviceWrite;

            // Map the ROM into the lower 8K of the memory space.
            var memory = new byte[_cpuConfig.MemorySize];

            Array.Copy(rom, memory, rom.Length);

            _cpu.LoadMemory(memory);

            _shiftRegister = new ShiftRegister();

            _renderEventArgs = new RenderEventArgs()
            {
                ShouldRender = false,
                FrameBuffer  = new byte[FRAME_BUFFER_SIZE],
            };

            _soundEventArgs = new SoundEventArgs();

            if (state != null)
            {
                LoadState(state);
            }

            _cancelled   = false;
            _thread      = new Thread(new ThreadStart(HardwareLoop));
            _thread.Name = "Emulator: Hardware Loop";
            _thread.Start();
        }
예제 #2
0
 /**
  * Fired when the emulator needs to play a sound.
  */
 private static void SpaceInvaders_OnSound(SoundEventArgs eventArgs)
 {
     _soundEffects.Add(eventArgs.SoundEffect);
     _playSoundNextTick = true;
 }