Ejemplo n.º 1
0
        public void InitializeComponents(ISystemBus systemBus)
        {
            _runDelegates.Clear();
            _addressManager.Clear();
            _interuptManager.Clear();
            _portManager.Clear();
            foreach (var component in _components)
            {
                if (component is IInteruptableSystemComponent)
                {
                    ((IInteruptableSystemComponent)component).RegisterInteruptHandlers(_interuptManager);
                }

                if (component is IAddressableSystemComponent)
                {
                    ((IAddressableSystemComponent)component).RegisterAddressBlocks(_addressManager);
                }

                if (component is IPortAddressableSystemComponent)
                {
                    ((IPortAddressableSystemComponent)component).RegisterPortAddresses(_portManager);
                }
            }

            foreach (var component in _components)
            {
                if (component is IRunnableSystemComponent)
                {
                    _runDelegates.Add((IRunnableSystemComponent)component, ((IRunnableSystemComponent)component).GetRunMethod(systemBus));
                }
            }            
        }
        public DataAccessExpressionLibrary(ISystemBus systemBus)
        {
            _systemBus = systemBus;

            CpuParameter = Expression.Variable(typeof(CpuData), "cpu");
            SystemBusParameter = Expression.Variable(typeof(ISystemBus), "systemBus");
            RegisterAParameter = Expression.Parameter(typeof(Int32), "registerA");
            RegisterBParameter = Expression.Variable(typeof(Int32), "registerB");
            RegisterCParameter = Expression.Variable(typeof(Int32), "registerC");
            RegisterDParameter = Expression.Variable(typeof(Int32), "registerD");
            RegisterEParameter = Expression.Variable(typeof(Int32), "registerE");
            RegisterHParameter = Expression.Variable(typeof(Int32), "registerH");
            RegisterLParameter = Expression.Variable(typeof(Int32), "registerL");
            RegisterIXParameter = Expression.Variable(typeof(Int32), "registerIX");
            RegisterIYParameter = Expression.Variable(typeof(Int32), "registerIY");
            StackPointerRegisterParameter = Expression.Variable(typeof(Int32), "stackPointerRegister");
            FlagsRegisterParameter = Expression.Variable(typeof(Int32), "flagsRegister");
            TempParameter = Expression.Variable(typeof(Byte), "temp");


            readByteMethod = typeof(ISystemBus).GetMethod("ReadByte");
            readWordMethod = typeof(ISystemBus).GetMethod("ReadWord");

            writeByteMethod = typeof(ISystemBus).GetMethod("WriteByte");
            writeWordMethod = typeof(ISystemBus).GetMethod("WriteWord");

            readPortMethod = typeof(ISystemBus).GetMethod("ReadPort");
            writePortMethod = typeof(ISystemBus).GetMethod("WritePort");
        }
Ejemplo n.º 3
0
 public void RunFrame(Int32 cycles, ISystemBus systemBus)
 {
     foreach (var runner in _runDelegates.Values)
     {
         runner.Invoke(cycles, systemBus);
     }
 }
Ejemplo n.º 4
0
        public RunDelegate GetRunMethod(ISystemBus systemBus)
        {
            return (cycles, bus) =>
                {
                    if (Settings.IsDisplayEnabled)
                       RenderScanline();

                    _currentScanline++;
                    
                    if (_currentScanline == VerticalResolution)
                    {
                        if (Settings.IsVSyncInterruptEnabled)
                        {
                            _statusByte |= 0x80;
                            bus.RequestInterupt(Interupts.Scanline);
                        }
                    }

                    if (_currentScanline == ScanlinesPerFrame)
                    {
                        _currentScanline = 0;
                    }

                    return 0;
                };
        }
Ejemplo n.º 5
0
 public OrderService(
     ILogger <OrderService> logger,
     IOrderRepository repository,
     ISystemBus bus)
 {
     _logger     = logger;
     _repository = repository;
     _bus        = bus;
 }
Ejemplo n.º 6
0
 public OrderCreatedConsumer(
     ILogger <OrderCreatedConsumer> logger,
     IStockChecker stockChecker,
     ISystemBus systemBus)
 {
     _logger       = logger;
     _stockChecker = stockChecker;
     _systemBus    = systemBus;
 }
        public ProgramControlExpressionLibrary(ISystemBus systemBus)
        {
            _systemBus = systemBus;

            CycleCounterParameter = Expression.Variable(typeof(Int32), "cycleCounter");
            ParameterByte1Parameter = Expression.Variable(typeof(Int32), "parameterByte1");
            ParameterByte2Parameter = Expression.Variable(typeof(Int32), "parameterByte2");
            ProgramCounterRegisterParameter = Expression.Variable(typeof(Int32), "programCounterRegister");
            CpuParameter = Expression.Variable(typeof(CpuData), "programControlCpu");
            SystemBusParameter = Expression.Variable(typeof(ISystemBus), "programControlSystemBus");
            TempParameter = Expression.Variable(typeof(Byte), "temp");
            TempIParameter = Expression.Variable(typeof(Int32), "tempI");
            CpuCacheParameter = Expression.Variable(typeof(Int32[]), "cpuCacheParameter");
            BreakpointHandlerParameter = Expression.Variable(typeof(BreakpointHandler), "breakpointHandler");

            readMethod = typeof(ISystemBus).GetMethod("ReadByte");
        }
