home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 200-299 / ff233.lzh / CacheCard / cachecard.c < prev    next >
C/C++ Source or Header  |  1989-07-29  |  4KB  |  157 lines

  1. /*
  2.     CacheCard V1.0
  3.     Copyright 1989 by Dave Haynie
  4.  
  5.     MAIN PROGRAM
  6.  
  7.     This program is a simple cache manager for use with SetCPU V1.5.
  8.     It allows the cachability of various autoconfig cards to be
  9.     adjusted.
  10.     
  11.     The current MMU table used by SetCPU establishes 128K pages using
  12.     the short form of the early termination descriptor.  Except for
  13.     any CardROMs that are translated, the table is only 1 level.  In
  14.     systems with more than 16meg of address space, the MMU table will
  15.     be accordingly adjusted, though it's unlikely that any program
  16.     will need adjust table parameters beyond the first 16 megabytes.
  17. */
  18.  
  19. #include "cachecard.h"
  20.  
  21. #define max(a,b)    ((a>b)?a:b)
  22. #define PAGESIZE    0x00020000L
  23.  
  24. struct ExpansionBase *ExpansionBase = NULL;    /* The expansion library */
  25. struct systag *tag;                /* The SetCPU system tag */
  26.  
  27. /* ====================================================================== */
  28.  
  29. /* A simple string comparison. */
  30.  
  31. BOOL striequ(s1,s2)
  32. char *s1,*s2;
  33. {
  34.    BOOL aok = FALSE;
  35.    
  36.    while (*s1 && *s2 && (aok = (*s1++ & 0xdf) == (*s2++ & 0xdf)));
  37.    return (BOOL) (!*s1 && !*s2 && aok);
  38. }
  39.  
  40. /* This routine gets the system tag from the patched system, if it's
  41.    there.  This tag is stored in an invalid table entry that's within the
  42.    physical ROM image.  If the MMU isn't on, I assume there's no system
  43.    tag. */
  44.    
  45. struct systag *GetSysTag() {
  46.    ULONG i, myCRP[2], *table = NULL;
  47.  
  48.    if (!(GetTC() & TC_ENB)) return NULL;
  49.  
  50.    GetCRP(myCRP);
  51.    table = (ULONG *)myCRP[1];
  52.    for (i = 0; i < 4096; ++i)
  53.       if ((table[i] & PD_DT_TYPE) == PD_DT_INVALID && IV_ADDR(table[i]))
  54.          return (struct systag *)IV_ADDR(table[i]);
  55.  
  56.    return NULL;
  57. }
  58.  
  59. /* This function prints a list of active devices and their associated
  60.    cache status. */
  61.    
  62. void PrintDevs() {
  63.    struct ConfigDev *cd = NULL;
  64.    ULONG page;
  65.  
  66.    if (!(cd = FindConfigDev(NULL,-1L,-1L))) {
  67.       printf("No Amiga Devices present\n");
  68.       return;
  69.    }
  70.  
  71.    printf("DEVICE             ADDRESS     LENGTH    CACHE\n");
  72.  
  73.    do {
  74.       printf("(%4x,%4x)      ",cd->cd_Rom.er_Manufacturer,cd->cd_Rom.er_Product);
  75.       printf("%8lx    %8lx    ",cd->cd_BoardAddr,cd->cd_BoardSize);
  76.       
  77.       page = (ULONG)cd->cd_BoardAddr/PAGESIZE;
  78.       if (tag->maintable[page] & PD_CI)
  79.          printf("DISABLED\n");
  80.       else
  81.          printf("ENABLED\n");
  82.    
  83.    } while (cd = FindConfigDev(cd,-1L,-1L));
  84. }
  85.  
  86.  
  87. /* The main thing */
  88.  
  89. int main(argc,argv)
  90. int argc;
  91. char *argv[];
  92. {
  93.    ULONG mmu = 0, page, size, manuf, prod;
  94.    BOOL ever;
  95.    struct ConfigDev *cd;
  96.    
  97.    printf("\23333mCacheCard V%1.2f Copyright 1989 by Dave Haynie\2330m\n",
  98.              ((float)PROGRAM_VERSION)/100.0);
  99.  
  100.    if (argc == 2 && argv[1][0] == '?') {
  101.       printf("Usage: CacheCard [ENABLE|DISABLE manuf# prod#]\n");
  102.       exit(0);
  103.    }
  104.    if ((mmu = GetMMUType()) != 68851 && mmu != 68030) {
  105.       printf("Error: System does not contain an MMU\n");
  106.       exit(10);
  107.    }
  108.    if (!(tag = GetSysTag())) {
  109.       printf("Error: SetCPU FASTROM or KICKROM must be installed\n");
  110.       exit(10);
  111.    }
  112.    if (tag->tagsize >= SizeOf(struct systag) && tag->tablerev != TABLE_REV) {
  113.       printf("Error: Version of SetCPU is incompatible, use newer CacheCard program\n");
  114.       exit(0);
  115.    }
  116.    if (!(ExpansionBase = (struct ExpansionBase *)OpenLibrary("expansion.library",33L))) {
  117.       printf("Error: Can't find \"expansion.library\"\n");
  118.       exit(10);
  119.    }
  120.  
  121.    if (argc > 1) {
  122.       sscanf(argv[2],"%lx",&manuf);
  123.       sscanf(argv[3],"%lx",&prod);
  124.    
  125.       if (striequ(argv[1],"DISABLE"))
  126.          ever = FALSE;
  127.       else if (striequ(argv[1],"ENABLE"))
  128.          ever = TRUE;
  129.       else {
  130.          printf("Error: Illegal option\n");
  131.          exit(10);
  132.       }
  133.  
  134.       if (!(cd = FindConfigDev(NULL,manuf,prod))) {
  135.          printf("Error: Device (%lx,%lx) Not Found\n",manuf,prod);
  136.          CloseLibrary(ExpansionBase);
  137.          exit(10);
  138.       }
  139.       
  140.       page = (ULONG)cd->cd_BoardAddr/PAGESIZE;
  141.       size = max((ULONG)cd->cd_BoardSize/PAGESIZE,1);
  142.  
  143.       while (size-- && page < tag->tablesize)
  144.          if ((tag->maintable[page] & PD_DT_TYPE) != PD_DT_INVALID) {
  145.             if (ever)
  146.                tag->maintable[page++] &= ~PD_CI;
  147.             else 
  148.                tag->maintable[page++] |=  PD_CI;
  149.          }
  150.    }
  151.    
  152.    PrintDevs();
  153.  
  154.    CloseLibrary(ExpansionBase);
  155.    exit(0);
  156. }
  157.