home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #6 / amigamamagazinepolishissue1998.iso / disks / misc / scsi_list / source / scsi.c < prev    next >
C/C++ Source or Header  |  1996-11-10  |  36KB  |  1,044 lines

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