示例#1
0
        /// <summary>
        /// Creates the RexBoard and all components within it.
        /// </summary>
        public RexBoard()
        {
            //Initialise busses
            mDataBus    = new Bus();
            mAddressBus = new Bus();
            mIrqs       = new Bus();

            //Initialise other components
            CPU = new SimpleWrampCpu(mAddressBus, mDataBus, mIrqs, mCs);

            //Memory and Memory-mapped IO
            RAM             = new MemoryDevice(0x00000, 0x20000, mAddressBus, mDataBus, "Memory (RAM)");
            Serial1         = new SerialIO(0x70000, 5, mAddressBus, mDataBus, "Serial Port 1");
            Serial2         = new SerialIO(0x71000, 5, mAddressBus, mDataBus, "Serial Port 2");
            Timer           = new Timer(0x72000, 4, mAddressBus, mDataBus, "Timer");
            Parallel        = new ParallelIO(0x73000, 6, mAddressBus, mDataBus, "Parallel Port");
            ROM             = new MemoryDevice(0x80000, 0x40000, mAddressBus, mDataBus, "Memory (ROM)");
            InterruptButton = new ButtonInterrupt(0x7f000, 1, mAddressBus, mDataBus, "Interrupt Button");

            //IRQs
            InterruptButton.AttachIRQ(mIrqs, 1, 0);
            Timer.AttachIRQ(mIrqs, 2, 3);
            Parallel.AttachIRQ(mIrqs, 3, 5);
            Serial1.AttachIRQ(mIrqs, 4, 4);
            Serial2.AttachIRQ(mIrqs, 5, 4);

            Reset();
        }
        /// <summary>
        /// Define how to handle an unattached port
        /// </summary>
        /// <param name="addr">Port address</param>
        /// <returns>Port value for the unhandled port address</returns>
        public override byte UnhandledRead(ushort addr)
        {
            var tact    = HostVm.CurrentFrameTact % ScreenDevice.RenderingTactTable.Length;
            var rt      = ScreenDevice.RenderingTactTable[tact];
            var memAddr = (ushort)0;

            switch (rt.Phase)
            {
            case ScreenRenderingPhase.BorderFetchPixel:
            case ScreenRenderingPhase.DisplayB1FetchB2:
            case ScreenRenderingPhase.DisplayB2FetchB1:
                memAddr = rt.PixelByteToFetchAddress;
                break;

            case ScreenRenderingPhase.BorderFetchPixelAttr:
            case ScreenRenderingPhase.DisplayB1FetchA2:
            case ScreenRenderingPhase.DisplayB2FetchA1:
                memAddr = rt.AttributeToFetchAddress;
                break;
            }

            if (memAddr == 0)
            {
                return(0xFF);
            }
            var readValue = MemoryDevice.Read(memAddr, true);

            return(readValue);
        }
示例#3
0
        static void Main(string[] args)
        {
            Console.WriteLine("Введите кол-во ячеек для запоминающего устройства: ");
            int countCell = int.Parse(Console.ReadLine());

            var memoryDevice = new MemoryDevice(countCell);
        }
示例#4
0
 /// <summary>
 /// Injects code into the memory
 /// </summary>
 /// <param name="addr">Start address</param>
 /// <param name="code">Code to inject</param>
 /// <remarks>The code leaves the ROM area untouched.</remarks>
 public void InjectCodeToMemory(ushort addr, IReadOnlyCollection <byte> code)
 {
     foreach (var codeByte in code)
     {
         MemoryDevice.Write(addr++, codeByte);
     }
 }
示例#5
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="mem">The memory device to display.</param>
        public MemoryForm(MemoryDevice mem)
        {
            InitializeComponent();

            this.Text                      = mem.Name;
            this.mDevice                   = mem;
            this.mIr                       = new IR();
            this.mShadow                   = new uint[mem.Size];
            this.mVirtualItems             = new ListViewItem[mem.Size];
            memoryListView.VirtualListSize = (int)mem.Size;
            mBreakpoints                   = new List <uint>();

            //Populate view buffer
            for (uint i = 0; i < mDevice.Size; i++)
            {
                uint address = i + mDevice.BaseAddress;
                uint value   = 0xffffffff; //Note: this should come from memory, but the default value zero is immediately set to 0xffffffff by WRAMPmon, resulting in a complete (slow) redraw.
                mIr.Instruction = value;
                mShadow[i]      = value;

                string addressStr  = address.ToString("X8");
                string valueStr    = value.ToString("X8");
                string disassembly = mIr.ToString();

                mVirtualItems[i] = new ListViewItem(new string[] { "", addressStr, valueStr, disassembly });
            }
            updateTimer.Start();
        }
示例#6
0
        /// <summary>
        /// Prepares the custom code for running, as if it were started
        /// with the RUN command
        /// </summary>
        public void PrepareRunMode()
        {
            // --- Set the keyboard in "L" mode
            var flags = MemoryDevice.Read(0x5C3B);

            flags |= 0x08;
            MemoryDevice.Write(0x5C3B, flags);
        }
示例#7
0
 /// <summary>
 /// Loads the content of the ROM through the specified provider
 /// </summary>
 /// <param name="romDevice">ROM device instance</param>
 /// <param name="romConfig">ROM configuration</param>
 /// <remarks>
 /// The content of the ROM is copied into the memory
 /// </remarks>
 public void InitRom(IRomDevice romDevice, IRomConfiguration romConfig)
 {
     for (var i = 0; i < romConfig.NumberOfRoms; i++)
     {
         MemoryDevice.SelectRom(i);
         MemoryDevice.CopyRom(romDevice.GetRomBytes(i));
     }
     MemoryDevice.SelectRom(0);
 }
