예제 #1
0
        static unsafe void TestManagedMemoryBlock(ManagedMemoryBlock memoryBlock)
        {
            memoryBlock.Write32(0, 1);
            Assert.AreEqual(1, memoryBlock[0], "ManagedMemoryBlock write int at index 0 works");
            Assert.AreEqual(1, memoryBlock.Read32(0), "ManagedMemoryBlock read/write at index 0 works");
            memoryBlock.Write32(1, 101);
            Assert.AreEqual(101, memoryBlock[1], "ManagedMemoryBlock read/write at index 1 works");
            Assert.AreEqual(25857, memoryBlock.Read32(0), "ManagedMemoryBlock read int at index 0 works");
            memoryBlock.Write32(2, 2 ^ 16 + 2);
            Assert.AreEqual(16, memoryBlock[2], "ManagedMemoryBlock write int at index 2 works");
            Assert.AreEqual(0, memoryBlock[3], "ManagedMemoryBlock write int at index 2 works");
            Assert.AreEqual(1074433, memoryBlock.Read32(0), "ManagedMemoryBlock read int at index 0 works");
            memoryBlock.Write32(3, int.MaxValue);
            Assert.AreEqual(255, memoryBlock[3], "ManagedMemoryBlock write int at index 3 works");
            Assert.AreEqual(0xFF106501, memoryBlock.Read32(0), "ManagedMemoryBlock read int at index 0 works");
            Assert.AreEqual(0xFFFF1065, memoryBlock.Read32(1), "ManagedMemoryBlock read int at index 1 works");
            Assert.AreEqual(0xFFFFFF10, memoryBlock.Read32(2), "ManagedMemoryBlock read int at index 2 works");
            Assert.AreEqual(int.MaxValue, memoryBlock.Read32(3), "ManagedMemoryBlock read/write at index 3 works");

            memoryBlock.Fill(101);
            Assert.AreEqual(101, memoryBlock.Read32(0), "ManagedMemoryBlock fill works at index 0");
            Assert.AreEqual(0, memoryBlock[1], "ManagedMemoryBlock fill fills entire ints");
            Assert.AreEqual(6619136, memoryBlock.Read32(10), "ManagedMemoryBlock fill works at index 10");

            memoryBlock.Write8(0, 101);
            Assert.AreEqual(101, memoryBlock[0], "ManagedMemoryBlock write byte works at index 0");
            memoryBlock.Fill(1, 1, 987893745);
            Assert.AreEqual(101, memoryBlock[0], "ManagedMemoryBlock Fill(1, int, int) skips index 0");
            Assert.AreEqual(987893745, memoryBlock.Read32(1), "ManagedMemoryBlock Fill(int, int, int) works at index 1");
        }
예제 #2
0
        /// <summary>
        /// Create new instance of the <see cref="VBEDriver"/> class.
        /// </summary>
        /// <param name="xres">X resolution.</param>
        /// <param name="yres">Y resolution.</param>
        /// <param name="bpp">BPP (color depth).</param>
        public VBEDriver(ushort xres, ushort yres, ushort bpp)
        {
            PCIDevice videocard;

            if (VBE.IsAvailable()) //VBE VESA Enabled Mulitboot Parsing
            {
                Global.mDebugger.SendInternal($"Creating VBE VESA driver with Mode {xres}*{yres}@{bpp}");
                IO.LinearFrameBuffer = new MemoryBlock(VBE.getLfbOffset(), (uint)xres * yres * (uint)(bpp / 8));
                lastbuffer           = new ManagedMemoryBlock((uint)xres * yres * (uint)(bpp / 8));
            }
            else if (ISAModeAvailable()) //Bochs Graphics Adaptor ISA Mode
            {
                Global.mDebugger.SendInternal($"Creating VBE BGA driver with Mode {xres}*{yres}@{bpp}.");

                IO.LinearFrameBuffer = new MemoryBlock(0xE0000000, 1920 * 1200 * 4);
                lastbuffer           = new ManagedMemoryBlock(1920 * 1200 * 4);
                VBESet(xres, yres, bpp);
            }
            else if (((videocard = HAL.PCI.GetDevice(VendorID.VirtualBox, DeviceID.VBVGA)) != null) || //VirtualBox Video Adapter PCI Mode
                     ((videocard = HAL.PCI.GetDevice(VendorID.Bochs, DeviceID.BGA)) != null))          // Bochs Graphics Adaptor PCI Mode
            {
                Global.mDebugger.SendInternal($"Creating VBE BGA driver with Mode {xres}*{yres}@{bpp}. Framebuffer address=" + videocard.BAR0);

                IO.LinearFrameBuffer = new MemoryBlock(videocard.BAR0, 1920 * 1200 * 4);
                lastbuffer           = new ManagedMemoryBlock(1920 * 1200 * 4);
                VBESet(xres, yres, bpp);
            }
            else
            {
                throw new Exception("No supported VBE device found.");
            }
        }
