home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Special 6 / Sonderheft_6-96.iso / pd / disktools / scsi_list / source / scsi.c < prev    next >
C/C++ Source or Header  |  1996-11-03  |  33KB  |  941 lines

  1. /*
  2.  * SCSI.C - Show SCSI Devices
  3.  *
  4.  *   $VER: SCSI.C 1.3 (5.5.96)
  5.  *
  6.  * (c) Copyright 1996 Richard Sellens.  All rights reserved.
  7.  *
  8.  * This software is provided as-is and is subject to change; no warranties
  9.  * are made.  All use is at your own risk.  No liability or responsibility
  10.  * is assumed.
  11.  *
  12.  * Release  Date     Change
  13.  *
  14.  * 1.0      02/02/96 Initial Program
  15.  * 1.1      31/03/96 Made SCSI Device string area longer
  16.  * 1.2      07/04/96 Added ability to select unit from List for display,
  17.  *                   Added Locale support for most strings 
  18.  * 1.3      05/05/96 Added ability to select controller device,
  19.  *                   Added Locale support for remaining strings 
  20.  * 
  21.  */
  22.  
  23.  
  24. /*------------------------------------------------------------------------*/
  25.  
  26. #define INTUITION_IOBSOLETE_H
  27. #define CATCOMP_NUMBERS
  28. #define CATCOMP_BLOCK
  29. #define CATCOMP_CODE
  30. #define REG(x) register __ ## x
  31. #define ASM    __asm
  32. #define SAVEDS __saveds
  33.  
  34. #include <dos/dos.h>
  35. #include <exec/devices.h> 
  36. #include <exec/errors.h> 
  37. #include <exec/execbase.h>
  38. #include <exec/memory.h>
  39. #include <exec/types.h>
  40. #include <graphics/gfxmacros.h>
  41. #include <libraries/mui.h>
  42. #include <libraries/locale.h>
  43. #include <workbench/workbench.h>
  44.  
  45. #include <clib/alib_protos.h>
  46. #include <clib/asl_protos.h>
  47. #include <clib/dos_protos.h>
  48. #include <clib/exec_protos.h>
  49. #include <clib/graphics_protos.h>
  50. #include <clib/icon_protos.h>
  51. #include <clib/intuition_protos.h>
  52. #include <clib/locale_protos.h>
  53. #include <clib/muimaster_protos.h>
  54. #include <clib/utility_protos.h>
  55.  
  56. #include <stdlib.h>
  57. #include <string.h>
  58. #include <stdio.h>
  59.  
  60. #include <pragmas/asl_pragmas.h>
  61. #include <pragmas/dos_pragmas.h>
  62. #include <pragmas/exec_pragmas.h>
  63. #include <pragmas/graphics_pragmas.h>
  64. #include <pragmas/icon_pragmas.h>
  65. #include <pragmas/intuition_pragmas.h>
  66. #include <pragmas/locale_pragmas.h>
  67. #include <pragmas/muimaster_pragmas.h>
  68. #include <pragmas/utility_pragmas.h>
  69.  
  70. #include "Scsi_Cmd.h"
  71.  
  72. /*------------------------------------------------------------------------*/
  73.  
  74. void    Main(int argc, char **argv);
  75. void    BailOut(APTR app, char *str);
  76. void    GetDevList(int argc, char **argv);
  77. void    gettooltypes(struct WBArg *);
  78. BOOL    InitClasses(void);
  79. void    ExitClasses(void);
  80. ULONG   ScsiList_New(struct IClass *, Object *, struct opSet *);
  81. ULONG   ScsiList_Cleanup(struct IClass *, Object *, Msg);
  82. ULONG   ScsiList_Setup(struct IClass *, Object *, Msg);
  83. void    ShowSCSI(char *);
  84. void    ShowScsi_exit(long code, char *);
  85. void    ListDevices(char *);
  86. UBYTE   *id2string(int ,IDTOSTRING * idtable);
  87. STRPTR  GetString(struct LocaleInfo *li, LONG stringNum);
  88. STRPTR  SetDeviceType(int id);
  89.  
  90. /*------------------------------------------------------------------------*/
  91.  
  92. extern  struct  Library         *DOSBase;
  93. extern  struct  ExecBase        *SysBase;
  94. extern  struct  GfxBase         *GfxBase;
  95. extern  struct  IntuitionBase   *IntuitionBase;
  96. struct  Library                 *LocaleBase;
  97. struct  Library                 *IconBase;
  98. extern  struct  Library         *UtilityBase;
  99. struct  Library                 *MUIMasterBase  = NULL;
  100.  
  101. /*------------------------------------------------------------------------*/
  102.  
  103. #include "Scsi_Locale.h" 
  104.  
  105. /*------------------------------------------------------------------------*/
  106.  
  107. #define USE_CD_ROM_BODY
  108. #define USE_CD_ROM_COLORS
  109. #include "CD_Rom.h"
  110.  
  111. #define USE_HARD_DRIVE_BODY
  112. #define USE_HARD_DRIVE_COLORS
  113. #include "Hard_Drive.h"
  114.  
  115.  
  116. #define USE_REMOVE_DRIVE_BODY
  117. #define USE_REMOVE_DRIVE_COLORS
  118. #include "Remove_Drive.h"
  119.  
  120.  
  121. #define USE_SCANNER_BODY
  122. #define USE_SCANNER_COLORS
  123. #include "Scanner.h"
  124.  
  125. #define USE_NULL_BODY
  126. #define USE_NULL_COLORS
  127. #include "Null.h"
  128.  
  129. #define USE_NOUNIT_BODY
  130. #define USE_NOUNIT_COLORS
  131. #include "NoUnit.h"
  132.  
  133. #define USE_SCSI_BODY
  134. #define USE_SCSI_COLORS
  135. #include "ScsiImage.h"
  136.  
  137. /*------------------------------------------------------------------------*/
  138.  
  139. #ifndef MAKE_ID
  140. #define MAKE_ID(a,b,c,d) ((ULONG) (a)<<24 | (ULONG) (b)<<16 | (ULONG) (c)<<8 | (ULONG) (d))
  141. #endif
  142.  
  143. #define MAKE_PAGE(occur) Child, VGroup, \ 
  144.                             MUIA_Weight, 120, \
  145.                             Child, ColGroup(2), GroupFrame, \
  146.                                 Child, Label1(GetString(&li, MSG_Vendor)), \
  147.                                 Child, Sl_Vendor[occur] = TextObject, \
  148.                                     TextFrame, \
  149.                                     MUIA_Text_SetMax, FALSE, \
  150.                                 End, \
  151.                                 Child, Label1(GetString(&li, MSG_Product)), \
  152.                                 Child, Sl_Product[occur] = TextObject, \ 
  153.                                     TextFrame, \
  154.                                     MUIA_Text_SetMax, FALSE, \
  155.                                 End, \
  156.                                 Child, Label1(GetString(&li, MSG_Revision)), \
  157.                                 Child, Sl_Revision[occur] = TextObject, \
  158.                                     TextFrame, \
  159.                                     MUIA_Text_SetMax, FALSE, \
  160.                                 End, \
  161.                                 Child, Label1(GetString(&li, MSG_Device_Type)), \
  162.                                 Child, Sl_DevType[occur] = TextObject, \
  163.                                     TextFrame, \
  164.                                     MUIA_Text_SetMax, FALSE, \
  165.                                 End, \
  166.                                 Child, Label1(GetString(&li, MSG_Standard)), \                                    
  167.                                 Child, Sl_Standard[occur] = TextObject, \
  168.                                     TextFrame, \
  169.                                     MUIA_Text_SetMax, FALSE, \
  170.                                 End, \
  171.                             End, \ 
  172.                             Child, ColGroup(4), GroupFrame, \
  173.                                 Child, Label1(GetString(&li, MSG_Removable)), \
  174.                                 Child, Sl_Removable[occur] = ImageObject, \
  175.                                     MUIA_InputMode, MUIV_InputMode_None, \
  176.                                     MUIA_Selected, FALSE, \
  177.                                     MUIA_Background, MUII_ButtonBack,\
  178.                                     MUIA_Image_Spec, MUII_CheckMark, \
  179.                                 End, \
  180.                                 Child, Label1(GetString(&li, MSG_Rel_Addr)), \
  181.                                 Child, Sl_Rel_Addr[occur] = ImageObject, \
  182.                                     MUIA_InputMode, MUIV_InputMode_None, \
  183.                                     MUIA_Selected, FALSE, \
  184.                                     MUIA_Background, MUII_ButtonBack,\
  185.                                     MUIA_Image_Spec, MUII_CheckMark, \
  186.                                 End, \
  187.                                 Child, Label1(GetString(&li, MSG_16_Wide)), \
  188.                                 Child, Sl_16Wide_Addr[occur] = ImageObject, \
  189.                                     MUIA_InputMode, MUIV_InputMode_None, \
  190.                                     MUIA_Selected, FALSE, \
  191.                                     MUIA_Background, MUII_ButtonBack,\
  192.                                     MUIA_Image_Spec, MUII_CheckMark, \
  193.                                 End, \
  194.                                 Child, Label1(GetString(&li, MSG_32_Wide)), \
  195.                                 Child, Sl_32Wide_Addr[occur] = ImageObject, \
  196.                                     MUIA_InputMode, MUIV_InputMode_None, \
  197.                                     MUIA_Selected, FALSE, \
  198.                                     MUIA_Background, MUII_ButtonBack,\
  199.                                     MUIA_Image_Spec, MUII_CheckMark, \
  200.                                 End, \
  201.                             End, \
  202.                         End, 
  203.  
  204.  
  205. /*------------------------------------------------------------------------*/
  206.  
  207. struct  MUI_CustomClass         *CL_ScsiList;
  208. struct  LocaleInfo              li;
  209.  
  210. APTR    app;
  211. APTR    win1;
  212. APTR    aboutwin;
  213. enum    { ID_OK = 1, ID_SELECT, ID_File, ID_Dev };
  214. static  APTR    lv_tools;
  215. static  APTR    lv_scsi;
  216. static  APTR    tx_device;
  217. static  APTR    pg_group;
  218. static  APTR    cycle;
  219. char    *DevList[20];
  220. char    *test;
  221. char    *scsi_name = "scsi";
  222. struct  Node    *DeviceLibNode;
  223. int     totitem = 0;
  224. int     i       = 0;
  225. BOOL    FromWb              = FALSE;
  226. int     scsiunit = 7;
  227. struct  ScsiList_Data
  228. {
  229.     Object  *SL_OImage_CD;
  230.     Object  *SL_OImage_HD;
  231.     Object  *SL_OImage_RD;
  232.     Object  *SL_OImage_SC;
  233.     Object  *SL_OImage_NO;
  234.     Object  *SL_OImage_NL;
  235.     APTR    SL_Image_CD;
  236.     APTR    SL_Image_HD;
  237.     APTR    SL_Image_RD;
  238.     APTR    SL_Image_SC;
  239.     APTR    SL_Image_NO;
  240.     APTR    SL_Image_NL;
  241.     struct  Hook    DisplayHook;
  242. };
  243. struct  ScsiUnitData
  244. {
  245.     int     SUD_Unit;           /*  Unit Id Number                        */
  246.     char    *SUD_Vendor;        /*  Vendor Name                           */
  247.     char    *SUD_Product;       /*  Product Name                          */
  248.     char    *SUD_Revision;      /*  Product Revision Id                   */
  249.     int     SUD_Dev_type;       /*  Type of Device                        */
  250.     int     SUD_Standard;       /*  Device Standard                       */
  251.     BOOL    SUD_Removable;      /*  Removable Media ?                     */
  252.     BOOL    SUD_Rel_Addr;       /*  Relative Addressing ?                 */
  253.     BOOL    SUD_16Wide_Addr;    /*  16 Bit Wide Addressing ?              */
  254.     BOOL    SUD_32Wide_Addr;    /*  16 Bit Wide Addressing ?              */
  255. };
  256. struct  Device      *scsi_dev;
  257. struct  MsgPort     *replymp;
  258. struct  IOStdReq    *scsi_req;
  259. struct  SCSICmd     scsi_cmd;
  260. struct  Node        *DeviceLibNode;
  261. UBYTE               *scsi_sense;
  262. UBYTE               *scsi_data      = NULL;
  263. static  UBYTE       cmd[] = { SCSI_CMD_INQ, 0, 0, 0, 252, 0, };
  264. static  char        *Units[] = { NULL, "0", "1", "2", "3", "4", "5", "6", NULL };
  265. static  APTR        Sl_Product[8];
  266. static  APTR        Sl_Vendor[8];
  267. static  APTR        Sl_Revision[8];
  268. static  APTR        Sl_DevType[8];
  269. static  APTR        Sl_Standard[8];
  270. static  APTR        Sl_Removable[8];
  271. static  APTR        Sl_Rel_Addr[8];
  272. static  APTR        Sl_16Wide_Addr[8];
  273. static  APTR        Sl_32Wide_Addr[8];
  274.  
  275. /*------------------------------------------------------------------------*/
  276.  
  277. ULONG __stdargs DoSuperNew(struct IClass *cl,Object *obj,ULONG tag1,...)
  278. {
  279.     return(DoSuperMethod(cl,obj,OM_NEW,&tag1,NULL));
  280. }
  281.  
  282. /*------------------------------------------------------------------------*/
  283.  
  284. void main(int argc, char **argv)
  285. {
  286.     ULONG   signals;
  287.     BOOL    running = TRUE;
  288.     ULONG   entry       = 0;
  289.     ULONG   c_pos;
  290.  
  291.     if (!(li.li_LocaleBase = LocaleBase = OpenLibrary("locale.library",0L)))
  292.         BailOut(NULL, "Unable to open locale.library");
  293.     
  294.     if ((IconBase = OpenLibrary("icon.library",0L)) == NULL)
  295.         BailOut(NULL, GetString(&li, MSG_Unable_to_Open_icon));
  296.     
  297.     GetDevList(argc,argv);
  298.  
  299.     li.li_Catalog = OpenCatalog(NULL, "Scsi_List.catalog", TAG_DONE);
  300.     
  301.     if (!(MUIMasterBase = OpenLibrary(MUIMASTER_NAME,MUIMASTER_VMIN)))
  302.         BailOut(NULL, GetString(&li, MSG_Unable_to_Open_MUI));
  303.  
  304.     Units[0] = (char *)AllocMem(strlen(GetString(&li, MSG_List)) + 1, MEMF_ANY|MEMF_CLEAR);
  305.     strcpy(Units[0], GetString(&li, MSG_List));
  306.  
  307.     if (!(InitClasses()))
  308.         BailOut(NULL, GetString(&li, MSG_Unable_to_Create_Cust_Class));
  309.         
  310.     app = ApplicationObject,
  311.             MUIA_Application_Title,         "Scsi Identifier",            
  312.             MUIA_Application_Version,       "$VER: Scsi_List 1.3 (5.5.96)",
  313.             MUIA_Application_Copyright,     "@1996, Richard Sellens",
  314.             MUIA_Application_Author,        "Richard Sellens",
  315.             MUIA_Application_Description,   "Show SCSI Devices",
  316.             MUIA_Application_Base,          "SCSI",
  317.             
  318.             MUIA_Application_Window, win1 = WindowObject,
  319.                 MUIA_Window_Title, "Scsi Identifier",
  320.                 MUIA_Window_ID   , MAKE_ID('S','C','S','I'),
  321.  
  322.                 WindowContents, VGroup,
  323.                     Child, HGroup, GroupFrame,
  324.                         MUIA_Weight, 100,
  325.                         Child, BodychunkObject, MUIA_FixWidth, SCSI_WIDTH,
  326.                                  MUIA_FixHeight, SCSI_HEIGHT,
  327.                                  MUIA_Bitmap_Width, SCSI_WIDTH,
  328.                                  MUIA_Bitmap_Height, SCSI_HEIGHT,
  329.                                  MUIA_Bodychunk_Depth, SCSI_DEPTH,
  330.                                  MUIA_Bodychunk_Body, (UBYTE *)Scsi_body,
  331.                                  MUIA_Bodychunk_Compression, SCSI_COMPRESSION,
  332.                                  MUIA_Bodychunk_Masking, SCSI_MASKING,
  333.                                  MUIA_Bitmap_SourceColors, (ULONG *)Scsi_colors,
  334.                                  MUIA_Bitmap_Transparent, 0,
  335.                         End,
  336.                         Child, ColGroup(2),
  337.                             Child, Label1(GetString(&li, MSG_Device)),
  338.                             Child, cycle = Cycle(DevList),
  339.                         End,
  340.                     End,  
  341.                     Child, pg_group = RegisterGroup(Units),
  342.                         MUIA_Register_Frame, TRUE,
  343.                         Child, lv_tools = ListviewObject,
  344.                             MUIA_Weight, 120,
  345.                             MUIA_CycleChain, 1,
  346.                             MUIA_Listview_Input, TRUE,
  347.                             ReadListFrame,
  348.                             MUIA_Listview_List, lv_scsi = NewObject(CL_ScsiList->mcc_Class, NULL, TAG_DONE),
  349.                         End,
  350.                         MAKE_PAGE(1)
  351.                         MAKE_PAGE(2)
  352.                         MAKE_PAGE(3)
  353.                         MAKE_PAGE(4)
  354.                         MAKE_PAGE(5)
  355.                         MAKE_PAGE(6)
  356.                         MAKE_PAGE(7)
  357.                     End,  
  358.                 End,
  359.             End,
  360.         End;
  361.        
  362.     if (!app)
  363.         BailOut(app, GetString(&li, MSG_Failed_to_Create_App));
  364.     
  365.     DoMethod(win1, MUIM_Notify, MUIA_Window_CloseRequest, TRUE,
  366.         app,2,MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit); 
  367.     DoMethod(lv_tools, MUIM_Notify,MUIA_Listview_DoubleClick,TRUE,
  368.         app,2, MUIM_Application_ReturnID, ID_SELECT); 
  369.     DoMethod(cycle,MUIM_Notify,MUIA_Cycle_Active, MUIV_EveryTime,
  370.         app,2,MUIM_Application_ReturnID, ID_Dev);    
  371.     
  372.     set(win1, MUIA_Window_Open, TRUE);
  373.  
  374.     set(cycle, MUIA_Cycle_Active, 0);    
  375.     ShowSCSI(DevList[0]);
  376.     
  377.     while (running)
  378.     { 
  379.         ULONG id = DoMethod(app, MUIM_Application_NewInput, &signals);
  380.         switch (id)
  381.         {
  382.             case MUIV_Application_ReturnID_Quit:
  383.                 running = FALSE;
  384.                 break;
  385.             case ID_Dev:
  386.                 get(cycle, MUIA_Cycle_Active, &entry);
  387.                 DoMethod(lv_tools, MUIM_List_Clear);
  388.                 ShowSCSI(DevList[entry]);
  389.                 break;
  390.             case ID_SELECT:
  391.                 get(lv_tools, MUIA_List_Active, &c_pos);
  392.                 set(pg_group, MUIA_Group_ActivePage, (c_pos + 1)); 
  393.                 break;
  394.             case ID_OK:
  395.                 break;
  396.         }
  397.         if (running && signals)
  398.             Wait(signals);
  399.     }
  400.     
  401.     set(win1, MUIA_Window_Open, FALSE);
  402.     BailOut(app, NULL);
  403. }
  404.  
  405. /*------------------------------------------------------------------------*/
  406.  
  407. void BailOut(APTR app, char *str)
  408. {
  409.     int loop;
  410.     if  (!(Units[0] = NULL))
  411.         FreeMem(Units[0], strlen(Units[0]) + 1);
  412.         
  413.     for (loop =0; loop<(totitem +1); loop++)
  414.     {
  415.         FreeMem(DevList[loop], strlen(DevList[loop]) + 1);   
  416.     }
  417.     
  418.     if (app)
  419.         MUI_DisposeObject(app);
  420.  
  421.     ExitClasses();
  422.  
  423.     if (MUIMasterBase)
  424.         CloseLibrary(MUIMasterBase);
  425.     
  426.     if (LocaleBase)
  427.     {
  428.         CloseCatalog(li.li_Catalog);
  429.         CloseLibrary(LocaleBase);
  430.     }
  431.     
  432.     if (IconBase)
  433.         CloseLibrary(IconBase);
  434.     
  435.     if (str)
  436.     {
  437.         puts(str);
  438.         exit(20);
  439.     }
  440.     
  441.     exit(0);    
  442. }
  443.  
  444. /*------------------------------------------------------------------------*/
  445. void GetDevList(int argc, char **argv)
  446. {
  447.     struct  WBStartup   *WBenchMsg;
  448.     struct  WBArg       *wbarg;
  449.     LONG    olddir;
  450.     
  451.     DeviceLibNode = SysBase->DeviceList.lh_Head;
  452.     while (DeviceLibNode->ln_Succ)
  453.     {
  454.         DeviceLibNode = DeviceLibNode->ln_Succ;
  455.         if (strstr(DeviceLibNode->ln_Name, scsi_name))
  456.         {
  457.             DevList[i] = (char *)AllocMem(strlen(DeviceLibNode->ln_Name) + 1, MEMF_ANY|MEMF_CLEAR);
  458.             strcpy(DevList[i], DeviceLibNode->ln_Name); 
  459.             i++;
  460.         }
  461.     }
  462.  
  463.     FromWb  = (argc==0) ?   TRUE : FALSE;
  464.     if (FromWb)
  465.     {
  466.         WBenchMsg = (struct WBStartup *)argv;
  467.         wbarg = WBenchMsg->sm_ArgList;
  468.         olddir = -1;
  469.         if ((wbarg->wa_Lock) && (*wbarg->wa_Name))
  470.             olddir = CurrentDir(wbarg->wa_Lock);
  471.         gettooltypes(wbarg);
  472.         if (olddir != -1)
  473.            CurrentDir(olddir); /*  CD back where we were           */
  474.     }
  475.     
  476.     totitem = i - 1;
  477.     DevList[i] = NULL;
  478.     return;
  479. }
  480.  
  481. /*------------------------------------------------------------------------*/
  482.  
  483. void gettooltypes(struct WBArg *wbarg)
  484. {
  485.     struct  DiskObject  *dobj;
  486.     char    **toolarray;
  487.     char    *s;
  488.  
  489.     if ((*wbarg->wa_Name) && (dobj = GetDiskObject(wbarg->wa_Name)))
  490.     {
  491.         toolarray = (char **)dobj->do_ToolTypes;
  492.         if (s = (char *)FindToolType(toolarray, "DEVICE"))
  493.         {
  494.             DevList[i] = (char *)AllocMem(strlen(s) + 1, MEMF_ANY|MEMF_CLEAR);  
  495.             strcpy(DevList[i], s);
  496.             i = i + 1;
  497.         } 
  498.         FreeDiskObject(dobj);
  499.     }
  500.        
  501.     return;   
  502. }
  503.  
  504. /*------------------------------------------------------------------------*/
  505.  
  506. SAVEDS ASM ULONG ScsiList_Dispatcher(REG(a0) struct IClass *cl,REG(a2) Object *obj,REG(a1) Msg msg)
  507. {
  508.     switch (msg->MethodID)
  509.     {
  510.         case OM_NEW              : return(ScsiList_New    (cl,obj,(APTR)msg));
  511.         case MUIM_Setup          : return(ScsiList_Setup  (cl,obj,(APTR)msg));
  512.         case MUIM_Cleanup        : return(ScsiList_Cleanup(cl,obj,(APTR)msg));
  513.     }
  514.     return(DoSuperMethodA(cl,obj,msg));
  515. }
  516.  
  517. /*------------------------------------------------------------------------*/
  518.  
  519. SAVEDS ASM APTR ScsiList_ConstructFunc(REG(a1) struct ScsiUnitData *SLCF_src)
  520. {
  521.     struct ScsiUnitData *SLCF_dest = (struct ScsiUnitData *)AllocMem(sizeof(struct ScsiUnitData), MEMF_ANY|MEMF_CLEAR);
  522.  
  523.     SLCF_dest->SUD_Vendor = (char *)AllocMem(10, MEMF_ANY|MEMF_CLEAR);
  524.        SLCF_dest->SUD_Product = (char *)AllocMem(18, MEMF_ANY|MEMF_CLEAR);
  525.     SLCF_dest->SUD_Revision = (char *)AllocMem(6, MEMF_ANY|MEMF_CLEAR); 
  526.  
  527.     SLCF_dest->SUD_Unit = SLCF_src->SUD_Unit;
  528.     strcpy(SLCF_dest->SUD_Vendor, SLCF_src->SUD_Vendor);
  529.     strcpy(SLCF_dest->SUD_Product, SLCF_src->SUD_Product);
  530.     strcpy(SLCF_dest->SUD_Revision, SLCF_src->SUD_Revision);
  531.     SLCF_dest->SUD_Dev_type = SLCF_src->SUD_Dev_type;
  532.     SLCF_dest->SUD_Standard = SLCF_src->SUD_Standard;
  533.     SLCF_dest->SUD_Removable = SLCF_src->SUD_Removable;
  534.     SLCF_dest->SUD_Rel_Addr = SLCF_src->SUD_Rel_Addr;
  535.     SLCF_dest->SUD_16Wide_Addr = SLCF_src->SUD_16Wide_Addr;
  536.     SLCF_dest->SUD_32Wide_Addr = SLCF_src->SUD_32Wide_Addr;
  537.      
  538.     return(SLCF_dest);
  539. }
  540.  
  541. /*------------------------------------------------------------------------*/
  542.  
  543. SAVEDS ASM VOID ScsiList_DestructFunc(REG(a1) struct ScsiUnitData *SLDF_data)
  544. {
  545.     FreeMem(SLDF_data->SUD_Vendor, 10);
  546.     FreeMem(SLDF_data->SUD_Product, 18);
  547.     FreeMem(SLDF_data->SUD_Revision, 6); 
  548.     
  549.     FreeMem(SLDF_data, sizeof(struct ScsiUnitData));
  550. }
  551.  
  552. /*------------------------------------------------------------------------*/
  553.  
  554. SAVEDS ASM LONG ScsiList_DisplayFunc(REG(a0) struct Hook *hook,REG(a2) char **array, REG(a1) struct ScsiUnitData *data1)
  555. {
  556.     struct ScsiList_Data *data = (APTR)hook->h_Data;
  557.     static char buf1[50], buf2[30], buf3[30];
  558.     
  559.     *array++ = "";
  560.     
  561.     if (!data1)
  562.     {
  563.         strcpy(buf2,"\33b\33u");
  564.         strcpy(buf3,"\33b\33u");
  565.         strcat(buf2, GetString(&li, MSG_Unit));
  566.         strcat(buf3, GetString(&li, MSG_Product));
  567.         *array++ = "";
  568.         *array++ = buf2;
  569.         *array   = buf3;
  570.     }
  571.     else
  572.     {
  573.         switch(data1->SUD_Dev_type)
  574.         {
  575.             case 0:
  576.                 if (data1->SUD_Removable)
  577.                     sprintf(buf1, "\33O[%08lx]", data->SL_Image_RD);
  578.                 else
  579.                     sprintf(buf1, "\33O[%08lx]", data->SL_Image_HD);
  580.                 break;
  581.             case 1:
  582.                 sprintf(buf1, "\33O[%08lx]", data->SL_Image_RD);
  583.                 break;
  584.             case 5:
  585.                 sprintf(buf1, "\33O[%08lx]", data->SL_Image_CD);
  586.                 break;
  587.             case 6:
  588.                 sprintf(buf1, "\33O[%08lx]", data->SL_Image_SC);
  589.                 break;
  590.             case 99:
  591.                 sprintf(buf1, "\33O[%08lx]", data->SL_Image_NO);
  592.                 break; 
  593.             default:
  594.                 sprintf(buf1, "\33O[%08lx]", data->SL_Image_NL);
  595.                 break;
  596.         }
  597.         sprintf(buf2, "%d", data1->SUD_Unit);
  598.         strcpy(buf3, data1->SUD_Product);
  599.         *array++ = buf1;
  600.         *array++ = buf2;
  601.         *array   = buf3;
  602.     }
  603.     
  604.     return(0);
  605. }
  606.  
  607. /*------------------------------------------------------------------------*/
  608.  
  609. ULONG ScsiList_New(struct IClass *cl,Object *obj,struct opSet *msg)
  610. {
  611.     static const struct Hook ScsiList_ConstructHook = { { 0,0 }, (VOID *)ScsiList_ConstructFunc, NULL, NULL};
  612.     static const struct Hook ScsiList_DestructHook  = { { 0,0 }, (VOID *)ScsiList_DestructFunc, NULL, NULL};
  613.  
  614.     obj=(Object *)DoSuperNew(cl,obj,
  615.         MUIA_List_ConstructHook, &ScsiList_ConstructHook, 
  616.         MUIA_List_DestructHook , &ScsiList_DestructHook,
  617.         MUIA_List_Format       , ",,,",
  618.         MUIA_List_Title        , TRUE,
  619.         MUIA_List_MinLineHeight, 14, 
  620.         TAG_MORE,msg->ops_AttrList);
  621.  
  622.     if (obj)
  623.     {
  624.         struct ScsiList_Data *data = INST_DATA(cl,obj);
  625.  
  626.         data->DisplayHook.h_Entry = (VOID *)ScsiList_DisplayFunc;
  627.         data->DisplayHook.h_Data  = (APTR)data;
  628.  
  629.         set(obj,MUIA_List_DisplayHook,&data->DisplayHook);
  630.     }
  631.  
  632.     return((ULONG)obj);
  633.     
  634. }
  635.  
  636. /*------------------------------------------------------------------------*/
  637.  
  638. static Object *makescsiimage(UBYTE *body)
  639. {
  640.     Object *obj = BodychunkObject,
  641.         MUIA_FixWidth             , CD_ROM_WIDTH ,
  642.         MUIA_FixHeight            , CD_ROM_HEIGHT,
  643.         MUIA_Bitmap_Width         , CD_ROM_WIDTH ,
  644.         MUIA_Bitmap_Height        , CD_ROM_HEIGHT,
  645.         MUIA_Bodychunk_Depth      , CD_ROM_DEPTH ,
  646.         MUIA_Bodychunk_Body       , (UBYTE *)body,
  647.         MUIA_Bodychunk_Compression, CD_ROM_COMPRESSION,
  648.         MUIA_Bodychunk_Masking    , CD_ROM_MASKING,
  649.         MUIA_Bitmap_SourceColors  , (ULONG *)CD_Rom_colors,
  650.         MUIA_Bitmap_Transparent   , 0,
  651.         End;
  652.  
  653.     return(obj);
  654. }
  655.  
  656. /*------------------------------------------------------------------------*/
  657.  
  658. static Object *makescsiimageSC(UBYTE *body)
  659. {
  660.     Object *obj = BodychunkObject,
  661.         MUIA_FixWidth             , SCANNER_WIDTH ,
  662.         MUIA_FixHeight            , SCANNER_HEIGHT,
  663.         MUIA_Bitmap_Width         , SCANNER_WIDTH ,
  664.         MUIA_Bitmap_Height        , SCANNER_HEIGHT,
  665.         MUIA_Bodychunk_Depth      , SCANNER_DEPTH ,
  666.         MUIA_Bodychunk_Body       , (UBYTE *)body,
  667.         MUIA_Bodychunk_Compression, SCANNER_COMPRESSION,
  668.         MUIA_Bodychunk_Masking    , SCANNER_MASKING,
  669.         MUIA_Bitmap_SourceColors  , (ULONG *)Scanner_colors,
  670.         MUIA_Bitmap_Transparent   , 0,
  671.         End;
  672.  
  673.     return(obj);
  674. }
  675.  
  676. /*------------------------------------------------------------------------*/
  677.  
  678. ULONG ScsiList_Setup(struct IClass *cl,Object *obj,Msg msg)
  679. {
  680.     struct ScsiList_Data *data = INST_DATA(cl,obj);
  681.  
  682.     if (!DoSuperMethodA(cl,obj,msg))
  683.         return(FALSE);
  684.  
  685.     data->SL_OImage_CD = makescsiimage((UBYTE *)CD_Rom_body);
  686.     data->SL_OImage_HD = makescsiimage((UBYTE *)Hard_Drive_body);
  687.     data->SL_OImage_RD = makescsiimage((UBYTE *)Remove_Drive_body);
  688.     data->SL_OImage_SC = makescsiimageSC((UBYTE *)Scanner_body);
  689.     data->SL_OImage_NO = makescsiimage((UBYTE *)NoUnit_body); 
  690.     data->SL_OImage_NL = makescsiimage((UBYTE *)Null_body);
  691.  
  692.     data->SL_Image_CD = (APTR)DoMethod(obj,MUIM_List_CreateImage,data->SL_OImage_CD ,0);
  693.     data->SL_Image_HD = (APTR)DoMethod(obj,MUIM_List_CreateImage,data->SL_OImage_HD ,0);
  694.     data->SL_Image_RD = (APTR)DoMethod(obj,MUIM_List_CreateImage,data->SL_OImage_RD ,0);
  695.     data->SL_Image_SC = (APTR)DoMethod(obj,MUIM_List_CreateImage,data->SL_OImage_SC ,0);
  696.     data->SL_Image_NO = (APTR)DoMethod(obj,MUIM_List_CreateImage,data->SL_OImage_NO ,0); 
  697.     data->SL_Image_NL = (APTR)DoMethod(obj,MUIM_List_CreateImage,data->SL_OImage_NL ,0);
  698.  
  699.     MUI_RequestIDCMP(obj,IDCMP_MOUSEBUTTONS);
  700.  
  701.     return(TRUE);
  702. }
  703.  
  704. /*------------------------------------------------------------------------*/
  705.  
  706. ULONG ScsiList_Cleanup(struct IClass *cl,Object *obj,Msg msg)
  707. {
  708.     struct ScsiList_Data *data = INST_DATA(cl,obj);
  709.  
  710.     DoMethod(obj,MUIM_List_DeleteImage,data->SL_Image_CD);
  711.     DoMethod(obj,MUIM_List_DeleteImage,data->SL_Image_HD);
  712.     DoMethod(obj,MUIM_List_DeleteImage,data->SL_Image_RD);
  713.     DoMethod(obj,MUIM_List_DeleteImage,data->SL_Image_SC);
  714.     DoMethod(obj,MUIM_List_DeleteImage,data->SL_Image_NO); 
  715.     DoMethod(obj,MUIM_List_DeleteImage,data->SL_Image_NL);
  716.  
  717.     MUI_RejectIDCMP(obj,IDCMP_MOUSEBUTTONS);
  718.  
  719.     return(DoSuperMethodA(cl,obj,msg));
  720. }
  721.  
  722. /*------------------------------------------------------------------------*/
  723.  
  724. BOOL InitClasses(VOID)
  725. {
  726.     CL_ScsiList   = MUI_CreateCustomClass(NULL, MUIC_List, NULL, sizeof(struct ScsiList_Data), ScsiList_Dispatcher);
  727.  
  728.     if (CL_ScsiList)
  729.         return(TRUE);
  730.  
  731.     ExitClasses();
  732.     return(FALSE);
  733. }
  734.  
  735. /*------------------------------------------------------------------------*/
  736.  
  737. VOID ExitClasses(VOID)
  738. {
  739.     if (CL_ScsiList) 
  740.         MUI_DeleteCustomClass(CL_ScsiList);
  741. }
  742.  
  743. /*------------------------------------------------------------------------*/
  744.  
  745. void ShowSCSI(char *SSdevice)
  746. {
  747.     if (!(scsi_sense = (UBYTE *)AllocMem(252, MEMF_CHIP|MEMF_CLEAR)))
  748.         ShowScsi_exit(20, GetString(&li, MSG_Unable_to_Allocate_Memory));
  749.  
  750.     if (!(scsi_data = (UBYTE *)AllocMem(252, MEMF_CHIP|MEMF_CLEAR)))
  751.         ShowScsi_exit(20, GetString(&li, MSG_Unable_to_Allocate_Memory));
  752.  
  753.     if (!(replymp = (struct MsgPort *)CreatePort(NULL, 0)))
  754.         ShowScsi_exit(20, GetString(&li, MSG_Unable_to_Create_Mess_Port));
  755.         
  756.     if (!(scsi_req = (struct IOStdReq *)CreateStdIO(replymp)))
  757.         ShowScsi_exit(20, GetString(&li, MSG_Unable_to_Create_StandardIO));
  758.     
  759.     ListDevices(SSdevice); 
  760.     
  761.     ShowScsi_exit(0, NULL);
  762. }
  763.  
  764. /*------------------------------------------------------------------------*/
  765.  
  766. void ShowScsi_exit(long code, char *errmsg)
  767. {
  768.     if (scsi_req)
  769.         DeleteStdIO(scsi_req);
  770.     
  771.     if (replymp)
  772.         DeletePort(replymp);
  773.     
  774.     if (scsi_sense)
  775.         FreeMem(scsi_sense, 252);
  776.     
  777.     if (scsi_data)
  778.         FreeMem(scsi_data, 252);
  779.     
  780.     if (errmsg)
  781.         printf("\n%s\n", errmsg);
  782.     
  783.     return;
  784. }
  785.  
  786. /*------------------------------------------------------------------------*/
  787.  
  788. void ListDevices(char *devname)
  789. {
  790.     int i;
  791.     struct ScsiUnitData *SUdata = (struct ScsiUnitData *)AllocMem(sizeof(struct ScsiUnitData), MEMF_ANY|MEMF_CLEAR);
  792.  
  793.     SUdata->SUD_Vendor = (char *)AllocMem(10, MEMF_ANY|MEMF_CLEAR);
  794.     SUdata->SUD_Product = (char *)AllocMem(18, MEMF_ANY|MEMF_CLEAR);
  795.     SUdata->SUD_Revision = (char *)AllocMem(6, MEMF_ANY|MEMF_CLEAR);
  796.             
  797.     set(lv_tools, MUIA_List_Quiet, TRUE);
  798.     for (i = 0; i < scsiunit; i++)
  799.     {
  800.         SUdata->SUD_Unit = i;    
  801.         if (OpenDevice(devname, i, scsi_req, 0))
  802.         {
  803.             strcpy(SUdata->SUD_Vendor, " ");
  804.             strcpy(SUdata->SUD_Product, GetString(&li, MSG_Not_Used));
  805.             strcpy(SUdata->SUD_Revision, " ");
  806.             SUdata->SUD_Dev_type = 99;
  807.             SUdata->SUD_Standard = 9;
  808.             SUdata->SUD_Removable = FALSE;
  809.             SUdata->SUD_Rel_Addr = FALSE;
  810.             SUdata->SUD_16Wide_Addr = FALSE;
  811.             SUdata->SUD_32Wide_Addr = FALSE;
  812.         }
  813.         else
  814.         {
  815.             scsi_req->io_Length         = sizeof(struct SCSICmd);
  816.             scsi_req->io_Data           = (APTR) &scsi_cmd;
  817.             scsi_req->io_Command        = HD_SCSICMD;
  818.             scsi_cmd.scsi_Data          = (APTR) scsi_data;
  819.             scsi_cmd.scsi_Length        = 252;
  820.             scsi_cmd.scsi_SenseActual   = 0;
  821.             scsi_cmd.scsi_SenseData     = scsi_sense;
  822.             scsi_cmd.scsi_SenseLength   = 252;
  823.             scsi_cmd.scsi_Command       = (UBYTE *)cmd;
  824.             scsi_cmd.scsi_CmdLength     = sizeof(cmd);
  825.             scsi_cmd.scsi_Flags         = SCSIF_READ|SCSIF_AUTOSENSE;
  826.     
  827.             DoIO((struct IOStdReq *)scsi_req);
  828.             
  829.             
  830.             if (scsi_req->io_Error)
  831.             { 
  832.                 strcpy(SUdata->SUD_Vendor," ");
  833.                 strcpy(SUdata->SUD_Product, GetString(&li, MSG_Not_Used));
  834.                 strcpy(SUdata->SUD_Revision, " ");
  835.                 SUdata->SUD_Dev_type = 99;
  836.                 SUdata->SUD_Standard = 9;
  837.                 SUdata->SUD_Removable = FALSE;
  838.                 SUdata->SUD_Rel_Addr = FALSE;
  839.                 SUdata->SUD_16Wide_Addr = FALSE;
  840.                 SUdata->SUD_32Wide_Addr = FALSE;
  841.             }
  842.             else
  843.             {
  844.                 sprintf(SUdata->SUD_Vendor, "%.8s", &scsi_data[8]);
  845.                 sprintf(SUdata->SUD_Product, "%.16s", &scsi_data[16]);
  846.                 sprintf(SUdata->SUD_Revision, "%.4s", &scsi_data[32]);
  847.                 SUdata->SUD_Dev_type = (scsi_data[0] & 0x1F);
  848.                 SUdata->SUD_Standard = (scsi_data[3] & 0x0F);
  849.                 SUdata->SUD_Removable = ((scsi_data[1] & 0x80) ? TRUE : FALSE); 
  850.                 SUdata->SUD_Rel_Addr = ((scsi_data[7] & 0x80) ? TRUE : FALSE); 
  851.                 SUdata->SUD_16Wide_Addr = ((scsi_data[7] & 0x20) ? TRUE : FALSE); 
  852.                 SUdata->SUD_32Wide_Addr = ((scsi_data[7] & 0x40) ? TRUE : FALSE);
  853.             }
  854.             CloseDevice(scsi_req);
  855.         } 
  856.         DoMethod(lv_tools, MUIM_List_InsertSingle, SUdata, MUIV_List_Insert_Bottom);
  857.         set(Sl_Product[i+1], MUIA_Text_Contents, SUdata->SUD_Product);
  858.         set(Sl_Vendor[i+1], MUIA_Text_Contents, SUdata->SUD_Vendor);
  859.         set(Sl_Revision[i+1], MUIA_Text_Contents, SUdata->SUD_Revision);
  860.         set(Sl_DevType[i+1], MUIA_Text_Contents, SetDeviceType(SUdata->SUD_Dev_type));
  861.         set(Sl_Standard[i+1], MUIA_Text_Contents, id2string(SUdata->SUD_Standard, responseformat));
  862.         set(Sl_Removable[i+1], MUIA_Selected, SUdata->SUD_Removable);
  863.         set(Sl_Rel_Addr[i+1], MUIA_Selected, SUdata->SUD_Rel_Addr);
  864.         set(Sl_16Wide_Addr[i+1], MUIA_Selected, SUdata->SUD_16Wide_Addr);
  865.         set(Sl_32Wide_Addr[i+1], MUIA_Selected, SUdata->SUD_32Wide_Addr);
  866.     }
  867.     set(lv_tools, MUIA_List_Quiet, FALSE);  
  868.     
  869.     FreeMem(SUdata->SUD_Vendor, 10);
  870.     FreeMem(SUdata->SUD_Product, 18);
  871.     FreeMem(SUdata->SUD_Revision, 6);
  872.     
  873.     FreeMem(SUdata, sizeof(struct ScsiUnitData));
  874. }
  875.  
  876. /*------------------------------------------------------------------------*/
  877.  
  878. UBYTE *id2string(int id, IDTOSTRING * idtable)
  879. {
  880.   int j = 0;
  881.   UBYTE *p;
  882.  
  883.   do
  884.   {
  885.     p = idtable[j].ptr;
  886.     if (idtable[j].code == id)
  887.         break;
  888.   } 
  889.   while (idtable[j++].code != -1);
  890.   
  891.   return p;
  892. }
  893.  
  894.  
  895. /*------------------------------------------------------------------------*/
  896.  
  897. STRPTR SetDeviceType(int id)
  898. {
  899.     char *Dev_string = "                                                   ";
  900.     
  901.     switch(id)
  902.     {
  903.         case 0:
  904.             strcpy(Dev_string, GetString(&li, MSG_Direct_Access_Device));
  905.             break;
  906.         case 1:
  907.             strcpy(Dev_string, GetString(&li, MSG_Sequential_Access_Device));
  908.             break;
  909.         case 2:
  910.             strcpy(Dev_string, GetString(&li, MSG_Printer_Device));
  911.             break;
  912.         case 3:
  913.             strcpy(Dev_string, GetString(&li, MSG_Processor_Device));
  914.             break;
  915.         case 4:
  916.             strcpy(Dev_string, GetString(&li, MSG_Write_Once_Device));
  917.             break;
  918.         case 5:
  919.             strcpy(Dev_string, GetString(&li, MSG_CDROM_Device));
  920.             break;
  921.         case 6:
  922.             strcpy(Dev_string, GetString(&li, MSG_Scanner_Device));
  923.             break;
  924.         case 7:
  925.             strcpy(Dev_string, GetString(&li, MSG_Optical_Device));
  926.             break;
  927.         case 8:
  928.             strcpy(Dev_string, GetString(&li, MSG_Medium_Changer_Device));
  929.             break;
  930.         case 9:
  931.             strcpy(Dev_string, GetString(&li, MSG_Communications_Device));
  932.             break;
  933.         case 99:
  934.             strcpy(Dev_string, " ");
  935.             break;
  936.         default:
  937.             strcpy(Dev_string, GetString(&li, MSG_Unknown_Device));
  938.             break;
  939.     }
  940.     return(Dev_string);   
  941. }