示例#8
0
 /// <summary>
 /// Prepares the custom code for running, as if it were started
 /// with the RUN command
 /// </summary>
 public void PrepareRunMode(HashSet <string> options)
 {
     if (!options.Contains("cursork"))
     {
         // --- Set the keyboard in "L" mode
         var flags = MemoryDevice.Read(0x5C3B);
         flags |= 0x08;
         MemoryDevice.Write(0x5C3B, flags);
     }
 }
示例#9
0
        /// <summary>
        /// Prepares the custom code for running, as if it were started
        /// with the RUN command
        /// </summary>
        public void PrepareRunMode()
        {
            // --- Set the keyboard in "L" mode
            var flags = MemoryDevice.Read(0x5C3B);

            flags |= 0x08;
            MemoryDevice.Write(0x5C3B, flags);

            // --- Allow interrupts
            RunsInMaskableInterrupt = false;
        }
示例#10
0
 /// <summary>
 /// Clears the screep
 /// </summary>
 public void ClearScreen()
 {
     // --- Clear the screen
     for (var i = 0; i < 0x1800; i++)
     {
         MemoryDevice.Write((ushort)(0x4000 + i), 0x00);
     }
     for (var i = 0; i < 0x300; i++)
     {
         MemoryDevice.Write((ushort)(0x5800 + i), 0x38);
     }
 }
示例#11
0
        /// <summary>
        /// Injects code into the memory
        /// </summary>
        /// <param name="addr">Start address</param>
        /// <param name="code">Code to inject</param>
        /// <remarks>The code leaves the ROM area untouched.</remarks>
        public void InjectCodeToMemory(ushort addr, IReadOnlyCollection <byte> code)
        {
            // --- Clear the screen
            for (var i = 0; i < 0x1800; i++)
            {
                MemoryDevice.Write((ushort)(0x4000 + i), 0x00);
            }
            for (var i = 0; i < 0x300; i++)
            {
                MemoryDevice.Write((ushort)(0x5800 + i), 0x38);
            }

            // --- Now, inject the code
            foreach (var codeByte in code)
            {
                MemoryDevice.Write(addr++, codeByte);
            }
        }
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="mem">The peripheral device to show the memory contents of.</param>
        public PeripheralMemoryForm(MemoryDevice mem)
        {
            InitializeComponent();

            this.Text    = mem.Name + " Registers";
            this.mDevice = mem;
            this.mShadow = new uint[mem.Size];

            //Populate view
            for (uint i = 0; i < mDevice.Size; i++)
            {
                uint address = i + mDevice.BaseAddress;
                uint v       = mDevice[address];
                mShadow[i] = v;

                listView1.Items.Add(new ListViewItem(new string[] { address.ToString("X8"), v.ToString(), v.ToString("X8"), Convert.ToString(v, 2).PadLeft(32, '0') }));
            }
            updateTimer.Start();
        }
示例#13
0
        protected virtual void InternalRegisterCoreSystemObjects()
        {
            // Create the Admin user
            _adminUser = new Schema.User(AdminUserID, "Administrator", String.Empty);

            // Register the System and Admin users
            _systemProcess.CatalogDeviceSession.InsertUser(_systemUser);
            _systemProcess.CatalogDeviceSession.InsertUser(_adminUser);

            _userRole         = new Schema.Role(UserRoleName);
            _userRole.Owner   = _systemUser;
            _userRole.Library = _systemLibrary;
            _systemProcess.CatalogDeviceSession.InsertRole(_userRole);

            // Register the Catalog device
            _systemProcess.CatalogDeviceSession.InsertCatalogObject(_catalogDevice);

            // Create the Temp Device
            _tempDevice                 = new MemoryDevice(Schema.Object.GetNextObjectID(), TempDeviceName);
            _tempDevice.Owner           = _systemUser;
            _tempDevice.Library         = _systemLibrary;
            _tempDevice.ClassDefinition = new ClassDefinition("System.MemoryDevice");
            _tempDevice.ClassDefinition.Attributes.Add(new ClassAttributeDefinition("MaxRowCount", TempDeviceMaxRowCount.ToString()));
            _tempDevice.MaxRowCount = TempDeviceMaxRowCount;
            _tempDevice.Start(_systemProcess);
            _tempDevice.Register(_systemProcess);
            _systemProcess.CatalogDeviceSession.InsertCatalogObject(_tempDevice);

            // Create the A/T Device
            _aTDevice                 = new ApplicationTransactionDevice(Schema.Object.GetNextObjectID(), ATDeviceName);
            _aTDevice.Owner           = _systemUser;
            _aTDevice.Library         = _systemLibrary;
            _aTDevice.ClassDefinition = new ClassDefinition("System.ApplicationTransactionDevice");
            _aTDevice.ClassDefinition.Attributes.Add(new ClassAttributeDefinition("MaxRowCount", ATDeviceMaxRowCount.ToString()));
            _aTDevice.MaxRowCount = ATDeviceMaxRowCount;
            _aTDevice.Start(_systemProcess);
            _aTDevice.Register(_systemProcess);
            _systemProcess.CatalogDeviceSession.InsertCatalogObject(_aTDevice);
        }