예제 #3
0
파일: RTL8139.cs 프로젝트: nifanfa/Cosmos
        protected bool SendBytes(ref byte[] aData)
        {
            int txd = mNextTXDesc++;

            if (mNextTXDesc >= 4)
            {
                mNextTXDesc = 0;
            }
            ManagedMemoryBlock txBuffer;

            if (aData.Length < 64)
            {
                txBuffer = new ManagedMemoryBlock(64);
                for (uint b = 0; b < aData.Length; b++)
                {
                    txBuffer[b] = aData[b];
                }
            }
            else
            {
                txBuffer = new ManagedMemoryBlock((uint)aData.Length);
                for (uint i = 0; i < aData.Length; i++)
                {
                    txBuffer[i] = aData[i];
                }
            }
            switch (txd)
            {
            case 0:
                TransmitAddress1Register    = txBuffer.Offset;
                TransmitDescriptor1Register = txBuffer.Size;
                break;

            case 1:
                TransmitAddress2Register    = txBuffer.Offset;
                TransmitDescriptor2Register = txBuffer.Size;
                break;

            case 2:
                TransmitAddress3Register    = txBuffer.Offset;
                TransmitDescriptor3Register = txBuffer.Size;
                break;

            case 3:
                TransmitAddress4Register    = txBuffer.Offset;
                TransmitDescriptor4Register = txBuffer.Size;
                break;

            default:
                return(false);
            }
            return(true);
        }
예제 #4
0
        public void AllocateMemoryBuffer(int bufferSize, uint bufferId)
        {
            if (!isIntialised) return;

            lock (lockObject)
            {
                var block = new ManagedMemoryBlock();
                block.ProfilerHasResults = new EventWaitHandle(false, EventResetMode.ManualReset, MakeName(@"\OpenCover_Profiler_Communication_SendResults_Event_", bufferId));
                block.ResultsHaveBeenReceived = new EventWaitHandle(false, EventResetMode.ManualReset, MakeName(@"\OpenCover_Profiler_Communication_ReceiveResults_Event_", bufferId));
                block.MMFResults = MemoryMappedFile.CreateNew(MakeName(@"\OpenCover_Profiler_Results_MemoryMapFile_", bufferId), bufferSize);
                block.StreamAccessorResults = block.MMFResults.CreateViewStream(0, bufferSize, MemoryMappedFileAccess.ReadWrite);
                block.StreamAccessorResults.Write(BitConverter.GetBytes(0), 0, 4);
                block.BufferSize = bufferSize;

                _blocks.Add(block);
            }
        }
예제 #5
0
파일: RTL8168.cs 프로젝트: KM198912/AirOS
        void InitBuffers()
        {
            mNextTXDesc = 0;

            mRxDescriptor = new ManagedMemoryBlock(32 * 16);
            mTxDescriptor = new ManagedMemoryBlock(32 * 16);

            mRxBuffers = new List <ManagedMemoryBlock>();
            mTxBuffers = new List <ManagedMemoryBlock>();

            mTransmitBuffer = new Queue <byte[]>();
            mRecvBuffer     = new Queue <byte[]>();

            for (int i = 0; i < 32; i++)
            {
                uint xOffset = (uint)i * 16;
                ManagedMemoryBlock rxbuffer = new ManagedMemoryBlock(2048, 8);
                ManagedMemoryBlock txbuffer = new ManagedMemoryBlock(2048, 8);
                if (i == (32 - 1))
                {
                    mRxDescriptor.Write32(xOffset + 0, OWN | EOR | (2048 & 0x3FFF));
                    mTxDescriptor.Write32(xOffset + 0, EOR);
                }
                else
                {
                    mRxDescriptor.Write32(xOffset + 0, OWN | EOR | (2048 & 0x3FFF));
                    mTxDescriptor.Write32(xOffset + 0, 0);
                }

                mRxBuffers.Add(rxbuffer);
                mTxBuffers.Add(txbuffer);

                mRxDescriptor.Write32(xOffset + 4, 0);
                mTxDescriptor.Write32(xOffset + 4, 0);

                mRxDescriptor.Write32(xOffset + 8, rxbuffer.Offset);
                mTxDescriptor.Write32(xOffset + 8, txbuffer.Offset);

                mRxDescriptor.Write32(xOffset + 12, 0);
                mTxDescriptor.Write32(xOffset + 12, 0);
            }
        }
