]> git.unchartedbackwaters.co.uk Git - francis/winuae.git/commitdiff
Floppyprofile support.
authorToni Wilen <twilen@winuae.net>
Sat, 26 Nov 2022 17:53:01 +0000 (19:53 +0200)
committerToni Wilen <twilen@winuae.net>
Sat, 26 Nov 2022 17:53:01 +0000 (19:53 +0200)
disk.cpp

index 6ea545ee3bd4254234341eb2a42445d6b349c606..76b202d0d0a6c1a5b0ef0035de3860b9c95c3df0 100644 (file)
--- a/disk.cpp
+++ b/disk.cpp
@@ -197,6 +197,7 @@ typedef struct {
        int num_tracks, write_num_tracks, num_secs, num_heads;
        int hard_num_cyls;
        bool dskeject;
+       int dskeject_time;
        bool dskchange;
        int dskchange_time;
        bool dskready;
@@ -236,6 +237,20 @@ typedef struct {
 
 #define MIN_STEPLIMIT_CYCLE (CYCLE_UNIT * 140)
 
+static const TCHAR *drivetypes[] = {
+       _T("none"),
+       _T("35dd"),
+       _T("35hd"),
+       _T("525sd"),
+       _T("35ddescom"),
+       _T("pc525_40"),
+       _T("pc525_80"),
+       _T("pc525_4080"),
+       _T("525dd"),
+       _T("floppybridge"),
+       NULL
+};
+
 static uae_u16 bigmfmbufw[0x4000 * DDHDMULT];
 static drive floppy[MAX_FLOPPY_DRIVES];
 static TCHAR dfxhistory[HISTORY_MAX][MAX_PREVIOUS_IMAGES][MAX_DPATH];
@@ -843,6 +858,7 @@ static void reset_drive (int num)
        if (num == 0 && currprefs.floppyslots[num].dfxtype == 0)
                drv->indexhackmode = 1;
        drv->dskchange_time = 0;
+       drv->dskeject_time = 0;
        drv->dskchange = false;
        drv->dskready_down_time = 0;
        drv->dskready_up_time = 0;
@@ -1726,8 +1742,11 @@ static void set_steplimit (drive *drv)
        drv->steplimitcycle = get_cycles();
 }
 
-static bool drive_empty (drive * drv)
+static bool drive_empty(drive * drv)
 {
+       if (drv->dskeject_time > 0) {
+               return true;
+       }
 #ifdef FLOPPYBRIDGE
        if (drv->bridge) {
                bool v = drv->bridge->isDiskInDrive();
@@ -1741,7 +1760,7 @@ static bool drive_empty (drive * drv)
        return drv->diskfile == 0 && drv->dskchange_time >= 0;
 }
 
-static void drive_step (drive *drv, int step_direction)
+static void drive_step(drive *drv, int step_direction)
 {
 #ifdef CATWEASEL
        if (drv->catweasel) {
@@ -1817,7 +1836,7 @@ static void drive_step (drive *drv, int step_direction)
                write_log (_T(" ->step %d"), drv->cyl);
 }
 
-static bool drive_track0 (drive * drv)
+static bool drive_track0(drive * drv)
 {
 #ifdef FLOPPYBRIDGE
        if (drv->bridge) {
@@ -1834,6 +1853,9 @@ static bool drive_track0 (drive * drv)
 
 static bool drive_diskchange(drive *drv)
 {
+       if (drv->dskeject_time > 0 && drv->dskchange) {
+               return true;
+       }
 #ifdef FLOPPYBRIDGE
        if (drv->bridge) {
                bool v = drv->bridge->hasDiskChanged();
@@ -3310,6 +3332,8 @@ static void DISK_check_change (void)
                currprefs.floppy_read_only = changed_prefs.floppy_read_only;
        for (int i = 0; i < MAX_FLOPPY_DRIVES; i++) {
                drive *drv = floppy + i;
+               bool dc = false;
+
                if (drv->dskeject) {
                        drive_eject(drv);
                        /* set dskchange_time, disk_insert() will be
@@ -3318,7 +3342,26 @@ static void DISK_check_change (void)
                        */
                        setdskchangetime(drv, 2 * 50 * 312);
                }
+
+               if (_tcscmp(currprefs.floppyslots[i].dfxprofile, changed_prefs.floppyslots[i].dfxprofile)) {
+                       TCHAR tmp[256];
+                       _tcscpy(tmp, changed_prefs.floppyslots[i].dfxprofile);
+                       const TCHAR *idx = _tcschr(tmp, ':');
+                       if (idx) {
+                               tmp[idx - tmp] = 0;
+                       }
+                       for (int j = 0; drivetypes[j]; j++) {
+                               if (!_tcsicmp(tmp, drivetypes[j])) {
+                                       changed_prefs.floppyslots[i].dfxtype = j - 1;
+                                       if (j > 0) {
+                                               dc = true;
+                                       }
+                               }
+                       }
+               }
+
                if (currprefs.floppyslots[i].dfxtype != changed_prefs.floppyslots[i].dfxtype ||
+                       _tcscmp(currprefs.floppyslots[i].dfxprofile, changed_prefs.floppyslots[i].dfxprofile) ||
                        currprefs.floppyslots[i].dfxsubtype != changed_prefs.floppyslots[i].dfxsubtype) {
                        int old = currprefs.floppyslots[i].dfxtype;
                        currprefs.floppyslots[i].dfxtype = changed_prefs.floppyslots[i].dfxtype;
@@ -3329,9 +3372,14 @@ static void DISK_check_change (void)
                        if (old >= DRV_FB || currprefs.floppyslots[i].dfxtype >= DRV_FB) {
                                floppybridge_getsetprofile(i);
                                floppybridge_init(&currprefs);
+                               dc = true;
                        }
 #endif
-                       reset_drive (i);
+                       reset_drive(i);
+                       if (dc) {
+                               drv->dskeject_time = 2 * 50 * 312;
+                               drv->dskchange = true;
+                       }
 #ifdef RETROPLATFORM
                        rp_floppy_device_enable (i, currprefs.floppyslots[i].dfxtype >= 0);
 #endif
@@ -3344,16 +3392,16 @@ static void DISK_check_change (void)
        }
 }
 
-void DISK_vsync (void)
+void DISK_vsync(void)
 {
-       DISK_check_change ();
+       DISK_check_change();
        for (int i = 0; i < MAX_FLOPPY_DRIVES; i++) {
                drive *drv = floppy + i;
                if (drv->selected_delay > 0) {
                        drv->selected_delay--;
                }
                if (drv->dskchange_time == 0 && _tcscmp (currprefs.floppyslots[i].df, changed_prefs.floppyslots[i].df))
-                       disk_insert (i, changed_prefs.floppyslots[i].df, changed_prefs.floppyslots[i].forcedwriteprotect);
+                       disk_insert(i, changed_prefs.floppyslots[i].df, changed_prefs.floppyslots[i].forcedwriteprotect);
        }
 }
 
@@ -3883,9 +3931,11 @@ static void disk_doupdate_write(int floppybits, int trackspeed)
                                        dsklength--;
                                        if (dsklength <= 0) {
                                                // delay write DMA finished state until bridge has all pending data written
+#ifdef FLOPPYBRIDGE
                                                if (!wasBridge) {
                                                        disk_dmafinished();
                                                }
+#endif
                                                for (int dr = 0; dr < MAX_FLOPPY_DRIVES ; dr++) {
                                                        drive *drv = &floppy[dr];
                                                        drv->writtento = 0;
@@ -4258,11 +4308,11 @@ static void disk_dma_debugmsg (void)
 
 /* this is very unoptimized. DSKBYTR is used very rarely, so it should not matter. */
 
-uae_u16 DSKBYTR (int hpos)
+uae_u16 DSKBYTR(int hpos)
 {
        uae_u16 v;
 
-       DISK_update (hpos);
+       DISK_update(hpos);
        v = dskbytr_val;
        dskbytr_val &= ~0x8000;
        if (word == dsksync && cycles_in_range(dsksync_cycles)) {
@@ -4276,7 +4326,7 @@ uae_u16 DSKBYTR (int hpos)
        if (dsklen & 0x4000)
                v |= 0x2000;
        if (disk_debug_logging > 2)
-               write_log (_T("DSKBYTR=%04X hpos=%d\n"), v, hpos);
+               write_log(_T("DSKBYTR=%04X PC=%08x\n"), v, M68K_GETPC);
        for (int dr = 0; dr < MAX_FLOPPY_DRIVES; dr++) {
                drive *drv = &floppy[dr];
                if (drv->motoroff)
@@ -4290,9 +4340,9 @@ uae_u16 DSKBYTR (int hpos)
                        drv->track_access_done = true;
                        if (disk_debug_mode & DISK_DEBUG_PIO) {
                                if (disk_debug_track < 0 || disk_debug_track == 2 * drv->cyl + side) {
-                                       disk_dma_debugmsg ();
-                                       write_log (_T("DSKBYTR=%04X\n"), v);
-                                       activate_debugger ();
+                                       disk_dma_debugmsg();
+                                       write_log(_T("DSKBYTR=%04X\n"), v);
+                                       activate_debugger();
                                        break;
                                }
                        }
@@ -4301,7 +4351,7 @@ uae_u16 DSKBYTR (int hpos)
        return v;
 }
 
-static void DISK_start (void)
+static void DISK_start(void)
 {
        int dr;
 
@@ -4338,7 +4388,7 @@ static void DISK_start (void)
 
                        if (dskdmaen == DSKDMA_WRITE) {
                                drv->tracklen = floppy_writemode > 0 ? FLOPPY_WRITE_MAXLEN : FLOPPY_WRITE_LEN * drv->ddhd * 8 * 2;
-                               drv->trackspeed = get_floppy_speed ();
+                               drv->trackspeed = get_floppy_speed();
                                drv->skipoffset = -1;
                                updatemfmpos (drv);
                        }
@@ -4391,14 +4441,17 @@ void DISK_hsync (void)
                        if (drv->dskready_up_time == 0 && !drv->motoroff)
                                drv->dskready = true;
                }
+               if (drv->dskeject_time > 0) {
+                       drv->dskeject_time--;
+               }
                /* delay until new disk image is inserted */
                if (drv->dskchange_time > 0) {
                        drv->dskchange_time--;
                        if (drv->dskchange_time == 0) {
-                               drive_insert (drv, &currprefs, dr, drv->newname, false, drv->newnamewriteprotected);
+                               drive_insert(drv, &currprefs, dr, drv->newname, false, drv->newnamewriteprotected);
                                if (disk_debug_logging > 0)
-                                       write_log (_T("delayed insert, drive %d, image '%s'\n"), dr, drv->newname);
-                               update_drive_gui (dr, false);
+                                       write_log(_T("delayed insert, drive %d, image '%s'\n"), dr, drv->newname);
+                               update_drive_gui(dr, false);
                        }
                }
 
@@ -4437,7 +4490,7 @@ void DISK_update (int tohpos)
        int cycles;
 
        if (disk_hpos < 0) {
-               disk_hpos = - disk_hpos;
+               disk_hpos = -disk_hpos;
                return;
        }
 
@@ -4448,11 +4501,13 @@ void DISK_update (int tohpos)
        if (tohpos != maxhpos || cycles / 256 != maxhpos)
                write_log (_T("%d %d %d\n"), tohpos, cycles / 256, disk_hpos / 256);
 #endif
-       if (cycles <= 0)
+       if (cycles <= 0) {
                return;
+       }
        disk_hpos += cycles;
-       if (disk_hpos >= (maxhpos << 8))
+       if (disk_hpos >= (maxhpos << 8)) {
                disk_hpos %= 1 << 8;
+       }
 
        for (dr = 0; dr < MAX_FLOPPY_DRIVES; dr++) {
                drive *drv = &floppy[dr];
@@ -5024,11 +5079,14 @@ bool floppybridge_has(void)
 
 static void floppybridge_init2(struct uae_prefs *p)
 {
-       floppybridge_init3();
+       static const TCHAR *floppybridgeprofile = _T("FloppyBridge:");
        bool needbridge = false;
+
+       floppybridge_init3();
        for (int i = 0; i < MAX_FLOPPY_DRIVES; i++) {
+               TCHAR *profile = p->floppyslots[i].dfxprofile;
                int type = p->floppyslots[i].dfxtype;
-               if (type >= DRV_FB) {
+               if (type >= DRV_FB || !_tcsncmp(profile, floppybridgeprofile, _tcslen(floppybridgeprofile))) {
                        needbridge = true;
                }
        }
@@ -5043,6 +5101,14 @@ static void floppybridge_init2(struct uae_prefs *p)
                return;
        }
        for (int dr = 0; dr < MAX_FLOPPY_DRIVES; dr++) {
+               TCHAR *profile = p->floppyslots[dr].dfxprofile;
+               if (!_tcsncmp(profile, floppybridgeprofile, _tcslen(floppybridgeprofile))) {
+                       profile += _tcslen(floppybridgeprofile);
+                       if (p->floppyslots[dr].dfxtype != DRV_FB) {
+                               p->floppyslots[dr].dfxtype = DRV_FB;
+                               changed_prefs.floppyslots[dr].dfxtype = DRV_FB;
+                       }
+               }
                int type = p->floppyslots[dr].dfxtype;
                if (type == DRV_FB) {
                        if (floppy[dr].bridge == NULL || type != bridge_type[dr]) {
@@ -5055,15 +5121,18 @@ static void floppybridge_init2(struct uae_prefs *p)
                                bridge_driver[dr] = NULL;
                                bridge_type[dr] = type;
                                FloppyBridgeAPI *bridge = NULL;
-                               int id = _tstol(p->floppyslots[dr].dfxsubtypeid);
-                               if (p->floppyslots[dr].dfxprofile[0]) {
-                                       char *a = ua(p->floppyslots[dr].dfxprofile);
+                               if (profile[0]) {
+                                       char *a = ua(profile);
                                        bridge = FloppyBridgeAPI::createDriverFromString(a);
+                                       if (!bridge) {
+                                               write_log(_T("FB profile '%s' failed\n"), profile);
+                                       }
                                        xfree(a);
                                }
                                if (!bridge) {
                                        const TCHAR *name = _tcschr(p->floppyslots[dr].dfxsubtypeid, ':');
                                        if (name) {
+                                               int id = _tstol(p->floppyslots[dr].dfxsubtypeid);
                                                name++;
                                                for (int i = 0; i < bridgeprofiles.size(); i++) {
                                                        FloppyBridgeAPI::FloppyBridgeProfileInformation fbpi = bridgeprofiles.at(i);
@@ -5083,7 +5152,8 @@ static void floppybridge_init2(struct uae_prefs *p)
                                                }
                                        }
                                }
-                               if (!bridge) {
+                               if (!bridge && p->floppyslots[dr].dfxsubtypeid[0]) {
+                                       int id = _tstol(p->floppyslots[dr].dfxsubtypeid);
                                        bridge = FloppyBridgeAPI::createDriverFromProfileID(id);
                                }
                                if (bridge) {