Ejemplo n.º 1
0
        public override void Probe()
        {
            LBALowPort.Write8(0x88);

            var found = LBALowPort.Read8() == 0x88;

            Device.Status = (found) ? DeviceStatus.Available : DeviceStatus.NotFound;
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Sets the palette.
 /// </summary>
 /// <param name="colorIndex">Index of the color.</param>
 /// <param name="color">The color.</param>
 public void SetPalette(byte colorIndex, Color color)
 {
     dacPaletteMask.Write8(0xFF);
     dacIndexWrite.Write8(colorIndex);
     dacData.Write8(color.Red);
     dacData.Write8(color.Green);
     dacData.Write8(color.Blue);
 }
Ejemplo n.º 3
0
        public override void Initialize()
        {
            Device.Name = "StandardMouse";

            data    = Device.Resources.GetIOPortReadWrite(0, 0);          // 0x60
            command = Device.Resources.GetIOPortReadWrite(1, 0);          // 0x64

            // Enable the auxiliary mouse device
            Wait(1);
            command.Write8(0xA8);

            // Enable the interrupts
            Wait(1);
            command.Write8(0x20);
            Wait(0);
            byte status = ((byte)(data.Read8() | 3));

            Wait(1);
            command.Write8(0x60);
            Wait(1);
            data.Write8(status);

            WriteRegister(SetDefaults);
            WriteRegister(EnableDataReporting);

            // Get "MouseID", but somehow do nothing with it (?)
            WriteRegister(0xF2);

            // Set sample rate to 200 Hz (maximum)
            // We're gradually going down to 80 Hz, see below
            WriteRegister(0xF3);
            WriteRegister(200);

            // Set sample rate to 100 Hz
            // See below for final register write of sample rate
            WriteRegister(0xF3);
            WriteRegister(100);

            // Set sample rate to 80 Hz
            // We're done!
            WriteRegister(0xF3);
            WriteRegister(80);

            // Get "MouseID"
            WriteRegister(0xF2);
            byte result = ReadRegister();

            if (result == 3)
            {
                // The scroll wheel is available
            }

            MouseState = byte.MaxValue;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Writes the settings.
        /// </summary>
        /// <param name="settings">The settings.</param>
        protected void WriteSettings(byte[] settings)
        {
            // Write MISCELLANEOUS reg
            miscellaneousOutputWrite.Write8(settings[0]);

            // Write SEQUENCER regs
            for (byte i = 0; i < 5; i++)
            {
                sequencerAddress.Write8(i);
                sequencerData.Write8(settings[1 + i]);
            }

            // Unlock CRTC registers
            crtControllerIndexColor.Write8(0x03);
            crtControllerDataColor.Write8((byte)(crtControllerData.Read8() | 0x80));
            crtControllerIndexColor.Write8(0x11);
            crtControllerDataColor.Write8((byte)(crtControllerData.Read8() & 0x7F));

            // Make sure they remain unlocked
            settings[0x03] = (byte)(settings[0x03] | 0x80);
            settings[0x11] = (byte)(settings[0x11] & 0x7F);

            // Write CRTC regs
            for (byte i = 0; i < 25; i++)
            {
                crtControllerIndexColor.Write8(i);
                crtControllerDataColor.Write8(settings[6 + i]);
            }

            // Write GRAPHICS CONTROLLER regs
            for (byte i = 0; i < 9; i++)
            {
                graphicsControllerAddress.Write8(i);
                graphicsControllerData.Write8(settings[31 + i]);
            }

            // Write ATTRIBUTE CONTROLLER regs
            for (byte i = 0; i < 21; i++)
            {
                inputStatus1ReadB.Read8();
                attributeAddress.Write8(i);
                attributeAddress.Write8(settings[40 + i]);                 // TODO: Double check
            }

            // Lock 16-color palette and unblank display */
            inputStatus1ReadB.Read8();
            attributeAddress.Write8(0x20);
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Reads the specified address.
 /// </summary>
 /// <param name="address">The address.</param>
 /// <returns></returns>
 public byte Read(byte address)
 {
     lock (_lock)
     {
         commandPort.Write8(address);
         return(dataPort.Read8());
     }
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Performs the LBA28.
        /// </summary>
        /// <param name="operation">The operation.</param>
        /// <param name="drive">The drive NBR.</param>
        /// <param name="lba">The lba.</param>
        /// <param name="data">The data.</param>
        /// <param name="offset">The offset.</param>
        /// <returns></returns>
        protected bool PerformLBA28(SectorOperation operation, uint drive, uint lba, byte[] data, uint offset)
        {
            if (drive >= MaximumDriveCount || !driveInfo[drive].Present)
            {
                return(false);
            }

            DeviceHeadPort.Write8((byte)(0xE0 | (drive << 4) | ((lba >> 24) & 0x0F)));
            FeaturePort.Write8(0);
            SectorCountPort.Write8(1);
            LBAHighPort.Write8((byte)((lba >> 16) & 0xFF));
            LBAMidPort.Write8((byte)((lba >> 8) & 0xFF));
            LBALowPort.Write8((byte)(lba & 0xFF));

            CommandPort.Write8((operation == SectorOperation.Write) ? IDECommand.WriteSectorsWithRetry : IDECommand.ReadSectorsWithRetry);

            if (!WaitForReadyStatus())
            {
                return(false);
            }

            var sector = new DataBlock(data);

            //TODO: Don't use PIO
            if (operation == SectorOperation.Read)
            {
                for (uint index = 0; index < 256; index++)
                {
                    sector.SetUShort(offset + (index * 2), DataPort.Read16());
                }
            }
            else
            {
                //NOTE: Transferring 16bits at a time seems to fail(?) to write each second 16bits - transferring 32bits seems to fix this (???)
                for (uint index = 0; index < 128; index++)
                {
                    DataPort.Write32(sector.GetUInt(offset + (index * 4)));
                }

                //Cache flush
                DoCacheFlush();
            }

            return(true);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Starts this hardware device.
        /// </summary>
        public override void Start()
        {
            if (Device.Status != DeviceStatus.Available)
            {
                return;
            }

            ushort timerCount = (ushort)(Frequency / Hz);

            // Set to Mode 3 - Square Wave Generator
            modeControlPort.Write8(SquareWave);
            counter0Divisor.Write8((byte)(timerCount & 0xFF));
            counter0Divisor.Write8((byte)((timerCount & 0xFF00) >> 8));

            tickCount = 0;

            Device.Status = DeviceStatus.Online;
        }
Ejemplo n.º 8
0
        private void WriteRegister(byte value)
        {
            Wait(1);
            command.Write8(0xD4);
            Wait(1);
            data.Write8(value);

            ReadRegister();
        }
Ejemplo n.º 9
0
        public override void Start()
        {
            Device.Status = DeviceStatus.Online;

            byte masterMask;
            byte slaveMask;

            // Save Masks
            masterMask = masterDataPort.Read8();
            slaveMask  = slaveDataPort.Read8();

            // ICW1 - Set Initialize Controller & Expect ICW4
            masterCommandPort.Write8(0x11);

            // ICW2 - interrupt offset
            masterDataPort.Write8(MasterIRQBase);

            // ICW3
            masterDataPort.Write8(0x04);

            // ICW4 - Set 8086 Mode
            masterDataPort.Write8(0x01);

            // ICW1 - Set Initialize Controller & Expect ICW4
            slaveCommandPort.Write8(0x11);

            // ICW2 - interrupt offset
            slaveDataPort.Write8(SlaveIRQBase);

            // ICW3
            slaveDataPort.Write8(0x02);

            // ICW4 - Set 8086 Mode
            slaveDataPort.Write8(0x01);

            // Restore Masks
            masterDataPort.Write8(masterMask);
            slaveDataPort.Write8(slaveMask);

            DisableIRQs();
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Gets the palette.
        /// </summary>
        /// <param name="colorIndex">Index of the color.</param>
        /// <returns></returns>
        public Color GetPalette(byte colorIndex)
        {
            Color color = new Color();

            dacPaletteMask.Write8(0xFF);
            dacIndexRead.Write8(colorIndex);
            color.Red   = dacData.Read8();
            color.Green = dacData.Read8();
            color.Blue  = dacData.Read8();

            return(color);
        }
Ejemplo n.º 11
0
 /// <summary>
 /// Writes to configuration space
 /// </summary>
 /// <param name="bus">The bus.</param>
 /// <param name="slot">The slot.</param>
 /// <param name="function">The function.</param>
 /// <param name="register">The register.</param>
 /// <param name="value">The value.</param>
 void IPCIController.WriteConfig8(byte bus, byte slot, byte function, byte register, byte value)
 {
     configAddress.Write32(GetIndex(bus, slot, function, register));
     configData.Write8(value);
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Sends the command.
 /// </summary>
 /// <param name="command">The command.</param>
 /// <param name="value">The value.</param>
 protected void SendCommand(byte command, byte value)
 {
     activeControllerIndex.Write8(command);
     activeControllerData.Write8(value);
 }
Ejemplo n.º 13
0
        private void DoIdentifyDrive(byte index)
        {
            driveInfo[index].Present = false;

            //Send the identify command to the selected drive
            DeviceHeadPort.Write8((byte)((index == 0) ? 0xA0 : 0xB0));
            SectorCountPort.Write8(0);
            LBALowPort.Write8(0);
            LBAMidPort.Write8(0);
            LBAHighPort.Write8(0);
            CommandPort.Write8(IDECommand.IdentifyDrive);

            if (StatusPort.Read8() == 0)
            {
                //Drive doesn't exist
                return;
            }

            //Wait until a ready status is present
            if (!WaitForReadyStatus())
            {
                return;                 //There's no ready status, this drive doesn't exist
            }

            if (LBAMidPort.Read8() != 0 && LBAHighPort.Read8() != 0)             //Check if the drive is ATA
            {
                //In this case the drive is ATAPI
                //HAL.DebugWriteLine("Device " + index.ToString() + " not ATA");
                return;
            }

            //Wait until the identify data is present (256x16 bits)
            if (!WaitForIdentifyData())
            {
                //HAL.DebugWriteLine("Device " + index.ToString() + " ID error");
                return;
            }

            //An ATA drive is present
            driveInfo[index].Present = true;

            //Read the identification info
            var info = new DataBlock(512);

            for (uint ix = 0; ix < 256; ix++)
            {
                info.SetUShort(ix * 2, DataPort.Read16());
            }

            //Find the addressing mode
            var lba28SectorCount = info.GetUInt(IdentifyDrive.MaxLBA28);

            AddressingMode aMode = AddressingMode.NotSupported;

            if ((info.GetUShort(IdentifyDrive.CommandSetSupported83) & 0x200) == 0x200)             //Check the LBA48 support bit
            {
                aMode = AddressingMode.LBA48;
                driveInfo[index].MaxLBA = info.GetUInt(IdentifyDrive.MaxLBA48);
            }
            else if (lba28SectorCount > 0)             //LBA48 not supported, check LBA28
            {
                aMode = AddressingMode.LBA28;
                driveInfo[index].MaxLBA = lba28SectorCount;
            }

            driveInfo[index].AddressingMode = aMode;

            //HAL.DebugWriteLine("Device " + index.ToString() + " present - MaxLBA=" + driveInfo[index].MaxLBA.ToString());
        }