예제 #6
0
파일: RTL8139.cs 프로젝트: nifanfa/Cosmos
 public RTL8139(PCIDevice device)
 {
     if (device == null)
     {
         throw new ArgumentException("PCI Device is null. Unable to get Realtek 8139 card");
     }
     pciCard = device;
     Base    = device.BaseAddressBar[0].BaseAddress;
     // We are handling this device
     pciCard.Claimed = true;
     // Setup interrupt handling
     INTs.SetIrqHandler(device.InterruptLine, HandleNetworkInterrupt);
     // Get IO Address from PCI Bus
     // Enable the card
     pciCard.EnableDevice();
     // Turn on the card
     OutB(Base + 0x52, 0x01);
     //Do a software reset
     SoftwareReset();
     // Get the MAC Address
     byte[] eeprom_mac = new byte[6];
     for (uint b = 0; b < 6; b++)
     {
         eeprom_mac[b] = Inb(Base + b);
     }
     this.mac = new MACAddress(eeprom_mac);
     // Get a receive buffer and assign it to the card
     rxBuffer        = new ManagedMemoryBlock(RxBufferSize + 2048 + 16, 4);
     RBStartRegister = rxBuffer.Offset;
     // Setup receive Configuration
     RecvConfigRegister = 0xF381;
     // Setup Transmit Configuration
     TransmitConfigRegister = 0x3000300;
     // Setup Interrupts
     IntMaskRegister   = 0x7F;
     IntStatusRegister = 0xFFFF;
     // Setup our Receive and Transmit Queues
     mRecvBuffer     = new Queue <byte[]>();
     mTransmitBuffer = new Queue <byte[]>();
 }
