]> git.unchartedbackwaters.co.uk Git - francis/winuae.git/commitdiff
CD/HD led correct UAE unit number information.
authorToni Wilen <twilen@winuae.net>
Sat, 31 Mar 2018 17:23:42 +0000 (20:23 +0300)
committerToni Wilen <twilen@winuae.net>
Sat, 31 Mar 2018 17:23:42 +0000 (20:23 +0300)
filesys.cpp
hardfile.cpp
ide.cpp
include/ide.h
include/options.h
include/scsi.h
ncr9x_scsi.cpp
ncr_scsi.cpp
od-win32/rp.cpp
od-win32/win32gui.cpp
scsi.cpp

index 7898bdb08624a8fdd860cb46690e22e4a861adab..adface9992d2a03db05cb2fbbe9bc4dbc4beded7 100644 (file)
@@ -831,19 +831,23 @@ static int set_filesys_unit (int nr, struct uaedev_config_info *ci)
 
 static int add_filesys_unit (struct uaedev_config_info *ci)
 {
-       int ret;
+       int nr;
 
        if (nr_units () >= MAX_FILESYSTEM_UNITS)
                return -1;
 
-       ret = set_filesys_unit_1 (-1, ci);
+       nr = set_filesys_unit_1 (-1, ci);
 #ifdef RETROPLATFORM
-       if (ret >= 0) {
-               rp_hd_device_enable (ret, true);
-               rp_harddrive_image_change (ret, ci->readonly, ci->rootdir);
+       if (nr >= 0) {
+               UnitInfo *ui = &mountinfo.ui[nr];
+               rp_hd_device_enable (nr, true);
+               if (ui->unit_type == UNIT_CDFS)
+                       rp_cd_image_change(nr, ci->rootdir);
+               else
+                       rp_harddrive_image_change(nr, ci->readonly, ci->rootdir);
        }
 #endif
-       return ret;
+       return nr;
 }
 
 int kill_filesys_unitconfig (struct uae_prefs *p, int nr)
@@ -1071,6 +1075,7 @@ static void initialize_mountinfo (void)
                int type = uci->controller_type;
                int unit = uci->controller_unit;
                bool added = false;
+               uci->uae_unitnum = nr;
                if (type == HD_CONTROLLER_TYPE_UAE) {
                        continue;
                } else if (type != HD_CONTROLLER_TYPE_IDE_AUTO && type >= HD_CONTROLLER_TYPE_IDE_FIRST && type <= HD_CONTROLLER_TYPE_IDE_LAST) {
index c4b52e5d0f10c9c990a17126cacce82bf342ea59..d75a6a3daaf8378630325cf85113cf8ad418048f 100644 (file)
@@ -534,6 +534,7 @@ int hdf_hd_open (struct hd_hardfiledata *hfd)
        struct uaedev_config_info *ci = &hfd->hfd.ci;
        if (hdf_open (&hfd->hfd) <= 0)
                return 0;
+       hfd->hfd.unitnum = ci->uae_unitnum;
        if (ci->physical_geometry) {
                hfd->cyls = ci->pcyls;
                hfd->heads = ci->pheads;
@@ -2450,7 +2451,7 @@ static uae_u32 REGPARAM2 hardfile_open (TrapContext *ctx)
                                        trap_put_byte(ctx, ioreq + 31, 0); /* io_Error */
                                        trap_put_byte(ctx, ioreq + 8, 7); /* ln_type = NT_REPLYMSG */
                                        if (!hfpd->sd)
-                                               hfpd->sd = scsi_alloc_generic(hfd, UAEDEV_DIR);
+                                               hfpd->sd = scsi_alloc_generic(hfd, UAEDEV_DIR, unit);
                                        hf_log(_T("virtual hardfile_open, unit %d (%d), OK\n"), unit, trap_get_dreg(ctx, 0));
                                        return 0;
                                }
@@ -2462,7 +2463,7 @@ static uae_u32 REGPARAM2 hardfile_open (TrapContext *ctx)
                                        trap_put_byte(ctx, ioreq + 31, 0); /* io_Error */
                                        trap_put_byte(ctx, ioreq + 8, 7); /* ln_type = NT_REPLYMSG */
                                        if (!hfpd->sd)
-                                               hfpd->sd = scsi_alloc_generic(hfd, UAEDEV_HDF);
+                                               hfpd->sd = scsi_alloc_generic(hfd, UAEDEV_HDF, unit);
                                        hf_log(_T("hardfile_open, unit %d (%d), OK\n"), unit, trap_get_dreg(ctx, 0));
                                        return 0;
                                }
diff --git a/ide.cpp b/ide.cpp
index f60a3529002a02a1bedeef168e1dc93e22dae384..a2b68e8c88d1dfa2b1d9c101fe350f841807f145 100644 (file)
--- a/ide.cpp
+++ b/ide.cpp
@@ -1023,7 +1023,7 @@ static void ide_read_sectors (struct ide_hdf *ide, int flags)
                return;
        }
        check_maxtransfer (ide, 1);
