11#include " HDD-ATA.h"
22
33void printf (char * );
4-
5- AdvancedTechnologyAttachment::AdvancedTechnologyAttachment (uint16_t PortBase, bool master)
6- :DataPort(PortBase),
7- ErrorPort(PortBase + 1 ),
8- SectorCountPort(PortBase + 2 ),
9- LBALowPort(PortBase + 3 ),
10- LBAMidPort(PortBase + 4 ),
11- LBAHighPort(PortBase + 5 ),
12- DevicePort(PortBase + 6 ),
13- CommandPort(PortBase + 7 ),
14- ControlPort(PortBase + 0x206 )
4+ void printHex (uint8_t );
5+
6+ AdvancedTechnologyAttachment::AdvancedTechnologyAttachment (bool master, uint16_t portBase)
7+ : dataPort(portBase),
8+ errorPort(portBase + 0x1 ),
9+ sectorCountPort(portBase + 0x2 ),
10+ lbaLowPort(portBase + 0x3 ),
11+ lbaMidPort(portBase + 0x4 ),
12+ lbaHiPort(portBase + 0x5 ),
13+ devicePort(portBase + 0x6 ),
14+ commandPort(portBase + 0x7 ),
15+ controlPort(portBase + 0x206 )
1516{
16- this ->Master = master;
17- BytesPerSector = 512 ;
18-
17+ this ->master = master;
1918}
2019
2120AdvancedTechnologyAttachment::~AdvancedTechnologyAttachment ()
2221{
23-
2422}
2523
26- void AdvancedTechnologyAttachment::identify ()
24+ void AdvancedTechnologyAttachment::Identify ()
2725{
28- DevicePort .WriteToPort (Master ? 0xA0 : 0xB0 );
29- ControlPort .WriteToPort (0 );
26+ devicePort .WriteToPort (master ? 0xA0 : 0xB0 );
27+ controlPort .WriteToPort (0 );
3028
31- DevicePort .WriteToPort (0xA0 );
32- uint8_t status = CommandPort .ReadFromPort ();
29+ devicePort .WriteToPort (0xA0 );
30+ uint8_t status = commandPort .ReadFromPort ();
3331 if (status == 0xFF )
3432 return ;
3533
3634
37- DevicePort .WriteToPort (Master ? 0xA0 : 0xB0 );
38- SectorCountPort .WriteToPort (0 );
39- LBALowPort .WriteToPort (0 );
40- LBAMidPort .WriteToPort (0 );
41- LBAHighPort .WriteToPort (0 );
42- CommandPort .WriteToPort (0xEC ); // identify command
35+ devicePort .WriteToPort (master ? 0xA0 : 0xB0 );
36+ sectorCountPort .WriteToPort (0 );
37+ lbaLowPort .WriteToPort (0 );
38+ lbaMidPort .WriteToPort (0 );
39+ lbaHiPort .WriteToPort (0 );
40+ commandPort .WriteToPort (0xEC ); // identify command
4341
4442
45- status = CommandPort .ReadFromPort ();
43+ status = commandPort .ReadFromPort ();
4644 if (status == 0x00 )
4745 return ;
4846
4947 while (((status & 0x80 ) == 0x80 )
5048 && ((status & 0x01 ) != 0x01 ))
51- status = CommandPort .ReadFromPort ();
49+ status = commandPort .ReadFromPort ();
5250
5351 if (status & 0x01 )
5452 {
5553 printf (" ERROR" );
5654 return ;
5755 }
5856
59- for (int i = 0 ; i < 256 ; i++)
57+ for (int i = 0 ; i < 35 ; i++)
6058 {
61- uint16_t data = DataPort.ReadFromPort ();
62- char *text = " \0 " ;
59+
60+ uint16_t data = dataPort.ReadFromPort ();
61+ char *text = " \0\0 " ;
6362 text[0 ] = (data >> 8 ) & 0xFF ;
6463 text[1 ] = data & 0xFF ;
6564 printf (text);
@@ -72,18 +71,18 @@ void AdvancedTechnologyAttachment::Read28(uint32_t sectorNum, int count)
7271 if (sectorNum > 0x0FFFFFFF )
7372 return ;
7473
75- DevicePort .WriteToPort ( (Master ? 0xE0 : 0xF0 ) | ((sectorNum & 0x0F000000 ) >> 24 ) );
76- ErrorPort .WriteToPort (0 );
77- SectorCountPort .WriteToPort (1 );
78- LBALowPort .WriteToPort ( sectorNum & 0x000000FF );
79- LBAMidPort .WriteToPort ( (sectorNum & 0x0000FF00 ) >> 8 );
80- LBALowPort .WriteToPort ( (sectorNum & 0x00FF0000 ) >> 16 );
81- CommandPort .WriteToPort (0x20 );
74+ devicePort .WriteToPort ( (master ? 0xE0 : 0xF0 ) | ((sectorNum & 0x0F000000 ) >> 24 ) );
75+ errorPort .WriteToPort (0 );
76+ sectorCountPort .WriteToPort (1 );
77+ lbaLowPort .WriteToPort ( sectorNum & 0x000000FF );
78+ lbaMidPort .WriteToPort ( (sectorNum & 0x0000FF00 ) >> 8 );
79+ lbaLowPort .WriteToPort ( (sectorNum & 0x00FF0000 ) >> 16 );
80+ commandPort .WriteToPort (0x20 );
8281
83- uint8_t status = CommandPort .ReadFromPort ();
82+ uint8_t status = commandPort .ReadFromPort ();
8483 while (((status & 0x80 ) == 0x80 )
8584 && ((status & 0x01 ) != 0x01 ))
86- status = CommandPort .ReadFromPort ();
85+ status = commandPort .ReadFromPort ();
8786
8887 if (status & 0x01 )
8988 {
@@ -96,7 +95,7 @@ void AdvancedTechnologyAttachment::Read28(uint32_t sectorNum, int count)
9695
9796 for (int i = 0 ; i < count; i += 2 )
9897 {
99- uint16_t wdata = DataPort .ReadFromPort ();
98+ uint16_t wdata = dataPort .ReadFromPort ();
10099
101100 char *text = " \0 " ;
102101 text[0 ] = wdata & 0xFF ;
@@ -110,7 +109,7 @@ void AdvancedTechnologyAttachment::Read28(uint32_t sectorNum, int count)
110109 }
111110
112111 for (int i = count + (count%2 ); i < 512 ; i += 2 )
113- DataPort .ReadFromPort ();
112+ dataPort .ReadFromPort ();
114113}
115114
116115void AdvancedTechnologyAttachment::Write28 (uint32_t sectorNum, uint8_t * data, uint32_t count)
@@ -121,13 +120,13 @@ void AdvancedTechnologyAttachment::Write28(uint32_t sectorNum, uint8_t* data, ui
121120 return ;
122121
123122
124- DevicePort .WriteToPort ( (Master ? 0xE0 : 0xF0 ) | ((sectorNum & 0x0F000000 ) >> 24 ) );
125- ErrorPort .WriteToPort (0 );
126- SectorCountPort .WriteToPort (1 );
127- LBALowPort .WriteToPort ( sectorNum & 0x000000FF );
128- LBAMidPort .WriteToPort ( (sectorNum & 0x0000FF00 ) >> 8 );
129- LBALowPort .WriteToPort ( (sectorNum & 0x00FF0000 ) >> 16 );
130- CommandPort .WriteToPort (0x30 );
123+ devicePort .WriteToPort ( (master ? 0xE0 : 0xF0 ) | ((sectorNum & 0x0F000000 ) >> 24 ) );
124+ errorPort .WriteToPort (0 );
125+ sectorCountPort .WriteToPort (1 );
126+ lbaLowPort .WriteToPort ( sectorNum & 0x000000FF );
127+ lbaMidPort .WriteToPort ( (sectorNum & 0x0000FF00 ) >> 8 );
128+ lbaLowPort .WriteToPort ( (sectorNum & 0x00FF0000 ) >> 16 );
129+ commandPort .WriteToPort (0x30 );
131130
132131
133132 printf (" Writing to ATA Drive: " );
@@ -137,7 +136,7 @@ void AdvancedTechnologyAttachment::Write28(uint32_t sectorNum, uint8_t* data, ui
137136 uint16_t wdata = data[i];
138137 if (i+1 < count)
139138 wdata |= ((uint16_t )data[i+1 ]) << 8 ;
140- DataPort .WriteToPort (wdata);
139+ dataPort .WriteToPort (wdata);
141140
142141 char *text = " \0 " ;
143142 text[0 ] = (wdata >> 8 ) & 0xFF ;
@@ -146,22 +145,22 @@ void AdvancedTechnologyAttachment::Write28(uint32_t sectorNum, uint8_t* data, ui
146145 }
147146
148147 for (int i = count + (count%2 ); i < 512 ; i += 2 )
149- DataPort .WriteToPort (0x0000 );
148+ dataPort .WriteToPort (0x0000 );
150149
151150}
152151
153152void AdvancedTechnologyAttachment::Flush ()
154153{
155- DevicePort .WriteToPort ( Master ? 0xE0 : 0xF0 );
156- CommandPort .WriteToPort (0xE7 );
154+ devicePort .WriteToPort ( master ? 0xE0 : 0xF0 );
155+ commandPort .WriteToPort (0xE7 );
157156
158- uint8_t status = CommandPort .ReadFromPort ();
157+ uint8_t status = commandPort .ReadFromPort ();
159158 if (status == 0x00 )
160159 return ;
161160
162161 while (((status & 0x80 ) == 0x80 )
163162 && ((status & 0x01 ) != 0x01 ))
164- status = CommandPort .ReadFromPort ();
163+ status = commandPort .ReadFromPort ();
165164
166165 if (status & 0x01 )
167166 {
0 commit comments