예제 #1
0
        public override void Start()
        {
            if (Device.Status != DeviceStatus.Available)
            {
                return;
            }

            ControlPort.Write8(0);

            for (byte drive = 0; drive < maximunDriveCount; drive++)
            {
                DoIdentifyDrive(drive);
            }
        }
예제 #2
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() & ~0x80));

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

            // 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[52 + i]);
            }

            // Lock 16-color palette and unblank display */
            inputStatus1ReadB.Read8();
            attributeAddress.Write8(0x20);
        }
예제 #3
0
        /// <summary>
        /// Writes the specified ch.
        /// </summary>
        /// <param name="ch">The ch.</param>
        public void Write(byte ch)
        {
            try
            {
                spinLock.Enter();

                while (!CanTransmit())
                {
                    ;
                }

                thrBase.Write8(ch);
            }
            finally
            {
                spinLock.Exit();
            }
        }
예제 #4
0
        private void DoIdentifyDrive(byte index)
        {
            //HAL.DebugWriteLine("Device " + index.ToString() + " ID...");

            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)
            {
                //HAL.DebugWriteLine("Device " + index.ToString() + " doesnt exist...");

                //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, which is not supported
                //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;
            }

            //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
            bool lba48Supported = ((info.GetUShort(IdentifyDrive.CommandSetSupported83) & 0x200) == 0x200);

            driveInfo[index].AddressingMode = (lba48Supported ? AddressingMode.LBA48 : AddressingMode.LBA28);

            //Find the max LBA count
            uint  lba28SectorCount = info.GetUInt(IdentifyDrive.MaxLBA28);
            ulong lba48SectorCount = info.GetULong(IdentifyDrive.MaxLBA48);

            //HAL.DebugWriteLine("LBA48BIT=" + lba48Supported.ToString());
            //HAL.DebugWriteLine("LBA28   =" + lba28SectorCount.ToString("X2"));

            if (!lba48Supported)            //No LBA48
            {
                driveInfo[index].MaxLBA = lba28SectorCount;
            }
            else                                    //LBA48 supported
            {
                if (lba28SectorCount == 0x0FFFFFFF) //Check the limit according to the d1699r3f-ata8-acs.pdf (4.10.4 IDENTIFY DEVICE data)
                {
                    driveInfo[index].MaxLBA = (uint)lba48SectorCount;
                }
                else
                {
                    driveInfo[index].MaxLBA = lba28SectorCount;
                }
            }

            //An ATA drive is present and ready to use
            driveInfo[index].Present = true;

            //HAL.DebugWriteLine("Device " + index.ToString() + " present - MaxLBA=" + driveInfo[index].MaxLBA.ToString());
        }
예제 #5
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());
        }