-       gui_flicker_led (LED_HD, ide->num, 1);
+       gui_flicker_led (LED_HD, ide->uae_unitnum, 1);
        nsec = get_nsec (ide);
        get_lbachs (ide, &lba, &cyl, &head, &sec);
        if (lba >= ide->max_lba) {
@@ -1061,7 +1061,7 @@ static void ide_write_sectors (struct ide_hdf *ide, int flags)
                return;
        }
        check_maxtransfer (ide, 1);
-       gui_flicker_led (LED_HD, ide->num, 2);
+       gui_flicker_led (LED_HD, ide->uae_unitnum, 2);
        nsec = get_nsec (ide);
        get_lbachs (ide, &lba, &cyl, &head, &sec);
        if (lba >= ide->max_lba) {
@@ -1093,7 +1093,7 @@ static void ide_format_track(struct ide_hdf *ide)
        unsigned int cyl, head, sec;
        uae_u64 lba;
 
-       gui_flicker_led(LED_HD, ide->num, 2);
+       gui_flicker_led(LED_HD, ide->uae_unitnum, 2);
        cyl = (ide->regs.ide_hcyl << 8) | ide->regs.ide_lcyl;
        head = ide->regs.ide_select & 15;
        sec = ide->regs.ide_nsector;
@@ -1131,7 +1131,7 @@ static void ide_do_command (struct ide_hdf *ide, uae_u8 cmd)
        if (ide->atapi) {
 
                if (ide->scsi->device_type == UAEDEV_CD) {
-                       gui_flicker_led(LED_CD, ide->num, 1);
+                       gui_flicker_led(LED_CD, ide->uae_unitnum, 1);
                }
                ide->atapi_drdy = true;
                if (cmd == 0x00) { /* nop */
@@ -1618,7 +1618,7 @@ struct ide_hdf *add_ide_unit (struct ide_hdf **idetable, int max, int ch, struct
        if (ci->type == UAEDEV_CD && ci->device_emu_unit >= 0) {
 
                device_func_init(0);
-               ide->scsi = scsi_alloc_cd(ch, ci->device_emu_unit, true);
+               ide->scsi = scsi_alloc_cd(ch, ci->device_emu_unit, true, ci->uae_unitnum);
                if (!ide->scsi) {
                        write_log(_T("IDE: CD EMU unit %d failed to open\n"), ide->cd_unit_num);
                        return NULL;
@@ -1628,13 +1628,14 @@ struct ide_hdf *add_ide_unit (struct ide_hdf **idetable, int max, int ch, struct
                ide->cd_unit_num = ci->device_emu_unit;
                ide->atapi = true;
                ide->blocksize = 512;
-               gui_flicker_led(LED_CD, ch, -1);
+               ide->uae_unitnum = ci->uae_unitnum;
+               gui_flicker_led(LED_CD, ci->uae_unitnum, -1);
 
                write_log(_T("IDE%d CD %d\n"), ch, ide->cd_unit_num);
 
        } else if (ci->type == UAEDEV_TAPE) {
 
-               ide->scsi = scsi_alloc_tape(ch, ci->rootdir, ci->readonly);
+               ide->scsi = scsi_alloc_tape(ch, ci->rootdir, ci->readonly, ci->uae_unitnum);
                if (!ide->scsi) {
                        write_log(_T("IDE: TAPE EMU unit %d failed to open\n"), ch);
                        return NULL;
@@ -1644,6 +1645,7 @@ struct ide_hdf *add_ide_unit (struct ide_hdf **idetable, int max, int ch, struct
                ide->atapi = true;
                ide->blocksize = 512;
                ide->cd_unit_num = -1;
+               ide->uae_unitnum = ci->uae_unitnum;
 
                write_log(_T("IDE%d TAPE %d\n"), ch, ide->cd_unit_num);
 
@@ -1658,7 +1660,8 @@ struct ide_hdf *add_ide_unit (struct ide_hdf **idetable, int max, int ch, struct
                ide->max_lba = ide->hdhfd.size / ide->blocksize;
                ide->lba48 = (ide->hdhfd.hfd.ci.unit_special_flags & 1) || ide->hdhfd.size >= 128 * (uae_u64)0x40000000 ? 1 : 0;
                ide->lba = true;
-               gui_flicker_led (LED_HD, ch, -1);
+               ide->uae_unitnum = ci->uae_unitnum;
+               gui_flicker_led (LED_HD, ide->uae_unitnum, -1);
                ide->cd_unit_num = -1;
                ide->media_type = ci->controller_media_type;
                ide->ata_level = ci->unit_feature_level;
index 7d03876ebf79be909272a90f7098c51d995a0da7..34aa6ea7a64d209874e019cd3ae036b6598d56fa 100644 (file)
@@ -99,6 +99,7 @@ struct ide_hdf
        int ide_drv;
        int media_type;
        bool mode_8bit;
+       int uae_unitnum;
 
        bool atapi;
        bool atapi_drdy;
index 2cec56397f0cdb6a760185844a59ca321249e86d..77fef87d242f3d49bc3efc749d15c9b9f812c85e 100644 (file)
@@ -228,6 +228,7 @@ struct uaedev_config_info {
        bool inject_icons;
        int badblock_num;
        struct uaedev_badblock badblocks[MAX_UAEDEV_BADBLOCKS];
+       int uae_unitnum; // mountunit nr
 };
 
 struct uaedev_config_data
index a4b428bf990729728773ff449fc2ed90dfbc3e88..6279bf5d301cb407776aa05b2e2fdf919a897a51 100644 (file)
@@ -55,12 +55,13 @@ struct scsi_data
        int cd_emu_unit;
        bool atapi;
        uae_u32 unit_attention;
+       int uae_unitnum;
 };
 
-extern struct scsi_data *scsi_alloc_generic(struct hardfiledata *hfd, int type);
-extern struct scsi_data *scsi_alloc_hd(int, struct hd_hardfiledata*);
-extern struct scsi_data *scsi_alloc_cd(int, int, bool);
-extern struct scsi_data *scsi_alloc_tape(int id, const TCHAR *tape_directory, bool readonly);
+extern struct scsi_data *scsi_alloc_generic(struct hardfiledata *hfd, int type, int);
+extern struct scsi_data *scsi_alloc_hd(int, struct hd_hardfiledata*, int);
+extern struct scsi_data *scsi_alloc_cd(int, int, bool, int);
+extern struct scsi_data *scsi_alloc_tape(int id, const TCHAR *tape_directory, bool readonly, int);
 extern struct scsi_data *scsi_alloc_native(int, int);
 extern void scsi_free(struct scsi_data*);
 extern void scsi_reset(void);
index 1362f3eac6b263cb60b8f53b835f1ce9a9e72209..0a0f56bafe87d014ce1fefe20e20626545c4acb7 100644 (file)
@@ -673,7 +673,7 @@ int32_t scsiesp_req_enqueue(SCSIRequest *req)
        struct scsi_data *sd = (struct scsi_data*)req->dev->handle;
 
        if (sd->device_type == UAEDEV_CD)
-               gui_flicker_led (LED_CD, sd->id, 1);
+               gui_flicker_led (LED_CD, sd->uae_unitnum, 1);
 
        sd->data_len = 0;
        scsi_start_transfer(sd);
@@ -2210,15 +2210,16 @@ void ncr9x_init(void)
 {
 }
 
-static void allocscsidevice(struct ncr9x_state *ncr, int ch, struct scsi_data *handle)
+static void allocscsidevice(struct ncr9x_state *ncr, int ch, struct scsi_data *handle, int uae_unitnum)
 {
        handle->privdata = ncr;
        ncr->scsid[ch] = xcalloc (SCSIDevice, 1);
        ncr->scsid[ch]->id = ch;
        ncr->scsid[ch]->handle = handle;
+       handle->uae_unitnum = uae_unitnum;
 }
 
-static void add_ncr_scsi_hd(struct ncr9x_state *ncr, int ch, struct hd_hardfiledata *hfd, struct uaedev_config_info *ci)
+static void add_ncr_scsi_hd(struct ncr9x_state *ncr, int ch, struct hd_hardfiledata *hfd, struct uaedev_config_info *ci, int uae_unitnum)
 {
        struct scsi_data *handle = NULL;
 
@@ -2226,11 +2227,11 @@ static void add_ncr_scsi_hd(struct ncr9x_state *ncr, int ch, struct hd_hardfiled
        ncr->scsid[ch] = NULL;
        if (!add_scsi_hd(&handle, ch, hfd, ci))
                return;
-       allocscsidevice(ncr, ch, handle);
+       allocscsidevice(ncr, ch, handle, uae_unitnum);
        ncr->enabled = true;
 }
 
-static void add_ncr_scsi_cd(struct ncr9x_state *ncr, int ch, int unitnum)
+static void add_ncr_scsi_cd(struct ncr9x_state *ncr, int ch, int unitnum, int uae_unitnum)
 {
        struct scsi_data *handle = NULL;
 
@@ -2238,11 +2239,11 @@ static void add_ncr_scsi_cd(struct ncr9x_state *ncr, int ch, int unitnum)
        ncr->scsid[ch] = NULL;
        if (!add_scsi_cd(&handle, ch, unitnum))
                return;
-       allocscsidevice(ncr, ch, handle);
+       allocscsidevice(ncr, ch, handle, uae_unitnum);
        ncr->enabled = true;
 }
 
-static void add_ncr_scsi_tape(struct ncr9x_state *ncr, int ch, const TCHAR *tape_directory, bool readonly)
+static void add_ncr_scsi_tape(struct ncr9x_state *ncr, int ch, const TCHAR *tape_directory, bool readonly, int uae_unitnum)
 {
        struct scsi_data *handle = NULL;
 
@@ -2250,7 +2251,7 @@ static void add_ncr_scsi_tape(struct ncr9x_state *ncr, int ch, const TCHAR *tape
        ncr->scsid[ch] = NULL;
        if (!add_scsi_tape(&handle, ch, tape_directory, readonly))
                return;
-       allocscsidevice(ncr, ch, handle);
+       allocscsidevice(ncr, ch, handle, uae_unitnum);
        ncr->enabled = true;
 }
 
@@ -2259,11 +2260,11 @@ static void ncr9x_add_scsi_unit(struct ncr9x_state **ncrp, int ch, struct uaedev
        struct ncr9x_state *ncr = allocscsi(ncrp, rc, ch);
        if (ch >= 0 && ncr) {
                if (ci->type == UAEDEV_CD)
-                       add_ncr_scsi_cd (ncr, ch, ci->device_emu_unit);
+                       add_ncr_scsi_cd (ncr, ch, ci->device_emu_unit, ci->uae_unitnum);
                else if (ci->type == UAEDEV_TAPE)
-                       add_ncr_scsi_tape (ncr, ch, ci->rootdir, ci->readonly);
+                       add_ncr_scsi_tape (ncr, ch, ci->rootdir, ci->readonly, ci->uae_unitnum);
                else if (ci->type == UAEDEV_HDF)
-                       add_ncr_scsi_hd (ncr, ch, NULL, ci);
+                       add_ncr_scsi_hd (ncr, ch, NULL, ci, ci->uae_unitnum);
        }
 }
 
index bcb08319e78f120546757efbf0a9e2012c7447c1..5b021c00590b22ddbe530b149277dd7374c5bb75 100644 (file)
@@ -232,7 +232,7 @@ int32_t scsi_req_enqueue(SCSIRequest *req)
        struct scsi_data *sd = (struct scsi_data*)req->dev->handle;
 
        if (sd->device_type == UAEDEV_CD)
-               gui_flicker_led (LED_CD, sd->id, 1);
+               gui_flicker_led (LED_CD, sd->uae_unitnum, 1);
 
        sd->data_len = 0;
        scsi_start_transfer(sd);
@@ -326,7 +326,7 @@ int32_t scsi710_req_enqueue(SCSIRequest *req)
        struct scsi_data *sd = (struct scsi_data*)req->dev->handle;
 
        if (sd->device_type == UAEDEV_CD)
-               gui_flicker_led (LED_CD, sd->id, 1);
+               gui_flicker_led (LED_CD, sd->uae_unitnum, 1);
 
        sd->data_len = 0;
        scsi_start_transfer (sd);
@@ -1045,15 +1045,16 @@ void ncr_reset(void)
        }
 }
 
-static void allocscsidevice(struct ncr_state *ncr, int ch, struct scsi_data *handle)
+static void allocscsidevice(struct ncr_state *ncr, int ch, struct scsi_data *handle, int uae_unitnum)
 {
        handle->privdata = ncr;
        ncr->scsid[ch] = xcalloc (SCSIDevice, 1);
        ncr->scsid[ch]->id = ch;
        ncr->scsid[ch]->handle = handle;
+       handle->uae_unitnum = uae_unitnum;
 }
 
-static void add_ncr_scsi_hd (struct ncr_state *ncr, int ch, struct hd_hardfiledata *hfd, struct uaedev_config_info *ci)
+static void add_ncr_scsi_hd (struct ncr_state *ncr, int ch, struct hd_hardfiledata *hfd, struct uaedev_config_info *ci, int uae_unitnum)
 {
        struct scsi_data *handle = NULL;
 
@@ -1061,11 +1062,11 @@ static void add_ncr_scsi_hd (struct ncr_state *ncr, int ch, struct hd_hardfileda
        ncr->scsid[ch] = NULL;
        if (!add_scsi_hd(&handle, ch, hfd, ci))
                return;
-       allocscsidevice(ncr, ch, handle);
+       allocscsidevice(ncr, ch, handle, uae_unitnum);
        ncr->enabled = true;
 }
 
-static void add_ncr_scsi_cd (struct ncr_state *ncr, int ch, int unitnum)
+static void add_ncr_scsi_cd (struct ncr_state *ncr, int ch, int unitnum, int uae_unitnum)
 {
        struct scsi_data *handle = NULL;
 
@@ -1073,11 +1074,11 @@ static void add_ncr_scsi_cd (struct ncr_state *ncr, int ch, int unitnum)
        ncr->scsid[ch] = NULL;
        if (!add_scsi_cd(&handle, ch, unitnum))
                return;
-       allocscsidevice(ncr, ch, handle);
+       allocscsidevice(ncr, ch, handle, uae_unitnum);
        ncr->enabled = true;
 }
 
-static void add_ncr_scsi_tape (struct ncr_state *ncr, int ch, const TCHAR *tape_directory, bool readonly)
+static void add_ncr_scsi_tape (struct ncr_state *ncr, int ch, const TCHAR *tape_directory, bool readonly, int uae_unitnum)
 {
        struct scsi_data *handle = NULL;
 
@@ -1085,7 +1086,7 @@ static void add_ncr_scsi_tape (struct ncr_state *ncr, int ch, const TCHAR *tape_
        ncr->scsid[ch] = NULL;
        if (!add_scsi_tape(&handle, ch, tape_directory, readonly))
                return;
-       allocscsidevice(ncr, ch, handle);
+       allocscsidevice(ncr, ch, handle, uae_unitnum);
        ncr->enabled = true;
 }
 
@@ -1098,11 +1099,11 @@ static void ncr_add_scsi_unit(struct ncr_state **ncrp, int ch, struct uaedev_con
        ncr_init_board(ncr);
        if (ch >= 0 && ncr) {
                if (ci->type == UAEDEV_CD)
-                       add_ncr_scsi_cd (ncr, ch, ci->device_emu_unit);
+                       add_ncr_scsi_cd (ncr, ch, ci->device_emu_unit, ci->uae_unitnum);
                else if (ci->type == UAEDEV_TAPE)
-                       add_ncr_scsi_tape (ncr, ch, ci->rootdir, ci->readonly);
+                       add_ncr_scsi_tape (ncr, ch, ci->rootdir, ci->readonly, ci->uae_unitnum);
                else if (ci->type == UAEDEV_HDF)
-                       add_ncr_scsi_hd (ncr, ch, NULL, ci);
+                       add_ncr_scsi_hd (ncr, ch, NULL, ci, ci->uae_unitnum);
        }
 }
 
index 9566d81ee75932f26b1c080c22d921087c411b8d..12ae40f45d4221688c4e5f31c893273e7cc75763 100644 (file)
@@ -1562,7 +1562,7 @@ static bool ishd(int n)
        } else if (uci->ci.controller_type >= HD_CONTROLLER_TYPE_SCSI_FIRST && uci->ci.controller_type <= HD_CONTROLLER_TYPE_SCSI_LAST) {
                num = uci->ci.controller_unit;
        }
-       return num >= 0;
+       return num >= 0 && uci->ci.type == UAEDEV_HDF;
 }
 
 void rp_fixup_options (struct uae_prefs *p)
@@ -1662,6 +1662,8 @@ void rp_fixup_options (struct uae_prefs *p)
        for (i = 0; i <= 4; i++)
                rp_update_leds (i, 0, -1, 0);
        set_config_changed ();
+
+       write_log(_T("rp_fixup_options end\n"));
 }
 
 static void rp_device_writeprotect (int dev, int num, bool writeprotected)
index 9d0a5c0bfadb4c9074da27a1b5a2030b2b8e9d82..f119825864c4caea76e8beac23e0cbbd6cf1c2d7 100644 (file)
@@ -20926,10 +20926,11 @@ static void gui_flicker_led2 (int led, int unitnum, int status)
        }
 #ifdef RETROPLATFORM
        if (unitnum >= 0) {
-               if (led == LED_HD)
-                       rp_hd_activity (unitnum, status ? 1 : 0, status == 2 ? 1 : 0);
-               else if (led == LED_CD)
-                       rp_cd_activity (unitnum, status);
+               if (led == LED_HD) {
+                       rp_hd_activity(unitnum, status ? 1 : 0, status == 2 ? 1 : 0);
+               } else if (led == LED_CD) {
+                       rp_cd_activity(unitnum, status);
+               }
        }
 #endif
        *p = status;
index c783f3ce1cf9df2c8e706217800be61dea7a9c31..d3c4c387d5311c3ed767768662a5cee78c81f93a 100644 (file)
--- a/scsi.cpp
+++ b/scsi.cpp
@@ -503,7 +503,7 @@ static void allocscsibuf(struct scsi_data *sd)
        sd->buffer = xcalloc(uae_u8, sd->buffer_size);
 }
 
-struct scsi_data *scsi_alloc_generic(struct hardfiledata *hfd, int type)
+struct scsi_data *scsi_alloc_generic(struct hardfiledata *hfd, int type, int uae_unitnum)
 {
        struct scsi_data *sd = xcalloc(struct scsi_data, 1);
        sd->hfd = hfd;
@@ -512,11 +512,12 @@ struct scsi_data *scsi_alloc_generic(struct hardfiledata *hfd, int type)
        sd->cd_emu_unit = -1;
        sd->blocksize = hfd->ci.blocksize;
        sd->device_type = type;
+       sd->uae_unitnum = uae_unitnum;
        allocscsibuf(sd);
        return sd;
 }
 
-struct scsi_data *scsi_alloc_hd(int id, struct hd_hardfiledata *hfd)
+struct scsi_data *scsi_alloc_hd(int id, struct hd_hardfiledata *hfd, int uae_unitnum)
 {
        struct scsi_data *sd = xcalloc (struct scsi_data, 1);
        sd->hdhfd = hfd;
@@ -526,11 +527,12 @@ struct scsi_data *scsi_alloc_hd(int id, struct hd_hardfiledata *hfd)
        sd->cd_emu_unit = -1;
        sd->blocksize = hfd->hfd.ci.blocksize;
        sd->device_type = UAEDEV_HDF;
+       sd->uae_unitnum = uae_unitnum;
        allocscsibuf(sd);
        return sd;
 }
 
-struct scsi_data *scsi_alloc_cd(int id, int unitnum, bool atapi)
+struct scsi_data *scsi_alloc_cd(int id, int unitnum, bool atapi, int uae_unitnum)
 {
        struct scsi_data *sd;
        if (!sys_command_open (unitnum)) {
@@ -544,11 +546,12 @@ struct scsi_data *scsi_alloc_cd(int id, int unitnum, bool atapi)
        sd->atapi = atapi;
        sd->blocksize = 2048;
        sd->device_type = UAEDEV_CD;
+       sd->uae_unitnum = uae_unitnum;
        allocscsibuf(sd);
        return sd;
 }
 
-struct scsi_data *scsi_alloc_tape(int id, const TCHAR *tape_directory, bool readonly)
+struct scsi_data *scsi_alloc_tape(int id, const TCHAR *tape_directory, bool readonly, int uae_unitnum)
 {
        struct scsi_data_tape *tape;
        tape = tape_alloc (id, tape_directory, readonly);
@@ -561,6 +564,7 @@ struct scsi_data *scsi_alloc_tape(int id, const TCHAR *tape_directory, bool read
        sd->blocksize = tape->blocksize;
        sd->tape = tape;
        sd->device_type = UAEDEV_TAPE;
+       sd->uae_unitnum = uae_unitnum;
        allocscsibuf(sd);
        return sd;
 }
@@ -670,7 +674,7 @@ int add_scsi_hd (struct scsi_data **sd, int ch, struct hd_hardfiledata *hfd, str
        if (!hdf_hd_open (hfd))
                return 0;
        hfd->ansi_version = ci->unit_feature_level + 1;
-       *sd = scsi_alloc_hd (ch, hfd);
+       *sd = scsi_alloc_hd (ch, hfd, ci->uae_unitnum);
        return *sd ? 1 : 0;
 }
 
@@ -678,14 +682,14 @@ int add_scsi_cd (struct scsi_data **sd, int ch, int unitnum)
 {
        device_func_init (0);
        free_scsi (*sd);
-       *sd = scsi_alloc_cd (ch, unitnum, false);
+       *sd = scsi_alloc_cd (ch, unitnum, false, unitnum);
        return *sd ? 1 : 0;
 }
 
 int add_scsi_tape (struct scsi_data **sd, int ch, const TCHAR *tape_directory, bool readonly)
 {
        free_scsi (*sd);
-       *sd = scsi_alloc_tape (ch, tape_directory, readonly);
+       *sd = scsi_alloc_tape (ch, tape_directory, readonly, ch);
        return *sd ? 1 : 0;
 }