Example #1
0
        public GameBoyCpu(GameBoy device)
        {
            if (device == null)
            {
                throw new ArgumentNullException(nameof(device));
            }
            _device       = device;
            _disassembler = new Z80Disassembler(device.Memory);

            Registers        = new RegisterBank();
            Alu              = new GameBoyAlu(Registers);
            Breakpoints      = new HashSet <ushort>();
            EnableFrameLimit = true;

            new Thread(CpuLoop)
            {
                Name         = "Z80CPULOOP",
                IsBackground = true
            }.Start();

            _frameTimer = new NativeTimer((timerid, msg, user, dw1, dw2) =>
            {
                _frameStartSignal.Set();
                var time             = DateTime.Now.TimeOfDay;
                var delta            = time - _frameStartTime;
                CyclesPerSecond      = (_ticks - _frameStartTickCount) / delta.TotalSeconds;
                FramesPerSecond      = 1 / delta.TotalSeconds;
                _frameStartTime      = time;
                _frameStartTickCount = _ticks;
            }, 59);
        }
Example #2
0
        public GameBoyCpu(GameBoy device, IClock clock)
        {
            _device       = device ?? throw new ArgumentNullException(nameof(device));
            _disassembler = new Z80Disassembler(device.Memory);

            Registers = new RegisterBank();
            Alu       = new GameBoyAlu(Registers);
        }
Example #3
0
        public GameBoyCpu(GameBoy device, IClock clock)
        {
            _device       = device ?? throw new ArgumentNullException(nameof(device));
            _disassembler = new Z80Disassembler(device.Memory);

            Registers        = new RegisterBank();
            Alu              = new GameBoyAlu(Registers);
            EnableFrameLimit = true;
            Clock            = clock ?? throw new ArgumentNullException(nameof(clock));

            Clock.Tick += ClockOnTick;
            new Thread(CpuLoop)
            {
                Name         = "Z80CPULOOP",
                IsBackground = true
            }.Start();
        }