示例#14
0
        /// <summary>
        /// The main execution cycle of the Spectrum VM
        /// </summary>
        /// <param name="token">Cancellation token</param>
        /// <param name="options">Execution options</param>
        /// <return>True, if the cycle completed; false, if it has been cancelled</return>
        public bool ExecuteCycle(CancellationToken token, ExecuteCycleOptions options)
        {
            ExecuteCycleOptions          = options;
            ExecutionCompletionReason    = ExecutionCompletionReason.None;
            LastExecutionStartTact       = Cpu.Tacts;
            LastExecutionContentionValue = ContentionAccumulated;

            // --- We use these variables to calculate wait time at the end of the frame
            var cycleStartTime  = Clock.GetCounter();
            var cycleStartTact  = Cpu.Tacts;
            var cycleFrameCount = 0;

            // --- We use this variable to check whether to stop in Debug mode
            var executedInstructionCount = -1;

            // --- Loop #1: The main cycle that goes on until cancelled
            while (!token.IsCancellationRequested)
            {
                if (_frameCompleted)
                {
                    // --- This counter helps us to calculate where we are in the frame after
                    // --- each CPU operation cycle
                    LastFrameStartCpuTick = Cpu.Tacts - Overflow;

                    // --- Notify devices to start a new frame
                    OnNewFrame();
                    LastRenderedUlaTact = Overflow;
                    _frameCompleted     = false;
                }

                // --- Loop #2: The physical frame cycle that goes on while CPU and ULA
                // --- processes everything whithin a physical frame (0.019968 second)
                while (!_frameCompleted)
                {
                    // --- Check for leaving maskable interrupt mode
                    if (RunsInMaskableInterrupt)
                    {
                        if (Cpu.Registers.PC == 0x0052)
                        {
                            // --- We leave the maskable interrupt mode when the
                            // --- current instruction completes
                            RunsInMaskableInterrupt = false;
                        }
                    }

                    // --- Check debug mode when a CPU instruction has been entirelly executed
                    if (!Cpu.IsInOpExecution)
                    {
                        // --- Check for cancellation
                        if (token.IsCancellationRequested)
                        {
                            ExecutionCompletionReason = ExecutionCompletionReason.Cancelled;
                            return(false);
                        }

                        // --- The next instruction is about to be executed
                        executedInstructionCount++;

                        // --- Check for timeout
                        if (options.TimeoutTacts > 0 &&
                            cycleStartTact + options.TimeoutTacts < Cpu.Tacts)
                        {
                            ExecutionCompletionReason = ExecutionCompletionReason.Timeout;
                            return(false);
                        }

                        // --- Check for reaching the termination point
                        if (options.EmulationMode == EmulationMode.UntilExecutionPoint)
                        {
                            if (options.TerminationPoint < 0x4000)
                            {
                                // --- ROM & address must match
                                if (options.TerminationRom == MemoryDevice.GetSelectedRomIndex() &&
                                    options.TerminationPoint == Cpu.Registers.PC)
                                {
                                    // --- We reached the termination point within ROM
                                    ExecutionCompletionReason = ExecutionCompletionReason.TerminationPointReached;
                                    return(true);
                                }
                            }
                            else if (options.TerminationPoint == Cpu.Registers.PC)
                            {
                                // --- We reached the termination point within RAM
                                ExecutionCompletionReason = ExecutionCompletionReason.TerminationPointReached;
                                return(true);
                            }
                        }

                        // --- Check for entering maskable interrupt mode
                        if (Cpu.MaskableInterruptModeEntered)
                        {
                            RunsInMaskableInterrupt = true;
                        }

                        // --- Check for a debugging stop point
                        if (options.EmulationMode == EmulationMode.Debugger)
                        {
                            if (IsDebugStop(options, executedInstructionCount))
                            {
                                // --- At this point, the cycle should be stopped because of debugging reasons
                                // --- The screen should be refreshed
                                ScreenDevice.OnFrameCompleted();
                                ExecutionCompletionReason = ExecutionCompletionReason.BreakpointReached;
                                return(true);
                            }
                        }
                    }

                    // --- Check for interrupt signal generation
                    InterruptDevice.CheckForInterrupt(CurrentFrameTact);

                    // --- Run a single Z80 instruction
                    Cpu.ExecuteCpuCycle();
                    _lastBreakpoint = null;

                    // --- Run a rendering cycle according to the current CPU tact count
                    var lastTact = CurrentFrameTact;
                    ScreenDevice.RenderScreen(LastRenderedUlaTact + 1, lastTact);
                    LastRenderedUlaTact = lastTact;

                    // --- Exit if the emulation mode specifies so
                    if (options.EmulationMode == EmulationMode.UntilHalt &&
                        (Cpu.StateFlags & Z80StateFlags.Halted) != 0)
                    {
                        ExecutionCompletionReason = ExecutionCompletionReason.Halted;
                        return(true);
                    }

                    // --- Notify each CPU-bound device that the current operation has been completed
                    foreach (var device in _cpuBoundDevices)
                    {
                        device.OnCpuOperationCompleted();
                    }

                    // --- Decide whether this frame has been completed
                    _frameCompleted = !Cpu.IsInOpExecution && CurrentFrameTact >= _frameTacts;
                } // -- End Loop #2

                // --- A physical frame has just been completed. Take care about screen refresh
                cycleFrameCount++;
                FrameCount++;

                // --- Notify devices that the current frame completed
                OnFrameCompleted();

                // --- Exit if the emulation mode specifies so
                if (options.EmulationMode == EmulationMode.UntilFrameEnds)
                {
                    ExecutionCompletionReason = ExecutionCompletionReason.FrameCompleted;
                    return(true);
                }

                // --- Wait while the frame time ellapses
                if (!ExecuteCycleOptions.FastVmMode)
                {
                    var nextFrameCounter = cycleStartTime + cycleFrameCount * PhysicalFrameClockCount;
                    Clock.WaitUntil((long)nextFrameCounter, token);
                }

                // --- Start a new frame and carry on
                Overflow = CurrentFrameTact % _frameTacts;
            } // --- End Loop #1

            // --- The cycle has been interrupted by cancellation
            ExecutionCompletionReason = ExecutionCompletionReason.Cancelled;
            return(false);
        }
