static uae_u32 REGPARAM2 dev_open_2 (TrapContext *context, int type) { uaecptr ioreq = m68k_areg (&context->regs, 1); uae_u32 unit = m68k_dreg (&context->regs, 0); uae_u32 flags = m68k_dreg (&context->regs, 1); struct devstruct *dev = getdevstruct (unit); struct priv_devstruct *pdev = 0; int i; if (log_scsi) write_log ("opening %s:%d ioreq=%08.8X\n", getdevname (type), unit, ioreq); if (!dev) return openfail (ioreq, 32); /* badunitnum */ if (!dev->opencnt) { for (i = 0; i < MAX_OPEN_DEVICES; i++) { pdev = &pdevst[i]; if (pdev->inuse == 0) break; } if (type == UAEDEV_SCSI_ID && sys_command_open (DF_SCSI, dev->unitnum)) { pdev->scsi = 1; pdev->mode = DF_SCSI; } if (type == UAEDEV_DISK_ID && sys_command_open (DF_IOCTL, dev->unitnum)) { pdev->ioctl = 1; pdev->mode = DF_IOCTL; } if (!pdev->scsi && !pdev->ioctl) return openfail (ioreq, -1); pdev->type = type; pdev->unit = unit; pdev->flags = flags; pdev->inuse = 1; put_long (ioreq + 24, pdev - pdevst); start_thread (dev); } else { for (i = 0; i < MAX_OPEN_DEVICES; i++) { pdev = &pdevst[i]; if (pdev->inuse && pdev->unit == (int)unit) break; } if (i == MAX_OPEN_DEVICES) return openfail (ioreq, -1); put_long (ioreq + 24, pdev - pdevst); } dev->opencnt++; put_word (m68k_areg (&context->regs, 6) + 32, get_word (m68k_areg (&context->regs, 6) + 32) + 1); put_byte (ioreq + 31, 0); put_byte (ioreq + 8, 7); return 0; }
static void dev_reset (void) { int i, j; struct devstruct *dev; struct device_info *discsi, discsi2; int unitnum = 0; device_func_init (DEVICE_TYPE_SCSI); dev_exit(); for (i = 0; i < MAX_OPEN_DEVICES; i++) memset (&pdevst[i], 0, sizeof (struct priv_devstruct)); i = j = 0; while (i < MAX_TOTAL_DEVICES) { dev = &devst[i]; discsi = 0; if (sys_command_open (DF_SCSI, j)) { discsi = sys_command_info (DF_SCSI, j, &discsi2); sys_command_close (DF_SCSI, j); } if (discsi) { dev->unitnum = j; dev->allow_scsi = 1; dev->drivetype = discsi->type; memcpy (&dev->di, discsi, sizeof (struct device_info)); if (discsi->type == INQ_ROMD) dev->iscd = 1; } i++; j++; } unitnum = 0; for (i = 0; i < MAX_TOTAL_DEVICES; i++) { dev = &devst[i]; if (dev->unitnum >= 0 && dev->iscd) { dev->aunit = unitnum; unitnum++; } } if (unitnum == 0) unitnum = 1; for (i = 0; i < MAX_TOTAL_DEVICES; i++) { dev = &devst[i]; if (dev->unitnum >= 0) { if (!dev->iscd) { dev->aunit = unitnum; unitnum++; } write_log ("%s = %s:%d\n", dev->di.label, UAEDEV_SCSI, dev->aunit); } } }
struct scsi_data *scsi_alloc_native(int id, int nativeunit) { struct scsi_data *sd; if (!sys_command_open (nativeunit)) { write_log (_T("SCSI: native scsi unit %d failed to open\n"), nativeunit); return NULL; } sd = xcalloc (struct scsi_data, 1); sd->id = id; sd->nativescsiunit = nativeunit; return sd; }
struct scsi_data *scsi_alloc_native(int id, int nativeunit) { struct scsi_data *sd; if (!sys_command_open (nativeunit)) { write_log (_T("SCSI: native scsi unit %d failed to open\n"), nativeunit); return NULL; } sd = xcalloc (struct scsi_data, 1); sd->id = id; sd->nativescsiunit = nativeunit; sd->cd_emu_unit = -1; sd->blocksize = 2048; sd->device_type = 0; return sd; }
struct scsi_data *scsi_alloc_cd(int id, int unitnum, bool atapi) { struct scsi_data *sd; if (!sys_command_open (unitnum)) { write_log (_T("SCSI: CD EMU scsi unit %d failed to open\n"), unitnum); return NULL; } sd = xcalloc (struct scsi_data, 1); sd->id = id; sd->cd_emu_unit = unitnum; sd->nativescsiunit = -1; sd->atapi = atapi; sd->blocksize = 2048; return sd; }