home *** CD-ROM | disk | FTP | other *** search
/ Amiga Elysian Archive / AmigaElysianArchive.iso / emulate / jdiag.lha / jdiag.c < prev    next >
C/C++ Source or Header  |  1990-03-04  |  29KB  |  689 lines

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. #include <error.h>
  5. #include <ctype.h>
  6. #include <fcntl.h>
  7. #include <exec/types.h>
  8. #include <exec/exec.h>
  9. #include <exec/execbase.h>
  10. #include <exec/devices.h>
  11. #include <janus/janus.h>
  12. #include <libraries/expansionbase.h>
  13. #include <libraries/expansion.h>
  14. #include <libraries/configvars.h>
  15. #include <libraries/dos.h>
  16. #include <proto/dos.h>
  17. #include <proto/exec.h>
  18. #include <proto/janus.h>
  19. #include <proto/expansion.h>
  20.  
  21. /**********************************************************************/
  22. /*              Freely Given into the Public Domain                   */
  23. /**********************************************************************/
  24. /* This program is meant as a general-purpose informational tool for  */
  25. /* working with the Amiga Bridgecard.  All structures and operation   */
  26. /* were gleaned from includes and various documents and may change or */
  27. /* be plain wrong.  I welcome any clarifications and suggestions for  */
  28. /* new pieces of data to display or new checks to perform on Janus.   */
  29. /*                                                                    */
  30. /* By: Jeff Rush of Tau Productions                                   */
  31. /*     BIX: jrush                                                     */
  32. /*     Sysop of the Rising Star BBS (An Opus Echomail System)         */
  33. /*         (214) 231-1372 300/1200/2400 24hrs                         */
  34. /*         Fidonet 1:124/4206                                         */
  35. /**********************************************************************/
  36. /* No attempt has been made to make this code small or efficient.     */
  37. /* Due to the infrequent use and non-residency of this code, there is */
  38. /* little need to squeeze, but knock yourself out if you wish.  It is */
  39. /* written so as to be easy to understand its workings and flow. I    */
  40. /* hope I succeeded...:-)                                             */
  41. /**********************************************************************/
  42. /* 26Feb90   JRR Original Creation                                    */
  43. /* 04Mar90   JRR Added Service Interrupts                             */
  44. /**********************************************************************/
  45.  
  46. /************************/
  47. /* Constants and Macros */
  48. /************************/
  49. #define MAXFLIST 100  /* Maximum # of Free Memory Blocks Expected Per Region */
  50.  
  51. #ifndef TRUE
  52. #define TRUE        1
  53. #endif
  54.  
  55. #ifndef FALSE
  56. #define FALSE       0
  57. #endif
  58.  
  59. /***************************/
  60. /* Structures and Typedefs */
  61. /***************************/
  62. typedef unsigned long        ulong;
  63. typedef unsigned char        bool;
  64. typedef unsigned char        byte;
  65. typedef unsigned short       word;
  66.  
  67. typedef struct Library       LIBRARY;
  68.  
  69. typedef struct ConfigDev     CONFIGDEV;
  70. typedef struct JanusAmiga    JANUSAMIGA;
  71. typedef struct JanusMemHead  JANUSMEMHEAD;
  72. typedef struct JanusMemChunk JANUSMEMCHUNK;
  73.  
  74. struct _flist {
  75.     UBYTE *base; /* Base Address of Free Block */
  76.     UWORD  size; /* Length of Free Block       */
  77. };
  78.  
  79. /**************/
  80. /* Prototypes */
  81. /**************/
  82. bool        Initialize(int argc, char *argv[]);
  83. void        Terminate(int retcode);
  84. CONFIGDEV  *FindBridgeCard(void);
  85. void        ShowConfigDevices(void);
  86. void        IdentifyJanus(void);
  87. void        ShowJanusState(void);
  88. void        ShowFreelist(JANUSMEMHEAD *jmh);
  89. void        CheckNormalJanusFiles(void);
  90. void        CheckCriticalJanusFiles(void);
  91. void        CheckFile(char *f);
  92. long        ScanFile(char *fname, long *ckcode);
  93.  
  94. word        CalcCRC16(word accum, byte *blk, int blklen);
  95. word        CalcCRC_CCITT(word accum, byte *blk, int blklen);
  96.  
  97. int         cmpflist(struct _flist *a, struct _flist *b);
  98.  
  99. /********************/
  100. /* Global Variables */
  101. /********************/
  102. struct ExpansionBase *ExpansionBase = NULL;
  103. bool                  shutdown      = FALSE; /* Server Shutdown Request Flag */
  104. bool                  opt_skipfiles = FALSE;
  105.  
  106. struct JanusBase     *JanusBase     = NULL;
  107. CONFIGDEV            *Bridgecard    = NULL;
  108.  
  109. struct _flist flist[MAXFLIST];
  110. int           numflist = 0;
  111.  
  112. char *snames[] = {
  113.     "Write to Mono Video RAM",
  114.     "",
  115.     "Write to CGA Video  RAM",
  116.     "",
  117.     "Write to Mono Video Registers",
  118.     "",
  119.     "Write to CGA Video Registers",
  120.     "",
  121.     "PC Keyboard Ready for Keystroke",
  122.     "",
  123.     "Write to Parallel I/O Register",
  124.     "",
  125.     "Write to Serial I/O Register",
  126.     "",
  127.     "PC Booted, Ready for Action",
  128.     "",
  129.     "PC Wants to Scroll Its Video",
  130.     "",
  131.     "Amiga Reading PC Harddisk",
  132.     "",
  133.     "PC Reading Amiga Memory",
  134.     "",
  135.     "Amiga Reading PC Memory",
  136.     "",
  137.     "PC Executing Amiga Routine",
  138.     "",
  139.     "Amiga Causing PC Interrupt",
  140.     "",
  141.     "PC Triggering Amiga Side of",
  142.     "    a New Service",
  143.     "Amiga Triggering PC Side of",
  144.     "    a New Service"
  145. };
  146. #define NUM_SNAMES (sizeof(snames)/sizeof(char *))
  147.  
  148. /**********************************************************************/
  149. /*                                                                    */
  150. /**********************************************************************/
  151. void
  152. main(int argc, char *argv[])
  153. {
  154.     printf("Bridgecard Configuration Diagnostic v1.0 by Jeff Rush (04Mar90)\n");
  155.     printf("* Freely Given into the Public Domain with Full Source Code *\n\n");
  156.  
  157.     if (Initialize(argc, argv)) {
  158.  
  159.         printf("Status of Bridgecard Hardware:\n");
  160.         Bridgecard = FindBridgeCard(); /* Locate Bridgecard Autoconfig Hardware      */
  161.  
  162.         if (!opt_skipfiles) {
  163.             printf("Status of Critical Support Files:\n");
  164.             CheckCriticalJanusFiles();
  165.  
  166.             printf("Status of Normal Support Files:\n");
  167.             CheckNormalJanusFiles();
  168.         }
  169.  
  170.         if (JanusBase != NULL) {
  171.             IdentifyJanus();           /* Print Identifying Data About Janus Library */
  172.             ShowJanusState();          /* Print Data in Janus Shared Memory          */
  173.         }
  174.  
  175.         Terminate(0);
  176.     } else
  177.         Terminate(10);
  178. }
  179. /**********************************************************************/
  180. /*                                                                    */
  181. /**********************************************************************/
  182. void
  183. CheckFile(char *f)
  184. {
  185.     long  ckcode, n;
  186.     char  line[256];
  187.  
  188.     sprintf(line, "  %s", f);
  189.     while (strlen(line) < 38)
  190.         strcat(line, " ");
  191.  
  192.     printf("%s", line);
  193.  
  194.     n = ScanFile(f, &ckcode);
  195.     if (n < 0)  printf("Error: %s\n", (errno<sys_nerr) ? sys_errlist[errno] : "Unknown");
  196.     else        printf("Check: 0x%08lX, %8lu\n", ckcode, n);
  197. }
  198. /**********************************************************************/
  199. /*                                                                    */
  200. /**********************************************************************/
  201. void
  202. CheckCriticalJanusFiles()
  203. {
  204.     CheckFile("SYS:Expansion/Janus.Library");         /* Janus Library                        */
  205.  
  206.     /**********************************/
  207.     /* Check for an Old Janus Library */
  208.     /**********************************/
  209.     if (access("LIBS:Janus.Library", 0) == 0)
  210.         printf("  *** Warning - Delete the JANUS.LIBRARY in LIBS: ***\n");
  211.  
  212.     CheckFile("SYS:Expansion/Janus.Library.info");    /* Janus Icon in Expansion Drawer       */
  213.     CheckFile("SYS:PC/System/PC.Boot");               /* Janus PC-Side Handler Code (PC.BOOT) */
  214.     CheckFile("SYS:PC/System/ScanCode.Table");        /* Keyboard Conversion Table            */
  215.     CheckFile("SYS:PC/System/SidecarKeys.Table");     /* Sidecar Keys Table (Obsolete?)       */
  216.     CheckFile("SYS:PC/System/SidecarSettings.Table"); /* Sidecard Settings Table              */
  217.     CheckFile("SYS:PC/PCWindow");                     /* PCWindow Program                     */
  218.  
  219.     printf("\n");
  220. }
  221. /**********************************************************************/
  222. /*                                                                    */
  223. /**********************************************************************/
  224. void
  225. CheckNormalJanusFiles()
  226. {
  227.     CheckFile("SYS:PC/PCHard");
  228.     CheckFile("SYS:PC/PCDisk");
  229.     CheckFile("SYS:PC/PCPrefs");
  230.     CheckFile("SYS:PC/Services/Timeserv");
  231.     CheckFile("SYS:PC/LPT1");
  232.     CheckFile("FONTS:PCFont.font");
  233.     CheckFile("DEVS:Jdisk.device");
  234.     CheckFile("C:DJMount");
  235.     CheckFile("SYS:PC/Amouse");
  236.  
  237.     printf("\n");
  238. }
  239. /**********************************************************************/
  240. /*                                                                    */
  241. /**********************************************************************/
  242. long
  243. ScanFile(char *fname, long *ckcode)
  244. {
  245.     byte  buffer[1024];
  246.     word  ck1, ck2;
  247.     int   fd, n;
  248.     long  size = 0L;
  249.  
  250.     fd = open(fname, O_RDONLY);
  251.     if (fd < 0)
  252.         return -1;
  253.  
  254.     ck1  = ck2 = 0;
  255.     size = 0L;
  256.     while ((n = read(fd, buffer, sizeof(buffer))) > 0) {
  257.         ck1   = CalcCRC16(ck1, buffer, n);
  258.         ck2   = CalcCRC_CCITT(ck2, buffer, n);
  259.         size += n;
  260.     }
  261.     *ckcode = ((long)ck1 << 16) | ck2;
  262.  
  263.     close(fd);
  264.     return size;
  265. }
  266. /**********************************************************************/
  267. /*                                                                    */
  268. /**********************************************************************/
  269. void
  270. IdentifyJanus()
  271. {
  272.     struct Interrupt *i;
  273.     struct ServiceBase *s;
  274.     byte   pcprefs, bank;
  275.  
  276.     printf("Status of Janus.Library for an %s-Bridgecard:\n",
  277.         JanusBase->jb_ATFlag ? "(A2286) AT" : "(A2088) PC");
  278.  
  279.     printf("  Library Version %u.%u (%s), Open Count = %u, Checksum = 0x%08lX\n",
  280.         JanusBase->jb_LibNode.lib_Version,
  281.         JanusBase->jb_LibNode.lib_Revision,
  282.         JanusBase->jb_LibNode.lib_IdString,
  283.         JanusBase->jb_LibNode.lib_OpenCnt,
  284.         JanusBase->jb_LibNode.lib_Sum);
  285.  
  286.     printf("  Outstanding Intr Requests (Bitfield)      : 0x%08lX\n", JanusBase->jb_IntReq);
  287.     printf("  Enabled Intrs (Bitfield)                  : 0x%08lX\n", JanusBase->jb_IntEna);
  288.     printf("  Location of Parameter Memory              : 0x%08lX\n", JanusBase->jb_ParamMem);
  289.     printf("  Location of I/O Register Map              : 0x%08lX\n", JanusBase->jb_IoBase);
  290.     printf("  Base Address of Janus AutoConfig Hardware : 0x%08lX\n", JanusBase->jb_ExpanBase);
  291.     printf("  Ptr to Seglist of Loaded Code             : 0x%08lX\n", JanusBase->jb_SegList);
  292.     printf("  Offset of the Keyboard Register           : 0x%04X\n",  JanusBase->jb_KeyboardRegisterOffset);
  293.     printf("  Offset of the AT Rom Bank (ATs Only)      : 0x%04X\n",  JanusBase->jb_ATOffset);
  294.     printf("  JSERV_READAMIGA Handler              Code : 0x%08lX\n", JanusBase->jb_ReadHandler.is_Code);
  295.     printf("                                       Data : 0x%08lX\n", JanusBase->jb_ReadHandler.is_Data);
  296.     printf("  From-PC Hardware Interrupt Server    Code : 0x%08lX\n", JanusBase->jb_IntServer.is_Code);
  297.     printf("                                       Data : 0x%08lX\n", JanusBase->jb_IntServer.is_Data);
  298.  
  299.     pcprefs = *((byte *)(JanusBase->jb_IoBase) + 0x1FF7);
  300.     bank    = (pcprefs >> 5) & 0x03;
  301.  
  302.     printf("\n  Emulation of PC Hardware by the Amiga (As Set by PCPREFS Utility)\n");
  303.     printf("    PC Serial Interface (COM2:)             : %s\n", (pcprefs & 0x01) ? "Enabled" : "Disabled");
  304.     printf("    PC Parallel Interface (LPT1:)           : %s\n", (pcprefs & 0x02) ? "Enabled" : "Disabled");
  305.     printf("    PC Keyboard Interface                   : %s\n", (pcprefs & 0x04) ? "Enabled" : "Disabled");
  306.     printf("    PC Monochrome Display (MDA)             : %s\n", (pcprefs & 0x08) ? "Enabled" : "Disabled");
  307.     printf("    PC Graphics Display (CGA)               : %s\n", (pcprefs & 0x10) ? "Enabled" : "Disabled");
  308.  
  309.     printf("\n  Hardware Operating Mode (As Set by PCPREFS Utility)\n");
  310.     printf("    Location of PC Memory                   : ");
  311.     switch(bank) {
  312.     case 0: printf("(Not Used)\n");                                           break;
  313.     case 1: printf("A0000-AFFFF\n");                                          break;
  314.     case 2: printf("%s\n", (pcprefs & 0x80) ? "D0000-DFFFF" : "D4000-DFFFF"); break;
  315.     case 3: printf("%s\n", (pcprefs & 0x80) ? "E0000-EFFFF" : "(Not Used)");  break;
  316.     }
  317.  
  318.     printf("    Type of Machine Emulated in Hardware    : %s\n", (pcprefs & 0x80) ? "PC" : "AT");
  319.  
  320.     i = *(JanusBase->jb_IntHandlers);
  321.  
  322.     s = JanusBase->jb_ServiceBase;
  323.  
  324.     printf("\n");
  325.  
  326. #if FALSE
  327.    struct   Interrupt   **jb_IntHandlers;/* base array of int handler ptrs */
  328.    struct   ServiceBase *jb_ServiceBase; /* Amiga Services data structure  */
  329. #endif
  330. }
  331.  
  332. /**********************************************************************/
  333. /*                                                                    */
  334. /**********************************************************************/
  335. void
  336. ShowJanusState()
  337. {
  338.     int            i;
  339.     JANUSAMIGA    *ja;
  340.     JANUSMEMHEAD  *jmh;
  341.     VOID         (*nop_code)(), (*i_code)();
  342.     APTR           nop_data, i_data;
  343.  
  344.     ja = (JANUSAMIGA *)MakeWordPtr((APTR)(JanusBase->jb_ParamMem));
  345.  
  346.     printf("Status of Janus Shared Memory on Bridgecard Hardware:\n");
  347.     printf("  Version of Janus.Library                  : %u.%u\n",
  348.         ja->ja_JLibVer, ja->ja_JLibRev);
  349.     printf("  Version of Janus Handler (PC.BOOT)        : %u.%u\n",
  350.         ja->ja_JHandlerVer, ja->ja_JHandlerRev);
  351.     printf("  Janus Handler Initialization Flag         : 0x%02X%02X%s\n",
  352.         ja->ja_HandlerLoaded & 0xFF, ja->ja_HandlerLoaded >> 8,
  353.         (ja->ja_HandlerLoaded == 0x5442) ? " ('BT')" : "");
  354.     printf("  Maximum Number of Service Interrupts      : %u\n",    ja->ja_NumInterrupts);
  355.  
  356.     /**************************************************************/
  357.     /* Heuristic! Assuming the Last Slot of the Services is Idle, */
  358.     /* Its Contents Must Point to Null Stubs for Safe Operation.  */
  359.     /**************************************************************/
  360.     nop_code = JanusBase->jb_IntHandlers[ja->ja_NumInterrupts - 1]->is_Code;
  361.     nop_data = JanusBase->jb_IntHandlers[ja->ja_NumInterrupts - 1]->is_Data;
  362.  
  363.     printf("\n  Table of Service Interrupts (Not for 3rd-Party Use):\n");
  364.  
  365.     for(i=0; i<ja->ja_NumInterrupts; i++) {
  366.         i_code = JanusBase->jb_IntHandlers[i]->is_Code;
  367.         i_data = JanusBase->jb_IntHandlers[i]->is_Data;
  368.  
  369.         printf("    %2d %-32sCode : 0x%08lX%s\n",
  370.             i, (i*2 > NUM_SNAMES-1) ? "Unknown Service" : snames[i*2],
  371.             i_code, (i_code == nop_code) ? " (Null Stub)" : "");
  372.  
  373.         printf("       %-32sData : 0x%08lX%s\n",
  374.             (i*2 > NUM_SNAMES-1) ? "" : snames[i*2+1],
  375.             i_data, (i_data == nop_data) ? " (Null Data)" : "");
  376.     }
  377.  
  378.     /**********************************/
  379.     /* Display Parameter Memory Usage */
  380.     /**********************************/
  381.     jmh = &(ja->ja_ParamMem);
  382.     printf("\n  Parameter Memory: (Used=%u, Free=%u, Total=%u)\n",
  383.         jmh->jmh_Max - jmh->jmh_Free, jmh->jmh_Free + 1, jmh->jmh_Max + 1);
  384.  
  385.     printf("    Lock Byte         : 0x%02X%s\n", jmh->jmh_Lock,
  386.         (jmh->jmh_Lock == 0x00) ? " (Unlocked)" : " (Locked)");
  387.     printf("    68000 Base Address: 0x%08lX\n",  jmh->jmh_68000Base);
  388.     printf("    80x86 Base Segment: 0x%04X\n",   jmh->jmh_8088Segment);
  389.  
  390.     ShowFreelist(jmh);
  391.  
  392.     /*******************************/
  393.     /* Display Buffer Memory Usage */
  394.     /*******************************/
  395.     jmh = &(ja->ja_BufferMem);
  396.     printf("\n  Buffer Memory: (Used=%u, Free=%u, Total=%u)\n",
  397.         jmh->jmh_Max - jmh->jmh_Free, jmh->jmh_Free + 1, jmh->jmh_Max + 1);
  398.  
  399.     printf("    Lock Byte         : 0x%02X%s\n", jmh->jmh_Lock,
  400.         (jmh->jmh_Lock == 0x00) ? " (Unlocked)" : " (Locked)");
  401.     printf("    68000 Base Address: 0x%08lX\n",  jmh->jmh_68000Base);
  402.     printf("    80x86 Base Segment: 0x%04X\n", jmh->jmh_8088Segment);
  403.  
  404.     ShowFreelist(jmh);
  405.  
  406.     printf("\n");
  407. }
  408. /**********************************************************************/
  409. /*                                                                    */
  410. /**********************************************************************/
  411. void
  412. ShowFreelist(JANUSMEMHEAD *jmh)
  413. {
  414.     JANUSMEMCHUNK *jmc;
  415.     UBYTE         *bp; /* Byte Pointer */
  416.     int            i;
  417.  
  418.     /***********************************/
  419.     /* Collect Information and Sort It */
  420.     /***********************************/
  421.     jmc = (JANUSMEMCHUNK *)MakeWordPtr((APTR)((UBYTE *)(jmh->jmh_68000Base) + jmh->jmh_First));
  422.     numflist = 0;
  423.     JanusLock(MakeBytePtr((APTR)(&jmh->jmh_Lock)));
  424.     while (jmc != (JANUSMEMCHUNK *)jmh->jmh_68000Base) {
  425.         flist[numflist].base = (UBYTE *)jmc;
  426.         flist[numflist].size = jmc->jmc_Size + 1;
  427.  
  428.         if (++numflist == MAXFLIST || jmc->jmc_Next == 0xFFFF)
  429.             break;
  430.  
  431.         bp  = (UBYTE *)(jmh->jmh_68000Base);
  432.  
  433.         if (jmc->jmc_Next & 1) /* If Odd Increment, Round to Next Word Boundary */
  434.             bp++;
  435.  
  436.         jmc = (JANUSMEMCHUNK *)MakeWordPtr((APTR)(bp + jmc->jmc_Next));
  437.     }
  438.     JanusUnlock(MakeBytePtr((APTR)(&jmh->jmh_Lock)));
  439.  
  440.     qsort((char *)flist, numflist, sizeof(struct _flist), cmpflist);
  441.  
  442.     /******************************************/
  443.     /* Display Information in Ascending Order */
  444.     /******************************************/
  445.     printf("\n    Amiga-Addr    PC-Addr    Length  Status\n");
  446.     bp = (UBYTE *)jmh->jmh_68000Base;
  447.     for(i=0; i<numflist; i++) {
  448.         if (flist[i].base != bp) { /* If Out of Sync */
  449.             printf("    0x%08lX  (%04X:%04X)  %6u  Allocated\n",
  450.                 bp, jmh->jmh_8088Segment,
  451.                 (bp - (UBYTE *)(jmh->jmh_68000Base)) & 0xFFFF,
  452.                 (flist[i].base - bp) & 0xFFFF);
  453.  
  454.             bp = flist[i].base; /* Catch Up to Tracking Pointer */
  455.         }
  456.  
  457.         printf("    0x%08lX  (%04X:%04X)  %6u  Free\n",
  458.             bp, jmh->jmh_8088Segment,
  459.             (bp - (UBYTE *)(jmh->jmh_68000Base)) & 0xFFFF,
  460.             flist[i].size);
  461.  
  462.         bp += flist[i].size; /* Advance Past Free Block */
  463.     }
  464.     if (bp < (UBYTE *)jmh->jmh_68000Base + jmh->jmh_Max) {
  465.         printf("    0x%08lX  (%04X:%04X)  %6u  Allocated\n",
  466.             bp, jmh->jmh_8088Segment,
  467.             (bp - (UBYTE *)(jmh->jmh_68000Base)) & 0xFFFF,
  468.             (flist[i].base - bp) & 0xFFFF);
  469.     }
  470. }
  471. /**********************************************************************/
  472. /*                                                                    */
  473. /**********************************************************************/
  474. int
  475. cmpflist(struct _flist *a, struct _flist *b)
  476. {
  477.     if (a->base > b->base)       return  1;
  478.     else if (a->base < b->base)  return -1;
  479.     else                         return  0;
  480. }
  481. /**********************************************************************/
  482. /*                                                                    */
  483. /**********************************************************************/
  484. CONFIGDEV *
  485. FindBridgeCard()
  486. {
  487.     CONFIGDEV *cd;
  488.  
  489.     cd = FindConfigDev((LONG)NULL, 513L, 1L);
  490.  
  491.     if (cd == NULL) {
  492.         printf("Bridgecard Autoconfig Interface Not Found (Manufacturer %lu, Product %lu)\n",
  493.             513L, 1L);
  494.         printf("Other Autoconfig Devices are:\n");
  495.         ShowConfigDevices();
  496.  
  497.     } else {
  498.         printf("%s Bridgecard @ 0x%08lX, Length %4luKb, Driver @ 0x%08lX\n",
  499.             (cd->cd_Flags & CDF_CONFIGME) ? "Unconfigured" : "  Configured",
  500.             cd->cd_BoardAddr, (long)cd->cd_BoardSize / 1024L, cd->cd_Driver);
  501.         printf("    Given Slots %u Through %u (%u Slots)\n",
  502.             cd->cd_SlotAddr, cd->cd_SlotAddr + cd->cd_SlotSize - 1, cd->cd_SlotSize);
  503.     }
  504.     printf("\n");
  505.     return cd;
  506. }
  507. /**********************************************************************/
  508. /*                                                                    */
  509. /**********************************************************************/
  510. void
  511. ShowConfigDevices()
  512. {
  513.     CONFIGDEV *cd;
  514.  
  515.     cd = NULL;
  516.     while ((cd = FindConfigDev((LONG)cd, -1, -1)) != NULL) {
  517.         printf("%s Device @ 0x%08lX, Length %4luKb, Driver @ 0x%08lX\n",
  518.             (cd->cd_Flags & CDF_CONFIGME) ? "Unconfigured" : "  Configured",
  519.             cd->cd_BoardAddr, (long)cd->cd_BoardSize / 1024L, cd->cd_Driver);
  520.         printf("  Given Slots %u Through %u (%u Slots)\n",
  521.             cd->cd_SlotAddr, cd->cd_SlotAddr + cd->cd_SlotSize - 1, cd->cd_SlotSize);
  522.     }
  523. }
  524. /**********************************************************************/
  525. /*                Calculate CRC16 of a Block of Data                  */
  526. /*                                                                    */
  527. /* CRC16 polynomial: x**0 + x**2 + x**15 + x**16 (0xA001)             */
  528. /* Initial condition: 0                                               */
  529. /*                                                                    */
  530. /* D. Hugh Redelmeier  1983 April 15                                  */
  531. /* Latest change: 1984 April 2.                                       */
  532. /*                                                                    */
  533. /*>PROTOTYPE word CalcCRC16(word accum, byte *blk, int blklen)        */
  534. /**********************************************************************/
  535.  
  536. /**********************************************************************/
  537. /*                                                                    */
  538. /**********************************************************************/
  539. static word CRC16table[256] = {
  540.     0x0000, 0xc0c1, 0xc181, 0x0140, 0xc301, 0x03c0, 0x0280, 0xc241,
  541.     0xc601, 0x06c0, 0x0780, 0xc741, 0x0500, 0xc5c1, 0xc481, 0x0440,
  542.     0xcc01, 0x0cc0, 0x0d80, 0xcd41, 0x0f00, 0xcfc1, 0xce81, 0x0e40,
  543.     0x0a00, 0xcac1, 0xcb81, 0x0b40, 0xc901, 0x09c0, 0x0880, 0xc841,
  544.     0xd801, 0x18c0, 0x1980, 0xd941, 0x1b00, 0xdbc1, 0xda81, 0x1a40,
  545.     0x1e00, 0xdec1, 0xdf81, 0x1f40, 0xdd01, 0x1dc0, 0x1c80, 0xdc41,
  546.     0x1400, 0xd4c1, 0xd581, 0x1540, 0xd701, 0x17c0, 0x1680, 0xd641,
  547.     0xd201, 0x12c0, 0x1380, 0xd341, 0x1100, 0xd1c1, 0xd081, 0x1040,
  548.     0xf001, 0x30c0, 0x3180, 0xf141, 0x3300, 0xf3c1, 0xf281, 0x3240,
  549.     0x3600, 0xf6c1, 0xf781, 0x3740, 0xf501, 0x35c0, 0x3480, 0xf441,
  550.     0x3c00, 0xfcc1, 0xfd81, 0x3d40, 0xff01, 0x3fc0, 0x3e80, 0xfe41,
  551.     0xfa01, 0x3ac0, 0x3b80, 0xfb41, 0x3900, 0xf9c1, 0xf881, 0x3840,
  552.     0x2800, 0xe8c1, 0xe981, 0x2940, 0xeb01, 0x2bc0, 0x2a80, 0xea41,
  553.     0xee01, 0x2ec0, 0x2f80, 0xef41, 0x2d00, 0xedc1, 0xec81, 0x2c40,
  554.     0xe401, 0x24c0, 0x2580, 0xe541, 0x2700, 0xe7c1, 0xe681, 0x2640,
  555.     0x2200, 0xe2c1, 0xe381, 0x2340, 0xe101, 0x21c0, 0x2080, 0xe041,
  556.     0xa001, 0x60c0, 0x6180, 0xa141, 0x6300, 0xa3c1, 0xa281, 0x6240,
  557.     0x6600, 0xa6c1, 0xa781, 0x6740, 0xa501, 0x65c0, 0x6480, 0xa441,
  558.     0x6c00, 0xacc1, 0xad81, 0x6d40, 0xaf01, 0x6fc0, 0x6e80, 0xae41,
  559.     0xaa01, 0x6ac0, 0x6b80, 0xab41, 0x6900, 0xa9c1, 0xa881, 0x6840,
  560.     0x7800, 0xb8c1, 0xb981, 0x7940, 0xbb01, 0x7bc0, 0x7a80, 0xba41,
  561.     0xbe01, 0x7ec0, 0x7f80, 0xbf41, 0x7d00, 0xbdc1, 0xbc81, 0x7c40,
  562.     0xb401, 0x74c0, 0x7580, 0xb541, 0x7700, 0xb7c1, 0xb681, 0x7640,
  563.     0x7200, 0xb2c1, 0xb381, 0x7340, 0xb101, 0x71c0, 0x7080, 0xb041,
  564.     0x5000, 0x90c1, 0x9181, 0x5140, 0x9301, 0x53c0, 0x5280, 0x9241,
  565.     0x9601, 0x56c0, 0x5780, 0x9741, 0x5500, 0x95c1, 0x9481, 0x5440,
  566.     0x9c01, 0x5cc0, 0x5d80, 0x9d41, 0x5f00, 0x9fc1, 0x9e81, 0x5e40,
  567.     0x5a00, 0x9ac1, 0x9b81, 0x5b40, 0x9901, 0x59c0, 0x5880, 0x9841,
  568.     0x8801, 0x48c0, 0x4980, 0x8941, 0x4b00, 0x8bc1, 0x8a81, 0x4a40,
  569.     0x4e00, 0x8ec1, 0x8f81, 0x4f40, 0x8d01, 0x4dc0, 0x4c80, 0x8c41,
  570.     0x4400, 0x84c1, 0x8581, 0x4540, 0x8701, 0x47c0, 0x4680, 0x8641,
  571.     0x8201, 0x42c0, 0x4380, 0x8341, 0x4100, 0x81c1, 0x8081, 0x4040
  572. };
  573. /**********************************************************************/
  574. /*                                                                    */
  575. /**********************************************************************/
  576. word
  577. CalcCRC16(accum, blk, blklen)
  578. register word  accum;
  579. byte          *blk;
  580. int            blklen;
  581. {
  582.     while (blklen--)
  583.         accum = CRC16table[(accum ^ *blk++) & 0xFF] ^ accum >> 8;
  584.  
  585.     return accum;
  586. }
  587. /**********************************************************************/
  588. /*              Calculate CRC (CCITT) of a Block of Data              */
  589. /*                                                                    */
  590. /* CCITT SDLC/HDLC polynomial: X**0 + X**5 + X**12 + X**16            */
  591. /* Initial condition: 0                                               */
  592. /*                                                                    */
  593. /* D. Hugh Redelmeier  1983 April 15                                  */
  594. /* Latest change: 1984 April 2.                                       */
  595. /*                                                                    */
  596. /*>PROTOTYPE word CalcCRC_CCITT(word accum, byte *blk, int blklen)    */
  597. /**********************************************************************/
  598.  
  599. /**********************************************************************/
  600. /*                                                                    */
  601. /**********************************************************************/
  602. static word CRC16table2[256] = {
  603.     0x0000, 0x1189, 0x2312, 0x329b, 0x4624, 0x57ad, 0x6536, 0x74bf,
  604.     0x8c48, 0x9dc1, 0xaf5a, 0xbed3, 0xca6c, 0xdbe5, 0xe97e, 0xf8f7,
  605.     0x1081, 0x0108, 0x3393, 0x221a, 0x56a5, 0x472c, 0x75b7, 0x643e,
  606.     0x9cc9, 0x8d40, 0xbfdb, 0xae52, 0xdaed, 0xcb64, 0xf9ff, 0xe876,
  607.     0x2102, 0x308b, 0x0210, 0x1399, 0x6726, 0x76af, 0x4434, 0x55bd,
  608.     0xad4a, 0xbcc3, 0x8e58, 0x9fd1, 0xeb6e, 0xfae7, 0xc87c, 0xd9f5,
  609.     0x3183, 0x200a, 0x1291, 0x0318, 0x77a7, 0x662e, 0x54b5, 0x453c,
  610.     0xbdcb, 0xac42, 0x9ed9, 0x8f50, 0xfbef, 0xea66, 0xd8fd, 0xc974,
  611.     0x4204, 0x538d, 0x6116, 0x709f, 0x0420, 0x15a9, 0x2732, 0x36bb,
  612.     0xce4c, 0xdfc5, 0xed5e, 0xfcd7, 0x8868, 0x99e1, 0xab7a, 0xbaf3,
  613.     0x5285, 0x430c, 0x7197, 0x601e, 0x14a1, 0x0528, 0x37b3, 0x263a,
  614.     0xdecd, 0xcf44, 0xfddf, 0xec56, 0x98e9, 0x8960, 0xbbfb, 0xaa72,
  615.     0x6306, 0x728f, 0x4014, 0x519d, 0x2522, 0x34ab, 0x0630, 0x17b9,
  616.     0xef4e, 0xfec7, 0xcc5c, 0xddd5, 0xa96a, 0xb8e3, 0x8a78, 0x9bf1,
  617.     0x7387, 0x620e, 0x5095, 0x411c, 0x35a3, 0x242a, 0x16b1, 0x0738,
  618.     0xffcf, 0xee46, 0xdcdd, 0xcd54, 0xb9eb, 0xa862, 0x9af9, 0x8b70,
  619.     0x8408, 0x9581, 0xa71a, 0xb693, 0xc22c, 0xd3a5, 0xe13e, 0xf0b7,
  620.     0x0840, 0x19c9, 0x2b52, 0x3adb, 0x4e64, 0x5fed, 0x6d76, 0x7cff,
  621.     0x9489, 0x8500, 0xb79b, 0xa612, 0xd2ad, 0xc324, 0xf1bf, 0xe036,
  622.     0x18c1, 0x0948, 0x3bd3, 0x2a5a, 0x5ee5, 0x4f6c, 0x7df7, 0x6c7e,
  623.     0xa50a, 0xb483, 0x8618, 0x9791, 0xe32e, 0xf2a7, 0xc03c, 0xd1b5,
  624.     0x2942, 0x38cb, 0x0a50, 0x1bd9, 0x6f66, 0x7eef, 0x4c74, 0x5dfd,
  625.     0xb58b, 0xa402, 0x9699, 0x8710, 0xf3af, 0xe226, 0xd0bd, 0xc134,
  626.     0x39c3, 0x284a, 0x1ad1, 0x0b58, 0x7fe7, 0x6e6e, 0x5cf5, 0x4d7c,
  627.     0xc60c, 0xd785, 0xe51e, 0xf497, 0x8028, 0x91a1, 0xa33a, 0xb2b3,
  628.     0x4a44, 0x5bcd, 0x6956, 0x78df, 0x0c60, 0x1de9, 0x2f72, 0x3efb,
  629.     0xd68d, 0xc704, 0xf59f, 0xe416, 0x90a9, 0x8120, 0xb3bb, 0xa232,
  630.     0x5ac5, 0x4b4c, 0x79d7, 0x685e, 0x1ce1, 0x0d68, 0x3ff3, 0x2e7a,
  631.     0xe70e, 0xf687, 0xc41c, 0xd595, 0xa12a, 0xb0a3, 0x8238, 0x93b1,
  632.     0x6b46, 0x7acf, 0x4854, 0x59dd, 0x2d62, 0x3ceb, 0x0e70, 0x1ff9,
  633.     0xf78f, 0xe606, 0xd49d, 0xc514, 0xb1ab, 0xa022, 0x92b9, 0x8330,
  634.     0x7bc7, 0x6a4e, 0x58d5, 0x495c, 0x3de3, 0x2c6a, 0x1ef1, 0x0f78
  635. };
  636. /**********************************************************************/
  637. /*                                                                    */
  638. /**********************************************************************/
  639. word
  640. CalcCRC_CCITT(accum, blk, blklen)
  641. register word  accum;
  642. byte          *blk;
  643. int            blklen;
  644. {
  645.     while (blklen--)
  646.         accum = CRC16table2[(accum ^ *blk++) & 0xFF] ^ accum >> 8;
  647.  
  648.     return accum;
  649. }
  650. /**********************************************************************/
  651. /*                                                                    */
  652. /**********************************************************************/
  653. bool
  654. Initialize(int argc, char *argv[])
  655. {
  656.     if (argc >= 2 && toupper(*argv[1]) == 'H') {
  657.         printf("Usage: JDIAG {Fast}\n");
  658.         printf("   Fast ::= Omit Scans of Command Files\n");
  659.         return FALSE;
  660.     }
  661.  
  662.     if ((ExpansionBase = (struct ExpansionBase *) OpenLibrary(EXPANSIONNAME, 0)) == NULL) {
  663.         printf("Unable to Open Expansion.Library, Shutting Down.\n");
  664.         return FALSE;
  665.     }
  666.  
  667.     JanusBase = (struct JanusBase *)OpenLibrary(JANUSNAME, 0);
  668.  
  669.     if (argc >= 2 && toupper(*argv[1]) == 'F')
  670.         opt_skipfiles = TRUE;
  671.  
  672.     return TRUE;
  673. }
  674. /**********************************************************************/
  675. /*                                                                    */
  676. /**********************************************************************/
  677. void
  678. Terminate(int retcode)
  679. {
  680.     if (JanusBase)      CloseLibrary((LIBRARY *)JanusBase);
  681.     if (ExpansionBase)  CloseLibrary((LIBRARY *)ExpansionBase);
  682.  
  683.     exit(retcode);
  684. }
  685. /**********************************************************************/
  686. /*                                                                    */
  687. /**********************************************************************/
  688.  
  689.