예제 #7
0
        public AMDPCNetII(PCIDeviceNormal device)
            : base()
        {
            if (device == null)
            {
                throw new ArgumentException("PCI Device is null. Unable to get AMD PCNet card");
            }

            this.pciCard = device;
            // this.pciCard.Claimed = true;
            //this.pciCard.EnableDevice();

            //this.io = new AMDPCNetIIIOGroup((ushort) this.pciCard.BaseAddresses[0].BaseAddress());
            this.io.RegisterData.DWord = 0;

            // Get the EEPROM MAC Address and set it as the devices MAC
            byte[] eeprom_mac = new byte[6];
            UInt32 result     = io.MAC1.DWord;

            eeprom_mac[0] = BinaryHelper.GetByteFrom32bit(result, 0);
            eeprom_mac[1] = BinaryHelper.GetByteFrom32bit(result, 8);
            eeprom_mac[2] = BinaryHelper.GetByteFrom32bit(result, 16);
            eeprom_mac[3] = BinaryHelper.GetByteFrom32bit(result, 24);
            result        = io.MAC2.DWord;
            eeprom_mac[4] = BinaryHelper.GetByteFrom32bit(result, 0);
            eeprom_mac[5] = BinaryHelper.GetByteFrom32bit(result, 8);

            mac = new MACAddress(eeprom_mac);

            mInitBlock    = new ManagedMemoryBlock(28, 4);
            mRxDescriptor = new ManagedMemoryBlock(256, 16);
            mTxDescriptor = new ManagedMemoryBlock(256, 16);

            mInitBlock.Write32(0x00, (0x4 << 28) | (0x4 << 20));
            mInitBlock.Write32(0x04,
                               (UInt32)(eeprom_mac[0] | (eeprom_mac[1] << 8) | (eeprom_mac[2] << 16) | (eeprom_mac[3] << 24)));
            mInitBlock.Write32(0x08, (UInt32)(eeprom_mac[4] | (eeprom_mac[5] << 8)));
            mInitBlock.Write32(0x0C, 0x0);
            mInitBlock.Write32(0x10, 0x0);
            mInitBlock.Write32(0x14, mRxDescriptor.Offset);
            mInitBlock.Write32(0x18, mTxDescriptor.Offset);

            InitializationBlockAddress = mInitBlock.Offset;
            SoftwareStyleRegister      = 0x03;

            mRxBuffers = new List <ManagedMemoryBlock>();
            mTxBuffers = new List <ManagedMemoryBlock>();
            for (uint rxd = 0; rxd < 16; rxd++)
            {
                uint xOffset = rxd * 16;

                ManagedMemoryBlock buffer = new ManagedMemoryBlock(2048);
                mRxDescriptor.Write32(xOffset + 8, buffer.Offset);
                UInt16 buffer_len = (UInt16)(~buffer.Size);
                buffer_len++;
                UInt32 flags = (UInt32)(buffer_len & 0x0FFF) | 0xF000 | 0x80000000;
                mRxDescriptor.Write32(xOffset + 4, flags);
                mRxBuffers.Add(buffer);
            }
            for (uint txd = 0; txd < 16; txd++)
            {
                uint xOffset = txd * 16;

                ManagedMemoryBlock buffer = new ManagedMemoryBlock(2048);
                mTxDescriptor.Write32(xOffset + 8, buffer.Offset);
                mTxBuffers.Add(buffer);
            }

            mNextTXDesc = 0;

            // Setup our Receive and Transmit Queues
            mTransmitBuffer = new Queue <byte[]>();
            mRecvBuffer     = new Queue <byte[]>();

            //INTs.SetIrqHandler(device.InterruptLine, HandleNetworkInterrupt);
        }
        /// <summary>
        /// Constructs a new demo.
        /// </summary>
        /// <param name="game">Game owning this demo.</param>
        public RobotArmDemo(DemosGame game)
            : base(game)
        {
            //Since this is not a "StandardDemo" derived class, we need to set our own gravity.
            Space.ForceUpdater.Gravity = new Vector3(0, -9.81f, 0);
            Entity ground = new Box(Vector3.Zero, 30, 1, 30);

            Space.Add(ground);

            var armBase = new Cylinder(new Vector3(0, 2, 0), 2.5f, 1, 40);

            Space.Add(armBase);

            //The arm base can rotate around the Y axis.
            //Rotation is controlled by user input.
            groundToBaseJoint = new RevoluteJoint(ground, armBase, Vector3.Zero, Vector3.Up);
            groundToBaseJoint.Motor.IsActive              = true;
            groundToBaseJoint.Motor.Settings.Mode         = MotorMode.VelocityMotor;
            groundToBaseJoint.Motor.Settings.MaximumForce = 3500;
            Space.Add(groundToBaseJoint);

            lowerArm = new Box(armBase.Position + new Vector3(0, 2, 0), 1, 3, .5f, 10);
            Space.Add(lowerArm);

            shoulder = new RevoluteJoint(armBase, lowerArm, armBase.Position, Vector3.Forward);
            shoulder.Motor.IsActive              = true;
            shoulder.Motor.Settings.Mode         = MotorMode.VelocityMotor;
            shoulder.Motor.Settings.MaximumForce = 2500;

            //Don't want it to rotate too far; this keeps the whole contraption off the ground.
            shoulder.Limit.IsActive     = true;
            shoulder.Limit.MinimumAngle = 0;
            shoulder.Limit.MaximumAngle = MathHelper.PiOver4;
            Space.Add(shoulder);

            //Make the next piece of the arm.
            upperArm = new Cylinder(lowerArm.Position + new Vector3(0, 3, 0), 3, .25f, 10);
            Space.Add(upperArm);

            //Swivel hinges allow motion around two axes.  Imagine a tablet PC's monitor hinge.
            elbow = new SwivelHingeJoint(lowerArm, upperArm, lowerArm.Position + new Vector3(0, 1.5f, 0), Vector3.Forward);
            elbow.TwistMotor.IsActive              = true;
            elbow.TwistMotor.Settings.Mode         = MotorMode.VelocityMotor;
            elbow.TwistMotor.Settings.MaximumForce = 1000;

            elbow.HingeMotor.IsActive              = true;
            elbow.HingeMotor.Settings.Mode         = MotorMode.VelocityMotor;
            elbow.HingeMotor.Settings.MaximumForce = 1250;

            //Keep it from rotating too much.
            elbow.HingeLimit.IsActive     = true;
            elbow.HingeLimit.MinimumAngle = 0;
            elbow.HingeLimit.MaximumAngle = MathHelper.PiOver2;
            Space.Add(elbow);


            //Add a menacing claw at the end.
            var lowerPosition = upperArm.Position + new Vector3(-.65f, 1.6f, 0);

            CollisionRules clawPart1ARules = new CollisionRules();
            var            bodies          = new List <CompoundChildData>()
            {
                new CompoundChildData()
                {
                    Entry = new CompoundShapeEntry(new BoxShape(1, .25f, .25f), lowerPosition, 3), CollisionRules = clawPart1ARules
                },
                new CompoundChildData()
                {
                    Entry = new CompoundShapeEntry(new ConeShape(1, .125f), lowerPosition + new Vector3(-.375f, .4f, 0), 3), Material = new Material(2, 2, 0)
                }
            };

            leftClaw = new CompoundBody(bodies, 6);
            Space.Add(leftClaw);

            clawHingeA = new RevoluteJoint(upperArm, leftClaw, upperArm.Position + new Vector3(0, 1.5f, 0), Vector3.Forward);
            clawHingeA.Motor.IsActive            = true;
            clawHingeA.Motor.Settings.Mode       = MotorMode.VelocityMotor;
            clawHingeA.Motor.Settings.Servo.Goal = -MathHelper.PiOver2;
            //Weaken the claw to prevent it from crushing the boxes.
            clawHingeA.Motor.Settings.Servo.SpringSettings.Damping   /= 100;
            clawHingeA.Motor.Settings.Servo.SpringSettings.Stiffness /= 100;

            clawHingeA.Limit.IsActive     = true;
            clawHingeA.Limit.MinimumAngle = -MathHelper.PiOver2;
            clawHingeA.Limit.MaximumAngle = -MathHelper.Pi / 6;
            Space.Add(clawHingeA);

            //Add one more claw to complete the contraption.
            lowerPosition = upperArm.Position + new Vector3(.65f, 1.6f, 0);

            CollisionRules clawPart1BRules = new CollisionRules();

            bodies = new List <CompoundChildData>()
            {
                new CompoundChildData()
                {
                    Entry = new CompoundShapeEntry(new BoxShape(1, .25f, .25f), lowerPosition, 3), CollisionRules = clawPart1BRules
                },
                new CompoundChildData()
                {
                    Entry = new CompoundShapeEntry(new ConeShape(1, .125f), lowerPosition + new Vector3(.375f, .4f, 0), 3), Material = new Material(2, 2, 0)
                }
            };

            rightClaw = new CompoundBody(bodies, 6);
            Space.Add(rightClaw);

            clawHingeB = new RevoluteJoint(upperArm, rightClaw, upperArm.Position + new Vector3(0, 1.5f, 0), Vector3.Forward);
            clawHingeB.Motor.IsActive            = true;
            clawHingeB.Motor.Settings.Mode       = MotorMode.VelocityMotor;
            clawHingeB.Motor.Settings.Servo.Goal = MathHelper.PiOver2;
            //Weaken the claw to prevent it from crushing the boxes.
            clawHingeB.Motor.Settings.Servo.SpringSettings.Damping   /= 100;
            clawHingeB.Motor.Settings.Servo.SpringSettings.Stiffness /= 100;

            clawHingeB.Limit.IsActive     = true;
            clawHingeB.Limit.MinimumAngle = MathHelper.Pi / 6;
            clawHingeB.Limit.MaximumAngle = MathHelper.PiOver2;
            Space.Add(clawHingeB);

            //Keep the pieces of the robot from interacting with each other.
            //The CollisionRules.AddRule method is just a convenience method that adds items to the 'specific' dictionary.
            //Sometimes, it's a little unwieldy to reference the collision rules,
            //so the convenience method just takes the owners and hides the ugly syntax.
            CollisionRules.AddRule(armBase, lowerArm, CollisionRule.NoBroadPhase);
            CollisionRules.AddRule(lowerArm, upperArm, CollisionRule.NoBroadPhase);
            CollisionRules.AddRule(clawPart1ARules, upperArm, CollisionRule.NoBroadPhase);
            CollisionRules.AddRule(clawPart1BRules, upperArm, CollisionRule.NoBroadPhase);
            //Here's an example without a convenience method.  Since they are both direct CollisionRules references, it's pretty clean.
            clawPart1BRules.Specific.Add(clawPart1ARules, CollisionRule.NoBroadPhase);


            //Put some boxes on the ground to try to pick up.
            for (double k = 0; k < Math.PI * 2; k += Math.PI / 6)
            {
                //Space.Add(new Box(new Vector3((float)Math.Cos(k) * 5.5f, 2, (float)Math.Sin(k) * 5.5f), 1, 1, 1, 10));
            }

            game.Camera.Position = new Vector3(0, 5, 13);



            logisticFunction = new ManagedLogisticFunction();
            input            = new ManagedMemoryBlock(9);
            target           = new ManagedMemoryBlock(3);

            network           = new ManagedSimpleRecurrentNetwork(9, 256, 3, logisticFunction);
            learningAlgorithm = new ManagedTBPTT(network, 0.005f, 0.9f, 4);
        }
예제 #9
0
 public Graphics(int width, int height)
 {
     this.width  = width;
     this.height = height;
     memory      = new ManagedMemoryBlock((uint)(width * height * depth));
 }