示例#15
0
 public BWArgs(Modes mode, MemoryDevice dev, string port)
 {
     Mode = mode;
     Device = dev;
     Port = port;
 }
示例#16
0
 /// <summary>
 /// Loads the content of the ROM through the specified provider
 /// </summary>
 /// <param name="romProvider">ROM provider instance</param>
 /// <param name="romResourceName">ROM Resource name</param>
 /// <remarks>
 /// The content of the ROM is copied into the memory
 /// </remarks>
 public void InitRom(IRomProvider romProvider, string romResourceName)
 {
     RomInfo = romProvider.LoadRom(romResourceName);
     MemoryDevice.FillMemory(RomInfo.RomBytes);
 }
示例#17
0
        /// <summary>
        /// The main execution cycle of the Spectrum VM
        /// </summary>
        /// <param name="token">Cancellation token</param>
        /// <param name="options">Execution options</param>
        /// <param name="completeOnCpuFrame">The cycle should complete on CPU frame completion</param>
        /// <return>True, if the cycle completed; false, if it has been cancelled</return>
        public bool ExecuteCycle(CancellationToken token, ExecuteCycleOptions options, bool completeOnCpuFrame = false)
        {
            ExecuteCycleOptions       = options;
            ExecutionCompletionReason = ExecutionCompletionReason.None;
            LastExecutionStartTact    = Cpu.Tacts;

            // --- We use this variables to check whether to stop in Debug mode
            var executedInstructionCount = -1;
            var entryStepOutDepth        = Cpu.StackDebugSupport.StepOutStackDepth;

            // --- Check if we're just start running the next frame
            if (HasFrameCompleted)
            {
                // --- This counter helps us to calculate where we are in the frame after
                // --- each CPU operation cycle
                LastFrameStartCpuTick = Cpu.Tacts - Overflow;

                // --- Notify devices to start a new frame
                OnNewFrame();
                LastRenderedUlaTact = Overflow;
                HasFrameCompleted   = false;
            }

            // --- The physical frame cycle that goes on while CPU and ULA
            // --- processes everything within a physical frame (0.019968 second)
            while (!HasFrameCompleted)
            {
                // --- Check debug mode when a CPU instruction has been entirely executed
                if (!Cpu.IsInOpExecution)
                {
                    // --- The next instruction is about to be executed
                    executedInstructionCount++;

                    // --- Check for cancellation
                    if (token.IsCancellationRequested)
                    {
                        ExecutionCompletionReason = ExecutionCompletionReason.Cancelled;
                        return(false);
                    }

                    // --- Check for CPU frame completion
                    if (completeOnCpuFrame && Cpu.Tacts > LastExecutionStartTact + CPU_FRAME)
                    {
                        ExecutionCompletionReason = ExecutionCompletionReason.CpuFrameCompleted;
                        return(true);
                    }

                    // --- Check for several termination modes
                    switch (options.EmulationMode)
                    {
                    // --- Check for reaching the termination point
                    case EmulationMode.UntilExecutionPoint when options.TerminationPoint < 0x4000:
                    {
                        // --- ROM & address must match
                        if (options.TerminationRom == MemoryDevice.GetSelectedRomIndex() &&
                            options.TerminationPoint == Cpu.Registers.PC)
                        {
                            // --- We reached the termination point within ROM
                            ExecutionCompletionReason = ExecutionCompletionReason.TerminationPointReached;
                            return(true);
                        }

                        break;
                    }

                    // --- Check if we reached the termination point within RAM
                    case EmulationMode.UntilExecutionPoint
                        when options.TerminationPoint == Cpu.Registers.PC:

                        ExecutionCompletionReason = ExecutionCompletionReason.TerminationPointReached;
                        return(true);

                    // --- Check for a debugging stop point
                    case EmulationMode.Debugger
                        when IsDebugStop(options, executedInstructionCount, entryStepOutDepth) &&
                        DebugConditionSatisfied():

                        // --- At this point, the cycle should be stopped because of debugging reasons
                        // --- The screen should be refreshed
                        ExecutionCompletionReason = ExecutionCompletionReason.BreakpointReached;

                        return(true);
                    }
                }

                // --- Check for interrupt signal generation
                InterruptDevice.CheckForInterrupt(CurrentFrameTact);

                // --- Run a single Z80 instruction
                Cpu.ExecuteCpuCycle();
                _lastBreakpoint = null;

                // --- Run a rendering cycle according to the current CPU tact count
                var lastTact = CurrentFrameTact;
                ScreenDevice.RenderScreen(LastRenderedUlaTact + 1, lastTact);
                LastRenderedUlaTact = lastTact;

                // --- Exit if the CPU is HALTed and the emulation mode specifies so
                if (options.EmulationMode == EmulationMode.UntilHalt &&
                    (Cpu.StateFlags & Z80StateFlags.Halted) != 0)
                {
                    ExecutionCompletionReason = ExecutionCompletionReason.Halted;
                    return(true);
                }

                // --- Notify each CPU-bound device that the current operation has been completed
                foreach (var device in _cpuBoundDevices)
                {
                    device.OnCpuOperationCompleted();
                }

                // --- Decide whether this frame has been completed
                HasFrameCompleted = !Cpu.IsInOpExecution && CurrentFrameTact >= FrameTacts;
            }

            // --- A physical frame has just been completed. Take care about screen refresh
            FrameCount++;
            Overflow = CurrentFrameTact % FrameTacts;

            // --- Notify devices that the current frame completed
            OnFrameCompleted();

            // --- We exit the cycle when the render frame has completed
            ExecutionCompletionReason = ExecutionCompletionReason.RenderFrameCompleted;
            return(true);
        }