Ejemplo n.º 8
0
        public SmsEmulator()
        {
            _cart = new Cartridge();
            _breakpointHandler = new BreakpointHandler(_cart);
            _cpu = new Z80Cpu(_breakpointHandler);
            _cpu.InstructionRan += new System.EventHandler<InstructionAdvice.CpuEventArgs>(_cpu_InstructionRan);
            _cpu.IsRecentHistoryEnabled = false;

            _ri = new ReferenceImplementation();            
            _ram = new Ram();
            _vdp = new VideoDisplayProcessor();
            _gamepads = new GamepadPorts();

            IInteruptManager interuptManager = new InteruptManager();
            IPortManager portManager = new PortManager();
            IAddressManager addressManager = new AddressManager(new CacheManager(_cpu.Data));

            _systemBus = new SystemBus(interuptManager, addressManager, portManager);
            _componentManager = new ComponentManager(interuptManager, addressManager, portManager);
        }
Ejemplo n.º 9
0
        private IExpressionLibraryRegistry BuildExpressionLibraryRegistry(ISystemBus systemBus)
        {
            var libRegistry = new ExpressionLibraryRegistry();
            libRegistry.RegisterLibrary(new DataAccessExpressionLibrary(systemBus));
            libRegistry.RegisterLibrary(new FlagLookupValuesExpressionLibrary());
            libRegistry.RegisterLibrary(new TemporaryExpressionLibrary());
            libRegistry.RegisterLibrary(new ProgramControlExpressionLibrary(systemBus));
            libRegistry.RegisterLibrary(new InteruptExpressionLibrary());
            libRegistry.RegisterLibrary(new PrimeRegisterExpressionLibrary());

            return libRegistry;
        }
Ejemplo n.º 10
0
 public CpuEventArgs(Int32 registerA, 
                     Int32 registerB,
                     Int32 registerC,
                     Int32 registerD,
                     Int32 registerE,
                     Int32 registerH,
                     Int32 registerL,
                     Int32 flagsRegister,
                     Int32 programCounterRegsiter,
                     Int32 stackPointerRegsiter,
                     Int32 cycleCounter,
                     InstructionInfo info,
                     ISystemBus systemBus
     )
 {
     RegisterA = registerA;
     RegisterB = registerB;
     RegisterC = registerC;
     RegisterD = registerD;
     RegisterE = registerE;
     RegisterH = registerH;
     RegisterL = registerL;
     FlagsRegister = flagsRegister;
     ProgramCounterRegister = programCounterRegsiter;
     StackPointerRegister = stackPointerRegsiter;
     CycleCounter = cycleCounter;
     Instruction = info;
     SystemBus = systemBus;
 }
        public RunDelegate GetRunMethod(ISystemBus systemBus)
        {
            _bus = systemBus;

            return (cycles, bus) =>
                {
                    Exec(cycles);
                    return 0;
                };

        }
Ejemplo n.º 12
0
        public RunDelegate GetRunMethod(ISystemBus systemBus)
        {
            _data.StackPointerRegister = 0;
            _data.InteruptMode = 1;

            return BuildRunMethod(systemBus);
        }
Ejemplo n.º 13
0
        private RunDelegate BuildRunMethod(ISystemBus systemBus)
        {
            _context.Data = _data;
            _context.Flags = _flagTables;
            _context.SystemBus = systemBus;
            _context.BreakpointHandler = _breakpointHandler;
            Object[] parameters = _expressionBuilder.GetObjects(_context);

            return ((cycles, bus) =>
                {
                    try
                    {
                        if (IsRecentHistoryEnabled)
                            _history.ClearHistory();

                        cycles = _cycleCounter + cycles;
                        _data.CycleCounter = cycles;

                        if (_data.CycleCounter > 0)
                            _cpuCode.DynamicInvoke(parameters);

                        _cycleCounter = _data.CycleCounter;
                        return 0;
                    }
                    catch (TargetInvocationException ex)
                    {
                        throw new InstructionExecutionException(InstructionHistory, Data, ex);
                    }
                }
            );
        }