Unify ata_cmd_data_in/out functions.
[seabios.git] / src / disk.c
index 7f8833b622500eb96cb7f2479ed45f9b15ebd5e5..676914ff6371ed09155ff95b037b3f7fb29eb516 100644 (file)
@@ -74,26 +74,19 @@ basic_access(struct bregs *regs, u8 device, u16 command)
         sector = 0; // this forces the command to be lba
     }
 
-    u16 segment = regs->es;
-    u16 offset  = regs->bx;
-
-    u8 status;
-    switch (command) {
-    case ATA_CMD_READ_SECTORS:
-        status = ata_cmd_data_in(device, ATA_CMD_READ_SECTORS
-                                 , count, cylinder, head, sector
-                                 , lba, segment, offset);
-        break;
-    case ATA_CMD_WRITE_SECTORS:
-        status = ata_cmd_data_out(device, ATA_CMD_WRITE_SECTORS
-                                  , count, cylinder, head, sector
-                                  , lba, segment, offset);
-        break;
-    default:
+    if (!command) {
+        // If verify or seek
         disk_ret(regs, DISK_RET_SUCCESS);
         return;
     }
 
+    u16 segment = regs->es;
+    u16 offset  = regs->bx;
+
+    u8 status = ata_cmd_data(device, command
+                             , count, cylinder, head, sector
+                             , lba, segment, offset);
+
     // Set nb of sector transferred
     regs->al = GET_EBDA(ata.trsfsectors);
 
@@ -187,27 +180,20 @@ extended_access(struct bregs *regs, u8 device, u16 command)
         return;
     }
 
-    u8 status;
-    switch (command) {
-    case ATA_CMD_READ_SECTORS:
-        if (type == ATA_TYPE_ATA)
-            status = ata_cmd_data_in(device, ATA_CMD_READ_SECTORS
-                                     , count, 0, 0, 0
-                                     , lba, segment, offset);
-        else
-            status = cdrom_read(device, lba, count*2048, segment, offset, 0);
-        break;
-    case ATA_CMD_WRITE_SECTORS:
-        status = ata_cmd_data_out(device, ATA_CMD_WRITE_SECTORS
-                                  , count, 0, 0, 0
-                                  , lba, segment, offset);
-        break;
-    default:
+    if (!command) {
         // If verify or seek
         disk_ret(regs, DISK_RET_SUCCESS);
         return;
     }
 
+    u8 status;
+    if (type == ATA_TYPE_ATA)
+        status = ata_cmd_data(device, command
+                              , count, 0, 0, 0
+                              , lba, segment, offset);
+    else
+        status = cdrom_read(device, lba, count*2048, segment, offset, 0);
+
     SET_INT13EXT(regs, count, GET_EBDA(ata.trsfsectors));
 
     if (status != 0) {