home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 22 / AACD 22.iso / AACD / Programming / PrometheusSDK / Developer / Examples / romdump / romdump.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-04-12  |  2.8 KB  |  108 lines

  1. /* Source code of RomDump - tool for dumping PCI boards ROMs to a file      */
  2. /* It demonstrates use of prometheus.library.                               */
  3.  
  4. #define __NOLIBBASE__  /* we do not want to peeking library bases */
  5.  
  6. #include <proto/exec.h>
  7. #include <exec/memory.h>
  8. #include <proto/dos.h>
  9. #include <proto/prometheus.h>
  10.  
  11. struct Library *SysBase, *DOSBase, *PrometheusBase, *AslBase;
  12.  
  13. const char *VString = "$VER: RomDump 1.1 (12.4.2001) © 2001 Matay.\n";
  14.  
  15. WORD SelectCard(WORD max)
  16.  {
  17.   LONG number, success = FALSE;
  18.   BPTR stdin = Input(), stdout = Output();
  19.  
  20.   while (!success)
  21.    {
  22.     Printf("Input board number: ");
  23.     Flush(stdout);
  24.     Flush(stdin);
  25.     number = FGetC(stdin) - 48;
  26.     if (number > 0 && number < max) return number;
  27.    }
  28.  }
  29.  
  30.  
  31. void WriteRom(ULONG address, ULONG size)
  32.  {
  33.   UBYTE *filename = "RAM:dump";
  34.   BPTR dumpfile;
  35.   UBYTE *buffer, *bufptr;
  36.   WORD i, kb = 0;
  37.  
  38.   if (dumpfile = Open(filename, MODE_NEWFILE))
  39.    {
  40.     if (buffer = AllocMem(2048, MEMF_ANY))
  41.      {
  42.       for (bufptr = (UBYTE*)address; bufptr < (UBYTE*)address + size;
  43.        bufptr += 2048)
  44.        {
  45.         for (i = 0; i < 2048; i++)
  46.          {
  47.           buffer[i] = bufptr[i];
  48.           CacheClearU();
  49.           buffer[i] = bufptr[i];
  50.          }
  51.         FWrite(dumpfile, buffer, 2048, 1);
  52.         kb += 2;
  53.         Printf("%ld kB read...     \r", kb);
  54.        }    
  55.       FreeMem(buffer,2048);
  56.      }
  57.     else Printf("Out of memory.\n");
  58.     Close(dumpfile);
  59.    }
  60.   else Printf("Can't open file.\n");
  61.  }
  62.  
  63.  
  64. LONG Main(void)
  65.  {
  66.   Printf("\nRomDump 1.0 © 2001 Matay.\n");
  67.   Printf("PCI cards with ROMs:\n-------------------------------------------------\n");
  68.  
  69.   if (AslBase = OpenLibrary("asl.library",38))
  70.    {
  71.     if (PrometheusBase = OpenLibrary("prometheus.library", 1))
  72.      {
  73.       APTR board = NULL;
  74.       ULONG vendor, device, romaddr, romsize;
  75.       ULONG addresses[4], sizes[4];
  76.       WORD card = 1;
  77.  
  78.       while (board = Prm_FindBoardTags (board, TAG_END))
  79.        {
  80.         Prm_GetBoardAttrsTags(board,
  81.          PRM_Vendor, (ULONG)&vendor,
  82.          PRM_Device, (ULONG)&device,
  83.          PRM_ROM_Address, (ULONG)&romaddr,
  84.          PRM_ROM_Size, (ULONG)&romsize,
  85.          TAG_END);
  86.         if (romaddr && romsize)
  87.          {
  88.           addresses[card] = romaddr;
  89.           sizes[card] = romsize;
  90.           Printf("%ld. Vendor %04lx, device %04lx, %ld kB of ROM at $%08lx.\n", card,
  91.            vendor, device, romsize >> 10, romaddr);
  92.          }
  93.         card++;
  94.        }
  95.       Printf ("\n");
  96.       card = SelectCard(card);
  97.       Printf("Selected card %ld with %ld kB of ROM at %08lx.\n", card,
  98.        sizes[card] >> 10, addresses[card]);
  99.       WriteRom(addresses[card], sizes[card]);
  100.       CloseLibrary(PrometheusBase);
  101.      }
  102.     CloseLibrary(AslBase);
  103.    }
  104.   else Printf("No working Prometheus board found in the system.\n\n");
  105.   return 0;
  106.  }
  107.  
  108.