home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 6 / AACD06.ISO / AACD / Emulation / AmigaVGB / testall.c < prev    next >
C/C++ Source or Header  |  1996-04-28  |  2KB  |  52 lines

  1. /** GameBoy Cartridge Tester *********************************/   
  2. /**                                                         **/
  3. /**                        testall.c                        **/
  4. /**                                                         **/
  5. /** This program written by Pascal Felber will test all of  **/
  6. /** your cartridges finding those which fail CRC check.     **/
  7. /**                                                         **/
  8. /** Copyright (C) Pascal Felber 1996                        **/
  9. /**     You are not allowed to distribute this software     **/
  10. /**     commercially. Please, notify me, if you make any    **/
  11. /**     changes to this file.                               **/
  12. /*************************************************************/
  13.  
  14. #include <stdio.h>
  15.  
  16. unsigned char RAM[0x4000];
  17.  
  18. void main(int argc,char *argv[])
  19. {
  20.   FILE *s;
  21.   unsigned checksum;
  22.   int i, arg = 0;
  23.  
  24.   if(argc < 2) {
  25.     fprintf(stderr, "Usage: %s file...\n", argv[0]);
  26.     exit(1);
  27.   }
  28.  
  29.   while(++arg < argc) {
  30.     if(!(s = fopen(argv[arg], "rb"))) {
  31.       perror("fopen");
  32.       exit(1);
  33.     }
  34.  
  35.     if(fread(RAM, 1, 0x4000, s) == 0x4000) {
  36.       checksum = ((unsigned)RAM[0x014E]<<8)+RAM[0x014F];
  37.       checksum += RAM[0x014E]+RAM[0x014F];
  38.       do {
  39.     for(i = 0; i < 0x4000; i++)
  40.       checksum -= RAM[i];
  41.       } while(fread(RAM, 1, 0x4000, s) == 0x4000);
  42.     } else {
  43.       fprintf(stderr, "Error while reading %s\n", argv[arg]);
  44.     }
  45.  
  46.     fclose(s);
  47.  
  48.     if(checksum & 0xFFFF)
  49.       printf("%s: Checksum error\n", argv[arg]);
  50.   }
  51. }
  52.