示例#18
0
        public SMBIOS()
        {
            int p = (int)Environment.OSVersion.Platform;

            if ((p == 4) || (p == 128))
            {
                this.raw   = null;
                this.table = null;

                string boardVendor  = ReadSysFS("/sys/class/dmi/id/board_vendor");
                string boardName    = ReadSysFS("/sys/class/dmi/id/board_name");
                string boardVersion = ReadSysFS("/sys/class/dmi/id/board_version");
                this.baseBoardInformation = new BaseBoardInformation(
                    boardVendor, boardName, boardVersion, null);

                string systemVendor   = ReadSysFS("/sys/class/dmi/id/sys_vendor");
                string productName    = ReadSysFS("/sys/class/dmi/id/product_name");
                string productVersion = ReadSysFS("/sys/class/dmi/id/product_version");
                this.systemInformation = new SystemInformation(systemVendor,
                                                               productName, productVersion, null, null);

                string biosVendor  = ReadSysFS("/sys/class/dmi/id/bios_vendor");
                string biosVersion = ReadSysFS("/sys/class/dmi/id/bios_version");
                this.biosInformation = new BIOSInformation(biosVendor, biosVersion);

                this.memoryDevices = new MemoryDevice[0];
            }
            else
            {
                List <Structure>    structureList    = new List <Structure>();
                List <MemoryDevice> memoryDeviceList = new List <MemoryDevice>();

                raw = null;
                byte majorVersion = 0;
                byte minorVersion = 0;
                try {
                    ManagementObjectCollection collection;
                    using (ManagementObjectSearcher searcher =
                               new ManagementObjectSearcher("root\\WMI",
                                                            "SELECT * FROM MSSMBios_RawSMBiosTables")) {
                        collection = searcher.Get();
                    }

                    foreach (ManagementObject mo in collection)
                    {
                        raw          = (byte[])mo["SMBiosData"];
                        majorVersion = (byte)mo["SmbiosMajorVersion"];
                        minorVersion = (byte)mo["SmbiosMinorVersion"];
                        break;
                    }
                } catch { }

                if (majorVersion > 0 || minorVersion > 0)
                {
                    version = new Version(majorVersion, minorVersion);
                }

                if (raw != null && raw.Length > 0)
                {
                    int  offset = 0;
                    byte type   = raw[offset];
                    while (offset + 4 < raw.Length && type != 127)
                    {
                        type = raw[offset];
                        int    length = raw[offset + 1];
                        ushort handle = (ushort)((raw[offset + 2] << 8) | raw[offset + 3]);

                        if (offset + length > raw.Length)
                        {
                            break;
                        }
                        byte[] data = new byte[length];
                        Array.Copy(raw, offset, data, 0, length);
                        offset += length;

                        List <string> stringsList = new List <string>();
                        if (offset < raw.Length && raw[offset] == 0)
                        {
                            offset++;
                        }

                        while (offset < raw.Length && raw[offset] != 0)
                        {
                            StringBuilder sb = new StringBuilder();
                            while (offset < raw.Length && raw[offset] != 0)
                            {
                                sb.Append((char)raw[offset]); offset++;
                            }
                            offset++;
                            stringsList.Add(sb.ToString());
                        }
                        offset++;
                        switch (type)
                        {
                        case 0x00:
                            this.biosInformation = new BIOSInformation(
                                type, handle, data, stringsList.ToArray());
                            structureList.Add(this.biosInformation); break;

                        case 0x01:
                            this.systemInformation = new SystemInformation(
                                type, handle, data, stringsList.ToArray());
                            structureList.Add(this.systemInformation); break;

                        case 0x02: this.baseBoardInformation = new BaseBoardInformation(
                                type, handle, data, stringsList.ToArray());
                            structureList.Add(this.baseBoardInformation); break;

                        case 0x04: this.processorInformation = new ProcessorInformation(
                                type, handle, data, stringsList.ToArray());
                            structureList.Add(this.processorInformation); break;

                        case 0x11: MemoryDevice m = new MemoryDevice(
                                type, handle, data, stringsList.ToArray());
                            memoryDeviceList.Add(m);
                            structureList.Add(m); break;

                        default: structureList.Add(new Structure(
                                                       type, handle, data, stringsList.ToArray())); break;
                        }
                    }
                }

                memoryDevices = memoryDeviceList.ToArray();
                table         = structureList.ToArray();
            }
        }
示例#19
0
 /// <summary>
 /// Writes a byte to the memory
 /// </summary>
 /// <param name="addr">Memory address</param>
 /// <param name="value">Data byte</param>
 public void WriteSpectrumMemory(ushort addr, byte value) =>
 MemoryDevice.Write(addr, value);
