Пример #1
0
        private void Wait(byte type)
        {
            int timeOut = 100000;

            if (type == 0)
            {
                for (; timeOut > 0; timeOut--)
                {
                    if ((command.Read8() & 1) == 1)
                    {
                        return;
                    }
                }

                return;
            }
            else
            {
                for (; timeOut > 0; timeOut--)
                {
                    if ((command.Read8() & 2) == 0)
                    {
                        return;
                    }
                }

                return;
            }
        }
Пример #2
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);
        }
Пример #3
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);
        }
Пример #4
0
        public override void Start()
        {
            if (Device.Status != DeviceStatus.Available)
            {
                return;
            }

            WriteSettings(VGAText80x25);

            colorMode = ((miscellaneousOutput.Read8() & 1) == 1);

            if (colorMode)
            {
                offset                = 0x8000;
                bytePerChar           = 2;
                activeControllerIndex = crtControllerIndexColor;
                activeControllerData  = crtControllerDataColor;
            }
            else
            {
                offset                = 0x0;
                bytePerChar           = 1;
                activeControllerIndex = crtControllerIndex;
                activeControllerData  = crtControllerData;
            }

            width  = GetValue(CRTCommands.HorizontalDisplayEnableEnd);
            height = GetValue(CRTCommands.VerticalDisplayEnableEnd);

            width++;
            height = 25;

            Device.Status = DeviceStatus.Online;
        }
Пример #5
0
        public override void Probe()
        {
            LBALowPort.Write8(0x88);

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

            Device.Status = (found) ? DeviceStatus.Available : DeviceStatus.NotFound;
        }
Пример #6
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());
     }
 }
Пример #7
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;
        }
Пример #8
0
        /// <summary>
        /// Reads the scan code from the device
        /// </summary>
        protected void ReadScanCode()
        {
            lock (_lock)
            {
                byte status = statusPort.Read8();

                if ((status & 0x01) == 0x01)
                {
                    byte data = dataPort.Read8();

                    AddToFIFO(data);
                }
            }
        }
Пример #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();
        }
Пример #10
0
 /// <summary>
 /// Gets the value.
 /// </summary>
 /// <param name="command">The command.</param>
 /// <returns></returns>
 protected byte GetValue(byte command)
 {
     activeControllerIndex.Write8(command);
     return(activeControllerData.Read8());
 }
Пример #11
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());
        }
Пример #12
0
        public override bool OnInterrupt()
        {
            byte D = data.Read8();

            if (phase == 0)
            {
                if (D == 0xfa)
                {
                    phase = 1;
                }
                return(true);
            }

            if (phase == 1)
            {
                if ((D & (1 << 3)) == (1 << 3))
                {
                    mData[0] = D;
                    phase    = 2;
                }
                return(true);
            }

            if (phase == 2)
            {
                mData[1] = D;
                phase    = 3;
                return(true);
            }

            if (phase == 3)
            {
                mData[2] = D;
                phase    = 1;

                mData[0]  &= 0x07;
                MouseState = mData[0] switch
                {
                    0x01 => 0,
                    0x02 => 1,

                    // TODO: Add scroll wheel
                    _ => byte.MaxValue,
                };

                if (mData[1] > 127)
                {
                    aX = -(255 - mData[1]);
                }
                else
                {
                    aX = mData[1];
                }

                if (mData[2] > 127)
                {
                    aY = -(255 - mData[2]);
                }
                else
                {
                    aY = mData[2];
                }

                X = Math.Clamp(X + aX, 0, screenWidth);
                Y = Math.Clamp(Y - aY, 0, screenHeight);
            }

            return(true);
        }