[SeaBIOS] [PATCH v2 1/3] floppy: add floppy_drive_seek()

Christian Quante posted 3 patches 2 months ago
There is a newer version of this series
[SeaBIOS] [PATCH v2 1/3] floppy: add floppy_drive_seek()
Posted by Christian Quante 2 months ago
Wrap the SEEK command and the BDA bookkeeping that goes with it, the way
floppy_drive_recal() already does for RECALIBRATE.  No functional change;
the next patch gains a second caller.

Signed-off-by: Christian Quante <christian@quante.one>
---
 src/hw/floppy.c | 24 +++++++++++++++++-------
 1 file changed, 17 insertions(+), 7 deletions(-)

diff --git a/src/hw/floppy.c b/src/hw/floppy.c
index 9e6647d4..8f053fe3 100644
--- a/src/hw/floppy.c
+++ b/src/hw/floppy.c
@@ -416,6 +416,21 @@ floppy_drive_recal(u8 floppyid)
     return DISK_RET_SUCCESS;
 }
 
+static int
+floppy_drive_seek(u8 floppyid, u8 cylinder)
+{
+    dprintf(2, "Floppy_drive_seek %d to %d\n", floppyid, cylinder);
+    u8 param[2];
+    param[0] = floppyid;
+    param[1] = cylinder;
+    int ret = floppy_drive_pio(floppyid, FC_SEEK, param);
+    if (ret)
+        return ret;
+
+    SET_BDA(floppy_track[floppyid], cylinder);
+    return DISK_RET_SUCCESS;
+}
+
 static int
 floppy_drive_specify(void)
 {
@@ -511,15 +526,10 @@ floppy_prep(struct drive_s *drive_gf, u8 cylinder)
     }
 
     // Seek to cylinder if needed.
-    u8 lastcyl = GET_BDA(floppy_track[floppyid]);
-    if (cylinder != lastcyl) {
-        u8 param[2];
-        param[0] = floppyid;
-        param[1] = cylinder;
-        int ret = floppy_drive_pio(floppyid, FC_SEEK, param);
+    if (cylinder != GET_BDA(floppy_track[floppyid])) {
+        int ret = floppy_drive_seek(floppyid, cylinder);
         if (ret)
             return ret;
-        SET_BDA(floppy_track[floppyid], cylinder);
     }
 
     return DISK_RET_SUCCESS;
-- 
2.53.0

_______________________________________________
SeaBIOS mailing list -- seabios@seabios.org
To unsubscribe send an email to seabios-leave@seabios.org