示例#20
0
        public SMBIOS()
        {
            if (OperatingSystem.IsUnix)
            {
                this.raw   = null;
                this.table = null;

                string boardVendor  = ReadSysFS("/sys/class/dmi/id/board_vendor");
                string boardName    = ReadSysFS("/sys/class/dmi/id/board_name");
                string boardVersion = ReadSysFS("/sys/class/dmi/id/board_version");
                this.baseBoardInformation = new BaseBoardInformation(
                    boardVendor, boardName, boardVersion, null);

                string systemVendor   = ReadSysFS("/sys/class/dmi/id/sys_vendor");
                string productName    = ReadSysFS("/sys/class/dmi/id/product_name");
                string productVersion = ReadSysFS("/sys/class/dmi/id/product_version");
                this.systemInformation = new SystemInformation(systemVendor,
                                                               productName, productVersion, null, null);

                string biosVendor  = ReadSysFS("/sys/class/dmi/id/bios_vendor");
                string biosVersion = ReadSysFS("/sys/class/dmi/id/bios_version");
                this.biosInformation = new BIOSInformation(biosVendor, biosVersion);

                this.memoryDevices = new MemoryDevice[0];
            }
            else
            {
                List <Structure>    structureList    = new List <Structure>();
                List <MemoryDevice> memoryDeviceList = new List <MemoryDevice>();

                raw = null;
                byte majorVersion = 0;
                byte minorVersion = 0;
                try {
                    // Get bios raw information
                    ManagementObjectCollection collection;
                    using (ManagementObjectSearcher searcher =
                               new ManagementObjectSearcher("root\\WMI",
                                                            "SELECT * FROM MSSMBios_RawSMBiosTables")) {
                        collection = searcher.Get();
                    }

                    foreach (ManagementObject mo in collection)
                    {
                        raw          = (byte[])mo["SMBiosData"];
                        majorVersion = (byte)mo["SmbiosMajorVersion"];
                        minorVersion = (byte)mo["SmbiosMinorVersion"];
                        break;
                    }
                } catch { }

                if (majorVersion > 0 || minorVersion > 0)
                {
                    version = new Version(majorVersion, minorVersion);
                }

                if (raw != null && raw.Length > 0)
                {
                    int  offset = 0;
                    byte type   = raw[offset];
                    while (offset + 4 < raw.Length && type != 127)
                    {
                        // each iteration finds the structure inforamtion which are seperated by two zero bytes

                        // first byte in structure is the type of information
                        type = raw[offset];
                        // second byte in structure is the length of the structure header
                        int    length = raw[offset + 1];
                        ushort handle = (ushort)((raw[offset + 2] << 8) | raw[offset + 3]);

                        if (offset + length > raw.Length)
                        {
                            break;
                        }
                        // data is the structure header not the actual values
                        byte[] data = new byte[length];
                        Array.Copy(raw, offset, data, 0, length);
                        // moves offset to the start of the structure values
                        offset += length;

                        // moves over all the zeros after the structure header
                        List <string> stringsList = new List <string>();
                        if (offset < raw.Length && raw[offset] == 0)
                        {
                            offset++;
                        }

                        // Convert bytes to strings seperated by one zero byte, puts them in 'stringsList'
                        // Structure ends at two successive zero bytes
                        while (offset < raw.Length && raw[offset] != 0)
                        {
                            StringBuilder sb = new StringBuilder();
                            while (offset < raw.Length && raw[offset] != 0)
                            {
                                sb.Append((char)raw[offset]); offset++;
                            }
                            offset++;
                            stringsList.Add(sb.ToString());
                        }
                        offset++;
                        switch (type)
                        {
                        case 0x00:
                            this.biosInformation = new BIOSInformation(
                                type, handle, data, stringsList.ToArray());
                            structureList.Add(this.biosInformation); break;

                        case 0x01:
                            this.systemInformation = new SystemInformation(
                                type, handle, data, stringsList.ToArray());
                            structureList.Add(this.systemInformation); break;

                        case 0x02: this.baseBoardInformation = new BaseBoardInformation(
                                type, handle, data, stringsList.ToArray());
                            structureList.Add(this.baseBoardInformation); break;

                        case 0x04: this.processorInformation = new ProcessorInformation(
                                type, handle, data, stringsList.ToArray());
                            structureList.Add(this.processorInformation); break;

                        case 0x07: //CPU Internal
                            //LCachenum = (data[5] ^ 0x80) + 1 //LCacheNum = data[16] - 3 //LCacheNum = (data[16] ^ 0x04) + 1
                            //LCacheSize = data[8] << 8 //LCacheSize = data[10] << 8
                            //LCacheAssociativity = 0
                            //switch (data[18]) {
                            //case 5: LCacheAssociativity = 4; break;
                            //case 7: LCacheAssociativity = 8; break;
                            //case 9: LCacheAssociativity = 12; break;
                            //}
                            break;

                        case 0x11: MemoryDevice m = new MemoryDevice(
                                type, handle, data, stringsList.ToArray());
                            memoryDeviceList.Add(m);
                            structureList.Add(m); break;

                        default: structureList.Add(new Structure(
                                                       type, handle, data, stringsList.ToArray())); break;
                            // type 8 = peripherals
                        }
                    }
                }

                memoryDevices = memoryDeviceList.ToArray();
                table         = structureList.ToArray();
            }
        }
示例#21
0
 public BWArgs(Modes mode, MemoryDevice dev, string port)
 {
     Mode   = mode;
     Device = dev;
     Port   = port;
 }
