From e418dc425133541c0740d3628d02124f41c42a2c Mon Sep 17 00:00:00 2001 From: mterwoord_cp <7cd3fd84a0151ea055c2f79e4d2eef9576fe9afesxUZAwxD> Date: Sat, 8 Mar 2008 10:16:23 +0000 Subject: [PATCH] ata works completely now --- .../Cosmos/Cosmos.Hardware/New/Storage/ATA.cs | 36 ++++++++++++++++++- .../Commands/DeviceCommand.cs | 15 +++----- 2 files changed, 40 insertions(+), 11 deletions(-) diff --git a/source/Cosmos/Cosmos.Hardware/New/Storage/ATA.cs b/source/Cosmos/Cosmos.Hardware/New/Storage/ATA.cs index 196469252..661efca10 100644 --- a/source/Cosmos/Cosmos.Hardware/New/Storage/ATA.cs +++ b/source/Cosmos/Cosmos.Hardware/New/Storage/ATA.cs @@ -217,7 +217,41 @@ namespace Cosmos.Hardware.New.Storage { } public override void WriteBlock(ulong aBlock, byte[] aContents) { - throw new NotImplementedException(); + uint xSleepCount = Timeout; + while (((IOReadByte(mController_Command) & 0x80) == 0x80) && xSleepCount > 0) { + mSleep(1); + xSleepCount--; + } + if (xSleepCount == 0) { + throw new Exception("[ATA|WriteBlockNew] Failed 1"); + } + IOWriteByte(mController_FeatureReg, 0); + IOWriteByte(mController_SectorCount, 1); + IOWriteByte(mController_SectorNumber, (byte)aBlock); + IOWriteByte(mController_CylinderLow, (byte)(aBlock >> 8)); + IOWriteByte(mController_CylinderHigh, (byte)(aBlock >> 16)); + IOWriteByte( mController_DeviceHead, (byte)(0xE0 | (mDrive << 4) | (byte)(aBlock >> 24))); + IOWriteByte(mController_DeviceControl, 0); // receive interrupts... + IOWriteByte(mController_Command, 0x30); + xSleepCount = Timeout; + while (((IOReadByte(mController_Command) & 0x80) == 0x80) && xSleepCount > 0) { + mSleep(1); + xSleepCount--; + } + if (xSleepCount == 0) { + throw new Exception("[ATA|WriteBlockNew] Failed 2"); + } + xSleepCount = Timeout; + while (((IOReadByte(mController_AlternateStatus) & 0x8) == 0x8) && xSleepCount > 0) { + mSleep(1); + xSleepCount--; + } + if (xSleepCount == 0) { + throw new Exception("[ATA|WriteBlockNew] Failed 3"); + } + for (int i = 0; i < 256; i++) { + IOWriteWord(mController_Data, (ushort)((aContents[i * 2]) | (aContents[i * 2 + 1] << 8))); + } } public override string Name { diff --git a/source/Cosmos/Cosmos.Shell.Console/Commands/DeviceCommand.cs b/source/Cosmos/Cosmos.Shell.Console/Commands/DeviceCommand.cs index 5889e2d0e..b7f6209ca 100644 --- a/source/Cosmos/Cosmos.Shell.Console/Commands/DeviceCommand.cs +++ b/source/Cosmos/Cosmos.Shell.Console/Commands/DeviceCommand.cs @@ -50,16 +50,11 @@ namespace Cosmos.Shell.Console.Commands { System.Console.WriteLine("Storage device is null!"); return; } - var xBytes = xBD.ReadBlock(2); - System.Console.Write("Byte 1-1: "); - System.Console.WriteLine(xBytes[6].ToString()); - System.Console.Write("Byte 1-2: "); - System.Console.WriteLine(xBytes[7].ToString()); - xBytes = xBD.ReadBlock(3); - System.Console.Write("Byte 2-1: "); - System.Console.WriteLine(xBytes[6].ToString()); - System.Console.Write("Byte 2-2: "); - System.Console.WriteLine(xBytes[7].ToString()); + var xBytes = new byte[512]; + for (int i = 0; i < 512; i++) { + xBytes[i] = (byte)(i % 255); + } + xBD.WriteBlock(0, xBytes); } } }