示例#22
0
文件: SMBIOS.cs 项目: reimashi/jotai
        public SMBIOS()
        {
            int p = (int)Environment.OSVersion.Platform;
            if ((p == 4) || (p == 128))
            {
                this.raw = null;
                this.table = null;

                string boardVendor = ReadSysFS("/sys/class/dmi/id/board_vendor");
                string boardName = ReadSysFS("/sys/class/dmi/id/board_name");
                string boardVersion = ReadSysFS("/sys/class/dmi/id/board_version");
                this.baseBoardInformation = new BaseBoardInformation(
                  boardVendor, boardName, boardVersion, null);

                string systemVendor = ReadSysFS("/sys/class/dmi/id/sys_vendor");
                string productName = ReadSysFS("/sys/class/dmi/id/product_name");
                string productVersion = ReadSysFS("/sys/class/dmi/id/product_version");
                this.systemInformation = new SystemInformation(systemVendor,
                  productName, productVersion, null, null);

                string biosVendor = ReadSysFS("/sys/class/dmi/id/bios_vendor");
                string biosVersion = ReadSysFS("/sys/class/dmi/id/bios_version");
                this.biosInformation = new BIOSInformation(biosVendor, biosVersion);

                this.memoryDevices = new MemoryDevice[0];
            }
            else
            {
                List<Structure> structureList = new List<Structure>();
                List<MemoryDevice> memoryDeviceList = new List<MemoryDevice>();

                raw = null;
                byte majorVersion = 0;
                byte minorVersion = 0;
                try
                {
                    ManagementObjectCollection collection;
                    using (ManagementObjectSearcher searcher =
                      new ManagementObjectSearcher("root\\WMI",
                        "SELECT * FROM MSSMBios_RawSMBiosTables"))
                    {
                        collection = searcher.Get();
                    }

                    foreach (ManagementObject mo in collection)
                    {
                        raw = (byte[])mo["SMBiosData"];
                        majorVersion = (byte)mo["SmbiosMajorVersion"];
                        minorVersion = (byte)mo["SmbiosMinorVersion"];
                        break;
                    }
                }
                catch { }

                if (majorVersion > 0 || minorVersion > 0)
                    version = new Version(majorVersion, minorVersion);

                if (raw != null && raw.Length > 0)
                {
                    int offset = 0;
                    byte type = raw[offset];
                    while (offset + 4 < raw.Length && type != 127)
                    {

                        type = raw[offset];
                        int length = raw[offset + 1];
                        ushort handle = (ushort)((raw[offset + 2] << 8) | raw[offset + 3]);

                        if (offset + length > raw.Length)
                            break;
                        byte[] data = new byte[length];
                        Array.Copy(raw, offset, data, 0, length);
                        offset += length;

                        List<string> stringsList = new List<string>();
                        if (offset < raw.Length && raw[offset] == 0)
                            offset++;

                        while (offset < raw.Length && raw[offset] != 0)
                        {
                            StringBuilder sb = new StringBuilder();
                            while (offset < raw.Length && raw[offset] != 0)
                            {
                                sb.Append((char)raw[offset]); offset++;
                            }
                            offset++;
                            stringsList.Add(sb.ToString());
                        }
                        offset++;
                        switch (type)
                        {
                            case 0x00:
                                this.biosInformation = new BIOSInformation(
                                  type, handle, data, stringsList.ToArray());
                                structureList.Add(this.biosInformation); break;
                            case 0x01:
                                this.systemInformation = new SystemInformation(
                                  type, handle, data, stringsList.ToArray());
                                structureList.Add(this.systemInformation); break;
                            case 0x02:
                                this.baseBoardInformation = new BaseBoardInformation(
                         type, handle, data, stringsList.ToArray());
                                structureList.Add(this.baseBoardInformation); break;
                            case 0x04:
                                this.processorInformation = new ProcessorInformation(
                         type, handle, data, stringsList.ToArray());
                                structureList.Add(this.processorInformation); break;
                            case 0x11:
                                MemoryDevice m = new MemoryDevice(
                         type, handle, data, stringsList.ToArray());
                                memoryDeviceList.Add(m);
                                structureList.Add(m); break;
                            default:
                                structureList.Add(new Structure(
                         type, handle, data, stringsList.ToArray())); break;
                        }
                    }
                }

                memoryDevices = memoryDeviceList.ToArray();
                table = structureList.ToArray();
            }
        }
示例#23
0
        /// <summary>
        /// Sends a byte to the port with the specified address
        /// </summary>
        /// <param name="addr">Port address</param>
        /// <param name="data">Data to write to the port</param>
        /// <returns>Byte read from the memory</returns>
        public override void WritePort(ushort addr, byte data)
        {
            HandleSpectrum48PortWrites(addr, data);

            // --- Port 0x7FFD, bit 14 set, bit 15 and bit 1 reset
            if ((addr & 0xC002) == 0x4000)
            {
                // --- When paging is disabled, it will be enabled next time
                // --- only after reset
                if (PagingEnabled)
                {
                    // --- Choose the RAM bank for Slot 3 (0xc000-0xffff)
                    LastSlot3Index = data & 0x07;
                    MemoryDevice.PageIn(3, LastSlot3Index);

                    // --- Choose screen (Bank 5 or 7)
                    MemoryDevice.UseShadowScreen = ((data >> 3) & 0x01) == 0x01;

                    // --- Choose ROM bank for Slot 0 (0x0000-0x3fff)
                    SelectRomLow = (byte)((data >> 4) & 0x01);

                    // --- Enable/disable paging
                    PagingEnabled = (data & 0x20) == 0x00;

                    // --- Page the ROM according to current settings
                    MemoryDevice.SelectRom(SelectRomHigh | SelectRomLow);
                }
            }
            // --- Port 0x1FFD, bit 12 set, bit 1, 13, 14 and 15 reset
            else if ((addr & 0xF002) == 0x1000)
            {
                PagingMode        = (data & 0x01) != 0;
                SpecialConfig     = (byte)((data >> 1) & 0x03);
                DiskMotorState    = (data & 0x08) != 0;
                PrinterPortStrobe = (data & 0x10) != 0;
                SelectRomHigh     = (byte)((data >> 1) & 0x02);

                // --- Page the ROM according to current settings
                if (PagingMode)
                {
                    // --- Special paging mode
                    switch (SpecialConfig)
                    {
                    case 0:
                        MemoryDevice.PageIn(0, 0);
                        MemoryDevice.PageIn(1, 1);
                        MemoryDevice.PageIn(2, 2);
                        MemoryDevice.PageIn(3, 3);
                        break;

                    case 1:
                        MemoryDevice.PageIn(0, 4);
                        MemoryDevice.PageIn(1, 5);
                        MemoryDevice.PageIn(2, 6);
                        MemoryDevice.PageIn(3, 7);
                        break;

                    case 2:
                        MemoryDevice.PageIn(0, 4);
                        MemoryDevice.PageIn(1, 5);
                        MemoryDevice.PageIn(2, 6);
                        MemoryDevice.PageIn(3, 3);
                        break;

                    case 3:
                        MemoryDevice.PageIn(0, 4);
                        MemoryDevice.PageIn(1, 7);
                        MemoryDevice.PageIn(2, 6);
                        MemoryDevice.PageIn(3, 3);
                        break;
                    }
                }
                else
                {
                    // --- Normal mode
                    MemoryDevice.PageIn(1, 5);
                    MemoryDevice.PageIn(2, 2);
                    MemoryDevice.PageIn(3, LastSlot3Index);
                    MemoryDevice.SelectRom(SelectRomHigh | SelectRomLow);
                }
            }
            else if (addr == 0xFFFD)
            {
                SoundDevice.SetRegisterIndex(data);
            }
            else if (addr == 0xBFFD || addr == 0xBEFD)
            {
                SoundDevice.SetRegisterValue(data);
            }
        }
示例#24
0
        public Smbios()
        {
            if (OperatingSystem.IsLinux)
            {
                raw   = null;
                table = null;

                var boardVendor  = ReadSysFS("/sys/class/dmi/id/board_vendor");
                var boardName    = ReadSysFS("/sys/class/dmi/id/board_name");
                var boardVersion = ReadSysFS("/sys/class/dmi/id/board_version");
                Board = new BaseBoardInformation(
                    boardVendor, boardName, boardVersion, null);

                var systemVendor   = ReadSysFS("/sys/class/dmi/id/sys_vendor");
                var productName    = ReadSysFS("/sys/class/dmi/id/product_name");
                var productVersion = ReadSysFS("/sys/class/dmi/id/product_version");
                System = new SystemInformation(systemVendor,
                                               productName, productVersion, null, null);

                var biosVendor  = ReadSysFS("/sys/class/dmi/id/bios_vendor");
                var biosVersion = ReadSysFS("/sys/class/dmi/id/bios_version");
                BIOS = new BIOSInformation(biosVendor, biosVersion);

                MemoryDevices = new MemoryDevice[0];
            }
            else
            {
                var structureList    = new List <Structure>();
                var memoryDeviceList = new List <MemoryDevice>();

                raw = null;
                byte majorVersion = 0;
                byte minorVersion = 0;
                try
                {
                    ManagementObjectCollection collection;
                    using (var searcher =
                               new ManagementObjectSearcher("root\\WMI",
                                                            "SELECT * FROM MSSMBios_RawSMBiosTables"))
                    {
                        collection = searcher.Get();
                    }

                    foreach (ManagementObject mo in collection)
                    {
                        raw          = (byte[])mo["SMBiosData"];
                        majorVersion = (byte)mo["SmbiosMajorVersion"];
                        minorVersion = (byte)mo["SmbiosMinorVersion"];
                        break;
                    }
                }
                catch
                {
                }

                if (majorVersion > 0 || minorVersion > 0)
                {
                    version = new Version(majorVersion, minorVersion);
                }

                if (raw != null && raw.Length > 0)
                {
                    var offset = 0;
                    var type   = raw[offset];
                    while (offset + 4 < raw.Length && type != 127)
                    {
                        type = raw[offset];
                        int length = raw[offset + 1];
                        var handle = (ushort)((raw[offset + 2] << 8) | raw[offset + 3]);

                        if (offset + length > raw.Length)
                        {
                            break;
                        }
                        var data = new byte[length];
                        Array.Copy(raw, offset, data, 0, length);
                        offset += length;

                        var stringsList = new List <string>();
                        if (offset < raw.Length && raw[offset] == 0)
                        {
                            offset++;
                        }

                        while (offset < raw.Length && raw[offset] != 0)
                        {
                            var sb = new StringBuilder();
                            while (offset < raw.Length && raw[offset] != 0)
                            {
                                sb.Append((char)raw[offset]);
                                offset++;
                            }

                            offset++;
                            stringsList.Add(sb.ToString());
                        }

                        offset++;
                        switch (type)
                        {
                        case 0x00:
                            BIOS = new BIOSInformation(
                                type, handle, data, stringsList.ToArray());
                            structureList.Add(BIOS);
                            break;

                        case 0x01:
                            System = new SystemInformation(
                                type, handle, data, stringsList.ToArray());
                            structureList.Add(System);
                            break;

                        case 0x02:
                            Board = new BaseBoardInformation(
                                type, handle, data, stringsList.ToArray());
                            structureList.Add(Board);
                            break;

                        case 0x04:
                            Processor = new ProcessorInformation(
                                type, handle, data, stringsList.ToArray());
                            structureList.Add(Processor);
                            break;

                        case 0x11:
                            var m = new MemoryDevice(
                                type, handle, data, stringsList.ToArray());
                            memoryDeviceList.Add(m);
                            structureList.Add(m);
                            break;

                        default:
                            structureList.Add(new Structure(
                                                  type, handle, data, stringsList.ToArray()));
                            break;
                        }
                    }
                }

                MemoryDevices = memoryDeviceList.ToArray();
                table         = structureList.ToArray();
            }
        }